Advertisement
Aliyah

Class.php (Database checks here)

Dec 7th, 2012
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.00 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.     global $wpdb;
  5.  
  6.  
  7.    
  8.  
  9.  
  10.     $wpdb->query("ALTER TABLE ".$wpdb->prefix."bp_activity
  11.  
  12.  
  13.         ADD star int(11)");
  14.  
  15.  
  16.     $wpdb->query("ALTER TABLE ".$wpdb->prefix."bp_activity
  17.  
  18.  
  19.         ADD usercheck int(11)");   
  20.  
  21.  
  22.        
  23.  
  24.  
  25.     function setupdata_depro($user_id,$component,$type,$action,$content,$primary_link,$item_id,$secondary_item_id,$date_recorded,$hide_sitewide,$mptt_left,$mptt_right,$star,$usercheck){
  26.  
  27.  
  28.         global $wpdb;
  29.  
  30.  
  31.         $wpdb->query( $wpdb->prepare(
  32.  
  33.  
  34.             "
  35.  
  36.  
  37.                 INSERT INTO ".$wpdb->prefix."bp_activity
  38.  
  39.  
  40.                 ( user_id, component, type ,action, content, primary_link, item_id, secondary_item_id, date_recorded, hide_sitewide, mptt_left, mptt_right,star,usercheck)
  41.  
  42.  
  43.                 VALUES ( %d, %s, %s ,%s, %s ,%s, %s ,%s, %s ,%s, %s ,%s,%s,%s)
  44.  
  45.  
  46.             ",
  47.  
  48.  
  49.                 array(
  50.  
  51.  
  52.                 $user_id,
  53.  
  54.  
  55.                 $component,
  56.  
  57.  
  58.                 $type,
  59.  
  60.  
  61.                 $action,
  62.  
  63.  
  64.                 $content,
  65.  
  66.  
  67.                 $primary_link,
  68.  
  69.  
  70.                 $item_id,
  71.  
  72.  
  73.                 $secondary_item_id,
  74.  
  75.  
  76.                 $date_recorded,
  77.  
  78.  
  79.                 $hide_sitewide,
  80.  
  81.  
  82.                 $mptt_left,
  83.  
  84.  
  85.                 $mptt_right,
  86.  
  87.  
  88.                 $star,
  89.  
  90.  
  91.                 $usercheck
  92.  
  93.  
  94.             )
  95.  
  96.  
  97.         ) );
  98.  
  99.  
  100.  
  101.  
  102.     }
  103.  
  104.  
  105.     add_action('bp_member_options_nav','deprohoang_add_style');
  106.  
  107.  
  108.     function deprohoang_add_style(){
  109.  
  110.  
  111.     echo '<style type="text/css">.Member_review{display:none;}</style>';
  112.  
  113.  
  114.     }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. $options = get_option('reviews_options');
  121.  
  122.  
  123. if($options['profile'] == "profile"){
  124.  
  125.  
  126.    
  127.  
  128.  
  129.     add_action('bp_after_member_header','add_star_loop_header');
  130.  
  131.  
  132.    
  133.  
  134.  
  135.     add_action('bp_directory_members_actions','add_star_loop_content');
  136.  
  137.  
  138.    
  139.  
  140.  
  141.     function add_star_loop_header(){
  142.  
  143.  
  144.         return add_star_loop(2);
  145.  
  146.  
  147.     }
  148.  
  149.  
  150.     function add_star_loop_content(){
  151.  
  152.  
  153.         return add_star_loop(1);
  154.  
  155.  
  156.     }
  157.  
  158.  
  159.     function add_star_loop($checkitem){
  160.  
  161.  
  162.         global $wpdb;
  163.  
  164.  
  165.         if($checkitem == 1){
  166.  
  167.  
  168.         $check_content_loop = $wpdb->get_results("SELECT AVG(star) AS Average FROM ".$wpdb->prefix."bp_activity WHERE  type = 'Member_review' AND usercheck='".bp_get_member_user_id()."'");
  169.  
  170.  
  171.        
  172.  
  173.  
  174.         $check_content_loop_count = $wpdb->get_col("SELECT star FROM ".$wpdb->prefix."bp_activity WHERE  type = 'Member_review' AND usercheck='".bp_get_member_user_id()."'");
  175.  
  176.  
  177.         }else{
  178.  
  179.  
  180.         $check_content_loop = $wpdb->get_results("SELECT AVG(star) AS Average FROM ".$wpdb->prefix."bp_activity WHERE  type = 'Member_review' AND usercheck='".bp_displayed_user_id()."'");
  181.  
  182.  
  183.        
  184.  
  185.  
  186.         $check_content_loop_count = $wpdb->get_col("SELECT star FROM ".$wpdb->prefix."bp_activity WHERE  type = 'Member_review' AND usercheck='".bp_displayed_user_id()."'");      
  187.  
  188.  
  189.         }
  190.  
  191.  
  192.         if($check_content_loop[0]->Average != ""){
  193.  
  194.  
  195.             $check_show_star_loop = $check_content_loop[0]->Average;           
  196.  
  197.  
  198.             $demss = 0;
  199.  
  200.  
  201.             echo '<span class="rating-top" style="position:relative;top:-10px"> ';
  202.  
  203.  
  204.             for($dem = 1; $dem < 6 ; $dem ++){
  205.  
  206.  
  207.                 if($dem <= $check_show_star_loop ){
  208.  
  209.  
  210.                     echo '<img alt="1 star" src="'.DEPROURL.'/images/star.png">';
  211.  
  212.  
  213.                 }else{
  214.  
  215.  
  216.                     $demss++;
  217.  
  218.  
  219.                     if(ceil($check_show_star_loop)- $check_show_star_loop > 0 and $demss == 1){
  220.  
  221.  
  222.                             echo '<img alt="1 star" src="'.DEPROURL.'/images/star_half.png">';
  223.  
  224.  
  225.                     }else{
  226.  
  227.  
  228.                         echo '<img alt="1 star" src="'.DEPROURL.'/images/star_off.png">';
  229.  
  230.  
  231.                     }
  232.  
  233.  
  234.                 }          
  235.  
  236.  
  237.            
  238.  
  239.  
  240.             }
  241.  
  242.  
  243.             echo ' (Based on '.count($check_content_loop_count).' reviews)</span>';
  244.  
  245.  
  246.         }else{
  247.  
  248.  
  249.             echo '<span class="rating-top" style="position:relative;top:-5px;font-weight:bold">No Reviews</span>';
  250.  
  251.  
  252.         }
  253.  
  254.  
  255.        
  256.  
  257.  
  258.        
  259.  
  260.  
  261.     }
  262.  
  263.  
  264.     add_action('bp_member_options_nav','deprohoang_add');
  265.  
  266.  
  267.    
  268.  
  269.  
  270.     function deprohoang_add(){
  271.  
  272.  
  273.         if(isset($_GET['review'])){
  274.  
  275.  
  276.             $check = $_GET['review'];
  277.  
  278.  
  279.         }  
  280.  
  281.  
  282.         if($check == "true"){      
  283.  
  284.  
  285.             $addclass = "class='supper_current supper_selected supper_deproadd'";
  286.  
  287.  
  288.         }else{
  289.  
  290.  
  291.             $addclass = "class='supper_deproadd'";
  292.  
  293.  
  294.         }
  295.  
  296.  
  297.         echo "<li ".$addclass." ><a href='".get_bloginfo('home')."/members/".bp_core_get_username(bp_displayed_user_id())."/?review=true'>Reviews</a></li>";
  298.  
  299.  
  300.         require_once('css/customstylememberone.php');
  301.  
  302.  
  303.     }
  304.  
  305.  
  306.    
  307.  
  308.  
  309.     add_action('bp_before_member_body','deprohoang_addbody');
  310.  
  311.  
  312.    
  313.  
  314.  
  315.     function deprohoang_addbody(){
  316.  
  317.  
  318.      
  319.  
  320.  
  321.    
  322.  
  323.  
  324.    
  325.  
  326.  
  327.         if(isset($_GET['review'])){
  328.  
  329.  
  330.             $check = $_GET['review'];
  331.  
  332.  
  333.         }else{
  334.  
  335.  
  336.             $check = "";
  337.  
  338.  
  339.         }  
  340.  
  341.  
  342.         if($check == "true"){  
  343.  
  344.  
  345.        
  346.  
  347.  
  348.         require_once('css/customstylemembertwo.php');
  349.  
  350.  
  351.         require_once('function/postreviewform.php');   
  352.  
  353.  
  354.        
  355.  
  356.  
  357. ?>
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.                
  367.  
  368.  
  369. <?php          
  370.  
  371.  
  372.         }
  373.  
  374.  
  375.     }  
  376.  
  377.  
  378.     if(isset($_POST['review_member_submit'])){
  379.  
  380.  
  381.         if(isset($_POST['review_member_content']) and $_POST['review_member_content'] != ""){          
  382.  
  383.  
  384.             add_action('template_notices','add_title_here_success');
  385.  
  386.  
  387.            
  388.  
  389.  
  390.             $current_user = wp_get_current_user();
  391.  
  392.  
  393.             $user_reviewd = $_POST['rating_member_id'];
  394.  
  395.  
  396.             $user_reviewd_name = $_POST['rating_member_name'];
  397.  
  398.  
  399.             $avartar_reviewd = "";
  400.  
  401.  
  402.             $link_set = get_bloginfo('home')."/members/".$current_user->user_login;
  403.  
  404.  
  405.            
  406.  
  407.  
  408.             $rating_member = $_POST['rating_member'];
  409.  
  410.  
  411.             $contentss.='<span class="ratingtop">';
  412.  
  413.  
  414.             for($dem = 1; $dem < 6 ; $dem ++){
  415.  
  416.  
  417.                 if($dem <= $rating_member ){
  418.  
  419.  
  420.                     $contentss.= '<img alt="1 star" src="'.DEPROURL.'/images/star.png">';
  421.  
  422.  
  423.                 }else{                 
  424.  
  425.  
  426.                     $contentss.='<img alt="1 star" src="'.DEPROURL.'/images/star_off.png">';                   
  427.  
  428.  
  429.                 }          
  430.  
  431.  
  432.            
  433.  
  434.  
  435.             }
  436.  
  437.  
  438.             $contentss.='</span>';
  439.  
  440.  
  441.             $user_id = $current_user->ID;
  442.  
  443.  
  444.             $component = "Members";
  445.  
  446.  
  447.             $type = "Member_review";
  448.  
  449.  
  450.             $action = "<a href='".$link_set."' title='".$current_user->user_login."'>".$current_user->user_login."</a> posted an Review ".$avartar_reviewd." <a href='".get_bloginfo('home')."/members/".$user_reviewd_name."'>".$user_reviewd_name."</a>";
  451.  
  452.  
  453.             $content = $contentss.$_POST['review_member_content'];
  454.  
  455.  
  456.             $primary_link = $link_set ;
  457.  
  458.  
  459.             $item_id = "";
  460.  
  461.  
  462.             $secondary_item_id = "";
  463.  
  464.  
  465.             $date_recorded = date('Y-m-d H:i:s ');
  466.  
  467.  
  468.             $hide_sitewide = 0;
  469.  
  470.  
  471.             $mptt_left = 0;
  472.  
  473.  
  474.             $mptt_right = 0;
  475.  
  476.  
  477.             $star  = $rating_member;
  478.  
  479.  
  480.             $usercheck = $user_reviewd;
  481.  
  482.  
  483.            
  484.  
  485.  
  486.             setupdata_depro($user_id,$component,$type,$action,$content,$primary_link,$item_id,$secondary_item_id,$date_recorded,$hide_sitewide,$mptt_left,$mptt_right,$star,$usercheck);
  487.  
  488.         $setcheckoption = $user_id."-".$usercheck;
  489.         $checkfirst = get_option($setcheckoption); 
  490.         if($checkfirst){
  491.             update_option( $setcheckoption, $checkfirst + 1 );
  492.         }else{
  493.             add_option( $setcheckoption, 1, '', 'yes' );
  494.         }
  495.  
  496.         }else{
  497.  
  498.  
  499.             add_action('template_notices','add_title_here_error');
  500.  
  501.  
  502.         }
  503.  
  504.  
  505.     }  
  506.  
  507.  
  508.     function add_title_here_success(){
  509.  
  510.  
  511.     echo '
  512.  
  513.  
  514.         <div id="message" class="updated">
  515.  
  516.  
  517.             <p>Your review was posted successfully!</p>
  518.  
  519.  
  520.         </div>
  521.  
  522.  
  523.     ';
  524.  
  525.  
  526.     }
  527.  
  528.  
  529.     function add_title_here_error(){
  530.  
  531.  
  532.         echo '
  533.  
  534.  
  535.             <div id="message" class="error" style="display: block;">
  536.  
  537.  
  538.                 <p>Please enter some content to post.</p>
  539.  
  540.  
  541.             </div>
  542.  
  543.  
  544.         ';
  545.  
  546.  
  547.     }
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556. }
  557.  
  558.  
  559. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement