예제 #1
0
파일: PageForward.php 프로젝트: Jobu/core
 /**
  * Redirect to an internal page
  * @param \PageModel $objPage
  */
 public function generate($objPage)
 {
     // Forward to the jumpTo or first published page
     if ($objPage->jumpTo) {
         /** @var \PageModel $objNextPage */
         $objNextPage = $objPage->getRelated('jumpTo');
     } else {
         $objNextPage = \PageModel::findFirstPublishedRegularByPid($objPage->id);
     }
     // Forward page does not exist
     if ($objNextPage === null) {
         header('HTTP/1.1 404 Not Found');
         $this->log('Forward page ID "' . $objPage->jumpTo . '" does not exist', __METHOD__, TL_ERROR);
         die_nicely('be_no_forward', 'Forward page not found');
     }
     $strForceLang = null;
     // Check the target page language (see #4706)
     if (\Config::get('addLanguageToUrl')) {
         $objNextPage->loadDetails();
         // see #3983
         $strForceLang = $objNextPage->language;
     }
     $strGet = '';
     $strQuery = \Environment::get('queryString');
     $arrQuery = array();
     // Extract the query string keys (see #5867)
     if ($strQuery != '') {
         $arrChunks = explode('&', $strQuery);
         foreach ($arrChunks as $strChunk) {
             list($k, ) = explode('=', $strChunk, 2);
             $arrQuery[] = $k;
         }
     }
     // Add $_GET parameters
     if (!empty($_GET)) {
         foreach (array_keys($_GET) as $key) {
             if (\Config::get('disableAlias') && $key == 'id') {
                 continue;
             }
             if (\Config::get('addLanguageToUrl') && $key == 'language') {
                 continue;
             }
             // Ignore the query string parameters (see #5867)
             if (in_array($key, $arrQuery)) {
                 continue;
             }
             // Ignore the auto_item parameter (see #5886)
             if ($key == 'auto_item') {
                 $strGet .= '/' . \Input::get($key);
             } else {
                 $strGet .= '/' . $key . '/' . \Input::get($key);
             }
         }
     }
     // Append the query string (see #5867)
     if ($strQuery != '') {
         $strQuery = '?' . $strQuery;
     }
     $this->redirect($this->generateFrontendUrl($objNextPage->row(), $strGet, $strForceLang) . $strQuery, $objPage->redirect == 'temporary' ? 302 : 301);
 }
예제 #2
0
 /**
  * Parse the given page and return the image information
  * @param    \PageModel
  * @return   array
  */
 protected static function parsePage(\PageModel $objPage)
 {
     if ($objPage->pageImage == '') {
         return array();
     }
     $arrImages = array();
     $objImages = \FilesModel::findMultipleByIds(deserialize($objPage->pageImage, true));
     if (null !== $objImages) {
         while ($objImages->next()) {
             $objFile = new \File($objImages->path, true);
             if (!$objFile->isGdImage) {
                 continue;
             }
             $arrImage = $objImages->row();
             $arrMeta = static::getMetaData($objImages->meta, $objPage->language);
             // Use the file name as title if none is given
             if ($arrMeta['title'] == '') {
                 $arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
             }
             $arrImage['alt'] = $objPage->pageImageAlt;
             $arrImage['imageUrl'] = $arrMeta['link'];
             $arrImage['caption'] = $arrMeta['caption'];
             if (null !== $objPage->getRelated('pageImageJumpTo')) {
                 $arrImage['hasLink'] = true;
                 $arrImage['title'] = $objPage->pageImageTitle ?: ($arrMeta['title'] ?: ($objJumpTo->pageTitle ?: $objJumpTo->title));
                 $arrImage['href'] = \Controller::generateFrontendUrl($objPage->getRelated('pageImageJumpTo')->row());
             }
             $arrImages[] = $arrImage;
         }
         $arrOrder = deserialize($objPage->pageImageOrder);
         if (!empty($arrOrder) && is_array($arrOrder)) {
             // Remove all values
             $arrOrder = array_map(function () {
             }, array_flip($arrOrder));
             // Move the matching elements to their position in $arrOrder
             foreach ($arrImages as $k => $v) {
                 if (array_key_exists($v['uuid'], $arrOrder)) {
                     $arrOrder[$v['uuid']] = $v;
                     unset($arrImages[$k]);
                 }
             }
             // Append the left-over images at the end
             if (!empty($arrImages)) {
                 $arrOrder = array_merge($arrOrder, array_values($arrImages));
             }
             // Remove empty (unreplaced) entries
             $arrImages = array_values(array_filter($arrOrder));
             unset($arrOrder);
         }
     }
     return $arrImages;
 }