Google Analytics Dashboard for WP (GADWP) - Version 4.8

Version Description

  • Enhancement: optimize the number of ajax requests
  • Enhancement: new versioning standard for a better management of automatic updates (M.M.m.u)
  • Enhancement: JavaScript code cleanup and optimization
  • Enhancement: memory usage optimization
  • Enhancement: small assets fixes, UX improvements, props by Adrian Pop
  • Enhancement: introducing reports for all frontend web pages (new feature)
  • Enhancement: gadwp_frontenditem_uri filter to allow URI corrections for frontend item reports
  • Bug Fix: avoid double encoding of UTF-8 URIs
  • Bug Fix: 100% number formatting issue on bounce rate report
Download this release

Release Info

Developer deconf
Plugin Icon 128x128 Google Analytics Dashboard for WP (GADWP)
Version 4.8
Comparing to
See all releases

Code changes from version 4.7.5 to 4.8

admin/ajax-actions.php CHANGED
@@ -7,125 +7,139 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
-
13
- if (! class_exists('GADWP_Backend_Ajax')) {
14
-
15
- final class GADWP_Backend_Ajax
16
- {
17
-
18
- private $gadwp;
19
-
20
- public function __construct()
21
- {
22
- $this->gadwp = GADWP();
23
-
24
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && (1 == $this->gadwp->config->options['dashboard_widget'])) {
25
- // Admin Widget action
26
- add_action('wp_ajax_gadash_get_widgetreports', array(
27
- $this,
28
- 'ajax_widget_reports'
29
- ));
30
- }
31
-
32
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && (1 == $this->gadwp->config->options['item_reports'])) {
33
- // Items action
34
- add_action('wp_ajax_gadwp_get_ItemReports', array(
35
- $this,
36
- 'ajax_item_reports'
37
- ));
38
- }
39
- }
40
-
41
- /**
42
- * Ajax handler for Items (posts/pages)
43
- *
44
- * @return json|int
45
- */
46
- public function ajax_item_reports()
47
- {
48
- if (! isset($_REQUEST['gadwp_security_item_reports']) || ! wp_verify_nonce($_REQUEST['gadwp_security_item_reports'], 'gadwp_get_itemreports')) {
49
- wp_die(- 30);
50
- }
51
- $from = $_REQUEST['from'];
52
- $to = $_REQUEST['to'];
53
- $query = $_REQUEST['query'];
54
- $filter_id = $_REQUEST['filter'];
55
- if (ob_get_length()) {
56
- ob_clean();
57
- }
58
-
59
- if (! GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) || 0 == $this->gadwp->config->options['item_reports']) {
60
- wp_die(- 31);
61
- }
62
- if ($this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail'] && $from && $to) {
63
- if (null === $this->gadwp->gapi_controller) {
64
- $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
65
- }
66
- } else {
67
- wp_die(- 24);
68
- }
69
- $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
70
- $profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId);
71
- if (isset($profile_info[4])) {
72
- $this->gadwp->gapi_controller->timeshift = $profile_info[4];
73
- } else {
74
- $this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time();
75
- }
76
-
77
- $uri_parts = explode('/', get_permalink($filter_id), 4);
78
-
79
- if (isset($uri_parts[3])) {
80
- $uri = '/' . $uri_parts[3];
81
- } else {
82
- wp_die(- 25);
83
- }
84
-
85
- // allow URL correction before sending an API request
86
- $filter = apply_filters('gadwp_backenditem_uri', $uri);
87
-
88
- //Encode URL
89
- $filter = rawurlencode($filter);
90
-
91
- $this->gadwp->gapi_controller->get($projectId, $query, $from, $to, $filter);
92
- }
93
-
94
- /**
95
- * Ajax handler for Admin Widget
96
- *
97
- * @return json|int
98
- */
99
- public function ajax_widget_reports()
100
- {
101
- if (! isset($_REQUEST['gadash_security_widget_reports']) || ! wp_verify_nonce($_REQUEST['gadash_security_widget_reports'], 'gadash_get_widgetreports')) {
102
- wp_die(- 30);
103
- }
104
- $projectId = $_REQUEST['projectId'];
105
- $from = $_REQUEST['from'];
106
- $to = $_REQUEST['to'];
107
- $query = $_REQUEST['query'];
108
- if (ob_get_length()) {
109
- ob_clean();
110
- }
111
-
112
- if (! GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) || 0 == $this->gadwp->config->options['dashboard_widget']) {
113
- wp_die(- 31);
114
- }
115
- if ($this->gadwp->config->options['ga_dash_token'] && $projectId && $from && $to) {
116
- if (null === $this->gadwp->gapi_controller) {
117
- $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
118
- }
119
- } else {
120
- wp_die(- 24);
121
- }
122
- $profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId);
123
- if (isset($profile_info[4])) {
124
- $this->gadwp->gapi_controller->timeshift = $profile_info[4];
125
- } else {
126
- $this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time();
127
- }
128
- $this->gadwp->gapi_controller->get($projectId, $query, $from, $to);
129
- }
130
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
+
13
+ if ( ! class_exists( 'GADWP_Backend_Ajax' ) ) {
14
+
15
+ final class GADWP_Backend_Ajax {
16
+
17
+ private $gadwp;
18
+
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
21
+
22
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) && ( 1 == $this->gadwp->config->options['dashboard_widget'] ) ) {
23
+ // Admin Widget action
24
+ add_action( 'wp_ajax_gadash_get_widgetreports', array( $this, 'ajax_widget_reports' ) );
25
+ }
26
+
27
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) && ( 1 == $this->gadwp->config->options['backend_item_reports'] ) ) {
28
+ // Items action
29
+ add_action( 'wp_ajax_gadwp_backend_item_reports', array( $this, 'ajax_item_reports' ) );
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Ajax handler for Item Reports
35
+ *
36
+ * @return json|int
37
+ */
38
+ public function ajax_item_reports() {
39
+ if ( ! isset( $_REQUEST['gadwp_security_backend_item_reports'] ) || ! wp_verify_nonce( $_REQUEST['gadwp_security_backend_item_reports'], 'gadwp_backend_item_reports' ) ) {
40
+ wp_die( - 30 );
41
+ }
42
+
43
+ $from = $_REQUEST['from'];
44
+ $to = $_REQUEST['to'];
45
+ $query = $_REQUEST['query'];
46
+ $filter_id = $_REQUEST['filter'];
47
+
48
+ if ( ob_get_length() ) {
49
+ ob_clean();
50
+ }
51
+
52
+ if ( ! GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) || 0 == $this->gadwp->config->options['backend_item_reports'] ) {
53
+ wp_die( - 31 );
54
+ }
55
+ if ( $this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail'] && $from && $to ) {
56
+ if ( null === $this->gadwp->gapi_controller ) {
57
+ $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
58
+ }
59
+ } else {
60
+ wp_die( - 24 );
61
+ }
62
+ $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
63
+ $profile_info = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $projectId );
64
+ if ( isset( $profile_info[4] ) ) {
65
+ $this->gadwp->gapi_controller->timeshift = $profile_info[4];
66
+ } else {
67
+ $this->gadwp->gapi_controller->timeshift = (int) current_time( 'timestamp' ) - time();
68
+ }
69
+
70
+ $uri_parts = explode( '/', get_permalink( $filter_id ), 4 );
71
+
72
+ if ( isset( $uri_parts[3] ) ) {
73
+ $uri = '/' . $uri_parts[3];
74
+ } else {
75
+ wp_die( - 25 );
76
+ }
77
+
78
+ // allow URL correction before sending an API request
79
+ $filter = apply_filters( 'gadwp_backenditem_uri', $uri );
80
+
81
+ // Encode URL
82
+ $filter = rawurlencode( rawurldecode( $filter ) );
83
+
84
+ $queries = explode( ',', $query );
85
+
86
+ $results = array();
87
+
88
+ foreach ( $queries as $value ) {
89
+ $results[] = $this->gadwp->gapi_controller->get( $projectId, $value, $from, $to, $filter );
90
+ }
91
+
92
+ wp_send_json( $results );
93
+ }
94
+
95
+ /**
96
+ * Ajax handler for Admin Widget
97
+ *
98
+ * @return json|int
99
+ */
100
+ public function ajax_widget_reports() {
101
+ if ( ! isset( $_REQUEST['gadash_security_widget_reports'] ) || ! wp_verify_nonce( $_REQUEST['gadash_security_widget_reports'], 'gadash_get_widgetreports' ) ) {
102
+ wp_die( - 30 );
103
+ }
104
+
105
+ $projectId = $_REQUEST['projectId'];
106
+ $from = $_REQUEST['from'];
107
+ $to = $_REQUEST['to'];
108
+ $query = $_REQUEST['query'];
109
+
110
+ if ( ob_get_length() ) {
111
+ ob_clean();
112
+ }
113
+
114
+ if ( ! GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) || 0 == $this->gadwp->config->options['dashboard_widget'] ) {
115
+ wp_die( - 31 );
116
+ }
117
+
118
+ if ( $this->gadwp->config->options['ga_dash_token'] && $projectId && $from && $to ) {
119
+ if ( null === $this->gadwp->gapi_controller ) {
120
+ $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
121
+ }
122
+ } else {
123
+ wp_die( - 24 );
124
+ }
125
+
126
+ $profile_info = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $projectId );
127
+
128
+ if ( isset( $profile_info[4] ) ) {
129
+ $this->gadwp->gapi_controller->timeshift = $profile_info[4];
130
+ } else {
131
+ $this->gadwp->gapi_controller->timeshift = (int) current_time( 'timestamp' ) - time();
132
+ }
133
+
134
+ $queries = explode( ',', $query );
135
+
136
+ $results = array();
137
+
138
+ foreach ( $queries as $value ) {
139
+ $results[] = $this->gadwp->gapi_controller->get( $projectId, $value, $from, $to );
140
+ }
141
+
142
+ wp_send_json( $results );
143
+ }
144
+ }
145
  }
admin/css/gadwp.css CHANGED
@@ -1,5 +1,6 @@
1
  /* Tab navigation */
2
- #gadwp-events, #gadwp-custom, #gadwp-advanced, #gadwp-exclude, #gadwp-config {
 
3
  display: none;
4
  }
5
 
@@ -22,8 +23,8 @@ td.title-select {
22
  width: 300px;
23
  }
24
 
25
- .gadwp-help{
26
- padding-left:15px;
27
  }
28
 
29
  td.debugging {
@@ -78,7 +79,7 @@ td.roles {
78
  }
79
 
80
  #poststuff h2 {
81
- padding-bottom:0;
82
  }
83
 
84
  /* Options pages ON/OFF Switch */
@@ -86,6 +87,13 @@ td.roles {
86
  position: relative;
87
  width: 50px;
88
  float: left;
 
 
 
 
 
 
 
89
  -webkit-user-select: none;
90
  -moz-user-select: none;
91
  -ms-user-select: none;
@@ -95,16 +103,11 @@ td.roles {
95
  display: none !important;
96
  }
97
 
98
- .onoffswitch:hover {
99
- border-color: #5b9dd9;
100
- -webkit-box-shadow: 0 0 2px rgba(30,140,190,.8);
101
- box-shadow: 0 0 2px rgba(30,140,190,.8);
102
- }
103
-
104
  .onoffswitch-label {
105
  display: block;
106
  overflow: hidden;
107
  cursor: pointer;
 
108
  border: 1px solid #ddd;
109
  border-radius: 2px;
110
  }
@@ -112,64 +115,74 @@ td.roles {
112
  .onoffswitch-inner {
113
  width: 200%;
114
  margin-left: -100%;
115
- -moz-transition: margin 0.3s ease-in 0s;
116
- -webkit-transition: margin 0.3s ease-in 0s;
117
- -o-transition: margin 0.3s ease-in 0s;
118
- transition: margin 0.3s ease-in 0s;
 
119
  }
120
 
121
  .onoffswitch-inner:before, .onoffswitch-inner:after {
122
  float: left;
123
  width: 50%;
124
- height: 22px;
125
- padding: 0;
126
- line-height: 22px;
127
- font-size: 12px;
128
- color: white;
129
- font-family: Trebuchet, Arial, sans-serif;
130
  font-weight: normal;
131
  -moz-box-sizing: border-box;
132
  -webkit-box-sizing: border-box;
 
133
  box-sizing: border-box;
 
 
 
134
  }
135
 
136
  .onoffswitch-inner:before {
137
  content: "On";
138
  padding-left: 5px;
139
- background-color: #00a0d2;
140
- color: #fff;
 
141
  }
142
 
143
  .onoffswitch-inner:after {
144
  content: "Off";
145
  padding-right: 5px;
146
- background-color: #fff;
147
- color: #999;
148
  text-align: right;
149
  }
150
 
151
  .onoffswitch-switch {
152
  width: 22px;
153
- margin: 0px;
154
  background: #fff;
 
155
  border: 1px solid #ddd;
156
  border-radius: 2px;
157
  position: absolute;
158
  top: 0;
159
  bottom: 0;
160
- right: 26px;
161
- -moz-transition: all 0.3s ease-in 0s;
162
- -webkit-transition: all 0.3s ease-in 0s;
163
- -o-transition: all 0.3s ease-in 0s;
164
- transition: all 0.3s ease-in 0s;
165
- background-image: -moz-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%,
166
- rgba(0, 0, 0, 0) 100%);
167
- background-image: -webkit-linear-gradient(center top, rgba(0, 0, 0, 0.1)
168
- 0%, rgba(0, 0, 0, 0) 100%);
169
- background-image: -o-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%,
170
- rgba(0, 0, 0, 0) 100%);
171
- background-image: linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%,
172
- rgba(0, 0, 0, 0) 100%);
 
 
 
 
 
 
 
 
 
 
173
  }
174
 
175
  .onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-inner {
@@ -183,6 +196,7 @@ td.roles {
183
  .switch-desc {
184
  float: left;
185
  margin-left: 10px;
 
186
  }
187
 
188
  /* Admin Widget & Real-Time Stats*/
1
  /* Tab navigation */
2
+ #gadwp-events, #gadwp-custom, #gadwp-advanced, #gadwp-exclude,
3
+ #gadwp-config {
4
  display: none;
5
  }
6
 
23
  width: 300px;
24
  }
25
 
26
+ .gadwp-help {
27
+ padding-left: 15px;
28
  }
29
 
30
  td.debugging {
79
  }
80
 
81
  #poststuff h2 {
82
+ padding-bottom: 0;
83
  }
84
 
85
  /* Options pages ON/OFF Switch */
87
  position: relative;
88
  width: 50px;
89
  float: left;
90
+ border: none !important;
91
+ padding: 0 !important;
92
+ height: 22px !important;
93
+ -moz-box-shadow: none !important;
94
+ -webkit-box-shadow: none !important;
95
+ -o-box-shadow: none !important;
96
+ box-shadow: none !important;
97
  -webkit-user-select: none;
98
  -moz-user-select: none;
99
  -ms-user-select: none;
103
  display: none !important;
104
  }
105
 
 
 
 
 
 
 
106
  .onoffswitch-label {
107
  display: block;
108
  overflow: hidden;
109
  cursor: pointer;
110
+ background: transparent;
111
  border: 1px solid #ddd;
112
  border-radius: 2px;
113
  }
115
  .onoffswitch-inner {
116
  width: 200%;
117
  margin-left: -100%;
118
+ border-radius: 2px;
119
+ -moz-transition: margin 0.2s ease-in 0s;
120
+ -webkit-transition: margin 0.2s ease-in 0s;
121
+ -o-transition: margin 0.2s ease-in 0s;
122
+ transition: margin 0.2s ease-in 0s;
123
  }
124
 
125
  .onoffswitch-inner:before, .onoffswitch-inner:after {
126
  float: left;
127
  width: 50%;
 
 
 
 
 
 
128
  font-weight: normal;
129
  -moz-box-sizing: border-box;
130
  -webkit-box-sizing: border-box;
131
+ -o-box-sizing: border-box;
132
  box-sizing: border-box;
133
+ height: 22px;
134
+ line-height: 22px;
135
+ font-size: 12px;
136
  }
137
 
138
  .onoffswitch-inner:before {
139
  content: "On";
140
  padding-left: 5px;
141
+ border-bottom: none;
142
+ /* background-color: #00a0d2;
143
+ color: #fff; /* inherit from button props */
144
  }
145
 
146
  .onoffswitch-inner:after {
147
  content: "Off";
148
  padding-right: 5px;
149
+ background-color: #ddd;
 
150
  text-align: right;
151
  }
152
 
153
  .onoffswitch-switch {
154
  width: 22px;
155
+ height: 22px;
156
  background: #fff;
157
+ color: #ddd;
158
  border: 1px solid #ddd;
159
  border-radius: 2px;
160
  position: absolute;
161
  top: 0;
162
  bottom: 0;
163
+ right: 27px;
164
+ -moz-transition: all 0.2s ease-in 0s;
165
+ -webkit-transition: all 0.2s ease-in 0s;
166
+ -o-transition: all 0.2s ease-in 0s;
167
+ transition: all 0.2s ease-in 0s;
168
+ }
169
+
170
+ .onoffswitch-switch:hover {
171
+ color: #aaa;
172
+ border-color: #aaa;
173
+ }
174
+
175
+ .onoffswitch-switch:after {
176
+ margin: 0;
177
+ outline: 0;
178
+ display: inline-block;
179
+ font: 400 16px/16px dashicons;
180
+ content: "\f228";
181
+ padding: 3px 0 0 3px;
182
+ text-align: left;
183
+ text-decoration: none;
184
+ -webkit-font-smoothing: antialiased;
185
+ -moz-osx-font-smoothing: grayscale;
186
  }
187
 
188
  .onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-inner {
196
  .switch-desc {
197
  float: left;
198
  margin-left: 10px;
199
+ line-height: 20px;
200
  }
201
 
202
  /* Admin Widget & Real-Time Stats*/
admin/css/item-reports.css CHANGED
@@ -1,4 +1,4 @@
1
- /* Posts & Pages stats */
2
  .column-gadwp_stats {
3
  width: 70px;
4
  }
1
+ /* Backend Item Reports */
2
  .column-gadwp_stats {
3
  width: 70px;
4
  }
admin/images/google-analytics-dashboard.png CHANGED
Binary file
admin/item-reports.php CHANGED
@@ -7,65 +7,58 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
 
13
- if (! class_exists('GADWP_Backend_Item_Reports')) {
14
 
15
- final class GADWP_Backend_Item_Reports
16
- {
17
 
18
- private $gadwp;
19
 
20
- public function __construct()
21
- {
22
- $this->gadwp = GADWP();
23
-
24
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && 1 == $this->gadwp->config->options['item_reports']) {
25
-
26
- // Add custom column in Posts List
27
- add_filter('manage_posts_columns', array(
28
- $this,
29
- 'add_columns'
30
- ));
31
- // Populate custom column in Posts List
32
- add_action('manage_posts_custom_column', array(
33
- $this,
34
- 'add_icons'
35
- ), 10, 2);
36
- // Add custom column in Pages List
37
- add_filter('manage_pages_columns', array(
38
- $this,
39
- 'add_columns'
40
- ));
41
- // Populate custom column in Pages List
42
- add_action('manage_pages_custom_column', array(
43
- $this,
44
- 'add_icons'
45
- ), 10, 2);
46
- }
47
- }
48
 
49
- public function add_icons($column, $id)
50
- {
51
- global $wp_version;
52
-
53
- if ($column != 'gadwp_stats') {
54
- return;
55
- }
56
-
57
- if (version_compare($wp_version, '3.8.0', '>=')) {
58
- echo '<a id="gadwp-' . $id . '" title="' . get_the_title($id) . '" href="#' . $id . '" class="gadwp-icon dashicons-before dashicons-chart-area"></a>';
59
- } else {
60
- echo '<a id="gadwp-' . $id . '" title="' . get_the_title($id) . '" href="#' . $id . '"><img class="gadwp-icon-oldwp" src="' . GADWP_URL . 'admin/images/gadash-icon.png"</a>';
61
- }
62
- }
63
 
64
- public function add_columns($columns)
65
- {
66
- return array_merge($columns, array(
67
- 'gadwp_stats' => __('Analytics', 'ga-dash')
68
- ));
69
- }
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
 
13
+ if ( ! class_exists( 'GADWP_Backend_Item_Reports' ) ) {
14
 
15
+ final class GADWP_Backend_Item_Reports {
 
16
 
17
+ private $gadwp;
18
 
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) && 1 == $this->gadwp->config->options['backend_item_reports'] ) {
23
+ // Add custom column in Posts List
24
+ add_filter( 'manage_posts_columns', array(
25
+ $this,
26
+ 'add_columns' ) );
 
 
 
 
 
 
 
 
 
27
 
28
+ // Populate custom column in Posts List
29
+ add_action( 'manage_posts_custom_column', array(
30
+ $this,
31
+ 'add_icons' ), 10, 2 );
32
+
33
+ // Add custom column in Pages List
34
+ add_filter( 'manage_pages_columns', array(
35
+ $this,
36
+ 'add_columns' ) );
37
+
38
+ // Populate custom column in Pages List
39
+ add_action( 'manage_pages_custom_column', array(
40
+ $this,
41
+ 'add_icons' ), 10, 2 );
42
+ }
43
+ }
44
+
45
+ public function add_icons( $column, $id ) {
46
+ global $wp_version;
47
+
48
+ if ( $column != 'gadwp_stats' ) {
49
+ return;
50
+ }
51
+
52
+ if ( version_compare( $wp_version, '3.8.0', '>=' ) ) {
53
+ echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '" class="gadwp-icon dashicons-before dashicons-chart-area"></a>';
54
+ } else {
55
+ echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '"><img class="gadwp-icon-oldwp" src="' . GADWP_URL . 'admin/images/gadash-icon.png"</a>';
56
+ }
57
+ }
58
+
59
+ public function add_columns( $columns ) {
60
+ return array_merge( $columns, array(
61
+ 'gadwp_stats' => __( 'Analytics', 'ga-dash' ) ) );
62
+ }
63
+ }
64
  }
admin/js/item-reports.js CHANGED
@@ -1,629 +1,616 @@
1
  "use strict";
2
 
3
- google.load("visualization", "1", {
4
- packages : ["corechart", "table", "orgchart", "geochart"]
5
- });
6
-
7
- jQuery(document).ready(
8
-
9
- function() {
10
- jQuery('a[id^="gadwp-"]').click(function(e) {
11
-
12
- var item_id = getID(this);
13
- var slug = "-" + item_id;
14
-
15
- if (!jQuery("#gadwp-window" + slug).length > 0) {
16
- jQuery("body").append('<div id="gadwp-window' + slug + '"></div>');
17
- }
18
- jQuery('#gadwp-window' + slug).gadwpItemReport(slug, item_id);
19
- });
20
-
21
- function getID(item) {
22
- if (typeof item.id == "undefined") {
23
- return 0
24
- }
25
- if (item.id.split('-')[1] == "undefined") {
26
- return 0;
27
- } else {
28
- return item.id.split('-')[1];
29
- }
30
- }
31
-
32
- // on window resize
33
- jQuery(window).resize(function() {
34
- fluidDialog();
35
- });
36
-
37
- // dialog width larger than viewport
38
- jQuery(document).on("dialogopen", ".ui-dialog", function(event, ui) {
39
- fluidDialog();
40
- });
41
-
42
- function fluidDialog() {
43
- var visible = jQuery(".ui-dialog:visible");
44
- // on each visible dialog
45
- visible.each(function() {
46
- var $this = jQuery(this);
47
- var dialog = $this.find(".ui-dialog-content").data("ui-dialog");
48
- // on each fluid dialog
49
- if (dialog.options.fluid) {
50
- var wWidth = jQuery(window).width();
51
- // window width vs dialog width
52
- if (wWidth < (parseInt(dialog.options.maxWidth) + 50)) {
53
- // don't fill the entire screen
54
- $this.css("max-width", "90%");
55
- } else {
56
- // maxWidth bug fix
57
- $this.css("max-width", dialog.options.maxWidth + "px");
58
- }
59
- // change dialog position
60
- dialog.option("position", dialog.options.position);
61
- }
62
- });
63
-
64
- }
65
- });
66
-
67
- jQuery.fn.extend({
68
- gadwpItemReport : function(slug, item_id) {
69
-
70
- var template = {
71
-
72
- data : '<div id="gadwp-container' + slug + '"><select id="gadwp-sel-period' + slug + '"></select> <select id="gadwp-sel-report' + slug + '"></select><div id="gadwp-progressbar' + slug + '"></div><div id="gadwp-status' + slug + '"></div><div id="gadwp-reports' + slug + '"></div><div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;margin-top:10px;">' + gadwp_item_data.i18n[14] + ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_report&utm_medium=link&utm_content=back_report&utm_campaign=gadwp" rel="nofollow" style="text-decoration:none;font-size:1em;">GADWP</a>&nbsp;</div></div>',
73
-
74
- addOptions : function(id, list) {
75
-
76
- var output = [];
77
- jQuery.each(list, function(key, value) {
78
- if (key == '30daysAgo' || key == 'sessions') {
79
- output.push('<option value="' + key + '" selected="selected">' + value + '</option>');
80
- } else {
81
- output.push('<option value="' + key + '">' + value + '</option>');
82
- }
83
- });
84
- jQuery(id).html(output.join(''));
85
- },
86
-
87
- init : function() {
88
- if (jQuery('#gadwp-window' + slug).html().length) { // add main template once
89
- return;
90
- }
91
-
92
- jQuery('#gadwp-window' + slug).append(this.data);
93
-
94
- this.addOptions('#gadwp-sel-period' + slug, gadwp_item_data.dateList);
95
- this.addOptions('#gadwp-sel-report' + slug, gadwp_item_data.reportList);
96
-
97
- }
98
- }
99
-
100
- var reports = {
101
-
102
- npcounter : 0,
103
- prs : '',
104
- trafficchannels : '',
105
- trafficmediums : '',
106
- traffictype : '',
107
- trafficorganic : '',
108
- socialnetworks : '',
109
- locations : '',
110
- mainchart : '',
111
- bottomstats : '',
112
-
113
- alertMessage : function(msg) {
114
- jQuery("#gadwp-status" + slug).css({
115
- "margin-top" : "3px",
116
- "padding-left" : "5px",
117
- "height" : "auto",
118
- "color" : "#000",
119
- "border-left" : "5px solid red"
120
- });
121
- jQuery("#gadwp-status" + slug).html(msg);
122
- },
123
-
124
- drawprs : function(gadwp_prs) {
125
- var data = google.visualization.arrayToDataTable(gadwp_prs);
126
- var options = {
127
- page : 'enable',
128
- pageSize : 10,
129
- width : '100%',
130
- allowHtml: true
131
- };
132
-
133
- var chart = new google.visualization.Table(document.getElementById('gadwp-prs' + slug));
134
- chart.draw(data, options);
135
- },
136
-
137
- drawtrafficchannels : function(gadwp_trafficchannels) {
138
- var data = google.visualization.arrayToDataTable(gadwp_trafficchannels);
139
- var options = {
140
- allowCollapse : true,
141
- allowHtml : true
142
- };
143
-
144
- var chart = new google.visualization.OrgChart(document.getElementById('gadwp-trafficchannels' + slug));
145
- chart.draw(data, options);
146
- },
147
-
148
- drawtrafficmediums : function(gadwp_trafficmediums) {
149
- var data = google.visualization.arrayToDataTable(gadwp_trafficmediums);
150
- var options = {
151
- is3D : false,
152
- tooltipText : 'percentage',
153
- legend : 'none',
154
- chartArea : {
155
- width : '99%',
156
- height : '80%'
157
- },
158
- title : gadwp_item_data.i18n[1],
159
- colors : gadwp_item_data.colorVariations
160
- };
161
-
162
- var chart = new google.visualization.PieChart(document.getElementById('gadwp-trafficmediums' + slug));
163
- chart.draw(data, options);
164
- },
165
-
166
- drawtraffictype : function(gadwp_traffictype) {
167
- var data = google.visualization.arrayToDataTable(gadwp_traffictype);
168
- var options = {
169
- is3D : false,
170
- tooltipText : 'percentage',
171
- legend : 'none',
172
- chartArea : {
173
- width : '99%',
174
- height : '80%'
175
- },
176
- title : gadwp_item_data.i18n[2],
177
- colors : gadwp_item_data.colorVariations
178
- };
179
-
180
- var chart = new google.visualization.PieChart(document.getElementById('gadwp-traffictype' + slug));
181
- chart.draw(data, options);
182
- },
183
-
184
- drawsocialnetworks : function(gadwp_socialnetworks) {
185
- var data = google.visualization.arrayToDataTable(gadwp_socialnetworks);
186
- var options = {
187
- is3D : false,
188
- tooltipText : 'percentage',
189
- legend : 'none',
190
- chartArea : {
191
- width : '99%',
192
- height : '80%'
193
- },
194
- title : gadwp_item_data.i18n[3],
195
- colors : gadwp_item_data.colorVariations
196
- };
197
-
198
- var chart = new google.visualization.PieChart(document.getElementById('gadwp-socialnetworks' + slug));
199
- chart.draw(data, options);
200
- },
201
-
202
- drawtrafficorganic : function(gadwp_trafficorganic) {
203
- var data = google.visualization.arrayToDataTable(gadwp_trafficorganic);
204
- var options = {
205
- is3D : false,
206
- tooltipText : 'percentage',
207
- legend : 'none',
208
- chartArea : {
209
- width : '99%',
210
- height : '80%'
211
- },
212
- title : gadwp_item_data.i18n[4],
213
- colors : gadwp_item_data.colorVariations
214
- };
215
-
216
- var chart = new google.visualization.PieChart(document.getElementById('gadwp-trafficorganic' + slug));
217
- chart.draw(data, options);
218
- },
219
-
220
- drawlocations : function(gadwp_locations) {
221
- var data = google.visualization.arrayToDataTable(gadwp_locations);
222
- var options = {
223
- page : 'enable',
224
- pageSize : 10,
225
- width : '100%'
226
- };
227
-
228
- var chart = new google.visualization.Table(document.getElementById('gadwp-locations' + slug));
229
- chart.draw(data, options);
230
- },
231
-
232
- drawmaplocations : function(gadwp_locations) {
233
-
234
- var data = google.visualization.arrayToDataTable(gadwp_locations);
235
-
236
- var options = {
237
- chartArea : {
238
- width : '99%',
239
- height : '90%'
240
- },
241
- colors : [gadwp_item_data.colorVariations[5], gadwp_item_data.colorVariations[4]],
242
- }
243
-
244
- if (gadwp_item_data.region) {
245
- options.region = gadwp_item_data.region;
246
- options.displayMode = 'markers';
247
- options.datalessRegionColor = 'EFEFEF';
248
- }
249
-
250
- var chart = new google.visualization.GeoChart(document.getElementById('gadwp-map' + slug));
251
- chart.draw(data, options);
252
- },
253
-
254
- drawmainchart : function(gadwp_mainchart) {
255
-
256
- var data = google.visualization.arrayToDataTable(gadwp_mainchart);
257
-
258
- var options = {
259
- legend : {
260
- position : 'none'
261
- },
262
- pointSize : 3,
263
- colors : [gadwp_item_data.colorVariations[0], gadwp_item_data.colorVariations[4]],
264
- chartArea : {
265
- width : '99%',
266
- height : '90%'
267
- },
268
- vAxis : {
269
- textPosition : "in",
270
- minValue : 0
271
- },
272
- hAxis : {
273
- textPosition : 'none'
274
- }
275
- };
276
- var chart = new google.visualization.AreaChart(document.getElementById('gadwp-mainchart' + slug));
277
- chart.draw(data, options);
278
- },
279
-
280
- drawbottomstats : function(gadwp_bottomstats) {
281
- jQuery("#gdsessions" + slug).text(gadwp_bottomstats[0]);
282
- jQuery("#gdusers" + slug).text(gadwp_bottomstats[1]);
283
- jQuery("#gdpageviews" + slug).text(gadwp_bottomstats[2]);
284
- jQuery("#gdbouncerate" + slug).text(parseFloat(gadwp_bottomstats[3]).toFixed(2) + "%");
285
- jQuery("#gdorganicsearch" + slug).text(gadwp_bottomstats[4]);
286
- jQuery("#gdpagespervisit" + slug).text(parseFloat(gadwp_bottomstats[5]).toFixed(2));
287
- },
288
-
289
- checknpcounter : function(max) {
290
- try {
291
- if (this.npcounter == max) {
292
- NProgress.done();
293
- } else {
294
- this.npcounter++;
295
- NProgress.set((1 / (max + 1)) * this.npcounter);
296
- }
297
- } catch (e) {
298
- }
299
- },
300
-
301
- throwDebug : function(response) {
302
- jQuery("#gadwp-status" + slug).css({
303
- "margin-top" : "3px",
304
- "padding-left" : "5px",
305
- "height" : "auto",
306
- "color" : "#000",
307
- "border-left" : "5px solid red"
308
- });
309
- jQuery("#gadwp-status" + slug).html(gadwp_item_data.i18n[11]);
310
- console.log("\n********************* GADWP Log ********************* \n\n" + response);
311
- },
312
-
313
- throwError : function(target, response, n, p) {
314
- jQuery(target).css({
315
- "background-color" : "#F7F7F7",
316
- "height" : "auto",
317
- "padding-top" : p,
318
- "padding-bottom" : p,
319
- "color" : "#000",
320
- "text-align" : "center"
321
- });
322
- if (response == -21) {
323
- jQuery(target).html(gadwp_item_data.i18n[12] + ' (' + response + ')');
324
- } else {
325
- jQuery(target).html(gadwp_item_data.i18n[13] + ' (' + response + ')');
326
- }
327
- this.checknpcounter(n);
328
- },
329
-
330
- render : function(period, query) {
331
- var from, to;
332
- jQuery('#gadwp-status' + slug).html('');
333
- switch (period) {
334
- case 'today' :
335
- from = 'today';
336
- to = 'today';
337
- break;
338
- case 'yesterday' :
339
- from = 'yesterday';
340
- to = 'yesterday';
341
- break;
342
- case '7daysAgo' :
343
- from = '7daysAgo';
344
- to = 'yesterday';
345
- break;
346
- case '14daysAgo' :
347
- from = '14daysAgo';
348
- to = 'yesterday';
349
- break;
350
- case '90daysAgo' :
351
- from = '90daysAgo';
352
- to = 'yesterday';
353
- break;
354
- default :
355
- from = '30daysAgo';
356
- to = 'yesterday';
357
- break;
358
- }
359
-
360
- var data = {
361
- action : 'gadwp_get_ItemReports',
362
- gadwp_security_item_reports : gadwp_item_data.security,
363
- from : from,
364
- to : to,
365
- filter : item_id
366
- }
367
-
368
- if (jQuery.inArray(query, ['referrers', 'contentpages', 'searches']) > -1) {
369
- jQuery('#gadwp-reports' + slug).html('<div id="gadwp-trafficchannels' + slug + '"></div>')
370
- jQuery('#gadwp-reports' + slug).append('<div id="gadwp-prs' + slug + '"></div>');
371
- data.query = 'trafficchannels';
372
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
373
- if (!jQuery.isNumeric(response)) {
374
- if (jQuery.isArray(response)) {
375
- reports.trafficchannels = response;
376
- google.setOnLoadCallback(reports.drawtrafficchannels(reports.trafficchannels));
377
- reports.checknpcounter(1);
378
- } else {
379
- reports.throwDebug(response);
380
- reports.checknpcounter(1);
381
- }
382
- } else {
383
- reports.throwError('#gadwp-trafficchannels' + slug, response, 1, "125px");
384
- }
385
- });
386
- data.query = query;
387
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
388
- if (!jQuery.isNumeric(response)) {
389
- if (jQuery.isArray(response)) {
390
- reports.prs = response;
391
- google.setOnLoadCallback(reports.drawprs(reports.prs));
392
- reports.checknpcounter(1);
393
- } else {
394
- reports.throwDebug(response);
395
- reports.checknpcounter(1);
396
- }
397
- } else {
398
- reports.throwError('#gadwp-prs' + slug, response, 1, "125px");
399
- }
400
- });
401
- } else if (query == 'trafficdetails') {
402
- jQuery('#gadwp-reports' + slug).html('<div id="gadwp-trafficchannels' + slug + '"></div>')
403
- jQuery('#gadwp-reports' + slug).append('<div class="gadwp-floatwraper"><div id="gadwp-trafficmediums' + slug + '"></div><div id="gadwp-traffictype' + slug + '"></div></div>');
404
- jQuery('#gadwp-reports' + slug).append('<div class="gadwp-floatwraper"><div id="gadwp-trafficorganic' + slug + '"></div><div id="gadwp-socialnetworks' + slug + '"></div></div>');
405
- data.query = 'trafficchannels';
406
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
407
- if (!jQuery.isNumeric(response)) {
408
- if (jQuery.isArray(response)) {
409
- reports.trafficchannels = response;
410
- google.setOnLoadCallback(reports.drawtrafficchannels(reports.trafficchannels));
411
- reports.checknpcounter(4);
412
- } else {
413
- reports.throwDebug(response);
414
- reports.checknpcounter(4);
415
- }
416
- } else {
417
- reports.throwError('#gadwp-trafficchannels' + slug, response, 4, "125px");
418
- }
419
- });
420
- data.query = 'medium';
421
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
422
- if (!jQuery.isNumeric(response)) {
423
- if (jQuery.isArray(response)) {
424
- reports.trafficmediums = response;
425
- google.setOnLoadCallback(reports.drawtrafficmediums(reports.trafficmediums));
426
- reports.checknpcounter(4);
427
- } else {
428
- reports.throwDebug(response);
429
- reports.checknpcounter(4);
430
- }
431
- } else {
432
- reports.throwError('#gadwp-trafficmediums' + slug, response, 4, "80px");
433
- }
434
- });
435
- data.query = 'visitorType';
436
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
437
- if (!jQuery.isNumeric(response)) {
438
- if (jQuery.isArray(response)) {
439
- reports.traffictype = response;
440
- google.setOnLoadCallback(reports.drawtraffictype(reports.traffictype));
441
- reports.checknpcounter(4);
442
- } else {
443
- reports.throwDebug(response);
444
- reports.checknpcounter(4);
445
- }
446
- } else {
447
- reports.throwError('#gadwp-traffictype' + slug, response, 4, "80px");
448
- }
449
- });
450
- data.query = 'source';
451
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
452
- if (!jQuery.isNumeric(response)) {
453
- if (jQuery.isArray(response)) {
454
- reports.trafficorganic = response;
455
- google.setOnLoadCallback(reports.drawtrafficorganic(reports.trafficorganic));
456
- reports.checknpcounter(4);
457
- } else {
458
- reports.throwDebug(response);
459
- reports.checknpcounter(4);
460
- }
461
- } else {
462
- reports.throwError('#gadwp-trafficorganic' + slug, response, 4, "80px");
463
- }
464
- });
465
- data.query = 'socialNetwork';
466
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
467
- if (!jQuery.isNumeric(response)) {
468
- if (jQuery.isArray(response)) {
469
- reports.socialnetworks = response;
470
- google.setOnLoadCallback(reports.drawsocialnetworks(reports.socialnetworks));
471
- reports.checknpcounter(4);
472
- } else {
473
- reports.throwDebug(response);
474
- reports.checknpcounter(4);
475
- }
476
- } else {
477
- reports.throwError('#gadwp-socialnetworks' + slug, response, 4, "80px");
478
- }
479
- });
480
- } else if (query == 'locations') {
481
- jQuery('#gadwp-reports' + slug).html('<div id="gadwp-map' + slug + '"></div>')
482
- jQuery('#gadwp-reports' + slug).append('<div id="gadwp-locations' + slug + '"></div>');
483
- data.query = query;
484
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
485
- if (!jQuery.isNumeric(response)) {
486
- if (jQuery.isArray(response)) {
487
- reports.locations = response;
488
- google.setOnLoadCallback(reports.drawmaplocations(reports.locations));
489
- reports.checknpcounter(1);
490
- google.setOnLoadCallback(reports.drawlocations(reports.locations));
491
- reports.checknpcounter(1);
492
- } else {
493
- reports.throwDebug(response);
494
- reports.checknpcounter(1);
495
- }
496
- } else {
497
- reports.throwError('#gadwp-map' + slug, response, 1, "125px");
498
- reports.throwError('#gadwp-locations' + slug, response, 1, "125px");
499
- }
500
- });
501
- } else {
502
- jQuery('#gadwp-reports' + slug).html('<div id="gadwp-mainchart' + slug + '"></div>')
503
- jQuery('#gadwp-reports' + slug).append('<div id="gadwp-bottomstats' + slug + '" class="gadwp-wrapper"><div class="inside"><div class="small-box"><h3>' + gadwp_item_data.i18n[5] + '</h3><p id="gdsessions' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[6] + '</h3><p id="gdusers' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[7] + '</h3><p id="gdpageviews' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[8] + '</h3><p id="gdbouncerate' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[9] + '</h3><p id="gdorganicsearch' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[10] + '</h3><p id="gdpagespervisit' + slug + '">&nbsp;</p></div></div></div>');
504
-
505
- data.query = query;
506
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
507
- if (!jQuery.isNumeric(response)) {
508
- if (jQuery.isArray(response)) {
509
- reports.mainchart = response;
510
- google.setOnLoadCallback(reports.drawmainchart(reports.mainchart));
511
- reports.checknpcounter(1);
512
- } else {
513
- reports.throwDebug(response);
514
- reports.checknpcounter(1);
515
- }
516
- } else {
517
- reports.throwError('#gadwp-mainchart' + slug, response, 1, "125px");
518
- }
519
- });
520
-
521
- data.query = 'bottomstats';
522
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
523
-
524
- if (!jQuery.isNumeric(response)) {
525
- if (jQuery.isArray(response)) {
526
- reports.bottomstats = response;
527
- google.setOnLoadCallback(reports.drawbottomstats(reports.bottomstats));
528
- reports.checknpcounter(1);
529
- } else {
530
- reports.throwDebug(response);
531
- reports.checknpcounter(1);
532
- }
533
- } else {
534
- reports.throwError('#gadwp-bottomstats' + slug, response, response, 1, "40px");
535
- }
536
- });
537
-
538
- }
539
-
540
- },
541
-
542
- refresh : function() {
543
- if (jQuery('#gadwp-bottomstats' + slug).length > 0){
544
- this.drawbottomstats(this.bottomstats);
545
- }
546
- if (jQuery('#gadwp-mainchart' + slug).length > 0 && jQuery.isArray(this.mainchart)){
547
- this.drawmainchart(this.mainchart);
548
- }
549
- if (jQuery('#gadwp-map' + slug).length > 0 && jQuery.isArray(this.locations)){
550
- this.drawmaplocations(this.locations);
551
- }
552
- if (jQuery('#gadwp-locations' + slug).length > 0 && jQuery.isArray(this.locations)){
553
- this.drawlocations(this.locations);
554
- }
555
- if (jQuery('#gadwp-socialnetworks' + slug).length > 0 && jQuery.isArray(this.socialnetworks)){
556
- this.drawsocialnetworks(this.socialnetworks);
557
- }
558
- if (jQuery('#gadwp-trafficorganic' + slug).length > 0 && jQuery.isArray(this.trafficorganic)){
559
- this.drawtrafficorganic(this.trafficorganic);
560
- }
561
- if (jQuery('#gadwp-traffictype' + slug).length > 0 && jQuery.isArray(this.traffictype)){
562
- this.drawtraffictype(this.traffictype);
563
- }
564
- if (jQuery('#gadwp-trafficmediums' + slug).length > 0 && jQuery.isArray(this.trafficmediums)){
565
- this.drawtrafficmediums(this.trafficmediums);
566
- }
567
- if (jQuery('#gadwp-trafficchannels' + slug).length > 0 && jQuery.isArray(this.trafficchannels)){
568
- this.drawtrafficchannels(this.trafficchannels);
569
- }
570
- if (jQuery('#gadwp-prs' + slug).length > 0 && jQuery.isArray(this.prs)){
571
- this.drawprs(this.prs);
572
- }
573
- },
574
-
575
- init : function() {
576
-
577
- if (jQuery("#gadwp-reports" + slug).html().length) { // only when report is empty
578
- return;
579
- }
580
-
581
- try {
582
- NProgress.configure({
583
- parent : "#gadwp-progressbar" + slug, showSpinner : false
584
- });
585
- NProgress.start();
586
- } catch (e) {
587
- this.alertMessage(gadwp_item_data.i18n[0]);
588
- }
589
-
590
- this.render(jQuery('#gadwp-sel-period' + slug).val(), jQuery('#gadwp-sel-report' + slug).val());
591
-
592
- jQuery(window).resize(function() {
593
- reports.refresh();
594
- });
595
- }
596
- }
597
-
598
- template.init();
599
-
600
- reports.init();
601
-
602
- jQuery('#gadwp-sel-period' + slug).change(function() {
603
- jQuery('#gadwp-reports' + slug).html('');
604
- reports.init();
605
- });
606
-
607
- jQuery('#gadwp-sel-report' + slug).change(function() {
608
- jQuery('#gadwp-reports' + slug).html('');
609
- reports.init();
610
- });
611
-
612
- return this.dialog({
613
- width : 'auto',
614
- maxWidth : 510,
615
- height : 'auto',
616
- modal : true,
617
- fluid : true,
618
- dialogClass : 'gadwp wp-dialog',
619
- resizable : false,
620
- title : jQuery('#gadwp'+slug).attr( "title" ),
621
- position : {
622
- my : "top",
623
- at : "top+100",
624
- of : window
625
- }
626
- });
627
-
628
- }
629
- });
1
  "use strict";
2
 
3
+ google.load( "visualization", "1", {
4
+ packages : [ "corechart", "table", "orgchart", "geochart" ]
5
+ } );
6
+
7
+ jQuery( document ).ready(
8
+
9
+ function () {
10
+ jQuery( 'a[id^="gadwp-"]' ).click( function ( e ) {
11
+
12
+ var item_id = getID( this );
13
+ var slug = "-" + item_id;
14
+
15
+ if ( !jQuery( "#gadwp-window" + slug ).length > 0 ) {
16
+ jQuery( "body" ).append( '<div id="gadwp-window' + slug + '"></div>' );
17
+ }
18
+ jQuery( '#gadwp-window' + slug ).gadwpItemReport( slug, item_id );
19
+ } );
20
+
21
+ function getID ( item ) {
22
+ if ( typeof item.id == "undefined" ) {
23
+ return 0
24
+ }
25
+ if ( item.id.split( '-' )[ 1 ] == "undefined" ) {
26
+ return 0;
27
+ } else {
28
+ return item.id.split( '-' )[ 1 ];
29
+ }
30
+ }
31
+
32
+ // on window resize
33
+ jQuery( window ).resize( function () {
34
+ fluidDialog();
35
+ } );
36
+
37
+ // dialog width larger than viewport
38
+ jQuery( document ).on( "dialogopen", ".ui-dialog", function ( event, ui ) {
39
+ fluidDialog();
40
+ } );
41
+
42
+ function fluidDialog () {
43
+ var visible = jQuery( ".ui-dialog:visible" );
44
+ // on each visible dialog
45
+ visible.each( function () {
46
+ var $this = jQuery( this );
47
+ var dialog = $this.find( ".ui-dialog-content" ).data( "ui-dialog" );
48
+ // on each fluid dialog
49
+ if ( dialog.options.fluid ) {
50
+ var wWidth = jQuery( window ).width();
51
+ // window width vs dialog width
52
+ if ( wWidth < ( parseInt( dialog.options.maxWidth ) + 50 ) ) {
53
+ // don't fill the entire screen
54
+ $this.css( "max-width", "90%" );
55
+ } else {
56
+ // maxWidth bug fix
57
+ $this.css( "max-width", dialog.options.maxWidth + "px" );
58
+ }
59
+ // change dialog position
60
+ dialog.option( "position", dialog.options.position );
61
+ }
62
+ } );
63
+
64
+ }
65
+ } );
66
+
67
+ jQuery.fn.extend( {
68
+ gadwpItemReport : function ( slug, item_id ) {
69
+
70
+ var template = {
71
+
72
+ data : '<div id="gadwp-container' + slug + '"><select id="gadwp-sel-period' + slug + '"></select> <select id="gadwp-sel-report' + slug + '"></select><div id="gadwp-progressbar' + slug + '"></div><div id="gadwp-status' + slug + '"></div><div id="gadwp-reports' + slug + '"></div><div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;margin-top:10px;">' + gadwp_item_data.i18n[ 14 ] + ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_report&utm_medium=link&utm_content=back_report&utm_campaign=gadwp" rel="nofollow" style="text-decoration:none;font-size:1em;">GADWP</a>&nbsp;</div></div>',
73
+
74
+ addOptions : function ( id, list ) {
75
+
76
+ var output = [];
77
+ jQuery.each( list, function ( key, value ) {
78
+ if ( key == '30daysAgo' || key == 'sessions' ) {
79
+ output.push( '<option value="' + key + '" selected="selected">' + value + '</option>' );
80
+ } else {
81
+ output.push( '<option value="' + key + '">' + value + '</option>' );
82
+ }
83
+ } );
84
+ jQuery( id ).html( output.join( '' ) );
85
+ },
86
+
87
+ init : function () {
88
+ if ( jQuery( '#gadwp-window' + slug ).html().length ) { // add main template once
89
+ return;
90
+ }
91
+
92
+ jQuery( '#gadwp-window' + slug ).append( this.data );
93
+
94
+ this.addOptions( '#gadwp-sel-period' + slug, gadwp_item_data.dateList );
95
+ this.addOptions( '#gadwp-sel-report' + slug, gadwp_item_data.reportList );
96
+
97
+ }
98
+ }
99
+
100
+ var reports = {
101
+
102
+ npcounter : 0,
103
+ prs : '',
104
+ trafficchannels : '',
105
+ trafficmediums : '',
106
+ traffictype : '',
107
+ trafficorganic : '',
108
+ socialnetworks : '',
109
+ locations : '',
110
+ mainchart : '',
111
+ bottomstats : '',
112
+
113
+ alertMessage : function ( msg ) {
114
+ jQuery( "#gadwp-status" + slug ).css( {
115
+ "margin-top" : "3px",
116
+ "padding-left" : "5px",
117
+ "height" : "auto",
118
+ "color" : "#000",
119
+ "border-left" : "5px solid red"
120
+ } );
121
+ jQuery( "#gadwp-status" + slug ).html( msg );
122
+ },
123
+
124
+ drawprs : function ( gadwp_prs ) {
125
+ var data = google.visualization.arrayToDataTable( gadwp_prs );
126
+ var options = {
127
+ page : 'enable',
128
+ pageSize : 10,
129
+ width : '100%',
130
+ allowHtml : true
131
+ };
132
+
133
+ var chart = new google.visualization.Table( document.getElementById( 'gadwp-prs' + slug ) );
134
+ chart.draw( data, options );
135
+ },
136
+
137
+ drawtrafficchannels : function ( gadwp_trafficchannels ) {
138
+ var data = google.visualization.arrayToDataTable( gadwp_trafficchannels );
139
+ var options = {
140
+ allowCollapse : true,
141
+ allowHtml : true,
142
+ height: '100%'
143
+ };
144
+
145
+ var chart = new google.visualization.OrgChart( document.getElementById( 'gadwp-trafficchannels' + slug ) );
146
+ chart.draw( data, options );
147
+ },
148
+
149
+ drawtrafficmediums : function ( gadwp_trafficmediums ) {
150
+ var data = google.visualization.arrayToDataTable( gadwp_trafficmediums );
151
+ var options = {
152
+ is3D : false,
153
+ tooltipText : 'percentage',
154
+ legend : 'none',
155
+ chartArea : {
156
+ width : '99%',
157
+ height : '80%'
158
+ },
159
+ title : gadwp_item_data.i18n[ 1 ],
160
+ colors : gadwp_item_data.colorVariations
161
+ };
162
+
163
+ var chart = new google.visualization.PieChart( document.getElementById( 'gadwp-trafficmediums' + slug ) );
164
+ chart.draw( data, options );
165
+ },
166
+
167
+ drawtraffictype : function ( gadwp_traffictype ) {
168
+ var data = google.visualization.arrayToDataTable( gadwp_traffictype );
169
+ var options = {
170
+ is3D : false,
171
+ tooltipText : 'percentage',
172
+ legend : 'none',
173
+ chartArea : {
174
+ width : '99%',
175
+ height : '80%'
176
+ },
177
+ title : gadwp_item_data.i18n[ 2 ],
178
+ colors : gadwp_item_data.colorVariations
179
+ };
180
+
181
+ var chart = new google.visualization.PieChart( document.getElementById( 'gadwp-traffictype' + slug ) );
182
+ chart.draw( data, options );
183
+ },
184
+
185
+ drawsocialnetworks : function ( gadwp_socialnetworks ) {
186
+ var data = google.visualization.arrayToDataTable( gadwp_socialnetworks );
187
+ var options = {
188
+ is3D : false,
189
+ tooltipText : 'percentage',
190
+ legend : 'none',
191
+ chartArea : {
192
+ width : '99%',
193
+ height : '80%'
194
+ },
195
+ title : gadwp_item_data.i18n[ 3 ],
196
+ colors : gadwp_item_data.colorVariations
197
+ };
198
+
199
+ var chart = new google.visualization.PieChart( document.getElementById( 'gadwp-socialnetworks' + slug ) );
200
+ chart.draw( data, options );
201
+ },
202
+
203
+ drawtrafficorganic : function ( gadwp_trafficorganic ) {
204
+ var data = google.visualization.arrayToDataTable( gadwp_trafficorganic );
205
+ var options = {
206
+ is3D : false,
207
+ tooltipText : 'percentage',
208
+ legend : 'none',
209
+ chartArea : {
210
+ width : '99%',
211
+ height : '80%'
212
+ },
213
+ title : gadwp_item_data.i18n[ 4 ],
214
+ colors : gadwp_item_data.colorVariations
215
+ };
216
+
217
+ var chart = new google.visualization.PieChart( document.getElementById( 'gadwp-trafficorganic' + slug ) );
218
+ chart.draw( data, options );
219
+ },
220
+
221
+ drawlocations : function ( gadwp_locations ) {
222
+ var data = google.visualization.arrayToDataTable( gadwp_locations );
223
+ var options = {
224
+ page : 'enable',
225
+ pageSize : 10,
226
+ width : '100%'
227
+ };
228
+
229
+ var chart = new google.visualization.Table( document.getElementById( 'gadwp-locations' + slug ) );
230
+ chart.draw( data, options );
231
+ },
232
+
233
+ drawmaplocations : function ( gadwp_locations ) {
234
+
235
+ var data = google.visualization.arrayToDataTable( gadwp_locations );
236
+
237
+ var options = {
238
+ chartArea : {
239
+ width : '99%',
240
+ height : '90%'
241
+ },
242
+ colors : [ gadwp_item_data.colorVariations[ 5 ], gadwp_item_data.colorVariations[ 4 ] ],
243
+ }
244
+
245
+ if ( gadwp_item_data.region ) {
246
+ options.region = gadwp_item_data.region;
247
+ options.displayMode = 'markers';
248
+ options.datalessRegionColor = 'EFEFEF';
249
+ }
250
+
251
+ var chart = new google.visualization.GeoChart( document.getElementById( 'gadwp-map' + slug ) );
252
+ chart.draw( data, options );
253
+ },
254
+
255
+ drawmainchart : function ( gadwp_mainchart ) {
256
+
257
+ var data = google.visualization.arrayToDataTable( gadwp_mainchart );
258
+
259
+ var options = {
260
+ legend : {
261
+ position : 'none'
262
+ },
263
+ pointSize : 3,
264
+ colors : [ gadwp_item_data.colorVariations[ 0 ], gadwp_item_data.colorVariations[ 4 ] ],
265
+ chartArea : {
266
+ width : '99%',
267
+ height : '90%'
268
+ },
269
+ vAxis : {
270
+ textPosition : "in",
271
+ minValue : 0
272
+ },
273
+ hAxis : {
274
+ textPosition : 'none'
275
+ }
276
+ };
277
+ var chart = new google.visualization.AreaChart( document.getElementById( 'gadwp-mainchart' + slug ) );
278
+ chart.draw( data, options );
279
+ },
280
+
281
+ drawbottomstats : function ( gadwp_bottomstats ) {
282
+ jQuery( "#gdsessions" + slug ).text( gadwp_bottomstats[ 0 ] );
283
+ jQuery( "#gdusers" + slug ).text( gadwp_bottomstats[ 1 ] );
284
+ jQuery( "#gdpageviews" + slug ).text( gadwp_bottomstats[ 2 ] );
285
+ jQuery( "#gdbouncerate" + slug ).text( parseFloat( gadwp_bottomstats[ 3 ] ).toFixed( 2 ) + "%" );
286
+ jQuery( "#gdorganicsearch" + slug ).text( gadwp_bottomstats[ 4 ] );
287
+ jQuery( "#gdpagespervisit" + slug ).text( parseFloat( gadwp_bottomstats[ 5 ] ).toFixed( 2 ) );
288
+ },
289
+
290
+ throwDebug : function ( response ) {
291
+ jQuery( "#gadwp-status" + slug ).css( {
292
+ "margin-top" : "3px",
293
+ "padding-left" : "5px",
294
+ "height" : "auto",
295
+ "color" : "#000",
296
+ "border-left" : "5px solid red"
297
+ } );
298
+ jQuery( "#gadwp-status" + slug ).html( gadwp_item_data.i18n[ 11 ] );
299
+ console.log( "\n********************* GADWP Log ********************* \n\n" + response );
300
+ },
301
+
302
+ throwError : function ( target, response, p ) {
303
+ jQuery( target ).css( {
304
+ "background-color" : "#F7F7F7",
305
+ "height" : "auto",
306
+ "padding-top" : p,
307
+ "padding-bottom" : p,
308
+ "color" : "#000",
309
+ "text-align" : "center"
310
+ } );
311
+ if ( response == -21 ) {
312
+ jQuery( target ).html( gadwp_item_data.i18n[ 12 ] + ' (' + response + ')' );
313
+ } else {
314
+ jQuery( target ).html( gadwp_item_data.i18n[ 13 ] + ' (' + response + ')' );
315
+ }
316
+ },
317
+
318
+ render : function ( period, query ) {
319
+ var from, to;
320
+ jQuery( '#gadwp-status' + slug ).html( '' );
321
+ switch ( period ) {
322
+ case 'today':
323
+ from = 'today';
324
+ to = 'today';
325
+ break;
326
+ case 'yesterday':
327
+ from = 'yesterday';
328
+ to = 'yesterday';
329
+ break;
330
+ case '7daysAgo':
331
+ from = '7daysAgo';
332
+ to = 'yesterday';
333
+ break;
334
+ case '14daysAgo':
335
+ from = '14daysAgo';
336
+ to = 'yesterday';
337
+ break;
338
+ case '90daysAgo':
339
+ from = '90daysAgo';
340
+ to = 'yesterday';
341
+ break;
342
+ default:
343
+ from = '30daysAgo';
344
+ to = 'yesterday';
345
+ break;
346
+ }
347
+
348
+ var data = {
349
+ action : 'gadwp_backend_item_reports',
350
+ gadwp_security_backend_item_reports : gadwp_item_data.security,
351
+ from : from,
352
+ to : to,
353
+ filter : item_id
354
+ }
355
+
356
+ if ( jQuery.inArray( query, [ 'referrers', 'contentpages', 'searches' ] ) > -1 ) {
357
+
358
+ jQuery( '#gadwp-reports' + slug ).html( '<div id="gadwp-trafficchannels' + slug + '"></div>' )
359
+ jQuery( '#gadwp-reports' + slug ).append( '<div id="gadwp-prs' + slug + '"></div>' );
360
+
361
+ data.query = 'trafficchannels,' + query;
362
+
363
+ jQuery.post( gadwp_item_data.ajaxurl, data, function ( response ) {
364
+ if ( jQuery.isArray( response ) ) {
365
+ if ( !jQuery.isNumeric( response[ 0 ] ) ) {
366
+ if ( jQuery.isArray( response[ 0 ] ) ) {
367
+ reports.trafficchannels = response[ 0 ];
368
+ google.setOnLoadCallback( reports.drawtrafficchannels( reports.trafficchannels ) );
369
+ } else {
370
+ reports.throwDebug( response[ 0 ] );
371
+ }
372
+ } else {
373
+ reports.throwError( '#gadwp-trafficchannels' + slug, response[ 0 ], "125px" );
374
+ }
375
+
376
+ if ( !jQuery.isNumeric( response[ 1 ] ) ) {
377
+ if ( jQuery.isArray( response[ 1 ] ) ) {
378
+ reports.prs = response[ 1 ];
379
+ google.setOnLoadCallback( reports.drawprs( reports.prs ) );
380
+ } else {
381
+ reports.throwDebug( response[ 1 ] );
382
+ }
383
+ } else {
384
+ reports.throwError( '#gadwp-prs' + slug, response[ 1 ], "125px" );
385
+ }
386
+ } else {
387
+ reports.throwDebug( response );
388
+ }
389
+ NProgress.done();
390
+ } );
391
+
392
+ } else if ( query == 'trafficdetails' ) {
393
+
394
+ jQuery( '#gadwp-reports' + slug ).html( '<div id="gadwp-trafficchannels' + slug + '"></div>' )
395
+ jQuery( '#gadwp-reports' + slug ).append( '<div class="gadwp-floatwraper"><div id="gadwp-trafficmediums' + slug + '"></div><div id="gadwp-traffictype' + slug + '"></div></div>' );
396
+ jQuery( '#gadwp-reports' + slug ).append( '<div class="gadwp-floatwraper"><div id="gadwp-trafficorganic' + slug + '"></div><div id="gadwp-socialnetworks' + slug + '"></div></div>' );
397
+
398
+ data.query = 'trafficchannels,medium,visitorType,source,socialNetwork';
399
+
400
+ jQuery.post( gadwp_item_data.ajaxurl, data, function ( response ) {
401
+ if ( jQuery.isArray( response ) ) {
402
+ if ( !jQuery.isNumeric( response[ 0 ] ) ) {
403
+ if ( jQuery.isArray( response[ 0 ] ) ) {
404
+ reports.trafficchannels = response[ 0 ];
405
+ google.setOnLoadCallback( reports.drawtrafficchannels( reports.trafficchannels ) );
406
+ } else {
407
+ reports.throwDebug( response[ 0 ] );
408
+ }
409
+ } else {
410
+ reports.throwError( '#gadwp-trafficchannels' + slug, response[ 0 ], "125px" );
411
+ }
412
+
413
+ if ( !jQuery.isNumeric( response[ 1 ] ) ) {
414
+ if ( jQuery.isArray( response[ 1 ] ) ) {
415
+ reports.trafficmediums = response[ 1 ];
416
+ google.setOnLoadCallback( reports.drawtrafficmediums( reports.trafficmediums ) );
417
+ } else {
418
+ reports.throwDebug( response[ 1 ] );
419
+ }
420
+ } else {
421
+ reports.throwError( '#gadwp-trafficmediums' + slug, response[ 1 ], "80px" );
422
+ }
423
+
424
+ if ( !jQuery.isNumeric( response[ 2 ] ) ) {
425
+ if ( jQuery.isArray( response[ 2 ] ) ) {
426
+ reports.traffictype = response[ 2 ];
427
+ google.setOnLoadCallback( reports.drawtraffictype( reports.traffictype ) );
428
+ } else {
429
+ reports.throwDebug( response[ 2 ] );
430
+ }
431
+ } else {
432
+ reports.throwError( '#gadwp-traffictype' + slug, response[ 2 ], "80px" );
433
+ }
434
+
435
+ if ( !jQuery.isNumeric( response[ 3 ] ) ) {
436
+ if ( jQuery.isArray( response[ 3 ] ) ) {
437
+ reports.trafficorganic = response[ 3 ];
438
+ google.setOnLoadCallback( reports.drawtrafficorganic( reports.trafficorganic ) );
439
+ } else {
440
+ reports.throwDebug( response[ 3 ] );
441
+ }
442
+ } else {
443
+ reports.throwError( '#gadwp-trafficorganic' + slug, response[ 3 ], "80px" );
444
+ }
445
+
446
+ if ( !jQuery.isNumeric( response[ 4 ] ) ) {
447
+ if ( jQuery.isArray( response[ 4 ] ) ) {
448
+ reports.socialnetworks = response[ 4 ];
449
+ google.setOnLoadCallback( reports.drawsocialnetworks( reports.socialnetworks ) );
450
+ } else {
451
+ reports.throwDebug( response[ 4 ] );
452
+ }
453
+ } else {
454
+ reports.throwError( '#gadwp-socialnetworks' + slug, response[ 4 ], "80px" );
455
+ }
456
+ } else {
457
+ reports.throwDebug( response );
458
+ }
459
+ NProgress.done();
460
+ } );
461
+
462
+ } else if ( query == 'locations' ) {
463
+
464
+ jQuery( '#gadwp-reports' + slug ).html( '<div id="gadwp-map' + slug + '"></div>' )
465
+ jQuery( '#gadwp-reports' + slug ).append( '<div id="gadwp-locations' + slug + '"></div>' );
466
+
467
+ data.query = query;
468
+
469
+ jQuery.post( gadwp_item_data.ajaxurl, data, function ( response ) {
470
+ if ( jQuery.isArray( response ) ) {
471
+ if ( !jQuery.isNumeric( response[ 0 ] ) ) {
472
+ if ( jQuery.isArray( response[ 0 ] ) ) {
473
+ reports.locations = response[ 0 ];
474
+ google.setOnLoadCallback( reports.drawmaplocations( reports.locations ) );
475
+ google.setOnLoadCallback( reports.drawlocations( reports.locations ) );
476
+ } else {
477
+ reports.throwDebug( response[ 0 ] );
478
+ }
479
+ } else {
480
+ reports.throwError( '#gadwp-map' + slug, response[ 0 ], "125px" );
481
+ reports.throwError( '#gadwp-locations' + slug, response[ 0 ], "125px" );
482
+ }
483
+ } else {
484
+ reports.throwDebug( response );
485
+ }
486
+ NProgress.done();
487
+ } );
488
+
489
+ } else {
490
+
491
+ jQuery( '#gadwp-reports' + slug ).html( '<div id="gadwp-mainchart' + slug + '"></div>' )
492
+ jQuery( '#gadwp-reports' + slug ).append( '<div id="gadwp-bottomstats' + slug + '" class="gadwp-wrapper"><div class="inside"><div class="small-box"><h3>' + gadwp_item_data.i18n[ 5 ] + '</h3><p id="gdsessions' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 6 ] + '</h3><p id="gdusers' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 7 ] + '</h3><p id="gdpageviews' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 8 ] + '</h3><p id="gdbouncerate' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 9 ] + '</h3><p id="gdorganicsearch' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 10 ] + '</h3><p id="gdpagespervisit' + slug + '">&nbsp;</p></div></div></div>' );
493
+
494
+ data.query = query + ',bottomstats';
495
+
496
+ jQuery.post( gadwp_item_data.ajaxurl, data, function ( response ) {
497
+ if ( jQuery.isArray( response ) ) {
498
+ if ( !jQuery.isNumeric( response[ 0 ] ) ) {
499
+ if ( jQuery.isArray( response[ 0 ] ) ) {
500
+ reports.mainchart = response[ 0 ];
501
+ google.setOnLoadCallback( reports.drawmainchart( reports.mainchart ) );
502
+ } else {
503
+ reports.throwDebug( response[ 0 ] );
504
+ }
505
+ } else {
506
+ reports.throwError( '#gadwp-mainchart' + slug, response[ 0 ], "125px" );
507
+ }
508
+ if ( !jQuery.isNumeric( response[ 1 ] ) ) {
509
+ if ( jQuery.isArray( response[ 1 ] ) ) {
510
+ reports.bottomstats = response[ 1 ];
511
+ google.setOnLoadCallback( reports.drawbottomstats( reports.bottomstats ) );
512
+ } else {
513
+ reports.throwDebug( response[ 1 ] );
514
+ }
515
+ } else {
516
+ reports.throwError( '#gadwp-bottomstats' + slug, response[ 1 ], "40px" );
517
+ }
518
+ } else {
519
+ reports.throwDebug( response );
520
+ }
521
+ NProgress.done();
522
+ } );
523
+
524
+ }
525
+
526
+ },
527
+
528
+ refresh : function () {
529
+ if ( jQuery( '#gadwp-bottomstats' + slug ).length > 0 ) {
530
+ this.drawbottomstats( this.bottomstats );
531
+ }
532
+ if ( jQuery( '#gadwp-mainchart' + slug ).length > 0 && jQuery.isArray( this.mainchart ) ) {
533
+ this.drawmainchart( this.mainchart );
534
+ }
535
+ if ( jQuery( '#gadwp-map' + slug ).length > 0 && jQuery.isArray( this.locations ) ) {
536
+ this.drawmaplocations( this.locations );
537
+ }
538
+ if ( jQuery( '#gadwp-locations' + slug ).length > 0 && jQuery.isArray( this.locations ) ) {
539
+ this.drawlocations( this.locations );
540
+ }
541
+ if ( jQuery( '#gadwp-socialnetworks' + slug ).length > 0 && jQuery.isArray( this.socialnetworks ) ) {
542
+ this.drawsocialnetworks( this.socialnetworks );
543
+ }
544
+ if ( jQuery( '#gadwp-trafficorganic' + slug ).length > 0 && jQuery.isArray( this.trafficorganic ) ) {
545
+ this.drawtrafficorganic( this.trafficorganic );
546
+ }
547
+ if ( jQuery( '#gadwp-traffictype' + slug ).length > 0 && jQuery.isArray( this.traffictype ) ) {
548
+ this.drawtraffictype( this.traffictype );
549
+ }
550
+ if ( jQuery( '#gadwp-trafficmediums' + slug ).length > 0 && jQuery.isArray( this.trafficmediums ) ) {
551
+ this.drawtrafficmediums( this.trafficmediums );
552
+ }
553
+ if ( jQuery( '#gadwp-trafficchannels' + slug ).length > 0 && jQuery.isArray( this.trafficchannels ) ) {
554
+ this.drawtrafficchannels( this.trafficchannels );
555
+ }
556
+ if ( jQuery( '#gadwp-prs' + slug ).length > 0 && jQuery.isArray( this.prs ) ) {
557
+ this.drawprs( this.prs );
558
+ }
559
+ },
560
+
561
+ init : function () {
562
+
563
+ if ( jQuery( "#gadwp-reports" + slug ).html().length ) { // only when report is empty
564
+ return;
565
+ }
566
+
567
+ try {
568
+ NProgress.configure( {
569
+ parent : "#gadwp-progressbar" + slug,
570
+ showSpinner : false
571
+ } );
572
+ NProgress.start();
573
+ } catch ( e ) {
574
+ this.alertMessage( gadwp_item_data.i18n[ 0 ] );
575
+ }
576
+
577
+ this.render( jQuery( '#gadwp-sel-period' + slug ).val(), jQuery( '#gadwp-sel-report' + slug ).val() );
578
+
579
+ jQuery( window ).resize( function () {
580
+ reports.refresh();
581
+ } );
582
+ }
583
+ }
584
+
585
+ template.init();
586
+
587
+ reports.init();
588
+
589
+ jQuery( '#gadwp-sel-period' + slug ).change( function () {
590
+ jQuery( '#gadwp-reports' + slug ).html( '' );
591
+ reports.init();
592
+ } );
593
+
594
+ jQuery( '#gadwp-sel-report' + slug ).change( function () {
595
+ jQuery( '#gadwp-reports' + slug ).html( '' );
596
+ reports.init();
597
+ } );
598
+
599
+ return this.dialog( {
600
+ width : 'auto',
601
+ maxWidth : 510,
602
+ height : 'auto',
603
+ modal : true,
604
+ fluid : true,
605
+ dialogClass : 'gadwp wp-dialog',
606
+ resizable : false,
607
+ title : jQuery( '#gadwp' + slug ).attr( "title" ),
608
+ position : {
609
+ my : "top",
610
+ at : "top+100",
611
+ of : window
612
+ }
613
+ } );
614
+
615
+ }
616
+ } );
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/settings.php CHANGED
@@ -8,98 +8,93 @@
8
  */
9
 
10
  // Exit if accessed directly
11
- if (! defined('ABSPATH'))
12
- exit();
13
 
14
- final class GADWP_Settings
15
- {
16
 
17
- private static function update_options($who)
18
- {
19
- $gadwp = GADWP();
20
- $network_settings = false;
21
- $options = $gadwp->config->options; // Get current options
22
- if (isset($_POST['options']['ga_dash_hidden']) && isset($_POST['options']) && (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) && $who != 'Reset') {
23
- $new_options = $_POST['options'];
24
- if ($who == 'tracking') {
25
- $options['ga_dash_anonim'] = 0;
26
- $options['ga_event_tracking'] = 0;
27
- $options['ga_enhanced_links'] = 0;
28
- $options['ga_dash_remarketing'] = 0;
29
- $options['ga_dash_adsense'] = 0;
30
- $options['ga_event_bouncerate'] = 0;
31
- $options['ga_crossdomain_tracking'] = 0;
32
- $options['ga_aff_tracking'] = 0;
33
- $options['ga_hash_tracking'] = 0;
34
- if (isset($_POST['options']['ga_tracking_code'])) {
35
- $new_options['ga_tracking_code'] = trim($new_options['ga_tracking_code'], "\t");
36
- }
37
- if (empty($new_options['ga_track_exclude'])) {
38
- $new_options['ga_track_exclude'] = array();
39
- }
40
- } else
41
- if ($who == 'backend') {
42
- $options['switch_profile'] = 0;
43
- $options['item_reports'] = 0;
44
- $options['dashboard_widget'] = 0;
45
- if (empty($new_options['ga_dash_access_back'])) {
46
- $new_options['ga_dash_access_back'][] = 'administrator';
47
- }
48
- } else
49
- if ($who == 'frontend') {
50
- $options['ga_dash_frontend_stats'] = 0;
51
- $options['ga_dash_frontend_keywords'] = 0;
52
- if (empty($new_options['ga_dash_access_front'])) {
53
- $new_options['ga_dash_access_front'][] = 'administrator';
54
- }
55
- } else
56
- if ($who == 'general') {
57
- $options['ga_dash_userapi'] = 0;
58
- if (! is_multisite()) {
59
- $options['automatic_updates_minorversion'] = 0;
60
- }
61
- } else
62
- if ($who == 'network') {
63
- $options['ga_dash_userapi'] = 0;
64
- $options['ga_dash_network'] = 0;
65
- $options['ga_dash_excludesa'] = 0;
66
- $options['automatic_updates_minorversion'] = 0;
67
- $network_settings = true;
68
- }
69
- $options = array_merge($options, $new_options);
70
- $gadwp->config->options = $options;
71
- $gadwp->config->set_plugin_options($network_settings);
72
- }
73
- return $options;
74
- }
75
 
76
- private static function navigation_tabs($tabs)
77
- {
78
- echo '<div id="icon-themes" class="icon32"><br></div>';
79
- echo '<h2 class="nav-tab-wrapper">';
80
- foreach ($tabs as $tab => $name) {
81
- echo "<a class='nav-tab' id='tab-$tab' href='#top#gadwp-$tab'>$name</a>";
82
- }
83
- echo '</h2>';
84
- }
85
 
86
- public static function frontend_settings()
87
- {
88
- $gadwp = GADWP();
89
- if (! current_user_can('manage_options')) {
90
- return;
91
- }
92
- $options = self::update_options('frontend');
93
- if (isset($_POST['options']['ga_dash_hidden'])) {
94
- $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>";
95
- if (! (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) {
96
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
97
- }
98
- }
99
- if (! $gadwp->config->options['ga_dash_tableid_jail'] || ! $gadwp->config->options['ga_dash_token']) {
100
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
101
- }
102
- ?>
103
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
104
  <div class="wrap">
105
  <?php echo "<h2>" . __( "Google Analytics Frontend Settings", 'ga-dash' ) . "</h2>"; ?><hr>
@@ -118,54 +113,45 @@ final class GADWP_Settings
118
  <td class="roles title"><label for="ga_dash_access_front"><?php _e("Show stats to:", 'ga-dash' ); ?></label></td>
119
  <td class="roles">
120
  <?php
121
- if (! isset($wp_roles)) {
122
- $wp_roles = new WP_Roles();
123
- }
124
- $i = 0;
125
- ?>
126
  <table>
127
  <tr>
128
  <?php
129
- foreach ($wp_roles->role_names as $role => $name) {
130
- if ($role != 'subscriber') {
131
- $i ++;
132
- ?>
133
  <td><label> <input type="checkbox" name="options[ga_dash_access_front][]" value="<?php echo $role; ?>" <?php if (in_array($role,$options['ga_dash_access_front']) || $role=='administrator') echo 'checked="checked"'; if ($role=='administrator') echo 'disabled="disabled"';?> /><?php echo $name; ?>
134
  </label></td>
135
  <?php
136
- }
137
- if ($i % 4 == 0) {
138
- ?>
139
  </tr>
140
  <tr>
141
  <?php
142
- }
143
- }
144
- ?>
145
-
 
 
146
  </table>
147
  </td>
148
  </tr>
149
  <tr>
150
  <td colspan="2" class="title">
151
- <div class="onoffswitch">
152
- <input type="checkbox" name="options[ga_dash_frontend_stats]" value="1" class="onoffswitch-checkbox" id="ga_dash_frontend_stats" <?php checked( $options['ga_dash_frontend_stats'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_frontend_stats">
153
  <div class="onoffswitch-inner"></div>
154
  <div class="onoffswitch-switch"></div>
155
  </label>
156
  </div>
157
- <div class="switch-desc"><?php echo " ".__("show page sessions and users in frontend (after each article)", 'ga-dash' );?></div>
158
- </td>
159
- </tr>
160
- <tr>
161
- <td colspan="2" class="title">
162
- <div class="onoffswitch">
163
- <input type="checkbox" name="options[ga_dash_frontend_keywords]" value="1" class="onoffswitch-checkbox" id="ga_dash_frontend_keywords" <?php checked( $options['ga_dash_frontend_keywords'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_frontend_keywords">
164
- <div class="onoffswitch-inner"></div>
165
- <div class="onoffswitch-switch"></div>
166
- </label>
167
- </div>
168
- <div class="switch-desc"><?php echo " ".__("show page searches (after each article)", 'ga-dash' );?></div>
169
  </td>
170
  </tr>
171
  <tr>
@@ -181,28 +167,29 @@ final class GADWP_Settings
181
 
182
 
183
 
 
 
184
  </form>
185
  <?php
186
- self::output_sidebar();
187
- }
188
 
189
- public static function backend_settings()
190
- {
191
- $gadwp = GADWP();
192
- if (! current_user_can('manage_options')) {
193
- return;
194
- }
195
- $options = self::update_options('backend');
196
- if (isset($_POST['options']['ga_dash_hidden'])) {
197
- $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>";
198
- if (! (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) {
199
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
200
- }
201
- }
202
- if (! $gadwp->config->options['ga_dash_tableid_jail'] || ! $gadwp->config->options['ga_dash_token']) {
203
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
204
- }
205
- ?>
206
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
207
  <div class="wrap">
208
  <?php echo "<h2>" . __( "Google Analytics Backend Settings", 'ga-dash' ) . "</h2>"; ?><hr>
@@ -221,39 +208,41 @@ final class GADWP_Settings
221
  <td class="roles title"><label for="ga_dash_access_back"><?php _e("Show stats to:", 'ga-dash' ); ?></label></td>
222
  <td class="roles">
223
  <?php
224
- if (! isset($wp_roles)) {
225
- $wp_roles = new WP_Roles();
226
- }
227
- $i = 0;
228
- ?>
229
  <table>
230
  <tr>
231
  <?php
232
-
233
- foreach ($wp_roles->role_names as $role => $name) {
234
- if ($role != 'subscriber') {
235
- $i ++;
236
- ?>
237
  <td><label> <input type="checkbox" name="options[ga_dash_access_back][]" value="<?php echo $role; ?>" <?php if (in_array($role,$options['ga_dash_access_back']) || $role=='administrator') echo 'checked="checked"'; if ($role=='administrator') echo 'disabled="disabled"';?> />
238
  <?php echo $name; ?>
239
  </label></td>
240
  <?php
241
- }
242
- if ($i % 4 == 0) {
243
- ?>
244
  </tr>
245
  <tr>
246
  <?php
247
- }
248
- }
249
- ?>
250
-
 
 
251
  </table>
252
  </td>
253
  </tr>
254
  <tr>
255
  <td colspan="2" class="title">
256
- <div class="onoffswitch">
257
  <input type="checkbox" name="options[switch_profile]" value="1" class="onoffswitch-checkbox" id="switch_profile" <?php checked( $options['switch_profile'], 1 ); ?>> <label class="onoffswitch-label" for="switch_profile">
258
  <div class="onoffswitch-inner"></div>
259
  <div class="onoffswitch-switch"></div>
@@ -264,8 +253,8 @@ final class GADWP_Settings
264
  </tr>
265
  <tr>
266
  <td colspan="2" class="title">
267
- <div class="onoffswitch">
268
- <input type="checkbox" name="options[item_reports]" value="1" class="onoffswitch-checkbox" id="item_reports" <?php checked( $options['item_reports'], 1 ); ?>> <label class="onoffswitch-label" for="item_reports">
269
  <div class="onoffswitch-inner"></div>
270
  <div class="onoffswitch-switch"></div>
271
  </label>
@@ -275,7 +264,7 @@ final class GADWP_Settings
275
  </tr>
276
  <tr>
277
  <td colspan="2" class="title">
278
- <div class="onoffswitch">
279
  <input type="checkbox" name="options[dashboard_widget]" value="1" class="onoffswitch-checkbox" id="dashboard_widget" <?php checked( $options['dashboard_widget'], 1 ); ?>> <label class="onoffswitch-label" for="dashboard_widget">
280
  <div class="onoffswitch-inner"></div>
281
  <div class="onoffswitch-switch"></div>
@@ -290,7 +279,7 @@ final class GADWP_Settings
290
  <tr>
291
  <td colspan="2" class="title"> <?php _e("Maximum number of pages to display on real-time tab:", 'ga-dash'); ?>
292
  <input type="number" name="options[ga_realtime_pages]" id="ga_realtime_pages" value="<?php echo (int)$options['ga_realtime_pages']; ?>" size="3">
293
- </td>
294
  </tr>
295
  <tr>
296
  <td colspan="2"><hr><?php echo "<h2>" . __( "Location Settings", 'ga-dash' ) . "</h2>"; ?></td>
@@ -299,7 +288,7 @@ final class GADWP_Settings
299
  <td colspan="2" class="title">
300
  <?php echo __("Target Geo Map to country:", 'ga-dash'); ?>
301
  <input type="text" style="text-align: center;" name="options[ga_target_geomap]" value="<?php echo esc_attr($options['ga_target_geomap']); ?>" size="3">
302
- </td>
303
  </tr>
304
  <tr>
305
  <td colspan="2"><hr></td>
@@ -311,32 +300,33 @@ final class GADWP_Settings
311
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
312
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
313
 
 
 
314
  </form>
315
  <?php
316
- self::output_sidebar();
317
- }
318
 
319
- public static function tracking_settings()
320
- {
321
- $gadwp = GADWP();
322
-
323
- if (! current_user_can('manage_options')) {
324
- return;
325
- }
326
- $options = self::update_options('tracking');
327
- if (isset($_POST['options']['ga_dash_hidden'])) {
328
- $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>";
329
- if (! (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) {
330
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
331
- }
332
- }
333
- if (! $gadwp->config->options['ga_dash_tableid_jail']) {
334
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
335
- }
336
- if (! $options['ga_dash_tracking']) {
337
- $message = "<div class='error'><p>" . __("The tracking component is disabled. You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>", 'ga-dash') . ".</p></div>";
338
- }
339
- ?>
340
  <form name="ga_dash_form" method="post" action="<?php esc_url($_SERVER['REQUEST_URI']); ?>">
341
  <div class="wrap">
342
  <?php echo "<h2>" . __( "Google Analytics Tracking Code", 'ga-dash' ) . "</h2>"; ?>
@@ -347,16 +337,16 @@ final class GADWP_Settings
347
  <div class="settings-wrapper">
348
  <div class="inside">
349
  <?php
350
- $tabs = array(
351
- 'basic' => __("Basic Settings", 'ga-dash'),
352
- 'events' => __("Events Tracking", 'ga-dash'),
353
- 'custom' => __("Custom Definitions", 'ga-dash'),
354
- 'exclude' => __("Exclude Tracking", 'ga-dash'),
355
- 'advanced' => __("Advanced Settings", 'ga-dash')
356
- );
357
- self::navigation_tabs($tabs);
358
- ?>
359
- <?php if (isset($message)) echo $message; ?>
360
  <div id="gadwp-basic">
361
  <table class="options">
362
  <tr>
@@ -390,7 +380,7 @@ final class GADWP_Settings
390
  </tr>
391
  <tr>
392
  <td colspan="2" class="title">
393
- <div class="onoffswitch">
394
  <input type="checkbox" name="options[ga_dash_anonim]" value="1" class="onoffswitch-checkbox" id="ga_dash_anonim" <?php checked( $options['ga_dash_anonim'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_anonim">
395
  <div class="onoffswitch-inner"></div>
396
  <div class="onoffswitch-switch"></div>
@@ -401,7 +391,7 @@ final class GADWP_Settings
401
  </tr>
402
  <tr>
403
  <td colspan="2" class="title">
404
- <div class="onoffswitch">
405
  <input type="checkbox" name="options[ga_dash_remarketing]" value="1" class="onoffswitch-checkbox" id="ga_dash_remarketing" <?php checked( $options['ga_dash_remarketing'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_remarketing">
406
  <div class="onoffswitch-inner"></div>
407
  <div class="onoffswitch-switch"></div>
@@ -419,7 +409,7 @@ final class GADWP_Settings
419
  </tr>
420
  <tr>
421
  <td colspan="2" class="title">
422
- <div class="onoffswitch">
423
  <input type="checkbox" name="options[ga_event_tracking]" value="1" class="onoffswitch-checkbox" id="ga_event_tracking" <?php checked( $options['ga_event_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_event_tracking">
424
  <div class="onoffswitch-inner"></div>
425
  <div class="onoffswitch-switch"></div>
@@ -434,7 +424,7 @@ final class GADWP_Settings
434
  </tr>
435
  <tr>
436
  <td colspan="2" class="title">
437
- <div class="onoffswitch">
438
  <input type="checkbox" name="options[ga_aff_tracking]" value="1" class="onoffswitch-checkbox" id="ga_aff_tracking" <?php checked( $options['ga_aff_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_aff_tracking">
439
  <div class="onoffswitch-inner"></div>
440
  <div class="onoffswitch-switch"></div>
@@ -449,7 +439,7 @@ final class GADWP_Settings
449
  </tr>
450
  <tr>
451
  <td colspan="2" class="title">
452
- <div class="onoffswitch">
453
  <input type="checkbox" name="options[ga_hash_tracking]" value="1" class="onoffswitch-checkbox" id="ga_hash_tracking" <?php checked( $options['ga_hash_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_hash_tracking">
454
  <div class="onoffswitch-inner"></div>
455
  <div class="onoffswitch-switch"></div>
@@ -510,7 +500,7 @@ final class GADWP_Settings
510
  </tr>
511
  <tr>
512
  <td colspan="2" class="title">
513
- <div class="onoffswitch">
514
  <input type="checkbox" name="options[ga_event_bouncerate]" value="1" class="onoffswitch-checkbox" id="ga_event_bouncerate" <?php checked( $options['ga_event_bouncerate'], 1 ); ?>> <label class="onoffswitch-label" for="ga_event_bouncerate">
515
  <div class="onoffswitch-inner"></div>
516
  <div class="onoffswitch-switch"></div>
@@ -521,7 +511,7 @@ final class GADWP_Settings
521
  </tr>
522
  <tr>
523
  <td colspan="2" class="title">
524
- <div class="onoffswitch">
525
  <input type="checkbox" name="options[ga_enhanced_links]" value="1" class="onoffswitch-checkbox" id="ga_enhanced_links" <?php checked( $options['ga_enhanced_links'], 1 ); ?>> <label class="onoffswitch-label" for="ga_enhanced_links">
526
  <div class="onoffswitch-inner"></div>
527
  <div class="onoffswitch-switch"></div>
@@ -532,7 +522,7 @@ final class GADWP_Settings
532
  </tr>
533
  <tr>
534
  <td colspan="2" class="title">
535
- <div class="onoffswitch">
536
  <input type="checkbox" name="options[ga_dash_adsense]" value="1" class="onoffswitch-checkbox" id="ga_dash_adsense" <?php checked( $options['ga_dash_adsense'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_adsense">
537
  <div class="onoffswitch-inner"></div>
538
  <div class="onoffswitch-switch"></div>
@@ -543,7 +533,7 @@ final class GADWP_Settings
543
  </tr>
544
  <tr>
545
  <td colspan="2" class="title">
546
- <div class="onoffswitch">
547
  <input type="checkbox" name="options[ga_crossdomain_tracking]" value="1" class="onoffswitch-checkbox" id="ga_crossdomain_tracking" <?php checked( $options['ga_crossdomain_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_crossdomain_tracking">
548
  <div class="onoffswitch-inner"></div>
549
  <div class="onoffswitch-switch"></div>
@@ -567,28 +557,34 @@ final class GADWP_Settings
567
  <td class="roles title"><label for="ga_track_exclude"><?php _e("Exclude tracking for:", 'ga-dash' ); ?></label></td>
568
  <td class="roles">
569
  <?php
570
- if (! isset($wp_roles)) {
571
- $wp_roles = new WP_Roles();
572
- }
573
- $i = 0;
574
- ?> <table>
575
  <tr>
576
  <?php
577
- foreach ($wp_roles->role_names as $role => $name) {
578
- $i ++;
579
- ?>
580
  <td><label> <input type="checkbox" name="options[ga_track_exclude][]" value="<?php echo $role; ?>" <?php if (in_array($role,$options['ga_track_exclude'])) echo 'checked="checked"'; ?> />
581
  <?php echo $name; ?>
582
  </label></td>
583
  <?php
584
- if ($i % 4 == 0) {
585
- ?>
586
  </tr>
587
  <tr>
588
  <?php
589
- }
590
- }
591
- ?>
 
 
 
 
 
 
592
  </table>
593
  </td>
594
  </tr>
@@ -605,45 +601,46 @@ final class GADWP_Settings
605
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
606
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
607
 
 
 
608
  </form>
609
  <?php
610
- self::output_sidebar();
611
- }
 
 
 
 
 
 
 
 
 
612
 
613
- public static function errors_debugging()
614
- {
615
- global $wp_version;
616
-
617
- $gadwp = GADWP();
618
-
619
- if (! current_user_can('manage_options')) {
620
- return;
621
- }
622
-
623
- $anonim = $gadwp->config->options;
624
- $anonim['wp_version'] = $wp_version;
625
- $anonim['gadwp_version'] = GADWP_CURRENT_VERSION;
626
- if ($anonim['ga_dash_token']) {
627
- $anonim['ga_dash_token'] = 'HIDDEN';
628
- }
629
- if ($anonim['ga_dash_refresh_token']) {
630
- $anonim['ga_dash_refresh_token'] = 'HIDDEN';
631
- }
632
- if ($anonim['ga_dash_clientid']) {
633
- $anonim['ga_dash_clientid'] = 'HIDDEN';
634
- }
635
- if ($anonim['ga_dash_clientsecret']) {
636
- $anonim['ga_dash_clientsecret'] = 'HIDDEN';
637
- }
638
- if ($anonim['ga_dash_apikey']) {
639
- $anonim['ga_dash_apikey'] = 'HIDDEN';
640
- }
641
-
642
- $options = self::update_options('frontend');
643
- if (! $gadwp->config->options['ga_dash_tableid_jail'] || ! $gadwp->config->options['ga_dash_token']) {
644
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
645
- }
646
- ?>
647
  <div class="wrap">
648
  <?php echo "<h2>" . __( "Google Analytics Errors & Debugging", 'ga-dash' ) . "</h2>"; ?>
649
  </div>
@@ -654,12 +651,11 @@ final class GADWP_Settings
654
  <div class="inside">
655
  <?php if (isset($message)) echo $message; ?>
656
  <?php
657
- $tabs = array(
658
- 'errors' => __("Errors & Details", 'ga-dash'),
659
- 'config' => __("Plugin Settings", 'ga-dash')
660
- );
661
- self::navigation_tabs($tabs);
662
- ?>
663
  <div id="gadwp-errors">
664
  <table class="options">
665
  <tr>
@@ -670,10 +666,10 @@ final class GADWP_Settings
670
  <tr>
671
  <td>
672
  <?php
673
- $errors = esc_html(print_r(get_transient('ga_dash_lasterror'), true)) ? esc_html(print_r(get_transient('ga_dash_lasterror'), true)) : __("None", 'ga-dash');
674
- echo '<pre class="log_data">Last Error: ';
675
- echo $errors;
676
- ?></pre>
677
  </td>
678
  </tr>
679
  <tr>
@@ -682,16 +678,16 @@ final class GADWP_Settings
682
  <tr>
683
  <td>
684
  <?php
685
- echo '<pre class="log_data">Error Details: ';
686
- $error_details = esc_html(print_r(get_transient('ga_dash_gapi_errors'), true)) ? "\n" . esc_html(print_r(get_transient('ga_dash_gapi_errors'), true)) : __("None", 'ga-dash');
687
- echo $error_details;
688
- ?></pre><br />
689
  <hr>
690
  </td>
691
-
692
-
693
  <tr>
694
-
695
  </table>
696
  </div>
697
  <div id="gadwp-config">
@@ -701,120 +697,118 @@ final class GADWP_Settings
701
  </tr>
702
  <tr>
703
  <td><pre class="log_data"><?php echo esc_html(print_r($anonim, true));?></pre><br />
704
- <hr></td>
705
  </tr>
706
  </table>
707
  </div>
708
  <?php
709
- self::output_sidebar();
710
- }
711
 
712
- public static function general_settings()
713
- {
714
- $gadwp = GADWP();
715
-
716
- global $wp_version;
717
-
718
- if (! current_user_can('manage_options')) {
719
- return;
720
- }
721
- $options = self::update_options('general');
722
- printf('<div id="gapi-warning" class="updated"><p>%1$s <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=gadwp">%2$s</a></p></div>', __('Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', "ga-dash"), __('Library conflicts between WordPress plugins', "ga-dash"));
723
- if (null === $gadwp->gapi_controller) {
724
- $gadwp->gapi_controller = new GADWP_GAPI_Controller();
725
- }
726
- echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
727
- if (isset($_POST['ga_dash_code'])) {
728
- if (! stripos('x' . $_POST['ga_dash_code'], 'UA-', 1) == 1) {
729
- try {
730
- $gadwp->gapi_controller->client->authenticate($_POST['ga_dash_code']);
731
- $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
732
- $google_token = json_decode($gadwp->gapi_controller->client->getAccessToken());
733
- $gadwp->config->options['ga_dash_refresh_token'] = $google_token->refresh_token;
734
- $gadwp->config->options['automatic_updates_minorversion'] = 1;
735
- $gadwp->config->set_plugin_options();
736
- $options = self::update_options('general');
737
- $message = "<div class='updated'><p>" . __("Plugin authorization succeeded.", 'ga-dash') . "</p></div>";
738
- delete_transient('ga_dash_gapi_errors');
739
- delete_transient('ga_dash_lasterror');
740
- } catch (Google_IO_Exception $e) {
741
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $gadwp->gapi_controller->error_timeout);
742
- return false;
743
- } catch (Google_Service_Exception $e) {
744
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $gadwp->gapi_controller->error_timeout);
745
- set_transient('ga_dash_gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout);
746
- return $e->getCode();
747
- } catch (Exception $e) {
748
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e) . "\nResponseHttpCode:" . $e->getCode(), $gadwp->gapi_controller->error_timeout);
749
- $gadwp->gapi_controller->reset_token(false);
750
- }
751
- } else {
752
- $message = "<div class='error'><p>" . __("The access code is <strong>NOT</strong> your <strong>Tracking ID</strong> (UA-XXXXX-X). Try again, and use the red link to get your access code", 'ga-dash') . ".</p></div>";
753
- }
754
- }
755
- if ($gadwp->config->options['ga_dash_token'] && $gadwp->gapi_controller->client->getAccessToken()) {
756
- if (!empty($gadwp->config->options['ga_dash_profile_list'])) {
757
- $profiles = $gadwp->config->options['ga_dash_profile_list'];
758
- } else {
759
- $profiles = $gadwp->gapi_controller->refresh_profiles();
760
- }
761
- if ($profiles) {
762
- $gadwp->config->options['ga_dash_profile_list'] = $profiles;
763
- if (! $gadwp->config->options['ga_dash_tableid_jail']) {
764
- $profile = GADWP_Tools::guess_default_domain($profiles);
765
- $gadwp->config->options['ga_dash_tableid_jail'] = $profile;
766
- $gadwp->config->options['ga_dash_tableid'] = $profile;
767
- }
768
- $gadwp->config->set_plugin_options();
769
- $options = self::update_options('general');
770
- }
771
- }
772
- if (isset($_POST['Clear'])) {
773
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
774
- GADWP_Tools::clear_cache();
775
- $message = "<div class='updated'><p>" . __("Cleared Cache.", 'ga-dash') . "</p></div>";
776
- } else {
777
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
778
- }
779
- }
780
- if (isset($_POST['Reset'])) {
781
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
782
- $gadwp->gapi_controller->reset_token(true);
783
- GADWP_Tools::clear_cache();
784
- $message = "<div class='updated'><p>" . __("Token Reseted and Revoked.", 'ga-dash') . "</p></div>";
785
- $options = self::update_options('Reset');
786
- } else {
787
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
788
- }
789
- }
790
- if (isset($_POST['Reset_Err'])) {
791
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
792
- delete_transient('ga_dash_lasterror');
793
- delete_transient('ga_dash_gapi_errors');
794
- $message = "<div class='updated'><p>" . __("All errors reseted.", 'ga-dash') . "</p></div>";
795
- } else {
796
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
797
- }
798
- }
799
- if (isset($_POST['options']['ga_dash_hidden']) && ! isset($_POST['Clear']) && ! isset($_POST['Reset']) && ! isset($_POST['Reset_Err'])) {
800
- $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>";
801
- if (! (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) {
802
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
803
- }
804
- }
805
- if (isset($_POST['Hide'])) {
806
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
807
- $message = "<div class='updated'><p>" . __("All other domains/properties were removed.", 'ga-dash') . "</p></div>";
808
- $lock_profile = GADWP_Tools::get_selected_profile($gadwp->config->options['ga_dash_profile_list'], $gadwp->config->options['ga_dash_tableid_jail']);
809
- $gadwp->config->options['ga_dash_profile_list'] = array(
810
- $lock_profile
811
- );
812
- $options = self::update_options('general');
813
- } else {
814
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
815
- }
816
- }
817
- ?>
818
  <div class="wrap">
819
  <?php echo "<h2>" . __( "Google Analytics Settings", 'ga-dash' ) . "</h2>"; ?>
820
  <hr>
@@ -823,18 +817,19 @@ final class GADWP_Settings
823
  <div id="post-body" class="metabox-holder columns-2">
824
  <div id="post-body-content">
825
  <div class="settings-wrapper">
826
- <div class="inside">
827
- if ($gadwp->gapi_controller->gapi_errors_handler()) {
828
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
829
- }
830
- if (isset($_POST['Authorize'])) {
831
- GADWP_Tools::clear_cache();
832
- $gadwp->gapi_controller->token_request();
833
- echo "<div class='updated'><p>" . __("Use the red link (see below) to generate and get your access code!", 'ga-dash') . "</p></div>";
834
- } else {
835
- if (isset($message))
836
- echo $message;
837
- ?>
 
838
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
839
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
840
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
@@ -853,7 +848,8 @@ final class GADWP_Settings
853
  <tr>
854
  <td colspan="2" class="info"><input name="options[ga_dash_userapi]" type="checkbox" id="ga_dash_userapi" value="1" <?php checked( $options['ga_dash_userapi'], 1 ); ?> onchange="this.form.submit()" <?php echo ($options['ga_dash_network'])?'disabled="disabled"':''; ?> /><?php echo " ".__("use your own API Project credentials", 'ga-dash' );?>
855
  </td>
856
- </tr>
857
  <?php } if ($options['ga_dash_userapi']) { ?>
 
 
858
  <tr>
859
  <td class="title"><label for="options[ga_dash_apikey]"><?php _e("API Key:", 'ga-dash'); ?></label></td>
860
  <td><input type="text" name="options[ga_dash_apikey]" value="<?php echo esc_attr($options['ga_dash_apikey']); ?>" size="40" required="required"></td>
@@ -869,9 +865,9 @@ final class GADWP_Settings
869
  </td>
870
  </tr>
871
  <?php
872
- }
873
- if ($options['ga_dash_token']) {
874
- ?>
875
  <tr>
876
  <td colspan="2"><input type="submit" name="Reset" class="button button-secondary" value="<?php _e( "Clear Authorization", 'ga-dash' ); ?>" <?php echo $options['ga_dash_network']?'disabled="disabled"':''; ?> /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e( "Clear Cache", 'ga-dash' ); ?>" /> <input type="submit" name="Reset_Err" class="button button-secondary" value="<?php _e( "Reset Errors", 'ga-dash' ); ?>" /></td>
877
  </tr>
@@ -885,37 +881,39 @@ final class GADWP_Settings
885
  <td class="title"><label for="ga_dash_tableid_jail"><?php _e("Select View:", 'ga-dash' ); ?></label></td>
886
  <td><select id="ga_dash_tableid_jail" <?php disabled(empty($options['ga_dash_profile_list']) || 1 == count($options['ga_dash_profile_list']), true); ?> name="options[ga_dash_tableid_jail]">
887
  <?php
888
- if (!empty($options['ga_dash_profile_list'])) {
889
- foreach ($options['ga_dash_profile_list'] as $items) {
890
- if ($items[3]) {
891
- echo '<option value="' . esc_attr($items[1]) . '" ' . selected($items[1], $options['ga_dash_tableid_jail']);
892
- echo ' title="' . __("View Name:", 'ga-dash') . ' ' . esc_attr($items[0]) . '">' . esc_html(GADWP_Tools::strip_protocol($items[3])) . ' &#8658; ' . esc_attr($items[0]) . '</option>';
893
- }
894
- }
895
- } else {
896
- echo '<option value="">' . __("Property not found", 'ga-dash') . '</option>';
897
- }
898
- ?>
899
- </select>
900
  <?php
901
- if (count($options['ga_dash_profile_list']) > 1) {
902
- ?>&nbsp;<input type="submit" name="Hide" class="button button-secondary" value="<?php _e( "Lock Selection", 'ga-dash' ); ?>" /><?php
903
- }
904
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
905
  </td>
906
  </tr>
907
  <?php
908
- if ($options['ga_dash_tableid_jail']) {
909
- ?>
910
  <tr>
911
  <td class="title"></td>
912
  <td><?php
913
- $profile_info = GADWP_Tools::get_selected_profile($gadwp->config->options['ga_dash_profile_list'], $gadwp->config->options['ga_dash_tableid_jail']);
914
- echo '<pre>' . __("View Name:", 'ga-dash') . "\t" . esc_html($profile_info[0]) . "<br />" . __("Tracking ID:", 'ga-dash') . "\t" . esc_html($profile_info[2]) . "<br />" . __("Default URL:", 'ga-dash') . "\t" . esc_html($profile_info[3]) . "<br />" . __("Time Zone:", 'ga-dash') . "\t" . esc_html($profile_info[5]) . '</pre>';
915
- ?></td>
916
  </tr>
917
  <?php
918
- }
919
- ?>
 
920
  <td class="title"><label for="ga_dash_style"><?php _e("Theme Color:", 'ga-dash' ); ?></label></td>
921
  <td><input type="text" id="ga_dash_style" class="ga_dash_style" name="options[ga_dash_style]" value="<?php echo esc_attr($options['ga_dash_style']); ?>" size="10"></td>
922
  </tr>
@@ -928,7 +926,7 @@ final class GADWP_Settings
928
  </tr>
929
  <tr>
930
  <td colspan="2" class="title">
931
- <div class="onoffswitch">
932
  <input type="checkbox" name="options[automatic_updates_minorversion]" value="1" class="onoffswitch-checkbox" id="automatic_updates_minorversion" <?php checked( $options['automatic_updates_minorversion'], 1 ); ?>> <label class="onoffswitch-label" for="automatic_updates_minorversion">
933
  <div class="onoffswitch-inner"></div>
934
  <div class="onoffswitch-switch"></div>
@@ -937,13 +935,14 @@ final class GADWP_Settings
937
  <div class="switch-desc"><?php echo " ".__( "automatic updates for minor versions (security and maintenance releases only)", 'ga-dash' );?></div>
938
  </td>
939
  </tr>
940
- <tr>
941
  <td colspan="2"><hr></td>
942
- </tr>
943
  <?php }?>
944
  <tr>
945
  <td colspan="2" class="submit"><input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'ga-dash' ) ?>" /></td>
946
- </tr>
 
947
  <tr>
948
  <td colspan="2"><hr></td>
949
  </tr>
@@ -956,134 +955,133 @@ final class GADWP_Settings
956
  </table>
957
  </form>
958
  <?php
959
- self::output_sidebar();
960
- return;
961
- }
962
- ?>
963
- </form>
964
- }
965
- self::output_sidebar();
966
- }
967
- // Network Settings
968
- public static function general_settings_network()
969
- {
970
- $gadwp = GADWP();
971
- global $wp_version;
972
-
973
- if (! current_user_can('manage_network_options')) {
974
- return;
975
- }
976
- $options = self::update_options('network');
977
- /*
978
- * Include GAPI
979
- */
980
- echo '<div id="gapi-warning" class="updated"><p>' . __('Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', "ga-dash") . ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=gadwp">Library conflicts between WordPress plugins</a></p></div>';
981
-
982
- if (null === $gadwp->gapi_controller) {
983
- $gadwp->gapi_controller = new GADWP_GAPI_Controller();
984
- }
985
-
986
- echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
987
- if (isset($_POST['ga_dash_code'])) {
988
- if (! stripos('x' . $_POST['ga_dash_code'], 'UA-', 1) == 1) {
989
- try {
990
- $gadwp->gapi_controller->client->authenticate($_POST['ga_dash_code']);
991
- $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
992
- $google_token = json_decode($gadwp->gapi_controller->client->getAccessToken());
993
- $gadwp->config->options['ga_dash_refresh_token'] = $google_token->refresh_token;
994
- $gadwp->config->options['automatic_updates_minorversion'] = 1;
995
- $gadwp->config->set_plugin_options(true);
996
- $options = self::update_options('network');
997
- $message = "<div class='updated'><p>" . __("Plugin authorization succeeded.", 'ga-dash') . "</p></div>";
998
- if (is_multisite()) { // Cleanup errors on the entire network
999
- foreach (wp_get_sites(array(
1000
- 'limit' => apply_filters('gadwp_sites_limit', 100)
1001
- )) as $blog) {
1002
- switch_to_blog($blog['blog_id']);
1003
- delete_transient('ga_dash_gapi_errors');
1004
- restore_current_blog();
1005
- }
1006
- } else {
1007
- delete_transient('ga_dash_gapi_errors');
1008
- }
1009
- } catch (Google_IO_Exception $e) {
1010
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $gadwp->gapi_controller->error_timeout);
1011
- return false;
1012
- } catch (Google_Service_Exception $e) {
1013
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $gadwp->gapi_controller->error_timeout);
1014
- set_transient('ga_dash_gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout);
1015
- return $e->getCode();
1016
- } catch (Exception $e) {
1017
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e) . "\nResponseHttpCode:" . $e->getCode(), $gadwp->gapi_controller->error_timeout);
1018
- $gadwp->gapi_controller->reset_token(false);
1019
- }
1020
- } else {
1021
- $message = "<div class='error'><p>" . __("The access code is <strong>NOT</strong> your <strong>Tracking ID</strong> (UA-XXXXX-X). Try again, and use the red link to get your access code", 'ga-dash') . ".</p></div>";
1022
- }
1023
- }
1024
- if (isset($_POST['Refresh'])) {
1025
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
1026
- $gadwp->config->options['ga_dash_profile_list'] = array();
1027
- $message = "<div class='updated'><p>" . __("Properties refreshed.", 'ga-dash') . "</p></div>";
1028
- $options = self::update_options('network');
1029
- } else {
1030
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
1031
- }
1032
- }
1033
- if ($gadwp->config->options['ga_dash_token'] && $gadwp->gapi_controller->client->getAccessToken()) {
1034
- if (!empty($gadwp->config->options['ga_dash_profile_list'])) {
1035
- $profiles = $gadwp->config->options['ga_dash_profile_list'];
1036
- } else {
1037
- $profiles = $gadwp->gapi_controller->refresh_profiles();
1038
- }
1039
- if ($profiles) {
1040
- $gadwp->config->options['ga_dash_profile_list'] = $profiles;
1041
- if (isset($gadwp->config->options['ga_dash_tableid_jail']) && ! $gadwp->config->options['ga_dash_tableid_jail']) {
1042
- $profile = GADWP_Tools::guess_default_domain($profiles);
1043
- $gadwp->config->options['ga_dash_tableid_jail'] = $profile;
1044
- $gadwp->config->options['ga_dash_tableid'] = $profile;
1045
- }
1046
- $gadwp->config->set_plugin_options(true);
1047
- $options = self::update_options('network');
1048
- }
1049
- }
1050
- if (isset($_POST['Clear'])) {
1051
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
1052
- GADWP_Tools::clear_cache();
1053
- $message = "<div class='updated'><p>" . __("Cleared Cache.", 'ga-dash') . "</p></div>";
1054
- } else {
1055
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
1056
- }
1057
- }
1058
- if (isset($_POST['Reset'])) {
1059
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
1060
- $gadwp->gapi_controller->reset_token(true);
1061
- GADWP_Tools::clear_cache();
1062
- $message = "<div class='updated'><p>" . __("Token Reseted and Revoked.", 'ga-dash') . "</p></div>";
1063
- $options = self::update_options('Reset');
1064
- } else {
1065
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
1066
- }
1067
- }
1068
- if (isset($_POST['options']['ga_dash_hidden']) && ! isset($_POST['Clear']) && ! isset($_POST['Reset']) && ! isset($_POST['Refresh'])) {
1069
- $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>";
1070
- if (! (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) {
1071
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
1072
- }
1073
- }
1074
- if (isset($_POST['Hide'])) {
1075
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
1076
- $message = "<div class='updated'><p>" . __("All other domains/properties were removed.", 'ga-dash') . "</p></div>";
1077
- $lock_profile = GADWP_Tools::get_selected_profile($gadwp->config->options['ga_dash_profile_list'], $gadwp->config->options['ga_dash_tableid_jail']);
1078
- $gadwp->config->options['ga_dash_profile_list'] = array(
1079
- $lock_profile
1080
- );
1081
- $options = self::update_options('network');
1082
- } else {
1083
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
1084
- }
1085
- }
1086
- ?>
1087
  <div class="wrap">
1088
  <?php echo "<h2>" . __( "Google Analytics Settings", 'ga-dash' ) . "</h2>"; ?><hr>
1089
  </div>
@@ -1091,18 +1089,19 @@ final class GADWP_Settings
1091
  <div id="post-body" class="metabox-holder columns-2">
1092
  <div id="post-body-content">
1093
  <div class="settings-wrapper">
1094
- <div class="inside">
1095
- if ($gadwp->gapi_controller->gapi_errors_handler()) {
1096
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
1097
- }
1098
- if (isset($_POST['Authorize'])) {
1099
- GADWP_Tools::clear_cache();
1100
- $gadwp->gapi_controller->token_request();
1101
- echo "<div class='updated'><p>" . __("Use the red link (see below) to generate and get your access code!", 'ga-dash') . "</p></div>";
1102
- } else {
1103
- if (isset($message))
1104
- echo $message;
1105
- ?>
 
1106
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
1107
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
1108
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
@@ -1112,7 +1111,7 @@ final class GADWP_Settings
1112
  </tr>
1113
  <tr>
1114
  <td colspan="2" class="title">
1115
- <div class="onoffswitch">
1116
  <input type="checkbox" name="options[ga_dash_network]" value="1" class="onoffswitch-checkbox" id="ga_dash_network" <?php checked( $options['ga_dash_network'], 1); ?> onchange="this.form.submit()"> <label class="onoffswitch-label" for="ga_dash_network">
1117
  <div class="onoffswitch-inner"></div>
1118
  <div class="onoffswitch-switch"></div>
@@ -1134,15 +1133,16 @@ final class GADWP_Settings
1134
  </td>
1135
  </tr>
1136
  <?php
1137
- if (! $options['ga_dash_token'] || $options['ga_dash_userapi']) {
1138
- ?>
1139
  <tr>
1140
  <td colspan="2" class="info"><input name="options[ga_dash_userapi]" type="checkbox" id="ga_dash_userapi" value="1" <?php checked( $options['ga_dash_userapi'], 1 ); ?> onchange="this.form.submit()" /><?php echo " ".__("use your own API Project credentials", 'ga-dash' );?>
1141
  </td>
1142
- </tr>
1143
- }
1144
- if ($options['ga_dash_userapi']) {
1145
- ?>
 
1146
  <tr>
1147
  <td class="title"><label for="options[ga_dash_apikey]"><?php _e("API Key:", 'ga-dash'); ?></label></td>
1148
  <td><input type="text" name="options[ga_dash_apikey]" value="<?php echo esc_attr($options['ga_dash_apikey']); ?>" size="40" required="required"></td>
@@ -1158,9 +1158,9 @@ final class GADWP_Settings
1158
  </td>
1159
  </tr>
1160
  <?php
1161
- }
1162
- if ($options['ga_dash_token']) {
1163
- ?>
1164
  <tr>
1165
  <td colspan="2"><input type="submit" name="Reset" class="button button-secondary" value="<?php _e( "Clear Authorization", 'ga-dash' ); ?>" /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e( "Clear Cache", 'ga-dash' ); ?>" /> <input type="submit" name="Refresh" class="button button-secondary" value="<?php _e( "Refresh Properties", 'ga-dash' ); ?>" /></td>
1166
  </tr>
@@ -1171,39 +1171,38 @@ final class GADWP_Settings
1171
  <td colspan="2"><?php echo "<h2>" . __( "Properties/Views Settings", 'ga-dash' ) . "</h2>"; ?></td>
1172
  </tr>
1173
  <?php
1174
- if (isset($options['ga_dash_tableid_network'])) {
1175
- $options['ga_dash_tableid_network'] = json_decode(json_encode($options['ga_dash_tableid_network']), false);
1176
- }
1177
- foreach (wp_get_sites(array(
1178
- 'limit' => apply_filters('gadwp_sites_limit', 100)
1179
- )) as $blog) {
1180
- ?>
1181
  <tr>
1182
  <td class="title-select"><label for="ga_dash_tableid_network"><?php echo '<strong>'.$blog['domain'].$blog['path'].'</strong>: ';?></label></td>
1183
  <td><select id="ga_dash_tableid_network" <?php disabled(!empty($options['ga_dash_profile_list']),false);?> name="options[ga_dash_tableid_network][<?php echo $blog['blog_id'];?>]">
1184
  <?php
1185
- if (!empty($options['ga_dash_profile_list'])) {
1186
- foreach ($options['ga_dash_profile_list'] as $items) {
1187
- if ($items[3]) {
1188
- echo '<option value="' . esc_attr($items[1]) . '" ' . selected($items[1], isset($options['ga_dash_tableid_network']->$blog['blog_id']) ? $options['ga_dash_tableid_network']->$blog['blog_id'] : '');
1189
- echo ' title="' . __("View Name:", 'ga-dash') . ' ' . esc_attr($items[0]) . '">' . esc_html(GADWP_Tools::strip_protocol($items[3])) . ' &#8658; ' . esc_attr($items[0]) . '</option>';
1190
- }
1191
- }
1192
- } else {
1193
- echo '<option value="">' . __("Property not found", 'ga-dash') . '</option>';
1194
- }
1195
- ?>
1196
  </select> <br /></td>
1197
  </tr>
1198
  <?php
1199
- }
1200
- ?>
1201
  <tr>
1202
  <td colspan="2"><?php echo "<h2>" . __( "Automatic Updates", 'ga-dash' ) . "</h2>"; ?></td>
1203
  </tr>
1204
  <tr>
1205
  <td colspan="2" class="title">
1206
- <div class="onoffswitch">
1207
  <input type="checkbox" name="options[automatic_updates_minorversion]" value="1" class="onoffswitch-checkbox" id="automatic_updates_minorversion" <?php checked( $options['automatic_updates_minorversion'], 1 ); ?>> <label class="onoffswitch-label" for="automatic_updates_minorversion">
1208
  <div class="onoffswitch-inner"></div>
1209
  <div class="onoffswitch-switch"></div>
@@ -1217,7 +1216,7 @@ final class GADWP_Settings
1217
  </tr>
1218
  <tr>
1219
  <td colspan="2" class="title">
1220
- <div class="onoffswitch">
1221
  <input type="checkbox" name="options[ga_dash_excludesa]" value="1" class="onoffswitch-checkbox" id="ga_dash_excludesa"<?php checked( $options['ga_dash_excludesa'], 1); ?>"> <label class="onoffswitch-label" for="ga_dash_excludesa">
1222
  <div class="onoffswitch-inner"></div>
1223
  <div class="onoffswitch-switch"></div>
@@ -1231,9 +1230,11 @@ final class GADWP_Settings
1231
  </tr>
1232
  <tr>
1233
  <td colspan="2" class="submit"><input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'ga-dash' ) ?>" /></td>
1234
- </tr>
1235
- } else {
1236
- ?>
 
 
1237
  <td colspan="2"><hr></td>
1238
  </tr>
1239
  <tr>
@@ -1246,21 +1247,20 @@ final class GADWP_Settings
1246
  </table>
1247
  </form>
1248
  <?php
1249
- self::output_sidebar();
1250
- return;
1251
- }
1252
- ?>
1253
  </table>
1254
  </form>
1255
  <?php
1256
- }
1257
- self::output_sidebar();
1258
- }
1259
 
1260
- public static function output_sidebar()
1261
- {
1262
- $gadwp = GADWP();
1263
- ?>
1264
  </div>
1265
  </div>
1266
  </div>
@@ -1276,14 +1276,26 @@ final class GADWP_Settings
1276
  </div>
1277
  <div class="postbox">
1278
  <h3>
1279
- <span><?php _e("Support & Reviews",'ga-dash')?></span>
1280
  </h3>
1281
  <div class="inside">
1282
- <div class="gadash-title">
1283
- <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=support&utm_campaign=gadwp"><img src="<?php echo plugins_url( 'images/help.png' , __FILE__ ); ?>" /></a>
 
 
 
 
 
 
 
 
 
 
1284
  </div>
 
1285
  <div class="gadash-desc">
1286
- <?php printf(__('Plugin documentation and support on %s', 'ga-dash'), '<a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=support&utm_campaign=gadwp">deconf.com</a>');?>
 
1287
  </div>
1288
  <br />
1289
  <div class="gadash-title">
8
  */
9
 
10
  // Exit if accessed directly
11
+ if ( ! defined( 'ABSPATH' ) )
12
+ exit();
13
 
14
+ final class GADWP_Settings {
 
15
 
16
+ private static function update_options( $who ) {
17
+ $gadwp = GADWP();
18
+ $network_settings = false;
19
+ $options = $gadwp->config->options; // Get current options
20
+ if ( isset( $_POST['options']['ga_dash_hidden'] ) && isset( $_POST['options'] ) && ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) && $who != 'Reset' ) {
21
+ $new_options = $_POST['options'];
22
+ if ( $who == 'tracking' ) {
23
+ $options['ga_dash_anonim'] = 0;
24
+ $options['ga_event_tracking'] = 0;
25
+ $options['ga_enhanced_links'] = 0;
26
+ $options['ga_dash_remarketing'] = 0;
27
+ $options['ga_dash_adsense'] = 0;
28
+ $options['ga_event_bouncerate'] = 0;
29
+ $options['ga_crossdomain_tracking'] = 0;
30
+ $options['ga_aff_tracking'] = 0;
31
+ $options['ga_hash_tracking'] = 0;
32
+ if ( isset( $_POST['options']['ga_tracking_code'] ) ) {
33
+ $new_options['ga_tracking_code'] = trim( $new_options['ga_tracking_code'], "\t" );
34
+ }
35
+ if ( empty( $new_options['ga_track_exclude'] ) ) {
36
+ $new_options['ga_track_exclude'] = array();
37
+ }
38
+ } else
39
+ if ( $who == 'backend' ) {
40
+ $options['switch_profile'] = 0;
41
+ $options['backend_item_reports'] = 0;
42
+ $options['dashboard_widget'] = 0;
43
+ if ( empty( $new_options['ga_dash_access_back'] ) ) {
44
+ $new_options['ga_dash_access_back'][] = 'administrator';
45
+ }
46
+ } else
47
+ if ( $who == 'frontend' ) {
48
+ $options['frontend_item_reports'] = 0;
49
+ if ( empty( $new_options['ga_dash_access_front'] ) ) {
50
+ $new_options['ga_dash_access_front'][] = 'administrator';
51
+ }
52
+ } else
53
+ if ( $who == 'general' ) {
54
+ $options['ga_dash_userapi'] = 0;
55
+ if ( ! is_multisite() ) {
56
+ $options['automatic_updates_minorversion'] = 0;
57
+ }
58
+ } else
59
+ if ( $who == 'network' ) {
60
+ $options['ga_dash_userapi'] = 0;
61
+ $options['ga_dash_network'] = 0;
62
+ $options['ga_dash_excludesa'] = 0;
63
+ $options['automatic_updates_minorversion'] = 0;
64
+ $network_settings = true;
65
+ }
66
+ $options = array_merge( $options, $new_options );
67
+ $gadwp->config->options = $options;
68
+ $gadwp->config->set_plugin_options( $network_settings );
69
+ }
70
+ return $options;
71
+ }
 
 
72
 
73
+ private static function navigation_tabs( $tabs ) {
74
+ echo '<div id="icon-themes" class="icon32"><br></div>';
75
+ echo '<h2 class="nav-tab-wrapper">';
76
+ foreach ( $tabs as $tab => $name ) {
77
+ echo "<a class='nav-tab' id='tab-$tab' href='#top#gadwp-$tab'>$name</a>";
78
+ }
79
+ echo '</h2>';
80
+ }
 
81
 
82
+ public static function frontend_settings() {
83
+ $gadwp = GADWP();
84
+ if ( ! current_user_can( 'manage_options' ) ) {
85
+ return;
86
+ }
87
+ $options = self::update_options( 'frontend' );
88
+ if ( isset( $_POST['options']['ga_dash_hidden'] ) ) {
89
+ $message = "<div class='updated'><p>" . __( "Settings saved.", 'ga-dash' ) . "</p></div>";
90
+ if ( ! ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) ) {
91
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
92
+ }
93
+ }
94
+ if ( ! $gadwp->config->options['ga_dash_tableid_jail'] || ! $gadwp->config->options['ga_dash_token'] ) {
95
+ $message = sprintf( '<div class="error"><p>%s</p></div>', sprintf( __( 'Something went wrong, check %1$s or %2$s.', 'ga-dash' ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_errors_debugging', false ), __( 'Errors & Debug', 'ga-dash' ) ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_settings', false ), __( 'authorize the plugin', 'ga-dash' ) ) ) );
96
+ }
97
+ ?>
 
98
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
99
  <div class="wrap">
100
  <?php echo "<h2>" . __( "Google Analytics Frontend Settings", 'ga-dash' ) . "</h2>"; ?><hr>
113
  <td class="roles title"><label for="ga_dash_access_front"><?php _e("Show stats to:", 'ga-dash' ); ?></label></td>
114
  <td class="roles">
115
  <?php
116
+ if ( ! isset( $wp_roles ) ) {
117
+ $wp_roles = new WP_Roles();
118
+ }
119
+ $i = 0;
120
+ ?>
121
  <table>
122
  <tr>
123
  <?php
124
+ foreach ( $wp_roles->role_names as $role => $name ) {
125
+ if ( $role != 'subscriber' ) {
126
+ $i++;
127
+ ?>
128
  <td><label> <input type="checkbox" name="options[ga_dash_access_front][]" value="<?php echo $role; ?>" <?php if (in_array($role,$options['ga_dash_access_front']) || $role=='administrator') echo 'checked="checked"'; if ($role=='administrator') echo 'disabled="disabled"';?> /><?php echo $name; ?>
129
  </label></td>
130
  <?php
131
+ }
132
+ if ( $i % 4 == 0 ) {
133
+ ?>
134
  </tr>
135
  <tr>
136
  <?php
137
+ }
138
+ }
139
+ ?>
140
+
141
+
142
+
143
  </table>
144
  </td>
145
  </tr>
146
  <tr>
147
  <td colspan="2" class="title">
148
+ <div class="button-primary onoffswitch">
149
+ <input type="checkbox" name="options[frontend_item_reports]" value="1" class="onoffswitch-checkbox" id="frontend_item_reports" <?php checked( $options['frontend_item_reports'], 1 ); ?>> <label class="onoffswitch-label" for="frontend_item_reports">
150
  <div class="onoffswitch-inner"></div>
151
  <div class="onoffswitch-switch"></div>
152
  </label>
153
  </div>
154
+ <div class="switch-desc"><?php echo " ".__("enable web page reports on frontend", 'ga-dash' );?></div>
 
 
 
 
 
 
 
 
 
 
 
155
  </td>
156
  </tr>
157
  <tr>
167
 
168
 
169
 
170
+
171
+
172
  </form>
173
  <?php
174
+ self::output_sidebar();
175
+ }
176
 
177
+ public static function backend_settings() {
178
+ $gadwp = GADWP();
179
+ if ( ! current_user_can( 'manage_options' ) ) {
180
+ return;
181
+ }
182
+ $options = self::update_options( 'backend' );
183
+ if ( isset( $_POST['options']['ga_dash_hidden'] ) ) {
184
+ $message = "<div class='updated'><p>" . __( "Settings saved.", 'ga-dash' ) . "</p></div>";
185
+ if ( ! ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) ) {
186
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
187
+ }
188
+ }
189
+ if ( ! $gadwp->config->options['ga_dash_tableid_jail'] || ! $gadwp->config->options['ga_dash_token'] ) {
190
+ $message = sprintf( '<div class="error"><p>%s</p></div>', sprintf( __( 'Something went wrong, check %1$s or %2$s.', 'ga-dash' ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_errors_debugging', false ), __( 'Errors & Debug', 'ga-dash' ) ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_settings', false ), __( 'authorize the plugin', 'ga-dash' ) ) ) );
191
+ }
192
+ ?>
 
193
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
194
  <div class="wrap">
195
  <?php echo "<h2>" . __( "Google Analytics Backend Settings", 'ga-dash' ) . "</h2>"; ?><hr>
208
  <td class="roles title"><label for="ga_dash_access_back"><?php _e("Show stats to:", 'ga-dash' ); ?></label></td>
209
  <td class="roles">
210
  <?php
211
+ if ( ! isset( $wp_roles ) ) {
212
+ $wp_roles = new WP_Roles();
213
+ }
214
+ $i = 0;
215
+ ?>
216
  <table>
217
  <tr>
218
  <?php
219
+
220
+ foreach ( $wp_roles->role_names as $role => $name ) {
221
+ if ( $role != 'subscriber' ) {
222
+ $i++;
223
+ ?>
224
  <td><label> <input type="checkbox" name="options[ga_dash_access_back][]" value="<?php echo $role; ?>" <?php if (in_array($role,$options['ga_dash_access_back']) || $role=='administrator') echo 'checked="checked"'; if ($role=='administrator') echo 'disabled="disabled"';?> />
225
  <?php echo $name; ?>
226
  </label></td>
227
  <?php
228
+ }
229
+ if ( $i % 4 == 0 ) {
230
+ ?>
231
  </tr>
232
  <tr>
233
  <?php
234
+ }
235
+ }
236
+ ?>
237
+
238
+
239
+
240
  </table>
241
  </td>
242
  </tr>
243
  <tr>
244
  <td colspan="2" class="title">
245
+ <div class="button-primary onoffswitch">
246
  <input type="checkbox" name="options[switch_profile]" value="1" class="onoffswitch-checkbox" id="switch_profile" <?php checked( $options['switch_profile'], 1 ); ?>> <label class="onoffswitch-label" for="switch_profile">
247
  <div class="onoffswitch-inner"></div>
248
  <div class="onoffswitch-switch"></div>
253
  </tr>
254
  <tr>
255
  <td colspan="2" class="title">
256
+ <div class="button-primary onoffswitch">
257
+ <input type="checkbox" name="options[backend_item_reports]" value="1" class="onoffswitch-checkbox" id="backend_item_reports" <?php checked( $options['backend_item_reports'], 1 ); ?>> <label class="onoffswitch-label" for="backend_item_reports">
258
  <div class="onoffswitch-inner"></div>
259
  <div class="onoffswitch-switch"></div>
260
  </label>
264
  </tr>
265
  <tr>
266
  <td colspan="2" class="title">
267
+ <div class="button-primary onoffswitch">
268
  <input type="checkbox" name="options[dashboard_widget]" value="1" class="onoffswitch-checkbox" id="dashboard_widget" <?php checked( $options['dashboard_widget'], 1 ); ?>> <label class="onoffswitch-label" for="dashboard_widget">
269
  <div class="onoffswitch-inner"></div>
270
  <div class="onoffswitch-switch"></div>
279
  <tr>
280
  <td colspan="2" class="title"> <?php _e("Maximum number of pages to display on real-time tab:", 'ga-dash'); ?>
281
  <input type="number" name="options[ga_realtime_pages]" id="ga_realtime_pages" value="<?php echo (int)$options['ga_realtime_pages']; ?>" size="3">
282
+ </td>
283
  </tr>
284
  <tr>
285
  <td colspan="2"><hr><?php echo "<h2>" . __( "Location Settings", 'ga-dash' ) . "</h2>"; ?></td>
288
  <td colspan="2" class="title">
289
  <?php echo __("Target Geo Map to country:", 'ga-dash'); ?>
290
  <input type="text" style="text-align: center;" name="options[ga_target_geomap]" value="<?php echo esc_attr($options['ga_target_geomap']); ?>" size="3">
291
+ </td>
292
  </tr>
293
  <tr>
294
  <td colspan="2"><hr></td>
300
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
301
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
302
 
303
+
304
+
305
  </form>
306
  <?php
307
+ self::output_sidebar();
308
+ }
309
 
310
+ public static function tracking_settings() {
311
+ $gadwp = GADWP();
312
+
313
+ if ( ! current_user_can( 'manage_options' ) ) {
314
+ return;
315
+ }
316
+ $options = self::update_options( 'tracking' );
317
+ if ( isset( $_POST['options']['ga_dash_hidden'] ) ) {
318
+ $message = "<div class='updated'><p>" . __( "Settings saved.", 'ga-dash' ) . "</p></div>";
319
+ if ( ! ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) ) {
320
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
321
+ }
322
+ }
323
+ if ( ! $gadwp->config->options['ga_dash_tableid_jail'] ) {
324
+ $message = sprintf( '<div class="error"><p>%s</p></div>', sprintf( __( 'Something went wrong, check %1$s or %2$s.', 'ga-dash' ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_errors_debugging', false ), __( 'Errors & Debug', 'ga-dash' ) ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_settings', false ), __( 'authorize the plugin', 'ga-dash' ) ) ) );
325
+ }
326
+ if ( ! $options['ga_dash_tracking'] ) {
327
+ $message = "<div class='error'><p>" . __( "The tracking component is disabled. You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>", 'ga-dash' ) . ".</p></div>";
328
+ }
329
+ ?>
 
330
  <form name="ga_dash_form" method="post" action="<?php esc_url($_SERVER['REQUEST_URI']); ?>">
331
  <div class="wrap">
332
  <?php echo "<h2>" . __( "Google Analytics Tracking Code", 'ga-dash' ) . "</h2>"; ?>
337
  <div class="settings-wrapper">
338
  <div class="inside">
339
  <?php
340
+ $tabs = array(
341
+ 'basic' => __( "Basic Settings", 'ga-dash' ),
342
+ 'events' => __( "Events Tracking", 'ga-dash' ),
343
+ 'custom' => __( "Custom Definitions", 'ga-dash' ),
344
+ 'exclude' => __( "Exclude Tracking", 'ga-dash' ),
345
+ 'advanced' => __( "Advanced Settings", 'ga-dash' ) );
346
+ self::navigation_tabs( $tabs );
347
+ if ( isset( $message ) )
348
+ echo $message;
349
+ ?>
350
  <div id="gadwp-basic">
351
  <table class="options">
352
  <tr>
380
  </tr>
381
  <tr>
382
  <td colspan="2" class="title">
383
+ <div class="button-primary onoffswitch">
384
  <input type="checkbox" name="options[ga_dash_anonim]" value="1" class="onoffswitch-checkbox" id="ga_dash_anonim" <?php checked( $options['ga_dash_anonim'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_anonim">
385
  <div class="onoffswitch-inner"></div>
386
  <div class="onoffswitch-switch"></div>
391
  </tr>
392
  <tr>
393
  <td colspan="2" class="title">
394
+ <div class="button-primary onoffswitch">
395
  <input type="checkbox" name="options[ga_dash_remarketing]" value="1" class="onoffswitch-checkbox" id="ga_dash_remarketing" <?php checked( $options['ga_dash_remarketing'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_remarketing">
396
  <div class="onoffswitch-inner"></div>
397
  <div class="onoffswitch-switch"></div>
409
  </tr>
410
  <tr>
411
  <td colspan="2" class="title">
412
+ <div class="button-primary onoffswitch">
413
  <input type="checkbox" name="options[ga_event_tracking]" value="1" class="onoffswitch-checkbox" id="ga_event_tracking" <?php checked( $options['ga_event_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_event_tracking">
414
  <div class="onoffswitch-inner"></div>
415
  <div class="onoffswitch-switch"></div>
424
  </tr>
425
  <tr>
426
  <td colspan="2" class="title">
427
+ <div class="button-primary onoffswitch">
428
  <input type="checkbox" name="options[ga_aff_tracking]" value="1" class="onoffswitch-checkbox" id="ga_aff_tracking" <?php checked( $options['ga_aff_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_aff_tracking">
429
  <div class="onoffswitch-inner"></div>
430
  <div class="onoffswitch-switch"></div>
439
  </tr>
440
  <tr>
441
  <td colspan="2" class="title">
442
+ <div class="button-primary onoffswitch">
443
  <input type="checkbox" name="options[ga_hash_tracking]" value="1" class="onoffswitch-checkbox" id="ga_hash_tracking" <?php checked( $options['ga_hash_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_hash_tracking">
444
  <div class="onoffswitch-inner"></div>
445
  <div class="onoffswitch-switch"></div>
500
  </tr>
501
  <tr>
502
  <td colspan="2" class="title">
503
+ <div class="button-primary onoffswitch">
504
  <input type="checkbox" name="options[ga_event_bouncerate]" value="1" class="onoffswitch-checkbox" id="ga_event_bouncerate" <?php checked( $options['ga_event_bouncerate'], 1 ); ?>> <label class="onoffswitch-label" for="ga_event_bouncerate">
505
  <div class="onoffswitch-inner"></div>
506
  <div class="onoffswitch-switch"></div>
511
  </tr>
512
  <tr>
513
  <td colspan="2" class="title">
514
+ <div class="button-primary onoffswitch">
515
  <input type="checkbox" name="options[ga_enhanced_links]" value="1" class="onoffswitch-checkbox" id="ga_enhanced_links" <?php checked( $options['ga_enhanced_links'], 1 ); ?>> <label class="onoffswitch-label" for="ga_enhanced_links">
516
  <div class="onoffswitch-inner"></div>
517
  <div class="onoffswitch-switch"></div>
522
  </tr>
523
  <tr>
524
  <td colspan="2" class="title">
525
+ <div class="button-primary onoffswitch">
526
  <input type="checkbox" name="options[ga_dash_adsense]" value="1" class="onoffswitch-checkbox" id="ga_dash_adsense" <?php checked( $options['ga_dash_adsense'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_adsense">
527
  <div class="onoffswitch-inner"></div>
528
  <div class="onoffswitch-switch"></div>
533
  </tr>
534
  <tr>
535
  <td colspan="2" class="title">
536
+ <div class="button-primary onoffswitch">
537
  <input type="checkbox" name="options[ga_crossdomain_tracking]" value="1" class="onoffswitch-checkbox" id="ga_crossdomain_tracking" <?php checked( $options['ga_crossdomain_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_crossdomain_tracking">
538
  <div class="onoffswitch-inner"></div>
539
  <div class="onoffswitch-switch"></div>
557
  <td class="roles title"><label for="ga_track_exclude"><?php _e("Exclude tracking for:", 'ga-dash' ); ?></label></td>
558
  <td class="roles">
559
  <?php
560
+ if ( ! isset( $wp_roles ) ) {
561
+ $wp_roles = new WP_Roles();
562
+ }
563
+ $i = 0;
564
+ ?> <table>
565
  <tr>
566
  <?php
567
+ foreach ( $wp_roles->role_names as $role => $name ) {
568
+ $i++;
569
+ ?>
570
  <td><label> <input type="checkbox" name="options[ga_track_exclude][]" value="<?php echo $role; ?>" <?php if (in_array($role,$options['ga_track_exclude'])) echo 'checked="checked"'; ?> />
571
  <?php echo $name; ?>
572
  </label></td>
573
  <?php
574
+ if ( $i % 4 == 0 ) {
575
+ ?>
576
  </tr>
577
  <tr>
578
  <?php
579
+ }
580
+ }
581
+ ?>
582
+
583
+
584
+
585
+
586
+
587
+
588
  </table>
589
  </td>
590
  </tr>
601
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
602
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
603
 
604
+
605
+
606
  </form>
607
  <?php
608
+ self::output_sidebar();
609
+ }
610
+
611
+ public static function errors_debugging() {
612
+ global $wp_version;
613
+
614
+ $gadwp = GADWP();
615
+
616
+ if ( ! current_user_can( 'manage_options' ) ) {
617
+ return;
618
+ }
619
 
620
+ $anonim = $gadwp->config->options;
621
+ $anonim['wp_version'] = $wp_version;
622
+ $anonim['gadwp_version'] = GADWP_CURRENT_VERSION;
623
+ if ( $anonim['ga_dash_token'] ) {
624
+ $anonim['ga_dash_token'] = 'HIDDEN';
625
+ }
626
+ if ( $anonim['ga_dash_refresh_token'] ) {
627
+ $anonim['ga_dash_refresh_token'] = 'HIDDEN';
628
+ }
629
+ if ( $anonim['ga_dash_clientid'] ) {
630
+ $anonim['ga_dash_clientid'] = 'HIDDEN';
631
+ }
632
+ if ( $anonim['ga_dash_clientsecret'] ) {
633
+ $anonim['ga_dash_clientsecret'] = 'HIDDEN';
634
+ }
635
+ if ( $anonim['ga_dash_apikey'] ) {
636
+ $anonim['ga_dash_apikey'] = 'HIDDEN';
637
+ }
638
+
639
+ $options = self::update_options( 'frontend' );
640
+ if ( ! $gadwp->config->options['ga_dash_tableid_jail'] || ! $gadwp->config->options['ga_dash_token'] ) {
641
+ $message = sprintf( '<div class="error"><p>%s</p></div>', sprintf( __( 'Something went wrong, check %1$s or %2$s.', 'ga-dash' ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_errors_debugging', false ), __( 'Errors & Debug', 'ga-dash' ) ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_settings', false ), __( 'authorize the plugin', 'ga-dash' ) ) ) );
642
+ }
643
+ ?>
 
 
 
 
 
 
 
 
 
 
644
  <div class="wrap">
645
  <?php echo "<h2>" . __( "Google Analytics Errors & Debugging", 'ga-dash' ) . "</h2>"; ?>
646
  </div>
651
  <div class="inside">
652
  <?php if (isset($message)) echo $message; ?>
653
  <?php
654
+ $tabs = array(
655
+ 'errors' => __( "Errors & Details", 'ga-dash' ),
656
+ 'config' => __( "Plugin Settings", 'ga-dash' ) );
657
+ self::navigation_tabs( $tabs );
658
+ ?>
 
659
  <div id="gadwp-errors">
660
  <table class="options">
661
  <tr>
666
  <tr>
667
  <td>
668
  <?php
669
+ $errors = esc_html( print_r( get_transient( 'ga_dash_lasterror' ), true ) ) ? esc_html( print_r( get_transient( 'ga_dash_lasterror' ), true ) ) : __( "None", 'ga-dash' );
670
+ echo '<pre class="log_data">Last Error: ';
671
+ echo $errors;
672
+ ?></pre>
673
  </td>
674
  </tr>
675
  <tr>
678
  <tr>
679
  <td>
680
  <?php
681
+ echo '<pre class="log_data">Error Details: ';
682
+ $error_details = esc_html( print_r( get_transient( 'ga_dash_gapi_errors' ), true ) ) ? "\n" . esc_html( print_r( get_transient( 'ga_dash_gapi_errors' ), true ) ) : __( "None", 'ga-dash' );
683
+ echo $error_details;
684
+ ?></pre><br />
685
  <hr>
686
  </td>
687
+
688
+
689
  <tr>
690
+
691
  </table>
692
  </div>
693
  <div id="gadwp-config">
697
  </tr>
698
  <tr>
699
  <td><pre class="log_data"><?php echo esc_html(print_r($anonim, true));?></pre><br />
700
+ <hr></td>
701
  </tr>
702
  </table>
703
  </div>
704
  <?php
705
+ self::output_sidebar();
706
+ }
707
 
708
+ public static function general_settings() {
709
+ $gadwp = GADWP();
710
+
711
+ global $wp_version;
712
+
713
+ if ( ! current_user_can( 'manage_options' ) ) {
714
+ return;
715
+ }
716
+ $options = self::update_options( 'general' );
717
+ printf( '<div id="gapi-warning" class="updated"><p>%1$s <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=gadwp">%2$s</a></p></div>', __( 'Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', "ga-dash" ), __( 'Library conflicts between WordPress plugins', "ga-dash" ) );
718
+ if ( null === $gadwp->gapi_controller ) {
719
+ $gadwp->gapi_controller = new GADWP_GAPI_Controller();
720
+ }
721
+ echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
722
+ if ( isset( $_POST['ga_dash_code'] ) ) {
723
+ if ( ! stripos( 'x' . $_POST['ga_dash_code'], 'UA-', 1 ) == 1 ) {
724
+ try {
725
+ $gadwp->gapi_controller->client->authenticate( $_POST['ga_dash_code'] );
726
+ $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
727
+ $google_token = json_decode( $gadwp->gapi_controller->client->getAccessToken() );
728
+ $gadwp->config->options['ga_dash_refresh_token'] = $google_token->refresh_token;
729
+ $gadwp->config->options['automatic_updates_minorversion'] = 1;
730
+ $gadwp->config->set_plugin_options();
731
+ $options = self::update_options( 'general' );
732
+ $message = "<div class='updated'><p>" . __( "Plugin authorization succeeded.", 'ga-dash' ) . "</p></div>";
733
+ delete_transient( 'ga_dash_gapi_errors' );
734
+ delete_transient( 'ga_dash_lasterror' );
735
+ } catch ( Google_IO_Exception $e ) {
736
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $gadwp->gapi_controller->error_timeout );
737
+ return false;
738
+ } catch ( Google_Service_Exception $e ) {
739
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $gadwp->gapi_controller->error_timeout );
740
+ set_transient( 'ga_dash_gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout );
741
+ return $e->getCode();
742
+ } catch ( Exception $e ) {
743
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ) . "\nResponseHttpCode:" . $e->getCode(), $gadwp->gapi_controller->error_timeout );
744
+ $gadwp->gapi_controller->reset_token( false );
745
+ }
746
+ } else {
747
+ $message = "<div class='error'><p>" . __( "The access code is <strong>NOT</strong> your <strong>Tracking ID</strong> (UA-XXXXX-X). Try again, and use the red link to get your access code", 'ga-dash' ) . ".</p></div>";
748
+ }
749
+ }
750
+ if ( $gadwp->config->options['ga_dash_token'] && $gadwp->gapi_controller->client->getAccessToken() ) {
751
+ if ( ! empty( $gadwp->config->options['ga_dash_profile_list'] ) ) {
752
+ $profiles = $gadwp->config->options['ga_dash_profile_list'];
753
+ } else {
754
+ $profiles = $gadwp->gapi_controller->refresh_profiles();
755
+ }
756
+ if ( $profiles ) {
757
+ $gadwp->config->options['ga_dash_profile_list'] = $profiles;
758
+ if ( ! $gadwp->config->options['ga_dash_tableid_jail'] ) {
759
+ $profile = GADWP_Tools::guess_default_domain( $profiles );
760
+ $gadwp->config->options['ga_dash_tableid_jail'] = $profile;
761
+ $gadwp->config->options['ga_dash_tableid'] = $profile;
762
+ }
763
+ $gadwp->config->set_plugin_options();
764
+ $options = self::update_options( 'general' );
765
+ }
766
+ }
767
+ if ( isset( $_POST['Clear'] ) ) {
768
+ if ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) {
769
+ GADWP_Tools::clear_cache();
770
+ $message = "<div class='updated'><p>" . __( "Cleared Cache.", 'ga-dash' ) . "</p></div>";
771
+ } else {
772
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
773
+ }
774
+ }
775
+ if ( isset( $_POST['Reset'] ) ) {
776
+ if ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) {
777
+ $gadwp->gapi_controller->reset_token( true );
778
+ GADWP_Tools::clear_cache();
779
+ $message = "<div class='updated'><p>" . __( "Token Reseted and Revoked.", 'ga-dash' ) . "</p></div>";
780
+ $options = self::update_options( 'Reset' );
781
+ } else {
782
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
783
+ }
784
+ }
785
+ if ( isset( $_POST['Reset_Err'] ) ) {
786
+ if ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) {
787
+ delete_transient( 'ga_dash_lasterror' );
788
+ delete_transient( 'ga_dash_gapi_errors' );
789
+ $message = "<div class='updated'><p>" . __( "All errors reseted.", 'ga-dash' ) . "</p></div>";
790
+ } else {
791
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
792
+ }
793
+ }
794
+ if ( isset( $_POST['options']['ga_dash_hidden'] ) && ! isset( $_POST['Clear'] ) && ! isset( $_POST['Reset'] ) && ! isset( $_POST['Reset_Err'] ) ) {
795
+ $message = "<div class='updated'><p>" . __( "Settings saved.", 'ga-dash' ) . "</p></div>";
796
+ if ( ! ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) ) {
797
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
798
+ }
799
+ }
800
+ if ( isset( $_POST['Hide'] ) ) {
801
+ if ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) {
802
+ $message = "<div class='updated'><p>" . __( "All other domains/properties were removed.", 'ga-dash' ) . "</p></div>";
803
+ $lock_profile = GADWP_Tools::get_selected_profile( $gadwp->config->options['ga_dash_profile_list'], $gadwp->config->options['ga_dash_tableid_jail'] );
804
+ $gadwp->config->options['ga_dash_profile_list'] = array(
805
+ $lock_profile );
806
+ $options = self::update_options( 'general' );
807
+ } else {
808
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
809
+ }
810
+ }
811
+ ?>
 
 
812
  <div class="wrap">
813
  <?php echo "<h2>" . __( "Google Analytics Settings", 'ga-dash' ) . "</h2>"; ?>
814
  <hr>
817
  <div id="post-body" class="metabox-holder columns-2">
818
  <div id="post-body-content">
819
  <div class="settings-wrapper">
820
+ <div class="inside">
821
+ <?php
822
+ if ( $gadwp->gapi_controller->gapi_errors_handler() ) {
823
+ $message = sprintf( '<div class="error"><p>%s</p></div>', sprintf( __( 'Something went wrong, check %1$s or %2$s.', 'ga-dash' ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_errors_debugging', false ), __( 'Errors & Debug', 'ga-dash' ) ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_settings', false ), __( 'authorize the plugin', 'ga-dash' ) ) ) );
824
+ }
825
+ if ( isset( $_POST['Authorize'] ) ) {
826
+ GADWP_Tools::clear_cache();
827
+ $gadwp->gapi_controller->token_request();
828
+ echo "<div class='updated'><p>" . __( "Use the red link (see below) to generate and get your access code!", 'ga-dash' ) . "</p></div>";
829
+ } else {
830
+ if ( isset( $message ) )
831
+ echo $message;
832
+ ?>
833
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
834
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
835
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
848
  <tr>
849
  <td colspan="2" class="info"><input name="options[ga_dash_userapi]" type="checkbox" id="ga_dash_userapi" value="1" <?php checked( $options['ga_dash_userapi'], 1 ); ?> onchange="this.form.submit()" <?php echo ($options['ga_dash_network'])?'disabled="disabled"':''; ?> /><?php echo " ".__("use your own API Project credentials", 'ga-dash' );?>
850
  </td>
 
851
  <?php } if ($options['ga_dash_userapi']) { ?>
852
+ </tr>
853
+ <?php } if ($options['ga_dash_userapi']) { ?>
854
  <tr>
855
  <td class="title"><label for="options[ga_dash_apikey]"><?php _e("API Key:", 'ga-dash'); ?></label></td>
856
  <td><input type="text" name="options[ga_dash_apikey]" value="<?php echo esc_attr($options['ga_dash_apikey']); ?>" size="40" required="required"></td>
865
  </td>
866
  </tr>
867
  <?php
868
+ }
869
+ if ( $options['ga_dash_token'] ) {
870
+ ?>
871
  <tr>
872
  <td colspan="2"><input type="submit" name="Reset" class="button button-secondary" value="<?php _e( "Clear Authorization", 'ga-dash' ); ?>" <?php echo $options['ga_dash_network']?'disabled="disabled"':''; ?> /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e( "Clear Cache", 'ga-dash' ); ?>" /> <input type="submit" name="Reset_Err" class="button button-secondary" value="<?php _e( "Reset Errors", 'ga-dash' ); ?>" /></td>
873
  </tr>
881
  <td class="title"><label for="ga_dash_tableid_jail"><?php _e("Select View:", 'ga-dash' ); ?></label></td>
882
  <td><select id="ga_dash_tableid_jail" <?php disabled(empty($options['ga_dash_profile_list']) || 1 == count($options['ga_dash_profile_list']), true); ?> name="options[ga_dash_tableid_jail]">
883
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
884
  <?php
885
+ if ( ! empty( $options['ga_dash_profile_list'] ) ) {
886
+ foreach ( $options['ga_dash_profile_list'] as $items ) {
887
+ if ( $items[3] ) {
888
+ echo '<option value="' . esc_attr( $items[1] ) . '" ' . selected( $items[1], $options['ga_dash_tableid_jail'] );
889
+ echo ' title="' . __( "View Name:", 'ga-dash' ) . ' ' . esc_attr( $items[0] ) . '">' . esc_html( GADWP_Tools::strip_protocol( $items[3] ) ) . ' &#8658; ' . esc_attr( $items[0] ) . '</option>';
890
+ }
891
+ }
892
+ } else {
893
+ echo '<option value="">' . __( "Property not found", 'ga-dash' ) . '</option>';
894
+ }
895
+ ?>
896
+ </select>
897
+ <?php
898
+ if ( count( $options['ga_dash_profile_list'] ) > 1 ) {
899
+ ?>&nbsp;<input type="submit" name="Hide" class="button button-secondary" value="<?php _e( "Lock Selection", 'ga-dash' ); ?>" /><?php
900
+ }
901
+ ?>
902
  </td>
903
  </tr>
904
  <?php
905
+ if ( $options['ga_dash_tableid_jail'] ) {
906
+ ?>
907
  <tr>
908
  <td class="title"></td>
909
  <td><?php
910
+ $profile_info = GADWP_Tools::get_selected_profile( $gadwp->config->options['ga_dash_profile_list'], $gadwp->config->options['ga_dash_tableid_jail'] );
911
+ echo '<pre>' . __( "View Name:", 'ga-dash' ) . "\t" . esc_html( $profile_info[0] ) . "<br />" . __( "Tracking ID:", 'ga-dash' ) . "\t" . esc_html( $profile_info[2] ) . "<br />" . __( "Default URL:", 'ga-dash' ) . "\t" . esc_html( $profile_info[3] ) . "<br />" . __( "Time Zone:", 'ga-dash' ) . "\t" . esc_html( $profile_info[5] ) . '</pre>';
912
+ ?></td>
913
  </tr>
914
  <?php
915
+ }
916
+ ?>
917
+ <tr>
918
  <td class="title"><label for="ga_dash_style"><?php _e("Theme Color:", 'ga-dash' ); ?></label></td>
919
  <td><input type="text" id="ga_dash_style" class="ga_dash_style" name="options[ga_dash_style]" value="<?php echo esc_attr($options['ga_dash_style']); ?>" size="10"></td>
920
  </tr>
926
  </tr>
927
  <tr>
928
  <td colspan="2" class="title">
929
+ <div class="button-primary onoffswitch">
930
  <input type="checkbox" name="options[automatic_updates_minorversion]" value="1" class="onoffswitch-checkbox" id="automatic_updates_minorversion" <?php checked( $options['automatic_updates_minorversion'], 1 ); ?>> <label class="onoffswitch-label" for="automatic_updates_minorversion">
931
  <div class="onoffswitch-inner"></div>
932
  <div class="onoffswitch-switch"></div>
935
  <div class="switch-desc"><?php echo " ".__( "automatic updates for minor versions (security and maintenance releases only)", 'ga-dash' );?></div>
936
  </td>
937
  </tr>
938
+ <tr>
939
  <td colspan="2"><hr></td>
940
+ </tr>
941
  <?php }?>
942
  <tr>
943
  <td colspan="2" class="submit"><input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'ga-dash' ) ?>" /></td>
944
+ </tr>
945
+ <?php } else {?>
946
  <tr>
947
  <td colspan="2"><hr></td>
948
  </tr>
955
  </table>
956
  </form>
957
  <?php
958
+ self::output_sidebar();
959
+ return;
960
+ }
961
+ ?>
962
+ </table>
963
+ </form>
964
+ <?php
965
+ }
966
+ self::output_sidebar();
967
+ }
968
+ // Network Settings
969
+ public static function general_settings_network() {
970
+ $gadwp = GADWP();
971
+ global $wp_version;
972
+
973
+ if ( ! current_user_can( 'manage_network_options' ) ) {
974
+ return;
975
+ }
976
+ $options = self::update_options( 'network' );
977
+ /*
978
+ * Include GAPI
979
+ */
980
+ echo '<div id="gapi-warning" class="updated"><p>' . __( 'Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', "ga-dash" ) . ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=gadwp">Library conflicts between WordPress plugins</a></p></div>';
981
+
982
+ if ( null === $gadwp->gapi_controller ) {
983
+ $gadwp->gapi_controller = new GADWP_GAPI_Controller();
984
+ }
985
+
986
+ echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
987
+ if ( isset( $_POST['ga_dash_code'] ) ) {
988
+ if ( ! stripos( 'x' . $_POST['ga_dash_code'], 'UA-', 1 ) == 1 ) {
989
+ try {
990
+ $gadwp->gapi_controller->client->authenticate( $_POST['ga_dash_code'] );
991
+ $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
992
+ $google_token = json_decode( $gadwp->gapi_controller->client->getAccessToken() );
993
+ $gadwp->config->options['ga_dash_refresh_token'] = $google_token->refresh_token;
994
+ $gadwp->config->options['automatic_updates_minorversion'] = 1;
995
+ $gadwp->config->set_plugin_options( true );
996
+ $options = self::update_options( 'network' );
997
+ $message = "<div class='updated'><p>" . __( "Plugin authorization succeeded.", 'ga-dash' ) . "</p></div>";
998
+ if ( is_multisite() ) { // Cleanup errors on the entire network
999
+ foreach ( wp_get_sites( array(
1000
+ 'limit' => apply_filters( 'gadwp_sites_limit', 100 ) ) ) as $blog ) {
1001
+ switch_to_blog( $blog['blog_id'] );
1002
+ delete_transient( 'ga_dash_gapi_errors' );
1003
+ restore_current_blog();
1004
+ }
1005
+ } else {
1006
+ delete_transient( 'ga_dash_gapi_errors' );
1007
+ }
1008
+ } catch ( Google_IO_Exception $e ) {
1009
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $gadwp->gapi_controller->error_timeout );
1010
+ return false;
1011
+ } catch ( Google_Service_Exception $e ) {
1012
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $gadwp->gapi_controller->error_timeout );
1013
+ set_transient( 'ga_dash_gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout );
1014
+ return $e->getCode();
1015
+ } catch ( Exception $e ) {
1016
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ) . "\nResponseHttpCode:" . $e->getCode(), $gadwp->gapi_controller->error_timeout );
1017
+ $gadwp->gapi_controller->reset_token( false );
1018
+ }
1019
+ } else {
1020
+ $message = "<div class='error'><p>" . __( "The access code is <strong>NOT</strong> your <strong>Tracking ID</strong> (UA-XXXXX-X). Try again, and use the red link to get your access code", 'ga-dash' ) . ".</p></div>";
1021
+ }
1022
+ }
1023
+ if ( isset( $_POST['Refresh'] ) ) {
1024
+ if ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) {
1025
+ $gadwp->config->options['ga_dash_profile_list'] = array();
1026
+ $message = "<div class='updated'><p>" . __( "Properties refreshed.", 'ga-dash' ) . "</p></div>";
1027
+ $options = self::update_options( 'network' );
1028
+ } else {
1029
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
1030
+ }
1031
+ }
1032
+ if ( $gadwp->config->options['ga_dash_token'] && $gadwp->gapi_controller->client->getAccessToken() ) {
1033
+ if ( ! empty( $gadwp->config->options['ga_dash_profile_list'] ) ) {
1034
+ $profiles = $gadwp->config->options['ga_dash_profile_list'];
1035
+ } else {
1036
+ $profiles = $gadwp->gapi_controller->refresh_profiles();
1037
+ }
1038
+ if ( $profiles ) {
1039
+ $gadwp->config->options['ga_dash_profile_list'] = $profiles;
1040
+ if ( isset( $gadwp->config->options['ga_dash_tableid_jail'] ) && ! $gadwp->config->options['ga_dash_tableid_jail'] ) {
1041
+ $profile = GADWP_Tools::guess_default_domain( $profiles );
1042
+ $gadwp->config->options['ga_dash_tableid_jail'] = $profile;
1043
+ $gadwp->config->options['ga_dash_tableid'] = $profile;
1044
+ }
1045
+ $gadwp->config->set_plugin_options( true );
1046
+ $options = self::update_options( 'network' );
1047
+ }
1048
+ }
1049
+ if ( isset( $_POST['Clear'] ) ) {
1050
+ if ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) {
1051
+ GADWP_Tools::clear_cache();
1052
+ $message = "<div class='updated'><p>" . __( "Cleared Cache.", 'ga-dash' ) . "</p></div>";
1053
+ } else {
1054
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
1055
+ }
1056
+ }
1057
+ if ( isset( $_POST['Reset'] ) ) {
1058
+ if ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) {
1059
+ $gadwp->gapi_controller->reset_token( true );
1060
+ GADWP_Tools::clear_cache();
1061
+ $message = "<div class='updated'><p>" . __( "Token Reseted and Revoked.", 'ga-dash' ) . "</p></div>";
1062
+ $options = self::update_options( 'Reset' );
1063
+ } else {
1064
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
1065
+ }
1066
+ }
1067
+ if ( isset( $_POST['options']['ga_dash_hidden'] ) && ! isset( $_POST['Clear'] ) && ! isset( $_POST['Reset'] ) && ! isset( $_POST['Refresh'] ) ) {
1068
+ $message = "<div class='updated'><p>" . __( "Settings saved.", 'ga-dash' ) . "</p></div>";
1069
+ if ( ! ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) ) {
1070
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
1071
+ }
1072
+ }
1073
+ if ( isset( $_POST['Hide'] ) ) {
1074
+ if ( isset( $_POST['gadash_security'] ) && wp_verify_nonce( $_POST['gadash_security'], 'gadash_form' ) ) {
1075
+ $message = "<div class='updated'><p>" . __( "All other domains/properties were removed.", 'ga-dash' ) . "</p></div>";
1076
+ $lock_profile = GADWP_Tools::get_selected_profile( $gadwp->config->options['ga_dash_profile_list'], $gadwp->config->options['ga_dash_tableid_jail'] );
1077
+ $gadwp->config->options['ga_dash_profile_list'] = array(
1078
+ $lock_profile );
1079
+ $options = self::update_options( 'network' );
1080
+ } else {
1081
+ $message = "<div class='error'><p>" . __( "Cheating Huh?", 'ga-dash' ) . "</p></div>";
1082
+ }
1083
+ }
1084
+ ?>
 
1085
  <div class="wrap">
1086
  <?php echo "<h2>" . __( "Google Analytics Settings", 'ga-dash' ) . "</h2>"; ?><hr>
1087
  </div>
1089
  <div id="post-body" class="metabox-holder columns-2">
1090
  <div id="post-body-content">
1091
  <div class="settings-wrapper">
1092
+ <div class="inside">
1093
+ <?php
1094
+ if ( $gadwp->gapi_controller->gapi_errors_handler() ) {
1095
+ $message = sprintf( '<div class="error"><p>%s</p></div>', sprintf( __( 'Something went wrong, check %1$s or %2$s.', 'ga-dash' ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_errors_debugging', false ), __( 'Errors & Debug', 'ga-dash' ) ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'gadash_settings', false ), __( 'authorize the plugin', 'ga-dash' ) ) ) );
1096
+ }
1097
+ if ( isset( $_POST['Authorize'] ) ) {
1098
+ GADWP_Tools::clear_cache();
1099
+ $gadwp->gapi_controller->token_request();
1100
+ echo "<div class='updated'><p>" . __( "Use the red link (see below) to generate and get your access code!", 'ga-dash' ) . "</p></div>";
1101
+ } else {
1102
+ if ( isset( $message ) )
1103
+ echo $message;
1104
+ ?>
1105
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
1106
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
1107
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
1111
  </tr>
1112
  <tr>
1113
  <td colspan="2" class="title">
1114
+ <div class="button-primary onoffswitch">
1115
  <input type="checkbox" name="options[ga_dash_network]" value="1" class="onoffswitch-checkbox" id="ga_dash_network" <?php checked( $options['ga_dash_network'], 1); ?> onchange="this.form.submit()"> <label class="onoffswitch-label" for="ga_dash_network">
1116
  <div class="onoffswitch-inner"></div>
1117
  <div class="onoffswitch-switch"></div>
1133
  </td>
1134
  </tr>
1135
  <?php
1136
+ if ( ! $options['ga_dash_token'] || $options['ga_dash_userapi'] ) {
1137
+ ?>
1138
  <tr>
1139
  <td colspan="2" class="info"><input name="options[ga_dash_userapi]" type="checkbox" id="ga_dash_userapi" value="1" <?php checked( $options['ga_dash_userapi'], 1 ); ?> onchange="this.form.submit()" /><?php echo " ".__("use your own API Project credentials", 'ga-dash' );?>
1140
  </td>
1141
+ </tr>
1142
+ <?php
1143
+ }
1144
+ if ( $options['ga_dash_userapi'] ) {
1145
+ ?>
1146
  <tr>
1147
  <td class="title"><label for="options[ga_dash_apikey]"><?php _e("API Key:", 'ga-dash'); ?></label></td>
1148
  <td><input type="text" name="options[ga_dash_apikey]" value="<?php echo esc_attr($options['ga_dash_apikey']); ?>" size="40" required="required"></td>
1158
  </td>
1159
  </tr>
1160
  <?php
1161
+ }
1162
+ if ( $options['ga_dash_token'] ) {
1163
+ ?>
1164
  <tr>
1165
  <td colspan="2"><input type="submit" name="Reset" class="button button-secondary" value="<?php _e( "Clear Authorization", 'ga-dash' ); ?>" /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e( "Clear Cache", 'ga-dash' ); ?>" /> <input type="submit" name="Refresh" class="button button-secondary" value="<?php _e( "Refresh Properties", 'ga-dash' ); ?>" /></td>
1166
  </tr>
1171
  <td colspan="2"><?php echo "<h2>" . __( "Properties/Views Settings", 'ga-dash' ) . "</h2>"; ?></td>
1172
  </tr>
1173
  <?php
1174
+ if ( isset( $options['ga_dash_tableid_network'] ) ) {
1175
+ $options['ga_dash_tableid_network'] = json_decode( json_encode( $options['ga_dash_tableid_network'] ), false );
1176
+ }
1177
+ foreach ( wp_get_sites( array(
1178
+ 'limit' => apply_filters( 'gadwp_sites_limit', 100 ) ) ) as $blog ) {
1179
+ ?>
 
1180
  <tr>
1181
  <td class="title-select"><label for="ga_dash_tableid_network"><?php echo '<strong>'.$blog['domain'].$blog['path'].'</strong>: ';?></label></td>
1182
  <td><select id="ga_dash_tableid_network" <?php disabled(!empty($options['ga_dash_profile_list']),false);?> name="options[ga_dash_tableid_network][<?php echo $blog['blog_id'];?>]">
1183
  <?php
1184
+ if ( ! empty( $options['ga_dash_profile_list'] ) ) {
1185
+ foreach ( $options['ga_dash_profile_list'] as $items ) {
1186
+ if ( $items[3] ) {
1187
+ echo '<option value="' . esc_attr( $items[1] ) . '" ' . selected( $items[1], isset( $options['ga_dash_tableid_network']->$blog['blog_id'] ) ? $options['ga_dash_tableid_network']->$blog['blog_id'] : '' );
1188
+ echo ' title="' . __( "View Name:", 'ga-dash' ) . ' ' . esc_attr( $items[0] ) . '">' . esc_html( GADWP_Tools::strip_protocol( $items[3] ) ) . ' &#8658; ' . esc_attr( $items[0] ) . '</option>';
1189
+ }
1190
+ }
1191
+ } else {
1192
+ echo '<option value="">' . __( "Property not found", 'ga-dash' ) . '</option>';
1193
+ }
1194
+ ?>
1195
  </select> <br /></td>
1196
  </tr>
1197
  <?php
1198
+ }
1199
+ ?>
1200
  <tr>
1201
  <td colspan="2"><?php echo "<h2>" . __( "Automatic Updates", 'ga-dash' ) . "</h2>"; ?></td>
1202
  </tr>
1203
  <tr>
1204
  <td colspan="2" class="title">
1205
+ <div class="button-primary onoffswitch">
1206
  <input type="checkbox" name="options[automatic_updates_minorversion]" value="1" class="onoffswitch-checkbox" id="automatic_updates_minorversion" <?php checked( $options['automatic_updates_minorversion'], 1 ); ?>> <label class="onoffswitch-label" for="automatic_updates_minorversion">
1207
  <div class="onoffswitch-inner"></div>
1208
  <div class="onoffswitch-switch"></div>
1216
  </tr>
1217
  <tr>
1218
  <td colspan="2" class="title">
1219
+ <div class="button-primary onoffswitch">
1220
  <input type="checkbox" name="options[ga_dash_excludesa]" value="1" class="onoffswitch-checkbox" id="ga_dash_excludesa"<?php checked( $options['ga_dash_excludesa'], 1); ?>"> <label class="onoffswitch-label" for="ga_dash_excludesa">
1221
  <div class="onoffswitch-inner"></div>
1222
  <div class="onoffswitch-switch"></div>
1230
  </tr>
1231
  <tr>
1232
  <td colspan="2" class="submit"><input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'ga-dash' ) ?>" /></td>
1233
+ </tr>
1234
+ <?php
1235
+ } else {
1236
+ ?>
1237
+ <tr>
1238
  <td colspan="2"><hr></td>
1239
  </tr>
1240
  <tr>
1247
  </table>
1248
  </form>
1249
  <?php
1250
+ self::output_sidebar();
1251
+ return;
1252
+ }
1253
+ ?>
1254
  </table>
1255
  </form>
1256
  <?php
1257
+ }
1258
+ self::output_sidebar();
1259
+ }
1260
 
1261
+ public static function output_sidebar() {
1262
+ $gadwp = GADWP();
1263
+ ?>
 
1264
  </div>
1265
  </div>
1266
  </div>
1276
  </div>
1277
  <div class="postbox">
1278
  <h3>
1279
+ <span><?php _e("Follow & Review",'ga-dash')?></span>
1280
  </h3>
1281
  <div class="inside">
1282
+ <div class="gadash-desc">
1283
+ <div style="margin-left:-10px;">
1284
+ <div class="g-page" data-width="273" data-href="//plus.google.com/+Deconfcom" data-layout="landscape" data-showtagline="false" data-showcoverphoto="false" data-rel="publisher"></div>
1285
+ </div>
1286
+
1287
+ <script type="text/javascript">
1288
+ (function() {
1289
+ var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
1290
+ po.src = 'https://apis.google.com/js/platform.js';
1291
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
1292
+ })();
1293
+ </script>
1294
  </div>
1295
+ <br />
1296
  <div class="gadash-desc">
1297
+ <a href="https://twitter.com/deconfcom" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @deconfcom</a>
1298
+ <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
1299
  </div>
1300
  <br />
1301
  <div class="gadash-title">
admin/setup.php CHANGED
@@ -7,266 +7,205 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
 
13
- if (! class_exists('GADWP_Backend_Setup')) {
14
 
15
- final class GADWP_Backend_Setup
16
- {
17
 
18
- private $gadwp;
19
 
20
- public function __construct()
21
- {
22
- $this->gadwp = GADWP();
23
-
24
- // Styles & Scripts
25
- add_action('admin_enqueue_scripts', array(
26
- $this,
27
- 'load_styles_scripts'
28
- ));
29
- // Site Menu
30
- add_action('admin_menu', array(
31
- $this,
32
- 'site_menu'
33
- ));
34
- // Network Menu
35
- add_action('network_admin_menu', array(
36
- $this,
37
- 'network_menu'
38
- ));
39
- // Settings link
40
- add_filter("plugin_action_links_" . plugin_basename(GADWP_DIR . 'gadwp.php'), array(
41
- $this,
42
- 'settings_link'
43
- ));
44
- // Error bubble
45
- add_action('admin_print_scripts', array(
46
- $this,
47
- 'draw_error_bubble'
48
- ), 10000);
49
- }
50
 
51
- /**
52
- * Error bubble for Errors & Debug
53
- */
54
- public function draw_error_bubble()
55
- {
56
- $bubble_msg = '!';
57
- if (get_transient('ga_dash_gapi_errors')) {
58
- ?>
 
 
 
 
 
 
 
 
 
 
 
59
  <script type="text/javascript">
60
  jQuery(document).ready(function() {
61
  jQuery('#toplevel_page_gadash_settings li > a[href*="page=gadash_errors_debugging"]').append('&nbsp;<span class="awaiting-mod count-1"><span class="pending-count" style="padding:0 7px;"><?php echo $bubble_msg ?></span></span>');
62
  });
63
  </script>
64
  <?php
65
- }
66
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- /**
69
- * Add Site Menu
70
- */
71
- public function site_menu()
72
- {
73
- global $wp_version;
74
- if (current_user_can('manage_options')) {
75
- include (GADWP_DIR . 'admin/settings.php');
76
- add_menu_page(__("Google Analytics", 'ga-dash'), 'Google Analytics', 'manage_options', 'gadash_settings', array(
77
- 'GADWP_Settings',
78
- 'general_settings'
79
- ), version_compare($wp_version, '3.8.0', '>=') ? 'dashicons-chart-area' : GADWP_URL . 'admin/images/gadash-icon.png');
80
- add_submenu_page('gadash_settings', __("General Settings", 'ga-dash'), __("General Settings", 'ga-dash'), 'manage_options', 'gadash_settings', array(
81
- 'GADWP_Settings',
82
- 'general_settings'
83
- ));
84
- add_submenu_page('gadash_settings', __("Backend Settings", 'ga-dash'), __("Backend Settings", 'ga-dash'), 'manage_options', 'gadash_backend_settings', array(
85
- 'GADWP_Settings',
86
- 'backend_settings'
87
- ));
88
- add_submenu_page('gadash_settings', __("Frontend Settings", 'ga-dash'), __("Frontend Settings", 'ga-dash'), 'manage_options', 'gadash_frontend_settings', array(
89
- 'GADWP_Settings',
90
- 'frontend_settings'
91
- ));
92
- add_submenu_page('gadash_settings', __("Tracking Code", 'ga-dash'), __("Tracking Code", 'ga-dash'), 'manage_options', 'gadash_tracking_settings', array(
93
- 'GADWP_Settings',
94
- 'tracking_settings'
95
- ));
96
- add_submenu_page('gadash_settings', __("Errors & Debug", 'ga-dash'), __("Errors & Debug", 'ga-dash'), 'manage_options', 'gadash_errors_debugging', array(
97
- 'GADWP_Settings',
98
- 'errors_debugging'
99
- ));
100
- }
101
- }
 
 
 
 
 
 
 
 
102
 
103
- /**
104
- * Add Network Menu
105
- */
106
- public function network_menu()
107
- {
108
- global $wp_version;
109
- if (current_user_can('manage_netwrok')) {
110
- include (GADWP_DIR . 'admin/settings.php');
111
- add_menu_page(__("Google Analytics", 'ga-dash'), "Google Analytics", 'manage_netwrok', 'gadash_settings', array(
112
- 'GADWP_Settings',
113
- 'general_settings_network'
114
- ), version_compare($wp_version, '3.8.0', '>=') ? 'dashicons-chart-area' : GADWP_URL . 'admin/images/gadash-icon.png');
115
- add_submenu_page('gadash_settings', __("General Settings", 'ga-dash'), __("General Settings", 'ga-dash'), 'manage_netwrok', 'gadash_settings', array(
116
- 'GADWP_Settings',
117
- 'general_settings_network'
118
- ));
119
- add_submenu_page('gadash_settings', __("Errors & Debug", 'ga-dash'), __("Errors & Debug", 'ga-dash'), 'manage_network', 'gadash_errors_debugging', array(
120
- 'GADWP_Settings',
121
- 'errors_debugging'
122
- ));
123
- }
124
- }
125
 
126
- /**
127
- * Styles & Scripts conditional loading (based on current URI)
128
- *
129
- * @param
130
- * $hook
131
- */
132
- public function load_styles_scripts($hook)
133
- {
134
-
135
- /*
136
- * GADWP main stylesheet
137
- */
138
- wp_enqueue_style('gadwp', GADWP_URL . 'admin/css/gadwp.css', null, GADWP_CURRENT_VERSION);
139
-
140
- /*
141
- * Dashboard Widgets Styles & Scripts
142
- */
143
- $widgets_hooks = array(
144
- 'index.php'
145
- );
146
- if (in_array($hook, $widgets_hooks)) {
147
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && $this->gadwp->config->options['dashboard_widget']) {
148
- wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION);
149
- wp_enqueue_script('gadwp-admin-widgets', plugins_url('js/widgets.js', __FILE__), array(
150
- 'jquery'
151
- ), GADWP_CURRENT_VERSION);
152
- if (! wp_script_is('googlejsapi')) {
153
- wp_register_script('googlejsapi', 'https://www.google.com/jsapi');
154
- wp_enqueue_script('googlejsapi');
155
- }
156
- wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array(
157
- 'jquery'
158
- ), GADWP_CURRENT_VERSION);
159
- }
160
- }
161
-
162
- /*
163
- * Posts/Pages List Styles & Scripts
164
- */
165
- $contentstats_hooks = array(
166
- 'edit.php'
167
- );
168
- if (in_array($hook, $contentstats_hooks)) {
169
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && $this->gadwp->config->options['item_reports']) {
170
- wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION);
171
- wp_enqueue_style('gadwp_itemreports', GADWP_URL . 'admin/css/item-reports.css', null, GADWP_CURRENT_VERSION);
172
- $country_codes = GADWP_Tools::get_countrycodes();
173
- if ($this->gadwp->config->options['ga_target_geomap'] && isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) {
174
- $region = $this->gadwp->config->options['ga_target_geomap'];
175
- } else {
176
- $region = false;
177
- }
178
- wp_enqueue_style("wp-jquery-ui-dialog");
179
- if (! wp_script_is('googlejsapi')) {
180
- wp_register_script('googlejsapi', 'https://www.google.com/jsapi');
181
- }
182
- wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array(
183
- 'jquery'
184
- ), GADWP_CURRENT_VERSION);
185
- wp_enqueue_script('gadwp_itemreports', plugins_url('js/item-reports.js', __FILE__), array(
186
- 'gadwp-nprogress',
187
- 'googlejsapi',
188
- 'jquery',
189
- 'jquery-ui-dialog'
190
- ), GADWP_CURRENT_VERSION);
191
- wp_localize_script('gadwp_itemreports', 'gadwp_item_data', array(
192
- 'ajaxurl' => admin_url('admin-ajax.php'),
193
- 'security' => wp_create_nonce('gadwp_get_itemreports'),
194
- 'dateList' => array(
195
- 'today' => __("Today", 'ga-dash'),
196
- 'yesterday' => __("Yesterday", 'ga-dash'),
197
- '7daysAgo' => __("Last 7 Days", 'ga-dash'),
198
- '30daysAgo' => __("Last 30 Days", 'ga-dash'),
199
- '90daysAgo' => __("Last 90 Days", 'ga-dash')
200
- ),
201
- 'reportList' => array(
202
- 'uniquePageviews' => __("Unique Views", 'ga-dash'),
203
- 'users' => __("Users", 'ga-dash'),
204
- 'organicSearches' => __("Organic", 'ga-dash'),
205
- 'pageviews' => __("Page Views", 'ga-dash'),
206
- 'visitBounceRate' => __("Bounce Rate", 'ga-dash'),
207
- 'locations' => __("Location", 'ga-dash'),
208
- 'referrers' => __("Referrers", 'ga-dash'),
209
- 'searches' => __("Searches", 'ga-dash'),
210
- 'trafficdetails' => __("Traffic Details", 'ga-dash')
211
- ),
212
- 'i18n' => array(
213
- __("A JavaScript Error is blocking plugin resources!", 'ga-dash'),
214
- __("Traffic Mediums", 'ga-dash'),
215
- __("Visitor Type", 'ga-dash'),
216
- __("Social Networks", 'ga-dash'),
217
- __("Search Engines", 'ga-dash'),
218
- __("Unique Views", 'ga-dash'),
219
- __("Users", 'ga-dash'),
220
- __("Page Views", 'ga-dash'),
221
- __("Bounce Rate", 'ga-dash'),
222
- __("Organic Search", 'ga-dash'),
223
- __("Pages/Session", 'ga-dash'),
224
- __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'),
225
- __("Not enough data collected", 'ga-dash'),
226
- __("This report is unavailable", 'ga-dash'),
227
- __("report generated by", 'ga-dash')
228
- ),
229
- 'colorVariations' => GADWP_Tools::variations($this->gadwp->config->options['ga_dash_style']),
230
- 'region' => $region
231
- ));
232
- }
233
- }
234
-
235
- /*
236
- * Settings Styles & Scripts
237
- */
238
- $settings_hooks = array(
239
- 'toplevel_page_gadash_settings',
240
- 'google-analytics_page_gadash_backend_settings',
241
- 'google-analytics_page_gadash_frontend_settings',
242
- 'google-analytics_page_gadash_tracking_settings',
243
- 'google-analytics_page_gadash_errors_debugging'
244
- );
245
-
246
- if (in_array($hook, $settings_hooks)) {
247
- wp_enqueue_style('wp-color-picker');
248
- wp_enqueue_script('wp-color-picker');
249
- wp_enqueue_script('wp-color-picker-script-handle', plugins_url('js/wp-color-picker-script.js', __FILE__), array(
250
- 'wp-color-picker'
251
- ), false, true);
252
- wp_enqueue_script('gadwp-settings', plugins_url('js/settings.js', __FILE__), array(
253
- 'jquery'
254
- ), GADWP_CURRENT_VERSION);
255
- }
256
- }
257
 
258
- /**
259
- * Add "Settings" link in Plugins List
260
- *
261
- * @param
262
- * $links
263
- * @return array
264
- */
265
- public function settings_link($links)
266
- {
267
- $settings_link = '<a href="' . esc_url(get_admin_url(null, 'admin.php?page=gadash_settings')). '">' . __("Settings", 'ga-dash') . '</a>';
268
- array_unshift($links, $settings_link);
269
- return $links;
270
- }
271
- }
272
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
 
13
+ if ( ! class_exists( 'GADWP_Backend_Setup' ) ) {
14
 
15
+ final class GADWP_Backend_Setup {
 
16
 
17
+ private $gadwp;
18
 
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ // Styles & Scripts
23
+ add_action( 'admin_enqueue_scripts', array( $this, 'load_styles_scripts' ) );
24
+ // Site Menu
25
+ add_action( 'admin_menu', array( $this, 'site_menu' ) );
26
+ // Network Menu
27
+ add_action( 'network_admin_menu', array( $this, 'network_menu' ) );
28
+ // Settings link
29
+ add_filter( "plugin_action_links_" . plugin_basename( GADWP_DIR . 'gadwp.php' ), array( $this, 'settings_link' ) );
30
+ // Error bubble
31
+ add_action( 'admin_print_scripts', array( $this, 'draw_error_bubble' ), 10000 );
32
+ }
33
+
34
+ /**
35
+ * Error bubble for Errors & Debug
36
+ */
37
+ public function draw_error_bubble() {
38
+ $bubble_msg = '!';
39
+ if ( get_transient( 'ga_dash_gapi_errors' ) ) {
40
+ ?>
41
  <script type="text/javascript">
42
  jQuery(document).ready(function() {
43
  jQuery('#toplevel_page_gadash_settings li > a[href*="page=gadash_errors_debugging"]').append('&nbsp;<span class="awaiting-mod count-1"><span class="pending-count" style="padding:0 7px;"><?php echo $bubble_msg ?></span></span>');
44
  });
45
  </script>
46
  <?php
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Add Site Menu
52
+ */
53
+ public function site_menu() {
54
+ global $wp_version;
55
+ if ( current_user_can( 'manage_options' ) ) {
56
+ include ( GADWP_DIR . 'admin/settings.php' );
57
+ add_menu_page( __( "Google Analytics", 'ga-dash' ), 'Google Analytics', 'manage_options', 'gadash_settings', array( 'GADWP_Settings', 'general_settings' ), version_compare( $wp_version, '3.8.0', '>=' ) ? 'dashicons-chart-area' : GADWP_URL . 'admin/images/gadash-icon.png' );
58
+ add_submenu_page( 'gadash_settings', __( "General Settings", 'ga-dash' ), __( "General Settings", 'ga-dash' ), 'manage_options', 'gadash_settings', array( 'GADWP_Settings', 'general_settings' ) );
59
+ add_submenu_page( 'gadash_settings', __( "Backend Settings", 'ga-dash' ), __( "Backend Settings", 'ga-dash' ), 'manage_options', 'gadash_backend_settings', array( 'GADWP_Settings', 'backend_settings' ) );
60
+ add_submenu_page( 'gadash_settings', __( "Frontend Settings", 'ga-dash' ), __( "Frontend Settings", 'ga-dash' ), 'manage_options', 'gadash_frontend_settings', array( 'GADWP_Settings', 'frontend_settings' ) );
61
+ add_submenu_page( 'gadash_settings', __( "Tracking Code", 'ga-dash' ), __( "Tracking Code", 'ga-dash' ), 'manage_options', 'gadash_tracking_settings', array( 'GADWP_Settings', 'tracking_settings' ) );
62
+ add_submenu_page( 'gadash_settings', __( "Errors & Debug", 'ga-dash' ), __( "Errors & Debug", 'ga-dash' ), 'manage_options', 'gadash_errors_debugging', array( 'GADWP_Settings', 'errors_debugging' ) );
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Add Network Menu
68
+ */
69
+ public function network_menu() {
70
+ global $wp_version;
71
+ if ( current_user_can( 'manage_netwrok' ) ) {
72
+ include ( GADWP_DIR . 'admin/settings.php' );
73
+ add_menu_page( __( "Google Analytics", 'ga-dash' ), "Google Analytics", 'manage_netwrok', 'gadash_settings', array( 'GADWP_Settings', 'general_settings_network' ), version_compare( $wp_version, '3.8.0', '>=' ) ? 'dashicons-chart-area' : GADWP_URL . 'admin/images/gadash-icon.png' );
74
+ add_submenu_page( 'gadash_settings', __( "General Settings", 'ga-dash' ), __( "General Settings", 'ga-dash' ), 'manage_netwrok', 'gadash_settings', array( 'GADWP_Settings', 'general_settings_network' ) );
75
+ add_submenu_page( 'gadash_settings', __( "Errors & Debug", 'ga-dash' ), __( "Errors & Debug", 'ga-dash' ), 'manage_network', 'gadash_errors_debugging', array( 'GADWP_Settings', 'errors_debugging' ) );
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Styles & Scripts conditional loading (based on current URI)
81
+ *
82
+ * @param
83
+ * $hook
84
+ */
85
+ public function load_styles_scripts( $hook ) {
86
+
87
+ /*
88
+ * GADWP main stylesheet
89
+ */
90
+ wp_enqueue_style( 'gadwp', GADWP_URL . 'admin/css/gadwp.css', null, GADWP_CURRENT_VERSION );
91
+
92
+ /*
93
+ * Dashboard Widgets Styles & Scripts
94
+ */
95
+ $widgets_hooks = array( 'index.php' );
96
+
97
+ if ( in_array( $hook, $widgets_hooks ) ) {
98
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) && $this->gadwp->config->options['dashboard_widget'] ) {
99
+
100
+ wp_enqueue_style( 'gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION );
101
+
102
+ wp_enqueue_script( 'gadwp-admin-widgets', plugins_url( 'js/widgets.js', __FILE__ ), array( 'jquery' ), GADWP_CURRENT_VERSION );
103
+
104
+ if ( ! wp_script_is( 'googlejsapi' ) ) {
105
+ wp_register_script( 'googlejsapi', 'https://www.google.com/jsapi' );
106
+ wp_enqueue_script( 'googlejsapi' );
107
+ }
108
+
109
+ wp_enqueue_script( 'gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array( 'jquery' ), GADWP_CURRENT_VERSION );
110
+ }
111
+ }
112
+
113
+ /*
114
+ * Posts/Pages List Styles & Scripts
115
+ */
116
+ $contentstats_hooks = array( 'edit.php' );
117
+ if ( in_array( $hook, $contentstats_hooks ) ) {
118
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) && $this->gadwp->config->options['backend_item_reports'] ) {
119
+
120
+ wp_enqueue_style( 'gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION );
121
+
122
+ wp_enqueue_style( 'gadwp_backend_item_reports', GADWP_URL . 'admin/css/item-reports.css', null, GADWP_CURRENT_VERSION );
123
+
124
+ $country_codes = GADWP_Tools::get_countrycodes();
125
+
126
+ if ( $this->gadwp->config->options['ga_target_geomap'] && isset( $country_codes[$this->gadwp->config->options['ga_target_geomap']] ) ) {
127
+ $region = $this->gadwp->config->options['ga_target_geomap'];
128
+ } else {
129
+ $region = false;
130
+ }
131
+
132
+ wp_enqueue_style( "wp-jquery-ui-dialog" );
133
+
134
+ if ( ! wp_script_is( 'googlejsapi' ) ) {
135
+ wp_register_script( 'googlejsapi', 'https://www.google.com/jsapi' );
136
+ }
137
+
138
+ wp_enqueue_script( 'gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array( 'jquery' ), GADWP_CURRENT_VERSION );
139
+
140
+ wp_enqueue_script( 'gadwp_backend_item_reports', plugins_url( 'js/item-reports.js', __FILE__ ), array( 'gadwp-nprogress', 'googlejsapi', 'jquery', 'jquery-ui-dialog' ), GADWP_CURRENT_VERSION );
141
 
142
+ /* @formatter:off */
143
+ wp_localize_script( 'gadwp_backend_item_reports', 'gadwp_item_data', array(
144
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
145
+ 'security' => wp_create_nonce( 'gadwp_backend_item_reports' ),
146
+ 'dateList' => array(
147
+ 'today' => __( "Today", 'ga-dash' ),
148
+ 'yesterday' => __( "Yesterday", 'ga-dash' ),
149
+ '7daysAgo' => __( "Last 7 Days", 'ga-dash' ),
150
+ '30daysAgo' => __( "Last 30 Days", 'ga-dash' ),
151
+ '90daysAgo' => __( "Last 90 Days", 'ga-dash' ) ),
152
+ 'reportList' => array(
153
+ 'uniquePageviews' => __( "Unique Views", 'ga-dash' ),
154
+ 'users' => __( "Users", 'ga-dash' ),
155
+ 'organicSearches' => __( "Organic", 'ga-dash' ),
156
+ 'pageviews' => __( "Page Views", 'ga-dash' ),
157
+ 'visitBounceRate' => __( "Bounce Rate", 'ga-dash' ),
158
+ 'locations' => __( "Location", 'ga-dash' ),
159
+ 'referrers' => __( "Referrers", 'ga-dash' ),
160
+ 'searches' => __( "Searches", 'ga-dash' ),
161
+ 'trafficdetails' => __( "Traffic Details", 'ga-dash' ) ),
162
+ 'i18n' => array(
163
+ __( "A JavaScript Error is blocking plugin resources!", 'ga-dash' ),
164
+ __( "Traffic Mediums", 'ga-dash' ),
165
+ __( "Visitor Type", 'ga-dash' ),
166
+ __( "Social Networks", 'ga-dash' ),
167
+ __( "Search Engines", 'ga-dash' ),
168
+ __( "Unique Views", 'ga-dash' ),
169
+ __( "Users", 'ga-dash' ),
170
+ __( "Page Views", 'ga-dash' ),
171
+ __( "Bounce Rate", 'ga-dash' ),
172
+ __( "Organic Search", 'ga-dash' ),
173
+ __( "Pages/Session", 'ga-dash' ),
174
+ __( "Invalid response, more details in JavaScript Console (F12).", 'ga-dash' ),
175
+ __( "Not enough data collected", 'ga-dash' ),
176
+ __( "This report is unavailable", 'ga-dash' ),
177
+ __( "report generated by", 'ga-dash' ) ),
178
+ 'colorVariations' => GADWP_Tools::variations( $this->gadwp->config->options['ga_dash_style'] ),
179
+ 'region' => $region )
180
+ );
181
+ /* @formatter:on */
182
+ }
183
+ }
184
 
185
+ /*
186
+ * Settings Styles & Scripts
187
+ */
188
+ $settings_hooks = array( 'toplevel_page_gadash_settings', 'google-analytics_page_gadash_backend_settings', 'google-analytics_page_gadash_frontend_settings', 'google-analytics_page_gadash_tracking_settings', 'google-analytics_page_gadash_errors_debugging' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
 
190
+ if ( in_array( $hook, $settings_hooks ) ) {
191
+ wp_enqueue_style( 'wp-color-picker' );
192
+ wp_enqueue_script( 'wp-color-picker' );
193
+ wp_enqueue_script( 'wp-color-picker-script-handle', plugins_url( 'js/wp-color-picker-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
194
+ wp_enqueue_script( 'gadwp-settings', plugins_url( 'js/settings.js', __FILE__ ), array( 'jquery' ), GADWP_CURRENT_VERSION );
195
+ }
196
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
 
198
+ /**
199
+ * Add "Settings" link in Plugins List
200
+ *
201
+ * @param
202
+ * $links
203
+ * @return array
204
+ */
205
+ public function settings_link( $links ) {
206
+ $settings_link = '<a href="' . esc_url( get_admin_url( null, 'admin.php?page=gadash_settings' ) ) . '">' . __( "Settings", 'ga-dash' ) . '</a>';
207
+ array_unshift( $links, $settings_link );
208
+ return $links;
209
+ }
210
+ }
 
211
  }
admin/widgets.php CHANGED
@@ -7,119 +7,113 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
-
13
- if (! class_exists('GADWP_Backend_Widgets')) {
14
-
15
- class GADWP_Backend_Widgets
16
- {
17
-
18
- private $gawp;
19
-
20
- public function __construct()
21
- {
22
- $this->gadwp = GADWP();
23
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && (1 == $this->gadwp->config->options['dashboard_widget'])) {
24
- add_action('wp_dashboard_setup', array(
25
- $this,
26
- 'add_widget'
27
- ));
28
- }
29
- }
30
-
31
- public function add_widget()
32
- {
33
- wp_add_dashboard_widget('gadash-widget', __("Google Analytics Dashboard", 'ga-dash'), array(
34
- $this,
35
- 'dashboard_widget'
36
- ), $control_callback = null);
37
- }
38
-
39
- public function dashboard_widget()
40
- {
41
- if (empty($this->gadwp->config->options['ga_dash_token'])) {
42
- echo '<p>' . __("This plugin needs an authorization:", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Authorize Plugin", 'ga-dash'), 'secondary') . '</form>';
43
- return;
44
- }
45
-
46
- if (current_user_can('manage_options')) {
47
- if (isset($_REQUEST['ga_dash_profile_select'])) {
48
- $this->gadwp->config->options['ga_dash_tableid'] = $_REQUEST['ga_dash_profile_select'];
49
- }
50
- $profiles = $this->gadwp->config->options['ga_dash_profile_list'];
51
- $profile_switch = '';
52
- if (!empty($profiles)) {
53
- if (! $this->gadwp->config->options['ga_dash_tableid']) {
54
- if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
55
- $this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail'];
56
- } else {
57
- $this->gadwp->config->options['ga_dash_tableid'] = GADWP_Tools::guess_default_domain($profiles);
58
- }
59
- } else
60
- if ($this->gadwp->config->options['switch_profile'] == 0 && $this->gadwp->config->options['ga_dash_tableid_jail']) {
61
- $this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail'];
62
- }
63
- $profile_switch .= '<select id="ga_dash_profile_select" name="ga_dash_profile_select" onchange="this.form.submit()">';
64
- foreach ($profiles as $profile) {
65
- if (! $this->gadwp->config->options['ga_dash_tableid']) {
66
- $this->gadwp->config->options['ga_dash_tableid'] = $profile[1];
67
- }
68
- if (isset($profile[3])) {
69
- $profile_switch .= '<option value="' . esc_attr($profile[1]) . '" ';
70
- $profile_switch .= selected($profile[1], $this->gadwp->config->options['ga_dash_tableid'], false);
71
- $profile_switch .= ' title="' . __("View Name:", 'ga-dash') . ' ' . esc_attr($profile[0]) . '">' . esc_attr(GADWP_Tools::strip_protocol($profile[3])) . '</option>';
72
- }
73
- }
74
- $profile_switch .= "</select>";
75
- } else {
76
- echo '<p>' . __("Something went wrong while retrieving profiles list.", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("More details", 'ga-dash'), 'secondary') . '</form>';
77
- return;
78
- }
79
- }
80
- $this->gadwp->config->set_plugin_options();
81
- ?>
82
  <form id="ga-dash" method="POST">
83
  <?php
84
- if (current_user_can('manage_options')) {
85
- if ($this->gadwp->config->options['switch_profile'] == 0) {
86
- if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
87
- $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
88
- } else {
89
- echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'ga-dash'), 'secondary') . '</form>';
90
- return;
91
- }
92
- } else {
93
- echo $profile_switch;
94
- $projectId = $this->gadwp->config->options['ga_dash_tableid'];
95
- }
96
- } else {
97
- if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
98
- $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
99
- } else {
100
- echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'ga-dash') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'ga-dash'), 'secondary') . '</form>';
101
- return;
102
- }
103
- }
104
- if (! ($projectId)) {
105
- echo '<p>' . __("Something went wrong while retrieving property data. You need to create and properly configure a Google Analytics account:", 'ga-dash') . '</p> <form action="https://deconf.com/how-to-set-up-google-analytics-on-your-website/" method="POST">' . get_submit_button(__("Find out more!", 'ga-dash'), 'secondary') . '</form>';
106
- return;
107
- }
108
- if (isset($_REQUEST['query'])) {
109
- $query = $_REQUEST['query'];
110
- $this->gadwp->config->options['ga_dash_default_metric'] = $query;
111
- $this->gadwp->config->set_plugin_options();
112
- } else {
113
- $query = isset($this->gadwp->config->options['ga_dash_default_metric']) ? $this->gadwp->config->options['ga_dash_default_metric'] : 'sessions';
114
- }
115
- if (isset($_REQUEST['period'])) {
116
- $period = $_REQUEST['period'];
117
- $this->gadwp->config->options['ga_dash_default_dimension'] = $period;
118
- $this->gadwp->config->set_plugin_options();
119
- } else {
120
- $period = isset($this->gadwp->config->options['ga_dash_default_dimension']) ? $this->gadwp->config->options['ga_dash_default_dimension'] : '30daysAgo';
121
- }
122
- ?>
123
 
124
  <select id="ga_dash_period" name="period" onchange="this.form.submit()">
125
  <option value="realtime" <?php selected ( "realtime", $period, true ); ?>><?php _e("Real-Time",'ga-dash'); ?></option>
@@ -147,81 +141,81 @@ if (! class_exists('GADWP_Backend_Widgets')) {
147
  </form>
148
  <div id="gadash-progressbar"></div>
149
  <?php
150
- switch ($period) {
151
- case 'today':
152
- $from = 'today';
153
- $to = 'today';
154
- $haxis = 4;
155
- break;
156
- case 'yesterday':
157
- $from = 'yesterday';
158
- $to = 'yesterday';
159
- $haxis = 4;
160
- break;
161
- case '7daysAgo':
162
- $from = '7daysAgo';
163
- $to = 'yesterday';
164
- $haxis = 2;
165
- break;
166
- case '14daysAgo':
167
- $from = '14daysAgo';
168
- $to = 'yesterday';
169
- $haxis = 3;
170
- break;
171
- case '30daysAgo':
172
- $from = '30daysAgo';
173
- $to = 'yesterday';
174
- $haxis = 5;
175
- break;
176
- default:
177
- $from = '90daysAgo';
178
- $to = 'yesterday';
179
- $haxis = 16;
180
- break;
181
- }
182
- if ($query == 'visitBounceRate') {
183
- $formater = "var formatter = new google.visualization.NumberFormat({
184
- pattern: '#,##%',
185
  fractionDigits: 2
186
  });
187
-
188
  formatter.format(data, 1); ";
189
- } else {
190
- $formater = '';
191
- }
192
-
193
- if (isset($this->gadwp->config->options['ga_dash_style'])) {
194
- $light_color = GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], 40);
195
- $dark_color = GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], - 20);
196
- $css = "colors:['" . $this->gadwp->config->options['ga_dash_style'] . "','" . GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], - 20) . "'],";
197
- $color = $this->gadwp->config->options['ga_dash_style'];
198
- } else {
199
- $css = "";
200
- $color = "#3366CC";
201
- }
202
- if ($period == 'realtime') {
203
- wp_register_style('jquery-ui-tooltip-html', GADWP_URL . 'realtime/jquery/jquery.ui.tooltip.html.css');
204
- wp_enqueue_style('jquery-ui-tooltip-html');
205
- if (! wp_script_is('jquery')) {
206
- wp_enqueue_script('jquery');
207
- }
208
- if (! wp_script_is('jquery-ui-tooltip')) {
209
- wp_enqueue_script("jquery-ui-tooltip");
210
- }
211
- if (! wp_script_is('jquery-ui-core')) {
212
- wp_enqueue_script("jquery-ui-core");
213
- }
214
- if (! wp_script_is('jquery-ui-position')) {
215
- wp_enqueue_script("jquery-ui-position");
216
- }
217
- if (! wp_script_is('jquery-ui-position')) {
218
- wp_enqueue_script("jquery-ui-position");
219
- }
220
- wp_register_script("jquery-ui-tooltip-html", GADWP_URL . 'realtime/jquery/jquery.ui.tooltip.html.js');
221
- wp_enqueue_script("jquery-ui-tooltip-html");
222
- }
223
- if ($period == 'realtime') {
224
- ?>
225
  <div class="realtime">
226
  <div class="gadash-rt-box">
227
  <div class='gadash-tdo-left'>
@@ -259,9 +253,9 @@ if (! class_exists('GADWP_Backend_Widgets')) {
259
  </div>
260
  </div>
261
  <script type="text/javascript">
262
-
263
  var focusFlag = 1;
264
-
265
  jQuery(document).ready(function(){
266
  jQuery(window).bind("focus",function(event){
267
  focusFlag = 1;
@@ -269,15 +263,15 @@ if (! class_exists('GADWP_Backend_Widgets')) {
269
  focusFlag = 0;
270
  });
271
  });
272
-
273
  jQuery(function() {
274
  jQuery('#gadash-widget *').tooltip();
275
  });
276
-
277
  function onlyUniqueValues(value, index, self) {
278
  return self.indexOf(value) === index;
279
  }
280
-
281
  function countsessions(data, searchvalue) {
282
  var count = 0;
283
  for ( var i = 0; i < data["rows"].length; i = i + 1 ) {
@@ -287,7 +281,7 @@ if (! class_exists('GADWP_Backend_Widgets')) {
287
  }
288
  return count;
289
  }
290
-
291
  function gadash_generatetooltip(data) {
292
  var count = 0;
293
  var table = "";
@@ -301,7 +295,7 @@ if (! class_exists('GADWP_Backend_Widgets')) {
301
  return("");
302
  }
303
  }
304
-
305
  function gadash_pagedetails(data, searchvalue) {
306
  var newdata = [];
307
  for ( var i = 0; i < data["rows"].length; i = i + 1 ){
@@ -316,7 +310,7 @@ if (! class_exists('GADWP_Backend_Widgets')) {
316
  newdata.push(data["rows"][i].slice());
317
  }
318
  }
319
-
320
  var countrfr = 0;
321
  var countkwd = 0;
322
  var countdrt = 0;
@@ -330,9 +324,9 @@ if (! class_exists('GADWP_Backend_Widgets')) {
330
  for ( var i = 0; i < newdata.length; i = i + 1 ) {
331
  if (newdata[i][0] == searchvalue){
332
  var pagetitle = newdata[i][5];
333
-
334
  switch (newdata[i][3]){
335
-
336
  case "REFERRAL": countrfr += parseInt(newdata[ i ][6]);
337
  tablerfr += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>";
338
  break;
@@ -344,7 +338,7 @@ if (! class_exists('GADWP_Backend_Widgets')) {
344
  break;
345
  case "CUSTOM": countcpg += parseInt(newdata[ i ][6]);
346
  tablecpg += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>";
347
- break;
348
  case "DIRECT": countdrt += parseInt(newdata[ i ][6]);
349
  break;
350
  };
@@ -361,25 +355,27 @@ if (! class_exists('GADWP_Backend_Widgets')) {
361
  }
362
  if (countcpg){
363
  tablecpg = "<table><tr><td><?php _e("CAMPAIGN", 'ga-dash');?> ("+countcpg+")</td></tr>"+tablecpg+"</table><br />";
364
- }
365
  if (countdrt){
366
  tabledrt = "<table><tr><td><?php _e("DIRECT", 'ga-dash');?> ("+countdrt+")</td></tr></table><br />";
367
  }
368
  return ("<p><center><strong>"+pagetitle+"</strong></center></p>"+tablerfr+tablekwd+tablescl+tablecpg+tabledrt);
369
  }
370
-
371
  function online_refresh(){
372
  if (focusFlag){
373
 
374
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: false,to: false,query: "realtime",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(data){
375
-
 
 
376
  if (jQuery.isNumeric(data) || typeof data === "undefined"){
377
  data = [];
378
  data["totalsForAllResults"] = []
379
  data["totalsForAllResults"]["rt:activeUsers"] = "0";
380
  data["rows"]= [];
381
  }
382
-
383
  if (data["totalsForAllResults"]["rt:activeUsers"]!==document.getElementById("gadash-online").innerHTML){
384
  jQuery("#gadash-online").fadeOut("slow");
385
  jQuery("#gadash-online").fadeOut(500);
@@ -397,11 +393,11 @@ if (! class_exists('GADWP_Backend_Widgets')) {
397
  jQuery("#gadash-online").css({'background-color' : '#FFFFFF'});
398
  });
399
  };
400
-
401
  if (data["totalsForAllResults"]["rt:activeUsers"] == 0){
402
  data["rows"]= [];
403
  };
404
-
405
  var pagepath = [];
406
  var referrals = [];
407
  var keywords = [];
@@ -421,7 +417,7 @@ if (! class_exists('GADWP_Backend_Widgets')) {
421
  }
422
  if (data["rows"][i][3]=="CUSTOM"){
423
  custom.push( data["rows"][ i ][1] );
424
- }
425
  visittype.push( data["rows"][ i ][3] );
426
  }
427
 
@@ -431,7 +427,7 @@ if (! class_exists('GADWP_Backend_Widgets')) {
431
  upagepathstats[i]={"pagepath":upagepath[i],"count":countsessions(data,upagepath[i])};
432
  }
433
  upagepathstats.sort( function(a,b){ return b.count - a.count } );
434
-
435
  var pgstatstable = "";
436
  for ( var i = 0; i < upagepathstats.length; i = i + 1 ) {
437
  if (i < <?php echo $this->gadwp->config->options['ga_realtime_pages']; ?>){
@@ -439,21 +435,21 @@ if (! class_exists('GADWP_Backend_Widgets')) {
439
  }
440
  }
441
  document.getElementById("gadash-pages").innerHTML='<br /><div class="gadash-pg">'+pgstatstable+'</div>';
442
-
443
  var ureferralsstats = [];
444
  var ureferrals = referrals.filter(onlyUniqueValues);
445
  for ( var i = 0; i < ureferrals.length; i = i + 1 ) {
446
  ureferralsstats[i]={"value":ureferrals[i],"count":countsessions(data,ureferrals[i])};
447
  }
448
  ureferralsstats.sort( function(a,b){ return b.count - a.count } );
449
-
450
  var ukeywordsstats = [];
451
  var ukeywords = keywords.filter(onlyUniqueValues);
452
  for ( var i = 0; i < ukeywords.length; i = i + 1 ) {
453
  ukeywordsstats[i]={"value":ukeywords[i],"count":countsessions(data,ukeywords[i])};
454
  }
455
  ukeywordsstats.sort( function(a,b){ return b.count - a.count } );
456
-
457
  var usocialstats = [];
458
  var usocial = social.filter(onlyUniqueValues);
459
  for ( var i = 0; i < usocial.length; i = i + 1 ) {
@@ -466,18 +462,18 @@ if (! class_exists('GADWP_Backend_Widgets')) {
466
  for ( var i = 0; i < ucustom.length; i = i + 1 ) {
467
  ucustomstats[i]={"value":ucustom[i],"count":countsessions(data,ucustom[i])};
468
  }
469
- ucustomstats.sort( function(a,b){ return b.count - a.count } );
470
-
471
  var uvisittype = ["REFERRAL","ORGANIC","SOCIAL","CUSTOM"];
472
  document.getElementById("gadash-tdo-right").innerHTML = '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(ureferralsstats)+'"><div class="gadash-bleft">'+'<?php _e("REFERRAL", 'ga-dash');?>'+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[0])+'</div></div>';
473
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(ukeywordsstats)+'"><div class="gadash-bleft">'+'<?php _e("ORGANIC", 'ga-dash');?>'+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[1])+'</div></div>';
474
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(usocialstats)+'"><div class="gadash-bleft">'+'<?php _e("SOCIAL", 'ga-dash');?>'+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[2])+'</div></div>';
475
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(ucustomstats)+'"><div class="gadash-bleft">'+'<?php _e("CAMPAIGN", 'ga-dash');?>'+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[3])+'</div></div>';
476
-
477
  var uvisitortype = ["DIRECT","NEW"];
478
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><div class="gadash-bleft">'+'<?php _e("DIRECT", 'ga-dash');?>'+'</div><div class="gadash-bright">'+countsessions(data,uvisitortype[0])+'</div></div>';
479
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><div class="gadash-bleft">'+'<?php _e("NEW", 'ga-dash');?>'+'</div><div class="gadash-bright">'+countsessions(data,uvisitortype[1])+'</div></div>';
480
-
481
  });
482
  };
483
  };
@@ -490,17 +486,6 @@ if (! class_exists('GADWP_Backend_Widgets')) {
490
  <script type="text/javascript">
491
  google.load("visualization", "1", {packages:["table","orgchart"]});
492
 
493
- function checknpcounter(max) {
494
- try {
495
- if (npcounter == max) {
496
- NProgress.done();
497
- } else {
498
- npcounter++;
499
- NProgress.set((1/(max+1))*npcounter);
500
- }
501
- } catch(e) {}
502
- }
503
-
504
  try {
505
  NProgress.configure({ parent: "#gadash-progressbar" });
506
  NProgress.configure({ showSpinner: false });
@@ -508,44 +493,45 @@ if (! class_exists('GADWP_Backend_Widgets')) {
508
  } catch(e) {
509
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
510
  jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?>");
511
- }
512
- npcounter = 0;
513
-
514
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
515
-
516
- if (!jQuery.isNumeric(response)){
517
- if (jQuery.isArray(response)){
518
- gadash_prs=response;
519
- google.setOnLoadCallback(ga_dash_drawprs(gadash_prs));
520
- } else {
521
- checknpcounter(0);
522
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
523
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
524
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
525
- }
526
- }else{
527
- jQuery("#gadash-prs").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
528
- jQuery("#gadash-prs").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
529
- checknpcounter(1);
530
- }
531
- });
532
 
533
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "trafficchannels",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
534
- if (!jQuery.isNumeric(response)){
535
- if (jQuery.isArray(response)){
536
- gadash_trafficchannels=response;
537
- google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels));
538
- } else {
539
- checknpcounter(0);
540
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
541
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
542
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
543
- }
544
- }else{
545
- jQuery("#gadash-trafficchannels").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
546
- jQuery("#gadash-trafficchannels").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
547
- checknpcounter(1);
548
- }
 
 
 
 
549
  });
550
 
551
  function ga_dash_drawprs(gadash_prs) {
@@ -556,11 +542,10 @@ if (! class_exists('GADWP_Backend_Widgets')) {
556
  width: '100%',
557
  allowHtml: true
558
  };
559
-
560
  var chart = new google.visualization.Table(document.getElementById('gadash-prs'));
561
  chart.draw(data, options);
562
- checknpcounter(1);
563
- };
564
 
565
  function ga_dash_drawtrafficchannels(gadash_trafficchannels) {
566
  var data = google.visualization.arrayToDataTable(gadash_trafficchannels);
@@ -568,10 +553,9 @@ if (! class_exists('GADWP_Backend_Widgets')) {
568
  allowCollapse:true,
569
  allowHtml:true
570
  };
571
-
572
  var chart = new google.visualization.OrgChart(document.getElementById('gadash-trafficchannels'));
573
  chart.draw(data, options);
574
- checknpcounter(1);
575
  };
576
  </script>
577
  <?php } else if ($query == 'trafficdetails') {?>
@@ -587,17 +571,6 @@ if (! class_exists('GADWP_Backend_Widgets')) {
587
  <script type="text/javascript">
588
  google.load("visualization", "1", {packages:["corechart","orgchart"]});
589
 
590
- function checknpcounter(max) {
591
- try {
592
- if (npcounter == max) {
593
- NProgress.done();
594
- } else {
595
- npcounter++;
596
- NProgress.set((1/(max+1))*npcounter);
597
- }
598
- } catch(e) {}
599
- }
600
-
601
  try {
602
  NProgress.configure({ parent: "#gadash-progressbar" });
603
  NProgress.configure({ showSpinner: false });
@@ -605,104 +578,89 @@ if (! class_exists('GADWP_Backend_Widgets')) {
605
  } catch(e) {
606
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
607
  jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?>");
608
- }
609
- npcounter = 0;
610
-
611
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "medium",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
612
-
613
- if (!jQuery.isNumeric(response)){
614
- if (jQuery.isArray(response)){
615
- gadash_trafficmediums=response;
616
- google.setOnLoadCallback(ga_dash_drawtrafficmediums(gadash_trafficmediums));
617
- } else {
618
- checknpcounter(0);
619
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
620
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
621
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
622
- }
623
- }else{
624
- jQuery("#gadash-trafficmediums").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
625
- jQuery("#gadash-trafficmediums").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
626
- checknpcounter(4);
627
- }
628
- });
629
-
630
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "visitorType",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
631
- if (!jQuery.isNumeric(response)){
632
- if (jQuery.isArray(response)){
633
- gadash_traffictype=response;
634
- google.setOnLoadCallback(ga_dash_drawtraffictype(gadash_traffictype));
635
- } else {
636
- checknpcounter(0);
637
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
638
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
639
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
640
- }
641
- }else{
642
- jQuery("#gadash-traffictype").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
643
- jQuery("#gadash-traffictype").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
644
- checknpcounter(4);
645
- }
646
- });
647
-
648
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "trafficchannels",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
649
-
650
- if (!jQuery.isNumeric(response)){
651
- if (jQuery.isArray(response)){
652
- gadash_trafficchannels=response;
653
- google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels));
654
- } else {
655
- checknpcounter(0);
656
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
657
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
658
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
659
- }
660
- }else{
661
- jQuery("#gadash-trafficchannels").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
662
- jQuery("#gadash-trafficchannels").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
663
- checknpcounter(4);
664
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
665
  });
666
 
667
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "socialNetwork",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
668
-
669
- if (!jQuery.isNumeric(response)){
670
- if (jQuery.isArray(response)){
671
- gadash_socialnetworks=response;
672
- google.setOnLoadCallback(ga_dash_drawsocialnetworks(gadash_socialnetworks));
673
- } else {
674
- checknpcounter(0);
675
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
676
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
677
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
678
- }
679
- }else{
680
- jQuery("#gadash-socialnetworks").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
681
- jQuery("#gadash-socialnetworks").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
682
- checknpcounter(4);
683
- }
684
- });
685
-
686
-
687
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "source",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
688
-
689
- if (!jQuery.isNumeric(response)){
690
- if (jQuery.isArray(response)){
691
- gadash_trafficorganic=response;
692
- google.setOnLoadCallback(ga_dash_drawtrafficorganic(gadash_trafficorganic));
693
- } else {
694
- checknpcounter(0);
695
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
696
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
697
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
698
- }
699
- }else{
700
- jQuery("#gadash-trafficorganic").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
701
- jQuery("#gadash-trafficorganic").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
702
- checknpcounter(4);
703
- }
704
- });
705
-
706
  function ga_dash_drawtrafficmediums(gadash_trafficmediums) {
707
  var data = google.visualization.arrayToDataTable(gadash_trafficmediums);
708
  var options = {
@@ -713,10 +671,9 @@ if (! class_exists('GADWP_Backend_Widgets')) {
713
  title: '<?php _e( "Traffic Mediums", 'ga-dash' ); ?>',
714
  colors:['<?php echo esc_html($this->gadwp->config->options ['ga_dash_style']); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 20 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 20 )); ?>']
715
  };
716
-
717
  var chart = new google.visualization.PieChart(document.getElementById('gadash-trafficmediums'));
718
  chart.draw(data, options);
719
- checknpcounter(4);
720
  };
721
 
722
  function ga_dash_drawtraffictype(gadash_traffictype) {
@@ -729,10 +686,9 @@ if (! class_exists('GADWP_Backend_Widgets')) {
729
  title: '<?php _e( "Visitor Type", 'ga-dash' ); ?>',
730
  colors:['<?php echo esc_html($this->gadwp->config->options ['ga_dash_style']); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 20 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 20 )); ?>']
731
  };
732
-
733
  var chart = new google.visualization.PieChart(document.getElementById('gadash-traffictype'));
734
  chart.draw(data, options);
735
- checknpcounter(4);
736
  };
737
 
738
  function ga_dash_drawsocialnetworks(gadash_socialnetworks) {
@@ -745,11 +701,10 @@ if (! class_exists('GADWP_Backend_Widgets')) {
745
  title: '<?php _e( "Social Networks", 'ga-dash' ); ?>',
746
  colors:['<?php echo esc_html($this->gadwp->config->options ['ga_dash_style']); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 20 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 20 )); ?>']
747
  };
748
-
749
  var chart = new google.visualization.PieChart(document.getElementById('gadash-socialnetworks'));
750
  chart.draw(data, options);
751
- checknpcounter(4);
752
- };
753
 
754
  function ga_dash_drawtrafficorganic(gadash_trafficorganic) {
755
  var data = google.visualization.arrayToDataTable(gadash_trafficorganic);
@@ -761,11 +716,10 @@ if (! class_exists('GADWP_Backend_Widgets')) {
761
  title: '<?php _e( "Search Engines", 'ga-dash' ); ?>',
762
  colors:['<?php echo esc_html($this->gadwp->config->options ['ga_dash_style']); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 20 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 20 )); ?>']
763
  };
764
-
765
  var chart = new google.visualization.PieChart(document.getElementById('gadash-trafficorganic'));
766
  chart.draw(data, options);
767
- checknpcounter(4);
768
- };
769
 
770
  function ga_dash_drawtrafficchannels(gadash_trafficchannels) {
771
  var data = google.visualization.arrayToDataTable(gadash_trafficchannels);
@@ -773,10 +727,9 @@ if (! class_exists('GADWP_Backend_Widgets')) {
773
  allowCollapse:true,
774
  allowHtml:true
775
  };
776
-
777
  var chart = new google.visualization.OrgChart(document.getElementById('gadash-trafficchannels'));
778
  chart.draw(data, options);
779
- checknpcounter(4);
780
  };
781
  </script>
782
  <?php } else if ($query == 'locations') {?>
@@ -785,17 +738,6 @@ if (! class_exists('GADWP_Backend_Widgets')) {
785
  <script type="text/javascript">
786
  google.load("visualization", "1", {packages:["geochart","table"]});
787
 
788
- function checknpcounter(max) {
789
- try {
790
- if (npcounter == max) {
791
- NProgress.done();
792
- } else {
793
- npcounter++;
794
- NProgress.set((1/(max+1))*npcounter);
795
- }
796
- } catch(e) {}
797
- }
798
-
799
  try {
800
  NProgress.configure({ parent: "#gadash-progressbar" });
801
  NProgress.configure({ showSpinner: false });
@@ -803,43 +745,48 @@ if (! class_exists('GADWP_Backend_Widgets')) {
803
  } catch(e) {
804
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
805
  jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?>");
806
- }
807
- npcounter = 0;
808
-
809
  jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
810
 
811
- if (!jQuery.isNumeric(response)){
812
- if (jQuery.isArray(response)){
813
- gadash_locations=response;
814
- google.setOnLoadCallback(ga_dash_drawmaplocations(gadash_locations));
815
- google.setOnLoadCallback(ga_dash_drawlocations(gadash_locations));
816
- } else {
817
- checknpcounter(0);
818
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
819
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
820
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
821
- }
822
- }else{
823
- jQuery("#gadash-map").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
824
- jQuery("#gadash-map").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
825
- checknpcounter(1);
826
- jQuery("#gadash-locations").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
827
- jQuery("#gadash-locations").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
828
- checknpcounter(1);
829
- }
830
- });
 
 
 
 
 
 
831
  function ga_dash_drawmaplocations(gadash_locations) {
832
-
833
  var data = google.visualization.arrayToDataTable(gadash_locations);
834
-
835
  var options = {
836
- chartArea: {width: '99%',height: '90%'},
837
  colors: ['<?php echo $light_color; ?>', '<?php echo $dark_color; ?>'],
838
  <?php
839
-
840
- $country_codes = GADWP_Tools::get_countrycodes();
841
- if ($this->gadwp->config->options['ga_target_geomap'] && isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) {
842
- ?>
843
  region : '<?php echo esc_html($this->gadwp->config->options ['ga_target_geomap']); ?>',
844
  displayMode : 'markers',
845
  datalessRegionColor : 'EFEFEF'
@@ -847,7 +794,6 @@ if (! class_exists('GADWP_Backend_Widgets')) {
847
  }
848
  var chart = new google.visualization.GeoChart(document.getElementById('gadash-map'));
849
  chart.draw(data, options);
850
- checknpcounter(1);
851
  }
852
 
853
  function ga_dash_drawlocations(gadash_locations) {
@@ -857,10 +803,9 @@ if (! class_exists('GADWP_Backend_Widgets')) {
857
  pageSize: 10,
858
  width: '100%'
859
  };
860
-
861
  var chart = new google.visualization.Table(document.getElementById('gadash-locations'));
862
  chart.draw(data, options);
863
- checknpcounter(1);
864
  };
865
  </script>
866
  <?php } else {?>
@@ -894,20 +839,9 @@ if (! class_exists('GADWP_Backend_Widgets')) {
894
  </div>
895
  </div>
896
  <script type="text/javascript">
897
-
898
  google.load("visualization", "1", {packages:["corechart"]});
899
 
900
- function checknpcounter(max) {
901
- try {
902
- if (npcounter == max) {
903
- NProgress.done();
904
- } else {
905
- npcounter++;
906
- NProgress.set((1/(max+1))*npcounter);
907
- }
908
- } catch(e) {}
909
- }
910
-
911
  try {
912
  NProgress.configure({ parent: "#gadash-progressbar" });
913
  NProgress.configure({ showSpinner: false });
@@ -915,45 +849,45 @@ if (! class_exists('GADWP_Backend_Widgets')) {
915
  } catch(e) {
916
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
917
  jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?>");
918
- }
919
- npcounter = 0;
920
-
921
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
922
-
923
- if (!jQuery.isNumeric(response)){
924
- if (jQuery.isArray(response)){
925
- gadash_mainchart=response;
926
- google.setOnLoadCallback(ga_dash_drawmainchart(gadash_mainchart));
927
- } else {
928
- checknpcounter(0);
929
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
930
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
931
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
932
- }
933
- }else{
934
- jQuery("#gadash-mainchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
935
- jQuery("#gadash-mainchart").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
936
- checknpcounter(1);
937
- }
938
- });
939
-
940
- jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "bottomstats",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
941
-
942
- if (!jQuery.isNumeric(response)){
943
- if (jQuery.isArray(response)){
944
- gadash_bottomstats=response;
945
- ga_dash_drawbottomstats(gadash_bottomstats);
946
- } else {
947
- checknpcounter(0);
948
- jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
949
- jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
950
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
951
- }
952
- }else{
953
- jQuery("#gadash-bottomstats").css({"background-color":"#F7F7F7","height":"auto","padding-top":"40px","padding-bottom":"40px","color":"#000","text-align":"center","width": "98%"});
954
- jQuery("#gadash-bottomstats").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
955
- checknpcounter(1);
956
- }
957
  });
958
 
959
  function ga_dash_drawbottomstats(gadash_bottomstats) {
@@ -963,11 +897,10 @@ if (! class_exists('GADWP_Backend_Widgets')) {
963
  jQuery("#gadash-bottomstats #gdbouncerate").text(parseFloat(gadash_bottomstats[3]).toFixed(2)+"%");
964
  jQuery("#gadash-bottomstats #gdorganicsearch").text(gadash_bottomstats[4]);
965
  jQuery("#gadash-bottomstats #gdpagespervisit").text(parseFloat(gadash_bottomstats[5]).toFixed(2));
966
- checknpcounter(1);
967
- }
968
-
969
  function ga_dash_drawmainchart(gadash_mainchart) {
970
-
971
  var data = google.visualization.arrayToDataTable(gadash_mainchart);
972
 
973
  var options = {
@@ -980,11 +913,10 @@ if (! class_exists('GADWP_Backend_Widgets')) {
980
  <?php echo $formater?>
981
  var chart = new google.visualization.AreaChart(document.getElementById('gadash-mainchart'));
982
  chart.draw(data, options);
983
- checknpcounter(1);
984
  };
985
  </script>
986
  <?php
987
- }
988
- }
989
- }
990
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
+
13
+ if ( ! class_exists( 'GADWP_Backend_Widgets' ) ) {
14
+
15
+ class GADWP_Backend_Widgets {
16
+
17
+ private $gawp;
18
+
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
21
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) && ( 1 == $this->gadwp->config->options['dashboard_widget'] ) ) {
22
+ add_action( 'wp_dashboard_setup', array(
23
+ $this,
24
+ 'add_widget' ) );
25
+ }
26
+ }
27
+
28
+ public function add_widget() {
29
+ wp_add_dashboard_widget( 'gadash-widget', __( "Google Analytics Dashboard", 'ga-dash' ), array(
30
+ $this,
31
+ 'dashboard_widget' ), $control_callback = null );
32
+ }
33
+
34
+ public function dashboard_widget() {
35
+ if ( empty( $this->gadwp->config->options['ga_dash_token'] ) ) {
36
+ echo '<p>' . __( "This plugin needs an authorization:", 'ga-dash' ) . '</p><form action="' . menu_page_url( 'gadash_settings', false ) . '" method="POST">' . get_submit_button( __( "Authorize Plugin", 'ga-dash' ), 'secondary' ) . '</form>';
37
+ return;
38
+ }
39
+
40
+ if ( current_user_can( 'manage_options' ) ) {
41
+ if ( isset( $_REQUEST['ga_dash_profile_select'] ) ) {
42
+ $this->gadwp->config->options['ga_dash_tableid'] = $_REQUEST['ga_dash_profile_select'];
43
+ }
44
+ $profiles = $this->gadwp->config->options['ga_dash_profile_list'];
45
+ $profile_switch = '';
46
+ if ( ! empty( $profiles ) ) {
47
+ if ( ! $this->gadwp->config->options['ga_dash_tableid'] ) {
48
+ if ( $this->gadwp->config->options['ga_dash_tableid_jail'] ) {
49
+ $this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail'];
50
+ } else {
51
+ $this->gadwp->config->options['ga_dash_tableid'] = GADWP_Tools::guess_default_domain( $profiles );
52
+ }
53
+ } else
54
+ if ( $this->gadwp->config->options['switch_profile'] == 0 && $this->gadwp->config->options['ga_dash_tableid_jail'] ) {
55
+ $this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail'];
56
+ }
57
+ $profile_switch .= '<select id="ga_dash_profile_select" name="ga_dash_profile_select" onchange="this.form.submit()">';
58
+ foreach ( $profiles as $profile ) {
59
+ if ( ! $this->gadwp->config->options['ga_dash_tableid'] ) {
60
+ $this->gadwp->config->options['ga_dash_tableid'] = $profile[1];
61
+ }
62
+ if ( isset( $profile[3] ) ) {
63
+ $profile_switch .= '<option value="' . esc_attr( $profile[1] ) . '" ';
64
+ $profile_switch .= selected( $profile[1], $this->gadwp->config->options['ga_dash_tableid'], false );
65
+ $profile_switch .= ' title="' . __( "View Name:", 'ga-dash' ) . ' ' . esc_attr( $profile[0] ) . '">' . esc_attr( GADWP_Tools::strip_protocol( $profile[3] ) ) . '</option>';
66
+ }
67
+ }
68
+ $profile_switch .= "</select>";
69
+ } else {
70
+ echo '<p>' . __( "Something went wrong while retrieving profiles list.", 'ga-dash' ) . '</p><form action="' . menu_page_url( 'gadash_settings', false ) . '" method="POST">' . get_submit_button( __( "More details", 'ga-dash' ), 'secondary' ) . '</form>';
71
+ return;
72
+ }
73
+ }
74
+ $this->gadwp->config->set_plugin_options();
75
+ ?>
 
 
 
 
 
 
76
  <form id="ga-dash" method="POST">
77
  <?php
78
+ if ( current_user_can( 'manage_options' ) ) {
79
+ if ( $this->gadwp->config->options['switch_profile'] == 0 ) {
80
+ if ( $this->gadwp->config->options['ga_dash_tableid_jail'] ) {
81
+ $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
82
+ } else {
83
+ echo '<p>' . __( "An admin should asign a default Google Analytics Profile.", 'ga-dash' ) . '</p><form action="' . menu_page_url( 'gadash_settings', false ) . '" method="POST">' . get_submit_button( __( "Select Domain", 'ga-dash' ), 'secondary' ) . '</form>';
84
+ return;
85
+ }
86
+ } else {
87
+ echo $profile_switch;
88
+ $projectId = $this->gadwp->config->options['ga_dash_tableid'];
89
+ }
90
+ } else {
91
+ if ( $this->gadwp->config->options['ga_dash_tableid_jail'] ) {
92
+ $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
93
+ } else {
94
+ echo '<p>' . __( "An admin should asign a default Google Analytics Profile.", 'ga-dash' ) . '</p><form action="' . menu_page_url( 'gadash_settings', false ) . '" method="POST">' . get_submit_button( __( "Select Domain", 'ga-dash' ), 'secondary' ) . '</form>';
95
+ return;
96
+ }
97
+ }
98
+ if ( ! ( $projectId ) ) {
99
+ echo '<p>' . __( "Something went wrong while retrieving property data. You need to create and properly configure a Google Analytics account:", 'ga-dash' ) . '</p> <form action="https://deconf.com/how-to-set-up-google-analytics-on-your-website/" method="POST">' . get_submit_button( __( "Find out more!", 'ga-dash' ), 'secondary' ) . '</form>';
100
+ return;
101
+ }
102
+ if ( isset( $_REQUEST['query'] ) ) {
103
+ $query = $_REQUEST['query'];
104
+ $this->gadwp->config->options['ga_dash_default_metric'] = $query;
105
+ $this->gadwp->config->set_plugin_options();
106
+ } else {
107
+ $query = isset( $this->gadwp->config->options['ga_dash_default_metric'] ) ? $this->gadwp->config->options['ga_dash_default_metric'] : 'sessions';
108
+ }
109
+ if ( isset( $_REQUEST['period'] ) ) {
110
+ $period = $_REQUEST['period'];
111
+ $this->gadwp->config->options['ga_dash_default_dimension'] = $period;
112
+ $this->gadwp->config->set_plugin_options();
113
+ } else {
114
+ $period = isset( $this->gadwp->config->options['ga_dash_default_dimension'] ) ? $this->gadwp->config->options['ga_dash_default_dimension'] : '30daysAgo';
115
+ }
116
+ ?>
117
 
118
  <select id="ga_dash_period" name="period" onchange="this.form.submit()">
119
  <option value="realtime" <?php selected ( "realtime", $period, true ); ?>><?php _e("Real-Time",'ga-dash'); ?></option>
141
  </form>
142
  <div id="gadash-progressbar"></div>
143
  <?php
144
+ switch ( $period ) {
145
+ case 'today' :
146
+ $from = 'today';
147
+ $to = 'today';
148
+ $haxis = 4;
149
+ break;
150
+ case 'yesterday' :
151
+ $from = 'yesterday';
152
+ $to = 'yesterday';
153
+ $haxis = 4;
154
+ break;
155
+ case '7daysAgo' :
156
+ $from = '7daysAgo';
157
+ $to = 'yesterday';
158
+ $haxis = 2;
159
+ break;
160
+ case '14daysAgo' :
161
+ $from = '14daysAgo';
162
+ $to = 'yesterday';
163
+ $haxis = 3;
164
+ break;
165
+ case '30daysAgo' :
166
+ $from = '30daysAgo';
167
+ $to = 'yesterday';
168
+ $haxis = 5;
169
+ break;
170
+ default :
171
+ $from = '90daysAgo';
172
+ $to = 'yesterday';
173
+ $haxis = 16;
174
+ break;
175
+ }
176
+ if ( $query == 'visitBounceRate' ) {
177
+ $formater = "var formatter = new google.visualization.NumberFormat({
178
+ suffix: '%',
179
  fractionDigits: 2
180
  });
181
+
182
  formatter.format(data, 1); ";
183
+ } else {
184
+ $formater = '';
185
+ }
186
+
187
+ if ( isset( $this->gadwp->config->options['ga_dash_style'] ) ) {
188
+ $light_color = GADWP_Tools::colourVariator( $this->gadwp->config->options['ga_dash_style'], 40 );
189
+ $dark_color = GADWP_Tools::colourVariator( $this->gadwp->config->options['ga_dash_style'], - 20 );
190
+ $css = "colors:['" . $this->gadwp->config->options['ga_dash_style'] . "','" . GADWP_Tools::colourVariator( $this->gadwp->config->options['ga_dash_style'], - 20 ) . "'],";
191
+ $color = $this->gadwp->config->options['ga_dash_style'];
192
+ } else {
193
+ $css = "";
194
+ $color = "#3366CC";
195
+ }
196
+ if ( $period == 'realtime' ) {
197
+ wp_register_style( 'jquery-ui-tooltip-html', GADWP_URL . 'realtime/jquery/jquery.ui.tooltip.html.css' );
198
+ wp_enqueue_style( 'jquery-ui-tooltip-html' );
199
+ if ( ! wp_script_is( 'jquery' ) ) {
200
+ wp_enqueue_script( 'jquery' );
201
+ }
202
+ if ( ! wp_script_is( 'jquery-ui-tooltip' ) ) {
203
+ wp_enqueue_script( "jquery-ui-tooltip" );
204
+ }
205
+ if ( ! wp_script_is( 'jquery-ui-core' ) ) {
206
+ wp_enqueue_script( "jquery-ui-core" );
207
+ }
208
+ if ( ! wp_script_is( 'jquery-ui-position' ) ) {
209
+ wp_enqueue_script( "jquery-ui-position" );
210
+ }
211
+ if ( ! wp_script_is( 'jquery-ui-position' ) ) {
212
+ wp_enqueue_script( "jquery-ui-position" );
213
+ }
214
+ wp_register_script( "jquery-ui-tooltip-html", GADWP_URL . 'realtime/jquery/jquery.ui.tooltip.html.js' );
215
+ wp_enqueue_script( "jquery-ui-tooltip-html" );
216
+ }
217
+ if ( $period == 'realtime' ) {
218
+ ?>
219
  <div class="realtime">
220
  <div class="gadash-rt-box">
221
  <div class='gadash-tdo-left'>
253
  </div>
254
  </div>
255
  <script type="text/javascript">
256
+
257
  var focusFlag = 1;
258
+
259
  jQuery(document).ready(function(){
260
  jQuery(window).bind("focus",function(event){
261
  focusFlag = 1;
263
  focusFlag = 0;
264
  });
265
  });
266
+
267
  jQuery(function() {
268
  jQuery('#gadash-widget *').tooltip();
269
  });
270
+
271
  function onlyUniqueValues(value, index, self) {
272
  return self.indexOf(value) === index;
273
  }
274
+
275
  function countsessions(data, searchvalue) {
276
  var count = 0;
277
  for ( var i = 0; i < data["rows"].length; i = i + 1 ) {
281
  }
282
  return count;
283
  }
284
+
285
  function gadash_generatetooltip(data) {
286
  var count = 0;
287
  var table = "";
295
  return("");
296
  }
297
  }
298
+
299
  function gadash_pagedetails(data, searchvalue) {
300
  var newdata = [];
301
  for ( var i = 0; i < data["rows"].length; i = i + 1 ){
310
  newdata.push(data["rows"][i].slice());
311
  }
312
  }
313
+
314
  var countrfr = 0;
315
  var countkwd = 0;
316
  var countdrt = 0;
324
  for ( var i = 0; i < newdata.length; i = i + 1 ) {
325
  if (newdata[i][0] == searchvalue){
326
  var pagetitle = newdata[i][5];
327
+
328
  switch (newdata[i][3]){
329
+
330
  case "REFERRAL": countrfr += parseInt(newdata[ i ][6]);
331
  tablerfr += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>";
332
  break;
338
  break;
339
  case "CUSTOM": countcpg += parseInt(newdata[ i ][6]);
340
  tablecpg += "<tr><td class='gadash-pgdetailsl'>"+newdata[i][1]+"</td><td class='gadash-pgdetailsr'>"+newdata[ i ][6]+"</td></tr>";
341
+ break;
342
  case "DIRECT": countdrt += parseInt(newdata[ i ][6]);
343
  break;
344
  };
355
  }
356
  if (countcpg){
357
  tablecpg = "<table><tr><td><?php _e("CAMPAIGN", 'ga-dash');?> ("+countcpg+")</td></tr>"+tablecpg+"</table><br />";
358
+ }
359
  if (countdrt){
360
  tabledrt = "<table><tr><td><?php _e("DIRECT", 'ga-dash');?> ("+countdrt+")</td></tr></table><br />";
361
  }
362
  return ("<p><center><strong>"+pagetitle+"</strong></center></p>"+tablerfr+tablekwd+tablescl+tablecpg+tabledrt);
363
  }
364
+
365
  function online_refresh(){
366
  if (focusFlag){
367
 
368
+ jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: false,to: false,query: "realtime",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(results){
369
+
370
+ data = results[0];
371
+
372
  if (jQuery.isNumeric(data) || typeof data === "undefined"){
373
  data = [];
374
  data["totalsForAllResults"] = []
375
  data["totalsForAllResults"]["rt:activeUsers"] = "0";
376
  data["rows"]= [];
377
  }
378
+
379
  if (data["totalsForAllResults"]["rt:activeUsers"]!==document.getElementById("gadash-online").innerHTML){
380
  jQuery("#gadash-online").fadeOut("slow");
381
  jQuery("#gadash-online").fadeOut(500);
393
  jQuery("#gadash-online").css({'background-color' : '#FFFFFF'});
394
  });
395
  };
396
+
397
  if (data["totalsForAllResults"]["rt:activeUsers"] == 0){
398
  data["rows"]= [];
399
  };
400
+
401
  var pagepath = [];
402
  var referrals = [];
403
  var keywords = [];
417
  }
418
  if (data["rows"][i][3]=="CUSTOM"){
419
  custom.push( data["rows"][ i ][1] );
420
+ }
421
  visittype.push( data["rows"][ i ][3] );
422
  }
423
 
427
  upagepathstats[i]={"pagepath":upagepath[i],"count":countsessions(data,upagepath[i])};
428
  }
429
  upagepathstats.sort( function(a,b){ return b.count - a.count } );
430
+
431
  var pgstatstable = "";
432
  for ( var i = 0; i < upagepathstats.length; i = i + 1 ) {
433
  if (i < <?php echo $this->gadwp->config->options['ga_realtime_pages']; ?>){
435
  }
436
  }
437
  document.getElementById("gadash-pages").innerHTML='<br /><div class="gadash-pg">'+pgstatstable+'</div>';
438
+
439
  var ureferralsstats = [];
440
  var ureferrals = referrals.filter(onlyUniqueValues);
441
  for ( var i = 0; i < ureferrals.length; i = i + 1 ) {
442
  ureferralsstats[i]={"value":ureferrals[i],"count":countsessions(data,ureferrals[i])};
443
  }
444
  ureferralsstats.sort( function(a,b){ return b.count - a.count } );
445
+
446
  var ukeywordsstats = [];
447
  var ukeywords = keywords.filter(onlyUniqueValues);
448
  for ( var i = 0; i < ukeywords.length; i = i + 1 ) {
449
  ukeywordsstats[i]={"value":ukeywords[i],"count":countsessions(data,ukeywords[i])};
450
  }
451
  ukeywordsstats.sort( function(a,b){ return b.count - a.count } );
452
+
453
  var usocialstats = [];
454
  var usocial = social.filter(onlyUniqueValues);
455
  for ( var i = 0; i < usocial.length; i = i + 1 ) {
462
  for ( var i = 0; i < ucustom.length; i = i + 1 ) {
463
  ucustomstats[i]={"value":ucustom[i],"count":countsessions(data,ucustom[i])};
464
  }
465
+ ucustomstats.sort( function(a,b){ return b.count - a.count } );
466
+
467
  var uvisittype = ["REFERRAL","ORGANIC","SOCIAL","CUSTOM"];
468
  document.getElementById("gadash-tdo-right").innerHTML = '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(ureferralsstats)+'"><div class="gadash-bleft">'+'<?php _e("REFERRAL", 'ga-dash');?>'+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[0])+'</div></div>';
469
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(ukeywordsstats)+'"><div class="gadash-bleft">'+'<?php _e("ORGANIC", 'ga-dash');?>'+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[1])+'</div></div>';
470
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(usocialstats)+'"><div class="gadash-bleft">'+'<?php _e("SOCIAL", 'ga-dash');?>'+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[2])+'</div></div>';
471
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><a href="#" data-tooltip="'+gadash_generatetooltip(ucustomstats)+'"><div class="gadash-bleft">'+'<?php _e("CAMPAIGN", 'ga-dash');?>'+'</a></div><div class="gadash-bright">'+countsessions(data,uvisittype[3])+'</div></div>';
472
+
473
  var uvisitortype = ["DIRECT","NEW"];
474
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><div class="gadash-bleft">'+'<?php _e("DIRECT", 'ga-dash');?>'+'</div><div class="gadash-bright">'+countsessions(data,uvisitortype[0])+'</div></div>';
475
  document.getElementById("gadash-tdo-right").innerHTML += '<div class="gadash-bigtext"><div class="gadash-bleft">'+'<?php _e("NEW", 'ga-dash');?>'+'</div><div class="gadash-bright">'+countsessions(data,uvisitortype[1])+'</div></div>';
476
+
477
  });
478
  };
479
  };
486
  <script type="text/javascript">
487
  google.load("visualization", "1", {packages:["table","orgchart"]});
488
 
 
 
 
 
 
 
 
 
 
 
 
489
  try {
490
  NProgress.configure({ parent: "#gadash-progressbar" });
491
  NProgress.configure({ showSpinner: false });
493
  } catch(e) {
494
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
495
  jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?>");
496
+ }
497
+
498
+ jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo 'trafficchannels,' . $query; ?>",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
499
+ if ( jQuery.isArray( response ) ) {
500
+
501
+ if (!jQuery.isNumeric(response[0])){
502
+ if (jQuery.isArray(response[0])){
503
+ gadash_trafficchannels=response[0];
504
+ google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels));
505
+ } else {
506
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
507
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
508
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[0]);
509
+ }
510
+ }else{
511
+ jQuery("#gadash-trafficchannels").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
512
+ jQuery("#gadash-trafficchannels").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[0]+")");
513
+ }
 
 
 
514
 
515
+ if (!jQuery.isNumeric(response[1])){
516
+ if (jQuery.isArray(response[1])){
517
+ gadash_prs=response[1];
518
+ google.setOnLoadCallback(ga_dash_drawprs(gadash_prs));
519
+ } else {
520
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
521
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
522
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[1]);
523
+ }
524
+ }else{
525
+ jQuery("#gadash-prs").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
526
+ jQuery("#gadash-prs").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[1]+")");
527
+ }
528
+
529
+ }else{
530
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
531
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
532
+ console.log("\n********************* GADWP Log ********************* \n\n"+response);
533
+ }
534
+ NProgress.done();
535
  });
536
 
537
  function ga_dash_drawprs(gadash_prs) {
542
  width: '100%',
543
  allowHtml: true
544
  };
545
+
546
  var chart = new google.visualization.Table(document.getElementById('gadash-prs'));
547
  chart.draw(data, options);
548
+ };
 
549
 
550
  function ga_dash_drawtrafficchannels(gadash_trafficchannels) {
551
  var data = google.visualization.arrayToDataTable(gadash_trafficchannels);
553
  allowCollapse:true,
554
  allowHtml:true
555
  };
556
+
557
  var chart = new google.visualization.OrgChart(document.getElementById('gadash-trafficchannels'));
558
  chart.draw(data, options);
 
559
  };
560
  </script>
561
  <?php } else if ($query == 'trafficdetails') {?>
571
  <script type="text/javascript">
572
  google.load("visualization", "1", {packages:["corechart","orgchart"]});
573
 
 
 
 
 
 
 
 
 
 
 
 
574
  try {
575
  NProgress.configure({ parent: "#gadash-progressbar" });
576
  NProgress.configure({ showSpinner: false });
578
  } catch(e) {
579
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
580
  jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?>");
581
+ }
582
+
583
+ jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "trafficchannels,medium,visitorType,source,socialNetwork",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
584
+ if ( jQuery.isArray( response ) ) {
585
+
586
+ if (!jQuery.isNumeric(response[0])){
587
+ if (jQuery.isArray(response[0])){
588
+ gadash_trafficchannels=response[0];
589
+ google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels));
590
+ } else {
591
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
592
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
593
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[0]);
594
+ }
595
+ }else{
596
+ jQuery("#gadash-trafficchannels").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
597
+ jQuery("#gadash-trafficchannels").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[0]+")");
598
+ }
599
+
600
+ if (!jQuery.isNumeric(response[1])){
601
+ if (jQuery.isArray(response[1])){
602
+ gadash_trafficmediums=response[1];
603
+ google.setOnLoadCallback(ga_dash_drawtrafficmediums(gadash_trafficmediums));
604
+ } else {
605
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
606
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
607
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[1]);
608
+ }
609
+ }else{
610
+ jQuery("#gadash-trafficmediums").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
611
+ jQuery("#gadash-trafficmediums").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[1]+")");
612
+ }
613
+
614
+ if (!jQuery.isNumeric(response[2])){
615
+ if (jQuery.isArray(response[2])){
616
+ gadash_traffictype=response[2];
617
+ google.setOnLoadCallback(ga_dash_drawtraffictype(gadash_traffictype));
618
+ } else {
619
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
620
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
621
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[2]);
622
+ }
623
+ }else{
624
+ jQuery("#gadash-traffictype").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
625
+ jQuery("#gadash-traffictype").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[2]+")");
626
+ }
627
+
628
+ if (!jQuery.isNumeric(response[3])){
629
+ if (jQuery.isArray(response[3])){
630
+ gadash_trafficorganic=response[3];
631
+ google.setOnLoadCallback(ga_dash_drawtrafficorganic(gadash_trafficorganic));
632
+ } else {
633
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
634
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
635
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[3]);
636
+ }
637
+ }else{
638
+ jQuery("#gadash-trafficorganic").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
639
+ jQuery("#gadash-trafficorganic").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[3]+")");
640
+ }
641
+
642
+ if (!jQuery.isNumeric(response[4])){
643
+ if (jQuery.isArray(response[4])){
644
+ gadash_socialnetworks=response[4];
645
+ google.setOnLoadCallback(ga_dash_drawsocialnetworks(gadash_socialnetworks));
646
+ } else {
647
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
648
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
649
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[4]);
650
+ }
651
+ }else{
652
+ jQuery("#gadash-socialnetworks").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
653
+ jQuery("#gadash-socialnetworks").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[4]+")");
654
+ }
655
+
656
+ }else{
657
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
658
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
659
+ console.log("\n********************* GADWP Log ********************* \n\n"+response);
660
+ }
661
+ NProgress.done();
662
  });
663
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664
  function ga_dash_drawtrafficmediums(gadash_trafficmediums) {
665
  var data = google.visualization.arrayToDataTable(gadash_trafficmediums);
666
  var options = {
671
  title: '<?php _e( "Traffic Mediums", 'ga-dash' ); ?>',
672
  colors:['<?php echo esc_html($this->gadwp->config->options ['ga_dash_style']); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 20 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 20 )); ?>']
673
  };
674
+
675
  var chart = new google.visualization.PieChart(document.getElementById('gadash-trafficmediums'));
676
  chart.draw(data, options);
 
677
  };
678
 
679
  function ga_dash_drawtraffictype(gadash_traffictype) {
686
  title: '<?php _e( "Visitor Type", 'ga-dash' ); ?>',
687
  colors:['<?php echo esc_html($this->gadwp->config->options ['ga_dash_style']); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 20 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 20 )); ?>']
688
  };
689
+
690
  var chart = new google.visualization.PieChart(document.getElementById('gadash-traffictype'));
691
  chart.draw(data, options);
 
692
  };
693
 
694
  function ga_dash_drawsocialnetworks(gadash_socialnetworks) {
701
  title: '<?php _e( "Social Networks", 'ga-dash' ); ?>',
702
  colors:['<?php echo esc_html($this->gadwp->config->options ['ga_dash_style']); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 20 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 20 )); ?>']
703
  };
704
+
705
  var chart = new google.visualization.PieChart(document.getElementById('gadash-socialnetworks'));
706
  chart.draw(data, options);
707
+ };
 
708
 
709
  function ga_dash_drawtrafficorganic(gadash_trafficorganic) {
710
  var data = google.visualization.arrayToDataTable(gadash_trafficorganic);
716
  title: '<?php _e( "Search Engines", 'ga-dash' ); ?>',
717
  colors:['<?php echo esc_html($this->gadwp->config->options ['ga_dash_style']); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 20 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], + 10 )); ?>','<?php echo esc_html(GADWP_Tools::colourVariator ( $this->gadwp->config->options ['ga_dash_style'], - 20 )); ?>']
718
  };
719
+
720
  var chart = new google.visualization.PieChart(document.getElementById('gadash-trafficorganic'));
721
  chart.draw(data, options);
722
+ };
 
723
 
724
  function ga_dash_drawtrafficchannels(gadash_trafficchannels) {
725
  var data = google.visualization.arrayToDataTable(gadash_trafficchannels);
727
  allowCollapse:true,
728
  allowHtml:true
729
  };
730
+
731
  var chart = new google.visualization.OrgChart(document.getElementById('gadash-trafficchannels'));
732
  chart.draw(data, options);
 
733
  };
734
  </script>
735
  <?php } else if ($query == 'locations') {?>
738
  <script type="text/javascript">
739
  google.load("visualization", "1", {packages:["geochart","table"]});
740
 
 
 
 
 
 
 
 
 
 
 
 
741
  try {
742
  NProgress.configure({ parent: "#gadash-progressbar" });
743
  NProgress.configure({ showSpinner: false });
745
  } catch(e) {
746
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
747
  jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?>");
748
+ }
749
+
 
750
  jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
751
 
752
+ if ( jQuery.isArray( response ) ) {
753
+ if (!jQuery.isNumeric(response[0])){
754
+ if (jQuery.isArray(response[0])){
755
+ gadash_locations=response[0];
756
+ google.setOnLoadCallback(ga_dash_drawmaplocations(gadash_locations));
757
+ google.setOnLoadCallback(ga_dash_drawlocations(gadash_locations));
758
+ } else {
759
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
760
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
761
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[0]);
762
+ }
763
+ }else{
764
+ jQuery("#gadash-map").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
765
+ jQuery("#gadash-map").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[0]+")");
766
+ jQuery("#gadash-locations").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
767
+ jQuery("#gadash-locations").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[0]+")");
768
+ }
769
+
770
+ }else{
771
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
772
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
773
+ console.log("\n********************* GADWP Log ********************* \n\n"+response);
774
+ }
775
+ NProgress.done();
776
+ });
777
+
778
  function ga_dash_drawmaplocations(gadash_locations) {
779
+
780
  var data = google.visualization.arrayToDataTable(gadash_locations);
781
+
782
  var options = {
783
+ chartArea: {width: '99%',height: '90%'},
784
  colors: ['<?php echo $light_color; ?>', '<?php echo $dark_color; ?>'],
785
  <?php
786
+
787
+ $country_codes = GADWP_Tools::get_countrycodes();
788
+ if ( $this->gadwp->config->options['ga_target_geomap'] && isset( $country_codes[$this->gadwp->config->options['ga_target_geomap']] ) ) {
789
+ ?>
790
  region : '<?php echo esc_html($this->gadwp->config->options ['ga_target_geomap']); ?>',
791
  displayMode : 'markers',
792
  datalessRegionColor : 'EFEFEF'
794
  }
795
  var chart = new google.visualization.GeoChart(document.getElementById('gadash-map'));
796
  chart.draw(data, options);
 
797
  }
798
 
799
  function ga_dash_drawlocations(gadash_locations) {
803
  pageSize: 10,
804
  width: '100%'
805
  };
806
+
807
  var chart = new google.visualization.Table(document.getElementById('gadash-locations'));
808
  chart.draw(data, options);
 
809
  };
810
  </script>
811
  <?php } else {?>
839
  </div>
840
  </div>
841
  <script type="text/javascript">
842
+
843
  google.load("visualization", "1", {packages:["corechart"]});
844
 
 
 
 
 
 
 
 
 
 
 
 
845
  try {
846
  NProgress.configure({ parent: "#gadash-progressbar" });
847
  NProgress.configure({ showSpinner: false });
849
  } catch(e) {
850
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
851
  jQuery("#gadash-progressbar").html("<?php _e("A JavaScript Error is blocking plugin resources!", 'ga-dash'); ?>");
852
+ }
853
+
854
+ jQuery.post(ajaxurl, {action: "gadash_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query . ',bottomstats'; ?>",gadash_security_widget_reports: "<?php echo wp_create_nonce('gadash_get_widgetreports'); ?>"}, function(response){
855
+ if ( jQuery.isArray( response ) ) {
856
+
857
+ if (!jQuery.isNumeric(response[0])){
858
+ if (jQuery.isArray(response[0])){
859
+ gadash_mainchart=response[0];
860
+ google.setOnLoadCallback(ga_dash_drawmainchart(gadash_mainchart));
861
+ } else {
862
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
863
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
864
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[0]);
865
+ }
866
+ }else{
867
+ jQuery("#gadash-mainchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"125px","padding-bottom":"125px","color":"#000","text-align":"center"});
868
+ jQuery("#gadash-mainchart").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[0]+")");
869
+ }
870
+
871
+ if (!jQuery.isNumeric(response[1])){
872
+ if (jQuery.isArray(response[1])){
873
+ gadash_bottomstats=response[1];
874
+ ga_dash_drawbottomstats(gadash_bottomstats);
875
+ } else {
876
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
877
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
878
+ console.log("\n********************* GADWP Log ********************* \n\n"+response[1]);
879
+ }
880
+ }else{
881
+ jQuery("#gadash-bottomstats").css({"background-color":"#F7F7F7","height":"auto","padding-top":"40px","padding-bottom":"40px","color":"#000","text-align":"center","width": "98%"});
882
+ jQuery("#gadash-bottomstats").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response[1]+")");
883
+ }
884
+
885
+ }else{
886
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
887
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
888
+ console.log("\n********************* GADWP Log ********************* \n\n"+response);
889
+ }
890
+ NProgress.done();
891
  });
892
 
893
  function ga_dash_drawbottomstats(gadash_bottomstats) {
897
  jQuery("#gadash-bottomstats #gdbouncerate").text(parseFloat(gadash_bottomstats[3]).toFixed(2)+"%");
898
  jQuery("#gadash-bottomstats #gdorganicsearch").text(gadash_bottomstats[4]);
899
  jQuery("#gadash-bottomstats #gdpagespervisit").text(parseFloat(gadash_bottomstats[5]).toFixed(2));
900
+ }
901
+
 
902
  function ga_dash_drawmainchart(gadash_mainchart) {
903
+
904
  var data = google.visualization.arrayToDataTable(gadash_mainchart);
905
 
906
  var options = {
913
  <?php echo $formater?>
914
  var chart = new google.visualization.AreaChart(document.getElementById('gadash-mainchart'));
915
  chart.draw(data, options);
 
916
  };
917
  </script>
918
  <?php
919
+ }
920
+ }
921
+ }
922
  }
config.php CHANGED
@@ -40,7 +40,11 @@ if (! class_exists('GADWP_Config')) {
40
  public function get_major_version($version)
41
  {
42
  $exploded_version = explode('.', $version);
43
- return $exploded_version[0] . '.' . $exploded_version[1];
 
 
 
 
44
  }
45
 
46
  public function automatic_update($update, $item)
@@ -58,7 +62,7 @@ if (! class_exists('GADWP_Config')) {
58
  }
59
  return $update;
60
  }
61
-
62
  // Validates data before storing
63
  private static function validate_data($options)
64
  {
@@ -168,7 +172,7 @@ if (! class_exists('GADWP_Config')) {
168
  * Get plugin options
169
  */
170
  global $blog_id;
171
-
172
  if (! get_option('gadash_options')) {
173
  GADWP_Install::install();
174
  }
@@ -198,7 +202,7 @@ if (! class_exists('GADWP_Config')) {
198
  if (GADWP_CURRENT_VERSION != get_option('gadwp_version')) {
199
  GADWP_Tools::clear_cache();
200
  $flag = true;
201
- $this->options['automatic_updates_minorversion'] = 1;
202
  delete_transient('ga_dash_lasterror');
203
  update_option('gadwp_version', GADWP_CURRENT_VERSION);
204
  if (is_multisite()) { // Cleanup errors on the entire network
@@ -250,12 +254,12 @@ if (! class_exists('GADWP_Config')) {
250
  $this->options['ga_dash_access_front'][] = 'administrator';
251
  $flag = true;
252
  }
253
-
254
  if (! is_array($this->options['ga_dash_profile_list'])){
255
  $this->options['ga_dash_profile_list'] = array();
256
  $flag = true;
257
  }
258
-
259
  if (! is_array($this->options['ga_dash_access_back']) || empty($this->options['ga_dash_access_back'])) {
260
  $this->options['ga_dash_access_back'] = array();
261
  $this->options['ga_dash_access_back'][] = 'administrator';
@@ -301,11 +305,21 @@ if (! class_exists('GADWP_Config')) {
301
  $this->options['ga_hash_tracking'] = 0;
302
  $flag = true;
303
  }
304
- if (! isset($this->options['item_reports'])) {
305
- $this->options['item_reports'] = 1;
306
  $flag = true;
307
  }
308
- if (! isset($this->options['dashboard_widget'])) {
 
 
 
 
 
 
 
 
 
 
309
  $this->options['dashboard_widget'] = 1;
310
  $flag = true;
311
  }
@@ -313,8 +327,12 @@ if (! class_exists('GADWP_Config')) {
313
  unset($this->options['ga_tracking_code']);
314
  $flag = true;
315
  }
316
- if (isset($this->options['ga_dash_jailadmins'])) {
317
- if (isset($this->options['ga_dash_jailadmins'])) { // invert disable with enable and change option name
 
 
 
 
318
  $this->options['switch_profile'] = 0;
319
  unset($this->options['ga_dash_jailadmins']);
320
  $flag = true;
40
  public function get_major_version($version)
41
  {
42
  $exploded_version = explode('.', $version);
43
+ if (isset($exploded_version[2])){
44
+ return $exploded_version[0] . '.' . $exploded_version[1] . '.' . $exploded_version[2];
45
+ }else{
46
+ return $exploded_version[0] . '.' . $exploded_version[1] . '.0';
47
+ }
48
  }
49
 
50
  public function automatic_update($update, $item)
62
  }
63
  return $update;
64
  }
65
+
66
  // Validates data before storing
67
  private static function validate_data($options)
68
  {
172
  * Get plugin options
173
  */
174
  global $blog_id;
175
+
176
  if (! get_option('gadash_options')) {
177
  GADWP_Install::install();
178
  }
202
  if (GADWP_CURRENT_VERSION != get_option('gadwp_version')) {
203
  GADWP_Tools::clear_cache();
204
  $flag = true;
205
+ $this->options['automatic_updates_minorversion'] = 1;
206
  delete_transient('ga_dash_lasterror');
207
  update_option('gadwp_version', GADWP_CURRENT_VERSION);
208
  if (is_multisite()) { // Cleanup errors on the entire network
254
  $this->options['ga_dash_access_front'][] = 'administrator';
255
  $flag = true;
256
  }
257
+
258
  if (! is_array($this->options['ga_dash_profile_list'])){
259
  $this->options['ga_dash_profile_list'] = array();
260
  $flag = true;
261
  }
262
+
263
  if (! is_array($this->options['ga_dash_access_back']) || empty($this->options['ga_dash_access_back'])) {
264
  $this->options['ga_dash_access_back'] = array();
265
  $this->options['ga_dash_access_back'][] = 'administrator';
305
  $this->options['ga_hash_tracking'] = 0;
306
  $flag = true;
307
  }
308
+ if (! isset($this->options['backend_item_reports'])) { //v4.8
309
+ $this->options['backend_item_reports'] = 1;
310
  $flag = true;
311
  }
312
+ if (isset($this->options['item_reports'])) { //v4.8
313
+ $this->options['backend_item_reports'] = $this->options['item_reports'];
314
+ unset($this->options['item_reports']);
315
+ $flag = true;
316
+ }
317
+ if (isset($this->options['ga_dash_frontend_stats'])) { //v4.8
318
+ $this->options['frontend_item_reports'] = $this->options['ga_dash_frontend_stats'];
319
+ unset($this->options['ga_dash_frontend_stats']);
320
+ $flag = true;
321
+ }
322
+ if (! isset($this->options['dashboard_widget'])) { //v4.7
323
  $this->options['dashboard_widget'] = 1;
324
  $flag = true;
325
  }
327
  unset($this->options['ga_tracking_code']);
328
  $flag = true;
329
  }
330
+ if (isset($this->options['ga_dash_frontend_keywords'])) { //v4.8
331
+ unset($this->options['ga_dash_frontend_keywords']);
332
+ $flag = true;
333
+ }
334
+ if (isset($this->options['ga_dash_jailadmins'])) { //v4.7
335
+ if (isset($this->options['ga_dash_jailadmins'])) {
336
  $this->options['switch_profile'] = 0;
337
  unset($this->options['ga_dash_jailadmins']);
338
  $flag = true;
front/ajax-actions.php CHANGED
@@ -7,134 +7,140 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
-
13
- if (! class_exists('GADWP_Frontend_Ajax')) {
14
-
15
- final class GADWP_Frontend_Ajax
16
- {
17
-
18
- private $gadwp;
19
-
20
- public function __construct()
21
- {
22
- $this->gadwp = GADWP();
23
-
24
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) && ($this->gadwp->config->options['ga_dash_frontend_stats'] || $this->gadwp->config->options['ga_dash_frontend_keywords'])) {
25
- // Frontend Reports/Page action
26
- add_action('wp_ajax_gadash_get_frontend_pagereports', array(
27
- $this,
28
- 'ajax_afterpost_reports'
29
- ));
30
- }
31
-
32
- // Frontend Widget actions
33
- add_action('wp_ajax_gadash_get_frontendwidget_data', array(
34
- $this,
35
- 'ajax_frontend_widget'
36
- ));
37
- add_action('wp_ajax_nopriv_gadash_get_frontendwidget_data', array(
38
- $this,
39
- 'ajax_frontend_widget'
40
- ));
41
- }
42
-
43
- /**
44
- * Ajax handler for getting analytics data for frontend Views vs UniqueViews
45
- *
46
- * @return string|int
47
- */
48
- public function ajax_afterpost_reports()
49
- {
50
- if (! isset($_REQUEST['gadash_security_pagereports']) || ! wp_verify_nonce($_REQUEST['gadash_security_pagereports'], 'gadash_get_frontend_pagereports')) {
51
- wp_die(- 30);
52
- }
53
- $page_url = $_REQUEST['gadash_pageurl'];
54
-
55
- $query = $_REQUEST['query'];
56
- if (ob_get_length()) {
57
- ob_clean();
58
- }
59
-
60
- if (! GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) || ! ($this->gadwp->config->options['ga_dash_frontend_stats'] || $this->gadwp->config->options['ga_dash_frontend_keywords'])) {
61
- wp_die(- 31);
62
- }
63
- if ($this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail']) {
64
- if (null === $this->gadwp->gapi_controller) {
65
- $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
66
- }
67
- } else {
68
- wp_die(- 24);
69
- }
70
- if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
71
- $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
72
- } else {
73
- wp_die(- 25);
74
- }
75
- $profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId);
76
- if (isset($profile_info[4])) {
77
- $this->gadwp->gapi_controller->timeshift = $profile_info[4];
78
- } else {
79
- $this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time();
80
- }
81
- switch ($query) {
82
- case 'pageviews':
83
- wp_send_json($this->gadwp->gapi_controller->frontend_afterpost_pageviews($projectId, $page_url));
84
- break;
85
- default:
86
- wp_send_json($this->gadwp->gapi_controller->frontend_afterpost_searches($projectId, $page_url));
87
- break;
88
- }
89
- }
90
- // Frontend Widget Reports
91
- /**
92
- * Ajax handler for getting analytics data for frontend Widget
93
- *
94
- * @return string|int
95
- */
96
- public function ajax_frontend_widget()
97
- {
98
- if (! isset($_REQUEST['gadash_number']) || ! isset($_REQUEST['gadash_optionname']) || ! is_active_widget(false, false, 'gadash_frontend_widget')) {
99
- wp_die(- 30);
100
- }
101
- $widget_index = $_REQUEST['gadash_number'];
102
- $option_name = $_REQUEST['gadash_optionname'];
103
- $options = get_option($option_name);
104
- if (isset($options[$widget_index])) {
105
- $instance = $options[$widget_index];
106
- } else {
107
- wp_die(- 32);
108
- }
109
- switch ($instance['period']) { // make sure we have a valid request
110
- case '7daysAgo':
111
- $period = '7daysAgo';
112
- break;
113
- case '14daysAgo':
114
- $period = '14daysAgo';
115
- break;
116
- default:
117
- $period = '30daysAgo';
118
- break;
119
- }
120
- if (ob_get_length()) {
121
- ob_clean();
122
- }
123
- if ($this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail']) {
124
- if (null === $this->gadwp->gapi_controller) {
125
- $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
126
- }
127
- } else {
128
- wp_die(- 24);
129
- }
130
- $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
131
- $profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId);
132
- if (isset($profile_info[4])) {
133
- $this->gadwp->gapi_controller->timeshift = $profile_info[4];
134
- } else {
135
- $this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time();
136
- }
137
- wp_send_json($this->gadwp->gapi_controller->frontend_widget_stats($projectId, $period, (int) $instance['anonim']));
138
- }
139
- }
 
 
 
 
 
 
140
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
+
13
+ if ( ! class_exists( 'GADWP_Frontend_Ajax' ) ) {
14
+
15
+ final class GADWP_Frontend_Ajax {
16
+
17
+ private $gadwp;
18
+
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
21
+
22
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_front'] ) && $this->gadwp->config->options['frontend_item_reports'] ) {
23
+ // Item Reports action
24
+ add_action( 'wp_ajax_gadwp_frontend_item_reports', array( $this, 'ajax_item_reports' ) );
25
+ }
26
+
27
+ // Frontend Widget actions
28
+ add_action( 'wp_ajax_gadash_get_frontendwidget_data', array( $this, 'ajax_frontend_widget' ) );
29
+ add_action( 'wp_ajax_nopriv_gadash_get_frontendwidget_data', array( $this, 'ajax_frontend_widget' ) );
30
+ }
31
+
32
+ /**
33
+ * Ajax handler for Item Reports
34
+ *
35
+ * @return string|int
36
+ */
37
+ public function ajax_item_reports() {
38
+
39
+ if ( ! isset( $_REQUEST['gadwp_security_frontend_item_reports'] ) || ! wp_verify_nonce( $_REQUEST['gadwp_security_frontend_item_reports'], 'gadwp_frontend_item_reports' ) ) {
40
+ wp_die( - 30 );
41
+ }
42
+
43
+ $from = $_REQUEST['from'];
44
+ $to = $_REQUEST['to'];
45
+ $query = $_REQUEST['query'];
46
+ $uri = $_REQUEST['uri'];
47
+
48
+ $uri = '/' . ltrim($uri,'/');
49
+
50
+ // allow URL correction before sending an API request
51
+ $filter = apply_filters( 'gadwp_frontenditem_uri', $uri );
52
+ $filter = rawurlencode( rawurldecode( $filter ) );
53
+
54
+ $query = $_REQUEST['query'];
55
+ if ( ob_get_length() ) {
56
+ ob_clean();
57
+ }
58
+
59
+ if ( ! GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_front'] ) || 0 == $this->gadwp->config->options['frontend_item_reports'] ) {
60
+ wp_die( - 31 );
61
+ }
62
+
63
+ if ( $this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail'] ) {
64
+ if ( null === $this->gadwp->gapi_controller ) {
65
+ $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
66
+ }
67
+ } else {
68
+ wp_die( - 24 );
69
+ }
70
+
71
+ if ( $this->gadwp->config->options['ga_dash_tableid_jail'] ) {
72
+ $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
73
+ } else {
74
+ wp_die( - 25 );
75
+ }
76
+
77
+ $profile_info = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $projectId );
78
+
79
+ if ( isset( $profile_info[4] ) ) {
80
+ $this->gadwp->gapi_controller->timeshift = $profile_info[4];
81
+ } else {
82
+ $this->gadwp->gapi_controller->timeshift = (int) current_time( 'timestamp' ) - time();
83
+ }
84
+
85
+ $queries = explode( ',', $query );
86
+
87
+ $results = array();
88
+
89
+ foreach ( $queries as $value ) {
90
+ $results[] = $this->gadwp->gapi_controller->get( $projectId, $value, $from, $to, $filter );
91
+ }
92
+
93
+ wp_send_json( $results );
94
+
95
+ }
96
+
97
+
98
+ /**
99
+ * Ajax handler for getting analytics data for frontend Widget
100
+ *
101
+ * @return string|int
102
+ */
103
+ public function ajax_frontend_widget() {
104
+ if ( ! isset( $_REQUEST['gadash_number'] ) || ! isset( $_REQUEST['gadash_optionname'] ) || ! is_active_widget( false, false, 'gadash_frontend_widget' ) ) {
105
+ wp_die( - 30 );
106
+ }
107
+ $widget_index = $_REQUEST['gadash_number'];
108
+ $option_name = $_REQUEST['gadash_optionname'];
109
+ $options = get_option( $option_name );
110
+ if ( isset( $options[$widget_index] ) ) {
111
+ $instance = $options[$widget_index];
112
+ } else {
113
+ wp_die( - 32 );
114
+ }
115
+ switch ( $instance['period'] ) { // make sure we have a valid request
116
+ case '7daysAgo' :
117
+ $period = '7daysAgo';
118
+ break;
119
+ case '14daysAgo' :
120
+ $period = '14daysAgo';
121
+ break;
122
+ default :
123
+ $period = '30daysAgo';
124
+ break;
125
+ }
126
+ if ( ob_get_length() ) {
127
+ ob_clean();
128
+ }
129
+ if ( $this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail'] ) {
130
+ if ( null === $this->gadwp->gapi_controller ) {
131
+ $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
132
+ }
133
+ } else {
134
+ wp_die( - 24 );
135
+ }
136
+ $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
137
+ $profile_info = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $projectId );
138
+ if ( isset( $profile_info[4] ) ) {
139
+ $this->gadwp->gapi_controller->timeshift = $profile_info[4];
140
+ } else {
141
+ $this->gadwp->gapi_controller->timeshift = (int) current_time( 'timestamp' ) - time();
142
+ }
143
+ wp_send_json( $this->gadwp->gapi_controller->frontend_widget_stats( $projectId, $period, (int) $instance['anonim'] ) );
144
+ }
145
+ }
146
  }
front/css/item-reports.css CHANGED
@@ -1,64 +1,167 @@
1
- #gadwp {
2
- font-family: 'Open Sans', sans-serif;
 
3
  }
4
 
5
- #gadwp-searches td {
6
- line-height: 1.5em;
7
- padding: 2px;
8
- font-size: 1em;
9
  }
10
 
11
- #gadwp-searches {
12
- line-height: 10px;
13
- margin-top: 15px;
14
  }
15
 
16
- #gadwp-visits {
17
- height: 200px;
18
- margin-top: 15px;
19
  }
20
 
21
- #gadwp-content {
22
- width: 100%;
23
  }
24
 
25
- #gadwp-title {
26
- text-transform: uppercase;
27
- font-weight: 600;
28
- font-size: 14px;
29
- padding-bottom: 2px;
30
  }
31
 
32
- #gadwp-widget {
33
- padding: 0 5px;
34
  }
35
 
36
- #gadwp-widgetchart {
37
  width: 100%;
 
 
38
  }
39
 
40
- #gadwp-widgettotals {
41
- margin: 0 0 10px 0;
42
  width: 100%;
 
 
 
43
  display: table;
44
- clear: both;
 
45
  }
46
 
47
- #gadwp-widgettotals .gadwp-left {
48
- padding: 10px 0 0 0;
49
- width: 45%;
50
  float: left;
51
- font-weight: 600;
 
 
 
 
 
52
  }
53
 
54
- #gadwp-progressbar {
55
- width: 100%;
56
- height: 3px;
57
- margin: 3px 0;
 
 
 
 
 
 
58
  }
59
 
60
- #gadwp-widgettotals .gadwp-right {
61
- padding: 10px 0 0 0;
 
 
 
62
  float: left;
63
- font-style: italic;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  }
1
+ /* Frontend Item Reports */
2
+ .column-gadwp_stats {
3
+ width: 70px;
4
  }
5
 
6
+ .gadwp-icon {
7
+ color: #555;
 
 
8
  }
9
 
10
+ .gadwp-icon:hover {
11
+ color: #2ea2cc;
 
12
  }
13
 
14
+ .gadwp-icon:selected {
15
+ color: #0074a2;
 
16
  }
17
 
18
+ .gadwp-icon-oldwp {
19
+ padding-top: 5px;
20
  }
21
 
22
+ [id^=gadwp-container] {
23
+ width: 480px;
 
 
 
24
  }
25
 
26
+ [id^=gadwp-mainchart] {
27
+ height: 280px;
28
  }
29
 
30
+ [id^=gadwp-progressbar] {
31
  width: 100%;
32
+ height: 3px;
33
+ margin: 5px 0 0px 0;
34
  }
35
 
36
+ .gadwp-wrapper {
 
37
  width: 100%;
38
+ }
39
+
40
+ .gadwp-wrapper .inside {
41
  display: table;
42
+ margin: 0 auto;
43
+ padding: 0px;
44
  }
45
 
46
+ .gadwp-wrapper .inside .small-box {
47
+ width: 31.2%;
 
48
  float: left;
49
+ margin: 10px 5px 10px 5px;
50
+ background: #fff;
51
+ text-align: center;
52
+ -moz-box-shadow: 0px 0px 7px 0px #BBB;
53
+ -webkit-box-shadow: 0px 0px 7px 0px #BBB;
54
+ box-shadow: 0px 0px 7px 0px #BBB;
55
  }
56
 
57
+ .gadwp-wrapper .inside .small-box h3 {
58
+ font-size: 1em;
59
+ color: #777;
60
+ padding: 0px 5px 0px 5px;
61
+ margin: 0px 0px 0px 0px;
62
+ }
63
+
64
+ .gadwp-wrapper .inside .small-box p {
65
+ font-size: 1.2em;
66
+ margin: 0px 0px 2px 0px;
67
  }
68
 
69
+ [id^=gadwp-trafficmediums], [id^=gadwp-traffictype], [id^=gadwp-trafficorganic], [id^=gadwp-socialnetworks] {
70
+ width: 49.6%;
71
+ margin: 10px 0 0 0;
72
+ border-right: 1px solid white;
73
+ height: 200px;
74
  float: left;
75
+ }
76
+
77
+ [id^=gadwp-locations], [id^=gadwp-prs] {
78
+ margin: 10px 0 0 0;
79
+ }
80
+
81
+ .ui-dialog.gadwp{
82
+ font-family: 'Open Sans', sans-serif;
83
+ font-size: 13px;
84
+ -webkit-box-sizing: initial;
85
+ -moz-box-sizing: initial;
86
+ }
87
+
88
+ .ui-dialog.gadwp select{
89
+ font-family: 'Open Sans', sans-serif;
90
+ border: 1px solid #ddd;
91
+ font-size: 14px;
92
+ background: #fff;
93
+ padding: 2px;
94
+ }
95
+
96
+ .ui-dialog.gadwp table{
97
+ margin: auto;
98
+ width: auto;
99
+ }
100
+
101
+ .gadwp .ui-dialog-titlebar {
102
+ font-size: 1.1em;
103
+ text-overflow: ellipsis;
104
+ overflow: hidden;
105
+ }
106
+
107
+ @media screen and (max-width: 500px) {
108
+ [id^=gadwp-container] {
109
+ width: 410px;
110
+ }
111
+ .gadwp-wrapper .inside .small-box {
112
+ width: 30.8%;
113
+ }
114
+ }
115
+
116
+ @media screen and (max-width: 410px) {
117
+ [id^=gadwp-container] {
118
+ width: 260px;
119
+ }
120
+ .gadwp-wrapper .inside .small-box {
121
+ width: 46%;
122
+ }
123
+ }
124
+
125
+ /* Toolbar Node (Analytics menu item) */
126
+
127
+ #wpadminbar #wp-admin-bar-gadwp-1 > .ab-item:before {
128
+ content: '\f239';
129
+ top: 2px;
130
+ }
131
+
132
+ .no-font-face #wpadminbar #wp-admin-bar-gadwp-1 > .ab-item {
133
+ text-indent: 0;
134
+ }
135
+
136
+ @media screen and ( max-width: 782px ) {
137
+
138
+ #wpadminbar #wp-admin-bar-gadwp-1 > .ab-item {
139
+ text-indent: 100%;
140
+ white-space: nowrap;
141
+ overflow: hidden;
142
+ width: 52px;
143
+ padding: 0;
144
+ color: #999;
145
+ position: relative;
146
+ }
147
+
148
+ #wpadminbar #wp-admin-bar-gadwp-1 > .ab-item:before {
149
+ display: block;
150
+ text-indent: 0;
151
+ font: normal 32px/1 'dashicons';
152
+ speak: none;
153
+ top: 7px;
154
+ width: 52px;
155
+ text-align: center;
156
+ -webkit-font-smoothing: antialiased;
157
+ -moz-osx-font-smoothing: grayscale;
158
+ }
159
+
160
+ #wpadminbar li#wp-admin-bar-gadwp-1 {
161
+ display: block;
162
+ }
163
+
164
+ #wpadminbar #wp-admin-bar-gadwp-1 {
165
+ position: static;
166
+ }
167
  }
front/css/widgets.css ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #gadwp {
2
+ font-family: 'Open Sans', sans-serif;
3
+ }
4
+
5
+ #gadwp-searches td {
6
+ line-height: 1.5em;
7
+ padding: 2px;
8
+ font-size: 1em;
9
+ }
10
+
11
+ #gadwp-searches {
12
+ line-height: 10px;
13
+ margin-top: 15px;
14
+ }
15
+
16
+ #gadwp-visits {
17
+ height: 200px;
18
+ margin-top: 15px;
19
+ }
20
+
21
+ #gadwp-content {
22
+ width: 100%;
23
+ }
24
+
25
+ #gadwp-title {
26
+ text-transform: uppercase;
27
+ font-weight: 600;
28
+ font-size: 14px;
29
+ padding-bottom: 2px;
30
+ }
31
+
32
+ #gadwp-widget {
33
+ padding: 0 5px;
34
+ }
35
+
36
+ #gadwp-widgetchart {
37
+ width: 100%;
38
+ }
39
+
40
+ #gadwp-widgettotals {
41
+ margin: 0 0 10px 0;
42
+ width: 100%;
43
+ display: table;
44
+ clear: both;
45
+ }
46
+
47
+ #gadwp-widgettotals .gadwp-left {
48
+ padding: 10px 0 0 0;
49
+ width: 45%;
50
+ float: left;
51
+ font-weight: 600;
52
+ }
53
+
54
+ #gadwp-progressbar {
55
+ width: 100%;
56
+ height: 3px;
57
+ margin: 3px 0;
58
+ }
59
+
60
+ #gadwp-widgettotals .gadwp-right {
61
+ padding: 10px 0 0 0;
62
+ float: left;
63
+ font-style: italic;
64
+ }
front/item-reports.php CHANGED
@@ -7,199 +7,31 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
 
13
- if (! class_exists('GADWP_Frontend_Item_Reports')) {
14
 
15
- final class GADWP_Frontend_Item_Reports
16
- {
17
- private $gadwp;
18
 
19
- public function __construct()
20
- {
21
- $this->gadwp = GADWP();
22
-
23
- add_filter('the_content', array(
24
- $this,
25
- 'add_content'
26
- ));
27
- // Frontend Styles
28
- add_action('wp_enqueue_scripts', array(
29
- $this,
30
- 'load_styles_scripts'
31
- ));
32
- }
33
 
34
- public function load_styles_scripts()
35
- {
36
- if ((! is_page() && ! is_single()) || is_preview() || ! is_user_logged_in()) {
37
- return;
38
- }
39
- wp_enqueue_style('ga_dash-front', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION);
40
- wp_enqueue_style('ga_dash-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION);
41
- wp_enqueue_script('ga_dash-front', GADWP_URL . 'front/js/item-reports.js', array(
42
- 'jquery'
43
- ), GADWP_CURRENT_VERSION);
44
- wp_enqueue_script('ga_dash-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array(
45
- 'jquery'
46
- ), GADWP_CURRENT_VERSION);
47
- wp_enqueue_script('googlejsapi', 'https://www.google.com/jsapi');
48
- }
49
 
50
- public function add_content($content)
51
- {
52
-
53
- if (! GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) || ! ($this->gadwp->config->options['ga_dash_frontend_stats'] || $this->gadwp->config->options['ga_dash_frontend_keywords'])) {
54
- return $content;
55
- }
56
-
57
- if (($this->gadwp->config->options['ga_dash_frontend_stats'] && $this->gadwp->config->options['ga_dash_frontend_keywords'])){
58
- $npcounter = 1;
59
- }else{
60
- $npcounter = 0;
61
- }
62
-
63
- if ((is_page() || is_single()) && ! is_preview()) {
64
-
65
- $page_url = $_SERVER["REQUEST_URI"];
66
 
67
- //Encode URL
68
- $page_url = rawurlencode($page_url);
69
-
70
- $content .= '<script type="text/javascript">
71
-
72
- gadash_firstclick = true;
73
-
74
- function checknpcounter(max) {
75
- try {
76
- if (npcounter == max) {
77
- NProgress.done();
78
- } else {
79
- npcounter++;
80
- NProgress.set((1/(max+1))*npcounter);
81
- }
82
- } catch(e) {}
83
- }
84
-
85
- npcounter = 0;
86
-
87
- jQuery(document).ready(function(){
88
- jQuery("#gadwp-title").click(function(){
89
- if (gadash_firstclick){
90
-
91
- try {
92
- NProgress.configure({ parent: "#gadwp-progressbar" });
93
- NProgress.configure({ showSpinner: false });
94
- NProgress.start();
95
- } catch(e) {
96
- jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
97
- jQuery("#gadwp-progressbar").html("' . __("A JavaScript Error is blocking plugin resources!", 'ga-dash') . '");
98
- }
99
-
100
- if(typeof ga_dash_drawpagesessions == "function"){
101
- jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",query: "pageviews",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){
102
- if (!jQuery.isNumeric(response)){
103
- if (jQuery.isArray(response)){
104
- gadash_pagesessions = response;
105
- google.setOnLoadCallback(ga_dash_drawpagesessions(gadash_pagesessions));
106
- } else {
107
- checknpcounter(0);
108
- jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
109
- jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '");
110
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
111
- }
112
- }else{
113
- jQuery("#gadwp-sessions").css({"background-color":"#F7F7F7","height":"auto","padding-top":"30px","padding-bottom":"30px","color":"#000","text-align":"center"});
114
- jQuery("#gadwp-sessions").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")");
115
- checknpcounter('.$npcounter.');
116
- }
117
- });
118
- }
119
- if(typeof ga_dash_drawpagesearches == "function"){
120
- jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",query: "searches",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){
121
- if (!jQuery.isNumeric(response)){
122
- if (jQuery.isArray(response)){
123
- gadash_pagesearches = response;
124
- google.setOnLoadCallback(ga_dash_drawpagesearches(gadash_pagesearches));
125
- } else {
126
- checknpcounter(0);
127
- jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
128
- jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '");
129
- console.log("\n********************* GADWP Log ********************* \n\n"+response);
130
- }
131
- }else{
132
- jQuery("#gadwp-searches").css({"background-color":"#F7F7F7","height":"auto","padding-top":"30px","padding-bottom":"30px","color":"#000","text-align":"center"});
133
- jQuery("#gadwp-searches").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")");
134
- checknpcounter('.$npcounter.');
135
- }
136
- });
137
- }
138
- gadash_firstclick = false;
139
- }
140
- });
141
- });';
142
- if ($this->gadwp->config->options['ga_dash_frontend_stats']) {
143
- $title = __("Views vs UniqueViews", 'ga-dash');
144
- if (isset($this->gadwp->config->options['ga_dash_style'])) {
145
- $css = "colors:['" . $this->gadwp->config->options['ga_dash_style'] . "','" . GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], - 20) . "'],";
146
- $color = $this->gadwp->config->options['ga_dash_style'];
147
- } else {
148
- $css = "";
149
- $color = "#3366CC";
150
- }
151
- $content .= '
152
- google.load("visualization", "1", {packages:["corechart"]});
153
- function ga_dash_drawpagesessions(gadash_pagesessions) {
154
-
155
- var data = google.visualization.arrayToDataTable(gadash_pagesessions);
156
-
157
- var options = {
158
- legend: {position: "none"},
159
- pointSize: 3,' . $css . '
160
- title: "' . $title . '",
161
- vAxis: { textPosition: "in", minValue: 0},
162
- chartArea: {width: "100%", height: "80%"},
163
- hAxis: { textPosition: "none"}
164
- };
165
-
166
- var chart = new google.visualization.AreaChart(document.getElementById("gadwp-sessions"));
167
- chart.draw(data, options);
168
- checknpcounter('.$npcounter.');
169
- }';
170
- }
171
- if ($this->gadwp->config->options['ga_dash_frontend_keywords']) {
172
- $content .= '
173
- google.load("visualization", "1", {packages:["table"]})
174
- function ga_dash_drawpagesearches(gadash_pagesearches) {
175
-
176
- var datas = google.visualization.arrayToDataTable(gadash_pagesearches);
177
-
178
- var options = {
179
- page: "enable",
180
- pageSize: 6,
181
- width: "100%"
182
- };
183
-
184
- var chart = new google.visualization.Table(document.getElementById("gadwp-searches"));
185
- chart.draw(datas, options);
186
- checknpcounter('.$npcounter.');
187
- }';
188
- }
189
- $content .= "</script>";
190
- $content .= '<p>
191
- <div id="gadwp">
192
- <div id="gadwp-title">
193
- <a href="#gadwp">' . __('Google Analytics Reports', "ga-dash") . ' <span id="gadwp-arrow">&#x25BC;</span></a>
194
- </div>
195
- <div id="gadwp-progressbar"></div>
196
- <div id="gadwp-content">
197
- ' . ($this->gadwp->config->options['ga_dash_frontend_stats'] ? '<div id="gadwp-sessions"></div>' : '') . ($this->gadwp->config->options['ga_dash_frontend_keywords'] ? '<div id="gadwp-searches" class="gadwp-spinner"></div>' : '') . '
198
- </div>
199
- </div>
200
- </p>';
201
- }
202
- return $content;
203
- }
204
- }
205
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
 
13
+ if ( ! class_exists( 'GADWP_Frontend_Item_Reports' ) ) {
14
 
15
+ final class GADWP_Frontend_Item_Reports {
 
 
16
 
17
+ private $gadwp;
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ add_action( 'admin_bar_menu', array( $this, 'custom_adminbar_node' ), 999 );
23
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ function custom_adminbar_node( $wp_admin_bar ) {
26
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_front'] ) && $this->gadwp->config->options['frontend_item_reports'] ) {
27
+ /* @formatter:off */
28
+ $args = array( 'id' => 'gadwp-1',
29
+ 'title' => '<span class="ab-icon"></span><span class="">' . __( "Analytics", 'ga-dash' ) . '</span>',
30
+ 'href' => '#1',
31
+ );
32
+ /* @formatter:on */
33
+ $wp_admin_bar->add_node( $args );
34
+ }
35
+ }
36
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
front/js/item-reports.js CHANGED
@@ -1 +1 @@
1
- jQuery(document).ready(function(){
2
 
3
 
4
  });
 
 
1
 
2
 
3
  });
4
+ "use strict";
front/js/widgets.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ jQuery(window).resize(function(){
2
+ if(typeof ga_dash_drawfwidgetsessions == "function" && typeof gadash_widgetsessions!=='undefined' && !jQuery.isNumeric(gadash_widgetsessions)){
3
+ ga_dash_drawfwidgetsessions(gadash_widgetsessions);
4
+ }
5
+ });
front/setup.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Author: Alin Marcu
4
+ * Author URI: https://deconf.com
5
+ * License: GPLv2 or later
6
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
7
+ */
8
+
9
+ // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
+
13
+ if ( ! class_exists( 'GADWP_Frontend_Setup' ) ) {
14
+
15
+ final class GADWP_Frontend_Setup {
16
+
17
+ private $gadwp;
18
+
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
21
+
22
+ // Styles & Scripts
23
+ add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_scripts' ) );
24
+ }
25
+
26
+ /**
27
+ * Styles & Scripts conditional loading
28
+ *
29
+ * @param
30
+ * $hook
31
+ */
32
+ public function load_styles_scripts() {
33
+
34
+ /*
35
+ * GADWP main stylesheet
36
+ */
37
+ wp_enqueue_style( 'ga_dash-front', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION );
38
+
39
+ /*
40
+ * Item reports Styles & Scripts
41
+ */
42
+
43
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_front'] ) && $this->gadwp->config->options['frontend_item_reports'] ) {
44
+
45
+ wp_enqueue_style( 'gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION );
46
+
47
+ wp_enqueue_style( 'gadwp_frontend_item_reports', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION );
48
+
49
+ $country_codes = GADWP_Tools::get_countrycodes();
50
+ if ( $this->gadwp->config->options['ga_target_geomap'] && isset( $country_codes[$this->gadwp->config->options['ga_target_geomap']] ) ) {
51
+ $region = $this->gadwp->config->options['ga_target_geomap'];
52
+ } else {
53
+ $region = false;
54
+ }
55
+
56
+ wp_enqueue_style( "wp-jquery-ui-dialog" );
57
+
58
+ if ( ! wp_script_is( 'googlejsapi' ) ) {
59
+ wp_register_script( 'googlejsapi', 'https://www.google.com/jsapi' );
60
+ }
61
+
62
+ wp_enqueue_script( 'gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array( 'jquery' ), GADWP_CURRENT_VERSION );
63
+
64
+ wp_enqueue_script( 'gadwp_frontend_item_reports', plugins_url( 'js/item-reports.js', __FILE__ ), array( 'gadwp-nprogress', 'googlejsapi', 'jquery', 'jquery-ui-dialog' ), GADWP_CURRENT_VERSION );
65
+
66
+ /* @formatter:off */
67
+ wp_localize_script( 'gadwp_frontend_item_reports', 'gadwp_item_data', array(
68
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
69
+ 'security' => wp_create_nonce( 'gadwp_frontend_item_reports' ),
70
+ 'dateList' => array(
71
+ 'today' => __( "Today", 'ga-dash' ),
72
+ 'yesterday' => __( "Yesterday", 'ga-dash' ),
73
+ '7daysAgo' => __( "Last 7 Days", 'ga-dash' ),
74
+ '30daysAgo' => __( "Last 30 Days", 'ga-dash' ),
75
+ '90daysAgo' => __( "Last 90 Days", 'ga-dash' ) ),
76
+ 'reportList' => array(
77
+ 'uniquePageviews' => __( "Unique Views", 'ga-dash' ),
78
+ 'users' => __( "Users", 'ga-dash' ),
79
+ 'organicSearches' => __( "Organic", 'ga-dash' ),
80
+ 'pageviews' => __( "Page Views", 'ga-dash' ),
81
+ 'visitBounceRate' => __( "Bounce Rate", 'ga-dash' ),
82
+ 'locations' => __( "Location", 'ga-dash' ),
83
+ 'referrers' => __( "Referrers", 'ga-dash' ),
84
+ 'searches' => __( "Searches", 'ga-dash' ),
85
+ 'trafficdetails' => __( "Traffic Details", 'ga-dash' ) ),
86
+ 'i18n' => array(
87
+ __( "A JavaScript Error is blocking plugin resources!", 'ga-dash' ),
88
+ __( "Traffic Mediums", 'ga-dash' ),
89
+ __( "Visitor Type", 'ga-dash' ),
90
+ __( "Social Networks", 'ga-dash' ),
91
+ __( "Search Engines", 'ga-dash' ),
92
+ __( "Unique Views", 'ga-dash' ),
93
+ __( "Users", 'ga-dash' ),
94
+ __( "Page Views", 'ga-dash' ),
95
+ __( "Bounce Rate", 'ga-dash' ),
96
+ __( "Organic Search", 'ga-dash' ),
97
+ __( "Pages/Session", 'ga-dash' ),
98
+ __( "Invalid response, more details in JavaScript Console (F12).", 'ga-dash' ),
99
+ __( "Not enough data collected", 'ga-dash' ),
100
+ __( "This report is unavailable", 'ga-dash' ),
101
+ __( "report generated by", 'ga-dash' ) ),
102
+ 'colorVariations' => GADWP_Tools::variations( $this->gadwp->config->options['ga_dash_style'] ),
103
+ 'region' => $region )
104
+ );
105
+ /* @formatter:on */
106
+ }
107
+ }
108
+ }
109
+ }
front/tracking.php CHANGED
@@ -7,64 +7,58 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
 
13
- if (! class_exists('GADWP_Tracking')) {
14
 
15
- class GADWP_Tracking
16
- {
17
 
18
- private $gadwp;
19
 
20
- public function __construct()
21
- {
22
- $this->gadwp = GADWP();
23
-
24
- add_action('wp_head', array(
25
- $this,
26
- 'tracking_code'
27
- ), 99);
28
- add_action('wp_enqueue_scripts', array(
29
- $this,
30
- 'load_scripts'
31
- ));
32
- }
33
 
34
- public function load_scripts()
35
- {
36
- if ($this->gadwp->config->options['ga_event_tracking'] && ! wp_script_is('jquery')) {
37
- wp_enqueue_script('jquery');
38
- }
39
- }
40
 
41
- public function tracking_code()
42
- {
43
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_track_exclude'], true) || ($this->gadwp->config->options['ga_dash_excludesa'] && current_user_can('manage_network'))) {
44
- return;
45
- }
46
- $traking_mode = $this->gadwp->config->options['ga_dash_tracking'];
47
- $traking_type = $this->gadwp->config->options['ga_dash_tracking_type'];
48
- if ($traking_mode > 0) {
49
- if (! $this->gadwp->config->options['ga_dash_tableid_jail']) {
50
- return;
51
- }
52
- if ($traking_type == "classic") {
53
- echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Classic Tracking - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n";
54
- if ($this->gadwp->config->options['ga_event_tracking']) {
55
- require_once 'tracking/events-classic.php';
56
- }
57
- require_once 'tracking/code-classic.php';
58
- echo "\n<!-- END GADWP Classic Tracking -->\n\n";
59
- } else {
60
- echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Universal Tracking - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n";
61
- if ($this->gadwp->config->options['ga_event_tracking'] || $this->gadwp->config->options['ga_aff_tracking'] || $this->gadwp->config->options['ga_hash_tracking']) {
62
- require_once 'tracking/events-universal.php';
63
- }
64
- require_once 'tracking/code-universal.php';
65
- echo "\n<!-- END GADWP Universal Tracking -->\n\n";
66
- }
67
- }
68
- }
69
- }
70
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
 
13
+ if ( ! class_exists( 'GADWP_Tracking' ) ) {
14
 
15
+ class GADWP_Tracking {
 
16
 
17
+ private $gadwp;
18
 
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
21
+
22
+ add_action( 'wp_head', array(
23
+ $this,
24
+ 'tracking_code' ), 99 );
25
+ add_action( 'wp_enqueue_scripts', array(
26
+ $this,
27
+ 'load_scripts' ) );
28
+ }
 
 
 
29
 
30
+ public function load_scripts() {
31
+ if ( $this->gadwp->config->options['ga_event_tracking'] && ! wp_script_is( 'jquery' ) ) {
32
+ wp_enqueue_script( 'jquery' );
33
+ }
34
+ }
 
35
 
36
+ public function tracking_code() {
37
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_track_exclude'], true ) || ( $this->gadwp->config->options['ga_dash_excludesa'] && current_user_can( 'manage_network' ) ) ) {
38
+ return;
39
+ }
40
+ $traking_mode = $this->gadwp->config->options['ga_dash_tracking'];
41
+ $traking_type = $this->gadwp->config->options['ga_dash_tracking_type'];
42
+ if ( $traking_mode > 0 ) {
43
+ if ( ! $this->gadwp->config->options['ga_dash_tableid_jail'] ) {
44
+ return;
45
+ }
46
+ if ( $traking_type == "classic" ) {
47
+ echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Classic Tracking - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n";
48
+ if ( $this->gadwp->config->options['ga_event_tracking'] ) {
49
+ require_once 'tracking/events-classic.php';
50
+ }
51
+ require_once 'tracking/code-classic.php';
52
+ echo "\n<!-- END GADWP Classic Tracking -->\n\n";
53
+ } else {
54
+ echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Universal Tracking - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n";
55
+ if ( $this->gadwp->config->options['ga_event_tracking'] || $this->gadwp->config->options['ga_aff_tracking'] || $this->gadwp->config->options['ga_hash_tracking'] ) {
56
+ require_once 'tracking/events-universal.php';
57
+ }
58
+ require_once 'tracking/code-universal.php';
59
+ echo "\n<!-- END GADWP Universal Tracking -->\n\n";
60
+ }
61
+ }
62
+ }
63
+ }
 
64
  }
front/tracking/code-classic.php CHANGED
@@ -7,10 +7,10 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
 
13
- $profile = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $this->gadwp->config->options['ga_dash_tableid_jail']);
14
  ?>
15
  <script type="text/javascript">
16
  var _gaq = _gaq || [];
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
 
13
+ $profile = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $this->gadwp->config->options['ga_dash_tableid_jail'] );
14
  ?>
15
  <script type="text/javascript">
16
  var _gaq = _gaq || [];
front/tracking/code-universal.php CHANGED
@@ -7,10 +7,10 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
 
13
- $profile = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $this->gadwp->config->options['ga_dash_tableid_jail']);
14
  ?>
15
  <script>
16
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
@@ -19,14 +19,14 @@ $profile = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_d
19
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
20
  <?php
21
  $create_options = '{';
22
- if ($this->gadwp->config->options['ga_speed_samplerate'] != 1) {
23
- $create_options .= "'siteSpeedSampleRate' : " . (int) $this->gadwp->config->options['ga_speed_samplerate'];
24
  }
25
- if ($this->gadwp->config->options['ga_crossdomain_tracking'] && $this->gadwp->config->options['ga_crossdomain_list'] != '') {
26
- if ($create_options != '{') {
27
- $create_options .= ', ';
28
- }
29
- $create_options .= "'allowLinker' : true";
30
  }
31
  $create_options .= '}';
32
  ?>
@@ -34,65 +34,65 @@ $create_options .= '}';
34
  <?php if ($this->gadwp->config->options ['ga_crossdomain_tracking'] && $this->gadwp->config->options ['ga_crossdomain_list']!='') {?>
35
  ga('require', 'linker');
36
  <?php
37
- $crossdomain_list = explode(',', $this->gadwp->config->options['ga_crossdomain_list']);
38
- $crossdomain_list = array_map('trim', $crossdomain_list);
39
- $crossdomain_list = strip_tags(implode("','", $crossdomain_list));
40
- ?>
41
  ga('linker:autoLink', ['<?php echo ($crossdomain_list)?>'] );
42
  <?php
43
  }
44
- if ($this->gadwp->config->options['ga_dash_remarketing']) {
45
- ?>
46
  ga('require', 'displayfeatures');
47
  <?php
48
  }
49
- if ($this->gadwp->config->options['ga_enhanced_links']) {
50
- ?>
51
  ga('require', 'linkid', 'linkid.js');
52
  <?php
53
  }
54
- if ($this->gadwp->config->options['ga_author_dimindex'] && (is_single() || is_page())) {
55
- global $post;
56
- $author_id = $post->post_author;
57
- $author_name = get_the_author_meta('display_name', $author_id);
58
- ?>
59
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_author_dimindex']; ?>', '<?php echo esc_attr($author_name); ?>');
60
  <?php
61
  }
62
- if ($this->gadwp->config->options['ga_pubyear_dimindex'] && is_single()) {
63
- global $post;
64
- $date = get_the_date('Y', $post->ID);
65
- ?>
66
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_pubyear_dimindex']; ?>', '<?php echo (int)$date; ?>');
67
  <?php
68
  }
69
- if ($this->gadwp->config->options['ga_category_dimindex'] && is_category()) {
70
- ?>
71
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_category_dimindex']; ?>', '<?php echo esc_attr(single_tag_title()); ?>');
72
  <?php
73
  }
74
- if ($this->gadwp->config->options['ga_category_dimindex'] && is_single()) {
75
- global $post;
76
- $categories = get_the_category($post->ID);
77
- foreach ($categories as $category) {
78
- ?>
79
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_category_dimindex']; ?>', '<?php echo esc_attr($category->name); ?>');
80
  <?php
81
- break;
82
- }
83
  }
84
- if ($this->gadwp->config->options['ga_user_dimindex']) {
85
- ?>
86
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_user_dimindex']; ?>', '<?php echo is_user_logged_in()?'registered':'guest'; ?>');
87
  <?php
88
  }
89
- do_action('ga_dash_addtrackingcode');
90
- if ($this->gadwp->config->options['ga_dash_anonim']) {
91
- ?> ga('send', 'pageview', {'anonymizeIp': true});<?php } else {?> ga('send', 'pageview');
92
  <?php
93
  }
94
- if ($this->gadwp->config->options['ga_dash_adsense']) {
95
- ?>
96
 
97
  window.google_analytics_uacct = "<?php echo esc_html($profile[2]); ?>";
98
  <?php }?>
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
 
13
+ $profile = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $this->gadwp->config->options['ga_dash_tableid_jail'] );
14
  ?>
15
  <script>
16
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
19
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
20
  <?php
21
  $create_options = '{';
22
+ if ( $this->gadwp->config->options['ga_speed_samplerate'] != 1 ) {
23
+ $create_options .= "'siteSpeedSampleRate' : " . (int) $this->gadwp->config->options['ga_speed_samplerate'];
24
  }
25
+ if ( $this->gadwp->config->options['ga_crossdomain_tracking'] && $this->gadwp->config->options['ga_crossdomain_list'] != '' ) {
26
+ if ( $create_options != '{' ) {
27
+ $create_options .= ', ';
28
+ }
29
+ $create_options .= "'allowLinker' : true";
30
  }
31
  $create_options .= '}';
32
  ?>
34
  <?php if ($this->gadwp->config->options ['ga_crossdomain_tracking'] && $this->gadwp->config->options ['ga_crossdomain_list']!='') {?>
35
  ga('require', 'linker');
36
  <?php
37
+ $crossdomain_list = explode( ',', $this->gadwp->config->options['ga_crossdomain_list'] );
38
+ $crossdomain_list = array_map( 'trim', $crossdomain_list );
39
+ $crossdomain_list = strip_tags( implode( "','", $crossdomain_list ) );
40
+ ?>
41
  ga('linker:autoLink', ['<?php echo ($crossdomain_list)?>'] );
42
  <?php
43
  }
44
+ if ( $this->gadwp->config->options['ga_dash_remarketing'] ) {
45
+ ?>
46
  ga('require', 'displayfeatures');
47
  <?php
48
  }
49
+ if ( $this->gadwp->config->options['ga_enhanced_links'] ) {
50
+ ?>
51
  ga('require', 'linkid', 'linkid.js');
52
  <?php
53
  }
54
+ if ( $this->gadwp->config->options['ga_author_dimindex'] && ( is_single() || is_page() ) ) {
55
+ global $post;
56
+ $author_id = $post->post_author;
57
+ $author_name = get_the_author_meta( 'display_name', $author_id );
58
+ ?>
59
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_author_dimindex']; ?>', '<?php echo esc_attr($author_name); ?>');
60
  <?php
61
  }
62
+ if ( $this->gadwp->config->options['ga_pubyear_dimindex'] && is_single() ) {
63
+ global $post;
64
+ $date = get_the_date( 'Y', $post->ID );
65
+ ?>
66
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_pubyear_dimindex']; ?>', '<?php echo (int)$date; ?>');
67
  <?php
68
  }
69
+ if ( $this->gadwp->config->options['ga_category_dimindex'] && is_category() ) {
70
+ ?>
71
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_category_dimindex']; ?>', '<?php echo esc_attr(single_tag_title()); ?>');
72
  <?php
73
  }
74
+ if ( $this->gadwp->config->options['ga_category_dimindex'] && is_single() ) {
75
+ global $post;
76
+ $categories = get_the_category( $post->ID );
77
+ foreach ( $categories as $category ) {
78
+ ?>
79
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_category_dimindex']; ?>', '<?php echo esc_attr($category->name); ?>');
80
  <?php
81
+ break;
82
+ }
83
  }
84
+ if ( $this->gadwp->config->options['ga_user_dimindex'] ) {
85
+ ?>
86
  ga('set', 'dimension<?php echo (int)$this->gadwp->config->options ['ga_user_dimindex']; ?>', '<?php echo is_user_logged_in()?'registered':'guest'; ?>');
87
  <?php
88
  }
89
+ do_action( 'ga_dash_addtrackingcode' );
90
+ if ( $this->gadwp->config->options['ga_dash_anonim'] ) {
91
+ ?> ga('send', 'pageview', {'anonymizeIp': true});<?php } else {?> ga('send', 'pageview');
92
  <?php
93
  }
94
+ if ( $this->gadwp->config->options['ga_dash_adsense'] ) {
95
+ ?>
96
 
97
  window.google_analytics_uacct = "<?php echo esc_html($profile[2]); ?>";
98
  <?php }?>
front/tracking/events-classic.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  // Exit if accessed directly
3
- if (! defined('ABSPATH'))
4
- exit();
5
  ?>
6
  <script type="text/javascript">
7
  (function($){
1
  <?php
2
  // Exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) )
4
+ exit();
5
  ?>
6
  <script type="text/javascript">
7
  (function($){
front/tracking/events-universal.php CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
  // Exit if accessed directly
3
- if (! defined('ABSPATH'))
4
- exit();
5
 
6
- $domaindata = GADWP_Tools::get_root_domain(esc_html(get_option('siteurl')));
7
  ?>
8
  <script type="text/javascript">
9
  (function($){
1
  <?php
2
  // Exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) )
4
+ exit();
5
 
6
+ $domaindata = GADWP_Tools::get_root_domain( esc_html( get_option( 'siteurl' ) ) );
7
  ?>
8
  <script type="text/javascript">
9
  (function($){
front/widgets.php CHANGED
@@ -8,109 +8,99 @@
8
  */
9
 
10
  // Exit if accessed directly
11
- if (! defined('ABSPATH'))
12
- exit();
13
 
14
- final class GADWP_Frontend_Widget extends WP_Widget
15
- {
16
- private $gadwp;
17
 
18
- public function __construct()
19
- {
20
- $this->gadwp = GADWP();
21
-
22
- parent::__construct('gadash_frontend_widget', __('Google Analytics Dashboard', 'ga-dash'), array(
23
- 'description' => __("Will display your google analytics stats in a widget", 'ga-dash')
24
- ));
25
- // Frontend Styles
26
- if (is_active_widget(false, false, $this->id_base, true)) {
27
- add_action('wp_enqueue_scripts', array(
28
- $this,
29
- 'load_styles_scripts'
30
- ));
31
- }
32
- }
33
 
34
- public function load_styles_scripts()
35
- {
36
- wp_enqueue_style('ga_dash-front', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION);
37
- wp_enqueue_script('ga_dash-front', GADWP_URL . 'front/js/item-reports.js', array(
38
- 'jquery'
39
- ), GADWP_CURRENT_VERSION);
40
- wp_enqueue_script('googlejsapi', 'https://www.google.com/jsapi');
41
- }
42
 
43
- public function widget($args, $instance)
44
- {
45
- $widget_title = apply_filters('widget_title', $instance['title']);
46
- $title = __("Sessions", 'ga-dash') . ($instance['anonim'] ? "' " . __("trend", 'ga-dash') : '');
47
- echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Widget - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n";
48
- echo $args['before_widget'];
49
- if (! empty($widget_title)) {
50
- echo $args['before_title'] . $widget_title . $args['after_title'];
51
- }
52
-
53
- if (isset($this->gadwp->config->options['ga_dash_style'])) {
54
- $css = "colors:['" . $this->gadwp->config->options['ga_dash_style'] . "','" . GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], - 20) . "'],";
55
- $color = $this->gadwp->config->options['ga_dash_style'];
56
- } else {
57
- $css = "";
58
- $color = "#3366CC";
59
- }
60
- ob_start();
61
- if ($instance['anonim']) {
62
- $formater = "var formatter = new google.visualization.NumberFormat({
 
 
 
 
 
 
 
 
 
 
 
 
63
  suffix: '%',
64
  fractionDigits: 2
65
  });
66
-
67
  formatter.format(data, 1); ";
68
- } else {
69
- $formater = '';
70
- }
71
- $periodtext = "";
72
- switch ($instance['period']) {
73
- case '7daysAgo':
74
- $periodtext = __('Last 7 Days', 'ga-dash');
75
- break;
76
- case '14daysAgo':
77
- $periodtext = __('Last 14 Days', 'ga-dash');
78
- break;
79
- case '30daysAgo':
80
- $periodtext = __('Last 30 Days', 'ga-dash');
81
- break;
82
- default:
83
- $periodtext = "";
84
- break;
85
- }
86
- switch ($instance['display']) {
87
- case '1':
88
- echo '<div id="gadwp-widget"><div id="gadwp-widgetchart"></div><div id="gadwp-widgettotals"></div></div>';
89
- break;
90
- case '2':
91
- echo '<div id="gadwp-widget"><div id="gadwp-widgetchart"></div></div>';
92
- break;
93
- case '3':
94
- echo '<div id="gadwp-widget"><div id="gadwp-widgettotals"></div></div>';
95
- break;
96
- }
97
- echo '<script type="text/javascript">
98
 
99
- jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontendwidget_data",gadash_number: "' . $this->number . '",gadash_optionname: "' . $this->option_name . '"}, function(response){
100
  if (!jQuery.isNumeric(response) && jQuery.isArray(response)){
101
  if (jQuery("#gadwp-widgetchart")[0]){
102
- gadash_widgetsessions=response[0];
103
  google.setOnLoadCallback(ga_dash_drawfwidgetsessions(gadash_widgetsessions));
104
  }
105
- if (jQuery("#gadwp-widgettotals")[0]){
106
  ga_dash_drawtotalsstats(response[1]);
107
- }
108
  }else{
109
- jQuery("#gadwp-widgetchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"50px","padding-bottom":"50px","color":"#000","text-align":"center"});
110
- jQuery("#gadwp-widgetchart").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")");
111
- }
112
  });';
113
- echo 'google.load("visualization", "1", {packages:["corechart"]});
114
  function ga_dash_drawfwidgetsessions(response) {
115
  var data = google.visualization.arrayToDataTable(response);
116
  var options = {
@@ -129,81 +119,61 @@ final class GADWP_Frontend_Widget extends WP_Widget
129
  function ga_dash_drawtotalsstats(response) {
130
  if (response == null){
131
  response = 0;
132
- }
133
- jQuery("#gadwp-widgettotals").html("<div class=\"gadwp-left\">' . __("Period:", 'ga-dash') . '</div> <div class=\"gadwp-right\">' . $periodtext . '</div><div class=\"gadwp-left\">' . __("Sessions:", 'ga-dash') . '</div> <div class=\"gadwp-right\">"+response+"</div>");
134
  }';
135
- echo '</script>';
136
- if ($instance['give_credits'] == 1)
137
- echo '<div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;">' . __('generated by', 'ga-dash') . ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_report&utm_medium=link&utm_content=front_widget&utm_campaign=gadwp" rel="nofollow" style="text-decoration:none;font-size:1em;">GADWP</a>&nbsp;</div>';
138
- $widget_content = ob_get_contents();
139
- ob_end_clean();
140
- echo apply_filters('widget_html_content', $widget_content);
141
- echo $args['after_widget'];
142
- echo "\n<!-- END GADWP Widget -->\n";
143
- }
144
-
145
- public function form($instance)
146
- {
147
- $widget_title = (isset($instance['title']) ? $instance['title'] : __("Google Analytics Stats", 'ga-dash'));
148
- $period = (isset($instance['period']) ? $instance['period'] : '7daysAgo');
149
- $display = (isset($instance['display']) ? $instance['display'] : 1);
150
- $give_credits = (isset($instance['give_credits']) ? $instance['give_credits'] : 1);
151
- $anonim = (isset($instance['anonim']) ? $instance['anonim'] : 0);
152
- ?>
153
- <p>
154
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( "Title:",'ga-dash' ); ?></label>
155
- <input class="widefat"
156
- id="<?php echo $this->get_field_id( 'title' ); ?>"
157
- name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
158
- value="<?php echo esc_attr( $widget_title ); ?>">
159
- </p>
160
- <p>
161
- <label for="<?php echo $this->get_field_id( 'display' ); ?>"><?php _e( "Display:",'ga-dash' ); ?></label>
162
- <select id="<?php echo $this->get_field_id('display'); ?>"
163
- class="widefat"
164
- name="<?php echo $this->get_field_name( 'display' ); ?>">
165
- <option value="1" <?php selected( $display, 1 ); ?>><?php _e('Chart & Totals', 'ga-dash');?></option>
166
- <option value="2" <?php selected( $display, 2 ); ?>><?php _e('Chart', 'ga-dash');?></option>
167
- <option value="3" <?php selected( $display, 3 ); ?>><?php _e('Totals', 'ga-dash');?></option>
168
- </select>
169
- </p>
170
- <p>
171
- <label for="<?php echo $this->get_field_id( 'anonim' ); ?>"><?php _e( "Anonymize stats:",'ga-dash' ); ?></label>
172
- <input class="widefat"
173
- id="<?php echo $this->get_field_id( 'anonim' ); ?>"
174
- name="<?php echo $this->get_field_name( 'anonim' ); ?>"
175
- type="checkbox" <?php checked( $anonim, 1 ); ?> value="1">
176
- </p>
177
- <p>
178
- <label for="<?php echo $this->get_field_id( 'period' ); ?>"><?php _e( "Stats for:",'ga-dash' ); ?></label>
179
- <select id="<?php echo $this->get_field_id('period'); ?>"
180
- class="widefat"
181
- name="<?php echo $this->get_field_name( 'period' ); ?>">
182
- <option value="7daysAgo" <?php selected( $period, '7daysAgo' ); ?>><?php _e('Last 7 Days', 'ga-dash');?></option>
183
- <option value="14daysAgo" <?php selected( $period, '14daysAgo' ); ?>><?php _e('Last 14 Days', 'ga-dash');?></option>
184
- <option value="30daysAgo" <?php selected( $period, '30daysAgo' ); ?>><?php _e('Last 30 Days', 'ga-dash');?></option>
185
- </select>
186
- </p>
187
- <p>
188
- <label for="<?php echo $this->get_field_id( 'give_credits' ); ?>"><?php _e( "Give credits:",'ga-dash' ); ?></label>
189
- <input class="widefat"
190
- id="<?php echo $this->get_field_id( 'give_credits' ); ?>"
191
- name="<?php echo $this->get_field_name( 'give_credits' ); ?>"
192
- type="checkbox" <?php checked( $give_credits, 1 ); ?> value="1">
193
- </p>
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
- <?php
197
- }
198
-
199
- public function update($new_instance, $old_instance)
200
- {
201
- $instance = array();
202
- $instance['title'] = (! empty($new_instance['title'])) ? strip_tags($new_instance['title']) : 'Analytics Stats';
203
- $instance['period'] = (! empty($new_instance['period'])) ? strip_tags($new_instance['period']) : '7daysAgo';
204
- $instance['display'] = (! empty($new_instance['display'])) ? strip_tags($new_instance['display']) : 1;
205
- $instance['give_credits'] = (! empty($new_instance['give_credits'])) ? strip_tags($new_instance['give_credits']) : 0;
206
- $instance['anonim'] = (! empty($new_instance['anonim'])) ? strip_tags($new_instance['anonim']) : 0;
207
- return $instance;
208
- }
209
  }
8
  */
9
 
10
  // Exit if accessed directly
11
+ if ( ! defined( 'ABSPATH' ) )
12
+ exit();
13
 
14
+ final class GADWP_Frontend_Widget extends WP_Widget {
 
 
15
 
16
+ private $gadwp;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ public function __construct() {
19
+ $this->gadwp = GADWP();
 
 
 
 
 
 
20
 
21
+ parent::__construct( 'gadash_frontend_widget', __( 'Google Analytics Dashboard', 'ga-dash' ), array( 'description' => __( "Will display your google analytics stats in a widget", 'ga-dash' ) ) );
22
+ // Frontend Styles
23
+ if ( is_active_widget( false, false, $this->id_base, true ) ) {
24
+ add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_scripts' ) );
25
+ }
26
+ }
27
+
28
+ public function load_styles_scripts() {
29
+ wp_enqueue_style( 'ga_dash-front', GADWP_URL . 'front/css/widgets.css', null, GADWP_CURRENT_VERSION );
30
+ wp_enqueue_script( 'ga_dash-front', GADWP_URL . 'front/js/widgets.js', array( 'jquery' ), GADWP_CURRENT_VERSION );
31
+ wp_enqueue_script( 'googlejsapi', 'https://www.google.com/jsapi' );
32
+ }
33
+
34
+ public function widget( $args, $instance ) {
35
+ $widget_title = apply_filters( 'widget_title', $instance['title'] );
36
+ $title = __( "Sessions", 'ga-dash' ) . ( $instance['anonim'] ? "' " . __( "trend", 'ga-dash' ) : '' );
37
+ echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Widget - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n";
38
+ echo $args['before_widget'];
39
+ if ( ! empty( $widget_title ) ) {
40
+ echo $args['before_title'] . $widget_title . $args['after_title'];
41
+ }
42
+
43
+ if ( isset( $this->gadwp->config->options['ga_dash_style'] ) ) {
44
+ $css = "colors:['" . $this->gadwp->config->options['ga_dash_style'] . "','" . GADWP_Tools::colourVariator( $this->gadwp->config->options['ga_dash_style'], - 20 ) . "'],";
45
+ $color = $this->gadwp->config->options['ga_dash_style'];
46
+ } else {
47
+ $css = "";
48
+ $color = "#3366CC";
49
+ }
50
+ ob_start();
51
+ if ( $instance['anonim'] ) {
52
+ $formater = "var formatter = new google.visualization.NumberFormat({
53
  suffix: '%',
54
  fractionDigits: 2
55
  });
56
+
57
  formatter.format(data, 1); ";
58
+ } else {
59
+ $formater = '';
60
+ }
61
+ $periodtext = "";
62
+ switch ( $instance['period'] ) {
63
+ case '7daysAgo' :
64
+ $periodtext = __( 'Last 7 Days', 'ga-dash' );
65
+ break;
66
+ case '14daysAgo' :
67
+ $periodtext = __( 'Last 14 Days', 'ga-dash' );
68
+ break;
69
+ case '30daysAgo' :
70
+ $periodtext = __( 'Last 30 Days', 'ga-dash' );
71
+ break;
72
+ default :
73
+ $periodtext = "";
74
+ break;
75
+ }
76
+ switch ( $instance['display'] ) {
77
+ case '1' :
78
+ echo '<div id="gadwp-widget"><div id="gadwp-widgetchart"></div><div id="gadwp-widgettotals"></div></div>';
79
+ break;
80
+ case '2' :
81
+ echo '<div id="gadwp-widget"><div id="gadwp-widgetchart"></div></div>';
82
+ break;
83
+ case '3' :
84
+ echo '<div id="gadwp-widget"><div id="gadwp-widgettotals"></div></div>';
85
+ break;
86
+ }
87
+ echo '<script type="text/javascript">
88
 
89
+ jQuery.post("' . admin_url( 'admin-ajax.php' ) . '", {action: "gadash_get_frontendwidget_data",gadash_number: "' . $this->number . '",gadash_optionname: "' . $this->option_name . '"}, function(response){
90
  if (!jQuery.isNumeric(response) && jQuery.isArray(response)){
91
  if (jQuery("#gadwp-widgetchart")[0]){
92
+ gadash_widgetsessions=response[0];
93
  google.setOnLoadCallback(ga_dash_drawfwidgetsessions(gadash_widgetsessions));
94
  }
95
+ if (jQuery("#gadwp-widgettotals")[0]){
96
  ga_dash_drawtotalsstats(response[1]);
97
+ }
98
  }else{
99
+ jQuery("#gadwp-widgetchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"50px","padding-bottom":"50px","color":"#000","text-align":"center"});
100
+ jQuery("#gadwp-widgetchart").html("' . __( "This report is unavailable", 'ga-dash' ) . ' ("+response+")");
101
+ }
102
  });';
103
+ echo 'google.load("visualization", "1", {packages:["corechart"]});
104
  function ga_dash_drawfwidgetsessions(response) {
105
  var data = google.visualization.arrayToDataTable(response);
106
  var options = {
119
  function ga_dash_drawtotalsstats(response) {
120
  if (response == null){
121
  response = 0;
122
+ }
123
+ jQuery("#gadwp-widgettotals").html("<div class=\"gadwp-left\">' . __( "Period:", 'ga-dash' ) . '</div> <div class=\"gadwp-right\">' . $periodtext . '</div><div class=\"gadwp-left\">' . __( "Sessions:", 'ga-dash' ) . '</div> <div class=\"gadwp-right\">"+response+"</div>");
124
  }';
125
+ echo '</script>';
126
+ if ( $instance['give_credits'] == 1 )
127
+ echo '<div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;">' . __( 'generated by', 'ga-dash' ) . ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_report&utm_medium=link&utm_content=front_widget&utm_campaign=gadwp" rel="nofollow" style="text-decoration:none;font-size:1em;">GADWP</a>&nbsp;</div>';
128
+ $widget_content = ob_get_contents();
129
+ ob_end_clean();
130
+ echo apply_filters( 'widget_html_content', $widget_content );
131
+ echo $args['after_widget'];
132
+ echo "\n<!-- END GADWP Widget -->\n";
133
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
+ public function form( $instance ) {
136
+ $widget_title = ( isset( $instance['title'] ) ? $instance['title'] : __( "Google Analytics Stats", 'ga-dash' ) );
137
+ $period = ( isset( $instance['period'] ) ? $instance['period'] : '7daysAgo' );
138
+ $display = ( isset( $instance['display'] ) ? $instance['display'] : 1 );
139
+ $give_credits = ( isset( $instance['give_credits'] ) ? $instance['give_credits'] : 1 );
140
+ $anonim = ( isset( $instance['anonim'] ) ? $instance['anonim'] : 0 );
141
+ /* @formatter:off */
142
+ ?>
143
+ <p>
144
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( "Title:",'ga-dash' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $widget_title ); ?>">
145
+ </p>
146
+ <p>
147
+ <label for="<?php echo $this->get_field_id( 'display' ); ?>"><?php _e( "Display:",'ga-dash' ); ?></label> <select id="<?php echo $this->get_field_id('display'); ?>" class="widefat" name="<?php echo $this->get_field_name( 'display' ); ?>">
148
+ <option value="1" <?php selected( $display, 1 ); ?>><?php _e('Chart & Totals', 'ga-dash');?></option>
149
+ <option value="2" <?php selected( $display, 2 ); ?>><?php _e('Chart', 'ga-dash');?></option>
150
+ <option value="3" <?php selected( $display, 3 ); ?>><?php _e('Totals', 'ga-dash');?></option>
151
+ </select>
152
+ </p>
153
+ <p>
154
+ <label for="<?php echo $this->get_field_id( 'anonim' ); ?>"><?php _e( "Anonymize stats:",'ga-dash' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'anonim' ); ?>" name="<?php echo $this->get_field_name( 'anonim' ); ?>" type="checkbox" <?php checked( $anonim, 1 ); ?> value="1">
155
+ </p>
156
+ <p>
157
+ <label for="<?php echo $this->get_field_id( 'period' ); ?>"><?php _e( "Stats for:",'ga-dash' ); ?></label> <select id="<?php echo $this->get_field_id('period'); ?>" class="widefat" name="<?php echo $this->get_field_name( 'period' ); ?>">
158
+ <option value="7daysAgo" <?php selected( $period, '7daysAgo' ); ?>><?php _e('Last 7 Days', 'ga-dash');?></option>
159
+ <option value="14daysAgo" <?php selected( $period, '14daysAgo' ); ?>><?php _e('Last 14 Days', 'ga-dash');?></option>
160
+ <option value="30daysAgo" <?php selected( $period, '30daysAgo' ); ?>><?php _e('Last 30 Days', 'ga-dash');?></option>
161
+ </select>
162
+ </p>
163
+ <p>
164
+ <label for="<?php echo $this->get_field_id( 'give_credits' ); ?>"><?php _e( "Give credits:",'ga-dash' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'give_credits' ); ?>" name="<?php echo $this->get_field_name( 'give_credits' ); ?>" type="checkbox" <?php checked( $give_credits, 1 ); ?> value="1">
165
+ </p>
166
+ <?php
167
+ /* @formatter:on */
168
+ }
169
 
170
+ public function update( $new_instance, $old_instance ) {
171
+ $instance = array();
172
+ $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : 'Analytics Stats';
173
+ $instance['period'] = ( ! empty( $new_instance['period'] ) ) ? strip_tags( $new_instance['period'] ) : '7daysAgo';
174
+ $instance['display'] = ( ! empty( $new_instance['display'] ) ) ? strip_tags( $new_instance['display'] ) : 1;
175
+ $instance['give_credits'] = ( ! empty( $new_instance['give_credits'] ) ) ? strip_tags( $new_instance['give_credits'] ) : 0;
176
+ $instance['anonim'] = ( ! empty( $new_instance['anonim'] ) ) ? strip_tags( $new_instance['anonim'] ) : 0;
177
+ return $instance;
178
+ }
 
 
 
 
179
  }
gadwp.php CHANGED
@@ -4,258 +4,243 @@
4
  * Plugin URI: https://deconf.com
5
  * Description: Displays Google Analytics Reports and Real-Time Statistics in your Dashboard. Automatically inserts the tracking code in every page of your website.
6
  * Author: Alin Marcu
7
- * Version: 4.7.5
8
  * Author URI: https://deconf.com
9
  */
10
 
11
  // Exit if accessed directly
12
- if (! defined('ABSPATH'))
13
- exit();
14
-
15
- if (! class_exists('GADWP_Manager')) {
16
-
17
- final class GADWP_Manager
18
- {
19
-
20
- private static $instance = null;
21
-
22
- public $config = null;
23
-
24
- public $frontend_actions = null;
25
-
26
- public $backend_actions = null;
27
-
28
- public $tracking = null;
29
-
30
- public $frontend_item_reports = null;
31
-
32
- public $backend_setup = null;
33
-
34
- public $backend_widgets = null;
35
-
36
- public $backend_item_reports = null;
37
-
38
- public $gapi_controller = null;
39
-
40
- /**
41
- * Construct forbidden
42
- */
43
- private function __construct()
44
- {
45
- if (null !== self::$instance) {
46
- _doing_it_wrong(__FUNCTION__, __("This is not allowed, read the documentation!", 'ga-dash'), '4.6');
47
- }
48
- }
49
-
50
- /**
51
- * Clone warning
52
- */
53
- private function __clone()
54
- {
55
- _doing_it_wrong(__FUNCTION__, __("This is not allowed, read the documentation!", 'ga-dash'), '4.6');
56
- }
57
-
58
- /**
59
- * Wakeup warning
60
- */
61
- private function __wakeup()
62
- {
63
- _doing_it_wrong(__FUNCTION__, __("This is not allowed, read the documentation!", 'ga-dash'), '4.6');
64
- }
65
-
66
- /**
67
- * Creates a single instance for GADWP and makes sure only one instance is present in memory.
68
- *
69
- * @return GADWP_Manager
70
- */
71
- public static function instance()
72
- {
73
- if (null === self::$instance) {
74
- self::$instance = new self();
75
- self::$instance->setup();
76
- self::$instance->config = new GADWP_Config();
77
- }
78
- return self::$instance;
79
- }
80
-
81
- /**
82
- * Defines constants and loads required resources
83
- */
84
- private function setup()
85
- {
86
-
87
- // Plugin Version
88
- if (! defined('GADWP_CURRENT_VERSION')) {
89
- define('GADWP_CURRENT_VERSION', '4.7.5');
90
- }
91
-
92
- // Plugin Path
93
- if (! defined('GADWP_DIR')) {
94
- define('GADWP_DIR', plugin_dir_path(__FILE__));
95
- }
96
-
97
- // Plugin URL
98
- if (! defined('GADWP_URL')) {
99
- define('GADWP_URL', plugin_dir_url(__FILE__));
100
- }
101
-
102
- // Plugin main File
103
- if (! defined('GADWP_FILE')) {
104
- define('GADWP_FILE', __FILE__);
105
- }
106
-
107
- /*
108
- * Load Tools class
109
- */
110
- include_once (GADWP_DIR . 'tools/tools.php');
111
-
112
- /*
113
- * Load Config class
114
- */
115
- include_once (GADWP_DIR . 'config.php');
116
-
117
- /*
118
- * Load GAPI Controller class
119
- */
120
- include_once (GADWP_DIR . 'tools/gapi.php');
121
-
122
- /*
123
- * Plugin i18n
124
- */
125
- add_action('init', array(
126
- self::$instance,
127
- 'load_i18n'
128
- ));
129
-
130
- /*
131
- * Plugin Init
132
- */
133
- add_action('init', array(
134
- self::$instance,
135
- 'load'
136
- ));
137
-
138
- /*
139
- * Include Install
140
- */
141
- include_once (GADWP_DIR . 'install/install.php');
142
- register_activation_hook(GADWP_FILE, array(
143
- 'GADWP_Install',
144
- 'install'
145
- ));
146
-
147
- /*
148
- * Include Uninstall
149
- */
150
- include_once (GADWP_DIR . 'install/uninstall.php');
151
- register_uninstall_hook(GADWP_FILE, array(
152
- 'GADWP_Uninstall',
153
- 'uninstall'
154
- ));
155
-
156
- /*
157
- * Load Frontend Widgets
158
- * (needed during ajax)
159
- */
160
- include_once (GADWP_DIR . 'front/widgets.php');
161
-
162
- /*
163
- * Add Frontend Widgets
164
- * (needed during ajax)
165
- */
166
- add_action('widgets_init', array(
167
- self::$instance,
168
- 'add_frontend_widget'
169
- ));
170
- }
171
-
172
- /**
173
- * Load i18n
174
- */
175
- public function load_i18n()
176
- {
177
- load_plugin_textdomain('ga-dash', false, dirname(plugin_basename(__FILE__)) . '/languages');
178
- }
179
-
180
- /**
181
- * Register Frontend Widgets
182
- */
183
- public function add_frontend_widget()
184
- {
185
- register_widget('GADWP_Frontend_Widget');
186
- }
187
-
188
- /**
189
- * Conditional load
190
- */
191
- public function load()
192
- {
193
- if (is_admin()) {
194
- if (defined('DOING_AJAX') && DOING_AJAX) {
195
- if (GADWP_Tools::check_roles(self::$instance->config->options['ga_dash_access_back'])) {
196
- /*
197
- * Load Backend ajax actions
198
- */
199
- include_once (GADWP_DIR . 'admin/ajax-actions.php');
200
- self::$instance->backend_actions = new GADWP_Backend_Ajax();
201
- }
202
-
203
- /*
204
- * Load Frontend ajax actions
205
- */
206
- include_once (GADWP_DIR . 'front/ajax-actions.php');
207
- self::$instance->frontend_actions = new GADWP_Frontend_Ajax();
208
- } else
209
- if (GADWP_Tools::check_roles(self::$instance->config->options['ga_dash_access_back'])) {
210
- /*
211
- * Load Backend Setup
212
- */
213
- include_once (GADWP_DIR . 'admin/setup.php');
214
- self::$instance->backend_setup = new GADWP_Backend_Setup();
215
-
216
- if (self::$instance->config->options['dashboard_widget']) {
217
- /*
218
- * Load Backend Widget
219
- */
220
- include_once (GADWP_DIR . 'admin/widgets.php');
221
- self::$instance->backend_widgets = new GADWP_Backend_Widgets();
222
- }
223
-
224
- if (self::$instance->config->options['item_reports']) {
225
- /*
226
- * Load Backend Item Reports
227
- */
228
- include_once (GADWP_DIR . 'admin/item-reports.php');
229
- self::$instance->backend_item_reports = new GADWP_Backend_Item_Reports();
230
- }
231
- }
232
- } else {
233
- if (GADWP_Tools::check_roles(self::$instance->config->options['ga_dash_access_front']) && (self::$instance->config->options['ga_dash_frontend_stats'] || self::$instance->config->options['ga_dash_frontend_keywords'])) {
234
- /*
235
- * Load Frontend Item Reports
236
- */
237
- include_once (GADWP_DIR . 'front/item-reports.php');
238
- self::$instance->frontend_item_reports = new GADWP_Frontend_Item_Reports();
239
- }
240
-
241
- if (! GADWP_Tools::check_roles(self::$instance->config->options['ga_track_exclude'], true) && self::$instance->config->options['ga_dash_tracking']) {
242
- /*
243
- * Load tracking class
244
- */
245
- include_once (GADWP_DIR . 'front/tracking.php');
246
- self::$instance->tracking = new GADWP_Tracking();
247
- }
248
- }
249
- }
250
- }
251
  }
252
 
253
  /**
254
  * Returns a unique instance of GADWP
255
  */
256
- function GADWP()
257
- {
258
- return GADWP_Manager::instance();
259
  }
260
 
261
  /*
4
  * Plugin URI: https://deconf.com
5
  * Description: Displays Google Analytics Reports and Real-Time Statistics in your Dashboard. Automatically inserts the tracking code in every page of your website.
6
  * Author: Alin Marcu
7
+ * Version: 4.8
8
  * Author URI: https://deconf.com
9
  */
10
 
11
  // Exit if accessed directly
12
+ if ( ! defined( 'ABSPATH' ) )
13
+ exit();
14
+
15
+ if ( ! class_exists( 'GADWP_Manager' ) ) {
16
+
17
+ final class GADWP_Manager {
18
+
19
+ private static $instance = null;
20
+
21
+ public $config = null;
22
+
23
+ public $frontend_actions = null;
24
+
25
+ public $backend_actions = null;
26
+
27
+ public $tracking = null;
28
+
29
+ public $frontend_item_reports = null;
30
+
31
+ public $backend_setup = null;
32
+
33
+ public $frontend_setup = null;
34
+
35
+ public $backend_widgets = null;
36
+
37
+ public $backend_item_reports = null;
38
+
39
+ public $gapi_controller = null;
40
+
41
+ /**
42
+ * Construct forbidden
43
+ */
44
+ private function __construct() {
45
+ if ( null !== self::$instance ) {
46
+ _doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'ga-dash' ), '4.6' );
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Clone warning
52
+ */
53
+ private function __clone() {
54
+ _doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'ga-dash' ), '4.6' );
55
+ }
56
+
57
+ /**
58
+ * Wakeup warning
59
+ */
60
+ private function __wakeup() {
61
+ _doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'ga-dash' ), '4.6' );
62
+ }
63
+
64
+ /**
65
+ * Creates a single instance for GADWP and makes sure only one instance is present in memory.
66
+ *
67
+ * @return GADWP_Manager
68
+ */
69
+ public static function instance() {
70
+ if ( null === self::$instance ) {
71
+ self::$instance = new self();
72
+ self::$instance->setup();
73
+ self::$instance->config = new GADWP_Config();
74
+ }
75
+ return self::$instance;
76
+ }
77
+
78
+ /**
79
+ * Defines constants and loads required resources
80
+ */
81
+ private function setup() {
82
+
83
+ // Plugin Version
84
+ if ( ! defined( 'GADWP_CURRENT_VERSION' ) ) {
85
+ define( 'GADWP_CURRENT_VERSION', '4.8' );
86
+ }
87
+
88
+ // Plugin Path
89
+ if ( ! defined( 'GADWP_DIR' ) ) {
90
+ define( 'GADWP_DIR', plugin_dir_path( __FILE__ ) );
91
+ }
92
+
93
+ // Plugin URL
94
+ if ( ! defined( 'GADWP_URL' ) ) {
95
+ define( 'GADWP_URL', plugin_dir_url( __FILE__ ) );
96
+ }
97
+
98
+ // Plugin main File
99
+ if ( ! defined( 'GADWP_FILE' ) ) {
100
+ define( 'GADWP_FILE', __FILE__ );
101
+ }
102
+
103
+ /*
104
+ * Load Tools class
105
+ */
106
+ include_once ( GADWP_DIR . 'tools/tools.php' );
107
+
108
+ /*
109
+ * Load Config class
110
+ */
111
+ include_once ( GADWP_DIR . 'config.php' );
112
+
113
+ /*
114
+ * Load GAPI Controller class
115
+ */
116
+ include_once ( GADWP_DIR . 'tools/gapi.php' );
117
+
118
+ /*
119
+ * Plugin i18n
120
+ */
121
+ add_action( 'init', array( self::$instance, 'load_i18n' ) );
122
+
123
+ /*
124
+ * Plugin Init
125
+ */
126
+ add_action( 'init', array( self::$instance, 'load' ) );
127
+
128
+ /*
129
+ * Include Install
130
+ */
131
+ include_once ( GADWP_DIR . 'install/install.php' );
132
+ register_activation_hook( GADWP_FILE, array( 'GADWP_Install', 'install' ) );
133
+
134
+ /*
135
+ * Include Uninstall
136
+ */
137
+ include_once ( GADWP_DIR . 'install/uninstall.php' );
138
+ register_uninstall_hook( GADWP_FILE, array( 'GADWP_Uninstall', 'uninstall' ) );
139
+
140
+ /*
141
+ * Load Frontend Widgets
142
+ * (needed during ajax)
143
+ */
144
+ include_once ( GADWP_DIR . 'front/widgets.php' );
145
+
146
+ /*
147
+ * Add Frontend Widgets
148
+ * (needed during ajax)
149
+ */
150
+ add_action( 'widgets_init', array( self::$instance, 'add_frontend_widget' ) );
151
+ }
152
+
153
+ /**
154
+ * Load i18n
155
+ */
156
+ public function load_i18n() {
157
+ load_plugin_textdomain( 'ga-dash', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
158
+ }
159
+
160
+ /**
161
+ * Register Frontend Widgets
162
+ */
163
+ public function add_frontend_widget() {
164
+ register_widget( 'GADWP_Frontend_Widget' );
165
+ }
166
+
167
+ /**
168
+ * Conditional load
169
+ */
170
+ public function load() {
171
+ if ( is_admin() ) {
172
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
173
+ if ( GADWP_Tools::check_roles( self::$instance->config->options['ga_dash_access_back'] ) ) {
174
+ /*
175
+ * Load Backend ajax actions
176
+ */
177
+ include_once ( GADWP_DIR . 'admin/ajax-actions.php' );
178
+ self::$instance->backend_actions = new GADWP_Backend_Ajax();
179
+ }
180
+
181
+ /*
182
+ * Load Frontend ajax actions
183
+ */
184
+ include_once ( GADWP_DIR . 'front/ajax-actions.php' );
185
+ self::$instance->frontend_actions = new GADWP_Frontend_Ajax();
186
+ } else
187
+ if ( GADWP_Tools::check_roles( self::$instance->config->options['ga_dash_access_back'] ) ) {
188
+ /*
189
+ * Load Backend Setup
190
+ */
191
+ include_once ( GADWP_DIR . 'admin/setup.php' );
192
+ self::$instance->backend_setup = new GADWP_Backend_Setup();
193
+
194
+ if ( self::$instance->config->options['dashboard_widget'] ) {
195
+ /*
196
+ * Load Backend Widget
197
+ */
198
+ include_once ( GADWP_DIR . 'admin/widgets.php' );
199
+ self::$instance->backend_widgets = new GADWP_Backend_Widgets();
200
+ }
201
+
202
+ if ( self::$instance->config->options['backend_item_reports'] ) {
203
+ /*
204
+ * Load Backend Item Reports
205
+ */
206
+ include_once ( GADWP_DIR . 'admin/item-reports.php' );
207
+ self::$instance->backend_item_reports = new GADWP_Backend_Item_Reports();
208
+ }
209
+ }
210
+ } else {
211
+ if ( GADWP_Tools::check_roles( self::$instance->config->options['ga_dash_access_front'] ) ) {
212
+ /*
213
+ * Load Frontend Setup
214
+ */
215
+ include_once ( GADWP_DIR . 'front/setup.php' );
216
+ self::$instance->frontend_setup = new GADWP_Frontend_Setup();
217
+
218
+ if ( self::$instance->config->options['frontend_item_reports'] ) {
219
+ /*
220
+ * Load Frontend Item Reports
221
+ */
222
+ include_once ( GADWP_DIR . 'front/item-reports.php' );
223
+ self::$instance->frontend_item_reports = new GADWP_Frontend_Item_Reports();
224
+ }
225
+ }
226
+
227
+ if ( ! GADWP_Tools::check_roles( self::$instance->config->options['ga_track_exclude'], true ) && self::$instance->config->options['ga_dash_tracking'] ) {
228
+ /*
229
+ * Load tracking class
230
+ */
231
+ include_once ( GADWP_DIR . 'front/tracking.php' );
232
+ self::$instance->tracking = new GADWP_Tracking();
233
+ }
234
+ }
235
+ }
236
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  }
238
 
239
  /**
240
  * Returns a unique instance of GADWP
241
  */
242
+ function GADWP() {
243
+ return GADWP_Manager::instance();
 
244
  }
245
 
246
  /*
install/install.php CHANGED
@@ -8,137 +8,137 @@
8
  */
9
 
10
  // Exit if accessed directly
11
- if (! defined('ABSPATH'))
12
- exit();
13
 
14
- class GADWP_Install
15
- {
16
 
17
- public static function install()
18
- {
19
- if (! get_option('ga_dash_token')) {
20
- $options = array();
21
- $options['ga_dash_apikey'] = '';
22
- $options['ga_dash_clientid'] = '';
23
- $options['ga_dash_clientsecret'] = '';
24
- $options['ga_dash_access_front'][] = 'administrator';
25
- $options['ga_dash_access_back'][] = 'administrator';
26
- $options['ga_dash_tableid_jail'] = '';
27
- $options['ga_dash_style'] = '#1e73be';
28
- $options['switch_profile'] = 0;
29
- $options['ga_dash_cachetime'] = 3600;
30
- $options['ga_dash_tracking'] = 1;
31
- $options['ga_dash_tracking_type'] = 'universal';
32
- $options['ga_dash_default_ua'] = '';
33
- $options['ga_dash_anonim'] = 0;
34
- $options['ga_dash_userapi'] = 0;
35
- $options['ga_event_tracking'] = 0;
36
- $options['ga_event_downloads'] = 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*';
37
- $options['ga_track_exclude'] = array();
38
- $options['ga_target_geomap'] = '';
39
- $options['ga_realtime_pages'] = 10;
40
- $options['ga_dash_token'] = '';
41
- $options['ga_dash_refresh_token'] = '';
42
- $options['ga_dash_profile_list'] = array();
43
- $options['ga_dash_tableid'] = '';
44
- $options['ga_dash_frontend_keywords'] = 0;
45
- $options['ga_tracking_code'] = '';
46
- $options['ga_enhanced_links'] = 0;
47
- $options['ga_dash_remarketing'] = 0;
48
- $options['ga_dash_default_metric'] = 'sessions';
49
- $options['ga_dash_default_dimension'] = '30daysAgo';
50
- $options['ga_dash_frontend_stats'] = 0;
51
- $options['ga_dash_network'] = 0;
52
- $options['ga_dash_adsense'] = 0;
53
- $options['ga_speed_samplerate'] = 1;
54
- $options['ga_event_bouncerate'] = 0;
55
- $options['ga_crossdomain_tracking'] = 0;
56
- $options['ga_crossdomain_list'] = '';
57
- $options['ga_author_dimindex'] = 0;
58
- $options['ga_category_dimindex'] = 0;
59
- $options['ga_user_dimindex'] = 0;
60
- $options['ga_pubyear_dimindex'] = 0;
61
- $options['ga_aff_tracking'] = 0;
62
- $options['ga_event_affiliates'] = '/out/';
63
- $options['automatic_updates_minorversion'] = 1;
64
- $options['item_reports'] = 1;
65
- $options['dashboard_widget'] = 1;
66
- } else {
67
- $options = array();
68
- $options['ga_dash_apikey'] = get_option('ga_dash_apikey');
69
- $options['ga_dash_clientid'] = get_option('ga_dash_clientid');
70
- $options['ga_dash_clientsecret'] = get_option('ga_dash_clientsecret');
71
- $options['ga_dash_access'] = get_option('ga_dash_access');
72
- $options['ga_dash_access_front'][] = 'administrator';
73
- $options['ga_dash_access_back'][] = 'administrator';
74
- $options['ga_dash_tableid_jail'] = get_option('ga_dash_tableid_jail');
75
- $options['ga_dash_frontend_stats'] = get_option('ga_dash_frontend');
76
- $options['ga_dash_style'] = '#1e73be';
77
- $options['switch_profile'] = get_option('ga_dash_jailadmins');
78
- $options['ga_dash_cachetime'] = get_option('ga_dash_cachetime');
79
- if (get_option('ga_dash_tracking') == 4) {
80
- $options['ga_dash_tracking'] = 0;
81
- } else {
82
- $options['ga_dash_tracking'] = 1;
83
- }
84
- $options['ga_dash_tracking_type'] = get_option('ga_dash_tracking_type');
85
- $options['ga_dash_default_ua'] = get_option('ga_dash_default_ua');
86
- $options['ga_dash_anonim'] = get_option('ga_dash_anonim');
87
- $options['ga_dash_userapi'] = get_option('ga_dash_userapi');
88
- $options['ga_event_tracking'] = get_option('ga_event_tracking');
89
- $options['ga_event_downloads'] = get_option('ga_event_downloads');
90
- $options['ga_track_exclude'] = array();
91
- $options['ga_target_geomap'] = get_option('ga_target_geomap');
92
- $options['ga_realtime_pages'] = get_option('ga_realtime_pages');
93
- $options['ga_dash_token'] = get_option('ga_dash_token');
94
- $options['ga_dash_refresh_token'] = get_option('ga_dash_refresh_token');
95
- $options['ga_dash_profile_list'] = get_option('ga_dash_profile_list');
96
- $options['ga_dash_tableid'] = get_option('ga_dash_tableid');
97
- $options['ga_dash_frontend_keywords'] = 0;
98
- $options['ga_enhanced_links'] = 0;
99
- $options['ga_dash_remarketing'] = 0;
100
- $options['ga_dash_default_metric'] = 'sessions';
101
- $options['ga_dash_default_dimension'] = '30daysAgo';
102
- $options['ga_dash_network'] = 0;
103
- $options['ga_event_bouncerate'] = 0;
104
- $options['ga_crossdomain_tracking'] = 0;
105
- $options['ga_crossdomain_list'] = '';
106
- $options['ga_author_dimindex'] = 0;
107
- $options['ga_category_dimindex'] = 0;
108
- $options['ga_user_dimindex'] = 0;
109
- $options['ga_pubyear_dimindex'] = 0;
110
- $options['ga_event_affiliates'] = '/out/';
111
- $options['ga_aff_tracking'] = 0;
112
- $options['automatic_updates_minorversion'] = 1;
113
- $options['item_reports'] = 1;
114
- $options['dashboard_widget'] = 1;
115
-
116
- delete_option('ga_dash_apikey');
117
- delete_option('ga_dash_clientid');
118
- delete_option('ga_dash_clientsecret');
119
- delete_option('ga_dash_access');
120
- delete_option('ga_dash_access_front');
121
- delete_option('ga_dash_access_back');
122
- delete_option('ga_dash_tableid_jail');
123
- delete_option('ga_dash_frontend');
124
- delete_option('ga_dash_style');
125
- delete_option('ga_dash_jailadmins');
126
- delete_option('ga_dash_cachetime');
127
- delete_option('ga_dash_tracking');
128
- delete_option('ga_dash_tracking_type');
129
- delete_option('ga_dash_default_ua');
130
- delete_option('ga_dash_anonim');
131
- delete_option('ga_dash_userapi');
132
- delete_option('ga_event_tracking');
133
- delete_option('ga_event_downloads');
134
- delete_option('ga_track_exclude');
135
- delete_option('ga_target_geomap');
136
- delete_option('ga_realtime_pages');
137
- delete_option('ga_dash_token');
138
- delete_option('ga_dash_refresh_token');
139
- delete_option('ga_dash_profile_list');
140
- delete_option('ga_dash_tableid');
141
- }
142
- add_option('gadash_options', json_encode($options));
143
- }
 
144
  }
8
  */
9
 
10
  // Exit if accessed directly
11
+ if ( ! defined( 'ABSPATH' ) )
12
+ exit();
13
 
14
+ class GADWP_Install {
 
15
 
16
+ public static function install() {
17
+ if ( ! get_option( 'ga_dash_token' ) ) {
18
+ $options = array();
19
+ $options['ga_dash_apikey'] = '';
20
+ $options['ga_dash_clientid'] = '';
21
+ $options['ga_dash_clientsecret'] = '';
22
+ $options['ga_dash_access_front'][] = 'administrator';
23
+ $options['ga_dash_access_back'][] = 'administrator';
24
+ $options['ga_dash_tableid_jail'] = '';
25
+ $options['ga_dash_style'] = '#1e73be';
26
+ $options['switch_profile'] = 0;
27
+ $options['ga_dash_cachetime'] = 3600;
28
+ $options['ga_dash_tracking'] = 1;
29
+ $options['ga_dash_tracking_type'] = 'universal';
30
+ $options['ga_dash_default_ua'] = '';
31
+ $options['ga_dash_anonim'] = 0;
32
+ $options['ga_dash_userapi'] = 0;
33
+ $options['ga_event_tracking'] = 0;
34
+ $options['ga_event_downloads'] = 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*';
35
+ $options['ga_track_exclude'] = array();
36
+ $options['ga_target_geomap'] = '';
37
+ $options['ga_realtime_pages'] = 10;
38
+ $options['ga_dash_token'] = '';
39
+ $options['ga_dash_refresh_token'] = '';
40
+ $options['ga_dash_profile_list'] = array();
41
+ $options['ga_dash_tableid'] = '';
42
+ $options['ga_dash_frontend_keywords'] = 0;
43
+ $options['ga_tracking_code'] = '';
44
+ $options['ga_enhanced_links'] = 0;
45
+ $options['ga_dash_remarketing'] = 0;
46
+ $options['ga_dash_default_metric'] = 'sessions';
47
+ $options['ga_dash_default_dimension'] = '30daysAgo';
48
+ $options['ga_dash_frontend_stats'] = 0;
49
+ $options['ga_dash_network'] = 0;
50
+ $options['ga_dash_adsense'] = 0;
51
+ $options['ga_speed_samplerate'] = 1;
52
+ $options['ga_event_bouncerate'] = 0;
53
+ $options['ga_crossdomain_tracking'] = 0;
54
+ $options['ga_crossdomain_list'] = '';
55
+ $options['ga_author_dimindex'] = 0;
56
+ $options['ga_category_dimindex'] = 0;
57
+ $options['ga_user_dimindex'] = 0;
58
+ $options['ga_pubyear_dimindex'] = 0;
59
+ $options['ga_aff_tracking'] = 0;
60
+ $options['ga_event_affiliates'] = '/out/';
61
+ $options['automatic_updates_minorversion'] = 1;
62
+ $options['backend_item_reports'] = 1;
63
+ $options['frontend_item_reports'] = 0;
64
+ $options['dashboard_widget'] = 1;
65
+ } else {
66
+ $options = array();
67
+ $options['ga_dash_apikey'] = get_option( 'ga_dash_apikey' );
68
+ $options['ga_dash_clientid'] = get_option( 'ga_dash_clientid' );
69
+ $options['ga_dash_clientsecret'] = get_option( 'ga_dash_clientsecret' );
70
+ $options['ga_dash_access'] = get_option( 'ga_dash_access' );
71
+ $options['ga_dash_access_front'][] = 'administrator';
72
+ $options['ga_dash_access_back'][] = 'administrator';
73
+ $options['ga_dash_tableid_jail'] = get_option( 'ga_dash_tableid_jail' );
74
+ $options['ga_dash_frontend_stats'] = get_option( 'ga_dash_frontend' );
75
+ $options['ga_dash_style'] = '#1e73be';
76
+ $options['switch_profile'] = get_option( 'ga_dash_jailadmins' );
77
+ $options['ga_dash_cachetime'] = get_option( 'ga_dash_cachetime' );
78
+ if ( get_option( 'ga_dash_tracking' ) == 4 ) {
79
+ $options['ga_dash_tracking'] = 0;
80
+ } else {
81
+ $options['ga_dash_tracking'] = 1;
82
+ }
83
+ $options['ga_dash_tracking_type'] = get_option( 'ga_dash_tracking_type' );
84
+ $options['ga_dash_default_ua'] = get_option( 'ga_dash_default_ua' );
85
+ $options['ga_dash_anonim'] = get_option( 'ga_dash_anonim' );
86
+ $options['ga_dash_userapi'] = get_option( 'ga_dash_userapi' );
87
+ $options['ga_event_tracking'] = get_option( 'ga_event_tracking' );
88
+ $options['ga_event_downloads'] = get_option( 'ga_event_downloads' );
89
+ $options['ga_track_exclude'] = array();
90
+ $options['ga_target_geomap'] = get_option( 'ga_target_geomap' );
91
+ $options['ga_realtime_pages'] = get_option( 'ga_realtime_pages' );
92
+ $options['ga_dash_token'] = get_option( 'ga_dash_token' );
93
+ $options['ga_dash_refresh_token'] = get_option( 'ga_dash_refresh_token' );
94
+ $options['ga_dash_profile_list'] = get_option( 'ga_dash_profile_list' );
95
+ $options['ga_dash_tableid'] = get_option( 'ga_dash_tableid' );
96
+ $options['ga_dash_frontend_keywords'] = 0;
97
+ $options['ga_enhanced_links'] = 0;
98
+ $options['ga_dash_remarketing'] = 0;
99
+ $options['ga_dash_default_metric'] = 'sessions';
100
+ $options['ga_dash_default_dimension'] = '30daysAgo';
101
+ $options['ga_dash_network'] = 0;
102
+ $options['ga_event_bouncerate'] = 0;
103
+ $options['ga_crossdomain_tracking'] = 0;
104
+ $options['ga_crossdomain_list'] = '';
105
+ $options['ga_author_dimindex'] = 0;
106
+ $options['ga_category_dimindex'] = 0;
107
+ $options['ga_user_dimindex'] = 0;
108
+ $options['ga_pubyear_dimindex'] = 0;
109
+ $options['ga_event_affiliates'] = '/out/';
110
+ $options['ga_aff_tracking'] = 0;
111
+ $options['automatic_updates_minorversion'] = 1;
112
+ $options['backend_item_reports'] = 1;
113
+ $options['frontend_item_reports'] = 0;
114
+ $options['dashboard_widget'] = 1;
115
+
116
+ delete_option( 'ga_dash_apikey' );
117
+ delete_option( 'ga_dash_clientid' );
118
+ delete_option( 'ga_dash_clientsecret' );
119
+ delete_option( 'ga_dash_access' );
120
+ delete_option( 'ga_dash_access_front' );
121
+ delete_option( 'ga_dash_access_back' );
122
+ delete_option( 'ga_dash_tableid_jail' );
123
+ delete_option( 'ga_dash_frontend' );
124
+ delete_option( 'ga_dash_style' );
125
+ delete_option( 'ga_dash_jailadmins' );
126
+ delete_option( 'ga_dash_cachetime' );
127
+ delete_option( 'ga_dash_tracking' );
128
+ delete_option( 'ga_dash_tracking_type' );
129
+ delete_option( 'ga_dash_default_ua' );
130
+ delete_option( 'ga_dash_anonim' );
131
+ delete_option( 'ga_dash_userapi' );
132
+ delete_option( 'ga_event_tracking' );
133
+ delete_option( 'ga_event_downloads' );
134
+ delete_option( 'ga_track_exclude' );
135
+ delete_option( 'ga_target_geomap' );
136
+ delete_option( 'ga_realtime_pages' );
137
+ delete_option( 'ga_dash_token' );
138
+ delete_option( 'ga_dash_refresh_token' );
139
+ delete_option( 'ga_dash_profile_list' );
140
+ delete_option( 'ga_dash_tableid' );
141
+ }
142
+ add_option( 'gadash_options', json_encode( $options ) );
143
+ }
144
  }
install/uninstall.php CHANGED
@@ -8,41 +8,38 @@
8
  */
9
 
10
  // Exit if accessed directly
11
- if (! defined('ABSPATH'))
12
- exit();
13
 
14
- class GADWP_Uninstall
15
- {
16
 
17
- public static function uninstall()
18
- {
19
- global $wpdb;
20
- if (is_multisite()) { // Cleanup Network install
21
- foreach (wp_get_sites(array(
22
- 'limit' => apply_filters('gadwp_sites_limit', 100)
23
- )) as $blog) {
24
- switch_to_blog($blog['blog_id']);
25
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_gadash%%'");
26
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_gadash%%'");
27
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_ga_dash%%'");
28
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_ga_dash%%'");
29
- delete_option('gadash_options');
30
- delete_transient('ga_dash_lasterror');
31
- delete_transient('ga_dash_refresh_token');
32
- delete_transient('ga_dash_gapi_errors');
33
- restore_current_blog();
34
- }
35
- delete_site_option('gadash_network_options');
36
- delete_site_transient('ga_dash_refresh_token');
37
- } else { // Cleanup Single install
38
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_gadash%%'");
39
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_gadash%%'");
40
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_ga_dash%%'");
41
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_ga_dash%%'");
42
- delete_option('gadash_options');
43
- delete_transient('ga_dash_lasterror');
44
- delete_transient('ga_dash_refresh_token');
45
- delete_transient('ga_dash_gapi_errors');
46
- }
47
- }
48
  }
8
  */
9
 
10
  // Exit if accessed directly
11
+ if ( ! defined( 'ABSPATH' ) )
12
+ exit();
13
 
14
+ class GADWP_Uninstall {
 
15
 
16
+ public static function uninstall() {
17
+ global $wpdb;
18
+ if ( is_multisite() ) { // Cleanup Network install
19
+ foreach ( wp_get_sites( array(
20
+ 'limit' => apply_filters( 'gadwp_sites_limit', 100 ) ) ) as $blog ) {
21
+ switch_to_blog( $blog['blog_id'] );
22
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_gadash%%'" );
23
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_gadash%%'" );
24
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_ga_dash%%'" );
25
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_ga_dash%%'" );
26
+ delete_option( 'gadash_options' );
27
+ delete_transient( 'ga_dash_lasterror' );
28
+ delete_transient( 'ga_dash_refresh_token' );
29
+ delete_transient( 'ga_dash_gapi_errors' );
30
+ restore_current_blog();
31
+ }
32
+ delete_site_option( 'gadash_network_options' );
33
+ delete_site_transient( 'ga_dash_refresh_token' );
34
+ } else { // Cleanup Single install
35
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_gadash%%'" );
36
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_gadash%%'" );
37
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_ga_dash%%'" );
38
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_ga_dash%%'" );
39
+ delete_option( 'gadash_options' );
40
+ delete_transient( 'ga_dash_lasterror' );
41
+ delete_transient( 'ga_dash_refresh_token' );
42
+ delete_transient( 'ga_dash_gapi_errors' );
43
+ }
44
+ }
 
 
45
  }
readme.txt CHANGED
@@ -1,36 +1,34 @@
1
  === Google Analytics Dashboard for WP ===
2
  Contributors: deconf
3
  Donate link: https://deconf.com/donate/
4
- Tags: google,analytics,google analytics,dashboard,analytics dashboard,google analytics dashboard,google analytics widget,tracking,realtime,wpmu,multisite
5
  Requires at least: 3.5
6
  Tested up to: 4.2.2
7
- Stable tag: 4.7.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Displays Google Analytics reports and real-time statistics in your WordPress Dashboard. Inserts the latest tracking code in every page of your site.
12
 
13
  == Description ==
14
- Using a widget, [Google Analytics Dashboard](https://deconf.com/google-analytics-dashboard-wordpress/) displays detailed analytics data and reports about: number of sessions, number of visitors (users), page views, bounce rates, organic searches, pages per visit directly on your WordPress Dashboard.
 
15
 
16
- In addition, in-depth Page reports and in-depth Post reports allow further segmentation of your analytics data, providing performance details for each post or page from your website.
17
 
18
- This plugin also inserts the latest version of the Google Analytics tracking code in every page of your site. The tracking code is fully customizable through options and hooks.
19
-
20
- > <strong>Google Analytics Dashboard on GitHub</strong><br>
21
- > You can submit pull requests, feature requests or bugs on [Google Analytics Dashboard](https://github.com/deconf/Google-Analytics-Dashboard-for-WP) repository.
22
 
23
  = Google Analytics Real-Time =
24
 
25
  Google Analytics reports, in real-time, on your dashboard screen:
26
 
27
  - displays the total number of visitors in real-time
28
- - real-time statistics about your acquisition channels
29
  - per page real-time reports with traffic sources details
30
 
31
  = Google Analytics Reports =
32
 
33
- The reports you need, in your dashboard, in your Posts and Pages List, and on site's frontend:
34
 
35
  - you can access all websites statistics in a single widget (websites within same Google Account)
36
  - option to choose a default color for your charts, graphs and maps
@@ -38,30 +36,28 @@ The reports you need, in your dashboard, in your Posts and Pages List, and on si
38
  - location reports, displaying visitors by country on a Geo Map and in a table chart
39
  - local websites and business have an option to display cities, instead of countries, on a regional map and in a table chart
40
  - traffic overview reports with details about acquisition channels, social networks, search engines, traffic mediums and visitor type
41
- - per post or page analytics reports in Posts List and Pages List
42
- - option to display Google Analytics statistics on frontend, at the end of each article
43
- - frontend widget with website's analytics stats and analytics data anonymization feature
44
- - localization support, a POT file is available for translations
45
- - user access level settings for Backend statistics and analytics reports
46
- - user access level settings for Frontend analytics data and reports
47
- - options to disable certain analytics reports from backend or frontend
48
 
49
  = Google Analytics Tracking =
50
 
51
  Install the Google Analytics tracking code in less than a minute and customize it as you wish:
52
 
53
- - enable/disable google analytics tracking code
54
- - switch between universal analytics and classic analytics tracking methods
55
- - supports analytics.js tracking for compatibility with Universal Analytics web property
56
- - supports ga.js tracking for compatibility with Classic Analytics web property
57
  - automatically generates and inserts the Google Analytics tracking code
58
  - IP address anonymization feature
59
  - enhanced link attribution feature
60
  - remarketing, demographics and interests tracking
61
  - Google AdSense account linking
62
  - page speed sampling rate customization
63
- - track events feature: track downloads, emails and outbound links
64
- - exclude traffic based on user roles
65
  - option to exclude event tracking from bounce-rate calculation
66
  - multiple domains / cross domain tracking
67
  - action hook for code customization
@@ -77,9 +73,8 @@ Install the Google Analytics tracking code in less than a minute and customize i
77
  * <em>Mode 3:</em> network deactivated allowing each site owner to activate and authorize the plugin
78
  * option to exclude Super Admins from tracking
79
 
80
- = Translations =
81
-
82
- Google Analytics Dashboard has been translated and is available in more than 12 languages.
83
 
84
  = Further reading and info =
85
 
@@ -89,32 +84,30 @@ Google Analytics Dashboard has been translated and is available in more than 12
89
 
90
  == Installation ==
91
 
92
- 1. Upload the full directory into your wp-content/plugins directory
93
- 2. Activate the plugin at the plugin administration page
94
  3. Open the plugin configuration page, which is located under "Google Analytics" menu (optionally enter your API Key, Client Secret and Client ID).
95
- 4. Authorize the plugin using the 'Authorize Plugin' button
96
  5. Go back to the plugin configuration page, which is located under "Google Analytics" menu to update/set your settings.
97
- 6. Use Google Analytics Tracking options to configure/enable/disable tracking
98
-
99
- The documentation, tutorials and a short demo is available here: [Google Analytics Dashboard video tutorial](https://deconf.com/google-analytics-dashboard-wordpress/)
100
 
101
  == Frequently Asked Questions ==
102
 
103
  = Do I have to insert the Google Analytics tracking code manually? =
104
 
105
  No, once the plugin is authorized and a default domain is selected the Google Analytics tracking code is automatically inserted in all webpages.
106
-
107
- = I have an error =
108
-
109
- Here's a list with common errors and how to fix them [Errors in Google Analytics Dashboard](https://deconf.com/error-codes-in-google-analytics-dashboard-for-wordpress/)
110
 
111
  = Some settings are missing in the video tutorial =
112
 
113
  We are constantly improving our plugin, sometimes the video tutorial may be a little outdated.
114
 
115
- = More Questions? =
116
 
117
- A dedicated section for WordPress Plugins is available here: [Wordpress Plugins Support](https://deconf.com/ask/)
 
 
 
 
118
 
119
  == Screenshots ==
120
 
@@ -134,6 +127,30 @@ This plugin it's released under the GPLv2, you can use it free of charge on your
134
 
135
  == Changelog ==
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  = 4.7.5 =
138
  - Bug Fix: html encode single quotes for custom dimensions
139
 
@@ -147,7 +164,7 @@ This plugin it's released under the GPLv2, you can use it free of charge on your
147
  - Enhancement: Russian translation
148
  - Enhancement: Romanian translation
149
  - Enhancement: Hungarian translation updated
150
- - Enhancement: UX improvements, props by [adipop](https://github.com/adipop)
151
  - Enhancement: settings page cleanup
152
 
153
  = 4.7.2 =
1
  === Google Analytics Dashboard for WP ===
2
  Contributors: deconf
3
  Donate link: https://deconf.com/donate/
4
+ Tags: google,analytics,google analytics,dashboard,analytics dashboard,google analytics dashboard,google analytics plugin,google analytics widget,tracking,realtime,wpmu,multisite,gadwp
5
  Requires at least: 3.5
6
  Tested up to: 4.2.2
7
+ Stable tag: 4.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Displays Google Analytics reports and real-time statistics in your WordPress Dashboard. Inserts the latest Google Analytics tracking code in every page of your site.
12
 
13
  == Description ==
14
+ This Google Analytics for WordPress plugin enables you to track your site using the latest Google Analytics tracking code and allows you to view the analytics reports in your
15
+ WordPress install.
16
 
17
+ In addition to a set of general reports, in-depth Page reports and in-depth Post reports allow further segmentation of your analytics data, providing performance details for each post or page from your website.
18
 
19
+ The tracking code is fully customizable through options and hooks, allows you to collect data using custom dimensions and enables you to track downloads, outbound links, affiliate links, and fragment identifiers.
 
 
 
20
 
21
  = Google Analytics Real-Time =
22
 
23
  Google Analytics reports, in real-time, on your dashboard screen:
24
 
25
  - displays the total number of visitors in real-time
26
+ - real-time reports about your acquisition channels
27
  - per page real-time reports with traffic sources details
28
 
29
  = Google Analytics Reports =
30
 
31
+ The analytics reports you need, in your dashboard, in your All Posts and All Pages screens, and on site's frontend:
32
 
33
  - you can access all websites statistics in a single widget (websites within same Google Account)
34
  - option to choose a default color for your charts, graphs and maps
36
  - location reports, displaying visitors by country on a Geo Map and in a table chart
37
  - local websites and business have an option to display cities, instead of countries, on a regional map and in a table chart
38
  - traffic overview reports with details about acquisition channels, social networks, search engines, traffic mediums and visitor type
39
+ - per post or page Google Analytics reports in All Posts and All Pages screens
40
+ - option to display Google Analytics reports on frontend; available for each web page
41
+ - frontend widget with website's analytics stats and analytics report anonymization feature
42
+ - option to share your backend and frontend Google Analytics reports with specified user roles
43
+ - options to disable certain Google Analytics reports from backend or frontend
 
 
44
 
45
  = Google Analytics Tracking =
46
 
47
  Install the Google Analytics tracking code in less than a minute and customize it as you wish:
48
 
49
+ - enable/disable the Google Analytics tracking code
50
+ - switch between Universal Google Analytics and Classic Google Analytics tracking methods
51
+ - supports analytics.js tracking for compatibility with Universal Google Analytics web property
52
+ - supports ga.js tracking for compatibility with Classic Google Analytics web property
53
  - automatically generates and inserts the Google Analytics tracking code
54
  - IP address anonymization feature
55
  - enhanced link attribution feature
56
  - remarketing, demographics and interests tracking
57
  - Google AdSense account linking
58
  - page speed sampling rate customization
59
+ - track events feature: track downloads, emails and outbound links with Google Analytics
60
+ - exclude tracking based on user roles
61
  - option to exclude event tracking from bounce-rate calculation
62
  - multiple domains / cross domain tracking
63
  - action hook for code customization
73
  * <em>Mode 3:</em> network deactivated allowing each site owner to activate and authorize the plugin
74
  * option to exclude Super Admins from tracking
75
 
76
+ > <strong>Google Analytics Dashboard for WP on GitHub</strong><br>
77
+ > You can submit pull requests, feature requests or bugs on [Google Analytics Dashboard for WP](https://github.com/deconf/Google-Analytics-Dashboard-for-WP) repository.
 
78
 
79
  = Further reading and info =
80
 
84
 
85
  == Installation ==
86
 
87
+ 1. Upload the full directory into your wp-content/plugins directory.
88
+ 2. Activate the plugin at the plugin administration page.
89
  3. Open the plugin configuration page, which is located under "Google Analytics" menu (optionally enter your API Key, Client Secret and Client ID).
90
+ 4. Authorize the plugin using the 'Authorize Plugin' button.
91
  5. Go back to the plugin configuration page, which is located under "Google Analytics" menu to update/set your settings.
92
+ 6. Use Google Analytics Tracking options to configure/enable/disable tracking.
 
 
93
 
94
  == Frequently Asked Questions ==
95
 
96
  = Do I have to insert the Google Analytics tracking code manually? =
97
 
98
  No, once the plugin is authorized and a default domain is selected the Google Analytics tracking code is automatically inserted in all webpages.
 
 
 
 
99
 
100
  = Some settings are missing in the video tutorial =
101
 
102
  We are constantly improving our plugin, sometimes the video tutorial may be a little outdated.
103
 
104
+ = How can I make suggest a new feature, contribute or report a bug? =
105
 
106
+ You can submit pull requests, feature requests, translations or bug reports on [our GitHub repository](https://github.com/deconf/Google-Analytics-Dashboard-for-WP).
107
+
108
+ = Documentation, Tutorials and FAQ =
109
+
110
+ For documentation, tutorials, FAQ and videos check out: [Google Analytics Dashboard Documentation](https://deconf.com/google-analytics-dashboard-wordpress/).
111
 
112
  == Screenshots ==
113
 
127
 
128
  == Changelog ==
129
 
130
+ = 4.8.1 =
131
+ - Bug Fix: add % suffix to bouncerate item reports
132
+ - Bug Fix: add query string support to frontend item reports
133
+ - Bug Fix: make the main menu translatable
134
+ - Bug Fix: PHP notice while no View is assigned to a new network site
135
+ - Enhancement: French translation updated
136
+ - Enhancement: Romanian translation updated
137
+ - Enhancement: display an admin notice after manual and automatic updates
138
+ - Enhancement: small I18N tweaks and POT file update
139
+ - Enhancement: introducing last 14 days range in items reports
140
+ - Enhancement: introducing last 365 days range for all reports
141
+ - Enhancement: set the last selected report and date range as default for subsequent requests
142
+
143
+ = 4.8 =
144
+ - Enhancement: optimize the number of ajax requests
145
+ - Enhancement: new versioning standard for a better management of automatic updates (M.M.m.u)
146
+ - Enhancement: JavaScript code cleanup and optimization
147
+ - Enhancement: memory usage optimization
148
+ - Enhancement: small assets fixes, UX improvements, props by [Adrian Pop](https://github.com/adipop)
149
+ - Enhancement: introducing reports for all frontend web pages (new feature)
150
+ - Enhancement: gadwp_frontenditem_uri filter to allow URI corrections for frontend item reports
151
+ - Bug Fix: avoid double encoding of UTF-8 URIs
152
+ - Bug Fix: 100% number formatting issue on bounce rate report
153
+
154
  = 4.7.5 =
155
  - Bug Fix: html encode single quotes for custom dimensions
156
 
164
  - Enhancement: Russian translation
165
  - Enhancement: Romanian translation
166
  - Enhancement: Hungarian translation updated
167
+ - Enhancement: UX improvements, props by [Adrian Pop](https://github.com/adipop)
168
  - Enhancement: settings page cleanup
169
 
170
  = 4.7.2 =
tools/gapi.php CHANGED
@@ -7,126 +7,117 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
-
13
- if (! class_exists('GADWP_GAPI_Controller')) {
14
-
15
- final class GADWP_GAPI_Controller
16
- {
17
-
18
- public $client;
19
-
20
- public $service;
21
-
22
- public $timeshift;
23
-
24
- public $error_timeout;
25
-
26
- private $managequota;
27
-
28
- private $gadwp;
29
-
30
- public function __construct()
31
- {
32
- $this->gadwp = GADWP();
33
-
34
- include_once (GADWP_DIR . 'tools/autoload.php');
35
- $config = new Google_Config();
36
- $config->setCacheClass('Google_Cache_Null');
37
- if (function_exists('curl_version')) {
38
- $curlversion = curl_version();
39
- if (isset($curlversion['version']) && (version_compare(PHP_VERSION, '5.3.0') >= 0) && version_compare($curlversion['version'], '7.10.8') >= 0 && defined('GADWP_IP_VERSION') && GADWP_IP_VERSION) {
40
- $config->setClassConfig('Google_IO_Curl', array(
41
- 'options' => array(
42
- CURLOPT_IPRESOLVE => GADWP_IP_VERSION
43
- )
44
- )); // Force CURL_IPRESOLVE_V4 or CURL_IPRESOLVE_V6
45
- }
46
- }
47
- $this->client = new Google_Client($config);
48
- $this->client->setScopes('https://www.googleapis.com/auth/analytics.readonly');
49
- $this->client->setAccessType('offline');
50
- $this->client->setApplicationName('Google Analytics Dashboard');
51
- $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
52
- $this->set_error_timeout();
53
- $this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id();
54
- if ($this->gadwp->config->options['ga_dash_userapi']) {
55
- $this->client->setClientId($this->gadwp->config->options['ga_dash_clientid']);
56
- $this->client->setClientSecret($this->gadwp->config->options['ga_dash_clientsecret']);
57
- $this->client->setDeveloperKey($this->gadwp->config->options['ga_dash_apikey']);
58
- } else {
59
- $this->client->setClientId($this->gadwp->config->access[0]);
60
- $this->client->setClientSecret($this->gadwp->config->access[1]);
61
- $this->client->setDeveloperKey($this->gadwp->config->access[2]);
62
- }
63
- $this->service = new Google_Service_Analytics($this->client);
64
- if ($this->gadwp->config->options['ga_dash_token']) {
65
- $token = $this->gadwp->config->options['ga_dash_token'];
66
- $token = $this->refresh_token();
67
- if ($token) {
68
- $this->client->setAccessToken($token);
69
- }
70
- }
71
- }
72
-
73
- private function set_error_timeout()
74
- {
75
- $midnight = strtotime("tomorrow 00:00:00"); // UTC midnight
76
- $midnight = $midnight + 8 * 3600; // UTC 8 AM
77
- $this->error_timeout = $midnight - time();
78
- return;
79
- }
80
-
81
- /**
82
- * Handles errors returned by GAPI and allows exponential backoff
83
- *
84
- * @return boolean
85
- */
86
- public function gapi_errors_handler()
87
- {
88
- $errors = get_transient('ga_dash_gapi_errors');
89
- if ($errors === false || ! isset($errors[0])) { // invalid error
90
- return false;
91
- }
92
- if (isset($errors[1][0]['reason']) && ($errors[1][0]['reason'] == 'invalidCredentials' || $errors[1][0]['reason'] == 'authError' || $errors[1][0]['reason'] == 'insufficientPermissions' || $errors[1][0]['reason'] == 'required' || $errors[1][0]['reason'] == 'keyExpired')) {
93
- $this->reset_token(false);
94
- return true;
95
- }
96
- if (isset($errors[1][0]['reason']) && ($errors[1][0]['reason'] == 'userRateLimitExceeded' || $errors[1][0]['reason'] == 'quotaExceeded')) { // allow retry
97
- return false;
98
- }
99
- if ($errors[0] == 400 || $errors[0] == 401 || $errors[0] == 403) {
100
- return true;
101
- }
102
- return false;
103
- }
104
-
105
- /**
106
- * Calculates proper timeouts for each GAPI query
107
- *
108
- * @param
109
- * $daily
110
- * @return number
111
- */
112
- public function get_timeouts($daily)
113
- {
114
- $local_time = time() + $this->timeshift;
115
- if ($daily) {
116
- $nextday = explode('-', date('n-j-Y', strtotime(' +1 day', $local_time)));
117
- $midnight = mktime(0, 0, 0, $nextday[0], $nextday[1], $nextday[2]);
118
- return $midnight - $local_time;
119
- } else {
120
- $nexthour = explode('-', date('H-n-j-Y', strtotime(' +1 hour', $local_time)));
121
- $newhour = mktime($nexthour[0], 0, 0, $nexthour[1], $nexthour[2], $nexthour[3]);
122
- return $newhour - $local_time;
123
- }
124
- }
125
-
126
- public function token_request()
127
- {
128
- $authUrl = $this->client->createAuthUrl();
129
- ?>
130
  <form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
131
  <table class="options">
132
  <tr>
@@ -147,876 +138,645 @@ if (! class_exists('GADWP_GAPI_Controller')) {
147
  </table>
148
  </form>
149
  <?php
150
- }
151
-
152
- /**
153
- * Retrives all Google Analytics Views with details
154
- *
155
- * @return array
156
- */
157
- public function refresh_profiles()
158
- {
159
- try {
160
-
161
- $ga_dash_profile_list = array();
162
- $startindex = 1;
163
- $totalresults = 65535; //use something big
164
-
165
- while ($startindex < $totalresults) {
166
-
167
- $profiles = $this->service->management_profiles->listManagementProfiles('~all', '~all', array(
168
- 'start-index' => $startindex
169
- ));
170
-
171
- $items = $profiles->getItems();
172
-
173
- $totalresults = $profiles->getTotalResults();
174
-
175
- if ($totalresults > 0) {
176
-
177
- foreach ($items as $profile) {
178
- $timetz = new DateTimeZone($profile->getTimezone());
179
- $localtime = new DateTime('now', $timetz);
180
- $timeshift = strtotime($localtime->format('Y-m-d H:i:s')) - time();
181
- $ga_dash_profile_list[] = array(
182
- $profile->getName(),
183
- $profile->getId(),
184
- $profile->getwebPropertyId(),
185
- $profile->getwebsiteUrl(),
186
- $timeshift,
187
- $profile->getTimezone()
188
- );
189
-
190
- $startindex ++;
191
- }
192
-
193
- }
194
-
195
- }
196
-
197
- if (empty($ga_dash_profile_list)) {
198
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': No properties were found in this account!', $this->error_timeout);
199
- } else {
200
- set_transient('ga_dash_lasterror', 'None');
201
- }
202
-
203
- return $ga_dash_profile_list;
204
-
205
- } catch (Google_IO_Exception $e) {
206
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
207
- return $ga_dash_profile_list;
208
- } catch (Google_Service_Exception $e) {
209
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
210
- set_transient('ga_dash_gapi_errors', array(
211
- $e->getCode(),
212
- (array) $e->getErrors()
213
- ), $this->error_timeout);
214
- } catch (Exception $e) {
215
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
216
- return $ga_dash_profile_list;
217
- }
218
- }
219
-
220
- /**
221
- * Handles the token refresh process
222
- *
223
- * @return token|boolean
224
- */
225
- private function refresh_token()
226
- {
227
- try {
228
- if (is_multisite() && $this->gadwp->config->options['ga_dash_network']) {
229
- $transient = get_site_transient("ga_dash_refresh_token");
230
- } else {
231
- $transient = get_transient("ga_dash_refresh_token");
232
- }
233
- if ($transient === false) {
234
- if (! $this->gadwp->config->options['ga_dash_refresh_token']) {
235
- $google_token = json_decode($this->gadwp->config->options['ga_dash_token']);
236
- $this->gadwp->config->options['ga_dash_refresh_token'] = $google_token->refresh_token;
237
- $this->client->refreshToken($google_token->refresh_token);
238
- } else {
239
- $this->client->refreshToken($this->gadwp->config->options['ga_dash_refresh_token']);
240
- }
241
- $token = $this->client->getAccessToken();
242
- $google_token = json_decode($token);
243
- $this->gadwp->config->options['ga_dash_token'] = $token;
244
- if (is_multisite() && $this->gadwp->config->options['ga_dash_network']) {
245
- set_site_transient("ga_dash_refresh_token", $token, $google_token->expires_in);
246
- $this->gadwp->config->set_plugin_options(true);
247
- } else {
248
- set_transient("ga_dash_refresh_token", $token, $google_token->expires_in);
249
- $this->gadwp->config->set_plugin_options();
250
- }
251
- return $token;
252
- } else {
253
- return $transient;
254
- }
255
- } catch (Google_IO_Exception $e) {
256
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
257
- return false;
258
- } catch (Google_Service_Exception $e) {
259
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
260
- set_transient('ga_dash_gapi_errors', array(
261
- $e->getCode(),
262
- (array) $e->getErrors()
263
- ), $this->error_timeout);
264
- return $e->getCode();
265
- } catch (Exception $e) {
266
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
267
- return false;
268
- }
269
- }
270
-
271
- /**
272
- * Handles the token reset process
273
- *
274
- * @param
275
- * $all
276
- */
277
- public function reset_token($all = true)
278
- {
279
- if (is_multisite() && $this->gadwp->config->options['ga_dash_network']) {
280
- delete_site_transient('ga_dash_refresh_token');
281
- } else {
282
- delete_transient('ga_dash_refresh_token');
283
- }
284
- $this->gadwp->config->options['ga_dash_token'] = "";
285
- $this->gadwp->config->options['ga_dash_refresh_token'] = "";
286
- if ($all) {
287
- $this->gadwp->config->options['ga_dash_tableid'] = "";
288
- $this->gadwp->config->options['ga_dash_tableid_jail'] = "";
289
- $this->gadwp->config->options['ga_dash_profile_list'] = array();
290
- try {
291
- $this->client->revokeToken();
292
- } catch (Exception $e) {
293
- if (is_multisite() && $this->gadwp->config->options['ga_dash_network']) {
294
- $this->gadwp->config->set_plugin_options(true);
295
- } else {
296
- $this->gadwp->config->set_plugin_options();
297
- }
298
- }
299
- }
300
- if (is_multisite() && $this->gadwp->config->options['ga_dash_network']) {
301
- $this->gadwp->config->set_plugin_options(true);
302
- } else {
303
- $this->gadwp->config->set_plugin_options();
304
- }
305
- }
306
-
307
- /**
308
- * Get and cache Core Reports
309
- *
310
- * @todo implement retries with exponential backoff
311
- *
312
- * @param
313
- * $projecId
314
- * @param
315
- * $from
316
- * @param
317
- * $to
318
- * @param
319
- * $metrics
320
- * @param
321
- * $options
322
- * @param
323
- * $serial
324
- * @return int|Google_Service_Analytics_GaData
325
- */
326
- private function handle_corereports($projectId, $from, $to, $metrics, $options, $serial)
327
- {
328
- try {
329
- if ($from == "today") {
330
- $timeouts = 0;
331
- } else {
332
- $timeouts = 1;
333
- }
334
- $transient = get_transient($serial);
335
- if ($transient === false) {
336
- if ($this->gapi_errors_handler()) {
337
- return - 23;
338
- }
339
- $data = $this->service->data_ga->get('ga:' . $projectId, $from, $to, $metrics, $options);
340
- set_transient($serial, $data, $this->get_timeouts($timeouts));
341
- } else {
342
- $data = $transient;
343
- }
344
- } catch (Google_Service_Exception $e) {
345
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
346
- set_transient('ga_dash_gapi_errors', array(
347
- $e->getCode(),
348
- (array) $e->getErrors()
349
- ), $this->error_timeout);
350
- return $e->getCode();
351
- } catch (Exception $e) {
352
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
353
- return $e->getCode();
354
- }
355
- if ($data->getRows() > 0) {
356
- return $data;
357
- } else {
358
- return - 21;
359
- }
360
- }
361
-
362
- /**
363
- * Generates serials for transients
364
- *
365
- * @param
366
- * $serial
367
- * @return string
368
- */
369
- public function get_serial($serial)
370
- {
371
- return sprintf("%u", crc32($serial));
372
- }
373
-
374
- /**
375
- * Analytics data for backend reports (Admin Widget main report)
376
- *
377
- * @param
378
- * $projectId
379
- * @param
380
- * $from
381
- * @param
382
- * $to
383
- * @param
384
- * $query
385
- * @return array|int
386
- */
387
- public function get_mainreport($projectId, $from, $to, $query, $filter = '')
388
- {
389
- switch ($query) {
390
- case 'users':
391
- $title = __("Users", 'ga-dash');
392
- break;
393
- case 'pageviews':
394
- $title = __("Page Views", 'ga-dash');
395
- break;
396
- case 'visitBounceRate':
397
- $title = __("Bounce Rate", 'ga-dash');
398
- break;
399
- case 'organicSearches':
400
- $title = __("Organic Searches", 'ga-dash');
401
- break;
402
- case 'uniquePageviews':
403
- $title = __("Unique Page Views", 'ga-dash');
404
- break;
405
- default:
406
- $title = __("Sessions", 'ga-dash');
407
- }
408
- $metrics = 'ga:' . $query;
409
- if ($from == "today" || $from == "yesterday") {
410
- $dimensions = 'ga:hour';
411
- $dayorhour = __("Hour", 'ga-dash');
412
- } else {
413
- $dimensions = 'ga:date,ga:dayOfWeekName';
414
- $dayorhour = __("Date", 'ga-dash');
415
- }
416
- $options = array(
417
- 'dimensions' => $dimensions,
418
- 'quotaUser' => $this->managequota . 'p' . $projectId
419
- );
420
- if ($filter) {
421
- $options['filters'] = 'ga:pagePath==' . $filter;
422
- }
423
- $serial = 'gadash_qr2_' . $this->get_serial($projectId . $from . $metrics . $filter);
424
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
425
- if (is_numeric($data)) {
426
- return $data;
427
- }
428
- $ga_dash_data = array(
429
- array(
430
- $dayorhour,
431
- $title
432
- )
433
- );
434
- if ($from == "today" || $from == "yesterday") {
435
- foreach ($data->getRows() as $row) {
436
- $ga_dash_data[] = array(
437
- (int) $row[0] . ':00',
438
- round($row[1], 2)
439
- );
440
- }
441
- } else {
442
- foreach ($data->getRows() as $row) {
443
- $ga_dash_data[] = array(
444
- esc_html(ucfirst(__($row[1]))) . ',' . esc_html(substr_replace(substr_replace($row[0], "-", 4, 0), "-", 7, 0)),
445
- round($row[2], 2)
446
- );
447
- }
448
- }
449
- return $ga_dash_data;
450
- }
451
-
452
- /**
453
- * Analytics data for backend reports (bottom stats main report)
454
- *
455
- * @param
456
- * $projectId
457
- * @param
458
- * $from
459
- * @param
460
- * $to
461
- * @return array|int
462
- */
463
- public function get_bottomstats($projectId, $from, $to, $filter = '')
464
- {
465
- $options = array(
466
- 'dimensions' => null,
467
- 'quotaUser' => $this->managequota . 'p' . $projectId
468
- );
469
- if ($filter) {
470
- $options['filters'] = 'ga:pagePath==' . $filter;
471
- $metrics = 'ga:uniquePageviews,ga:users,ga:pageviews,ga:BounceRate,ga:organicSearches,ga:pageviewsPerSession';
472
- } else {
473
- $metrics = 'ga:sessions,ga:users,ga:pageviews,ga:BounceRate,ga:organicSearches,ga:pageviewsPerSession';
474
- }
475
- $serial = 'gadash_qr3_' . $this->get_serial($projectId . $from . $filter);
476
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
477
- if (is_numeric($data)) {
478
- if ($data == - 21) {
479
- return array_fill(0, 6, 0);
480
- } else {
481
- return $data;
482
- }
483
- }
484
- $ga_dash_data = array();
485
- foreach ($data->getRows() as $row) {
486
- $ga_dash_data = array_map('floatval', $row);
487
- }
488
- return $ga_dash_data;
489
- }
490
-
491
- /**
492
- * Analytics data for backend reports (contentpages)
493
- *
494
- * @param
495
- * $projectId
496
- * @param
497
- * $from
498
- * @param
499
- * $to
500
- * @return array|int
501
- */
502
- public function get_contentpages($projectId, $from, $to, $filter = '')
503
- {
504
- $metrics = 'ga:pageviews';
505
- $dimensions = 'ga:pageTitle';
506
- $options = array(
507
- 'dimensions' => $dimensions,
508
- 'sort' => '-ga:pageviews',
509
- 'quotaUser' => $this->managequota . 'p' . $projectId
510
- );
511
- if ($filter) {
512
- $options['filters'] = 'ga:pagePath==' . $filter;
513
- }
514
- $serial = 'gadash_qr4_' . $this->get_serial($projectId . $from . $filter);
515
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
516
- if (is_numeric($data)) {
517
- return $data;
518
- }
519
- $ga_dash_data = array(
520
- array(
521
- __("Pages", 'ga-dash'),
522
- __("Views", 'ga-dash')
523
- )
524
- );
525
- foreach ($data->getRows() as $row) {
526
- $ga_dash_data[] = array(
527
- esc_html($row[0]),
528
- (int) $row[1]
529
- );
530
- }
531
- return $ga_dash_data;
532
- }
533
-
534
- /**
535
- * Analytics data for backend reports (referrers)
536
- *
537
- * @param
538
- * $projectId
539
- * @param
540
- * $from
541
- * @param
542
- * $to
543
- * @return array|int
544
- */
545
- public function get_referrers($projectId, $from, $to, $filter = '')
546
- {
547
- $metrics = 'ga:sessions';
548
- $dimensions = 'ga:source';
549
- $options = array(
550
- 'dimensions' => $dimensions,
551
- 'sort' => '-ga:sessions',
552
- 'quotaUser' => $this->managequota . 'p' . $projectId
553
- );
554
- if ($filter) {
555
- $options['filters'] = 'ga:medium==referral;ga:pagePath==' . $filter;
556
- } else {
557
- $options['filters'] = 'ga:medium==referral';
558
- }
559
- $serial = 'gadash_qr5_' . $this->get_serial($projectId . $from . $filter);
560
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
561
- if (is_numeric($data)) {
562
- return $data;
563
- }
564
- $ga_dash_data = array(
565
- array(
566
- __("Referrers", 'ga-dash'),
567
- __("Sessions", 'ga-dash')
568
- )
569
- );
570
- foreach ($data->getRows() as $row) {
571
- $ga_dash_data[] = array(
572
- esc_html($row[0]),
573
- (int) $row[1]
574
- );
575
- }
576
- return $ga_dash_data;
577
- }
578
-
579
- /**
580
- * Analytics data for backend reports (searches)
581
- *
582
- * @param
583
- * $projectId
584
- * @param
585
- * $from
586
- * @param
587
- * $to
588
- * @return array|int
589
- */
590
- public function get_searches($projectId, $from, $to, $filter = '')
591
- {
592
- $metrics = 'ga:sessions';
593
- $dimensions = 'ga:keyword';
594
- $options = array(
595
- 'dimensions' => $dimensions,
596
- 'sort' => '-ga:sessions',
597
- 'quotaUser' => $this->managequota . 'p' . $projectId
598
- );
599
- if ($filter) {
600
- $options['filters'] = 'ga:keyword!=(not set);ga:pagePath==' . $filter;
601
- } else {
602
- $options['filters'] = 'ga:keyword!=(not set)';
603
- }
604
- $serial = 'gadash_qr6_' . $this->get_serial($projectId . $from . $filter);
605
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
606
- if (is_numeric($data)) {
607
- return $data;
608
- }
609
-
610
- $ga_dash_data = array(
611
- array(
612
- __("Searches", 'ga-dash'),
613
- __("Sessions", 'ga-dash')
614
- )
615
- );
616
- foreach ($data->getRows() as $row) {
617
- $ga_dash_data[] = array(
618
- esc_html($row[0]),
619
- (int) $row[1]
620
- );
621
- }
622
- return $ga_dash_data;
623
- }
624
-
625
- /**
626
- * Analytics data for backend reports (location reports)
627
- *
628
- * @param
629
- * $projectId
630
- * @param
631
- * $from
632
- * @param
633
- * $to
634
- * @return array|int
635
- */
636
- public function get_locations($projectId, $from, $to, $filter = '')
637
- {
638
- $metrics = 'ga:sessions';
639
- $options = "";
640
- $title = __("Countries", 'ga-dash');
641
- $serial = 'gadash_qr7_' . $this->get_serial($projectId . $from . $filter);
642
- $dimensions = 'ga:country';
643
- $local_filter = '';
644
- if ($this->gadwp->config->options['ga_target_geomap']) {
645
- $dimensions = 'ga:city, ga:region';
646
-
647
- $country_codes = GADWP_Tools::get_countrycodes();
648
- if (isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) {
649
- $local_filter = 'ga:country==' . ($country_codes[$this->gadwp->config->options['ga_target_geomap']]);
650
- $title = __("Cities from", 'ga-dash') . ' ' . __($country_codes[$this->gadwp->config->options['ga_target_geomap']]);
651
- $serial = 'gadash_qr7_' . $this->get_serial($projectId . $from . $this->gadwp->config->options['ga_target_geomap'] . $filter);
652
- }
653
- }
654
- $options = array(
655
- 'dimensions' => $dimensions,
656
- 'sort' => '-ga:sessions',
657
- 'quotaUser' => $this->managequota . 'p' . $projectId
658
- );
659
- if ($filter) {
660
- $options['filters'] = 'ga:pagePath==' . $filter;
661
- if ($local_filter) {
662
- $options['filters'] .= ';' . $local_filter;
663
- }
664
- } else {
665
- if ($local_filter) {
666
- $options['filters'] = $local_filter;
667
- }
668
- }
669
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
670
- if (is_numeric($data)) {
671
- return $data;
672
- }
673
- $ga_dash_data = array(
674
- array(
675
- $title,
676
- __("Sessions", 'ga-dash')
677
- )
678
- );
679
- foreach ($data->getRows() as $row) {
680
- if (isset($row[2])) {
681
- $ga_dash_data[] = array(
682
- esc_html($row[0]) . ', ' . esc_html($row[1]),
683
- (int) $row[2]
684
- );
685
- } else {
686
- $ga_dash_data[] = array(
687
- esc_html($row[0]),
688
- (int) $row[1]
689
- );
690
- }
691
- }
692
- return $ga_dash_data;
693
- }
694
-
695
- /**
696
- * Analytics data for backend reports (traffic channels)
697
- *
698
- * @param
699
- * $projectId
700
- * @param
701
- * $from
702
- * @param
703
- * $to
704
- * @return array|int
705
- */
706
- public function get_trafficchannels($projectId, $from, $to, $filter = '')
707
- {
708
- $metrics = 'ga:sessions';
709
- $dimensions = 'ga:channelGrouping';
710
- $options = array(
711
- 'dimensions' => $dimensions,
712
- 'quotaUser' => $this->managequota . 'p' . $projectId
713
- );
714
- if ($filter) {
715
- $options['filters'] = 'ga:pagePath==' . $filter;
716
- }
717
- $serial = 'gadash_qr8_' . $this->get_serial($projectId . $from . $filter);
718
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
719
- if (is_numeric($data)) {
720
- return $data;
721
- }
722
- $title = __("Channels", 'ga-dash');
723
- $ga_dash_data = array(
724
- array(
725
- '<div style="color:black; font-size:1.1em">' . $title . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>',
726
- ""
727
- )
728
- );
729
- foreach ($data->getRows() as $row) {
730
- $shrink = explode(" ", $row[0]);
731
- $ga_dash_data[] = array(
732
- '<div style="color:black; font-size:1.1em">' . esc_html($shrink[0]) . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $row[1] . '</div>',
733
- '<div style="color:black; font-size:1.1em">' . $title . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>'
734
- );
735
- }
736
- return $ga_dash_data;
737
- }
738
-
739
- /**
740
- * Analytics data for backend reports (traffic mediums, type, serach engines, social networks)
741
- *
742
- * @param
743
- * $projectId
744
- * @param
745
- * $from
746
- * @param
747
- * $to
748
- * @param
749
- * $query
750
- * @return array|int
751
- */
752
- public function get_trafficdetails($projectId, $from, $to, $query, $filter = '')
753
- {
754
- $metrics = 'ga:sessions';
755
- $dimensions = 'ga:' . $query;
756
-
757
- if ($query == 'source') {
758
- $options = array(
759
- 'dimensions' => $dimensions,
760
- 'quotaUser' => $this->managequota . 'p' . $projectId
761
- );
762
- if ($filter) {
763
- $options['filters'] = 'ga:medium==organic;ga:keyword!=(not set);ga:pagePath==' . $filter;
764
- } else {
765
- $options['filters'] = 'ga:medium==organic;ga:keyword!=(not set)';
766
- }
767
- } else {
768
- $options = array(
769
- 'dimensions' => $dimensions,
770
- 'quotaUser' => $this->managequota . 'p' . $projectId
771
- );
772
- if ($filter) {
773
- $options['filters'] = 'ga:' . $query . '!=(not set);ga:pagePath==' . $filter;
774
- } else {
775
- $options['filters'] = 'ga:' . $query . '!=(not set)';
776
- }
777
- }
778
- $serial = 'gadash_qr10_' . $this->get_serial($projectId . $from . $query . $filter);
779
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
780
- if (is_numeric($data)) {
781
- return $data;
782
- }
783
- $ga_dash_data = array(
784
- array(
785
- __("Type", 'ga-dash'),
786
- __("Sessions", 'ga-dash')
787
- )
788
- );
789
- foreach ($data->getRows() as $row) {
790
- $ga_dash_data[] = array(
791
- str_replace("(none)", "direct", esc_html($row[0])),
792
- (int) $row[1]
793
- );
794
- }
795
- return $ga_dash_data;
796
- }
797
-
798
- /**
799
- * Analytics data for frontend Widget (chart data and totals)
800
- *
801
- * @param
802
- * $projectId
803
- * @param
804
- * $period
805
- * @param
806
- * $anonim
807
- * @return array|int
808
- */
809
- public function frontend_widget_stats($projectId, $from, $anonim)
810
- {
811
- $content = '';
812
- $to = 'yesterday';
813
- $metrics = 'ga:sessions';
814
- $dimensions = 'ga:date,ga:dayOfWeekName';
815
- $options = array(
816
- 'dimensions' => $dimensions,
817
- 'quotaUser' => $this->managequota . 'p' . $projectId
818
- );
819
- $serial = 'gadash_qr2_' . $this->get_serial($projectId . $from . $metrics);
820
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
821
- if (is_numeric($data)) {
822
- return $data;
823
- }
824
- $ga_dash_data = array(
825
- array(
826
- __("Date", 'ga-dash'),
827
- __("Sessions", 'ga-dash') . ($anonim ? "' " . __("trend", 'ga-dash') : '')
828
- )
829
- );
830
- if ($anonim) {
831
- $max_array = array();
832
- foreach ($data->getRows() as $item) {
833
- $max_array[] = $item[2];
834
- }
835
- $max = max($max_array) ? max($max_array) : 1;
836
- }
837
- foreach ($data->getRows() as $row) {
838
- $ga_dash_data[] = array(
839
- ucfirst(esc_html((__($row[1])))) . ', ' . esc_html(substr_replace(substr_replace($row[0], "-", 4, 0), "-", 7, 0)),
840
- ($anonim ? round($row[2] * 100 / $max, 2) : (int) $row[2])
841
- );
842
- }
843
- $totals = $data->getTotalsForAllResults();
844
- return array(
845
- $ga_dash_data,
846
- $anonim ? 0 : $totals['ga:sessions']
847
- );
848
- }
849
-
850
- /**
851
- * Analytics data for frontend reports (pagviews and unique pageviews per page)
852
- *
853
- * @param
854
- * $projectId
855
- * @param
856
- * $page_url
857
- * @return array|int
858
- */
859
- public function frontend_afterpost_pageviews($projectId, $page_url)
860
- {
861
- $from = '30daysAgo';
862
- $to = 'yesterday';
863
- $metrics = 'ga:pageviews,ga:uniquePageviews';
864
- $dimensions = 'ga:date,ga:dayOfWeekName';
865
- $serial = 'gadash_qr21_' . $this->get_serial($page_url . 'stats');
866
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, array(
867
- 'dimensions' => $dimensions,
868
- 'filters' => 'ga:pagePath==' . $page_url,
869
- 'quotaUser' => $this->managequota . 'p' . $projectId
870
- ), $serial);
871
- if (is_numeric($data)) {
872
- return $data;
873
- }
874
- $ga_dash_data = array(
875
- array(
876
- __("Date", 'ga-dash'),
877
- __("Views", 'ga-dash'),
878
- __('UniqueViews', "ga-dash")
879
- )
880
- );
881
- foreach ($data->getRows() as $row) {
882
- $ga_dash_data[] = array(
883
- ucfirst(esc_html(__($row[1]))) . ',' . esc_html(substr_replace(substr_replace($row[0], "-", 4, 0), "-", 7, 0)),
884
- round($row[2], 2),
885
- round($row[3], 2)
886
- );
887
- }
888
- return $ga_dash_data;
889
- }
890
-
891
- /**
892
- * Analytics data for frontend reports (searches per page)
893
- *
894
- * @param
895
- * $projectId
896
- * @param
897
- * $page_url
898
- * @return array|int
899
- */
900
- public function frontend_afterpost_searches($projectId, $page_url)
901
- {
902
- $from = '30daysAgo';
903
- $to = 'yesterday';
904
- $metrics = 'ga:sessions';
905
- $dimensions = 'ga:keyword';
906
- $serial = 'gadash_qr22_' . $this->get_serial($page_url . 'search');
907
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, array(
908
- 'dimensions' => $dimensions,
909
- 'sort' => '-ga:sessions',
910
- 'filters' => 'ga:pagePath==' . $page_url . ';ga:keyword!=(not set)',
911
- 'quotaUser' => $this->managequota . 'p' . $projectId
912
- ), $serial);
913
- if (is_numeric($data)) {
914
- return $data;
915
- }
916
- $ga_dash_data = array(
917
- array(
918
- __("Searches", 'ga-dash'),
919
- __("Sessions", 'ga-dash')
920
- )
921
- );
922
- foreach ($data->getRows() as $row) {
923
- $ga_dash_data[] = array(
924
- esc_html($row[0]),
925
- (int) $row[1]
926
- );
927
- }
928
- return $ga_dash_data;
929
- }
930
-
931
- /**
932
- * Analytics data for backend reports (Real-Time)
933
- *
934
- * @param
935
- * $projectId
936
- * @return array|int
937
- */
938
- public function get_realtime($projectId)
939
- {
940
- $metrics = 'rt:activeUsers';
941
- $dimensions = 'rt:pagePath,rt:source,rt:keyword,rt:trafficType,rt:visitorType,rt:pageTitle';
942
- try {
943
- $serial = 'gadash_realtimecache_' . $this->get_serial($projectId);
944
- $transient = get_transient($serial);
945
- if ($transient === false) {
946
- if ($this->gapi_errors_handler()) {
947
- return - 23;
948
- }
949
- $data = $this->service->data_realtime->get('ga:' . $projectId, $metrics, array(
950
- 'dimensions' => $dimensions,
951
- 'quotaUser' => $this->managequota . 'p' . $projectId
952
- ));
953
- set_transient($serial, $data, 55);
954
- } else {
955
- $data = $transient;
956
- }
957
- } catch (Google_Service_Exception $e) {
958
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
959
- set_transient('ga_dash_gapi_errors', array(
960
- $e->getCode(),
961
- (array) $e->getErrors()
962
- ), $this->error_timeout);
963
- return $e->getCode();
964
- } catch (Exception $e) {
965
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
966
- return $e->getCode();
967
- }
968
- if ($data->getRows() < 1) {
969
- return - 21;
970
- }
971
- $i = 0;
972
- $ga_dash_data = $data;
973
- foreach ($data->getRows() as $row) {
974
- $ga_dash_data->rows[$i] = array_map('esc_html', $row);
975
- $i ++;
976
- }
977
- return $ga_dash_data;
978
- }
979
-
980
- public function get($projectId, $query, $from = false, $to = false, $filter = '')
981
- {
982
- switch ($query) {
983
- case 'referrers':
984
- wp_send_json($this->get_referrers($projectId, $from, $to, $filter));
985
- break;
986
- case 'contentpages':
987
- wp_send_json($this->get_contentpages($projectId, $from, $to, $filter));
988
- break;
989
- case 'locations':
990
- wp_send_json($this->get_locations($projectId, $from, $to, $filter));
991
- break;
992
- case 'bottomstats':
993
- wp_send_json($this->get_bottomstats($projectId, $from, $to, $filter));
994
- break;
995
- case 'trafficchannels':
996
- wp_send_json($this->get_trafficchannels($projectId, $from, $to, $filter));
997
- break;
998
- case 'medium':
999
- wp_send_json($this->get_trafficdetails($projectId, $from, $to, 'medium', $filter));
1000
- break;
1001
- case 'visitorType':
1002
- wp_send_json($this->get_trafficdetails($projectId, $from, $to, 'visitorType', $filter));
1003
- break;
1004
- case 'socialNetwork':
1005
- wp_send_json($this->get_trafficdetails($projectId, $from, $to, 'socialNetwork', $filter));
1006
- break;
1007
- case 'source':
1008
- wp_send_json($this->get_trafficdetails($projectId, $from, $to, 'source', $filter));
1009
- break;
1010
- case 'searches':
1011
- wp_send_json($this->get_searches($projectId, $from, $to, $filter));
1012
- break;
1013
- case 'realtime':
1014
- wp_send_json($this->get_realtime($projectId));
1015
- break;
1016
- default:
1017
- wp_send_json($this->get_mainreport($projectId, $from, $to, $query, $filter));
1018
- break;
1019
- }
1020
- }
1021
- }
1022
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
+
13
+ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
14
+
15
+ final class GADWP_GAPI_Controller {
16
+
17
+ public $client;
18
+
19
+ public $service;
20
+
21
+ public $timeshift;
22
+
23
+ public $error_timeout;
24
+
25
+ private $managequota;
26
+
27
+ private $gadwp;
28
+
29
+ public function __construct() {
30
+ $this->gadwp = GADWP();
31
+
32
+ include_once ( GADWP_DIR . 'tools/autoload.php' );
33
+ $config = new Google_Config();
34
+ $config->setCacheClass( 'Google_Cache_Null' );
35
+ if ( function_exists( 'curl_version' ) ) {
36
+ $curlversion = curl_version();
37
+ if ( isset( $curlversion['version'] ) && ( version_compare( PHP_VERSION, '5.3.0' ) >= 0 ) && version_compare( $curlversion['version'], '7.10.8' ) >= 0 && defined( 'GADWP_IP_VERSION' ) && GADWP_IP_VERSION ) {
38
+ $config->setClassConfig( 'Google_IO_Curl', array( 'options' => array( CURLOPT_IPRESOLVE => GADWP_IP_VERSION ) ) ); // Force CURL_IPRESOLVE_V4 or CURL_IPRESOLVE_V6
39
+ }
40
+ }
41
+ $this->client = new Google_Client( $config );
42
+ $this->client->setScopes( 'https://www.googleapis.com/auth/analytics.readonly' );
43
+ $this->client->setAccessType( 'offline' );
44
+ $this->client->setApplicationName( 'Google Analytics Dashboard' );
45
+ $this->client->setRedirectUri( 'urn:ietf:wg:oauth:2.0:oob' );
46
+ $this->set_error_timeout();
47
+ $this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id();
48
+ if ( $this->gadwp->config->options['ga_dash_userapi'] ) {
49
+ $this->client->setClientId( $this->gadwp->config->options['ga_dash_clientid'] );
50
+ $this->client->setClientSecret( $this->gadwp->config->options['ga_dash_clientsecret'] );
51
+ $this->client->setDeveloperKey( $this->gadwp->config->options['ga_dash_apikey'] );
52
+ } else {
53
+ $this->client->setClientId( $this->gadwp->config->access[0] );
54
+ $this->client->setClientSecret( $this->gadwp->config->access[1] );
55
+ $this->client->setDeveloperKey( $this->gadwp->config->access[2] );
56
+ }
57
+ $this->service = new Google_Service_Analytics( $this->client );
58
+ if ( $this->gadwp->config->options['ga_dash_token'] ) {
59
+ $token = $this->gadwp->config->options['ga_dash_token'];
60
+ $token = $this->refresh_token();
61
+ if ( $token ) {
62
+ $this->client->setAccessToken( $token );
63
+ }
64
+ }
65
+ }
66
+
67
+ private function set_error_timeout() {
68
+ $midnight = strtotime( "tomorrow 00:00:00" ); // UTC midnight
69
+ $midnight = $midnight + 8 * 3600; // UTC 8 AM
70
+ $this->error_timeout = $midnight - time();
71
+ return;
72
+ }
73
+
74
+ /**
75
+ * Handles errors returned by GAPI and allows exponential backoff
76
+ *
77
+ * @return boolean
78
+ */
79
+ public function gapi_errors_handler() {
80
+ $errors = get_transient( 'ga_dash_gapi_errors' );
81
+ if ( $errors === false || ! isset( $errors[0] ) ) { // invalid error
82
+ return false;
83
+ }
84
+ if ( isset( $errors[1][0]['reason'] ) && ( $errors[1][0]['reason'] == 'invalidCredentials' || $errors[1][0]['reason'] == 'authError' || $errors[1][0]['reason'] == 'insufficientPermissions' || $errors[1][0]['reason'] == 'required' || $errors[1][0]['reason'] == 'keyExpired' ) ) {
85
+ $this->reset_token( false );
86
+ return true;
87
+ }
88
+ if ( isset( $errors[1][0]['reason'] ) && ( $errors[1][0]['reason'] == 'userRateLimitExceeded' || $errors[1][0]['reason'] == 'quotaExceeded' ) ) { // allow
89
+ // retry
90
+ return false;
91
+ }
92
+ if ( $errors[0] == 400 || $errors[0] == 401 || $errors[0] == 403 ) {
93
+ return true;
94
+ }
95
+ return false;
96
+ }
97
+
98
+ /**
99
+ * Calculates proper timeouts for each GAPI query
100
+ *
101
+ * @param
102
+ * $daily
103
+ * @return number
104
+ */
105
+ public function get_timeouts( $daily ) {
106
+ $local_time = time() + $this->timeshift;
107
+ if ( $daily ) {
108
+ $nextday = explode( '-', date( 'n-j-Y', strtotime( ' +1 day', $local_time ) ) );
109
+ $midnight = mktime( 0, 0, 0, $nextday[0], $nextday[1], $nextday[2] );
110
+ return $midnight - $local_time;
111
+ } else {
112
+ $nexthour = explode( '-', date( 'H-n-j-Y', strtotime( ' +1 hour', $local_time ) ) );
113
+ $newhour = mktime( $nexthour[0], 0, 0, $nexthour[1], $nexthour[2], $nexthour[3] );
114
+ return $newhour - $local_time;
115
+ }
116
+ }
117
+
118
+ public function token_request() {
119
+ $authUrl = $this->client->createAuthUrl();
120
+ ?>
 
 
 
 
 
 
 
 
 
121
  <form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
122
  <table class="options">
123
  <tr>
138
  </table>
139
  </form>
140
  <?php
141
+ }
142
+
143
+ /**
144
+ * Retrives all Google Analytics Views with details
145
+ *
146
+ * @return array
147
+ */
148
+ public function refresh_profiles() {
149
+ try {
150
+
151
+ $ga_dash_profile_list = array();
152
+ $startindex = 1;
153
+ $totalresults = 65535; // use something big
154
+
155
+ while ( $startindex < $totalresults ) {
156
+
157
+ $profiles = $this->service->management_profiles->listManagementProfiles( '~all', '~all', array( 'start-index' => $startindex ) );
158
+
159
+ $items = $profiles->getItems();
160
+
161
+ $totalresults = $profiles->getTotalResults();
162
+
163
+ if ( $totalresults > 0 ) {
164
+
165
+ foreach ( $items as $profile ) {
166
+ $timetz = new DateTimeZone( $profile->getTimezone() );
167
+ $localtime = new DateTime( 'now', $timetz );
168
+ $timeshift = strtotime( $localtime->format( 'Y-m-d H:i:s' ) ) - time();
169
+ $ga_dash_profile_list[] = array( $profile->getName(), $profile->getId(), $profile->getwebPropertyId(), $profile->getwebsiteUrl(), $timeshift, $profile->getTimezone() );
170
+
171
+ $startindex++;
172
+ }
173
+ }
174
+ }
175
+
176
+ if ( empty( $ga_dash_profile_list ) ) {
177
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': No properties were found in this account!', $this->error_timeout );
178
+ } else {
179
+ set_transient( 'ga_dash_lasterror', 'None' );
180
+ }
181
+
182
+ return $ga_dash_profile_list;
183
+ } catch ( Google_IO_Exception $e ) {
184
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
185
+ return $ga_dash_profile_list;
186
+ } catch ( Google_Service_Exception $e ) {
187
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
188
+ set_transient( 'ga_dash_gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
189
+ } catch ( Exception $e ) {
190
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
191
+ return $ga_dash_profile_list;
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Handles the token refresh process
197
+ *
198
+ * @return token|boolean
199
+ */
200
+ private function refresh_token() {
201
+ try {
202
+ if ( is_multisite() && $this->gadwp->config->options['ga_dash_network'] ) {
203
+ $transient = get_site_transient( "ga_dash_refresh_token" );
204
+ } else {
205
+ $transient = get_transient( "ga_dash_refresh_token" );
206
+ }
207
+ if ( $transient === false ) {
208
+ if ( ! $this->gadwp->config->options['ga_dash_refresh_token'] ) {
209
+ $google_token = json_decode( $this->gadwp->config->options['ga_dash_token'] );
210
+ $this->gadwp->config->options['ga_dash_refresh_token'] = $google_token->refresh_token;
211
+ $this->client->refreshToken( $google_token->refresh_token );
212
+ } else {
213
+ $this->client->refreshToken( $this->gadwp->config->options['ga_dash_refresh_token'] );
214
+ }
215
+ $token = $this->client->getAccessToken();
216
+ $google_token = json_decode( $token );
217
+ $this->gadwp->config->options['ga_dash_token'] = $token;
218
+ if ( is_multisite() && $this->gadwp->config->options['ga_dash_network'] ) {
219
+ set_site_transient( "ga_dash_refresh_token", $token, $google_token->expires_in );
220
+ $this->gadwp->config->set_plugin_options( true );
221
+ } else {
222
+ set_transient( "ga_dash_refresh_token", $token, $google_token->expires_in );
223
+ $this->gadwp->config->set_plugin_options();
224
+ }
225
+ return $token;
226
+ } else {
227
+ return $transient;
228
+ }
229
+ } catch ( Google_IO_Exception $e ) {
230
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
231
+ return false;
232
+ } catch ( Google_Service_Exception $e ) {
233
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
234
+ set_transient( 'ga_dash_gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
235
+ return $e->getCode();
236
+ } catch ( Exception $e ) {
237
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
238
+ return false;
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Handles the token reset process
244
+ *
245
+ * @param
246
+ * $all
247
+ */
248
+ public function reset_token( $all = true ) {
249
+ if ( is_multisite() && $this->gadwp->config->options['ga_dash_network'] ) {
250
+ delete_site_transient( 'ga_dash_refresh_token' );
251
+ } else {
252
+ delete_transient( 'ga_dash_refresh_token' );
253
+ }
254
+ $this->gadwp->config->options['ga_dash_token'] = "";
255
+ $this->gadwp->config->options['ga_dash_refresh_token'] = "";
256
+ if ( $all ) {
257
+ $this->gadwp->config->options['ga_dash_tableid'] = "";
258
+ $this->gadwp->config->options['ga_dash_tableid_jail'] = "";
259
+ $this->gadwp->config->options['ga_dash_profile_list'] = array();
260
+ try {
261
+ $this->client->revokeToken();
262
+ } catch ( Exception $e ) {
263
+ if ( is_multisite() && $this->gadwp->config->options['ga_dash_network'] ) {
264
+ $this->gadwp->config->set_plugin_options( true );
265
+ } else {
266
+ $this->gadwp->config->set_plugin_options();
267
+ }
268
+ }
269
+ }
270
+ if ( is_multisite() && $this->gadwp->config->options['ga_dash_network'] ) {
271
+ $this->gadwp->config->set_plugin_options( true );
272
+ } else {
273
+ $this->gadwp->config->set_plugin_options();
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Get and cache Core Reports
279
+ *
280
+ * @todo implement retries with exponential backoff
281
+ *
282
+ * @param
283
+ * $projecId
284
+ * @param
285
+ * $from
286
+ * @param
287
+ * $to
288
+ * @param
289
+ * $metrics
290
+ * @param
291
+ * $options
292
+ * @param
293
+ * $serial
294
+ * @return int|Google_Service_Analytics_GaData
295
+ */
296
+ private function handle_corereports( $projectId, $from, $to, $metrics, $options, $serial ) {
297
+ try {
298
+ if ( $from == "today" ) {
299
+ $timeouts = 0;
300
+ } else {
301
+ $timeouts = 1;
302
+ }
303
+ $transient = get_transient( $serial );
304
+ if ( $transient === false ) {
305
+ if ( $this->gapi_errors_handler() ) {
306
+ return - 23;
307
+ }
308
+ $data = $this->service->data_ga->get( 'ga:' . $projectId, $from, $to, $metrics, $options );
309
+ set_transient( $serial, $data, $this->get_timeouts( $timeouts ) );
310
+ } else {
311
+ $data = $transient;
312
+ }
313
+ } catch ( Google_Service_Exception $e ) {
314
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
315
+ set_transient( 'ga_dash_gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
316
+ return $e->getCode();
317
+ } catch ( Exception $e ) {
318
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
319
+ return $e->getCode();
320
+ }
321
+ if ( $data->getRows() > 0 ) {
322
+ return $data;
323
+ } else {
324
+ return - 21;
325
+ }
326
+ }
327
+
328
+ /**
329
+ * Generates serials for transients
330
+ *
331
+ * @param
332
+ * $serial
333
+ * @return string
334
+ */
335
+ public function get_serial( $serial ) {
336
+ return sprintf( "%u", crc32( $serial ) );
337
+ }
338
+
339
+ /**
340
+ * Analytics data for backend reports (Admin Widget main report)
341
+ *
342
+ * @param
343
+ * $projectId
344
+ * @param
345
+ * $from
346
+ * @param
347
+ * $to
348
+ * @param
349
+ * $query
350
+ * @return array|int
351
+ */
352
+ public function get_mainreport( $projectId, $from, $to, $query, $filter = '' ) {
353
+ switch ( $query ) {
354
+ case 'users' :
355
+ $title = __( "Users", 'ga-dash' );
356
+ break;
357
+ case 'pageviews' :
358
+ $title = __( "Page Views", 'ga-dash' );
359
+ break;
360
+ case 'visitBounceRate' :
361
+ $title = __( "Bounce Rate", 'ga-dash' );
362
+ break;
363
+ case 'organicSearches' :
364
+ $title = __( "Organic Searches", 'ga-dash' );
365
+ break;
366
+ case 'uniquePageviews' :
367
+ $title = __( "Unique Page Views", 'ga-dash' );
368
+ break;
369
+ default :
370
+ $title = __( "Sessions", 'ga-dash' );
371
+ }
372
+ $metrics = 'ga:' . $query;
373
+ if ( $from == "today" || $from == "yesterday" ) {
374
+ $dimensions = 'ga:hour';
375
+ $dayorhour = __( "Hour", 'ga-dash' );
376
+ } else {
377
+ $dimensions = 'ga:date,ga:dayOfWeekName';
378
+ $dayorhour = __( "Date", 'ga-dash' );
379
+ }
380
+ $options = array( 'dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId );
381
+ if ( $filter ) {
382
+ $options['filters'] = 'ga:pagePath==' . $filter;
383
+ }
384
+ $serial = 'gadash_qr2_' . $this->get_serial( $projectId . $from . $metrics . $filter );
385
+ $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
386
+ if ( is_numeric( $data ) ) {
387
+ return $data;
388
+ }
389
+ $gadwp_data = array( array( $dayorhour, $title ) );
390
+ if ( $from == "today" || $from == "yesterday" ) {
391
+ foreach ( $data->getRows() as $row ) {
392
+ $gadwp_data[] = array( (int) $row[0] . ':00', round( $row[1], 2 ) );
393
+ }
394
+ } else {
395
+ foreach ( $data->getRows() as $row ) {
396
+ $gadwp_data[] = array( esc_html( ucfirst( __( $row[1] ) ) ) . ',' . esc_html( substr_replace( substr_replace( $row[0], "-", 4, 0 ), "-", 7, 0 ) ), round( $row[2], 2 ) );
397
+ }
398
+ }
399
+ return $gadwp_data;
400
+ }
401
+
402
+ /**
403
+ * Analytics data for backend reports (bottom stats main report)
404
+ *
405
+ * @param
406
+ * $projectId
407
+ * @param
408
+ * $from
409
+ * @param
410
+ * $to
411
+ * @return array|int
412
+ */
413
+ public function get_bottomstats( $projectId, $from, $to, $filter = '' ) {
414
+ $options = array( 'dimensions' => null, 'quotaUser' => $this->managequota . 'p' . $projectId );
415
+ if ( $filter ) {
416
+ $options['filters'] = 'ga:pagePath==' . $filter;
417
+ $metrics = 'ga:uniquePageviews,ga:users,ga:pageviews,ga:BounceRate,ga:organicSearches,ga:pageviewsPerSession';
418
+ } else {
419
+ $metrics = 'ga:sessions,ga:users,ga:pageviews,ga:BounceRate,ga:organicSearches,ga:pageviewsPerSession';
420
+ }
421
+ $serial = 'gadash_qr3_' . $this->get_serial( $projectId . $from . $filter );
422
+ $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
423
+ if ( is_numeric( $data ) ) {
424
+ if ( $data == - 21 ) {
425
+ return array_fill( 0, 6, 0 );
426
+ } else {
427
+ return $data;
428
+ }
429
+ }
430
+ $gadwp_data = array();
431
+ foreach ( $data->getRows() as $row ) {
432
+ $gadwp_data = array_map( 'floatval', $row );
433
+ }
434
+ return $gadwp_data;
435
+ }
436
+
437
+ /**
438
+ * Analytics data for backend reports (contentpages)
439
+ *
440
+ * @param
441
+ * $projectId
442
+ * @param
443
+ * $from
444
+ * @param
445
+ * $to
446
+ * @return array|int
447
+ */
448
+ public function get_contentpages( $projectId, $from, $to, $filter = '' ) {
449
+ $metrics = 'ga:pageviews';
450
+ $dimensions = 'ga:pageTitle';
451
+ $options = array( 'dimensions' => $dimensions, 'sort' => '-ga:pageviews', 'quotaUser' => $this->managequota . 'p' . $projectId );
452
+ if ( $filter ) {
453
+ $options['filters'] = 'ga:pagePath==' . $filter;
454
+ }
455
+ $serial = 'gadash_qr4_' . $this->get_serial( $projectId . $from . $filter );
456
+ $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
457
+ if ( is_numeric( $data ) ) {
458
+ return $data;
459
+ }
460
+ $gadwp_data = array( array( __( "Pages", 'ga-dash' ), __( "Views", 'ga-dash' ) ) );
461
+ foreach ( $data->getRows() as $row ) {
462
+ $gadwp_data[] = array( esc_html( $row[0] ), (int) $row[1] );
463
+ }
464
+ return $gadwp_data;
465
+ }
466
+
467
+ /**
468
+ * Analytics data for backend reports (referrers)
469
+ *
470
+ * @param
471
+ * $projectId
472
+ * @param
473
+ * $from
474
+ * @param
475
+ * $to
476
+ * @return array|int
477
+ */
478
+ public function get_referrers( $projectId, $from, $to, $filter = '' ) {
479
+ $metrics = 'ga:sessions';
480
+ $dimensions = 'ga:source';
481
+ $options = array( 'dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId );
482
+ if ( $filter ) {
483
+ $options['filters'] = 'ga:medium==referral;ga:pagePath==' . $filter;
484
+ } else {
485
+ $options['filters'] = 'ga:medium==referral';
486
+ }
487
+ $serial = 'gadash_qr5_' . $this->get_serial( $projectId . $from . $filter );
488
+ $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
489
+ if ( is_numeric( $data ) ) {
490
+ return $data;
491
+ }
492
+ $gadwp_data = array( array( __( "Referrers", 'ga-dash' ), __( "Sessions", 'ga-dash' ) ) );
493
+ foreach ( $data->getRows() as $row ) {
494
+ $gadwp_data[] = array( esc_html( $row[0] ), (int) $row[1] );
495
+ }
496
+ return $gadwp_data;
497
+ }
498
+
499
+ /**
500
+ * Analytics data for backend reports (searches)
501
+ *
502
+ * @param
503
+ * $projectId
504
+ * @param
505
+ * $from
506
+ * @param
507
+ * $to
508
+ * @return array|int
509
+ */
510
+ public function get_searches( $projectId, $from, $to, $filter = '' ) {
511
+ $metrics = 'ga:sessions';
512
+ $dimensions = 'ga:keyword';
513
+ $options = array( 'dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId );
514
+ if ( $filter ) {
515
+ $options['filters'] = 'ga:keyword!=(not set);ga:pagePath==' . $filter;
516
+ } else {
517
+ $options['filters'] = 'ga:keyword!=(not set)';
518
+ }
519
+ $serial = 'gadash_qr6_' . $this->get_serial( $projectId . $from . $filter );
520
+ $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
521
+ if ( is_numeric( $data ) ) {
522
+ return $data;
523
+ }
524
+
525
+ $gadwp_data = array( array( __( "Searches", 'ga-dash' ), __( "Sessions", 'ga-dash' ) ) );
526
+ foreach ( $data->getRows() as $row ) {
527
+ $gadwp_data[] = array( esc_html( $row[0] ), (int) $row[1] );
528
+ }
529
+ return $gadwp_data;
530
+ }
531
+
532
+ /**
533
+ * Analytics data for backend reports (location reports)
534
+ *
535
+ * @param
536
+ * $projectId
537
+ * @param
538
+ * $from
539
+ * @param
540
+ * $to
541
+ * @return array|int
542
+ */
543
+ public function get_locations( $projectId, $from, $to, $filter = '' ) {
544
+ $metrics = 'ga:sessions';
545
+ $options = "";
546
+ $title = __( "Countries", 'ga-dash' );
547
+ $serial = 'gadash_qr7_' . $this->get_serial( $projectId . $from . $filter );
548
+ $dimensions = 'ga:country';
549
+ $local_filter = '';
550
+ if ( $this->gadwp->config->options['ga_target_geomap'] ) {
551
+ $dimensions = 'ga:city, ga:region';
552
+
553
+ $country_codes = GADWP_Tools::get_countrycodes();
554
+ if ( isset( $country_codes[$this->gadwp->config->options['ga_target_geomap']] ) ) {
555
+ $local_filter = 'ga:country==' . ( $country_codes[$this->gadwp->config->options['ga_target_geomap']] );
556
+ $title = __( "Cities from", 'ga-dash' ) . ' ' . __( $country_codes[$this->gadwp->config->options['ga_target_geomap']] );
557
+ $serial = 'gadash_qr7_' . $this->get_serial( $projectId . $from . $this->gadwp->config->options['ga_target_geomap'] . $filter );
558
+ }
559
+ }
560
+ $options = array( 'dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId );
561
+ if ( $filter ) {
562
+ $options['filters'] = 'ga:pagePath==' . $filter;
563
+ if ( $local_filter ) {
564
+ $options['filters'] .= ';' . $local_filter;
565
+ }
566
+ } else {
567
+ if ( $local_filter ) {
568
+ $options['filters'] = $local_filter;
569
+ }
570
+ }
571
+ $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
572
+ if ( is_numeric( $data ) ) {
573
+ return $data;
574
+ }
575
+ $gadwp_data = array( array( $title, __( "Sessions", 'ga-dash' ) ) );
576
+ foreach ( $data->getRows() as $row ) {
577
+ if ( isset( $row[2] ) ) {
578
+ $gadwp_data[] = array( esc_html( $row[0] ) . ', ' . esc_html( $row[1] ), (int) $row[2] );
579
+ } else {
580
+ $gadwp_data[] = array( esc_html( $row[0] ), (int) $row[1] );
581
+ }
582
+ }
583
+ return $gadwp_data;
584
+ }
585
+
586
+ /**
587
+ * Analytics data for backend reports (traffic channels)
588
+ *
589
+ * @param
590
+ * $projectId
591
+ * @param
592
+ * $from
593
+ * @param
594
+ * $to
595
+ * @return array|int
596
+ */
597
+ public function get_trafficchannels( $projectId, $from, $to, $filter = '' ) {
598
+ $metrics = 'ga:sessions';
599
+ $dimensions = 'ga:channelGrouping';
600
+ $options = array( 'dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId );
601
+ if ( $filter ) {
602
+ $options['filters'] = 'ga:pagePath==' . $filter;
603
+ }
604
+ $serial = 'gadash_qr8_' . $this->get_serial( $projectId . $from . $filter );
605
+ $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
606
+ if ( is_numeric( $data ) ) {
607
+ return $data;
608
+ }
609
+ $title = __( "Channels", 'ga-dash' );
610
+ $gadwp_data = array( array( '<div style="color:black; font-size:1.1em">' . $title . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>', "" ) );
611
+ foreach ( $data->getRows() as $row ) {
612
+ $shrink = explode( " ", $row[0] );
613
+ $gadwp_data[] = array( '<div style="color:black; font-size:1.1em">' . esc_html( $shrink[0] ) . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $row[1] . '</div>', '<div style="color:black; font-size:1.1em">' . $title . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>' );
614
+ }
615
+ return $gadwp_data;
616
+ }
617
+
618
+ /**
619
+ * Analytics data for backend reports (traffic mediums, type, serach engines, social networks)
620
+ *
621
+ * @param
622
+ * $projectId
623
+ * @param
624
+ * $from
625
+ * @param
626
+ * $to
627
+ * @param
628
+ * $query
629
+ * @return array|int
630
+ */
631
+ public function get_trafficdetails( $projectId, $from, $to, $query, $filter = '' ) {
632
+ $metrics = 'ga:sessions';
633
+ $dimensions = 'ga:' . $query;
634
+
635
+ if ( $query == 'source' ) {
636
+ $options = array( 'dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId );
637
+ if ( $filter ) {
638
+ $options['filters'] = 'ga:medium==organic;ga:keyword!=(not set);ga:pagePath==' . $filter;
639
+ } else {
640
+ $options['filters'] = 'ga:medium==organic;ga:keyword!=(not set)';
641
+ }
642
+ } else {
643
+ $options = array( 'dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId );
644
+ if ( $filter ) {
645
+ $options['filters'] = 'ga:' . $query . '!=(not set);ga:pagePath==' . $filter;
646
+ } else {
647
+ $options['filters'] = 'ga:' . $query . '!=(not set)';
648
+ }
649
+ }
650
+ $serial = 'gadash_qr10_' . $this->get_serial( $projectId . $from . $query . $filter );
651
+ $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
652
+ if ( is_numeric( $data ) ) {
653
+ return $data;
654
+ }
655
+ $gadwp_data = array( array( __( "Type", 'ga-dash' ), __( "Sessions", 'ga-dash' ) ) );
656
+ foreach ( $data->getRows() as $row ) {
657
+ $gadwp_data[] = array( str_replace( "(none)", "direct", esc_html( $row[0] ) ), (int) $row[1] );
658
+ }
659
+ return $gadwp_data;
660
+ }
661
+
662
+ /**
663
+ * Analytics data for frontend Widget (chart data and totals)
664
+ *
665
+ * @param
666
+ * $projectId
667
+ * @param
668
+ * $period
669
+ * @param
670
+ * $anonim
671
+ * @return array|int
672
+ */
673
+ public function frontend_widget_stats( $projectId, $from, $anonim ) {
674
+ $content = '';
675
+ $to = 'yesterday';
676
+ $metrics = 'ga:sessions';
677
+ $dimensions = 'ga:date,ga:dayOfWeekName';
678
+ $options = array( 'dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId );
679
+ $serial = 'gadash_qr2_' . $this->get_serial( $projectId . $from . $metrics );
680
+ $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
681
+ if ( is_numeric( $data ) ) {
682
+ return $data;
683
+ }
684
+ $gadwp_data = array( array( __( "Date", 'ga-dash' ), __( "Sessions", 'ga-dash' ) . ( $anonim ? "' " . __( "trend", 'ga-dash' ) : '' ) ) );
685
+ if ( $anonim ) {
686
+ $max_array = array();
687
+ foreach ( $data->getRows() as $item ) {
688
+ $max_array[] = $item[2];
689
+ }
690
+ $max = max( $max_array ) ? max( $max_array ) : 1;
691
+ }
692
+ foreach ( $data->getRows() as $row ) {
693
+ $gadwp_data[] = array( ucfirst( esc_html( ( __( $row[1] ) ) ) ) . ', ' . esc_html( substr_replace( substr_replace( $row[0], "-", 4, 0 ), "-", 7, 0 ) ), ( $anonim ? round( $row[2] * 100 / $max, 2 ) : (int) $row[2] ) );
694
+ }
695
+ $totals = $data->getTotalsForAllResults();
696
+ return array( $gadwp_data, $anonim ? 0 : $totals['ga:sessions'] );
697
+ }
698
+
699
+ /**
700
+ * Analytics data for backend reports (Real-Time)
701
+ *
702
+ * @param
703
+ * $projectId
704
+ * @return array|int
705
+ */
706
+ public function get_realtime( $projectId ) {
707
+ $metrics = 'rt:activeUsers';
708
+ $dimensions = 'rt:pagePath,rt:source,rt:keyword,rt:trafficType,rt:visitorType,rt:pageTitle';
709
+ try {
710
+ $serial = 'gadash_realtimecache_' . $this->get_serial( $projectId );
711
+ $transient = get_transient( $serial );
712
+ if ( $transient === false ) {
713
+ if ( $this->gapi_errors_handler() ) {
714
+ return - 23;
715
+ }
716
+ $data = $this->service->data_realtime->get( 'ga:' . $projectId, $metrics, array( 'dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId ) );
717
+ set_transient( $serial, $data, 55 );
718
+ } else {
719
+ $data = $transient;
720
+ }
721
+ } catch ( Google_Service_Exception $e ) {
722
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
723
+ set_transient( 'ga_dash_gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
724
+ return $e->getCode();
725
+ } catch ( Exception $e ) {
726
+ set_transient( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
727
+ return $e->getCode();
728
+ }
729
+ if ( $data->getRows() < 1 ) {
730
+ return - 21;
731
+ }
732
+ $i = 0;
733
+ $gadwp_data = $data;
734
+ foreach ( $data->getRows() as $row ) {
735
+ $gadwp_data->rows[$i] = array_map( 'esc_html', $row );
736
+ $i++;
737
+ }
738
+ return $gadwp_data;
739
+ }
740
+
741
+ public function get( $projectId, $query, $from = false, $to = false, $filter = '' ) {
742
+ switch ( $query ) {
743
+ case 'referrers' :
744
+ return $this->get_referrers( $projectId, $from, $to, $filter );
745
+ break;
746
+ case 'contentpages' :
747
+ return $this->get_contentpages( $projectId, $from, $to, $filter );
748
+ break;
749
+ case 'locations' :
750
+ return $this->get_locations( $projectId, $from, $to, $filter );
751
+ break;
752
+ case 'bottomstats' :
753
+ return $this->get_bottomstats( $projectId, $from, $to, $filter );
754
+ break;
755
+ case 'trafficchannels' :
756
+ return $this->get_trafficchannels( $projectId, $from, $to, $filter );
757
+ break;
758
+ case 'medium' :
759
+ return $this->get_trafficdetails( $projectId, $from, $to, 'medium', $filter );
760
+ break;
761
+ case 'visitorType' :
762
+ return $this->get_trafficdetails( $projectId, $from, $to, 'visitorType', $filter );
763
+ break;
764
+ case 'socialNetwork' :
765
+ return $this->get_trafficdetails( $projectId, $from, $to, 'socialNetwork', $filter );
766
+ break;
767
+ case 'source' :
768
+ return $this->get_trafficdetails( $projectId, $from, $to, 'source', $filter );
769
+ break;
770
+ case 'searches' :
771
+ return $this->get_searches( $projectId, $from, $to, $filter );
772
+ break;
773
+ case 'realtime' :
774
+ return $this->get_realtime( $projectId );
775
+ break;
776
+ default :
777
+ return $this->get_mainreport( $projectId, $from, $to, $query, $filter );
778
+ break;
779
+ }
780
+ }
781
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
782
  }
tools/iso3166.php CHANGED
@@ -7,247 +7,246 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
 
13
  $country_codes = array(
14
- 'AD' => 'Andorra',
15
- 'AE' => 'United Arab Emirates',
16
- 'AF' => 'Afghanistan',
17
- 'AG' => 'Antigua and Barbuda',
18
- 'AI' => 'Anguilla',
19
- 'AL' => 'Albania',
20
- 'AM' => 'Armenia',
21
- 'AN' => 'Netherlands Antilles',
22
- 'AO' => 'Angola',
23
- 'AQ' => 'Antarctica',
24
- 'AR' => 'Argentina',
25
- 'AS' => 'American Samoa',
26
- 'AT' => 'Austria',
27
- 'AU' => 'Australia',
28
- 'AW' => 'Aruba',
29
- 'AZ' => 'Azerbaijan',
30
- 'BA' => 'Bosnia and Herzegovina',
31
- 'BB' => 'Barbados',
32
- 'BD' => 'Bangladesh',
33
- 'BE' => 'Belgium',
34
- 'BF' => 'Burkina Faso',
35
- 'BG' => 'Bulgaria',
36
- 'BH' => 'Bahrain',
37
- 'BI' => 'Burundi',
38
- 'BJ' => 'Benin',
39
- 'BM' => 'Bermuda',
40
- 'BN' => 'Brunei',
41
- 'BO' => 'Bolivia',
42
- 'BR' => 'Brazil',
43
- 'BS' => 'Bahamas',
44
- 'BT' => 'Bhutan',
45
- 'BV' => 'Bouvet Island',
46
- 'BW' => 'Botswana',
47
- 'BY' => 'Belarus',
48
- 'BZ' => 'Belize',
49
- 'CA' => 'Canada',
50
- 'CC' => 'Cocos (Keeling) Islands',
51
- 'CD' => 'Congo, The Democratic Republic of the',
52
- 'CF' => 'Central African Republic',
53
- 'CG' => 'Congo',
54
- 'CH' => 'Switzerland',
55
- 'CI' => 'C�te d?Ivoire',
56
- 'CK' => 'Cook Islands',
57
- 'CL' => 'Chile',
58
- 'CM' => 'Cameroon',
59
- 'CN' => 'China',
60
- 'CO' => 'Colombia',
61
- 'CR' => 'Costa Rica',
62
- 'CU' => 'Cuba',
63
- 'CV' => 'Cape Verde',
64
- 'CX' => 'Christmas Island',
65
- 'CY' => 'Cyprus',
66
- 'CZ' => 'Czech Republic',
67
- 'DE' => 'Germany',
68
- 'DJ' => 'Djibouti',
69
- 'DK' => 'Denmark',
70
- 'DM' => 'Dominica',
71
- 'DO' => 'Dominican Republic',
72
- 'DZ' => 'Algeria',
73
- 'EC' => 'Ecuador',
74
- 'EE' => 'Estonia',
75
- 'EG' => 'Egypt',
76
- 'EH' => 'Western Sahara',
77
- 'ER' => 'Eritrea',
78
- 'ES' => 'Spain',
79
- 'ET' => 'Ethiopia',
80
- 'FI' => 'Finland',
81
- 'FJ' => 'Fiji Islands',
82
- 'FK' => 'Falkland Islands',
83
- 'FM' => 'Micronesia, Federated States of',
84
- 'FO' => 'Faroe Islands',
85
- 'FR' => 'France',
86
- 'GA' => 'Gabon',
87
- 'GB' => 'United Kingdom',
88
- 'GD' => 'Grenada',
89
- 'GE' => 'Georgia',
90
- 'GF' => 'French Guiana',
91
- 'GH' => 'Ghana',
92
- 'GI' => 'Gibraltar',
93
- 'GL' => 'Greenland',
94
- 'GM' => 'Gambia',
95
- 'GN' => 'Guinea',
96
- 'GP' => 'Guadeloupe',
97
- 'GQ' => 'Equatorial Guinea',
98
- 'GR' => 'Greece',
99
- 'GS' => 'South Georgia and the South Sandwich Islands',
100
- 'GT' => 'Guatemala',
101
- 'GU' => 'Guam',
102
- 'GW' => 'Guinea-Bissau',
103
- 'GY' => 'Guyana',
104
- 'HK' => 'Hong Kong',
105
- 'HM' => 'Heard Island and McDonald Islands',
106
- 'HN' => 'Honduras',
107
- 'HR' => 'Croatia',
108
- 'HT' => 'Haiti',
109
- 'HU' => 'Hungary',
110
- 'ID' => 'Indonesia',
111
- 'IE' => 'Ireland',
112
- 'IL' => 'Israel',
113
- 'IN' => 'India',
114
- 'IO' => 'British Indian Ocean Territory',
115
- 'IQ' => 'Iraq',
116
- 'IR' => 'Iran',
117
- 'IS' => 'Iceland',
118
- 'IT' => 'Italy',
119
- 'JM' => 'Jamaica',
120
- 'JO' => 'Jordan',
121
- 'JP' => 'Japan',
122
- 'KE' => 'Kenya',
123
- 'KG' => 'Kyrgyzstan',
124
- 'KH' => 'Cambodia',
125
- 'KI' => 'Kiribati',
126
- 'KM' => 'Comoros',
127
- 'KN' => 'Saint Kitts and Nevis',
128
- 'KP' => 'North Korea',
129
- 'KR' => 'South Korea',
130
- 'KW' => 'Kuwait',
131
- 'KY' => 'Cayman Islands',
132
- 'KZ' => 'Kazakstan',
133
- 'LA' => 'Laos',
134
- 'LB' => 'Lebanon',
135
- 'LC' => 'Saint Lucia',
136
- 'LI' => 'Liechtenstein',
137
- 'LK' => 'Sri Lanka',
138
- 'LR' => 'Liberia',
139
- 'LS' => 'Lesotho',
140
- 'LT' => 'Lithuania',
141
- 'LU' => 'Luxembourg',
142
- 'LV' => 'Latvia',
143
- 'LY' => 'Libyan Arab Jamahiriya',
144
- 'MA' => 'Morocco',
145
- 'MC' => 'Monaco',
146
- 'MD' => 'Moldova',
147
- 'MG' => 'Madagascar',
148
- 'MH' => 'Marshall Islands',
149
- 'MK' => 'Macedonia',
150
- 'ML' => 'Mali',
151
- 'MM' => 'Myanmar',
152
- 'MN' => 'Mongolia',
153
- 'MO' => 'Macao',
154
- 'MP' => 'Northern Mariana Islands',
155
- 'MQ' => 'Martinique',
156
- 'MR' => 'Mauritania',
157
- 'MS' => 'Montserrat',
158
- 'MT' => 'Malta',
159
- 'MU' => 'Mauritius',
160
- 'MV' => 'Maldives',
161
- 'MW' => 'Malawi',
162
- 'MX' => 'Mexico',
163
- 'MY' => 'Malaysia',
164
- 'MZ' => 'Mozambique',
165
- 'NA' => 'Namibia',
166
- 'NC' => 'New Caledonia',
167
- 'NE' => 'Niger',
168
- 'NF' => 'Norfolk Island',
169
- 'NG' => 'Nigeria',
170
- 'NI' => 'Nicaragua',
171
- 'NL' => 'Netherlands',
172
- 'NO' => 'Norway',
173
- 'NP' => 'Nepal',
174
- 'NR' => 'Nauru',
175
- 'NU' => 'Niue',
176
- 'NZ' => 'New Zealand',
177
- 'OM' => 'Oman',
178
- 'PA' => 'Panama',
179
- 'PE' => 'Peru',
180
- 'PF' => 'French Polynesia',
181
- 'PG' => 'Papua New Guinea',
182
- 'PH' => 'Philippines',
183
- 'PK' => 'Pakistan',
184
- 'PL' => 'Poland',
185
- 'PM' => 'Saint Pierre and Miquelon',
186
- 'PN' => 'Pitcairn',
187
- 'PR' => 'Puerto Rico',
188
- 'PS' => 'Palestine',
189
- 'PT' => 'Portugal',
190
- 'PW' => 'Palau',
191
- 'PY' => 'Paraguay',
192
- 'QA' => 'Qatar',
193
- 'RE' => 'Reunion',
194
- 'RO' => 'Romania',
195
- 'RU' => 'Russia',
196
- 'RW' => 'Rwanda',
197
- 'SA' => 'Saudi Arabia',
198
- 'SB' => 'Solomon Islands',
199
- 'SC' => 'Seychelles',
200
- 'SD' => 'Sudan',
201
- 'SE' => 'Sweden',
202
- 'SG' => 'Singapore',
203
- 'SH' => 'Saint Helena',
204
- 'SI' => 'Slovenia',
205
- 'SJ' => 'Svalbard and Jan Mayen',
206
- 'SK' => 'Slovakia',
207
- 'SL' => 'Sierra Leone',
208
- 'SM' => 'San Marino',
209
- 'SN' => 'Senegal',
210
- 'SO' => 'Somalia',
211
- 'SR' => 'Suriname',
212
- 'ST' => 'Sao Tome and Principe',
213
- 'SV' => 'El Salvador',
214
- 'SY' => 'Syria',
215
- 'SZ' => 'Swaziland',
216
- 'TC' => 'Turks and Caicos Islands',
217
- 'TD' => 'Chad',
218
- 'TF' => 'French Southern territories',
219
- 'TG' => 'Togo',
220
- 'TH' => 'Thailand',
221
- 'TJ' => 'Tajikistan',
222
- 'TK' => 'Tokelau',
223
- 'TM' => 'Turkmenistan',
224
- 'TN' => 'Tunisia',
225
- 'TO' => 'Tonga',
226
- 'TP' => 'East Timor',
227
- 'TR' => 'Turkey',
228
- 'TT' => 'Trinidad and Tobago',
229
- 'TV' => 'Tuvalu',
230
- 'TW' => 'Taiwan',
231
- 'TZ' => 'Tanzania',
232
- 'UA' => 'Ukraine',
233
- 'UG' => 'Uganda',
234
- 'UM' => 'United States Minor Outlying Islands',
235
- 'US' => 'United States',
236
- 'UY' => 'Uruguay',
237
- 'UZ' => 'Uzbekistan',
238
- 'VA' => 'Holy See (Vatican City State)',
239
- 'VC' => 'Saint Vincent and the Grenadines',
240
- 'VE' => 'Venezuela',
241
- 'VG' => 'Virgin Islands, British',
242
- 'VI' => 'Virgin Islands, U.S.',
243
- 'VN' => 'Vietnam',
244
- 'VU' => 'Vanuatu',
245
- 'WF' => 'Wallis and Futuna',
246
- 'WS' => 'Samoa',
247
- 'YE' => 'Yemen',
248
- 'YT' => 'Mayotte',
249
- 'YU' => 'Yugoslavia',
250
- 'ZA' => 'South Africa',
251
- 'ZM' => 'Zambia',
252
- 'ZW' => 'Zimbabwe'
253
- );
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
 
13
  $country_codes = array(
14
+ 'AD' => 'Andorra',
15
+ 'AE' => 'United Arab Emirates',
16
+ 'AF' => 'Afghanistan',
17
+ 'AG' => 'Antigua and Barbuda',
18
+ 'AI' => 'Anguilla',
19
+ 'AL' => 'Albania',
20
+ 'AM' => 'Armenia',
21
+ 'AN' => 'Netherlands Antilles',
22
+ 'AO' => 'Angola',
23
+ 'AQ' => 'Antarctica',
24
+ 'AR' => 'Argentina',
25
+ 'AS' => 'American Samoa',
26
+ 'AT' => 'Austria',
27
+ 'AU' => 'Australia',
28
+ 'AW' => 'Aruba',
29
+ 'AZ' => 'Azerbaijan',
30
+ 'BA' => 'Bosnia and Herzegovina',
31
+ 'BB' => 'Barbados',
32
+ 'BD' => 'Bangladesh',
33
+ 'BE' => 'Belgium',
34
+ 'BF' => 'Burkina Faso',
35
+ 'BG' => 'Bulgaria',
36
+ 'BH' => 'Bahrain',
37
+ 'BI' => 'Burundi',
38
+ 'BJ' => 'Benin',
39
+ 'BM' => 'Bermuda',
40
+ 'BN' => 'Brunei',
41
+ 'BO' => 'Bolivia',
42
+ 'BR' => 'Brazil',
43
+ 'BS' => 'Bahamas',
44
+ 'BT' => 'Bhutan',
45
+ 'BV' => 'Bouvet Island',
46
+ 'BW' => 'Botswana',
47
+ 'BY' => 'Belarus',
48
+ 'BZ' => 'Belize',
49
+ 'CA' => 'Canada',
50
+ 'CC' => 'Cocos (Keeling) Islands',
51
+ 'CD' => 'Congo, The Democratic Republic of the',
52
+ 'CF' => 'Central African Republic',
53
+ 'CG' => 'Congo',
54
+ 'CH' => 'Switzerland',
55
+ 'CI' => 'C�te d?Ivoire',
56
+ 'CK' => 'Cook Islands',
57
+ 'CL' => 'Chile',
58
+ 'CM' => 'Cameroon',
59
+ 'CN' => 'China',
60
+ 'CO' => 'Colombia',
61
+ 'CR' => 'Costa Rica',
62
+ 'CU' => 'Cuba',
63
+ 'CV' => 'Cape Verde',
64
+ 'CX' => 'Christmas Island',
65
+ 'CY' => 'Cyprus',
66
+ 'CZ' => 'Czech Republic',
67
+ 'DE' => 'Germany',
68
+ 'DJ' => 'Djibouti',
69
+ 'DK' => 'Denmark',
70
+ 'DM' => 'Dominica',
71
+ 'DO' => 'Dominican Republic',
72
+ 'DZ' => 'Algeria',
73
+ 'EC' => 'Ecuador',
74
+ 'EE' => 'Estonia',
75
+ 'EG' => 'Egypt',
76
+ 'EH' => 'Western Sahara',
77
+ 'ER' => 'Eritrea',
78
+ 'ES' => 'Spain',
79
+ 'ET' => 'Ethiopia',
80
+ 'FI' => 'Finland',
81
+ 'FJ' => 'Fiji Islands',
82
+ 'FK' => 'Falkland Islands',
83
+ 'FM' => 'Micronesia, Federated States of',
84
+ 'FO' => 'Faroe Islands',
85
+ 'FR' => 'France',
86
+ 'GA' => 'Gabon',
87
+ 'GB' => 'United Kingdom',
88
+ 'GD' => 'Grenada',
89
+ 'GE' => 'Georgia',
90
+ 'GF' => 'French Guiana',
91
+ 'GH' => 'Ghana',
92
+ 'GI' => 'Gibraltar',
93
+ 'GL' => 'Greenland',
94
+ 'GM' => 'Gambia',
95
+ 'GN' => 'Guinea',
96
+ 'GP' => 'Guadeloupe',
97
+ 'GQ' => 'Equatorial Guinea',
98
+ 'GR' => 'Greece',
99
+ 'GS' => 'South Georgia and the South Sandwich Islands',
100
+ 'GT' => 'Guatemala',
101
+ 'GU' => 'Guam',
102
+ 'GW' => 'Guinea-Bissau',
103
+ 'GY' => 'Guyana',
104
+ 'HK' => 'Hong Kong',
105
+ 'HM' => 'Heard Island and McDonald Islands',
106
+ 'HN' => 'Honduras',
107
+ 'HR' => 'Croatia',
108
+ 'HT' => 'Haiti',
109
+ 'HU' => 'Hungary',
110
+ 'ID' => 'Indonesia',
111
+ 'IE' => 'Ireland',
112
+ 'IL' => 'Israel',
113
+ 'IN' => 'India',
114
+ 'IO' => 'British Indian Ocean Territory',
115
+ 'IQ' => 'Iraq',
116
+ 'IR' => 'Iran',
117
+ 'IS' => 'Iceland',
118
+ 'IT' => 'Italy',
119
+ 'JM' => 'Jamaica',
120
+ 'JO' => 'Jordan',
121
+ 'JP' => 'Japan',
122
+ 'KE' => 'Kenya',
123
+ 'KG' => 'Kyrgyzstan',
124
+ 'KH' => 'Cambodia',
125
+ 'KI' => 'Kiribati',
126
+ 'KM' => 'Comoros',
127
+ 'KN' => 'Saint Kitts and Nevis',
128
+ 'KP' => 'North Korea',
129
+ 'KR' => 'South Korea',
130
+ 'KW' => 'Kuwait',
131
+ 'KY' => 'Cayman Islands',
132
+ 'KZ' => 'Kazakstan',
133
+ 'LA' => 'Laos',
134
+ 'LB' => 'Lebanon',
135
+ 'LC' => 'Saint Lucia',
136
+ 'LI' => 'Liechtenstein',
137
+ 'LK' => 'Sri Lanka',
138
+ 'LR' => 'Liberia',
139
+ 'LS' => 'Lesotho',
140
+ 'LT' => 'Lithuania',
141
+ 'LU' => 'Luxembourg',
142
+ 'LV' => 'Latvia',
143
+ 'LY' => 'Libyan Arab Jamahiriya',
144
+ 'MA' => 'Morocco',
145
+ 'MC' => 'Monaco',
146
+ 'MD' => 'Moldova',
147
+ 'MG' => 'Madagascar',
148
+ 'MH' => 'Marshall Islands',
149
+ 'MK' => 'Macedonia',
150
+ 'ML' => 'Mali',
151
+ 'MM' => 'Myanmar',
152
+ 'MN' => 'Mongolia',
153
+ 'MO' => 'Macao',
154
+ 'MP' => 'Northern Mariana Islands',
155
+ 'MQ' => 'Martinique',
156
+ 'MR' => 'Mauritania',
157
+ 'MS' => 'Montserrat',
158
+ 'MT' => 'Malta',
159
+ 'MU' => 'Mauritius',
160
+ 'MV' => 'Maldives',
161
+ 'MW' => 'Malawi',
162
+ 'MX' => 'Mexico',
163
+ 'MY' => 'Malaysia',
164
+ 'MZ' => 'Mozambique',
165
+ 'NA' => 'Namibia',
166
+ 'NC' => 'New Caledonia',
167
+ 'NE' => 'Niger',
168
+ 'NF' => 'Norfolk Island',
169
+ 'NG' => 'Nigeria',
170
+ 'NI' => 'Nicaragua',
171
+ 'NL' => 'Netherlands',
172
+ 'NO' => 'Norway',
173
+ 'NP' => 'Nepal',
174
+ 'NR' => 'Nauru',
175
+ 'NU' => 'Niue',
176
+ 'NZ' => 'New Zealand',
177
+ 'OM' => 'Oman',
178
+ 'PA' => 'Panama',
179
+ 'PE' => 'Peru',
180
+ 'PF' => 'French Polynesia',
181
+ 'PG' => 'Papua New Guinea',
182
+ 'PH' => 'Philippines',
183
+ 'PK' => 'Pakistan',
184
+ 'PL' => 'Poland',
185
+ 'PM' => 'Saint Pierre and Miquelon',
186
+ 'PN' => 'Pitcairn',
187
+ 'PR' => 'Puerto Rico',
188
+ 'PS' => 'Palestine',
189
+ 'PT' => 'Portugal',
190
+ 'PW' => 'Palau',
191
+ 'PY' => 'Paraguay',
192
+ 'QA' => 'Qatar',
193
+ 'RE' => 'Reunion',
194
+ 'RO' => 'Romania',
195
+ 'RU' => 'Russia',
196
+ 'RW' => 'Rwanda',
197
+ 'SA' => 'Saudi Arabia',
198
+ 'SB' => 'Solomon Islands',
199
+ 'SC' => 'Seychelles',
200
+ 'SD' => 'Sudan',
201
+ 'SE' => 'Sweden',
202
+ 'SG' => 'Singapore',
203
+ 'SH' => 'Saint Helena',
204
+ 'SI' => 'Slovenia',
205
+ 'SJ' => 'Svalbard and Jan Mayen',
206
+ 'SK' => 'Slovakia',
207
+ 'SL' => 'Sierra Leone',
208
+ 'SM' => 'San Marino',
209
+ 'SN' => 'Senegal',
210
+ 'SO' => 'Somalia',
211
+ 'SR' => 'Suriname',
212
+ 'ST' => 'Sao Tome and Principe',
213
+ 'SV' => 'El Salvador',
214
+ 'SY' => 'Syria',
215
+ 'SZ' => 'Swaziland',
216
+ 'TC' => 'Turks and Caicos Islands',
217
+ 'TD' => 'Chad',
218
+ 'TF' => 'French Southern territories',
219
+ 'TG' => 'Togo',
220
+ 'TH' => 'Thailand',
221
+ 'TJ' => 'Tajikistan',
222
+ 'TK' => 'Tokelau',
223
+ 'TM' => 'Turkmenistan',
224
+ 'TN' => 'Tunisia',
225
+ 'TO' => 'Tonga',
226
+ 'TP' => 'East Timor',
227
+ 'TR' => 'Turkey',
228
+ 'TT' => 'Trinidad and Tobago',
229
+ 'TV' => 'Tuvalu',
230
+ 'TW' => 'Taiwan',
231
+ 'TZ' => 'Tanzania',
232
+ 'UA' => 'Ukraine',
233
+ 'UG' => 'Uganda',
234
+ 'UM' => 'United States Minor Outlying Islands',
235
+ 'US' => 'United States',
236
+ 'UY' => 'Uruguay',
237
+ 'UZ' => 'Uzbekistan',
238
+ 'VA' => 'Holy See (Vatican City State)',
239
+ 'VC' => 'Saint Vincent and the Grenadines',
240
+ 'VE' => 'Venezuela',
241
+ 'VG' => 'Virgin Islands, British',
242
+ 'VI' => 'Virgin Islands, U.S.',
243
+ 'VN' => 'Vietnam',
244
+ 'VU' => 'Vanuatu',
245
+ 'WF' => 'Wallis and Futuna',
246
+ 'WS' => 'Samoa',
247
+ 'YE' => 'Yemen',
248
+ 'YT' => 'Mayotte',
249
+ 'YU' => 'Yugoslavia',
250
+ 'ZA' => 'South Africa',
251
+ 'ZM' => 'Zambia',
252
+ 'ZW' => 'Zimbabwe' );
 
tools/nprogress/nprogress.css CHANGED
@@ -57,32 +57,11 @@
57
  position: absolute;
58
  }
59
 
60
- @
61
- -webkit-keyframes nprogress-spinner { 0% {
62
- -webkit-transform: rotate(0deg);
63
- }
64
-
65
- 100%
66
- {
67
- -webkit-transform
68
- :
69
-
70
- rotate
71
- (360deg);
72
-
73
- }
74
- }
75
- @
76
- keyframes nprogress-spinner { 0% {
77
- transform: rotate(0deg);
78
- }
79
- 100%
80
- {
81
- transform
82
- :
83
-
84
- rotate
85
- (360deg);
86
-
87
  }
 
 
 
88
  }
57
  position: absolute;
58
  }
59
 
60
+ @-webkit-keyframes nprogress-spinner {
61
+ 0% { -webkit-transform: rotate(0deg); }
62
+ 100% { -webkit-transform: rotate(360deg); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
+ @keyframes nprogress-spinner {
65
+ 0% { transform: rotate(0deg); }
66
+ 100% { transform: rotate(360deg); }
67
  }
tools/tools.php CHANGED
@@ -7,123 +7,111 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
 
13
- if (! class_exists('GADWP_Tools')) {
14
 
15
- class GADWP_Tools
16
- {
17
 
18
- public static function get_countrycodes()
19
- {
20
- include_once 'iso3166.php';
21
- return $country_codes;
22
- }
23
 
24
- public static function guess_default_domain($profiles)
25
- {
26
- $domain = get_option('siteurl');
27
- $domain = str_ireplace(array(
28
- 'http://',
29
- 'https://'
30
- ), '', $domain);
31
- if (!empty($profiles)) {
32
- foreach ($profiles as $items) {
33
- if (strpos($items[3], $domain)) {
34
- return $items[1];
35
- }
36
- }
37
- return $profiles[0][1];
38
- } else {
39
- return '';
40
- }
41
- }
42
 
43
- public static function get_selected_profile($profiles, $profile)
44
- {
45
- if (!empty($profiles)) {
46
- foreach ($profiles as $item) {
47
- if ($item[1] == $profile) {
48
- return $item;
49
- }
50
- }
51
- }
52
- }
53
 
54
- public static function get_root_domain($domain)
55
- {
56
- $root = explode('/', $domain);
57
- preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", str_ireplace('www', '', isset($root[2]) ? $root[2] : $domain), $root);
58
- return $root;
59
- }
60
 
61
- public static function strip_protocol($domain)
62
- {
63
- return str_replace(array(
64
- "https://",
65
- "http://",
66
- " "
67
- ), "", $domain);
68
- }
69
 
70
- public static function clear_cache()
71
- {
72
- global $wpdb;
73
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_gadash%%'");
74
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_gadash%%'");
75
- }
76
 
77
- public static function colourVariator($colour, $per)
78
- {
79
- $colour = substr($colour, 1);
80
- $rgb = '';
81
- $per = $per / 100 * 255;
82
- if ($per < 0) {
83
- // Darker
84
- $per = abs($per);
85
- for ($x = 0; $x < 3; $x ++) {
86
- $c = hexdec(substr($colour, (2 * $x), 2)) - $per;
87
- $c = ($c < 0) ? 0 : dechex($c);
88
- $rgb .= (strlen($c) < 2) ? '0' . $c : $c;
89
- }
90
- } else {
91
- // Lighter
92
- for ($x = 0; $x < 3; $x ++) {
93
- $c = hexdec(substr($colour, (2 * $x), 2)) + $per;
94
- $c = ($c > 255) ? 'ff' : dechex($c);
95
- $rgb .= (strlen($c) < 2) ? '0' . $c : $c;
96
- }
97
- }
98
- return '#' . $rgb;
99
- }
100
 
101
- public static function variations($base)
102
- {
103
- $variations[] = $base;
104
- $variations[] = self::colourVariator($base, - 10);
105
- $variations[] = self::colourVariator($base, + 10);
106
- $variations[] = self::colourVariator($base, + 20);
107
- $variations[] = self::colourVariator($base, - 20);
108
- $variations[] = self::colourVariator($base, + 30);
109
- $variations[] = self::colourVariator($base, - 30);
110
- return $variations;
111
- }
112
 
113
- public static function check_roles($access_level, $tracking = false)
114
- {
115
- if (is_user_logged_in() && isset($access_level)) {
116
- $current_user = wp_get_current_user();
117
- $roles = (array) $current_user->roles;
118
- if ((current_user_can('manage_options')) && ! $tracking) {
119
- return true;
120
- }
121
- if (count(array_intersect($roles, $access_level)) > 0) {
122
- return true;
123
- } else {
124
- return false;
125
- }
126
- }
127
- }
128
- }
129
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
 
13
+ if ( ! class_exists( 'GADWP_Tools' ) ) {
14
 
15
+ class GADWP_Tools {
 
16
 
17
+ public static function get_countrycodes() {
18
+ include_once 'iso3166.php';
19
+ return $country_codes;
20
+ }
 
21
 
22
+ public static function guess_default_domain( $profiles ) {
23
+ $domain = get_option( 'siteurl' );
24
+ $domain = str_ireplace( array(
25
+ 'http://',
26
+ 'https://' ), '', $domain );
27
+ if ( ! empty( $profiles ) ) {
28
+ foreach ( $profiles as $items ) {
29
+ if ( strpos( $items[3], $domain ) ) {
30
+ return $items[1];
31
+ }
32
+ }
33
+ return $profiles[0][1];
34
+ } else {
35
+ return '';
36
+ }
37
+ }
 
 
38
 
39
+ public static function get_selected_profile( $profiles, $profile ) {
40
+ if ( ! empty( $profiles ) ) {
41
+ foreach ( $profiles as $item ) {
42
+ if ( $item[1] == $profile ) {
43
+ return $item;
44
+ }
45
+ }
46
+ }
47
+ }
 
48
 
49
+ public static function get_root_domain( $domain ) {
50
+ $root = explode( '/', $domain );
51
+ preg_match( "/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", str_ireplace( 'www', '', isset( $root[2] ) ? $root[2] : $domain ), $root );
52
+ return $root;
53
+ }
 
54
 
55
+ public static function strip_protocol( $domain ) {
56
+ return str_replace( array(
57
+ "https://",
58
+ "http://",
59
+ " " ), "", $domain );
60
+ }
 
 
61
 
62
+ public static function clear_cache() {
63
+ global $wpdb;
64
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_gadash%%'" );
65
+ $sqlquery = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_gadash%%'" );
66
+ }
 
67
 
68
+ public static function colourVariator( $colour, $per ) {
69
+ $colour = substr( $colour, 1 );
70
+ $rgb = '';
71
+ $per = $per / 100 * 255;
72
+ if ( $per < 0 ) {
73
+ // Darker
74
+ $per = abs( $per );
75
+ for ( $x = 0; $x < 3; $x++ ) {
76
+ $c = hexdec( substr( $colour, ( 2 * $x ), 2 ) ) - $per;
77
+ $c = ( $c < 0 ) ? 0 : dechex( $c );
78
+ $rgb .= ( strlen( $c ) < 2 ) ? '0' . $c : $c;
79
+ }
80
+ } else {
81
+ // Lighter
82
+ for ( $x = 0; $x < 3; $x++ ) {
83
+ $c = hexdec( substr( $colour, ( 2 * $x ), 2 ) ) + $per;
84
+ $c = ( $c > 255 ) ? 'ff' : dechex( $c );
85
+ $rgb .= ( strlen( $c ) < 2 ) ? '0' . $c : $c;
86
+ }
87
+ }
88
+ return '#' . $rgb;
89
+ }
 
90
 
91
+ public static function variations( $base ) {
92
+ $variations[] = $base;
93
+ $variations[] = self::colourVariator( $base, - 10 );
94
+ $variations[] = self::colourVariator( $base, + 10 );
95
+ $variations[] = self::colourVariator( $base, + 20 );
96
+ $variations[] = self::colourVariator( $base, - 20 );
97
+ $variations[] = self::colourVariator( $base, + 30 );
98
+ $variations[] = self::colourVariator( $base, - 30 );
99
+ return $variations;
100
+ }
 
101
 
102
+ public static function check_roles( $access_level, $tracking = false ) {
103
+ if ( is_user_logged_in() && isset( $access_level ) ) {
104
+ $current_user = wp_get_current_user();
105
+ $roles = (array) $current_user->roles;
106
+ if ( ( current_user_can( 'manage_options' ) ) && ! $tracking ) {
107
+ return true;
108
+ }
109
+ if ( count( array_intersect( $roles, $access_level ) ) > 0 ) {
110
+ return true;
111
+ } else {
112
+ return false;
113
+ }
114
+ }
115
+ }
116
+ }
 
117
  }