コード例 #1
0
ファイル: Helper.php プロジェクト: KasaiDot/FansubCMS
 /**
  * Get an instance
  * 
  * @return FansubCMS_Cache_Helper
  */
 public static function getInstance()
 {
     if (empty(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #2
0
ファイル: Navigation.php プロジェクト: KasaiDot/FansubCMS
 public function postDispatch(Zend_Controller_Request_Abstract $request)
 {
     $this->layout = Zend_Layout::getMvcInstance();
     $ch = FansubCMS_Cache_Helper::getInstance();
     # add a navigation cache
     if (!$ch->hasCacheTemplate('Navigation_Settings')) {
         $frontend = array('name' => 'Core', 'options' => array('lifetime' => 300, 'automatic_serialization' => true));
         # add a new cache template for this module
         $ch->setCacheTemplate('Navigation_Settings', $frontend);
     }
     $cache = $ch->getCache('Navigation_Settings');
     if (($request->getParam('module') == 'admin' || $request->getParam('controller') == 'admin') && Zend_Auth::getInstance()->hasIdentity()) {
         $config = $cache->load('Navigation_Backend_Settings');
         if (!$config) {
             // add the module and addon admin menus
             $modConf = glob(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'module.ini');
             foreach ($modConf as $nav) {
                 try {
                     $nav = new Zend_Config_Ini($nav, 'adminnav', true);
                     if (isset($adminNav) && $adminNav instanceof Zend_Config_Ini) {
                         $adminNav->merge($nav);
                     } else {
                         $adminNav = $nav;
                     }
                 } catch (Zend_Config_Exception $e) {
                     // do nothing on error, just ignore
                 }
             }
             $config = $adminNav->toArray();
             $cache->save($config);
         }
         $navigation = new Zend_Navigation($config);
     } else {
         $config = $cache->load('Navigation_Frontend_Settings');
         if (!$config) {
             $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/navigation.ini', 'nav');
             $config = $config->toArray();
             $cache->save($config);
         }
         if (Zend_Auth::getInstance()->hasIdentity()) {
             $adminPage = array('administrationLinkAdministration' => array('label' => 'administration', 'module' => 'admin', 'order' => 999999999, 'route' => 'default'));
             $config = array_merge($config, $adminPage);
         }
         $navigation = new Zend_Navigation($config);
     }
     $this->layout->getView()->navigation($navigation);
 }
コード例 #3
0
ファイル: Acl.php プロジェクト: KasaiDot/FansubCMS
 /**
  * init acl
  * @return void
  */
 protected function _initAcl()
 {
     $ch = FansubCMS_Cache_Helper::getInstance();
     # add a navigation cache
     if (!$ch->hasCacheTemplate('Acl_Settings')) {
         $frontend = array('name' => 'Core', 'options' => array('lifetime' => 300, 'automatic_serialization' => true));
         # add a new cache template for this module
         $ch->setCacheTemplate('Acl_Settings', $frontend);
     }
     $cache = $ch->getCache('Acl_Settings');
     $config = $cache->load('Acl');
     if (!$config) {
         $config = array();
         $modules = glob(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'module.ini');
         foreach ($modules as $module) {
             $cleanName = str_replace(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR, '', $module);
             $cleanName = str_replace(DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'module.ini', '', $cleanName);
             try {
                 $ini = new Zend_Config_Ini($module, 'acl');
                 $config[$cleanName] = $ini->toArray();
             } catch (Zend_Config_Exception $e) {
                 // there is just no config or no acl block
             }
         }
         $cache->save($config);
     }
     $acl = new FansubCMS_Acl();
     foreach ($config as $options) {
         $acl->setOptions($options);
     }
     if ($this->_auth->hasIdentity()) {
         $ident = $this->_auth->getIdentity();
         $role = new Zend_Acl_Role('fansubcms_user_custom_role_logged_in_user');
         $inherit = $ident->getRoles();
         $inherit[] = 'fansubcms_custom_role_default';
         // every user is in this role
         foreach ($inherit as $key => $value) {
             if (!$acl->hasRole($value)) {
                 unset($inherit[$key]);
             }
         }
         $acl->addRole($role, $inherit);
     }
     Zend_Registry::set('Zend_Acl', $acl);
     $this->_acl = $acl;
 }
コード例 #4
0
ファイル: Role.php プロジェクト: KasaiDot/FansubCMS
 public static function getRoles()
 {
     if (!isset(self::$_roles)) {
         $ch = FansubCMS_Cache_Helper::getInstance();
         $cache = $ch->getCache('Acl_Settings');
         $config = $cache->load('Acl');
         foreach ($config as $module => $modconf) {
             if (empty($modconf['roles'])) {
                 continue;
             }
             foreach ($modconf['roles'] as $role) {
                 self::$_roles[$role['role']] = $module . '_role_' . $role['role'];
             }
             asort(self::$_roles);
         }
     }
     return self::$_roles;
 }
コード例 #5
0
ファイル: Action.php プロジェクト: KasaiDot/FansubCMS
 /**
  * The class constructor
  * @param Zend_Controller_Request_Abstract $request
  * @param Zend_Controller_Response_Abstract $response
  * @param array $invokeArgs
  */
 public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
 {
     $this->_delegateHelper = new FansubCMS_Helper_Delegate($request->getModuleName());
     $this->_cacheHelper = FansubCMS_Cache_Helper::getInstance();
     parent::__construct($request, $response, $invokeArgs);
     $this->defaultUseRole = 'fansubcms_user_custom_role_logged_in_user';
     $this->request = $request;
     $this->session = Zend_Registry::get('applicationSessionNamespace');
     $this->session->tableActions = array();
     $this->acl = Zend_Registry::get('Zend_Acl');
     $envSettings = Zend_Registry::get('environmentSettings');
     if (!empty($this->session->message)) {
         $this->view->message = $this->session->message;
         $this->view->message_type = $this->session->message_type;
         unset($this->session->message);
         unset($this->session->message_type);
     }
     $this->session->markitup = '';
 }
コード例 #6
0
ファイル: Bootstrap.php プロジェクト: KasaiDot/FansubCMS
 protected function _initI18n()
 {
     $ch = FansubCMS_Cache_Helper::getInstance();
     if (!$ch->hasCacheTemplate('I18n_Settings')) {
         # life time in development 30 seconds in other mode a half hour
         $frontend = array('name' => 'Core', 'options' => array('lifetime' => 1800, 'automatic_serialization' => true));
         # add a new cache template for this module
         $ch->setCacheTemplate('I18n_Settings', $frontend);
     }
     $cache = $ch->getCache('I18n_Settings');
     $trans = $cache->load(ucfirst($this->getModuleName()));
     // there are no translations or cache is invalid - generate cache!
     $locale = $this->envSettings->locale;
     if (!$trans) {
         $module = APPLICATION_PATH . '/modules/' . strtolower($this->getModuleName()) . '/locale/';
         if (file_exists($module . $locale . '.ini')) {
             $trans = new Zend_Config_Ini($module . $locale . '.ini');
         } else {
             $trans = new Zend_Config_Ini($module . 'en.ini');
         }
         $arr = $trans->toArray();
         $ret = array();
         foreach ($arr as $val) {
             $ret = array_merge($ret, $val);
         }
         $trans = $ret;
         $cache->save($trans);
     }
     # get translation object
     $transObj = Zend_Registry::get('Zend_Translate');
     # add the modules translation
     $transObj->addTranslation($trans, $locale);
     # save the transjation to registry
     Zend_Registry::set('Zend_Translate', $transObj);
     return $transObj;
 }