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;
     }
 }
 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;
         }
     }
 }
예제 #3
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;
 }
예제 #4
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);
 }
예제 #5
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();
 }
예제 #6
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;
 }
예제 #7
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;
 }
예제 #8
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')));
     }
 }
예제 #9
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;
 }
예제 #10
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);
 }
예제 #11
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();
 }
예제 #12
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)));
 }
예제 #13
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;
 }
예제 #14
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();
     }
 }
예제 #15
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']);
     }
 }
예제 #16
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;
 }