Beispiel #1
0
/**
 * Filter for output HTML, get value, save value of a field
 *
 * @param string $name  Based filter name
 * @param mixed  $value Value
 *
 * @return mixed
 */
function constructent_options_filter($name, $value)
{
    // Get function arguments
    // 0 - $name
    // 1 - $value
    // 2 - field (optional)
    // 3, ... - other params (optional)
    $args = func_get_args();
    $args = array_slice($args, 2);
    $tags = array("constructent_options_{$name}");
    if (!empty($args)) {
        $field = array_shift($args);
        if (isset($field['type'])) {
            $tags[] = "constructent_options_{$name}_{$field['type']}";
        }
        if (isset($field['id'])) {
            $tags[] = "constructent_options_{$name}_{$field['id']}";
        }
    }
    array_unshift($args, $value);
    foreach ($tags as $tag) {
        $value = apply_filters_ref_array($tag, $args);
    }
    return $value;
}
 function __invoke()
 {
     $args = func_get_args();
     $message_name = $this->get_message_name();
     $event_before = $message_name . '_before';
     if (has_action($event_before)) {
         do_action_ref_array($event_before, $args);
     }
     $event_pre = $message_name . '_args';
     if (has_filter($event_pre)) {
         $args = apply_filters_ref_array($event_pre, $args);
     }
     $result = null;
     $fn = $this->find_real_function($args);
     if (is_callable($fn)) {
         $result = call_user_func_array($fn, $args);
     }
     if (has_filter($message_name)) {
         $new_args = array_merge(array($result), $args);
         $result = apply_filters_ref_array($message_name, $new_args);
     }
     $event_after = $message_name . '_after';
     if (has_action($event_after)) {
         do_action_ref_array($event_after, array_merge($args, array($result)));
     }
     return $result;
 }
/** Topic Functions ***********************************************************/
function bp_forums_get_forum_topics($args = '')
{
    global $bp;
    do_action('bbpress_init');
    $defaults = array('type' => 'newest', 'forum_id' => false, 'user_id' => false, 'page' => 1, 'per_page' => 15, 'offset' => false, 'number' => false, 'exclude' => false, 'show_stickies' => 'all', 'filter' => false);
    $r = nxt_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    if (class_exists('BB_Query')) {
        switch ($type) {
            case 'newest':
                $query = new BB_Query('topic', array('forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies, 'offset' => $offset, 'number' => $number), 'get_latest_topics');
                $topics =& $query->results;
                break;
            case 'popular':
                $query = new BB_Query('topic', array('forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_posts', 'topic_title' => $filter, 'sticky' => $show_stickies, 'offset' => $offset, 'number' => $number));
                $topics =& $query->results;
                break;
            case 'unreplied':
                $query = new BB_Query('topic', array('forum_id' => $forum_id, 'topic_author_id' => $user_id, 'post_count' => 1, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies, 'offset' => $offset, 'number' => $number));
                $topics =& $query->results;
                break;
            case 'tags':
                $query = new BB_Query('topic', array('forum_id' => $forum_id, 'topic_author_id' => $user_id, 'tag' => $filter, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'sticky' => $show_stickies, 'offset' => $offset, 'number' => $number));
                $topics =& $query->results;
                break;
        }
    } else {
        $topics = array();
    }
    return apply_filters_ref_array('bp_forums_get_forum_topics', array(&$topics, &$r));
}
Beispiel #4
0
 /**
  *
  * @param \WP_Post $taxonomy
  */
 public static function format(&$taxonomy, $state = 'read')
 {
     if (!$taxonomy) {
         return $taxonomy = null;
     }
     $data = array('name' => $taxonomy->name, 'post_types' => $taxonomy->object_type, 'hierarchical' => $taxonomy->hierarchical, 'queryVar' => $taxonomy->query_var, 'labels' => $taxonomy->labels, 'meta' => new \stdClass());
     $taxonomy = apply_filters_ref_array('thermal_taxonomy_entity', array((object) $data, &$taxonomy, $state));
 }
Beispiel #5
0
/**
 * Protect access to single groups.
 *
 * @since BuddyPress (2.1.0)
 */
function bp_groups_group_access_protection()
{
    if (!bp_is_group()) {
        return;
    }
    $current_group = groups_get_current_group();
    $user_has_access = $current_group->user_has_access;
    $no_access_args = array();
    if (!$user_has_access && 'hidden' !== $current_group->status) {
        // Always allow access to home and request-membership
        if (bp_is_current_action('home') || bp_is_current_action('request-membership')) {
            $user_has_access = true;
            // User doesn't have access, so set up redirect args
        } else {
            if (is_user_logged_in()) {
                $no_access_args = array('message' => __('You do not have access to this group.', 'buddypress'), 'root' => bp_get_group_permalink($current_group) . 'home/', 'redirect' => false);
            }
        }
    }
    // Protect the admin tab from non-admins
    if (bp_is_current_action('admin') && !bp_is_item_admin()) {
        $user_has_access = false;
        $no_access_args = array('message' => __('You are not an admin of this group.', 'buddypress'), 'root' => bp_get_group_permalink($current_group), 'redirect' => false);
    }
    /**
     * Allow plugins to filter whether the current user has access to this group content.
     *
     * Note that if a plugin sets $user_has_access to false, it may also
     * want to change the $no_access_args, to avoid problems such as
     * logged-in users being redirected to wp-login.php.
     *
     * @since BuddyPress (2.1.0)
     *
     * @param bool $user_has_access True if the user has access to the
     *        content, otherwise false.
     * @param array $no_access_args Arguments to be passed to
     *        bp_core_no_access() in case of no access. Note that this
     *        value is passed by reference, so it can be modified by the
     *        filter callback.
     */
    $user_has_access = apply_filters_ref_array('bp_group_user_has_access', array($user_has_access, &$no_access_args));
    // If user has access, we return rather than redirect
    if ($user_has_access) {
        return;
    }
    // Hidden groups should return a 404 for non-members.
    // Unset the current group so that you're not redirected
    // to the default group tab
    if ('hidden' == $current_group->status) {
        buddypress()->groups->current_group = 0;
        buddypress()->is_single_item = false;
        bp_do_404();
        return;
    } else {
        bp_core_no_access($no_access_args);
    }
}
Beispiel #6
0
 /**
  * Run all filters registered with the hook.
  *
  * @param string $hook The filter hook name.
  * @param mixed  $args
  *
  * @return mixed
  */
 public function run($hook, $args = null)
 {
     if (is_array($args)) {
         apply_filters_ref_array($hook, $args);
     } else {
         apply_filters($hook, $args);
     }
     return $this;
 }
 /**
  * Constructor with settings passed as arguments
  * Available options include 'status_map' and 'default_status'.
  * 
  * @param array $args
  */
 function __construct($args = array())
 {
     $args = array_merge(array('status_map' => array('CONFIRMED' => 'publish', 'CANCELLED' => 'trash', 'TENTATIVE' => 'draft'), 'default_status' => 'draft', 'parse_html' => true), $args);
     $args = apply_filters_ref_array('eventorganiser_ical_parser_args', array($args, &$this));
     $this->calendar_timezone = eo_get_blog_timezone();
     $this->default_status = $args['default_status'];
     $this->status_map = $args['status_map'];
     $this->parse_html = $args['parse_html'];
 }
 /**
  * Set up the amount of found posts and the number of pages (if limit clause was used)
  * for the current query.
  *
  * @access public
  */
 public function set_found_posts($q, $es_response)
 {
     if (!is_wp_error($es_response) && isset($es_response['results']['total'])) {
         $this->found_posts = absint($es_response['results']['total']);
     } else {
         $this->found_posts = 0;
     }
     $this->found_posts = apply_filters_ref_array('es_found_posts', array($this->found_posts, &$this));
     $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
 }
 public static function flt_nav_menu_items($items, $menu_name, $args)
 {
     global $wpdb;
     $item_types = array();
     //d_echo( '********************** enter flt_nav_menu_items <br /> ' );
     foreach ($items as $key => $item) {
         if (!isset($item_types[$item->type])) {
             $item_types["{$item->type}"] = array();
         }
         $item_types[$item->type][$item->object][$key] = $item->object_id;
     }
     $teaser_enabled = apply_filters('pp_teaser_enabled', false, 'post');
     // remove unreadable terms
     if (isset($item_types['taxonomy'])) {
         foreach ($item_types['taxonomy'] as $taxonomy => $item_ids) {
             $hide_empty = defined('PP_NAV_MENU_SHOW_EMPTY_TERMS') ? '0' : '1';
             $okay_ids = get_terms($taxonomy, "fields=ids&hide_empty={$hide_empty}");
             if ($remove_ids = apply_filters('pp_nav_menu_hide_terms', array_diff($item_ids, $okay_ids), $taxonomy)) {
                 $item_types['taxonomy'][$taxonomy] = array_diff($item_types['taxonomy'][$taxonomy], $remove_ids);
                 foreach (array_keys($items) as $key) {
                     if (!empty($items[$key]->type) && 'taxonomy' == $items[$key]->type && in_array($items[$key]->object_id, $remove_ids)) {
                         unset($items[$key]);
                     }
                 }
             }
         }
     }
     // remove or tease unreadable posts
     if (isset($item_types['post_type'])) {
         $post_types = array_keys($item_types['post_type']);
         $post_ids = pp_array_flatten($item_types['post_type']);
     } else {
         $post_types = $post_ids = array();
     }
     $pub_stati = pp_get_post_stati(array('public' => true, 'post_type' => $post_types));
     $pvt_stati = pp_get_post_stati(array('private' => true, 'post_type' => $post_types));
     $stati = array_merge($pub_stati, $pvt_stati);
     $clauses = array_fill_keys(array('distinct', 'join', 'groupby', 'orderby', 'limits'), '');
     $clauses['fields'] = 'ID';
     $clauses['where'] = "AND post_type IN ( '" . implode("','", $post_types) . "' ) AND ID IN ( '" . implode("','", $post_ids) . "') AND post_status IN ('" . implode("','", $stati) . "')";
     $clauses = apply_filters('pp_posts_clauses', $clauses, array('post_types' => $post_types, 'skip_teaser' => true, 'required_operation' => 'read', 'force_types' => true));
     $okay_ids = $wpdb->get_col("SELECT {$clauses['distinct']} ID FROM {$wpdb->posts} {$clauses['join']} WHERE 1=1 {$clauses['where']}");
     foreach ($post_types as $_post_type) {
         $remove_ids = array_diff($item_types['post_type'][$_post_type], $okay_ids);
         if ($remove_ids = apply_filters_ref_array('pp_nav_menu_hide_posts', array($remove_ids, &$items, $_post_type))) {
             foreach (array_keys($items) as $key) {
                 if (!empty($items[$key]->type) && 'post_type' == $items[$key]->type && in_array($items[$key]->object_id, $remove_ids)) {
                     unset($items[$key]);
                 }
             }
         }
     }
     //d_echo( '**************** exit flt_nav_menu_items <br /> ' );
     return $items;
 }
/**
 * Get rendez-vouss
 *
 * @package Rendez Vous
 * @subpackage Functions
 *
 * @since Rendez Vous (1.0.0)
 */
function rendez_vous_get_items($args = array())
{
    $defaults = array('attendees' => array(), 'organizer' => false, 'per_page' => 20, 'page' => 1, 'search' => false, 'exclude' => false, 'orderby' => 'modified', 'order' => 'DESC', 'group_id' => false, 'type' => '');
    $r = bp_parse_args($args, $defaults, 'rendez_vous_get_items_args');
    $rendez_vouss = wp_cache_get('rendez_vous_rendez_vouss', 'bp');
    if (empty($rendez_vouss)) {
        $rendez_vouss = Rendez_Vous_Item::get(array('attendees' => (array) $r['attendees'], 'organizer' => (int) $r['organizer'], 'per_page' => $r['per_page'], 'page' => $r['page'], 'search' => $r['search'], 'exclude' => $r['exclude'], 'orderby' => $r['orderby'], 'order' => $r['order'], 'group_id' => $r['group_id'], 'type' => $r['type']));
        wp_cache_set('rendez_vous_rendez_vouss', $rendez_vouss, 'bp');
    }
    return apply_filters_ref_array('rendez_vous_get_items', array(&$rendez_vouss, &$r));
}
 function oz_optimized_get_posts()
 {
     global $wp_query, $wpdb;
     if ($wp_query->max_num_pages > 1) {
         $wp_query->query_vars['no_found_rows'] = 1;
         $wp_query->found_posts = $wpdb->get_var("SELECT COUNT(*) FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')");
         $wp_query->found_posts = apply_filters_ref_array('found_posts', array($wp_query->found_posts, &$wp_query));
         $posts_per_page = !empty($wp_query->query_vars['posts_per_page']) ? $wp_query->query_vars['posts_per_page'] : get_option('posts_per_page');
         $wp_query->max_num_pages = ceil($wp_query->found_posts / $posts_per_page);
     } else {
         if ($query->is_main_query()) {
             $query->set('no_found_rows', TRUE);
         }
     }
     return $wp_query;
 }
Beispiel #12
0
/**
 * Adds contextual filter hooks to the theme.  This allows users to easily filter context-based content 
 * without having to know how to use WordPress conditional tags.  The theme handles the logic.
 *
 * An example of a basic hook would be 'omega_entry_meta'.  The apply_atomic() function extends 
 * that to give extra hooks such as 'omega_singular_entry_meta', 'omega_singular-post_entry_meta', 
 * and 'omega_singular-post-ID_entry_meta'.
 *
 * @since  0.9.0
 * @access public
 * @param  string $tag     Usually the location of the hook but defines what the base hook is.
 * @param  mixed  $value   The value on which the filters hooked to $tag are applied on.
 * @param  mixed  $var,... Additional variables passed to the functions hooked to $tag.
 * @return mixed  $value   The value after it has been filtered.
 */
function omega_apply_atomic($tag = '', $value = '')
{
    if (empty($tag)) {
        return false;
    }
    /* Get the args passed into the function and remove $tag. */
    $args = func_get_args();
    array_splice($args, 0, 1);
    /* Apply filters on the basic hook. */
    $value = $args[0] = apply_filters_ref_array("omega_{$tag}", $args);
    /* Loop through context array and apply filters on a contextual scale. */
    foreach ((array) omega_get_context() as $context) {
        $value = $args[0] = apply_filters_ref_array("omega_{$context}_{$tag}", $args);
    }
    /* Return the final value once all filters have been applied. */
    return $value;
}
/**
 * Allow core components and dependent plugins to register activity actions
 *
 * @since 1.2.0
 *
 * @global object $bp BuddyPress global settings
 * @uses bp_is_activity_component()
 * @uses bp_is_current_action()
 * @uses bp_action_variable()
 * @uses bp_activity_get_specific()
 * @uses bp_is_active()
 * @uses bp_core_get_user_domain()
 * @uses groups_get_group()
 * @uses bp_get_group_permalink()
 * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_redirect_url' hook
 * @uses bp_core_redirect()
 * @uses bp_get_root_domain()
 *
 * @return bool False on failure
 */
function bp_activity_action_permalink_router()
{
    global $bp;
    // Not viewing activity
    if (!bp_is_activity_component() || !bp_is_current_action('p')) {
        return false;
    }
    // No activity to display
    if (!bp_action_variable(0) || !is_numeric(bp_action_variable(0))) {
        return false;
    }
    // Get the activity details
    $activity = bp_activity_get_specific(array('activity_ids' => bp_action_variable(0), 'show_hidden' => true));
    // 404 if activity does not exist
    if (empty($activity['activities'][0])) {
        bp_do_404();
        return;
    } else {
        $activity = $activity['activities'][0];
    }
    // Do not redirect at default
    $redirect = false;
    // Redirect based on the type of activity
    if (bp_is_active('groups') && $activity->component == $bp->groups->id) {
        // Activity is a user update
        if (!empty($activity->user_id)) {
            $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/';
            // Activity is something else
        } else {
            // Set redirect to group activity stream
            if ($group = groups_get_group(array('group_id' => $activity->item_id))) {
                $redirect = bp_get_group_permalink($group) . bp_get_activity_slug() . '/' . $activity->id . '/';
            }
        }
        // Set redirect to users' activity stream
    } else {
        $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id;
    }
    // Allow redirect to be filtered
    if (!($redirect = apply_filters_ref_array('bp_activity_permalink_redirect_url', array($redirect, &$activity)))) {
        bp_core_redirect(bp_get_root_domain());
    }
    // Redirect to the actual activity permalink page
    bp_core_redirect($redirect);
}
 function save()
 {
     global $wpdb, $bp;
     $this->id = apply_filters_ref_array('bp_activity_id_before_save', array($this->id, &$this));
     $this->item_id = apply_filters_ref_array('bp_activity_item_id_before_save', array($this->item_id, &$this));
     $this->secondary_item_id = apply_filters_ref_array('bp_activity_secondary_item_id_before_save', array($this->secondary_item_id, &$this));
     $this->user_id = apply_filters_ref_array('bp_activity_user_id_before_save', array($this->user_id, &$this));
     $this->primary_link = apply_filters_ref_array('bp_activity_primary_link_before_save', array($this->primary_link, &$this));
     $this->component = apply_filters_ref_array('bp_activity_component_before_save', array($this->component, &$this));
     $this->type = apply_filters_ref_array('bp_activity_type_before_save', array($this->type, &$this));
     $this->action = apply_filters_ref_array('bp_activity_action_before_save', array($this->action, &$this));
     $this->content = apply_filters_ref_array('bp_activity_content_before_save', array($this->content, &$this));
     $this->date_recorded = apply_filters_ref_array('bp_activity_date_recorded_before_save', array($this->date_recorded, &$this));
     $this->hide_sitewide = apply_filters_ref_array('bp_activity_hide_sitewide_before_save', array($this->hide_sitewide, &$this));
     $this->mptt_left = apply_filters_ref_array('bp_activity_mptt_left_before_save', array($this->mptt_left, &$this));
     $this->mptt_right = apply_filters_ref_array('bp_activity_mptt_right_before_save', array($this->mptt_right, &$this));
     $this->is_spam = apply_filters_ref_array('bp_activity_is_spam_before_save', array($this->is_spam, &$this));
     // Use this, not the filters above
     do_action_ref_array('bp_activity_before_save', array(&$this));
     if (!$this->component || !$this->type) {
         return false;
     }
     if (!$this->primary_link) {
         $this->primary_link = bp_loggedin_user_domain();
     }
     // If we have an existing ID, update the activity item, otherwise insert it.
     if ($this->id) {
         $q = $wpdb->prepare("UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %d, secondary_item_id = %d, hide_sitewide = %d, is_spam = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->is_spam, $this->id);
     } else {
         $q = $wpdb->prepare("INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide, is_spam ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %d, %d, %d, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->is_spam);
     }
     if (false === $wpdb->query($q)) {
         return false;
     }
     // If this is a new activity item, set the $id property
     if (empty($this->id)) {
         $this->id = $wpdb->insert_id;
         // If an existing activity item, prevent any changes to the content generating new @mention notifications.
     } else {
         add_filter('bp_activity_at_name_do_notifications', '__return_false');
     }
     do_action_ref_array('bp_activity_after_save', array(&$this));
     return true;
 }
 /**
  * Get list users.
  * 
  * @since    1.0.0
  * 
  * @return   array
  */
 public function get_users($args = '')
 {
     $defaults = array('max' => false, 'page' => 1, 'per_page' => false, 'sort' => 'DESC', 'meta_query' => false, 'search_terms' => false, 'in' => false, 'filter' => array());
     $r = wp_parse_args($args, $defaults);
     extract($r, EXTR_SKIP);
     // Cache first load list users
     $model_user = DLN_Class_Model_User::get_instance();
     if (1 == (int) $page && empty($max) && empty($search_terms) && empty($filter) && empty($in) && $sort == 'DESC') {
         if (!($user = wp_cache_get('dln_list_users', 'dln_like'))) {
             $args = array('page' => $page, 'per_page' => $per_page, 'max' => $max, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter);
             $user = $model_user->get($args);
             wp_cache_set('dln_list_users', $user, 'dln_like');
         }
     } else {
         $args = array('page' => $page, 'per_page' => $per_page, 'max' => $max, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter);
         $user = $model_user->get($args);
     }
     return apply_filters_ref_array('dln_get_users', array($user, $r));
 }
Beispiel #16
0
 /**
  * 
  * @param \WP_User $user
  * @param string $state  State of CRUD to render for, options 
  * 	include 'read', new', 'edit'
  */
 public static function format(&$user, $state = 'read')
 {
     if (!$user) {
         return $user = null;
     }
     //allow for use with array_walk
     if (func_num_args() > 2) {
         $state = func_get_arg(func_num_args() - 1);
     }
     if (!in_array($state, array('read', 'new', 'edit'))) {
         $state = 'read';
     }
     $data = array('id' => $user->ID, 'id_str' => (string) $user->ID, 'nicename' => $user->data->user_nicename, 'display_name' => $user->data->display_name, 'user_url' => $user->data->user_url);
     if ($state === 'read') {
         $avatar = get_avatar($user->ID);
         preg_match("/src='([^']*)'/i", $avatar, $matches);
         $data = array_merge($data, array('posts_url' => get_author_posts_url($user->ID), 'avatar' => array(array('url' => array_pop($matches), 'width' => 96, 'height' => 96)), 'meta' => (object) array('description' => get_user_meta($user->ID, 'description', true), 'first_name' => get_user_meta($user->ID, 'first_name', true), 'last_name' => get_user_meta($user->ID, 'last_name', true), 'nickname' => get_user_meta($user->ID, 'nickname', true))));
     }
     $user = apply_filters_ref_array('thermal_user_entity', array((object) $data, &$user, $state));
 }
 function save()
 {
     global $wpdb, $bp, $current_user;
     $this->id = apply_filters_ref_array('bp_activity_id_before_save', array($this->id, &$this));
     $this->item_id = apply_filters_ref_array('bp_activity_item_id_before_save', array($this->item_id, &$this));
     $this->secondary_item_id = apply_filters_ref_array('bp_activity_secondary_item_id_before_save', array($this->secondary_item_id, &$this));
     $this->user_id = apply_filters_ref_array('bp_activity_user_id_before_save', array($this->user_id, &$this));
     $this->primary_link = apply_filters_ref_array('bp_activity_primary_link_before_save', array($this->primary_link, &$this));
     $this->component = apply_filters_ref_array('bp_activity_component_before_save', array($this->component, &$this));
     $this->type = apply_filters_ref_array('bp_activity_type_before_save', array($this->type, &$this));
     $this->action = apply_filters_ref_array('bp_activity_action_before_save', array($this->action, &$this));
     $this->content = apply_filters_ref_array('bp_activity_content_before_save', array($this->content, &$this));
     $this->date_recorded = apply_filters_ref_array('bp_activity_date_recorded_before_save', array($this->date_recorded, &$this));
     $this->hide_sitewide = apply_filters_ref_array('bp_activity_hide_sitewide_before_save', array($this->hide_sitewide, &$this));
     $this->mptt_left = apply_filters_ref_array('bp_activity_mptt_left_before_save', array($this->mptt_left, &$this));
     $this->mptt_right = apply_filters_ref_array('bp_activity_mptt_right_before_save', array($this->mptt_right, &$this));
     $this->is_spam = apply_filters_ref_array('bp_activity_is_spam_before_save', array($this->is_spam, &$this));
     // Use this, not the filters above
     do_action_ref_array('bp_activity_before_save', array(&$this));
     if (!$this->component || !$this->type) {
         return false;
     }
     if (!$this->primary_link) {
         $this->primary_link = $bp->loggedin_user->domain;
     }
     // If we have an existing ID, update the activity item, otherwise insert it.
     if ($this->id) {
         $q = $wpdb->prepare("UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %s, secondary_item_id = %s, hide_sitewide = %d, is_spam = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->is_spam, $this->id);
     } else {
         $q = $wpdb->prepare("INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide, is_spam ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->is_spam);
     }
     if (!$wpdb->query($q)) {
         return false;
     }
     if (empty($this->id)) {
         $this->id = $wpdb->insert_id;
     }
     do_action_ref_array('bp_activity_after_save', array(&$this));
     return true;
 }
function groups_screen_group_invites()
{
    $group_id = (int) bp_action_variable(1);
    if (bp_is_action_variable('accept') && is_numeric($group_id)) {
        // Check the nonce
        if (!check_admin_referer('groups_accept_invite')) {
            return false;
        }
        if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) {
            bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Group invite accepted', 'buddypress'));
            // Record this in activity streams
            $group = new BP_Groups_Group($group_id);
            groups_record_activity(array('action' => apply_filters_ref_array('groups_activity_accepted_invite_action', array(sprintf(__('%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink(bp_loggedin_user_id()), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), bp_loggedin_user_id(), &$group)), 'type' => 'joined_group', 'item_id' => $group->id));
        }
        bp_core_redirect(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
    } else {
        if (bp_is_action_variable('reject') && is_numeric($group_id)) {
            // Check the nonce
            if (!check_admin_referer('groups_reject_invite')) {
                return false;
            }
            if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) {
                bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Group invite rejected', 'buddypress'));
            }
            bp_core_redirect(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
        }
    }
    // Remove notifications
    bp_core_delete_notifications_by_type(bp_loggedin_user_id(), 'groups', 'group_invite');
    do_action('groups_screen_group_invites', $group_id);
    bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home'));
}
Beispiel #19
0
 /**
  * Generates SQL clauses to be appended to a main query.
  *
  * @since 3.2.0
  * @access public
  *
  * @param string $type              Type of meta, eg 'user', 'post'.
  * @param string $primary_table     Database table where the object being filtered is stored (eg wp_users).
  * @param string $primary_id_column ID column for the filtered object in $primary_table.
  * @param object $context           Optional. The main query object.
  * @return array {
  *     Array containing JOIN and WHERE SQL clauses to append to the main query.
  *
  *     @type string $join  SQL fragment to append to the main JOIN clause.
  *     @type string $where SQL fragment to append to the main WHERE clause.
  * }
  */
 public function get_sql($type, $primary_table, $primary_id_column, $context = null)
 {
     if (!($meta_table = _get_meta_table($type))) {
         return false;
     }
     $this->meta_table = $meta_table;
     $this->meta_id_column = sanitize_key($type . '_id');
     $this->primary_table = $primary_table;
     $this->primary_id_column = $primary_id_column;
     $sql = $this->get_sql_clauses();
     /*
      * If any JOINs are LEFT JOINs (as in the case of NOT EXISTS), then all JOINs should
      * be LEFT. Otherwise posts with no metadata will be excluded from results.
      */
     if (false !== strpos($sql['join'], 'LEFT JOIN')) {
         $sql['join'] = str_replace('INNER JOIN', 'LEFT JOIN', $sql['join']);
     }
     /**
      * Filter the meta query's generated SQL.
      *
      * @since 3.1.0
      *
      * @param array $args {
      *     An array of meta query SQL arguments.
      *
      *     @type array  $clauses           Array containing the query's JOIN and WHERE clauses.
      *     @type array  $queries           Array of meta queries.
      *     @type string $type              Type of meta.
      *     @type string $primary_table     Primary table.
      *     @type string $primary_id_column Primary column ID.
      *     @type object $context           The main query object.
      * }
      */
     return apply_filters_ref_array('get_meta_sql', array($sql, $this->queries, $type, $primary_table, $primary_id_column, $context));
 }
 /**
  * Markup for the Last Active column.
  *
  * @since 1.7.0
  *
  * @param array $item Information about the current row.
  */
 public function column_last_active($item = array())
 {
     $last_active = groups_get_groupmeta($item['id'], 'last_activity');
     /**
      * Filters the markup for the Last Active column.
      *
      * @since 1.7.0
      *
      * @param string $last_active Markup for the Last Active column.
      * @parma array  $item        The current group item in the loop.
      */
     echo apply_filters_ref_array('bp_groups_admin_get_group_last_active', array($last_active, $item));
 }
 /**
  * Used internally to get a list of comment IDs matching the query vars.
  *
  * @since 4.4.0
  * @access protected
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  */
 protected function get_comment_ids()
 {
     global $wpdb;
     // Assemble clauses related to 'comment_approved'.
     $approved_clauses = array();
     // 'status' accepts an array or a comma-separated string.
     $status_clauses = array();
     $statuses = $this->query_vars['status'];
     if (!is_array($statuses)) {
         $statuses = preg_split('/[\\s,]+/', $statuses);
     }
     // 'any' overrides other statuses.
     if (!in_array('any', $statuses)) {
         foreach ($statuses as $status) {
             switch ($status) {
                 case 'hold':
                     $status_clauses[] = "comment_approved = '0'";
                     break;
                 case 'approve':
                     $status_clauses[] = "comment_approved = '1'";
                     break;
                 case 'all':
                 case '':
                     $status_clauses[] = "( comment_approved = '0' OR comment_approved = '1' )";
                     break;
                 default:
                     $status_clauses[] = $wpdb->prepare("comment_approved = %s", $status);
                     break;
             }
         }
         if (!empty($status_clauses)) {
             $approved_clauses[] = '( ' . implode(' OR ', $status_clauses) . ' )';
         }
     }
     // User IDs or emails whose unapproved comments are included, regardless of $status.
     if (!empty($this->query_vars['include_unapproved'])) {
         $include_unapproved = $this->query_vars['include_unapproved'];
         // Accepts arrays or comma-separated strings.
         if (!is_array($include_unapproved)) {
             $include_unapproved = preg_split('/[\\s,]+/', $include_unapproved);
         }
         $unapproved_ids = $unapproved_emails = array();
         foreach ($include_unapproved as $unapproved_identifier) {
             // Numeric values are assumed to be user ids.
             if (is_numeric($unapproved_identifier)) {
                 $approved_clauses[] = $wpdb->prepare("( user_id = %d AND comment_approved = '0' )", $unapproved_identifier);
                 // Otherwise we match against email addresses.
             } else {
                 $approved_clauses[] = $wpdb->prepare("( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier);
             }
         }
     }
     // Collapse comment_approved clauses into a single OR-separated clause.
     if (!empty($approved_clauses)) {
         if (1 === count($approved_clauses)) {
             $this->sql_clauses['where']['approved'] = $approved_clauses[0];
         } else {
             $this->sql_clauses['where']['approved'] = '( ' . implode(' OR ', $approved_clauses) . ' )';
         }
     }
     $order = 'ASC' == strtoupper($this->query_vars['order']) ? 'ASC' : 'DESC';
     // Disable ORDER BY with 'none', an empty array, or boolean false.
     if (in_array($this->query_vars['orderby'], array('none', array(), false), true)) {
         $orderby = '';
     } elseif (!empty($this->query_vars['orderby'])) {
         $ordersby = is_array($this->query_vars['orderby']) ? $this->query_vars['orderby'] : preg_split('/[,\\s]/', $this->query_vars['orderby']);
         $orderby_array = array();
         $found_orderby_comment_ID = false;
         foreach ($ordersby as $_key => $_value) {
             if (!$_value) {
                 continue;
             }
             if (is_int($_key)) {
                 $_orderby = $_value;
                 $_order = $order;
             } else {
                 $_orderby = $_key;
                 $_order = $_value;
             }
             if (!$found_orderby_comment_ID && in_array($_orderby, array('comment_ID', 'comment__in'))) {
                 $found_orderby_comment_ID = true;
             }
             $parsed = $this->parse_orderby($_orderby);
             if (!$parsed) {
                 continue;
             }
             if ('comment__in' === $_orderby) {
                 $orderby_array[] = $parsed;
                 continue;
             }
             $orderby_array[] = $parsed . ' ' . $this->parse_order($_order);
         }
         // If no valid clauses were found, order by comment_date_gmt.
         if (empty($orderby_array)) {
             $orderby_array[] = "{$wpdb->comments}.comment_date_gmt {$order}";
         }
         // To ensure determinate sorting, always include a comment_ID clause.
         if (!$found_orderby_comment_ID) {
             $comment_ID_order = '';
             // Inherit order from comment_date or comment_date_gmt, if available.
             foreach ($orderby_array as $orderby_clause) {
                 if (preg_match('/comment_date(?:_gmt)*\\ (ASC|DESC)/', $orderby_clause, $match)) {
                     $comment_ID_order = $match[1];
                     break;
                 }
             }
             // If no date-related order is available, use the date from the first available clause.
             if (!$comment_ID_order) {
                 foreach ($orderby_array as $orderby_clause) {
                     if (false !== strpos('ASC', $orderby_clause)) {
                         $comment_ID_order = 'ASC';
                     } else {
                         $comment_ID_order = 'DESC';
                     }
                     break;
                 }
             }
             // Default to DESC.
             if (!$comment_ID_order) {
                 $comment_ID_order = 'DESC';
             }
             $orderby_array[] = "{$wpdb->comments}.comment_ID {$comment_ID_order}";
         }
         $orderby = implode(', ', $orderby_array);
     } else {
         $orderby = "{$wpdb->comments}.comment_date_gmt {$order}";
     }
     $number = absint($this->query_vars['number']);
     $offset = absint($this->query_vars['offset']);
     if (!empty($number)) {
         if ($offset) {
             $limits = 'LIMIT ' . $offset . ',' . $number;
         } else {
             $limits = 'LIMIT ' . $number;
         }
     }
     if ($this->query_vars['count']) {
         $fields = 'COUNT(*)';
     } else {
         $fields = "{$wpdb->comments}.comment_ID";
     }
     $post_id = absint($this->query_vars['post_id']);
     if (!empty($post_id)) {
         $this->sql_clauses['where']['post_id'] = $wpdb->prepare('comment_post_ID = %d', $post_id);
     }
     // Parse comment IDs for an IN clause.
     if (!empty($this->query_vars['comment__in'])) {
         $this->sql_clauses['where']['comment__in'] = "{$wpdb->comments}.comment_ID IN ( " . implode(',', wp_parse_id_list($this->query_vars['comment__in'])) . ' )';
     }
     // Parse comment IDs for a NOT IN clause.
     if (!empty($this->query_vars['comment__not_in'])) {
         $this->sql_clauses['where']['comment__not_in'] = "{$wpdb->comments}.comment_ID NOT IN ( " . implode(',', wp_parse_id_list($this->query_vars['comment__not_in'])) . ' )';
     }
     // Parse comment parent IDs for an IN clause.
     if (!empty($this->query_vars['parent__in'])) {
         $this->sql_clauses['where']['parent__in'] = 'comment_parent IN ( ' . implode(',', wp_parse_id_list($this->query_vars['parent__in'])) . ' )';
     }
     // Parse comment parent IDs for a NOT IN clause.
     if (!empty($this->query_vars['parent__not_in'])) {
         $this->sql_clauses['where']['parent__not_in'] = 'comment_parent NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['parent__not_in'])) . ' )';
     }
     // Parse comment post IDs for an IN clause.
     if (!empty($this->query_vars['post__in'])) {
         $this->sql_clauses['where']['post__in'] = 'comment_post_ID IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post__in'])) . ' )';
     }
     // Parse comment post IDs for a NOT IN clause.
     if (!empty($this->query_vars['post__not_in'])) {
         $this->sql_clauses['where']['post__not_in'] = 'comment_post_ID NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post__not_in'])) . ' )';
     }
     if ('' !== $this->query_vars['author_email']) {
         $this->sql_clauses['where']['author_email'] = $wpdb->prepare('comment_author_email = %s', $this->query_vars['author_email']);
     }
     if ('' !== $this->query_vars['author_url']) {
         $this->sql_clauses['where']['author_url'] = $wpdb->prepare('comment_author_url = %s', $this->query_vars['author_url']);
     }
     if ('' !== $this->query_vars['karma']) {
         $this->sql_clauses['where']['karma'] = $wpdb->prepare('comment_karma = %d', $this->query_vars['karma']);
     }
     // Filtering by comment_type: 'type', 'type__in', 'type__not_in'.
     $raw_types = array('IN' => array_merge((array) $this->query_vars['type'], (array) $this->query_vars['type__in']), 'NOT IN' => (array) $this->query_vars['type__not_in']);
     $comment_types = array();
     foreach ($raw_types as $operator => $_raw_types) {
         $_raw_types = array_unique($_raw_types);
         foreach ($_raw_types as $type) {
             switch ($type) {
                 // An empty translates to 'all', for backward compatibility
                 case '':
                 case 'all':
                     break;
                 case 'comment':
                 case 'comments':
                     $comment_types[$operator][] = "''";
                     break;
                 case 'pings':
                     $comment_types[$operator][] = "'pingback'";
                     $comment_types[$operator][] = "'trackback'";
                     break;
                 default:
                     $comment_types[$operator][] = $wpdb->prepare('%s', $type);
                     break;
             }
         }
         if (!empty($comment_types[$operator])) {
             $types_sql = implode(', ', $comment_types[$operator]);
             $this->sql_clauses['where']['comment_type__' . strtolower(str_replace(' ', '_', $operator))] = "comment_type {$operator} ({$types_sql})";
         }
     }
     if ($this->query_vars['hierarchical'] && !$this->query_vars['parent']) {
         $this->query_vars['parent'] = 0;
     }
     if ('' !== $this->query_vars['parent']) {
         $this->sql_clauses['where']['parent'] = $wpdb->prepare('comment_parent = %d', $this->query_vars['parent']);
     }
     if (is_array($this->query_vars['user_id'])) {
         $this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode(',', array_map('absint', $this->query_vars['user_id'])) . ')';
     } elseif ('' !== $this->query_vars['user_id']) {
         $this->sql_clauses['where']['user_id'] = $wpdb->prepare('user_id = %d', $this->query_vars['user_id']);
     }
     // Falsy search strings are ignored.
     if (strlen($this->query_vars['search'])) {
         $search_sql = $this->get_search_sql($this->query_vars['search'], array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content'));
         // Strip leading 'AND'.
         $this->sql_clauses['where']['search'] = preg_replace('/^\\s*AND\\s*/', '', $search_sql);
     }
     // If any post-related query vars are passed, join the posts table.
     $join_posts_table = false;
     $plucked = wp_array_slice_assoc($this->query_vars, array('post_author', 'post_name', 'post_parent'));
     $post_fields = array_filter($plucked);
     if (!empty($post_fields)) {
         $join_posts_table = true;
         foreach ($post_fields as $field_name => $field_value) {
             // $field_value may be an array.
             $esses = array_fill(0, count((array) $field_value), '%s');
             $this->sql_clauses['where'][$field_name] = $wpdb->prepare(" {$wpdb->posts}.{$field_name} IN (" . implode(',', $esses) . ')', $field_value);
         }
     }
     // 'post_status' and 'post_type' are handled separately, due to the specialized behavior of 'any'.
     foreach (array('post_status', 'post_type') as $field_name) {
         $q_values = array();
         if (!empty($this->query_vars[$field_name])) {
             $q_values = $this->query_vars[$field_name];
             if (!is_array($q_values)) {
                 $q_values = explode(',', $q_values);
             }
             // 'any' will cause the query var to be ignored.
             if (in_array('any', $q_values, true) || empty($q_values)) {
                 continue;
             }
             $join_posts_table = true;
             $esses = array_fill(0, count($q_values), '%s');
             $this->sql_clauses['where'][$field_name] = $wpdb->prepare(" {$wpdb->posts}.{$field_name} IN (" . implode(',', $esses) . ")", $q_values);
         }
     }
     // Comment author IDs for an IN clause.
     if (!empty($this->query_vars['author__in'])) {
         $this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode(',', wp_parse_id_list($this->query_vars['author__in'])) . ' )';
     }
     // Comment author IDs for a NOT IN clause.
     if (!empty($this->query_vars['author__not_in'])) {
         $this->sql_clauses['where']['author__not_in'] = 'user_id NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['author__not_in'])) . ' )';
     }
     // Post author IDs for an IN clause.
     if (!empty($this->query_vars['post_author__in'])) {
         $join_posts_table = true;
         $this->sql_clauses['where']['post_author__in'] = 'post_author IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post_author__in'])) . ' )';
     }
     // Post author IDs for a NOT IN clause.
     if (!empty($this->query_vars['post_author__not_in'])) {
         $join_posts_table = true;
         $this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post_author__not_in'])) . ' )';
     }
     $join = '';
     if ($join_posts_table) {
         $join .= "JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID";
     }
     if (!empty($this->meta_query_clauses)) {
         $join .= $this->meta_query_clauses['join'];
         // Strip leading 'AND'.
         $this->sql_clauses['where']['meta_query'] = preg_replace('/^\\s*AND\\s*/', '', $this->meta_query_clauses['where']);
         if (!$this->query_vars['count']) {
             $groupby = "{$wpdb->comments}.comment_ID";
         }
     }
     if (!empty($this->query_vars['date_query']) && is_array($this->query_vars['date_query'])) {
         $this->date_query = new WP_Date_Query($this->query_vars['date_query'], 'comment_date');
         $this->sql_clauses['where']['date_query'] = preg_replace('/^\\s*AND\\s*/', '', $this->date_query->get_sql());
     }
     $where = implode(' AND ', $this->sql_clauses['where']);
     $pieces = array('fields', 'join', 'where', 'orderby', 'limits', 'groupby');
     /**
      * Filter the comment query clauses.
      *
      * @since 3.1.0
      *
      * @param array            $pieces A compacted array of comment query clauses.
      * @param WP_Comment_Query &$this  Current instance of WP_Comment_Query, passed by reference.
      */
     $clauses = apply_filters_ref_array('comments_clauses', array(compact($pieces), &$this));
     $fields = isset($clauses['fields']) ? $clauses['fields'] : '';
     $join = isset($clauses['join']) ? $clauses['join'] : '';
     $where = isset($clauses['where']) ? $clauses['where'] : '';
     $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : '';
     $limits = isset($clauses['limits']) ? $clauses['limits'] : '';
     $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : '';
     $this->filtered_where_clause = $where;
     if ($where) {
         $where = 'WHERE ' . $where;
     }
     if ($groupby) {
         $groupby = 'GROUP BY ' . $groupby;
     }
     if ($orderby) {
         $orderby = "ORDER BY {$orderby}";
     }
     $found_rows = '';
     if (!$this->query_vars['no_found_rows']) {
         $found_rows = 'SQL_CALC_FOUND_ROWS';
     }
     $this->sql_clauses['select'] = "SELECT {$found_rows} {$fields}";
     $this->sql_clauses['from'] = "FROM {$wpdb->comments} {$join}";
     $this->sql_clauses['groupby'] = $groupby;
     $this->sql_clauses['orderby'] = $orderby;
     $this->sql_clauses['limits'] = $limits;
     $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
     if ($this->query_vars['count']) {
         return intval($wpdb->get_var($this->request));
     } else {
         $comment_ids = $wpdb->get_col($this->request);
         return array_map('intval', $comment_ids);
     }
 }
/**
 * Get a collection of groups, based on the parameters passed.
 *
 * @param array|string $args {
 *     Array of arguments. Supports all arguments of
 *     {@link BP_Groups_Group::get()}. Where the default values differ, they
 *     have been described here.
 *     @type int $per_page Default: 20.
 *     @type int $page Default: 1.
 * }
 * @return array See {@link BP_Groups_Group::get()}.
 */
function groups_get_groups($args = '')
{
    $defaults = array('type' => false, 'order' => 'DESC', 'orderby' => 'date_created', 'user_id' => false, 'include' => false, 'exclude' => false, 'search_terms' => false, 'meta_query' => false, 'show_hidden' => false, 'per_page' => 20, 'page' => 1, 'populate_extras' => true, 'update_meta_cache' => true);
    $r = wp_parse_args($args, $defaults);
    $groups = BP_Groups_Group::get(array('type' => $r['type'], 'user_id' => $r['user_id'], 'include' => $r['include'], 'exclude' => $r['exclude'], 'search_terms' => $r['search_terms'], 'meta_query' => $r['meta_query'], 'show_hidden' => $r['show_hidden'], 'per_page' => $r['per_page'], 'page' => $r['page'], 'populate_extras' => $r['populate_extras'], 'update_meta_cache' => $r['update_meta_cache'], 'order' => $r['order'], 'orderby' => $r['orderby']));
    /**
     * Filters the collection of groups based on parsed parameters.
     *
     * @since 1.2.0
     *
     * @param BP_Groups_Group $groups Object of found groups based on parameters.
     *                                Passed by reference.
     * @param array           $r      Array of parsed arguments used for group query.
     *                                Passed by reference.
     */
    return apply_filters_ref_array('groups_get_groups', array(&$groups, &$r));
}
 /**
  * Locates specified template
  *
  * @since 6.0
  * @access public
  *
  * @param string|array $template_names The template(s) to locate
  * @param string $template_path Directory of default template
  * @param bool $load If true, the template will be included if found
  * @param array $args Array of extra variables to make available to template
  * @return string|bool Template path if found, false if not
  */
 function get_template($template_names, $template_path = '', $load = true, $args = array())
 {
     // Shothand reference to this
     $template =& $this;
     // Shorthand reference to $theme_my_login
     $theme_my_login =& $GLOBALS['theme_my_login'];
     // Easy access to current user
     $current_user = wp_get_current_user();
     if (empty($template_path)) {
         $template_path = TML_ABSPATH . '/templates';
     }
     extract(apply_filters_ref_array('tml_template_args', array($args, &$this)));
     if (!is_array($template_names)) {
         $template_names = array($template_names);
     }
     if (!($found_template = locate_template($template_names))) {
         foreach ($template_names as $template_name) {
             if (file_exists(rtrim($template_path, '/') . '/' . $template_name)) {
                 $found_template = rtrim($template_path, '/') . '/' . $template_name;
                 break;
             }
         }
     }
     $found_template = apply_filters_ref_array('tml_template', array($found_template, $template_names, $template_path, &$this));
     if ($load && $found_template) {
         include $found_template;
     }
     return $found_template;
 }
 /**
  * Set up the amount of found posts and the number of pages (if limit clause was used)
  * for the current query.
  *
  * @since 3.5.0
  * @access private
  *
  * @param array  $q      Query variables.
  * @param string $limits LIMIT clauses of the query.
  */
 private function set_found_posts($q, $limits)
 {
     // Bail if posts is an empty array. Continue if posts is an empty string,
     // null, or false to accommodate caching plugins that fill posts later.
     if ($q['no_found_rows'] || is_array($this->posts) && !$this->posts) {
         return;
     }
     if (!empty($limits)) {
         /**
          * Filters the query to run for retrieving the found posts.
          *
          * @since 2.1.0
          *
          * @param string   $found_posts The query to run to find the found posts.
          * @param WP_Query &$this       The WP_Query instance (passed by reference).
          */
         $this->found_posts = $this->db->get_var(apply_filters_ref_array('found_posts_query', array('SELECT FOUND_ROWS()', &$this)));
     } else {
         $this->found_posts = count($this->posts);
     }
     /**
      * Filters the number of found posts for the query.
      *
      * @since 2.1.0
      *
      * @param int      $found_posts The number of posts found.
      * @param WP_Query &$this       The WP_Query instance (passed by reference).
      */
     $this->found_posts = apply_filters_ref_array('found_posts', array($this->found_posts, &$this));
     if (!empty($limits)) {
         $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
     }
 }
    /**
    * Display or return the thumbnail view
    * @param : thumbnail model (img, width, height), layout value, echo bool
    * @package Customizr
    * @since Customizr 3.0.10
    */
    function tc_render_thumb_view( $_thumb_model , $layout = 'span3', $_echo = true ) {
      if ( empty( $_thumb_model ) )
        return;
      //extract "tc_thumb" , "tc_thumb_height" , "tc_thumb_width"
      extract( $_thumb_model );
      $thumb_img        = ! isset( $_thumb_model) ? false : $tc_thumb;
      $thumb_img        = apply_filters( 'tc_post_thumb_img', $thumb_img, TC_utils::tc_id() );
      if ( ! $thumb_img )
        return;

      //handles the case when the image dimensions are too small
      $thumb_size       = apply_filters( 'tc_thumb_size' , TC_init::$instance -> tc_thumb_size, TC_utils::tc_id()  );
      $no_effect_class  = ( isset($tc_thumb) && isset($tc_thumb_height) && ( $tc_thumb_height < $thumb_size['height']) ) ? 'no-effect' : '';
      $no_effect_class  = ( esc_attr( TC_utils::$inst->tc_opt( 'tc_center_img') ) || ! isset($tc_thumb) || empty($tc_thumb_height) || empty($tc_thumb_width) ) ? '' : $no_effect_class;

      //default hover effect
      $thumb_wrapper    = sprintf('<div class="%5$s %1$s"><div class="round-div"></div><a class="round-div %1$s" href="%2$s" title="%3$s"></a>%4$s</div>',
                                    implode( " ", apply_filters( 'tc_thumbnail_link_class', array( $no_effect_class ) ) ),
                                    get_permalink( get_the_ID() ),
                                    esc_attr( strip_tags( get_the_title( get_the_ID() ) ) ),
                                    $thumb_img,
                                    implode( " ", apply_filters( 'tc_thumb_wrapper_class', array('thumb-wrapper') ) )
      );

      $thumb_wrapper    = apply_filters_ref_array( 'tc_post_thumb_wrapper', array( $thumb_wrapper, $thumb_img, TC_utils::tc_id() ) );

      //cache the thumbnail view
      $html             = sprintf('<section class="tc-thumbnail %1$s">%2$s</section>',
        apply_filters( 'tc_post_thumb_class', $layout ),
        $thumb_wrapper
      );
      $html = apply_filters_ref_array( 'tc_render_thumb_view', array( $html, $_thumb_model, $layout ) );
      if ( ! $_echo )
        return $html;
      echo $html;
    }//end of function
 /**
  * Check if this data is for a valid field.
  *
  * @global object $wpdb
  * @global array $bp
  * @return bool
  */
 public function is_valid_field()
 {
     global $wpdb, $bp;
     $retval = $wpdb->get_row($wpdb->prepare("SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id));
     return apply_filters_ref_array('xprofile_data_is_valid_field', array((bool) $retval, $this));
 }
Beispiel #27
0
 /**
  * Get a list of comments matching the query vars.
  *
  * @since 0.0.1
  * @access public
  *
  * @global hqdb $hqdb HiveQueen database abstraction object.
  *
  * @return int|array The list of comments.
  */
 public function get_comments()
 {
     global $hqdb;
     $groupby = '';
     $this->parse_query();
     // Parse meta query
     $this->meta_query = new HQ_Meta_Query();
     $this->meta_query->parse_query_vars($this->query_vars);
     /**
      * Fires before comments are retrieved.
      *
      * @since 0.0.1
      *
      * @param HQ_Comment_Query &$this Current instance of HQ_Comment_Query, passed by reference.
      */
     do_action_ref_array('pre_get_comments', array(&$this));
     // Reparse query vars, in case they were modified in a 'pre_get_comments' callback.
     $this->meta_query->parse_query_vars($this->query_vars);
     if (!empty($this->meta_query->queries)) {
         $meta_query_clauses = $this->meta_query->get_sql('comment', $hqdb->comments, 'comment_ID', $this);
     }
     // $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
     $key = md5(serialize(hq_array_slice_assoc($this->query_vars, array_keys($this->query_var_defaults))));
     $last_changed = hq_cache_get('last_changed', 'comment');
     if (!$last_changed) {
         $last_changed = microtime();
         hq_cache_set('last_changed', $last_changed, 'comment');
     }
     $cache_key = "get_comments:{$key}:{$last_changed}";
     if ($cache = hq_cache_get($cache_key, 'comment')) {
         $this->comments = $cache;
         return $this->comments;
     }
     $where = array();
     // Assemble clauses related to 'comment_approved'.
     $approved_clauses = array();
     // 'status' accepts an array or a comma-separated string.
     $status_clauses = array();
     $statuses = $this->query_vars['status'];
     if (!is_array($statuses)) {
         $statuses = preg_split('/[\\s,]+/', $statuses);
     }
     // 'any' overrides other statuses.
     if (!in_array('any', $statuses)) {
         foreach ($statuses as $status) {
             switch ($status) {
                 case 'hold':
                     $status_clauses[] = "comment_approved = '0'";
                     break;
                 case 'approve':
                     $status_clauses[] = "comment_approved = '1'";
                     break;
                 case 'all':
                 case '':
                     $status_clauses[] = "( comment_approved = '0' OR comment_approved = '1' )";
                     break;
                 default:
                     $status_clauses[] = $hqdb->prepare("comment_approved = %s", $status);
                     break;
             }
         }
         if (!empty($status_clauses)) {
             $approved_clauses[] = '( ' . implode(' OR ', $status_clauses) . ' )';
         }
     }
     // User IDs or emails whose unapproved comments are included, regardless of $status.
     if (!empty($this->query_vars['include_unapproved'])) {
         $include_unapproved = $this->query_vars['include_unapproved'];
         // Accepts arrays or comma-separated strings.
         if (!is_array($include_unapproved)) {
             $include_unapproved = preg_split('/[\\s,]+/', $include_unapproved);
         }
         $unapproved_ids = $unapproved_emails = array();
         foreach ($include_unapproved as $unapproved_identifier) {
             // Numeric values are assumed to be user ids.
             if (is_numeric($unapproved_identifier)) {
                 $approved_clauses[] = $hqdb->prepare("( user_id = %d AND comment_approved = '0' )", $unapproved_identifier);
                 // Otherwise we match against email addresses.
             } else {
                 $approved_clauses[] = $hqdb->prepare("( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier);
             }
         }
     }
     // Collapse comment_approved clauses into a single OR-separated clause.
     if (!empty($approved_clauses)) {
         if (1 === count($approved_clauses)) {
             $where[] = $approved_clauses[0];
         } else {
             $where[] = '( ' . implode(' OR ', $approved_clauses) . ' )';
         }
     }
     $order = 'ASC' == strtoupper($this->query_vars['order']) ? 'ASC' : 'DESC';
     // Disable ORDER BY with 'none', an empty array, or boolean false.
     if (in_array($this->query_vars['orderby'], array('none', array(), false), true)) {
         $orderby = '';
     } elseif (!empty($this->query_vars['orderby'])) {
         $ordersby = is_array($this->query_vars['orderby']) ? $this->query_vars['orderby'] : preg_split('/[,\\s]/', $this->query_vars['orderby']);
         $orderby_array = array();
         $found_orderby_comment_ID = false;
         foreach ($ordersby as $_key => $_value) {
             if (!$_value) {
                 continue;
             }
             if (is_int($_key)) {
                 $_orderby = $_value;
                 $_order = $order;
             } else {
                 $_orderby = $_key;
                 $_order = $_value;
             }
             if (!$found_orderby_comment_ID && 'comment_ID' === $_orderby) {
                 $found_orderby_comment_ID = true;
             }
             $parsed = $this->parse_orderby($_orderby);
             if (!$parsed) {
                 continue;
             }
             $orderby_array[] = $parsed . ' ' . $this->parse_order($_order);
         }
         // If no valid clauses were found, order by comment_date_gmt.
         if (empty($orderby_array)) {
             $orderby_array[] = "{$hqdb->comments}.comment_date_gmt {$order}";
         }
         // To ensure determinate sorting, always include a comment_ID clause.
         if (!$found_orderby_comment_ID) {
             $comment_ID_order = '';
             // Inherit order from comment_date or comment_date_gmt, if available.
             foreach ($orderby_array as $orderby_clause) {
                 if (preg_match('/comment_date(?:_gmt)*\\ (ASC|DESC)/', $orderby_clause, $match)) {
                     $comment_ID_order = $match[1];
                     break;
                 }
             }
             // If no date-related order is available, use the date from the first available clause.
             if (!$comment_ID_order) {
                 foreach ($orderby_array as $orderby_clause) {
                     if (false !== strpos('ASC', $orderby_clause)) {
                         $comment_ID_order = 'ASC';
                     } else {
                         $comment_ID_order = 'DESC';
                     }
                     break;
                 }
             }
             // Default to DESC.
             if (!$comment_ID_order) {
                 $comment_ID_order = 'DESC';
             }
             $orderby_array[] = "{$hqdb->comments}.comment_ID {$comment_ID_order}";
         }
         $orderby = implode(', ', $orderby_array);
     } else {
         $orderby = "{$hqdb->comments}.comment_date_gmt {$order}";
     }
     $number = absint($this->query_vars['number']);
     $offset = absint($this->query_vars['offset']);
     if (!empty($number)) {
         if ($offset) {
             $limits = 'LIMIT ' . $offset . ',' . $number;
         } else {
             $limits = 'LIMIT ' . $number;
         }
     } else {
         $limits = '';
     }
     if ($this->query_vars['count']) {
         $fields = 'COUNT(*)';
     } else {
         switch (strtolower($this->query_vars['fields'])) {
             case 'ids':
                 $fields = "{$hqdb->comments}.comment_ID";
                 break;
             default:
                 $fields = "*";
                 break;
         }
     }
     $join = '';
     $post_id = absint($this->query_vars['post_id']);
     if (!empty($post_id)) {
         $where[] = $hqdb->prepare('comment_post_ID = %d', $post_id);
     }
     // Parse comment IDs for an IN clause.
     if (!empty($this->query_vars['comment__in'])) {
         $where[] = "{$hqdb->comments}.comment_ID IN ( " . implode(',', hq_parse_id_list($this->query_vars['comment__in'])) . ' )';
     }
     // Parse comment IDs for a NOT IN clause.
     if (!empty($this->query_vars['comment__not_in'])) {
         $where[] = "{$hqdb->comments}.comment_ID NOT IN ( " . implode(',', hq_parse_id_list($this->query_vars['comment__not_in'])) . ' )';
     }
     // Parse comment post IDs for an IN clause.
     if (!empty($this->query_vars['post__in'])) {
         $where[] = 'comment_post_ID IN ( ' . implode(',', hq_parse_id_list($this->query_vars['post__in'])) . ' )';
     }
     // Parse comment post IDs for a NOT IN clause.
     if (!empty($this->query_vars['post__not_in'])) {
         $where[] = 'comment_post_ID NOT IN ( ' . implode(',', hq_parse_id_list($this->query_vars['post__not_in'])) . ' )';
     }
     if ('' !== $this->query_vars['author_email']) {
         $where[] = $hqdb->prepare('comment_author_email = %s', $this->query_vars['author_email']);
     }
     if ('' !== $this->query_vars['karma']) {
         $where[] = $hqdb->prepare('comment_karma = %d', $this->query_vars['karma']);
     }
     // Filtering by comment_type: 'type', 'type__in', 'type__not_in'.
     $raw_types = array('IN' => array_merge((array) $this->query_vars['type'], (array) $this->query_vars['type__in']), 'NOT IN' => (array) $this->query_vars['type__not_in']);
     $comment_types = array();
     foreach ($raw_types as $operator => $_raw_types) {
         $_raw_types = array_unique($_raw_types);
         foreach ($_raw_types as $type) {
             switch ($type) {
                 // An empty translates to 'all', for backward compatibility
                 case '':
                 case 'all':
                     break;
                 case 'comment':
                 case 'comments':
                     $comment_types[$operator][] = "''";
                     break;
                 case 'pings':
                     $comment_types[$operator][] = "'pingback'";
                     $comment_types[$operator][] = "'trackback'";
                     break;
                 default:
                     $comment_types[$operator][] = $hqdb->prepare('%s', $type);
                     break;
             }
         }
         if (!empty($comment_types[$operator])) {
             $types_sql = implode(', ', $comment_types[$operator]);
             $where[] = "comment_type {$operator} ({$types_sql})";
         }
     }
     if ('' !== $this->query_vars['parent']) {
         $where[] = $hqdb->prepare('comment_parent = %d', $this->query_vars['parent']);
     }
     if (is_array($this->query_vars['user_id'])) {
         $where[] = 'user_id IN (' . implode(',', array_map('absint', $this->query_vars['user_id'])) . ')';
     } elseif ('' !== $this->query_vars['user_id']) {
         $where[] = $hqdb->prepare('user_id = %d', $this->query_vars['user_id']);
     }
     if ('' !== $this->query_vars['search']) {
         $search_sql = $this->get_search_sql($this->query_vars['search'], array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content'));
         // Strip leading 'AND'.
         $where[] = preg_replace('/^\\s*AND\\s*/', '', $search_sql);
     }
     // If any post-related query vars are passed, join the posts table.
     $join_posts_table = false;
     $plucked = hq_array_slice_assoc($this->query_vars, array('post_author', 'post_name', 'post_parent', 'post_status', 'post_type'));
     $post_fields = array_filter($plucked);
     if (!empty($post_fields)) {
         $join_posts_table = true;
         foreach ($post_fields as $field_name => $field_value) {
             // $field_value may be an array.
             $esses = array_fill(0, count((array) $field_value), '%s');
             $where[] = $hqdb->prepare(" {$hqdb->posts}.{$field_name} IN (" . implode(',', $esses) . ')', $field_value);
         }
     }
     // Comment author IDs for an IN clause.
     if (!empty($this->query_vars['author__in'])) {
         $where[] = 'user_id IN ( ' . implode(',', hq_parse_id_list($this->query_vars['author__in'])) . ' )';
     }
     // Comment author IDs for a NOT IN clause.
     if (!empty($this->query_vars['author__not_in'])) {
         $where[] = 'user_id NOT IN ( ' . implode(',', hq_parse_id_list($this->query_vars['author__not_in'])) . ' )';
     }
     // Post author IDs for an IN clause.
     if (!empty($this->query_vars['post_author__in'])) {
         $join_posts_table = true;
         $where[] = 'post_author IN ( ' . implode(',', hq_parse_id_list($this->query_vars['post_author__in'])) . ' )';
     }
     // Post author IDs for a NOT IN clause.
     if (!empty($this->query_vars['post_author__not_in'])) {
         $join_posts_table = true;
         $where[] = 'post_author NOT IN ( ' . implode(',', hq_parse_id_list($this->query_vars['post_author__not_in'])) . ' )';
     }
     if ($join_posts_table) {
         $join = "JOIN {$hqdb->posts} ON {$hqdb->posts}.ID = {$hqdb->comments}.comment_post_ID";
     }
     if (!empty($meta_query_clauses)) {
         $join .= $meta_query_clauses['join'];
         // Strip leading 'AND'.
         $where[] = preg_replace('/^\\s*AND\\s*/', '', $meta_query_clauses['where']);
         if (!$this->query_vars['count']) {
             $groupby = "{$hqdb->comments}.comment_ID";
         }
     }
     $date_query = $this->query_vars['date_query'];
     if (!empty($date_query) && is_array($date_query)) {
         $date_query_object = new HQ_Date_Query($date_query, 'comment_date');
         $where[] = preg_replace('/^\\s*AND\\s*/', '', $date_query_object->get_sql());
     }
     $where = implode(' AND ', $where);
     $pieces = array('fields', 'join', 'where', 'orderby', 'limits', 'groupby');
     /**
      * Filter the comment query clauses.
      *
      * @since 0.0.1
      *
      * @param array            $pieces A compacted array of comment query clauses.
      * @param HQ_Comment_Query &$this  Current instance of HQ_Comment_Query, passed by reference.
      */
     $clauses = apply_filters_ref_array('comments_clauses', array(compact($pieces), &$this));
     $fields = isset($clauses['fields']) ? $clauses['fields'] : '';
     $join = isset($clauses['join']) ? $clauses['join'] : '';
     $where = isset($clauses['where']) ? $clauses['where'] : '';
     $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : '';
     $limits = isset($clauses['limits']) ? $clauses['limits'] : '';
     $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : '';
     if ($where) {
         $where = 'WHERE ' . $where;
     }
     if ($groupby) {
         $groupby = 'GROUP BY ' . $groupby;
     }
     if ($orderby) {
         $orderby = "ORDER BY {$orderby}";
     }
     $this->request = "SELECT {$fields} FROM {$hqdb->comments} {$join} {$where} {$groupby} {$orderby} {$limits}";
     if ($this->query_vars['count']) {
         return $hqdb->get_var($this->request);
     }
     if ('ids' == $this->query_vars['fields']) {
         $this->comments = $hqdb->get_col($this->request);
         return array_map('intval', $this->comments);
     }
     $results = $hqdb->get_results($this->request);
     /**
      * Filter the comment query results.
      *
      * @since 0.0.1
      *
      * @param array            $results  An array of comments.
      * @param HQ_Comment_Query &$this    Current instance of HQ_Comment_Query, passed by reference.
      */
     $comments = apply_filters_ref_array('the_comments', array($results, &$this));
     hq_cache_add($cache_key, $comments, 'comment');
     if ('*' === $fields) {
         update_comment_cache($comments);
     }
     $this->comments = $comments;
     return $this->comments;
 }
 /**
  * Constructor method.
  *
  * @param string $type The 'type' is the sort order/kind. 'newest',
  *        'popular', 'unreplied', 'tags'.
  * @param int $forum_id The ID of the forum for which topics are being
  *        queried.
  * @param int $user_id The ID of the user to whom topics should be
  *        limited. Pass false to remove this filter.
  * @param int $page The number of the page being requested.
  * @param int $per_page The number of items being requested perpage.
  * @param string $no_stickies Requested sticky format.
  * @param string $search_terms Filter results by a string.
  * @param int $offset Optional. Offset results by a given numeric value.
  * @param int $number Optional. Total number of items to retrieve.
  */
 function __construct($type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false)
 {
     global $bp;
     $this->pag_page = $page;
     $this->pag_num = $per_page;
     $this->type = $type;
     $this->search_terms = $search_terms;
     $this->forum_id = $forum_id;
     $this->offset = $offset;
     $this->number = $number;
     switch ($type) {
         case 'newest':
         default:
             $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number));
             break;
         case 'popular':
             $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'type' => 'popular', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number));
             break;
         case 'unreplied':
             $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'type' => 'unreplied', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number));
             break;
         case 'tags':
             $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'type' => 'tags', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number));
             break;
     }
     $this->topics = apply_filters('bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies);
     if (!(int) $this->topics) {
         $this->topic_count = 0;
         $this->total_topic_count = 0;
     } else {
         // Get a total topic count, for use in pagination. This value will differ
         // depending on scope
         if (!empty($forum_id)) {
             // Group forums
             $topic_count = bp_forums_get_forum($forum_id);
             $topic_count = (int) $topic_count->topics;
         } else {
             if (!empty($bp->groups->current_group)) {
                 $topic_count = (int) groups_total_public_forum_topic_count($type);
             } else {
                 if (bp_is_user_forums_started() || bp_is_directory() && $user_id) {
                     // This covers the case of Profile > Forums > Topics Started, as
                     // well as Forum Directory > My Topics
                     $topic_count = bp_forums_total_topic_count_for_user(bp_displayed_user_id(), $type);
                 } else {
                     if (bp_is_user_forums_replied_to()) {
                         // Profile > Forums > Replied To
                         $topic_count = bp_forums_total_replied_count_for_user(bp_displayed_user_id(), $type);
                     } else {
                         if ('tags' == $type) {
                             $tag = bb_get_tag($search_terms);
                             $topic_count = $tag->count;
                         } else {
                             // For forum directories (All Topics), get a true count
                             $status = bp_current_user_can('bp_moderate') ? 'all' : 'public';
                             // todo: member-of
                             $topic_count = (int) groups_total_forum_topic_count($status, $search_terms);
                         }
                     }
                 }
             }
         }
         if (!$max || $max >= $topic_count) {
             $this->total_topic_count = $topic_count;
         } else {
             $this->total_topic_count = (int) $max;
         }
         if ($max) {
             if ($max >= count($this->topics)) {
                 $this->topic_count = count($this->topics);
             } else {
                 $this->topic_count = (int) $max;
             }
         } else {
             $this->topic_count = count($this->topics);
         }
     }
     $this->topic_count = apply_filters_ref_array('bp_forums_template_topic_count', array($this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies));
     $this->total_topic_count = apply_filters_ref_array('bp_forums_template_total_topic_count', array($this->total_topic_count, $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies));
     // Fetch extra information for topics, so we don't have to query inside the loop
     $this->topics = bp_forums_get_topic_extras($this->topics);
     if ((int) $this->total_topic_count && (int) $this->pag_num) {
         $this->pag_links = paginate_links(array('base' => add_query_arg(array('p' => '%#%', 'n' => $this->pag_num)), 'format' => '', 'total' => ceil((int) $this->total_topic_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('&larr;', 'Forum topic pagination previous text', 'buddypress'), 'next_text' => _x('&rarr;', 'Forum topic pagination next text', 'buddypress'), 'mid_size' => 1));
     }
 }
/**
 * Get full-text description for a specific notification.
 *
 * @since BuddyPress (1.9.0)
 *
 * @return string
 */
function bp_get_the_notification_description()
{
    $bp = buddypress();
    $notification = $bp->notifications->query_loop->notification;
    // Callback function exists
    if (isset($bp->{$notification->component_name}->notification_callback) && is_callable($bp->{$notification->component_name}->notification_callback)) {
        $description = call_user_func($bp->{$notification->component_name}->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1);
        // @deprecated format_notification_function - 1.5
    } elseif (isset($bp->{$notification->component_name}->format_notification_function) && function_exists($bp->{$notification->component_name}->format_notification_function)) {
        $description = call_user_func($bp->{$notification->component_name}->format_notification_function, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1);
        // Allow non BuddyPress components to hook in
    } else {
        /** This filter is documented in bp-notifications/bp-notifications-functions.php */
        $description = apply_filters_ref_array('bp_notifications_get_notifications_for_user', array($notification->component_action, $notification->item_id, $notification->secondary_item_id, 1));
    }
    /**
     * Filters the full-text description for a specific notification.
     *
     * @since BuddyPress (1.9.0)
     * @since BuddyPress (2.3.0) Added the `$notification` parameter.
     *
     * @param string $description  Full-text description for a specific notification.
     * @param object $notification Notification object.
     */
    return apply_filters('bp_get_the_notification_description', $description, $notification);
}
/**
 * Get notifications for a specific user.
 *
 * @since BuddyPress (1.9.0)
 *
 * @param int $user_id ID of the user whose notifications are being fetched.
 * @param string $format Format of the returned values. 'string' returns HTML,
 *        while 'object' returns a structured object for parsing.
 * @return mixed Object or array on success, false on failure.
 */
function bp_notifications_get_notifications_for_user($user_id, $format = 'string')
{
    // Setup local variables
    $bp = buddypress();
    // Get notifications (out of the cache, or query if necessary)
    $notifications = bp_notifications_get_all_notifications_for_user($user_id);
    $grouped_notifications = array();
    // Notification groups
    $renderable = array();
    // Renderable notifications
    // Group notifications by component and component_action and provide totals
    for ($i = 0, $count = count($notifications); $i < $count; ++$i) {
        $notification = $notifications[$i];
        $grouped_notifications[$notification->component_name][$notification->component_action][] = $notification;
    }
    // Bail if no notification groups
    if (empty($grouped_notifications)) {
        return false;
    }
    // Calculate a renderable output for each notification type
    foreach ($grouped_notifications as $component_name => $action_arrays) {
        // Skip if group is empty
        if (empty($action_arrays)) {
            continue;
        }
        // Loop through each actionable item and try to map it to a component
        foreach ((array) $action_arrays as $component_action_name => $component_action_items) {
            // Get the number of actionable items
            $action_item_count = count($component_action_items);
            // Skip if the count is less than 1
            if ($action_item_count < 1) {
                continue;
            }
            // Callback function exists
            if (isset($bp->{$component_name}->notification_callback) && is_callable($bp->{$component_name}->notification_callback)) {
                // Function should return an object
                if ('object' === $format) {
                    // Retrieve the content of the notification using the callback
                    $content = call_user_func($bp->{$component_name}->notification_callback, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count, 'array');
                    // Create the object to be returned
                    $notification_object = $component_action_items[0];
                    // Minimal backpat with non-compatible notification
                    // callback functions
                    if (is_string($content)) {
                        $notification_object->content = $content;
                        $notification_object->href = bp_loggedin_user_domain();
                    } else {
                        $notification_object->content = $content['text'];
                        $notification_object->href = $content['link'];
                    }
                    $renderable[] = $notification_object;
                    // Return an array of content strings
                } else {
                    $content = call_user_func($bp->{$component_name}->notification_callback, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count);
                    $renderable[] = $content;
                }
                // @deprecated format_notification_function - 1.5
            } elseif (isset($bp->{$component_name}->format_notification_function) && function_exists($bp->{$component_name}->format_notification_function)) {
                $renderable[] = call_user_func($bp->{$component_name}->format_notification_function, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count);
                // Allow non BuddyPress components to hook in
            } else {
                // The array to reference with apply_filters_ref_array()
                $ref_array = array($component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count, $format);
                // Function should return an object
                if ('object' === $format) {
                    /**
                     * Filters the notifications for a user.
                     *
                     * @since BuddyPress (1.9.0)
                     *
                     * @param array $ref_array Array of properties for the current notification being rendered.
                     */
                    $content = apply_filters_ref_array('bp_notifications_get_notifications_for_user', $ref_array);
                    // Create the object to be returned
                    $notification_object = $component_action_items[0];
                    // Minimal backpat with non-compatible notification
                    // callback functions
                    if (is_string($content)) {
                        $notification_object->content = $content;
                        $notification_object->href = bp_loggedin_user_domain();
                    } else {
                        $notification_object->content = $content['text'];
                        $notification_object->href = $content['link'];
                    }
                    $renderable[] = $notification_object;
                    // Return an array of content strings
                } else {
                    /** This filters is documented in bp-notifications/bp-notifications-functions.php */
                    $renderable[] = apply_filters_ref_array('bp_notifications_get_notifications_for_user', $ref_array);
                }
            }
        }
    }
    // If renderable is empty array, set to false
    if (empty($renderable)) {
        $renderable = false;
    }
    /**
     * Filters the final array of notifications to be displayed for a user.
     *
     * @since BuddyPress (1.6.0)
     *
     * @param Array|Bool $renderable Array of notifications to render or false if no notifications.
     * @param int        $user_id    ID of the user whose notifications are being displayed.
     * @param string     $format     Display format requested for the notifications.
     */
    return apply_filters('bp_core_get_notifications_for_user', $renderable, $user_id, $format);
}