/** * Calculates the bible references for an activity before it is saved * * @param $activity */ function bfox_bp_activity_before_save($activity) { global $bp; // For blog posts, index the full post content and tags if ($activity->component == $bp->blogs->id && $activity->type == 'new_blog_post') { switch_to_blog($activity->item_id); $ref = bfox_blog_post_get_ref($activity->secondary_item_id); restore_current_blog(); } elseif ($activity->component == $bp->groups->id && ($activity->type == 'new_forum_post' || $activity->type == 'new_forum_topic')) { // Get the forum post if ($activity->type == 'new_forum_topic') { list($post) = bp_forums_get_topic_posts(array('topic_id' => $activity->secondary_item_id, 'per_page' => 1)); } else { $post = bp_forums_get_post($activity->secondary_item_id); } // Index the post text $ref = bfox_ref_from_content($post->post_text); // Only index the tags for the first post in a topic if ($activity->type == 'new_forum_topic') { $tags = bb_get_topic_tags($post->topic_id, array('fields' => 'names')); foreach ($tags as $tag) { $ref->add_ref(bfox_ref_from_tag($tag)); } } } else { $ref = bfox_ref_from_content($activity->content); } // Add any 'Bible Tag' read passage strings if ('activity_update' == $activity->type && isset($_REQUEST['bfox_read_ref_str'])) { $tag_ref = new BfoxRef($_REQUEST['bfox_read_ref_str']); if ($tag_ref->is_valid()) { $activity->bfox_read_ref_str = $tag_ref->get_string(); $activity->action = str_replace('posted an update', __('posted an update about ', 'bfox') . $activity->bfox_read_ref_str, $activity->action); $ref->add_ref($tag_ref); } } if ($ref->is_valid()) { $activity->bfox_ref = $ref; } }
/** * Constructor method. * * @param int $topic_id ID of the topic whose posts are being requested. * @param int $per_page Number of items to return per page. * @param int $max Max records to return. * @param string $order Direction to order results. */ function __construct($topic_id, $per_page, $max, $order) { global $bp, $current_user, $forum_template; if (!isset($forum_template)) { $forum_template = new stdClass(); } $this->pag_page = isset($_REQUEST['topic_page']) ? intval($_REQUEST['topic_page']) : 1; $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page; $this->order = $order; $this->topic_id = $topic_id; $forum_template->topic = (object) bp_forums_get_topic_details($this->topic_id); $this->forum_id = $forum_template->topic->forum_id; $this->posts = bp_forums_get_topic_posts(array('topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'order' => $this->order)); if (!$this->posts) { $this->post_count = 0; $this->total_post_count = 0; } else { if (!$max || $max >= (int) $forum_template->topic->topic_posts) { $this->total_post_count = (int) $forum_template->topic->topic_posts; } else { $this->total_post_count = (int) $max; } if ($max) { if ($max >= count($this->posts)) { $this->post_count = count($this->posts); } else { $this->post_count = (int) $max; } } else { $this->post_count = count($this->posts); } } // Load topic tags $this->topic_tags = bb_get_topic_tags($this->topic_id); $this->pag = new stdClass(); if ((int) $this->total_post_count && (int) $this->pag_num) { $this->pag_links = paginate_links(array('base' => add_query_arg(array('topic_page' => '%#%', 'num' => (int) $this->pag_num)), 'format' => '', 'total' => ceil((int) $this->total_post_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Forum thread pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Forum thread pagination next text', 'buddypress'), 'mid_size' => 1)); $this->pag->total_pages = ceil((int) $this->total_post_count / (int) $this->pag_num); } else { $this->pag->total_pages = 1; } }
/** * Delete a group forum topic and also any corresponding activity items. * * Uses the bundled version of bbPress packaged with BuddyPress. * * @since BuddyPress (1.1.0) * * @param int $topic_id The ID of the topic to be deleted. * * @return bool True if the delete routine went through properly. */ function groups_delete_group_forum_topic($topic_id) { $bp = buddypress(); // Before deleting the thread, get the post ids so that their activity items can be deleted $posts = bp_forums_get_topic_posts(array('topic_id' => $topic_id, 'per_page' => -1)); $action = bp_forums_delete_topic(array('topic_id' => $topic_id)); if (!empty($action)) { /** * Fires before the deletion of a group forum topic. * * @since BuddyPress (1.2.9) * * @param int $topic_id ID of the topic to be deleted. */ do_action('groups_before_delete_group_forum_topic', $topic_id); // Delete the corresponding activity stream items if (bp_is_active('activity')) { // The activity item for the initial topic bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic')); // The activity item for each post foreach ((array) $posts as $post) { bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post->post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post')); } } /** * Fires after the deletion of a group forum topic. * * @since BuddyPress (1.1.0) * * @param int $topic_id ID of the topic that was deleted. */ do_action('groups_delete_group_forum_topic', $topic_id); } return (bool) $action; }
function BP_Forums_Template_Topic( $topic_id, $per_page, $max, $order ) { global $bp, $current_user, $forum_template; $this->pag_page = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1; $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; $this->order = $order; $this->topic_id = $topic_id; $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id ); $this->forum_id = $forum_template->topic->forum_id; $this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'order' => $this->order ) ); if ( !$this->posts ) { $this->post_count = 0; $this->total_post_count = 0; } else { if ( !$max || $max >= (int)$forum_template->topic->topic_posts ) { $this->total_post_count = (int)$forum_template->topic->topic_posts; } else { $this->total_post_count = (int)$max; } if ( $max ) { if ( $max >= count( $this->posts ) ) { $this->post_count = count( $this->posts ); } else { $this->post_count = (int)$max; } } else { $this->post_count = count( $this->posts ); } } if ( (int)$this->total_post_count && (int)$this->pag_num ) { $this->pag_links = paginate_links( array( 'base' => add_query_arg( array( 'topic_page' => '%#%', 'num' => (int)$this->pag_num ) ), 'format' => '', 'total' => ceil( (int)$this->total_post_count / (int)$this->pag_num ), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1 ) ); $this->pag->total_pages = ceil( (int)$this->total_post_count / (int)$this->pag_num ); } else { $this->pag->total_pages = 1; } }
/** * Deletes a group forum topic and also any corresponding activity items. * * Uses the bundled version of bbPress packaged with BuddyPress. * * @package BuddyPress * * @uses bp_activity_delete() to delete corresponding activity items * @uses bp_forums_get_topic_posts() to get the child posts * @uses bp_forums_delete_topic() to do the deletion itself * @param int $topic_id The id of the topic to be deleted * @return bool True if the delete routine went through properly * * @since BuddyPress (1.1) */ function groups_delete_group_forum_topic($topic_id) { global $bp; // Before deleting the thread, get the post ids so that their activity items can be deleted $posts = bp_forums_get_topic_posts(array('topic_id' => $topic_id, 'per_page' => -1)); if (bp_forums_delete_topic(array('topic_id' => $topic_id))) { do_action('groups_before_delete_group_forum_topic', $topic_id); // Delete the corresponding activity stream items if (bp_is_active('activity')) { // The activity item for the initial topic bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic')); // The activity item for each post foreach ((array) $posts as $post) { bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post->post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post')); } } do_action('groups_delete_group_forum_topic', $topic_id); return true; } return false; }
function forum_post_convert_activity_args($args) { //in the 'new topic' activity we want to flag only the first post, not the whole topic $first_post = bp_forums_get_topic_posts(array('topic_id' => $args['id2'], 'post_status' => 'all', 'page' => 1, 'per_page' => 1)); $args['id2'] = $first_post[0]->post_id; return $args; }
function ass_digest_format_item($item, $type) { global $ass_email_css; $replies = ''; //load from the cache if it exists if ($item_cached = wp_cache_get('digest_item_' . $type . '_' . $item->id, 'ass')) { //$item_cached .= "GENERATED FROM CACHE"; return $item_cached; } /* Action text - This technique will not translate well */ // bbPress 2 support if (strpos($item->type, 'bbp_') !== false) { $action_split = explode(' in the forum', ass_clean_subject_html($item->action)); // regular group activity items } else { $action_split = explode(' in the group', ass_clean_subject_html($item->action)); } if ($action_split[1]) { $action = $action_split[0]; } else { $action = $item->action; } $action = ass_digest_filter($action); $action = str_replace(' started the forum topic', ' started', $action); // won't translate but it's not essential $action = str_replace(' posted on the forum topic', ' posted on', $action); $action = str_replace(' started the discussion topic', ' started', $action); $action = str_replace(' posted on the discussion topic', ' posted on', $action); /* Activity timestamp */ // $timestamp = strtotime( $item->date_recorded ); /* Because BuddyPress core set gmt = true, timezone must be added */ $timestamp = strtotime($item->date_recorded) + date('Z'); $time_posted = date(get_option('time_format'), $timestamp); $date_posted = date(get_option('date_format'), $timestamp); // Daily Digest if ($type == 'dig') { //$item_message = strip_tags( $action ) . ": \n"; $item_message = "<div {$ass_email_css['item_div']}>"; $item_message .= "<span {$ass_email_css['item_action']}>" . $action . ": "; $item_message .= "<span {$ass_email_css['item_date']}>" . sprintf(__('at %s, %s', 'bp-ass'), $time_posted, $date_posted) . "</span>"; $item_message .= "</span>\n"; // activity content if (!empty($item->content)) { $item_message .= "<br><span {$ass_email_css['item_content']}>" . apply_filters('ass_digest_content', $item->content, $item, $type) . "</span>"; } // view link if ($item->type == 'activity_update' || $item->type == 'activity_comment') { $item_message .= ' - <a href="' . bp_activity_get_permalink($item->id, $item) . '">' . __('View', 'bp-ass') . '</a>'; } else { $item_message .= ' - <a href="' . $item->primary_link . '">' . __('View', 'bp-ass') . '</a>'; } $item_message .= "</div>\n\n"; // Weekly summary } elseif ($type == 'sum') { // count the number of replies // @todo Remove this... only works for bundled forums and is hella ugly if ($item->type == 'new_forum_topic') { if ($posts = bp_forums_get_topic_posts('per_page=10000&topic_id=' . $item->secondary_item_id)) { foreach ($posts as $post) { $since = time() - strtotime($post->post_time); if ($since < 604800) { //number of seconds in a week $counter++; } } } $replies = ' ' . sprintf(__('(%s replies)', 'bp-ass'), $counter); } $item_message = "<div {$ass_email_css['item_weekly']}>" . $action . $replies; $item_message .= " <span {$ass_email_css['item_date']}>" . sprintf(__('at %s, %s', 'bp-ass'), $time_posted, $date_posted) . "</span>"; // activity content if (!empty($item->content)) { $item_message .= "<br><span {$ass_email_css['item_content']}>" . apply_filters('ass_digest_content', $item->content, $item, $type) . "</span>"; } // view link if ($item->type == 'activity_update' || $item->type == 'activity_comment') { $item_message .= ' - <a href="' . bp_activity_get_permalink($item->id, $item) . '">' . __('View', 'bp-ass') . '</a>'; } else { $item_message .= ' - <a href="' . $item->primary_link . '">' . __('View', 'bp-ass') . '</a>'; } $item_message .= "</div>\n\n"; } $item_message = apply_filters('ass_digest_format_item', $item_message, $item, $action, $timestamp, $type, $replies); $item_message = ass_digest_filter($item_message); // save the cache if ($item->id) { wp_cache_set('digest_item_' . $type . '_' . $item->id, $item_message, 'ass'); } return $item_message; }