aliroDirectory Class Reference

List of all members.

Public Member Functions

 __construct ($path)
 getPath ()
 listAll ($type='file', $recurse=false, $fullpath=false)
 soleDir ()
 deleteAll ()
 deleteFiles ($keepstandard=true)
 createFresh ()
 createIfNeeded ()
 listFiles ($pattern='', $type='file', $recurse=false, $fullpath=false)
 getSize ()
 zip ($zipname)

Private Attributes

 $path = ''


Detailed Description

Definition at line 275 of file aliroFileManager.php.


Constructor & Destructor Documentation

aliroDirectory::__construct ( path  ) 

Definition at line 278 of file aliroFileManager.php.

References $path.

00278                                         {
00279         $path = str_replace('\\', '/', $path);
00280         $this->path = ('/' == substr($path,-1)) ? $path : $path.'/';
00281     }


Member Function Documentation

aliroDirectory::getPath (  ) 

Definition at line 283 of file aliroFileManager.php.

00283                                {
00284         return $this->path;
00285     }

aliroDirectory::listAll ( type = 'file',
recurse = false,
fullpath = false 
)

Definition at line 287 of file aliroFileManager.php.

Referenced by deleteAll(), deleteFiles(), listFiles(), and zip().

00287                                                                             {
00288         $results = array();
00289         if ($dir = @opendir($this->path)) {
00290             while ($file = readdir($dir)) {
00291                 if ($file == '.' OR $file == '..') continue;
00292                 if (is_dir($this->path.$file)) {
00293                     if ($recurse) {
00294                         $subdir = new aliroDirectory($this->path.$file);
00295                         $results = array_merge($results, $subdir->listAll($type, $recurse, $fullpath));
00296                         unset($subdir);
00297                     }
00298                     if ($type == 'file') continue;
00299                 }
00300                 elseif ($type == 'dir') continue;
00301                 if ($fullpath) $results[] = $this->path.$file;
00302                 else $results[] = $file;
00303             }
00304             closedir($dir);
00305         }
00306         return $results;
00307     }

aliroDirectory::soleDir (  ) 

Definition at line 309 of file aliroFileManager.php.

00309                                {
00310         $found = '';
00311         if ($dir = @opendir($this->path)) {
00312             while ($file = readdir($dir)) {
00313                 if ($file == '.' OR $file == '..') continue;
00314                 if (is_dir($this->path.$file)) {
00315                     if ($found) return '';
00316                     else $found = $file;
00317                 }
00318                 else return '';
00319             }
00320             closedir($dir);
00321         }
00322         return $found;
00323     }

aliroDirectory::deleteAll (  ) 

Definition at line 325 of file aliroFileManager.php.

References deleteFiles(), aliroFileManager::getInstance(), and listAll().

Referenced by createFresh().

00325                                  {
00326         if (!file_exists($this->path)) return;
00327         $subdirs = $this->listAll ('dir', false, true);
00328         foreach ($subdirs as $subdir) {
00329             $subdirectory = new aliroDirectory($subdir);
00330             $subdirectory->deleteAll();
00331             unset($subdirectory);
00332         }
00333         $this->deleteFiles(false);
00334         aliroFileManager::getInstance()->deleteDirectory($this->path);
00335     }

aliroDirectory::deleteFiles ( keepstandard = true  ) 

Definition at line 337 of file aliroFileManager.php.

References aliroFileManager::getInstance(), and listAll().

Referenced by deleteAll().

00337                                                      {
00338         $filemanager = aliroFileManager::getInstance();
00339         $files = $this->listAll ('file', false, true);
00340         foreach ($files as $file) {
00341             $filename = basename($file);
00342             if (!$keepstandard OR ('index.html' != $filename AND '.' != $filename[0])) $filemanager->deleteFile($file);
00343         }
00344     }

aliroDirectory::createFresh (  ) 

Definition at line 346 of file aliroFileManager.php.

References deleteAll(), and aliroFileManager::getInstance().

00346                                    {
00347         $this->deleteAll();
00348         $filemanager = aliroFileManager::getInstance();
00349         $filemanager->createDirectory($this->path);
00350         return true;
00351     }

aliroDirectory::createIfNeeded (  ) 

Definition at line 353 of file aliroFileManager.php.

References aliroFileManager::getInstance().

00353                                       {
00354         if (!file_exists($this->path)) {
00355             $filemanager = aliroFileManager::getInstance();
00356             $filemanager->createDirectory($this->path);
00357         }
00358     }

aliroDirectory::listFiles ( pattern = '',
type = 'file',
recurse = false,
fullpath = false 
)

Definition at line 360 of file aliroFileManager.php.

References listAll().

Referenced by getSize().

00360                                                                                            {
00361         $results = array();
00362         $all = $this->listAll($type, $recurse, $fullpath);
00363         foreach ($all as $file) {
00364             $name = basename($file);
00365             if ($pattern AND !preg_match( "/$pattern/", $name )) continue;
00366             if (($name != 'index.html') AND ($name[0] != '.')) $results[] = $file;
00367         }
00368         return $results;
00369     }

aliroDirectory::getSize (  ) 

Definition at line 371 of file aliroFileManager.php.

References listFiles().

00371                                {
00372         $totalsize = 0;
00373         $files = $this->listFiles();
00374         foreach ($files as $file) $totalsize += filesize($this->path.$file);
00375         return $totalsize;
00376     }

aliroDirectory::zip ( zipname  ) 

Definition at line 378 of file aliroFileManager.php.

References listAll(), and T_().

00378                                    {
00379         $zipfile = $this->path.$zipname;
00380         $files = $this->listAll('file', true, true);
00381         $zip = new ZipArchive();
00382         if (!$zip->open($zipfile, ZIPARCHIVE::CREATE)) trigger_error(T_('Unable to open zip file ').$zipfile);
00383         else foreach ($files as $file) $zip->addFile($file,substr($file,strlen($this->path)));
00384         $zip->close();
00385         return $zipfile;
00386     }


Member Data Documentation

aliroDirectory::$path = '' [private]

Definition at line 276 of file aliroFileManager.php.

Referenced by __construct().


The documentation for this class was generated from the following file:

Generated on Wed May 14 13:01:58 2008 for ALIRO by  doxygen 1.5.5