当前位置: 首页>>代码示例>>PHP>>正文


PHP OC_Helper::getFileNameMimeType方法代码示例

本文整理汇总了PHP中OC_Helper::getFileNameMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Helper::getFileNameMimeType方法的具体用法?PHP OC_Helper::getFileNameMimeType怎么用?PHP OC_Helper::getFileNameMimeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OC_Helper的用法示例。


在下文中一共展示了OC_Helper::getFileNameMimeType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: show

 /**
  * 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();
 }
开发者ID:samj1912,项目名称:repo,代码行数:36,代码来源:display.php

示例2: show

 /**
  * 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();
 }
开发者ID:yheric455042,项目名称:owncloud82,代码行数:36,代码来源:display.php

示例3: testGetFileNameMimeType

 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(''));
 }
开发者ID:reverserob,项目名称:core,代码行数:9,代码来源:helper.php

示例4: getTrashFiles

 /**
  * 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;
 }
开发者ID:evanjt,项目名称:core,代码行数:65,代码来源:helper.php

示例5: getFilesSharedWithMe

 /**
  * 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;
 }
开发者ID:heldernl,项目名称:owncloud8-extended,代码行数:22,代码来源:local.php

示例6: touch

 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;
 }
开发者ID:olucao,项目名称:owncloud-core,代码行数:32,代码来源:objectstorestorage.php

示例7: getMimeType

 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;
     }
 }
开发者ID:reverserob,项目名称:core,代码行数:10,代码来源:common.php

示例8: array_key_exists

$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);
}
开发者ID:omusico,项目名称:isle-web-framework,代码行数:31,代码来源:preview.php

示例9: pathinfo

    //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);
}
开发者ID:enoch85,项目名称:owncloud-testserver,代码行数:31,代码来源:preview.php


注:本文中的OC_Helper::getFileNameMimeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。