1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
<?php
/* * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) * Copyright (C) 2002-2005 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 * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2005 The Nucleus Group * @version $Id: COMMENT.php,v 1.18.2.1 2005/08/15 10:50:12 dekarma 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:\/\/)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', '/([^:\/\/\w]|^)((http:\/\/|www\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/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('"', '>', '<'); 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.'" rel="nofollow">'.shorten($displayedUrl,30,'...').'</a>' . $post; }
}
?>
|