| [ Index ] |
PHP Cross Reference of Nucleus CMS 3.32 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 5 * Copyright (C) 2002-2007 The Nucleus Group 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * (see nucleus/documentation/index.html#license for more info) 12 */ 13 /** 14 * A class representing a single comment 15 * 16 * @license http://nucleuscms.org/license.txt GNU General Public License 17 * @copyright Copyright (C) 2002-2007 The Nucleus Group 18 * @version $Id: COMMENT.php 1116 2007-02-03 08:24:29Z kimitake $ 19 */ 20 class COMMENT { 21 22 /** 23 * Returns the requested comment (static) 24 */ 25 function getComment($commentid) { 26 $query = 'SELECT cnumber as commentid, cbody as body, cuser as user, cmail as userid, cemail as email, cmember as memberid, ctime, chost as host, mname as member, cip as ip, cblog as blogid' 27 . ' FROM '.sql_table('comment').' left outer join '.sql_table('member').' on cmember=mnumber' 28 . ' WHERE cnumber=' . intval($commentid); 29 $comments = sql_query($query); 30 31 $aCommentInfo = mysql_fetch_assoc($comments); 32 if ($aCommentInfo) 33 { 34 $aCommentInfo['timestamp'] = strtotime($aCommentInfo['ctime']); 35 } 36 return $aCommentInfo; 37 } 38 39 /** 40 * prepares a comment to be saved 41 * (static) 42 */ 43 function prepare($comment) { 44 $comment['user'] = strip_tags($comment['user']); 45 $comment['userid'] = strip_tags($comment['userid']); 46 $comment['email'] = strip_tags($comment['email']); 47 48 // remove quotes and newlines from user and userid 49 $comment['user'] = strtr($comment['user'], "\'\"\n",'-- '); 50 $comment['userid'] = strtr($comment['userid'], "\'\"\n",'-- '); 51 $comment['email'] = strtr($comment['email'], "\'\"\n",'-- '); 52 53 $comment['body'] = COMMENT::prepareBody($comment['body']); 54 55 return $comment; 56 } 57 58 // prepares the body of a comment (static) 59 function prepareBody($body) { 60 61 // remove newlines when too many in a row 62 $body = ereg_replace("\n.\n.\n","\n",$body); 63 64 // encode special characters as entities 65 $body = htmlspecialchars($body); 66 67 // trim away whitespace and newlines at beginning and end 68 $body = trim($body); 69 70 // add <br /> tags 71 $body = addBreaks($body); 72 73 // create hyperlinks for http:// addresses 74 // there's a testcase for this in /build/testcases/urllinking.txt 75 $replaceFrom = array( 76 '/([^:\/\/\w]|^)((https:\/\/)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', 77 '/([^:\/\/\w]|^)((http:\/\/|www\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', 78 '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', 79 '/([^:\/\/\w]|^)(mailto:(([a-zA-Z\@\%\.\-\+_])+))/ie' 80 ); 81 $replaceTo = array( 82 'COMMENT::createLinkCode("\\1", "\\2","https")', 83 'COMMENT::createLinkCode("\\1", "\\2","http")', 84 'COMMENT::createLinkCode("\\1", "\\2","ftp")', 85 'COMMENT::createLinkCode("\\1", "\\3","mailto")' 86 ); 87 $body = preg_replace($replaceFrom, $replaceTo, $body); 88 89 return $body; 90 } 91 92 function createLinkCode($pre, $url, $protocol = 'http') { 93 $post = ''; 94 95 // it's possible that $url ends contains entities we don't want, 96 // since htmlspecialchars is applied _before_ URL linking 97 // move the part of URL, starting from the disallowed entity to the 'post' link part 98 $aBadEntities = array('"', '>', '<'); 99 foreach ($aBadEntities as $entity) 100 { 101 $pos = strpos($url, $entity); 102 if ($pos) 103 { 104 $post = substr($url, $pos) . $post; 105 $url = substr($url, 0, $pos); 106 107 } 108 } 109 110 // remove entities at end (&&&&) 111 if (preg_match('/(&\w+;)+$/i', $url, $matches)) { 112 $post = $matches[0] . $post; // found entities (1 or more) 113 $url = substr($url, 0, strlen($url) - strlen($post)); 114 } 115 116 // move ending comma from url to 'post' part 117 if (substr($url, strlen($url) - 1) == ',') 118 { 119 $url = substr($url, 0, strlen($url) - 1); 120 $post = ',' . $post; 121 } 122 123 if (!ereg('^'.$protocol.'://',$url)) 124 $linkedUrl = $protocol . (($protocol == 'mailto') ? ':' : '://') . $url; 125 else 126 $linkedUrl = $url; 127 128 129 if ($protocol != 'mailto') 130 $displayedUrl = $linkedUrl; 131 else 132 $displayedUrl = $url; 133 return $pre . '<a href="'.$linkedUrl.'" rel="nofollow">'.shorten($displayedUrl,30,'...').'</a>' . $post; 134 } 135 136 } 137 138 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Feb 12 15:34:36 2008 | Cross-referenced by PHPXref 0.7 |