<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>shooting's sky &#187; fckeditor插件</title>
	<atom:link href="http://anfirst.cn/archives/tag/fckeditor%e6%8f%92%e4%bb%b6/feed" rel="self" type="application/rss+xml" />
	<link>http://anfirst.cn</link>
	<description>专心每一天</description>
	<lastBuildDate>Fri, 11 May 2012 04:49:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>smarty中使用fckeditor</title>
		<link>http://anfirst.cn/archives/946</link>
		<comments>http://anfirst.cn/archives/946#comments</comments>
		<pubDate>Tue, 06 Apr 2010 12:39:02 +0000</pubDate>
		<dc:creator>shooting</dc:creator>
				<category><![CDATA[全部文章]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[fckeditor插件]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://anfirst.cn/?p=946</guid>
		<description><![CDATA[网上最常用的做法是先在php中调用fckeditor类的createHtml方法生成一段html，直接assign给一个samrty变量即可 这里我通过smarty的插件机制，可以更方便的在smarty中集成fckeditor，在smarty的plugin目录中新建文件function.fck.php 内容如下 &#60;?php function smarty_function_fck($params, &#38;$smarty) {  if(!isset($params['InstanceName']) &#124;&#124; empty($params['InstanceName']))  {   $smarty-&#62;trigger_error(&#8216;fckeditor: required parameter “InstanceName” missing&#8217;);  }  static $base_arguments = array();  static $config_arguments = array();  if(!count($base_arguments))   $init = TRUE;  else   $init = FALSE;  if(isset($params['BasePath']))  {   $base_arguments['BasePath'] = $params['BasePath'];  }  else if(empty($base_arguments['BasePath']))  { //这里设置默认的fck所在的目录,相对于要使用fck的程序的目录   $base_arguments['BasePath'] = &#8216;../plugins/fckeditor/&#8217;;  }  $base_arguments['InstanceName'] = $params['InstanceName'];  if(isset($params['Value'])) $base_arguments['Value'] = $params['Value']; [...]]]></description>
			<content:encoded><![CDATA[<p>网上最常用的做法是先在php中调用fckeditor类的createHtml方法生成一段html，直接assign给一个samrty变量即可</p>
<p>这里我通过smarty的插件机制，可以更方便的在smarty中集成fckeditor，在smarty的plugin目录中新建文件function.fck.php</p>
<p>内容如下</p>
<blockquote><p>&lt;?php<br />
function smarty_function_fck($params, &amp;$smarty)<br />
{<br />
 if(!isset($params['InstanceName']) || empty($params['InstanceName']))<br />
 {<br />
  $smarty-&gt;trigger_error(&#8216;fckeditor: required parameter “InstanceName” missing&#8217;);<br />
 }</p>
<p> static $base_arguments = array();<br />
 static $config_arguments = array();</p>
<p> if(!count($base_arguments))<br />
  $init = TRUE;<br />
 else<br />
  $init = FALSE;</p>
<p> if(isset($params['BasePath']))<br />
 {<br />
  $base_arguments['BasePath'] = $params['BasePath'];<br />
 }<br />
 else if(empty($base_arguments['BasePath']))<br />
 {</p>
<p>//这里设置默认的fck所在的目录,相对于要使用fck的程序的目录<br />
  $base_arguments['BasePath'] = &#8216;../plugins/fckeditor/&#8217;;<br />
 }</p>
<p> $base_arguments['InstanceName'] = $params['InstanceName'];</p>
<p> if(isset($params['Value'])) $base_arguments['Value'] = $params['Value'];<br />
 if(isset($params['Width'])) $base_arguments['Width'] = $params['Width'];<br />
 if(isset($params['Height'])) $base_arguments['Height'] = $params['Height'];<br />
 if(isset($params['ToolbarSet'])) $base_arguments['ToolbarSet'] = $params['ToolbarSet'];<br />
 if(isset($params['CheckBrowser'])) $base_arguments['CheckBrowser'] = $params['CheckBrowser'];<br />
 if(isset($params['DisplayErrors'])) $base_arguments['DisplayErrors'] = $params['DisplayErrors'];</p>
<p> // Use all other parameters for the config array (replace if needed)<br />
 $other_arguments = array_diff_assoc($params, $base_arguments);<br />
 $config_arguments = array_merge($config_arguments, $other_arguments);</p>
<p> $out = ”;</p>
<p> if($init)<br />
 {<br />
  $out .= &#8216;&lt;script type=”text/javascript” src=”&#8216; . $base_arguments['BasePath'] . &#8216;fckeditor.js”&gt;&lt;/script&gt;&#8217;;<br />
 }</p>
<p> $out .= “\n&lt;script type=\”text/javascript\”&gt;\n”;<br />
 $out .= “var oFCKeditor = new FCKeditor(&#8216;” . $base_arguments['InstanceName'] . “&#8216;);\n”;</p>
<p> foreach($base_arguments as $key =&gt; $value)<br />
 {<br />
  if(!is_bool($value))<br />
  {<br />
   // Fix newlines, javascript cannot handle multiple line strings very well.<br />
   $value = &#8216;”&#8216; . preg_replace(“/[\r\n]+/”, &#8216;” + $0&#8243;&#8216;, addslashes($value)) . &#8216;”&#8216;;<br />
  }<br />
  $out .= “oFCKeditor.$key = $value; “;<br />
 }</p>
<p> foreach($config_arguments as $key =&gt; $value)<br />
 {<br />
  if(!is_bool($value))<br />
  {<br />
   $value = &#8216;”&#8216; . preg_replace(“/[\r\n]+/”, &#8216;” + $0&#8243;&#8216;, addslashes($value)) . &#8216;”&#8216;;<br />
  }<br />
  $out .= “oFCKeditor.Config[\"$key\"] = $value; “;<br />
 }</p>
<p> $out .= “\noFCKeditor.Create();\n”;<br />
 $out .= “&lt;/script&gt;\n”;</p>
<p> return $out;<br />
}<br />
?&gt;</p></blockquote>
<p>使用代码</p>
<blockquote><p>{fck InstanceName=”body”  BasePath=“../plugins/fckeditor/” Value=$news_info.body Width=”100%” Height=”400&#8243;}<br />
可以自定义参数 ToolbarSet-使用的工具栏, BasePath-fck相对于当前脚本的目录,InstanceName-要赋予的$_POST变量名, Value-默认值等</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://anfirst.cn/archives/946/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

