'user_id' => (int) $user->ID, 'url' => $article_url, ), 5 * MINUTE_IN_SECONDS ); return rest_ensure_response(array( 'success' => true, 'url' => add_query_arg( array('session' => rawurlencode($session_key)), home_url('/wp-json/hsf/v1/article-open') ), )); } function hsf_mobile_open_article_session(WP_REST_Request $request) { $session_key = sanitize_text_field((string) $request->get_param('session')); if (!$session_key) { return hsf_mobile_json_error('Missing article session.', 400); } $session = get_transient('hsf_article_session_' . $session_key); delete_transient('hsf_article_session_' . $session_key); if (empty($session['user_id']) || empty($session['url'])) { return hsf_mobile_json_error('Article session expired.', 401); } $user_id = (int) $session['user_id']; wp_set_current_user($user_id); wp_set_auth_cookie($user_id, true, is_ssl()); wp_safe_redirect(esc_url_raw($session['url'])); exit; } function hsf_mobile_save_article_reaction(WP_REST_Request $request) { $user = hsf_mobile_user_from_bearer_token($request); if (!$user) { return hsf_mobile_json_error('Article reactions are installed, but they are not connected to the mobile token validator yet.', 401); } $article_url = esc_url_raw((string) $request->get_param('url')); $reaction = sanitize_key((string) $request->get_param('reaction')); $allowed = array('heart', 'thumbs_up', 'prayers', 'smile', 'sad', 'thumbs_down'); if (!$article_url || !hsf_mobile_is_allowed_article_url($article_url)) { return hsf_mobile_json_error('Invalid article URL.', 400); } if (!in_array($reaction, $allowed, true)) { return hsf_mobile_json_error('Invalid reaction.', 400); } $post_id = url_to_postid($article_url); if (!$post_id) { return hsf_mobile_json_error('Article not found.', 404); } update_user_meta((int) $user->ID, 'hsf_reaction_' . $post_id, $reaction); $counts = get_post_meta($post_id, 'hsf_reaction_counts', true); if (!is_array($counts)) { $counts = array(); } $counts[$reaction] = isset($counts[$reaction]) ? ((int) $counts[$reaction] + 1) : 1; update_post_meta($post_id, 'hsf_reaction_counts', $counts); return rest_ensure_response(array( 'success' => true, 'reaction' => $reaction, 'message' => 'Reaction saved.', )); } function hsf_mobile_is_allowed_article_url($url) { $home_host = wp_parse_url(home_url(), PHP_URL_HOST); $url_host = wp_parse_url($url, PHP_URL_HOST); return $home_host && $url_host && strtolower($home_host) === strtolower($url_host); } function hsf_mobile_user_from_bearer_token(WP_REST_Request $request) { $header = $request->get_header('authorization'); if (!$header && function_exists('getallheaders')) { $headers = getallheaders(); if (!empty($headers['Authorization'])) { $header = $headers['Authorization']; } elseif (!empty($headers['authorization'])) { $header = $headers['authorization']; } } if (!$header && !empty($_SERVER['HTTP_AUTHORIZATION'])) { $header = $_SERVER['HTTP_AUTHORIZATION']; } if (!$header && !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { $header = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; } $token = ''; if ($header && preg_match('/Bearer\s+(.*)$/i', $header, $matches)) { $token = trim($matches[1]); } if (!$token) { return null; } if (function_exists('hsf_mobile_get_user_from_token')) { return hsf_mobile_get_user_from_token($token); } if (function_exists('hsf_get_user_from_mobile_token')) { return hsf_get_user_from_mobile_token($token); } if (!class_exists('HSF_Mobile_API')) { return null; } $token_hash = hash('sha256', $token); $users = get_users(array( 'meta_key' => HSF_Mobile_API::TOKEN_META_KEY, 'meta_value' => $token_hash, 'number' => 1, 'fields' => 'all', )); if (empty($users)) { return null; } return $users[0]; } function hsf_mobile_json_error($message, $status) { return new WP_REST_Response( array( 'success' => false, 'message' => $message, ), $status ); } FD/PD: Sea Venture Drive – Havasu Scanner Feed, LLC.

FD/PD: Sea Venture Drive

Posted . (SUPPORT ID: 110166) — Your IP Address (18.97.9.170) has been logged.

I’m sorry, you are not logged in.

  

Back To Top