Dragonfly CMS logo Server sponsored and hosted by
DedicatedNOW
CVS logo  
.:: Home :: Dev. Resources :: Forums ::.
Dragonfly CMS CVS Repository
 Location: / cvs / html / includes / nbbcode.php
This is a web interface to the Dragonfly CMS CVS tree. You can browse the file hierarchy by picking directories. If you pick a file, you will see the revision history for that file.
Selecting a revision number will show that revision of the file. There are links at each revision to display diffs, annotate and download.
Note: Info about CVS and our commits can be found at our CVS Info Forum
File name: html/includes/nbbcode.php
Revision : 10.8 (2 years 2 months 4 weeks 7 hours 14 minutes 21 seconds ago) by nanocaiordo
Changed : +3 -5 lines
Comment: v10, fixed bbcode img tag.


# Author Rev Line
1 djmaze 1.1 <?php
2 djmaze 1.1 /*********************************************
3 djmaze 9.12 CPG Dragonfly™ CMS
4 djmaze 1.1 ********************************************
5 nanocaio 9.38 Copyright © 2004 - 2007 by CPG-Nuke Dev Team
6 djmaze 9.27 http://dragonflycms.org
7 djmaze 1.1  
8 djmaze 8.41 Dragonfly is released under the terms and conditions
9 djmaze 8.13 of the GNU GPL version 2 or any later version
10 djmaze 1.1  
11 djmaze 9.13 $Source: /cvs/html/includes/nbbcode.php,v $
12 nanocaio 10.8 $Revision: 10.7 $
13 nanocaio 10.2 $Author: nanocaiordo $
14 nanocaio 10.8 $Date: 2011/12/12 10:46:19 $
15 djmaze 8.41 **********************************************/
16 trevor 8.22 if (!defined('CPG_NUKE')) { exit; }
17 djmaze 1.1  
18 akamu 9.22  
19 akamu 9.22 global $db, $prefix, $smilies_path, $bbbttns_path, $BASEHREF, $CPG_SESS, $bb_codes, $smilies_close, $bbcode_common;
20 akamu 9.22  
21 djmaze 9.32 $smilies_path = file_exists("themes/$CPG_SESS[theme]/images/smiles/icon_smile.gif") ? "themes/$CPG_SESS[theme]/images/smiles/" : 'images/smiles/';
22 djmaze 9.31 $bbbttns_path = file_exists("themes/$CPG_SESS[theme]/images/bbcode/b.gif") ? "themes/$CPG_SESS[theme]/images/bbcode/" : 'themes/default/images/bbcode/';
23 djmaze 1.1  
24 djmaze 8.10 get_lang('bbcode');
25 djmaze 1.16  
26 nanocaio 9.53 $bb_codes['quote'] = '<div class="genmed"><b>'.$bbcode_common['quote'][0].':</b></div>
27 estlane 9.56 <div class="quote">';
28 nanocaio 9.53 $bb_codes['quote_name'] = '<div class="genmed"><b>\\1 '.$bbcode_common['Wrote'].':</b></div>
29 estlane 9.56 <div class="quote">';
30 nanocaio 9.53 $bb_codes['quote_close'] = '</div>';
31 nanocaio 9.53 $bb_codes['code_start'] = '<div class="genmed"><b>'.$bbcode_common['code'][0].':</b></div>
32 estlane 9.56 <div class="code"><code>';
33 nanocaio 9.53 $bb_codes['code_end'] = '</code></div>';
34 phoenix 9.47 $bb_codes['php_start'] = '<table border="0" style="margin:auto;" width="90%" cellpadding="3" cellspacing="1"><tr>
35 estlane 9.56 <td><span class="genmed"><b>PHP:</b></span></td>
36 djmaze 9.12 </tr><tr>
37 estlane 9.56 <td class="code">';
38 djmaze 8.31 $bb_codes['php_end'] = '</td></tr></table>';
39 djmaze 8.31 $bb_codes['win_start'] = '<html>
40 djmaze 8.31 <head>
41 djmaze 8.31 <title>Smiley Selection</title>
42 djmaze 8.31 <base href="'.$BASEHREF.'" />
43 djmaze 8.31 <link rel="stylesheet" href="themes/'.$CPG_SESS['theme'].'/style/style.css" type="text/css" />
44 djmaze 8.31 </head>
45 djmaze 8.31 <body>
46 phoenix 9.40 <script type="text/javascript">
47 djmaze 8.31 <!--
48 djmaze 8.31 function emoticon(form, field, text) {
49 estlane 9.56 text = \' \' + text + \' \';
50 estlane 9.56 if (opener.document.forms[form].elements[field].createTextRange && opener.document.forms[form].elements[field].caretPos) {
51 estlane 9.56 var caretPos = opener.document.forms[form].elements[field].caretPos;
52 estlane 9.56 caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == \' \' ? text + \' \' : text;
53 estlane 9.56 opener.document.forms[form].elements[field].focus();
54 estlane 9.56 } else {
55 estlane 9.56 opener.document.forms[form].elements[field].value += text;
56 estlane 9.56 opener.document.forms[form].elements[field].focus();
57 estlane 9.56 }
58 djmaze 8.31 }
59 djmaze 8.31 //-->
60 djmaze 8.31 </script>';
61 djmaze 9.12 $bb_codes['win_end'] = '<br />
62 phoenix 9.47 <div style="text-align:center;"><a href="javascript:window.close();" class="genmed">'.$smilies_close.'</a></div>
63 djmaze 8.31 </body></html>';
64 djmaze 8.31 if (file_exists('themes/'.$CPG_SESS['theme'].'/bbcode.inc')) {
65 estlane 9.56 include('themes/'.$CPG_SESS['theme'].'/bbcode.inc');
66 djmaze 8.27 }
67 djmaze 8.27  
68 djmaze 1.1 function get_code_lang($var, $array) {
69 estlane 9.56 return (isset($array[$var])) ? $array[$var] : $var;
70 djmaze 1.1 }
71 djmaze 1.1  
72 djmaze 1.1 function smilies_table($mode, $field='message', $form='post')
73 djmaze 1.1 {
74 estlane 9.56 global $bb_codes, $db, $prefix, $smilies_path, $MAIN_CFG, $CPG_SESS;
75 estlane 9.56 global $smilies_more, $smilies_desc;
76 estlane 9.56 $url = $MAIN_CFG['server']['path'].URL::index("smilies&amp;field=$field&amp;form=$form");
77 estlane 9.56  
78 estlane 9.56 $inline_cols = 4;
79 estlane 9.56 $inline_rows = 5;
80 estlane 9.56 $window_cols = 8;
81 estlane 9.56  
82 estlane 9.56 $content = '';
83 estlane 9.56 if ($mode == 'window') {
84 estlane 9.56 $content = $bb_codes['win_start'];
85 estlane 9.56 } else if (!defined('BBCODE_JS_ACTIVE')) {
86 estlane 9.56 $content .= '<script src="includes/javascript/bbcode.js" type="text/javascript"></script>';
87 estlane 9.56 define('BBCODE_JS_ACTIVE', 1);
88 estlane 9.56 }
89 estlane 9.56 if ($mode == 'onerow') {
90 estlane 9.56 $content .= '
91 djmaze 8.20 <table width="450" border="0" cellspacing="0" cellpadding="0" class="forumline">';
92 estlane 9.56 } else {
93 estlane 9.56 $content .= '
94 djmaze 8.20 <table width="100" border="0" cellspacing="0" cellpadding="5" class="forumline">';
95 estlane 9.56 }
96 estlane 9.56 $smilies = get_smilies();
97 estlane 9.56 if (is_array($smilies)) {
98 estlane 9.56 $num_smilies = 0;
99 estlane 9.56 $rowset = array();
100 estlane 9.56 #while ($row = $db->sql_fetchrow($result)) {
101 estlane 9.56 for ($i=0; $i<count($smilies); ++$i) {
102 estlane 9.56 if (empty($rowset[$smilies[$i]['smile_url']])) {
103 estlane 9.56 $rowset[$smilies[$i]['smile_url']]['code'] = str_replace("'", "\\'", str_replace('\\', '\\\\', $smilies[$i]['code']));
104 djmaze 9.20 # process the smiley description
105 estlane 9.56 $rowset[$smilies[$i]['smile_url']]['emoticon'] = get_code_lang($smilies[$i]['emoticon'],$smilies_desc);
106 estlane 9.56 $num_smilies++;
107 estlane 9.56 }
108 estlane 9.56 }
109 estlane 9.56 if ($num_smilies) {
110 estlane 9.56 $smilies_count = ($mode == 'inline') ? min(19, $num_smilies) : $num_smilies;
111 estlane 9.56 $smilies_split_row = ($mode == 'inline') ? $inline_cols - 1 : $window_cols - 1;
112 estlane 9.56  
113 estlane 9.56 $s_colspan = $row = $col = 0;
114 estlane 9.56  
115 estlane 9.56 while (list($smile_url, $data) = each($rowset)) {
116 estlane 9.56 if (!$col) {
117 estlane 9.56 $content .= '<tr align="center" valign="middle">';
118 estlane 9.56 }
119 estlane 9.56 $content .= "<td><a href=\"javascript:emoticon('".$form."', '".$field."', '".$data['code']."')\"><img src=\"" . $smilies_path . $smile_url . "\" style=\"border:0;\" alt=\"".$data['emoticon']."\" title=\"".$data['emoticon']."\" /></a></td>";
120 estlane 9.56 $s_colspan = max($s_colspan, $col + 1);
121 estlane 9.56  
122 estlane 9.56 if ($mode == 'onerow') {
123 estlane 9.56 if ($col >= 15) {
124 estlane 9.56 if ($num_smilies > 15) {
125 estlane 9.56 $content .= "<td colspan=\"$s_colspan\" class=\"nav\"><a href=\"$url\" onclick=\"window.open('$url', '_smilies', 'height=200,resizable=yes,scrollbars=yes,width=230');return false;\" target=\"_smilies\" class=\"nav\">$smilies_more</a></td>";
126 estlane 9.56 }
127 estlane 9.56 break;
128 estlane 9.56 }
129 estlane 9.56 $col++;
130 estlane 9.56 }
131 estlane 9.56 else if ($col == $smilies_split_row) {
132 estlane 9.56 $content .= '</tr>';
133 estlane 9.56 $col = 0;
134 estlane 9.56 if ($mode == 'inline' && $row == $inline_rows - 1) {
135 estlane 9.56 break;
136 estlane 9.56 }
137 estlane 9.56 $row++;
138 estlane 9.56 }
139 estlane 9.56 else { $col++; }
140 estlane 9.56 }
141 estlane 9.56 if ($col > 0) { $content .= '</tr>'; }
142 estlane 9.56  
143 estlane 9.56 if ($mode == 'inline' && $num_smilies > $inline_rows * $inline_cols) {
144 estlane 9.56 $content .= "<tr align=\"center\">
145 estlane 9.56 <td colspan=\"$s_colspan\" class=\"nav\"><a href=\"$url\" onclick=\"window.open('$url', '_smilies', 'height=200,resizable=yes,scrollbars=yes,width=230');return false;\" target=\"_smilies\" class=\"nav\">$smilies_more</a></td>
146 estlane 9.56 </tr>";
147 estlane 9.56 }
148 estlane 9.56 }
149 estlane 9.56 }
150 estlane 9.56 $content .= "\n</table>\n";
151 estlane 9.56 if ($mode == 'window') { $content .= $bb_codes['win_end']; }
152 estlane 9.56 return $content;
153 djmaze 1.1 }
154 djmaze 1.1  
155 djmaze 1.1 function bbcode_table($field='message', $form='post', $allowed=0)
156 djmaze 1.1 {
157 estlane 9.56 global $bbbttns_path, $color_desc, $font_desc, $textcolor1, $bbcode_common;
158 nanocaio 10.6 $content = '';
159 nanocaio 10.6 if (!defined('BBCODE_JS_ACTIVE')) {
160 nanocaio 10.6 $content .= ' <script type="text/javascript">
161 nanocaio 10.6 var b_help = "'. $bbcode_common['bold'][0].' '.$bbcode_common['bold'][1].'";
162 nanocaio 10.6 var i_help = "'. $bbcode_common['italic'][0].' '.$bbcode_common['italic'][1].'";
163 nanocaio 10.6 var u_help = "'. $bbcode_common['underline'][0].' '.$bbcode_common['underline'][1].'";
164 nanocaio 10.6 var quote_help = "'. $bbcode_common['quote'][0].' '.$bbcode_common['quote'][1].'";
165 nanocaio 10.6 var code_help = "'. $bbcode_common['code'][0].' '.$bbcode_common['code'][1].'";
166 nanocaio 10.6 var php_help = "'. $bbcode_common['php'][0].' '.$bbcode_common['php'][1].'";
167 nanocaio 10.6 var img_help = "'. $bbcode_common['img'][0].' '.$bbcode_common['img'][1].'";
168 nanocaio 10.6 var fc_help = "'. $bbcode_common['fc'][0].' '.$bbcode_common['fc'][1].'";
169 nanocaio 10.6 var fs_help = "'. $bbcode_common['fs'][0].' '.$bbcode_common['fs'][1].'";
170 nanocaio 10.6 var ft_help = "'. $bbcode_common['ft'][0].' '.$bbcode_common['ft'][1].'";
171 nanocaio 10.6 var rtl_help = "'. $bbcode_common['rtl'][0].' '.$bbcode_common['rtl'][1].'";
172 nanocaio 10.6 var ltr_help = "'. $bbcode_common['ltr'][0].' '.$bbcode_common['ltr'][1].'";
173 nanocaio 10.6 var mail_help = "'. $bbcode_common['mail'][0].' '.$bbcode_common['mail'][1].'";
174 nanocaio 10.6 var url_help= "'. $bbcode_common['url'][0].' '.$bbcode_common['url'][1].'";
175 nanocaio 10.6 var right_help= "'. $bbcode_common['right'][0].' '.$bbcode_common['right'][1].'";
176 nanocaio 10.6 var left_help= "'. $bbcode_common['left'][0].' '.$bbcode_common['left'][1].'";
177 nanocaio 10.6 var center_help= "'. $bbcode_common['center'][0].' '.$bbcode_common['center'][1].'";
178 nanocaio 10.6 var justify_help= "'. $bbcode_common['justify'][0].' '.$bbcode_common['justify'][1].'";
179 nanocaio 10.6 var marqr_help= "'. $bbcode_common['marqr'][0].' '.$bbcode_common['marqr'][1].'";
180 nanocaio 10.6 var marql_help= "'. $bbcode_common['marql'][0].' '.$bbcode_common['marql'][1].'";
181 nanocaio 10.6 var marqu_help= "'. $bbcode_common['marqu'][0].' '.$bbcode_common['marqu'][1].'";
182 nanocaio 10.6 var marqd_help= "'. $bbcode_common['marqd'][0].' '.$bbcode_common['marqd'][1].'";
183 nanocaio 10.6 var hr_help= "'. $bbcode_common['hr'][0].' '.$bbcode_common['hr'][1].'";
184 nanocaio 10.6 var video_help="'. $bbcode_common['video'][0].' '.$bbcode_common['video'][1].'";
185 nanocaio 10.7 var flash_help="'. $bbcode_common['flash'][0].' '.$bbcode_common['flash'][1].'";</script>';
186 nanocaio 10.7 JS::add('includes/javascript/bbcode.js');
187 nanocaio 10.7 $content .= JS::flushToTpl();
188 nanocaio 10.6 define('BBCODE_JS_ACTIVE', 1);
189 nanocaio 10.6 }
190 nanocaio 10.6 $content .= '<table cellpadding="0" cellspacing="0">
191 djmaze 9.12 <tr>
192 estlane 9.56 <td>
193 estlane 9.56 <img alt="'.$bbcode_common['bold'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'b\')" onclick="BBCcode(\''.$form.'\',\''.$field.'\',this,\'b\')" src="'.$bbbttns_path.'b.gif" />
194 estlane 9.56 <img alt="'.$bbcode_common['italic'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'i\')" onclick="BBCcode(\''.$form.'\',\''.$field.'\',this,\'i\')" src="'.$bbbttns_path.'i.gif" />
195 estlane 9.56 <img alt="'.$bbcode_common['underline'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'u\')" onclick="BBCcode(\''.$form.'\',\''.$field.'\',this,\'u\')" src="'.$bbbttns_path.'u.gif" />
196 djmaze 1.1 &nbsp;&nbsp;
197 estlane 9.56 <img alt="'.$bbcode_common['ltr'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'ltr\')" onclick="BBCdir(\''.$form.'\',\''.$field.'\',\'ltr\')" src="'.$bbbttns_path.'ltr.gif" />
198 estlane 9.56 <img alt="'.$bbcode_common['rtl'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'rtl\')" onclick="BBCdir(\''.$form.'\',\''.$field.'\',\'rtl\')" src="'.$bbbttns_path.'rtl.gif" />
199 djmaze 1.1 &nbsp;&nbsp;
200 estlane 9.56 <img alt="'.$bbcode_common['url'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'url\')" onclick="BBCurl(\''.$form.'\',\''.$field.'\')" src="'.$bbbttns_path.'url.gif" />
201 estlane 9.56 <img alt="'.$bbcode_common['mail'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'mail\')" onclick="BBCwmi(\''.$form.'\',\''.$field.'\',\'email\')" src="'.$bbbttns_path.'email.gif" />';
202 estlane 9.56 if ($allowed) {
203 estlane 9.56 $content .= '
204 djmaze 1.1 &nbsp;&nbsp;
205 estlane 9.56 <img alt="'.$bbcode_common['justify'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'justify\')" onclick="BBCode(\''.$form.'\',\''.$field.'\',\'align\',this,\'justify\')" src="'.$bbbttns_path.'align_justify.gif" />
206 estlane 9.56 <img alt="'.$bbcode_common['left'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'left\')" onclick="BBCode(\''.$form.'\',\''.$field.'\',\'align\',this,\'left\')" src="'.$bbbttns_path.'align_left.gif" />
207 estlane 9.56 <img alt="'.$bbcode_common['center'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'center\')" onclick="BBCode(\''.$form.'\',\''.$field.'\',\'align\',this,\'center\')" src="'.$bbbttns_path.'align_center.gif" />
208 estlane 9.56 <img alt="'.$bbcode_common['right'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'right\')" onclick="BBCode(\''.$form.'\',\''.$field.'\',\'align\',this,\'right\')" src="'.$bbbttns_path.'align_right.gif" />';
209 estlane 9.56 }
210 estlane 9.56 $content .= '
211 djmaze 1.1 &nbsp;&nbsp;
212 estlane 9.56 <select onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'fc\')" onchange="BBCfc(\''.$form.'\',\''.$field.'\',this)" title="'.$color_desc['color'].'">
213 estlane 9.56 <option class="genmed" value="'.$textcolor1.'" style="color: black; background-color: rgb(250, 250, 250);">'.$color_desc['Default'].'</option>
214 estlane 9.56 <option class="genmed" value="maroon" style="color: maroon; background-color: rgb(250, 250, 250);">'.$color_desc['Dark Red'].'</option>
215 estlane 9.56 <option class="genmed" value="red" style="color: red; background-color: rgb(250, 250, 250);">'.$color_desc['Red'].'</option>
216 estlane 9.56 <option class="genmed" value="orange" style="color: orange; background-color: rgb(250, 250, 250);">'.$color_desc['Orange'].'</option>
217 estlane 9.56 <option class="genmed" value="brown" style="color: brown; background-color: rgb(250, 250, 250);">'.$color_desc['Brown'].'</option>
218 estlane 9.56 <option class="genmed" value="yellow" style="color: yellow; background-color: rgb(250, 250, 250);">'.$color_desc['Yellow'].'</option>
219 estlane 9.56 <option class="genmed" value="green" style="color: green; background-color: rgb(250, 250, 250);">'.$color_desc['Green'].'</option>
220 estlane 9.56 <option class="genmed" value="olive" style="color: olive; background-color: rgb(250, 250, 250);">'.$color_desc['Olive'].'</option>
221 estlane 9.56 <option class="genmed" value="cyan" style="color: cyan; background-color: rgb(250, 250, 250);">'.$color_desc['Cyan'].'</option>
222 estlane 9.56 <option class="genmed" value="blue" style="color: blue; background-color: rgb(250, 250, 250);">'.$color_desc['Blue'].'</option>
223 estlane 9.56 <option class="genmed" value="darkblue" style="color: darkblue; background-color: rgb(250, 250, 250);">'.$color_desc['Dark Blue'].'</option>
224 estlane 9.56 <option class="genmed" value="indigo" style="color: indigo; background-color: rgb(250, 250, 250);">'.$color_desc['Indigo'].'</option>
225 estlane 9.56 <option class="genmed" value="violet" style="color: violet; background-color: rgb(250, 250, 250);">'.$color_desc['Violet'].'</option>
226 estlane 9.56 <option class="genmed" value="white" style="color: white; background-color: rgb(250, 250, 250);">'.$color_desc['White'].'</option>
227 estlane 9.56 <option class="genmed" value="black" style="color: black; background-color: rgb(250, 250, 250);">'.$color_desc['Black'].'</option>
228 estlane 9.56 </select>';
229 estlane 9.56 if ($allowed) {
230 estlane 9.56 $content .= '
231 estlane 9.56 </td>
232 djmaze 9.12 </tr><tr>
233 estlane 9.56 <td>
234 estlane 9.56 <img alt="'.$bbcode_common['img'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'img\')" onclick="BBCwmi(\''.$form.'\',\''.$field.'\',\'img\')" src="'.$bbbttns_path.'img.gif" />
235 estlane 9.56 <img alt="'.$bbcode_common['flash'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'flash\')" onclick="BBCmm(\''.$form.'\',\''.$field.'\',\'flash\')" src="'.$bbbttns_path.'flash.gif" />
236 estlane 9.56 <img alt="'.$bbcode_common['video'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'video\')" onclick="BBCmm(\''.$form.'\',\''.$field.'\',\'video\')" src="'.$bbbttns_path.'video.gif" />
237 djmaze 8.2 &nbsp;&nbsp;
238 estlane 9.56 <img alt="'.$bbcode_common['quote'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'quote\')" onclick="BBCcode(\''.$form.'\',\''.$field.'\',this,\'quote\')" src="'.$bbbttns_path.'quote.gif" />
239 estlane 9.56 <img alt="'.$bbcode_common['code'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'code\')" onclick="BBCcode(\''.$form.'\',\''.$field.'\',this,\'code\')" src="'.$bbbttns_path.'code.gif" />
240 estlane 9.56 <img alt="'.$bbcode_common['php'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'php\')" onclick="BBCcode(\''.$form.'\',\''.$field.'\',this,\'php\')" src="'.$bbbttns_path.'php.gif" />
241 djmaze 1.1 &nbsp;&nbsp;
242 estlane 9.56 <img alt="'.$bbcode_common['hr'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'hr\')" onclick="BBChr(\''.$form.'\',\''.$field.'\')" src="'.$bbbttns_path.'hr.gif" />
243 djmaze 1.1 &nbsp;&nbsp;
244 estlane 9.56 <img alt="'.$bbcode_common['marqd'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'marqd\')" onclick="BBCode(\''.$form.'\',\''.$field.'\',\'marq\',this,\'down\')" src="'.$bbbttns_path.'marq_down.gif" />
245 estlane 9.56 <img alt="'.$bbcode_common['marqu'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'marqu\')" onclick="BBCode(\''.$form.'\',\''.$field.'\',\'marq\',this,\'up\')" src="'.$bbbttns_path.'marq_up.gif" />
246 estlane 9.56 <img alt="'.$bbcode_common['marql'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'marql\')" onclick="BBCode(\''.$form.'\',\''.$field.'\',\'marq\',this,\'left\')" src="'.$bbbttns_path.'marq_left.gif" />
247 estlane 9.56 <img alt="'.$bbcode_common['marqr'][0].'" class="bbcbutton" onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'marqr\')" onclick="BBCode(\''.$form.'\',\''.$field.'\',\'marq\',this,\'right\')" src="'.$bbbttns_path.'marq_right.gif" />
248 djmaze 1.1 &nbsp;&nbsp;
249 estlane 9.56 <select onmouseover="helpline(\''.$form.'\',\''.$field.'\',\'fs\')" onchange="BBCfs(\''.$form.'\',\''.$field.'\',this)" title="'.$font_desc['size'].'">
250 estlane 9.56 <option value="7" class="genmed">'.$font_desc['Tiny'].'</option>
251 estlane 9.56 <option value="9" class="genmed">'.$font_desc['Small'].'</option>
252 estlane 9.56 <option value="12" class="genmed" selected="selected">'.$font_desc['Normal'].'</option>
253 estlane 9.56 <option value="18" class="genmed">'.$font_desc['Large'].'</option>
254 estlane 9.56 <option value="24" class="genmed">'.$font_desc['Huge'].'</option>
255 estlane 9.56 </select>';
256 estlane 9.56 }
257 estlane 9.56 $content .= '
258 estlane 9.56 </td>
259 djmaze 9.12 </tr><tr>
260 estlane 9.56 <td>
261 estlane 9.56 <input type="text" name="help'.$field.'" size="66" maxlength="100" value="'.$bbcode_common['Tip'].'" class="helpline" />
262 estlane 9.56 </td>
263 djmaze 1.1 </tr>
264 djmaze 1.1 </table>';
265 djmaze 1.1  
266 estlane 9.56 return $content;
267 djmaze 1.1 }
268 djmaze 1.1  
269 djmaze 9.28 function get_smilies() {
270 estlane 9.56 global $db, $prefix;
271 estlane 9.56 $smilies = Cache::array_load('smilies','bb', false);
272 estlane 9.56 if (!$smilies) {
273 estlane 9.56 $smilies = $db->sql_ufetchrowset('SELECT * FROM '.$prefix.'_bbsmilies', SQL_ASSOC);
274 estlane 9.56 if (count($smilies)) {
275 estlane 9.56 usort($smilies, 'sort_smiley');
276 estlane 9.56 Cache::array_save('smilies','bb', $smilies);
277 estlane 9.56 }
278 estlane 9.56 }
279 estlane 9.56 return $smilies;
280 djmaze 9.28 }
281 djmaze 9.20 # smilies_pass(
282 djmaze 1.1 function set_smilies($message, $url='') {
283 nanocaio 10.4 depricated_warning();
284 nanocaio 10.4 return BBCode::setSmilies($message, $url);
285 djmaze 1.1 }
286 djmaze 1.1  
287 djmaze 1.1 function sort_smiley($a, $b)
288 djmaze 1.1 {
289 nanocaio 10.4 depricated_warning();
290 estlane 9.56 if ($a['pos'] == $b['code']) { return 0; }
291 estlane 9.56 return ($a['pos'] < $b['pos']) ? -1 : 1;
292 estlane 9.56 // if (strlen($a['code']) == strlen($b['code'])) { return 0; }
293 estlane 9.56 // return (strlen($a['code']) > strlen($b['code'])) ? -1 : 1;
294 djmaze 9.3 }
295 djmaze 9.3  
296 djmaze 9.20 # bbencode_first_pass() prepare bbcode for db insert
297 djmaze 9.3 function encode_bbcode($text)
298 djmaze 9.3 {
299 nanocaio 10.4 depricated_warning();
300 estlane 9.56 return BBCode::encode($text);
301 djmaze 1.1 }
302 djmaze 9.1 function decode_bb_all($text, $allowed=0, $allow_html=false, $url='') {
303 nanocaio 10.4 depricated_warning();
304 nanocaio 10.4 return BBCode::decodeAll($text, $allowed, $allow_html, $url);
305 djmaze 9.1 }
306 djmaze 9.30 function decode_bbcode($text, $allowed=0, $allow_html=false)
307 djmaze 9.15 {
308 nanocaio 10.4 depricated_warning();
309 estlane 9.56 return BBCode::decode($text, $allowed, $allow_html);
310 djmaze 9.15 }
311 djmaze 9.15  
312 djmaze 1.22 function shrink_url($url) {
313 estlane 9.56 $url = preg_replace("#(^[\w]+?://)#", '', $url);
314 estlane 9.56 return (strlen($url) > 35) ? substr($url,0,22).'...'.substr($url,-10) : $url;
315 djmaze 1.22 }
316 djmaze 1.1  
317 djmaze 1.1 function make_clickable($text)
318 djmaze 1.1 {
319 estlane 9.56 $ret = ' ' . $text;
320 estlane 9.56 $ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1<a href=\"\\2\" rel=\"nofollow\" title=\"\\2\" target=\"_blank\">'.shrink_url('\\2').'</a>'", $ret);
321 estlane 9.56 $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://\\2\" rel=\"nofollow\" target=\"_blank\" title=\"\\2\">'.shrink_url('\\2').'</a>'", $ret);
322 estlane 9.56 $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1 \\2 &#64; \\3", $ret);
323 estlane 9.56 $ret = substr($ret, 1);
324 estlane 9.56 return($ret);
325 djmaze 1.1 }
326 djmaze 1.1  
327 djmaze 9.20 # prepare_message(
328 djmaze 1.1 function message_prepare($message, $html_on, $bbcode_on)
329 djmaze 1.1 {
330 estlane 9.56 #
331 estlane 9.56 # Clean up the message
332 estlane 9.56 #
333 estlane 9.56 $message = trim($message);
334 nanocaio 9.60 /*if ($html_on) {
335 nanocaio 9.60 $allowed_html_tags = split(',', 'b,i,u,pre');
336 estlane 9.56 $end_html = 0;
337 estlane 9.56 $start_html = 1;
338 estlane 9.56 $tmp_message = '';
339 estlane 9.56 $message = ' ' . $message . ' ';
340 estlane 9.56 while ($start_html = strpos($message, '<', $start_html)) {
341 estlane 9.56 $tmp_message .= BBCode::encode_html(substr($message, $end_html + 1, ($start_html - $end_html - 1)));
342 estlane 9.56 if ($end_html = strpos($message, '>', $start_html)) {
343 estlane 9.56 $length = $end_html - $start_html + 1;
344 estlane 9.56 $hold_string = substr($message, $start_html, $length);
345 estlane 9.56 if (($unclosed_open = strrpos(' ' . $hold_string, '<')) != 1) {
346 estlane 9.56 $tmp_message .= BBCode::encode_html(substr($hold_string, 0, $unclosed_open - 1));
347 estlane 9.56 $hold_string = substr($hold_string, $unclosed_open - 1);
348 estlane 9.56 }
349 estlane 9.56 $tagallowed = false;
350 estlane 9.56 for ($i = 0; $i < sizeof($allowed_html_tags); $i++) {
351 estlane 9.56 $match_tag = trim($allowed_html_tags[$i]);
352 estlane 9.56 if (preg_match('#^<\/?' . $match_tag . '[> ]#i', $hold_string)) {
353 estlane 9.56 $tagallowed = (preg_match('#^<\/?' . $match_tag . ' .*?(style[ ]*?=|on[\w]+[ ]*?=)#i', $hold_string)) ? false : true;
354 estlane 9.56 }
355 estlane 9.56 }
356 estlane 9.56 $tmp_message .= ($length && !$tagallowed) ? BBCode::encode_html($hold_string) : $hold_string;
357 estlane 9.56 $start_html += $length;
358 estlane 9.56 } else {
359 estlane 9.56 $tmp_message .= BBCode::encode_html(substr($message, $start_html));
360 estlane 9.56 $start_html = strlen($message);
361 estlane 9.56 $end_html = $start_html;
362 estlane 9.56 }
363 estlane 9.56 }
364 estlane 9.56 if ($end_html != strlen($message) && $tmp_message != '') {
365 estlane 9.56 $tmp_message .= BBCode::encode_html(substr($message, $end_html + 1));
366 estlane 9.56 }
367 estlane 9.56 $message = ($tmp_message != '') ? trim($tmp_message) : trim($message);
368 nanocaio 9.60 } else {*/
369 estlane 9.56 $message = BBCode::encode_html($message);
370 nanocaio 9.60 /*}*/
371 estlane 9.56 if ($bbcode_on) {
372 estlane 9.56 $message = BBCode::encode($message);
373 estlane 9.56 }
374 estlane 9.56 return $message;
375 djmaze 8.31 }
376 djmaze 9.3  
377 nanocaio 9.49 abstract class BBCode {
378 djmaze 9.3  
379 nanocaio 10.4 public static function decodeAll($text, $allowed=0, $allow_html=false, $url='') {
380 nanocaio 10.4 return BBCode::setSmilies(BBCode::decode($text, $allowed, $allow_html), $url);
381 nanocaio 10.4 }
382 nanocaio 10.4  
383 nanocaio 10.4  
384 nanocaio 10.4 public static function setSmilies($message, $url='')
385 nanocaio 10.4 {
386 nanocaio 10.4 static $orig, $repl;
387 nanocaio 10.4 if (!isset($orig)) {
388 nanocaio 10.4 global $smilies_path, $smilies_desc;
389 nanocaio 10.4 $orig = $repl = array();
390 nanocaio 10.4 $smilies = get_smilies();
391 nanocaio 10.4 if ($url != '' && substr($url, -1) != '/') { $url .= '/'; }
392 nanocaio 10.4 for ($i = 0; $i < count($smilies); $i++) {
393 nanocaio 10.4 $smilies[$i]['code'] = str_replace('#', '\#', preg_quote($smilies[$i]['code']));
394 nanocaio 10.4 $orig[] = "#([\s])".$smilies[$i]['code']."([\s<])#si";
395 nanocaio 10.4 $repl[] = '\\1<img class="bbsmilies" src="' . $url . $smilies_path . $smilies[$i]['smile_url'] . '" alt="'.get_code_lang($smilies[$i]['emoticon'],$smilies_desc).'" title="'.get_code_lang($smilies[$i]['emoticon'],$smilies_desc).'" />\\2';
396 nanocaio 10.4 }
397 nanocaio 10.4 }
398 nanocaio 10.4 if (count($orig)) {
399 nanocaio 10.4 $message = preg_replace($orig, $repl, " $message ");
400 nanocaio 10.4 $message = substr($message, 1, -1);
401 nanocaio 10.4 }
402 nanocaio 10.4 return $message;
403 nanocaio 10.4 }
404 nanocaio 10.4  
405 estlane 9.56 public static function encode_html($text) {
406 estlane 9.56 return (false !== strpos($text, '<')) ? htmlprepare($text, false, ENT_NOQUOTES) : $text;
407 estlane 9.56 }
408 estlane 9.56  
409 estlane 9.56 public static function encode($text)
410 estlane 9.56 {
411 estlane 9.56 # Split all bbcodes.
412 estlane 9.56 $text_parts = BBCode::split_bbcodes($text);
413 estlane 9.56 # Merge all bbcodes and do special actions depending on the type of code.
414 estlane 9.56 $text = '';
415 estlane 9.56 while ($part = array_shift($text_parts)) {
416 estlane 9.56 if (isset($part['code'])) {
417 estlane 9.56 if ($part['code'] == 'list' && $part['text'][5] == '=' && substr($part['text'], -3) != ':o]') {
418 estlane 9.56 # [list=x] for ordered lists.
419 estlane 9.56 $part['text'] = substr($part['text'], 0, -1).':o]';
420 estlane 9.56 }
421 estlane 9.56 if ($part['code'] != 'code' && $part['code'] != 'php' && $part['subc']) {
422 estlane 9.56 $part['text'] = '['.encode_bbcode(substr($part['text'], 1, -1)).']';
423 estlane 9.56 }
424 estlane 9.56 }
425 estlane 9.56 $text .= $part['text'];
426 estlane 9.56 }
427 estlane 9.56 return trim($text);
428 estlane 9.56 }
429 estlane 9.56  
430 estlane 9.56 public static function decode($text, $allowed=0, $allow_html=false)
431 estlane 9.56 {
432 estlane 9.56 global $bb_codes;
433 estlane 9.56 # First: If there isn't a "[" and a "]" in the message, don't bother.
434 estlane 9.56 if (!(strpos($text, '[') !== false && strpos($text, ']'))) {
435 estlane 9.56 return ($allow_html ? (false !== strpos($text, '<') ? $text : nl2br($text)) : nl2br(strip_tags($text)));
436 estlane 9.56 }
437 estlane 9.56  
438 estlane 9.56 // strip the obsolete bbcode_uid
439 estlane 9.56 $text = preg_replace("/:(([a-z0-9]+:)?)[a-z0-9]{10}(=|\])/si", '\\3', $text);
440 estlane 9.56  
441 estlane 9.56 # pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
442 estlane 9.56 $text = BBCode::split_on_bbcodes($text, $allowed, $allow_html);
443 estlane 9.56  
444 estlane 9.56 # Patterns and replacements for URL, email tags etc.
445 estlane 9.56 $patterns = $replacements = array();
446 estlane 9.56  
447 estlane 9.56 # replace single & to &amp;
448 estlane 9.56 $text = preg_replace('/&(?![a-z]{2,6};|#[0-9]{1,4};)/is', '&amp;', $text);
449 estlane 9.56  
450 estlane 9.56 # colours
451 estlane 9.56 $patterns[] = '#\[color=(\#[0-9A-F]{6}|[a-z]+)\](.*?)\[/color\]#si';
452 estlane 9.56 $replacements[] = '<span style="color: \\1">\\2</span>';
453 estlane 9.56  
454 estlane 9.56 # size
455 estlane 9.56 $patterns[] = '#\[size=([1-2]?[0-9])\](.*?)\[/size\]#si';
456 estlane 9.56 $replacements[] = '<span style="font-size: \\1px; line-height: normal">\\2</span>';
457 estlane 9.56  
458 estlane 9.56 # [b] and [/b] for bolding text.
459 estlane 9.56 $patterns[] = '#\[b\](.*?)\[/b\]#si';
460 estlane 9.56 $replacements[] = '<span style="font-weight: bold">\\1</span>';
461 estlane 9.56  
462 estlane 9.56 # [u] and [/u] for underlining text.
463 estlane 9.56 $patterns[] = '#\[u\](.*?)\[/u\]#si';
464 estlane 9.56 $replacements[] = '<span style="text-decoration: underline">\\1</span>';
465 estlane 9.56  
466 estlane 9.56 # [i] and [/i] for italicizing text.
467 estlane 9.56 $patterns[] = '#\[i\](.*?)\[/i\]#si';
468 estlane 9.56 $replacements[] = '<span style="font-style: italic">\\1</span>';
469 estlane 9.56  
470 estlane 9.56 # align
471 estlane 9.56 $patterns[] = '#\[align=(left|right|center|justify)\](.*?)\[/align\]#si';
472 estlane 9.56 $replacements[] = '<div style="text-align:\\1">\\2</div>';
473 estlane 9.56  
474 estlane 9.56 # [google]search string[/google]
475 estlane 9.56 $patterns[] = "#\[search=google\](.*?)\[/search\]#ise";
476 estlane 9.56 $replacements[] = "'<form action=\"http://google.com/search\" method=\"get\"><input type=\"text\" name=\"q\" value=\"'.trim('\\1').'\" /><input type=\"submit\" value=\"Search Google\" /></form>'";
477 estlane 9.56 $patterns[] = "#\[search\](.*?)\[/search\]#ise";
478 estlane 9.56 $replacements[] = "'<form action=\"search.html\" method=\"post\"><input type=\"text\" name=\"search\" value=\"'.trim('\\1').'\" /><input type=\"submit\" value=\"Search\" /></form>'";
479 estlane 9.56 // $replacements[] = "'<a href=\"http://google.com/search?q='.urlencode(trim('\\1')).'\" target=\"_blank\" class=\"postlink\" rel=\"nofollow\">\\1</a>'";
480 estlane 9.56  
481 estlane 9.56 # [url] local
482 estlane 9.56 $patterns[] = "#\[url\]([\w]+(\.html|\.php|/)[^ \[\"\n\r\t<]*?)\[/url\]#ise";
483 estlane 9.56 $replacements[] = "'<a href=\"\\1\" title=\"\\1\" class=\"postlink\">'.shrink_url('\\1').'</a>'";
484 estlane 9.56 $patterns[] = "#\[url=([\w]+(\.html|\.php|/)[^ \[\"\n\r\t<]*?)\](.*?)\[/url\]#is";
485 estlane 9.56 $replacements[] = "<a href=\"\\1\" title=\"\\1\" class=\"postlink\">\\3</a>";
486 estlane 9.56  
487 estlane 9.56 # [url]xxxx://www.cpgnuke.com[/url]
488 estlane 9.59 $patterns[] = "#\[url\]([\w]+?://[^ \[\"\n\r\t<]*?)\[/url\]#ise";
489 estlane 9.56 $replacements[] = "'<a href=\"\\1\" target=\"_blank\" title=\"\\1\" class=\"postlink\" rel=\"nofollow\">'.shrink_url('\\1').'</a>'";
490 estlane 9.56 # [url]www.cpgnuke.com[/url] (no xxxx:// prefix).
491 estlane 9.59 $patterns[] = "#\[url\]((www|ftp)\.[^ \[\"\n\r\t<]*?)\[/url\]#ise";
492 estlane 9.56 $replacements[] = "'<a href=\"http://\\1\" target=\"_blank\" title=\"\\1\" class=\"postlink\" rel=\"nofollow\">'.shrink_url('\\1').'</a>'";
493 estlane 9.56 # [url=www.cpgnuke.com]cpgnuke[/url] (no xxxx:// prefix).
494 estlane 9.56 $patterns[] = "#\[url=((www|ftp)\.[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is";
495 estlane 9.56 $replacements[] = "<a href=\"http://\\1\" target=\"_blank\" title=\"\\1\" class=\"postlink\" rel=\"nofollow\">\\3</a>";
496 estlane 9.56 # [url=xxxx://www.cpgnuke.com]cpgnuke[/url]
497 estlane 9.59 $patterns[] = "#\[url=([\w]+://[^ (\"\n\r\t<]*?)\](.*?)\[/url\]#is";
498 estlane 9.56 $replacements[] = "<a href=\"\\1\" target=\"_blank\" title=\"\\1\" class=\"postlink\" rel=\"nofollow\">\\2</a>";
499 estlane 9.56  
500 estlane 9.56 # [email]user@domain.tld[/email] code..
501 estlane 9.56 $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
502 estlane 9.56 $replacements[] = "<a href=\"mailto:\\1\">\\1</a>";
503 estlane 9.56  
504 estlane 9.56 if ($allowed) {
505 estlane 9.56 # [hr]
506 estlane 9.56 $patterns[] = "#\[hr\]#si";
507 estlane 9.56 $replacements[] = '<hr />';
508 estlane 9.56  
509 estlane 9.56 # marquee
510 estlane 9.56 $patterns[] = "#\[marq=(left|right|up|down)\](.*?)\[/marq\]#si";
511 estlane 9.56 $replacements[] = '<marquee direction="\\1" scrolldelay="60" scrollamount="1" onmouseover="this.stop()" onmouseout="this.start()">\\2</marquee>';
512 estlane 9.56  
513 estlane 9.56 # [img]image_url_here[/img] code..
514 nanocaio 10.8 $patterns[] = "#\[img\]([\w]+(://|\.|/)[^ \?%=&(\"\n\r\t<\\\]*?)\[/img\]#si";
515 estlane 9.56 $replacements[] = "<img src=\"\\1\" alt=\"\" />";
516 estlane 9.56  
517 estlane 9.56 # [flash width= height= loop= ] and [/flash] code..
518 estlane 9.56 $patterns[] = "#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9])\]((ht|f)tp://)([^ \?&=\"\n\r\t<]*?(\.(swf|fla)))\[/flash\]#si";
519 estlane 9.56 $replacements[] = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="\\1" height="\\2">
520 estlane 9.56 <param name="movie" value="\\3\\5" />
521 estlane 9.56 <param name="quality" value="high" />
522 estlane 9.56 <param name="scale" value="noborder" />
523 estlane 9.56 <param name="wmode" value="transparent" />
524 estlane 9.56 <param name="bgcolor" value="#000000" />
525 djmaze 9.15 <embed src="\\3\\5" quality="high" scale="noborder" wmode="transparent" bgcolor="#000000" width="\\1" height="\\2" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
526 djmaze 9.15 </embed></object>';
527 djmaze 9.15  
528 estlane 9.56 # [video width= height= loop= ] and [/video] code..
529 estlane 9.56 $patterns[] = "#\[video width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9])\]([\w]+?://[^ \?&=\"\n\r\t<]*?(\.(avi|mpg|mpeg|wmv)))\[/video\]#si";
530 estlane 9.56 $replacements[] = '<embed src="\\3" width=\\1 height=\\2></embed>';
531 estlane 9.56 }
532 estlane 9.56  
533 estlane 9.56 $text = preg_replace($patterns, $replacements, $text);
534 estlane 9.56  
535 estlane 9.56 # Fix linebreaks on important items
536 estlane 9.56 $text = preg_replace('#<br>#si', '<br />', $text);
537 estlane 9.56 $text = preg_replace('#<ul><br \/>#si', '<ul>', $text);
538 estlane 9.56 $text = preg_replace('#<\/ul><br \/>#si', '</ul>', $text);
539 estlane 9.56 $text = preg_replace('#<\/ol><br \/>#si', '</ol>', $text);
540 estlane 9.56 $text = preg_replace('#<\/table><br \>#si', '</table>', $text);
541 estlane 9.56 $text = preg_replace('#<\/div><br \/>#si', '</div>', $text);
542 estlane 9.56 $text = preg_replace('#<br \/><table#si', '<table', $text);
543 estlane 9.56  
544 estlane 9.56 # Remove our padding from the string..
545 estlane 9.56 return trim($text);
546 estlane 9.56 }
547 estlane 9.56  
548 estlane 9.56 protected static function split_bbcodes($text)
549 estlane 9.56 {
550 estlane 9.56 $curr_pos = 0;
551 estlane 9.56 $str_len = strlen($text);
552 estlane 9.56 $text_parts = array();
553 estlane 9.56 while ($curr_pos < $str_len) {
554 estlane 9.56 # Find bbcode start tag, if not found end the loop.
555 estlane 9.56 $curr_pos = strpos($text, '[', $curr_pos);
556 estlane 9.56 if ($curr_pos === false) { break; }
557 estlane 9.56 $end = strpos($text, ']', $curr_pos);
558 estlane 9.56 if ($end === false) { break; }
559 estlane 9.56  
560 estlane 9.56 $code_start = substr($text, $curr_pos, $end-$curr_pos+1);
561 estlane 9.56 $code = strtolower(preg_replace('/\[([a-z]+).*]/i', '\\1', $code_start));
562 estlane 9.56 $code_len = strlen($code);
563 estlane 9.56  
564 estlane 9.56 $end_pos = empty($code) ? false : $end;
565 estlane 9.56 $depth = 0;
566 estlane 9.56 $sub = false;
567 estlane 9.56 while ($end_pos) {
568 estlane 9.56 # Find bbcode end tag, if not found end the loop.
569 estlane 9.56 $end_pos = strpos($text, '[', $end_pos);
570 estlane 9.56 if ($end_pos === false) { break; }
571 estlane 9.56 $end = strpos($text, ']', $end_pos);
572 estlane 9.56 if ($end === false) { break; }
573 estlane 9.56 $code_end = strtolower(substr($text, $end_pos, $code_len+2));
574 estlane 9.56 if ($code_end == "[/$code") {
575 estlane 9.56 if ($depth > 0) {
576 estlane 9.56 $depth--;
577 estlane 9.56 $end_pos++;
578 estlane 9.56 $sub = true;
579 estlane 9.56 } else {
580 estlane 9.56 if ($curr_pos > 0) {
581 estlane 9.56 $text_parts[] = array('text' => substr($text, 0, $curr_pos), 'code' => false, 'subc' => false);
582 estlane 9.56 }
583 estlane 9.56 $text_parts[] = array(
584 estlane 9.56 'text' => substr($text, $curr_pos, $end-$curr_pos+1),
585 estlane 9.56 'code' => $code,
586 estlane 9.56 'subc' => $sub);
587 estlane 9.56 $text = substr($text, $end+1);
588 estlane 9.56 $str_len = strlen($text);
589 estlane 9.56 $curr_pos = 0;
590 estlane 9.56 break;
591 estlane 9.56 }
592 estlane 9.56 } else {
593 estlane 9.56 if (substr($code_end, 0, -1) == "[$code") { $depth++; }
594 estlane 9.56 $end_pos++;
595 estlane 9.56 }
596 estlane 9.56 }
597 estlane 9.56 $curr_pos++;
598 estlane 9.56 }
599 estlane 9.56 if ($str_len > 0) { $text_parts[] = array('text' => $text, 'code' => false, 'subc' => false); }
600 estlane 9.56 return $text_parts;
601 estlane 9.56 }
602 estlane 9.56  
603 estlane 9.56 # split the bbcodes and use nl2br on everything except [php]
604 estlane 9.56 protected static function split_on_bbcodes($text, $allowed=0, $allow_html=false)
605 estlane 9.56 {
606 estlane 9.56 global $bb_codes;
607 estlane 9.56 # Split all bbcodes.
608 estlane 9.56 $text_parts = BBCode::split_bbcodes($text);
609 estlane 9.56 # Merge all bbcodes and do special actions depending on the type of code.
610 estlane 9.56 $text = '';
611 estlane 9.56 while ($part = array_shift($text_parts)) {
612 estlane 9.56 if ($part['code'] == 'php') {
613 estlane 9.56 # [PHP]
614 estlane 9.56 $text .= ($allowed) ? BBCode::decode_php($part['text']) : nl2br(htmlspecialchars($part['text']));
615 estlane 9.56 } elseif ($part['code'] == 'code') {
616 estlane 9.56 # [CODE]
617 estlane 9.56 if (!$allowed && false !== strpos($part['text'], '<')) {
618 estlane 9.56 $part['text'] = nl2br(htmlspecialchars($part['text']));
619 estlane 9.56 }
620 estlane 9.56 $text .= $allowed ? BBCode::decode_code($part['text']) : $part['text'];
621 estlane 9.56 } elseif ($part['code'] == 'quote') {
622 estlane 9.56 # [QUOTE] and [QUOTE=""]
623 estlane 9.56 if ($part['text'][6] == ']') {
624 estlane 9.56 $text .= $bb_codes['quote'].BBCode::split_on_bbcodes(substr($part['text'], 7, -8), $allowed, $allow_html).$bb_codes['quote_close'];
625 estlane 9.56 } else {
626 estlane 9.56 $part['text'] = preg_replace('/\[quote=["]*(.*?)["]*\]/si', $bb_codes['quote_name'], BBCode::split_on_bbcodes(substr($part['text'], 0, -8), $allowed, $allow_html), 1);
627 estlane 9.56 $text .= $part['text'].$bb_codes['quote_close'];
628 estlane 9.56 }
629 estlane 9.56 } elseif ($part['subc']) {
630 estlane 9.56 $tmptext = '['.BBCode::split_on_bbcodes(substr($part['text'], 1, -1)).']';
631 estlane 9.56 $text .= ($part['code'] == 'list') ? BBCode::decode_list($tmptext) : $tmptext;
632 estlane 9.56 unset($tmptext);
633 estlane 9.56 } else {
634 estlane 9.56 if ($allow_html) {
635 estlane 9.56 $tmptext = (false === strpos($part['text'], '<') ? nl2br($part['text']) : $part['text']);
636 estlane 9.56 } else {
637 estlane 9.56 $tmptext = nl2br(BBCode::encode_html($part['text']));
638 estlane 9.56 }
639 estlane 9.56 $text .= ($part['code'] == 'list') ? BBCode::decode_list($tmptext) : $tmptext;
640 estlane 9.56 unset($tmptext);
641 estlane 9.56 }
642 estlane 9.56 }
643 estlane 9.56 return $text;
644 estlane 9.56 }
645 estlane 9.56  
646 estlane 9.56 protected static function decode_code($text)
647 estlane 9.56 {
648 estlane 9.56 global $bb_codes;
649 estlane 9.56 $text = substr($text, 6, -7);
650 estlane 9.56 $code_entities_match = array('#<#', '#>#', '#"#', '#:#', '#\[#', '#\]#', '#\(#', '#\)#', '#\{#', '#\}#');
651 estlane 9.56 $code_entities_replace = array('&lt;', '&gt;', '&quot;', '&#58;', '&#91;', '&#93;', '&#40;', '&#41;', '&#123;', '&#125;');
652 estlane 9.56 $text = preg_replace($code_entities_match, $code_entities_replace, $text);
653 estlane 9.56 return $bb_codes['code_start']."<pre>$text</pre>".$bb_codes['code_end'];
654 estlane 9.56 }
655 estlane 9.56  
656 estlane 9.56 protected static function decode_php($text)
657 estlane 9.56 {
658 estlane 9.56 global $bb_codes;
659 estlane 9.56 $text = str_replace("\r\n", "\n", substr($text, 5, -6)); # Windows
660 estlane 9.56 $text = str_replace("\r", "\n", $text); # Mac
661 estlane 9.56 $text = str_replace("\t", '/*t*/', $text); # Temporary tab fix
662 estlane 9.56 $text = htmlunprepare($text, true);
663 estlane 9.56 $added = FALSE;
664 estlane 9.56 if (preg_match('/^<\?.*/', $text) <= 0) {
665 estlane 9.56 $text = "<?php\n$text";
666 estlane 9.56 $added = TRUE;
667 estlane 9.56 }
668 estlane 9.56 $text = highlight_string($text, TRUE);
669 estlane 9.56 if ($added == TRUE) {
670 estlane 9.56 $text = preg_replace('/^(.*)\n.*php<br \/><\/span>/i', "\\1\n", $text, 1);
671 estlane 9.56 $text = preg_replace('/^(.*)\n(.*)>.*php<br \/>/i', "\\1\n\\2>", $text, 1);
672 estlane 9.56 }
673 estlane 9.56 $text = str_replace('[', '&#91;', $text);
674 estlane 9.56 $text = str_replace("\n", '', $text);
675 estlane 9.56 $text = str_replace('&nbsp;', ' ', $text);
676 estlane 9.56 $text = str_replace('/*t*/', "\t", $text);
677 estlane 9.56 $text = preg_replace('#<span style="color: \#[A-F0-9]{6}">([\t]+)</span>#', '\\1', $text);
678 estlane 9.56 return $bb_codes['php_start']."<pre>$text</pre>".$bb_codes['php_end'];
679 estlane 9.56 }
680 estlane 9.56  
681 estlane 9.56 protected static function decode_list($text)
682 estlane 9.56 {
683 estlane 9.56 // &(?![a-z]{2,6};|#[0-9]{1,4};)
684 estlane 9.56 $items = explode('[*]', $text);
685 estlane 9.56 $text = array_shift($items).'<li>';
686 estlane 9.56 $text .= implode('</li><li>', $items);
687 estlane 9.56 if (count($items) > 1) $text = str_replace('[/list', '</li>[/list', $text);
688 estlane 9.56 $text = preg_replace("#<br />[\r\n]+</li>#", "</li>\n", $text);
689 estlane 9.56 unset($items);
690 estlane 9.56 # [list] and [list=x] for (un)ordered lists.
691 estlane 9.56 # unordered lists
692 estlane 9.56 $text = preg_replace('#\[list\]#i', '<ul>', $text);
693 estlane 9.56 $text = preg_replace('#\[/list:u\]#i', '</ul>', $text);
694 estlane 9.56 $text = preg_replace('#\[/list\]#i', '</ul>', $text);
695 estlane 9.56 # Ordered lists
696 estlane 9.56 $text = preg_replace('#\[list=([ai1])\]#i', '<ol type="\\1">', $text);
697 estlane 9.56 $text = preg_replace('#\[/list:o\]#i', '</ol>', $text);
698 estlane 9.56  
699 estlane 9.56 $text = preg_replace('#(<[ou]l.*?>)<br />#s', '\\1', $text);
700 estlane 9.56 return $text;
701 estlane 9.56 }
702 djmaze 9.20  
703 nanocaio 10.2 }
704 nanocaio 10.2  
705 nanocaio 10.2  
706 nanocaio 10.3 if (isset($Module) && $Module->name == 'smilies') {
707 nanocaio 10.2 echo smilies_table('window', $_GET['field'], $_GET['form']);
708 nanocaio 10.2 exit;
709 nanocaio 10.2 }


Code Credits - Privacy Policy