예제 #1
0
 /**
  * Sends the response as a JSON encoded string
  *
  * @param	mixed	The data (usually an array) to send
  */
 public function sendAsJson($data)
 {
     //This function needs to be kept in sync with the implmentation in applicationlight.php
     if (headers_sent($file, $line)) {
         throw new Exception("Cannot send response, headers already sent. File: {$file} Line: {$line}");
     }
     // We need to convert $data charset if we're not using UTF-8
     if (vB5_String::getTempCharset() != 'UTF-8') {
         $data = vB5_String::toCharset($data, vB5_String::getTempCharset(), 'UTF-8');
     }
     //If this is IE9, IE10, or IE11 -- we also need to work around the deliberate attempt to break "is IE" logic by the
     //IE dev team -- we need to send type "text/plain". Yes, we know that's not the standard.
     if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false or strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false)) {
         header('Content-type: text/plain; charset=UTF-8');
     } else {
         header('Content-type: application/json; charset=UTF-8');
     }
     // IE will cache ajax requests, and we need to prevent this - VBV-148
     header('Cache-Control: max-age=0,no-cache,no-store,post-check=0,pre-check=0');
     header('Expires: Sat, 1 Jan 2000 01:00:00 GMT');
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Pragma: no-cache");
     if (isset($data['template']) and !empty($data['template'])) {
         $data['template'] = $this->outputPage($data['template'], false);
     }
     echo vB5_String::jsonEncode($data);
 }
예제 #2
0
 public function actionOutput()
 {
     $api = Api_InterfaceAbstract::instance();
     $response = $api->callApi('session', 'getGuestSession');
     if (is_array($response) and !empty($response['errors'])) {
         return '';
     }
     $type = !empty($_REQUEST['type']) ? $_REQUEST['type'] : '';
     // default rss2
     switch ($type) {
         case 'rss2':
         case 'rss1':
         case 'rss':
         case 'xml':
         case 'js':
             $type = $_REQUEST['type'];
             break;
         default:
             $type = 'rss2';
             break;
     }
     if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) and !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
         $response = $api->callApi('external', 'getCacheData', array('type' => $type, 'options' => $_REQUEST));
         if (is_array($response) and !empty($response['errors'])) {
             return '';
         }
         if ($_SERVER['HTTP_IF_NONE_MATCH'] == "\"{$response['cachehash']}\"") {
             $timediff = strtotime(gmdate('D, d M Y H:i:s') . ' GMT') - strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
             if ($timediff <= $response['cachetime']) {
                 if (SAPI_NAME == 'cgi' or SAPI_NAME == 'cgi-fcgi') {
                     header('Status: 304 Not Modified');
                 } else {
                     header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
                 }
                 exit;
             }
         }
     }
     // always disable nohtml
     $_REQUEST['nohtml'] = 0;
     $response = $api->callApi('external', 'createExternalOutput', array('type' => $type, 'options' => $_REQUEST));
     if (is_array($response) and !empty($response['errors'])) {
         return '';
     }
     $data = $_REQUEST + array('Pragma' => '', 'Content-Type' => vB5_String::getTempCharset());
     $headers = $api->callApi('external', 'getHeadersFromLastOutput', array('type' => $type, 'data' => $data));
     if (is_array($headers) and !empty($headers['errors'])) {
         return '';
     }
     foreach ($headers as $name => $value) {
         header("{$name}: {$value}");
     }
     return $response;
 }
 public static function getPreheader()
 {
     $templater = new vB5_Template('preheader');
     if (self::$needCharset) {
         $templater->register('charset', vB5_String::getTempCharset());
     } else {
         $templater->register('charset', false);
     }
     return $templater->render();
 }
예제 #4
0
 function actionResult()
 {
     //the api init can redirect.  We need to make sure that happens before we echo anything
     $api = Api_InterfaceAbstract::instance();
     $top = '';
     if (vB5_Request::get('cachePageForGuestTime') > 0 and !vB5_User::get('userid')) {
         $fullPageKey = md5(serialize($_REQUEST));
         $fullPage = vB_Cache::instance()->read($fullPageKey);
         if (!empty($fullPage)) {
             echo $fullPage;
             exit;
         }
     }
     $preheader = vB5_ApplicationAbstract::getPreheader();
     $top .= $preheader;
     if (vB5_Request::get('useEarlyFlush')) {
         echo $preheader;
         flush();
     }
     $serverData = array_merge($_GET, $_POST);
     $router = vB5_ApplicationAbstract::instance()->getRouter();
     $arguments = $router->getArguments();
     $userAction = $router->getUserAction();
     if (!empty($userAction)) {
         $api->callApi('wol', 'register', array($userAction['action'], $userAction['params']));
     }
     // if Human verification is required, and we don't have 'q' set in serverData (means the user is using
     // the quick search box), we redirect user to advanced search page with HV
     $requirehv = $api->callApi('hv', 'fetchRequireHvcheck', array('search'));
     if (!empty($serverData['AdvSearch']) or $requirehv and isset($serverData['q'])) {
         $adv_search = $api->callApi('route', 'getRoute', array('pathInfo' => 'advanced_search', 'queryString' => ''), true);
         $arguments = $adv_search['arguments'];
     } elseif ($requirehv) {
         // Advanced search form submitted
         if (empty($serverData['humanverify'])) {
             $serverData['humanverify'] = array();
         }
         $return = $api->callApi('hv', 'verifyToken', array($serverData['humanverify'], 'search'));
         if ($return !== true) {
             $adv_search = $api->callApi('route', 'getRoute', array('pathInfo' => 'advanced_search', 'queryString' => ''), true);
             $arguments = $adv_search['arguments'];
             $error = $return['errors'][0][0];
         }
     }
     $pageid = (int) (isset($arguments['pageid']) ? $arguments['pageid'] : $arguments['contentid']);
     $page = $api->callApi('page', 'fetchPageById', array($pageid, $arguments));
     if (!$page) {
         echo 'Could not find page.';
         exit;
     }
     $phrases = $api->callApi('phrase', 'fetch', array(array('advanced_search', 'search_results')));
     $page['crumbs'] = array(0 => array('title' => $phrases['advanced_search'], 'url' => vB5_Template_Runtime::buildUrl('advanced_search', array(), array(), array('noBaseUrl' => true))), 1 => array('title' => $phrases['search_results'], 'url' => ''));
     // avoid search page itself being indexed
     $page['noindex'] = 1;
     if (!empty($serverData['cookie'])) {
         $serverData['searchJSON'] = '{"specific":[' . $_COOKIE[$serverData['cookie']] . ']}';
     }
     if (!empty($serverData['searchJSON'])) {
         if (is_string($serverData['searchJSON'])) {
             if (preg_match('/[^\\x00-\\x7F]/', $serverData['searchJSON'])) {
                 $serverData['searchJSON'] = vB5_String::toUtf8($serverData['searchJSON'], vB5_String::getTempCharset());
             }
             $serverData['searchJSON'] = json_decode($serverData['searchJSON'], true);
         }
         if (!empty($serverData['searchJSON'])) {
             if (!empty($serverData['searchJSON']['keywords'])) {
                 $serverData['searchJSON']['keywords'] = str_replace(array('"', '\\'), '', $serverData['searchJSON']['keywords']);
                 $serverData['searchJSON']['keywords'] = filter_var($serverData['searchJSON']['keywords'], FILTER_SANITIZE_STRING);
             }
             $serverData['searchJSON'] = json_encode($serverData['searchJSON']);
         } else {
             $serverData['searchJSON'] = '';
         }
         $page['searchJSON'] = $serverData['searchJSON'];
         $extra = array('searchJSON' => !empty($serverData['searchJSON']) ? $serverData['searchJSON'] : '{}');
         if (!empty($serverData['AdvSearch'])) {
             $extra['AdvSearch'] = 1;
         }
         $page['url'] = str_replace('&amp;', '&', vB5_Route::buildUrl('search', array(), $extra));
         //$page['searchJSONStructure'] = json_decode($page['searchJSON'],true);
         $page['crumbs'][0]['url'] = vB5_Template_Runtime::buildUrl('advanced_search', array(), array('searchJSON' => $page['searchJSON']), array('noBaseUrl' => true));
     } elseif (!empty($serverData['q'])) {
         $serverData['q'] = str_replace(array('"', '\\'), '', $serverData['q']);
         $serverData['q'] = filter_var($serverData['q'], FILTER_SANITIZE_STRING);
         $searchType = '';
         if (!empty($serverData['type'])) {
             $serverData['type'] = str_replace(array('"', '\\'), '', $serverData['type']);
             $serverData['type'] = filter_var($serverData['type'], FILTER_SANITIZE_STRING);
             $searchType = ',"type":"' . $serverData['type'] . '"';
         }
         $page['searchJSON'] = '{"keywords":"' . $serverData['q'] . '","sort":"title"' . $searchType . '}';
         $extra = array('q' => $serverData['q']);
         if (!empty($serverData['AdvSearch'])) {
             $extra['AdvSearch'] = 1;
         }
         $page['url'] = str_replace('&amp;', '&', vB5_Route::buildUrl('search', array(), $extra));
         $page['searchStr'] = $serverData['q'];
         $page['crumbs'][0]['url'] = vB5_Template_Runtime::buildUrl('advanced_search', array(''), array('searchJSON' => $page['searchJSON']), array('noBaseUrl' => true));
     } elseif (!empty($serverData['r'])) {
         unset($page['crumbs'][0]);
         $page['url'] = str_replace('&amp;', '&', vB5_Route::buildUrl('search', array(), array('r' => $serverData['r'])));
         $page['resultId'] = $serverData['r'];
         if (!empty($serverData['p']) && is_numeric($serverData['p'])) {
             $page['currentPage'] = intval($serverData['p']);
         }
         $page['crumbs'][0]['url'] = vB5_Template_Runtime::buildUrl('advanced_search', array(), array('r' => $serverData['r']), array('noBaseUrl' => true));
     } else {
         return $this->actionIndex();
     }
     $page['ignore_np_notices'] = vB5_ApplicationAbstract::getIgnoreNPNotices();
     if (!empty($error)) {
         $page['error'] = $error;
     }
     $templater = new vB5_Template($page['screenlayouttemplate']);
     $templater->registerGlobal('page', $page);
     $page = $this->outputPage($templater->render(), false);
     $fullPage = $top . $page;
     if (vB5_Request::get('cachePageForGuestTime') > 0 and !vB5_User::get('userid')) {
         vB_Cache::instance()->write($fullPageKey, $fullPage, vB5_Request::get('cachePageForGuestTime'));
     }
     if (!vB5_Request::get('useEarlyFlush')) {
         echo $fullPage;
     } else {
         echo $page;
     }
 }