Example #1
0
 function get_trend_calculation($ids, $grouping = "post", $show = "total", $last = 1, $over = 30, $source = "article", $multi_id = 0)
 {
     global $wpdb, $table_prefix;
     $data_over = $data_last = $votes_over = $voters_over = array();
     $data_last = GDSRX::get_trend_data($ids, $grouping, $source, "last", $last, $over, $multi_id);
     $data_over = GDSRX::get_trend_data($ids, $grouping, $source, "over", $last, $over, $multi_id);
     if (count($data_last) == 0) {
         $votes_last = $voters_last = array();
     }
     if (count($data_over) == 0) {
         $votes_over = $voters_over = array();
     }
     for ($i = 0; $i < count($data_over); $i++) {
         $row_over = $data_over[$i];
         if ($show == "total") {
             $votes_over[$row_over->id] = $row_over->user_votes + $row_over->visitor_votes;
             $voters_over[$row_over->id] = $row_over->user_voters + $row_over->visitor_voters;
         }
         if ($show == "visitors") {
             $votes_over[$row_over->id] = $row_over->visitor_votes;
             $voters_over[$row_over->id] = $row_over->visitor_voters;
         }
         if ($show == "users") {
             $votes_over[$row_over->id] = $row_over->user_votes;
             $voters_over[$row_over->id] = $row_over->user_voters;
         }
     }
     for ($i = 0; $i < count($data_last); $i++) {
         $row_last = $data_last[$i];
         if ($show == "total") {
             $votes_last[$row_last->id] = $row_last->user_votes + $row_last->visitor_votes;
             $voters_last[$row_last->id] = $row_last->user_voters + $row_last->visitor_voters;
         }
         if ($show == "visitors") {
             $votes_last[$row_last->id] = $row_last->visitor_votes;
             $voters_last[$row_last->id] = $row_last->visitor_voters;
         }
         if ($show == "users") {
             $votes_last[$row_last->id] = $row_last->user_votes;
             $voters_last[$row_last->id] = $row_last->user_voters;
         }
     }
     foreach ($votes_last as $key => $value) {
         if (!isset($votes_over[$key])) {
             $votes_over[$key] = $voters_over[$key] = 0;
         }
     }
     foreach ($votes_over as $key => $value) {
         if (!isset($votes_last[$key])) {
             $votes_last[$key] = $voters_last[$key] = 0;
         }
     }
     $trends = array();
     foreach ($votes_last as $key => $value) {
         $trends[$key] = new TrendValue($votes_last[$key], $voters_last[$key], $votes_over[$key], $voters_over[$key], $last, $over);
     }
     return $trends;
 }
Example #2
0
 function prepare_wcr($widget, $template)
 {
     global $gdsr, $wpdb;
     $post_id = $gdsr->widget_post_id;
     $sql = GDSRX::get_widget_comments($widget, $post_id);
     $all_rows = $wpdb->get_results($sql);
     if (count($all_rows) > 0) {
         $new_rows = array();
         foreach ($all_rows as $row) {
             if ($widget['show'] == "total") {
                 $row->votes = $row->user_votes + $row->visitor_votes;
                 $row->voters = $row->user_voters + $row->visitor_voters;
             }
             if ($widget['show'] == "visitors") {
                 $row->votes = $row->visitor_votes;
                 $row->voters = $row->visitor_voters;
             }
             if ($widget['show'] == "users") {
                 $row->votes = $row->user_votes;
                 $row->voters = $row->user_voters;
             }
             if ($row->voters == 0) {
                 $row->rating = 0;
             } else {
                 $row->rating = @number_format($row->votes / $row->voters, 1);
             }
             $new_rows[] = $row;
         }
         $tr_class = "odd";
         $all_rows = array();
         $pl = get_permalink($post_id);
         foreach ($new_rows as $row) {
             $row->table_row_class = $tr_class;
             $row->comment_content = strip_tags($row->comment_content);
             if (strlen($row->comment_content) > $widget["text_max"] - 3 && $widget["text_max"] > 0) {
                 $row->comment_content = substr($row->comment_content, 0, $widget["text_max"] - 3) . " ...";
             }
             $row->comment_content = apply_filters('gdsr_comments_widget_comment_content', $row->comment_content);
             $row->comment_author_email = get_avatar($row->comment_author_email, $widget["avatar"]);
             if (!(strpos($template, "%CMM_STARS%") === false)) {
                 $row->rating_stars = GDSRRender::render_static_stars($widget['rating_stars'], $widget['rating_size'], $gdsr->o["cmm_stars"], $row->rating);
             }
             $row->permalink = $pl . "#comment-" . $row->comment_id;
             if ($tr_class == "odd") {
                 $tr_class = "even";
             } else {
                 $tr_class = "odd";
             }
             $all_rows[] = $row;
         }
     }
     if ($widget["column"] == "votes") {
         $widget["column"] = "voters";
     }
     if ($widget["column"] == "id") {
         $widget["column"] = "comment_id";
     }
     $properties = array();
     $properties[] = array("property" => $widget["column"], "order" => $widget["order"]);
     if ($widget["column"] == "rating") {
         $properties[] = array("property" => "voters", "order" => $widget["order"]);
     }
     $sort = new gdSortObjectsArrayGDSR($all_rows, $properties);
     $all_rows = $sort->sorted;
     $all_rows = apply_filters('gdsr_comments_widget_data_prepare', $all_rows);
     return $all_rows;
 }