public function last_verse() { return BibleVerse::calc_ref($this->end()); }
/** * Creates an output string with a table row for each verse in the $verses data * * @param array $verses results from get_results() select statement with verse data * @param array $words the list of words to highlight as having been used in the search * @return string */ function chapter_content($verses) { $chapter_content = array(); if ('ESV' == $this->display_translation->short_name) { foreach ($verses as $unique_id => $match) { list($book, $chapter, $verse) = BibleVerse::calc_ref($unique_id); $book_name = BibleMeta::get_book_name($book); $chap_name = "{$book_name} {$chapter}"; $ref_str = "{$chap_name}:{$verse}"; $chapter_content[$chap_name][$ref_str] = $this->display_translation->get_javascript_placeholder($ref_str, __('Loading...', 'bfox')); } return $chapter_content; } $count = count($verses); if (0 < $count) { global $wpdb; // Get the verse data for these verses (from the global bible translation) $queries = array(); foreach ($verses as $unique_id => $match) { $queries[] = $wpdb->prepare('unique_id = %d', $unique_id); } $verses = $wpdb->get_results("SELECT * FROM {$this->display_translation->table} WHERE " . implode(' OR ', $queries)); unset($queries); // Turn the words into keys $words = array_fill_keys($this->words, TRUE); $book = 0; $chapter = 0; foreach ($verses as $verse) { if ($book != $verse->book_id || $chapter != $verse->chapter_id) { $book = $verse->book_id; $chapter = $verse->chapter_id; $book_name = BibleMeta::get_book_name($book); $chap_name = "{$book_name} {$chapter}"; $chapter_content[$chap_name] = array(); } // TODO3: Find a good way to display footnotes in search (until then, just get rid of them) $verse->verse = preg_replace('/<footnote>.*<\\/footnote>/Ui', '', $verse->verse); // Get the words in the verse as an associative array (use '_' as a part of a word) $verse_words = str_word_count($verse->verse, 2, '_'); // For each word in the verse that is also a search word, bold it foreach (array_reverse($verse_words, TRUE) as $pos => $verse_word) { if ($words[strtolower($verse_word)]) { $verse->verse = substr_replace($verse->verse, "<strong>{$verse_word}</strong>", $pos, strlen($verse_word)); } } $ref_str = "{$chap_name}:{$verse->verse_id}"; $chapter_content[$chap_name][$ref_str] = $verse->verse; } } return $chapter_content; }