Example #1
0
 /**
  * if cacheing is active and a cached file is availible it outputs the cache and exits the script
  *
  * @return void
  */
 public function load()
 {
     // gets the current uri - example: /folder/folder2
     $filename = $this->getCacheName();
     // create the cache filename
     $cacheFilename = self::DIR_PAGES . $filename . '.cache.php';
     $cacheFilenamePhpData = self::DIR_PAGES . $filename . '.cache.config.php';
     $menuItemTranslation = false;
     $domain = false;
     $executedBlocks = array();
     if (defined('GLOBAL_CACHING_ENABLED') && GLOBAL_CACHING_ENABLED && !$this->request->isXmlHttpRequest() && !$this->request->isPost() && $this->user->isAdmin() === false && is_file($cacheFilename) && is_file($cacheFilenamePhpData)) {
         include $cacheFilenamePhpData;
         if ($menuItemTranslation) {
             $menuItemTranslation = json_decode($menuItemTranslation);
             if (is_object($menuItemTranslation)) {
                 if ($this->request->isXmlHttpRequest() === false && $this->route->isHTTPS() === false && $menuItemTranslation->menuItem->https === true) {
                     $this->route->redirectToURL('https://' . $this->route->getRequestRoute());
                 }
                 $this->route->setCurrentMenuItem($menuItemTranslation->menuItem);
                 $this->route->setCurrentMenuItemTranslation($menuItemTranslation);
                 $this->route->setCurrentDomain($domain);
                 if ($this->isCachingActive($menuItemTranslation->menuItem)) {
                     $this->blockParser->setExecutedBlocks(json_decode($executedBlocks));
                     // display the cached file to the client
                     $contents = file_get_contents($cacheFilename);
                     $content = $this->blockParser->parse($contents, 'outputFilter', true);
                     echo eval('?>' . $content . '<?php ');
                     exit;
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * @param $xml
  */
 protected function newsList($xml)
 {
     $itemsPerPage = 10;
     $currentPage = 1;
     $entryIds = empty($xml->listItems) ? array() : explode(',', trim($xml->listItems));
     $sort = (string) $xml->newsListSort;
     $filter = $this->getNewsListFilter();
     $qb = $this->db->createQueryBuilder();
     $newsItems = $qb->select("n")->from('\\Extension\\News\\Entity\\News', 'n')->leftJoin('n.sites', 's', \Doctrine\ORM\Query\Expr\Join::WITH, $qb->expr()->eq('s.id', $this->route->getCurrentMenuItem()->site->id));
     if (count($entryIds)) {
         $newsItems->andWhere("n.id IN (:ids)")->setParameter('ids', $entryIds);
     }
     if ($sort == 'date_asc') {
         $newsItems->orderBy('n.date', 'ASC');
     } else {
         if ($sort == 'title_asc') {
             $newsItems->orderBy('n.title', 'ASC');
         } else {
             $newsItems->orderBy('n.date', 'DESC');
         }
     }
     if (is_numeric((string) $xml->limit)) {
         $itemsPerPage = (int) $xml->limit;
         $newsItems->setMaxResults($itemsPerPage);
     } else {
         $newsItems->setMaxResults($itemsPerPage);
     }
     if ($filter) {
         if ($filter[0] === 'c') {
             $newsItems->join('n.categories', 'c')->andWhere("c.name = :category")->setParameter('category', $filter[1]);
         } elseif ($filter[0] === 't') {
             $newsItems->join('n.tags', 't')->andWhere("t.name = :tag")->setParameter('tag', $filter[1]);
         } elseif ($filter[0] === 'page') {
             $currentPage = $filter[1];
             if ($currentPage == '1') {
                 $this->route->redirectToURL($this->route->getCurrentMenuItem()->getUrl($this->route, true));
             }
             $newsItems->setFirstResult($currentPage * $itemsPerPage - $itemsPerPage);
         }
     }
     $detailPageUrl = '';
     $detailPage = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($xml->detailPage);
     if ($detailPage) {
         $detailPageUrl = $detailPage->getUrl($this->route, true);
     }
     $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($newsItems, false);
     $c = count($paginator);
     $pagination = array('currentPage' => $currentPage, 'count' => $c, 'itemsPerPage' => $itemsPerPage);
     return $this->newsController->renderNewsList($detailPageUrl, $paginator, $pagination);
 }