Plugin Directory

Changeset 2436326


Ignore:
Timestamp:
12/10/2020 08:59:54 AM (5 years ago)
Author:
vinema
Message:

v1.1.1, some bugfixing

Location:
vine-ma/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • vine-ma/trunk/readme.txt

    r2389569 r2436326  
    2121
    2222== Changelog ==
     23
     24= 1.1.1 =
     25* Some bugfixing
    2326
    2427= 1.1.0 =
  • vine-ma/trunk/vine.js

    r2389533 r2436326  
    11var vinehost = "https://vine.eu"
    22
    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       };
     3window.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        };
    99
    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    }
    1616});
    1717
     
    1919
    2020function 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');
    2222}
    2323
    2424function logoutFromMA() {
    25    var data = {
    26      action: 'vine_ma_logout'
    27    };
     25    var data = {
     26        action: 'vine_ma_logout'
     27    };
    2828
    29    jQuery.post( ajaxurl, data, function(response) {
    30       location.reload();
    31    });
     29    jQuery.post(ajaxurl, data, function (response) {
     30        location.reload();
     31    });
    3232}
  • vine-ma/trunk/vine_ma_plugin.php

    r2389533 r2436326  
    33/**
    44 * Plugin Name: Vine MA - Email Marketing, Forms, Interactive Bot Forms, Chatbot, Analytics
    5  * Version: 1.1.0
     5 * Version: 1.1.1
    66 * 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.
    77 * Author: Vine Oy
     
    1313
    1414define("VINEHOST", "https://vine.eu");
     15
    1516
    1617// add menu item to wordpress admin dashboard
     
    5253    register_setting( 'vine-plugin-options', 'vine-plugin-options');
    5354    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');
    5456    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');
    5558}
    5659
     
    6164    $apikey = vine_ma_get_option('apikey');
    6265    $token = null;
    63     if( $apikey != null)
     66    if( $apikey != null )
    6467    {
    65         $token = vine_ma_get_authtoken($apikey);
    66     }
    67     if( $token != null ) {
    6868        echo "<p>You are currently connected to MA</p>";
    6969        echo "<p><a href='javascript:logoutFromMA();'>Logout from MA</a></p>";
     
    7676function vine_ma_plugin_setting_organization_id() {
    7777    $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
     81function 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 />";
    7986}
    8087
     
    95102    $url= VINEHOST.'/api/rest/2.0/login';
    96103    $args = array(
    97       'timeout' => 120,
     104      'timeout' => 20,
    98105      'headers' => array(
    99106        'Content-Type' => 'application/json',
    100         'x-api-key' => $apikey
     107        'x-api-key' => $apikey,
     108        'user-agent'  =>  ''
    101109      )
    102110    );
    103111    $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    }
    108126}
    109127
     
    112130
    113131//get user organization id
    114 function vine_ma_get_organizationid($token) {
     132function vine_ma_get_organizationid_username($token) {
    115133    $url=VINEHOST."/api/rest/2.0/vy_user?\$authtoken={$token}";
    116134    $args = array(
    117       'timeout' => 120
     135      'timeout' => 20,
     136      'user-agent'  =>  ''
    118137    );
    119138    $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 {
    127155        return null;
     156    }
    128157}
    129158
     
    131160function vine_ma_hook_save_option() {
    132161    $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);
    135165    update_option( 'vine-plugin-options' ,array(
    136         'organization_id' => $organizationid,
     166        'organization_id' => $userdata['orgid'],
     167        'username' => $userdata['username'],
    137168        'apikey' => $apikey
    138169      ));
     
    145176    update_option( 'vine-plugin-options' ,array(
    146177        'organization_id' => '',
     178        'username' => '',
    147179        'apikey' => ''
    148180      ));
     181    update_option( 'vine-plugin-web-forms-cache', array());
    149182    //echo $organizationid;
    150183    wp_die();
     
    154187function vine_ma_admin_notice()
    155188{
    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">
    165191            <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'/>
    166192                <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'/>
     
    170196                <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'/>
    171197        </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    }
    176227}
    177228
     
    184235//vine web block hook
    185236function vine_ma_gutenberg_register_web_form_block() {
     237    global $pagenow;
     238    if ( $pagenow != 'post.php' )
     239        return;
    186240    if ( ! function_exists( 'register_block_type' ) ) {
    187241        // Gutenberg is not active.
     
    208262function vine_ma_get_option($name) {
    209263    $options = get_option( 'vine-plugin-options' );
    210     if(!is_array( $options ) || $options[$name] == null || $options[$name] == '')
     264    if(!is_array( $options ) || $options[$name] == '')
    211265        return null;
    212266    return $options[$name];
     
    215269//get vine web forms via rest api
    216270function 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.';
    217280    $apikey = vine_ma_get_option('apikey');
    218     $token = null;
    219281    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'];
    221285      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        );
    223295    }
    224296    $url=VINEHOST."/api/rest/2.0/VS_TRACK_FORM([FORMTYPE] <> 1 and [FORMTYPE] <> 2 and [FORMTYPE] <> 3 and [FORMTYPE] <> 4)?order=name&\$authtoken={$token}";
    225297    $args = array(
    226       'timeout' => 120
     298      'timeout' => 20,
     299      'user-agent'  =>  ''
    227300    );
    228301    $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);
    231306        $webforms = array();
    232307        foreach($xml->xpath('//m:properties') as $event) {
     
    237312          ));
    238313        }
    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) {
    22    var el = element.createElement;
    33
     
    77    };
    88
    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++) {
    4243                    els.push(
    4344                        el(
    44                         'option',
    45                         {value: vineforms[i].id},
    46                         vineforms[i].name
    47                     )
     45                            'option',
     46                            { value: vineforms[i].id },
     47                            vineforms[i].name
     48                        )
    4849                    );
    4950                }
    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                       els
    66                     )
    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 : undefined
    83             }
    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        });
    9192}(
    9293    window.wp.blocks,
    9394    window.wp.element
    94 ) );
     95));
Note: See TracChangeset for help on using the changeset viewer.