Changeset 716369
- Timestamp:
- 05/22/2013 03:22:45 AM (13 years ago)
- Location:
- jetpack-post-views
- Files:
-
- 1 added
- 2 edited
-
assets/banner-772×250.png (added)
-
trunk/jetpack-post-views.php (modified) (14 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
jetpack-post-views/trunk/jetpack-post-views.php
r681931 r716369 6 6 * Description: Adds a widget that displays your most popular posts using Jetpack stats. <strong>NOTE:</strong> If the plugin does not work, visit the <a href="options-general.php?page=jetpack_post_views">Settings</a> page to enter a WordPress API Key. 7 7 * Author: Steven Lambert 8 * Version: 1.0. 48 * Version: 1.0.5 9 9 * Author URI: http://sklambert.com 10 10 * License: GPL2+ … … 13 13 // Define plugin version 14 14 if ( !defined( 'JETPACK_POST_VIEWS_VERSION_NUM' ) ) { 15 define( 'JETPACK_POST_VIEWS_VERSION_NUM', '1.0. 4' );15 define( 'JETPACK_POST_VIEWS_VERSION_NUM', '1.0.5' ); 16 16 } 17 17 … … 34 34 // Admin hooks 35 35 add_action( 'admin_init', array( &$this, 'register_setting' ) ); 36 add_action( 'admin_menu', array( &$this, 'register_settings_page' ) ); 37 add_filter( 'plugin_action_links', array( &$this, 'settings_link' ), 10, 2 ); 36 add_action( 'admin_menu', array( &$this, 'register_settings_page' ) ); 37 add_filter( 'plugin_action_links', array( &$this, 'settings_link' ), 10, 2 ); 38 38 39 39 // Shecudled hooks 40 40 add_action( 'jetpack_post_views_scheduled_update', array( &$this, 'get_post_views' ) ); 41 41 42 // Post hooks 43 add_action( 'publish_post', array( &$this, 'add_jetpack_meta' ) ); 44 42 45 // Query the database for the blog_id 43 46 global $wpdb; 44 $stats_options = $wpdb->get_var( "SELECT option_value 45 FROM wp_options 47 $options_table = $wpdb->base_prefix."options"; 48 $stats_options = $wpdb->get_var( "SELECT option_value 49 FROM $options_table 46 50 WHERE option_name = 'stats_options'" ); 47 51 $stats = unserialize($stats_options); … … 54 58 55 59 // Try another possiblility to get the blog_id 56 $jetpack_options = $wpdb->get_var( "SELECT option_value 57 FROM wp_options60 $jetpack_options = $wpdb->get_var( "SELECT option_value 61 FROM $options_table 58 62 WHERE option_name = 'jetpack_options'" ); 59 63 $jetpack = unserialize($jetpack_options); … … 62 66 $this->blog_id = $jetpack['id']; 63 67 } 64 else { // Jetpack stats really una bailable68 else { // Jetpack stats really unavailable 65 69 $this->blog_id = -1; 66 70 } … … 107 111 function register_setting() { 108 112 register_setting( 'jetpack_post_views_settings', 'jetpack_post_views_settings', array( &$this, 'validate_settings' ) ); 113 } 114 115 116 /* ADD JETPACK POST META ON POST PUBLISH */ 117 function add_jetpack_meta() { 118 global $post; 119 add_post_meta( $post->ID, 'jetpack-post-views', 0, true ); 109 120 } 110 121 … … 348 359 <li><a href="<?php echo get_permalink( $post['post_id'] ) ?>"><?php echo get_the_title( $post['post_id'] ) ?></a> 349 360 <?php if ( $instance['show_views'] ) { 350 echo " - ".number_format_i18n( $post['views'] )." views";361 echo " - ".number_format_i18n( $post['views'] ? $post['views'] : 0 )." views"; 351 362 } ?> 352 363 </li> … … 513 524 foreach( $allposts as $post) { 514 525 // Ensure that the $post-ID exists as a key in the array before trying to update post information. 515 // This prevents the u ersfrom pulling data from another website and trying to add it to their own526 // This prevents the user from pulling data from another website and trying to add it to their own 516 527 // posts. 517 528 if ( array_key_exists( $post->ID, $postdata) ) { … … 525 536 } 526 537 else { 527 add_post_meta( $post->ID, 'jetpack-post-views', $newViews, true );538 add_post_meta( $post->ID, 'jetpack-post-views', ($newViews ? $newViews: 0), true ); 528 539 } 540 } 541 else { 542 add_post_meta( $post->ID, 'jetpack-post-views', 0, true ); 529 543 } 530 544 } … … 534 548 /* UPGRADE PLUGIN TO NEW VERSION */ 535 549 function upgrade() { 550 global $post; 551 536 552 // Delete old options 537 553 delete_option( 'jetpack-post-views_version' ); … … 539 555 delete_option( 'jetpack_post_views_stats_has_run' ); 540 556 541 define( 'JETPACK_POST_VIEWS_VERSION_NUM', '1.0.4' ); 557 // Add post meta for each post 558 $args = array( 'numberposts' => -1, 'post_type' => 'post', 'post_status' => 'publish'); 559 $allposts = get_posts( $args ); 560 foreach( $allposts as $post) { 561 $views = get_post_meta( $post->ID, 'jetpack-post-views', true ); 562 563 if (!$views) { 564 add_post_meta( $post->ID, 'jetpack-post-views', 0, true ); 565 } 566 } 567 568 define( 'JETPACK_POST_VIEWS_VERSION_NUM', '1.0.5' ); 542 569 } 543 570 … … 587 614 588 615 // Upgrade the plugin if necessary 589 if ( JETPACK_POST_VIEWS_VERSION_NUM != '1.0. 4' ) {616 if ( JETPACK_POST_VIEWS_VERSION_NUM != '1.0.5' ) { 590 617 $Jetpack_Post_Views->upgrade(); 591 618 } … … 626 653 <li><a href="<?php echo get_permalink( $post['post_id'] ) ?>"><?php echo get_the_title( $post['post_id'] ) ?></a> 627 654 <?php if ( $args['displayViews'] ) { 628 echo " - ".number_format_i18n( $post['views'] )." views";655 echo " - ".number_format_i18n( $post['views'] ? $post['views'] : 0 )." views"; 629 656 } ?> 630 657 </li> … … 636 663 } 637 664 } 665 666 /* 667 * SHORTCODE 668 * Use the Jetpack stats_get_csv() function to create a list of the top posts 669 * atts: days - number of days of the desired time frame. '-1' means unlimited 670 * limit - number of posts to display. '-1' means unlimited. If days is -1, then limit is capped at 500 671 * exclude - comma-separated list of post IDs to exclude form displaying 672 * displayviews - flag to display the post views 673 */ 674 add_shortcode( 'jpv', 'JPV_shortcode' ); 675 function JPV_shortcode( $atts ) { 676 extract( shortcode_atts( array( 677 'days' => '-1', 678 'limit' => '5', 679 'exclude' => '', 680 'displayviews' => false, 681 ), $atts ) ); 682 683 JPV_display_top_posts( $args = array( 'days' => $days, 'limit' => $limit, 'exclude' => $exclude, 'displayViews' => $displayviews ) ); 684 } -
jetpack-post-views/trunk/readme.txt
r681940 r716369 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 9 10 A plugin that displays your most popular posts using Jetpack stats.10 Displays your most popular posts using Jetpack stats. 11 11 12 12 == Description == … … 61 61 **NOTE** This function only works if the function `stats_get_csv()` exists. If this function is not working probably, it is probably due to the `stats_get_csv()` function not returning the needed results. 62 62 63 = How can I display the top posts in my posts? = 64 65 Use the shortcode '[jpv]' 66 67 The shotcode uses the same parameters as the 'JPV_display_top_posts()' function 68 63 69 == Screenshots == 64 70 … … 69 75 70 76 == Changelog == 77 78 = 1.0.5 (2013-05-21) = 79 * Fixed posts not properly displaying post views 80 * Fixed database access to tables using 'wp_' table prefix to use prefix defined in wp-config.php 81 * Added shortcode 71 82 72 83 = 1.0.4 (2013-03-14) =
Note: See TracChangeset
for help on using the changeset viewer.