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

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