PageRenderTime 61ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/gd-star-rating/code/class.php

https://bitbucket.org/openfarmtech/weblog-content
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

  1. <?php
  2. /**
  3. * Main plugin class
  4. */
  5. class GDStarRating {
  6. var $is_bot = false;
  7. var $is_ban = false;
  8. var $is_ie6 = false;
  9. var $is_cached = false;
  10. var $is_update = false;
  11. var $security_level = 9;
  12. var $security_level_front = 1;
  13. var $security_level_builder = 1;
  14. var $security_level_setup = 9;
  15. var $security_my_ratings = false;
  16. var $security_my_ratings_level = 0;
  17. var $security_users = '0';
  18. var $is_cached_integration_std = false;
  19. var $is_cached_integration_mur = false;
  20. var $use_nonce = true;
  21. var $extra_folders = false;
  22. var $safe_mode = false;
  23. var $widget_post_id;
  24. var $cats_data_posts = array();
  25. var $cats_data_cats = array();
  26. var $wp_access_level = 0;
  27. var $wp_secure_level = false;
  28. var $wpr8_available = false;
  29. var $admin_plugin = false;
  30. var $admin_plugin_page = '';
  31. var $admin_page;
  32. var $script;
  33. var $widgets;
  34. var $active_wp_page;
  35. var $wp_version;
  36. var $vote_status;
  37. var $rendering_sets = null;
  38. var $override_readonly_standard = false;
  39. var $override_readonly_multis = false;
  40. var $tables_list;
  41. var $plugin_base;
  42. var $plugin_url;
  43. var $plugin_ajax;
  44. var $plugin_path;
  45. var $plugin_xtra_url;
  46. var $plugin_xtra_path;
  47. var $plugin_chart_url;
  48. var $plugin_chart_path;
  49. var $plugin_cache_path;
  50. var $plugin_wpr8_path;
  51. var $post_comment;
  52. var $wpr8;
  53. var $l; // language
  54. var $o; // options
  55. var $w; // widget options
  56. var $p; // post data
  57. var $i; // import
  58. var $g; // gfx object
  59. var $q; // query object
  60. var $c; // cached post ids
  61. var $f; // front end rendering object
  62. var $m; // admin menus object
  63. var $v; // ajax votes saving object
  64. var $s; // shared objects functions
  65. var $qc;
  66. var $rSnippets;
  67. var $ginc;
  68. var $bots;
  69. var $shortcodes;
  70. var $stars_sizes;
  71. var $thumb_sizes;
  72. var $function_restrict;
  73. var $default_shortcode_starrating;
  74. var $default_shortcode_starratingmulti;
  75. var $default_shortcode_starreviewmulti;
  76. var $default_shortcode_starcomments;
  77. var $default_shortcode_starrater;
  78. var $default_shortcode_starthumbsblock;
  79. var $default_shortcode_starreview;
  80. var $default_user_ratings_filter;
  81. var $default_options;
  82. var $default_import;
  83. var $default_widget_comments;
  84. var $default_widget_top;
  85. var $default_widget;
  86. var $default_spider_bots;
  87. var $default_wpr8;
  88. /**
  89. * Constructor method
  90. */
  91. function GDStarRating($base_path, $base_file) {
  92. $this->tabpage = "front";
  93. $this->plugin_path = $base_path."/";
  94. $this->plugin_base = $base_file;
  95. $gdd = new GDSRDefaults();
  96. $this->default_options = $gdd->default_options;
  97. $this->shortcodes = $gdd->shortcodes;
  98. $this->stars_sizes = $gdd->stars_sizes;
  99. $this->thumb_sizes = $gdd->thumb_sizes;
  100. $this->tables_list = $gdd->tables_list;
  101. $this->function_restrict = $gdd->function_restrict;
  102. $this->default_spider_bots = $gdd->default_spider_bots;
  103. $this->default_wpr8 = $gdd->default_wpr8;
  104. $this->default_user_ratings_filter = $gdd->default_user_ratings_filter;
  105. $this->default_import = $gdd->default_import;
  106. $this->default_widget_comments = $gdd->default_widget_comments;
  107. $this->default_widget_top = $gdd->default_widget_top;
  108. $this->default_widget = $gdd->default_widget;
  109. $this->default_shortcode_starrating = $gdd->default_shortcode_starrating;
  110. $this->default_shortcode_starratingmulti = $gdd->default_shortcode_starratingmulti;
  111. $this->default_shortcode_starreviewmulti = $gdd->default_shortcode_starreviewmulti;
  112. $this->default_shortcode_starcomments = $gdd->default_shortcode_starcomments;
  113. $this->default_shortcode_starrater = $gdd->default_shortcode_starrater;
  114. $this->default_shortcode_starthumbsblock = $gdd->default_shortcode_starthumbsblock;
  115. $this->default_shortcode_starreview = $gdd->default_shortcode_starreview;
  116. $this->function_restrict = $gdd->function_restrict;
  117. define("STARRATING_INSTALLED", $this->default_options["version"]." ".$this->default_options["status"]);
  118. define("STARRATING_EOL", "\r\n");
  119. $this->c = array();
  120. $this->plugin_path_url();
  121. if ($this->wp_version > 29) {
  122. $this->default_widget["select"] = "post";
  123. }
  124. $this->install_plugin();
  125. if (!GDSR_WP_ADMIN) {
  126. if (!STARRATING_AJAX) {
  127. $google_rspf = isset($this->o["google_rich_snippets_format"]) ? $this->o["google_rich_snippets_format"] : "microformat";
  128. $this->q = new gdsrQuery();
  129. $this->rSnippets = new gdGoogleRichSnippetsGDSR($google_rspf);
  130. } else {
  131. $this->v = new gdsrVotes($this);
  132. }
  133. $this->f = new gdsrFront($this);
  134. } else {
  135. $this->m = new gdsrMenus($this);
  136. }
  137. $this->s = new gdsrShared($this);
  138. if (!STARRATING_AJAX) {
  139. $this->actions_filters();
  140. $this->initialize_security();
  141. }
  142. if ($this->o["ajax_jsonp"] == 1) $this->plugin_ajax.= "?callback=?";
  143. $this->is_cached = $this->o["cache_active"];
  144. $this->use_nonce = $this->o["use_nonce"] == 1;
  145. define("STARRATING_VERSION", $this->o["version"].'_'.$this->o["build"]);
  146. define("STARRATING_DEBUG_ACTIVE", $this->o["debug_active"]);
  147. define("STARRATING_STARS_GENERATOR", $this->o["gfx_generator_auto"] == 0 ? "DIV" : "GFX");
  148. define('STARRATING_AJAX_URL', $this->plugin_ajax);
  149. define('STARRATING_ENCODING', $this->o["encoding"]);
  150. }
  151. function get($name) {
  152. return $this->o[$name];
  153. }
  154. function set($name, $value, $save = true) {
  155. $this->o[$name] = $value;
  156. if ($save) update_option('gd-star-rating', $this->o);
  157. }
  158. /**
  159. * Initialize security variables based on the gdsr-config.php file
  160. */
  161. function initialize_security() {
  162. if (defined('STARRATING_ACCESS_LEVEL')) $this->security_level = STARRATING_ACCESS_LEVEL;
  163. if (defined('STARRATING_ACCESS_LEVEL_FRONT')) $this->security_level_front = STARRATING_ACCESS_LEVEL_FRONT;
  164. if (defined('STARRATING_ACCESS_LEVEL_BUILDER')) $this->security_level_builder = STARRATING_ACCESS_LEVEL_BUILDER;
  165. if (defined('STARRATING_ACCESS_LEVEL_SETUP')) $this->security_level_setup = STARRATING_ACCESS_LEVEL_SETUP;
  166. if (defined('STARRATING_ACCESS_ADMIN_USERIDS')) $this->security_users = STARRATING_ACCESS_ADMIN_USERIDS;
  167. if (defined('STARRATING_ACCESS_MY_RATINGS')) $this->security_my_ratings = STARRATING_ACCESS_MY_RATINGS;
  168. if (defined('STARRATING_ACCESS_MY_RATINGS_LEVEL')) $this->security_my_ratings_level = STARRATING_ACCESS_MY_RATINGS_LEVEL;
  169. }
  170. /**
  171. * Adds new button to tinyMCE editor toolbar
  172. *
  173. * @param mixed $buttons
  174. */
  175. function add_tinymce_button($buttons) {
  176. array_push($buttons, "separator", "StarRating");
  177. return $buttons;
  178. }
  179. /**
  180. * Adds plugin to tinyMCE editor
  181. *
  182. * @param mixed $plugin_array
  183. */
  184. function add_tinymce_plugin($plugin_array) {
  185. $plugin_array['StarRating'] = $this->plugin_url.'tinymce3/plugin.js';
  186. return $plugin_array;
  187. }
  188. // shortcodes
  189. /**
  190. * Adds shortcodes into WordPress instance
  191. *
  192. * @param string|array $scode one or more shortcode names
  193. */
  194. function shortcode_action($scode) {
  195. $sc_name = $scode;
  196. $sc_method = "shortcode_".$scode;
  197. if (is_array($scode)) {
  198. $sc_name = $scode["name"];
  199. $sc_method = $scode["method"];
  200. }
  201. add_shortcode(strtolower($sc_name), array(&$this, $sc_method));
  202. add_shortcode(strtoupper($sc_name), array(&$this, $sc_method));
  203. }
  204. /**
  205. * Code for StarRater shortcode implementation
  206. *
  207. * @param array $atts
  208. */
  209. function shortcode_starrater($atts = array()) {
  210. return $this->shortcode_starratingblock($atts);
  211. }
  212. /**
  213. * Code for StarThumbsBlock shortcode implementation
  214. *
  215. * @param array $atts
  216. */
  217. function shortcode_starthumbsblock($atts = array()) {
  218. global $userdata;
  219. $user_id = is_object($userdata) ? $userdata->ID : 0;
  220. $override = shortcode_atts($this->default_shortcode_starthumbsblock, $atts);
  221. if ($override["post"] == 0) global $post;
  222. else $post = get_post($override["post"]);
  223. $this->cache_posts($user_id);
  224. return $this->f->render_thumb_article($post, $userdata, $override);
  225. }
  226. /**
  227. * Code for StarRatingBlock shortcode implementation
  228. *
  229. * @param array $atts
  230. */
  231. function shortcode_starratingblock($atts = array()) {
  232. global $userdata;
  233. $user_id = is_object($userdata) ? $userdata->ID : 0;
  234. $this->cache_posts($user_id);
  235. $override = shortcode_atts($this->default_shortcode_starrater, $atts);
  236. if ($override["post"] == 0) global $post;
  237. else $post = get_post($override["post"]);
  238. return $this->f->render_article($post, $userdata, $override);
  239. }
  240. /**
  241. * Code for StarRating shortcode implementation
  242. *
  243. * @param array $atts
  244. */
  245. function shortcode_starrating($atts = array()) {
  246. $sett = shortcode_atts($this->default_shortcode_starrating, $atts);
  247. return GDSRRenderT2::render_srr($sett);
  248. }
  249. /**
  250. * Code for StarComments shortcode implementation
  251. *
  252. * @param array $atts
  253. */
  254. function shortcode_starcomments($atts = array()) {
  255. $sett = shortcode_atts($this->default_shortcode_starcomments, $atts);
  256. if ($sett["post"] == 0) {
  257. global $post;
  258. $sett["post"] = $post->ID;
  259. } else {
  260. $post = get_post($sett["post"]);
  261. }
  262. $rating = "";
  263. $sett["comments"] = $post->comment_count;
  264. if ($post->ID > 0) {
  265. $rows = gdsrBlgDB::get_comments_aggregation($sett["post"], $sett["show"]);
  266. $totel_comments = count($rows);
  267. $total_voters = 0;
  268. $total_votes = 0;
  269. $calc_rating = 0;
  270. foreach ($rows as $row) {
  271. switch ($sett["show"]) {
  272. default:
  273. case "total":
  274. $total_voters += $row->user_voters + $row->visitor_voters;
  275. $total_votes += $row->user_votes + $row->visitor_votes;
  276. break;
  277. case "users":
  278. $total_voters += $row->user_voters;
  279. $total_votes += $row->user_votes;
  280. break;
  281. case "visitors":
  282. $total_voters += $row->visitor_voters;
  283. $total_votes += $row->visitor_votes;
  284. break;
  285. }
  286. }
  287. if ($total_voters > 0) $calc_rating = $total_votes / $total_voters;
  288. $calc_rating = number_format($calc_rating, 1);
  289. $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"]));
  290. }
  291. return $rating;
  292. }
  293. /**
  294. * Code for StarReview shortcode implementation
  295. *
  296. * @param array $atts
  297. */
  298. function shortcode_starreview($atts = array()) {
  299. global $userdata;
  300. $user_id = is_object($userdata) ? $userdata->ID : 0;
  301. $this->cache_posts($user_id);
  302. $sett = shortcode_atts($this->default_shortcode_starreview, $atts);
  303. if ($sett["post"] == 0) {
  304. global $post;
  305. $sett["post"] = $post->ID;
  306. }
  307. $star_css = $sett["css"] != "" ? $sett["css"] : $this->o["review_class_block"];
  308. $star_style = $sett["style"] != "" ? $sett["style"] : $this->o["review_style"];
  309. $star_style_ie6 = $sett["style_ie6"] != "" ? $sett["style_ie6"] : $this->o["review_style_ie6"];
  310. $star_size = $sett["size"] != "" ? $sett["size"] : $this->o['review_size'];
  311. $post_data = wp_gdget_post($sett["post"]);
  312. $rating = is_object($post_data) ? $post_data->review : -1;
  313. $rating = $rating < 0 ? 0 : $rating;
  314. 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));
  315. }
  316. /**
  317. * Code for StarReviewMulti shortcode implementation
  318. *
  319. * @param array $atts
  320. */
  321. function shortcode_starreviewmulti($atts = array()) {
  322. $settings = shortcode_atts($this->default_shortcode_starreviewmulti, $atts);
  323. $el_stars = $settings["element_stars"] != "" ? $settings["element_stars"] : $settings["style"];
  324. $el_size = $settings["element_size"] != "" ? $settings["element_size"] : $settings["size"];
  325. $post_id = $settings["post"];
  326. if ($post_id == 0) {
  327. global $post;
  328. $post_id = $post->ID;
  329. }
  330. $multi_id = $settings["id"] == 0 ? $this->o["mur_review_set"] : $settings["id"];
  331. $set = gd_get_multi_set($multi_id);
  332. if ($multi_id > 0 && $post_id > 0) {
  333. $vote_id = GDSRDBMulti::get_vote($post_id, $multi_id, count($set->object));
  334. $multi_data = GDSRDBMulti::get_values($vote_id, 'rvw');
  335. $votes = array();
  336. foreach ($multi_data as $md) {
  337. $single_vote = array();
  338. $single_vote["votes"] = 1;
  339. $single_vote["score"] = $md->user_votes;
  340. $single_vote["rating"] = $md->user_votes;
  341. $votes[] = $single_vote;
  342. }
  343. $avg_rating = GDSRDBMulti::get_multi_review_average($vote_id);
  344. 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"]));
  345. }
  346. else return '';
  347. }
  348. /**
  349. * Code for StarRatingMulti shortcode implementation
  350. *
  351. * @param array $atts
  352. */
  353. function shortcode_starratingmulti($atts = array()) {
  354. if ($this->o["multis_active"] == 1) {
  355. global $post, $userdata;
  356. if (!isset($atts["style"]) && isset($atts["element_stars"]) && $atts["element_stars"] != "") $atts["style"] = $atts["element_stars"];
  357. if (!isset($atts["size"]) && isset($atts["element_size"]) && $atts["element_size"] != 0) $atts["size"] = $atts["element_size"];
  358. $settings = shortcode_atts($this->default_shortcode_starratingmulti, $atts);
  359. return $this->f->render_multi_rating($post, $userdata, $settings);
  360. } else return "";
  361. }
  362. // shortcodes
  363. // various rendering
  364. /**
  365. * Renders comment review stars for selected comment
  366. *
  367. * @param int $comment_id id of the comment you want displayed
  368. * @param bool $zero_render if set to false and $value is 0 then nothing will be rendered
  369. * @param bool $use_default rendering is using default rendering settings
  370. * @param string $style folder name of the stars set to use
  371. * @param int $size stars size 12, 20, 30, 46
  372. * @return string rendered stars for comment review
  373. */
  374. function display_comment_review($comment_id, $use_default = true, $style = "oxygen", $size = 20) {
  375. $review = wp_gdget_comment_review($comment_id);
  376. if ($review < 1) return "";
  377. else {
  378. if ($use_default) {
  379. $style = ($this->is_ie6 ? $this->o["cmm_review_style_ie6"] : $this->o["cmm_review_style"]);
  380. $size = $this->o["cmm_review_size"];
  381. }
  382. $stars = $this->o["cmm_review_stars"];
  383. return GDSRRender::render_static_stars($style, $size, $stars, $review);
  384. }
  385. }
  386. /**
  387. * Renders post review stars for selected post
  388. *
  389. * @param int $post_id id for the post you want review displayed
  390. * @param bool $zero_render if set to false and $value is 0 then nothing will be rendered
  391. * @param bool $use_default rendering is using default rendering settings
  392. * @param string $style folder name of the stars set to use
  393. * @param int $size stars size 12, 20, 30, 46
  394. * @return string rendered stars for article review
  395. */
  396. function display_article_review($post_id, $use_default = true, $style = "oxygen", $size = 20) {
  397. global $userdata;
  398. $user_id = is_object($userdata) ? $userdata->ID : 0;
  399. $this->cache_posts($user_id);
  400. if ($use_default) {
  401. $style = ($this->is_ie6 ? $this->o["review_style_ie6"] : $this->o["review_style"]);
  402. $size = $this->o["review_size"];
  403. }
  404. $stars = $this->o["review_stars"];
  405. $post_data = wp_gdget_post($post_id);
  406. $review = is_object($post_data) ? $post_data->review : -1;
  407. if ($review < 0) $review = 0;
  408. return GDSRRender::render_static_stars($style, $size, $stars, $review);
  409. }
  410. /**
  411. * Renders post review stars for selected post
  412. *
  413. * @param int $post_id id for the post you want review displayed
  414. * @param bool $zero_render if set to false and $value is 0 then nothing will be rendered
  415. * @param bool $use_default rendering is using default rendering settings
  416. * @param string $style folder name of the stars set to use
  417. * @param int $size stars size 12, 20, 30, 46
  418. * @return string rendered stars for article review
  419. */
  420. function display_multis_review($multi_id, $post_id, $use_default = true, $style = "oxygen", $size = 20) {
  421. if ($use_default) {
  422. $style = ($this->is_ie6 ? $this->o["review_style_ie6"] : $this->o["review_style"]);
  423. $size = $this->o["review_size"];
  424. }
  425. $set = gd_get_multi_set($multi_id);
  426. $stars = $set->stars;
  427. $review = GDSRDBMulti::get_review_avg($multi_id, $post_id);
  428. if ($review < 0) $review = 0;
  429. return GDSRRender::render_static_stars($style, $size, $stars, $review);
  430. }
  431. /**
  432. * Renders post rating stars for selected post
  433. *
  434. * @param int $post_id id for the post you want rating displayed
  435. * @param bool $zero_render if set to false and $value is 0 then nothing will be rendered
  436. * @param bool $use_default rendering is using default rendering settings
  437. * @param string $style folder name of the stars set to use
  438. * @param int $size stars size 12, 20, 30, 46
  439. * @return string rendered stars for article rating
  440. */
  441. function display_article_rating($post_id, $use_default = true, $style = "oxygen", $size = 20) {
  442. global $userdata;
  443. $user_id = is_object($userdata) ? $userdata->ID : 0;
  444. $this->cache_posts($user_id);
  445. if ($use_default) {
  446. $style = ($this->is_ie6 ? $this->o["style_ie6"] : $this->o["style"]);
  447. $size = $this->o["size"];
  448. }
  449. $stars = $this->o["stars"];
  450. $rating = $this->get_article_rating_simple($post_id);
  451. return GDSRRender::render_static_stars($style, $size, $stars, $rating);
  452. }
  453. /**
  454. * Renders single rating stars image with average rating for the multi rating post results from rating or review.
  455. *
  456. * @param int $post_id id of the post rating will be attributed to
  457. * @param bool $review if set to true average of review will be rendered
  458. * @param array $settings override settings for rendering the block
  459. */
  460. function get_multi_average_rendered($post_id, $settings = array()) {
  461. $sum = $votes = $rating = 0;
  462. if ($settings["id"] == "") $multi_id = $this->o["mur_review_set"];
  463. else $multi_id = $settings["id"];
  464. if ($multi_id > 0 && $post_id > 0) {
  465. $set = gd_get_multi_set($multi_id);
  466. $data = GDSRDBMulti::get_averages($post_id, $multi_id);
  467. if ($set != null && is_object($data)) {
  468. if ($settings["render"] == "review") {
  469. $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);
  470. return $review;
  471. } else {
  472. switch ($settings["show"]) {
  473. case "visitors":
  474. $rating = $data->average_rating_visitors;
  475. break;
  476. case "users":
  477. $rating = $data->average_rating_users;
  478. break;
  479. case "total":
  480. $sum = $data->average_rating_users * $data->total_votes_users + $data->average_rating_visitors * $data->total_votes_visitors;
  481. $votes = $data->total_votes_users + $data->total_votes_visitors;
  482. $rating = number_format($votes == 0 ? 0 : $sum / $votes, 1);
  483. break;
  484. }
  485. $rating = GDSRRender::render_static_stars(($this->is_ie6 ? $this->o["mur_style_ie6"] : $this->o["mur_style"]), $this->o['mur_size'], $set->stars, $rating);
  486. return $rating;
  487. }
  488. }
  489. }
  490. $max = is_null($set) ? 10 : $set->stars;
  491. $rating = GDSRRender::render_static_stars(($this->is_ie6 ? $this->o["mur_style_ie6"] : $this->o["mur_style"]), $this->o['mur_size'], $max, 0);
  492. return $rating;
  493. }
  494. // various rendering
  495. // edit boxes
  496. /**
  497. * Insert box multi review on post edit panel.
  498. */
  499. function editbox_post_mur() {
  500. global $post;
  501. gdsr_render_multi_editor(array("post_id" => $post->ID, "admin" => true));
  502. }
  503. /**
  504. * Insert plugin box on post edit panel.
  505. */
  506. function editbox_post() {
  507. global $post;
  508. $gdsr_options = $this->o;
  509. $post_id = $post->ID;
  510. $default = false;
  511. $countdown_value = $gdsr_options["default_timer_countdown_value"];
  512. $countdown_type = $gdsr_options["default_timer_countdown_type"];
  513. $recc_countdown_value = $gdsr_options["default_timer_countdown_value"];
  514. $recc_countdown_type = $gdsr_options["default_timer_countdown_type"];
  515. $timer_date_value = $recc_timer_date_value = "";
  516. if ($post_id == 0) $default = true;
  517. else {
  518. $post_data = GDSRDatabase::get_post_edit($post_id);
  519. if (count($post_data) > 0) {
  520. $rating = explode(".", strval($post_data->review));
  521. $rating_decimal = intval($rating[1]);
  522. $rating = intval($rating[0]);
  523. $recc_vote_rules = $post_data->recc_rules_articles;
  524. $recc_moderation_rules = $post_data->recc_moderate_articles;
  525. $recc_cmm_vote_rules = $post_data->recc_rules_comments;
  526. $recc_cmm_moderation_rules = $post_data->recc_moderate_comments;
  527. $recc_timer_restrictions = $post_data->recc_expiry_type;
  528. if ($recc_timer_restrictions == "T") {
  529. $recc_countdown_type = substr($post_data->recc_expiry_value, 0, 1);
  530. $recc_countdown_value = substr($post_data->recc_expiry_value, 1);
  531. } else if ($recc_timer_restrictions == "D") {
  532. $recc_timer_date_value = $post_data->recc_expiry_value;
  533. }
  534. $vote_rules = $post_data->rules_articles;
  535. $moderation_rules = $post_data->moderate_articles;
  536. $cmm_vote_rules = $post_data->rules_comments;
  537. $cmm_moderation_rules = $post_data->moderate_comments;
  538. $timer_restrictions = $post_data->expiry_type;
  539. if ($timer_restrictions == "T") {
  540. $countdown_type = substr($post_data->expiry_value, 0, 1);
  541. $countdown_value = substr($post_data->expiry_value, 1);
  542. } else if ($timer_restrictions == "D") {
  543. $timer_date_value = $post_data->expiry_value;
  544. }
  545. } else $default = true;
  546. }
  547. if ($default) {
  548. $rating_decimal = $rating = -1;
  549. $recc_vote_rules = $gdsr_options["recc_default_voterules_articles"];
  550. $recc_moderation_rules = $gdsr_options["recc_default_moderation_articles"];
  551. $recc_cmm_vote_rules = $gdsr_options["recc_default_voterules_comments"];
  552. $recc_cmm_moderation_rules = $gdsr_options["recc_default_moderation_comments"];
  553. $recc_timer_restrictions = $gdsr_options["recc_default_timer_type"];
  554. $vote_rules = $gdsr_options["default_voterules_articles"];
  555. $moderation_rules = $gdsr_options["default_moderation_articles"];
  556. $cmm_vote_rules = $gdsr_options["default_voterules_comments"];
  557. $cmm_moderation_rules = $gdsr_options["default_moderation_comments"];
  558. $timer_restrictions = $gdsr_options["default_timer_type"];
  559. }
  560. include($this->plugin_path.'integrate/edit.php');
  561. }
  562. // edit boxes
  563. /**
  564. * Check the user access levels.
  565. *
  566. * @global object $userdata Object with user data.
  567. */
  568. function check_user_access() {
  569. global $userdata;
  570. $this->wp_access_level = isset($userdata->user_level) ? $userdata->user_level : 0;
  571. if ($this->security_users == "0") {
  572. $this->wp_secure_level = $this->wp_access_level > 8;
  573. } else {
  574. $allowed = explode(",", $this->security_users);
  575. if (is_array($allowed)) {
  576. $this->wp_secure_level = in_array($userdata->ID, $allowed);
  577. } else $this->wp_secure_level = false;
  578. }
  579. }
  580. function meta_boxes_30() {
  581. global $wp_meta_boxes;
  582. $post_types = get_post_types(array(), "objects");
  583. foreach ($post_types as $name => $data) {
  584. if ($this->o["integrate_post_edit"] == 1) {
  585. add_meta_box("gdsr-meta-box", "GD Star Rating", array(&$this, 'editbox_post'), $name, "side", "high");
  586. }
  587. if ($this->o["integrate_post_edit_mur"] == 1) {
  588. add_meta_box("gdsr-meta-box-mur", "GD Star Rating: ".__("Multi Ratings Review", "gd-star-rating"), array(&$this, 'editbox_post_mur'), $name, "advanced", "high");
  589. }
  590. }
  591. }
  592. function meta_boxes_pre30() {
  593. if ($this->o["integrate_post_edit"] == 1) {
  594. add_meta_box("gdsr-meta-box", "GD Star Rating", array(&$this, 'editbox_post'), "post", "side", "high");
  595. add_meta_box("gdsr-meta-box", "GD Star Rating", array(&$this, 'editbox_post'), "page", "side", "high");
  596. }
  597. if ($this->o["integrate_post_edit_mur"] == 1) {
  598. add_meta_box("gdsr-meta-box-mur", "GD Star Rating: ".__("Multi Ratings Review", "gd-star-rating"), array(&$this, 'editbox_post_mur'), "post", "advanced", "high");
  599. add_meta_box("gdsr-meta-box-mur", "GD Star Rating: ".__("Multi Ratings Review", "gd-star-rating"), array(&$this, 'editbox_post_mur'), "page", "advanced", "high");
  600. }
  601. }
  602. /**
  603. * WordPress action for adding administration menu items
  604. */
  605. function admin_menu() {
  606. $this->check_user_access();
  607. if ($this->wp_version < 30) $this->meta_boxes_pre30();
  608. if ($this->wp_version > 29) $this->meta_boxes_30();
  609. 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'));
  610. 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"));
  611. if ($this->security_my_ratings) {
  612. 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"));
  613. } else {
  614. 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"));
  615. }
  616. 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"));
  617. 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"));
  618. 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"));
  619. 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"));
  620. if ($this->o["multis_active"] == 1)
  621. 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"));
  622. 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"));
  623. 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"));
  624. 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"));
  625. if ($this->o["admin_ips"] == 1)
  626. 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"));
  627. if ($this->o["admin_import"] == 1)
  628. 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"));
  629. if ($this->o["admin_export"] == 1)
  630. 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"));
  631. $this->custom_actions('admin_menu');
  632. 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"));
  633. 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"));
  634. }
  635. function load_colorbox() {
  636. if ($this->wp_version >= 28) {
  637. wp_enqueue_script('gdsr-colorbox', $this->plugin_url."js/jquery/jquery-colorbox.js", array("jquery"), $this->o["version"], true);
  638. wp_enqueue_style('gdsr-colorbox', $this->plugin_url."css/jquery/colorbox.css");
  639. }
  640. }
  641. function load_jquery() {
  642. if ($this->wp_version < 28) {
  643. wp_enqueue_script('gdsr-jquery-ui', $this->plugin_url."js/jquery/jquery-ui.js", array("jquery"), $this->o["version"], true);
  644. 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);
  645. wp_enqueue_style('gdsr-jquery-ui-tabs', $this->plugin_url."css/jquery/ui.tabs.js");
  646. }
  647. }
  648. function load_datepicker() {
  649. if ($this->wp_version < 28) {
  650. wp_enqueue_script('gdsr-jquery-datepicker', $this->plugin_url."js/jquery/jquery-ui-datepicker.js", array("jquery", "gdsr-jquery-ui"), $this->o["version"], true);
  651. wp_enqueue_style('gdsr-jquery-ui-core', $this->plugin_url."css/jquery/ui.core.css");
  652. wp_enqueue_style('gdsr-jquery-ui-theme', $this->plugin_url."css/jquery/ui.theme.css");
  653. } else {
  654. 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);
  655. wp_enqueue_style('gdsr-jquery-ui-theme', $this->plugin_url."css/jquery/ui.17.css");
  656. }
  657. if(!empty($this->l)) {
  658. $jsFile = $this->plugin_path.'js/i18n'.($this->wp_version < 28 ? '' : '-17').'/jquery-ui-datepicker-'.$this->l.'.js';
  659. if (@file_exists($jsFile) && is_readable($jsFile)) {
  660. $jsUrl = $this->plugin_url.'js/i18n'.($this->wp_version < 28 ? '' : '-17').'/jquery-ui-datepicker-'.$this->l.'.js';
  661. wp_enqueue_script('gdsr-jquery-datepicker-translation', $jsUrl, array("gdsr-jquery-datepicker"), $this->o["version"], true);
  662. }
  663. }
  664. }
  665. function load_corrections() {
  666. wp_enqueue_script('gdsr-js-corrections', $this->plugin_url."js/rating/rating-corrections.js", array(), $this->o["version"], true);
  667. }
  668. /**
  669. * WordPress action for adding administration header contents
  670. */
  671. function admin_head() {
  672. global $parent_file;
  673. //$this->wp_head_javascript();
  674. $this->admin_page = $parent_file;
  675. $datepicker_date = date("Y, n, j");
  676. $tabs_extras = "";
  677. if ($this->admin_plugin_page == "ips" && isset($_GET["gdsr"]) && $_GET["gdsr"] == "iplist") {
  678. $tabs_extras = ", selected: 1";
  679. }
  680. if ($this->script == "post.php" || $this->script == "post-new.php" || $this->script == "page.php") {
  681. echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-editors.js"></script>'.STARRATING_EOL);
  682. $this->include_rating_css_admin();
  683. }
  684. if ($this->admin_plugin) {
  685. wp_admin_css('css/dashboard');
  686. echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_main.css" type="text/css" media="screen" />'.STARRATING_EOL);
  687. echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-admin.js"></script>'.STARRATING_EOL);
  688. if ($this->wp_version < 28) {
  689. echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_wp27.css" type="text/css" media="screen" />'.STARRATING_EOL);
  690. } else {
  691. echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_wp28.css" type="text/css" media="screen" />'.STARRATING_EOL);
  692. }
  693. }
  694. echo('<script type="text/javascript">jQuery(document).ready(function() {'.STARRATING_EOL);
  695. if ($this->admin_plugin) {
  696. if ($this->wp_version >= 28) {
  697. echo('jQuery(".clrboxed").colorbox({width:800, height:470, iframe:true});'.STARRATING_EOL);
  698. }
  699. echo('jQuery("#gdsr_tabs'.($this->wp_version < 28 ? ' > ul' : '').'").tabs({fx: {height: "toggle"}'.$tabs_extras.' });'.STARRATING_EOL);
  700. }
  701. if ($this->admin_plugin || $this->admin_page == "edit.php" || $this->admin_page == "post-new.php" || $this->admin_page == "themes.php") {
  702. echo('if (jQuery().datepicker) jQuery("#gdsr_timer_date_value").datepicker({duration: "fast", minDate: new Date('.$datepicker_date.'), dateFormat: "yy-mm-dd"});'.STARRATING_EOL);
  703. }
  704. if ($this->admin_plugin_page == "tools") {
  705. echo('if (jQuery().datepicker) jQuery("#gdsr_lock_date").datepicker({duration: "fast", dateFormat: "yy-mm-dd"});'.STARRATING_EOL);
  706. }
  707. echo("});</script>".STARRATING_EOL);
  708. if ($this->admin_plugin_page == "settings") {
  709. echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-loaders.js"></script>'.STARRATING_EOL);
  710. }
  711. if ($this->admin_page == "widgets.php" || $this->admin_page == "themes.php") {
  712. if ($this->wp_version < 28) {
  713. echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-widgets.js"></script>'.STARRATING_EOL);
  714. } else if ($this->wp_version > 29) {
  715. echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-widgets-30.js"></script>'.STARRATING_EOL);
  716. } else {
  717. echo('<script type="text/javascript" src="'.$this->plugin_url.'js/rating/rating-widgets-28.js"></script>'.STARRATING_EOL);
  718. }
  719. echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_widgets.css" type="text/css" media="screen" />'.STARRATING_EOL);
  720. }
  721. $this->custom_actions('admin_head');
  722. if ($this->admin_plugin_page == "builder") {
  723. echo('<script type="text/javascript" src="'.$this->plugin_url.'tinymce3/tinymce.js"></script>'.STARRATING_EOL);
  724. if ($this->wp_version > 29) {
  725. echo('<script type="text/javascript" src="'.$this->plugin_url.'tinymce3/tinymce-30.js"></script>'.STARRATING_EOL);
  726. }
  727. }
  728. echo('<link rel="stylesheet" href="'.$this->plugin_url.'css/admin/admin_post.css" type="text/css" media="screen" />'.STARRATING_EOL);
  729. }
  730. /**
  731. * WordPress action to get post ID's from active loop
  732. *
  733. * @param WP_Query $wpq query object
  734. * @return WP_Query query object
  735. */
  736. function loop_start($wp_query) {
  737. if (!is_admin()) {
  738. if ($this->wp_version < 28) global $wp_query;
  739. if (is_array($wp_query->posts)) {
  740. foreach ($wp_query->posts as $p) {
  741. if (!isset($this->c[$p->ID])) $this->c[$p->ID] = 0;
  742. }
  743. }
  744. }
  745. if ($this->wp_version >= 28) return $wp_query;
  746. }
  747. /**
  748. * WordPress action to get and cache comments rating data for a post
  749. *
  750. * @param array $comments post comments
  751. * @param int $post_id post id
  752. * @return array post comments
  753. */
  754. function comments_array($comments, $post_id) {
  755. if (count($comments) > 0 && !is_admin()) {
  756. if ((is_single() && ($this->o["display_comment"] == 1 || $this->o["thumb_display_comment"] == 1)) ||
  757. (is_page() && ($this->o["display_comment_page"] == 1 || $this->o["thumb_display_comment_page"] == 1)) ||
  758. $this->o["override_thumb_display_comment"] == 1 || $this->o["override_display_comment"] == 1) {
  759. $this->cache_comments($post_id);
  760. }
  761. }
  762. return $comments;
  763. }
  764. /**
  765. * Adding WordPress action and filter
  766. */
  767. function actions_filters() {
  768. if (GDSR_WP_ADMIN) {
  769. add_action('admin_menu', array(&$this, 'admin_menu'));
  770. add_action('admin_head', array(&$this, 'admin_head'));
  771. add_filter('plugin_action_links', array(&$this, 'plugin_links'), 10, 2 );
  772. add_action('after_plugin_row', array(&$this,'plugin_check_version'), 10, 2);
  773. if ($this->o["integrate_post_edit_mur"] == 1 || $this->o["integrate_post_edit"] == 1) {
  774. add_action('save_post', array(&$this, 'saveedit_post'));
  775. }
  776. if ($this->o["integrate_dashboard"] == 1) {
  777. add_action('wp_dashboard_setup', array(&$this, 'add_dashboard_widget'));
  778. if (!function_exists('wp_add_dashboard_widget')) add_filter('wp_dashboard_widgets', array(&$this, 'add_dashboard_widget_filter'));
  779. }
  780. if ($this->o["integrate_tinymce"] == 1) {
  781. add_filter("mce_external_plugins", array(&$this, 'add_tinymce_plugin'), 5);
  782. add_filter('mce_buttons', array(&$this, 'add_tinymce_button'), 5);
  783. }
  784. } else {
  785. add_action('wp_head', array(&$this, 'wp_head'));
  786. add_action('gdsr_gsr_insert_snippet', array(&$this->f, 'insert_google_rich_snippet'));
  787. add_filter('query_vars', array($this->q, 'query_vars'));
  788. add_action('pre_get_posts', array($this->q, 'pre_get_posts'));
  789. add_filter('comment_text', array(&$this, 'display_comment'), 10000);
  790. add_filter('the_content', array(&$this, 'display_article'));
  791. add_action('loop_start', array(&$this, 'loop_start'));
  792. add_filter('preprocess_comment', array(&$this, 'comment_read_post'));
  793. add_filter('comment_post', array(&$this, 'comment_save'));
  794. if ($this->o["integrate_rss_powered"] == 1 || $this->o["rss_active"] == 1) {
  795. add_filter('the_excerpt_rss', array(&$this, 'rss_filter'));
  796. add_filter('the_content_rss', array(&$this, 'rss_filter'));
  797. add_filter('the_content', array(&$this, 'rss_filter'));
  798. }
  799. if ($this->o["cached_loading"] == 0) {
  800. add_filter('comments_array', array(&$this, 'comments_array'), 10, 2);
  801. }
  802. }
  803. add_action('init', array(&$this, 'init'));
  804. add_action('widgets_init', array(&$this, 'widgets_init'));
  805. add_action('delete_comment', array(&$this, 'comment_delete'));
  806. add_action('delete_post', array(&$this, 'post_delete'));
  807. foreach ($this->shortcodes as $code) $this->shortcode_action($code);
  808. }
  809. /**
  810. * WordPress widgets init action
  811. */
  812. function widgets_init() {
  813. if ($this->wp_version < 28) {
  814. $this->widgets = new gdsrWidgets($this->g, $this->default_widget_comments, $this->default_widget_top, $this->default_widget);
  815. if ($this->o["widget_articles"] == 1) $this->widgets->widget_articles_init();
  816. if ($this->o["widget_top"] == 1) $this->widgets->widget_top_init();
  817. if ($this->o["widget_comments"] == 1) $this->widgets->widget_comments_init();
  818. } else {
  819. if ($this->o["widget_articles"] == 1) register_widget("gdsrWidgetRating");
  820. if ($this->o["widget_top"] == 1) register_widget("gdsrWidgetTop");
  821. if ($this->o["widget_comments"] == 1) register_widget("gdsrWidgetComments");
  822. }
  823. }
  824. /**
  825. * Adds Settings link to plugins panel grid
  826. */
  827. function plugin_links($links, $file) {
  828. static $this_plugin;
  829. if (!$this_plugin) $this_plugin = plugin_basename($this->plugin_base);
  830. if ($file == $this_plugin){
  831. $settings_link = '<a href="admin.php?page=gd-star-rating-settings">'.__("Settings", "gd-star-rating").'</a>';
  832. array_unshift($links, $settings_link);
  833. }
  834. return $links;
  835. }
  836. /**
  837. * Render update info on the plugins panel if the update is available.
  838. *
  839. * @param string $file name of the plugin file
  840. * @param array $plugin_data plugin info
  841. * @return bool false if no update available
  842. */
  843. function plugin_check_version($file, $plugin_data) {
  844. static $this_plugin;
  845. if (!$this_plugin) $this_plugin = plugin_basename($this->plugin_base);
  846. if ($file == $this_plugin){
  847. $current = $this->wp_version < 28 ? get_option('update_plugins') : get_transient('update_plugins');
  848. if (!isset($current->response[$file])) return false;
  849. $columns = $this->wp_version < 28 ? 5 : 3;
  850. $url = gdFunctionsGDSR::get_update_url($this->o, get_option('home'));
  851. $update = wp_remote_fopen($url);
  852. if ($update != "") {
  853. echo '<td colspan="'.$columns.'" class="gdr-plugin-update"><div class="gdr-plugin-update-message">';
  854. echo $update;
  855. echo '</div></td>';
  856. }
  857. }
  858. }
  859. /**
  860. * WordPress rss content filter
  861. */
  862. function rss_filter($content) {
  863. if (is_feed()) {
  864. if ($this->o["rss_active"] == 1) $content.= "<br />".$this->f->render_article_rss();
  865. if ($this->o["integrate_rss_powered"] == 1) $content.= "<br />".$this->powered_by();
  866. $content.= "<br />";
  867. }
  868. return $content;
  869. }
  870. /**
  871. * Renders tag with link and powered by button
  872. *
  873. * @return string rendered content
  874. */
  875. function powered_by() {
  876. return '<a target="_blank" href="http://www.gdstarrating.com/"><img src="'.STARRATING_URL.'gfx/powered.png" border="0" width="80" height="15" /></a>';
  877. }
  878. function get_users_votes($user_id, $limit = 100, $filter = array()) {
  879. $sett = array();
  880. $sett["integrate_dashboard_latest_count"] = $limit;
  881. $settings = shortcode_atts($this->default_user_ratings_filter, $filter);
  882. foreach ($settings as $name => $value) {
  883. $sett["integrate_dashboard_latest_filter_".$name] = $value;
  884. }
  885. return gdsrDB::filter_latest_votes($sett, $user_id);
  886. }
  887. function add_dashboard_widget() {
  888. global $userdata;
  889. $user_level = intval($userdata->user_level);
  890. if ($user_level >= intval($this->o["security_showdashboard_user_level"])) {
  891. if (!function_exists('wp_add_dashboard_widget')) {
  892. if ($this->o["integrate_dashboard_latest"] == 1)
  893. 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'));
  894. } else {
  895. if ($this->o["integrate_dashboard_latest"] == 1)
  896. wp_add_dashboard_widget("dashboard_gdstarrating_latest", "GD Star Rating ".__("Latest", "gd-star-rating"), array(&$this, 'display_dashboard_widget_latest'));
  897. }
  898. }
  899. }
  900. function add_dashboard_widget_filter($widgets) {
  901. global $userdata;
  902. $user_level = intval($userdata->user_level);
  903. if ($user_level >= intval($this->o["security_showdashboard_user_level"])) {
  904. global $wp_registered_widgets;
  905. if (!isset($wp_registered_widgets["dashboard_gdstarrating_latest"])) return $widgets;
  906. if ($this->o["integrate_dashboard_latest"] == 1)
  907. array_splice($widgets, 2, 0, "dashboard_gdstarrating_latest");
  908. }
  909. return $widgets;
  910. }
  911. function display_dashboard_widget_chart($sidebar_args) {
  912. if (!function_exists('wp_add_dashboard_widget')) {
  913. extract($sidebar_args, EXTR_SKIP);
  914. echo $before_widget.$before_title.$widget_name.$after_title;
  915. }
  916. include($this->plugin_path.'integrate/dash_chart.php');
  917. if (!function_exists('wp_add_dashboard_widget')) echo $after_widget;
  918. }
  919. function display_dashboard_widget_latest($sidebar_args) {
  920. if (!function_exists('wp_add_dashboard_widget')) {
  921. extract($sidebar_args, EXTR_SKIP);
  922. echo $before_widget.$before_title.$widget_name.$after_title;
  923. }
  924. $o = $this->o;
  925. include($this->plugin_path.'integrate/dash_latest.php');
  926. if (!function_exists('wp_add_dashboard_widget')) echo $after_widget;
  927. }
  928. function comment_read_post($comment) {
  929. $this->post_comment["post_id"] = $_POST["comment_post_ID"];
  930. $this->post_comment["review"] = isset($_POST["gdsr_cmm_value"]) ? intval($_POST["gdsr_cmm_value"]) : -1;
  931. $this->post_comment["standard_rating"] = isset($_POST["gdsr_int_value"]) ? intval($_POST["gdsr_int_value"]) : -1;
  932. $this->post_comment["multi_rating"] = isset($_POST["gdsr_mur_value"]) ? $_POST["gdsr_mur_value"] : "";
  933. $this->post_comment["multi_id"] = isset($_POST["gdsr_mur_set"]) ? intval($_POST["gdsr_mur_set"]) : 0;
  934. return $comment;
  935. }
  936. function comment_save($comment_id) {
  937. global $userdata;
  938. $user_id = is_object($userdata) ? $userdata->ID : 0;
  939. $user = intval($user_id);
  940. $ip = $_SERVER["REMOTE_ADDR"];
  941. if ($this->post_comment["review"] > -1) {
  942. $comment_data = GDSRDatabase::get_comment_data($comment_id);
  943. if (count($comment_data) == 0) GDSRDatabase::add_empty_comment($comment_id, $this->post_comment["post_id"], $this->post_comment["review"]);
  944. else GDSRDatabase::save_comment_review($comment_id, $this->post_comment["review"]);
  945. }
  946. $std_minimum = $this->o["int_comment_std_zero"] == 1 ? -1 : 0;
  947. $mur_minimum = $this->o["int_comment_mur_zero"] == 1 ? 0 : 1;
  948. $id = $this->post_comment["post_id"];
  949. if ($this->post_comment["standard_rating"] > $std_minimum) {
  950. $votes = $this->post_comment["standard_rating"];
  951. $ua = $this->o["save_user_agent"] == 1 ? $_SERVER["HTTP_USER_AGENT"] : "";
  952. $allow_vote = true;
  953. if ($this->o["cmm_integration_prevent_duplicates"] == 1) {
  954. $allow_vote = intval($votes) <= $this->o["stars"];
  955. if ($allow_vote) $allow_vote = gdsrFrontHelp::check_cookie($id);
  956. if ($allow_vote) $allow_vote = gdsrBlgDB::check_vote($id, $user, 'article', $ip, false, false);
  957. }
  958. if ($allow_vote) {
  959. gdsrBlgDB::save_vote($id, $user, $ip, $ua, $

Large files files are truncated, but you can click here to view the full file