Просмотр файла system/inc/classes/bbcode.class.php

Размер файла: 4.76Kb
<?php

	/*
	 * Обработка ссылки
	*/
	function parser_link($link) {
	    
		return'<a target="_blank" href="http://'.$_SERVER['HTTP_HOST'].'/go.php?url='.@base64_encode(''.$link[1].'').'">'.$link[2].'</a>';
	}
      /*
       * Обработка Спойлера 
      */
	function parser_spoiler($spoiler) {
	    
		return '<div class="hide"><b><a href="#" onclick="show_hide(\'#'.bbcode::process($spoiler[1]).'\');">'.$spoiler[1].'</a></b>
	            <div id="'.bbcode::process($spoiler[1]).'" style="display: none; overflow: hidden; vertical-align: top;">'.$spoiler[2].'</div></div>';
	}


abstract class bbcode {
  /*
   * Класс для обработки текста
   * @authot: Shamsik
   * @var bbcode   
  */
    public function process($text) {
	        $process = array(' '=>'_');
                if( $type == 'link' ) {
                    $process[' '] = '_';
                }
                $process = strtr( $text, $process);
				
        return $process;
	}
      /*
       * Подвеска PHP кода
      */
	public function printCode($code) { 
		$code = strtr($code,array('&#124;'=>'|','&lt;'=>'<','&gt;'=>'>','&amp;'=>'&','&#36;'=>'$','&quot;'=>'"','&#39;'=>"'", '&#92;'=>'`',
		                          '&#37;'=>'%','&#94;'=>'^','&#58;'=>':','<br />'=>"\r\n")); 
								  
    	    if(!strpos($code,'<?') && substr($code,0,2)!='<?') {
        	    $code="<?php\r\n".trim($code).'?>';
    	    }
        	    $code = highlight_string($code, true); 	
        	    $code = strtr($code,array("\r\n"=>'<br />','|'=>'&#124;',   '$'=>'&#36;', "'"=>'&#39;', '`'=>'&#92;', '%'=>'&#37;','^'=>'&#94;',    ':'=>'&#58;')); 
        	    $code = $code; 
        
		return '<div class="SHCMS_code">'.$code.'</div>'; 
	}
      /*
       * Скрывает текст от неавторизованных
      */
	public function hidden_text($hide) {
            global $user_id;
                if(isset($user_id)){
    		        $hide = '<div class="hide"><b>Скрытый текст </b><br/> '.$hide.'</div>';
		        }else {
			        $hide = '<div class="hide"><b>Скрытый текст</b> <br/>Для отображения текста необходимо пройти авторизацию на сайте.</div>';
				}					
        
		return $hide;
	}
      /*
       * Обработка тэгов 
      */
	public function parser_video($parservideo) {
	return '<object><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="movie" value="../download/uppod.swf" /><param name="flashvars" value="st=../download/video127-1094.txt&amp;file='.$parservideo.'" /><embed src="../download/uppod.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" flashvars="st=../download/video127-1094.txt&amp;file='.$parservideo.'" width="500" height="310"> </embed></object>';
	}
	public function parser_audiomp3($parsermp3) {
	return '<object width="500" height="41"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="movie" value="../download/uppod.swf" /><param name="flashvars" value="st=../download/audio127-501.txt&amp;file='.$parsermp3.'" /><embed src="../download/uppod.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" flashvars="st=../download/audio127-501.txt&amp;file='.$parsermp3.'" width="500" height="41"></embed></object>';
	}
    public function bb_codes($message) {
		$message = preg_replace('#\[small\](.*?)\[/small\]#si', '<div style="font-size: smaller;">\1</div>', $message);
		$message = preg_replace(array ('#\[php\](.*?)\[\/php\]#se'), array ("''.bbcode::printCode('$1').''"), str_replace("]\n", "]",   $message));
    	$message=  preg_replace_callback('/\[url=(.+)\](.+)\[\/url\]/isU', 'parser_link', $message); 
		$message=  preg_replace_callback('/\[spoiler=(.+)\](.+)\[\/spoiler\]/isU', 'parser_spoiler', $message); 
    	$message = preg_replace('#\[img\](.*?)\[/img\]#si', '<img src="\1"/>', $message);
		$message = preg_replace( "#\[(left|right|center)\](.+?)\[/\\1\]#is", "<div style=\"text-align:\\1;\">\\2</div>", $message);
    	$message = preg_replace('#\[post\](.*?)\[/post\]#si', '<div class="posts">\1</div>', $message);
		$message = preg_replace('#\[fontred\](.*?)\[/fontred\]#si', '<font color="red">\1</font>', $message);
    	$message = preg_replace('#\[hide\](.*?)\[/hide\]#ie', 'bbcode::hidden_text("\1")', $message);
		$message = preg_replace('#\[audio=([^\]]+)\]#ies', 'bbcode::parser_audiomp3("\\1")', $message);
		$message = preg_replace('#\[video=([^\]]+)\]#ies', 'bbcode::parser_video("\\1")', $message);

		$message = nl2br($message);
		
      return $message;
	}

}
?>