本文整理汇总了PHP中OC_Helper类的典型用法代码示例。如果您正苦于以下问题:PHP OC_Helper类的具体用法?PHP OC_Helper怎么用?PHP OC_Helper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OC_Helper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
$this->datadir = \OC_Helper::tmpFolder();
file_put_contents($this->datadir . '/.ocdata', '');
\OC::$server->getSession()->set('checkServer_succeeded', false);
}
示例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 (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']) {
$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();
}
示例3: getThumbnail
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$mimetype = $fileview->getMimeType($path);
$path = \OC_Helper::mimetypeIcon($mimetype);
$path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT));
$svgPath = substr_replace($path, 'svg', -3);
if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) {
// http://www.php.net/manual/de/imagick.setresolution.php#85284
$svg = new \Imagick();
$svg->readImage($svgPath);
$res = $svg->getImageResolution();
$x_ratio = $res['x'] / $svg->getImageWidth();
$y_ratio = $res['y'] / $svg->getImageHeight();
$svg->removeImage();
$svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio);
$svg->setBackgroundColor(new \ImagickPixel('transparent'));
$svg->readImage($svgPath);
$svg->setImageFormat('png32');
$image = new \OC_Image();
$image->loadFromData($svg);
} else {
$image = new \OC_Image($path);
}
return $image;
}
示例4: search
function search($query)
{
$files = OC_FileCache::search($query, true);
$results = array();
foreach ($files as $fileData) {
$file = $fileData['path'];
$mime = $fileData['mimetype'];
if ($mime == 'httpd/unix-directory') {
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'index.php') . '?dir=' . $file, 'Files');
} else {
$mimeBase = $fileData['mimepart'];
switch ($mimeBase) {
case 'audio':
break;
case 'text':
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php') . '?file=' . $file, 'Text');
break;
case 'image':
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php') . '?file=' . $file, 'Images');
break;
default:
if ($mime == 'application/xml') {
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php') . '?file=' . $file, 'Text');
} else {
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php') . '?file=' . $file, 'Files');
}
}
}
}
return $results;
}
示例5: testCloseStream
public function testCloseStream()
{
//ensure all basic stream stuff works
$sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
$tmpFile = OC_Helper::TmpFile('.txt');
$file = 'close://' . $tmpFile;
$this->assertTrue(file_exists($file));
file_put_contents($file, file_get_contents($sourceFile));
$this->assertEquals(file_get_contents($sourceFile), file_get_contents($file));
unlink($file);
clearstatcache();
$this->assertFalse(file_exists($file));
//test callback
$tmpFile = OC_Helper::TmpFile('.txt');
$file = 'close://' . $tmpFile;
\OC\Files\Stream\Close::registerCallback($tmpFile, array('Test_StreamWrappers', 'closeCallBack'));
$fh = fopen($file, 'w');
fwrite($fh, 'asd');
try {
fclose($fh);
$this->fail('Expected exception');
} catch (Exception $e) {
$path = $e->getMessage();
$this->assertEquals($path, $tmpFile);
}
}
示例6: setUp
function setUp()
{
$this->randomTmpDir = \OC_Helper::tmpFolder();
$this->configFile = $this->randomTmpDir . 'testconfig.php';
file_put_contents($this->configFile, self::TESTCONTENT);
$this->config = new OC\Config($this->randomTmpDir, 'testconfig.php');
}
示例7: 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();
}
示例8: __construct
/**
* @brief The constructor
* @param $app the app requesting l10n
* @param $lang default: null Language
* @returns OC_L10N-Object
*
* If language is not set, the constructor tries to find the right
* language.
*/
public function __construct($app, $lang = null)
{
// Find the right language
if (is_null($lang)) {
$lang = self::findLanguage($app);
}
// Use cache if possible
if (array_key_exists($app . '::' . $lang, self::$cache)) {
$this->translations = self::$cache[$app . '::' . $lang]['t'];
$this->localizations = self::$cache[$app . '::' . $lang]['l'];
} else {
$i18ndir = self::findI18nDir($app);
// Localization is in /l10n, Texts are in $i18ndir
// (Just no need to define date/time format etc. twice)
if ((OC_Helper::issubdirectory($i18ndir . $lang . '.php', OC::$APPSROOT . "/apps") || OC_Helper::issubdirectory($i18ndir . $lang . '.php', OC::$SERVERROOT . '/core/l10n/') || OC_Helper::issubdirectory($i18ndir . $lang . '.php', OC::$SERVERROOT . '/settings')) && file_exists($i18ndir . $lang . '.php')) {
// Include the file, save the data from $CONFIG
include $i18ndir . $lang . '.php';
if (isset($TRANSLATIONS) && is_array($TRANSLATIONS)) {
$this->translations = $TRANSLATIONS;
}
}
if (file_exists(OC::$SERVERROOT . '/core/l10n/l10n-' . $lang . '.php')) {
// Include the file, save the data from $CONFIG
include OC::$SERVERROOT . '/core/l10n/l10n-' . $lang . '.php';
if (isset($LOCALIZATIONS) && is_array($LOCALIZATIONS)) {
$this->localizations = array_merge($this->localizations, $LOCALIZATIONS);
}
}
self::$cache[$app . '::' . $lang]['t'] = $this->translations;
self::$cache[$app . '::' . $lang]['l'] = $this->localizations;
}
}
示例9: determineIcon
public static function determineIcon($file)
{
if ($file['type'] === 'dir') {
$dir = $file['directory'];
$absPath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir . '/' . $file['name']);
$mount = \OC\Files\Filesystem::getMountManager()->find($absPath);
if (!is_null($mount)) {
$sid = $mount->getStorageId();
if (!is_null($sid)) {
$sid = explode(':', $sid);
if ($sid[0] === 'shared') {
return \OC_Helper::mimetypeIcon('dir-shared');
}
if ($sid[0] !== 'local' and $sid[0] !== 'home') {
return \OC_Helper::mimetypeIcon('dir-external');
}
}
}
return \OC_Helper::mimetypeIcon('dir');
}
if ($file['isPreviewAvailable']) {
$pathForPreview = $file['directory'] . '/' . $file['name'];
return \OC_Helper::previewIcon($pathForPreview) . '&c=' . $file['etag'];
}
return \OC_Helper::mimetypeIcon($file['mimetype']);
}
示例10: search
function search($query)
{
$files = OC_Filesystem::search($query);
$results = array();
foreach ($files as $file) {
if (OC_Filesystem::is_dir($file)) {
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'index.php?dir=' . $file), 'Files');
} else {
$mime = OC_Filesystem::getMimeType($file);
$mimeBase = substr($mime, 0, strpos($mime, '/'));
switch ($mimeBase) {
case 'audio':
break;
case 'text':
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Text');
break;
case 'image':
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Images');
break;
default:
if ($mime == 'application/xml') {
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Text');
} else {
$results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Files');
}
}
}
}
return $results;
}
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:30,代码来源:owncloud_lib_search_provider_file.php
示例11: sendEmail
public static function sendEmail($args)
{
if (OC_User::userExists($_POST['user'])) {
$token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
// Hash the token again to prevent timing attacks
$email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
if (!empty($email)) {
$link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
$link = OC_Helper::makeURLAbsolute($link);
$tmpl = new OC_Template('core/lostpassword', 'email');
$tmpl->assign('link', $link, false);
$msg = $tmpl->fetchPage();
$l = OC_L10N::get('core');
$from = 'lostpassword-noreply@' . OCP\Util::getServerHost();
OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
echo 'Mailsent';
self::displayLostPasswordPage(false, true);
} else {
self::displayLostPasswordPage(true, false);
}
} else {
self::displayLostPasswordPage(true, false);
}
}
示例12: tearDown
protected function tearDown()
{
foreach ($this->tmpDirs as $dir) {
\OC_Helper::rmdirr($dir);
}
parent::tearDown();
}
示例13: setUp
protected function setUp()
{
parent::setUp();
$this->user = new DummyUser('foo', \OC_Helper::tmpFolder());
$this->storage = new \OC\Files\Storage\Home(array('user' => $this->user));
$this->cache = $this->storage->getCache();
}
示例14: getThumbnail
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
// TODO: use proc_open() and stream the source file ?
$absPath = \OC_Helper::tmpFile();
$tmpPath = \OC_Helper::tmpFile();
$handle = $fileview->fopen($path, 'rb');
// we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB.
// in some cases 1MB was no enough to generate thumbnail
$firstmb = stream_get_contents($handle, 5242880);
file_put_contents($absPath, $firstmb);
if (self::$avconvBinary) {
$cmd = self::$avconvBinary . ' -an -y -ss 5' . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
} else {
$cmd = self::$ffmpegBinary . ' -y -ss 5' . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
}
exec($cmd, $output, $returnCode);
unlink($absPath);
if ($returnCode === 0) {
$image = new \OC_Image();
$image->loadFromFile($tmpPath);
unlink($tmpPath);
return $image->valid() ? $image : false;
}
return false;
}
示例15: listAll
/**
* lists the documents the user has access to (including shared files, once the code in core has been fixed)
* also adds session and member info for these files
*/
public static function listAll()
{
self::preDispatch();
$found = Storage::getDocuments();
$fileIds = array();
$documents = array();
foreach ($found as $key => $document) {
if (is_object($document)) {
$documents[] = $document->getData();
} else {
$documents[$key] = $document;
}
$documents[$key]['icon'] = preg_replace('/\\.png$/', '.svg', \OC_Helper::mimetypeIcon($document['mimetype']));
$fileIds[] = $document['fileid'];
}
usort($documents, function ($a, $b) {
return @$b['mtime'] - @$a['mtime'];
});
$session = new Db\Session();
$sessions = $session->getCollectionBy('file_id', $fileIds);
$members = array();
$member = new Db\Member();
foreach ($sessions as $session) {
$members[$session['es_id']] = $member->getActiveCollection($session['es_id']);
}
\OCP\JSON::success(array('documents' => $documents, 'sessions' => $sessions, 'members' => $members));
}