WordPress Related Posts - Version 2.5

Version Description

This version adds a wrapper around related posts and a link to zemanta.com (can be turned off in plugin settings). Please recheck the layout after upgrade.

=

Download this release

Release Info

Developer jureham
Plugin Icon wp plugin WordPress Related Posts
Version 2.5
Comparing to
See all releases

Code changes from version 2.4 to 2.5

config.php CHANGED
@@ -1,8 +1,7 @@
1
  <?php
2
 
3
  define('WP_RP_STATIC_BASE_URL', 'http://dtmvdvtzf8rz0.cloudfront.net/static/');
4
- define('WP_RP_STATIC_THEMES_PATH', 'css-text/');
5
- define('WP_RP_STATIC_THEMES_THUMBS_PATH', 'css-img/');
6
  define('WP_RP_STATIC_JSON_PATH', 'json/');
7
 
8
  define("WP_RP_DEFAULT_CUSTOM_CSS",
@@ -26,8 +25,10 @@ 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
 
32
  define("WP_RP_RECOMMENDATIONS_AUTO_TAGS_MAX_WORDS", 200);
33
  define("WP_RP_RECOMMENDATIONS_AUTO_TAGS_MAX_TAGS", 15);
@@ -171,6 +172,7 @@ function wp_rp_install() {
171
  'version' => WP_RP_VERSION,
172
  'first_version' => WP_RP_VERSION,
173
  'new_user' => true,
 
174
  'show_upgrade_tooltip' => false,
175
  'show_install_tooltip' => true,
176
  'remote_recommendations' => false,
@@ -181,34 +183,45 @@ function wp_rp_install() {
181
  'remote_notifications' => array(),
182
  'turn_on_button_pressed' => false,
183
  'show_statistics' => false,
184
- 'show_traffic_exchange' => false
 
185
  );
186
 
187
  $wp_rp_options = array(
188
  'related_posts_title' => __('Related Posts', 'wp_related_posts'),
189
- 'related_posts_title_tag' => 'h3',
190
- 'display_excerpt' => false,
191
- 'excerpt_max_length' => 200,
192
  'max_related_posts' => 5,
193
  'exclude_categories' => '',
194
  'on_single_post' => true,
195
  'on_rss' => false,
196
- 'display_comment_count' => false,
197
- 'display_publish_date' => false,
198
- 'display_thumbnail' => false,
199
- 'thumbnail_display_title' => true,
200
- 'thumbnail_custom_field' => false,
201
- 'thumbnail_use_attached' => true,
202
- 'thumbnail_use_custom' => false,
203
  'default_thumbnail_path' => false,
204
- 'theme_name' => 'vertical-m.css',
205
- 'theme_custom_css' => WP_RP_DEFAULT_CUSTOM_CSS,
206
  'ctr_dashboard_enabled' => false,
207
  'promoted_content_enabled' => false,
208
  'enable_themes' => false,
209
- 'custom_theme_enabled' => false,
210
  'traffic_exchange_enabled' => false,
211
- 'max_related_post_age_in_days' => 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  );
213
 
214
  update_option('wp_rp_meta', $wp_rp_meta);
@@ -217,6 +230,60 @@ function wp_rp_install() {
217
  wp_rp_related_posts_db_table_install();
218
  }
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  function wp_rp_migrate_2_3() {
221
  $wp_rp_meta = get_option('wp_rp_meta');
222
  $wp_rp_options = get_option('wp_rp_options');
1
  <?php
2
 
3
  define('WP_RP_STATIC_BASE_URL', 'http://dtmvdvtzf8rz0.cloudfront.net/static/');
4
+ define('WP_RP_STATIC_THEMES_PATH', 'wp-rp-css/');
 
5
  define('WP_RP_STATIC_JSON_PATH', 'json/');
6
 
7
  define("WP_RP_DEFAULT_CUSTOM_CSS",
25
  define("WP_RP_STATIC_CTR_PAGEVIEW_FILE", "js/pageview.js");
26
 
27
  define("WP_RP_STATIC_RECOMMENDATIONS_JS_FILE", "js/recommendations.js");
28
+ define("WP_RP_STATIC_RECOMMENDATIONS_CSS_FILE", "wp-rp-css/recommendations.css");
29
 
30
+ define("WP_RP_STATIC_INFINITE_RECS_JS_FILE", "js/infiniterecs.js");
31
+ define("WP_RP_STATIC_PINTEREST_JS_FILE", "js/pinterest.js");
32
 
33
  define("WP_RP_RECOMMENDATIONS_AUTO_TAGS_MAX_WORDS", 200);
34
  define("WP_RP_RECOMMENDATIONS_AUTO_TAGS_MAX_TAGS", 15);
172
  'version' => WP_RP_VERSION,
173
  'first_version' => WP_RP_VERSION,
174
  'new_user' => true,
175
+ 'blog_tg' => rand(0, 1),
176
  'show_upgrade_tooltip' => false,
177
  'show_install_tooltip' => true,
178
  'remote_recommendations' => false,
183
  'remote_notifications' => array(),
184
  'turn_on_button_pressed' => false,
185
  'show_statistics' => false,
186
+ 'show_traffic_exchange' => false,
187
+ 'show_zemanta_linky_option' => false
188
  );
189
 
190
  $wp_rp_options = array(
191
  'related_posts_title' => __('Related Posts', 'wp_related_posts'),
 
 
 
192
  'max_related_posts' => 5,
193
  'exclude_categories' => '',
194
  'on_single_post' => true,
195
  'on_rss' => false,
196
+ 'max_related_post_age_in_days' => 0,
 
 
 
 
 
 
197
  'default_thumbnail_path' => false,
 
 
198
  'ctr_dashboard_enabled' => false,
199
  'promoted_content_enabled' => false,
200
  'enable_themes' => false,
 
201
  'traffic_exchange_enabled' => false,
202
+ 'thumbnail_use_custom' => false,
203
+ 'thumbnail_custom_field' => false,
204
+ 'display_zemanta_linky' => true,
205
+
206
+ 'mobile' => array(
207
+ 'display_comment_count' => false,
208
+ 'display_publish_date' => false,
209
+ 'display_excerpt' => false,
210
+ 'display_thumbnail' => false,
211
+ 'excerpt_max_length' => 200,
212
+ 'theme_name' => 'm-modern.css',
213
+ 'theme_custom_css' => WP_RP_DEFAULT_CUSTOM_CSS,
214
+ ),
215
+ 'desktop' => array(
216
+ 'display_comment_count' => false,
217
+ 'display_publish_date' => false,
218
+ 'display_thumbnail' => false,
219
+ 'display_excerpt' => false,
220
+ 'excerpt_max_length' => 200,
221
+ 'theme_name' => 'momma.css',
222
+ 'theme_custom_css' => WP_RP_DEFAULT_CUSTOM_CSS,
223
+ 'custom_theme_enabled' => false,
224
+ )
225
  );
226
 
227
  update_option('wp_rp_meta', $wp_rp_meta);
230
  wp_rp_related_posts_db_table_install();
231
  }
232
 
233
+ function wp_rp_migrate_2_4_1() {
234
+ $wp_rp_meta = get_option('wp_rp_meta');
235
+ $wp_rp_options = get_option('wp_rp_options');
236
+
237
+ $wp_rp_meta['version'] = '2.5';
238
+
239
+ $wp_rp_meta['blog_tg'] = rand(0, 1);
240
+
241
+ $display_options = array(
242
+ 'display_comment_count' => $wp_rp_options['display_comment_count'],
243
+ 'display_publish_date' => $wp_rp_options['display_publish_date'],
244
+ 'display_thumbnail' => $wp_rp_options['display_thumbnail'],
245
+ 'display_excerpt' => $wp_rp_options['display_excerpt'],
246
+ 'excerpt_max_length' => $wp_rp_options['excerpt_max_length'],
247
+ 'theme_name' => $wp_rp_options['theme_name'],
248
+ 'theme_custom_css' => $wp_rp_options['theme_custom_css'],
249
+ 'custom_theme_enabled' => $wp_rp_options['custom_theme_enabled']
250
+ );
251
+
252
+ $wp_rp_options['desktop'] = $display_options;
253
+ $wp_rp_options['mobile'] = $display_options;
254
+
255
+ if($wp_rp_options['mobile']['theme_name'] !== 'plain.css') {
256
+ $wp_rp_options['mobile']['theme_name'] = 'm-modern.css';
257
+ }
258
+
259
+ unset($wp_rp_options['related_posts_title_tag']);
260
+ unset($wp_rp_options['thumbnail_display_title']);
261
+ unset($wp_rp_options['thumbnail_use_attached']);
262
+ unset($wp_rp_options['display_comment_count']);
263
+ unset($wp_rp_options['display_publish_date']);
264
+ unset($wp_rp_options['display_thumbnail']);
265
+ unset($wp_rp_options['display_excerpt']);
266
+ unset($wp_rp_options['excerpt_max_length']);
267
+ unset($wp_rp_options['theme_name']);
268
+ unset($wp_rp_options['theme_custom_css']);
269
+ unset($wp_rp_options['custom_theme_enabled']);
270
+
271
+ $wp_rp_options['display_zemanta_linky'] = true;
272
+ $wp_rp_meta['show_zemanta_linky_option'] = true;
273
+
274
+ update_option('wp_rp_meta', $wp_rp_meta);
275
+ update_option('wp_rp_options', $wp_rp_options);
276
+ }
277
+
278
+ function wp_rp_migrate_2_4() {
279
+ $wp_rp_meta = get_option('wp_rp_meta');
280
+ $wp_rp_options = get_option('wp_rp_options');
281
+
282
+ $wp_rp_meta['version'] = '2.4.1';
283
+
284
+ update_option('wp_rp_meta', $wp_rp_meta);
285
+ update_option('wp_rp_options', $wp_rp_options);
286
+ }
287
  function wp_rp_migrate_2_3() {
288
  $wp_rp_meta = get_option('wp_rp_meta');
289
  $wp_rp_options = get_option('wp_rp_options');
edit_related_posts.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function wp_rp_update_related_posts_callback() {
4
+ if (!current_user_can('edit_posts')) {
5
+ die('error');
6
+ }
7
+
8
+ $options = wp_rp_get_options();
9
+
10
+ if (!isset($_POST['related_posts']) || !isset($_POST['post_id'])) {
11
+ die('error');
12
+ }
13
+
14
+ global $wpdb;
15
+
16
+ $post_id = intval(stripslashes($_POST['post_id']));
17
+
18
+ $articles_json = stripslashes($_POST['related_posts']);
19
+ if ($articles_json) {
20
+ $articles = json_decode($articles_json);
21
+ } else {
22
+ $articles = '';
23
+ }
24
+
25
+ update_post_meta($post_id, '_wp_rp_selected_related_posts', $articles);
26
+ die('ok');
27
+ }
28
+ add_action('wp_ajax_rp_update_related_posts', 'wp_rp_update_related_posts_callback');
lib/mobile_detect.php ADDED
@@ -0,0 +1,767 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MIT License
4
+ * ===========
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * "Software"), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included
15
+ * in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ *
26
+ * @author Serban Ghita <serbanghita@gmail.com>
27
+ * Victor Stanciu <vic.stanciu@gmail.com> (until v.1.0)
28
+ * @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt
29
+ * @link Official page: http://mobiledetect.net
30
+ * GitHub Repository: https://github.com/serbanghita/Mobile-Detect
31
+ * Google Code Old Page: http://code.google.com/p/php-mobile-detect/
32
+ */
33
+
34
+ class WpRpMobileDetect {
35
+
36
+ protected $scriptVersion = '2.5.4';
37
+
38
+ // External info.
39
+ protected $userAgent = null;
40
+ protected $httpHeaders;
41
+
42
+ // Arrays holding all detection rules.
43
+ protected $mobileDetectionRules = null;
44
+ protected $mobileDetectionRulesExtended = null;
45
+ // Type of detection to use.
46
+ protected $detectionType = 'mobile'; // mobile, extended @todo: refactor this.
47
+
48
+ // List of mobile devices (phones)
49
+ protected $phoneDevices = array(
50
+ 'iPhone' => '(iPhone.*Mobile|iPod|iTunes)',
51
+ 'BlackBerry' => 'BlackBerry|rim[0-9]+',
52
+ 'HTC' => 'HTC|HTC.*(Sensation|Evo|Vision|Explorer|6800|8100|8900|A7272|S510e|C110e|Legend|Desire|T8282)|APX515CKT|Qtek9090|APA9292KT|HD_mini|Sensation.*Z710e|PG86100|Z715e|Desire.*(A8181|HD)|ADR6200|ADR6425|001HT|Inspire 4G',
53
+ 'Nexus' => 'Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile',
54
+ // @todo: Is 'Dell Streak' a tablet or a phone? ;)
55
+ 'Dell' => 'Dell.*Streak|Dell.*Aero|Dell.*Venue|DELL.*Venue Pro|Dell Flash|Dell Smoke|Dell Mini 3iX|XCD28|XCD35|\b001DL\b|\b101DL\b|\bGS01\b',
56
+ 'Motorola' => 'Motorola|\bDroid\b.*Build|DROIDX|Android.*Xoom|HRI39|MOT-|A1260|A1680|A555|A853|A855|A953|A955|A956|Motorola.*ELECTRIFY|Motorola.*i1|i867|i940|MB200|MB300|MB501|MB502|MB508|MB511|MB520|MB525|MB526|MB611|MB612|MB632|MB810|MB855|MB860|MB861|MB865|MB870|ME501|ME502|ME511|ME525|ME600|ME632|ME722|ME811|ME860|ME863|ME865|MT620|MT710|MT716|MT720|MT810|MT870|MT917|Motorola.*TITANIUM|WX435|WX445|XT300|XT301|XT311|XT316|XT317|XT319|XT320|XT390|XT502|XT530|XT531|XT532|XT535|XT603|XT610|XT611|XT615|XT681|XT701|XT702|XT711|XT720|XT800|XT806|XT860|XT862|XT875|XT882|XT883|XT894|XT909|XT910|XT912|XT928',
57
+ 'Samsung' => 'Samsung|BGT-S5230|GT-B2100|GT-B2700|GT-B2710|GT-B3210|GT-B3310|GT-B3410|GT-B3730|GT-B3740|GT-B5510|GT-B5512|GT-B5722|GT-B6520|GT-B7300|GT-B7320|GT-B7330|GT-B7350|GT-B7510|GT-B7722|GT-B7800|GT-C3010|GT-C3011|GT-C3060|GT-C3200|GT-C3212|GT-C3212I|GT-C3222|GT-C3300|GT-C3300K|GT-C3303|GT-C3303K|GT-C3310|GT-C3322|GT-C3330|GT-C3350|GT-C3500|GT-C3510|GT-C3530|GT-C3630|GT-C3780|GT-C5010|GT-C5212|GT-C6620|GT-C6625|GT-C6712|GT-E1050|GT-E1070|GT-E1075|GT-E1080|GT-E1081|GT-E1085|GT-E1087|GT-E1100|GT-E1107|GT-E1110|GT-E1120|GT-E1125|GT-E1130|GT-E1160|GT-E1170|GT-E1175|GT-E1180|GT-E1182|GT-E1200|GT-E1210|GT-E1225|GT-E1230|GT-E1390|GT-E2100|GT-E2120|GT-E2121|GT-E2152|GT-E2220|GT-E2222|GT-E2230|GT-E2232|GT-E2250|GT-E2370|GT-E2550|GT-E2652|GT-E3210|GT-E3213|GT-I5500|GT-I5503|GT-I5700|GT-I5800|GT-I5801|GT-I6410|GT-I6420|GT-I7110|GT-I7410|GT-I7500|GT-I8000|GT-I8150|GT-I8160|GT-I8320|GT-I8330|GT-I8350|GT-I8530|GT-I8700|GT-I8703|GT-I8910|GT-I9000|GT-I9001|GT-I9003|GT-I9010|GT-I9020|GT-I9023|GT-I9070|GT-I9100|GT-I9103|GT-I9220|GT-I9250|GT-I9300|GT-I9300 |GT-M3510|GT-M5650|GT-M7500|GT-M7600|GT-M7603|GT-M8800|GT-M8910|GT-N7000|GT-P6810|GT-P7100|GT-S3110|GT-S3310|GT-S3350|GT-S3353|GT-S3370|GT-S3650|GT-S3653|GT-S3770|GT-S3850|GT-S5210|GT-S5220|GT-S5229|GT-S5230|GT-S5233|GT-S5250|GT-S5253|GT-S5260|GT-S5263|GT-S5270|GT-S5300|GT-S5330|GT-S5350|GT-S5360|GT-S5363|GT-S5369|GT-S5380|GT-S5380D|GT-S5560|GT-S5570|GT-S5600|GT-S5603|GT-S5610|GT-S5620|GT-S5660|GT-S5670|GT-S5690|GT-S5750|GT-S5780|GT-S5830|GT-S5839|GT-S6102|GT-S6500|GT-S7070|GT-S7200|GT-S7220|GT-S7230|GT-S7233|GT-S7250|GT-S7500|GT-S7530|GT-S7550|GT-S8000|GT-S8003|GT-S8500|GT-S8530|GT-S8600|SCH-A310|SCH-A530|SCH-A570|SCH-A610|SCH-A630|SCH-A650|SCH-A790|SCH-A795|SCH-A850|SCH-A870|SCH-A890|SCH-A930|SCH-A950|SCH-A970|SCH-A990|SCH-I100|SCH-I110|SCH-I400|SCH-I405|SCH-I500|SCH-I510|SCH-I515|SCH-I600|SCH-I730|SCH-I760|SCH-I770|SCH-I830|SCH-I910|SCH-I920|SCH-LC11|SCH-N150|SCH-N300|SCH-R100|SCH-R300|SCH-R351|SCH-R400|SCH-R410|SCH-T300|SCH-U310|SCH-U320|SCH-U350|SCH-U360|SCH-U365|SCH-U370|SCH-U380|SCH-U410|SCH-U430|SCH-U450|SCH-U460|SCH-U470|SCH-U490|SCH-U540|SCH-U550|SCH-U620|SCH-U640|SCH-U650|SCH-U660|SCH-U700|SCH-U740|SCH-U750|SCH-U810|SCH-U820|SCH-U900|SCH-U940|SCH-U960|SCS-26UC|SGH-A107|SGH-A117|SGH-A127|SGH-A137|SGH-A157|SGH-A167|SGH-A177|SGH-A187|SGH-A197|SGH-A227|SGH-A237|SGH-A257|SGH-A437|SGH-A517|SGH-A597|SGH-A637|SGH-A657|SGH-A667|SGH-A687|SGH-A697|SGH-A707|SGH-A717|SGH-A727|SGH-A737|SGH-A747|SGH-A767|SGH-A777|SGH-A797|SGH-A817|SGH-A827|SGH-A837|SGH-A847|SGH-A867|SGH-A877|SGH-A887|SGH-A897|SGH-A927|SGH-B100|SGH-B130|SGH-B200|SGH-B220|SGH-C100|SGH-C110|SGH-C120|SGH-C130|SGH-C140|SGH-C160|SGH-C170|SGH-C180|SGH-C200|SGH-C207|SGH-C210|SGH-C225|SGH-C230|SGH-C417|SGH-C450|SGH-D307|SGH-D347|SGH-D357|SGH-D407|SGH-D415|SGH-D780|SGH-D807|SGH-D980|SGH-E105|SGH-E200|SGH-E315|SGH-E316|SGH-E317|SGH-E335|SGH-E590|SGH-E635|SGH-E715|SGH-E890|SGH-F300|SGH-F480|SGH-I200|SGH-I300|SGH-I320|SGH-I550|SGH-I577|SGH-I600|SGH-I607|SGH-I617|SGH-I627|SGH-I637|SGH-I677|SGH-I700|SGH-I717|SGH-I727|SGH-I777|SGH-I780|SGH-I827|SGH-I847|SGH-I857|SGH-I896|SGH-I897|SGH-I900|SGH-I907|SGH-I917|SGH-I927|SGH-I937|SGH-I997|SGH-J150|SGH-J200|SGH-L170|SGH-L700|SGH-M110|SGH-M150|SGH-M200|SGH-N105|SGH-N500|SGH-N600|SGH-N620|SGH-N625|SGH-N700|SGH-N710|SGH-P107|SGH-P207|SGH-P300|SGH-P310|SGH-P520|SGH-P735|SGH-P777|SGH-Q105|SGH-R210|SGH-R220|SGH-R225|SGH-S105|SGH-S307|SGH-T109|SGH-T119|SGH-T139|SGH-T209|SGH-T219|SGH-T229|SGH-T239|SGH-T249|SGH-T259|SGH-T309|SGH-T319|SGH-T329|SGH-T339|SGH-T349|SGH-T359|SGH-T369|SGH-T379|SGH-T409|SGH-T429|SGH-T439|SGH-T459|SGH-T469|SGH-T479|SGH-T499|SGH-T509|SGH-T519|SGH-T539|SGH-T559|SGH-T589|SGH-T609|SGH-T619|SGH-T629|SGH-T639|SGH-T659|SGH-T669|SGH-T679|SGH-T709|SGH-T719|SGH-T729|SGH-T739|SGH-T746|SGH-T749|SGH-T759|SGH-T769|SGH-T809|SGH-T819|SGH-T839|SGH-T919|SGH-T929|SGH-T939|SGH-T959|SGH-T989|SGH-U100|SGH-U200|SGH-U800|SGH-V205|SGH-V206|SGH-X100|SGH-X105|SGH-X120|SGH-X140|SGH-X426|SGH-X427|SGH-X475|SGH-X495|SGH-X497|SGH-X507|SGH-X600|SGH-X610|SGH-X620|SGH-X630|SGH-X700|SGH-X820|SGH-X890|SGH-Z130|SGH-Z150|SGH-Z170|SGH-ZX10|SGH-ZX20|SHW-M110|SPH-A120|SPH-A400|SPH-A420|SPH-A460|SPH-A500|SPH-A560|SPH-A600|SPH-A620|SPH-A660|SPH-A700|SPH-A740|SPH-A760|SPH-A790|SPH-A800|SPH-A820|SPH-A840|SPH-A880|SPH-A900|SPH-A940|SPH-A960|SPH-D600|SPH-D700|SPH-D710|SPH-D720|SPH-I300|SPH-I325|SPH-I330|SPH-I350|SPH-I500|SPH-I600|SPH-I700|SPH-L700|SPH-M100|SPH-M220|SPH-M240|SPH-M300|SPH-M305|SPH-M320|SPH-M330|SPH-M350|SPH-M360|SPH-M370|SPH-M380|SPH-M510|SPH-M540|SPH-M550|SPH-M560|SPH-M570|SPH-M580|SPH-M610|SPH-M620|SPH-M630|SPH-M800|SPH-M810|SPH-M850|SPH-M900|SPH-M910|SPH-M920|SPH-M930|SPH-N100|SPH-N200|SPH-N240|SPH-N300|SPH-N400|SPH-Z400|SWC-E100|SCH-i909|GT-N7100|GT-N8010',
58
+ 'Sony' => 'sony|SonyEricsson|SonyEricssonLT15iv|LT18i|E10i',
59
+ 'Asus' => 'Asus.*Galaxy',
60
+ 'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ; @todo - complete the regex.
61
+ 'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;)
62
+ // @ref: http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH)
63
+ // Most of the VEGA devices are legacy. PANTECH seem to be newer devices based on Android.
64
+ 'Pantech' => 'PANTECH|IM-A850S|IM-A840S|IM-A830L|IM-A830K|IM-A830S|IM-A820L|IM-A810K|IM-A810S|IM-A800S|IM-T100K|IM-A725L|IM-A780L|IM-A775C|IM-A770K|IM-A760S|IM-A750K|IM-A740S|IM-A730S|IM-A720L|IM-A710K|IM-A690L|IM-A690S|IM-A650S|IM-A630K|IM-A600S|VEGA PTL21|PT003|P8010|ADR910L|P6030|P6020|P9070|P4100|P9060|P5000|CDM8992|TXT8045|ADR8995|IS11PT|P2030|P6010|P8000|PT002|IS06|CDM8999|P9050|PT001|TXT8040|P2020|P9020|P2000|P7040|P7000|C790',
65
+ // @ref: http://www.fly-phone.com/devices/smartphones/ ; Included only smartphones.
66
+ 'Fly' => 'IQ230|IQ444|IQ450|IQ440|IQ442|IQ441|IQ245|IQ256|IQ236|IQ255|IQ235|IQ245|IQ275|IQ240|IQ285|IQ280|IQ270|IQ260|IQ250',
67
+ 'GenericPhone' => 'PDA;|PPC;|SAGEM|mmp|pocket|psp|symbian|Smartphone|smartfon|treo|up.browser|up.link|vodafone|wap|nokia|Series40|Series60|S60|SonyEricsson|N900|MAUI.*WAP.*Browser|LG-P500'
68
+ );
69
+ // List of tablet devices.
70
+ protected $tabletDevices = array(
71
+ 'BlackBerryTablet' => 'PlayBook|RIM Tablet',
72
+ 'iPad' => 'iPad|iPad.*Mobile', // @todo: check for mobile friendly emails topic.
73
+ 'NexusTablet' => '^.*Android.*Nexus(((?:(?!Mobile))|(?:(\s(7|10).+))).)*$',
74
+ // @reference: http://www.labnol.org/software/kindle-user-agent-string/20378/
75
+ 'Kindle' => 'Kindle|Silk.*Accelerated',
76
+ 'SamsungTablet' => 'SAMSUNG.*Tablet|Galaxy.*Tab|GT-P1000|GT-P1010|GT-P6210|GT-P6800|GT-P6810|GT-P7100|GT-P7300|GT-P7310|GT-P7500|GT-P7510|SCH-I800|SCH-I815|SCH-I905|SGH-I957|SGH-I987|SGH-T849|SGH-T859|SGH-T869|SPH-P100|GT-P3100|GT-P3110|GT-P5100|GT-P5110|GT-P6200|GT-P7320|GT-P7511|GT-N8000|GT-P8510|SGH-I497|SPH-P500|SGH-T779|SCH-I705|SCH-I915|GT-N8013|GT-P3113|GT-P5113|GT-P8110|GT-N8010|GT-N8005|GT-N8020|GT-P1013|GT-P6201|GT-P6810|GT-P7501',
77
+ 'HTCtablet' => 'HTC Flyer|HTC Jetstream|HTC-P715a|HTC EVO View 4G|PG41200',
78
+ 'MotorolaTablet' => 'xoom|sholest|MZ615|MZ605|MZ505|MZ601|MZ602|MZ603|MZ604|MZ606|MZ607|MZ608|MZ609|MZ615|MZ616|MZ617',
79
+ 'AsusTablet' => 'Transformer|TF101',
80
+ 'NookTablet' => 'Android.*Nook|NookColor|nook browser|BNTV250A|LogicPD Zoom2',
81
+ // @ref: http://www.acer.ro/ac/ro/RO/content/drivers
82
+ // @ref: http://www.packardbell.co.uk/pb/en/GB/content/download (Packard Bell is part of Acer)
83
+ 'AcerTablet' => 'Android.*\b(A100|A101|A200|A500|A501|A510|A700|A701|W500|W500P|W501|W501P|G100|G100W)\b',
84
+ // @ref: http://eu.computers.toshiba-europe.com/innovation/family/Tablets/1098744/banner_id/tablet_footerlink/
85
+ // @ref: http://us.toshiba.com/tablets/tablet-finder
86
+ // @ref: http://www.toshiba.co.jp/regza/tablet/
87
+ 'ToshibaTablet' => 'Android.*(AT100|AT105|AT200|AT205|AT270|AT275|AT300|AT305|AT1S5|AT500|AT570|AT700|AT830)',
88
+ 'YarvikTablet' => 'Android.*(TAB210|TAB211|TAB224|TAB250|TAB260|TAB264|TAB310|TAB360|TAB364|TAB410|TAB411|TAB420|TAB424|TAB450|TAB460|TAB461|TAB464|TAB465|TAB467|TAB468)',
89
+ 'MedionTablet' => 'Android.*\bOYO\b|LIFE.*(P9212|P9514|P9516|S9512)|LIFETAB',
90
+ 'ArnovaTablet' => 'AN10G2|AN7bG3|AN7fG3|AN8G3|AN8cG3|AN7G3|AN9G3|AN7dG3|AN7dG3ST|AN7dG3ChildPad|AN10bG3|AN10bG3DT',
91
+ // @reference: http://wiki.archosfans.com/index.php?title=Main_Page
92
+ 'ArchosTablet' => 'Android.*ARCHOS|101G9|80G9',
93
+ // @reference: http://en.wikipedia.org/wiki/NOVO7
94
+ 'AinolTablet' => 'NOVO7|Novo7Aurora|Novo7Basic|NOVO7PALADIN',
95
+ // @todo: inspect http://esupport.sony.com/US/p/select-system.pl?DIRECTOR=DRIVER
96
+ 'SonyTablet' => 'Sony Tablet|Sony Tablet S',
97
+ // @ref: db + http://www.cube-tablet.com/buy-products.html
98
+ 'CubeTablet' => 'Android.*(K8GT|U9GT|U10GT|U16GT|U17GT|U18GT|U19GT|U20GT|U23GT|U30GT)',
99
+ // @ref: http://www.cobyusa.com/?p=pcat&pcat_id=3001
100
+ 'CobyTablet' => 'MID1042|MID1045|MID1125|MID1126|MID7012|MID7014|MID7034|MID7035|MID7036|MID7042|MID7048|MID7127|MID8042|MID8048|MID8127|MID9042|MID9740|MID9742|MID7022|MID7010',
101
+ // @ref: http://pdadb.net/index.php?m=pdalist&list=SMiT (NoName Chinese Tablets)
102
+ // @ref: http://www.imp3.net/14/show.php?itemid=20454
103
+ 'SMiTTablet' => 'Android.*(\bMID\b|MID-560|MTV-T1200|MTV-PND531|MTV-P1101|MTV-PND530)',
104
+ // @ref: http://www.rock-chips.com/index.php?do=prod&pid=2
105
+ 'RockChipTablet' => 'Android.*(RK2818|RK2808A|RK2918|RK3066)|RK2738|RK2808A',
106
+ // @ref: http://www.telstra.com.au/home-phone/thub-2/
107
+ 'TelstraTablet' => 'T-Hub2',
108
+ // @ref: http://www.fly-phone.com/devices/tablets/ ; http://www.fly-phone.com/service/
109
+ 'FlyTablet' => 'IQ310|Fly Vision',
110
+ // @ref: http://www.bqreaders.com/gb/tablets-prices-sale.html
111
+ 'bqTablet' => 'bq.*(Elcano|Curie|Edison|Maxwell|Kepler|Pascal|Tesla|Hypatia|Platon|Newton|Livingstone|Cervantes|Avant)',
112
+ // @ref: http://www.huaweidevice.com/worldwide/productFamily.do?method=index&directoryId=5011&treeId=3290
113
+ // @ref: http://www.huaweidevice.com/worldwide/downloadCenter.do?method=index&directoryId=3372&treeId=0&tb=1&type=software (including legacy tablets)
114
+ 'HuaweiTablet' => 'MediaPad|IDEOS S7|S7-201c|S7-202u|S7-101|S7-103|S7-104|S7-105|S7-106|S7-201|S7-Slim',
115
+ 'GenericTablet' => 'Android.*\b97D\b|Tablet(?!.*PC)|ViewPad7|LG-V909|MID7015|BNTV250A|LogicPD Zoom2|\bA7EB\b|CatNova8|A1_07|CT704|CT1002|\bM721\b|hp-tablet',
116
+ );
117
+ // List of mobile Operating Systems.
118
+ protected $operatingSystems = array(
119
+ 'AndroidOS' => 'Android',
120
+ 'BlackBerryOS' => 'blackberry|rim tablet os',
121
+ 'PalmOS' => 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino',
122
+ 'SymbianOS' => 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b',
123
+ // @reference: http://en.wikipedia.org/wiki/Windows_Mobile
124
+ 'WindowsMobileOS' => 'Windows CE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window Mobile|Windows Phone [0-9.]+|WCE;',
125
+ // @reference: http://en.wikipedia.org/wiki/Windows_Phone
126
+ // http://wifeng.cn/?r=blog&a=view&id=106
127
+ // http://nicksnettravels.builttoroam.com/post/2011/01/10/Bogus-Windows-Phone-7-User-Agent-String.aspx
128
+ 'WindowsPhoneOS' => 'Windows Phone OS|XBLWP7|ZuneWP7',
129
+ 'iOS' => 'iphone|ipod|ipad',
130
+ 'FlashLiteOS' => '',
131
+ // http://en.wikipedia.org/wiki/MeeGo
132
+ // @todo: research MeeGo in UAs
133
+ 'MeeGoOS' => 'MeeGo',
134
+ // http://en.wikipedia.org/wiki/Maemo
135
+ // @todo: research Maemo in UAs
136
+ 'MaemoOS' => 'Maemo',
137
+ 'JavaOS' => 'J2ME/MIDP|Java/',
138
+ 'webOS' => 'webOS|hpwOS',
139
+ 'badaOS' => '\bBada\b',
140
+ 'BREWOS' => 'BREW',
141
+ );
142
+ // List of mobile User Agents.
143
+ protected $userAgents = array(
144
+ // @reference: https://developers.google.com/chrome/mobile/docs/user-agent
145
+ 'Chrome' => '\bCrMo\b|CriOS|Android.*Chrome/[.0-9]* (Mobile)?',
146
+ 'Dolfin' => '\bDolfin\b',
147
+ 'Opera' => 'Opera.*Mini|Opera.*Mobi|Android.*Opera',
148
+ 'Skyfire' => 'Skyfire',
149
+ 'IE' => 'IEMobile|MSIEMobile',
150
+ 'Firefox' => 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile',
151
+ 'Bolt' => 'bolt',
152
+ 'TeaShark' => 'teashark',
153
+ 'Blazer' => 'Blazer',
154
+ // @reference: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html#//apple_ref/doc/uid/TP40006517-SW3
155
+ 'Safari' => 'Version.*Mobile.*Safari|Safari.*Mobile',
156
+ // @ref: http://en.wikipedia.org/wiki/Midori_(web_browser)
157
+ //'Midori' => 'midori',
158
+ 'Tizen' => 'Tizen',
159
+ 'UCBrowser' => 'UC.*Browser|UCWEB',
160
+ // @ref: https://github.com/serbanghita/Mobile-Detect/issues/7
161
+ 'DiigoBrowser' => 'DiigoBrowser',
162
+ // http://www.puffinbrowser.com/index.php
163
+ 'Puffin' => 'Puffin',
164
+ // @reference: http://en.wikipedia.org/wiki/Minimo
165
+ // http://en.wikipedia.org/wiki/Vision_Mobile_Browser
166
+ 'GenericBrowser' => 'NokiaBrowser|OviBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision'
167
+ );
168
+ // Utilities.
169
+ protected $utilities = array(
170
+ 'WebKit' => '(webkit)[ /]([\w.]+)',
171
+ 'Bot' => 'Googlebot|DoCoMo|YandexBot|bingbot|ia_archiver|AhrefsBot|Ezooms|GSLFbot|WBSearchBot|Twitterbot|TweetmemeBot|Twikle|PaperLiBot|Wotbox|UnwindFetchor|facebookexternalhit',
172
+ 'MobileBot' => 'Googlebot-Mobile|DoCoMo|YahooSeeker/M1A1-R2D2',
173
+ );
174
+ // Properties list.
175
+ // @reference: http://user-agent-string.info/list-of-ua#Mobile Browser
176
+ const VER = '([\w._]+)';
177
+ protected $properties = array(
178
+
179
+ // Build
180
+ 'Mobile' => 'Mobile/[VER]',
181
+ 'Build' => 'Build/[VER]',
182
+ 'Version' => 'Version/[VER]',
183
+ 'VendorID' => 'VendorID/[VER]',
184
+
185
+ // Devices
186
+ 'iPad' => 'iPad.*CPU[a-z ]+[VER]',
187
+ 'iPhone' => 'iPhone.*CPU[a-z ]+[VER]',
188
+ 'iPod' => 'iPod.*CPU[a-z ]+[VER]',
189
+ //'BlackBerry' => array('BlackBerry[VER]', 'BlackBerry [VER];'),
190
+ 'Kindle' => 'Kindle/[VER]',
191
+
192
+ // Browser
193
+ 'Chrome' => 'Chrome/[VER]',
194
+ 'CriOS' => 'CriOS/[VER]',
195
+ 'Dolfin' => 'Dolfin/[VER]',
196
+ // @reference: https://developer.mozilla.org/en-US/docs/User_Agent_Strings_Reference
197
+ 'Firefox' => 'Firefox/[VER]',
198
+ 'Fennec' => 'Fennec/[VER]',
199
+ // @reference: http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
200
+ 'IEMobile' => array('IEMobile/[VER];', 'IEMobile [VER]'),
201
+ 'MSIE' => 'MSIE [VER];',
202
+ // http://en.wikipedia.org/wiki/NetFront
203
+ 'NetFront' => 'NetFront/[VER]',
204
+ 'NokiaBrowser' => 'NokiaBrowser/[VER]',
205
+ 'NokiaBrowser' => 'NokiaBrowser/[VER]',
206
+ 'Opera' => 'Version/[VER]',
207
+ 'Opera Mini' => 'Opera Mini/[VER]',
208
+ 'Opera Mobi' => 'Version/[VER]',
209
+ 'UC Browser' => 'UC Browser[VER]',
210
+ 'Safari' => 'Version/[VER]',
211
+ 'Skyfire' => 'Skyfire/[VER]',
212
+ 'Tizen' => 'Tizen/[VER]',
213
+ 'Webkit' => 'webkit[ /][VER]',
214
+
215
+ // Engine
216
+ 'Gecko' => 'Gecko/[VER]',
217
+ 'Trident' => 'Trident/[VER]',
218
+ 'Presto' => 'Presto/[VER]',
219
+
220
+ // OS
221
+ 'Android' => 'Android [VER]',
222
+ 'BlackBerry' => array('BlackBerry[\w]+/[VER]', 'BlackBerry.*Version/[VER]'),
223
+ 'BREW' => 'BREW [VER]',
224
+ 'Java' => 'Java/[VER]',
225
+ // @reference: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/08/29/introducing-the-ie9-on-windows-phone-mango-user-agent-string.aspx
226
+ // @reference: http://en.wikipedia.org/wiki/Windows_NT#Releases
227
+ 'Windows Phone OS' => 'Windows Phone OS [VER]',
228
+ 'Windows Phone' => 'Windows Phone [VER]',
229
+ 'Windows CE' => 'Windows CE/[VER]',
230
+ // http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/6be392da-4d2f-41b4-8354-8dcee20c85cd
231
+ 'Windows NT' => 'Windows NT [VER]',
232
+ 'Symbian' => array('SymbianOS/[VER]', 'Symbian/[VER]'),
233
+ 'webOS' => array('webOS/[VER]', 'hpwOS/[VER];'),
234
+
235
+
236
+ );
237
+
238
+ function __construct(){
239
+
240
+ $this->setHttpHeaders();
241
+ $this->setUserAgent();
242
+
243
+ $this->setMobileDetectionRules();
244
+ $this->setMobileDetectionRulesExtended();
245
+
246
+ }
247
+
248
+
249
+ /**
250
+ * Get the current script version.
251
+ * This is useful for the demo.php file,
252
+ * so people can check on what version they are testing
253
+ * for mobile devices.
254
+ */
255
+ public function getScriptVersion(){
256
+
257
+ return $this->scriptVersion;
258
+
259
+ }
260
+
261
+ public function setHttpHeaders($httpHeaders = null){
262
+
263
+ if(!empty($httpHeaders)){
264
+ $this->httpHeaders = $httpHeaders;
265
+ } else {
266
+ foreach($_SERVER as $key => $value){
267
+ if(substr($key,0,5)=='HTTP_'){
268
+ $this->httpHeaders[$key] = $value;
269
+ }
270
+ }
271
+ }
272
+
273
+ }
274
+
275
+ public function getHttpHeaders(){
276
+
277
+ return $this->httpHeaders;
278
+
279
+ }
280
+
281
+ public function setUserAgent($userAgent = null){
282
+
283
+ if(!empty($userAgent)){
284
+ $this->userAgent = $userAgent;
285
+ } else {
286
+ $this->userAgent = isset($this->httpHeaders['HTTP_USER_AGENT']) ? $this->httpHeaders['HTTP_USER_AGENT'] : null;
287
+
288
+ if(empty($this->userAgent)){
289
+ $this->userAgent = isset($this->httpHeaders['HTTP_X_DEVICE_USER_AGENT']) ? $this->httpHeaders['HTTP_X_DEVICE_USER_AGENT'] : null;
290
+ }
291
+ // Header can occur on devices using Opera Mini (can expose the real device type). Let's concatenate it (we need this extra info in the regexes).
292
+ if(!empty($this->httpHeaders['HTTP_X_OPERAMINI_PHONE_UA'])){
293
+ $this->userAgent .= ' '.$this->httpHeaders['HTTP_X_OPERAMINI_PHONE_UA'];
294
+ }
295
+ }
296
+
297
+ }
298
+
299
+ public function getUserAgent(){
300
+
301
+ return $this->userAgent;
302
+
303
+ }
304
+
305
+ function setDetectionType($type = null){
306
+
307
+ $this->detectionType = (!empty($type) ? $type : 'mobile');
308
+
309
+ }
310
+
311
+ public function getPhoneDevices(){
312
+
313
+ return $this->phoneDevices;
314
+
315
+ }
316
+
317
+ public function getTabletDevices(){
318
+
319
+ return $this->tabletDevices;
320
+
321
+ }
322
+
323
+ /**
324
+ * Method sets the mobile detection rules.
325
+ *
326
+ * This method is used for the magic methods $detect->is*()
327
+ */
328
+ public function setMobileDetectionRules(){
329
+ // Merge all rules together.
330
+ $this->mobileDetectionRules = array_merge(
331
+ $this->phoneDevices,
332
+ $this->tabletDevices,
333
+ $this->operatingSystems,
334
+ $this->userAgents
335
+ );
336
+
337
+ }
338
+
339
+ /**
340
+ * Method sets the mobile detection rules + utilities.
341
+ * The reason this is separate is because utilities rules
342
+ * don't necessary imply mobile.
343
+ *
344
+ * This method is used inside the new $detect->is('stuff') method.
345
+ *
346
+ * @return bool
347
+ */
348
+ public function setMobileDetectionRulesExtended(){
349
+
350
+ // Merge all rules together.
351
+ $this->mobileDetectionRulesExtended = array_merge(
352
+ $this->phoneDevices,
353
+ $this->tabletDevices,
354
+ $this->operatingSystems,
355
+ $this->userAgents,
356
+ $this->utilities
357
+ );
358
+
359
+ }
360
+
361
+ /**
362
+ * @return array
363
+ */
364
+ public function getRules()
365
+ {
366
+
367
+ if($this->detectionType=='extended'){
368
+ return $this->mobileDetectionRulesExtended;
369
+ } else {
370
+ return $this->mobileDetectionRules;
371
+ }
372
+
373
+ }
374
+
375
+ /**
376
+ * Check the HTTP headers for signs of mobile.
377
+ * This is the fastest mobile check possible; it's used
378
+ * inside isMobile() method.
379
+ * @return boolean
380
+ */
381
+ public function checkHttpHeadersForMobile(){
382
+
383
+ if(
384
+ isset($this->httpHeaders['HTTP_ACCEPT']) &&
385
+ (strpos($this->httpHeaders['HTTP_ACCEPT'], 'application/x-obml2d') !== false || // Opera Mini; @reference: http://dev.opera.com/articles/view/opera-binary-markup-language/
386
+ strpos($this->httpHeaders['HTTP_ACCEPT'], 'application/vnd.rim.html') !== false || // BlackBerry devices.
387
+ strpos($this->httpHeaders['HTTP_ACCEPT'], 'text/vnd.wap.wml') !== false ||
388
+ strpos($this->httpHeaders['HTTP_ACCEPT'], 'application/vnd.wap.xhtml+xml') !== false) ||
389
+ isset($this->httpHeaders['HTTP_X_WAP_PROFILE']) || // @todo: validate
390
+ isset($this->httpHeaders['HTTP_X_WAP_CLIENTID']) ||
391
+ isset($this->httpHeaders['HTTP_WAP_CONNECTION']) ||
392
+ isset($this->httpHeaders['HTTP_PROFILE']) ||
393
+ isset($this->httpHeaders['HTTP_X_OPERAMINI_PHONE_UA']) || // Reported by Nokia devices (eg. C3)
394
+ isset($this->httpHeaders['HTTP_X_NOKIA_IPADDRESS']) ||
395
+ isset($this->httpHeaders['HTTP_X_NOKIA_GATEWAY_ID']) ||
396
+ isset($this->httpHeaders['HTTP_X_ORANGE_ID']) ||
397
+ isset($this->httpHeaders['HTTP_X_VODAFONE_3GPDPCONTEXT']) ||
398
+ isset($this->httpHeaders['HTTP_X_HUAWEI_USERID']) ||
399
+ isset($this->httpHeaders['HTTP_UA_OS']) || // Reported by Windows Smartphones.
400
+ isset($this->httpHeaders['HTTP_X_MOBILE_GATEWAY']) || // Reported by Verizon, Vodafone proxy system.
401
+ isset($this->httpHeaders['HTTP_X_ATT_DEVICEID']) || // Seend this on HTC Sensation. @ref: SensationXE_Beats_Z715e
402
+ //HTTP_X_NETWORK_TYPE = WIFI
403
+ ( isset($this->httpHeaders['HTTP_UA_CPU']) &&
404
+ $this->httpHeaders['HTTP_UA_CPU'] == 'ARM' // Seen this on a HTC.
405
+ )
406
+ ){
407
+
408
+ return true;
409
+
410
+ }
411
+
412
+ return false;
413
+
414
+ }
415
+
416
+ /**
417
+ * Magic overloading method.
418
+ *
419
+ * @method boolean is[...]()
420
+ * @param string $name
421
+ * @param array $arguments
422
+ * @return mixed
423
+ */
424
+ public function __call($name, $arguments)
425
+ {
426
+
427
+ $this->setDetectionType('mobile');
428
+
429
+ $key = substr($name, 2);
430
+ return $this->matchUAAgainstKey($key);
431
+
432
+ }
433
+
434
+ /**
435
+ * Find a detection rule that matches the current User-agent.
436
+ *
437
+ * @param null $userAgent deprecated
438
+ * @return boolean
439
+ */
440
+ private function matchDetectionRulesAgainstUA($userAgent = null){
441
+
442
+ // Begin general search.
443
+ foreach($this->getRules() as $_regex){
444
+ if(empty($_regex)){ continue; }
445
+ if( $this->match($_regex, $userAgent) ){
446
+ //var_dump( $_regex );
447
+ return true;
448
+ }
449
+ }
450
+
451
+ return false;
452
+
453
+ }
454
+
455
+ /**
456
+ * Search for a certain key in the rules array.
457
+ * If the key is found the try to match the corresponding
458
+ * regex agains the User-agent.
459
+ *
460
+ * @param string $key
461
+ * @param null $userAgent deprecated
462
+ * @return mixed
463
+ */
464
+ private function matchUAAgainstKey($key, $userAgent = null){
465
+
466
+ // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc.
467
+ $key = strtolower($key);
468
+ $_rules = array_change_key_case($this->getRules());
469
+
470
+ if(array_key_exists($key, $_rules)){
471
+ if(empty($_rules[$key])){ return null; }
472
+ return $this->match($_rules[$key], $userAgent);
473
+ }
474
+
475
+ return false;
476
+
477
+ }
478
+
479
+ /**
480
+ * Check if the device is mobile.
481
+ * Returns true if any type of mobile device detected, including special ones
482
+ * @param null $userAgent deprecated
483
+ * @param null $httpHeaders deprecated
484
+ * @return bool
485
+ */
486
+ public function isMobile($userAgent = null, $httpHeaders = null) {
487
+
488
+ if($httpHeaders){ $this->setHttpHeaders($httpHeaders); }
489
+ if($userAgent){ $this->setUserAgent($userAgent); }
490
+
491
+ $this->setDetectionType('mobile');
492
+
493
+ if ($this->checkHttpHeadersForMobile()) {
494
+ return true;
495
+ } else {
496
+ return $this->matchDetectionRulesAgainstUA();
497
+ }
498
+
499
+ }
500
+
501
+ /**
502
+ * Check if the device is a tablet.
503
+ * Return true if any type of tablet device is detected.
504
+ *
505
+ * @param null $userAgent deprecated
506
+ * @param null $httpHeaders deprecated
507
+ * @return bool
508
+ */
509
+ public function isTablet($userAgent = null, $httpHeaders = null) {
510
+
511
+ $this->setDetectionType('mobile');
512
+
513
+ foreach($this->tabletDevices as $_regex){
514
+ if($this->match($_regex, $userAgent)){
515
+ return true;
516
+ }
517
+ }
518
+
519
+ return false;
520
+
521
+ }
522
+
523
+ /**
524
+ * This method checks for a certain property in the
525
+ * userAgent.
526
+ * @todo: The httpHeaders part is not yet used.
527
+ *
528
+ * @param $key
529
+ * @param string $userAgent deprecated
530
+ * @param string $httpHeaders deprecated
531
+ * @return bool|int|null
532
+ */
533
+ public function is($key, $userAgent = null, $httpHeaders = null){
534
+
535
+
536
+ // Set the UA and HTTP headers only if needed (eg. batch mode).
537
+ if($httpHeaders) $this->setHttpHeaders($httpHeaders);
538
+ if($userAgent) $this->setUserAgent($userAgent);
539
+
540
+ $this->setDetectionType('extended');
541
+
542
+ return $this->matchUAAgainstKey($key);
543
+
544
+ }
545
+
546
+ public function getOperatingSystems(){
547
+
548
+ return $this->operatingSystems;
549
+
550
+ }
551
+
552
+ /**
553
+ * Some detection rules are relative (not standard),
554
+ * because of the diversity of devices, vendors and
555
+ * their conventions in representing the User-Agent or
556
+ * the HTTP headers.
557
+ *
558
+ * This method will be used to check custom regexes against
559
+ * the User-Agent string.
560
+ *
561
+ * @param $regex
562
+ * @param string $userAgent
563
+ * @return bool
564
+ *
565
+ * @todo: search in the HTTP headers too.
566
+ */
567
+ function match($regex, $userAgent=null){
568
+
569
+ // Escape the special character which is the delimiter.
570
+ $regex = str_replace('/', '\/', $regex);
571
+
572
+ return (bool)preg_match('/'.$regex.'/is', (!empty($userAgent) ? $userAgent : $this->userAgent));
573
+
574
+ }
575
+
576
+ /**
577
+ * Get the properties array.
578
+ * @return array
579
+ */
580
+ function getProperties(){
581
+
582
+ return $this->properties;
583
+
584
+ }
585
+
586
+ /**
587
+ * Prepare the version number.
588
+ *
589
+ * @param $ver
590
+ * @return int
591
+ */
592
+ function prepareVersionNo($ver){
593
+
594
+ $ver = str_replace(array('_', ' ', '/'), array('.', '.', '.'), $ver);
595
+ $arrVer = explode('.', $ver, 2);
596
+ $arrVer[1] = @str_replace('.', '', $arrVer[1]); // @todo: treat strings versions.
597
+ $ver = (float)implode('.', $arrVer);
598
+
599
+ return $ver;
600
+
601
+ }
602
+
603
+ /**
604
+ * Check the version of the given property in the User-Agent.
605
+ * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31)
606
+ *
607
+ * @param string $propertyName
608
+ * @return mixed $version
609
+ */
610
+ function version($propertyName){
611
+
612
+ $properties = $this->getProperties();
613
+
614
+ // If the property is found in the User-Agent then move to the next step.
615
+ if(stripos($this->userAgent, $propertyName)!==false){
616
+
617
+ // Prepare the pattern to be matched.
618
+ // Make sure we always deal with an array (string is converted).
619
+ $properties[$propertyName] = (array)$properties[$propertyName];
620
+
621
+ foreach($properties[$propertyName] as $propertyMatchString){
622
+
623
+ $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString);
624
+
625
+ // Escape the special character which is the delimiter.
626
+ $propertyPattern = str_replace('/', '\/', $propertyPattern);
627
+
628
+ // Identify and extract the version.
629
+ preg_match('/'.$propertyPattern.'/is', $this->userAgent, $match);
630
+
631
+ if(!empty($match[1])){
632
+ $version = $this->prepareVersionNo($match[1]);
633
+ return $version;
634
+ }
635
+
636
+ }
637
+
638
+ return 0;
639
+
640
+ }
641
+
642
+ return false;
643
+
644
+ }
645
+
646
+ function mobileGrade(){
647
+
648
+ $isMobile = $this->isMobile();
649
+
650
+ if(
651
+ // Apple iOS 3.2-5.1 - Tested on the original iPad (4.3 / 5.0), iPad 2 (4.3), iPad 3 (5.1), original iPhone (3.1), iPhone 3 (3.2), 3GS (4.3), 4 (4.3 / 5.0), and 4S (5.1)
652
+ $this->version('iPad')>=4.3 ||
653
+ $this->version('iPhone')>=3.1 ||
654
+ $this->version('iPod')>=3.1 ||
655
+
656
+ // Android 2.1-2.3 - Tested on the HTC Incredible (2.2), original Droid (2.2), HTC Aria (2.1), Google Nexus S (2.3). Functional on 1.5 & 1.6 but performance may be sluggish, tested on Google G1 (1.5)
657
+ // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM
658
+ // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices
659
+ // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7
660
+ ( $this->version('Android')>2.1 && $this->is('Webkit') ) ||
661
+
662
+ // Windows Phone 7-7.5 - Tested on the HTC Surround (7.0) HTC Trophy (7.5), LG-E900 (7.5), Nokia Lumia 800
663
+ $this->version('Windows Phone OS')>=7.0 ||
664
+
665
+ // Blackberry 7 - Tested on BlackBerry® Torch 9810
666
+ // Blackberry 6.0 - Tested on the Torch 9800 and Style 9670
667
+ $this->version('BlackBerry')>=6.0 ||
668
+ // Blackberry Playbook (1.0-2.0) - Tested on PlayBook
669
+ $this->match('Playbook.*Tablet') ||
670
+
671
+ // Palm WebOS (1.4-2.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0)
672
+ ( $this->version('webOS')>=1.4 && $this->match('Palm|Pre|Pixi') ) ||
673
+ // Palm WebOS 3.0 - Tested on HP TouchPad
674
+ $this->match('hp.*TouchPad') ||
675
+
676
+ // Firefox Mobile (12 Beta) - Tested on Android 2.3 device
677
+ ( $this->is('Firefox') && $this->version('Firefox')>=12 ) ||
678
+
679
+ // Chrome for Android - Tested on Android 4.0, 4.1 device
680
+ ( $this->is('Chrome') && $this->is('AndroidOS') && $this->version('Android')>=4.0 ) ||
681
+
682
+ // Skyfire 4.1 - Tested on Android 2.3 device
683
+ ( $this->is('Skyfire') && $this->version('Skyfire')>=4.1 && $this->is('AndroidOS') && $this->version('Android')>=2.3 ) ||
684
+
685
+ // Opera Mobile 11.5-12: Tested on Android 2.3
686
+ ( $this->is('Opera') && $this->version('Opera Mobi')>11 && $this->is('AndroidOS') ) ||
687
+
688
+ // Meego 1.2 - Tested on Nokia 950 and N9
689
+ $this->is('MeeGoOS') ||
690
+
691
+ // Tizen (pre-release) - Tested on early hardware
692
+ $this->is('Tizen') ||
693
+
694
+ // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser
695
+ // @todo: more tests here!
696
+ $this->is('Dolfin') && $this->version('Bada')>=2.0 ||
697
+
698
+ // UC Browser - Tested on Android 2.3 device
699
+ ( ($this->is('UC Browser') || $this->is('Dolfin')) && $this->version('Android')>=2.3 ) ||
700
+
701
+ // Kindle 3 and Fire - Tested on the built-in WebKit browser for each
702
+ ( $this->match('Kindle Fire') ||
703
+ $this->is('Kindle') && $this->version('Kindle')>=3.0 ) ||
704
+
705
+ // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet
706
+ $this->is('AndroidOS') && $this->is('NookTablet') ||
707
+
708
+ // Chrome Desktop 11-21 - Tested on OS X 10.7 and Windows 7
709
+ $this->version('Chrome')>=11 && !$isMobile ||
710
+
711
+ // Safari Desktop 4-5 - Tested on OS X 10.7 and Windows 7
712
+ $this->version('Safari')>=5.0 && !$isMobile ||
713
+
714
+ // Firefox Desktop 4-13 - Tested on OS X 10.7 and Windows 7
715
+ $this->version('Firefox')>=4.0 && !$isMobile ||
716
+
717
+ // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7
718
+ $this->version('MSIE')>=7.0 && !$isMobile ||
719
+
720
+ // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7
721
+ // @reference: http://my.opera.com/community/openweb/idopera/
722
+ $this->version('Opera')>=10 && !$isMobile
723
+
724
+
725
+ ){
726
+ return 'A';
727
+ }
728
+
729
+ if(
730
+ // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770
731
+ $this->version('BlackBerry')>=5 && $this->version('BlackBerry')<6 ||
732
+
733
+ //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3
734
+ ( $this->version('Opera Mini')>=5.0 && $this->version('Opera Mini')<=6.5 &&
735
+ ($this->version('Android')>=2.3 || $this->is('iOS')) ) ||
736
+
737
+ // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1)
738
+ $this->match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') ||
739
+
740
+ // @todo: report this (tested on Nokia N71)
741
+ $this->version('Opera Mobi')>=11 && $this->is('SymbianOS')
742
+
743
+ ){
744
+ return 'B';
745
+ }
746
+
747
+ if(
748
+ // Blackberry 4.x - Tested on the Curve 8330
749
+ $this->version('BlackBerry')<5.0 ||
750
+ // Windows Mobile - Tested on the HTC Leo (WinMo 5.2)
751
+ $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile')<=5.2
752
+
753
+
754
+ ){
755
+
756
+ return 'C';
757
+
758
+ }
759
+
760
+ // All older smartphone platforms and featurephones - Any device that doesn't support media queries will receive the basic, C grade experience
761
+ return 'C';
762
+
763
+
764
+ }
765
+
766
+
767
+ }
notifications.php CHANGED
@@ -66,7 +66,7 @@ function wp_rp_load_remote_notifications() {
66
  'timeout' => 5
67
  );
68
 
69
- if(empty($blog_id) || empty($auth_key) || !$options['ctr_dashboard_enabled']) return;
70
 
71
  // receive remote recommendations
72
  $url = WP_RP_CTR_DASHBOARD_URL . "notifications/?blog_id=$blog_id&auth_key=$auth_key";
66
  'timeout' => 5
67
  );
68
 
69
+ if(!$blog_id || !$auth_key || !$options['ctr_dashboard_enabled']) return;
70
 
71
  // receive remote recommendations
72
  $url = WP_RP_CTR_DASHBOARD_URL . "notifications/?blog_id=$blog_id&auth_key=$auth_key";
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: related,posts,post,related posts,plugin
4
  License: GPLv2
5
  Requires at least: 3.3
6
  Tested up to: 3.5
7
- Stable tag: 2.4
8
 
9
  WordPress Related Posts generates a list of related posts with thumbnails and gives you click-through statistics.
10
 
@@ -63,8 +63,21 @@ We adopted the principle of having three "release channels". You can try the mos
63
  2. WordPress Related Posts reporting real time statistics for mobile and desktop devices.
64
  3. WordPress Related Posts responsive theme on a Galaxy Nexus and iPhone 4s.
65
 
 
 
 
 
 
66
  == Changelog ==
67
 
 
 
 
 
 
 
 
 
68
  = 2.4 =
69
  * Limit related post age
70
  * Bugfix for thumbnail extraction
4
  License: GPLv2
5
  Requires at least: 3.3
6
  Tested up to: 3.5
7
+ Stable tag: 2.5
8
 
9
  WordPress Related Posts generates a list of related posts with thumbnails and gives you click-through statistics.
10
 
63
  2. WordPress Related Posts reporting real time statistics for mobile and desktop devices.
64
  3. WordPress Related Posts responsive theme on a Galaxy Nexus and iPhone 4s.
65
 
66
+ == Upgrade Notice ==
67
+
68
+ = 2.5 =
69
+ This version adds a wrapper around related posts and a link to zemanta.com (can be turned off in plugin settings). Please recheck the layout after upgrade.
70
+
71
  == Changelog ==
72
 
73
+ = 2.5 =
74
+ * Mobile themes settings
75
+ * Editorial control
76
+ * New Pinterest inspired theme
77
+ * Support us by displaying our logo
78
+ * Small output html layout change
79
+ * Bugfixes
80
+
81
  = 2.4 =
82
  * Limit related post age
83
  * Bugfix for thumbnail extraction
recommendations.php CHANGED
@@ -311,10 +311,11 @@ function wp_rp_fetch_random_posts($limit = 10, $exclude_ids = array()) {
311
  }
312
  $ids = $wpdb->get_col($q1, 0);
313
  $count = count($ids);
314
- if($count <= 1) {
315
- if($count === 0) return false;
316
- if($count === 1) $rnd = $ids;
317
- } else {
 
318
  $display_number = min($limit, $count);
319
 
320
  $next_seed = rand();
@@ -322,18 +323,16 @@ function wp_rp_fetch_random_posts($limit = 10, $exclude_ids = array()) {
322
  $seed = $t - $t % 300 + $post->ID << 4; // We keep the same seed for 5 minutes, so MySQL can cache the `q2` query.
323
  srand($seed);
324
 
325
- $rnd = array_rand($ids, $display_number); // This is an array of random indexes, sorted
326
- if ($display_number == 1) {
327
- $ids = array($ids[$rnd]);
328
- } else {
329
- shuffle($rnd);
330
- foreach ($rnd as &$i) { // Here, index is passed by reference, so we can modify it
331
- $i = $ids[$i]; // Replace indexes with corresponding IDs
332
- }
333
- $ids = $rnd;
334
- }
335
  srand($next_seed);
336
  }
337
  $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) . ")";
338
- return $wpdb->get_results($q2);
 
 
 
 
339
  }
311
  }
312
  $ids = $wpdb->get_col($q1, 0);
313
  $count = count($ids);
314
+ if($count === 0) {
315
+ return false;
316
+ /*} else if($count === 1) {
317
+ $rnd = $ids;*/
318
+ } else if($count > 1) {
319
  $display_number = min($limit, $count);
320
 
321
  $next_seed = rand();
323
  $seed = $t - $t % 300 + $post->ID << 4; // We keep the same seed for 5 minutes, so MySQL can cache the `q2` query.
324
  srand($seed);
325
 
326
+ shuffle($ids);
327
+
328
+ $ids = array_slice($ids, 0, $display_number);
329
+
 
 
 
 
 
 
330
  srand($next_seed);
331
  }
332
  $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) . ")";
333
+ $results = $wpdb->get_results($q2);
334
+ asort($ids);
335
+ $ids_keys = array_keys($ids);
336
+ array_multisort($ids_keys, $results);
337
+ return $results;
338
  }
settings.php CHANGED
@@ -134,12 +134,13 @@ function wp_rp_settings_scripts() {
134
  wp_enqueue_script("wp_rp_dashboard_script", plugins_url('static/js/dashboard.js', __FILE__), array('jquery'), WP_RP_VERSION);
135
  }
136
  function wp_rp_settings_styles() {
137
- wp_enqueue_style("wp_rp_dashaboard_style", plugins_url("static/css/dashboard.css", __FILE__));
138
  }
139
 
140
  function wp_rp_register_blog($account_type='other') {
141
  $meta = wp_rp_get_meta();
142
 
 
143
  $req_options = array(
144
  'timeout' => 30
145
  );
@@ -225,8 +226,6 @@ function wp_rp_ajax_hide_show_statistics() {
225
  add_action('wp_ajax_rp_show_hide_statistics', 'wp_rp_ajax_hide_show_statistics');
226
 
227
  function wp_rp_settings_page() {
228
- $title_tags = array('h2', 'h3', 'h4', 'p', 'div');
229
-
230
  $options = wp_rp_get_options();
231
  $meta = wp_rp_get_meta();
232
 
@@ -235,30 +234,39 @@ function wp_rp_settings_page() {
235
  // load notifications every time user goes to settings page
236
  wp_rp_load_remote_notifications();
237
 
238
- if(sizeof($_POST))
239
- {
240
  $old_options = $options;
241
  $new_options = array(
242
  'on_single_post' => isset($postdata['wp_rp_on_single_post']),
243
- 'display_comment_count' => isset($postdata['wp_rp_display_comment_count']),
244
- 'display_publish_date' => isset($postdata['wp_rp_display_publish_date']),
245
- 'display_excerpt' => isset($postdata['wp_rp_display_excerpt']),
246
- 'excerpt_max_length' => (isset($postdata['wp_rp_excerpt_max_length']) && is_numeric(trim($postdata['wp_rp_excerpt_max_length']))) ? intval(trim($postdata['wp_rp_excerpt_max_length'])) : 200,
247
  'max_related_posts' => (isset($postdata['wp_rp_max_related_posts']) && is_numeric(trim($postdata['wp_rp_max_related_posts']))) ? intval(trim($postdata['wp_rp_max_related_posts'])) : 5,
248
  'on_rss' => isset($postdata['wp_rp_on_rss']),
249
- 'display_thumbnail' => isset($postdata['wp_rp_display_thumbnail']),
250
- 'thumbnail_custom_field' => isset($postdata['wp_rp_thumbnail_custom_field']) ? trim($postdata['wp_rp_thumbnail_custom_field']) : false,
251
- 'thumbnail_display_title' => isset($postdata['wp_rp_thumbnail_display_title']),
252
  'related_posts_title' => isset($postdata['wp_rp_related_posts_title']) ? trim($postdata['wp_rp_related_posts_title']) : '',
253
- 'related_posts_title_tag' => isset($postdata['wp_rp_related_posts_title_tag']) ? $postdata['wp_rp_related_posts_title_tag'] : 'h3',
254
- 'thumbnail_use_attached' => isset($postdata['wp_rp_thumbnail_use_attached']),
255
- 'thumbnail_use_custom' => isset($postdata['wp_rp_thumbnail_use_custom']) && $postdata['wp_rp_thumbnail_use_custom'] === 'yes',
256
  'ctr_dashboard_enabled' => isset($postdata['wp_rp_ctr_dashboard_enabled']),
257
  'promoted_content_enabled' => isset($postdata['wp_rp_promoted_content_enabled']),
258
  'enable_themes' => isset($postdata['wp_rp_enable_themes']),
259
- 'custom_theme_enabled' => isset($postdata['wp_rp_custom_theme_enabled']),
260
  'traffic_exchange_enabled' => isset($postdata['wp_rp_traffic_exchange_enabled']),
261
- 'max_related_post_age_in_days' => (isset($postdata['wp_rp_max_related_post_age_in_days']) && is_numeric(trim($postdata['wp_rp_max_related_post_age_in_days']))) ? intval(trim($postdata['wp_rp_max_related_post_age_in_days'])) : 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  );
263
 
264
  if(!isset($postdata['wp_rp_exclude_categories'])) {
@@ -269,25 +277,31 @@ function wp_rp_settings_page() {
269
  $new_options['exclude_categories'] = trim($postdata['wp_rp_exclude_categories']);
270
  }
271
 
272
- $preprocess_thumbnails = $new_options['display_thumbnail'] && $new_options['thumbnail_use_attached'] && (!$old_options['display_thumbnail'] || !$old_options['thumbnail_use_attached']);
273
-
274
- if(isset($postdata['wp_rp_theme_name'])) { // If this isn't set, maybe the AJAX didn't load...
275
- $new_options['theme_name'] = trim($postdata['wp_rp_theme_name']);
276
 
277
- if(isset($postdata['wp_rp_theme_custom_css'])) {
278
- $new_options['theme_custom_css'] = $postdata['wp_rp_theme_custom_css'];
 
 
 
279
  } else {
280
- $new_options['theme_custom_css'] = '';
 
281
  }
282
- } else {
283
- $new_options['theme_name'] = $old_options['theme_name'];
284
- $new_options['theme_custom_css'] = $old_options['theme_custom_css'];
285
  }
286
 
287
  if (isset($postdata['wp_rp_turn_on_button_pressed'])) {
 
288
  $meta['turn_on_button_pressed'] = $postdata['wp_rp_turn_on_button_pressed'];
 
 
289
  }
290
 
 
 
 
291
  $default_thumbnail_path = wp_rp_upload_default_thumbnail_file();
292
 
293
  if($default_thumbnail_path === false) { // no file uploaded
@@ -307,7 +321,7 @@ function wp_rp_settings_page() {
307
  if($new_options['ctr_dashboard_enabled'] && !$old_options['ctr_dashboard_enabled']) {
308
  $meta['show_statistics'] = true;
309
 
310
- if($new_options['display_thumbnail']) {
311
  $meta['show_turn_on_button'] = false;
312
  }
313
 
@@ -337,17 +351,8 @@ function wp_rp_settings_page() {
337
  ?>
338
 
339
  <div class="wrap" id="wp_rp_wrap">
340
- <?php
341
- $related_posts_title_tag = $options['related_posts_title_tag'];
342
- $theme_name = $options['theme_name'];
343
- $theme_custom_css = $options['theme_custom_css'];
344
-
345
- include(dirname(__FILE__) . '/static/settings.js.php');
346
- ?>
347
-
348
  <input type="hidden" id="wp_rp_json_url" value="<?php esc_attr_e(WP_RP_STATIC_BASE_URL . WP_RP_STATIC_JSON_PATH); ?>" />
349
  <input type="hidden" id="wp_rp_version" value="<?php esc_attr_e(WP_RP_VERSION); ?>" />
350
- <input type="hidden" id="wp_rp_theme_selected" value="<?php esc_attr_e($theme_name); ?>" />
351
  <input type="hidden" id="wp_rp_dashboard_url" value="<?php esc_attr_e(WP_RP_CTR_DASHBOARD_URL); ?>" />
352
  <input type="hidden" id="wp_rp_static_base_url" value="<?php esc_attr_e(WP_RP_STATIC_BASE_URL); ?>" />
353
 
@@ -377,15 +382,34 @@ function wp_rp_settings_page() {
377
 
378
  <?php if($meta['show_turn_on_button']): ?>
379
  <div id="wp_rp_turn_on_statistics">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  <ul>
381
  <li>
382
  <div>
383
  <ul>
384
- <li class="title"><h3>Basic</h3></li>
385
  <li>Related Posts</li>
386
  <li>Settings</li>
387
  <li>Analytics</li>
388
- <li class="turn-on-wrap"><a data-type="basic" href="#" class="zemanta-button turn-on">Turn on</a></li>
 
 
389
  </ul>
390
  </div>
391
  </li>
@@ -397,25 +421,24 @@ function wp_rp_settings_page() {
397
  <li>Settings</li>
398
  <li>Analytics</li>
399
  <li>Increase pageviews<br />(traffic exchange)</li>
400
- <li class="turn-on-wrap"><a data-type="advanced" href="#" class="zemanta-button turn-on">Turn on</a></li>
401
  </ul>
402
  </div>
403
  </li>
404
  <li>
405
  <div>
406
  <ul>
407
- <li class="title"><h3>Publisher</h3></li>
408
  <li>Related Posts</li>
409
  <li>Settings</li>
410
  <li>Analytics</li>
411
- <li>Increase pageviews<br />(traffic exchange)</li>
412
- <li>Earn money<br />(promoted posts)</li>
413
- <li class="turn-on-wrap"><a data-type="publisher" href="#" class="zemanta-button turn-on">Turn on</a></li>
414
  </ul>
415
  </div>
416
  </li>
417
  </ul>
418
- <p>Analytics, traffic exchange and promoted posts are provided via <a target="_blank" href="http://related-posts.com/tos/">3rd party service</a>.</p>
 
419
  </div>
420
  <?php endif; ?>
421
 
@@ -543,128 +566,125 @@ jQuery(function($) {
543
  </select> &nbsp;months.
544
  </label></td>
545
  </tr>
546
- </table>
 
 
 
 
547
 
 
548
  <h3>Theme Settings</h3>
549
- <table class="form-table">
550
- <tr id="wp_rp_theme_options_wrap">
551
- <th scope="row">Select Theme:</th>
552
- <td>
553
- <label>
554
- <input name="wp_rp_enable_themes" type="checkbox" id="wp_rp_enable_themes" value="yes"<?php checked($options["enable_themes"]); ?> />
555
- <?php _e("Enable Themes",'wp_related_posts'); ?>*
556
- </label>
557
- <div id="wp_rp_theme_area" style="display: none;">
558
- <div class="theme-list"></div>
559
- <div class="theme-screenshot"></div>
560
- <div class="theme-extra-options">
561
- <label>
562
- <input type="checkbox" id="wp_rp_custom_theme_enabled" name="wp_rp_custom_theme_enabled" value="yes"<?php checked($options['custom_theme_enabled']); ?> />
563
- Customize
564
- </label>
 
 
 
 
 
565
  </div>
566
- </div>
567
- </td>
568
- </tr>
569
- <tr id="wp_rp_theme_custom_css_wrap" style="display: none; ">
570
- <th scope="row"></th>
571
- <td>
572
- <p class="notice">To override default rules please add "!important" after every declaration.</p>
573
- <textarea style="width: 300px; height: 215px;" name="wp_rp_theme_custom_css" class="custom-css"><?php echo htmlspecialchars($theme_custom_css, ENT_QUOTES); ?></textarea>
574
- </td>
575
- </tr>
576
- <tr>
577
- <th scope="row"><?php _e("Thumbnail Options:",'wp_related_posts'); ?></th>
578
- <td>
579
- <label>
580
- <input name="wp_rp_display_thumbnail" type="checkbox" id="wp_rp_display_thumbnail" value="yes"<?php checked($options["display_thumbnail"]); ?> onclick="wp_rp_display_thumbnail_onclick();" />
581
- <?php _e("Display Thumbnails For Related Posts",'wp_related_posts');?>
582
- </label>
583
- <br />
584
- <span id="wp_rp_thumbnail_span" style="<?php echo $options["display_thumbnail"] ? '' : 'display:none;'; ?>">
585
- <label>
586
- <input name="wp_rp_thumbnail_display_title" type="checkbox" id="wp_rp_thumbnail_display_title" value="yes"<?php checked($options["thumbnail_display_title"]); ?> />
587
- <?php _e('Display Post Titles', 'wp_related_posts');?>
588
- </label>
589
- <br />
590
-
591
- <?php
592
- global $wpdb;
593
-
594
- $custom_fields = $wpdb->get_col( "SELECT meta_key FROM $wpdb->postmeta GROUP BY meta_key HAVING meta_key NOT LIKE '\_%' ORDER BY LOWER(meta_key)" );
595
-
596
- if($custom_fields) :
597
- ?>
598
- <label><input name="wp_rp_thumbnail_use_custom" type="radio" value="no" <?php checked(!$options['thumbnail_use_custom']); ?>> Use featured image</label>&nbsp;&nbsp;&nbsp;&nbsp;
599
- <label><input name="wp_rp_thumbnail_use_custom" type="radio" value="yes" <?php checked($options['thumbnail_use_custom']); ?>> Use custom field</label>
600
-
601
- <select name="wp_rp_thumbnail_custom_field" id="wp_rp_thumbnail_custom_field" class="postform">
602
-
603
- <?php foreach ( $custom_fields as $custom_field ) : ?>
604
- <option value="<?php esc_attr_e($custom_field); ?>"<?php selected($options["thumbnail_custom_field"], $custom_field); ?>><?php esc_html_e($custom_field);?></option>
605
- <?php endforeach; ?>
606
-
607
- </select>
608
- <br />
609
- <?php endif; ?>
610
-
611
- <label>
612
- <input name="wp_rp_thumbnail_use_attached" type="checkbox" value="yes" <?php checked($options["thumbnail_use_attached"]); ?>>
613
- <?php _e("If featured image is missing, show an image from the post",'wp_related_posts');?>
614
- </label>
615
- <br />
616
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617
 
618
- <br />
619
- <label>
620
- <?php _e('For posts without images, a default image will be shown.<br/>
621
- You can upload your own default image here','wp_related_posts');?>
622
- <input type="file" name="wp_rp_default_thumbnail" />
623
- </label>
624
- <?php if($options['default_thumbnail_path']) : ?>
625
- <span style="display: inline-block; vertical-align: top; *display: inline; zoom: 1;">
626
- <img style="padding: 3px; border: 1px solid #DFDFDF; border-radius: 3px;" valign="top" width="80" height="80" src="<?php esc_attr_e(wp_rp_get_default_thumbnail_url()); ?>" alt="selected thumbnail" />
627
- <br />
628
- <label>
629
- <input type="checkbox" name="wp_rp_default_thumbnail_remove" value="yes" />
630
- <?php _e("Remove selected",'wp_related_posts');?>
631
- </label>
632
- </span>
633
- <?php endif; ?>
634
- </span>
635
- </td>
636
- </tr>
637
- <tr>
638
- <th scope="row"><?php _e("Display Options:",'wp_related_posts'); ?></th>
639
- <td>
640
- <label>
641
- <input name="wp_rp_display_comment_count" type="checkbox" id="wp_rp_display_comment_count" value="yes" <?php checked($options["display_comment_count"]); ?>>
642
- <?php _e("Display Number of Comments",'wp_related_posts');?>
643
- </label><br />
644
- <label>
645
- <input name="wp_rp_display_publish_date" type="checkbox" id="wp_rp_display_publish_date" value="yes" <?php checked($options["display_publish_date"]); ?>>
646
- <?php _e("Display Publish Date",'wp_related_posts');?>
647
- </label><br />
648
- <label>
649
- <input name="wp_rp_display_excerpt" type="checkbox" id="wp_rp_display_excerpt" value="yes"<?php checked($options["display_excerpt"]); ?> onclick="wp_rp_display_excerpt_onclick();" >
650
- <?php _e("Display Post Excerpt",'wp_related_posts');?>
651
- </label>
652
- <label id="wp_rp_excerpt_max_length_label"<?php echo $options["display_excerpt"] ? '' : ' style="display: none;"'; ?>>
653
- <input name="wp_rp_excerpt_max_length" type="text" id="wp_rp_excerpt_max_length" class="small-text" value="<?php esc_attr_e($options["excerpt_max_length"]); ?>" /> <span class="description"><?php _e('Maximum Number of Characters.', 'wp_related_posts'); ?></span>
654
- </label><br/>
655
- <label for="wp_rp_related_posts_title_tag">
656
- <?php _e('Related Posts Title Tag', 'wp_related_posts'); ?>
657
- <select name="wp_rp_related_posts_title_tag" id="wp_rp_related_posts_title_tag" class="postform">
658
  <?php
659
- foreach ($title_tags as $tag) :
 
 
 
660
  ?>
661
- <option value="<?php esc_attr_e($tag); ?>"<?php selected($related_posts_title_tag, $tag); ?>>&lt;<?php esc_html_e($tag); ?>&gt;</option>
 
 
 
 
 
 
662
  <?php endforeach; ?>
663
  </select>
664
- </label>
665
- </td>
666
- </tr>
667
- </table>
 
 
 
 
 
 
 
 
668
  <h3><?php _e("Other Settings:",'wp_related_posts'); ?></h3>
669
  <table class="form-table">
670
  <tr valign="top">
@@ -692,6 +712,8 @@ jQuery(function($) {
692
  </tr>
693
  <tr valign="top">
694
  <td colspan="2">
 
 
695
  <label>
696
  <input name="wp_rp_on_single_post" type="checkbox" id="wp_rp_on_single_post" value="yes" <?php checked($options['on_single_post']); ?>>
697
  <?php _e("Auto Insert Related Posts",'wp_related_posts');?>
@@ -714,21 +736,27 @@ jQuery(function($) {
714
  <input name="wp_rp_ctr_dashboard_enabled" type="checkbox" id="wp_rp_ctr_dashboard_enabled" value="yes" <?php checked($options['ctr_dashboard_enabled']); ?> />
715
  <?php _e("Turn statistics on",'wp_related_posts');?>*
716
  </label>
 
717
  <br />
718
  <label>
719
  <input name="wp_rp_promoted_content_enabled" type="checkbox" id="wp_rp_promoted_content_enabled" value="yes" <?php checked($options['promoted_content_enabled']); ?> />
720
  <?php _e('Promoted Content', 'wp_related_posts');?>*
721
  </label>
 
 
 
 
 
 
 
722
  </td>
 
723
  </tr>
724
  </table>
725
  <p class="submit"><input type="submit" value="<?php _e('Save changes', 'wp_related_posts'); ?>" class="button-primary" /></p>
726
 
727
  </div>
728
  </div>
729
- <div id="wp_rp_tos">
730
- * Provided via <a target="_blank" href="http://related-posts.com/tos/">3rd party service</a>.
731
- </div>
732
  </form>
733
  </div>
734
  <?php }
134
  wp_enqueue_script("wp_rp_dashboard_script", plugins_url('static/js/dashboard.js', __FILE__), array('jquery'), WP_RP_VERSION);
135
  }
136
  function wp_rp_settings_styles() {
137
+ wp_enqueue_style("wp_rp_dashboard_style", plugins_url("static/css/dashboard.css", __FILE__));
138
  }
139
 
140
  function wp_rp_register_blog($account_type='other') {
141
  $meta = wp_rp_get_meta();
142
 
143
+ if($meta['blog_id']) return true;
144
  $req_options = array(
145
  'timeout' => 30
146
  );
226
  add_action('wp_ajax_rp_show_hide_statistics', 'wp_rp_ajax_hide_show_statistics');
227
 
228
  function wp_rp_settings_page() {
 
 
229
  $options = wp_rp_get_options();
230
  $meta = wp_rp_get_meta();
231
 
234
  // load notifications every time user goes to settings page
235
  wp_rp_load_remote_notifications();
236
 
237
+ if(sizeof($_POST)) {
 
238
  $old_options = $options;
239
  $new_options = array(
240
  'on_single_post' => isset($postdata['wp_rp_on_single_post']),
 
 
 
 
241
  'max_related_posts' => (isset($postdata['wp_rp_max_related_posts']) && is_numeric(trim($postdata['wp_rp_max_related_posts']))) ? intval(trim($postdata['wp_rp_max_related_posts'])) : 5,
242
  'on_rss' => isset($postdata['wp_rp_on_rss']),
 
 
 
243
  'related_posts_title' => isset($postdata['wp_rp_related_posts_title']) ? trim($postdata['wp_rp_related_posts_title']) : '',
 
 
 
244
  'ctr_dashboard_enabled' => isset($postdata['wp_rp_ctr_dashboard_enabled']),
245
  'promoted_content_enabled' => isset($postdata['wp_rp_promoted_content_enabled']),
246
  'enable_themes' => isset($postdata['wp_rp_enable_themes']),
 
247
  'traffic_exchange_enabled' => isset($postdata['wp_rp_traffic_exchange_enabled']),
248
+ 'max_related_post_age_in_days' => (isset($postdata['wp_rp_max_related_post_age_in_days']) && is_numeric(trim($postdata['wp_rp_max_related_post_age_in_days']))) ? intval(trim($postdata['wp_rp_max_related_post_age_in_days'])) : 0,
249
+
250
+ 'thumbnail_use_custom' => isset($postdata['wp_rp_thumbnail_use_custom']) && $postdata['wp_rp_thumbnail_use_custom'] === 'yes',
251
+ 'thumbnail_custom_field' => isset($postdata['wp_rp_thumbnail_custom_field']) ? trim($postdata['wp_rp_thumbnail_custom_field']) : '',
252
+ 'display_zemanta_linky' => $meta['show_zemanta_linky_option'] ? isset($postdata['wp_rp_display_zemanta_linky']) : true,
253
+
254
+ 'mobile' => array(
255
+ 'display_comment_count' => isset($postdata['wp_rp_mobile_display_comment_count']),
256
+ 'display_publish_date' => isset($postdata['wp_rp_mobile_display_publish_date']),
257
+ 'display_excerpt' => isset($postdata['wp_rp_mobile_display_excerpt']),
258
+ 'display_thumbnail' => isset($postdata['wp_rp_mobile_display_thumbnail']),
259
+ 'excerpt_max_length' => (isset($postdata['wp_rp_mobile_excerpt_max_length']) && is_numeric(trim($postdata['wp_rp_mobile_excerpt_max_length']))) ? intval(trim($postdata['wp_rp_mobile_excerpt_max_length'])) : 200,
260
+ 'custom_theme_enabled' => isset($postdata['wp_rp_mobile_custom_theme_enabled']),
261
+ ),
262
+ 'desktop' => array(
263
+ 'display_comment_count' => isset($postdata['wp_rp_desktop_display_comment_count']),
264
+ 'display_publish_date' => isset($postdata['wp_rp_desktop_display_publish_date']),
265
+ 'display_excerpt' => isset($postdata['wp_rp_desktop_display_excerpt']),
266
+ 'display_thumbnail' => isset($postdata['wp_rp_desktop_display_thumbnail']),
267
+ 'excerpt_max_length' => (isset($postdata['wp_rp_desktop_excerpt_max_length']) && is_numeric(trim($postdata['wp_rp_desktop_excerpt_max_length']))) ? intval(trim($postdata['wp_rp_desktop_excerpt_max_length'])) : 200,
268
+ 'custom_theme_enabled' => isset($postdata['wp_rp_desktop_custom_theme_enabled']),
269
+ )
270
  );
271
 
272
  if(!isset($postdata['wp_rp_exclude_categories'])) {
277
  $new_options['exclude_categories'] = trim($postdata['wp_rp_exclude_categories']);
278
  }
279
 
280
+ foreach(array('mobile', 'desktop') as $platform) {
281
+ if(isset($postdata['wp_rp_' . $platform . '_theme_name'])) { // If this isn't set, maybe the AJAX didn't load...
282
+ $new_options[$platform]['theme_name'] = trim($postdata['wp_rp_' . $platform . '_theme_name']);
 
283
 
284
+ if(isset($postdata['wp_rp_' . $platform . '_theme_custom_css'])) {
285
+ $new_options[$platform]['theme_custom_css'] = $postdata['wp_rp_' . $platform . '_theme_custom_css'];
286
+ } else {
287
+ $new_options[$platform]['theme_custom_css'] = '';
288
+ }
289
  } else {
290
+ $new_options[$platform]['theme_name'] = $old_options[$platform]['theme_name'];
291
+ $new_options[$platform]['theme_custom_css'] = $old_options[$platform]['theme_custom_css'];
292
  }
 
 
 
293
  }
294
 
295
  if (isset($postdata['wp_rp_turn_on_button_pressed'])) {
296
+ $meta['show_turn_on_button'] = false;
297
  $meta['turn_on_button_pressed'] = $postdata['wp_rp_turn_on_button_pressed'];
298
+ $new_options['mobile']['display_thumbnail'] = true;
299
+ $new_options['desktop']['display_thumbnail'] = true;
300
  }
301
 
302
+ $preprocess_thumbnails = ($new_options['desktop']['display_thumbnail'] && !$old_options['desktop']['display_thumbnail']) || ($new_options['mobile']['display_thumbnail'] && !$old_options['mobile']['display_thumbnail']);
303
+
304
+
305
  $default_thumbnail_path = wp_rp_upload_default_thumbnail_file();
306
 
307
  if($default_thumbnail_path === false) { // no file uploaded
321
  if($new_options['ctr_dashboard_enabled'] && !$old_options['ctr_dashboard_enabled']) {
322
  $meta['show_statistics'] = true;
323
 
324
+ if($new_options['desktop']['display_thumbnail'] || $new_options['mobile']['display_thumbnail']) {
325
  $meta['show_turn_on_button'] = false;
326
  }
327
 
351
  ?>
352
 
353
  <div class="wrap" id="wp_rp_wrap">
 
 
 
 
 
 
 
 
354
  <input type="hidden" id="wp_rp_json_url" value="<?php esc_attr_e(WP_RP_STATIC_BASE_URL . WP_RP_STATIC_JSON_PATH); ?>" />
355
  <input type="hidden" id="wp_rp_version" value="<?php esc_attr_e(WP_RP_VERSION); ?>" />
 
356
  <input type="hidden" id="wp_rp_dashboard_url" value="<?php esc_attr_e(WP_RP_CTR_DASHBOARD_URL); ?>" />
357
  <input type="hidden" id="wp_rp_static_base_url" value="<?php esc_attr_e(WP_RP_STATIC_BASE_URL); ?>" />
358
 
382
 
383
  <?php if($meta['show_turn_on_button']): ?>
384
  <div id="wp_rp_turn_on_statistics">
385
+ <?php
386
+ if (!isset($meta['blog_tg'])) {
387
+ // TODO remove this after a proper migration
388
+ $meta['blog_tg'] = rand(0, 1);
389
+ }
390
+ if ($meta['blog_tg'] == 1):
391
+ ?>
392
+ <div class="turn_on_wrap">
393
+ <h4>Turn on Related Posts and start using awesome features.</h4>
394
+ <div class="button_wrap">
395
+ <a data-type="singlebutton" href="#" class="zemanta-button turn-on">Turn on Related Posts</a>
396
+ </div>
397
+ <p>You'll get Settings, Themes, Thumbnails, Reader Exchange and Promoted Content.</p>
398
+ <p>These features are provided by <a target="_blank" href="http://www.zemanta.com">Zemanta</a> as a service.</p>
399
+ </div>
400
+ <img class="screendesc" src="<?php echo plugins_url("static/img/turnonscreen.jpg", __FILE__); ?>" />
401
+ <?php else: ?>
402
  <ul>
403
  <li>
404
  <div>
405
  <ul>
406
+ <li class="title"><h3>Publisher</h3></li>
407
  <li>Related Posts</li>
408
  <li>Settings</li>
409
  <li>Analytics</li>
410
+ <li>Increase pageviews<br />(traffic exchange)</li>
411
+ <li>Earn money<br />(promoted posts)</li>
412
+ <li class="turn-on-wrap"><a data-type="types-publisher" href="#" class="zemanta-button turn-on">Turn on</a></li>
413
  </ul>
414
  </div>
415
  </li>
421
  <li>Settings</li>
422
  <li>Analytics</li>
423
  <li>Increase pageviews<br />(traffic exchange)</li>
424
+ <li class="turn-on-wrap"><a data-type="types-advanced" href="#" class="zemanta-button turn-on">Turn on</a></li>
425
  </ul>
426
  </div>
427
  </li>
428
  <li>
429
  <div>
430
  <ul>
431
+ <li class="title"><h3>Basic</h3></li>
432
  <li>Related Posts</li>
433
  <li>Settings</li>
434
  <li>Analytics</li>
435
+ <li class="turn-on-wrap"><a data-type="types-basic" href="#" class="zemanta-button turn-on">Turn on</a></li>
 
 
436
  </ul>
437
  </div>
438
  </li>
439
  </ul>
440
+ <p>Analytics, traffic exchange and promoted posts are provided by <a target="_blank" href="http://www.zemanta.com">Zemanta</a> as a service.</p>
441
+ <?php endif; ?>
442
  </div>
443
  <?php endif; ?>
444
 
566
  </select> &nbsp;months.
567
  </label></td>
568
  </tr>
569
+ </table><?php
570
+
571
+ /**************************************
572
+ * Theme Settings *
573
+ **************************************/
574
 
575
+ ?>
576
  <h3>Theme Settings</h3>
577
+ <label>
578
+ <input name="wp_rp_enable_themes" type="checkbox" id="wp_rp_enable_themes" value="yes"<?php checked($options["enable_themes"]); ?> />
579
+ <?php _e("Enable Themes",'wp_related_posts'); ?>*
580
+ </label>
581
+
582
+ <div id="wp_rp_theme_options_wrap" style="display:none;">
583
+ <?php foreach(array('desktop' => 'Desktop/Tablet', 'mobile' => 'Mobile Phones') as $platform => $platform_title): ?>
584
+ <input type="hidden" id="wp_rp_<?php echo $platform; ?>_theme_selected" value="<?php esc_attr_e($options[$platform]['theme_name']); ?>" />
585
+ <table class="form-table wp_rp_settings_table">
586
+ <tr id="wp_rp_<?php echo $platform; ?>_theme_options_wrap">
587
+ <td>
588
+ <h4><?php _e($platform_title, 'wp_related_posts'); ?></h4>
589
+ <div id="wp_rp_<?php echo $platform; ?>_theme_area" style="display: none;">
590
+ <div class="theme-list"></div>
591
+ <div class="theme-screenshot"></div>
592
+ <div class="theme-extra-options">
593
+ <label class="wp_rp_settings_button">
594
+ <input type="checkbox" id="wp_rp_<?php echo $platform; ?>_custom_theme_enabled" name="wp_rp_<?php echo $platform; ?>_custom_theme_enabled" value="yes" <?php checked($options[$platform]['custom_theme_enabled']); ?> />
595
+ Customize
596
+ </label>
597
+ </div>
598
  </div>
599
+ </td>
600
+ </tr>
601
+ <tr id="wp_rp_<?php echo $platform; ?>_theme_custom_css_wrap" style="display: none; ">
602
+ <td>
603
+ <label>
604
+ <input name="wp_rp_<?php echo $platform; ?>_display_thumbnail" type="checkbox" id="wp_rp_<?php echo $platform; ?>_display_thumbnail" value="yes" <?php checked($options[$platform]["display_thumbnail"]); ?> onclick="wp_rp_display_thumbnail_onclick();" />
605
+ <?php _e("Display Thumbnails For Related Posts",'wp_related_posts');?>
606
+ </label><br />
607
+ <label>
608
+ <input name="wp_rp_<?php echo $platform; ?>_display_comment_count" type="checkbox" id="wp_rp_<?php echo $platform; ?>_display_comment_count" value="yes" <?php checked($options[$platform]["display_comment_count"]); ?>>
609
+ <?php _e("Display Number of Comments",'wp_related_posts');?>
610
+ </label><br />
611
+ <label>
612
+ <input name="wp_rp_<?php echo $platform; ?>_display_publish_date" type="checkbox" id="wp_rp_<?php echo $platform; ?>_display_publish_date" value="yes" <?php checked($options[$platform]["display_publish_date"]); ?>>
613
+ <?php _e("Display Publish Date",'wp_related_posts');?>
614
+ </label><br />
615
+ <label>
616
+ <input name="wp_rp_<?php echo $platform; ?>_display_excerpt" type="checkbox" id="wp_rp_<?php echo $platform; ?>_display_excerpt" value="yes" <?php checked($options[$platform]["display_excerpt"]); ?> onclick="wp_rp_display_excerpt_onclick();" >
617
+ <?php _e("Display Post Excerpt",'wp_related_posts');?>
618
+ </label>
619
+ <label id="wp_rp_<?php echo $platform; ?>_excerpt_max_length_label">
620
+ <input name="wp_rp_<?php echo $platform; ?>_excerpt_max_length" type="text" id="wp_rp_<?php echo $platform; ?>_excerpt_max_length" class="small-text" value="<?php esc_attr_e($options[$platform]["excerpt_max_length"]); ?>" /> <span class="description"><?php _e('Maximum Number of Characters.', 'wp_related_posts'); ?></span>
621
+ </label>
622
+ <br/>
623
+ <h4>Custom CSS</h4>
624
+ <textarea style="width: 300px; height: 215px; background: #EEE;" name="wp_rp_<?php echo $platform; ?>_theme_custom_css" class="custom-css"><?php echo htmlspecialchars($options[$platform]['theme_custom_css'], ENT_QUOTES); ?></textarea>
625
+ </td>
626
+ </tr>
627
+ <tr>
628
+ <td>
629
+
630
+ </td>
631
+ </tr>
632
+ </table>
633
+ <?php endforeach; ?>
634
+ </div><?php
635
+
636
+ /**************************************
637
+ * Thumbnail Settings *
638
+ **************************************/
 
 
 
 
 
 
 
 
 
 
639
 
640
+ ?>
641
+ <table class="form-table">
642
+ <tbody>
643
+ <tr valign="top">
644
+ <td>
645
+ <label>
646
+ <?php _e('For posts without images, a default image will be shown.<br/>
647
+ You can upload your own default image here','wp_related_posts');?>
648
+ <input type="file" name="wp_rp_default_thumbnail" />
649
+ </label>
650
+ <?php if($options['default_thumbnail_path']) : ?>
651
+ <span style="display: inline-block; vertical-align: top; *display: inline; zoom: 1;">
652
+ <img style="padding: 3px; border: 1px solid #DFDFDF; border-radius: 3px;" valign="top" width="80" height="80" src="<?php esc_attr_e(wp_rp_get_default_thumbnail_url()); ?>" alt="selected thumbnail" />
653
+ <br />
654
+ <label>
655
+ <input type="checkbox" name="wp_rp_default_thumbnail_remove" value="yes" />
656
+ <?php _e("Remove selected",'wp_related_posts');?>
657
+ </label>
658
+ </span>
659
+ <?php endif; ?>
660
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
661
  <?php
662
+ global $wpdb;
663
+
664
+ $custom_fields = $wpdb->get_col( "SELECT meta_key FROM $wpdb->postmeta GROUP BY meta_key HAVING meta_key NOT LIKE '\_%' ORDER BY LOWER(meta_key)" );
665
+ if($custom_fields) :
666
  ?>
667
+ <br />
668
+ <br />
669
+ <label><input name="wp_rp_thumbnail_use_custom" type="checkbox" value="yes" <?php checked($options['thumbnail_use_custom']); ?>> Use custom field for thumbnails</label>
670
+ <select name="wp_rp_thumbnail_custom_field" id="wp_rp_thumbnail_custom_field" class="postform">
671
+
672
+ <?php foreach ( $custom_fields as $custom_field ) : ?>
673
+ <option value="<?php esc_attr_e($custom_field); ?>"<?php selected($options["thumbnail_custom_field"], $custom_field); ?>><?php esc_html_e($custom_field);?></option>
674
  <?php endforeach; ?>
675
  </select>
676
+ <br />
677
+ <?php endif; ?>
678
+ </td>
679
+ </tr>
680
+ </tbody>
681
+ </table><?php
682
+
683
+ /**************************************
684
+ * Other Settings *
685
+ **************************************/
686
+
687
+ ?>
688
  <h3><?php _e("Other Settings:",'wp_related_posts'); ?></h3>
689
  <table class="form-table">
690
  <tr valign="top">
712
  </tr>
713
  <tr valign="top">
714
  <td colspan="2">
715
+
716
+ <br/>
717
  <label>
718
  <input name="wp_rp_on_single_post" type="checkbox" id="wp_rp_on_single_post" value="yes" <?php checked($options['on_single_post']); ?>>
719
  <?php _e("Auto Insert Related Posts",'wp_related_posts');?>
736
  <input name="wp_rp_ctr_dashboard_enabled" type="checkbox" id="wp_rp_ctr_dashboard_enabled" value="yes" <?php checked($options['ctr_dashboard_enabled']); ?> />
737
  <?php _e("Turn statistics on",'wp_related_posts');?>*
738
  </label>
739
+ <?php if($meta['remote_recommendations']): ?>
740
  <br />
741
  <label>
742
  <input name="wp_rp_promoted_content_enabled" type="checkbox" id="wp_rp_promoted_content_enabled" value="yes" <?php checked($options['promoted_content_enabled']); ?> />
743
  <?php _e('Promoted Content', 'wp_related_posts');?>*
744
  </label>
745
+ <?php endif; ?>
746
+ <?php if($meta['show_zemanta_linky_option']): ?>
747
+ <br />
748
+ <label>
749
+ <input name="wp_rp_display_zemanta_linky" type="checkbox" id="wp_rp_display_zemanta_linky" value="yes" <?php checked($options['display_zemanta_linky']); ?> />
750
+ <?php _e("Support us (show our logo)",'wp_related_posts');?>
751
+ </label>
752
  </td>
753
+ <?php endif; ?>
754
  </tr>
755
  </table>
756
  <p class="submit"><input type="submit" value="<?php _e('Save changes', 'wp_related_posts'); ?>" class="button-primary" /></p>
757
 
758
  </div>
759
  </div>
 
 
 
760
  </form>
761
  </div>
762
  <?php }
static/css/dashboard.css CHANGED
@@ -7,6 +7,8 @@
7
  #wp_rp_wrap div.header div.support p {margin: 0; font-size: 11px;}
8
  #wp_rp_wrap div.header div.support p a {color: #82c1cb; font-weight: bold; text-decoration: none;}
9
 
 
 
10
 
11
  #wp_rp_wrap div#wp_rp_statistics_wrap {position: relative; overflow: hidden;}
12
  #wp_rp_wrap div#wp_rp_statistics_holder {overflow: hidden;}
@@ -73,7 +75,16 @@
73
  #wp_rp_invite_friends_form img.down { display: none; }
74
  #wp_rp_invite_friends_form.up img.down { display: block; }
75
 
76
- #wp_rp_turn_on_statistics {}
 
 
 
 
 
 
 
 
 
77
  #wp_rp_turn_on_statistics > ul {margin: 0 0 10px 0;}
78
  #wp_rp_turn_on_statistics > ul > li {display: inline-block; margin-right: 10px; vertical-align: top; text-align: center;}
79
  #wp_rp_turn_on_statistics > ul > li {text-decoration: none; font-size: 12px;}
@@ -88,7 +99,6 @@
88
  #wp_rp_turn_on_statistics > ul > li > div .zemanta-button {font-size: 16px;text-shadow: 1px 1px #555;padding: 7px 15px;background-color: #999;-moz-border-radius: 15px;-webkit-border-radius: 15px;border-radius: 15px;border: 1px solid #999;display: inline-block;color: #fff;text-decoration: none;cursor: pointer;}
89
  #wp_rp_turn_on_statistics > ul > li > div:hover .zemanta-button {font-size: 16px;text-shadow: 1px 1px #a05515;padding: 7px 15px;-moz-box-shadow: inset 0 1px 0 0 #ffaf65;-webkit-box-shadow: inset 0 1px 0 0 #ffaf65;box-shadow: inset 0 1px 0 0 #ffaf65;background: -webkit-gradient(linear,left top,left bottom,color-stop(0.05,#f79124),color-stop(1,#f57b1e));background: -moz-linear-gradient(center top,#f79124 5%,#f57b1e 100%);filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f79124', endColorstr='#f57b1e');background-color: #f79124;-moz-border-radius: 15px;-webkit-border-radius: 15px;border-radius: 15px;border: 1px solid #e77001;display: inline-block;color: #fff;text-decoration: none;cursor: pointer;}
90
 
91
-
92
  form.wp_rp_message_form { background: #f7f7f7; padding: 20px; margin: 30px 0px; border: 1px solid #e1e1e1; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }
93
  form.wp_rp_message_form p {font-size: 14px;}
94
  form.wp_rp_message_form h2 { font-size: 19px; line-height: 20px; padding-top: 0px; }
@@ -116,12 +126,23 @@ form.wp_rp_message_form a.dismiss {float: right;}
116
  #wp_rp_wrap .collapsible.collapsed .collapse-handle {background-image: url('../img/down.jpg');}
117
  #wp_rp_wrap .collapsible .collapse-handle:after {clear:both;overflow:hidden;height:0;}
118
 
 
 
 
 
119
  #wp_rp_theme_options_wrap .theme-list {margin: 5px 0; width: 150px; float: left;}
120
- #wp_rp_theme_options_wrap .theme-screenshot img {width: 448px; margin-top: -30px;}
121
- #wp_rp_theme_options_wrap .theme-screenshot {height: 170px;}
122
  #wp_rp_theme_options_wrap .theme-extra-options {clear: left;}
123
  #wp_rp_theme_options_wrap .custom-theme {clear: both;}
124
 
 
 
 
 
 
 
 
125
  #wp_rp_theme_custom_css_wrap td {margin: 0; padding-top: 0;}
126
  #wp_rp_theme_custom_css_wrap .notice {margin: 0; padding: 0 0 3px 0; color: #666;}
127
 
7
  #wp_rp_wrap div.header div.support p {margin: 0; font-size: 11px;}
8
  #wp_rp_wrap div.header div.support p a {color: #82c1cb; font-weight: bold; text-decoration: none;}
9
 
10
+ #wp_rp_settings_form th,
11
+ #wp_rp_settings_form td {padding-left: 0;}
12
 
13
  #wp_rp_wrap div#wp_rp_statistics_wrap {position: relative; overflow: hidden;}
14
  #wp_rp_wrap div#wp_rp_statistics_holder {overflow: hidden;}
75
  #wp_rp_invite_friends_form img.down { display: none; }
76
  #wp_rp_invite_friends_form.up img.down { display: block; }
77
 
78
+
79
+ #wp_rp_turn_on_statistics {margin-top: 50px;}
80
+ #wp_rp_turn_on_statistics .turn_on_wrap {max-width: 790px; border: 1px solid #ddd; border-top-right-radius: 5px; border-top-left-radius: 5px; padding: 30px 0; text-align: center;}
81
+ #wp_rp_turn_on_statistics .turn_on_wrap { background: #e7f7fb; /* Old browsers */ background: -moz-linear-gradient(top, #e7f7fb 50%, #c1edef 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(50%,#e7f7fb), color-stop(100%,#c1edef)); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, #e7f7fb 50%,#c1edef 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, #e7f7fb 50%,#c1edef 100%); /* Opera 11.10+ */ background: -ms-linear-gradient(top, #e7f7fb 50%,#c1edef 100%); /* IE10+ */ background: linear-gradient(to bottom, #e7f7fb 50%,#c1edef 100%); /* W3C */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e7f7fb', endColorstr='#c1edef',GradientType=0 ); /* IE6-9 */ }
82
+ #wp_rp_turn_on_statistics h4 {font-size: 1.8em;font-weight: normal; margin: 5px 0 30px 0;}
83
+ #wp_rp_turn_on_statistics p {margin: 10px 0 0 0; font-size: 13px;}
84
+ #wp_rp_turn_on_statistics .screendesc {margin: 0;}
85
+ #wp_rp_turn_on_statistics .button_wrap {margin-bottom: 30px;}
86
+ #wp_rp_turn_on_statistics .turn_on_wrap .zemanta-button {font-size: 20px;text-shadow: 1px 1px #a05515;padding: 15px 30px;-moz-box-shadow: inset 0 1px 0 0 #ffaf65;-webkit-box-shadow: inset 0 1px 0 0 #ffaf65;box-shadow: inset 0 1px 0 0 #ffaf65;background: -webkit-gradient(linear,left top,left bottom,color-stop(0.05,#f79124),color-stop(1,#f57b1e));background: -moz-linear-gradient(center top,#f79124 5%,#f57b1e 100%);filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f79124', endColorstr='#f57b1e');background-color: #f79124;-moz-border-radius: 30px;-webkit-border-radius: 30px;border-radius: 30px;border: 1px solid #e77001;display: inline-block;color: #fff;text-decoration: none;cursor: pointer;}
87
+
88
  #wp_rp_turn_on_statistics > ul {margin: 0 0 10px 0;}
89
  #wp_rp_turn_on_statistics > ul > li {display: inline-block; margin-right: 10px; vertical-align: top; text-align: center;}
90
  #wp_rp_turn_on_statistics > ul > li {text-decoration: none; font-size: 12px;}
99
  #wp_rp_turn_on_statistics > ul > li > div .zemanta-button {font-size: 16px;text-shadow: 1px 1px #555;padding: 7px 15px;background-color: #999;-moz-border-radius: 15px;-webkit-border-radius: 15px;border-radius: 15px;border: 1px solid #999;display: inline-block;color: #fff;text-decoration: none;cursor: pointer;}
100
  #wp_rp_turn_on_statistics > ul > li > div:hover .zemanta-button {font-size: 16px;text-shadow: 1px 1px #a05515;padding: 7px 15px;-moz-box-shadow: inset 0 1px 0 0 #ffaf65;-webkit-box-shadow: inset 0 1px 0 0 #ffaf65;box-shadow: inset 0 1px 0 0 #ffaf65;background: -webkit-gradient(linear,left top,left bottom,color-stop(0.05,#f79124),color-stop(1,#f57b1e));background: -moz-linear-gradient(center top,#f79124 5%,#f57b1e 100%);filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f79124', endColorstr='#f57b1e');background-color: #f79124;-moz-border-radius: 15px;-webkit-border-radius: 15px;border-radius: 15px;border: 1px solid #e77001;display: inline-block;color: #fff;text-decoration: none;cursor: pointer;}
101
 
 
102
  form.wp_rp_message_form { background: #f7f7f7; padding: 20px; margin: 30px 0px; border: 1px solid #e1e1e1; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }
103
  form.wp_rp_message_form p {font-size: 14px;}
104
  form.wp_rp_message_form h2 { font-size: 19px; line-height: 20px; padding-top: 0px; }
126
  #wp_rp_wrap .collapsible.collapsed .collapse-handle {background-image: url('../img/down.jpg');}
127
  #wp_rp_wrap .collapsible .collapse-handle:after {clear:both;overflow:hidden;height:0;}
128
 
129
+ #wp_rp_theme_options_wrap .wp_rp_settings_button {font-size: 1.5em;padding:0 0 0 20px;background: url('../img/arrow_right.png') left center no-repeat;background-position: 3px 3px;}
130
+ #wp_rp_theme_options_wrap .wp_rp_settings_button_disabled {background: url('../img/arrow_down.png') left center no-repeat;background-position: 0px 7px;}
131
+
132
+ /* theme options */
133
  #wp_rp_theme_options_wrap .theme-list {margin: 5px 0; width: 150px; float: left;}
134
+ #wp_rp_theme_options_wrap .theme-screenshot img {width: 448px;}
135
+ #wp_rp_theme_options_wrap .theme-screenshot {height: 250px; overflow:hidden;}
136
  #wp_rp_theme_options_wrap .theme-extra-options {clear: left;}
137
  #wp_rp_theme_options_wrap .custom-theme {clear: both;}
138
 
139
+ #wp_rp_theme_options_wrap .wp_rp_settings_table {padding: 15px;border: 1px solid #CCC;width: 630px;margin-bottom: 30px;border-top: 5px solid #CCC;}
140
+ #wp_rp_theme_options_wrap .wp_rp_settings_table tbody tr td {padding: 8px 10px;}
141
+ #wp_rp_theme_options_wrap .wp_rp_settings_table tbody tr td h4 {font-size: 1.5em;font-weight: normal;}
142
+ #wp_rp_theme_options_wrap .wp_rp_settings_table tbody tr td div .theme-extra-options label {}
143
+ #wp_rp_theme_options_wrap .wp_rp_settings_table tbody tr td div .theme-extra-options label.selected {}
144
+ #wp_rp_theme_options_wrap .wp_rp_settings_table tbody tr td div .theme-extra-options label input {display: none;}
145
+
146
  #wp_rp_theme_custom_css_wrap td {margin: 0; padding-top: 0;}
147
  #wp_rp_theme_custom_css_wrap .notice {margin: 0; padding: 0 0 3px 0; color: #666;}
148
 
static/img/arrow_down.png ADDED
Binary file
static/img/arrow_right.png ADDED
Binary file
static/img/turnonscreen.jpg ADDED
Binary file
static/js/dashboard.js CHANGED
@@ -6,6 +6,5 @@ a.getJSON(j+"pageviews/?callback=?",{blog_id:h,auth_key:g},function(a){var d=a.d
6
  stats.mobile_pageviews,stats.desktop_pageviews||0);stats.desktop_clicks=Math.max(d.clicks-stats.mobile_clicks,stats.desktop_clicks||0);var e=0<stats.desktop_pageviews&&(100*(stats.desktop_clicks/stats.desktop_pageviews)).toFixed(1)||0;stats.network_in_pageviews=Math.max(d.network_in_pageviews,stats.network_in_pageviews||0);if(promoted_content_enabled&&d.promoted_content_money_earned){stats.promoted_content_money_earned=Math.max(d.promoted_content_money_earned,stats.promoted_content_money_earned||
7
  0);var l=(stats.promoted_content_money_earned/100).toFixed(2),g=(d.meta.min_payout/100).toFixed(2);b.find(".num").html("$"+l);b.find(".payout").html("$"+g);stats.promoted_content_money_earned>=d.meta.min_payout&&b.find(".claim").hasClass("disabled")&&(b.find(".claim").removeClass("disabled"),b.find(".claim").attr("href","mailto:support+claim@gmail.com?subject="+encodeURIComponent("I earned over $50!")+"&body="+encodeURIComponent("I would like to claim my money.\nMy reference code is: "+h+" \nMy PayPal account is:\n")));
8
  i.show()}ul.find(".ctr .num.all").html(e+"%");ul.find(".pageviews .num.all").html(stats.desktop_pageviews);ul.find(".clicks .num.all").html(stats.desktop_clicks);ul.find(".ctr .num.mobile").html(a+"%");ul.find(".pageviews .num.mobile").html(stats.mobile_pageviews);ul.find(".clicks .num.mobile").html(stats.mobile_clicks);f.find(".network .num").html(stats.network_in_pageviews);updating=!1}}))};h&&g&&(update_dashboard(!0),update_interval=setInterval(update_dashboard,2E3));a("#wp_rp_turn_on_statistics a.turn-on").click(function(c){c.preventDefault();
9
- a("#wp_rp_static_base_url").val();c=a(this).data("type");a("#wp_rp_ctr_dashboard_enabled, #wp_rp_display_thumbnail, #wp_rp_enable_themes, #wp_rp_promoted_content_enabled").prop("checked",!0);a("#wp_rp_settings_form").append('<input type="hidden" value="statistics+thumbnails+promoted" name="wp_rp_turn_on_button_pressed" id="wp_rp_turn_on_button_pressed">');a("#wp_rp_settings_form").append('<input type="hidden" value="'+c+'" name="wp_rp_account_type" id="wp_rp_account_type">');a("#wp_rp_settings_form").submit()});
10
- a(".wp_rp_notification .close").on("click",function(c){a.ajax({url:a(this).attr("href"),data:{noredirect:!0}});a(this).parent().slideUp(function(){a(this).remove()});c.preventDefault()});a("#wp_rp_wrap .collapsible .collapse-handle").on("click",function(c){var b=a(this).closest(".collapsible"),d=b.find(".container"),e=b.hasClass("collapsed"),f=b.attr("block");e?(d.slideDown(),a.post(ajaxurl,{action:"rp_show_hide_"+f,show:!0})):(d.slideUp(),a.post(ajaxurl,{action:"rp_show_hide_"+f,hide:!0}));b.toggleClass("collapsed");
11
- c.preventDefault()})})})(jQuery);
6
  stats.mobile_pageviews,stats.desktop_pageviews||0);stats.desktop_clicks=Math.max(d.clicks-stats.mobile_clicks,stats.desktop_clicks||0);var e=0<stats.desktop_pageviews&&(100*(stats.desktop_clicks/stats.desktop_pageviews)).toFixed(1)||0;stats.network_in_pageviews=Math.max(d.network_in_pageviews,stats.network_in_pageviews||0);if(promoted_content_enabled&&d.promoted_content_money_earned){stats.promoted_content_money_earned=Math.max(d.promoted_content_money_earned,stats.promoted_content_money_earned||
7
  0);var l=(stats.promoted_content_money_earned/100).toFixed(2),g=(d.meta.min_payout/100).toFixed(2);b.find(".num").html("$"+l);b.find(".payout").html("$"+g);stats.promoted_content_money_earned>=d.meta.min_payout&&b.find(".claim").hasClass("disabled")&&(b.find(".claim").removeClass("disabled"),b.find(".claim").attr("href","mailto:support+claim@gmail.com?subject="+encodeURIComponent("I earned over $50!")+"&body="+encodeURIComponent("I would like to claim my money.\nMy reference code is: "+h+" \nMy PayPal account is:\n")));
8
  i.show()}ul.find(".ctr .num.all").html(e+"%");ul.find(".pageviews .num.all").html(stats.desktop_pageviews);ul.find(".clicks .num.all").html(stats.desktop_clicks);ul.find(".ctr .num.mobile").html(a+"%");ul.find(".pageviews .num.mobile").html(stats.mobile_pageviews);ul.find(".clicks .num.mobile").html(stats.mobile_clicks);f.find(".network .num").html(stats.network_in_pageviews);updating=!1}}))};h&&g&&(update_dashboard(!0),update_interval=setInterval(update_dashboard,2E3));a("#wp_rp_turn_on_statistics a.turn-on").click(function(c){c.preventDefault();
9
+ a("#wp_rp_static_base_url").val();c=a(this).data("type");a("#wp_rp_ctr_dashboard_enabled, #wp_rp_enable_themes, #wp_rp_promoted_content_enabled").prop("checked",!0);a("#wp_rp_settings_form").append('<input type="hidden" value="statistics+thumbnails+promoted" name="wp_rp_turn_on_button_pressed" id="wp_rp_turn_on_button_pressed">');a("#wp_rp_settings_form").append('<input type="hidden" value="'+c+'" name="wp_rp_account_type" id="wp_rp_account_type">');a("#wp_rp_settings_form").submit()});a(".wp_rp_notification .close").on("click",
10
+ function(c){a.ajax({url:a(this).attr("href"),data:{noredirect:!0}});a(this).parent().slideUp(function(){a(this).remove()});c.preventDefault()});a("#wp_rp_wrap .collapsible .collapse-handle").on("click",function(c){var b=a(this).closest(".collapsible"),d=b.find(".container"),e=b.hasClass("collapsed"),f=b.attr("block");e?(d.slideDown(),a.post(ajaxurl,{action:"rp_show_hide_"+f,show:!0})):(d.slideUp(),a.post(ajaxurl,{action:"rp_show_hide_"+f,hide:!0}));b.toggleClass("collapsed");c.preventDefault()})})})(jQuery);
 
static/js/themes.js CHANGED
@@ -1,4 +1,5 @@
1
- (function(a){a(function(){var e=a("#wp_rp_theme_options_wrap"),h=e.find("#wp_rp_theme_area"),l=a("#wp_rp_static_base_url").val(),m=a("#wp_rp_json_url").val(),n=a("#wp_rp_version").val(),p=a("#wp_rp_theme_selected").val(),i=null,j=function(){var a=document.createElement("script"),b=document.getElementsByTagName("body").item(0);a.type="text/javascript";a.src=m+"themes.js?plv="+n;b.appendChild(a)},k=function(){var d=a("#wp_rp_custom_theme_enabled:checked"),b=a("#wp_rp_theme_custom_css_wrap");d.length?
2
- b.show():b.hide()};k();a("#wp_rp_custom_theme_enabled").on("change",function(){k()});window.wp_rp_themes_cb=function(d){if(d&&d.themes&&(i=d.themes)){var b=e.find("div.theme-list"),f=e.find("div.theme-screenshot"),g=function(b){if("plain.css"==b.val())f.html("");else{var b=l+"img/themes/"+b.val().replace(/\.css$/,".jpg"),c=f.find("img");if(c.length){if(c.attr("src")===b)return}else c=a("<img />"),f.html(c);c.attr("src",b)}};b.empty();a.each(i,function(a,c){"custom.css"!=c.location&&b.append('<label class="theme-label"><input '+
3
- (c.location===p?'checked="checked"':"")+' class="theme-option" type="radio" name="wp_rp_theme_name" value="'+c.location+'" /> '+c.name+"</label><br />")});b.on("hover","label.theme-label",function(){g(a("input",this))});b.on("mouseleave",function(){g(b.find("input:checked"))});g(b.find("input:checked"));h.show()}};a("#wp_rp_enable_themes:checked").length&&j();a("#wp_rp_enable_themes").change(function(){a("#wp_rp_enable_themes:checked").length?(j(),a("#wp_rp_theme_custom_css_wrap").css({display:a("#wp_rp_custom_theme_enabled:checked").length?
4
- "table-row":"none"})):(a("#wp_rp_theme_options_wrap div.theme-list").empty(),a("#wp_rp_theme_custom_css_wrap").hide(),h.hide())})})})(jQuery);
 
1
+ (function(a){a(function(){var i={mobile:{wrap:a("#wp_rp_mobile_theme_options_wrap"),theme_area:a("#wp_rp_mobile_theme_area"),current_theme:a("#wp_rp_mobile_theme_selected").val()},desktop:{wrap:a("#wp_rp_desktop_theme_options_wrap"),theme_area:a("#wp_rp_desktop_theme_area"),current_theme:a("#wp_rp_desktop_theme_selected").val()}},k=a("#wp_rp_static_base_url").val(),l=a("#wp_rp_json_url").val(),m=a("#wp_rp_version").val(),j=null,d=!1;append_get_themes_script=function(){if(d)window.wp_rp_themes_cb();
2
+ else{var a=document.createElement("script"),g=document.getElementsByTagName("body").item(0);a.type="text/javascript";a.src=l+"themes2.js?plv="+m;g.appendChild(a)}};update_custom_css_area=function(b){var g=a("#wp_rp_"+b+"_custom_theme_enabled:checked"),e=a("#wp_rp_"+b+"_theme_custom_css_wrap");g.length?(e.show(),g.closest("label").addClass("wp_rp_settings_button_disabled")):(e.hide(),a("#wp_rp_"+b+"_custom_theme_enabled").closest("label").removeClass("wp_rp_settings_button_disabled"))};a.each(i,function(b){update_custom_css_area(b);
3
+ a("#wp_rp_"+b+"_custom_theme_enabled").on("change",function(){update_custom_css_area(b)})});window.wp_rp_themes_cb=function(b){if(b&&b.themes&&(j=b.themes))d=!0,a.each(i,function(b,e){var f=e.wrap.find("div.theme-list"),d=e.wrap.find("div.theme-screenshot"),h=function(b){if(b.val()){var b=k+"img/rp-themes/"+b.val().replace(/\.css$/,".jpg"),c=d.find("img");if(c.length){if(c.attr("src")===b)return}else c=a("<img />"),d.html(c);c.attr("src",b)}else d.html("")};f.empty();a.each(j[b],function(a,c){"custom.css"!=
4
+ c.location&&f.append('<label class="theme-label"><input '+(c.location===e.current_theme?'checked="checked"':"")+' class="theme-option" type="radio" name="wp_rp_'+b+'_theme_name" value="'+c.location+'" /> '+c.name+"</label><br />")});f.on("hover","label.theme-label",function(){h(a("input",this))});f.on("mouseleave",function(){h(f.find("input:checked"))});h(f.find("input:checked"));e.theme_area.show()});d&&a("#wp_rp_theme_options_wrap").show()};a("#wp_rp_enable_themes:checked").length&&append_get_themes_script();
5
+ a("#wp_rp_enable_themes").change(function(){a("#wp_rp_enable_themes:checked").length?append_get_themes_script():a("#wp_rp_theme_options_wrap").hide()})})})(jQuery);
static/settings.js.php DELETED
@@ -1,20 +0,0 @@
1
- <script type="text/javascript">
2
- function wp_rp_display_excerpt_onclick(){
3
- var wp_rp_display_excerpt = document.getElementById('wp_rp_display_excerpt');
4
- var wp_rp_excerpt_max_length_label = document.getElementById('wp_rp_excerpt_max_length_label');
5
- if(wp_rp_display_excerpt.checked){
6
- wp_rp_excerpt_max_length_label.style.display = '';
7
- } else {
8
- wp_rp_excerpt_max_length_label.style.display = 'none';
9
- }
10
- }
11
- function wp_rp_display_thumbnail_onclick(){
12
- var wp_rp_display_thumbnail = document.getElementById('wp_rp_display_thumbnail');
13
- var wp_rp_thumbnail_span = document.getElementById('wp_rp_thumbnail_span');
14
- if(wp_rp_display_thumbnail.checked){
15
- wp_rp_thumbnail_span.style.display = '';
16
- } else {
17
- wp_rp_thumbnail_span.style.display = 'none';
18
- }
19
- }
20
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
thumbnailer.php CHANGED
@@ -37,7 +37,7 @@ function wp_rp_upload_default_thumbnail_file() {
37
  return false;
38
  }
39
 
40
- function wp_rp_get_default_thumbnail_url($seed = false) {
41
  $options = wp_rp_get_options();
42
  $upload_dir = wp_upload_dir();
43
 
@@ -56,7 +56,7 @@ function wp_rp_get_default_thumbnail_url($seed = false) {
56
  }
57
  }
58
 
59
- function wp_rp_extract_post_image($post_id) {
60
  // We don't have an image stored for this post yet - find the first uploaded image and save it
61
  $args = array(
62
  'post_type' => 'attachment',
@@ -71,7 +71,7 @@ function wp_rp_extract_post_image($post_id) {
71
  $image_id = '-1';
72
  if ( $attachments ) {
73
  foreach ( $attachments as $attachment ) {
74
- $img = wp_get_attachment_image($attachment->ID, 'thumbnail');
75
  if($img) {
76
  $image_id = $attachment->ID;
77
  break;
@@ -90,16 +90,16 @@ function wp_rp_actually_extract_images_from_post_html($post) {
90
  preg_match_all('/<img (?:[^>]+ )?src="([^"]+)"/', $content, $matches);
91
  $urls = $matches[1];
92
 
93
- $img_url = false;
94
 
95
  if(count($urls) == 0) {
96
- return $img_url;
97
  }
98
  array_splice($urls, 10);
99
 
100
  $upload_dir = wp_upload_dir();
101
  if($upload_dir['error'] !== false) {
102
- return $img_url;
103
  }
104
  require_once(ABSPATH . 'wp-admin/includes/file.php');
105
 
@@ -142,30 +142,38 @@ function wp_rp_actually_extract_images_from_post_html($post) {
142
  continue;
143
  }
144
 
145
- $img_url = $upload_dir['url'] . '/' . urlencode(wp_basename($resized_img_path));
 
 
 
 
 
 
146
 
147
  break;
148
  }
149
 
150
  remove_filter('filesystem_method', 'wp_rp_direct_filesystem_method');
151
-
152
- return $img_url;
153
  }
154
 
155
  function wp_rp_cron_do_extract_images_from_post_html($post_id) {
156
  $post_id = (int) $post_id;
157
  $post = get_post($post_id);
158
 
159
- $img_url = wp_rp_actually_extract_images_from_post_html($post);
160
 
161
- if($img_url) {
162
- update_post_meta($post_id, '_wp_rp_extracted_image_url', $img_url);
 
163
  }
164
  }
165
  add_action('wp_rp_cron_extract_images_from_post_html', 'wp_rp_cron_do_extract_images_from_post_html');
166
 
167
  function wp_rp_extract_images_from_post_html($post) {
168
  update_post_meta($post->ID, '_wp_rp_extracted_image_url', '');
 
169
  if(empty($post->post_content)) { return; }
170
 
171
  wp_schedule_single_event(time(), 'wp_rp_cron_extract_images_from_post_html', array($post->ID));
@@ -179,18 +187,25 @@ function wp_rp_post_save_update_image($post_id) {
179
  }
180
 
181
  delete_post_meta($post->ID, '_wp_rp_extracted_image_url');
 
182
 
183
  wp_rp_get_post_thumbnail_img($post);
184
  }
185
  add_action('save_post', 'wp_rp_post_save_update_image');
186
 
187
 
188
- function wp_rp_get_post_thumbnail_img($related_post) {
189
  $options = wp_rp_get_options();
190
- if (!$options["display_thumbnail"]) {
 
 
191
  return false;
192
  }
193
 
 
 
 
 
194
  if ($options['thumbnail_use_custom']) {
195
  $thumbnail_src = get_post_meta($related_post->ID, $options["thumbnail_custom_field"], true);
196
 
@@ -198,35 +213,39 @@ function wp_rp_get_post_thumbnail_img($related_post) {
198
  $img = '<img src="' . esc_attr($thumbnail_src) . '" alt="' . esc_attr(wptexturize($related_post->post_title)) . '" />';
199
  return $img;
200
  }
201
- } else if (has_post_thumbnail($related_post->ID)) {
 
 
202
  $attr = array(
203
  'alt' => esc_attr(wptexturize($related_post->post_title)),
204
  'title' => false
205
  );
206
- $img = get_the_post_thumbnail($related_post->ID, 'thumbnail', $attr);
207
  return $img;
208
  }
209
 
210
- if($options["thumbnail_use_attached"]) {
 
 
211
  $image_url = get_post_meta($related_post->ID, '_wp_rp_extracted_image_url', false);
 
212
 
213
- if(!empty($image_url) && ($image_url[0] != '')) {
214
- $img = '<img src="' . esc_attr($image_url[0]) . '" alt="' . esc_attr(wptexturize($related_post->post_title)) . '" />';
215
- return $img;
216
- }
217
 
218
- $image_id = wp_rp_extract_post_image($related_post->ID);
219
- if ($image_id !== '-1') {
220
- $img = wp_get_attachment_image($image_id, 'thumbnail');
221
- return $img;
222
- }
223
 
224
- if(empty($image_url)) {
225
- wp_rp_extract_images_from_post_html($related_post);
226
- }
227
  }
228
 
229
- $img = '<img src="'. esc_attr(wp_rp_get_default_thumbnail_url($related_post->ID)) . '" alt="' . esc_attr(wptexturize($related_post->post_title)) . '" />';
230
  return $img;
231
  }
232
 
37
  return false;
38
  }
39
 
40
+ function wp_rp_get_default_thumbnail_url($seed = false, $size = 'thumbnail') {
41
  $options = wp_rp_get_options();
42
  $upload_dir = wp_upload_dir();
43
 
56
  }
57
  }
58
 
59
+ function wp_rp_extract_post_image($post_id, $size = 'thumbnail') {
60
  // We don't have an image stored for this post yet - find the first uploaded image and save it
61
  $args = array(
62
  'post_type' => 'attachment',
71
  $image_id = '-1';
72
  if ( $attachments ) {
73
  foreach ( $attachments as $attachment ) {
74
+ $img = wp_get_attachment_image($attachment->ID, $size);
75
  if($img) {
76
  $image_id = $attachment->ID;
77
  break;
90
  preg_match_all('/<img (?:[^>]+ )?src="([^"]+)"/', $content, $matches);
91
  $urls = $matches[1];
92
 
93
+ $imgs = false;
94
 
95
  if(count($urls) == 0) {
96
+ return $imgs;
97
  }
98
  array_splice($urls, 10);
99
 
100
  $upload_dir = wp_upload_dir();
101
  if($upload_dir['error'] !== false) {
102
+ return $imgs;
103
  }
104
  require_once(ABSPATH . 'wp-admin/includes/file.php');
105
 
142
  continue;
143
  }
144
 
145
+ $thumbnail_img_url = $upload_dir['url'] . '/' . urlencode(wp_basename($resized_img_path));
146
+ $full_img_url = $upload_dir['url'] . '/' . urlencode(wp_basename($img_path));
147
+
148
+ $imgs = array(
149
+ 'thumbnail' => $thumbnail_img_url,
150
+ 'full' => $full_img_url
151
+ );
152
 
153
  break;
154
  }
155
 
156
  remove_filter('filesystem_method', 'wp_rp_direct_filesystem_method');
157
+
158
+ return $imgs;
159
  }
160
 
161
  function wp_rp_cron_do_extract_images_from_post_html($post_id) {
162
  $post_id = (int) $post_id;
163
  $post = get_post($post_id);
164
 
165
+ $imgs = wp_rp_actually_extract_images_from_post_html($post);
166
 
167
+ if($imgs) {
168
+ update_post_meta($post_id, '_wp_rp_extracted_image_url', $imgs['thumbnail']);
169
+ update_post_meta($post_id, '_wp_rp_extracted_image_url_full', $imgs['full']);
170
  }
171
  }
172
  add_action('wp_rp_cron_extract_images_from_post_html', 'wp_rp_cron_do_extract_images_from_post_html');
173
 
174
  function wp_rp_extract_images_from_post_html($post) {
175
  update_post_meta($post->ID, '_wp_rp_extracted_image_url', '');
176
+ update_post_meta($post->ID, '_wp_rp_extracted_image_url_full', '');
177
  if(empty($post->post_content)) { return; }
178
 
179
  wp_schedule_single_event(time(), 'wp_rp_cron_extract_images_from_post_html', array($post->ID));
187
  }
188
 
189
  delete_post_meta($post->ID, '_wp_rp_extracted_image_url');
190
+ delete_post_meta($post->ID, '_wp_rp_extracted_image_url_full');
191
 
192
  wp_rp_get_post_thumbnail_img($post);
193
  }
194
  add_action('save_post', 'wp_rp_post_save_update_image');
195
 
196
 
197
+ function wp_rp_get_post_thumbnail_img($related_post, $size = 'thumbnail', $force = false) {
198
  $options = wp_rp_get_options();
199
+ $platform_options = wp_rp_get_platform_options();
200
+
201
+ if (!($platform_options["display_thumbnail"] || $force)) {
202
  return false;
203
  }
204
 
205
+ if (property_exists($related_post, 'thumbnail')) {
206
+ return '<img src="'. esc_attr($related_post->thumbnail) . '" alt="' . esc_attr(wptexturize($related_post->post_title)) . '" />';
207
+ }
208
+
209
  if ($options['thumbnail_use_custom']) {
210
  $thumbnail_src = get_post_meta($related_post->ID, $options["thumbnail_custom_field"], true);
211
 
213
  $img = '<img src="' . esc_attr($thumbnail_src) . '" alt="' . esc_attr(wptexturize($related_post->post_title)) . '" />';
214
  return $img;
215
  }
216
+ }
217
+
218
+ if (has_post_thumbnail($related_post->ID)) {
219
  $attr = array(
220
  'alt' => esc_attr(wptexturize($related_post->post_title)),
221
  'title' => false
222
  );
223
+ $img = get_the_post_thumbnail($related_post->ID, $size, $attr);
224
  return $img;
225
  }
226
 
227
+ if($size == 'full') {
228
+ $image_url = get_post_meta($related_post->ID, '_wp_rp_extracted_image_url_full', false);
229
+ } else {
230
  $image_url = get_post_meta($related_post->ID, '_wp_rp_extracted_image_url', false);
231
+ }
232
 
233
+ if(!empty($image_url) && ($image_url[0] != '')) {
234
+ $img = '<img src="' . esc_attr($image_url[0]) . '" alt="' . esc_attr(wptexturize($related_post->post_title)) . '" />';
235
+ return $img;
236
+ }
237
 
238
+ $image_id = wp_rp_extract_post_image($related_post->ID, $size);
239
+ if ($image_id !== '-1') {
240
+ $img = wp_get_attachment_image($image_id, $size);
241
+ return $img;
242
+ }
243
 
244
+ if(empty($image_url)) {
245
+ wp_rp_extract_images_from_post_html($related_post);
 
246
  }
247
 
248
+ $img = '<img src="'. esc_attr(wp_rp_get_default_thumbnail_url($related_post->ID, $size)) . '" alt="' . esc_attr(wptexturize($related_post->post_title)) . '" />';
249
  return $img;
250
  }
251
 
wp_related_posts.php CHANGED
@@ -1,17 +1,18 @@
1
  <?php
2
  /*
3
  Plugin Name: WordPress Related Posts
4
- Version: 2.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.
7
  Author: Zemanta Ltd.
8
  Author URI: http://www.zemanta.com
9
  */
10
 
11
- define('WP_RP_VERSION', '2.4');
12
 
13
  include_once(dirname(__FILE__) . '/config.php');
14
  include_once(dirname(__FILE__) . '/lib/stemmer.php');
 
15
 
16
  include_once(dirname(__FILE__) . '/admin_notices.php');
17
  include_once(dirname(__FILE__) . '/notifications.php');
@@ -20,6 +21,7 @@ include_once(dirname(__FILE__) . '/thumbnailer.php');
20
  include_once(dirname(__FILE__) . '/settings.php');
21
  include_once(dirname(__FILE__) . '/recommendations.php');
22
  include_once(dirname(__FILE__) . '/dashboard_widget.php');
 
23
  include_once(dirname(__FILE__) . '/compatibility.php');
24
 
25
  register_activation_hook(__FILE__, 'wp_rp_activate_hook');
@@ -57,12 +59,82 @@ function wp_rp_add_related_posts_hook($content) {
57
 
58
  return $content;
59
  }
60
- add_filter('the_content', 'wp_rp_add_related_posts_hook', 101);
61
 
62
- function wp_rp_append_posts(&$related_posts, $fetch_function_name) {
 
 
 
 
 
 
 
 
 
 
 
 
63
  $options = wp_rp_get_options();
64
 
65
- $limit = $options['max_related_posts'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  $len = sizeof($related_posts);
68
  $num_missing_posts = $limit - $len;
@@ -84,9 +156,9 @@ function wp_rp_fetch_posts_and_title() {
84
 
85
  $related_posts = array();
86
 
87
- wp_rp_append_posts($related_posts, 'wp_rp_fetch_related_posts_v2');
88
- wp_rp_append_posts($related_posts, 'wp_rp_fetch_related_posts');
89
- wp_rp_append_posts($related_posts, 'wp_rp_fetch_random_posts');
90
 
91
  if(function_exists('qtrans_postsFilter')) {
92
  $related_posts = qtrans_postsFilter($related_posts);
@@ -98,45 +170,103 @@ function wp_rp_fetch_posts_and_title() {
98
  );
99
  }
100
 
101
- function wp_rp_generate_related_posts_list_items($related_posts) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  $options = wp_rp_get_options();
 
103
  $output = "";
104
- $i = 0;
105
 
106
  $statistics_enabled = $options['ctr_dashboard_enabled'];
107
 
108
- foreach ($related_posts as $related_post ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  $data_attrs = '';
110
  if ($statistics_enabled) {
111
- $data_attrs .= 'data-position="' . $i++ . '" data-poid="in-' . $related_post->ID . '" ';
112
  }
113
 
114
  $output .= '<li ' . $data_attrs . '>';
115
 
116
- $img = wp_rp_get_post_thumbnail_img($related_post);
 
 
117
  if ($img) {
118
- $output .= '<a href="' . get_permalink($related_post->ID) . '" class="wp_rp_thumbnail">' . $img . '</a>';
119
  }
120
 
121
- if (!$options["display_thumbnail"] || ($options["display_thumbnail"] && ($options["thumbnail_display_title"] || !$img))) {
122
- if ($options["display_publish_date"]){
123
- $dateformat = get_option('date_format');
124
- $output .= mysql2date($dateformat, $related_post->post_date) . " -- ";
125
- }
126
 
127
- $output .= '<a href="' . get_permalink($related_post->ID) . '" class="wp_rp_title">' . wptexturize($related_post->post_title) . '</a>';
128
 
129
- if ($options["display_comment_count"]){
130
- $output .= " (" . $related_post->comment_count . ")";
131
- }
132
 
133
- if ($options["display_excerpt"]){
134
- $excerpt_max_length = $options["excerpt_max_length"];
135
- if($related_post->post_excerpt){
136
- $output .= '<br /><small>' . (mb_substr(strip_shortcodes(strip_tags($related_post->post_excerpt)), 0, $excerpt_max_length)) . '...</small>';
137
- } else {
138
- $output .= '<br /><small>' . (mb_substr(strip_shortcodes(strip_tags($related_post->post_content)), 0, $excerpt_max_length)) . '...</small>';
139
- }
140
  }
141
  }
142
  $output .= '</li>';
@@ -187,7 +317,6 @@ function wp_rp_ajax_blogger_network_blacklist_callback() {
187
  if ($body) {
188
  $doc = json_decode($body);
189
  if ($doc && $doc->status === 'ok') {
190
- header_remove();
191
  header('Content-Type: text/javascript');
192
  echo "if(window['_wp_rp_blacklist_callback$sourcefeed']) window._wp_rp_blacklist_callback$sourcefeed();";
193
  }
@@ -207,6 +336,7 @@ function wp_rp_head_resources() {
207
 
208
  $meta = wp_rp_get_meta();
209
  $options = wp_rp_get_options();
 
210
  $statistics_enabled = false;
211
  $remote_recommendations = false;
212
  $output = '';
@@ -216,6 +346,13 @@ function wp_rp_head_resources() {
216
  $remote_recommendations = $meta['remote_recommendations'] && $statistics_enabled;
217
  }
218
 
 
 
 
 
 
 
 
219
  if ($statistics_enabled) {
220
  $tags = $wpdb->get_col("SELECT label FROM " . $wpdb->prefix . "wp_rp_tags WHERE post_id=$post->ID ORDER BY weight desc;", 0);
221
  if (!empty($tags)) {
@@ -224,22 +361,21 @@ function wp_rp_head_resources() {
224
  $post_tags = '[]';
225
  }
226
 
227
- $output .= "<script type=\"text/javascript\">\n" .
228
- "\twindow._wp_rp_blog_id = '" . esc_js($meta['blog_id']) . "';\n" .
229
  "\twindow._wp_rp_ajax_img_src_url = '" . esc_js(WP_RP_CTR_REPORT_URL) . "';\n" .
230
- "\twindow._wp_rp_post_id = '" . esc_js($post->ID) . "';\n" .
231
- "\twindow._wp_rp_thumbnails = " . ($options['display_thumbnail'] ? 'true' : 'false') . ";\n" .
232
  "\twindow._wp_rp_post_title = '" . urlencode($post->post_title) . "';\n" .
233
  "\twindow._wp_rp_post_tags = {$post_tags};\n" .
234
- "\twindow._wp_rp_static_base_url = '" . esc_js(WP_RP_STATIC_BASE_URL) . "';\n" .
235
  "\twindow._wp_rp_promoted_content = " . ($options['promoted_content_enabled'] ? 'true' : 'false') . ";\n" .
236
- "\twindow._wp_rp_plugin_version = '" . WP_RP_VERSION . "';\n" .
237
  "\twindow._wp_rp_traffic_exchange = " . ($options['traffic_exchange_enabled'] ? 'true' : 'false') . ";\n" .
238
- (current_user_can('delete_users') ? "\twindow._wp_rp_admin_ajax_url = '" . admin_url('admin-ajax.php') . "';\n" : '') .
239
- "\twindow._wp_rp_num_rel_posts = '" . $options['max_related_posts'] . "';\n" .
240
- "</script>\n";
 
241
  }
242
 
 
 
243
  if ($remote_recommendations) {
244
  $output .= '<script type="text/javascript" src="' . WP_RP_STATIC_BASE_URL . WP_RP_STATIC_RECOMMENDATIONS_JS_FILE . '?version=' . WP_RP_VERSION . '"></script>' . "\n";
245
  $output .= '<link rel="stylesheet" href="' . WP_RP_STATIC_BASE_URL . WP_RP_STATIC_RECOMMENDATIONS_CSS_FILE . '?version=' . WP_RP_VERSION . '" />' . "\n";
@@ -250,63 +386,113 @@ function wp_rp_head_resources() {
250
  }
251
 
252
  if ($options['enable_themes']) {
253
- if ($options["display_thumbnail"]) {
254
- $theme_url = WP_RP_STATIC_BASE_URL . WP_RP_STATIC_THEMES_THUMBS_PATH;
255
- } else {
256
- $theme_url = WP_RP_STATIC_BASE_URL . WP_RP_STATIC_THEMES_PATH;
 
257
  }
258
 
259
- $output .= '<link rel="stylesheet" href="' . $theme_url . $options['theme_name'] . '?version=' . WP_RP_VERSION . '" />' . "\n";
260
- if ($options['custom_theme_enabled']) {
261
- $output .= '<style type="text/css">' . "\n" . $options['theme_custom_css'] . "</style>\n";
262
  }
 
 
 
 
 
 
 
 
 
263
  }
264
 
265
  echo $output;
266
  }
267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  function wp_rp_get_related_posts($before_title = '', $after_title = '') {
269
  if (wp_rp_should_exclude()) {
270
  return;
271
  }
272
 
 
 
273
  $options = wp_rp_get_options();
 
274
  $meta = wp_rp_get_meta();
275
 
276
  $statistics_enabled = $options['ctr_dashboard_enabled'] && $meta['blog_id'] && $meta['auth_key'];
277
  $remote_recommendations = is_single() && $meta['remote_recommendations'] && $statistics_enabled;
278
 
279
- $output = "";
280
- $promotional_link = '';
281
-
282
  $posts_and_title = wp_rp_fetch_posts_and_title();
283
-
284
  $related_posts = $posts_and_title['posts'];
285
  $title = $posts_and_title['title'];
286
 
 
 
 
 
287
  if (!$related_posts) {
288
  return;
289
  }
290
 
291
- $css_classes = 'related_post wp_rp';
292
- if ($options['enable_themes']) {
293
- $css_classes .= ' ' . str_replace(array('.css', '-'), array('', '_'), esc_attr('wp_rp_' . $options['theme_name']));
 
 
 
 
 
294
  }
295
 
296
- $output = wp_rp_generate_related_posts_list_items($related_posts);
297
- $output = '<ul class="' . $css_classes . '" style="visibility: ' . ($remote_recommendations ? 'hidden' : 'visible') . '">' . $output . '</ul>';
298
- if($remote_recommendations) {
299
- $output = $output . '<script type="text/javascript">window._wp_rp_callback_widget_exists && window._wp_rp_callback_widget_exists();</script>';
300
- }
301
 
302
- if ($title != '') {
303
- if ($before_title) {
304
- $output = $before_title . $title . $after_title . $output;
305
- } else {
306
- $title_tag = $options["related_posts_title_tag"];
307
- $output = '<' . $title_tag . ' class="related_post_title">' . $title . $promotional_link . '</' . $title_tag . '>' . $output;
308
- }
 
 
309
  }
310
 
 
 
 
 
 
 
 
 
 
311
  return "\n" . $output . "\n";
312
  }
1
  <?php
2
  /*
3
  Plugin Name: WordPress Related Posts
4
+ Version: 2.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.
7
  Author: Zemanta Ltd.
8
  Author URI: http://www.zemanta.com
9
  */
10
 
11
+ define('WP_RP_VERSION', '2.5');
12
 
13
  include_once(dirname(__FILE__) . '/config.php');
14
  include_once(dirname(__FILE__) . '/lib/stemmer.php');
15
+ include_once(dirname(__FILE__) . '/lib/mobile_detect.php');
16
 
17
  include_once(dirname(__FILE__) . '/admin_notices.php');
18
  include_once(dirname(__FILE__) . '/notifications.php');
21
  include_once(dirname(__FILE__) . '/settings.php');
22
  include_once(dirname(__FILE__) . '/recommendations.php');
23
  include_once(dirname(__FILE__) . '/dashboard_widget.php');
24
+ include_once(dirname(__FILE__) . '/edit_related_posts.php');
25
  include_once(dirname(__FILE__) . '/compatibility.php');
26
 
27
  register_activation_hook(__FILE__, 'wp_rp_activate_hook');
59
 
60
  return $content;
61
  }
62
+ add_filter('the_content', 'wp_rp_add_related_posts_hook', 1);
63
 
64
+ global $wp_rp_is_phone;
65
+ function wp_rp_is_phone() {
66
+ global $wp_rp_is_phone;
67
+
68
+ if (!isset($wp_rp_is_phone)) {
69
+ $detect = new WpRpMobileDetect();
70
+ $wp_rp_is_phone = $detect->isMobile() && !$detect->isTablet();
71
+ }
72
+
73
+ return $wp_rp_is_phone;
74
+ }
75
+
76
+ function wp_rp_get_platform_options() {
77
  $options = wp_rp_get_options();
78
 
79
+ if (wp_rp_is_phone()) {
80
+ return $options['mobile'];
81
+ }
82
+ return $options['desktop'];
83
+ }
84
+
85
+ function wp_rp_ajax_load_articles_callback() {
86
+ global $post;
87
+
88
+ $getdata = stripslashes_deep($_GET);
89
+ if (!isset($getdata['post_id'])) {
90
+ die('error');
91
+ }
92
+
93
+ $post = get_post($getdata['post_id']);
94
+ if (!$post) {
95
+ die('error');
96
+ }
97
+
98
+ $from = (isset($getdata['from']) && is_numeric($getdata['from'])) ? intval($getdata['from']) : 0;
99
+ $count = (isset($getdata['count']) && is_numeric($getdata['count'])) ? intval($getdata['count']) : 50;
100
+
101
+ $image_size = isset($getdata['size']) ? $getdata['size'] : 'thumbnail';
102
+ if(!($image_size == 'thumbnail' || $image_size == 'full')) {
103
+ die('error');
104
+ }
105
+
106
+ $limit = $count + $from;
107
+
108
+ $related_posts = array();
109
+
110
+ wp_rp_append_posts($related_posts, 'wp_rp_fetch_related_posts_v2', $limit);
111
+ wp_rp_append_posts($related_posts, 'wp_rp_fetch_related_posts', $limit);
112
+ wp_rp_append_posts($related_posts, 'wp_rp_fetch_random_posts', $limit);
113
+
114
+ if(function_exists('qtrans_postsFilter')) {
115
+ $related_posts = qtrans_postsFilter($related_posts);
116
+ }
117
+
118
+ $response_list = array();
119
+
120
+ foreach (array_slice($related_posts, $from) as $related_post) {
121
+ array_push($response_list, array(
122
+ 'id' => $related_post->ID,
123
+ 'url' => get_permalink($related_post->ID),
124
+ 'title' => $related_post->post_title,
125
+ 'img' => wp_rp_get_post_thumbnail_img($related_post, $image_size)
126
+ ));
127
+ }
128
+
129
+ header('Content-Type: text/javascript');
130
+
131
+ die(json_encode($response_list));
132
+ }
133
+ add_action('wp_ajax_wp_rp_load_articles', 'wp_rp_ajax_load_articles_callback');
134
+ add_action('wp_ajax_nopriv_wp_rp_load_articles', 'wp_rp_ajax_load_articles_callback');
135
+
136
+ function wp_rp_append_posts(&$related_posts, $fetch_function_name, $limit) {
137
+ $options = wp_rp_get_options();
138
 
139
  $len = sizeof($related_posts);
140
  $num_missing_posts = $limit - $len;
156
 
157
  $related_posts = array();
158
 
159
+ wp_rp_append_posts($related_posts, 'wp_rp_fetch_related_posts_v2', $limit);
160
+ wp_rp_append_posts($related_posts, 'wp_rp_fetch_related_posts', $limit);
161
+ wp_rp_append_posts($related_posts, 'wp_rp_fetch_random_posts', $limit);
162
 
163
  if(function_exists('qtrans_postsFilter')) {
164
  $related_posts = qtrans_postsFilter($related_posts);
170
  );
171
  }
172
 
173
+ function wp_rp_get_next_post(&$related_posts, &$selected_related_posts, &$inserted_urls, $default_post_type) {
174
+ $post = false;
175
+
176
+ while (!($post && $post->ID) && !(empty($related_posts) && empty($selected_related_posts))) {
177
+ $post = array_shift($selected_related_posts);
178
+ $post_type = $default_post_type;
179
+
180
+ if ($post && $post->type) {
181
+ $post_type = $post->type;
182
+ }
183
+
184
+ if (!$post || !$post->ID) {
185
+ $post = array_shift($related_posts);
186
+ }
187
+ if ($post && $post->ID) {
188
+ $post_url = property_exists($post, 'post_url') ? $post->post_url : get_permalink($post->ID);
189
+ if (isset($inserted_urls[$post_url])) {
190
+ $post = false;
191
+ } else {
192
+ $post->type = $post_type;
193
+ }
194
+ }
195
+ }
196
+
197
+ if (!$post || !$post->ID) {
198
+ return false;
199
+ }
200
+
201
+ $inserted_urls[$post_url] = true;
202
+
203
+ return $post;
204
+ }
205
+
206
+ function wp_rp_generate_related_posts_list_items($related_posts, $selected_related_posts) {
207
  $options = wp_rp_get_options();
208
+ $platform_options = wp_rp_get_platform_options();
209
  $output = "";
 
210
 
211
  $statistics_enabled = $options['ctr_dashboard_enabled'];
212
 
213
+ $limit = $options['max_related_posts'];
214
+
215
+ $inserted_urls = array(); // Used to prevent duplicates
216
+
217
+ $default_post_type = empty($selected_related_posts) ? 'none' : 'empty';
218
+
219
+ $image_size = ($platform_options['theme_name'] == 'pinterest.css') ? 'full' : 'thumbnail';
220
+
221
+ for ($i = 0; $i < $limit; $i++) {
222
+ $related_post = wp_rp_get_next_post($related_posts, $selected_related_posts, $inserted_urls, $default_post_type);
223
+ if (!$related_post) {
224
+ break;
225
+ }
226
+
227
+ if (property_exists($related_post, 'type')) {
228
+ $post_type = $related_post->type;
229
+ } else {
230
+ $post_type = $default_post_type;
231
+ }
232
+
233
+ if (in_array($post_type, array('empty', 'none'))) {
234
+ $post_id = 'in-' . $related_post->ID;
235
+ } else {
236
+ $post_id = 'ex-' . $related_post->ID;
237
+ }
238
+
239
  $data_attrs = '';
240
  if ($statistics_enabled) {
241
+ $data_attrs .= 'data-position="' . $i . '" data-poid="' . $post_id . '" data-post-type="' . $post_type . '" ';
242
  }
243
 
244
  $output .= '<li ' . $data_attrs . '>';
245
 
246
+ $post_url = property_exists($related_post, 'post_url') ? $related_post->post_url : get_permalink($related_post->ID);
247
+
248
+ $img = wp_rp_get_post_thumbnail_img($related_post, $image_size);
249
  if ($img) {
250
+ $output .= '<a href="' . $post_url . '" class="wp_rp_thumbnail">' . $img . '</a>';
251
  }
252
 
253
+ if ($platform_options["display_publish_date"]){
254
+ $dateformat = get_option('date_format');
255
+ $output .= mysql2date($dateformat, $related_post->post_date) . " -- ";
256
+ }
 
257
 
258
+ $output .= '<a href="' . $post_url . '" class="wp_rp_title">' . wptexturize($related_post->post_title) . '</a>';
259
 
260
+ if ($platform_options["display_comment_count"] && property_exists($related_post, 'comment_count')){
261
+ $output .= " (" . $related_post->comment_count . ")";
262
+ }
263
 
264
+ if ($platform_options["display_excerpt"]){
265
+ $excerpt_max_length = $platform_options["excerpt_max_length"];
266
+ if($related_post->post_excerpt){
267
+ $output .= '<br /><small>' . (mb_substr(strip_shortcodes(strip_tags($related_post->post_excerpt)), 0, $excerpt_max_length)) . '...</small>';
268
+ } else {
269
+ $output .= '<br /><small>' . (mb_substr(strip_shortcodes(strip_tags($related_post->post_content)), 0, $excerpt_max_length)) . '...</small>';
 
270
  }
271
  }
272
  $output .= '</li>';
317
  if ($body) {
318
  $doc = json_decode($body);
319
  if ($doc && $doc->status === 'ok') {
 
320
  header('Content-Type: text/javascript');
321
  echo "if(window['_wp_rp_blacklist_callback$sourcefeed']) window._wp_rp_blacklist_callback$sourcefeed();";
322
  }
336
 
337
  $meta = wp_rp_get_meta();
338
  $options = wp_rp_get_options();
339
+ $platform_options = wp_rp_get_platform_options();
340
  $statistics_enabled = false;
341
  $remote_recommendations = false;
342
  $output = '';
346
  $remote_recommendations = $meta['remote_recommendations'] && $statistics_enabled;
347
  }
348
 
349
+ $output_vars = "\twindow._wp_rp_static_base_url = '" . esc_js(WP_RP_STATIC_BASE_URL) . "';\n" .
350
+ "\twindow._wp_rp_wp_ajax_url = \"" . admin_url('admin-ajax.php') . "\";\n" .
351
+ "\twindow._wp_rp_plugin_version = '" . WP_RP_VERSION . "';\n" .
352
+ "\twindow._wp_rp_post_id = '" . esc_js($post->ID) . "';\n" .
353
+ "\twindow._wp_rp_num_rel_posts = '" . $options['max_related_posts'] . "';\n";
354
+
355
+
356
  if ($statistics_enabled) {
357
  $tags = $wpdb->get_col("SELECT label FROM " . $wpdb->prefix . "wp_rp_tags WHERE post_id=$post->ID ORDER BY weight desc;", 0);
358
  if (!empty($tags)) {
361
  $post_tags = '[]';
362
  }
363
 
364
+ $output_vars .= "\twindow._wp_rp_blog_id = '" . esc_js($meta['blog_id']) . "';\n" .
 
365
  "\twindow._wp_rp_ajax_img_src_url = '" . esc_js(WP_RP_CTR_REPORT_URL) . "';\n" .
366
+ "\twindow._wp_rp_thumbnails = " . ($platform_options['display_thumbnail'] ? 'true' : 'false') . ";\n" .
 
367
  "\twindow._wp_rp_post_title = '" . urlencode($post->post_title) . "';\n" .
368
  "\twindow._wp_rp_post_tags = {$post_tags};\n" .
 
369
  "\twindow._wp_rp_promoted_content = " . ($options['promoted_content_enabled'] ? 'true' : 'false') . ";\n" .
 
370
  "\twindow._wp_rp_traffic_exchange = " . ($options['traffic_exchange_enabled'] ? 'true' : 'false') . ";\n" .
371
+ (current_user_can('edit_posts') ?
372
+ "\twindow._wp_rp_admin_ajax_url = '" . admin_url('admin-ajax.php') . "';\n" .
373
+ "\twindow._wp_rp_plugin_static_base_url = '" . esc_js(plugins_url('static/' , __FILE__)) . "';\n"
374
+ : '');
375
  }
376
 
377
+ $output .= "<script type=\"text/javascript\">\n" . $output_vars . "</script>\n";
378
+
379
  if ($remote_recommendations) {
380
  $output .= '<script type="text/javascript" src="' . WP_RP_STATIC_BASE_URL . WP_RP_STATIC_RECOMMENDATIONS_JS_FILE . '?version=' . WP_RP_VERSION . '"></script>' . "\n";
381
  $output .= '<link rel="stylesheet" href="' . WP_RP_STATIC_BASE_URL . WP_RP_STATIC_RECOMMENDATIONS_CSS_FILE . '?version=' . WP_RP_VERSION . '" />' . "\n";
386
  }
387
 
388
  if ($options['enable_themes']) {
389
+ $theme_url = WP_RP_STATIC_BASE_URL . WP_RP_STATIC_THEMES_PATH;
390
+
391
+ $output .= '<link rel="stylesheet" href="' . $theme_url . $platform_options['theme_name'] . '?version=' . WP_RP_VERSION . '" />' . "\n";
392
+ if ($platform_options['custom_theme_enabled']) {
393
+ $output .= '<style type="text/css">' . "\n" . $platform_options['theme_custom_css'] . "</style>\n";
394
  }
395
 
396
+ if ($platform_options['theme_name'] === 'm-stream.css') {
397
+ wp_enqueue_script('wp_rp_infiniterecs', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_INFINITE_RECS_JS_FILE, array('jquery'));
 
398
  }
399
+
400
+ if ($platform_options['theme_name'] === 'pinterest.css') {
401
+ wp_enqueue_script('wp_rp_pinterest', WP_RP_STATIC_BASE_URL . WP_RP_STATIC_PINTEREST_JS_FILE, array('jquery'));
402
+ }
403
+ }
404
+
405
+ if (current_user_can('edit_posts') && $remote_recommendations) {
406
+ wp_enqueue_style('wp_rp_edit_related_posts_css', WP_RP_STATIC_BASE_URL . 'wp-rp-css/edit_related_posts.css');
407
+ wp_enqueue_script('wp_rp_edit_related_posts_js', WP_RP_STATIC_BASE_URL . 'js/edit_related_posts.js', array('jquery'));
408
  }
409
 
410
  echo $output;
411
  }
412
 
413
+ function wp_rp_get_selected_posts($remote_recommendations) {
414
+ if (!$remote_recommendations) {
415
+ return array();
416
+ }
417
+
418
+ global $post;
419
+
420
+ $selected_related_posts = get_post_meta($post->ID, '_wp_rp_selected_related_posts');
421
+ if (empty($selected_related_posts)) {
422
+ return array();
423
+ }
424
+
425
+ $selected_related_posts = $selected_related_posts[0];
426
+ if (empty($selected_related_posts)) {
427
+ return array();
428
+ }
429
+
430
+ $options = wp_rp_get_options();
431
+ $limit = $options['max_related_posts'];
432
+
433
+ return array_slice((array)$selected_related_posts, 0, $limit);
434
+ }
435
+
436
+ global $wp_rp_is_first_widget;
437
+ $wp_rp_is_first_widget = true;
438
  function wp_rp_get_related_posts($before_title = '', $after_title = '') {
439
  if (wp_rp_should_exclude()) {
440
  return;
441
  }
442
 
443
+ global $post, $wp_rp_is_first_widget;
444
+
445
  $options = wp_rp_get_options();
446
+ $platform_options = wp_rp_get_platform_options();
447
  $meta = wp_rp_get_meta();
448
 
449
  $statistics_enabled = $options['ctr_dashboard_enabled'] && $meta['blog_id'] && $meta['auth_key'];
450
  $remote_recommendations = is_single() && $meta['remote_recommendations'] && $statistics_enabled;
451
 
 
 
 
452
  $posts_and_title = wp_rp_fetch_posts_and_title();
 
453
  $related_posts = $posts_and_title['posts'];
454
  $title = $posts_and_title['title'];
455
 
456
+ $selected_related_posts = wp_rp_get_selected_posts($remote_recommendations);
457
+
458
+ $related_posts_content = "";
459
+
460
  if (!$related_posts) {
461
  return;
462
  }
463
 
464
+ $posts_footer = '';
465
+ if ($options['display_zemanta_linky'] || $remote_recommendations) {
466
+ $posts_footer = '<div class="wp_rp_footer">' .
467
+ ((current_user_can('edit_posts') && $remote_recommendations)
468
+ ? '<a class="wp_rp_edit" id="wp_rp_edit_related_posts" href="#" id="wp_rp_edit_related_posts">Edit Related Posts</a>'
469
+ : ($options['display_zemanta_linky'] ? '<a class="wp_rp_backlink" target="_blank" rel="nofollow" href="http://www.zemanta.com/?wp-related-posts">Zemanta</a>' : '')
470
+ ) .
471
+ '</div>';
472
  }
473
 
474
+ $css_classes = 'related_post wp_rp';
475
+ $css_classes_wrap = ' ' . str_replace(array('.css', '-'), array('', '_'), esc_attr('wp_rp_' . $platform_options['theme_name']));
 
 
 
476
 
477
+ $related_posts_lis = wp_rp_generate_related_posts_list_items($related_posts, $selected_related_posts);
478
+ $related_posts_ul = '<ul class="' . $css_classes . '" style="visibility: ' . ($remote_recommendations ? 'hidden' : 'visible') . '">' . $related_posts_lis . '</ul>';
479
+
480
+ $related_posts_title = $title ? ($before_title ? $before_title . $title . $after_title : '<h3 class="related_post_title">' . $title . '</h3>') : '';
481
+
482
+ $first_id_attr = '';
483
+ if($wp_rp_is_first_widget) {
484
+ $wp_rp_is_first_widget = false;
485
+ $first_id_attr = 'id="wp_rp_first"';
486
  }
487
 
488
+ $output = '<div class="wp_rp_wrap ' . $css_classes_wrap . '" ' . $first_id_attr . '>' .
489
+ '<div class="wp_rp_content">' .
490
+ $related_posts_title .
491
+ $related_posts_ul .
492
+ $posts_footer .
493
+ '</div>' .
494
+ ($remote_recommendations ? '<script type="text/javascript">window._wp_rp_callback_widget_exists && window._wp_rp_callback_widget_exists();</script>' : '') .
495
+ '</div>';
496
+
497
  return "\n" . $output . "\n";
498
  }