Цитата
<?php
/*
Copyright © Eleanor CMS
URL: http://eleanor-cms.ru, http://eleanor-cms.com
E-mail: support@eleanor-cms.ru
Developing: Alexander Sunvas*
Interface: Rumin Sergey
=====
*Pseudonym. See addons/copyrights/info.txt for more information.
*/
if(!defined('CMS'))
die('Попытка взлома?');
class OwnBbCode_url extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
$params=$params ? Strings::ParseParams($params,'href') : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
reEdit($tag,$params,$content,true);
}
if(!isset($params['href']) and !isset($params['url']))
$params['href']=trim($content);
static $el=true;
if($el)
{
$this->Mainclass->LoadOptions(array('editor'),false);
$el=false;
}
$new_params=array('target'=>'_blank');
foreach($params as $k=>$v)
switch($k)
{
case 'url':
case 'href':
if(!Strings::XssCheckUrl($v))
return '';
if($this->Mainclass->vars['anti_directlink'] and 0!==strpos($v,ELEANOR_PROTOCOL.$this->Mainclass->domain) and false!==$pos=strpos($v,'://') and $pos<7)
$v='go.php?'.$v;
$new_params['href']=$v;
break;
case 'title':
$new_params['title']=$v;
break;
case 'target':
if($v=='_blank' or $v=='_self')
$new_params['target']=$v;
break;
case 'noparse':
$new_params['noparse']='noparse';
break;
case 'self':
unset($new_params['target']);
break;
}
return parent:
reDisplay('a',$new_params,$content,$canuse);
}
public function PreSave($tag,$params,$content,$canuse)
{
$params=Strings::ParseParams($params,$tag);
$new_params=array();
foreach($params as $k=>$v)
if(in_array($k,array('title','href',$tag,'self','target')))
$new_params[$k]=$v;
return parent:
reEdit($tag,$new_params,$content,$canuse);
}
}
class OwnBbCode_nobb extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
if(strpos($params,'noparse')===false)
return $content;
return '['.$tag.']'.$content.'[/'.$tag.']';
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
$this->Mainclass->LoadClass('classes/others/class_editor.php');
$content=$this->Mainclass->Editor->SafeHtml($content);
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_code extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params,$tag) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
reEdit($tag,$params,$content,true);
}
if(!isset($params[$tag]))
$params[$tag]='no-highlight';
$js='';
static $addedjs=true;
if($addedjs)
{
$js=Strings::AddJs('addons/highlight/highlight.pack.js').
'<script type="text/javascript">//<![CDATA[
AddStyle("addons/highlight/styles/default.css");
hljs.tabReplace=" ";
hljs.initHighlightingOnLoad("php","html","css");
//]]></script>';
$addedjs=false;
}
return '<pre><code'.(isset($params['auto']) ? '' : ' class="'.$params[$tag].'"').'>'.$content.'</code></pre>'.$js;
}
public function PreEdit($tag,$params,$content,$canuse)
{
$params=$params ? Strings::ParseParams($params,$tag) : array();
if(isset($params[$tag]) and $params[$tag]=='no-highlight')
unset($params[$tag]);
if($this->visual)
{
$content=str_replace("t",' ',$content);
$content=str_replace(' ',' ',$content);
$content=nl2br($content);
}
return parent:
reEdit($tag,$params,$content,$canuse);
}
public function PreSave($tag,$params,$content,$canuse)
{
if($this->visual)
$content=strip_tags($content,'<span><b><i><u><em><strong>');
$this->Mainclass->LoadClass('classes/others/class_editor.php');
$content=$this->Mainclass->Editor->SafeHtml($content);
$params=$params ? Strings::ParseParams($params,$tag) : array();
if(!isset($params[$tag]))
$params[$tag]='no-highlight';
return parent:
reEdit($tag,$params,$content,$canuse);
}
}
class OwnBbCode_csel extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
if(strpos($params,'noparse')===false)
return '<span style="color:red;background-color:lightgray">'.$content.'</span>';
return parent:
reEdit($tag,array(),$content,true);
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_quote extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
reEdit($tag,$params,$content,true);
}
return '<div class="quote">'.$content.'</div>';
}
public function PreSave($tag,$params,$content,$canuse)
{
$content=preg_replace("#^(r?n?<br />r?n?)+#i",'<br />',$content);
$content=preg_replace("#(r?n?<br />r?n?)+$#i",'<br />',$content);
return parent:
reSave($tag,$params,$content,$canuse);
}
}
class OwnBbCode_script extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
reEdit($tag,$params,$content,true);
}
if(isset($params['src']))
return '<script type="text/javascript" src="'.$params['src'].'"></script>';
return '<script type="text/javascript">//<![CDATA['."rn".trim($content)."rn//]]></script>";
}
public function PreSave($tag,$params,$content,$canuse)
{
$params=Strings::ParseParams($params,$tag);
$canuse&=!isset($params['noparse']);
$new_params=array();
if(isset($params['src']))
$new_params['src']=$params['src'];
return parent:
reEdit($tag,$new_params,$content,$canuse);
}
}
class OwnBbCode_php extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
if(strpos($params,'noparse')===false)
{
ob_start();
$content=@eval($content);
$content.=ob_get_contents();
ob_end_clean();
return $content;
}
return '['.$tag.']'.$content.'[/'.$tag.']';
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_dohtml extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
return strpos($params,'noparse')===false ? $content : '['.$tag.']'.$content.'[/'.$tag.']';
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_hide extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
return '['.$tag.']'.$content.'[/'.$tag.']';
if($this->Mainclass->Login->IsUser())
return $content;
$this->LoadLang();
return '<div style="font-weight:bold;color:red;text-align:center;border: solid black 1px;">'.$this->lang['hidden'].'</div>';
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_attach extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params,'file') : array();
if(isset($params['noparse']) or !isset($params['file']))
return parent:
reDisplay($tag,$params,$content,$canuse);
$is_our=strpos($params['file'],'://')===false;
if($is_our)
$params['file']=ELEANOR_PROTOCOL.$this->Mainclass->domain.$this->Mainclass->site_path.'/'.$params['file'];
$type=isset($params['type']) ? $params['type'] : substr(strrchr($params['file'],'.'),1);
switch(strtolower($type))
{
case 'flv':
case 'mp4':
$params['width']=isset($params['width']) ? (int)$params['width'] : 520;
$params['height']=isset($params['height']) ? (int)$params['height'] : 330;
$autobuf='false';
case 'mp3':
$params['width']=isset($params['width']) ? (int)$params['width'] : 400;
$params['height']=isset($params['height']) ? (int)$params['height'] : 30;
if(!isset($autobuf))
$autobuf='false';
if(isset($params['autobuf']))
$autobuf='true';
$align=(isset($params['align']) and in_array($params['align'],array('left','center','right'))) ? 'float:'.$params['align'] : '';
self::$jscripts[]='addons/flowplayer/flowplayer-3.1.4.min.js';
$pl=uniqid('player_');
$html='<a href="'.$params['file'].'" style="display:block;width:'.$params['width'].'px;height:'.$params['height'].'px;'.$align.'" id="'.$pl.'"></a>
<script type="text/javascript">//<![CDATA[
flowplayer("'.$pl.'","addons/flowplayer/flowplayer-3.1.5.swf",{
plugins:{
controls: {
tooltips: {
// enable english tooltips on all buttons
buttons: true,
},
// background color for all tooltips
tooltipColor: "#112233",
// text color
tooltipTextColor: "#8899ff"
}
},
// pause on first frame of the video
clip: {
autoPlay: false,
autoBuffering: '.$autobuf.'
}
});
//]]></script>';
break;
case 'swf':
$id=uniqid('swf_');
$params['width']=isset($params['width']) ? (int)$params['width'] : 520;
$params['height']=isset($params['height']) ? (int)$params['height'] : 330;
self::$jscripts[]='js/swfobject.js';
$html='<div id="'.$id.'"></div><script type="text/javascript">//<![CDATA[
swfobject.embedSWF("'.$params['file'].'", "'.$id.'", "'.$params['width'].'", "'.$params['height'].'", "9.0.0");
//]]></script>';
break;
case 'jpeg':
case 'jpg':
case 'png':
case 'bmp':
case 'gif':
$params_img=array('alt'=>' alt=""','style'=>' style="max-width:'.(isset($params['mw']) ? (int)$params['mw'] : 200).'px"');
if(!isset($params['preview']))
$params['preview']=$params['file'];
foreach($params as $k=>$v)
switch(strtolower($k))
{
case 'border':
$v=abs((int)$v);
if($v>5)
$v=5;
$params_img['border']=' border="'.$v.'"';
break;
case 'alt':
$params_img['alt']=' alt="'.$v.'" title="'.$v.'"';
break;
case 'width':
$params_img['width']=' width="'.$v.'"';
break;
case 'style':
$params_img['style']=' style="'.str_ireplace(array('expression','url','@import'),'not_allowed',$v).'"';
break;
case 'height':
$params_img['height']=' height="'.$v.'"';
break;
case 'class':
$params_img['class']=' class="'.$v.'"';
break;
case 'align':
$params_img['align']=' align="'.$v.'"';
break;
}
self::$jscripts[]='js/wz_tooltip.js';
$html='<a href="'.$params['file'].'" target="_blank" onmouseover="var sw=Math.round(screen.width*0.8);Tip('<img src="'.$params['file'].'" style="max-width:'+sw+'px" alt="" />',BGCOLOR,'#fff')" onmouseout="UnTip()"><img src="'.$params['preview'].'"'.join('',$params_img).' /></a>';
break;
case 'mpg':
case 'avi':
$params['height']=isset($params['height']) ? (int)$params['height'] : 420;
case 'mid':
case 'kar':
$params['width']=isset($params['width']) ? (int)$params['width'] : '100%';
$html=Strings::ScriptText('<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaplayer/en/default.asp" src="'.$params['file'].'" width="'.$params['width'].'" height="'.$params['height'].'" autostart="0" showcontrols="true" showstatusbar="true" showdisplay="true" />');
break;
case 'mov':
$params['width']=isset($params['width']) ? (int)$params['width'] : 520;
$params['height']=isset($params['height']) ? (int)$params['height'] : 330;
$html=Strings::ScriptText('<embed type="application/x-mplayer2" pluginspage="http://www.apple.com/quicktime/download/indext.html" src="'.$params['file'].'" width="'.$params['width'].'" height="'.$params['height'].'" autostart="0" showcontrols="true" showstatusbar="true" showdisplay="true" />');
break;
default:
$html='<a href="'.$params['file'].'" target="_blank">'.$params['file'].'</a>';
}
return $html;
}
}
class OwnBbCode_video extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
reEdit($tag,$params,$content,true);
}
$content=trim($content);
#YouTube
if(preg_match('%watch(?:?|#)v=([a-z0-9-_]+)%i',$content,$m)>0)
{
$w=isset($params['width']) ? (int)$params['width'] : 425;
$h=isset($params['height']) ? (int)$params['height'] : 344;
$video='<object width="'.$w.'" height="'.$h.'"><param name="movie" value="http://www.youtube.com/v/'.$m[1].'&hl=ru_RU&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$m[1].'&hl=ru_RU&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'.$w.'" height="'.$h.'"></embed></object>';
}
#RuTube
elseif(preg_match('#v=([a-f0-9]{32})#i',$content,$m)>0)
{
$w=isset($params['width']) ? (int)$params['width'] : 470;
$h=isset($params['height']) ? (int)$params['height'] : 353;
$video='<object width="470" height="353"><param name="movie" value="http://video.rutube.ru/'.$m[1].'"></param><param name="wmode" value="window"></param><param name="allowfullscreen" value="true"></param><embed src="http://video.rutube.ru/'.$m[1].'" type="application/x-shockwave-flash" wmode="window" width="'.$w.'" height="'.$h.'" allowfullscreen="true" ></embed></object>';
}
#Smotri.com
elseif(preg_match('#?id=([a-z0-9]+)#i',$content,$m)>0)
{
$w=isset($params['width']) ? (int)$params['width'] : 400;
$h=isset($params['height']) ? (int)$params['height'] : 330;
$video='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'.$w.'" height="'.$h.'"><param name="movie" value="http://pics.smotri.com/scrubber_custom8.swf?file='.$m[1].'&bufferTime=3&autoStart=false&str_lang=rus&xmlsource=http%3A%2F%2Fpics.smotri.com%2Fcskins%2Fblue%2Fskin_color_lightaqua.xml&xmldatasource=http%3A%2F%2Fpics.smotri.com%2Fskin_ng.xml" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="bgcolor" value="#ffffff" /><embed src="http://pics.smotri.com/scrubber_custom8.swf?file='.$m[1].'&bufferTime=3&autoStart=false&str_lang=rus&xmlsource=http%3A%2F%2Fpics.smotri.com%2Fcskins%2Fblue%2Fskin_color_lightaqua.xml&xmldatasource=http%3A%2F%2Fpics.smotri.com%2Fskin_ng.xml" quality="high" allowscriptaccess="always" allowfullscreen="true" wmode="window" width="'.$w.'" height="'.$h.'" type="application/x-shockwave-flash"></embed></object>';
}
#Big)mir
elseif(preg_match('#show/([0-9]+)/#i',$content,$m)>0)
{
$w=isset($params['width']) ? (int)$params['width'] : 625;
$h=isset($params['height']) ? (int)$params['height'] : 395;
$video='<object width="'.$w.'" height="'.$h.'"><param name="movie" value="http://video.bigmir.net/extplayer/'.$m[1].'/"></param><param name="wmode" value="transparent"></param><param name="flashvars" value=""></param><embed src="http://video.bigmir.net/extplayer/'.$m[1].'/" type="application/x-shockwave-flash" wmode="transparent" width="'.$w.'" height="'.$h.'" flashvars=""></embed></object>';
}
elseif(Strings::XssCheckUrl($content))
{
$href=$content;
if($this->Mainclass->vars['anti_directlink'] and 0!==strpos($v,ELEANOR_PROTOCOL.$this->Mainclass->domain) and false!==$pos=strpos($v,'://') and $pos<7)
$href='go.php?'.$href;
return '<a href="'.$href.'">'.$content.'</a>';
}
else
return '';
return $video;
}
}
class OwnBbCodes extends BaseClass
{
const
DISPLAY=1,
SHOW=2,#Это когда мы результат обработки должны сразу показать на экран. Отличие от DISPLAY состсавляет в том, что мы используем разрешение не gr_see, а gr_use!
EDIT=3,
SAVE=4;
public
$bbcodes=array(),
$visual=false;#Флаг определяющий, редактор визуальный или нет
protected
$notparsed,
$plugins=array();
public function __construct($Mainclass)
{
$this->bbcodes=$Mainclass->Cache->Get('ownbbcodes',true);
if($this->bbcodes===false)
$this->bbcodes=$this->RecacheBB();
}
/*
Функция парсит свои ББ коды.
$text - текст с ББ кодами.
$type - тип (см. выше константы)
$codes - только эти ББ коды нужно парсить. Задаются через запятую. Неверный формат недопустим! Например b,i,u
*/
public function ParseAll($text,$type=self::DISPLAY,$codes=array())
{
BaseOwnBbCode::$jscripts=array();
$text=$this->StoreNotParsed($text,$type);
$text=$this->ParseBbCodes($text,$type,$codes);
$text=$this->ParseNotParsed($text,$type);
BaseOwnBbCode::$jscripts=array_unique(BaseOwnBbCode::$jscripts);
return $text;
}
public function ParseBbCodes($text,$type,$codes=array())
{
switch($type)
{
case self::EDIT:
$method='PreEdit';
break;
case self::SAVE:
$method='PreSave';
break;
default:
$method='PreDisplay';
}
if(!is_array($codes))
$codes=$codes ? explode(',',$codes) : array();
$groups=$this->Mainclass->Account->GetUserGroups();
foreach($this->bbcodes as &$bbcode)
{
$canuse=true;
if($type==self::DISPLAY and $grs=$bbcode['gr_see'] or $type==self::SHOW and $grs=$bbcode['gr_use'] or $type>self::SHOW and $grs=$bbcode['gr_use'])
{
$grs=explode(',',$grs);
$canuse=count(array_intersect($grs,$groups))>0;
}
if($type==self::SHOW and !$canuse)
continue;
$tags=array($bbcode['tag']);
if($bbcode['aliases'])
$tags=array_merge($tags,explode(',',$bbcode['aliases']));
if($codes and count(array_intersect($codes,$tags))==0 or !$codes and $bbcode['special'])
continue;
foreach($tags as &$tag)
{
$oldcurpos=-1;
$curpos=0;
while(false!==$curpos=strpos($text,'['.$tag,$curpos))
{
if($curpos==$oldcurpos)
{
++$curpos;
continue;
}
$taglen=strlen($tag);
$next_let=substr($text,$curpos+$taglen+1,1);
#Если мы нашли нужный нам тег т.е. i != img (отшибем все следующие знаки после найденного тега - )
if(trim($next_let,'=] ')!='')
{
++$curpos;
continue;
}
$length=strpos($text,']',$curpos);
if($length===false)
{
++$curpos;
continue;
}
$params=trim(substr($text,$curpos+$taglen+1,$length-$curpos-$taglen-1));
if($bbcode['single'])
{
$length-=$curpos-1;#]
$content='';
}
else
{
$begin_content=$length+1;
$length=stripos($text,'[/'.$tag.']',$begin_content);
if($length===false)
{
++$curpos;
continue;
}
$content=substr($text,$begin_content,$length-$begin_content);
$length-=$curpos-$taglen-3;#[/]
}
$class_name='OwnBbCode_'.$bbcode['tag'];
if(!isset($this->plugins[$bbcode['tag']]))
{
if(!class_exists($class_name,false))
{
if(!$bbcode['file'])
{
++$curpos;
continue;
}
$file=$this->Mainclass->FormatPath($bbcode['file']);
if(!is_file($file))
{
++$curpos;
continue;
}
include $file;
}
$this->plugins[$bbcode['tag']]=new $class_name($this->Mainclass);
$this->plugins[$bbcode['tag']]->visual=$this->visual;
}
if(method_exists($this->plugins[$bbcode['tag']],'Total'.$method))
{
$m='Total'.$method;
$text=$this->plugins[$bbcode['tag']]->$m($text,$tags,$canuse,$params,$content,$curpos,$length,$bbcode['single']);
continue 3;
}
$replace=$this->plugins[$bbcode['tag']]->$method($bbcode['tag'],$params,$content,$canuse,$bbcode['single']);
$text=substr_replace($text,$replace,$curpos,$length);
$oldcurpos=$curpos;
}
}
}
return $text;
}
public function StoreNotParsed($text,$type)
{
$text=str_replace('<!-- ','<!-- ',$text);
$n=0;
$this->notparsed=array();
$groups=$this->Mainclass->Account->GetUserGroups();
foreach($this->bbcodes as &$bbcode)
{
if(!$bbcode['no_parse'])
continue;
if($type==self::DISPLAY and $grs=$bbcode['gr_see'] or $type==self::SHOW and $grs=$bbcode['gr_use'] or $type>self::SHOW and $grs=$bbcode['gr_use'])
{
$grs=explode(',',$grs);
if(count(array_intersect($grs,$groups))==0)
continue;
}
if($grs=$bbcode['gr_use'])
{
$grs=explode(',',$grs);
if(count(array_intersect($grs,$groups))==0)
continue;
}
$tags=array($bbcode['tag']);
if($bbcode['aliases'])
$tags=array_merge($tags,explode(',',$bbcode['aliases']));
foreach($tags as &$tag)
{
$oldcurpos=-1;
$curpos=0;
while(false!==$curpos=stripos($text,'['.$tag,$curpos))
{
if($curpos==$oldcurpos)
{
++$curpos;
continue;
}
$taglen=strlen($tag);
$next_let=substr($text,$curpos+$taglen+1,1);
#Если мы нашли нужный нам тег т.е. i != img (отшибем все следующие знаки после найденного тега - )
if(trim($next_let,'=] ')!='')
{
++$curpos;
continue;
}
if($bbcode['single'])
{
$length=strpos($text,']',$curpos);
if($length===false)
{
++$curpos;
continue;
}
$length-=$curpos-1;#]
}
else
{
if(false!==$nop=strpos($text,'noparse]',$curpos) and $nop<strpos($text,']',$curpos))
{
++$curpos;
continue;
}
$length=strpos($text,'[/'.$tag.']',$curpos);
if($length===false)
{
++$curpos;
continue;
}
$length-=$curpos-$taglen-3;#[/]
}
$replace='<!-- '.$n++.' -->';
$content=substr($text,$curpos,$length);
$text=substr_replace($text,$replace,$curpos,$length);
$this->notparsed[]=array(
'find'=>$replace,
'text'=>$content,
'code'=>$bbcode['sp_tags'] ? $tag.','.$bbcode['sp_tags'] : $tag,
);
$oldcurpos=$curpos;
}
}
}
return $text;
}
/*
Если $type===false - ничего не парсим.
*/
public function ParseNotParsed($text,$type)
{
if($this->notparsed)
{
if($type)
foreach($this->notparsed as &$v)
$text=str_replace($v['find'],$this->ParseBBCodes($v['text'],$type,$v['code']),$text);
else
foreach($this->notparsed as &$v)
$text=str_replace($v['find'],$v['text'],$text);
}
$this->notparsed=array();
return $text;
}
protected function RecacheBB()
{
$bbcodes=array();
$this->Mainclass->Db->Query('SELECT `tag`,`aliases`,`single`,`no_parse`,`special`,`file`,`sp_tags`,`gr_use`,`gr_see`,`options`,`sb` FROM `f_own_bbcodes` WHERE `active`=1 ORDER BY `pos` ASC',__file__,__line__);
while($arr=$this->Mainclass->Db->Fetch_assoc())
$bbcodes[]=$arr;
$this->Mainclass->Cache->Put('ownbbcodes',$bbcodes,0,true);
return $bbcodes;
}
}
class BaseOwnBbCode extends BaseClass
{
public
$visual=false;
static
$jscripts=array();
protected
$lang;
protected function LoadLang()
{
if(!$this->lang)
$this->lang=$this->Mainclass->LoadLanguage('langs','','ownbbcodes-%');
}
public function RestrictDisplay()
{
$this->LoadLang();
return isset($this->restrict_text) ? $this->restrict_text : '<div style="font-weight:bold;color:red;text-align:center;border: solid black 1px;">'.$this->lang['restrict'].'</div>';
}
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
if(!is_array($params))
$params=Strings::ParseParams($params,$tag);
if(isset($params['noparse']))
{
unset($params['noparse']);
$putparams=isset($params[$tag]) ? '' : ' ';
foreach($params as $k=>$v)
if($k==$tag)
$putparams='='.$v.' '.$putparams;
else
{
if(strpos($v,' ')===false)
$sep='';
elseif(strpos($v,''')===false)
$sep='"';
else
$sep=''';
$putparams.=$k.'='.$sep.$v.$sep.' ';
}
return '['.$tag.rtrim($putparams).']'.$content.'[/'.$tag.']';
}
unset($params['noparse'],$params[$tag]);
$putparams=' ';
foreach($params as $k=>$v)
{
$sep=strpos($v,''')===false ? '"' : ''';
$putparams.=$k.'='.$sep.$v.$sep.' ';
}
return '<'.$tag.rtrim($putparams).'>'.$content.'</'.$tag.'>';
}
public function PreEdit($tag,$params,$content,$canuse,$single=false)
{
if(!is_array($params))
$params=Strings::ParseParams($params,$tag);
$putparams=isset($params[$tag]) ? '' : ' ';
if(!$canuse or isset($params['noparse']))
{
unset($params['noparse']);
$canuse=false;
}
foreach($params as $k=>$v)
if($k==$tag)
$putparams='='.$v.' '.$putparams;
elseif($v==$k)
$putparams.=$k.' ';
else
{
if(strpos($v,' ')===false)
$sep='';
elseif(strpos($v,''')===false)
$sep='"';
else
$sep=''';
$putparams.=$k.'='.$sep.$v.$sep.' ';
}
return '['.$tag.rtrim($putparams).($canuse ? '' : ' noparse').']'.$content.($single ? '' : '[/'.$tag.']');
}
public function PreSave($tag,$params,$content,$canuse,$single=false)
{
return $this->PreEdit($tag,$params,$content,$canuse,$single);
}
/*
Функции, которым для обработки необходимо передать весь массив текста
public function TotalPreSave($text,$tags,$canuse,$params,$content,$curpos,$length,$single){retur
n $text;}
public function TotalPreEdit($text,$tags,$canuse,$params,$content,$curpos,$length,$single){retur
n $text;}
public function TotalPreDisplay($text,$tags,$canuse,$params,$content,$curpos,$length,$single){re
turn $text;}
*/
}
?>
/*
Copyright © Eleanor CMS
URL: http://eleanor-cms.ru, http://eleanor-cms.com
E-mail: support@eleanor-cms.ru
Developing: Alexander Sunvas*
Interface: Rumin Sergey
=====
*Pseudonym. See addons/copyrights/info.txt for more information.
*/
if(!defined('CMS'))
die('Попытка взлома?');
class OwnBbCode_url extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
$params=$params ? Strings::ParseParams($params,'href') : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
if(!isset($params['href']) and !isset($params['url']))
$params['href']=trim($content);
static $el=true;
if($el)
{
$this->Mainclass->LoadOptions(array('editor'),false);
$el=false;
}
$new_params=array('target'=>'_blank');
foreach($params as $k=>$v)
switch($k)
{
case 'url':
case 'href':
if(!Strings::XssCheckUrl($v))
return '';
if($this->Mainclass->vars['anti_directlink'] and 0!==strpos($v,ELEANOR_PROTOCOL.$this->Mainclass->domain) and false!==$pos=strpos($v,'://') and $pos<7)
$v='go.php?'.$v;
$new_params['href']=$v;
break;
case 'title':
$new_params['title']=$v;
break;
case 'target':
if($v=='_blank' or $v=='_self')
$new_params['target']=$v;
break;
case 'noparse':
$new_params['noparse']='noparse';
break;
case 'self':
unset($new_params['target']);
break;
}
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
public function PreSave($tag,$params,$content,$canuse)
{
$params=Strings::ParseParams($params,$tag);
$new_params=array();
foreach($params as $k=>$v)
if(in_array($k,array('title','href',$tag,'self','target')))
$new_params[$k]=$v;
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
}
class OwnBbCode_nobb extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
if(strpos($params,'noparse')===false)
return $content;
return '['.$tag.']'.$content.'[/'.$tag.']';
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
$this->Mainclass->LoadClass('classes/others/class_editor.php');
$content=$this->Mainclass->Editor->SafeHtml($content);
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_code extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params,$tag) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
if(!isset($params[$tag]))
$params[$tag]='no-highlight';
$js='';
static $addedjs=true;
if($addedjs)
{
$js=Strings::AddJs('addons/highlight/highlight.pack.js').
'<script type="text/javascript">//<![CDATA[
AddStyle("addons/highlight/styles/default.css");
hljs.tabReplace=" ";
hljs.initHighlightingOnLoad("php","html","css");
//]]></script>';
$addedjs=false;
}
return '<pre><code'.(isset($params['auto']) ? '' : ' class="'.$params[$tag].'"').'>'.$content.'</code></pre>'.$js;
}
public function PreEdit($tag,$params,$content,$canuse)
{
$params=$params ? Strings::ParseParams($params,$tag) : array();
if(isset($params[$tag]) and $params[$tag]=='no-highlight')
unset($params[$tag]);
if($this->visual)
{
$content=str_replace("t",' ',$content);
$content=str_replace(' ',' ',$content);
$content=nl2br($content);
}
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
public function PreSave($tag,$params,$content,$canuse)
{
if($this->visual)
$content=strip_tags($content,'<span><b><i><u><em><strong>');
$this->Mainclass->LoadClass('classes/others/class_editor.php');
$content=$this->Mainclass->Editor->SafeHtml($content);
$params=$params ? Strings::ParseParams($params,$tag) : array();
if(!isset($params[$tag]))
$params[$tag]='no-highlight';
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
}
class OwnBbCode_csel extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
if(strpos($params,'noparse')===false)
return '<span style="color:red;background-color:lightgray">'.$content.'</span>';
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_quote extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
return '<div class="quote">'.$content.'</div>';
}
public function PreSave($tag,$params,$content,$canuse)
{
$content=preg_replace("#^(r?n?<br />r?n?)+#i",'<br />',$content);
$content=preg_replace("#(r?n?<br />r?n?)+$#i",'<br />',$content);
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
}
class OwnBbCode_script extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
if(isset($params['src']))
return '<script type="text/javascript" src="'.$params['src'].'"></script>';
return '<script type="text/javascript">//<![CDATA['."rn".trim($content)."rn//]]></script>";
}
public function PreSave($tag,$params,$content,$canuse)
{
$params=Strings::ParseParams($params,$tag);
$canuse&=!isset($params['noparse']);
$new_params=array();
if(isset($params['src']))
$new_params['src']=$params['src'];
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
}
class OwnBbCode_php extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
if(strpos($params,'noparse')===false)
{
ob_start();
$content=@eval($content);
$content.=ob_get_contents();
ob_end_clean();
return $content;
}
return '['.$tag.']'.$content.'[/'.$tag.']';
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_dohtml extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
return strpos($params,'noparse')===false ? $content : '['.$tag.']'.$content.'[/'.$tag.']';
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_hide extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
return '['.$tag.']'.$content.'[/'.$tag.']';
if($this->Mainclass->Login->IsUser())
return $content;
$this->LoadLang();
return '<div style="font-weight:bold;color:red;text-align:center;border: solid black 1px;">'.$this->lang['hidden'].'</div>';
}
public function PreSave($tag,$params,$content,$canuse)
{
$canuse&=strpos($params,'noparse')===false;
return '['.$tag.($canuse ? '' : ' noparse').']'.$content.'[/'.$tag.']';
}
}
class OwnBbCode_attach extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params,'file') : array();
if(isset($params['noparse']) or !isset($params['file']))
return parent:
![:P :P](style_emoticons/default/tongue.gif)
$is_our=strpos($params['file'],'://')===false;
if($is_our)
$params['file']=ELEANOR_PROTOCOL.$this->Mainclass->domain.$this->Mainclass->site_path.'/'.$params['file'];
$type=isset($params['type']) ? $params['type'] : substr(strrchr($params['file'],'.'),1);
switch(strtolower($type))
{
case 'flv':
case 'mp4':
$params['width']=isset($params['width']) ? (int)$params['width'] : 520;
$params['height']=isset($params['height']) ? (int)$params['height'] : 330;
$autobuf='false';
case 'mp3':
$params['width']=isset($params['width']) ? (int)$params['width'] : 400;
$params['height']=isset($params['height']) ? (int)$params['height'] : 30;
if(!isset($autobuf))
$autobuf='false';
if(isset($params['autobuf']))
$autobuf='true';
$align=(isset($params['align']) and in_array($params['align'],array('left','center','right'))) ? 'float:'.$params['align'] : '';
self::$jscripts[]='addons/flowplayer/flowplayer-3.1.4.min.js';
$pl=uniqid('player_');
$html='<a href="'.$params['file'].'" style="display:block;width:'.$params['width'].'px;height:'.$params['height'].'px;'.$align.'" id="'.$pl.'"></a>
<script type="text/javascript">//<![CDATA[
flowplayer("'.$pl.'","addons/flowplayer/flowplayer-3.1.5.swf",{
plugins:{
controls: {
tooltips: {
// enable english tooltips on all buttons
buttons: true,
},
// background color for all tooltips
tooltipColor: "#112233",
// text color
tooltipTextColor: "#8899ff"
}
},
// pause on first frame of the video
clip: {
autoPlay: false,
autoBuffering: '.$autobuf.'
}
});
//]]></script>';
break;
case 'swf':
$id=uniqid('swf_');
$params['width']=isset($params['width']) ? (int)$params['width'] : 520;
$params['height']=isset($params['height']) ? (int)$params['height'] : 330;
self::$jscripts[]='js/swfobject.js';
$html='<div id="'.$id.'"></div><script type="text/javascript">//<![CDATA[
swfobject.embedSWF("'.$params['file'].'", "'.$id.'", "'.$params['width'].'", "'.$params['height'].'", "9.0.0");
//]]></script>';
break;
case 'jpeg':
case 'jpg':
case 'png':
case 'bmp':
case 'gif':
$params_img=array('alt'=>' alt=""','style'=>' style="max-width:'.(isset($params['mw']) ? (int)$params['mw'] : 200).'px"');
if(!isset($params['preview']))
$params['preview']=$params['file'];
foreach($params as $k=>$v)
switch(strtolower($k))
{
case 'border':
$v=abs((int)$v);
if($v>5)
$v=5;
$params_img['border']=' border="'.$v.'"';
break;
case 'alt':
$params_img['alt']=' alt="'.$v.'" title="'.$v.'"';
break;
case 'width':
$params_img['width']=' width="'.$v.'"';
break;
case 'style':
$params_img['style']=' style="'.str_ireplace(array('expression','url','@import'),'not_allowed',$v).'"';
break;
case 'height':
$params_img['height']=' height="'.$v.'"';
break;
case 'class':
$params_img['class']=' class="'.$v.'"';
break;
case 'align':
$params_img['align']=' align="'.$v.'"';
break;
}
self::$jscripts[]='js/wz_tooltip.js';
$html='<a href="'.$params['file'].'" target="_blank" onmouseover="var sw=Math.round(screen.width*0.8);Tip('<img src="'.$params['file'].'" style="max-width:'+sw+'px" alt="" />',BGCOLOR,'#fff')" onmouseout="UnTip()"><img src="'.$params['preview'].'"'.join('',$params_img).' /></a>';
break;
case 'mpg':
case 'avi':
$params['height']=isset($params['height']) ? (int)$params['height'] : 420;
case 'mid':
case 'kar':
$params['width']=isset($params['width']) ? (int)$params['width'] : '100%';
$html=Strings::ScriptText('<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaplayer/en/default.asp" src="'.$params['file'].'" width="'.$params['width'].'" height="'.$params['height'].'" autostart="0" showcontrols="true" showstatusbar="true" showdisplay="true" />');
break;
case 'mov':
$params['width']=isset($params['width']) ? (int)$params['width'] : 520;
$params['height']=isset($params['height']) ? (int)$params['height'] : 330;
$html=Strings::ScriptText('<embed type="application/x-mplayer2" pluginspage="http://www.apple.com/quicktime/download/indext.html" src="'.$params['file'].'" width="'.$params['width'].'" height="'.$params['height'].'" autostart="0" showcontrols="true" showstatusbar="true" showdisplay="true" />');
break;
default:
$html='<a href="'.$params['file'].'" target="_blank">'.$params['file'].'</a>';
}
return $html;
}
}
class OwnBbCode_video extends BaseOwnBbCode
{
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
$params=$params ? Strings::ParseParams($params) : array();
if(isset($params['noparse']))
{
unset($params['noparse']);
return parent:
![:P :P](style_emoticons/default/tongue.gif)
}
$content=trim($content);
#YouTube
if(preg_match('%watch(?:?|#)v=([a-z0-9-_]+)%i',$content,$m)>0)
{
$w=isset($params['width']) ? (int)$params['width'] : 425;
$h=isset($params['height']) ? (int)$params['height'] : 344;
$video='<object width="'.$w.'" height="'.$h.'"><param name="movie" value="http://www.youtube.com/v/'.$m[1].'&hl=ru_RU&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$m[1].'&hl=ru_RU&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'.$w.'" height="'.$h.'"></embed></object>';
}
#RuTube
elseif(preg_match('#v=([a-f0-9]{32})#i',$content,$m)>0)
{
$w=isset($params['width']) ? (int)$params['width'] : 470;
$h=isset($params['height']) ? (int)$params['height'] : 353;
$video='<object width="470" height="353"><param name="movie" value="http://video.rutube.ru/'.$m[1].'"></param><param name="wmode" value="window"></param><param name="allowfullscreen" value="true"></param><embed src="http://video.rutube.ru/'.$m[1].'" type="application/x-shockwave-flash" wmode="window" width="'.$w.'" height="'.$h.'" allowfullscreen="true" ></embed></object>';
}
#Smotri.com
elseif(preg_match('#?id=([a-z0-9]+)#i',$content,$m)>0)
{
$w=isset($params['width']) ? (int)$params['width'] : 400;
$h=isset($params['height']) ? (int)$params['height'] : 330;
$video='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'.$w.'" height="'.$h.'"><param name="movie" value="http://pics.smotri.com/scrubber_custom8.swf?file='.$m[1].'&bufferTime=3&autoStart=false&str_lang=rus&xmlsource=http%3A%2F%2Fpics.smotri.com%2Fcskins%2Fblue%2Fskin_color_lightaqua.xml&xmldatasource=http%3A%2F%2Fpics.smotri.com%2Fskin_ng.xml" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="bgcolor" value="#ffffff" /><embed src="http://pics.smotri.com/scrubber_custom8.swf?file='.$m[1].'&bufferTime=3&autoStart=false&str_lang=rus&xmlsource=http%3A%2F%2Fpics.smotri.com%2Fcskins%2Fblue%2Fskin_color_lightaqua.xml&xmldatasource=http%3A%2F%2Fpics.smotri.com%2Fskin_ng.xml" quality="high" allowscriptaccess="always" allowfullscreen="true" wmode="window" width="'.$w.'" height="'.$h.'" type="application/x-shockwave-flash"></embed></object>';
}
#Big)mir
elseif(preg_match('#show/([0-9]+)/#i',$content,$m)>0)
{
$w=isset($params['width']) ? (int)$params['width'] : 625;
$h=isset($params['height']) ? (int)$params['height'] : 395;
$video='<object width="'.$w.'" height="'.$h.'"><param name="movie" value="http://video.bigmir.net/extplayer/'.$m[1].'/"></param><param name="wmode" value="transparent"></param><param name="flashvars" value=""></param><embed src="http://video.bigmir.net/extplayer/'.$m[1].'/" type="application/x-shockwave-flash" wmode="transparent" width="'.$w.'" height="'.$h.'" flashvars=""></embed></object>';
}
elseif(Strings::XssCheckUrl($content))
{
$href=$content;
if($this->Mainclass->vars['anti_directlink'] and 0!==strpos($v,ELEANOR_PROTOCOL.$this->Mainclass->domain) and false!==$pos=strpos($v,'://') and $pos<7)
$href='go.php?'.$href;
return '<a href="'.$href.'">'.$content.'</a>';
}
else
return '';
return $video;
}
}
class OwnBbCodes extends BaseClass
{
const
DISPLAY=1,
SHOW=2,#Это когда мы результат обработки должны сразу показать на экран. Отличие от DISPLAY состсавляет в том, что мы используем разрешение не gr_see, а gr_use!
EDIT=3,
SAVE=4;
public
$bbcodes=array(),
$visual=false;#Флаг определяющий, редактор визуальный или нет
protected
$notparsed,
$plugins=array();
public function __construct($Mainclass)
{
$this->bbcodes=$Mainclass->Cache->Get('ownbbcodes',true);
if($this->bbcodes===false)
$this->bbcodes=$this->RecacheBB();
}
/*
Функция парсит свои ББ коды.
$text - текст с ББ кодами.
$type - тип (см. выше константы)
$codes - только эти ББ коды нужно парсить. Задаются через запятую. Неверный формат недопустим! Например b,i,u
*/
public function ParseAll($text,$type=self::DISPLAY,$codes=array())
{
BaseOwnBbCode::$jscripts=array();
$text=$this->StoreNotParsed($text,$type);
$text=$this->ParseBbCodes($text,$type,$codes);
$text=$this->ParseNotParsed($text,$type);
BaseOwnBbCode::$jscripts=array_unique(BaseOwnBbCode::$jscripts);
return $text;
}
public function ParseBbCodes($text,$type,$codes=array())
{
switch($type)
{
case self::EDIT:
$method='PreEdit';
break;
case self::SAVE:
$method='PreSave';
break;
default:
$method='PreDisplay';
}
if(!is_array($codes))
$codes=$codes ? explode(',',$codes) : array();
$groups=$this->Mainclass->Account->GetUserGroups();
foreach($this->bbcodes as &$bbcode)
{
$canuse=true;
if($type==self::DISPLAY and $grs=$bbcode['gr_see'] or $type==self::SHOW and $grs=$bbcode['gr_use'] or $type>self::SHOW and $grs=$bbcode['gr_use'])
{
$grs=explode(',',$grs);
$canuse=count(array_intersect($grs,$groups))>0;
}
if($type==self::SHOW and !$canuse)
continue;
$tags=array($bbcode['tag']);
if($bbcode['aliases'])
$tags=array_merge($tags,explode(',',$bbcode['aliases']));
if($codes and count(array_intersect($codes,$tags))==0 or !$codes and $bbcode['special'])
continue;
foreach($tags as &$tag)
{
$oldcurpos=-1;
$curpos=0;
while(false!==$curpos=strpos($text,'['.$tag,$curpos))
{
if($curpos==$oldcurpos)
{
++$curpos;
continue;
}
$taglen=strlen($tag);
$next_let=substr($text,$curpos+$taglen+1,1);
#Если мы нашли нужный нам тег т.е. i != img (отшибем все следующие знаки после найденного тега - )
if(trim($next_let,'=] ')!='')
{
++$curpos;
continue;
}
$length=strpos($text,']',$curpos);
if($length===false)
{
++$curpos;
continue;
}
$params=trim(substr($text,$curpos+$taglen+1,$length-$curpos-$taglen-1));
if($bbcode['single'])
{
$length-=$curpos-1;#]
$content='';
}
else
{
$begin_content=$length+1;
$length=stripos($text,'[/'.$tag.']',$begin_content);
if($length===false)
{
++$curpos;
continue;
}
$content=substr($text,$begin_content,$length-$begin_content);
$length-=$curpos-$taglen-3;#[/]
}
$class_name='OwnBbCode_'.$bbcode['tag'];
if(!isset($this->plugins[$bbcode['tag']]))
{
if(!class_exists($class_name,false))
{
if(!$bbcode['file'])
{
++$curpos;
continue;
}
$file=$this->Mainclass->FormatPath($bbcode['file']);
if(!is_file($file))
{
++$curpos;
continue;
}
include $file;
}
$this->plugins[$bbcode['tag']]=new $class_name($this->Mainclass);
$this->plugins[$bbcode['tag']]->visual=$this->visual;
}
if(method_exists($this->plugins[$bbcode['tag']],'Total'.$method))
{
$m='Total'.$method;
$text=$this->plugins[$bbcode['tag']]->$m($text,$tags,$canuse,$params,$content,$curpos,$length,$bbcode['single']);
continue 3;
}
$replace=$this->plugins[$bbcode['tag']]->$method($bbcode['tag'],$params,$content,$canuse,$bbcode['single']);
$text=substr_replace($text,$replace,$curpos,$length);
$oldcurpos=$curpos;
}
}
}
return $text;
}
public function StoreNotParsed($text,$type)
{
$text=str_replace('<!-- ','<!-- ',$text);
$n=0;
$this->notparsed=array();
$groups=$this->Mainclass->Account->GetUserGroups();
foreach($this->bbcodes as &$bbcode)
{
if(!$bbcode['no_parse'])
continue;
if($type==self::DISPLAY and $grs=$bbcode['gr_see'] or $type==self::SHOW and $grs=$bbcode['gr_use'] or $type>self::SHOW and $grs=$bbcode['gr_use'])
{
$grs=explode(',',$grs);
if(count(array_intersect($grs,$groups))==0)
continue;
}
if($grs=$bbcode['gr_use'])
{
$grs=explode(',',$grs);
if(count(array_intersect($grs,$groups))==0)
continue;
}
$tags=array($bbcode['tag']);
if($bbcode['aliases'])
$tags=array_merge($tags,explode(',',$bbcode['aliases']));
foreach($tags as &$tag)
{
$oldcurpos=-1;
$curpos=0;
while(false!==$curpos=stripos($text,'['.$tag,$curpos))
{
if($curpos==$oldcurpos)
{
++$curpos;
continue;
}
$taglen=strlen($tag);
$next_let=substr($text,$curpos+$taglen+1,1);
#Если мы нашли нужный нам тег т.е. i != img (отшибем все следующие знаки после найденного тега - )
if(trim($next_let,'=] ')!='')
{
++$curpos;
continue;
}
if($bbcode['single'])
{
$length=strpos($text,']',$curpos);
if($length===false)
{
++$curpos;
continue;
}
$length-=$curpos-1;#]
}
else
{
if(false!==$nop=strpos($text,'noparse]',$curpos) and $nop<strpos($text,']',$curpos))
{
++$curpos;
continue;
}
$length=strpos($text,'[/'.$tag.']',$curpos);
if($length===false)
{
++$curpos;
continue;
}
$length-=$curpos-$taglen-3;#[/]
}
$replace='<!-- '.$n++.' -->';
$content=substr($text,$curpos,$length);
$text=substr_replace($text,$replace,$curpos,$length);
$this->notparsed[]=array(
'find'=>$replace,
'text'=>$content,
'code'=>$bbcode['sp_tags'] ? $tag.','.$bbcode['sp_tags'] : $tag,
);
$oldcurpos=$curpos;
}
}
}
return $text;
}
/*
Если $type===false - ничего не парсим.
*/
public function ParseNotParsed($text,$type)
{
if($this->notparsed)
{
if($type)
foreach($this->notparsed as &$v)
$text=str_replace($v['find'],$this->ParseBBCodes($v['text'],$type,$v['code']),$text);
else
foreach($this->notparsed as &$v)
$text=str_replace($v['find'],$v['text'],$text);
}
$this->notparsed=array();
return $text;
}
protected function RecacheBB()
{
$bbcodes=array();
$this->Mainclass->Db->Query('SELECT `tag`,`aliases`,`single`,`no_parse`,`special`,`file`,`sp_tags`,`gr_use`,`gr_see`,`options`,`sb` FROM `f_own_bbcodes` WHERE `active`=1 ORDER BY `pos` ASC',__file__,__line__);
while($arr=$this->Mainclass->Db->Fetch_assoc())
$bbcodes[]=$arr;
$this->Mainclass->Cache->Put('ownbbcodes',$bbcodes,0,true);
return $bbcodes;
}
}
class BaseOwnBbCode extends BaseClass
{
public
$visual=false;
static
$jscripts=array();
protected
$lang;
protected function LoadLang()
{
if(!$this->lang)
$this->lang=$this->Mainclass->LoadLanguage('langs','','ownbbcodes-%');
}
public function RestrictDisplay()
{
$this->LoadLang();
return isset($this->restrict_text) ? $this->restrict_text : '<div style="font-weight:bold;color:red;text-align:center;border: solid black 1px;">'.$this->lang['restrict'].'</div>';
}
public function PreDisplay($tag,$params,$content,$canuse)
{
if(!$canuse)
return $this->RestrictDisplay();
if(!is_array($params))
$params=Strings::ParseParams($params,$tag);
if(isset($params['noparse']))
{
unset($params['noparse']);
$putparams=isset($params[$tag]) ? '' : ' ';
foreach($params as $k=>$v)
if($k==$tag)
$putparams='='.$v.' '.$putparams;
else
{
if(strpos($v,' ')===false)
$sep='';
elseif(strpos($v,''')===false)
$sep='"';
else
$sep=''';
$putparams.=$k.'='.$sep.$v.$sep.' ';
}
return '['.$tag.rtrim($putparams).']'.$content.'[/'.$tag.']';
}
unset($params['noparse'],$params[$tag]);
$putparams=' ';
foreach($params as $k=>$v)
{
$sep=strpos($v,''')===false ? '"' : ''';
$putparams.=$k.'='.$sep.$v.$sep.' ';
}
return '<'.$tag.rtrim($putparams).'>'.$content.'</'.$tag.'>';
}
public function PreEdit($tag,$params,$content,$canuse,$single=false)
{
if(!is_array($params))
$params=Strings::ParseParams($params,$tag);
$putparams=isset($params[$tag]) ? '' : ' ';
if(!$canuse or isset($params['noparse']))
{
unset($params['noparse']);
$canuse=false;
}
foreach($params as $k=>$v)
if($k==$tag)
$putparams='='.$v.' '.$putparams;
elseif($v==$k)
$putparams.=$k.' ';
else
{
if(strpos($v,' ')===false)
$sep='';
elseif(strpos($v,''')===false)
$sep='"';
else
$sep=''';
$putparams.=$k.'='.$sep.$v.$sep.' ';
}
return '['.$tag.rtrim($putparams).($canuse ? '' : ' noparse').']'.$content.($single ? '' : '[/'.$tag.']');
}
public function PreSave($tag,$params,$content,$canuse,$single=false)
{
return $this->PreEdit($tag,$params,$content,$canuse,$single);
}
/*
Функции, которым для обработки необходимо передать весь массив текста
public function TotalPreSave($text,$tags,$canuse,$params,$content,$curpos,$length,$single){retur
n $text;}
public function TotalPreEdit($text,$tags,$canuse,$params,$content,$curpos,$length,$single){retur
n $text;}
public function TotalPreDisplay($text,$tags,$canuse,$params,$content,$curpos,$length,$single){re
turn $text;}
*/
}
?>
Цитата