OSDN Git Service

MERGE:リビジョン1717/1718のマージ。mysqldate()を非推奨、i18n::formatted_datetime()を整備
authorsakamocchi <o-takashi@sakamocchi.jp>
Sat, 31 Mar 2012 08:17:06 +0000 (17:17 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Sat, 31 Mar 2012 08:17:06 +0000 (17:17 +0900)
i18n::formatted_datetime()は、PHPのdatetimeサブシステムとCライブラリのstrftimeのどちらをどう使うかを今後実装していく予定。

CHANGE: deprecate mysqldate() and some works for
i18n::formatted_datetime()

Some codes is moved from mysqldate() into i18n::formatted_datetime() for
time and date expression of SQL statement and is deprecated. Users
should use i18n::formatted_datetime() instead of mysqldate() with single
quotation.

nucleus/libs/BLOG.php
nucleus/libs/COMMENT.php
nucleus/libs/ITEM.php
nucleus/libs/i18n.php

index 1dff9bf..00cfac5 100644 (file)
@@ -218,14 +218,30 @@ class BLOG {
                                        {\r
                                                $oldTS = strtotime($old_date);\r
                                                $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));\r
-                                               $tmp_footer = i18n::strftime(isset($template['DATE_FOOTER'])?$template['DATE_FOOTER']:'', $oldTS);\r
+                                               
+                                               if ( !in_array('DATE_FOOTER', $template) || !empty($template['DATE_FOOTER']) )
+                                               {
+                                                       $tmp_footer = i18n::formatted_datetime('', $oldTS);
+                                               }
+                                               else
+                                               {
+                                                       $tmp_footer = i18n::formatted_datetime($template['DATE_FOOTER'], $oldTS);
+                                               }
                                                $parser->parse($tmp_footer);\r
                                                $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));\r
                                        }\r
                                        $manager->notify('PreDateHead',array('blog' => &$this, 'timestamp' => $timestamp));\r
                                        // note, to use templatvars in the dateheader, the %-characters need to be doubled in\r
                                        // order to be preserved by strftime\r
-                                       $tmp_header = i18n::strftime((isset($template['DATE_HEADER']) ? $template['DATE_HEADER'] : null), $timestamp);\r
+                                       if ( !in_array('DATE_HEADER', $template) || !empty($template['DATE_HEADER']) )\r
+                                       {\r
+                                               $tmp_footer = i18n::formatted_datetime('', $timestamp);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               $tmp_footer = i18n::formatted_datetime($template['DATE_FOOTER'], $timestamp);\r
+                                       }\r
+                                       
                                        $parser->parse($tmp_header);\r
                                        $manager->notify('PostDateHead',array('blog' => &$this, 'timestamp' => $timestamp));\r
                                }\r
@@ -739,7 +755,7 @@ class BLOG {
                        );\r
                        \r
                        $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data);\r
-                       echo i18n::strftime($temp,$current->itime);\r
+                       echo i18n::formatted_datetime($temp, $current->itime);
                        return;\r
                }\r
                \r
@@ -1541,7 +1557,7 @@ class BLOG {
                        if ( !$showFuture )\r
                        {\r
                                // don't show future items\r
-                               $query .= ' and i.itime<="' . i18n::formatted_datetime('mysql', $this->getCorrectTime()) . '"';\r
+                               $query .= " and i.itime<='" . i18n::formatted_datetime('mysql', $this->getCorrectTime()) . "'";\r
                        }\r
                        \r
                        $query .= ' and i.inumber='.intval($value);\r
index 36e725a..6bef268 100644 (file)
@@ -24,7 +24,7 @@ class COMMENT
         * Returns the requested comment\r
         * \r
         * @static\r
-        * @param       integer $commentid\r
+        * @param       integer $commentid      id for comment
         * @return      array   comment information\r
         * \r
         */\r
@@ -45,10 +45,12 @@ class COMMENT
                       . 'WHERE cnumber = %d;';\r
                \r
                $query = sprintf($query, sql_table('comment'), sql_table('member'), (integer) $commentid);\r
+               $comments = sql_query($query);
                \r
                $aCommentInfo = sql_fetch_assoc($comments);\r
 \r
-               if ($aCommentInfo) {\r
+               if ( $aCommentInfo )
+               {
                        $aCommentInfo['timestamp'] = strtotime($aCommentInfo['ctime']);\r
                }\r
 \r
@@ -56,9 +58,13 @@ class COMMENT
        }\r
 \r
        /**\r
+        * COMMENT::prepare()
          * Prepares a comment to be saved\r
          *\r
          * @static\r
+        * @param       array   $comment        comment data
+        * @return      array   comment date
+        * 
          */\r
        function prepare($comment)\r
        {\r
@@ -72,10 +78,13 @@ class COMMENT
                $comment['email'] = trim(strtr($comment['email'], "\'\"\n", '-- ') );\r
 \r
                // begin if: a comment userid is supplied, but does not have an "http://" or "https://" at the beginning - prepend an "http://"\r
-               if ( !empty($comment['userid']) && (i18n::strpos($comment['userid'], 'http://') !== 0) && (i18n::strpos($comment['userid'], 'https://') !== 0) )\r
+               if ( array_key_exists('userid', $comment)
+                 && !empty($comment['userid'])
+                 && (i18n::strpos($comment['userid'], 'http://') !== 0)
+                 && (i18n::strpos($comment['userid'], 'https://') !== 0) )
                {\r
                        $comment['userid'] = 'http://' . $comment['userid'];\r
-               } // end if\r
+               }
 \r
                $comment['body'] = COMMENT::prepareBody($comment['body']);\r
 \r
@@ -83,12 +92,16 @@ class COMMENT
        }\r
 \r
        /**\r
+        * COMMENT::prepareBody()
         * Prepares the body of a comment\r
         *\r
         * @ static\r
+        * @param       string  $body   string for comment body
+        * @return      string  validate string for comment body
+        * 
         */\r
-       function prepareBody($body) {\r
-\r
+       function prepareBody($body)
+       {
                # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0\r
                # original ereg_replace: ereg_replace("\n.\n.\n", "\n", $body);\r
 \r
@@ -128,9 +141,11 @@ class COMMENT
         * Creates a link code for unlinked URLs with different protocols\r
         *\r
         * @static\r
-        * @param       String  $pre    Prefix of comment\r
-        * @param       String  $url    URL\r
-        * @param       String  $protocol       http, mailto and so on\r
+        * @param       string  $pre    Prefix of comment
+        * @param       string  $url    URL
+        * @param       string  $protocol       http, mailto and so on
+        * @return      string  string  including anchor element and child text
+        * 
         */\r
        function createLinkCode($pre, $url, $protocol = 'http')\r
        {\r
@@ -190,9 +205,12 @@ class COMMENT
        }\r
        \r
        /**\r
+        * COMMENT::prepareBody_cb()
         * This method is a callback for creating link codes\r
-        * @param array $match\r
-        * @return string\r
+        * 
+        * @param       array   $match  elements for achor
+        * @return      string  including anchor element and child text
+        * 
         */\r
        function prepareBody_cb($match)\r
        {\r
@@ -219,8 +237,8 @@ class COMMENT
                                return self::createLinkCode($match[1], $match[2], 'http');\r
                        break;\r
                }\r
+               return;
        }\r
 \r
 }\r
 \r
-?>\r
index 9ce3eff..2795089 100644 (file)
@@ -199,9 +199,15 @@ class ITEM
                }\r
                else\r
                {\r
-                       // time with offset, or 0 for drafts\r
-                       $posttime = $i_draft ? 0 : $blog->getCorrectTime();\r
-               }\r
+                       if ( !$i_draft )
+                       {
+                               $posttime = $blog->getCorrectTime();
+                       }
+                       else
+                       {
+                               $posttime = 0;
+                       }\r
+               }
                \r
                if ( $posttime > $blog->getCorrectTime() )\r
                {\r
index d3d113c..27c0ff2 100644 (file)
@@ -437,10 +437,10 @@ class i18n
         * Working with Time Zones\r
         * @link        http://www.w3.org/TR/timezone/\r
         * \r
-        * @param       String          $format time expression format\r
-        * @param       String          $timestamp      UNIX timestamp\r
+        * @param       String  $format time expression format\r
+        * @param       String  $timestamp      UNIX timestamp\r
         * @param       Integer $offset timestamp offset\r
-        * @return      String          formatted datetime\r
+        * @return      String  formatted datetime\r
         */\r
        static public function formatted_datetime($format, $timestamp, $offset=0)\r
        {\r