aliroFileManager Class Reference

List of all members.

Public Member Functions

 deleteFile ($file)
 deleteDirectory ($dir)
 setPermissions ($fileSysObject, $mode=null)
 makeDirectory ($dir)
 createDirectory ($dir, $onlyCheck=false)
 simpleCopy ($from, $to)
 forceCopy ($from, $to, $reportErrors=false)
 lightCopy ($from, $to)
 acceptCopy ($to)
 mosPathName ($p_path, $p_addtrailingslash=true)
 mosChmod ($path)
 mosChmodRecursive ($path, $filemode=NULL, $dirmode=NULL)
 makeUploadSafe ($name, $useRealName=false)
 extractArchive ($filename, $extractDir='')
 makeTemp ()

Static Public Member Functions

static getInstance ()

Private Member Functions

 __construct ()
 __clone ()
 containingDirectory ($dir)

Static Private Attributes

static $instance = __CLASS__


Detailed Description

Definition at line 49 of file aliroFileManager.php.


Constructor & Destructor Documentation

aliroFileManager::__construct (  )  [private]

Definition at line 53 of file aliroFileManager.php.

00053                                     {
00054         // Enforce singleton
00055     }


Member Function Documentation

aliroFileManager::__clone (  )  [private]

Definition at line 57 of file aliroFileManager.php.

00057                                 {
00058         // Enforce singleton
00059     }

static aliroFileManager::getInstance (  )  [static]

aliroFileManager::deleteFile ( file  ) 

Definition at line 65 of file aliroFileManager.php.

Referenced by forceCopy().

00065                                 {
00066         if (file_exists($file)) {
00067             @chmod($file, 0644);
00068             return unlink($file);
00069         }
00070         return true;
00071     }

aliroFileManager::deleteDirectory ( dir  ) 

Definition at line 73 of file aliroFileManager.php.

00073                                     {
00074         if (file_exists($dir)) {
00075             if (is_dir($dir)) {
00076                 @chmod($dir, 0755);
00077                 return rmdir($dir);
00078             }
00079             return false;
00080         }
00081         return true;
00082     }

aliroFileManager::setPermissions ( fileSysObject,
mode = null 
)

Definition at line 84 of file aliroFileManager.php.

References aliroCore::get().

Referenced by makeDirectory(), makeUploadSafe(), and simpleCopy().

00084                                                          {
00085         $result = true;
00086         if (file_exists($fileSysObject))  {
00087             if ($mode);
00088             elseif (is_dir($fileSysObject)) $mode = octdec(aliroCore::get('mosConfig_dirperms'));
00089             else $mode = octdec(aliroCore::get('mosConfig_fileperms'));
00090             if ($mode) {
00091                 $origmask = @umask(0);
00092                 $result = @chmod($fileSysObject, $mode);
00093                 @umask($origmask);
00094             }
00095         }
00096         return $result;
00097     }

aliroFileManager::makeDirectory ( dir  ) 

Definition at line 99 of file aliroFileManager.php.

References setPermissions().

Referenced by createDirectory().

00099                                   {
00100         $result = @mkdir($dir, 0755);
00101         if ($result) $this->setPermissions($dir);
00102         return $result;
00103     }

aliroFileManager::createDirectory ( dir,
onlyCheck = false 
)

Definition at line 105 of file aliroFileManager.php.

References containingDirectory(), list, and makeDirectory().

Referenced by acceptCopy(), forceCopy(), lightCopy(), and makeTemp().

00105                                                              {
00106         if (file_exists($dir)) {
00107             if (is_dir($dir) AND is_writable($dir)) return true;
00108             else return false;
00109         }
00110         list($upDirectory, $count) = $this->containingDirectory($dir);
00111         if ($count > 1 AND !file_exists($upDirectory) AND !($result = $this->createDirectory($upDirectory, $onlyCheck))) return false;
00112         if ($onlyCheck AND isset($result)) return true;
00113         if (!is_dir($upDirectory) OR !is_writable($upDirectory)) return false;
00114         if ($onlyCheck) return true;
00115         else return $this->makeDirectory($dir);
00116     }

aliroFileManager::containingDirectory ( dir  )  [private]

Definition at line 118 of file aliroFileManager.php.

Referenced by createDirectory().

00118                                                 {
00119         $dirs = preg_split('*[/|\\\]*', $dir);
00120         for ($i = count($dirs)-1; $i >= 0; $i--) {
00121             $text = trim($dirs[$i]);
00122             unset($dirs[$i]);
00123             if ($text) break;
00124         }
00125         $result2 = count($dirs);
00126         $result1 = implode('/',$dirs).($result2 > 1 ? '' : '/');
00127         return array($result1, $result2);
00128     }

aliroFileManager::simpleCopy ( from,
to 
)

Definition at line 130 of file aliroFileManager.php.

References setPermissions().

Referenced by forceCopy(), and lightCopy().

00130                                      {
00131         if (@copy($from, $to)) {
00132             $this->setPermissions($to);
00133             return true;
00134         }
00135         else return false;
00136     }

aliroFileManager::forceCopy ( from,
to,
reportErrors = false 
)

Definition at line 138 of file aliroFileManager.php.

References createDirectory(), deleteFile(), aliroRequest::getInstance(), simpleCopy(), and T_().

00138                                                          {
00139         if (!file_exists($from)) {
00140             if ($reportErrors) aliroRequest::getInstance()->setErrorMessage (sprintf(T_('Copy requested for %s, but source file not found'), $from), _ALIRO_ERROR_WARN);
00141             return false;
00142         }
00143         $todir = dirname($to);
00144         if (!file_exists($todir)) $this->createDirectory($todir);
00145         if (!file_exists($todir)) {
00146             if ($reportErrors) aliroRequest::getInstance()->setErrorMessage (sprintf(T_('Copy requested for %s, but could not create destination directory'), $from), _ALIRO_ERROR_WARN);
00147             return false;
00148         }
00149         $name = basename($from);
00150         $this->deleteFile($to.$name);
00151         if ($this->simpleCopy ($from, $to)) return true;
00152         elseif ($reportErrors) aliroRequest::getInstance()->setErrorMessage (sprintf(T_('Copy requested for %s, source found but could not copy to %s'), $from, $to), _ALIRO_ERROR_WARN);
00153         return false;
00154     }

aliroFileManager::lightCopy ( from,
to 
)

Definition at line 156 of file aliroFileManager.php.

References createDirectory(), and simpleCopy().

00156                                     {
00157         $name = basename($from);
00158         if (file_exists($to.$name)) return false;
00159         $todir = dirname($to);
00160         if (!file_exists($todir)) $this->createDirectory($todir);
00161         if (!file_exists($todir)) return false;
00162         return $this->simpleCopy ($from, $to);
00163     }

aliroFileManager::acceptCopy ( to  ) 

Definition at line 165 of file aliroFileManager.php.

References createDirectory().

00165                               {
00166         $todir = dirname($to);
00167         return $this->createDirectory($todir, true);
00168     }

aliroFileManager::mosPathName ( p_path,
p_addtrailingslash = true 
)

Definition at line 173 of file aliroFileManager.php.

00173                                                             {
00174         if (substr(PHP_OS, 0, 3) == 'WIN')  {
00175             $retval = str_replace( '/', '\\', $p_path );
00176             if ($p_addtrailingslash AND substr( $retval, -1 ) != '\\') $retval .= '\\';
00177             // Remove double \\
00178             $retval = str_replace( '\\\\', '\\', $retval );
00179         }
00180         else {
00181             $retval = str_replace( '\\', '/', $p_path );
00182             if ($p_addtrailingslash AND substr( $retval, -1 ) != '/') $retval .= '/';
00183             // Remove double //
00184             $retval = str_replace('//','/',$retval);
00185         }
00186         return $retval;
00187     }

aliroFileManager::mosChmod ( path  ) 

Chmods files and directories recursively to mos global permissions. Available from 4.5.2 up.

Parameters:
path The starting file or directory (no trailing slash)
filemode Integer value to chmod files. NULL = dont chmod files.
dirmode Integer value to chmod directories. NULL = dont chmod directories.
Returns:
TRUE=all succeeded FALSE=one or more chmods failed

Definition at line 196 of file aliroFileManager.php.

References aliroCore::get(), and mosChmodRecursive().

00197     {
00198         $filemode = octdec(aliroCore::get('mosConfig_fileperms'));
00199         $dirmode = octdec(aliroCore::get('mosConfig_dirperms'));
00200         if ($filemode OR $dirmode) return $this->mosChmodRecursive($path, $filemode, $dirmode);
00201         return true;
00202     } // mosChmod

aliroFileManager::mosChmodRecursive ( path,
filemode = NULL,
dirmode = NULL 
)

Chmods files and directories recursively to given permissions. Available from 4.5.2 up.

Parameters:
path The starting file or directory (no trailing slash)
filemode Integer value to chmod files. NULL = dont chmod files.
dirmode Integer value to chmod directories. NULL = dont chmod directories.
Returns:
TRUE=all succeeded FALSE=one or more chmods failed

Definition at line 211 of file aliroFileManager.php.

Referenced by extractArchive(), and mosChmod().

00211                                                                      {
00212         $ret = true;
00213         if (is_dir($path)) {
00214             $topdir = new aliroDirectory($path);
00215             $files = $topdir->listFiles ('', 'file', true, true);
00216             $dirs = $topdir->listFiles ('', 'dir', true, true);
00217         }
00218         else {
00219             $files = array($path);
00220             $dirs = array();
00221         }
00222         if (isset($filemode)) foreach ($files as $file) $ret = @chmod($file, $filemode) ? $ret : false;
00223         if (isset($dirmode)) foreach ($dirs as $dir) $ret = @chmod($dir, $dirmode) ? $ret : false;
00224         return $ret;
00225     }

aliroFileManager::makeUploadSafe ( name,
useRealName = false 
)

Definition at line 227 of file aliroFileManager.php.

References makeTemp(), and setPermissions().

00227                                                                {
00228         $tempdir = $this->makeTemp();
00229         $files = array();
00230         $tempfiles = (array) $_FILES[$name]['tmp_name'];
00231         $filenames = (array) $_FILES[$name]['name'];
00232         foreach ($tempfiles as $key=>$temp) {
00233             if ($useRealName) $filename = $filenames[$key];
00234             else $filename = basename($temp);
00235             if (move_uploaded_file($temp, $tempdir.$filename)) {
00236                 $files[$filenames[$key]] = $tempdir.$filename;
00237                 $this->setPermissions($tempdir.$filename);
00238             }
00239         }
00240         return $files;
00241     }

aliroFileManager::extractArchive ( filename,
extractDir = '' 
)

Definition at line 243 of file aliroFileManager.php.

References aliroRequest::getInstance(), makeTemp(), mosChmodRecursive(), and T_().

00243                                                                {
00244         if (!$extractDir) $extractDir = $this->makeTemp();
00245         if (preg_match( '/\.zip$/i', $filename )) {
00246             $zipfile = new PclZip( $filename );
00247             $ret = $zipfile->extract( PCLZIP_OPT_PATH, $extractDir );
00248             if($ret == 0) {
00249                 aliroRequest::getInstance()->setErrorMessage (sprintf(T_('Installer unrecoverable ZIP error %s in %s'), $zipfile->errorName(true), $filename), _ALIRO_ERROR_FATAL);
00250                 return false;
00251             }
00252         } else {
00253             error_reporting(E_ALL);
00254             $archive = new Archive_Tar( $filename );
00255             $archive->setErrorHandling( PEAR_ERROR_PRINT );
00256 
00257             if (!$archive->extractModify( $extractDir, '' )) {
00258                 aliroRequest::getInstance()->setErrorMessage (sprintf(T_('Installer unrecoverable TAR error in %s'), $filename), _ALIRO_ERROR_FATAL);
00259                 return false;
00260             }
00261             error_reporting(E_ALL|E_STRICT);
00262         }
00263         $this->mosChmodRecursive($extractDir);
00264         return $extractDir;
00265     }

aliroFileManager::makeTemp (  ) 

Definition at line 267 of file aliroFileManager.php.

References createDirectory(), and criticalInfo::getInstance().

Referenced by extractArchive(), and makeUploadSafe().

00267                                 {
00268         $tempDir = criticalInfo::getInstance()->class_base.'/media/'.uniqid('_aliro_temp_').'/';
00269         $this->createDirectory($tempDir);
00270         return $tempDir;
00271     }


Member Data Documentation

aliroFileManager::$instance = __CLASS__ [static, private]

Definition at line 51 of file aliroFileManager.php.


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

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