Ejemplo n.º 1
0
 /**
  * Get the template for a specific activity-event in the activities
  *
  * @param array $activity An array with all the activity data in it
  * @return string
  */
 public function show($activity)
 {
     $tmpl = new Template('activity', 'stream.item');
     $tmpl->assign('formattedDate', $this->dateTimeFormatter->formatDateTime($activity['timestamp']));
     $tmpl->assign('formattedTimestamp', Template::relative_modified_date($activity['timestamp']));
     $tmpl->assign('user', $activity['user']);
     $tmpl->assign('displayName', User::getDisplayName($activity['user']));
     if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
         // We do not link the subject as we create links for the parameters instead
         $activity['link'] = '';
     }
     $tmpl->assign('event', $activity);
     if ($activity['file']) {
         $this->view->chroot('/' . $activity['affecteduser'] . '/files');
         $exist = $this->view->file_exists($activity['file']);
         $is_dir = $this->view->is_dir($activity['file']);
         $tmpl->assign('previewLink', $this->getPreviewLink($activity['file'], $is_dir));
         // show a preview image if the file still exists
         $mimeType = \OC_Helper::getFileNameMimeType($activity['file']);
         if ($mimeType && !$is_dir && $this->preview->isMimeSupported($mimeType) && $exist) {
             $tmpl->assign('previewImageLink', $this->urlGenerator->linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
         } else {
             $mimeTypeIcon = Template::mimetype_icon($is_dir ? 'dir' : $mimeType);
             $mimeTypeIcon = substr($mimeTypeIcon, -4) === '.png' ? substr($mimeTypeIcon, 0, -4) . '.svg' : $mimeTypeIcon;
             $tmpl->assign('previewImageLink', $mimeTypeIcon);
             $tmpl->assign('previewLinkIsDir', true);
         }
     }
     return $tmpl->fetchPage();
 }
Ejemplo n.º 2
0
 /**
  * Get the template for a specific activity-event in the activities
  *
  * @param array $activity An array with all the activity data in it
  * @return string
  */
 public static function show($activity)
 {
     $tmpl = new Template('activity', 'activity.box');
     $tmpl->assign('formattedDate', Util::formatDate($activity['timestamp']));
     $tmpl->assign('formattedTimestamp', \OCP\relative_modified_date($activity['timestamp']));
     $tmpl->assign('user', $activity['user']);
     $tmpl->assign('displayName', User::getDisplayName($activity['user']));
     if ($activity['app'] === 'files') {
         // We do not link the subject as we create links for the parameters instead
         $activity['link'] = '';
     }
     $tmpl->assign('event', $activity);
     if ($activity['file']) {
         $rootView = new View('/' . $activity['affecteduser'] . '/files');
         $exist = $rootView->file_exists($activity['file']);
         $is_dir = $rootView->is_dir($activity['file']);
         unset($rootView);
         // show a preview image if the file still exists
         $mimetype = \OC_Helper::getFileNameMimeType($activity['file']);
         if (!$is_dir && \OC::$server->getPreviewManager()->isMimeSupported($mimetype) && $exist) {
             $tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => dirname($activity['file']))));
             $tmpl->assign('previewImageLink', Util::linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
         } else {
             $tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => $activity['file'])));
             $tmpl->assign('previewImageLink', \OC_Helper::mimetypeIcon($is_dir ? 'dir' : $mimetype));
             $tmpl->assign('previewLinkIsDir', true);
         }
     }
     return $tmpl->fetchPage();
 }
Ejemplo n.º 3
0
 function testGetFileNameMimeType()
 {
     $this->assertEquals('text/plain', OC_Helper::getFileNameMimeType('foo.txt'));
     $this->assertEquals('image/png', OC_Helper::getFileNameMimeType('foo.png'));
     $this->assertEquals('image/png', OC_Helper::getFileNameMimeType('foo.bar.png'));
     $this->assertEquals('application/octet-stream', OC_Helper::getFileNameMimeType('.png'));
     $this->assertEquals('application/octet-stream', OC_Helper::getFileNameMimeType('foo'));
     $this->assertEquals('application/octet-stream', OC_Helper::getFileNameMimeType(''));
 }
Ejemplo n.º 4
0
 /**
  * Retrieves the contents of a trash bin directory.
  *
  * @param string $dir path to the directory inside the trashbin
  * or empty to retrieve the root of the trashbin
  * @param string $user
  * @param string $sortAttribute attribute to sort on or empty to disable sorting
  * @param bool $sortDescending true for descending sort, false otherwise
  * @return \OCP\Files\FileInfo[]
  */
 public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false)
 {
     $result = array();
     $timestamp = null;
     $view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
     if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
         throw new \Exception('Directory does not exists');
     }
     $dirContent = $view->opendir($dir);
     if ($dirContent === false) {
         return $result;
     }
     $mount = $view->getMount($dir);
     $storage = $mount->getStorage();
     $absoluteDir = $view->getAbsolutePath($dir);
     $internalPath = $mount->getInternalPath($absoluteDir);
     if (is_resource($dirContent)) {
         $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
         while (($entryName = readdir($dirContent)) !== false) {
             if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
                 $id = $entryName;
                 if ($dir === '' || $dir === '/') {
                     $size = $view->filesize($id);
                     $pathparts = pathinfo($entryName);
                     $timestamp = substr($pathparts['extension'], 1);
                     $id = $pathparts['filename'];
                 } else {
                     if ($timestamp === null) {
                         // for subfolders we need to calculate the timestamp only once
                         $size = $view->filesize($dir . '/' . $id);
                         $parts = explode('/', ltrim($dir, '/'));
                         $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
                     }
                 }
                 $originalPath = '';
                 if (isset($originalLocations[$id][$timestamp])) {
                     $originalPath = $originalLocations[$id][$timestamp];
                     if (substr($originalPath, -1) === '/') {
                         $originalPath = substr($originalPath, 0, -1);
                     }
                 }
                 $i = array('name' => $id, 'mtime' => $timestamp, 'mimetype' => $view->is_dir($dir . '/' . $entryName) ? 'httpd/unix-directory' : \OC_Helper::getFileNameMimeType($id), 'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file', 'directory' => $dir === '/' ? '' : $dir, 'size' => $size);
                 if ($originalPath) {
                     $i['extraData'] = $originalPath . '/' . $id;
                 }
                 $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
             }
         }
         closedir($dirContent);
     }
     if ($sortAttribute !== '') {
         return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * get files shared with the user
  * @return \OC_OCS_Result
  */
 private static function getFilesSharedWithMe()
 {
     try {
         $shares = \OCP\Share::getItemsSharedWith('file');
         foreach ($shares as &$share) {
             if ($share['item_type'] === 'file') {
                 $share['mimetype'] = \OC_Helper::getFileNameMimeType($share['file_target']);
                 if (\OC::$server->getPreviewManager()->isMimeSupported($share['mimetype'])) {
                     $share['isPreviewAvailable'] = true;
                 }
             }
         }
         $result = new \OC_OCS_Result($shares);
     } catch (\Exception $e) {
         $result = new \OC_OCS_Result(null, 403, $e->getMessage());
     }
     return $result;
 }
Ejemplo n.º 6
0
 public function touch($path, $mtime = null)
 {
     if (is_null($mtime)) {
         $mtime = time();
     }
     $path = $this->normalizePath($path);
     $dirName = dirname($path);
     $parentExists = $this->is_dir($dirName);
     if (!$parentExists) {
         return false;
     }
     $stat = $this->stat($path);
     if (is_array($stat)) {
         // update existing mtime in db
         $stat['mtime'] = $mtime;
         $this->getCache()->update($stat['fileid'], $stat);
     } else {
         $mimeType = \OC_Helper::getFileNameMimeType($path);
         // create new file
         $stat = array('etag' => $this->getETag($path), 'mimetype' => $mimeType, 'size' => 0, 'mtime' => $mtime, 'storage_mtime' => $mtime, 'permissions' => \OCP\PERMISSION_ALL);
         $fileId = $this->getCache()->put($path, $stat);
         try {
             //read an empty file from memory
             $this->objectStore->writeObject($this->getURN($fileId), fopen('php://memory', 'r'));
         } catch (\Exception $ex) {
             $this->getCache()->remove($path);
             \OCP\Util::writeLog('objectstore', 'Could not create object: ' . $ex->getMessage(), \OCP\Util::ERROR);
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 7
0
 public function getMimeType($path)
 {
     if ($this->is_dir($path)) {
         return 'httpd/unix-directory';
     } elseif ($this->file_exists($path)) {
         return \OC_Helper::getFileNameMimeType($path);
     } else {
         return false;
     }
 }
Ejemplo n.º 8
0
$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44';
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
if ($file === '') {
    \OC_Response::setStatus(400);
    //400 Bad Request
    \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG);
    exit;
}
if ($maxX === 0 || $maxY === 0) {
    \OC_Response::setStatus(400);
    //400 Bad Request
    \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
    exit;
}
try {
    $preview = new \OC\Preview(\OC_User::getUser(), 'files_trashbin/files', $file);
    $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files_trashbin/files');
    if ($view->is_dir($file)) {
        $mimetype = 'httpd/unix-directory';
    } else {
        $mimetype = \OC_Helper::getFileNameMimeType(pathinfo($file, PATHINFO_FILENAME));
    }
    $preview->setMimetype($mimetype);
    $preview->setMaxX($maxX);
    $preview->setMaxY($maxY);
    $preview->setScalingUp($scalingUp);
    $preview->showPreview();
} catch (\Exception $e) {
    \OC_Response::setStatus(500);
    \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
}
Ejemplo n.º 9
0
    //400 Bad Request
    \OCP\Util::writeLog('core-preview', 'x and/or y set to 0', \OCP\Util::DEBUG);
    exit;
}
try {
    $preview = new \OC\Preview(\OC_User::getUser(), 'files_trashbin/files', $file);
    $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files_trashbin/files');
    if ($view->is_dir($file)) {
        $mimetype = 'httpd/unix-directory';
    } else {
        $pathInfo = pathinfo(ltrim($file, '/'));
        $fileName = $pathInfo['basename'];
        // if in root dir
        if ($pathInfo['dirname'] === '.') {
            // cut off the .d* suffix
            $i = strrpos($fileName, '.');
            if ($i !== false) {
                $fileName = substr($fileName, 0, $i);
            }
        }
        $mimetype = \OC_Helper::getFileNameMimeType($fileName);
    }
    $preview->setMimetype($mimetype);
    $preview->setMaxX($maxX);
    $preview->setMaxY($maxY);
    $preview->setScalingUp($scalingUp);
    $preview->showPreview();
} catch (\Exception $e) {
    \OC_Response::setStatus(500);
    \OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::DEBUG);
}