public static function words($words, $string) { // Array of needles to look for. // The needles contain the search $words as they occur in the $string // in upper case or lower case, or any mixed case. $needles = array(); foreach ($words as $word) { if ($word == "") { continue; } $needles = array_merge($needles, Filter_Search::needles($word, $string)); } $needles = array_unique($needles); // All the $needles are converted to $markup, // which will replace the $needles. $markup = array(); foreach ($needles as $needle) { $markup[] = '<mark>' . $needle . '</mark>'; } // Do the replacement. $string = str_replace($needles, $markup, $string); // Result. return $string; }
// Get the old USFM into an array of verse => USFM fragment. $usfmArray = array(); $usfmString = $database_bibles->getChapter($bible, $book, $chapter); $verses = Filter_Usfm::getVerseNumbers($usfmString); $verses = array_unique($verses); sort($verses, SORT_NUMERIC); foreach ($verses as $vs) { $usfmArray[$vs] = Filter_Usfm::getVerseText($usfmString, $vs); } // Do the replacing in the correct verse of the raw USFM, and count how many replacements were made. $usfm = $usfmArray[$verse]; $usfmReplacementCount = 0; if ($casesensitive) { $usfm = str_replace($searchfor, $replacewith, $usfm, $usfmReplacementCount); } else { $needles = Filter_Search::needles($searchfor, $usfm); $usfm = str_replace($needles, $replacewith, $usfm, $usfmReplacementCount); } $usfmArray[$verse] = $usfm; // Create the updated chapter USFM as a string. $updatedUsfm = implode("\n", $usfmArray); // Text filter for getting the new plain text from the new USFM. // This is for search/replace in plain text, not in USFM. if ($searchplain) { $filter_text = new Filter_Text($bible); $filter_text->text_text = new Text_Text(); $filter_text->initializeHeadingsAndTextPerVerse(); $filter_text->addUsfmCode($updatedUsfm); $filter_text->run($stylesheet); } // Get the updated plain text of the correct verse of the updated USFM.
@($id = $_GET['id']); // Get the Bible and passage for this identifier. $details = $database_search->getBiblePassage($id); $bible = $details['bible']; $book = $details['book']; $chapter = $details['chapter']; $verse = $details['verse']; // Get the plain text. $text = $database_search->getBibleVerseText($bible, $book, $chapter, $verse); // Clickable passage. $link = Filter_Books::linkForOpeningEditorAt($book, $chapter, $verse); $oldtext = Filter_Markup::words(array($searchfor), $text); if ($casesensitive) { $newtext = str_replace($searchfor, $replacewith, $text); } else { $needles = Filter_Search::needles($searchfor, $text); $newtext = str_replace($needles, $replacewith, $text); } if ($replacewith != "") { $newtext = Filter_Markup::words(array($replacewith), $newtext); } // The id sent to the browser contains bible identifier, book, chapter, and verse. $bibleID = $database_bibles->getID($bible); $id = implode("_", array($bibleID, $book, $chapter, $verse)); // Create output. $output = <<<EOD <div id="{$id}"> <p><a href="replace"> ✔ </a> <a href="delete"> ✗ </a> {$link}</p> <p>{$oldtext}</p> <p>{$newtext}</p> </div>