00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 {
00004 header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005 echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006 echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007 exit(1);
00008 }
00016
00017 function phpentities($text) {
00018 $search = array("&", "\"", "'", "\\", "<", ">");
00019 $replace = array("&", """, "'", "\", "<", ">");
00020 $text = str_replace($search, $replace, $text);
00021 return $text;
00022 }
00023
00024 global $urlRequestRoot,$sourceFolder,$moduleFolder,$cmsFolder;
00025 $imgpath=$urlRequestRoot."/".$cmsFolder."/".$moduleFolder."/forum/images/smileys";
00026 define("IMAGES","$imgpath");
00027 function parsesmileys($message) {
00028 global $IMAGES;
00029 $smiley = array(
00030 "#\:\)#si" => "<img title='Smile' src='".IMAGES."smile.gif' alt=':)'>",
00031 "#\;\)#si" => "<img title='Wink' src='".IMAGES."wink.gif' alt=';)'>",
00032 "#\:\(#si" => "<img title='Sad' src='".IMAGES."sad.gif' alt=':('>",
00033 "#\:\|#si" => "<img title='Frown' src='".IMAGES."frown.gif' alt=':|'>",
00034 "#\:o#si" => "<img title='Shock' src='".IMAGES."shock.gif' alt=':o'>",
00035 "#\:p#si" => "<img title='lol'src='".IMAGES."pfft.gif' alt=':P'>",
00036 "#b\)#si" => "<img title='Cool'src='".IMAGES."cool.gif' alt='B)'>",
00037 "#\:d#si" => "<img title='Grin' src='".IMAGES."grin.gif' alt=':D'>",
00038 "#\:@#si" => "<img title='Angry' src='".IMAGES."angry.gif' alt=':@'>",
00039 );
00040 foreach($smiley as $key=>$smiley_img) $message = preg_replace($key, $smiley_img, $message);
00041 return $message;
00042 }
00043 function parsenewline($text) {
00044 $text = preg_replace('#<br/>#si', '[br/]', $text);
00045 $text = preg_replace('#<br />#si', '[br /]', $text);
00046 return $text;
00047 }
00048
00049 function displaysmileys($textarea) {
00050 $smiles = "";
00051 $smileys = array (
00052 ":)" => "smile.gif",
00053 ";)" => "wink.gif",
00054 ":|" => "frown.gif",
00055 ":(" => "sad.gif",
00056 ":o" => "shock.gif",
00057 ":p" => "pfft.gif",
00058 "B)" => "cool.gif",
00059 ":D" => "grin.gif",
00060 ":@" => "angry.gif",
00061 );
00062 foreach($smileys as $key=>$smiley) $smiles .= "<img src='".IMAGES."$smiley' alt='smiley' onClick=\"insertText('$textarea', '$key');\">\n";
00063 return $smiles;
00064 }
00065
00066
00067 function parseubb($text) {
00068 $text = preg_replace('#\[b\](.*?)\[/b\]#si', '<b>\1</b>', $text);
00069 $text = preg_replace('#\[i\](.*?)\[/i\]#si', '<i>\1</i>', $text);
00070 $text = preg_replace('#\[u\](.*?)\[/u\]#si', '<u>\1</u>', $text);
00071 $text = preg_replace('#\[center\](.*?)\[/center\]#si', '<center>\1</center>', $text);
00072 $text = preg_replace('#\[br/\]#si', '<br/>', $text);
00073 $text = preg_replace('#\[br /\]#si', '<br />', $text);
00074 $text = preg_replace('#\[url\]([\r\n]*)(http://|ftp://|https://|ftps://)([^\s\'\";\+]*?)([\r\n]*)\[/url\]#si', '<a href=\'\2\3\' target=\'_blank\'>\2\3</a>', $text);
00075 $text = preg_replace('#\[url\]([\r\n]*)([^\s\'\";\+]*?)([\r\n]*)\[/url\]#si', '<a href=\'http://\2\' target=\'_blank\'>\2</a>', $text);
00076 $text = preg_replace('#\[url=([\r\n]*)(http://|ftp://|https://|ftps://)([^\s\'\";\+]*?)\](.*?)([\r\n]*)\[/url\]#si', '<a href=\'\2\3\' target=\'_blank\'>\4</a>', $text);
00077 $text = preg_replace('#\[url=([\r\n]*)([^\s\'\";\+]*?)\](.*?)([\r\n]*)\[/url\]#si', '<a href=\'http://\2\' target=\'_blank\'>\3</a>', $text);
00078
00079 $text = preg_replace('#\[mail\]([\r\n]*)([^\s\'\";:\+]*?)([\r\n]*)\[/mail\]#si', '<a href=\'mailto:\2\'>\2</a>', $text);
00080 $text = preg_replace('#\[mail=([\r\n]*)([^\s\'\";:\+]*?)\](.*?)([\r\n]*)\[/mail\]#si', '<a href=\'mailto:\2\'>\3</a>', $text);
00081
00082 $text = preg_replace('#\[small\](.*?)\[/small\]#si', '<span class=\'small\'>\1</span>', $text);
00083 $text = preg_replace('#\[color=(black|blue|brown|cyan|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|violet|white|yellow)\](.*?)\[/color\]#si', '<span style=\'color:\1\'>\2</span>', $text);
00084
00085 $text = preg_replace('#\[flash width=([0-9]*?) height=([0-9]*?)\]([^\s\'\";:\+]*?)(\.swf)\[/flash\]#si', '<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://active.macromedia.com/flash6/cabs/swflash.cab#version=6,0,0,0\' id=\'\3\4\' width=\'\1\' height=\'\2\'><param name=movie value=\'\3\4\'><param name=\'quality\' value=\'high\'><param name=\'bgcolor\' value=\'#ffffff\'><embed src=\'\3\4\' quality=\'high\' bgcolor=\'#ffffff\' width=\'\1\' height=\'\2\' type=\'application/x-shockwave-flash\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\'></embed></object>', $text);
00086 $text = preg_replace("#\[img\]((http|ftp|https|ftps)://)(.*?)(\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]#sie","'<img src=\'\\1'.str_replace(array('.php','?','&','='),'','\\3').'\\4\' style=\'border:0px\'>'",$text);
00087
00088 $qcount = substr_count($text, "[quote]"); $ccount = substr_count($text, "[code]");
00089 for ($i=0;$i < $qcount;$i++) $text = preg_replace('#\[quote\](.*?)\[/quote\]#si', '<div class=\'quote\'>\1</div>', $text);
00090 for ($i=0;$i < $ccount;$i++) $text = preg_replace('#\[code\](.*?)\[/code\]#si', '<div class=\'quote\' style=\'width:400px;white-space:nowrap;overflow:auto\'><code style=\'white-space:nowrap\'>\1<br><br><br></code></div>', $text);
00091
00092 $text = descript($text,false);
00093
00094 return $text;
00095 }
00096
00097
00098 function descript($text,$striptags=true) {
00099
00100 $search = array("40","41","58","65","66","67","68","69","70",
00101 "71","72","73","74","75","76","77","78","79","80","81",
00102 "82","83","84","85","86","87","88","89","90","97","98",
00103 "99","100","101","102","103","104","105","106","107",
00104 "108","109","110","111","112","113","114","115","116",
00105 "117","118","119","120","121","122"
00106 );
00107 $replace = array("(",")",":","a","b","c","d","e","f","g","h",
00108 "i","j","k","l","m","n","o","p","q","r","s","t","u",
00109 "v","w","x","y","z","a","b","c","d","e","f","g","h",
00110 "i","j","k","l","m","n","o","p","q","r","s","t","u",
00111 "v","w","x","y","z"
00112 );
00113 $entities = count($search);
00114 for ($i=0;$i < $entities;$i++) $text = preg_replace("#(&\#)(0*".$search[$i]."+);*#si", $replace[$i], $text);
00115
00116
00117 $text = preg_replace('#(&\#x)([0-9A-F]+);*#si', "", $text);
00118
00119 $text = preg_replace('#(<[^>]+[\\"\'\s])(onmouseover|onmousedown|onmouseup|onmouseout|onmousemove|onclick|ondblclick|onload|xmlns)[^>]*>#iU', ">", $text);
00120
00121 $text = preg_replace('#([a-z]*)=([\`\'\"]*)script:#iU', '$1=$2nojscript...', $text);
00122 $text = preg_replace('#([a-z]*)=([\`\'\"]*)javascript:#iU', '$1=$2nojavascript...', $text);
00123 $text = preg_replace('#([a-z]*)=([\'\"]*)vbscript:#iU', '$1=$2novbscript...', $text);
00124
00125 $text = preg_replace('#(<[^>]+)style=([\`\'\"]*).*expression\([^>]*>#iU', "$1>", $text);
00126 $text = preg_replace('#(<[^>]+)style=([\`\'\"]*).*behaviour\([^>]*>#iU', "$1>", $text);
00127 if ($striptags) {
00128 do {
00129 $thistext = $text;
00130 $text = preg_replace('#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i', "", $text);
00131 } while ($thistext != $text);
00132 }
00133 return $text;
00134 }
00135
00136
00137
00138 function censorwords($text) {
00139 global $settings;
00140 if ($settings['bad_words_enabled'] == "1" && $settings['bad_words'] != "" ) {
00141 $word_list = explode("\r\n", $settings['bad_words']);
00142 for ($i=0;$i < count($word_list);$i++) {
00143 if ($word_list[$i] != "") $text = preg_replace("/".$word_list[$i]."/si", $settings['bad_word_replace'], $text);
00144 }
00145 }
00146 return $text;
00147 }
00148
00149
00150 function makepagenav($start,$count,$total,$range=0,$link=""){
00151 global $locale;
00152 if ($link == "") $link = FUSION_SELF."?";
00153 $res="";
00154 $pg_cnt=ceil($total / $count);
00155 if ($pg_cnt > 1) {
00156 $idx_back = $start - $count;
00157 $idx_next = $start + $count;
00158 $cur_page=ceil(($start + 1) / $count);
00159 $res.="<table cellspacing='1' cellpadding='1' border='0' class='tbl-border'>\n<tr>\n";
00160 $res.="<td class='tbl2'><span class='small'>".$locale['052']."$cur_page".$locale['053']."$pg_cnt</span></td>\n";
00161 if ($idx_back >= 0) {
00162 if ($cur_page > ($range + 1)) $res.="<td class='tbl2'><a class='small' href='$link"."rowstart=0'><<</a></td>\n";
00163 $res.="<td class='tbl2'><a class='small' href='$link"."rowstart=$idx_back'><</a></td>\n";
00164 }
00165 $idx_fst=max($cur_page - $range, 1);
00166 $idx_lst=min($cur_page + $range, $pg_cnt);
00167 if ($range==0) {
00168 $idx_fst = 1;
00169 $idx_lst=$pg_cnt;
00170 }
00171 for($i=$idx_fst;$i<=$idx_lst;$i++) {
00172 $offset_page=($i - 1) * $count;
00173 if ($i==$cur_page) {
00174 $res.="<td class='tbl1'><span class='small'><b>$i</b></span></td>\n";
00175 } else {
00176 $res.="<td class='tbl1'><a class='small' href='$link"."rowstart=$offset_page'>$i</a></td>\n";
00177 }
00178 }
00179 if ($idx_next < $total) {
00180 $res.="<td class='tbl2'><a class='small' href='$link"."rowstart=$idx_next'>></a></td>\n";
00181 if ($cur_page < ($pg_cnt - $range)) $res.="<td class='tbl2'><a class='small' href='$link"."rowstart=".($pg_cnt-1)*$count."'>>></a></td>\n";
00182 }
00183 $res.="</tr>\n</table>\n";
00184
00185 }
00186 return $res;
00187 }
00188