예제 #1
0
 public static function postAvatar($args)
 {
     \OC_JSON::checkLoggedIn();
     \OC_JSON::callCheck();
     $user = \OC_User::getUser();
     if (isset($_POST['path'])) {
         $path = stripslashes($_POST['path']);
         $view = new \OC\Files\View('/' . $user . '/files');
         $fileInfo = $view->getFileInfo($path);
         if ($fileInfo['encrypted'] === true) {
             $fileName = $view->toTmpFile($path);
         } else {
             $fileName = $view->getLocalFile($path);
         }
     } elseif (!empty($_FILES)) {
         $files = $_FILES['files'];
         if ($files['error'][0] === 0 && is_uploaded_file($files['tmp_name'][0]) && !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0])) {
             \OC\Cache::set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200);
             $view = new \OC\Files\View('/' . $user . '/cache');
             $fileName = $view->getLocalFile('avatar_upload');
             unlink($files['tmp_name'][0]);
         }
     } else {
         $l = new \OC_L10n('core');
         \OC_JSON::error(array("data" => array("message" => $l->t("No image or file provided"))));
         return;
     }
     try {
         $image = new \OC_Image();
         $image->loadFromFile($fileName);
         $image->fixOrientation();
         if ($image->valid()) {
             \OC\Cache::set('tmpavatar', $image->data(), 7200);
             \OC_JSON::error(array("data" => "notsquare"));
         } else {
             $l = new \OC_L10n('core');
             $mimeType = $image->mimeType();
             if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') {
                 \OC_JSON::error(array("data" => array("message" => $l->t("Unknown filetype"))));
             }
             if (!$image->valid()) {
                 \OC_JSON::error(array("data" => array("message" => $l->t("Invalid image"))));
             }
         }
     } catch (\Exception $e) {
         \OC_JSON::error(array("data" => array("message" => $e->getMessage())));
     }
 }
예제 #2
0
 /**
  * @NoAdminRequired
  *
  * @param string $path
  * @return DataResponse
  */
 public function postAvatar($path)
 {
     $userId = $this->userSession->getUser()->getUID();
     $files = $this->request->getUploadedFile('files');
     if (isset($path)) {
         $path = stripslashes($path);
         $view = new \OC\Files\View('/' . $userId . '/files');
         if ($view->filesize($path) > 20 * 1024 * 1024) {
             return new DataResponse(['data' => ['message' => $this->l->t('File is too big')]], Http::STATUS_BAD_REQUEST);
         }
         $fileName = $view->getLocalFile($path);
     } elseif (!is_null($files)) {
         if ($files['error'][0] === 0 && is_uploaded_file($files['tmp_name'][0]) && !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0])) {
             if ($files['size'][0] > 20 * 1024 * 1024) {
                 return new DataResponse(['data' => ['message' => $this->l->t('File is too big')]], Http::STATUS_BAD_REQUEST);
             }
             $this->cache->set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200);
             $view = new \OC\Files\View('/' . $userId . '/cache');
             $fileName = $view->getLocalFile('avatar_upload');
             unlink($files['tmp_name'][0]);
         } else {
             return new DataResponse(['data' => ['message' => $this->l->t('Invalid file provided')]], Http::STATUS_BAD_REQUEST);
         }
     } else {
         //Add imgfile
         return new DataResponse(['data' => ['message' => $this->l->t('No image or file provided')]], Http::STATUS_BAD_REQUEST);
     }
     try {
         $image = new \OC_Image();
         $image->loadFromFile($fileName);
         $image->fixOrientation();
         if ($image->valid()) {
             $mimeType = $image->mimeType();
             if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') {
                 return new DataResponse(['data' => ['message' => $this->l->t('Unknown filetype')]]);
             }
             $this->cache->set('tmpAvatar', $image->data(), 7200);
             return new DataResponse(['data' => 'notsquare']);
         } else {
             return new DataResponse(['data' => ['message' => $this->l->t('Invalid image')]]);
         }
     } catch (\Exception $e) {
         return new DataResponse(['data' => ['message' => $e->getMessage()]]);
     }
 }
예제 #3
0
 /**
  * @brief get a list of all available versions of a file in descending chronological order
  * @param $uid user id from the owner of the file
  * @param $filename file to find versions of, relative to the user files dir
  * @param $count number of versions to return
  * @returns array
  */
 public static function getVersions($uid, $filename, $count = 0)
 {
     if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
         $versions_fileview = new \OC\Files\View('/' . $uid . '/files_versions');
         $versionsName = $versions_fileview->getLocalFile($filename) . '.v';
         $escapedVersionName = preg_replace('/(\\*|\\?|\\[)/', '[$1]', $versionsName);
         $versions = array();
         // fetch for old versions
         $matches = glob($escapedVersionName . '*');
         if (!$matches) {
             return $versions;
         }
         sort($matches);
         $files_view = new \OC\Files\View('/' . $uid . '/files');
         $local_file = $files_view->getLocalFile($filename);
         $local_file_md5 = \md5_file($local_file);
         foreach ($matches as $ma) {
             $parts = explode('.v', $ma);
             $version = end($parts);
             $key = $version . '#' . $filename;
             $versions[$key]['cur'] = 0;
             $versions[$key]['version'] = $version;
             $versions[$key]['path'] = $filename;
             $versions[$key]['size'] = $versions_fileview->filesize($filename . '.v' . $version);
             \md5_file($ma) == $local_file_md5 ? $versions[$key]['fileMatch'] = 1 : ($versions[$key]['fileMatch'] = 0);
         }
         $versions = array_reverse($versions);
         foreach ($versions as $key => $value) {
             // flag the first matched file in array (which will have latest modification date) as current version
             if ($value['fileMatch']) {
                 $value['cur'] = 1;
                 break;
             }
         }
         $versions = array_reverse($versions);
         // only show the newest commits
         if ($count != 0 and count($versions) > $count) {
             $versions = array_slice($versions, count($versions) - $count);
         }
         return $versions;
     } else {
         // if versioning isn't enabled then return an empty array
         return array();
     }
 }
예제 #4
0
 /**
  * find all versions which belong to the file we want to restore
  *
  * @param string $filename name of the file which should be restored
  * @param int $timestamp timestamp when the file was deleted
  */
 private static function getVersionsFromTrash($filename, $timestamp)
 {
     $view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files_trashbin/versions');
     $versionsName = $view->getLocalFile($filename) . '.v';
     $escapedVersionsName = preg_replace('/(\\*|\\?|\\[)/', '[$1]', $versionsName);
     $versions = array();
     if ($timestamp) {
         // fetch for old versions
         $matches = glob($escapedVersionsName . '*.d' . $timestamp);
         $offset = -strlen($timestamp) - 2;
     } else {
         $matches = glob($escapedVersionsName . '*');
     }
     if (is_array($matches)) {
         foreach ($matches as $ma) {
             if ($timestamp) {
                 $parts = explode('.v', substr($ma, 0, $offset));
                 $versions[] = end($parts);
             } else {
                 $parts = explode('.v', $ma);
                 $versions[] = end($parts);
             }
         }
     }
     return $versions;
 }
예제 #5
0
 /**
  * index a file
  *
  * @author Jörn Dreyer <*****@*****.**>
  *
  * @param string $path the path of the file
  *
  * @return bool
  */
 public static function indexFile($path = '', $user = null)
 {
     if (!Filesystem::isValidPath($path)) {
         return;
     }
     if ($path === '') {
         //ignore the empty path element
         return false;
     }
     if (is_null($user)) {
         $view = Filesystem::getView();
         $user = \OCP\User::getUser();
     } else {
         $view = new \OC\Files\View('/' . $user . '/files');
     }
     if (!$view) {
         Util::writeLog('search_lucene', 'could not resolve filesystem view', Util::WARN);
         return false;
     }
     if (!$view->file_exists($path)) {
         Util::writeLog('search_lucene', 'file vanished, ignoring', Util::DEBUG);
         return true;
     }
     $root = $view->getRoot();
     $pk = md5($root . $path);
     // the cache already knows mime and other basic stuff
     $data = $view->getFileInfo($path);
     if (isset($data['mimetype'])) {
         $mimeType = $data['mimetype'];
         // initialize plain lucene document
         $doc = new \Zend_Search_Lucene_Document();
         // index content for local files only
         $localFile = $view->getLocalFile($path);
         if ($localFile) {
             //try to use special lucene document types
             if ('text/plain' === $mimeType) {
                 $body = $view->file_get_contents($path);
                 if ($body != '') {
                     $doc->addField(\Zend_Search_Lucene_Field::UnStored('body', $body));
                 }
             } else {
                 if ('text/html' === $mimeType) {
                     //TODO could be indexed, even if not local
                     $doc = \Zend_Search_Lucene_Document_Html::loadHTML($view->file_get_contents($path));
                 } else {
                     if ('application/pdf' === $mimeType) {
                         $doc = Pdf::loadPdf($view->file_get_contents($path));
                         // commented the mimetype checks, as the zend classes only understand docx and not doc files.
                         // FIXME distinguish doc and docx, xls and xlsx, ppt and pptx, in oc core mimetype helper ...
                         //} else if ('application/msword' === $mimeType) {
                     } else {
                         if (strtolower(substr($data['name'], -5)) === '.docx') {
                             $doc = \Zend_Search_Lucene_Document_Docx::loadDocxFile($localFile);
                             //} else if ('application/msexcel' === $mimeType) {
                         } else {
                             if (strtolower(substr($data['name'], -5)) === '.xlsx') {
                                 $doc = \Zend_Search_Lucene_Document_Xlsx::loadXlsxFile($localFile);
                                 //} else if ('application/mspowerpoint' === $mimeType) {
                             } else {
                                 if (strtolower(substr($data['name'], -5)) === '.pptx') {
                                     $doc = \Zend_Search_Lucene_Document_Pptx::loadPptxFile($localFile);
                                 } else {
                                     if (strtolower(substr($data['name'], -4)) === '.odt') {
                                         $doc = Odt::loadOdtFile($localFile);
                                     } else {
                                         if (strtolower(substr($data['name'], -4)) === '.ods') {
                                             $doc = Ods::loadOdsFile($localFile);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // Store filecache id as unique id to lookup by when deleting
         $doc->addField(\Zend_Search_Lucene_Field::Keyword('pk', $pk));
         // Store filename
         $doc->addField(\Zend_Search_Lucene_Field::Text('filename', $data['name'], 'UTF-8'));
         // Store document path to identify it in the search results
         $doc->addField(\Zend_Search_Lucene_Field::Text('path', $path, 'UTF-8'));
         $doc->addField(\Zend_Search_Lucene_Field::unIndexed('size', $data['size']));
         $doc->addField(\Zend_Search_Lucene_Field::unIndexed('mimetype', $mimeType));
         //self::extractMetadata($doc, $path, $view, $mimeType);
         Lucene::updateFile($doc, $path, $user);
         return true;
     } else {
         Util::writeLog('search_lucene', 'need mimetype for content extraction', Util::ERROR);
         return false;
     }
 }
예제 #6
0
    }
    $img = trim($fullPath . '/' . $img);
} else {
    OCP\JSON::checkLoggedIn();
    $user = OCP\User::getUser();
}
session_write_close();
$ownerView = new \OC\Files\View('/' . $user . '/files');
$mime = $ownerView->getMimeType($img);
list($mimePart, ) = explode('/', $mime);
if ($mimePart === 'image') {
    $fileInfo = $ownerView->getFileInfo($img);
    if ($fileInfo['encrypted'] === true) {
        $local = $ownerView->toTmpFile($img);
    } else {
        $local = $ownerView->getLocalFile($img);
    }
    $rotate = false;
    if (is_callable('exif_read_data')) {
        //don't use OCP\Image here, using OCP\Image will always cause parsing the image file
        $exif = @exif_read_data($local, 'IFD0');
        if (isset($exif['Orientation'])) {
            $rotate = $exif['Orientation'] > 1;
        }
    }
    OCP\Response::setContentDispositionHeader(basename($img), 'attachment');
    if ($rotate) {
        $image = new OCP\Image($local);
        $image->fixOrientation();
        $image->show();
    } else {
예제 #7
0
 /**
  * Delete versions of a file
  */
 public static function delete($path)
 {
     $deletedFile = self::$deletedFiles[$path];
     $uid = $deletedFile['uid'];
     $filename = $deletedFile['filename'];
     if (!\OC\Files\Filesystem::file_exists($path)) {
         $versions_fileview = new \OC\Files\View('/' . $uid . '/files_versions');
         $abs_path = $versions_fileview->getLocalFile($filename . '.v');
         $versions = self::getVersions($uid, $filename);
         if (!empty($versions)) {
             $versionsSize = self::getVersionsSize($uid);
             if ($versionsSize === false || $versionsSize < 0) {
                 $versionsSize = self::calculateSize($uid);
             }
             foreach ($versions as $v) {
                 unlink($abs_path . $v['version']);
                 \OC_Hook::emit('\\OCP\\Versions', 'delete', array('path' => $abs_path . $v['version']));
                 $versionsSize -= $v['size'];
             }
             self::setVersionsSize($uid, $versionsSize);
         }
     }
     unset(self::$deletedFiles[$path]);
 }
예제 #8
0
$thumbPath = OCP\Util::linkToAbsolute('oclife', 'getThumbnail.php', array('filePath' => $filePath));
$preview = '<img style="border: 1px solid black; display: block;" src="' . $thumbPath . '" />';
$infos = array();
$infos[] = '<strong>' . $l->t('File name') . ': </strong>' . $fileInfos['name'];
$infos[] = '<strong>MIME: </strong>' . $fileInfos['mimetype'];
$infos[] = '<strong>' . $l->t('Size') . ': </strong>' . \OCA\OCLife\utilities::formatBytes($fileInfos['size'], 2, TRUE);
$infos[] = '<strong>' . $l->t('When added') . ': </strong>' . \OCP\Util::formatDate($fileInfos['storage_mtime']);
$infos[] = '<strong>' . $l->t('Encrypted? ') . '</strong>' . ($fileInfos['encrypted'] === TRUE ? $l->t('Yes') : $l->t('No'));
if ($fileInfos['encrypted']) {
    $infos[] = '<strong>' . $l->t('Unencrypted size') . ': </strong>' . \OCA\OCLife\utilities::formatBytes($fileInfos['unencrypted_size'], 2, TRUE);
}
// Output basic infos
$htmlInfos = implode('<br />', $infos);
// Check for EXIF data
// Get current user
$user = \OCP\User::getUser();
$viewPath = '/' . $user . '/files';
$view = new \OC\Files\View($viewPath);
$imageLocalPath = $view->getLocalFile($filePath);
$exifHandler = new OCA\OCLife\exifHandler($imageLocalPath);
$allInfos = $exifHandler->getExifData();
$ifd0Infos = isset($allInfos['IFD0']) ? $allInfos['IFD0'] : array();
$exifInfos = isset($allInfos['EXIF']) ? $allInfos['EXIF'] : array();
$fullInfoArray = array_merge($ifd0Infos, $exifInfos);
if (is_array($fullInfoArray)) {
    $extInfoText = OCA\OCLife\utilities::glueArrayHTML($fullInfoArray);
} else {
    $extInfoText = '';
}
$result = array('preview' => $preview, 'infos' => $htmlInfos, 'exif' => $extInfoText, 'fileid' => $fileInfos['fileid']);
print json_encode($result);
예제 #9
0
 /**
  * Generate thumbnail of an Image with GD
  * @param string $viewPath Source view path
  * @param string $srcImagePath Source image path relative to the ownCloud fakeroot
  * @param string $dstImagePath Destination image path
  * @return boolean TRUE image generated successfully, FALSE otherwise
  */
 private function generateImageThumbnailGD($viewPath, $srcImagePath, $dstImagePath)
 {
     $view = new \OC\Files\View($viewPath);
     $imageLocalPath = $view->getLocalFile($srcImagePath);
     $image = new \OCP\Image();
     $image->loadFromFile($imageLocalPath);
     if (!$image->valid()) {
         return FALSE;
     }
     //Non legge il path
     $image->fixOrientation();
     $image->resize($this->width);
     $imageRsrc = $image->resource();
     $height = $image->height();
     $width = $image->width();
     $widthOffset = intval(($this->width - $width) / 2);
     $heightOffset = intval(($this->height - $height) / 2);
     $thumbGDImage = imagecreatetruecolor($this->width, $this->height);
     // Fill with background color
     $bgColor = imagecolorallocate($thumbGDImage, $this->bgColor['red'], $this->bgColor['green'], $this->bgColor['blue']);
     imagefilledrectangle($thumbGDImage, 0, 0, $this->width, $this->height, $bgColor);
     imagecopyresampled($thumbGDImage, $imageRsrc, $widthOffset, $heightOffset, 0, 0, $width, $height, $width, $height);
     imagepng($thumbGDImage, $dstImagePath, 7);
     imagedestroy($thumbGDImage);
     return TRUE;
 }