Esempio n. 1
0
 public function renderInfo()
 {
     $id = mvb_Model_Helper::getParam('id', 'POST');
     $type = mvb_Model_Helper::getParam('type', 'POST');
     if (mvb_Model_Helper::getParam('restore', 'POST')) {
         $user = mvb_Model_Helper::getParam('user', 'POST');
         $role = mvb_Model_Helper::getParam('role', 'POST');
         if ($user) {
             $config = mvb_Model_API::getUserAccessConfig($user);
         } else {
             $config = mvb_Model_API::getRoleAccessConfig($role);
         }
         $config->deleteRestriction($type, $id);
         $config->saveConfig();
     }
     $tmpl = mvb_Model_Template::retrieveSub('POST_INFORMATION', $this->template);
     $result = mvb_Model_Manager_Restriction::renderInfo($id, $type, $this, $tmpl);
     return $result;
 }
Esempio n. 2
0
 protected function initConfig()
 {
     if ($this->current_user) {
         $this->config = mvb_Model_API::getUserAccessConfig($this->current_user);
     } else {
         $this->config = mvb_Model_API::getRoleAccessConfig($this->current_role);
     }
 }
 /**
  * Initiate an object and other parameters
  * 
  * @param string $currentRole Current role to work with
  * @param string $currentUser Current user to work with
  * @param object Main Object
  */
 function __construct($pObj, $currentRole = FALSE, $currentUser = FALSE)
 {
     $this->pObj = $pObj;
     $this->templObj = new mvb_Model_Template();
     $templatePath = WPACCESS_TEMPLATE_DIR . 'admin_options.html';
     $this->template = $this->templObj->readTemplate($templatePath);
     $this->roles = mvb_Model_API::getRoleList();
     $this->custom_caps = mvb_Model_API::getBlogOption(WPACCESS_PREFIX . 'custom_caps', array());
     $this->setCurrentRole($currentRole);
     $this->setCurrentUser($currentUser);
     if ($this->currentUser) {
         $this->config = mvb_Model_API::getUserAccessConfig($this->currentUser);
     } else {
         $this->config = mvb_Model_API::getRoleAccessConfig($this->currentRole);
     }
     //get cache. Compatible with version previouse versions
     $cache = mvb_Model_API::getBlogOption(WPACCESS_PREFIX . 'cache', NULL);
     if (is_array($cache)) {
         //yeap this is new version
         $this->cache = $cache;
     } else {
         //TODO - will be deprecated
         $cache = mvb_Model_API::getBlogOption(WPACCESS_PREFIX . 'options', array());
         $this->cache = isset($cache['settings']) ? $cache['settings'] : array();
         mvb_Model_API::updateBlogOption(WPACCESS_PREFIX . 'cache', $this->cache);
     }
     $this->userSummary = count_users();
 }
Esempio n. 4
0
 /**
  * Get User Access Config Object
  *
  * @param int $user_id
  * @param array $force_roles
  * @return object
  */
 public static function getUserAccessConfig($user_id, $force_roles = FALSE)
 {
     if ($force_roles || !($config = mvb_Model_Cache::getCacheData('user', $user_id))) {
         $config = new mvb_Model_UserConfig($user_id);
         if (!$config->getID()) {
             //user is logged in
             $config = new mvb_Model_RoleConfig('_visitor');
         } else {
             if (is_array($force_roles)) {
                 $role_list = $force_roles;
             } else {
                 $role_list = $config->getUser()->getRoles();
             }
             //get first role and use as base
             //TODO - probably implement multirole support
             $r_config = mvb_Model_API::getRoleAccessConfig(array_shift($role_list));
             if (!count($config->getMenu())) {
                 $config->setMenu($r_config->getMenu());
             }
             if (!count($config->getMetaboxes())) {
                 $config->setMetaboxes($r_config->getMetaboxes());
             }
             if (!count($config->getMenuOrder())) {
                 $config->setMenuOrder($r_config->getMenuOrder());
             }
             if (!count($config->getCapabilities())) {
                 $config->setCapabilities($r_config->getCapabilities());
             }
             //merge restrictions
             $role_restrs = $r_config->getRestrictions();
             if (count($role_restrs)) {
                 if (isset($role_restrs['post'])) {
                     foreach ($role_restrs['post'] as $id => $data) {
                         if (!$config->hasRestriction('post', $id)) {
                             $config->addRestriction('post', $id, $data);
                         }
                     }
                 }
                 if (isset($role_restrs['taxonomy'])) {
                     foreach ($role_restrs['taxonomy'] as $id => $data) {
                         if (!$config->hasRestriction('taxonomy', $id)) {
                             $config->addRestriction('taxonomy', $id, $data);
                         }
                     }
                 }
             }
             if (!$force_roles) {
                 mvb_Model_Cache::saveCacheData('user', $user_id, $config);
             }
         }
     }
     return $config;
 }
 /**
  * Save menu order
  * 
  * @return array
  */
 protected function save_order()
 {
     $apply_all = $_POST['apply_all'];
     $role = $_POST['role'];
     $user = $_POST['user'];
     if ($user) {
         $config = mvb_Model_API::getUserAccessConfig($user);
         $config->setMenuOrder($_POST['menu']);
         $config->saveConfig();
     } else {
         if ($apply_all) {
             foreach (mvb_Model_API::getRoleList() as $role => $dummy) {
                 $config = mvb_Model_API::getRoleAccessConfig($role);
                 $config->setMenuOrder($_POST['menu']);
                 $config->saveConfig();
             }
         } else {
             $config = mvb_Model_API::getRoleAccessConfig($role);
             $config->setMenuOrder($_POST['menu']);
             $config->saveConfig();
         }
     }
     mvb_Model_Cache::clearCache();
     return array('status' => 'success');
 }
 /**
  * Get User Access Config Object
  * 
  * @param int $user_id
  * @param array $force_roles
  * @return object
  */
 public static function getUserAccessConfig($user_id, $force_roles = FALSE)
 {
     $config = new mvb_Model_UserConfig($user_id);
     if (!$config->getID()) {
         //user is logged in
         $config = new mvb_Model_RoleConfig('_visitor');
     } else {
         if (is_array($force_roles)) {
             $role_list = $force_roles;
         } else {
             $role_list = $config->getUser()->getRoles();
         }
         $m_config = mvb_Model_API::getRoleAccessConfig(array_shift($role_list));
         foreach ($role_list as $role) {
             mvb_merge_configs($m_config, mvb_Model_API::getRoleAccessConfig($role));
         }
         mvb_merge_configs($config, $m_config);
     }
     return $config;
 }