Changeset 2436326
- Timestamp:
- 12/10/2020 08:59:54 AM (5 years ago)
- Location:
- vine-ma/trunk
- Files:
-
- 4 edited
-
readme.txt (modified) (1 diff)
-
vine.js (modified) (2 diffs)
-
vine_ma_plugin.php (modified) (15 diffs)
-
web_form_block.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vine-ma/trunk/readme.txt
r2389569 r2436326 21 21 22 22 == Changelog == 23 24 = 1.1.1 = 25 * Some bugfixing 23 26 24 27 = 1.1.0 = -
vine-ma/trunk/vine.js
r2389533 r2436326 1 1 var vinehost = "https://vine.eu" 2 2 3 window.addEventListener('message', function (e) {4 if(e.data.message && e.data.message == 'ma_wordpress_token') {5 var data = {6 action: 'vine_ma_save_option',7 apikey: e.data.token8 };3 window.addEventListener('message', function (e) { 4 if (e.data.message && e.data.message == 'ma_wordpress_token') { 5 var data = { 6 action: 'vine_ma_save_option', 7 apikey: e.data.token 8 }; 9 9 10 jQuery.post( ajaxurl, data, function(response) {11 if(authWindow != null)12 authWindow.close();13 location.reload();14 });15 }10 jQuery.post(ajaxurl, data, function (response) { 11 if (authWindow != null) 12 authWindow.close(); 13 location.reload(); 14 }); 15 } 16 16 }); 17 17 … … 19 19 20 20 function openMaLoginWindow() { 21 authWindow = window.open(vinehost + '/ma/oauth?appName=WordPress', 'mywindow', 'toolbar=no, menubar=no, width=600, height=500');21 authWindow = window.open(vinehost + '/ma/oauth?appName=WordPress', 'mywindow', 'toolbar=no, menubar=no, width=600, height=500'); 22 22 } 23 23 24 24 function logoutFromMA() { 25 var data = {26 action: 'vine_ma_logout'27 };25 var data = { 26 action: 'vine_ma_logout' 27 }; 28 28 29 jQuery.post( ajaxurl, data, function(response) {30 location.reload();31 });29 jQuery.post(ajaxurl, data, function (response) { 30 location.reload(); 31 }); 32 32 } -
vine-ma/trunk/vine_ma_plugin.php
r2389533 r2436326 3 3 /** 4 4 * Plugin Name: Vine MA - Email Marketing, Forms, Interactive Bot Forms, Chatbot, Analytics 5 * Version: 1.1. 05 * Version: 1.1.1 6 6 * Description: Vine is a Marketing automation tool to generate more leads from your web site. Vine includes web forms, interactive bot forms, landing pages, AI chatbot, visitor tracking, and other functionality to help you to make your site more interesting and to know better what your visitors do there. 7 7 * Author: Vine Oy … … 13 13 14 14 define("VINEHOST", "https://vine.eu"); 15 15 16 16 17 // add menu item to wordpress admin dashboard … … 52 53 register_setting( 'vine-plugin-options', 'vine-plugin-options'); 53 54 add_settings_section( 'vine_ma_general_settings', '', 'vine_ma_render_help_text', 'vine_ma_plugin' ); 55 add_settings_field( 'vine_ma_plugin_setting_username', 'Username:', 'vine_ma_plugin_setting_username', 'vine_ma_plugin', 'vine_ma_general_settings'); 54 56 add_settings_field( 'vine_ma_plugin_setting_organization_id', 'Organization ID:', 'vine_ma_plugin_setting_organization_id', 'vine_ma_plugin', 'vine_ma_general_settings'); 57 register_setting( 'vine-plugin-web-forms-cache', 'vine-plugin-web-forms-cache'); 55 58 } 56 59 … … 61 64 $apikey = vine_ma_get_option('apikey'); 62 65 $token = null; 63 if( $apikey != null )66 if( $apikey != null ) 64 67 { 65 $token = vine_ma_get_authtoken($apikey);66 }67 if( $token != null ) {68 68 echo "<p>You are currently connected to MA</p>"; 69 69 echo "<p><a href='javascript:logoutFromMA();'>Logout from MA</a></p>"; … … 76 76 function vine_ma_plugin_setting_organization_id() { 77 77 $orgid = vine_ma_get_option('organization_id'); 78 echo "<input id='vine_ma_plugin_setting_organization_id' name='vine-plugin-options[organization_id]' type='text' value='{$orgid}' readonly />"; 78 echo "<input id='vine_ma_plugin_setting_organization_id' name='vine-plugin-options[organization_id]' type='text' value='{$orgid}' readonly />"; 79 } 80 81 function vine_ma_plugin_setting_username() { 82 $username = vine_ma_get_option('username'); 83 if($username == null) 84 $username == ''; 85 echo "<input id='vine_ma_plugin_setting_username' name='vine-plugin-options[username]' type='text' value='{$username}' readonly />"; 79 86 } 80 87 … … 95 102 $url= VINEHOST.'/api/rest/2.0/login'; 96 103 $args = array( 97 'timeout' => 120,104 'timeout' => 20, 98 105 'headers' => array( 99 106 'Content-Type' => 'application/json', 100 'x-api-key' => $apikey 107 'x-api-key' => $apikey, 108 'user-agent' => '' 101 109 ) 102 110 ); 103 111 $html = wp_remote_get($url, $args); 104 if ( is_array( $html ) && ! is_wp_error( $html ) && $html['body'] != 'Unauthorized' ) 105 return $html['body']; 106 else 107 return null; 112 $errorcode = wp_remote_retrieve_response_code($html); 113 $body = wp_remote_retrieve_body($html); 114 if ( $errorcode === 200 || $errorcode === 304) { 115 return array( 116 'token' => $body, 117 'error' => null 118 ); 119 } 120 else { 121 return array( 122 'token' => null, 123 'error' => ($errorcode ? "{$errorcode}:{$body}" : "Timed out" ) 124 ); 125 } 108 126 } 109 127 … … 112 130 113 131 //get user organization id 114 function vine_ma_get_organizationid ($token) {132 function vine_ma_get_organizationid_username($token) { 115 133 $url=VINEHOST."/api/rest/2.0/vy_user?\$authtoken={$token}"; 116 134 $args = array( 117 'timeout' => 120 135 'timeout' => 20, 136 'user-agent' => '' 118 137 ); 119 138 $html = wp_remote_get($url, $args); 120 if ( is_array( $html ) && !is_wp_error( $html ) && $html['body'] != 'Unauthorized') { 121 $xml = new SimpleXMLElement($html['body']); 122 $xml->registerXPathNamespace('aa', 'http://schemas.microsoft.com/ado/2007/08/dataservices'); 123 $result = $xml->xpath('//aa:ORGANIZATIONID'); 124 return (string)$result[0]; 125 } 126 else 139 $returncode = wp_remote_retrieve_response_code($html); 140 if ( $returncode === 200 || $returncode === 304) { 141 $body = wp_remote_retrieve_body($html); 142 $xml = new SimpleXMLElement($body); 143 $orgid = ''; 144 $username = ''; 145 foreach($xml->xpath('//m:properties') as $event) { 146 $orgid = (string)$event->xpath('d:ORGANIZATIONID')[0]; 147 $username = (string)$event->xpath('d:NAME')[0]; 148 } 149 return array( 150 'orgid' => $orgid, 151 'username' => $username 152 ); 153 } 154 else { 127 155 return null; 156 } 128 157 } 129 158 … … 131 160 function vine_ma_hook_save_option() { 132 161 $apikey = $_POST['apikey']; 133 $token = vine_ma_get_authtoken($apikey); 134 $organizationid = vine_ma_get_organizationid($token); 162 $tokendata = vine_ma_get_authtoken($apikey); 163 $token = $tokendata['token']; 164 $userdata = vine_ma_get_organizationid_username($token); 135 165 update_option( 'vine-plugin-options' ,array( 136 'organization_id' => $organizationid, 166 'organization_id' => $userdata['orgid'], 167 'username' => $userdata['username'], 137 168 'apikey' => $apikey 138 169 )); … … 145 176 update_option( 'vine-plugin-options' ,array( 146 177 'organization_id' => '', 178 'username' => '', 147 179 'apikey' => '' 148 180 )); 181 update_option( 'vine-plugin-web-forms-cache', array()); 149 182 //echo $organizationid; 150 183 wp_die(); … … 154 187 function vine_ma_admin_notice() 155 188 { 156 $apikey = vine_ma_get_option('apikey'); 157 if( $apikey != null) { 158 $token = vine_ma_get_authtoken($apikey); 159 if( $token != null ) return; 160 } 161 ?> 162 <div class="notice notice-warning is-dismissible"> 163 <p> 164 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="9" viewBox='0 0 134 34' style="margin-right: 10px"> 189 $vineLogo = <<<EOD 190 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="9" viewBox='0 0 134 34' style="margin-right: 10px"> 165 191 <path fill='white' d='M 0.00 0.00 L 134.00 0.00 L 134.00 34.00 L 0.00 34.00 L 0.00 0.00 Z'/> 166 192 <path fill='rgb(213,40,60)' d='M 42.07 0.99 C 46.17 2.04 50.16 3.47 54.14 4.88 C 54.13 13.39 54.19 21.90 54.10 30.40 C 51.01 30.52 47.91 30.61 44.82 30.64 C 44.64 23.83 44.84 17.02 44.66 10.22 C 43.13 9.76 41.60 9.29 40.08 8.79 C 40.68 6.17 41.33 3.57 42.07 0.99 Z'/> … … 170 196 <path fill='white' d='M 113.50 12.98 C 114.55 11.46 115.41 9.58 117.22 8.81 C 119.50 7.95 121.51 9.73 123.36 10.80 C 120.15 11.83 116.86 12.64 113.50 12.98 Z'/> 171 197 </svg> 172 <?php _e('Warning! You are not connected to Vine MA. Vine services cannot work on your pages!', 'textdomain') ?> 173 </p> 174 </div> 175 <?php 198 EOD; 199 200 $apikey = vine_ma_get_option('apikey'); 201 if( $apikey == null) 202 { 203 ?> 204 <div class="notice notice-warning is-dismissible"> 205 <p> 206 <?php echo $vineLogo ?> 207 <?php _e('Warning! You are not connected to Vine MA. Vine services cannot work on your pages!', 'textdomain') ?> 208 </p> 209 </div> 210 <?php 211 } 212 else { 213 $orgid = vine_ma_get_option('organization_id'); 214 $username = vine_ma_get_option('username'); 215 if($orgid == null || $username == null ) 216 { 217 ?> 218 <div class="notice notice-error is-dismissible"> 219 <p> 220 <?php echo $vineLogo ?> 221 <?php _e('An error occurred while communicating with Vine MA. Please try to relogin.', 'textdomain') ?> 222 </p> 223 </div> 224 <?php 225 } 226 } 176 227 } 177 228 … … 184 235 //vine web block hook 185 236 function vine_ma_gutenberg_register_web_form_block() { 237 global $pagenow; 238 if ( $pagenow != 'post.php' ) 239 return; 186 240 if ( ! function_exists( 'register_block_type' ) ) { 187 241 // Gutenberg is not active. … … 208 262 function vine_ma_get_option($name) { 209 263 $options = get_option( 'vine-plugin-options' ); 210 if(!is_array( $options ) || $options[$name] == null || $options[$name] =='')264 if(!is_array( $options ) || $options[$name] == '') 211 265 return null; 212 266 return $options[$name]; … … 215 269 //get vine web forms via rest api 216 270 function vine_ma_get_web_forms() { 271 $cache = get_option( 'vine-plugin-web-forms-cache' ); 272 if(is_array( $cache ) && $cache['timestamp'] != null && (time() - $cache['timestamp']) < 120) 273 { 274 return array( 275 'forms' => $cache['forms'], 276 'error' => null 277 ); 278 } 279 $errorMessage = 'An error occurred while communicating with Vine MA. Please try to refresh page.'; 217 280 $apikey = vine_ma_get_option('apikey'); 218 $token = null;219 281 if( $apikey != null) { 220 $token = vine_ma_get_authtoken($apikey); 282 $tokendata = vine_ma_get_authtoken($apikey); 283 $token = $tokendata['token']; 284 $error = $tokendata['error']; 221 285 if( $token == null ) 222 return array(); 286 return array( 287 'forms' => array(), 288 'error' => "{$errorMessage} Token:{$error}" 289 ); 290 } else { 291 return array( 292 'forms' => array(), 293 'error' => "{$errorMessage} You are not logged in to Vine MA." 294 ); 223 295 } 224 296 $url=VINEHOST."/api/rest/2.0/VS_TRACK_FORM([FORMTYPE] <> 1 and [FORMTYPE] <> 2 and [FORMTYPE] <> 3 and [FORMTYPE] <> 4)?order=name&\$authtoken={$token}"; 225 297 $args = array( 226 'timeout' => 120 298 'timeout' => 20, 299 'user-agent' => '' 227 300 ); 228 301 $html = wp_remote_get($url,$args); 229 if ( is_array( $html ) && !is_wp_error( $html ) && $html['body'] != 'Unauthorized') { 230 $xml = new SimpleXMLElement($html['body']); 302 $returncode = wp_remote_retrieve_response_code($html); 303 if ( $returncode === 200 || $returncode === 304 ) { 304 $body = wp_remote_retrieve_body($html); 305 $xml = new SimpleXMLElement($body); 231 306 $webforms = array(); 232 307 foreach($xml->xpath('//m:properties') as $event) { … … 237 312 )); 238 313 } 239 return $webforms; 240 } 241 else 242 return array(); 243 } 314 $timestamp = time(); 315 update_option( 'vine-plugin-web-forms-cache', array( 316 'forms' => $webforms, 317 'timestamp' => $timestamp 318 )); 319 return array( 320 'forms' => $webforms, 321 'error' => null 322 ); 323 } 324 else { 325 return array( 326 'forms' => array(), 327 'error' => "{$errorMessage} Forms:" . ($errorcode ? "{$errorcode}:{$body}" : "Timed out" ) 328 ); 329 } 330 } -
vine-ma/trunk/web_form_block.js
r2389533 r2436326 1 ( function( blocks, element) {1 (function (blocks, element) { 2 2 var el = element.createElement; 3 3 … … 7 7 }; 8 8 9 blocks.registerBlockType( 'vine-ma-plugin/vine-web-form', { 10 title: 'Vine: Web Form', 11 icon: 'universal-access-alt', 12 category: 'layout', 13 attributes: { 14 formid: { 15 type: 'string', 16 default: '-1', 17 source: 'attribute', 18 selector: '.VineForm', 19 attribute: 'data-form-id' 20 }, 21 botformid: { 22 type: 'string', 23 default: '-1', 24 source: 'attribute', 25 selector: '.VineForm', 26 attribute: 'data-bot-id' 27 } 28 }, 29 edit: function(props) { 30 var vineforms = VineFormsData; 31 var els = []; 32 els.push( 33 el( 34 'option', 35 {value: '-1'}, 36 '<not set>' 37 ) 38 ); 39 if(vineforms) 40 for(var i=0; i<vineforms.length; i++) 41 { 9 if (VineFormsData.error != null) 10 alert(VineFormsData.error); 11 else 12 blocks.registerBlockType('vine-ma-plugin/vine-web-form', { 13 title: 'Vine: Web Form', 14 icon: 'universal-access-alt', 15 category: 'layout', 16 attributes: { 17 formid: { 18 type: 'string', 19 default: '-1', 20 source: 'attribute', 21 selector: '.VineForm', 22 attribute: 'data-form-id' 23 }, 24 botformid: { 25 type: 'string', 26 default: '-1', 27 source: 'attribute', 28 selector: '.VineForm', 29 attribute: 'data-bot-id' 30 } 31 }, 32 edit: function (props) { 33 var vineforms = VineFormsData.forms; 34 var els = []; 35 els.push( 36 el( 37 'option', 38 { value: '-1' }, 39 '<not set>' 40 ) 41 ); 42 for (var i = 0; i < vineforms.length; i++) { 42 43 els.push( 43 44 el( 44 'option',45 {value: vineforms[i].id},46 vineforms[i].name47 )45 'option', 46 { value: vineforms[i].id }, 47 vineforms[i].name 48 ) 48 49 ); 49 50 } 50 function onChangeContent( newContent) {51 props.setAttributes( { formid: newContent.target.value });52 }53 return el(54 'div',55 {},56 [57 el(58 'span',59 {},60 'Vine Form:'61 ),62 el(63 'select',64 { style: blockStyle, onChange: onChangeContent, value: props.attributes.formid === '-1' ? props.attributes.botformid : props.attributes.formid},65 els66 )67 ]68 );69 },70 save: function(props) {71 var form = props.attributes.formid === '-1' ? props.attributes.botformid : props.attributes.formid;72 var vineforms = VineFormsData;73 var targetForm = [];74 if(vineforms)75 targetForm = vineforms.filter(function(f) { return f.id == form; });76 var isDataForm = true;77 if(targetForm.length > 0 && targetForm[0].type == 5)78 isDataForm = false;79 var args = {80 className: 'VineForm' + (isDataForm ? '' : ' B' + form),81 'data-form-id': isDataForm ? form : undefined,82 'data-bot-id': !isDataForm ? form : undefined83 }84 return el(85 'div',86 args,87 ''88 );89 },90 });51 function onChangeContent(newContent) { 52 props.setAttributes({ formid: newContent.target.value }); 53 } 54 return el( 55 'div', 56 {}, 57 [ 58 el( 59 'span', 60 {}, 61 'Vine Form:' 62 ), 63 el( 64 'select', 65 { style: blockStyle, onChange: onChangeContent, value: props.attributes.formid === '-1' ? props.attributes.botformid : props.attributes.formid }, 66 els 67 ) 68 ] 69 ); 70 }, 71 save: function (props) { 72 var form = props.attributes.formid === '-1' ? props.attributes.botformid : props.attributes.formid; 73 var vineforms = VineFormsData.forms; 74 var targetForm = []; 75 if (vineforms) 76 targetForm = vineforms.filter(function (f) { return f.id == form; }); 77 var isDataForm = true; 78 if (targetForm.length > 0 && targetForm[0].type == 5) 79 isDataForm = false; 80 var args = { 81 className: 'VineForm' + (isDataForm ? '' : ' B' + form), 82 'data-form-id': isDataForm ? form : undefined, 83 'data-bot-id': !isDataForm ? form : undefined 84 } 85 return el( 86 'div', 87 args, 88 '' 89 ); 90 }, 91 }); 91 92 }( 92 93 window.wp.blocks, 93 94 window.wp.element 94 ) );95 ));
Note: See TracChangeset
for help on using the changeset viewer.