/** * Main regex processing to extract dates and timespans, to be able to expand them later */ private function _processDateText($text) { $regEx = SELF::_constructRegEx(); $julGregPrefix = $regEx["julGregPrefix"]; $date = $regEx["date"]; $useGregJulPrefixes = intval(get_option('date_search_use_gregjul_prefixes')); $mainRegEx = $regEx["dateTimespan"]; // Default: Ignore prefixes switch ($useGregJulPrefixes) { case 1: $mainRegEx = $regEx["julGregDateTimeSpan"]; break; // 1 == old "true": Require [J]/[G] // 2 == optional prefix: honor if present, but also parse dates without prefix // 1 == old "true": Require [J]/[G] // 2 == optional prefix: honor if present, but also parse dates without prefix case 2: $mainRegEx = $regEx["optionalJulGregTimeSpan"]; break; } $allCount = preg_match_all("({$mainRegEx})i", $text, $allMatches); # echo "<pre>Count: $allCount\n" . print_r($allMatches,true) . "</pre>"; $cookedDates = array(); foreach ($allMatches[0] as $singleMatch) { $singleCount = preg_match_all("({$date})", $singleMatch, $singleSplit); $timespan = array(); $timespan[] = $singleSplit[0][0]; $timespan[] = $singleSplit[0][$singleCount == 2 ? 1 : 0]; $timespan = SELF::_expandTimespan($timespan); $storeDate = true; if ($useGregJulPrefixes > 0) { // Gregorian / Julian date prefixes $julGreg = preg_match("({$julGregPrefix})i", $singleMatch, $julGregMatch); $julGregJG = $julGreg == 1 ? strtoupper($julGregMatch[1]) : null; // "G" or "J" or null # echo "<pre>$julGreg / $julGregJG: " . print_r($julGregMatch,true) . "</pre>"; switch ($julGregJG) { case "J": $storeDate = $timespan[0] <= "1582-10-04"; break; case "G": $storeDate = $timespan[1] >= "1582-10-15"; break; } # echo "<pre>StoreDate: $storeDate\n" . print_r($timespan,true) . "</pre>"; } if ($storeDate) { $cookedDates[] = $timespan; } } # echo "<pre>" . print_r($cookedDates,true) . "</pre>"; # die(); return $cookedDates; }
/** * Main regex processing to extract dates and timespans, to be able to expand them later */ private function _processDateText($text) { $regEx = SELF::_constructRegEx(); $julGregPrefix = $regEx["julGregPrefix"]; $date = $regEx["date"]; $useGregJulPrexifes = intval(get_option('date_search_use_gregjul_prefixes')); $mainRegEx = $useGregJulPrexifes ? $regEx["julGregDateTimeSpan"] : $regEx["dateTimespan"]; $allCount = preg_match_all("({$mainRegEx})i", $text, $allMatches); # echo "<pre>Count: $allCount\n"; print_r($allMatches); die("</pre>"); $cookedDates = array(); foreach ($allMatches[0] as $singleMatch) { $singleCount = preg_match_all("({$date})", $singleMatch, $singleSplit); $timespan = array(); $timespan[] = $singleSplit[0][0]; $timespan[] = $singleSplit[0][$singleCount == 2 ? 1 : 0]; $timespan = SELF::_expandTimespan($timespan); $storeDate = true; if ($useGregJulPrexifes) { // Gregorian / Julian date prefixes $julGreg = preg_match("({$julGregPrefix})i", $singleMatch, $julGregMatch); $julGregJG = $julGreg == 1 ? strtoupper($julGregMatch[1]) : null; // "G" or "J" or null # echo "<pre>$julGreg / $julGregJG: "; print_r($julGregMatch); die("</pre>"); switch ($julGregJG) { case "J": $storeDate = $timespan[0] <= "1582-10-04"; break; case "G": $storeDate = $timespan[1] >= "1582-10-15"; break; } # echo "<pre>StoreDate: $storeDate\n"; print_r($timespan); die("</pre>"); } if ($storeDate) { $cookedDates[] = $timespan; } } #echo "<pre>"; print_r($cookedDates); die("</pre>"); return $cookedDates; }