Changeset 2389533
- Timestamp:
- 09/28/2020 10:14:15 AM (5 years ago)
- Location:
- vine-ma
- Files:
-
- 3 added
- 3 edited
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-9.png (added)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/vine.js (added)
-
trunk/vine_ma_plugin.php (modified) (6 diffs)
-
trunk/web_form_block.js (added)
Legend:
- Unmodified
- Added
- Removed
-
vine-ma/trunk/readme.txt
r2364653 r2389533 22 22 == Changelog == 23 23 24 = 1.1.0 = 25 * MA Login added to plugin settings. Not necessary to enter the organization ID manually. 26 * Vine Web Form Gutenberg Block added to editor. Just insert the block and select a Vine Form. 27 24 28 = 1.0.0 = 25 29 * Initial Public Release … … 31 35 There is no option to use it without account 32 36 33 = Where can I find organization id for the plugin settings = 34 35 You can get it from Vine MA / Settings / Tracking page. Login to your account in https://vine.eu/ma/ 37 == Upgrade Notice == 36 38 37 == Upgrade Notice == 39 = 1.1 = 40 MA Login added to plugin settings 38 41 39 42 = 1.0 = … … 50 53 7. Landing Page Usage Statistics 51 54 8. Workflow Automation Diagram 55 9. Vine Web Form Gutenberg Block 52 56 53 57 -
vine-ma/trunk/vine_ma_plugin.php
r2338535 r2389533 3 3 /** 4 4 * Plugin Name: Vine MA - Email Marketing, Forms, Interactive Bot Forms, Chatbot, Analytics 5 * Version: 1. 0.05 * Version: 1.1.0 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 … … 12 12 */ 13 13 14 14 define("VINEHOST", "https://vine.eu"); 15 15 16 16 // add menu item to wordpress admin dashboard … … 21 21 add_action( 'admin_menu', 'vine_ma_menu' ); 22 22 add_action( 'admin_init', 'vine_ma_register_plugin_settings' ); 23 add_action( 'admin_enqueue_scripts', 'vine_ma_add_vine_script'); 24 25 function vine_ma_add_vine_script($hook) { 26 wp_enqueue_script('vine_script', plugin_dir_url(__FILE__) . '/vine.js'); 27 } 23 28 24 29 function vine_ma_add_plugin_page_settings_link( $links ) { … … 29 34 } 30 35 31 32 36 // add settings link to the plugin item 33 37 add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'vine_ma_add_plugin_page_settings_link'); … … 36 40 ?> 37 41 <h2>Vine MA</h2> 38 < form action="options.php" method="post"style="padding-right: 20px">42 <div style="padding-right: 20px"> 39 43 <?php 40 44 settings_fields('vine-plugin-options'); 41 45 do_settings_sections('vine_ma_plugin'); ?> 42 <input name="submit" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Save' ); ?>" /> 43 </form> 46 </div> 44 47 <?php 45 48 } … … 55 58 function vine_ma_render_help_text() { 56 59 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>"; 57 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>"; 58 echo "<p>Please fill the organization ID below. You can get it from Vine MA / Settings / Tracking page. Login to your account in <a target='_blank' href='https://vine.eu/ma/'>https://vine.eu/ma/</a></p>"; 60 61 $apikey = vine_ma_get_option('apikey'); 62 $token = null; 63 if( $apikey != null) 64 { 65 $token = vine_ma_get_authtoken($apikey); 66 } 67 if( $token != null ) { 68 echo "<p>You are currently connected to MA</p>"; 69 echo "<p><a href='javascript:logoutFromMA();'>Logout from MA</a></p>"; 70 } 71 else { 72 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>"; 73 echo "<p><a id='vinemaloginbtn' href='javascript:openMaLoginWindow();'>Login to MA</a></p>"; 74 } 59 75 } 60 76 function vine_ma_plugin_setting_organization_id() { 61 $o ptions = get_option( 'vine-plugin-options');62 echo "<input id='vine_ma_plugin_setting_organization_id' name='vine-plugin-options[organization_id]' type='text' value='{$o ptions['organization_id']}'/>";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 />"; 63 79 } 64 80 65 81 //add 'Vine' script to WP pages by using organization id settings 66 82 function vine_ma_wpes_hook_add_script() { 83 $orgid = vine_ma_get_option('organization_id'); 84 $src = VINEHOST."/track/t.js?sg={$orgid}"; 85 wp_enqueue_script('vinematrack', $src, array(), null); 86 } 87 add_action( 'wp_enqueue_scripts', 'vine_ma_wpes_hook_add_script'); 88 89 add_action( 'wp_ajax_vine_ma_save_option', 'vine_ma_hook_save_option' ); 90 91 //get vine temporary token 92 function vine_ma_get_authtoken($apikey) { 93 if($apikey === '' || $apikey == null) 94 return null; 95 $url= VINEHOST.'/api/rest/2.0/login'; 96 $args = array( 97 'timeout' => 120, 98 'headers' => array( 99 'Content-Type' => 'application/json', 100 'x-api-key' => $apikey 101 ) 102 ); 103 $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; 108 } 109 110 //logout hook 111 add_action( 'wp_ajax_vine_ma_logout', 'vine_ma_hook_logout' ); 112 113 //get user organization id 114 function vine_ma_get_organizationid($token) { 115 $url=VINEHOST."/api/rest/2.0/vy_user?\$authtoken={$token}"; 116 $args = array( 117 'timeout' => 120 118 ); 119 $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 127 return null; 128 } 129 130 //save constant api key 131 function vine_ma_hook_save_option() { 132 $apikey = $_POST['apikey']; 133 $token = vine_ma_get_authtoken($apikey); 134 $organizationid = vine_ma_get_organizationid($token); 135 update_option( 'vine-plugin-options' ,array( 136 'organization_id' => $organizationid, 137 'apikey' => $apikey 138 )); 139 //echo $organizationid; 140 wp_die(); 141 } 142 143 //logaout action, remove api key 144 function vine_ma_hook_logout() { 145 update_option( 'vine-plugin-options' ,array( 146 'organization_id' => '', 147 'apikey' => '' 148 )); 149 //echo $organizationid; 150 wp_die(); 151 } 152 153 //banner hook 154 function vine_ma_admin_notice() 155 { 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"> 165 <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 <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'/> 167 <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'/> 168 <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'/> 169 <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'/> 170 <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 </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 176 } 177 178 //subscribe to admin notices event 179 add_action( 'admin_notices', 'vine_ma_admin_notice' ); 180 181 //register vine web form block hook 182 add_action( 'init', 'vine_ma_gutenberg_register_web_form_block' ); 183 184 //vine web block hook 185 function vine_ma_gutenberg_register_web_form_block() { 186 if ( ! function_exists( 'register_block_type' ) ) { 187 // Gutenberg is not active. 188 return; 189 } 190 191 wp_register_script( 192 'vine-web-form-01', 193 plugins_url( 'web_form_block.js', __FILE__ ), 194 array( 'wp-blocks', 'wp-element' ) 195 ); 196 197 $webforms = vine_ma_get_web_forms(); 198 199 wp_localize_script('vine-web-form-01', 'VineFormsData', $webforms); 200 201 register_block_type( 'vine-ma-plugin/vine-web-form', array( 202 'editor_script' => 'vine-web-form-01' 203 ) 204 ); 205 } 206 207 //get plugins options function 208 function vine_ma_get_option($name) { 67 209 $options = get_option( 'vine-plugin-options' ); 68 $orgid = $options['organization_id']; 69 $src = "https://vine.eu/track/t.js?sg={$orgid}"; 70 wp_enqueue_script('vinematrack', $src, array(), null); 71 } 72 add_action('wp_enqueue_scripts', 'vine_ma_wpes_hook_add_script'); 210 if(!is_array( $options ) || $options[$name] == null || $options[$name] == '') 211 return null; 212 return $options[$name]; 213 } 214 215 //get vine web forms via rest api 216 function vine_ma_get_web_forms() { 217 $apikey = vine_ma_get_option('apikey'); 218 $token = null; 219 if( $apikey != null) { 220 $token = vine_ma_get_authtoken($apikey); 221 if( $token == null ) 222 return array(); 223 } 224 $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 $args = array( 226 'timeout' => 120 227 ); 228 $html = wp_remote_get($url,$args); 229 if ( is_array( $html ) && !is_wp_error( $html ) && $html['body'] != 'Unauthorized') { 230 $xml = new SimpleXMLElement($html['body']); 231 $webforms = array(); 232 foreach($xml->xpath('//m:properties') as $event) { 233 array_push($webforms, array( 234 'id' => (string)$event->xpath('d:ID')[0], 235 'name' => (string)$event->xpath('d:NAME')[0], 236 'type' => (string)$event->xpath('d:FORMTYPE')[0], 237 )); 238 } 239 return $webforms; 240 } 241 else 242 return array(); 243 }
Note: See TracChangeset
for help on using the changeset viewer.