function prepare_wsr($widget, $template) { global $gdsr; $bayesian_calculated = !(strpos($template, "%BAYES_") === false); $t_rate = !(strpos($template, "%RATE_TREND%") === false); $t_vote = !(strpos($template, "%VOTE_TREND%") === false); $a_name = !(strpos($template, "%AUTHOR_NAME%") === false); $a_link = !(strpos($template, "%AUTHOR_LINK%") === false); if ($widget["column"] == "bayes" && !$bayesian_calculated) { $widget["column"] == "rating"; } $all_rows = GDSRRenderT2::prepare_data_retrieve($widget, $gdsr->o["bayesian_minimal"]); if (count($all_rows) > 0) { $trends = array(); $trends_calculated = false; if ($t_rate || $t_vote) { $idx = array(); foreach ($all_rows as $row) { switch ($widget["grouping"]) { case "post": $id = $row->post_id; break; case "category": $id = $row->term_id; break; case "user": $id = $row->id; break; } $idx[] = $id; } $trends = GDSRX::get_trend_calculation(join(", ", $idx), $widget["grouping"], $widget['show'], $gdsr->o["trend_last"], $gdsr->o["trend_over"], $widget['source'], $widget['source_set']); $trends_calculated = true; } $stars = $gdsr->o["stars"]; $review_stars = $gdsr->o["review_stars"]; if ($widget["source"] == "multis") { $set = wp_gdget_multi_set($widget["source_set"]); $stars = $review_stars = $set->stars; } $new_rows = array(); foreach ($all_rows as $row) { if ($widget["image_from"] == "content") { $row->image = gdFunctionsGDSR::get_image_from_text($row->post_content); } else { if ($widget["image_from"] == "custom") { $row->image = get_post_meta($row->post_id, $widget["image_custom"], true); } else { $row->image = ""; } } $row->image = apply_filters('gdsr_widget_image_url_prepare', $row->image, $widget, $row); if ($row->image != "" && intval($widget["image_resize_x"]) > 0 && intval($widget["image_resize_y"]) > 0) { $row->image = GDSRRenderT2::prepare_image($row->image, $widget["image_resize_x"], $widget["image_resize_y"]); } $row->votes_plus = 0; $row->votes_minus = 0; if ($widget['source'] == "thumbs") { if ($widget['show'] == "total") { $row->votes = $row->rating = $row->user_recc_plus - $row->user_recc_minus + $row->visitor_recc_plus - $row->visitor_recc_minus; $row->voters = $row->user_recc_plus + $row->user_recc_minus + $row->visitor_recc_plus + $row->visitor_recc_minus; $row->votes_plus = $row->user_recc_plus + $row->visitor_recc_plus; $row->votes_minus = $row->user_recc_minus + $row->visitor_recc_minus; } if ($widget['show'] == "visitors") { $row->votes = $row->rating = $row->visitor_recc_plus - $row->visitor_recc_minus; $row->voters = $row->visitor_recc_plus + $row->visitor_recc_minus; $row->votes_plus = $row->visitor_recc_plus; $row->votes_minus = $row->visitor_recc_minus; } if ($widget['show'] == "users") { $row->votes = $row->rating = $row->user_recc_plus - $row->user_recc_minus; $row->voters = $row->user_recc_plus + $row->user_recc_minus; $row->votes_plus = $row->user_recc_plus; $row->votes_minus = $row->user_recc_minus; } $row->bayesian = -1; } else { 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; } $row->rating = $row->voters == 0 ? 0 : @number_format($row->votes / $row->voters, 1); $row->review = $row->review == 0 ? 0 : @number_format($row->review / $row->counter, 1); $row->bayesian = $bayesian_calculated ? $gdsr->bayesian_estimate($row->voters, $row->rating, $stars) : -1; } $new_rows[] = $row; } $set_rating = $set_voting = null; if ($trends_calculated) { $set_rating = $gdsr->g->find_trend($widget["trends_rating_set"]); $set_voting = $gdsr->g->find_trend($widget["trends_voting_set"]); } $all_rows = array(); foreach ($new_rows as $row) { $row->rating_stars = $row->bayesian_stars = $row->rating_thumb = $row->review_stars = ""; if (strlen($row->title) > $widget["tpl_title_length"] - 3 && $widget["tpl_title_length"] > 0) { $row->title = substr($row->title, 0, $widget["tpl_title_length"] - 3) . " ..."; } $row->content = GDSRRenderT2::prepare_content($row); $row->excerpt = GDSRRenderT2::prepare_excerpt($widget["excerpt_words"], $row); $row->content = apply_filters('gdsr_widget_post_content', $row->content, $row, $widget); $row->excerpt = apply_filters('gdsr_widget_post_excerpt', $row->excerpt, $row, $widget); $row->title = apply_filters('gdsr_widget_post_title', $row->title, $row, $widget); if ($a_link || $a_name && intval($row->author) > 0) { $user = get_userdata($row->author); $row->author_name = $user->display_name; $row->author_url = get_author_posts_url(intval($row->author)); } else { $row->author_name = ""; $row->author_url = ""; } if ($trends_calculated) { $empty = $gdsr->e; switch ($widget["grouping"]) { case "post": $id = $row->post_id; break; case "taxonomy": case "category": $id = $row->term_id; break; case "user": $id = $row->id; break; } $t = $trends[$id]; switch ($widget["trends_rating"]) { case "img": $rate_url = is_null($set_rating) ? "" : $set_rating->get_url(); $image_loc = "center"; switch ($t->trend_rating) { case -1: $image_loc = "bottom"; break; case 0: $image_loc = "center"; break; case 1: $image_loc = "top"; break; } $image_bg = sprintf('background: url(%s) %s no-repeat; height: %spx; width: %spx;', $rate_url, $image_loc, $set_rating->size, $set_rating->size); $row->item_trend_rating = sprintf('<img class="trend" src="%s" style="%s" width="%s" height="%s"></img>', $gdsr->e, $image_bg, $set_rating->size, $set_rating->size); break; case "txt": switch ($t->trend_rating) { case -1: $row->item_trend_rating = $widget["trends_rating_fall"]; break; case 0: $row->item_trend_rating = $widget["trends_rating_same"]; break; case 1: $row->item_trend_rating = $widget["trends_rating_rise"]; break; } break; } switch ($widget["trends_voting"]) { case "img": $vote_url = is_null($set_voting) ? "" : $set_voting->get_url(); $image_loc = "center"; switch ($t->trend_voting) { case -1: $image_loc = "bottom"; break; case 0: $image_loc = "center"; break; case 1: $image_loc = "top"; break; } $image_bg = sprintf('background: url(%s) %s no-repeat; height: %spx; width: %spx;', $vote_url, $image_loc, $set_voting->size, $set_voting->size); $row->item_trend_voting = sprintf('<img class="trend" src="%s" style="%s" width="%s" height="%s"></img>', $gdsr->e, $image_bg, $set_voting->size, $set_voting->size); break; case "txt": switch ($t->trend_voting) { case -1: $row->item_trend_voting = $widget["trends_voting_fall"]; break; case 0: $row->item_trend_voting = $widget["trends_voting_same"]; break; case 1: $row->item_trend_voting = $widget["trends_voting_rise"]; break; } break; } } switch ($widget["grouping"]) { case "post": $row->permalink = get_permalink($row->post_id); break; case "taxonomy": $row->permalink = get_term_link($row->slug, $widget["taxonomy"]); break; case "category": $row->permalink = get_category_link($row->term_id); break; case "user": $row->permalink = get_author_posts_url(intval($row->id)); break; } if ($widget["source"] == "thumbs") { if (!(strpos($template, "%THUMB%") === false)) { $row->rating_thumb = GDSRRender::render_static_thumb($widget['rating_thumb'], $widget['rating_thumb_size'], $row->rating); } } else { if (!(strpos($template, "%STARS%") === false)) { $row->rating_stars = GDSRRender::render_static_stars($widget['rating_stars'], $widget['rating_size'], $stars, $row->rating); } if (!(strpos($template, "%BAYES_STARS%") === false) && $row->bayesian > -1) { $row->bayesian_stars = GDSRRender::render_static_stars($widget['rating_stars'], $widget['rating_size'], $stars, $row->bayesian); } } if (!(strpos($template, "%REVIEW_STARS%") === false) && $row->review > -1) { $row->review_stars = GDSRRender::render_static_stars($widget['review_stars'], $widget['review_size'], $review_stars, $row->review); } $all_rows[] = $row; } } if ($widget["column"] == "votes") { $widget["column"] = "voters"; } if ($widget["column"] == "post_title") { $widget["column"] = "title"; } if ($widget["column"] == "count") { $widget["column"] = "counter"; } if ($widget["column"] == "bayes") { $widget["column"] = "bayesian"; } if ($widget["column"] == "id") { $widget["column"] = "post_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); $tr_class = "odd"; $all_rows = array(); foreach ($sort->sorted as $row) { $row->table_row_class = $tr_class; $tr_class = $tr_class == "odd" ? "even" : "odd"; $all_rows[] = $row; } $all_rows = apply_filters("gdsr_widget_data_prepare", $all_rows); return $all_rows; }