public function listHtml() { $cache = Ajde_Cache::getInstance(); $cache->disable(); if (Ajde::app()->getRequest()->has('edit') || Ajde::app()->getRequest()->has('new')) { return $this->editDefault(); } if (Ajde::app()->getRequest()->has('output') && Ajde::app()->getRequest()->get('output') == 'table') { Ajde::app()->getDocument()->setLayout(new Ajde_Layout('empty')); } $crud = $this->getCrudInstance(); /* @var $crud Ajde_Crud */ if (!$crud) { Ajde::app()->getResponse()->redirectNotFound(); } $session = new Ajde_Session('AC.Crud'); $session->setModel($crud->getHash(), $crud); $viewSession = new Ajde_Session('AC.Crud.View'); $sessionName = $crud->getSessionName(); if ($viewSession->has($sessionName)) { $crudView = $viewSession->get($sessionName); } else { $crudView = new Ajde_Collection_View($sessionName, $crud->getOption('list.view', array())); } $viewParams = Ajde::app()->getRequest()->getParam('view', array()); $crudView->setOptions($viewParams); $viewSession->set($sessionName, $crudView); $crud->getCollection()->setView($crudView); $view = $crud->getTemplate(); $view->assign('crud', $crud); return $view->render(); }
public function beforeInvoke() { if ($this->_allowGuestTransaction === true) { $this->_allowedActions[] = $this->getAction(); } Ajde_Cache::getInstance()->disable(); return parent::beforeInvoke(); }
public function getContents() { ob_start(); Ajde_Cache::getInstance()->addFile($this->getFilename()); include $this->getFilename(); $contents = ob_get_contents(); ob_end_clean(); return $contents; }
/** * Optional function called before controller is invoked * When returning false, invocation is cancelled. * * @return bool */ public function beforeInvoke($allowed = []) { // set admin layout Ajde::app()->getDocument()->setLayout(new Ajde_Layout(config('layout.admin'))); // disable cache and auto translations Ajde_Cache::getInstance()->disable(); Ajde_Lang::getInstance()->disableAutoTranslationOfModels(); return parent::beforeInvoke($allowed); }
public function beforeInvoke() { $adminAccess = false; //Ajde_Acl::validatePage('admin', '', ''); if (isset($_GET['_route']) && substr($_GET['_route'], 0, 5) == 'admin' || isset($_GET['returnto']) && substr($_GET['returnto'], 0, 5) == 'admin' || $adminAccess) { Ajde::app()->getDocument()->setLayout(new Ajde_Layout(config('layout.admin'))); } Ajde_Cache::getInstance()->disable(); return parent::beforeInvoke(); }
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 static function get($key) { $session = new Ajde_Session('AC.Flash'); if ($session->has($key)) { // Disable the cache, as getting a flashed string means outputting some message to the user Ajde_Cache::getInstance()->disable(); return $session->getOnce($key); } else { return false; } }
public function beforeInvoke() { Ajde_Cache::getInstance()->disable(); $this->_providername = Ajde::app()->getRequest()->getParam('provider', false); $sso = config('ssoProviders'); if (!$this->_providername || !in_array($this->_providername, $sso)) { Ajde_Http_Response::redirectNotFound(); } $classname = 'Ajde_User_Sso_' . ucfirst($this->_providername); $this->_provider = new $classname(); return parent::beforeInvoke(); }
public function item() { // 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(); /* @var $product ProductModel */ $product = new ProductModel(); $product->loadBySlug($slug); $this->product = $product; if ($product->getPublished() === false) { Ajde_Dump::warn('Previewing unpublished product'); } // check if we have a hit if (!$product->hasLoaded()) { Ajde::app()->getResponse()->redirectNotFound(); } Ajde_Event::trigger($this, 'onAfterProductLoaded', [$product]); // update cache Ajde_Cache::getInstance()->updateHash($product->hash()); Ajde_Cache::getInstance()->addLastModified(strtotime($product->updated)); // set title if (!Ajde::app()->getDocument()->hasNotEmpty('title')) { Ajde::app()->getDocument()->setTitle($product->getTitle()); } // set summary if ($product->content) { Ajde::app()->getDocument()->setDescription(Ajde_Component_String::trim(strip_tags($product->content), '100')); } // set author $product->loadParent('user'); /** @var UserModel $owner */ $owner = $product->getUser(); Ajde::app()->getDocument()->setAuthor($owner->getFullname()); // featured image if ($image = $product->featuredImage()) { Ajde::app()->getDocument()->setFeaturedImage($image); } // pass node to view $this->setAction('item'); $this->getView()->assign('product', $product); // render the template return $this->render(); }
public function beforeInvoke($allowed = []) { // disable cache and auto translations Ajde_Cache::getInstance()->disable(); Ajde_Lang::getInstance()->disableAutoTranslationOfModels(); // try to get the crud instance $crud = $this->hasCrudInstance() ? $this->getCrudInstance() : false; if (!$crud && Ajde::app()->getRequest()->has('crudId')) { $session = new Ajde_Session('AC.Crud'); $crud = $session->getModel(Ajde::app()->getRequest()->getParam('crudId')); } if ($crud) { /* @var $crud Ajde_Crud */ $this->setAclParam($crud->getSessionName()); } return parent::beforeInvoke(); }
/** * @param Ajde_Model|Ajde_Collection $object */ public function touchCache($object = null) { Ajde_Cache::getInstance()->updateHash(isset($object) ? $object->hash() : time()); }
public function addResource(Ajde_Resource $resource, $position = self::RESOURCE_POSITION_DEFAULT) { if ($position == self::RESOURCE_POSITION_TOP) { $resource->setPosition(self::RESOURCE_POSITION_FIRST); } else { $resource->setPosition($position); } // Check for duplicates // TODO: another option, replace current resource foreach ($this->_resources as $positionArray) { foreach ($positionArray as $item) { if ((string) $item == (string) $resource) { return false; } } } if ($position === self::RESOURCE_POSITION_TOP) { array_unshift($this->_resources[self::RESOURCE_POSITION_FIRST], $resource); } else { $this->_resources[$position][] = $resource; } // Add to cache if ($resource instanceof Ajde_Resource_Local) { Ajde_Cache::getInstance()->addFile($resource->getFilename()); } return true; }
/** * CSRF prevention token. */ public static function getFormToken() { static $token; if (!isset($token)) { Ajde_Cache::getInstance()->disable(); $token = md5(uniqid(rand(), true)); $session = new Ajde_Session('AC.Form'); $tokenDictionary = self::_getTokenDictionary($session); $tokenDictionary[$token] = self::_tokenHash($token); $session->set('formTokens', $tokenDictionary); } self::markFormTime(); return $token; }
public function set($key, $value) { parent::set($key, $value); if ($value instanceof Ajde_Model) { // TODO: throw new Ajde_Exception('It is not allowed to store a Model directly in the session, use Ajde_Session::setModel() instead.'); } $_SESSION[$this->_namespace][$key] = $value; Ajde_Cache::getInstance()->updateHash($this->hash()); }
public static function includeFileOnce($filename) { Ajde_Cache::getInstance()->addFile($filename); include_once $filename; }
public function getContents() { ob_start(); $filename = $this->getFilename(); Ajde_Cache::getInstance()->addFile($filename); if ($this->exist($filename)) { include $this->realpath($filename); } else { throw new Exception("Couldn't find resource " . $filename); } $contents = ob_get_contents(); ob_end_clean(); return $contents; }
public function verifyCookie($includeDomain = true) { $cookie = new Ajde_Cookie(config('app.id') . '_user', true); if (!$cookie->has('auth')) { return false; } $auth = $cookie->get('auth'); list($uid, $hash) = explode(':', $auth); if (!$this->loadByPK($uid)) { return false; } if ($this->getCookieHash($includeDomain) === $hash) { $this->login(); Ajde_Session_Flash::alert(sprintf(trans('Welcome back %s'), $this->getFullname())); Ajde_Cache::getInstance()->disable(); } else { return false; } }
public function getContents() { if (!isset($this->_contents)) { Ajde_Event::trigger($this, 'beforeGetContents'); Ajde_Cache::getInstance()->addFile($this->getFilename()); $contents = $this->getParser()->parse($this); $this->setContents($contents); Ajde_Event::trigger($this, 'afterGetContents'); } return $this->_contents; }
public function render() { Ajde_Cache::getInstance()->disable(); Ajde::app()->getDocument()->setLayout(new Ajde_Layout('empty')); return parent::render(); }