Пример #1
0
function bfox_ref_links(BfoxRef $ref, $options = array())
{
    $serializer = new BfoxRefSerializer();
    $serializer->setCombineNone();
    $elements = $serializer->elementsForRef($ref);
    $str = '';
    foreach ($elements as $index => $element) {
        if ($index % 2 == 0) {
            $str .= bfox_ref_link($element, $options);
        } else {
            $str .= $element;
        }
    }
    return $str;
}
 /**
  * @return BfoxRefSerializer
  */
 static function sharedInstance()
 {
     if (is_null(self::$_sharedInstance)) {
         self::$_sharedInstance = new BfoxRefSerializer();
     }
     return self::$_sharedInstance;
 }
 /**
  * Returns a string of links for the passed in Bible reference, uses separate links for each individual range of verses
  *
  * Example: Genesis 1-2,4 would become two separate links [Genesis 1-2]; [Genesis 4] because chapters 1-2 are not contiguous with chapter 4
  * For returning [Genesis 1-2,4] use the link() function
  *
  * @param mixed $ref string or BfoxRef
  * @param array $attributes Attributes for the links
  * @return string
  */
 function links($ref, $attributes = array())
 {
     if (!is_a($ref, 'BfoxRef')) {
         $ref = new BfoxRef($ref);
     }
     $serializer = new BfoxRefSerializer();
     $serializer->setCombineNone();
     $elements = $serializer->elementsForRef($ref);
     $linksString = '';
     foreach ($elements as $index => $element) {
         if ($index % 2 == 0) {
             $linksString .= $this->link($element, $attributes);
         } else {
             $linksString .= $element;
         }
     }
     return $linksString;
 }
Пример #4
0
 /**
  * Get the string
  *
  * @return string
  */
 public function get_string($name = '')
 {
     $serializer = BfoxRefSerializer::sharedInstance();
     $serializer->bookNameFormat = $name;
     $serializer->pushRef($this);
     return $serializer->popResult();
 }
Пример #5
0
 /**
  * Tests different bible reference input strings
  *
  */
 function test_refs()
 {
     $start = microtime(true);
     // Test the typical references
     $this->test_ref('1 sam', '1 Samuel');
     $this->test_ref('1sam 1', '1 Samuel 1');
     $this->test_ref('1sam 1-2', '1 Samuel 1-2');
     $this->test_ref('1sam 1:1', '1 Samuel 1:1');
     $this->test_ref('1sam 1:1-5', '1 Samuel 1:1-5');
     $this->test_ref('1sam 1:1-2:5', '1 Samuel 1:1-2:5');
     $this->test_ref('1sam 1:2-2:5', '1 Samuel 1:2-2:5');
     $this->test_ref('1sam 1-2:5', '1 Samuel 1:1-2:5');
     // Test Serializer options
     $serializer = BfoxRefSerializer::sharedInstance();
     $serializer->setCombineNone();
     $this->test_ref('Gen 1:1,3', 'Genesis 1:1; Genesis 1:3');
     $serializer->setCombineBooks();
     $this->test_ref('Gen 1:1,3', 'Genesis 1:1; 1:3');
     $serializer->setCombineChapters();
     $this->test_ref('Gen 1:1,3', 'Genesis 1:1,3');
     // Test periods
     $this->test_ref('1sam. 1', '1 Samuel 1');
     $this->test_ref('1sam 1.1', '1 Samuel 1:1');
     $this->test_ref('1sam 1.1-5', '1 Samuel 1:1-5');
     $this->test_ref('1sam 1.1-2.5', '1 Samuel 1:1-2:5');
     $this->test_ref('1sam 1.2-2.5', '1 Samuel 1:2-2:5');
     $this->test_ref('1sam 1-2.5', '1 Samuel 1:1-2:5');
     // This test was failing (see bug 21)
     $this->test_ref('Judges 2:6-3:6', 'Judges 2:6-3:6');
     // Test ignore words
     $this->test_ref('Book of Judges 2', 'Judges 2');
     $this->test_ref('First Book of Judges 2', 'error', 'This one should not work, but I dont remember why not...');
     // This one should not work!
     $this->test_ref('First Book of Samuel 2', '1 Samuel 2');
     // Test that we can match synonyms with multiple words
     $this->test_ref('Song of Solomon 2', 'Song of Solomon 2');
     // This should be Gen 1:1, 1:3 - 2:3
     $this->test_ref('gen 1:1,3-2:3', 'Genesis 1:1,3-2:3');
     $this->test_ref('gen 1-100', 'Genesis');
     $this->test_ref('gen 2-100', 'Genesis 2-50');
     $this->test_ref('gen 49:1-100', 'Genesis 49');
     $this->test_ref('gen 49:2-100', 'Genesis 49:2-33');
     $this->test_ref('gen 50:1-100', 'Genesis 50');
     $this->test_ref('gen 50:2-100', 'Genesis 50:2-26');
     $this->test_ref('gen 50:1,2-100', 'Genesis 50');
     $this->test_ref('gen 50:1,3-100', 'Genesis 50:1,3-26');
     // Test min/max in Romans 14
     $this->test_ref('rom 14:2-100', 'Romans 14:2-26');
     $this->test_ref('rom 14:1-22', 'Romans 14:1-22');
     $this->test_ref('rom 14:1-23', 'Romans 14');
     $this->test_ref('rom 14:2-23', 'Romans 14:2-26');
     // Test having consecutive books
     $this->test_ref('Gen 2-100, Exodus', 'Genesis 2 - Exodus 40');
     $this->test_ref('Gen 2-100, Exodus, Lev', 'Genesis 2 - Leviticus 27');
     // Test long strings with lots of garbage
     $this->test_ref('hello dude genesis 1,;,2 gen 5 1 sam 4, song ;of song 3', 'Genesis 1-2; 5; 1 Samuel 4; Song of Solomon');
     // TODO3: words like song get detected as the entire book Song of Solomon
     $this->test_ref("<xml>\n\t\t<p>I like Gen 1.</p>\n\t\t<p>What do you think? john. 21 Do you prefer<d><d> ex 2 or 1sam 3 - 4 or 1 th 4? gen 3:4-8:2 gen 3ddd:2 fff- 1 1 3 </p>\n\t\t<p>exodus lala yoyo 4:5</p>\n\t\t</xml>\n\t\t", 'Genesis 1; 3:1-8:2; Exodus; 1 Samuel 3-4; John 21; 1 Thessalonians 4');
     // TODO3: 'ex' is not detected because it is only 2 letters
     // Test non-existent chapter
     $this->test_ref('2jhn 2', 'Invalid', 'non-existent chapter');
     $this->test_ref('hag 3', 'Invalid', 'non-existent chapter');
     $this->test_ref('hag 2-3', 'Haggai 2', 'ends with non-existent chapter');
     $this->test_ref('hag 1-3', 'Haggai', 'ends with non-existent chapter');
     $this->test_ref('hag 5-7', 'Invalid', 'non-existent chapters');
     $this->test_ref('hag 1:100-2:4', 'Haggai 2:1-4', 'begins with non-existent verse');
     // This test fails unless parsing in reverse
     $this->test_ref('Genesis 3; 1 Samuel 5', 'Genesis 3; 1 Samuel 5', 'Only works in reverse');
     $end = microtime(true);
     pre("start: {$start}");
     pre("end: {$end}");
     pre("Took " . ($end - $start) . " seconds");
     pre("Unexpected: {$this->test_ref_unexpected}");
     pre("Unequal: {$this->test_ref_unequal}");
 }