コード例 #1
0
ファイル: FileMessage.class.php プロジェクト: Superbeest/Core
 /**
  * Creates a new Message object with a file.
  * @param \System\IO\File The file to send in the message
  * @param string The target filename. This is a fullpath
  * @param string The host. This can be local or remote, or an IPv4
  * @param int The port to use
  * @param string The username to connect to the local SSH server
  * @param string The password to connect to the local SSH server
  */
 public function __construct_6(\System\IO\File $file, $targetFilename, $host, $port, $username, $password)
 {
     $this->setType(\System\System\Interaction\MessageType::TYPE_SYSTEM);
     $this->setMessage('file');
     $contents = @base64_encode($file->getContents());
     $this->setParams(array('file' => $contents, 'atime' => $file->getLastAccessTime(), 'mtime' => $file->getModifiedTime(), 'host' => $host, 'port' => $port, 'username' => $username, 'password' => $password, 'target' => $targetFilename));
 }
コード例 #2
0
ファイル: Hash.class.php プロジェクト: Superbeest/Core
 /**
  * Adds the given file to the hash pool. The hash will be calculated over the total hash pool.
  * @param \System\IO\File The file to include in the hashing
  */
 public final function addFile(\System\IO\File $file)
 {
     if ($this->hash) {
         if ($file->exists()) {
             hash_update_file($this->hash, $file->getFullPath());
         } else {
             throw new \System\Error\Exception\FileNotFoundException('The given file does not exists: ' . $file->getFilename());
         }
     } else {
         throw new \System\Error\Exception\InvalidMethodException('This method is called after finalizing the hash');
     }
 }
コード例 #3
0
 /**
  * Adds an attachment to the Email message.
  * @param \System\IO\File The file object to attach
  */
 public final function addAttachment(\System\IO\File $file)
 {
     if ($file->exists()) {
         $this->attachments[] = $file;
     } else {
         throw new \System\Error\Exception\FileNotFoundException('The given email attachment file ' . $file->getFilename() . ' does not exists');
     }
 }
コード例 #4
0
ファイル: BasePage.page.php プロジェクト: Superbeest/Core
 /**
  * Adds a JS file to be loaded upon clientside rendering. Leave the localpath empty for remote files
  * @param \SimpleXMLElement The XML root
  * @param string The (full)path to the local JS file
  * @param string The (full)path to the remote file
  * @param int The \System\Web\BasePage\Page\InclusionLocation for inclusion location
  */
 public function addJSFile(\SimpleXMLElement $xml, $localFile, $remoteFile, $location = \System\Web\BasePage\Page\InclusionLocation::LOCATION_HEAD)
 {
     if (!isset($xml->jsfiles)) {
         $xml->addChild('jsfiles');
     }
     $jsFiles = $xml->jsfiles;
     $jsFile = $jsFiles->addChild('jsfile');
     if ($localFile) {
         $file = new \System\IO\File($localFile);
         if (MINIFY_ENABLE && mb_strpos($file->getFilename(), self::JS_MIN_EXTENSION) === false && mb_strpos($file->getFilename(), self::JS_MIN_PACKED) === false) {
             $localMinFile = $file->getPath() . basename($file->getFilename(), self::JS_EXTENSION) . self::JS_MIN_EXTENSION;
             if (!file_exists($localMinFile)) {
                 $file = \System\IO\File::writeContents($localMinFile, \System\Web\Minify\JS\Minify::minify($file->getContents()));
             } else {
                 $file = new \System\IO\File($localMinFile);
             }
             $remoteFile = str_ireplace(self::JS_EXTENSION, self::JS_MIN_EXTENSION, $remoteFile);
         }
         $jsFile->addChild('filesize', $file->getFileSizeInBytes());
     }
     $jsFile->addChild('name', $remoteFile);
     $jsFile->addChild('location', $location);
 }
コード例 #5
0
 /**
  * Gets the url name of the file. This will be in the following form:
  * if $file = 'abc.jpg', and container = 'myRandomContainer', then
  * retrun value is 'abc.myran.jpg'
  * @param File The file to use
  * @param string The container to use
  * @return string The name of the url file. This excludes base paths.
  */
 public static function getURLFile(\System\IO\File $file, $container)
 {
     $filename = $file->getFilename();
     $extension = $file->getExtension();
     $filename = mb_substr($filename, 0, -mb_strlen($extension));
     $containerNameUsage = self::getContainerNameParts($container);
     $filename .= $containerNameUsage . '.' . $file->getExtension();
     return $filename;
 }
コード例 #6
0
 /**
  * Transfer the file to its new location by copying it.
  * @param \System\IO\File The sourcefile.
  * @return bool True on success, false otherwise
  */
 public final function transferFile(\System\IO\File $file)
 {
     $target = \System\IO\Directory::getPath($this->targetFolder . $file->getFilename());
     return \System\IO\File::writeContents($target, $file->getContents()) instanceof \System\IO\File;
 }
コード例 #7
0
ファイル: FTP.class.php プロジェクト: Superbeest/Core
 /**
  * Transfer the file to its new location by copying it.
  * @param \System\IO\File The sourcefile.
  * @return bool True on success, false otherwise
  */
 public final function transferFile(\System\IO\File $file)
 {
     return $this->putBlocking($file->getFilename(), $file->getFullPath());
 }
コード例 #8
0
 /**
  * Handles the receiving of remote files and places them on the correct location. Listens to the EVENT_RECEIVE_FILE message
  * @param OnInteractionEvent The event to listen to
  */
 public static final function receiveFile(\System\System\Interaction\Event\OnInteractionEvent $event)
 {
     $msg = $event->getMessage();
     if ($msg->getType() == \System\System\Interaction\MessageType::TYPE_SYSTEM && $msg->getMessage() == SystemInteractionEventEvent::EVENT_RECEIVE_FILE && $msg instanceof \System\System\Interaction\FileMessage) {
         $params = $msg->getParams();
         $targetFile = getcwd() . '/' . $params['target'];
         $tempFileName = PATH_TEMP . uniqid('sshtransfer');
         $file = \System\IO\File::writeContents($tempFileName, $msg->getFileData());
         $file->touch($params['mtime'], $params['atime']);
         $transfer = new \System\IO\SSHFileTransfer($params['host'], $params['port'], $params['username'], $params['password'], $targetFile);
         if ($transfer->transferFile($file)) {
             $response = new \System\System\Interaction\Response($msg, $targetFile . ' (' . $file->getFileSizeInBytes() . 'b)');
             $file->delete();
             $event->addResponse($response);
         }
     }
 }