Example #1
0
 /**
  *
  * @global array $submenu
  * @param string $tmpl
  * @param mvb_Model_Manager $parent
  * @return string
  */
 public static function render($tmpl, $parent)
 {
     global $submenu;
     $sorted_menu = $parent->getRoleMenu();
     $item_tmpl = mvb_Model_Template::retrieveSub('MAIN_MENU_ITEM', $tmpl);
     $sublist_tmpl = mvb_Model_Template::retrieveSub('MAIN_MENU_SUBLIST', $item_tmpl);
     $subitem_tmpl = mvb_Model_Template::retrieveSub('MAIN_MENU_SUBITEM', $sublist_tmpl);
     $list = '';
     foreach ($sorted_menu as $menu) {
         if (self::isSeperator($menu)) {
             continue;
         }
         //render submenu
         $sub_list = '';
         if (isset($submenu[$menu[2]]) && is_array($submenu[$menu[2]])) {
             foreach ($submenu[$menu[2]] as $sub_menu) {
                 $markers = array('###submenu_name###' => utf8_encode(mvb_Model_Helper::removeHTML($sub_menu[0])), '###value###' => $sub_menu[2], '###checked###' => $parent->getConfig()->hasSubMenu($menu[2], $sub_menu[2]) ? 'checked' : '');
                 $sub_list .= mvb_Model_Template::updateMarkers($markers, $subitem_tmpl);
             }
             $sub_list = mvb_Model_Template::replaceSub('MAIN_MENU_SUBITEM', $sub_list, $sublist_tmpl);
         }
         $temp = mvb_Model_Template::replaceSub('MAIN_MENU_SUBLIST', $sub_list, $item_tmpl);
         $whole = $parent->getConfig()->getMenu($menu[2]);
         $markers = array('###name###' => utf8_encode(mvb_Model_Helper::removeHTML($menu[0])), '###id###' => $menu[5], '###menu###' => $menu[2], '###whole_checked###' => isset($whole['whole']) ? 'checked' : '');
         $list .= mvb_Model_Template::updateMarkers($markers, $temp);
     }
     return mvb_Model_Template::replaceSub('MAIN_MENU_ITEM', $list, $tmpl);
 }
Example #2
0
 public static function renderInfo($id, $type, $parent, $tmpl)
 {
     global $wp_post_statuses, $wp_post_types;
     switch ($type) {
         case 'post':
             //get information about page or post
             $post = get_post($id);
             if ($post->ID) {
                 $tmpl = mvb_Model_Template::retrieveSub('POST', $tmpl);
                 $tmpl = phpQuery::newDocument($tmpl);
                 $data = $parent->getConfig()->getRestriction('post', $id);
                 foreach ($data as $key => $value) {
                     $tmpl['#' . $key]->attr('checked', 'checked');
                 }
                 if ($parent->getCurrentUser()) {
                     $tmpl['.save-postinfo-all']->attr('disabled', 'disabled');
                 }
                 $tmpl['.category-title']->html(mvb_Model_Helper::editPostLink($post));
                 //check what type of post is it and render exclude if page
                 if (isset($wp_post_types[$post->post_type])) {
                     if ($wp_post_types[$post->post_type]->capability_type != 'page') {
                         $tmpl['#exclude']->remove();
                     }
                 }
                 $tmpl = $tmpl->htmlOuter();
             }
             break;
         case 'taxonomy':
             //get information about category
             $taxonomy = mvb_Model_Helper::getTaxonomyByTerm($id);
             $term = get_term($id, $taxonomy);
             if ($term->term_id) {
                 $tmpl = mvb_Model_Template::retrieveSub('CATEGORY', $tmpl);
                 $tmpl = phpQuery::newDocument($tmpl);
                 $data = $parent->getConfig()->getRestriction('taxonomy', $id);
                 foreach ($data as $key => $value) {
                     $tmpl['#' . $key]->attr('checked', 'checked');
                 }
                 if ($parent->getCurrentUser()) {
                     $tmpl['.save-postinfo-all']->attr('disabled', 'disabled');
                 }
                 $tmpl['.category-title']->html(mvb_Model_Helper::editTermLink($term));
                 $tmpl['.subposts']->html(sprintf(mvb_Model_Label::get('LABEL_178'), $term->name));
                 if (mvb_Model_Helper::isPremium()) {
                     $tmpl['.premium']->removeClass('premium');
                     $tmpl['#premium-ind']->html(' ');
                 }
                 $tmpl = $tmpl->htmlOuter();
             }
             break;
         default:
             $tmpl = '';
             break;
     }
     $tmpl = mvb_Model_Label::clearLabels($tmpl);
     $result = array('status' => 'success', 'html' => mvb_Model_Template::clearTemplate($tmpl));
     return $result;
 }
/**
 * Merget to configs
 * 
 * @param object $config
 * @param object $m_config 
 */
function mvb_merge_configs($config, $m_config)
{
    //check which config has highest user level and overwrite lower
    if (mvb_Model_Helper::isLowerLevel($config, $m_config)) {
        $config->setMenu($m_config->getMenu());
        $config->setMetaboxes($m_config->getMetaboxes());
        if (count($m_config->getMenuOrder())) {
            $config->setMenuOrder($m_config->getMenuOrder());
        }
    }
    $caps = array_merge($config->getCapabilities(), $m_config->getCapabilities());
    $config->setCapabilities($caps);
    $rests = mvb_Model_Helper::array_merge_recursive($m_config->getRestrictions(), $config->getRestrictions());
    $config->setRestrictions($rests, FALSE);
    $excludes = mvb_Model_Helper::array_merge_recursive($config->getExcludes(), $m_config->getExcludes());
    $config->setExcludes($excludes);
    return $config;
}
Example #4
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;
 }
 /**
  * 
  */
 public function render_optionlist()
 {
     $role = mvb_Model_Helper::getParam('role', 'POST');
     $user = mvb_Model_Helper::getParam('user', 'POST');
     $m = new mvb_Model_Manager($this, $role, $user);
     $or_roles = mvb_Model_API::getBlogOption(WPACCESS_PREFIX . 'original_user_roles');
     $content = $m->getMainOptionsList();
     $content = $m->templObj->clearTemplate($content);
     $result = array('html' => apply_filters(WPACCESS_PREFIX . 'option_page', $content), 'restorable' => isset($or_roles[$role]) ? TRUE : FALSE);
     die(json_encode($result));
 }
Example #6
0
 function do_save()
 {
     if (isset($_POST['submited'])) {
         $params = isset($_POST['wpaccess']) ? $_POST['wpaccess'] : array();
         $error_message = NULL;
         if (mvb_Model_API::isNetworkPanel() && mvb_Model_ConfigPress::getOption('aam.multisite.apply_all') == 'true') {
             $limit = apply_filters(WPACCESS_PREFIX . 'msar_restrict_limit', WPACCESS_APPLY_LIMIT);
             foreach (mvb_Model_Helper::getSiteList() as $i => $site) {
                 if ($site->blog_id == $_GET['site']) {
                     continue;
                 } elseif ($i + 1 >= WPACCESS_APPLY_LIMIT && $limit != -1) {
                     $error_message = mvb_Model_Label::get('LABEL_148');
                     break;
                 }
                 mvb_Model_API::setCurrentBlog($site->blog_id);
                 $this->initConfig();
                 $this->config->setMenu(isset($params['menu']) ? $params['menu'] : array());
                 $this->config->setMetaboxes(isset($params['metabox']) ? $params['metabox'] : array());
                 $this->config->setCapabilities(isset($params['advance']) ? $params['advance'] : array());
                 $this->config->saveConfig();
             }
         }
         //overwrite current blog
         //TODO - maybe there is better way
         if (isset($_GET['site'])) {
             mvb_Model_API::setCurrentBlog($_GET['site']);
         }
         $this->config->setMenu(isset($params['menu']) ? $params['menu'] : array());
         $this->config->setMetaboxes(isset($params['metabox']) ? $params['metabox'] : array());
         $this->config->setCapabilities(isset($params['advance']) ? $params['advance'] : array());
         $this->config->saveConfig();
         mvb_Model_ConfigPress::saveConfig(stripslashes($params['config_press']));
     } else {
         $error_message = FALSE;
     }
     return $error_message;
 }
Example #7
0
 /**
  *
  */
 public function render_optionlist()
 {
     $role = mvb_Model_Helper::getParam('role', 'POST');
     $user = mvb_Model_Helper::getParam('user', 'POST');
     $m = new mvb_Model_ManagerAjax($this, $role, $user);
     die(json_encode($m->manage_ajax('option_list')));
 }
Example #8
0
 public static function renderUserSelector($tmpl, $parent)
 {
     $tmpl = mvb_Model_Template::retrieveSub('USER_LIST', $tmpl);
     $list = '';
     $users = mvb_Model_Helper::getUserList($parent->getCurrentRole());
     $default = new stdClass();
     $default->ID = 0;
     $default->user_login = mvb_Model_Label::get('LABEL_120');
     array_unshift($users, $default);
     foreach ($users as $user) {
         $selected = $parent->getCurrentUser() == $user->ID ? 'selected' : '';
         $markers = array('###value###' => $user->ID, '###title###' => stripcslashes($user->user_login) . ' ', '###selected###' => $selected);
         $list .= mvb_Model_Template::updateMarkers($markers, $tmpl);
     }
     return $list;
 }
Example #9
0
 protected function populateRestriction($type)
 {
     $result = array();
     if (mvb_Model_Helper::isPremium()) {
         $result = mvb_Model_Pro::populateRestriction($type);
     }
     return $result;
 }
Example #10
0
 /**
  * Main function for checking if user has access to a page
  *
  * Check if current user has access to requested page. If no, print an
  * notification
  *
  * @access public
  * @global object $wp_query
  * @global object $post
  * @return bool
  */
 public function checkAccess()
 {
     global $wp_query, $post;
     //skip Super Admin Role
     if (mvb_Model_API::isSuperAdmin()) {
         return TRUE;
     }
     if (is_admin()) {
         //check if user has access to requested Menu
         $uri = $_SERVER['REQUEST_URI'];
         if (!$this->getMenuFilter()->checkAccess($uri)) {
             mvb_Model_Helper::doRedirect();
         }
         //check if current user has access to requested Post
         $post_id = mvb_Model_Helper::getCurrentPostID();
         if ($post_id) {
             if (!$this->checkPostAccess($post_id, WPACCESS_ACCESS_EDIT)) {
                 mvb_Model_Helper::doRedirect();
             }
         } elseif (isset($_GET['taxonomy']) && isset($_GET['tag_ID'])) {
             // TODO - Find better way
             if (!$this->checkTaxonomyAccess($_GET['tag_ID'], WPACCESS_ACCESS_EDIT)) {
                 mvb_Model_Helper::doRedirect();
             }
         }
     } else {
         if (is_category()) {
             $cat_obj = $wp_query->get_queried_object();
             if (!$this->checkTaxonomyAccess($cat_obj->term_id, WPACCESS_ACCESS_BROWSE)) {
                 mvb_Model_Helper::doRedirect();
             }
         } else {
             if (!$wp_query->is_home() && isset($post->ID)) {
                 if (!$this->checkPostAccess($post->ID, WPACCESS_ACCESS_READ)) {
                     mvb_Model_Helper::doRedirect();
                 }
             }
         }
     }
 }
 /**
  *
  * @global type $submenu
  * @param type $template
  * @return type 
  */
 public function renderMainMenuOptions($template)
 {
     global $submenu;
     $s_menu = $this->getRoleMenu();
     /*
      * First Tab - Main Menu
      */
     $listTemplate = $this->templObj->retrieveSub('MAIN_MENU_LIST', $template);
     $itemTemplate = $this->templObj->retrieveSub('MAIN_MENU_ITEM', $listTemplate);
     $sublistTemplate = $this->templObj->retrieveSub('MAIN_MENU_SUBLIST', $itemTemplate);
     $subitemTemplate = $this->templObj->retrieveSub('MAIN_MENU_SUBITEM', $sublistTemplate);
     $list = '';
     if (is_array($s_menu)) {
         foreach ($s_menu as $menuItem) {
             if (!$menuItem[0]) {
                 //seperator
                 continue;
             }
             //render submenu
             $subList = '';
             if (isset($submenu[$menuItem[2]]) && is_array($submenu[$menuItem[2]])) {
                 foreach ($submenu[$menuItem[2]] as $submenuItem) {
                     $checked = $this->checkChecked('submenu', array($menuItem[2], $submenuItem[2]));
                     $markers = array('###submenu_name###' => $this->removeHTML($submenuItem[0]), '###value###' => $submenuItem[2], '###checked###' => $checked);
                     $subList .= $this->templObj->updateMarkers($markers, $subitemTemplate);
                 }
                 $subList = $this->templObj->replaceSub('MAIN_MENU_SUBITEM', $subList, $sublistTemplate);
             }
             $tTempl = $this->templObj->replaceSub('MAIN_MENU_SUBLIST', $subList, $itemTemplate);
             $markers = array('###name###' => $this->removeHTML($menuItem[0]), '###id###' => $menuItem[5], '###menu###' => $menuItem[2], '###whole_checked###' => $this->checkChecked('menu', array($menuItem[2])));
             $list .= $this->templObj->updateMarkers($markers, $tTempl);
         }
     }
     $listTemplate = $this->templObj->replaceSub('MAIN_MENU_ITEM', $list, $listTemplate);
     $template = $this->templObj->replaceSub('MAIN_MENU_LIST', $listTemplate, $template);
     /*
      * Second Tab - Metaboxes
      */
     $listTemplate = $this->renderMetaboxList($template);
     $template = $this->templObj->replaceSub('METABOX_LIST', $listTemplate, $template);
     /*
      * Third Tab - Advance Settings
      */
     $capList = mvb_Model_API::getCurrentUser()->getAllCaps();
     //TODO ?
     ksort($capList);
     $listTemplate = $this->templObj->retrieveSub('CAPABILITY_LIST', $template);
     $itemTemplate = $this->templObj->retrieveSub('CAPABILITY_ITEM', $listTemplate);
     $list = '';
     if (is_array($capList) && count($capList)) {
         foreach ($capList as $cap => $dump) {
             $desc = str_replace("\n", '<br/>', mvb_Model_Label::get($cap));
             $markers = array('###title###' => $cap, '###description###' => $desc, '###checked###' => $this->checkChecked('capability', array($cap)), '###cap_name###' => mvb_Model_Helper::getCapabilityHumanTitle($cap));
             $titem = $this->templObj->updateMarkers($markers, $itemTemplate);
             if (!in_array($cap, $this->custom_caps)) {
                 $titem = $this->templObj->replaceSub('CAPABILITY_DELETE', '', $titem);
             } else {
                 $titem = $this->templObj->replaceSub('CAPABILITY_DELETE', $this->templObj->retrieveSub('CAPABILITY_DELETE', $titem), $titem);
             }
             $list .= $titem;
         }
         $template = $this->templObj->replaceSub('CAPABILITY_LIST_EMPTY', '', $template);
     } else {
         $empty = $this->templObj->retrieveSub('CAPABILITY_LIST_EMPTY', $template);
         $template = $this->templObj->replaceSub('CAPABILITY_LIST_EMPTY', $empty, $template);
     }
     $listTemplate = $this->templObj->replaceSub('CAPABILITY_ITEM', $list, $listTemplate);
     $template = $this->templObj->replaceSub('CAPABILITY_LIST', $listTemplate, $template);
     //Posts & Pages
     $template = $this->templObj->replaceSub('POST_INFORMATION', '', $template);
     $template = $this->templObj->updateMarkers(array('###access_config###' => stripslashes(mvb_Model_API::getBlogOption(WPACCESS_PREFIX . 'access_config', ''))), $template);
     return $template;
 }
 /**
  * Initialize hierarhical restriction tree
  *  
  */
 public function initRestrictionTree()
 {
     $rests = $this->getRestrictions();
     if (isset($rests['categories']) && is_array($rests['categories'])) {
         foreach ($rests['categories'] as $id => $restrict) {
             $r = $this->checkExpiration($restrict);
             if ($r) {
                 $rests['categories'][$id]['restrict'] = $r & self::RESTRICT_BACK ? 1 : 0;
                 $rests['categories'][$id]['restrict_front'] = $r & self::RESTRICT_FRONT ? 1 : 0;
                 //get list of all subcategories
                 $taxonomy = mvb_Model_Helper::getTaxonomyByTerm($id);
                 $rests['categories'][$id]['taxonomy'] = $taxonomy;
                 $cat_list = get_term_children($id, $taxonomy);
                 if (is_array($cat_list)) {
                     foreach ($cat_list as $cid) {
                         $rests['categories'][$cid] = $rests['categories'][$id];
                     }
                 }
             } else {
                 unset($rests['categories'][$id]);
             }
         }
     }
     //prepare list of posts and pages
     if (isset($rests['posts']) && is_array($rests['posts'])) {
         foreach ($rests['posts'] as $id => $restrict) {
             //now check combination of options
             $r = $this->checkExpiration($restrict);
             if ($r) {
                 $rests['posts'][$id]['restrict'] = $r & self::RESTRICT_BACK ? 1 : 0;
                 $rests['posts'][$id]['restrict_front'] = $r & self::RESTRICT_FRONT ? 1 : 0;
             } else {
                 if ($rests['posts'][$id]['exclude_page']) {
                     $rests['posts'][$id] = array('exclude_page' => 1);
                 } else {
                     unset($rests['posts'][$id]);
                 }
             }
         }
     }
     $this->setRestrictions($rests);
 }
 protected function check_addons()
 {
     //grab list of features
     $url = 'http://whimba.org/features.php';
     //second paramter is FALSE, which means that I'm not sending any
     //cookies to my website
     $response = mvb_Model_Helper::cURL($url, FALSE, TRUE);
     if (isset($response['content'])) {
         $data = json_decode($response['content']);
     }
     $available = FALSE;
     if (is_array($data->features) && count($data->features)) {
         $plugins = get_plugins();
         foreach ($data->features as $feature) {
             if (!isset($plugins[$feature])) {
                 $available = TRUE;
                 break;
             }
         }
     }
     $result = array('status' => 'success', 'available' => $available);
     return $result;
 }
Example #14
0
 private static function isPremium($capability)
 {
     return in_array($capability, self::$premium_caps) && !mvb_Model_Helper::isPremium() ? 'premium' : '';
 }
Example #15
0
 public static function renderMetabox($tmpl, $list, $type)
 {
     $content = '';
     foreach ($list as $position => $set) {
         foreach ($set as $priority => $metaboxes) {
             if (is_array($metaboxes)) {
                 foreach ($metaboxes as $id => $data) {
                     if (is_array($data)) {
                         $data['title'] = mvb_Model_Helper::removeHTML($data['title']);
                         $markers = array('###title###' => utf8_encode(mvb_Model_Helper::removeHTML($data['title'])), '###short_id###' => mvb_Model_Helper::cutStr($data['id'], 25), '###id###' => $data['id'], '###priority###' => $priority, '###internal_id###' => $type . '-' . $id, '###position###' => $position, '###checked###' => self::$parent->getConfig()->hasMetabox($type . '-' . $id) ? 'checked' : '');
                         $content .= mvb_Model_Template::updateMarkers($markers, $tmpl);
                     }
                 }
             }
         }
     }
     return $content;
 }
 /**
  * Returst Edit Term Link
  * 
  * @param object $term
  * @return string 
  */
 public static function editTermLink($term)
 {
     $st = mvb_Model_Helper::shortTitle($term->name);
     $link = '<a href="' . get_edit_term_link($term->term_id, 'category') . '" target="_blank" title="' . esc_attr($term->name) . '">' . $st . '</a>';
     return $link;
 }
Example #17
0
 /**
  * Save Restriction Information
  *
  * @access protected
  * @return array
  */
 protected function save_info()
 {
     $role = mvb_Model_Helper::getParam('role', 'POST');
     $user = mvb_Model_Helper::getParam('user', 'POST');
     $apply_all = mvb_Model_Helper::getParam('apply', 'POST');
     $apply_all_cb = mvb_Model_Helper::getParam('apply_all_cb', 'POST');
     $info = mvb_Model_Helper::getParam('info', 'POST');
     mvb_Model_API::updateBlogOption(WPACCESS_PREFIX . 'hide_apply_all', $apply_all_cb);
     if ($user) {
         $config = mvb_Model_API::getUserAccessConfig($user);
         $result = $this->updateRestriction($config, $info);
     } else {
         if ($apply_all) {
             foreach (mvb_Model_API::getRoleList() as $role => $dummy) {
                 $config = mvb_Model_API::getRoleAccessConfig($role);
                 $result = $this->updateRestriction($config, $info);
                 if ($result['status'] == 'error') {
                     break;
                 }
             }
         } else {
             $config = mvb_Model_API::getRoleAccessConfig($role);
             $result = $this->updateRestriction($config, $info);
         }
     }
     return $result;
 }