Ejemplo n.º 1
0
 /**
  * Gets the file from the Zibo include paths
  * @param string $path Path, in the webdirectory, of the file
  * @return null|zibo\library\filesystem\File
  */
 private function getFile($path)
 {
     $zibo = Zibo::getInstance();
     $plainPath = new File(Zibo::DIRECTORY_WEB . File::DIRECTORY_SEPARATOR . $path);
     $file = $zibo->getFile($plainPath->getPath());
     if ($file) {
         return $file;
     }
     $encodedPath = new File($plainPath->getParent()->getPath(), urlencode($plainPath->getName()));
     return $zibo->getFile($encodedPath->getPath());
 }
Ejemplo n.º 2
0
 /**
  * During construction, you can specify a path to a file and a file name. This
  * will prep the File instance for an upload. If you do not wish
  * to upload a file, simply instantiate this class without any attributes.
  *
  * If you want to fill this class with the details of a specific file, then
  * get_file_info and it will be imported into its own Box_Client_File class.
  *
  * @param zibo\library\filesystem\File $file Provide a file if you want to upload a directory or a file
  * @return null
  */
 public function __construct(File $file = null)
 {
     $this->attributes = array();
     $this->tags = array();
     if ($file) {
         if ($file->isDirectory) {
             $this->attribute('localpath', $file->getPath());
         } else {
             $this->attribute('localpath', $file->getParent()->getPath());
             $this->attribute('filename', $file->getName());
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Compresses a file into the archive
  * @param ZipArchive $archive ZipArchive object of PHP
  * @param zibo\library\filesystem\File $file The file to compress in the archive
  * @param zibo\library\filesystem\File $prefix The path for the file in the archive
  * @return null
  */
 private function compressFile(ZipArchive $archive, File $file, File $prefix = null)
 {
     if ($prefix == null) {
         $prefix = new File($file->getName());
     } else {
         $prefix = new File($prefix, $file->getName());
     }
     $children = null;
     if ($file->exists()) {
         if ($file->isDirectory()) {
             $children = $file->read();
         } else {
             $archive->addFile($file->getPath(), $prefix->getPath());
             return;
         }
     }
     if (empty($children)) {
         $archive->addEmptyDir($prefix->getPath());
     } else {
         foreach ($children as $file) {
             $this->compressFile($archive, $file, $prefix);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Get the parent of the provided file
  *
  * If you provide a path like /var/www/yoursite, the parent will be /var/www
  * @param File $file
  * @return File the parent of the file
  */
 public function getParent(File $file)
 {
     $path = $file->getPath();
     if (strpos($path, File::DIRECTORY_SEPARATOR) === false) {
         $parent = new File('.');
         return new File($this->getAbsolutePath($parent));
     }
     $name = $file->getName();
     $nameLength = strlen($name);
     $parent = substr($path, 0, ($nameLength + 1) * -1);
     if (!$parent) {
         return new File(File::DIRECTORY_SEPARATOR);
     }
     return new File($parent);
 }
Ejemplo n.º 5
0
 /**
  * Uploads a file to the FTP server
  * @param zibo\library\filesystem\File $localFile The file to upload
  * @param string $remoteFile The destination file on the FTP server
  * @param integer $mode ASCII or binary (constants FTP_ASCII or FTP_BINARY)
  * @return null
  * @throws zibo\library\ftp\exception\FtpException when not connected to the FTP server
  * @throws zibo\library\ftp\exception\FtpException when the file could not be uploaded
  */
 public function put(File $localFile, $remoteFile, $mode = null)
 {
     $this->checkConnected();
     if (!$localFile->exists()) {
         throw new FtpException('Could not upload ' . $localFile->getName() . ': Source does not exist');
     } elseif ($localFile->isDirectory()) {
         throw new FtpException('Could not upload ' . $localFile->getName() . ': Source is a directory');
     }
     if (!$mode) {
         $mode = FTP_BINARY;
     }
     if (!@ftp_put($this->handle, $remoteFile, $localFile->getAbsolutePath(), $mode)) {
         throw new FtpException('Could not upload ' . $localFile->getName() . ': A problem occured while uploading');
     }
 }
Ejemplo n.º 6
0
 /**
  * Compresses a directory into the archive
  * @param \Phar $archive Phar object of PHP
  * @param zibo\library\filesystem\File $dir The directory to compress in the archive
  * @param zibo\library\filesystem\File $prefix The path for the directory in the archive
  * @return null
  */
 private function compressDirectory(PhpPhar $archive, File $dir, File $prefix)
 {
     $children = $dir->read();
     if (empty($children)) {
         $archive->addEmptyDir(new File($prefix->getPath(), $dir->getName()));
     } else {
         foreach ($children as $file) {
             $this->compressFile($archive, $file, $prefix);
         }
     }
 }
 /**
  * Action to process files and directories from the clipboard to the current path
  * @param string $action The method to invoke (copy or move)
  * @param array $files Array with the files to copy
  * @return null
  */
 private function clipboardFileAction($action, array $files = null)
 {
     $this->response->setRedirect($this->getReferer());
     if ($files == null) {
         return;
     }
     $root = $this->fileBrowser->getRoot();
     $baseDestination = new File($root, $this->path);
     foreach ($files as $file) {
         $file = new File($file);
         $path = $file->getPath();
         if (!array_key_exists($path, $this->clipboard)) {
             continue;
         }
         $source = new File($root, $file);
         $destination = new File($baseDestination, $file->getName());
         if (!$destination->isWritable()) {
             $this->addError(self::TRANSLATION_ERROR_WRITABLE, array('path' => $this->fileBrowser->getPath($destination)));
             continue;
         }
         $source->{$action}($destination);
         unset($this->clipboard[$path]);
     }
 }
Ejemplo n.º 8
0
 /**
  * @dataProvider providerGetName
  */
 public function testGetName($expected, $value)
 {
     $file = new File($value);
     $this->assertEquals($expected, $file->getName());
 }
Ejemplo n.º 9
0
 /**
  * Copies a file into the modules directory
  * @param zibo\library\filesystem\File $file
  * @return zibo\library\filesystem\File the destination file
  */
 private function copyFile(File $file)
 {
     if ($file->getExtension() == 'phar' && class_exists(self::CLASS_ARCHIVE_FACTORY)) {
         $module = new File(Zibo::DIRECTORY_MODULES, substr($file->getName(), 0, -5));
         $archive = ArchiveFactory::getInstance()->getArchive($file);
         $archive->uncompress($module);
     } else {
         $module = new File(Zibo::DIRECTORY_MODULES, $file->getName());
         if ($module->getAbsolutePath() != $file->getAbsolutePath()) {
             $file->copy($module);
         }
     }
     return $module;
 }
Ejemplo n.º 10
0
 /**
  * Gets the HTML for a file
  * @param zibo\library\filesystem\File $file The file to get the HTML for
  * @return string The HTML of the file
  */
 private function getFileHtml(File $file)
 {
     $html = $this->getNameHtml($file->getName(), self::CLASS_FILE, $this->fileAction);
     $html .= '<div class="info">';
     $html .= '<span class="size">' . $this->translator->translate(self::TRANSLATION_SIZE) . ': ' . $this->formatter->formatSize($this->fileBrowser->getSize($file)) . '</span>';
     $html .= '</div>';
     return $html;
 }