OSDN Git Service

3.15 taka-san version
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / COMMENT.php
index 2992869..c77e362 100755 (executable)
-<?php
-
-/**
-  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
-  * Copyright (C) 2002-2004 The Nucleus Group
-  *
-  * This program is free software; you can redistribute it and/or
-  * modify it under the terms of the GNU General Public License
-  * as published by the Free Software Foundation; either version 2
-  * of the License, or (at your option) any later version.
-  * (see nucleus/documentation/index.html#license for more info)
-  *
-  * A class representing a single comment
-  *
-  * $Id: COMMENT.php,v 1.1.1.1 2005-02-28 07:14:49 kimitake Exp $
-  */
-class COMMENT {
-       
-       /**
-         * Returns the requested comment (static)
-         */
-       function getComment($commentid) {
-               $query =  'SELECT cnumber as commentid, cbody as body, cuser as user, cmail as userid, cmember as memberid, ctime, chost as host, mname as member, cip as ip, cblog as blogid'
-                      . ' FROM '.sql_table('comment').' left outer join '.sql_table('member').' on cmember=mnumber'
-                      . ' WHERE cnumber=' . intval($commentid);
-               $comments = sql_query($query);
-
-               $aCommentInfo = mysql_fetch_assoc($comments);
-               if ($aCommentInfo)
-               {
-                       $aCommentInfo['timestamp'] = strtotime($aCommentInfo['ctime']);
-               }
-               return $aCommentInfo;
-       }       
-       
-       /**
-         * prepares a comment to be saved
-         * (static)
-         */
-       function prepare($comment) {
-               $comment['user'] = strip_tags($comment['user']);
-               $comment['userid'] = strip_tags($comment['userid']);
-               
-               // remove quotes and newlines from user and userid
-               $comment['user'] = strtr($comment['user'], "\'\"\n",'-- ');
-               $comment['userid'] = strtr($comment['userid'], "\'\"\n",'-- ');
-               
-               $comment['body'] = COMMENT::prepareBody($comment['body']);
-               
-               return $comment;
-       }
-       
-       // prepares the body of a comment (static)
-       function prepareBody($body) {
-       
-               // remove newlines when too many in a row
-               $body = ereg_replace("\n.\n.\n","\n",$body);
-
-               // encode special characters as entities
-               $body = htmlspecialchars($body);
-
-               // trim away whitespace and newlines at beginning and end
-               $body = trim($body);
-
-               // add <br /> tags
-               $body = addBreaks($body);
-       
-               // create hyperlinks for http:// addresses
-               // there's a testcase for this in /build/testcases/urllinking.txt
-               $replaceFrom = array(
-               '/([^:\/\/\w]|^)((https:\/\/)([a-z0-9_\.-]+)([\/a-z0-9_+\.~%&?@=_:;#,-]+))/ie',
-               '/([^:\/\/\w]|^)((http:\/\/|www\.)([a-z0-9_\.-]+)([\/a-z0-9_+\.~%&?@=_:;#,-]+))/ie',
-               '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([a-z0-9_\.-]+)([\/a-z0-9_+\.~%&?@=_:;#,-]+))/ie',
-               '/([^:\/\/\w]|^)(mailto:(([a-zA-Z\@\%\.\-\+_])+))/ie'
-               );
-               $replaceTo = array(
-                       'COMMENT::createLinkCode("\\1", "\\2","https")',                
-                       'COMMENT::createLinkCode("\\1", "\\2","http")',
-                       'COMMENT::createLinkCode("\\1", "\\2","ftp")',
-                       'COMMENT::createLinkCode("\\1", "\\3","mailto")'                        
-               );
-               $body = preg_replace($replaceFrom, $replaceTo, $body);
-
-               return $body;
-       }
-       
-       function createLinkCode($pre, $url, $protocol = 'http') {
-               $post = '';
-       
-               // it's possible that $url ends contains entities we don't want,
-               // since htmlspecialchars is applied _before_ URL linking
-               // move the part of URL, starting from the disallowed entity to the 'post' link part
-               $aBadEntities = array('&quot;', '&gt;', '&lt;');
-               foreach ($aBadEntities as $entity)
-               {
-                       $pos = strpos($url, $entity);
-                       if ($pos)
-                       {
-                               $post = substr($url, $pos) . $post;
-                               $url = substr($url, 0, $pos);
-                               
-                       }
-               }
-               
-               // remove entities at end (&&&&)
-               if (preg_match('/(&\w+;)+$/i', $url, $matches)) {
-                       $post = $matches[0] . $post;    // found entities (1 or more)
-                       $url = substr($url, 0, strlen($url) - strlen($post));
-               }
-               
-               // move ending comma from url to 'post' part
-               if (substr($url, strlen($url) - 1) == ',')
-               {
-                       $url = substr($url, 0, strlen($url) - 1);
-                       $post = ',' . $post;
-               }
-
-               if (!ereg('^'.$protocol.'://',$url))
-                       $linkedUrl = $protocol . (($protocol == 'mailto') ? ':' : '://') . $url;
-               else
-                       $linkedUrl = $url;
-                       
-                       
-               if ($protocol != 'mailto')
-                       $displayedUrl = $linkedUrl;
-               else
-                       $displayedUrl = $url;
-               return $pre . '<a href="'.$linkedUrl.'">'.shorten($displayedUrl,30,'...').'</a>' . $post;
-       }
-       
-}
-
+<?php\r
+\r
+/**\r
+  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) \r
+  * Copyright (C) 2002-2004 The Nucleus Group\r
+  *\r
+  * This program is free software; you can redistribute it and/or\r
+  * modify it under the terms of the GNU General Public License\r
+  * as published by the Free Software Foundation; either version 2\r
+  * of the License, or (at your option) any later version.\r
+  * (see nucleus/documentation/index.html#license for more info)\r
+  *\r
+  * A class representing a single comment\r
+  */\r
+class COMMENT {\r
+       \r
+       /**\r
+         * Returns the requested comment (static)\r
+         */\r
+       function getComment($commentid) {\r
+               $query =  'SELECT cnumber as commentid, cbody as body, cuser as user, cmail as userid, cmember as memberid, ctime, chost as host, mname as member, cip as ip, cblog as blogid'\r
+                      . ' FROM '.sql_table('comment').' left outer join '.sql_table('member').' on cmember=mnumber'\r
+                      . ' WHERE cnumber=' . intval($commentid);\r
+               $comments = sql_query($query);\r
+\r
+               $aCommentInfo = mysql_fetch_assoc($comments);\r
+               if ($aCommentInfo)\r
+               {\r
+                       $aCommentInfo['timestamp'] = strtotime($aCommentInfo['ctime']);\r
+               }\r
+               return $aCommentInfo;\r
+       }       \r
+       \r
+       /**\r
+         * prepares a comment to be saved\r
+         * (static)\r
+         */\r
+       function prepare($comment) {\r
+               $comment['user'] = strip_tags($comment['user']);\r
+               $comment['userid'] = strip_tags($comment['userid']);\r
+               \r
+               // remove quotes and newlines from user and userid\r
+               $comment['user'] = strtr($comment['user'], "\'\"\n",'-- ');\r
+               $comment['userid'] = strtr($comment['userid'], "\'\"\n",'-- ');\r
+               \r
+               $comment['body'] = COMMENT::prepareBody($comment['body']);\r
+               \r
+               return $comment;\r
+       }\r
+       \r
+       // prepares the body of a comment (static)\r
+       function prepareBody($body) {\r
+       \r
+               // remove newlines when too many in a row\r
+               $body = ereg_replace("\n.\n.\n","\n",$body);\r
+\r
+               // encode special characters as entities\r
+               $body = htmlspecialchars($body);\r
+\r
+               // trim away whitespace and newlines at beginning and end\r
+               $body = trim($body);\r
+\r
+               // add <br /> tags\r
+               $body = addBreaks($body);\r
+       \r
+               // create hyperlinks for http:// addresses\r
+               // there's a testcase for this in /build/testcases/urllinking.txt\r
+               $replaceFrom = array(\r
+               '/([^:\/\/\w]|^)((https:\/\/)([a-z0-9_\.-]+)([\/a-z0-9_+\.~%&?@=_:;#,-]+))/ie',\r
+               '/([^:\/\/\w]|^)((http:\/\/|www\.)([a-z0-9_\.-]+)([\/a-z0-9_+\.~%&?@=_:;#,-]+))/ie',\r
+               '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([a-z0-9_\.-]+)([\/a-z0-9_+\.~%&?@=_:;#,-]+))/ie',\r
+               '/([^:\/\/\w]|^)(mailto:(([a-zA-Z\@\%\.\-\+_])+))/ie'\r
+               );\r
+               $replaceTo = array(\r
+                       'COMMENT::createLinkCode("\\1", "\\2","https")',                \r
+                       'COMMENT::createLinkCode("\\1", "\\2","http")',\r
+                       'COMMENT::createLinkCode("\\1", "\\2","ftp")',\r
+                       'COMMENT::createLinkCode("\\1", "\\3","mailto")'                        \r
+               );\r
+               $body = preg_replace($replaceFrom, $replaceTo, $body);\r
+\r
+               return $body;\r
+       }\r
+       \r
+       function createLinkCode($pre, $url, $protocol = 'http') {\r
+               $post = '';\r
+       \r
+               // it's possible that $url ends contains entities we don't want,\r
+               // since htmlspecialchars is applied _before_ URL linking\r
+               // move the part of URL, starting from the disallowed entity to the 'post' link part\r
+               $aBadEntities = array('&quot;', '&gt;', '&lt;');\r
+               foreach ($aBadEntities as $entity)\r
+               {\r
+                       $pos = strpos($url, $entity);\r
+                       if ($pos)\r
+                       {\r
+                               $post = substr($url, $pos) . $post;\r
+                               $url = substr($url, 0, $pos);\r
+                               \r
+                       }\r
+               }\r
+               \r
+               // remove entities at end (&&&&)\r
+               if (preg_match('/(&\w+;)+$/i', $url, $matches)) {\r
+                       $post = $matches[0] . $post;    // found entities (1 or more)\r
+                       $url = substr($url, 0, strlen($url) - strlen($post));\r
+               }\r
+               \r
+               // move ending comma from url to 'post' part\r
+               if (substr($url, strlen($url) - 1) == ',')\r
+               {\r
+                       $url = substr($url, 0, strlen($url) - 1);\r
+                       $post = ',' . $post;\r
+               }\r
+\r
+               if (!ereg('^'.$protocol.'://',$url))\r
+                       $linkedUrl = $protocol . (($protocol == 'mailto') ? ':' : '://') . $url;\r
+               else\r
+                       $linkedUrl = $url;\r
+                       \r
+                       \r
+               if ($protocol != 'mailto')\r
+                       $displayedUrl = $linkedUrl;\r
+               else\r
+                       $displayedUrl = $url;\r
+               return $pre . '<a href="'.$linkedUrl.'">'.shorten($displayedUrl,30,'...').'</a>' . $post;\r
+       }\r
+       \r
+}\r
+\r
 ?>
\ No newline at end of file