Version Description
Fixed: Initialisation error for new installs
Download this release
Release Info
Developer | Ajay |
Plugin | Top 10 – Popular posts plugin for WordPress |
Version | 1.9.10.1 |
Comparing to | |
See all releases |
Code changes from version 1.9.10 to 1.9.10.1
- readme.txt +17 -11
- top-10.php +126 -126
readme.txt
CHANGED
@@ -21,7 +21,7 @@ Includes a sidebar widget to display the popular posts. And, all settings can be
|
|
21 |
* **Display the count**: Customize the text that can be displayed
|
22 |
* **Show off popular posts**: Display a list of daily and/or overall popular posts by page count. You can choose how many posts are to be displayed plus loads of other customisation options
|
23 |
* **Widget ready**: Sidebar widgets available for daily popular and overall popular posts. Highly customizable widgets to control what you want to display in the list of posts
|
24 |
-
* **Customisable output**:
|
25 |
* Top 10 includes a default CSS style to make your popular posts list look pretty. Choose **Thumbnails inline, before title** under 'Thumbnail options' when using this option
|
26 |
* Output wrapped in CSS classes that allows you to style the list. You can enter your custom CSS styles from within WordPress Admin area under "Custom Styles"
|
27 |
* Pick your own HTML tags to use for displaying the output in case you don't prefer the default `list` format
|
@@ -53,12 +53,18 @@ If you're looking for a plugin to display related, look no further than my other
|
|
53 |
|
54 |
== Upgrade Notice ==
|
55 |
|
|
|
|
|
|
|
56 |
= 1.9.10 =
|
57 |
New meta box to set thumbnails; Edit total view count; Stop tracking Editors; Shortcode accepts all parameters as options page;
|
58 |
Refer to the Changelog for full list of changes.
|
59 |
|
60 |
== Changelog ==
|
61 |
|
|
|
|
|
|
|
62 |
= 1.9.10 =
|
63 |
* New: Meta box on Edit post / page and similar screens that allow you to set the Top 10 (and my other plugins) specific thumbnail for the current post (different from the Featured thumb)
|
64 |
* New: Admins can edit the number of total views (find it in the same meta box as above)
|
@@ -85,7 +91,7 @@ Refer to the Changelog for full list of changes.
|
|
85 |
* New: Option to disable display of counts to non-admins. Check out the option 'Show number of views to non-admins'
|
86 |
* New: Option to display different text when there are no hits on the post on non single posts e.g. home page, archives, etc.
|
87 |
* New: Class `tptn_posts_widget` for the widgets
|
88 |
-
* Modified: Brought back the old columns "Views" in the Admin Posts and Pages which contains both the Overall and Daily counts
|
89 |
* Modified: New admin interface keeping mobile first in mind
|
90 |
* Modified: Optimised widgets loading
|
91 |
* Modified: Cron job will now delete entries from the daily table older than 90 days
|
@@ -112,11 +118,11 @@ Refer to the Changelog for full list of changes.
|
|
112 |
|
113 |
= 1.9.8.2 =
|
114 |
* New: Option to add author
|
115 |
-
* New: More options for the Widgets to configure the post lists
|
116 |
* Modified: Shortcodes are now stripped from excerpts
|
117 |
* New: Added *s3.amazonaws.com* to list of allowed sites that timthumb can fetch images from
|
118 |
* Fixed: Counter was not always displayed on posts
|
119 |
-
* New: All Posts / All Pages have separate *sortable* columns for total and daily counts
|
120 |
* Fixed: Warning messages with WP_DEBUG mode ON
|
121 |
|
122 |
= 1.9.8.1 =
|
@@ -129,7 +135,7 @@ Refer to the Changelog for full list of changes.
|
|
129 |
* New: Option to add nofollow attribute to links
|
130 |
* New: Option to exclude posts by ID in the list of top posts being displayed
|
131 |
* New: Option to prevent display of the Visit Count on posts by ID
|
132 |
-
* New: Option to choose between using CSS styles or HTML attributes for thumbnail width and height. *HTML width and height attributes are default*
|
133 |
* New: Option to restrict the title to fixed number of characters
|
134 |
* New: Option to add the date to the list
|
135 |
* Modified: Numbers are now formatted based on the locale
|
@@ -171,7 +177,7 @@ Refer to the Changelog for full list of changes.
|
|
171 |
= 1.9 =
|
172 |
* New: Option to use timthumb to resize thumbnails
|
173 |
* New: New variable **%overallcount%** that will display the total pageviews on the blog across all posts
|
174 |
-
* New: Post thumbnails are now properly resized based on width and height settings in the Top 10 settings page
|
175 |
* New: Customise what to display when there are no top posts detected
|
176 |
* New: New scheduled maintenance to clear up daily tables and optimise performance
|
177 |
* New: Custom CSS code to style the output. Check out the available styles in the <a href="http://wordpress.org/extend/plugins/top-10/faq/">FAQ</a>.
|
@@ -217,7 +223,7 @@ Refer to the Changelog for full list of changes.
|
|
217 |
* Turned the credit option to false by default. This setting won't effect current users.
|
218 |
* Turned off borders on post thumbnails. You can customise the CSS class "tptn_thumb" to style the post thumbnail.
|
219 |
* The plugin will now display a list of changes in the WordPress Admin > Plugins area whenever an update is available
|
220 |
-
* Fixed: Display of caching plugin compliant daily top posts lists
|
221 |
|
222 |
= 1.6 =
|
223 |
* New: Added support for excerpts and detection of first image in the post
|
@@ -238,7 +244,7 @@ Refer to the Changelog for full list of changes.
|
|
238 |
* Added support for post thumbnails feature of WordPress 2.9
|
239 |
|
240 |
= 1.4.1 =
|
241 |
-
* Fixed compatibility with WordPress 2.9
|
242 |
* Fixed XHTML validation errors in output code
|
243 |
* Added buttons to reset post count of overall and daily posts
|
244 |
|
@@ -281,7 +287,7 @@ Refer to the Changelog for full list of changes.
|
|
281 |
|
282 |
2. Extract the contents of top-10.zip to wp-content/plugins/ folder. You should get a folder called top-10.
|
283 |
|
284 |
-
3. Activate the Plugin in WP-Admin.
|
285 |
|
286 |
4. Go to **Top 10** to configure
|
287 |
|
@@ -330,7 +336,7 @@ You can insert the popular posts anywhere in your post using the `[tptn_list]` s
|
|
330 |
|
331 |
`
|
332 |
<h3>Top posts</h3>
|
333 |
-
[tptn_list limit="2" heading="0"]
|
334 |
`
|
335 |
*daily* : If set to 1, then the shortcode will return the daily popular posts list
|
336 |
|
@@ -384,7 +390,7 @@ Never. This plugin is designed to only track the number of pageviews on your blo
|
|
384 |
|
385 |
= How does the scheduled maintenance work maintenance work? =
|
386 |
|
387 |
-
When you enabled the scheduled maintenance, Top 10 will create a cron job that will run at a predefined interval and truncate the `wp_top_ten_daily` table.
|
388 |
*Note: If you enable this option, WordPress will execute this job when it is scheduled the first time*
|
389 |
|
390 |
= How to make the columns on the Custom Posts pages sortable? =
|
21 |
* **Display the count**: Customize the text that can be displayed
|
22 |
* **Show off popular posts**: Display a list of daily and/or overall popular posts by page count. You can choose how many posts are to be displayed plus loads of other customisation options
|
23 |
* **Widget ready**: Sidebar widgets available for daily popular and overall popular posts. Highly customizable widgets to control what you want to display in the list of posts
|
24 |
+
* **Customisable output**:
|
25 |
* Top 10 includes a default CSS style to make your popular posts list look pretty. Choose **Thumbnails inline, before title** under 'Thumbnail options' when using this option
|
26 |
* Output wrapped in CSS classes that allows you to style the list. You can enter your custom CSS styles from within WordPress Admin area under "Custom Styles"
|
27 |
* Pick your own HTML tags to use for displaying the output in case you don't prefer the default `list` format
|
53 |
|
54 |
== Upgrade Notice ==
|
55 |
|
56 |
+
= 1.9.10.1 =
|
57 |
+
Fixed: Initialisation error for new installs
|
58 |
+
|
59 |
= 1.9.10 =
|
60 |
New meta box to set thumbnails; Edit total view count; Stop tracking Editors; Shortcode accepts all parameters as options page;
|
61 |
Refer to the Changelog for full list of changes.
|
62 |
|
63 |
== Changelog ==
|
64 |
|
65 |
+
= 1.9.10.1 =
|
66 |
+
* Fixed: Initialisation error for new installs
|
67 |
+
|
68 |
= 1.9.10 =
|
69 |
* New: Meta box on Edit post / page and similar screens that allow you to set the Top 10 (and my other plugins) specific thumbnail for the current post (different from the Featured thumb)
|
70 |
* New: Admins can edit the number of total views (find it in the same meta box as above)
|
91 |
* New: Option to disable display of counts to non-admins. Check out the option 'Show number of views to non-admins'
|
92 |
* New: Option to display different text when there are no hits on the post on non single posts e.g. home page, archives, etc.
|
93 |
* New: Class `tptn_posts_widget` for the widgets
|
94 |
+
* Modified: Brought back the old columns "Views" in the Admin Posts and Pages which contains both the Overall and Daily counts
|
95 |
* Modified: New admin interface keeping mobile first in mind
|
96 |
* Modified: Optimised widgets loading
|
97 |
* Modified: Cron job will now delete entries from the daily table older than 90 days
|
118 |
|
119 |
= 1.9.8.2 =
|
120 |
* New: Option to add author
|
121 |
+
* New: More options for the Widgets to configure the post lists
|
122 |
* Modified: Shortcodes are now stripped from excerpts
|
123 |
* New: Added *s3.amazonaws.com* to list of allowed sites that timthumb can fetch images from
|
124 |
* Fixed: Counter was not always displayed on posts
|
125 |
+
* New: All Posts / All Pages have separate *sortable* columns for total and daily counts
|
126 |
* Fixed: Warning messages with WP_DEBUG mode ON
|
127 |
|
128 |
= 1.9.8.1 =
|
135 |
* New: Option to add nofollow attribute to links
|
136 |
* New: Option to exclude posts by ID in the list of top posts being displayed
|
137 |
* New: Option to prevent display of the Visit Count on posts by ID
|
138 |
+
* New: Option to choose between using CSS styles or HTML attributes for thumbnail width and height. *HTML width and height attributes are default*
|
139 |
* New: Option to restrict the title to fixed number of characters
|
140 |
* New: Option to add the date to the list
|
141 |
* Modified: Numbers are now formatted based on the locale
|
177 |
= 1.9 =
|
178 |
* New: Option to use timthumb to resize thumbnails
|
179 |
* New: New variable **%overallcount%** that will display the total pageviews on the blog across all posts
|
180 |
+
* New: Post thumbnails are now properly resized based on width and height settings in the Top 10 settings page
|
181 |
* New: Customise what to display when there are no top posts detected
|
182 |
* New: New scheduled maintenance to clear up daily tables and optimise performance
|
183 |
* New: Custom CSS code to style the output. Check out the available styles in the <a href="http://wordpress.org/extend/plugins/top-10/faq/">FAQ</a>.
|
223 |
* Turned the credit option to false by default. This setting won't effect current users.
|
224 |
* Turned off borders on post thumbnails. You can customise the CSS class "tptn_thumb" to style the post thumbnail.
|
225 |
* The plugin will now display a list of changes in the WordPress Admin > Plugins area whenever an update is available
|
226 |
+
* Fixed: Display of caching plugin compliant daily top posts lists
|
227 |
|
228 |
= 1.6 =
|
229 |
* New: Added support for excerpts and detection of first image in the post
|
244 |
* Added support for post thumbnails feature of WordPress 2.9
|
245 |
|
246 |
= 1.4.1 =
|
247 |
+
* Fixed compatibility with WordPress 2.9
|
248 |
* Fixed XHTML validation errors in output code
|
249 |
* Added buttons to reset post count of overall and daily posts
|
250 |
|
287 |
|
288 |
2. Extract the contents of top-10.zip to wp-content/plugins/ folder. You should get a folder called top-10.
|
289 |
|
290 |
+
3. Activate the Plugin in WP-Admin.
|
291 |
|
292 |
4. Go to **Top 10** to configure
|
293 |
|
336 |
|
337 |
`
|
338 |
<h3>Top posts</h3>
|
339 |
+
[tptn_list limit="2" heading="0"]
|
340 |
`
|
341 |
*daily* : If set to 1, then the shortcode will return the daily popular posts list
|
342 |
|
390 |
|
391 |
= How does the scheduled maintenance work maintenance work? =
|
392 |
|
393 |
+
When you enabled the scheduled maintenance, Top 10 will create a cron job that will run at a predefined interval and truncate the `wp_top_ten_daily` table.
|
394 |
*Note: If you enable this option, WordPress will execute this job when it is scheduled the first time*
|
395 |
|
396 |
= How to make the columns on the Custom Posts pages sortable? =
|
top-10.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Top 10
|
4 |
-
Version: 1.9.10
|
5 |
Plugin URI: http://ajaydsouza.com/wordpress/plugins/top-10/
|
6 |
Description: Count daily and total visits per post and display the most popular posts based on the number of views. Based on the plugin by <a href="http://weblogtoolscollection.com">Mark Ghosh</a>
|
7 |
Author: Ajay D'Souza
|
@@ -25,7 +25,7 @@ $tptn_settings = tptn_read_options();
|
|
25 |
|
26 |
/**
|
27 |
* Function to load translation files.
|
28 |
-
*
|
29 |
* @access public
|
30 |
* @return void
|
31 |
*/
|
@@ -37,7 +37,7 @@ add_action( 'init', 'tptn_lang_init' );
|
|
37 |
|
38 |
/**
|
39 |
* Filter for content to update post views.
|
40 |
-
*
|
41 |
* @access public
|
42 |
* @param string $content Post content
|
43 |
* @return string Filtered content
|
@@ -49,12 +49,12 @@ function tptn_add_viewed_count( $content ) {
|
|
49 |
if ( is_singular() ) {
|
50 |
|
51 |
global $tptn_settings;
|
52 |
-
|
53 |
-
$current_user = wp_get_current_user();
|
54 |
$post_author = ( $current_user->ID == $post->post_author ) ? true : false; // Is the current user the post author?
|
55 |
$current_user_admin = ( current_user_can( 'manage_options' ) ) ? true : false; // Is the current user an admin?
|
56 |
$current_user_editor = ( ( current_user_can( 'edit_others_posts' ) ) && ( ! current_user_can( 'manage_options' ) ) ) ? true : false; // Is the current user pure editor?
|
57 |
-
|
58 |
$include_code = true;
|
59 |
if ( ( $post_author ) && ( ! $tptn_settings['track_authors'] ) ) $include_code = false;
|
60 |
if ( ( $current_user_admin ) && ( ! $tptn_settings['track_admins'] ) ) $include_code = false;
|
@@ -67,7 +67,7 @@ function tptn_add_viewed_count( $content ) {
|
|
67 |
$activate_counter = $activate_counter + ( $tptn_settings['activate_daily'] ? 10 : 0 );
|
68 |
if ( $activate_counter > 0 ) {
|
69 |
if ( $tptn_settings['cache_fix'] ) {
|
70 |
-
$output = '<script type="text/javascript">jQuery.ajax({url: "' .$tptn_url. '/top-10-addcount.js.php", data: {top_ten_id: ' .$id. ', activate_counter: ' . $activate_counter . ', top10_rnd: (new Date()).getTime() + "-" + Math.floor(Math.random()*100000)}});</script>';
|
71 |
} else {
|
72 |
$output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-addcount.js.php?top_ten_id='.$id.'&activate_counter='.$activate_counter.'"></script>';
|
73 |
}
|
@@ -86,13 +86,13 @@ add_filter( 'the_content', 'tptn_add_viewed_count' );
|
|
86 |
|
87 |
/**
|
88 |
* Enqueue Scripts.
|
89 |
-
*
|
90 |
* @access public
|
91 |
* @return void
|
92 |
*/
|
93 |
function tptn_enqueue_scripts() {
|
94 |
global $tptn_settings;
|
95 |
-
|
96 |
if ( $tptn_settings['cache_fix'] ) wp_enqueue_script( 'jquery' );
|
97 |
}
|
98 |
add_action( 'wp_enqueue_scripts', 'tptn_enqueue_scripts' ); // wp_enqueue_scripts action hook to link only on the front-end
|
@@ -100,7 +100,7 @@ add_action( 'wp_enqueue_scripts', 'tptn_enqueue_scripts' ); // wp_enqueue_script
|
|
100 |
|
101 |
/**
|
102 |
* Filter to add visited count to content.
|
103 |
-
*
|
104 |
* @access public
|
105 |
* @param string $content
|
106 |
* @return string
|
@@ -113,7 +113,7 @@ function tptn_pc_content( $content ) {
|
|
113 |
if ( in_array( $post->ID, $exclude_on_post_ids ) ) {
|
114 |
return $content; // Exit without adding related posts
|
115 |
}
|
116 |
-
|
117 |
if ( ( is_single() ) && ( $tptn_settings['add_to_content'] ) ) {
|
118 |
return $content.echo_tptn_post_count(0);
|
119 |
} elseif ( ( is_page() ) && ( $tptn_settings['count_on_pages'] ) ) {
|
@@ -135,7 +135,7 @@ add_filter( 'the_content', 'tptn_pc_content' );
|
|
135 |
|
136 |
/**
|
137 |
* Filter to add related posts to feeds.
|
138 |
-
*
|
139 |
* @access public
|
140 |
* @param string $content
|
141 |
* @return string
|
@@ -157,16 +157,16 @@ add_filter( 'the_content_feed', 'ald_tptn_rss' );
|
|
157 |
|
158 |
/**
|
159 |
* Function to manually display count.
|
160 |
-
*
|
161 |
* @access public
|
162 |
* @param int|boolean $echo (default: 1)
|
163 |
* @return string
|
164 |
*/
|
165 |
function echo_tptn_post_count( $echo = 1 ) {
|
166 |
global $post, $tptn_url, $tptn_path, $tptn_settings;
|
167 |
-
|
168 |
$id = intval( $post->ID );
|
169 |
-
|
170 |
$nonce_action = 'tptn-nonce-' . $id ;
|
171 |
$nonce = wp_create_nonce( $nonce_action );
|
172 |
|
@@ -175,7 +175,7 @@ function echo_tptn_post_count( $echo = 1 ) {
|
|
175 |
} else {
|
176 |
$output = '<div class="tptn_counter" id="tptn_counter_' . $id . '">' . get_tptn_post_count( $id ) . '</div>';
|
177 |
}
|
178 |
-
|
179 |
if ( $echo ) {
|
180 |
echo $output;
|
181 |
} else {
|
@@ -186,21 +186,21 @@ function echo_tptn_post_count( $echo = 1 ) {
|
|
186 |
|
187 |
/**
|
188 |
* Return the formatted post count for the supplied ID.
|
189 |
-
*
|
190 |
* @access public
|
191 |
* @param int|string $id Post ID
|
192 |
* @return int|string Formatted post count
|
193 |
*/
|
194 |
function get_tptn_post_count( $id = FALSE ) {
|
195 |
global $wpdb, $tptn_settings;
|
196 |
-
|
197 |
$table_name = $wpdb->prefix . "top_ten";
|
198 |
$table_name_daily = $wpdb->prefix . "top_ten_daily";
|
199 |
|
200 |
$count_disp_form = stripslashes( $tptn_settings['count_disp_form'] );
|
201 |
$count_disp_form_zero = stripslashes( $tptn_settings['count_disp_form_zero'] );
|
202 |
$totalcntaccess = get_tptn_post_count_only( $id, 'total' );
|
203 |
-
|
204 |
if ( $id > 0 ) {
|
205 |
|
206 |
// Total count per post
|
@@ -211,7 +211,7 @@ function get_tptn_post_count( $id = FALSE ) {
|
|
211 |
$count_disp_form = str_replace( "%totalcount%", ( 0 == $totalcntaccess ? $totalcntaccess + 1 : $totalcntaccess ), $count_disp_form );
|
212 |
}
|
213 |
}
|
214 |
-
|
215 |
// Now process daily count
|
216 |
if ( ( false !== strpos( $count_disp_form, "%dailycount%" ) ) || ( false !== strpos( $count_disp_form_zero, "%dailycount%" ) ) ) {
|
217 |
$cntaccess = get_tptn_post_count_only( $id, 'daily' );
|
@@ -221,7 +221,7 @@ function get_tptn_post_count( $id = FALSE ) {
|
|
221 |
$count_disp_form = str_replace( "%dailycount%", ( 0 == $cntaccess ? $cntaccess + 1 : $cntaccess ), $count_disp_form );
|
222 |
}
|
223 |
}
|
224 |
-
|
225 |
// Now process overall count
|
226 |
if ( ( false !== strpos( $count_disp_form, "%overallcount%" ) ) || ( false !== strpos( $count_disp_form_zero, "%overallcount%" ) ) ) {
|
227 |
$cntaccess = get_tptn_post_count_only( $id, 'overall' );
|
@@ -231,7 +231,7 @@ function get_tptn_post_count( $id = FALSE ) {
|
|
231 |
$count_disp_form = str_replace( "%overallcount%", ( 0 == $cntaccess ? $cntaccess + 1 : $cntaccess ), $count_disp_form );
|
232 |
}
|
233 |
}
|
234 |
-
|
235 |
if ( ( 0 == $totalcntaccess ) && ( ! is_singular() ) ) {
|
236 |
return apply_filters( 'tptn_post_count', $count_disp_form_zero );
|
237 |
} else {
|
@@ -245,7 +245,7 @@ function get_tptn_post_count( $id = FALSE ) {
|
|
245 |
|
246 |
/**
|
247 |
* Returns the post count.
|
248 |
-
*
|
249 |
* @access public
|
250 |
* @param mixed $id (default: FALSE) Post ID
|
251 |
* @param string $count (default: 'total') Which count to return? total, daily or overall
|
@@ -253,11 +253,11 @@ function get_tptn_post_count( $id = FALSE ) {
|
|
253 |
*/
|
254 |
function get_tptn_post_count_only( $id = FALSE, $count = 'total' ) {
|
255 |
global $wpdb;
|
256 |
-
|
257 |
$table_name = $wpdb->prefix . "top_ten";
|
258 |
$table_name_daily = $wpdb->prefix . "top_ten_daily";
|
259 |
global $tptn_settings;
|
260 |
-
|
261 |
if($id > 0) {
|
262 |
switch ($count) {
|
263 |
case 'total':
|
@@ -269,7 +269,7 @@ function get_tptn_post_count_only( $id = FALSE, $count = 'total' ) {
|
|
269 |
$current_time = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
|
270 |
$current_date = strtotime ( '-'.$daily_range. ' DAY' , strtotime ( $current_time ) );
|
271 |
$current_date = date ( 'Y-m-j' , $current_date );
|
272 |
-
|
273 |
$resultscount = $wpdb->get_row( $wpdb->prepare( "SELECT postnumber, SUM(cntaccess) as sumCount FROM {$table_name_daily} WHERE postnumber = %d AND dp_date >= '%s' GROUP BY postnumber ", array($id, $current_date) ) );
|
274 |
$cntaccess = number_format_i18n((($resultscount) ? $resultscount->sumCount : 0));
|
275 |
break;
|
@@ -286,14 +286,14 @@ function get_tptn_post_count_only( $id = FALSE, $count = 'total' ) {
|
|
286 |
|
287 |
/**
|
288 |
* Function to return popular posts.
|
289 |
-
*
|
290 |
* @access public
|
291 |
* @param mixed $args
|
292 |
* @return array|string Array of posts if posts_only = 0 or a formatted string if posts_only = 1
|
293 |
*/
|
294 |
function tptn_pop_posts( $args ) {
|
295 |
global $wpdb, $siteurl, $tableposts, $id, $tptn_settings;
|
296 |
-
|
297 |
$defaults = array(
|
298 |
'is_widget' => FALSE,
|
299 |
'daily' => FALSE,
|
@@ -304,26 +304,26 @@ function tptn_pop_posts( $args ) {
|
|
304 |
'heading' => 1,
|
305 |
);
|
306 |
$defaults = array_merge( $defaults, $tptn_settings );
|
307 |
-
|
308 |
// Parse incomming $args into an array and merge it with $defaults
|
309 |
$args = wp_parse_args( $args, $defaults );
|
310 |
-
|
311 |
// OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
|
312 |
extract( $args, EXTR_SKIP );
|
313 |
|
314 |
if ($daily) {
|
315 |
-
$table_name = $wpdb->prefix . "top_ten_daily";
|
316 |
} else {
|
317 |
$table_name = $wpdb->prefix . "top_ten";
|
318 |
}
|
319 |
-
|
320 |
-
$limit = ( $strict_limit ) ? $limit : ( $limit * 5 );
|
321 |
|
322 |
$exclude_categories = explode( ',', $exclude_categories );
|
323 |
|
324 |
$target_attribute = ( $link_new_window ) ? ' target="_blank" ' : ' '; // Set Target attribute
|
325 |
$rel_attribute = ( $link_nofollow ) ? ' nofollow' : ''; // Set nofollow attribute
|
326 |
-
|
327 |
parse_str( $post_types, $post_types ); // Save post types in $post_types variable
|
328 |
|
329 |
if ( ! $daily ) {
|
@@ -331,7 +331,7 @@ function tptn_pop_posts( $args ) {
|
|
331 |
$sql = "SELECT postnumber, cntaccess as sumCount, ID, post_type, post_status ";
|
332 |
$sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
333 |
$sql .= "AND post_status = 'publish' ";
|
334 |
-
if ( '' != $exclude_post_ids ) {
|
335 |
$sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
|
336 |
}
|
337 |
$sql .= "AND ( ";
|
@@ -349,14 +349,14 @@ function tptn_pop_posts( $args ) {
|
|
349 |
$current_time = current_time( 'timestamp', 0 );
|
350 |
$current_time = $current_time - ( $daily_range - 1 ) * 3600 * 24;
|
351 |
$current_date = date( 'Y-m-j', $current_time );
|
352 |
-
|
353 |
$args = array(
|
354 |
$current_date,
|
355 |
);
|
356 |
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
|
357 |
$sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
358 |
$sql .= "AND post_status = 'publish' AND dp_date >= '%s' ";
|
359 |
-
if ( '' != $exclude_post_ids ) {
|
360 |
$sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
|
361 |
}
|
362 |
$sql .= "AND ( ";
|
@@ -372,17 +372,17 @@ function tptn_pop_posts( $args ) {
|
|
372 |
$sql .= "ORDER BY sumCount DESC LIMIT %d";
|
373 |
$args[] = $limit;
|
374 |
}
|
375 |
-
|
376 |
if ( $posts_only ) { // Return the array of posts only if the variable is set
|
377 |
return apply_filters( 'tptn_pop_posts_array', $wpdb->get_results( $wpdb->prepare( $sql , $args ) , ARRAY_A ) );
|
378 |
}
|
379 |
-
|
380 |
$results = $wpdb->get_results( $wpdb->prepare( $sql , $args ) );
|
381 |
-
|
382 |
$counter = 0;
|
383 |
|
384 |
$output = '';
|
385 |
-
|
386 |
$shortcode_class = $is_shortcode ? ' tptn_posts_shortcode' : '';
|
387 |
$widget_class = $is_widget ? ' tptn_posts_widget' : '';
|
388 |
|
@@ -399,7 +399,7 @@ function tptn_pop_posts( $args ) {
|
|
399 |
$output .= '<div class="tptn_posts_daily' . $widget_class . $shortcode_class . '">';
|
400 |
}
|
401 |
}
|
402 |
-
|
403 |
if ( $results ) {
|
404 |
$output .= apply_filters( 'tptn_before_list', $before_list );
|
405 |
foreach ( $results as $result ) {
|
@@ -426,7 +426,7 @@ function tptn_pop_posts( $args ) {
|
|
426 |
}
|
427 |
if ( 'inline' == $post_thumb_op || 'after' == $post_thumb_op || 'thumbs_only' == $post_thumb_op ) {
|
428 |
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
|
429 |
-
$output .= tptn_get_the_post_thumbnail( array(
|
430 |
'postid' => $result->ID,
|
431 |
'thumb_height' => $thumb_height,
|
432 |
'thumb_width' => $thumb_width,
|
@@ -438,7 +438,7 @@ function tptn_pop_posts( $args ) {
|
|
438 |
'thumb_timthumb_q' => $thumb_timthumb_q,
|
439 |
'scan_images' => $scan_images,
|
440 |
'class' => "tptn_thumb",
|
441 |
-
'filter' => "tptn_postimage",
|
442 |
) );
|
443 |
$output .= '</a>'; // Close the link
|
444 |
}
|
@@ -452,7 +452,7 @@ function tptn_pop_posts( $args ) {
|
|
452 |
$author_info = get_userdata( $result->post_author );
|
453 |
$author_name = ucwords( trim( stripslashes( $author_info->display_name ) ) );
|
454 |
$author_link = get_author_posts_url( $author_info->ID );
|
455 |
-
|
456 |
$output .= '<span class="tptn_author"> ' . __( ' by ', TPTN_LOCAL_NAME ).'<a href="' . $author_link . '">' . $author_name . '</a></span> ';
|
457 |
}
|
458 |
if ( $show_date ) {
|
@@ -462,13 +462,13 @@ function tptn_pop_posts( $args ) {
|
|
462 |
$output .= '<span class="tptn_excerpt"> ' . tptn_excerpt( $result->ID, $excerpt_length ).'</span>';
|
463 |
}
|
464 |
if ( $disp_list_count ) $output .= ' <span class="tptn_list_count">(' . number_format_i18n( $sumcount ) . ')</span>';
|
465 |
-
|
466 |
if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
|
467 |
$output .= '</span>';
|
468 |
}
|
469 |
-
|
470 |
$output .= apply_filters( 'tptn_after_list_item', $after_list_item, $result->ID );
|
471 |
-
$counter++;
|
472 |
}
|
473 |
if ( $counter == $limit/5 ) break; // End loop when related posts limit is reached
|
474 |
}
|
@@ -489,7 +489,7 @@ function tptn_pop_posts( $args ) {
|
|
489 |
|
490 |
/**
|
491 |
* Function to echo popular posts.
|
492 |
-
*
|
493 |
* @access public
|
494 |
* @return void
|
495 |
*/
|
@@ -500,13 +500,13 @@ function tptn_show_pop_posts( $args = NULL ) {
|
|
500 |
|
501 |
/**
|
502 |
* Function to show daily popular posts.
|
503 |
-
*
|
504 |
* @access public
|
505 |
* @return void
|
506 |
*/
|
507 |
function tptn_show_daily_pop_posts() {
|
508 |
global $tptn_url, $tptn_settings;
|
509 |
-
|
510 |
if ( $tptn_settings['d_use_js'] ) {
|
511 |
echo '<script type="text/javascript" src="' . $tptn_url . '/top-10-daily.js.php?widget=1"></script>';
|
512 |
} else {
|
@@ -517,26 +517,26 @@ function tptn_show_daily_pop_posts() {
|
|
517 |
|
518 |
/**
|
519 |
* Function to add CSS to header.
|
520 |
-
*
|
521 |
* @access public
|
522 |
* @return void
|
523 |
*/
|
524 |
function tptn_header() {
|
525 |
global $wpdb, $post, $single, $tptn_settings;
|
526 |
-
|
527 |
$tptn_custom_CSS = stripslashes( $tptn_settings['custom_CSS'] );
|
528 |
-
|
529 |
-
// Add CSS to header
|
530 |
if ( '' != $tptn_custom_CSS ) {
|
531 |
echo '<style type="text/css">' . $tptn_custom_CSS . '</style>';
|
532 |
}
|
533 |
}
|
534 |
add_action('wp_head','tptn_header');
|
535 |
|
536 |
-
|
537 |
/**
|
538 |
* Top 10 Widget.
|
539 |
-
*
|
540 |
* @extends WP_Widget
|
541 |
*/
|
542 |
class Top_Ten_Widget extends WP_Widget {
|
@@ -574,12 +574,12 @@ class Top_Ten_Widget extends WP_Widget {
|
|
574 |
?>
|
575 |
<p>
|
576 |
<label for="<?php echo $this->get_field_id( 'title' ); ?>">
|
577 |
-
<?php _e( 'Title', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
|
578 |
</label>
|
579 |
</p>
|
580 |
<p>
|
581 |
<label for="<?php echo $this->get_field_id( 'limit' ); ?>">
|
582 |
-
<?php _e( 'No. of posts', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" />
|
583 |
</label>
|
584 |
</p>
|
585 |
<p>
|
@@ -590,7 +590,7 @@ class Top_Ten_Widget extends WP_Widget {
|
|
590 |
</p>
|
591 |
<p>
|
592 |
<label for="<?php echo $this->get_field_id( 'daily_range' ); ?>">
|
593 |
-
<?php _e( 'Range in number of days (applies only to custom option above)', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'daily_range' ); ?>" name="<?php echo $this->get_field_name( 'daily_range' ); ?>" type="text" value="<?php echo esc_attr( $daily_range ); ?>" />
|
594 |
</label>
|
595 |
</p>
|
596 |
<p>
|
@@ -624,12 +624,12 @@ class Top_Ten_Widget extends WP_Widget {
|
|
624 |
</p>
|
625 |
<p>
|
626 |
<label for="<?php echo $this->get_field_id( 'thumb_height' ); ?>">
|
627 |
-
<?php _e( 'Thumbnail height', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'thumb_height' ); ?>" name="<?php echo $this->get_field_name( 'thumb_height' ); ?>" type="text" value="<?php echo esc_attr($thumb_height); ?>" />
|
628 |
</label>
|
629 |
</p>
|
630 |
<p>
|
631 |
<label for="<?php echo $this->get_field_id( 'thumb_width' ); ?>">
|
632 |
-
<?php _e( 'Thumbnail width', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'thumb_width' ); ?>" name="<?php echo $this->get_field_name( 'thumb_width' ); ?>" type="text" value="<?php echo esc_attr( $thumb_width ); ?>" />
|
633 |
</label>
|
634 |
</p>
|
635 |
<?php
|
@@ -671,9 +671,9 @@ class Top_Ten_Widget extends WP_Widget {
|
|
671 |
*/
|
672 |
function widget( $args, $instance ) {
|
673 |
global $wpdb, $tptn_url, $tptn_settings;
|
674 |
-
|
675 |
extract( $args, EXTR_SKIP );
|
676 |
-
|
677 |
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? strip_tags( $tptn_settings['title'] ) : $instance['title'] );
|
678 |
$limit = $instance['limit'];
|
679 |
if ( empty( $limit ) ) {
|
@@ -724,7 +724,7 @@ class Top_Ten_Widget extends WP_Widget {
|
|
724 |
}
|
725 |
|
726 |
$output .= $after_widget;
|
727 |
-
|
728 |
echo $output;
|
729 |
|
730 |
} //ending function widget
|
@@ -733,42 +733,42 @@ class Top_Ten_Widget extends WP_Widget {
|
|
733 |
|
734 |
/**
|
735 |
* Initialise the widget.
|
736 |
-
*
|
737 |
* @access public
|
738 |
* @return void
|
739 |
*/
|
740 |
function tptn_register_widget() {
|
741 |
register_widget( 'Top_Ten_Widget' );
|
742 |
}
|
743 |
-
add_action( 'widgets_init', 'tptn_register_widget', 1 );
|
744 |
|
745 |
|
746 |
/**
|
747 |
* Enqueue styles.
|
748 |
-
*
|
749 |
* @access public
|
750 |
* @return void
|
751 |
*/
|
752 |
function tptn_heading_styles() {
|
753 |
global $tptn_settings;
|
754 |
-
|
755 |
if ( $tptn_settings['include_default_style'] ) {
|
756 |
wp_register_style( 'tptn_list_style', plugins_url( 'css/default-style.css', __FILE__ ) );
|
757 |
wp_enqueue_style( 'tptn_list_style' );
|
758 |
}
|
759 |
}
|
760 |
-
add_action( 'wp_enqueue_scripts', 'tptn_heading_styles' );
|
761 |
|
762 |
|
763 |
/**
|
764 |
* Default Options.
|
765 |
-
*
|
766 |
* @access public
|
767 |
* @return void
|
768 |
*/
|
769 |
function tptn_default_options() {
|
770 |
global $tptn_url;
|
771 |
-
|
772 |
$title = __( '<h3>Popular Posts</h3>', TPTN_LOCAL_NAME );
|
773 |
$title_daily = __( '<h3>Daily Popular</h3>', TPTN_LOCAL_NAME );
|
774 |
$blank_output_text = __( 'No top posts yet', TPTN_LOCAL_NAME );
|
@@ -796,7 +796,7 @@ function tptn_default_options() {
|
|
796 |
'track_editors' => true, // Track Admin visits
|
797 |
'pv_in_admin' => true, // Add an extra column on edit posts/pages to display page views?
|
798 |
'show_count_non_admins' => true, // Show counts to non-admins
|
799 |
-
|
800 |
'blank_output' => false, // Blank output? Default is "blank Output test"
|
801 |
'blank_output_text' => $blank_output_text, // Blank output text
|
802 |
'disp_list_count' => true, // Display count in popular lists?
|
@@ -858,7 +858,7 @@ function tptn_default_options() {
|
|
858 |
|
859 |
/**
|
860 |
* Function to read options from the database.
|
861 |
-
*
|
862 |
* @access public
|
863 |
* @return void
|
864 |
*/
|
@@ -869,16 +869,16 @@ function tptn_read_options() {
|
|
869 |
$installed_ver = get_option( "tptn_db_version" );
|
870 |
|
871 |
if ( $installed_ver != $tptn_db_version ) {
|
872 |
-
|
873 |
}
|
874 |
|
875 |
$tptn_settings_changed = false;
|
876 |
-
|
877 |
$defaults = tptn_default_options();
|
878 |
-
|
879 |
$tptn_settings = array_map( 'stripslashes', (array)get_option( 'ald_tptn_settings' ) );
|
880 |
unset( $tptn_settings[0] ); // produced by the (array) casting when there's nothing in the DB
|
881 |
-
|
882 |
foreach ( $defaults as $k=>$v ) {
|
883 |
if ( ! isset( $tptn_settings[$k] ) ) {
|
884 |
$tptn_settings[$k] = $v;
|
@@ -888,14 +888,14 @@ function tptn_read_options() {
|
|
888 |
if ( $tptn_settings_changed == true ) {
|
889 |
update_option('ald_tptn_settings', $tptn_settings);
|
890 |
}
|
891 |
-
|
892 |
return apply_filters( 'tptn_read_options', $tptn_settings );
|
893 |
}
|
894 |
|
895 |
|
896 |
/**
|
897 |
* Create tables to store pageviews.
|
898 |
-
*
|
899 |
* @access public
|
900 |
* @return void
|
901 |
*/
|
@@ -904,7 +904,7 @@ function tptn_activation_hook() {
|
|
904 |
|
905 |
$table_name = $wpdb->prefix . "top_ten";
|
906 |
$table_name_daily = $wpdb->prefix . "top_ten_daily";
|
907 |
-
|
908 |
if ( $wpdb->get_var( "show tables like '$table_name'" ) != $table_name ) {
|
909 |
|
910 |
$sql = "CREATE TABLE " . $table_name . " (
|
@@ -912,25 +912,25 @@ function tptn_activation_hook() {
|
|
912 |
cntaccess int NOT NULL,
|
913 |
PRIMARY KEY (postnumber)
|
914 |
);";
|
915 |
-
|
916 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
917 |
dbDelta( $sql );
|
918 |
-
|
919 |
add_option( "tptn_db_version", $tptn_db_version );
|
920 |
}
|
921 |
|
922 |
if($wpdb->get_var("show tables like '$table_name_daily'") != $table_name_daily) {
|
923 |
-
|
924 |
$sql = "CREATE TABLE " . $table_name_daily . " (
|
925 |
postnumber int NOT NULL,
|
926 |
cntaccess int NOT NULL,
|
927 |
dp_date date NOT NULL,
|
928 |
PRIMARY KEY (postnumber, dp_date)
|
929 |
);";
|
930 |
-
|
931 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
932 |
dbDelta($sql);
|
933 |
-
|
934 |
add_option("tptn_db_version", $tptn_db_version);
|
935 |
}
|
936 |
|
@@ -943,12 +943,12 @@ function tptn_activation_hook() {
|
|
943 |
$wpdb->query($sql);
|
944 |
$sql = "ALTER IGNORE TABLE " . $table_name . " ADD PRIMARY KEY (postnumber) ";
|
945 |
$wpdb->query($sql);
|
946 |
-
|
947 |
$sql = "ALTER TABLE " . $table_name_daily . " DROP COLUMN accessedid ";
|
948 |
$wpdb->query($sql);
|
949 |
$sql = "ALTER IGNORE TABLE " . $table_name_daily . " ADD PRIMARY KEY (postnumber, dp_date) ";
|
950 |
$wpdb->query($sql);
|
951 |
-
|
952 |
update_option( "tptn_db_version", $tptn_db_version );
|
953 |
}
|
954 |
|
@@ -958,13 +958,13 @@ register_activation_hook( __FILE__, 'tptn_activation_hook' );
|
|
958 |
|
959 |
/**
|
960 |
* Function to call install function if needed.
|
961 |
-
*
|
962 |
* @access public
|
963 |
* @return void
|
964 |
*/
|
965 |
function tptn_update_db_check() {
|
966 |
global $tptn_db_version;
|
967 |
-
|
968 |
if (get_site_option('tptn_db_version') != $tptn_db_version) {
|
969 |
tptn_activation_hook();
|
970 |
}
|
@@ -974,14 +974,14 @@ add_action( 'plugins_loaded', 'tptn_update_db_check' );
|
|
974 |
|
975 |
/**
|
976 |
* Function to delete all rows in the posts table.
|
977 |
-
*
|
978 |
* @access public
|
979 |
* @param bool $daily (default: false)
|
980 |
* @return void
|
981 |
*/
|
982 |
function tptn_trunc_count( $daily = false ) {
|
983 |
global $wpdb;
|
984 |
-
|
985 |
$table_name = $wpdb->prefix . "top_ten";
|
986 |
if ( $daily ) $table_name .= "_daily";
|
987 |
|
@@ -992,7 +992,7 @@ function tptn_trunc_count( $daily = false ) {
|
|
992 |
|
993 |
/**
|
994 |
* Filter function to resize post thumbnail. Filters out tp10_postimage.
|
995 |
-
*
|
996 |
* @access public
|
997 |
* @param string $postimage
|
998 |
* @param string|int $thumb_width
|
@@ -1003,9 +1003,9 @@ function tptn_trunc_count( $daily = false ) {
|
|
1003 |
*/
|
1004 |
function tptn_scale_thumbs( $postimage, $thumb_width, $thumb_height, $thumb_timthumb, $thumb_timthumb_q, $post ) {
|
1005 |
global $tptn_url;
|
1006 |
-
|
1007 |
if ( $thumb_timthumb ) {
|
1008 |
-
$new_pi = $tptn_url . '/timthumb/timthumb.php?src=' . urlencode( $postimage ) . '&w=' . $thumb_width . '&h=' . $thumb_height . '&zc=1&q=' . $thumb_timthumb_q;
|
1009 |
} else {
|
1010 |
$new_pi = $postimage;
|
1011 |
}
|
@@ -1016,7 +1016,7 @@ add_filter( 'tptn_postimage', 'tptn_scale_thumbs', 10, 6 );
|
|
1016 |
|
1017 |
/**
|
1018 |
* Function to get the post thumbnail.
|
1019 |
-
*
|
1020 |
* @access public
|
1021 |
* @param array $args (default: array()) Query string of options related to thumbnails
|
1022 |
* @return string
|
@@ -1024,7 +1024,7 @@ add_filter( 'tptn_postimage', 'tptn_scale_thumbs', 10, 6 );
|
|
1024 |
function tptn_get_the_post_thumbnail( $args = array() ) {
|
1025 |
|
1026 |
global $tptn_url;
|
1027 |
-
|
1028 |
$defaults = array(
|
1029 |
'postid' => '',
|
1030 |
'thumb_height' => '50', // Max height of thumbnails
|
@@ -1039,10 +1039,10 @@ function tptn_get_the_post_thumbnail( $args = array() ) {
|
|
1039 |
'class' => 'tptn_thumb', // Class of the thumbnail
|
1040 |
'filter' => 'tptn_postimage', // Class of the thumbnail
|
1041 |
);
|
1042 |
-
|
1043 |
// Parse incomming $args into an array and merge it with $defaults
|
1044 |
$args = wp_parse_args( $args, $defaults );
|
1045 |
-
|
1046 |
// OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
|
1047 |
extract( $args, EXTR_SKIP );
|
1048 |
|
@@ -1051,12 +1051,12 @@ function tptn_get_the_post_thumbnail( $args = array() ) {
|
|
1051 |
|
1052 |
$output = '';
|
1053 |
$thumb_html = ( 'css' == $thumb_html ) ? 'style="max-width:' . $thumb_width . 'px;max-height:' . $thumb_height . 'px;"' : 'width="' . $thumb_width . '" height="' .$thumb_height . '"';
|
1054 |
-
|
1055 |
if ( function_exists( 'has_post_thumbnail' ) && ( ( '' != wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ) ) ) || ( false != wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ) ) ) ) ) {
|
1056 |
$postimage = wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ) );
|
1057 |
-
|
1058 |
if ( ( $postimage[1] < $thumb_width ) || ( $postimage[2] < $thumb_height ) ) {
|
1059 |
-
$postimage = wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ) , 'full' );
|
1060 |
}
|
1061 |
$postimage = apply_filters( $filter, $postimage[0], $thumb_width, $thumb_height, $thumb_timthumb, $thumb_timthumb_q, $result );
|
1062 |
$output .= '<img src="' . $postimage . '" alt="' . $title . '" title="' . $title . '" ' . $thumb_html . ' border="0" class="' . $class . '" />';
|
@@ -1082,14 +1082,14 @@ function tptn_get_the_post_thumbnail( $args = array() ) {
|
|
1082 |
$output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" '.$thumb_html.' border="0" class="'.$class.'" />';
|
1083 |
}
|
1084 |
}
|
1085 |
-
|
1086 |
return apply_filters( 'tptn_get_the_post_thumbnail', $output );
|
1087 |
}
|
1088 |
|
1089 |
|
1090 |
/**
|
1091 |
* Get the first image in the post.
|
1092 |
-
*
|
1093 |
* @access public
|
1094 |
* @param mixed $postID Post ID
|
1095 |
* @return string
|
@@ -1120,7 +1120,7 @@ function tptn_get_first_image( $postID ) {
|
|
1120 |
|
1121 |
/**
|
1122 |
* Function to create an excerpt for the post.
|
1123 |
-
*
|
1124 |
* @access public
|
1125 |
* @param int $id Post ID
|
1126 |
* @param int|string $excerpt_length Length of the excerpt in words
|
@@ -1140,14 +1140,14 @@ function tptn_excerpt( $id, $excerpt_length = 0, $use_excerpt = true ) {
|
|
1140 |
if ( $excerpt_length > 0 ) {
|
1141 |
$output = wp_trim_words( $output, $excerpt_length );
|
1142 |
}
|
1143 |
-
|
1144 |
return apply_filters( 'tptn_excerpt', $output, $id, $excerpt_length, $use_excerpt );
|
1145 |
}
|
1146 |
|
1147 |
|
1148 |
/**
|
1149 |
* Function to limit content by characters.
|
1150 |
-
*
|
1151 |
* @access public
|
1152 |
* @param string $content Content to be used to make an excerpt
|
1153 |
* @param int $MaxLength (default: -1) Maximum length of excerpt in characters
|
@@ -1173,13 +1173,13 @@ function tptn_max_formatted_content( $content, $MaxLength = -1 ) {
|
|
1173 |
|
1174 |
/**
|
1175 |
* Function to truncate daily run.
|
1176 |
-
*
|
1177 |
* @access public
|
1178 |
* @return void
|
1179 |
*/
|
1180 |
function ald_tptn_cron() {
|
1181 |
global $tptn_settings, $wpdb;
|
1182 |
-
|
1183 |
$table_name_daily = $wpdb->prefix . "top_ten_daily";
|
1184 |
|
1185 |
$current_time = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
|
@@ -1187,17 +1187,17 @@ function ald_tptn_cron() {
|
|
1187 |
$current_date = date ( 'Y-m-j' , $current_date );
|
1188 |
|
1189 |
$resultscount = $wpdb->query( $wpdb->prepare(
|
1190 |
-
"DELETE FROM {$table_name_daily} WHERE dp_date <= '%s' ",
|
1191 |
-
$current_date
|
1192 |
) );
|
1193 |
-
|
1194 |
}
|
1195 |
add_action( 'ald_tptn_hook', 'ald_tptn_cron' );
|
1196 |
|
1197 |
|
1198 |
/**
|
1199 |
* Function to enable run or actions.
|
1200 |
-
*
|
1201 |
* @access public
|
1202 |
* @param int $hour
|
1203 |
* @param int $min
|
@@ -1219,7 +1219,7 @@ function tptn_enable_run( $hour, $min, $recurrence ) {
|
|
1219 |
|
1220 |
/**
|
1221 |
* Function to disable daily run or actions.
|
1222 |
-
*
|
1223 |
* @access public
|
1224 |
* @return void
|
1225 |
*/
|
@@ -1234,7 +1234,7 @@ function tptn_disable_run() {
|
|
1234 |
if ( ! function_exists( 'ald_more_reccurences' ) ) :
|
1235 |
/**
|
1236 |
* Function to add weekly and fortnightly recurrences - Sample Code courtesy http://blog.slaven.net.au/archives/2007/02/01/timing-is-everything-scheduling-in-wordpress/.
|
1237 |
-
*
|
1238 |
* @access public
|
1239 |
* @return void
|
1240 |
*/
|
@@ -1261,7 +1261,7 @@ endif;
|
|
1261 |
|
1262 |
/**
|
1263 |
* Creates a shortcode [tptn_list limit="5" heading="1" daily="0"].
|
1264 |
-
*
|
1265 |
* @access public
|
1266 |
* @param array $atts
|
1267 |
* @param string $content (default: null)
|
@@ -1269,7 +1269,7 @@ endif;
|
|
1269 |
*/
|
1270 |
function tptn_shortcode( $atts, $content = null ) {
|
1271 |
global $tptn_settings;
|
1272 |
-
|
1273 |
$atts = shortcode_atts( array_merge(
|
1274 |
$tptn_settings,
|
1275 |
array(
|
@@ -1286,7 +1286,7 @@ add_shortcode( 'tptn_list', 'tptn_shortcode' );
|
|
1286 |
|
1287 |
/**
|
1288 |
* Creates a shortcode [tptn_views daily="0"].
|
1289 |
-
*
|
1290 |
* @access public
|
1291 |
* @param array $atts
|
1292 |
* @param string $content (default: null)
|
@@ -1296,7 +1296,7 @@ function tptn_shortcode_views( $atts , $content=null ) {
|
|
1296 |
extract( shortcode_atts( array(
|
1297 |
'daily' => '0',
|
1298 |
), $atts ) );
|
1299 |
-
|
1300 |
return get_tptn_post_count_only( get_the_ID(), ( $daily ? 'daily' : 'total' ) );
|
1301 |
}
|
1302 |
add_shortcode( 'tptn_views', 'tptn_shortcode_views' );
|
@@ -1311,27 +1311,27 @@ if ( is_admin() || strstr( $_SERVER['PHP_SELF'], 'wp-admin/' ) ) {
|
|
1311 |
|
1312 |
/**
|
1313 |
* Adding WordPress plugin action links.
|
1314 |
-
*
|
1315 |
* @access public
|
1316 |
* @param mixed $links
|
1317 |
* @return void
|
1318 |
*/
|
1319 |
function tptn_plugin_actions_links( $links ) {
|
1320 |
-
|
1321 |
return array_merge(
|
1322 |
array(
|
1323 |
'settings' => '<a href="' . admin_url( 'options-general.php?page=tptn_options' ) . '">' . __( 'Settings', TPTN_LOCAL_NAME ) . '</a>'
|
1324 |
),
|
1325 |
$links
|
1326 |
);
|
1327 |
-
|
1328 |
}
|
1329 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'tptn_plugin_actions_links' );
|
1330 |
|
1331 |
|
1332 |
/**
|
1333 |
* Add meta links.
|
1334 |
-
*
|
1335 |
* @access public
|
1336 |
* @param mixed $links
|
1337 |
* @param mixed $file
|
@@ -1339,7 +1339,7 @@ if ( is_admin() || strstr( $_SERVER['PHP_SELF'], 'wp-admin/' ) ) {
|
|
1339 |
*/
|
1340 |
function tptn_plugin_actions( $links, $file ) {
|
1341 |
$plugin = plugin_basename( __FILE__ );
|
1342 |
-
|
1343 |
// create link
|
1344 |
if ( $file == $plugin ) {
|
1345 |
$links[] = '<a href="http://ajaydsouza.com/support/">' . __( 'Support', TPTN_LOCAL_NAME ) . '</a>';
|
@@ -1347,9 +1347,9 @@ if ( is_admin() || strstr( $_SERVER['PHP_SELF'], 'wp-admin/' ) ) {
|
|
1347 |
}
|
1348 |
return $links;
|
1349 |
}
|
1350 |
-
|
1351 |
global $wp_version;
|
1352 |
-
|
1353 |
if ( version_compare( $wp_version, '2.8alpha', '>' ) ) {
|
1354 |
add_filter( 'plugin_row_meta', 'tptn_plugin_actions', 10, 2 ); // only 2.8 and higher
|
1355 |
} else {
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Top 10
|
4 |
+
Version: 1.9.10.1
|
5 |
Plugin URI: http://ajaydsouza.com/wordpress/plugins/top-10/
|
6 |
Description: Count daily and total visits per post and display the most popular posts based on the number of views. Based on the plugin by <a href="http://weblogtoolscollection.com">Mark Ghosh</a>
|
7 |
Author: Ajay D'Souza
|
25 |
|
26 |
/**
|
27 |
* Function to load translation files.
|
28 |
+
*
|
29 |
* @access public
|
30 |
* @return void
|
31 |
*/
|
37 |
|
38 |
/**
|
39 |
* Filter for content to update post views.
|
40 |
+
*
|
41 |
* @access public
|
42 |
* @param string $content Post content
|
43 |
* @return string Filtered content
|
49 |
if ( is_singular() ) {
|
50 |
|
51 |
global $tptn_settings;
|
52 |
+
|
53 |
+
$current_user = wp_get_current_user();
|
54 |
$post_author = ( $current_user->ID == $post->post_author ) ? true : false; // Is the current user the post author?
|
55 |
$current_user_admin = ( current_user_can( 'manage_options' ) ) ? true : false; // Is the current user an admin?
|
56 |
$current_user_editor = ( ( current_user_can( 'edit_others_posts' ) ) && ( ! current_user_can( 'manage_options' ) ) ) ? true : false; // Is the current user pure editor?
|
57 |
+
|
58 |
$include_code = true;
|
59 |
if ( ( $post_author ) && ( ! $tptn_settings['track_authors'] ) ) $include_code = false;
|
60 |
if ( ( $current_user_admin ) && ( ! $tptn_settings['track_admins'] ) ) $include_code = false;
|
67 |
$activate_counter = $activate_counter + ( $tptn_settings['activate_daily'] ? 10 : 0 );
|
68 |
if ( $activate_counter > 0 ) {
|
69 |
if ( $tptn_settings['cache_fix'] ) {
|
70 |
+
$output = '<script type="text/javascript">jQuery.ajax({url: "' .$tptn_url. '/top-10-addcount.js.php", data: {top_ten_id: ' .$id. ', activate_counter: ' . $activate_counter . ', top10_rnd: (new Date()).getTime() + "-" + Math.floor(Math.random()*100000)}});</script>';
|
71 |
} else {
|
72 |
$output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-addcount.js.php?top_ten_id='.$id.'&activate_counter='.$activate_counter.'"></script>';
|
73 |
}
|
86 |
|
87 |
/**
|
88 |
* Enqueue Scripts.
|
89 |
+
*
|
90 |
* @access public
|
91 |
* @return void
|
92 |
*/
|
93 |
function tptn_enqueue_scripts() {
|
94 |
global $tptn_settings;
|
95 |
+
|
96 |
if ( $tptn_settings['cache_fix'] ) wp_enqueue_script( 'jquery' );
|
97 |
}
|
98 |
add_action( 'wp_enqueue_scripts', 'tptn_enqueue_scripts' ); // wp_enqueue_scripts action hook to link only on the front-end
|
100 |
|
101 |
/**
|
102 |
* Filter to add visited count to content.
|
103 |
+
*
|
104 |
* @access public
|
105 |
* @param string $content
|
106 |
* @return string
|
113 |
if ( in_array( $post->ID, $exclude_on_post_ids ) ) {
|
114 |
return $content; // Exit without adding related posts
|
115 |
}
|
116 |
+
|
117 |
if ( ( is_single() ) && ( $tptn_settings['add_to_content'] ) ) {
|
118 |
return $content.echo_tptn_post_count(0);
|
119 |
} elseif ( ( is_page() ) && ( $tptn_settings['count_on_pages'] ) ) {
|
135 |
|
136 |
/**
|
137 |
* Filter to add related posts to feeds.
|
138 |
+
*
|
139 |
* @access public
|
140 |
* @param string $content
|
141 |
* @return string
|
157 |
|
158 |
/**
|
159 |
* Function to manually display count.
|
160 |
+
*
|
161 |
* @access public
|
162 |
* @param int|boolean $echo (default: 1)
|
163 |
* @return string
|
164 |
*/
|
165 |
function echo_tptn_post_count( $echo = 1 ) {
|
166 |
global $post, $tptn_url, $tptn_path, $tptn_settings;
|
167 |
+
|
168 |
$id = intval( $post->ID );
|
169 |
+
|
170 |
$nonce_action = 'tptn-nonce-' . $id ;
|
171 |
$nonce = wp_create_nonce( $nonce_action );
|
172 |
|
175 |
} else {
|
176 |
$output = '<div class="tptn_counter" id="tptn_counter_' . $id . '">' . get_tptn_post_count( $id ) . '</div>';
|
177 |
}
|
178 |
+
|
179 |
if ( $echo ) {
|
180 |
echo $output;
|
181 |
} else {
|
186 |
|
187 |
/**
|
188 |
* Return the formatted post count for the supplied ID.
|
189 |
+
*
|
190 |
* @access public
|
191 |
* @param int|string $id Post ID
|
192 |
* @return int|string Formatted post count
|
193 |
*/
|
194 |
function get_tptn_post_count( $id = FALSE ) {
|
195 |
global $wpdb, $tptn_settings;
|
196 |
+
|
197 |
$table_name = $wpdb->prefix . "top_ten";
|
198 |
$table_name_daily = $wpdb->prefix . "top_ten_daily";
|
199 |
|
200 |
$count_disp_form = stripslashes( $tptn_settings['count_disp_form'] );
|
201 |
$count_disp_form_zero = stripslashes( $tptn_settings['count_disp_form_zero'] );
|
202 |
$totalcntaccess = get_tptn_post_count_only( $id, 'total' );
|
203 |
+
|
204 |
if ( $id > 0 ) {
|
205 |
|
206 |
// Total count per post
|
211 |
$count_disp_form = str_replace( "%totalcount%", ( 0 == $totalcntaccess ? $totalcntaccess + 1 : $totalcntaccess ), $count_disp_form );
|
212 |
}
|
213 |
}
|
214 |
+
|
215 |
// Now process daily count
|
216 |
if ( ( false !== strpos( $count_disp_form, "%dailycount%" ) ) || ( false !== strpos( $count_disp_form_zero, "%dailycount%" ) ) ) {
|
217 |
$cntaccess = get_tptn_post_count_only( $id, 'daily' );
|
221 |
$count_disp_form = str_replace( "%dailycount%", ( 0 == $cntaccess ? $cntaccess + 1 : $cntaccess ), $count_disp_form );
|
222 |
}
|
223 |
}
|
224 |
+
|
225 |
// Now process overall count
|
226 |
if ( ( false !== strpos( $count_disp_form, "%overallcount%" ) ) || ( false !== strpos( $count_disp_form_zero, "%overallcount%" ) ) ) {
|
227 |
$cntaccess = get_tptn_post_count_only( $id, 'overall' );
|
231 |
$count_disp_form = str_replace( "%overallcount%", ( 0 == $cntaccess ? $cntaccess + 1 : $cntaccess ), $count_disp_form );
|
232 |
}
|
233 |
}
|
234 |
+
|
235 |
if ( ( 0 == $totalcntaccess ) && ( ! is_singular() ) ) {
|
236 |
return apply_filters( 'tptn_post_count', $count_disp_form_zero );
|
237 |
} else {
|
245 |
|
246 |
/**
|
247 |
* Returns the post count.
|
248 |
+
*
|
249 |
* @access public
|
250 |
* @param mixed $id (default: FALSE) Post ID
|
251 |
* @param string $count (default: 'total') Which count to return? total, daily or overall
|
253 |
*/
|
254 |
function get_tptn_post_count_only( $id = FALSE, $count = 'total' ) {
|
255 |
global $wpdb;
|
256 |
+
|
257 |
$table_name = $wpdb->prefix . "top_ten";
|
258 |
$table_name_daily = $wpdb->prefix . "top_ten_daily";
|
259 |
global $tptn_settings;
|
260 |
+
|
261 |
if($id > 0) {
|
262 |
switch ($count) {
|
263 |
case 'total':
|
269 |
$current_time = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
|
270 |
$current_date = strtotime ( '-'.$daily_range. ' DAY' , strtotime ( $current_time ) );
|
271 |
$current_date = date ( 'Y-m-j' , $current_date );
|
272 |
+
|
273 |
$resultscount = $wpdb->get_row( $wpdb->prepare( "SELECT postnumber, SUM(cntaccess) as sumCount FROM {$table_name_daily} WHERE postnumber = %d AND dp_date >= '%s' GROUP BY postnumber ", array($id, $current_date) ) );
|
274 |
$cntaccess = number_format_i18n((($resultscount) ? $resultscount->sumCount : 0));
|
275 |
break;
|
286 |
|
287 |
/**
|
288 |
* Function to return popular posts.
|
289 |
+
*
|
290 |
* @access public
|
291 |
* @param mixed $args
|
292 |
* @return array|string Array of posts if posts_only = 0 or a formatted string if posts_only = 1
|
293 |
*/
|
294 |
function tptn_pop_posts( $args ) {
|
295 |
global $wpdb, $siteurl, $tableposts, $id, $tptn_settings;
|
296 |
+
|
297 |
$defaults = array(
|
298 |
'is_widget' => FALSE,
|
299 |
'daily' => FALSE,
|
304 |
'heading' => 1,
|
305 |
);
|
306 |
$defaults = array_merge( $defaults, $tptn_settings );
|
307 |
+
|
308 |
// Parse incomming $args into an array and merge it with $defaults
|
309 |
$args = wp_parse_args( $args, $defaults );
|
310 |
+
|
311 |
// OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
|
312 |
extract( $args, EXTR_SKIP );
|
313 |
|
314 |
if ($daily) {
|
315 |
+
$table_name = $wpdb->prefix . "top_ten_daily";
|
316 |
} else {
|
317 |
$table_name = $wpdb->prefix . "top_ten";
|
318 |
}
|
319 |
+
|
320 |
+
$limit = ( $strict_limit ) ? $limit : ( $limit * 5 );
|
321 |
|
322 |
$exclude_categories = explode( ',', $exclude_categories );
|
323 |
|
324 |
$target_attribute = ( $link_new_window ) ? ' target="_blank" ' : ' '; // Set Target attribute
|
325 |
$rel_attribute = ( $link_nofollow ) ? ' nofollow' : ''; // Set nofollow attribute
|
326 |
+
|
327 |
parse_str( $post_types, $post_types ); // Save post types in $post_types variable
|
328 |
|
329 |
if ( ! $daily ) {
|
331 |
$sql = "SELECT postnumber, cntaccess as sumCount, ID, post_type, post_status ";
|
332 |
$sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
333 |
$sql .= "AND post_status = 'publish' ";
|
334 |
+
if ( '' != $exclude_post_ids ) {
|
335 |
$sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
|
336 |
}
|
337 |
$sql .= "AND ( ";
|
349 |
$current_time = current_time( 'timestamp', 0 );
|
350 |
$current_time = $current_time - ( $daily_range - 1 ) * 3600 * 24;
|
351 |
$current_date = date( 'Y-m-j', $current_time );
|
352 |
+
|
353 |
$args = array(
|
354 |
$current_date,
|
355 |
);
|
356 |
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
|
357 |
$sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
358 |
$sql .= "AND post_status = 'publish' AND dp_date >= '%s' ";
|
359 |
+
if ( '' != $exclude_post_ids ) {
|
360 |
$sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
|
361 |
}
|
362 |
$sql .= "AND ( ";
|
372 |
$sql .= "ORDER BY sumCount DESC LIMIT %d";
|
373 |
$args[] = $limit;
|
374 |
}
|
375 |
+
|
376 |
if ( $posts_only ) { // Return the array of posts only if the variable is set
|
377 |
return apply_filters( 'tptn_pop_posts_array', $wpdb->get_results( $wpdb->prepare( $sql , $args ) , ARRAY_A ) );
|
378 |
}
|
379 |
+
|
380 |
$results = $wpdb->get_results( $wpdb->prepare( $sql , $args ) );
|
381 |
+
|
382 |
$counter = 0;
|
383 |
|
384 |
$output = '';
|
385 |
+
|
386 |
$shortcode_class = $is_shortcode ? ' tptn_posts_shortcode' : '';
|
387 |
$widget_class = $is_widget ? ' tptn_posts_widget' : '';
|
388 |
|
399 |
$output .= '<div class="tptn_posts_daily' . $widget_class . $shortcode_class . '">';
|
400 |
}
|
401 |
}
|
402 |
+
|
403 |
if ( $results ) {
|
404 |
$output .= apply_filters( 'tptn_before_list', $before_list );
|
405 |
foreach ( $results as $result ) {
|
426 |
}
|
427 |
if ( 'inline' == $post_thumb_op || 'after' == $post_thumb_op || 'thumbs_only' == $post_thumb_op ) {
|
428 |
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
|
429 |
+
$output .= tptn_get_the_post_thumbnail( array(
|
430 |
'postid' => $result->ID,
|
431 |
'thumb_height' => $thumb_height,
|
432 |
'thumb_width' => $thumb_width,
|
438 |
'thumb_timthumb_q' => $thumb_timthumb_q,
|
439 |
'scan_images' => $scan_images,
|
440 |
'class' => "tptn_thumb",
|
441 |
+
'filter' => "tptn_postimage",
|
442 |
) );
|
443 |
$output .= '</a>'; // Close the link
|
444 |
}
|
452 |
$author_info = get_userdata( $result->post_author );
|
453 |
$author_name = ucwords( trim( stripslashes( $author_info->display_name ) ) );
|
454 |
$author_link = get_author_posts_url( $author_info->ID );
|
455 |
+
|
456 |
$output .= '<span class="tptn_author"> ' . __( ' by ', TPTN_LOCAL_NAME ).'<a href="' . $author_link . '">' . $author_name . '</a></span> ';
|
457 |
}
|
458 |
if ( $show_date ) {
|
462 |
$output .= '<span class="tptn_excerpt"> ' . tptn_excerpt( $result->ID, $excerpt_length ).'</span>';
|
463 |
}
|
464 |
if ( $disp_list_count ) $output .= ' <span class="tptn_list_count">(' . number_format_i18n( $sumcount ) . ')</span>';
|
465 |
+
|
466 |
if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
|
467 |
$output .= '</span>';
|
468 |
}
|
469 |
+
|
470 |
$output .= apply_filters( 'tptn_after_list_item', $after_list_item, $result->ID );
|
471 |
+
$counter++;
|
472 |
}
|
473 |
if ( $counter == $limit/5 ) break; // End loop when related posts limit is reached
|
474 |
}
|
489 |
|
490 |
/**
|
491 |
* Function to echo popular posts.
|
492 |
+
*
|
493 |
* @access public
|
494 |
* @return void
|
495 |
*/
|
500 |
|
501 |
/**
|
502 |
* Function to show daily popular posts.
|
503 |
+
*
|
504 |
* @access public
|
505 |
* @return void
|
506 |
*/
|
507 |
function tptn_show_daily_pop_posts() {
|
508 |
global $tptn_url, $tptn_settings;
|
509 |
+
|
510 |
if ( $tptn_settings['d_use_js'] ) {
|
511 |
echo '<script type="text/javascript" src="' . $tptn_url . '/top-10-daily.js.php?widget=1"></script>';
|
512 |
} else {
|
517 |
|
518 |
/**
|
519 |
* Function to add CSS to header.
|
520 |
+
*
|
521 |
* @access public
|
522 |
* @return void
|
523 |
*/
|
524 |
function tptn_header() {
|
525 |
global $wpdb, $post, $single, $tptn_settings;
|
526 |
+
|
527 |
$tptn_custom_CSS = stripslashes( $tptn_settings['custom_CSS'] );
|
528 |
+
|
529 |
+
// Add CSS to header
|
530 |
if ( '' != $tptn_custom_CSS ) {
|
531 |
echo '<style type="text/css">' . $tptn_custom_CSS . '</style>';
|
532 |
}
|
533 |
}
|
534 |
add_action('wp_head','tptn_header');
|
535 |
|
536 |
+
|
537 |
/**
|
538 |
* Top 10 Widget.
|
539 |
+
*
|
540 |
* @extends WP_Widget
|
541 |
*/
|
542 |
class Top_Ten_Widget extends WP_Widget {
|
574 |
?>
|
575 |
<p>
|
576 |
<label for="<?php echo $this->get_field_id( 'title' ); ?>">
|
577 |
+
<?php _e( 'Title', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
|
578 |
</label>
|
579 |
</p>
|
580 |
<p>
|
581 |
<label for="<?php echo $this->get_field_id( 'limit' ); ?>">
|
582 |
+
<?php _e( 'No. of posts', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" />
|
583 |
</label>
|
584 |
</p>
|
585 |
<p>
|
590 |
</p>
|
591 |
<p>
|
592 |
<label for="<?php echo $this->get_field_id( 'daily_range' ); ?>">
|
593 |
+
<?php _e( 'Range in number of days (applies only to custom option above)', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'daily_range' ); ?>" name="<?php echo $this->get_field_name( 'daily_range' ); ?>" type="text" value="<?php echo esc_attr( $daily_range ); ?>" />
|
594 |
</label>
|
595 |
</p>
|
596 |
<p>
|
624 |
</p>
|
625 |
<p>
|
626 |
<label for="<?php echo $this->get_field_id( 'thumb_height' ); ?>">
|
627 |
+
<?php _e( 'Thumbnail height', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'thumb_height' ); ?>" name="<?php echo $this->get_field_name( 'thumb_height' ); ?>" type="text" value="<?php echo esc_attr($thumb_height); ?>" />
|
628 |
</label>
|
629 |
</p>
|
630 |
<p>
|
631 |
<label for="<?php echo $this->get_field_id( 'thumb_width' ); ?>">
|
632 |
+
<?php _e( 'Thumbnail width', TPTN_LOCAL_NAME ); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'thumb_width' ); ?>" name="<?php echo $this->get_field_name( 'thumb_width' ); ?>" type="text" value="<?php echo esc_attr( $thumb_width ); ?>" />
|
633 |
</label>
|
634 |
</p>
|
635 |
<?php
|
671 |
*/
|
672 |
function widget( $args, $instance ) {
|
673 |
global $wpdb, $tptn_url, $tptn_settings;
|
674 |
+
|
675 |
extract( $args, EXTR_SKIP );
|
676 |
+
|
677 |
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? strip_tags( $tptn_settings['title'] ) : $instance['title'] );
|
678 |
$limit = $instance['limit'];
|
679 |
if ( empty( $limit ) ) {
|
724 |
}
|
725 |
|
726 |
$output .= $after_widget;
|
727 |
+
|
728 |
echo $output;
|
729 |
|
730 |
} //ending function widget
|
733 |
|
734 |
/**
|
735 |
* Initialise the widget.
|
736 |
+
*
|
737 |
* @access public
|
738 |
* @return void
|
739 |
*/
|
740 |
function tptn_register_widget() {
|
741 |
register_widget( 'Top_Ten_Widget' );
|
742 |
}
|
743 |
+
add_action( 'widgets_init', 'tptn_register_widget', 1 );
|
744 |
|
745 |
|
746 |
/**
|
747 |
* Enqueue styles.
|
748 |
+
*
|
749 |
* @access public
|
750 |
* @return void
|
751 |
*/
|
752 |
function tptn_heading_styles() {
|
753 |
global $tptn_settings;
|
754 |
+
|
755 |
if ( $tptn_settings['include_default_style'] ) {
|
756 |
wp_register_style( 'tptn_list_style', plugins_url( 'css/default-style.css', __FILE__ ) );
|
757 |
wp_enqueue_style( 'tptn_list_style' );
|
758 |
}
|
759 |
}
|
760 |
+
add_action( 'wp_enqueue_scripts', 'tptn_heading_styles' );
|
761 |
|
762 |
|
763 |
/**
|
764 |
* Default Options.
|
765 |
+
*
|
766 |
* @access public
|
767 |
* @return void
|
768 |
*/
|
769 |
function tptn_default_options() {
|
770 |
global $tptn_url;
|
771 |
+
|
772 |
$title = __( '<h3>Popular Posts</h3>', TPTN_LOCAL_NAME );
|
773 |
$title_daily = __( '<h3>Daily Popular</h3>', TPTN_LOCAL_NAME );
|
774 |
$blank_output_text = __( 'No top posts yet', TPTN_LOCAL_NAME );
|
796 |
'track_editors' => true, // Track Admin visits
|
797 |
'pv_in_admin' => true, // Add an extra column on edit posts/pages to display page views?
|
798 |
'show_count_non_admins' => true, // Show counts to non-admins
|
799 |
+
|
800 |
'blank_output' => false, // Blank output? Default is "blank Output test"
|
801 |
'blank_output_text' => $blank_output_text, // Blank output text
|
802 |
'disp_list_count' => true, // Display count in popular lists?
|
858 |
|
859 |
/**
|
860 |
* Function to read options from the database.
|
861 |
+
*
|
862 |
* @access public
|
863 |
* @return void
|
864 |
*/
|
869 |
$installed_ver = get_option( "tptn_db_version" );
|
870 |
|
871 |
if ( $installed_ver != $tptn_db_version ) {
|
872 |
+
tptn_activation_hook();
|
873 |
}
|
874 |
|
875 |
$tptn_settings_changed = false;
|
876 |
+
|
877 |
$defaults = tptn_default_options();
|
878 |
+
|
879 |
$tptn_settings = array_map( 'stripslashes', (array)get_option( 'ald_tptn_settings' ) );
|
880 |
unset( $tptn_settings[0] ); // produced by the (array) casting when there's nothing in the DB
|
881 |
+
|
882 |
foreach ( $defaults as $k=>$v ) {
|
883 |
if ( ! isset( $tptn_settings[$k] ) ) {
|
884 |
$tptn_settings[$k] = $v;
|
888 |
if ( $tptn_settings_changed == true ) {
|
889 |
update_option('ald_tptn_settings', $tptn_settings);
|
890 |
}
|
891 |
+
|
892 |
return apply_filters( 'tptn_read_options', $tptn_settings );
|
893 |
}
|
894 |
|
895 |
|
896 |
/**
|
897 |
* Create tables to store pageviews.
|
898 |
+
*
|
899 |
* @access public
|
900 |
* @return void
|
901 |
*/
|
904 |
|
905 |
$table_name = $wpdb->prefix . "top_ten";
|
906 |
$table_name_daily = $wpdb->prefix . "top_ten_daily";
|
907 |
+
|
908 |
if ( $wpdb->get_var( "show tables like '$table_name'" ) != $table_name ) {
|
909 |
|
910 |
$sql = "CREATE TABLE " . $table_name . " (
|
912 |
cntaccess int NOT NULL,
|
913 |
PRIMARY KEY (postnumber)
|
914 |
);";
|
915 |
+
|
916 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
917 |
dbDelta( $sql );
|
918 |
+
|
919 |
add_option( "tptn_db_version", $tptn_db_version );
|
920 |
}
|
921 |
|
922 |
if($wpdb->get_var("show tables like '$table_name_daily'") != $table_name_daily) {
|
923 |
+
|
924 |
$sql = "CREATE TABLE " . $table_name_daily . " (
|
925 |
postnumber int NOT NULL,
|
926 |
cntaccess int NOT NULL,
|
927 |
dp_date date NOT NULL,
|
928 |
PRIMARY KEY (postnumber, dp_date)
|
929 |
);";
|
930 |
+
|
931 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
932 |
dbDelta($sql);
|
933 |
+
|
934 |
add_option("tptn_db_version", $tptn_db_version);
|
935 |
}
|
936 |
|
943 |
$wpdb->query($sql);
|
944 |
$sql = "ALTER IGNORE TABLE " . $table_name . " ADD PRIMARY KEY (postnumber) ";
|
945 |
$wpdb->query($sql);
|
946 |
+
|
947 |
$sql = "ALTER TABLE " . $table_name_daily . " DROP COLUMN accessedid ";
|
948 |
$wpdb->query($sql);
|
949 |
$sql = "ALTER IGNORE TABLE " . $table_name_daily . " ADD PRIMARY KEY (postnumber, dp_date) ";
|
950 |
$wpdb->query($sql);
|
951 |
+
|
952 |
update_option( "tptn_db_version", $tptn_db_version );
|
953 |
}
|
954 |
|
958 |
|
959 |
/**
|
960 |
* Function to call install function if needed.
|
961 |
+
*
|
962 |
* @access public
|
963 |
* @return void
|
964 |
*/
|
965 |
function tptn_update_db_check() {
|
966 |
global $tptn_db_version;
|
967 |
+
|
968 |
if (get_site_option('tptn_db_version') != $tptn_db_version) {
|
969 |
tptn_activation_hook();
|
970 |
}
|
974 |
|
975 |
/**
|
976 |
* Function to delete all rows in the posts table.
|
977 |
+
*
|
978 |
* @access public
|
979 |
* @param bool $daily (default: false)
|
980 |
* @return void
|
981 |
*/
|
982 |
function tptn_trunc_count( $daily = false ) {
|
983 |
global $wpdb;
|
984 |
+
|
985 |
$table_name = $wpdb->prefix . "top_ten";
|
986 |
if ( $daily ) $table_name .= "_daily";
|
987 |
|
992 |
|
993 |
/**
|
994 |
* Filter function to resize post thumbnail. Filters out tp10_postimage.
|
995 |
+
*
|
996 |
* @access public
|
997 |
* @param string $postimage
|
998 |
* @param string|int $thumb_width
|
1003 |
*/
|
1004 |
function tptn_scale_thumbs( $postimage, $thumb_width, $thumb_height, $thumb_timthumb, $thumb_timthumb_q, $post ) {
|
1005 |
global $tptn_url;
|
1006 |
+
|
1007 |
if ( $thumb_timthumb ) {
|
1008 |
+
$new_pi = $tptn_url . '/timthumb/timthumb.php?src=' . urlencode( $postimage ) . '&w=' . $thumb_width . '&h=' . $thumb_height . '&zc=1&q=' . $thumb_timthumb_q;
|
1009 |
} else {
|
1010 |
$new_pi = $postimage;
|
1011 |
}
|
1016 |
|
1017 |
/**
|
1018 |
* Function to get the post thumbnail.
|
1019 |
+
*
|
1020 |
* @access public
|
1021 |
* @param array $args (default: array()) Query string of options related to thumbnails
|
1022 |
* @return string
|
1024 |
function tptn_get_the_post_thumbnail( $args = array() ) {
|
1025 |
|
1026 |
global $tptn_url;
|
1027 |
+
|
1028 |
$defaults = array(
|
1029 |
'postid' => '',
|
1030 |
'thumb_height' => '50', // Max height of thumbnails
|
1039 |
'class' => 'tptn_thumb', // Class of the thumbnail
|
1040 |
'filter' => 'tptn_postimage', // Class of the thumbnail
|
1041 |
);
|
1042 |
+
|
1043 |
// Parse incomming $args into an array and merge it with $defaults
|
1044 |
$args = wp_parse_args( $args, $defaults );
|
1045 |
+
|
1046 |
// OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
|
1047 |
extract( $args, EXTR_SKIP );
|
1048 |
|
1051 |
|
1052 |
$output = '';
|
1053 |
$thumb_html = ( 'css' == $thumb_html ) ? 'style="max-width:' . $thumb_width . 'px;max-height:' . $thumb_height . 'px;"' : 'width="' . $thumb_width . '" height="' .$thumb_height . '"';
|
1054 |
+
|
1055 |
if ( function_exists( 'has_post_thumbnail' ) && ( ( '' != wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ) ) ) || ( false != wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ) ) ) ) ) {
|
1056 |
$postimage = wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ) );
|
1057 |
+
|
1058 |
if ( ( $postimage[1] < $thumb_width ) || ( $postimage[2] < $thumb_height ) ) {
|
1059 |
+
$postimage = wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ) , 'full' );
|
1060 |
}
|
1061 |
$postimage = apply_filters( $filter, $postimage[0], $thumb_width, $thumb_height, $thumb_timthumb, $thumb_timthumb_q, $result );
|
1062 |
$output .= '<img src="' . $postimage . '" alt="' . $title . '" title="' . $title . '" ' . $thumb_html . ' border="0" class="' . $class . '" />';
|
1082 |
$output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" '.$thumb_html.' border="0" class="'.$class.'" />';
|
1083 |
}
|
1084 |
}
|
1085 |
+
|
1086 |
return apply_filters( 'tptn_get_the_post_thumbnail', $output );
|
1087 |
}
|
1088 |
|
1089 |
|
1090 |
/**
|
1091 |
* Get the first image in the post.
|
1092 |
+
*
|
1093 |
* @access public
|
1094 |
* @param mixed $postID Post ID
|
1095 |
* @return string
|
1120 |
|
1121 |
/**
|
1122 |
* Function to create an excerpt for the post.
|
1123 |
+
*
|
1124 |
* @access public
|
1125 |
* @param int $id Post ID
|
1126 |
* @param int|string $excerpt_length Length of the excerpt in words
|
1140 |
if ( $excerpt_length > 0 ) {
|
1141 |
$output = wp_trim_words( $output, $excerpt_length );
|
1142 |
}
|
1143 |
+
|
1144 |
return apply_filters( 'tptn_excerpt', $output, $id, $excerpt_length, $use_excerpt );
|
1145 |
}
|
1146 |
|
1147 |
|
1148 |
/**
|
1149 |
* Function to limit content by characters.
|
1150 |
+
*
|
1151 |
* @access public
|
1152 |
* @param string $content Content to be used to make an excerpt
|
1153 |
* @param int $MaxLength (default: -1) Maximum length of excerpt in characters
|
1173 |
|
1174 |
/**
|
1175 |
* Function to truncate daily run.
|
1176 |
+
*
|
1177 |
* @access public
|
1178 |
* @return void
|
1179 |
*/
|
1180 |
function ald_tptn_cron() {
|
1181 |
global $tptn_settings, $wpdb;
|
1182 |
+
|
1183 |
$table_name_daily = $wpdb->prefix . "top_ten_daily";
|
1184 |
|
1185 |
$current_time = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
|
1187 |
$current_date = date ( 'Y-m-j' , $current_date );
|
1188 |
|
1189 |
$resultscount = $wpdb->query( $wpdb->prepare(
|
1190 |
+
"DELETE FROM {$table_name_daily} WHERE dp_date <= '%s' ",
|
1191 |
+
$current_date
|
1192 |
) );
|
1193 |
+
|
1194 |
}
|
1195 |
add_action( 'ald_tptn_hook', 'ald_tptn_cron' );
|
1196 |
|
1197 |
|
1198 |
/**
|
1199 |
* Function to enable run or actions.
|
1200 |
+
*
|
1201 |
* @access public
|
1202 |
* @param int $hour
|
1203 |
* @param int $min
|
1219 |
|
1220 |
/**
|
1221 |
* Function to disable daily run or actions.
|
1222 |
+
*
|
1223 |
* @access public
|
1224 |
* @return void
|
1225 |
*/
|
1234 |
if ( ! function_exists( 'ald_more_reccurences' ) ) :
|
1235 |
/**
|
1236 |
* Function to add weekly and fortnightly recurrences - Sample Code courtesy http://blog.slaven.net.au/archives/2007/02/01/timing-is-everything-scheduling-in-wordpress/.
|
1237 |
+
*
|
1238 |
* @access public
|
1239 |
* @return void
|
1240 |
*/
|
1261 |
|
1262 |
/**
|
1263 |
* Creates a shortcode [tptn_list limit="5" heading="1" daily="0"].
|
1264 |
+
*
|
1265 |
* @access public
|
1266 |
* @param array $atts
|
1267 |
* @param string $content (default: null)
|
1269 |
*/
|
1270 |
function tptn_shortcode( $atts, $content = null ) {
|
1271 |
global $tptn_settings;
|
1272 |
+
|
1273 |
$atts = shortcode_atts( array_merge(
|
1274 |
$tptn_settings,
|
1275 |
array(
|
1286 |
|
1287 |
/**
|
1288 |
* Creates a shortcode [tptn_views daily="0"].
|
1289 |
+
*
|
1290 |
* @access public
|
1291 |
* @param array $atts
|
1292 |
* @param string $content (default: null)
|
1296 |
extract( shortcode_atts( array(
|
1297 |
'daily' => '0',
|
1298 |
), $atts ) );
|
1299 |
+
|
1300 |
return get_tptn_post_count_only( get_the_ID(), ( $daily ? 'daily' : 'total' ) );
|
1301 |
}
|
1302 |
add_shortcode( 'tptn_views', 'tptn_shortcode_views' );
|
1311 |
|
1312 |
/**
|
1313 |
* Adding WordPress plugin action links.
|
1314 |
+
*
|
1315 |
* @access public
|
1316 |
* @param mixed $links
|
1317 |
* @return void
|
1318 |
*/
|
1319 |
function tptn_plugin_actions_links( $links ) {
|
1320 |
+
|
1321 |
return array_merge(
|
1322 |
array(
|
1323 |
'settings' => '<a href="' . admin_url( 'options-general.php?page=tptn_options' ) . '">' . __( 'Settings', TPTN_LOCAL_NAME ) . '</a>'
|
1324 |
),
|
1325 |
$links
|
1326 |
);
|
1327 |
+
|
1328 |
}
|
1329 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'tptn_plugin_actions_links' );
|
1330 |
|
1331 |
|
1332 |
/**
|
1333 |
* Add meta links.
|
1334 |
+
*
|
1335 |
* @access public
|
1336 |
* @param mixed $links
|
1337 |
* @param mixed $file
|
1339 |
*/
|
1340 |
function tptn_plugin_actions( $links, $file ) {
|
1341 |
$plugin = plugin_basename( __FILE__ );
|
1342 |
+
|
1343 |
// create link
|
1344 |
if ( $file == $plugin ) {
|
1345 |
$links[] = '<a href="http://ajaydsouza.com/support/">' . __( 'Support', TPTN_LOCAL_NAME ) . '</a>';
|
1347 |
}
|
1348 |
return $links;
|
1349 |
}
|
1350 |
+
|
1351 |
global $wp_version;
|
1352 |
+
|
1353 |
if ( version_compare( $wp_version, '2.8alpha', '>' ) ) {
|
1354 |
add_filter( 'plugin_row_meta', 'tptn_plugin_actions', 10, 2 ); // only 2.8 and higher
|
1355 |
} else {
|