コード例 #1
0
 function posts_orderby($orderBy, $query)
 {
     //check for single object query on which no sort apply is necesarelly
     if ($query->is_single() || $query->is_page() || $query->is_singular() || $query->is_preview() || $query->is_attachment()) {
         return $orderBy;
     }
     //check for orderby GET paramether in which case return default data
     if (!defined('DOING_AJAX') && isset($_GET['orderby']) && $_GET['orderby'] != 'menu_order') {
         return $orderBy;
     }
     //check for the force_no_custom_order param
     //deprecated force_no_custom_order   relay on ignore_custom_sort instead
     if (isset($query->query_vars['force_no_custom_order']) && $query->query_vars['force_no_custom_order'] === TRUE) {
         return $orderBy;
     }
     if (isset($query->query_vars['ignore_custom_sort']) && $query->query_vars['ignore_custom_sort'] === TRUE) {
         return $orderBy;
     }
     if (apto_is_plugin_active('bbpress/bbpress.php') && isset($query->query_vars['post_type']) && (is_array($query->query_vars['post_type']) && in_array("reply", $query->query_vars['post_type']) || $query->query_vars['post_type'] == "reply")) {
         return $orderBy;
     }
     //WP E-Commerce check if drag-and-drop for archive
     if (apto_is_plugin_active('wp-e-commerce/wp-shopping-cart.php') && $query->is_archive('wpsc-product') && !$query->is_tax('wpsc_product_category')) {
         if ($this->functions->wp_ecommerce_is_draganddrop() === FALSE) {
             return $orderBy;
         }
     }
     //allowing a way to suppress sorting apply and return original orderby
     if (apply_filters('apto/posts_orderby', $orderBy, $query) === FALSE) {
         return $orderBy;
     }
     global $wpdb;
     //check if menu_order provided through the query params
     if (isset($query->query['orderby']) && $query->query['orderby'] == 'menu_order') {
         $orderBy = $this->functions->query_get_orderby($orderBy, $query);
         return $orderBy;
     }
     $default_orderBy = $orderBy;
     if (is_admin() && !defined('DOING_AJAX')) {
         //force to use the custom order
         //$orderBy = $wpdb->posts.".menu_order, " . $wpdb->posts.".post_date DESC";
         $args = array('_adminsort' => array('yes'));
         $orderBy = $this->functions->query_get_orderby($orderBy, $query, $args);
         if ($orderBy == '') {
             $orderBy = $default_orderBy;
         }
     } else {
         //check against any Autosort On sort list
         $args = array('_autosort' => array('yes'));
         $orderBy = $this->functions->query_get_orderby($orderBy, $query, $args);
         return $orderBy;
     }
     return $orderBy;
 }
コード例 #2
0
 function is_BBPress_topic_simple($sortID)
 {
     if (apto_is_plugin_active('bbpress/bbpress.php') === FALSE) {
         return FALSE;
     }
     $sort_settings = $this->get_sort_settings($sortID);
     $sort_rules = $this->get_sort_current_language_rules($sort_settings, FALSE);
     if ($sort_rules === FALSE) {
         return FALSE;
     }
     //check for query rules match
     /**
      * 
      * Check for post type
      * 
      */
     if (count($sort_rules['post_type']) < 1 || count($sort_rules['post_type']) > 1 || $sort_rules['post_type'][0] != 'topic') {
         return FALSE;
     }
     /**
      * 
      * Check for taxonomies match
      * 
      */
     if (isset($sort_rules['taxonomy']) && is_array($sort_rules['taxonomy']) && count($sort_rules['taxonomy']) > 0) {
         return FALSE;
     }
     return TRUE;
 }
コード例 #3
0
 function get_interface_query_arguments($sort_view_id, $args)
 {
     $sort_view_settings = $this->functions->get_sort_view_settings($sort_view_id);
     $sort_view_data = get_post($sort_view_id);
     if ($sort_view_data->post_parent > 0) {
         $sortID = $sort_view_data->post_parent;
     } else {
         $sortID = $sort_view_id;
     }
     $sort_settings = $this->functions->get_sort_settings($sortID);
     $is_hierarhical = $this->get_is_hierarhical_by_settings($sortID);
     $defaults = array('depth' => 0, 'post_status' => 'any', 'sort_id' => $sortID, 'sort_view_id' => $sort_view_id, 'posts_per_page' => -1, 'filter_date' => 0, 'search' => '');
     $args = wp_parse_args($args, $defaults);
     if ($sort_settings['_view_type'] == 'multiple') {
         $args['post_type'] = $sort_settings['_rules']['post_type'];
         $args['orderby'] = 'menu_order';
         $args['order'] = 'ASC';
         //set author if need
         if (isset($sort_settings['_rules']['author']) && is_array($sort_settings['_rules']['author']) && count($sort_settings['_rules']['author']) > 0) {
             $args['author'] = implode(",", $sort_settings['_rules']['author']);
         }
         //set taxonomy if need (deppends on current view_selection
         if ($sort_view_settings['_view_selection'] == 'taxonomy') {
             $args['tax_query'] = array(array('taxonomy' => $sort_view_settings['_taxonomy'], 'field' => 'id', 'terms' => array(intval($sort_view_settings['_term_id']))));
         }
     }
     if ($sort_settings['_view_type'] == 'simple') {
         $args['post_type'] = $sort_settings['_rules']['post_type'];
         $args['orderby'] = 'menu_order';
         $args['order'] = 'ASC';
         $sort_rules = $this->functions->get_sort_current_language_rules($sort_settings, FALSE);
         //set author if need
         if (isset($sort_rules['author']) && is_array($sort_rules['author']) && count($sort_rules['author']) > 0) {
             $args['author'] = implode(",", $sort_rules['author']);
         }
         //set taxonomy if need (deppends on current view_selection
         $taxonomy_data = $sort_rules['taxonomy'];
         $taxonomy_data['relation'] = $sort_rules['taxonomy_relation'];
         $args['tax_query'] = $taxonomy_data;
     }
     //limit the returnds only to IDS to prevent memory exhaust
     if ($this->get_is_hierarhical_by_settings($sortID) === TRUE || $this->functions->is_woocommerce($sortID) === TRUE && $sort_view_settings['_view_selection'] == 'archive') {
         $args['fields'] = 'id=>parent';
     } else {
         $args['fields'] = 'ids';
     }
     if ($this->functions->is_woocommerce($sortID) === TRUE && $sort_view_settings['_view_selection'] == 'archive') {
         $r['depth'] = 0;
     } else {
         if ($this->functions->is_woocommerce($sortID) === TRUE) {
             $args['meta_query'] = array(array('key' => '_visibility', 'value' => array('visible', 'catalog'), 'compare' => 'IN'));
         }
     }
     //Interface date filter
     if ($args['filter_date'] != '0') {
         if ($args['filter_date'] == 'last_week') {
             $last_week = strtotime('-8 days');
             $next_day = strtotime('+1 day');
             $args['date_query'] = array(array('after' => array('year' => date("Y", $last_week), 'month' => date("m", $last_week), 'day' => date("d", $last_week)), 'before' => array('year' => date("Y", $next_day), 'month' => date("m", $next_day), 'day' => date("d", $next_day)), 'inclusive' => FALSE));
         } else {
             if ($args['filter_date'] == 'today') {
                 $time = current_time('timestamp');
                 $year = date("Y", $time);
                 $month = date("m", $time);
                 $day = date("d", $time);
                 $args['date_query'] = array(array('year' => $year, 'month' => $month, 'day' => $day));
             } else {
                 if ($args['filter_date'] == 'yesterday') {
                     $time = current_time('timestamp');
                     $time = $time - 86400;
                     $year = date("Y", $time);
                     $month = date("m", $time);
                     $day = date("d", $time);
                     $args['date_query'] = array(array('year' => $year, 'month' => $month, 'day' => $day));
                 } else {
                     $year = substr($args['filter_date'], 0, 4);
                     $month = substr($args['filter_date'], 4, 2);
                     $args['date_query'] = array(array('year' => $year, 'month' => $month));
                 }
             }
         }
     }
     //Search filter
     if ($args['search'] != '') {
         $args['s'] = $args['search'];
     }
     //check for bbPress filter
     if (apto_is_plugin_active('bbpress/bbpress.php') !== FALSE && isset($_GET['bbpress_forum']) && $_GET['bbpress_forum'] != '') {
         $args['post_parent'] = $_GET['bbpress_forum'];
     }
     $exclude = apply_filters('apto_exclude_posts_from_interface', array(), $sort_view_id, $args);
     if (is_array($exclude) && count($exclude) > 0) {
         $args['post__not_in'] = $exclude;
     }
     return $args;
 }