/** * 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; }
/** * 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); }
/** * 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); } } }