Пример #1
0
 public function index($pageid)
 {
     //the api init can redirect.  We need to make sure that happens before we echo anything
     $api = Api_InterfaceAbstract::instance();
     $top = '';
     // We should not cache register page for guest. See VBV-7695.
     if (vB5_Request::get('cachePageForGuestTime') > 0 and !vB5_User::get('userid') and (empty($_REQUEST['routestring']) or $_REQUEST['routestring'] != 'register' and $_REQUEST['routestring'] != 'lostpw')) {
         // languageid should be in the pagekey to fix VBV-8095
         $fullPageKey = 'vBPage_' . md5(serialize($_REQUEST)) . '_' . vB::getCurrentSession()->get('languageid');
         $styleid = vB5_Cookie::get('userstyleid', vB5_Cookie::TYPE_UINT);
         if (!empty($styleid)) {
             $fullPageKey .= '_' . $styleid;
         }
         $fullPage = vB_Cache::instance(vB_Cache::CACHE_LARGE)->read($fullPageKey);
         if (!empty($fullPage)) {
             echo $fullPage;
             exit;
         }
     }
     $preheader = vB5_ApplicationAbstract::getPreheader();
     $top .= $preheader;
     if (vB5_Request::get('useEarlyFlush')) {
         echo $preheader;
         flush();
     }
     $router = vB5_ApplicationAbstract::instance()->getRouter();
     $arguments = $router->getArguments();
     $userAction = $router->getUserAction();
     $pageKey = $router->getPageKey();
     $api->callApi('page', 'preload', array($pageKey));
     if (!empty($userAction)) {
         $api->callApi('wol', 'register', array($userAction['action'], $userAction['params'], $pageKey, vB::getRequest()->getScriptPath(), !empty($arguments['nodeid']) ? $arguments['nodeid'] : 0));
     }
     if (isset($arguments['pagenum'])) {
         $arguments['pagenum'] = intval($arguments['pagenum']) > 0 ? intval($arguments['pagenum']) : 1;
     }
     $pageid = (int) (isset($arguments['pageid']) ? $arguments['pageid'] : (isset($arguments['contentid']) ? $arguments['contentid'] : 0));
     if ($pageid < 1) {
         // @todo This needs to output a user-friendly "page not found" page
         throw new Exception('Could not find page.');
     }
     $page = $api->callApi('page', 'fetchPageById', array($pageid, $arguments));
     if (!$page) {
         // @todo This needs to output a user-friendly "page not found" page
         throw new Exception('Could not find page.');
     }
     // Go to the first new / unread post for this user in this topic
     if (!empty($_REQUEST['goto']) and $_REQUEST['goto'] == 'newpost' and !empty($arguments['nodeid']) and !empty($arguments['channelid'])) {
         if ($this->vboptions['threadmarking'] and vB5_User::get('userid')) {
             // Database read marking
             $channelRead = $api->callApi('node', 'getNodeReadTime', array($arguments['channelid']));
             $topicRead = $api->callApi('node', 'getNodeReadTime', array($arguments['nodeid']));
             $topicView = max($topicRead, $channelRead, time() - $this->vboptions['markinglimit'] * 86400);
         } else {
             // Cookie read marking
             $topicView = intval(vB5_Cookie::fetchBbarrayCookie('discussion_view', $arguments['nodeid']));
             if (!$topicView) {
                 $topicView = vB5_User::get('lastvisit');
             }
         }
         $topicView = intval($topicView);
         // Get the first unread reply
         $goToNodeId = $api->callApi('node', 'getFirstChildAfterTime', array($arguments['nodeid'], $topicView));
         if (empty($goToNodeId)) {
             $thread = $api->callApi('node', 'getNodes', array(array($arguments['nodeid'])));
             if (!empty($thread) and isset($thread[$arguments['nodeid']])) {
                 $goToNodeId = $thread[$arguments['nodeid']]['lastcontentid'];
             }
         }
         if ($goToNodeId) {
             // Redirect to the new post
             $urlCache = vB5_Template_Url::instance();
             $urlKey = $urlCache->register($router->getRouteId(), array('nodeid' => $arguments['nodeid']), array('p' => $goToNodeId));
             $replacements = $urlCache->finalBuildUrls(array($urlKey));
             $url = $replacements[$urlKey];
             if ($url) {
                 $url .= '#post' . $goToNodeId;
                 if (headers_sent()) {
                     echo '<script type="text/javascript">window.location = "' . $url . '";</script>';
                 } else {
                     header('Location: ' . $url);
                 }
                 exit;
             }
         }
     }
     $page['routeInfo'] = array('routeId' => $router->getRouteId(), 'arguments' => $arguments, 'queryParameters' => $router->getQueryParameters());
     $page['crumbs'] = $router->getBreadcrumbs();
     $page['headlinks'] = $router->getHeadLinks();
     $page['pageKey'] = $pageKey;
     // default value for pageSchema
     $page['pageSchema'] = 'http://schema.org/WebPage';
     $queryParameters = $router->getQueryParameters();
     /*
      *	VBV-12506
      *	this is where we would add other things to clean up dangerous query params.
      *	For VBV-12486, I'll just unset anything here that can't use vb:var in the templates,
      *	but really we should just make a whitelist of expected page object parameters that
      *	come from the query string and unset EVERYTHING else. For the expected ones, we
      *	should also force the value into the expected (and hopefully safer) range
      */
     /*
      *	VBV-12506
      *	$doNotReplaceWithQueryParams is a list of parameters that the page object usually
      *	gets naturally/internally, and we NEVER want to replace with a user provided query
      *	parameter. (In fact, *when* exactly DO we want to do this???)
      *	If we don't do this, it's a potential XSS vulnerability for the items that we
      *	cannot send through vb:var for whatever reason (title for ex)
      * 	and even if they *are* sent through vb:var, the replacements can sometimes just
      *	break the page even when it's sent through vb:var (for example, ?pagetemplateid=%0D,
      *	the new line this inserts in var pageData = {...} in the header template tends to
      *	break things (tested on Chrome).
      *	Furthermore, any script that uses the pageData var would get the user injected data
      *	that might cause more problems down the line.
      *	Parameter Notes:
      *		'titleprefix'
      *			As these two should already be html escaped, we don't want to double escape
      *			them. So we can't us vb:var in the templates. As such, we must prevent a
      *			malicious querystring from being injected into the page object here.
      *		'title'
      *			Similar to above, but channels are allowed to have HTML in the title, so
      *			they are intentinoally not escaped in the DB, and the templates can't use
      *			vb:var.
      *		'pageid', 'channelid', 'nodeid'
      *			These are usually set in the arguments, so the array_merge below usually
      *			takes care of not passing a pageid query string through to the page object,
      *			but I'm leaving them in just in case.
      */
     $doNotReplaceWithQueryParams = array('titleprefix', 'title', 'pageid', 'channelid', 'nodeid', 'pagetemplateid', 'url', 'pagenum', 'tagCloudTitle');
     foreach ($doNotReplaceWithQueryParams as $key) {
         unset($queryParameters[$key]);
     }
     $arguments = array_merge($queryParameters, $arguments);
     foreach ($arguments as $key => $value) {
         $page[$key] = $value;
     }
     $options = vB5_Template_Options::instance();
     $page['phrasedate'] = $options->get('miscoptions.phrasedate');
     $page['optionsdate'] = $options->get('miscoptions.optionsdate');
     // if no meta description, use node data or global one instead, prefer node data
     if (empty($page['metadescription']) and !empty($page['nodedescription'])) {
         $page['metadescription'] = $page['nodedescription'];
     }
     if (empty($page['metadescription'])) {
         $page['metadescription'] = $options->get('options.description');
     }
     $config = vB5_Config::instance();
     // Non-persistent notices @todo - change this to use vB_Cookie
     $page['ignore_np_notices'] = vB5_ApplicationAbstract::getIgnoreNPNotices();
     $templateCache = vB5_Template_Cache::instance();
     $templater = new vB5_Template($page['screenlayouttemplate']);
     //IMPORTANT: If you add any variable to the page object here,
     // please make sure you add them to other controllers which create page objects.
     // That includes at a minimum the search controller (in two places currently)
     // and vB5_ApplicationAbstract::showErrorPage
     $templater->registerGlobal('page', $page);
     $page = $this->outputPage($templater->render(), false);
     $fullPage = $top . $page;
     if (!empty($fullPageKey) and is_string($fullPageKey)) {
         vB_Cache::instance(vB_Cache::CACHE_LARGE)->write($fullPageKey, $fullPage, vB5_Request::get('cachePageForGuestTime'), 'vbCachedFullPage');
     }
     // these are the templates rendered for this page
     $loadedTemplates = vB5_Template::getRenderedTemplates();
     $api->callApi('page', 'savePreCacheInfo', array($pageKey));
     if (!vB5_Request::get('useEarlyFlush')) {
         echo $fullPage;
     } else {
         echo $page;
     }
 }
 protected static function showBannedPage($bannedInfo)
 {
     //We want the simplest possible page.
     $page = array();
     $page['routeInfo'] = self::getRouteInfo();
     $page['ignore_np_notices'] = self::getIgnoreNPNotices();
     $templater = new vB5_Template('banned_page');
     $templater->registerGlobal('page', $page);
     $templater->register('bannedInfo', $bannedInfo);
     echo self::getPreheader() . $templater->render();
 }
Пример #3
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;
     }
 }