Exemplo n.º 1
0
 function delete_votes($ids, $delete, $ids_array)
 {
     global $wpdb, $table_prefix;
     $dbt_data_article = $table_prefix . 'gdsr_data_article';
     $dbt_data_comment = $table_prefix . 'gdsr_data_comment';
     $dbt_votes_log = $table_prefix . 'gdsr_votes_log';
     if ($delete == "") {
         return;
     }
     $delstring = "";
     $dellog = "";
     switch (substr($delete, 1, 1)) {
         case "A":
             $delstring = "user_votes = 0, user_voters = 0, visitor_votes = 0, visitor_voters = 0";
             break;
         case "V":
             $delstring = "visitor_votes = 0, visitor_voters = 0";
             $dellog = " and user_id = 0";
             break;
         case "U":
             $delstring = "user_votes = 0, user_voters = 0";
             $dellog = " and user_id > 0";
             break;
         default:
             return;
             break;
     }
     if (substr($delete, 0, 1) == "A") {
         $wpdb->query(sprintf("update %s set %s where post_id in %s", $dbt_data_article, $delstring, $ids));
         $wpdb->query(sprintf("delete from %s where vote_type = 'article' and id in %s%s", $dbt_votes_log, $ids, $dellog));
     } else {
         if (substr($delete, 0, 1) == "K") {
             $wpdb->query(sprintf("update %s set %s where comment_id in %s", $dbt_data_comment, $delstring, $ids));
             $wpdb->query(sprintf("delete from %s where vote_type = 'comment' and id in %s%s", $dbt_votes_log, $ids, $dellog));
         } else {
             if (substr($delete, 0, 1) == "C") {
                 $cids = GDSRDatabase::get_commentids_posts($ids);
                 $cm = array();
                 foreach ($cids as $cid) {
                     $cm[] = $cid->comment_id;
                 }
                 $cms = "(" . join(", ", $cm) . ")";
                 $wpdb->query(sprintf("update %s set %s where post_id in %s", $dbt_data_comment, $delstring, $ids));
                 $wpdb->query(sprintf("delete from %s where vote_type = 'comment' and id in %s%s", $dbt_votes_log, $cms, $dellog));
             } else {
                 return;
             }
         }
     }
 }