Пример #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;
     $httpStatusCode = 200;
     $executedBlocks = [];
     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->locale->setLocale($menuItemTranslation->locale);
                 $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir);
                 $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);
                     $this->blockParser->setParseCached(true);
                     $content = $this->blockParser->parse($contents, 'outputFilter');
                     $this->response->sendHTTPStatusCode($httpStatusCode);
                     echo $this->core->includeScript($content);
                     exit;
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  * Save the block configuration received by the client.
  *
  * @return bool
  */
 public function saveBlockConfig()
 {
     $blockConfigGP = $this->request->getGPAsObject();
     $validate = $this->validation->setData($blockConfigGP);
     $validate->addRule('id', 'numeric')->addRule('menuId', 'numeric')->addRule('contentId', 'notEmpty');
     $block = false;
     $menuItemTranslation = null;
     if (($result = $validate->check()) === true) {
         $extension = $this->db->getRepository('\\Fraym\\Block\\Entity\\BlockExtension')->findOneById($blockConfigGP->id);
         $menu = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($blockConfigGP->menuId);
         $menuItemTranslation = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItemTranslation')->findOneById($blockConfigGP->menuTranslationId);
         if (isset($blockConfigGP->currentBlockId)) {
             $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockConfigGP->currentBlockId);
         }
         if ($extension) {
             if ($block) {
                 $newBlock = new BlockXML();
                 $newBlock->init($block->config);
             } else {
                 $newBlock = new BlockXML();
             }
             if (isset($blockConfigGP->excludedDevices)) {
                 $newBlock->setExcludedDevices($blockConfigGP->excludedDevices);
             }
             if (isset($blockConfigGP->permissions)) {
                 $newBlock->setPermissions($blockConfigGP->permissions);
             }
             $newBlock->setActive($blockConfigGP->active);
             $newBlock->setCache($blockConfigGP->cache);
             $newBlock->setMethod($extension->execMethod);
             $newBlock->setClass($extension->class);
             if (!empty($blockConfigGP->startDate)) {
                 $date = new \DateTime(date('Y-m-d H:i:s', strtotime($blockConfigGP->startDate)));
                 $newBlock->setStartDate($date);
             }
             if (!empty($blockConfigGP->endDate)) {
                 $date = new \DateTime(date('Y-m-d H:i:s', strtotime($blockConfigGP->endDate)));
                 $newBlock->setEndDate($date);
             }
             if ($blockConfigGP->template == 'custom') {
                 $newBlock->setTemplate($blockConfigGP->templateContent);
                 $newBlock->setTemplateType('string');
             } elseif (empty($blockConfigGP->template)) {
                 $newBlock->setTemplate($blockConfigGP->templateFile);
                 $newBlock->setTemplateType('file');
             } else {
                 $newBlock->setTemplateType($blockConfigGP->template);
             }
             $saveMethod = $extension->saveMethod;
             $instance = $this->serviceLocator->get($extension->class);
             if (empty($block)) {
                 $block = new \Fraym\Block\Entity\Block();
             }
             $blockCount = count($this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findByContentId($blockConfigGP->contentId));
             $block->contentId = $blockConfigGP->contentId;
             $block->position = $block->position ? $block->position : $blockCount;
             $block->menuItem = isset($blockConfigGP->menu) && $blockConfigGP->menu == '1' ? null : $menu;
             $block->site = $menu->site;
             $block->menuItemTranslation = $blockConfigGP->menuTranslation === 'current' ? $menuItemTranslation : null;
             $block->extension = $extension;
             $this->db->persist($block);
             $this->db->flush();
             /**
              * Set configuration for the block output
              */
             $this->locale->setLocale($menuItemTranslation->locale->id);
             $this->route->setCurrentMenuItem($menu);
             $this->route->setCurrentMenuItemTranslation($menuItemTranslation);
             /**
              * Extension event callback
              */
             if (method_exists($instance, $saveMethod)) {
                 $newBlock = $instance->{$saveMethod}($block->id, $newBlock);
             }
             $blockConfig = $this->blockParser->getBlockConfig((string) $newBlock);
             $block->config = $blockConfig;
             $this->db->flush();
             /**
              * Save block in history
              */
             if (isset($blockConfigGP->currentBlockId)) {
                 $this->block->saveHistory($block, 'edited');
             } else {
                 $this->block->saveHistory($block, 'added');
             }
             $data = $this->prepareBlockOutput($block);
             $this->response->sendAsJson(array('data' => $data, 'blockId' => $block->id));
         }
     }
     $this->response->sendAsJson(array('error' => $result));
 }
Пример #3
0
 /**
  * @param $menuItemTranslation
  * @return bool
  */
 private function setupPage($menuItemTranslation)
 {
     try {
         $this->currentMenuItemTranslation = $menuItemTranslation;
         $this->currentMenuItem = $menuItemTranslation->menuItem;
         $this->locale->setLocale($menuItemTranslation->locale);
         $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir);
         $pageTitle = ((string) $menuItemTranslation->pageTitle === '' ? $menuItemTranslation->title : $menuItemTranslation->pageTitle) . ' | ' . $menuItemTranslation->menuItem->site->name;
         $this->template->setPageTitle($pageTitle);
         $this->template->setPageDescription($menuItemTranslation->longDescription);
         $this->template->setKeywords(explode(',', $menuItemTranslation->keywords));
         setlocale(LC_ALL, $this->locale->getLocale()->locale);
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
Пример #4
0
 /**
  * @return array|bool
  */
 protected function initConfigurations()
 {
     $gp = $this->request->getGPAsObject();
     $errors = [];
     /**
      * create default language
      */
     $locale = new \Fraym\Locale\Entity\Locale();
     switch ($gp->locale) {
         case 'german':
             $locale->name = 'German';
             $locale->locale = 'de_DE';
             $locale->country = 'Germany';
             $locale->default = true;
             break;
         case 'french':
             $locale->name = 'French';
             $locale->locale = 'fr_FR';
             $locale->country = 'France';
             $locale->default = true;
             break;
         case 'swedish':
             $locale->name = 'swedish';
             $locale->locale = 'sv_SE';
             $locale->country = 'Sweden';
             $locale->default = true;
             break;
         case 'spanish':
             $locale->name = 'Spanish';
             $locale->locale = 'es_ES';
             $locale->country = 'Spain';
             $locale->default = true;
             break;
         default:
             // english
             $locale->name = 'English';
             $locale->locale = 'en_US';
             $locale->country = 'USA';
             $locale->default = true;
             break;
     }
     $this->db->persist($locale);
     $this->db->flush();
     $this->locale->setLocale($locale);
     $this->db->setUpTranslateable()->setUpSortable();
     /**
      * create site
      */
     $site = new \Fraym\Site\Entity\Site();
     $site->name = $gp->site->name;
     $site->caching = true;
     $site->active = true;
     $site->menuItems->clear();
     $this->db->persist($site);
     /**
      * create domain for site
      */
     $domain = new \Fraym\Site\Entity\Domain();
     $domain->site = $site;
     $domain->address = $gp->site->url;
     $this->db->persist($domain);
     $this->addMenuItems($site);
     $adminGroup = new \Fraym\User\Entity\Group();
     $adminGroup->name = $this->translation->autoTranslation('Administrator', 'en', $this->locale->getLocale()->locale);
     $adminGroup->identifier = 'Administrator';
     $this->db->persist($adminGroup);
     $adminUser = new \Fraym\User\Entity\User();
     $adminUser->updateEntity($gp->user, false);
     if (strlen($gp->user->password) < 8) {
         $errors[] = 'Password is too short.';
     } elseif ($gp->user->password === $gp->user->password_repeat) {
         $adminUser->password = $gp->user->password;
     } else {
         $errors[] = 'Passwords do not match.';
     }
     $adminUser->groups->add($adminGroup);
     $this->db->persist($adminUser);
     if (count($errors) === 0) {
         $this->db->flush();
         $this->db->clear();
         /**
          * Register extensions, default theme...
          */
         $this->registry->registerExtensions();
         /**
          * Set menuitem template -> default theme
          */
         $this->setupMenuItemTemplate();
         /**
          * Login admin user
          */
         $this->user->setUserId($adminUser->id);
         return true;
     }
     return $errors;
 }
Пример #5
0
 /**
  * @param $menuItemTranslation
  * @return bool
  * @throws \Exception
  */
 protected function setupPage($menuItemTranslation)
 {
     try {
         $this->currentMenuItemTranslation = $menuItemTranslation;
         $this->currentMenuItem = $menuItemTranslation->menuItem;
         $this->db->setTranslatableLocale($menuItemTranslation->locale->locale);
         $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir);
         if ($this->request->isXmlHttpRequest() || $this->user->isAdmin()) {
             $localeId = $this->request->gp('locale_id');
             if ($localeId && is_numeric($localeId)) {
                 $this->locale->setLocale($localeId);
             } else {
                 $this->locale->setLocale($menuItemTranslation->locale);
             }
         } else {
             $this->locale->setLocale($menuItemTranslation->locale);
         }
         $pageTitle = (string) $menuItemTranslation->pageTitle === '' ? $menuItemTranslation->title : $menuItemTranslation->pageTitle;
         $pageTitle = str_replace('[SITE_NAME]', $menuItemTranslation->menuItem->site->name, $pageTitle);
         $this->template->setPageTitle($pageTitle);
         $this->template->setPageDescription($menuItemTranslation->description);
         $this->template->setKeywords(explode(',', $menuItemTranslation->keywords));
         setlocale(LC_ALL, $this->locale->getLocale()->locale);
     } catch (Exception $e) {
         throw new \Exception('Error setup page: ' . $e->getMessage());
     }
     return true;
 }