WordPress Popular Posts - Version 3.0.3

Version Description

  • Fixes widget not saving 'freshness' setting.
  • Adds HTMLentities conversion/deconversion on wpp_get_mostpopular().
  • Improves thumbnail detection.
  • Fixes a bug affecting the truncation of excerpts.
  • Fixes yet another bug on wpp_get_views().
  • Other minor changes.
Download this release

Release Info

Developer hcabrera
Plugin Icon 128x128 WordPress Popular Posts
Version 3.0.3
Comparing to
See all releases

Code changes from version 3.0.2 to 3.0.3

Files changed (3) hide show
  1. readme.txt +17 -3
  2. views/admin.php +6 -3
  3. wordpress-popular-posts.php +58 -56
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hcabr
4
  Tags: popular, posts, widget, popularity, top
5
  Requires at least: 3.8
6
  Tested up to: 3.9.1
7
- Stable tag: 3.0.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -31,6 +31,11 @@ Wordpress Popular Posts is a highly customizable widget that displays the most p
31
  * **Localizable** to your own language (*See the [FAQ section](http://wordpress.org/extend/plugins/wordpress-popular-posts/faq/) for more info*).
32
  * **[WP-PostRatings](http://wordpress.org/extend/plugins/wp-postratings/) support**. Show your visitors how your readers are rating your posts!
33
 
 
 
 
 
 
34
  == Installation ==
35
 
36
  1. Download the plugin and extract its contents.
@@ -63,7 +68,7 @@ The idea of creating this plugin came from the need to know how many people were
63
  Since Wordpress doesn't store views count (only comments count), this plugin stores that info for you. When you sort your popular posts by *views*, Wordpress Popular Posts will retrieve the views count it started caching from the time you first installed this plugin, and then rank the top posts according to the settings you have configured in the plugin. Wordpress Popular Posts can also rank the popularity of your posts based on comments count as well.
64
 
65
  = I'm getting "Sorry. No data so far". What's up with that? =
66
- There are a number of reasons that might explain why you are seeing this message: no one has seen or commented on your posts/pages since Wordpress Popular Posts activation, you should give it some time; your current theme does not have the [wp_head()](http://codex.wordpress.org/Theme_Development#Plugin_API_Hooks) tag in its <head> section, required by my plugin to keep track of what your visitors are viewing on your site; Wordpress Popular Posts was unable to create the necessary DB tables to work, make sure your hosting has granted you permission to create / update / modify tables in the database.
67
 
68
  = My current theme does not support widgets (booooo!). Can I show my most popular posts in any other way? =
69
  Yes, there are other choices: you can use the [wpp shortcode](https://github.com/cabrerahector/wordpress-popular-posts/wiki/1.-Using-WPP-on-posts-&-pages), which allows you to embed your popular listing directly in the content of your posts and/or pages; or you can use the [wpp_get_mostpopular() template tag](https://github.com/cabrerahector/wordpress-popular-posts/wiki/2.-Template-tags#wpp_get_mostpopular). Both options are highly customizable via parameters, check them out via *wp-admin > Settings > Wordpress Popular Posts > Parameters*.
@@ -145,6 +150,14 @@ For the time being, the [Support Forum](http://wordpress.org/support/plugin/word
145
  4. Wordpress Popular Posts Stats panel.
146
 
147
  == Changelog ==
 
 
 
 
 
 
 
 
148
  = 3.0.2 =
149
  * Fixes an introduced bug on wpp_get_views().
150
  * Fixes bug where thumbnail size was cached for multiple instances.
@@ -158,6 +171,7 @@ For the time being, the [Support Forum](http://wordpress.org/support/plugin/word
158
  * Fixes bug that prevented disabling plugin's stylesheet.
159
 
160
  = 3.0.0 =
 
161
  * Plugin refactoring based on [@tikaszvince](https://github.com/tikaszvince)'s work (many thanks, Vince!).
162
  * Added WPML support.
163
  * Added experimental Wordpress Multisite support.
@@ -373,5 +387,5 @@ All translations are community made: people who are nice enough to share their t
373
 
374
  == Upgrade Notice ==
375
 
376
- = 3.0.2 =
377
  This version requires PHP 5.2+ and Wordpress 3.8 or greater. Also, backup the wpp.css file first if you modified it!
4
  Tags: popular, posts, widget, popularity, top
5
  Requires at least: 3.8
6
  Tested up to: 3.9.1
7
+ Stable tag: 3.0.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
31
  * **Localizable** to your own language (*See the [FAQ section](http://wordpress.org/extend/plugins/wordpress-popular-posts/faq/) for more info*).
32
  * **[WP-PostRatings](http://wordpress.org/extend/plugins/wp-postratings/) support**. Show your visitors how your readers are rating your posts!
33
 
34
+ = Notices =
35
+ * Starting version 3.0.0, the way plugin tracks views count switched back to [AJAX](http://codex.wordpress.org/AJAX). The reason for this change is to prevent bots / spiders from inflating views count, so if you're using a caching plugin you should clear its cache after installing / upgrading the Wordpress Popular Posts plugin so it can track your posts and pages normally.
36
+
37
+ **Wordpress Popular Posts** is now also on [GitHub](https://github.com/cabrerahector/wordpress-popular-posts)!
38
+
39
  == Installation ==
40
 
41
  1. Download the plugin and extract its contents.
68
  Since Wordpress doesn't store views count (only comments count), this plugin stores that info for you. When you sort your popular posts by *views*, Wordpress Popular Posts will retrieve the views count it started caching from the time you first installed this plugin, and then rank the top posts according to the settings you have configured in the plugin. Wordpress Popular Posts can also rank the popularity of your posts based on comments count as well.
69
 
70
  = I'm getting "Sorry. No data so far". What's up with that? =
71
+ There are a number of reasons that might explain why you are seeing this message: no one has seen or commented on your posts/pages since Wordpress Popular Posts activation, you should give it some time; your current theme does not have the [wp_head()](http://codex.wordpress.org/Theme_Development#Plugin_API_Hooks) tag in its <head> section, required by my plugin to keep track of what your visitors are viewing on your site; Wordpress Popular Posts was unable to create the necessary DB tables to work, make sure your hosting has granted you permission to create / update / modify tables in the database; if you're using a caching plugin -such as W3 Total Cache- you need to clear its cache once right after installing/upgrading this plugin.
72
 
73
  = My current theme does not support widgets (booooo!). Can I show my most popular posts in any other way? =
74
  Yes, there are other choices: you can use the [wpp shortcode](https://github.com/cabrerahector/wordpress-popular-posts/wiki/1.-Using-WPP-on-posts-&-pages), which allows you to embed your popular listing directly in the content of your posts and/or pages; or you can use the [wpp_get_mostpopular() template tag](https://github.com/cabrerahector/wordpress-popular-posts/wiki/2.-Template-tags#wpp_get_mostpopular). Both options are highly customizable via parameters, check them out via *wp-admin > Settings > Wordpress Popular Posts > Parameters*.
150
  4. Wordpress Popular Posts Stats panel.
151
 
152
  == Changelog ==
153
+ = 3.0.3 =
154
+ * Fixes widget not saving 'freshness' setting.
155
+ * Adds HTMLentities conversion/deconversion on wpp_get_mostpopular().
156
+ * Improves thumbnail detection.
157
+ * Fixes a bug affecting the truncation of excerpts.
158
+ * Fixes yet another bug on wpp_get_views().
159
+ * Other minor changes.
160
+
161
  = 3.0.2 =
162
  * Fixes an introduced bug on wpp_get_views().
163
  * Fixes bug where thumbnail size was cached for multiple instances.
171
  * Fixes bug that prevented disabling plugin's stylesheet.
172
 
173
  = 3.0.0 =
174
+ * Starting from this version, the way plugin tracks views count switched back to [AJAX](http://codex.wordpress.org/AJAX) to prevent bots / spiders from inflating views count. If you're using a caching plugin you should clear its cache after installing / upgrading the Wordpress Popular Posts plugin so it can track your posts and pages normally.
175
  * Plugin refactoring based on [@tikaszvince](https://github.com/tikaszvince)'s work (many thanks, Vince!).
176
  * Added WPML support.
177
  * Added experimental Wordpress Multisite support.
387
 
388
  == Upgrade Notice ==
389
 
390
+ = 3.0.3 =
391
  This version requires PHP 5.2+ and Wordpress 3.8 or greater. Also, backup the wpp.css file first if you modified it!
views/admin.php CHANGED
@@ -696,9 +696,12 @@ if (empty($wpp_rand)) {
696
  <h3><?php echo sprintf( __('About Wordpress Popular Posts %s', $this->plugin_slug), $this->version); ?></h3>
697
  <p><?php _e( 'This version includes the following changes', $this->plugin_slug ); ?>:</p>
698
  <ul>
699
- <li>Fixes bug on wpp_get_views.</li>
700
- <li>Sustitutes WP_DEBUG with custom debugging constant.</li>
701
- <li>Fixes bug that prevented disabling plugin's stylesheet.</li>
 
 
 
702
  </ul>
703
  </div>
704
 
696
  <h3><?php echo sprintf( __('About Wordpress Popular Posts %s', $this->plugin_slug), $this->version); ?></h3>
697
  <p><?php _e( 'This version includes the following changes', $this->plugin_slug ); ?>:</p>
698
  <ul>
699
+ <li>Fixes widget not saving 'freshness' setting.</li>
700
+ <li>Adds HTMLentities conversion/deconversion on wpp_get_mostpopular().</li>
701
+ <li>Improves thumbnail detection.</li>
702
+ <li>Fixes a bug affecting the truncation of excerpts.</li>
703
+ <li>Fixes yet another bug on wpp_get_views().</li>
704
+ <li>Other minor changes.</li>
705
  </ul>
706
  </div>
707
 
wordpress-popular-posts.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Wordpress Popular Posts
4
  Plugin URI: http://wordpress.org/extend/plugins/wordpress-popular-posts
5
  Description: Wordpress Popular Posts is a highly customizable widget that displays the most popular posts on your blog
6
- Version: 3.0.2
7
  Author: Hector Cabrera
8
  Author URI: http://cabrerahector.com
9
  Author Email: hcabrerab@gmail.com
@@ -61,7 +61,7 @@ if ( !class_exists('WordpressPopularPosts') ) {
61
  * @since 1.3.0
62
  * @var string
63
  */
64
- private $version = '3.0.2';
65
 
66
  /**
67
  * Plugin identifier.
@@ -456,6 +456,8 @@ if ( !class_exists('WordpressPopularPosts') ) {
456
  ? 'post,page'
457
  : $new_instance['post_type'];
458
 
 
 
459
  $instance['pid'] = implode(",", array_filter(explode(",", preg_replace( '|[^0-9,]|', '', $new_instance['pid'] ))));
460
  $instance['cat'] = implode(",", array_filter(explode(",", preg_replace( '|[^0-9,-]|', '', $new_instance['cat'] ))));
461
  $instance['author'] = implode(",", array_filter(explode(",", preg_replace( '|[^0-9,]|', '', $new_instance['uid'] ))));
@@ -646,7 +648,7 @@ if ( !class_exists('WordpressPopularPosts') ) {
646
  * @since 1.0.0
647
  */
648
  public function register_widget_styles() {
649
-
650
  $theme_file = get_stylesheet_directory() . '/wpp.css';
651
  $plugin_file = plugin_dir_path(__FILE__) . 'style/wpp.css';
652
 
@@ -655,7 +657,7 @@ if ( !class_exists('WordpressPopularPosts') ) {
655
  } elseif ( @file_exists($plugin_file) ) { // no custom wpp.css, use plugin's instead
656
  wp_enqueue_style( $this->plugin_slug, plugins_url( 'style/wpp.css', __FILE__ ), array(), $this->version );
657
  }
658
-
659
  } // end register_widget_styles
660
 
661
  /**
@@ -1250,7 +1252,7 @@ if ( !class_exists('WordpressPopularPosts') ) {
1250
 
1251
  if ( !$result1 || !$result2 )
1252
  return false;
1253
-
1254
  // Allow WP themers / coders perform an action
1255
  // after updating views count
1256
  if ( has_action( 'wpp_update_views' ) )
@@ -1714,13 +1716,13 @@ if ( !class_exists('WordpressPopularPosts') ) {
1714
  }
1715
  // build regular layout
1716
  else {
1717
- $content =
1718
- '<li>'
1719
- . $thumb
1720
- . '<a href="' . $permalink . '" title="' . esc_attr($title) . '" class="wpp-post-title" target="' . $this->user_settings['tools']['link']['target'] . '">' . $title_sub . '</a> '
1721
- . $excerpt . ' <span class="post-stats">' . $_stats . '</span> '
1722
- . $rating
1723
- . "</li>\n";
1724
  }
1725
 
1726
  return apply_filters('wpp_post', $content, $p, $instance);
@@ -2161,7 +2163,7 @@ if ( !class_exists('WordpressPopularPosts') ) {
2161
 
2162
  // Get image by post ID (parent)
2163
  if ( $id ) {
2164
- $file_paths = $this->__get_image_file_paths($id, $source);
2165
  $file_path = $file_paths['file_path'];
2166
  $thumbnail = isset( $file_paths['thumbnail'] )
2167
  ? $file_paths['thumbnail']
@@ -2183,7 +2185,7 @@ if ( !class_exists('WordpressPopularPosts') ) {
2183
  $attachment_id = $this->__get_attachment_id($image_url);
2184
 
2185
  // Image is hosted locally
2186
- if ( $attachment_id ) {
2187
  $thumbnail = $image_url;
2188
  $file_path = get_attached_file($attachment_id);
2189
  }
@@ -2205,7 +2207,7 @@ if ( !class_exists('WordpressPopularPosts') ) {
2205
 
2206
  // there is a thumbnail already
2207
  if (file_exists($cropped_thumb)) {
2208
- $new_img = str_replace(basename($thumbnail), basename($cropped_thumb), $thumbnail);
2209
  return $this->_render_image($new_img, $dim, 'wpp-thumbnail wpp_cached_thumb wpp_' . $source, $title);
2210
  }
2211
 
@@ -2223,9 +2225,9 @@ if ( !class_exists('WordpressPopularPosts') ) {
2223
  * @return string
2224
  */
2225
  private function __image_resize($path, $thumbnail, $dimension, $source) {
2226
-
2227
  $image = wp_get_image_editor($path);
2228
-
2229
  // valid image, create thumbnail
2230
  if (!is_wp_error($image)) {
2231
 
@@ -2235,9 +2237,9 @@ if ( !class_exists('WordpressPopularPosts') ) {
2235
  if (is_wp_error($new_img)) {
2236
  return $this->_render_image($this->default_thumbnail, $dimension, 'wpp-thumbnail wpp_imgeditor_error wpp_' . $source, '', $image->get_error_message());
2237
  }
2238
-
2239
  $new_img = str_replace(basename($thumbnail), $new_img['file'], $thumbnail);
2240
-
2241
  return $this->_render_image($new_img, $dimension, 'wpp-thumbnail wpp_imgeditor_thumb wpp_' . $source, '');
2242
  }
2243
 
@@ -2296,11 +2298,8 @@ if ( !class_exists('WordpressPopularPosts') ) {
2296
  $attachment_id = $this->__get_attachment_id($content_images[1][0]);
2297
 
2298
  // image from Media Library
2299
- if ($attachment_id) {
2300
  $thumbnail = $content_images[1][0];
2301
- // If it's a resized image, get the original name
2302
- $thumbnail = preg_replace( '/-[0-9]{1,4}x[0-9]{1,4}\.(jpg|jpeg|png|gif|bmp)$/i', '.$1', $thumbnail );
2303
-
2304
  $file_path = get_attached_file($attachment_id);
2305
  } // external image?
2306
  else {
@@ -2355,28 +2354,29 @@ if ( !class_exists('WordpressPopularPosts') ) {
2355
  * @return bool|int
2356
  */
2357
  private function __get_attachment_id($url) {
2358
-
2359
  // Split the $url into two parts with the wp-content directory as the separator.
2360
  $parse_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
2361
-
2362
  // Get the host of the current site and the host of the $url, ignoring www.
2363
  $this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
2364
  $file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
2365
-
2366
  // Return nothing if there aren't any $url parts or if the current host and $url host do not match.
2367
  if ( ! isset( $parse_url[1] ) || empty( $parse_url[1] ) || ( $this_host != $file_host ) ) {
2368
  return false;
2369
  }
2370
-
2371
  // Now we're going to quickly search the DB for any attachment GUID with a partial path match.
2372
  // Example: /uploads/2013/05/test-image.jpg
2373
  global $wpdb;
2374
-
2375
- // If it's a resized image, get the original name
2376
- $parse_url[1] = preg_replace( '/-[0-9]{1,4}x[0-9]{1,4}\.(jpg|jpeg|png|gif|bmp)$/i', '.$1', $parse_url[1] );
2377
-
2378
- $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;", $parse_url[1] ) );
2379
-
 
2380
  // Returns null if no attachment is found.
2381
  return $attachment[0];
2382
 
@@ -2396,7 +2396,7 @@ if ( !class_exists('WordpressPopularPosts') ) {
2396
  $uploads = wp_upload_dir();
2397
  $image['thumbnail'] = trailingslashit( $uploads['baseurl'] ) . "{$id}_". sanitize_file_name( rawurldecode(wp_basename( $url )) );
2398
  $image['file_path'] = trailingslashit( $uploads['basedir'] ) . "{$id}_". sanitize_file_name( rawurldecode(wp_basename( $url )) );
2399
-
2400
  // if the file exists already, return URL and path
2401
  if ( file_exists($image['file_path']) )
2402
  return $image;
@@ -2476,8 +2476,17 @@ if ( !class_exists('WordpressPopularPosts') ) {
2476
  // remove Iframes
2477
  $excerpt = preg_replace( "/<iframe.*?\/iframe>/i", "", $excerpt);
2478
 
2479
- // remove URLs
2480
- $excerpt = preg_replace( '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS', '', $excerpt );
 
 
 
 
 
 
 
 
 
2481
 
2482
  // Fix RSS CDATA tags
2483
  $excerpt = str_replace( ']]>', ']]&gt;', $excerpt );
@@ -2491,10 +2500,8 @@ if ( !class_exists('WordpressPopularPosts') ) {
2491
  $words = explode(" ", $excerpt, $instance['post-excerpt']['length'] + 1);
2492
 
2493
  if ( count($words) > $instance['post-excerpt']['length'] ) {
2494
-
2495
  array_pop($words);
2496
  $excerpt = implode(" ", $words) . "...";
2497
-
2498
  }
2499
 
2500
  } else { // by characters
@@ -2505,16 +2512,11 @@ if ( !class_exists('WordpressPopularPosts') ) {
2505
 
2506
  }
2507
 
2508
- // remove HTML tags if requested
2509
- if ( $instance['post-excerpt']['keep_format'] ) {
2510
- $excerpt = force_balance_tags(strip_tags($excerpt, '<a><b><i><em><strong>'));
2511
- } else {
2512
- $excerpt = strip_tags($excerpt);
2513
- }
2514
-
2515
- // remove WP shortcodes
2516
- $excerpt = strip_shortcodes( $excerpt );
2517
 
 
 
 
2518
  }
2519
 
2520
  return $excerpt;
@@ -2629,12 +2631,12 @@ if ( !class_exists('WordpressPopularPosts') ) {
2629
  'category' => empty($stats_category) ? false : $stats_category,
2630
  ),
2631
  'markup' => array(
2632
- 'custom_html' => true,
2633
- 'wpp-start' => empty($wpp_start) ? '<ul class="wpp-list">' : $wpp_start,
2634
- 'wpp-end' => empty($wpp_end) ? '</ul>' : $wpp_end,
2635
- 'title-start' => empty($header_start) ? '' : $header_start,
2636
- 'title-end' => empty($header_end) ? '' : $header_end,
2637
- 'post-html' => empty($post_html) ? '<li>{thumb} {title} {stats}</li>' : $post_html
2638
  )
2639
  );
2640
 
@@ -2642,7 +2644,7 @@ if ( !class_exists('WordpressPopularPosts') ) {
2642
 
2643
  // is there a title defined by user?
2644
  if (!empty($header) && !empty($header_start) && !empty($header_end)) {
2645
- $shortcode_content .= $header_start . apply_filters('widget_title', $header) . $header_end;
2646
  }
2647
 
2648
  // print popular posts list
@@ -2965,7 +2967,7 @@ function wpp_get_views($id = NULL, $range = NULL, $number_format = true) {
2965
 
2966
  $now = current_time('mysql');
2967
 
2968
- $query = "SELECT SUM(views) FROM {$table_name}summary WHERE postid = '{$id}' AND last_viewed > DATE_SUB('{$now}', INTERVAL {$interval}) LIMIT 1;";
2969
  }
2970
 
2971
  $result = $wpdb->get_var($query);
@@ -2995,7 +2997,7 @@ function wpp_get_mostpopular($args = NULL) {
2995
  if( is_array( $args ) ){
2996
  $atts = '';
2997
  foreach( $args as $key => $arg ){
2998
- $atts .= ' ' . $key . '="' . $arg . '"';
2999
  }
3000
  } else {
3001
  $atts = trim( str_replace( "&", " ", $args ) );
3
  Plugin Name: Wordpress Popular Posts
4
  Plugin URI: http://wordpress.org/extend/plugins/wordpress-popular-posts
5
  Description: Wordpress Popular Posts is a highly customizable widget that displays the most popular posts on your blog
6
+ Version: 3.0.3
7
  Author: Hector Cabrera
8
  Author URI: http://cabrerahector.com
9
  Author Email: hcabrerab@gmail.com
61
  * @since 1.3.0
62
  * @var string
63
  */
64
+ private $version = '3.0.3';
65
 
66
  /**
67
  * Plugin identifier.
456
  ? 'post,page'
457
  : $new_instance['post_type'];
458
 
459
+ $instance['freshness'] = $new_instance['freshness'];
460
+
461
  $instance['pid'] = implode(",", array_filter(explode(",", preg_replace( '|[^0-9,]|', '', $new_instance['pid'] ))));
462
  $instance['cat'] = implode(",", array_filter(explode(",", preg_replace( '|[^0-9,-]|', '', $new_instance['cat'] ))));
463
  $instance['author'] = implode(",", array_filter(explode(",", preg_replace( '|[^0-9,]|', '', $new_instance['uid'] ))));
648
  * @since 1.0.0
649
  */
650
  public function register_widget_styles() {
651
+
652
  $theme_file = get_stylesheet_directory() . '/wpp.css';
653
  $plugin_file = plugin_dir_path(__FILE__) . 'style/wpp.css';
654
 
657
  } elseif ( @file_exists($plugin_file) ) { // no custom wpp.css, use plugin's instead
658
  wp_enqueue_style( $this->plugin_slug, plugins_url( 'style/wpp.css', __FILE__ ), array(), $this->version );
659
  }
660
+
661
  } // end register_widget_styles
662
 
663
  /**
1252
 
1253
  if ( !$result1 || !$result2 )
1254
  return false;
1255
+
1256
  // Allow WP themers / coders perform an action
1257
  // after updating views count
1258
  if ( has_action( 'wpp_update_views' ) )
1716
  }
1717
  // build regular layout
1718
  else {
1719
+ $content =
1720
+ '<li>'
1721
+ . $thumb
1722
+ . '<a href="' . $permalink . '" title="' . esc_attr($title) . '" class="wpp-post-title" target="' . $this->user_settings['tools']['link']['target'] . '">' . $title_sub . '</a> '
1723
+ . $excerpt . ' <span class="post-stats">' . $_stats . '</span> '
1724
+ . $rating
1725
+ . "</li>\n";
1726
  }
1727
 
1728
  return apply_filters('wpp_post', $content, $p, $instance);
2163
 
2164
  // Get image by post ID (parent)
2165
  if ( $id ) {
2166
+ $file_paths = $this->__get_image_file_paths($id, $source);
2167
  $file_path = $file_paths['file_path'];
2168
  $thumbnail = isset( $file_paths['thumbnail'] )
2169
  ? $file_paths['thumbnail']
2185
  $attachment_id = $this->__get_attachment_id($image_url);
2186
 
2187
  // Image is hosted locally
2188
+ if ( $attachment_id ) {
2189
  $thumbnail = $image_url;
2190
  $file_path = get_attached_file($attachment_id);
2191
  }
2207
 
2208
  // there is a thumbnail already
2209
  if (file_exists($cropped_thumb)) {
2210
+ $new_img = str_replace(basename($thumbnail), basename($cropped_thumb), $thumbnail);
2211
  return $this->_render_image($new_img, $dim, 'wpp-thumbnail wpp_cached_thumb wpp_' . $source, $title);
2212
  }
2213
 
2225
  * @return string
2226
  */
2227
  private function __image_resize($path, $thumbnail, $dimension, $source) {
2228
+
2229
  $image = wp_get_image_editor($path);
2230
+
2231
  // valid image, create thumbnail
2232
  if (!is_wp_error($image)) {
2233
 
2237
  if (is_wp_error($new_img)) {
2238
  return $this->_render_image($this->default_thumbnail, $dimension, 'wpp-thumbnail wpp_imgeditor_error wpp_' . $source, '', $image->get_error_message());
2239
  }
2240
+
2241
  $new_img = str_replace(basename($thumbnail), $new_img['file'], $thumbnail);
2242
+
2243
  return $this->_render_image($new_img, $dimension, 'wpp-thumbnail wpp_imgeditor_thumb wpp_' . $source, '');
2244
  }
2245
 
2298
  $attachment_id = $this->__get_attachment_id($content_images[1][0]);
2299
 
2300
  // image from Media Library
2301
+ if ($attachment_id) {
2302
  $thumbnail = $content_images[1][0];
 
 
 
2303
  $file_path = get_attached_file($attachment_id);
2304
  } // external image?
2305
  else {
2354
  * @return bool|int
2355
  */
2356
  private function __get_attachment_id($url) {
2357
+
2358
  // Split the $url into two parts with the wp-content directory as the separator.
2359
  $parse_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
2360
+
2361
  // Get the host of the current site and the host of the $url, ignoring www.
2362
  $this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
2363
  $file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
2364
+
2365
  // Return nothing if there aren't any $url parts or if the current host and $url host do not match.
2366
  if ( ! isset( $parse_url[1] ) || empty( $parse_url[1] ) || ( $this_host != $file_host ) ) {
2367
  return false;
2368
  }
2369
+
2370
  // Now we're going to quickly search the DB for any attachment GUID with a partial path match.
2371
  // Example: /uploads/2013/05/test-image.jpg
2372
  global $wpdb;
2373
+
2374
+ if ( !$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;", $parse_url[1] ) ) ) {
2375
+ // Maybe it's a resized image, so try to get the full one
2376
+ $parse_url[1] = preg_replace( '/-[0-9]{1,4}x[0-9]{1,4}\.(jpg|jpeg|png|gif|bmp)$/i', '.$1', $parse_url[1] );
2377
+ $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;", $parse_url[1] ) );
2378
+ }
2379
+
2380
  // Returns null if no attachment is found.
2381
  return $attachment[0];
2382
 
2396
  $uploads = wp_upload_dir();
2397
  $image['thumbnail'] = trailingslashit( $uploads['baseurl'] ) . "{$id}_". sanitize_file_name( rawurldecode(wp_basename( $url )) );
2398
  $image['file_path'] = trailingslashit( $uploads['basedir'] ) . "{$id}_". sanitize_file_name( rawurldecode(wp_basename( $url )) );
2399
+
2400
  // if the file exists already, return URL and path
2401
  if ( file_exists($image['file_path']) )
2402
  return $image;
2476
  // remove Iframes
2477
  $excerpt = preg_replace( "/<iframe.*?\/iframe>/i", "", $excerpt);
2478
 
2479
+ // remove WP shortcodes
2480
+ $excerpt = strip_shortcodes( $excerpt );
2481
+
2482
+ // remove HTML tags if requested
2483
+ if ( $instance['post-excerpt']['keep_format'] ) {
2484
+ $excerpt = strip_tags($excerpt, '<a><b><i><em><strong>');
2485
+ } else {
2486
+ $excerpt = strip_tags($excerpt);
2487
+ // remove URLs, too
2488
+ $excerpt = preg_replace( '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS', '', $excerpt );
2489
+ }
2490
 
2491
  // Fix RSS CDATA tags
2492
  $excerpt = str_replace( ']]>', ']]&gt;', $excerpt );
2500
  $words = explode(" ", $excerpt, $instance['post-excerpt']['length'] + 1);
2501
 
2502
  if ( count($words) > $instance['post-excerpt']['length'] ) {
 
2503
  array_pop($words);
2504
  $excerpt = implode(" ", $words) . "...";
 
2505
  }
2506
 
2507
  } else { // by characters
2512
 
2513
  }
2514
 
2515
+ }
 
 
 
 
 
 
 
 
2516
 
2517
+ // Balance tags, if needed
2518
+ if ( $instance['post-excerpt']['keep_format'] ) {
2519
+ $excerpt = force_balance_tags($excerpt);
2520
  }
2521
 
2522
  return $excerpt;
2631
  'category' => empty($stats_category) ? false : $stats_category,
2632
  ),
2633
  'markup' => array(
2634
+ 'custom_html' => true,
2635
+ 'wpp-start' => empty($wpp_start) ? '<ul class="wpp-list">' : $wpp_start,
2636
+ 'wpp-end' => empty($wpp_end) ? '</ul>' : $wpp_end,
2637
+ 'title-start' => empty($header_start) ? '' : $header_start,
2638
+ 'title-end' => empty($header_end) ? '' : $header_end,
2639
+ 'post-html' => empty($post_html) ? '<li>{thumb} {title} {stats}</li>' : $post_html
2640
  )
2641
  );
2642
 
2644
 
2645
  // is there a title defined by user?
2646
  if (!empty($header) && !empty($header_start) && !empty($header_end)) {
2647
+ $shortcode_content .= htmlspecialchars_decode($header_start, ENT_QUOTES) . apply_filters('widget_title', $header) . htmlspecialchars_decode($header_end, ENT_QUOTES);
2648
  }
2649
 
2650
  // print popular posts list
2967
 
2968
  $now = current_time('mysql');
2969
 
2970
+ $query = "SELECT SUM(pageviews) FROM {$table_name}summary WHERE postid = '{$id}' AND last_viewed > DATE_SUB('{$now}', INTERVAL {$interval}) LIMIT 1;";
2971
  }
2972
 
2973
  $result = $wpdb->get_var($query);
2997
  if( is_array( $args ) ){
2998
  $atts = '';
2999
  foreach( $args as $key => $arg ){
3000
+ $atts .= ' ' . $key . '="' . htmlspecialchars($arg, ENT_QUOTES) . '"';
3001
  }
3002
  } else {
3003
  $atts = trim( str_replace( "&", " ", $args ) );