查看完整版本: fck的中级使用

lily 2007-8-1 22:31

fck的中级使用

             <p>今天突然想看看cms的东西,我到处找了找,发现了三个一个是dedecms,一个是phpcms(加密了),还有一个是verycms。<BR>在弄dedecms的时候发现它使用的编辑器是fck,我原来也用过,但是没有他修改的那么好,修改了很多的东西,我也想<BR>修改一个自己使用的,但是我使用的时候发现没有那么简单,现在的版本跟那个时候差的比较远,我到现在也没有找到<BR>toolbar这些图片放到那里了,感觉是一张大图做的热点,而原来是是图片,而且也没找到具体的对应关系。<BR>但是弄了就不能白弄,顺便修改了一个能使用的fck出来,当然是针对php的,关于fck的初级使用我就不说了,如果不会的你<BR>可以去 blog.csdn.net/sanshi0815 上面去找 那里面有简单的一个使用。这个称之为中级使用,我一定是做修改的。<BR>使用fck的好处就是,使用他的上传功能,fck的上传功能分三种,一种是文件,一种是图片,一种的flash,<BR>如果使用默认的配置文件的话,一定会出现问题。他上传的文件全放在一个目录下,这个目录在你使用以上三种浏览的时候都看不到,<BR>所以要设置下,修改 FCKeditor\editor\filemanager\upload\php\下 的文件,还有一个问题就是,他默认是你上传什么样的文件名字<BR>最后给你存在服务器为什么名字。这样使用我感觉有写地方不太适用,我做了简单的修改<BR>在config.php修改成了如下的样子<BR>[php]<BR>global $Config ;<BR>$Config['Enabled'] = "uploader" ;<BR>$Config['UserFilesPath'] = '/UserFiles/' ;<BR>$Config['UserFilesAbsolutePath'] = '' ;<BR>$Config['ForceSingleExtension'] = true ;<BR><BR>$Config['AllowedExtensions']['File'] = array('rar','doc') ;<BR>$Config['DeniedExtensions']['File'] = array() ;<BR><BR>$Config['AllowedExtensions']['Image'] = array('jpg','gif','jpeg','png') ;<BR>$Config['DeniedExtensions']['Image'] = array() ;<BR><BR>$Config['AllowedExtensions']['Flash'] = array('swf','fla') ;<BR>$Config['DeniedExtensions']['Flash'] = array() ;<BR><BR>//sanshi add. set save file name ,donot the file type<BR>//如果使用上传的文件名的话,设置 $saveFileName=false<BR>$saveFileName = date("Y,m,d,H,i,s");<BR>[/php]<BR>而upload.php 同样进行了修改,动的比较乱,同时做一些东西做了简单的中文翻译<BR>[php]<BR>require('config.php') ;<BR>require('util.php') ;<BR><BR>// This is the function that sends the results of the uploading process.<BR>function SendResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' )<BR>{<BR>echo '&lt;script type="text/javascript"&gt;' ;<BR>echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . str_replace( '"', '\\"', $fileUrl ) . '","' . str_replace( '"', '\\"', $fileName ) . '", "' . str_replace( '"', '\\"', $customMsg ) . '") ;' ;<BR>echo '&lt;/script&gt;' ;<BR>exit ;<BR>}<BR><BR>// Check if this uploader has been enabled.<BR>if ( !$Config['Enabled'] )<BR>SendResults( '1', '', '', '这个文件上传失败请检查 "editor/filemanager/upload/php/config.php" 文件' ) ;<BR><BR>// Check if the file has been correctly uploaded.<BR>if ( !isset( $_FILES['NewFile'] ) || is_null( $_FILES['NewFile']['tmp_name'] ) || $_FILES['NewFile']['name'] == '' )<BR>SendResults( '202' ) ;<BR><BR>// Get the posted file.<BR>$oFile = $_FILES['NewFile'] ;<BR><BR>// Get the uploaded file name extension.<BR>$sFileName = $oFile['name'] ;<BR><BR>// Replace dots in the name with underscores (only one dot can be there... security issue).<BR>if ( $Config['ForceSingleExtension'] )<BR>$sFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sFileName ) ;<BR><BR>$sOriginalFileName = $sFileName ;<BR><BR>// Get the extension.<BR>$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;<BR>$sExtension = strtolower( $sExtension ) ;<BR><BR>// The the file type (from the QueryString, by default 'File').<BR>$sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ;<BR><BR>// Check if it is an allowed type.<BR>if ( !in_array( $sType, array('File','Image','Flash','Media') ) )<BR>SendResults( 1, '', '', '上传类别错误!' ) ;<BR><BR>// Get the allowed and denied extensions arrays.<BR>$arAllowed = $Config['AllowedExtensions'][$sType] ;<BR>$arDenied = $Config['DeniedExtensions'][$sType] ;<BR><BR>// Check if it is an allowed extension.<BR>if ( ( count($arAllowed) &gt; 0 &amp;&amp; !in_array( $sExtension, $arAllowed ) ) || ( count($arDenied) &gt; 0 &amp;&amp; in_array( $sExtension, $arDenied ) ) )<BR>SendResults( '202' ) ;<BR><BR>$sErrorNumber = '0' ;<BR>$sFileUrl = '' ;<BR><BR>// Initializes the counter used to rename the file, if another one with the same name already exists.<BR>$iCounter = 0 ;<BR><BR>// The the target directory.<BR>if ( isset( $Config['UserFilesAbsolutePath'] ) &amp;&amp; strlen( $Config['UserFilesAbsolutePath'] ) &gt; 0 )<BR>$sServerDir = $Config['UserFilesAbsolutePath'] ;<BR>else <BR>$sServerDir = GetRootPath() . $Config["UserFilesPath"]."{$sType}/";<BR><BR>while ( true )<BR>{<BR>// Compose the file path. <BR>//$sExtension 这个变量是文件后缀<BR>// $saveFileName 为设置的保存文件名<BR>//$sFilePath = $sServerDir . $sFileName ; //old<BR>//sanshi add<BR>if( $saveFileName!=false )<BR>$sFileName = $saveFileName.".".$sExtension;<BR>else<BR>$sFilePath = $sServerDir . $sFileName ;<BR><BR>$sFilePath = $sServerDir . $sFileName ;<BR>// If a file with that name already exists.<BR>if ( is_file( $sFilePath ) )<BR>{<BR>$iCounter++ ;<BR>$sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;<BR>$sErrorNumber = '201' ;<BR>}<BR>else<BR>{<BR>//SendResults( '1', '', '', $sFilePath) ;exit(); <BR>if( function_exists("move_uploaded_file") )<BR>move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;<BR>else<BR>copy($oFile['tmp_name'], $sFilePath);<BR><BR>if ( is_file( $sFilePath ) )<BR>{<BR>$oldumask = umask(0) ;<BR>chmod( $sFilePath, 0777 ) ;<BR>umask( $oldumask ) ;<BR>}<BR><BR>$sFileUrl = $Config["UserFilesPath"]."{$sType}/" . $sFileName ;<BR><BR>break ;<BR>}<BR>}<BR><BR>SendResults( $sErrorNumber, $sFileUrl, $sFileName ) ;<BR>[/php]<BR>php的文件基本处理完成了,然后看其他的文件<BR>对fck的配制文件的修改是必然的了,就不在展示了<BR>同时,我对几个错误处理文件也做了中文的错误提示的修改<BR>路径是 <BR>FCKeditor\editor\dialog\的 fck_image ,fck_flash,fck_link 目录下的错误提示做的修改<BR>然后就是对上面路径下的js文件大家有个思想准备,他们提供了错误号<BR>0 成功<BR>1 自己定义<BR>101 自己定义<BR>202 类型错误<BR>203 权限错误<BR><BR>大家注意使用fck的时候会做一些权限的处理,这个时候可以使用js在这几个js的文件里做判断了<BR>这几个文件是在提交的时候用的上,如果加权限判断的话,请加在 CheckUpload()这个函数里。<BR><BR>关于如何找到tool与文件的对应关系我使劲的找也没有结果,<BR>不过大家可以看到 FCKeditor\editor\dialog\ 这个目录下有很多的对应文件,大家可以想办法做些处理来完善下。<BR><BR>说另外一个问题,多用户使用<BR>fck可以完成多用使用,原来是不同的用户把图片放到不同的目录下,浏览的时候根据不同的用户去看不同的目录就可以了,<BR>把管理员的目录放到最上面,也就是说其他人员的图片目录在管理员的目录下面,就可以了。<BR>关于上传还是设置 config.php这个文件的 $Config['UserFilesPath'] 路径 加个什么其他的您自己看着办<BR>浏览目录的设置在 FCKeditor\editor\filemanager\browser\default\connectors\php\config.php<BR>文件<BR>修改<BR>$Config['UserFilesPath'] = '/UserFiles/' ; 要做基本的对应<BR>这个目录看名字增加了很多新的功能,不过,没具体看<BR><BR>另外一个问题就是,如果用户上传了什么东西,我们要做个记录这个怎么办?<BR>没有什么好的办法,在用户提交以后做判断,如果是附件上传那您需要自己分析下,如果是图片的<BR>我写了一个,不过我正则不好,也就是笔画下,有什么好的方式,<a href="http://www.phpchina.com/javascript:;" onClick="javascript:tagshow(event, '%B7%BD%B7%A8');" target="_self"><u><strong>方法</strong></u></a>麻烦您留言,我也顺便<a href="http://www.phpchina.com/javascript:;" onClick="javascript:tagshow(event, '%D1%A7%CF%B0');" target="_self"><u><strong>学习</strong></u></a>下<BR>[php]<BR>$str=' <P><IMG height=100 alt="" src="http://www.phpx.com/UserFiles/Image/2006,08,24,12,10,36.jpg" width=100><IMG height=100 alt="" src="http://www.phpx.com/UserFiles/Image/2006,08,24,12,10,36.jpg" width=100></P>';<BR>$format='/<IMG.*?\ />/i';<BR>$temp=array();<BR>preg_match_all($format,$str,$out);<BR>foreach ((array)$out[0] As $k)<BR>{<BR>$format2 = '/src=http://www.phpchina.com/["](.*)["]/';<BR>$len=preg_match_all($format2,$k,$outTemp);<BR>$temp[]=$outTemp[$len];<BR>}<BR>print_r($temp);<BR>[/php]<BR><BR>还有个问题,就是<a href="http://www.phpchina.com/javascript:;" onClick="javascript:tagshow(event, 'css');" target="_self"><u><strong>css</strong></u></a>的问题,如果用户在选择字体的时候一直使用默认的,当用户发表以后有可能会发现,<BR>编辑时候的字体与发表后的字体有区别,我当初使用的时候就遇到了,但是没想出来好的解决办法,现在告诉您,去修改一个文件<BR>文件位置在<BR>FCKeditor\editor\css\fck_editorarea.css 这个文件,起作用的是 <BR>body, td<BR>{<BR>font-family: Arial, Verdana, Sans-Serif;<BR>font-size: 12px;<BR>}<BR>这里的内容把字体的大小设置成,跟您发布的默认大小一样就不会出现上面说的问题了。<BR><BR>最后一个问题就是,当我要浏览服务器上的图片,flash,还有文件的时候,会出现一个提示,你可以建立新的文件夹<BR>并可以选择文件夹上传东西,这个功能如果你想关闭的话<BR>请到<BR>FCKeditor\editor\filemanager\browser\default 目录下<BR>修改<BR>frmcreatefolder.html<BR>把下面的内容注释掉<BR><CENTER><TABLE cellSpacing=0 cellPadding=0 width="90%" border=0><TBODY><TR><TD><DIV class=codetop>CODE:
页: [1]
查看完整版本: fck的中级使用
PageRank