WordPress Related Posts - Version 1.6

Version Description

  • Bugfixes
  • Settings page update
  • Scroll up related posts experiment
Download this release

Release Info

Developer andddd
Plugin Icon wp plugin WordPress Related Posts
Version 1.6
Comparing to
See all releases

Code changes from version 1.5.2 to 1.6

compatibility.php CHANGED
@@ -5,8 +5,7 @@
5
  /* ***************************** */
6
 
7
  function wp_random_posts ($number = 10){
8
- $limitclause="LIMIT " . $number;
9
- $random_posts = wp_get_random_posts ($limitclause);
10
 
11
  foreach ($random_posts as $random_post ){
12
  $output .= '<li>';
@@ -20,8 +19,7 @@ function wp_random_posts ($number = 10){
20
  }
21
 
22
  function wp_most_popular_posts ($number = 10){
23
- $limitclause="LIMIT " . $number;
24
- $most_popular_posts = wp_get_most_popular_posts ($limitclause);
25
 
26
  foreach($most_popular_posts as $most_popular_post) {
27
  $output .= '<li><a href="' . get_permalink($most_popular_post->ID) . '" title="' . esc_attr(wptexturize($most_popular_post->post_title)) . '">' . wptexturize($most_popular_post->post_title) . '</a></li>';
@@ -33,8 +31,7 @@ function wp_most_popular_posts ($number = 10){
33
  }
34
 
35
  function wp_most_commented_posts ($number = 10){
36
- $limitclause="LIMIT " . $number;
37
- $most_commented_posts = wp_get_most_commented_posts ($limitclause);
38
 
39
  foreach($most_commented_posts as $most_commented_post) {
40
  $output .= '<li><a href="'.get_permalink($most_commented_post->ID).'" title="' . esc_attr(wptexturize($most_commented_post->post_title)) . '">' . wptexturize($most_commented_post->post_title) . '</a></li>';
@@ -55,19 +52,23 @@ function wp_related_posts() {
55
  }
56
 
57
  function wp_get_random_posts ($limitclause = '') {
58
- return wp_rp_fetch_random_posts($limitclause);
 
59
  }
60
 
61
  function wp_get_most_commented_posts($limitclause = '') {
62
- return wp_rp_fetch_most_commented_posts($limitclause);
 
63
  }
64
 
65
  function wp_get_most_popular_posts ($limitclause = '') {
66
- return wp_rp_fetch_most_popular_posts($limitclause);
 
67
  }
68
 
69
  function wp_fetch_related_posts($limitclause = '') {
70
- return wp_rp_fetch_related_posts($limitclause);
 
71
  }
72
 
73
  function wp_fetch_random_posts($limit = 10) {
@@ -75,11 +76,13 @@ function wp_fetch_random_posts($limit = 10) {
75
  }
76
 
77
  function wp_fetch_most_commented_posts($limitclause = '') {
78
- return wp_rp_fetch_most_commented_posts($limitclause);
 
79
  }
80
 
81
  function wp_fetch_most_popular_posts($limitclause = '') {
82
- return wp_rp_fetch_most_popular_posts($limitclause);
 
83
  }
84
 
85
  function wp_fetch_content() {
5
  /* ***************************** */
6
 
7
  function wp_random_posts ($number = 10){
8
+ $random_posts = wp_get_random_posts ($number);
 
9
 
10
  foreach ($random_posts as $random_post ){
11
  $output .= '<li>';
19
  }
20
 
21
  function wp_most_popular_posts ($number = 10){
22
+ $most_popular_posts = wp_get_most_popular_posts ($number);
 
23
 
24
  foreach($most_popular_posts as $most_popular_post) {
25
  $output .= '<li><a href="' . get_permalink($most_popular_post->ID) . '" title="' . esc_attr(wptexturize($most_popular_post->post_title)) . '">' . wptexturize($most_popular_post->post_title) . '</a></li>';
31
  }
32
 
33
  function wp_most_commented_posts ($number = 10){
34
+ $most_commented_posts = wp_get_most_commented_posts ($number);
 
35
 
36
  foreach($most_commented_posts as $most_commented_post) {
37
  $output .= '<li><a href="'.get_permalink($most_commented_post->ID).'" title="' . esc_attr(wptexturize($most_commented_post->post_title)) . '">' . wptexturize($most_commented_post->post_title) . '</a></li>';
52
  }
53
 
54
  function wp_get_random_posts ($limitclause = '') {
55
+ $limit = filter_var($limitclause, FILTER_SANITIZE_NUMBER_INT);
56
+ return wp_rp_fetch_random_posts($limit);
57
  }
58
 
59
  function wp_get_most_commented_posts($limitclause = '') {
60
+ $limit = filter_var($limitclause, FILTER_SANITIZE_NUMBER_INT);
61
+ return wp_rp_fetch_most_commented_posts($limit);
62
  }
63
 
64
  function wp_get_most_popular_posts ($limitclause = '') {
65
+ $limit = filter_var($limitclause, FILTER_SANITIZE_NUMBER_INT);
66
+ return wp_rp_fetch_most_popular_posts($limit);
67
  }
68
 
69
  function wp_fetch_related_posts($limitclause = '') {
70
+ $limit = filter_var($limitclause, FILTER_SANITIZE_NUMBER_INT);
71
+ return wp_rp_fetch_related_posts($limit);
72
  }
73
 
74
  function wp_fetch_random_posts($limit = 10) {
76
  }
77
 
78
  function wp_fetch_most_commented_posts($limitclause = '') {
79
+ $limit = filter_var($limitclause, FILTER_SANITIZE_NUMBER_INT);
80
+ return wp_rp_fetch_most_commented_posts($limit);
81
  }
82
 
83
  function wp_fetch_most_popular_posts($limitclause = '') {
84
+ $limit = filter_var($limitclause, FILTER_SANITIZE_NUMBER_INT);
85
+ return wp_rp_fetch_most_popular_posts($limit);
86
  }
87
 
88
  function wp_fetch_content() {
config.php CHANGED
@@ -21,19 +21,24 @@ define('WP_RP_THUMBNAILS_WIDTH', 150);
21
  define('WP_RP_THUMBNAILS_HEIGHT', 150);
22
  define('WP_RP_THUMBNAILS_DEFAULTS_COUNT', 15);
23
 
24
- define("WP_RP_CTR_BASE_URL", "http://d.related-posts.com/");
25
  define("WP_RP_CTR_REPORT_URL", "http://t.related-posts.com/pageview/?");
26
- define("WP_RP_CTR_PAGEVIEW_FILE", "js/pageview.js");
27
 
28
- define("WP_RP_BANNER_FILE", "js/welcome.js");
 
 
 
 
 
 
29
 
30
 
31
  global $wp_rp_options, $wp_rp_meta;
32
  $wp_rp_options = false;
33
  $wp_rp_meta = false;
34
 
35
- function wp_rp_get_options()
36
- {
37
  global $wp_rp_options, $wp_rp_meta;
38
  if($wp_rp_options) {
39
  return $wp_rp_options;
@@ -44,12 +49,9 @@ function wp_rp_get_options()
44
  wp_rp_upgrade();
45
  $wp_rp_meta = get_option('wp_rp_meta');
46
  }
 
47
 
48
- $wp_rp_options = get_option('wp_rp_options');
49
-
50
- if ($wp_rp_options['ctr_dashboard_enabled'] && !$wp_rp_meta['blog_id']) {
51
- wp_rp_fetch_blog_credentials();
52
- }
53
 
54
  return $wp_rp_options;
55
  }
@@ -64,37 +66,36 @@ function wp_rp_get_meta() {
64
  return $wp_rp_meta;
65
  }
66
 
67
- function wp_rp_activate_hook() {
68
- wp_rp_get_options();
69
- }
70
-
71
- function wp_rp_fetch_blog_credentials() {
72
  global $wp_rp_meta;
73
 
74
- if (!wp_rp_statistics_supported()) {
75
- return;
 
 
 
 
76
  }
77
 
78
- $options = array(
79
- 'timeout' => 10
80
- );
81
 
82
- $response = wp_remote_get(WP_RP_CTR_BASE_URL . 'register/?blog_url=' . get_bloginfo('wpurl') . ($wp_rp_meta['new_user'] ? '&new' : ''), $options);
83
- if (wp_remote_retrieve_response_code($response) == 200) {
84
- $body = wp_remote_retrieve_body($response);
85
- if ($body) {
86
- $doc = json_decode($body);
87
- if ($doc && $doc->status === 'ok') {
88
- $wp_rp_meta['blog_id'] = $doc->data->blog_id;
89
- $wp_rp_meta['auth_key'] = $doc->data->auth_key;
90
- $wp_rp_meta['new_user'] = false;
91
- update_option('wp_rp_meta', $wp_rp_meta);
92
- }
93
- }
94
  }
 
 
95
  }
96
- function wp_rp_statistics_supported() {
97
- return function_exists('json_decode'); // PHP < 5.2.0
 
98
  }
99
 
100
  function wp_rp_upgrade() {
@@ -129,8 +130,11 @@ function wp_rp_install() {
129
  'new_user' => true,
130
  'show_upgrade_tooltip' => false,
131
  'show_install_tooltip' => true,
132
- 'show_ctr_banner' => true,
133
- 'show_blogger_network' => true
 
 
 
134
  );
135
 
136
  $wp_rp_options = array(
@@ -146,7 +150,7 @@ function wp_rp_install() {
146
  'on_rss' => false,
147
  'display_comment_count' => false,
148
  'display_publish_date' => false,
149
- 'display_thumbnail' => true,
150
  'thumbnail_display_title' => true,
151
  'thumbnail_custom_field' => false,
152
  'thumbnail_use_attached' => true,
@@ -156,20 +160,42 @@ function wp_rp_install() {
156
  'theme_custom_css' => WP_RP_DEFAULT_CUSTOM_CSS,
157
  'ctr_dashboard_enabled' => false,
158
  'include_promotionail_link' => false,
159
- 'enable_themes' => false
 
160
  );
161
 
162
  update_option('wp_rp_meta', $wp_rp_meta);
163
  update_option('wp_rp_options', $wp_rp_options);
164
  }
165
 
166
- function wp_rp_migrate_1_5_2() { # Silent release
 
 
 
 
 
 
 
 
167
  $wp_rp_meta = get_option('wp_rp_meta');
 
 
 
168
 
169
  $wp_rp_meta['show_install_tooltip'] = false;
170
- $wp_rp_meta['version'] = '1.5.2.1';
 
 
 
 
 
 
 
 
 
171
 
172
  update_option('wp_rp_meta', $wp_rp_meta);
 
173
  }
174
  function wp_rp_migrate_1_5_1() {
175
  $wp_rp_options = get_option('wp_rp_options');
21
  define('WP_RP_THUMBNAILS_HEIGHT', 150);
22
  define('WP_RP_THUMBNAILS_DEFAULTS_COUNT', 15);
23
 
24
+ define("WP_RP_CTR_DASHBOARD_URL", "http://d.related-posts.com/");
25
  define("WP_RP_CTR_REPORT_URL", "http://t.related-posts.com/pageview/?");
26
+ define("WP_RP_STATIC_CTR_PAGEVIEW_FILE", "js/pageview.js");
27
 
28
+ define("WP_RP_STATIC_RECOMMENDATIONS_JS_FILE", "js/recommendations.js");
29
+ define("WP_RP_STATIC_RECOMMENDATIONS_CSS_FILE", "css-img/recommendations.css");
30
+
31
+ define("WP_RP_STATIC_SCROLLUP_JS_FILE", "js/scrollup.js");
32
+ define("WP_RP_STATIC_SCROLLUP_CSS_FILE", "css-img/scrollup.css");
33
+
34
+ define("WP_RP_STATIC_BANNER_FILE", "js/welcome.js");
35
 
36
 
37
  global $wp_rp_options, $wp_rp_meta;
38
  $wp_rp_options = false;
39
  $wp_rp_meta = false;
40
 
41
+ function wp_rp_get_options() {
 
42
  global $wp_rp_options, $wp_rp_meta;
43
  if($wp_rp_options) {
44
  return $wp_rp_options;
49
  wp_rp_upgrade();
50
  $wp_rp_meta = get_option('wp_rp_meta');
51
  }
52
+ $wp_rp_meta = new ArrayObject($wp_rp_meta);
53
 
54
+ $wp_rp_options = new ArrayObject(get_option('wp_rp_options'));
 
 
 
 
55
 
56
  return $wp_rp_options;
57
  }
66
  return $wp_rp_meta;
67
  }
68
 
69
+ function wp_rp_update_meta($new_meta) {
 
 
 
 
70
  global $wp_rp_meta;
71
 
72
+ $new_meta = (array) $new_meta;
73
+
74
+ $r = update_option('wp_rp_meta', $new_meta);
75
+
76
+ if($r && $wp_rp_meta !== false) {
77
+ $wp_rp_meta->exchangeArray($new_meta);
78
  }
79
 
80
+ return $r;
81
+ }
 
82
 
83
+ function wp_rp_update_options($new_options) {
84
+ global $wp_rp_options;
85
+
86
+ $new_options = (array) $new_options;
87
+
88
+ $r = update_option('wp_rp_options', $new_options);
89
+
90
+ if($r && $wp_rp_options !== false) {
91
+ $wp_rp_options->exchangeArray($new_options);
 
 
 
92
  }
93
+
94
+ return $r;
95
  }
96
+
97
+ function wp_rp_activate_hook() {
98
+ wp_rp_get_options();
99
  }
100
 
101
  function wp_rp_upgrade() {
130
  'new_user' => true,
131
  'show_upgrade_tooltip' => false,
132
  'show_install_tooltip' => true,
133
+ 'remote_recommendations' => false,
134
+ 'show_turn_on_button' => true,
135
+ 'name' => '',
136
+ 'email' => '',
137
+ 'show_invite_friends_form' => true
138
  );
139
 
140
  $wp_rp_options = array(
150
  'on_rss' => false,
151
  'display_comment_count' => false,
152
  'display_publish_date' => false,
153
+ 'display_thumbnail' => false,
154
  'thumbnail_display_title' => true,
155
  'thumbnail_custom_field' => false,
156
  'thumbnail_use_attached' => true,
160
  'theme_custom_css' => WP_RP_DEFAULT_CUSTOM_CSS,
161
  'ctr_dashboard_enabled' => false,
162
  'include_promotionail_link' => false,
163
+ 'enable_themes' => false,
164
+ 'scroll_up_related_posts' => true
165
  );
166
 
167
  update_option('wp_rp_meta', $wp_rp_meta);
168
  update_option('wp_rp_options', $wp_rp_options);
169
  }
170
 
171
+ function wp_rp_migrate_1_5_2_1() { # This was a silent release, but WP_RP_VERSION was not properly updated, so we don't know exactly what happened...
172
+ $wp_rp_meta = get_option('wp_rp_meta');
173
+
174
+ $wp_rp_meta['version'] = '1.5.2';
175
+
176
+ update_option('wp_rp_meta', $wp_rp_meta);
177
+ }
178
+
179
+ function wp_rp_migrate_1_5_2() {
180
  $wp_rp_meta = get_option('wp_rp_meta');
181
+ $wp_rp_options = get_option('wp_rp_options');
182
+
183
+ $wp_rp_meta['version'] = '1.6';
184
 
185
  $wp_rp_meta['show_install_tooltip'] = false;
186
+ $wp_rp_meta['remote_recommendations'] = false;
187
+ $wp_rp_meta['show_turn_on_button'] = !($wp_rp_options['ctr_dashboard_enabled'] && $wp_rp_options['display_thumbnail']);
188
+ $wp_rp_meta['name'] = '';
189
+ $wp_rp_meta['email'] = '';
190
+ $wp_rp_meta['show_invite_friends_form'] = false;
191
+
192
+ unset($wp_rp_meta['show_ctr_banner']);
193
+ unset($wp_rp_meta['show_blogger_network']);
194
+
195
+ $wp_rp_options['scroll_up_related_posts'] = false;
196
 
197
  update_option('wp_rp_meta', $wp_rp_meta);
198
+ update_option('wp_rp_options', $wp_rp_options);
199
  }
200
  function wp_rp_migrate_1_5_1() {
201
  $wp_rp_options = get_option('wp_rp_options');
readme.txt CHANGED
@@ -1,35 +1,73 @@
1
  === Plugin Name ===
2
  Contributors: jureham
3
- Tags: Related,Posts
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LB3MVPLUAWCY6
5
- Requires at least: 3.0
6
- Tested up to: 3.4.2
7
- Stable tag: 1.5.2
 
8
 
9
- WordPress Related Posts Plugin will generate a related posts via WordPress tags, and add the related posts to feed.
10
 
11
  == Description ==
12
 
13
- WordPress Related Posts Plugin will generate a related posts via WordPress tags, and add the related posts to feed.
14
 
15
- Quickly increase engagement with your posts by adding Related Posts at the bottom of your content. This plugin also delivers statistics about Pageviews and Clicks*. Supports different styles, thumbnails and is fully customizable.
16
 
17
- * Real time traffic analytics are provided via third party service.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  == Installation ==
20
 
21
- 1. Upload the folder WPRP to the `/wp-content/plugins/` directory
22
- 1. Activate the plugin through the 'Plugins' menu in WordPress
23
- 1. Navigate to Manage > Option > WordPress Related Posts to configure plugin output.
 
 
 
 
 
 
 
 
 
 
24
 
25
  == Screenshots ==
26
- 1. WordPress Related Posts default theme.
27
- 2. WordPress Related Posts statistics.
28
- 3. WordPress Related Posts setting.
29
 
30
 
31
  == Changelog ==
32
 
 
 
 
 
 
33
  = 1.5.2 =
34
  * Opt-in remote assets
35
 
1
  === Plugin Name ===
2
  Contributors: jureham
3
+ Tags: related,posts,post,related posts,plugin
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LB3MVPLUAWCY6
5
+ License: GPLv2
6
+ Requires at least: 3.3
7
+ Tested up to: 3.5
8
+ Stable tag: 1.6
9
 
10
+ WordPress Related Posts generates a list of related posts with thumbnails and gives you click-through statistics.
11
 
12
  == Description ==
13
 
14
+ Quickly increase your readers' engagement with your posts by adding Related Posts in the footer of your content. The plugin also delivers statistics about Pageviews and Clicks\*. It supports different styles, thumbnails and is fully customizable.
15
 
16
+ After installation, go to Settings -> Related Posts in your plugins list and turn on Thumbnails & Statistics!
17
 
18
+ \* Real time traffic analytics are provided via third party service.
19
+
20
+ == Frequently Asked Questions ==
21
+
22
+ = Why should I use this plugin and not any other? =
23
+
24
+ WordPress Related Posts is constantly improved to bring you the highest rates of audience engagement with your content. Our highest Click-Through rates speak for themselves.
25
+
26
+ = What does this plugin do? =
27
+
28
+ It places a list of links with thumbnails at the bottom of your posts. It increases pageviews and engages readers to stay on your site longer and discover more of your content.
29
+
30
+ = Are there any settings? Plenty! =
31
+
32
+ * thumbnail size, style
33
+ * number of posts
34
+ * display post excerpt, publish date, number of comments
35
+ * fallback if there are no related posts
36
+ * categories to exclude
37
+ * set default image
38
+
39
+ = Does it support mobile themes? =
40
+
41
+ Yes, related posts are responsive so they adapt to the screen size to ensure maximum click-through rates.
42
 
43
  == Installation ==
44
 
45
+ = Via upload: =
46
+ 1. Download the plugin .zip file
47
+ 2. Log in to yourdomain.com/wp-admin
48
+ 3. Click Plugins -> Add New -> Upload
49
+ 4. After installation go to Settings -> Related Posts in your plugins list to turn on Thumbnails & Statistics
50
+ 5. You're finished!
51
+
52
+ = Via admin: =
53
+ 1. Go to Plugins -> Add New
54
+ 2. Search for WordPress Related Posts
55
+ 3. Install and activate the first result
56
+ 4. After installation go to Settings -> Related Posts in your plugins list to turn on Thumbnails & Statistics
57
+ 5. Done!
58
 
59
  == Screenshots ==
60
+ 1. WordPress Related Posts Default Theme.
61
+ 2. WordPress Related Posts Settings and Statistics.
 
62
 
63
 
64
  == Changelog ==
65
 
66
+ = 1.6 =
67
+ * Bugfixes
68
+ * Settings page update
69
+ * Scroll up related posts experiment
70
+
71
  = 1.5.2 =
72
  * Opt-in remote assets
73
 
settings.php CHANGED
@@ -6,18 +6,15 @@
6
 
7
  function wp_rp_display_tooltips() {
8
  $meta = wp_rp_get_meta();
9
- global $wp_rp_meta;
10
 
11
  if ($meta['show_upgrade_tooltip']) {
12
  $meta['show_upgrade_tooltip'] = false;
13
- update_option('wp_rp_meta', $meta);
14
- $wp_rp_meta = $meta;
15
 
16
  add_action('admin_enqueue_scripts', 'wp_rp_load_upgrade_tooltip');
17
  } else if ($meta['show_install_tooltip']) {
18
  $meta['show_install_tooltip'] = false;
19
- update_option('wp_rp_meta', $meta);
20
- $wp_rp_meta = $meta;
21
 
22
  add_action('admin_enqueue_scripts', 'wp_rp_load_install_tooltip');
23
  }
@@ -53,49 +50,58 @@ function wp_rp_print_install_tooltip() {
53
  function wp_rp_print_tooltip($content) {
54
  ?>
55
  <script type="text/javascript">
56
- jQuery(function () {
57
- var body = jQuery(document.body),
58
- collapse = jQuery('#collapse-menu'),
59
- menu = jQuery('#menu-settings'),
60
- wprpp = menu.find("a[href='options-general.php?page=wordpress-related-posts']"),
 
 
61
  options = {
62
  content: "<?php echo $content; ?>",
63
  position: {
64
  edge: 'left',
65
  align: 'center',
66
- of: menu.is('.wp-menu-open') && !menu.is('.folded *') ? wprpp : menu
 
 
 
67
  },
68
  close: function() {
69
- menu.unbind('mouseenter mouseleave', wprpp_pointer);
70
- collapse.unbind('mouseenter mouseleave', wprpp_pointer);
71
  }
72
- },
73
- wprpp_pointer = function (e) {
74
- setTimeout(function() {
75
- if (wprpp.is(':visible')) {
76
- options.position.of = wprpp;
77
- } else {
78
- options.position.of = menu;
79
- }
80
- body.pointer(options);
81
- }, 200);
82
  };
83
 
84
- if (!wprpp.length) {
85
- return;
86
- }
87
-
88
- body.pointer(options).pointer('open');
89
-
90
- if (menu.is('.folded *') || !menu.is('.wp-menu-open')) {
91
- menu.bind('mouseenter mouseleave', wprpp_pointer);
92
- collapse.bind('mouseenter mouseleave', wprpp_pointer);
93
  }
94
  });
95
  </script>
96
  <?php
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  /**
100
  * Settings
101
  **/
@@ -103,7 +109,8 @@ function wp_rp_print_tooltip($content) {
103
  add_action('admin_menu', 'wp_rp_settings_admin_menu');
104
 
105
  function wp_rp_settings_admin_menu() {
106
- $page = add_options_page(__('Related Posts', 'wp_related_posts'), __('Related Posts', 'wp_related_posts'), 'manage_options', 'wordpress-related-posts', 'wp_rp_settings_page');
 
107
 
108
  add_action('admin_print_styles-' . $page, 'wp_rp_settings_styles');
109
  add_action('admin_print_scripts-' . $page, 'wp_rp_settings_scripts');
@@ -119,32 +126,75 @@ function wp_rp_settings_styles() {
119
  wp_enqueue_style("wp_rp_dashaboard_style", plugins_url("static/css/dashboard.css", __FILE__));
120
  }
121
 
122
- function wp_rp_ajax_blogger_network_submit_callback() {
123
  $meta = wp_rp_get_meta();
124
 
125
- $meta['show_blogger_network'] = false;
126
- update_option('wp_rp_meta', $meta);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
 
128
- echo 'ok';
129
 
 
130
  die();
131
  }
132
 
133
- add_action('wp_ajax_blogger_network_submit', 'wp_rp_ajax_blogger_network_submit_callback');
134
 
135
  function wp_rp_settings_page()
136
  {
137
- global $wp_rp_empty_options;
138
-
139
  $title_tags = array('h2', 'h3', 'h4', 'p', 'div');
140
 
 
 
 
141
  $postdata = stripslashes_deep($_POST);
142
 
143
  if(sizeof($_POST))
144
  {
145
  $message = __('WordPress Related Posts Setting Updated', 'wp_related_posts');
146
 
147
- $old_options = wp_rp_get_options();
148
  $new_options = array(
149
  'missing_rp_algorithm' => isset($postdata['wp_rp_missing_rp_algorithm']) ? trim($postdata['wp_rp_missing_rp_algorithm']) : 'random',
150
  'missing_rp_title' => isset($postdata['wp_rp_missing_rp_title']) ? ($postdata['wp_rp_missing_rp_title']) : __('Random Posts', 'wp_related_posts'),
@@ -164,7 +214,8 @@ function wp_rp_settings_page()
164
  'thumbnail_use_custom' => isset($postdata['wp_rp_thumbnail_use_custom']) && $postdata['wp_rp_thumbnail_use_custom'] === 'yes',
165
  'ctr_dashboard_enabled' => isset($postdata['wp_rp_ctr_dashboard_enabled']),
166
  'include_promotionail_link' => isset($postdata['wp_rp_include_promotionail_link']),
167
- 'enable_themes' => isset($postdata['wp_rp_enable_themes'])
 
168
  );
169
 
170
  if(!isset($postdata['wp_rp_not_on_categories'])) {
@@ -199,26 +250,21 @@ function wp_rp_settings_page()
199
  }
200
  }
201
 
202
- if ($old_options != $new_options) {
203
- if($new_options['ctr_dashboard_enabled'] && !$old_options['ctr_dashboard_enabled']) {
204
- $meta = wp_rp_get_meta();
205
- if($meta['show_ctr_banner']) {
206
- $meta['show_ctr_banner'] = false;
207
- update_option('wp_rp_meta', $meta);
208
- }
209
  }
210
 
211
- global $wp_rp_options;
212
- $wp_rp_options = null; // clear options cache to execute wp_rp_get_options again
213
-
214
- if(!update_option('wp_rp_options', $new_options)) {
215
  $message = __('Update Failed', 'wp_related_posts');
216
  }
217
  }
218
  }
219
 
220
- $options = wp_rp_get_options();
221
- $meta = wp_rp_get_meta();
 
222
 
223
  ?>
224
 
@@ -235,22 +281,22 @@ function wp_rp_settings_page()
235
  <input type="hidden" id="wp_rp_json_url" value="<?php esc_attr_e(WP_RP_STATIC_BASE_URL . WP_RP_STATIC_JSON_PATH); ?>" />
236
  <input type="hidden" id="wp_rp_version" value="<?php esc_attr_e(WP_RP_VERSION); ?>" />
237
  <input type="hidden" id="wp_rp_theme_selected" value="<?php esc_attr_e($theme_name); ?>" />
 
238
 
239
- <?php if (wp_rp_statistics_supported() && $options['ctr_dashboard_enabled']):?>
240
- <input type="hidden" id="wp_rp_dashboard_url" value="<?php esc_attr_e(WP_RP_CTR_BASE_URL); ?>" />
241
  <input type="hidden" id="wp_rp_blog_id" value="<?php esc_attr_e($meta['blog_id']); ?>" />
242
  <input type="hidden" id="wp_rp_auth_key" value="<?php esc_attr_e($meta['auth_key']); ?>" />
243
  <?php endif; ?>
244
 
245
  <div class="header">
246
- <h2 class="title"><?php _e("Related Posts",'wp_related_posts');?></h2>
247
- <p class="desc"><?php _e("WordPress Related Posts Plugin places a list of related articles via WordPress tags at the bottom of your post.",'wp_related_posts');?></p>
248
  <div class="support">
249
  <h4><?php _e("Awesome support", 'wp_related_posts'); ?></h4>
250
  <p>
251
  <?php _e("If you have any questions please contact us at",'wp_related_posts');?> <a target="_blank" href="mailto:relatedpostsplugin@gmail.com"><?php _e("support", 'wp_related_posts');?></a>.
252
  </p>
253
  </div>
 
 
254
  </div>
255
  <div id="wp-rp-survey" class="updated highlight" style="display:none;"><p><?php _e("Please fill out",'wp_related_posts');?> <a class="link" target="_blank" href="http://wprelatedposts.polldaddy.com/s/new-features"><?php _e("a quick survey", 'wp_related_posts');?></a>.<a href="#" class="close" style="float: right;">x</a></p></div>
256
 
@@ -258,94 +304,165 @@ function wp_rp_settings_page()
258
  <div id="message" class="updated fade"><p><?php echo $message ?>.</p></div>
259
  <?php endif; ?>
260
 
261
- <?php if ($meta['show_blogger_network']): ?>
262
- <form action="https://docs.google.com/a/zemanta.com/spreadsheet/formResponse?formkey=dDEyTlhraEd0dnRwVVFMX19LRW8wbWc6MQ&amp;ifq" method="POST" id="wp_rp_blogger_network_form" target="wp_rp_blogger_network_hidden_iframe">
263
- <input type="hidden" name="pageNumber" value="0" />
264
- <input type="hidden" name="backupCache" />
265
- <input type="hidden" name="entry.2.single" value="<?php echo get_bloginfo('wpurl'); ?>">
266
-
267
- <h2>Blogger networks</h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
 
269
- <table class="form-table"><tbody>
270
- <tr valign="top">
271
- <th scope="row"><label for="wp_rp_blogger_network_kind">I want to exchange traffic with</label></th>
272
- <td width="1%">
273
- <select name="entry.0.group" id="wp_rp_blogger_network_kind">
274
- <option value="Automotive" />Automotive bloggers</option>
275
- <option value="Beauty &amp; Style" />Beauty &amp; Style bloggers</option>
276
- <option value="Business" />Business bloggers</option>
277
- <option value="Consumer Tech" />Consumer Tech bloggers</option>
278
- <option value="Enterprise Tech" />Enterprise Tech bloggers</option>
279
- <option value="Entertainment" />Entertainment bloggers</option>
280
- <option value="Family &amp; Parenting" />Family &amp; Parenting bloggers</option>
281
- <option value="Food &amp; Drink" />Food &amp; Drink bloggers</option>
282
- <option value="Graphic Arts" />Graphic Arts bloggers</option>
283
- <option value="Healthy Living" />Healthy Living bloggers</option>
284
- <option value="Home &amp; Shelter" />Home &amp; Shelter bloggers</option>
285
- <option value="Lifestyle &amp; Hobby" />Lifestyle &amp; Hobby bloggers</option>
286
- <option value="Men's Lifestyle" />Men's Lifestyle bloggers</option>
287
- <option value="Personal Finance" />Personal Finance bloggers</option>
288
- <option value="Women's Lifestyle" />Women's Lifestyle bloggers</option>
289
- </select>
290
- </td>
291
- <td rowspan="2" valign="middle"><div id="wp_rp_blogger_network_thankyou"><img src="<?php echo plugins_url("static/img/check.png", __FILE__); ?>" width="30" height="22" />Thanks for showing interest.<br/>We'll contact you by email soon.</div></td>
292
- </tr>
293
- <tr valign="top">
294
- <th scope="row"><label for="wp_rp_blogger_network_email">My email is:</label></th>
295
- <td><input type="email" name="entry.1.single" value="" id="wp_rp_blogger_network_email" required="required" /></td>
296
- </tr>
297
- <tr valign="top">
298
- <th scope="row"></th>
299
- <td><input type="submit" name="submit" value="Submit" id="wp_rp_blogger_network_submit" /></td>
300
- </tbody></table>
301
 
302
  <script type="text/javascript">
303
  jQuery(function($) {
304
- var submit = $('#wp_rp_blogger_network_submit'),
305
- email_input = $('#wp_rp_blogger_network_email'),
 
 
 
 
 
 
306
  email_regex = /^[^@]+@[^@]+$/;
307
- $('#wp_rp_blogger_network_form').submit(function(event) {
308
- if(!email_regex.test(email_input.val())) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  event.preventDefault();
310
- email_input.animate({backgroundColor: '#faa'}).focus();
311
  return;
312
  }
313
- email_input.css({backgroundColor: ''});
 
314
  submit.addClass('disabled');
315
  setTimeout(function() { submit.attr('disabled', true); }, 0);
316
- $('#wp_rp_blogger_network_hidden_iframe').load(function() {
317
- submit.attr('disabled', false).removeClass('disabled');
318
- $('#wp_rp_blogger_network_thankyou').fadeIn('slow');
319
- $.post(ajaxurl, {action: 'blogger_network_submit'});
320
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  });
322
  });
323
  </script>
324
  </form>
325
- <iframe id="wp_rp_blogger_network_hidden_iframe" name="wp_rp_blogger_network_hidden_iframe" style="display: none"></iframe>
326
  <?php endif; ?>
327
 
328
- <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=wordpress-related-posts">
329
- <?php if (wp_rp_statistics_supported()): ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  <h2><?php _e("Statistics",'wp_related_posts');?></h2>
331
  <div id="wp_rp_statistics_wrap">
332
- <div class="option-enable">
333
- <?php if ($meta['show_ctr_banner']):?>
334
- <img src="<?php echo plugins_url("static/img/arrow.png", __FILE__); ?>" class="arrow" />
335
- <?php endif; ?>
336
- <label>
337
- <input name="wp_rp_ctr_dashboard_enabled" type="checkbox" value="yes" <?php checked($options['ctr_dashboard_enabled']); ?> />
338
- <span><?php _e("Turn statistics on",'wp_related_posts');?> </span>
339
- </label>
340
- </div>
341
- <?php if ($meta['show_ctr_banner']):?>
342
- <div class="message enable">
343
- <?php _e("Curious about the Click-Through Statistics on your blog?",'wp_related_posts');?>
344
- </div>
345
- <?php endif; ?>
346
  <div class="message unavailable"><?php _e("Statistics currently unavailable",'wp_related_posts');?></div>
347
  </div>
348
- <?php endif; ?>
349
 
350
  <h2><?php _e("Settings",'wp_related_posts');?></h2>
351
  <h3><?php _e("Basic Settings",'wp_related_posts');?></h3>
@@ -386,14 +503,14 @@ jQuery(function($) {
386
  </tr>
387
  </table>
388
 
389
- <h3>Theme Settings <small style="color: #c33;">(new)</small></h3>
390
  <table class="form-table">
391
  <tr id="wp_rp_theme_options_wrap">
392
  <th scope="row">Select Theme:</th>
393
  <td>
394
  <label>
395
  <input name="wp_rp_enable_themes" type="checkbox" id="wp_rp_enable_themes" value="yes"<?php checked($options["enable_themes"]); ?> />
396
- <?php _e("Enable Themes (Loaded from external service)",'wp_related_posts'); ?>
397
  </label>
398
  <div class="theme-list"></div>
399
  </td>
@@ -495,6 +612,15 @@ jQuery(function($) {
495
  </label>
496
  </td>
497
  </tr>
 
 
 
 
 
 
 
 
 
498
  </table>
499
 
500
  <h3><?php _e("If there are no related posts",'wp_related_posts');?></h3>
@@ -545,7 +671,7 @@ jQuery(function($) {
545
  <input name="wp_rp_on_single_post" type="checkbox" id="wp_rp_on_single_post" value="yes" <?php checked($options['on_single_post']); ?>>
546
  <?php _e("Auto Insert Related Posts",'wp_related_posts');?>
547
  </label>
548
- (or add `&lt;?php wp_related_posts()?&gt;` to your single post template)
549
  <br />
550
  <label>
551
  <input name="wp_rp_on_rss" type="checkbox" id="wp_rp_on_rss" value="yes"<?php checked($options['on_rss']); ?>>
@@ -554,7 +680,12 @@ jQuery(function($) {
554
  <br />
555
  <label>
556
  <input name="wp_rp_include_promotionail_link" type="checkbox" id="wp_rp_include_promotionail_link" value="yes"<?php checked($options['include_promotionail_link']); ?> />
557
- <?php _e('Help Promote This Plugin', 'wp_related_posts'); ?>
 
 
 
 
 
558
  </label>
559
  </td>
560
  </tr>
@@ -562,5 +693,8 @@ jQuery(function($) {
562
  <p class="submit"><input type="submit" value="<?php _e('Save changes', 'wp_related_posts'); ?>" class="button-primary" /></p>
563
 
564
  </form>
 
 
 
565
  </div>
566
  <?php }
6
 
7
  function wp_rp_display_tooltips() {
8
  $meta = wp_rp_get_meta();
 
9
 
10
  if ($meta['show_upgrade_tooltip']) {
11
  $meta['show_upgrade_tooltip'] = false;
12
+ wp_rp_update_meta($meta);
 
13
 
14
  add_action('admin_enqueue_scripts', 'wp_rp_load_upgrade_tooltip');
15
  } else if ($meta['show_install_tooltip']) {
16
  $meta['show_install_tooltip'] = false;
17
+ wp_rp_update_meta($meta);
 
18
 
19
  add_action('admin_enqueue_scripts', 'wp_rp_load_install_tooltip');
20
  }
50
  function wp_rp_print_tooltip($content) {
51
  ?>
52
  <script type="text/javascript">
53
+ jQuery(function ($) {
54
+ var body = $(document.body),
55
+ collapse = $('#collapse-menu'),
56
+ target = $("#toplevel_page_wordpress-related-posts"),
57
+ collapse_handler = function (e) {
58
+ body.pointer('reposition');
59
+ },
60
  options = {
61
  content: "<?php echo $content; ?>",
62
  position: {
63
  edge: 'left',
64
  align: 'center',
65
+ of: target
66
+ },
67
+ open: function () {
68
+ collapse.bind('click', collapse_handler);
69
  },
70
  close: function() {
71
+ collapse.unbind('click', collapse_handler);
 
72
  }
 
 
 
 
 
 
 
 
 
 
73
  };
74
 
75
+ if (target.length) {
76
+ body.pointer(options).pointer('open');
 
 
 
 
 
 
 
77
  }
78
  });
79
  </script>
80
  <?php
81
  }
82
 
83
+ /**
84
+ * Place menu icons at admin head
85
+ **/
86
+ add_action('admin_head', 'wp_rp_admin_head');
87
+ function wp_rp_admin_head() {
88
+ $menu_icon = plugins_url('static/img/menu_icon.png', __FILE__);
89
+ $menu_icon_retina = plugins_url('static/img/menu_icon_2x.png', __FILE__);
90
+ ?>
91
+ <style type="text/css">
92
+ #toplevel_page_wordpress-related-posts .wp-menu-image {
93
+ background: url('<?php echo $menu_icon; ?>') 7px 6px no-repeat;
94
+ }
95
+ @media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
96
+ #toplevel_page_wordpress-related-posts .wp-menu-image {
97
+ background-image: url('<?php echo $menu_icon_retina; ?>');
98
+ background-size: 16px 16px;
99
+ }
100
+ }
101
+ </style>
102
+ <?php
103
+ }
104
+
105
  /**
106
  * Settings
107
  **/
109
  add_action('admin_menu', 'wp_rp_settings_admin_menu');
110
 
111
  function wp_rp_settings_admin_menu() {
112
+ $page = add_menu_page(__('Related Posts', 'wp_related_posts'), __('Related Posts', 'wp_related_posts'),
113
+ 'manage_options', 'wordpress-related-posts', 'wp_rp_settings_page', 'div');
114
 
115
  add_action('admin_print_styles-' . $page, 'wp_rp_settings_styles');
116
  add_action('admin_print_scripts-' . $page, 'wp_rp_settings_scripts');
126
  wp_enqueue_style("wp_rp_dashaboard_style", plugins_url("static/css/dashboard.css", __FILE__));
127
  }
128
 
129
+ function wp_rp_register_blog() {
130
  $meta = wp_rp_get_meta();
131
 
132
+ $req_options = array(
133
+ 'timeout' => 30
134
+ );
135
+
136
+ $response = wp_remote_get(WP_RP_CTR_DASHBOARD_URL . 'register/?blog_url=' . get_bloginfo('wpurl') . ($meta['new_user'] ? '&new' : ''), $req_options);
137
+ if (wp_remote_retrieve_response_code($response) == 200) {
138
+ $body = wp_remote_retrieve_body($response);
139
+ if ($body) {
140
+ $doc = json_decode($body);
141
+ if ($doc && $doc->status === 'ok') {
142
+ $meta['blog_id'] = $doc->data->blog_id;
143
+ $meta['auth_key'] = $doc->data->auth_key;
144
+ $meta['new_user'] = false;
145
+ wp_rp_update_meta($meta);
146
+
147
+ return true;
148
+ }
149
+ }
150
+ }
151
+ return false;
152
+ }
153
+
154
+ function wp_rp_ajax_invite_friends_callback() {
155
+ $postdata = stripslashes_deep($_POST);
156
+
157
+ $meta = wp_rp_get_meta();
158
+
159
+ if(isset($postdata['name'])) {
160
+ $meta['name'] = $postdata['name'];
161
+ }
162
+ if(isset($postdata['email'])) {
163
+ $meta['email'] = $postdata['email'];
164
+ }
165
+ if(isset($postdata['show'])) {
166
+ $meta['show_invite_friends_form'] = true;
167
+ }
168
+ if(isset($postdata['hide'])) {
169
+ $meta['show_invite_friends_form'] = false;
170
+ }
171
+ if(isset($postdata['recommend'])) {
172
+ $meta['remote_recommendations'] = true;
173
+ }
174
+
175
+ wp_rp_update_meta($meta);
176
 
 
177
 
178
+ echo 'ok';
179
  die();
180
  }
181
 
182
+ add_action('wp_ajax_rp_invite_friends', 'wp_rp_ajax_invite_friends_callback');
183
 
184
  function wp_rp_settings_page()
185
  {
 
 
186
  $title_tags = array('h2', 'h3', 'h4', 'p', 'div');
187
 
188
+ $options = wp_rp_get_options();
189
+ $meta = wp_rp_get_meta();
190
+
191
  $postdata = stripslashes_deep($_POST);
192
 
193
  if(sizeof($_POST))
194
  {
195
  $message = __('WordPress Related Posts Setting Updated', 'wp_related_posts');
196
 
197
+ $old_options = $options;
198
  $new_options = array(
199
  'missing_rp_algorithm' => isset($postdata['wp_rp_missing_rp_algorithm']) ? trim($postdata['wp_rp_missing_rp_algorithm']) : 'random',
200
  'missing_rp_title' => isset($postdata['wp_rp_missing_rp_title']) ? ($postdata['wp_rp_missing_rp_title']) : __('Random Posts', 'wp_related_posts'),
214
  'thumbnail_use_custom' => isset($postdata['wp_rp_thumbnail_use_custom']) && $postdata['wp_rp_thumbnail_use_custom'] === 'yes',
215
  'ctr_dashboard_enabled' => isset($postdata['wp_rp_ctr_dashboard_enabled']),
216
  'include_promotionail_link' => isset($postdata['wp_rp_include_promotionail_link']),
217
+ 'enable_themes' => isset($postdata['wp_rp_enable_themes']),
218
+ 'scroll_up_related_posts' => isset($postdata['wp_rp_scroll_up_related_posts'])
219
  );
220
 
221
  if(!isset($postdata['wp_rp_not_on_categories'])) {
250
  }
251
  }
252
 
253
+ if (((array) $old_options) != $new_options) {
254
+ if($new_options['ctr_dashboard_enabled'] && $new_options['display_thumbnail'] && $meta['show_turn_on_button']) {
255
+ $meta['show_turn_on_button'] = false;
256
+ wp_rp_update_meta($meta);
 
 
 
257
  }
258
 
259
+ if(!wp_rp_update_options($new_options)) {
 
 
 
260
  $message = __('Update Failed', 'wp_related_posts');
261
  }
262
  }
263
  }
264
 
265
+ if($options['ctr_dashboard_enabled'] && (!$meta['blog_id'] || !$meta['auth_key'])) {
266
+ wp_rp_register_blog();
267
+ }
268
 
269
  ?>
270
 
281
  <input type="hidden" id="wp_rp_json_url" value="<?php esc_attr_e(WP_RP_STATIC_BASE_URL . WP_RP_STATIC_JSON_PATH); ?>" />
282
  <input type="hidden" id="wp_rp_version" value="<?php esc_attr_e(WP_RP_VERSION); ?>" />
283
  <input type="hidden" id="wp_rp_theme_selected" value="<?php esc_attr_e($theme_name); ?>" />
284
+ <input type="hidden" id="wp_rp_dashboard_url" value="<?php esc_attr_e(WP_RP_CTR_DASHBOARD_URL); ?>" />
285
 
286
+ <?php if ($options['ctr_dashboard_enabled']):?>
 
287
  <input type="hidden" id="wp_rp_blog_id" value="<?php esc_attr_e($meta['blog_id']); ?>" />
288
  <input type="hidden" id="wp_rp_auth_key" value="<?php esc_attr_e($meta['auth_key']); ?>" />
289
  <?php endif; ?>
290
 
291
  <div class="header">
 
 
292
  <div class="support">
293
  <h4><?php _e("Awesome support", 'wp_related_posts'); ?></h4>
294
  <p>
295
  <?php _e("If you have any questions please contact us at",'wp_related_posts');?> <a target="_blank" href="mailto:relatedpostsplugin@gmail.com"><?php _e("support", 'wp_related_posts');?></a>.
296
  </p>
297
  </div>
298
+ <h2 class="title"><?php _e("Related Posts",'wp_related_posts');?></h2>
299
+ <p class="desc"><?php _e("WordPress Related Posts Plugin places a list of related articles via WordPress tags at the bottom of your post.",'wp_related_posts');?></p>
300
  </div>
301
  <div id="wp-rp-survey" class="updated highlight" style="display:none;"><p><?php _e("Please fill out",'wp_related_posts');?> <a class="link" target="_blank" href="http://wprelatedposts.polldaddy.com/s/new-features"><?php _e("a quick survey", 'wp_related_posts');?></a>.<a href="#" class="close" style="float: right;">x</a></p></div>
302
 
304
  <div id="message" class="updated fade"><p><?php echo $message ?>.</p></div>
305
  <?php endif; ?>
306
 
307
+ <?php if(!$meta['show_turn_on_button']): ?>
308
+ <form action="https://docs.google.com/a/zemanta.com/spreadsheet/formResponse?formkey=dHhqdWtyZHIwN0Z5R2ZEel9oZVBidEE6MQ&amp;ifq" method="POST" id="wp_rp_invite_friends_form" target="wp_rp_invite_friends_hidden_iframe" <?php if(!$meta['show_invite_friends_form']) { ?>class="up"<?php } ?>>
309
+ <input type="hidden" name="pageNumber" value="0">
310
+ <input type="hidden" name="backupCache" value="">
311
+ <input type="hidden" name="entry.6.single" value="<?php echo get_bloginfo('wpurl'); ?>">
312
+
313
+ <a href="#" id="wp_rp_invite_friends_slide"><img src="<?php echo plugins_url('/static/img/up.png', __FILE__); ?>" width="17" height="6" border="0" class="up" /><img src="<?php echo plugins_url('/static/img/down.png', __FILE__); ?>" width="17" height="6" border="0" class="down" /></a>
314
+ <h2>Invite friends</h2>
315
+
316
+ <div class="slide-down" <?php if(!$meta['show_invite_friends_form']) { ?>style="display: none"<?php } ?>>
317
+ <p>Get your friends to use WordPress Related Posts and instantly exchange traffic with them. Your posts will appear on their site and vice versa.</p>
318
+
319
+ <?php if(!$meta['name'] || !$meta['email']): ?>
320
+ <table class="form-table" id="wp_rp_invite_friends_name_table"><tbody>
321
+ <tr valign="top">
322
+ <th scope="row"><label for="wp_rp_invite_friends_blogger_name">Your name</label></th>
323
+ <td width="1%"><input type="text" name="entry.0.single" value="" id="wp_rp_invite_friends_blogger_name" tabindex="1" requred="required" /></td>
324
+ <td rowspan="2"></td>
325
+ </tr><tr valign="top">
326
+ <th scope="row"><label for="wp_rp_invite_friends_blogger_email">Your email</label></th>
327
+ <td><input type="email" name="entry.1.single" value="" id="wp_rp_invite_friends_blogger_email" tabindex="2" requred="required" /><br/></td>
328
+ </tr>
329
+ </tbody></table>
330
+ <div class="hr" id="wp_rp_confirmation_hr"></div>
331
+ <? else: ?>
332
+ <input type="hidden" name="entry.0.single" value="<?php echo $meta['name']; ?>">
333
+ <input type="hidden" name="entry.1.single" value="<?php echo $meta['email']; ?>">
334
+ <div class="hr" id="wp_rp_confirmation_hr" style="display: none;"></div>
335
+ <?php endif; ?>
336
 
337
+ <table class="form-table"><tbody>
338
+ <tr valign="top">
339
+ <th scope="row"><label for="wp_rp_invite_friends_friend_url">Your friend's blog</label></th>
340
+ <td width="1%"><input type="text" name="entry.2.single" value="" id="wp_rp_invite_friends_friend_url" tabindex="3" required="required" /></td>
341
+ <td rowspan="2" valign="middle"><input type="submit" name="submit" value="Invite" id="wp_rp_invite_friends_submit" tabindex="5" /></td>
342
+ </tr><tr valign="top">
343
+ <th scope="row"><label for="wp_rp_invite_friends_friend_email">Your friend's email</label></th>
344
+ <td><input type="email" name="entry.4.single" value="" id="wp_rp_invite_friends_friend_email" tabindex="4" required="required" /></td>
345
+ </tr>
346
+ </tbody></table>
347
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
 
349
  <script type="text/javascript">
350
  jQuery(function($) {
351
+ var submit = $('#wp_rp_invite_friends_submit'),
352
+ form = $('#wp_rp_invite_friends_form'),
353
+ blogger_name = $('#wp_rp_invite_friends_blogger_name'),
354
+ blogger_email = $('#wp_rp_invite_friends_blogger_email'),
355
+ friend_url = $('#wp_rp_invite_friends_friend_url'),
356
+ friend_email = $('#wp_rp_invite_friends_friend_email'),
357
+ slide_div = form.find('.slide-down'),
358
+ submitted = false;
359
  email_regex = /^[^@]+@[^@]+$/;
360
+ $('#wp_rp_invite_friends_form').submit(function(event) {
361
+ var valid = true;
362
+ if(!email_regex.test(friend_email.val())) {
363
+ valid = false;
364
+ friend_email.animate({backgroundColor: '#faa'}).focus();
365
+ } else {
366
+ friend_email.css({backgroundColor: ''});
367
+ }
368
+ if(!friend_url.val()) {
369
+ valid = false;
370
+ friend_url.animate({backgroundColor: '#faa'}).focus();
371
+ } else {
372
+ friend_url.css({backgroundColor: ''});
373
+ }
374
+ if(blogger_email.length && !email_regex.test(blogger_email.val())) {
375
+ valid = false;
376
+ blogger_email.animate({backgroundColor: '#faa'}).focus();
377
+ } else {
378
+ blogger_email.css({backgroundColor: ''});
379
+ }
380
+ if(blogger_name.length && !blogger_name.val()) {
381
+ valid = false;
382
+ blogger_name.animate({backgroundColor: '#faa'}).focus();
383
+ } else {
384
+ blogger_name.css({backgroundColor: ''});
385
+ }
386
+ if(!valid) {
387
  event.preventDefault();
 
388
  return;
389
  }
390
+
391
+ submitted = true;
392
  submit.addClass('disabled');
393
  setTimeout(function() { submit.attr('disabled', true); }, 0);
394
+ });
395
+
396
+ $('#wp_rp_invite_friends_hidden_iframe').load(function() {
397
+ if(!submitted) { return; } else { submitted = false; }
398
+
399
+ setTimeout(function() {
400
+ submit.attr('disabled', false).removeClass('disabled');
401
+ var confirmation = $('<div class="confirmation">An invitation was sent to <span>' + friend_email.val() + '</span>.</div>'),
402
+ hr = form.find('#wp_rp_confirmation_hr'),
403
+ name_table = $('#wp_rp_invite_friends_name_table');
404
+
405
+ name_table.hide();
406
+ hr.fadeIn();
407
+ confirmation.hide().insertBefore(hr).fadeIn();
408
+
409
+ var data = { action: 'rp_invite_friends',
410
+ recommend: true };
411
+
412
+ if(blogger_name.length && blogger_email.length) {
413
+ form.append('<input type="hidden" name="entry.0.single" value="' + blogger_name.val() + '">');
414
+ form.append('<input type="hidden" name="entry.1.single" value="' + blogger_email.val() + '">');
415
+
416
+ data['name'] = blogger_name.val();
417
+ data['email'] = blogger_email.val();
418
+
419
+ blogger_name.remove();
420
+ blogger_email.remove();
421
+ }
422
+ $.post(ajaxurl, data);
423
+
424
+ form[0].reset();
425
+ }, 100);
426
+ });
427
+
428
+ $('#wp_rp_invite_friends_slide').click(function (event) {
429
+ event.preventDefault();
430
+ if(form.hasClass('up')) {
431
+ slide_div.slideDown();
432
+ form.removeClass('up');
433
+ $.post(ajaxurl, { action: 'rp_invite_friends', show: true });
434
+ } else {
435
+ slide_div.slideUp();
436
+ form.addClass('up');
437
+ $.post(ajaxurl, { action: 'rp_invite_friends', hide: true });
438
+ }
439
  });
440
  });
441
  </script>
442
  </form>
443
+ <iframe id="wp_rp_invite_friends_hidden_iframe" name="wp_rp_invite_friends_hidden_iframe" style="display: none"></iframe>
444
  <?php endif; ?>
445
 
446
+ <?php if($meta['show_turn_on_button']): ?>
447
+ <div id="wp_rp_turn_on_statistics">
448
+ <table cellspacing="0" cellpadding="0"><tbody><tr>
449
+ <td>
450
+ <h2>Turn on Statistics & Thumbnails</h2>
451
+ <p>Real time traffic analytics are provided via third party service.</p>
452
+ </td><td>
453
+ <a href="#">Turn on</a>
454
+ </td>
455
+ </tr></tbody></table>
456
+ </div>
457
+ <?php endif; ?>
458
+
459
+ <form method="post" enctype="multipart/form-data" action="" id="wp_rp_settings_form">
460
+ <?php if ($options['ctr_dashboard_enabled']): ?>
461
  <h2><?php _e("Statistics",'wp_related_posts');?></h2>
462
  <div id="wp_rp_statistics_wrap">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
  <div class="message unavailable"><?php _e("Statistics currently unavailable",'wp_related_posts');?></div>
464
  </div>
465
+ <?php endif; ?>
466
 
467
  <h2><?php _e("Settings",'wp_related_posts');?></h2>
468
  <h3><?php _e("Basic Settings",'wp_related_posts');?></h3>
503
  </tr>
504
  </table>
505
 
506
+ <h3>Theme Settings</h3>
507
  <table class="form-table">
508
  <tr id="wp_rp_theme_options_wrap">
509
  <th scope="row">Select Theme:</th>
510
  <td>
511
  <label>
512
  <input name="wp_rp_enable_themes" type="checkbox" id="wp_rp_enable_themes" value="yes"<?php checked($options["enable_themes"]); ?> />
513
+ <?php _e("Enable Themes",'wp_related_posts'); ?>*
514
  </label>
515
  <div class="theme-list"></div>
516
  </td>
612
  </label>
613
  </td>
614
  </tr>
615
+ <tr>
616
+ <th scope="row"><?php _e("Experimental:",'wp_related_posts'); ?></th>
617
+ <td>
618
+ <label>
619
+ <input name="wp_rp_scroll_up_related_posts" type="checkbox" id="wp_rp_scroll_up_related_posts" value="yes" <?php checked($options["scroll_up_related_posts"]); ?>>
620
+ <?php _e("Scroll Up Related Posts",'wp_related_posts');?>*
621
+ </label><br />
622
+ </td>
623
+ </tr>
624
  </table>
625
 
626
  <h3><?php _e("If there are no related posts",'wp_related_posts');?></h3>
671
  <input name="wp_rp_on_single_post" type="checkbox" id="wp_rp_on_single_post" value="yes" <?php checked($options['on_single_post']); ?>>
672
  <?php _e("Auto Insert Related Posts",'wp_related_posts');?>
673
  </label>
674
+ (or add <pre style="display: inline">&lt;?php wp_related_posts()?&gt;</pre> to your single post template)
675
  <br />
676
  <label>
677
  <input name="wp_rp_on_rss" type="checkbox" id="wp_rp_on_rss" value="yes"<?php checked($options['on_rss']); ?>>
680
  <br />
681
  <label>
682
  <input name="wp_rp_include_promotionail_link" type="checkbox" id="wp_rp_include_promotionail_link" value="yes"<?php checked($options['include_promotionail_link']); ?> />
683
+ <?php _e('Help Promote This Plugin', 'wp_related_posts'); ?>*
684
+ </label>
685
+ <br />
686
+ <label>
687
+ <input name="wp_rp_ctr_dashboard_enabled" type="checkbox" id="wp_rp_ctr_dashboard_enabled" value="yes" <?php checked($options['ctr_dashboard_enabled']); ?> />
688
+ <?php _e("Turn statistics on",'wp_related_posts');?>*
689
  </label>
690
  </td>
691
  </tr>
693
  <p class="submit"><input type="submit" value="<?php _e('Save changes', 'wp_related_posts'); ?>" class="button-primary" /></p>
694
 
695
  </form>
696
+ <div>
697
+ * Provided via third party service.
698
+ </div>
699
  </div>
700
  <?php }
static/css/dashboard.css CHANGED
@@ -8,16 +8,15 @@
8
  #wp_rp_wrap th {padding-left: 0; font-size: 14px;}
9
 
10
  #wp_rp_wrap div.header {border-bottom: 1px solid #ddd; position: relative; padding-bottom: 5px;}
11
- #wp_rp_wrap .updated, #wp_rp_wrap .error {max-width: 600px;}
12
  #wp_rp_wrap div.header h2.title {font-size: 2.5em; line-height: 1em; font-weight: bold;}
13
  #wp_rp_wrap div.header p.desc {font-size: 1.2em; line-height: 1.5em; max-width: 430px;}
14
- #wp_rp_wrap div.header div.support {padding: 15px 15px 15px 67px; background: url(../img/icon_support.png) 15px 20px no-repeat; background-size: 37px 37px; border: 1px solid #ddd; position: absolute; top: 10px; right: 0px; width: 150px;}
15
  #wp_rp_wrap div.header div.support h4 {text-transform: uppercase; font-weight: bold; margin: 0; font-size: 11px;}
16
  #wp_rp_wrap div.header div.support p {margin: 0; font-size: 11px;}
17
  #wp_rp_wrap div.header div.support p a {color: #82c1cb; font-weight: bold; text-decoration: none;}
18
 
19
  #wp_rp_wrap div#wp_rp_statistics_wrap {padding: 5px 0;}
20
- #wp_rp_wrap div#wp_rp_statistics_wrap .option-enable {width: 790px; text-align: right; height: 30px;}
21
  #wp_rp_wrap div#wp_rp_statistics_wrap ul.statistics li {display: inline-block; zoom: 1; *display: inline; width: 250px; margin: 0 20px 0 0; padding: 0; position: relative;}
22
  #wp_rp_wrap div#wp_rp_statistics_wrap ul.statistics li div.overlay {display: none; position: absolute; top: 0; left: 0; width: 240px; padding: 100px 10px 10px 10px; margin: -5px 0 0 -5px; border: 1px solid #ccc; box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.2);}
23
  #wp_rp_wrap div#wp_rp_statistics_wrap ul.statistics li div.overlay p {background: #fff; margin: -10px; padding: 10px;}
@@ -29,11 +28,23 @@
29
  #wp_rp_wrap div#wp_rp_statistics_wrap div.message {font-size: 25px; line-height: 1em; padding-top: 50px; margin-bottom: 15px; position: relative; font-weight: bold;}
30
  #wp_rp_wrap div#wp_rp_statistics_wrap div.message.enable {color: #82c1cb;}
31
  #wp_rp_wrap div#wp_rp_statistics_wrap div.message.unavailable {color: #848484; display: none; padding-top: 20px;}
32
- #wp_rp_wrap div#wp_rp_statistics_wrap div.option-enable img.arrow {width: 83px; height: 51px; margin-bottom: -40px; margin-right: 1em;}
33
 
34
- #wp_rp_blogger_network_form { background: #f7f7f7; padding: 20px; margin: 30px 0px; border: 1px solid #e1e1e1; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }
35
- #wp_rp_blogger_network_form h2 { font-size: 19px; line-height: 20px; padding-top: 0px; }
36
- #wp_rp_blogger_network_submit { background-color: #8ac6d0; border-color: #57aab8; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; color: white; padding: 7px 25px; font-size: 14px; text-shadow: 1px 1px 1px #666; }
37
- #wp_rp_blogger_network_submit.disabled { background-color: #ddd; border-color: #bababa; }
38
- #wp_rp_blogger_network_thankyou { font-size: 14px; display: none; }
39
- #wp_rp_blogger_network_thankyou img { float: left; margin: 10px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  #wp_rp_wrap th {padding-left: 0; font-size: 14px;}
9
 
10
  #wp_rp_wrap div.header {border-bottom: 1px solid #ddd; position: relative; padding-bottom: 5px;}
11
+ #wp_rp_wrap .updated, #wp_rp_wrap .error {max-width: 600px; margin-right: 254px; }
12
  #wp_rp_wrap div.header h2.title {font-size: 2.5em; line-height: 1em; font-weight: bold;}
13
  #wp_rp_wrap div.header p.desc {font-size: 1.2em; line-height: 1.5em; max-width: 430px;}
14
+ #wp_rp_wrap div.header div.support {padding: 15px 15px 15px 67px; background: url(../img/icon_support.png) 15px 20px no-repeat; background-size: 37px 37px; border: 1px solid #ddd; float: right; clear: right; width: 150px;}
15
  #wp_rp_wrap div.header div.support h4 {text-transform: uppercase; font-weight: bold; margin: 0; font-size: 11px;}
16
  #wp_rp_wrap div.header div.support p {margin: 0; font-size: 11px;}
17
  #wp_rp_wrap div.header div.support p a {color: #82c1cb; font-weight: bold; text-decoration: none;}
18
 
19
  #wp_rp_wrap div#wp_rp_statistics_wrap {padding: 5px 0;}
 
20
  #wp_rp_wrap div#wp_rp_statistics_wrap ul.statistics li {display: inline-block; zoom: 1; *display: inline; width: 250px; margin: 0 20px 0 0; padding: 0; position: relative;}
21
  #wp_rp_wrap div#wp_rp_statistics_wrap ul.statistics li div.overlay {display: none; position: absolute; top: 0; left: 0; width: 240px; padding: 100px 10px 10px 10px; margin: -5px 0 0 -5px; border: 1px solid #ccc; box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.2);}
22
  #wp_rp_wrap div#wp_rp_statistics_wrap ul.statistics li div.overlay p {background: #fff; margin: -10px; padding: 10px;}
28
  #wp_rp_wrap div#wp_rp_statistics_wrap div.message {font-size: 25px; line-height: 1em; padding-top: 50px; margin-bottom: 15px; position: relative; font-weight: bold;}
29
  #wp_rp_wrap div#wp_rp_statistics_wrap div.message.enable {color: #82c1cb;}
30
  #wp_rp_wrap div#wp_rp_statistics_wrap div.message.unavailable {color: #848484; display: none; padding-top: 20px;}
 
31
 
32
+ #wp_rp_invite_friends_form { background: #f7f7f7; padding: 15px; margin: 30px 0px; border: 1px solid #e1e1e1; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }
33
+ #wp_rp_invite_friends_form h2 { font-size: 19px; line-height: 20px; padding: 0px; }
34
+ #wp_rp_invite_friends_submit { background: #8bc7d1; border-color: #57aab8; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; color: white; padding: 8px 25px; font-size: 15px; text-shadow: 0px 1px 1px #888; font-weight: bold; box-shadow: 0px 1px 4px -2px black, 0px 1px 0px #a8d9e0 inset; }
35
+ #wp_rp_invite_friends_submit.disabled { background-color: #ddd; border-color: #bababa; box-shadow: 0px 1px 4px -2px black, 0px 1px 0px #eaeaea inset; }
36
+ #wp_rp_invite_friends_form .hr { margin: 20px 10px; border-top: 1px solid #ddd; }
37
+ #wp_rp_invite_friends_form .confirmation { color: #222; margin: 12px 0px; }
38
+ #wp_rp_invite_friends_form .confirmation span { font-style: italic; color: #57aab8; }
39
+ #wp_rp_invite_friends_form .slide-down { overflow: hidden; }
40
+ #wp_rp_invite_friends_slide { float: right; }
41
+ #wp_rp_invite_friends_slide img { margin-top: 8px; }
42
+ #wp_rp_invite_friends_form.up img.up { display: none; }
43
+ #wp_rp_invite_friends_form img.down { display: none; }
44
+ #wp_rp_invite_friends_form.up img.down { display: block; }
45
+
46
+ #wp_rp_turn_on_statistics { margin: 20px 0px; padding: 20px; background: #f7f7f7; border: 1px solid #e1e1e1; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }
47
+ #wp_rp_turn_on_statistics table { margin: 0px auto; }
48
+ #wp_rp_turn_on_statistics h2 { font-weight: bold; }
49
+ #wp_rp_turn_on_statistics p { margin: 0px; color: #777; }
50
+ #wp_rp_turn_on_statistics a { margin-left: 25px; background: #8bc7d1; border: 1px solid #57aab8; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; color: white; padding: 8px 30px; text-shadow: 0px 1px 1px #888; font-weight: bold; font-size: 20px; line-height: 20px; text-decoration: none; text-transform: uppercase; box-shadow: 0px 1px 4px -2px black, 0px 1px 0px #a8d9e0 inset; }
static/img/arrow.png DELETED
Binary file
static/img/down.png ADDED
Binary file
static/img/menu_icon.png ADDED
Binary file
static/img/menu_icon_2x.png ADDED
Binary file
static/img/promoted_arrow.png ADDED
Binary file
static/img/up.png ADDED
Binary file
static/js/dashboard.js CHANGED
@@ -1,6 +1,5 @@
1
- (function(a){var e=function(b,c){a.each(c,function(a,c){b=b.replace(RegExp("{{ *"+a+" *}}"),c)});return b};a(function(){var b=a("#wp_rp_statistics_wrap"),c=a("#wp_rp_dashboard_url").val(),h=a("#wp_rp_blog_id").val(),i=a("#wp_rp_auth_key").val();update_interval=req_timeout=null;update_interval_sec=2E3;update_interval_error_sec=3E4;updating=!1;ul=null;set_update_interval=function(a){a||(a=update_interval_sec);clearInterval(update_interval);0<a&&(update_interval=setInterval(update_dashboard,a))};display_error=
2
- function(b){var n=a("#wp_rp_statistics_wrap");b||n.find(".unavailable").slideDown();set_update_interval(update_interval_error_sec);updating=!1};create_dashboard=function(){ul=a('<ul class="statistics" />');b.find(".unavailable").slideUp();ul.append(e('<li class="{{class}}"><h4>{{ title}}<span>{{range}}</span></h4><p class="num"></p><div class="overlay"><p>{{description}}</p></div></li>',{"class":"ctr",title:"click-through rate",description:"Number of clicks on a Related Post divided by the number of times the post was shown to readers. Tip: Using thumbnails will generally rise Click-through Rates.",
3
- range:"last 30 days"}));ul.append(e('<li class="{{class}}"><h4>{{ title}}<span>{{range}}</span></h4><p class="num"></p><div class="overlay"><p>{{description}}</p></div></li>',{"class":"pageviews",title:"page views",description:"Number of times the page (usually post) was loaded to readers.",range:"last 30 days"}));ul.append(e('<li class="{{class}}"><h4>{{ title}}<span>{{range}}</span></h4><p class="num"></p><div class="overlay"><p>{{description}}</p></div></li>',{"class":"clicks",title:"clicks",description:"Number of times a reader has clicked on one of the Related Posts.",
4
- range:"last 30 days"}));ul.hide();b.append(ul);ul.slideDown()};update_dashboard=function(b){updating||(updating=!0,req_timeout=setTimeout(function(){display_error(!b)},2E3),a.getJSON(c+"pageviews/?callback=?",{blog_id:h,auth_key:i},function(a){clearTimeout(req_timeout);!a||"ok"!==a.status||!a.data?display_error(!b):(ul||create_dashboard(),set_update_interval(a.data.update_interval),ul.find(".ctr .num").html(a.data.ctr+"%"),ul.find(".pageviews .num").html(a.data.pageviews),ul.find(".clicks .num").html(a.data.clicks),
5
- updating=!1)}))};if(c){if(!h||!i){display_error();return}update_dashboard(!0);update_interval=setInterval(update_dashboard,2E3)}var f=a("<em>(don't forget to save the changes)</em>").css({display:"none",color:"red"}),j=a("#wp_rp_statistics_wrap .option-enable span"),d=j.parent(),k=d.position(),g=d.parent().find("img"),l=g.position(),m=d.find("input"),p=m[0].checked;d.css({position:"absolute",top:k.top+"px",left:k.left+"px"});g.length&&g.css({position:"absolute",top:l.top+"px",left:l.left+"px"});j.append(f);
6
- m.change(function(){this.checked!==p?f.show():f.hide()})})})(jQuery);
1
+ (function(a){var b=function(c,b){a.each(b,function(a,b){c=c.replace(RegExp("{{ *"+a+" *}}"),b)});return c};a(function(){var c=a("#wp_rp_statistics_wrap"),f=a("#wp_rp_dashboard_url").val(),d=a("#wp_rp_blog_id").val(),e=a("#wp_rp_auth_key").val();update_interval=req_timeout=null;update_interval_sec=2E3;update_interval_error_sec=3E4;updating=!1;ul=null;set_update_interval=function(a){a||(a=update_interval_sec);clearInterval(update_interval);0<a&&(update_interval=setInterval(update_dashboard,a))};display_error=
2
+ function(b){var g=a("#wp_rp_statistics_wrap");b||g.find(".unavailable").slideDown();set_update_interval(update_interval_error_sec);updating=!1};create_dashboard=function(){ul=a('<ul class="statistics" />');c.find(".unavailable").slideUp();ul.append(b('<li class="{{class}}"><h4>{{ title}}<span>{{range}}</span></h4><p class="num"></p><div class="overlay"><p>{{description}}</p></div></li>',{"class":"ctr",title:"click-through rate",description:"Number of clicks on a Related Post divided by the number of times the post was shown to readers. Tip: Using thumbnails will generally rise Click-through Rates.",
3
+ range:"last 30 days"}));ul.append(b('<li class="{{class}}"><h4>{{ title}}<span>{{range}}</span></h4><p class="num"></p><div class="overlay"><p>{{description}}</p></div></li>',{"class":"pageviews",title:"page views",description:"Number of times the page (usually post) was loaded to readers.",range:"last 30 days"}));ul.append(b('<li class="{{class}}"><h4>{{ title}}<span>{{range}}</span></h4><p class="num"></p><div class="overlay"><p>{{description}}</p></div></li>',{"class":"clicks",title:"clicks",description:"Number of times a reader has clicked on one of the Related Posts.",
4
+ range:"last 30 days"}));ul.hide();c.append(ul);ul.slideDown()};update_dashboard=function(b){updating||(updating=!0,req_timeout=setTimeout(function(){display_error(!b)},2E3),a.getJSON(f+"pageviews/?callback=?",{blog_id:d,auth_key:e},function(a){clearTimeout(req_timeout);!a||"ok"!==a.status||!a.data?display_error(!b):(ul||create_dashboard(),set_update_interval(a.data.update_interval),ul.find(".ctr .num").html(a.data.ctr+"%"),ul.find(".pageviews .num").html(a.data.pageviews),ul.find(".clicks .num").html(a.data.clicks),
5
+ updating=!1)}))};d&&e&&(update_dashboard(!0),update_interval=setInterval(update_dashboard,2E3));a("#wp_rp_turn_on_statistics a").click(function(b){b.preventDefault();a("#wp_rp_ctr_dashboard_enabled, #wp_rp_include_promotionail_link, #wp_rp_display_thumbnail, #wp_rp_enable_themes, #wp_rp_scroll_up_related_posts").prop("checked",!0);a("#wp_rp_settings_form").submit()})})})(jQuery);
 
static/settings.js.php CHANGED
@@ -10,15 +10,15 @@
10
  break;
11
  case 'random':
12
  wp_rp_missing_rp_title_th.innerHTML = '<?php _e("Random Posts Title:", 'wp_related_posts'); ?>';
13
- wp_rp_missing_rp_title.value = '<?php _e("Random Posts", 'wp_related_posts'); ?>';
14
  break;
15
  case 'commented':
16
  wp_rp_missing_rp_title_th.innerHTML = '<?php _e("Most Commented Posts Title:", 'wp_related_posts'); ?>';
17
- wp_rp_missing_rp_title.value = '<?php _e("Most Commented Posts", 'wp_related_posts'); ?>';
18
  break;
19
  case 'popularity':
20
  wp_rp_missing_rp_title_th.innerHTML = '<?php _e("Most Popular Posts Title:", 'wp_related_posts'); ?>';
21
- wp_rp_missing_rp_title.value = '<?php _e("Most Popular Posts", 'wp_related_posts'); ?>';
22
  break;
23
  default:
24
  wp_rp_missing_rp_title_th.innerHTML = '';
10
  break;
11
  case 'random':
12
  wp_rp_missing_rp_title_th.innerHTML = '<?php _e("Random Posts Title:", 'wp_related_posts'); ?>';
13
+ wp_rp_missing_rp_title.value = '<?php _e("Other Posts", 'wp_related_posts'); ?>';
14
  break;
15
  case 'commented':
16
  wp_rp_missing_rp_title_th.innerHTML = '<?php _e("Most Commented Posts Title:", 'wp_related_posts'); ?>';
17
+ wp_rp_missing_rp_title.value = '<?php _e("Other Posts", 'wp_related_posts'); ?>';
18
  break;
19
  case 'popularity':
20
  wp_rp_missing_rp_title_th.innerHTML = '<?php _e("Most Popular Posts Title:", 'wp_related_posts'); ?>';
21
+ wp_rp_missing_rp_title.value = '<?php _e("Other Posts", 'wp_related_posts'); ?>';
22
  break;
23
  default:
24
  wp_rp_missing_rp_title_th.innerHTML = '';
versions.php CHANGED
@@ -1,4 +1,37 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /* ************************* */
3
  /* Version 1.5.1 */
4
  /* ************************* */
@@ -6,6 +39,7 @@
6
  /* Settings:
7
 
8
  ctr_dashboard_enabled bool : show CTR statistics in dashboard
 
9
 
10
  */
11
 
@@ -46,6 +80,7 @@
46
 
47
  - wp_rp_version -> meta.version
48
  - wp_rp_log_new_user -> meta.new_user
 
49
  */
50
 
51
  /* Meta options:
@@ -58,6 +93,8 @@
58
  show_upgrade_tooltip bool : show a tooltip for upgrades, informing the user of new features
59
  show_ctr_banner bool : show a banner for the new CTR tracking option, until the user has first enable the CTR tracking
60
 
 
 
61
  /* ************************* */
62
  /* Version 1.4 */
63
  /* ************************* */
1
  <?php
2
+ /* ************************* */
3
+ /* Version 1.6 */
4
+ /* ************************* */
5
+
6
+ /* Settings:
7
+
8
+ + scroll_up_related_posts bool : display scroll up related posts
9
+
10
+ */
11
+
12
+ /* Meta options:
13
+
14
+ + show_install_tooltip bool : show a tooltip for new users, telling them to go to settings and enable features
15
+ + remote_recommendations bool : query sre for recommendations
16
+ + show_turn_on_button bool : show "Turn on statistics & thumbnails" button in settings
17
+ + name string : the user's name ('' means not set)
18
+ + email string : the user's email ('' means not set)
19
+ + show_invite_friends_form bool : show the Invite Friends form in settings
20
+ - show_ctr_banner
21
+ - show_blogger_network
22
+
23
+ */
24
+
25
+ /* ************************* */
26
+ /* Version 1.5.2 */
27
+ /* ************************* */
28
+
29
+ /* Settings:
30
+
31
+ + enable_themes bool : themes are now disabled by default (to avoid tracking users)
32
+
33
+ */
34
+
35
  /* ************************* */
36
  /* Version 1.5.1 */
37
  /* ************************* */
39
  /* Settings:
40
 
41
  ctr_dashboard_enabled bool : show CTR statistics in dashboard
42
+ + include_promotionail_link bool : show promotional link next to related articles
43
 
44
  */
45
 
80
 
81
  - wp_rp_version -> meta.version
82
  - wp_rp_log_new_user -> meta.new_user
83
+
84
  */
85
 
86
  /* Meta options:
93
  show_upgrade_tooltip bool : show a tooltip for upgrades, informing the user of new features
94
  show_ctr_banner bool : show a banner for the new CTR tracking option, until the user has first enable the CTR tracking
95
 
96
+ */
97
+
98
  /* ************************* */
99
  /* Version 1.4 */
100
  /* ************************* */
wp_related_posts.php CHANGED
@@ -1,297 +1,336 @@
1
- <?php
2
- /*
3
- Plugin Name: WordPress Related Posts
4
- Version: 1.5.2
5
- Plugin URI: http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/
6
- Description: Generate a related posts list via tags of WordPress
7
- Author: Jure Ham
8
- Author URI: http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/
9
- */
10
-
11
- define('WP_RP_VERSION', '1.5.2');
12
-
13
- include_once(dirname(__FILE__) . '/config.php');
14
-
15
- register_activation_hook(__FILE__, 'wp_rp_activate_hook');
16
-
17
- include_once(dirname(__FILE__) . '/widget.php');
18
- include_once(dirname(__FILE__) . '/thumbnailer.php');
19
- include_once(dirname(__FILE__) . '/settings.php');
20
- include_once(dirname(__FILE__) . '/compatibility.php');
21
-
22
- add_action('init', 'wp_rp_init_hook');
23
- add_filter('the_content', 'wp_rp_add_related_posts_hook', 99);
24
-
25
- function wp_rp_init_hook() {
26
- load_plugin_textdomain('wp_related_posts', false, dirname(plugin_basename (__FILE__)) . '/lang');
27
- }
28
-
29
- function wp_rp_add_related_posts_hook($content) {
30
- $options = wp_rp_get_options();
31
-
32
- if ((is_single() && $options["on_single_post"]) || (is_feed() && $options["on_rss"])) {
33
- $output = wp_rp_get_related_posts();
34
- $content = $content . $output;
35
- }
36
-
37
- return $content;
38
- }
39
-
40
- function wp_rp_fetch_related_posts($limitclause = '') {
41
- global $wpdb, $post;
42
- $options = wp_rp_get_options();
43
-
44
- if(!$post->ID){return;}
45
- $now = current_time('mysql', 1);
46
- $tags = wp_get_post_tags($post->ID);
47
-
48
- $tagcount = count($tags);
49
- $taglist = false;
50
- if ($tagcount > 0) {
51
- $taglist = "'" . $tags[0]->term_id. "'";
52
- for ($i = 1; $i < $tagcount; $i++) {
53
- $taglist = $taglist . ", '" . $tags[$i]->term_id . "'";
54
- }
55
- }
56
-
57
- $related_posts = false;
58
- if ($taglist) {
59
- $q = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count, count(t_r.object_id) as cnt FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p WHERE t_t.taxonomy ='post_tag' AND t_t.term_taxonomy_id = t_r.term_taxonomy_id AND t_r.object_id = p.ID AND (t_t.term_id IN ($taglist)) AND p.ID != $post->ID AND p.post_status = 'publish' AND p.post_date_gmt < '$now' GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC $limitclause;";
60
-
61
- $related_posts = $wpdb->get_results($q);
62
- }
63
-
64
- return $related_posts;
65
- }
66
-
67
- function wp_rp_fetch_random_posts ($limit = 10, $exclude_ids = array()) {
68
- global $wpdb, $post;
69
-
70
- array_push($exclude_ids, $post->ID);
71
- $exclude_ids = array_map('intval', $exclude_ids);
72
-
73
- $q1 = "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND ID NOT IN(" . implode(', ', $exclude_ids) . ")";
74
- $ids = $wpdb->get_col($q1, 0);
75
- $count = count($ids);
76
- if($count <= 1) {
77
- if($count === 0) return false;
78
- if($count === 1) $rnd = $ids;
79
- } else {
80
- $display_number = min($limit, $count);
81
-
82
- $next_seed = rand();
83
- $t = time();
84
- $seed = $t - $t % 300 + $post->ID << 4; // We keep the same seed for 5 minutes, so MySQL can cache the `q2` query.
85
- srand($seed);
86
-
87
- $rnd = array_rand($ids, $display_number); // This is an array of random indexes, sorted
88
- if ($display_number == 1) {
89
- $ids = array($ids[$rnd]);
90
- } else {
91
- shuffle($rnd);
92
- foreach ($rnd as &$i) { // Here, index is passed by reference, so we can modify it
93
- $i = $ids[$i]; // Replace indexes with corresponding IDs
94
- }
95
- $ids = $rnd;
96
- }
97
- srand($next_seed);
98
- }
99
-
100
- $q2 = "SELECT ID, post_title, post_content, post_excerpt, post_date, comment_count FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND ID IN (" . implode(',', $ids) . ")";
101
- return $wpdb->get_results($q2);
102
- }
103
-
104
- function wp_rp_fetch_most_commented_posts($limitclause = '') {
105
- global $wpdb;
106
- $q = "SELECT ID, post_title, post_content, post_excerpt, post_date, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC $limitclause";
107
- return $wpdb->get_results($q);
108
- }
109
-
110
- function wp_rp_fetch_most_popular_posts ($limitclause = '') {
111
- global $wpdb, $table_prefix;
112
-
113
- $q = $sql = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count FROM ". $table_prefix ."ak_popularity as akpc,".$table_prefix ."posts as p WHERE p.ID = akpc.post_id ORDER BY akpc.total DESC $limitclause";;
114
- return $wpdb->get_results($q);
115
- }
116
-
117
- function wp_rp_fetch_posts_and_title() {
118
- $options = wp_rp_get_options();
119
-
120
- $limit = $options['max_related_posts'];
121
- $limitclause = "LIMIT $limit";
122
-
123
- $title = $options["related_posts_title"];
124
- $related_posts = wp_rp_fetch_related_posts($limitclause);
125
- $missing_rp_algorithm = $options["missing_rp_algorithm"];
126
-
127
- if (!$related_posts && $missing_rp_algorithm === "text") {
128
- $title = $options["missing_rp_title"];
129
- $related_posts = false;
130
- } else {
131
- if (!$related_posts) {
132
- $title = $options["missing_rp_title"];
133
-
134
- if ($missing_rp_algorithm === "commented") {
135
- $related_posts = wp_rp_fetch_most_commented_posts($limitclause);
136
- } else if ($missing_rp_algorithm === "popularity" && function_exists('akpc_most_popular')) {
137
- $related_posts = wp_rp_fetch_most_popular_posts($limitclause);
138
- } else {
139
- $related_posts = wp_rp_fetch_random_posts($limit);
140
- }
141
- }
142
-
143
- // fill related posts with random posts if there not enough posts found
144
- if(empty($related_posts) || sizeof($related_posts) < $limit) {
145
- $src_posts = !is_array($related_posts) ? array() : $related_posts;
146
- $exclude_ids = array_map(create_function('$p', 'return $p->ID;'), $src_posts);
147
- $random_posts = wp_rp_fetch_random_posts($limit - sizeof($src_posts), $exclude_ids);
148
-
149
- if(!empty($random_posts))
150
- $related_posts = array_merge($src_posts, $random_posts);
151
- }
152
- }
153
-
154
- return array(
155
- "posts" => $related_posts,
156
- "title" => $title
157
- );
158
- }
159
-
160
- function wp_rp_generate_related_posts_list_items($related_posts) {
161
- $options = wp_rp_get_options();
162
- $output = "";
163
- $i = 0;
164
-
165
- foreach ($related_posts as $related_post ) {
166
- $output .= '<li position="' . $i++ . '">';
167
-
168
- $img = wp_rp_get_post_thumbnail_img($related_post);
169
- if ($img) {
170
- $output .= '<a href="' . get_permalink($related_post->ID) . '">' . $img . '</a>';
171
- }
172
-
173
- if (!$options["display_thumbnail"] || ($options["display_thumbnail"] && ($options["thumbnail_display_title"] || !$img))) {
174
- if ($options["display_publish_date"]){
175
- $dateformat = get_option('date_format');
176
- $output .= mysql2date($dateformat, $related_post->post_date) . " -- ";
177
- }
178
-
179
- $output .= '<a href="' . get_permalink($related_post->ID) . '">' . wptexturize($related_post->post_title) . '</a>';
180
-
181
- if ($options["display_comment_count"]){
182
- $output .= " (" . $related_post->comment_count . ")";
183
- }
184
-
185
- if ($options["display_excerpt"]){
186
- $excerpt_max_length = $options["excerpt_max_length"];
187
- if($related_post->post_excerpt){
188
- $output .= '<br /><small>' . (mb_substr(strip_shortcodes(strip_tags($related_post->post_excerpt)), 0, $excerpt_max_length)) . '...</small>';
189
- } else {
190
- $output .= '<br /><small>' . (mb_substr(strip_shortcodes(strip_tags($related_post->post_content)), 0, $excerpt_max_length)) . '...</small>';
191
- }
192
- }
193
- }
194
- $output .= '</li>';
195
- }
196
-
197
- return $output;
198
- }
199
-
200
- function wp_rp_should_exclude() {
201
- global $wpdb, $post;
202
- $options = wp_rp_get_options();
203
-
204
- if($options['not_on_categories'] === '') { return false; }
205
-
206
- $exclude = explode(",", $options["not_on_categories"]);
207
- $q = 'SELECT tt.term_id FROM '. $wpdb->term_taxonomy.' tt, ' . $wpdb->term_relationships.' tr WHERE tt.taxonomy = \'category\' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = '.$post->ID;
208
-
209
- $cats = $wpdb->get_results($q);
210
-
211
- foreach($cats as $cat) {
212
- if (in_array($cat->term_id, $exclude) != false){
213
- return true;
214
- }
215
- }
216
- return false;
217
- }
218
-
219
- function wp_rp_get_related_posts($before_title = '', $after_title = '') {
220
- global $wpdb, $post;
221
-
222
- if (wp_rp_should_exclude())
223
- return;
224
-
225
- $options = wp_rp_get_options();
226
- $meta = wp_rp_get_meta();
227
-
228
- $output = "";
229
- $output_script = "";
230
- $promotional_link = '';
231
-
232
- $posts_and_title = wp_rp_fetch_posts_and_title();
233
- $related_posts = $posts_and_title['posts'];
234
- $title = $posts_and_title['title'];
235
-
236
-
237
- if ($related_posts) {
238
- $output = wp_rp_generate_related_posts_list_items($related_posts);
239
- $output = '<ul class="related_post wp_rp">' . $output . '</ul>';
240
-
241
- if ($options['include_promotionail_link']) {
242
- $promotional_link = ' <a target="_blank" rel="nofollow" title="WordPress Related Posts" href="http://related-posts.com/welcome2/" class="wp_rp_welcome" onclick="return window._wp_rp_show_banner && window._wp_rp_show_banner(event)">[?]</a>';
243
- $output .= '<div id="wp_rp_popup_holder"></div>';
244
- $output .= '<script async type="text/javascript" src="' . esc_attr(WP_RP_STATIC_BASE_URL . WP_RP_BANNER_FILE) . '"></script>';
245
-
246
- $output_script .= 'window._wp_rp_static_base_url = "' . WP_RP_STATIC_BASE_URL . '";';
247
- }
248
- }
249
-
250
- if ($title != '') {
251
- if ($before_title) {
252
- $output = $before_title . $title . $after_title . $output;
253
- } else {
254
- $title_tag = $options["related_posts_title_tag"];
255
- $output = '<' . $title_tag . ' class="related_post_title">' . $title . $promotional_link . '</' . $title_tag . '>' . $output;
256
- }
257
- }
258
-
259
- if ($options['enable_themes']) {
260
- $theme_name = $options['theme_name'];
261
-
262
- if ($options["display_thumbnail"]) {
263
- $theme_url = WP_RP_STATIC_BASE_URL . WP_RP_STATIC_THEMES_THUMBS_PATH . $theme_name;
264
- } else {
265
- $theme_url = WP_RP_STATIC_BASE_URL . WP_RP_STATIC_THEMES_PATH . $theme_name;
266
- }
267
-
268
- if ($theme_name === 'custom.css') {
269
- $theme_custom_css = $options['theme_custom_css'];
270
-
271
- $output .= '<style>' . $theme_custom_css . '</style>';
272
- }
273
-
274
- $output_script .= 'setTimeout(function () {
275
- var link = document.createElement("link");
276
- link.rel = "stylesheet";
277
- link.href = "' . esc_js($theme_url) . '";
278
- link.type = "text/css";
279
- document.getElementsByTagName("body")[0].appendChild(link);
280
- }, 1);';
281
- }
282
-
283
- if ($options['ctr_dashboard_enabled'] && $meta['blog_id'] && $meta['auth_key']) {
284
- $output_script .= 'window._wp_rp_blog_id = "' . esc_js($meta['blog_id']) . '";
285
- window._wp_rp_ajax_img_src_url = "' . esc_js(WP_RP_CTR_REPORT_URL) . '";
286
- window._wp_rp_post_id = ' . esc_js($post->ID) . ';
287
- window._wp_rp_thumbnails = ' . ($options["display_thumbnail"] ? 'true' : 'false') . ';';
288
-
289
- $output .= '<script type="text/javascript" src="' . esc_attr(WP_RP_STATIC_BASE_URL . WP_RP_CTR_PAGEVIEW_FILE) . '"></script>';
290
- }
291
-
292
- if ($output_script) {
293
- $output_script = '<script type="text/javascript">' . $output_script . '</script>';
294
- }
295
-
296
- return $output . $output_script;
297
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WordPress Related Posts
4
+ Version: 1.6
5
+ Plugin URI: http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/
6
+ Description: Generate a related posts list via tags of WordPress
7
+ Author: Jure Ham
8
+ Author URI: http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/
9
+ */
10
+
11
+ define('WP_RP_VERSION', '1.6');
12
+
13
+ include_once(dirname(__FILE__) . '/config.php');
14
+
15
+ register_activation_hook(__FILE__, 'wp_rp_activate_hook');
16
+
17
+ include_once(dirname(__FILE__) . '/widget.php');
18
+ include_once(dirname(__FILE__) . '/thumbnailer.php');
19
+ include_once(dirname(__FILE__) . '/settings.php');
20
+ include_once(dirname(__FILE__) . '/compatibility.php');
21
+
22
+ add_action('init', 'wp_rp_init_hook');
23
+ add_filter('the_content', 'wp_rp_add_related_posts_hook', 99);
24
+
25
+ add_action('wp_before_admin_bar_render', 'wp_rp_extend_adminbar');
26
+ function wp_rp_extend_adminbar() {
27
+ global $wp_admin_bar;
28
+
29
+ if(!is_super_admin() || !is_admin_bar_showing())
30
+ return;
31
+
32
+ $wp_admin_bar->add_menu(array(
33
+ 'id' => 'wp_rp_adminbar_menu',
34
+ 'title' => __('Related Posts Statistics', 'wp_related_posts'),
35
+ 'href' => admin_url('admin.php?page=wordpress-related-posts&ref=adminbar')
36
+ ));
37
+ }
38
+
39
+ function wp_rp_init_hook() {
40
+ load_plugin_textdomain('wp_related_posts', false, dirname(plugin_basename (__FILE__)) . '/lang');
41
+ }
42
+
43
+ function wp_rp_add_related_posts_hook($content) {
44
+ $options = wp_rp_get_options();
45
+
46
+ if ((is_single() && $options["on_single_post"]) || (is_feed() && $options["on_rss"])) {
47
+ $output = wp_rp_get_related_posts();
48
+ $content = $content . $output;
49
+ }
50
+
51
+ return $content;
52
+ }
53
+
54
+ function wp_rp_fetch_related_posts($limit = 10, $exclude_ids = array()) {
55
+ global $wpdb, $post;
56
+ $options = wp_rp_get_options();
57
+
58
+ $exclude_ids_str = wp_rp_get_exclude_ids_list_string($exclude_ids);
59
+
60
+ if(!$post->ID){return;}
61
+ $now = current_time('mysql', 1);
62
+ $tags = wp_get_post_tags($post->ID);
63
+
64
+ $tagcount = count($tags);
65
+ $taglist = false;
66
+ if ($tagcount > 0) {
67
+ $taglist = "'" . $tags[0]->term_id. "'";
68
+ for ($i = 1; $i < $tagcount; $i++) {
69
+ $taglist = $taglist . ", '" . $tags[$i]->term_id . "'";
70
+ }
71
+ }
72
+
73
+ $related_posts = false;
74
+ if ($taglist) {
75
+ $q = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count, count(t_r.object_id) as cnt FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p WHERE t_t.taxonomy ='post_tag' AND t_t.term_taxonomy_id = t_r.term_taxonomy_id AND t_r.object_id = p.ID AND (t_t.term_id IN ($taglist)) AND p.ID NOT IN ($exclude_ids_str) AND p.post_status = 'publish' AND p.post_date_gmt < '$now' GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC LIMIT $limit;";
76
+
77
+ $related_posts = $wpdb->get_results($q);
78
+ }
79
+
80
+ return $related_posts;
81
+ }
82
+
83
+ function wp_rp_get_exclude_ids_list_string($exclude_ids = array()) {
84
+ global $post;
85
+
86
+ array_push($exclude_ids, $post->ID);
87
+ $exclude_ids = array_map('intval', $exclude_ids);
88
+ $exclude_ids_str = implode(', ', $exclude_ids);
89
+
90
+ return $exclude_ids_str;
91
+ }
92
+
93
+ function wp_rp_fetch_random_posts($limit = 10, $exclude_ids = array()) {
94
+ global $wpdb, $post;
95
+
96
+ $exclude_ids_str = wp_rp_get_exclude_ids_list_string($exclude_ids);
97
+
98
+ $q1 = "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND ID NOT IN ($exclude_ids_str)";
99
+ $ids = $wpdb->get_col($q1, 0);
100
+ $count = count($ids);
101
+ if($count <= 1) {
102
+ if($count === 0) return false;
103
+ if($count === 1) $rnd = $ids;
104
+ } else {
105
+ $display_number = min($limit, $count);
106
+
107
+ $next_seed = rand();
108
+ $t = time();
109
+ $seed = $t - $t % 300 + $post->ID << 4; // We keep the same seed for 5 minutes, so MySQL can cache the `q2` query.
110
+ srand($seed);
111
+
112
+ $rnd = array_rand($ids, $display_number); // This is an array of random indexes, sorted
113
+ if ($display_number == 1) {
114
+ $ids = array($ids[$rnd]);
115
+ } else {
116
+ shuffle($rnd);
117
+ foreach ($rnd as &$i) { // Here, index is passed by reference, so we can modify it
118
+ $i = $ids[$i]; // Replace indexes with corresponding IDs
119
+ }
120
+ $ids = $rnd;
121
+ }
122
+ srand($next_seed);
123
+ }
124
+ $q2 = "SELECT ID, post_title, post_content, post_excerpt, post_date, comment_count FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND ID IN (" . implode(',', $ids) . ")";
125
+ return $wpdb->get_results($q2);
126
+ }
127
+
128
+ function wp_rp_fetch_most_commented_posts($limit = 10, $exclude_ids = array()) {
129
+ global $wpdb;
130
+
131
+ $exclude_ids_str = wp_rp_get_exclude_ids_list_string($exclude_ids);
132
+
133
+ $q = "SELECT ID, post_title, post_content, post_excerpt, post_date, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' AND ID NOT IN ($exclude_ids_str) GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $limit";
134
+ return $wpdb->get_results($q);
135
+ }
136
+
137
+ function wp_rp_fetch_most_popular_posts ($limit = 10, $exclude_ids = array()) {
138
+ global $wpdb, $table_prefix;
139
+
140
+ $exclude_ids_str = wp_rp_get_exclude_ids_list_string($exclude_ids);
141
+
142
+ $q = $sql = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count FROM ". $table_prefix ."ak_popularity as akpc,".$table_prefix ."posts as p WHERE p.ID = akpc.post_id AND p.ID NOT IN ($exclude_ids_str) ORDER BY akpc.total DESC LIMIT $limit";;
143
+ return $wpdb->get_results($q);
144
+ }
145
+
146
+ function wp_rp_fetch_posts_and_title() {
147
+ $options = wp_rp_get_options();
148
+
149
+ $limit = $options['max_related_posts'];
150
+
151
+ $title = $options["related_posts_title"];
152
+ $related_posts = wp_rp_fetch_related_posts($limit);
153
+ $missing_rp_algorithm = $options["missing_rp_algorithm"];
154
+
155
+ if (!$related_posts) {
156
+ $title = $options["missing_rp_title"];
157
+ }
158
+
159
+ if (!$related_posts && $missing_rp_algorithm === "text") {
160
+ $related_posts = false;
161
+ } else if (!$related_posts || sizeof($related_posts) < $limit) {
162
+ $related_posts = !is_array($related_posts) ? array() : $related_posts;
163
+ $exclude_ids = array_map(create_function('$p', 'return $p->ID;'), $related_posts);
164
+
165
+ $num_missing_posts = $limit - sizeof($related_posts);
166
+
167
+ $other_posts = false;
168
+ if ($missing_rp_algorithm === "commented") {
169
+ $other_posts = wp_rp_fetch_most_commented_posts($num_missing_posts, $exclude_ids);
170
+ } else if ($missing_rp_algorithm === "popularity" && function_exists('akpc_most_popular')) {
171
+ $other_posts = wp_rp_fetch_most_popular_posts($num_missing_posts, $exclude_ids);
172
+ } else if ($missing_rp_algorithm === "random") {
173
+ $other_posts = wp_rp_fetch_random_posts($num_missing_posts, $exclude_ids);
174
+ }
175
+
176
+ if ($other_posts) {
177
+ $related_posts = array_merge($related_posts, $other_posts);
178
+ }
179
+ }
180
+
181
+ return array(
182
+ "posts" => $related_posts,
183
+ "title" => $title
184
+ );
185
+ }
186
+
187
+ function wp_rp_generate_related_posts_list_items($related_posts) {
188
+ $options = wp_rp_get_options();
189
+ $output = "";
190
+ $i = 0;
191
+
192
+ foreach ($related_posts as $related_post ) {
193
+ $output .= '<li position="' . $i++ . '">';
194
+
195
+ $img = wp_rp_get_post_thumbnail_img($related_post);
196
+ if ($img) {
197
+ $output .= '<a href="' . get_permalink($related_post->ID) . '">' . $img . '</a>';
198
+ }
199
+
200
+ if (!$options["display_thumbnail"] || ($options["display_thumbnail"] && ($options["thumbnail_display_title"] || !$img))) {
201
+ if ($options["display_publish_date"]){
202
+ $dateformat = get_option('date_format');
203
+ $output .= mysql2date($dateformat, $related_post->post_date) . " -- ";
204
+ }
205
+
206
+ $output .= '<a href="' . get_permalink($related_post->ID) . '">' . wptexturize($related_post->post_title) . '</a>';
207
+
208
+ if ($options["display_comment_count"]){
209
+ $output .= " (" . $related_post->comment_count . ")";
210
+ }
211
+
212
+ if ($options["display_excerpt"]){
213
+ $excerpt_max_length = $options["excerpt_max_length"];
214
+ if($related_post->post_excerpt){
215
+ $output .= '<br /><small>' . (mb_substr(strip_shortcodes(strip_tags($related_post->post_excerpt)), 0, $excerpt_max_length)) . '...</small>';
216
+ } else {
217
+ $output .= '<br /><small>' . (mb_substr(strip_shortcodes(strip_tags($related_post->post_content)), 0, $excerpt_max_length)) . '...</small>';
218
+ }
219
+ }
220
+ }
221
+ $output .= '</li>';
222
+ }
223
+
224
+ return $output;
225
+ }
226
+
227
+ function wp_rp_should_exclude() {
228
+ global $wpdb, $post;
229
+ $options = wp_rp_get_options();
230
+
231
+ if($options['not_on_categories'] === '') { return false; }
232
+
233
+ $exclude = explode(",", $options["not_on_categories"]);
234
+ $q = 'SELECT tt.term_id FROM '. $wpdb->term_taxonomy.' tt, ' . $wpdb->term_relationships.' tr WHERE tt.taxonomy = \'category\' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = '.$post->ID;
235
+
236
+ $cats = $wpdb->get_results($q);
237
+
238
+ foreach($cats as $cat) {
239
+ if (in_array($cat->term_id, $exclude) != false){
240
+ return true;
241
+ }
242
+ }
243
+ return false;
244
+ }
245
+
246
+ function wp_rp_get_related_posts($before_title = '', $after_title = '') {
247
+ global $wpdb, $post;
248
+
249
+ if (wp_rp_should_exclude()) {
250
+ return;
251
+ }
252
+
253
+ $options = wp_rp_get_options();
254
+ $meta = wp_rp_get_meta();
255
+
256
+ $output = "";
257
+ $output_script = "";
258
+
259
+ $promotional_link = '';
260
+
261
+ $posts_and_title = wp_rp_fetch_posts_and_title();
262
+ $related_posts = $posts_and_title['posts'];
263
+ $title = $posts_and_title['title'];
264
+
265
+ $statistics_enabled = $options['ctr_dashboard_enabled'] && $meta['blog_id'] && $meta['auth_key'];
266
+ $remote_recommendations = $meta['remote_recommendations'] && $statistics_enabled;
267
+
268
+
269
+ $output_script .= "window._wp_rp_static_base_url = \"" . WP_RP_STATIC_BASE_URL . "\";\n";
270
+
271
+ if ($related_posts) {
272
+ $output = wp_rp_generate_related_posts_list_items($related_posts);
273
+ $output = "<ul class=\"related_post wp_rp\" style=\"visibility:" . ($remote_recommendations ? 'hidden' : 'visible') . ";\">" . $output . "</ul>\n";
274
+
275
+ if ($options['include_promotionail_link']) {
276
+ $promotional_link = ' <a target="_blank" rel="nofollow" title="WordPress Related Posts" href="http://related-posts.com/welcome2/" class="wp_rp_welcome" onclick="return window._wp_rp_show_banner && window._wp_rp_show_banner(event)">[?]</a>';
277
+ $output .= "<div id=\"wp_rp_popup_holder\"></div>\n";
278
+
279
+ wp_enqueue_script('wp_rp_welcome', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_BANNER_FILE);
280
+ }
281
+ }
282
+
283
+ if ($title != '') {
284
+ if ($before_title) {
285
+ $output = $before_title . $title . $after_title . $output;
286
+ } else {
287
+ $title_tag = $options["related_posts_title_tag"];
288
+ $output = '<' . $title_tag . ' class="related_post_title">' . $title . $promotional_link . '</' . $title_tag . '>' . $output;
289
+ }
290
+ }
291
+
292
+ if ($options['enable_themes']) {
293
+ $theme_name = $options['theme_name'];
294
+
295
+ if ($options["display_thumbnail"]) {
296
+ wp_enqueue_style('wp_rp_theme', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_THEMES_THUMBS_PATH . $theme_name);
297
+ } else {
298
+ wp_enqueue_style('wp_rp_theme', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_THEMES_PATH . $theme_name);
299
+ }
300
+
301
+ if ($theme_name === 'custom.css') {
302
+ $theme_custom_css = $options['theme_custom_css'];
303
+
304
+ $output .= '<style>' . $theme_custom_css . '</style>';
305
+ }
306
+ }
307
+
308
+ if ($statistics_enabled) {
309
+ $post_tags = '[' . implode(', ', array_map(create_function('$v', 'return "\'" . urlencode($v) . "\'";'), wp_get_post_tags($post->ID, array('fields' => 'names')))) . ']';
310
+
311
+ $output_script .= 'window._wp_rp_blog_id = \'' . esc_js($meta['blog_id']) . '\';
312
+ window._wp_rp_ajax_img_src_url = "' . esc_js(WP_RP_CTR_REPORT_URL) . '";
313
+ window._wp_rp_post_id = \'' . esc_js($post->ID) . '\';
314
+ window._wp_rp_thumbnails = ' . ($options["display_thumbnail"] ? 'true' : 'false') . ';
315
+ window._wp_rp_post_title = \'' . urlencode($post->post_title) . '\';
316
+ window._wp_rp_post_tags = ' . $post_tags . ';';
317
+
318
+ wp_enqueue_script('wp_rp_pageview', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_CTR_PAGEVIEW_FILE);
319
+ }
320
+
321
+ if ($remote_recommendations) {
322
+ wp_enqueue_script('wp_rp_recommendations', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_RECOMMENDATIONS_JS_FILE);
323
+ wp_enqueue_style('wp_rp_recommendations', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_RECOMMENDATIONS_CSS_FILE);
324
+ }
325
+
326
+ if ($options['scroll_up_related_posts']) {
327
+ wp_enqueue_script('wp_rp_scrollup', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_SCROLLUP_JS_FILE, array('jquery'));
328
+ wp_enqueue_style('wp_rp_scrollup', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_SCROLLUP_CSS_FILE);
329
+ }
330
+
331
+ if ($output_script) {
332
+ $output_script = "<script type=\"text/javascript\">\n" . $output_script . "\n</script>";
333
+ }
334
+
335
+ return "\n" . $output_script . "\n" . $output . "\n";
336
+ }