Advertisement
Guest User

Prevent Duplicate Data

a guest
Dec 6th, 2012
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.85 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. global $wpdb;
  5.  
  6.  
  7. $current_user = wp_get_current_user();
  8.  
  9.  
  10.  
  11.  
  12.  
  13. $check_exit = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."bp_activity WHERE user_id ='$current_user->ID' AND type = 'Member_review' AND usercheck='".bp_displayed_user_id()."'");
  14.  
  15.  
  16.  
  17.  
  18.  
  19. $check_content = $wpdb->get_col("SELECT star FROM ".$wpdb->prefix."bp_activity WHERE user_id ='$current_user->ID' AND type = 'Member_review' AND usercheck='".bp_displayed_user_id()."'");
  20.  
  21.  
  22.  
  23.  
  24.  
  25. $check_content_true = $wpdb->get_col("SELECT content FROM ".$wpdb->prefix."bp_activity WHERE user_id ='$current_user->ID' AND type = 'Member_review' AND usercheck='".bp_displayed_user_id()."'");
  26.  
  27. $check_content_true_arrayid = $wpdb->get_col("SELECT ID FROM ".$wpdb->prefix."bp_activity WHERE user_id ='$current_user->ID' AND type = 'Member_review' AND usercheck='".bp_displayed_user_id()."'");
  28.  
  29.  
  30.  
  31. $check_content_loop = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."bp_activity WHERE  type = 'Member_review' AND usercheck='".bp_displayed_user_id()."'");
  32.  
  33.  
  34.  
  35.  
  36.  
  37. if ( is_user_logged_in() ) {
  38.  
  39. ?>
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. <?php
  47.  
  48.     $options = get_option('reviews_options');
  49.  
  50.     $check_total_set = $wpdb->get_col("SELECT id FROM ".$wpdb->prefix."bp_activity WHERE user_id ='$current_user->ID' AND type = 'Member_review' ");
  51.  
  52.     if($options['limit'] == 0){
  53.         $show_check = true;
  54.     }else{
  55.         $show_check = false;
  56.     };
  57.     $check_show = (bp_displayed_user_id() == $current_user->ID  and  $options['Prevent'] == "Prevent");
  58.  
  59.     if($check_show){
  60.  
  61.         echo "<p style='padding-bottom:5px'>You can't review yourself</p>";
  62.  
  63.     }else{ ?>
  64.  
  65. <form class="review-member-form whats-new-form-member" name="whats-new-form" id="whats-new-form " method="post" action="">
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.     <div id="whats-new-avatar">
  75.  
  76.  
  77.         <a href="<?php echo get_bloginfo('home');?>/members/<?php echo $current_user->user_login;?>/">
  78.  
  79.  
  80.             <?php echo get_avatar( $current_user->ID, 60, $default, $current_user->display_name ); ?>
  81.  
  82.  
  83.         </a>
  84.  
  85.  
  86.     </div>
  87.  
  88.  
  89. <?PHP
  90.  
  91.  
  92.     IF(COUNT($check_exit) != 0){
  93.  
  94.     if($options['limit'] == 0){
  95.             $maxss = 10000;
  96.     }else{
  97.         $maxss = $options['limit'];
  98.     }
  99.  
  100.  
  101.  
  102.  
  103. ?>
  104.  
  105.  
  106. <?php
  107.  
  108.  
  109. $args = array(
  110.  
  111.  
  112.     'user_id' => $check_exit[0]->user_id,
  113.  
  114.  
  115.     'action'  => 'Member_review',
  116.  
  117.  
  118.     'in'     => $check_content_true_arrayid,
  119.  
  120.     'max'    => $maxss
  121.  
  122.  
  123. );
  124.  
  125.  
  126.  if ( bp_has_activities($args)) :
  127.  
  128.         $demsss = -1;
  129.  
  130.     ?>
  131.  
  132.  
  133.     <?php while ( bp_activities() ) : bp_the_activity();
  134.  
  135.         $demsss++;
  136.  
  137.     ?>
  138.  
  139.  
  140.     <div class="already-rated">
  141.  
  142.  
  143.         <h5><?php printf( __( "You rated %s "), bp_core_get_username(bp_displayed_user_id()) ) ?></h5>
  144.  
  145.  
  146.     <style type="text/css">
  147.  
  148.  
  149.     #activity-<?php echo $check_exit[0]->id; ?> .hidencheck{display:none }
  150.  
  151.  
  152.     </style>
  153.  
  154.  
  155.         <blockquote style="padding-bottom:20px">
  156.  
  157.  
  158.             <style type="text/css">.already-rated p .ratingtop{display:none ;}</style>
  159.  
  160.  
  161.             <p><?php echo $check_content_true[$demsss]; ?></p>
  162.  
  163.  
  164.             <div class="rest-stars">
  165.  
  166.  
  167.                 <span class="ratingtop" style="float:right">
  168.  
  169.  
  170.  
  171.  
  172.  
  173.                 <?php
  174.  
  175.  
  176.                 for($dem = 1; $dem < 6 ; $dem ++){
  177.  
  178.  
  179.                     if($dem <= $check_content[$demsss] ){
  180.  
  181.  
  182.                         echo '<img alt="1 star" src="'.DEPROURL.'/images/star.png">';
  183.  
  184.  
  185.                     }else{
  186.  
  187.  
  188.                         echo '<img alt="1 star" src="'.DEPROURL.'/images/star_off.png">';
  189.  
  190.  
  191.                     }
  192.  
  193.  
  194.  
  195.  
  196.  
  197.                 }
  198.  
  199.  
  200.                 ?>
  201.  
  202.  
  203.                 </span><br>
  204.             <p style="float:right;margin-top:5px;"><?php bp_activity_delete_link() ?></p>
  205.  
  206.             </div>
  207.  
  208.  
  209.         </blockquote>
  210.  
  211.  
  212.  
  213.  
  214.     </div>
  215.  
  216.  
  217.     <?php endwhile; ?>
  218.  
  219.  
  220. <?php endif;
  221.  
  222. };
  223. if(COUNT($check_exit) < $options['limit'] or $options['limit'] == 0){
  224.  
  225.  
  226. ?>
  227.  
  228.  
  229.  
  230.  
  231.  
  232.     <h5>What are your thoughts on <?php echo bp_core_get_username(bp_displayed_user_id()); ?>, <?php echo $current_user->display_name ; ?>?</h5>
  233.  
  234.  
  235.  
  236.  
  237.  
  238.     <div id="whats-new-content">
  239.  
  240.  
  241.         <div id="whats-new-textarea">
  242.  
  243.  
  244.             <div>
  245.  
  246.  
  247.                 <textarea value="" id="whats-new" name="review_member_content" style="display: inline-block; height: 50px;"></textarea>
  248.  
  249.  
  250.             </div>
  251.  
  252.  
  253.         </div>
  254.  
  255.  
  256.  
  257.  
  258.  
  259.         <div id="review-rating" >
  260.  
  261.  
  262.             Rate it: <img src="<?php echo DEPROURL;?>/images/star_off.png" class="star" id="star1">
  263.  
  264.  
  265.                     <img src="<?php echo DEPROURL;?>/images/star_off.png" class="star" id="star2">
  266.  
  267.  
  268.                     <img src="<?php echo DEPROURL;?>/images/star_off.png" class="star" id="star3">
  269.  
  270.  
  271.                     <img src="<?php echo DEPROURL;?>/images/star_off.png" class="star" id="star4">
  272.  
  273.  
  274.                     <img src="<?php echo DEPROURL;?>/images/star_off.png" class="star" id="star5">
  275.  
  276.  
  277.         </div>
  278.  
  279.  
  280.         <div id="whats-new-options" style="height: 40px;">
  281.  
  282.  
  283.             <div id="whats-new-submit">
  284.  
  285.  
  286.                 <input type="hidden" value="0" id="rating" name="rating_member">
  287.  
  288.  
  289.                 <input type="hidden" value="<?php echo bp_displayed_user_id(); ?>" id="rating_id" name="rating_member_id">
  290.  
  291.  
  292.                 <input type="hidden" value="<?php echo bp_core_get_username(bp_displayed_user_id()); ?>" id="rating_name" name="rating_member_name">
  293.  
  294.  
  295.                 <span class="ajax-loader"></span> &nbsp;
  296.  
  297.  
  298.                 <input type="submit" value="Post My Review" id="whats-new-submit" name="review_member_submit">
  299.  
  300.  
  301.             </div>
  302.  
  303.  
  304.         </div><!-- #whats-new-options -->
  305.  
  306.  
  307.     </div><!-- #whats-new-content -->
  308.  
  309.  
  310. <?php
  311.  
  312.  
  313.     }
  314.  
  315. ?>
  316.  
  317.  
  318.  
  319.  
  320.  
  321. </form>
  322. <?php };?>
  323.  
  324. <?php };?>
  325.  
  326.  
  327. <script type="text/javascript">
  328.  
  329.  
  330. jQuery(document).ready( function() {
  331.  
  332.  
  333.     jQuery(".Member_review").html("");
  334.  
  335.  
  336. });
  337.  
  338.  
  339. </script>
  340.  
  341.  
  342. <?php if (count($check_content_loop) > 0){ ?>
  343.  
  344.  
  345.     <div class="pagination" id="pag-top" style="margin-bottom:20px">
  346.  
  347.  
  348.  
  349.  
  350.  
  351.         <div id="group-dir-count-top" class="pag-count">
  352.  
  353.  
  354.  
  355.  
  356.  
  357.             Viewing reviews 1 to <?php echo count($check_content_loop);?>  (of <?php echo bp_core_get_username(bp_displayed_user_id()); ?> )
  358.  
  359.  
  360.         </div>
  361.  
  362.  
  363.  
  364.  
  365.  
  366.         <div id="group-dir-pag-top" class="pagination-links">
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.         </div>
  376.  
  377.  
  378.  
  379.  
  380.  
  381.     </div>
  382.  
  383.  
  384. <?php }else{; ?>
  385.  
  386.  
  387.     <div id="message" class="info">
  388.  
  389.  
  390.         <p><?php printf( __( "There are no reviews yet. Why not <a href=\"#\">be the first to write one</a>?", 'bpgr' ) ) ?></p>
  391.  
  392.  
  393.     </div>
  394.  
  395.  
  396. <?php }; ?>
  397.  
  398.  
  399.     <div class="activity show_important">
  400.  
  401.  
  402.     <ul id="activity-stream" class="activity-list item-list ">
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411. <?php
  412.  
  413.  
  414.         foreach($check_content_loop as $check_content_loopss) :
  415.  
  416.  
  417.         $depro_idcheck = $check_content_loopss->id;
  418.  
  419.  
  420.         $user_info_id = $check_content_loopss->user_id;
  421.  
  422.  
  423.         $user_info_lastcheck = get_userdata($user_info_id);
  424.  
  425.  
  426. ?>
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438. <?php
  439.  
  440.  
  441.  
  442.  
  443.  
  444. $args = array(
  445.  
  446.  
  447.             'user_id' => $user_info_id,
  448.  
  449.  
  450.             'action' => 'Member_review',
  451.  
  452.  
  453.             'max' => 1
  454.  
  455.  
  456. );
  457.  
  458.  
  459.  if ( bp_has_activities($args)) : ?>
  460.  
  461.  
  462.     <?php while ( bp_activities() ) : bp_the_activity(); ?>
  463.  
  464.  
  465.  
  466.  
  467.  
  468.     <li id="activity-<?php echo $depro_idcheck; ?>" class="member review">
  469.  
  470.  
  471.     <div class="activity-avatar">
  472.  
  473.  
  474.         <a href="<?php echo get_bloginfo('home');?>/members/<?php echo $user_info_lastcheck->user_login;?>/">
  475.  
  476.  
  477.             <?php echo get_avatar( $check_content_loopss->user_id, 30, $default, "" ); ?>
  478.  
  479.  
  480.         </a>
  481.  
  482.  
  483.     </div>
  484.  
  485.  
  486.  
  487.  
  488.  
  489.     <div class="activity-content">
  490.  
  491.  
  492.  
  493.  
  494.  
  495.         <div class="activity-header">
  496.  
  497.  
  498.             <span class="ratingtop">
  499.  
  500.  
  501.  
  502.  
  503.  
  504.                 <?php
  505.  
  506.  
  507.                 for($dem = 1; $dem < 6 ; $dem ++){
  508.  
  509.  
  510.                     if($dem <= $check_content_loopss->star){
  511.  
  512.  
  513.                         echo '<img alt="1 star" src="'.DEPROURL.'/images/star.png">';
  514.  
  515.  
  516.                     }else{
  517.  
  518.  
  519.                         echo '<img alt="1 star" src="'.DEPROURL.'/images/star_off.png">';
  520.  
  521.  
  522.                     }
  523.  
  524.  
  525.                 }
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.                 ?>
  538.  
  539.  
  540.             </span> By <a href="<?php echo get_bloginfo('home');?>/members/<?php echo $user_info_lastcheck->user_login;?>/"><?php echo $user_info_lastcheck->user_login; ?></a> <?php echo  bp_core_time_since($check_content_loopss->date_recorded ) ?>
  541.  
  542.  
  543. <span class="hidencheck"><span style='color:red'><!-- only Administrator see this button --></span><?php if(current_user_can('administrator')){ bp_activity_delete_link(); }; ?></span>
  544.  
  545.  
  546.         </div>
  547.  
  548.  
  549.  
  550.  
  551.  
  552.             <div class="activity-inner delete_star">
  553.  
  554.  
  555.                 <p><?php echo $check_content_loopss->content ; ?></p>
  556.  
  557.  
  558.             </div>
  559.  
  560.  
  561.             <style type="text/css">.delete_star .ratingtop{display:none}</style>
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.         <div class="activity-meta">
  571.  
  572.  
  573.             <?php if ( is_user_logged_in() && bp_activity_can_comment() ) : ?>
  574.  
  575.  
  576.                 <a href="<?php bp_activity_comment_link() ?>" class="acomment-reply" id="acomment-comment-<?php echo $depro_idcheck; ?>"><?php _e( 'Comment', 'buddypress' ) ?> (<span><?php bp_activity_comment_count() ?></span>)</a>
  577.  
  578.  
  579.             <?php endif; ?>
  580.  
  581.  
  582.  
  583.  
  584.  
  585.             <?php do_action( 'bp_activity_entry_meta' ) ?>
  586.  
  587.  
  588.         </div>
  589.  
  590.  
  591.     </div>
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.         <div class="activity-comments">
  601.  
  602.  
  603.  
  604.  
  605.  
  606.             <?php bp_activity_comments(); ?>
  607.  
  608.  
  609.  
  610.  
  611.  
  612.             <?php if ( is_user_logged_in() ) : ?>
  613.  
  614.  
  615.  
  616.  
  617.  
  618.                 <form action="<?php bp_activity_comment_form_action(); ?>" method="post" id="ac-form-<?php echo $depro_idcheck; ?>" class="ac-form"<?php bp_activity_comment_form_nojs_display(); ?>>
  619.  
  620.  
  621.                     <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=' . BP_AVATAR_THUMB_WIDTH . '&height=' . BP_AVATAR_THUMB_HEIGHT ); ?></div>
  622.  
  623.  
  624.                     <div class="ac-reply-content">
  625.  
  626.  
  627.                         <div class="ac-textarea">
  628.  
  629.  
  630.                             <textarea id="ac-input-<?php echo $depro_idcheck; ?>" class="ac-input" name="ac_input_<?php echo $depro_idcheck; ?>"></textarea>
  631.  
  632.  
  633.                         </div>
  634.  
  635.  
  636.                         <input type="submit" name="ac_form_submit" value="<?php _e( 'Post', 'buddypress' ); ?>" /> &nbsp; <?php _e( 'or press esc to cancel.', 'buddypress' ); ?>
  637.  
  638.  
  639.                         <input type="hidden" name="comment_form_id" value="<?php echo $depro_idcheck; ?>" />
  640.  
  641.  
  642.                     </div>
  643.  
  644.  
  645.  
  646.  
  647.  
  648.                     <?php do_action( 'bp_activity_entry_comments' ); ?>
  649.  
  650.  
  651.  
  652.  
  653.  
  654.                     <?php wp_nonce_field( 'new_activity_comment', '_wpnonce_new_activity_comment' ); ?>
  655.  
  656.  
  657.  
  658.  
  659.  
  660.                 </form>
  661.  
  662.  
  663.  
  664.  
  665.  
  666.             <?php endif; ?>
  667.  
  668.  
  669.  
  670.  
  671.  
  672.         </div>
  673.  
  674.  
  675.  
  676.  
  677.  
  678.     </li>
  679.  
  680.  
  681.  
  682.  
  683.  
  684.     <?php endwhile; ?>
  685.  
  686.  
  687. <?php endif; ?>
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696. <?php
  697.  
  698.  
  699.         endforeach;
  700.  
  701.  
  702.  
  703.  
  704.  
  705. ?>
  706.  
  707.  
  708.     </ul>
  709.  
  710.  
  711.     </div>
  712.     <?php wp_redirect( home_url() ); exit; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement