buildCache() public static method

Build the cache
public static buildCache ( string $language = null )
$language string The language to build the cache for, if not passed we use the working language.
Example #1
0
 /**
  * @param KernelInterface $kernel
  */
 public function __construct(KernelInterface $kernel)
 {
     parent::__construct($kernel);
     // store for later use throughout the application
     $this->getContainer()->set('navigation', $this);
     $this->URL = $this->getContainer()->get('url');
     // check if navigation cache file exists
     if (!is_file(self::getCacheDirectory() . 'navigation.php')) {
         $this->buildCache();
     }
     // check if editor_link_list_LANGUAGE.js cache file exists
     if (!is_file(FRONTEND_CACHE_PATH . '/Navigation/editor_link_list_' . BackendLanguage::getWorkingLanguage() . '.js')) {
         BackendPagesModel::buildCache(BackendLanguage::getWorkingLanguage());
     }
     $navigation = array();
     // require navigation-file
     require self::getCacheDirectory() . 'navigation.php';
     // load it
     $this->navigation = (array) $navigation;
     $this->navigation = $this->addActiveStateToNavigation($this->navigation);
     // cleanup navigation (not needed for god user)
     if (!Authentication::getUser()->isGod()) {
         $this->navigation = $this->cleanup($this->navigation);
     }
 }
Example #2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendPagesModel::exists($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // init var
         $success = false;
         // cannot have children
         if (BackendPagesModel::getFirstChildId($this->id) !== false) {
             $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing');
         }
         $revisionId = $this->getParameter('revision_id', 'int');
         if ($revisionId == 0) {
             $revisionId = null;
         }
         // get page (we need the title)
         $page = BackendPagesModel::get($this->id, $revisionId);
         // valid page?
         if (!empty($page)) {
             // delete the page
             $success = BackendPagesModel::delete($this->id, null, $revisionId);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
             // delete search indexes
             BackendSearchModel::removeIndex($this->getModule(), $this->id);
             // build cache
             BackendPagesModel::buildCache(BL::getWorkingLanguage());
         }
         // page is deleted, so redirect to the overview
         if ($success) {
             $this->redirect(BackendModel::createURLForAction('Index') . '&id=' . $page['parent_id'] . '&report=deleted&var=' . rawurlencode($page['title']));
         } else {
             $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing');
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing');
     }
 }
Example #3
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent
     parent::execute();
     // get parameters
     $id = \SpoonFilter::getPostValue('id', null, 0, 'int');
     $droppedOn = \SpoonFilter::getPostValue('dropped_on', null, -1, 'int');
     $typeOfDrop = \SpoonFilter::getPostValue('type', null, '');
     $tree = \SpoonFilter::getPostValue('tree', array('main', 'meta', 'footer', 'root'), '');
     // init validation
     $errors = array();
     // validate
     if ($id === 0) {
         $errors[] = 'no id provided';
     }
     if ($droppedOn === -1) {
         $errors[] = 'no dropped_on provided';
     }
     if ($typeOfDrop == '') {
         $errors[] = 'no type provided';
     }
     if ($tree == '') {
         $errors[] = 'no tree provided';
     }
     // got errors
     if (!empty($errors)) {
         $this->output(self::BAD_REQUEST, array('errors' => $errors), 'not all fields were filled');
     } else {
         // get page
         $success = BackendPagesModel::move($id, $droppedOn, $typeOfDrop, $tree);
         // build cache
         BackendPagesModel::buildCache(BL::getWorkingLanguage());
         // output
         if ($success) {
             $this->output(self::OK, BackendPagesModel::get($id), 'page moved');
         } else {
             $this->output(self::ERROR, null, 'page not moved');
         }
     }
 }
Example #4
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // add js
     $this->header->addJS('jstree/jquery.tree.js', null, false);
     $this->header->addJS('jstree/lib/jquery.cookie.js', null, false);
     $this->header->addJS('jstree/plugins/jquery.tree.cookie.js', null, false);
     // add css
     $this->header->addCSS('/src/Backend/Modules/Pages/Js/jstree/themes/fork/style.css', null, true);
     // check if the cached files exists
     if (!is_file(PATH_WWW . '/src/Frontend/Cache/Navigation/keys_' . BL::getWorkingLanguage() . '.php')) {
         BackendPagesModel::buildCache(BL::getWorkingLanguage());
     }
     if (!is_file(PATH_WWW . '/src/Frontend/Cache/Navigation/navigation_' . BL::getWorkingLanguage() . '.php')) {
         BackendPagesModel::buildCache(BL::getWorkingLanguage());
     }
     // load the dgRecentlyEdited
     $this->loadDataGrids();
     // parse
     $this->parse();
     // display the page
     $this->display();
 }
Example #5
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // get the status
         $status = \SpoonFilter::getPostValue('status', array('active', 'draft'), 'active');
         // validate redirect
         $redirectValue = $this->frm->getField('redirect')->getValue();
         if ($redirectValue == 'internal') {
             $this->frm->getField('internal_redirect')->isFilled(BL::err('FieldIsRequired'));
         }
         if ($redirectValue == 'external') {
             $this->frm->getField('external_redirect')->isURL(BL::err('InvalidURL'));
         }
         // set callback for generating an unique URL
         $this->meta->setURLCallback('Backend\\Modules\\Pages\\Engine\\Model', 'getURL', array($this->record['id'], $this->record['parent_id'], $this->frm->getField('is_action')->getChecked()));
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // validate meta
         $this->meta->validate();
         // no errors?
         if ($this->frm->isCorrect()) {
             // init var
             $data = null;
             // build data
             if ($this->frm->getField('is_action')->isChecked()) {
                 $data['is_action'] = true;
             }
             if ($redirectValue == 'internal') {
                 $data['internal_redirect'] = array('page_id' => $this->frm->getField('internal_redirect')->getValue(), 'code' => '301');
             }
             if ($redirectValue == 'external') {
                 $data['external_redirect'] = array('url' => BackendPagesModel::getEncodedRedirectURL($this->frm->getField('external_redirect')->getValue()), 'code' => '301');
             }
             // build page record
             $page['id'] = $this->record['id'];
             $page['user_id'] = BackendAuthentication::getUser()->getUserId();
             $page['parent_id'] = $this->record['parent_id'];
             $page['template_id'] = (int) $this->frm->getField('template_id')->getValue();
             $page['meta_id'] = (int) $this->meta->save();
             $page['language'] = BL::getWorkingLanguage();
             $page['type'] = $this->record['type'];
             $page['title'] = $this->frm->getField('title')->getValue();
             $page['navigation_title'] = $this->frm->getField('navigation_title')->getValue() != '' ? $this->frm->getField('navigation_title')->getValue() : $this->frm->getField('title')->getValue();
             $page['navigation_title_overwrite'] = $this->frm->getField('navigation_title_overwrite')->getActualValue();
             $page['hidden'] = $this->frm->getField('hidden')->getValue();
             $page['status'] = $status;
             $page['publish_on'] = BackendModel::getUTCDate(null, $this->record['publish_on']);
             $page['created_on'] = BackendModel::getUTCDate(null, $this->record['created_on']);
             $page['edited_on'] = BackendModel::getUTCDate();
             $page['allow_move'] = $this->record['allow_move'];
             $page['allow_children'] = $this->record['allow_children'];
             $page['allow_edit'] = $this->record['allow_edit'];
             $page['allow_delete'] = $this->record['allow_delete'];
             $page['sequence'] = $this->record['sequence'];
             $page['data'] = $data !== null ? serialize($data) : null;
             if ($this->isGod) {
                 $page['allow_move'] = in_array('move', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N';
                 $page['allow_children'] = in_array('children', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N';
                 $page['allow_edit'] = in_array('edit', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N';
                 $page['allow_delete'] = in_array('delete', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N';
             }
             // set navigation title
             if ($page['navigation_title'] == '') {
                 $page['navigation_title'] = $page['title'];
             }
             // insert page, store the id, we need it when building the blocks
             $page['revision_id'] = BackendPagesModel::update($page);
             // loop blocks
             foreach ($this->blocksContent as $i => $block) {
                 // add page revision id to blocks
                 $this->blocksContent[$i]['revision_id'] = $page['revision_id'];
                 // validate blocks, only save blocks for valid positions
                 if (!in_array($block['position'], $this->templates[$this->frm->getField('template_id')->getValue()]['data']['names'])) {
                     unset($this->blocksContent[$i]);
                 }
             }
             // insert the blocks
             BackendPagesModel::insertBlocks($this->blocksContent);
             // trigger an event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $page));
             // save tags
             BackendTagsModel::saveTags($page['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // build cache
             BackendPagesModel::buildCache(BL::getWorkingLanguage());
             // active
             if ($page['status'] == 'active') {
                 // init var
                 $text = '';
                 // build search-text
                 foreach ($this->blocksContent as $block) {
                     $text .= ' ' . $block['html'];
                 }
                 // add to search index
                 BackendSearchModel::saveIndex($this->getModule(), $page['id'], array('title' => $page['title'], 'text' => $text));
                 // everything is saved, so redirect to the overview
                 $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $page['id'] . '&report=edited&var=' . urlencode($page['title']) . '&highlight=row-' . $page['id']);
             } elseif ($page['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $page['id'] . '&report=saved-as-draft&var=' . urlencode($page['title']) . '&highlight=row-' . $page['id'] . '&draft=' . $page['revision_id']);
             }
         }
     }
 }
Example #6
0
 /**
  * Get the navigation-items
  *
  * @param string $language The language to use, if not provided we will use the working language.
  * @return array
  */
 public static function getNavigation($language = null)
 {
     $language = $language !== null ? (string) $language : FRONTEND_LANGUAGE;
     // does the keys exists in the cache?
     if (!isset(self::$navigation[$language]) || empty(self::$navigation[$language])) {
         if (!is_file(FRONTEND_CACHE_PATH . '/Navigation/navigation_' . $language . '.php')) {
             BackendPagesModel::buildCache($language);
         }
         $navigation = array();
         require FRONTEND_CACHE_PATH . '/Navigation/navigation_' . $language . '.php';
         self::$navigation[$language] = $navigation;
     }
     return self::$navigation[$language];
 }
Example #7
0
 /**
  * Get the page-keys
  *
  * @param string $language The language wherefore the navigation should be loaded,
  *                         if not provided we will load the language that was provided in the URL.
  * @return array
  */
 public static function getKeys($language = null)
 {
     $language = $language !== null ? (string) $language : FRONTEND_LANGUAGE;
     // does the keys exists in the cache?
     if (!isset(self::$keys[$language]) || empty(self::$keys[$language])) {
         // validate file
         if (!is_file(FRONTEND_CACHE_PATH . '/Navigation/keys_' . $language . '.php')) {
             // generate the cache
             BackendPagesModel::buildCache($language);
             // recall
             return self::getKeys($language);
         }
         // init var
         $keys = array();
         // require file
         require FRONTEND_CACHE_PATH . '/Navigation/keys_' . $language . '.php';
         // validate keys
         if (empty($keys)) {
             throw new Exception('No pages for ' . $language . '.');
         }
         // store
         self::$keys[$language] = $keys;
     }
     // return from cache
     return self::$keys[$language];
 }