/**
  * Create module Backbone template
  * for administration
  *
  * @since  2.0
  * @return void
  */
 public function template_condition()
 {
     if (WPCACore::post_types()->has(get_post_type())) {
         echo WPCAView::make("module/condition_template", array('id' => $this->id, 'placeholder' => $this->placeholder, 'default' => $this->default_value))->render();
     }
 }
 /**
  * Get filtered condition groups
  *
  * @since  2.0
  * @return array
  */
 public static function get_conditions()
 {
     global $wpdb, $wp_query, $post;
     if (!$wp_query->query && !$post || is_admin() || post_password_required()) {
         return array();
     }
     // Return cache if present
     if (self::$condition_cache) {
         return self::$condition_cache;
     }
     $context_data['WHERE'] = $context_data['JOIN'] = $context_data['EXCLUDE'] = array();
     $context_data = apply_filters('wpca/modules/context-data', $context_data);
     // Check if there are any rules for this type of content
     if (empty($context_data['WHERE'])) {
         return array();
     }
     $context_data['WHERE'][] = "posts.post_type = '" . self::TYPE_CONDITION_GROUP . "'";
     $post_status = array(self::STATUS_PUBLISHED, self::STATUS_NEGATED);
     $context_data['WHERE'][] = "posts.post_status IN ('" . implode("','", $post_status) . "')";
     //Syntax changed in MySQL 5.5 and MariaDB 10.0 (reports as version 5.5)
     $wpdb->query('SET' . (version_compare($wpdb->db_version(), '5.5', '>=') ? '' : ' OPTION') . ' SQL_BIG_SELECTS = 1');
     $groups_in_context = $wpdb->get_results("SELECT posts.ID, posts.post_parent " . "FROM {$wpdb->posts} posts " . implode(' ', $context_data['JOIN']) . "\n\t\t\t\tWHERE\n\t\t\t\t" . implode(' AND ', $context_data['WHERE']) . "\n\t\t\t", OBJECT_K);
     $groups_negated = $wpdb->get_results($wpdb->prepare("SELECT p.ID, p.post_parent " . "FROM {$wpdb->posts} p " . "WHERE p.post_type = '%s' " . "AND p.post_status = '%s' ", self::TYPE_CONDITION_GROUP, self::STATUS_NEGATED), OBJECT_K);
     $valid = array();
     //Force update of meta cache to prevent lazy loading
     update_meta_cache('post', array_keys($groups_in_context + $groups_negated));
     //Exclude sidebars that have unrelated content in same group
     foreach ($groups_in_context as $key => $sidebar) {
         $valid[$sidebar->ID] = $sidebar->post_parent;
         //TODO: move to modules
         foreach ($context_data['EXCLUDE'] as $exclude) {
             //quick fix to check for taxonomies terms
             if ($exclude == 'taxonomy') {
                 if ($wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->term_relationships} WHERE object_id = '{$sidebar->ID}'") > 0) {
                     unset($valid[$sidebar->ID]);
                     break;
                 }
             }
             if (get_post_custom_values(self::PREFIX . $exclude, $sidebar->ID) !== null) {
                 unset($valid[$sidebar->ID]);
                 break;
             }
         }
     }
     $handled_already = array_flip($valid);
     foreach ($groups_negated as $sidebar) {
         if (isset($valid[$sidebar->ID])) {
             unset($valid[$sidebar->ID]);
         } else {
             $valid[$sidebar->ID] = $sidebar->post_parent;
         }
         if (isset($handled_already[$sidebar->post_parent])) {
             unset($valid[$sidebar->ID]);
         }
         $handled_already[$sidebar->post_parent] = 1;
     }
     return self::$condition_cache = $valid;
 }
 public function initiate()
 {
     parent::initiate();
     if (is_admin()) {
         global $q_config;
         //Disable multilanguage
         if (is_array($q_config["post_type_excluded"])) {
             foreach (WPCACore::post_types()->get_all() as $name => $post_type) {
                 $q_config["post_type_excluded"][] = $name;
             }
             $q_config["post_type_excluded"][] = WPCACore::TYPE_CONDITION_GROUP;
         }
     }
 }
Example #4
0
 /**
  * Constructor
  *
  * @param   string    $id
  * @param   string    $title
  * @param   boolean   $ajax
  * @param   string    $description
  */
 public function __construct($id, $title, $ajax = false, $description = "")
 {
     $this->id = $id;
     $this->name = $title;
     $this->ajax = $ajax;
     $this->description = $description;
     if (is_admin()) {
         add_action('wpca/modules/admin-box', array(&$this, 'meta_box_content'));
         add_action('wpca/modules/save-data', array(&$this, 'save_data'));
         add_filter('wpca/modules/print-data', array(&$this, 'print_group_data'), 10, 2);
         foreach (WPCACore::post_types()->get_all() as $post_type) {
             add_filter('manage_' . $post_type->name . '_columns', array(&$this, 'metabox_preferences'));
         }
         if ($this->ajax) {
             add_action('wp_ajax_wpca/module/' . $this->id, array(&$this, 'ajax_print_content'));
         }
     }
     add_filter('wpca/modules/context-data', array(&$this, 'parse_context_data'));
 }
Example #5
0
 /**
  * Register taxonomies to sidebar post type
  *
  * @since  1.0
  * @return void 
  */
 public function add_taxonomies_to_sidebar()
 {
     foreach ($this->_get_taxonomies() as $tax) {
         foreach (WPCACore::post_types()->get_all() as $post_type) {
             register_taxonomy_for_object_type($tax->name, $post_type->name);
         }
     }
 }
Example #6
0
 /**
  * Automatically select child of selected parent
  *
  * @since  1.0
  * @param  string  $new_status 
  * @param  string  $old_status 
  * @param  WP_Post $post       
  * @return void 
  */
 public function post_ancestry_check($new_status, $old_status, $post)
 {
     if (!WPCACore::post_types()->has($post->post_type) && $post->post_type != WPCACore::TYPE_CONDITION_GROUP) {
         $status = array('publish', 'private', 'future');
         // Only new posts are relevant
         if (!in_array($old_status, $status) && in_array($new_status, $status)) {
             $post_type = get_post_type_object($post->post_type);
             if ($post_type->hierarchical && $post_type->public && $post->post_parent) {
                 // Get sidebars with post ancestor wanting to auto-select post
                 $query = new WP_Query(array('post_type' => WPCACore::TYPE_CONDITION_GROUP, 'meta_query' => array('relation' => 'AND', array('key' => WPCACore::PREFIX . $this->id, 'value' => WPCACore::PREFIX . 'sub_' . $post->post_type, 'compare' => '='), array('key' => WPCACore::PREFIX . $this->id, 'value' => get_ancestors($post->ID, $post->post_type), 'type' => 'numeric', 'compare' => 'IN'))));
                 if ($query && $query->found_posts) {
                     foreach ($query->posts as $sidebar) {
                         add_post_meta($sidebar->ID, WPCACore::PREFIX . $this->id, $post->ID);
                     }
                 }
             }
         }
     }
 }
Example #7
0
 /**
  * Remove sidebars from multilingual list
  *
  * @since  1.0
  * @param  array $post_types 
  * @return array             
  */
 public function remove_sidebar_multilingual($post_types)
 {
     foreach (WPCACore::post_types()->get_all() as $post_type) {
         unset($post_types[$post_type->name]);
     }
     return $post_types;
 }
Example #8
0
 /**
  * Get module manager
  *
  * @since   1.0
  * @return  WPCAModuleManager
  */
 public static function modules()
 {
     if (!self::$module_manager) {
         self::$module_manager = new WPCAModuleManager();
     }
     return self::$module_manager;
 }
Example #9
0
 /**
  * Get conditional restrictions 
  * and authorize access for user
  * 
  * @since  0.1
  * @return void
  */
 public function authorize_access()
 {
     if ($this->_has_global_access()) {
         return;
     }
     $posts = WPCACore::get_posts(RUA_App::TYPE_RESTRICT);
     if ($posts) {
         $kick = 0;
         $levels = array_flip($this->_get_user_levels());
         foreach ($posts as $post) {
             if (!isset($levels[$post->ID])) {
                 $kick = $post->ID;
             } else {
                 $kick = 0;
                 break;
             }
         }
         if ($kick) {
             $action = $this->metadata()->get('handle')->get_data($kick);
             self::$page = $this->metadata()->get('page')->get_data($kick);
             switch ($action) {
                 case 0:
                     if (self::$page != get_the_ID()) {
                         wp_safe_redirect(get_permalink(self::$page));
                         exit;
                     }
                     break;
                 case 1:
                     add_filter('the_content', array($this, 'content_tease'), 8);
                     break;
                 default:
                     break;
             }
             return;
         }
     }
 }
Example #10
0
 /**
  * Runs is_active_sidebar for sidebars
  * Widget management in Theme Customizer
  * expects this
  * 
  * @global type $wp_customize
  * @since  2.2
  * @return void
  */
 public function sidebar_notify_theme_customizer()
 {
     global $wp_customize;
     if (!empty($wp_customize)) {
         $sidebars = WPCACore::get_posts(CAS_App::TYPE_SIDEBAR);
         if ($sidebars) {
             foreach ($sidebars as $sidebar) {
                 is_active_sidebar(CAS_App::SIDEBAR_PREFIX . $sidebar->ID);
             }
         }
     }
 }