Skip to content
Snippets Groups Projects
Select Git revision
  • a74d8523b5abdf3aa0ece072b472b927d22b0eb8
  • master default protected
  • server_prod
  • server_dev
  • next_version
  • laurent-change.log
  • HEAD
  • 2019.03.00
  • 2019.02.07
  • 2019.02.06
  • 2019.02.05
  • 2019.02.04
  • 2019.02.03
  • 2019.02.02
  • 2019.02.01
  • 2019.02.00
  • 2019.01.02
  • 2019.01.01
  • 2019.01.00
  • 2018.04.04
  • 2018.04.03
  • 2018.04.02
  • 2018.04.01
  • 2018.04.00
24 results

Local_files.class.inc

Blame
  • Forked from Open source / vMap
    Source project has a limited visibility.
    Local_files.class.inc 4.46 KiB
    <?php
    
    require_once ("Files.interface.inc");
    
    class Local_files implements Files{
    
        var $oProperties;
    
        function __construct($properties){
            $this->oProperties = $properties;
        }
    
        /**
         *This method return the extension of a file.
         *@param string $sFilePath File's path.
         *@return string|boolean hash sha1 of file content or false if the file doesn't exist.
         */
        public function getFileEtag($sFilePath){
            if(file_exists($sFilePath)){
                return sha1(file_get_contents($sFilePath), false);
            } else {
                return false;
            }
    
        }
    
        /**
         *verify if a file exists.
         *@param string $sFilePath File's path.
         *@return boolean true if file exists, false else.
         */
        public function file_exists ($sFilePath){
            return file_exists($sFilePath);
        }
        /**
         *Write a string in a file.
         *@param string $sFilePath File's path.
         *@param string $sData string to write in this file.
         *@param integer $iFlags flags to write in file (http://php.net/manual/fr/function.file-put-contents.php) Default : 0.
         *@param resource $mContext result de stream_context_create().
         *@return integer|boolean number of byte written, or false if the process encounter an error.
         */
        public function file_put_contents ($sFilePath, $sData, $iFlags = 0, $mContext = null){
            return file_put_contents($sFilePath, $sData, $iFlags, $mContext);
        }
        public function file_get_contents ($sFilePath, $bUseIncludePath = FALSE, $mContext = null, $iOffset = 0, $iMaxLen = -1){
            if ($iMaxLen == -1){
                return file_get_contents ($sFilePath, $bUseIncludePath, null, $iOffset);
            } else {
                return file_get_contents ($sFilePath, $bUseIncludePath, null, $iOffset, $iMaxLen);
            }
        }
        public function file_get_contents_with_etag ($sFilePath, $sEtag ,$bUseIncludePath = FALSE, $mContext = null, $iOffset = 0, $iMaxLen = -1){
            $sProcessedEtag = $this->getFileEtag($sFilePath);
            if ($sEtag == $sProcessedEtag){
                return $this->file_get_contents($sFilePath, $bUseIncludePath, $mContext, $iOffset, $iMaxLen);
            } else {
                return false;
            }
        }
        public function copy ($sSourceFilePath, $sDestFilePath){
            return copy ($sSourceFilePath, $sDestFilePath);
        }
        public function filesize ($sFilePath){
            return filesize($sFilePath);
        }
        public function readfile ($sFilePath, $bUseIncludePath = FALSE, $mContext = null){
            return readfile($sFilePath, $bUseIncludePath, $mContext);
        }
        public function rename ($sSourceFilePath, $sDestFilePath, $mContext = null){
            if(empty($mContext)){
                return rename($sSourceFilePath, $sDestFilePath);
            }else{
                return rename($sSourceFilePath, $sDestFilePath, $mContext);
            }
        }
        public function unlink ($sFilePath, $mContext = null){
            if(empty($mContext)){
                return unlink($sFilePath);
            } else {
                return unlink($sFilePath, $mContext);
            }
        }
        public function filemtime ($sFilePath){
            return filemtime($sFilePath);
        }
    
        public function filemtime_formated($sFilePath, $sFormat){
            return date ($sFormat, $this->filemtime($sFilePath));
        }
        public function getFileInfos ($sFilePath){
            $iFileSize = $this->filesize($sFilePath);
    
            $sFileSize = $iFileSize . " octets";
            if($iFileSize > 1024){
                if($iFileSize > 1024*1024){
                    if($iFileSize > 1024*1024*1024){
                        $sFileSize = "-";
                    } else {
                        $sFileSize = (ceil($iFileSize/(1024*1024))) . "Mo";
                    }
                }else{
                    $sFileSize = (ceil($iFileSize/1024)) . "Ko";
                }
            }
    
            $aFileName = explode("/", $sFilePath);
    
            return array("filename"=>$aFileName[count($aFileName) - 1], "size"=>$sFileSize, "lastModification"=> $this->filemtime_formated ($sFilePath, "d/m/Y H:i:s"), "href" => $this->getProxyPassUrl($sFilePath));
        }
        public function getProxyPassUrl ($sFilePath){
            $date = new DateTime();
            $sDataUrl = $this->oProperties['web_server_name'] . "/rest/vitis/file_downloader?key=[KEY]&eTag=[ETAG]&d=" . $date->getTimestamp();
    
            $sFileUrl = str_replace("[KEY]", str_replace($this->oProperties['ws_data_dir'], "ws_data" , $sFilePath), $sDataUrl);
            $sFileUrl = str_replace("[ETAG]", sha1(file_get_contents($sFilePath), false), $sFileUrl);
    
            return $sFileUrl;
        }
    }
    
    
    ?>