/wp-content/plugins/gd-star-rating/code/class.php
PHP | 2124 lines | 1646 code | 257 blank | 221 comment | 630 complexity | 13e7bd90d8850d0c6576f5a3a276fd18 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Main plugin class
- */
- class GDStarRating {
- var $is_bot = false;
- var $is_ban = false;
- var $is_ie6 = false;
- var $is_cached = false;
- var $is_update = false;
- var $security_level = 9;
- var $security_level_front = 1;
- var $security_level_builder = 1;
- var $security_level_setup = 9;
- var $security_my_ratings = false;
- var $security_my_ratings_level = 0;
- var $security_users = '0';
- var $is_cached_integration_std = false;
- var $is_cached_integration_mur = false;
- var $use_nonce = true;
- var $extra_folders = false;
- var $safe_mode = false;
- var $widget_post_id;
- var $cats_data_posts = array();
- var $cats_data_cats = array();
- var $wp_access_level = 0;
- var $wp_secure_level = false;
- var $wpr8_available = false;
- var $admin_plugin = false;
- var $admin_plugin_page = '';
- var $admin_page;
- var $script;
- var $widgets;
- var $active_wp_page;
- var $wp_version;
- var $vote_status;
- var $rendering_sets = null;
- var $override_readonly_standard = false;
- var $override_readonly_multis = false;
- var $tables_list;
- var $plugin_base;
- var $plugin_url;
- var $plugin_ajax;
- var $plugin_path;
- var $plugin_xtra_url;
- var $plugin_xtra_path;
- var $plugin_chart_url;
- var $plugin_chart_path;
- var $plugin_cache_path;
- var $plugin_wpr8_path;
- var $post_comment;
- var $wpr8;
- var $l; // language
- var $o; // options
- var $w; // widget options
- var $p; // post data
- var $i; // import
- var $g; // gfx object
- var $q; // query object
- var $c; // cached post ids
- var $f; // front end rendering object
- var $m; // admin menus object
- var $v; // ajax votes saving object
- var $s; // shared objects functions
- var $qc;
- var $rSnippets;
- var $ginc;
- var $bots;
- var $shortcodes;
- var $stars_sizes;
- var $thumb_sizes;
- var $function_restrict;
- var $default_shortcode_starrating;
- var $default_shortcode_starratingmulti;
- var $default_shortcode_starreviewmulti;
- var $default_shortcode_starcomments;
- var $default_shortcode_starrater;
- var $default_shortcode_starthumbsblock;
- var $default_shortcode_starreview;
- var $default_user_ratings_filter;
- var $default_options;
- var $default_import;
- var $default_widget_comments;
- var $default_widget_top;
- var $default_widget;
- var $default_spider_bots;
- var $default_wpr8;
- /**
- * Constructor method
- */
- function GDStarRating($base_path, $base_file) {
- $this->tabpage = "front";
- $this->plugin_path = $base_path."/";
- $this->plugin_base = $base_file;
- $gdd = new GDSRDefaults();
- $this->default_options = $gdd->default_options;
- $this->shortcodes = $gdd->shortcodes;
- $this->stars_sizes = $gdd->stars_sizes;
- $this->thumb_sizes = $gdd->thumb_sizes;
- $this->tables_list = $gdd->tables_list;
- $this->function_restrict = $gdd->function_restrict;
- $this->default_spider_bots = $gdd->default_spider_bots;
- $this->default_wpr8 = $gdd->default_wpr8;
- $this->default_user_ratings_filter = $gdd->default_user_ratings_filter;
- $this->default_import = $gdd->default_import;
- $this->default_widget_comments = $gdd->default_widget_comments;
- $this->default_widget_top = $gdd->default_widget_top;
- $this->default_widget = $gdd->default_widget;
- $this->default_shortcode_starrating = $gdd->default_shortcode_starrating;
- $this->default_shortcode_starratingmulti = $gdd->default_shortcode_starratingmulti;
- $this->default_shortcode_starreviewmulti = $gdd->default_shortcode_starreviewmulti;
- $this->default_shortcode_starcomments = $gdd->default_shortcode_starcomments;
- $this->default_shortcode_starrater = $gdd->default_shortcode_starrater;
- $this->default_shortcode_starthumbsblock = $gdd->default_shortcode_starthumbsblock;
- $this->default_shortcode_starreview = $gdd->default_shortcode_starreview;
- $this->function_restrict = $gdd->function_restrict;
- define("STARRATING_INSTALLED", $this->default_options["version"]." ".$this->default_options["status"]);
- define("STARRATING_EOL", "\r\n");
- $this->c = array();
- $this->plugin_path_url();
- if ($this->wp_version > 29) {
- $this->default_widget["select"] = "post";
- }
- $this->install_plugin();
- if (!GDSR_WP_ADMIN) {
- if (!STARRATING_AJAX) {
- $google_rspf = isset($this->o["google_rich_snippets_format"]) ? $this->o["google_rich_snippets_format"] : "microformat";
- $this->q = new gdsrQuery();
- $this->rSnippets = new gdGoogleRichSnippetsGDSR($google_rspf);
- } else {
- $this->v = new gdsrVotes($this);
- }
- $this->f = new gdsrFront($this);
- } else {
- $this->m = new gdsrMenus($this);
- }
- $this->s = new gdsrShared($this);
- if (!STARRATING_AJAX) {
- $this->actions_filters();
- $this->initialize_security();
- }
- if ($this->o["ajax_jsonp"] == 1) $this->plugin_ajax.= "?callback=?";
- $this->is_cached = $this->o["cache_active"];
- $this->use_nonce = $this->o["use_nonce"] == 1;
- define("STARRATING_VERSION", $this->o["version"].'_'.$this->o["build"]);
- define("STARRATING_DEBUG_ACTIVE", $this->o["debug_active"]);
- define("STARRATING_STARS_GENERATOR", $this->o["gfx_generator_auto"] == 0 ? "DIV" : "GFX");
- define('STARRATING_AJAX_URL', $this->plugin_ajax);
- define('STARRATING_ENCODING', $this->o["encoding"]);
- }
- function get($name) {
- return $this->o[$name];
- }
- function set($name, $value, $save = true) {
- $this->o[$name] = $value;
- if ($save) update_option('gd-star-rating', $this->o);
- }
- /**
- * Initialize security variables based on the gdsr-config.php file
- */
- function initialize_security() {
- if (defined('STARRATING_ACCESS_LEVEL')) $this->security_level = STARRATING_ACCESS_LEVEL;
- if (defined('STARRATING_ACCESS_LEVEL_FRONT')) $this->security_level_front = STARRATING_ACCESS_LEVEL_FRONT;
- if (defined('STARRATING_ACCESS_LEVEL_BUILDER')) $this->security_level_builder = STARRATING_ACCESS_LEVEL_BUILDER;
- if (defined('STARRATING_ACCESS_LEVEL_SETUP')) $this->security_level_setup = STARRATING_ACCESS_LEVEL_SETUP;
- if (defined('STARRATING_ACCESS_ADMIN_USERIDS')) $this->security_users = STARRATING_ACCESS_ADMIN_USERIDS;
- if (defined('STARRATING_ACCESS_MY_RATINGS')) $this->security_my_ratings = STARRATING_ACCESS_MY_RATINGS;
- if (defined('STARRATING_ACCESS_MY_RATINGS_LEVEL')) $this->security_my_ratings_level = STARRATING_ACCESS_MY_RATINGS_LEVEL;
- }
- /**
- * Adds new button to tinyMCE editor toolbar
- *
- * @param mixed $buttons
- */
- function add_tinymce_button($buttons) {
- array_push($buttons, "separator", "StarRating");
- return $buttons;
- }
- /**
- * Adds plugin to tinyMCE editor
- *
- * @param mixed $plugin_array
- */
- function add_tinymce_plugin($plugin_array) {
- $plugin_array['StarRating'] = $this->plugin_url.'tinymce3/plugin.js';
- return $plugin_array;
- }
- // shortcodes
- /**
- * Adds shortcodes into WordPress instance
- *
- * @param string|array $scode one or more shortcode names
- */
- function shortcode_action($scode) {
- $sc_name = $scode;
- $sc_method = "shortcode_".$scode;
- if (is_array($scode)) {
- $sc_name = $scode["name"];
- $sc_method = $scode["method"];
- }
- add_shortcode(strtolower($sc_name), array(&$this, $sc_method));
- add_shortcode(strtoupper($sc_name), array(&$this, $sc_method));
- }
- /**
- * Code for StarRater shortcode implementation
- *
- * @param array $atts
- */
- function shortcode_starrater($atts = array()) {
- return $this->shortcode_starratingblock($atts);
- }
- /**
- * Code for StarThumbsBlock shortcode implementation
- *
- * @param array $atts
- */
- function shortcode_starthumbsblock($atts = array()) {
- global $userdata;
- $user_id = is_object($userdata) ? $userdata->ID : 0;
- $override = shortcode_atts($this->default_shortcode_starthumbsblock, $atts);
- if ($override["post"] == 0) global $post;
- else $post = get_post($override["post"]);
- $this->cache_posts($user_id);
- return $this->f->render_thumb_article($post, $userdata, $override);
- }
- /**
- * Code for StarRatingBlock shortcode implementation
- *
- * @param array $atts
- */
- function shortcode_starratingblock($atts = array()) {
- global $userdata;
- $user_id = is_object($userdata) ? $userdata->ID : 0;
- $this->cache_posts($user_id);
- $override = shortcode_atts($this->default_shortcode_starrater, $atts);
- if ($override["post"] == 0) global $post;
- else $post = get_post($override["post"]);
- return $this->f->render_article($post, $userdata, $override);
- }
- /**
- * Code for StarRating shortcode implementation
- *
- * @param array $atts
- */
- function shortcode_starrating($atts = array()) {
- $sett = shortcode_atts($this->default_shortcode_starrating, $atts);
- return GDSRRenderT2::render_srr($sett);
- }
- /**
- * Code for StarComments shortcode implementation
- *
- * @param array $atts
- */
- function shortcode_starcomments($atts = array()) {
- $sett = shortcode_atts($this->default_shortcode_starcomments, $atts);
- if ($sett["post"] == 0) {
- global $post;
- $sett["post"] = $post->ID;
- } else {
- $post = get_post($sett["post"]);
- }
- $rating = "";
- $sett["comments"] = $post->comment_count;
- if ($post->ID > 0) {
- $rows = gdsrBlgDB::get_comments_aggregation($sett["post"], $sett["show"]);
- $totel_comments = count($rows);
- $total_voters = 0;
- $total_votes = 0;
- $calc_rating = 0;
- foreach ($rows as $row) {
- switch ($sett["show"]) {
- default:
- case "total":
- $total_voters += $row->user_voters + $row->visitor_voters;
- $total_votes += $row->user_votes + $row->visitor_votes;
- break;
- case "users":
- $total_voters += $row->user_voters;
- $total_votes += $row->user_votes;
- break;
- case "visitors":
- $total_voters += $row->visitor_voters;
- $total_votes += $row->visitor_votes;
- break;
- }
- }
- if ($total_voters > 0) $calc_rating = $total_votes / $total_voters;
- $calc_rating = number_format($calc_rating, 1);
- $rating = GDSRRenderT2::render_car($sett["tpl"], array("votes" => $total_voters, "rating" => $calc_rating, "comments" => $sett["comments"], "star_style" => ($this->is_ie6 ? $this->o["cmm_aggr_style_ie6"] : $this->o["cmm_aggr_style"]), "star_size" => $this->o['cmm_aggr_size'], "star_max" => $this->o["cmm_stars"]));
- }
- return $rating;
- }
- /**
- * Code for StarReview shortcode implementation
- *
- * @param array $atts
- */
- function shortcode_starreview($atts = array()) {
- global $userdata;
- $user_id = is_object($userdata) ? $userdata->ID : 0;
- $this->cache_posts($user_id);
- $sett = shortcode_atts($this->default_shortcode_starreview, $atts);
- if ($sett["post"] == 0) {
- global $post;
- $sett["post"] = $post->ID;
- }
- $star_css = $sett["css"] != "" ? $sett["css"] : $this->o["review_class_block"];
- $star_style = $sett["style"] != "" ? $sett["style"] : $this->o["review_style"];
- $star_style_ie6 = $sett["style_ie6"] != "" ? $sett["style_ie6"] : $this->o["review_style_ie6"];
- $star_size = $sett["size"] != "" ? $sett["size"] : $this->o['review_size'];
- $post_data = wp_gdget_post($sett["post"]);
- $rating = is_object($post_data) ? $post_data->review : -1;
- $rating = $rating < 0 ? 0 : $rating;
- return GDSRRenderT2::render_rsb($sett["tpl"], array("rating" => $rating, "star_style" => $this->is_ie6 ? $star_style_ie6 : $star_style, "star_size" => $star_size, "star_max" => $this->o["review_stars"], "header_text" => $this->o["review_header_text"], "css" => $star_css));
- }
- /**
- * Code for StarReviewMulti shortcode implementation
- *
- * @param array $atts
- */
- function shortcode_starreviewmulti($atts = array()) {
- $settings = shortcode_atts($this->default_shortcode_starreviewmulti, $atts);
- $el_stars = $settings["element_stars"] != "" ? $settings["element_stars"] : $settings["style"];
- $el_size = $settings["element_size"] != "" ? $settings["element_size"] : $settings["size"];
- $post_id = $settings["post"];
- if ($post_id == 0) {
- global $post;
- $post_id = $post->ID;
- }
- $multi_id = $settings["id"] == 0 ? $this->o["mur_review_set"] : $settings["id"];
- $set = gd_get_multi_set($multi_id);
- if ($multi_id > 0 && $post_id > 0) {
- $vote_id = GDSRDBMulti::get_vote($post_id, $multi_id, count($set->object));
- $multi_data = GDSRDBMulti::get_values($vote_id, 'rvw');
- $votes = array();
- foreach ($multi_data as $md) {
- $single_vote = array();
- $single_vote["votes"] = 1;
- $single_vote["score"] = $md->user_votes;
- $single_vote["rating"] = $md->user_votes;
- $votes[] = $single_vote;
- }
- $avg_rating = GDSRDBMulti::get_multi_review_average($vote_id);
- return GDSRRenderT2::render_rmb($settings["tpl"], array("votes" => $votes, "star_factor" => $settings["factor"], "post_id" => $post_id, "set" => $set, "avg_rating" => $avg_rating, "style" => $el_stars, "size" => $el_size, "avg_style" => $settings["average_stars"], "avg_size" => $settings["average_size"]));
- }
- else return '';
- }
- /**
- * Code for StarRatingMulti shortcode implementation
- *
- * @param array $atts
- */
- function shortcode_starratingmulti($atts = array()) {
- if ($this->o["multis_active"] == 1) {
- global $post, $userdata;
- if (!isset($atts["style"]) && isset($atts["element_stars"]) && $atts["element_stars"] != "") $atts["style"] = $atts["element_stars"];
- if (!isset($atts["size"]) && isset($atts["element_size"]) && $atts["element_size"] != 0) $atts["size"] = $atts["element_size"];
- $settings = shortcode_atts($this->default_shortcode_starratingmulti, $atts);
- return $this->f->render_multi_rating($post, $userdata, $settings);
- } else return "";
- }
- // shortcodes
- // various rendering
- /**
- * Renders comment review stars for selected comment
- *
- * @param int $comment_id id of the comment you want displayed
- * @param bool $zero_render if set to false and $value is 0 then nothing will be rendered
- * @param bool $use_default rendering is using default rendering settings
- * @param string $style folder name of the stars set to use
- * @param int $size stars size 12, 20, 30, 46
- * @return string rendered stars for comment review
- */
- function display_comment_review($comment_id, $use_default = true, $style = "oxygen", $size = 20) {
- $review = wp_gdget_comment_review($comment_id);
- if ($review < 1) return "";
- else {
- if ($use_default) {
- $style = ($this->is_ie6 ? $this->o["cmm_review_style_ie6"] : $this->o["cmm_review_style"]);
- $size = $this->o["cmm_review_size"];
- }
- $stars = $this->o["cmm_review_stars"];
- return GDSRRender::render_static_stars($style, $size, $stars, $review);
- }
- }
- /**
- * Renders post review stars for selected post
- *
- * @param int $post_id id for the post you want review displayed
- * @param bool $zero_render if set to false and $value is 0 then nothing will be rendered
- * @param bool $use_default rendering is using default rendering settings
- * @param string $style folder name of the stars set to use
- * @param int $size stars size 12, 20, 30, 46
- * @return string rendered stars for article review
- */
- function display_article_review($post_id, $use_default = true, $style = "oxygen", $size = 20) {
- global $userdata;
- $user_id = is_object($userdata) ? $userdata->ID : 0;
- $this->cache_posts($user_id);
- if ($use_default) {
- $style = ($this->is_ie6 ? $this->o["review_style_ie6"] : $this->o["review_style"]);
- $size = $this->o["review_size"];
- }
- $stars = $this->o["review_stars"];
- $post_data = wp_gdget_post($post_id);
- $review = is_object($post_data) ? $post_data->review : -1;
- if ($review < 0) $review = 0;
- return GDSRRender::render_static_stars($style, $size, $stars, $review);
- }
- /**
- * Renders post review stars for selected post
- *
- * @param int $post_id id for the post you want review displayed
- * @param bool $zero_render if set to false and $value is 0 then nothing will be rendered
- * @param bool $use_default rendering is using default rendering settings
- * @param string $style folder name of the stars set to use
- * @param int $size stars size 12, 20, 30, 46
- * @return string rendered stars for article review
- */
- function display_multis_review($multi_id, $post_id, $use_default = true, $style = "oxygen", $size = 20) {
- if ($use_default) {
- $style = ($this->is_ie6 ? $this->o["review_style_ie6"] : $this->o["review_style"]);
- $size = $this->o["review_size"];
- }
- $set = gd_get_multi_set($multi_id);
- $stars = $set->stars;
- $review = GDSRDBMulti::get_review_avg($multi_id, $post_id);
- if ($review < 0) $review = 0;
- return GDSRRender::render_static_stars($style, $size, $stars, $review);
- }
- /**
- * Renders post rating stars for selected post
- *
- * @param int $post_id id for the post you want rating displayed
- * @param bool $zero_render if set to false and $value is 0 then nothing will be rendered
- * @param bool $use_default rendering is using default rendering settings
- * @param string $style folder name of the stars set to use
- * @param int $size stars size 12, 20, 30, 46
- * @return string rendered stars for article rating
- */
- function display_article_rating($post_id, $use_default = true, $style = "oxygen", $size = 20) {
- global $userdata;
- $user_id = is_object($userdata) ? $userdata->ID : 0;
- $this->cache_posts($user_id);
- if ($use_default) {
- $style = ($this->is_ie6 ? $this->o["style_ie6"] : $this->o["style"]);
- $size = $this->o["size"];
- }
- $stars = $this->o["stars"];
- $rating = $this->get_article_rating_simple($post_id);
- return GDSRRender::render_static_stars($style, $size, $stars, $rating);
- }
- /**
- * Renders single rating stars image with average rating for the multi rating post results from rating or review.
- *
- * @param int $post_id id of the post rating will be attributed to
- * @param bool $review if set to true average of review will be rendered
- * @param array $settings override settings for rendering the block
- */
- function get_multi_average_rendered($post_id, $settings = array()) {
- $sum = $votes = $rating = 0;
- if ($settings["id"] == "") $multi_id = $this->o["mur_review_set"];
- else $multi_id = $settings["id"];
- if ($multi_id > 0 && $post_id > 0) {
- $set = gd_get_multi_set($multi_id);
- $data = GDSRDBMulti::get_averages($post_id, $multi_id);
- if ($set != null && is_object($data)) {
- if ($settings["render"] == "review") {
- $review = GDSRRender::render_static_stars(($this->is_ie6 ? $this->o["mur_style_ie6"] : $this->o["mur_style"]), $this->o['mur_size'], $set->stars, $data->average_review);
- return $review;
- } else {
- switch ($settings["show"]) {
- case "visitors":
- $rating = $data->average_rating_visitors;
- break;
- case "users":
- $rating = $data->average_rating_users;
- break;
- case "total":
- $sum = $data->average_rating_users * $data->total_votes_users + $data->average_rating_visitors * $data->total_votes_visitors;
- $votes = $data->total_votes_users + $data->total_votes_visitors;
- $rating = number_format($votes == 0 ? 0 : $sum / $votes, 1);
- break;
- }
- $rating = GDSRRender::render_static_stars(($this->is_ie6 ? $this->o["mur_style_ie6"] : $this->o["mur_style"]), $this->o['mur_size'], $set->stars, $rating);
- return $rating;
- }
- }
- }
- $max = is_null($set) ? 10 : $set->stars;
- $rating = GDSRRender::render_static_stars(($this->is_ie6 ? $this->o["mur_style_ie6"] : $this->o["mur_style"]), $this->o['mur_size'], $max, 0);
- return $rating;
- }
- // various rendering
- // edit boxes
- /**
- * Insert box multi review on post edit panel.
- */
- function editbox_post_mur() {
- global $post;
- gdsr_render_multi_editor(array("post_id" => $post->ID, "admin" => true));
- }
- /**
- * Insert plugin box on post edit panel.
- */
- function editbox_post() {
- global $post;
- $gdsr_options = $this->o;
- $post_id = $post->ID;
- $default = false;
- $countdown_value = $gdsr_options["default_timer_countdown_value"];
- $countdown_type = $gdsr_options["default_timer_countdown_type"];
- $recc_countdown_value = $gdsr_options["default_timer_countdown_value"];
- $recc_countdown_type = $gdsr_options["default_timer_countdown_type"];
- $timer_date_value = $recc_timer_date_value = "";
- if ($post_id == 0) $default = true;
- else {
- $post_data = GDSRDatabase::get_post_edit($post_id);
- if (count($post_data) > 0) {
- $rating = explode(".", strval($post_data->review));
- $rating_decimal = intval($rating[1]);
- $rating = intval($rating[0]);
- $recc_vote_rules = $post_data->recc_rules_articles;
- $recc_moderation_rules = $post_data->recc_moderate_articles;
- $recc_cmm_vote_rules = $post_data->recc_rules_comments;
- $recc_cmm_moderation_rules = $post_data->recc_moderate_comments;
- $recc_timer_restrictions = $post_data->recc_expiry_type;
- if ($recc_timer_restrictions == "T") {
- $recc_countdown_type = substr($post_data->recc_expiry_value, 0, 1);
- $recc_countdown_value = substr($post_data->recc_expiry_value, 1);
- } else if ($recc_timer_restrictions == "D") {
- $recc_timer_date_value = $post_data->recc_expiry_value;
- }
- $vote_rules = $post_data->rules_articles;
- $moderation_rules = $post_data->moderate_articles;
- $cmm_vote_rules = $post_data->rules_comments;
- $cmm_moderation_rules = $post_data->moderate_comments;
- $timer_restrictions = $post_data->expiry_type;
- if ($timer_restrictions == "T") {
- $countdown_type = substr($post_data->expiry_value, 0, 1);
- $countdown_value = substr($post_data->expiry_value, 1);
- } else if ($timer_restrictions == "D") {
- $timer_date_value = $post_data->expiry_value;
- }
- } else $default = true;
- }
- if ($default) {
- $rating_decimal = $rating = -1;
- $recc_vote_rules = $gdsr_options["recc_default_voterules_articles"];
- $recc_moderation_rules = $gdsr_options["recc_default_moderation_articles"];
- $recc_cmm_vote_rules = $gdsr_options["recc_default_voterules_comments"];
- $recc_cmm_moderation_rules = $gdsr_options["recc_default_moderation_comments"];
- $recc_timer_restrictions = $gdsr_options["recc_default_timer_type"];
- $vote_rules = $gdsr_options["default_voterules_articles"];
- $moderation_rules = $gdsr_options["default_moderation_articles"];
- $cmm_vote_rules = $gdsr_options["default_voterules_comments"];
- $cmm_moderation_rules = $gdsr_options["default_moderation_comments"];
- $timer_restrictions = $gdsr_options["default_timer_type"];
- }
- include($this->plugin_path.'integrate/edit.php');
- }
- // edit boxes
- /**
- * Check the user access levels.
- *
- * @global object $userdata Object with user data.
- */
- function check_user_access() {
- global $userdata;
- $this->wp_access_level = isset($userdata->user_level) ? $userdata->user_level : 0;
- if ($this->security_users == "0") {
- $this->wp_secure_level = $this->wp_access_level > 8;
- } else {
- $allowed = explode(",", $this->security_users);
- if (is_array($allowed)) {
- $this->wp_secure_level = in_array($userdata->ID, $allowed);
- } else $this->wp_secure_level = false;
- }
- }
- function meta_boxes_30() {
- global $wp_meta_boxes;
- $post_types = get_post_types(array(), "objects");
- foreach ($post_types as $name => $data) {
- if ($this->o["integrate_post_edit"] == 1) {
- add_meta_box("gdsr-meta-box", "GD Star Rating", array(&$this, 'editbox_post'), $name, "side", "high");
- }
- if ($this->o["integrate_post_edit_mur"] == 1) {
- add_meta_box("gdsr-meta-box-mur", "GD Star Rating: ".__("Multi Ratings Review", "gd-star-rating"), array(&$this, 'editbox_post_mur'), $name, "advanced", "high");
- }
- }
- }
- function meta_boxes_pre30() {
- if ($this->o["integrate_post_edit"] == 1) {
- add_meta_box("gdsr-meta-box", "GD Star Rating", array(&$this, 'editbox_post'), "post", "side", "high");
- add_meta_box("gdsr-meta-box", "GD Star Rating", array(&$this, 'editbox_post'), "page", "side", "high");
- }
- if ($this->o["integrate_post_edit_mur"] == 1) {
- add_meta_box("gdsr-meta-box-mur", "GD Star Rating: ".__("Multi Ratings Review", "gd-star-rating"), array(&$this, 'editbox_post_mur'), "post", "advanced", "high");
- add_meta_box("gdsr-meta-box-mur", "GD Star Rating: ".__("Multi Ratings Review", "gd-star-rating"), array(&$this, 'editbox_post_mur'), "page", "advanced", "high");
- }
- }
- /**
- * WordPress action for adding administration menu items
- */
- function admin_menu() {
- $this->check_user_access();
- if ($this->wp_version < 30) $this->meta_boxes_pre30();
- if ($this->wp_version > 29) $this->meta_boxes_30();
- add_menu_page('GD Star Rating', 'GD Star Rating', $this->security_level_front, $this->plugin_base, array(&$this->m, "star_menu_front"), plugins_url('gd-star-rating/gfx/menu.png'));
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Front Page", "gd-star-rating"), __("Front Page", "gd-star-rating"), $this->security_level_front, $this->plugin_base, array(&$this->m, "star_menu_front"));
- if ($this->security_my_ratings) {
- add_submenu_page('index.php', 'GD Star Rating: '.__("My Ratings", "gd-star-rating"), __("My Ratings", "gd-star-rating"), $this->security_my_ratings_level, "gd-star-rating-my", array(&$this->m, "star_menu_my"));
- } else {
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("My Ratings", "gd-star-rating"), __("My Ratings", "gd-star-rating"), $this->security_level_front, "gd-star-rating-my", array(&$this->m, "star_menu_my"));
- }
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Builder", "gd-star-rating"), __("Builder", "gd-star-rating"), $this->security_level_builder, "gd-star-rating-builder", array(&$this->m, "star_menu_builder"));
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Articles", "gd-star-rating"), __("Articles", "gd-star-rating"), $this->security_level, "gd-star-rating-stats", array(&$this->m, "star_menu_stats"));
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Categories", "gd-star-rating"), __("Categories", "gd-star-rating"), $this->security_level, "gd-star-rating-cats", array(&$this->m, "star_menu_cats"));
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("All Users", "gd-star-rating"), __("All Users", "gd-star-rating"), $this->security_level, "gd-star-rating-users", array(&$this->m, "star_menu_users"));
- if ($this->o["multis_active"] == 1)
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Multi Sets", "gd-star-rating"), __("Multi Sets", "gd-star-rating"), $this->security_level, "gd-star-rating-multi-sets", array(&$this->m, "star_multi_sets"));
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Settings", "gd-star-rating"), __("Settings", "gd-star-rating"), $this->security_level, "gd-star-rating-settings", array(&$this->m, "star_menu_settings"));
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Graphics", "gd-star-rating"), __("Graphics", "gd-star-rating"), $this->security_level, "gd-star-rating-gfx-page", array(&$this->m, "star_menu_gfx"));
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("T2 Templates", "gd-star-rating"), __("T2 Templates", "gd-star-rating"), $this->security_level, "gd-star-rating-t2", array(&$this->m, "star_menu_t2"));
- if ($this->o["admin_ips"] == 1)
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("IP's", "gd-star-rating"), __("IP's", "gd-star-rating"), $this->security_level, "gd-star-rating-ips", array(&$this->m, "star_menu_ips"));
- if ($this->o["admin_import"] == 1)
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Import", "gd-star-rating"), __("Import", "gd-star-rating"), $this->security_level, "gd-star-rating-import", array(&$this->m, "star_menu_import"));
- if ($this->o["admin_export"] == 1)
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Export", "gd-star-rating"), __("Export", "gd-star-rating"), $this->security_level, "gd-star-rating-export", array(&$this->m, "star_menu_export"));
- $this->custom_actions('admin_menu');
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Tools", "gd-star-rating"), __("Tools", "gd-star-rating"), $this->security_level, "gd-star-rating-tools", array(&$this->m, "star_menu_tools"));
- add_submenu_page($this->plugin_base, 'GD Star Rating: '.__("Setup", "gd-star-rating"), __("Setup", "gd-star-rating"), $this->security_level_setup, "gd-star-rating-setup", array(&$this->m, "star_menu_setup"));
- }
- function load_colorbox() {
- if ($this->wp_version >= 28) {
- wp_enqueue_script('gdsr-colorbox', $this->plugin_url."js/jquery/jquery-colorbox.js", array("jquery"), $this->o["version"], true);
- wp_enqueue_style('gdsr-colorbox', $this->plugin_url."css/jquery/colorbox.css");
- }
- }
- function load_jquery() {
- if ($this->wp_version < 28) {
- wp_enqueue_script('gdsr-jquery-ui', $this->plugin_url."js/jquery/jquery-ui.js", array("jquery"), $this->o["version"], true);
- wp_enqueue_script('gdsr-jquery-ui-tabs', $this->plugin_url."js/jquery/jquery-ui-tabs.js", array("jquery", "gdsr-jquery-ui"), $this->o["version"], true);
- wp_enqueue_style('gdsr-jquery-ui-tabs', $this->plugin_url."css/jquery/ui.tabs.js");
- }
- }
- function load_datepicker() {
- if ($this->wp_version < 28) {
- wp_enqueue_script('gdsr-jquery-datepicker', $this->plugin_url."js/jquery/jquery-ui-datepicker.js", array("jquery", "gdsr-jquery-ui"), $this->o["version"], true);
- wp_enqueue_style('gdsr-jquery-ui-core', $this->plugin_url."css/jquery/ui.core.css");
- wp_enqueue_style('gdsr-jquery-ui-theme', $this->plugin_url."css/jquery/ui.theme.css");
- } else {
- wp_enqueue_script('gdsr-jquery-datepicker', $this->plugin_url."js/jquery/jquery-ui-datepicker-17.js", array("jquery", "jquery-ui-core"), $this->o["version"], true);
- wp_enqueue_style('gdsr-jquery-ui-theme', $this->plugin_url."css/jquery/ui.17.css");
- }
- if(!empty($this->l)) {
- $jsFile = $this->plugin_path.'js/i18n'.($this->wp_version < 28 ? '' : '-17').'/jquery-ui-datepicker-'.$this->l.'.js';
- if (@file_exists($jsFile) && is_readable($jsFile)) {
- $jsUrl = $this->plugin_url.'js/i18n'.($this->wp_version < 28 ? '' : '-17').'/jquery-ui-datepicker-'.$this->l.'.js';
- wp_enqueue_script('gdsr-jquery-datepicker-translation', $jsUrl, array("gdsr-jquery-datepicker"), $this->o["version"], true);
- }
- }
- }
- function load_corrections() {
- wp_enqueue_script('gdsr-js-corrections', $this->plugin_url."js/rating/rating-corrections.js", array(), $this->o["version"], true);
- }
- /**
- * WordPress action for adding administration header contents
- */
- function admin_head() {
- global $parent_file;
- //$this->wp_head_javascript();
- $this->admin_page = $parent_file;
- $datepicker_date = date("Y, n, j");
- $tabs_extras = "";
- if ($this->admin_plugin_page == "ips" && isset($_GET["gdsr"]) && $_GET["gdsr"] == "iplist") {
- $tabs_extras = ", selected: 1";
- }
- if ($this->script == "post.php" || $this->script == "post-new.php" || $this->script == "page.php") {
- echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-editors.js"></script>'.STARRATING_EOL);
- $this->include_rating_css_admin();
- }
- if ($this->admin_plugin) {
- wp_admin_css('css/dashboard');
- echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_main.css" type="text/css" media="screen" />'.STARRATING_EOL);
- echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-admin.js"></script>'.STARRATING_EOL);
- if ($this->wp_version < 28) {
- echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_wp27.css" type="text/css" media="screen" />'.STARRATING_EOL);
- } else {
- echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_wp28.css" type="text/css" media="screen" />'.STARRATING_EOL);
- }
- }
- echo('<script type="text/javascript">jQuery(document).ready(function() {'.STARRATING_EOL);
- if ($this->admin_plugin) {
- if ($this->wp_version >= 28) {
- echo('jQuery(".clrboxed").colorbox({width:800, height:470, iframe:true});'.STARRATING_EOL);
- }
- echo('jQuery("#gdsr_tabs'.($this->wp_version < 28 ? ' > ul' : '').'").tabs({fx: {height: "toggle"}'.$tabs_extras.' });'.STARRATING_EOL);
- }
- if ($this->admin_plugin || $this->admin_page == "edit.php" || $this->admin_page == "post-new.php" || $this->admin_page == "themes.php") {
- echo('if (jQuery().datepicker) jQuery("#gdsr_timer_date_value").datepicker({duration: "fast", minDate: new Date('.$datepicker_date.'), dateFormat: "yy-mm-dd"});'.STARRATING_EOL);
- }
- if ($this->admin_plugin_page == "tools") {
- echo('if (jQuery().datepicker) jQuery("#gdsr_lock_date").datepicker({duration: "fast", dateFormat: "yy-mm-dd"});'.STARRATING_EOL);
- }
- echo("});</script>".STARRATING_EOL);
- if ($this->admin_plugin_page == "settings") {
- echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-loaders.js"></script>'.STARRATING_EOL);
- }
- if ($this->admin_page == "widgets.php" || $this->admin_page == "themes.php") {
- if ($this->wp_version < 28) {
- echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-widgets.js"></script>'.STARRATING_EOL);
- } else if ($this->wp_version > 29) {
- echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-widgets-30.js"></script>'.STARRATING_EOL);
- } else {
- echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-widgets-28.js"></script>'.STARRATING_EOL);
- }
- echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_widgets.css" type="text/css" media="screen" />'.STARRATING_EOL);
- }
- $this->custom_actions('admin_head');
- if ($this->admin_plugin_page == "builder") {
- echo('<script type="text/javascript" src="'.$this->plugin_url.'tinymce3/tinymce.js"></script>'.STARRATING_EOL);
- if ($this->wp_version > 29) {
- echo('<script type="text/javascript" src="'.$this->plugin_url.'tinymce3/tinymce-30.js"></script>'.STARRATING_EOL);
- }
- }
- echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_post.css" type="text/css" media="screen" />'.STARRATING_EOL);
- }
- /**
- * WordPress action to get post ID's from active loop
- *
- * @param WP_Query $wpq query object
- * @return WP_Query query object
- */
- function loop_start($wp_query) {
- if (!is_admin()) {
- if ($this->wp_version < 28) global $wp_query;
- if (is_array($wp_query->posts)) {
- foreach ($wp_query->posts as $p) {
- if (!isset($this->c[$p->ID])) $this->c[$p->ID] = 0;
- }
- }
- }
- if ($this->wp_version >= 28) return $wp_query;
- }
- /**
- * WordPress action to get and cache comments rating data for a post
- *
- * @param array $comments post comments
- * @param int $post_id post id
- * @return array post comments
- */
- function comments_array($comments, $post_id) {
- if (count($comments) > 0 && !is_admin()) {
- if ((is_single() && ($this->o["display_comment"] == 1 || $this->o["thumb_display_comment"] == 1)) ||
- (is_page() && ($this->o["display_comment_page"] == 1 || $this->o["thumb_display_comment_page"] == 1)) ||
- $this->o["override_thumb_display_comment"] == 1 || $this->o["override_display_comment"] == 1) {
- $this->cache_comments($post_id);
- }
- }
- return $comments;
- }
- /**
- * Adding WordPress action and filter
- */
- function actions_filters() {
- if (GDSR_WP_ADMIN) {
- add_action('admin_menu', array(&$this, 'admin_menu'));
- add_action('admin_head', array(&$this, 'admin_head'));
- add_filter('plugin_action_links', array(&$this, 'plugin_links'), 10, 2 );
- add_action('after_plugin_row', array(&$this,'plugin_check_version'), 10, 2);
- if ($this->o["integrate_post_edit_mur"] == 1 || $this->o["integrate_post_edit"] == 1) {
- add_action('save_post', array(&$this, 'saveedit_post'));
- }
- if ($this->o["integrate_dashboard"] == 1) {
- add_action('wp_dashboard_setup', array(&$this, 'add_dashboard_widget'));
- if (!function_exists('wp_add_dashboard_widget')) add_filter('wp_dashboard_widgets', array(&$this, 'add_dashboard_widget_filter'));
- }
- if ($this->o["integrate_tinymce"] == 1) {
- add_filter("mce_external_plugins", array(&$this, 'add_tinymce_plugin'), 5);
- add_filter('mce_buttons', array(&$this, 'add_tinymce_button'), 5);
- }
- } else {
- add_action('wp_head', array(&$this, 'wp_head'));
- add_action('gdsr_gsr_insert_snippet', array(&$this->f, 'insert_google_rich_snippet'));
- add_filter('query_vars', array($this->q, 'query_vars'));
- add_action('pre_get_posts', array($this->q, 'pre_get_posts'));
- add_filter('comment_text', array(&$this, 'display_comment'), 10000);
- add_filter('the_content', array(&$this, 'display_article'));
- add_action('loop_start', array(&$this, 'loop_start'));
- add_filter('preprocess_comment', array(&$this, 'comment_read_post'));
- add_filter('comment_post', array(&$this, 'comment_save'));
- if ($this->o["integrate_rss_powered"] == 1 || $this->o["rss_active"] == 1) {
- add_filter('the_excerpt_rss', array(&$this, 'rss_filter'));
- add_filter('the_content_rss', array(&$this, 'rss_filter'));
- add_filter('the_content', array(&$this, 'rss_filter'));
- }
- if ($this->o["cached_loading"] == 0) {
- add_filter('comments_array', array(&$this, 'comments_array'), 10, 2);
- }
- }
- add_action('init', array(&$this, 'init'));
- add_action('widgets_init', array(&$this, 'widgets_init'));
- add_action('delete_comment', array(&$this, 'comment_delete'));
- add_action('delete_post', array(&$this, 'post_delete'));
- foreach ($this->shortcodes as $code) $this->shortcode_action($code);
- }
- /**
- * WordPress widgets init action
- */
- function widgets_init() {
- if ($this->wp_version < 28) {
- $this->widgets = new gdsrWidgets($this->g, $this->default_widget_comments, $this->default_widget_top, $this->default_widget);
- if ($this->o["widget_articles"] == 1) $this->widgets->widget_articles_init();
- if ($this->o["widget_top"] == 1) $this->widgets->widget_top_init();
- if ($this->o["widget_comments"] == 1) $this->widgets->widget_comments_init();
- } else {
- if ($this->o["widget_articles"] == 1) register_widget("gdsrWidgetRating");
- if ($this->o["widget_top"] == 1) register_widget("gdsrWidgetTop");
- if ($this->o["widget_comments"] == 1) register_widget("gdsrWidgetComments");
- }
- }
- /**
- * Adds Settings link to plugins panel grid
- */
- function plugin_links($links, $file) {
- static $this_plugin;
- if (!$this_plugin) $this_plugin = plugin_basename($this->plugin_base);
- if ($file == $this_plugin){
- $settings_link = '<a href="admin.php?page=gd-star-rating-settings">'.__("Settings", "gd-star-rating").'</a>';
- array_unshift($links, $settings_link);
- }
- return $links;
- }
- /**
- * Render update info on the plugins panel if the update is available.
- *
- * @param string $file name of the plugin file
- * @param array $plugin_data plugin info
- * @return bool false if no update available
- */
- function plugin_check_version($file, $plugin_data) {
- static $this_plugin;
- if (!$this_plugin) $this_plugin = plugin_basename($this->plugin_base);
- if ($file == $this_plugin){
- $current = $this->wp_version < 28 ? get_option('update_plugins') : get_transient('update_plugins');
- if (!isset($current->response[$file])) return false;
- $columns = $this->wp_version < 28 ? 5 : 3;
- $url = gdFunctionsGDSR::get_update_url($this->o, get_option('home'));
- $update = wp_remote_fopen($url);
- if ($update != "") {
- echo '<td colspan="'.$columns.'" class="gdr-plugin-update"><div class="gdr-plugin-update-message">';
- echo $update;
- echo '</div></td>';
- }
- }
- }
- /**
- * WordPress rss content filter
- */
- function rss_filter($content) {
- if (is_feed()) {
- if ($this->o["rss_active"] == 1) $content.= "<br />".$this->f->render_article_rss();
- if ($this->o["integrate_rss_powered"] == 1) $content.= "<br />".$this->powered_by();
- $content.= "<br />";
- }
- return $content;
- }
- /**
- * Renders tag with link and powered by button
- *
- * @return string rendered content
- */
- function powered_by() {
- return '<a target="_blank" href="http://www.gdstarrating.com/"><img src="'.STARRATING_URL.'gfx/powered.png" border="0" width="80" height="15" /></a>';
- }
- function get_users_votes($user_id, $limit = 100, $filter = array()) {
- $sett = array();
- $sett["integrate_dashboard_latest_count"] = $limit;
- $settings = shortcode_atts($this->default_user_ratings_filter, $filter);
- foreach ($settings as $name => $value) {
- $sett["integrate_dashboard_latest_filter_".$name] = $value;
- }
- return gdsrDB::filter_latest_votes($sett, $user_id);
- }
- function add_dashboard_widget() {
- global $userdata;
- $user_level = intval($userdata->user_level);
- if ($user_level >= intval($this->o["security_showdashboard_user_level"])) {
- if (!function_exists('wp_add_dashboard_widget')) {
- if ($this->o["integrate_dashboard_latest"] == 1)
- wp_register_sidebar_widget("dashboard_gdstarrating_latest", "GD Star Rating ".__("Latest", "gd-star-rating"), array(&$this, 'display_dashboard_widget_latest'), array('all_link' => get_bloginfo('wpurl').'/wp-admin/admin.php?page=gd-star-rating/gd-star-rating.php', 'width' => 'half', 'height' => 'single'));
- } else {
- if ($this->o["integrate_dashboard_latest"] == 1)
- wp_add_dashboard_widget("dashboard_gdstarrating_latest", "GD Star Rating ".__("Latest", "gd-star-rating"), array(&$this, 'display_dashboard_widget_latest'));
- }
- }
- }
- function add_dashboard_widget_filter($widgets) {
- global $userdata;
- $user_level = intval($userdata->user_level);
- if ($user_level >= intval($this->o["security_showdashboard_user_level"])) {
- global $wp_registered_widgets;
- if (!isset($wp_registered_widgets["dashboard_gdstarrating_latest"])) return $widgets;
- if ($this->o["integrate_dashboard_latest"] == 1)
- array_splice($widgets, 2, 0, "dashboard_gdstarrating_latest");
- }
- return $widgets;
- }
- function display_dashboard_widget_chart($sidebar_args) {
- if (!function_exists('wp_add_dashboard_widget')) {
- extract($sidebar_args, EXTR_SKIP);
- echo $before_widget.$before_title.$widget_name.$after_title;
- }
- include($this->plugin_path.'integrate/dash_chart.php');
- if (!function_exists('wp_add_dashboard_widget')) echo $after_widget;
- }
- function display_dashboard_widget_latest($sidebar_args) {
- if (!function_exists('wp_add_dashboard_widget')) {
- extract($sidebar_args, EXTR_SKIP);
- echo $before_widget.$before_title.$widget_name.$after_title;
- }
- $o = $this->o;
- include($this->plugin_path.'integrate/dash_latest.php');
- if (!function_exists('wp_add_dashboard_widget')) echo $after_widget;
- }
- function comment_read_post($comment) {
- $this->post_comment["post_id"] = $_POST["comment_post_ID"];
- $this->post_comment["review"] = isset($_POST["gdsr_cmm_value"]) ? intval($_POST["gdsr_cmm_value"]) : -1;
- $this->post_comment["standard_rating"] = isset($_POST["gdsr_int_value"]) ? intval($_POST["gdsr_int_value"]) : -1;
- $this->post_comment["multi_rating"] = isset($_POST["gdsr_mur_value"]) ? $_POST["gdsr_mur_value"] : "";
- $this->post_comment["multi_id"] = isset($_POST["gdsr_mur_set"]) ? intval($_POST["gdsr_mur_set"]) : 0;
- return $comment;
- }
- function comment_save($comment_id) {
- global $userdata;
- $user_id = is_object($userdata) ? $userdata->ID : 0;
- $user = intval($user_id);
- $ip = $_SERVER["REMOTE_ADDR"];
- if ($this->post_comment["review"] > -1) {
- $comment_data = GDSRDatabase::get_comment_data($comment_id);
- if (count($comment_data) == 0) GDSRDatabase::add_empty_comment($comment_id, $this->post_comment["post_id"], $this->post_comment["review"]);
- else GDSRDatabase::save_comment_review($comment_id, $this->post_comment["review"]);
- }
- $std_minimum = $this->o["int_comment_std_zero"] == 1 ? -1 : 0;
- $mur_minimum = $this->o["int_comment_mur_zero"] == 1 ? 0 : 1;
- $id = $this->post_comment["post_id"];
- if ($this->post_comment["standard_rating"] > $std_minimum) {
- $votes = $this->post_comment["standard_rating"];
- $ua = $this->o["save_user_agent"] == 1 ? $_SERVER["HTTP_USER_AGENT"] : "";
- $allow_vote = true;
- if ($this->o["cmm_integration_prevent_duplicates"] == 1) {
- $allow_vote = intval($votes) <= $this->o["stars"];
- if ($allow_vote) $allow_vote = gdsrFrontHelp::check_cookie($id);
- if ($allow_vote) $allow_vote = gdsrBlgDB::check_vote($id, $user, 'article', $ip, false, false);
- }
- if ($allow_vote) {
- gdsrBlgDB::save_vote($id, $user, $ip, $ua, $…
Large files files are truncated, but you can click here to view the full file