| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Post Pay Counter |
| 4 |
Plugin URI: https://postpaycounter.com |
| 5 |
Description: Easily handle authors payments on a multi-author blog by computing posts pay basing on admin defined rules. |
| 6 |
Author: Stefano Ottolenghi |
| 7 |
Version: 2.792 |
| 8 |
Author URI: https://thecrowned.org/ |
| 9 |
Text Domain: post-pay-counter |
| 10 |
*/ |
| 11 |
|
| 12 |
/** Copyright Stefano Ottolenghi 2013 |
| 13 |
* |
| 14 |
* This program is free software: you can redistribute it and/or modify |
| 15 |
* it under the terms of the GNU General Public License as published by |
| 16 |
* the Free Software Foundation, either version 3 of the License, or |
| 17 |
* (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 26 |
*/ |
| 27 |
|
| 28 |
if( defined( 'WP_CLI' ) && WP_CLI ) |
| 29 |
require_once( 'wp-cli.php' ); |
| 30 |
|
| 31 |
if( ! function_exists( 'add_action' ) ) |
| 32 |
die( 'This file is not meant to be called directly.' ); |
| 33 |
|
| 34 |
require_once( 'classes/ppc_general_functions_class.php' ); |
| 35 |
require_once( 'classes/ppc_generate_stats_class.php' ); |
| 36 |
require_once( 'classes/ppc_counting_stuff_class.php' ); |
| 37 |
require_once( 'classes/ppc_html_functions_class.php' ); |
| 38 |
require_once( 'classes/ppc_options_fields_class.php' ); |
| 39 |
require_once( 'classes/ppc_ajax_functions_class.php' ); |
| 40 |
require_once( 'classes/ppc_install_functions_class.php' ); |
| 41 |
require_once( 'classes/ppc_permissions_class.php' ); |
| 42 |
require_once( 'classes/ppc_meta_boxes_class.php' ); |
| 43 |
require_once( 'classes/ppc_system_info_class.php' ); |
| 44 |
require_once( 'classes/ppc_error_class.php' ); |
| 45 |
require_once( 'classes/ppc_welcome_class.php' ); |
| 46 |
require_once( 'classes/ppc_addons_class.php' ); |
| 47 |
require_once( 'classes/ppc_notifications_class.php' ); |
| 48 |
require_once( 'classes/ppc_counting_types_class.php' ); |
| 49 |
require_once( 'classes/ppc_license_class.php' ); |
| 50 |
require_once( 'classes/ppc_autoupdate_class.php' ); |
| 51 |
require_once( 'classes/ppc_cache_class.php' ); |
| 52 |
require_once( 'classes/ppc_wp_list_table_authors_class.php' ); |
| 53 |
require_once( 'classes/ppc_wp_list_table_posts_class.php' ); |
| 54 |
require_once( 'classes/ppc_visits_trackers.php' ); |
| 55 |
|
| 56 |
define( 'PPC_DEBUG_SHOW', false ); |
| 57 |
define( 'PPC_DEBUG_LOG', true ); |
| 58 |
|
| 59 |
class post_pay_counter { |
| 60 |
public static $options_page_settings; |
| 61 |
|
| 62 |
function __construct() { |
| 63 |
global $ppc_global_settings; |
| 64 |
|
| 65 |
$ppc_global_settings['current_version'] = get_option( 'ppc_current_version' ); |
| 66 |
$ppc_global_settings['newest_version'] = '2.792'; |
| 67 |
$ppc_global_settings['option_name'] = 'ppc_settings'; |
| 68 |
$ppc_global_settings['option_errors'] = 'ppc_errors'; |
| 69 |
$ppc_global_settings['option_stats_cache_incrementor'] = 'ppc_stats_cache_incrementor'; |
| 70 |
$ppc_global_settings['option_error_deletion'] = 'ppc_error_daily_deletion'; |
| 71 |
$ppc_global_settings['transient_activation_redirect'] = '_ppc_activation_redirect'; |
| 72 |
$ppc_global_settings['transient_update_redirect'] = '_ppc_update_redirect'; |
| 73 |
$ppc_global_settings['folder_path'] = plugins_url( '/', __FILE__ ); |
| 74 |
$ppc_global_settings['dir_path'] = plugin_dir_path( __FILE__ ); |
| 75 |
$ppc_global_settings['file_errors'] = $ppc_global_settings['dir_path'].'errors.log'; |
| 76 |
$ppc_global_settings['current_page'] = ''; |
| 77 |
$ppc_global_settings['options_menu_link'] = 'admin.php?page=ppc-options'; |
| 78 |
$ppc_global_settings['stats_menu_link'] = 'admin.php?page=ppc-stats'; |
| 79 |
$ppc_global_settings['cap_manage_options'] = 'post_pay_counter_manage_options'; |
| 80 |
$ppc_global_settings['cap_access_stats'] = 'post_pay_counter_access_stats'; |
| 81 |
$ppc_global_settings['temp'] = array( 'settings' => array() ); |
| 82 |
|
| 83 |
//Add left menu entries for both stats and options pages |
| 84 |
add_action( 'admin_menu', array( $this, 'admin_menus' ) ); |
| 85 |
//add_action( 'network_admin_menu', array( $this, 'post_pay_counter_network_admin_menus' ) ); |
| 86 |
|
| 87 |
//Hook for the install procedure |
| 88 |
register_activation_hook( __FILE__, array( 'PPC_install_functions', 'ppc_install' ) ); |
| 89 |
|
| 90 |
//Hook on blog adding on multisite wp to install the plugin there either |
| 91 |
add_action( 'wpmu_new_blog', array( 'PPC_install_functions', 'ppc_new_blog_install' ), 10, 6); |
| 92 |
|
| 93 |
//Plugin update routine |
| 94 |
add_action( 'plugins_loaded', array( $this, 'maybe_update' ) ); |
| 95 |
|
| 96 |
//Add custom times |
| 97 |
add_filter( 'cron_schedules', array( $this, 'cron_add_times' ) ); |
| 98 |
|
| 99 |
//On load plugin pages |
| 100 |
add_action( 'load-toplevel_page_ppc-stats', array( $this, 'on_load_stats_page' ) ); |
| 101 |
add_action( 'load-'.sanitize_title( apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ) ).'_page_ppc-options', array( $this, 'on_load_options_page_get_settings' ), 1 ); |
| 102 |
add_action( 'load-'.sanitize_title( apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ) ).'_page_ppc-options', array( $this, 'on_load_options_page_enqueue' ), 2 ); |
| 103 |
add_action( 'load-'.sanitize_title( apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ) ).'_page_ppc-addons', array( 'PPC_addons', 'on_load_addons_page_enqueue' ) ); |
| 104 |
//add_action( 'load-toplevel_page_post_pay_counter_show_network_stats', array( &$this, 'on_load_stats_page' ) ); |
| 105 |
add_filter('set-screen-option', array( $this, 'handle_stats_pagination_values' ), 10, 3 ); |
| 106 |
|
| 107 |
//About screen |
| 108 |
add_action( 'admin_menu', array( 'PPC_welcome', 'add_pages' ) ); |
| 109 |
add_action( 'admin_head', array( 'PPC_welcome', 'admin_head' ) ); |
| 110 |
//add_action( 'admin_init', array( 'PPC_welcome', 'welcome' ) ); |
| 111 |
add_action( 'load-dashboard_page_ppc-about', array( 'PPC_welcome', 'custom_css' ) ); |
| 112 |
add_action( 'load-dashboard_page_ppc-changelog', array( 'PPC_welcome', 'custom_css' ) ); |
| 113 |
|
| 114 |
//Custom links besides the usual "Edit" and "Deactivate" |
| 115 |
add_filter( 'plugin_action_links', array( $this, 'settings_meta_link' ), 10, 2 ); |
| 116 |
add_filter( 'plugin_row_meta', array( $this, 'donate_meta_link' ), 10, 2 ); |
| 117 |
|
| 118 |
//Counting types |
| 119 |
//add_filter( 'ppc_active_user_counting_types', array( 'PPC_counting_types', 'counting_type_visits_callback' ), 10, 2 ); |
| 120 |
|
| 121 |
//Notifications |
| 122 |
add_action( 'admin_init', array( $this, 'load_notifications' ) ); |
| 123 |
|
| 124 |
//Manage AJAX calls |
| 125 |
add_action( 'wp_ajax_ppc_save_counting_settings', array( 'PPC_ajax_functions', 'save_counting_settings' ) ); |
| 126 |
add_action( 'wp_ajax_ppc_save_permissions', array( 'PPC_ajax_functions', 'save_permissions' ) ); |
| 127 |
add_action( 'wp_ajax_ppc_save_misc_settings', array( 'PPC_ajax_functions', 'save_misc_settings' ) ); |
| 128 |
add_action( 'wp_ajax_ppc_personalize_fetch_users_by_roles', array( 'PPC_ajax_functions', 'personalize_fetch_users_by_roles' ) ); |
| 129 |
add_action( 'wp_ajax_ppc_vaporize_user_settings', array( 'PPC_ajax_functions', 'vaporize_user_settings' ) ); |
| 130 |
add_action( 'wp_ajax_ppc_import_settings', array( 'PPC_ajax_functions', 'import_settings' ) ); |
| 131 |
add_action( 'wp_ajax_ppc_clear_error_log', array( 'PPC_ajax_functions', 'clear_error_log' ) ); |
| 132 |
add_action( 'wp_ajax_ppc_dismiss_notification', array( 'PPC_ajax_functions', 'dismiss_notification' ) ); |
| 133 |
add_action( 'wp_ajax_ppc_stats_get_users_by_role', array( 'PPC_ajax_functions', 'stats_get_users_by_role' ) ); |
| 134 |
|
| 135 |
//License hooks |
| 136 |
add_action( 'wp_ajax_ppc_license_activate', array( 'PPC_ajax_functions', 'license_activate' ) ); |
| 137 |
add_action( 'wp_ajax_ppc_license_deactivate', array( 'PPC_ajax_functions', 'license_deactivate' ) ); |
| 138 |
|
| 139 |
//Caching compatibility hooks with old PRO version and other addons |
| 140 |
PPC_cache_functions::clear_post_stats_old_addons(); |
| 141 |
|
| 142 |
//Clear post stats cache on post update |
| 143 |
add_action( 'post_updated', array( 'PPC_cache_functions' , 'clear_post_stats' ), 10, 1 ); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Adds "every two weeks" as schedule time (ppcp activation check). |
| 148 |
* |
| 149 |
* @access public |
| 150 |
* @since 2.511 |
| 151 |
* @param $schedules array shedules already |
| 152 |
* @return array schedules |
| 153 |
*/ |
| 154 |
function cron_add_times( $schedules ) { |
| 155 |
$schedules['weekly2'] = array( |
| 156 |
'interval' => 3600*24*14, |
| 157 |
'display' => 'Once every two weeks' |
| 158 |
); |
| 159 |
return $schedules; |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Adds first level side menu "Post Pay Counter" |
| 164 |
* |
| 165 |
* @access public |
| 166 |
* @since 2.0 |
| 167 |
*/ |
| 168 |
function admin_menus() { |
| 169 |
global $ppc_global_settings; |
| 170 |
|
| 171 |
add_menu_page( apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ), apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ), $ppc_global_settings['cap_access_stats'], 'ppc-stats', array( $this, 'show_stats' ), plugin_dir_url( __FILE__ ).'style/images/dollar.png' ); |
| 172 |
add_submenu_page( 'ppc-stats', apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ).' - '.__( 'Stats', 'post-pay-counter' ), __( 'Stats', 'post-pay-counter' ), $ppc_global_settings['cap_access_stats'], 'ppc-stats', array( $this, 'show_stats' ) ); |
| 173 |
$ppc_global_settings['options_menu_slug'] = add_submenu_page( 'ppc-stats', apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ).' - '.__( 'Options', 'post-pay-counter' ), __( 'Options', 'post-pay-counter' ), $ppc_global_settings['cap_manage_options'], 'ppc-options', array( $this, 'show_options' ) ); |
| 174 |
add_submenu_page( 'ppc-stats', apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ).' - '.__( 'System Info', 'post-pay-counter' ), __( 'System Info', 'post-pay-counter' ), $ppc_global_settings['cap_manage_options'], 'ppc-system-info', array( 'PPC_system_info', 'system_info' ) ); |
| 175 |
add_submenu_page( 'ppc-stats', apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ).' - '.__( 'Addons', 'post-pay-counter' ), __( 'Addons', 'post-pay-counter' ), $ppc_global_settings['cap_manage_options'], 'ppc-addons', array( 'PPC_addons', 'addons_page' ) ); |
| 176 |
} |
| 177 |
|
| 178 |
//Adds first level side menu (network admin) |
| 179 |
/*function post_pay_counter_network_admin_menus() { |
| 180 |
add_menu_page( 'Post Pay Counter', 'Post Pay Counter', 'post_pay_counter_access_stats', 'post_pay_counter_show_network_stats', array( $this, 'post_pay_counter_show_network_stats' ) ); |
| 181 |
add_submenu_page( 'post_pay_counter_show_network_stats', 'Post Pay Counter Stats', 'Stats', 'post_pay_counter_access_stats', 'post_pay_counter_show_network_stats', array( $this, 'post_pay_counter_show_network_stats' ) ); |
| 182 |
$ppc_global_settings['stats_menu_link'] = 'admin.php?page=post_pay_counter_show_network_stats'; |
| 183 |
$ppc_global_settings['options_menu_slug'] = add_submenu_page( 'post_pay_counter_show_network_stats', 'Post Pay Counter Options', 'Options', 'post_pay_counter_manage_options', 'post_pay_counter_network_options', array( $this, 'post_pay_counter_network_options' ) ); |
| 184 |
$ppc_global_settings['options_menu_link'] = 'admin.php?page=post_pay_counter_network_options'; |
| 185 |
}*/ |
| 186 |
|
| 187 |
/** |
| 188 |
* If current_version option is DIFFERENT from the latest release number, launch the update procedure. |
| 189 |
* |
| 190 |
* @access public |
| 191 |
* @since 2.1.1 |
| 192 |
*/ |
| 193 |
function maybe_update() { |
| 194 |
global $ppc_global_settings; |
| 195 |
|
| 196 |
if( $ppc_global_settings['current_version'] != $ppc_global_settings['newest_version'] ) { |
| 197 |
require_once( 'classes/ppc_update_class.php' ); |
| 198 |
PPC_update_class::update(); |
| 199 |
$ppc_global_settings['current_version'] = $ppc_global_settings['newest_version']; |
| 200 |
|
| 201 |
/** |
| 202 |
* Fires after PPC has been updated to latest version. |
| 203 |
* @since 2.1.1 |
| 204 |
*/ |
| 205 |
do_action( 'ppc_updated' ); |
| 206 |
|
| 207 |
//Send to Welcome page |
| 208 |
//wp_safe_redirect( admin_url( add_query_arg( array( 'page' => 'ppc-about' ), 'admin.php' ) ) ); |
| 209 |
//set_transient( $ppc_global_settings['transient_update_redirect'], 'do it!', 3600 ); |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Reponsible of the datepicker's files, plugin's js and css loading in the stats page |
| 215 |
* |
| 216 |
* @access public |
| 217 |
* @since 2.0 |
| 218 |
*/ |
| 219 |
function on_load_stats_page() { |
| 220 |
global $ppc_global_settings; |
| 221 |
|
| 222 |
add_thickbox(); |
| 223 |
|
| 224 |
//If an author is given, put that in an array |
| 225 |
if( isset( $_REQUEST['author'] ) AND is_numeric( $_REQUEST['author'] ) AND get_userdata( $_REQUEST['author'] ) ) { |
| 226 |
$ppc_global_settings['current_page'] = 'stats_detailed'; |
| 227 |
$this->author = array( $_REQUEST['author'] ); |
| 228 |
} else { |
| 229 |
$ppc_global_settings['current_page'] = 'stats_general'; |
| 230 |
$this->author = NULL; |
| 231 |
} |
| 232 |
|
| 233 |
//Store and maybe_redirect to ordered stats |
| 234 |
PPC_general_functions::default_stats_order(); |
| 235 |
|
| 236 |
$general_settings = PPC_general_functions::get_settings( 'general' ); |
| 237 |
|
| 238 |
//Initiliaze counting types |
| 239 |
$ppc_global_settings['counting_types_object'] = new PPC_counting_types(); |
| 240 |
$ppc_global_settings['counting_types_object']->register_built_in_counting_types(); |
| 241 |
|
| 242 |
//Also populates $ppc_global_settings['first_available_post_time'] and $ppc_global_settings['last_available_post_time'] |
| 243 |
PPC_general_functions::get_default_stats_time_range( $general_settings ); |
| 244 |
|
| 245 |
$time_end_now = date( 'Y-m-d', strtotime( '23:59:59' ) ); |
| 246 |
$time_start_end_week = get_weekstartend( current_time('mysql') ); |
| 247 |
|
| 248 |
wp_enqueue_script( 'jquery-ui-datepicker' ); |
| 249 |
wp_enqueue_style( 'jquery.ui.theme', $ppc_global_settings['folder_path'].'style/ui-lightness/jquery-ui-1.8.15.custom.css' ); |
| 250 |
wp_enqueue_style( 'ppc_header_style', $ppc_global_settings['folder_path'].'style/ppc_header_style.css', array( 'wp-admin' ) ); |
| 251 |
wp_enqueue_style( 'ppc_stats_style', $ppc_global_settings['folder_path'].'style/ppc_stats_style.css' ); |
| 252 |
wp_enqueue_script( 'ppc_stats_effects', $ppc_global_settings['folder_path'].'js/ppc_stats_effects.js', array( 'jquery' ) ); |
| 253 |
wp_localize_script( 'ppc_stats_effects', 'ppc_stats_effects_vars', array( |
| 254 |
'datepicker_mindate' => date( 'Y-m-d', $ppc_global_settings['first_available_post_time'] ), |
| 255 |
'datepicker_maxdate' => date( 'Y-m-d', $ppc_global_settings['last_available_post_time'] ), |
| 256 |
'time_start_this_month' => date( 'Y-m-d', strtotime( 'first day of this month' ) ), |
| 257 |
'time_end_this_month' => $time_end_now, |
| 258 |
'time_start_this_year' => date( 'Y-m-d', strtotime( 'first day of january this year' ) ), |
| 259 |
'time_end_this_year' => $time_end_now, |
| 260 |
'time_start_this_week' => date( 'Y-m-d', $time_start_end_week['start'] ), |
| 261 |
'time_end_this_week' => $time_end_now, |
| 262 |
'time_start_last_month' => date( 'Y-m-d', strtotime('first day of last month') ), |
| 263 |
'time_end_last_month' => date( 'Y-m-d', strtotime( 'first day of this month' ) - 86400 ), //go to first day of current month and back of one day |
| 264 |
'time_start_all_time' => $ppc_global_settings['first_available_post_time'], |
| 265 |
'time_end_all_time' => $time_end_now, |
| 266 |
'nonce_ppc_stats_get_users_by_role' => wp_create_nonce( 'ppc_stats_get_users_by_role' ) |
| 267 |
) ); |
| 268 |
|
| 269 |
$this->initialize_stats(); |
| 270 |
} |
| 271 |
|
| 272 |
/** |
| 273 |
* Loads metaboxes and tooltips js+css in the plugin options page and all the js and css needed, plus the strings js needs (nonces and localized text). |
| 274 |
* |
| 275 |
* @access public |
| 276 |
* @since 2.0 |
| 277 |
*/ |
| 278 |
function on_load_options_page_enqueue() { |
| 279 |
global $ppc_global_settings; |
| 280 |
wp_enqueue_script( 'post' ); |
| 281 |
|
| 282 |
add_meta_box( 'ppc_counting_settings', __( 'Counting Settings', 'post-pay-counter' ), array( 'PPC_meta_boxes', 'meta_box_counting_settings' ), $ppc_global_settings['options_menu_slug'], 'normal', 'default', self::$options_page_settings ); |
| 283 |
add_meta_box( 'ppc_permissions', __( 'Permissions', 'post-pay-counter' ), array( 'PPC_meta_boxes', 'meta_box_permissions' ), $ppc_global_settings['options_menu_slug'], 'normal', 'default', self::$options_page_settings ); |
| 284 |
|
| 285 |
if( ! isset( $_GET['userid'] ) OR ( isset( $_GET['userid'] ) AND $_GET['userid'] == 'general' ) ) { |
| 286 |
add_meta_box( 'ppc_personalize_settings', __( 'Personalize Settings', 'post-pay-counter' ), array( 'PPC_meta_boxes', 'meta_box_personalize_settings' ), $ppc_global_settings['options_menu_slug'], 'side', 'default', self::$options_page_settings ); |
| 287 |
add_meta_box( 'ppc_license', __( 'License status', 'post-pay-counter' ), array( 'PPC_meta_boxes', 'meta_box_license' ), $ppc_global_settings['options_menu_slug'], 'side', 'default', post_pay_counter::$options_page_settings ); |
| 288 |
add_meta_box( 'ppc_misc_settings', __( 'Miscellanea', 'post-pay-counter' ), array( 'PPC_meta_boxes', 'meta_box_misc_settings' ), $ppc_global_settings['options_menu_slug'], 'normal', 'default', self::$options_page_settings ); |
| 289 |
} |
| 290 |
|
| 291 |
add_meta_box( 'ppc_import_export_settings', __( 'Import/Export Settings', 'post-pay-counter' ), array( 'PPC_meta_boxes', 'meta_box_import_export_settings' ), $ppc_global_settings['options_menu_slug'], 'side', 'default', self::$options_page_settings ); |
| 292 |
add_meta_box( 'ppc_pro_features', __( 'Everything you\'re missing by not being PRO', 'post-pay-counter' ), array( 'PPC_meta_boxes', 'meta_box_pro_features' ), $ppc_global_settings['options_menu_slug'], 'side' ); |
| 293 |
add_meta_box( 'ppc_support_the_fucking_author', __( 'Support the author', 'post-pay-counter' ), array( 'PPC_meta_boxes', 'meta_box_support_the_fucking_author' ), $ppc_global_settings['options_menu_slug'], 'side' ); |
| 294 |
|
| 295 |
if( ! isset( $_GET['userid'] ) OR ( isset( $_GET['userid'] ) AND $_GET['userid'] == 'general' ) ) { |
| 296 |
add_meta_box( 'ppc_error_log', __( 'Error log', 'post-pay-counter' ), array( 'PPC_meta_boxes', 'meta_box_error_log' ), $ppc_global_settings['options_menu_slug'], 'side', 'default', self::$options_page_settings ); |
| 297 |
} |
| 298 |
|
| 299 |
wp_enqueue_style( 'jquery.tooltip.theme', $ppc_global_settings['folder_path'].'style/tipTip.css' ); |
| 300 |
wp_enqueue_style( 'ppc_header_style', $ppc_global_settings['folder_path'].'style/ppc_header_style.css', array( 'wp-admin' ), filemtime( $ppc_global_settings['dir_path'].'style/ppc_header_style.css' ) ); |
| 301 |
wp_enqueue_style( 'ppc_options_style_old', $ppc_global_settings['folder_path'].'style/ppc_options_style_old.css', array( 'wp-admin' ), filemtime( $ppc_global_settings['dir_path'].'style/ppc_options_style_old.css' ) ); |
| 302 |
wp_enqueue_style( 'ppc_options_style', $ppc_global_settings['folder_path'].'style/ppc_options_style.css', array( 'wp-admin' ), filemtime( $ppc_global_settings['dir_path'].'style/ppc_options_style.css' ) ); |
| 303 |
wp_enqueue_script( 'jquery-tooltip-plugin', $ppc_global_settings['folder_path'].'js/jquery.tiptip.min.js', array( 'jquery' ) ); |
| 304 |
wp_enqueue_script( 'ppc_options_ajax_stuff', $ppc_global_settings['folder_path'].'js/ppc_options_ajax_stuff.js', array( 'jquery' ), filemtime( $ppc_global_settings['dir_path'].'js/ppc_options_ajax_stuff.js' ) ); |
| 305 |
wp_localize_script( 'ppc_options_ajax_stuff', 'ppc_options_ajax_stuff_vars', array( |
| 306 |
'nonce_ppc_save_counting_settings' => wp_create_nonce( 'ppc_save_counting_settings' ), |
| 307 |
'nonce_ppc_save_permissions' => wp_create_nonce( 'ppc_save_permissions' ), |
| 308 |
'nonce_ppc_save_misc_settings' => wp_create_nonce( 'ppc_save_misc_settings' ), |
| 309 |
'nonce_ppc_personalize_fetch_users_by_roles' => wp_create_nonce( 'ppc_personalize_fetch_users_by_roles' ), |
| 310 |
'nonce_ppc_vaporize_user_settings' => wp_create_nonce( 'ppc_vaporize_user_settings' ), |
| 311 |
'nonce_ppc_import_settings' => wp_create_nonce( 'ppc_import_settings' ), |
| 312 |
'nonce_ppc_clear_error_log' => wp_create_nonce( 'ppc_clear_error_log' ), |
| 313 |
'nonce_ppc_license_key_activate' => wp_create_nonce( 'ppc_license_key_activate' ), |
| 314 |
'nonce_ppc_license_key_deactivate' => wp_create_nonce( 'ppc_license_key_deactivate' ), |
| 315 |
'localized_ppc_license_deactivated' => __( 'Your license was successfully deactivated, you can now use it on other websites.', 'ppc'), |
| 316 |
'localized_license_deactivate_warning' => __( 'Are you sure you want to deactivate your license on this website? You will be able to unlock the addon features on another website, but you will not be able to use them on this one anymore.', 'ppc'), |
| 317 |
'localized_vaporize_user_success' => __( 'User\'s settings successfully deleted. You will be redirected to the general options page.' , 'ppc'), |
| 318 |
'ppc_options_url' => $ppc_global_settings['options_menu_link'] |
| 319 |
) ); |
| 320 |
wp_enqueue_script( 'ppc_options_effects', $ppc_global_settings['folder_path'].'js/ppc_options_effects.js', array( 'jquery' ), filemtime( $ppc_global_settings['dir_path'].'js/ppc_options_effects.js' ) ); |
| 321 |
wp_localize_script( 'ppc_options_effects', 'ppc_options_effects_vars', array( |
| 322 |
'counting_words_current_zones_count' => count( self::$options_page_settings['counting_words_system_zonal_value'] ), |
| 323 |
'counting_visits_current_zones_count' => count( self::$options_page_settings['counting_visits_system_zonal_value'] ), |
| 324 |
'counting_images_current_zones_count' => count( self::$options_page_settings['counting_images_system_zonal_value'] ), |
| 325 |
'counting_comments_current_zones_count' => count( self::$options_page_settings['counting_comments_system_zonal_value'] ), |
| 326 |
'localized_too_many_zones' => __( 'No more than 10 zones are allowed.' , 'post-pay-counter'), |
| 327 |
'localized_too_few_zones' => __( 'No less than 2 zones are allowed.' , 'post-pay-counter'), |
| 328 |
'localized_need_threshold' => __( 'A payment threshold must first be set.' , 'post-pay-counter') |
| 329 |
) ); |
| 330 |
|
| 331 |
/** |
| 332 |
* Fires on PPC options page load. |
| 333 |
* |
| 334 |
* Equivalent to load-post-pay-counter_page_ppc-options but recommended, as fires after all PPC matters have been dealt with. |
| 335 |
* For example, if you hooked to load-post-pay-counter_page_ppc-options before PPC run its functions, the class variable $options_page_settings would not be set. |
| 336 |
* |
| 337 |
* @since 2.0 |
| 338 |
* @param $_GET['userid'] string userid (querystring param) |
| 339 |
*/ |
| 340 |
do_action( 'ppc_on_load_options_page', @$_GET['userid'] ); |
| 341 |
} |
| 342 |
|
| 343 |
/** |
| 344 |
* Selects the correct settings for the Options page. |
| 345 |
* |
| 346 |
* Acts depending on the given $_GET['userid']: general, trial or user-personalized. |
| 347 |
* If a valid user id is asked which does not have any personalized settings, get general ones and set the userid field to the user's one, unsetting all only-general options. |
| 348 |
* |
| 349 |
* @access public |
| 350 |
* @since 2.0 |
| 351 |
*/ |
| 352 |
function on_load_options_page_get_settings() { |
| 353 |
//Numeric userid |
| 354 |
if( isset( $_GET['userid'] ) AND is_numeric( $_GET['userid'] ) ) { |
| 355 |
if( ! get_userdata( (int) $_GET['userid'] ) ) { |
| 356 |
echo '<strong>'.__( 'The requested user does not exist.' , 'post-pay-counter' ).'</strong>'; |
| 357 |
return; |
| 358 |
} |
| 359 |
|
| 360 |
$settings = PPC_general_functions::get_settings( (int) $_GET['userid'], true ); |
| 361 |
|
| 362 |
//User who never had personalized settings is being set, get rid of only-general settings |
| 363 |
if( $settings['userid'] == 'general' ) { |
| 364 |
$settings['userid'] = (int) $_GET['userid']; |
| 365 |
} |
| 366 |
|
| 367 |
/** |
| 368 |
* Filters general settings on new user's custom settings. |
| 369 |
* |
| 370 |
* When a user's settings are customized for the first time, general settings are taken and stripped of the only general ones (i.e. non-customizable options, such as the Miscellanea box). |
| 371 |
* It's crucial that all non-personalizable settings indexes are unset before handling/saving the user's settings. |
| 372 |
* |
| 373 |
* ~ This was changed in 2.516, with only user settings different from general ones are stored. ~ |
| 374 |
* |
| 375 |
* @since 2.0 |
| 376 |
* @param $settings array PPC general settings |
| 377 |
*/ |
| 378 |
//$settings = apply_filters( 'ppc_unset_only_general_settings_personalize_user', $settings ); |
| 379 |
|
| 380 |
//General |
| 381 |
} else { |
| 382 |
$settings = PPC_general_functions::get_settings( 'general' ); |
| 383 |
} |
| 384 |
|
| 385 |
/** |
| 386 |
* Filters selected options page settings, final. |
| 387 |
* |
| 388 |
* They are stored in a class var and used throghout all the functions that need to know **what** settings we are displaying and using in the plugin options page. |
| 389 |
* |
| 390 |
* @since 2.0 |
| 391 |
* @param $settings PPC options settings |
| 392 |
*/ |
| 393 |
$settings = apply_filters( 'ppc_selected_options_settings', $settings ); |
| 394 |
|
| 395 |
self::$options_page_settings = $settings; //store in class var |
| 396 |
} |
| 397 |
|
| 398 |
/** |
| 399 |
* Adds a simple WordPress notice to plugin's page |
| 400 |
* |
| 401 |
* @access public |
| 402 |
* @since 2.46 |
| 403 |
*/ |
| 404 |
function load_notifications() { |
| 405 |
if( ! current_user_can( 'manage_options' ) ) return; |
| 406 |
|
| 407 |
//Get notifications to be displayed |
| 408 |
$notifications = PPC_notifications::notifications_get_list(); |
| 409 |
if( ! is_array( $notifications ) OR empty( $notifications ) OR is_wp_error( $notifications ) ) return; |
| 410 |
|
| 411 |
//Get array list of dismissed notifications for current user and convert it to array |
| 412 |
$dismissed_notifications = get_option( 'ppc_dismissed_notifications', array() ); |
| 413 |
|
| 414 |
foreach( $notifications as $single ) { |
| 415 |
//Check if notification is not among dismissed ones |
| 416 |
if( in_array( $single['id'], $dismissed_notifications ) ) |
| 417 |
continue; |
| 418 |
|
| 419 |
//Check where notification should be shown |
| 420 |
switch( $single['display'] ) { |
| 421 |
case 'stats': |
| 422 |
if( strpos( $_SERVER['QUERY_STRING'], 'ppc-stats' ) === false ) |
| 423 |
continue 2; |
| 424 |
|
| 425 |
case 'options': |
| 426 |
if( strpos( $_SERVER['QUERY_STRING'], 'ppc-options' ) === false ) |
| 427 |
continue 2; |
| 428 |
|
| 429 |
case 'plugin': |
| 430 |
if( strpos( $_SERVER['QUERY_STRING'], 'ppc-' ) === false ) |
| 431 |
continue 2; |
| 432 |
} |
| 433 |
|
| 434 |
//Load notification |
| 435 |
$notification = new PPC_notifications( $single ); |
| 436 |
add_action( 'admin_notices', array( $notification, 'display_notification' ) ); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
/** |
| 441 |
* Shows the "Settings" link in the plugins list (under the title) |
| 442 |
* |
| 443 |
* @access public |
| 444 |
* @since 2.0 |
| 445 |
* @param $links array links already in place |
| 446 |
* @param $file string current plugin-file |
| 447 |
*/ |
| 448 |
function settings_meta_link( $links, $file ) { |
| 449 |
global $ppc_global_settings; |
| 450 |
|
| 451 |
if( $file == plugin_basename( __FILE__ ) ) |
| 452 |
$links[] = '<a href="'.admin_url( $ppc_global_settings['options_menu_link'] ).'" title="'.__( 'Settings', 'post-pay-counter' ).'">'.__( 'Settings', 'post-pay-counter' ).'</a>'; |
| 453 |
|
| 454 |
return $links; |
| 455 |
} |
| 456 |
|
| 457 |
/** |
| 458 |
* Shows the "Donate" and "Go PRO" links in the plugins list (under the description) |
| 459 |
* |
| 460 |
* @access public |
| 461 |
* @since 2.0 |
| 462 |
* @param $links array links already in place |
| 463 |
* @param $file string current plugin-file |
| 464 |
*/ |
| 465 |
function donate_meta_link( $links, $file ) { |
| 466 |
if( $file == plugin_basename( __FILE__ ) ) { |
| 467 |
$links[] = '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SM5Q9BVU4RT22" title="'.__( 'Donate', 'post-pay-counter' ).'">'.__( 'Donate', 'post-pay-counter' ).'</a>'; |
| 468 |
$links[] = '<a href="https://postpaycounter.com/post-pay-counter-pro?utm_source=users_site&utm_medium=plugins_list&utm_campaign=ppcp" title="'.__( 'Go PRO', 'post-pay-counter' ).'">'.__( 'Go PRO', 'post-pay-counter' ).'</a>'; |
| 469 |
$links[] = '<a href="https://postpaycounter.com/addons?utm_source=users_site&utm_medium=plugins_list&utm_campaign=ppc_addons" title="'.__( 'Addons', 'post-pay-counter' ).'">'.__( 'Addons', 'post-pay-counter' ).'</a>'; |
| 470 |
} |
| 471 |
|
| 472 |
return $links; |
| 473 |
} |
| 474 |
|
| 475 |
/** |
| 476 |
* Shows the Options page |
| 477 |
* |
| 478 |
* @access public |
| 479 |
* @since 2.0 |
| 480 |
*/ |
| 481 |
function show_options() { |
| 482 |
global $ppc_global_settings; |
| 483 |
?> |
| 484 |
|
| 485 |
<div class="wrap"> |
| 486 |
<div id="ppc_header"> |
| 487 |
<div id="ppc_header_text"> |
| 488 |
<div id="ppc_header_links"> |
| 489 |
<?php |
| 490 |
/** |
| 491 |
* Filters installed version text displayed in upper-right section of the options page. |
| 492 |
* |
| 493 |
* @since 2.0 |
| 494 |
* @param string installed version text (whole). |
| 495 |
*/ |
| 496 |
echo apply_filters( 'ppc_options_installed_version', __( 'Installed version' , 'post-pay-counter' ).': '.$ppc_global_settings['current_version'].' - <a href="https://postpaycounter.com/forums2/forum/post-pay-counter?utm_source=users_site&utm_medium=options_header&utm_campaign=ppc" title="'.__( 'Support', 'post-pay-counter' ).'" target="_blank">'.__( 'Support', 'post-pay-counter' ).'</a> - <a href="https://postpaycounter.com/category/tutorials?utm_source=users_site&utm_medium=options_header&utm_campaign=ppc" title="'.__( 'Tutorials', 'post-pay-counter' ).'" target="_blank">'.__( 'Tutorials', 'post-pay-counter' ).'</a> - <a href="https://postpaycounter.com/category/questionsanswers?utm_source=users_site&utm_medium=options_header&utm_campaign=ppc" title="'.__( 'Questions & Answers', 'post-pay-counter' ).'" target="_blank">'.__( 'Questions & Answers', 'post-pay-counter' ).'</a>' ); |
| 497 |
|
| 498 |
?> |
| 499 |
</div> |
| 500 |
<h2><?php echo apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ).' - '.__( 'Options', 'post-pay-counter' ); ?></h2> |
| 501 |
<p><?php _e( 'The Post Pay Counter plugin is ready to make handling authors\' payments much, much easier, starting from... now! From this page you can set the plugin up, customizing each possible feature to best suit your needs. Options are divided into groups, and for each of the following boxes you will find details of all the features of the plugin and, for most of them, additional details and examples are available by clicking on the info icon on the right of them.', 'post-pay-counter' ); ?></p> |
| 502 |
<p><?php printf( __( 'Don\'t forget to take our %1$sfeatures survey%2$s to let us know what functions you\'d like to see in future releases of the plugin! Also, if you like this plugin, you may be interested in trying the shiny %3$sPRO version%2$s, containing a whole lot of useful features!', 'post-pay-counter' ), '<a href="https://postpaycounter.com/post-pay-counter-pro/post-pay-counter-pro-features-survey" title="'.__( 'Features survey', 'post-pay-counter' ).'" target="_blank">', '</a>', '<a href="https://postpaycounter.com/post-pay-counter-pro?utm_source=users_site&utm_medium=options_description&utm_campaign=ppcp" title="Post Pay Counter PRO" target="_blank">' ); ?></p> |
| 503 |
</div> |
| 504 |
</div> |
| 505 |
|
| 506 |
<?php |
| 507 |
/** |
| 508 |
* Fires after options page header intro. |
| 509 |
* |
| 510 |
* @since 2.518 |
| 511 |
*/ |
| 512 |
do_action( 'ppc_options_page_after_intro' ); |
| 513 |
|
| 514 |
if( is_numeric( self::$options_page_settings['userid'] ) ) { |
| 515 |
$userdata = get_userdata( self::$options_page_settings['userid'] ); |
| 516 |
?> |
| 517 |
|
| 518 |
<p style="clear: both; text-transform: uppercase; font-size: x-small; margin-bottom: -3px; text-align: center;"> |
| 519 |
<a href="<?php echo $ppc_global_settings['options_menu_link']; ?>" title="<?php _e( 'Go back to general settings' , 'post-pay-counter'); ?>" style="float: left; color: black; "><?php _e( 'Back to general' , 'post-pay-counter'); ?></a> |
| 520 |
<a href="#" id="vaporize_user_settings" accesskey="<?php echo self::$options_page_settings['userid']; ?>" title="<?php _e( 'Delete user\'s settings' , 'post-pay-counter'); ?>" style="float: right; color: red; "><?php _e( 'Delete user\'s settings' , 'post-pay-counter'); ?></a> |
| 521 |
<?php echo __( 'Currently editing user:' , 'post-pay-counter').' "'.$userdata->display_name.'"'; ?> |
| 522 |
</p> |
| 523 |
|
| 524 |
<?php |
| 525 |
} |
| 526 |
|
| 527 |
/** |
| 528 |
* Fires before any metabox has been displayed in options page. |
| 529 |
* |
| 530 |
* @since 2.0 |
| 531 |
*/ |
| 532 |
do_action( 'ppc_html_options_before_boxes' ); |
| 533 |
|
| 534 |
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
| 535 |
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
| 536 |
?> |
| 537 |
|
| 538 |
<div id="poststuff" class="metabox-holder has-right-sidebar"> |
| 539 |
<div id="post-body" class="has-sidebar"> |
| 540 |
<div id="post-body-content" class="has-sidebar-content"> |
| 541 |
|
| 542 |
<?php |
| 543 |
do_meta_boxes( $ppc_global_settings['options_menu_slug'], 'normal', null ); |
| 544 |
?> |
| 545 |
|
| 546 |
</div> |
| 547 |
</div> |
| 548 |
<div id="side-info-column" class="inner-sidebar"> |
| 549 |
|
| 550 |
<?php |
| 551 |
do_meta_boxes( $ppc_global_settings['options_menu_slug'], 'side', null ); |
| 552 |
?> |
| 553 |
|
| 554 |
</div> |
| 555 |
</div> |
| 556 |
</div> |
| 557 |
|
| 558 |
<?php |
| 559 |
} |
| 560 |
|
| 561 |
/** |
| 562 |
* Initilizes stats page (defines time range and stuff like that). |
| 563 |
* Needed to be done before actual HTML loading because the WP_List_Table object needs to be loaded early, or it won't be possible to hide columns. |
| 564 |
* |
| 565 |
* @access public |
| 566 |
* @since 2.700 |
| 567 |
*/ |
| 568 |
function initialize_stats() { |
| 569 |
global $current_user, $ppc_global_settings, $wp_roles; |
| 570 |
$general_settings = PPC_general_functions::get_settings( 'general' ); |
| 571 |
$perm = new PPC_permissions(); |
| 572 |
|
| 573 |
//Validate time range values (start and end), if set. They must be isset, numeric and positive. If something's wrong, start and end time are taken from the default publication time range |
| 574 |
if( ( isset( $_REQUEST['tstart'] ) AND ( ! is_numeric( $_REQUEST['tstart'] ) OR $_REQUEST['tstart'] < 0 ) ) |
| 575 |
OR ( isset( $_REQUEST['tend'] ) AND ( ! is_numeric( $_REQUEST['tend'] ) OR $_REQUEST['tend'] < 0 ) ) ) { |
| 576 |
$_REQUEST['tstart'] = strtotime( $_REQUEST['tstart'].' 00:00:00' ); |
| 577 |
$_REQUEST['tend'] = strtotime( $_REQUEST['tend'].' 23:59:59' ); |
| 578 |
} else if ( ! isset( $_REQUEST['tstart'] ) OR ! isset( $_REQUEST['tend'] ) ) { |
| 579 |
$_REQUEST['tstart'] = $ppc_global_settings['stats_tstart']; |
| 580 |
$_REQUEST['tend'] = $ppc_global_settings['stats_tend']; |
| 581 |
} |
| 582 |
//else the values are correct and valid |
| 583 |
|
| 584 |
//If empty role, or any role, or invalid role => get rid of role param |
| 585 |
if( isset( $_REQUEST['role'] ) AND ( $_REQUEST['role'] == 'ppc_any' OR $_REQUEST['role'] == '' OR ! isset( $wp_roles->role_names[$_REQUEST['role']] ) ) ) |
| 586 |
unset( $_REQUEST['role'] ); |
| 587 |
|
| 588 |
//Assign to global var |
| 589 |
$ppc_global_settings['stats_tstart'] = esc_attr( $_REQUEST['tstart'] ); |
| 590 |
$ppc_global_settings['stats_tend'] = esc_attr( $_REQUEST['tend'] ); |
| 591 |
|
| 592 |
if( isset( $_REQUEST['role'] ) ) |
| 593 |
$ppc_global_settings['stats_role'] = esc_attr( $_REQUEST['role'] ); |
| 594 |
|
| 595 |
//If filtered by user role, add filter to stats generation args and complete page permalink |
| 596 |
if( isset( $ppc_global_settings['stats_role'] ) ) { |
| 597 |
add_filter( 'ppc_get_requested_posts_args', function( $grp_args ) { |
| 598 |
global $ppc_global_settings; |
| 599 |
$grp_args['ppc_allowed_user_roles'] = array( $ppc_global_settings['stats_role'] ); |
| 600 |
return $grp_args; |
| 601 |
} ); |
| 602 |
} |
| 603 |
|
| 604 |
if( is_array( $this->author ) ) { |
| 605 |
|
| 606 |
if( ! $perm->can_see_others_detailed_stats() AND $current_user->ID != $this->author[0] ) |
| 607 |
wp_die( __( 'You do not have sufficient permissions to access this page' ) ); |
| 608 |
|
| 609 |
$this->stats = PPC_generate_stats::produce_stats( $ppc_global_settings['stats_tstart'], $ppc_global_settings['stats_tend'], $this->author ); |
| 610 |
|
| 611 |
if( ! is_wp_error( $this->stats ) ) { |
| 612 |
$option = 'per_page'; |
| 613 |
$args = array( |
| 614 |
'label' => 'Posts', |
| 615 |
'default' => 500, |
| 616 |
'option' => 'ppc_posts_per_page' |
| 617 |
); |
| 618 |
add_screen_option( $option, $args ); |
| 619 |
|
| 620 |
$this->stats_table = apply_filters( 'ppc_init_author_stats_table', new Post_Pay_Counter_Posts_List_Table( $this->stats ), $this->stats, $this->author ); |
| 621 |
} |
| 622 |
|
| 623 |
} else { |
| 624 |
$this->stats = PPC_generate_stats::produce_stats( $ppc_global_settings['stats_tstart'], $ppc_global_settings['stats_tend'] ); |
| 625 |
|
| 626 |
if( ! is_wp_error( $this->stats ) ) { |
| 627 |
$option = 'per_page'; |
| 628 |
$args = array( |
| 629 |
'label' => 'Authors', |
| 630 |
'default' => 50, |
| 631 |
'option' => 'ppc_authors_per_page' |
| 632 |
); |
| 633 |
add_screen_option( $option, $args ); |
| 634 |
|
| 635 |
$this->stats_table = apply_filters( 'ppc_init_general_stats_table', new Post_Pay_Counter_Authors_List_Table( $this->stats ), $this->stats ); |
| 636 |
} |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
/** |
| 641 |
* Saves pagination value in Screen Options. |
| 642 |
* |
| 643 |
* @access public |
| 644 |
* @since 2.700 |
| 645 |
*/ |
| 646 |
function handle_stats_pagination_values( $status, $option, $value ) { |
| 647 |
return $value; |
| 648 |
} |
| 649 |
|
| 650 |
/** |
| 651 |
* Shows the Stats page. |
| 652 |
* |
| 653 |
* @access public |
| 654 |
* @since 2.0 |
| 655 |
*/ |
| 656 |
function show_stats() { |
| 657 |
global $current_user, $ppc_global_settings, $wp_roles; |
| 658 |
$general_settings = PPC_general_functions::get_settings( 'general' ); |
| 659 |
|
| 660 |
/** |
| 661 |
* Fires before any HTML has been output in the stats page. |
| 662 |
* |
| 663 |
* @since 2.0 |
| 664 |
* @param mixed $author author for which stats are displayed. If given, is the only index of an array, NULL means general stats are being requested. |
| 665 |
*/ |
| 666 |
do_action( 'ppc_before_stats_html', $this->author ); |
| 667 |
?> |
| 668 |
|
| 669 |
<div class="wrap"> |
| 670 |
<h2><?php echo apply_filters( "ppc_admin_menu_name", "Post Pay Counter" ) .' - '. __( 'Stats', 'post-pay-counter' ); ?></h2> |
| 671 |
|
| 672 |
<?php |
| 673 |
//AUTHOR STATS |
| 674 |
if( is_array( $this->author ) ) { |
| 675 |
$userdata = get_userdata( $this->author[0] ); |
| 676 |
|
| 677 |
echo PPC_HTML_functions::show_stats_page_header( $userdata->display_name, PPC_general_functions::get_the_author_link( $this->author[0] ) ); |
| 678 |
|
| 679 |
/** |
| 680 |
* Fires before the *author* stats page form and table been output. |
| 681 |
* |
| 682 |
* @since 2.0 |
| 683 |
* @param array $stats a PPC_generate_stats::produce_stats() result - current stats. |
| 684 |
*/ |
| 685 |
do_action( 'ppc_html_stats_author_before_stats_form', $this->stats ); |
| 686 |
|
| 687 |
if( is_wp_error( $this->stats ) ) { |
| 688 |
echo $this->stats->get_error_message(); |
| 689 |
echo '</div>'; |
| 690 |
return; |
| 691 |
} |
| 692 |
|
| 693 |
?> |
| 694 |
|
| 695 |
<form method="post" id="ppc_stats" accesskey="<?php echo $this->author[0]; //accesskey holds author id ?>"> |
| 696 |
<div id="ppc_stats_table"> <!-- PRO mark as paid retrocompatibility --> |
| 697 |
|
| 698 |
<?php |
| 699 |
$cache_time = get_transient( 'ppc_full_stats_snapshot_time' ); |
| 700 |
if( $cache_time ) { |
| 701 |
echo '<div style="float: left; margin-bottom: -20px; font-style: italic;">'.sprintf( __( 'Displayed data comes from a cached snapshot taken in %1$s at %2$s.', 'post-pay-counter' ), date_i18n( get_option( 'date_format' ), $cache_time ), date( 'H:i:s', $cache_time ) ).'</div>'; |
| 702 |
} else if( $general_settings['enable_post_stats_caching'] ) { |
| 703 |
echo '<div style="float: left; margin-bottom: -20px; font-style: italic;">'.__( 'Displayed data is cached. You may have to wait 24 hours for updated data.', 'post-pay-counter' ).'</div>'; |
| 704 |
} |
| 705 |
|
| 706 |
if( isset( $this->stats_table ) AND ! is_wp_error( $this->stats_table ) ) { |
| 707 |
$this->stats_table->prepare_items(); |
| 708 |
$this->stats_table->display(); |
| 709 |
} |
| 710 |
?> |
| 711 |
|
| 712 |
<input type="submit" value="Needed to override payment buttons for PRO users" name="ppc_first_submit" style="display: none;" /> |
| 713 |
|
| 714 |
<?php |
| 715 |
/** |
| 716 |
* Fires after the *author* stats page form and table been output. |
| 717 |
* |
| 718 |
* @since 2.0 |
| 719 |
*/ |
| 720 |
do_action( 'ppc_html_stats_author_after_stats_form' ); |
| 721 |
|
| 722 |
//GENERAL STATS |
| 723 |
} else { |
| 724 |
$page_permalink = $ppc_global_settings['stats_menu_link'].'&tstart='.$ppc_global_settings['stats_tstart'].'&tend='.$ppc_global_settings['stats_tend']; |
| 725 |
|
| 726 |
if( isset( $_REQUEST['ppc-time-range'] ) ) |
| 727 |
$page_permalink .= '&ppc-time-range='.esc_attr( $_REQUEST['ppc-time-range'] ); |
| 728 |
if( isset( $_REQUEST['orderby'] ) ) |
| 729 |
$page_permalink .= '&orderby='.esc_attr( $_REQUEST['orderby'] ); |
| 730 |
if( isset( $_REQUEST['order'] ) ) |
| 731 |
$page_permalink .= '&order='.esc_attr( $_REQUEST['order'] ); |
| 732 |
|
| 733 |
//If filtered by user role, add filter to stats generation args and complete page permalink |
| 734 |
if( isset( $_REQUEST['role'] ) ) |
| 735 |
$page_permalink .= '&role='.$ppc_global_settings['stats_role']; |
| 736 |
|
| 737 |
//If filtered by category, add filter to stats generation args and complete page permalink |
| 738 |
if( isset( $_REQUEST['category'] ) ) |
| 739 |
$page_permalink .= '&category='.$ppc_global_settings['stats_category']; |
| 740 |
|
| 741 |
echo PPC_HTML_functions::show_stats_page_header( __( 'General' , 'post-pay-counter'), admin_url( $page_permalink ) ); |
| 742 |
|
| 743 |
/** |
| 744 |
* Fires before the *general* stats page form and table been output. |
| 745 |
* |
| 746 |
* @since 2.0 |
| 747 |
* @param array $stats a PPC_generate_stats::produce_stats() result - current stats. |
| 748 |
*/ |
| 749 |
do_action( 'ppc_html_stats_general_before_stats_form', $this->stats ); |
| 750 |
|
| 751 |
if( is_wp_error( $this->stats ) ) { |
| 752 |
echo $this->stats->get_error_message(); |
| 753 |
echo '</div>'; |
| 754 |
return; |
| 755 |
} |
| 756 |
?> |
| 757 |
|
| 758 |
<form method="post" id="ppc_stats"> |
| 759 |
<div id="ppc_stats_table"> <!-- PRO mark as paid retrocompatibility --> |
| 760 |
|
| 761 |
<?php |
| 762 |
$cache_time = get_transient( 'ppc_full_stats_snapshot_time' ); |
| 763 |
if( $cache_time ) { |
| 764 |
echo '<div style="float: left; margin-bottom: -20px; font-style: italic;">'.sprintf( __( 'Displayed data comes from a cached snapshot taken in %1$s at %2$s.', 'post-pay-counter' ), date_i18n( get_option( 'date_format' ), $cache_time ), date( 'H:i:s', $cache_time ) ).'</div>'; |
| 765 |
} else if( $general_settings['enable_post_stats_caching'] ) { |
| 766 |
echo '<div style="float: left; margin-bottom: -20px; font-style: italic;">Displayed data is cached. You may have to wait 24 hours for updated data.</div>'; |
| 767 |
} |
| 768 |
|
| 769 |
if( isset( $this->stats_table ) AND ! is_wp_error( $this->stats_table ) ) { |
| 770 |
$this->stats_table->prepare_items(); |
| 771 |
$this->stats_table->display(); |
| 772 |
} |
| 773 |
|
| 774 |
/** |
| 775 |
* Fires after the *general* stats page form and table been output. |
| 776 |
* |
| 777 |
* @since 2.0 |
| 778 |
*/ |
| 779 |
do_action( 'ppc_html_stats_general_after_stats_form' ); |
| 780 |
} |
| 781 |
?> |
| 782 |
|
| 783 |
</div> |
| 784 |
</form> |
| 785 |
<div class="ppc_table_divider"></div> |
| 786 |
|
| 787 |
<?php |
| 788 |
if( $general_settings['display_overall_stats'] ) { |
| 789 |
$overall_stats = PPC_generate_stats::get_overall_stats( $this->stats['raw_stats'] ); |
| 790 |
echo PPC_HTML_functions::print_overall_stats( $overall_stats ); |
| 791 |
|
| 792 |
/** |
| 793 |
* Fires after the overall stats table been output. |
| 794 |
* |
| 795 |
* @since 2.0 |
| 796 |
*/ |
| 797 |
do_action( 'ppc_html_stats_after_overall_stats' ); |
| 798 |
} |
| 799 |
?> |
| 800 |
|
| 801 |
</div> |
| 802 |
|
| 803 |
<?php |
| 804 |
} |
| 805 |
} |
| 806 |
|
| 807 |
/** |
| 808 |
* Loads localization files |
| 809 |
* |
| 810 |
* @access public |
| 811 |
* @since 2.0 |
| 812 |
*/ |
| 813 |
function ppc_load_localization() { |
| 814 |
load_plugin_textdomain( 'post-pay-counter', false, dirname( plugin_basename( __FILE__ ) ).'/lang/' ); |
| 815 |
} |
| 816 |
add_action( 'plugins_loaded', 'ppc_load_localization' ); |
| 817 |
|
| 818 |
global $ppc_global_settings; |
| 819 |
$ppc_global_settings = array(); |
| 820 |
new post_pay_counter(); |
| 821 |
|