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

Размер файла: 6.4Kb
<?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(\'#'.$spoiler[1].'\');">'.$spoiler[1].'</a></b>
	           <div id="'.$spoiler[1].'" style="display: none; overflow: hidden; vertical-align: top;">'.$spoiler[2].'</div></div>';
	}
abstract class bbcode {
  /*
   * Класс для обработки текста
   * @author: Shamsik
   * @var bbcode   
  */
    public function process($text) {
	        $process = array(' '=>'_');
                if( $type == 'link' ) {
                    $process[' '] = '_';
                }
                $process = strtr( $text, $process);
				
        return $process;
	}
	// Функция обработки Изображения [img][/img]
	public function parser_img($img) {
	    global $new_image;
	        $SHCMS_http = new SHCMS_http($img);
	$image_path = $img;
    list($width, $height, $type, $attr)= getimagesize($image_path); 

        $percent_resizing = 80;

        $new_width = round((($percent_resizing/100)*$width));
        $new_height = round((($percent_resizing/100)*$height));

    return '<a class="SHCMS_modal" title="'.$SHCMS_http->getName().'" href="'.$img.'"><img src="'.$image_path.'" height="'.$new_height.'" width="'.$new_width.'"></a>';
	}
	public function List_Code($txt) { 
			$txt = str_replace( "&", "&amp;", $txt );
			$txt = str_replace( "'", "&#39;", $txt );
			$txt = str_replace( "<", "&lt;", $txt );
			$txt = str_replace( ">", "&gt;", $txt );
			$txt = str_replace( "&quot;", "&#34;", $txt );
			$txt = str_replace( "\\\"", "&#34;", $txt );
			$txt = str_replace( ":", "&#58;", $txt );
			$txt = str_replace( "[", "&#91;", $txt );
			$txt = str_replace( "]", "&#93;", $txt );
			$txt = str_replace( "\r", "__CODENR__", $txt );
			$txt = str_replace( "\n", "__CODENN__", $txt );

		return $txt; 
	}
      /*
       * Подвеска 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-1216.txt&amp;file='.$parservideo.'" /><embed src="../download/uppod.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" flashvars="st=../download/video127-1216.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 user($user) {
	
	$list_mysql = mysql_fetch_array(mysql_query("SELECT `id`,`login` FROM `users` WHERE `login` = '$user'"));
		return '<strong><a title="Просмотр профиля" href="'.DIR_SHCMS.'change_view.php?id='.$list_mysql['id'].'">'.$list_mysql['login'].'</a></strong>';
		}
    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(array ('#\[text\](.*?)\[\/text\]#se'), array ("''.bbcode::List_Code('$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\]#se', 'bbcode::parser_img("$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 = preg_replace('#\[user=([^\]]+)\]#ies', 'bbcode::user("\\1")', $message);
		$message = nl2br($message);
		
      return $message;
	}

}
?>