PageRenderTime 70ms CodeModel.GetById 17ms 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
  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, $votes, $comment_id);
  960. if ($this->o["cmm_integration_prevent_duplicates"] == 1) gdsrFrontHelp::save_cookie($id);
  961. do_action("gdsr_vote_rating_article_integrate", $id, $user, $votes);
  962. }
  963. }
  964. if ($this->post_comment["multi_id"] > 0 && $this->post_comment["multi_rating"] != "") {
  965. $set_id = $this->post_comment["multi_id"];
  966. $set = gd_get_multi_set($set_id);
  967. $values = explode("X", $this->post_comment["multi_rating"]);
  968. $allow_vote = true;
  969. foreach ($values as $v) {
  970. if ($v > $set->stars || $v < $mur_minimum) {
  971. $allow_vote = false;
  972. break;
  973. }
  974. }
  975. if ($this->o["cmm_integration_prevent_duplicates"] == 1) {
  976. if ($allow_vote) $allow_vote = gdsrFrontHelp::check_cookie($id."#".$set_id, "multis");
  977. if ($allow_vote) $allow_vote = GDSRDBMulti::check_vote($id, $user, $set_id, 'multis', $ip, false, false);
  978. }
  979. if ($allow_vote) {
  980. $ip = $_SERVER["REMOTE_ADDR"];
  981. $ua = $this->o["save_user_agent"] == 1 ? $_SERVER["HTTP_USER_AGENT"] : "";
  982. $data = GDSRDatabase::get_post_data($id);
  983. GDSRDBMulti::save_vote($id, $set->multi_id, $user, $ip, $ua, $values, $data, $comment_id);
  984. GDSRDBMulti::recalculate_multi_averages($id, $set->multi_id, "", $set, true);
  985. if ($this->o["cmm_integration_prevent_duplicates"] == 1) gdsrFrontHelp::save_cookie($id."#".$set_id, "multis");
  986. do_action("gdsr_vote_rating_multis_integrate", $id, $user, $set_id, $values);
  987. }
  988. }
  989. }
  990. function comment_delete($comment_id) {
  991. GDSRDatabase::delete_by_comment($comment_id);
  992. GDSRDBMulti::delete_by_comment($comment_id);
  993. }
  994. function post_delete($post_id) { }
  995. /**
  996. * Triggers saving GD Star Rating data for post.
  997. *
  998. * @param int $post_id ID of the post saving
  999. */
  1000. function saveedit_post($post_id) {
  1001. if (isset($_POST["post_ID"]) && $_POST["post_ID"] > 0)
  1002. $post_id = $_POST["post_ID"];
  1003. if ((isset($_POST['gdsr_post_edit']) && $_POST['gdsr_post_edit'] == "edit") || (isset($_POST['gdsr_post_edit_mur']) && $_POST['gdsr_post_edit_mur'] == "edit")) {
  1004. if ($this->o["integrate_post_edit"] == 1 && isset($_POST["gdsrmultiactive"])) {
  1005. $set_id = intval($_POST["gdsrmultiactive"]);
  1006. if ($set_id > 0) {
  1007. $mur = $_POST['gdsrmulti'];
  1008. $mur = isset($mur[$post_id]) ? $mur[$post_id][$set_id] : $mur[0][$set_id];
  1009. $values = explode("X", $mur);
  1010. $set = gd_get_multi_set($set_id);
  1011. $record_id = GDSRDBMulti::get_vote($post_id, $set_id, count($set->object));
  1012. GDSRDBMulti::save_review($record_id, $values);
  1013. GDSRDBMulti::recalculate_multi_review($record_id, $values, $set);
  1014. $this->o["mur_review_set"] = $_POST["gdsrmultiset"];
  1015. update_option('gd-star-rating', $this->o);
  1016. }
  1017. }
  1018. $old = gdsrAdmDB::check_post_review($post_id);
  1019. $review = $_POST['gdsr_review'];
  1020. if ($_POST['gdsr_review_decimal'] != "-1") $review.= ".".$_POST['gdsr_review_decimal'];
  1021. GDSRDatabase::save_review($post_id, $review, $old);
  1022. $old = true;
  1023. GDSRDatabase::save_article_rules($post_id,
  1024. isset($_POST['gdsr_vote_articles']) ? $_POST['gdsr_vote_articles'] : "A",
  1025. isset($_POST['gdsr_mod_articles']) ? $_POST['gdsr_mod_articles'] : "N",
  1026. isset($_POST['gdsr_recc_vote_articles']) ? $_POST['gdsr_recc_vote_articles'] : "A",
  1027. isset($_POST['gdsr_recc_mod_articles']) ? $_POST['gdsr_recc_mod_articles'] : "N");
  1028. if ($this->o["comments_active"] == 1) {
  1029. GDSRDatabase::save_comment_rules($post_id,
  1030. isset($_POST['gdsr_cmm_vote_articles']) ? $_POST['gdsr_cmm_vote_articles'] : "A",
  1031. isset($_POST['gdsr_cmm_mod_articles']) ? $_POST['gdsr_cmm_mod_articles'] : "N",
  1032. isset($_POST['gdsr_recc_cmm_vote_articles']) ? $_POST['gdsr_recc_cmm_vote_articles'] : "A",
  1033. isset($_POST['gdsr_recc_cmm_mod_articles']) ? $_POST['gdsr_recc_cmm_mod_articles'] : "N");
  1034. }
  1035. if (isset($_POST['gdsr_timer_type'])) {
  1036. $timer = $_POST['gdsr_timer_type'];
  1037. GDSRDatabase::save_timer_rules(
  1038. $post_id,
  1039. $timer,
  1040. GDSRHelper::timer_value($timer,
  1041. isset($_POST['gdsr_timer_date_value']) ? $_POST['gdsr_timer_date_value'] : "",
  1042. isset($_POST['gdsr_timer_countdown_value']) ? $_POST['gdsr_timer_countdown_value'] : "",
  1043. isset($_POST['gdsr_timer_countdown_type']) ? $_POST['gdsr_timer_countdown_type'] : "")
  1044. );
  1045. }
  1046. if (isset($_POST['gdsr_timer_type_recc'])) {
  1047. $timer = $_POST['gdsr_timer_type_recc'];
  1048. GDSRDatabase::save_timer_rules_thumbs(
  1049. $post_id,
  1050. $timer,
  1051. GDSRHelper::timer_value($timer,
  1052. isset($_POST['gdsr_recc_timer_date_value']) ? $_POST['gdsr_recc_timer_date_value'] : "",
  1053. isset($_POST['gdsr_recc_timer_countdown_value']) ? $_POST['gdsr_recc_timer_countdown_value'] : "",
  1054. isset($_POST['gdsr_recc_timer_countdown_type']) ? $_POST['gdsr_recc_timer_countdown_type'] : "")
  1055. );
  1056. }
  1057. }
  1058. }
  1059. /**
  1060. * Main installation method of the plugin
  1061. */
  1062. function install_plugin() {
  1063. $this->o = get_option('gd-star-rating');
  1064. $this->i = get_option('gd-star-rating-import');
  1065. $this->g = get_option('gd-star-rating-gfx');
  1066. $this->wpr8 = get_option('gd-star-rating-wpr8');
  1067. $this->ginc = get_option('gd-star-rating-inc');
  1068. $this->bots = get_option('gd-star-rating-bots');
  1069. if (!STARRATING_AJAX && GDSR_WP_ADMIN) {
  1070. if ($this->o["build"] != $this->default_options["build"] || !is_array($this->o)) {
  1071. if (is_object($this->g)) {
  1072. $this->g = gdsrAdmFunc::gfx_scan();
  1073. update_option('gd-star-rating-gfx', $this->g);
  1074. }
  1075. require_once(STARRATING_PATH."/gdragon/gd_db_install.php");
  1076. if ($this->o["build"] < 911)
  1077. gdDBInstallGDSR::upgrade_collation(STARRATING_PATH);
  1078. gdDBInstallGDSR::delete_tables(STARRATING_PATH);
  1079. gdDBInstallGDSR::delete_columns(STARRATING_PATH);
  1080. gdDBInstallGDSR::create_tables(STARRATING_PATH);
  1081. gdDBInstallGDSR::upgrade_tables(STARRATING_PATH);
  1082. gdDBInstallGDSR::alter_tables(STARRATING_PATH);
  1083. gdDBInstallGDSR::alter_index(STARRATING_PATH);
  1084. $this->o["database_upgrade"] = date("r");
  1085. gdsrAdmDB::install_all_templates();
  1086. $this->o = gdFunctionsGDSR::upgrade_settings($this->o, $this->default_options);
  1087. $this->o["css_last_changed"] = time();
  1088. $this->o["version"] = $this->default_options["version"];
  1089. $this->o["code_name"] = $this->default_options["code_name"];
  1090. $this->o["date"] = $this->default_options["date"];
  1091. $this->o["status"] = $this->default_options["status"];
  1092. $this->o["build"] = $this->default_options["build"];
  1093. $this->o["revision"] = $this->default_options["revision"];
  1094. $this->is_update = true;
  1095. update_option('gd-star-rating', $this->o);
  1096. }
  1097. if (!is_array($this->o)) {
  1098. update_option('gd-star-rating', $this->default_options);
  1099. $this->o = get_option('gd-star-rating');
  1100. gdDBInstallGDSR::create_tables(STARRATING_PATH);
  1101. }
  1102. if (!is_array($this->i)) {
  1103. update_option('gd-star-rating-import', $this->default_import);
  1104. $this->i = get_option('gd-star-rating-import');
  1105. } else {
  1106. $this->i = gdFunctionsGDSR::upgrade_settings($this->i, $this->default_import);
  1107. update_option('gd-star-rating-import', $this->i);
  1108. }
  1109. if (!is_object($this->g)) {
  1110. $this->g = gdsrAdmFunc::gfx_scan();
  1111. update_option('gd-star-rating-gfx', $this->g);
  1112. }
  1113. if (!is_array($this->wpr8)) {
  1114. update_option('gd-star-rating-wpr8', $this->default_wpr8);
  1115. $this->wpr8 = get_option('gd-star-rating-wpr8');
  1116. } else {
  1117. $this->wpr8 = gdFunctionsGDSR::upgrade_settings($this->wpr8, $this->default_wpr8);
  1118. update_option('gd-star-rating-wpr8', $this->wpr8);
  1119. }
  1120. if (!is_array($this->bots)) {
  1121. $this->bots = $this->default_spider_bots;
  1122. update_option('gd-star-rating-bots', $this->bots);
  1123. }
  1124. if (!is_array($this->ginc)) {
  1125. $this->ginc = array();
  1126. $this->ginc[] = $this->stars_sizes;
  1127. $this->ginc[] = $this->g->get_list(true);
  1128. $this->ginc[] = $this->thumb_sizes;
  1129. $this->ginc[] = $this->g->get_list(false);
  1130. update_option('gd-star-rating-inc', $this->ginc);
  1131. }
  1132. if (count($this->ginc) == 2) {
  1133. $this->ginc[] = $this->thumb_sizes;
  1134. $this->ginc[] = $this->g->get_list(false);
  1135. update_option('gd-star-rating-inc', $this->ginc);
  1136. }
  1137. }
  1138. $this->script = basename($_SERVER["PHP_SELF"]);
  1139. }
  1140. /**
  1141. * Calculates all needed paths and sets them as constants.
  1142. *
  1143. * @global string $wp_version wordpress version
  1144. */
  1145. function plugin_path_url() {
  1146. global $wp_version;
  1147. $this->wp_version = substr(str_replace('.', '', $wp_version), 0, 2);
  1148. $this->plugin_url = plugins_url('/gd-star-rating/');
  1149. $this->plugin_xtra_url = content_url('/gd-star-rating/');
  1150. $this->plugin_xtra_path = WP_CONTENT_DIR.'/gd-star-rating/';
  1151. $this->plugin_cache_path = $this->plugin_xtra_path."cache/";
  1152. $this->plugin_ajax = $this->plugin_url.'ajax.php';
  1153. $this->plugin_chart_path = $this->plugin_path."options/charts/";
  1154. $this->plugin_chart_url = $this->plugin_url."options/charts/";
  1155. define('STARRATING_URL', $this->plugin_url);
  1156. define('STARRATING_PATH', $this->plugin_path);
  1157. define('STARRATING_XTRA_URL', $this->plugin_xtra_url);
  1158. define('STARRATING_XTRA_PATH', $this->plugin_xtra_path);
  1159. define('STARRATING_CACHE_PATH', $this->plugin_cache_path);
  1160. define('STARRATING_CHART_URL', $this->plugin_chart_url);
  1161. define('STARRATING_CHART_PATH', $this->plugin_chart_path);
  1162. }
  1163. /**
  1164. * Executes attached hook actions methods for plugin internal actions.
  1165. * - init: executed after init method
  1166. *
  1167. * @param <type> $action name of the plugin action
  1168. */
  1169. function custom_actions($action) {
  1170. do_action('gdsr_'.$action);
  1171. }
  1172. /**
  1173. * Main init method executed as wordpress action 'init'.
  1174. */
  1175. function init() {
  1176. $this->is_ie6 = $this->o["disable_ie6_check"] == 1 ? false : is_msie6();
  1177. if ($this->is_update) GDSRDatabase::init_categories_data();
  1178. if (is_admin()) {
  1179. gdsrAdmFunc::init_uninstall();
  1180. gdsrAdmFunc::init_templates();
  1181. $this->init_operations();
  1182. $this->load_translation();
  1183. }
  1184. wp_enqueue_script('jquery');
  1185. if (!is_admin()) {
  1186. $this->is_bot = gdsrFrontHelp::detect_bot($_SERVER['HTTP_USER_AGENT'], $this->bots);
  1187. $this->is_ban = gdsrFrontHelp::detect_ban();
  1188. if ($this->o["cached_loading"] != 1) {
  1189. $this->f->render_wait_article();
  1190. $this->f->render_wait_comment();
  1191. $this->f->render_wait_multis();
  1192. $this->f->render_wait_article_thumb();
  1193. $this->f->render_wait_comment_thumb();
  1194. }
  1195. $js_name = STARRATING_JAVASCRIPT_DEBUG ? 'gd-star-rating/js/gdsr.debug.js' : 'gd-star-rating/js/gdsr.js';
  1196. wp_enqueue_script("gdsr_script", plugins_url($js_name), array(), $this->o["version"]);
  1197. if ($this->o["external_rating_css"] == 1) {
  1198. wp_enqueue_style("gdsr_style_main", $this->include_rating_css(true, true), array(), $this->o["version"]);
  1199. }
  1200. if ($this->o["external_css"] == 1 && file_exists($this->plugin_xtra_path."css/rating.css")) {
  1201. wp_enqueue_style("gdsr_style_xtra", $this->plugin_xtra_url."css/rating.css", array(), $this->o["version"]);
  1202. }
  1203. } else {
  1204. if (isset($_GET["page"])) {
  1205. if (substr($_GET["page"], 0, 14) == "gd-star-rating") {
  1206. $this->admin_plugin = true;
  1207. $this->admin_plugin_page = substr($_GET["page"], 15);
  1208. } else {
  1209. $this->admin_plugin = false;
  1210. }
  1211. }
  1212. if ($this->admin_plugin) {
  1213. if ($this->wp_version >= 28) {
  1214. wp_enqueue_script('jquery-ui-core');
  1215. wp_enqueue_script('jquery-ui-tabs');
  1216. }
  1217. $this->load_datepicker();
  1218. }
  1219. $this->cache_cleanup();
  1220. $this->init_specific_pages();
  1221. }
  1222. if (is_admin() && $this->o["mur_review_set"] == 0) {
  1223. $set = GDSRDBMulti::get_multis(0, 1);
  1224. if (count($set) > 0) {
  1225. $this->o["mur_review_set"] = $set[0]->multi_id;
  1226. update_option('gd-star-rating', $this->o);
  1227. }
  1228. }
  1229. $this->custom_actions('init');
  1230. }
  1231. /**
  1232. * Initialization of plugin panels
  1233. */
  1234. function init_specific_pages() {
  1235. if ($this->admin_plugin_page == "settings") {
  1236. $gdsr_options = $this->o;
  1237. include ($this->plugin_path."code/adm/save_settings.php");
  1238. $this->o = $gdsr_options;
  1239. }
  1240. if ($this->admin_plugin_page == "gfx-page") {
  1241. $gdsr_options = $this->o;
  1242. $ginc = $this->ginc;
  1243. $ginc_sizes = $this->ginc[0];
  1244. $ginc_stars = $this->ginc[1];
  1245. $ginc_sizes_thumb = $this->ginc[2];
  1246. $ginc_stars_thumb = $this->ginc[3];
  1247. include ($this->plugin_path."code/adm/save_gfx.php");
  1248. $this->o = $gdsr_options;
  1249. $this->ginc = $ginc;
  1250. }
  1251. if ($this->admin_plugin_page == "multi-sets" ||
  1252. $this->admin_plugin_page == "t2") $this->load_corrections();
  1253. if ($this->admin_plugin) {
  1254. $this->load_colorbox();
  1255. $this->load_jquery();
  1256. $this->safe_mode = gdFunctionsGDSR::php_in_safe_mode();
  1257. if (!$this->safe_mode)
  1258. $this->extra_folders = $this->o["cache_forced"] == 1 || GDSRHelper::create_folders($this->wp_version);
  1259. }
  1260. }
  1261. /**
  1262. * Loads plugin translation file.
  1263. */
  1264. function load_translation() {
  1265. $this->l = get_locale();
  1266. if(!empty($this->l)) {
  1267. $moFile = $this->plugin_path."/languages/gd-star-rating-".$this->l.".mo";
  1268. if (@file_exists($moFile) && is_readable($moFile)) load_textdomain('gd-star-rating', $moFile);
  1269. }
  1270. }
  1271. function wp_head_javascript() {
  1272. echo '<script type="text/javascript">'.STARRATING_EOL;
  1273. echo '//<![CDATA['.STARRATING_EOL;
  1274. echo 'var gdsr_cnst_nonce = "'.wp_create_nonce('gdsr_ajax_r8').'";'.STARRATING_EOL;
  1275. echo 'var gdsr_cnst_ajax = "'.STARRATING_AJAX_URL.'";'.STARRATING_EOL;
  1276. echo 'var gdsr_cnst_button = '.$this->o["mur_button_active"].';'.STARRATING_EOL;
  1277. echo 'var gdsr_cnst_cache = '.$this->o["cached_loading"].';'.STARRATING_EOL;
  1278. if ($this->o["cmm_integration_replay_hide_review"]) {
  1279. echo 'jQuery(document).ready(function() { jQuery(".comment-reply-link").click(function() { hideshowCmmInt(); }); });'.STARRATING_EOL;
  1280. }
  1281. echo '// ]]>'.STARRATING_EOL;
  1282. echo '</script>'.STARRATING_EOL;
  1283. }
  1284. /**
  1285. * WordPress action for adding blog header contents
  1286. */
  1287. function wp_head() {
  1288. $this->f->init_google_rich_snippet();
  1289. if (is_feed()) return;
  1290. $this->wp_head_javascript();
  1291. $include_cmm_review = $this->o["comments_review_active"] == 1;
  1292. $include_mur_rating = $this->o["multis_active"] == 1;
  1293. if ($this->o["external_rating_css"] == 0) $this->include_rating_css(false);
  1294. if ($this->o["debug_wpquery"] == 1) {
  1295. global $wp_query;
  1296. wp_gdsr_dump("WP_QUERY", $wp_query->request);
  1297. }
  1298. $this->custom_actions('wp_head');
  1299. if ($this->o["ie_opacity_fix"] == 1) gdsrFrontHelp::ie_opacity_fix();
  1300. }
  1301. /**
  1302. * Prepare multi sets for rendering.
  1303. */
  1304. function prepare_multiset() {
  1305. $this->rendering_sets = GDSRDBMulti::get_multisets_for_auto_insert();
  1306. if (!is_array($this->rendering_sets)) $this->rendering_sets = array();
  1307. }
  1308. function init_operations() {
  1309. $msg = "";
  1310. if (isset($_POST["gdsr_multi_review_form"]) && $_POST["gdsr_multi_review_form"] == "review") {
  1311. $mur_all = $_POST['gdsrmulti'];
  1312. foreach ($mur_all as $post_id => $data) {
  1313. if ($post_id > 0) {
  1314. foreach ($data as $set_id => $mur) {
  1315. $set = gd_get_multi_set($set_id);
  1316. $values = explode("X", $mur);
  1317. $record_id = GDSRDBMulti::get_vote($post_id, $set_id, count($set->object));
  1318. GDSRDBMulti::save_review($record_id, $values);
  1319. GDSRDBMulti::recalculate_multi_review($record_id, $values, $set);
  1320. }
  1321. }
  1322. }
  1323. $this->custom_actions('init_save_review');
  1324. wp_redirect_self();
  1325. exit;
  1326. }
  1327. if (isset($_POST["gdsr_editcss_rating"])) {
  1328. $rating_css = STARRATING_XTRA_PATH."css/rating.css";
  1329. if (is_writeable($rating_css)) {
  1330. $newcontent = stripslashes($_POST['gdsr_editcss_contents']);
  1331. $f = fopen($rating_css, 'w+');
  1332. fwrite($f, $newcontent);
  1333. fclose($f);
  1334. }
  1335. wp_redirect_self();
  1336. exit;
  1337. }
  1338. if (isset($_POST['gdsr_debug_clean'])) {
  1339. wp_gdsr_debug_clean();
  1340. wp_redirect_self();
  1341. exit;
  1342. }
  1343. if (isset($_POST['gdsr_cache_clean'])) {
  1344. GDSRHelper::clean_cache(substr(STARRATING_CACHE_PATH, 0, strlen(STARRATING_CACHE_PATH) - 1));
  1345. $this->o["cache_cleanup_last"] = date("r");
  1346. update_option('gd-star-rating', $this->o);
  1347. wp_redirect_self();
  1348. exit;
  1349. }
  1350. if (isset($_POST['gdsr_preview_scan'])) {
  1351. $this->g = gdsrAdmFunc::gfx_scan();
  1352. update_option('gd-star-rating-gfx', $this->g);
  1353. wp_redirect_self();
  1354. exit;
  1355. }
  1356. if (isset($_POST['gdsr_t2_import'])) {
  1357. gdsrAdmDB::insert_extras_templates(STARRATING_XTRA_PATH, false);
  1358. wp_redirect_self();
  1359. exit;
  1360. }
  1361. if (isset($_POST['gdsr_reset_db_tool'])) {
  1362. gdsrAdmDB::reset_db_tool();
  1363. gdsrAdmDBMulti::reset_db_tool();
  1364. wp_redirect_self();
  1365. exit;
  1366. }
  1367. if (isset($_POST['gdsr_upgrade_tool'])) {
  1368. require_once(STARRATING_PATH."/gdragon/gd_db_install.php");
  1369. gdDBInstallGDSR::delete_tables(STARRATING_PATH);
  1370. gdDBInstallGDSR::create_tables(STARRATING_PATH);
  1371. gdDBInstallGDSR::upgrade_tables(STARRATING_PATH);
  1372. gdDBInstallGDSR::alter_tables(STARRATING_PATH);
  1373. gdDBInstallGDSR::alter_tables(STARRATING_PATH, "idx.txt");
  1374. $this->o["database_upgrade"] = date("r");
  1375. update_option('gd-star-rating', $this->o);
  1376. wp_redirect_self();
  1377. exit;
  1378. }
  1379. if (isset($_POST['gdsr_updatemultilog_tool'])) {
  1380. GDSRDBMulti::recalculate_multi_rating_log();
  1381. wp_redirect_self();
  1382. exit;
  1383. }
  1384. if (isset($_POST['gdsr_mulitrecalc_tool'])) {
  1385. $set_id = $_POST['gdsr_mulitrecalc_set'];
  1386. if ($set_id > 0) GDSRDBMulti::recalculate_set($set_id);
  1387. else GDSRDBMulti::recalculate_all_sets();
  1388. wp_redirect_self();
  1389. exit;
  1390. }
  1391. if (isset($_POST['gdsr_cleanup_tool'])) {
  1392. if (isset($_POST['gdsr_tools_clean_invalid_log'])) {
  1393. $count = gdsrTlsDB::clean_invalid_log_articles();
  1394. if ($count > 0) $msg.= $count." ".__("articles records from log table removed.", "gd-star-rating")." ";
  1395. $count = gdsrTlsDB::clean_invalid_log_comments();
  1396. if ($count > 0) $msg.= $count." ".__("comments records from log table removed.", "gd-star-rating")." ";
  1397. }
  1398. if (isset($_POST['gdsr_tools_clean_invalid_trend'])) {
  1399. $count = gdsrTlsDB::clean_invalid_trend_articles();
  1400. if ($count > 0) $msg.= $count." ".__("articles records from trends log table removed.", "gd-star-rating")." ";
  1401. $count = gdsrTlsDB::clean_invalid_trend_comments();
  1402. if ($count > 0) $msg.= $count." ".__("comments records from trends log table removed.", "gd-star-rating")." ";
  1403. }
  1404. if (isset($_POST['gdsr_tools_clean_old_posts'])) {
  1405. $count = gdsrTlsDB::clean_dead_articles();
  1406. if ($count > 0) $msg.= $count." ".__("dead articles records from articles table.", "gd-star-rating")." ";
  1407. $count = gdsrTlsDB::clean_revision_articles();
  1408. if ($count > 0) $msg.= $count." ".__("post revisions records from articles table.", "gd-star-rating")." ";
  1409. $count = gdsrTlsDB::clean_dead_comments();
  1410. if ($count > 0) $msg.= $count." ".__("dead comments records from comments table.", "gd-star-rating")." ";
  1411. }
  1412. if (isset($_POST['gdsr_tools_clean_old_posts'])) {
  1413. $count = GDSRDBMulti::clean_dead_articles();
  1414. if ($count > 0) $msg.= $count." ".__("dead articles records from multi ratings tables.", "gd-star-rating")." ";
  1415. $count = GDSRDBMulti::clean_revision_articles();
  1416. if ($count > 0) $msg.= $count." ".__("post revisions records from multi ratings tables.", "gd-star-rating")." ";
  1417. }
  1418. $this->o["database_cleanup"] = date("r");
  1419. $this->o["database_cleanup_msg"] = $msg;
  1420. update_option('gd-star-rating', $this->o);
  1421. wp_redirect_self();
  1422. exit;
  1423. }
  1424. if (isset($_POST['gdsr_post_lock'])) {
  1425. $lock_date = $_POST['gdsr_lock_date'];
  1426. gdsrAdmDB::lock_post_massive($lock_date);
  1427. $this->o["mass_lock"] = $lock_date;
  1428. update_option('gd-star-rating', $this->o);
  1429. wp_redirect_self();
  1430. exit;
  1431. }
  1432. if (isset($_POST['gdsr_rules_set'])) {
  1433. gdsrAdmDB::update_settings_full($_POST["gdsr_article_moderation"], $_POST["gdsr_article_voterules"],
  1434. $_POST["gdsr_comments_moderation"], $_POST["gdsr_comments_voterules"],
  1435. $_POST["gdsr_artthumb_moderation"], $_POST["gdsr_artthumb_voterules"],
  1436. $_POST["gdsr_cmmthumbs_moderation"], $_POST["gdsr_cmmthumbs_voterules"]);
  1437. wp_redirect_self();
  1438. exit;
  1439. }
  1440. }
  1441. function init_post_categories_data($post_id) {
  1442. if (!isset($this->cats_data_posts[$post_id]) || (isset($this->cats_data_posts[$post_id]) && count($this->cats_data_posts[$post_id]) == 0)) {
  1443. $cats = wp_get_post_categories($post_id);
  1444. $this->cats_data_posts[$post_id] = GDSRDatabase::get_categories_data($cats);
  1445. }
  1446. }
  1447. function init_cats_categories_data($cat_id) {
  1448. if (!isset($this->cats_data_cats[$cat_id]) || (isset($this->cats_data_cats[$cat_id]) && count($this->cats_data_cats[$cat_id]) == 0)) {
  1449. $this->cats_data_cats[$cat_id] = GDSRDatabase::get_categories_data(array($cat_id));
  1450. }
  1451. }
  1452. function get_article_rating_simple($post_id) {
  1453. $rating = 0;
  1454. list($votes, $score) = $this->get_article_rating($post_id);
  1455. if ($votes > 0) $rating = $score / $votes;
  1456. $rating = @number_format($rating, 1);
  1457. return $rating;
  1458. }
  1459. function get_article_rating($post_id, $is_page = '') {
  1460. $post_data = wp_gdget_post($post_id);
  1461. if (count($post_data) == 0) {
  1462. GDSRDatabase::add_default_vote($post_id, $is_page);
  1463. $post_data = wp_gdget_post($post_id);
  1464. }
  1465. $votes = $score = 0;
  1466. if ($post_data->rules_articles == "A" || $post_data->rules_articles == "N") {
  1467. $votes = $post_data->user_voters + $post_data->visitor_voters;
  1468. $score = $post_data->user_votes + $post_data->visitor_votes;
  1469. } else if ($post_data->rules_articles == "V") {
  1470. $votes = $post_data->visitor_voters;
  1471. $score = $post_data->visitor_votes;
  1472. } else {
  1473. $votes = $post_data->user_voters;
  1474. $score = $post_data->user_votes;
  1475. }
  1476. return array($votes, $score);
  1477. }
  1478. function get_post_rule_value($post_id, $rule = "rules_articles", $default = "default_voterules_articles") {
  1479. $this->init_post_categories_data($post_id);
  1480. $prn = 0;
  1481. $value = "";
  1482. foreach ($this->cats_data_posts[$post_id] as $cat) {
  1483. if ($cat->parent > 0 && $prn == 0) $prn = $cat->parent;
  1484. if ($cat->$rule != "" && $value == "") $value = $cat->$rule;
  1485. if ($value != "" || ($value != "" && $prn > 0)) break;
  1486. }
  1487. if ($value != "P") return $value;
  1488. if ($prn > 0) {
  1489. $value = $this->get_post_rule_value_recursion($prn, $rule);
  1490. if ($value != "P" && $value != "") return $value;
  1491. }
  1492. return $this->o[$default];
  1493. }
  1494. function get_post_rule_value_recursion($cat_id, $rule = "rules_articles") {
  1495. $this->init_cats_categories_data($cat_id);
  1496. if (count($this->cats_data_cats[$cat_id]) == 0) return 0;
  1497. $cat = $this->cats_data_cats[$cat_id][0];
  1498. if ($cat->$rule != "P" && $cat->$rule != "") return $cat->$rule;
  1499. if ($cat->parent > 0) return $this->get_post_rule_value_recursion($cat->parent, $rule);
  1500. return "";
  1501. }
  1502. function check_integration_std($post_id) {
  1503. $post_data = wp_gdget_post($post_id);
  1504. if (is_object($post_data)) {
  1505. if ($post_data->cmm_integration_std == "N") return false;
  1506. else if ($post_data->cmm_integration_std == "A") return true;
  1507. }
  1508. $this->init_post_categories_data($post_id);
  1509. foreach ($this->cats_data_posts[$post_id] as $cat) {
  1510. if ($cat->cmm_integration_std == "N") return false;
  1511. }
  1512. return true;
  1513. }
  1514. function get_multi_set($post_id) {
  1515. $post_data = wp_gdget_post($post_id);
  1516. if (is_object($post_data)) {
  1517. if ($post_data->cmm_integration_mur == "N") return 0;
  1518. else if ($post_data->cmm_integration_mur == "A") return $post_data->cmm_integration_set;
  1519. }
  1520. $this->init_post_categories_data($post_id);
  1521. $set = $prn = 0;
  1522. foreach ($this->cats_data_posts[$post_id] as $cat) {
  1523. if ($cat->cmm_integration_mur == "N") return 0;
  1524. if ($cat->parent > 0 && $prn == 0) $prn = $cat->parent;
  1525. if ($cat->cmm_integration_set > 0 && $set == 0) $set = $cat->cmm_integration_set;
  1526. if ($set > 0 || ($set > 0 && $prn > 0)) break;
  1527. }
  1528. if ($set > 0) return $set;
  1529. if ($prn > 0) {
  1530. $set = $this->get_multi_set_recursion($prn);
  1531. if ($set > 0) return $set;
  1532. $first = GDSRDBMulti::get_first_multi_set();
  1533. return $first->multi_id;
  1534. } else return 0;
  1535. }
  1536. function get_multi_set_recursion($cat_id) {
  1537. $this->init_cats_categories_data($cat_id);
  1538. if (count($this->cats_data_cats[$cat_id]) == 0) return 0;
  1539. $cat = $this->cats_data_cats[$cat_id][0];
  1540. if ($cat->cmm_integration_set > 0) return $cat->cmm_integration_set;
  1541. if ($cat->parent > 0) return $this->get_multi_set_recursion($cat->parent);
  1542. return 0;
  1543. }
  1544. function include_rating_css_admin() {
  1545. $elements = array();
  1546. $presizes = "m".gdFunctionsGDSR::prefill_zeros(20, 2);
  1547. $sizes = array(20);
  1548. $elements[] = $presizes;
  1549. $elements[] = join("", $sizes);
  1550. $elements[] = join("", $sizes);
  1551. $elements[] = "s1poxygen";
  1552. $elements[] = "t1pstarrating";
  1553. $q = join("#", $elements);
  1554. $t = $this->o["css_cache_active"] == 1 ? $this->o["css_last_changed"] : 0;
  1555. $opacity = $this->o["include_opacity"] == 1 ? "on" : "off";
  1556. $url = $this->plugin_url.'css/gdsr.css.php?t='.urlencode($t).'&amp;s='.urlencode($q).'&amp;o='.urlencode($opacity);
  1557. echo('<link rel="stylesheet" href="'.$url.'" type="text/css" media="screen" />');
  1558. }
  1559. function include_rating_css($external = true, $return = false) {
  1560. $star_sizes = $thumb_sizes = $elements = $loaders = array();
  1561. $presizes = "a".gdFunctionsGDSR::prefill_zeros($this->o["stars"], 2);
  1562. $presizes.= "i".gdFunctionsGDSR::prefill_zeros($this->o["stars"], 2);
  1563. $presizes.= "m".gdFunctionsGDSR::prefill_zeros(20, 2);
  1564. $presizes.= "k".gdFunctionsGDSR::prefill_zeros(20, 2);
  1565. $presizes.= "c".gdFunctionsGDSR::prefill_zeros($this->o["cmm_stars"], 2);
  1566. $presizes.= "r".gdFunctionsGDSR::prefill_zeros($this->o["cmm_review_stars"], 2);
  1567. $elements[] = $presizes;
  1568. foreach ($this->ginc[0] as $size => $var) {
  1569. if ($var == 1) $star_sizes[] = $size;
  1570. }
  1571. if (count($star_sizes) == 0) $star_sizes[] = 24;
  1572. $elements[] = join("", $star_sizes);
  1573. foreach ($this->ginc[2] as $size => $var) {
  1574. if ($var == 1) $thumb_sizes[] = $size;
  1575. }
  1576. if (count($thumb_sizes) == 0) $thumb_sizes[] = 24;
  1577. $elements[] = join("", $thumb_sizes);
  1578. if (!is_array($this->ginc[1])) $elements[] = "spstarrating";
  1579. else {
  1580. foreach($this->g->stars as $s) {
  1581. if (in_array($s->folder, $this->ginc[1]))
  1582. $elements[] = "s".$s->primary.substr($s->type, 0, 1).$s->folder;
  1583. }
  1584. }
  1585. if (!is_array($this->ginc[3])) $elements[] = "tpstarrating";
  1586. else {
  1587. foreach($this->g->thumbs as $s) {
  1588. if (in_array($s->folder, $this->ginc[3]))
  1589. $elements[] = "t".$s->primary.substr($s->type, 0, 1).$s->folder;
  1590. }
  1591. }
  1592. $loaders[] = $this->o["wait_loader_artthumb"];
  1593. $loaders[] = $this->o["wait_loader_cmmthumb"];
  1594. $loaders[] = $this->o["wait_loader_article"];
  1595. $loaders[] = $this->o["wait_loader_comment"];
  1596. $loaders[] = $this->o["wait_loader_multis"];
  1597. $loaders = array_unique($loaders);
  1598. foreach ($loaders as $l) $elements[] = "lsg".$l;
  1599. $q = join("#", $elements);
  1600. $t = $this->o["css_cache_active"] == 1 ? $this->o["css_last_changed"] : 0;
  1601. $opacity = $this->o["include_opacity"] == 1 ? "on" : "off";
  1602. if ($external) {
  1603. $url = $this->plugin_url.'css/gdsr.css.php?t='.urlencode($t).'&amp;s='.urlencode($q).'&amp;o='.urlencode($opacity);
  1604. if ($return) return $url;
  1605. else echo('<link rel="stylesheet" href="'.$url.'" type="text/css" media="screen" />');
  1606. } else {
  1607. echo('<style type="text/css" media=screen>');
  1608. $inclusion = "internal";
  1609. $base_url_local = $this->plugin_url;
  1610. $base_url_extra = $this->plugin_xtra_url;
  1611. include ($this->plugin_path."css/gdsr.css.php");
  1612. echo('</style>');
  1613. }
  1614. }
  1615. function multi_rating_header($external_css = true) {
  1616. $this->include_rating_css($external_css);
  1617. echo('<script type="text/javascript" src="'.$this->plugin_url.'js/gdsr.js"></script>');
  1618. }
  1619. /**
  1620. * Calculates Bayesian Estimate Mean value for given number of votes and rating
  1621. *
  1622. * @param int $v number of votes
  1623. * @param decimal $R rating value
  1624. * @param int $s maximal rating
  1625. * @return decimal Bayesian rating value
  1626. */
  1627. function bayesian_estimate($v, $R, $s) {
  1628. $m = $this->o["bayesian_minimal"];
  1629. $C = ($this->o["bayesian_mean"] / 100) * $s;
  1630. $WR = ($v / ($v + $m)) * $R + ($m / ($v + $m)) * $C;
  1631. return @number_format($WR, 1);
  1632. }
  1633. // display
  1634. function display_comment($content) {
  1635. global $post, $comment, $userdata;
  1636. if (is_admin() || !is_object($comment) || $comment->comment_type == "pingback") return $content;
  1637. if (!is_feed()) {
  1638. if ((is_single() && $this->o["display_comment"] == 1) ||
  1639. (is_page() && $this->o["display_comment_page"] == 1) ||
  1640. $this->o["override_display_comment"] == 1
  1641. ) {
  1642. $rendered = $this->f->render_comment($post, $comment, $userdata);
  1643. if ($this->o["auto_display_comment_position"] == "top" || $this->o["auto_display_comment_position"] == "both")
  1644. $content = $rendered.$content;
  1645. if ($this->o["auto_display_comment_position"] == "bottom" || $this->o["auto_display_comment_position"] == "both")
  1646. $content = $content.$rendered;
  1647. }
  1648. if ($this->o["thumbs_active"] == 1) {
  1649. if ((is_single() && $this->o["thumb_display_comment"] == 1) ||
  1650. (is_page() && $this->o["thumb_display_comment_page"] == 1) ||
  1651. $this->o["override_thumb_display_comment"] == 1
  1652. ) {
  1653. $rendered = $this->f->render_thumb_comment($post, $comment, $userdata);
  1654. if ($this->o["thumb_auto_display_comment_position"] == "top" || $this->o["thumb_auto_display_comment_position"] == "both")
  1655. $content = $rendered.$content;
  1656. if ($this->o["thumb_auto_display_comment_position"] == "bottom" || $this->o["thumb_auto_display_comment_position"] == "both")
  1657. $content = $content.$rendered;
  1658. }
  1659. }
  1660. }
  1661. return $content;
  1662. }
  1663. function check_backtrace_access() {
  1664. $back_trace = gdFunctionsGDSR::get_caller_backtrace();
  1665. foreach($this->function_restrict as $fr) {
  1666. if (in_array($fr, $back_trace)) return true;
  1667. }
  1668. return false;
  1669. }
  1670. function display_article($content) {
  1671. if (is_admin() || $this->check_backtrace_access()) return $content;
  1672. global $post, $userdata;
  1673. $post_id = is_object($post) ? $post->ID : 0;
  1674. if ($post_id == 0) return $content;
  1675. $user_id = is_object($userdata) ? $userdata->ID : 0;
  1676. if (!is_feed()) {
  1677. if (is_single() || is_page()) {
  1678. gdsrBlgDB::add_new_view($post_id);
  1679. $this->widget_post_id = $post_id;
  1680. }
  1681. // standard rating
  1682. if ((is_single() && $this->o["display_posts"] == 1) ||
  1683. (is_page() && $this->o["display_pages"] == 1) ||
  1684. (is_home() && $this->o["display_home"] == 1) ||
  1685. (is_archive() && $this->o["display_archive"] == 1) ||
  1686. (is_search() && $this->o["display_search"] == 1)
  1687. ) {
  1688. if ($this->o["cached_loading"] == 0) $this->cache_posts($user_id);
  1689. $rendered = $this->f->render_article($post, $userdata);
  1690. if ($this->o["auto_display_position"] == "top" || $this->o["auto_display_position"] == "both")
  1691. $content = $rendered.$content;
  1692. if ($this->o["auto_display_position"] == "bottom" || $this->o["auto_display_position"] == "both")
  1693. $content = $content.$rendered;
  1694. }
  1695. // thumbs rating
  1696. if ($this->o["thumbs_active"] == 1) {
  1697. if ((is_single() && $this->o["thumb_display_posts"] == 1) ||
  1698. (is_page() && $this->o["thumb_display_pages"] == 1) ||
  1699. (is_home() && $this->o["thumb_display_home"] == 1) ||
  1700. (is_archive() && $this->o["thumb_display_archive"] == 1) ||
  1701. (is_search() && $this->o["thumb_display_search"] == 1)
  1702. ) {
  1703. if ($this->o["cached_loading"] == 0) $this->cache_posts($user_id);
  1704. $rendered = $this->f->render_thumb_article($post, $userdata);
  1705. if ($this->o["thumb_auto_display_position"] == "top" || $this->o["thumb_auto_display_position"] == "both")
  1706. $content = $rendered.$content;
  1707. if ($this->o["thumb_auto_display_position"] == "bottom" || $this->o["thumb_auto_display_position"] == "both")
  1708. $content = $content.$rendered;
  1709. }
  1710. }
  1711. // multis rating
  1712. if ($this->o["multis_active"] && (is_single() || is_page())) {
  1713. $this->prepare_multiset();
  1714. if ($this->o["cached_loading"] == 0) $this->cache_posts($user_id);
  1715. $content = $this->display_multi_rating("top", $post, $userdata).$content;
  1716. $content = $content.$this->display_multi_rating("bottom", $post, $userdata);
  1717. }
  1718. }
  1719. $rich_snippet = $this->f->gsr;
  1720. if ($this->o["google_rich_snippets_location"] == "top") return $rich_snippet.$content;
  1721. else if ($this->o["google_rich_snippets_location"] == "bottom") return $content.$rich_snippet;
  1722. else return $content;
  1723. }
  1724. function display_multi_rating($location, $post, $user) {
  1725. $sets = $this->rendering_sets;
  1726. $rendered = "";
  1727. if (is_array($sets) && count($sets) > 0) {
  1728. foreach ($sets as $set) {
  1729. if ($set->auto_location == $location) {
  1730. $insert = false;
  1731. $auto = $set->auto_insert;
  1732. if (is_single() && ($auto == "apst" || $auto == "allp")) $insert = true;
  1733. if (!$insert && is_page() && ($auto == "apgs" || $auto == "allp")) $insert = true;
  1734. if (!$insert && is_single() && in_category(explode(",", $set->auto_categories), $post->ID) && $auto == "cats") $insert = true;
  1735. if ($insert) {
  1736. $settings = array('id' => $set->multi_id, 'read_only' => 0);
  1737. $rendered.= $this->f->render_multi_rating($post, $user, $settings);
  1738. }
  1739. }
  1740. }
  1741. }
  1742. return $rendered;
  1743. }
  1744. // display
  1745. // cache
  1746. function cache_cleanup() {
  1747. if ($this->o["cache_cleanup_auto"] == 1) {
  1748. $clean = false;
  1749. $pdate = strtotime($this->o["cache_cleanup_last"]);
  1750. $next_clean = mktime(date("H", $pdate), date("i", $pdate), date("s", $pdate), date("m", $pdate) + $this->o["cache_cleanup_days"], date("j", $pdate), date("Y", $pdate));
  1751. if (intval($next_clean) < intval(mktime())) $clean = true;
  1752. if ($clean) {
  1753. GDSRHelper::clean_cache(substr(STARRATING_CACHE_PATH, 0, strlen(STARRATING_CACHE_PATH) - 1));
  1754. $this->o["cache_cleanup_last"] = date("r");
  1755. update_option('gd-star-rating', $this->o);
  1756. }
  1757. }
  1758. }
  1759. function cache_posts($user_id) {
  1760. $to_get = array();
  1761. foreach ($this->c as $id => $value) {
  1762. if ($value == 0) $to_get[] = $id;
  1763. }
  1764. if (count($to_get) > 0) {
  1765. global $gdsr_cache_posts_std_data, $gdsr_cache_posts_std_log, $gdsr_cache_posts_std_thumbs_log;
  1766. $data = GDSRDBCache::get_posts($to_get);
  1767. foreach ($data as $row) {
  1768. $id = $row->post_id;
  1769. $this->c[$id] = 1;
  1770. $gdsr_cache_posts_std_data->set($id, $row);
  1771. }
  1772. $logs = GDSRDBCache::get_logs($to_get, $user_id, "article", $_SERVER["REMOTE_ADDR"], $this->o["logged"] != 1, $this->o["allow_mixed_ip_votes"] == 1);
  1773. foreach ($logs as $id => $value) {
  1774. $gdsr_cache_posts_std_log->set($id, $value == 0);
  1775. }
  1776. if ($this->o["thumbs_active"] == 1) {
  1777. $logs_thumb = GDSRDBCache::get_logs($to_get, $user_id, "artthumb", $_SERVER["REMOTE_ADDR"], $this->o["logged"] != 1, $this->o["allow_mixed_ip_votes"] == 1);
  1778. foreach ($logs_thumb as $id => $value) {
  1779. $gdsr_cache_posts_std_thumbs_log->set($id, $value == 0);
  1780. }
  1781. }
  1782. }
  1783. }
  1784. function cache_comments($post_id) {
  1785. global $gdsr_cache_posts_cmm_data, $gdsr_cache_posts_cmm_log, $gdsr_cache_posts_cmm_thumbs_log, $userdata;
  1786. $user_id = is_object($userdata) ? $userdata->ID : 0;
  1787. $to_get = array();
  1788. $data = GDSRDBCache::get_comments($post_id);
  1789. foreach ($data as $row) {
  1790. $id = $row->comment_id;
  1791. $gdsr_cache_posts_cmm_data->set($id, $row);
  1792. $to_get[] = $id;
  1793. }
  1794. if (count($to_get) > 0) {
  1795. $logs = GDSRDBCache::get_logs($to_get, $user_id, "comment", $_SERVER["REMOTE_ADDR"], $this->o["cmm_logged"] != 1, $this->o["cmm_allow_mixed_ip_votes"] == 1);
  1796. foreach ($logs as $id => $value) {
  1797. $gdsr_cache_posts_cmm_log->set($id, $value == 0);
  1798. }
  1799. if ($this->o["thumbs_active"] == 1) {
  1800. $logs_thumb = GDSRDBCache::get_logs($to_get, $user_id, "cmmthumb", $_SERVER["REMOTE_ADDR"], $this->o["cmm_logged"] != 1, $this->o["cmm_allow_mixed_ip_votes"] == 1);
  1801. foreach ($logs_thumb as $id => $value) {
  1802. $gdsr_cache_posts_cmm_thumbs_log->set($id, $value == 0);
  1803. }
  1804. }
  1805. }
  1806. }
  1807. function cached_posts($votes) {
  1808. global $userdata;
  1809. $user_id = is_object($userdata) ? $userdata->ID : 0;
  1810. $rendered = $alls = array();
  1811. foreach ($votes as $vote) {
  1812. $settings = explode(".", $vote);
  1813. $alls[$vote] = $settings;
  1814. $this->c[$settings[1]] = 0;
  1815. }
  1816. $this->f->render_wait_article();
  1817. $this->f->render_wait_multis();
  1818. $this->f->render_wait_article_thumb();
  1819. $this->cache_posts($user_id);
  1820. foreach ($alls as $vote => $settings) {
  1821. $cde = substr($vote, 0, 3);
  1822. $html = "";
  1823. switch ($cde) {
  1824. case "asr":
  1825. $html = $this->f->render_article_actual($settings);
  1826. break;
  1827. case "atr":
  1828. $html = $this->f->render_thumb_article_actual($settings);
  1829. break;
  1830. case "amr":
  1831. $html = $this->f->render_multi_rating_actual($settings);
  1832. break;
  1833. }
  1834. $html = str_replace('"', '\"', $html);
  1835. $rendered[] = '{"id": "gdsrc_'.$vote.'", "html": "'.$html.'"}';
  1836. }
  1837. return '{ "items": ['.join(", ", $rendered).']}';
  1838. }
  1839. function cached_comments($votes) {
  1840. $rendered = $alls = $postids = array();
  1841. foreach ($votes as $vote) {
  1842. $settings = explode(".", $vote);
  1843. $alls[$vote] = $settings;
  1844. if (!in_array($settings[1], $postids)) $postids[] = $settings[1];
  1845. }
  1846. $this->f->render_wait_comment();
  1847. $this->f->render_wait_comment_thumb();
  1848. foreach ($postids as $post_id) $this->cache_comments($post_id);
  1849. foreach ($alls as $vote => $settings) {
  1850. $cde = substr($vote, 0, 3);
  1851. $html = "";
  1852. switch ($cde) {
  1853. case "csr":
  1854. $html = $this->f->render_comment_actual($settings);
  1855. break;
  1856. case "ctr":
  1857. $html = $this->f->render_thumb_comment_actual($settings);
  1858. break;
  1859. }
  1860. $html = str_replace('"', '\"', $html);
  1861. $rendered[] = '{"id": "gdsrc_'.$vote.'", "html": "'.$html.'"}';
  1862. }
  1863. return '{ "items": ['.join(", ", $rendered).']}';
  1864. }
  1865. // cache
  1866. }
  1867. ?>