PluginProbe
Analytify – Google Analytics Dashboard For WordPress (GA4 analytics tracking) / 1.0.2
Analytify – Google Analytics Dashboard For WordPress (GA4 analytics tracking) v1.0.2
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.2, at wp-analytify.php

867 lines 29.2 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.2
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
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 foreach ( $post_types as $post_type ) {
175
176 add_meta_box('pa-single-admin-analytics', // $id
177 'Analytify: Google Analytics of this page.', // $title
178 array(
179 'WP_Analytify',
180 'show_admin_single_analytics'
181 ), // $callback
182
183 $post_type, // $posts
184 'normal', // $context
185 'high' // $priority
186 );
187 } //$post_types as $post_type
188 }
189
190
191 public static function get_ajax_secret_keys(){
192
193 $response = wp_remote_get( "http://wp-analytify.com/secret/keys.json" );
194 if( is_wp_error( $response ) ) {
195 $error_message = $response->get_error_message();
196 echo "Something went wrong: $error_message";
197 } else {
198 print_r($response['body']);
199 }
200 die();
201 }
202
203 /*
204 * Show Analytics of single post/page in wp-admin under EDIT screen.
205 */
206 public static function show_admin_single_analytics() {
207
208 global $post;
209
210 $back_exclude_posts = explode( ',', get_option( 'post_analytics_exclude_posts_back' ));
211
212 if ( is_array( $back_exclude_posts ) ) {
213
214 if ( in_array( $post->ID, $back_exclude_posts ) ) {
215
216 _e('This post is excluded and will not show Analytics.');
217
218 return;
219 }
220 }
221
222 $urlPost = '';
223 $wp_analytify = new WP_Analytify();
224 $urlPost = parse_url( get_permalink( $post->ID ) );
225 $start_date = ''; $end_date = ''; $urlpost = '' ;
226 $is_access_level = get_option( 'post_analytics_access_back' );
227
228 if( $wp_analytify->pa_check_roles( $is_access_level ) ){ ?>
229
230 <div class="pa-filter">
231 <table cellspacing="0" cellpadding="0" width="400">
232 <tbody>
233 <tr>
234 <td width="0">
235 <input type="text" id="start_date" name="start_date">
236 </td>
237 <td width="0">
238 <input type="text" id="end_date" name="end_date">
239 </td>
240 <input type="hidden" name="urlpost" id="urlpost" value="<?php echo $urlPost['path']; ?>">
241 <td width="0">
242 <input type="button" id="view_analytics" name="view_analytics" value="View Analytics" class="button-primary btn-green">
243 </td>
244 </tr>
245 </tbody>
246 </table>
247 </div>
248 <div class="loading" style="display:none">
249 <img src="<?php echo plugins_url('images/loading.gif', __FILE__);?>">
250 </div>
251 <div class="show-hide">
252 <?php $wp_analytify->get_single_admin_analytics( $start_date, $end_date, $post->ID, 0 ); ?>
253 </div>
254 <?php
255 }
256 else{
257 echo _e( 'You are not allowed to see stats', 'wp-analytify' );
258 }
259 }
260
261 // Add Google Analytics JS code
262 public function analytify_add_analytics_code() {
263
264 global $current_user;
265
266 $roles = $current_user->roles;
267
268 if ( isset( $roles[0] ) and in_array( $roles[0], get_option( 'display_tracking_code' ) )) {
269
270 }
271 else{
272
273 echo '<!-- This code is added by Analytify v - ' . ANALYTIFY_VERSION . ' http://wp-analytify.com/ !--> ';
274
275 if ( get_option( 'analytify_tracking_code' ) == 'universal' ) { ?>
276
277 <script>
278 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
279 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
280 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
281 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
282 ga('create', '<?php echo get_option( "webPropertyId" );?>', 'auto');
283 ga('send', 'pageview');
284 </script>
285
286 <?php
287 }
288
289 if ( get_option( 'analytify_tracking_code' ) == 'ga' ) { ?>
290
291 <script type="text/javascript">//<![CDATA[
292 var _gaq = _gaq || [];
293 _gaq.push(['_setAccount', '<?php echo get_option( "webPropertyId" );?>']);
294 _gaq.push(['_trackPageview']);
295 (function () {
296 var ga = document.createElement('script');
297 ga.type = 'text/javascript';
298 ga.async = true;
299 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
300 var s = document.getElementsByTagName('script')[0];
301 s.parentNode.insertBefore(ga, s);
302 })();
303 //]]>
304 </script>
305
306 <?php
307 }
308
309 echo '<!-- This code is added by Analytify v - ' . ANALYTIFY_VERSION . ' !-->';
310 }
311 }
312
313 /**
314 * Add a link to the settings page to the plugins list
315 */
316 public function pa_plugin_links( $links, $file ) {
317
318 static $this_plugin;
319
320 if ( empty( $this_plugin ) ){
321
322 $this_plugin = 'wp-analytify/wp-analytify.php';
323 }
324
325 if ( $file == $this_plugin ) {
326
327 $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>';
328 array_unshift( $links, $settings_link );
329 }
330
331 return $links;
332 }
333
334 /**
335 * Plugin row meta links
336 *
337 * @since 1.1
338 * @param array $input already defined meta links
339 * @param string $file plugin file path and name being processed
340 * @return array $input
341 */
342 function analytify_plugin_row_meta( $input, $file ) {
343 if ( $file != 'wp-analytify/wp-analytify.php' )
344 return $input;
345
346 $links = array(
347 '<a href="http://wp-analytify.com/">' . esc_html__( 'Buy Pro Version', 'edd' ) . '</a>',
348 '<a href="http://wp-analytify.com/add-ons/">' . esc_html__( 'Add Ons', 'edd' ) . '</a>',
349 );
350
351 $input = array_merge( $input, $links );
352
353 return $input;
354 }
355
356
357 /**
358 * Display warning if profiles are not selected.
359 */
360 public function pa_check_warnings(){
361
362 add_action( 'admin_footer', array(
363 &$this,
364 'profile_warning'
365 ));
366 }
367
368 /**
369 * Get current screen details
370 */
371 public static function pa_page_file_path() {
372
373 $screen = get_current_screen();
374
375 if ( strpos( $screen->base, 'analytify-settings' ) !== false ) {
376 include( ANALYTIFY_ROOT_PATH . '/inc/analytify-settings.php' );
377 }
378 else {
379 include( ANALYTIFY_ROOT_PATH . '/inc/analytify-dashboard.php' );
380 }
381 }
382
383 /**
384 * Styling: loading stylesheets for the plugin.
385 */
386 public function pa_styles( $page ) {
387
388 wp_enqueue_style( 'wp-analytify-style', plugins_url('css/wp-analytify-style.css', __FILE__));
389
390 // wp_enqueue_style( 'ui-css', plugins_url('jquery-ui-theme/jquery-ui.css', __FILE__));
391 wp_enqueue_style( 'chosen', plugins_url('css/chosen.css', __FILE__));
392 // wp_enqueue_style( 'jquery-ui-tooltip-css', plugins_url('css/jquery.ui.tooltip.html.css', __FILE__) );
393
394 if ( get_option( 'pa_welcome_message' ) == '0' ) {
395
396 wp_enqueue_style( 'wp-pointer' );
397
398 }
399 }
400
401 public function pa_front_styles( $page ) {
402
403 if( get_option( 'analytify_disable_front') == 0 ) {
404
405 wp_enqueue_style( 'front-end-style', plugins_url('css/frontend_styles.css', __FILE__),false,ANALYTIFY_VERSION);
406 }
407 }
408
409 /**
410 * Loading scripts js for the plugin.
411 */
412 public function pa_scripts( $page ) {
413
414 wp_enqueue_script ( 'jquery' );
415 wp_enqueue_script ( 'charts_api_js', 'https://www.google.com/jsapi', false, ANALYTIFY_VERSION );
416 wp_enqueue_script ( 'chosen-js', plugins_url('js/chosen.jquery.js', __FILE__), false, ANALYTIFY_VERSION );
417 wp_enqueue_script ( 'script-js', plugins_url('js/wp-analytify.js', __FILE__), false, ANALYTIFY_VERSION );
418 wp_enqueue_script ( 'jquery-ui-tooltip' );
419 wp_enqueue_script ( 'jquery-ui-datepicker');
420
421 if ( get_option( 'pa_welcome_message' ) == '0' ) {
422
423 wp_enqueue_script( 'wp-pointer' );
424 }
425 }
426
427 /**
428 * Loading scripts js for the plugin.
429 */
430 public function pa_front_scripts( $page ) {
431
432 if( get_option( 'analytify_disable_front') == 0 ){
433
434 wp_enqueue_script ('jquery');
435 wp_enqueue_script ('analytify-classie', plugins_url('js/classie.js', __FILE__), false, ANALYTIFY_VERSION);
436 wp_enqueue_script ('analytify-selectfx', plugins_url('js/selectFx.js', __FILE__), false, ANALYTIFY_VERSION);
437 wp_enqueue_script ('analytify-script', plugins_url('js/script.js', __FILE__), false, ANALYTIFY_VERSION);
438
439 }
440 }
441
442 /**
443 * Create Analytics menu at the left side of dashboard
444 */
445 public static function wpa_add_menu() {
446
447 add_menu_page( ANALYTIFY_NICK, 'Analytify', 'manage_options', 'analytify-dashboard', array(
448 __CLASS__,
449 'pa_page_file_path'
450 ), plugins_url('images/wp-analytics-logo.png', __FILE__),'2.1.9');
451
452 add_submenu_page( 'analytify-dashboard', ANALYTIFY_NICK . ' Dashboard', ' Dashboard', 'manage_options', 'analytify-dashboard', array(
453 __CLASS__,
454 'pa_page_file_path'
455 ));
456
457 add_submenu_page( 'analytify-dashboard', ANALYTIFY_NICK . ' Settings', '<b style="color:#f9845b">Settings</b>', 'manage_options', 'analytify-settings', array(
458 __CLASS__,
459 'pa_page_file_path'
460 ));
461 }
462
463 /**
464 * Creating tabs for settings
465 * @since 1.0
466 */
467
468 public function pa_settings_tabs( $current = 'authentication' ) {
469
470 $tabs = array( 'authentication' => 'Authentication',
471 'profile' => 'Profile',
472
473 'admin' => 'Admin'
474 );
475
476 echo '<div class="left-area">';
477
478 echo '<div id="icon-themes" class="icon32"><br></div>';
479 echo '<h2 class="nav-tab-wrapper">';
480
481 foreach( $tabs as $tab => $name ) {
482
483 $class = ( $tab == $current ) ? ' nav-tab-active' : '';
484 echo "<a class='nav-tab$class' href='?page=analytify-settings&tab=$tab'>$name</a>";
485 }
486
487 echo '</h2>';
488 }
489
490 /**
491 * Get profiles from user Google Analytics account profiles.
492 */
493 public function pt_get_analytics_accounts() {
494
495 try {
496
497 if( get_option( 'pa_google_token' ) !='' ) {
498 $profiles = $this->service->management_profiles->listManagementProfiles( "~all", "~all" );
499 return $profiles;
500 }
501
502 else{
503 echo '<br /><p class="description">' . __( 'You must authenticate to access your web profiles.', 'wp-analytify' ) . '</p>';
504 }
505
506 }
507
508 catch (Exception $e) {
509 die('An error occured: ' . $e->getMessage() . '\n');
510 }
511 }
512
513 public function pa_setting_url() {
514
515 return admin_url('admin.php?page=analytify-settings');
516
517 }
518
519
520 public function pt_save_data( $key_google_token ) {
521
522 update_option( 'post_analytics_token', $key_google_token );
523 $this->pa_connect();
524
525 return true;
526 }
527
528 /**
529 * Warning messages.
530 */
531 public function profile_warning() {
532
533 $profile_id = get_option( "pt_webprofile" );
534 $acces_token = get_option( "post_analytics_token" );
535
536 if (! isset( $acces_token ) || empty( $acces_token )) {
537
538 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>";
539 }
540 else{
541
542 if (! isset( $profile_id ) || empty( $profile_id )){
543 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>';
544 }
545 }
546 }
547
548
549 public function get_single_front_analytics( $content ) {
550
551 global $post, $wp_analytify;
552
553 $front_access = get_option( 'post_analytics_access' );
554
555 if ( is_single() || is_page() ) {
556
557 $post_type = get_post_type( $post->ID );
558
559 if( strlen( get_option( 'analytify_posts_stats_front' ) < 3) ) {
560 return $content;
561 }
562
563 if( is_array( get_option( 'analytify_posts_stats_front' )) and !in_array( $post_type, get_option( 'analytify_posts_stats_front' ) ) ) {
564
565 return $content;
566 }
567
568 if ( is_array( get_option( 'post_analytics_exclude_posts_front' ) ) ) {
569
570 if ( in_array( get_the_ID(), get_option( 'post_analytics_exclude_posts_front' ) ) ) {
571
572 return $content;
573 }
574 }
575
576 // Showing stats to guests
577 if ( $front_access[0] == 'every-one' || $this->pa_check_roles( $front_access )) {
578
579 $post_analytics_settings_front = array();
580 $post_analytics_settings_front = get_option( 'post_analytics_settings_front' );
581
582 $urlPost = parse_url( get_permalink( $post->ID ) );
583
584 if ( $urlPost['host'] == 'localhost' )
585 $filter = 'ga:pagePath==/'; //.$u_post['path'];
586 else
587 $filter = 'ga:pagePath==' .$urlPost['path']. '';
588
589 if( get_the_time('Y', $post->ID) < 2005 ) {
590
591 $start_date = '2005-01-01';
592 }
593 else {
594
595 $start_date = get_the_time('Y-m-d', $post->ID);
596 }
597
598 $end_date = date('Y-m-d');
599
600 ob_start();
601
602 include ANALYTIFY_ROOT_PATH . '/inc/front-menus.php';
603
604 if(! empty( $post_analytics_settings_front )){
605
606 if (is_array( $post_analytics_settings_front )){
607
608 $stats = $this->pa_get_analytics( 'ga:sessions,ga:bounces,ga:newUsers,ga:entrances,ga:pageviews,ga:sessionDuration,ga:avgSessionDuration,ga:users',$start_date, $end_date, false, false, $filter);
609
610 if ( isset( $stats->totalsForAllResults ) ) {
611
612 include ANALYTIFY_ROOT_PATH . '/views/front/general-stats.php';
613 pa_include_general( $this, $stats);
614 }
615 }
616 }
617
618 $content .= ob_get_contents();
619 ob_get_clean();
620 }
621
622 }
623
624 return $content;
625
626 }
627
628 /*
629 * get the Analytics data from ajax() call
630 *
631 */
632
633 public function get_ajax_single_admin_analytics() {
634
635 $startDate = '';
636 $endDate = '';
637 $postID = 0 ;
638 $startDate = $_POST['start_date'];
639 $endDate = $_POST['end_date'];
640 $postID = $_POST['post_id'];
641 $this->get_single_admin_analytics( $startDate, $endDate, $postID, 1 );
642
643 die();
644 }
645
646 /*
647 * get the Analytics data for wp-admin posts/pages.
648 *
649 */
650 public function get_single_admin_analytics( $start_date = '', $end_date = '', $postID = 0, $ajax = 0 ) {
651
652 global $post;
653
654 //$urlPost = parse_url( get_permalink( $post->ID ) );
655
656 if ( $postID == 0 ) {
657 $u_post = '/'; //$urlPost['path'];
658 }
659 else{
660 $u_post = parse_url( get_permalink( $postID ) );
661 }
662
663 if ( $u_post['host'] == 'localhost' )
664 $filter = false;
665 else
666 $filter = 'ga:pagePath==' .$u_post['path']. '';
667
668
669 if ( $start_date == '' ) {
670
671 $s_date = get_the_time('Y-m-d', $post->ID);
672 if(get_the_time('Y', $post->ID) < 2005){
673 $s_date = '2005-01-01';
674 }
675 }
676 else{
677 $s_date = $start_date;
678 }
679
680 if ( $end_date == '' ) {
681 $e_date = date('Y-m-d');
682 }
683 else{
684 $e_date = $end_date;
685 }
686
687 $show_settings = array();
688 $show_settings = get_option('post_analytics_settings_back');
689
690 // Stop here, if user has disable backend analytics i.e OFF
691 if ( get_option( 'post_analytics_disable_back' ) == 1 and $ajax == 0) {
692 return;
693 }
694
695 echo '<p> Displaying Analytics of this page from ' . date("jS F, Y", strtotime($s_date)) . ' to '. date("jS F, Y", strtotime($e_date)) . '</p>';
696
697 if( !empty( $show_settings )){
698
699 if (is_array( $show_settings )){
700
701 if (in_array( 'show-overall-back', $show_settings )) {
702
703 $stats = $this->pa_get_analytics( 'ga:sessions,ga:bounces,ga:newUsers,ga:entrances,ga:pageviews,ga:sessionDuration,ga:avgSessionDuration,ga:users',$s_date, $e_date, false, false, $filter);
704
705 if ( isset( $stats->totalsForAllResults ) ) {
706
707 include ANALYTIFY_ROOT_PATH . '/views/admin/single-general-stats.php';
708 wpa_single_include_general( $this, $stats);
709 }
710 }
711 }
712 }
713 }
714
715
716 /*
717 * Pretty numbers
718 */
719 function wpa_pretty_numbers( $num ) {
720
721 return round(($num/1000),2).'k';
722 }
723
724 /*
725 * format numbers
726 */
727 function wpa_number_format( $num ) {
728
729 return number_format($num);
730 }
731
732 /*
733 * Pretty time to display
734 */
735 function pa_pretty_time( $time ) {
736
737 // Check if numeric
738 if ( is_numeric($time) ) {
739
740 $value = array(
741 "years" => '00',
742 "days" => '00',
743 "hours" => '',
744 "minutes" => '',
745 "seconds" => ''
746 );
747
748 if ($time >= 31556926) {
749 $value["years"] = floor($time / 31556926);
750 $time = ($time % 31556926);
751 } //$time >= 31556926
752
753 if ($time >= 86400)
754 {
755 $value["days"] = floor($time / 86400);
756 $time = ($time % 86400);
757 } //$time >= 86400
758 if ($time >= 3600)
759 {
760 $value["hours"] = str_pad(floor($time / 3600), 1, 0, STR_PAD_LEFT);
761 $time = ($time % 3600);
762 } //$time >= 3600
763 if ($time >= 60)
764 {
765 $value["minutes"] = str_pad(floor($time / 60), 1, 0, STR_PAD_LEFT);
766 $time = ($time % 60);
767 } //$time >= 60
768 $value["seconds"] = str_pad(floor($time), 1, 0, STR_PAD_LEFT);
769 # Get the hour:minute:second version
770 if($value['hours']!=''){
771 $attach_hours='<sub>h</sub> ';
772 }
773 if($value['minutes']!=''){
774 $attach_min='<sub>min</sub> ';
775 }
776 if($value['seconds']!=''){
777 $attach_sec='<sub>sec</sub>';
778 }
779 return $value['hours'] .@$attach_hours. $value['minutes'] .@$attach_min. $value['seconds'].$attach_sec;
780 //return $value['hours'] . ':' . $value['minutes'] . ':' . $value['seconds'];
781 } //is_numeric($time)
782 else
783 {
784 return false;
785 }
786 }
787
788
789 public function pa_check_roles( $access_level ) {
790
791 if ( is_user_logged_in () && isset ( $access_level ) ) {
792
793 global $current_user;
794 $roles = $current_user->roles;
795
796 /*if ( ( current_user_can ( 'manage_options' ) ) ) {
797
798 return true;
799 }*/
800
801 if ( in_array ( $roles[0], $access_level ) ) {
802
803 return true;
804 }
805 else {
806
807 return false;
808 }
809 }
810 }
811
812 public function pa_welcome_message() {
813
814 $pointer_content = '<h3>Analytify - Google Analytics for WordPress.</h3>';
815 $pointer_content .= '<p>Thank you for activating Analytify Plugin. Enjoy Google Analytics for everything in WordPress.</p>';
816 ?>
817
818 <script type="text/javascript">
819 //<![CDATA[
820 jQuery(document).ready( function($) {
821
822 $('#toplevel_page_pa-dashboard').pointer({
823 content: '<?php echo $pointer_content; ?>',
824 position: 'left',
825 close: function() {
826 <?php update_option("pa_welcome_message",1) ?>
827 }
828 }).pointer('open');
829 });
830 //]]>
831 </script>
832
833 <?php
834 }
835
836 /*
837 * Activate options by default on installing the plugin.
838 */
839 static function install() {
840
841 update_option( 'analytify_posts_stats', array( 'post','page' ));
842 update_option( 'post_analytics_disable_back' , 1 );
843 update_option( 'analytify_code' , 1 );
844 update_option( 'post_analytics_settings_back' , array( 'show-overall-back' ) );
845 update_option( 'post_analytics_access_back' , array( 'editor','administrator' ) );
846 update_option( 'display_tracking_code' , array( 'administrator' ) );
847
848
849 }
850
851 static function uninstall() {
852
853 delete_option( 'analytify_posts_stats' );
854 delete_option( 'pa_google_token' );
855 delete_option( 'pa_welcome_message' );
856 delete_option( 'post_analytics_token' );
857
858 }
859
860 }
861
862 $wp_analytify = new WP_Analytify();
863
864 $wp_analytify->pa_check_warnings();
865
866 } //end if
867 ?>