Changeset 2001695
- Timestamp:
- 12/26/2018 01:14:25 PM (7 years ago)
- Location:
- here-mobility/tags/1.0.5
- Files:
-
- 3 edited
-
heremobility.php (modified) (8 diffs)
-
js/loader.js (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
here-mobility/tags/1.0.5/heremobility.php
r2001110 r2001695 20 20 const SHORTCODE_WIDGET_TAG = 'here_panel'; 21 21 const SHORTCODE_LINK_TAG = 'here_link'; 22 const GET_AUTH_ACTION = 'get_auth_action'; 22 23 const WIDGET_URL = 'https://marketplace.mobility.here.com/web-widget/widget.js'; 23 24 … … 52 53 add_shortcode(self::SHORTCODE_LINK_TAG, array($this, 'link_shortcode_handler')); 53 54 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 54 58 register_deactivation_hook(__FILE__, array($this, 'here_deactivation')); 55 59 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'add_action_links')); 56 60 } 57 61 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 } 58 101 59 102 function register_block_type_function() … … 130 173 { 131 174 // Attributes 132 $attrs = shortcode_atts(175 $attrs = array_merge( 133 176 array( 134 177 'pickup' => '', 135 178 'destination' => '', 136 179 'id' => '', 137 'app Key' => '',138 'app Secret' => ''180 'appkey' => '', 181 'appsecret' => '' 139 182 ), 140 $attrs183 array_change_key_case($attrs, CASE_LOWER) 141 184 ); 142 185 … … 148 191 149 192 if (($options[HereMobility_Settings::APP_KEY_OPTION] && $options[HereMobility_Settings::APP_SECRET_OPTION]) 150 || ($attrs['app Key'] && $attrs['appSecret'])) {193 || ($attrs['appkey'] && $attrs['appsecret'])) { 151 194 $options = get_option(HereMobility_Settings::HERE_OPTIONS); 152 $appKey = $attrs['app Key'] ?: $options[HereMobility_Settings::APP_KEY_OPTION];153 $appSecret = $attrs['app Secret'] ?: $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]; 154 197 155 198 if ($options[HereMobility_Settings::USE_CURRENT_WP_USER] && is_user_logged_in()) { … … 167 210 'appKey' => $appKey, 168 211 '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() 170 216 ]); 171 217 return "<div class='wordpress-hmw' id='" . $attrs['id'] . "'></div><div id='table-booking-date'></div>"; … … 182 228 function get_auth_data($appKey, $appSecret, $user) 183 229 { 184 $expiration = time() + 25 * 60 * 60; 230 $expiration = time() + 60 * 60; 231 185 232 $hash = hash_hmac( 186 233 'sha256', … … 231 278 { 232 279 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); 234 281 wp_enqueue_style('wordpress_hmw', plugins_url('css/wordpress-hmw.css', __FILE__)); 235 282 } … … 329 376 330 377 new HereMobility(); 331 -
here-mobility/tags/1.0.5/js/loader.js
r2001110 r2001695 1 1 2 (function (w, i, d, g, e, t) { 2 3 var h = 'HereMobilityWidget'; … … 14 15 s.src = d + '?a=' + t + '&b=' + (w[e].t / 864e5 | 0); 15 16 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); 17 18 18 19 jQuery('em.here-destination').on('click', function () { … … 23 24 }); 24 25 26 setTimeout(function () { 27 jQuery(document).ready(function(_) { 25 28 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 74 74 == Changelog == 75 75 76 = 1.0.5 = 77 * Fixed cache bug 78 76 79 = 1.0.3 = 77 80 * Added support of gutenberg text editor
Note: See TracChangeset
for help on using the changeset viewer.