Changeset 3105745
- Timestamp:
- 06/21/2024 02:44:27 PM (22 months ago)
- Location:
- udimi-optin
- Files:
-
- 29 added
- 7 edited
-
assets/banner-1544x500.png (added)
-
assets/banner-772x250.png (modified) (previous)
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-2.png (modified) (previous)
-
assets/screenshot-3.png (added)
-
assets/screenshot-4.png (added)
-
tags/3.0 (added)
-
tags/3.0/admin (added)
-
tags/3.0/admin/greyboxes.php (added)
-
tags/3.0/admin/optin.php (added)
-
tags/3.0/admin/solo-ads.php (added)
-
tags/3.0/class.php (added)
-
tags/3.0/css (added)
-
tags/3.0/css/style.css (added)
-
tags/3.0/images (added)
-
tags/3.0/images/logo.png (added)
-
tags/3.0/images/logo16.png (added)
-
tags/3.0/images/logo24.png (added)
-
tags/3.0/images/logo64.png (added)
-
tags/3.0/js (added)
-
tags/3.0/js/adminpanel-greyboxes.js (added)
-
tags/3.0/js/adminpanel-optin.js (added)
-
tags/3.0/readme.txt (added)
-
tags/3.0/udimi-optin.php (added)
-
tags/3.0/uninstall.php (added)
-
trunk/admin/greyboxes.php (added)
-
trunk/admin/optin.php (added)
-
trunk/admin/solo-ads.php (added)
-
trunk/class.php (modified) (10 diffs)
-
trunk/css (added)
-
trunk/css/style.css (added)
-
trunk/js/adminpanel-greyboxes.js (added)
-
trunk/js/adminpanel-optin.js (added)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/udimi-optin.php (modified) (2 diffs)
-
trunk/uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
udimi-optin/trunk/class.php
r3102844 r3105745 10 10 const PLUGIN_NAME = 'udimioptin'; 11 11 const PLUGIN_FOLDER = 'udimi-optin'; 12 const OPTIN_CODE_TTL_HOURS = 24;12 const OPTIN_CODE_TTL_HOURS = 1; 13 13 14 14 private $apiError = ''; … … 21 21 { 22 22 if ($key = get_option('udimi_optin_key')) { 23 $date = get_option('udimi_optin_date'); 24 if (!$date || !strtotime($date) || time() - strtotime($date) > self::OPTIN_CODE_TTL_HOURS * 3600) { 25 if ($trackingCode = $this->getTrackingCode($key)) { 26 update_option('udimi_optin_script', $trackingCode); 27 update_option('udimi_optin_date', date('Y-m-d H:i:s')); 23 if (is_admin()) { 24 $this->updateScriptFromServer($key); 25 } else { 26 $is_last_success = get_option('udimi_is_last_success'); 27 $date = get_option('udimi_optin_date'); 28 $ttlSeconds = $is_last_success ? self::OPTIN_CODE_TTL_HOURS * 3600 : 60; 29 if (!$date || !strtotime($date) || time() - strtotime($date) > $ttlSeconds) { 30 $this->updateScriptFromServer($key); 28 31 } 29 32 } … … 31 34 } 32 35 36 public function updateScriptFromServer($key) 37 { 38 if ($initData = $this->init($key)) { 39 update_option('udimi_allow_optin_tracking', $initData->allow_optin_tracking); 40 update_option('udimi_allow_greyboxes', $initData->allow_greyboxes); 41 update_option('udimi_greyboxes_list', $initData->greyboxes_options); 42 43 $uid = get_option('udimi_selected_greybox'); 44 if ($loadedScript = $this->createCode($uid, $key)) { 45 update_option('udimi_optin_script', $loadedScript); 46 } 47 } 48 49 update_option('udimi_optin_date', date('Y-m-d H:i:s')); 50 } 33 51 public function ajax_connect() 34 52 { … … 36 54 37 55 $error = ''; 56 $initData = []; 38 57 if (empty($key)) { 39 $error = '" Client Key" is empty';58 $error = '"API key" is empty'; 40 59 } else { 41 42 $trackingCode = $this->getTrackingCode($key); 43 if (!$trackingCode) { 60 $initData = $this->init($key); 61 if (!$initData) { 44 62 $error = $this->getApiError(); 45 63 } … … 51 69 ]); 52 70 } else { 71 if ($initData->allow_optin_tracking) { 72 $boxScript = $this->createCode(null, $key); 73 update_option('udimi_optin_script', $boxScript); 74 } 53 75 54 76 update_option('udimi_optin_key', $key); 55 update_option('udimi_optin_script', stripslashes($trackingCode)); 77 update_option('udimi_allow_optin_tracking', $initData->allow_optin_tracking); 78 update_option('udimi_allow_greyboxes', $initData->allow_greyboxes); 79 update_option('udimi_greyboxes_list', $initData->greyboxes_options); 56 80 update_option('udimi_optin_date', date('Y-m-d H:i:s')); 57 wp_send_json_success(); 81 82 wp_send_json_success($initData); 83 } 84 } 85 86 public function ajax_load_greybox_script() 87 { 88 $uid = isset($_POST['uid']) && !is_array($_POST['uid']) ? trim($_POST['uid']) : ''; 89 90 if ($key = get_option('udimi_optin_key')) { 91 $error = ''; 92 $boxScript = $this->createCode($uid, $key); 93 if (!$boxScript) { 94 $error = $this->getApiError(); 95 } 96 97 if ($error) { 98 wp_send_json_error([ 99 'error' => $error, 100 ]); 101 } else { 102 update_option('udimi_selected_greybox', $uid); 103 update_option('udimi_optin_script', $boxScript); 104 update_option('udimi_optin_date', date('Y-m-d H:i:s')); 105 106 wp_send_json_success(array( 107 'code' => $boxScript, 108 'uid' => $uid 109 )); 110 } 58 111 } 59 112 } … … 62 115 { 63 116 delete_option('udimi_optin_key'); 117 delete_option('udimi_optin_date'); 64 118 delete_option('udimi_optin_script'); 65 delete_option('udimi_optin_date'); 119 120 delete_option('udimi_allow_optin_tracking'); 121 delete_option('udimi_allow_greyboxes'); 122 delete_option('udimi_is_last_success'); 123 delete_option('udimi_greyboxes_list'); 124 delete_option('udimi_selected_greybox'); 125 66 126 wp_send_json_success(); 67 127 } … … 77 137 public function addAdminScript() 78 138 { 139 $date = get_option('udimi_optin_date'); 79 140 wp_enqueue_script('jquery'); 80 wp_register_script('udimi_optin_admin_js', plugins_url(self::PLUGIN_FOLDER . '/js/adminpanel.js'), ['jquery']); 141 142 // optin 143 wp_register_script('udimi_optin_admin_js', plugins_url(self::PLUGIN_FOLDER . '/js/adminpanel-optin.js'), ['jquery'], $date); 81 144 wp_localize_script( 82 145 'udimi_optin_admin_js', … … 86 149 ] 87 150 ); 88 wp_enqueue_script('udimi_optin_admin_js', false, ['jquery']); 89 } 90 91 /** 92 * Получание трекинг кода с удаленного апи 151 wp_enqueue_script('udimi_optin_admin_js', false, ['jquery'], $date); 152 153 // greyboxes 154 wp_register_script('udimi_greyboxes_admin_js', plugins_url(self::PLUGIN_FOLDER . '/js/adminpanel-greyboxes.js'), ['jquery'], $date); 155 wp_localize_script( 156 'udimi_greyboxes_admin_js', 157 'config', 158 [ 159 'saveUrl' => admin_url('admin-ajax.php'), 160 ] 161 ); 162 wp_enqueue_script('udimi_greyboxes_admin_js', false, ['jquery'], $date); 163 164 // styles 165 wp_enqueue_style('style', plugins_url(self::PLUGIN_FOLDER . '/css/style.css'), [], $date); 166 } 167 168 169 /** 170 * Получение списка грейбоксов с удаленного апи 171 * @param $key 172 * 173 * @return false|mixed 174 */ 175 private function init($key) 176 { 177 $res = wp_remote_get((self::IS_LOCAL ? self::API_HOST_LOCAL : self::API_HOST_PROD) . "/v1/clients/wordpress/init", array( 178 'sslverify' => !self::IS_LOCAL, 179 'headers' => array( 180 'User-Hash' => $key 181 ) 182 )); 183 184 if (!is_array($res)) { 185 $this->apiError = 'Wordpress error. Unable to execute init API request.'; 186 return false; 187 } else { 188 if ($res['response']['code'] != 200) { 189 if (!$errorResponse = json_decode($res['body'])) { 190 $errorMessage = 'Unknown error'; 191 } else { 192 $errorMessage = $errorResponse->message; 193 } 194 195 $this->apiError = $res['response']['code'] === 404 ? 196 'Client not found. Make sure the "API key" is correct.' : 197 $errorMessage; 198 199 return false; 200 } else { 201 $successResponse = json_decode($res['body']); 202 203 return $successResponse->data; 204 } 205 } 206 } 207 208 /** 209 * Получение loader-кода для выбранного грейбокса 93 210 * @param $key 94 211 * 95 212 * @return false|mixed 96 213 */ 97 private function getTrackingCode($key)98 { 99 if (self::IS_LOCAL) {100 add_action('http_api_curl', function($handle) {101 //Don't verify SSL certs102 curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);103 curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);104 }, 10);105 }106 107 $res = wp_remote_get($this->getApiUrl($key));214 private function createCode($uid, $key) 215 { 216 $res = wp_remote_post((self::IS_LOCAL ? self::API_HOST_LOCAL : self::API_HOST_PROD)."/v1/clients/wordpress/create-code", array( 217 'sslverify' => !self::IS_LOCAL, 218 'body' => $uid ? array( 219 'greybox_uid' => $uid 220 ) : null, 221 'headers' => array( 222 'User-Hash' => $key 223 ) 224 )); 108 225 109 226 if (!is_array($res)) { 110 $this->apiError = 'WP_error'; 227 update_option('udimi_is_last_success', 0); 228 $this->apiError = 'Wordpress error. Unable to execute create code API request.'; 111 229 112 230 return false; 113 231 } else { 114 232 if ($res['response']['code'] != 200) { 233 update_option('udimi_is_last_success', 0); 115 234 if (!$errorResponse = json_decode($res['body'])) { 116 235 $errorMessage = 'Unknown error'; … … 119 238 } 120 239 121 if (self::IS_LOCAL) { 122 $this->apiError = '['.$res['response']['code'].'] ' . $res['response']['message'] . '. ' . $errorMessage; 123 } else { 124 $this->apiError = $res['response']['code'] === 404 ? 125 'Client not found. Make sure the "Client Key" is correct.' : 126 $errorMessage; 127 } 240 $this->apiError = $res['response']['code'] === 404 ? 241 'Loader code not found. Make sure the "Greybox uid" is correct.' : 242 $errorMessage; 128 243 129 244 return false; 130 245 } else { 131 if (!$successResponse = json_decode($res['body'])) { 132 $tracking_code = ''; 133 } else { 134 $tracking_code = !empty($successResponse->tracking_code) ? $successResponse->tracking_code : ''; 135 } 136 137 if (empty($tracking_code)) { 138 $this->apiError = 'Invalid Udimi API service response format'; 139 return false; 140 } 141 142 return $tracking_code; 143 } 144 } 145 } 146 147 private function getApiUrl($key) 148 { 149 return (self::IS_LOCAL ? self::API_HOST_LOCAL : self::API_HOST_PROD) . "/v1/guests/wordpress-plugin-ot/get-code/$key"; 150 } 151 152 //////////// 153 154 public function registerPlugin($plugin_array) 155 { 156 $plugin_array[self::PLUGIN_NAME] = get_site_url() . '/index.php?scplugin'; 157 158 return $plugin_array; 159 } 160 161 /** 162 * Метод WP. Вставить трекинг код в исходный код блога 246 update_option('udimi_is_last_success', 1); 247 $successResponse = json_decode($res['body']); 248 $data = $successResponse->data; 249 $code = $data->code; 250 251 return $code; 252 } 253 } 254 } 255 256 /** 257 * Метод WP. Вставить скрипты в исходный код блога 163 258 * @return void 164 259 */ 165 public function add OptinScript()260 public function addHeadScripts() 166 261 { 167 262 if ($trackingCode = get_option('udimi_optin_script', '')) { … … 176 271 public function addAdminMenu() 177 272 { 178 add_menu_page('Udimi t racker', 'Udimi tracker', 'manage_options', 'udimi-optin-settings', [273 add_menu_page('Udimi tools', 'Udimi tools', 'manage_options', 'udimi-optin-settings', [ 179 274 $this, 180 'render Settings'275 'renderOptin' 181 276 ], plugins_url(self::PLUGIN_FOLDER . '/images/logo16.png')); 182 277 183 add_submenu_page('udimi-optin-settings', ' Settings', 'Settings', 'manage_options', 'udimi-optin-settings', [278 add_submenu_page('udimi-optin-settings', 'Optin tracking', 'Optin tracking', 'manage_options', 'udimi-optin-settings', [ 184 279 $this, 185 'render Settings'280 'renderOptin' 186 281 ]); 187 } 188 189 public function renderSettings() 190 { 191 include(dirname(__FILE__) . '/admin/settings.php'); 282 283 add_submenu_page('udimi-optin-settings', 'My greyboxes', 'My greyboxes', 'manage_options', 'udimi-greyboxes-settings', [ 284 $this, 285 'renderGreyboxes' 286 ]); 287 288 add_submenu_page('udimi-optin-settings', 'Solo ad seller', 'Solo ad seller', 'manage_options', 'udimi-solo-ads-settings', [ 289 $this, 290 'renderSoloAds' 291 ]); 292 } 293 294 public function renderOptin() 295 { 296 include(dirname(__FILE__) . '/admin/optin.php'); 297 } 298 299 public function renderGreyboxes() 300 { 301 include(dirname(__FILE__) . '/admin/greyboxes.php'); 302 } 303 304 public function renderSoloAds() 305 { 306 include(dirname(__FILE__) . '/admin/solo-ads.php'); 192 307 } 193 308 -
udimi-optin/trunk/readme.txt
r3102844 r3105745 1 === Udimi Optin Tracking===2 Tags: udimi, solo , optin3 Requires at least: 3.01 === Udimi tools === 2 Tags: udimi, solo ads, buy solo ads, email marketing, marketing 3 Requires at least: 4.7 4 4 Tested up to: 6.5 5 Stable tag: 2.3 6 Contributors: udimi.com 5 Stable tag: 3.0 6 Requires PHP: 7.0 7 Donate link: https://udimi.com/prime/ 8 Contributors: webocoders 7 9 License: GPLv2 or later 8 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 11 10 This plugin automatically inserts Udimi Optin tracking code to your site.12 This plugin automatically inserts Udimi Optin tracking code or Udimi greyboxes to your site. 11 13 12 14 == Description == 13 15 14 This plugin automatically inserts Udimi Optin tracking code to your site. 16 After the installation, you'll be able to use Udimi solo ads optin tracking functions on your site. It will also open access to Greybox functionality from Udimi on your blog. 17 15 18 16 19 == Installation == 17 20 18 21 1. Activate the plugin 19 2. Click on "Udimi tracker" link on the leftside menu 20 3. Paste "Client Key" from "Optin tracking setup" page on Udimi 21 4. Click "Save and connect" button 22 2. Click on "Udimi tools" link on the leftside menu. It will ask your for API key. 23 3. Log into your Udimi account 24 4. Go to Settings > General and copy the key 25 5. Paste it on plugin's page 26 6. Click "Save and connect" button 22 27 23 28 You are all set! 24 29 30 ==Frequently Asked Questions== 31 =Do I need Udimi account for this plugin to work= 32 Yes, you need an account 33 34 How to change greybox settings 35 To change settings, please login to your Udimi account and do it from there. All settings and customizations are available there. 36 37 Do I have to be paid member of Udimi to use the plugin 38 Plugin is free, but has some volume-based limits. To remove all limits, just subscribe for Udimi Prime account 39 40 25 41 == Screenshots == 42 1. Optin tracking on Udimi 43 2. Optin tracking example 44 3. Greybox functionality on Udimi 45 4. Greybox types and setup 46 47 == Changelog == 48 =3.0= 49 * Added greybox functions and improved plugin setup and activation 50 51 =1.0= 52 * Initial release 53 54 == Upgrade Notice == 55 56 = 3.0 = 57 Upgrade to add Greyboxes functions to Udimi tools and improve plugin setup procedure -
udimi-optin/trunk/udimi-optin.php
r3102844 r3105745 1 1 <?php 2 2 /* 3 Plugin Name: Udimi Optin Tracker3 Plugin Name: Udimi tools 4 4 Plugin URI: https://udimi.com 5 Description: This plugin automatically inserts Udimi Optin tracking code to your site.6 Version: 2.3.05 Description: This plugin automatically inserts Udimi Optin tracking code or Udimi greyboxes to your site. 6 Version: 3.0 7 7 Author: Udimicom, Limited 8 8 Author URI: http://udimi.com … … 16 16 $udimiOptin->updateScript(); 17 17 18 add_action('wp_head',array($udimiOptin, 'add OptinScript'));18 add_action('wp_head',array($udimiOptin, 'addHeadScripts')); 19 19 add_action('admin_menu', array($udimiOptin, 'addAdminMenu')); 20 20 add_action('admin_enqueue_scripts', array($udimiOptin, 'addAdminScript')); 21 add_action( "wp_ajax_connect", array($udimiOptin, 'ajax_connect')); 22 add_action( "wp_ajax_disconnect", array($udimiOptin, 'ajax_disconnect')); 21 add_action( 'wp_ajax_connect', array($udimiOptin, 'ajax_connect')); 22 add_action( 'wp_ajax_load_greybox_script', array($udimiOptin, 'ajax_load_greybox_script')); 23 add_action( 'wp_ajax_disconnect', array($udimiOptin, 'ajax_disconnect')); -
udimi-optin/trunk/uninstall.php
r2817643 r3105745 8 8 'udimi_optin_script', 9 9 'udimi_optin_date', 10 'udimi_is_last_success', 11 12 'udimi_greyboxes_list', 13 'udimi_selected_greybox', 14 'udimi_allow_optin_tracking', 15 'udimi_allow_greyboxes', 16 10 17 // deprecated: 11 18 'udimi_optin_name',
Note: See TracChangeset
for help on using the changeset viewer.