Wp-Insert - Version 2.4.3

Version Description

Download this release

Release Info

Developer namith.jawahar
Plugin Icon 128x128 Wp-Insert
Version 2.4.3
Comparing to
See all releases

Code changes from version 2.4.2 to 2.4.3

includes/assets/css/wp-insert.css CHANGED
@@ -33,16 +33,42 @@
33
 
34
  .wp-insert .plugin-card .plugin-card-top {
35
  background: #ffffff;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  }
37
 
38
  .wp-insert .plugin-card-bottom .wp_insert_delete_icon {
39
- color: #b20a0a;
 
40
  cursor: pointer;
41
  float: right;
42
  }
43
 
44
  .wp-insert .plugin-card-bottom .wp_insert_delete_icon:hover {
45
- color: #FC0505;
 
 
 
 
 
 
 
 
 
 
 
46
  }
47
 
48
  .wp-insert .plugin-card-bottom p {
33
 
34
  .wp-insert .plugin-card .plugin-card-top {
35
  background: #ffffff;
36
+ border-bottom: 1px solid #dedede;
37
+ }
38
+
39
+ .wp-insert .plugin-card .plugin-card-bottom {
40
+ border-top: none;
41
+ }
42
+
43
+ .wp-insert .plugin-card-bottom .wp_insert_ad_unit_title {
44
+ color: #656565;
45
+ font-weight: 600;
46
+ }
47
+
48
+ .wp-insert .plugin-card-bottom .wp_insert_ad_unit_title:hover {
49
+ color: #0085BA;
50
  }
51
 
52
  .wp-insert .plugin-card-bottom .wp_insert_delete_icon {
53
+ /*color: #b20a0a;*/
54
+ color: #656565;
55
  cursor: pointer;
56
  float: right;
57
  }
58
 
59
  .wp-insert .plugin-card-bottom .wp_insert_delete_icon:hover {
60
+ color: #D81F1F;
61
+ }
62
+
63
+ .wp-insert .plugin-card-bottom .wp_insert_duplicate_icon {
64
+ float: right;
65
+ cursor: pointer;
66
+ color: #656565;
67
+ margin: 0 3px;
68
+ }
69
+
70
+ .wp-insert .plugin-card-bottom .wp_insert_duplicate_icon:hover {
71
+ color: #0085BA;
72
  }
73
 
74
  .wp-insert .plugin-card-bottom p {
includes/assets/images/{vi-empty-graph.jpg → empty-graph.jpg} RENAMED
File without changes
includes/assets/images/{vi-no-data.jpg → no-data.jpg} RENAMED
File without changes
includes/modules/core/controlpanel/module.php CHANGED
@@ -58,7 +58,7 @@ function wp_insert_title_plugin_card() {
58
  echo '<div id="wpInsertMeta">';
59
  echo '<p><b>Donate :</b><br /><a target="_blank" href="http://wpinsert.smartlogix.co.in/support/">Click Here</a> to Donate and Promote further development of this plugin.</p>';
60
  echo '<p><b>Like Us :</b><br /><a target="_blank" href="https://www.facebook.com/SmartLogix/">Click here</a> to like and support us on Facebook</p>';
61
- echo '<p><b>Rate and Review :</b><br />If you find this plugin useful do leave a honest <a target="_blank" href="http://wordpress.org/plugins/wp-insert">RATING</a> and <a target="_blank" href="https://wordpress.org/support/view/plugin-reviews/wp-insert#postform">REVIEW</a><br /><span style="font-size: 15px; font-weight: 600;">You spending a few minutes to let us know your appreciation for the project will motivate us further in improving the plugin and adding new features.</span></p>';
62
  echo '</div>';
63
  echo '</div>';
64
  echo '</div>';
@@ -66,7 +66,7 @@ function wp_insert_title_plugin_card() {
66
  /* End Add Card in Admin Panel */
67
 
68
  /* Begin Admin Notice */
69
- add_action('admin_notices', 'wp_insert_admin_notices');
70
  function wp_insert_admin_notices() {
71
  if(current_user_can('manage_options')) {
72
  $userId = get_current_user_id();
@@ -84,7 +84,7 @@ function wp_insert_admin_notices() {
84
  echo '</div>';
85
  }
86
  }
87
- }
88
 
89
  add_action('wp_ajax_wp_insert_admin_notice_dismiss', 'wp_insert_admin_notice_dismiss');
90
  function wp_insert_admin_notice_dismiss() {
58
  echo '<div id="wpInsertMeta">';
59
  echo '<p><b>Donate :</b><br /><a target="_blank" href="http://wpinsert.smartlogix.co.in/support/">Click Here</a> to Donate and Promote further development of this plugin.</p>';
60
  echo '<p><b>Like Us :</b><br /><a target="_blank" href="https://www.facebook.com/SmartLogix/">Click here</a> to like and support us on Facebook</p>';
61
+ echo '<div style="font-size: 16px; font-weight: 600; background: #FFFFAA; display: block; padding: 10px; text-align: justify; border: 1px dashed #FF0000; margin: 10px 0 0; border-radius: 5px;">Thanks for using Wp-Insert. Positive <a target="_blank" href="https://wordpress.org/support/view/plugin-reviews/wp-insert#postform">reviews</a> are a great motivation for us to add new features, fix bugs and spend more time working on Wp-Insert.<br />Looking forward to your continued support and patronage - <i>Namith Jawahar</i>.</div>';
62
  echo '</div>';
63
  echo '</div>';
64
  echo '</div>';
66
  /* End Add Card in Admin Panel */
67
 
68
  /* Begin Admin Notice */
69
+ /*add_action('admin_notices', 'wp_insert_admin_notices');
70
  function wp_insert_admin_notices() {
71
  if(current_user_can('manage_options')) {
72
  $userId = get_current_user_id();
84
  echo '</div>';
85
  }
86
  }
87
+ }*/
88
 
89
  add_action('wp_ajax_wp_insert_admin_notice_dismiss', 'wp_insert_admin_notice_dismiss');
90
  function wp_insert_admin_notice_dismiss() {
includes/modules/core/units/adunit.php CHANGED
@@ -265,14 +265,20 @@ function wp_insert_get_ad_status($rules) {
265
  break;
266
  case 'PAGE':
267
  if(isset($rules['rules_exclude_page']) && wp_validate_boolean($rules['rules_exclude_page']) ) {
268
- return false;
 
 
269
  } else if(isset($rules['rules_page_exceptions']) && is_array($rules['rules_page_exceptions']) && (in_array($page_details['ID'], $rules['rules_page_exceptions']))) {
270
  return false;
271
  }
272
  break;
273
  case 'POST':
274
  if(isset($rules['rules_exclude_post']) && wp_validate_boolean($rules['rules_exclude_post']) ) {
275
- return false;
 
 
 
 
276
  } else if(isset($rules['rules_post_exceptions']) && is_array($rules['rules_post_exceptions']) && (in_array($page_details['ID'], $rules['rules_post_exceptions']))) {
277
  return false;
278
  } else if(isset($rules['rules_post_categories_exceptions']) && isset($page_details['categories']) && is_array($rules['rules_post_categories_exceptions']) && is_array($page_details['categories']) && (count(array_intersect($page_details['categories'], $rules['rules_post_categories_exceptions'])) > 0)) {
@@ -281,7 +287,9 @@ function wp_insert_get_ad_status($rules) {
281
  break;
282
  case 'CATEGORY':
283
  if(isset($rules['rules_exclude_categories']) && wp_validate_boolean($rules['rules_exclude_categories'])) {
284
- return false;
 
 
285
  } else if(isset($rules['rules_categories_exceptions']) && is_array($rules['rules_categories_exceptions']) && (in_array($page_details['ID'], $rules['rules_categories_exceptions']))) {
286
  return false;
287
  } else if(isset($rules['rules_categories_instances']) && is_array($rules['rules_categories_instances']) && (in_array($wpInsertPostInstance, $rules['rules_categories_instances']))) {
265
  break;
266
  case 'PAGE':
267
  if(isset($rules['rules_exclude_page']) && wp_validate_boolean($rules['rules_exclude_page']) ) {
268
+ if((!isset($rules['rules_page_exceptions'])) || (!is_array($rules['rules_page_exceptions'])) || (!in_array($page_details['ID'], $rules['rules_page_exceptions']))) {
269
+ return false;
270
+ }
271
  } else if(isset($rules['rules_page_exceptions']) && is_array($rules['rules_page_exceptions']) && (in_array($page_details['ID'], $rules['rules_page_exceptions']))) {
272
  return false;
273
  }
274
  break;
275
  case 'POST':
276
  if(isset($rules['rules_exclude_post']) && wp_validate_boolean($rules['rules_exclude_post']) ) {
277
+ if((!isset($rules['rules_post_exceptions'])) || (!is_array($rules['rules_post_exceptions'])) || (!in_array($page_details['ID'], $rules['rules_post_exceptions']))) {
278
+ return false;
279
+ } else if ((!isset($rules['rules_post_categories_exceptions'])) || (!is_array($rules['rules_post_categories_exceptions'])) || (!isset($page_details['categories'])) || (!is_array($page_details['categories'])) || (!(count(array_intersect($page_details['categories'], $rules['rules_post_categories_exceptions'])) > 0))) {
280
+ return false;
281
+ }
282
  } else if(isset($rules['rules_post_exceptions']) && is_array($rules['rules_post_exceptions']) && (in_array($page_details['ID'], $rules['rules_post_exceptions']))) {
283
  return false;
284
  } else if(isset($rules['rules_post_categories_exceptions']) && isset($page_details['categories']) && is_array($rules['rules_post_categories_exceptions']) && is_array($page_details['categories']) && (count(array_intersect($page_details['categories'], $rules['rules_post_categories_exceptions'])) > 0)) {
287
  break;
288
  case 'CATEGORY':
289
  if(isset($rules['rules_exclude_categories']) && wp_validate_boolean($rules['rules_exclude_categories'])) {
290
+ if((!isset($rules['rules_categories_exceptions'])) || (!is_array($rules['rules_categories_exceptions'])) || (!in_array($page_details['ID'], $rules['rules_categories_exceptions']))) {
291
+ return false;
292
+ }
293
  } else if(isset($rules['rules_categories_exceptions']) && is_array($rules['rules_categories_exceptions']) && (in_array($page_details['ID'], $rules['rules_categories_exceptions']))) {
294
  return false;
295
  } else if(isset($rules['rules_categories_instances']) && is_array($rules['rules_categories_instances']) && (in_array($wpInsertPostInstance, $rules['rules_categories_instances']))) {
includes/modules/core/units/js/module.js CHANGED
@@ -1,4 +1,9 @@
1
  function wp_insert_ads_click_handler(type, identifier, title, isNew) {
 
 
 
 
 
2
  var preTitle = jQuery('#wp_insert_'+type+'_ad_'+identifier).attr('data-pre-title');
3
  jQuery('<div id="wp_insert_'+type+'_'+identifier+'_dialog"></div>').html('<div class="wp_insert_ajaxloader"></div>').dialog({
4
  'modal': true,
@@ -15,7 +20,7 @@ function wp_insert_ads_click_handler(type, identifier, title, isNew) {
15
  jQuery.post(
16
  jQuery('#wp_insert_admin_ajax').val(), {
17
  'action': 'wp_insert_'+type+'_get_ad_form',
18
- 'wp_insert_identifier': identifier,
19
  'wp_insert_type': type,
20
  'wp_insert_nonce': jQuery('#wp_insert_nonce').val()
21
  }, function(response) {
@@ -39,13 +44,19 @@ function wp_insert_ads_click_handler(type, identifier, title, isNew) {
39
  var adLink = jQuery("<a></a>");
40
  adLink.attr('id', 'wp_insert_'+type+'_ad_'+newIdentifier);
41
  adLink.attr('href', 'javascript:;');
 
42
  adLink.attr('data-pre-title', preTitle);
43
  adLink.attr('onClick', "wp_insert_ads_click_handler(\'"+type+"\', \'"+newIdentifier+"\', \'"+jQuery('#wp_insert_'+type+'_'+newIdentifier+'_title').val()+"\', false)");
44
  adLink.html(preTitle+' : '+jQuery('#wp_insert_'+type+'_'+newIdentifier+'_title').val());
45
  var deleteButton = jQuery('<span></span>');
46
- deleteButton.attr('class', 'dashicons dashicons-dismiss wp_insert_delete_icon');
 
47
  deleteButton.attr('onClick', "wp_insert_ad_delete_handler(\'"+type+"\', \'"+newIdentifier+"\')");
48
- jQuery('#wp_insert_'+type+'_ad_new').parent().before(jQuery('<p></p>').append(adLink, deleteButton));
 
 
 
 
49
  wp_insert_ad_update_handler(type, newIdentifier);
50
  } else {
51
  jQuery("#wp_insert_"+type+"_ad_"+identifier).html(preTitle+' : '+jQuery('#wp_insert_'+type+'_'+identifier+'_title').val());
1
  function wp_insert_ads_click_handler(type, identifier, title, isNew) {
2
+ var isDuplicate = false;
3
+ if(identifier.indexOf("###DUPLICATE###") != -1) {
4
+ isDuplicate = true;
5
+ identifier = identifier.replace("###DUPLICATE###","");
6
+ }
7
  var preTitle = jQuery('#wp_insert_'+type+'_ad_'+identifier).attr('data-pre-title');
8
  jQuery('<div id="wp_insert_'+type+'_'+identifier+'_dialog"></div>').html('<div class="wp_insert_ajaxloader"></div>').dialog({
9
  'modal': true,
20
  jQuery.post(
21
  jQuery('#wp_insert_admin_ajax').val(), {
22
  'action': 'wp_insert_'+type+'_get_ad_form',
23
+ 'wp_insert_identifier': ((isDuplicate)?'###DUPLICATE###':'')+identifier,
24
  'wp_insert_type': type,
25
  'wp_insert_nonce': jQuery('#wp_insert_nonce').val()
26
  }, function(response) {
44
  var adLink = jQuery("<a></a>");
45
  adLink.attr('id', 'wp_insert_'+type+'_ad_'+newIdentifier);
46
  adLink.attr('href', 'javascript:;');
47
+ adLink.attr('class', 'wp_insert_ad_unit_title');
48
  adLink.attr('data-pre-title', preTitle);
49
  adLink.attr('onClick', "wp_insert_ads_click_handler(\'"+type+"\', \'"+newIdentifier+"\', \'"+jQuery('#wp_insert_'+type+'_'+newIdentifier+'_title').val()+"\', false)");
50
  adLink.html(preTitle+' : '+jQuery('#wp_insert_'+type+'_'+newIdentifier+'_title').val());
51
  var deleteButton = jQuery('<span></span>');
52
+ deleteButton.attr('class', 'dashicons dashicons-no wp_insert_delete_icon');
53
+ deleteButton.attr('title', 'Delete Ad Unit');
54
  deleteButton.attr('onClick', "wp_insert_ad_delete_handler(\'"+type+"\', \'"+newIdentifier+"\')");
55
+ var duplicateButton = jQuery('<span></span>');
56
+ duplicateButton.attr('class', 'dashicons dashicons-format-gallery wp_insert_duplicate_icon');
57
+ duplicateButton.attr('title', 'Duplicate Ad Unit');
58
+ duplicateButton.attr('onClick', "wp_insert_ads_click_handler(\'"+type+"\', \'###DUPLICATE###"+newIdentifier+"\', \'"+newIdentifier+"\', \'"+jQuery('#wp_insert_'+type+'_'+newIdentifier+'_title').val()+" Duplicate\', false)");
59
+ jQuery('#wp_insert_'+type+'_ad_new').parent().before(jQuery('<p></p>').append(adLink, deleteButton, duplicateButton));
60
  wp_insert_ad_update_handler(type, newIdentifier);
61
  } else {
62
  jQuery("#wp_insert_"+type+"_ad_"+identifier).html(preTitle+' : '+jQuery('#wp_insert_'+type+'_'+identifier+'_title').val());
includes/modules/core/units/module.php CHANGED
@@ -52,8 +52,9 @@ function wp_insert_get_plugin_card($title, $description, $type, $preTitle) {
52
  }
53
  /* End Workaround for migrating old users to new system (can be removed in a later version) */
54
  echo '<p>';
55
- echo '<a id="wp_insert_'.$type.'_ad_'.$key.'" href="javascript:;" data-pre-title="'.$preTitle.'" onclick="wp_insert_ads_click_handler(\''.$type.'\', \''.$key.'\', \''.$value['title'].'\', false)">'.$preTitle.' : '.$title.'</a>';
56
- echo '<span class="dashicons dashicons-dismiss wp_insert_delete_icon" onclick="wp_insert_ad_delete_handler(\''.$type.'\', \''.$key.'\')"></span>';
 
57
  echo '</p>';
58
  }
59
  }
@@ -68,13 +69,20 @@ function wp_insert_get_ad_form($script = '') {
68
  check_ajax_referer('wp-insert', 'wp_insert_nonce');
69
  if(isset($_POST['wp_insert_identifier']) && isset($_POST['wp_insert_type'])) {
70
  $type = $_POST['wp_insert_type'];
 
 
71
  $identifier = substr(str_shuffle(str_repeat("abcdefghijklmnopqrstuvwxyz", 5)), 0, 5).uniqid();
72
- if($_POST['wp_insert_identifier'] != 'new') {
 
 
 
 
73
  $identifier = $_POST['wp_insert_identifier'];
 
74
  }
75
- $data = get_option('wp_insert_'.$type);
76
  echo '<div class="wp_insert_popup_content_wrapper">';
77
- $control = new smartlogixControls(array('optionIdentifier' => 'wp_insert_'.$type.'['.$identifier.']', 'values' => $data[$identifier]));
78
  $control->add_control(array('type' => 'ipCheckbox', 'className' => 'wp_insert_'.$type.'_status', 'optionName' => 'status'));
79
  $control->add_control(array('type' => 'hidden', 'className' => 'wp_insert_'.$type.'_identifier', 'optionName' => 'identifier', 'value' => $identifier));
80
  echo $control->HTML;
52
  }
53
  /* End Workaround for migrating old users to new system (can be removed in a later version) */
54
  echo '<p>';
55
+ echo '<a class="wp_insert_ad_unit_title" title="Edit Ad Unit" id="wp_insert_'.$type.'_ad_'.$key.'" href="javascript:;" data-pre-title="'.$preTitle.'" onclick="wp_insert_ads_click_handler(\''.$type.'\', \''.$key.'\', \''.$value['title'].'\', false)">'.$preTitle.' : '.$title.'</a>';
56
+ echo '<span class="dashicons dashicons-no wp_insert_delete_icon" title="Delete Ad Unit" onclick="wp_insert_ad_delete_handler(\''.$type.'\', \''.$key.'\')"></span>';
57
+ echo '<span class="dashicons dashicons-format-gallery wp_insert_duplicate_icon" title="Duplicate Ad Unit" onclick="wp_insert_ads_click_handler(\''.$type.'\', \'###DUPLICATE###'.$key.'\', \''.$value['title'].' Duplicate\', true)"></span>';
58
  echo '</p>';
59
  }
60
  }
69
  check_ajax_referer('wp-insert', 'wp_insert_nonce');
70
  if(isset($_POST['wp_insert_identifier']) && isset($_POST['wp_insert_type'])) {
71
  $type = $_POST['wp_insert_type'];
72
+ $data = get_option('wp_insert_'.$type);
73
+
74
  $identifier = substr(str_shuffle(str_repeat("abcdefghijklmnopqrstuvwxyz", 5)), 0, 5).uniqid();
75
+ $dataIdentifier = $identifier;
76
+ if(strpos($_POST['wp_insert_identifier'], '###DUPLICATE###') !== false) {
77
+ $dataIdentifier = str_replace('###DUPLICATE###', '', $_POST['wp_insert_identifier']);
78
+ $data[$dataIdentifier]['title'] = $data[$dataIdentifier]['title'].' (Duplicate)';
79
+ } else if($_POST['wp_insert_identifier'] != 'new') {
80
  $identifier = $_POST['wp_insert_identifier'];
81
+ $dataIdentifier = $identifier;
82
  }
83
+
84
  echo '<div class="wp_insert_popup_content_wrapper">';
85
+ $control = new smartlogixControls(array('optionIdentifier' => 'wp_insert_'.$type.'['.$identifier.']', 'values' => $data[$dataIdentifier]));
86
  $control->add_control(array('type' => 'ipCheckbox', 'className' => 'wp_insert_'.$type.'_status', 'optionName' => 'status'));
87
  $control->add_control(array('type' => 'hidden', 'className' => 'wp_insert_'.$type.'_identifier', 'optionName' => 'identifier', 'value' => $identifier));
88
  echo $control->HTML;
includes/modules/core/units/notes.php CHANGED
@@ -28,7 +28,6 @@ function wp_insert_form_accordion_tabs_notes($control, $identifier, $location) {
28
  } else {
29
  $title = $control->values['title'];
30
  }
31
- echo $title;
32
  $control->add_control(array('type' => 'text', 'optionName' => 'title', 'helpText' => 'The title is used to identify your Ad Widget easily in future. A Random Title will be assigned to your Ad widget by default.', 'value' => $title));
33
  $control->create_section('Title');
34
  echo $control->HTML;
28
  } else {
29
  $title = $control->values['title'];
30
  }
 
31
  $control->add_control(array('type' => 'text', 'optionName' => 'title', 'helpText' => 'The title is used to identify your Ad Widget easily in future. A Random Title will be assigned to your Ad widget by default.', 'value' => $title));
32
  $control->create_section('Title');
33
  echo $control->HTML;
includes/modules/general/google/api-handler.php ADDED
@@ -0,0 +1,408 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function wp_insert_google_api_get_auth_url($clientId) {
3
+ return 'https://accounts.google.com/o/oauth2/v2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadsense.readonly&access_type=offline&include_granted_scopes=true&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id='.$clientId;
4
+ }
5
+
6
+ function wp_insert_google_api_get_authentication_data() {
7
+ $authenticationData = get_option('wp_insert_google_api_authentication_data', true);
8
+ if(isset($authenticationData) && (is_array($authenticationData)) && isset($authenticationData['clientId']) && ($authenticationData['clientId'] != '') && isset($authenticationData['clientSecret']) && ($authenticationData['clientSecret'] != '')) {
9
+ return array(
10
+ 'clientId' => $authenticationData['clientId'],
11
+ 'clientSecret' => $authenticationData['clientSecret']
12
+ );
13
+ }
14
+ return false;
15
+ }
16
+
17
+ function wp_insert_google_api_set_access_token($clientId, $clientSecret, $authCode) {
18
+ try{
19
+ $response = wp_remote_post(
20
+ 'https://www.googleapis.com/oauth2/v4/token',
21
+ array(
22
+ 'timeout' => 15,
23
+ 'headers' => array(
24
+ 'Content-Type' => 'application/x-www-form-urlencoded'
25
+ ),
26
+ 'body' => array(
27
+ 'code' => $authCode,
28
+ 'client_id' => $clientId,
29
+ 'client_secret' => $clientSecret,
30
+ 'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob',
31
+ 'grant_type' => 'authorization_code',
32
+ )
33
+ )
34
+ );
35
+ if(!is_wp_error($response)) {
36
+ if(200 == wp_remote_retrieve_response_code($response)) {
37
+ $responseBody = json_decode($response['body']);
38
+ if(json_last_error() == JSON_ERROR_NONE) {
39
+ $authenticationData = array(
40
+ 'clientId' => $clientId,
41
+ 'clientSecret' => $clientSecret,
42
+ 'refreshToken' => $responseBody->refresh_token
43
+ );
44
+ update_option('wp_insert_google_api_authentication_data', $authenticationData);
45
+ delete_transient('wp_insert_google_api_access_token');
46
+ set_transient('wp_insert_vi_api_access_token', $responseBody->access_token, MINUTE_IN_SECONDS * 50);
47
+ return true;
48
+ } else {
49
+ return false;
50
+ }
51
+ } else {
52
+ return false;
53
+ }
54
+ }
55
+ } catch(Exception $ex) {
56
+ return false;
57
+ }
58
+ }
59
+
60
+ function wp_insert_google_api_get_access_token() {
61
+ $accessToken = get_transient('wp_insert_google_api_access_token');
62
+ if(($accessToken === false) || ($accessToken == '')) {
63
+ $authenticationData = get_option('wp_insert_google_api_authentication_data', true);
64
+ if(isset($authenticationData) && (is_array($authenticationData)) && isset($authenticationData['clientId']) && ($authenticationData['clientId'] != '') && isset($authenticationData['clientSecret']) && ($authenticationData['clientSecret'] != '') && isset($authenticationData['refreshToken']) && ($authenticationData['refreshToken'] != '')) {
65
+ try {
66
+ $response = wp_remote_post(
67
+ 'https://www.googleapis.com/oauth2/v4/token',
68
+ array(
69
+ 'timeout' => 15,
70
+ 'headers' => array(
71
+ 'Content-Type' => 'application/x-www-form-urlencoded'
72
+ ),
73
+ 'body' => array(
74
+ 'client_id' => $authenticationData['clientId'],
75
+ 'client_secret' => $authenticationData['clientSecret'],
76
+ 'refresh_token' => $authenticationData['refreshToken'],
77
+ 'grant_type' => 'refresh_token',
78
+ )
79
+ )
80
+ );
81
+ if(!is_wp_error($response)) {
82
+ if(200 == wp_remote_retrieve_response_code($response)) {
83
+ $responseBody = json_decode($response['body']);
84
+ if(json_last_error() == JSON_ERROR_NONE) {
85
+ delete_transient('wp_insert_google_api_access_token');
86
+ set_transient('wp_insert_vi_api_access_token', $responseBody->access_token, MINUTE_IN_SECONDS * 50);
87
+ return $responseBody->access_token;
88
+ } else {
89
+ return false;
90
+ }
91
+ } else {
92
+ return false;
93
+ }
94
+ }
95
+ } catch(Exception $ex) {
96
+ return false;
97
+ }
98
+ } else {
99
+ return false;
100
+ }
101
+ }
102
+ return $accessToken;
103
+ }
104
+
105
+ function wp_insert_google_api_revoke_access_token($accessToken = '') {
106
+ if($accessToken == '') {
107
+ $accessToken = wp_insert_google_api_get_access_token();
108
+ }
109
+ if($accessToken != false) {
110
+ try {
111
+ $response = wp_remote_get(
112
+ 'https://accounts.google.com/o/oauth2/revoke?token='.$accessToken,
113
+ array(
114
+ 'timeout' => 15,
115
+ 'headers' => array(
116
+ 'Content-Type' => 'application/x-www-form-urlencoded'
117
+ ),
118
+
119
+ )
120
+ );
121
+ if(!is_wp_error($response)) {
122
+ if(200 == wp_remote_retrieve_response_code($response)) {
123
+ delete_transient('wp_insert_google_api_access_token');
124
+ $authenticationData = get_option('wp_insert_google_api_authentication_data', true);
125
+ $authenticationData['refreshToken'] = '';
126
+ update_option('wp_insert_google_api_authentication_data', $authenticationData);
127
+ return true;
128
+ } else {
129
+ return false;
130
+ }
131
+ }
132
+ } catch(Exception $ex) {
133
+ return false;
134
+ }
135
+ }
136
+ return false;
137
+ }
138
+
139
+ function wp_insert_google_api_get_accounts($accessToken = '') {
140
+ if($accessToken == '') {
141
+ $accessToken = wp_insert_google_api_get_access_token();
142
+ }
143
+ if($accessToken != false) {
144
+ try {
145
+ $response = wp_remote_get(
146
+ 'https://www.googleapis.com/adsense/v1.4/accounts',
147
+ array(
148
+ 'timeout' => 15,
149
+ 'headers' => array(
150
+ 'Content-Type' => 'application/x-www-form-urlencoded',
151
+ 'Authorization' => 'Bearer '.$accessToken
152
+ ),
153
+
154
+ )
155
+ );
156
+ if(!is_wp_error($response)) {
157
+ if(200 == wp_remote_retrieve_response_code($response)) {
158
+ $responseBody = json_decode($response['body']);
159
+ if(json_last_error() == JSON_ERROR_NONE) {
160
+ $accounts = array();
161
+ if(isset($responseBody->items) && (count($responseBody->items) > 0)) {
162
+ foreach($responseBody->items as $account) {
163
+ $accounts[] = array('name' => $account->name, 'id' => $account->id);
164
+ }
165
+ }
166
+ if(count($accounts) > 0) {
167
+ return $accounts;
168
+ }
169
+ return false;
170
+ } else {
171
+ return false;
172
+ }
173
+ } else {
174
+ return false;
175
+ }
176
+ }
177
+ } catch(Exception $ex) {
178
+ return false;
179
+ }
180
+ }
181
+ return false;
182
+ }
183
+
184
+ function wp_insert_google_api_get_adclients($accountID, $accessToken = '') {
185
+ if($accessToken == '') {
186
+ $accessToken = wp_insert_google_api_get_access_token();
187
+ }
188
+ if($accessToken != false) {
189
+ try {
190
+ $response = wp_remote_get(
191
+ 'https://www.googleapis.com/adsense/v1.4/accounts/'.$accountID.'/adclients',
192
+ array(
193
+ 'timeout' => 15,
194
+ 'headers' => array(
195
+ 'Content-Type' => 'application/x-www-form-urlencoded',
196
+ 'Authorization' => 'Bearer '.$accessToken
197
+ ),
198
+
199
+ )
200
+ );
201
+ if(!is_wp_error($response)) {
202
+ if(200 == wp_remote_retrieve_response_code($response)) {
203
+ $responseBody = json_decode($response['body']);
204
+ if(json_last_error() == JSON_ERROR_NONE) {
205
+ $adClients = array();
206
+ if(isset($responseBody->items) && (count($responseBody->items) > 0)) {
207
+ foreach($responseBody->items as $adClient) {
208
+ $adClients[] = array('productCode' => $adClient->productCode, 'id' => $adClient->id);
209
+ }
210
+ }
211
+ if(count($adClients) > 0) {
212
+ return $adClients;
213
+ }
214
+ return false;
215
+ } else {
216
+ return false;
217
+ }
218
+ } else {
219
+ return false;
220
+ }
221
+ }
222
+ } catch(Exception $ex) {
223
+ return false;
224
+ }
225
+ }
226
+ return false;
227
+ }
228
+
229
+ function wp_insert_google_api_get_ad_units($refresh = false, $accounts = '', $adClients = '', $accessToken = '') {
230
+ $adUnits = false;
231
+ if($refresh == false) {
232
+ $adUnits = get_transient('wp_insert_google_api_ad_units');
233
+ }
234
+ if(($adUnits === false) || ($adUnits == '')) {
235
+ $adUnits = array();
236
+ if($accessToken == '') {
237
+ $accessToken = wp_insert_google_api_get_access_token();
238
+ }
239
+ if($accessToken != false) {
240
+ if($accounts == '') {
241
+ $accounts = wp_insert_google_api_get_accounts($accessToken);
242
+ if($accounts == false || (!is_array($accounts))) {
243
+ return false;
244
+ }
245
+ }
246
+ foreach($accounts as $account) {
247
+ if($adClients == '') {
248
+ $adClients = wp_insert_google_api_get_adclients($account['id'], $accessToken);
249
+ if(($adClients == false) || (!is_array($adClients))) {
250
+ return false;
251
+ }
252
+ }
253
+ try {
254
+ foreach($adClients as $adClient) {
255
+ $response = wp_remote_get(
256
+ 'https://www.googleapis.com/adsense/v1.4/accounts/'.$account['id'].'/adclients/'.$adClient['id'].'/adunits',
257
+ array(
258
+ 'timeout' => 15,
259
+ 'headers' => array(
260
+ 'Content-Type' => 'application/x-www-form-urlencoded',
261
+ 'Authorization' => 'Bearer '.$accessToken
262
+ ),
263
+
264
+ )
265
+ );
266
+ if(!is_wp_error($response)) {
267
+ if(200 == wp_remote_retrieve_response_code($response)) {
268
+ $responseBody = json_decode($response['body']);
269
+ if(json_last_error() == JSON_ERROR_NONE) {
270
+ if(isset($responseBody->items) && (count($responseBody->items) > 0)) {
271
+ foreach($responseBody->items as $adUnit) {
272
+ $adUnits[] = array(
273
+ 'accountID' => $account['id'],
274
+ 'code' => $adUnit->code,
275
+ 'id' => $adUnit->id,
276
+ 'kind' => $adUnit->kind,
277
+ 'name' => $adUnit->name,
278
+ 'status' => $adUnit->status
279
+ );
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+ }
286
+ } catch(Exception $ex) {
287
+ return false;
288
+ }
289
+ }
290
+ if(count($adUnits) > 0) {
291
+ delete_transient('wp_insert_google_api_ad_units');
292
+ set_transient('wp_insert_google_api_ad_units', $adUnits, WEEK_IN_SECONDS);
293
+ return $adUnits;
294
+ } else {
295
+ return false;
296
+ }
297
+ }
298
+ return false;
299
+ }
300
+ return $adUnits;
301
+ }
302
+
303
+ function wp_insert_google_api_get_revenue_data($accountID, $startDate, $endDate, $accessToken = '') {
304
+ if($accessToken == '') {
305
+ $accessToken = wp_insert_google_api_get_access_token();
306
+ }
307
+ if($accessToken != false) {
308
+ try {
309
+ $response = wp_remote_get(
310
+ 'https://www.googleapis.com/adsense/v1.4/accounts/'.$accountID.'/reports?dimension=DATE&metric=EARNINGS&startDate='.$startDate.'&endDate='.$endDate,
311
+ array(
312
+ 'timeout' => 15,
313
+ 'headers' => array(
314
+ 'Content-Type' => 'application/x-www-form-urlencoded',
315
+ 'Authorization' => 'Bearer '.$accessToken
316
+ ),
317
+
318
+ )
319
+ );
320
+ if(!is_wp_error($response)) {
321
+ if(200 == wp_remote_retrieve_response_code($response)) {
322
+ $responseBody = json_decode($response['body']);
323
+ if(json_last_error() == JSON_ERROR_NONE) {
324
+ if(isset($responseBody->totals[1]) && is_numeric($responseBody->totals[1]) && isset($responseBody->headers) && isset($responseBody->headers[1]->currency) && isset($responseBody->rows) && (count($responseBody->rows) > 0)) {
325
+ $report = array();
326
+ foreach($responseBody->rows as $row) {
327
+ $report[] = array(
328
+ 'date' => $row[0],
329
+ 'revenue' => floatval($row[1])
330
+ );
331
+ }
332
+
333
+ return array(
334
+ 'revenue' => array(
335
+ 'revenue' => floatval($responseBody->totals[1]),
336
+ 'currency' => $responseBody->headers[1]->currency
337
+ ),
338
+ 'report' => $report
339
+ );
340
+ }
341
+ return false;
342
+ } else {
343
+ return false;
344
+ }
345
+ } else {
346
+ return false;
347
+ }
348
+ }
349
+ } catch(Exception $ex) {
350
+ return false;
351
+ }
352
+ }
353
+ return false;
354
+ }
355
+
356
+ function wp_insert_google_api_get_adunit_revenue_data($adUnitID, $accountID, $startDate, $endDate, $accessToken = '') {
357
+ if($accessToken == '') {
358
+ $accessToken = wp_insert_google_api_get_access_token();
359
+ }
360
+ if($accessToken != false) {
361
+ try {
362
+ $response = wp_remote_get(
363
+ 'https://www.googleapis.com/adsense/v1.4/accounts/'.$accountID.'/reports?dimension=AD_UNIT_ID&dimension=DATE&metric=EARNINGS&metric=IMPRESSIONS&metric=CLICKS&startDate='.$startDate.'&endDate='.$endDate,
364
+ array(
365
+ 'timeout' => 15,
366
+ 'headers' => array(
367
+ 'Content-Type' => 'application/x-www-form-urlencoded',
368
+ 'Authorization' => 'Bearer '.$accessToken
369
+ ),
370
+
371
+ )
372
+ );
373
+ if(!is_wp_error($response)) {
374
+ if(200 == wp_remote_retrieve_response_code($response)) {
375
+ $responseBody = json_decode($response['body']);
376
+ if(json_last_error() == JSON_ERROR_NONE) {
377
+ if(isset($responseBody->headers) && isset($responseBody->headers[2]->currency) && isset($responseBody->rows) && (count($responseBody->rows) > 0)) {
378
+ $report = array();
379
+ foreach($responseBody->rows as $row) {
380
+ if($row[0] == $adUnitID) {
381
+ $report[] = array(
382
+ 'date' => $row[1],
383
+ 'earnings' => floatval($row[2]),
384
+ 'impressions' => $row[3],
385
+ 'clicks' => $row[4]
386
+ );
387
+ }
388
+ }
389
+ return array(
390
+ 'currency' => $responseBody->headers[2]->currency,
391
+ 'report' => $report
392
+ );
393
+ }
394
+ return false;
395
+ } else {
396
+ return false;
397
+ }
398
+ } else {
399
+ return false;
400
+ }
401
+ }
402
+ } catch(Exception $ex) {
403
+ return false;
404
+ }
405
+ }
406
+ return false;
407
+ }
408
+ ?>
includes/modules/general/google/css/module.css ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wp-insert .plugin-card.google-card {
2
+ position: relative;
3
+ }
4
+
5
+ .wp-insert .plugin-card.google-card .plugin-card-top {
6
+ padding-bottom: 100px;
7
+ }
8
+
9
+ .wp-insert .google-card .plugin-card-bottom {
10
+ /*bottom: 0;
11
+ left: 0;
12
+ right: 0;
13
+ position: absolute;*/
14
+ }
15
+
16
+ .google-card .plugin-card-top {
17
+ padding: 0;
18
+ }
19
+
20
+ .google-card .plugin-card-top h4 {
21
+ color: #000;
22
+ font-size: 14px;
23
+ font-weight: 600;
24
+ line-height: 18px;
25
+ margin: 0;
26
+ }
27
+
28
+ .google-card .plugin-card-top .plugin-card-top-header {
29
+ border-bottom: 1px solid #eee;
30
+ padding: 5px 10px;
31
+ }
32
+
33
+ .google-card .plugin-card-top .plugin-card-top-content {
34
+ padding: 0 10px 5px;
35
+ font-family: arial;
36
+ font-size: 13px;
37
+ line-height: 18px;
38
+ color: #444444;
39
+ }
40
+
41
+ .google-card .plugin-card-top .plugin-card-top-content p {
42
+ font-family: arial;
43
+ font-size: 13px;
44
+ line-height: 18px;
45
+ color: #444444;
46
+ }
47
+
48
+
49
+ .google-card .plugin-card-top .plugin-card-top-content p.strong {
50
+ color: #000;
51
+ font-size: 15px;
52
+ }
53
+
54
+ .google-card .plugin-card-top .plugin-card-top-content ul {
55
+ margin: 10px 0 10px 15px;
56
+ padding: 0 0 0 15px;
57
+ }
58
+
59
+ .google-card .plugin-card-top .plugin-card-top-content ul li {
60
+ list-style-type: disc;
61
+ margin: 0;
62
+ padding: 0 0 0 7px;
63
+ list-style-position: outside;
64
+ }
65
+
66
+ .google-card .plugin-card-bottom {
67
+ text-align: right;
68
+ padding: 24px 20px;
69
+ }
70
+
71
+ .google-card .plugin-card-bottom .button {
72
+ height: 32px;
73
+ line-height: 28px;
74
+ padding: 0 15px;
75
+ margin: 5px 0;
76
+ }
77
+
78
+ .google-card .plugin-card-bottom .button#wp_insert_google_signup {
79
+ margin: 5px 0 5px 15px;
80
+ }
81
+
82
+ .google-card .plugin-card-bottom span {
83
+ display: inline;
84
+ float: left;
85
+ font-size: 13px;
86
+ text-align: left;
87
+ width: calc(100% - 200px);
88
+ font-family: arial;
89
+ line-height: 18px;
90
+ }
91
+
92
+ p.googleError {
93
+ font-weight: bold;
94
+ color: #fd5740;
95
+ }
96
+
97
+ .google-card #wp_insert_google_earnings_wrapper {
98
+ margin-top: 50px;
99
+ }
100
+
101
+ .google-card #wp_insert_google_earnings_wrapper #wp_insert_google_earnings {
102
+ float: left;
103
+ width: calc(100% - 348px);
104
+ margin-top: 38px;
105
+ min-width: 150px;
106
+ margin-bottom: 15px;
107
+ }
108
+
109
+ @media only screen and (max-width: 1256px) {
110
+ .google-card #wp_insert_google_earnings_wrapper {
111
+ margin-top: 0;
112
+ }
113
+
114
+ .google-card #wp_insert_google_earnings_wrapper #wp_insert_google_earnings {
115
+ margin-top: 0;
116
+ }
117
+ }
118
+
119
+ .google-card #wp_insert_google_earnings_wrapper #wp_insert_google_earnings #wp_insert_google_earnings_label {
120
+ color: rgb(35, 40, 45);
121
+ display: block;
122
+ font-size: 14px;
123
+ line-height: 18px;
124
+ font-family: Arial;
125
+ }
126
+
127
+ .google-card #wp_insert_google_earnings_wrapper #wp_insert_google_earnings #wp_insert_google_earnings_value {
128
+ color: rgb(35, 40, 45);
129
+ display: block;
130
+ font-size: 32px;
131
+ font-weight: bold;
132
+ line-height: 44px;
133
+ font-family: Arial;
134
+ }
135
+
136
+ .google-card #wp_insert_google_earnings_wrapper #wp_insert_google_chart_wrapper {
137
+ float: right;
138
+ height: 139px;
139
+ width: 348px;
140
+ max-width: 100%;
141
+ }
142
+
143
+ .google-card #wp_insert_google_earnings_wrapper #wp_insert_google_chart_wrapper canvas {
144
+ border: 1px solid #ddd
145
+ }
146
+
147
+ .wp_insert_google_login_error {
148
+ color: #ff0000;
149
+ font-size: 10px;
150
+ margin: -10px 0 0;
151
+ }
152
+
153
+ .google-card #wp_insert_google_ad_units_wrapper {
154
+ border-top: 1px solid #dedede;
155
+ margin-top: 15px;
156
+ text-align: left;
157
+ }
158
+
159
+ .google-card #wp_insert_google_ad_units_wrapper p {
160
+ }
161
+
162
+ .google-card #wp_insert_google_ad_units_wrapper p .wp_insert_ad_unit_title {
163
+ }
164
+
165
+ .google-card #wp_insert_google_ad_units_wrapper p span {
166
+ display: inline-block;
167
+ width: 20px;
168
+ font-size: 20px;
169
+ font-family: dashicons;
170
+ line-height: 1;
171
+ }
172
+
173
+ .google-card #wp_insert_google_ad_units_wrapper #wp_insert_google_inactive_ad_units {
174
+ height: 16px;
175
+ position: relative;
176
+ overflow: hidden;
177
+ }
178
+
179
+ .google-card #wp_insert_google_ad_units_wrapper #wp_insert_google_inactive_ad_units.expanded {
180
+ overflow: visible;
181
+ height: auto;
182
+ }
183
+
184
+ .google-card #wp_insert_google_ad_units_wrapper #wp_insert_google_inactive_ad_units #wp_insert_google_inactive_ad_units_button {
185
+ padding: 0 16px 0 0;
186
+ border: none;
187
+ text-align: right;
188
+ font-size: 11px;
189
+ cursor: pointer;
190
+ }
191
+
192
+ .google-card #wp_insert_google_ad_units_wrapper #wp_insert_google_inactive_ad_units #wp_insert_google_inactive_ad_units_button span.dashicons {
193
+ position: absolute;
194
+ right: 0;
195
+ cursor: pointer;
196
+ top: -1px;
197
+ }
includes/modules/general/google/functions.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Begin Login / Authorization Form */
3
+ add_action('wp_ajax_wp_insert_google_login_form_get_content', 'wp_insert_google_login_form_get_content');
4
+ function wp_insert_google_login_form_get_content() {
5
+ check_ajax_referer('wp-insert', 'wp_insert_nonce');
6
+ echo '<div class="wp_insert_popup_content_wrapper">';
7
+ echo '<div class="wp_insert_google_loginform_wrapper_step_1">';
8
+ $authenticationData = get_option('wp_insert_google_api_authentication_data', true);
9
+ $control = new smartlogixControls();
10
+
11
+ $clientId = '';
12
+ if(isset($authenticationData) && is_array($authenticationData) && ($authenticationData['clientId'] != '')) {
13
+ $clientId = $authenticationData['clientId'];
14
+ }
15
+ $control->add_control(array('type' => 'text', 'id' => 'wp_insert_google_login_client_id', 'name' => 'wp_insert_google_login_client_id', 'label' => '', 'value' => $clientId, 'className' => "text ui-widget-content ui-corner-all widefat"));
16
+ $control->create_section('Client ID : xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com');
17
+ $controlClientID = $control->HTML;
18
+ $control->clear_controls();
19
+
20
+ $clientSecret = '';
21
+ if(isset($authenticationData) && is_array($authenticationData) && ($authenticationData['clientSecret'] != '')) {
22
+ $clientSecret = $authenticationData['clientSecret'];
23
+ }
24
+ $control->add_control(array('type' => 'text', 'id' => 'wp_insert_google_login_client_secret', 'name' => 'wp_insert_google_login_client_secret', 'label' => '', 'value' => $clientSecret, 'className' => "text ui-widget-content ui-corner-all widefat"));
25
+ $control->create_section('Client Secret : xxxxxxxxxxxxxxxxxxxxxxxx');
26
+ $controlClientSecret = $control->HTML;
27
+ $control->clear_controls();
28
+
29
+ $control->HTML .= '<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" role="button" onclick="wp_insert_google_login_get_auth_code()">';
30
+ $control->HTML .= '<span class="ui-button-text">Get Authorization Code</span>';
31
+ $control->HTML .= '</button>';
32
+ $control->create_section('Get Authorization Code');
33
+ $controlAuthButton = $control->HTML;
34
+ $control->clear_controls();
35
+
36
+ $control->add_control(array('type' => 'text', 'id' => 'wp_insert_google_login_auth_code', 'name' => 'wp_insert_google_login_auth_code', 'label' => '', 'value' => '', 'className' => "text ui-widget-content ui-corner-all widefat"));
37
+ $control->create_section('Auth Code : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
38
+ $controlAuthCode = $control->HTML;
39
+ $control->clear_controls();
40
+
41
+ $control->HTML .= '<ol>';
42
+ $control->HTML .= '<li>Go to the Google Developers Console at <a href="https://console.developers.google.com">https://console.developers.google.com.</a></li>';
43
+ $control->HTML .= '<li>If you have not created a project yet, choose <b>Select a project</b> from the menu bar, and then choose <b>Create</b> a project.<br /><small>(Returning users can go straight to step 14)</small></li>';
44
+ $control->HTML .= '<li>Enter <b>Wp-Insert</b> as the project name and click on the <b>Create</b> button</li>';
45
+ $control->HTML .= '<li>Wait for the project to be created and select <b>Wp-Insert</b> as the current project</li>';
46
+ $control->HTML .= '<li>Click on <b>ENABLE APIS AND SERVICES</b></li>';
47
+ $control->HTML .= '<li>Search for <b>adsense</b> and click on / select <b>AdSense Management API</b> and then click on <b>Enable</b></li>';
48
+ $control->HTML .= '<li>Click on <b>Create credentials</b></li>';
49
+ $control->HTML .= '<li>Under <b>Where will you be calling the API from?</b>; Select <b>Other UI (e.g. Windows, CLI tool)</b></li>';
50
+ $control->HTML .= '<li>Under <b>What data will you be accessing?</b>; Select <b>User data</b></li>';
51
+ $control->HTML .= '<li>Click on <b>What credentials do I need?</b></li>';
52
+ $control->HTML .= '<li>Under <b>Create an OAuth 2.0 client ID</b> Enter the name as <b>Wp-Insert</b></li>';
53
+ $control->HTML .= '<li>Under <b>Set up the OAuth 2.0 consent screen</b> select your email address and enter the <b>Product name shown to users</b> as <b>Wp-Insert</b></li>';
54
+ $control->HTML .= '<li>Click on <b>I will do this later</b> or <b>Done</b></li>';
55
+ $control->HTML .= '<li>In the new screen under <b>OAuth 2.0 client IDs</b> click on <b>Wp-Insert</b></li>';
56
+ $control->HTML .= '<li>';
57
+ $control->HTML .= 'Copy <b>Client ID</b> and paste it below';
58
+ $control->HTML .= $controlClientID;
59
+ $control->HTML .= '</li>';
60
+ $control->HTML .= '<li>';
61
+ $control->HTML .= 'Copy <b>Client Secret</b> and paste it below';
62
+ $control->HTML .= $controlClientSecret;
63
+ $control->HTML .= '</li>';
64
+ $control->HTML .= '<li>You can now close Google Developers Console</li>';
65
+ $control->HTML .= '<li>';
66
+ $control->HTML .= 'Click <b>Get Authorization Code</b> button below<br />';
67
+ $control->HTML .= $controlAuthButton;
68
+ $control->HTML .= '</li>';
69
+ $control->HTML .= '<li>';
70
+ $control->HTML .= 'Copy <b>Authorization Code</b> and paste it below';
71
+ $control->HTML .= $controlAuthCode;
72
+ $control->HTML .= '</li>';
73
+ $control->HTML .= '</ol>';
74
+ $control->create_section('Please follow the steps below to connect your Adsense account.');
75
+ echo $control->HTML;
76
+ echo '</div>';
77
+ echo '<script type="text/javascript">';
78
+ echo $control->JS;
79
+ echo 'jQuery(".ui-dialog-buttonset").find("button").first().find("span:nth-child(2)").hide().after("<span class=\'ui-button-text\'>Login / Authorize</span>");';
80
+ echo 'jQuery(".ui-dialog-buttonset").find("button").first().find("span:nth-child(1)").attr("class", "ui-button-icon-primary ui-icon ui-icon-key");';
81
+ echo '</script>';
82
+ echo '</div>';
83
+ die();
84
+ }
85
+
86
+ add_action('wp_ajax_wp_insert_google_login_generate_auth_url', 'wp_insert_google_login_generate_auth_url');
87
+ function wp_insert_google_login_generate_auth_url() {
88
+ check_ajax_referer('wp-insert', 'wp_insert_nonce');
89
+ if(isset($_POST['wp_insert_google_login_client_id']) && ($_POST['wp_insert_google_login_client_id'] != '')) {
90
+ $wp_insert_google_api_get_auth_url = wp_insert_google_api_get_auth_url($_POST['wp_insert_google_login_client_id']);
91
+ if(isset($wp_insert_google_api_get_auth_url) && ($wp_insert_google_api_get_auth_url != '')) {
92
+ echo '###SUCCESS###';
93
+ echo $wp_insert_google_api_get_auth_url;
94
+ }
95
+ }
96
+ die();
97
+ }
98
+
99
+ add_action('wp_ajax_wp_insert_google_login_form_save_action', 'wp_insert_google_login_form_save_action');
100
+ function wp_insert_google_login_form_save_action() {
101
+ check_ajax_referer('wp-insert', 'wp_insert_nonce');
102
+ if(isset($_POST['wp_insert_google_login_client_id']) && ($_POST['wp_insert_google_login_client_id'] != '') && isset($_POST['wp_insert_google_login_client_secret']) && ($_POST['wp_insert_google_login_client_secret'] != '') && isset($_POST['wp_insert_google_login_auth_code']) && ($_POST['wp_insert_google_login_auth_code'] != '')) {
103
+ $authenticationStatus = wp_insert_google_api_set_access_token($_POST['wp_insert_google_login_client_id'], $_POST['wp_insert_google_login_client_secret'], $_POST['wp_insert_google_login_auth_code']);
104
+ if(isset($authenticationStatus) && ($authenticationStatus == true)) {
105
+ echo '###SUCCESS###';
106
+ wp_insert_google_plugin_card_content(true, true);
107
+ } else {
108
+ echo '<p class="wp_insert_google_login_error">Login Error:<br />Please check your credentials and try again later!'.'</p>';
109
+ }
110
+ }
111
+ die();
112
+ }
113
+ /* End Login / Authorization Form */
114
+
115
+ /* Begin Logout / De-Authorization */
116
+ add_action('wp_ajax_wp_insert_google_logout_action', 'wp_insert_google_logout_action');
117
+ function wp_insert_google_logout_action() {
118
+ check_ajax_referer('wp-insert', 'wp_insert_nonce');
119
+ wp_insert_google_api_revoke_access_token();
120
+ echo '###SUCCESS###';
121
+ wp_insert_google_plugin_card_content(false, true);
122
+ die();
123
+ }
124
+ /* End Logout / De-Authorization */
125
+
126
+ /* Begin Ad Unit Stats */
127
+ add_action('wp_ajax_wp_insert_google_adunit_get_stats', 'wp_insert_google_adunit_get_stats');
128
+ function wp_insert_google_adunit_get_stats() {
129
+ check_ajax_referer('wp-insert', 'wp_insert_nonce');
130
+ if(isset($_POST['wp_insert_google_account_id']) && ($_POST['wp_insert_google_account_id'] != '') && isset($_POST['wp_insert_google_adunit_id']) && ($_POST['wp_insert_google_adunit_id'] != '')) {
131
+ $wp_insert_google_account_id = $_POST['wp_insert_google_account_id'];
132
+ $wp_insert_google_adunit_id = $_POST['wp_insert_google_adunit_id'];
133
+
134
+ $revenueData = wp_insert_google_api_get_adunit_revenue_data($wp_insert_google_adunit_id, $wp_insert_google_account_id, date('Y-m-d', strtotime('-3 month')), date('Y-m-d'), $accessToken);
135
+ //echo '<pre>'; print_r($revenueData); echo '</pre>';
136
+ if(isset($revenueData) && is_array($revenueData)) {
137
+ echo '###SUCCESS###';
138
+ echo '<div id="wp_insert_google_adunit_chart_wrapper">';
139
+ echo '<canvas id="wp_insert_google_adunit_chart"></canvas>';
140
+ echo '<textarea id="wp_insert_google_adunit_chart_data" style="display: none;">[';
141
+ if(isset($revenueData['report']) && is_array($revenueData['report']) & (count($revenueData['report']) > 0)) {
142
+ $isFirstItem = true;
143
+ foreach($revenueData['report'] as $reportData) {
144
+ if(!$isFirstItem) {
145
+ echo ',';
146
+ }
147
+ $date = DateTime::createFromFormat('Y-m-d', $reportData['date']);
148
+ echo '{"x": "'.$date->format('m/d/Y').'", "y": "'.$reportData['earnings'].'"}';
149
+ $isFirstItem = false;;
150
+ }
151
+ } else {
152
+ echo '{"x": "'.date('m/d/Y').'", "y": "0.00"}';
153
+ }
154
+ echo ']</textarea>';
155
+ echo '</div>';
156
+ }
157
+ }
158
+ die();
159
+ }
160
+ /* End Ad Unit Stats */
161
+ ?>
includes/modules/general/google/js/module.js ADDED
@@ -0,0 +1,335 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function() {
2
+ wp_insert_google_login_handler();
3
+ wp_insert_google_logout_handler();
4
+ wp_insert_google_chart_draw();
5
+ wp_insert_google_get_ad_units();
6
+ });
7
+
8
+ function wp_insert_google_login_handler() {
9
+ wp_insert_click_handler(
10
+ 'wp_insert_google_login',
11
+ 'Adsense by Google: Login / Authorize',
12
+ jQuery("body").width() * 0.8,
13
+ jQuery("body").height() * 0.8,
14
+ function() {
15
+ jQuery('.ui-dialog-buttonset').find('button').first().unbind('click').click(function() {
16
+ if((jQuery('#wp_insert_google_login_client_id').val() != '') && (jQuery('#wp_insert_google_login_client_secret').val() != '') && (jQuery('#wp_insert_google_login_auth_code').val() != '')) {
17
+ jQuery('.ui-dialog-buttonset').find('button').first().button('disable');
18
+ jQuery('.ui-dialog-buttonset').find('button').last().button('disable');
19
+ jQuery('.ui-dialog-titlebar').find('button').last().button('disable');
20
+ var wp_insert_google_login_client_id = jQuery.trim(jQuery('#wp_insert_google_login_client_id').val());
21
+ var wp_insert_google_login_client_secret = jQuery.trim(jQuery('#wp_insert_google_login_client_secret').val());
22
+ var wp_insert_google_login_auth_code = jQuery.trim(jQuery('#wp_insert_google_login_auth_code').val());
23
+ jQuery('.ui-dialog-content').html('<div class="wp_insert_ajaxloader"></div>');
24
+ jQuery('.wp_insert_ajaxloader').show();
25
+ jQuery.post(
26
+ jQuery('#wp_insert_admin_ajax').val(), {
27
+ 'action': 'wp_insert_google_login_form_save_action',
28
+ 'wp_insert_nonce': jQuery('#wp_insert_nonce').val(),
29
+ 'wp_insert_google_login_client_id': wp_insert_google_login_client_id,
30
+ 'wp_insert_google_login_client_secret': wp_insert_google_login_client_secret,
31
+ 'wp_insert_google_login_auth_code': wp_insert_google_login_auth_code,
32
+ }, function(response) {
33
+ if(response.indexOf('###SUCCESS###') !== -1) {
34
+ jQuery('.google-card .plugin-card-bottom, .google-card .plugin-card-top-content').animate({'opacity': 0}, 1000);
35
+ jQuery('.google-card').html(response.replace('###SUCCESS###', ''));
36
+ wp_insert_google_chart_draw();
37
+ wp_insert_google_get_ad_units();
38
+ wp_insert_google_logout_handler();
39
+ jQuery(window).resize();
40
+ jQuery('.google-card .plugin-card-bottom, .google-card .plugin-card-top-content').animate({'opacity': 1}, 1000);
41
+ jQuery('.ui-dialog-titlebar').find('button').last().button('enable').click();
42
+ } else {
43
+ jQuery('.ui-dialog-buttonset').find('button').first().button('enable');
44
+ jQuery('.ui-dialog-buttonset').find('button').last().button('enable');
45
+ jQuery('.ui-dialog-titlebar').find('button').last().button('enable');
46
+ jQuery('.ui-dialog-content').html(response);
47
+ }
48
+ }
49
+ );
50
+ } else {
51
+ jQuery('#wp_insert_google_login_client_id').css('border-color', '#dddddd');
52
+ jQuery('#wp_insert_google_login_client_secret').css('border-color', '#dddddd');
53
+ jQuery('#wp_insert_google_login_auth_code').css('border-color', '#dddddd');
54
+ if(jQuery('#wp_insert_google_login_client_id').val() == '') {
55
+ jQuery('#wp_insert_google_login_client_id').css('border-color', '#ff0000');
56
+ }
57
+ if(jQuery('#wp_insert_google_login_client_secret').val() == '') {
58
+ jQuery('#wp_insert_google_login_client_secret').css('border-color', '#ff0000');
59
+ }
60
+ if(jQuery('#wp_insert_google_login_auth_code').val() == '') {
61
+ jQuery('#wp_insert_google_login_auth_code').css('border-color', '#ff0000');
62
+ }
63
+ }
64
+ });
65
+ },
66
+ function() { },
67
+ function() { }
68
+ );
69
+ }
70
+
71
+ function wp_insert_google_login_get_auth_code() {
72
+ var wp_insert_google_login_client_id = jQuery.trim(jQuery('#wp_insert_google_login_client_id').val());
73
+ if(wp_insert_google_login_client_id != '') {
74
+ jQuery('#wp_insert_google_login_client_id').css('border-color', '#dddddd');
75
+ jQuery.post(
76
+ jQuery('#wp_insert_admin_ajax').val(), {
77
+ 'action': 'wp_insert_google_login_generate_auth_url',
78
+ 'wp_insert_nonce': jQuery('#wp_insert_nonce').val(),
79
+ 'wp_insert_google_login_client_id': jQuery('#wp_insert_google_login_client_id').val(),
80
+ }, function(response) {
81
+ if(response.indexOf('###SUCCESS###') !== -1) {
82
+ var gauth = window.open(response.replace('###SUCCESS###', ''), 'Authenticate', 'width=480, height=600');
83
+ gauth.focus();
84
+ }
85
+ }
86
+ );
87
+ } else {
88
+ jQuery('#wp_insert_google_login_client_id').css('border-color', '#ff0000');
89
+ }
90
+ }
91
+
92
+ function wp_insert_google_logout_handler() {
93
+ jQuery('#wp_insert_google_logout').click(function() {
94
+ jQuery.post(
95
+ jQuery('#wp_insert_admin_ajax').val(), {
96
+ 'action': 'wp_insert_google_logout_action',
97
+ 'wp_insert_nonce': jQuery('#wp_insert_nonce').val(),
98
+ }, function(response) {
99
+ if(response.indexOf('###SUCCESS###') !== -1) {
100
+ jQuery('.google-card').html(response.replace('###SUCCESS###', ''));
101
+ wp_insert_google_login_handler();
102
+ jQuery(window).resize();
103
+ }
104
+ jQuery('.google-card .plugin-card-bottom, .google-card .plugin-card-top-content').animate({'opacity': 1}, 1000);
105
+ }
106
+ );
107
+ jQuery('.google-card .plugin-card-bottom, .google-card .plugin-card-top-content').animate({'opacity': 0}, 1000);
108
+
109
+ });
110
+ }
111
+
112
+ function wp_insert_google_chart_draw() {
113
+ if(jQuery('#wp_insert_google_earnings_wrapper').length) {
114
+ jQuery.post(
115
+ jQuery('#wp_insert_admin_ajax').val(), {
116
+ 'action': 'wp_insert_google_get_chart',
117
+ 'wp_insert_nonce': jQuery('#wp_insert_nonce').val(),
118
+ }, function(response) {
119
+ if(response.indexOf('###SUCCESS###') !== -1) {
120
+ jQuery('#wp_insert_google_earnings_wrapper').html(response.replace('###SUCCESS###', ''));
121
+ if(jQuery('#wp_insert_google_chart_data').length) {
122
+ var ctx = document.getElementById("myChart");
123
+ var wp_insert_google_chart = new Chart(jQuery('#wp_insert_google_chart'), {
124
+ type: 'line',
125
+ data: {
126
+ datasets: [{
127
+ data: JSON.parse(jQuery('#wp_insert_google_chart_data').val()),
128
+ backgroundColor: '#EDF5FB',
129
+ borderColor: '#186EAE',/*E8EBEF*/
130
+ borderWidth: 1
131
+ }]
132
+ },
133
+ options: {
134
+ title: {
135
+ display: false,
136
+ backgroundColor: '#EDF5FB'
137
+ },
138
+ legend: {
139
+ display: false,
140
+ },
141
+ scales: {
142
+ xAxes: [{
143
+ type: "time",
144
+ display: true,
145
+ scaleLabel: {
146
+ display: false
147
+ },
148
+ gridLines: {
149
+ display: false,
150
+ drawTicks: false
151
+ },
152
+ ticks: {
153
+ display: false
154
+ }
155
+ }],
156
+ yAxes: [{
157
+ display: true,
158
+ scaleLabel: {
159
+ display: false
160
+ },
161
+ gridLines: {
162
+ display: true,
163
+ drawTicks: false
164
+ },
165
+ ticks: {
166
+ display: false
167
+ }
168
+ }]
169
+ },
170
+ tooltips: {
171
+ displayColors: false,
172
+ callbacks: {
173
+ label: function(tooltipItem, data) {
174
+ return '$ '+parseFloat(tooltipItem.yLabel).toFixed(2);
175
+ },
176
+ title: function(tooltipItem, data) {
177
+ var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
178
+ var dateParts = tooltipItem[0].xLabel.split('/');
179
+ var date = new Date(dateParts[2], dateParts[0]-1, dateParts[1]);
180
+ return monthNames[date.getMonth()]+' '+date.getDate();
181
+ }
182
+ }
183
+ }
184
+ }
185
+ });
186
+ }
187
+ } else {
188
+ jQuery('#wp_insert_google_earnings_wrapper').parent().html(response);
189
+ }
190
+ jQuery(window).resize();
191
+ }
192
+ );
193
+ }
194
+ }
195
+
196
+ function wp_insert_google_get_ad_units() {
197
+ if(jQuery('#wp_insert_google_ad_units_wrapper').length) {
198
+ jQuery.post(
199
+ jQuery('#wp_insert_admin_ajax').val(), {
200
+ 'action': 'wp_insert_google_get_ad_units',
201
+ 'wp_insert_nonce': jQuery('#wp_insert_nonce').val(),
202
+ }, function(response) {
203
+ if(response.indexOf('###SUCCESS###') !== -1) {
204
+ jQuery('#wp_insert_google_ad_units_wrapper').html(response.replace('###SUCCESS###', ''));
205
+ } else {
206
+ jQuery('#wp_insert_google_ad_units_wrapper').parent().html(response);
207
+ }
208
+ jQuery(window).resize();
209
+ }
210
+ );
211
+ }
212
+ }
213
+
214
+ function wp_insert_google_inactive_ad_units_toggle() {
215
+ if(jQuery('#wp_insert_google_inactive_ad_units').height() == '16') {
216
+ jQuery('#wp_insert_google_inactive_ad_units').addClass('expanded');
217
+ jQuery('#wp_insert_google_inactive_ad_units_button').html('Hide Inactive Ad Units<span class="dashicons dashicons-arrow-up" title="Hide Inactive Ad Units"></span>');
218
+ } else {
219
+ jQuery('#wp_insert_google_inactive_ad_units').removeClass('expanded');
220
+ jQuery('#wp_insert_google_inactive_ad_units_button').html('Show Inactive Ad Units<span class="dashicons dashicons-arrow-down" title="Show Inactive Ad Units"></span>');
221
+ }
222
+ jQuery(window).resize();
223
+ }
224
+
225
+ function wp_insert_google_adunit_stats_handler(adUnitID, adUnitName, accountID) {
226
+ jQuery('<div id="wp_insert_google_active_adunit_stats_dialog"></div>').html('<div class="wp_insert_ajaxloader"></div>').dialog({
227
+ 'modal': true,
228
+ 'resizable': false,
229
+ 'width': jQuery("body").width() * 0.8,
230
+ 'maxWidth': jQuery("body").width() * 0.8,
231
+ 'maxHeight': jQuery("body").height() * 0.8,
232
+ 'title': adUnitName + ': Performance Stats (Last 3 Months)',
233
+ position: { my: 'center', at: 'center', of: window },
234
+ open: function (event, ui) {
235
+ jQuery('.ui-dialog').css({'z-index': 999999, 'max-width': '90%'});
236
+ jQuery('.ui-widget-overlay').css({'z-index': 999998, 'opacity': 0.8, 'background': '#000000'});
237
+ jQuery.post(
238
+ jQuery('#wp_insert_admin_ajax').val(), {
239
+ 'action': 'wp_insert_google_adunit_get_stats',
240
+ 'wp_insert_nonce': jQuery('#wp_insert_nonce').val(),
241
+ 'wp_insert_google_account_id': accountID,
242
+ 'wp_insert_google_adunit_id': adUnitID
243
+ }, function(response) {
244
+ jQuery('.wp_insert_ajaxloader').hide();
245
+ jQuery('.ui-dialog-content').html(response.replace('###SUCCESS###', ''));
246
+ jQuery('#wp_insert_google_adunit_chart').attr('width', ((jQuery("body").width() * 0.8) - 60));
247
+ jQuery('#wp_insert_google_adunit_chart').attr('height', ((jQuery("body").height() * 0.8) - 150));
248
+ jQuery('.ui-dialog').css({'position': 'fixed'});
249
+ jQuery('#wp_insert_google_active_adunit_stats_dialog').delay(500).dialog({position: { my: 'center', at: 'center', of: window }});
250
+
251
+ if(response.indexOf('###SUCCESS###') !== -1) {
252
+ if(jQuery('#wp_insert_google_adunit_chart_data').length) {
253
+ var ctx = document.getElementById("myChart");
254
+ var wp_insert_google_adunit_chart = new Chart(jQuery('#wp_insert_google_adunit_chart'), {
255
+ type: 'line',
256
+ data: {
257
+ datasets: [{
258
+ data: JSON.parse(jQuery('#wp_insert_google_adunit_chart_data').val()),
259
+ backgroundColor: '#EDF5FB',
260
+ borderColor: '#186EAE',
261
+ borderWidth: 1
262
+ }]
263
+ },
264
+ options: {
265
+ title: {
266
+ display: false,
267
+ backgroundColor: '#EDF5FB'
268
+ },
269
+ legend: {
270
+ display: false,
271
+ },
272
+ scales: {
273
+ xAxes: [{
274
+ type: "time",
275
+ display: true,
276
+ scaleLabel: {
277
+ display: false
278
+ },
279
+ gridLines: {
280
+ display: false,
281
+ drawTicks: false
282
+ },
283
+ ticks: {
284
+ display: false
285
+ }
286
+ }],
287
+ yAxes: [{
288
+ display: true,
289
+ scaleLabel: {
290
+ display: false
291
+ },
292
+ gridLines: {
293
+ display: true,
294
+ drawTicks: false
295
+ },
296
+ ticks: {
297
+ display: false
298
+ }
299
+ }]
300
+ },
301
+ tooltips: {
302
+ displayColors: false,
303
+ callbacks: {
304
+ label: function(tooltipItem, data) {
305
+ return '$ '+parseFloat(tooltipItem.yLabel).toFixed(2);
306
+ },
307
+ title: function(tooltipItem, data) {
308
+ var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
309
+ var dateParts = tooltipItem[0].xLabel.split('/');
310
+ var date = new Date(dateParts[2], dateParts[0]-1, dateParts[1]);
311
+ return monthNames[date.getMonth()]+' '+date.getDate();
312
+ }
313
+ }
314
+ }
315
+ }
316
+ });
317
+ }
318
+ }
319
+ }
320
+ );
321
+ },
322
+ buttons: {
323
+ Cancel: {
324
+ text: 'Close',
325
+ icons: { primary: "ui-icon-cancel" },
326
+ click: function() {
327
+ jQuery(this).dialog('close');
328
+ }
329
+ }
330
+ },
331
+ close: function() {
332
+ jQuery(this).dialog('destroy');
333
+ }
334
+ });
335
+ }
includes/modules/general/google/module.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(dirname(__FILE__).'/functions.php');
3
+ require_once(dirname(__FILE__).'/api-handler.php');
4
+
5
+ /* Begin Add Assets */
6
+ add_action('wp_insert_modules_css', 'wp_insert_module_google_css', 0);
7
+ function wp_insert_module_google_css() {
8
+ wp_register_style('wp-insert-module-google-css', WP_INSERT_URL.'includes/modules/general/google/css/module.css', array('wp-insert-css'), WP_INSERT_VERSION.((WP_INSERT_DEBUG)?rand(0,9999):''));
9
+ wp_enqueue_style('wp-insert-module-google-css');
10
+ }
11
+
12
+ add_action('wp_insert_modules_js', 'wp_insert_module_google_js', 0);
13
+ function wp_insert_module_google_js() {
14
+ wp_register_script('wp-insert-module-google-js', WP_INSERT_URL.'includes/modules/general/google/js/module.js', array('wp-insert-js'), WP_INSERT_VERSION.((WP_INSERT_DEBUG)?rand(0,9999):''));
15
+ wp_enqueue_script('wp-insert-module-google-js');
16
+ }
17
+ /* End Add Assets */
18
+
19
+ /* Begin Add Card in Admin Panel */
20
+ add_action('wp_insert_plugin_card', 'wp_insert_google_plugin_card', 11);
21
+ function wp_insert_google_plugin_card() {
22
+ echo '<div class="plugin-card google-card">';
23
+ if(wp_insert_google_api_get_access_token()) {
24
+ wp_insert_google_plugin_card_content(true);
25
+ } else {
26
+ wp_insert_google_plugin_card_content(false);
27
+ }
28
+ echo '</div>';
29
+ }
30
+
31
+ function wp_insert_google_plugin_card_content($isLoggedin = false, $isAjaxRequest = false) {
32
+ if(!$isLoggedin) {
33
+ echo '<div class="plugin-card-top">';
34
+ echo '<div class="plugin-card-top-header">';
35
+ echo '<h4>Adsense by Google (Optional - Recommended)</h4>';
36
+ echo '</div>';
37
+ echo '<div class="plugin-card-top-content" '.(($isAjaxRequest)?'style="opacity: 0;"':'').'>';
38
+ echo '<p>Connect your Adsense account to Wp-Insert to enable seamless integration and view your Adsense Stats right here</p>';
39
+ echo '<ul>';
40
+ echo '<li>No need to copy and paste Ad codes</li>';
41
+ echo '<li>View stats and earnings in Wp-Insert dashboard</li>';
42
+ echo '<li>Recognize which ads are performing and which are not</li>';
43
+ echo '<li>View Adsense Alerts and Messages in Wp-Insert dashboard</li>';
44
+ echo '<li>Ease of Use</li>';
45
+ echo '</ul>';
46
+ echo '<p>PS : You can continue to use adsense ads without linking your account to Wp-Insert. This feature is just an added convinence.</p>';
47
+
48
+ echo '<pre>';
49
+
50
+ echo '</pre>';
51
+
52
+ echo '</div>';
53
+ echo '</div>';
54
+ echo '<div class="plugin-card-bottom" '.(($isAjaxRequest)?'style="opacity: 0;"':'').'>';
55
+ echo '<a id="wp_insert_google_login" href="javascript:;" class="button button-secondary">Log In / Authorize</a>';
56
+ echo '<a id="wp_insert_google_signup" href="http://google.com/adsense" target="_blank" class="button button-primary">Sign Up</a>';
57
+ echo '</div>';
58
+ } else {
59
+ echo '<div class="plugin-card-top">';
60
+ echo '<div class="plugin-card-top-header">';
61
+ echo '<h4>Adsense by Google (Optional - Recommended)</h4>';
62
+ echo '</div>';
63
+ echo '<div class="plugin-card-top-content" '.(($isAjaxRequest)?'style="opacity: 0;"':'').'>';
64
+ echo '<p>You can see your earnings and stats below.<br />You can use Adsense ad units in supported Ad types without having to copy and paste the Ad code.</p>';
65
+ echo '<div id="wp_insert_google_earnings_wrapper">';
66
+ echo '<div class="wp_insert_ajaxloader"></div>';
67
+ echo '</div>';
68
+ echo '</div>';
69
+ echo '</div>';
70
+ echo '<div class="plugin-card-bottom" '.(($isAjaxRequest)?'style="opacity: 0;"':'').'>';
71
+ echo '<a id="wp_insert_google_dashboard" href="http://google.com/adsense" target="_blank" class="button button-primary alignleft">Publisher Dashboard</a>';
72
+ echo '<a id="wp_insert_google_logout" href="javascript:;" class="button button-secondary">Log Out / Deauthorize</a>';
73
+ echo '<div id="wp_insert_google_ad_units_wrapper">';
74
+ echo '<div class="wp_insert_ajaxloader"></div>';
75
+ echo '</div>';
76
+ echo '</div>';
77
+ }
78
+ }
79
+ add_action('wp_ajax_wp_insert_google_get_ad_units', 'wp_insert_google_get_ad_units');
80
+ function wp_insert_google_get_ad_units() {
81
+ check_ajax_referer('wp-insert', 'wp_insert_nonce');
82
+ $adUnits = wp_insert_google_api_get_ad_units();
83
+ if(is_array($adUnits)) {
84
+ echo '###SUCCESS###';
85
+ echo '<div id="wp_insert_google_active_ad_units">';
86
+ foreach($adUnits as $adUnit) {
87
+ if($adUnit['status'] == 'ACTIVE') {
88
+ echo '<p>';
89
+ echo '<a class="wp_insert_ad_unit_title" title="Ad Unit" onclick="wp_insert_google_adunit_stats_handler(\''.$adUnit['id'].'\', \''.$adUnit['name'].'\', \''.$adUnit['accountID'].'\')" id="wp_insert_google_active_ad_'.$adUnit['id'].'" href="javascript:;">'.$adUnit['name'].'</a>';
90
+ //echo '<span class="dashicons dashicons-no wp_insert_delete_icon" title="Delete Ad Unit"></span>';
91
+ //echo '<span class="dashicons dashicons-format-gallery wp_insert_duplicate_icon" title="Duplicate Ad Unit"></span>';
92
+ echo '</p>';
93
+ }
94
+ }
95
+ echo '</div>';
96
+ /*echo '<div id="wp_insert_google_inactive_ad_units">';
97
+ echo '<p id="wp_insert_google_inactive_ad_units_button" onclick="wp_insert_google_inactive_ad_units_toggle()">Show Inactive Ad Units<span class="dashicons dashicons-arrow-down" title="Show Inactive Ad Units"></span></p>';
98
+ foreach($adUnits as $adUnit) {
99
+ if($adUnit['status'] == 'INACTIVE') {
100
+ echo '<p>';
101
+ echo '<a class="wp_insert_ad_unit_title" title="Ad Unit" id="wp_insert__ad_" href="javascript:;">'.$adUnit['name'].'</a>';
102
+ //echo '<span class="dashicons dashicons-no wp_insert_delete_icon" title="Delete Ad Unit"></span>';
103
+ //echo '<span class="dashicons dashicons-format-gallery wp_insert_duplicate_icon" title="Duplicate Ad Unit"></span>';
104
+ echo '</p>';
105
+ }
106
+ }
107
+ echo '</div>';*/
108
+ }
109
+ die();
110
+ }
111
+
112
+ add_action('wp_ajax_wp_insert_google_get_chart', 'wp_insert_google_get_chart');
113
+ function wp_insert_google_get_chart() {
114
+ check_ajax_referer('wp-insert', 'wp_insert_nonce');
115
+ $accessToken = wp_insert_google_api_get_access_token();
116
+ $accounts = wp_insert_google_api_get_accounts($accessToken);
117
+ if(($accounts != false) && is_array($accounts) && isset($accounts[0]['id'])) {
118
+ $revenueData = wp_insert_google_api_get_revenue_data($accounts[0]['id'], date('Y-m-d', strtotime('-1 month')), date('Y-m-d'), $accessToken);
119
+ }
120
+ if(isset($revenueData) && is_array($revenueData)) {
121
+ echo '###SUCCESS###';
122
+ echo '<div id="wp_insert_google_earnings">';
123
+ echo '<span id="wp_insert_google_earnings_label">Total Earnings</span>';
124
+ echo '<span id="wp_insert_google_earnings_value">'.$revenueData['revenue']['currency'].' '.$revenueData['revenue']['revenue'].'</span>';
125
+ echo '</div>';
126
+ echo '<div id="wp_insert_google_chart_wrapper">';
127
+ echo '<canvas id="wp_insert_google_chart" width="348" height="139"></canvas>';
128
+ echo '<textarea id="wp_insert_google_chart_data" style="display: none;">[';
129
+ if(isset($revenueData['report']) && is_array($revenueData['report']) & (count($revenueData['report']) > 0)) {
130
+ $isFirstItem = true;
131
+ foreach($revenueData['report'] as $reportData) {
132
+ if(!$isFirstItem) {
133
+ echo ',';
134
+ }
135
+ $date = DateTime::createFromFormat('Y-m-d', $reportData['date']);
136
+ echo '{"x": "'.$date->format('m/d/Y').'", "y": "'.$reportData['revenue'].'"}';
137
+ $isFirstItem = false;;
138
+ }
139
+ } else {
140
+ echo '{"x": "'.date('m/d/Y').'", "y": "0.00"}';
141
+ }
142
+ echo ']</textarea>';
143
+ echo '</div>';
144
+ echo '<div class="clear"></div>';
145
+ } else {
146
+ echo '<p class="googleError">There was an error processing your request, our team was notified. Try clearing your browser cache, log out and log in again.</p>';
147
+ echo '<div id="wp_insert_google_earnings_wrapper">';
148
+ echo '<div id="wp_insert_google_earnings">';
149
+ echo '<span id="wp_insert_google_earnings_label">Total Earnings</span>';
150
+ echo '<span id="wp_insert_google_earnings_value"><img src="'.WP_INSERT_URL.'includes/assets/images/no-data.jpg?'.WP_INSERT_VERSION.'"></span>';
151
+ echo '</div>';
152
+ echo '<div id="wp_insert_google_chart_wrapper">';
153
+ echo '<img width="348" height="139" src="'.WP_INSERT_URL.'includes/assets/images/empty-graph.jpg?'.WP_INSERT_VERSION.'">';
154
+ echo '</div>';
155
+ echo '<div class="clear"></div>';
156
+ echo '</div>';
157
+ }
158
+ die();
159
+ }
160
+ /* End Add Card in Admin Panel */
161
+ ?>
includes/modules/general/modules.php CHANGED
@@ -6,5 +6,6 @@ require_once(dirname(__FILE__).'/intheme/module.php');
6
  require_once(dirname(__FILE__).'/pagelevel/module.php');
7
  require_once(dirname(__FILE__).'/trackingcodes/module.php');
8
  require_once(dirname(__FILE__).'/legalpages/module.php');
 
9
  require_once(dirname(__FILE__).'/videointelligence/module.php');
10
  ?>
6
  require_once(dirname(__FILE__).'/pagelevel/module.php');
7
  require_once(dirname(__FILE__).'/trackingcodes/module.php');
8
  require_once(dirname(__FILE__).'/legalpages/module.php');
9
+ //require_once(dirname(__FILE__).'/google/module.php');
10
  require_once(dirname(__FILE__).'/videointelligence/module.php');
11
  ?>
includes/modules/general/videointelligence/functions.php CHANGED
@@ -30,7 +30,7 @@ function wp_insert_vi_login_form_get_content() {
30
  wp_insert_vi_login_form_get_controls();
31
  echo '</div>';
32
  echo '<script type="text/javascript">';
33
- echo $control->JS;
34
  echo 'jQuery(".ui-dialog-buttonset").find("button").first().find("span:nth-child(2)").hide().after("<span class=\'ui-button-text\'>Login</span>");';
35
  echo 'jQuery(".ui-dialog-buttonset").find("button").first().find("span:nth-child(1)").attr("class", "ui-button-icon-primary ui-icon ui-icon-key");';
36
  echo '</script>';
30
  wp_insert_vi_login_form_get_controls();
31
  echo '</div>';
32
  echo '<script type="text/javascript">';
33
+ //echo $control->JS;
34
  echo 'jQuery(".ui-dialog-buttonset").find("button").first().find("span:nth-child(2)").hide().after("<span class=\'ui-button-text\'>Login</span>");';
35
  echo 'jQuery(".ui-dialog-buttonset").find("button").first().find("span:nth-child(1)").attr("class", "ui-button-icon-primary ui-icon ui-icon-key");';
36
  echo '</script>';
includes/modules/general/videointelligence/module.php CHANGED
@@ -45,13 +45,14 @@ function wp_insert_vi_plugin_card_content($isLoggedin = false, $isAjaxRequest =
45
  echo '<li>The video player is customizable to match your site</li>';
46
  echo '</ul>';
47
  echo '<p>You\'ll see video content that is matched to your sites keywords straight away. A few days after activation you’ll begin to receive revenue from advertising served before this video content.</p>';
 
48
  //echo '<p>Watch a <a href="http://demo.vi.ai/ViewsterBlog_Nintendo.html" target="_blank">demo</a> of how <b>vi stories</b> works.</p>';
49
  echo '</div>';
50
  echo '</div>';
51
  echo '<div class="plugin-card-bottom" '.(($isAjaxRequest)?'style="opacity: 0;"':'').'>';
52
- echo '<span>By clicking Sign Up button you agree to send current domain, email and affiliate ID to video intelligence.</span>';
53
  echo '<a id="wp_insert_vi_login" href="javascript:;" class="button button-secondary">Log In</a>';
54
- echo '<a id="wp_insert_vi_signup" href="javascript:;" class="button button-primary">Sign Up</a>';
55
  echo '</div>';
56
  } else {
57
  $dashboardURL = wp_insert_vi_api_get_dashboardurl();
@@ -60,7 +61,7 @@ function wp_insert_vi_plugin_card_content($isLoggedin = false, $isAjaxRequest =
60
  echo '<h4>Video content and video advertising – powered by video intelligence</h4>';
61
  echo '</div>';
62
  echo '<div class="plugin-card-top-content" '.(($isAjaxRequest)?'style="opacity: 0;"':'').'>';
63
- echo '<p>Below you can see your current revenues.<br />Don’t see anything? Consult the <a target="_blank" href="https://www.vi.ai/frequently-asked-questions-vi-stories-for-wordpress/?utm_source=WordPress&utm_medium=Plugin%20FAQ&utm_campaign=WP%20Insert">FAQs</a>.</p>';
64
  echo '<div id="wp_insert_vi_earnings_wrapper">';
65
  echo '<div class="wp_insert_ajaxloader"></div>';
66
  echo '</div>';
@@ -82,7 +83,7 @@ function wp_insert_vi_get_chart() {
82
  echo '###SUCCESS###';
83
  echo '<div id="wp_insert_vi_earnings">';
84
  echo '<span id="wp_insert_vi_earnings_label">Total Earnings</span>';
85
- echo '<span id="wp_insert_vi_earnings_value">$'.$revenueData['netRevenue'].'</span>';
86
  echo '</div>';
87
  echo '<div id="wp_insert_vi_chart_wrapper">';
88
  echo '<canvas id="wp_insert_vi_chart" width="348" height="139"></canvas>';
@@ -108,10 +109,10 @@ function wp_insert_vi_get_chart() {
108
  echo '<div id="wp_insert_vi_earnings_wrapper">';
109
  echo '<div id="wp_insert_vi_earnings">';
110
  echo '<span id="wp_insert_vi_earnings_label">Total Earnings</span>';
111
- echo '<span id="wp_insert_vi_earnings_value"><img src="'.WP_INSERT_URL.'includes/assets/images/vi-no-data.jpg?'.WP_INSERT_VERSION.'"></span>';
112
  echo '</div>';
113
  echo '<div id="wp_insert_vi_chart_wrapper">';
114
- echo '<img width="348" height="139" src="'.WP_INSERT_URL.'includes/assets/images/vi-empty-graph.jpg?'.WP_INSERT_VERSION.'">';
115
  echo '</div>';
116
  echo '<div class="clear"></div>';
117
  echo '</div>';
45
  echo '<li>The video player is customizable to match your site</li>';
46
  echo '</ul>';
47
  echo '<p>You\'ll see video content that is matched to your sites keywords straight away. A few days after activation you’ll begin to receive revenue from advertising served before this video content.</p>';
48
+ echo '<p><b>This Panel will be withdrawn from the next version.<br />Existing users will be able to continue using vi ads.</b></p>';
49
  //echo '<p>Watch a <a href="http://demo.vi.ai/ViewsterBlog_Nintendo.html" target="_blank">demo</a> of how <b>vi stories</b> works.</p>';
50
  echo '</div>';
51
  echo '</div>';
52
  echo '<div class="plugin-card-bottom" '.(($isAjaxRequest)?'style="opacity: 0;"':'').'>';
53
+ //echo '<span>By clicking Sign Up button you agree to send current domain, email and affiliate ID to video intelligence.</span>';
54
  echo '<a id="wp_insert_vi_login" href="javascript:;" class="button button-secondary">Log In</a>';
55
+ //echo '<a id="wp_insert_vi_signup" href="javascript:;" class="button button-primary">Sign Up</a>';
56
  echo '</div>';
57
  } else {
58
  $dashboardURL = wp_insert_vi_api_get_dashboardurl();
61
  echo '<h4>Video content and video advertising – powered by video intelligence</h4>';
62
  echo '</div>';
63
  echo '<div class="plugin-card-top-content" '.(($isAjaxRequest)?'style="opacity: 0;"':'').'>';
64
+ echo '<p>Below you can see your current revenues.<br />Don’t see anything? Consult the <a target="_blank" href="https://www.vi.ai/frequently-asked-questions-vi-stories-for-wordpress/?utm_source=WordPress&utm_medium=Plugin%20FAQ&utm_campaign=WP%20Insert">FAQs</a>.<br /><b>This Panel will be withdrawn from the next version.<br />Existing users will be able to continue using vi ads.</b></p>';
65
  echo '<div id="wp_insert_vi_earnings_wrapper">';
66
  echo '<div class="wp_insert_ajaxloader"></div>';
67
  echo '</div>';
83
  echo '###SUCCESS###';
84
  echo '<div id="wp_insert_vi_earnings">';
85
  echo '<span id="wp_insert_vi_earnings_label">Total Earnings</span>';
86
+ echo '<span id="wp_insert_vi_earnings_value">USD '.$revenueData['netRevenue'].'</span>';
87
  echo '</div>';
88
  echo '<div id="wp_insert_vi_chart_wrapper">';
89
  echo '<canvas id="wp_insert_vi_chart" width="348" height="139"></canvas>';
109
  echo '<div id="wp_insert_vi_earnings_wrapper">';
110
  echo '<div id="wp_insert_vi_earnings">';
111
  echo '<span id="wp_insert_vi_earnings_label">Total Earnings</span>';
112
+ echo '<span id="wp_insert_vi_earnings_value"><img src="'.WP_INSERT_URL.'includes/assets/images/no-data.jpg?'.WP_INSERT_VERSION.'"></span>';
113
  echo '</div>';
114
  echo '<div id="wp_insert_vi_chart_wrapper">';
115
+ echo '<img width="348" height="139" src="'.WP_INSERT_URL.'includes/assets/images/empty-graph.jpg?'.WP_INSERT_VERSION.'">';
116
  echo '</div>';
117
  echo '<div class="clear"></div>';
118
  echo '</div>';
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Namith Jawahar
3
  Tags: google adsense, adsense, google ads, google analytics, privacy policy, best adsense plugin, ad management, ad rotation, tracking codes
4
  Donate link: http://wpinsert.smartlogix.co.in/support/
5
  Requires at least: 4.1.0
6
- Tested up to: 4.9.6
7
- Stable tag: 2.4.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
3
  Tags: google adsense, adsense, google ads, google analytics, privacy policy, best adsense plugin, ad management, ad rotation, tracking codes
4
  Donate link: http://wpinsert.smartlogix.co.in/support/
5
  Requires at least: 4.1.0
6
+ Tested up to: 4.9.8
7
+ Stable tag: 2.4.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
wp-insert.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Wp-Insert
4
  Plugin URI: http://www.wp-insert.smartlogix.co.in/
5
  Description: WP-INSERT by SMARTLOGIX : The Ultimate Adsense / Ad-Management Plugin for WordPress
6
- Version: 2.4.2
7
  Author: Namith Jawahar
8
  Author URI: http://www.smartlogix.co.in/
9
  WP-INSERT by SMARTLOGIX : The Ultimate Adsense / Ad-Management Plugin for WordPress
3
  Plugin Name: Wp-Insert
4
  Plugin URI: http://www.wp-insert.smartlogix.co.in/
5
  Description: WP-INSERT by SMARTLOGIX : The Ultimate Adsense / Ad-Management Plugin for WordPress
6
+ Version: 2.4.3
7
  Author: Namith Jawahar
8
  Author URI: http://www.smartlogix.co.in/
9
  WP-INSERT by SMARTLOGIX : The Ultimate Adsense / Ad-Management Plugin for WordPress