Related Posts Thumbnails Plugin for WordPress - Version 1.6.4

Version Description

  • Please upgrade immediately - Multiple Enhancements and bugfixes.

=

Download this release

Release Info

Developer hiddenpearls
Plugin Icon 128x128 Related Posts Thumbnails Plugin for WordPress
Version 1.6.4
Comparing to
See all releases

Code changes from version 1.6.3 to 1.6.4

assets/css/admin.css CHANGED
@@ -207,3 +207,28 @@
207
  #relpoststh_customwidth {
208
  padding-right: 3px;
209
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  #relpoststh_customwidth {
208
  padding-right: 3px;
209
  }
210
+ #custom_taxonomies {
211
+ padding-top: 5px;
212
+ }
213
+ #relpoststh_cleanhtml {
214
+ margin-left: 5px;
215
+ }
216
+ #relpoststh_cleanhtml input{
217
+ margin-left: 1px;
218
+ }
219
+ #pt_page {
220
+ margin-left: 10px;
221
+ }
222
+ #pt_attachment {
223
+ margin-left: 10px;
224
+ }
225
+ .rpth-discription {
226
+ display: inline;
227
+ }
228
+ .rpt-no-validate-error {
229
+ font-style: italic;
230
+ color: #b94444;
231
+ }
232
+ .rpth-setting-options th {
233
+ color: #3e3838;
234
+ }
assets/css/front.css CHANGED
@@ -167,3 +167,13 @@ text-align: center;
167
  display: inline-block;
168
  float: none;
169
  }
 
 
 
 
 
 
 
 
 
 
167
  display: inline-block;
168
  float: none;
169
  }
170
+ .relpost-thumb-wrapper:after{
171
+ content:"";
172
+ display:block;
173
+ clear:both;
174
+ }
175
+ .rpth_post_date {
176
+ display: block;
177
+ padding-top: 10px;
178
+ font-size: 11px;
179
+ }
assets/js/admin.js CHANGED
@@ -91,6 +91,16 @@
91
  $(this).parent().find("div.select_specific").show();
92
  }
93
  });
 
 
 
 
 
 
 
 
 
 
94
  $('#relpoststh_thsource').change(function(){
95
  if (this.value == 'post-thumbnails') {
96
  $('#relpoststh-post-thumbnails').show();
91
  $(this).parent().find("div.select_specific").show();
92
  }
93
  });
94
+
95
+ // TODO Following is to be done with css.
96
+ if ($('#relpoststh_thsource').val() == 'custom-field') {
97
+ $('#relpoststh-post-thumbnails').hide();
98
+ $('#relpoststh-custom-field').show();
99
+ } else if($('#relpoststh_thsource').val() == 'post-thumbnails'){
100
+ $('#relpoststh-post-thumbnails').show();
101
+ $('#relpoststh-custom-field').hide();
102
+ }
103
+
104
  $('#relpoststh_thsource').change(function(){
105
  if (this.value == 'post-thumbnails') {
106
  $('#relpoststh-post-thumbnails').show();
inc/rpt-settings.php CHANGED
@@ -1,190 +1,200 @@
1
  <?php
2
 
3
  // Admin interface
4
- if ( isset( $_POST['action'] ) && ($_POST['action'] == 'update') ) {
5
- if ( ! current_user_can( 'manage_options' ) ) {
6
- wp_die( __( 'No access', 'related-posts-thumbnails' ) );
7
- }
8
- check_admin_referer( 'related-posts-thumbnails' );
9
- $validation = true;
10
-
11
- $set_date = isset( $_POST['rpt_post_include'] ) ? sanitize_text_field( wp_unslash( $_POST['rpt_post_include'] ) ) : '';
12
-
13
- if ( $validation ) {
14
-
15
- if ( isset( $_POST['relpoststh_single_only'] ) ) {
16
- update_option( 'relpoststh_single_only', sanitize_text_field( wp_unslash( $_POST['relpoststh_single_only'] ) ) );
17
- } else {
18
- update_option( 'relpoststh_single_only', '0' );
19
- }
20
-
21
- if ( isset( $_POST['relpoststh_post_types'] ) ) {
22
- update_option( 'relpoststh_post_types', array_map( 'sanitize_text_field', wp_unslash( $_POST['relpoststh_post_types'] ) ) );
23
- } else {
24
- update_option( 'relpoststh_post_types', array() );
25
- }
26
-
27
- if ( isset( $_POST['onlywiththumbs'] ) ) {
28
- update_option( 'relpoststh_onlywiththumbs', sanitize_text_field( wp_unslash( $_POST['onlywiththumbs'] ) ) );
29
- } else {
30
- update_option( 'relpoststh_onlywiththumbs', '0' );
31
- }
32
-
33
- if ( isset( $_POST['relpoststh_output_style'] ) ) {
34
- update_option( 'relpoststh_output_style', sanitize_text_field( wp_unslash( $_POST['relpoststh_output_style'] ) ) );
35
- }
36
-
37
- if ( isset( $_POST['relpoststh_cleanhtml'] ) ) {
38
- update_option( 'relpoststh_cleanhtml', sanitize_text_field( wp_unslash( $_POST['relpoststh_cleanhtml'] ) ) );
39
- } else {
40
- update_option( 'relpoststh_cleanhtml', '0' );
41
- }
42
-
43
- if ( isset( $_POST['relpoststh_auto'] ) ) {
44
- update_option( 'relpoststh_auto', sanitize_text_field( wp_unslash( $_POST['relpoststh_auto'] ) ) );
45
- } else {
46
- update_option( 'relpoststh_auto', '0' );
47
- }
48
-
49
- if ( isset( $_POST['relpoststh_top_text'] ) ) {
50
- update_option( 'relpoststh_top_text', wp_kses( $_POST['relpoststh_top_text'], $this->wp_kses_rp_args ) );
51
- }
52
-
53
-
54
- if ( isset( $_POST['relpoststh_number'] ) ) {
55
- update_option( 'relpoststh_number', absint( $_POST['relpoststh_number'] ) );
56
- }
57
-
58
- if ( isset( $_POST['relpoststh_relation'] ) ) {
59
- update_option( 'relpoststh_relation', sanitize_text_field( wp_unslash( $_POST['relpoststh_relation'] ) ) );
60
- }
61
-
62
- if ( isset( $_POST['relpoststh_default_image'] ) ) {
63
- update_option( 'relpoststh_default_image', sanitize_text_field( wp_unslash( $_POST['relpoststh_default_image'] ) ) );
64
- }
65
-
66
- if ( isset( $_POST['relpoststh_poststhname'] ) ) {
67
- update_option( 'relpoststh_poststhname', sanitize_text_field( wp_unslash( $_POST['relpoststh_poststhname'] ) ) );
68
- }
69
-
70
- if ( isset( $_POST['relpoststh_background'] ) ) {
71
- update_option( 'relpoststh_background', sanitize_text_field( wp_unslash( $_POST['relpoststh_background'] ) ) );
72
- }
73
-
74
- if ( isset( $_POST['relpoststh_hoverbackground'] ) ) {
75
- update_option( 'relpoststh_hoverbackground', sanitize_text_field( wp_unslash( $_POST['relpoststh_hoverbackground'] ) ) );
76
- }
77
-
78
-
79
- if ( isset( $_POST['relpoststh_bordercolor'] ) ) {
80
- update_option( 'relpoststh_bordercolor', sanitize_text_field( wp_unslash( $_POST['relpoststh_bordercolor'] ) ) );
81
- }
82
-
83
- if ( isset( $_POST['relpoststh_fontcolor'] ) ) {
84
- update_option( 'relpoststh_fontcolor', sanitize_text_field( wp_unslash( $_POST['relpoststh_fontcolor'] ) ) );
85
- }
86
-
87
- if ( isset( $_POST['relpoststh_fontsize'] ) ) {
88
- update_option( 'relpoststh_fontsize', sanitize_text_field( wp_unslash( $_POST['relpoststh_fontsize'] ) ) );
89
- }
90
-
91
- if ( isset( $_POST['relpoststh_fontfamily'] ) ) {
92
- update_option( 'relpoststh_fontfamily', sanitize_text_field( wp_unslash( $_POST['relpoststh_fontfamily'] ) ) );
93
- }
94
-
95
- if ( isset( $_POST['relpoststh_textlength'] ) ) {
96
- update_option( 'relpoststh_textlength', sanitize_text_field( wp_unslash( $_POST['relpoststh_textlength'] ) ) );
97
- }
98
-
99
- if ( isset( $_POST['relpoststh_excerptlength'] ) ) {
100
- update_option( 'relpoststh_excerptlength', sanitize_text_field( wp_unslash( $_POST['relpoststh_excerptlength'] ) ) );
101
- }
102
-
103
- if ( isset( $_POST['relpoststh_thsource'] ) ) {
104
- update_option( 'relpoststh_thsource', sanitize_text_field( wp_unslash( $_POST['relpoststh_thsource'] ) ) );
105
- }
106
-
107
- if ( isset( $_POST['relpoststh_customfield'] ) ) {
108
- update_option( 'relpoststh_customfield', sanitize_text_field( wp_unslash( $_POST['relpoststh_customfield'] ) ) );
109
- }
110
-
111
- if ( isset( $_POST['relpoststh_theme_resize_url'] ) ) {
112
- update_option( 'relpoststh_theme_resize_url', sanitize_text_field( wp_unslash( $_POST['relpoststh_theme_resize_url'] ) ) );
113
- }
114
-
115
- if ( isset( $_POST['relpoststh_customwidth'] ) ) {
116
- update_option( 'relpoststh_customwidth', sanitize_text_field( wp_unslash( $_POST['relpoststh_customwidth'] ) ) );
117
- }
118
-
119
- if ( isset( $_POST['relpoststh_customheight'] ) ) {
120
- update_option( 'relpoststh_customheight', sanitize_text_field( wp_unslash( $_POST['relpoststh_customheight'] ) ) );
121
- }
122
-
123
- if ( isset( $_POST['relpoststh_textblockheight'] ) ) {
124
- update_option( 'relpoststh_textblockheight', sanitize_text_field( wp_unslash( $_POST['relpoststh_textblockheight'] ) ) );
125
- }
126
-
127
- if ( isset( $_POST['relpoststh_customwidth'] ) ) {
128
- update_option( 'relpoststh_customwidth', sanitize_text_field( wp_unslash( $_POST['relpoststh_customwidth'] ) ) );
129
- }
130
-
131
- if ( isset( $_POST['relpoststh_categories'] ) ) {
132
- update_option( 'relpoststh_categories', array_map( 'sanitize_text_field', wp_unslash( $_POST['relpoststh_categories'] ) ) );
133
- } else {
134
- update_option( 'relpoststh_categories', array() );
135
- }
136
-
137
- if ( isset( $_POST['relpoststh_categoriesall'] ) ) {
138
- update_option( 'relpoststh_categoriesall', sanitize_text_field( wp_unslash( $_POST['relpoststh_categoriesall'] ) ) );
139
- } else {
140
- update_option( 'relpoststh_categoriesall', '' );
141
- }
142
-
143
- if ( isset( $_POST['relpoststh_show_categoriesall'] ) ) {
144
- update_option( 'relpoststh_show_categoriesall', sanitize_text_field( wp_unslash( $_POST['relpoststh_show_categoriesall'] ) ) );
145
- } else {
146
- update_option( 'relpoststh_show_categoriesall', '' );
147
- }
148
-
149
- if ( isset( $_POST['relpoststh_show_categories'] ) ) {
150
- update_option( 'relpoststh_show_categories', array_map( 'sanitize_text_field', wp_unslash( $_POST['relpoststh_show_categories'] ) ) );
151
- } else {
152
- update_option( 'relpoststh_show_categories', array() );
153
- }
154
-
155
- if ( isset( $_POST['relpoststh_devmode'] ) ) {
156
- update_option( 'relpoststh_devmode', sanitize_text_field( wp_unslash( $_POST['relpoststh_devmode'] ) ) );
157
- } else {
158
- update_option( 'relpoststh_devmode', '0' );
159
- }
160
-
161
- update_option( 'relpoststh_startdate', $set_date );
162
-
163
- if ( isset( $_POST['relpoststh_custom_taxonomies'] ) ) {
164
- update_option( 'relpoststh_custom_taxonomies', array_map( 'sanitize_text_field', wp_unslash( $_POST['relpoststh_custom_taxonomies'] ) ) );
165
- } else {
166
- update_option( 'relpoststh_custom_taxonomies', array() );
167
- }
168
-
169
- // Updating layout option
170
- // if ( isset( $_POST['relpoststh_layout_style'] ) ) {
171
- // update_option( 'relpoststh_layout_style', sanitize_text_field( $_POST['relpoststh_layout_style'] ) );
172
- // }
173
-
174
- echo "<div class='updated fade'><p>" . __( 'Settings updated', 'related-posts-thumbnails' ) . '</p></div>';
175
- } else {
176
- echo "<div class='error fade'><p>" . __( 'Settings update failed', 'related-posts-thumbnails' ) . '. ' . $error . '</p></div>';
177
- }
 
 
 
 
 
 
 
 
 
 
178
  }
179
  $available_sizes = array(
180
- 'thumbnail' => 'thumbnail',
181
- 'medium' => 'medium',
182
  );
183
  if ( current_theme_supports( 'post-thumbnails' ) ) {
184
- global $_wp_additional_image_sizes;
185
- if ( is_array( $_wp_additional_image_sizes ) ) {
186
- $available_sizes = array_merge( $available_sizes, $_wp_additional_image_sizes );
187
- }
188
  }
189
 
190
  $relpoststh_single_only = get_option( 'relpoststh_single_only', $this->single_only );
@@ -195,505 +205,831 @@ $relpoststh_thsource = get_option( 'relpoststh_thsource', $this->thsou
195
  $relpoststh_devmode = get_option( 'relpoststh_devmode', $this->devmode );
196
  $relpoststh_categoriesall = get_option( 'relpoststh_categoriesall', $this->categories_all );
197
  $relpoststh_categories = get_option( 'relpoststh_categories' );
 
198
  $relpoststh_show_categories = get_option( 'relpoststh_show_categories', get_option( 'relpoststh_categories' ) );
199
  $relpoststh_show_categoriesall = get_option( 'relpoststh_show_categoriesall', $relpoststh_categoriesall );
200
  $onlywiththumbs = get_option( 'relpoststh_onlywiththumbs', false );
201
  $relpoststh_startdate = explode( '-', get_option( 'relpoststh_startdate' ) );
202
  $relpoststh_output_style = get_option( 'relpoststh_output_style', $this->output_style );
203
- $thsources = array(
204
- 'post-thumbnails' => __( 'Post thumbnails', 'related_posts_thumbnails' ),
205
- 'custom-field' => __( 'Custom field', 'related_posts_thumbnails' ),
206
- );
207
  $categories = get_categories();
208
  if ( $this->wp_version >= 3 ) {
209
- $post_types = get_post_types( array( 'public' => 1 ) );
210
  } else {
211
- $post_types = get_post_types();
212
  }
 
213
  $relpoststh_post_types = get_option( 'relpoststh_post_types', $this->post_types );
214
- $output_styles = array(
 
215
  'div' => __( 'Blocks', 'related-posts-thumbnails' ),
216
- 'list' => __( 'List', 'related-posts-thumbnails' ),
217
- );
218
- $relation_options = array(
219
- 'categories' => __( 'Categories', 'related-posts-thumbnails' ),
220
- 'tags' => __( 'Tags', 'related-posts-thumbnails' ),
221
- 'both' => __( 'Categories and Tags', 'related-posts-thumbnails' ),
222
- 'no' => __( 'Random', 'related-posts-thumbnails' ),
223
- 'custom' => __( 'Custom', 'related-posts-thumbnails' ),
224
  );
 
225
  if ( $this->wp_version >= 3 ) {
226
- $custom_taxonomies = get_taxonomies( array( 'public' => 1 ) );
227
- $relpoststh_custom_taxonomies = get_option( 'relpoststh_custom_taxonomies', $this->custom_taxonomies );
228
- if ( ! is_array( $relpoststh_custom_taxonomies ) ) {
229
- $relpoststh_custom_taxonomies = array();
230
- }
 
 
231
  } else {
232
- $relation_options['custom'] .= ' ' . __( '(This option is available for WP v3+ only)', 'related_posts_thumbnails' );
233
  }
234
  ?>
235
 
236
  <div class="wrap relpoststh">
237
 
238
  <div class="rpt-top-bar">
239
- <a href="<?php echo esc_url( 'https://wpbrigade.com/' ); ?>"><img src="<?php echo plugins_url( 'assets/images/rpt-logo.png', dirname( __FILE__ ) ); ?>" alt="<?php echo esc_attr( 'Related Post Thumbnails' ); ?>"></a>
240
- <div class="rpt-top-bar-content">
241
- <h3><?php _e( 'Related Post Thumbnails - Settings', 'related-posts-thumbnails' ); ?>:</h3>
242
- <p><?php _e( '<strong>Related Post Thumbnails</strong> by <strong><a href=" '. esc_url( "https://wpbrigade.com/" ) .' ">WPBrigade</a></strong>.', 'related-posts-thumbnails' ); ?></p>
243
- </div>
244
  </div>
245
 
246
  <div class="icon32" id="icon-options-general"><br></div>
247
  <h2><?php _e( 'Related Posts Thumbnails Settings', 'related-posts-thumbnails' ); ?></h2>
248
 
249
  <form action="?page=related-posts-thumbnails" method="POST" style="clear:both;">
250
- <input type="hidden" name="action" value="update" />
251
- <?php wp_nonce_field( 'related-posts-thumbnails' ); ?>
252
-
253
- <div class="wpbr-wrap"><div class="wpbr-tabsWrapper">
254
- <div class="wpbr-button-container top">
255
- <div class="setting-notification">
256
- <?php echo __( 'Settings have changed, you should save them!' , 'related-posts-thumbnails' ); ?>
257
- </div>
258
- <input type="submit" name="Submit" class="wpb-rpt-settings-submit button button-primary button-big" value="<?php esc_html_e( 'Save Settings','related-posts-thumbnails' ); ?>" id="wpb_rpt_save_setting_top">
259
- </div>
260
-
261
- <div id="relpoststh-settings" class="">
262
- <ul class="nav-tab-wrapper">
263
- <li> <a href="#content_general_options" class="nav-tab" id="content_general_options-tab"><?php _e( 'General Display Options', 'related-posts-thumbnails' ) ?></a> </li>
264
- <li> <a href="#content_thumbnail_options" class="nav-tab" id="content_thumbnail_options-tab"><?php _e( 'Thumbnails Source', 'related-posts-thumbnails' ) ?></a> </li>
265
- <li> <a href="#content_style_options" class="nav-tab" id="content_style_options-tab"><?php _e( 'Style Options:', 'related-posts-thumbnails' ) ?></a> </li>
266
- <li> <a href="#content_relation_options" class="nav-tab" id="content_relation_options-tab"><?php _e( 'Relation Builder Options', 'related-posts-thumbnails' ) ?></a> </li>
267
- </ul>
268
-
269
- <div class="metabox-holder">
270
- <div class="postbox" style="padding: 20px" id="content_general_options">
271
- <h2><?php _e( 'General Display Options', 'related-posts-thumbnails' ); ?>:</h2>
272
-
273
- <table class="form-table">
274
- <tr valign="top">
275
- <th scope="row"><?php _e( 'Automatically append to the post content', 'related-posts-thumbnails' ); ?>:</th>
276
- <td>
277
- <input type="checkbox" name="relpoststh_auto" id="relpoststh_auto" value="1"
278
- <?php
279
- if ( $relpoststh_auto ) {
280
- echo 'checked="checked"'; }
281
- ?>
282
- />
283
- <label for="relpoststh_auto"><?php _e( 'Or use <b>&lt;?php get_related_posts_thumbnails(); ?&gt;</b> in the Loop', 'related-posts-thumbnails' ); ?></label><br />
284
- </td>
285
- </tr>
286
- <tr valign="top">
287
- <th scope="row"><?php _e( 'Developer mode', 'related-posts-thumbnails' ); ?>:</th>
288
- <td>
289
- <input type="checkbox" name="relpoststh_devmode" id="relpoststh_devmode" value="1"
290
- <?php
291
- if ( $relpoststh_devmode ) {
292
- echo 'checked="checked"'; }
293
- ?>
294
- />
295
- <label for="relpoststh_devmode"><?php _e( 'This will add debugging information in HTML source', 'related-posts-thumbnails' ); ?></label><br />
296
- </td>
297
- </tr>
298
- <tr valign="top">
299
- <th scope="row"><?php _e( 'Display related posts', 'related-posts-thumbnails' ); ?>:</th>
300
- <td>
301
- <input type="checkbox" name="relpoststh_single_only" id="relpoststh_single_only" value="1"
302
- <?php
303
- if ( $relpoststh_single_only ) {
304
- echo 'checked="checked"'; }
305
- ?>
306
- />
307
- <label for="relpoststh_single_only"><?php _e( 'On single posts only', 'related-posts-thumbnails' ); ?></label><br />
308
- </td>
309
- </tr>
310
- <tr valign="top">
311
- <th scope="row"><?php _e( 'Post types', 'related-posts-thumbnails' ); ?>:</th>
312
- <td>
313
- <?php if ( is_array( $post_types ) && count( $post_types ) ) : ?>
314
- <?php foreach ( $post_types as $post_type ) : ?>
315
- <input type="checkbox" name="relpoststh_post_types[]" id="pt_<?php echo $post_type; ?>" value="<?php echo $post_type; ?>"
316
- <?php
317
- if ( in_array( $post_type, $relpoststh_post_types ) ) {
318
- echo 'checked="checked"'; }
319
- ?>
320
- />
321
- <label for="pt_<?php echo $post_type; ?>"><?php echo $post_type; ?></label>
322
- <?php endforeach; ?>
323
- <?php endif; ?>
324
- </td>
325
- </tr>
326
- <tr valign="top">
327
- <th scope="row"><?php _e( 'Display related posts on categories', 'related-posts-thumbnails' ); ?>:</th>
328
- <td>
329
- <?php $this->display_categories_list( $relpoststh_categoriesall, $categories, $relpoststh_categories, 'relpoststh_categoriesall', 'relpoststh_categories' ); ?>
330
- </td>
331
- </tr>
332
- <tr valign="top">
333
- <th scope="row"><?php _e( 'Categories will appear in related posts', 'related-posts-thumbnails' ); ?>:</th>
334
- <td>
335
- <?php $this->display_categories_list( $relpoststh_show_categoriesall, $categories, $relpoststh_show_categories, 'relpoststh_show_categoriesall', 'relpoststh_show_categories' ); ?>
336
- </td>
337
- </tr>
338
- <tr>
339
- <th scope="row"><?php _e( 'Include posts after', 'related-posts-thumbnails' ); ?>:</th>
340
- <td>
341
- <input type="text" class="rpt_post_include" name="rpt_post_include" value="<?php echo get_option( 'relpoststh_startdate' ); ?>">
342
- <button type="button" class="button rpt_clear_date">Clear</button>
343
- <label for="relpoststh_excerptlength"><?php _e( 'Leave empty for all posts dates', 'related-posts-thumbnails' ); ?></label><br />
344
- </td>
345
- </tr>
346
- <tr>
347
- <th scope="row"><?php _e( 'Top text', 'related-posts-thumbnails' ); ?>:</th>
348
- <td>
349
- <input type="text" name="relpoststh_top_text" value="<?php echo stripslashes( htmlspecialchars( get_option( 'relpoststh_top_text', $this->top_text ) ) ); ?>" size="50"/>
350
- </td>
351
- </tr>
352
- <tr>
353
- <th scope="row"><?php _e( 'Number of posts to display', 'related-posts-thumbnails' ); ?>:</th>
354
- <td>
355
- <input type="number" min="1" name="relpoststh_number" value="<?php echo get_option( 'relpoststh_number', $this->number ); ?>" size="2"/>
356
- <span class='rpt-no-validate-error' style="display:none;color:red;"><?php _e( 'Only Digits are allow', 'related-posts-thumbnails' ); ?></span>
357
- </td>
358
- </tr>
359
- <tr>
360
- <th scope="row"><?php _e( 'Default image', 'related-posts-thumbnails' ); ?>:</th>
361
- <td>
362
- <?php
363
- // $imgid =(isset( $instance[ 'imgid' ] )) ? $instance[ 'imgid' ] : "";
364
- // $img = wp_get_attachment_image_src($imgid, 'thumbnail');
365
- // var_dump($img);
366
- ?>
367
- <!-- <input type="text" value="<?php // echo get_option( 'relpoststh_default_image', $this->default_image ); ?>" class="regular-text process_custom_images" id="process_custom_images" name=""> -->
368
- <img src="<?php echo get_option( 'relpoststh_default_image', $this->default_image ); ?>" id="relpoststh_default_image_prev" class="regular-text process_custom_images" height="200" width="30">
369
- <div class="relposts-button-section">
370
- <button class="relpoststh_set_def_image button"><?php _e( 'Set Image', 'related-posts-thumbnails' ); ?></button>
371
- <button value="<?php echo esc_url( plugins_url( '../img/default.png', __FILE__ ) ); ?>" class="relpoststh_set_plug_image button"><?php _e( 'Default Image', 'related-posts-thumbnails' ); ?></button>
372
- <input type="hidden" name="relpoststh_default_image" id="relpoststh_default_image" value="<?php echo get_option( 'relpoststh_default_image', $this->default_image ); ?>" size="50"/>
373
- </div>
374
- </td>
375
- </tr>
376
- <tr>
377
- <th scope="row"><?php _e( 'Thumbnails Source', 'related-posts-thumbnails' ); ?>:</th>
378
- <td>
379
- <select name="relpoststh_thsource" id="relpoststh_thsource">
380
- <?php foreach ( $thsources as $name => $title ) : ?>
381
- <option value="<?php echo $name; ?>"
382
- <?php
383
- if ( $relpoststh_thsource == $name ) {
384
- echo 'selected'; }
385
- ?>
386
- ><?php echo $title; ?></option>
387
- <?php endforeach; ?>
388
- </select>
389
- </td>
390
- </tr>
391
- </table>
392
- </div>
393
-
394
- <div class="postbox" style="padding: 20px; display:none;" id="content_thumbnail_options">
395
- <div style="padding: 20px" id="relpoststh-post-thumbnails"
396
- <?php
397
- if ( $relpoststh_thsource != 'post-thumbnails' ) :
398
- ?>
399
- style="display:none" <?php endif; ?>>
400
- <h2><?php _e( 'Thumbnails Source', 'related-posts-thumbnails' ); ?>:</h2>
401
- <table class="form-table">
402
- <tr valign="top">
403
- <th scope="row"><?php _e( 'Related posts thumbnail size', 'related-posts-thumbnails' ); ?>:</th>
404
- <td>
405
- <select name="relpoststh_poststhname">
406
- <?php foreach ( $available_sizes as $size_name => $size ) : ?>
407
- <option
408
- <?php
409
- if ( $size_name == get_option( 'relpoststh_poststhname', $this->poststhname ) ) {
410
- echo 'selected'; }
411
- ?>
412
- ><?php echo $size_name; ?></option>
413
- <?php endforeach; ?>
414
- </select>
415
- <?php if ( ! current_theme_supports( 'post-thumbnails' ) ) : ?>
416
- (<?php _e( 'Your theme has to support post-thumbnails to have more choices', 'related-posts-thumbnails' ); ?>)
417
- <?php endif; ?>
418
- </td>
419
- </tr>
420
- <?php if ( current_theme_supports( 'post-thumbnails' ) ) : ?>
421
- <tr>
422
- <th scope="row"><?php _e( 'Show posts with featured image', 'related-posts-thumbnails' ); ?>:</th>
423
- <td>
424
- <input type="checkbox" name="onlywiththumbs" id="onlywiththumbs" value="1"
425
- <?php
426
- if ( $onlywiththumbs ) {
427
- echo 'checked="checked"'; }
428
- ?>
429
- />
430
- <label for="onlywiththumbs"><?php _e( 'Only those posts will be shown that has featured image', 'related-posts-thumbnails' ); ?></label><br />
431
- </td>
432
- </tr>
433
- <?php endif; ?>
434
- </table>
435
- </div>
436
- <div style="padding: 20px" id="relpoststh-custom-field"
437
- <?php
438
- if ( $relpoststh_thsource != 'custom-field' ) :
439
- ?>
440
- style="display:none" <?php endif; ?>>
441
- <h2><?php _e( 'Thumbnails source', 'related-posts-thumbnails' ); ?>:</h2>
442
- <table class="form-table">
443
- <tr valign="top">
444
- <th scope="row"><?php _e( 'Custom field name', 'related-posts-thumbnails' ); ?>:</th>
445
- <td>
446
- <input type="text" name="relpoststh_customfield" value="<?php echo get_option( 'relpoststh_customfield', $this->custom_field ); ?>" size="50"/>
447
- </td>
448
- </tr>
449
- <tr valign="top">
450
- <th scope="row"><?php _e( 'Size', 'related-posts-thumbnails' ); ?>:</th>
451
- <td>
452
- <label for="relpoststh_customwidth" id="relpoststh_customwidth">
453
- <?php _e( 'Width', 'related-posts-thumbnails' ); ?>:
454
- </label>
455
- <input type="number" min="1" name="relpoststh_customwidth" value="<?php echo get_option( 'relpoststh_customwidth', $this->custom_width ); ?>" size="3"/><?php _e( ' px', 'related-posts-thumbnails' ) ?>
456
- <br>
457
- <label for="relpoststh_customheight">
458
- <?php _e( 'Height', 'related-posts-thumbnails' ); ?>:
459
- </label>
460
- <input type="number" min="1" name="relpoststh_customheight" value="<?php echo get_option( 'relpoststh_customheight', $this->custom_height ); ?>" size="3"/><?php _e( ' px', 'related-posts-thumbnails' ) ?>
461
- <br>
462
- <span class='rpt-no-validate-error' style="display:none;color:red;"><?php _e( 'Only Digits are allow', 'related-posts-thumbnails' ); ?></span>
463
- </td>
464
- </tr>
465
- <tr valign="top">
466
- <th scope="row"><?php _e( 'Theme resize url', 'related-posts-thumbnails' ); ?>:</th>
467
- <td>
468
- <input type="text" name="relpoststh_theme_resize_url" value="<?php echo get_option( 'relpoststh_theme_resize_url', '' ); ?>" size="50"/>
469
- (<?php _e( 'If your theme resizes images, enter URL to its resizing PHP file', 'related-posts-thumbnails' ); ?>)
470
- </td>
471
- </tr>
472
- </table>
473
- </div>
474
- </div>
475
-
476
-
477
- <!-- DISPLAY SETTINGS -->
478
- <div class="postbox" style="padding: 20px; display:none;" id="content_style_options">
479
- <h2><?php _e( 'Style Options', 'related-posts-thumbnails' ); ?>:</h2>
480
- <table class="form-table">
481
-
482
- <!-- calling layouts from pro -->
483
- <?php
484
- // do_action('rptp_style_layouts');
485
- ?>
486
-
487
- <tr>
488
- <th scope="row"><?php _e( 'Output style', 'related-posts-thumbnails' ); ?>:</th>
489
- <td>
490
- <select name="relpoststh_output_style" id="relpoststh_output_style">
491
- <?php foreach ( $output_styles as $name => $title ) : ?>
492
- <option value="<?php echo $name; ?>"
493
- <?php
494
- if ( $relpoststh_output_style == $name ) {
495
- echo 'selected'; }
496
- ?>
497
- ><?php echo $title; ?></option>
498
- <?php endforeach; ?>
499
- </select>
500
- <span id="relpoststh_cleanhtml" style="display:
501
- <?php
502
- if ( $relpoststh_output_style == 'list' ) {
503
- echo 'inline';
504
- } else {
505
- echo 'none'; }
506
- ?>
507
- ;"><?php _e( 'Turn off plugin styles', 'related-posts-thumbnails' ); ?> <input type="checkbox" name="relpoststh_cleanhtml"
508
- <?php
509
- if ( $relpoststh_cleanhtml ) {
510
- echo 'checked="checked"'; }
511
- ?>
512
- /></span>
513
- </td>
514
- </tr>
515
- <tr valign="top">
516
- <th scope="row"><?php _e( 'Background color', 'related-posts-thumbnails' ); ?>:</th>
517
- <td>
518
- <input type="text" name="relpoststh_background" value="<?php echo get_option( 'relpoststh_background', $this->background ); ?>" data-default-color="<?php echo $this->background; ?>"/>
519
- </td>
520
- </tr>
521
- <tr valign="top">
522
- <th scope="row"><?php _e( 'Background color on mouse over', 'related-posts-thumbnails' ); ?>:</th>
523
- <td>
524
- <input type="text" name="relpoststh_hoverbackground" value="<?php echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground ); ?>" data-default-color="<?php echo $this->hoverbackground; ?>" />
525
- </td>
526
- </tr>
527
- <tr valign="top">
528
- <th scope="row"><?php _e( 'Border color', 'related-posts-thumbnails' ); ?>:</th>
529
- <td>
530
- <input type="text" name="relpoststh_bordercolor" value="<?php echo get_option( 'relpoststh_bordercolor', $this->border_color ); ?>" data-default-color="<?php echo $this->border_color; ?>"/>
531
- </td>
532
- </tr>
533
- <tr valign="top">
534
- <th scope="row"><?php _e( 'Font color', 'related-posts-thumbnails' ); ?>:</th>
535
- <td>
536
- <input type="text" name="relpoststh_fontcolor" value="<?php echo get_option( 'relpoststh_fontcolor', $this->font_color ); ?>" data-default-color="<?php echo $this->font_color; ?>"/>
537
- </td>
538
- </tr>
539
- <tr valign="top">
540
- <th scope="row"><?php _e( 'Font family', 'related-posts-thumbnails' ); ?>:</th>
541
- <td>
542
- <input type="text" name="relpoststh_fontfamily" value="<?php echo stripslashes( htmlspecialchars( get_option( 'relpoststh_fontfamily', $this->font_family ) ) ); ?>" size="50"/>
543
- </td>
544
- </tr>
545
- <tr valign="top">
546
- <th scope="row"><?php _e( 'Font size', 'related-posts-thumbnails' ); ?>:</th>
547
- <td>
548
- <input type="number" min="1" name="relpoststh_fontsize" value="<?php echo get_option( 'relpoststh_fontsize', $this->font_size ); ?>" size="7"/>
549
- <label for="relpoststh_fontsize"><?php _e( 'px', 'related-posts-thumbnails' ); ?></label>
550
- <span class='rpt-no-validate-error' style="display:none;color:red;"><?php _e( 'Only Digits are allow', 'related-posts-thumbnails' ); ?></span>
551
- </td>
552
- </tr>
553
- <tr valign="top">
554
- <th scope="row"><?php _e( 'Text maximum length', 'related-posts-thumbnails' ); ?>:</th>
555
- <td>
556
- <input type="number" min="0" name="relpoststh_textlength" value="<?php echo get_option( 'relpoststh_textlength', $this->text_length ); ?>" size="7"/>
557
- <label for="relpoststh_textlength"><?php _e( 'Set 0 for no title', 'related-posts-thumbnails' ); ?></label>
558
- <span class='rpt-no-validate-error' style="display:none;color:red;"><?php _e( 'Only Digits are allow', 'related-posts-thumbnails' ); ?></span>
559
- <br />
560
- </td>
561
- </tr>
562
- <tr valign="top">
563
- <th scope="row"><?php _e( 'Excerpt maximum length', 'related-posts-thumbnails' ); ?>:</th>
564
- <td>
565
- <input type="number" min="0" name="relpoststh_excerptlength" value="<?php echo get_option( 'relpoststh_excerptlength', $this->excerpt_length ); ?>" size="7"/>
566
- <label for="relpoststh_excerptlength"><?php _e( 'Set 0 for no excerpt', 'related-posts-thumbnails' ); ?></label>
567
- <span class='rpt-no-validate-error' style="display:none;color:red;"><?php _e( 'Only Digits are allow', 'related-posts-thumbnails' ); ?></span>
568
- <br />
569
- </td>
570
- </tr>
571
- <tr valign="top">
572
- <th scope="row"><?php _e( 'Text block height', 'related-posts-thumbnails' ); ?>:</th>
573
- <td>
574
- <input type="number" min="0" name="relpoststh_textblockheight" value="<?php echo get_option( 'relpoststh_textblockheight', $this->text_block_height ); ?>" size="7"/> px
575
- <span class='rpt-no-validate-error' style="display:none;color:red;"><?php _e( 'Only Digits are allow', 'related-posts-thumbnails' ); ?></span>
576
- </td>
577
- </tr>
578
- </table>
579
- </div>
580
- <div class="postbox" style="padding: 20px; display:none;" id="content_relation_options">
581
- <h2><?php _e( 'Relation Builder Options', 'related-posts-thumbnails' ); ?>:</h2>
582
- <table class="form-table">
583
- <tr valign="top">
584
- <th scope="row"><?php _e( 'Base relation on', 'related-posts-thumbnails' ); ?>:</th>
585
- <td>
586
- <?php if ( is_array( $relation_options ) && count( $relation_options ) ) : ?>
587
- <?php foreach ( $relation_options as $ro_key => $ro_name ) : ?>
588
- <input type="radio" name="relpoststh_relation" id="relpoststh_relation_<?php echo $ro_key; ?>" value="<?php echo $ro_key; ?>"
589
- <?php
590
- if ( $relpoststh_relation == $ro_key ) {
591
- echo 'checked="checked"'; }
592
- ?>
593
- />
594
- <label for="relpoststh_relation_<?php echo $ro_key; ?>"><?php echo $ro_name; ?></label><br />
595
- <?php endforeach; ?>
596
- <?php endif; ?>
597
- <div id="custom_taxonomies" style="display:
598
- <?php
599
- if ( $relpoststh_relation == 'custom' ) {
600
- echo 'inline';
601
- } else {
602
- echo 'none'; }
603
- ?>
604
- ;">
605
- <?php if ( is_array( $custom_taxonomies ) && count( $custom_taxonomies ) ) : ?>
606
- <?php foreach ( $custom_taxonomies as $custom_taxonomy ) : ?>
607
- <input type="checkbox" name="relpoststh_custom_taxonomies[]" id="ct_<?php echo $custom_taxonomy; ?>" value="<?php echo $custom_taxonomy; ?>"
608
- <?php
609
- if ( in_array( $custom_taxonomy, $relpoststh_custom_taxonomies ) ) {
610
- echo 'checked="checked"'; }
611
- ?>
612
- />
613
- <label for="ct_<?php echo $custom_taxonomy; ?>"><?php echo $custom_taxonomy; ?></label>
614
- <?php endforeach; ?>
615
- <?php endif; ?>
616
- </div>
617
- </td>
618
- </tr>
619
- </table>
620
- </div>
621
- <!-- <input name="Submit" value="<?php _e( 'Save Changes', 'related-posts-thumbnails' ); ?>" type="submit" class="button-primary"> -->
622
- </div>
623
- </div>
624
-
625
- <div class="wpbr-button-container bottom">
626
- <div class="wpbr-social-links alignleft">
627
- <a href="https://profiles.wordpress.org/hiddenpearls/" class="wordpress" target="_blank"><span class="dashicons dashicons-wordpress"></span></a>
628
- </div>
629
- <input type="submit" name="Submit" class="wpb-rpt-settings-submit button button-primary button-big" value="<?php esc_html_e( 'Save Settings','related-posts-thumbnails' ); ?>" id="wpb_rpt_save_setting_bottom">
630
- </div>
631
- </div>
632
-
633
- <div class="metabox-holder wpbr-sidebar">
634
- <div class="sidebar postbox">
635
- <h2><?php esc_html_e( 'Spread the Word' , 'related-posts-thumbnails' ); ?></h2>
636
- <ul>
637
- <li>
638
- <a href="http://twitter.com/share?text=This is Best Related Post Thumbnails Plugin for WordPress&url=https://wordpress.org/support/view/plugin-reviews/related-posts-thumbnails" data-count="none" class="button twitter" target="_blank" title="Post to Twitter Now"><?php esc_html_e( 'Share on Twitter' , 'related-posts-thumbnails' ); ?><span class="dashicons dashicons-twitter"></span></a>
639
- </li>
640
-
641
- <li>
642
- <a href="https://www.facebook.com/sharer/sharer.php?u=https://wordpress.org/support/view/plugin-reviews/related-posts-thumbnails" class="button facebook" target="_blank" title="Share with your facebook friends about this awesome plugin."><?php esc_html_e( 'Share on Facebook' , 'related-posts-thumbnails' ); ?><span class="dashicons dashicons-facebook"></span>
643
- </a>
644
- </li>
645
-
646
- <li>
647
- <a href="https://wordpress.org/support/view/plugin-reviews/related-posts-thumbnails?filter=5" class="button wordpress" target="_blank" title="Rate on Wordpress.org"><?php esc_html_e( 'Rate on Wordpress.org' , 'related-posts-thumbnails' ); ?><span class="dashicons dashicons-wordpress"></span>
648
- </a>
649
- </li>
650
- </ul>
651
- </div>
652
-
653
- <div class="sidebar postbox">
654
-
655
- <h2><?php esc_html_e( 'Subscribe Newsletter' , 'related-posts-thumbnails' ); ?></h2>
656
- <ul>
657
- <li>
658
- <label for="">Email</label>
659
- <input type="email" name="subscriber_mail" value="<?php echo get_option( 'admin_email' ); ?>" id="rpt_subscribe_mail">
660
- <p class='rpt_subscribe_warning'></p>
661
- </li>
662
- <li>
663
- <label for="">Name</label>
664
- <input type="text" name="subscriber_name" id="rpt_subscribe_name" value="<?php echo wp_get_current_user()->display_name; ?>" id="rpt_subscribe_mail">
665
- </li>
666
- <li>
667
- <input type="submit" value="Subscribe Now" class="button button-primary button-big" id='rpt_subscribe_btn' />
668
- <img src="<?php echo admin_url( 'images/spinner.gif' ); ?>" class='rpt_subscribe_loader' style="display:none" />
669
- </li>
670
- <li>
671
- <p class='rpt_return_message'></p>
672
- </li>
673
- </ul>
674
- </div>
675
-
676
- <div class="sidebar postbox">
677
- <h2><?php esc_html_e( 'Recommended Plugins' , 'related-posts-thumbnails' ); ?></h2>
678
- <!-- <p>Following are the plugins highly recommend by Team WPBrigade.</p> -->
679
- <ul class="plugins_lists">
680
- <li>
681
- <a href="https://wpbrigade.com/wordpress/plugins/loginpress-pro/?utm_source=related-posts-lite&utm_medium=sidebar&utm_campaign=pro-upgrade" data-count="none" target="_blank" title="Post to Twitter Now"><?php esc_html_e( 'LoginPress - Login Customizer' , 'related-posts-thumbnails' ); ?></a>
682
- </li>
683
-
684
- <li>
685
- <a href="https://analytify.io/ref/73/?utm_source=related-posts-lite&utm_medium=sidebar&utm_campaign=pro-upgrade" target="_blank" title="Share with your facebook friends about this awesome plugin."><?php esc_html_e( 'Google Analytics by Analytify' , 'related-posts-thumbnails' ); ?></span>
686
- </a>
687
- </li>
688
-
689
- <li>
690
- <a href="http://wpbrigade.com/recommend/maintenance-mode" target="_blank" title="Under Construction & Maintenance mode"><?php esc_html_e( 'Under Construction & Maintenance mode' , 'related-posts-thumbnails' ); ?></span>
691
- </a>
692
- </li>
693
- </ul>
694
- </div>
695
- </div>
696
-
697
- </div>
698
- </form>
699
- <p style="margin-top: 40px;"><small><?php _e( 'If you experience some problems with this plugin please let me know about it on <a target="_blank" href="https://wpbrigade.com/wordpress/plugins/related-posts/">Plugin\'s homepage</a>. If you think this plugin is awesome please vote on <a target="_blank" href="https://wordpress.org/plugins/related-posts-thumbnails/">WordPress plugin page</a>. Thanks!', 'related-posts-thumbnails' ); ?></small></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
  // Admin interface
4
+ if ( isset( $_POST[ 'action' ] ) && ( $_POST[ 'action' ] == 'update' ) ) {
5
+ if ( !current_user_can( 'manage_options' ) ) {
6
+ wp_die( __( 'No access', 'related-posts-thumbnails' ) );
7
+ }
8
+ check_admin_referer( 'related-posts-thumbnails' );
9
+ $validation = true;
10
+
11
+ $set_date = isset( $_POST[ 'rpt_post_include' ] ) ? sanitize_text_field( wp_unslash( $_POST[ 'rpt_post_include' ] ) ) : '';
12
+
13
+ if ( $validation ) {
14
+
15
+ if ( isset( $_POST[ 'relpoststh_single_only' ] ) ) {
16
+ update_option( 'relpoststh_single_only', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_single_only' ] ) ) );
17
+ } else {
18
+ update_option( 'relpoststh_single_only', '0' );
19
+ }
20
+
21
+ if ( isset( $_POST[ 'relpoststh_post_types' ] ) ) {
22
+ update_option( 'relpoststh_post_types', array_map( 'sanitize_text_field', wp_unslash( $_POST[ 'relpoststh_post_types' ] ) ) );
23
+ } else {
24
+ update_option( 'relpoststh_post_types', array ());
25
+ }
26
+
27
+ if ( isset( $_POST[ 'onlywiththumbs' ] ) ) {
28
+ update_option( 'relpoststh_onlywiththumbs', sanitize_text_field( wp_unslash( $_POST[ 'onlywiththumbs' ] ) ) );
29
+ } else {
30
+ update_option( 'relpoststh_onlywiththumbs', '0' );
31
+ }
32
+
33
+ // if ( isset( $_POST[ 'relpoststh_show_date' ] ) ) {
34
+ // update_option( 'relpoststh_show_date', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_show_date' ] ) ) );
35
+ // } else {
36
+ // update_option( 'relpoststh_show_date', '0' );
37
+ // }
38
+
39
+ if ( isset( $_POST[ 'relpoststh_output_style' ] ) ) {
40
+ update_option( 'relpoststh_output_style', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_output_style' ] ) ) );
41
+ }
42
+
43
+ if ( isset( $_POST[ 'relpoststh_cleanhtml' ] ) ) {
44
+ update_option( 'relpoststh_cleanhtml', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_cleanhtml' ] ) ) );
45
+ } else {
46
+ update_option( 'relpoststh_cleanhtml', '0' );
47
+ }
48
+
49
+ if ( isset( $_POST[ 'relpoststh_auto' ] ) ) {
50
+ update_option( 'relpoststh_auto', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_auto' ] ) ) );
51
+ } else {
52
+ update_option( 'relpoststh_auto', '0' );
53
+ }
54
+
55
+ if ( isset( $_POST[ 'relpoststh_top_text' ] ) ) {
56
+ update_option( 'relpoststh_top_text', wp_kses( $_POST[ 'relpoststh_top_text' ], $this->wp_kses_rp_args ) );
57
+ }
58
+
59
+
60
+ if ( isset( $_POST[ 'relpoststh_number' ] ) ) {
61
+ update_option( 'relpoststh_number', absint( $_POST[ 'relpoststh_number' ] ) );
62
+ }
63
+
64
+ if ( isset( $_POST[ 'relpoststh_relation' ] ) ) {
65
+ update_option( 'relpoststh_relation', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_relation' ] ) ) );
66
+ }
67
+
68
+ if ( isset( $_POST[ 'relpoststh_default_image' ] ) ) {
69
+ update_option( 'relpoststh_default_image', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_default_image' ] ) ) );
70
+ }
71
+
72
+ if ( isset( $_POST[ 'relpoststh_poststhname' ] ) ) {
73
+ update_option( 'relpoststh_poststhname', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_poststhname' ] ) ) );
74
+ }
75
+
76
+ if ( isset( $_POST[ 'relpoststh_background' ] ) ) {
77
+ update_option( 'relpoststh_background', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_background' ] ) ) );
78
+ }
79
+
80
+ if ( isset( $_POST[ 'relpoststh_hoverbackground' ] ) ) {
81
+ update_option( 'relpoststh_hoverbackground', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_hoverbackground' ] ) ) );
82
+ }
83
+
84
+
85
+ if ( isset( $_POST[ 'relpoststh_bordercolor' ] ) ) {
86
+ update_option( 'relpoststh_bordercolor', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_bordercolor' ] ) ) );
87
+ }
88
+
89
+ if ( isset( $_POST[ 'relpoststh_fontcolor' ] ) ) {
90
+ update_option( 'relpoststh_fontcolor', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_fontcolor' ] ) ) );
91
+ }
92
+
93
+ if ( isset( $_POST[ 'relpoststh_fontsize' ] ) ) {
94
+ update_option( 'relpoststh_fontsize', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_fontsize' ] ) ) );
95
+ }
96
+
97
+ if ( isset( $_POST[ 'relpoststh_fontfamily' ] ) ) {
98
+ update_option( 'relpoststh_fontfamily', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_fontfamily' ] ) ) );
99
+ }
100
+
101
+ if ( isset( $_POST[ 'relpoststh_textlength' ] ) ) {
102
+ update_option( 'relpoststh_textlength', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_textlength' ] ) ) );
103
+ }
104
+
105
+ if ( isset( $_POST[ 'relpoststh_excerptlength' ] ) ) {
106
+ update_option( 'relpoststh_excerptlength', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_excerptlength' ] ) ) );
107
+ }
108
+
109
+ if ( isset( $_POST[ 'relpoststh_thsource' ] ) ) {
110
+ update_option( 'relpoststh_thsource', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_thsource' ] ) ) );
111
+ }
112
+
113
+ if ( isset( $_POST[ 'relpoststh_customfield' ] ) ) {
114
+ update_option( 'relpoststh_customfield', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_customfield' ] ) ) );
115
+ }
116
+
117
+ if ( isset( $_POST[ 'relpoststh_theme_resize_url' ] ) ) {
118
+ update_option( 'relpoststh_theme_resize_url', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_theme_resize_url' ] ) ) );
119
+ }
120
+
121
+ if ( isset( $_POST[ 'relpoststh_customwidth' ] ) ) {
122
+ update_option( 'relpoststh_customwidth', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_customwidth' ] ) ) );
123
+ }
124
+
125
+ if ( isset( $_POST[ 'relpoststh_customheight' ] ) ) {
126
+ update_option( 'relpoststh_customheight', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_customheight' ] ) ) );
127
+ }
128
+
129
+ if ( isset( $_POST[ 'relpoststh_textblockheight' ] ) ) {
130
+ update_option( 'relpoststh_textblockheight', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_textblockheight' ] ) ) );
131
+ }
132
+
133
+ if ( isset( $_POST[ 'relpoststh_customwidth' ] ) ) {
134
+ update_option( 'relpoststh_customwidth', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_customwidth' ] ) ) );
135
+ }
136
+
137
+ if ( isset( $_POST[ 'rpt_post_sort' ] ) ) {
138
+ update_option( 'rpt_post_sort', sanitize_text_field( wp_unslash( $_POST[ 'rpt_post_sort' ] ) ) );
139
+ }
140
+
141
+ if ( isset( $_POST[ 'relpoststh_categories' ] ) ) {
142
+ update_option( 'relpoststh_categories', array_map( 'sanitize_text_field', wp_unslash( $_POST[ 'relpoststh_categories' ] ) ) );
143
+ } else {
144
+ update_option( 'relpoststh_categories', array ());
145
+ }
146
+
147
+ if ( isset( $_POST[ 'relpoststh_categoriesall' ] ) ) {
148
+ update_option( 'relpoststh_categoriesall', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_categoriesall' ] ) ) );
149
+ } else {
150
+ update_option( 'relpoststh_categoriesall', '' );
151
+ }
152
+
153
+ if ( isset( $_POST[ 'relpoststh_show_categoriesall' ] ) ) {
154
+ update_option( 'relpoststh_show_categoriesall', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_show_categoriesall' ] ) ) );
155
+ } else {
156
+ update_option( 'relpoststh_show_categoriesall', '' );
157
+ }
158
+
159
+ if ( isset( $_POST[ 'relpoststh_show_categories' ] ) ) {
160
+ update_option( 'relpoststh_show_categories', array_map( 'sanitize_text_field', wp_unslash( $_POST[ 'relpoststh_show_categories' ] ) ) );
161
+ } else {
162
+ update_option( 'relpoststh_show_categories', array ());
163
+ }
164
+
165
+ if ( isset( $_POST[ 'relpoststh_devmode' ] ) ) {
166
+ update_option( 'relpoststh_devmode', sanitize_text_field( wp_unslash( $_POST[ 'relpoststh_devmode' ] ) ) );
167
+ } else {
168
+ update_option( 'relpoststh_devmode', '0' );
169
+ }
170
+
171
+ update_option( 'relpoststh_startdate', $set_date );
172
+
173
+ if ( isset( $_POST[ 'relpoststh_custom_taxonomies' ] ) ) {
174
+ update_option( 'relpoststh_custom_taxonomies', array_map( 'sanitize_text_field', wp_unslash( $_POST[ 'relpoststh_custom_taxonomies' ] ) ) );
175
+ } else {
176
+ update_option( 'relpoststh_custom_taxonomies', array ());
177
+ }
178
+
179
+ // Updating layout option
180
+ // if ( isset( $_POST['relpoststh_layout_style'] ) ) {
181
+ // update_option( 'relpoststh_layout_style', sanitize_text_field( $_POST['relpoststh_layout_style'] ) );
182
+ // }
183
+
184
+ echo "<div class='updated fade'><p>" . __( 'Settings updated', 'related-posts-thumbnails' ) . '</p></div>';
185
+ } else {
186
+ echo "<div class='error fade'><p>" . __( 'Settings update failed', 'related-posts-thumbnails' ) . '. ' . $error . '</p></div>';
187
+ }
188
  }
189
  $available_sizes = array(
190
+ 'thumbnail' => 'thumbnail',
191
+ 'medium' => 'medium'
192
  );
193
  if ( current_theme_supports( 'post-thumbnails' ) ) {
194
+ global $_wp_additional_image_sizes;
195
+ if ( is_array( $_wp_additional_image_sizes ) ) {
196
+ $available_sizes = array_merge( $available_sizes, $_wp_additional_image_sizes );
197
+ }
198
  }
199
 
200
  $relpoststh_single_only = get_option( 'relpoststh_single_only', $this->single_only );
205
  $relpoststh_devmode = get_option( 'relpoststh_devmode', $this->devmode );
206
  $relpoststh_categoriesall = get_option( 'relpoststh_categoriesall', $this->categories_all );
207
  $relpoststh_categories = get_option( 'relpoststh_categories' );
208
+ // $relpoststh_show_date = get_option( 'relpoststh_show_date', '0' );
209
  $relpoststh_show_categories = get_option( 'relpoststh_show_categories', get_option( 'relpoststh_categories' ) );
210
  $relpoststh_show_categoriesall = get_option( 'relpoststh_show_categoriesall', $relpoststh_categoriesall );
211
  $onlywiththumbs = get_option( 'relpoststh_onlywiththumbs', false );
212
  $relpoststh_startdate = explode( '-', get_option( 'relpoststh_startdate' ) );
213
  $relpoststh_output_style = get_option( 'relpoststh_output_style', $this->output_style );
214
+ $thsources = array( 'post-thumbnails' => __( 'Post thumbnails', 'related_posts_thumbnails' ),'custom-field' => __( 'Custom field', 'related_posts_thumbnails' ) );
 
 
 
215
  $categories = get_categories();
216
  if ( $this->wp_version >= 3 ) {
217
+ $post_types = get_post_types( array( 'public' => 1 ) );
218
  } else {
219
+ $post_types = get_post_types();
220
  }
221
+
222
  $relpoststh_post_types = get_option( 'relpoststh_post_types', $this->post_types );
223
+
224
+ $output_styles = array(
225
  'div' => __( 'Blocks', 'related-posts-thumbnails' ),
226
+ 'list' => __( 'List', 'related-posts-thumbnails' ) );
227
+
228
+ $relation_options = array(
229
+ 'categories' => __( 'Categories', 'related-posts-thumbnails' ),
230
+ 'tags' => __( 'Tags', 'related-posts-thumbnails' ),
231
+ 'both' => __( 'Categories and Tags', 'related-posts-thumbnails' ),
232
+ 'no' => __( 'Random', 'related-posts-thumbnails' ),
233
+ 'custom' => __( 'Custom', 'related-posts-thumbnails' )
234
  );
235
+
236
  if ( $this->wp_version >= 3 ) {
237
+ $custom_taxonomies = get_taxonomies( array(
238
+ 'public' => 1
239
+ ) );
240
+ $relpoststh_custom_taxonomies = get_option( 'relpoststh_custom_taxonomies', $this->custom_taxonomies );
241
+ if ( !is_array( $relpoststh_custom_taxonomies ) ) {
242
+ $relpoststh_custom_taxonomies = array();
243
+ }
244
  } else {
245
+ $relation_options[ 'custom' ] .= ' ' . __( '(This option is available for WP v3+ only)', 'related_posts_thumbnails' );
246
  }
247
  ?>
248
 
249
  <div class="wrap relpoststh">
250
 
251
  <div class="rpt-top-bar">
252
+ <a href="<?php echo esc_url( 'https://wpbrigade.com/' ); ?>"><img src="<?php echo plugins_url( 'assets/images/rpt-logo.png', dirname( __FILE__ ) ); ?>" alt="<?php echo esc_attr( 'Related Post Thumbnails' ); ?>"></a>
253
+ <div class="rpt-top-bar-content">
254
+ <h3><?php _e( 'Related Post Thumbnails - Settings', 'related-posts-thumbnails' ); ?>:</h3>
255
+ <p><?php _e( '<strong>Related Post Thumbnails</strong> by <strong><a href=" ' . esc_url( "https://wpbrigade.com/" ) . ' ">WPBrigade</a></strong>.', 'related-posts-thumbnails' ); ?></p>
256
+ </div>
257
  </div>
258
 
259
  <div class="icon32" id="icon-options-general"><br></div>
260
  <h2><?php _e( 'Related Posts Thumbnails Settings', 'related-posts-thumbnails' ); ?></h2>
261
 
262
  <form action="?page=related-posts-thumbnails" method="POST" style="clear:both;">
263
+ <input type="hidden" name="action" value="update" />
264
+ <?php wp_nonce_field( 'related-posts-thumbnails' ); ?>
265
+
266
+ <div class="wpbr-wrap"><div class="wpbr-tabsWrapper">
267
+ <div class="wpbr-button-container top">
268
+ <div class="setting-notification">
269
+ <?php echo __( 'Settings have changed, you should save them!', 'related-posts-thumbnails' ); ?>
270
+ </div>
271
+ <input type="submit" name="Submit" class="wpb-rpt-settings-submit button button-primary button-big"
272
+ value="<?php esc_html_e( 'Save Settings', 'related-posts-thumbnails' ); ?>" id="wpb_rpt_save_setting_top">
273
+ </div>
274
+
275
+ <div id="relpoststh-settings" class="">
276
+ <ul class="nav-tab-wrapper">
277
+ <li>
278
+ <a href="#content_general_options" class="nav-tab" id="content_general_options-tab">
279
+ <?php _e( 'General Display Options', 'related-posts-thumbnails' ); ?>
280
+ </a>
281
+ </li>
282
+ <li>
283
+ <a href="#content_thumbnail_options" class="nav-tab" id="content_thumbnail_options-tab">
284
+ <?php _e( 'Thumbnails', 'related-posts-thumbnails' ); ?>
285
+ </a>
286
+ </li>
287
+ <li>
288
+ <a href="#content_style_options" class="nav-tab" id="content_style_options-tab">
289
+ <?php _e( 'Style Options', 'related-posts-thumbnails' ); ?>
290
+ </a>
291
+ </li>
292
+ <li>
293
+ <a href="#content_relation_options" class="nav-tab" id="content_relation_options-tab">
294
+ <?php _e( 'Relation Builder Options', 'related-posts-thumbnails' ); ?>
295
+ </a>
296
+ </li>
297
+ </ul>
298
+
299
+ <div class="metabox-holder rpth-setting-options">
300
+ <div class="postbox" style="padding: 20px" id="content_general_options">
301
+ <h2>
302
+ <?php _e( 'General Display Options', 'related-posts-thumbnails' ); ?>
303
+ </h2>
304
+
305
+ <table class="form-table">
306
+ <tr valign="top">
307
+ <th scope="row">
308
+ <?php _e( 'Automatically append to the post content', 'related-posts-thumbnails' ); ?>:
309
+ </th>
310
+ <td>
311
+ <input type="checkbox" name="relpoststh_auto" id="relpoststh_auto" value="1"
312
+ <?php
313
+ if ( $relpoststh_auto ) {
314
+ echo 'checked="checked"';
315
+ }
316
+ ?>
317
+ />
318
+ <label for="relpoststh_auto">
319
+ <p class="description rpth-discription" >
320
+ <?php _e( 'Or use the following snippet in The Loop <b>&lt;?php get_related_posts_thumbnails(); ?&gt;</b>', 'related-posts-thumbnails' ); ?>
321
+ </p>
322
+ </label>
323
+ <br />
324
+ </td>
325
+ </tr>
326
+ <tr valign="top">
327
+ <th scope="row">
328
+ <?php _e( 'Developer mode', 'related-posts-thumbnails' ); ?>:
329
+ </th>
330
+ <td>
331
+ <input type="checkbox" name="relpoststh_devmode" id="relpoststh_devmode" value="1"
332
+ <?php
333
+ if ( $relpoststh_devmode ) {
334
+ echo 'checked="checked"';
335
+ }
336
+ ?>
337
+ />
338
+ <label for="relpoststh_devmode">
339
+ <p class="description rpth-discription">
340
+ <?php _e( 'This will add debugging information in HTML source', 'related-posts-thumbnails' ); ?>
341
+ </p>
342
+ </label>
343
+ <br />
344
+ </td>
345
+ </tr>
346
+ <tr valign="top">
347
+ <th scope="row">
348
+ <?php _e( 'Display related posts', 'related-posts-thumbnails' ); ?>:
349
+ </th>
350
+ <td>
351
+ <input type="checkbox" name="relpoststh_single_only" id="relpoststh_single_only" value="1"
352
+ <?php
353
+ if ( $relpoststh_single_only ) {
354
+ echo 'checked="checked"';
355
+ }
356
+ ?>
357
+ />
358
+ <label for="relpoststh_single_only">
359
+ <?php _e( 'On single posts only', 'related-posts-thumbnails' ); ?>
360
+ </label>
361
+ <br />
362
+ </td>
363
+ </tr>
364
+ <tr valign="top">
365
+ <th scope="row">
366
+ <?php _e( 'Post types', 'related-posts-thumbnails' ); ?>:
367
+ </th>
368
+ <td>
369
+ <?php
370
+ if ( is_array( $post_types ) && count( $post_types ) ):
371
+ foreach ( $post_types as $post_type ):
372
+ ?>
373
+ <input type="checkbox" name="relpoststh_post_types[]"
374
+ id="pt_<?php echo $post_type; ?>"
375
+ value="<?php echo $post_type; ?>"
376
+ <?php
377
+ if ( in_array( $post_type, $relpoststh_post_types ) ) {
378
+ echo 'checked="checked"';
379
+ }
380
+ ?>
381
+ />
382
+ <label for="pt_<?php echo $post_type; ?>">
383
+ <?php echo $post_type; ?>
384
+ </label>
385
+
386
+ <?php
387
+ endforeach;
388
+ endif;
389
+ ?>
390
+ </td>
391
+ </tr>
392
+ <tr valign="top">
393
+ <th scope="row">
394
+ <?php _e( 'Display related posts on categories', 'related-posts-thumbnails' ); ?>:
395
+ </th>
396
+ <td>
397
+ <?php
398
+ $this->display_categories_list( $relpoststh_categoriesall, $categories, $relpoststh_categories, 'relpoststh_categoriesall', 'relpoststh_categories' );
399
+ ?>
400
+ </td>
401
+ </tr>
402
+ <tr valign="top">
403
+ <th scope="row">
404
+ <?php _e( 'Categories will appear in related posts', 'related-posts-thumbnails' ); ?>:
405
+ </th>
406
+ <td>
407
+ <?php
408
+ $this->display_categories_list( $relpoststh_show_categoriesall, $categories, $relpoststh_show_categories, 'relpoststh_show_categoriesall', 'relpoststh_show_categories' );
409
+ ?>
410
+ </td>
411
+ </tr>
412
+ <!-- <tr valign="top">
413
+ <th scope="row">
414
+ <?php // _e( 'Show date under posts', 'related-posts-thumbnails' ); ?>:
415
+ </th>
416
+ <td>
417
+ <input type="checkbox" name="relpoststh_show_date" id="relpoststh_show_date" value="1"
418
+ <?php
419
+ // if ( $relpoststh_show_date == '1' ) {
420
+ // echo 'checked="checked"';
421
+ // }
422
+ ?>
423
+ />
424
+ </td>
425
+ </tr> -->
426
+ <tr>
427
+ <th scope="row">
428
+ <?php _e( 'Include posts after', 'related-posts-thumbnails' ); ?>:
429
+ </th>
430
+ <td>
431
+ <input type="text" class="rpt_post_include" name="rpt_post_include"
432
+ value="<?php echo get_option( 'relpoststh_startdate' ); ?>"
433
+ >
434
+ <button type="button" class="button rpt_clear_date">Clear</button>
435
+ <label for="relpoststh_excerptlength">
436
+ <p class="description">
437
+ <?php _e( 'Leave empty for all posts dates', 'related-posts-thumbnails' ); ?>
438
+ </p>
439
+ </label>
440
+ <br />
441
+ </td>
442
+ </tr>
443
+ <tr>
444
+ <th scope="row">
445
+ <?php _e( 'Sort by', 'related-posts-thumbnails' ); ?>:
446
+ </th>
447
+ <td>
448
+ <select class="rpt_post_sort" name="rpt_post_sort">
449
+ <option value="rand"
450
+ <?php
451
+ if( get_option('rpt_post_sort') == 'rand' ) {
452
+ echo 'selected';
453
+ }
454
+ ?> >
455
+ <?php _e( 'Random', 'related-posts-thumbnails' ); ?>
456
+ </option>
457
+ <option value="latest"
458
+ <?php
459
+ if( get_option('rpt_post_sort') == 'latest' ) {
460
+ echo 'selected';
461
+ }
462
+ ?> >
463
+ <?php _e( 'Latest posts', 'related-posts-thumbnails' ); ?>
464
+ </option>
465
+ </select>
466
+ </td>
467
+ </tr>
468
+ <tr>
469
+ <th scope="row">
470
+ <?php _e( 'Top text', 'related-posts-thumbnails' ); ?>:
471
+ </th>
472
+ <td>
473
+ <input type="text" name="relpoststh_top_text"
474
+ value="<?php echo stripslashes( htmlspecialchars( get_option( 'relpoststh_top_text', $this->top_text ) ) ); ?>" size="50"/>
475
+ </td>
476
+ </tr>
477
+ <tr>
478
+ <th scope="row">
479
+ <?php _e( 'Number of posts to display', 'related-posts-thumbnails' ); ?>:
480
+ </th>
481
+ <td>
482
+ <input type="number" min="1" name="relpoststh_number"
483
+ value="<?php echo get_option( 'relpoststh_number', $this->number ); ?>" size="2"/>
484
+ <span class='rpt-no-validate-error' style="display:none;">
485
+ <?php _e( 'Only Digits are allowed', 'related-posts-thumbnails' ); ?>
486
+ </span>
487
+ </td>
488
+ </tr>
489
+ <!-- <table class="form-table"> -->
490
+ <tr>
491
+ <th scope="row">
492
+ <?php _e( 'Default image', 'related-posts-thumbnails' ); ?>:
493
+ </th>
494
+ <td>
495
+ <?php
496
+ // $imgid =(isset( $instance[ 'imgid' ] )) ? $instance[ 'imgid' ] : "";
497
+ // $img = wp_get_attachment_image_src($imgid, 'thumbnail');
498
+ // var_dump($img);
499
+ ?>
500
+ <!-- <input type="text" value="<?php // echo get_option( 'relpoststh_default_image', $this->default_image ); ?>" class="regular-text process_custom_images" id="process_custom_images" name=""> -->
501
+ <img
502
+ src="<?php echo get_option( 'relpoststh_default_image', $this->default_image ); ?>"
503
+ id="relpoststh_default_image_prev" class="regular-text process_custom_images" height="200" width="30">
504
+ <div class="relposts-button-section">
505
+ <button class="relpoststh_set_def_image button">
506
+ <?php _e( 'Set Image', 'related-posts-thumbnails' ); ?>
507
+ </button>
508
+ <button
509
+ value="<?php echo esc_url( plugins_url( '../img/default.png', __FILE__ ) ); ?>"
510
+ class="relpoststh_set_plug_image button">
511
+ <?php _e( 'Default Image', 'related-posts-thumbnails' ); ?>
512
+ </button>
513
+ <input type="hidden" name="relpoststh_default_image" id="relpoststh_default_image"
514
+ value="<?php echo get_option( 'relpoststh_default_image', $this->default_image ); ?>" size="50"/>
515
+ </div>
516
+ </td>
517
+ </tr>
518
+ <!-- </table> -->
519
+ </table>
520
+ </div>
521
+
522
+
523
+ <div class="postbox" style="padding: 20px; display:none;" id="content_thumbnail_options">
524
+ <h2>
525
+ <?php _e( 'Thumbnails', 'related-posts-thumbnails' ); ?>
526
+ </h2>
527
+
528
+ <table class="form-table">
529
+ <tr>
530
+ <th>
531
+ <?php _e( 'Select thumbnails source', 'related-posts-thumbnails' ); ?>
532
+ </th>
533
+ <td>
534
+ <select class="select-style" name="relpoststh_thsource" id="relpoststh_thsource">
535
+ <?php foreach ( $thsources as $name => $title ): ?>
536
+ <option value="<?php echo $name; ?>"
537
+ <?php
538
+ if ( $relpoststh_thsource == $name ) {
539
+ echo 'selected';
540
+ }
541
+ ?> >
542
+ <?php echo $title; ?>
543
+ </option>
544
+ <?php endforeach; ?>
545
+ </select>
546
+ </td>
547
+ </tr>
548
+ </table>
549
+
550
+ <div id="relpoststh-post-thumbnails">
551
+ <table class="form-table">
552
+ <tr valign="top">
553
+ <th scope="row">
554
+ <?php _e( 'Related posts thumbnail size', 'related-posts-thumbnails' ); ?>:
555
+ </th>
556
+ <td>
557
+ <select name="relpoststh_poststhname">
558
+ <?php foreach ( $available_sizes as $size_name => $size ): ?>
559
+ <option
560
+ <?php
561
+ if ( $size_name == get_option( 'relpoststh_poststhname', $this->poststhname ) ) {
562
+ echo 'selected';
563
+ }
564
+ ?> >
565
+ <?php echo $size_name; ?>
566
+ </option>
567
+ <?php endforeach; ?>
568
+ </select>
569
+ <?php if ( !current_theme_supports( 'post-thumbnails' ) ): ?>
570
+ (<?php
571
+ _e( 'Your theme has to support post-thumbnails to have more choices', 'related-posts-thumbnails' );
572
+ ?>)
573
+ <?php endif; ?>
574
+ </td>
575
+ </tr>
576
+
577
+ <?php
578
+ if ( current_theme_supports( 'post-thumbnails' ) ):
579
+ ?>
580
+ <tr>
581
+ <th scope="row">
582
+ <?php _e( 'Show posts with featured image', 'related-posts-thumbnails' ); ?>:
583
+ </th>
584
+ <td>
585
+ <input type="checkbox" name="onlywiththumbs" id="onlywiththumbs" value="1"
586
+ <?php
587
+ if ( $onlywiththumbs ) {
588
+ echo 'checked="checked"';
589
+ }
590
+ ?>
591
+ />
592
+ <label for="onlywiththumbs">
593
+ <p class="description rpth-discription">
594
+ <?php _e( 'Only those posts will be shown that has featured image', 'related-posts-thumbnails' ); ?>
595
+ </p>
596
+ </label>
597
+ <br />
598
+ </td>
599
+ </tr>
600
+ <?php endif; ?>
601
+ </table>
602
+ </div>
603
+
604
+ <div id="relpoststh-custom-field">
605
+ <table class="form-table">
606
+ <tr valign="top">
607
+ <th scope="row">
608
+ <?php _e( 'Custom field name', 'related-posts-thumbnails' ); ?>:
609
+ </th>
610
+ <td>
611
+ <input type="text" name="relpoststh_customfield"
612
+ value="<?php echo get_option( 'relpoststh_customfield', $this->custom_field ); ?>" size="50"/>
613
+ </td>
614
+ </tr>
615
+ <tr valign="top">
616
+ <th scope="row">
617
+ <?php _e( 'Size', 'related-posts-thumbnails' ); ?>:
618
+ </th>
619
+ <td>
620
+ <label for="relpoststh_customwidth" id="relpoststh_customwidth">
621
+ <?php _e( 'Width', 'related-posts-thumbnails' ); ?>:
622
+ </label>
623
+ <input type="number" min="1" name="relpoststh_customwidth"
624
+ value="<?php echo get_option( 'relpoststh_customwidth', $this->custom_width ); ?>" size="3"/>
625
+ <p class="description rpth-discription"><?php _e( ' px', 'related-posts-thumbnails' ); ?></p>
626
+ <br>
627
+ <label for="relpoststh_customheight">
628
+ <?php _e( 'Height', 'related-posts-thumbnails' ); ?>:
629
+ </label>
630
+ <input type="number" min="1" name="relpoststh_customheight"
631
+ value="<?php echo get_option( 'relpoststh_customheight', $this->custom_height );?>" size="3"/>
632
+ <p class="description rpth-discription"><?php _e( ' px', 'related-posts-thumbnails' ); ?></p>
633
+ <br>
634
+ <span class='rpt-no-validate-error' style="display:none;">
635
+ <?php _e( 'Only Digits are allowed', 'related-posts-thumbnails' ); ?>
636
+ </span>
637
+ </td>
638
+ </tr>
639
+ <tr valign="top">
640
+ <th scope="row">
641
+ <?php _e( 'Theme resize url', 'related-posts-thumbnails' ); ?>:
642
+ </th>
643
+ <td>
644
+ <input type="text" name="relpoststh_theme_resize_url"
645
+ value="<?php echo get_option( 'relpoststh_theme_resize_url', '' ); ?>" size="50"/>
646
+ <p class='description rpth-discription'>
647
+ <?php _e( 'If your theme resizes images, enter URL to its resizing PHP file', 'related-posts-thumbnails' ); ?>
648
+ </p>
649
+ </td>
650
+ </tr>
651
+ </table>
652
+ </div>
653
+
654
+ </div>
655
+
656
+
657
+ <!-- DISPLAY SETTINGS -->
658
+ <div class="postbox" style="padding: 20px; display:none;" id="content_style_options">
659
+ <h2>
660
+ <?php
661
+ _e( 'Style Options', 'related-posts-thumbnails' );
662
+ ?>
663
+ </h2>
664
+ <table class="form-table">
665
+
666
+ <!-- calling layouts from pro -->
667
+ <?php
668
+ // do_action('rptp_style_layouts');
669
+ ?>
670
+
671
+ <tr>
672
+ <th scope="row"><?php
673
+ _e( 'Output style', 'related-posts-thumbnails' );
674
+ ?>:</th>
675
+ <td>
676
+ <select name="relpoststh_output_style" id="relpoststh_output_style">
677
+ <?php
678
+ foreach ( $output_styles as $name => $title ):
679
+ ?>
680
+ <option value="<?php
681
+ echo $name;
682
+ ?>"
683
+ <?php
684
+ if ( $relpoststh_output_style == $name )
685
+ {
686
+ echo 'selected';
687
+ }
688
+ ?>
689
+ ><?php
690
+ echo $title;
691
+ ?></option>
692
+ <?php
693
+ endforeach;
694
+ ?>
695
+ </select>
696
+ <span id="relpoststh_cleanhtml" style="display:
697
+ <?php
698
+ if ( $relpoststh_output_style == 'list' )
699
+ {
700
+ echo 'inline';
701
+ }
702
+ else
703
+ {
704
+ echo 'none';
705
+ }
706
+ ?>
707
+ ;"><?php
708
+ _e( 'Turn off plugin styles', 'related-posts-thumbnails' );
709
+ ?> <input type="checkbox" name="relpoststh_cleanhtml"
710
+ <?php
711
+ if ( $relpoststh_cleanhtml )
712
+ {
713
+ echo 'checked="checked"';
714
+ }
715
+ ?>
716
+ /></span>
717
+ </td>
718
+ </tr>
719
+ <tr valign="top">
720
+ <th scope="row"><?php
721
+ _e( 'Background color', 'related-posts-thumbnails' );
722
+ ?>:</th>
723
+ <td>
724
+ <input type="text" name="relpoststh_background" value="<?php
725
+ echo get_option( 'relpoststh_background', $this->background );
726
+ ?>" data-default-color="<?php
727
+ echo $this->background;
728
+ ?>"/>
729
+ </td>
730
+ </tr>
731
+ <tr valign="top">
732
+ <th scope="row"><?php
733
+ _e( 'Background color on mouse over', 'related-posts-thumbnails' );
734
+ ?>:</th>
735
+ <td>
736
+ <input type="text" name="relpoststh_hoverbackground" value="<?php
737
+ echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground );
738
+ ?>" data-default-color="<?php
739
+ echo $this->hoverbackground;
740
+ ?>" />
741
+ </td>
742
+ </tr>
743
+ <tr valign="top">
744
+ <th scope="row"><?php
745
+ _e( 'Border color', 'related-posts-thumbnails' );
746
+ ?>:</th>
747
+ <td>
748
+ <input type="text" name="relpoststh_bordercolor" value="<?php
749
+ echo get_option( 'relpoststh_bordercolor', $this->border_color );
750
+ ?>" data-default-color="<?php
751
+ echo $this->border_color;
752
+ ?>"/>
753
+ </td>
754
+ </tr>
755
+ <tr valign="top">
756
+ <th scope="row"><?php
757
+ _e( 'Font color', 'related-posts-thumbnails' );
758
+ ?>:</th>
759
+ <td>
760
+ <input type="text" name="relpoststh_fontcolor" value="<?php
761
+ echo get_option( 'relpoststh_fontcolor', $this->font_color );
762
+ ?>" data-default-color="<?php
763
+ echo $this->font_color;
764
+ ?>"/>
765
+ </td>
766
+ </tr>
767
+ <tr valign="top">
768
+ <th scope="row"><?php
769
+ _e( 'Font family', 'related-posts-thumbnails' );
770
+ ?>:</th>
771
+ <td>
772
+ <input type="text" name="relpoststh_fontfamily" value="<?php
773
+ echo stripslashes( htmlspecialchars( get_option( 'relpoststh_fontfamily', $this->font_family ) ) );
774
+ ?>" size="50"/>
775
+ </td>
776
+ </tr>
777
+ <tr valign="top">
778
+ <th scope="row"><?php
779
+ _e( 'Font size', 'related-posts-thumbnails' );
780
+ ?>:</th>
781
+ <td>
782
+ <input type="number" min="1" name="relpoststh_fontsize" value="<?php
783
+ echo get_option( 'relpoststh_fontsize', $this->font_size );
784
+ ?>" size="7"/>
785
+ <label for="relpoststh_fontsize"><p class="description rpth-discription"><?php
786
+ _e( 'px', 'related-posts-thumbnails' );
787
+ ?></p></label>
788
+ <span class='rpt-no-validate-error' style="display:none;"><?php
789
+ _e( 'Only Digits are allowed', 'related-posts-thumbnails' );
790
+ ?></span>
791
+ </td>
792
+ </tr>
793
+ <tr valign="top">
794
+ <th scope="row"><?php
795
+ _e( 'Text maximum length', 'related-posts-thumbnails' );
796
+ ?>:</th>
797
+ <td>
798
+ <input type="number" min="0" name="relpoststh_textlength" value="<?php
799
+ echo get_option( 'relpoststh_textlength', $this->text_length );
800
+ ?>" size="7"/>
801
+ <label for="relpoststh_textlength"><p class="description rpth-discription"><?php
802
+ _e( 'Set 0 for no title', 'related-posts-thumbnails' );
803
+ ?></p></label>
804
+ <span class='rpt-no-validate-error' style="display:none;"><?php
805
+ _e( 'Only Digits are allowed', 'related-posts-thumbnails' );
806
+ ?></span>
807
+ <br />
808
+ </td>
809
+ </tr>
810
+ <tr valign="top">
811
+ <th scope="row"><?php
812
+ _e( 'Excerpt maximum length', 'related-posts-thumbnails' );
813
+ ?>:</th>
814
+ <td>
815
+ <input type="number" min="0" name="relpoststh_excerptlength" value="<?php
816
+ echo get_option( 'relpoststh_excerptlength', $this->excerpt_length );
817
+ ?>" size="7"/>
818
+ <label for="relpoststh_excerptlength"><p class="description rpth-discription" ><?php
819
+ _e( 'Set 0 for no excerpt', 'related-posts-thumbnails' );
820
+ ?></p></label>
821
+ <span class='rpt-no-validate-error' style="display:none;"><?php
822
+ _e( 'Only Digits are allowed', 'related-posts-thumbnails' );
823
+ ?></span>
824
+ <br />
825
+ </td>
826
+ </tr>
827
+ <tr valign="top">
828
+ <th scope="row"><?php
829
+ _e( 'Text block height', 'related-posts-thumbnails' );
830
+ ?>:</th>
831
+ <td>
832
+ <input type="number" min="0" name="relpoststh_textblockheight" value="<?php
833
+ echo get_option( 'relpoststh_textblockheight', $this->text_block_height );
834
+ ?>" size="7"/> <p class="description rpth-discription">px</p>
835
+ <span class='rpt-no-validate-error' style="display:none;"><?php
836
+ _e( 'Only Digits are allowed', 'related-posts-thumbnails' );
837
+ ?></span>
838
+ </td>
839
+ </tr>
840
+ </table>
841
+ </div>
842
+ <div class="postbox" style="padding: 20px; display:none;" id="content_relation_options">
843
+ <h2><?php
844
+ _e( 'Relation Builder Options', 'related-posts-thumbnails' );
845
+ ?></h2>
846
+ <table class="form-table">
847
+ <tr valign="top">
848
+ <th scope="row"><?php
849
+ _e( 'Base relation on', 'related-posts-thumbnails' );
850
+ ?>:</th>
851
+ <td>
852
+ <?php
853
+ if ( is_array( $relation_options ) && count( $relation_options ) ):
854
+ ?>
855
+ <?php
856
+ foreach ( $relation_options as $ro_key => $ro_name ):
857
+ ?>
858
+ <input type="radio" name="relpoststh_relation" id="relpoststh_relation_<?php
859
+ echo $ro_key;
860
+ ?>" value="<?php
861
+ echo $ro_key;
862
+ ?>"
863
+ <?php
864
+ if ( $relpoststh_relation == $ro_key )
865
+ {
866
+ echo 'checked="checked"';
867
+ }
868
+ ?>
869
+ />
870
+ <label for="relpoststh_relation_<?php
871
+ echo $ro_key;
872
+ ?>"><?php
873
+ echo $ro_name;
874
+ ?></label><br />
875
+ <?php
876
+ endforeach;
877
+ ?>
878
+ <?php
879
+ endif;
880
+ ?>
881
+ <div id="custom_taxonomies" style="display:
882
+ <?php
883
+ if ( $relpoststh_relation == 'custom' )
884
+ {
885
+ echo 'inline';
886
+ }
887
+ else
888
+ {
889
+ echo 'none';
890
+ }
891
+ ?>
892
+ ;">
893
+ <?php
894
+ if ( is_array( $custom_taxonomies ) && count( $custom_taxonomies ) ):
895
+ ?>
896
+ <?php
897
+ foreach ( $custom_taxonomies as $custom_taxonomy ):
898
+ ?>
899
+ <input type="checkbox" name="relpoststh_custom_taxonomies[]" id="ct_<?php
900
+ echo $custom_taxonomy;
901
+ ?>" value="<?php
902
+ echo $custom_taxonomy;
903
+ ?>"
904
+ <?php
905
+ if ( in_array( $custom_taxonomy, $relpoststh_custom_taxonomies ) )
906
+ {
907
+ echo 'checked="checked"';
908
+ }
909
+ ?>
910
+ />
911
+ <label for="ct_<?php
912
+ echo $custom_taxonomy;
913
+ ?>"><?php
914
+ echo $custom_taxonomy;
915
+ ?></label>
916
+ <?php
917
+ endforeach;
918
+ ?>
919
+ <?php
920
+ endif;
921
+ ?>
922
+ </div>
923
+ </td>
924
+ </tr>
925
+ </table>
926
+ </div>
927
+ <!-- <input name="Submit" value="<?php
928
+ _e( 'Save Changes', 'related-posts-thumbnails' );
929
+ ?>" type="submit" class="button-primary"> -->
930
+ </div>
931
+ </div>
932
+
933
+ <div class="wpbr-button-container bottom">
934
+ <div class="wpbr-social-links alignleft">
935
+ <a href="https://profiles.wordpress.org/hiddenpearls/" class="wordpress" target="_blank"><span class="dashicons dashicons-wordpress"></span></a>
936
+ </div>
937
+ <input type="submit" name="Submit" class="wpb-rpt-settings-submit button button-primary button-big" value="<?php
938
+ esc_html_e( 'Save Settings', 'related-posts-thumbnails' );
939
+ ?>" id="wpb_rpt_save_setting_bottom">
940
+ </div>
941
+ </div>
942
+
943
+ <div class="metabox-holder wpbr-sidebar">
944
+ <div class="sidebar postbox">
945
+ <h2><?php
946
+ esc_html_e( 'Spread the Word', 'related-posts-thumbnails' );
947
+ ?></h2>
948
+ <ul>
949
+ <li>
950
+ <a href="http://twitter.com/share?text=This is Best Related Post Thumbnails Plugin for WordPress&url=https://wordpress.org/support/view/plugin-reviews/related-posts-thumbnails" data-count="none" class="button twitter" target="_blank" title="Post to Twitter Now"><?php
951
+ esc_html_e( 'Share on Twitter', 'related-posts-thumbnails' );
952
+ ?><span class="dashicons dashicons-twitter"></span></a>
953
+ </li>
954
+
955
+ <li>
956
+ <a href="https://www.facebook.com/sharer/sharer.php?u=https://wordpress.org/support/view/plugin-reviews/related-posts-thumbnails" class="button facebook" target="_blank" title="Share with your facebook friends about this awesome plugin."><?php
957
+ esc_html_e( 'Share on Facebook', 'related-posts-thumbnails' );
958
+ ?><span class="dashicons dashicons-facebook"></span>
959
+ </a>
960
+ </li>
961
+
962
+ <li>
963
+ <a href="https://wordpress.org/support/view/plugin-reviews/related-posts-thumbnails?filter=5" class="button wordpress" target="_blank" title="Rate on Wordpress.org"><?php
964
+ esc_html_e( 'Rate on Wordpress.org', 'related-posts-thumbnails' );
965
+ ?><span class="dashicons dashicons-wordpress"></span>
966
+ </a>
967
+ </li>
968
+ </ul>
969
+ </div>
970
+
971
+ <div class="sidebar postbox">
972
+
973
+ <h2><?php
974
+ esc_html_e( 'Subscribe Newsletter', 'related-posts-thumbnails' );
975
+ ?></h2>
976
+ <ul>
977
+ <li>
978
+ <label for="">Email</label>
979
+ <input type="email" name="subscriber_mail" value="<?php
980
+ echo get_option( 'admin_email' );
981
+ ?>" id="rpt_subscribe_mail">
982
+ <p class='rpt_subscribe_warning'></p>
983
+ </li>
984
+ <li>
985
+ <label for="">Name</label>
986
+ <input type="text" name="subscriber_name" id="rpt_subscribe_name" value="<?php
987
+ echo wp_get_current_user()->display_name;
988
+ ?>" id="rpt_subscribe_mail">
989
+ </li>
990
+ <li>
991
+ <input type="submit" value="Subscribe Now" class="button button-primary button-big" id='rpt_subscribe_btn' />
992
+ <img src="<?php
993
+ echo admin_url( 'images/spinner.gif' );
994
+ ?>" class='rpt_subscribe_loader' style="display:none" />
995
+ </li>
996
+ <li>
997
+ <p class='rpt_return_message'></p>
998
+ </li>
999
+ </ul>
1000
+ </div>
1001
+
1002
+ <div class="sidebar postbox">
1003
+ <h2><?php
1004
+ esc_html_e( 'Recommended Plugins', 'related-posts-thumbnails' );
1005
+ ?></h2>
1006
+ <!-- <p>Following are the plugins highly recommend by Team WPBrigade.</p> -->
1007
+ <ul class="plugins_lists">
1008
+ <li>
1009
+ <a href="https://wpbrigade.com/wordpress/plugins/loginpress-pro/?utm_source=related-posts-lite&utm_medium=sidebar&utm_campaign=pro-upgrade" data-count="none" target="_blank" title="Post to Twitter Now"><?php
1010
+ esc_html_e( 'LoginPress - Login Customizer', 'related-posts-thumbnails' );
1011
+ ?></a>
1012
+ </li>
1013
+
1014
+ <li>
1015
+ <a href="https://analytify.io/ref/73/?utm_source=related-posts-lite&utm_medium=sidebar&utm_campaign=pro-upgrade" target="_blank" title="Share with your facebook friends about this awesome plugin."><?php
1016
+ esc_html_e( 'Google Analytics by Analytify', 'related-posts-thumbnails' );
1017
+ ?></span>
1018
+ </a>
1019
+ </li>
1020
+
1021
+ <li>
1022
+ <a href="http://wpbrigade.com/recommend/maintenance-mode" target="_blank" title="Under Construction & Maintenance mode"><?php
1023
+ esc_html_e( 'Under Construction & Maintenance mode', 'related-posts-thumbnails' );
1024
+ ?></span>
1025
+ </a>
1026
+ </li>
1027
+ </ul>
1028
+ </div>
1029
+ </div>
1030
+
1031
+ </div>
1032
+ </form>
1033
+ <p style="margin-top: 40px;"><small><?php
1034
+ _e( 'If you experience some problems with this plugin please let me know about it on <a target="_blank" href="https://wpbrigade.com/wordpress/plugins/related-posts/">Plugin\'s homepage</a>. If you think this plugin is awesome please vote on <a target="_blank" href="https://wordpress.org/plugins/related-posts-thumbnails/">WordPress plugin page</a>. Thanks!', 'related-posts-thumbnails' );
1035
+ ?></small></p>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://wpbrigade.com/
4
  Tags: related, posts, thumbnails, Related Content, related posts, pages, similar posts, shortcodes, widgets, related thumbs
5
  Requires at least: 3.6
6
  Tested up to: 4.9
7
- Stable tag: 1.6.3
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -67,11 +67,21 @@ If there are no images of the specified size in the post, or file does not exist
67
 
68
  == Upgrade Notice ==
69
 
70
- = 1.6.3 =
71
- * Please upgrade immediately
72
 
73
  == Changelog ==
74
 
 
 
 
 
 
 
 
 
 
 
75
  = 1.6.3 - 2018-03-26 =
76
  * Feature : Multilingual Compatible. All text is now translateable.
77
  * Feature : Add filter to left, right or center align Related Posts.
@@ -84,7 +94,6 @@ If there are no images of the specified size in the post, or file does not exist
84
  * Bug Fix : Fix the image issue in widget.
85
  * Bug Fix : Fix the image issue in thumbnails of Related Posts.
86
 
87
-
88
  = 1.6.2 - 2018-02-27 =
89
  * Feature : Change inline style to class.
90
  * Feature : Add RTL support.
4
  Tags: related, posts, thumbnails, Related Content, related posts, pages, similar posts, shortcodes, widgets, related thumbs
5
  Requires at least: 3.6
6
  Tested up to: 4.9
7
+ Stable tag: 1.6.4
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
67
 
68
  == Upgrade Notice ==
69
 
70
+ = 1.6.4 =
71
+ * Please upgrade immediately - Multiple Enhancements and bugfixes.
72
 
73
  == Changelog ==
74
 
75
+ = 1.6.4 - 2018-06-06 =
76
+ * Feature : Add sort by option for Related Posts.
77
+ * Enhancement : Add class attribute in list styling, if someone wants to style list Related Posts.
78
+ * Enhancement : Move thumbnails source option to its own section.
79
+ * Enhancement : Minor style changes in settings page.
80
+ * Bug Fix : Fonts are unable to change in list output style.
81
+ * Bug Fix : Unclosed div making layout break.
82
+ * Bug Fix : Left content alignment is breaking layout.
83
+ * Bug Fix : Content of alt tag of Related Posts image is breaking layout.
84
+
85
  = 1.6.3 - 2018-03-26 =
86
  * Feature : Multilingual Compatible. All text is now translateable.
87
  * Feature : Add filter to left, right or center align Related Posts.
94
  * Bug Fix : Fix the image issue in widget.
95
  * Bug Fix : Fix the image issue in thumbnails of Related Posts.
96
 
 
97
  = 1.6.2 - 2018-02-27 =
98
  * Feature : Change inline style to class.
99
  * Feature : Add RTL support.
related-posts-thumbnails.php CHANGED
@@ -3,763 +3,925 @@
3
  * Plugin Name: WordPress Related Posts Thumbnails
4
  * Plugin URI: https://wpbrigade.com/wordpress/plugins/related-posts/?utm_source=related-posts-lite&utm_medium=plugin-uri&utm_campaign=pro-upgrade-rp
5
  * Description: Showing related posts thumbnails under the posts.
6
- * Version: 1.6.3
7
  * Author: WPBrigade
8
  * Author URI: https://WPBrigade.com/?utm_source=related-posts-lite&utm_medium=author-link&utm_campaign=pro-upgrade-rp
9
  */
10
 
11
  /*
12
- Copyright 2010 to 2018
13
 
14
- This product was first developed by Maria I Shaldybina and later on maintained and developed by Adnan (WPBrigade.com)
15
 
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License as published by
18
- the Free Software Foundation; either version 2 of the License, or
19
- (at your option) any later version.
20
 
21
- This program is distributed in the hope that it will be useful,
22
- but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
- GNU General Public License for more details.
25
  */
26
  class RelatedPostsThumbnails {
27
- /* Default values. PHP 4 compatible */
28
- public $single_only = '1';
29
- public $auto = '1';
30
- public $top_text = '<h3>Related posts:</h3>';
31
- public $number = 3;
32
- public $relation = 'categories';
33
- public $poststhname = 'thumbnail';
34
- public $background = '#ffffff';
35
- public $hoverbackground = '#eeeeee';
36
- public $border_color = '#dddddd';
37
- public $font_color = '#333333';
38
- public $font_family = 'Arial';
39
- public $font_size = '12';
40
- public $text_length = '100';
41
- public $excerpt_length = '0';
42
- public $custom_field = '';
43
- public $custom_height = '100';
44
- public $custom_width = '100';
45
- public $text_block_height = '75';
46
- public $thsource = 'post-thumbnails';
47
- public $categories_all = '1';
48
- public $devmode = '0';
49
- public $output_style = 'div';
50
- public $post_types = array( 'post' );
51
- public $custom_taxonomies = array();
52
-
53
- protected $wp_kses_rp_args = array(
54
-
55
- 'h1' => array(),
56
- 'h2' => array(),
57
- 'h3' => array(),
58
- 'h4' => array(),
59
- 'h5' => array(),
60
- 'h6' => array(),
61
- 'strong' => array(),
62
- );
63
-
64
- function __construct() {
65
-
66
- $this->constant();
67
- // initialization
68
- load_plugin_textdomain( 'related-posts-thumbnails', false, basename( dirname( __FILE__ ) ) . '/locale' );
69
- $this->default_image = esc_url( plugins_url( 'img/default.png', __FILE__ ) );
70
-
71
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
72
-
73
- // Compatibility for old default image path.
74
- if ( $this->is_old_default_img() )
75
- update_option( 'relpoststh_default_image', $this->default_image );
76
-
77
- if ( get_option( 'relpoststh_auto', $this->auto ) ) {
78
- $priority = apply_filters( 'rpt_content_prioirty', 10); // Alter priority of the related post content
79
- add_filter( 'the_content', array( $this, 'auto_show' ), $priority );
80
- }
81
-
82
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
83
- add_shortcode( 'related-posts-thumbnails' , array( $this, 'get_html' ) );
84
-
85
- $this->wp_version = get_bloginfo( 'version' );
86
-
87
- add_action( 'admin_footer', array( $this, 'add_deactive_modal' ) );
88
- add_action( 'wp_ajax_rpt_deactivate', array( $this, 'rpt_deactivate' ) );
89
-
90
- add_action( 'admin_init', array( $this, 'review_notice' ) );
91
- add_action( 'wp_enqueue_scripts', array( $this, 'front_scripts' ) );
92
-
93
- add_action( 'wp_head', array( $this, 'head_style' ) );
94
- }
95
-
96
- function admin_scripts( $page ) {
97
-
98
- if ( 'toplevel_page_related-posts-thumbnails' === $page ) {
99
- wp_enqueue_media();
100
- wp_enqueue_style( 'rpt_admin_css', plugins_url( 'assets/css/admin.css', __FILE__ ), false, RELATED_POSTS_THUMBNAILS_VERSION );
101
- wp_enqueue_style( 'jquery-ui', 'http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css' );
102
- wp_enqueue_style( 'wp-color-picker' );
103
- wp_enqueue_script( 'rpt_admin_js', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery', 'wp-color-picker', 'jquery-ui-datepicker' ), RELATED_POSTS_THUMBNAILS_VERSION );
104
- }
105
-
106
- }
107
-
108
- function front_scripts() {
109
-
110
- wp_enqueue_style( 'rpt_front_style', plugins_url( 'assets/css/front.css', __FILE__ ), false, RELATED_POSTS_THUMBNAILS_VERSION );
111
- }
112
-
113
- function constant() {
114
-
115
- define( 'RELATED_POSTS_THUMBNAILS_VERSION', '1.6.2' );
116
- define( 'RELATED_POSTS_THUMBNAILS_FEEDBACK_SERVER', 'https://wpbrigade.com/' );
117
- define( 'RELATED_POSTS_THUMBNAILS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
118
-
119
- }
120
-
121
- /**
122
- * Show the popup on pluing deactivate
123
- *
124
- * @since 1.6.2
125
- */
126
- function add_deactive_modal() {
127
- global $pagenow;
128
-
129
- if ( 'plugins.php' !== $pagenow ) {
130
- return;
131
- }
132
-
133
- include RELATED_POSTS_THUMBNAILS_PLUGIN_DIR. 'inc/rpt-deactivate-form.php';
134
- }
135
-
136
-
137
- /**
138
- * Send the user responce to api.
139
- *
140
- * @since 1.6.2
141
- */
142
- function rpt_deactivate() {
143
- $email = get_option( 'admin_email' );
144
- $_reason = sanitize_text_field( wp_unslash( $_POST['reason'] ) );
145
- $reason_detail = sanitize_text_field( wp_unslash( $_POST['reason_detail'] ) );
146
- $reason = '';
147
-
148
- if ( $_reason == '1' ) {
149
- $reason = 'I only needed the plugin for a short period';
150
- } elseif ( $_reason == '2' ) {
151
- $reason = 'I found a better plugin';
152
- } elseif ( $_reason == '3' ) {
153
- $reason = 'The plugin broke my site';
154
- } elseif ( $_reason == '4' ) {
155
- $reason = 'The plugin suddenly stopped working';
156
- } elseif ( $_reason == '5' ) {
157
- $reason = 'I no longer need the plugin';
158
- } elseif ( $_reason == '6' ) {
159
- $reason = 'It\'s a temporary deactivation. I\'m just debugging an issue.';
160
- } elseif ( $_reason == '7' ) {
161
- $reason = 'Other';
162
- }
163
- $fields = array(
164
- 'email' => $email,
165
- 'website' => get_site_url(),
166
- 'action' => 'Deactivate',
167
- 'reason' => $reason,
168
- 'reason_detail' => $reason_detail,
169
- 'blog_language' => get_bloginfo( 'language' ),
170
- 'wordpress_version' => get_bloginfo( 'version' ),
171
- 'php_version' => PHP_VERSION,
172
- 'plugin_version' => RELATED_POSTS_THUMBNAILS_VERSION,
173
- 'plugin_name' => 'Related Post Thumbnails',
174
- );
175
-
176
- $response = wp_remote_post( RELATED_POSTS_THUMBNAILS_FEEDBACK_SERVER, array(
177
- 'method' => 'POST',
178
- 'timeout' => 5,
179
- 'httpversion' => '1.0',
180
- 'blocking' => false,
181
- 'headers' => array(),
182
- 'body' => $fields,
183
- ) );
184
-
185
- wp_die();
186
- }
187
-
188
- /**
189
- * Check either to show notice or not.
190
- *
191
- * @since 1.8.2
192
- */
193
- public function review_notice() {
194
-
195
- $this->review_dismissal();
196
- $this->review_prending();
197
-
198
- $review_dismissal = get_option( 'rpt_review_dismiss' );
199
- if ( 'yes' == $review_dismissal ) {
200
- return;
201
- }
202
-
203
- $activation_time = get_option( 'rpt_active_time' );
204
- if ( ! $activation_time ) {
205
-
206
- $activation_time = time();
207
- add_option( 'rpt_active_time', $activation_time );
208
- }
209
-
210
- // 1296000 = 15 Days in seconds.
211
- if ( time() - $activation_time > 1296000 ) {
212
- add_action( 'admin_notices' , array( $this, 'review_notice_message' ) );
213
- }
214
-
215
- }
216
-
217
- /**
218
- * Show review Message After 15 days.
219
- *
220
- * @since 1.8.2
221
- */
222
- public function review_notice_message() {
223
-
224
- $scheme = ( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY ) ) ? '&' : '?';
225
- $url = $_SERVER['REQUEST_URI'] . $scheme . 'rpt_review_dismiss=yes';
226
- $dismiss_url = wp_nonce_url( $url, 'rpt-review-nonce' );
227
-
228
- $_later_link = $_SERVER['REQUEST_URI'] . $scheme . 'ssb_review_later=yes';
229
- $later_url = wp_nonce_url( $_later_link, 'rpt-review-nonce' );
230
-
231
- ?>
232
- <style media="screen">
233
- .rpt-review-notice { padding: 15px 0; background-color: #fff; border-radius: 3px; margin: 20px 20px 0 0; border-left: 4px solid transparent; } .rpt-review-notice:after { content: ''; display: table; clear: both; }
234
- .rpt-review-thumbnail { float: left; line-height: 80px; text-align: center; width: 117px; }
235
- .rpt-review-thumbnail img { width: 118px; vertical-align: middle; }
236
- .rpt-review-text { overflow: hidden; }
237
- .rpt-review-text h3 { font-size: 24px; margin: 0 0 5px; font-weight: 400; line-height: 1.3; }
238
- .rpt-review-text p { font-size: 13px; margin: 0 0 5px; }
239
- .rpt-review-ul { margin: 0; padding: 0; }
240
- .rpt-review-ul li { display: inline-block; margin-right: 15px; }
241
- .rpt-review-ul li a { display: inline-block; color: #10738B; text-decoration: none; padding-left: 26px; position: relative; }
242
- .rpt-review-ul li a span { position: absolute; left: 0; top: -2px; }
243
- </style>
244
- <div class="rpt-review-notice">
245
- <div class="rpt-review-thumbnail">
246
- <img src="<?php echo plugins_url( 'assets/images/rpt-logo.png', __FILE__ ) ?>" alt="">
247
- </div>
248
- <div class="rpt-review-text">
249
- <h3><?php _e( 'Leave A Review?', 'related-posts-thumbnails' ) ?></h3>
250
- <p><?php _e( 'We hope you\'ve enjoyed using Related Post Thumbnails! Would you consider leaving us a review on WordPress.org?', 'related-posts-thumbnails' ) ?></p>
251
- <ul class="rpt-review-ul"><li><a href="https://wordpress.org/support/plugin/related-posts-thumbnails/reviews/?filter=5" target="_blank"><span class="dashicons dashicons-external"></span><?php _e( 'Sure! I\'d love to!', 'related-posts-thumbnails' ) ?></a></li>
252
- <li><a href="<?php echo $dismiss_url ?>"><span class="dashicons dashicons-smiley"></span><?php _e( 'I\'ve already left a review', 'related-posts-thumbnails' ) ?></a></li>
253
- <li><a href="<?php echo $later_url ?>"><span class="dashicons dashicons-calendar-alt"></span><?php _e( 'Maybe Later', 'related-posts-thumbnails' ) ?></a></li>
254
- <li><a href="<?php echo $dismiss_url ?>"><span class="dashicons dashicons-dismiss"></span><?php _e( 'Never show again', 'related-posts-thumbnails' ) ?></a></li></ul>
255
- </div>
256
- </div>
257
- <?php
258
- }
259
-
260
- /**
261
- * Set time to current so review notice will popup after 15 days
262
- *
263
- * @since 1.8.2
264
- */
265
- function review_prending() {
266
-
267
- // delete_site_option( 'rpt_review_dismiss' );
268
- if ( ! is_admin() ||
269
- ! current_user_can( 'manage_options' ) ||
270
- ! isset( $_GET['_wpnonce'] ) ||
271
- ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'rpt-review-nonce' ) ||
272
- ! isset( $_GET['ssb_review_later'] ) ) {
273
-
274
- return;
275
- }
276
-
277
- // Reset Time to current time.
278
- update_option( 'rpt_active_time', time() );
279
-
280
- }
281
-
282
- /**
283
- * Check and Dismiss review message.
284
- *
285
- * @since 1.8.2
286
- */
287
- private function review_dismissal() {
288
-
289
- //delete_option( 'rpt_review_dismiss' );
290
- if ( ! is_admin() ||
291
- ! current_user_can( 'manage_options' ) ||
292
- ! isset( $_GET['_wpnonce'] ) ||
293
- ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'rpt-review-nonce' ) ||
294
- ! isset( $_GET['rpt_review_dismiss'] ) ) {
295
-
296
- return;
297
- }
298
-
299
- add_option( 'rpt_review_dismiss', 'yes' );
300
- }
301
-
302
-
303
- /**
304
- * [is_old_default_img Check the compatibility for old default image path.]
305
- * @return boolean Return true if path is old.
306
- */
307
- function is_old_default_img() {
308
-
309
- if ( get_option( 'relpoststh_default_image') !== $this->default_image ) {
310
-
311
- $chunks = explode( '/', get_option( 'relpoststh_default_image') );
312
- if ( in_array('related-posts-thumbnails', $chunks) ) {
313
- return true;
314
- }
315
- }
316
-
317
- }
318
-
319
- function auto_show( $content ) {
320
- // Automatically displaying related posts under post body
321
- return $content . $this->get_html( true );
322
-
323
- }
324
-
325
- function get_html( $show_top = false ) {
326
- // Getting related posts HTML
327
- if ( $this->is_relpoststh_show() ) {
328
- return $this->get_thumbnails( $show_top ); }
329
- return '';
330
- }
331
-
332
- function get_thumbnails( $show_top = false ) {
333
- // Retrieve Related Posts HTML for output
334
- $output = '';
335
- $debug = 'Developer mode initialisation; Version: 1.2.9;';
336
- $time = microtime( true );
337
- $posts_number = get_option( 'relpoststh_number', $this->number );
338
- $height = '';
339
- $width = '';
340
- // rpt_content_align: add content allignment class; clases are: relpost-align-left, relpost-align-right and relpost-align-center
341
- $output = '<div class="relpost-thumb-wrapper ' . apply_filters( 'rpt_content_align', 'relpost-align-left') . ' ">';
342
- $alt = '';
343
-
344
- if ( $posts_number <= 0 ) { // return nothing if this parameter was set to <= 0
345
- return $this->finish_process( $output, $debug . 'Posts number is 0;', $time );
346
- }
347
-
348
- $id = get_the_ID();
349
- $relation = get_option( 'relpoststh_relation', $this->relation );
350
- $poststhname = get_option( 'relpoststh_poststhname', $this->poststhname );
351
- $text_length = get_option( 'relpoststh_textlength', $this->text_length );
352
- $excerpt_length = get_option( 'relpoststh_excerptlength', $this->excerpt_length );
353
- $thsource = get_option( 'relpoststh_thsource', $this->thsource );
354
- $categories_show_all = get_option( 'relpoststh_show_categoriesall', get_option( 'relpoststh_categoriesall', $this->categories_all ) );
355
- $onlywiththumbs = ( current_theme_supports( 'post-thumbnails' ) && $thsource == 'post-thumbnails' ) ? get_option( 'relpoststh_onlywiththumbs', false ) : false;
356
- $post_type = get_post_type();
357
-
358
- global $wpdb;
359
-
360
- /* Get taxonomy terms */
361
- $debug .= "Relation: $relation; All categories: $categories_show_all;";
362
- $use_filter = ( $categories_show_all != '1' || $relation != 'no' );
363
-
364
- if ( $use_filter ) {
365
- $query_objects = "SELECT distinct object_id FROM $wpdb->term_relationships WHERE 1=1 ";
366
-
367
- if ( $relation != 'no' ) { /* Get object terms */
368
- if ( $relation == 'categories' ) {
369
- $taxonomy = array( 'category' ); } elseif ( $relation == 'tags' ) {
370
- $taxonomy = array( 'post_tag' ); } elseif ( $relation == 'custom' ) {
371
- $taxonomy = get_option( 'relpoststh_custom_taxonomies', $this->custom_taxonomies );
372
- } else {
373
- $taxonomy = array( 'category', 'post_tag' );
374
- }
375
- $object_terms = wp_get_object_terms( $id, $taxonomy, array( 'fields' => 'ids' ) );
376
- if ( empty( $object_terms ) || ! is_array( $object_terms ) ) { // no terms to get taxonomy
377
- return $this->finish_process( $output, $debug . __( 'No taxonomy terms to get posts;' ), $time );
378
- }
379
-
380
- $query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('". implode( "', '", $object_terms ) . "')";
381
- $object_taxonomy = $wpdb->get_results( $query );
382
- $object_taxonomy_a = array();
383
- if ( count( $object_taxonomy ) > 0 ) {
384
- foreach ( $object_taxonomy as $item ) {
385
- $object_taxonomy_a[] = $item->term_taxonomy_id;
386
- }
387
- }
388
- $query_objects .= " AND term_taxonomy_id IN ('". implode( "', '", $object_taxonomy_a ) . "') ";
389
- }
390
-
391
- if ( $categories_show_all != '1' ) { /* Get filter terms */
392
- $select_terms = get_option( 'relpoststh_show_categories',
393
- get_option( 'relpoststh_categories' ) );
394
- if ( empty( $select_terms ) || ! is_array( $select_terms ) ) { // if no categories were specified intentionally return nothing
395
- return $this->finish_process( $output, $debug . __( 'No categories were selected;' ), $time );
396
- }
397
-
398
- $query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('". implode( "', '", $select_terms ) . "')";
399
- $taxonomy = $wpdb->get_results( $query );
400
- $filter_taxonomy_a = array();
401
- if ( count( $taxonomy ) > 0 ) {
402
- foreach ( $taxonomy as $item ) {
403
- $filter_taxonomy_a[] = $item->term_taxonomy_id; }
404
- }
405
- if ( $relation != 'no' ) {
406
- $query_objects .= " AND object_id IN (SELECT distinct object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ('". implode( "', '", $filter_taxonomy_a ) . "') )";
407
- } else {
408
- $query_objects .= " AND term_taxonomy_id IN ('". implode( "', '", $filter_taxonomy_a ) . "')";
409
- }
410
- }
411
-
412
- $relationships = $wpdb->get_results( $query_objects );
413
- $related_objects = array();
414
- if ( count( $relationships ) > 0 ) {
415
- foreach ( $relationships as $item ) {
416
- $related_objects[] = $item->object_id;
417
- }
418
- }
419
- }
420
-
421
- $query = "SELECT distinct ID FROM $wpdb->posts ";
422
- $where = " WHERE post_type = '" . $post_type . "' AND post_status = 'publish' AND ID<>" . $id; // not the current post
423
- $startdate = get_option( 'relpoststh_startdate' );
424
- if ( ! empty( $startdate ) && preg_match( '/^\d\d\d\d-\d\d-\d\d$/', $startdate ) ) { // If startdate was set
425
- $debug .= "Startdate: $startdate;";
426
- $where .= " AND post_date >= '" . $startdate . "'";
427
- }
428
- if ( $use_filter ) {
429
- $where .= " AND ID IN ('". implode( "', '", $related_objects ) . "')";
430
- }
431
- $join = '';
432
- if ( $onlywiththumbs ) {
433
- $debug .= 'Only with thumbnails;';
434
- $join = " INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)";
435
- $where .= " AND $wpdb->postmeta.meta_key = '_thumbnail_id'";
436
- }
437
-
438
- $order = ' ORDER BY rand() LIMIT ' . $posts_number;
439
- $random_posts = $wpdb->get_results( $query . $join . $where . $order );
440
-
441
- /* Get posts by their IDs */
442
- if ( ! is_array( $random_posts ) || count( $random_posts ) < 1 ) {
443
- return $this->finish_process( $output, $debug . __( 'No posts matching relationships criteria;' ), $time );
444
- }
445
-
446
- $posts_in = array();
447
- foreach ( $random_posts as $random_post ) {
448
- $posts_in[] = $random_post->ID;
449
- }
450
- $query = "SELECT ID, post_content, post_excerpt, post_title FROM $wpdb->posts WHERE ID IN ('". implode( "', '", $posts_in ) . "')";
451
- $posts = $wpdb->get_results( $query );
452
- if ( ! ( is_array( $posts ) && count( $posts ) > 0 ) ) { // no posts
453
- $debug .= 'No posts found;';
454
- return $this->finish_process( $output, $debug, $time );
455
- } else {
456
- $debug .= 'Found ' . count( $posts ) . ' posts;';
457
- }
458
-
459
- /* Calculating sizes */
460
- if ( $thsource == 'custom-field' ) {
461
- $debug .= 'Custom sizes;';
462
- $width = get_option( 'relpoststh_customwidth', $this->custom_width );
463
- $height = get_option( 'relpoststh_customheight', $this->custom_height );
464
- } else { // post-thumbnails source
465
- if ( $poststhname == 'thumbnail' || $poststhname == 'medium' || $poststhname == 'large' ) { // get thumbnail size for basic sizes
466
- $debug .= 'Basic sizes;';
467
- $width = get_option( "{$poststhname}_size_w" );
468
- $height = get_option( "{$poststhname}_size_h" );
469
- } elseif ( current_theme_supports( 'post-thumbnails' ) ) { // get sizes for theme supported thumbnails
470
- global $_wp_additional_image_sizes;
471
- if ( isset( $_wp_additional_image_sizes[ $poststhname ] ) ) {
472
- $debug .= 'Additional sizes;';
473
- $width = $_wp_additional_image_sizes[ $poststhname ]['width'];
474
- $height = $_wp_additional_image_sizes[ $poststhname ]['height'];
475
- } else { $debug .= 'No additional sizes;'; }
476
- }
477
- }
478
- // displaying square if one size is not cropping
479
- if ( $height == 9999 ) {
480
- $height = $width;
481
- }
482
- if ( $width == 9999 ) {
483
- $width = $height;
484
- }
485
- // theme is not supporting but settings were not changed
486
- if ( empty( $width ) ) {
487
- $debug .= 'Using default width;';
488
- $width = get_option( 'thumbnail_size_w' );
489
- }
490
- if ( empty( $height ) ) {
491
- $debug .= 'Using default height;';
492
- $height = get_option( 'thumbnail_size_h' );
493
- }
494
- $debug .= 'Got sizes '.$width.'x'.$height.';';
495
- // rendering related posts HTML
496
- if ( $show_top ) {
497
- $output .= stripslashes( get_option( 'relpoststh_top_text', $this->top_text ) );
498
- }
499
- $relpoststh_output_style = get_option( 'relpoststh_output_style', $this->output_style );
500
- $relpoststh_cleanhtml = get_option( 'relpoststh_cleanhtml', 0 );
501
- $text_height = get_option( 'relpoststh_textblockheight', $this->text_block_height );
502
-
503
-
504
- if ( $relpoststh_output_style == 'list' ) {
505
- $output .= '<ul id="related_posts_thumbnails"';
506
- // if ( ! $relpoststh_cleanhtml ) {
507
- // $output .= ' style="list-style-type:none; list-style-position: inside; padding: 0; margin:0"';
508
- // }
509
- $output .= '>';
510
- } else {
511
- // $output .= '<div style="clear: both"></div><ul class="related-posts-nav">';
512
- $output .= '<div style="clear: both"></div><div class="relpost-block-container">';
513
- }
514
-
515
- foreach ( $posts as $post ) {
516
- $image = '';
517
- $url = '';
518
- $alt = '';
519
- if ( $thsource == 'custom-field' ) {
520
- $debug .= 'Using custom field;';
521
- $url = $basic_url = get_post_meta( $post->ID, get_option( 'relpoststh_customfield', $this->custom_field ), true );
522
- if ( strpos( $url, '/wp-content' ) !== false ) {
523
- $url = substr( $url, strpos( $url, '/wp-content' ) );
524
- }
525
- $theme_resize_url = get_option( 'relpoststh_theme_resize_url', '' );
526
- if ( ! empty( $theme_resize_url ) ) {
527
- $url = $theme_resize_url . '?src=' . $url . '&w=' . $width . '&h=' . $height . '&zc=1&q=90';
528
- }
529
- } else {
530
- $from_post_body = true;
531
- if ( current_theme_supports( 'post-thumbnails' ) ) { // using built in Wordpress feature
532
- $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
533
- $debug .= 'Post-thumbnails enabled in theme;';
534
- if ( ! ( empty( $post_thumbnail_id ) || $post_thumbnail_id === false ) ) { // post has thumbnail
535
- $debug .= 'Post has thumbnail '.$post_thumbnail_id.';';
536
- $debug .= 'Postthname: '.$poststhname.';';
537
- $image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
538
- $alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
539
- $url = $image[0];
540
- $from_post_body = false;
541
- } else {
542
- $debug .= 'Post has no thumbnail;';
543
- }
544
- }
545
- if ( $from_post_body ) { // Theme does not support post-thumbnails, or post does not have assigned thumbnail
546
- $debug .= 'Getting image from post body;';
547
- $wud = wp_upload_dir();
548
- preg_match_all( '|<img.*?src=[\'"](' . $wud['baseurl'] . '.*?)[\'"].*?>|i', $post->post_content, $matches ); // searching for the first uploaded image in text
549
-
550
- if ( isset( $matches ) && isset( $matches[1][0] ) ) {
551
- $image = $matches[1][0];
552
- $html = $matches[0][0];
553
- if ( !empty( $html ) ) {
554
- preg_match( '/alt="([^"]*)"/i', $html, $array );
555
- $explode_tag = explode( '"' , $array[0] );
556
- $alt = $explode_tag[1];
557
-
558
- // $dom = new DOMDocument();
559
- // $dom->loadHTML($html);
560
- // $nodes = $dom->getElementsByTagName('img');
561
- // $alt = $nodes->item(0)->getAttribute('alt');
562
- }
563
- } else {
564
- $debug .= 'No image was found;';
565
- }
566
-
567
- if ( strlen( trim( $image ) ) > 0 ) {
568
- $image_sizes = @getimagesize( $image );
569
- if ( $image_sizes === false ) {
570
- $debug .= 'Unable to determine parsed image size';
571
- }
572
- if ( $image_sizes !== false && isset( $image_sizes[0] ) && $image_sizes[0] == $width ) { // if this image is the same size as we need
573
- $debug .= 'Image used is the required size;';
574
- $url = $image;
575
- } else { // if not, search for resized thumbnail according to Wordpress thumbnails naming function
576
- $debug .= 'Changing image according to Wordpress standards;';
577
- $url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
578
- }
579
- } else {
580
- $debug .= 'Found wrong formatted image: '.$image.';';
581
- }
582
- }
583
- $basic_url = $url;
584
- }
585
-
586
- if ( strpos( $url, '/' ) === 0 ) {
587
- $debug .= 'Relative url: ' . $url . ';';
588
- $url = $basic_url = get_bloginfo( 'url' ) . $url;
589
- }
590
-
591
- $debug .= 'Image URL: '.$url.';';
592
- if ( empty( $basic_url ) ) { // parsed URL is empty or no file if can check
593
- $debug .= 'Image is empty or no file. Using default image;';
594
- $url = get_option( 'relpoststh_default_image', $this->default_image );
595
- }
596
-
597
- $title = $this->process_text_cut( $post->post_title, $text_length );
598
- $post_excerpt = ( empty( $post->post_excerpt ) ) ? $post->post_content : $post->post_excerpt;
599
- $excerpt = $this->process_text_cut( $post_excerpt, $excerpt_length );
600
-
601
- if ( ! empty( $title ) && ! empty( $excerpt ) ) {
602
- $title = '<b>' . $title . '</b>';
603
- $excerpt = '<br/>' . $excerpt;
604
- }
605
-
606
- if ( empty( $alt ) ) {
607
- $alt = $title;
608
- }
609
-
610
- $fontface = '';
611
-
612
- $debug .= 'Using title with size ' . $text_length . '. Using excerpt with size ' . $excerpt_length . ';';
613
- if ( $relpoststh_output_style == 'list' ) {
614
- $link = get_permalink( $post->ID );
615
- $fontface = str_replace( '"', "'", stripslashes( get_option( 'relpoststh_fontfamily', $this->font_family ) ) );
616
- $output .= '<li ';
617
- if ( ! $relpoststh_cleanhtml ) {
618
- // $output .= ' onmouseout="this.style.backgroundColor=\'' . get_option( 'relpoststh_background', $this->background ) . '\'"';
619
- }
620
- $output .= '>';
621
- $output .= '<a href="' . $link . '" ><img class="relpost-post-image" alt="' . $alt . '" src="' . esc_url( $url ) . '" width="' . $width . '" height="' . $height . '" ';
622
- if ( ! $relpoststh_cleanhtml ) {
623
- // $output .= 'style="padding: 0px; margin: 0px; border: 0pt none;"';
624
- }
625
- $output .= '/></a>';
626
- if ( $text_height != '0' ) {
627
- $output .= '<a href="' . $link . '" class="relpost_content"';
628
- if ( ! $relpoststh_cleanhtml ) {
629
- $output .= ' style="width: ' . $width . 'px;height: ' . $text_height . 'px; font-family: ' . $fontface . '; "'; }
630
- $output .= '><span>' . $title . $excerpt . '</span></a></li>';
631
- }
632
- } else {
633
- $output .= '<a class="relpost-block-single" href="' . get_permalink( $post->ID ) . '">';
634
- $output .= '<div style="width: ' . $width . 'px; height: ' . ( $height + $text_height ) . 'px;">';
635
- $output .= '<div class="relpost-block-single-image" alt="' . $alt . '" style=" background: transparent url(' . esc_url( $url ) . ') no-repeat scroll 0% 0%; width: ' . $width . 'px; height: ' . $height . 'px; "></div>';
636
- $output .= '<div class="relpost-block-single-text" style="font-family: ' . $fontface . '; font-size: ' . get_option( 'relpoststh_fontsize', $this->font_size ) . 'px; color: ' . get_option( 'relpoststh_fontcolor', $this->font_color ) . ';">' . $title . $excerpt . '</div>';
637
- $output .= '</div>';
638
- $output .= '</a>';
639
- }
640
- } // end foreach
641
- if ( $relpoststh_output_style == 'list' ) {
642
- $output .= '</ul>';
643
- } else {
644
- $output .= '</div>';
645
- }
646
- $output .= '<div style="clear: both"></div>';
647
- $output .= '</div>';
648
- return $this->finish_process( $output, $debug, $time );
649
- }
650
-
651
- function finish_process( $output, $debug, $time ) {
652
- $devmode = get_option( 'relpoststh_devmode', $this->devmode );
653
- if ( $devmode ) {
654
- $time = microtime( true ) - $time;
655
- $debug .= "Plugin execution time: $time sec;";
656
- $output .= '<!-- '.$debug.' -->';
657
- }
658
- return $output;
659
- }
660
-
661
- function process_text_cut( $text, $length ) {
662
- if ( $length == 0 ) {
663
- return '';
664
- } else {
665
- $text = strip_tags( strip_shortcodes( $text ) );
666
- if ( function_exists( 'mb_strlen' ) ) {
667
- return ( ( mb_strlen( $text ) > $length ) ? mb_substr( $text, 0, $length ) . '...' : $text );
668
- } else {
669
- return ( ( strlen( $text ) > $length ) ? substr( $text, 0, $length ) . '...' : $text );
670
- }
671
- }
672
- }
673
-
674
- function is_relpoststh_show() {
675
- // Checking display options
676
- if ( ! is_single() && get_option( 'relpoststh_single_only', $this->single_only ) ) { // single only
677
- return false;
678
- }
679
- /* Check post type */
680
- $post_types = get_option( 'relpoststh_post_types', $this->post_types );
681
- $post_type = get_post_type();
682
- if ( ! in_array( $post_type, $post_types ) ) {
683
- return false;
684
- }
685
- /* Check categories */
686
- $id = get_the_ID();
687
- $categories_all = get_option( 'relpoststh_categoriesall', $this->categories_all );
688
- if ( $categories_all != '1' ) { // only specific categories were selected
689
- $post_categories = wp_get_object_terms( $id, array( 'category' ), array( 'fields' => 'ids' ) );
690
- $relpoststh_categories = get_option( 'relpoststh_categories' );
691
- if ( ! is_array( $relpoststh_categories ) || ! is_array( $post_categories ) ) { // no categories were selcted or post doesn't belong to any
692
- return false;
693
- }
694
- $common_categories = array_intersect( $relpoststh_categories, $post_categories );
695
- if ( empty( $common_categories ) ) { // post doesn't belong to specified categories
696
- return false;
697
- }
698
- }
699
- return true;
700
- }
701
-
702
- function admin_menu() {
703
- $page = add_menu_page( __( 'Related Posts Thumbnails', 'related-posts-thumbnails' ), __( 'Related Posts', 'related-posts-thumbnails' ), 'administrator', 'related-posts-thumbnails', array( $this, 'admin_interface' ), 'dashicons-screenoptions' );
704
- }
705
-
706
- function admin_interface() {
707
-
708
- include_once RELATED_POSTS_THUMBNAILS_PLUGIN_DIR . '/inc/rpt-settings.php';
709
- }
710
-
711
- function display_categories_list( $categoriesall, $categories, $selected_categories, $all_name, $specific_name ) {
712
- ?>
713
- <input id="<?php echo $all_name; ?>" class="select_all" type="checkbox" name="<?php echo $all_name; ?>" value="1" <?php if ( $categoriesall == '1' ) { echo 'checked="checked"'; } ?>/>
714
- <label for="<?php echo $all_name; ?>"><?php _e( 'All', 'related-posts-thumbnails' ); ?></label>
715
- <div class="select_specific" <?php if ( $categoriesall == '1' ) : ?> style="display:none" <?php endif; ?>>
716
- <?php foreach ( $categories as $category ) : ?>
717
- <input type="checkbox" name="<?php echo $specific_name; ?>[]" id="<?php echo $specific_name; ?>_<?php echo $category->category_nicename; ?>" value="<?php echo $category->cat_ID; ?>" <?php if ( in_array( $category->cat_ID, (array) $selected_categories ) ) { echo 'checked="checked"'; } ?>/>
718
- <label for="<?php echo $specific_name; ?>_<?php echo $category->category_nicename; ?>"><?php echo $category->cat_name; ?></label><br />
719
- <?php endforeach; ?>
720
- </div>
721
- <?php
722
- }
723
-
724
-
725
-
726
-
727
- function head_style() {
728
- ?>
729
- <style>
730
- #related_posts_thumbnails li{
731
- border-right: 1px solid <?php echo get_option( 'relpoststh_bordercolor', $this->border_color ) ?>;
732
- background-color: <?php echo get_option( 'relpoststh_background', $this->background ) ?>
733
- }
734
- #related_posts_thumbnails li:hover{
735
- background-color: <?php echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground ) ?>;
736
- }
737
- .relpost_content{
738
- font-size: <?php echo get_option( 'relpoststh_fontsize', $this->font_size ) . 'px' ?>;
739
- color: <?php echo get_option( 'relpoststh_fontcolor', $this->font_color ) ?>;
740
- }
741
- .relpost-block-single{
742
- background-color: <?php echo get_option( 'relpoststh_background', $this->background ) ?>;
743
- border-right: 1px solid <?php echo get_option( 'relpoststh_bordercolor', $this->border_color ) ?>;
744
- border-left: 1px solid <?php echo get_option( 'relpoststh_bordercolor', $this->border_color ) ?>;
745
- margin-right: -1px;
746
- }
747
- .relpost-block-single:hover{
748
- background-color: <?php echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground ) ?>;
749
- }
750
- </style>
751
-
752
- <?php
753
- }
754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
 
756
  }
757
 
758
  add_action( 'init', 'related_posts_thumbnails' );
759
 
760
  function related_posts_thumbnails() {
761
- global $related_posts_thumbnails;
762
- $related_posts_thumbnails = new RelatedPostsThumbnails();
 
 
763
  }
764
 
765
  // Include Widget File.
3
  * Plugin Name: WordPress Related Posts Thumbnails
4
  * Plugin URI: https://wpbrigade.com/wordpress/plugins/related-posts/?utm_source=related-posts-lite&utm_medium=plugin-uri&utm_campaign=pro-upgrade-rp
5
  * Description: Showing related posts thumbnails under the posts.
6
+ * Version: 1.6.4
7
  * Author: WPBrigade
8
  * Author URI: https://WPBrigade.com/?utm_source=related-posts-lite&utm_medium=author-link&utm_campaign=pro-upgrade-rp
9
  */
10
 
11
  /*
12
+ Copyright 2010 to 2018
13
 
14
+ This product was first developed by Maria I Shaldybina and later on maintained and developed by Adnan (WPBrigade.com)
15
 
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation; either version 2 of the License, or
19
+ (at your option) any later version.
20
 
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
  */
26
  class RelatedPostsThumbnails {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ /* Default values. PHP 4 compatible */
29
+ public $single_only = '1';
30
+ public $auto = '1';
31
+ public $top_text = '<h3>Related posts:</h3>';
32
+ public $number = 3;
33
+ public $relation = 'categories';
34
+ public $poststhname = 'thumbnail';
35
+ public $background = '#ffffff';
36
+ public $hoverbackground = '#eeeeee';
37
+ public $border_color = '#dddddd';
38
+ public $font_color = '#333333';
39
+ public $font_family = 'Arial';
40
+ public $font_size = '12';
41
+ public $text_length = '100';
42
+ public $excerpt_length = '0';
43
+ public $custom_field = '';
44
+ public $custom_height = '100';
45
+ public $custom_width = '100';
46
+ public $text_block_height = '75';
47
+ public $thsource = 'post-thumbnails';
48
+ public $categories_all = '1';
49
+ public $devmode = '0';
50
+ public $output_style = 'div';
51
+ public $post_types = array( 'post' );
52
+ public $custom_taxonomies = array();
53
+
54
+ protected $wp_kses_rp_args = array( 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), 'strong' => array() );
55
+
56
+ function __construct() {
57
+
58
+ $this->constant();
59
+ // initialization
60
+ load_plugin_textdomain( 'related-posts-thumbnails', false, basename( dirname( __FILE__ ) ) . '/locale' );
61
+ $this->default_image = esc_url( plugins_url( 'img/default.png', __FILE__ ) );
62
+
63
+ add_action( 'admin_enqueue_scripts', array(
64
+ $this,
65
+ 'admin_scripts'
66
+ ) );
67
+
68
+ // Compatibility for old default image path.
69
+ if ( $this->is_old_default_img() )
70
+ update_option( 'relpoststh_default_image', $this->default_image );
71
+
72
+ if ( get_option( 'relpoststh_auto', $this->auto ) ) {
73
+ $priority = apply_filters( 'rpt_content_prioirty', 10 ); // Alter priority of the related post content
74
+ add_filter( 'the_content', array(
75
+ $this,
76
+ 'auto_show'
77
+ ), $priority );
78
+ }
79
+
80
+ add_action( 'admin_menu', array(
81
+ $this,
82
+ 'admin_menu'
83
+ ) );
84
+ add_shortcode( 'related-posts-thumbnails', array(
85
+ $this,
86
+ 'get_html'
87
+ ) );
88
+
89
+ $this->wp_version = get_bloginfo( 'version' );
90
+
91
+ add_action( 'admin_footer', array(
92
+ $this,
93
+ 'add_deactive_modal'
94
+ ) );
95
+ add_action( 'wp_ajax_rpt_deactivate', array(
96
+ $this,
97
+ 'rpt_deactivate'
98
+ ) );
99
+
100
+ add_action( 'admin_init', array(
101
+ $this,
102
+ 'review_notice'
103
+ ) );
104
+ add_action( 'wp_enqueue_scripts', array(
105
+ $this,
106
+ 'front_scripts'
107
+ ) );
108
+
109
+ add_action( 'wp_head', array(
110
+ $this,
111
+ 'head_style'
112
+ ) );
113
+ }
114
+
115
+ function admin_scripts( $page ) {
116
+
117
+ if ( 'toplevel_page_related-posts-thumbnails' === $page ) {
118
+ wp_enqueue_media();
119
+ wp_enqueue_style( 'rpt_admin_css', plugins_url( 'assets/css/admin.css', __FILE__ ), false, RELATED_POSTS_THUMBNAILS_VERSION );
120
+ wp_enqueue_style( 'jquery-ui', 'http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css' );
121
+ wp_enqueue_style( 'wp-color-picker' );
122
+ wp_enqueue_script( 'rpt_admin_js', plugins_url( 'assets/js/admin.js', __FILE__ ), array(
123
+ 'jquery',
124
+ 'wp-color-picker',
125
+ 'jquery-ui-datepicker'
126
+ ), RELATED_POSTS_THUMBNAILS_VERSION );
127
+ }
128
+
129
+ }
130
+
131
+ function front_scripts() {
132
+
133
+ wp_enqueue_style( 'rpt_front_style', plugins_url( 'assets/css/front.css', __FILE__ ), false, RELATED_POSTS_THUMBNAILS_VERSION );
134
+
135
+ }
136
+
137
+ function constant() {
138
+
139
+ define( 'RELATED_POSTS_THUMBNAILS_VERSION', '1.6.2' );
140
+ define( 'RELATED_POSTS_THUMBNAILS_FEEDBACK_SERVER', 'https://wpbrigade.com/' );
141
+ define( 'RELATED_POSTS_THUMBNAILS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
142
+
143
+ }
144
+
145
+ /**
146
+ * Show the popup on pluing deactivate
147
+ *
148
+ * @since 1.6.2
149
+ */
150
+ function add_deactive_modal() {
151
+
152
+ global $pagenow;
153
+
154
+ if ( 'plugins.php' !== $pagenow ) {
155
+ return;
156
+ }
157
+
158
+ include RELATED_POSTS_THUMBNAILS_PLUGIN_DIR . 'inc/rpt-deactivate-form.php';
159
+
160
+ }
161
+
162
+
163
+ /**
164
+ * Send the user responce to api.
165
+ *
166
+ * @since 1.6.2
167
+ */
168
+ function rpt_deactivate() {
169
+
170
+ $email = get_option( 'admin_email' );
171
+ $_reason = sanitize_text_field( wp_unslash( $_POST[ 'reason' ] ) );
172
+ $reason_detail = sanitize_text_field( wp_unslash( $_POST[ 'reason_detail' ] ) );
173
+ $reason = '';
174
+
175
+ if ( $_reason == '1' ) {
176
+ $reason = 'I only needed the plugin for a short period';
177
+ } elseif ( $_reason == '2' ) {
178
+ $reason = 'I found a better plugin';
179
+ } elseif ( $_reason == '3' ) {
180
+ $reason = 'The plugin broke my site';
181
+ } elseif ( $_reason == '4' ) {
182
+ $reason = 'The plugin suddenly stopped working';
183
+ } elseif ( $_reason == '5' ) {
184
+ $reason = 'I no longer need the plugin';
185
+ } elseif ( $_reason == '6' ) {
186
+ $reason = 'It\'s a temporary deactivation. I\'m just debugging an issue.';
187
+ } elseif ( $_reason == '7' ) {
188
+ $reason = 'Other';
189
+ }
190
+ $fields = array(
191
+ 'email' => $email,
192
+ 'website' => get_site_url(),
193
+ 'action' => 'Deactivate',
194
+ 'reason' => $reason,
195
+ 'reason_detail' => $reason_detail,
196
+ 'blog_language' => get_bloginfo( 'language' ),
197
+ 'wordpress_version' => get_bloginfo( 'version' ),
198
+ 'php_version' => PHP_VERSION,
199
+ 'plugin_version' => RELATED_POSTS_THUMBNAILS_VERSION,
200
+ 'plugin_name' => 'Related Post Thumbnails'
201
+ );
202
+
203
+ $response = wp_remote_post( RELATED_POSTS_THUMBNAILS_FEEDBACK_SERVER, array(
204
+ 'method' => 'POST',
205
+ 'timeout' => 5,
206
+ 'httpversion' => '1.0',
207
+ 'blocking' => false,
208
+ 'headers' => array(),
209
+ 'body' => $fields
210
+ ) );
211
+
212
+ wp_die();
213
+
214
+ }
215
+
216
+ /**
217
+ * Check either to show notice or not.
218
+ *
219
+ * @since 1.8.2
220
+ */
221
+ public function review_notice() {
222
+
223
+ $this->review_dismissal();
224
+ $this->review_prending();
225
+
226
+ $review_dismissal = get_option( 'rpt_review_dismiss' );
227
+ if ( 'yes' == $review_dismissal ) {
228
+ return;
229
+ }
230
+
231
+ $activation_time = get_option( 'rpt_active_time' );
232
+ if ( !$activation_time ) {
233
+ $activation_time = time();
234
+ add_option( 'rpt_active_time', $activation_time );
235
+ }
236
+
237
+ // 1296000 = 15 Days in seconds.
238
+ if ( time() - $activation_time > 1296000 ) {
239
+ add_action( 'admin_notices', array(
240
+ $this,
241
+ 'review_notice_message'
242
+ ) );
243
+ }
244
+
245
+ }
246
+
247
+ /**
248
+ * Show review Message After 15 days.
249
+ *
250
+ * @since 1.8.2
251
+ */
252
+ public function review_notice_message() {
253
+
254
+ $scheme = ( parse_url( $_SERVER[ 'REQUEST_URI' ], PHP_URL_QUERY ) ) ? '&' : '?';
255
+ $url = $_SERVER[ 'REQUEST_URI' ] . $scheme . 'rpt_review_dismiss=yes';
256
+ $dismiss_url = wp_nonce_url( $url, 'rpt-review-nonce' );
257
+
258
+ $_later_link = $_SERVER[ 'REQUEST_URI' ] . $scheme . 'ssb_review_later=yes';
259
+ $later_url = wp_nonce_url( $_later_link, 'rpt-review-nonce' );
260
+
261
+ ?>
262
+ <style media="screen">
263
+ .rpt-review-notice { padding: 15px 0; background-color: #fff; border-radius: 3px; margin: 20px 20px 0 0; border-left: 4px solid transparent; } .rpt-review-notice:after { content: ''; display: table; clear: both; }
264
+ .rpt-review-thumbnail { float: left; line-height: 80px; text-align: center; width: 117px; }
265
+ .rpt-review-thumbnail img { width: 118px; vertical-align: middle; }
266
+ .rpt-review-text { overflow: hidden; }
267
+ .rpt-review-text h3 { font-size: 24px; margin: 0 0 5px; font-weight: 400; line-height: 1.3; }
268
+ .rpt-review-text p { font-size: 13px; margin: 0 0 5px; }
269
+ .rpt-review-ul { margin: 0; padding: 0; }
270
+ .rpt-review-ul li { display: inline-block; margin-right: 15px; }
271
+ .rpt-review-ul li a { display: inline-block; color: #10738B; text-decoration: none; padding-left: 26px; position: relative; }
272
+ .rpt-review-ul li a span { position: absolute; left: 0; top: -2px; }
273
+ </style>
274
+ <div class="rpt-review-notice">
275
+ <div class="rpt-review-thumbnail">
276
+ <img src="<?php
277
+ echo plugins_url( 'assets/images/rpt-logo.png', __FILE__ );
278
+ ?>" alt="">
279
+ </div>
280
+ <div class="rpt-review-text">
281
+ <h3><?php
282
+ _e( 'Leave A Review?', 'related-posts-thumbnails' );
283
+ ?></h3>
284
+ <p><?php
285
+ _e( 'We hope you\'ve enjoyed using Related Post Thumbnails! Would you consider leaving us a review on WordPress.org?', 'related-posts-thumbnails' );
286
+ ?></p>
287
+ <ul class="rpt-review-ul">
288
+ <li>
289
+ <a href="https://wordpress.org/support/plugin/related-posts-thumbnails/reviews/?filter=5" target="_blank"><span class="dashicons dashicons-external"></span>
290
+ <?php _e( 'Sure! I\'d love to!', 'related-posts-thumbnails' ); ?>
291
+ </a>
292
+ </li>
293
+ <li>
294
+ <a href="<?php echo $dismiss_url; ?>">
295
+ <span class="dashicons dashicons-smiley"></span>
296
+ <?php _e( 'I\'ve already left a review', 'related-posts-thumbnails' ); ?>
297
+ </a>
298
+ </li>
299
+ <li>
300
+ <a href="<?php echo $later_url; ?>">
301
+ <span class="dashicons dashicons-calendar-alt"></span>
302
+ <?php _e( 'Maybe Later', 'related-posts-thumbnails' ); ?>
303
+ </a>
304
+ </li>
305
+ <li>
306
+ <a href="<?php echo $dismiss_url; ?>">
307
+ <span class="dashicons dashicons-dismiss"></span>
308
+ <?php _e( 'Never show again', 'related-posts-thumbnails' ); ?>
309
+ </a>
310
+ </li>
311
+ </ul>
312
+ </div>
313
+ </div>
314
+
315
+ <?php }
316
+
317
+ /**
318
+ * Set time to current so review notice will popup after 15 days
319
+ *
320
+ * @since 1.8.2
321
+ */
322
+ function review_prending() {
323
+
324
+ // delete_site_option( 'rpt_review_dismiss' );
325
+ if ( !is_admin() || !current_user_can( 'manage_options' ) || !isset( $_GET[ '_wpnonce' ] ) || !wp_verify_nonce( sanitize_key( wp_unslash( $_GET[ '_wpnonce' ] ) ), 'rpt-review-nonce' ) || !isset( $_GET[ 'ssb_review_later' ] ) ) {
326
+
327
+ return;
328
+ }
329
+
330
+ // Reset Time to current time.
331
+ update_option( 'rpt_active_time', time() );
332
+
333
+ }
334
+
335
+ /**
336
+ * Check and Dismiss review message.
337
+ *
338
+ * @since 1.8.2
339
+ */
340
+ private function review_dismissal() {
341
+
342
+ //delete_option( 'rpt_review_dismiss' );
343
+ if ( !is_admin() || !current_user_can( 'manage_options' ) || !isset( $_GET[ '_wpnonce' ] ) || !wp_verify_nonce( sanitize_key( wp_unslash( $_GET[ '_wpnonce' ] ) ), 'rpt-review-nonce' ) || !isset( $_GET[ 'rpt_review_dismiss' ] ) ) {
344
+
345
+ return;
346
+ }
347
+
348
+ add_option( 'rpt_review_dismiss', 'yes' );
349
+
350
+ }
351
+
352
+
353
+ /**
354
+ * [is_old_default_img Check the compatibility for old default image path.]
355
+ * @return boolean Return true if path is old.
356
+ */
357
+ function is_old_default_img() {
358
+
359
+ if ( get_option( 'relpoststh_default_image' ) !== $this->default_image ) {
360
+
361
+ $chunks = explode( '/', get_option( 'relpoststh_default_image' ) );
362
+ if ( in_array( 'related-posts-thumbnails', $chunks ) ) {
363
+ return true;
364
+ }
365
+ }
366
+
367
+ }
368
+
369
+ function auto_show( $content ) {
370
+
371
+ // Automatically displaying related posts under post body
372
+ return $content . $this->get_html( true );
373
+
374
+ }
375
+
376
+ function get_html( $show_top = false ) {
377
+
378
+ // Getting related posts HTML
379
+ if ( $this->is_relpoststh_show() ) {
380
+ return $this->get_thumbnails( $show_top );
381
+ }
382
+ return '';
383
+
384
+ }
385
+
386
+ function get_thumbnails( $show_top = false ) {
387
+
388
+ // Retrieve Related Posts HTML for output
389
+ $output = '';
390
+ $debug = 'Developer mode initialisation; Version: 1.2.9;';
391
+ $time = microtime( true );
392
+ $posts_number = get_option( 'relpoststh_number', $this->number );
393
+ $height = '';
394
+ $width = '';
395
+ // $date = '';
396
+ $sort_by = get_option( 'rpt_post_sort') == 'latest' ? 'post_date': 'rand()';
397
+
398
+ // rpt_content_align: add content allignment class; clases are: relpost-align-left, relpost-align-right and relpost-align-center
399
+ $output = '<div class="relpost-thumb-wrapper"><div class="'. apply_filters( 'rpt_content_align', '' ) . '">';
400
+ $alt = '';
401
+
402
+ if ( $posts_number <= 0 ) { // return nothing if this parameter was set to <= 0
403
+ $output = '';
404
+ return $this->finish_process( $output, $debug . 'Posts number is 0;', $time );
405
+ }
406
+
407
+ $id = get_the_ID();
408
+ $relation = get_option( 'relpoststh_relation', $this->relation );
409
+ $poststhname = get_option( 'relpoststh_poststhname', $this->poststhname );
410
+ $text_length = get_option( 'relpoststh_textlength', $this->text_length );
411
+ $excerpt_length = get_option( 'relpoststh_excerptlength', $this->excerpt_length );
412
+ $thsource = get_option( 'relpoststh_thsource', $this->thsource );
413
+ $categories_show_all = get_option( 'relpoststh_show_categoriesall', get_option( 'relpoststh_categoriesall', $this->categories_all ) );
414
+ $onlywiththumbs = ( current_theme_supports( 'post-thumbnails' ) && $thsource == 'post-thumbnails' ) ? get_option( 'relpoststh_onlywiththumbs', false ) : false;
415
+ $post_type = get_post_type();
416
+
417
+ global $wpdb;
418
+
419
+ /* Get taxonomy terms */
420
+ $debug .= "Relation: $relation; All categories: $categories_show_all;";
421
+ $use_filter = ( $categories_show_all != '1' || $relation != 'no' );
422
+
423
+ if ( $use_filter ) {
424
+ $query_objects = "SELECT distinct object_id FROM $wpdb->term_relationships WHERE 1=1 ";
425
+
426
+ if ( $relation != 'no' ) {
427
+ /* Get object terms */
428
+ if ( $relation == 'categories' ) {
429
+ $taxonomy = array(
430
+ 'category'
431
+ );
432
+ } elseif ( $relation == 'tags' ) {
433
+ $taxonomy = array(
434
+ 'post_tag'
435
+ );
436
+ } elseif ( $relation == 'custom' ) {
437
+ $taxonomy = get_option( 'relpoststh_custom_taxonomies', $this->custom_taxonomies );
438
+ } else {
439
+ $taxonomy = array(
440
+ 'category',
441
+ 'post_tag'
442
+ );
443
+ }
444
+ $object_terms = wp_get_object_terms( $id, $taxonomy, array(
445
+ 'fields' => 'ids'
446
+ ) );
447
+ if ( empty( $object_terms ) || !is_array( $object_terms ) ) { // no terms to get taxonomy
448
+ $output = '';
449
+ return $this->finish_process( $output, $debug . __( 'No taxonomy terms to get posts;' ), $time );
450
+ }
451
+
452
+ $query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('" . implode( "', '", $object_terms ) . "')";
453
+ $object_taxonomy = $wpdb->get_results( $query );
454
+ $object_taxonomy_a = array();
455
+ if ( count( $object_taxonomy ) > 0 ) {
456
+ foreach ( $object_taxonomy as $item ) {
457
+ $object_taxonomy_a[] = $item->term_taxonomy_id;
458
+ }
459
+ }
460
+ $query_objects .= " AND term_taxonomy_id IN ('" . implode( "', '", $object_taxonomy_a ) . "') ";
461
+ }
462
+
463
+ if ( $categories_show_all != '1' ) {
464
+ /* Get filter terms */
465
+ $select_terms = get_option( 'relpoststh_show_categories', get_option( 'relpoststh_categories' ) );
466
+ if ( empty( $select_terms ) || !is_array( $select_terms ) ) { // if no categories were specified intentionally return nothing
467
+ $output = '';
468
+ return $this->finish_process( $output, $debug . __( 'No categories were selected;' ), $time );
469
+ }
470
+
471
+ $query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('" . implode( "', '", $select_terms ) . "')";
472
+ $taxonomy = $wpdb->get_results( $query );
473
+ $filter_taxonomy_a = array();
474
+ if ( count( $taxonomy ) > 0 ) {
475
+ foreach ( $taxonomy as $item ) {
476
+ $filter_taxonomy_a[] = $item->term_taxonomy_id;
477
+ }
478
+ }
479
+ if ( $relation != 'no' ) {
480
+ $query_objects .= " AND object_id IN (SELECT distinct object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ('" . implode( "', '", $filter_taxonomy_a ) . "') )";
481
+ } else {
482
+ $query_objects .= " AND term_taxonomy_id IN ('" . implode( "', '", $filter_taxonomy_a ) . "')";
483
+ }
484
+ }
485
+
486
+ $relationships = $wpdb->get_results( $query_objects );
487
+ $related_objects = array();
488
+ if ( count( $relationships ) > 0 ) {
489
+ foreach ( $relationships as $item ) {
490
+ $related_objects[] = $item->object_id;
491
+ }
492
+ }
493
+ }
494
+
495
+ $query = "SELECT distinct ID FROM $wpdb->posts ";
496
+ $where = " WHERE post_type = '" . $post_type . "' AND post_status = 'publish' AND ID<>" . $id; // not the current post
497
+ $startdate = get_option( 'relpoststh_startdate' );
498
+ if ( !empty( $startdate ) && preg_match( '/^\d\d\d\d-\d\d-\d\d$/', $startdate ) ) { // If startdate was set
499
+ $debug .= "Startdate: $startdate;";
500
+ $where .= " AND post_date >= '" . $startdate . "'";
501
+ }
502
+ if ( $use_filter ) {
503
+ $where .= " AND ID IN ('" . implode( "', '", $related_objects ) . "')";
504
+ }
505
+ $join = '';
506
+ if ( $onlywiththumbs ) {
507
+ $debug .= 'Only with thumbnails;';
508
+ $join = " INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)";
509
+ $where .= " AND $wpdb->postmeta.meta_key = '_thumbnail_id'";
510
+ }
511
+
512
+ $order = ' ORDER BY ' . $sort_by . ' LIMIT ' . $posts_number;
513
+ $random_posts = $wpdb->get_results( $query . $join . $where . $order );
514
+
515
+ /* Get posts by their IDs */
516
+ if ( !is_array( $random_posts ) || count( $random_posts ) < 1 ) {
517
+ $output = '';
518
+ return $this->finish_process( $output, $debug . __( 'No posts matching relationships criteria;' ), $time );
519
+ }
520
+
521
+ $posts_in = array();
522
+ foreach ( $random_posts as $random_post ) {
523
+ $posts_in[] = $random_post->ID;
524
+ }
525
+ $query = "SELECT ID, post_content, post_excerpt, post_title FROM $wpdb->posts WHERE ID IN ('" . implode( "', '", $posts_in ) . "')";
526
+ $posts = $wpdb->get_results( $query );
527
+
528
+ if ( !( is_array( $posts ) && count( $posts ) > 0 ) ) { // no posts
529
+ $debug .= 'No posts found;';
530
+ $output = '';
531
+ return $this->finish_process( $output, $debug, $time );
532
+ } else {
533
+ $debug .= 'Found ' . count( $posts ) . ' posts;';
534
+ }
535
+
536
+ /* Calculating sizes */
537
+ if ( $thsource == 'custom-field' ) {
538
+ $debug .= 'Custom sizes;';
539
+ $width = get_option( 'relpoststh_customwidth', $this->custom_width );
540
+ $height = get_option( 'relpoststh_customheight', $this->custom_height );
541
+ } else { // post-thumbnails source
542
+ if ( $poststhname == 'thumbnail' || $poststhname == 'medium' || $poststhname == 'large' ) { // get thumbnail size for basic sizes
543
+ $debug .= 'Basic sizes;';
544
+ $width = get_option( "{$poststhname}_size_w" );
545
+ $height = get_option( "{$poststhname}_size_h" );
546
+ } elseif ( current_theme_supports( 'post-thumbnails' ) ) { // get sizes for theme supported thumbnails
547
+ global $_wp_additional_image_sizes;
548
+ if ( isset( $_wp_additional_image_sizes[ $poststhname ] ) ) {
549
+ $debug .= 'Additional sizes;';
550
+ $width = $_wp_additional_image_sizes[ $poststhname ][ 'width' ];
551
+ $height = $_wp_additional_image_sizes[ $poststhname ][ 'height' ];
552
+ } else {
553
+ $debug .= 'No additional sizes;';
554
+ }
555
+ }
556
+ }
557
+ // displaying square if one size is not cropping
558
+ if ( $height == 9999 ) {
559
+ $height = $width;
560
+ }
561
+ if ( $width == 9999 ) {
562
+ $width = $height;
563
+ }
564
+ // theme is not supporting but settings were not changed
565
+ if ( empty( $width ) ) {
566
+ $debug .= 'Using default width;';
567
+ $width = get_option( 'thumbnail_size_w' );
568
+ }
569
+ if ( empty( $height ) ) {
570
+ $debug .= 'Using default height;';
571
+ $height = get_option( 'thumbnail_size_h' );
572
+ }
573
+ $debug .= 'Got sizes ' . $width . 'x' . $height . ';';
574
+ // rendering related posts HTML
575
+ if ( $show_top ) {
576
+ $output .= stripslashes( get_option( 'relpoststh_top_text', $this->top_text ) );
577
+ }
578
+ $relpoststh_output_style = get_option( 'relpoststh_output_style', $this->output_style );
579
+ $relpoststh_cleanhtml = get_option( 'relpoststh_cleanhtml', 0 );
580
+ $text_height = get_option( 'relpoststh_textblockheight', $this->text_block_height );
581
+
582
+
583
+ if ( $relpoststh_output_style == 'list' ) {
584
+ $output .= '<ul id="related_posts_thumbnails"';
585
+ if ( ! $relpoststh_cleanhtml ) {
586
+ $output .= ' style="list-style-type:none; list-style-position: inside; padding: 0; margin:0"';
587
+ }
588
+ $output .= '>';
589
+ } else {
590
+ $output .= '<div style="clear: both"></div><ul class="related-posts-nav">';
591
+ $output .= '<div style="clear: both"></div><div class="relpost-block-container">';
592
+ }
593
+
594
+ foreach ( $posts as $post ) {
595
+ $image = '';
596
+ $url = '';
597
+ $alt = '';
598
+ if ( $thsource == 'custom-field' ) {
599
+ $debug .= 'Using custom field;';
600
+ $url = $basic_url = get_post_meta( $post->ID, get_option( 'relpoststh_customfield', $this->custom_field ), true );
601
+ if ( strpos( $url, '/wp-content' ) !== false ) {
602
+ $url = substr( $url, strpos( $url, '/wp-content' ) );
603
+ }
604
+ $theme_resize_url = get_option( 'relpoststh_theme_resize_url', '' );
605
+ if ( !empty( $theme_resize_url ) ) {
606
+ $url = $theme_resize_url . '?src=' . $url . '&w=' . $width . '&h=' . $height . '&zc=1&q=90';
607
+ }
608
+ } else {
609
+ $from_post_body = true;
610
+ if ( current_theme_supports( 'post-thumbnails' ) ) { // using built in Wordpress feature
611
+ $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
612
+ $debug .= 'Post-thumbnails enabled in theme;';
613
+ if ( !( empty( $post_thumbnail_id ) || $post_thumbnail_id === false ) ) { // post has thumbnail
614
+ $debug .= 'Post has thumbnail ' . $post_thumbnail_id . ';';
615
+ $debug .= 'Postthname: ' . $poststhname . ';';
616
+ $image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
617
+ $alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
618
+ $url = $image[ 0 ];
619
+ $from_post_body = false;
620
+ } else {
621
+ $debug .= 'Post has no thumbnail;';
622
+ }
623
+ }
624
+ if ( $from_post_body ) { // Theme does not support post-thumbnails, or post does not have assigned thumbnail
625
+ $debug .= 'Getting image from post body;';
626
+ $wud = wp_upload_dir();
627
+ preg_match_all( '|<img.*?src=[\'"](' . $wud[ 'baseurl' ] . '.*?)[\'"].*?>|i', $post->post_content, $matches ); // searching for the first uploaded image in text
628
+
629
+ if ( isset( $matches ) && isset( $matches[ 1 ][ 0 ] ) ) {
630
+ $image = $matches[ 1 ][ 0 ];
631
+ $html = $matches[ 0 ][ 0 ];
632
+ if ( !empty( $html ) ) {
633
+ preg_match( '/alt="([^"]*)"/i', $html, $array );
634
+
635
+ if ( !empty( $array ) && is_array( $array ) ) {
636
+ $explode_tag = explode( '"', $array[ 0 ] );
637
+ $alt = $explode_tag[ 1 ];
638
+ }
639
+
640
+ }
641
+ } else {
642
+ $debug .= 'No image was found;';
643
+ }
644
+
645
+ if ( strlen( trim( $image ) ) > 0 ) {
646
+ $image_sizes = @getimagesize( $image );
647
+ if ( $image_sizes === false ) {
648
+ $debug .= 'Unable to determine parsed image size';
649
+ }
650
+ if ( $image_sizes !== false && isset( $image_sizes[ 0 ] ) && $image_sizes[ 0 ] == $width ) { // if this image is the same size as we need
651
+ $debug .= 'Image used is the required size;';
652
+ $url = $image;
653
+ } else { // if not, search for resized thumbnail according to Wordpress thumbnails naming function
654
+ $debug .= 'Changing image according to Wordpress standards;';
655
+ $url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
656
+ }
657
+ } else {
658
+ $debug .= 'Found wrong formatted image: ' . $image . ';';
659
+ }
660
+ }
661
+ $basic_url = $url;
662
+ }
663
+
664
+ if ( strpos( $url, '/' ) === 0 ) {
665
+ $debug .= 'Relative url: ' . $url . ';';
666
+ $url = $basic_url = get_bloginfo( 'url' ) . $url;
667
+ }
668
+
669
+ $debug .= 'Image URL: ' . $url . ';';
670
+ if ( empty( $basic_url ) ) { // parsed URL is empty or no file if can check
671
+ $debug .= 'Image is empty or no file. Using default image;';
672
+ $url = get_option( 'relpoststh_default_image', $this->default_image );
673
+ }
674
+
675
+ $title = $this->process_text_cut( $post->post_title, $text_length );
676
+ $post_excerpt = ( empty( $post->post_excerpt ) ) ? $post->post_content : $post->post_excerpt;
677
+ $excerpt = $this->process_text_cut( $post_excerpt, $excerpt_length );
678
+
679
+ if ( !empty( $title ) && !empty( $excerpt ) ) {
680
+ $title = '<b>' . $title . '</b>';
681
+ $excerpt = '<br/>' . $excerpt;
682
+ }
683
+
684
+ if ( empty( $alt ) ) {
685
+ $alt = str_replace('"', '', $title);
686
+ }
687
+
688
+ // if ( get_option( 'relpoststh_show_date' ) == '1' ) {
689
+ // $date = '<span class="rpth_post_date">' . get_the_date( 'l F j, Y', $post->ID ) . '</span>';
690
+ // $debug .= 'Using date under posts;';
691
+ // }
692
+
693
+ $fontface = str_replace( '"', "'", stripslashes( get_option( 'relpoststh_fontfamily', $this->font_family ) ) );
694
+
695
+ $debug .= 'Using title with size ' . $text_length . '. Using excerpt with size ' . $excerpt_length . ';';
696
+
697
+ if ( $relpoststh_output_style == 'list' ) {
698
+ $link = get_permalink( $post->ID );
699
+ $output .= '<li ';
700
+ if ( !$relpoststh_cleanhtml ) {
701
+ // $output .= ' onmouseout="this.style.backgroundColor=\'' . get_option( 'relpoststh_background', $this->background ) . '\'"';
702
+ }
703
+ $output .= '>';
704
+ $output .= '<a href="' . $link . '" ><img class="relpost-post-image" alt="' . $alt . '" src="' . esc_url( $url ) . '" width="' . $width . '" height="' . $height . '" ';
705
+ if ( !$relpoststh_cleanhtml ) {
706
+ // $output .= 'style="padding: 0px; margin: 0px; border: 0pt none;"';
707
+ }
708
+ $output .= '/></a>';
709
+ if ( $text_height != '0' ) {
710
+ $output .= '<a href="' . $link . '" class="relpost_content"';
711
+ if ( !$relpoststh_cleanhtml ) {
712
+ $output .= ' style="width: ' . $width . 'px;height: ' . $text_height . 'px; font-family: ' . $fontface . '; "';
713
+ }
714
+ // $output .= '><span class="rpth_list_content">' . $title . $excerpt . '</span>' . $date . '</a></li>';
715
+ $output .= '><span class="rpth_list_content">' . $title . $excerpt . '</span>' . $date . '</a></li>';
716
+ }
717
+ } else {
718
+ $output .= '<a class="relpost-block-single" href="' . get_permalink( $post->ID ) . '">';
719
+ $output .= '<div style="width: ' . $width . 'px; height: ' . ( $height + $text_height ) . 'px;">';
720
+ $output .= '<div class="relpost-block-single-image" alt="' . $alt . '" style=" background: transparent url(' . esc_url( $url ) . ') no-repeat scroll 0% 0%; width: ' . $width . 'px; height: ' . $height . 'px; "></div>';
721
+ $output .= '<div class="relpost-block-single-text" style="font-family: ' . $fontface . '; font-size: ' . get_option( 'relpoststh_fontsize', $this->font_size ) . 'px; color: ' . get_option( 'relpoststh_fontcolor', $this->font_color ) . ';">' . $title . $excerpt . '</div>';
722
+ // $output .= $date;
723
+ $output .= '</div>';
724
+ $output .= '</a>';
725
+ }
726
+ } // end foreach
727
+ if ( $relpoststh_output_style == 'list' ) {
728
+ $output .= '</ul>';
729
+ } else {
730
+ $output .= '</div></div>';
731
+ }
732
+
733
+ $output .= '<div style="clear: both"></div>';
734
+ $output .= '</div>';
735
+ return $this->finish_process( $output, $debug, $time );
736
+
737
+ }
738
+
739
+ function finish_process( $output, $debug, $time ) {
740
+
741
+ $devmode = get_option( 'relpoststh_devmode', $this->devmode );
742
+ if ( $devmode ) {
743
+ $time = microtime( true ) - $time;
744
+ $debug .= "Plugin execution time: $time sec;";
745
+ $output .= '<!-- ' . $debug . ' -->';
746
+ }
747
+ return $output;
748
+
749
+ }
750
+
751
+ function process_text_cut( $text, $length ) {
752
+
753
+ if ( $length == 0 ) {
754
+ return '';
755
+ } else {
756
+ $text = strip_tags( strip_shortcodes( $text ) );
757
+ if ( function_exists( 'mb_strlen' ) ) {
758
+ return ( ( mb_strlen( $text ) > $length ) ? mb_substr( $text, 0, $length ) . '...' : $text );
759
+ } else {
760
+ return ( ( strlen( $text ) > $length ) ? substr( $text, 0, $length ) . '...' : $text );
761
+ }
762
+ }
763
+
764
+ }
765
+
766
+ function is_relpoststh_show() {
767
+
768
+ // Checking display options
769
+ if ( !is_single() && get_option( 'relpoststh_single_only', $this->single_only ) ) { // single only
770
+ return false;
771
+ }
772
+ /* Check post type */
773
+ $post_types = get_option( 'relpoststh_post_types', $this->post_types );
774
+ $post_type = get_post_type();
775
+ if ( !in_array( $post_type, $post_types ) ) {
776
+ return false;
777
+ }
778
+ /* Check categories */
779
+ $id = get_the_ID();
780
+ $categories_all = get_option( 'relpoststh_categoriesall', $this->categories_all );
781
+ if ( $categories_all != '1' ) { // only specific categories were selected
782
+ $post_categories = wp_get_object_terms( $id, array(
783
+ 'category'
784
+ ), array(
785
+ 'fields' => 'ids'
786
+ ) );
787
+ $relpoststh_categories = get_option( 'relpoststh_categories' );
788
+ if ( !is_array( $relpoststh_categories ) || !is_array( $post_categories ) ) { // no categories were selcted or post doesn't belong to any
789
+ return false;
790
+ }
791
+ $common_categories = array_intersect( $relpoststh_categories, $post_categories );
792
+ if ( empty( $common_categories ) ) { // post doesn't belong to specified categories
793
+ return false;
794
+ }
795
+ }
796
+ return true;
797
+
798
+ }
799
+
800
+ function admin_menu() {
801
+
802
+ $page = add_menu_page( __( 'Related Posts Thumbnails', 'related-posts-thumbnails' ), __( 'Related Posts', 'related-posts-thumbnails' ), 'administrator', 'related-posts-thumbnails', array(
803
+ $this,
804
+ 'admin_interface'
805
+ ), 'dashicons-screenoptions' );
806
+
807
+ }
808
+
809
+ function admin_interface() {
810
+
811
+ include_once RELATED_POSTS_THUMBNAILS_PLUGIN_DIR . '/inc/rpt-settings.php';
812
+
813
+ }
814
+
815
+ function display_categories_list( $categoriesall, $categories, $selected_categories, $all_name, $specific_name ) {
816
+ ?>
817
+ <input id="<?php
818
+ echo $all_name;
819
+ ?>" class="select_all" type="checkbox" name="<?php
820
+ echo $all_name;
821
+ ?>" value="1" <?php
822
+ if ( $categoriesall == '1' ) {
823
+ echo 'checked="checked"';
824
+ }
825
+ ?>/>
826
+ <label for="<?php
827
+ echo $all_name;
828
+ ?>"><?php
829
+ _e( 'All', 'related-posts-thumbnails' );
830
+ ?></label>
831
+ <div class="select_specific" <?php
832
+ if ( $categoriesall == '1' ):
833
+ ?> style="display:none" <?php
834
+ endif;
835
+ ?>>
836
+ <?php
837
+ foreach ( $categories as $category ):
838
+ ?>
839
+ <input type="checkbox" name="<?php
840
+ echo $specific_name;
841
+ ?>[]" id="<?php
842
+ echo $specific_name;
843
+ ?>_<?php
844
+ echo $category->category_nicename;
845
+ ?>" value="<?php
846
+ echo $category->cat_ID;
847
+ ?>" <?php
848
+ if ( in_array( $category->cat_ID, (array) $selected_categories ) ) {
849
+ echo 'checked="checked"';
850
+ }
851
+ ?>/>
852
+ <label for="<?php
853
+ echo $specific_name;
854
+ ?>_<?php
855
+ echo $category->category_nicename;
856
+ ?>"><?php
857
+ echo $category->cat_name;
858
+ ?></label><br />
859
+ <?php
860
+ endforeach;
861
+ ?>
862
+ </div>
863
+
864
+ <?php
865
+ }
866
+
867
+
868
+
869
+
870
+ function head_style() {
871
+ ?>
872
+ <style>
873
+ #related_posts_thumbnails li{
874
+ border-right: 1px solid <?php
875
+ echo get_option( 'relpoststh_bordercolor', $this->border_color );
876
+ ?>;
877
+ background-color: <?php
878
+ echo get_option( 'relpoststh_background', $this->background );
879
+ ?>
880
+ }
881
+ #related_posts_thumbnails li:hover{
882
+ background-color: <?php
883
+ echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground );
884
+ ?>;
885
+ }
886
+ .relpost_content{
887
+ font-size: <?php
888
+ echo get_option( 'relpoststh_fontsize', $this->font_size ) . 'px';
889
+ ?>;
890
+ color: <?php
891
+ echo get_option( 'relpoststh_fontcolor', $this->font_color );
892
+ ?>;
893
+ }
894
+ .relpost-block-single{
895
+ background-color: <?php
896
+ echo get_option( 'relpoststh_background', $this->background );
897
+ ?>;
898
+ border-right: 1px solid <?php
899
+ echo get_option( 'relpoststh_bordercolor', $this->border_color );
900
+ ?>;
901
+ border-left: 1px solid <?php
902
+ echo get_option( 'relpoststh_bordercolor', $this->border_color );
903
+ ?>;
904
+ margin-right: -1px;
905
+ }
906
+ .relpost-block-single:hover{
907
+ background-color: <?php
908
+ echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground );
909
+ ?>;
910
+ }
911
+ </style>
912
+
913
+ <?php
914
+ }
915
 
916
  }
917
 
918
  add_action( 'init', 'related_posts_thumbnails' );
919
 
920
  function related_posts_thumbnails() {
921
+
922
+ global $related_posts_thumbnails;
923
+ $related_posts_thumbnails = new RelatedPostsThumbnails();
924
+
925
  }
926
 
927
  // Include Widget File.