public function begin()
 {
     if (null == $this->viewFile) {
         $this->viewFile = 'pagination';
     }
     if (!$this->viewPath) {
         $this->viewPath = __DIR__ . '/template/';
     }
     $this->router = Factory::getRouter();
     $this->totalPage = ceil($this->total / $this->pageSize);
     if ($this->currentPage < 0 || $this->currentPage > $this->totalPage) {
         $this->currentPage = 1;
     }
     if ($this->currentPage > $this->numPageShow / 2) {
         $this->startPage = $this->currentPage - floor($this->numPageShow / 2);
         if ($this->totalPage - $this->startPage < $this->numPageShow) {
             $this->startPage = $this->totalPage - $this->numPageShow + 1;
         }
     } else {
         $this->startPage = 1;
     }
     if ($this->startPage < 1) {
         $this->startPage = 1;
     }
 }
Esempio n. 2
0
 protected function _init()
 {
     $doc = \Flywheel\Factory::getDocument();
     $doc->addJsVar('get_locations_url', $this->getRender()->createUrl('transporter/location/get_all_locations'));
     $doc->addJs('js/process/transporter/transporter.js');
     $doc->addJs('js/process/transporter/location.js');
 }
Esempio n. 3
0
 public function end()
 {
     $htmlOptions = array_merge(['rel' => $this->rel, 'data-value' => $this->selected, 'id' => $this->id], $this->htmlOptions);
     /** @var Form $this->form */
     $this->form->selectOption($this->name, '', $htmlOptions)->display();
     $doc = \Flywheel\Factory::getDocument();
     $doc->addJsCode('Transporter.Location.Province.display("#' . $this->id . '");');
 }
Esempio n. 4
0
 public function endForm($csrfProtection = true)
 {
     $s = '';
     if ($csrfProtection) {
         $s .= '<input type="hidden" name="' . Factory::getRequest()->getCsrfToken() . '" value=1>';
     }
     $s .= '</form>';
     echo $s;
 }
Esempio n. 5
0
 public function executeLogin()
 {
     $this->document()->title = t('Login');
     $this->setLayout('login');
     $this->setView('Login/default');
     /** @var CMSBackendAuth $backendAuth */
     $backendAuth = CMSBackendAuth::getInstance();
     $comeback = $this->get('r');
     $comeback = null != $comeback ? urldecode($comeback) : '/';
     if ($backendAuth->isCMSBackendAuthenticated()) {
         $this->redirect($comeback);
     }
     $display = $this->post('credential');
     if (!$display) {
         $display = Factory::getCookie()->read('username');
     }
     $languages = \Languages::getAllActiveLanguages('lang_code');
     $error = array();
     if ($this->request()->isPostRequest()) {
         //check captcha first
         $password = $this->post('password');
         $credential = $this->post('credential');
         //don't care display name
         $chosen_lang = $this->post('language');
         Factory::getCookie()->write('language', $chosen_lang);
         /*$captcha = $this->post('captcha');*/
         Factory::getCookie()->write('username', $credential);
         /*if(Math::check($captcha)==false) {
               $error[] = t('Sai rồi, tính nhẩm kém quá');
           }*/
         if (empty($error) && true === ($result = $backendAuth->authenticate($credential, $password))) {
             //authenticated, redirect to pre-page
             $this->redirect($comeback);
         } else {
             if (isset($result)) {
                 switch ($result) {
                     case CMSBackendAuth::ERROR_USER_NOT_ACCESS_ADMIN:
                         $error[] = t('Restricted area, no permission');
                         break;
                     case CMSBackendAuth::ERROR_CREDENTIAL_INVALID:
                         $error[] = t('Plz re-enter your email or your password');
                         break;
                     case CMSBackendAuth::ERROR_UNKNOWN_IDENTITY:
                         $error[] = t('Unknown identity');
                         break;
                     default:
                         $error[] = t('Login fail');
                 }
             }
         }
     }
     $this->view()->assign('display', $display);
     $this->view()->assign('error', $error);
     $this->view()->assign('current_lang', $this->currentLang ? $this->currentLang->getLangCode() : '');
     $this->view()->assign('languages', $languages);
     return $this->renderComponent();
 }
Esempio n. 6
0
 public function __construct($render = null)
 {
     if (null == $render) {
         $this->_render = Factory::getView();
     } else {
         $this->_render = $render;
     }
     $this->_init();
 }
 public function begin()
 {
     foreach ($this->links as $label => $link) {
         if (is_string($label)) {
             $link = array_merge_recursive(array('htmlOptions' => array()), $link);
             $this->_actives[] = array('label' => $label, 'url' => is_array($link['url']) ? Factory::getRouter()->createUrl($link['url'][0], array_slice($link['url'], 1)) : $link['url'], 'htmlOptions' => $link['htmlOptions']);
         } else {
             $this->_inactive[] = $link;
         }
     }
 }
 /**
  * Run
  * @throws \Flywheel\Exception\Api
  */
 public function run()
 {
     $this->beforeRun();
     $this->getEventDispatcher()->dispatch('onBeginRequest', new Event($this));
     $content = $this->_loadMethod();
     $response = Factory::getResponse();
     $response->setBody($content);
     $response->send();
     $this->getEventDispatcher()->dispatch('onEndRequest', new Event($this));
     $this->afterRun();
 }
Esempio n. 9
0
 private static function _responseError(\Exception $e)
 {
     /* @var \Flywheel\Router\ApiRouter $router */
     $router = \Flywheel\Factory::getRouter();
     $response = new \stdClass();
     $response->hash = array('request' => $router->getUri(), 'error' => $e->getMessage());
     if (400 != $e->getCode()) {
         $response->hash['api'] = $router->getApi() . '/' . $router->getMethod();
         $response->hash['format'] = $router->getFormat();
     }
     return $response;
 }
Esempio n. 10
0
 protected function _loadMethod()
 {
     /* @var \Flywheel\Router\WebRouter $router */
     $router = Factory::getRouter();
     $name = $router->getCamelControllerName();
     $apiMethod = $router->getAction();
     $class = $this->getAppNamespace() . "\\Controller\\{$name}";
     if (!file_exists($file = $this->_basePath . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . str_replace("\\", DIRECTORY_SEPARATOR, $name) . '.php')) {
         throw new Exception("Api's method {$class}/{$apiMethod} not found!", 404);
     }
     $this->_controller = new $class($name, $router->getParams());
     return $this->_controller->execute($this->_requestMethod, $apiMethod);
 }
Esempio n. 11
0
 /**
  * @param bool $isRemap
  * @throws \Flywheel\Exception\NotFound404
  * @param bool $isRemap
  * @return mixed
  */
 protected function _loadController($isRemap = false)
 {
     /* @var \Flywheel\Router\WebRouter $router */
     $router = Factory::getRouter();
     $controllerName = $router->getCamelControllerName();
     $className = $this->getAppNamespace() . "\\Controller\\{$controllerName}";
     $controllerPath = $router->getControllerPath();
     if (!file_exists($file = $this->_basePath . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . str_replace("\\", DIRECTORY_SEPARATOR, $controllerName) . '.php')) {
         throw new NotFound404("Application: Controller \"{$controllerName}\"[{$file}] does not existed!");
     }
     /* @var \Flywheel\Controller\Web _controller */
     $this->_controller = new $className($controllerName, $router->getControllerPath());
     $this->_controller->execute($router->getAction());
     return $this->_controller->render();
 }
Esempio n. 12
0
 public final function execute($regMethod, $method = null)
 {
     if (!$method) {
         throw new \Flywheel\Exception\Api('Api not found', 404);
     }
     $apiMethod = strtolower($regMethod) . Inflection::camelize($method);
     $this->getEventDispatcher()->dispatch('onBeginControllerExecute', new Event($this, array('action' => $apiMethod)));
     if (!method_exists($this, $apiMethod)) {
         throw new \Flywheel\Exception\Api('Api ' . Factory::getRouter()->getApi() . "/{$method} not found", 404);
     }
     $this->beforeExecute();
     $buffer = $this->{$apiMethod}();
     $this->afterExecute();
     $this->getEventDispatcher()->dispatch('onAfterControllerExecute', new Event($this, array('action' => $apiMethod)));
     return $buffer;
 }
Esempio n. 13
0
 /**
  * @param $item
  * @return bool
  */
 protected function _isItemActive($item)
 {
     $router = Factory::getRouter();
     if (isset($item['url']) && is_array($item['url']) && !strcasecmp(trim($item['url'][0], '/'), $router->getRoute())) {
         unset($item['url']['#']);
         if (count($item['url']) > 1) {
             foreach (array_splice($item['url'], 1) as $name => $value) {
                 if (!isset($_GET[$name]) || $_GET[$name] != $value) {
                     return false;
                 }
             }
         }
         return true;
     }
     return false;
 }
Esempio n. 14
0
 public function end()
 {
     $doc = Factory::getDocument();
     $js = 'tinymce.init({
         selector: "' . implode(array_unique($this->_selectors)) . "\",\n" . ($this->width ? 'width :' . $this->width . ",\n" : '') . ($this->height ? 'height :' . $this->height . ",\n" : '') . ($this->content_css ? 'content_css : "' . $this->content_css . "\",\n" : '') . 'plugins: [
             "advlist autolink lists link image charmap print preview hr anchor pagebreak",
             "searchreplace wordcount visualblocks visualchars code fullscreen",
             "media save table directionality",
             "emoticons template paste textcolor"
         ],
         theme:"modern",
         skin:"lightgray",
         menubar : false,
         toolbar1: "bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | preview media | forecolor",
         image_advtab: true,
     });';
     $doc->addJsCode($js, 'TOP', 'standard');
 }
Esempio n. 15
0
 /**
  * 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')));
     }
 }
Esempio n. 16
0
 public function end()
 {
     $doc = Factory::getDocument();
     $opt = array_merge(['focus' => false, 'styleWithSpan' => false, 'maximumImageFileSize' => ini_get('upload_max_filesize') * 1000000.0, 'toolbar' => [['style', ['style']], ['font', ['bold', 'italic', 'underline', 'clear']], ['font-style', ['fontsize']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['height', ['height']], ['table', ['table']], ['insert', ['link', 'video', 'picture', 'hr']], ['view', ['fullscreen', 'codeview']], ['help', ['undo', 'redo', 'help']]]], ['height' => $this->height]);
     $js = '';
     $opt = json_encode($opt);
     $opt = str_replace('}', ', onImageUpload: function(files, editor, welEditable) {
                 media_upload(files[0],editor,welEditable);
             }
         }', $opt);
     foreach ($this->_selectors as $selector) {
         $js .= '$("' . $selector . '").summernote(
             ' . $opt . '
         );';
         /*$js .= '$("' .$selector .'").summernote({
               onImageUpload: function(files, editor, welEditable) {
                   media_upload(files[0],editor,welEditable);
               }
           });';*/
     }
     $doc->addJsCode($js);
 }
Esempio n. 17
0
 /**
  * load languages
  */
 private function _loadLanguage()
 {
     $i18nCfg = ConfigHandler::get('i18n');
     if (!$i18nCfg['enable']) {
         return null;
     }
     $current_lang_code = $this->get('lang');
     if (!$current_lang_code) {
         $current_lang_code = Factory::getCookie()->read('language');
     }
     if (!$current_lang_code) {
         $this->currentLang = \Languages::retrieveByDefault(1);
         $current_lang_code = $this->currentLang->getLangCode();
     } else {
         $this->currentLang = \Languages::retrieveByLangCode($current_lang_code);
     }
     if ($current_lang_code) {
         Factory::getCookie()->write('language', $current_lang_code);
     }
     //load message
     $translator = Translator::getInstance();
     $translator->setLocale($current_lang_code);
     if ($translator) {
         $translator->addLoader('yml', new YamlFileLoader());
         if (isset($i18nCfg['resource']) && is_array($i18nCfg['resource'])) {
             foreach ($i18nCfg['resource'] as $locale => $files) {
                 for ($i = 0, $size = sizeof($files); $i < $size; ++$i) {
                     $fileInfo = new \SplFileInfo($files[$i]);
                     $filename = $fileInfo->getFilename();
                     $ext = $fileInfo->getExtension();
                     if ($ext == 'yml') {
                         $domain = str_replace('.' . $fileInfo->getExtension(), '', $fileInfo->getFilename());
                         $translator->addResource('yml', $files[$i], $locale, $domain);
                     }
                 }
             }
         }
     }
 }
Esempio n. 18
0
 protected function _initLanguages()
 {
     $this->languages = \Languages::findByPublished(true);
     if (sizeof($this->languages) < 2) {
         $this->currentLang = $this->languages[0];
         return;
     }
     $currentLangCode = $this->request()->get('lang');
     if (!$currentLangCode) {
         $currentLangCode = Factory::getCookie()->read('lang');
     }
     if (!$currentLangCode) {
         $this->currentLang = \Languages::findOneByDefault(true);
         $currentLangCode = $this->currentLang->getLangCode();
     }
     Factory::getCookie()->write('lang', $currentLangCode);
     if (Factory::getRouter()->getUrl() == '/' && !$this->request()->get('lang')) {
         $this->redirect($currentLangCode);
     }
     if (!$this->currentLang) {
         $this->currentLang = \Languages::findOneByLangCode($currentLangCode);
     }
     $translator = Translator::getInstance();
     $translator->setLocale($currentLangCode);
     Cms::$currentLang = $this->currentLang;
 }
Esempio n. 19
0
 protected function _columnCategory($item)
 {
     /** @var \Posts $item */
     $s = '';
     if ($item->getTermId()) {
         $category = \Terms::retrieveById($item->getTermId());
         if ($category) {
             $eLink = Factory::getRouter()->createUrl('category/edit', array('id' => $category->getId(), 'taxonomy' => $category->getTaxonomy()));
             $s .= '<a href="' . $eLink . '">' . $category->getName() . '</a>';
         }
     }
     return $s;
 }
Esempio n. 20
0
 private function _clearCookie()
 {
     Factory::getCookie()->writeSecure('auth', null, -100000);
 }
 /**
  * Parses a URL based on this rule.
  * @param WebRouter $router the URL manager
  * @param string $pathInfo path info part of the URL
  * @param string $rawPathInfo path info that contains the potential URL suffix
  * @return mixed the route that consists of the controller ID and action ID or false on error
  */
 public function parseUrl($router, $pathInfo, $rawPathInfo)
 {
     $request = Factory::getRequest();
     if (isset($this->filter['method']) && is_array($this->filter['method']) && !in_array($request->getMethod(), $this->filter['method'], true)) {
         return false;
     }
     if (isset($this->options['urlSuffix']) && null !== $this->options['urlSuffix']) {
         $pathInfo = $router->removeUrlSuffix($rawPathInfo, $this->options['urlSuffix']);
     }
     $pathInfo .= '/';
     if (preg_match($this->pattern, $pathInfo, $matches)) {
         foreach ($this->initParameters as $name => $value) {
             if (!isset($_GET[$name])) {
                 $_REQUEST[$name] = $_GET[$name] = $value;
             }
         }
         $tr = array();
         foreach ($matches as $key => $value) {
             if (isset($this->references[$key])) {
                 $tr[$this->references[$key]] = $value;
             } else {
                 if (isset($this->params[$key])) {
                     $router->params[$key] = $_GET[$key] = $value;
                 }
             }
         }
         if ($pathInfo !== $matches[0]) {
             $router->parsePathInfo(ltrim(substr($pathInfo, strlen($matches[0])), '/'));
         }
         if ($this->routePattern !== null) {
             return strtr($this->route, $tr);
         } else {
             return $this->route;
         }
     } else {
         return false;
     }
 }
 /**
  *
  */
 protected function _init()
 {
     define('TASK_DIR', APP_PATH . '/');
     ini_set('display_errors', ConfigHandler::get('debug') ? '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());
     }
     if (true === $this->isCli()) {
         $argv = $_SERVER['argv'];
         $seek = 1;
         if (null == $this->_task) {
             $this->_task = $argv[$seek];
             ++$seek;
         }
         if (null == $this->_act && isset($argv[$seek])) {
             $this->_act = $argv[$seek];
             ++$seek;
         } else {
             $this->_act = 'default';
         }
         if (isset($argv[$seek])) {
             $this->_originalParams = array_slice($argv, $seek);
             $this->_params = $this->_process($this->_originalParams);
         }
     } else {
         //run on browser (only for test)
         if (null !== ($task = Factory::getRequest()->get('task'))) {
             $this->_task = $task;
         }
         if (null !== ($act = Factory::getRequest()->get('act'))) {
             $this->_act = $act;
         }
     }
 }
Esempio n. 23
0
 protected function _columnTool($item)
 {
     $s = '';
     $subtool = '';
     $subtool = '<div class="sub-tool">';
     $subtool = Plugin::applyFilters('custom_' . $item->taxonomy . '_subtool', $subtool);
     $s .= $subtool;
     $removeLink = Factory::getRouter()->createUrl('category/delete', array('id' => $item->id));
     $editLink = Factory::getRouter()->createUrl('category/edit', array('id' => $item->id));
     $s .= '<a href="' . $editLink . '" class="tool-link tool-edit">' . t('Edit') . '</a> | <a href="' . $removeLink . '" class="tool-link tool-remove" rel="term-' . $item->getId() . '">' . t('Remove') . '</a>';
     $s = Plugin::applyFilters('manage_' . $this->taxonomy . '_custom_tool_column', $s, $item->id);
     return $s;
 }
Esempio n. 24
0
 protected function _setCookieParams()
 {
     //define the lifetime of the cookie
     if (isset($this->_config['cookie_ttl']) || isset($this->_config['cookie_domain']) || isset($this->_config['cookie_path'])) {
         //LuuHieu: since May 2015 remove default share cookie sub domain
         // 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']);
     }
 }
Esempio n. 25
0
 /**
  * alias call @see WebRouter::createUrl();
  * @param $route
  * @param array $params
  * @param string $ampersand
  * @return mixed
  */
 public function createUrl($route, $params = array(), $ampersand = '&')
 {
     return Factory::getRouter()->createUrl($route, $params, $ampersand);
 }
Esempio n. 26
0
 public static function responseJson()
 {
     Factory::getResponse()->setContentType('application/json');
 }
Esempio n. 27
0
 /**
  * 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();
     }
 }
Esempio n. 28
0
 public function html()
 {
     $this->begin();
     $this->fetchViewPath();
     $this->fetchViewFile();
     $widget = Factory::getWidget('\\Flywheel\\Html\\Widget\\Menu', $this->getRender());
     if (isset($this->lists['items'])) {
         $widget->items = $this->lists['items'];
     }
     $widget->begin();
     $widget->viewFile = $this->viewFile;
     $widget->viewPath = preg_replace('#/+#', '/', $this->viewPath);
     $buffer = $widget->render(array('items' => $widget->items));
     return $buffer;
 }
Esempio n. 29
0
 public function __construct()
 {
     /** @var WebRouter $router */
     $router = Factory::getRouter();
     $this->_baseUrl = $router->getBaseUrl();
     $this->_domain = $router->getDomain();
     $this->_publicPath = $router->getFrontControllerPath();
     //		$this->openGraph = new \Flywheel\Document\Html\OpenGraph();
 }
Esempio n. 30
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)));
 }