Exemplo n.º 1
0
 /**
  * Set different errorHandler module
  * while Axis_Admin is using
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (!Axis_Area::isBackend()) {
         return;
     }
     Zend_Controller_Front::getInstance()->getPlugin('Zend_Controller_Plugin_ErrorHandler')->setErrorHandlerModule('Axis_Admin');
 }
Exemplo n.º 2
0
 /**
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     if (Axis_Area::isFrontend() && null !== $request->getParam('locale')) {
         $locale = $request->getParam('locale');
     } elseif (isset(Axis::session()->locale)) {
         $locale = Axis::session()->locale;
     } else {
         $locale = Axis_Locale::getDefaultLocale();
     }
     Axis_Locale::setLocale($locale);
 }
Exemplo n.º 3
0
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param string $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $params = parent::match($path, $partial);
     if (!empty($params['controller']) && 'Axis_Admin' !== $params['module']) {
         $params['controller'] = 'admin_' . $params['controller'];
     }
     if ($params) {
         Axis_Area::backend();
     }
     return $params;
 }
Exemplo n.º 4
0
 public function preDispatch()
 {
     $return = Axis_Area::isBackend() && Axis::config('core/backend/ssl') || $this->getActionController() instanceof Axis_Core_Controller_Front_Secure && Axis::config('core/frontend/ssl');
     if (!$return) {
         return;
     }
     $request = $this->getRequest();
     if ($request->isSecure()) {
         return;
     }
     $url = Zend_Controller_Request_Http::SCHEME_HTTPS . "://" . $request->getServer('HTTP_HOST') . $request->getRequestUri();
     $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
     $redirector->setGoToUrl($url);
     $redirector->redirectAndExit();
 }
Exemplo n.º 5
0
 public function __get($key)
 {
     if (Axis_Area::isBackend()) {
         return parent::__get($key);
     }
     $before = $after = '';
     foreach ($this->getBlocks($key) as $blockId => $_config) {
         $blockContent = $this->_getBlockContent($_config);
         if ($_config['sort_order'] < 0) {
             $before .= $blockContent;
         } else {
             $after .= $blockContent;
         }
     }
     return $before . parent::__get($key) . $after;
 }
Exemplo n.º 6
0
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param string $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $path = trim($path, $this->_urlDelimiter);
     $pathParts = explode($this->_urlDelimiter, $path, 2);
     if (!empty($pathParts[0]) && strlen($pathParts[0]) > 1) {
         foreach (self::$_locales as $locale) {
             // preventing duplicate urls:
             // site.com/uk and site.com/uk_UA - only one will work after next check
             if (trim(Axis_Locale::getLanguageUrl($locale), '/') == $pathParts[0]) {
                 self::$_hasLocaleInUrl = true;
                 break;
             }
         }
     }
     if (self::$_hasLocaleInUrl) {
         $path = sizeof($pathParts) > 1 ? $pathParts[1] : '';
         $currentLocale = $pathParts[0];
     } elseif (isset($this->_defaults['locale'])) {
         $currentLocale = $this->_defaults['locale'];
     } else {
         $currentLocale = self::$_defaultLocale;
     }
     self::$_currentLocale = $currentLocale;
     $params = parent::match($path, $partial);
     if ($params) {
         Axis_Area::frontend();
         $params = array_merge($params, array('locale' => $currentLocale));
     }
     return $params;
 }
Exemplo n.º 7
0
 protected function _initArea()
 {
     Axis_Area::installer();
 }
Exemplo n.º 8
0
 protected function _initVars()
 {
     $view = $this->view;
     $request = $this->getRequest();
     if (Axis_Area::isBackend()) {
         $templateId = Axis::config('design/main/adminTemplateId');
     } else {
         $templateId = Axis::config('design/main/frontTemplateId');
     }
     $view->templateName = Axis::single('core/template')->getTemplateNameById($templateId);
     $view->path = Axis::config('system/path');
     $view->area = Axis_Area::getArea();
     list($view->namespace, $view->moduleName) = explode('_', $request->getModuleName(), 2);
     $currentUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getRequestUri();
     $site = Axis::getSite();
     $view->baseUrl = $site ? $site->base : $this->getFrontController()->getBaseUrl();
     $view->secureUrl = $site ? $site->secure : $view->baseUrl;
     $view->resourceUrl = 0 === strpos($currentUrl, $view->secureUrl) ? $view->secureUrl : $view->baseUrl;
     $view->catalogUrl = Axis::config('catalog/main/route');
 }
Exemplo n.º 9
0
 /**
  * Renders a normal menu (called from {@link renderMenu()})
  *
  * @param  Zend_Navigation_Container $container   container to render
  * @param  string                    $ulClass     CSS class for first UL
  * @param  string                    $indent      initial indentation
  * @param  int|null                  $minDepth    minimum depth
  * @param  int|null                  $maxDepth    maximum depth
  * @param  bool                      $onlyActive  render only active branch?
  * @return string
  */
 protected function _renderMenu(Zend_Navigation_Container $container, $ulClass, $indent, $minDepth, $maxDepth, $onlyActive)
 {
     $html = '';
     // find deepest active
     if ($found = $this->findActive($container, $minDepth, $maxDepth)) {
         $foundPage = $found['page'];
         $foundDepth = $found['depth'];
     } else {
         $foundPage = null;
     }
     // create iterator
     $iterator = new RecursiveIteratorIterator($container, RecursiveIteratorIterator::SELF_FIRST);
     if (is_int($maxDepth)) {
         $iterator->setMaxDepth($maxDepth);
     }
     // iterate container
     $prevDepth = -1;
     foreach ($iterator as $page) {
         $depth = $iterator->getDepth();
         $isActive = $page->isActive(true);
         if ($depth < $minDepth || !$this->accept($page) || Axis_Area::isBackend() && !$this->isVisibleAtBackend($page)) {
             // page is below minDepth or not accepted by acl/visibilty
             continue;
         } else {
             if ($onlyActive && !$isActive) {
                 // page is not active itself, but might be in the active branch
                 $accept = false;
                 if ($foundPage) {
                     if ($foundPage->hasPage($page)) {
                         // accept if page is a direct child of the active page
                         $accept = true;
                     } else {
                         if ($foundPage->getParent()->hasPage($page)) {
                             // page is a sibling of the active page...
                             if (!$foundPage->hasPages() || is_int($maxDepth) && $foundDepth + 1 > $maxDepth) {
                                 // accept if active page has no children, or the
                                 // children are too deep to be rendered
                                 $accept = true;
                             }
                         }
                     }
                 }
                 if (!$accept) {
                     continue;
                 }
             }
         }
         // make sure indentation is correct
         $depth -= $minDepth;
         $myIndent = $indent . str_repeat('        ', $depth);
         if ($depth > $prevDepth) {
             // start new ul tag
             if (0 !== $depth) {
                 $ulClass = 'level' . ($depth - 1);
             }
             $html .= $myIndent . '<ul class="' . trim($ulClass) . '">' . self::EOL;
         } else {
             if ($prevDepth > $depth) {
                 // close li/ul tags until we're at current depth
                 for ($i = $prevDepth; $i > $depth; $i--) {
                     $ind = $indent . str_repeat('        ', $i);
                     $html .= $ind . '    </li>' . self::EOL;
                     $html .= $ind . '</ul>' . self::EOL;
                 }
                 // close previous li tag
                 $html .= $myIndent . '    </li>' . self::EOL;
             } else {
                 // close previous li tag
                 $html .= $myIndent . '    </li>' . self::EOL;
             }
         }
         // render li tag and page
         $liClass = 'level' . $depth;
         if ($page->hasPages()) {
             $liClass .= ' parent';
         }
         if ($isActive) {
             $liClass .= ' active';
         }
         $liClass .= ' ' . $page->getClass();
         $html .= $myIndent . '    <li class="' . $liClass . '">' . self::EOL . $myIndent . '        ' . $this->htmlify($page) . self::EOL;
         // store as previous depth for next iteration
         $prevDepth = $depth;
     }
     if ($html) {
         // done iterating container; close open ul/li tags
         for ($i = $prevDepth + 1; $i > 0; $i--) {
             $myIndent = $indent . str_repeat('        ', $i - 1);
             $html .= $myIndent . '    </li>' . self::EOL . $myIndent . '</ul>' . self::EOL;
         }
         $html = rtrim($html, self::EOL);
     }
     return $html;
 }
Exemplo n.º 10
0
 public function preDispatch()
 {
     $request = $this->getRequest();
     if (Axis_Area::isFrontend()) {
         if (!Axis::getCustomerId() && $this->getActionController() instanceof Axis_Account_Controller_Abstract) {
             $request->setModuleName('Axis_Account')->setControllerName('auth')->setActionName('index')->setDispatched(false);
         }
         return;
     }
     if (!Axis_Area::isBackend()) {
         return;
     }
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('admin'));
     if (in_array($request->getControllerName(), array('auth', 'forgot')) && 'Axis_Admin' === $request->getModuleName()) {
         return;
     }
     if (!$auth->hasIdentity()) {
         if ($request->isXmlHttpRequest()) {
             Axis::message()->addError(Axis::translate('admin')->__('Your session has been expired. Please relogin'));
             $jsonHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
             $jsonHelper->sendFailure();
             return;
         }
         $request->setModuleName('Axis_Admin')->setControllerName('auth')->setActionName('index')->setDispatched(false);
         return;
     }
     $user = Axis::single('admin/user')->find($auth->getIdentity())->current();
     if (!$user) {
         $request->setModuleName('Axis_Admin')->setControllerName('auth')->setActionName('logout')->setDispatched(false);
         return;
     }
     $acl = new Zend_Acl();
     // add resources
     $resources = Axis::model('admin/acl_resource')->toFlatTree();
     foreach ($resources as $resource) {
         $parent = $resource['parent'];
         try {
             $acl->addResource($resource['id'], $parent);
         } catch (Zend_Acl_Exception $e) {
             Axis::message()->addError($e->getMessage());
         }
     }
     //add role(s)
     $role = (string) $user->role_id;
     $acl->addRole($role);
     //add permission
     $rowset = Axis::single('admin/acl_rule')->select('*')->where('role_id = ?', $role)->fetchRowset();
     foreach ($rowset as $row) {
         if (!$acl->has($row->resource_id)) {
             // $row->delete(); // remove invalid rule
             continue;
         }
         $action = 'deny';
         if ('allow' === $row->permission) {
             $action = 'allow';
         }
         try {
             $acl->{$action}($row->role_id, $row->resource_id);
         } catch (Zend_Acl_Exception $e) {
             Axis::message()->addError($e->getMessage());
         }
     }
     Zend_View_Helper_Navigation_HelperAbstract::setDefaultAcl($acl);
     Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole($role);
     if (in_array($request->getControllerName(), array('error')) && 'Axis_Admin' === $request->getModuleName()) {
         return;
     }
     //get current resource by request
     $request = $this->getRequest();
     $inflector = new Zend_Filter_Inflector();
     $resource = $inflector->addRules(array(':module' => array('Word_CamelCaseToDash', new Zend_Filter_Word_UnderscoreToSeparator('/'), 'StringToLower'), ':controller' => array('Word_CamelCaseToDash', 'StringToLower', new Zend_Filter_PregReplace('/admin_/', '')), ':action' => array('Word_CamelCaseToDash', 'StringToLower')))->setTarget('admin/:module/:controller/:action')->filter($request->getParams());
     if (!$acl->has($resource) || $acl->isAllowed($role, $resource)) {
         return;
     }
     if ($request->isXmlHttpRequest()) {
         Axis::message()->addError(Axis::translate('admin')->__('You have no permission for this operation'));
         $jsonHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
         $jsonHelper->sendFailure();
         return;
     }
     $request->setModuleName('Axis_Admin')->setControllerName('error')->setActionName('access-denied')->setDispatched(false);
 }
Exemplo n.º 11
0
 protected function _initArea()
 {
     Axis_Area::frontend();
 }
Exemplo n.º 12
0
 /**
  * postDispatch() plugin hook -- render layout
  *
  * @param  Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function postDispatch(Zend_Controller_Request_Abstract $request)
 {
     $layout = $this->getLayout();
     $helper = $this->getLayoutActionHelper();
     // Return early if forward detected
     if (!$request->isDispatched() || $this->getResponse()->isRedirect() || $layout->getMvcSuccessfulActionOnly() && (!empty($helper) && !$helper->isActionControllerSuccessful())) {
         $layout->setLayout(null);
         return;
     }
     // Return early if layout has been disabled
     if (!$layout->isEnabled()) {
         return;
     }
     // two logic mix
     $layoutName = $layout->getLayout();
     if (Axis_Area::isFrontend()) {
         $this->_initPages();
         if (empty($layoutName)) {
             $layoutName = $this->_getLayoutName();
         }
         $this->_initBlockAssigns();
     } elseif (empty($layoutName)) {
         $layoutName = 'layout';
     }
     $layout->setLayout($layoutName, false);
     $response = $this->getResponse();
     $content = $response->getBody(true);
     $contentKey = $layout->getContentKey();
     if (isset($content['default'])) {
         $content[$contentKey] = $content['default'];
     }
     if ('default' != $contentKey) {
         unset($content['default']);
     }
     $layout->assign($content);
     $fullContent = null;
     $obStartLevel = ob_get_level();
     try {
         $fullContent = $layout->render();
         $response->setBody($fullContent);
     } catch (Exception $e) {
         while (ob_get_level() > $obStartLevel) {
             $fullContent .= ob_get_clean();
         }
         $request->setParam('layoutFullContent', $fullContent);
         $request->setParam('layoutContent', $layout->content);
         $response->setBody(null);
         throw $e;
     }
 }
Exemplo n.º 13
0
 public function getKeywords()
 {
     if (!Axis_Area::isFrontend()) {
         return array();
     }
     $path = urldecode($this->getRequest()->getPathInfo());
     $keywords = explode('/', trim($path, '/'));
     $route = Zend_Controller_Front::getInstance()->getRouter()->getCurrentRoute();
     if ($route->hasLocaleInUrl()) {
         array_shift($keywords);
         //remove locale from array
     }
     array_shift($keywords);
     //remove root catalog from array
     return $keywords;
 }
Exemplo n.º 14
0
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param string $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $path = trim($path, $this->_urlDelimiter);
     $pathParts = explode($this->_urlDelimiter, $path, 2);
     if (in_array($pathParts[0], self::$_locales)) {
         $path = sizeof($pathParts) > 1 ? $pathParts[1] : '';
         $currentLocale = $pathParts[0];
         self::$_hasLocaleInUrl = true;
     } else {
         if (isset($this->_defaults['locale'])) {
             $currentLocale = $this->_defaults['locale'];
         } else {
             $currentLocale = self::$_defaultLocale;
         }
     }
     self::$_currentLocale = $currentLocale;
     $params = parent::match($path, $partial);
     if ($params) {
         Axis_Area::frontend();
         $params = array_merge($params, array('locale' => $currentLocale));
     }
     return $params;
 }
Exemplo n.º 15
0
 /**
  * Retrieve languageId from session;
  *
  * @static
  * @return int
  */
 public static function getLanguageId()
 {
     if (!isset(Axis::session()->language)) {
         if (Axis_Area::isBackend()) {
             Axis::session()->language = Axis::config('locale/main/language_admin');
         } else {
             Axis::session()->language = Axis::config('locale/main/language_front');
         }
     }
     return Axis::session()->language;
 }
Exemplo n.º 16
0
 /**
  * Translates given text
  *
  * @param array $args
  * @return string
  */
 public function translate(array $args)
 {
     $text = array_shift($args);
     if (!Axis_Area::isInstaller() && Axis::config('core/translation/autodetect') && !$this->getAdapter()->isTranslated($text)) {
         $this->writeTranslationToFile($text, $this->_module);
     }
     $translated = $this->getAdapter()->translate($text);
     if (!count($args)) {
         return $translated;
     }
     return @vsprintf($translated, $args);
 }
Exemplo n.º 17
0
 /**
  *
  * @return void
  */
 public static function installer()
 {
     self::$_area = self::INSTALL;
 }