Beispiel #1
0
 public function registerEvents()
 {
     if (!Ajde_Event::has($this, 'afterCrudLoaded', 'parseForCrud')) {
         Ajde_Event::register($this, 'afterCrudLoaded', 'parseForCrud');
         Ajde_Event::register($this, 'beforeCrudSave', 'prepareCrudSave');
     }
 }
Beispiel #2
0
 public function __bootstrap()
 {
     Ajde_Event::register('Ajde_Core_Route', 'onAfterLangSet', [$this, 'setHomepage']);
     Ajde_Event::register('Ajde_Core_Route', 'onAfterRouteSet', [$this, 'detectNodeSlug']);
     Ajde_Event::register('Ajde_Core_Route', 'onAfterRouteSet', [$this, 'detectShopSlug']);
     return true;
 }
Beispiel #3
0
 public function registerEvents()
 {
     if (!Ajde_Event::has($this, 'afterCrudSave', 'postCrudSave')) {
         Ajde_Event::register($this, 'beforeCrudSave', 'preCrudSave');
         Ajde_Event::register($this, 'afterCrudSave', 'postCrudSave');
     }
 }
Beispiel #4
0
 protected function addTimeoutWarning()
 {
     // Add timeout warning to layout
     if ($this->getLoggedInUser() !== false) {
         Ajde_Event::register('Ajde_Layout', 'beforeGetContents', 'requireTimeoutWarning');
     }
 }
Beispiel #5
0
 public function __fallback($method, $arguments)
 {
     if (Ajde_Event::has('Ajde_Controller', 'call')) {
         return Ajde_Event::trigger('Ajde_Controller', 'call', [$method, $arguments]);
     }
     throw new Ajde_Exception('Call to undefined method ' . get_class($this) . "::{$method}()", 90006);
 }
Beispiel #6
0
 public function __construct()
 {
     /*
      * We add the resources before the template is included, otherwise the
      * layout resources never make it into the <head> section.
      */
     Ajde_Event::register('Ajde_Template', 'beforeGetContents', array($this, 'autoAddResources'));
     parent::__construct();
 }
Beispiel #7
0
 public function __construct($action = null, $format = null)
 {
     $nodetypes = new NodetypeCollection();
     $nodetypes->orderBy('sort');
     foreach ($nodetypes as $type) {
         $this->_modelPermissions['Node types'][$type->name] = ['model' => 'node', 'extra' => $type->id];
     }
     Ajde_Event::trigger($this, 'initAclTypes');
     parent::__construct($action, $format);
 }
Beispiel #8
0
 public function __construct()
 {
     /*
      * We add the resources before the template is included, otherwise the
      * layout resources never make it into the <head> section.
      */
     Ajde_Event::register('Ajde_Template', 'beforeGetContents', [$this, 'autoAddResources']);
     Ajde_Event::register('Ajde_Application', 'onAfterDocumentRendered', [$this, 'setupExternalPageCache']);
     parent::__construct();
 }
Beispiel #9
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();
 }
Beispiel #10
0
 public function __bootstrap()
 {
     \Nabble\SemaltBlocker\Blocker::protect();
     Ajde_Event::register('TransactionModel', 'onPaid', [$this, 'onTransactionPaid']);
     Ajde_Event::register('TransactionModel', 'onCreate', [$this, 'onTransactionCreated']);
     if (UserModel::isTester() || UserModel::isAdmin()) {
         $providers = config('shop.transaction.providers');
         $providers[] = 'test';
         Config::set('shop.transaction.providers', $providers);
     }
     return true;
 }
 public static function register($controller)
 {
     // Extend Ajde_Controller
     if (!Ajde_Event::has('Ajde_Controller', 'call', 'Ajde_Collection::extendController')) {
         Ajde_Event::register('Ajde_Controller', 'call', 'Ajde_Collection::extendController');
     }
     // Extend autoloader
     if ($controller instanceof Ajde_Controller) {
         Ajde_Core_Autoloader::addDir(MODULE_DIR . $controller->getModule() . '/model/');
     } elseif ($controller === '*') {
         self::registerAll();
     } else {
         Ajde_Core_Autoloader::addDir(MODULE_DIR . $controller . '/model/');
     }
 }
Beispiel #12
0
 public function quickJson()
 {
     $parent = Ajde::app()->getRequest()->getPostParam('parent');
     $title = Ajde::app()->getRequest()->getPostParam('title');
     $due = Ajde::app()->getRequest()->getPostParam('due');
     $allocated = Ajde::app()->getRequest()->getPostParam('allocated');
     $model = new NodeModel();
     $model->populate(['parent' => $parent, 'title' => $title, 'user' => UserModel::getLoggedIn()->getPK(), 'nodetype' => NodeModel::NODETYPE_ISSUE]);
     Ajde_Event::trigger($model, 'beforeCrudSave', []);
     $success = $model->insert();
     Ajde_Event::trigger($model, 'afterCrudSave', []);
     $model->saveMetaValue(NodeModel::META_ISSUESTATUS, NodeModel::ISSUESTATUS_NEW);
     $model->saveMetaValue(NodeModel::META_ISSUEDUE, $due);
     $model->saveMetaValue(NodeModel::META_ALLOCATED, $allocated);
     return ['success' => $success, 'message' => $success ? 'Node added' : 'Something went wrong'];
 }
Beispiel #13
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();
 }
Beispiel #14
0
 public function __construct($route)
 {
     $this->_originalRoute = $route;
     // See if first part is language code (i.e. first part is exactly
     // two characters in length)
     if (strlen($route) === 2 || substr($route, 2, 1) === '/') {
         $shortLang = substr($route, 0, 2);
         $langInstance = Ajde_Lang::getInstance();
         if ($lang = $langInstance->getAvailableLang($shortLang)) {
             $this->set('lang', $lang);
             $route = substr($route, 3);
             // set global lang
             $langInstance->setGlobalLang($lang);
         }
     }
     Ajde_Event::trigger($this, 'onAfterLangSet');
     if (!$route) {
         $route = config('routes.homepage');
     }
     // Check for route aliases
     $aliases = config('routes.aliases');
     if (array_key_exists($route, $aliases)) {
         $this->_route = $aliases[$route];
     } else {
         $this->_route = $route;
     }
     Ajde_Event::trigger($this, 'onAfterRouteSet');
     // Get route parts
     $routeParts = $this->_extractRouteParts();
     if (empty($routeParts)) {
         $exception = new Ajde_Core_Exception_Routing(sprintf('Invalid route: %s', $route), 90021);
         Ajde::routingError($exception);
     }
     $defaultParts = config('routes.default');
     $parts = array_merge($defaultParts, $routeParts);
     foreach ($parts as $part => $value) {
         $this->set($part, $value);
     }
 }
Beispiel #15
0
 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;
 }
Beispiel #16
0
 public function run()
 {
     // For debugger
     $this->addTimer('<i>Application</i>');
     // Create fresh response
     $timer = $this->addTimer('Create response');
     $response = new Ajde_Http_Response();
     $this->setResponse($response);
     $this->endTimer($timer);
     Ajde_Event::trigger($this, 'onAfterResponseCreated');
     // Bootstrap init
     $timer = $this->addTimer('Run bootstrap queue');
     $bootstrap = new Ajde_Core_Bootstrap();
     $bootstrap->run();
     $this->endTimer($timer);
     Ajde_Event::trigger($this, 'onAfterBootstrap');
     // Get request
     $timer = $this->addTimer('Read in global request');
     $request = $this->loadRequest();
     $this->endTimer($timer);
     Ajde_Event::trigger($this, 'onAfterRequestCreated');
     // Get route
     $timer = $this->addTimer('Initialize route');
     $route = $request->initRoute();
     $this->setRoute($route);
     $this->endTimer($timer);
     Ajde_Event::trigger($this, 'onAfterRouteInitialized');
     // Load document
     $timer = $this->addTimer('Create document');
     $document = Ajde_Document::fromRoute($route);
     $this->setDocument($document);
     $this->endTimer($timer);
     Ajde_Event::trigger($this, 'onAfterDocumentCreated');
     // Load controller
     $timer = $this->addTimer('Load controller');
     $controller = Ajde_Controller::fromRoute($route);
     $this->setController($controller);
     $this->endTimer($timer);
     Ajde_Event::trigger($this, 'onAfterControllerCreated');
     // Invoke controller action
     $timer = $this->addTimer('Invoke controller');
     $actionResult = $controller->invoke();
     $document->setBody($actionResult);
     $this->endTimer($timer);
     Ajde_Event::trigger($this, 'onAfterControllerInvoked');
     // Get document contents
     $timer = $this->addTimer('Render document');
     $contents = $document->render();
     $this->endTimer($timer);
     Ajde_Event::trigger($this, 'onAfterDocumentRendered');
     // Let the cache handle the contents and have it saved to the response
     $timer = $this->addTimer('Save to response');
     $cache = Ajde_Cache::getInstance();
     $cache->setContents($contents);
     $cache->saveResponse();
     $this->endTimer($timer);
     Ajde_Event::trigger($this, 'onAfterResponseSaved');
     // Output the buffer
     $response->send();
     Ajde_Event::trigger($this, 'onAfterResponseSent');
 }
Beispiel #17
0
 private function submission($crudId, $id)
 {
     $session = new Ajde_Session('AC.Crud');
     /* @var $crud Ajde_Crud */
     $crud = $session->getModel($crudId);
     // verify that we have a valid crud model
     if (!$crud) {
         return ['success' => false];
     }
     /* @var $model FormModel */
     $model = $crud->getModel();
     $model->setOptions($crud->getOptions('model'));
     // Get POST params
     $post = Ajde_Http_Request::globalPost();
     $id = issetor($post['id']);
     // verify that we have a valid form model
     if (!$id) {
         return ['success' => false];
     }
     // load form
     $model->loadByPK($id);
     $model->populate($post);
     // validate form
     Ajde_Event::trigger($model, 'beforeCrudSave', [$crud]);
     if (!$model->validate($crud->getOptions('fields'))) {
         return ['operation' => 'save', 'success' => false, 'errors' => $model->getValidationErrors()];
     }
     // prepare submission
     $values = [];
     foreach ($post as $key => $value) {
         if (substr($key, 0, 5) === 'meta_') {
             $metaId = str_replace('meta_', '', $key);
             $metaName = MetaModel::getNameFromId($metaId);
             $values[$metaName] = $value;
         }
     }
     $entryText = '';
     foreach ($values as $k => $v) {
         $entryText .= $k . ': ' . $v . PHP_EOL;
     }
     $submission = new SubmissionModel();
     $submission->form = $id;
     $submission->ip = $_SERVER['REMOTE_ADDR'];
     $submission->user = Ajde_User::getLoggedIn();
     $submission->entry = json_encode($values);
     $submission->entry_text = $entryText;
     $success = $submission->insert();
     if ($success === true) {
         // Destroy reference to crud instance
         $session->destroy($crudId);
         // set message for next page
         Ajde_Session_Flash::alert(trans('Form submitted successfully'));
         $mailer = new Ajde_Mailer();
         // send email to administrator
         $body = 'Form: ' . $model->displayField() . '<br/><br/>' . nl2br($entryText);
         $mailer->SendQuickMail(config('app.email'), config('app.email'), config('app.title'), 'New form submission', $body);
         // send email to user
         $email = $model->getEmail();
         /* @var $email EmailModel */
         $email_to = $model->getEmailTo();
         /* @var $email MetaModel */
         $email_address = issetor($post['meta_' . $email_to->getPK()]);
         if ($email->hasLoaded() && $email_to->hasLoaded() && $email_address) {
             $mailer->sendUsingModel($email->getIdentifier(), $email_address, $email_address, ['entry' => nl2br($entryText)]);
         }
     }
     return ['operation' => 'save', 'id' => $model->getPK(), 'displayField' => $model->get($model->getDisplayField()), 'success' => $success];
 }
Beispiel #18
0
 public function fireCrudLoadedOnModel($model)
 {
     Ajde_Event::trigger($model, 'afterCrudLoaded');
 }
Beispiel #19
0
 public static function registerDocumentProcessor($format, $registerOn = 'layout')
 {
     $documentProcessors = Config::get('documentProcessors');
     if (is_array($documentProcessors) && isset($documentProcessors[$format])) {
         foreach ($documentProcessors[$format] as $processor) {
             $processorClass = 'Ajde_Document_Processor_' . ucfirst($format) . '_' . $processor;
             if (!Ajde_Core_Autoloader::exists($processorClass)) {
                 // TODO:
                 throw new Ajde_Exception('Processor ' . $processorClass . ' not found', 90022);
             }
             if ($registerOn == 'layout') {
                 Ajde_Event::register('Ajde_Layout', 'beforeGetContents', $processorClass . '::preProcess');
                 Ajde_Event::register('Ajde_Layout', 'afterGetContents', $processorClass . '::postProcess');
             } elseif ($registerOn == 'compressor') {
                 Ajde_Event::register('Ajde_Resource_Local_Compressor', 'beforeCompress', $processorClass . '::preCompress');
                 Ajde_Event::register('Ajde_Resource_Local_Compressor', 'afterCompress', $processorClass . '::postCompress');
             } else {
                 // TODO:
                 throw new Ajde_Exception('Document processor must be registered on either \'layout\' or \'compressor\'');
             }
         }
     }
 }
Beispiel #20
0
 public function paid()
 {
     Ajde_Event::trigger($this, 'onPaid');
     $this->payment_status = 'completed';
     $this->save();
 }
Beispiel #21
0
 public function __construct()
 {
     Ajde_Event::register($this, 'afterCrudLoaded', [$this, 'parseForCrud']);
     parent::__construct();
 }
Beispiel #22
0
 public function saveCache()
 {
     // Bind document processors to compressor
     Ajde_Document::registerDocumentProcessor($this->getType(), 'compressor');
     // Prepare content
     $this->_contents = '';
     foreach ($this->_resources as $resource) {
         /* @var $resource Ajde_Resource_Local */
         $this->_contents .= $resource->getContents() . PHP_EOL;
     }
     if (!is_writable(LOCAL_ROOT . $this->getBase())) {
         throw new Ajde_Exception(sprintf('Directory %s is not writable', $this->getBase()), 90014);
     }
     // Execute compression
     Ajde_Event::trigger($this, 'beforeCompress');
     $this->compress();
     Ajde_Event::trigger($this, 'afterCompress');
     // Save file to cache folder
     file_put_contents(LOCAL_ROOT . $this->getFilename(), $this->_contents);
 }