columns.php
12 years ago
counter.php
12 years ago
cron.php
12 years ago
frontend.php
11 years ago
functions.php
12 years ago
query.php
12 years ago
settings.php
12 years ago
update.php
12 years ago
widgets.php
12 years ago
settings.php
861 lines
| 1 | <?php |
| 2 | if(!defined('ABSPATH')) exit; |
| 3 | |
| 4 | new Post_Views_Counter_Settings(); |
| 5 | |
| 6 | class Post_Views_Counter_Settings |
| 7 | { |
| 8 | private $tabs; |
| 9 | private $choices; |
| 10 | private $modes; |
| 11 | private $time_types; |
| 12 | private $groups; |
| 13 | private $user_roles; |
| 14 | private $positions; |
| 15 | private $display_styles; |
| 16 | public $post_types; |
| 17 | |
| 18 | |
| 19 | public function __construct() |
| 20 | { |
| 21 | // sets instance |
| 22 | Post_Views_Counter()->add_instance('settings', $this); |
| 23 | |
| 24 | // actions |
| 25 | add_action('admin_init', array(&$this, 'register_settings')); |
| 26 | add_action('admin_menu', array(&$this, 'admin_menu_options')); |
| 27 | add_action('after_setup_theme', array(&$this, 'load_defaults')); |
| 28 | add_action('wp_loaded', array(&$this, 'load_post_types')); |
| 29 | |
| 30 | // filters |
| 31 | add_filter('plugin_row_meta', array(&$this, 'plugin_extend_links'), 10, 2); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * |
| 37 | */ |
| 38 | public function load_defaults() |
| 39 | { |
| 40 | $this->choices = array( |
| 41 | 'yes' => __('Enable', 'post-views-counter'), |
| 42 | 'no' => __('Disable', 'post-views-counter') |
| 43 | ); |
| 44 | |
| 45 | $this->modes = array( |
| 46 | 'php' => __('PHP', 'post-views-counter'), |
| 47 | 'js' => __('JavaScript', 'post-views-counter') |
| 48 | ); |
| 49 | |
| 50 | $this->time_types = array( |
| 51 | 'minutes' => __('minutes', 'post-views-counter'), |
| 52 | 'hours' => __('hours', 'post-views-counter'), |
| 53 | 'days' => __('days', 'post-views-counter'), |
| 54 | 'weeks' => __('weeks', 'post-views-counter'), |
| 55 | 'months' => __('months', 'post-views-counter'), |
| 56 | 'years' => __('years', 'post-views-counter') |
| 57 | ); |
| 58 | |
| 59 | $this->groups = array( |
| 60 | 'robots' => __('robots', 'post-views-counter'), |
| 61 | 'users' => __('logged in users', 'post-views-counter'), |
| 62 | 'guests' => __('guests', 'post-views-counter'), |
| 63 | 'roles' => __('selected user roles', 'post-views-counter') |
| 64 | ); |
| 65 | |
| 66 | $this->positions = array( |
| 67 | 'before' => __('before the content', 'post-views-counter'), |
| 68 | 'after' => __('after the content', 'post-views-counter'), |
| 69 | 'manual' => __('manual', 'post-views-counter') |
| 70 | ); |
| 71 | |
| 72 | $this->display_styles = array( |
| 73 | 'icon' => __('icon', 'post-views-counter'), |
| 74 | 'text' => __('label', 'post-views-counter') |
| 75 | ); |
| 76 | |
| 77 | $this->tabs = array( |
| 78 | 'general' => array( |
| 79 | 'name' => __('General', 'post-views-counter'), |
| 80 | 'key' => 'post_views_counter_settings_general', |
| 81 | 'submit' => 'save_pvc_general', |
| 82 | 'reset' => 'reset_pvc_general' |
| 83 | ), |
| 84 | 'display' => array( |
| 85 | 'name' => __('Display', 'post-views-counter'), |
| 86 | 'key' => 'post_views_counter_settings_display', |
| 87 | 'submit' => 'save_pvc_display', |
| 88 | 'reset' => 'reset_pvc_display' |
| 89 | ) |
| 90 | ); |
| 91 | |
| 92 | $this->user_roles = $this->get_users_roles(); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | /** |
| 97 | * |
| 98 | */ |
| 99 | public function load_post_types() |
| 100 | { |
| 101 | $post_types = array(); |
| 102 | |
| 103 | // built in public post types |
| 104 | foreach(get_post_types(array('_builtin' => true, 'public' => true), 'objects', 'and') as $key => $post_type) |
| 105 | { |
| 106 | if($key !== 'attachment') |
| 107 | $post_types[$key] = $post_type->labels->name; |
| 108 | } |
| 109 | |
| 110 | // public custom post types |
| 111 | foreach(get_post_types(array('_builtin' => false, 'public' => true), 'objects', 'and') as $key => $post_type) |
| 112 | { |
| 113 | $post_types[$key] = $post_type->labels->name; |
| 114 | } |
| 115 | |
| 116 | // sorts post types alphabetically with their keys |
| 117 | asort($post_types, SORT_STRING); |
| 118 | |
| 119 | $this->post_types = $post_types; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /** |
| 124 | * Gets all users roles |
| 125 | */ |
| 126 | public function get_users_roles() |
| 127 | { |
| 128 | global $wp_roles; |
| 129 | |
| 130 | $roles = array(); |
| 131 | |
| 132 | foreach(apply_filters('editable_roles', $wp_roles->roles) as $role => $details) |
| 133 | { |
| 134 | $roles[$role] = translate_user_role($details['name']); |
| 135 | } |
| 136 | |
| 137 | asort($roles, SORT_STRING); |
| 138 | |
| 139 | return $roles; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | /** |
| 144 | * Adds options page |
| 145 | */ |
| 146 | public function admin_menu_options() |
| 147 | { |
| 148 | add_options_page( |
| 149 | __('Post Views Counter', 'post-views-counter'), |
| 150 | __('Post Views Counter', 'post-views-counter'), |
| 151 | 'manage_options', |
| 152 | 'post-views-counter', |
| 153 | array(&$this, 'options_page') |
| 154 | ); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * |
| 160 | */ |
| 161 | public function options_page() |
| 162 | { |
| 163 | $tab_key = (isset($_GET['tab']) ? $_GET['tab'] : 'general'); |
| 164 | |
| 165 | echo ' |
| 166 | <div class="wrap">'.screen_icon().' |
| 167 | <h2>'.__('Post Views Counter', 'post-views-counter').'</h2> |
| 168 | <h2 class="nav-tab-wrapper">'; |
| 169 | |
| 170 | foreach($this->tabs as $key => $name) |
| 171 | { |
| 172 | echo ' |
| 173 | <a class="nav-tab '.($tab_key == $key ? 'nav-tab-active' : '').'" href="'.esc_url(admin_url('options-general.php?page=post-views-counter&tab='.$key)).'">'.$name['name'].'</a>'; |
| 174 | } |
| 175 | |
| 176 | echo ' |
| 177 | </h2> |
| 178 | <div class="post-views-counter-settings"> |
| 179 | <div class="df-credits"> |
| 180 | <h3 class="hndle">'.__('Post Views Counter', 'post-views-counter').' '.Post_Views_Counter()->get_attribute('defaults', 'version').'</h3> |
| 181 | <div class="inside"> |
| 182 | <h4 class="inner">'.__('Need support?', 'post-views-counter').'</h4> |
| 183 | <p class="inner">'.__('If you are having problems with this plugin, please talk about them in the', 'post-views-counter').' <a href="http://www.dfactory.eu/support/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=support" target="_blank" title="'.__('Support forum', 'post-views-counter').'">'.__('Support forum', 'post-views-counter').'</a></p> |
| 184 | <hr /> |
| 185 | <h4 class="inner">'.__('Do you like this plugin?', 'post-views-counter').'</h4> |
| 186 | <p class="inner"><a href="http://wordpress.org/support/view/plugin-reviews/post-views-counter" target="_blank" title="'.__('Rate it 5', 'events-maker').'">'.__('Rate it 5', 'post-views-counter').'</a> '.__('on WordPress.org', 'post-views-counter').'<br />'. |
| 187 | __('Blog about it & link to the', 'post-views-counter').' <a href="http://www.dfactory.eu/plugins/post-views-counter/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=blog-about" target="_blank" title="'.__('plugin page', 'post-views-counter').'">'.__('plugin page', 'post-views-counter').'</a><br/>'. |
| 188 | __('Check out our other', 'post-views-counter').' <a href="http://www.dfactory.eu/plugins/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=other-plugins" target="_blank" title="'.__('WordPress plugins', 'post-views-counter').'">'.__('WordPress plugins', 'post-views-counter').'</a> |
| 189 | </p> |
| 190 | <hr /> |
| 191 | <p class="df-link inner">'.__('Created by', 'post-views-counter').' <a href="http://www.dfactory.eu/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=created-by" target="_blank" title="dFactory - Quality plugins for WordPress"><img src="'.POST_VIEWS_COUNTER_URL.'/images/logo-dfactory.png'.'" title="dFactory - Quality plugins for WordPress" alt="dFactory - Quality plugins for WordPress" /></a></p> |
| 192 | </div> |
| 193 | </div> |
| 194 | <form action="options.php" method="post">'; |
| 195 | |
| 196 | wp_nonce_field('update-options'); |
| 197 | settings_fields($this->tabs[$tab_key]['key']); |
| 198 | do_settings_sections($this->tabs[$tab_key]['key']); |
| 199 | |
| 200 | echo ' |
| 201 | <p class="submit">'; |
| 202 | |
| 203 | submit_button('', 'primary', $this->tabs[$tab_key]['submit'], FALSE); |
| 204 | |
| 205 | echo ' '; |
| 206 | |
| 207 | submit_button(__('Reset to defaults', 'post-views-counter'), 'secondary reset_pvc_settings', $this->tabs[$tab_key]['reset'], FALSE); |
| 208 | |
| 209 | echo ' |
| 210 | </p> |
| 211 | </form> |
| 212 | </div> |
| 213 | <div class="clear"></div> |
| 214 | </div>'; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | /** |
| 219 | * |
| 220 | */ |
| 221 | public function register_settings() |
| 222 | { |
| 223 | // general options |
| 224 | register_setting('post_views_counter_settings_general', 'post_views_counter_settings_general', array(&$this, 'validate_settings')); |
| 225 | add_settings_section('post_views_counter_settings_general', __('General settings', 'post-views-counter'), '', 'post_views_counter_settings_general'); |
| 226 | add_settings_field('pvc_post_types_count', __('Post Types Count', 'post-views-counter'), array(&$this, 'post_types_count'), 'post_views_counter_settings_general', 'post_views_counter_settings_general'); |
| 227 | add_settings_field('pvc_counter_mode', __('Counter Mode', 'post-views-counter'), array(&$this, 'counter_mode'), 'post_views_counter_settings_general', 'post_views_counter_settings_general'); |
| 228 | add_settings_field('pvc_post_views_column', __('Post Views Column', 'post-views-counter'), array(&$this, 'post_views_column'), 'post_views_counter_settings_general', 'post_views_counter_settings_general'); |
| 229 | add_settings_field('pvc_time_between_counts', __('Time Between Counts', 'post-views-counter'), array(&$this, 'time_between_counts'), 'post_views_counter_settings_general', 'post_views_counter_settings_general'); |
| 230 | add_settings_field('pvc_reset_counts', __('Reset Data', 'post-views-counter'), array(&$this, 'reset_counts'), 'post_views_counter_settings_general', 'post_views_counter_settings_general'); |
| 231 | add_settings_field('pvc_exclude', __('Exclude Visitors', 'post-views-counter'), array(&$this, 'exclude'), 'post_views_counter_settings_general', 'post_views_counter_settings_general'); |
| 232 | add_settings_field('pvc_exclude_ips', __('Exclude IPs', 'post-views-counter'), array(&$this, 'exclude_ips'), 'post_views_counter_settings_general', 'post_views_counter_settings_general'); |
| 233 | add_settings_field('pvc_wp_postviews', __('WP-PostViews', 'post-views-counter'), array(&$this, 'wp_postviews'), 'post_views_counter_settings_general', 'post_views_counter_settings_general'); |
| 234 | add_settings_field('pvc_deactivation_delete', __('Deactivation', 'post-views-counter'), array(&$this, 'deactivation_delete'), 'post_views_counter_settings_general', 'post_views_counter_settings_general'); |
| 235 | |
| 236 | // display options |
| 237 | register_setting('post_views_counter_settings_display', 'post_views_counter_settings_display', array(&$this, 'validate_settings')); |
| 238 | add_settings_section('post_views_counter_settings_display', __('Display settings', 'post-views-counter'), '', 'post_views_counter_settings_display'); |
| 239 | add_settings_field('pvc_post_views_label', __('Post Views Label', 'post-views-counter'), array(&$this, 'post_views_label'), 'post_views_counter_settings_display', 'post_views_counter_settings_display'); |
| 240 | add_settings_field('pvc_post_types_display', __('Post Types Display', 'post-views-counter'), array(&$this, 'post_types_display'), 'post_views_counter_settings_display', 'post_views_counter_settings_display'); |
| 241 | add_settings_field('pvc_restrict_display', __('Restrict Display', 'post-views-counter'), array(&$this, 'restrict_display'), 'post_views_counter_settings_display', 'post_views_counter_settings_display'); |
| 242 | add_settings_field('pvc_position', __('Position', 'post-views-counter'), array(&$this, 'position'), 'post_views_counter_settings_display', 'post_views_counter_settings_display'); |
| 243 | add_settings_field('pvc_display_style', __('Display Style', 'post-views-counter'), array(&$this, 'display_style'), 'post_views_counter_settings_display', 'post_views_counter_settings_display'); |
| 244 | add_settings_field('pvc_icon_class', __('Icon Class', 'post-views-counter'), array(&$this, 'icon_class'), 'post_views_counter_settings_display', 'post_views_counter_settings_display'); |
| 245 | } |
| 246 | |
| 247 | |
| 248 | /** |
| 249 | * |
| 250 | */ |
| 251 | public function post_views_label() |
| 252 | { |
| 253 | echo ' |
| 254 | <div id="pvc_post_views_label"> |
| 255 | <fieldset> |
| 256 | <input type="text" class="large-text" name="post_views_counter_settings_display[label]" value="'.esc_attr(Post_Views_Counter()->get_attribute('options', 'display', 'label')).'" /> |
| 257 | <br/> |
| 258 | <span class="description">'.esc_html__('Enter the label for the post views counter field.', 'post-views-counter').'</span> |
| 259 | </fieldset> |
| 260 | </div>'; |
| 261 | } |
| 262 | |
| 263 | |
| 264 | /** |
| 265 | * |
| 266 | */ |
| 267 | public function post_types_count() |
| 268 | { |
| 269 | echo ' |
| 270 | <div id="pvc_post_types_count"> |
| 271 | <fieldset> |
| 272 | <select class="pvc-chosen" data-placeholder="'.esc_attr__('Select post types', 'post-views-counter').'" name="post_views_counter_settings_general[post_types_count][]" multiple="multiple">'; |
| 273 | |
| 274 | foreach($this->post_types as $post_type => $post_type_name) |
| 275 | { |
| 276 | echo ' |
| 277 | <option value="'.esc_attr($post_type).'" '.selected(in_array($post_type, Post_Views_Counter()->get_attribute('options', 'general', 'post_types_count'), true), true, false).'>'.esc_html($post_type_name).'</option>'; |
| 278 | } |
| 279 | |
| 280 | echo ' |
| 281 | </select> |
| 282 | <br/> |
| 283 | <span class="description">'.esc_html__('Select post types for which post views will be counted.', 'post-views-counter').'</span> |
| 284 | </fieldset> |
| 285 | </div>'; |
| 286 | } |
| 287 | |
| 288 | |
| 289 | /** |
| 290 | * |
| 291 | */ |
| 292 | public function post_types_display() |
| 293 | { |
| 294 | echo ' |
| 295 | <div id="pvc_post_types_display"> |
| 296 | <fieldset> |
| 297 | <select class="pvc-chosen" data-placeholder="'.esc_attr__('Select groups', 'post-views-counter').'" name="post_views_counter_settings_display[post_types_display][]" multiple="multiple">'; |
| 298 | |
| 299 | foreach($this->post_types as $post_type => $post_type_name) |
| 300 | { |
| 301 | echo ' |
| 302 | <option value="'.esc_attr($post_type).'" '.selected(in_array($post_type, Post_Views_Counter()->get_attribute('options', 'display', 'post_types_display'), true), true, false).'>'.esc_html($post_type_name).'</option>'; |
| 303 | } |
| 304 | |
| 305 | echo ' |
| 306 | </select> |
| 307 | <br/> |
| 308 | <span class="description">'.esc_html__('Select post types for which post views will be displayed.', 'post-views-counter').'</span> |
| 309 | </fieldset> |
| 310 | </div>'; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * |
| 315 | */ |
| 316 | public function counter_mode() |
| 317 | { |
| 318 | echo ' |
| 319 | <div id="pvc_counter_mode"> |
| 320 | <fieldset>'; |
| 321 | |
| 322 | foreach($this->modes as $key => $value) |
| 323 | { |
| 324 | $key = esc_attr($key); |
| 325 | |
| 326 | echo ' |
| 327 | <input id="pvc-counter-mode-'.$key.'" type="radio" name="post_views_counter_settings_general[counter_mode]" value="'.$key.'" '.checked($key, Post_Views_Counter()->get_attribute('options', 'general', 'counter_mode'), false).' /><label for="pvc-counter-mode-'.$key.'">'.esc_html($value).'</label>'; |
| 328 | } |
| 329 | |
| 330 | echo ' |
| 331 | <br/> |
| 332 | <span class="description">'.esc_html__('Select the method of collecting post views data. If you are using any of the caching plugins select Javascript.', 'post-views-counter').'</span> |
| 333 | </fieldset> |
| 334 | </div>'; |
| 335 | } |
| 336 | |
| 337 | |
| 338 | /** |
| 339 | * |
| 340 | */ |
| 341 | public function post_views_column() |
| 342 | { |
| 343 | echo ' |
| 344 | <div id="pvc_post_views_column"> |
| 345 | <fieldset>'; |
| 346 | |
| 347 | foreach($this->choices as $key => $value) |
| 348 | { |
| 349 | $key = esc_attr($key); |
| 350 | |
| 351 | echo ' |
| 352 | <input id="pvc-post-views-column-'.$key.'" type="radio" name="post_views_counter_settings_general[post_views_column]" value="'.$key.'" '.checked($key, (Post_Views_Counter()->get_attribute('options', 'general', 'post_views_column') === true ? 'yes' : 'no'), false).' /><label for="pvc-post-views-column-'.$key.'">'.esc_html($value).'</label>'; |
| 353 | } |
| 354 | |
| 355 | echo ' |
| 356 | <br/> |
| 357 | <span class="description">'.esc_html__('Enable to display post views count column for each of the selected post types.', 'post-views-counter').'</span> |
| 358 | </fieldset> |
| 359 | </div>'; |
| 360 | } |
| 361 | |
| 362 | |
| 363 | /** |
| 364 | * |
| 365 | */ |
| 366 | public function time_between_counts() |
| 367 | { |
| 368 | echo ' |
| 369 | <div id="pvc_time_between_counts"> |
| 370 | <fieldset> |
| 371 | <input size="4" type="text" name="post_views_counter_settings_general[time_between_counts][number]" value="'.esc_attr(Post_Views_Counter()->get_attribute('options', 'general', 'time_between_counts', 'number')).'" /> |
| 372 | <select class="pvc-chosen-short" name="post_views_counter_settings_general[time_between_counts][type]">'; |
| 373 | |
| 374 | foreach($this->time_types as $type => $type_name) |
| 375 | { |
| 376 | echo ' |
| 377 | <option value="'.esc_attr($type).'" '.selected($type, Post_Views_Counter()->get_attribute('options', 'general', 'time_between_counts', 'type'), false).'>'.esc_html($type_name).'</option>'; |
| 378 | } |
| 379 | |
| 380 | echo ' |
| 381 | </select> |
| 382 | <br/> |
| 383 | <span class="description">'.esc_html__('Enter the time between single user visit count.', 'post-views-counter').'</span> |
| 384 | </fieldset> |
| 385 | </div>'; |
| 386 | } |
| 387 | |
| 388 | |
| 389 | /** |
| 390 | * |
| 391 | */ |
| 392 | public function reset_counts() |
| 393 | { |
| 394 | echo ' |
| 395 | <div id="pvc_reset_counts"> |
| 396 | <fieldset> |
| 397 | <input size="4" type="text" name="post_views_counter_settings_general[reset_counts][number]" value="'.esc_attr(Post_Views_Counter()->get_attribute('options', 'general', 'reset_counts', 'number')).'" /> |
| 398 | <select class="pvc-chosen-short" name="post_views_counter_settings_general[reset_counts][type]">'; |
| 399 | |
| 400 | foreach($this->time_types as $type => $type_name) |
| 401 | { |
| 402 | echo ' |
| 403 | <option value="'.esc_attr($type).'" '.selected($type, Post_Views_Counter()->get_attribute('options', 'general', 'reset_counts', 'type'), false).'>'.esc_html($type_name).'</option>'; |
| 404 | } |
| 405 | |
| 406 | echo ' |
| 407 | </select> |
| 408 | <br/> |
| 409 | <span class="description">'.esc_html__('Delete single day post views data older than specified above. Enter 0 (number zero) if you want to preserve your data regardless of its age.', 'post-views-counter').'</span> |
| 410 | </fieldset> |
| 411 | </div>'; |
| 412 | } |
| 413 | |
| 414 | |
| 415 | /** |
| 416 | * |
| 417 | */ |
| 418 | public function exclude() |
| 419 | { |
| 420 | echo ' |
| 421 | <div id="pvc_exclude"> |
| 422 | <fieldset> |
| 423 | <select class="pvc-chosen" data-placeholder="'.esc_attr__('Select groups', 'post-views-counter').'" name="post_views_counter_settings_general[exclude][groups][]" multiple="multiple">'; |
| 424 | |
| 425 | foreach($this->groups as $type => $type_name) |
| 426 | { |
| 427 | echo ' |
| 428 | <option value="'.esc_attr($type).'" '.selected(in_array($type, Post_Views_Counter()->get_attribute('options', 'general', 'exclude', 'groups'), true), true, false).'>'.esc_html($type_name).'</option>'; |
| 429 | } |
| 430 | |
| 431 | echo ' |
| 432 | </select> |
| 433 | <br/> |
| 434 | <div class="pvc_user_roles"'.(in_array('roles', Post_Views_Counter()->get_attribute('options', 'general', 'exclude', 'groups'), true) ? '' : ' style="display: none;"').'> |
| 435 | <select class="pvc-chosen" data-placeholder="'.esc_attr__('Select user roles', 'post-views-counter').'" name="post_views_counter_settings_general[exclude][roles][]" multiple="multiple">'; |
| 436 | |
| 437 | foreach($this->user_roles as $role => $role_name) |
| 438 | { |
| 439 | echo ' |
| 440 | <option value="'.esc_attr($role).'" '.selected(in_array($role, Post_Views_Counter()->get_attribute('options', 'general', 'exclude', 'roles'), true), true, false).'>'.esc_html($role_name).'</option>'; |
| 441 | } |
| 442 | |
| 443 | echo ' |
| 444 | </select> |
| 445 | <br/> |
| 446 | </div> |
| 447 | <span class="description">'.esc_html__('Select the type of visitors to be excluded from post views count.', 'post-views-counter').'</span> |
| 448 | </fieldset> |
| 449 | </div>'; |
| 450 | } |
| 451 | |
| 452 | |
| 453 | /** |
| 454 | * |
| 455 | */ |
| 456 | public function exclude_ips() |
| 457 | { |
| 458 | echo ' |
| 459 | <div id="pvc_exclude_ips"> |
| 460 | <fieldset>'; |
| 461 | |
| 462 | foreach(Post_Views_Counter()->get_attribute('options', 'general', 'exclude_ips') as $key => $ip) |
| 463 | { |
| 464 | echo ' |
| 465 | <div class="ip-box"> |
| 466 | <input type="text" name="post_views_counter_settings_general[exclude_ips][]" value="'.esc_attr($ip).'" /> <input type="button" class="button button-secondary remove-exclude-ip" value="'.esc_attr__('Remove', 'post-views-counter').'" /> |
| 467 | </div>'; |
| 468 | } |
| 469 | |
| 470 | // lovely php 5.2 limitations |
| 471 | $ips = Post_Views_Counter()->get_attribute('options', 'general', 'exclude_ips'); |
| 472 | |
| 473 | echo ' |
| 474 | <div class="ip-box"> |
| 475 | <input type="text" name="post_views_counter_settings_general[exclude_ips][]" value="" /> <input type="button" class="button button-secondary remove-exclude-ip" value="'.esc_attr__('Remove', 'post-views-counter').'"'.(empty($ips) ? ' style="display: none;"' : '').' /> <input type="button" class="button button-secondary add-exclude-ip" value="'.esc_attr__('Add new', 'post-views-counter').'" /> <input type="button" class="button button-secondary add-current-ip" value="'.esc_attr__('Add my current IP', 'post-views-counter').'" data-rel="'.esc_attr($_SERVER['REMOTE_ADDR']).'" /> |
| 476 | </div> |
| 477 | <span class="description">'.esc_html__('Enter the IP addresses to be excluded from post views count.', 'post-views-counter').'</span> |
| 478 | </fieldset> |
| 479 | </div>'; |
| 480 | } |
| 481 | |
| 482 | |
| 483 | /** |
| 484 | * |
| 485 | */ |
| 486 | public function wp_postviews() |
| 487 | { |
| 488 | echo ' |
| 489 | <div id="pvc_wp_postviews"> |
| 490 | <fieldset> |
| 491 | <input type="submit" class="button button-secondary" name="post_views_counter_import_wp_postviews" value="'.__('Import', 'post-views-counter').'"/> |
| 492 | <br/> |
| 493 | <p class="description">'.esc_html__('Import post views data from WP-PostViews plugin.', 'post-views-counter').'</p> |
| 494 | <input id="pvc-wp-postviews" type="checkbox" name="post_views_counter_import_wp_postviews_override"/><label for="pvc-wp-postviews">'.esc_html__('Override existing Post Views Counter data.', 'post-views-counter').'</label> |
| 495 | </fieldset> |
| 496 | </div>'; |
| 497 | } |
| 498 | |
| 499 | |
| 500 | /** |
| 501 | * |
| 502 | */ |
| 503 | public function deactivation_delete() |
| 504 | { |
| 505 | echo ' |
| 506 | <div id="pvc_deactivation_delete"> |
| 507 | <fieldset>'; |
| 508 | |
| 509 | foreach($this->choices as $key => $value) |
| 510 | { |
| 511 | $key = esc_attr($key); |
| 512 | |
| 513 | echo ' |
| 514 | <input id="pvc-deactivation-delete-'.$key.'" type="radio" name="post_views_counter_settings_general[deactivation_delete]" value="'.$key.'" '.checked($key, (Post_Views_Counter()->get_attribute('options', 'general', 'deactivation_delete') === true ? 'yes' : 'no'), false).' /><label for="pvc-deactivation-delete-'.$key.'">'.esc_html($value).'</label>'; |
| 515 | } |
| 516 | |
| 517 | echo ' |
| 518 | <br/> |
| 519 | <span class="description">'.esc_html__('Enable to delete all plugin data on deactivation.', 'post-views-counter').'</span> |
| 520 | </fieldset> |
| 521 | </div>'; |
| 522 | } |
| 523 | |
| 524 | |
| 525 | /** |
| 526 | * |
| 527 | */ |
| 528 | public function position() |
| 529 | { |
| 530 | echo ' |
| 531 | <div id="pvc_position"> |
| 532 | <fieldset> |
| 533 | <select class="pvc-chosen-short" name="post_views_counter_settings_display[position]">'; |
| 534 | |
| 535 | foreach($this->positions as $position => $position_name) |
| 536 | { |
| 537 | echo ' |
| 538 | <option value="'.esc_attr($position).'" '.selected($position, Post_Views_Counter()->get_attribute('options', 'display', 'position'), false).'>'.esc_html($position_name).'</option>'; |
| 539 | } |
| 540 | |
| 541 | echo ' |
| 542 | </select> |
| 543 | <br/> |
| 544 | <span class="description">'.esc_html__('Select where would you like to display the post views counter. Use [post-views] shortcode for manual display.', 'post-views-counter').'</span> |
| 545 | </fieldset> |
| 546 | </div>'; |
| 547 | } |
| 548 | |
| 549 | |
| 550 | /** |
| 551 | * |
| 552 | */ |
| 553 | public function display_style() |
| 554 | { |
| 555 | echo ' |
| 556 | <div id="pvc_display_style"> |
| 557 | <fieldset>'; |
| 558 | |
| 559 | foreach($this->display_styles as $display => $style) |
| 560 | { |
| 561 | $display = esc_attr($display); |
| 562 | |
| 563 | echo ' |
| 564 | <input id="pvc-display-style-'.$display.'" type="checkbox" name="post_views_counter_settings_display[display_style]['.$display.']" value="'.$display.'" '.checked(true, Post_Views_Counter()->get_attribute('options', 'display', 'display_style', $display), false).' /><label for="pvc-display-style-'.$display.'">'.esc_html($style).'</label>'; |
| 565 | } |
| 566 | |
| 567 | echo ' |
| 568 | <br/> |
| 569 | <span class="description">'.esc_html__('Choose how to display the post views counter.', 'post-views-counter').'</span> |
| 570 | </fieldset> |
| 571 | </div>'; |
| 572 | } |
| 573 | |
| 574 | |
| 575 | /** |
| 576 | * |
| 577 | */ |
| 578 | public function icon_class() |
| 579 | { |
| 580 | echo ' |
| 581 | <div id="pvc_icon_class"> |
| 582 | <fieldset> |
| 583 | <input type="text" name="post_views_counter_settings_display[icon_class]" class="large-text" value="'.esc_attr(Post_Views_Counter()->get_attribute('options', 'display', 'icon_class')).'"/> |
| 584 | <br/> |
| 585 | <span class="description">'.sprintf(__('Enter the post views icon class. Any of the <a href="%s" target="_blank">Dashicons</a> classes are available.', 'post-views-counter'), 'http://melchoyce.github.io/dashicons/').'</span> |
| 586 | </fieldset> |
| 587 | </div>'; |
| 588 | } |
| 589 | |
| 590 | |
| 591 | /** |
| 592 | * |
| 593 | */ |
| 594 | public function restrict_display() |
| 595 | { |
| 596 | echo ' |
| 597 | <div id="pvc_restrict_display"> |
| 598 | <fieldset> |
| 599 | <select class="pvc-chosen" data-placeholder="'.esc_attr__('Select groups', 'post-views-counter').'" name="post_views_counter_settings_display[restrict_display][groups][]" multiple="multiple">'; |
| 600 | |
| 601 | foreach($this->groups as $type => $type_name) |
| 602 | { |
| 603 | if($type === 'robots') |
| 604 | continue; |
| 605 | |
| 606 | echo ' |
| 607 | <option value="'.esc_attr($type).'" '.selected(in_array($type, Post_Views_Counter()->get_attribute('options', 'display', 'restrict_display', 'groups'), true), true, false).'>'.esc_html($type_name).'</option>'; |
| 608 | } |
| 609 | |
| 610 | echo ' |
| 611 | </select> |
| 612 | <br/> |
| 613 | <div class="pvc_user_roles"'.(in_array('roles', Post_Views_Counter()->get_attribute('options', 'display', 'restrict_display', 'groups'), true) ? '' : ' style="display: none;"').'> |
| 614 | <select class="pvc-chosen" data-placeholder="'.esc_attr__('Select user roles', 'post-views-counter').'" name="post_views_counter_settings_display[restrict_display][roles][]" multiple="multiple">'; |
| 615 | |
| 616 | foreach($this->user_roles as $role => $role_name) |
| 617 | { |
| 618 | echo ' |
| 619 | <option value="'.esc_attr($role).'" '.selected(in_array($role, Post_Views_Counter()->get_attribute('options', 'display', 'restrict_display', 'roles'), true), true, false).'>'.esc_html($role_name).'</option>'; |
| 620 | } |
| 621 | |
| 622 | echo ' |
| 623 | </select> |
| 624 | <br/> |
| 625 | </div> |
| 626 | <span class="description">'.esc_html__('Use it to hide the post views counter from selected type of visitors.', 'post-views-counter').'</span> |
| 627 | </fieldset> |
| 628 | </div>'; |
| 629 | } |
| 630 | |
| 631 | |
| 632 | /** |
| 633 | * Validates general settings |
| 634 | */ |
| 635 | public function validate_settings($input) |
| 636 | { |
| 637 | if(isset($_POST['post_views_counter_import_wp_postviews'])) |
| 638 | { |
| 639 | global $wpdb; |
| 640 | |
| 641 | $views = $wpdb->get_results( |
| 642 | "SELECT post_id, meta_value FROM ".$wpdb->postmeta." WHERE meta_key = 'views'", |
| 643 | ARRAY_A, |
| 644 | 0 |
| 645 | ); |
| 646 | |
| 647 | if(!empty($views)) |
| 648 | { |
| 649 | $input = Post_Views_Counter()->get_attribute('defaults', 'general'); |
| 650 | $input['wp_postviews_import'] = true; |
| 651 | |
| 652 | $sql = ''; |
| 653 | |
| 654 | foreach($views as $view) |
| 655 | { |
| 656 | $sql[] = "(".$view['post_id'].", 4, 'total', ".$view['meta_value'].")"; |
| 657 | } |
| 658 | |
| 659 | $wpdb->query("INSERT INTO ".$wpdb->prefix."post_views(id, type, period, count) VALUES ".implode(',', $sql)." ON DUPLICATE KEY UPDATE count = ".(isset($_POST['post_views_counter_import_wp_postviews_override']) ? '' : 'count + ')."VALUES(count)"); |
| 660 | |
| 661 | add_settings_error('wp_postviews_import', 'wp_postviews_import', __('WP-PostViews data imported succesfully.', 'post-views-counter'), 'updated'); |
| 662 | } |
| 663 | else |
| 664 | { |
| 665 | add_settings_error('wp_postviews_import', 'wp_postviews_import', __('There was no data to import.', 'post-views-counter'), 'updated'); |
| 666 | } |
| 667 | } |
| 668 | elseif(isset($_POST['save_pvc_general'])) |
| 669 | { |
| 670 | // post types count |
| 671 | if(isset($input['post_types_count'])) |
| 672 | { |
| 673 | $post_types = array(); |
| 674 | |
| 675 | foreach($input['post_types_count'] as $post_type) |
| 676 | { |
| 677 | if(isset($this->post_types[$post_type])) |
| 678 | $post_types[] = $post_type; |
| 679 | } |
| 680 | |
| 681 | $input['post_types_count'] = array_unique($post_types); |
| 682 | } |
| 683 | else |
| 684 | $input['post_types_count'] = array(); |
| 685 | |
| 686 | // counter mode |
| 687 | $input['counter_mode'] = (isset($input['counter_mode'], $this->modes[$input['counter_mode']]) ? $input['counter_mode'] : Post_Views_Counter()->get_attribute('defaults', 'general', 'counter_mode')); |
| 688 | |
| 689 | // post views column |
| 690 | $input['post_views_column'] = (isset($input['post_views_column'], $this->choices[$input['post_views_column']]) ? ($input['post_views_column'] === 'yes' ? true : false) : Post_Views_Counter()->get_attribute('defaults', 'general', 'post_views_column')); |
| 691 | |
| 692 | // time between counts |
| 693 | $input['time_between_counts']['number'] = (int)(isset($input['time_between_counts']['number']) ? $input['time_between_counts']['number'] : Post_Views_Counter()->get_attribute('defaults', 'general', 'time_between_counts', 'number')); |
| 694 | $input['time_between_counts']['type'] = (isset($input['time_between_counts']['type'], $this->time_types[$input['time_between_counts']['type']]) ? $input['time_between_counts']['type'] : Post_Views_Counter()->get_attribute('defaults', 'general', 'time_between_counts', 'type')); |
| 695 | |
| 696 | // reset counts |
| 697 | $input['reset_counts']['number'] = (int)(isset($input['reset_counts']['number']) ? $input['reset_counts']['number'] : Post_Views_Counter()->get_attribute('defaults', 'general', 'reset_counts', 'number')); |
| 698 | $input['reset_counts']['type'] = (isset($input['reset_counts']['type'], $this->time_types[$input['reset_counts']['type']]) ? $input['reset_counts']['type'] : Post_Views_Counter()->get_attribute('defaults', 'general', 'reset_counts', 'type')); |
| 699 | |
| 700 | // run cron on next visit? |
| 701 | $input['cron_run'] = ($input['reset_counts']['number'] > 0 ? true : false); |
| 702 | $input['cron_update'] = ($input['cron_run'] && (Post_Views_Counter()->get_attribute('options', 'general', 'reset_counts', 'number') !== $input['reset_counts']['number'] || Post_Views_Counter()->get_attribute('options', 'general', 'reset_counts', 'type') !== $input['reset_counts']['type']) ? true : false); |
| 703 | |
| 704 | // exclude |
| 705 | if(isset($input['exclude']['groups'])) |
| 706 | { |
| 707 | $groups = array(); |
| 708 | |
| 709 | foreach($input['exclude']['groups'] as $group) |
| 710 | { |
| 711 | if(isset($this->groups[$group])) |
| 712 | $groups[] = $group; |
| 713 | } |
| 714 | |
| 715 | $input['exclude']['groups'] = array_unique($groups); |
| 716 | } |
| 717 | else |
| 718 | $input['exclude']['groups'] = array(); |
| 719 | |
| 720 | if(in_array('roles', $input['exclude']['groups'], true) && isset($input['exclude']['roles'])) |
| 721 | { |
| 722 | $roles = array(); |
| 723 | |
| 724 | foreach($input['exclude']['roles'] as $role) |
| 725 | { |
| 726 | if(isset($this->user_roles[$role])) |
| 727 | $roles[] = $role; |
| 728 | } |
| 729 | |
| 730 | $input['exclude']['roles'] = array_unique($roles); |
| 731 | } |
| 732 | else |
| 733 | $input['exclude']['roles'] = array(); |
| 734 | |
| 735 | // exclude ips |
| 736 | if(isset($input['exclude_ips'])) |
| 737 | { |
| 738 | $ips = array(); |
| 739 | |
| 740 | foreach($input['exclude_ips'] as $ip) |
| 741 | { |
| 742 | if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) |
| 743 | $ips[] = $ip; |
| 744 | } |
| 745 | |
| 746 | $input['exclude_ips'] = array_unique($ips); |
| 747 | } |
| 748 | |
| 749 | // deactivation delete |
| 750 | $input['deactivation_delete'] = (isset($input['deactivation_delete'], $this->choices[$input['deactivation_delete']]) ? ($input['deactivation_delete'] === 'yes' ? true : false) : Post_Views_Counter()->get_attribute('defaults', 'general', 'deactivation_delete')); |
| 751 | } |
| 752 | elseif(isset($_POST['save_pvc_display'])) |
| 753 | { |
| 754 | // post views label |
| 755 | $input['label'] = (isset($input['label']) ? $input['label'] : Post_Views_Counter()->get_attribute('defaults', 'general', 'label')); |
| 756 | |
| 757 | if(function_exists('icl_register_string')) |
| 758 | icl_register_string('Post Views Counter', 'Post Views Label', $input['label']); |
| 759 | |
| 760 | // position |
| 761 | $input['position'] = (isset($input['position'], $this->positions[$input['position']]) ? $input['position'] : Post_Views_Counter()->get_attribute('defaults', 'general', 'position')); |
| 762 | |
| 763 | // display style |
| 764 | $input['display_style']['icon'] = (isset($input['display_style']['icon']) ? true : false); |
| 765 | $input['display_style']['text'] = (isset($input['display_style']['text']) ? true : false); |
| 766 | |
| 767 | // link to post |
| 768 | $input['link_to_post'] = (isset($input['link_to_post'], $this->choices[$input['link_to_post']]) ? ($input['link_to_post'] === 'yes' ? true : false) : Post_Views_Counter()->get_attribute('defaults', 'general', 'link_to_post')); |
| 769 | |
| 770 | // icon class |
| 771 | $input['icon_class'] = (isset($input['icon_class']) ? trim($input['icon_class']) : Post_Views_Counter()->get_attribute('defaults', 'general', 'icon_class')); |
| 772 | |
| 773 | // post types display |
| 774 | if(isset($input['post_types_display'])) |
| 775 | { |
| 776 | $post_types = array(); |
| 777 | |
| 778 | foreach($input['post_types_display'] as $post_type) |
| 779 | { |
| 780 | if(isset($this->post_types[$post_type])) |
| 781 | $post_types[] = $post_type; |
| 782 | } |
| 783 | |
| 784 | $input['post_types_display'] = array_unique($post_types); |
| 785 | } |
| 786 | else |
| 787 | $input['post_types_display'] = array(); |
| 788 | |
| 789 | // restrict display |
| 790 | if(isset($input['restrict_display']['groups'])) |
| 791 | { |
| 792 | $groups = array(); |
| 793 | |
| 794 | foreach($input['restrict_display']['groups'] as $group) |
| 795 | { |
| 796 | if($group === 'robots') |
| 797 | continue; |
| 798 | |
| 799 | if(isset($this->groups[$group])) |
| 800 | $groups[] = $group; |
| 801 | } |
| 802 | |
| 803 | $input['restrict_display']['groups'] = array_unique($groups); |
| 804 | } |
| 805 | else |
| 806 | $input['restrict_display']['groups'] = array(); |
| 807 | |
| 808 | if(in_array('roles', $input['restrict_display']['groups'], true) && isset($input['restrict_display']['roles'])) |
| 809 | { |
| 810 | $roles = array(); |
| 811 | |
| 812 | foreach($input['restrict_display']['roles'] as $role) |
| 813 | { |
| 814 | if(isset($this->user_roles[$role])) |
| 815 | $roles[] = $role; |
| 816 | } |
| 817 | |
| 818 | $input['restrict_display']['roles'] = array_unique($roles); |
| 819 | } |
| 820 | else |
| 821 | $input['restrict_display']['roles'] = array(); |
| 822 | } |
| 823 | elseif(isset($_POST['reset_pvc_general'])) |
| 824 | { |
| 825 | $input = Post_Views_Counter()->get_attribute('defaults', 'general'); |
| 826 | |
| 827 | add_settings_error('reset_general_settings', 'settings_reset', __('General settings restored to defaults.', 'post-views-counter'), 'updated'); |
| 828 | } |
| 829 | elseif(isset($_POST['reset_pvc_display'])) |
| 830 | { |
| 831 | $input = Post_Views_Counter()->get_attribute('defaults', 'display'); |
| 832 | |
| 833 | add_settings_error('reset_general_settings', 'settings_reset', __('Display settings restored to defaults.', 'post-views-counter'), 'updated'); |
| 834 | } |
| 835 | |
| 836 | return $input; |
| 837 | } |
| 838 | |
| 839 | |
| 840 | /** |
| 841 | * Adds links to Support Forum |
| 842 | */ |
| 843 | public function plugin_extend_links($links, $file) |
| 844 | { |
| 845 | if(!current_user_can('install_plugins')) |
| 846 | return $links; |
| 847 | |
| 848 | $plugin = plugin_basename(__FILE__); |
| 849 | |
| 850 | if($file == $plugin) |
| 851 | { |
| 852 | return array_merge( |
| 853 | $links, |
| 854 | array(sprintf('<a href="http://www.dfactory.eu/support/forum/post-views-counter/" target="_blank">%s</a>', __('Support', 'post-views-counter'))) |
| 855 | ); |
| 856 | } |
| 857 | |
| 858 | return $links; |
| 859 | } |
| 860 | } |
| 861 | ?> |