/**
  * validation ajax request
  *
  * @param bool $end
  * @param string $endMess
  * @return bool|void
  */
 public function validAjaxRequest($end = true, $endMess = 'Invalid request!')
 {
     $valid = $this->request()->isXmlHttpRequest();
     if ($valid) {
         return true;
     }
     if ($end) {
         Base::end($endMess);
     }
 }
 public final function execute($action)
 {
     $action = 'execute' . Inflection::hungaryNotationToCamel($action);
     if (method_exists($this, $action)) {
         $this->getEventDispatcher()->dispatch('onBeginControllerExecute', new Event($this, array('action' => $action)));
         $this->beforeExecute();
         $this->{$action}();
         $this->afterExecute();
         $this->getEventDispatcher()->dispatch('onAfterControllerExecute', new Event($this, array('action' => $action)));
     } else {
         Base::end('ERROR: task ' . Inflection::hungaryNotationToCamel($this->_name) . ':' . $action . ' not existed!' . PHP_EOL);
     }
 }
Exemple #3
0
 public function beforeExecute()
 {
     parent::beforeExecute();
     // TODO: Change the autogenerated stub
     $this->_registerDefaultTaxonomies();
     $this->loadPlugin();
     if ($this->_need_login) {
         /** @var CMSBackendAuth $auth */
         $auth = CMSBackendAuth::getInstance();
         if (!$auth->isCMSBackendAuthenticated()) {
             if ($this->request()->isXmlHttpRequest()) {
                 Base::end(json_encode(array('error' => 'AUTHENTICATE FAIL', 'error_code' => 'E0001', 'message' => t('This session was expired, plz login and comeback!'))));
             } else {
                 //redirect
                 $this->redirect($this->createUrl('login', array('r' => urlencode($this->request()->getUri()))));
             }
         }
     }
     $this->document()->addJsVar('login_url', $this->createUrl('login'));
     $this->document()->addJsVar('media_upload_url', $this->createUrl('media/upload'));
     $this->_initTemplate();
     $this->_loadLanguage();
 }
Exemple #4
0
 public function executeRemoveCf()
 {
     if ($this->validAjaxRequest() || !$this->request()->isPostRequest()) {
         Base::end('Invalid request!');
     }
     $ajax = new \AjaxResponse();
     $customField = \TermCustomFields::retrieveById($this->request()->get('id'));
     if (!$customField) {
         $ajax->message = t("Custom field not found!");
         $ajax->type = \AjaxResponse::ERROR;
         return $this->renderText($ajax->toString());
     }
     $customField->beginTransaction();
     if ($customField->delete()) {
         \PostCustomFields::write()->delete(\PostCustomFields::getTableName())->where('cf_id = ?')->setParameter(1, $customField->getId(), \PDO::PARAM_INT)->execute();
         $customField->commit();
         $ajax->message = t($customField->getName() . ' was removed!');
         $ajax->type = \AjaxResponse::SUCCESS;
         return $this->renderText($ajax->toString());
     }
     $customField->rollBack();
     $ajax->message = t("Could not remove {$customField->getName()}!");
     $ajax->type = \AjaxResponse::ERROR;
     return $this->renderText($ajax->toString());
 }
 public function run()
 {
     $this->beforeRun();
     $this->getEventDispatcher()->dispatch('onBeginRequest', new Event($this));
     if (null == $this->_task) {
         throw new Exception("Missing 'task' parameter!");
     }
     $camelName = Inflection::hungaryNotationToCamel($this->_task);
     $class = $this->getAppNamespace() . '\\Task\\' . $camelName;
     $taskPath = TASK_DIR . 'Task/' . str_replace('\\', DIRECTORY_SEPARATOR, $camelName) . '.php';
     if (file_exists($taskPath)) {
         //            require_once $file;
         $this->_controller = new $class($this->_task, $taskPath);
         $this->_controller->execute($this->_act);
         $this->_finished = true;
     } else {
         Base::end("ERROR: task {$this->_task} ({$taskPath}/{$class}Task.php) not existed" . PHP_EOL);
     }
     $this->getEventDispatcher()->dispatch('onEndRequest', new Event($this));
     $this->afterRun();
 }
Exemple #6
0
 /**
  * Execute
  *
  * @param $action
  * @throws \Flywheel\Exception\NotFound404
  * @return string component process result
  */
 public final function execute($action)
 {
     $this->getEventDispatcher()->dispatch('onBeginControllerExecute', new Event($this, array('action' => $action)));
     $csrf_auto_protect = ConfigHandler::get('csrf_protection');
     if (null === $csrf_auto_protect || $csrf_auto_protect) {
         if (!$this->request()->validateCsrfToken()) {
             Base::end('Invalid token');
         }
     }
     /* @var \Flywheel\Router\WebRouter $router */
     $router = Factory::getRouter();
     $this->_action = $action;
     /* removed from version 1.1
      * //set view file with action name
      * $this->_view = $this->_path .$action;
      */
     $action = 'execute' . Inflection::camelize($action);
     if (!method_exists($this, $action)) {
         throw new NotFound404("Controller: Action \"" . $router->getController() . '/' . $action . "\" doesn't exist");
     }
     $this->beforeExecute();
     $this->filter();
     $this->_beforeRender();
     $this->view()->assign('controller', $this);
     $this->_buffer = $this->{$action}();
     $this->_afterRender();
     $this->afterExecute();
     // assign current controller
     $this->view()->assign('controller', $this);
     $this->getEventDispatcher()->dispatch('onAfterControllerExecute', new Event($this, array('action' => $action)));
 }
 /**
  * Redirects the browser to the specified URL.
  * @param string $url URL to be redirected to. If the URL is a relative one, the base URL of
  * the application will be inserted at the beginning.
  * @param int $code the HTTP status code. Defaults to 302. See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html}
  * @param bool $end whether to terminate the current application
  */
 public static function redirect($url, $code = 302, $end = true, $absolute = true)
 {
     $baseUrl = Factory::getRouter()->getBaseUrl();
     $domain = Factory::getRouter()->getDomain();
     if (strpos($url, 'http') !== 0) {
         //not entire url
         $baseUrl = Factory::getRouter()->getBaseUrl();
         if (false === strpos($baseUrl, '.php')) {
             $baseUrl = rtrim($baseUrl, '/') . '/';
         }
         $url = $baseUrl . ltrim($url, '/');
     }
     header('Location: ' . $url, true, $code);
     if (true == $end) {
         Base::end();
     }
 }