public static function getNode($settingName) { $metaValue = (int) self::byName($settingName); $node = new NodeModel(); $node->loadByPK($metaValue); return $node->hasLoaded() ? $node : false; }
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(); }
public function getItems() { $collection = new MenuCollection(); $collection->filterByParent($this->id); $collection->orderBy('sort'); $currentParentUrl = false; if ($current = Ajde_Cms::getInstance()->getRoutedNode()) { $currentParentUrl = $current->getParent() && $current->getParent()->hasLoaded() ? $current->getParent()->getUrl() : false; } $items = []; foreach ($collection as $item) { /* @var $item MenuModel */ $name = $item->name; $target = ''; $submenus = []; $current = ''; $node = new NodeModel(); if ($item->type == 'URL') { $url = $item->url; if (substr($url, 0, 7) === 'http://' || substr($url, 0, 8) === 'https://') { $target = '_blank'; } } else { if ($item->type == 'Node link') { $node->loadByPK($item->node); $url = $node->getUrl(); } else { if ($item->type == 'Submenu') { $node->loadByPK($item->node); $url = $node->getUrl(); $submenus = $item->getItems(); foreach ($submenus as $submenu) { if ($submenu['current']) { $current = 'active sub-active'; } } } } } if ($url == Ajde::app()->getRoute()->getOriginalRoute()) { $current = 'active'; } if (Ajde::app()->getRoute()->getOriginalRoute() == '' && $url == config('routes.homepage')) { $current = 'active'; } if ($url == $currentParentUrl) { $current = 'active sub-active'; } if ($item->type == 'Node link' && !$node->hasLoaded()) { } else { $items[] = ['node' => $node, 'name' => $name, 'url' => $url, 'target' => $target, 'current' => $current, 'submenus' => $submenus]; } } return $items; }
public function getNodeModelFromMetaValue($metaId) { $metaValue = (int) $this->getMetaValue($metaId); $node = new NodeModel(); $node->loadByPK($metaValue); return $node->hasLoaded() ? $node : false; }