public function __construct($config, $type) { if (is_string($config)) { $config = (require $config); } if (isset($config['app_path'])) { $this->setBasePath($config['app_path']); Base::setAppPath($config['app_path']); Loader::setPathOfAlias('app', Base::getAppPath()); Loader::setPathOfAlias('public', dirname($_SERVER['SCRIPT_FILENAME'])); unset($config['app_path']); } else { throw new Exception('Application: missing application\'s config "app_path"'); } if (!isset($config['namespace'])) { throw new Exception('Application: missng config "namespace"'); } Loader::addNamespace($config['namespace'], dirname(Base::getAppPath())); $this->setAppNamespace($config['namespace']); if (isset($config['import'])) { $this->_import($config['import']); unset($config['import']); } $this->_type = $type; $this->preInit(); $this->configuration($config); $this->_init(); $this->afterInit(); /** * @TODO removed since version 1.0.2, application custom error handler */ // set_error_handler(array($this,'handleError'),error_reporting()); }
protected function _init() { parent::_init(); $this->viewPath = Base::getApp()->getController()->getTemplatePath() . DIRECTORY_SEPARATOR . 'Widget' . DIRECTORY_SEPARATOR; $this->items = \CMSBackend\Library\MobileMenu::$items; $this->items = \Toxotes\Plugin::applyFilters('custom_admin_mobile_nav', $this->items); }
protected function _init() { /** @var Web $controller */ $controller = \Flywheel\Base::getApp()->getController(); $this->viewPath = $controller->getTemplatePath() . DIRECTORY_SEPARATOR . 'Widget' . DIRECTORY_SEPARATOR; if (null == $this->viewFile) { $this->viewFile = get_class($this); } }
/** * 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); } }
protected function _makeUrl($url) { if (0 === stripos($url[0], 'http') || '#' == $url[0]) { return $url[0]; } if (($coll = \Flywheel\Base::getApp()->getController()) && $coll instanceof Web) { return $coll->createUrl($url[0], array_splice($url, 1)); } return Factory::getRouter()->createUrl($url[0], array_splice($url, 1)); }
public function beforeExecute() { parent::beforeExecute(); // TODO: Change the autogenerated stub $this->form_cfg = ['common' => ['label' => t('Common Settings'), 'settings' => ['site_name' => ['label' => t('Site Name'), 'control' => 'input', 'type' => 'text'], 'site_url' => ['label' => t('Site Url'), 'control' => 'input', 'type' => 'text', 'placeholder' => 'http://'], 'email_address' => ['label' => t('E-mail Address'), 'control' => 'input', 'type' => 'email'], 'contact_phone' => ['label' => t('Company Phone'), 'control' => 'input', 'type' => 'tel'], 'contact_address' => ['label' => t('Company Address'), 'control' => 'input', 'type' => 'text'], 'site_offline' => ['label' => t('Site Offline?'), 'control' => 'checkbox', 'value' => 1]]]]; $other_setting = ConfigHandler::get('site_setting'); if (!empty($other_setting)) { $this->form_cfg['common']['settings'] = Base::mergeArray($this->form_cfg['common']['settings'], $other_setting); } $this->form_cfg = Plugin::applyFilters('custom_system_setting', $this->form_cfg); }
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); } }
public function init() { $app = \Flywheel\Base::getApp(); if (!$app instanceof \Flywheel\Application\ApiApp) { throw new \Flywheel\Exception('Response: application instance not is a "\\Flywheel\\Application\\ApiApp"'); } $this->format = strtolower($app->getFormat()); switch ($this->format) { case 'json': $this->setHeader('Content-type', 'application/json', true); break; case 'xml': $this->setHeader('Content-type', 'text/xml', true); break; default: } }
/** * Initialize * * @return void */ protected function _init() { parent::_init(); ini_set('display_errors', Base::ENV_DEV == Base::getEnv() || Base::ENV_TEST == Base::getEnv() ? 'on' : 'off'); if (Base::getEnv() == Base::ENV_DEV) { error_reporting(E_ALL); } else { if (Base::getEnv() == Base::ENV_TEST) { error_reporting(E_ALL ^ E_NOTICE); } } if (ConfigHandler::has('timezone')) { date_default_timezone_set(ConfigHandler::get('timezone')); } else { date_default_timezone_set(@date_default_timezone_get()); } }
/** * initConfig * @param $config */ public function __construct($config = array()) { // Load config if (empty($config)) { ConfigHandler::get('session'); // Read config from session key in config file } $this->_config = array_merge($this->_config, $config); if (isset($this->_config['storage']) && $this->_config['storage']) { $handlerClass = $this->_config['storage']; unset($this->_config['handler']); $storage = new $handlerClass($this->_config); session_set_save_handler(array(&$storage, 'open'), array(&$storage, 'close'), array(&$storage, 'read'), array(&$storage, 'write'), array(&$storage, 'destroy'), array(&$storage, 'gc')); self::$_storage = $storage; } if (isset($this->_config['name'])) { session_name($this->_config['name']); } ini_set('session.gc_maxlifetime', $this->_config['lifetime']); //define the lifetime of the cookie if (isset($this->_config['cookie_ttl']) || isset($this->_config['cookie_domain']) || isset($this->_config['cookie_path'])) { // cross subdomain validity is default behavior $ttl = isset($this->_config['cookie_ttl']) ? (int) $this->_config['cookie_ttl'] : 0; $domain = isset($this->_config['cookie_domain']) ? $this->_config['cookie_domain'] : '.' . Factory::getRouter()->getDomain(); $path = isset($this->_config['cookie_path']) ? '/' . trim($this->_config['cookie_path'], '/') . '/' : '/'; session_set_cookie_params($ttl, $path, $domain); } else { $cookie = session_get_cookie_params(); session_set_cookie_params($cookie['lifetime'], $cookie['path'], $cookie['domain']); } if (Base::getApp()) { if (Factory::getRequest()->isSecure()) { ini_set('session.cookie_secure', true); } } ini_set('session.use_only_cookies', 1); if (isset($handlerClass)) { $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => $handlerClass))); } else { $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => 'default'))); } }
protected function _init() { parent::_init(); $this->viewPath = Base::getApp()->getController()->getTemplatePath() . DIRECTORY_SEPARATOR . 'Widget' . DIRECTORY_SEPARATOR; //f**k it foreach ($this->_menus as $m => $content) { $this->_menus[$m]['label'] = t($this->_menus[$m]['label']); } //Menu Widget $this->_addChildMenu('menu_widget', ['label' => t('Menu List'), 'url' => ['menu/default']]); $this->_addChildMenu('menu_widget', ['label' => t('Add Menu'), 'url' => ['menu/create']]); //Post $this->_addChildMenu('posts', ['label' => t('All Posts'), 'url' => ['post/default']]); $this->_addChildMenu('posts', ['label' => t('Compose New'), 'url' => ['post/create']]); $this->_addChildMenu('posts', ['label' => t('Categories'), 'url' => ['category/default', 'taxonomy' => 'category']]); $this->_addSiteContentMenu(); $this->_addProductsMenu(); $this->items = \Toxotes\Plugin::applyFilters('after_init_admin_main_nav', $this->items); $this->_addSystemMenu(); $this->_buildMenu(); }
protected function _init() { ini_set('display_errors', Base::ENV_DEV == Base::getEnv() || Base::ENV_TEST == Base::getEnv() ? 'on' : 'off'); //Error reporting if (Base::getEnv() == Base::ENV_DEV) { error_reporting(E_ALL); } else { if (Base::getEnv() == Base::ENV_TEST) { error_reporting(E_ALL ^ E_NOTICE); } } //set timezone if (ConfigHandler::has('timezone')) { date_default_timezone_set(ConfigHandler::get('timezone')); } else { date_default_timezone_set(@date_default_timezone_get()); } $this->_requestMethod = strtoupper($_SERVER['REQUEST_METHOD']); if (!in_array($this->_requestMethod, self::$RESTfulREQUEST)) { throw new ApiException('Application: Request method unsupported!', null, 400); } }
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(); }
public function authenticate($credential, $password, $cookie = false) { $this->dispatch('onBeginAuthenticate', new BaseEvent($this, array($credential))); if (empty($credential) || empty($password)) { return self::ERROR_CREDENTIAL_INVALID; } $this->_identity = $credential; $this->_credential = $password; if (strpos($credential, '@') !== false) { $user = \Users::retrieveByEmail($credential); } else { $user = \Users::retrieveByUsername($credential); } if (!$user || empty($user) || !$user instanceof \Users) { return self::ERROR_UNKNOWN_IDENTITY; } if ($user instanceof \Users) { if ($user->password != \Users::hashPassword($password, $user->password)) { return self::ERROR_CREDENTIAL_INVALID; } $this->_clearCookie(); if ($cookie) { $this->setCookie($user); } $this->setSession($user); $this->_setIsAuthenticated(true); $user->setLastVisitTime(new DateTime()); $user->setLastLoginIp(Base::getApp()->getClientIp()); $user->save(); if ($user) { $this->dispatch('onAfterAuthenticate', new BaseEvent($this, $user->getAttributes())); } return $this->isAuthenticated(); } return false; }
public function parseUrl($url) { $url = trim($url, '/'); if (null == $url) { throw new ApiException('Invalid request !', 404); } $segment = explode('/', $url); $_cf = explode('.', end($segment)); //check define format if (isset($_cf[1])) { $this->_format = $_cf[1]; $segment[count($segment) - 1] = $_cf[0]; } $size = sizeof($segment); $router = array(); for ($i = 0; $i < $size; ++$i) { $router[$i] = Inflection::camelize($segment[$i]); } for ($i = $size - 1; $i >= 0; --$i) { $router = array_slice($router, 0, $i + 1); $_camelName = implode("\\", $router); $_path = implode(DIRECTORY_SEPARATOR, $router); if (false !== file_exists($file = Base::getAppPath() . '/Controller/' . $_path . '.php')) { $this->_api = trim($_camelName, "\\"); break; } } if (null == $this->_api) { throw new ApiException('API not found', 404); } $segment = array_slice($segment, $i + 1); if (!empty($segment)) { $this->_method = array_shift($segment); $this->_params = !empty($segment) ? $segment : array(); } }
/** * Add Config setting * @param array $config * @param string $namespace */ public static function add($config, $namespace = 'default') { if (!isset(self::$_data[$namespace])) { self::$_data[$namespace] = $config; } else { self::$_data[$namespace] = Base::mergeArray(self::$_data[$namespace], $config); } }
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()); }
private function _parseControllers($route) { if (false === is_array($route)) { $route = explode('/', $route); } $_path = ''; $_camelName = ''; $size = sizeof($route); for ($i = 0; $i < $size; ++$i) { $route[$i] = Inflection::camelize($route[$i]); } for ($i = $size - 1; $i >= 0; --$i) { $_camelName = implode("\\", array_slice($route, 0, $i + 1)); $_path = implode(DIRECTORY_SEPARATOR, array_slice($route, 0, $i + 1)); if (false !== file_exists($file = Base::getAppPath() . '/Controller/' . $_path . '.php')) { $this->_camelControllerName = trim($_camelName, "\\"); break; } } return $i; }
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(); }
protected function _init() { parent::_init(); $this->viewPath = Base::getApp()->getController()->getTemplatePath() . DIRECTORY_SEPARATOR . 'Widget' . DIRECTORY_SEPARATOR; $this->items = \Toxotes\Plugin::applyFilters('custom_admin_left_sidebar', $this->items); }
/** * 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))); }
/** * Get Session * @deprecated Change method to \Flywheel\Session\Session::getInstance() * * @throws Exception * @return \Flywheel\Session\Session */ public static function getSession() { if (!Base::getApp()) { throw new Exception('Factory: Session must start after the application is initialized!'); } if (!isset(self::$_registry['session'])) { $config = ConfigHandler::load('app.config.session', 'session', false) or $config = ConfigHandler::load('global.config.session', 'session'); if (false == $config) { throw new Exception('Session: config file not found, "session.cfg.php" must be exist at globals/config or ' . Base::getAppPath() . ' config directory'); } $class = self::$_classesList['Session']; self::$_registry['session'] = new $class($config); } return self::$_registry['session']; }
/** * 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(); } }
protected function _setOptions() { if (isset($this->_config['session_name'])) { session_name($this->_config['session_name']); } if (isset($this->_config['session_id'])) { session_id($this->_config['session_id']); } //using cookie secure if (Base::getApp()) { if (Factory::getRequest()->isSecure()) { ini_set('session.cookie_secure', true); } } ini_set('session.gc_maxlifetime', $this->_config['lifetime']); ini_set('session.cookie_lifetime', $this->_config['lifetime']); }
public function __construct($render = null) { parent::__construct($render); $this->viewPath = Base::getApp()->getController()->getTemplatePath() . DIRECTORY_SEPARATOR . 'Widget' . DIRECTORY_SEPARATOR; }
protected function _init() { parent::_init(); $this->viewPath = Base::getApp()->getController()->getTemplatePath() . DIRECTORY_SEPARATOR . 'Widget' . DIRECTORY_SEPARATOR; }