예제 #1
0
파일: Config.php 프로젝트: nabble/ajde
 /**
  * TODO.
  */
 public function __construct()
 {
     $this->repository = new Ajde_Config_Repository(CONFIG_DIR);
     if ($this->repository->get('security.secret') === '_RANDOM_12_16_OR_32_CHAR_STRING_') {
         Ajde_Dump::warn('Using unsafe secret: your app is insecure. See security.json');
     }
 }
예제 #2
0
 public function getModel($name)
 {
     // If during the session class definitions has changed, this will throw an exception.
     try {
         return unserialize($this->get($name));
     } catch (Exception $e) {
         Ajde_Dump::warn('Model definition changed during cookie period');
         return false;
     }
 }
예제 #3
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();
 }
 public function view()
 {
     Ajde_Model::register($this);
     // Direct object creation and chaining only from PHP 5.3!
     // Use $blog = new BlogCollection() instead
     /* @var $samples SamplesCollection */
     $samples = SamplesCollection::create()->orderBy('sort', Ajde_Query::ORDER_ASC)->filter('published', 1);
     if ($this->hasId()) {
         $samples->addFilter(new Ajde_Filter_Where('id', Ajde_Filter::FILTER_EQUALS, $this->getId()));
     }
     $this->getView()->assign('samples', $samples);
     Ajde_Dump::warn('This is a test warning');
     Ajde::app()->getDocument()->setDescription("This is the samples module");
     return $this->render();
 }
예제 #5
0
 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();
 }
예제 #6
0
 public function createHash($password)
 {
     // @see http://net.tutsplus.com/tutorials/php/understanding-hash-functions-and-keeping-passwords-safe/
     if (CRYPT_BLOWFISH !== 1) {
         Ajde_Dump::warn('BLOWFISH algorithm not available for hashing, using MD5 instead');
         // Use MD5
         $algo = '$1';
         $cost = '';
         $unique_salt = $this->generateSecret(12);
     } else {
         // Use BLOWFISH
         $algo = '$2a';
         $cost = '$10';
         $unique_salt = $this->generateSecret(22);
     }
     $hash = crypt($password, $algo . $cost . '$' . $unique_salt);
     if (empty($hash)) {
         // TODO:
         throw new Ajde_Exception('crypt() algorithm failed');
     }
     return $hash;
 }