• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-jp-ancient: Commit

Nucleus CMS日本語版SVNをgit-svnしたもの。リポジトリの変換作業用


Commit MetaInfo

Revision2be4e2f1b9f887e1bc24cec41920745241102ae6 (tree)
Zeit2011-06-06 09:28:45
Autorsakamocchi <sakamocchi@1ca2...>
Commitersakamocchi

Log Message

Modify the way to deal with i18n::strftime. i18n::mail should still be checked in various circumstances.

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@1201 1ca29b6e-896d-4ea0-84a5-967f57386b96

Ändern Zusammenfassung

Diff

--- a/utf8/nucleus/libs/i18n.php
+++ b/utf8/nucleus/libs/i18n.php
@@ -1,13 +1,9 @@
11 <?php
22 /*
33 * i18n class
4- * written by Takashi Sakamoto as of Apr.18, 2011
4+ * written by Takashi Sakamoto as of Jun.5, 2011
55 * This is wrapper functions of iconv and mbstring
66 * for multibyte processing.
7- *
8- * Usage: Firstly i18n::initialize($charset),
9- * then access to each static functions.
10- *
117 */
128
139 class i18n {
@@ -15,7 +11,7 @@ class i18n {
1511 private static $iconv = FALSE;
1612 private static $mbstring = FALSE;
1713
18- public static function initialize ($charset) {
14+ public static function init ($charset) {
1915 if (extension_loaded('iconv')) {
2016 self::$iconv = TRUE;
2117 if (iconv_set_encoding ('output_encoding', $charset)
@@ -37,16 +33,16 @@ class i18n {
3733 $return =FALSE;
3834 }
3935 self::$charset = $charset;
40- return $return;
36+ return (boolean) $return;
4137 }
4238
43- public static function hsc ($string, $quotation) {
44- return htmlspecialchars($string, $quotation, self::$charset);
39+ public static function hsc ($string, $quotation=ENT_QUOTES) {
40+ return (string) htmlspecialchars($string, $quotation, self::$charset);
4541 }
4642
4743 public static function convert ($target, $from, $to='') {
4844 $string = '';
49- if (!$to) {
45+ if ($to == '') {
5046 $to = self::$charset;
5147 }
5248 if (self::$iconv) {
@@ -54,7 +50,7 @@ class i18n {
5450 } else if (self::$mbstring) {
5551 $string = mb_convert_encoding($string, $to, $from);
5652 }
57- return $string;
53+ return (string) $string;
5854 }
5955
6056 public static function strlen ($string) {
@@ -66,7 +62,7 @@ class i18n {
6662 } else {
6763 $length = strlen ($string);
6864 }
69- return $length;
65+ return (integer) $length;
7066 }
7167
7268 public static function strpos ($haystack, $needle, $offset=0) {
@@ -78,7 +74,7 @@ class i18n {
7874 } else {
7975 $position = strpos ($haystack, $needle, $offset);
8076 }
81- return $position;
77+ return (integer) $position;
8278 }
8379
8480 public static function strrpos ($haystack, $needle) {
@@ -90,11 +86,11 @@ class i18n {
9086 } else {
9187 $position = strrpos ($haystack, $needle, 0);
9288 }
93- return $position;
89+ return (integer) $position;
9490 }
9591
9692 public static function substr ($string, $start, $length=0) {
97- $return = 0;
93+ $return = '';
9894 if (self::$iconv) {
9995 $return = iconv_substr ($string, $start, $length, self::$charset);
10096 } else if (self::$mbstring) {
@@ -102,35 +98,69 @@ class i18n {
10298 } else {
10399 $return = strrpos ($string, $start, $length);
104100 }
105- return $return;
101+ return (string) $return;
106102 }
107103
108- /*
109- * we should use preg_split function instead of this, I think.
110- */
111104 public static function explode ($delimiter, $target, $limit=0) {
112105 $array = array();
106+ if (preg_match("#$delimiter#", $target) === 0) {
107+ return $target;
108+ }
113109 for ($count=0; $limit == 0 || $count < $limit; $count++) {
114110 $offset = self::strpos($target, $delimiter);
115- if ($offset == 0) {
116- $array[] = $target;
111+ if ($array != array() && $offset == 0) {
112+ $array[] = $target;
117113 break;
118114 }
119- $before = self::substr($target, 0, $offset);
120- $array[] = $before;
121- $length = self::strlen($target) - self::strlen($before);
115+ $array[] = self::substr($target, 0, $offset);
116+ $length = self::strlen($target) - $offset;
122117 $target = self::substr($target, $offset+1, $length);
118+ continue;
123119 }
124- return $array;
120+ return (array) $array;
125121 }
126122
127123 public static function strftime ($format, $timestamp='') {
128124 $formatted = '';
129- if (setlocale(LC_CTYPE, 0) == 'Japanese_Japan.932') {
130- $formatted = iconv('CP932', self::$charset, strftime(iconv(self::$charset, 'CP932', $format),$timestamp));
125+ $elements = array();
126+ if (preg_match('#%#', $format) === 0) {
127+ return $format;
128+ }
129+ $format = trim(preg_replace('#(%.)#', ',$1,', $format), ',');
130+ $elements = self::explode(',', $format);
131+
132+ foreach ($elements as $element) {
133+ if (preg_match('#^%.$#', $element)) {
134+ $formatted .= strftime($element, $timestamp);
135+ } else {
136+ $formatted .= $element;
137+ }
138+ }
139+
140+ return (string) $formatted;
141+ }
142+
143+ /*
144+ * This function is experimental, need to be tested in various PHP environment
145+ */
146+ public static function mail($to, $subject, $message, $from) {
147+ if (self::$iconv) {
148+ $options = array(
149+ 'scheme' => 'B',
150+ 'input-charset' => self::$charset,
151+ 'output-charset' => self::$charset,
152+ 'line-length' => 76,
153+ 'line-break-chars' => "\r\n");
154+
155+ $subject = iconv_mime_encode('Subject', $subject, $options);
156+ $addition = iconv_mime_encode('From', $from, $options);
157+
158+ $result = mail($to, $subject, $message, $addition);
159+ } else if (self::$mbstring) {
160+ $result = mb_send_mail ($to, $subject, $message, "From: $from");
131161 } else {
132- $formatted = strftime($format,$timestamp);
162+ $result = mail ($to, $subject, $message, "From: $from");
133163 }
134- return $formatted;
164+ return (boolean) $result;
135165 }
136166 }
\ No newline at end of file
Show on old repository browser