Example #1
0
    function render_dash_widget_vote($data, $cls = "", $id = "")
    {
        global $userdata, $gdsr;
        $user_level = intval($userdata->user_level);
        echo '<div id="gdsr-latest-votes' . $id . '"' . ($cls != "" ? ' class="' . $cls . '"' : '') . '>';
        $first = true;
        $tr_class = "";
        foreach ($data as $row) {
            $user = $row->user_id == 0 ? __("visitor", "gd-star-rating") : $row->display_name;
            $voteon = $votevl = $loguser = $pocmlog = $postlog = "";
            if ($row->vote_type == "artthumb" || $row->vote_type == "cmmthumb") {
                $votevl = __("Thumb", "gd-star-rating") . " <strong>" . ($row->vote > 0 ? "UP" : "DOWN") . "</strong> ";
            } else {
                if ($row->vote_type == "multis") {
                    $voteval = intval($row->vote) / 10;
                    if ($row->vote == 0) {
                        $set = wp_gdget_multi_set($row->multi_id);
                        $voteval = GDSRDBMulti::get_multi_rating_from_single_object($set, unserialize($row->object));
                    }
                    $votevl = __("Multi Vote", "gd-star-rating") . " <strong>" . $voteval . "</strong> ";
                } else {
                    $votevl = __("Vote", "gd-star-rating") . " <strong>" . $row->vote . "</strong> ";
                }
            }
            if ($row->vote_type == "article" || $row->vote_type == "artthumb" || $row->vote_type == "multis") {
                $post = get_post($row->id);
                $voteon = '<a href="' . get_permalink($post->ID) . '"><span style="color: #2683AE">' . $post->post_title . '</span></a>';
                $pocmlog = sprintf("admin.php?page=gd-star-rating-stats&gdsr=voters&pid=%s&vt=%s&vg=total", $row->id, $row->vote_type);
                $pocmlog = sprintf('<a href="%s">%s</a>', $pocmlog, __("post", "gd-star-rating"));
            } else {
                $comment = get_comment($row->id);
                $post = get_post($comment->comment_post_ID);
                $voteon = ' <a href="' . get_comment_link($comment) . '">' . __("comment", "gd-star-rating") . '</a> ' . __("for", "gd-star-rating") . ' <a href="' . get_permalink($post->ID) . '"><span style="color: #2683AE">' . $post->post_title . '</span></a>';
                $pocmlog = sprintf("admin.php?page=gd-star-rating-stats&gdsr=voters&pid=%s&vt=%s&vg=total", $row->id, $row->vote_type);
                $pocmlog = sprintf('<a href="%s">%s</a>', $pocmlog, __("comment", "gd-star-rating"));
                $pctype = $row->vote_type == "comment" ? "article" : "artthumb";
                $postlog = sprintf("admin.php?page=gd-star-rating-stats&gdsr=voters&pid=%s&vt=%s&vg=total", $comment->comment_post_ID, $pctype);
                $postlog = sprintf('<a href="%s">%s</a>', $postlog, __("post", "gd-star-rating"));
            }
            if ($row->user_id == 0) {
                $loguser = sprintf("admin.php?page=gd-star-rating-users&gdsr=userslog&ui=0&vt=%s&un=Visitor", $row->vote_type);
                $loguser = sprintf('<a href="%s">%s</a>', $loguser, __("visitors", "gd-star-rating"));
            } else {
                $loguser = sprintf("admin.php?page=gd-star-rating-users&gdsr=userslog&ui=%s&vt=%s&un=%s", $row->user_id, $row->vote_type, $row->display_name);
                $loguser = sprintf('<a href="%s">%s</a>', $loguser, __("user", "gd-star-rating"));
            }
            ?>

            <div class="gdsr-latest-item<?php 
            echo $tr_class;
            echo $first ? " first" : "";
            echo $row->user_id > 0 ? " user" : "";
            ?>
">
                <?php 
            echo get_avatar($row->user_email, 32);
            ?>
                <h5><?php 
            echo '<span style="color: #CC0000">' . $votevl . '</span>';
            _e("from", "gd-star-rating");
            ?>
 <strong style="color: <?php 
            echo $row->user_id == 0 ? "blue" : "green";
            ?>
"><?php 
            echo $user;
            ?>
</strong> <?php 
            _e("on", "gd-star-rating");
            ?>
 <?php 
            echo $voteon;
            ?>
</h5>
                <p class="datx"><?php 
            echo $row->voted;
            ?>
</p>
                <p class="linx">
                    <?php 
            if ($user_level >= intval($gdsr->o["security_showip_user_level"])) {
                ?>
                    <strong><?php 
                _e("ip", "gd-star-rating");
                ?>
:</strong> <span style="color: blue"><?php 
                echo $row->ip;
                ?>
</span> |
                    <?php 
            }
            ?>
                    <strong><?php 
            _e("log", "gd-star-rating");
            ?>
:</strong> <?php 
            echo $loguser;
            ?>
, <?php 
            echo $pocmlog;
            if ($postlog != "") {
                echo ", ";
            }
            echo $postlog;
            ?>
                </p>
                <div class="clear"></div>
            </div>

            <?php 
            $tr_class = $tr_class == "" ? " alter" : "";
            $first = false;
        }
        echo '</div>';
    }
Example #2
0
 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"]);
             }
             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;
                 }
                 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;
                 }
                 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->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;
         }
         $tr_class = "odd";
         $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->table_row_class = $tr_class;
             $row->rating_stars = $row->bayesian_stars = $row->rating_thumb = $row->review_stars = "";
             $row->excerpt = GDSRRenderT2::prepare_excerpt($widget["excerpt_words"], $row);
             $row->excerpt = apply_filters('gdsr_widget_post_excerpt', $row->excerpt);
             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->title = apply_filters('gdsr_widget_post_title', $row->title);
             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'], $stars, $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);
             }
             if ($tr_class == "odd") {
                 $tr_class = "even";
             } else {
                 $tr_class = "odd";
             }
             $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);
     $all_rows = apply_filters("gdsr_widget_data_prepare", $sort->sorted);
     return $all_rows;
 }
 function render_article_rss()
 {
     global $post;
     $rd_post_id = intval($post->ID);
     $post_data = GDSRDatabase::get_post_data($rd_post_id);
     $template_id = $this->g->o["default_ssb_template"];
     $votes = $score = 0;
     $stars = 10;
     if ($this->g->o["rss_datasource"] == "thumbs") {
         if ($rules_articles == "A" || $rules_articles == "N") {
             $votes = $post_data->user_recc_plus + $post_data->user_recc_minus + $post_data->visitor_recc_plus + $post_data->visitor_recc_minus;
             $score = $post_data->user_recc_plus - $post_data->user_recc_minus + $post_data->visitor_recc_plus - $post_data->visitor_recc_minus;
         } else {
             if ($rules_articles == "V") {
                 $votes = $post_data->visitor_recc_plus + $post_data->visitor_recc_minus;
                 $score = $post_data->visitor_recc_plus - $post_data->visitor_recc_minus;
             } else {
                 $votes = $post_data->user_recc_plus + $post_data->user_recc_minus;
                 $score = $post_data->user_recc_plus - $post_data->user_recc_minus;
             }
         }
     } else {
         if ($this->g->o["rss_datasource"] == "standard") {
             $stars = $this->g->o["stars"];
             if ($post_data->rules_articles == "A" || $post_data->rules_articles == "N") {
                 $votes = $post_data->user_voters + $post_data->visitor_voters;
                 $score = $post_data->user_votes + $post_data->visitor_votes;
             } else {
                 if ($post_data->rules_articles == "V") {
                     $votes = $post_data->visitor_voters;
                     $score = $post_data->visitor_votes;
                 } else {
                     $votes = $post_data->user_voters;
                     $score = $post_data->user_votes;
                 }
             }
         } else {
             $data = gdsrBlgDB::get_rss_multi_data($post_id);
             if (count($row) > 0) {
                 $set = wp_gdget_multi_set($data->multi_id);
                 $stars = $set->stars;
                 if ($post_data->rules_articles == "A" || $post_data->rules_articles == "N") {
                     $sum = $data->average_rating_users * $data->total_votes_users + $data->average_rating_visitors * $data->total_votes_visitors;
                     $votes = $data->total_votes_visitors + $data->total_votes_users;
                     $score = number_format($votes == 0 ? 0 : $sum / $votes, 1);
                 } else {
                     if ($post_data->rules_articles == "V") {
                         $votes = $data->total_votes_visitors;
                         $score = $data->average_rating_visitors;
                     } else {
                         $votes = $data->total_votes_users;
                         $score = $data->average_rating_users;
                     }
                 }
             }
         }
     }
     $rating_block = GDSRRenderT2::render_ssb($template_id, array("post_id" => $rd_post_id, "votes" => $votes, "score" => $score, "unit_count" => $stars, "header_text" => $this->g->o["rss_header_text"], "type" => $this->g->o["rss_datasource"]));
     return $rating_block;
 }
Example #4
0
 function add_to_log($post_id, $set_id, $user_id, $ip, $ua, $values, $comment_id = 0)
 {
     global $wpdb, $table_prefix;
     $set = wp_gdget_multi_set($set_id);
     $vote = intval(GDSRDBMulti::get_multi_rating_from_single_object($set, $values) * 10);
     $modsql = sprintf("INSERT INTO %sgdsr_votes_log (id, vote_type, multi_id, user_id, vote, object, voted, ip, user_agent, comment_id) VALUES (%s, 'multis', %s, %s, %s, '%s', '%s', '%s', '%s', %s)", $table_prefix, $post_id, $set_id, $user_id, $vote, serialize($values), str_replace("'", "''", current_time('mysql')), $ip, $ua, $comment_id);
     wp_gdsr_dump("LOG", $modsql);
     $wpdb->query($modsql);
 }