/** * Calculates the amount of disk space used * Redirects to storage exceeded view if amount is past limit * * @param string $type Soft/Hard * @param bool $redirect Redirect if over quota? * @return void */ private function _getDiskUsage($type = 'soft', $redirect = true) { // Check that the user is logged in if (User::isGuest()) { $this->loginTask(); return; } bcscale(6); $du = \Components\Tools\Helpers\Utils::getDiskUsage(User::get('username')); if (isset($du['space'])) { if (strtolower($type) == 'hard') { $val = $du['hardspace'] != 0 ? bcdiv($du['space'], $du['hardspace']) : 0; } else { $val = $du['softspace'] != 0 ? bcdiv($du['space'], $du['softspace']) : 0; } } else { $val = 0; } $percent = round($val * 100); $percent = $percent > 100 ? 100 : $percent; if (isset($du['softspace'])) { $total = $du['softspace'] / 1024000000; } else { $total = 0; } $this->remaining = isset($du['remaining']) ? $du['remaining'] : 0; $this->percent = $percent; $this->total = $total; //if ($this->percent >= 100 && $this->remaining == 0) { if ($this->percent >= 100 && $redirect) { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=storageexceeded')); } }
/** * Display how much disk usage is being used * * @return void */ public function diskusageTask() { // Check that the user is logged in if (User::isGuest()) { $this->_login(); return; } $msgs = Request::getInt('msgs', 0); $du = \Components\Tools\Helpers\Utils::getDiskUsage(User::get('username')); if (count($du) <= 1) { // error $percent = 0; } else { bcscale(6); $val = isset($du['softspace']) && $du['softspace'] != 0 ? bcdiv($du['space'], $du['softspace']) : 0; $percent = round($val * 100); } $amt = $percent > 100 ? '100' : $percent; $total = isset($du['softspace']) ? $du['softspace'] / 1024000000 : 0; $this->view->amt = $amt; $this->view->total = $total; $this->view->du = $du; $this->view->percent = $percent; $this->view->msgs = $msgs; $this->view->ajax = 1; $this->view->writelink = 1; foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->display(); }
<?php if ($this->params->get('show_storage', 1)) { ?> <div class="session-storage"> <span><?php echo Lang::txt('MOD_MYSESSIONS_STORAGE'); ?> (<a href="<?php echo Route::url('index.php?option=com_tools&task=storage'); ?> "><?php echo Lang::txt('MOD_MYSESSIONS_MANAGE'); ?> </a>)</span> <?php $diskUsage = \Components\Tools\Helpers\Utils::getDiskUsage(User::get('username')); if (!is_array($diskUsage) || !isset($diskUsage['space'])) { echo '<p class="error">' . Lang::txt('MOD_MYSESSIONS_ERROR_RETRIEVING_STORAGE') . '</p></div>'; return; } else { if (isset($diskUsage['softspace']) && $diskUsage['softspace'] == 0) { echo '<p class="info">' . Lang::txt('MOD_MYSESSIONS_NO_QUOTA') . '</p></div>'; return; } else { // Calculate the percentage of spaced used bcscale(6); $total = $diskUsage['softspace'] / 1024000000; $val = $diskUsage['softspace'] > 0 ? bcdiv($diskUsage['space'], $diskUsage['softspace']) : 0; $percent = round($val * 100); $percent = $percent > 100 ? 100 : $percent; // Amount can only have a max of 100 due to some display restrictions
/** * Method to return users storage results * * @apiMethod GET * @apiUri /tools/{user_id} * @return void */ public function storageTask() { $this->requiresAuthentication(); // get the userid and attempt to load user profile $userid = App::get('authn')['user_id']; $result = User::getInstance($userid); // make sure we have a user if (!$result->get('id')) { throw new Exception(Lang::txt('Unable to find user.'), 404); } // get request vars $type = Request::getVar('type', 'soft'); // get storage quota require_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'utils.php'; $disk_usage = \Components\Tools\Helpers\Utils::getDiskUsage($result->get('username')); // get the tools storage path $com_tools_params = Component::params('com_tools'); $path = DS . $com_tools_params->get('storagepath', 'webdav' . DS . 'home') . DS . $result->get('username'); // get a list of files $files = array(); //$files = Filesystem::files($path, '.', true, true, array('.svn', 'CVS')); // return result $object = new stdClass(); $object->storage = array('quota' => $disk_usage, 'files' => $files); $this->send($object); }
/** * Get a resource based on tool name * * @apiMethod GET * @apiUri /members/{id}/tools/diskusage * @apiParameter { * "name": "id", * "description": "Member identifier", * "type": "integer", * "required": true, * "default": null * } * @return void */ public function diskusageTask() { $this->requiresAuthentication(); $userid = App::get('authn')['user_id']; $result = User::getInstance($userid); if ($result === false) { throw new Exception(Lang::txt('COM_MEMBERS_ERROR_USER_NOT_FOUND'), 404); } require_once Component::path('com_tools') . DS . 'helpers' . DS . 'utils.php'; $du = \Components\Tools\Helpers\Utils::getDiskUsage($result->get('username')); if (count($du) <= 1) { // Error $percent = 0; } else { bcscale(6); $val = isset($du['softspace']) && $du['softspace'] != 0 ? bcdiv($du['space'], $du['softspace']) : 0; $percent = round($val * 100); } $amt = $percent > 100 ? '100' : $percent; $total = isset($du['softspace']) ? $du['softspace'] / 1024000000 : 0; // Encode sessions for return $object = new stdClass(); $object->amount = $amt; $object->total = $total; $this->send($object); }