Newpost Catch - Version 1.3.1

Version Description

  • Required PHP5.3+(changed widgets_init hook).
  • Abolished option page.
  • Compatibility check with WP 4.5.
Download this release

Release Info

Developer s56bouya
Plugin Icon wp plugin Newpost Catch
Version 1.3.1
Comparing to
See all releases

Code changes from version 1.2.7 to 1.3.1

Files changed (4) hide show
  1. class.php +117 -147
  2. newpost-catch.php +2 -15
  3. npc_admin.php +0 -152
  4. readme.txt +18 -3
class.php CHANGED
@@ -1,43 +1,38 @@
1
  <?php
2
- /**
3
- * NewpostCatch class
4
- **/
5
  if ( !class_exists('NewpostCatch') ) {
6
  class NewpostCatch extends WP_Widget {
7
- /*** variables ***/
8
- var $version = "1.2.7";
9
  var $pluginDir = "";
10
 
11
- /*** structure ***/
12
- function NewpostCatch() {
13
- /** widget settings **/
14
  $widget_ops = array( 'description' => 'Thumbnails in new articles.' );
15
 
16
- /** widget actual processes **/
17
- parent::WP_Widget(false, $name = 'Newpost Catch', $widget_ops );
18
-
19
- /** plugin path **/
20
- if (empty($this->pluginDir)) $this->pluginDir = WP_PLUGIN_URL . '/newpost-catch';
21
-
22
- /** default thumbnail **/
23
- $this->default_thumbnail = $this->pluginDir . "/no_thumb.png";
24
 
25
- /** charset **/
26
- $this->charset = get_bloginfo('charset');
27
 
28
- /** print stylesheet **/
 
 
 
29
  add_action( 'get_header', array( &$this, 'enqueue_stylesheet' ) );
30
 
31
- /** activate textdomain for translations **/
32
  add_action( 'init', array( &$this, 'NewpostCatch_textdomain') );
33
  }
34
 
35
- /** plugin localization **/
36
  function NewpostCatch_textdomain() {
37
  load_plugin_textdomain ( 'newpost-catch', false, basename( rtrim(dirname(__FILE__), '/') ) . '/languages' );
38
  }
39
 
40
- /** plugin enqueue_stylesheet **/
41
  function enqueue_stylesheet() {
42
  if( get_option( 'widget_newpostcatch' ) ){
43
  $options = array_filter( get_option( 'widget_newpostcatch' ) );
@@ -48,99 +43,90 @@ if ( !class_exists('NewpostCatch') ) {
48
  if( in_array('on' , $options) ){
49
  $css_path = plugins_url('newpost-catch/style.css');
50
  } else {
51
- $css_path = ( @file_exists(STYLESHEETPATH.'/css/newpost-catch.css') ) ? get_stylesheet_directory_uri() . '/css/newpost-catch.css' : "" ;
52
  }
53
 
54
  // register CSS
55
- wp_register_style( 'newpost-catch', $css_path, array(), $this->version );
56
  wp_enqueue_style( 'newpost-catch' );
57
  }
58
  }
59
 
60
- /**▼ create widget ▼**/
61
- function widget($args, $instance) {
62
- extract( $args );
 
 
63
 
64
- $title = apply_filters('NewpostCatch_widget_title', $instance['title']);
65
- $width = apply_filters('NewpostCatch_widget_width', $instance['width']);
66
- $height = apply_filters('NewpostCatch_widget_height', $instance['height']);
67
- $number = apply_filters('NewpostCatch_widget_number', $instance['number']);
68
- $ignore = apply_filters('NewpostCatch_widget_ignore', $instance['ignore_check']['active']);
69
- $css = apply_filters('NewpostCatch_widget_css', $instance['css']);
70
- $cat = apply_filters('NewpostCatch_widget_cat', $instance['cat']);
71
- if( !empty($instance['post_type']) ){
72
- $post_type = apply_filters('NewpostCatch_widget_post_type', $instance['post_type']);
73
  } else {
74
- $post_type = apply_filters('NewpostCatch_widget_post_type', 'post');
75
  }
76
- /* if( $instance['ignore_check']['active'] = !false ) { $ignore = 1; } else { $ignore = 0; }*/
77
-
78
- if( !function_exists('no_thumb_image') ){
79
- function no_thumb_image() {
80
- ob_start();
81
- ob_end_clean();
82
- preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_content(), $matches );
83
 
84
- if( isset($matches[1][0]) && !is_wp_error($matches[1][0]) ){
85
- $set_img = $matches[1][0];
86
- } else {
87
- $set_img = WP_PLUGIN_URL . '/newpost-catch' . '/no_thumb.png';
88
- }
89
- return $set_img;
90
- }
 
 
 
 
91
  }
92
 
93
  echo $before_widget;
94
 
95
  if ( $title ) echo $before_title . $title . $after_title;
96
- $sticky = get_option( 'sticky_posts' );
97
- if( $ignore == !false ){
98
- $npc_query = new WP_Query( array(
99
- 'post_type' => $post_type,
100
- 'cat' => $cat,
101
- 'posts_per_page' => $number,
102
- 'ignore_sticky_posts' => 0,
103
- 'orderby' => 'date',
104
- 'order' => 'DESC'
105
- ));
106
- } else {
107
- $npc_query = new WP_Query( array(
108
- 'post_type' => $post_type,
109
- 'cat' => $cat,
110
- 'posts_per_page' => $number,
111
- 'post_not_in' => $sticky,
112
- 'ignore_sticky_posts' => 1,
113
- 'orderby' => 'date',
114
- 'order' => 'DESC'
115
- ));
116
- }
117
  ?>
118
- <ul id="npcatch" >
119
- <?php if( $npc_query->have_posts() ) : ?>
120
- <?php $i = 0; ?>
121
- <?php while( $npc_query->have_posts() ) : $npc_query->the_post(); ?>
122
- <li>
123
- <a href="<?php echo esc_html( get_permalink() ); ?>" title="<?php esc_attr( the_title() ); ?>" >
124
- <?php if( has_post_thumbnail() ) { ?>
125
  <?php
126
- $thumb_id = get_post_thumbnail_id();
127
- $thumb_url = wp_get_attachment_image_src($thumb_id);
128
- $thumb_url = $thumb_url[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  ?>
130
- <img src="<?php echo esc_attr( $thumb_url ); ?>" width="<?php echo esc_attr( $width ); ?>" height="<?php echo esc_attr( $height ); ?>" alt="<?php esc_attr( the_title() ); ?>" title="<?php esc_attr( the_title() ); ?>" />
131
- <?php } else { ?>
132
- <img src="<?php echo esc_attr( no_thumb_image() ); ?>" width="<?php echo esc_attr( $width ); ?>" height="<?php echo esc_attr( $height ); ?>" alt="<?php esc_attr( the_title() ); ?>" title="<?php esc_attr( the_title() ); ?>" />
133
- <?php } ?>
134
- </a>
135
- <span class="title"><a href="<?php echo esc_html( get_permalink() ); ?>" title="<?php esc_attr( the_title() ); ?>"><?php esc_html( the_title() ); ?>
136
- <?php if ( $instance['date']['active'] == true ) { ?>
137
- <span class="date"><?php echo esc_html( get_the_time( get_option('date_format') ) ); ?></span>
138
- <?php } ?>
139
- </a></span>
140
- </li>
141
- <?php $i++; ?>
142
- <?php endwhile; ?>
143
- <?php else : ?>
144
  <p>no post</p>
145
  <?php endif; wp_reset_postdata(); ?>
146
  </ul>
@@ -148,7 +134,6 @@ $thumb_url = $thumb_url[0];
148
  <?php
149
  echo $after_widget;
150
  }
151
- /**▲ create widget ▲**/
152
 
153
  /** @see WP_Widget::update **/
154
  // updates each widget instance when user clicks the "save" button
@@ -180,7 +165,7 @@ $thumb_url = $thumb_url[0];
180
  /** @see WP_Widget::form **/
181
  function form($instance) {
182
 
183
- /** define default value **/
184
  $defaults = array(
185
  'title' => __('LatestPost(s)' , 'newpost-catch'),
186
  'width' => 10,
@@ -212,13 +197,13 @@ $thumb_url = $thumb_url[0];
212
  <input style="width:30px;" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($instance['number']); ?>" /> <?php _e('Post(s)', 'newpost-catch'); ?>
213
  </p>
214
  <p>
215
- <input type="checkbox" class="checkbox" <?php echo ($instance['date']['active']) ? 'checked="checked"' : ''; ?> id="<?php echo $this->get_field_id( 'date' ); ?>" name="<?php echo $this->get_field_name( 'date' ); ?>" /> <label for="<?php echo $this->get_field_id( 'date' ); ?>"><?php _e('Display date', 'newpost-catch'); ?></label>
216
  </p>
217
  <p>
218
- <input type="checkbox" class="checkbox" <?php echo ($instance['ignore_check']['active']) ? 'checked="checked"' : ''; ?> id="<?php echo $this->get_field_id( 'ignore_check' ); ?>" name="<?php echo $this->get_field_name( 'ignore_check' ); ?>" /> <label for="<?php echo $this->get_field_id( 'ignore_check' ); ?>"><?php _e('Display sticky post', 'newpost-catch'); ?></label>
219
  </p>
220
  <p>
221
- <input type="checkbox" class="checkbox" <?php if($instance['css']['active']){ echo 'checked="checked"'; } else { echo ''; } ?> id="<?php echo $this->get_field_id( 'css' ); ?>" name="<?php echo $this->get_field_name( 'css' ); ?>" /> <label for="<?php echo $this->get_field_id( 'css' ); ?>"><?php _e('Use default css', 'newpost-catch'); ?></label>
222
  </p>
223
  <?php _e('Post types' , 'newpost-catch'); ?><br />
224
  <?php
@@ -249,9 +234,6 @@ $thumb_url = $thumb_url[0];
249
  <?php _e('Use shortcode' , 'newpost-catch'); ?>
250
  <?php _e('Can use the shortcode in a textwidget and theme files.' , 'newpost-catch'); ?> <a href="http://wordpress.org/plugins/newpost-catch/faq/" target="_blank">FAQ</a>
251
  </p>
252
- <p>
253
- <span><a href="<?php echo get_site_url() . '/wp-admin/options-general.php?page=Newpost-Catch.php'; ?>"><?php _e('Setting Thumbnails' , 'newpost-catch'); ?></a></span>
254
- </p>
255
  <p>
256
  <?php _e('Contact/Follow' , 'newpost-catch'); ?>
257
  <a href="https://twitter.com/NewpostCatch" target="_blank">Twitter</a>
@@ -262,43 +244,32 @@ $thumb_url = $thumb_url[0];
262
  }
263
  }
264
 
265
- if ( !class_exists('NewpostCatch_SC') ) {
266
  class NewpostCatch_SC {
267
- function __construct(){
268
- add_shortcode('npc', array(&$this, 'npc_sc'));
269
-
270
- function no_thumb_image() {
271
- ob_start();
272
- ob_end_clean();
273
- preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_content(), $matches );
274
- if( isset( $matches[1][0]) ){
275
- $set_img = $matches[1][0];
276
- } else {
277
- $set_img = WP_PLUGIN_URL . '/newpost-catch' . '/no_thumb.png';
278
- }
279
- return $set_img;
280
- }
281
  }
282
-
283
  function npc_sc($atts) {
284
-
285
- /** default value **/
 
286
  extract( shortcode_atts( array(
287
- 'id' => "npcatch",
288
- 'post_type' => "post",
289
  'cat' => NULL,
290
  'width' => 10,
291
  'height' => 10,
292
  'posts_per_page' => 5,
293
  'sticky' => 0,
294
  'offset' => 0,
295
- 'orderby' => "date",
296
- 'order' => "DESC",
297
  'date' => 0,
298
  'dynamic' => 0,
299
  ), $atts ) );
300
 
301
- if( is_array($atts) && array_key_exists('dynamic',$atts) && $atts['dynamic'] == 1 && get_post_type() == "post" && is_single() ){
302
  $cat = get_the_category();
303
  $cat = $cat[0];
304
  $cat = $cat->cat_ID;
@@ -314,7 +285,7 @@ if ( !class_exists('NewpostCatch_SC') ) {
314
  $sticky = 1;
315
  }
316
 
317
- /** query **/
318
  $npc_sc_query = new WP_Query( array(
319
  'post_type' => $post_type,
320
  'cat' => $cat,
@@ -325,30 +296,29 @@ if ( !class_exists('NewpostCatch_SC') ) {
325
  'order' => $order
326
  ));
327
 
328
- $html = "";
329
  if( $npc_sc_query->have_posts() ) :
330
- $html .= "<ul id=\"$id\">\n";
331
  while( $npc_sc_query->have_posts() ) :
332
  $npc_sc_query->the_post();
 
 
 
 
 
 
 
 
 
 
 
333
 
334
- $html .= "<li>";
335
- $html .= "<a href=\"" . esc_html( get_permalink() ) . "\" title=\"" . esc_attr( get_the_title() ) . "\" >\n";
336
- $thumb_url = "";
337
- if( has_post_thumbnail() ) {
338
- $thumb_id = get_post_thumbnail_id();
339
- $thumb_url = wp_get_attachment_image_src($thumb_id);
340
- $thumb_url = $thumb_url[0];
341
- $html .= "<img src=\"" . esc_attr( $thumb_url ) . "\" width=\"" . esc_attr( $width ) . "\" height=\"" . esc_attr( $height ) . "\" alt=\"" . esc_attr( get_the_title() ) . "\" title=\"" . esc_attr( get_the_title() ) . "\" /></a>\n";
342
- } else {
343
- $html .= "<img src=\"" . esc_attr( no_thumb_image() ) . "\" width=\"" . esc_attr( $width ) . "\" height=\"" . esc_attr( $height ) . "\" alt=\"" . esc_attr( get_the_title() ) . "\" title=\"" . esc_attr( get_the_title() ) . "\" /></a>\n";
344
- }
345
- $html .= "<span class=\"title\"><a href=\"" . esc_html( get_permalink() ) . "\" title=\"" . esc_attr( get_the_title() ) . "\" >" . esc_html( get_the_title() );
346
- if ( $date == true ) {
347
- $html .= "<span class=\"date\">" . esc_html( get_the_time( get_option('date_format') ) ) . "</span>\n";
348
- }
349
- $html .= "</a></span></li>\n";
350
  endwhile;
351
- $html .= "</ul>";
352
  endif;
353
  wp_reset_postdata();
354
 
1
  <?php
2
+ //NewpostCatch class
 
 
3
  if ( !class_exists('NewpostCatch') ) {
4
  class NewpostCatch extends WP_Widget {
5
+
6
+ // variables
7
  var $pluginDir = "";
8
 
9
+ // structure
10
+ function __construct() {
11
+ // widget settings
12
  $widget_ops = array( 'description' => 'Thumbnails in new articles.' );
13
 
14
+ // widget actual processes
15
+ parent::__construct(false, $name = 'Newpost Catch', $widget_ops );
 
 
 
 
 
 
16
 
17
+ // plugin path
18
+ if ( empty($this->pluginDir) ) $this->pluginDir = WP_PLUGIN_URL . '/newpost-catch';
19
 
20
+ // default thumbnail
21
+ $this->default_thumbnail = apply_filters('npc_thumb', $this->pluginDir . '/no_thumb.png' );
22
+
23
+ // print stylesheet
24
  add_action( 'get_header', array( &$this, 'enqueue_stylesheet' ) );
25
 
26
+ // activate textdomain for translations
27
  add_action( 'init', array( &$this, 'NewpostCatch_textdomain') );
28
  }
29
 
30
+ // localization
31
  function NewpostCatch_textdomain() {
32
  load_plugin_textdomain ( 'newpost-catch', false, basename( rtrim(dirname(__FILE__), '/') ) . '/languages' );
33
  }
34
 
35
+ // enqueue_stylesheet
36
  function enqueue_stylesheet() {
37
  if( get_option( 'widget_newpostcatch' ) ){
38
  $options = array_filter( get_option( 'widget_newpostcatch' ) );
43
  if( in_array('on' , $options) ){
44
  $css_path = plugins_url('newpost-catch/style.css');
45
  } else {
46
+ $css_path = ( @file_exists( STYLESHEETPATH.'/css/newpost-catch.css' ) ) ? get_stylesheet_directory_uri() . '/css/newpost-catch.css' : '' ;
47
  }
48
 
49
  // register CSS
50
+ wp_register_style( 'newpost-catch', $css_path, array() );
51
  wp_enqueue_style( 'newpost-catch' );
52
  }
53
  }
54
 
55
+ //thumbnail
56
+ function no_thumb_image() {
57
+ ob_start();
58
+ ob_end_clean();
59
+ preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_content(), $matches );
60
 
61
+ if( isset($matches[1][0]) && !is_wp_error($matches[1][0]) ){
62
+ $set_img = $matches[1][0];
 
 
 
 
 
 
 
63
  } else {
64
+ $set_img = $this->default_thumbnail;
65
  }
66
+ return $set_img;
67
+ }
68
+
69
+ // create widget
70
+ function widget($args, $instance) {
71
+ extract( $args );
 
72
 
73
+ $title = apply_filters( 'NewpostCatch_widget_title', $instance['title'] );
74
+ $width = apply_filters( 'NewpostCatch_widget_width', $instance['width'] );
75
+ $height = apply_filters( 'NewpostCatch_widget_height', $instance['height'] );
76
+ $number = apply_filters( 'NewpostCatch_widget_number', $instance['number'] );
77
+ $ignore = apply_filters( 'NewpostCatch_widget_ignore', $instance['ignore_check']['active'] );
78
+ $css = apply_filters( 'NewpostCatch_widget_css', $instance['css'] );
79
+ $cat = apply_filters( 'NewpostCatch_widget_cat', $instance['cat'] );
80
+ if( !empty( $instance['post_type'] ) ){
81
+ $post_type = apply_filters( 'NewpostCatch_widget_post_type', $instance['post_type'] );
82
+ } else {
83
+ $post_type = apply_filters( 'NewpostCatch_widget_post_type', 'post' );
84
  }
85
 
86
  echo $before_widget;
87
 
88
  if ( $title ) echo $before_title . $title . $after_title;
89
+ $sticky = get_option( 'sticky_posts' );
90
+ if( $ignore == !false ){
91
+ $npc_query = new WP_Query( array(
92
+ 'post_type' => $post_type,
93
+ 'cat' => $cat,
94
+ 'posts_per_page' => $number,
95
+ 'ignore_sticky_posts' => 0,
96
+ 'orderby' => 'date',
97
+ 'order' => 'DESC'
98
+ ));
99
+ } else {
100
+ $npc_query = new WP_Query( array(
101
+ 'post_type' => $post_type,
102
+ 'cat' => $cat,
103
+ 'posts_per_page' => $number,
104
+ 'post_not_in' => $sticky,
105
+ 'ignore_sticky_posts' => 1,
106
+ 'orderby' => 'date',
107
+ 'order' => 'DESC'
108
+ ));
109
+ }
110
  ?>
111
+ <ul id="npcatch">
 
 
 
 
 
 
112
  <?php
113
+ if( $npc_query->have_posts() ) :
114
+ while( $npc_query->have_posts() ) : $npc_query->the_post();
115
+ $date = ( $instance['date']['active'] == true ) ? '<span class="date">' . get_the_time( get_option('date_format') ) . '</span>' : '';
116
+
117
+ if( has_post_thumbnail() ) {
118
+ $thumb_id = get_post_thumbnail_id();
119
+ $thumb_url = wp_get_attachment_image_src($thumb_id);
120
+ $thumb_url = $thumb_url[0];
121
+ } else {
122
+ $thumb_url = $this->no_thumb_image();
123
+ }
124
+ ?>
125
+ <li><a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php esc_attr( the_title() ); ?>"><img src="<?php echo esc_url( $thumb_url ); ?>" width="<?php echo esc_attr( $width ); ?>" height="<?php echo esc_attr( $height ); ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"/><span class="title"><?php the_title(); echo $date; ?></span></a></li>
126
+ <?php
127
+ endwhile;
128
+ else :
129
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  <p>no post</p>
131
  <?php endif; wp_reset_postdata(); ?>
132
  </ul>
134
  <?php
135
  echo $after_widget;
136
  }
 
137
 
138
  /** @see WP_Widget::update **/
139
  // updates each widget instance when user clicks the "save" button
165
  /** @see WP_Widget::form **/
166
  function form($instance) {
167
 
168
+ // define default value
169
  $defaults = array(
170
  'title' => __('LatestPost(s)' , 'newpost-catch'),
171
  'width' => 10,
197
  <input style="width:30px;" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($instance['number']); ?>" /> <?php _e('Post(s)', 'newpost-catch'); ?>
198
  </p>
199
  <p>
200
+ <input type="checkbox" class="checkbox" <?php echo ($instance['date']['active']) ? 'checked="checked"' : ''; ?> id="<?php echo $this->get_field_id( 'date' ); ?>" name="<?php echo $this->get_field_name( 'date' ); ?>" /> <label for="<?php echo $this->get_field_id( 'date' ); ?>"><?php _e('Display date', 'newpost-catch'); ?></label>
201
  </p>
202
  <p>
203
+ <input type="checkbox" class="checkbox" <?php echo ($instance['ignore_check']['active']) ? 'checked="checked"' : ''; ?> id="<?php echo $this->get_field_id( 'ignore_check' ); ?>" name="<?php echo $this->get_field_name( 'ignore_check' ); ?>" /> <label for="<?php echo $this->get_field_id( 'ignore_check' ); ?>"><?php _e('Display sticky post', 'newpost-catch'); ?></label>
204
  </p>
205
  <p>
206
+ <input type="checkbox" class="checkbox" <?php if($instance['css']['active']){ echo 'checked="checked"'; } else { echo ''; } ?> id="<?php echo $this->get_field_id( 'css' ); ?>" name="<?php echo $this->get_field_name( 'css' ); ?>" /> <label for="<?php echo $this->get_field_id( 'css' ); ?>"><?php _e('Use default css', 'newpost-catch'); ?></label>
207
  </p>
208
  <?php _e('Post types' , 'newpost-catch'); ?><br />
209
  <?php
234
  <?php _e('Use shortcode' , 'newpost-catch'); ?>
235
  <?php _e('Can use the shortcode in a textwidget and theme files.' , 'newpost-catch'); ?> <a href="http://wordpress.org/plugins/newpost-catch/faq/" target="_blank">FAQ</a>
236
  </p>
 
 
 
237
  <p>
238
  <?php _e('Contact/Follow' , 'newpost-catch'); ?>
239
  <a href="https://twitter.com/NewpostCatch" target="_blank">Twitter</a>
244
  }
245
  }
246
 
247
+ if ( !class_exists( 'NewpostCatch_SC' ) ) {
248
  class NewpostCatch_SC {
249
+ function __construct() {
250
+ add_shortcode( 'npc', array( &$this, 'npc_sc' ) );
 
 
 
 
 
 
 
 
 
 
 
 
251
  }
252
+
253
  function npc_sc($atts) {
254
+ $npc_construct = new NewpostCatch();
255
+
256
+ // default value
257
  extract( shortcode_atts( array(
258
+ 'id' => 'npcatch',
259
+ 'post_type' => 'post',
260
  'cat' => NULL,
261
  'width' => 10,
262
  'height' => 10,
263
  'posts_per_page' => 5,
264
  'sticky' => 0,
265
  'offset' => 0,
266
+ 'orderby' => 'date',
267
+ 'order' => 'DESC',
268
  'date' => 0,
269
  'dynamic' => 0,
270
  ), $atts ) );
271
 
272
+ if( is_array($atts) && array_key_exists('dynamic',$atts) && $atts['dynamic'] == 1 && get_post_type() == 'post' && is_single() ){
273
  $cat = get_the_category();
274
  $cat = $cat[0];
275
  $cat = $cat->cat_ID;
285
  $sticky = 1;
286
  }
287
 
288
+ // query
289
  $npc_sc_query = new WP_Query( array(
290
  'post_type' => $post_type,
291
  'cat' => $cat,
296
  'order' => $order
297
  ));
298
 
299
+ $html = '';
300
  if( $npc_sc_query->have_posts() ) :
301
+ $html .= '<ul id="' . $id . '">';
302
  while( $npc_sc_query->have_posts() ) :
303
  $npc_sc_query->the_post();
304
+
305
+ $get_date = ( $date == true ) ? '<span class="date">' . esc_html( get_the_time( get_option('date_format') ) ) . '</span>' : '';
306
+
307
+ $thumb_url = '';
308
+ if( has_post_thumbnail() ) {
309
+ $thumb_id = get_post_thumbnail_id();
310
+ $thumb_url = wp_get_attachment_image_src($thumb_id);
311
+ $thumb_url = $thumb_url[0];
312
+ } else {
313
+ $thumb_url = $npc_construct->default_thumbnail;
314
+ }
315
 
316
+ $html .= '<li><a href="' . esc_url( get_permalink() ) . '" title="' . get_the_title() . '">';
317
+ $html .= '<img src="' . esc_url( $thumb_url ) . '" width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '" alt="' . get_the_title() . '" title="' . get_the_title() . '" /></a>';
318
+ $html .= '<span class="title"><a href="' . esc_url( get_permalink() ) . '" title="' . get_the_title() . '">' . get_the_title() . $get_date;
319
+ $html .= '</a></span></li>';
 
 
 
 
 
 
 
 
 
 
 
 
320
  endwhile;
321
+ $html .= '</ul>';
322
  endif;
323
  wp_reset_postdata();
324
 
newpost-catch.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Newpost Catch
4
  Plugin URI: http://www.imamura.biz/blog/newpost-catch/
5
  Description: Thumbnails in new articles setting widget.
6
- Version: 1.2.7
7
  Author: Tetsuya Imamura
8
  Text Domain: newpost-catch
9
  Author URI: http://www.imamura.biz/blog/
@@ -14,24 +14,11 @@ License: GPL2
14
  include "class.php";
15
 
16
  //Hook
17
- add_action('widgets_init', create_function('', 'return register_widget("NewpostCatch");'));
18
 
19
  //Instance
20
  new NewpostCatch_SC();
21
 
22
- //Hook npc_filter
23
- add_action( 'admin_menu', 'npc_plugin_menu' );
24
-
25
- //Add Admin Menu
26
- function npc_plugin_menu() {
27
- add_options_page( 'Newpost-Catch', 'Newpost Catch', 'manage_options', "Newpost-Catch.php" , 'npc_options_page' );
28
- }
29
-
30
- //Define Option Page
31
- function npc_options_page() {
32
- require('npc_admin.php');
33
- }
34
-
35
  /* Copyright 2012-2015 Tetsuya Imamura (@s56bouya)
36
 
37
  This program is free software; you can redistribute it and/or modify
3
  Plugin Name: Newpost Catch
4
  Plugin URI: http://www.imamura.biz/blog/newpost-catch/
5
  Description: Thumbnails in new articles setting widget.
6
+ Version: 1.3.1
7
  Author: Tetsuya Imamura
8
  Text Domain: newpost-catch
9
  Author URI: http://www.imamura.biz/blog/
14
  include "class.php";
15
 
16
  //Hook
17
+ add_action( 'widgets_init', function(){ register_widget( 'NewpostCatch' ); });
18
 
19
  //Instance
20
  new NewpostCatch_SC();
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  /* Copyright 2012-2015 Tetsuya Imamura (@s56bouya)
23
 
24
  This program is free software; you can redistribute it and/or modify
npc_admin.php DELETED
@@ -1,152 +0,0 @@
1
- <?php
2
- //Init
3
- if( isset($_POST['number']) && preg_match("/^[0-9]+$/", $_POST['number']) ){
4
- $number = $_POST['number'];
5
- } else {
6
- $number = 5;
7
- }
8
- if( isset($set_array) ){
9
- $set_array = array();
10
- }
11
-
12
- //Send to Submit Button
13
- if ( !empty($_POST) && isset( $_POST['npc_submit'] ) ) {
14
- //Check Adminn Referer
15
- check_admin_referer("npc_options" , "npc_submit_wpnonce" );
16
-
17
- //Get Option
18
- $set_array = get_option('npc_search_posts');
19
-
20
- //Generate Thumbnails
21
- foreach( $set_array as $set ){
22
- //Up Dir
23
- $upload_dir = wp_upload_dir();
24
- $image_data = file_get_contents($set['img_url']);
25
- $filename = basename($set['img_url']);
26
- if(wp_mkdir_p($upload_dir['path']))
27
- $file = $upload_dir['path'] . '/' . $filename;
28
- else
29
- $file = $upload_dir['basedir'] . '/' . $filename;
30
-
31
- file_put_contents($file, $image_data);
32
-
33
- $wp_filetype = wp_check_filetype($filename, null );
34
- $attachment = array(
35
- 'post_mime_type' => $wp_filetype['type'],
36
- 'post_title' => sanitize_file_name($filename),
37
- 'post_content' => '',
38
- 'post_status' => 'inherit'
39
- );
40
- $attach_id = wp_insert_attachment( $attachment, $file, $set['ID'] );
41
- require_once(ABSPATH . 'wp-admin/includes/image.php');
42
- $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
43
- wp_update_attachment_metadata( $attach_id, $attach_data );
44
-
45
- //Set Thumbnail
46
- set_post_thumbnail( $set['ID'], $attach_id );
47
- delete_option('npc_search_posts');
48
- }
49
- //Display Messages
50
- echo "<div class=\"updated\"><p><strong>" . __('completed.','newpost-catch') . "</strong></p></div>";
51
- }
52
- ?>
53
-
54
- <form name="form1" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
55
- <?php wp_nonce_field( "npc_options" , "npc_submit_wpnonce" ); ?>
56
- <div class="wrap">
57
- <h2>Newpost Catch <?php _e('Setting Thumbnails','newpost-catch'); ?></h2>
58
- <h3><?php _e('Eyecatch image batch setting','newpost-catch'); ?></h3>
59
- <h4><?php _e('I can set the eyecatch image, [the first image] found in the body of the post. (※ image does not exist, invalid image of (dead link) can not be set the URL.','newpost-catch'); ?></h4>
60
- <div class="postbox">
61
- <div class="inside">
62
- <strong><?php _e('Search the post.','newpost-catch'); ?></strong>
63
- <p><?php _e('LatestPost(s)','newpost-catch'); ?> <input type="text" name="number" value="<?php echo intval($number); ?>" size="4"> <?php _e('Post(s)','newpost-catch'); ?> <input type="submit" class="button" name="search_posts" value="<?php _e('Search','newpost-catch'); ?>" /></p>
64
- </div>
65
- </div>
66
- <?php
67
- if ( !empty($_POST) && isset( $_POST['search_posts'] ) ) {
68
- //Check Adminn Referer
69
- check_admin_referer("npc_options" , "npc_submit_wpnonce" );
70
-
71
- global $wpdb;
72
- $data = $wpdb->get_results("SELECT ID,post_title,post_content FROM {$wpdb->posts} p where p.post_status = 'publish' AND p.post_content REGEXP '<img[^>]+src=\"([^\">]+)\"' AND p.post_type IN('post') AND p.ID NOT IN ( SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ('_thumbnail_id')) ORDER BY p.ID DESC LIMIT $number");
73
-
74
- // var_dump($data);
75
-
76
- if( $data ){
77
- $set_array = array();
78
- $set_count = 1;
79
- ?>
80
- <hr />
81
- <h3><?php _e('Search Result','newpost-catch'); ?></h3>
82
- <h4><?php _e('Can be edited post in the [Edit] button. Please confirm the image displayed in the text and, whether or not broken links.','newpost-catch'); ?></h4>
83
- <table class="wp-list-table widefat fixed">
84
- <thead>
85
- <tr>
86
- <th width="10%"><?php _e('Edit','newpost-catch'); ?></th>
87
- <th width="30%"><?php _e('Title','newpost-catch'); ?></th>
88
- <th width="30%"><?php _e('Image','newpost-catch'); ?></th>
89
- <th width="30%"><?php _e('Image URL','newpost-catch'); ?></th>
90
- </tr>
91
- </thead>
92
- <tbody id="the-list">
93
- <?php foreach( $data as $result ){ ?>
94
- <tr <?php if( $set_count % 2 == 1 ){ echo 'class="alternate"'; } ?>>
95
- <?php
96
- $set_img = "";
97
- preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $result->post_content, $matches );
98
- if( isset($matches[1][0]) && !is_wp_error($matches[1][0]) ){
99
- $file_check = @get_headers($matches[1][0]);
100
- if( preg_match('#^HTTP/.*\s+[200|302]+\s#i', $file_check[0]) ) {
101
- $set_img = $matches[1][0];
102
- $set_array[] = array('ID'=>$result->ID,'img_url'=>$matches[1][0]);
103
- }
104
- } else {
105
- $set_img = WP_PLUGIN_URL . '/newpost-catch' . '/no_thumb.png';
106
- }
107
- echo "<td><a class=\"button\" href=\"" . get_edit_post_link($result->ID) . "\">" . __('Edit','newpost-catch') . "</a></td>";
108
- echo "<td>" . $result->post_title . "</td>";
109
- echo "<td>";
110
- if( $set_img != "" ){
111
- echo "<img src=\"" . $set_img . "\" width=\"" . 80 . "\" >";
112
- }
113
- echo "</td>";
114
- echo "<td>" . $set_img . "</td>";
115
- ?>
116
- </tr>
117
- <?php
118
- $set_count++;
119
- }
120
- ?>
121
- </tbody>
122
- <tfoot>
123
- <tr>
124
- <th width="10%"><?php _e('Edit','newpost-catch'); ?></th>
125
- <th width="30%"><?php _e('Title','newpost-catch'); ?></th>
126
- <th width="30%"><?php _e('Image','newpost-catch'); ?></th>
127
- <th width="30%"><?php _e('Image URL','newpost-catch'); ?></th>
128
- </tr>
129
- </tfoot>
130
- </tbody>
131
- </table>
132
- <?php if( count($set_array) > 0 ){ ?>
133
- <h3><span style="color:#4AA21A; font-weight:bold; font-size:16px;"><?php echo count($set_array); ?></span> <?php _e('Image(s) found.','newpost-catch'); ?></h3>
134
- <h4><?php _e('Setting start in the [Generate] button','newpost-catch'); ?></h4>
135
- <p class="submit"><input type="submit" class="button-primary" name="npc_submit" value="<?php echo _e('Generate','newpost-catch'); ?>" /></p>
136
- <?php } else { ?>
137
- <h3><?php _e('Not found.','newpost-catch'); ?></h3>
138
- <?php } ?>
139
- <hr />
140
- <h3><?php _e('Thumbnail','newpost-catch'); ?></h3>
141
- <p><?php _e('Width'); ?><?php echo get_option('thumbnail_size_w'); ?>px</p>
142
- <p><?php _e('Height'); ?><?php echo get_option('thumbnail_size_h'); ?>px</p>
143
- <p><?php if( get_option('thumbnail_crop') == 1 ) { _e('Crop thumbnail to exact dimensions (normally thumbnails are proportional)'); } ?></p>
144
- <p><?php _e('Configuration','newpost-catch'); ?> <a href="<?php echo get_bloginfo('url') . '/wp-admin/options-media.php'; ?>"><?php _e('Media Settings','newpost-catch'); ?></a></p>
145
- <?php
146
- //var_dump($set_array);
147
- update_option('npc_search_posts', $set_array);
148
- }
149
- }
150
- ?>
151
- </form>
152
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: s56bouya
3
  Donate link: http://www.imamura.biz/blog/newpost-catch
4
  Tags: widget, plugin, posts, sidebar, image, images, thumb, thumbnail
5
  Requires at least: 3.3.1
6
- Tested up to: 4.1
7
- Stable tag: 1.2.7
8
 
9
  Thumbnails in new articles setting widget.
10
 
@@ -14,7 +14,7 @@ Thumbnails in new articles setting widget.
14
 
15
  == Installation ==
16
 
17
- ### **Required PHP5.**
18
 
19
  1. Unzip "Newpost Catch" archive.
20
  2. Upload folder 'newpost-catch' to the `/wp-content/plugins/` directory
@@ -93,6 +93,21 @@ When the post other than, post_type of the current page is the value of the prio
93
 
94
  == Changelog ==
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  = 1.2.7 =
97
  * The css reading order adjustment.
98
 
3
  Donate link: http://www.imamura.biz/blog/newpost-catch
4
  Tags: widget, plugin, posts, sidebar, image, images, thumb, thumbnail
5
  Requires at least: 3.3.1
6
+ Tested up to: 4.5
7
+ Stable tag: 1.3.1
8
 
9
  Thumbnails in new articles setting widget.
10
 
14
 
15
  == Installation ==
16
 
17
+ ### **Required PHP5.3+**
18
 
19
  1. Unzip "Newpost Catch" archive.
20
  2. Upload folder 'newpost-catch' to the `/wp-content/plugins/` directory
93
 
94
  == Changelog ==
95
 
96
+ = 1.3.1 =
97
+ * Required PHP5.3+(changed widgets_init hook).
98
+ * Abolished option page.
99
+ * Compatibility check with WP 4.5.
100
+
101
+ = 1.3.0 =
102
+ * Compatibility check with WP 4.4.2.
103
+
104
+ = 1.2.9 =
105
+ * Removed the same name method.
106
+ * Apply filters default thumbnail.
107
+
108
+ = 1.2.8 =
109
+ * The constructor method was corrected.
110
+
111
  = 1.2.7 =
112
  * The css reading order adjustment.
113