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; }
/** * 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); }
/** * Get Restriction info * * @param string $type * @param int $id * @return array */ public function getRestriction($type, $id) { $result = NULL; if ($this->hasRestriction($type, $id)) { $result = $this->restrictions[$type][$id]; } else { //get default restriction set if ($type == 'post') { $taxonomies = get_object_taxonomies(get_post($id)); if (is_array($taxonomies) && count($taxonomies)) { $cat_list = wp_get_object_terms($id, $taxonomies, array('fields' => 'ids')); if (is_array($cat_list)) { $cat_list = array_reverse($cat_list); foreach ($cat_list as $cat_id) { if ($r = $this->getRestriction('taxonomy', $cat_id)) { if (isset($r['post_in_category'])) { foreach ($r as $key => $value) { if (strpos($key, '_post_')) { $result[$key] = $value; } } } break; } } } } } elseif ($type == 'taxonomy') { $taxonomy = mvb_Model_Helper::getTaxonomyByTerm($id); foreach (get_ancestors($id, $taxonomy) as $ans) { if ($this->hasRestriction('taxonomy', $ans)) { $result = $this->getRestriction('taxonomy', $ans); break; } } } //update restriction by configPress if (is_null($result)) { $result = $this->populateRestriction($type); } if (!is_null($result)) { $this->addRestriction($type, $id, $result); //cache result } } return $result; }
/** * Get Information about current post or page * * @global type $wp_post_statuses * @global type $wp_post_types * @return type */ protected function get_info() { global $wp_post_statuses, $wp_post_types; $id = intval($_POST['id']); $type = trim($_POST['type']); $role = $_POST['role']; $user = $_POST['user']; if ($user) { $config = mvb_Model_API::getUserAccessConfig($user); } else { $config = mvb_Model_API::getRoleAccessConfig($role); } //render html $tmpl = new mvb_Model_Template(); $templatePath = WPACCESS_TEMPLATE_DIR . 'admin_options.html'; $template = $tmpl->readTemplate($templatePath); $template = $tmpl->retrieveSub('POST_INFORMATION', $template); $result = array('status' => 'error'); switch ($type) { case 'post': //get information about page or post $post = get_post($id); if ($post->ID) { $template = $tmpl->retrieveSub('POST', $template); if ($config->hasRestriction('post', $id)) { $restiction = $config->getRestriction('post', $id); $checked = $restiction['restrict'] ? 'checked' : ''; $checked_front = $restiction['restrict_front'] ? 'checked' : ''; $exclude = $config->hasExclude($id) ? 'checked' : ''; $expire = $restiction['expire'] ? date('m/d/Y', $restiction['expire']) : ''; } $markerArray = array('###post_title###' => mvb_Model_Helper::editPostLink($post), '###disabled_apply_all###' => $user ? 'disabled="disabled"' : '', '###restrict_checked###' => isset($checked) ? $checked : '', '###restrict_front_checked###' => isset($checked_front) ? $checked_front : '', '###restrict_expire###' => isset($expire) ? $expire : '', '###exclude_page_checked###' => isset($exclude) ? $exclude : '', '###post_type###' => ucfirst($post->post_type), '###post_status###' => $wp_post_statuses[$post->post_status]->label, '###post_visibility###' => mvb_Model_Helper::checkVisibility($post), '###ID###' => $post->ID); //check what type of post is it and render exclude if page $render_exclude = FALSE; if (isset($wp_post_types[$post->post_type])) { switch ($wp_post_types[$post->post_type]->capability_type) { case 'page': $render_exclude = TRUE; break; default: break; } } if ($render_exclude) { $excld_tmlp = $tmpl->retrieveSub('EXCLUDE_PAGE', $template); } else { $excld_tmlp = ''; } $template = $tmpl->replaceSub('EXCLUDE_PAGE', $excld_tmlp, $template); $template = $tmpl->updateMarkers($markerArray, $template); $result = array('status' => 'success', 'html' => $tmpl->clearTemplate($template)); } break; case 'taxonomy': //get information about category $taxonomy = mvb_Model_Helper::getTaxonomyByTerm($id); $term = get_term($id, $taxonomy); if ($term->term_id) { $template = $tmpl->retrieveSub('CATEGORY', $template); if ($config->hasRestriction('taxonomy', $id)) { $tax = $config->getRestriction('taxonomy', $id); $checked = $tax['restrict'] ? 'checked' : ''; $checked_front = $tax['restrict_front'] ? 'checked' : ''; $expire = $tax['expire'] ? date('m/d/Y', $tax['expire']) : ''; } $markerArray = array('###name###' => mvb_Model_Helper::editTermLink($term), '###disabled_apply_all###' => $user ? 'disabled="disabled"' : '', '###restrict_checked###' => isset($checked) ? $checked : '', '###restrict_front_checked###' => isset($checked_front) ? $checked_front : '', '###restrict_expire###' => isset($expire) ? $expire : '', '###post_number###' => $term->count, '###ID###' => $term->term_id); $template = $tmpl->updateMarkers($markerArray, $template); $result = array('status' => 'success', 'html' => $tmpl->clearTemplate($template)); } break; default: break; } return $result; }
protected function prepareRestrictions($data) { $prep = array(); if ($data['type'] == 'taxonomy') { $prep['taxonomy'] = mvb_Model_Helper::getTaxonomyByTerm($data['id']); } if (isset($data['data']) && is_array($data['data'])) { foreach ($data['data'] as $input) { if ($data['type'] == 'taxonomy' && strpos($input['name'], '_post_') !== FALSE && !mvb_Model_Helper::isPremium()) { continue; } $prep[$input['name']] = $input['value']; } } return $prep; }