function setRef(BfoxRef $ref) { if ($ref->is_valid()) { $this->ref = $ref; $this->setLastViewedRefStr($ref->get_string()); } }
/** * Returns a BfoxRef for the total of all Bible references in the reading plan * @param integer $post_id * @return BfoxRef $total_ref */ function bfox_plan_total_ref($post_id = 0) { $total_ref = new BfoxRef(); $reading_data = bfox_plan_reading_data($post_id); foreach ($reading_data->refs as $ref) { $total_ref->add_ref($ref); } return $total_ref; }
/** * Create an array of values to use in place of variables in template strings * * @param BfoxRef $ref * @return array */ private static function template_vars(BfoxRef $ref) { $book_name = ''; $ch1 = $vs1 = 0; if ($ref->is_valid()) { $bcvs = BfoxRef::get_bcvs($ref->get_seqs()); $books = array_keys($bcvs); $book_name = BibleMeta::get_book_name($books[0]); $cvs = array_shift($bcvs); $cv = array_shift($cvs); list($ch1, $vs1) = $cv->start; } return array('%ref%' => urlencode($ref->get_string()), '%book%' => urlencode($book_name), '%chapter%' => $ch1, '%verse%' => $vs1); }
function rowsForRef(BfoxRef $ref) { global $wpdb; $tableName = $wpdb->escape($this->tableName); $indexCol = $wpdb->escape($this->indexCol); $indexCol2 = $wpdb->escape($this->indexCol2); if (empty($indexCol2)) { $refWhere = $ref->sql_where($indexCol); } else { $refWhere = $ref->sql_where2($indexCol, $indexCol2); } $sql = $wpdb->prepare("SELECT * FROM {$tableName} WHERE {$refWhere}"); $rows = $wpdb->get_results($sql); return $rows; }
function parsePassagesIntoReadings($passages, $readingSize, $allowPassageGroups = true) { $readingSize = max(1, $readingSize); if ($allowPassageGroups) { $ref = BfoxRefParser::with_groups($passages); } else { $ref = new BfoxRef($passages); } if ($ref->is_valid()) { $readingRefs = $ref->get_sections($readingSize); foreach ($readingRefs as $readingRef) { if ($readingRef->is_valid()) { $this->addReading($readingRef); } } } return $readings; }
function pushRef(BfoxRef $ref) { $ranges = $ref->refRanges(); $elements = array(); foreach ($ranges as $range) { $elements = array_merge($elements, $this->pushRefRange($range)); } return $elements; }
function bfox_tool_shortcode($atts) { // [bible-tool tool="esv" ref="Matthew 1"] extract(shortcode_atts(array('tool' => '', 'ref' => ''), $atts)); $bfoxTools = BfoxBibleToolController::sharedInstance(); $tool = $bfoxTools->toolForShortName($tool); if (is_null($tool)) { return; } $ref = new BfoxRef($ref); if (!$ref->is_valid()) { return; } ob_start(); $tool->echoContentForRef($ref); $content = ob_get_clean(); return $content; }
function bfox_bp_bible_directory_before_activity_loop() { $ref = bfox_ref(); // Try to get a ref from the REQUEST params if there isn't already an active ref if (!empty($_REQUEST['bfox_ref']) && !$ref->is_valid()) { $ref = new BfoxRef(urldecode($_REQUEST['bfox_ref'])); if ($ref->is_valid()) { set_bfox_ref($ref); } } if ($ref->is_valid()) { // Make sure our bible references get added to the search terms add_filter('bp_ajax_querystring', 'bfox_bp_bible_directory_querystring', 20, 2); // Enable search term refs bfox_bp_activity_enable_search_term_refs(); // Disable the search term refs after the activity loop add_action('bp_after_activity_loop', 'bfox_bp_activity_disable_search_term_refs'); } }
function list_bfox_ref_chapters(BfoxRef $ref = null, $options = array()) { $defaults = array('format' => BibleMeta::name_none, 'first_format' => false, 'before' => '<li>', 'after' => '</li>', 'between' => '', 'link_cb' => 'bfox_ref_link', 'link_cb_options' => array()); extract(wp_parse_args($options, $defaults)); $chapters = $ref->get_sections(1); $strs = array(); foreach ($chapters as $chapter) { if ($first_format !== false) { $ref_str = $chapter->get_string($first_format); $first_format = false; } else { $ref_str = $chapter->get_string($format); } $link_cb_options['text'] = $ref_str; if ($link_cb && is_callable($link_cb)) { $ref_str = call_user_func($link_cb, $chapter->get_string(), $link_cb_options); } $strs[] = $before . $ref_str . $after; } return implode($between, $strs); }
function setRef(BfoxRef $ref) { $this->_ref = $ref; $this->_bookName = ''; $this->_chapterNum = $this->_verseNum = 0; if ($this->_ref->is_valid()) { $bcvs = BfoxRef::get_bcvs($this->_ref->get_seqs()); $books = array_keys($bcvs); $this->_bookName = BibleMeta::get_book_name($books[0]); $cvs = array_shift($bcvs); $cv = array_shift($cvs); list($this->_chapterNum, $this->_verseNum) = $cv->start; } foreach ($this->varCallbacks as $var => $callback) { $params = array(); if (isset($this->varCallbackParams[$var])) { $params = (array) $this->varCallbackParams[$var]; } $this->varValues[$var] = call_user_func_array($callback, $params); } }
function linkForTextAndRef($text, BfoxRef $ref) { return $this->linkForRefStr($ref->get_string(), array('text' => $text)); }
/** * Add the number part of a bible reference (ie, the 3:16 in John 3:16) * * @param BfoxRef $ref * @param integer $book_id * @param string $str */ private static function parse_book_str(BfoxRef &$ref, $book_id, $str) { // Spaces between numbers count as semicolons preg_replace('/(\\d)\\s+(\\d)/', '$1;$2', $str); // Periods between numbers count as colons $str = str_replace('.', ':', $str); $semis = explode(';', $str); foreach ($semis as $semi) { $commas = explode(',', $semi); $verse_chapter = 0; foreach ($commas as $comma) { $dash = explode('-', $comma, 2); $left = explode(':', $dash[0], 2); $ch1 = intval($left[0]); $vs1 = isset($left[1]) ? intval($left[1]) : 0; $ch2 = $vs2 = 0; if (isset($dash[1])) { $right = explode(':', $dash[1], 2); $ch2 = intval($right[0]); $vs2 = isset($right[1]) ? intval($right[1]) : 0; } // We must have a chapter1 if (0 != $ch1) { // If verse0 is not 0, but verse1 is 0, we should use chapter1 as verse1, and chapter1 should be 0 // This fixes the following type of case: 1:2-3 (1:2-3:0 becomes 1:2-0:3) if (0 != $vs1 && 0 == $vs2) { $vs2 = $ch2; $ch2 = 0; } // Whole Chapters (or whole verses) if (0 == $vs1 && 0 == $vs2) { $ref->add_whole($book_id, $ch1, $ch2, $verse_chapter); } elseif (0 == $ch2 || $ch1 == $ch2) { $verse_chapter = $ch1; $ref->add_inner($book_id, $verse_chapter, $vs1, $vs2); } else { $ref->add_mixed($book_id, $ch1, $vs1, $ch2, $vs2, $verse_chapter); $verse_chapter = $ch2; } } } } }
/** * Returns a WP_Query object with the posts that contain the given BfoxRef * * @param BfoxRef $ref * @return WP_Query */ function bfox_blog_query_for_ref(BfoxRef $ref) { return new WP_Query('s=' . urlencode($ref->get_string())); }
/** * Subtract bible references * * @param BfoxRef $ref */ public function sub_ref(BfoxRef $ref) { return $this->sub_seqs($ref->get_seqs()); }
public static function intersecting_readings($readings, BfoxRef $ref) { $intersecting = array(); foreach ($readings as $reading_id => $reading) { if ($ref->intersects($reading)) { $intersecting[] = $reading_id; } } return $intersecting; }
public function book_ref() { $bcvs = BfoxRef::get_bcvs($this->get_seqs()); $book_ref = new BfoxRef(); foreach ($bcvs as $book => $cvs) { $book_ref->add_whole_book($book); } return $book_ref; }
function linkForTextAndRef($text, BfoxRef $ref, $attributes = array()) { $attributes['text'] = $text; return $this->linkForRefStr($ref->get_string(), $attributes); }
public function possible_ref() { $ref = new BfoxRef($this->text); if (!$this->is_group) { $ref->add_string($this->ref_str); } return $ref; }
function bfox_wp_get_object_terms($terms) { $hidden_ref = new BfoxRef($_REQUEST['bfox_ref']); if ($hidden_ref->is_valid()) { $term = new stdClass(); $term->name = $hidden_ref->get_string(); $terms = array($term); } return $terms; }
/** * Return the bible references for a given blog post * * @param $post * @return BfoxRef */ function refsForTaxonomiesOfPost($post) { if (!is_object($post)) { $post = get_post($post); } $refs_for_taxonomies = array(); if (!$post) { return $refs_for_taxonomies; } $taxonomies = $this->indexedTaxonomiesForPostType($post->post_type); foreach ($taxonomies as $taxonomy) { if ('post_content' == $taxonomy) { $ref = $this->core->refs->refFromPostContent($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($this->core->refs->refFromTag($term)); } } if ($ref && $ref->is_valid()) { $refs_for_taxonomies[$taxonomy] = $ref; } unset($ref); } return $refs_for_taxonomies; }
<?php // Limit the ref to 10 chapters $input_ref = new BfoxRef($_REQUEST['bfoxp']); list($ref) = $input_ref->get_sections(10, 1); $trans_ids = BfoxTrans::get_ids_by_short_name(); $trans = new BfoxTrans($trans_ids[$_REQUEST['trans']]); // Get the show options param (default is to show options) $show_options = !(isset($_REQUEST['opts']) && !$_REQUEST['opts']); $allow_tooltips = !!$_REQUEST['allow_tooltips']; // TODO: We shouldn't really use tooltips on the print screen, but use inline scriptures if (!$allow_tooltips) { wp_deregister_script('bfox-blog'); } // All we need are the scripture styles and script // TODO: Buddypress is adding a few other syles which we don't need to load here wp_enqueue_script('bfox-theme-print', BFOX_TRANS_URL . '/theme/print.js', array('jquery')); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?> > <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?> ; charset=<?php
function bfox_plan_reading_shortcode($atts) { // [bible-reading plan="cbr" intersects="old"] extract(shortcode_atts(array('post_id' => 0, 'reading' => 'latest', 'intersects' => '', 'tool' => ''), $atts)); if (empty($post_id)) { return; } if ($reading == 'latest') { $reading = bfox_plan_latest_reading($post_id); } $reading_id = intval($reading); if ($reading_id >= bfox_plan_reading_count($post_id)) { return; } $ref_str = bfox_plan_reading_ref_str($reading_id, $post_id); if (!empty($intersects)) { $ref = new BfoxRef($ref_str); $sub = new BibleGroupPassage('bible'); $sub->sub_ref(new BibleGroupPassage($intersects)); $ref->sub_ref($sub); $ref_str = $ref->get_string(); } $link = bfox_ref_link($ref_str); $content = $link; if (!empty($tool)) { $passage = bfox_tool_shortcode(array('tool' => $tool, 'ref' => $ref_str)); $content = "{$link} {$passage}"; } return $content; }
public function test_add_ref() { $start = 'eze 14:10'; $adds = array('eze 14:8-9', 'eze 14:6-7', 'eze 14:5-8', 'eze 14:4', 'eze 14:4-11', 'eze 14:5', 'eze 14:4-11', 'eze 14:4-5', 'eze 14:10-11', 'eze 14:1-2', 'eze 14:3-12', 'eze 13', 'eze 14:13-22', 'eze 15:1-100', 'eze 14:23'); //$adds = array('eze 14:10'); $ref = new BfoxRef($start); pre("start:" . $ref->get_string()); foreach ($adds as $add) { $add_ref = new BfoxRef($add); $is_modified = $ref->add_ref($add_ref); pre(" + " . $add_ref->get_string() . " = " . $ref->get_string() . ' modified? ' . ($is_modified ? 'yes' : 'no')); //pre($ref); } }
/** * 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; } }
/** * Return verse content for the given bible ref with minimum formatting * * @param BfoxRef $ref * @return string */ public function get_verse_content(BfoxRef $ref) { // Get the verse data from the bible translation $formatter = new BfoxVerseFormatter(); return $this->get_verses($ref->sql_where(), $formatter); }