diff --git a/blocks/private_files/block_private_files.php b/blocks/private_files/block_private_files.php index 1301112c5ae..a5c6ef287ec 100755 --- a/blocks/private_files/block_private_files.php +++ b/blocks/private_files/block_private_files.php @@ -21,7 +21,7 @@ * * @package moodlecore * @subpackage repository - * @copyright 2010 Dongsheng Cai + * @copyright 2010 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -46,7 +46,7 @@ class block_private_files extends block_base { } function get_content() { - global $CFG, $USER, $PAGE; + global $CFG, $USER, $PAGE, $OUTPUT; if ($this->content !== NULL) { return $this->content; } @@ -56,36 +56,19 @@ class block_private_files extends block_base { $this->content->text = ''; $this->content->footer = ''; if (isloggedin() && !isguestuser()) { // Show the block - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); - $client_id = uniqid(); - $params = new stdclass; - $params->accepted_types = '*'; - $params->return_types = FILE_INTERNAL; - $params->context = $PAGE->context; - $params->env = 'filemanager'; - - $filepicker_options = initialise_filepicker($params); - - $fs = get_file_storage(); - $draftfiles = $fs->get_area_files($usercontext->id, 'user_private', 0, 'id', false); - // the number of existing files in user private area - $filecount = count($draftfiles); - - // read existing user private files - $options = file_get_user_area_files(0, '/', 'user_private'); + $options = new stdclass; $options->maxbytes = -1; $options->maxfiles = -1; $options->filearea = 'user_private'; - $options->client_id = $client_id; - $options->filecount = $filecount; $options->itemid = 0; $options->subdirs = true; - // store filepicker options - $options->filepicker = $filepicker_options; + $options->accepted_types = '*'; + $options->return_types = FILE_INTERNAL; + $options->context = $PAGE->context; $this->content = new stdClass; - $this->content->text = print_filemanager($options, true); + $this->content->text = $OUTPUT->file_manager($options); ; $this->content->footer = ''; diff --git a/lang/en/repository.php b/lang/en/repository.php index 211b4cf23e1..31be839b391 100644 --- a/lang/en/repository.php +++ b/lang/en/repository.php @@ -156,6 +156,7 @@ $string['upload'] = 'Upload this file'; $string['uploading'] = 'Uploading...'; $string['uploadsucc'] = 'The file has been uploaded successfully'; $string['usercontextrepositorydisabled'] = 'You cannot edit this repository in user context'; +$string['usenonjsfilemanager'] = 'Use non javascript file manager'; $string['wrongcontext'] = 'You cannot access to this context'; $string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle'; $string['ziped'] = 'Compress folder successfully'; diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 076ba1d6540..56f7dc2ac9d 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -132,36 +132,26 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { $draftitemid = $this->getValue(); } - $draftareainfo = file_get_draft_area_info($draftitemid); - $filecount = $draftareainfo['filecount']; $client_id = uniqid(); - $params = new stdclass; - $params->accepted_types = $accepted_types; - $params->return_types = FILE_INTERNAL; - $params->context = $PAGE->context; - $params->env = 'filemanager'; - - // including the repository instances list - $filepicker_options = initialise_filepicker($params); - - // including draft files - $options = file_get_user_area_files($draftitemid, '/', 'user_draft'); // filemanager options - $options->filepicker = $filepicker_options; + $options = new stdclass; $options->mainfile = $this->_options['mainfile']; + $options->filearea = 'user_draft'; $options->maxbytes = $this->_options['maxbytes']; $options->maxfiles = $this->getMaxfiles(); $options->client_id = $client_id; - $options->filecount = $filecount; $options->itemid = $draftitemid; $options->subdirs = $this->_options['subdirs']; - // store filepicker options $options->target = $id; + $options->accepted_types = $accepted_types; + $options->return_types = FILE_INTERNAL; + $options->context = $PAGE->context; $html = $this->_getTabs(); + $html .= $OUTPUT->file_manager($options); + $html .= ''; - $html .= print_filemanager($options, true); return $html; } diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index d1ec56078be..e1187d9036d 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -35,6 +35,61 @@ interface renderable { // intentionally empty } +/** + * Data structure representing a file manager. + * + * @copyright 2010 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 2.0 + */ +class file_manager implements renderable { + public $options; + public function __construct(stdClass $options) { + global $CFG, $USER, $PAGE; + require_once($CFG->dirroot. '/repository/lib.php'); + $defaults = array( + 'maxbytes'=>-1, + 'maxfiles'=>-1, + 'filearea'=>'user_draft', + 'itemid'=>0, + 'subdirs'=>0, + 'client_id'=>uniqid(), + 'accepted_types'=>'*', + 'return_types'=>FILE_INTERNAL, + 'context'=>$PAGE->context + ); + foreach ($defaults as $key=>$value) { + if (empty($options->$key)) { + $options->$key = $value; + } + } + + $fs = get_file_storage(); + + // initilise options, getting files in root path + $this->options = file_get_user_area_files($options->itemid, '/', $options->filearea); + + // calculate file count + $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $files = $fs->get_area_files($usercontext->id, $options->filearea, $options->itemid, 'id', false); + $filecount = count($files); + $this->options->filecount = $filecount; + + // copying other options + foreach ($options as $name=>$value) { + $this->options->$name = $value; + } + + // building file picker options + $params = new stdclass; + $params->accepted_types = $options->accepted_types; + $params->return_types = $options->return_types; + $params->context = $options->context; + $params->env = 'filemanager'; + $filepicker_options = initialise_filepicker($params); + $this->options->filepicker = $filepicker_options; + } +} /** * Data structure representing a user picture. @@ -2133,7 +2188,7 @@ class custom_menu extends custom_menu_item { * -Second level third item|http://www.moodle.com/development/ * First level second item|http://www.moodle.com/feedback/ * First level third item - * + * * @static * @param string $text * @return array @@ -2217,4 +2272,4 @@ class custom_menu extends custom_menu_item { } return ($itema > $itemb) ? +1 : -1; } -} \ No newline at end of file +} diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 094d42f532f..7f5a4694d7c 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -623,7 +623,7 @@ class core_renderer extends renderer_base { global $CFG, $DB; $output = $this->container_end_all(true); - + $footer = $this->opencontainers->pop('header/footer'); if (debugging() and $DB and $DB->is_transaction_started()) { @@ -739,7 +739,7 @@ class core_renderer extends renderer_base { $output = html_writer::tag('a', get_string('skipa', 'access', $skiptitle), array('href' => '#sb-' . $bc->skipid, 'class' => 'skip-block')); $skipdest = html_writer::tag('span', '', array('id' => 'sb-' . $bc->skipid, 'class' => 'skip-block-to')); } - + $output .= html_writer::start_tag('div', $bc->attributes); $controlshtml = $this->block_controls($bc->controls); @@ -1269,9 +1269,9 @@ class core_renderer extends renderer_base { $ratinghtml = ''; //the string we'll return //permissions check - can they view the aggregate? - if ( ($rating->itemuserid==$USER->id + if ( ($rating->itemuserid==$USER->id && $rating->settings->permissions->view && $rating->settings->pluginpermissions->view) - || ($rating->itemuserid!=$USER->id + || ($rating->itemuserid!=$USER->id && $rating->settings->permissions->viewany && $rating->settings->pluginpermissions->viewany) ) { $aggregatelabel = ''; @@ -1337,7 +1337,7 @@ class core_renderer extends renderer_base { && $rating->settings->permissions->rate && $rating->settings->pluginpermissions->rate && $inassessablewindow) { - + //start the rating form $formstart = html_writer::start_tag('form', array('id'=>"postrating{$rating->itemid}", 'class'=>'postratingform', 'method'=>'post', 'action'=>"{$CFG->wwwroot}/rating/rate.php")); @@ -1391,7 +1391,7 @@ class core_renderer extends renderer_base { $ratinghtml .= html_writer::select($scalearray, 'rating', $rating->rating, false, array('class'=>'postratingmenu ratinginput','id'=>'menurating'.$rating->itemid)); //output submit button - + $ratinghtml .= html_writer::start_tag('span', array('class'=>"ratingsubmit")); $attributes = array('type'=>'submit', 'class'=>'postratingmenusubmit', 'id'=>'postratingsubmit'.$rating->itemid, 'value'=>s(get_string('rate', 'rating'))); @@ -1720,6 +1720,127 @@ class core_renderer extends renderer_base { return html_writer::tag('a', $output, $attributes); } + /** + * Print the file manager + * + *
+     * $OUTPUT->file_manager($options);
+     * 
+ * + * @param array $options associative array with file manager options + * options are: + * maxbytes=>-1, + * maxfiles=>-1, + * filearea=>'user_draft', + * itemid=>0, + * subdirs=>false, + * client_id=>uniqid(), + * ccepted_types=>'*', + * return_types=>FILE_INTERNAL, + * context=>$PAGE->context + * @return string HTML fragment + */ + public function file_manager($options) { + $fm = new file_manager($options); + return $this->render($fm); + } + + /** + * Internal implementation of file manager rendering. + * @param file_manager $fm + * @return string + */ + public function render_file_manager(file_manager $fm) { + global $CFG, $OUTPUT; + static $filemanagertemplateloaded; + $html = ''; + $nonjsfilemanager = optional_param('usenonjsfilemanager', 0, PARAM_INT); + $options = $fm->options; + $straddfile = get_string('add', 'repository') . '...'; + $strmakedir = get_string('makeafolder', 'moodle'); + $strdownload = get_string('downloadfolder', 'repository'); + + $icon_add_file = $OUTPUT->pix_icon('t/addfile', $straddfile).''; + $icon_add_folder = $OUTPUT->pix_icon('t/adddir', $strmakedir).''; + $icon_download = $OUTPUT->pix_icon('t/download', $strdownload).''; + + $client_id = $options->client_id; + $itemid = $options->itemid; + $filearea = $options->filearea; + + if (empty($options->filecount)) { + $extra = ' style="display:none"'; + } else { + $extra = ''; + } + + $html .= <<