WordPress Related Posts - Version 3.5.4

Version Description

  • Fixed bug that prevented image download from posts
  • Pinterest theme fixes
  • Fixed missing featured image
  • Fixed missing thumbnail for selected related articles
  • Article upload support
Download this release

Release Info

Developer ddksr
Plugin Icon wp plugin WordPress Related Posts
Version 3.5.4
Comparing to
See all releases

Code changes from version 3.5 to 3.5.4

config.php CHANGED
@@ -5,6 +5,9 @@ define("WP_RP_ZEMANTA_SUBSCRIPTION_URL", "http://prefs.zemanta.com/api/");
5
  define('WP_RP_STATIC_THEMES_PATH', 'static/themes/');
6
  define('WP_RP_STATIC_JSON_PATH', 'json/');
7
  define('WP_RP_CONTENT_BASE_URL', 'https://wprp.zemanta.com/static/');
 
 
 
8
 
9
  define("WP_RP_DEFAULT_CUSTOM_CSS",
10
  ".related_post_title {
@@ -176,8 +179,8 @@ function wp_rp_related_posts_db_table_install() {
176
  post_date datetime NOT NULL,
177
  label VARCHAR(" . WP_RP_MAX_LABEL_LENGTH . ") NOT NULL,
178
  weight float,
179
- INDEX post_id (post_id),
180
- INDEX label (label)
181
  );";
182
 
183
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
@@ -252,6 +255,34 @@ function wp_rp_is_classic() {
252
  return false;
253
  }
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  function wp_rp_migrate_3_4_3() {
256
  $meta = get_option('wp_rp_meta');
257
  $meta['version'] = '3.5';
5
  define('WP_RP_STATIC_THEMES_PATH', 'static/themes/');
6
  define('WP_RP_STATIC_JSON_PATH', 'json/');
7
  define('WP_RP_CONTENT_BASE_URL', 'https://wprp.zemanta.com/static/');
8
+ define("WP_RP_ZEMANTA_UPLOAD_URL", "http://prefs.zemanta.com/api/upload-articles/");
9
+ define("WP_RP_ZEMANTA_ARTICLE_COUNT_URL", "http://prefs.zemanta.com/api/article-count/");
10
+
11
 
12
  define("WP_RP_DEFAULT_CUSTOM_CSS",
13
  ".related_post_title {
179
  post_date datetime NOT NULL,
180
  label VARCHAR(" . WP_RP_MAX_LABEL_LENGTH . ") NOT NULL,
181
  weight float,
182
+ KEY post_id (post_id),
183
+ KEY label (label)
184
  );";
185
 
186
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
255
  return false;
256
  }
257
 
258
+ function wp_rp_migrate_3_5_3() {
259
+ $meta = get_option('wp_rp_meta');
260
+ $meta['version'] = '3.5.4';
261
+ $meta['new_user'] = false;
262
+ update_option('wp_rp_meta', $meta);
263
+ }
264
+
265
+ function wp_rp_migrate_3_5_2() {
266
+ $meta = get_option('wp_rp_meta');
267
+ $meta['version'] = '3.5.3';
268
+ $meta['new_user'] = false;
269
+ update_option('wp_rp_meta', $meta);
270
+ }
271
+
272
+ function wp_rp_migrate_3_5_1() {
273
+ $meta = get_option('wp_rp_meta');
274
+ $meta['version'] = '3.5.2';
275
+ $meta['new_user'] = false;
276
+ update_option('wp_rp_meta', $meta);
277
+ }
278
+
279
+ function wp_rp_migrate_3_5() {
280
+ $meta = get_option('wp_rp_meta');
281
+ $meta['version'] = '3.5.1';
282
+ $meta['new_user'] = false;
283
+ update_option('wp_rp_meta', $meta);
284
+ }
285
+
286
  function wp_rp_migrate_3_4_3() {
287
  $meta = get_option('wp_rp_meta');
288
  $meta['version'] = '3.5';
init.php CHANGED
@@ -1,5 +1,5 @@
1
  <?php
2
- define('WP_RP_VERSION', '3.5');
3
 
4
  define('WP_RP_PLUGIN_FILE', plugin_basename(__FILE__));
5
 
@@ -75,7 +75,11 @@ global $wp_rp_output;
75
  $wp_rp_output = array();
76
  function wp_rp_add_related_posts_hook($content) {
77
  global $wp_rp_output, $post;
78
-
 
 
 
 
79
  $options = wp_rp_get_options();
80
 
81
  if ($content != "" && $post->post_type === 'post' && (($options["on_single_post"] && is_single()) || (is_feed() && $options["on_rss"]))) {
@@ -118,6 +122,8 @@ function wp_rp_get_platform_options() {
118
  function wp_rp_ajax_load_articles_callback() {
119
  global $post;
120
 
 
 
121
  $getdata = stripslashes_deep($_GET);
122
  if (!isset($getdata['post_id'])) {
123
  die('error');
@@ -161,11 +167,23 @@ function wp_rp_ajax_load_articles_callback() {
161
  $response_list = array();
162
 
163
  foreach (array_slice($related_posts, $from) as $related_post) {
 
 
 
 
 
 
 
 
 
 
 
 
164
  array_push($response_list, array(
165
  'id' => $related_post->ID,
166
  'url' => get_permalink($related_post->ID),
167
  'title' => $related_post->post_title,
168
- 'excerpt' => $related_post->post_excerpt,
169
  'date' => $related_post->post_date,
170
  'comments' => $related_post->comment_count,
171
  'img' => wp_rp_get_post_thumbnail_img($related_post, $image_size)
1
  <?php
2
+ define('WP_RP_VERSION', '3.5.4');
3
 
4
  define('WP_RP_PLUGIN_FILE', plugin_basename(__FILE__));
5
 
75
  $wp_rp_output = array();
76
  function wp_rp_add_related_posts_hook($content) {
77
  global $wp_rp_output, $post;
78
+
79
+ if( !is_object($post) ) {
80
+ return $content;
81
+ }
82
+
83
  $options = wp_rp_get_options();
84
 
85
  if ($content != "" && $post->post_type === 'post' && (($options["on_single_post"] && is_single()) || (is_feed() && $options["on_rss"]))) {
122
  function wp_rp_ajax_load_articles_callback() {
123
  global $post;
124
 
125
+ $platform_options = wp_rp_get_platform_options();
126
+
127
  $getdata = stripslashes_deep($_GET);
128
  if (!isset($getdata['post_id'])) {
129
  die('error');
167
  $response_list = array();
168
 
169
  foreach (array_slice($related_posts, $from) as $related_post) {
170
+ $excerpt_max_length = $platform_options["excerpt_max_length"];
171
+
172
+ $excerpt = $related_post->post_excerpt;
173
+ if (!$excerpt) {
174
+ $excerpt = strip_shortcodes(strip_tags($related_post->post_content));
175
+ }
176
+ if ($excerpt) {
177
+ if (strlen($excerpt) > $excerpt_max_length) {
178
+ $excerpt = wp_rp_text_shorten($excerpt, $excerpt_max_length);
179
+ }
180
+ }
181
+
182
  array_push($response_list, array(
183
  'id' => $related_post->ID,
184
  'url' => get_permalink($related_post->ID),
185
  'title' => $related_post->post_title,
186
+ 'excerpt' => $excerpt,
187
  'date' => $related_post->post_date,
188
  'comments' => $related_post->comment_count,
189
  'img' => wp_rp_get_post_thumbnail_img($related_post, $image_size)
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: zemanta
3
  Tags: related,posts,post,related posts,plugin,seo
4
  License: GPLv2
5
- Requires at least: 3.3
6
- Tested up to: 3.9.1
7
- Stable tag: 3.5
8
 
9
  WordPress Related Posts - the plugin for related posts with thumbnails. Caching included.
10
 
@@ -54,6 +54,10 @@ Yes, Zemanta is offered in different themes which you can also customize with si
54
 
55
  No, Zemanta does not use redirects and is juice friendly. :)
56
 
 
 
 
 
57
  == Installation ==
58
 
59
  = Via admin: =
@@ -76,6 +80,9 @@ No, Zemanta does not use redirects and is juice friendly. :)
76
  1. WordPress Related Posts Default Theme.
77
  2. WordPress Related Posts responsive theme on a Galaxy Nexus and iPhone 4s.
78
 
 
 
 
79
  == Upgrade Notice ==
80
 
81
  = 2.7 =
@@ -86,6 +93,25 @@ Fix for security vulnerability. Upgrade immediately.
86
 
87
  == Changelog ==
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  = 3.5 =
90
  * Removed statistics
91
 
2
  Contributors: zemanta
3
  Tags: related,posts,post,related posts,plugin,seo
4
  License: GPLv2
5
+ Requires at least: 3.6
6
+ Tested up to: 4.3
7
+ Stable tag: 3.5.4
8
 
9
  WordPress Related Posts - the plugin for related posts with thumbnails. Caching included.
10
 
54
 
55
  No, Zemanta does not use redirects and is juice friendly. :)
56
 
57
+ = What about Terms of Service and Privacy Policy? =
58
+
59
+ Before using the plugin please read the full version of [Zemanta Terms of Service](http://www.zemanta.com/legal/terms-of-service/) and [Zemanta Privacy Policy](http://www.zemanta.com/legal/privacy/).
60
+
61
  == Installation ==
62
 
63
  = Via admin: =
80
  1. WordPress Related Posts Default Theme.
81
  2. WordPress Related Posts responsive theme on a Galaxy Nexus and iPhone 4s.
82
 
83
+ == Terms of service ==
84
+ The plugin source code is released under GPLv2. Usage of our service is governed by [Zemanta Terms of Service](http://www.zemanta.com/legal/terms-of-service/) and [Zemanta Privacy Policy](http://www.zemanta.com/legal/privacy/).
85
+
86
  == Upgrade Notice ==
87
 
88
  = 2.7 =
93
 
94
  == Changelog ==
95
 
96
+ = 3.5.4 =
97
+ * Fixed bug that prevented image download from posts
98
+ * Pinterest theme fixes
99
+ * Fixed missing featured image
100
+ * Fixed missing thumbnail for selected related articles
101
+ * Article upload support
102
+
103
+ = 3.5.3 =
104
+ * Fixed non-object bug
105
+ * Fixed the index database error after activation
106
+ * Related posts query optimization
107
+
108
+ = 3.5.2 =
109
+ * Fixed excerpt bug
110
+
111
+ = 3.5.1 =
112
+ * The subscription API forwards blog URLs
113
+ * Responsive themes bugfix
114
+
115
  = 3.5 =
116
  * Removed statistics
117
 
recommendations.php CHANGED
@@ -184,7 +184,7 @@ function wp_rp_fetch_related_posts_v2($limit = 10, $exclude_ids = array()) {
184
  $exclude_categories_labels = array();
185
  }
186
 
187
- $total_number_of_posts = $wpdb->get_col("SELECT count(distinct(post_id)) FROM " . $wpdb->prefix . "wp_rp_tags;", 0);
188
  if (empty($total_number_of_posts)) {
189
  return array();
190
  }
184
  $exclude_categories_labels = array();
185
  }
186
 
187
+ $total_number_of_posts = $wpdb->get_col("SELECT count(post_id) from (SELECT post_id FROM " . $wpdb->prefix . "wp_rp_tags group by post_id) t;", 0);
188
  if (empty($total_number_of_posts)) {
189
  return array();
190
  }
settings.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  /**
4
  * Place menu icons at admin head
5
  **/
@@ -42,6 +44,7 @@ function wp_rp_subscription($email_or_unsubscribe, $subscription_types) {
42
  $post = array(
43
  'api_key' => $meta['zemanta_api_key'],
44
  'platform' => 'wordpress-wprp',
 
45
  'subscriptions' => $subscription_types
46
  );
47
 
@@ -210,10 +213,18 @@ function wp_rp_settings_page() {
210
  }
211
 
212
  wp_rp_register();
213
-
214
  $options = wp_rp_get_options();
215
  $meta = wp_rp_get_meta();
216
-
 
 
 
 
 
 
 
 
217
  // Update already subscribed but in the old pipeline
218
  if (!empty($meta["email"]) && empty($meta["subscribed"])) {
219
  wp_rp_subscription($meta["email"], $options["subscription_types"]);
@@ -353,6 +364,8 @@ function wp_rp_settings_page() {
353
  'order' => 'ASC',
354
  'hide_empty' => false
355
  ));
 
 
356
 
357
  include wp_rp_get_template('settings');
358
  }
1
  <?php
2
 
3
+ include_once(dirname(__FILE__) . '/uploader.php');
4
+
5
  /**
6
  * Place menu icons at admin head
7
  **/
44
  $post = array(
45
  'api_key' => $meta['zemanta_api_key'],
46
  'platform' => 'wordpress-wprp',
47
+ 'url' => get_site_url(),
48
  'subscriptions' => $subscription_types
49
  );
50
 
213
  }
214
 
215
  wp_rp_register();
216
+
217
  $options = wp_rp_get_options();
218
  $meta = wp_rp_get_meta();
219
+
220
+
221
+ $articles_count = wp_rp_article_count($meta['zemanta_api_key']);
222
+ $articles_uploaded = false;
223
+ if (isset( $_GET['wp_rp_upload_articles'] ) && !empty($meta['zemanta_api_key'])) {
224
+ $articles_uploaded = wp_rp_upload_articles($meta['zemanta_api_key']);
225
+ }
226
+
227
+
228
  // Update already subscribed but in the old pipeline
229
  if (!empty($meta["email"]) && empty($meta["subscribed"])) {
230
  wp_rp_subscription($meta["email"], $options["subscription_types"]);
364
  'order' => 'ASC',
365
  'hide_empty' => false
366
  ));
367
+
368
+ $blog_url = get_site_url();
369
 
370
  include wp_rp_get_template('settings');
371
  }
static/css/dashboard.css CHANGED
@@ -155,4 +155,4 @@ form.wp_rp_message_form a.dismiss {float: right;}
155
  #wpwrap #wpcontent .wp_rp-updated .wp_rp-dismiss a:before {content: '\f153'; display: inline-block; font: 400 16px/1 dashicons; speak: none; height: 20px; margin: 2px 0; text-align: center; vertical-align: middle; width: 20px; -webkit-font-smoothing: antialiased!important;}
156
  #wpwrap h2.title span {font-size:0.5em;}
157
 
158
- #wpwrap .subscription-container { width: 800px; border: 1px solid #ccc; margin-bottom: 20px; padding: 5px 5px 5px 5px; background-color: #eee;}
155
  #wpwrap #wpcontent .wp_rp-updated .wp_rp-dismiss a:before {content: '\f153'; display: inline-block; font: 400 16px/1 dashicons; speak: none; height: 20px; margin: 2px 0; text-align: center; vertical-align: middle; width: 20px; -webkit-font-smoothing: antialiased!important;}
156
  #wpwrap h2.title span {font-size:0.5em;}
157
 
158
+ #wpwrap .subscription-container { width: 700px; padding: 5px 5px 5px 5px; background-color: #eee; margin-bottom: 20px;}
static/img/arrow_down.png CHANGED
Binary file
static/img/arrow_right.png CHANGED
Binary file
static/img/cross.png CHANGED
Binary file
static/img/desktop_icon.png CHANGED
Binary file
static/img/down.png CHANGED
Binary file
static/img/mobile_icon.png CHANGED
Binary file
static/img/network_icon.png CHANGED
Binary file
static/img/outlink.png CHANGED
Binary file
static/img/themes/modern.jpg CHANGED
Binary file
static/img/themes/vertical-m.jpg CHANGED
Binary file
static/img/themes/vertical-s.jpg CHANGED
Binary file
static/img/themes/vertical.jpg CHANGED
Binary file
static/img/turnonscreen.jpg CHANGED
Binary file
static/img/up.png CHANGED
Binary file
static/themes/momma.css CHANGED
@@ -117,8 +117,6 @@ ul.related_post li small {
117
  @media screen and (max-width: 480px) {
118
  ul.related_post li {
119
  display: inline-block !important;
120
- width: auto !important;
121
- min-height: auto !important;
122
  clear: both !important;
123
  border:none !important;
124
  }
117
  @media screen and (max-width: 480px) {
118
  ul.related_post li {
119
  display: inline-block !important;
 
 
120
  clear: both !important;
121
  border:none !important;
122
  }
static/themes/twocolumns.css CHANGED
@@ -66,13 +66,13 @@ div.wp_rp_footer a.wp_rp_edit {
66
  }
67
  @media screen and (max-width: 480px) {
68
  ul.related_post {
69
- -moz-column-count: 2 !important;
70
  -moz-column-gap: normal !important;
71
  -moz-column-rule: none !important;
72
- -webkit-column-count: 2 !important;
73
  -webkit-column-gap: normal !important;
74
  -webkit-column-rule: none !important;
75
- column-count: 2 !important;
76
  column-gap: normal !important;
77
  column-rule: none !important;
78
  }
66
  }
67
  @media screen and (max-width: 480px) {
68
  ul.related_post {
69
+ -moz-column-count: auto !important;
70
  -moz-column-gap: normal !important;
71
  -moz-column-rule: none !important;
72
+ -webkit-column-count:auto !important;
73
  -webkit-column-gap: normal !important;
74
  -webkit-column-rule: none !important;
75
+ column-count: auto !important;
76
  column-gap: normal !important;
77
  column-rule: none !important;
78
  }
static/themes/vertical-m.css CHANGED
@@ -77,7 +77,7 @@ ul.related_post li small {
77
  @media screen and (max-width: 480px) {
78
  ul.related_post li {
79
  display: inline-block !important;
80
- width: auto !important;
81
  clear: both !important;
82
  }
83
  ul.related_post li a:nth-child(1) {
77
  @media screen and (max-width: 480px) {
78
  ul.related_post li {
79
  display: inline-block !important;
80
+ width: 100px !important;
81
  clear: both !important;
82
  }
83
  ul.related_post li a:nth-child(1) {
static/themes/vertical-s.css CHANGED
@@ -77,7 +77,7 @@ ul.related_post li small {
77
  @media screen and (max-width: 480px) {
78
  ul.related_post li {
79
  display: inline-block !important;
80
- width: auto !important;
81
  clear: both !important;
82
  }
83
  ul.related_post li a:nth-child(1) {
77
  @media screen and (max-width: 480px) {
78
  ul.related_post li {
79
  display: inline-block !important;
80
+ width: 75px !important;
81
  clear: both !important;
82
  }
83
  ul.related_post li a:nth-child(1) {
static/themes/vertical.css CHANGED
@@ -77,7 +77,7 @@ ul.related_post li small {
77
  @media screen and (max-width: 480px) {
78
  ul.related_post li {
79
  display: inline-block !important;
80
- width: auto !important;
81
  clear: both !important;
82
  }
83
  ul.related_post li a:nth-child(1) {
77
  @media screen and (max-width: 480px) {
78
  ul.related_post li {
79
  display: inline-block !important;
80
+ width: 150px !important;
81
  clear: both !important;
82
  }
83
  ul.related_post li a:nth-child(1) {
thumbnailer.php CHANGED
@@ -120,6 +120,7 @@ function wp_rp_actually_extract_images_from_post_html($post) {
120
  foreach ($html_tags as $html_tag) {
121
  if (preg_match('#src=([\'"])(.+?)\1#is', $html_tag, $matches) && !empty($matches)) {
122
  $url = $matches[2];
 
123
 
124
  $attachment_id = wp_rp_get_image_from_img_tag($post->ID, $url, $html_tag);
125
  if ($attachment_id) {
@@ -148,6 +149,7 @@ function wp_rp_cron_do_extract_images_from_post($post_id, $attachment_id) {
148
  // Prevent multiple thumbnail extractions for a single post
149
  if (get_post_meta($post_id, '_wp_rp_image', true) !== '') { return; }
150
 
 
151
  $post_id = (int) $post_id;
152
  $attachment_id = (int) $attachment_id;
153
  $post = get_post($post_id);
@@ -171,8 +173,10 @@ function wp_rp_extract_images_from_post($post, $attachment_id=null) {
171
  //if(empty($post->post_content) && !$attachment_id) { return; }
172
  if(empty($post->post_content)) { return; }
173
 
174
- delete_post_meta($post->ID, '_wp_rp_image');
175
- wp_schedule_single_event(time(), 'wp_rp_cron_extract_images_from_post', array($post->ID, $attachment_id));
 
 
176
  }
177
 
178
 
@@ -217,6 +221,7 @@ function wp_rp_get_img_tag($src, $alt, $size=null) {
217
  function wp_rp_get_default_thumbnail_url($seed = false, $size = 'thumbnail') {
218
  $options = wp_rp_get_options();
219
  $upload_dir = wp_upload_dir();
 
220
 
221
  if ($options['default_thumbnail_path']) {
222
  return $options['default_thumbnail_path'];
@@ -240,6 +245,7 @@ function wp_rp_get_image_with_exact_size($image_data, $size) {
240
  $img_url = wp_get_attachment_url($image_data['id']);
241
  $img_url_basename = wp_basename($img_url);
242
  $platform_options = wp_rp_get_platform_options();
 
243
 
244
  // Calculate exact dimensions for proportional images
245
  if (!$size[0]) { $size[0] = (int) ($image_data['data']['width'] / $image_data['data']['height'] * $size[1]); }
@@ -265,7 +271,15 @@ function wp_rp_get_image_with_exact_size($image_data, $size) {
265
 
266
  foreach ($image_data['data']['sizes'] as $_size => $data) {
267
  // width and height can be both string and integers. WordPress..
268
- if (($size[0] == $data['width']) && ($size[1] == $data['height'])) {
 
 
 
 
 
 
 
 
269
  $file = $data['file'];
270
  $img_url = str_replace($img_url_basename, wp_basename($file), $img_url);
271
  return array(
@@ -294,21 +308,23 @@ function wp_rp_get_image_data($image_id) {
294
  }
295
 
296
  function wp_rp_get_attached_img_url($related_post, $size) {
297
- $extracted_image = get_post_meta($related_post->ID, '_wp_rp_image', true);
 
298
  if ($extracted_image === 'empty') { return false; }
299
 
300
  $image_data = wp_rp_get_image_data((int)$extracted_image);
301
  if (!$image_data && $extracted_image) {
302
  // image_id in the db is incorrect
303
- delete_post_meta($related_post->ID, '_wp_rp_image');
304
  }
305
- if (!$image_data && has_post_thumbnail($related_post->ID)) {
306
- $image_data = wp_rp_get_image_data(get_post_thumbnail_id($related_post->ID));
307
  }
308
 
 
309
  if (!$image_data && function_exists('get_post_format_meta') && function_exists('img_html_to_post_id')) {
310
  // WP 3.6 Image post format. Check wp-includes/media.php:get_the_post_format_image for the reference.
311
- $meta = get_post_format_meta($related_post->ID);
312
  if (!empty($meta['image'])) {
313
  if (is_numeric($meta['image'])) {
314
  $image_id = absint($meta['image']);
@@ -356,21 +372,29 @@ function wp_rp_get_post_thumbnail_img($related_post, $size = null, $force = fals
356
  return false;
357
  }
358
 
 
359
  $post_title = wptexturize($related_post->post_title);
360
- if (property_exists($related_post, 'thumbnail')) {
361
- return wp_rp_get_img_tag($related_post->thumbnail, $post_title, $size);
362
- }
363
 
364
  $size = wp_rp_get_thumbnail_size_array($size);
365
  if (!$size) { return false; }
366
 
367
  if ($options['thumbnail_use_custom']) {
368
- $thumbnail_src = get_post_meta($related_post->ID, $options["thumbnail_custom_field"], true);
369
 
370
  if ($thumbnail_src) {
371
  return wp_rp_get_img_tag($thumbnail_src, $post_title, $size);
372
  }
373
  }
 
 
 
 
 
 
 
 
 
 
374
 
375
  $attached_img_url = wp_rp_get_attached_img_url($related_post, $size);
376
  if ($attached_img_url) {
120
  foreach ($html_tags as $html_tag) {
121
  if (preg_match('#src=([\'"])(.+?)\1#is', $html_tag, $matches) && !empty($matches)) {
122
  $url = $matches[2];
123
+ if (substr($url, 0, 2) == '//') { $url = "http:$url"; }
124
 
125
  $attachment_id = wp_rp_get_image_from_img_tag($post->ID, $url, $html_tag);
126
  if ($attachment_id) {
149
  // Prevent multiple thumbnail extractions for a single post
150
  if (get_post_meta($post_id, '_wp_rp_image', true) !== '') { return; }
151
 
152
+ $post_id = str_replace("in_", "", "$post_id");
153
  $post_id = (int) $post_id;
154
  $attachment_id = (int) $attachment_id;
155
  $post = get_post($post_id);
173
  //if(empty($post->post_content) && !$attachment_id) { return; }
174
  if(empty($post->post_content)) { return; }
175
 
176
+ $post_id = str_replace("in_", "", "$post->ID");
177
+ delete_post_meta($post_id, '_wp_rp_image');
178
+ wp_schedule_single_event(time(), 'wp_rp_cron_extract_images_from_post', array($post_id, $attachment_id));
179
+
180
  }
181
 
182
 
221
  function wp_rp_get_default_thumbnail_url($seed = false, $size = 'thumbnail') {
222
  $options = wp_rp_get_options();
223
  $upload_dir = wp_upload_dir();
224
+ $seed = (int)$seed;
225
 
226
  if ($options['default_thumbnail_path']) {
227
  return $options['default_thumbnail_path'];
245
  $img_url = wp_get_attachment_url($image_data['id']);
246
  $img_url_basename = wp_basename($img_url);
247
  $platform_options = wp_rp_get_platform_options();
248
+ $pinterest = $size[1] === 0;
249
 
250
  // Calculate exact dimensions for proportional images
251
  if (!$size[0]) { $size[0] = (int) ($image_data['data']['width'] / $image_data['data']['height'] * $size[1]); }
271
 
272
  foreach ($image_data['data']['sizes'] as $_size => $data) {
273
  // width and height can be both string and integers. WordPress..
274
+ $width_ok = ($size[0] == $data['width']);
275
+ // Pinterest fix (don't match exact sizes, we could be wrong
276
+ if ($pinterest) {
277
+ $height_ok = ($size[1] < $data['height'] + 5) && ($size[1] > $data['height'] - 5);
278
+ } else {
279
+ $height_ok = ($size[1] == $data['height']);
280
+ }
281
+
282
+ if ($width_ok && $height_ok) {
283
  $file = $data['file'];
284
  $img_url = str_replace($img_url_basename, wp_basename($file), $img_url);
285
  return array(
308
  }
309
 
310
  function wp_rp_get_attached_img_url($related_post, $size) {
311
+ $post_id = str_replace("in_", "", "$related_post->ID");
312
+ $extracted_image = get_post_meta($post_id, '_wp_rp_image', true);
313
  if ($extracted_image === 'empty') { return false; }
314
 
315
  $image_data = wp_rp_get_image_data((int)$extracted_image);
316
  if (!$image_data && $extracted_image) {
317
  // image_id in the db is incorrect
318
+ delete_post_meta($post_id, '_wp_rp_image');
319
  }
320
+ if (!$image_data && has_post_thumbnail($post_id)) {
321
+ $image_data = wp_rp_get_image_data(get_post_thumbnail_id($post_id));
322
  }
323
 
324
+
325
  if (!$image_data && function_exists('get_post_format_meta') && function_exists('img_html_to_post_id')) {
326
  // WP 3.6 Image post format. Check wp-includes/media.php:get_the_post_format_image for the reference.
327
+ $meta = get_post_format_meta($post_id);
328
  if (!empty($meta['image'])) {
329
  if (is_numeric($meta['image'])) {
330
  $image_id = absint($meta['image']);
372
  return false;
373
  }
374
 
375
+ $post_id = str_replace("in_", "", "$related_post->ID");
376
  $post_title = wptexturize($related_post->post_title);
 
 
 
377
 
378
  $size = wp_rp_get_thumbnail_size_array($size);
379
  if (!$size) { return false; }
380
 
381
  if ($options['thumbnail_use_custom']) {
382
+ $thumbnail_src = get_post_meta($post_id, $options["thumbnail_custom_field"], true);
383
 
384
  if ($thumbnail_src) {
385
  return wp_rp_get_img_tag($thumbnail_src, $post_title, $size);
386
  }
387
  }
388
+ $featured_image = get_post_thumbnail_id($post_id);
389
+ if ($featured_image) {
390
+ $featured_image_data = wp_rp_get_image_data($featured_image);
391
+ $featured_image_thumb = wp_rp_get_image_with_exact_size($featured_image_data, $size);
392
+ if ($featured_image_thumb) {
393
+ return wp_rp_get_img_tag($featured_image_thumb["url"], $post_title, $size);
394
+ } else {
395
+ return get_the_post_thumbnail($post_id, $size);
396
+ }
397
+ }
398
 
399
  $attached_img_url = wp_rp_get_attached_img_url($related_post, $size);
400
  if ($attached_img_url) {
uploader.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function wp_rp_get_all_attachments() {
4
+ global $wpdb;
5
+ $images = $wpdb->get_results("select p1.*, m.meta_value as meta
6
+ FROM {$wpdb->posts} p1, {$wpdb->posts} p2, {$wpdb->postmeta} m
7
+ WHERE m.post_id = p1.ID
8
+ AND p1.post_parent = p2.ID
9
+ AND p1.post_mime_type LIKE 'image%'
10
+ AND p2.post_type = 'post'
11
+ AND m.meta_key = '_wp_attachment_metadata'
12
+ ORDER BY p2.post_date;"
13
+ );
14
+ return $images;
15
+ }
16
+
17
+ function wp_rp_article_count($api_key) {
18
+ $http_response = wp_remote_get(WP_RP_ZEMANTA_ARTICLE_COUNT_URL . $api_key . '/');
19
+ if (!is_wp_error($http_response) && wp_remote_retrieve_response_code($http_response) == 200) {
20
+ $response = json_decode(wp_remote_retrieve_body($http_response));
21
+ if ($response->status == 'ok') {
22
+ return $response->articles;
23
+ }
24
+ }
25
+ return __('Sorry, could not connect to server', 'wp_related_posts');
26
+ }
27
+
28
+ function wp_rp_upload_articles($api_key) {
29
+ $media = array();
30
+ foreach(wp_rp_get_all_attachments() as $image) {
31
+ if (empty($media[$image->post_parent])) {
32
+ $media[$image->post_parent] = array();
33
+ }
34
+ $meta = unserialize($image->meta);
35
+ $media["$image->post_parent"][] = array(
36
+ "URL" => $image->guid,
37
+ "width" => $meta['width'],
38
+ "height" => $meta['height']
39
+ );
40
+ }
41
+
42
+ $payload = array(
43
+ "found" => 0,
44
+ "posts" => array(),
45
+ );
46
+ foreach(get_posts() as $post) {
47
+ $obj = array(
48
+ "ID" => $post->ID,
49
+ "URL" => get_permalink($post->ID),
50
+ "attachment_count" => 0,
51
+ "attachments" => array(),
52
+ "content" => $post->post_content,
53
+ "date" => $post->post_date,
54
+ "excerpt" => $post->post_excerpt,
55
+ "featured_image" => "",
56
+ "modified" => $post->post_modified,
57
+ "post_thumbnail" => null,
58
+ "slug" => $post->post_name,
59
+ "status" => $post->post_status,
60
+ "title" => $post->post_title,
61
+ "type" => $post->post_type,
62
+ );
63
+ if (has_post_thumbnail( $post->ID ) ) {
64
+ $thumb_id = get_post_thumbnail_id( $post->ID );
65
+ $meta = wp_get_attachment_metadata($thumb_id);
66
+ $obj["post_thumbnail"] = array(
67
+ "URL" => wp_get_attachment_url ($thumb_id),
68
+ "width" => $meta["width"],
69
+ "height" => $meta["height"]
70
+ );
71
+ }
72
+ if (!empty($media[$post->ID])) {
73
+ $obj["attachments"] = $media[$post->ID];
74
+ }
75
+
76
+ $obj["attachment_count"] = sizeof($obj["attachments"]);
77
+
78
+ $payload["posts"][] = $obj;
79
+ }
80
+ $payload["found"] = sizeof($payload["posts"]);
81
+ $payload["posts"] = $payload["posts"];
82
+
83
+ $http_response = wp_remote_post(WP_RP_ZEMANTA_UPLOAD_URL, array(
84
+ "body" => array(
85
+ "payload" => json_encode($payload),
86
+ "blog_name" => get_bloginfo('name'),
87
+ "api_key" => $api_key,
88
+ "feed_url" => get_bloginfo('rss2_url'),
89
+ "blog_url" => get_bloginfo('url'),
90
+ "platform" => 'wordpress-wprp',
91
+ )
92
+ ));
93
+ if (!is_wp_error($http_response) && wp_remote_retrieve_response_code($http_response) == 200) {
94
+ $response = json_decode(wp_remote_retrieve_body($http_response));
95
+ return $response->status === 'ok';
96
+ }
97
+ return false;
98
+ }
views/settings.php CHANGED
@@ -36,13 +36,32 @@
36
  <tr valign="top">
37
  <th scope="row"></th>
38
  <td>
39
- <?php _e("We know when Zemanta users link to each other and we know when they link to you! Subscribe and <strong>we'll let you know</strong> when this happens.", 'wp_related_posts'); ?>
40
  </td>
41
  </tr>
42
  </table>
43
  </div>
44
  <?php endif; ?>
45
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  <!-- MAIN FORM -->
47
  <form method="post" enctype="multipart/form-data" action="<?php echo $form_url; ?>" id="wp_rp_settings_form" style="display: <?php echo $form_display; ?>;">
48
  <?php wp_nonce_field('wp_rp_settings', '_wp_rp_nonce') ?>
36
  <tr valign="top">
37
  <th scope="row"></th>
38
  <td>
39
+ <?php _e("Subscribe and we'll start monitoring our network for your <a href=\"$blog_url\" target=\"_blank\">blog</a>. <br />We'll <strong>let you know</strong> when somebody links to you.", 'wp_related_posts'); ?>
40
  </td>
41
  </tr>
42
  </table>
43
  </div>
44
  <?php endif; ?>
45
+ <div class="container article-upload-container">
46
+ <h2>Amazing new feature - Upload your history of posts</h2>
47
+ <p>
48
+ You can now upload your content! This means you will be reaching out to even more people that write about similar topics – not only new but also old posts will now be suggested in related articles section, to you and to other bloggers.
49
+ </p>
50
+ <p>
51
+ Note: If you have a very large database, it can take some time to upload your articles, so please be patient. =)
52
+ </p>
53
+ <?php if (! $articles_uploaded): ?>
54
+ <form method="get" action="">
55
+ <fieldset>
56
+ <input type="hidden" name="page" value="wordpress-related-posts" />
57
+ <input class="button-primary" type="submit" name="wp_rp_upload_articles" value="<?php _e("Upload my articles to Zemanta", 'wp_related_posts');?>">
58
+ </fieldset>
59
+ </form>
60
+ <?php else: ?>
61
+ <p>Your articles are being uploaded.</p>
62
+ <?php endif; ?>
63
+ <h3>Number of articles in Zemanta network: <?php echo $articles_count; ?></h3>
64
+ </div>
65
  <!-- MAIN FORM -->
66
  <form method="post" enctype="multipart/form-data" action="<?php echo $form_url; ?>" id="wp_rp_settings_form" style="display: <?php echo $form_display; ?>;">
67
  <?php wp_nonce_field('wp_rp_settings', '_wp_rp_nonce') ?>
wp_related_posts.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: WordPress Related Posts
4
- Version: 3.5
5
  Plugin URI: http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/
6
  Description: Quickly increase your readers' engagement with your posts by adding Related Posts in the footer of your content. Click on <a href="admin.php?page=wordpress-related-posts">Related Posts tab</a> to configure your settings.
7
  Author: Zemanta Ltd.
1
  <?php
2
  /*
3
  Plugin Name: WordPress Related Posts
4
+ Version: 3.5.4
5
  Plugin URI: http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/
6
  Description: Quickly increase your readers' engagement with your posts by adding Related Posts in the footer of your content. Click on <a href="admin.php?page=wordpress-related-posts">Related Posts tab</a> to configure your settings.
7
  Author: Zemanta Ltd.