/** * Return the bible references for a given blog post * * @param $post * @return BfoxRef */ function bfox_blog_post_get_refs_for_taxonomies($post) { if (!is_object($post)) { $post = get_post($post); } $refs_for_taxonomies = array(); $taxonomies = bfox_post_type_ref_taxonomies($post->post_type); foreach ($taxonomies as $taxonomy) { if ('post_content' == $taxonomy) { $ref = bfox_ref_from_content($post->post_content); } else { $ref = new BfoxRef(); $terms = wp_get_post_terms($post->ID, $taxonomy, array('fields' => 'names')); foreach ($terms as $term) { $ref->add_ref(bfox_ref_from_tag($term)); } } if ($ref && $ref->is_valid()) { $refs_for_taxonomies[$taxonomy] = $ref; } unset($ref); } return $refs_for_taxonomies; }
/** * 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; } }