PluginProbe
Analytify – Google Analytics Dashboard For WordPress (GA4 analytics tracking) / 1.0.4
Analytify – Google Analytics Dashboard For WordPress (GA4 analytics tracking) v1.0.4
9.1.2 9.1.1 9.1.0 9.0.2 9.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 All 153 releases
wp-analytify / wp-analytify.php

wp-analytify.php in Analytify – Google Analytics Dashboard For WordPress (GA4 analytics tracking) 1.0.4, at wp-analytify.php

901 lines 31.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Analytify - Google Analytics Dashboard
4 * Plugin URI: hhttp://wp-analytify.com/details
5 * Description: Analytify brings a brand new and modern feeling Google Analytics superbly integrated with WordPress Dashboard. It presents the statistics in a beautiful way under the WordPress Posts/Pages at front end, backend and in its own Dashboard. This provides Stats from Country, Referrers, Social media, General stats, New visitors, Returning visitors, Exit pages, Browser wise and Top keywords. This plugin provides the RealTime statistics in a new UI which is easy to understand and looks good.
6 * Version: 1.0.4
7 * Author: WPBrigade
8 * Author URI: http://wpbrigade.com/
9 * License: GPLv2+
10 * Text Domain: wp-analytify
11 * Min WP Version: 3.0.1
12 * Max WP Version: 4.1.1
13 * Domain Path: /lang
14 */
15
16 // Exit if accessed directly
17 if ( !defined( 'ABSPATH' ) ) exit;
18
19 ini_set( 'include_path', dirname(__FILE__) . '/lib/' );
20
21 if ( !class_exists( 'WP_Analytify' ) ) {
22
23 if ( !class_exists( 'Analytify_General_FREE' ) ){
24
25 require_once WP_PLUGIN_DIR .'/wp-analytify/analytify-general.php';
26 }
27
28 class WP_Analytify extends Analytify_General_FREE{
29
30 public $token = false;
31 public $client = null;
32
33 // Constructor
34 function __construct() {
35
36 parent::__construct();
37
38 if ( !class_exists( 'Analytify_Google_Client' ) ) {
39
40 require_once ANALYTIFY_LIB_PATH . 'Google/Client.php';
41 require_once ANALYTIFY_LIB_PATH . 'Google/Service/Analytics.php';
42 }
43
44 add_action( 'plugin_action_links', array(
45 $this,
46 'pa_plugin_links'
47 ),10,2);
48
49 add_action( 'plugin_row_meta', array(
50 $this,
51 'analytify_plugin_row_meta'
52 ),10,2);
53
54 add_action( 'admin_enqueue_scripts', array(
55 $this,
56 'pa_scripts'
57 ));
58 add_action( 'admin_enqueue_scripts', array(
59 $this,
60 'pa_styles'
61 ));
62
63
64 add_action( 'wp_enqueue_scripts', array(
65 $this,
66 'pa_front_scripts'
67 ));
68 add_action( 'wp_enqueue_scripts', array(
69 $this,
70 'pa_front_styles'
71 ));
72
73 add_action( 'admin_menu', array(
74 $this,
75 'wpa_add_menu'
76 ));
77
78 // Insert Google Analytics Code
79 if( get_option( 'analytify_code') == 1 ) {
80
81 add_action( 'wp_head', array(
82 $this,
83 'analytify_add_analytics_code'
84 ));
85 }
86
87 add_action( 'wp_ajax_nopriv_get_ajax_single_admin_analytics', array(
88 $this,
89 'get_ajax_single_admin_analytics'
90 ));
91
92 add_action( 'wp_ajax_get_ajax_single_admin_analytics', array(
93 $this,
94 'get_ajax_single_admin_analytics'
95 ));
96
97 add_action( 'wp_ajax_get_ajax_secret_keys', array(
98 $this,
99 'get_ajax_secret_keys'
100 ));
101
102 if( get_option( 'analytify_disable_front') == 0 ) {
103
104 add_filter( 'the_content', array(
105 $this,
106 'get_single_front_analytics'
107 ));
108 }
109
110 /*
111 * load Analytics under the EDIT POST Screen
112 * add action runs only for admin section and load metabox.
113 */
114
115 if ( is_admin() ) {
116 add_action( 'load-post.php', array(
117 $this,
118 'load_metaboxes'
119 ));
120 }
121
122 // Show welcome message when user activate plugin.
123 if ( get_option( 'pa_welcome_message' ) == 0 ) {
124
125 add_action( 'admin_print_footer_scripts', array(
126 $this,
127 'pa_welcome_message'
128 ) );
129 }
130
131 /*
132 * localization language file filter
133 */
134
135 add_action( 'init', array(
136 $this,
137 'analytify_textdomain') );
138
139 //add_action( 'admin_footer', array( &$this, 'profile_warning' ) );
140
141 register_activation_hook( __FILE__, array( $this, 'install' ) );
142 register_deactivation_hook( __FILE__, array( $this, 'uninstall' ) );
143 }
144
145 /*
146 * Set plugin language/localizations files directory
147 */
148 public function analytify_textdomain() {
149
150 $plugin_dir = basename( dirname(__FILE__) );
151 load_plugin_textdomain( 'wp-analytify', false , $plugin_dir . '/lang/');
152
153 }
154
155 /*
156 * Show analytics sections under the posts/pages in the metabox.
157 */
158
159 function load_metaboxes() {
160
161 add_action( 'add_meta_boxes', array(
162 $this,
163 'show_admin_single_analytics_add_metabox'
164 ));
165 }
166
167 /*
168 * Show metabox under each Post type to display Analytics of single post/page in wp-admin
169 */
170 public function show_admin_single_analytics_add_metabox() {
171
172 $post_types = get_option( 'analytify_posts_stats' );
173
174 // Don't load boxes/sections if no any post type is selected.
175 if( !empty($post_types))
176 foreach ( $post_types as $post_type ) {
177
178 add_meta_box('pa-single-admin-analytics', // $id
179 'Analytify: Google Analytics of this page.', // $title
180 array(
181 'WP_Analytify',
182 'show_admin_single_analytics'
183 ), // $callback
184
185 $post_type, // $posts
186 'normal', // $context
187 'high' // $priority
188 );
189 } //$post_types as $post_type
190 }
191
192
193 public static function get_ajax_secret_keys(){
194
195 $response = wp_remote_get( "http://wp-analytify.com/secret/keys.json" );
196 if( is_wp_error( $response ) ) {
197 $error_message = $response->get_error_message();
198 echo "Something went wrong: $error_message";
199 } else {
200 print_r($response['body']);
201 }
202 die();
203 }
204
205 /*
206 * Show Analytics of single post/page in wp-admin under EDIT screen.
207 */
208 public static function show_admin_single_analytics() {
209
210 global $post;
211
212 $back_exclude_posts = explode( ',', get_option( 'post_analytics_exclude_posts_back' ));
213
214 if ( is_array( $back_exclude_posts ) ) {
215
216 if ( in_array( $post->ID, $back_exclude_posts ) ) {
217
218 _e('This post is excluded and will not show Analytics.');
219
220 return;
221 }
222 }
223
224 $urlPost = '';
225 $wp_analytify = new WP_Analytify();
226 $urlPost = parse_url( get_permalink( $post->ID ) );
227 $start_date = ''; $end_date = ''; $urlpost = '' ;
228 $is_access_level = get_option( 'post_analytics_access_back' );
229
230 if( $wp_analytify->pa_check_roles( $is_access_level ) ){ ?>
231
232 <div class="pa-filter">
233 <table cellspacing="0" cellpadding="0" width="400">
234 <tbody>
235 <tr>
236 <td width="0">
237 <input type="text" id="start_date" name="start_date">
238 </td>
239 <td width="0">
240 <input type="text" id="end_date" name="end_date">
241 </td>
242 <input type="hidden" name="urlpost" id="urlpost" value="<?php echo $urlPost['path']; ?>">
243 <td width="0">
244 <input type="button" id="view_analytics" name="view_analytics" value="View Analytics" class="button-primary btn-green">
245 </td>
246 </tr>
247 </tbody>
248 </table>
249 </div>
250 <div class="loading" style="display:none">
251 <img src="<?php echo plugins_url('images/loading.gif', __FILE__);?>">
252 </div>
253 <div class="show-hide">
254 <?php $wp_analytify->get_single_admin_analytics( $start_date, $end_date, $post->ID, 0 ); ?>
255 </div>
256 <?php
257 }
258 else{
259 echo _e( 'You are not allowed to see stats', 'wp-analytify' );
260 }
261 }
262
263 // Add Google Analytics JS code
264 public function analytify_add_analytics_code() {
265
266 global $current_user;
267
268 $roles = $current_user->roles;
269
270 if ( isset( $roles[0] ) and in_array( $roles[0], get_option( 'display_tracking_code' ) )) {
271
272 }
273 else{
274
275 echo '<!-- This code is added by Analytify v - ' . ANALYTIFY_VERSION . ' http://wp-analytify.com/ !--> ';
276
277 if ( get_option( 'analytify_tracking_code' ) == 'universal' ) { ?>
278
279 <script>
280 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
281 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
282 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
283 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
284 ga('create', '<?php echo get_option( "webPropertyId" );?>', 'auto');
285 ga('send', 'pageview');
286 </script>
287
288 <?php
289 }
290
291 if ( get_option( 'analytify_tracking_code' ) == 'ga' ) { ?>
292
293 <script type="text/javascript">//<![CDATA[
294 var _gaq = _gaq || [];
295 _gaq.push(['_setAccount', '<?php echo get_option( "webPropertyId" );?>']);
296 _gaq.push(['_trackPageview']);
297 (function () {
298 var ga = document.createElement('script');
299 ga.type = 'text/javascript';
300 ga.async = true;
301 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
302 var s = document.getElementsByTagName('script')[0];
303 s.parentNode.insertBefore(ga, s);
304 })();
305 //]]>
306 </script>
307
308 <?php
309 }
310
311 echo '<!-- This code is added by Analytify v - ' . ANALYTIFY_VERSION . ' !-->';
312 }
313 }
314
315 /**
316 * Add a link to the settings page to the plugins list
317 */
318 public function pa_plugin_links( $links, $file ) {
319
320 static $this_plugin;
321
322 if ( empty( $this_plugin ) ){
323
324 $this_plugin = 'wp-analytify/wp-analytify.php';
325 }
326
327 if ( $file == $this_plugin ) {
328
329 $settings_link = '<a href="' . admin_url("admin.php?page=analytify-settings") . '">' . __( 'Settings', 'wp-analytify' ) . '</a> | <a href="' . admin_url("admin.php?page=analytify-dashboard") . '">' . __( 'Dashboard', 'wp-analytify' ) . '</a>';
330 array_unshift( $links, $settings_link );
331 }
332
333 return $links;
334 }
335
336 /**
337 * Plugin row meta links
338 *
339 * @since 1.1
340 * @param array $input already defined meta links
341 * @param string $file plugin file path and name being processed
342 * @return array $input
343 */
344 function analytify_plugin_row_meta( $input, $file ) {
345 if ( $file != 'wp-analytify/wp-analytify.php' )
346 return $input;
347
348 $links = array(
349 '<a href="http://wp-analytify.com/">' . esc_html__( 'Buy Pro Version', 'edd' ) . '</a>',
350 '<a href="http://wp-analytify.com/add-ons/">' . esc_html__( 'Add Ons', 'edd' ) . '</a>',
351 );
352
353 $input = array_merge( $input, $links );
354
355 return $input;
356 }
357
358
359 /**
360 * Display warning if profiles are not selected.
361 */
362 public function pa_check_warnings(){
363
364 add_action( 'admin_footer', array(
365 &$this,
366 'profile_warning'
367 ));
368 }
369
370 /**
371 * Get current screen details
372 */
373 public static function pa_page_file_path() {
374
375 $screen = get_current_screen();
376
377 if ( strpos( $screen->base, 'analytify-settings' ) !== false ) {
378 include( ANALYTIFY_ROOT_PATH . '/inc/analytify-settings.php' );
379 }
380 else {
381 include( ANALYTIFY_ROOT_PATH . '/inc/analytify-dashboard.php' );
382 }
383 }
384
385 /**
386 * Styling: loading stylesheets for the plugin.
387 */
388 public function pa_styles( $page ) {
389
390 wp_enqueue_style( 'wp-analytify-style', plugins_url('css/wp-analytify-style.css', __FILE__));
391
392 // wp_enqueue_style( 'ui-css', plugins_url('jquery-ui-theme/jquery-ui.css', __FILE__));
393 wp_enqueue_style( 'chosen', plugins_url('css/chosen.css', __FILE__));
394 // wp_enqueue_style( 'jquery-ui-tooltip-css', plugins_url('css/jquery.ui.tooltip.html.css', __FILE__) );
395
396 if ( get_option( 'pa_welcome_message' ) == '0' ) {
397
398 wp_enqueue_style( 'wp-pointer' );
399
400 }
401 }
402
403 public function pa_front_styles( $page ) {
404
405 if( get_option( 'analytify_disable_front') == 0 ) {
406
407 wp_enqueue_style( 'front-end-style', plugins_url('css/frontend_styles.css', __FILE__),false,ANALYTIFY_VERSION);
408 }
409 }
410
411 /**
412 * Loading scripts js for the plugin.
413 */
414 public function pa_scripts( $page ) {
415
416 wp_enqueue_script ( 'jquery' );
417 wp_enqueue_script ( 'charts_api_js', 'https://www.google.com/jsapi', false, ANALYTIFY_VERSION );
418 wp_enqueue_script ( 'chosen-js', plugins_url('js/chosen.jquery.js', __FILE__), false, ANALYTIFY_VERSION );
419 wp_enqueue_script ( 'script-js', plugins_url('js/wp-analytify.js', __FILE__), false, ANALYTIFY_VERSION );
420 wp_enqueue_script ( 'jquery-ui-tooltip' );
421 wp_enqueue_script ( 'jquery-ui-datepicker');
422
423 if ( get_option( 'pa_welcome_message' ) == '0' ) {
424
425 wp_enqueue_script( 'wp-pointer' );
426 }
427 }
428
429 /**
430 * Loading scripts js for the plugin.
431 */
432 public function pa_front_scripts( $page ) {
433
434 if( get_option( 'analytify_disable_front') == 0 ){
435
436 wp_enqueue_script ('jquery');
437 wp_enqueue_script ('analytify-classie', plugins_url('js/classie.js', __FILE__), false, ANALYTIFY_VERSION);
438 wp_enqueue_script ('analytify-selectfx', plugins_url('js/selectFx.js', __FILE__), false, ANALYTIFY_VERSION);
439 wp_enqueue_script ('analytify-script', plugins_url('js/script.js', __FILE__), false, ANALYTIFY_VERSION);
440
441 }
442 }
443
444 /**
445 * Create Analytics menu at the left side of dashboard
446 */
447 public static function wpa_add_menu() {
448
449 add_menu_page( ANALYTIFY_NICK, 'Analytify', 'manage_options', 'analytify-dashboard', array(
450 __CLASS__,
451 'pa_page_file_path'
452 ), plugins_url('images/wp-analytics-logo.png', __FILE__),'2.1.9');
453
454 add_submenu_page( 'analytify-dashboard', ANALYTIFY_NICK . ' Dashboard', ' Dashboard', 'manage_options', 'analytify-dashboard', array(
455 __CLASS__,
456 'pa_page_file_path'
457 ));
458
459 add_submenu_page( 'analytify-dashboard', ANALYTIFY_NICK . ' Settings', '<b style="color:#f9845b">Settings</b>', 'manage_options', 'analytify-settings', array(
460 __CLASS__,
461 'pa_page_file_path'
462 ));
463 }
464
465 /**
466 * Creating tabs for settings
467 * @since 1.0
468 */
469
470 public function pa_settings_tabs( $current = 'authentication' ) {
471
472 $tabs = array( 'authentication' => 'Authentication',
473 'profile' => 'Profile',
474
475 'admin' => 'Admin'
476 );
477
478 echo '<div class="left-area">';
479
480 echo '<div id="icon-themes" class="icon32"><br></div>';
481 echo '<h2 class="nav-tab-wrapper">';
482
483 foreach( $tabs as $tab => $name ) {
484
485 $class = ( $tab == $current ) ? ' nav-tab-active' : '';
486 echo "<a class='nav-tab$class' href='?page=analytify-settings&tab=$tab'>$name</a>";
487 }
488
489 echo '</h2>';
490 }
491
492 /**
493 * Get profiles from user Google Analytics account profiles.
494 */
495 public function pt_get_analytics_accounts() {
496
497 try {
498
499 if( get_option( 'pa_google_token' ) !='' ) {
500 $profiles = $this->service->management_profiles->listManagementProfiles( "~all", "~all" );
501 return $profiles;
502 }
503
504 else{
505 echo '<br /><p class="description">' . __( 'You must authenticate to access your web profiles.', 'wp-analytify' ) . '</p>';
506 }
507
508 }
509
510 catch (Exception $e) {
511 die('An error occured: ' . $e->getMessage() . '\n');
512 }
513 }
514
515 public function pa_setting_url() {
516
517 return admin_url('admin.php?page=analytify-settings');
518
519 }
520
521
522 public function pt_save_data( $key_google_token ) {
523
524 update_option( 'post_analytics_token', $key_google_token );
525 $this->pa_connect();
526
527 return true;
528 }
529
530 /**
531 * Warning messages.
532 */
533 public function profile_warning() {
534
535 $profile_id = get_option( "pt_webprofile" );
536 $acces_token = get_option( "post_analytics_token" );
537
538 if (! isset( $acces_token ) || empty( $acces_token )) {
539
540 echo "<div id='message' class='error'><p><strong>" . __( "Analytify is not active. Please <a href='" . menu_page_url ( 'analytify-settings', false ) ."'>Authenticate</a> in order to get started using this plugin.", 'wp-analytify' )."</p></div>";
541 }
542 else{
543
544 if (! isset( $profile_id ) || empty( $profile_id )){
545 echo '<div class="error"><p><strong>' . __( 'Google Analytics Profile is not set. Set the <a href="' . menu_page_url ( 'analytify-settings', false ) . '&tab=profile">Profile</a> ', 'wp-analytify' ) . '</p></div>';
546 }
547 }
548 }
549
550
551 public function get_single_front_analytics( $content ) {
552
553 global $post, $wp_analytify;
554
555 $front_access = get_option( 'post_analytics_access' );
556
557 if ( is_single() || is_page() ) {
558
559 $post_type = get_post_type( $post->ID );
560
561 if( strlen( get_option( 'analytify_posts_stats_front' ) < 3) ) {
562 return $content;
563 }
564
565 if( is_array( get_option( 'analytify_posts_stats_front' )) and !in_array( $post_type, get_option( 'analytify_posts_stats_front' ) ) ) {
566
567 return $content;
568 }
569
570 if ( is_array( get_option( 'post_analytics_exclude_posts_front' ) ) ) {
571
572 if ( in_array( get_the_ID(), get_option( 'post_analytics_exclude_posts_front' ) ) ) {
573
574 return $content;
575 }
576 }
577
578 // Showing stats to guests
579 if ( $front_access[0] == 'every-one' || $this->pa_check_roles( $front_access )) {
580
581 $post_analytics_settings_front = array();
582 $post_analytics_settings_front = get_option( 'post_analytics_settings_front' );
583
584 $urlPost = parse_url( get_permalink( $post->ID ) );
585
586 if ( $urlPost['host'] == 'localhost' )
587 $filter = 'ga:pagePath==/'; //.$u_post['path'];
588 else
589 $filter = 'ga:pagePath==' .$urlPost['path']. '';
590
591 if( get_the_time('Y', $post->ID) < 2005 ) {
592
593 $start_date = '2005-01-01';
594 }
595 else {
596
597 $start_date = get_the_time('Y-m-d', $post->ID);
598 }
599
600 $end_date = date('Y-m-d');
601
602 ob_start();
603
604 include ANALYTIFY_ROOT_PATH . '/inc/front-menus.php';
605
606 if(! empty( $post_analytics_settings_front )){
607
608 if (is_array( $post_analytics_settings_front )){
609
610 $stats = $this->pa_get_analytics( 'ga:sessions,ga:bounces,ga:newUsers,ga:entrances,ga:pageviews,ga:sessionDuration,ga:avgTimeOnPage,ga:users',$start_date, $end_date, false, false, $filter);
611
612 if ( isset( $stats->totalsForAllResults ) ) {
613
614 include ANALYTIFY_ROOT_PATH . '/views/front/general-stats.php';
615 pa_include_general( $this, $stats);
616 }
617 }
618 }
619
620 $content .= ob_get_contents();
621 ob_get_clean();
622 }
623
624 }
625
626 return $content;
627
628 }
629
630 /*
631 * get the Analytics data from ajax() call
632 *
633 */
634
635 public function get_ajax_single_admin_analytics() {
636
637 $startDate = '';
638 $endDate = '';
639 $postID = 0 ;
640 $startDate = $_POST['start_date'];
641 $endDate = $_POST['end_date'];
642 $postID = $_POST['post_id'];
643 $this->get_single_admin_analytics( $startDate, $endDate, $postID, 1 );
644
645 die();
646 }
647
648 /*
649 * get the Analytics data for wp-admin posts/pages.
650 *
651 */
652 public function get_single_admin_analytics( $start_date = '', $end_date = '', $postID = 0, $ajax = 0 ) {
653
654 global $post;
655
656 //$urlPost = parse_url( get_permalink( $post->ID ) );
657
658 if ( $postID == 0 ) {
659 $u_post = '/'; //$urlPost['path'];
660 }
661 else{
662 $u_post = parse_url( get_permalink( $postID ) );
663 }
664
665 if ( $u_post['host'] == 'localhost' )
666 $filter = false;
667 else
668 $filter = 'ga:pagePath==' .$u_post['path']. '';
669
670
671 if ( $start_date == '' ) {
672
673 $s_date = get_the_time('Y-m-d', $post->ID);
674 if(get_the_time('Y', $post->ID) < 2005){
675 $s_date = '2005-01-01';
676 }
677 }
678 else{
679 $s_date = $start_date;
680 }
681
682 if ( $end_date == '' ) {
683 $e_date = date('Y-m-d');
684 }
685 else{
686 $e_date = $end_date;
687 }
688
689 $show_settings = array();
690 $show_settings = get_option('post_analytics_settings_back');
691
692 // Stop here, if user has disable backend analytics i.e OFF
693 if ( get_option( 'post_analytics_disable_back' ) == 1 and $ajax == 0) {
694 return;
695 }
696
697 echo '<p> Displaying Analytics of this page from ' . date("jS F, Y", strtotime($s_date)) . ' to '. date("jS F, Y", strtotime($e_date)) . '</p>';
698
699 if( !empty( $show_settings )){
700
701 if (is_array( $show_settings )){
702
703 if (in_array( 'show-overall-back', $show_settings )) {
704
705 $stats = $this->pa_get_analytics( 'ga:sessions,ga:bounces,ga:newUsers,ga:entrances,ga:pageviews,ga:sessionDuration,ga:avgTimeOnPage,ga:users',$s_date, $e_date, false, false, $filter);
706
707 if ( isset( $stats->totalsForAllResults ) ) {
708
709 include ANALYTIFY_ROOT_PATH . '/views/admin/single-general-stats.php';
710 wpa_single_include_general( $this, $stats);
711 }
712 }
713 }
714 }
715 }
716
717
718 /*
719 * Pretty numbers
720 */
721 function wpa_pretty_numbers( $num ) {
722
723 return round(($num/1000),2).'k';
724 }
725
726 /*
727 * format numbers
728 */
729 function wpa_number_format( $num ) {
730
731 return number_format($num);
732 }
733
734 /*
735 * Pretty time to display
736 */
737 function pa_pretty_time( $time ) {
738
739 // Check if numeric
740 if ( is_numeric($time) ) {
741
742 $value = array(
743 "years" => '00',
744 "days" => '00',
745 "hours" => '',
746 "minutes" => '',
747 "seconds" => ''
748 );
749
750 if ($time >= 31556926) {
751 $value["years"] = floor($time / 31556926);
752 $time = ($time % 31556926);
753 } //$time >= 31556926
754
755 if ($time >= 86400)
756 {
757 $value["days"] = floor($time / 86400);
758 $time = ($time % 86400);
759 } //$time >= 86400
760 if ($time >= 3600)
761 {
762 $value["hours"] = str_pad(floor($time / 3600), 1, 0, STR_PAD_LEFT);
763 $time = ($time % 3600);
764 } //$time >= 3600
765 if ($time >= 60)
766 {
767 $value["minutes"] = str_pad(floor($time / 60), 1, 0, STR_PAD_LEFT);
768 $time = ($time % 60);
769 } //$time >= 60
770 $value["seconds"] = str_pad(floor($time), 1, 0, STR_PAD_LEFT);
771 # Get the hour:minute:second version
772 if($value['hours']!=''){
773 $attach_hours='<sub>h</sub> ';
774 }
775 if($value['minutes']!=''){
776 $attach_min='<sub>min</sub> ';
777 }
778 if($value['seconds']!=''){
779 $attach_sec='<sub>sec</sub>';
780 }
781 return $value['hours'] .@$attach_hours. $value['minutes'] .@$attach_min. $value['seconds'].$attach_sec;
782 //return $value['hours'] . ':' . $value['minutes'] . ':' . $value['seconds'];
783 } //is_numeric($time)
784 else
785 {
786 return false;
787 }
788 }
789
790
791 public function pa_check_roles( $access_level ) {
792
793 if ( is_user_logged_in () && isset ( $access_level ) ) {
794
795 global $current_user;
796 $roles = $current_user->roles;
797
798 /*if ( ( current_user_can ( 'manage_options' ) ) ) {
799
800 return true;
801 }*/
802
803 if ( in_array ( $roles[0], $access_level ) ) {
804
805 return true;
806 }
807 else {
808
809 return false;
810 }
811 }
812 }
813
814 public function pa_welcome_message() {
815
816 $pointer_content = '<h3>Analytify - Google Analytics for WordPress.</h3>';
817 $pointer_content .= '<p>Thank you for activating Analytify Plugin. Enjoy Google Analytics for everything in WordPress.</p>';
818 ?>
819
820 <script type="text/javascript">
821 //<![CDATA[
822 jQuery(document).ready( function($) {
823
824 $('#toplevel_page_pa-dashboard').pointer({
825 content: '<?php echo $pointer_content; ?>',
826 position: 'left',
827 close: function() {
828 <?php update_option("pa_welcome_message",1) ?>
829 }
830 }).pointer('open');
831 });
832 //]]>
833 </script>
834
835 <?php
836 }
837
838 /*
839 * Activate options by default on installing the plugin.
840 */
841 static function install() {
842
843 update_option( 'analytify_posts_stats', array( 'post','page' ));
844 update_option( 'post_analytics_disable_back' , 1 );
845 update_option( 'analytify_code' , 1 );
846 update_option( 'post_analytics_settings_back' , array( 'show-overall-back' ) );
847 update_option( 'post_analytics_access_back' , array( 'editor','administrator' ) );
848 update_option( 'display_tracking_code' , array( 'administrator' ) );
849
850
851 }
852
853 static function uninstall() {
854
855 delete_option( 'analytify_posts_stats' );
856 delete_option( 'pa_google_token' );
857 delete_option( 'pa_welcome_message' );
858 delete_option( 'post_analytics_token' );
859
860 }
861
862 }
863
864 $wp_analytify = new WP_Analytify();
865
866 $wp_analytify->pa_check_warnings();
867
868 } //end if
869
870 /* Display a notice that can be dismissed */
871
872 add_action('admin_notices', 'analytify_admin_notice');
873
874 function analytify_admin_notice() {
875 if ( current_user_can( 'install_plugins' ) )
876 {
877 global $current_user ;
878 $user_id = $current_user->ID;
879 /* Check that the user hasn't already clicked to ignore the message */
880 if ( ! get_user_meta($user_id, 'analytify_ignore_notice') ) {
881 echo '<div class="updated"><p>';
882 printf(__('<b>[Notice]</b> Thank you for using <strong><a href="https://wp-analytify.com/details" target="_blank">Analytify</a>!</strong> Do you know you could get detailed <a href="https://wp-analytify.com/details" target="_blank"><strong>Keyword Analytics</strong></a> per post, right below your <strong>Post Edit Panel</strong>?  Here is <strong>Exclusive $5 off Coupon "<em><a href="https://wp-analytify.com/upgrade-from-free" target="_blank">Analytify2015</a>"</em></strong><a href="https://wp-analytify.com/upgrade-from-free" target="_blank"><em>,</em></a> only for <strong>You</strong>, existing user. <a href="%1$s">[Hide Notice]</a>'), admin_url( 'admin.php?page=analytify-dashboard&analytify_nag_ignore=0' ));
883 echo "</p></div>";
884 }
885 }
886 }
887
888 add_action('admin_init', 'analytify_nag_ignore');
889
890 function analytify_nag_ignore() {
891 global $current_user;
892 $user_id = $current_user->ID;
893 /* If user clicks to ignore the notice, add that to their user meta */
894 if ( isset($_GET['analytify_nag_ignore']) && '0' == $_GET['analytify_nag_ignore'] ) {
895 add_user_meta($user_id, 'analytify_ignore_notice', 'true', true);
896 }
897 }
898
899 ?>
900
901