function bp_blogs_record_activity($args = '')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    $defaults = array('user_id' => bp_loggedin_user_id(), 'action' => '', 'content' => '', 'primary_link' => '', 'component' => $bp->blogs->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Remove large images and replace them with just one image thumbnail
    if (bp_is_active('activity') && !empty($content)) {
        $content = bp_activity_thumbnail_content_images($content, $primary_link);
    }
    if (!empty($action)) {
        $action = apply_filters('bp_blogs_record_activity_action', $action);
    }
    if (!empty($content)) {
        $content = apply_filters('bp_blogs_record_activity_content', bp_create_excerpt($content), $content);
    }
    // Check for an existing entry and update if one exists.
    $id = bp_activity_get_activity_id(array('user_id' => $user_id, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id));
    return bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
 /**
  * Add or edit activities so that they are private
  *
  * @package WP Idea Stream
  * @subpackage buddypress/activity
  *
  * @since 2.0.0
  *
  * @param  int     $idea_id     the idea ID
  * @param  WP_Post $idea        the idea object
  * @uses   get_post()           to get the idea object if not set
  * @uses   WP_Idea_Stream_Activity->get_idea_and_comments() to get activities to manage
  * @uses   self::bulk_edit_activity to mark activities as private
  * @uses   get_current_blog_id() to get the current blog ID
  * @uses   buddypress() to get BuddyPress instance
  * @uses   add_query_arg(), get_home_url() to build the link to the idea.
  * @uses   bp_activity_thumbnail_content_images() to take content, remove images, and replace them with a single thumbnail image
  * @uses   bp_create_excerpt() to generate the content of the activity
  * @uses   bp_activity_add() to save the private activity
  * @uses   apply_filters() call 'bp_blogs_record_activity_content' to apply the filters on blog posts for private ideas
  *                         call 'wp_idea_stream_buddypress_activity_post_private' to override the private activity args
  */
 public function mark_activity_private($idea_id = 0, $idea = null)
 {
     if (empty($idea)) {
         $idea = get_post($idea_id);
     }
     // Get activities
     $activities = $this->get_idea_and_comments($idea_id, $idea->post_status);
     // If activities, then update their visibility status
     if (!empty($activities)) {
         // Do not update activities if they all are already marked as private.
         if (!empty($this->private_activities[$idea_id]) && !array_diff($activities, $this->private_activities[$idea_id])) {
             return;
         }
         self::bulk_edit_activity($activities, 1);
         // Otherwise, we need to create the activity
     } else {
         /**
          * Here we can't use bp_blogs_record_activity() as we need
          * to allow the groups component to eventually override the
          * component argument. As a result, we need to set a fiew vars
          */
         $bp = buddypress();
         $bp_activity_actions = new stdClass();
         $bp_activity_actions = $bp->activity->actions;
         // First the item id: the current blog
         $blog_id = get_current_blog_id();
         // Then all needed args except content
         $args = array('component' => buddypress()->blogs->id, 'type' => 'new_' . $this->post_type, 'primary_link' => add_query_arg('p', $idea_id, trailingslashit(get_home_url($blog_id))), 'user_id' => (int) $idea->post_author, 'item_id' => $blog_id, 'secondary_item_id' => $idea_id, 'recorded_time' => $idea->post_date_gmt, 'hide_sitewide' => 1);
         // The content will require to use functions that bp_blogs_record_activity()
         // is using to format it.
         $content = '';
         if (!empty($idea->post_content)) {
             $content = bp_activity_thumbnail_content_images($idea->post_content, $args['primary_link'], $args);
             $content = bp_create_excerpt($content);
         }
         // Add the content to the activity args
         $args['content'] = $content;
         /**
          * Filter is used internally to override ideas posted within a private or hidden group
          *
          * @param array   $args    the private activity arguments
          * @param WP_Post $idea    the idea object
          */
         $args = apply_filters('wp_idea_stream_buddypress_activity_post_private', $args, $idea);
         // Define the corresponding index
         $activity_type = $args['type'];
         $activity_component = $args['component'];
         // override the activity type
         $args['type'] = $this->activity_actions[$activity_type]->type;
         if (empty($bp->activity->actions->{$activity_component}->{$activity_type}['format_callback'])) {
             bp_activity_set_action($this->activity_actions[$activity_type]->component, $this->activity_actions[$activity_type]->type, $this->activity_actions[$activity_type]->admin_caption, $this->activity_actions[$activity_type]->action_callback);
         }
         /**
          * Finally publish the private activity
          * and reset BuddyPress activity actions
          */
         $private_activity_id = bp_activity_add($args);
         // Check for comments
         if (!empty($private_activity_id)) {
             $activities = $this->get_idea_and_comments($idea_id, $idea->post_status);
             $activities = array_diff($activities, array($private_activity_id));
             // Update comments visibility
             if (!empty($activities)) {
                 $test = self::bulk_edit_activity($activities, 1);
             }
         }
         $bp->activity->actions = $bp_activity_actions;
         // Reset edited activities
         $this->edit_activities = array();
     }
 }
/**
 * Get an excerpt of a group description.
 *
 * @param object $group Optional. The group being referenced. Defaults
 *        to the group currently being iterated on in the groups loop.
 * @return string Excerpt.
 */
function bp_get_group_description_excerpt($group = false)
{
    global $groups_template;
    if (empty($group)) {
        $group =& $groups_template->group;
    }
    return apply_filters('bp_get_group_description_excerpt', bp_create_excerpt($group->description), $group);
}
/**
 * Get an excerpt of a group description.
 *
 * @since 1.0.0
 *
 * @param object|bool $group Optional. The group being referenced.
 *                           Defaults to the group currently being
 *                           iterated on in the groups loop.
 * @return string Excerpt.
 */
function bp_get_group_description_excerpt($group = false)
{
    global $groups_template;
    if (empty($group)) {
        $group =& $groups_template->group;
    }
    /**
     * Filters the excerpt of a group description.
     *
     * @since 1.0.0
     *
     * @param string $value Excerpt of a group description.
     * @param object $group Object for group whose description is made into an excerpt.
     */
    return apply_filters('bp_get_group_description_excerpt', bp_create_excerpt($group->description), $group);
}
/**
 * Record blog-related activity to the activity stream.
 *
 * @since BuddyPress (1.0.0)
 *
 * @see bp_activity_add() for description of parameters.
 * @global object $bp The BuddyPress global settings object.
 *
 * @param array $args {
 *     See {@link bp_activity_add()} for complete description of arguments.
 *     The arguments listed here have different default values from
 *     bp_activity_add().
 *     @type string $component Default: 'blogs'.
 * }
 * @return int|bool On success, returns the activity ID. False on failure.
 */
function bp_blogs_record_activity( $args = '' ) {
	global $bp;

	// Bail if activity is not active
	if ( ! bp_is_active( 'activity' ) ) {
		return false;
	}

	$defaults = array(
		'user_id'           => bp_loggedin_user_id(),
		'action'            => '',
		'content'           => '',
		'primary_link'      => '',
		'component'         => $bp->blogs->id,
		'type'              => false,
		'item_id'           => false,
		'secondary_item_id' => false,
		'recorded_time'     => bp_core_current_time(),
		'hide_sitewide'     => false
	);

	$r = wp_parse_args( $args, $defaults );

	// Remove large images and replace them with just one image thumbnail
	if ( ! empty( $r['content'] ) ) {
		$r['content'] = bp_activity_thumbnail_content_images( $r['content'], $r['primary_link'], $r );
	}

	if ( ! empty( $r['action'] ) ) {

		/**
		 * Filters the action associated with activity for activity stream.
		 *
		 * @since BuddyPress (1.2.0)
		 *
		 * @param string $value Action for the activity stream.
		 */
		$r['action'] = apply_filters( 'bp_blogs_record_activity_action', $r['action'] );
	}

	if ( ! empty( $r['content'] ) ) {

		/**
		 * Filters the content associated with activity for activity stream.
		 *
		 * @since BuddyPress (1.2.0)
		 *
		 * @param string $value Generated excerpt from content for the activity stream.
		 * @param string $value Content for the activity stream.
		 * @param array  $r     Array of arguments used for the activity stream item.
		 */
		$r['content'] = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $r['content'] ), $r['content'], $r );
	}

	// Check for an existing entry and update if one exists.
	$id = bp_activity_get_activity_id( array(
		'user_id'           => $r['user_id'],
		'component'         => $r['component'],
		'type'              => $r['type'],
		'item_id'           => $r['item_id'],
		'secondary_item_id' => $r['secondary_item_id'],
	) );

	return bp_activity_add( array( 'id' => $id, 'user_id' => $r['user_id'], 'action' => $r['action'], 'content' => $r['content'], 'primary_link' => $r['primary_link'], 'component' => $r['component'], 'type' => $r['type'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'recorded_time' => $r['recorded_time'], 'hide_sitewide' => $r['hide_sitewide'] ) );
}
function bp_get_message_thread_excerpt()
{
    global $messages_template;
    return apply_filters('bp_get_message_thread_excerpt', bp_create_excerpt($messages_template->thread->last_message_message, 20));
}
Exemple #7
0
 /**
  * Record an activity stream entry when a reply is created
  *
  * @since bbPress (r3395)
  * @param int $topic_id
  * @param int $forum_id
  * @param array $anonymous_data
  * @param int $topic_author_id
  * @uses bbp_get_reply_id()
  * @uses bbp_get_topic_id()
  * @uses bbp_get_forum_id()
  * @uses bbp_get_user_profile_link()
  * @uses bbp_get_reply_url()
  * @uses bbp_get_reply_content()
  * @uses bbp_get_topic_permalink()
  * @uses bbp_get_topic_title()
  * @uses bbp_get_forum_permalink()
  * @uses bbp_get_forum_title()
  * @uses bp_create_excerpt()
  * @uses apply_filters()
  * @return Bail early if topic is by anonywous user
  */
 public function reply_create($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author_id)
 {
     // Do not log activity of anonymous users
     if (!empty($anonymous_data)) {
         return;
     }
     // Bail if site is private
     if (!bbp_is_site_public()) {
         return;
     }
     // Validate activity data
     $user_id = $reply_author_id;
     $reply_id = bbp_get_reply_id($reply_id);
     $topic_id = bbp_get_topic_id($topic_id);
     $forum_id = bbp_get_forum_id($forum_id);
     // Bail if user is not active
     if (bbp_is_user_inactive($user_id)) {
         return;
     }
     // Bail if reply is not published
     if (!bbp_is_reply_published($reply_id)) {
         return;
     }
     // Setup links for activity stream
     $user_link = bbp_get_user_profile_link($user_id);
     // Reply
     $reply_url = bbp_get_reply_url($reply_id);
     $reply_content = get_post_field('post_content', $reply_id, 'raw');
     // Topic
     $topic_permalink = bbp_get_topic_permalink($topic_id);
     $topic_title = get_post_field('post_title', $topic_id, 'raw');
     $topic_link = '<a href="' . $topic_permalink . '" title="' . $topic_title . '">' . $topic_title . '</a>';
     // Forum
     $forum_permalink = bbp_get_forum_permalink($forum_id);
     $forum_title = get_post_field('post_title', $forum_id, 'raw');
     $forum_link = '<a href="' . $forum_permalink . '" title="' . $forum_title . '">' . $forum_title . '</a>';
     // Activity action & text
     $activity_text = sprintf(__('%1$s replied to the topic %2$s in the forum %3$s', 'bbpress'), $user_link, $topic_link, $forum_link);
     $activity_action = apply_filters('bbp_activity_reply_create', $activity_text, $user_id, $reply_id, $topic_id);
     $activity_content = apply_filters('bbp_activity_reply_create_excerpt', bp_create_excerpt($reply_content), $reply_content);
     // Compile the activity stream results
     $activity = array('id' => $this->get_activity_id($reply_id), 'user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $reply_url, 'type' => $this->reply_create, 'item_id' => $reply_id, 'secondary_item_id' => $topic_id, 'recorded_time' => get_post_time('Y-m-d H:i:s', true, $reply_id), 'hide_sitewide' => !bbp_is_forum_public($forum_id, false));
     // Record the activity
     $activity_id = $this->record_activity($activity);
     // Add the activity entry ID as a meta value to the reply
     if (!empty($activity_id)) {
         update_post_meta($reply_id, '_bbp_activity_id', $activity_id);
     }
 }
	function bp_get_group_description_excerpt( $group = false ) {
		global $groups_template;

		if ( !$group )
			$group =& $groups_template->group;

		return apply_filters( 'bp_get_group_description_excerpt', bp_create_excerpt( $group->description, 20 ) );
	}
/**
 * Create a rich summary of an activity item for the activity stream.
 *
 * More than just a simple excerpt, the summary could contain oEmbeds and other types of media.
 * Currently, it's only used for blog post items, but it will probably be used for all types of
 * activity in the future.
 *
 * @since 2.3.0
 *
 * @param string $content  The content of the activity item.
 * @param array  $activity The data passed to bp_activity_add() or the values
 *                         from an Activity obj.
 * @return string $summary
 */
function bp_activity_create_summary($content, $activity)
{
    $args = array('width' => isset($GLOBALS['content_width']) ? (int) $GLOBALS['content_width'] : 'medium');
    // Get the WP_Post object if this activity type is a blog post.
    if ($activity['type'] === 'new_blog_post') {
        $content = get_post($activity['secondary_item_id']);
    }
    /**
     * Filter the class name of the media extractor when creating an Activity summary.
     *
     * Use this filter to change the media extractor used to extract media info for the activity item.
     *
     * @since 2.3.0
     *
     * @param string $extractor Class name.
     * @param string $content   The content of the activity item.
     * @param array  $activity  The data passed to bp_activity_add() or the values from an Activity obj.
     */
    $extractor = apply_filters('bp_activity_create_summary_extractor_class', 'BP_Media_Extractor', $content, $activity);
    $extractor = new $extractor();
    /**
     * Filter the arguments passed to the media extractor when creating an Activity summary.
     *
     * @since 2.3.0
     *
     * @param array              $args      Array of bespoke data for the media extractor.
     * @param string             $content   The content of the activity item.
     * @param array              $activity  The data passed to bp_activity_add() or the values from an Activity obj.
     * @param BP_Media_Extractor $extractor The media extractor object.
     */
    $args = apply_filters('bp_activity_create_summary_extractor_args', $args, $content, $activity, $extractor);
    // Extract media information from the $content.
    $media = $extractor->extract($content, BP_Media_Extractor::ALL, $args);
    // If we converted $content to an object earlier, flip it back to a string.
    if (is_a($content, 'WP_Post')) {
        $content = $content->post_content;
    }
    $para_count = substr_count(strtolower(wpautop($content)), '<p>');
    $has_audio = !empty($media['has']['audio']) && $media['has']['audio'];
    $has_videos = !empty($media['has']['videos']) && $media['has']['videos'];
    $has_feat_image = !empty($media['has']['featured_images']) && $media['has']['featured_images'];
    $has_galleries = !empty($media['has']['galleries']) && $media['has']['galleries'];
    $has_images = !empty($media['has']['images']) && $media['has']['images'];
    $has_embeds = false;
    // Embeds must be subtracted from the paragraph count.
    if (!empty($media['has']['embeds'])) {
        $has_embeds = $media['has']['embeds'] > 0;
        $para_count -= count($media['has']['embeds']);
    }
    $extracted_media = array();
    $use_media_type = '';
    $image_source = '';
    // If it's a short article and there's an embed/audio/video, use it.
    if ($para_count <= 3) {
        if ($has_embeds) {
            $use_media_type = 'embeds';
        } elseif ($has_audio) {
            $use_media_type = 'audio';
        } elseif ($has_videos) {
            $use_media_type = 'videos';
        }
    }
    // If not, or in any other situation, try to use an image.
    if (!$use_media_type && $has_images) {
        $use_media_type = 'images';
        $image_source = 'html';
        // Featured Image > Galleries > inline <img>.
        if ($has_feat_image) {
            $image_source = 'featured_images';
        } elseif ($has_galleries) {
            $image_source = 'galleries';
        }
    }
    // Extract an item from the $media results.
    if ($use_media_type) {
        if ($use_media_type === 'images') {
            $extracted_media = wp_list_filter($media[$use_media_type], array('source' => $image_source));
            $extracted_media = array_shift($extracted_media);
        } else {
            $extracted_media = array_shift($media[$use_media_type]);
        }
        /**
         * Filter the results of the media extractor when creating an Activity summary.
         *
         * @since 2.3.0
         *
         * @param array  $extracted_media Extracted media item. See {@link BP_Media_Extractor::extract()} for format.
         * @param string $content         Content of the activity item.
         * @param array  $activity        The data passed to bp_activity_add() or the values from an Activity obj.
         * @param array  $media           All results from the media extraction.
         *                                See {@link BP_Media_Extractor::extract()} for format.
         * @param string $use_media_type  The kind of media item that was preferentially extracted.
         * @param string $image_source    If $use_media_type was "images", the preferential source of the image.
         *                                Otherwise empty.
         */
        $extracted_media = apply_filters('bp_activity_create_summary_extractor_result', $extracted_media, $content, $activity, $media, $use_media_type, $image_source);
    }
    // Generate a text excerpt for this activity item (and remove any oEmbeds URLs).
    $summary = strip_shortcodes(html_entity_decode(strip_tags($content)));
    $summary = bp_create_excerpt(preg_replace('#^\\s*(https?://[^\\s"]+)\\s*$#im', '', $summary));
    if ($use_media_type === 'embeds') {
        $summary .= PHP_EOL . PHP_EOL . $extracted_media['url'];
    } elseif ($use_media_type === 'images') {
        $summary .= sprintf(' <img src="%s">', esc_url($extracted_media['url']));
    } elseif (in_array($use_media_type, array('audio', 'videos'), true)) {
        $summary .= PHP_EOL . PHP_EOL . $extracted_media['original'];
        // Full shortcode.
    }
    /**
     * Filters the newly-generated summary for the activity item.
     *
     * @since 2.3.0
     *
     * @param string $summary         Activity summary HTML.
     * @param string $content         Content of the activity item.
     * @param array  $activity        The data passed to bp_activity_add() or the values from an Activity obj.
     * @param array  $extracted_media Media item extracted. See {@link BP_Media_Extractor::extract()} for format.
     */
    return apply_filters('bp_activity_create_summary', $summary, $content, $activity, $extracted_media);
}
/**
 * Returns the activity feed item title
 *
 * @since 1.0.0
 *
 * @global object $activities_template {@link BP_Activity_Template}
 * @uses ent2ncr()
 * @uses convert_chars()
 * @uses bp_create_excerpt()
 * @uses apply_filters() To call the 'bp_get_activity_feed_item_title' hook
 *
 * @return string $title The activity feed item title
 */
function bp_get_activity_feed_item_title()
{
    global $activities_template;
    if (!empty($activities_template->activity->action)) {
        $content = $activities_template->activity->action;
    } else {
        $content = $activities_template->activity->content;
    }
    $content = explode('<span', $content);
    $title = strip_tags(ent2ncr(trim(convert_chars($content[0]))));
    if (':' == substr($title, -1)) {
        $title = substr($title, 0, -1);
    }
    if ('activity_update' == $activities_template->activity->type) {
        $title .= ': ' . strip_tags(ent2ncr(trim(convert_chars(bp_create_excerpt($activities_template->activity->content, 70, array('ending' => " [&#133;]"))))));
    }
    return apply_filters('bp_get_activity_feed_item_title', $title);
}
function bp_get_message_thread_excerpt()
{
    global $messages_template;
    return apply_filters('bp_get_message_thread_excerpt', strip_tags(bp_create_excerpt($messages_template->thread->last_message_content, 75)));
}
/**
 * Truncates long activity entries when viewed in activity streams
 *
 * @since 1.5.0
 *
 * @param $text The original activity entry text
 *
 * @uses bp_is_single_activity()
 * @uses apply_filters() To call the 'bp_activity_excerpt_append_text' hook
 * @uses apply_filters() To call the 'bp_activity_excerpt_length' hook
 * @uses bp_create_excerpt()
 * @uses bp_get_activity_id()
 * @uses bp_get_activity_thread_permalink()
 * @uses apply_filters() To call the 'bp_activity_truncate_entry' hook
 *
 * @return string $excerpt The truncated text
 */
function bp_activity_truncate_entry($text)
{
    global $activities_template;
    // The full text of the activity update should always show on the single activity screen
    if (bp_is_single_activity()) {
        return $text;
    }
    $append_text = apply_filters('bp_activity_excerpt_append_text', __('[Read more]', 'buddypress'));
    $excerpt_length = apply_filters('bp_activity_excerpt_length', 358);
    // Run the text through the excerpt function. If it's too short, the original text will be
    // returned.
    $excerpt = bp_create_excerpt($text, $excerpt_length, array('ending' => __('&hellip;', 'buddypress')));
    // If the text returned by bp_create_excerpt() is different from the original text (ie it's
    // been truncated), add the "Read More" link.
    if ($excerpt != $text) {
        $id = !empty($activities_template->activity->current_comment->id) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
        $excerpt = sprintf('%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', $excerpt, $id, bp_get_activity_thread_permalink(), $append_text);
    }
    return apply_filters('bp_activity_truncate_entry', $excerpt, $text, $append_text);
}
/**
 * Update an existing group forum post.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int $post_id The post ID of the existing forum post.
 * @param string $post_text The text for the forum post.
 * @param int $topic_id The topic ID of the existing forum topic.
 * @param mixed $page The page number where the new forum post should reside.
 *	  Optional.
 * @return mixed The forum post ID on success. Boolean false on failure.
 */
function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false)
{
    $bp = buddypress();
    $post_text = apply_filters('group_forum_post_text_before_save', $post_text);
    $topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id);
    $post = bp_forums_get_post($post_id);
    $post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id));
    if (empty($post_id)) {
        return false;
    }
    $topic = bp_forums_get_topic_details($topic_id);
    $activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_id), '<a href="' . bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink(groups_get_current_group()) . '">' . esc_attr(bp_get_current_group_name()) . '</a>');
    $activity_content = bp_create_excerpt($post_text);
    $primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/';
    if (!empty($page)) {
        $primary_link .= "?topic_page=" . $page;
    }
    // Get the corresponding activity item
    if (bp_is_active('activity')) {
        $id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id));
    }
    // Update the entry in activity streams
    groups_record_activity(array('id' => $id, 'action' => apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic)), 'content' => apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic)), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id), 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time));
    do_action_ref_array('groups_update_group_forum_post', array($post, &$topic));
    return $post_id;
}
function bp_album_get_picture_desc_truncate($words = 55)
{
    global $pictures_template;
    $exc = bp_create_excerpt($pictures_template->picture->description, $words, true);
    return apply_filters('bp_album_get_picture_desc_truncate', $exc, $pictures_template->picture->description, $words);
}
 /**
  * Function to fetch group feeds and save RSS entries as BP activity items.
  *
  * @param int $group_id The group ID.
  */
 function bp_groupblogs_fetch_group_feeds($group_id = false)
 {
     if (empty($group_id)) {
         $group_id = bp_get_current_group_id();
     }
     if ($group_id == bp_get_current_group_id()) {
         $group = groups_get_current_group();
     } else {
         $group = new BP_Groups_Group($group_id);
     }
     if (!$group) {
         return false;
     }
     $group_blogs = groups_get_groupmeta($group_id, 'blogfeeds');
     $items = array();
     foreach ((array) $group_blogs as $feed_url) {
         $feed_url = trim($feed_url);
         if (empty($feed_url)) {
             continue;
         }
         // Make sure the feed is accessible
         $test = wp_remote_get($feed_url);
         if (is_wp_error($test)) {
             continue;
         }
         try {
             $rss = new SimpleXmlElement($test['body']);
         } catch (Exception $e) {
             continue;
         }
         $rss = fetch_feed(trim($feed_url));
         if (!is_wp_error($rss)) {
             $maxitems = $rss->get_item_quantity(10);
             $rss_items = $rss->get_items(0, $maxitems);
             foreach ($rss_items as $item) {
                 $key = $item->get_date('U');
                 $items[$key]['title'] = $item->get_title();
                 $items[$key]['subtitle'] = $item->get_title();
                 //$items[$key]['author'] = $item->get_author()->get_name();
                 $items[$key]['blogname'] = $item->get_feed()->get_title();
                 $items[$key]['link'] = $item->get_permalink();
                 $items[$key]['blogurl'] = $item->get_feed()->get_link();
                 $items[$key]['description'] = $item->get_description();
                 $items[$key]['source'] = $item->get_source();
                 $items[$key]['copyright'] = $item->get_copyright();
                 $items[$key]['primary_link'] = $item->get_link();
                 $items[$key]['guid'] = $item->get_id();
                 $items[$key]['feedurl'] = $feed_url;
             }
         }
     }
     if (!empty($items)) {
         ksort($items);
         $items = array_reverse($items, true);
     } else {
         return false;
     }
     /* Set the visibility */
     $hide_sitewide = 'public' != $group->status ? true : false;
     /* Record found blog posts in activity streams */
     foreach ((array) $items as $post_date => $post) {
         $activity_action = sprintf(__('Blog: %s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">' . esc_attr($post['title']) . '</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . esc_attr($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>');
         $activity_content = '<div>' . strip_tags(bp_create_excerpt($post['description'], 175)) . '</div>';
         $activity_content = apply_filters('bp_groupblogs_activity_content', $activity_content, $post, $group);
         /* Fetch an existing activity_id if one exists. */
         // backpat
         $id = bp_activity_get_activity_id(array('user_id' => false, 'action' => $activity_action, 'component' => 'groups', 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl'])));
         // new method
         if (empty($id)) {
             $existing = bp_activity_get(array('user_id' => false, 'component' => 'groups', 'type' => 'exb', 'item_id' => $group_id, 'update_meta_cache' => false, 'display_comments' => false, 'meta_query' => array(array('key' => 'exb_guid', 'value' => $post['guid']))));
             // we've found an existing entry
             if (!empty($existing['activities'])) {
                 $id = (int) $existing['activities'][0]->id;
             }
         }
         /* Record or update in activity streams. */
         // Skip if it already exists
         if (empty($id)) {
             $aid = groups_record_activity(array('id' => $id, 'user_id' => false, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $post['primary_link'], 'type' => 'exb', 'item_id' => $group_id, 'recorded_time' => gmdate("Y-m-d H:i:s", $post_date), 'hide_sitewide' => $hide_sitewide));
             // save rss guid as activity meta
             bp_activity_update_meta($aid, 'exb_guid', $post['guid']);
             bp_activity_update_meta($aid, 'exb_feedurl', $post['feedurl']);
         }
     }
     return $items;
 }
/**
 * Create activity for paper edits.
 *
 * Edit activity is throttled: no more than one activity item per 60 minutes.
 *
 * @param int     $post_id     ID of the post.
 * @param WP_Post $post_after  New post.
 * @param WP_Post $post_before Old post.
 */
function cacsp_create_edit_activity($post_id, WP_Post $post_after, WP_Post $post_before)
{
    if ('cacsp_paper' !== $post_after->post_type) {
        return;
    }
    // We only want to record edits of published posts. Drafts don't get activity, and BP handles publishing.
    if ('publish' !== $post_before->post_status || 'publish' !== $post_after->post_status) {
        return;
    }
    // The author of the edit is the one who wrote the last revision.
    if ($revisions = wp_get_post_revisions($post_id)) {
        // Grab the last revision, but not an autosave.
        foreach ($revisions as $revision) {
            if (false !== strpos($revision->post_name, "{$revision->post_parent}-revision")) {
                $last_revision = $revision;
                break;
            }
        }
    }
    // Either revisions are disabled, or something else has gone wrong. Just use the post author.
    if (!isset($last_revision)) {
        $rev_author = $post_after->post_author;
    } else {
        $rev_author = $last_revision->post_author;
    }
    // Throttle.
    $existing = bp_activity_get(array('filter_query' => array(array('column' => 'component', 'value' => 'cacsp'), array('column' => 'type', 'value' => 'new_cacsp_edit'), array('column' => 'secondary_item_id', 'value' => $post_id), array('column' => 'user_id', 'value' => $rev_author)), 'update_meta_cache' => false, 'per_page' => 1));
    if (!empty($existing['activities'])) {
        /**
         * Filters the number of seconds in the edit throttle.
         *
         * This prevents activity stream flooding by multiple edits of the same paper.
         *
         * @param int $throttle_period Defaults to 6 hours.
         */
        $throttle_period = apply_filters('bpeo_event_edit_throttle_period', 6 * HOUR_IN_SECONDS);
        if (time() - strtotime($existing['activities'][0]->date_recorded) < $throttle_period) {
            return;
        }
    }
    // Poor man's diff. https://coderwall.com/p/3j2hxq/find-and-format-difference-between-two-strings-in-php
    $old = $post_before->post_content;
    $new = $post_after->post_content;
    $from_start = strspn($old ^ $new, "");
    $from_end = strspn(strrev($old) ^ strrev($new), "");
    $old_end = strlen($old) - $from_end;
    $new_end = strlen($new) - $from_end;
    $start = substr($new, 0, $from_start);
    $end = substr($new, $new_end);
    $new_diff = substr($new, $from_start, $new_end - $from_start);
    // Take a few words before the diff.
    $_start = explode(' ', $start);
    $_start = implode(' ', array_slice($_start, -5));
    $content = bp_create_excerpt('&hellip;' . $_start . $new_diff . $end);
    $activity_id = bp_activity_add(array('content' => $content, 'component' => 'cacsp', 'type' => 'new_cacsp_edit', 'primary_link' => get_permalink($post_id), 'user_id' => $rev_author, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id, 'hide_sitewide' => false));
}
/**
 * Update an existing group forum post.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int    $post_id   The post ID of the existing forum post.
 * @param string $post_text The text for the forum post.
 * @param int    $topic_id  The topic ID of the existing forum topic.
 * @param mixed  $page      The page number where the new forum post should reside. Optional.
 *
 * @return mixed The forum post ID on success. Boolean false on failure.
 */
function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false)
{
    $bp = buddypress();
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $post_text = apply_filters('group_forum_post_text_before_save', $post_text);
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id);
    $post = bp_forums_get_post($post_id);
    $post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id));
    if (empty($post_id)) {
        return false;
    }
    $topic = bp_forums_get_topic_details($topic_id);
    $activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_id), '<a href="' . bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink(groups_get_current_group()) . '">' . esc_attr(bp_get_current_group_name()) . '</a>');
    $activity_content = bp_create_excerpt($post_text);
    $primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/';
    if (!empty($page)) {
        $primary_link .= "?topic_page=" . $page;
    }
    // Get the corresponding activity item
    if (bp_is_active('activity')) {
        $id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id));
    }
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $action = apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic));
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $content = apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic));
    /** This filter is documented in bp-groups/bp-groups-forums.php */
    $filtered_primary_link = apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id);
    groups_record_activity(array('id' => $id, 'action' => $action, 'content' => $content, 'primary_link' => $filtered_primary_link, 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time));
    /**
     * Fires after the update of a group forum post.
     *
     * @since BuddyPress (1.1.0)
     *
     * @param object $post  Object holding current post being updated.
     * @param object $topic Object holding current topic details. Passed by reference.
     */
    do_action_ref_array('groups_update_group_forum_post', array($post, &$topic));
    return $post_id;
}
 function x_buddypress_get_message_thread_excerpt()
 {
     global $messages_template;
     return strip_tags(bp_create_excerpt($messages_template->thread->last_message_content, 200));
 }
/**
 * Get the latest update from the current member in the loop.
 *
 * @param array|string $args {
 *     Array of optional arguments.
 *     @type int  $length    Truncation length. Default: 225.
 *     @type bool $view_link Whether to provide a 'View' link for
 *                           truncated entries. Default: false.
 * }
 * @return string
 */
function bp_get_member_latest_update($args = '')
{
    global $members_template;
    $defaults = array('length' => 225, 'view_link' => true);
    $r = wp_parse_args($args, $defaults);
    extract($r);
    if (!bp_is_active('activity') || empty($members_template->member->latest_update) || !($update = maybe_unserialize($members_template->member->latest_update))) {
        return false;
    }
    /**
     * Filters the excerpt of the latest update for current member in the loop.
     *
     * @since 1.2.5
     *
     * @param string $value Excerpt of the latest update for current member in the loop.
     */
    $update_content = apply_filters('bp_get_activity_latest_update_excerpt', trim(strip_tags(bp_create_excerpt($update['content'], $length))));
    $update_content = sprintf(_x('- &quot;%s&quot;', 'member latest update in member directory', 'buddypress'), $update_content);
    // If $view_link is true and the text returned by bp_create_excerpt() is different from the original text (ie it's
    // been truncated), add the "View" link.
    if ($view_link && $update_content != $update['content']) {
        $view = __('View', 'buddypress');
        $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink($update['id']) . '" rel="nofollow">' . $view . '</a></span>';
    }
    /**
     * Filters the latest update from the current member in the loop.
     *
     * @since 1.2.0
     *
     * @param string $update_content Formatted latest update for current member.
     */
    return apply_filters('bp_get_member_latest_update', $update_content);
}
 /**
  * activity_for_response( $response_data, $type = "add" )
  *
  * Function generates activity updates on response actions
  * @param Mixed $response_data, response details
  * @param String $type, the type of action: add - default, on response creations
  */
 function activity_for_response($response_data, $type = "add")
 {
     global $bp;
     if (!isset($response_data['public']) || !$response_data['public']) {
         return;
     }
     $response = $response_data['response'];
     $activity_action = sprintf(__('%s added a response %s to %s Courseware Assignment:', 'bpsp'), bp_core_get_userlink($bp->loggedin_user->id), '<a href="' . $response_data['assignment_permalink'] . '/response/' . $response->post_name . '/">' . attribute_escape($response->post_title) . '</a>', '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . attribute_escape($bp->groups->current_group->name) . '</a>');
     $activity_content = bp_create_excerpt($response->post_content);
     $primary_link = $response_data['assignment_permalink'] . '/response/' . $response->post_name . '/';
     groups_record_activity(array('action' => apply_filters('courseware_response_activity_action', $activity_action, $response->ID, $response->post_content, $response), 'content' => apply_filters('courseware_response_activity_content', $activity_content, $response->ID, $response->post_content, $response), 'primary_link' => apply_filters('courseware_response_activity_primary_link', "{$primary_link}#post-{$response->ID}"), 'type' => "response_{$type}", 'item_id' => $bp->groups->current_group->id));
 }
/**
 * Generate an excerpt from the current message in the loop.
 *
 * @return string
 */
function bp_get_message_thread_excerpt()
{
    global $messages_template;
    /**
     * Filters the excerpt of the current thread in the loop.
     *
     * @since 1.0.0
     *
     * @param string $value Excerpt of the current thread in the loop.
     */
    return apply_filters('bp_get_message_thread_excerpt', strip_tags(bp_create_excerpt($messages_template->thread->last_message_content, 75)));
}
/**
 * Truncate long activity entries when viewed in activity streams.
 *
 * This method can only be used inside the Activity loop.
 *
 * @since 1.5.0
 *
 * @uses bp_is_single_activity()
 * @uses apply_filters() To call the 'bp_activity_excerpt_append_text' hook.
 * @uses apply_filters() To call the 'bp_activity_excerpt_length' hook.
 * @uses bp_create_excerpt()
 * @uses bp_get_activity_id()
 * @uses bp_get_activity_thread_permalink()
 * @uses apply_filters() To call the 'bp_activity_truncate_entry' hook.
 *
 * @param string $text The original activity entry text.
 * @return string $excerpt The truncated text.
 */
function bp_activity_truncate_entry($text)
{
    global $activities_template;
    /**
     * Provides a filter that lets you choose whether to skip this filter on a per-activity basis.
     *
     * @since 2.3.0
     *
     * @param bool $value If true, text should be checked to see if it needs truncating.
     */
    $maybe_truncate_text = apply_filters('bp_activity_maybe_truncate_entry', isset($activities_template->activity->type) && !in_array($activities_template->activity->type, array('new_blog_post'), true));
    // The full text of the activity update should always show on the single activity screen.
    if (!$maybe_truncate_text || bp_is_single_activity()) {
        return $text;
    }
    /**
     * Filters the appended text for the activity excerpt.
     *
     * @since 1.5.0
     *
     * @param string $value Internationalized "Read more" text.
     */
    $append_text = apply_filters('bp_activity_excerpt_append_text', __('[Read more]', 'buddypress'));
    /**
     * Filters the excerpt length for the activity excerpt.
     *
     * @since 1.5.0
     *
     * @param int $value Number indicating how many words to trim the excerpt down to.
     */
    $excerpt_length = apply_filters('bp_activity_excerpt_length', 358);
    // Run the text through the excerpt function. If it's too short, the original text will be returned.
    $excerpt = bp_create_excerpt($text, $excerpt_length, array('ending' => __('&hellip;', 'buddypress')));
    /*
     * If the text returned by bp_create_excerpt() is different from the original text (ie it's
     * been truncated), add the "Read More" link. Note that bp_create_excerpt() is stripping
     * shortcodes, so we have strip them from the $text before the comparison.
     */
    if ($excerpt != strip_shortcodes($text)) {
        $id = !empty($activities_template->activity->current_comment->id) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
        $excerpt = sprintf('%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', $excerpt, $id, bp_get_activity_thread_permalink(), $append_text);
    }
    /**
     * Filters the composite activity excerpt entry.
     *
     * @since 1.5.0
     *
     * @param string $excerpt     Excerpt text and markup to be displayed.
     * @param string $text        The original activity entry text.
     * @param string $append_text The final append text applied.
     */
    return apply_filters('bp_activity_truncate_entry', $excerpt, $text, $append_text);
}
function bp_get_link_description_excerpt($link = false, $length = 55)
{
    global $links_template;
    if (!$link) {
        $link =& $links_template->link;
    }
    return apply_filters('bp_get_link_description_excerpt', bp_create_excerpt($link->description, $length));
}
/**
 * Publish!
 *
 * @package Rendez Vous
 * @subpackage Activity
 *
 * @since Rendez Vous (1.0.0)
 */
function rendez_vous_published_activity($id = 0, $args = array(), $notify = false, $activity = false)
{
    if (empty($id) || empty($activity)) {
        return;
    }
    $rendez_vous = rendez_vous_get_item($id);
    $rendez_vous_url = rendez_vous_get_single_link($id, $rendez_vous->organizer);
    $rendez_vous_link = '<a href="' . esc_url($rendez_vous_url) . '">' . esc_html($rendez_vous->title) . '</a>';
    $user_link = bp_core_get_userlink($rendez_vous->organizer);
    $action_part = __('scheduled a new', 'rendez-vous');
    $action = sprintf(__('%1$s %2$s rendez-vous, %3$s', 'rendez-vous'), $user_link, $action_part, $rendez_vous_link);
    $content = false;
    if (!empty($rendez_vous->description)) {
        $content = bp_create_excerpt($rendez_vous->description);
    }
    $activity_id = bp_activity_add(apply_filters('rendez_vous_published_activity_args', array('action' => $action, 'content' => $content, 'component' => buddypress()->rendez_vous->id, 'type' => 'new_rendez_vous', 'primary_link' => $rendez_vous_url, 'user_id' => $rendez_vous->organizer, 'item_id' => $rendez_vous->id, 'secondary_item_id' => $rendez_vous->organizer)));
    if (!empty($activity_id)) {
        bp_activity_update_meta($activity_id, 'rendez_vous_title', $rendez_vous->title);
    }
    return true;
}
 /**
  * @ticket BP6517
  */
 public function test_string_should_not_be_cut_mid_tag_when_exact_is_false()
 {
     $text = '<p><span>Foo</span> <a href="http://example.com">Bar</a> Baz.</p><p>Foo Bar Baz</p>';
     $actual = bp_create_excerpt($text, 7, array('html' => true, 'ending' => '', 'exact' => false));
     $this->assertSame('<p><span>Foo</span> <a href="http://example.com">Bar</a></p>', $actual);
 }
	/**
	 * Return an excerpt from the latest post of the current topic in the loop.
	 *
	 * @param array $args {
	 *     @type int $length The length of the excerpted text. Default: 225.
	 * }
	 * @return string Post excerpt.
	 */
	function bp_get_the_topic_latest_post_excerpt( $args = '' ) {
		global $forum_template;

		$defaults = array(
			'length' => 225
		);

		$r = wp_parse_args( $args, $defaults );
		extract( $r, EXTR_SKIP );

		$post = bp_forums_get_post( $forum_template->topic->topic_last_post_id );
		$post = bp_create_excerpt( $post->post_text, $length );

		/**
		 * Filters an excerpt from the latest post of the current topic in the loop.
		 *
		 * @since BuddyPress (1.0.0)
		 *
		 * @param string $post   Post exceprt for the current topic.
		 * @param string $length String length to trim excerpt down to.
		 */
		return apply_filters( 'bp_get_the_topic_latest_post_excerpt', $post, $length );
	}
/**
 * Return an excerpt from the latest post of the current topic in the loop.
 *
 * @param array $args {
 *     @type int $length The length of the excerpted text. Default: 225.
 * }
 * @return string Post excerpt.
 */
function bp_get_the_topic_latest_post_excerpt($args = '')
{
    global $forum_template;
    $defaults = array('length' => 225);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $post = bp_forums_get_post($forum_template->topic->topic_last_post_id);
    $post = bp_create_excerpt($post->post_text, $length);
    return apply_filters('bp_get_the_topic_latest_post_excerpt', $post, $length);
}
/**
 * xprofile_format_activity()
 *
 * The function xprofile_record_activity() simply records ID's, which component and action, and dates into
 * the database. These variables need to be formatted into something that can be read and displayed to
 * the user.
 *
 * This function will format an activity item based on the component action and return it for saving
 * in the activity cache database tables. It can then be selected and displayed with far less load on
 * the server.
 * 
 * @package BuddyPress Xprofile
 * @param $item_id The ID of the specific item for which the activity is recorded (could be a wire post id, user id etc)
 * @param $action The component action name e.g. 'new_wire_post' or 'updated_profile'
 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
 * @global $current_user WordPress global variable containing current logged in user information
 * @uses BP_Wire_Post Class Creates a new wire post object based on the table name and ID.
 * @uses BP_XProfile_Group Class Creates a new group object based on the group ID.
 * @return The readable activity item
 */
function xprofile_format_activity($item_id, $user_id, $action, $secondary_item_id = false, $for_secondary_user = false)
{
    global $bp;
    switch ($action) {
        case 'new_wire_post':
            if (class_exists('BP_Wire_Post')) {
                $wire_post = new BP_Wire_Post($bp->profile->table_name_wire, $item_id);
            }
            if (!$wire_post) {
                return false;
            }
            if ($wire_post->item_id == $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id || $wire_post->item_id == $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id) {
                $from_user_link = bp_core_get_userlink($wire_post->user_id);
                $to_user_link = false;
                $content = sprintf(__('%s wrote on their own wire', 'buddypress'), $from_user_link) . ': <span class="time-since">%s</span>';
                $return_values['primary_link'] = bp_core_get_userlink($wire_post->user_id, false, true);
            } else {
                if ($wire_post->item_id != $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id || $wire_post->item_id != $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id) {
                    $from_user_link = bp_core_get_userlink($wire_post->user_id);
                    $to_user_link = bp_core_get_userlink($wire_post->item_id, false, false, true, true);
                    $content = sprintf(__('%s wrote on %s wire', 'buddypress'), $from_user_link, $to_user_link) . ': <span class="time-since">%s</span>';
                    $return_values['primary_link'] = bp_core_get_userlink($wire_post->item_id, false, true);
                }
            }
            if ($content != '') {
                $post_excerpt = bp_create_excerpt($wire_post->content);
                $content .= '<blockquote>' . $post_excerpt . '</blockquote>';
                $return_values['content'] = $content;
                $return_values['content'] = apply_filters('xprofile_new_wire_post_activity', $content, $from_user_link, $to_user_link, $post_excerpt);
                return $return_values;
            }
            return false;
            break;
        case 'updated_profile':
            $profile_group = new BP_XProfile_Group($item_id);
            if (!$profile_group) {
                return false;
            }
            $user_link = bp_core_get_userlink($user_id);
            return array('primary_link' => bp_core_get_userlink($user_id, false, true), 'content' => apply_filters('xprofile_updated_profile_activity', sprintf(__('%s updated the "%s" information on their profile', 'buddypress'), $user_link, '<a href="' . $bp->displayed_user->domain . $bp->profile->slug . '">' . $profile_group->name . '</a>') . ' <span class="time-since">%s</span>', $user_link, $profile_group->name));
            break;
    }
    do_action('xprofile_format_activity', $action, $item_id, $user_id, $action, $secondary_item_id, $for_secondary_user);
    return false;
}
Exemple #29
0
 function kleo_ajax_search()
 {
     //if "s" input is missing exit
     if (empty($_REQUEST['s']) && empty($_REQUEST['bbp_search'])) {
         die;
     }
     if (!empty($_REQUEST['bbp_search'])) {
         $search_string = $_REQUEST['bbp_search'];
     } else {
         $search_string = $_REQUEST['s'];
     }
     $output = "";
     $context = "any";
     $defaults = array('numberposts' => 4, 'posts_per_page' => 20, 'post_type' => 'any', 'post_status' => 'publish', 'post_password' => '', 'suppress_filters' => false, 's' => $_REQUEST['s']);
     if (isset($_REQUEST['context']) && $_REQUEST['context'] != '') {
         $context = explode(",", $_REQUEST['context']);
         $defaults['post_type'] = $context;
     }
     $defaults = apply_filters('kleo_ajax_query_args', $defaults);
     $the_query = new WP_Query($defaults);
     $posts = $the_query->get_posts();
     $members = array();
     $members['total'] = 0;
     $groups = array();
     $groups['total'] = 0;
     $forums = FALSE;
     if (function_exists('bp_is_active') && ($context == "any" || in_array("members", $context))) {
         $members = bp_core_get_users(array('search_terms' => $search_string, 'per_page' => $defaults['numberposts'], 'populate_extras' => false));
     }
     if (function_exists('bp_is_active') && bp_is_active("groups") && ($context == "any" || in_array("groups", $context))) {
         $groups = groups_get_groups(array('search_terms' => $search_string, 'per_page' => $defaults['numberposts'], 'populate_extras' => false));
     }
     if (class_exists('bbPress') && ($context == "any" || in_array("forum", $context))) {
         $forums = kleo_bbp_get_replies($search_string);
     }
     //if there are no posts, groups nor members
     if (empty($posts) && $members['total'] == 0 && $groups['total'] == 0 && !$forums) {
         $output = "<div class='kleo_ajax_entry ajax_not_found'>";
         $output .= "<div class='ajax_search_content'>";
         $output .= "<i class='icon icon-exclamation-sign'></i> ";
         $output .= __("Sorry, we haven't found anything based on your criteria.", 'kleo_framework');
         $output .= "<br>";
         $output .= __("Please try searching by different terms.", 'kleo_framework');
         $output .= "</div>";
         $output .= "</div>";
         echo $output;
         die;
     }
     //if there are members
     if ($members['total'] != 0) {
         $output .= '<div class="kleo-ajax-part kleo-ajax-type-members">';
         $output .= '<h4><span>' . __("Members", 'kleo_framework') . '</span></h4>';
         foreach ((array) $members['users'] as $member) {
             $image = '<img src="' . bp_core_fetch_avatar(array('item_id' => $member->ID, 'width' => 25, 'height' => 25, 'html' => false)) . '" class="kleo-rounded" alt="">';
             if ($update = bp_get_user_meta($member->ID, 'bp_latest_update', true)) {
                 $latest_activity = char_trim(trim(strip_tags(bp_create_excerpt($update['content'], 50, "..."))));
             } else {
                 $latest_activity = '';
             }
             $output .= "<div class ='kleo_ajax_entry'>";
             $output .= "<div class='ajax_search_image'>{$image}</div>";
             $output .= "<div class='ajax_search_content'>";
             $output .= "<a href='" . bp_core_get_user_domain($member->ID) . "' class='search_title'>";
             $output .= $member->display_name;
             $output .= "</a>";
             $output .= "<span class='search_excerpt'>";
             $output .= $latest_activity;
             $output .= "</span>";
             $output .= "</div>";
             $output .= "</div>";
         }
         $output .= "<a class='ajax_view_all' href='" . bp_get_members_directory_permalink() . "?s=" . $search_string . "'>" . __('View member results', 'kleo_framework') . "</a>";
         $output .= "</div>";
     }
     //if there are groups
     if ($groups['total'] != 0) {
         $output .= '<div class="kleo-ajax-part kleo-ajax-type-groups">';
         $output .= '<h4><span>' . __("Groups", 'kleo_framework') . '</span></h4>';
         foreach ((array) $groups['groups'] as $group) {
             $image = '<img src="' . bp_core_fetch_avatar(array('item_id' => $group->id, 'object' => 'group', 'width' => 25, 'height' => 25, 'html' => false)) . '" class="kleo-rounded" alt="">';
             $output .= "<div class ='kleo_ajax_entry'>";
             $output .= "<div class='ajax_search_image'>{$image}</div>";
             $output .= "<div class='ajax_search_content'>";
             $output .= "<a href='" . bp_get_group_permalink($group) . "' class='search_title'>";
             $output .= $group->name;
             $output .= "</a>";
             $output .= "</div>";
             $output .= "</div>";
         }
         $output .= "<a class='ajax_view_all' href='" . bp_get_groups_directory_permalink() . "?s=" . $search_string . "'>" . __('View group results', 'kleo_framework') . "</a>";
         $output .= "</div>";
     }
     //if there are posts
     if (!empty($posts)) {
         $post_types = array();
         $post_type_obj = array();
         foreach ($posts as $post) {
             $post_types[$post->post_type][] = $post;
             if (empty($post_type_obj[$post->post_type])) {
                 $post_type_obj[$post->post_type] = get_post_type_object($post->post_type);
             }
         }
         foreach ($post_types as $ptype => $post_type) {
             $output .= '<div class="kleo-ajax-part kleo-ajax-type-' . esc_attr($post_type_obj[$ptype]->name) . '">';
             if (isset($post_type_obj[$ptype]->labels->name)) {
                 $output .= "<h4><span>" . $post_type_obj[$ptype]->labels->name . "</span></h4>";
             } else {
                 $output .= "<hr>";
             }
             $count = 0;
             foreach ($post_type as $post) {
                 $count++;
                 if ($count > 4) {
                     continue;
                 }
                 $format = get_post_format($post->ID);
                 if ($img_url = kleo_get_post_thumbnail_url($post->ID)) {
                     $image = aq_resize($img_url, 44, 44, true, true, true);
                     if (!$image) {
                         $image = $img_url;
                     }
                     $image = '<img src="' . $image . '" class="kleo-rounded">';
                 } else {
                     if ($format == 'video') {
                         $image = "<i class='icon icon-video'></i>";
                     } elseif ($format == 'image' || $format == 'gallery') {
                         $image = "<i class='icon icon-picture'></i>";
                     } else {
                         $image = "<i class='icon icon-link'></i>";
                     }
                 }
                 $excerpt = "";
                 if (!empty($post->post_content)) {
                     $excerpt = char_trim(trim(strip_tags(strip_shortcodes($post->post_content))), 40, "...");
                 }
                 $link = apply_filters('kleo_custom_url', get_permalink($post->ID));
                 $classes = "format-" . $format;
                 $output .= "<div class ='kleo_ajax_entry {$classes}'>";
                 $output .= "<div class='ajax_search_image'>{$image}</div>";
                 $output .= "<div class='ajax_search_content'>";
                 $output .= "<a href='{$link}' class='search_title'>";
                 $output .= get_the_title($post->ID);
                 $output .= "</a>";
                 $output .= "<span class='search_excerpt'>";
                 $output .= $excerpt;
                 $output .= "</span>";
                 $output .= "</div>";
                 $output .= "</div>";
             }
             $output .= '</div>';
         }
         $output .= "<a class='ajax_view_all' href='" . home_url('/') . '?s=' . $search_string . "'>" . __('View all results', 'kleo_framework') . "</a>";
     }
     /* Forums topics search */
     if (!empty($forums)) {
         $output .= '<div class="kleo-ajax-part kleo-ajax-type-forums">';
         $output .= '<h4><span>' . __("Forums", 'kleo_framework') . '</span></h4>';
         $i = 0;
         foreach ($forums as $fk => $forum) {
             $i++;
             if ($i <= 4) {
                 $image = "<i class='icon icon-chat-1'></i>";
                 $output .= "<div class ='kleo_ajax_entry'>";
                 $output .= "<div class='ajax_search_image'>{$image}</div>";
                 $output .= "<div class='ajax_search_content'>";
                 $output .= "<a href='" . $forum['url'] . "' class='search_title'>";
                 $output .= $forum['name'];
                 $output .= "</a>";
                 //$output .= "<span class='search_excerpt'>";
                 //$output .= $latest_activity;
                 //$output .= "</span>";
                 $output .= "</div>";
                 $output .= "</div>";
             }
         }
         $output .= "<a class='ajax_view_all' href='" . bbp_get_search_url() . "?bbp_search=" . $search_string . "'>" . __('View forum results', 'kleo_framework') . "</a>";
         $output .= "</div>";
     }
     echo $output;
     die;
 }
Exemple #30
0
function bp_blogs_record_activity( $args = '' ) {
	global $bp;

	if ( !function_exists( 'bp_activity_add' ) )
		return false;

	/* Because blog, comment, and blog post code execution happens before anything else
	   we may need to manually instantiate the activity component globals */
	if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
		bp_activity_setup_globals();

	$defaults = array(
		'user_id' => $bp->loggedin_user->id,
		'action' => '',
		'content' => '',
		'primary_link' => '',
		'component' => $bp->blogs->id,
		'type' => false,
		'item_id' => false,
		'secondary_item_id' => false,
		'recorded_time' => bp_core_current_time(),
		'hide_sitewide' => false
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	/* Remove large images and replace them with just one image thumbnail */
 	if ( function_exists( 'bp_activity_thumbnail_content_images' ) && !empty( $content ) )
		$content = bp_activity_thumbnail_content_images( $content );

	if ( !empty( $action ) )
		$action = apply_filters( 'bp_blogs_record_activity_action', $action );

	if ( !empty( $content ) )
		$content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );

	/* Check for an existing entry and update if one exists. */
	$id = bp_activity_get_activity_id( array(
		'user_id' => $user_id,
		'component' => $component,
		'type' => $type,
		'item_id' => $item_id,
		'secondary_item_id' => $secondary_item_id
	) );

	return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
}