Example #1
0
 protected function setUp()
 {
     parent::setUp();
     $this->datadir = \OC_Helper::tmpFolder();
     file_put_contents($this->datadir . '/.ocdata', '');
     \OC::$server->getSession()->set('checkServer_succeeded', false);
 }
Example #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 (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();
 }
Example #3
0
 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;
 }
Example #4
0
 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;
 }
Example #5
0
 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);
     }
 }
Example #6
0
 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');
 }
Example #7
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();
 }
Example #8
0
 /**
  * @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;
     }
 }
Example #9
0
 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']);
 }
 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;
 }
Example #11
0
 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);
     }
 }
Example #12
0
 protected function tearDown()
 {
     foreach ($this->tmpDirs as $dir) {
         \OC_Helper::rmdirr($dir);
     }
     parent::tearDown();
 }
Example #13
0
 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();
 }
Example #14
0
 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;
 }
 /**
  * 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));
 }
 public function testGetFileSizeViaExec()
 {
     if (!\OC_Helper::is_function_enabled('exec')) {
         $this->markTestSkipped('The exec() function needs to be enabled for this test.');
     }
     $this->assertSame($this->fileSize, $this->helper->getFileSizeViaExec($this->filename));
 }
Example #17
0
 /**
  * Get the template for a specific activity-event in the activities
  *
  * @param array $activity An array with all the activity data in it
  * @param return string
  */
 public static function show($activity)
 {
     $tmpl = new \OCP\Template('activity', 'activity.box');
     $tmpl->assign('formattedDate', \OCP\Util::formatDate($activity['timestamp']));
     $tmpl->assign('formattedTimestamp', \OCP\relative_modified_date($activity['timestamp']));
     $tmpl->assign('user', $activity['user']);
     $tmpl->assign('displayName', \OCP\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 \OC\Files\View('');
         $exist = $rootView->file_exists('/' . $activity['user'] . '/files' . $activity['file']);
         $is_dir = $rootView->is_dir('/' . $activity['user'] . '/files' . $activity['file']);
         unset($rootView);
         // show a preview image if the file still exists
         if (!$is_dir && $exist) {
             $tmpl->assign('previewLink', \OCP\Util::linkTo('files', 'index.php', array('dir' => dirname($activity['file']))));
             $tmpl->assign('previewImageLink', \OCP\Util::linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
         } else {
             if ($exist) {
                 $tmpl->assign('previewLink', \OCP\Util::linkTo('files', 'index.php', array('dir' => $activity['file'])));
                 $tmpl->assign('previewImageLink', \OC_Helper::mimetypeIcon('dir'));
                 $tmpl->assign('previewLinkIsDir', true);
             }
         }
     }
     return $tmpl->fetchPage();
 }
Example #18
0
 public static function sendEmail($args)
 {
     $isEncrypted = OC_App::isEnabled('files_encryption');
     if (!$isEncrypted || isset($_POST['continue'])) {
         $continue = true;
     } else {
         $continue = false;
     }
     if (OC_User::userExists($_POST['user']) && $continue) {
         $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 = OCP\Util::getDefaultEmailAddress('lostpassword-noreply');
             try {
                 OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
             } catch (Exception $e) {
                 OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.');
             }
             self::displayLostPasswordPage(false, true);
         } else {
             self::displayLostPasswordPage(true, false);
         }
     } else {
         self::displayLostPasswordPage(true, false);
     }
 }
Example #19
0
 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;
     $actual = false;
     $callback = function ($path) use(&$actual) {
         $actual = $path;
     };
     \OC\Files\Stream\Close::registerCallback($tmpFile, $callback);
     $fh = fopen($file, 'w');
     fwrite($fh, 'asd');
     fclose($fh);
     $this->assertSame($tmpFile, $actual);
 }
Example #20
0
 public function run()
 {
     if (!\OC_Template::isAssetPipelineEnabled()) {
         $this->emit('\\OC\\Repair', 'info', array('Asset pipeline disabled -> nothing to do'));
         return;
     }
     $assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT) . '/assets';
     \OC_Helper::rmdirr($assetDir, false);
     $this->emit('\\OC\\Repair', 'info', array('Asset cache cleared.'));
 }
Example #21
0
 public function run(IOutput $output)
 {
     if (!\OC_Template::isAssetPipelineEnabled()) {
         $output->info('Asset pipeline disabled -> nothing to do');
         return;
     }
     $assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT) . '/assets';
     \OC_Helper::rmdirr($assetDir, false);
     $output->info('Asset cache cleared.');
 }
Example #22
0
 public static function buildFileStorageStatistics($dir)
 {
     $l = new \OC_L10N('files');
     $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir);
     $maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize);
     $maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize;
     // information about storage capacities
     $storageInfo = \OC_Helper::getStorageInfo();
     return array('uploadMaxFilesize' => $maxUploadFilesize, 'maxHumanFilesize' => $maxHumanFilesize, 'usedSpacePercent' => (int) $storageInfo['relative']);
 }
Example #23
0
/**
 * Try to find a programm
 *
 * @param string $program
 * @return null|string
 */
function findBinaryPath($program)
{
    if (OC_Helper::is_function_enabled('exec')) {
        exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode);
        if ($returnCode === 0 && count($output) > 0) {
            return escapeshellcmd($output[0]);
        }
    }
    return null;
}
Example #24
0
 public function __construct()
 {
     $baseUrl = OC_Helper::linkTo('', 'index.php');
     $method = $_SERVER['REQUEST_METHOD'];
     $host = OC_Request::serverHost();
     $schema = OC_Request::serverProtocol();
     $this->context = new RequestContext($baseUrl, $method, $host, $schema);
     // TODO cache
     $this->root = $this->getCollection('root');
 }
Example #25
0
 public function run()
 {
     if (!\OC_Template::isAssetPipelineEnabled()) {
         $this->emit('\\OC\\Repair', 'info', array('Asset pipeline disabled -> nothing to do'));
         return;
     }
     $assetDir = \OC::$SERVERROOT . '/assets';
     \OC_Helper::rmdirr($assetDir, false);
     $this->emit('\\OC\\Repair', 'info', array('Asset cache cleared.'));
 }
Example #26
0
 /**
  * @param string $dir
  * @return array
  * @throws \OCP\Files\NotFoundException
  */
 public static function buildFileStorageStatistics($dir)
 {
     // information about storage capacities
     $storageInfo = \OC_Helper::getStorageInfo($dir);
     $l = new \OC_L10N('files');
     $maxUploadFileSize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']);
     $maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize);
     $maxHumanFileSize = $l->t('Upload (max. %s)', array($maxHumanFileSize));
     return ['uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize, 'freeSpace' => $storageInfo['free'], 'usedSpacePercent' => (int) $storageInfo['relative'], 'owner' => $storageInfo['owner'], 'ownerDisplayName' => $storageInfo['ownerDisplayName']];
 }
Example #27
0
 /**
  * @brief Search in the activities and return search results
  * @param $query
  * @return search results
  */
 function search($query)
 {
     $data = Data::search($query, 100);
     $results = array();
     foreach ($data as $d) {
         $file = $d['file'];
         $results[] = new \OC_Search_Result(basename($file), $d['subject'] . ' (' . \OCP\Util::formatDate($d['timestamp']) . ')', \OC_Helper::linkTo('activity', 'index.php'), 'Activity');
     }
     return $results;
 }
Example #28
0
 public function tearDown()
 {
     $u = new OC_User();
     foreach ($this->users as $user) {
         $u->deleteUser($user);
     }
     foreach ($this->tmpfiles as $file) {
         \OC_Helper::rmdirr($file);
     }
 }
Example #29
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;
 }
Example #30
0
function do_exit($jobid, $pid, $message)
{
    $redirect = isset($_GET["redirect"]);
    $url = isset($_GET["url"]) ? $_GET["url"] : OC_Helper::linkTo("neurocloud", "index.php", array("jobid" => $jobid, "pid" => $pid, "message" => $message, "action" => "kill"));
    if ($redirect) {
        header("Location: " . $url);
    } else {
        echo $message;
        exit;
    }
}