Changeset 2532343
- Timestamp:
- 05/16/2021 01:45:27 AM (3 years ago)
- Location:
- simple-ga-ranking
- Files:
-
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
simple-ga-ranking/tags/2.1.1/admin/admin.php
r2531557 r2532343 1 1 <?php 2 2 3 add_action( 'admin_menu', function () { 3 add_action( 'admin_menu', function () 4 { 4 5 add_options_page( 5 6 __( 'Simple GA Ranking', SGA_RANKING_DOMAIN ), … … 11 12 }); 12 13 13 function sga_ranking_options_page() { 14 function sga_ranking_options_page() 15 { 14 16 echo '<div class="wrap">'; 15 17 … … 18 20 echo '<form action="options.php" method="post" id="sga-post">'; 19 21 20 settings_fields( 'sga_ranking_options');22 settings_fields( ); 21 23 do_settings_sections( 'sga_ranking' ); 22 24 do_meta_boxes( 'sga_ranking', 'advanced', '' ); … … 35 37 } 36 38 37 add_action( 'admin_init', function () { 39 add_action( 'admin_init', function () 40 { 38 41 register_setting( 39 'sga_ranking_options',40 'sga_ranking_options',42 , 43 , 41 44 'sga_ranking_options_validate' 42 45 ); … … 65 68 }); 66 69 67 function sga_ranking_section_text() { 70 function sga_ranking_section_text() 71 { 68 72 do_action( 'sga_ranking_section_text' ); 69 73 } 70 74 71 function sga_ranking_setting_period() { 72 $options = get_option( 'sga_ranking_options' ); 75 function sga_ranking_setting_period() 76 { 77 $options = get_option( SGA_RANKING_OPTION_NAME ); 73 78 $option_name = 'period'; 74 79 … … 84 89 } 85 90 86 function sga_ranking_setting_display_count() { 87 $options = get_option( 'sga_ranking_options' ); 91 function sga_ranking_setting_display_count() 92 { 93 $options = get_option( SGA_RANKING_OPTION_NAME ); 88 94 $option_name = 'display_count'; 89 95 … … 98 104 } 99 105 100 function sga_ranking_setting_debug_mode() { 101 $options = get_option( 'sga_ranking_options' ); 106 function sga_ranking_setting_debug_mode() 107 { 108 $options = get_option( SGA_RANKING_OPTION_NAME ); 102 109 $option_name = 'debug_mode'; 103 110 … … 113 120 } 114 121 115 function sga_ranking_options_validate( $input ) { 122 function sga_ranking_options_validate( $input ) 123 { 116 124 $newinput['period'] = absint( $input['period'] ); 117 125 $newinput['display_count'] = absint( $input['display_count'] ); … … 122 130 } 123 131 124 add_action( 'admin_notices', function () { 132 add_action( 'admin_notices', function () 133 { 125 134 $token = get_option('gapiwp_token'); 126 135 -
simple-ga-ranking/tags/2.1.1/lib/wp-rest-api.class.php
r1086949 r2532343 3 3 * Name: SGRanking Endpoint 4 4 */ 5 class WP_JSON_SGRanking extends WP_JSON_Posts { 5 class WP_JSON_SGRanking extends WP_JSON_Posts 6 { 6 7 7 8 /** … … 11 12 * @return array Modified routes 12 13 */ 13 public function register_routes( $routes ) { 14 public function register_routes( $routes ) 15 { 14 16 $ranking_routes = array( 15 17 '/ranking' => array( … … 28 30 * @see WP_JSON_Posts::get_posts() 29 31 */ 30 public function get_ranking( $filter = array(), $context = 'view' ) { 32 public function get_ranking( $filter = array(), $context = 'view' ) 33 { 31 34 $ids = sga_ranking_get_date( $filter ); 32 35 $posts_list = array(); -
simple-ga-ranking/tags/2.1.1/readme.txt
r2531567 r2532343 4 4 Requires at least: 3.6.1 5 5 Tested up to: 5.7.2 6 Stable tag: 2.1 6 Stable tag: 2.1 7 7 8 8 Ranking plugin using data from google analytics. … … 92 92 = 2.1 = 93 93 * refactoring 94 95 -
simple-ga-ranking/tags/2.1.1/simple-ga-ranking.php
r2531557 r2532343 5 5 Plugin URI: http://simple-ga-ranking.org 6 6 Description: Ranking plugin using data from google analytics. 7 Version: 2.1 7 Version: 2.1 8 8 Author URI: http://simple-ga-ranking.org 9 9 Domain Path: /languages … … 31 31 } 32 32 if ( ! defined( 'SGA_RANKING_PLUGIN_URL' ) ) { 33 define( 'SGA_RANKING_PLUGIN_URL', plugins_url() . '/' . dirname( plugin_basename( __FILE__ ) ) );33 define( 'SGA_RANKING_PLUGIN_URL', plugins_url() . '/' . dirname( plugin_basename( __FILE__ ) )); 34 34 } 35 35 if ( ! defined( 'SGA_RANKING_PLUGIN_DIR' ) ) { 36 define( 'SGA_RANKING_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) )); 36 define( 'SGA_RANKING_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) ); 37 } 38 if ( ! defined( 'SGA_RANKING_OPTION_NAME' ) ) { 39 define( 'SGA_RANKING_OPTION_NAME', 'sga_ranking_options' ); 37 40 } 38 41 … … 45 48 $simple_ga_ranking = \Hametuha\GapiWP\Loader::analytics(); 46 49 47 function sga_ranking_get_date( $args = array() ) { 50 function sga_ranking_get_date( $args = array() ) 51 { 52 return sga_ranking_get_data( $args ); 53 } 54 function sga_ranking_get_data( $args = array() ) 55 { 48 56 // cache expire time 49 57 $cache_expires = (int) apply_filters( 'sga_ranking_cache_expire', 24*60*60 ); … … 53 61 54 62 // get options 55 $options = get_option( 'sga_ranking_options');63 $options = get_option( ); 56 64 57 65 // get args … … 129 137 $debug_mode = ( defined( 'SGA_RANKING_TEST_MODE' ) && SGA_RANKING_TEST_MODE === true ) || ( isset($options['debug_mode']) && $options['debug_mode'] == 1 ); 130 138 if ( false === $ids && $debug_mode ) { 131 global $wpdb; 132 133 $query = $wpdb->prepare( 134 "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s ORDER BY RAND() LIMIT 0, %d", 135 'post', 136 'publish', 137 $options['display_count'] 138 ); 139 $rets = $wpdb->get_results( $query ); 140 $ids = array(); 141 foreach ( $rets as $ret ) { 142 $ids[] = $ret->ID; 143 } 144 139 $ids = sga_ranking_get_dummy_data( $args ); 145 140 set_transient( $transient_key, $ids, $cache_expires * 2 ); 146 141 } … … 148 143 // get GA ranking 149 144 if ( false !== $ids ) { 145 150 146 $post_ids = $ids; 151 147 152 148 } else { 153 $post_ids = array(); 154 155 $args = array( 149 // from Google Analytics API 150 $ga_args = array( 156 151 'start-index' => 1, 157 152 'max-results' => $post_limit, … … 159 154 'sort' => '-ga:pageviews', 160 155 ); 161 if ( ! empty( $filter_val) ) {162 $ args['filters'] = $filter_val;156 if ( ! empty() ) { 157 $args['filters'] = $filter_val; 163 158 } 164 159 $results = $simple_ga_ranking->fetch( … … 166 161 $options['end_date'], 167 162 'ga:pageviews', 168 $ args163 $args 169 164 ); 170 165 171 $cnt = 0; 172 if ( !empty( $results ) && !is_wp_error( $results ) && is_array( $results->rows ) ) { 166 if ( ! empty( $results ) && !is_wp_error( $results ) && is_array( $results->rows ) ) { 167 $post_ids = array(); 168 $cnt = 0; 169 173 170 foreach($results->rows as $result) { 174 171 $max = (int) $options['display_count']; … … 192 189 193 190 $post_obj = get_post($post_id); 194 if ( !is_object($post_obj) || $post_obj->post_status != 'publish' ) {191 if ( !is_object($post_obj) || $post_obj->post_status != 'publish' ){ 195 192 continue; 196 193 } 197 194 198 195 if ( !empty($r) ) { 199 196 if ( array_key_exists( 'post_type', $r ) && is_string($r['post_type']) ) { … … 253 250 } 254 251 } 255 252 256 253 $post_ids[] = $post_id; 257 254 $cnt++; 258 255 } 256 259 257 260 258 } else { 259 260 261 261 if ( is_super_admin() ) { 262 262 echo '<pre>'; … … 265 265 } 266 266 } 267 268 set_transient( $transient_key, $post_ids, $cache_expires * 2 );269 267 } 270 268 271 269 return apply_filters( 'sga_ranking_ids', $post_ids ); 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 272 295 } 273 296 274 297 add_filter( 'widget_text', 'do_shortcode' ); 275 298 add_shortcode('sga_ranking', 'sga_ranking_shortcode'); 276 function sga_ranking_shortcode( $atts ) { 277 278 $ids = sga_ranking_get_date($atts); 299 function sga_ranking_shortcode( $atts ) 300 { 301 302 $ids = sga_ranking_get_data($atts); 279 303 280 304 if ( empty( $ids ) ) { … … 296 320 297 321 //widget 298 class WP_Widget_Simple_GA_Ranking extends WP_Widget { 299 300 function __construct() { 322 class WP_Widget_Simple_GA_Ranking extends WP_Widget 323 { 324 325 function __construct() 326 { 301 327 $widget_ops = array('classname' => 'widget_simple_ga_ranking', 'description' => __( "Show ranking the data from Google Analytics", SGA_RANKING_DOMAIN ) ); 302 328 parent::__construct('simple_ga_rankig', __('Simple GA Ranking'), $widget_ops); 303 329 } 304 330 305 function widget( $args, $instance ) { 331 function widget( $args, $instance ) 332 { 306 333 extract($args); 307 334 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); … … 317 344 } 318 345 319 function form( $instance ) { 346 function form( $instance ) 347 { 320 348 $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); 321 349 $title = $instance['title']; … … 325 353 } 326 354 327 function update( $new_instance, $old_instance ) { 355 function update( $new_instance, $old_instance ) 356 { 328 357 $instance = $old_instance; 329 358 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => '')); … … 475 504 require_once( SGA_RANKING_PLUGIN_DIR . '/lib/wp-rest-api.class.php' ); 476 505 477 function sga_json_api_ranking_filters( $server ) { 506 function sga_json_api_ranking_filters( $server ) 507 { 478 508 // Ranking 479 509 $wp_json_ranking = new WP_JSON_SGRanking( $server ); 480 add_filter( 'json_endpoints', array( $wp_json_ranking, 'register_routes' ), 1 510 add_filter( 'json_endpoints', array( $wp_json_ranking, 'register_routes' ), 1 ); 481 511 } 482 512 add_action( 'wp_json_server_before_serve', 'sga_json_api_ranking_filters', 10, 1 ); -
simple-ga-ranking/trunk/admin/admin.php
r2531557 r2532343 1 1 <?php 2 2 3 add_action( 'admin_menu', function () { 3 add_action( 'admin_menu', function () 4 { 4 5 add_options_page( 5 6 __( 'Simple GA Ranking', SGA_RANKING_DOMAIN ), … … 11 12 }); 12 13 13 function sga_ranking_options_page() { 14 function sga_ranking_options_page() 15 { 14 16 echo '<div class="wrap">'; 15 17 … … 18 20 echo '<form action="options.php" method="post" id="sga-post">'; 19 21 20 settings_fields( 'sga_ranking_options');22 settings_fields( ); 21 23 do_settings_sections( 'sga_ranking' ); 22 24 do_meta_boxes( 'sga_ranking', 'advanced', '' ); … … 35 37 } 36 38 37 add_action( 'admin_init', function () { 39 add_action( 'admin_init', function () 40 { 38 41 register_setting( 39 'sga_ranking_options',40 'sga_ranking_options',42 , 43 , 41 44 'sga_ranking_options_validate' 42 45 ); … … 65 68 }); 66 69 67 function sga_ranking_section_text() { 70 function sga_ranking_section_text() 71 { 68 72 do_action( 'sga_ranking_section_text' ); 69 73 } 70 74 71 function sga_ranking_setting_period() { 72 $options = get_option( 'sga_ranking_options' ); 75 function sga_ranking_setting_period() 76 { 77 $options = get_option( SGA_RANKING_OPTION_NAME ); 73 78 $option_name = 'period'; 74 79 … … 84 89 } 85 90 86 function sga_ranking_setting_display_count() { 87 $options = get_option( 'sga_ranking_options' ); 91 function sga_ranking_setting_display_count() 92 { 93 $options = get_option( SGA_RANKING_OPTION_NAME ); 88 94 $option_name = 'display_count'; 89 95 … … 98 104 } 99 105 100 function sga_ranking_setting_debug_mode() { 101 $options = get_option( 'sga_ranking_options' ); 106 function sga_ranking_setting_debug_mode() 107 { 108 $options = get_option( SGA_RANKING_OPTION_NAME ); 102 109 $option_name = 'debug_mode'; 103 110 … … 113 120 } 114 121 115 function sga_ranking_options_validate( $input ) { 122 function sga_ranking_options_validate( $input ) 123 { 116 124 $newinput['period'] = absint( $input['period'] ); 117 125 $newinput['display_count'] = absint( $input['display_count'] ); … … 122 130 } 123 131 124 add_action( 'admin_notices', function () { 132 add_action( 'admin_notices', function () 133 { 125 134 $token = get_option('gapiwp_token'); 126 135 -
simple-ga-ranking/trunk/lib/wp-rest-api.class.php
r1086949 r2532343 3 3 * Name: SGRanking Endpoint 4 4 */ 5 class WP_JSON_SGRanking extends WP_JSON_Posts { 5 class WP_JSON_SGRanking extends WP_JSON_Posts 6 { 6 7 7 8 /** … … 11 12 * @return array Modified routes 12 13 */ 13 public function register_routes( $routes ) { 14 public function register_routes( $routes ) 15 { 14 16 $ranking_routes = array( 15 17 '/ranking' => array( … … 28 30 * @see WP_JSON_Posts::get_posts() 29 31 */ 30 public function get_ranking( $filter = array(), $context = 'view' ) { 32 public function get_ranking( $filter = array(), $context = 'view' ) 33 { 31 34 $ids = sga_ranking_get_date( $filter ); 32 35 $posts_list = array(); -
simple-ga-ranking/trunk/readme.txt
r2531567 r2532343 4 4 Requires at least: 3.6.1 5 5 Tested up to: 5.7.2 6 Stable tag: 2.1 6 Stable tag: 2.1 7 7 8 8 Ranking plugin using data from google analytics. … … 92 92 = 2.1 = 93 93 * refactoring 94 95 -
simple-ga-ranking/trunk/simple-ga-ranking.php
r2531557 r2532343 5 5 Plugin URI: http://simple-ga-ranking.org 6 6 Description: Ranking plugin using data from google analytics. 7 Version: 2.1 7 Version: 2.1 8 8 Author URI: http://simple-ga-ranking.org 9 9 Domain Path: /languages … … 31 31 } 32 32 if ( ! defined( 'SGA_RANKING_PLUGIN_URL' ) ) { 33 define( 'SGA_RANKING_PLUGIN_URL', plugins_url() . '/' . dirname( plugin_basename( __FILE__ ) ) );33 define( 'SGA_RANKING_PLUGIN_URL', plugins_url() . '/' . dirname( plugin_basename( __FILE__ ) )); 34 34 } 35 35 if ( ! defined( 'SGA_RANKING_PLUGIN_DIR' ) ) { 36 define( 'SGA_RANKING_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) )); 36 define( 'SGA_RANKING_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) ); 37 } 38 if ( ! defined( 'SGA_RANKING_OPTION_NAME' ) ) { 39 define( 'SGA_RANKING_OPTION_NAME', 'sga_ranking_options' ); 37 40 } 38 41 … … 45 48 $simple_ga_ranking = \Hametuha\GapiWP\Loader::analytics(); 46 49 47 function sga_ranking_get_date( $args = array() ) { 50 function sga_ranking_get_date( $args = array() ) 51 { 52 return sga_ranking_get_data( $args ); 53 } 54 function sga_ranking_get_data( $args = array() ) 55 { 48 56 // cache expire time 49 57 $cache_expires = (int) apply_filters( 'sga_ranking_cache_expire', 24*60*60 ); … … 53 61 54 62 // get options 55 $options = get_option( 'sga_ranking_options');63 $options = get_option( ); 56 64 57 65 // get args … … 129 137 $debug_mode = ( defined( 'SGA_RANKING_TEST_MODE' ) && SGA_RANKING_TEST_MODE === true ) || ( isset($options['debug_mode']) && $options['debug_mode'] == 1 ); 130 138 if ( false === $ids && $debug_mode ) { 131 global $wpdb; 132 133 $query = $wpdb->prepare( 134 "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s ORDER BY RAND() LIMIT 0, %d", 135 'post', 136 'publish', 137 $options['display_count'] 138 ); 139 $rets = $wpdb->get_results( $query ); 140 $ids = array(); 141 foreach ( $rets as $ret ) { 142 $ids[] = $ret->ID; 143 } 144 139 $ids = sga_ranking_get_dummy_data( $args ); 145 140 set_transient( $transient_key, $ids, $cache_expires * 2 ); 146 141 } … … 148 143 // get GA ranking 149 144 if ( false !== $ids ) { 145 150 146 $post_ids = $ids; 151 147 152 148 } else { 153 $post_ids = array(); 154 155 $args = array( 149 // from Google Analytics API 150 $ga_args = array( 156 151 'start-index' => 1, 157 152 'max-results' => $post_limit, … … 159 154 'sort' => '-ga:pageviews', 160 155 ); 161 if ( ! empty( $filter_val) ) {162 $ args['filters'] = $filter_val;156 if ( ! empty() ) { 157 $args['filters'] = $filter_val; 163 158 } 164 159 $results = $simple_ga_ranking->fetch( … … 166 161 $options['end_date'], 167 162 'ga:pageviews', 168 $ args163 $args 169 164 ); 170 165 171 $cnt = 0; 172 if ( !empty( $results ) && !is_wp_error( $results ) && is_array( $results->rows ) ) { 166 if ( ! empty( $results ) && !is_wp_error( $results ) && is_array( $results->rows ) ) { 167 $post_ids = array(); 168 $cnt = 0; 169 173 170 foreach($results->rows as $result) { 174 171 $max = (int) $options['display_count']; … … 192 189 193 190 $post_obj = get_post($post_id); 194 if ( !is_object($post_obj) || $post_obj->post_status != 'publish' ) {191 if ( !is_object($post_obj) || $post_obj->post_status != 'publish' ){ 195 192 continue; 196 193 } 197 194 198 195 if ( !empty($r) ) { 199 196 if ( array_key_exists( 'post_type', $r ) && is_string($r['post_type']) ) { … … 253 250 } 254 251 } 255 252 256 253 $post_ids[] = $post_id; 257 254 $cnt++; 258 255 } 256 259 257 260 258 } else { 259 260 261 261 if ( is_super_admin() ) { 262 262 echo '<pre>'; … … 265 265 } 266 266 } 267 268 set_transient( $transient_key, $post_ids, $cache_expires * 2 );269 267 } 270 268 271 269 return apply_filters( 'sga_ranking_ids', $post_ids ); 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 272 295 } 273 296 274 297 add_filter( 'widget_text', 'do_shortcode' ); 275 298 add_shortcode('sga_ranking', 'sga_ranking_shortcode'); 276 function sga_ranking_shortcode( $atts ) { 277 278 $ids = sga_ranking_get_date($atts); 299 function sga_ranking_shortcode( $atts ) 300 { 301 302 $ids = sga_ranking_get_data($atts); 279 303 280 304 if ( empty( $ids ) ) { … … 296 320 297 321 //widget 298 class WP_Widget_Simple_GA_Ranking extends WP_Widget { 299 300 function __construct() { 322 class WP_Widget_Simple_GA_Ranking extends WP_Widget 323 { 324 325 function __construct() 326 { 301 327 $widget_ops = array('classname' => 'widget_simple_ga_ranking', 'description' => __( "Show ranking the data from Google Analytics", SGA_RANKING_DOMAIN ) ); 302 328 parent::__construct('simple_ga_rankig', __('Simple GA Ranking'), $widget_ops); 303 329 } 304 330 305 function widget( $args, $instance ) { 331 function widget( $args, $instance ) 332 { 306 333 extract($args); 307 334 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); … … 317 344 } 318 345 319 function form( $instance ) { 346 function form( $instance ) 347 { 320 348 $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); 321 349 $title = $instance['title']; … … 325 353 } 326 354 327 function update( $new_instance, $old_instance ) { 355 function update( $new_instance, $old_instance ) 356 { 328 357 $instance = $old_instance; 329 358 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => '')); … … 475 504 require_once( SGA_RANKING_PLUGIN_DIR . '/lib/wp-rest-api.class.php' ); 476 505 477 function sga_json_api_ranking_filters( $server ) { 506 function sga_json_api_ranking_filters( $server ) 507 { 478 508 // Ranking 479 509 $wp_json_ranking = new WP_JSON_SGRanking( $server ); 480 add_filter( 'json_endpoints', array( $wp_json_ranking, 'register_routes' ), 1 510 add_filter( 'json_endpoints', array( $wp_json_ranking, 'register_routes' ), 1 ); 481 511 } 482 512 add_action( 'wp_json_server_before_serve', 'sga_json_api_ranking_filters', 10, 1 );
Note: See TracChangeset
for help on using the changeset viewer.