Changeset 5560
- Timestamp:
- 10/17/07 10:51:04 (2 years ago)
- Files:
-
- trunk/lib/util/sfFinder.class.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/util/sfFinder.class.php
r5110 r5560 48 48 protected $relative = false; 49 49 protected $follow_link = false; 50 protected $sort = false; 50 51 51 52 /** … … 247 248 248 249 return $this->discard($ignores)->prune($ignores); 250 } 251 252 /** 253 * Returns files and directories ordered by name 254 * 255 * @return object current sfFinder object 256 */ 257 public function sort_by_name() 258 { 259 $this->sort = 'name'; 260 261 return $this; 262 } 263 264 /** 265 * Returns files and directories ordered by type (directories before files), then by name 266 * 267 * @return object current sfFinder object 268 */ 269 public function sort_by_type() 270 { 271 $this->sort = 'type'; 272 273 return $this; 249 274 } 250 275 … … 352 377 } 353 378 379 if ($this->sort == 'name') 380 { 381 sort($files); 382 } 383 354 384 return array_unique($files); 355 385 } … … 368 398 369 399 $files = array(); 370 400 $temp_files = array(); 401 $temp_folders = array(); 371 402 if (is_dir($dir)) 372 403 { … … 383 414 384 415 if (is_dir($current_entry)) 416 { 417 if ($this->sort == 'type') 418 { 419 $temp_folders[$entryname] = $current_entry; 420 } 421 else 422 { 423 if (($this->type == 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->exec_ok($dir, $entryname)) 424 { 425 $files[] = realpath($current_entry); 426 } 427 428 if (!$this->is_pruned($dir, $entryname)) 429 { 430 $files = array_merge($files, $this->search_in($current_entry, $depth + 1)); 431 } 432 } 433 } 434 else 435 { 436 if (($this->type != 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->size_ok($dir, $entryname) && $this->exec_ok($dir, $entryname)) 437 { 438 if ($this->sort == 'type') 439 { 440 $temp_files[] = realpath($current_entry); 441 } 442 else 443 { 444 $files[] = realpath($current_entry); 445 } 446 } 447 } 448 } 449 450 if ($this->sort == 'type') 451 { 452 ksort($temp_folders); 453 foreach($temp_folders as $entryname => $current_entry) 385 454 { 386 455 if (($this->type == 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->exec_ok($dir, $entryname)) … … 394 463 } 395 464 } 396 else 397 { 398 if (($this->type != 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->size_ok($dir, $entryname) && $this->exec_ok($dir, $entryname)) 399 { 400 $files[] = realpath($current_entry); 401 } 402 } 403 } 465 466 sort($temp_files); 467 $files = array_merge($files, $temp_files); 468 } 469 404 470 closedir($current_dir); 405 471 }

