/** * @covers Symfony\Polyfill\Iconv\Iconv::iconv_strpos * @covers Symfony\Polyfill\Iconv\Iconv::iconv_strrpos */ public function testIconvStrPos() { $this->assertSame(1, iconv_strpos('11--', '1-', 0, 'UTF-8')); $this->assertSame(2, iconv_strpos('-11--', '1-', 0, 'UTF-8')); $this->assertSame(false, iconv_strrpos('한국어', '', 'UTF-8')); $this->assertSame(1, iconv_strrpos('한국어', '국', 'UTF-8')); }
/** * mb_strpos() * * WARNING: This function WILL fall-back to strpos() * if iconv is not available! * * @link http://php.net/mb_strpos() * @param string $haystack * @param string $needle * @param int $offset * @param string $encoding * @return mixed */ function mb_strpos($haystack, $needle, $offset = 0, $encoding = NULL) { if (ICONV_ENABLED === TRUE) { return iconv_strpos($haystack, $needle, $offset, isset($encoding) ? $encoding : config_item('charset')); } log_message('debug', 'Compatibility (mbstring): iconv_strpos() is not available, falling back to strpos().'); return strpos($haystack, $needle, $offset); }
function _strpos($str, $search, $offset = null) { if (is_null($offset)) { $old_enc = $this->_setUTF8IconvEncoding(); $result = iconv_strpos($str, $search); $this->_setIconvEncoding($old_enc); return $result; } else { return iconv_strpos($str, $search, (int) $offset, 'utf-8'); } }
function foo($haystk, $needle, $offset, $to_charset = false, $from_charset = false) { if ($from_charset !== false) { $haystk = iconv($from_charset, $to_charset, $haystk); } var_dump(strpos($haystk, $needle, $offset)); if ($to_charset !== false) { var_dump(iconv_strpos($haystk, $needle, $offset, $to_charset)); } else { var_dump(iconv_strpos($haystk, $needle, $offset)); } }
/** * Word wrap * * @param string $string * @param integer $width * @param string $break * @param boolean $cut * @param string $charset * @return string */ public static function wordWrap($string, $width = 75, $break = "\n", $cut = false, $charset = 'UTF-8') { $result = array(); while (($stringLength = iconv_strlen($string, $charset)) > 0) { $subString = iconv_substr($string, 0, $width, $charset); if ($subString === $string) { $cutLength = null; } else { $nextChar = iconv_substr($string, $width, 1, $charset); if ($nextChar === ' ' || $nextChar === $break) { $afterNextChar = iconv_substr($string, $width + 1, 1, $charset); if ($afterNextChar === false) { $subString .= $nextChar; } $cutLength = iconv_strlen($subString, $charset) + 1; } else { $spacePos = iconv_strrpos($subString, ' ', $charset); if ($spacePos !== false) { $subString = iconv_substr($subString, 0, $spacePos, $charset); $cutLength = $spacePos + 1; } else { if ($cut === false) { $spacePos = iconv_strpos($string, ' ', 0, $charset); if ($spacePos !== false) { $subString = iconv_substr($string, 0, $spacePos, $charset); $cutLength = $spacePos + 1; } else { $subString = $string; $cutLength = null; } } else { $breakPos = iconv_strpos($subString, $break, 0, $charset); if ($breakPos !== false) { $subString = iconv_substr($subString, 0, $breakPos, $charset); $cutLength = $breakPos + 1; } else { $subString = iconv_substr($subString, 0, $width, $charset); $cutLength = $width; } } } } } $result[] = $subString; if ($cutLength !== null) { $string = iconv_substr($string, $cutLength, $stringLength - $cutLength, $charset); } else { break; } } return implode($break, $result); }
protected static function grapheme_position($s, $needle, $offset, $mode) { if ($offset > 0) { $s = (string) self::grapheme_substr($s, $offset); } else { if ($offset < 0) { $offset = 0; } } if ('' === (string) $needle) { return false; } if ('' === (string) $s) { return false; } switch ($mode) { case 0: $needle = iconv_strpos($s, $needle, 0, 'UTF-8'); break; case 1: $needle = mb_stripos($s, $needle, 0, 'UTF-8'); break; case 2: $needle = iconv_strrpos($s, $needle, 'UTF-8'); break; default: $needle = mb_strripos($s, $needle, 0, 'UTF-8'); break; } return $needle ? self::grapheme_strlen(iconv_substr($s, 0, $needle, 'UTF-8')) + $offset : $needle; }
/** * gets the information required for formating the currency from the LDML files * * @return Zend_Currency * @throws Zend_Currency_Exception */ protected function _updateFormat() { $formatLocale = $this->_formatLocale; if (empty($formatLocale)) { $this->_formatLocale = $this->_currencyLocale; $formatLocale = $this->_formatLocale; } //getting the format information of the currency $format = Zend_Locale_Data::getContent($formatLocale, 'currencyformat'); $format = $format['default']; iconv_set_encoding('internal_encoding', 'UTF-8'); if (iconv_strpos($format, ';')) { $format = iconv_substr($format, 0, iconv_strpos($format, ';')); } //knowing the sign positioning information if (iconv_strpos($format, '¤') == 0) { $this->_signPosition = self::LEFT; } else { if (iconv_strpos($format, '¤') == iconv_strlen($format) - 1) { $this->_signPosition = self::RIGHT; } } return $this; }
function appnet_create_entities($a, $b, $postdata) { require_once "include/bbcode.php"; require_once "include/plaintext.php"; $bbcode = $b["body"]; $bbcode = bb_remove_share_information($bbcode, false, true); // Change pure links in text to bbcode uris $bbcode = preg_replace("/([^\\]\\='" . '"' . "]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode); $URLSearchString = "^\\[\\]"; $bbcode = preg_replace("/#\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '#$2', $bbcode); $bbcode = preg_replace("/@\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '@$2', $bbcode); $bbcode = preg_replace("/\\[bookmark\\=([{$URLSearchString}]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $bbcode); $bbcode = preg_replace("/\\[video\\](.*?)\\[\\/video\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[youtube\\]https?:\\/\\/(.*?)\\[\\/youtube\\]/ism", '[url=https://$1]https://$1[/url]', $bbcode); $bbcode = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", '[url=https://www.youtube.com/watch?v=$1]https://www.youtube.com/watch?v=$1[/url]', $bbcode); $bbcode = preg_replace("/\\[vimeo\\]https?:\\/\\/(.*?)\\[\\/vimeo\\]/ism", '[url=https://$1]https://$1[/url]', $bbcode); $bbcode = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[url=https://vimeo.com/$1]https://vimeo.com/$1[/url]', $bbcode); //$bbcode = preg_replace("/\[vimeo\](.*?)\[\/vimeo\]/ism",'[url=$1]$1[/url]',$bbcode); $bbcode = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '[img]$3[/img]', $bbcode); preg_match_all("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", $bbcode, $urls, PREG_SET_ORDER); $bbcode = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '$1', $bbcode); $b["body"] = $bbcode; // To-Do: // Bilder // https://alpha.app.net/heluecht/post/32424376 // https://alpha.app.net/heluecht/post/32424307 $plaintext = plaintext($a, $b, 0, false, 6); $text = $plaintext["text"]; $start = 0; $entities = array(); foreach ($urls as $url) { $lenurl = iconv_strlen($url[1], "UTF-8"); $len = iconv_strlen($url[2], "UTF-8"); $pos = iconv_strpos($text, $url[1], $start, "UTF-8"); $pre = iconv_substr($text, 0, $pos, "UTF-8"); $post = iconv_substr($text, $pos + $lenurl, 1000000, "UTF-8"); $mid = $url[2]; $html = bbcode($mid, false, false, 6); $mid = html2plain($html, 0, true); $mid = trim(html_entity_decode($mid, ENT_QUOTES, 'UTF-8')); $text = $pre . $mid . $post; if ($mid != "") { $entities[] = array("pos" => $pos, "len" => $len, "url" => $url[1], "text" => $mid); } $start = $pos + 1; } if (isset($postdata["url"]) and isset($postdata["title"]) and $postdata["type"] != "photo") { $postdata["title"] = shortenmsg($postdata["title"], 90); $max = 256 - strlen($postdata["title"]); $text = shortenmsg($text, $max); $text .= "\n[" . $postdata["title"] . "](" . $postdata["url"] . ")"; } elseif (isset($postdata["url"]) and $postdata["type"] != "photo") { $postdata["url"] = short_link($postdata["url"]); $max = 240; $text = shortenmsg($text, $max); $text .= " [" . $postdata["url"] . "](" . $postdata["url"] . ")"; } else { $max = 256; $text = shortenmsg($text, $max); } if (iconv_strlen($text, "UTF-8") < $max) { $max = iconv_strlen($text, "UTF-8"); } krsort($entities); foreach ($entities as $entity) { //if (iconv_strlen($text, "UTF-8") >= $entity["pos"] + $entity["len"]) { if ($entity["pos"] + $entity["len"] <= $max) { $pre = iconv_substr($text, 0, $entity["pos"], "UTF-8"); $post = iconv_substr($text, $entity["pos"] + $entity["len"], 1000000, "UTF-8"); $text = $pre . "[" . $entity["text"] . "](" . $entity["url"] . ")" . $post; } } return $text; }
/** * Returns if the given datestring contains all date parts from the given format. * If no format is given, the default date format from the locale is used * If you want to check if the date is a proper date you should use Zend_Date::isDate() * * @param string $date Date string * @param array $options Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details. * @return boolean */ public static function checkDateFormat($date, array $options = array()) { try { $date = self::getDate($date, $options); } catch (Exception $e) { return false; } if (empty($options['date_format'])) { $options['format_type'] = 'iso'; $options['date_format'] = self::getDateFormat($options['locale']); } $options = self::_checkOptions($options) + self::$_options; // day expected but not parsed if (iconv_strpos($options['date_format'], 'd', 0, 'UTF-8') !== false and (!isset($date['day']) or $date['day'] === "")) { return false; } // month expected but not parsed if (iconv_strpos($options['date_format'], 'M', 0, 'UTF-8') !== false and (!isset($date['month']) or $date['month'] === "")) { return false; } // year expected but not parsed if ((iconv_strpos($options['date_format'], 'Y', 0, 'UTF-8') !== false or iconv_strpos($options['date_format'], 'y', 0, 'UTF-8') !== false) and (!isset($date['year']) or $date['year'] === "")) { return false; } // second expected but not parsed if (iconv_strpos($options['date_format'], 's', 0, 'UTF-8') !== false and (!isset($date['second']) or $date['second'] === "")) { return false; } // minute expected but not parsed if (iconv_strpos($options['date_format'], 'm', 0, 'UTF-8') !== false and (!isset($date['minute']) or $date['minute'] === "")) { return false; } // hour expected but not parsed if ((iconv_strpos($options['date_format'], 'H', 0, 'UTF-8') !== false or iconv_strpos($options['date_format'], 'h', 0, 'UTF-8') !== false) and (!isset($date['hour']) or $date['hour'] === "")) { return false; } return true; }
/** * Gets the information required for formating the currency from Zend_Locale * * @return Zend_Currency */ protected function _updateFormat() { $locale = empty($this->_options['format']) === true ? $this->_locale : $this->_options['format']; // Getting the format information of the currency $format = Zend_Locale_Data::getContent($locale, 'currencynumber'); iconv_set_encoding('internal_encoding', 'UTF-8'); if (iconv_strpos($format, ';') !== false) { $format = iconv_substr($format, 0, iconv_strpos($format, ';')); } // Knowing the sign positioning information if (iconv_strpos($format, '¤') === 0) { $position = self::LEFT; } else { if (iconv_strpos($format, '¤') === iconv_strlen($format) - 1) { $position = self::RIGHT; } } return $position; }
/** * Find position of first occurrence of a string, both arguments are in UTF-8. * * @param string $haystack UTF-8 string to search in * @param string $needle UTF-8 string to search for * @param int $offset Position to start the search * @return int The character position * @see strpos() */ public function utf8_strpos($haystack, $needle, $offset = 0) { if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] === 'mbstring') { return mb_strpos($haystack, $needle, $offset, 'utf-8'); } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] === 'iconv') { return iconv_strpos($haystack, $needle, $offset, 'utf-8'); } $byte_offset = $this->utf8_char2byte_pos($haystack, $offset); if ($byte_offset === FALSE) { // Offset beyond string length return FALSE; } $byte_pos = strpos($haystack, $needle, $byte_offset); if ($byte_pos === FALSE) { // Needle not found return FALSE; } return $this->utf8_byte2char_pos($haystack, $byte_pos); }
/** * Calculate several measures necessary to generate a bar. * * @return void */ protected function calculateMeasures() { // Calc number of steps bar goes through $this->numSteps = (int) round($this->max / $this->properties['options']->step); // Calculate measures $this->measures['fixedCharSpace'] = iconv_strlen($this->stripEscapeSequences($this->insertValues()), 'UTF-8'); if (iconv_strpos($this->properties['options']->formatString, '%max%', 0, 'UTF-8') !== false) { $this->measures['maxSpace'] = iconv_strlen(sprintf($this->properties['options']->maxFormat, $this->max), 'UTF-8'); } if (iconv_strpos($this->properties['options']->formatString, '%act%', 0, 'UTF-8') !== false) { $this->measures['actSpace'] = iconv_strlen(sprintf($this->properties['options']->actFormat, $this->max), 'UTF-8'); } if (iconv_strpos($this->properties['options']->formatString, '%fraction%', 0, 'UTF-8') !== false) { $this->measures['fractionSpace'] = iconv_strlen(sprintf($this->properties['options']->fractionFormat, 100), 'UTF-8'); } $this->measures['barSpace'] = $this->properties['options']->width - array_sum($this->measures); }
/** * Разбивает строку символом перевода строки на месте проблема наиболее приближенного к центру строки * @param string $string */ protected function divideString($string) { $lastPos = 0; $positions = array(); while (($pos = iconv_strpos($string, ' ', $lastPos, 'UTF-8')) !== false) { $positions[abs(iconv_strlen($string, 'UTF-8') - $pos * 2)] = $pos; $lastPos = $pos + 1; } if (count($positions)) { ksort($positions); $centeredPos = 0; foreach ($positions as $pos) { $centeredPos = $pos; break; } return iconv_substr($string, 0, $pos, 'UTF-8') . "\n" . iconv_substr($string, $pos + 1, iconv_strlen($string, 'UTF-8'), 'UTF-8'); } return false; }
/** * Validates the checksum () * * @param string $value The barcode to validate * @return boolean */ protected function _code128($value) { $sum = 0; $pos = 1; $set = $this->_getCodingSet($value); $read = $set; $hascheck = $this->_hasChecksum; $char = iconv_substr($value, 0, 1, 'UTF-8'); if ($char == '‡') { $sum = 103; } else { if ($char == 'ˆ') { $sum = 104; } else { if ($char == '‰') { $sum = 105; } else { if ($hascheck == true) { // no start value, unable to detect an proper checksum return false; } } } } $value = iconv_substr($value, 1, iconv_strlen($value, 'UTF-8'), 'UTF-8'); while (iconv_strpos($value, 'Š') || $value != '') { $char = iconv_substr($value, 0, 1, 'UTF-8'); if ($read == 'C') { $char = iconv_substr($value, 0, 2, 'UTF-8'); } switch ($char) { // Function definition case 'Ç': case 'ü': case 'å': $sum += $pos * $this->_ord128($char, $set); break; case 'é': $sum += $pos * $this->_ord128($char, $set); if ($set == 'A') { $read = 'B'; } else { if ($set == 'B') { $read = 'A'; } } break; // Switch to C // Switch to C case 'â': $sum += $pos * $this->_ord128($char, $set); $set = 'C'; $read = 'C'; break; // Switch to B // Switch to B case 'ä': $sum += $pos * $this->_ord128($char, $set); $set = 'B'; $read = 'B'; break; // Switch to A // Switch to A case 'à': $sum += $pos * $this->_ord128($char, $set); $set = 'A'; $read = 'A'; break; case '‡': case 'ˆ': case '‰': return false; break; default: // Does the char exist within the charset to read? if ($this->_ord128($char, $read) == -1) { return false; } $sum += $pos * $this->_ord128($char, $set); break; } $value = iconv_substr($value, 1, iconv_strlen($value, 'UTF-8'), 'UTF-8'); ++$pos; if (iconv_strpos($value, 'Š', 0, 'UTF-8') == 1 && iconv_strlen($value, 'UTF-8') == 2) { // break by stop and checksum char break; } $read = $set; } if (iconv_strpos($value, 'Š', 0, 'UTF-8') != 1 || iconv_strlen($value, 'UTF-8') != 2) { // return false if checksum is not readable and true if no startvalue is detected return !$hascheck; } $mod = $sum % 103; if (iconv_substr($value, 0, 1, 'UTF-8') == $this->_chr128($mod, $set)) { return true; } return false; }
/** * Split string and appending $insert string after $needle * * @param string $str * @param integer $length * @param string $needle * @param string $insert * @return string */ public function splitInjection($str, $length = 50, $needle = '-', $insert = ' ') { $str = $this->str_split($str, $length); $newStr = ''; foreach ($str as $part) { if ($this->strlen($part) >= $length) { $lastDelimetr = iconv_strpos(strrev($part), $needle, null, self::ICONV_CHARSET); $tmpNewStr = ''; $tmpNewStr = $this->substr(strrev($part), 0, $lastDelimetr) . $insert . $this->substr(strrev($part), $lastDelimetr); $newStr .= strrev($tmpNewStr); } else { $newStr .= $part; } } return $newStr; }
function mb_strpos($haystack, $needle, $offset, $charset = null) { if (function_exists('iconv_strpos')) { return iconv_strpos($haystack, $needle, $offset, $charset); } else { return strpos($haystack, $needle, $offset); } }
function mb_strpos($haystack, $needle, $offset = 0, $encoding = '') { $encoding = $this->regularize_encoding($encoding); if ($this->use_iconv) { return iconv_strpos($haystack, $needle, $offset, $encoding); } else { switch ($e = $this->mbemu_internals['encoding'][$encoding]) { case 1: //euc-jp //euc-jp case 2: //shift-jis //shift-jis case 4: //utf-8 //utf-8 case 5: //utf-16 //utf-16 case 8: //utf16BE preg_match_all('/' . $this->mbemu_internals['regex'][$e] . '/', $haystack, $ar_h); preg_match_all('/' . $this->mbemu_internals['regex'][$e] . '/', $needle, $ar_n); return $this->_sub_strpos($ar_h[0], $ar_n[0], $offset); case 3: //jis $haystack = $this->mb_convert_encoding($haystack, 'SJIS', 'JIS'); $needle = $this->mb_convert_encoding($needle, 'SJIS', 'JIS'); preg_match_all('/' . $this->mbemu_internals['regex'][2] . '/', $haystack, $ar_h); preg_match_all('/' . $this->mbemu_internals['regex'][2] . '/', $needle, $ar_n); return $this->_sub_strpos($ar_h[0], $ar_n[0], $offset); case 0: //ascii //ascii case 6: //iso-8859-1 //iso-8859-1 default: return strpos($haystack, $needle, $offset); } } }
//get an unset variable $unset_var = 10; unset($unset_var); // get a class class classA { public function __toString() { return "UTF-8"; } } // heredoc string $heredoc = <<<EOT UTF-8 EOT; // get a resource variable $fp = fopen(__FILE__, "r"); // unexpected values to be passed to $input argument $inputs = array(0, 1, 12345, -2345, 10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5, NULL, null, true, false, TRUE, FALSE, "", '', "UTF-8", 'UTF-8', $heredoc, new classA(), @$undefined_var, @$unset_var, $fp); // loop through each element of $inputs to check the behavior of iconv_strpos() $iterator = 1; foreach ($inputs as $input) { echo "\n-- Iteration {$iterator} --\n"; var_dump(iconv_strpos($haystack, $needle, $offset, $input)); $iterator++; } fclose($fp); echo "Done"; ?>
function utf8_strpos($string, $needle, $offset = 0) { return iconv_strpos($string, $needle, $offset, 'UTF-8'); }
/** * Find the position of the first occurrence of a substring in a string. * UTF-8 ONLY safe strpos(), uses mbstring, falls back to iconv. * * @param string $haystack the string to search in * @param string $needle one or more charachters to search for * @param int $offset offset from begining of string * @return int the numeric position of the first occurrence of needle in haystack. */ public static function strpos($haystack, $needle, $offset=0) { if (function_exists('mb_strpos')) { return mb_strpos($haystack, $needle, $offset, 'UTF-8'); } else { return iconv_strpos($haystack, $needle, $offset, 'UTF-8'); } }
function api_get_entitities(&$text, $bbcode) { /* To-Do: * Links at the first character of the post */ $a = get_app(); $include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false"); if ($include_entities != "true") { preg_match_all("/\\[img](.*?)\\[\\/img\\]/ism", $bbcode, $images); foreach ($images[1] as $image) { $replace = proxy_url($image); $text = str_replace($image, $replace, $text); } return array(); } $bbcode = bb_CleanPictureLinks($bbcode); // Change pure links in text to bbcode uris $bbcode = preg_replace("/([^\\]\\='" . '"' . "]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode); $entities = array(); $entities["hashtags"] = array(); $entities["symbols"] = array(); $entities["urls"] = array(); $entities["user_mentions"] = array(); $URLSearchString = "^\\[\\]"; $bbcode = preg_replace("/#\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '#$2', $bbcode); $bbcode = preg_replace("/\\[bookmark\\=([{$URLSearchString}]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $bbcode); //$bbcode = preg_replace("/\[url\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$bbcode); $bbcode = preg_replace("/\\[video\\](.*?)\\[\\/video\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", '[url=https://www.youtube.com/watch?v=$1]https://www.youtube.com/watch?v=$1[/url]', $bbcode); $bbcode = preg_replace("/\\[youtube\\](.*?)\\[\\/youtube\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[url=https://vimeo.com/$1]https://vimeo.com/$1[/url]', $bbcode); $bbcode = preg_replace("/\\[vimeo\\](.*?)\\[\\/vimeo\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '[img]$3[/img]', $bbcode); //preg_match_all("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $bbcode, $urls1); preg_match_all("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", $bbcode, $urls); $ordered_urls = array(); foreach ($urls[1] as $id => $url) { //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $url, 0, "UTF-8"); if (!($start === false)) { $ordered_urls[$start] = array("url" => $url, "title" => $urls[2][$id]); } } ksort($ordered_urls); $offset = 0; //foreach ($urls[1] AS $id=>$url) { foreach ($ordered_urls as $url) { if (substr($url["title"], 0, 7) != "http://" and substr($url["title"], 0, 8) != "https://" and !strpos($url["title"], "http://") and !strpos($url["title"], "https://")) { $display_url = $url["title"]; } else { $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url["url"]); $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url); if (strlen($display_url) > 26) { $display_url = substr($display_url, 0, 25) . "…"; } } //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $url["url"], $offset, "UTF-8"); if (!($start === false)) { $entities["urls"][] = array("url" => $url["url"], "expanded_url" => $url["url"], "display_url" => $display_url, "indices" => array($start, $start + strlen($url["url"]))); $offset = $start + 1; } } preg_match_all("/\\[img](.*?)\\[\\/img\\]/ism", $bbcode, $images); $ordered_images = array(); foreach ($images[1] as $image) { //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $image, 0, "UTF-8"); if (!($start === false)) { $ordered_images[$start] = $image; } } //$entities["media"] = array(); $offset = 0; foreach ($ordered_images as $url) { $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url); $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url); if (strlen($display_url) > 26) { $display_url = substr($display_url, 0, 25) . "…"; } $start = iconv_strpos($text, $url, $offset, "UTF-8"); if (!($start === false)) { $image = get_photo_info($url); if ($image) { // If image cache is activated, then use the following sizes: // thumb (150), small (340), medium (600) and large (1024) if (!get_config("system", "proxy_disabled")) { $media_url = proxy_url($url); $sizes = array(); $scale = scale_image($image[0], $image[1], 150); $sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); if ($image[0] > 150 or $image[1] > 150) { $scale = scale_image($image[0], $image[1], 340); $sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); } $scale = scale_image($image[0], $image[1], 600); $sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); if ($image[0] > 600 or $image[1] > 600) { $scale = scale_image($image[0], $image[1], 1024); $sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); } } else { $media_url = $url; $sizes["medium"] = array("w" => $image[0], "h" => $image[1], "resize" => "fit"); } $entities["media"][] = array("id" => $start + 1, "id_str" => (string) $start + 1, "indices" => array($start, $start + strlen($url)), "media_url" => normalise_link($media_url), "media_url_https" => $media_url, "url" => $url, "display_url" => $display_url, "expanded_url" => $url, "type" => "photo", "sizes" => $sizes); } $offset = $start + 1; } } return $entities; }
protected function _parseBB($text_forum, $id = 0, $type = 'pm') { $this->_init_parse(); if ($type == 'post' && iconv_strpos($text_forum, "[attachment=", 0, DLE_CHARSET) !== false) { $this->_db_disconnect(); $this->db->query("SELECT id, name, onserver, dcount FROM " . PREFIX . "_files WHERE news_id={$id}"); while ($file = $this->db->get_row()) { preg_match("#\\[attachment={$file['id']}:(.+?)\\]#i", $text_forum, $matche); $size = formatsize(@filesize(ROOT_DIR . '/uploads/files/' . $file['onserver'])); $file['name'] = explode("/", $file['name']); $file['name'] = end($file['name']); if (!empty($matche)) { $file['name'] = $matche[1]; } if ($GLOBALS['config']['files_count'] == 'yes') { $link = "[URL=\"{$GLOBALS['config']['http_home_url']}engine/download.php?id={$file['id']}\"]{$file['name']}[/URL] [{$size}] ({$this->lang['att_dcount']} {$file['dcount']})"; } else { $link = "[URL=\"{$GLOBALS['config']['http_home_url']}engine/download.php?id={$file['id']}\"]{$file['name']}[/URL] [{$size}]"; } $text_forum = preg_replace("#\\[attachment={$file['id']}(:.+?)?\\]#i", $link, $text_forum); } $this->_db_connect(); } if ($type == 'post') { $text_forum = preg_replace('#\\[[^U]+\\]#i', '', $text_forum); $text_forum = $this->_parse->decodeBBCodes($text_forum, false); $text_forum = preg_replace('#\\[page=[0-9]+\\]#si', "", $text_forum); $text_forum = str_replace('{PAGEBREAK}', '', $text_forum); $text_forum = preg_replace('#\\[hide\\](.*?)\\[/hide\\]#si', "\\1", $text_forum); } $text_forum = html_entity_decode($text_forum); $text_forum = preg_replace('#\\[s\\](.*?)\\[/s\\]#si', "\\1", $text_forum); //$text_forum = preg_replace('#\[spoiler(=.+?)?\](.*?)\[/spoiler\]#si', "\\2", $text_forum); $text_forum = preg_replace('#\\[img=(.+?)\\](.*?)\\[/img\\]#si', "[\\1][img]\\2[/img][/\\1]", $text_forum); /*$text_forum = preg_replace('#<.+?>#s', '', $text_forum);*/ $smilies_arr = explode(",", $GLOBALS['config']['smilies']); foreach ($smilies_arr as $smile) { $smile = trim($smile); $find[] = "#:{$smile}:#si"; $replace[] = "[img]" . $GLOBALS['config']['http_home_url'] . "engine/data/emoticons/{$smile}.gif[/img]"; } $text_forum = preg_replace($find, $replace, $text_forum); $text_forum = str_replace('leech', 'url', $text_forum); if ($type == 'post') { $text_forum = preg_replace("#\\[video\\s*=\\s*(\\S.+?)\\s*\\]#ie", "\$this->_parse->build_video('\\1')", $text_forum); $text_forum = preg_replace("#\\[audio\\s*=\\s*(\\S.+?)\\s*\\]#ie", "\$this->_parse->build_audio('\\1')", $text_forum); $text_forum = preg_replace("#\\[flash=([^\\]]+)\\](.+?)\\[/flash\\]#ies", "\$this->_parse->build_flash('\\1', '\\2')", $text_forum); $text_forum = preg_replace("#\\[youtube=([^\\]]+)\\]#ies", "\$this->_parse->build_youtube('\\1')", $text_forum); $text_forum = preg_replace("'\\[thumb\\]([^\\[]*)([/\\\\])(.*?)\\[/thumb\\]'ie", "\$this->build_thumb('\$1\$2\$3', '\$1\$2thumbs\$2\$3')", $text_forum); $text_forum = preg_replace("'\\[thumb=(.*?)\\]([^\\[]*)([/\\\\])(.*?)\\[/thumb\\]'ie", "\$this->build_thumb('\$2\$3\$4', '\$2\$3thumbs\$3\$4', '\$1')", $text_forum); $text_forum = str_replace('D27CDB6E', 'F27CDB6E', $text_forum); preg_match_all('#<object .+?</object>#si', $text_forum, $mathes); if (!empty($mathes[0])) { foreach ($mathes[0] as $obj) { $obj_new = str_replace("\n", '', $obj); $obj_new = str_replace("\r", '', $obj_new); $obj_new = str_replace("\t", '', $obj_new); $obj_new = preg_replace('# {2,}#si', " ", $obj_new); $text_forum = str_replace($obj, $obj_new, $text_forum); $text_forum = urldecode($text_forum); } } } $text_forum = preg_replace('#<!--.+?-->#s', '', $text_forum); $text_forum = str_replace('{THEME}', $GLOBALS['config']['http_home_url'] . 'templates/' . $GLOBALS['config']['skin'], $text_forum); return $text_forum; }
/** * 双字节语言版 strpos * * 使用方法同 strpos() * * @param string * @param string * @param int * @param string * @return string */ function cjk_strpos($haystack, $needle, $offset = 0, $charset = 'UTF-8') { if (function_exists('iconv_strpos')) { return iconv_strpos($haystack, $needle, $offset, $charset); } return mb_strpos($haystack, $needle, $offset, $charset); }
public function strrpos($str, $needle, $charset = 'utf-8') { return iconv_strpos($str, $needle, $charset = 'utf-8'); }
/** * Find position of first occurrence of a string * * @param string $haystack * @param string $needle * @param int $offset * @return int|false */ public function strpos($haystack, $needle, $offset = null) { return iconv_strpos($haystack, $needle, $offset, self::ICONV_CHARSET); }
private static function grapheme_position($s, $needle, $offset, $mode) { if (!preg_match('/./us', $needle .= '')) { return false; } if (!preg_match('/./us', $s .= '')) { return false; } if ($offset > 0) { $s = self::grapheme_substr($s, $offset); } elseif ($offset < 0) { $offset = 0; } switch ($mode) { case 0: $needle = iconv_strpos($s, $needle, 0, 'UTF-8'); break; case 1: $needle = mb_stripos($s, $needle, 0, 'UTF-8'); break; case 2: $needle = iconv_strrpos($s, $needle, 'UTF-8'); break; default: $needle = mb_strripos($s, $needle, 0, 'UTF-8'); break; } return $needle ? self::grapheme_strlen(iconv_substr($s, 0, $needle, 'UTF-8')) + $offset : $needle; }
/** * Calculates the date or object * * @param string $calc Calculation to make, one of: 'add'|'sub'|'cmp'|'copy'|'set' * @param string|integer|array|Zend_Date $date Date or datepart to calculate with * @param string $part Part of the date to calculate, if null the timestamp is used * @param string|Zend_Locale $locale Locale for parsing input * @return integer|string|Zend_Date new timestamp * @throws Zend_Date_Exception */ private function _calculate($calc, $date, $part, $locale) { if ($date === null) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('parameter $date must be set, null is not allowed'); } if ($part !== null && strlen($part) !== 2 && Zend_Locale::isLocale($part, null, false)) { $locale = $part; $part = null; } if ($locale === null) { $locale = $this->getLocale(); } $locale = (string) $locale; // Create date parts $year = $this->toString(self::YEAR, 'iso'); $month = $this->toString(self::MONTH_SHORT, 'iso'); $day = $this->toString(self::DAY_SHORT, 'iso'); $hour = $this->toString(self::HOUR_SHORT, 'iso'); $minute = $this->toString(self::MINUTE_SHORT, 'iso'); $second = $this->toString(self::SECOND_SHORT, 'iso'); // If object extract value if ($date instanceof Zend_Date) { $date = $date->toString($part, 'iso', $locale); } if (is_array($date) === true) { if (empty($part) === false) { switch ($part) { // Fall through case self::DAY: case self::DAY_SHORT: if (isset($date['day']) === true) { $date = $date['day']; } break; // Fall through // Fall through case self::WEEKDAY_SHORT: case self::WEEKDAY: case self::WEEKDAY_8601: case self::WEEKDAY_DIGIT: case self::WEEKDAY_NARROW: case self::WEEKDAY_NAME: if (isset($date['weekday']) === true) { $date = $date['weekday']; $part = self::WEEKDAY_DIGIT; } break; case self::DAY_OF_YEAR: if (isset($date['day_of_year']) === true) { $date = $date['day_of_year']; } break; // Fall through // Fall through case self::MONTH: case self::MONTH_SHORT: case self::MONTH_NAME: case self::MONTH_NAME_SHORT: case self::MONTH_NAME_NARROW: if (isset($date['month']) === true) { $date = $date['month']; } break; // Fall through // Fall through case self::YEAR: case self::YEAR_SHORT: case self::YEAR_8601: case self::YEAR_SHORT_8601: if (isset($date['year']) === true) { $date = $date['year']; } break; // Fall through // Fall through case self::HOUR: case self::HOUR_AM: case self::HOUR_SHORT: case self::HOUR_SHORT_AM: if (isset($date['hour']) === true) { $date = $date['hour']; } break; // Fall through // Fall through case self::MINUTE: case self::MINUTE_SHORT: if (isset($date['minute']) === true) { $date = $date['minute']; } break; // Fall through // Fall through case self::SECOND: case self::SECOND_SHORT: if (isset($date['second']) === true) { $date = $date['second']; } break; // Fall through // Fall through case self::TIMEZONE: case self::TIMEZONE_NAME: if (isset($date['timezone']) === true) { $date = $date['timezone']; } break; case self::TIMESTAMP: if (isset($date['timestamp']) === true) { $date = $date['timestamp']; } break; case self::WEEK: if (isset($date['week']) === true) { $date = $date['week']; } break; case self::TIMEZONE_SECS: if (isset($date['gmtsecs']) === true) { $date = $date['gmtsecs']; } break; default: require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("datepart for part ({$part}) not found in array"); break; } } else { $hours = 0; if (isset($date['hour']) === true) { $hours = $date['hour']; } $minutes = 0; if (isset($date['minute']) === true) { $minutes = $date['minute']; } $seconds = 0; if (isset($date['second']) === true) { $seconds = $date['second']; } $months = 0; if (isset($date['month']) === true) { $months = $date['month']; } $days = 0; if (isset($date['day']) === true) { $days = $date['day']; } $years = 0; if (isset($date['year']) === true) { $years = $date['year']; } return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, $months, $days, $years, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), $hour); } } // $date as object, part of foreign date as own date switch ($part) { // day formats case self::DAY: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true), $this->mktime(0, 0, 0, 1, 1 + intval($day), 1970, true), $hour); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, day expected", 0, null, $date); break; case self::WEEKDAY_SHORT: $daylist = Zend_Locale_Data::getList($locale, 'day'); $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale); $cnt = 0; foreach ($daylist as $key => $value) { if (strtoupper(iconv_substr($value, 0, 3, 'UTF-8')) == strtoupper($date)) { $found = $cnt; break; } ++$cnt; } // Weekday found if ($cnt < 7) { return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour); } // Weekday not found require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", 0, null, $date); break; case self::DAY_SHORT: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true), $this->mktime(0, 0, 0, 1, 1 + intval($day), 1970, true), $hour); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, day expected", 0, null, $date); break; case self::WEEKDAY: $daylist = Zend_Locale_Data::getList($locale, 'day'); $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale); $cnt = 0; foreach ($daylist as $key => $value) { if (strtoupper($value) == strtoupper($date)) { $found = $cnt; break; } ++$cnt; } // Weekday found if ($cnt < 7) { return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour); } // Weekday not found require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", 0, null, $date); break; case self::WEEKDAY_8601: $weekday = (int) $this->toString(self::WEEKDAY_8601, 'iso', $locale); if (intval($date) > 0 and intval($date) < 8) { return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour); } // Weekday not found require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", 0, null, $date); break; case self::DAY_SUFFIX: require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('day suffix not supported', 0, null, $date); break; case self::WEEKDAY_DIGIT: $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale); if (is_numeric($date) and intval($date) >= 0 and intval($date) < 7) { return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $date, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour); } // Weekday not found require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", 0, null, $date); break; case self::DAY_OF_YEAR: if (is_numeric($date)) { if ($calc == 'add' || $calc == 'sub') { $year = 1970; ++$date; ++$day; } return $this->_assign($calc, $this->mktime(0, 0, 0, 1, $date, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, day expected", 0, null, $date); break; case self::WEEKDAY_NARROW: $daylist = Zend_Locale_Data::getList($locale, 'day', array('gregorian', 'format', 'abbreviated')); $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale); $cnt = 0; foreach ($daylist as $key => $value) { if (strtoupper(iconv_substr($value, 0, 1, 'UTF-8')) == strtoupper($date)) { $found = $cnt; break; } ++$cnt; } // Weekday found if ($cnt < 7) { return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour); } // Weekday not found require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", 0, null, $date); break; case self::WEEKDAY_NAME: $daylist = Zend_Locale_Data::getList($locale, 'day', array('gregorian', 'format', 'abbreviated')); $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale); $cnt = 0; foreach ($daylist as $key => $value) { if (strtoupper($value) == strtoupper($date)) { $found = $cnt; break; } ++$cnt; } // Weekday found if ($cnt < 7) { return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour); } // Weekday not found require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", 0, null, $date); break; // week formats // week formats case self::WEEK: if (is_numeric($date)) { $week = (int) $this->toString(self::WEEK, 'iso', $locale); return $this->_assign($calc, parent::mktime(0, 0, 0, 1, 1 + $date * 7, 1970, true), parent::mktime(0, 0, 0, 1, 1 + $week * 7, 1970, true), $hour); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, week expected", 0, null, $date); break; // month formats // month formats case self::MONTH_NAME: $monthlist = Zend_Locale_Data::getList($locale, 'month'); $cnt = 0; foreach ($monthlist as $key => $value) { if (strtoupper($value) == strtoupper($date)) { $found = $key; break; } ++$cnt; } $date = array_search($date, $monthlist); // Monthname found if ($cnt < 12) { $fixday = 0; if ($calc == 'add') { $date += $found; $calc = 'set'; if (self::$_options['extend_month'] == false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } else { if ($calc == 'sub') { $date = $month - $found; $calc = 'set'; if (self::$_options['extend_month'] == false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } } return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour); } // Monthname not found require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", 0, null, $date); break; case self::MONTH: if (is_numeric($date)) { $fixday = 0; if ($calc == 'add') { $date += $month; $calc = 'set'; if (self::$_options['extend_month'] == false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } else { if ($calc == 'sub') { $date = $month - $date; $calc = 'set'; if (self::$_options['extend_month'] == false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } } return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", 0, null, $date); break; case self::MONTH_NAME_SHORT: $monthlist = Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'format', 'abbreviated')); $cnt = 0; foreach ($monthlist as $key => $value) { if (strtoupper($value) == strtoupper($date)) { $found = $key; break; } ++$cnt; } $date = array_search($date, $monthlist); // Monthname found if ($cnt < 12) { $fixday = 0; if ($calc == 'add') { $date += $found; $calc = 'set'; if (self::$_options['extend_month'] === false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } else { if ($calc == 'sub') { $date = $month - $found; $calc = 'set'; if (self::$_options['extend_month'] === false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } } return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour); } // Monthname not found require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", 0, null, $date); break; case self::MONTH_SHORT: if (is_numeric($date) === true) { $fixday = 0; if ($calc === 'add') { $date += $month; $calc = 'set'; if (self::$_options['extend_month'] === false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } else { if ($calc === 'sub') { $date = $month - $date; $calc = 'set'; if (self::$_options['extend_month'] === false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } } return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", 0, null, $date); break; case self::MONTH_DAYS: require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('month days not supported', 0, null, $date); break; case self::MONTH_NAME_NARROW: $monthlist = Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'stand-alone', 'narrow')); $cnt = 0; foreach ($monthlist as $key => $value) { if (strtoupper($value) === strtoupper($date)) { $found = $key; break; } ++$cnt; } $date = array_search($date, $monthlist); // Monthname found if ($cnt < 12) { $fixday = 0; if ($calc === 'add') { $date += $found; $calc = 'set'; if (self::$_options['extend_month'] === false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } else { if ($calc === 'sub') { $date = $month - $found; $calc = 'set'; if (self::$_options['extend_month'] === false) { $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false)); if ($parts['mday'] != $day) { $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day; } } } } return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour); } // Monthname not found require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", 0, null, $date); break; // year formats // year formats case self::LEAPYEAR: require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('leap year not supported', 0, null, $date); break; case self::YEAR_8601: if (is_numeric($date)) { if ($calc === 'add') { $date += $year; $calc = 'set'; } else { if ($calc === 'sub') { $date = $year - $date; $calc = 'set'; } } return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, intval($date), true), $this->mktime(0, 0, 0, $month, $day, $year, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", 0, null, $date); break; case self::YEAR: if (is_numeric($date)) { if ($calc === 'add') { $date += $year; $calc = 'set'; } else { if ($calc === 'sub') { $date = $year - $date; $calc = 'set'; } } return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, intval($date), true), $this->mktime(0, 0, 0, $month, $day, $year, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", 0, null, $date); break; case self::YEAR_SHORT: if (is_numeric($date)) { $date = intval($date); if ($calc == 'set' || $calc == 'cmp') { $date = self::getFullYear($date); } if ($calc === 'add') { $date += $year; $calc = 'set'; } else { if ($calc === 'sub') { $date = $year - $date; $calc = 'set'; } } return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, $date, true), $this->mktime(0, 0, 0, $month, $day, $year, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", 0, null, $date); break; case self::YEAR_SHORT_8601: if (is_numeric($date)) { $date = intval($date); if ($calc === 'set' || $calc === 'cmp') { $date = self::getFullYear($date); } if ($calc === 'add') { $date += $year; $calc = 'set'; } else { if ($calc === 'sub') { $date = $year - $date; $calc = 'set'; } } return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, $date, true), $this->mktime(0, 0, 0, $month, $day, $year, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", 0, null, $date); break; // time formats // time formats case self::MERIDIEM: require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('meridiem not supported', 0, null, $date); break; case self::SWATCH: if (is_numeric($date)) { $rest = intval($date); $hours = floor($rest * 24 / 1000); $rest = $rest - $hours * 1000 / 24; $minutes = floor($rest * 1440 / 1000); $rest = $rest - $minutes * 1000 / 1440; $seconds = floor($rest * 86400 / 1000); return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1, 1, 1970, true), $this->mktime($hour, $minute, $second, 1, 1, 1970, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, swatchstamp expected", 0, null, $date); break; case self::HOUR_SHORT_AM: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true), $this->mktime($hour, 0, 0, 1, 1, 1970, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", 0, null, $date); break; case self::HOUR_SHORT: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true), $this->mktime($hour, 0, 0, 1, 1, 1970, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", 0, null, $date); break; case self::HOUR_AM: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true), $this->mktime($hour, 0, 0, 1, 1, 1970, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", 0, null, $date); break; case self::HOUR: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true), $this->mktime($hour, 0, 0, 1, 1, 1970, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", 0, null, $date); break; case self::MINUTE: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(0, intval($date), 0, 1, 1, 1970, true), $this->mktime(0, $minute, 0, 1, 1, 1970, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, minute expected", 0, null, $date); break; case self::SECOND: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(0, 0, intval($date), 1, 1, 1970, true), $this->mktime(0, 0, $second, 1, 1, 1970, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, second expected", 0, null, $date); break; case self::MILLISECOND: if (is_numeric($date)) { switch ($calc) { case 'set': return $this->setMillisecond($date); break; case 'add': return $this->addMillisecond($date); break; case 'sub': return $this->subMillisecond($date); break; } return $this->compareMillisecond($date); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, milliseconds expected", 0, null, $date); break; case self::MINUTE_SHORT: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(0, intval($date), 0, 1, 1, 1970, true), $this->mktime(0, $minute, 0, 1, 1, 1970, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, minute expected", 0, null, $date); break; case self::SECOND_SHORT: if (is_numeric($date)) { return $this->_assign($calc, $this->mktime(0, 0, intval($date), 1, 1, 1970, true), $this->mktime(0, 0, $second, 1, 1, 1970, true), false); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, second expected", 0, null, $date); break; // timezone formats // break intentionally omitted // timezone formats // break intentionally omitted case self::TIMEZONE_NAME: case self::TIMEZONE: case self::TIMEZONE_SECS: require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('timezone not supported', 0, null, $date); break; case self::DAYLIGHT: require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('daylight not supported', 0, null, $date); break; case self::GMT_DIFF: case self::GMT_DIFF_SEP: require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('gmtdiff not supported', 0, null, $date); break; // date strings // date strings case self::ISO_8601: // (-)YYYY-MM-dd preg_match('/^(-{0,1}\\d{4})-(\\d{2})-(\\d{2})/', $date, $datematch); // (-)YY-MM-dd if (empty($datematch)) { preg_match('/^(-{0,1}\\d{2})-(\\d{2})-(\\d{2})/', $date, $datematch); } // (-)YYYYMMdd if (empty($datematch)) { preg_match('/^(-{0,1}\\d{4})(\\d{2})(\\d{2})/', $date, $datematch); } // (-)YYMMdd if (empty($datematch)) { preg_match('/^(-{0,1}\\d{2})(\\d{2})(\\d{2})/', $date, $datematch); } $tmpdate = $date; if (!empty($datematch)) { $dateMatchCharCount = iconv_strlen($datematch[0], 'UTF-8'); $tmpdate = iconv_substr($date, $dateMatchCharCount, iconv_strlen($date, 'UTF-8') - $dateMatchCharCount, 'UTF-8'); } // (T)hh:mm:ss preg_match('/[T,\\s]{0,1}(\\d{2}):(\\d{2}):(\\d{2})/', $tmpdate, $timematch); if (empty($timematch)) { preg_match('/[T,\\s]{0,1}(\\d{2})(\\d{2})(\\d{2})/', $tmpdate, $timematch); } if (empty($datematch) and empty($timematch)) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("unsupported ISO8601 format ({$date})", 0, null, $date); } if (!empty($timematch)) { $timeMatchCharCount = iconv_strlen($timematch[0], 'UTF-8'); $tmpdate = iconv_substr($tmpdate, $timeMatchCharCount, iconv_strlen($tmpdate, 'UTF-8') - $timeMatchCharCount, 'UTF-8'); } if (empty($datematch)) { $datematch[1] = 1970; $datematch[2] = 1; $datematch[3] = 1; } else { if (iconv_strlen($datematch[1], 'UTF-8') == 2) { $datematch[1] = self::getFullYear($datematch[1]); } } if (empty($timematch)) { $timematch[1] = 0; $timematch[2] = 0; $timematch[3] = 0; } if ($calc == 'set' || $calc == 'cmp') { --$datematch[2]; --$month; --$datematch[3]; --$day; $datematch[1] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($timematch[1], $timematch[2], $timematch[3], 1 + $datematch[2], 1 + $datematch[3], 1970 + $datematch[1], false), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, false), false); break; case self::RFC_2822: $result = preg_match('/^\\w{3},\\s(\\d{1,2})\\s(\\w{3})\\s(\\d{4})\\s' . '(\\d{2}):(\\d{2}):{0,1}(\\d{0,2})\\s([+-]' . '{1}\\d{4}|\\w{1,20})$/', $date, $match); if (!$result) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("no RFC 2822 format ({$date})", 0, null, $date); } $months = $this->_getDigitFromName($match[2]); if ($calc == 'set' || $calc == 'cmp') { --$months; --$month; --$match[1]; --$day; $match[3] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], false), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, false), false); break; case self::TIMESTAMP: if (is_numeric($date)) { return $this->_assign($calc, $date, $this->getUnixTimestamp()); } require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, timestamp expected", 0, null, $date); break; // additional formats // break intentionally omitted // additional formats // break intentionally omitted case self::ERA: case self::ERA_NAME: require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('era not supported', 0, null, $date); break; case self::DATES: try { $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true)); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::DATE_FULL: try { $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full')); $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::DATE_LONG: try { $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long')); $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::DATE_MEDIUM: try { $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium')); $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::DATE_SHORT: try { $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short')); $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); $parsed['year'] = self::getFullYear($parsed['year']); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::TIMES: try { if ($calc != 'set') { $month = 1; $day = 1; $year = 1970; } $parsed = Zend_Locale_Format::getTime($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true)); return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::TIME_FULL: try { $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'full')); $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc != 'set') { $month = 1; $day = 1; $year = 1970; } if (!isset($parsed['second'])) { $parsed['second'] = 0; } return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::TIME_LONG: try { $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'long')); $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc != 'set') { $month = 1; $day = 1; $year = 1970; } return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::TIME_MEDIUM: try { $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'medium')); $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc != 'set') { $month = 1; $day = 1; $year = 1970; } return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::TIME_SHORT: try { $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'short')); $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc != 'set') { $month = 1; $day = 1; $year = 1970; } if (!isset($parsed['second'])) { $parsed['second'] = 0; } return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::DATETIME: try { $parsed = Zend_Locale_Format::getDateTime($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true)); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::DATETIME_FULL: try { $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full')); $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } if (!isset($parsed['second'])) { $parsed['second'] = 0; } return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::DATETIME_LONG: try { $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long')); $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::DATETIME_MEDIUM: try { $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium')); $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; case self::DATETIME_SHORT: try { $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short')); $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale)); $parsed['year'] = self::getFullYear($parsed['year']); if ($calc == 'set' || $calc == 'cmp') { --$parsed['month']; --$month; --$parsed['day']; --$day; $parsed['year'] -= 1970; $year -= 1970; } if (!isset($parsed['second'])) { $parsed['second'] = 0; } return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), $hour); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } break; // ATOM and RFC_3339 are identical // ATOM and RFC_3339 are identical case self::ATOM: case self::RFC_3339: $result = preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\d{0,4}([+-]{1}\\d{2}:\\d{2}|Z)$/', $date, $match); if (!$result) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, ATOM format expected", 0, null, $date); } if ($calc == 'set' || $calc == 'cmp') { --$match[2]; --$month; --$match[3]; --$day; $match[1] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $match[2], 1 + $match[3], 1970 + $match[1], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false); break; case self::COOKIE: $result = preg_match("/^\\w{6,9},\\s(\\d{2})-(\\w{3})-(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})\\s.{3,20}\$/", $date, $match); if (!$result) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, COOKIE format expected", 0, null, $date); } $matchStartPos = iconv_strpos($match[0], ' ', 0, 'UTF-8') + 1; $match[0] = iconv_substr($match[0], $matchStartPos, iconv_strlen($match[0], 'UTF-8') - $matchStartPos, 'UTF-8'); $months = $this->_getDigitFromName($match[2]); $match[3] = self::getFullYear($match[3]); if ($calc == 'set' || $calc == 'cmp') { --$months; --$month; --$match[1]; --$day; $match[3] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false); break; case self::RFC_822: case self::RFC_1036: // new RFC 822 format, identical to RFC 1036 standard $result = preg_match('/^\\w{0,3},{0,1}\\s{0,1}(\\d{1,2})\\s(\\w{3})\\s(\\d{2})\\s(\\d{2}):(\\d{2}):{0,1}(\\d{0,2})\\s([+-]{1}\\d{4}|\\w{1,20})$/', $date, $match); if (!$result) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 822 date format expected", 0, null, $date); } $months = $this->_getDigitFromName($match[2]); $match[3] = self::getFullYear($match[3]); if ($calc == 'set' || $calc == 'cmp') { --$months; --$month; --$match[1]; --$day; $match[3] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], false), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, false), false); break; case self::RFC_850: $result = preg_match('/^\\w{6,9},\\s(\\d{2})-(\\w{3})-(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})\\s.{3,21}$/', $date, $match); if (!$result) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 850 date format expected", 0, null, $date); } $months = $this->_getDigitFromName($match[2]); $match[3] = self::getFullYear($match[3]); if ($calc == 'set' || $calc == 'cmp') { --$months; --$month; --$match[1]; --$day; $match[3] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false); break; case self::RFC_1123: $result = preg_match('/^\\w{0,3},{0,1}\\s{0,1}(\\d{1,2})\\s(\\w{3})\\s(\\d{2,4})\\s(\\d{2}):(\\d{2}):{0,1}(\\d{0,2})\\s([+-]{1}\\d{4}|\\w{1,20})$/', $date, $match); if (!$result) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 1123 date format expected", 0, null, $date); } $months = $this->_getDigitFromName($match[2]); if ($calc == 'set' || $calc == 'cmp') { --$months; --$month; --$match[1]; --$day; $match[3] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false); break; case self::RSS: $result = preg_match('/^\\w{3},\\s(\\d{2})\\s(\\w{3})\\s(\\d{2,4})\\s(\\d{1,2}):(\\d{2}):(\\d{2})\\s.{1,21}$/', $date, $match); if (!$result) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, RSS date format expected", 0, null, $date); } $months = $this->_getDigitFromName($match[2]); $match[3] = self::getFullYear($match[3]); if ($calc == 'set' || $calc == 'cmp') { --$months; --$month; --$match[1]; --$day; $match[3] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false); break; case self::W3C: $result = preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})[+-]{1}\\d{2}:\\d{2}$/', $date, $match); if (!$result) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid date ({$date}) operand, W3C date format expected", 0, null, $date); } if ($calc == 'set' || $calc == 'cmp') { --$match[2]; --$month; --$match[3]; --$day; $match[1] -= 1970; $year -= 1970; } return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $match[2], 1 + $match[3], 1970 + $match[1], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false); break; default: if (!is_numeric($date) || !empty($part)) { try { if (empty($part)) { $part = Zend_Locale_Format::getDateFormat($locale) . " "; $part .= Zend_Locale_Format::getTimeFormat($locale); } $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $part, 'locale' => $locale, 'fix_date' => true, 'format_type' => 'iso')); if (strpos(strtoupper($part), 'YY') !== false and strpos(strtoupper($part), 'YYYY') === false) { $parsed['year'] = self::getFullYear($parsed['year']); } if ($calc == 'set' || $calc == 'cmp') { if (isset($parsed['month'])) { --$parsed['month']; } else { $parsed['month'] = 0; } if (isset($parsed['day'])) { --$parsed['day']; } else { $parsed['day'] = 0; } if (!isset($parsed['year'])) { $parsed['year'] = 1970; } } return $this->_assign($calc, $this->mktime(isset($parsed['hour']) ? $parsed['hour'] : 0, isset($parsed['minute']) ? $parsed['minute'] : 0, isset($parsed['second']) ? $parsed['second'] : 0, isset($parsed['month']) ? 1 + $parsed['month'] : 1, isset($parsed['day']) ? 1 + $parsed['day'] : 1, $parsed['year'], false), $this->getUnixTimestamp(), false); } catch (Zend_Locale_Exception $e) { if (!is_numeric($date)) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date); } } } return $this->_assign($calc, $date, $this->getUnixTimestamp(), false); break; } }
/** * Find the position of the first occurrence of a substring in a string * * @param string $haystack * @param string $needle * @param int $offset * @return int|false */ public function strpos($haystack, $needle, $offset = 0) { return iconv_strpos($haystack, $needle, $offset, $this->getEncoding()); }
/** * Internal method to extract the currency pattern * when a choice is given based on the given value * * @param string $pattern * @param float|integer $value * @return string */ private function _extractPattern($pattern, $value) { if (strpos($pattern, '|') === false) { return $pattern; } $patterns = explode('|', $pattern); $token = $pattern; $value = trim(str_replace('¤', '', $value)); krsort($patterns); foreach ($patterns as $content) { if (strpos($content, '<') !== false) { $check = iconv_substr($content, 0, iconv_strpos($content, '<')); $token = iconv_substr($content, iconv_strpos($content, '<') + 1); if ($check < $value) { return $token; } } else { $check = iconv_substr($content, 0, iconv_strpos($content, '≤')); $token = iconv_substr($content, iconv_strpos($content, '≤') + 1); if ($check <= $value) { return $token; } } } return $token; }
function mb_strpos($a, $b) { return iconv_strpos($a, $b); }