Changeset 2001693
- Timestamp:
- 12/26/2018 01:11:11 PM (7 years ago)
- Location:
- here-mobility/trunk
- Files:
-
- 3 edited
-
heremobility.php (modified) (7 diffs)
-
js/loader.js (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
here-mobility/trunk/heremobility.php
r2001637 r2001693 64 64 $options = get_option(HereMobility_Settings::HERE_OPTIONS); 65 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 66 77 if (($options[HereMobility_Settings::APP_KEY_OPTION] && $options[HereMobility_Settings::APP_SECRET_OPTION]) 67 78 && $_POST['application_key'] == $options[HereMobility_Settings::APP_KEY_OPTION]) { … … 70 81 $appSecret = $options[HereMobility_Settings::APP_SECRET_OPTION]; 71 82 72 if ($options[HereMobility_Settings::USE_CURRENT_WP_USER] && is_user_logged_in()) {73 $current_user = wp_get_current_user();74 $user = $current_user->user_email;75 } else {76 $user = $this->generateRandomUser();77 }78 79 83 $authData = $this->get_auth_data($appKey, $appSecret, $user); 80 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 } 81 97 } 82 98 … … 157 173 { 158 174 // Attributes 159 $attrs = shortcode_atts(175 $attrs = array_merge( 160 176 array( 161 177 'pickup' => '', 162 178 'destination' => '', 163 179 'id' => '', 164 'app Key' => '',165 'app Secret' => ''180 'appkey' => '', 181 'appsecret' => '' 166 182 ), 167 $attrs183 array_change_key_case($attrs, CASE_LOWER) 168 184 ); 169 185 … … 175 191 176 192 if (($options[HereMobility_Settings::APP_KEY_OPTION] && $options[HereMobility_Settings::APP_SECRET_OPTION]) 177 || ($attrs['app Key'] && $attrs['appSecret'])) {193 || ($attrs['appkey'] && $attrs['appsecret'])) { 178 194 $options = get_option(HereMobility_Settings::HERE_OPTIONS); 179 $appKey = $attrs['app Key'] ?: $options[HereMobility_Settings::APP_KEY_OPTION];180 $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]; 181 197 182 198 if ($options[HereMobility_Settings::USE_CURRENT_WP_USER] && is_user_logged_in()) { … … 196 212 'authData' => $this->get_auth_data($appKey, $appSecret, $user), 197 213 'auth_ajax_url' => admin_url('admin-ajax.php'), 198 'auth_ajax_action' => self::GET_AUTH_ACTION 214 'auth_ajax_action' => self::GET_AUTH_ACTION, 215 'post_id' => get_the_ID() 199 216 ]); 200 217 return "<div class='wordpress-hmw' id='" . $attrs['id'] . "'></div><div id='table-booking-date'></div>"; … … 211 228 function get_auth_data($appKey, $appSecret, $user) 212 229 { 213 $expiration = time() + 2 *60 * 60;230 $expiration = time() + 60 * 60; 214 231 215 232 $hash = hash_hmac( … … 359 376 360 377 new HereMobility(); 361 -
here-mobility/trunk/js/loader.js
r2001637 r2001693 24 24 }); 25 25 26 var d = new Date(Date.now() + 24 * 60 * 60 * 1000); // tomorrow27 hmw({28 eventTime: d.getTime(),29 pickup: hereLoaderData.pickup,30 destination: hereLoaderData.destination,31 // timezone: 'Europe/Paris',32 locale: hereLoaderData.locale || 'en-US',33 auth: hereLoaderData.authData,34 });35 36 26 setTimeout(function () { 37 27 jQuery(document).ready(function(_) { 38 28 39 if ((Date.now()/1000 - hereLoaderData.authData.expiration) > 0){40 var postData = {41 'action': hereLoaderData.auth_ajax_action,42 'application_key': hereLoaderData.authData.application_key43 };29 var postData = { 30 'action': hereLoaderData.auth_ajax_action, 31 'application_key': hereLoaderData.appKey, 32 'post_id': hereLoaderData.post_id 33 }; 44 34 45 jQuery.post(hereLoaderData.auth_ajax_url, postData, function(response) { 46 if (response) { 47 hmw({ 48 auth: JSON.parse(response) 49 }); 50 } 51 }); 52 } 35 jQuery.post(hereLoaderData.auth_ajax_url, postData, function(response) { 36 if (response) { 53 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 }); 54 48 }); 55 49 }, 0); -
here-mobility/trunk/readme.txt
r2001109 r2001693 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.