.
/**
* Private folder module utility functions
*
* @package mod-folder
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("$CFG->dirroot/mod/folder/lib.php");
require_once("$CFG->libdir/file/file_browser.php");
require_once("$CFG->libdir/filelib.php");
/**
* Prints file folder tree view
* @param object $folder instance
* @param object $cm instance
* @param object $course
* @return void
*/
function folder_print_tree($folder, $cm, $course) {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$fs = get_file_storage();
$dir = $fs->get_area_tree($context->id, 'folder_content', 0);
echo '
';
echo folder_htmllize_tree($dir, $folder, $context);
echo '
';
$PAGE->requires->js_init_call('M.mod_folder.init_tree', array(true));
}
/**
* Internal function - creates htmls structure suitable for YUI tree.
*/
function folder_htmllize_tree($dir, $folder, $context) {
if (empty($dir['subdirs']) and empty($dir['files'])) {
return '';
}
$result = '';
foreach ($dir['subdirs'] as $subdir) {
$result .= '- '.s($subdir['dirname']).' '.folder_htmllize_tree($subdir, $folder, $context).'
';
}
foreach ($dir['files'] as $file) {
$result .= '- '.folder_get_file_link($file, $folder, $context).'
';
}
$result .= '
';
return $result;
}
/**
* Returns file link
* @param object $file
* @param object $folder
* @param object $context
* @return string html link
*/
function folder_get_file_link($file, $folder, $context) {
global $CFG, $OUTPUT;
$strfile = get_string('file');
$strdownload = get_string('download');
$urlbase = "$CFG->wwwroot/pluginfile.php";
$path = '/'.$context->id.'/folder_content/'.$folder->revision.$file->get_filepath().$file->get_filename();
$viewurl = file_encode_url($urlbase, $path, false);
$downloadurl = file_encode_url($urlbase, $path, true);
$downicon = $OUTPUT->pix_url('t/down');
$mimeicon = $OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype()));
$downloadurl = "
";
return "
".s($file->get_filename()).''.$downloadurl;
}
/**
* File browsing support class
*/
class folder_content_file_info extends file_info_stored {
public function get_parent() {
if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
return $this->browser->get_file_info($this->context);
}
return parent::get_parent();
}
public function get_visible_name() {
if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
return $this->topvisiblename;
}
return parent::get_visible_name();
}
}