Esempio 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');
 }
Esempio n. 2
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();
 }
Esempio n. 3
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;
 }
Esempio n. 4
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');
 }
Esempio n. 5
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;
 }
Esempio n. 6
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);
 }
Esempio n. 7
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;
 }