function _routeRequest($request) { error_reporting(0); $fullReq = explode('&', $request); $req = explode('/', $fullReq[0]); $service = $req[1]; $action = $req[2]; if ($service == 'user') { if ($action == 'check' || $action == 'login') { wiziapp_check_login(); } elseif ($action == 'track') { wiziapp_user_push_subscription($req[3], $req[4]); /**} elseif($action == 'register'){ - Disabled for now $message = wiziapp_user_registration(); wiziapp_buildRegisterForm($message); */ } elseif ($action == 'forgot_pass') { $message = wiziapp_user_forgot_password(); wiziapp_buildForgotPassForm($message); } } elseif ($service == 'content' || $service == 'search') { // Content requests should trigger a the caching $cache = new WiziappCache(); $key = str_replace('/', '_', $request); $qs = str_replace('&', '_', $_SERVER['QUERY_STRING']); $qs = str_replace('=', '', $qs); $key .= $qs; $key .= wiziapp_getCacheTimestampKey(); global $wiziappLoader; $key .= $wiziappLoader->getVersion(); // Added the accept encoding headers, so we won't try to return zip when we can't $httpXcept = isset($_SERVER['HTTP_X_CEPT_ENCODING']) ? $_SERVER['HTTP_X_CEPT_ENCODING'] : ''; $httpAccept = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : ''; $etagHeader = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : ''; $key .= str_replace(', ', '_', "{$httpXcept}_{$httpAccept}_{$etagHeader}"); $key .= str_replace(',', '', $key); //if ( $cache->beginCache(md5($key)) ){ if ($cache->beginCache(md5($key), array('duration' => 30))) { $output = $this->_routeContent($req); $cache->endCache($output); if (!$output) { $GLOBALS['WiziappLog']->write('info', "Nothing to output the app should use the cache", "remote.WiziappRequestHandler._routeRequest"); /** * IIS needs us to be very specific */ header('Content-Length: 0'); $GLOBALS['WiziappLog']->write('info', "Sent the content-length", "remote.WiziappRequestHandler._routeRequest"); header("HTTP/1.1 304 Not Modified"); $GLOBALS['WiziappLog']->write('info', "sent 304 Not Modified for the app", "remote.WiziappRequestHandler._routeRequest"); } } /** * The content services are the only thing that will expose themselves and * do a clean exit, the rest of the services will pass the handling to wordpress * if they weren't able to process the request due to missing parameters and such */ exit; // } elseif( $service == 'rate' ) { // wiziapp_rate_content($req); } elseif ($service == 'getrate') { wiziapp_the_rating_wrapper($req); } elseif ($service == "getimage") { wiziapp_getImageUrl(); exit; } elseif ($service == "getthumb") { wiziapp_doPostThumbnail($req[2], array('width' => $_GET['width'], 'height' => $_GET['height']), array('width' => $_GET['limitWidth'], 'height' => $_GET['limitHeight'])); exit; } elseif ($service == 'post') { $GLOBALS['WiziappLog']->write('info', "Need to do something with post..:" . print_r($req, TRUE), "remote.WiziappRequestHandler._routeRequest"); if ($req[3] == "comments") { wiziapp_getCommentsCount($req[2]); } } elseif ($service == 'comment') { wiziapp_add_comment($request); /**} elseif ( $service == 'search' ){ $this->_routeContent($req); */ } elseif ($service == 'keywords') { wiziapp_get_search_keywords(); } elseif ($service == 'system') { if ($action == 'screens') { wiziapp_updateScreenConfiguration(); } else { if ($action == 'components') { wiziapp_updateComponentsConfiguration(); } else { if ($action == 'pages') { wiziapp_updatePagesConfiguration(); } else { if ($action == 'frame') { wiziapp_getCrossFrameHandler(); } else { if ($action == 'settings') { wiziapp_updateConfiguration(); } else { if ($action == 'thumbs') { wiziapp_updateThumbsConfiguration(); } else { if ($action == 'check') { wiziapp_checkInstalledPlugin(); } else { if ($action == 'logs') { wiziapp_listLogsWS(); } else { if ($action == 'getLog') { wiziapp_getLogFileWS($req[3]); } } } } } } } } } } }
function wiziapp_user_push_subscription($key, $val = '') { // Validate the user $user = wiziapp_check_login(TRUE); // @todo add validation to key and val if ($user != null && $user !== FALSE) { // The user is valid and can login to the service, // set his options for him if (!empty($key)) { $settings = get_usermeta($user->ID, 'wiziapp_push_settings'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!isset($settings[$key])) { $settings[$key] = array(); } $settings[$key][$val] = TRUE; } elseif ($_SERVER['REQUEST_METHOD'] == 'DELETE') { if (isset($settings[$key]) && isset($settings[$key][$val])) { unset($settings[$key][$val]); } } update_usermeta($user->ID, 'wiziapp_push_settings', $settings); // If we are here everything is ok $status = TRUE; echo json_encode(array('status' => $status)); exit; } } }