本文整理汇总了PHP中display_size函数的典型用法代码示例。如果您正苦于以下问题:PHP display_size函数的具体用法?PHP display_size怎么用?PHP display_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了display_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: definition_inner
/**
* Add question-type specific form fields.
*
* @param MoodleQuickForm $mform the form being built.
*/
function definition_inner(&$mform)
{
global $COURSE, $CFG;
// don't need these default elements :
$mform->removeElement('defaultgrade');
$mform->removeElement('penalty');
$mform->addElement('html', '<a target="_new" href="' . $CFG->wwwroot . '/files/index.php?id=' . $COURSE->id . '">' . get_string("openinnewwindow", "qtype_imagedit") . '</a>');
// this element will hold the URL of the HTML's IMG SRC value
// of the altered image file that was uploaded by the user
// to the current course's "users" folder
//$mform->addElement('hidden', 'imgurl', '');
// add feedback
$mform->addElement('htmleditor', 'feedback', get_string("feedback", "quiz"));
$mform->setType('feedback', PARAM_RAW);
// add default elements
$mform->addElement('hidden', 'defaultgrade', 0);
$mform->addElement('hidden', 'fraction', 0);
// add max upload limit menu
$choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
$choices[0] = get_string('courseuploadlimit') . ' (' . display_size($COURSE->maxbytes) . ')';
$mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
$mform->setDefault('maxbytes', $COURSE->maxbytes);
// add essay area checkbox
$mform->addElement('advcheckbox', 'essay', get_string('addessay', 'qtype_imagedit'), null, null, array(0, 1));
}
示例2: __construct
public function __construct($path = SEARCH_INDEX_PATH)
{
global $CFG, $db;
$this->path = $path;
//test to see if there is a valid index on disk, at the specified path
try {
$test_index = new Zend_Search_Lucene($this->path, false);
$validindex = true;
} catch (Exception $e) {
$validindex = false;
}
//retrieve file system info about the index if it is valid
if ($validindex) {
$this->size = display_size(get_directory_size($this->path));
$index_dir = get_directory_list($this->path, '', false, false);
$this->filecount = count($index_dir);
$this->indexcount = $test_index->count();
} else {
$this->size = 0;
$this->filecount = 0;
$this->indexcount = 0;
}
$db_exists = false;
//for now
//get all the current tables in moodle
$admin_tables = $db->MetaTables();
//TODO: use new IndexDBControl class for database checks?
//check if our search table exists
if (in_array($CFG->prefix . SEARCH_DATABASE_TABLE, $admin_tables)) {
//retrieve database information if it does
$db_exists = true;
//total documents
$this->dbcount = count_records(SEARCH_DATABASE_TABLE);
//individual document types
// $types = search_get_document_types();
$types = search_collect_searchables(true, false);
sort($types);
foreach ($types as $type) {
$c = count_records(SEARCH_DATABASE_TABLE, 'doctype', $type);
$this->types[$type] = (int) $c;
}
} else {
$this->dbcount = 0;
$this->types = array();
}
//check if the busy flag is set
if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
$this->complete = false;
} else {
$this->complete = true;
}
//get the last run date for the indexer
if ($this->valid() && $CFG->search_indexer_run_date) {
$this->time = $CFG->search_indexer_run_date;
} else {
$this->time = 0;
}
}
示例3: onQuickFormEvent
/**
* Override createElement event to add max files
*/
function onQuickFormEvent($event, $arg, &$caller)
{
if ($event == 'createElement') {
$className = get_class($this);
$this->{$className}($arg[0], $arg[1] . ' (' . get_string('maxsize', '', display_size($caller->getMaxFileSize())) . ')', $arg[2]);
return true;
}
return parent::onQuickFormEvent($event, $arg, $caller);
}
示例4: execute
public function execute()
{
global $CFG, $DB;
$options = $this->expandedOptions;
$dataroot = run_external_command("du -s {$CFG->dataroot}", "Couldn't find dataroot directory");
$pattern = '/\\d*/';
preg_match($pattern, $dataroot[0], $matches);
$filedir = run_external_command("du -s {$CFG->dataroot}/filedir", "Couldn't find filedir directory");
preg_match($pattern, $filedir[0], $dir_matches);
$sql_query = "SELECT SUM(filesize) AS total FROM {files}";
$all_files = $DB->get_record_sql($sql_query);
$sql_query = "SELECT DISTINCT contenthash, SUM(filesize) AS total FROM {files}";
if (is_a($DB, 'pgsql_native_moodle_database')) {
$sql_query .= " GROUP BY contenthash";
$distinct_contenthash = $DB->get_records_sql($sql_query);
$total = 0;
foreach ($distinct_contenthash as $k => $v) {
$total += $v->total;
}
$distinctfilestotal = $total;
} else {
$distinct_contenthash = $DB->get_record_sql($sql_query);
$distinctfilestotal = $distinct_contenthash->total;
}
$filesbycourse = array();
if ($courses = get_all_courses()) {
foreach ($courses as $course) {
$subcontexts = get_sub_context_ids($course->ctxpath);
$filesbycourse[$course->id] = array('unique' => 0, 'all' => 0);
foreach ($subcontexts as $subcontext) {
if ($files = get_files($subcontext->id)) {
foreach ($files as $file) {
$filesbycourse[$course->id]['unique'] += file_is_unique($file->contenthash, $subcontext->id) ? $file->filesize : 0;
$filesbycourse[$course->id]['all'] += $file->filesize;
}
}
}
}
}
$sortarray = higher_size($filesbycourse);
$backups = backup_size();
$data = array('dataroot' => $matches[0], 'filedir' => $dir_matches[0], 'files total' => $all_files->total, 'distinct files total' => $distinctfilestotal);
foreach ($sortarray as $courseid => $values) {
$data["Course {$courseid} files total"] = strval($values['all']);
$data["Course {$courseid} files unique"] = strval($values['unique']);
}
foreach ($backups as $key => $values) {
$data["Backup {$values->username}"] = strval($values->backupsize);
}
if ($options['json']) {
echo json_encode($data);
} else {
foreach ($data as $k => $v) {
echo "{$k}: " . display_size($v) . "\n";
}
}
}
示例5: krystle2_performance_output
/**
* get_performance_output() override get_peformance_info()
* in moodlelib.php. Returns a string
* values ready for use.
*
* @return string
*/
function krystle2_performance_output($param) {
$html = '<div class="performanceinfo"><ul>';
if (isset($param['realtime'])) $html .= '<li><a class="red" href="#"><var>'.$param['realtime'].' secs</var><span>Load Time</span></a></li>';
if (isset($param['memory_total'])) $html .= '<li><a class="orange" href="#"><var>'.display_size($param['memory_total']).'</var><span>Memory Used</span></a></li>';
if (isset($param['includecount'])) $html .= '<li><a class="blue" href="#"><var>'.$param['includecount'].' Files </var><span>Included</span></a></li>';
if (isset($param['dbqueries'])) $html .= '<li><a class="purple" href="#"><var>'.$param['dbqueries'].' </var><span>DB Read/Write</span></a></li>';
$html .= '</ul></div>';
return $html;
}
示例6: view_upload_form
function view_upload_form()
{
global $CFG;
$struploadafile = get_string("uploadafile");
$strmaxsize = get_string("maxsize", "", display_size($this->wqmaxbytes));
echo '<center>';
echo '<form enctype="multipart/form-data" method="post" ' . "action=\"{$CFG->wwwroot}/mod/webquestscorm/upload.php\">";
echo "<p>{$struploadafile} ({$strmaxsize})</p>";
echo '<input type="hidden" name="cmid" value="' . $this->cm->id . '" />';
require_once $CFG->libdir . '/uploadlib.php';
upload_print_form_fragment(1, array('newfile'), false, null, 0, $this->wqmaxbytes, false);
echo '<input type="submit" name="save" value="' . get_string('uploadthisfile') . '" />';
echo '</form>';
echo '</center>';
}
示例7: print_table
function print_table($data)
{
$table = new html_table();
$table->head = array(get_string('lastcrawledtime', 'local_linkchecker_robot'), get_string('linktext', 'local_linkchecker_robot'), get_string('idattr', 'local_linkchecker_robot'), get_string('response', 'local_linkchecker_robot'), get_string('size', 'local_linkchecker_robot'), get_string('url', 'local_linkchecker_robot'), get_string('mimetype', 'local_linkchecker_robot'));
$table->data = array();
foreach ($data as $row) {
$text = trim($row->title);
if (!$text || $text == "") {
$text = get_string('unknown', 'local_linkchecker_robot');
}
$code = local_linkchecker_robot_http_code($row);
$size = $row->filesize * 1;
$data = array(userdate($row->lastcrawled, '%h %e, %H:%M:%S'), $row->text, str_replace(' #', '<br>#', $row->idattr), $code, display_size($size), local_linkchecker_robot_link($row->target, $text, $row->redirect), $row->mimetype);
$table->data[] = $data;
}
echo html_writer::table($table);
}
示例8: view_upload_form
function view_upload_form()
{
global $CFG;
$struploadafile = get_string("uploadafile");
$maxbytes = $this->assignment->maxbytes == 0 ? $this->course->maxbytes : $this->assignment->maxbytes;
$strmaxsize = get_string('maxsize', '', display_size($maxbytes));
echo '<div style="text-align:center">';
echo '<form enctype="multipart/form-data" method="post" ' . "action=\"{$CFG->wwwroot}/mod/assignment/upload-embedded.php\">";
echo '<fieldset class="invisiblefieldset">';
echo "<p>{$struploadafile} ({$strmaxsize})</p>";
echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />';
require_once $CFG->libdir . '/uploadlib.php';
upload_print_form_fragment(1, array('newfile'), false, null, 0, $this->assignment->maxbytes, false);
echo '<input type="submit" name="save" value="' . get_string('uploadthisfile') . '" />';
echo '</fieldset>';
echo '</form>';
echo '</div>';
}
示例9: definition_inner
/**
* Add question-type specific form fields.
*
* @param MoodleQuickForm $mform the form being built.
*/
function definition_inner(&$mform)
{
global $COURSE, $CFG;
// don't need these default elements :
$mform->removeElement('defaultgrade');
$mform->removeElement('penalty');
// add feedback
$mform->addElement('htmleditor', 'feedback', get_string("feedback", "quiz"));
$mform->setType('feedback', PARAM_RAW);
// add default elements
$mform->addElement('hidden', 'defaultgrade', 0);
$mform->addElement('hidden', 'fraction', 0);
// add max upload limit menu
$choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
$choices[0] = get_string('courseuploadlimit') . ' (' . display_size($COURSE->maxbytes) . ')';
$mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
$mform->setDefault('maxbytes', $COURSE->maxbytes);
// add essay area checkbox
$mform->addElement('advcheckbox', 'essay', get_string('addessay', 'qtype_fileresponse'), null, null, array(0, 1));
}
示例10: render_instance
public static function render_instance(BlockInstance $instance, $editing = false)
{
require_once get_config('docroot') . 'artefact/lib.php';
$configdata = $instance->get('configdata');
$result = '';
if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) {
foreach ($configdata['artefactids'] as $artefactid) {
try {
$artefact = $instance->get_artefact_instance($artefactid);
} catch (ArtefactNotFoundException $e) {
continue;
}
$icondata = array('id' => $artefactid, 'viewid' => $instance->get('view'));
$detailsurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view');
if ($artefact instanceof ArtefactTypeProfileIcon) {
require_once 'file.php';
$downloadurl = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $artefactid;
$size = filesize(get_dataroot_image_path('artefact/file/profileicons/', $artefactid));
} else {
if ($artefact instanceof ArtefactTypeFile) {
$downloadurl = get_config('wwwroot') . 'artefact/file/download.php?file=' . $artefactid . '&view=' . $icondata['viewid'];
$size = $artefact->get('size');
}
}
$result .= '<div title="' . hsc($artefact->get('title')) . '">';
$result .= '<div class="fl"><a href="' . hsc($downloadurl) . '">';
$result .= '<img src="' . hsc(call_static_method(generate_artefact_class_name($artefact->get('artefacttype')), 'get_icon', $icondata)) . '" alt=""></a></div>';
$result .= '<div style="margin-left: 30px;">';
$result .= '<h4><a href="' . hsc($detailsurl) . '">' . str_shorten_text($artefact->get('title'), 20) . '</a></h4>';
$description = $artefact->get('description');
if ($description) {
$result .= '<p style="margin: 0;"><strong>' . hsc($description) . '</strong></p>';
}
$result .= '' . display_size($size) . ' | ' . strftime(get_string('strftimedaydate'), $artefact->get('ctime'));
$result .= '</div>';
$result .= '</div>';
}
}
return $result;
}
示例11: Dwoo_Plugin_mahara_performance_info
/**
* Dwoo {mahara_performance_info} function plugin
*
* Type: function<br>
* Name: mahara_performance_info<br>
* Date: June 22, 2006<br>
* Purpose: Fetch internationalized strings
* @author Catalyst IT Ltd
* @version 1.0
* @return html to display in the footer.
*/
function Dwoo_Plugin_mahara_performance_info(Dwoo $dwoo)
{
if (!get_config('perftofoot') && !get_config('perftolog')) {
return;
}
$info = get_performance_info();
$dwoo = smarty_core();
foreach ($info as $key => $value) {
if ($key == 'realtime') {
$value = round($value, 3);
}
$dwoo->assign('perf_' . $key, $value);
}
// extras
$dwoo->assign('perf_memory_total_display', display_size($info['memory_total']));
$dwoo->assign('perf_memory_growth_display', display_size($info['memory_growth']));
if (get_config('perftolog')) {
perf_to_log($info);
}
if (get_config('perftofoot')) {
return $dwoo->fetch('performancefooter.tpl');
}
}
示例12: adduser_validate
function adduser_validate(Pieform $form, $values)
{
global $USER, $TRANSPORTER;
$authobj = AuthFactory::create($values['authinstance']);
$institution = $authobj->institution;
// Institutional admins can only set their own institutions' authinstances
if (!$USER->get('admin') && !$USER->is_institutional_admin($authobj->institution)) {
$form->set_error('authinstance', get_string('notadminforinstitution', 'admin'));
return;
}
$institution = new Institution($authobj->institution);
// Don't exceed max user accounts for the institution
if ($institution->isFull()) {
$institution->send_admin_institution_is_full_message();
$form->set_error('authinstance', get_string('institutionmaxusersexceeded', 'admin'));
return;
}
$username = $values['username'];
$firstname = sanitize_firstname($values['firstname']);
$lastname = sanitize_lastname($values['lastname']);
$email = sanitize_email($values['email']);
$password = $values['password'];
if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
$maxquotaenabled = get_config_plugin('artefact', 'file', 'maxquotaenabled');
$maxquota = get_config_plugin('artefact', 'file', 'maxquota');
if ($maxquotaenabled && $values['quota'] > $maxquota) {
$form->set_error('quota', get_string('maxquotaexceededform', 'artefact.file', display_size($maxquota)));
}
}
if (method_exists($authobj, 'is_username_valid_admin')) {
if (!$authobj->is_username_valid_admin($username)) {
$form->set_error('username', get_string('usernameinvalidadminform', 'auth.internal'));
}
} else {
if (method_exists($authobj, 'is_username_valid')) {
if (!$authobj->is_username_valid($username)) {
$form->set_error('username', get_string('usernameinvalidform', 'auth.internal'));
}
}
}
if (!$form->get_error('username') && record_exists_select('usr', 'LOWER(username) = ?', array(strtolower($username)))) {
$form->set_error('username', get_string('usernamealreadytaken', 'auth.internal'));
}
if (method_exists($authobj, 'is_password_valid') && !$authobj->is_password_valid($password)) {
$form->set_error('password', get_string('passwordinvalidform', 'auth.' . $authobj->type));
}
if (isset($_POST['createmethod']) && $_POST['createmethod'] == 'leap2a') {
$form->set_error('firstname', null);
$form->set_error('lastname', null);
$form->set_error('email', null);
if (!$values['leap2afile'] && ($_FILES['leap2afile']['error'] == UPLOAD_ERR_INI_SIZE || $_FILES['leap2afile']['error'] == UPLOAD_ERR_FORM_SIZE)) {
$form->reply(PIEFORM_ERR, array('message' => get_string('uploadedfiletoobig'), 'goto' => '/admin/users/add.php'));
$form->set_error('leap2afile', get_string('uploadedfiletoobig'));
return;
} else {
if (!$values['leap2afile']) {
$form->set_error('leap2afile', $form->i18n('rule', 'required', 'required'));
return;
}
}
if ($values['leap2afile']['type'] == 'application/octet-stream') {
require_once 'file.php';
$mimetype = file_mime_type($values['leap2afile']['tmp_name']);
} else {
$mimetype = trim($values['leap2afile']['type'], '"');
}
$date = time();
$niceuser = preg_replace('/[^a-zA-Z0-9_-]/', '-', $values['username']);
safe_require('import', 'leap');
$fakeimportrecord = (object) array('data' => array('importfile' => $values['leap2afile']['tmp_name'], 'importfilename' => $values['leap2afile']['name'], 'importid' => $niceuser . '-' . $date, 'mimetype' => $mimetype));
$TRANSPORTER = new LocalImporterTransport($fakeimportrecord);
try {
$TRANSPORTER->extract_file();
PluginImportLeap::validate_transported_data($TRANSPORTER);
} catch (Exception $e) {
$form->set_error('leap2afile', $e->getMessage());
}
} else {
if (!$form->get_error('firstname') && empty($firstname)) {
$form->set_error('firstname', $form->i18n('rule', 'required', 'required'));
}
if (!$form->get_error('lastname') && empty($lastname)) {
$form->set_error('lastname', $form->i18n('rule', 'required', 'required'));
}
if (!$form->get_error('email')) {
if (!$form->get_error('email') && empty($email)) {
$form->set_error('email', get_string('invalidemailaddress', 'artefact.internal'));
}
if (record_exists('usr', 'email', $email) || record_exists('artefact_internal_profile_email', 'email', $email)) {
$form->set_error('email', get_string('emailalreadytaken', 'auth.internal'));
}
}
}
}
示例13: get_performance_info
/**
* get_performance_info() pairs up with init_performance_info()
* loaded in setup.php. Returns an array with 'html' and 'txt'
* values ready for use, and each of the individual stats provided
* separately as well.
*
* @return array
*/
function get_performance_info()
{
global $CFG, $PERF, $DB, $PAGE;
$info = array();
$info['txt'] = me() . ' ';
// Holds log-friendly representation.
$info['html'] = '';
if (!empty($CFG->themedesignermode)) {
// Attempt to avoid devs debugging peformance issues, when its caused by css building and so on.
$info['html'] .= '<p><strong>Warning: Theme designer mode is enabled.</strong></p>';
}
$info['html'] .= '<ul class="list-unstyled m-l-1">';
// Holds userfriendly HTML representation.
$info['realtime'] = microtime_diff($PERF->starttime, microtime());
$info['html'] .= '<li class="timeused">' . $info['realtime'] . ' secs</li> ';
$info['txt'] .= 'time: ' . $info['realtime'] . 's ';
if (function_exists('memory_get_usage')) {
$info['memory_total'] = memory_get_usage();
$info['memory_growth'] = memory_get_usage() - $PERF->startmemory;
$info['html'] .= '<li class="memoryused">RAM: ' . display_size($info['memory_total']) . '</li> ';
$info['txt'] .= 'memory_total: ' . $info['memory_total'] . 'B (' . display_size($info['memory_total']) . ') memory_growth: ' . $info['memory_growth'] . 'B (' . display_size($info['memory_growth']) . ') ';
}
if (function_exists('memory_get_peak_usage')) {
$info['memory_peak'] = memory_get_peak_usage();
$info['html'] .= '<li class="memoryused">RAM peak: ' . display_size($info['memory_peak']) . '</li> ';
$info['txt'] .= 'memory_peak: ' . $info['memory_peak'] . 'B (' . display_size($info['memory_peak']) . ') ';
}
$inc = get_included_files();
$info['includecount'] = count($inc);
$info['html'] .= '<li class="included">Included ' . $info['includecount'] . ' files</li> ';
$info['txt'] .= 'includecount: ' . $info['includecount'] . ' ';
if (!empty($CFG->early_install_lang) or empty($PAGE)) {
// We can not track more performance before installation or before PAGE init, sorry.
return $info;
}
$filtermanager = filter_manager::instance();
if (method_exists($filtermanager, 'get_performance_summary')) {
list($filterinfo, $nicenames) = $filtermanager->get_performance_summary();
$info = array_merge($filterinfo, $info);
foreach ($filterinfo as $key => $value) {
$info['html'] .= "<li class='{$key}'>{$nicenames[$key]}: {$value} </li> ";
$info['txt'] .= "{$key}: {$value} ";
}
}
$stringmanager = get_string_manager();
if (method_exists($stringmanager, 'get_performance_summary')) {
list($filterinfo, $nicenames) = $stringmanager->get_performance_summary();
$info = array_merge($filterinfo, $info);
foreach ($filterinfo as $key => $value) {
$info['html'] .= "<li class='{$key}'>{$nicenames[$key]}: {$value} </li> ";
$info['txt'] .= "{$key}: {$value} ";
}
}
if (!empty($PERF->logwrites)) {
$info['logwrites'] = $PERF->logwrites;
$info['html'] .= '<li class="logwrites">Log DB writes ' . $info['logwrites'] . '</li> ';
$info['txt'] .= 'logwrites: ' . $info['logwrites'] . ' ';
}
$info['dbqueries'] = $DB->perf_get_reads() . '/' . ($DB->perf_get_writes() - $PERF->logwrites);
$info['html'] .= '<li class="dbqueries">DB reads/writes: ' . $info['dbqueries'] . '</li> ';
$info['txt'] .= 'db reads/writes: ' . $info['dbqueries'] . ' ';
$info['dbtime'] = round($DB->perf_get_queries_time(), 5);
$info['html'] .= '<li class="dbtime">DB queries time: ' . $info['dbtime'] . ' secs</li> ';
$info['txt'] .= 'db queries time: ' . $info['dbtime'] . 's ';
if (function_exists('posix_times')) {
$ptimes = posix_times();
if (is_array($ptimes)) {
foreach ($ptimes as $key => $val) {
$info[$key] = $ptimes[$key] - $PERF->startposixtimes[$key];
}
$info['html'] .= "<li class=\"posixtimes\">ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']}</li> ";
$info['txt'] .= "ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']} ";
}
}
// Grab the load average for the last minute.
// /proc will only work under some linux configurations
// while uptime is there under MacOSX/Darwin and other unices.
if (is_readable('/proc/loadavg') && ($loadavg = @file('/proc/loadavg'))) {
list($serverload) = explode(' ', $loadavg[0]);
unset($loadavg);
} else {
if (function_exists('is_executable') && is_executable('/usr/bin/uptime') && ($loadavg = `/usr/bin/uptime`)) {
if (preg_match('/load averages?: (\\d+[\\.,:]\\d+)/', $loadavg, $matches)) {
$serverload = $matches[1];
} else {
trigger_error('Could not parse uptime output!');
}
}
}
if (!empty($serverload)) {
$info['serverload'] = $serverload;
$info['html'] .= '<li class="serverload">Load average: ' . $info['serverload'] . '</li> ';
//.........这里部分代码省略.........
示例14: define
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
define('INSTITUTIONALADMIN', 1);
require dirname(dirname(dirname(__FILE__))) . '/init.php';
require_once 'pieforms/pieform/elements/bytes.php';
$instid = param_integer('instid');
$disabled = param_boolean('disabled', false);
$definst = get_field('auth_instance', 'id', 'institution', 'mahara');
$record = get_record_sql('SELECT i.name, i.defaultquota FROM {institution} i JOIN {auth_instance} ai ON (i.name = ai.institution) WHERE ai.id = ?', array($instid));
if (!$USER->get('admin') && !$USER->is_institutional_admin($record->name)) {
json_reply(true, 'You are not an administrator for institution ' . $record->name);
return;
}
if ($definst && $instid == $definst) {
$quota = get_config_plugin('artefact', 'file', 'defaultquota');
} else {
$quota = $record->defaultquota;
if (!$quota) {
$quota = get_config_plugin('artefact', 'file', 'defaultquota');
}
}
$data = array('data' => $disabled ? display_size($quota) : pieform_element_bytes_get_bytes_from_bytes($quota), 'error' => false, 'message' => null);
json_reply(false, $data);
示例15: file_get_drafarea_files
/**
* Listing all files (including folders) in current path (draft area)
* used by file manager
* @param int $draftitemid
* @param string $filepath
* @return stdClass
*/
function file_get_drafarea_files($draftitemid, $filepath = '/')
{
global $USER, $OUTPUT, $CFG;
$context = context_user::instance($USER->id);
$fs = get_file_storage();
$data = new stdClass();
$data->path = array();
$data->path[] = array('name' => get_string('files'), 'path' => '/');
// will be used to build breadcrumb
$trail = '/';
if ($filepath !== '/') {
$filepath = file_correct_filepath($filepath);
$parts = explode('/', $filepath);
foreach ($parts as $part) {
if ($part != '' && $part != null) {
$trail .= $part . '/';
$data->path[] = array('name' => $part, 'path' => $trail);
}
}
}
$list = array();
$maxlength = 12;
if ($files = $fs->get_directory_files($context->id, 'user', 'draft', $draftitemid, $filepath, false)) {
foreach ($files as $file) {
$item = new stdClass();
$item->filename = $file->get_filename();
$item->filepath = $file->get_filepath();
$item->fullname = trim($item->filename, '/');
$filesize = $file->get_filesize();
$item->size = $filesize ? $filesize : null;
$item->filesize = $filesize ? display_size($filesize) : '';
$item->sortorder = $file->get_sortorder();
$item->author = $file->get_author();
$item->license = $file->get_license();
$item->datemodified = $file->get_timemodified();
$item->datecreated = $file->get_timecreated();
$item->isref = $file->is_external_file();
if ($item->isref && $file->get_status() == 666) {
$item->originalmissing = true;
}
// find the file this draft file was created from and count all references in local
// system pointing to that file
$source = @unserialize($file->get_source());
if (isset($source->original)) {
$item->refcount = $fs->search_references_count($source->original);
}
if ($file->is_directory()) {
$item->filesize = 0;
$item->icon = $OUTPUT->pix_url(file_folder_icon(24))->out(false);
$item->type = 'folder';
$foldername = explode('/', trim($item->filepath, '/'));
$item->fullname = trim(array_pop($foldername), '/');
$item->thumbnail = $OUTPUT->pix_url(file_folder_icon(90))->out(false);
} else {
// do NOT use file browser here!
$item->mimetype = get_mimetype_description($file);
if (file_extension_in_typegroup($file->get_filename(), 'archive')) {
$item->type = 'zip';
} else {
$item->type = 'file';
}
$itemurl = moodle_url::make_draftfile_url($draftitemid, $item->filepath, $item->filename);
$item->url = $itemurl->out();
$item->icon = $OUTPUT->pix_url(file_file_icon($file, 24))->out(false);
$item->thumbnail = $OUTPUT->pix_url(file_file_icon($file, 90))->out(false);
if ($imageinfo = $file->get_imageinfo()) {
$item->realthumbnail = $itemurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified()));
$item->realicon = $itemurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
$item->image_width = $imageinfo['width'];
$item->image_height = $imageinfo['height'];
}
}
$list[] = $item;
}
}
$data->itemid = $draftitemid;
$data->list = $list;
return $data;
}