| 147 | | return filesize( $data ); |
|---|
| | 148 | $fileSize = 0; |
|---|
| | 149 | if( file_exists( $data ) ) |
|---|
| | 150 | { |
|---|
| | 151 | if( is_readable( $data ) ) |
|---|
| | 152 | $fileSize = filesize( $data ); |
|---|
| | 153 | } |
|---|
| | 154 | |
|---|
| | 155 | if( isset( $attributes["RETURNFORMAT"] ) && strtolower( $attributes["RETURNFORMAT"] ) == "pretty" ) |
|---|
| | 156 | { |
|---|
| | 157 | if( $fileSize == 0 ) |
|---|
| | 158 | { |
|---|
| | 159 | if( isset( $attributes["IFZERO"] ) ) |
|---|
| | 160 | $fileSize = $attributes["IFZERO"]; |
|---|
| | 161 | else |
|---|
| | 162 | $fileSize = "n/a"; |
|---|
| | 163 | } |
|---|
| | 164 | else |
|---|
| | 165 | { |
|---|
| | 166 | $transform = array( |
|---|
| | 167 | "GByte" => 1024 * 1024 * 1024, |
|---|
| | 168 | "MByte" => 1024 * 1024, |
|---|
| | 169 | "KByte" => 1024, |
|---|
| | 170 | "Byte" => 1 |
|---|
| | 171 | ); |
|---|
| | 172 | foreach( $transform as $title => $div ) |
|---|
| | 173 | { |
|---|
| | 174 | $size = $fileSize / $div; |
|---|
| | 175 | |
|---|
| | 176 | if( $size < 1 ) |
|---|
| | 177 | continue; |
|---|
| | 178 | $fileSize = number_format( $size, 2, ",", "." ) . " " . $title; |
|---|
| | 179 | break; |
|---|
| | 180 | } |
|---|
| | 181 | } |
|---|
| | 182 | } |
|---|
| | 183 | |
|---|
| | 184 | return $fileSize; |
|---|
| 175 | | $data = basename( $data ); |
|---|
| 176 | | |
|---|
| 177 | | if( $newdir ) |
|---|
| 178 | | $dirname = $dirname."/".$newdir; |
|---|
| 179 | | |
|---|
| 180 | | // open dir and read all files |
|---|
| 181 | | $dir = dir( $dirname ); |
|---|
| 182 | | $files = array(); |
|---|
| 183 | | while( $entry = $dir->read() ) |
|---|
| 184 | | { |
|---|
| 185 | | if( $entry != "." && $entry != ".." ) |
|---|
| 186 | | { |
|---|
| 187 | | $p = 0; |
|---|
| 188 | | similar_text( $data, $entry, $p ); |
|---|
| 189 | | if( $p > $percentage ) |
|---|
| 190 | | array_push( $files, $entry ); |
|---|
| 191 | | } |
|---|
| 192 | | } |
|---|
| 193 | | $dir->close(); |
|---|
| 194 | | |
|---|
| 195 | | if( empty( $files ) ) |
|---|
| 196 | | return false; |
|---|
| 197 | | |
|---|
| 198 | | $data = "<filelist>"; |
|---|
| 199 | | for( $i=0; $i<count( $files ); $i++ ) |
|---|
| 200 | | $data .= "<file url=\"".$files[$i]."\"/>"; |
|---|
| 201 | | $data .= "</filelist>"; |
|---|
| | 216 | { |
|---|
| | 217 | return "<noFiles/>"; |
|---|
| | 218 | } |
|---|
| | 228 | |
|---|
| | 229 | /** |
|---|
| | 230 | * search for similar files |
|---|
| | 231 | * |
|---|
| | 232 | * @access private |
|---|
| | 233 | * @param string $filename |
|---|
| | 234 | * @param string $baseDir |
|---|
| | 235 | * @param integer $percentage |
|---|
| | 236 | * @return array $files |
|---|
| | 237 | */ |
|---|
| | 238 | function getSimilarFiles( $filename, $baseDir, $percentage ) |
|---|
| | 239 | { |
|---|
| | 240 | // extract dirname and filename |
|---|
| | 241 | $newdir = dirname( $filename ); |
|---|
| | 242 | |
|---|
| | 243 | if( $newdir == $filename ) |
|---|
| | 244 | $newdir = false; |
|---|
| | 245 | else |
|---|
| | 246 | $filename = basename( $filename ); |
|---|
| | 247 | |
|---|
| | 248 | |
|---|
| | 249 | if( !empty( $newdir ) ) |
|---|
| | 250 | { |
|---|
| | 251 | $dirname = $baseDir."/".$newdir; |
|---|
| | 252 | if( !file_exists( $dirname ) || !is_dir( $dirname ) ) |
|---|
| | 253 | { |
|---|
| | 254 | $dirname = $baseDir; |
|---|
| | 255 | $newdir = ""; |
|---|
| | 256 | } |
|---|
| | 257 | } |
|---|
| | 258 | |
|---|
| | 259 | $files = $this->recursiveSearch( $filename, $dirname, $percentage, $newdir ); |
|---|
| | 260 | return $files; |
|---|
| | 261 | } |
|---|
| | 262 | |
|---|
| | 263 | /** |
|---|
| | 264 | * recursively search a directory |
|---|
| | 265 | * |
|---|
| | 266 | * @access private |
|---|
| | 267 | * @param string $filename |
|---|
| | 268 | * @param string $baseDir |
|---|
| | 269 | * @param integer $percentage |
|---|
| | 270 | * @param string $path |
|---|
| | 271 | * @return array $files |
|---|
| | 272 | */ |
|---|
| | 273 | function recursiveSearch( $filename, $dirname, $percentage, $path = "" ) |
|---|
| | 274 | { |
|---|
| | 275 | // open dir and read all files |
|---|
| | 276 | if( !$dir = @dir( $dirname ) ) |
|---|
| | 277 | return false; |
|---|
| | 278 | |
|---|
| | 279 | $files = array(); |
|---|
| | 280 | |
|---|
| | 281 | while( $entry = $dir->read() ) |
|---|
| | 282 | { |
|---|
| | 283 | if( $entry == "." || $entry == ".." ) |
|---|
| | 284 | continue; |
|---|
| | 285 | |
|---|
| | 286 | if( is_dir( $dirname."/".$entry ) ) |
|---|
| | 287 | { |
|---|
| | 288 | // scan the subdir |
|---|
| | 289 | $tmp = $this->recursiveSearch( $filename, $dirname."/".$entry, $percentage, $path.$entry ); |
|---|
| | 290 | |
|---|
| | 291 | if( !is_array( $tmp ) ) |
|---|
| | 292 | continue; |
|---|
| | 293 | foreach( $tmp as $file ) |
|---|
| | 294 | array_push( $files, $file ); |
|---|
| | 295 | } |
|---|
| | 296 | elseif( is_file( $dirname."/".$entry ) ) |
|---|
| | 297 | { |
|---|
| | 298 | $p = 0; |
|---|
| | 299 | similar_text( $filename, $entry, $p ); |
|---|
| | 300 | if( $p > $percentage ) |
|---|
| | 301 | array_push( $files, $path . "/" . $entry ); |
|---|
| | 302 | } |
|---|
| | 303 | } |
|---|
| | 304 | $dir->close(); |
|---|
| | 305 | |
|---|
| | 306 | if( empty( $files ) ) |
|---|
| | 307 | return false; |
|---|
| | 308 | |
|---|
| | 309 | return $files; |
|---|
| | 310 | } |
|---|