23-FCKEditor参数配置详解(PHP方法)
今天我们来看一下通过PHP来实现编辑器配置的方法。
通过PHP实现的编辑器的编辑方法也是很简单的,其关键是通过Config属性来实现的,其语法结构是:
$oFCKeditor->Config[“属性名称”] = "值";
初始状态如下:

我们就来举个例子吧!
$oFCKeditor = new FCKeditor ( "content" );
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
$oFCKeditor->Width = "100%";
$oFCKeditor->Height = "350";
$oFCKeditor->ToolbarSet = "Default";
$oFCKeditor->BasePath = "/fckeditor/fckeditor/";
$oFCKeditor->Config["BasePath"] = $oFCKeditor->BasePath ."editor/";
$oFCKeditor->Config ["FontNames"] = "宋体;隶书;华文行楷;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana";
$oFCKeditor->Config["FontFormats"] = "p;h1;h2;h3";
$oFCKeditor->Config ["FontSizes"] = "12px;14px;16px;18px;20px;24px;28px;smaller;larger;xx-small;x-small;small;medium;large;x-large;xx-large";
在上述的的配置中,我们修改了字体、字号及文本的格式化
运行效果如下:

好了,现在我们来设置一下表情吧!
$oFCKeditor->Config["SmileyPath"] = $oFCKeditor->Config["BasePath"] . "p_w_picpaths/smiley/QQFace/";
$oFCKeditor->Config["SmileyImages"] = "1.gif,2.gif";
运行效果如下:

唉,怎么看不到图片呢!
如果看不到图片,那只有可能图片的路径或文件名称引用错误,我们来找一下问题所在吧!
所以,我找到了editor\dialog\fck_smiley.html(这是一个读取表情的文件)
先修改一下下再说!(红色代码部分)
<script type="text/javascript">
var FCKConfig = oEditor.FCKConfig ;
var sBasePath = FCKConfig.SmileyPath ;
var aImages = FCKConfig.SmileyImages ;
var iCols = FCKConfig.SmileyColumns ;
var iColWidth = parseInt( 100 / iCols, 10 ) ;
var i = 0 ;
while (i < aImages.length)
{
document.write( '<tr>' ) ;
for(var j = 0 ; j < iCols ; j++)
{
if (aImages[i])
{
var sUrl = sBasePath + aImages[i] ;
document.write( '<td width="' + iColWidth + '%" align="center" class="DarkBackground Hand" + sUrl.replace(/'/g, "\\'" ) + '\')" onmouseover="over(this)" onmouseout="out(this)">' ) ;
document.write(sUrl + " " + sBasePath);
document.write( '<img src="' + sUrl + '" border="0"/>' ) ;
}
else
document.write( '<td width="' + iColWidth + '%" class="DarkBackground"> ' ) ;
document.write( '<\/td>' ) ;
i++ ;
}
document.write('<\/tr>') ;
}
</script>
效果如下:

啊,怎么还这样呀!换个浏览器!(Firefox)

还是火狐呀!终于找到病灶所在了!(唉,其实仔细一下,也应该想得出来!要不是嫌疼,早抽自己一个大嘴巴了!哈哈哈)
因为,JS文件中需要的是一个数组,而通过PHP只能传递一个字符串!
那好办呀,我们只需要看看现在的aImages是数组还是字符串,如果是字符串,那就按JS的办法拆分为数组,如果是数组,也就直接引用吧!
好了,现在关键问题是如果在JS中判断一个变量是否为数组呢!google一下吧!找到了!
function is_array(test)
{
if(typeof test == 'object' && typeof test.sort == 'function' && typeof test.length == 'number')
{
return true;
}
else
{
return false;
}
}
好了,代码修改如下:
<script type="text/javascript">
function is_array(test)
{
if(typeof test == 'object' && typeof test.sort == 'function' && typeof test.length == 'number')
{
return true;
}
else
{
return false;
}
}
var FCKConfig = oEditor.FCKConfig ;
var sBasePath = FCKConfig.SmileyPath ;
var aImages = FCKConfig.SmileyImages ;
if(!is_array(aImages))
aImages = aImages.split(",");
var iCols = FCKConfig.SmileyColumns ;
var iColWidth = parseInt( 100 / iCols, 10 ) ;
var i = 0 ;
while (i < aImages.length)
{
document.write( '<tr>' ) ;
for(var j = 0 ; j < iCols ; j++)
{
if (aImages[i])
{
var sUrl = sBasePath + aImages[i] ;
document.write( '<td width="' + iColWidth + '%" align="center" class="DarkBackground Hand" + sUrl.replace(/'/g, "\\'" ) + '\')" onmouseover="over(this)" onmouseout="out(this)">' ) ;
document.write( '<img src="' + sUrl + '" border="0"/>' ) ;
}
else
document.write( '<td width="' + iColWidth + '%" class="DarkBackground"> ' ) ;
document.write( '<\/td>' ) ;
i++ ;
}
document.write('<\/tr>') ;
}
</script>
好了,试一下下吧!

OK,大功告成!
我们可以停止呼吸,但决不能停止思考!
转载于:https://blog.51cto.com/pangdou/252324