예제 #1
0
 public static function Convert($from, $format = '')
 {
     //first, get the original file
     $myFile = FSI::getFile($from);
     $myFile->checkReadPermission();
     if ($myFile instanceof EyeLocalFile) {
         $fileNameOriginal = $from;
     } else {
         $myRealFile = $myFile->getRealFile();
         $fileNameOriginal = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     }
     $hash = md5(md5_file($fileNameOriginal) . '/' . $format);
     $to = 'home:///';
     //then, check the destination file
     $myFileDest = FSI::getFile($to);
     $myFileDest->checkWritePermission();
     $myRealFile = $myFileDest->getRealFile();
     $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     $conversionCache = $fileNameDestination . '/.office/' . $hash . '/' . $hash;
     if (!file_exists($fileNameDestination . '/.office/')) {
         mkdir($fileNameDestination . '/.office/');
     }
     if (file_exists($conversionCache)) {
         return $conversionCache;
     } else {
         if (!is_dir($fileNameDestination . '/.office/' . $hash)) {
             mkdir($fileNameDestination . '/.office/' . $hash);
         }
         $fileNameDestination = $conversionCache;
     }
     $fileNameReturn = $fileNameDestination;
     /*
      * If isset format do conversion, otherwise just copy original file to 
      */
     if ($format != '') {
         $fileNameOriginal = escapeshellarg($fileNameOriginal);
         $fileNameDestination = escapeshellarg($fileNameDestination);
         $format = escapeshellarg($format);
         //some legacy applications do not use the filter writer_pdf_Export, just pdf
         if ($format == 'pdf') {
             $format = 'writer_pdf_Export';
         }
         if (!@fsockopen('127.0.0.1', '2002', $errno, $errstr, 3)) {
             shell_exec('nohup soffice "-accept=socket,host=localhost,port=2002;urp;" >/dev/null 2>/dev/null &');
             //shell_exec with soffice forked to avoid soffice to be killed
             //at the end of the php execution, cannot be synchronous.
             sleep(4);
         }
         $cmd = 'python ' . EYE_ROOT . '/' . SYSTEM_DIR . '/' . FRAMEWORKS_DIR . '/Converter/ooo2any.py --extension eyeos --format ' . $format;
         $cmd .= ' --destination ' . $fileNameDestination . ' ' . $fileNameOriginal;
         shell_exec('LANG=en_US.utf-8;' . $cmd);
     } else {
         // Just copy file to new destination
         copy($fileNameOriginal, $fileNameDestination);
     }
     return $fileNameReturn;
 }
예제 #2
0
 public static function download($path)
 {
     $myFile = FSI::getFile($path);
     $myFile->checkReadPermission();
     $len = $myFile->getSize();
     $filename = $myFile->getName();
     $mimetype = $myFile->getMimeType();
     $filename = str_replace("\n", "", $filename);
     $filename = str_replace("\r", "", $filename);
     header('Content-Length: ' . $len);
     header('Content-Type: ' . $mimetype);
     header('Accept-Ranges: bytes');
     header('X-Pad: avoid browser bug');
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     $currentProc = ProcManager::getInstance()->getCurrentProcess();
     ProcManager::getInstance()->kill($currentProc);
     $myRealFile = $myFile->getRealFile();
     $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     session_write_close();
     readFile($fileNameDestination);
     exit;
 }
예제 #3
0
 /**
  * Get the first image of a video
  * @param Array $params = (
  *		path => string				Path of the file
  * )
  * @return fill the response with the image
  */
 public static function getVideoPoster($params)
 {
     if ($params === null || !is_array($params)) {
         throw new EyeInvalidArgumentException('Missing or invalid $params');
     }
     if (!isset($params['path']) || !is_string($params['path'])) {
         throw new EyeInvalidArgumentException('Missing or invalid $params[\'path\']');
     }
     $myFile = FSI::getFile($params['path']);
     if (method_exists($myFile, 'getRealFile')) {
         $fileName = AdvancedPathLib::getPhpLocalHackPath($myFile->getRealFile()->getAbsolutePath());
     } else {
         $fileName = $params['path'];
     }
     Logger::getLogger('Mobile - files.php')->debug('$fileName: ' . $fileName);
     try {
         $MediaConverter = new MediaConverter();
         $fileName = $MediaConverter->Convert($fileName, 'JPG');
     } catch (Exception $e) {
         Logger::getLogger('Mobile - files.php')->debug('$MediaConverter error: ' . $e);
     }
     $size = filesize($fileName);
     $data = file_get_contents($fileName);
     $response = MMapManager::getCurrentResponse();
     $response->getHeaders()->append('Content-Type: image/jpeg');
     $response->getHeaders()->append('Content-Length: ' . $size);
     $response->getHeaders()->append('Accept-Ranges: bytes');
     //		$response->getHeaders()->append('Expires: 0');
     //		$response->getHeaders()->append('Pragma: public');
     //		$response->getHeaders()->append('Content-Disposition: inline');
     //		$response->getHeaders()->append('Content-Transfer-Encoding: binary');
     //		$response->getHeaders()->append('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     //		$response->getHeaders()->append('X-Pad: avoid browser bug');
     $response->setBody($data);
 }
예제 #4
0
 public static function getFileVersionData($params)
 {
     if (isset($params['cloud']) && isset($_SESSION['access_token_' . $params['cloud'] . '_v2'])) {
         $cloud = $params['cloud'];
         $user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId();
         $id = $params['id'];
         $version = $params['version'];
         $file = FSI::getFile($params['path']);
         $apiManager = new ApiManager();
         $path = AdvancedPathLib::getPhpLocalHackPath($file->getRealFile()->getAbsolutePath());
         $token = $_SESSION['access_token_' . $cloud . '_v2'];
         $resourceUrl = null;
         if (isset($params['resource_url'])) {
             $token = new stdClass();
             $resourceUrl = $params['resource_url'];
             $token->key = $params['access_token_key'];
             $token->secret = $params['access_token_secret'];
         }
         $result = $apiManager->getFileVersionData($cloud, $token, $id, $version, $path, $user, $resourceUrl);
         if ($result) {
             if (isset($result['error']) && $result['error'] == 403) {
                 $denied = self::permissionDeniedCloud($cloud);
                 $result['path'] = $denied['path'];
             }
         }
     } else {
         $result['error'] = -1;
         $result['description'] = "Access token not exists";
     }
     return $result;
 }
예제 #5
0
 public static function getFile($params)
 {
     $hash = utf8_basename($params[0]);
     $num = utf8_basename(intval($params[1]));
     $thubnail = $params[2];
     $to = 'home:///';
     //then, check the destination file
     $myFileDest = FSI::getFile($to);
     $myFileDest->checkWritePermission();
     $myRealFile = $myFileDest->getRealFile();
     $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     header('Content-Type: image/jpeg');
     if (!$thubnail) {
         readfile($fileNameDestination . '/.office/' . $hash . '/' . $hash . '-' . $num . '.jpg');
     } else {
         session_write_close();
         require_once 'system/Frameworks/Applications/Executables/EyeosModules/FileSystemExecModule.php';
         FileSystemExecModule::getScaledImage(array('maxWidth' => '150', 'path' => $fileNameDestination . '/.office/' . $hash . '/' . $hash . '-' . $num . '.jpg'));
     }
     exit;
 }
예제 #6
0
 /**
  * Modify the path of the file to the output folder
  * @param	string	$fileName	original path of the file
  */
 private function CreateOutputPath($fileName)
 {
     if (!isset($fileName) || !is_string($fileName)) {
         throw new EyeInvalidArgumentException('Missing or invalid param $fileName');
     }
     //Home of the user
     $to = 'home:///';
     //then, check the destination file
     $myFileDest = FSI::getFile($to);
     $myFileDest->checkWritePermission();
     $myRealFile = $myFileDest->getRealFile();
     $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     if (!file_exists($fileNameDestination . '/.office/')) {
         mkdir($fileNameDestination . '/.office/');
     }
     if (!file_exists($fileNameDestination . '/.office/.media/')) {
         mkdir($fileNameDestination . '/.office/.media/');
     }
     $this->outputPath = $fileNameDestination . '/.office/.media/';
 }
예제 #7
0
 /**
  * Return the scaled version of image.
  *
  * @param Array $params = (
  *		maxHeight => integer,		Max Height of output image
  *		maxWidth => integer,		Max Width of output image
  *		path => string				Path of input image
  * )
  */
 public static function getScaledImage($params)
 {
     if ($params === null || !is_array($params)) {
         throw new EyeInvalidArgumentException('Missing or invalid $params');
     }
     if (!isset($params['path']) || !is_string($params['path'])) {
         throw new EyeInvalidArgumentException('Missing or invalid $params[\'path\']');
     }
     $path = $params['path'];
     $maxHeight = isset($params['maxHeight']) ? intval($params['maxHeight']) : null;
     $maxWidth = isset($params['maxWidth']) ? intval($params['maxWidth']) : null;
     $response = MMapManager::getCurrentResponse();
     $myFile = FSI::getFile($params['path']);
     if (method_exists($myFile, 'getRealFile')) {
         $fileName = AdvancedPathLib::getPhpLocalHackPath($myFile->getRealFile()->getAbsolutePath());
     } else {
         $fileName = $params['path'];
     }
     $info = GetImageSize($fileName);
     $width = $info[0];
     $height = $info[1];
     $mime = $info['mime'];
     //Calculate new dimensions
     $newDimensions = self::calculateDimensions(array('height' => $height, 'width' => $width, 'maxHeight' => $maxHeight, 'maxWidth' => $maxWidth));
     $newHeight = $newDimensions['height'];
     $newWidth = $newDimensions['width'];
     if ($newHeight == $height && $newWidth == $width) {
         //No resize is necessary
         $imageData = $myFile->getContents();
     } else {
         // What sort of image?
         $type = substr(strrchr($mime, '/'), 1);
         switch ($type) {
             case 'jpeg':
                 $image_create_func = 'ImageCreateFromJPEG';
                 $image_save_func = 'ImageJPEG';
                 $new_image_ext = 'jpg';
                 break;
             case 'png':
                 $image_create_func = 'ImageCreateFromPNG';
                 $image_save_func = 'ImagePNG';
                 $new_image_ext = 'png';
                 break;
             case 'bmp':
                 $image_create_func = 'ImageCreateFromBMP';
                 $image_save_func = 'ImageBMP';
                 $new_image_ext = 'bmp';
                 break;
             case 'gif':
                 $image_create_func = 'ImageCreateFromGIF';
                 $image_save_func = 'ImageGIF';
                 $new_image_ext = 'gif';
                 break;
             case 'vnd.wap.wbmp':
                 $image_create_func = 'ImageCreateFromWBMP';
                 $image_save_func = 'ImageWBMP';
                 $new_image_ext = 'bmp';
                 break;
             case 'xbm':
                 $image_create_func = 'ImageCreateFromXBM';
                 $image_save_func = 'ImageXBM';
                 $new_image_ext = 'xbm';
                 break;
             default:
                 $image_create_func = 'ImageCreateFromJPEG';
                 $image_save_func = 'ImageJPEG';
                 $new_image_ext = 'jpg';
         }
         // Create blank image with new dimensions
         $imageData = ImageCreateTrueColor($newWidth, $newHeight);
         $originalImage = $image_create_func($fileName);
         ImageCopyResampled($imageData, $originalImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
         $image_save_func($imageData);
     }
     $imagevariable = ob_get_contents();
     ob_end_clean();
     header('Content-Type:' . $mime);
     header('Content-Length: ' . strlen($imagevariable));
     header('Accept-Ranges: bytes');
     header('X-Pad: avoid browser bug');
     echo $imagevariable;
     exit;
 }
 private function downloadFile($filePath, $request, $response)
 {
     $myFile = FSI::getFile($filePath);
     $len = $myFile->getSize();
     $filename = $myFile->getName();
     $mimetype = $myFile->getMimeType();
     $filename = str_replace("\n", "", $filename);
     $filename = str_replace("\r", "", $filename);
     header('Content-Length: ' . $len);
     header('Content-Type: ' . $mimetype);
     header('Accept-Ranges: bytes');
     header('X-Pad: avoid browser bug');
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     $myRealFile = $myFile->getRealFile();
     $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     session_write_close();
     readFile($fileNameDestination);
     exit;
 }
예제 #9
0
 public static function viewTempImg($params)
 {
     $parts = explode('_', $params);
     $filepath = 'home:///';
     $myFile = FSI::getFile($filepath);
     $myFile->checkWritePermission();
     $myRealFile = $myFile->getRealFile();
     $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     $fileNameDestination .= '/.office/' . utf8_basename($parts[0]) . '/' . utf8_basename($params);
     $info = pathinfo($fileNameDestination);
     $myExt = strtolower($info['extension']);
     $response = MMapManager::getCurrentResponse();
     header('Content-Type: image/' . $myExt);
     header('Content-Length: ' . filesize($fileNameDestination));
     header('Accept-Ranges: bytes');
     header('X-Pad: avoid browser bug');
     readfile($fileNameDestination);
     exit;
 }
예제 #10
0
 public function testGetPhpLocalHackPath()
 {
     if (AdvancedPathLib::getCurrentOS() == AdvancedPathLib::OS_WINDOWS) {
         $this->assertEquals('C:/path/to/myFile.ext', AdvancedPathLib::getPhpLocalHackPath('file://C:/path/to/myFile.ext'));
         $this->assertEquals('C:/path/to/myDir/', AdvancedPathLib::getPhpLocalHackPath('file://C:/path/to/myDir/'));
         $this->assertEquals('C:/path/to/myFile.ext', AdvancedPathLib::getPhpLocalHackPath('file://localhost/C:/path/to/myFile.ext'));
     } else {
         $this->assertEquals('/path/to/myFile.ext', AdvancedPathLib::getPhpLocalHackPath('file:///path/to/myFile.ext'));
         $this->assertEquals('/path/to/myFile.ext', AdvancedPathLib::getPhpLocalHackPath('file://path/to/myFile.ext'));
         $this->assertEquals('/path/to/myFile.ext', AdvancedPathLib::getPhpLocalHackPath('file://localhost/path/to/myFile.ext'));
         $this->assertEquals('/path/to/myDir', AdvancedPathLib::getPhpLocalHackPath('file://localhost/path/to/myDir/'));
     }
 }
예제 #11
0
 public static function fileExport(array $params)
 {
     $destinationFile = $params[0];
     $originalFile = $params[1];
     $format = $params[2];
     if ($format == 'PDF') {
         $extension = 'pdf';
         $format = 'writer_pdf_Export';
     } elseif ($format == 'Doc') {
         $extension = 'doc';
         $format = 'MS Word 97';
     } elseif ($format == 'Open Office') {
         $extension = 'odt';
         $format = 'writer8';
     } elseif ($format == 'HTML') {
         $extension = 'html';
         $format = 'HTML (StarWriter)';
     } elseif ($format == 'RTF') {
         $extension = 'rtf';
         $format = 'Rich Text Format';
     } elseif ($format == 'TXT') {
         $extension = 'txt';
         $format = 'Text (encoded)';
     }
     $destinationFile .= '.' . $extension;
     $file = FSI::getFile($originalFile);
     $memory = MemoryManager::getInstance();
     $file->checkReadPermission();
     $to = 'home:///';
     //then, check the destination file
     $myFileDest = FSI::getFile($to);
     $myFileDest->checkWritePermission();
     $myRealFile = $myFileDest->getRealFile();
     $partName = '.office/' . uniqid(time()) . '_conversion/';
     $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/' . $partName;
     mkdir($fileNameDestination);
     $myRealFile = $file->getRealFile();
     $originalFile = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     $cmd = 'unzip  -d ' . escapeshellarg($fileNameDestination) . ' ' . escapeshellarg($originalFile);
     shell_exec($cmd);
     $myConverter = new Converter();
     $fileName = $myConverter->Convert($to . $partName . '/document.html', $format);
     shell_exec('rm -rf ' . escapeshellarg($fileNameDestination));
     if (!file_exists($fileName)) {
         return false;
     }
     $content = file_get_contents($fileName);
     $newFile = FSI::getFile($destinationFile);
     $newFile->createNewFile(true);
     $newFile->putContents($content);
     return $destinationFile;
 }
예제 #12
0
 /**
  * @param array Special parameters for FileOutputStream::__construct() (see FileOutputStream constants)
  * @return FileOutputStream
  */
 public function getOutputStream($params = null)
 {
     return new FileOutputStream(AdvancedPathLib::getPhpLocalHackPath($this->getPath()), $params);
 }
예제 #13
0
 public static function refreshContent($params)
 {
     $user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId();
     $file = FSI::getFile($params['path']);
     $path = AdvancedPathLib::getPhpLocalHackPath($file->getRealFile()->getAbsolutePath());
     $id = $params['id'];
     $cloud = $params['cloud'];
     $apiManager = new ApiManager();
     $token = $_SESSION['access_token_' . $cloud . '_v2'];
     $resourceUrl = null;
     if (isset($params['resource_url'])) {
         $token = new stdClass();
         $token->key = $params['access_token_key'];
         $token->secret = $params['access_token_secret'];
         $resourceUrl = $params['resource_url'];
     }
     $result = $apiManager->downloadMetadata($token, $id, $path, $user, false, $cloud, $resourceUrl);
     $content = self::fileOpen($params['path']);
     $result['content'] = $content[0];
     return $result;
 }
예제 #14
0
    public static function getPDF($params)
    {
        $path = $params['path'];
        $myFile = FSI::getFile($path);
        $myRealFile = $myFile->getRealFile();
        $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
        $checknum = $params['checknum'];
        //echo  htmlentities("http://192.168.56.101/index.php?message=getContentFile&checknum=$checknum&params[0]=$fileNameDestination");
        ?>
        <html>
            <body>
                <iframe src="<?php 
        echo htmlentities("index.php?message=getContentFile&checknum={$checknum}&params[0]={$fileNameDestination}");
        ?>
" style="width:868px; height:550px;" frameborder="0"></iframe>
            </body>
        </html>
        <?php 
        exit;
    }
예제 #15
0
 /**
  * @return bool TRUE if the file has been successfully renamed.
  * @throws EyeIOException
  */
 public function renameTo($newName)
 {
     if (!$this->exists()) {
         throw new EyeFileNotFoundException($this->path . ' does not exist.');
     }
     if (!$newName) {
         return true;
     }
     $urlParts = AdvancedPathLib::parse_url($this->path);
     $urlParts['path'] = AdvancedPathLib::unifyPath(dirname($urlParts['path']) . '/' . $newName);
     $newPath = AdvancedPathLib::buildURL($urlParts);
     if ($this->exists()) {
         $path = AdvancedPathLib::getPhpLocalHackPath($this->path);
         $newPath = AdvancedPathLib::getPhpLocalHackPath($newPath);
         try {
             if (rename($path, $newPath)) {
                 $this->path = $newPath;
                 return true;
             }
             throw new EyeIOException('Unable to rename file ' . $this->path . '.');
         } catch (EyeErrorException $e) {
             throw new EyeIOException('Unable to rename file ' . $this->path . '.', 0, $e);
         }
     } else {
         $this->path = $newPath;
         return true;
     }
 }
예제 #16
0
 /**
  * TODO: Will need to be moved/merged to/with FileSystemExecModule
  */
 public static function createNewFile($params)
 {
     $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
     $settings = MetaManager::getInstance()->retrieveMeta($currentUser);
     $newFile = FSI::getFile($params[0]);
     $name = explode(".", $newFile->getName());
     $extension = (string) $name[count($name) - 1];
     if ($newFile->exists()) {
         $name = explode(".", $newFile->getName());
         $path = str_replace($newFile->getName(), '', $newFile->getPath());
         $extension = (string) $name[count($name) - 1];
         $theName = substr($newFile->getName(), 0, strlen($newFile->getName()) - strlen($extension) - 1);
         $futureName = array($theName, 1);
         $nameForCheck = implode(' ', $futureName);
         $nameForCheck .= '.' . $extension;
         $newFile = FSI::getFile($path . "/" . $nameForCheck);
         while ($newFile->exists()) {
             $futureName[1] += 1;
             $nameForCheck = implode(' ', $futureName);
             $nameForCheck .= '.' . $extension;
             $newFile = FSI::getFile($path . "/" . $nameForCheck);
         }
     }
     if ($extension == 'edoc') {
         $rand = md5(uniqid(time()));
         mkdir('/tmp/' . $rand);
         $uniqid = uniqid();
         shell_exec('touch /tmp/' . $rand . '/document.html');
         file_put_contents('/tmp/' . $rand . '/duid', $uniqid);
         $myFile = FSI::getFile($params[0] . '_tmp');
         $myFile->checkWritePermission();
         $myRealFile = $myFile->getRealFile();
         $fileNameOriginal = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
         //this is REALLY annoying to be forced to do this, but zip command line util is a mess
         $oldDir = getcwd();
         chdir('/tmp/' . $rand);
         $cmd = 'zip -r ' . escapeshellarg($fileNameOriginal) . ' ./';
         shell_exec($cmd);
         //we return into the normal directory...this is ugly
         chdir($oldDir);
         AdvancedPathLib::rmdirs('/tmp/' . $rand);
         // creating a fake file trought FSI, so we can have our nice xml :)
         $newFile->createNewFile(true);
         $newFile->putContents($myFile->getContents());
         unlink($fileNameOriginal);
         // FIXME!!!!!
     } else {
         $newFile->createNewFile();
     }
     return self::getFileInfo($newFile, $settings);
 }
예제 #17
0
 public static function createFile($params)
 {
     $number = 1;
     $newfile = FSI::getFile($params[0]);
     $info = pathinfo($params[0]);
     while ($newfile->exists()) {
         $newfile = FSI::getFile($info['dirname'] . '/' . $info['filename'] . ' ' . $number . '.' . $info['extension']);
         $number++;
     }
     if (strtoupper($info['extension']) == 'EDOC') {
         $rand = md5(uniqid(time()));
         mkdir('/tmp/' . $rand);
         $uniqid = uniqid();
         shell_exec('touch /tmp/' . $rand . '/document.html');
         file_put_contents('/tmp/' . $rand . '/duid', $uniqid);
         $myFile = FSI::getFile($params[0] . '_tmp');
         $myFile->checkWritePermission();
         $myRealFile = $myFile->getRealFile();
         $fileNameOriginal = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
         //this is REALLY annoying to be forced to do this, but zip command line util is a mess
         $oldDir = getcwd();
         chdir('/tmp/' . $rand);
         $cmd = 'zip -r ' . escapeshellarg($fileNameOriginal) . ' ./';
         shell_exec($cmd);
         //we return into the normal directory...this is ugly
         chdir($oldDir);
         AdvancedPathLib::rmdirs('/tmp/' . $rand);
         // creating a fake file trought FSI, so we can have our nice xml :)
         $newfile->createNewFile(true);
         $newfile->putContents($myFile->getContents());
         unlink($fileNameOriginal);
         // FIXME!!!!!
     } else {
         $newfile->createNewFile();
     }
     $return = array('class' => get_class($newfile), 'type' => $newfile->isDirectory() ? 'folder' : ($newfile->isLink() ? 'link' : 'file'), 'extension' => utf8_strtoupper($newfile->getExtension()), 'size' => $newfile->isDirectory() ? 0 : $newfile->getSize(), 'permissions' => $newfile->getPermissions(false), 'owner' => $newfile->getOwner(), 'group' => $newfile->getGroup(), 'absolutepath' => $newfile->getAbsolutePath(), 'meta' => $newfile->getMeta()->getAll());
     if ($return['extension'] == 'LNK') {
         $return['content'] = $newfile->getContents();
     }
     $return['name'] = $newfile->getName() != '/' ? $newfile->getName() : $return['absolutepath'];
     if ($newfile instanceof EyeosAbstractVirtualFile) {
         $return['virtual'] = 'true';
     } else {
         $return['virtual'] = 'false';
     }
     return $return;
 }
예제 #18
0
 public function fileWritten(FileEvent $e)
 {
     //Logger::getLogger('sebas')->error('MetadataWritten:' . $e->getSource()->getPath());
     $apiManager = new ApiManager();
     $path = $e->getSource()->getPath();
     $user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
     $userName = $user->getName();
     $cloud = $this->isCloud($path, $userName);
     $resourceUrl = null;
     if ($cloud->isCloud) {
         $pathU1db = substr($path, strlen($cloud->path));
         $lenfinal = strrpos($pathU1db, $e->getSource()->getName());
         $posfinal = $lenfinal > 1 ? $lenfinal - strlen($pathU1db) - 1 : $lenfinal - strlen($pathU1db);
         $pathParent = substr($pathU1db, 0, $posfinal);
         $folder = NULL;
         if ($pathParent !== '/') {
             $pos = strrpos($pathParent, '/');
             $folder = substr($pathParent, $pos + 1);
             $pathParent = substr($pathParent, 0, $pos + 1);
         }
         $parentId = false;
         if ($folder !== NULL) {
             $path = $pathParent . $folder . '/';
             $lista = new stdClass();
             $lista->cloud = $cloud->name;
             $lista->path = $pathParent;
             $lista->filename = $folder;
             $lista->user_eyeos = $user->getId();
             $u1db = json_decode($apiManager->callProcessU1db('parent', $lista));
             if ($u1db !== NULL && count($u1db) > 0) {
                 $parentId = $u1db[0]->id;
                 if (isset($u1db[0]->resource_url)) {
                     $resourceUrl = new stdClass();
                     $resourceUrl->resource_url = $u1db[0]->resource_url;
                     $resourceUrl->token = new stdClass();
                     $resourceUrl->token->key = $u1db[0]->access_token_key;
                     $resourceUrl->token->secret = $u1db[0]->access_token_secret;
                     if ($parentId === 'null') {
                         $parentId = 0;
                     }
                 }
             }
         } else {
             $parentId = '0';
             $path = $pathParent;
         }
         if ($parentId !== false) {
             $pathAbsolute = AdvancedPathLib::getPhpLocalHackPath($e->getSource()->getRealFile()->getAbsolutePath());
             $token = $_SESSION['access_token_' . $cloud->name . '_v2'];
             if ($resourceUrl) {
                 $token = $resourceUrl->token;
                 $resourceUrl = $resourceUrl->resource_url;
             }
             $result = $apiManager->createMetadata($cloud->name, $token, $user->getId(), true, $e->getSource()->getName(), $parentId, $path, $pathAbsolute, $resourceUrl);
             if ($result['status'] == 'OK') {
                 $params = array($e->getSource()->getParentPath(), $e->getSource()->getPath());
                 $message = new ClientBusMessage('file', 'refreshStackSync', $params);
                 ClientMessageBusController::getInstance()->queueMessage($message);
             } else {
                 if ($result['error'] == 403) {
                     $path = $this->cleanCloud($cloud->name, $user);
                     $params = array($path, $cloud->name);
                     $message = new ClientBusMessage('file', 'permissionDenied', $params);
                     ClientMessageBusController::getInstance()->queueMessage($message);
                 }
             }
         }
     }
 }