3 PHP Connector for the FCKEditor v2 File Manager
4 Written By Grant French, UK, Sept 2004
7 FCKEditor - By Frederico Caldeira Knabben
8 http://www.fckeditor.net
11 Implements the GetFoldersAndFiles command, to list
12 files and folders in the current directory.
15 2009.2.10 mbstringなしでも実行できるように修正 by naoki hirata
16 2010.8.25 画像のサイズを調べるときファイルサイズもチェック by naoki hirata
19 class GetFoldersAndFiles extends command {
24 if ($dh = @opendir($this->path($this->actual_cwd))) {
25 while (($filename = readdir($dh)) !== false) {
26 if ($filename == ".") continue;
27 if ($filename == "..") continue;
29 if (function_exists('mb_convert_encoding')){
30 $filename = mb_convert_encoding($filename, 'UTF-8', $this->fckphp_config['FileEncoding']);
33 if (is_dir($this->path("{$this->actual_cwd}{$filename}"))) {
34 //check if$fckphp_configured not to show this folder
38 if (function_exists('mb_ereg')){
39 for($i = 0; $i < sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders']); $i++) {
40 if ( mb_ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders'][$i], $filename) ) {
46 for($i = 0; $i < sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders']); $i++) {
47 if ( ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders'][$i], $filename) ) {
56 array_push($folders, $filename);
58 if (function_exists('mb_strrpos')){
59 $lastdot = mb_strrpos($filename, ".");
60 $ext = ($lastdot !== false) ? (mb_substr($filename, $lastdot + 1)) : "";
62 $lastdot = strrpos($filename, ".");
63 $ext = ($lastdot !== false) ? (substr($filename, $lastdot + 1)) : "";
66 if (! in_array(strtolower($ext), $this->fckphp_config['ResourceAreas'][$this->type]['AllowedExtensions'])) continue;
68 //check if $fckphp_configured not to show this file
72 if (function_exists('mb_ereg')){
73 for($i = 0; $i < sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles']); $i++) {
74 if ( mb_ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles'][$i], $filename) ) {
80 for($i = 0; $i < sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles']); $i++) {
81 if ( ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles'][$i], $filename) ) {
90 array_push($files, $filename);
100 header ("Content-Type: application/xml; charset=utf-8");
101 echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
103 <!DOCTYPE Connector [
105 <?php include "dtd/iso-lat1.ent";?>
107 <!ELEMENT Connector (CurrentFolder,Folders,Files)>
108 <!ATTLIST Connector command CDATA "noname">
109 <!ATTLIST Connector resourceType CDATA "0">
111 <!ELEMENT CurrentFolder (#PCDATA)>
112 <!ATTLIST CurrentFolder path CDATA "noname">
113 <!ATTLIST CurrentFolder url CDATA "0">
115 <!ELEMENT Folders (#PCDATA)>
117 <!ELEMENT Folder (#PCDATA)>
118 <!ATTLIST Folder name CDATA "noname_dir">
120 <!ELEMENT Files (#PCDATA)>
122 <!ELEMENT File (#PCDATA)>
123 <!ATTLIST File name CDATA "noname_file">
124 <!ATTLIST File size CDATA "0">
127 <Connector command="GetFoldersAndFiles" resourceType="<?php echo $this->XMLEncode($this->type); ?>">
128 <CurrentFolder path="<?php echo $this->XMLEncode($this->raw_cwd); ?>" url="<?php echo $this->XMLEncode($this->url($this->actual_cwd)); ?>" />
131 for ($i = 0; $i < sizeof($folders); $i++) {
133 <Folder name="<?php echo $this->XMLEncode($folders[$i]); ?>" url="<?php echo $this->XMLEncode($this->url($folders[$i])); ?>" />
141 for ($i = 0; $i < sizeof($files); $i++) {
142 $size = ceil(@filesize($this->path("{$this->actual_cwd}{$files[$i]}")) / 1024);
144 // PHPの割り当てメモリサイズが小さいとき、ファイルサイズが大きいとgetimagesizeが落ちるのでサイズをチェック(2010/8/25)
147 if ($size <= 1024 * 3){ // 3Mバイトまで
148 $info = getimagesize($this->path("{$this->actual_cwd}{$files[$i]}"));
149 if ($info !== false){
155 <File name="<?php echo $this->XMLEncode($files[$i]); ?>" url="<?php echo $this->XMLEncode($this->url($files[$i])); ?>" size="<?php echo $size; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />