www.gusucode.com > citySHOP B2C商城系统 进销存 2.0.6码程序 > upload/editer/decode.inc.php
<?php /** * 默认编辑器视图模式 1=所见即所得模式 0=UBB模式 */ $viewmode = 1; /** * 表单 submit Javascript 事件 */ $submitCallback = ''; /** * [code][/code]内容数据 */ $messagecodes = array('pcodecount'=>0,'codehtml'=>0); /** * 自定义UBB标签解析 */ $bbcodes = array(); /** * 最大表情匹配次数 */ $maxsmilies = 10; /** * 表情定义 */ $smilies = array ( 'searcharray' => array ( 13 => '/\\:loveliness\\:/', 23 => '/\\:handshake/', 20 => '/\\:victory\\:/', 18 => '/\\:sleepy\\:/', 17 => '/\\:shutup\\:/', 16 => '/\\:dizzy\\:/', 15 => '/\\:curse\\:/', 43 => '/\\[g\\:03\\]/', 54 => '/\\[g\\:14\\]/', 34 => '/\\[m\\:10\\]/', 45 => '/\\[g\\:05\\]/', 56 => '/\\[g\\:16\\]/', 14 => '/\\:funk\\:/', 25 => '/\\[m\\:01\\]/', 36 => '/\\[m\\:12\\]/', 47 => '/\\[g\\:07\\]/', 27 => '/\\[m\\:03\\]/', 38 => '/\\[m\\:14\\]/', 49 => '/\\[g\\:09\\]/', 29 => '/\\[m\\:05\\]/', 40 => '/\\[m\\:16\\]/', 51 => '/\\[g\\:11\\]/', 31 => '/\\[m\\:07\\]/', 42 => '/\\[g\\:02\\]/', 53 => '/\\[g\\:13\\]/', 22 => '/\\:kiss\\:/', 33 => '/\\[m\\:09\\]/', 44 => '/\\[g\\:04\\]/', 55 => '/\\[g\\:15\\]/', 24 => '/\\:call\\:/', 35 => '/\\[m\\:11\\]/', 46 => '/\\[g\\:06\\]/', 57 => '/\\[g\\:17\\]/', 26 => '/\\[m\\:02\\]/', 37 => '/\\[m\\:13\\]/', 48 => '/\\[g\\:08\\]/', 28 => '/\\[m\\:04\\]/', 39 => '/\\[m\\:15\\]/', 50 => '/\\[g\\:10\\]/', 30 => '/\\[m\\:06\\]/', 41 => '/\\[g\\:01\\]/', 52 => '/\\[g\\:12\\]/', 21 => '/\\:time\\:/', 32 => '/\\[m\\:08\\]/', 19 => '/\\:hug\\:/', 12 => '/\\:lol/', 4 => '/\\:\'\\(/', 1 => '/\\:\\)/', 3 => '/\\:D/', 5 => '/\\:@/', 7 => '/\\:P/', 9 => '/;P/', 11 => '/\\:Q/', 2 => '/\\:\\(/', 6 => '/\\:o/', 8 => '/\\:\\$/', 10 => '/\\:L/', ), 'replacearray' => array ( 13 => 'loveliness.gif', 23 => 'handshake.gif', 20 => 'victory.gif', 18 => 'sleepy.gif', 17 => 'shutup.gif', 16 => 'dizzy.gif', 15 => 'curse.gif', 43 => '03.gif', 54 => '14.gif', 34 => '10.gif', 45 => '05.gif', 56 => '16.gif', 14 => 'funk.gif', 25 => '01.gif', 36 => '12.gif', 47 => '07.gif', 27 => '03.gif', 38 => '14.gif', 49 => '09.gif', 29 => '05.gif', 40 => '16.gif', 51 => '11.gif', 31 => '07.gif', 42 => '02.gif', 53 => '13.gif', 22 => 'kiss.gif', 33 => '09.gif', 44 => '04.gif', 55 => '15.gif', 24 => 'call.gif', 35 => '11.gif', 46 => '06.gif', 57 => '17.gif', 26 => '02.gif', 37 => '13.gif', 48 => '08.gif', 28 => '04.gif', 39 => '15.gif', 50 => '10.gif', 30 => '06.gif', 41 => '01.gif', 52 => '12.gif', 21 => 'time.gif', 32 => '08.gif', 19 => 'hug.gif', 12 => 'lol.gif', 4 => 'cry.gif', 1 => 'smile.gif', 3 => 'biggrin.gif', 5 => 'huffy.gif', 7 => 'tongue.gif', 9 => 'titter.gif', 11 => 'mad.gif', 2 => 'sad.gif', 6 => 'shocked.gif', 8 => 'shy.gif', 10 => 'sweat.gif', ), 'typearray' => array ( 13 => '1', 23 => '1', 20 => '1', 18 => '1', 17 => '1', 16 => '1', 15 => '1', 43 => '3', 54 => '3', 34 => '2', 45 => '3', 56 => '3', 14 => '1', 25 => '2', 36 => '2', 47 => '3', 27 => '2', 38 => '2', 49 => '3', 29 => '2', 40 => '2', 51 => '3', 31 => '2', 42 => '3', 53 => '3', 22 => '1', 33 => '2', 44 => '3', 55 => '3', 24 => '1', 35 => '2', 46 => '3', 57 => '3', 26 => '2', 37 => '2', 48 => '3', 28 => '2', 39 => '2', 50 => '3', 30 => '2', 41 => '3', 52 => '3', 21 => '1', 32 => '2', 19 => '1', 12 => '1', 4 => '1', 1 => '1', 3 => '1', 5 => '1', 7 => '1', 9 => '1', 11 => '1', 2 => '1', 6 => '1', 8 => '1', 10 => '1', ), ); $smilies['smileytypes'] = array ( 1 => array ('name' => '默认', 'directory' => 'default'), 2 => array ('name' => '酷猴', 'directory' => 'monkey'), 3 => array ('name' => '呆呆男', 'directory' => 'grapeman') ); $bbcodes = array ( 'searcharray' => array ( 0 => '/\\[fly]([^"\\[]+?)\\[\\/fly\\]/is', 1 => '/\\[flash]([^"\\[]+?)\\[\\/flash\\]/is', 2 => '/\\[qq]([^"\\[]+?)\\[\\/qq\\]/is', 3 => '/\\[sup]([^"\\[]+?)\\[\\/sup\\]/is', 4 => '/\\[sub]([^"\\[]+?)\\[\\/sub\\]/is', ), 'replacearray' => array ( 0 => '<marquee width="90%" behavior="alternate" scrollamount="3">\\1</marquee>', 1 => '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="550" height="400"><param name="allowScriptAccess" value="sameDomain"><param name="movie" value="\\1"><param name="quality" value="high"><param name="bgcolor" value="#ffffff"><embed src="\\1" quality="high" bgcolor="#ffffff" width="550" height="400" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>', 2 => '<a href="http://wpa.qq.com/msgrd?V=1&Uin=\\1&Site=[Discuz!]&Menu=yes" target="_blank"><img src="http://wpa.qq.com/pa?p=1:\\1:1" border="0"></a>', 3 => '<sup>\\1</sup>', 4 => '<sub>\\1</sub>', ), ); $messagecodes['smiliesreplaced'] = 0; function codedisp($code) { $messagecodes['pcodecount']++; $code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code))); $code = str_replace("\n", "<li>", $code); $messagecodes['codehtml'][$messagecodes['pcodecount']] = tpl_codedisp($messagecodes, $code); $messagecodes['codecount']++; return "[\tISOSHU_CODE_{$messagecodes[pcodecount]}\t]"; } function tpl_codedisp($messagecodes, $code) { $codesid = 'code' . $messagecodes['codecount']; $str = '<div class="blockcode"><div id="code'. $codesid . '"><ol><li>'.$code.'</li></ol></div>'; $str .= '<em onclick="copycode($(\''.$codesid.'\'));">复制</em></div>'; } function tpl_quote() { return '<div class="quote"><blockquote>\\1</blockquote></div>'; } function tpl_free() { return '<div class="quote"><blockquote>\\1</blockquote></div>'; } function bbcodeurl($url, $tags) { if(!preg_match("/<.+?>/s", $url)) { if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://'))) { $url = 'http://'.$url; } return str_replace(array('submit', 'logging.php'), array('', ''), sprintf($tags, $url, addslashes($url))); } else { return ' '.$url; } } function discuzcode($message) { global $smilies,$messagecodes,$maxsmilies,$bbcodes; if((strpos($message, '[/code]') || strpos($message, '[/CODE]')) !== FALSE) { $message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "codedisp('\\1')", $message); } $msglower = strtolower($message); $message = h($message); if(is_array($smilies)) { if(!$messagecodes['smiliesreplaced']) { foreach($smilies['replacearray'] AS $key => $smiley) { $smilies['replacearray'][$key] = '<img src="images/smilies/'.$smilies['smileytypes'][$smilies['typearray'][$key]]['directory'].'/'.$smiley.'" smilieid="'.$key.'" border="0" alt="" />'; } $messagecodes['smiliesreplaced'] = 1; } $message = preg_replace($smilies['searcharray'], $smilies['replacearray'], $message, $maxsmilies); } if(strpos($msglower, '[/url]') !== FALSE) { $message = preg_replace("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)([^\[\"']+?))?\](.+?)\[\/url\]/ies", "parseurl('\\1', '\\5')", $message); } if(strpos($msglower, '[/email]') !== FALSE) { $message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "parseemail('\\1', '\\4')", $message); } $message = str_replace(array( '[/color]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', '[i=s]', '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]', '[list=A]', '[*]', '[/list]', '[indent]', '[/indent]', '[/float]' ), array( '</font>', '</font>', '</font>', '</p>', '<strong>', '</strong>', '<i class="pstatus">', '<i>', '</i>', '<u>', '</u>', '<ul>', '<ul type="1">', '<ul type="a">', '<ul type="A">', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>' ), preg_replace(array( "/\[color=([#\w]+?)\]/i", "/\[size=(\d+?)\]/i", "/\[size=(\d+(\.\d+)?(px|pt|in|cm|mm|pc|em|ex|%)+?)\]/i", "/\[font=([^\[\<]+?)\]/i", "/\[align=(left|center|right)\]/i", "/\[float=(left|right)\]/i" ), array( "<font color=\"\\1\">", "<font size=\"\\1\">", "<font style=\"font-size: \\1\">", "<font face=\"\\1 \">", "<p align=\"\\1\">", "<span style=\"float: \\1;\">" ), $message)); $nest = 0; while(strpos($msglower, '[table') !== FALSE && strpos($msglower, '[/table]') !== FALSE){ $message = preg_replace("/\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*(.+?)\s*\[\/table\]/ies", "parsetable('\\1', '\\2', '\\3')", $message); if(++$nest > 4) break; } $parsetype = 0; if($parsetype != 1) { if(strpos($msglower, '[/quote]') !== FALSE) { $message = preg_replace("/\s*\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s*/is", tpl_quote(), $message); } if(strpos($msglower, '[/free]') !== FALSE) { $message = preg_replace("/\s*\[free\][\n\r]*(.+?)[\n\r]*\[\/free\]\s*/is", tpl_free(), $message); } } if(strpos($msglower, '[/media]') !== FALSE) { $message = preg_replace("/\[media=(\w{1,4}),(\d{1,4}),(\d{1,4}),(\d)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/ies", $allowmediacode ? "parsemedia('\\1', \\2, \\3, \\4, '\\5')" : "bbcodeurl('\\5', '<a href=\"%s\" target=\"_blank\">%s</a>')", $message); } if($bbcodes) { $message = preg_replace($bbcodes['searcharray'], $bbcodes['replacearray'], $message); } if($parsetype != 1 && strpos($msglower, '[swf]') !== FALSE) { $message = preg_replace("/\[swf\]\s*([^\[\<\r\n]+?)\s*\[\/swf\]/ies", "bbcodeurl('\\1', ' <img src=\"images/attachicons/flash.gif\" align=\"absmiddle\" alt=\"\" /> <a href=\"%s\" target=\"_blank\">Flash: %s</a> ')", $message); } $allowimgcode = 1; if(strpos($msglower, '[/img]') !== FALSE) { $message = preg_replace(array( "/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies", "/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies" ), $allowimgcode ? array( "bbcodeurl('\\1', '<img src=\"%s\" alt=\"\" />')", "bbcodeurl('\\3', '<img width=\"\\1\" height=\"\\2\" src=\"%s\" border=\"0\" alt=\"\" />')" ) : array( "bbcodeurl('\\1', '<a href=\"%s\" target=\"_blank\">%s</a>')", "bbcodeurl('\\3', '<a href=\"%s\" target=\"_blank\">%s</a>')" ), $message); } for($i = 0; $i <= $messagecodes['pcodecount']; $i++) { $message = str_replace("[\tISOSHU_CODE_$i\t]", $messagecodes['codehtml'][$i], $message); } unset($msglower); return nl2br(str_replace(array("\t", ' ', ' '), array(' ', ' ', ' '), $message)); } function parseurl($url, $text) { if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) { $url = $matches[0]; $length = 65; if(strlen($url) > $length) { $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3)); } return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>'; } else { $url = substr($url, 1); if(substr(strtolower($url), 0, 4) == 'www.') { $url = 'http://'.$url; } return '<a href="'.$url.'" target="_blank">'.$text.'</a>'; } } function parseemail($email, $text) { if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) { $email = trim($matches[0]); return '<a href="mailto:'.$email.'">'.$email.'</a>'; } else { return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>'; } } function parsetable($width, $bgcolor, $message) { if(!preg_match("/^\[tr(?:=([\(\)%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/", $message) && !preg_match("/^<tr[^>]*?>\s*<td[^>]*?>/", $message)) { return str_replace('\\"', '"', preg_replace("/\[tr(?:=([\(\)%,#\w]+))?\]|\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]|\[\/td\]|\[\/tr\]/", '', $message)); } if(substr($width, -1) == '%') { $width = substr($width, 0, -1) <= 98 ? intval($width).'%' : '98%'; } else { $width = intval($width); $width = $width ? ($width <= 560 ? $width.'px' : '98%') : ''; } return '<table cellspacing="0" class="t_table" '. ($width == '' ? NULL : 'style="width:'.$width.'"'). ($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>'). str_replace('\\"', '"', preg_replace(array( "/\[tr(?:=([\(\)%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ie", "/\[\/td\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ie", "/\[\/td\]\s*\[\/tr\]/i" ), array( "parsetrtd('\\1', '\\2', '\\3', '\\4')", "parsetrtd('td', '\\1', '\\2', '\\3')", '</td></tr>' ), $message) ).'</table>'; } function parsetrtd($bgcolor, $colspan, $rowspan, $width) { return ($bgcolor == 'td' ? '</td>' : '<tr'.($bgcolor ? ' bgcolor="'.$bgcolor.'"' : '').'>').'<td'.($colspan > 1 ? ' colspan="'.$colspan.'"' : '').($rowspan > 1 ? ' rowspan="'.$rowspan.'"' : '').($width ? ' width="'.$width.'"' : '').'>'; } function parsemedia($type, $width, $height, $autostart, $url) { if(in_array($type, array('ra', 'rm', 'wma', 'wmv', 'mp3', 'mov'))) { $url = str_replace(array('<', '>'), '', str_replace('\\"', '\"', $url)); $mediaid = 'media_'.random(3); switch($type) { case 'ra' : return '<object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" width="'.$width.'" height="32"><param name="autostart" value="'.$autostart.'" /><param name="src" value="'.$url.'" /><param name="controls" value="controlpanel" /><param name="console" value="'.$mediaid.'_" /><embed src="'.$url.'" type="audio/x-pn-realaudio-plugin" controls="ControlPanel" '.($autostart ? 'autostart="true"' : '').' console="'.$mediaid.'_" width="'.$width.'" height="32"></embed></object>';break; case 'rm' : return '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'.$width.'" height="'.$height.'"><param name="autostart" value="'.$autostart.'" /><param name="src" value="'.$url.'" /><param name="controls" value="imagewindow" /><param name="console" value="'.$mediaid.'_" /><embed src="'.$url.'" type="audio/x-pn-realaudio-plugin" controls="IMAGEWINDOW" console="'.$mediaid.'_" width="'.$width.'" height="'.$height.'"></embed></object><br /><object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" width="'.$width.'" height="32"><param name="src" value="'.$url.'" /><param name="controls" value="controlpanel" /><param name="console" value="'.$mediaid.'_" /><embed src="'.$url.'" type="audio/x-pn-realaudio-plugin" controls="ControlPanel" '.($autostart ? 'autostart="true"' : '').' console="'.$mediaid.'_" width="'.$width.'" height="32"></embed></object>';break; case 'wma' : return '<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'.$width.'" height="64"><param name="autostart" value="'.$autostart.'" /><param name="url" value="'.$url.'" /><embed src="'.$url.'" autostart="'.$autostart.'" type="audio/x-ms-wma" width="'.$width.'" height="64"></embed></object>';break; case 'wmv' : return '<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'.$width.'" height="'.$height.'"><param name="autostart" value="'.$autostart.'" /><param name="url" value="'.$url.'" /><embed src="'.$url.'" autostart="'.$autostart.'" type="video/x-ms-wmv" width="'.$width.'" height="'.$height.'"></embed></object>';break; case 'mp3' : return '<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'.$width.'" height="64"><param name="autostart" value="'.$autostart.'" /><param name="url" value="'.$url.'" /><embed src="'.$url.'" autostart="'.$autostart.'" type="application/x-mplayer2" width="'.$width.'" height="64"></embed></object>';break; case 'mov' : return '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'.$width.'" height="'.$height.'"><param name="autostart" value="'.($autostart ? 'true' : 'false').'" /><param name="src" value="'.$url.'" /><embed controller="true" width="'.$width.'" height="'.$height.'" src="'.$url.'" autostart="'.($autostart ? 'true' : 'false').'"></embed></object>';break; } } return; } function h($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = h($val); } } else { $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1', str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string)); } return $string; } ?>