Changeset 3429994
- Timestamp:
- 12/31/2025 08:54:48 AM (8 weeks ago)
- Location:
- vine-ma/trunk
- Files:
-
- 4 edited
-
readme.txt (modified) (2 diffs)
-
vine.js (modified) (2 diffs)
-
vine_ma_plugin.php (modified) (9 diffs)
-
web_form_block.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vine-ma/trunk/readme.txt
r3429934 r3429994 5 5 Requires at least: 3.0.1 6 6 Requires PHP: 5.2 7 Stable tag: 1. 0.07 Stable tag: 1.3.1 8 8 License: GPLv2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0 … … 21 21 22 22 == Changelog == 23 24 = 1.3.1 = 25 * Shorten the form selection list by having separate control for bot forms and static forms. Compatibility with Wordpress 6.9 23 26 24 27 = 1.3.0 = -
vine-ma/trunk/vine.js
r2436326 r3429994 1 var vinehost = "https://vine.eu" 1 var vinehost = "https://vine.eu"; 2 2 3 3 window.addEventListener('message', function (e) { 4 if (e.data.message && e.data.message == 'ma_wordpress_token') { 4 if (e.origin !== vinehost) return; 5 if (e.data && e.data.message && e.data.message == 'ma_wordpress_token') { 5 6 var data = { 6 7 action: 'vine_ma_save_option', 7 apikey: e.data.token 8 apikey: e.data.token, 9 nonce: window.VineMaAdmin && window.VineMaAdmin.nonce 8 10 }; 9 11 … … 24 26 function logoutFromMA() { 25 27 var data = { 26 action: 'vine_ma_logout' 28 action: 'vine_ma_logout', 29 nonce: window.VineMaAdmin && window.VineMaAdmin.nonce 27 30 }; 28 31 -
vine-ma/trunk/vine_ma_plugin.php
r2986610 r3429994 3 3 /** 4 4 * Plugin Name: Vine MA - Email Marketing, Forms, Interactive Bot Forms, Chatbot, Analytics 5 * Version: 1.3. 05 * Version: 1.3.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 … … 26 26 27 27 function vine_ma_add_vine_script($hook) { 28 wp_enqueue_script('vine_script', plugin_dir_url(__FILE__) . '/vine.js'); 28 // Only load admin JS on this plugin's settings page. 29 if ( $hook !== 'settings_page_vine_ma_plugin' ) { 30 return; 31 } 32 33 $script_path = plugin_dir_path(__FILE__) . 'vine.js'; 34 $script_url = plugin_dir_url(__FILE__) . 'vine.js'; 35 $version = file_exists($script_path) ? filemtime($script_path) : false; 36 37 wp_enqueue_script('vine_script', $script_url, array('jquery'), $version, true); 38 wp_localize_script('vine_script', 'VineMaAdmin', array( 39 'nonce' => wp_create_nonce('vine_ma_admin'), 40 )); 29 41 } 30 42 31 43 function vine_ma_add_plugin_page_settings_link( $links ) { 32 $links[] = '<a href="' .33 admin_url( 'options-general.php?page=vine_ma_plugin' ) .34 '">' . __('Settings') . '</a>';35 return $links;44 $links[] = '<a href="' . 45 admin_url( 'options-general.php?page=vine_ma_plugin' ) . 46 '">' . __('Settings') . '</a>'; 47 return $links; 36 48 } 37 49 … … 54 66 register_setting( 'vine-plugin-options', 'vine-plugin-options'); 55 67 add_settings_section( 'vine_ma_general_settings', '', 'vine_ma_render_help_text', 'vine_ma_plugin' ); 56 add_settings_field( 'vine_ma_plugin_setting_username', 'Username:', 'vine_ma_plugin_setting_username', 'vine_ma_plugin', 'vine_ma_general_settings');68 add_settings_field( 'vine_ma_plugin_setting_username', 'Username:', 'vine_ma_plugin_setting_username', 'vine_ma_plugin', 'vine_ma_general_settings'); 57 69 add_settings_field( 'vine_ma_plugin_setting_organization_id', 'Organization ID:', 'vine_ma_plugin_setting_organization_id', 'vine_ma_plugin', 'vine_ma_general_settings'); 58 register_setting( 'vine-plugin-web-forms-cache', 'vine-plugin-web-forms-cache');70 register_setting( 'vine-plugin-web-forms-cache', 'vine-plugin-web-forms-cache'); 59 71 } 60 72 … … 62 74 function vine_ma_render_help_text() { 63 75 echo "<p>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.</p>"; 64 65 $apikey = vine_ma_get_option('apikey');66 $token = null;67 if( $apikey != null )68 {69 echo "<p>You are currently connected to MA</p>";70 echo "<p><a href='javascript:logoutFromMA();'>Logout from MA</a></p>";71 }72 else {73 echo "<p>You need Vine account to use this plugin. If you do not have one, you can register trial account in <a target='_blank' href='https://vine.eu/en/try-for-free'>https://vine.eu/en/try-for-free</a></p>";74 echo "<p><a id='vinemaloginbtn' href='javascript:openMaLoginWindow();'>Login to MA</a></p>";75 echo "<p><b>Please do not use partner account which can be moved between different customers.</b></p>";76 }76 77 $apikey = vine_ma_get_option('apikey'); 78 $token = null; 79 if( $apikey != null ) 80 { 81 echo "<p>You are currently connected to MA</p>"; 82 echo "<p><a href='javascript:logoutFromMA();'>Logout from MA</a></p>"; 83 } 84 else { 85 echo "<p>You need Vine account to use this plugin. If you do not have one, you can register trial account in <a target='_blank' href='https://vine.eu/en/try-for-free'>https://vine.eu/en/try-for-free</a></p>"; 86 echo "<p><a id='vinemaloginbtn' href='javascript:openMaLoginWindow();'>Login to MA</a></p>"; 87 echo "<p><b>Please do not use partner account which can be moved between different customers.</b></p>"; 88 } 77 89 } 78 90 function vine_ma_plugin_setting_organization_id() { 79 $orgid = vine_ma_get_option('organization_id');80 echo "<input id='vine_ma_plugin_setting_organization_id' name='vine-plugin-options[organization_id]' type='text' value='{$orgid}' readonly />";91 $orgid = vine_ma_get_option('organization_id'); 92 echo "<input id='vine_ma_plugin_setting_organization_id' name='vine-plugin-options[organization_id]' type='text' value='{$orgid}' readonly />"; 81 93 } 82 94 83 95 function vine_ma_plugin_setting_username() { 84 $username = vine_ma_get_option('username');85 if($username == null)86 $username == '';96 $username = vine_ma_get_option('username'); 97 if($username == null) 98 $username = ''; 87 99 echo "<input id='vine_ma_plugin_setting_username' name='vine-plugin-options[username]' type='text' value='{$username}' readonly />"; 88 100 } … … 90 102 //add 'Vine' script to WP pages by using organization id settings 91 103 function vine_ma_wpes_hook_add_script() { 92 if ( is_user_logged_in() && isset($_GET['et_fb']) && isset($_GET['PageSpeed'])) return;93 $orgid = vine_ma_get_option('organization_id');104 if ( is_user_logged_in() && isset($_GET['et_fb']) && isset($_GET['PageSpeed'])) return; 105 $orgid = vine_ma_get_option('organization_id'); 94 106 $src = VINECDNHOST."/vscript/{$orgid}.js"; 95 $srcac = VINECDNHOST."/vscript/allowCookies.js";96 ?>97 <script type="text/javascript" src="<?php echo $src ?>" data-cookieconsent="ignore"></script>98 <script type="text/plain" src="<?php echo $srcac ?>" data-cookieconsent="marketing" async></script>99 <?php107 $srcac = VINECDNHOST."/vscript/allowCookies.js"; 108 ?> 109 <script type="text/javascript" src="<?php echo $src ?>" data-cookieconsent="ignore"></script> 110 <script type="text/plain" src="<?php echo $srcac ?>" data-cookieconsent="marketing" async></script> 111 <?php 100 112 } 101 113 … … 106 118 //get vine temporary token 107 119 function vine_ma_get_authtoken($apikey) { 108 if($apikey === '' || $apikey == null)109 return null;110 $url= VINEHOST.'/api/rest/2.0/login';111 $args = array(112 'timeout' => 20,120 if($apikey === '' || $apikey == null) 121 return null; 122 $url= VINEHOST.'/api/rest/2.0/login'; 123 $args = array( 124 'timeout' => 20, 113 125 'headers' => array( 114 126 'Content-Type' => 'application/json', 115 127 'x-api-key' => $apikey, 116 'user-agent' => ''117 )118 );119 $html = wp_remote_get($url, $args);120 $errorcode = wp_remote_retrieve_response_code($html);121 $body = wp_remote_retrieve_body($html);122 if ( $errorcode === 200 || $errorcode === 304) {123 return array(124 'token' => $body,125 'error' => null126 );127 }128 else {129 return array(130 'token' => null,131 'error' => ($errorcode ? "{$errorcode}:{$body}" : "Timed out" )132 );133 }128 'user-agent' => '' 129 ) 130 ); 131 $html = wp_remote_get($url, $args); 132 $errorcode = wp_remote_retrieve_response_code($html); 133 $body = wp_remote_retrieve_body($html); 134 if ( $errorcode === 200 || $errorcode === 304) { 135 return array( 136 'token' => $body, 137 'error' => null 138 ); 139 } 140 else { 141 return array( 142 'token' => null, 143 'error' => ($errorcode ? "{$errorcode}:{$body}" : "Timed out" ) 144 ); 145 } 134 146 } 135 147 … … 139 151 //get user organization id 140 152 function vine_ma_get_organizationid_username($token) { 141 $url=VINEHOST."/api/rest/2.0/user?\$authtoken={$token}";142 $args = array(143 'timeout' => 20,144 'user-agent' => ''145 );146 $html = wp_remote_get($url, $args);147 $returncode = wp_remote_retrieve_response_code($html);148 if ( $returncode === 200 || $returncode === 304) {149 $body = wp_remote_retrieve_body($html);150 $xml = new SimpleXMLElement($body);151 $orgid = '';152 $username = '';153 foreach($xml->xpath('//m:properties') as $event) {154 $orgid = (string)$event->xpath('d:ORGANIZATIONID')[0];155 $firstname = (string)$event->xpath('d:FIRSTNAME')[0];156 $lastname = (string)$event->xpath('d:LASTNAME')[0];157 $email = (string)$event->xpath('d:EMAIL')[0];158 $username = $firstname . ' ' . $lastname . ' (' . $email . ')';153 $url=VINEHOST."/api/rest/2.0/user?\$authtoken={$token}"; 154 $args = array( 155 'timeout' => 20, 156 'user-agent' => '' 157 ); 158 $html = wp_remote_get($url, $args); 159 $returncode = wp_remote_retrieve_response_code($html); 160 if ( $returncode === 200 || $returncode === 304) { 161 $body = wp_remote_retrieve_body($html); 162 $xml = new SimpleXMLElement($body); 163 $orgid = ''; 164 $username = ''; 165 foreach($xml->xpath('//m:properties') as $event) { 166 $orgid = (string)$event->xpath('d:ORGANIZATIONID')[0]; 167 $firstname = (string)$event->xpath('d:FIRSTNAME')[0]; 168 $lastname = (string)$event->xpath('d:LASTNAME')[0]; 169 $email = (string)$event->xpath('d:EMAIL')[0]; 170 $username = $firstname . ' ' . $lastname . ' (' . $email . ')'; 159 171 } 160 return array(161 'orgid' => $orgid,162 'username' => $username163 );164 }165 else {166 return null;167 }172 return array( 173 'orgid' => $orgid, 174 'username' => $username 175 ); 176 } 177 else { 178 return null; 179 } 168 180 } 169 181 170 182 //save constant api key 171 183 function vine_ma_hook_save_option() { 172 $apikey = $_POST['apikey']; 173 $tokendata = vine_ma_get_authtoken($apikey); 174 $token = $tokendata['token']; 175 $userdata = vine_ma_get_organizationid_username($token); 176 update_option( 'vine-plugin-options' ,array( 184 if ( ! current_user_can('manage_options') ) { 185 wp_send_json_error(array('message' => 'Forbidden'), 403); 186 } 187 check_ajax_referer('vine_ma_admin', 'nonce'); 188 189 $apikey = isset($_POST['apikey']) ? sanitize_text_field(wp_unslash($_POST['apikey'])) : ''; 190 if ( $apikey === '' ) { 191 wp_send_json_error(array('message' => 'Missing apikey'), 400); 192 } 193 194 $tokendata = vine_ma_get_authtoken($apikey); 195 $token = is_array($tokendata) ? ($tokendata['token'] ?? null) : null; 196 if ( $token == null ) { 197 $error = is_array($tokendata) ? ($tokendata['error'] ?? null) : null; 198 wp_send_json_error(array('message' => 'Authentication failed', 'error' => $error), 400); 199 } 200 201 $userdata = vine_ma_get_organizationid_username($token); 202 if ( ! is_array($userdata) || empty($userdata['orgid']) ) { 203 wp_send_json_error(array('message' => 'Failed to fetch user data'), 400); 204 } 205 206 update_option('vine-plugin-options', array( 177 207 'organization_id' => $userdata['orgid'], 178 'username' => $userdata['username'],179 'apikey' => $apikey 180 ));181 //echo $organizationid; 182 wp_die();208 'username' => $userdata['username'] ?? '', 209 'apikey' => $apikey, 210 )); 211 212 wp_send_json_success(); 183 213 } 184 214 185 215 //logaout action, remove api key 186 216 function vine_ma_hook_logout() { 187 update_option( 'vine-plugin-options' ,array( 217 if ( ! current_user_can('manage_options') ) { 218 wp_send_json_error(array('message' => 'Forbidden'), 403); 219 } 220 check_ajax_referer('vine_ma_admin', 'nonce'); 221 222 update_option('vine-plugin-options', array( 188 223 'organization_id' => '', 189 'username' => '',190 'apikey' => '' 191 ));192 update_option('vine-plugin-web-forms-cache', array());193 //echo $organizationid; 194 wp_die();224 'username' => '', 225 'apikey' => '', 226 )); 227 update_option('vine-plugin-web-forms-cache', array()); 228 229 wp_send_json_success(); 195 230 } 196 231 … … 198 233 function vine_ma_admin_notice() 199 234 { 200 $vineLogo = <<<EOD201 <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">202 <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'/>203 <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'/>204 <path fill='rgb(213,40,60)' d='M 65.58 3.73 C 68.38 2.67 71.23 1.71 74.15 0.97 C 74.16 3.70 74.14 6.42 74.11 9.14 C 77.06 5.39 80.50 0.41 85.97 1.10 C 90.27 0.65 93.94 4.82 93.79 8.95 C 93.85 16.18 93.81 23.41 93.77 30.64 C 90.88 30.65 87.99 30.66 85.10 30.67 C 84.85 23.81 86.35 16.75 84.14 10.08 C 82.51 11.08 80.77 12.10 79.84 13.84 C 76.78 18.93 75.53 24.83 74.30 30.57 C 71.38 30.67 68.45 30.66 65.52 30.60 C 65.49 21.64 65.39 12.69 65.58 3.73 Z'/>205 <path fill='rgb(213,40,60)' d='M 107.37 6.40 C 112.93 -1.95 127.19 -0.22 131.70 8.36 C 133.11 10.69 133.02 13.49 133.28 16.11 C 127.17 18.05 120.86 19.33 114.77 21.37 C 116.45 22.64 118.11 24.22 120.29 24.48 C 123.20 24.86 125.96 23.67 128.73 23.01 C 128.77 25.78 128.76 28.56 128.64 31.33 C 123.48 32.33 117.89 33.23 112.88 31.10 C 108.20 29.06 105.38 24.01 105.22 19.02 C 105.04 14.77 104.78 10.05 107.37 6.40 Z'/>206 <path fill='rgb(213,40,60)' d='M 23.37 2.15 C 26.50 1.67 29.67 1.62 32.82 1.77 C 28.11 12.02 23.80 22.46 19.44 32.87 C 18.13 32.84 16.70 33.47 15.47 32.82 C 13.14 29.91 11.67 26.45 9.69 23.31 C 6.84 18.21 3.24 13.54 0.79 8.21 C 3.13 6.36 5.58 4.64 8.15 3.12 C 11.98 7.42 14.30 12.75 17.39 17.56 C 19.90 12.64 21.44 7.30 23.37 2.15 Z'/>207 <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'/>208 </svg>235 $vineLogo = <<<EOD 236 <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"> 237 <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'/> 238 <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'/> 239 <path fill='rgb(213,40,60)' d='M 65.58 3.73 C 68.38 2.67 71.23 1.71 74.15 0.97 C 74.16 3.70 74.14 6.42 74.11 9.14 C 77.06 5.39 80.50 0.41 85.97 1.10 C 90.27 0.65 93.94 4.82 93.79 8.95 C 93.85 16.18 93.81 23.41 93.77 30.64 C 90.88 30.65 87.99 30.66 85.10 30.67 C 84.85 23.81 86.35 16.75 84.14 10.08 C 82.51 11.08 80.77 12.10 79.84 13.84 C 76.78 18.93 75.53 24.83 74.30 30.57 C 71.38 30.67 68.45 30.66 65.52 30.60 C 65.49 21.64 65.39 12.69 65.58 3.73 Z'/> 240 <path fill='rgb(213,40,60)' d='M 107.37 6.40 C 112.93 -1.95 127.19 -0.22 131.70 8.36 C 133.11 10.69 133.02 13.49 133.28 16.11 C 127.17 18.05 120.86 19.33 114.77 21.37 C 116.45 22.64 118.11 24.22 120.29 24.48 C 123.20 24.86 125.96 23.67 128.73 23.01 C 128.77 25.78 128.76 28.56 128.64 31.33 C 123.48 32.33 117.89 33.23 112.88 31.10 C 108.20 29.06 105.38 24.01 105.22 19.02 C 105.04 14.77 104.78 10.05 107.37 6.40 Z'/> 241 <path fill='rgb(213,40,60)' d='M 23.37 2.15 C 26.50 1.67 29.67 1.62 32.82 1.77 C 28.11 12.02 23.80 22.46 19.44 32.87 C 18.13 32.84 16.70 33.47 15.47 32.82 C 13.14 29.91 11.67 26.45 9.69 23.31 C 6.84 18.21 3.24 13.54 0.79 8.21 C 3.13 6.36 5.58 4.64 8.15 3.12 C 11.98 7.42 14.30 12.75 17.39 17.56 C 19.90 12.64 21.44 7.30 23.37 2.15 Z'/> 242 <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'/> 243 </svg> 209 244 EOD; 210 211 $apikey = vine_ma_get_option('apikey');212 if( $apikey == null)213 {214 ?>215 <div class="notice notice-warning is-dismissible">216 <p>217 <?php echo $vineLogo ?>218 <?php _e('Warning! You are not connected to Vine MA. Vine services cannot work on your pages!', 'textdomain') ?>219 </p>220 </div>221 <?php222 }223 else {224 $orgid = vine_ma_get_option('organization_id');225 $username = vine_ma_get_option('username');226 if($orgid == null || $username == null )227 {228 ?>229 <div class="notice notice-error is-dismissible">230 <p>231 <?php echo $vineLogo ?>232 <?php _e('An error occurred while communicating with Vine MA. Please try to relogin.', 'textdomain') ?>233 </p>234 </div>235 <?php236 }237 }245 246 $apikey = vine_ma_get_option('apikey'); 247 if( $apikey == null) 248 { 249 ?> 250 <div class="notice notice-warning is-dismissible"> 251 <p> 252 <?php echo $vineLogo ?> 253 <?php _e('Warning! You are not connected to Vine MA. Vine services cannot work on your pages!', 'textdomain') ?> 254 </p> 255 </div> 256 <?php 257 } 258 else { 259 $orgid = vine_ma_get_option('organization_id'); 260 $username = vine_ma_get_option('username'); 261 if($orgid == null || $username == null ) 262 { 263 ?> 264 <div class="notice notice-error is-dismissible"> 265 <p> 266 <?php echo $vineLogo ?> 267 <?php _e('An error occurred while communicating with Vine MA. Please try to relogin.', 'textdomain') ?> 268 </p> 269 </div> 270 <?php 271 } 272 } 238 273 } 239 274 240 275 function vine_ma_admin_notice_multiorg_status() 241 276 { 242 $vineLogo = <<<EOD243 <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">244 <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'/>245 <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'/>246 <path fill='rgb(213,40,60)' d='M 65.58 3.73 C 68.38 2.67 71.23 1.71 74.15 0.97 C 74.16 3.70 74.14 6.42 74.11 9.14 C 77.06 5.39 80.50 0.41 85.97 1.10 C 90.27 0.65 93.94 4.82 93.79 8.95 C 93.85 16.18 93.81 23.41 93.77 30.64 C 90.88 30.65 87.99 30.66 85.10 30.67 C 84.85 23.81 86.35 16.75 84.14 10.08 C 82.51 11.08 80.77 12.10 79.84 13.84 C 76.78 18.93 75.53 24.83 74.30 30.57 C 71.38 30.67 68.45 30.66 65.52 30.60 C 65.49 21.64 65.39 12.69 65.58 3.73 Z'/>247 <path fill='rgb(213,40,60)' d='M 107.37 6.40 C 112.93 -1.95 127.19 -0.22 131.70 8.36 C 133.11 10.69 133.02 13.49 133.28 16.11 C 127.17 18.05 120.86 19.33 114.77 21.37 C 116.45 22.64 118.11 24.22 120.29 24.48 C 123.20 24.86 125.96 23.67 128.73 23.01 C 128.77 25.78 128.76 28.56 128.64 31.33 C 123.48 32.33 117.89 33.23 112.88 31.10 C 108.20 29.06 105.38 24.01 105.22 19.02 C 105.04 14.77 104.78 10.05 107.37 6.40 Z'/>248 <path fill='rgb(213,40,60)' d='M 23.37 2.15 C 26.50 1.67 29.67 1.62 32.82 1.77 C 28.11 12.02 23.80 22.46 19.44 32.87 C 18.13 32.84 16.70 33.47 15.47 32.82 C 13.14 29.91 11.67 26.45 9.69 23.31 C 6.84 18.21 3.24 13.54 0.79 8.21 C 3.13 6.36 5.58 4.64 8.15 3.12 C 11.98 7.42 14.30 12.75 17.39 17.56 C 19.90 12.64 21.44 7.30 23.37 2.15 Z'/>249 <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'/>250 </svg>277 $vineLogo = <<<EOD 278 <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"> 279 <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'/> 280 <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'/> 281 <path fill='rgb(213,40,60)' d='M 65.58 3.73 C 68.38 2.67 71.23 1.71 74.15 0.97 C 74.16 3.70 74.14 6.42 74.11 9.14 C 77.06 5.39 80.50 0.41 85.97 1.10 C 90.27 0.65 93.94 4.82 93.79 8.95 C 93.85 16.18 93.81 23.41 93.77 30.64 C 90.88 30.65 87.99 30.66 85.10 30.67 C 84.85 23.81 86.35 16.75 84.14 10.08 C 82.51 11.08 80.77 12.10 79.84 13.84 C 76.78 18.93 75.53 24.83 74.30 30.57 C 71.38 30.67 68.45 30.66 65.52 30.60 C 65.49 21.64 65.39 12.69 65.58 3.73 Z'/> 282 <path fill='rgb(213,40,60)' d='M 107.37 6.40 C 112.93 -1.95 127.19 -0.22 131.70 8.36 C 133.11 10.69 133.02 13.49 133.28 16.11 C 127.17 18.05 120.86 19.33 114.77 21.37 C 116.45 22.64 118.11 24.22 120.29 24.48 C 123.20 24.86 125.96 23.67 128.73 23.01 C 128.77 25.78 128.76 28.56 128.64 31.33 C 123.48 32.33 117.89 33.23 112.88 31.10 C 108.20 29.06 105.38 24.01 105.22 19.02 C 105.04 14.77 104.78 10.05 107.37 6.40 Z'/> 283 <path fill='rgb(213,40,60)' d='M 23.37 2.15 C 26.50 1.67 29.67 1.62 32.82 1.77 C 28.11 12.02 23.80 22.46 19.44 32.87 C 18.13 32.84 16.70 33.47 15.47 32.82 C 13.14 29.91 11.67 26.45 9.69 23.31 C 6.84 18.21 3.24 13.54 0.79 8.21 C 3.13 6.36 5.58 4.64 8.15 3.12 C 11.98 7.42 14.30 12.75 17.39 17.56 C 19.90 12.64 21.44 7.30 23.37 2.15 Z'/> 284 <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'/> 285 </svg> 251 286 EOD; 252 253 $ismultiorg = vine_ma_get_multiorg_status();254 255 if( $ismultiorg == true)256 {257 ?>258 <div class="notice notice-warning is-dismissible">259 <p>260 <?php echo $vineLogo ?>261 <?php _e('Warning! The account used should be account which cannot access multiple organizations. Please relogin with proper account.', 'textdomain') ?>262 </p>263 </div>264 <?php265 }287 288 $ismultiorg = vine_ma_get_multiorg_status(); 289 290 if( $ismultiorg == true) 291 { 292 ?> 293 <div class="notice notice-warning is-dismissible"> 294 <p> 295 <?php echo $vineLogo ?> 296 <?php _e('Warning! The account used should be account which cannot access multiple organizations. Please relogin with proper account.', 'textdomain') ?> 297 </p> 298 </div> 299 <?php 300 } 266 301 } 267 302 … … 275 310 //vine web block hook 276 311 function vine_ma_gutenberg_register_web_form_block() { 277 global $pagenow; 278 if ( $pagenow != 'post.php' ) 279 return; 280 if ( ! function_exists( 'register_block_type' ) ) { 281 // Gutenberg is not active. 282 return; 283 } 284 285 wp_register_script( 286 'vine-web-form-01', 287 plugins_url( 'web_form_block.js', __FILE__ ), 288 array( 'wp-blocks', 'wp-element' ) 289 ); 290 291 $webforms = vine_ma_get_web_forms(); 292 293 wp_localize_script('vine-web-form-01', 'VineFormsData', $webforms); 294 295 register_block_type( 'vine-ma-plugin/vine-web-form', array( 296 'editor_script' => 'vine-web-form-01' 312 global $pagenow; 313 if ( $pagenow != 'post.php' && $pagenow != 'post-new.php' ) 314 return; 315 if ( ! function_exists( 'register_block_type' ) ) { 316 // Gutenberg is not active. 317 return; 318 } 319 320 $block_script_path = plugin_dir_path(__FILE__) . 'web_form_block.js'; 321 $block_script_ver = file_exists($block_script_path) ? filemtime($block_script_path) : false; 322 323 wp_register_script( 324 'vine-web-form-01', 325 plugins_url( 'web_form_block.js', __FILE__ ), 326 array( 'wp-blocks', 'wp-element' ), 327 $block_script_ver 328 ); 329 330 $webforms = vine_ma_get_web_forms(); 331 332 wp_localize_script('vine-web-form-01', 'VineFormsData', $webforms); 333 334 register_block_type( 'vine-ma-plugin/vine-web-form', array( 335 'editor_script' => 'vine-web-form-01' 297 336 ) 298 );337 ); 299 338 } 300 339 301 340 //get plugins options function 302 341 function vine_ma_get_option($name) { 303 $options = get_option( 'vine-plugin-options' );304 if(!is_array( $options ) || $options[$name]== '')305 return null;306 return $options[$name];342 $options = get_option( 'vine-plugin-options' ); 343 if(!is_array( $options ) || !isset($options[$name]) || $options[$name] === '') 344 return null; 345 return $options[$name]; 307 346 } 308 347 309 348 //get vine web forms via rest api 310 349 function vine_ma_get_web_forms() { 311 $cache = get_option( 'vine-plugin-web-forms-cache' );312 if(is_array( $cache) && $cache['timestamp'] != null && (time() - $cache['timestamp']) < 120)313 {314 return array(315 'forms' => $cache['forms'],316 'error' => null317 );318 }319 $errorMessage = 'An error occurred while communicating with Vine MA. Please try to refresh page.';320 $apikey = vine_ma_get_option('apikey');321 if( $apikey != null) {322 $tokendata = vine_ma_get_authtoken($apikey);323 $token = $tokendata['token'];324 $error = $tokendata['error'];325 if( $token == null )326 return array(327 'forms' => array(),328 'error' => "{$errorMessage} Token:{$error}"329 );330 } else {331 return array(332 'forms' => array(),333 'error' => "{$errorMessage} You are not logged in to Vine MA."334 );335 }336 $url=VINEHOST."/api/rest/2.0/VS_TRACK_FORM([FORMTYPE] <> 1 and [FORMTYPE] <> 2 and [FORMTYPE] <> 3 and [FORMTYPE] <> 4)?order=name&\$authtoken={$token}";337 $args = array(338 'timeout' => 20,339 'user-agent' => ''340 );341 $html = wp_remote_get($url,$args);342 $returncode = wp_remote_retrieve_response_code($html);343 if ( $returncode === 200 || $returncode === 304 ) {344 $body = wp_remote_retrieve_body($html); 345 $xml = new SimpleXMLElement($body);346 $webforms = array();350 $cache = get_option( 'vine-plugin-web-forms-cache' ); 351 if(is_array( $cache ) && isset($cache['timestamp']) && $cache['timestamp'] != null && (time() - $cache['timestamp']) < 120) 352 { 353 return array( 354 'forms' => isset($cache['forms']) ? $cache['forms'] : array(), 355 'error' => null 356 ); 357 } 358 $errorMessage = 'An error occurred while communicating with Vine MA. Please try to refresh page.'; 359 $apikey = vine_ma_get_option('apikey'); 360 if( $apikey != null) { 361 $tokendata = vine_ma_get_authtoken($apikey); 362 $token = $tokendata['token']; 363 $error = $tokendata['error']; 364 if( $token == null ) 365 return array( 366 'forms' => array(), 367 'error' => "{$errorMessage} Token:{$error}" 368 ); 369 } else { 370 return array( 371 'forms' => array(), 372 'error' => "{$errorMessage} You are not logged in to Vine MA." 373 ); 374 } 375 $url=VINEHOST."/api/rest/2.0/VS_TRACK_FORM([FORMTYPE] <> 1 and [FORMTYPE] <> 2 and [FORMTYPE] <> 3 and [FORMTYPE] <> 4)?order=name&\$authtoken={$token}"; 376 $args = array( 377 'timeout' => 20, 378 'user-agent' => '' 379 ); 380 $html = wp_remote_get($url,$args); 381 $returncode = wp_remote_retrieve_response_code($html); 382 $body = wp_remote_retrieve_body($html); 383 if ( $returncode === 200 || $returncode === 304 ) { 384 $xml = new SimpleXMLElement($body); 385 $webforms = array(); 347 386 foreach($xml->xpath('//m:properties') as $event) { 348 387 array_push($webforms, array( 349 388 'id' => (string)$event->xpath('d:ID')[0], 350 'name' => (string)$event->xpath('d:NAME')[0],351 'type' => (string)$event->xpath('d:FORMTYPE')[0],389 'name' => (string)$event->xpath('d:NAME')[0], 390 'type' => (string)$event->xpath('d:FORMTYPE')[0], 352 391 )); 353 392 } 354 $timestamp = time();355 update_option( 'vine-plugin-web-forms-cache', array(356 'forms' => $webforms,357 'timestamp' => $timestamp358 ));359 return array(360 'forms' => $webforms,361 'error' => null362 );363 }364 else {365 return array(366 'forms' => array(),367 'error' => "{$errorMessage} Forms:" . ($errorcode ? "{$errorcode}:{$body}" : "Timed out" )368 );369 }393 $timestamp = time(); 394 update_option( 'vine-plugin-web-forms-cache', array( 395 'forms' => $webforms, 396 'timestamp' => $timestamp 397 )); 398 return array( 399 'forms' => $webforms, 400 'error' => null 401 ); 402 } 403 else { 404 return array( 405 'forms' => array(), 406 'error' => "{$errorMessage} Forms:" . ($returncode ? "{$returncode}:{$body}" : "Timed out" ) 407 ); 408 } 370 409 } 371 410 372 411 //check account multiorg status 373 412 function vine_ma_get_multiorg_status() { 374 $cache = get_option( 'vine-plugin-account-multiorgstatus-cache' );375 if(is_array( $cache) && $cache['timestamp'] != null && (time() - $cache['timestamp']) < 120)376 {377 return $cache['multiorgstatus'];378 }379 $errorMessage = 'An error occurred while communicating with Vine MA. Please try to refresh page.';380 $apikey = vine_ma_get_option('apikey');381 if( $apikey != null) {382 $tokendata = vine_ma_get_authtoken($apikey);383 $token = $tokendata['token'];384 $error = $tokendata['error'];385 if( $token == null )386 return false;387 } else {388 return false;389 }390 $url=VINEHOST."/api/rest/2.0/VY_USERGROUP([STATUS]='B' and [GROUPROLE] in ('SWITCHORGANIZATION','SWITCHTOANYORG'))?\$authtoken={$token}";391 $args = array(392 'timeout' => 20,393 'user-agent' => ''394 );395 $html = wp_remote_get($url,$args);396 $returncode = wp_remote_retrieve_response_code($html);397 if ( $returncode === 200 || $returncode === 304 ) {398 $body = wp_remote_retrieve_body($html);399 $xml = new SimpleXMLElement($body);400 $status = $xml->xpath('//m:count')[0] == 0 ? false : true;401 $timestamp = time();402 update_option( 'vine-plugin-account-multiorgstatus-cache', array(403 'multiorgstatus' => $status,404 'timestamp' => $timestamp405 ));406 return $status;407 }408 else {409 return false;410 }411 } 413 $cache = get_option( 'vine-plugin-account-multiorgstatus-cache' ); 414 if(is_array( $cache ) && isset($cache['timestamp']) && $cache['timestamp'] != null && (time() - $cache['timestamp']) < 120) 415 { 416 return isset($cache['multiorgstatus']) ? $cache['multiorgstatus'] : false; 417 } 418 $errorMessage = 'An error occurred while communicating with Vine MA. Please try to refresh page.'; 419 $apikey = vine_ma_get_option('apikey'); 420 if( $apikey != null) { 421 $tokendata = vine_ma_get_authtoken($apikey); 422 $token = $tokendata['token']; 423 $error = $tokendata['error']; 424 if( $token == null ) 425 return false; 426 } else { 427 return false; 428 } 429 $url=VINEHOST."/api/rest/2.0/VY_USERGROUP([STATUS]='B' and [GROUPROLE] in ('SWITCHORGANIZATION','SWITCHTOANYORG'))?\$authtoken={$token}"; 430 $args = array( 431 'timeout' => 20, 432 'user-agent' => '' 433 ); 434 $html = wp_remote_get($url,$args); 435 $returncode = wp_remote_retrieve_response_code($html); 436 if ( $returncode === 200 || $returncode === 304 ) { 437 $body = wp_remote_retrieve_body($html); 438 $xml = new SimpleXMLElement($body); 439 $status = $xml->xpath('//m:count')[0] == 0 ? false : true; 440 $timestamp = time(); 441 update_option( 'vine-plugin-account-multiorgstatus-cache', array( 442 'multiorgstatus' => $status, 443 'timestamp' => $timestamp 444 )); 445 return $status; 446 } 447 else { 448 return false; 449 } 450 } -
vine-ma/trunk/web_form_block.js
r2436326 r3429994 1 1 (function (blocks, element) { 2 2 var el = element.createElement; 3 4 function isBotForm(form) { 5 return form && String(form.type) === '5'; 6 } 3 7 4 8 var blockStyle = { … … 15 19 category: 'layout', 16 20 attributes: { 21 formtype: { 22 type: 'string', 23 default: 'static' 24 }, 25 formclass: { 26 type: 'string', 27 source: 'attribute', 28 selector: '.VineForm', 29 attribute: 'class' 30 }, 17 31 formid: { 18 32 type: 'string', … … 31 45 }, 32 46 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++) { 43 els.push( 44 el( 45 'option', 46 { value: vineforms[i].id }, 47 vineforms[i].name 48 ) 49 ); 47 const vineforms = (VineFormsData && VineFormsData.forms) ? VineFormsData.forms : []; 48 const legacyBotMatch = (props.attributes.formclass || '').match(/(?:^|\s)B(\d+)(?:\s|$)/); 49 const legacyBotId = legacyBotMatch ? String(legacyBotMatch[1]) : '-1'; 50 51 // Auto-migrate legacy bot blocks (class-only) so next save writes data-bot-id. 52 if (legacyBotId !== '-1' && props.attributes.botformid === '-1' && props.attributes.formid === '-1') { 53 props.setAttributes({ botformid: legacyBotId, formtype: 'bot' }); 50 54 } 51 function onChangeContent(newContent) { 52 props.setAttributes({ formid: newContent.target.value }); 55 56 const hasStaticId = props.attributes.formid && props.attributes.formid !== '-1'; 57 const hasBotId = (props.attributes.botformid && props.attributes.botformid !== '-1') || legacyBotId !== '-1'; 58 const inferredType = hasBotId && !hasStaticId ? 'bot' : 'static'; 59 const selectedType = (hasStaticId || hasBotId) ? inferredType : (props.attributes.formtype || 'static'); 60 const isBotType = selectedType === 'bot'; 61 62 // Auto-migrate formtype for pre-formtype blocks that already have an id. 63 if ((hasStaticId || hasBotId) && props.attributes.formtype !== inferredType) { 64 props.setAttributes({ formtype: inferredType }); 53 65 } 66 67 const filteredForms = vineforms.filter(function (f) { 68 return isBotType ? isBotForm(f) : !isBotForm(f); 69 }); 70 71 const els = []; 72 els.push(el('option', { value: '-1' }, '<not set>')); 73 for (const form of filteredForms) { 74 els.push(el('option', { value: String(form.id) }, form.name)); 75 } 76 77 function onChangeType(event) { 78 const newType = event.target.value; 79 if (newType === selectedType) return; 80 props.setAttributes({ 81 formtype: newType, 82 formid: '-1', 83 botformid: '-1' 84 }); 85 } 86 87 function onChangeForm(event) { 88 const newValue = String(event.target.value || '-1'); 89 if (isBotType) { 90 props.setAttributes({ botformid: newValue, formid: '-1', formtype: 'bot' }); 91 } else { 92 props.setAttributes({ formid: newValue, botformid: '-1', formtype: 'static' }); 93 } 94 } 95 96 const selectedId = isBotType 97 ? ((props.attributes.botformid && props.attributes.botformid !== '-1') ? props.attributes.botformid : legacyBotId) 98 : props.attributes.formid; 54 99 return el( 55 100 'div', 56 101 {}, 57 102 [ 103 el( 104 'div', 105 {}, 106 [ 107 el('span', {}, 'Form Type:'), 108 el( 109 'label', 110 { style: { marginLeft: '12px' } }, 111 [ 112 el('input', { 113 type: 'radio', 114 name: 'vine-form-type-' + props.clientId, 115 value: 'static', 116 checked: !isBotType, 117 onChange: onChangeType 118 }), 119 ' Static Form' 120 ] 121 ), 122 el( 123 'label', 124 { style: { marginLeft: '12px' } }, 125 [ 126 el('input', { 127 type: 'radio', 128 name: 'vine-form-type-' + props.clientId, 129 value: 'bot', 130 checked: isBotType, 131 onChange: onChangeType 132 }), 133 ' Bot Form' 134 ] 135 ) 136 ] 137 ), 58 138 el( 59 139 'span', … … 63 143 el( 64 144 'select', 65 { style: blockStyle, onChange: onChange Content, value: props.attributes.formid === '-1' ? props.attributes.botformid : props.attributes.formid},145 { style: blockStyle, onChange: onChangeForm, value: selectedId || '-1' }, 66 146 els 67 147 ) … … 70 150 }, 71 151 save: function (props) { 72 var form = props.attributes.formid === '-1' ? props.attributes.botformid : props.attributes.formid; 152 var form = (props.attributes.formtype === 'bot') ? props.attributes.botformid : props.attributes.formid; 153 if (form === '-1') 154 form = props.attributes.formid === '-1' ? props.attributes.botformid : props.attributes.formid; 73 155 var vineforms = VineFormsData.forms; 74 156 var targetForm = [];
Note: See TracChangeset
for help on using the changeset viewer.