/**
  * Returns bible verses
  *
  * @return Response
  */
 public function getBibleVerses()
 {
     $arr = array();
     $bibleVerses = BibleVerse::all();
     if (count($bibleVerses) == 0) {
         $arr['Success'] = false;
         $arr['Status'] = 'Verse not found';
         $arr['StatusCode'] = 404;
     } else {
         $arr['Success'] = true;
         $arr['Status'] = 'OK';
         $arr['StatusCode'] = 200;
         $i = 0;
         foreach ($bibleVerses as $verse) {
             $arr['Result'][$i]['book_order'] = $verse->book_order;
             $arr['Result'][$i]['chapter'] = $verse->chapter;
             $arr['Result'][$i]['verse'] = $verse->verse;
             $arr['Result'][$i]['bible_name'] = $verse->bible_name;
             $arr['Result'][$i]['language'] = $verse->language;
             $i++;
         }
     }
     return Response::json($arr);
 }
Exemple #2
0
 /**
  * Saves verse text to the DB and resets the verse data for the next verse
  *
  */
 private function save_verse()
 {
     $open_tags = array();
     if (!empty($this->vs) && !empty($this->vs['text'])) {
         // Store the currently open tags, so we can close them at the end of this verse,
         // and reopen them at the beginning of the next verse
         $open_tags = $this->verse_tag_stack;
         // Close any open tags
         $count = count($open_tags);
         for ($i = 0; $i < $count; $i++) {
             $this->add_close_tag();
         }
         $bible_verse = new BibleVerse($this->vs['book'], $this->vs['chapter'], $this->vs['verse']);
         // Save some stat data
         $id = $bible_verse->get_string();
         $verse_filter = TRUE;
         //$this->vs['book'] == 43 && $this->vs['chapter'] == 3; // John 3
         if ($verse_filter && 15 > count($this->verse_samples)) {
             // Save the verse
             $this->verse_samples[$id] = htmlspecialchars($this->vs['text']);
         }
         // Validate the XML
         libxml_use_internal_errors(true);
         $doc = '<verse_text>' . $this->vs['text'] . '</verse_text>';
         $xml = simplexml_load_string($doc, NULL, LIBXML_NOWARNING);
         if (!$xml) {
             $this->invalid_verses++;
             if (count($this->verse_xml_errors) < 10) {
                 $errors = libxml_get_errors();
                 foreach ($errors as &$error) {
                     $error->xml = $doc;
                 }
                 $this->verse_xml_errors[$id] = $errors;
                 libxml_clear_errors();
             }
         } else {
             $this->valid_verses++;
         }
         // Save the verse data to the DB
         if (!empty($this->table_name) && isset($this->vs['book'])) {
             BfoxTransInstaller::update_verse_text($this->table_name, $bible_verse, $this->vs['text']);
         }
     }
     // Reset the verse text
     $this->vs['text'] = '';
     $this->verse_tag_stack = array();
     // Reopen any tags that we had to close
     foreach ($open_tags as $tag) {
         $this->add_open_tag($tag);
     }
 }
 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;
 }