OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / scripts / fckeditor2.6.6 / editor / plugins / FileBrowser_Thumbnail / connectors / php / Commands / GetFoldersAndFiles.php
1 <?php
2 /*
3 PHP Connector for the FCKEditor v2 File Manager
4 Written By Grant French, UK, Sept 2004
5 http://www.mcpuk.net
6
7 FCKEditor - By Frederico Caldeira Knabben
8 http://www.fckeditor.net
9
10 File Description:
11 Implements the GetFoldersAndFiles command, to list
12 files and folders in the current directory.
13 Output is in XML
14
15 2009.2.10       mbstringなしでも実行できるように修正 by naoki hirata
16 2010.8.25       画像のサイズを調べるときファイルサイズもチェック by naoki hirata
17 */
18
19 class GetFoldersAndFiles extends command {
20         function run() {
21                 $folders = array();
22                 $files = array();
23                 
24                 if ($dh = @opendir($this->path($this->actual_cwd))) {
25                         while (($filename = readdir($dh)) !== false) {
26                                 if ($filename == ".") continue;
27                                 if ($filename == "..") continue;
28                                 
29                                 if (function_exists('mb_convert_encoding')){
30                                         $filename = mb_convert_encoding($filename, 'UTF-8', $this->fckphp_config['FileEncoding']);
31                                 }
32                                 
33                                 if (is_dir($this->path("{$this->actual_cwd}{$filename}"))) {
34                                         //check if$fckphp_configured not to show this folder
35                                         
36                                         $hide = false;
37                                         
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) ) {
41                                                                 $hide = true;
42                                                                 break;
43                                                         }
44                                                 }
45                                         } else {
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) ) {
48                                                                 $hide = true;
49                                                                 break;
50                                                         }
51                                                 }
52                                         }
53                                         
54                                         if ($hide) continue;
55                                         
56                                         array_push($folders, $filename);
57                                 } else {
58                                         if (function_exists('mb_strrpos')){
59                                                 $lastdot = mb_strrpos($filename, ".");
60                                                 $ext = ($lastdot !== false) ? (mb_substr($filename, $lastdot + 1)) : "";
61                                         } else {
62                                                 $lastdot = strrpos($filename, ".");
63                                                 $ext = ($lastdot !== false) ? (substr($filename, $lastdot + 1)) : "";
64                                         }
65                                         
66                                         if (! in_array(strtolower($ext), $this->fckphp_config['ResourceAreas'][$this->type]['AllowedExtensions'])) continue;
67                                         
68                                         //check if $fckphp_configured not to show this file
69                                         
70                                         $hide = false;
71                                         
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) ) {
75                                                                 $hide = true;
76                                                                 break;
77                                                         }
78                                                 }
79                                         } else {
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) ) {
82                                                                 $hide = true;
83                                                                 break;
84                                                         }
85                                                 }
86                                         }
87                                         
88                                         if ($hide) continue;
89                                         
90                                         array_push($files, $filename);
91                                 }
92                         }
93                         
94                         closedir($dh); 
95                 }
96                 
97                 sort($folders);
98                 sort($files);
99                 
100                 header ("Content-Type: application/xml; charset=utf-8");
101                 echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
102 ?>
103 <!DOCTYPE Connector [
104
105 <?php include "dtd/iso-lat1.ent";?>
106         
107         <!ELEMENT Connector     (CurrentFolder,Folders,Files)>
108                 <!ATTLIST Connector command CDATA "noname">
109                 <!ATTLIST Connector resourceType CDATA "0">
110                 
111         <!ELEMENT CurrentFolder (#PCDATA)>
112                 <!ATTLIST CurrentFolder path CDATA "noname">
113                 <!ATTLIST CurrentFolder url CDATA "0">
114                 
115         <!ELEMENT Folders       (#PCDATA)>
116         
117         <!ELEMENT Folder        (#PCDATA)>
118                 <!ATTLIST Folder name CDATA "noname_dir">
119                 
120         <!ELEMENT Files         (#PCDATA)>
121                 
122         <!ELEMENT File          (#PCDATA)>
123                 <!ATTLIST File name CDATA "noname_file">
124                 <!ATTLIST File size CDATA "0">
125 ] >
126
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)); ?>" />
129         <Folders>
130 <?php
131                 for ($i = 0; $i < sizeof($folders); $i++) {
132 ?>
133                 <Folder name="<?php echo $this->XMLEncode($folders[$i]); ?>" url="<?php echo $this->XMLEncode($this->url($folders[$i])); ?>" />
134 <?php
135                 }
136 ?>
137         </Folders>
138         <Files>
139 <?php
140                 
141                 for ($i = 0; $i < sizeof($files); $i++) {
142                         $size = ceil(@filesize($this->path("{$this->actual_cwd}{$files[$i]}")) / 1024);
143                         
144                         // PHPの割り当てメモリサイズが小さいとき、ファイルサイズが大きいとgetimagesizeが落ちるのでサイズをチェック(2010/8/25)
145                         $width = '';
146                         $height = '';
147                         if ($size <= 1024 * 3){                 // 3Mバイトまで
148                                 $info = getimagesize($this->path("{$this->actual_cwd}{$files[$i]}"));
149                                 if ($info !== false){
150                                         $width = $info[0];
151                                         $height = $info[1];
152                                 }
153                         }
154 ?>
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; ?>" />
156 <?php
157                 }
158 ?>
159         </Files>
160         </Connector>
161 <?php
162         }
163 }
164 ?>