Plugin Directory

Changeset 2001695


Ignore:
Timestamp:
12/26/2018 01:14:25 PM (7 years ago)
Author:
heremobilitydemand
Message:

Tagged version 1.0.5

Location:
here-mobility/tags/1.0.5
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • here-mobility/tags/1.0.5/heremobility.php

    r2001110 r2001695  
    2020    const SHORTCODE_WIDGET_TAG = 'here_panel';
    2121    const SHORTCODE_LINK_TAG = 'here_link';
     22    const GET_AUTH_ACTION = 'get_auth_action';
    2223    const WIDGET_URL = 'https://marketplace.mobility.here.com/web-widget/widget.js';
    2324
     
    5253        add_shortcode(self::SHORTCODE_LINK_TAG, array($this, 'link_shortcode_handler'));
    5354
     55        add_action( 'wp_ajax_get_auth_action', array($this, self::GET_AUTH_ACTION));
     56        add_action( 'wp_ajax_nopriv_get_auth_action', array($this, self::GET_AUTH_ACTION));
     57
    5458        register_deactivation_hook(__FILE__, array($this, 'here_deactivation'));
    5559        add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'add_action_links'));
    5660    }
    5761
     62    function get_auth_action($data)
     63    {
     64        $options = get_option(HereMobility_Settings::HERE_OPTIONS);
     65
     66        if (!isset($_POST['application_key'])) {
     67            wp_die();
     68        }
     69
     70        if ($options[HereMobility_Settings::USE_CURRENT_WP_USER] && is_user_logged_in()) {
     71            $current_user = wp_get_current_user();
     72            $user = $current_user->user_email;
     73        } else {
     74            $user = $this->generateRandomUser();
     75        }
     76
     77        if (($options[HereMobility_Settings::APP_KEY_OPTION] && $options[HereMobility_Settings::APP_SECRET_OPTION])
     78            && $_POST['application_key'] == $options[HereMobility_Settings::APP_KEY_OPTION]) {
     79            $options = get_option(HereMobility_Settings::HERE_OPTIONS);
     80            $appKey = $options[HereMobility_Settings::APP_KEY_OPTION];
     81            $appSecret = $options[HereMobility_Settings::APP_SECRET_OPTION];
     82
     83            $authData = $this->get_auth_data($appKey, $appSecret, $user);
     84            echo json_encode($authData);
     85        } elseif (!empty($_POST['post_id'])  && !empty($_POST['application_key']) && $content_post = get_post($_POST['post_id'])){
     86            $content = htmlspecialchars_decode($content_post->post_content);
     87
     88            preg_match('/appSecret="([^"]+)"/i', $content, $matchesTinyMce);
     89            preg_match('/"appSecret":"([^"]+)"/i', $content, $matchesGutenBerg);
     90
     91            $appSecret = isset($matchesTinyMce[1]) ? $matchesTinyMce[1] : (isset($matchesGutenBerg[1]) ? $matchesGutenBerg[1] : null);
     92
     93            if ($appSecret) {
     94                $authData = $this->get_auth_data($_POST['application_key'], $appSecret, $user);
     95                echo json_encode($authData);
     96            }
     97        }
     98
     99        wp_die();
     100    }
    58101
    59102    function register_block_type_function()
     
    130173    {
    131174        // Attributes
    132         $attrs = shortcode_atts(
     175        $attrs = array_merge(
    133176            array(
    134177                'pickup' => '',
    135178                'destination' => '',
    136179                'id' => '',
    137                 'appKey' => '',
    138                 'appSecret' => ''
     180                'appkey' => '',
     181                'appsecret' => ''
    139182            ),
    140             $attrs
     183            array_change_key_case($attrs, CASE_LOWER)
    141184        );
    142185
     
    148191
    149192        if (($options[HereMobility_Settings::APP_KEY_OPTION] && $options[HereMobility_Settings::APP_SECRET_OPTION])
    150             || ($attrs['appKey'] && $attrs['appSecret'])) {
     193            || ($attrs['appkey'] && $attrs['appsecret'])) {
    151194            $options = get_option(HereMobility_Settings::HERE_OPTIONS);
    152             $appKey = $attrs['appKey'] ?: $options[HereMobility_Settings::APP_KEY_OPTION];
    153             $appSecret = $attrs['appSecret'] ?: $options[HereMobility_Settings::APP_SECRET_OPTION];
     195            $appKey = $attrs['appkey'] ?: $options[HereMobility_Settings::APP_KEY_OPTION];
     196            $appSecret = $attrs['appsecret'] ?: $options[HereMobility_Settings::APP_SECRET_OPTION];
    154197
    155198            if ($options[HereMobility_Settings::USE_CURRENT_WP_USER] && is_user_logged_in()) {
     
    167210                'appKey' => $appKey,
    168211                'locale' => $options[HereMobility_Settings::LOCALIZATION_OPTION],
    169                 'authData' => $this->get_auth_data($appKey, $appSecret, $user)
     212                'authData' => $this->get_auth_data($appKey, $appSecret, $user),
     213                'auth_ajax_url' => admin_url('admin-ajax.php'),
     214                'auth_ajax_action' => self::GET_AUTH_ACTION,
     215                'post_id' => get_the_ID()
    170216            ]);
    171217            return "<div class='wordpress-hmw' id='" . $attrs['id'] . "'></div><div id='table-booking-date'></div>";
     
    182228    function get_auth_data($appKey, $appSecret, $user)
    183229    {
    184         $expiration = time() + 25 * 60 * 60;
     230        $expiration = time() + 60 * 60;
     231
    185232        $hash = hash_hmac(
    186233            'sha256',
     
    231278    {
    232279        wp_enqueue_script('here_loader', plugins_url('js/loader.js', __FILE__), array('jquery'), self::PLUGIN_VERSION, TRUE);
    233         wp_localize_script('here_loader', 'data', $data);
     280        wp_localize_script('here_loader', 'hereLoaderData', $data);
    234281        wp_enqueue_style('wordpress_hmw', plugins_url('css/wordpress-hmw.css', __FILE__));
    235282    }
     
    329376
    330377new HereMobility();
    331 
  • here-mobility/tags/1.0.5/js/loader.js

    r2001110 r2001695  
     1
    12(function (w, i, d, g, e, t) {
    23    var h = 'HereMobilityWidget';
     
    1415    s.src = d + '?a=' + t + '&b=' + (w[e].t / 864e5 | 0);
    1516    i.querySelector('#' + g) && i.querySelector('#' + g).appendChild(s);
    16 })(window, document, data.widgetUrl, data.id, 'hmw', data.appKey);
     17})(window, document, hereLoaderData.widgetUrl, hereLoaderData.id, 'hmw', hereLoaderData.appKey);
    1718
    1819jQuery('em.here-destination').on('click', function () {
     
    2324});
    2425
     26setTimeout(function () {
     27    jQuery(document).ready(function(_) {
    2528
    26 var d = new Date(Date.now() + 24 * 60 * 60 * 1000); // tomorrow
    27 hmw({
    28     eventTime: d.getTime(),
    29     pickup: data.pickup,
    30     destination: data.destination,
    31     // timezone: 'Europe/Paris',
    32     locale: data.locale || 'en-US',
    33   auth: data.authData,
    34 });
     29        var postData = {
     30            'action': hereLoaderData.auth_ajax_action,
     31            'application_key': hereLoaderData.appKey,
     32            'post_id': hereLoaderData.post_id
     33        };
     34
     35        jQuery.post(hereLoaderData.auth_ajax_url, postData, function(response) {
     36            if (response) {
     37
     38                var d = new Date(Date.now() + 24 * 60 * 60 * 1000); // tomorrow
     39                hmw({
     40                    eventTime: d.getTime(),
     41                    pickup: hereLoaderData.pickup,
     42                    destination: hereLoaderData.destination,
     43                    locale: hereLoaderData.locale || 'en-US',
     44                    auth: JSON.parse(response)
     45                });
     46            }
     47        });
     48    });
     49}, 0);
     50
  • here-mobility/tags/1.0.5/readme.txt

    r2001110 r2001695  
    7474== Changelog ==
    7575
     76= 1.0.5 =
     77* Fixed cache bug
     78
    7679= 1.0.3 =
    7780* Added support of gutenberg text editor
Note: See TracChangeset for help on using the changeset viewer.