<?php
/*
　* @$Id
　* @
　* @Ver: 2.0
　* @Create: 2009-11-18 8:10
　* @Modify: 
　* @Author: CPWEB http://www.cpweb.net.cn
　* @Copyright (C) 2008 www.cpweb.net.cn. All Rights Reserved.
　* @License CPWEB is free software and use is subject to license terms
　*/
import('TagLib');
class TagLibCpweb extends TagLib{
	public function _initialize(){
		$this->xml = dirname(__FILE__).'/Tags/cpweb.xml';
	}
	public function _cpweb_list($attr,$content){
		$tag=$this->parseXmlAttr($attr,'include');
		$name=$tag['name'];
		$limit=$tag['limit'];
		if($limit){
			$url_limit='limit/'.$limit.'/';
		}else{
			$url_limit='';
		}
		if($name){
			$url_name='sn/'.$name.'/';
		}else{
			$url_name='';
		}
		$url='http://www.cpweb.net.cn/index.php/announce_article/cpweb_announce/'.$url_limit.$url_name;
		$return=file_get_contents($url);
		return '<?php $return=file_get_contents("'.$url.'");
		if($return){
		echo $return;
		}else{
		echo "<div align=\"center\">暂无内容</div>";}
		?>';
	}
	
	/**
     +----------------------------------------------------------
     * editor标签解析 插入可视化编辑器
     * 格式： <html:editor id="editor" name="remark" type="FCKeditor" content="{$vo.remark}" />
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string|void
     +----------------------------------------------------------
     */
    public function _editor($attr)
    {
        $tag        =	$this->parseXmlAttr($attr,'editor');
        $id			=	!empty($tag['id'])?$tag['id']: '_editor';
        $name   	=	$tag['name'];
        $style   	    =	!empty($tag['style'])?$tag['style']:'';
        $width		=	!empty($tag['width'])?$tag['width']: '100%';
        $height     =	!empty($tag['height'])?$tag['height'] :'320px';
		$toolbarset =   !empty($tag['toolbarset'])?$tag['toolbarset'] :'Default';
        $content    =   $tag['content'];
        $type       =   $tag['type'] ;
		$repeat     =   $tag['repeat'] ;
		if(!$type) $type='CKEDITOR';
		if(!$repeat){
			switch(strtoupper($type)) {
            case 'CKEDITOR':
                $repeat_js   =	'<script type="text/javascript" src="__ROOT__/Public/Js/ckeditor/ckeditor.js"></script>';
                break;
			case 'FCKEDITOR':
                $repeat_js   =	'<script type="text/javascript" src="__ROOT__/Public/Js/FCKeditor/fckeditor.js"></script>';
                break;
            case 'EWEBEDITOR':
                $repeat_js	=	"<script type='text/javascript' src='__ROOT__/Public/Js/eWebEditor/js/edit.js'></script>";
                break;
            case 'UBB':
                $repeat_js	=	'<script type="text/javascript" src="__ROOT__/Public/Js/UbbEditor.js"></script>';
                break;
            default :
                $repeat_js  =  '';
        }
		}
		if(strtoupper($type)=='CKEDITOR'){
			if($tag['toolbarset']=='Basic'){
				$toolbarset=",toolbar : [ ['Bold', 'Italic', 'Underline', 'Strike','-','Link', '-', 'MyButton' ] ]";
			}elseif($tag['toolbarset']=='Default'){
				$toolbarset=",toolbar : [ ['Source','Preview','Templates'],['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],'/',['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],['Link','Unlink','Anchor'],['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],'/',['Styles','Format','Font','FontSize'],['TextColor','BGColor'],['Maximize', 'ShowBlocks'] ]";
			}else{
				$toolbarset=",toolbar : ['".$tag['toolbarset']."']";
			}
		}
        switch(strtoupper($type)) {
            case 'CKEDITOR':
                $parseStr   =	'<!-- 编辑器调用开始 -->'.$repeat_js.'<textarea id="'.$id.'" name="'.$name.'">'.$content.'</textarea><script type="text/javascript">CKEDITOR.replace( "'.$name.'" ,{width:"'.$width.'",height:"'.$height.'" '.$toolbarset.'});</script> <!-- 编辑器调用结束 -->';
                break;
			case 'FCKEDITOR':
                $parseStr   =	'<!-- 编辑器调用开始 -->'.$repeat_js.'<textarea id="'.$id.'" name="'.$name.'">'.$content.'</textarea><script type="text/javascript"> var oFCKeditor = new FCKeditor( "'.$id.'","'.$width.'","'.$height.'","'.$toolbarset.'" ) ; oFCKeditor.BasePath = "__ROOT__/Public/Js/FCKeditor/" ; oFCKeditor.ReplaceTextarea() ;function resetEditor(){setContents("'.$id.'",document.getElementById("'.$id.'").value)}; function saveEditor(){document.getElementById("'.$id.'").value = getContents("'.$id.'");} function InsertHTML(html){ var oEditor = FCKeditorAPI.GetInstance("'.$id.'") ;if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG ){oEditor.InsertHtml(html) ;}else	alert( "FCK必须处于WYSIWYG模式!" ) ;}</script> <!-- 编辑器调用结束 -->';
                break;
            case 'EWEBEDITOR':
                $parseStr	=	"<!-- 编辑器调用开始 -->".$repeat_js."<input type='hidden'  id='{$id}' name='{$name}'  value='{$conent}'><iframe src='__ROOT__/Public/Js/eWebEditor/ewebeditor.htm?id={$name}' frameborder=0 scrolling=no width='{$width}' height='{$height}'></iframe><script type='text/javascript'>function saveEditor(){document.getElementById('{$id}').value = getHTML();} </script><!-- 编辑器调用结束 -->";
                break;
            case 'NETEASE':
                $parseStr   =	'<!-- 编辑器调用开始 --><textarea id="'.$id.'" name="'.$name.'" style="display:none">'.$content.'</textarea><iframe ID="Editor" name="Editor" src="__ROOT__/Public/Js/HtmlEditor/index.html?ID='.$name.'" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" style="height:'.$height.';width:'.$width.'"></iframe><!-- 编辑器调用结束 -->';
                break;
            case 'UBB':
                $parseStr	=	$repeat_js.'<div style="padding:1px;width:'.$width.';border:1px solid silver;float:left;"><script LANGUAGE="JavaScript"> showTool(); </script></div><div><TEXTAREA id="UBBEditor" name="'.$name.'"  style="clear:both;float:none;width:'.$width.';height:'.$height.'" >'.$content.'</TEXTAREA></div><div style="padding:1px;width:'.$width.';border:1px solid silver;float:left;"><script LANGUAGE="JavaScript">showEmot();  </script></div>';
                break;
            default :
                $parseStr  =  '<textarea id="'.$id.'" style="'.$style.'" name="'.$name.'" >'.$content.'</textarea>';
        }

        return $parseStr;
    }
}
?>