/** * Internal function - creates htmls structure suitable for YUI tree. */ protected function htmllize_tree($tree, $dir) { global $CFG; if (empty($dir['subdirs']) and empty($dir['files'])) { return ''; } $browser = get_file_browser(); $result = '<ul>'; foreach ($dir['subdirs'] as $subdir) { $image = $this->output->pix_icon(file_folder_icon(24), $subdir['dirname'], 'moodle'); $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', s($subdir['dirname']), array('class' => 'fp-filename')); $filename = html_writer::tag('div', $filename, array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename. $this->htmllize_tree($tree, $subdir)); } foreach ($dir['files'] as $file) { $fileinfo = $browser->get_file_info($tree->context, $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); $url = $fileinfo->get_url(true); $filename = $file->get_filename(); if ($imageinfo = $fileinfo->get_imageinfo()) { $fileurl = new moodle_url($fileinfo->get_url()); $image = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $fileinfo->get_timemodified())); $image = html_writer::empty_tag('img', array('src' => $image)); } else { $image = $this->output->pix_icon(file_file_icon($file, 24), $filename, 'moodle'); } $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', $filename, array('class' => 'fp-filename')); $filename = html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename); } $result .= '</ul>'; return $result; }
/** * Returns a list of files the user has formated for files api * * @param string $path the path which we are in * @return mixed Array of files formated for fileapoi */ public function get_file_list($path = '') { global $OUTPUT; if (empty($path)) { $url = self::API . "/me/skydrive/files/"; } else { $url = self::API . "/{$path}/files/"; } $ret = json_decode($this->get($url)); if (isset($ret->error)) { $this->log_out(); return false; } $files = array(); foreach ($ret->data as $file) { switch ($file->type) { case 'folder': $files[] = array('title' => $file->name, 'path' => $file->id, 'size' => 0, 'date' => strtotime($file->updated_time), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'children' => array()); break; case 'photo': $files[] = array('title' => $file->name, 'size' => $file->size, 'date' => strtotime($file->updated_time), 'thumbnail' => $file->picture, 'source' => $file->id, 'url' => $file->link); break; case 'video': $files[] = array('title' => $file->name, 'size' => $file->size, 'date' => strtotime($file->updated_time), 'thumbnail' => $file->picture, 'source' => $file->id, 'url' => $file->link); break; case 'audio': $files[] = array('title' => $file->name, 'size' => $file->size, 'date' => strtotime($file->updated_time), 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file->name, 90))->out(false), 'source' => $file->id, 'url' => $file->link); break; case 'file': $files[] = array('title' => $file->name, 'size' => $file->size, 'date' => strtotime($file->updated_time), 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file->name, 90))->out(false), 'source' => $file->id, 'url' => $file->link); break; } } return $files; }
/** * Get S3 file list * * @param string $path * @return array The file list and options */ public function get_listing($path = '', $page = '') { global $CFG, $OUTPUT; if (empty($this->access_key)) { die(json_encode(array('e' => get_string('needaccesskey', 'repository_s3')))); } $list = array(); $list['list'] = array(); // the management interface url $list['manage'] = false; // dynamically loading $list['dynload'] = true; // the current path of this list. // set to true, the login link will be removed $list['nologin'] = true; // set to true, the search button will be removed $list['nosearch'] = true; $tree = array(); if (empty($path)) { $buckets = $this->s->listBuckets(); foreach ($buckets as $bucket) { $folder = array('title' => $bucket, 'children' => array(), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'path' => $bucket); $tree[] = $folder; } } else { $contents = $this->s->getBucket($path); foreach ($contents as $file) { $info = $this->s->getObjectInfo($path, baseName($file['name'])); $tree[] = array('title' => $file['name'], 'size' => $file['size'], 'date' => userdate($file['time']), 'source' => $path . '/' . $file['name'], 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file['name'], 90))->out(false)); } } $list['list'] = $tree; return $list; }
/** * Internal function - creates htmls structure suitable for YUI tree. */ protected function htmllize_tree($tree, $dir) { global $CFG; $yuiconfig = array(); $yuiconfig['type'] = 'html'; if (empty($dir['subdirs']) and empty($dir['files'])) { return ''; } $result = '<ul>'; foreach ($dir['subdirs'] as $subdir) { $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon')); $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>'; } foreach ($dir['files'] as $file) { $filename = $file->get_filename(); if ($CFG->enableplagiarism) { require_once($CFG->libdir.'/plagiarismlib.php'); $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course)); } else { $plagiarsmlinks = ''; } $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon')); $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>'; } $result .= '</ul>'; return $result; }
protected function get_other_values(renderer_base $output) { $filename = $this->file->get_filename(); $filenameshort = $filename; if (core_text::strlen($filename) > 25) { $filenameshort = shorten_text(substr($filename, 0, -4), 21, true, '..'); $filenameshort .= substr($filename, -4); } $icon = $this->file->is_directory() ? file_folder_icon() : file_file_icon($this->file); $iconurl = $output->pix_url($icon, 'core'); $url = moodle_url::make_pluginfile_url($this->file->get_contextid(), $this->file->get_component(), $this->file->get_filearea(), $this->file->get_itemid(), $this->file->get_filepath(), $this->file->get_filename(), true); return array('filenameshort' => $filenameshort, 'filesizeformatted' => display_size((int) $this->file->get_filesize()), 'icon' => $icon, 'iconurl' => $iconurl->out(false), 'url' => $url->out(false), 'timecreatedformatted' => userdate($this->file->get_timecreated()), 'timemodifiedformatted' => userdate($this->file->get_timemodified())); }
/** * Get file listing * * @param string $path * @param string $path not used by this plugin * @return mixed */ public function get_listing($path = '', $page = '') { global $USER, $OUTPUT; $itemid = optional_param('itemid', 0, PARAM_INT); $env = optional_param('env', 'filepicker', PARAM_ALPHA); $ret = array('dynload' => true, 'nosearch' => true, 'nologin' => true, 'list' => array()); if (empty($itemid) || $env !== 'editor') { return $ret; } // In the most cases files embedded in textarea do not have subfolders. Do not show path by default. $retpath = array(array('name' => get_string('files'), 'path' => '')); if (!empty($path)) { $pathchunks = preg_split('|/|', trim($path, '/')); foreach ($pathchunks as $i => $chunk) { $retpath[] = array('name' => $chunk, 'path' => '/' . join('/', array_slice($pathchunks, 0, $i + 1)) . '/'); } $ret['path'] = $retpath; // Show path if already inside subfolder. } $context = context_user::instance($USER->id); $fs = get_file_storage(); $files = $fs->get_directory_files($context->id, 'user', 'draft', $itemid, empty($path) ? '/' : $path, false, true); foreach ($files as $file) { if ($file->is_directory()) { $node = array('title' => basename($file->get_filepath()), 'path' => $file->get_filepath(), 'children' => array(), 'datemodified' => $file->get_timemodified(), 'datecreated' => $file->get_timecreated(), 'icon' => $OUTPUT->pix_url(file_folder_icon(24))->out(false), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false)); $ret['list'][] = $node; $ret['path'] = $retpath; // Show path if subfolders exist. continue; } $fileurl = moodle_url::make_draftfile_url($itemid, $file->get_filepath(), $file->get_filename()); $node = array('title' => $file->get_filename(), 'size' => $file->get_filesize(), 'source' => $fileurl->out(), 'datemodified' => $file->get_timemodified(), 'datecreated' => $file->get_timecreated(), 'author' => $file->get_author(), 'license' => $file->get_license(), 'isref' => $file->is_external_file(), 'icon' => $OUTPUT->pix_url(file_file_icon($file, 24))->out(false), 'thumbnail' => $OUTPUT->pix_url(file_file_icon($file, 90))->out(false)); if ($file->get_status() == 666) { $node['originalmissing'] = true; } if ($imageinfo = $file->get_imageinfo()) { $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified())); $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified())); $node['image_width'] = $imageinfo['width']; $node['image_height'] = $imageinfo['height']; } $ret['list'][] = $node; } $ret['list'] = array_filter($ret['list'], array($this, 'filter')); return $ret; }
public function render_files_tree_viewer(files_tree_viewer $tree) { $html = $this->output->heading_with_help(get_string('coursefiles'), 'courselegacyfiles', 'moodle'); $html .= $this->output->container_start('coursefilesbreadcrumb'); foreach($tree->path as $path) { $html .= $path; $html .= ' / '; } $html .= $this->output->container_end(); $html .= $this->output->box_start(); $table = new html_table(); $table->head = array(get_string('name'), get_string('lastmodified'), get_string('size', 'repository'), get_string('type', 'repository')); $table->align = array('left', 'left', 'left', 'left'); $table->width = '100%'; $table->data = array(); foreach ($tree->tree as $file) { $filedate = $filesize = $filetype = ''; if ($file['filedate']) { $filedate = userdate($file['filedate'], get_string('strftimedatetimeshort', 'langconfig')); } if (empty($file['isdir'])) { if ($file['filesize']) { $filesize = display_size($file['filesize']); } $fileicon = file_file_icon($file, 24); $filetype = get_mimetype_description($file); } else { $fileicon = file_folder_icon(24); } $table->data[] = array( html_writer::link($file['url'], $this->output->pix_icon($fileicon, get_string('icon')) . ' ' . $file['filename']), $filedate, $filesize, $filetype ); } $html .= html_writer::table($table); $html .= $this->output->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid'=>$tree->context->id)), get_string('coursefilesedit'), 'get'); $html .= $this->output->box_end(); return $html; }
function get_listing($path = '', $page = '') { global $OUTPUT; if (!empty($path)) { $pathArray = json_decode($path); } else { $pathArray = array(array('name' => '', 'type' => 'top-communities')); } $list = array(); $list['nologin'] = true; $list['dynload'] = true; $list['nosearch'] = true; $list['list'] = array(); $lastPath = (array) end($pathArray); $results = $this->getChildrenByType($lastPath); foreach ($results as $result) { $itemPath = $pathArray; $itemPath[] = array('name' => $result->name, 'id' => $result->id, 'type' => $result->type); if ($result->countItems === 0) { continue; } $baseElement = array('title' => $result->name); switch ($result->type) { case 'community': case 'collection': case 'item': $typeOptions = array('children' => array(), 'dynload' => true, 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(64))->out(false), 'path' => json_encode($itemPath)); break; case 'bitstream': $typeOptions = array('thumbnail' => $OUTPUT->pix_url(file_extension_icon($result->name, 64))->out(false), 'url' => $this->rest_url . 'bitstreams/' . $result->id . '/retrieve', 'source' => $this->rest_url . 'bitstreams/' . $result->id . '/retrieve'); break; } $list['list'][] = array_merge($baseElement, $typeOptions); } $list['path'] = array(); while (count($pathArray) > 0) { $lastItem = (array) end($pathArray); array_unshift($list['path'], array('path' => json_encode($pathArray), 'name' => strlen($lastItem['name']) <= 20 ? $lastItem['name'] : substr($lastItem['name'], 0, 17) . '...')); array_pop($pathArray); } return $list; }
/** * Get S3 file list * * @param string $path this parameter can a folder name, or a identification of folder * @param string $page the page number of file list * @return array the list of files, including some meta infomation */ public function get_listing($path = '', $page = '') { global $OUTPUT; $s = $this->create_s3(); $bucket = $this->get_option('bucket_name'); $list = array(); $list['list'] = array(); $list['path'] = array(array('name' => $bucket, 'path' => '')); $list['manage'] = false; $list['dynload'] = true; $list['nologin'] = true; $list['nosearch'] = true; $files = array(); $folders = array(); try { $contents = $s->getBucket($bucket, $path, null, null, '/', true); } catch (S3Exception $e) { throw new moodle_exception('errorwhilecommunicatingwith', 'repository', '', $this->get_name(), $e->getMessage()); } foreach ($contents as $object) { if (isset($object['prefix'])) { $title = rtrim($object['prefix'], '/'); } else { $title = $object['name']; } if (strlen($path) > 0) { $title = substr($title, strlen($path)); if (empty($title) && !is_numeric($title)) { continue; } } if (isset($object['prefix'])) { $folders[] = array('title' => $title, 'children' => array(), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'path' => $object['prefix']); } else { $files[] = array('title' => $title, 'size' => $object['size'], 'datemodified' => $object['time'], 'source' => $object['name'], 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 90))->out(false)); } } $list['list'] = array_merge($folders, $files); return $list; }
/** * Internal function - creates htmls structure suitable for YUI tree. * @param user_files_tree $tree * @param array $dir * @return string HTML */ protected function htmllize_tree($tree, $dir) { global $CFG; $yuiconfig = array(); $yuiconfig['type'] = 'html'; if (empty($dir['subdirs']) and empty($dir['files'])) { return ''; } $result = '<ul>'; foreach ($dir['subdirs'] as $subdir) { $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class' => 'icon')); $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' . $this->htmllize_tree($tree, $subdir) . '</li>'; } foreach ($dir['files'] as $file) { $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $tree->context->id . '/user/private' . $file->get_filepath() . $file->get_filename(), true); $filename = $file->get_filename(); $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class' => 'icon')); $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . $image . ' ' . html_writer::link($url, $filename) . '</div></li>'; } $result .= '</ul>'; return $result; }
/** * Get the list of files and directories in that repository. * * @param string $path to browse. * @param string $page page number. * @return array list of files and folders. */ public function get_listing($path = '', $page = '') { global $OUTPUT; $list = array(); $list['list'] = array(); $list['manage'] = false; $list['dynload'] = true; $list['nologin'] = true; $list['nosearch'] = true; $list['path'] = array(array('name' => get_string('root', 'repository_filesystem'), 'path' => '')); $path = trim($path, '/'); if (!$this->is_in_repository($path)) { // In case of doubt on the path, reset to default. $path = ''; } $abspath = rtrim($this->get_rootpath() . $path, '/') . '/'; // Construct the breadcrumb. $trail = ''; if ($path !== '') { $parts = explode('/', $path); if (count($parts) > 1) { foreach ($parts as $part) { if (!empty($part)) { $trail .= '/' . $part; $list['path'][] = array('name' => $part, 'path' => $trail); } } } else { $list['path'][] = array('name' => $path, 'path' => $path); } } // Retrieve list of files and directories and sort them. $fileslist = array(); $dirslist = array(); if ($dh = opendir($abspath)) { while (($file = readdir($dh)) != false) { if ($file != '.' and $file != '..') { if (is_file($abspath . $file)) { $fileslist[] = $file; } else { $dirslist[] = $file; } } } } core_collator::asort($fileslist, core_collator::SORT_NATURAL); core_collator::asort($dirslist, core_collator::SORT_NATURAL); // Fill the $list['list']. foreach ($dirslist as $file) { $list['list'][] = array('title' => $file, 'children' => array(), 'datecreated' => filectime($abspath . $file), 'datemodified' => filemtime($abspath . $file), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'path' => $path . '/' . $file); } foreach ($fileslist as $file) { $node = array('title' => $file, 'source' => $path . '/' . $file, 'size' => filesize($abspath . $file), 'datecreated' => filectime($abspath . $file), 'datemodified' => filemtime($abspath . $file), 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file, 90))->out(false), 'icon' => $OUTPUT->pix_url(file_extension_icon($file, 24))->out(false)); if (file_extension_in_typegroup($file, 'image') && ($imageinfo = @getimagesize($abspath . $file))) { // This means it is an image and we can return dimensions and try to generate thumbnail/icon. $token = $node['datemodified'] . $node['size']; // To prevent caching by browser. $node['realthumbnail'] = $this->get_thumbnail_url($path . '/' . $file, 'thumb', $token)->out(false); $node['realicon'] = $this->get_thumbnail_url($path . '/' . $file, 'icon', $token)->out(false); $node['image_width'] = $imageinfo[0]; $node['image_height'] = $imageinfo[1]; } $list['list'][] = $node; } $list['list'] = array_filter($list['list'], array($this, 'filter')); return $list; }
/** * Get file listing * * @param string $encodedpath * @return mixed */ public function get_listing($encodedpath = '', $page = '') { global $CFG, $USER, $OUTPUT; $ret = array(); $ret['dynload'] = true; $ret['nosearch'] = true; $ret['nologin'] = true; $manageurl = new moodle_url('/user/files.php'); $ret['manage'] = $manageurl->out(); $list = array(); if (!empty($encodedpath)) { $params = json_decode(base64_decode($encodedpath), true); if (is_array($params)) { $filepath = clean_param($params['filepath'], PARAM_PATH); $filename = clean_param($params['filename'], PARAM_FILE); } } else { $itemid = 0; $filepath = '/'; $filename = null; } $filearea = 'private'; $component = 'user'; $itemid = 0; $context = context_user::instance($USER->id); try { $browser = get_file_browser(); if ($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) { $pathnodes = array(); $level = $fileinfo; $params = $fileinfo->get_params(); while ($level && $params['component'] == 'user' && $params['filearea'] == 'private') { $encodedpath = base64_encode(json_encode($level->get_params())); $pathnodes[] = array('name' => $level->get_visible_name(), 'path' => $encodedpath); $level = $level->get_parent(); $params = $level->get_params(); } $ret['path'] = array_reverse($pathnodes); // build file tree $children = $fileinfo->get_children(); foreach ($children as $child) { if ($child->is_directory()) { $encodedpath = base64_encode(json_encode($child->get_params())); $node = array('title' => $child->get_visible_name(), 'datemodified' => $child->get_timemodified(), 'datecreated' => $child->get_timecreated(), 'path' => $encodedpath, 'children' => array(), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false)); $list[] = $node; } else { $encodedpath = base64_encode(json_encode($child->get_params())); $node = array('title' => $child->get_visible_name(), 'size' => $child->get_filesize(), 'datemodified' => $child->get_timemodified(), 'datecreated' => $child->get_timecreated(), 'author' => $child->get_author(), 'license' => $child->get_license(), 'isref' => $child->is_external_file(), 'source' => $encodedpath, 'icon' => $OUTPUT->pix_url(file_file_icon($child, 24))->out(false), 'thumbnail' => $OUTPUT->pix_url(file_file_icon($child, 90))->out(false)); if ($child->get_status() == 666) { $node['originalmissing'] = true; } if ($imageinfo = $child->get_imageinfo()) { $fileurl = new moodle_url($child->get_url()); $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $child->get_timemodified())); $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $child->get_timemodified())); $node['image_width'] = $imageinfo['width']; $node['image_height'] = $imageinfo['height']; } $list[] = $node; } } } } catch (Exception $e) { throw new repository_exception('emptyfilelist', 'repository_user'); } $ret['list'] = $list; $ret['list'] = array_filter($list, array($this, 'filter')); return $ret; }
public function get_listing($path = '', $page = '') { global $CFG, $OUTPUT; $list = array(); $list['list'] = array(); // process breacrumb trail $list['path'] = array( array('name'=>get_string('root', 'repository_filesystem'), 'path'=>'') ); $trail = ''; if (!empty($path)) { $parts = explode('/', $path); if (count($parts) > 1) { foreach ($parts as $part) { if (!empty($part)) { $trail .= ('/'.$part); $list['path'][] = array('name'=>$part, 'path'=>$trail); } } } else { $list['path'][] = array('name'=>$path, 'path'=>$path); } $this->root_path .= ($path.'/'); } $list['manage'] = false; $list['dynload'] = true; $list['nologin'] = true; $list['nosearch'] = true; // retrieve list of files and directories and sort them $fileslist = array(); $dirslist = array(); if ($dh = opendir($this->root_path)) { while (($file = readdir($dh)) != false) { if ( $file != '.' and $file !='..') { if (is_file($this->root_path.$file)) { $fileslist[] = $file; } else { $dirslist[] = $file; } } } } collatorlib::asort($fileslist, collatorlib::SORT_STRING); collatorlib::asort($dirslist, collatorlib::SORT_STRING); // fill the $list['list'] foreach ($dirslist as $file) { if (!empty($path)) { $current_path = $path . '/'. $file; } else { $current_path = $file; } $list['list'][] = array( 'title' => $file, 'children' => array(), 'datecreated' => filectime($this->root_path.$file), 'datemodified' => filemtime($this->root_path.$file), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'path' => $current_path ); } foreach ($fileslist as $file) { $list['list'][] = array( 'title' => $file, 'source' => $path.'/'.$file, 'size' => filesize($this->root_path.$file), 'datecreated' => filectime($this->root_path.$file), 'datemodified' => filemtime($this->root_path.$file), 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file, 90))->out(false), 'icon' => $OUTPUT->pix_url(file_extension_icon($file, 24))->out(false) ); } $list['list'] = array_filter($list['list'], array($this, 'filter')); return $list; }
/** * Get a file list from alfresco * * @param string $uuid a unique id of directory in alfresco * @param string $path path to a directory * @return array */ public function get_listing($uuid = '', $path = '') { global $CFG, $SESSION, $OUTPUT; $ret = array(); $ret['dynload'] = true; $ret['list'] = array(); $server_url = $this->options['alfresco_url']; $pattern = '#^(.*)api#'; if ($return = preg_match($pattern, $server_url, $matches)) { $ret['manage'] = $matches[1] . 'faces/jsp/dashboards/container.jsp'; } $ret['path'] = array(array('name' => get_string('pluginname', 'repository_alfresco'), 'path' => '')); try { if (empty($uuid)) { $this->current_node = $this->store->companyHome; } else { $this->current_node = $this->user_session->getNode($this->store, $uuid); } $folder_filter = "{http://www.alfresco.org/model/content/1.0}folder"; $file_filter = "{http://www.alfresco.org/model/content/1.0}content"; // top level sites folder $sites_filter = "{http://www.alfresco.org/model/site/1.0}sites"; // individual site $site_filter = "{http://www.alfresco.org/model/site/1.0}site"; foreach ($this->current_node->children as $child) { if ($child->child->type == $folder_filter or $child->child->type == $sites_filter or $child->child->type == $site_filter) { $ret['list'][] = array('title' => $child->child->cm_name, 'path' => $child->child->id, 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'children' => array()); } elseif ($child->child->type == $file_filter) { $ret['list'][] = array('title' => $child->child->cm_name, 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($child->child->cm_name, 90))->out(false), 'source' => $child->child->id); } } } catch (Exception $e) { unset($SESSION->{$this->sessname}); $ret = $this->print_login(); } return $ret; }
/** * Returns icon of element * * @param array &$element An array representing an element in the grade_tree * @param bool $spacerifnone return spacer if no icon found * * @return string icon or spacer */ public function get_element_icon(&$element, $spacerifnone = false) { global $CFG, $OUTPUT; require_once $CFG->libdir . '/filelib.php'; switch ($element['type']) { case 'item': case 'courseitem': case 'categoryitem': $is_course = $element['object']->is_course_item(); $is_category = $element['object']->is_category_item(); $is_scale = $element['object']->gradetype == GRADE_TYPE_SCALE; $is_value = $element['object']->gradetype == GRADE_TYPE_VALUE; $is_outcome = !empty($element['object']->outcomeid); if ($element['object']->is_calculated()) { $strcalc = get_string('calculatedgrade', 'grades'); return '<img src="' . $OUTPUT->pix_url('i/calc') . '" class="icon itemicon" title="' . s($strcalc) . '" alt="' . s($strcalc) . '"/>'; } else { if (($is_course or $is_category) and ($is_scale or $is_value)) { if ($category = $element['object']->get_item_category()) { switch ($category->aggregation) { case GRADE_AGGREGATE_MEAN: case GRADE_AGGREGATE_MEDIAN: case GRADE_AGGREGATE_WEIGHTED_MEAN: case GRADE_AGGREGATE_WEIGHTED_MEAN2: case GRADE_AGGREGATE_EXTRACREDIT_MEAN: $stragg = get_string('aggregation', 'grades'); return '<img src="' . $OUTPUT->pix_url('i/agg_mean') . '" ' . 'class="icon itemicon" title="' . s($stragg) . '" alt="' . s($stragg) . '"/>'; case GRADE_AGGREGATE_SUM: $stragg = get_string('aggregation', 'grades'); return '<img src="' . $OUTPUT->pix_url('i/agg_sum') . '" ' . 'class="icon itemicon" title="' . s($stragg) . '" alt="' . s($stragg) . '"/>'; } } } else { if ($element['object']->itemtype == 'mod') { //prevent outcomes being displaying the same icon as the activity they are attached to if ($is_outcome) { $stroutcome = s(get_string('outcome', 'grades')); return '<img src="' . $OUTPUT->pix_url('i/outcomes') . '" ' . 'class="icon itemicon" title="' . $stroutcome . '" alt="' . $stroutcome . '"/>'; } else { $strmodname = get_string('modulename', $element['object']->itemmodule); return '<img src="' . $OUTPUT->pix_url('icon', $element['object']->itemmodule) . '" ' . 'class="icon itemicon" title="' . s($strmodname) . '" alt="' . s($strmodname) . '"/>'; } } else { if ($element['object']->itemtype == 'manual') { if ($element['object']->is_outcome_item()) { $stroutcome = get_string('outcome', 'grades'); return '<img src="' . $OUTPUT->pix_url('i/outcomes') . '" ' . 'class="icon itemicon" title="' . s($stroutcome) . '" alt="' . s($stroutcome) . '"/>'; } else { $strmanual = get_string('manualitem', 'grades'); return '<img src="' . $OUTPUT->pix_url('t/manual_item') . '" ' . 'class="icon itemicon" title="' . s($strmanual) . '" alt="' . s($strmanual) . '"/>'; } } } } } break; case 'category': $strcat = get_string('category', 'grades'); return '<img src="' . $OUTPUT->pix_url(file_folder_icon()) . '" class="icon itemicon" ' . 'title="' . s($strcat) . '" alt="' . s($strcat) . '" />'; } if ($spacerifnone) { return $OUTPUT->spacer() . ' '; } else { return ''; } }
/** * Transform a onedrive API response for a folder into a list parameter that the respository class can understand. * * @param string $response The response from the API. * @param string $path The list path. * @param string $clienttype The type of client that the response is from. onedrive/sharepoint. * @param string $spparentsiteuri If using the Sharepoint clienttype, this is the parent site URI. * @return array A $list array to be used by the respository class in get_listing. */ protected function contents_api_response_to_list($response, $path, $clienttype, $spparentsiteuri = null) { global $OUTPUT, $DB; $list = []; if ($clienttype === 'onedrive') { $pathprefix = '/my' . $path; } else { if ($clienttype === 'unified') { $pathprefix = '/my'; } else { if ($clienttype === 'sharepoint') { $pathprefix = '/courses' . $path; } } } if ($clienttype === 'unified' && $path === '/' || $clienttype !== 'unified') { $list[] = ['title' => get_string('upload', 'repository_office365'), 'path' => $pathprefix . '/upload/', 'thumbnail' => $OUTPUT->pix_url('a/add_file')->out(false), 'children' => []]; } if (isset($response['value'])) { foreach ($response['value'] as $content) { if ($clienttype === 'unified') { $itempath = $pathprefix . '/' . $content['id']; } else { $itempath = $pathprefix . '/' . $content['name']; } if ($content['type'] === 'Folder') { $list[] = ['title' => $content['name'], 'path' => $itempath, 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'date' => strtotime($content['dateTimeCreated']), 'datemodified' => strtotime($content['dateTimeLastModified']), 'datecreated' => strtotime($content['dateTimeCreated']), 'children' => []]; } else { if ($content['type'] === 'File') { $url = $content['webUrl'] . '?web=1'; $source = ['id' => $content['id'], 'source' => $clienttype === 'sharepoint' ? 'sharepoint' : 'onedrive']; if ($clienttype === 'sharepoint') { $source['parentsiteuri'] = $spparentsiteuri; } $author = ''; if (!empty($content['createdBy']['user']['displayName'])) { $author = $content['createdBy']['user']['displayName']; $author = explode(',', $author); $author = $author[0]; } $list[] = ['title' => $content['name'], 'date' => strtotime($content['dateTimeCreated']), 'datemodified' => strtotime($content['dateTimeLastModified']), 'datecreated' => strtotime($content['dateTimeCreated']), 'size' => $content['size'], 'url' => $url, 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($content['name'], 90))->out(false), 'author' => $author, 'source' => $this->pack_reference($source)]; } } } } return $list; }
public function get_listing($path='', $page = '') { global $CFG, $OUTPUT; $list = array(); $ret = array(); $ret['dynload'] = true; $ret['nosearch'] = true; $ret['nologin'] = true; $ret['path'] = array(array('name'=>get_string('webdav', 'repository_webdav'), 'path'=>'')); $ret['list'] = array(); if (!$this->dav->open()) { return $ret; } $webdavpath = rtrim('/'.ltrim($this->options['webdav_path'], '/ '), '/ '); // without slash in the end if (empty($path) || $path =='/') { $path = '/'; } else { $chunks = preg_split('|/|', trim($path, '/')); for ($i = 0; $i < count($chunks); $i++) { $ret['path'][] = array( 'name' => urldecode($chunks[$i]), 'path' => '/'. join('/', array_slice($chunks, 0, $i+1)). '/' ); } } $dir = $this->dav->ls($webdavpath. urldecode($path)); if (!is_array($dir)) { return $ret; } $folders = array(); $files = array(); foreach ($dir as $v) { if (!empty($v['lastmodified'])) { $v['lastmodified'] = strtotime($v['lastmodified']); } else { $v['lastmodified'] = null; } // Extracting object title from absolute path $v['href'] = substr(urldecode($v['href']), strlen($webdavpath)); $title = substr($v['href'], strlen($path)); if (!empty($v['resourcetype']) && $v['resourcetype'] == 'collection') { // a folder if ($path != $v['href']) { $folders[strtoupper($title)] = array( 'title'=>rtrim($title, '/'), 'thumbnail'=>$OUTPUT->pix_url(file_folder_icon(90))->out(false), 'children'=>array(), 'datemodified'=>$v['lastmodified'], 'path'=>$v['href'] ); } }else{ // a file $size = !empty($v['getcontentlength'])? $v['getcontentlength']:''; $files[strtoupper($title)] = array( 'title'=>$title, 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 90))->out(false), 'size'=>$size, 'datemodified'=>$v['lastmodified'], 'source'=>$v['href'] ); } } ksort($files); ksort($folders); $ret['list'] = array_merge($folders, $files); return $ret; }
/** * Query Google Drive for files and folders using a search query. * * Documentation about the query format can be found here: * https://developers.google.com/drive/search-parameters * * This returns a list of files and folders with their details as they should be * formatted and returned by functions such as get_listing() or search(). * * @param string $q search query as expected by the Google API. * @param string $path parent path of the current files, will not be used for the query. * @param int $page page. * @return array of files and folders. */ protected function query($q, $path = null, $page = 0) { global $OUTPUT; $files = array(); $folders = array(); $fields = "items(id,title,mimeType,downloadUrl,fileExtension,exportLinks,modifiedDate,fileSize,thumbnailLink)"; $params = array('q' => $q, 'fields' => $fields); try { // Retrieving files and folders. $response = $this->service->files->listFiles($params); } catch (Google_ServiceException $e) { if ($e->getCode() == 403 && strpos($e->getMessage(), 'Access Not Configured') !== false) { // This is raised when the service Drive API has not been enabled on Google APIs control panel. throw new repository_exception('servicenotenabled', 'repository_googledocs'); } else { throw $e; } } $items = isset($response['items']) ? $response['items'] : array(); foreach ($items as $item) { if ($item['mimeType'] == 'application/vnd.google-apps.folder') { // This is a folder. $folders[$item['title'] . $item['id']] = array('title' => $item['title'], 'path' => $this->build_node_path($item['id'], $item['title'], $path), 'date' => strtotime($item['modifiedDate']), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(64))->out(false), 'thumbnail_height' => 64, 'thumbnail_width' => 64, 'children' => array()); } else { // This is a file. if (isset($item['fileExtension'])) { // The file has an extension, therefore there is a download link. $title = $item['title']; $source = $item['downloadUrl']; } else { // The file is probably a Google Doc file, we get the corresponding export link. // This should be improved by allowing the user to select the type of export they'd like. $type = str_replace('application/vnd.google-apps.', '', $item['mimeType']); $title = ''; $exportType = ''; switch ($type) { case 'document': $title = $item['title'] . '.rtf'; $exportType = 'application/rtf'; break; case 'presentation': $title = $item['title'] . '.pptx'; $exportType = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; break; case 'spreadsheet': $title = $item['title'] . '.xlsx'; $exportType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; break; } // Skips invalid/unknown types. if (empty($title) || !isset($item['exportLinks'][$exportType])) { continue; } $source = $item['exportLinks'][$exportType]; } // Adds the file to the file list. Using the itemId along with the title as key // of the array because Google Drive allows files with identical names. $files[$title . $item['id']] = array('title' => $title, 'source' => $source, 'date' => strtotime($item['modifiedDate']), 'size' => isset($item['fileSize']) ? $item['fileSize'] : null, 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 64))->out(false), 'thumbnail_height' => 64, 'thumbnail_width' => 64); // Sometimes the real thumbnails can't be displayed, for example if 3rd party cookies are disabled // or if the user is not logged in Google anymore. But this restriction does not seem to be applied // to a small subset of files. $extension = strtolower(pathinfo($title, PATHINFO_EXTENSION)); if (isset($item['thumbnailLink']) && in_array($extension, array('jpg', 'png', 'txt', 'pdf'))) { $files[$title . $item['id']]['realthumbnail'] = $item['thumbnailLink']; } } } // Filter and order the results. $files = array_filter($files, array($this, 'filter')); core_collator::ksort($files, core_collator::SORT_NATURAL); core_collator::ksort($folders, core_collator::SORT_NATURAL); return array_merge(array_values($folders), array_values($files)); }
/** * Build a file or directory node. * * @param string $rootpath The absolute path to the repository. * @param string $path The relative path of the object * @param string $name The name of the object * @param string $isdir Is the object a directory? * @param string $rootnodepath The node leading to this node (for breadcrumb). * @return array */ protected function build_node($rootpath, $path, $name, $isdir, $rootnodepath) { global $OUTPUT; $relpath = trim($path, '/') . '/' . $name; $abspath = $rootpath . $relpath; $node = array('title' => $name, 'datecreated' => filectime($abspath), 'datemodified' => filemtime($abspath)); if ($isdir) { $node['children'] = array(); $node['thumbnail'] = $OUTPUT->pix_url(file_folder_icon(90))->out(false); $node['path'] = $this->build_node_path('browse', $relpath, $name, $rootnodepath); } else { $node['source'] = $relpath; $node['size'] = filesize($abspath); $node['thumbnail'] = $OUTPUT->pix_url(file_extension_icon($name, 90))->out(false); $node['icon'] = $OUTPUT->pix_url(file_extension_icon($name, 24))->out(false); $node['path'] = $relpath; if (file_extension_in_typegroup($name, 'image') && ($imageinfo = @getimagesize($abspath))) { // This means it is an image and we can return dimensions and try to generate thumbnail/icon. $token = $node['datemodified'] . $node['size']; // To prevent caching by browser. $node['realthumbnail'] = $this->get_thumbnail_url($relpath, 'thumb', $token)->out(false); $node['realicon'] = $this->get_thumbnail_url($relpath, 'icon', $token)->out(false); $node['image_width'] = $imageinfo[0]; $node['image_height'] = $imageinfo[1]; } } return $node; }
/** * Get file listing * * @param string $encodedpath * @return mixed */ public function get_listing($encodedpath = '', $page = '') { global $CFG, $USER, $OUTPUT; $ret = array(); $ret['dynload'] = true; $ret['nosearch'] = true; $ret['nologin'] = true; $list = array(); $component = 'course'; $filearea = 'legacy'; $itemid = 0; $browser = get_file_browser(); if (!empty($encodedpath)) { $params = json_decode(base64_decode($encodedpath), true); if (is_array($params)) { $filepath = is_null($params['filepath']) ? NULL : clean_param($params['filepath'], PARAM_PATH); $filename = is_null($params['filename']) ? NULL : clean_param($params['filename'], PARAM_FILE); $context = context::instance_by_id(clean_param($params['contextid'], PARAM_INT)); } } else { $filename = null; $filepath = null; list($context, $course, $cm) = get_context_info_array($this->context->id); $courseid = is_object($course) ? $course->id : SITEID; $context = context_course::instance($courseid); } if ($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) { // build path navigation $pathnodes = array(); $encodedpath = base64_encode(json_encode($fileinfo->get_params())); $pathnodes[] = array('name' => $fileinfo->get_visible_name(), 'path' => $encodedpath); $level = $fileinfo->get_parent(); while ($level) { $params = $level->get_params(); $encodedpath = base64_encode(json_encode($params)); if ($params['contextid'] != $context->id) { break; } $pathnodes[] = array('name' => $level->get_visible_name(), 'path' => $encodedpath); $level = $level->get_parent(); } if (!empty($pathnodes) && is_array($pathnodes)) { $pathnodes = array_reverse($pathnodes); $ret['path'] = $pathnodes; } // build file tree $children = $fileinfo->get_children(); foreach ($children as $child) { if ($child->is_directory()) { $params = $child->get_params(); $subdir_children = $child->get_children(); $encodedpath = base64_encode(json_encode($params)); $node = array('title' => $child->get_visible_name(), 'datemodified' => $child->get_timemodified(), 'datecreated' => $child->get_timecreated(), 'path' => $encodedpath, 'children' => array(), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false)); $list[] = $node; } else { $encodedpath = base64_encode(json_encode($child->get_params())); $node = array('title' => $child->get_visible_name(), 'size' => $child->get_filesize(), 'author' => $child->get_author(), 'license' => $child->get_license(), 'datemodified' => $child->get_timemodified(), 'datecreated' => $child->get_timecreated(), 'source' => $encodedpath, 'isref' => $child->is_external_file(), 'thumbnail' => $OUTPUT->pix_url(file_file_icon($child, 90))->out(false)); if ($child->get_status() == 666) { $node['originalmissing'] = true; } if ($imageinfo = $child->get_imageinfo()) { $fileurl = new moodle_url($child->get_url()); $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $child->get_timemodified())); $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $child->get_timemodified())); $node['image_width'] = $imageinfo['width']; $node['image_height'] = $imageinfo['height']; } $list[] = $node; } } } else { $list = array(); } $ret['list'] = array_filter($list, array($this, 'filter')); return $ret; }
/** * Prepares list of files before passing it to AJAX, makes sure data is in the correct * format and stores formatted values. * * @param array|stdClass $listing result of get_listing() or search() or file_get_drafarea_files() * @return array */ public static function prepare_listing($listing) { global $OUTPUT; $defaultfoldericon = $OUTPUT->pix_url(file_folder_icon(24))->out(false); // prepare $listing['path'] or $listing->path if (is_array($listing) && isset($listing['path']) && is_array($listing['path'])) { $path = &$listing['path']; } else if (is_object($listing) && isset($listing->path) && is_array($listing->path)) { $path = &$listing->path; } if (isset($path)) { $len = count($path); for ($i=0; $i<$len; $i++) { if (is_array($path[$i]) && !isset($path[$i]['icon'])) { $path[$i]['icon'] = $defaultfoldericon; } else if (is_object($path[$i]) && !isset($path[$i]->icon)) { $path[$i]->icon = $defaultfoldericon; } } } // prepare $listing['list'] or $listing->list if (is_array($listing) && isset($listing['list']) && is_array($listing['list'])) { $listing['list'] = array_values($listing['list']); // convert to array $files = &$listing['list']; } else if (is_object($listing) && isset($listing->list) && is_array($listing->list)) { $listing->list = array_values($listing->list); // convert to array $files = &$listing->list; } else { return $listing; } $len = count($files); for ($i=0; $i<$len; $i++) { if (is_object($files[$i])) { $file = (array)$files[$i]; $converttoobject = true; } else { $file = & $files[$i]; $converttoobject = false; } if (isset($file['size'])) { $file['size'] = (int)$file['size']; $file['size_f'] = display_size($file['size']); } if (isset($file['license']) && get_string_manager()->string_exists($file['license'], 'license')) { $file['license_f'] = get_string($file['license'], 'license'); } if (isset($file['image_width']) && isset($file['image_height'])) { $a = array('width' => $file['image_width'], 'height' => $file['image_height']); $file['dimensions'] = get_string('imagesize', 'repository', (object)$a); } foreach (array('date', 'datemodified', 'datecreated') as $key) { if (!isset($file[$key]) && isset($file['date'])) { $file[$key] = $file['date']; } if (isset($file[$key])) { // must be UNIX timestamp $file[$key] = (int)$file[$key]; if (!$file[$key]) { unset($file[$key]); } else { $file[$key.'_f'] = userdate($file[$key], get_string('strftimedatetime', 'langconfig')); $file[$key.'_f_s'] = userdate($file[$key], get_string('strftimedatetimeshort', 'langconfig')); } } } $isfolder = (array_key_exists('children', $file) || (isset($file['type']) && $file['type'] == 'folder')); $filename = null; if (isset($file['title'])) { $filename = $file['title']; } else if (isset($file['fullname'])) { $filename = $file['fullname']; } if (!isset($file['mimetype']) && !$isfolder && $filename) { $file['mimetype'] = get_mimetype_description(array('filename' => $filename)); } if (!isset($file['icon'])) { if ($isfolder) { $file['icon'] = $defaultfoldericon; } else if ($filename) { $file['icon'] = $OUTPUT->pix_url(file_extension_icon($filename, 24))->out(false); } } if ($converttoobject) { $files[$i] = (object)$file; } } return $listing; }
/** * Get dropbox files * * @param string $path * @param int $page * @return array */ public function get_listing($path = '', $page = '1') { global $OUTPUT; if (empty($path) || $path == '/') { $path = '/'; } else { $path = file_correct_filepath($path); } $encoded_path = str_replace("%2F", "/", rawurlencode($path)); $list = array(); $list['list'] = array(); $list['manage'] = 'https://www.dropbox.com/home'; $list['dynload'] = true; $list['nosearch'] = true; $list['logouturl'] = 'https://www.dropbox.com/logout'; $list['message'] = get_string('logoutdesc', 'repository_dropbox'); // process breadcrumb trail $list['path'] = array(array('name' => get_string('dropbox', 'repository_dropbox'), 'path' => '/')); $result = $this->dropbox->get_listing($encoded_path, $this->access_key, $this->access_secret); if (!is_object($result) || empty($result)) { return $list; } if (empty($result->path)) { $current_path = '/'; } else { $current_path = file_correct_filepath($result->path); } $trail = ''; if (!empty($path)) { $parts = explode('/', $path); if (count($parts) > 1) { foreach ($parts as $part) { if (!empty($part)) { $trail .= '/' . $part; $list['path'][] = array('name' => $part, 'path' => $trail); } } } else { $list['path'][] = array('name' => $path, 'path' => $path); } } if (!empty($result->error)) { // reset access key set_user_preference($this->setting . '_access_key', ''); set_user_preference($this->setting . '_access_secret', ''); throw new repository_exception('repositoryerror', 'repository', '', $result->error); } if (empty($result->contents) or !is_array($result->contents)) { return $list; } $files = $result->contents; $dirslist = array(); $fileslist = array(); foreach ($files as $file) { if ($file->is_dir) { $dirslist[] = array('title' => substr($file->path, strpos($file->path, $current_path) + strlen($current_path)), 'path' => file_correct_filepath($file->path), 'date' => strtotime($file->modified), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(64))->out(false), 'thumbnail_height' => 64, 'thumbnail_width' => 64, 'children' => array()); } else { $thumbnail = null; if ($file->thumb_exists) { $thumburl = new moodle_url('/repository/dropbox/thumbnail.php', array('repo_id' => $this->id, 'ctx_id' => $this->context->id, 'source' => $file->path, 'rev' => $file->rev)); $thumbnail = $thumburl->out(false); } $fileslist[] = array('title' => substr($file->path, strpos($file->path, $current_path) + strlen($current_path)), 'source' => $file->path, 'size' => $file->bytes, 'date' => strtotime($file->modified), 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file->path, 64))->out(false), 'realthumbnail' => $thumbnail, 'thumbnail_height' => 64, 'thumbnail_width' => 64); } } $fileslist = array_filter($fileslist, array($this, 'filter')); $list['list'] = array_merge($dirslist, array_values($fileslist)); return $list; }
/** * Get file listing * * @param string $path * @param string $page * @return mixed */ public function get_listing($fullpath = '', $page = '') { global $OUTPUT; $ret = array(); $ret['list'] = array(); $ret['manage'] = self::MANAGE_URL; $ret['dynload'] = true; $crumbs = explode('/', $fullpath); $path = array_pop($crumbs); if (empty($path)) { $type = 'folder'; $pathid = 0; $pathname = get_string('pluginname', 'repository_boxnet'); } else { list($type, $pathid, $pathname) = $this->split_part($path); } $ret['path'] = $this->build_breadcrumb($fullpath); $folders = array(); $files = array(); if ($type == 'search') { $result = $this->boxnetclient->search($pathname); } else { $result = $this->boxnetclient->get_folder_items($pathid); } foreach ($result->entries as $item) { if ($item->type == 'folder') { $folders[$item->name . ':' . $item->id] = array('title' => $item->name, 'path' => $fullpath . '/' . $this->build_part('folder', $item->id, $item->name), 'date' => strtotime($item->modified_at), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(64))->out(false), 'thumbnail_height' => 64, 'thumbnail_width' => 64, 'children' => array(), 'size' => $item->size); } else { $files[$item->name . ':' . $item->id] = array('title' => $item->name, 'source' => $this->build_part('file', $item->id, $item->name), 'size' => $item->size, 'date' => strtotime($item->modified_at), 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($item->name, 64))->out(false), 'thumbnail_height' => 64, 'thumbnail_width' => 64, 'author' => $item->owned_by->name); } } collatorlib::ksort($folders, core_collator::SORT_NATURAL); collatorlib::ksort($files, core_collator::SORT_NATURAL); $ret['list'] = array_merge($folders, $files); $ret['list'] = array_filter($ret['list'], array($this, 'filter')); return $ret; }
$home_url->param('action', 'deletedraft'); echo ' [<a href="' . $home_url->out() . '" class="fm-operation">' . get_string('delete') . '</a>]'; $home_url->param('action', 'movefile'); echo ' [<a href="' . $home_url->out() . '" class="fm-operation">' . get_string('move') . '</a>]'; $home_url->param('action', 'renameform'); echo ' [<a href="' . $home_url->out() . '" class="fm-operation">' . get_string('rename') . '</a>]'; if (file_extension_in_typegroup($file->filename, 'archive', true)) { $home_url->param('action', 'unzip'); $home_url->param('draftpath', $file->filepath); echo ' [<a href="' . $home_url->out() . '" class="fm-operation">' . get_string('unzip') . '</a>]'; } echo '</li>'; } else { // a folder echo '<li>'; echo '<img src="' . $OUTPUT->pix_url(file_folder_icon()) . '" class="iconsmall" />'; $home_url->param('action', 'browse'); $home_url->param('draftpath', $file->filepath); $filepathchunks = explode('/', trim($file->filepath, '/')); $foldername = trim(array_pop($filepathchunks), '/'); echo html_writer::link($home_url, $foldername); $home_url->param('draftpath', $file->filepath); $home_url->param('filename', $file->filename); $home_url->param('action', 'deletedraft'); echo ' [<a href="' . $home_url->out() . '" class="fm-operation">' . get_string('delete') . '</a>]'; $home_url->param('action', 'zip'); echo ' [<a href="' . $home_url->out() . '" class="fm-operation">Zip</a>]'; echo '</li>'; } } echo '</ul>';
/** * Prepare the file/folder listing. * * @param array $list of files and folders. * @return array of files and folders. * @since Moodle 2.3.3 */ protected static function prepare_list($list) { global $OUTPUT; $foldericon = $OUTPUT->pix_url(file_folder_icon(24))->out(false); // Reset the array keys because non-numeric keys will create an object when converted to JSON. $list = array_values($list); $len = count($list); for ($i = 0; $i < $len; $i++) { if (is_object($list[$i])) { $file = (array) $list[$i]; $converttoobject = true; } else { $file =& $list[$i]; $converttoobject = false; } if (isset($file['size'])) { $file['size'] = (int) $file['size']; $file['size_f'] = display_size($file['size']); } if (isset($file['license']) && get_string_manager()->string_exists($file['license'], 'license')) { $file['license_f'] = get_string($file['license'], 'license'); } if (isset($file['image_width']) && isset($file['image_height'])) { $a = array('width' => $file['image_width'], 'height' => $file['image_height']); $file['dimensions'] = get_string('imagesize', 'repository', (object) $a); } foreach (array('date', 'datemodified', 'datecreated') as $key) { if (!isset($file[$key]) && isset($file['date'])) { $file[$key] = $file['date']; } if (isset($file[$key])) { // must be UNIX timestamp $file[$key] = (int) $file[$key]; if (!$file[$key]) { unset($file[$key]); } else { $file[$key . '_f'] = userdate($file[$key], get_string('strftimedatetime', 'langconfig')); $file[$key . '_f_s'] = userdate($file[$key], get_string('strftimedatetimeshort', 'langconfig')); } } } $isfolder = array_key_exists('children', $file) || isset($file['type']) && $file['type'] == 'folder'; $filename = null; if (isset($file['title'])) { $filename = $file['title']; } else { if (isset($file['fullname'])) { $filename = $file['fullname']; } } if (!isset($file['mimetype']) && !$isfolder && $filename) { $file['mimetype'] = get_mimetype_description(array('filename' => $filename)); } if (!isset($file['icon'])) { if ($isfolder) { $file['icon'] = $foldericon; } else { if ($filename) { $file['icon'] = $OUTPUT->pix_url(file_extension_icon($filename, 24))->out(false); } } } // Recursively loop over children. if (isset($file['children'])) { $file['children'] = self::prepare_list($file['children']); } // Convert the array back to an object. if ($converttoobject) { $list[$i] = (object) $file; } } return $list; }
/** * 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; }
/** * Get S3 file list * * @param string $path * @return array The file list and options */ public function get_listing($path = '', $page = '') { global $CFG, $OUTPUT; if (empty($this->access_key)) { throw new moodle_exception('needaccesskey', 'repository_s3'); } $list = array(); $list['list'] = array(); $list['path'] = array( array('name' => get_string('pluginname', 'repository_s3'), 'path' => '') ); // the management interface url $list['manage'] = false; // dynamically loading $list['dynload'] = true; // the current path of this list. // set to true, the login link will be removed $list['nologin'] = true; // set to true, the search button will be removed $list['nosearch'] = true; $tree = array(); if (empty($path)) { try { $buckets = $this->s->listBuckets(); } catch (S3Exception $e) { throw new moodle_exception('errorwhilecommunicatingwith', 'repository', '', $this->get_name()); } foreach ($buckets as $bucket) { $folder = array( 'title' => $bucket, 'children' => array(), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'path' => $bucket ); $tree[] = $folder; } } else { $files = array(); $folders = array(); list($bucket, $uri) = $this->explode_path($path); try { $contents = $this->s->getBucket($bucket, $uri, null, null, '/', true); } catch (S3Exception $e) { throw new moodle_exception('errorwhilecommunicatingwith', 'repository', '', $this->get_name()); } foreach ($contents as $object) { // If object has a prefix, it is a 'CommonPrefix', which we consider a folder if (isset($object['prefix'])) { $title = rtrim($object['prefix'], '/'); } else { $title = $object['name']; } // Removes the prefix (folder path) from the title if (strlen($uri) > 0) { $title = substr($title, strlen($uri)); // Check if title is empty and not zero if (empty($title) && !is_numeric($title)) { // Amazon returns the prefix itself, we skip it continue; } } // This is a so-called CommonPrefix, we consider it as a folder if (isset($object['prefix'])) { $folders[] = array( 'title' => $title, 'children' => array(), 'thumbnail'=> $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'path' => $bucket . '/' . $object['prefix'] ); } else { $files[] = array( 'title' => $title, 'size' => $object['size'], 'datemodified' => $object['time'], 'source' => $bucket . '/' . $object['name'], 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 90))->out(false) ); } } $tree = array_merge($folders, $files); } $trail = ''; if (!empty($path)) { $parts = explode('/', $path); if (count($parts) > 1) { foreach ($parts as $part) { if (!empty($part)) { $trail .= $part . '/'; $list['path'][] = array('name' => $part, 'path' => $trail); } } } else { $list['path'][] = array('name' => $path, 'path' => $path); } } $list['list'] = $tree; return $list; }
/** * Converts file_info object to element of repository return list * * @param file_info $fileinfo * @return array */ private function get_node(file_info $fileinfo) { global $OUTPUT; $encodedpath = base64_encode(json_encode($fileinfo->get_params())); $node = array('title' => $fileinfo->get_visible_name(), 'datemodified' => $fileinfo->get_timemodified(), 'datecreated' => $fileinfo->get_timecreated()); if ($fileinfo->is_directory()) { $node['path'] = $encodedpath; $node['thumbnail'] = $OUTPUT->pix_url(file_folder_icon(90))->out(false); $node['children'] = array(); } else { $node['size'] = $fileinfo->get_filesize(); $node['author'] = $fileinfo->get_author(); $node['license'] = $fileinfo->get_license(); $node['isref'] = $fileinfo->is_external_file(); if ($fileinfo->get_status() == 666) { $node['originalmissing'] = true; } $node['source'] = $encodedpath; $node['thumbnail'] = $OUTPUT->pix_url(file_file_icon($fileinfo, 90))->out(false); $node['icon'] = $OUTPUT->pix_url(file_file_icon($fileinfo, 24))->out(false); if ($imageinfo = $fileinfo->get_imageinfo()) { // what a beautiful picture, isn't it $fileurl = new moodle_url($fileinfo->get_url()); $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $fileinfo->get_timemodified())); $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $fileinfo->get_timemodified())); $node['image_width'] = $imageinfo['width']; $node['image_height'] = $imageinfo['height']; } } return $node; }
/** * Fill data for a list item * * @param $type * @param $item * @param null $filter * @return array|null */ public function process_list_item($type, $item, $filter = null) { global $OUTPUT; // Hardwired filter to force only a subset of projects and datasets if (strcmp($type, "Project") == 0 || strcmp($type, "Dataset") == 0) { foreach ($this->item_black_list as $pattern) { if (preg_match("/^{$pattern}\$/", $item->name)) { return null; } } } $thumbnail_height = 95; $thumbnail_width = 95; $itemObj = array('image_id' => $item->id, 'title' => "Undefined", 'source' => $item->id, 'license' => "unknown", 'children' => array()); if (strcmp($type, "ProjectRoot") == 0) { $itemObj["title"] = get_string('projects', 'repository_omero'); $itemObj["path"] = PathUtils::build_project_list_url(); $itemObj["thumbnail"] = $OUTPUT->pix_url(file_folder_icon(64))->out(true); } else { if (strcmp($type, "TagRoot") == 0) { $itemObj["title"] = get_string('tags', 'repository_omero'); $itemObj["path"] = PathUtils::build_annotation_list_url(); $itemObj["thumbnail"] = $this->file_icon("tagset", 64); } else { if (strcmp($type, "TagSet") == 0) { $itemObj["title"] = get_string('tagset', 'repository_omero') . $item->value; $itemObj["path"] = PathUtils::build_tagset_deatails_url($item->id); $itemObj["thumbnail"] = $this->file_icon("tagset", 64); } else { if (strcmp($type, "Tag") == 0) { $itemObj["title"] = $item->value . ": " . $item->description . " [id:" . $item->id . "]"; $itemObj["path"] = PathUtils::build_tag_detail_url($item->id); $itemObj["thumbnail"] = $this->file_icon("tag", 64); } else { if (strcmp($type, "Project") == 0) { $itemObj["title"] = $item->name . " [id:" . $item->id . "]"; $itemObj["path"] = PathUtils::build_project_detail_url($item->id); $itemObj["thumbnail"] = $OUTPUT->pix_url(file_folder_icon(64))->out(true); } else { if (strcmp($type, "Dataset") == 0) { $itemObj["title"] = $item->name . " [id:" . $item->id . "]"; $itemObj["path"] = PathUtils::build_dataset_detail_url($item->id); $itemObj["thumbnail"] = $OUTPUT->pix_url(file_folder_icon(64))->out(true); } else { if (strcmp($type, "Image") == 0) { // replace image ID with the ID of the higher resolution image of the series $image_source = isset($item->high_resolution_image) ? $item->high_resolution_image : $item->id; $image_thumbnail = PathUtils::build_image_thumbnail_url($item->id, $item->lastUpdate, $thumbnail_height, $thumbnail_width); $itemObj['source'] = $image_source; $itemObj["title"] = $item->name . " [id:" . $image_source . "]"; $itemObj["author"] = $item->author; $itemObj["path"] = PathUtils::build_image_detail_url($item->id); $itemObj["thumbnail"] = $image_thumbnail; $itemObj["url"] = $image_thumbnail; $itemObj["date"] = $item->importTime; $itemObj["datecreated"] = $item->creationTime; $itemObj["datemodified"] = $item->lastUpdate; $itemObj['children'] = null; $itemObj["image_width"] = $item->width; $itemObj["image_height"] = $item->height; $itemObj['thumbnail_height'] = $thumbnail_height; $itemObj['thumbnail_width'] = $thumbnail_width; } else { throw new RuntimeException("Unknown data type"); } } } } } } } $itemObj["icon"] = $itemObj["thumbnail"]; return $itemObj; }
/** * Internal function - creates htmls structure suitable for YUI tree. */ protected function htmllize_tree($tree, $dir) { global $CFG; if (empty($dir['subdirs']) and empty($dir['files'])) { return ''; } $result = '<ul>'; foreach ($dir['subdirs'] as $subdir) { $image = $this->output->pix_icon(file_folder_icon(24), $subdir['dirname'], 'moodle'); $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', s($subdir['dirname']), array('class' => 'fp-filename')); $filename = html_writer::tag('div', $filename, array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename. $this->htmllize_tree($tree, $subdir)); } foreach ($dir['files'] as $file) { $filename = $file->get_filename(); $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $filename, false); if (file_extension_in_typegroup($filename, 'web_image')) { $image = $url->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified())); $image = html_writer::empty_tag('img', array('src' => $image)); } else { $image = $this->output->pix_icon(file_file_icon($file, 24), $filename, 'moodle'); } $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', $filename, array('class' => 'fp-filename')); $filename = html_writer::tag('span', html_writer::link($url->out(false, array('forcedownload' => 1)), $filename), array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename); } $result .= '</ul>'; return $result; }