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