fixPath() public method

Append a / to the path if required.
public fixPath ( string $path ) : string
$path string the path
return string path with trailing /
 /**
  * Get all the files and directories of a relative path.
  * @param string $path relative path to be base path.
  * @return array of file and path information.
  * <code>array(0=>array('relative'=>'fullpath',...), 1=>array('filename'=>fileinfo array(),...)</code>
  * fileinfo array: <code>array('url'=>'full url', 
  *                       'relative'=>'relative to base', 
  *                        'fullpath'=>'full file path', 
  *                        'image'=>imageInfo array() false if not image,
  *                        'stat' => filestat)</code>
  */
 function getFiles($path)
 {
     $files = array();
     $dirs = array();
     if ($this->isValidBase() == false) {
         return array($files, $dirs);
     }
     $path = Files::fixPath($path);
     $base = Files::fixPath($this->getImagesDir());
     $fullpath = Files::makePath($base, $path);
     $d = @dir($fullpath);
     while (false !== ($entry = $d->read())) {
         //not a dot file or directory
         if (substr($entry, 0, 1) != '.') {
             if (is_dir($fullpath . $entry) && $this->isThumbDir($entry) == false) {
                 $relative = Files::fixPath($path . $entry);
                 $full = Files::fixPath($fullpath . $entry);
                 $count = $this->countFiles($full);
                 $dirs[$relative] = array('fullpath' => $full, 'entry' => $entry, 'count' => $count);
             } else {
                 if (is_file($fullpath . $entry) && $this->isThumb($entry) == false && $this->isTmpFile($entry) == false) {
                     $img = $this->getImageInfo($fullpath . $entry);
                     if (!(!is_array($img) && $this->config['validate_images'])) {
                         $file['url'] = Files::makePath($this->config['base_url'], $path) . $entry;
                         $file['relative'] = $path . $entry;
                         $file['fullpath'] = $fullpath . $entry;
                         $file['image'] = $img;
                         $file['stat'] = stat($fullpath . $entry);
                         $files[$entry] = $file;
                     }
                 }
             }
         }
     }
     $d->close();
     ksort($dirs);
     ksort($files);
     return array($dirs, $files);
 }
Beispiel #2
0
 /**
  * Get all the files and directories of a relative path.
  *
  * @param string $path relative path to be base path.
  *
  * @return array of file and path information.
  * <code>
  *   array(0 => array('relative'=>'fullpath',...),
  *		   1 => array('filename'=>fileinfo array(),...)
  * </code>
  * fileinfo array:
  * <code>
  *   array('url'=>'full url',
  *         'relative'=>'relative to base',
  *         'fullpath'=>'full file path',
  *         'image'=>imageInfo array() false if not image,
  *         'stat' => filestat)
  * </code>
  */
 function getFiles($path, $articleId)
 {
     $files = array();
     $dirs = array();
     if ($this->isValidBase() == false) {
         return array($files, $dirs);
     }
     $path = Files::fixPath($path);
     $base = Files::fixPath($this->getBaseDir());
     $fullpath = Files::makePath($base, $path);
     $articleImages = ArticleImage::GetImagesByArticleNumber($articleId);
     foreach ($articleImages as $articleImage) {
         $image = $articleImage->getImage();
         $img = $this->getImageInfo($image->getImageStorageLocation());
         if (is_array($img) || !$this->config['validate_images']) {
             $file['template_id'] = $articleImage->getTemplateId();
             $file['url'] = $image->getImageUrl();
             $file['image'] = $img;
             $file['image_object'] = $image;
             $file['alt'] = htmlspecialchars($image->getDescription(), ENT_QUOTES);
             $files[$articleImage->getTemplateId()] = $file;
         }
     }
     ksort($dirs);
     ksort($files);
     return array($dirs, $files);
 }
 /**
  * Delete any tmp image files.
  * @param string $path the full path 
  * where the clean should take place.
  */
 function cleanUp($path, $file)
 {
     $path = Files::fixPath($path);
     if (!is_dir($path)) {
         return false;
     }
     $d = @dir($path);
     $tmp = $this->manager->getTmpPrefix();
     $tmpLen = strlen($tmp);
     $prefix = $tmp . $this->_uid;
     $len = strlen($prefix);
     while (false !== ($entry = $d->read())) {
         //echo $entry."<br>";
         if (is_file($path . $entry) && $this->manager->isTmpFile($entry)) {
             if (substr($entry, 0, $len) == $prefix && $entry != $file) {
                 Files::delFile($path . $entry);
             } else {
                 if (substr($entry, 0, $tmpLen) == $tmp && $entry != $file) {
                     if (filemtime($path . $entry) + $this->lapse_time < time()) {
                         Files::delFile($path . $entry);
                     }
                 }
             }
         }
     }
     $d->close();
 }
Beispiel #4
0
 /**
  * Similar to makePath, but the second parameter
  * is not only a path, it may contain say a file ending.
  * @param string $pathA the leading path
  * @param string $pathB the ending path with file
  * @return string combined file path.
  */
 function makeFile($pathA, $pathB)
 {
     $pathA = Files::fixPath($pathA);
     if (substr($pathB, 0, 1) == '/') {
         $pathB = substr($pathB, 1);
     }
     return $pathA . $pathB;
 }
Beispiel #5
0
 function _checkIMLibrary($method)
 {
     //ImageMagick goes throught 1 single executable
     if (is_file(Files::fixPath(IMAGE_TRANSFORM_LIB_PATH) . 'convert')) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Get all the files and directories of a relative path.
  * @param string $path relative path to be base path.
  * @return array of file and path information.
  * <code>array(0=>array('relative'=>'fullpath',...), 1=>array('filename'=>fileinfo array(),...)</code>
  * fileinfo array: <code>array('url'=>'full url', 
  *                       'relative'=>'relative to base', 
  *                        'fullpath'=>'full file path', 
  *                        'image'=>imageInfo array() false if not image,
  *                        'stat' => filestat)</code>
  */
 function getFiles($path)
 {
     $files = array();
     $dirs = array();
     $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions'];
     if ($this->isValidBase() == false) {
         return array($files, $dirs);
     }
     $path = Files::fixPath($path);
     $base = Files::fixPath($this->getImagesDir());
     $fullpath = Files::makePath($base, $path);
     $d = @dir($fullpath);
     while (false !== ($entry = $d->read())) {
         //not a dot file or directory
         if (substr($entry, 0, 1) != '.') {
             if (is_dir($fullpath . $entry) && $this->isThumbDir($entry) == false) {
                 $relative = Files::fixPath($path . $entry);
                 $full = Files::fixPath($fullpath . $entry);
                 $count = $this->countFiles($full);
                 $dirs[$relative] = array('fullpath' => $full, 'entry' => $entry, 'count' => $count, 'stat' => stat($fullpath . $entry));
             } else {
                 if (is_file($fullpath . $entry) && $this->isThumb($entry) == false && $this->isTmpFile($entry) == false) {
                     $afruext = strtolower(substr(strrchr($entry, "."), 1));
                     if (in_array($afruext, $valid_extensions)) {
                         $file['url'] = Files::makePath($this->config['base_url'], $path) . $entry;
                         $file['relative'] = $path . $entry;
                         $file['fullpath'] = $fullpath . $entry;
                         $img = $this->getImageInfo($fullpath . $entry);
                         if (!is_array($img)) {
                             $img[0] = $img[1] = 0;
                         }
                         $file['image'] = $img;
                         $file['stat'] = stat($fullpath . $entry);
                         $file['ext'] = $afruext;
                         $files[$entry] = $file;
                     }
                 }
             }
         }
     }
     $d->close();
     ksort($dirs);
     ksort($files);
     return array($dirs, $files);
 }