Exemplo n.º 1
0
/**
 * Initialize the ideas loop.
 *
 * @package WP Idea Stream
 * @subpackage ideas/tags
 *
 * @since 2.0.0
 *
 * @param array $args {
 *     Arguments for customizing ideas retrieved in the loop.
 *     Arguments must be passed as an associative array
 *     @type int 'author' to restrict the loop to one author
 *     @type int 'per_page' Number of results per page.
 *     @type int 'page' the page of results to display.
 *     @type string 'search' to limit the query to ideas containing the requested search terms
 *     @type array|string 'exclude' Array or comma separated list of idea IDs to exclude
 *     @type array|string 'include' Array or comma separated list of idea IDs to include
 *     @type string 'orderby' to customize the sorting order type for the ideas (default is by date)
 *     @type string 'order' the way results should be sorted : 'DESC' or 'ASC' (default is DESC)
 *     @type array 'meta_query' Limit ideas regarding their post meta by passing an array of
 *           meta_query conditions. See {@link WP_Meta_Query->queries} for a
 *           description of the syntax.
 *     @type array 'tax_query' Limit ideas regarding their terms by passing an array of
 *           tax_query conditions. See {@link WP_Tax_Query->queries} for a
 *           description of the syntax.
 *     @type string 'idea_name' Limit results by a the post name of the idea.
 *     @type bool 'is_widget' is the query performed inside a widget ?
 * }
 * @uses   wp_parse_args() to merge args with defaults
 * @uses   wp_idea_stream_search_rewrite_id() to get the search rewrite id
 * @uses   wp_idea_stream_is_user_profile_ideas() to check if a user's profile is displayed
 * @uses   wp_idea_stream_users_displayed_user_id() to get the ID of the displayed user.
 * @uses   wp_idea_stream_ideas_per_page() to get the pagination preferences
 * @uses   WP_Idea_Stream_Loop_Ideas to get the ideas matching arguments
 * @uses   wp_idea_stream() to get plugin's main instance
 * @uses   apply_filters() call 'wp_idea_stream_ideas_has_ideas' to choose whether to init the loop or not
 * @return bool         true if ideas were found, false otherwise
 */
function wp_idea_stream_ideas_has_ideas($args = array())
{
    if (!is_array($args)) {
        $args = wp_parse_args($args, array());
    }
    $template_args = array();
    /**
     * We have arguments, so let's override the main query
     */
    if (!empty($args)) {
        $search_terms = '';
        if (isset($_GET[wp_idea_stream_search_rewrite_id()])) {
            $search_terms = stripslashes($_GET[wp_idea_stream_search_rewrite_id()]);
        }
        $r = wp_parse_args($args, array('author' => wp_idea_stream_is_user_profile_ideas() ? wp_idea_stream_users_displayed_user_id() : '', 'per_page' => wp_idea_stream_ideas_per_page(), 'page' => 1, 'search' => '', 'exclude' => '', 'include' => '', 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => array(), 'tax_query' => array(), 'idea_name' => '', 'is_widget' => false));
        $template_args = array('author' => (int) $r['author'], 'per_page' => (int) $r['per_page'], 'page' => (int) $r['page'], 'search' => $r['search'], 'exclude' => $r['exclude'], 'include' => $r['include'], 'orderby' => $r['orderby'], 'order' => $r['order'], 'meta_query' => (array) $r['meta_query'], 'tax_query' => (array) $r['tax_query'], 'idea_name' => $r['idea_name'], 'is_widget' => (bool) $r['is_widget']);
    }
    // Get the ideas
    $query_loop = new WP_Idea_Stream_Loop_Ideas($template_args);
    // Setup the global query loop
    wp_idea_stream()->query_loop = $query_loop;
    /**
     * @param  bool   true if ideas were found, false otherwise
     * @param  object $query_loop the ideas loop
     * @param  array  $template_args arguments used to build the loop
     * @param  array  $args requested arguments
     */
    return apply_filters('wp_idea_stream_ideas_has_ideas', $query_loop->has_items(), $query_loop, $template_args, $args);
}
/**
 * Are we searching ideas ?
 *
 * @package WP Idea Stream
 * @subpackage core/template-functions
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream_search_rewrite_id() to get the search rewrite id
 * @uses   wp_idea_stream_get_idea_var() to get a globalized var
 * @uses   apply_filters() call 'wp_idea_stream_is_search' to override the condition
 * @return bool true if an idea search is performed, otherwise false
 */
function wp_idea_stream_is_search()
{
    $retval = false;
    if (get_query_var(wp_idea_stream_search_rewrite_id()) || wp_idea_stream_get_idea_var('is_search')) {
        $retval = true;
    }
    return apply_filters('wp_idea_stream_is_search', $retval);
}
Exemplo n.º 3
0
 /**
  * Setup the rewrite ids and slugs
  *
  * @package WP Idea Stream
  * @subpackage core/classes
  *
  * @since 2.0.0
  *
  * @uses  wp_idea_stream_user_rewrite_id()
  * @uses  wp_idea_stream_user_rates_rewrite_id()
  * @uses  wp_idea_stream_user_comments_rewrite_id()
  * @uses  wp_idea_stream_cpage_rewrite_id()
  * @uses  wp_idea_stream_action_rewrite_id()
  * @uses  wp_idea_stream_search_rewrite_id()
  * @uses  wp_idea_stream_user_slug()
  * @uses  wp_idea_stream_user_rates_slug()
  * @uses  wp_idea_stream_user_comments_slug()
  * @uses  wp_idea_stream_cpage_slug()
  * @uses  wp_idea_stream_action_slug()
  */
 private function setup_globals()
 {
     /** Rewrite ids ***************************************************************/
     $this->page_rid = 'paged';
     // WordPress built-in global var
     $this->user_rid = wp_idea_stream_user_rewrite_id();
     $this->user_rates_rid = wp_idea_stream_user_rates_rewrite_id();
     $this->user_comments_rid = wp_idea_stream_user_comments_rewrite_id();
     $this->cpage_rid = wp_idea_stream_cpage_rewrite_id();
     $this->action_rid = wp_idea_stream_action_rewrite_id();
     $this->search_rid = wp_idea_stream_search_rewrite_id();
     /** Rewrite slugs *************************************************************/
     $this->user_slug = wp_idea_stream_user_slug();
     $this->user_rates_slug = wp_idea_stream_user_rates_slug();
     $this->user_comments_slug = wp_idea_stream_user_comments_slug();
     $this->cpage_slug = wp_idea_stream_cpage_slug();
     $this->action_slug = wp_idea_stream_action_slug();
 }
Exemplo n.º 4
0
 /**
  * Constructor
  *
  * @package WP Idea Stream
  * @subpackage idea/tags
  *
  * @since 2.0.0
  *
  * @param  array $args the loop args
  * @uses   get_query_var()
  * @uses   wp_idea_stream_get_idea_var() to get the globalized query loop
  * @uses   wp_idea_stream_ideas_get_idea_by_name() to get the idea object thanks to its post_name
  * @uses   wp_idea_stream_reset_post() to reset the $wp_query->post data
  * @uses   wp_idea_stream_set_idea_var() to globalized the need for a reset postdata
  * @uses   wp_idea_stream_ideas_get_ideas() get all matching ideas
  * @uses   wp_idea_stream_is_pretty_links() do we have a custom permalink structure ?
  * @uses   add_query_arg() to build the url in case default permalink is set
  * @uses   wp_idea_stream_is_idea_archive() to check an idea archive page is being displayed
  * @uses   wp_idea_stream_get_root_url() to get ideas archive url
  * @uses   wp_idea_stream_is_category() to check a category page is being displayed
  * @uses   wp_idea_stream_get_category_url() to get the category url
  * @uses   wp_idea_stream_is_tag() to check a tag page is being displayed
  * @uses   wp_idea_stream_get_tag_url() to get the category url
  * @uses   wp_idea_stream_is_user_profile_rates() to check the rates user's profile page is displayed
  * @uses   wp_idea_stream_users_get_displayed_profile_url() to get user's profile url
  * @uses   wp_idea_stream_is_user_profile_ideas() to check the main user's profile page is displayed
  * @uses   wp_idea_stream_paged_slug() to get the pagination slug
  * @uses   wp_idea_stream_search_rewrite_id() to get the search rewrite id
  * @uses   WP_Idea_Stream_Loop::start() to launch the loop
  * @uses   apply_filters() call 'wp_idea_stream_ideas_pagination_args' to override paginate args
  */
 public function __construct($args = array())
 {
     if (!empty($args) && empty($args['is_widget'])) {
         $paged = get_query_var('paged');
         // Set which pagination page
         if (!empty($paged)) {
             $args['page'] = $paged;
             // Checking query string just in case
         } else {
             if (!empty($_GET['paged'])) {
                 $args['page'] = absint($_GET['paged']);
                 // Checking in page args
             } else {
                 if (!empty($args['page'])) {
                     $args['page'] = absint($args['page']);
                     // Default to first page
                 } else {
                     $args['page'] = 1;
                 }
             }
         }
     }
     // Only get the idea requested
     if (!empty($args['idea_name'])) {
         $query_loop = wp_idea_stream_get_idea_var('query_loop');
         if (empty($query_loop->idea)) {
             $idea = wp_idea_stream_ideas_get_idea_by_name($args['idea_name']);
         } else {
             $idea = $query_loop->idea;
         }
         // can't do this too ealy
         $reset_data = array_merge((array) $idea, array('is_page' => true));
         wp_idea_stream_reset_post($reset_data);
         // this needs a "reset postdata"!
         wp_idea_stream_set_idea_var('needs_reset', true);
         $ideas = array('ideas' => array($idea), 'total' => 1, 'get_args' => array('page' => 1, 'per_page' => 1));
         // Get the ideas
     } else {
         $ideas = wp_idea_stream_ideas_get_ideas($args);
     }
     if (!empty($ideas['get_args'])) {
         foreach ($ideas['get_args'] as $key => $value) {
             $this->{$key} = $value;
         }
     } else {
         return false;
     }
     $params = array('plugin_prefix' => 'wp_idea_stream', 'item_name' => 'idea', 'item_name_plural' => 'ideas', 'items' => $ideas['ideas'], 'total_item_count' => $ideas['total'], 'page' => $this->page, 'per_page' => $this->per_page);
     $paginate_args = array();
     // No pretty links
     if (!wp_idea_stream_is_pretty_links()) {
         $paginate_args['base'] = add_query_arg('paged', '%#%');
     } else {
         // Is it the main archive page ?
         if (wp_idea_stream_is_idea_archive()) {
             $base = trailingslashit(wp_idea_stream_get_root_url()) . '%_%';
             // Or the category archive page ?
         } else {
             if (wp_idea_stream_is_category()) {
                 $base = trailingslashit(wp_idea_stream_get_category_url()) . '%_%';
                 // Or the tag archive page ?
             } else {
                 if (wp_idea_stream_is_tag()) {
                     $base = trailingslashit(wp_idea_stream_get_tag_url()) . '%_%';
                     // Or the displayed user rated ideas ?
                 } else {
                     if (wp_idea_stream_is_user_profile_rates()) {
                         $base = trailingslashit(wp_idea_stream_users_get_displayed_profile_url('rates')) . '%_%';
                         // Or the displayed user published ideas ?
                     } else {
                         if (wp_idea_stream_is_user_profile_ideas()) {
                             $base = trailingslashit(wp_idea_stream_users_get_displayed_profile_url()) . '%_%';
                             // Or nothing i've planed ?
                         } else {
                             /**
                              * Create your own pagination base if not handled by the plugin
                              *
                              * @param string empty string
                              */
                             $base = apply_filters('wp_idea_stream_ideas_pagination_base', '');
                         }
                     }
                 }
             }
         }
         $paginate_args['base'] = $base;
         $paginate_args['format'] = wp_idea_stream_paged_slug() . '/%#%/';
     }
     // Is this a search ?
     if (wp_idea_stream_get_idea_var('is_search')) {
         $paginate_args['add_args'] = array(wp_idea_stream_search_rewrite_id() => $_GET[wp_idea_stream_search_rewrite_id()]);
     }
     // Do we have a specific order to use ?
     $orderby = wp_idea_stream_get_idea_var('orderby');
     if (!empty($orderby) && 'date' != $orderby) {
         $merge = array();
         if (!empty($paginate_args['add_args'])) {
             $merge = $paginate_args['add_args'];
         }
         $paginate_args['add_args'] = array_merge($merge, array('orderby' => $orderby));
     }
     /**
      * Use this filter to override the pagination
      *
      * @param array $paginate_args the pagination arguments
      */
     parent::start($params, apply_filters('wp_idea_stream_ideas_pagination_args', $paginate_args));
 }
Exemplo n.º 5
0
 /**
  * Loads needed IdeaStream template parts
  *
  * - new form
  * - single idea
  * - ideas loop
  *
  * @package WP Idea Stream
  * @subpackage buddypress/groups
  *
  * @since  2.0.0
  *
  * @global $wp_query
  * @uses   bp_get_current_group_id() to get the group id
  * @uses   wp_idea_stream_tag_get_slug() to get the ideas tag taxonomy slug
  * @uses   wp_idea_stream_category_get_slug() to get the ideas category taxonomy slug
  * @uses   get_query_var() to get the value of the needed query var
  * @uses   wp_idea_stream_search_rewrite_id() to get the search ideas rewrite id
  * @uses   add_filter() to temporarly override some IdeaStream vars
  * @uses   wp_idea_stream_template_part() to load the needed template part
  * @uses   remove_filter() to remove the temporary filters
  * @return string html output
  */
 public function display($group_id = null)
 {
     global $wp_query;
     // Catch BuddyPress group's query post settings
     if (!empty($wp_query->post)) {
         $this->group_post = $wp_query->post;
     }
     if (empty($this->group_ideastream->is_action)) {
         return;
     }
     // Default vars
     $template_slug = 'archive';
     $template_name = '';
     $filters = array('ideas_query_args');
     $this->group_ideastream->query_args = array('meta_query' => array(array('key' => '_ideastream_group_id', 'value' => bp_get_current_group_id(), 'compare' => '=')));
     switch ($this->group_ideastream->is_action) {
         case 'new':
         case 'edit':
             $template_slug = 'idea';
             $template_name = 'form';
             $filters = array();
             break;
         case 'idea':
             $template_slug = 'idea';
             $template_name = 'group';
             $this->group_ideastream->query_args = array('idea_name' => $this->group_ideastream->idea_name);
             break;
         case wp_idea_stream_tag_get_slug():
         case wp_idea_stream_category_get_slug():
             $this->group_ideastream->query_args['tax_query'] = array(array('field' => 'term_id', 'taxonomy' => $this->group_ideastream->current_taxonomy, 'terms' => $this->group_ideastream->current_term->term_id));
             break;
     }
     $search_terms = get_query_var(wp_idea_stream_search_rewrite_id());
     if (!empty($search_terms) && 'archive' == $this->group_ideastream->is_action) {
         $this->group_ideastream->query_args['search'] = $search_terms;
     }
     if (!empty($this->group_ideastream->is_paged)) {
         $this->group_ideastream->query_args['page'] = $this->group_ideastream->is_paged;
     }
     $orderby = get_query_var('orderby');
     if (!empty($orderby)) {
         $this->group_ideastream->query_args['orderby'] = $orderby;
     }
     // Loop in filters to temporarly add needed ones
     foreach ($filters as $filter) {
         add_filter('wp_idea_stream_' . $filter, array($this, $filter), 10, 1);
     }
     // remove all filters to content, we'll use custom filters
     remove_all_filters('the_content');
     wp_idea_stream_template_part($template_slug, $template_name);
     // Loop in filters to remove
     foreach ($filters as $filter) {
         remove_filter('wp_idea_stream_' . $filter, array($this, $filter), 10, 1);
     }
 }