Пример #1
0
 public function view()
 {
     // we want to display published nodes only
     if (!(UserModel::getLoggedIn() && UserModel::getLoggedIn()->isAdmin())) {
         Ajde::app()->getRequest()->set('filterPublished', true);
     }
     // get the current slug
     $slug = $this->getSlug();
     $node = new NodeModel();
     $node->loadBySlug($slug);
     $this->node = $node;
     if ($node->checkPublished() === false) {
         Ajde_Dump::warn('Previewing unpublished node');
     }
     // check if we have a hit
     if (!$node->hasLoaded()) {
         Ajde::app()->getResponse()->redirectNotFound();
     }
     Ajde_Event::trigger($this, 'onAfterNodeLoaded', [$node]);
     // update cache
     Ajde_Cache::getInstance()->updateHash($node->hash());
     Ajde_Cache::getInstance()->updateHash($node->getChildren()->hash());
     Ajde_Cache::getInstance()->addLastModified(strtotime($node->updated));
     // set title
     if (!Ajde::app()->getDocument()->hasNotEmpty('title')) {
         Ajde::app()->getDocument()->setTitle($node->getTitle());
     }
     // set summary
     if ($node->summary) {
         Ajde::app()->getDocument()->setDescription($node->summary);
     }
     // set author
     $node->loadParent('user');
     /** @var UserModel $owner */
     $owner = $node->getUser();
     Ajde::app()->getDocument()->setAuthor($owner->getFullname());
     // set template
     $nodetype = $node->getNodetype();
     $action = str_replace(' ', '_', strtolower($nodetype->get($nodetype->getDisplayField())));
     $this->setAction($action);
     // featured image
     if ($image = $node->featuredImage()) {
         Ajde::app()->getDocument()->setFeaturedImage($image);
     }
     // pass node to document, only first
     $layout = Ajde::app()->getDocument()->getLayout();
     if (!$layout->hasAssigned('node')) {
         $layout->assign('node', $node);
     }
     // pass node to view
     $this->getView()->assign('node', $node);
     // render the temnplate
     return $this->render();
 }