Example #1
0
 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 array('uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize, 'freeSpace' => $storageInfo['free'], 'usedSpacePercent' => (int) $storageInfo['relative']);
 }
Example #2
0
 /**
  * gets user info
  *
  * exposes the quota of an user:
  * <data>
  *   <quota>
  *      <free>1234</free>
  *      <used>4321</used>
  *      <total>5555</total>
  *      <ralative>0.78</ralative>
  *   </quota>
  * </data>
  *
  * @param $parameters object should contain parameter 'userid' which identifies
  *                           the user from whom the information will be returned
  */
 public static function getUser($parameters)
 {
     // Check if they are viewing information on themselves
     if ($parameters['userid'] === OC_User::getUser()) {
         // Self lookup
         $storage = OC_Helper::getStorageInfo('/');
         $quota = array('free' => $storage['free'], 'used' => $storage['used'], 'total' => $storage['total'], 'relative' => $storage['relative']);
         return new OC_OCS_Result(array('quota' => $quota));
     } else {
         // No permission to view this user data
         return new OC_OCS_Result(null, 997);
     }
 }
Example #3
0
 /**
  * gets user info
  *
  * exposes the quota of an user:
  * <data>
  *   <quota>
  *      <free>1234</free>
  *      <used>4321</used>
  *      <total>5555</total>
  *      <ralative>0.78</ralative>
  *   </quota>
  * </data>
  *
  * @param $parameters object should contain parameter 'userid' which identifies
  *                           the user from whom the information will be returned
  */
 public static function getUser($parameters)
 {
     $return = array();
     // Check if they are viewing information on themselves
     if ($parameters['userid'] === OC_User::getUser()) {
         // Self lookup
         $storage = OC_Helper::getStorageInfo('/');
         $return['quota'] = array('free' => $storage['free'], 'used' => $storage['used'], 'total' => $storage['total'], 'relative' => $storage['relative']);
     }
     if (OC_User::isAdminUser(OC_User::getUser()) || OC_Subadmin::isUserAccessible(OC_User::getUser(), $parameters['userid'])) {
         // Is an admin/subadmin so can see display name
         $return['displayname'] = OC_User::getDisplayName($parameters['userid']);
     }
     if (count($return)) {
         return new OC_OCS_Result($return);
     } else {
         // No permission to view this user data
         return new OC_OCS_Result(null, 997);
     }
 }
 /**
  * Return the chart data you want to return based on the ChartConfig
  *
  * @return mixed
  */
 public function getChartUsage()
 {
     $new = array();
     $storageInfo = \OC_Helper::getStorageInfo('/');
     $free = ceil($storageInfo['free'] / 1024 / 1024);
     if ($this->isAdminUser()) {
         $data = $this->repository->findAllWithLimit(1);
         foreach ($data as $username => $items) {
             foreach ($items as $item) {
                 $new[$username] = ceil($item->getUsage() / 1024 / 1024);
             }
         }
         $new['free'] = $free;
         $data = $new;
     } else {
         $free = ceil($storageInfo['free'] / 1024 / 1024);
         $used = ceil($storageInfo['used'] / 1024 / 1024);
         $data = array('used' => $used, 'free' => $free);
     }
     return $data;
 }
 /**
  * Test getting the storage info when the remaining
  * free storage space is less than the quota
  */
 function testGetStorageInfoWhenFreeSpaceLessThanQuota()
 {
     $homeStorage = $this->getStorageMock(12);
     $homeStorage->file_put_contents('test.txt', '01234');
     $homeStorage = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $homeStorage, 'quota' => 18));
     \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files');
     $storageInfo = \OC_Helper::getStorageInfo('');
     $this->assertEquals(12, $storageInfo['free']);
     $this->assertEquals(5, $storageInfo['used']);
     // total = free + used (because quota > total)
     $this->assertEquals(17, $storageInfo['total']);
 }
Example #6
0
if ($isIE8 && (isset($_GET['dir']) || isset($_GET['view']))) {
    $hash = '#?';
    $dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
    $view = isset($_GET['view']) ? $_GET['view'] : 'files';
    $hash = '#?dir=' . \OCP\Util::encodePath($dir);
    if ($view !== 'files') {
        $hash .= '&view=' . urlencode($view);
    }
    header('Location: ' . OCP\Util::linkTo('files', 'index.php') . $hash);
    exit;
}
$user = OC_User::getUser();
$config = \OC::$server->getConfig();
// mostly for the home storage's free space
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
$storageInfo = OC_Helper::getStorageInfo('/', $dirInfo);
$nav = new OCP\Template('files', 'appnavigation', '');
function sortNavigationItems($item1, $item2)
{
    return $item1['order'] - $item2['order'];
}
\OCA\Files\App::getNavigationManager()->add(array('id' => 'favorites', 'appname' => 'files', 'script' => 'simplelist.php', 'order' => 5, 'name' => $l->t('Favorites')));
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
usort($navItems, 'sortNavigationItems');
$nav->assign('navigationItems', $navItems);
$contentItems = array();
function renderScript($appName, $scriptName)
{
    $content = '';
    $appPath = OC_App::getAppPath($appName);
    $scriptPath = $appPath . '/' . $scriptName;
Example #7
0
$urlGenerator = \OC::$server->getURLGenerator();
// Highlight navigation entry
OC_Util::addScript('settings', 'personal');
OC_Util::addScript('settings', 'certificates');
OC_Util::addStyle('settings', 'settings');
\OC_Util::addVendorScript('strengthify/jquery.strengthify');
\OC_Util::addVendorStyle('strengthify/strengthify');
\OC_Util::addScript('files', 'jquery.iframe-transport');
\OC_Util::addScript('files', 'jquery.fileupload');
if ($config->getSystemValue('enable_avatars', true) === true) {
    \OC_Util::addVendorScript('jcrop/js/jquery.Jcrop');
    \OC_Util::addVendorStyle('jcrop/css/jquery.Jcrop');
}
// Highlight navigation entry
OC::$server->getNavigationManager()->setActiveEntry('personal');
$storageInfo = OC_Helper::getStorageInfo('/');
$user = OC::$server->getUserManager()->get(OC_User::getUser());
$email = $user->getEMailAddress();
$userLang = $config->getUserValue(OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage());
$languageCodes = OC_L10N::findAvailableLanguages();
// array of common languages
$commonLangCodes = array('en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko');
$languageNames = (include 'languageCodes.php');
$languages = array();
$commonLanguages = array();
foreach ($languageCodes as $lang) {
    $l = \OC::$server->getL10N('settings', $lang);
    // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
    if (substr($l->t('__language_name__'), 0, 1) !== '_') {
        //first check if the language name is in the translation file
        $ln = array('code' => $lang, 'name' => (string) $l->t('__language_name__'));
Example #8
0
 /**
  * Returns available diskspace information
  *
  * @return array
  */
 public function getQuotaInfo()
 {
     if ($this->quotaInfo) {
         return $this->quotaInfo;
     }
     try {
         $storageInfo = \OC_Helper::getStorageInfo($this->info->getPath(), $this->info);
         $this->quotaInfo = array($storageInfo['used'], $storageInfo['free']);
         return $this->quotaInfo;
     } catch (\OCP\Files\StorageNotAvailableException $e) {
         return array(0, 0);
     }
 }
Example #9
0
$list = new OCP\Template('files', 'part.list', '');
$list->assign('files', $files);
$list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
$list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/')));
$list->assign('isPublic', false);
$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
$breadcrumbNav->assign('breadcrumb', $breadcrumb);
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
$permissions = \OCA\Files\Helper::getDirPermissions($dir);
if ($needUpgrade) {
    OCP\Util::addscript('files', 'upgrade');
    $tmpl = new OCP\Template('files', 'upgrade', 'user');
    $tmpl->printPage();
} else {
    // information about storage capacities
    $storageInfo = OC_Helper::getStorageInfo($dir);
    $maxUploadFilesize = OCP\Util::maxUploadFilesize($dir);
    $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes');
    // if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code)
    $encryptionInitStatus = 2;
    if (OC_App::isEnabled('files_encryption')) {
        $session = new \OCA\Encryption\Session(new \OC\Files\View('/'));
        $encryptionInitStatus = $session->getInitialized();
    }
    $trashEnabled = \OCP\App::isEnabled('files_trashbin');
    $trashEmpty = true;
    if ($trashEnabled) {
        $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user);
    }
    $isCreatable = \OC\Files\Filesystem::isCreatable($dir . '/');
    $fileHeader = (!isset($files) or count($files) > 0);
Example #10
0
 /**
  * Returns available diskspace information
  *
  * @return array
  */
 public function getQuotaInfo()
 {
     $path = \OC\Files\Filesystem::getView()->getRelativePath($this->info->getPath());
     $storageInfo = OC_Helper::getStorageInfo($path);
     return array($storageInfo['used'], $storageInfo['free']);
 }
Example #11
0
 /**
  * FIXME: Replace with non static code
  *
  * @return array
  * @throws \OCP\Files\NotFoundException
  */
 protected function getStorageInfo()
 {
     $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
     return \OC_Helper::getStorageInfo('/', $dirInfo);
 }
Example #12
0
 /**
  * Returns available diskspace information
  *
  * @return array
  */
 public function getQuotaInfo()
 {
     $storageInfo = OC_Helper::getStorageInfo($this->path);
     return array($storageInfo['used'], $storageInfo['free']);
 }
Example #13
0
 /**
  * Returns available diskspace information
  *
  * @return array
  */
 public function getQuotaInfo()
 {
     if ($this->quotaInfo) {
         return $this->quotaInfo;
     }
     try {
         $storageInfo = \OC_Helper::getStorageInfo($this->info->getPath(), $this->info);
         if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
             $free = \OCP\Files\FileInfo::SPACE_UNLIMITED;
         } else {
             $free = $storageInfo['free'];
         }
         $this->quotaInfo = array($storageInfo['used'], $free);
         return $this->quotaInfo;
     } catch (\OCP\Files\StorageNotAvailableException $e) {
         return array(0, 0);
     }
 }
Example #14
0
 public static function post_deleteHook($arguments)
 {
     $h = new Publisher();
     $path = $arguments['path'];
     $info = null;
     if (isset(self::$deleteFileInfo[$path])) {
         $info = self::$deleteFileInfo[$path];
     }
     $h->pushFileChange('deleted', $path, $info);
     // quota change handling
     $postStorageInfo = \OC_Helper::getStorageInfo('/');
     $h->pushQuotaChange(self::$preStorageInfo, $postStorageInfo);
 }
Example #15
0
 /**
  * Returns available diskspace information
  *
  * @return array
  */
 public function getQuotaInfo()
 {
     try {
         $path = \OC\Files\Filesystem::getView()->getRelativePath($this->info->getPath());
         $storageInfo = OC_Helper::getStorageInfo($path);
         return array($storageInfo['used'], $storageInfo['free']);
     } catch (\OCP\Files\StorageNotAvailableException $e) {
         return array(0, 0);
     }
 }
    /**
     * @TODO refactor to proper code
     *
     * @param ChartConfig $config
     * @return ChartTypeAdapterInterface
     *
     * @throws \OCA\ocUsageCharts\Exception\StorageUsageRepositoryException
     */
    public function getUsage(ChartConfig $config)
    {
        switch($config->getChartType())
        {
            default:
            case 'StorageUsageLastMonth':
                $created = new \DateTime("-1 month");
                if ( $this->isAdminUser() )
                {
                    $data = $this->findAllAfterCreated($created);
                }
                else
                {
                    $data = $this->findAfterCreated($config->getUsername(), $created);
                    $data = array($config->getUsername() => $data);
                }
                break;

            case 'StorageUsagePerMonth':
                //@TODO don't need to get everything for one user...
                // Performance and such
                $data = $this->findAllPerMonth();
                if ( !$this->isAdminUser() )
                {
                    $data = array($config->getUsername() => $data[$config->getUsername()]);
                }
                break;
            case 'StorageUsageCurrent':
                $new = array();

                $storageInfo = \OC_Helper::getStorageInfo('/');
                $free = ceil($storageInfo['free'] / 1024 / 1024);
                if ( $this->isAdminUser() )
                {
                    $data = $this->findAll(1);
                    foreach($data as $username => $items)
                    {
                        foreach($items as $item)
                        {
                            $new[$username] = ceil($item->getUsage() / 1024 / 1024);
                        }
                    }
                    $new['free'] = $free;
                    $data = $new;
                }
                else
                {
                    $free = ceil($storageInfo['free'] / 1024 / 1024);
                    $used = ceil($storageInfo['used'] / 1024 / 1024);
                    $data = array(
                        'used' => $used,
                        'free' => $free
                    );
                }
                break;
        }

        // If an adapter has been defined, format the data, else just return data parsed by the system
        $adapter = '\OCA\ocUsageCharts\ChartType\\' .  $config->getChartProvider() . '\Adapters\\' . $config->getChartType() . 'Adapter';
        if ( class_exists($adapter) )
        {
            $chartAdapter = new $adapter($config);
            return $chartAdapter->formatData($data);
        }
        return $data;
    }