[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/files/ -> renderer.php (source)

   1  <?php
   2  ///////////////////////////////////////////////////////////////////////////
   3  //                                                                       //
   4  // This file is part of Moodle - http://moodle.org/                      //
   5  // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
   6  //                                                                       //
   7  // Moodle is free software: you can redistribute it and/or modify        //
   8  // it under the terms of the GNU General Public License as published by  //
   9  // the Free Software Foundation, either version 3 of the License, or     //
  10  // (at your option) any later version.                                   //
  11  //                                                                       //
  12  // Moodle is distributed in the hope that it will be useful,             //
  13  // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  14  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  15  // GNU General Public License for more details.                          //
  16  //                                                                       //
  17  // You should have received a copy of the GNU General Public License     //
  18  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.       //
  19  //                                                                       //
  20  ///////////////////////////////////////////////////////////////////////////
  21  
  22  defined('MOODLE_INTERNAL') || die();
  23  
  24  /**
  25   * Rendering of files viewer related widgets.
  26   * @package   core
  27   * @subpackage file
  28   * @copyright 2010 Dongsheng Cai
  29   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   * @since     Moodle 2.0
  31   */
  32  
  33  /**
  34   * File browser render
  35   *
  36   * @copyright 2010 Dongsheng Cai
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   * @since     Moodle 2.0
  39   */
  40  class core_files_renderer extends plugin_renderer_base {
  41  
  42      public function files_tree_viewer(file_info $file_info, array $options = null) {
  43          $tree = new files_tree_viewer($file_info, $options);
  44          return $this->render($tree);
  45      }
  46  
  47      public function render_files_tree_viewer(files_tree_viewer $tree) {
  48          $html = $this->output->heading_with_help(get_string('coursefiles'), 'courselegacyfiles', 'moodle');
  49  
  50          $html .= $this->output->container_start('coursefilesbreadcrumb');
  51          foreach($tree->path as $path) {
  52              $html .= $path;
  53              $html .= ' / ';
  54          }
  55          $html .= $this->output->container_end();
  56  
  57          $html .= $this->output->box_start();
  58          $table = new html_table();
  59          $table->head = array(get_string('name'), get_string('lastmodified'), get_string('size', 'repository'), get_string('type', 'repository'));
  60          $table->align = array('left', 'left', 'left', 'left');
  61          $table->width = '100%';
  62          $table->data = array();
  63  
  64          foreach ($tree->tree as $file) {
  65              $filedate = $filesize = $filetype = '';
  66              if ($file['filedate']) {
  67                  $filedate = userdate($file['filedate'], get_string('strftimedatetimeshort', 'langconfig'));
  68              }
  69              if (empty($file['isdir'])) {
  70                  if ($file['filesize']) {
  71                      $filesize = display_size($file['filesize']);
  72                  }
  73                  $fileicon = file_file_icon($file, 24);
  74                  $filetype = get_mimetype_description($file);
  75              } else {
  76                  $fileicon = file_folder_icon(24);
  77              }
  78              $table->data[] = array(
  79                  html_writer::link($file['url'], $this->output->pix_icon($fileicon, get_string('icon')) . ' ' . $file['filename']),
  80                  $filedate,
  81                  $filesize,
  82                  $filetype
  83                  );
  84          }
  85  
  86          $html .= html_writer::table($table);
  87          $html .= $this->output->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid'=>$tree->context->id)), get_string('coursefilesedit'), 'get');
  88          $html .= $this->output->box_end();
  89          return $html;
  90      }
  91  
  92      /**
  93       * Prints the file manager and initializes all necessary libraries
  94       *
  95       * <pre>
  96       * $fm = new form_filemanager($options);
  97       * $output = get_renderer('core', 'files');
  98       * echo $output->render($fm);
  99       * </pre>
 100       *
 101       * @param form_filemanager $fm File manager to render
 102       * @return string HTML fragment
 103       */
 104      public function render_form_filemanager($fm) {
 105          $html = $this->fm_print_generallayout($fm);
 106          $module = array(
 107              'name'=>'form_filemanager',
 108              'fullpath'=>'/lib/form/filemanager.js',
 109              'requires' => array('moodle-core-notification-dialogue', 'core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'),
 110              'strings' => array(
 111                  array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'),
 112                  array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
 113                  array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'),
 114                  array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'),
 115                  array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'),
 116                  array('confirmrenamefile', 'repository'), array('newfolder', 'repository'), array('edit', 'moodle')
 117              )
 118          );
 119          if ($this->page->requires->should_create_one_time_item_now('core_file_managertemplate')) {
 120              $this->page->requires->js_init_call('M.form_filemanager.set_templates',
 121                      array($this->filemanager_js_templates()), true, $module);
 122          }
 123          $this->page->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module);
 124  
 125          // non javascript file manager
 126          $html .= '<noscript>';
 127          $html .= "<div><object type='text/html' data='".$fm->get_nonjsurl()."' height='160' width='600' style='border:1px solid #000'></object></div>";
 128          $html .= '</noscript>';
 129  
 130  
 131          return $html;
 132      }
 133  
 134      /**
 135       * Returns html for displaying one file manager
 136       *
 137       * The main element in HTML must have id="filemanager-{$client_id}" and
 138       * class="filemanager fm-loading";
 139       * After all necessary code on the page (both html and javascript) is loaded,
 140       * the class fm-loading will be removed and added class fm-loaded;
 141       * The main element (class=filemanager) will be assigned the following classes:
 142       * 'fm-maxfiles' - when filemanager has maximum allowed number of files;
 143       * 'fm-nofiles' - when filemanager has no files at all (although there might be folders);
 144       * 'fm-noitems' - when current view (folder) has no items - neither files nor folders;
 145       * 'fm-updating' - when current view is being updated (usually means that loading icon is to be displayed);
 146       * 'fm-nomkdir' - when 'Make folder' action is unavailable (empty($fm->options->subdirs) == true)
 147       *
 148       * Element with class 'filemanager-container' will be holding evens for dnd upload (dragover, etc.).
 149       * It will have class:
 150       * 'dndupload-ready' - when a file is being dragged over the browser
 151       * 'dndupload-over' - when file is being dragged over this filepicker (additional to 'dndupload-ready')
 152       * 'dndupload-uploading' - during the upload process (note that after dnd upload process is
 153       * over, the file manager will refresh the files list and therefore will have for a while class
 154       * fm-updating. Both waiting processes should look similar so the images don't jump for user)
 155       *
 156       * If browser supports Drag-and-drop, the body element will have class 'dndsupported',
 157       * otherwise - 'dndnotsupported';
 158       *
 159       * Element with class 'fp-content' will be populated with files list;
 160       * Element with class 'fp-btn-add' will hold onclick event for adding a file (opening filepicker);
 161       * Element with class 'fp-btn-mkdir' will hold onclick event for adding new folder;
 162       * Element with class 'fp-btn-download' will hold onclick event for download action;
 163       *
 164       * Element with class 'fp-path-folder' is a template for one folder in path toolbar.
 165       * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
 166       * Parent element will receive class 'empty' when there are no folders to be displayed;
 167       * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
 168       *
 169       * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode
 170       * can be changed or not;
 171       * Inside element with class 'fp-viewbar' there are expected elements with classes
 172       * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch
 173       * between the view modes, the last clicked element will have the class 'checked';
 174       *
 175       * @param form_filemanager $fm
 176       * @return string
 177       */
 178      private function fm_print_generallayout($fm) {
 179          global $OUTPUT;
 180          $options = $fm->options;
 181          $client_id = $options->client_id;
 182          $straddfile  = get_string('addfile', 'repository');
 183          $strmakedir  = get_string('makeafolder', 'moodle');
 184          $strdownload = get_string('downloadfolder', 'repository');
 185          $strloading  = get_string('loading', 'repository');
 186          $strdroptoupload = get_string('droptoupload', 'moodle');
 187          $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
 188          $restrictions = $this->fm_print_restrictions($fm);
 189          $strdndnotsupported = get_string('dndnotsupported_insentence', 'moodle').$OUTPUT->help_icon('dndnotsupported');
 190          $strdndenabledinbox = get_string('dndenabled_inbox', 'moodle');
 191          $loading = get_string('loading', 'repository');
 192  
 193          $html = '
 194  <div id="filemanager-'.$client_id.'" class="filemanager fm-loading">
 195      <div class="fp-restrictions">
 196          '.$restrictions.'
 197          <span class="dnduploadnotsupported-message"> - '.$strdndnotsupported.' </span>
 198      </div>
 199      <div class="fp-navbar">
 200          <div class="filemanager-toolbar">
 201              <div class="fp-toolbar">
 202                  <div class="fp-btn-add">
 203                      <a role="button" title="'.$straddfile.'" href="#"><img src="'.$this->pix_url('a/add_file').'" alt="" /></a>
 204                  </div>
 205                  <div class="fp-btn-mkdir">
 206                      <a role="button" title="'.$strmakedir.'" href="#"><img src="'.$this->pix_url('a/create_folder').'" alt="" /></a>
 207                  </div>
 208                  <div class="fp-btn-download">
 209                      <a role="button" title="'.$strdownload.'" href="#"><img src="'.$this->pix_url('a/download_all').'" alt="" /></a>
 210                  </div>
 211                  <img class="fp-img-downloading" src="'.$this->pix_url('i/loading_small').'" alt="" />
 212              </div>
 213              <div class="fp-viewbar">
 214                  <a title="'. get_string('displayicons', 'repository') .'" class="fp-vb-icons" href="#">
 215                      <img alt="" src="'. $this->pix_url('fp/view_icon_active', 'theme') .'" />
 216                  </a>
 217                  <a title="'. get_string('displaydetails', 'repository') .'" class="fp-vb-details" href="#">
 218                      <img alt="" src="'. $this->pix_url('fp/view_list_active', 'theme') .'" />
 219                  </a>
 220                  <a title="'. get_string('displaytree', 'repository') .'" class="fp-vb-tree" href="#">
 221                      <img alt="" src="'. $this->pix_url('fp/view_tree_active', 'theme') .'" />
 222                  </a>
 223              </div>
 224          </div>
 225          <div class="fp-pathbar">
 226              <span class="fp-path-folder"><a class="fp-path-folder-name" href="#"></a></span>
 227          </div>
 228      </div>
 229      <div class="filemanager-loading mdl-align">'.$icon_progress.'</div>
 230      <div class="filemanager-container" >
 231          <div class="fm-content-wrapper">
 232              <div class="fp-content"></div>
 233              <div class="fm-empty-container">
 234                  <div class="dndupload-message">'.$strdndenabledinbox.'<br/><div class="dndupload-arrow"></div></div>
 235              </div>
 236              <div class="dndupload-target">'.$strdroptoupload.'<br/><div class="dndupload-arrow"></div></div>
 237              <div class="dndupload-progressbars"></div>
 238              <div class="dndupload-uploadinprogress">'.$icon_progress.'</div>
 239          </div>
 240          <div class="filemanager-updating">'.$icon_progress.'</div>
 241      </div>
 242  </div>';
 243          return $html;
 244      }
 245  
 246      /**
 247       * FileManager JS template for displaying one file in 'icon view' mode.
 248       *
 249       * Except for elements described in fp_js_template_iconfilename, this template may also
 250       * contain element with class 'fp-contextmenu'. If context menu is available for this
 251       * file, the top element will receive the additional class 'fp-hascontextmenu' and
 252       * the element with class 'fp-contextmenu' will hold onclick event for displaying
 253       * the context menu.
 254       *
 255       * @see fp_js_template_iconfilename()
 256       * @return string
 257       */
 258      private function fm_js_template_iconfilename() {
 259          $rv = '
 260  <div class="fp-file">
 261      <a href="#">
 262      <div style="position:relative;">
 263          <div class="fp-thumbnail"></div>
 264          <div class="fp-reficons1"></div>
 265          <div class="fp-reficons2"></div>
 266      </div>
 267      <div class="fp-filename-field">
 268          <div class="fp-filename"></div>
 269      </div>
 270      </a>
 271      <a class="fp-contextmenu" href="#">'.$this->pix_icon('i/menu', 'â–¶').'</a>
 272  </div>';
 273          return $rv;
 274      }
 275  
 276      /**
 277       * FileManager JS template for displaying file name in 'table view' and 'tree view' modes.
 278       *
 279       * Except for elements described in fp_js_template_listfilename, this template may also
 280       * contain element with class 'fp-contextmenu'. If context menu is available for this
 281       * file, the top element will receive the additional class 'fp-hascontextmenu' and
 282       * the element with class 'fp-contextmenu' will hold onclick event for displaying
 283       * the context menu.
 284       *
 285       * @todo MDL-32736 remove onclick="return false;"
 286       * @see fp_js_template_listfilename()
 287       * @return string
 288       */
 289      private function fm_js_template_listfilename() {
 290          $rv = '
 291  <span class="fp-filename-icon">
 292      <a href="#">
 293      <span class="fp-icon"></span>
 294      <span class="fp-reficons1"></span>
 295      <span class="fp-reficons2"></span>
 296      <span class="fp-filename"></span>
 297      </a>
 298      <a class="fp-contextmenu" href="#" onclick="return false;">'.$this->pix_icon('i/menu', 'â–¶').'</a>
 299  </span>';
 300          return $rv;
 301      }
 302  
 303      /**
 304       * FileManager JS template for displaying 'Make new folder' dialog.
 305       *
 306       * Must be wrapped in an element, CSS for this element must define width and height of the window;
 307       *
 308       * Must have one input element with type="text" (for users to enter the new folder name);
 309       *
 310       * content of element with class 'fp-dlg-curpath' will be replaced with current path where
 311       * new folder is about to be created;
 312       * elements with classes 'fp-dlg-butcreate' and 'fp-dlg-butcancel' will hold onclick events;
 313       *
 314       * @return string
 315       */
 316      private function fm_js_template_mkdir() {
 317          $rv = '
 318  <div class="filemanager fp-mkdir-dlg" role="dialog" aria-live="assertive" aria-labelledby="fp-mkdir-dlg-title">
 319      <div class="fp-mkdir-dlg-text">
 320          <label id="fp-mkdir-dlg-title">' . get_string('newfoldername', 'repository') . '</label><br/>
 321          <input type="text" />
 322      </div>
 323      <button class="fp-dlg-butcreate btn-primary btn">'.get_string('makeafolder').'</button>
 324      <button class="fp-dlg-butcancel btn-cancel btn">'.get_string('cancel').'</button>
 325  </div>';
 326          return $rv;
 327      }
 328  
 329      /**
 330       * FileManager JS template for error/info message displayed as a separate popup window.
 331       *
 332       * @see fp_js_template_message()
 333       * @return string
 334       */
 335      private function fm_js_template_message() {
 336          return $this->fp_js_template_message();
 337      }
 338  
 339      /**
 340       * FileManager JS template for window with file information/actions.
 341       *
 342       * All content must be enclosed in one element, CSS for this class must define width and
 343       * height of the window;
 344       *
 345       * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
 346       *
 347       * Inside the window the elements with the following classnames must be present:
 348       * 'fp-saveas', 'fp-author', 'fp-license', 'fp-path'. Inside each of them must be
 349       * one input element (or select in case of fp-license and fp-path). They may also have labels.
 350       * The elements will be assign with class 'uneditable' and input/select element will become
 351       * disabled if they are not applicable for the particular file;
 352       *
 353       * There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated',
 354       * 'fp-size', 'fp-dimensions', 'fp-reflist'. They will receive additional class 'fp-unknown' if
 355       * information is unavailable. If there is information available, the content of embedded
 356       * element with class 'fp-value' will be substituted with the value;
 357       *
 358       * The value of Original ('fp-original') is loaded in separate request. When it is applicable
 359       * but not yet loaded the 'fp-original' element receives additional class 'fp-loading';
 360       *
 361       * The value of 'Aliases/Shortcuts' ('fp-reflist') is also loaded in separate request. When it
 362       * is applicable but not yet loaded the 'fp-original' element receives additional class
 363       * 'fp-loading'. The string explaining that XX references exist will replace content of element
 364       * 'fp-refcount'. Inside '.fp-reflist .fp-value' each reference will be enclosed in <li>;
 365       *
 366       * Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip',
 367       * 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick
 368       * events (there may be several elements with class 'fp-file-cancel');
 369       *
 370       * When confirm button is pressed and file is being selected, the top element receives
 371       * additional class 'loading'. It is removed when response from server is received.
 372       *
 373       * When any of the input fields is changed, the top element receives class 'fp-changed';
 374       * When current file can be set as main - top element receives class 'fp-cansetmain';
 375       * When current file is folder/zip/file - top element receives respectfully class
 376       * 'fp-folder'/'fp-zip'/'fp-file';
 377       *
 378       * @return string
 379       */
 380      private function fm_js_template_fileselectlayout() {
 381          global $OUTPUT;
 382          $strloading  = get_string('loading', 'repository');
 383          $iconprogress = $this->pix_icon('i/loading_small', $strloading).'';
 384          $rv = '
 385  <div class="filemanager fp-select">
 386      <div class="fp-select-loading">
 387          <img src="'.$this->pix_url('i/loading_small').'" />
 388      </div>
 389      <form class="form-horizontal">
 390          <button class="fp-file-download">'.get_string('download').'</button>
 391          <button class="fp-file-delete">'.get_string('delete').'</button>
 392          <button class="fp-file-setmain">'.get_string('setmainfile', 'repository').'</button>
 393          <span class="fp-file-setmain-help">'.$OUTPUT->help_icon('setmainfile', 'repository').'</span>
 394          <button class="fp-file-zip">'.get_string('zip', 'editor').'</button>
 395          <button class="fp-file-unzip">'.get_string('unzip').'</button>
 396          <div class="fp-hr"></div>
 397  
 398          <div class="fp-forminset">
 399                  <div class="fp-saveas control-group clearfix">
 400                      <label class="control-label">'.get_string('name', 'repository').'</label>
 401                      <div class="controls">
 402                          <input type="text"/>
 403                      </div>
 404                  </div>
 405                  <div class="fp-author control-group clearfix">
 406                      <label class="control-label">'.get_string('author', 'repository').'</label>
 407                      <div class="controls">
 408                          <input type="text"/>
 409                      </div>
 410                  </div>
 411                  <div class="fp-license control-group clearfix">
 412                      <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
 413                      <div class="controls">
 414                          <select></select>
 415                      </div>
 416                  </div>
 417                  <div class="fp-path control-group clearfix">
 418                      <label class="control-label">'.get_string('path', 'repository').'</label>
 419                      <div class="controls">
 420                          <select></select>
 421                      </div>
 422                  </div>
 423                  <div class="fp-original control-group clearfix">
 424                      <label class="control-label">'.get_string('original', 'repository').'</label>
 425                      <div class="controls">
 426                          <span class="fp-originloading">'.$iconprogress.' '.$strloading.'</span><span class="fp-value"></span>
 427                      </div>
 428                  </div>
 429                  <div class="fp-reflist control-group clearfix">
 430                      <label class="control-label">'.get_string('referenceslist', 'repository').'</label>
 431                      <div class="controls">
 432                          <p class="fp-refcount"></p>
 433                          <span class="fp-reflistloading">'.$iconprogress.' '.$strloading.'</span>
 434                          <ul class="fp-value"></ul>
 435                      </div>
 436                  </div>
 437          </div>
 438          <div class="fp-select-buttons">
 439              <button class="fp-file-update btn-primary btn">'.get_string('update', 'moodle').'</button>
 440              <button class="fp-file-cancel btn-cancel btn">'.get_string('cancel').'</button>
 441          </div>
 442      </form>
 443      <div class="fp-info clearfix">
 444          <div class="fp-hr"></div>
 445          <p class="fp-thumbnail"></p>
 446          <div class="fp-fileinfo">
 447              <div class="fp-datemodified">'.get_string('lastmodified', 'repository').' <span class="fp-value"></span></div>
 448              <div class="fp-datecreated">'.get_string('datecreated', 'repository').' <span class="fp-value"></span></div>
 449              <div class="fp-size">'.get_string('size', 'repository').' <span class="fp-value"></span></div>
 450              <div class="fp-dimensions">'.get_string('dimensions', 'repository').' <span class="fp-value"></span></div>
 451          </div>
 452      </div>
 453  </div>';
 454          return $rv;
 455      }
 456  
 457      /**
 458       * FileManager JS template for popup confirm dialogue window.
 459       *
 460       * Must have one top element, CSS for this element must define width and height of the window;
 461       *
 462       * content of element with class 'fp-dlg-text' will be replaced with dialog text;
 463       * elements with classes 'fp-dlg-butconfirm' and 'fp-dlg-butcancel' will
 464       * hold onclick events;
 465       *
 466       * @return string
 467       */
 468      private function fm_js_template_confirmdialog() {
 469          $rv = '
 470  <div class="filemanager fp-dlg">
 471      <div class="fp-dlg-text"></div>
 472      <button class="fp-dlg-butconfirm btn-primary btn">'.get_string('ok').'</button>
 473      <button class="fp-dlg-butcancel btn-cancel btn">'.get_string('cancel').'</button>
 474  </div>';
 475          return $rv;
 476      }
 477  
 478      /**
 479       * Returns all FileManager JavaScript templates as an array.
 480       *
 481       * @return array
 482       */
 483      public function filemanager_js_templates() {
 484          $class_methods = get_class_methods($this);
 485          $templates = array();
 486          foreach ($class_methods as $method_name) {
 487              if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches))
 488              $templates[$matches[1]] = $this->$method_name();
 489          }
 490          return $templates;
 491      }
 492  
 493      /**
 494       * Displays restrictions for the file manager
 495       *
 496       * @param form_filemanager $fm
 497       * @return string
 498       */
 499      private function fm_print_restrictions($fm) {
 500          $maxbytes = display_size($fm->options->maxbytes);
 501          $strparam = (object) array('size' => $maxbytes, 'attachments' => $fm->options->maxfiles,
 502              'areasize' => display_size($fm->options->areamaxbytes));
 503          $hasmaxfiles = !empty($fm->options->maxfiles) && $fm->options->maxfiles > 0;
 504          $hasarealimit = !empty($fm->options->areamaxbytes) && $fm->options->areamaxbytes != -1;
 505          if ($hasmaxfiles && $hasarealimit) {
 506              $maxsize = get_string('maxsizeandattachmentsandareasize', 'moodle', $strparam);
 507          } else if ($hasmaxfiles) {
 508              $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam);
 509          } else if ($hasarealimit) {
 510              $maxsize = get_string('maxsizeandareasize', 'moodle', $strparam);
 511          } else {
 512              $maxsize = get_string('maxfilesize', 'moodle', $maxbytes);
 513          }
 514          // TODO MDL-32020 also should say about 'File types accepted'
 515          return '<span>'. $maxsize . '</span>';
 516      }
 517  
 518      /**
 519       * Template for FilePicker with general layout (not QuickUpload).
 520       *
 521       * Must have one top element containing everything else (recommended <div class="file-picker">),
 522       * CSS for this element must define width and height of the filepicker window. Or CSS must
 523       * define min-width, max-width, min-height and max-height and in this case the filepicker
 524       * window will be resizeable;
 525       *
 526       * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode
 527       * can be changed or not;
 528       * Inside element with class 'fp-viewbar' there are expected elements with classes
 529       * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch
 530       * between the view modes, the last clicked element will have the class 'checked';
 531       *
 532       * Element with class 'fp-repo' is a template for displaying one repository. Other repositories
 533       * will be attached as siblings (classes first/last/even/odd will be added respectfully).
 534       * The currently selected repostory will have class 'active'. Contents of element with class
 535       * 'fp-repo-name' will be replaced with repository name, source of image with class
 536       * 'fp-repo-icon' will be replaced with repository icon;
 537       *
 538       * Element with class 'fp-content' is obligatory and will hold the current contents;
 539       *
 540       * Element with class 'fp-paging' will contain page navigation (will be deprecated soon);
 541       *
 542       * Element with class 'fp-path-folder' is a template for one folder in path toolbar.
 543       * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
 544       * Parent element will receive class 'empty' when there are no folders to be displayed;
 545       * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
 546       *
 547       * Element with class 'fp-toolbar' will have class 'empty' if all 'Back', 'Search', 'Refresh',
 548       * 'Logout', 'Manage' and 'Help' are unavailable for this repo;
 549       *
 550       * Inside fp-toolbar there are expected elements with classes fp-tb-back, fp-tb-search,
 551       * fp-tb-refresh, fp-tb-logout, fp-tb-manage and fp-tb-help. Each of them will have
 552       * class 'enabled' or 'disabled' if particular repository has this functionality.
 553       * Element with class 'fp-tb-search' must contain empty form inside, it's contents will
 554       * be substituted with the search form returned by repository (in the most cases it
 555       * is generated with template core_repository_renderer::repository_default_searchform);
 556       * Other elements must have either <a> or <button> element inside, it will hold onclick
 557       * event for corresponding action; labels for fp-tb-back and fp-tb-logout may be
 558       * replaced with those specified by repository;
 559       *
 560       * @return string
 561       */
 562      private function fp_js_template_generallayout() {
 563          $rv = '
 564  <div tabindex="0" class="file-picker fp-generallayout" role="dialog" aria-live="assertive">
 565      <div class="fp-repo-area">
 566          <ul class="fp-list">
 567              <li class="fp-repo">
 568                  <a href="#"><img class="fp-repo-icon" alt=" " width="16" height="16" />&nbsp;<span class="fp-repo-name"></span></a>
 569              </li>
 570          </ul>
 571      </div>
 572      <div class="fp-repo-items" tabindex="0">
 573          <div class="fp-navbar">
 574              <div>
 575                  <div class="fp-toolbar">
 576                      <div class="fp-tb-back">
 577                          <a href="#">'.get_string('back', 'repository').'</a>
 578                      </div>
 579                      <div class="fp-tb-search">
 580                          <form></form>
 581                      </div>
 582                      <div class="fp-tb-refresh">
 583                          <a title="'. get_string('refresh', 'repository') .'" href="#">
 584                              <img alt=""  src="'.$this->pix_url('a/refresh').'" />
 585                          </a>
 586                      </div>
 587                      <div class="fp-tb-logout">
 588                          <a title="'. get_string('logout', 'repository') .'" href="#">
 589                              <img alt="" src="'.$this->pix_url('a/logout').'" />
 590                          </a>
 591                      </div>
 592                      <div class="fp-tb-manage">
 593                          <a title="'. get_string('settings', 'repository') .'" href="#">
 594                              <img alt="" src="'.$this->pix_url('a/setting').'" />
 595                          </a>
 596                      </div>
 597                      <div class="fp-tb-help">
 598                          <a title="'. get_string('help', 'repository') .'" href="#">
 599                              <img alt="" src="'.$this->pix_url('a/help').'" />
 600                          </a>
 601                      </div>
 602                      <div class="fp-tb-message"></div>
 603                  </div>
 604                  <div class="fp-viewbar">
 605                      <a role="button" title="'. get_string('displayicons', 'repository') .'" class="fp-vb-icons" href="#">
 606                          <img alt="" src="'. $this->pix_url('fp/view_icon_active', 'theme') .'" />
 607                      </a>
 608                      <a role="button" title="'. get_string('displaydetails', 'repository') .'" class="fp-vb-details" href="#">
 609                          <img alt="" src="'. $this->pix_url('fp/view_list_active', 'theme') .'" />
 610                      </a>
 611                      <a role="button" title="'. get_string('displaytree', 'repository') .'" class="fp-vb-tree" href="#">
 612                          <img alt="" src="'. $this->pix_url('fp/view_tree_active', 'theme') .'" />
 613                      </a>
 614                  </div>
 615                  <div class="fp-clear-left"></div>
 616              </div>
 617              <div class="fp-pathbar">
 618                   <span class="fp-path-folder"><a class="fp-path-folder-name" href="#"></a></span>
 619              </div>
 620          </div>
 621          <div class="fp-content"></div>
 622      </div>
 623  </div>';
 624          return $rv;
 625      }
 626  
 627      /**
 628       * FilePicker JS template for displaying one file in 'icon view' mode.
 629       *
 630       * the element with class 'fp-thumbnail' will be resized to the repository thumbnail size
 631       * (both width and height, unless min-width and/or min-height is set in CSS) and the content of
 632       * an element will be replaced with an appropriate img;
 633       *
 634       * the width of element with class 'fp-filename' will be set to the repository thumbnail width
 635       * (unless min-width is set in css) and the content of an element will be replaced with filename
 636       * supplied by repository;
 637       *
 638       * top element(s) will have class fp-folder if the element is a folder;
 639       *
 640       * List of files will have parent <div> element with class 'fp-iconview'
 641       *
 642       * @return string
 643       */
 644      private function fp_js_template_iconfilename() {
 645          $rv = '
 646  <a class="fp-file" href="#" >
 647      <div style="position:relative;">
 648          <div class="fp-thumbnail"></div>
 649          <div class="fp-reficons1"></div>
 650          <div class="fp-reficons2"></div>
 651      </div>
 652      <div class="fp-filename-field">
 653          <p class="fp-filename"></p>
 654      </div>
 655  </a>';
 656          return $rv;
 657      }
 658  
 659      /**
 660       * FilePicker JS template for displaying file name in 'table view' and 'tree view' modes.
 661       *
 662       * content of the element with class 'fp-icon' will be replaced with an appropriate img;
 663       *
 664       * content of element with class 'fp-filename' will be replaced with filename supplied by
 665       * repository;
 666       *
 667       * top element(s) will have class fp-folder if the element is a folder;
 668       *
 669       * Note that tree view and table view are the YUI widgets and therefore there are no
 670       * other templates. The widgets will be wrapped in <div> with class fp-treeview or
 671       * fp-tableview (respectfully).
 672       *
 673       * @return string
 674       */
 675      private function fp_js_template_listfilename() {
 676          $rv = '
 677  <span class="fp-filename-icon">
 678      <a href="#">
 679          <span class="fp-icon"></span>
 680          <span class="fp-filename"></span>
 681      </a>
 682  </span>';
 683          return $rv;
 684      }
 685  
 686      /**
 687       * FilePicker JS template for displaying link/loading progress for fetching of the next page
 688       *
 689       * This text is added to .fp-content AFTER .fp-iconview/.fp-treeview/.fp-tableview
 690       *
 691       * Must have one parent element with class 'fp-nextpage'. It will be assigned additional
 692       * class 'loading' during loading of the next page (it is recommended that in this case the link
 693       * becomes unavailable). Also must contain one element <a> or <button> that will hold
 694       * onclick event for displaying of the next page. The event will be triggered automatically
 695       * when user scrolls to this link.
 696       *
 697       * @return string
 698       */
 699      private function fp_js_template_nextpage() {
 700          $rv = '
 701  <div class="fp-nextpage">
 702      <div class="fp-nextpage-link"><a href="#">'.get_string('more').'</a></div>
 703      <div class="fp-nextpage-loading">
 704          <img src="'.$this->pix_url('i/loading_small').'" />
 705      </div>
 706  </div>';
 707          return $rv;
 708      }
 709  
 710      /**
 711       * FilePicker JS template for window appearing to select a file.
 712       *
 713       * All content must be enclosed in one element, CSS for this class must define width and
 714       * height of the window;
 715       *
 716       * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
 717       *
 718       * Inside the window the elements with the following classnames must be present:
 719       * 'fp-saveas', 'fp-linktype-2', 'fp-linktype-1', 'fp-linktype-4', 'fp-setauthor',
 720       * 'fp-setlicense'. Inside each of them must have one input element (or select in case of
 721       * fp-setlicense). They may also have labels.
 722       * The elements will be assign with class 'uneditable' and input/select element will become
 723       * disabled if they are not applicable for the particular file;
 724       *
 725       * There may be present elements with classes 'fp-datemodified', 'fp-datecreated', 'fp-size',
 726       * 'fp-license', 'fp-author', 'fp-dimensions'. They will receive additional class 'fp-unknown'
 727       * if information is unavailable. If there is information available, the content of embedded
 728       * element with class 'fp-value' will be substituted with the value;
 729       *
 730       * Elements with classes 'fp-select-confirm' and 'fp-select-cancel' will hold corresponding
 731       * onclick events;
 732       *
 733       * When confirm button is pressed and file is being selected, the top element receives
 734       * additional class 'loading'. It is removed when response from server is received.
 735       *
 736       * @return string
 737       */
 738      private function fp_js_template_selectlayout() {
 739          $rv = '
 740  <div class="file-picker fp-select">
 741      <div class="fp-select-loading">
 742          <img src="'.$this->pix_url('i/loading_small').'" />
 743      </div>
 744      <form class="form-horizontal">
 745          <div class="fp-forminset">
 746                  <div class="fp-linktype-2 control-group control-radio clearfix">
 747                      <label class="control-label control-radio">'.get_string('makefileinternal', 'repository').'</label>
 748                      <div class="controls control-radio">
 749                          <input type="radio"/>
 750                      </div>
 751                  </div>
 752                  <div class="fp-linktype-1 control-group control-radio clearfix">
 753                      <label class="control-label control-radio">'.get_string('makefilelink', 'repository').'</label>
 754                      <div class="controls control-radio">
 755                          <input type="radio"/>
 756                      </div>
 757                  </div>
 758                  <div class="fp-linktype-4 control-group control-radio clearfix">
 759                      <label class="control-label control-radio">'.get_string('makefilereference', 'repository').'</label>
 760                      <div class="controls control-radio">
 761                          <input type="radio"/>
 762                      </div>
 763                  </div>
 764                  <div class="fp-saveas control-group clearfix">
 765                      <label class="control-label">'.get_string('saveas', 'repository').'</label>
 766                      <div class="controls">
 767                          <input type="text"/>
 768                      </div>
 769                  </div>
 770                  <div class="fp-setauthor control-group clearfix">
 771                      <label class="control-label">'.get_string('author', 'repository').'</label>
 772                      <div class="controls">
 773                          <input type="text"/>
 774                      </div>
 775                  </div>
 776                  <div class="fp-setlicense control-group clearfix">
 777                      <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
 778                      <div class="controls">
 779                          <select></select>
 780                      </div>
 781                  </div>
 782          </div>
 783         <div class="fp-select-buttons">
 784              <button class="fp-select-confirm btn-primary btn">'.get_string('getfile', 'repository').'</button>
 785              <button class="fp-select-cancel btn-cancel btn">'.get_string('cancel').'</button>
 786          </div>
 787      </form>
 788      <div class="fp-info clearfix">
 789          <div class="fp-hr"></div>
 790          <p class="fp-thumbnail"></p>
 791          <div class="fp-fileinfo">
 792              <div class="fp-datemodified">'.get_string('lastmodified', 'repository').'<span class="fp-value"></span></div>
 793              <div class="fp-datecreated">'.get_string('datecreated', 'repository').'<span class="fp-value"></span></div>
 794              <div class="fp-size">'.get_string('size', 'repository').'<span class="fp-value"></span></div>
 795              <div class="fp-license">'.get_string('license', 'repository').'<span class="fp-value"></span></div>
 796              <div class="fp-author">'.get_string('author', 'repository').'<span class="fp-value"></span></div>
 797              <div class="fp-dimensions">'.get_string('dimensions', 'repository').'<span class="fp-value"></span></div>
 798          </div>
 799      </div>
 800  </div>';
 801          return $rv;
 802      }
 803  
 804      /**
 805       * FilePicker JS template for 'Upload file' repository
 806       *
 807       * Content to display when user chooses 'Upload file' repository (will be nested inside
 808       * element with class 'fp-content').
 809       *
 810       * Must contain form (enctype="multipart/form-data" method="POST")
 811       *
 812       * The elements with the following classnames must be present:
 813       * 'fp-file', 'fp-saveas', 'fp-setauthor', 'fp-setlicense'. Inside each of them must have
 814       * one input element (or select in case of fp-setlicense). They may also have labels.
 815       *
 816       * Element with class 'fp-upload-btn' will hold onclick event for uploading the file;
 817       *
 818       * Please note that some fields may be hidden using CSS if this is part of quickupload form
 819       *
 820       * @return string
 821       */
 822      private function fp_js_template_uploadform() {
 823          $rv = '
 824  <div class="fp-upload-form">
 825      <div class="fp-content-center">
 826          <form enctype="multipart/form-data" method="POST" class="form-horizontal">
 827              <div class="fp-formset">
 828                  <div class="fp-file control-group clearfix">
 829                      <label class="control-label">'.get_string('attachment', 'repository').'</label>
 830                      <div class="controls">
 831                          <input type="file"/>
 832                      </div>
 833                  </div>
 834                  <div class="fp-saveas control-group clearfix">
 835                      <label class="control-label">'.get_string('saveas', 'repository').'</label>
 836                      <div class="controls">
 837                          <input type="text"/>
 838                      </div>
 839                  </div>
 840                  <div class="fp-setauthor control-group clearfix">
 841                      <label class="control-label">'.get_string('author', 'repository').'</label>
 842                      <div class="controls">
 843                          <input type="text"/>
 844                      </div>
 845                  </div>
 846                  <div class="fp-setlicense control-group clearfix">
 847                      <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
 848                      <div class="controls">
 849                          <select ></select>
 850                      </div>
 851                  </div>
 852              </div>
 853          </form>
 854          <div class="mdl-align">
 855              <button class="fp-upload-btn btn-primary btn">'.get_string('upload', 'repository').'</button>
 856          </div>
 857      </div>
 858  </div> ';
 859          return $rv;
 860      }
 861  
 862      /**
 863       * FilePicker JS template to display during loading process (inside element with class 'fp-content').
 864       *
 865       * @return string
 866       */
 867      private function fp_js_template_loading() {
 868          return '
 869  <div class="fp-content-loading">
 870      <div class="fp-content-center">
 871          <img src="'.$this->pix_url('i/loading_small').'" />
 872      </div>
 873  </div>';
 874      }
 875  
 876      /**
 877       * FilePicker JS template for error (inside element with class 'fp-content').
 878       *
 879       * must have element with class 'fp-error', its content will be replaced with error text
 880       * and the error code will be assigned as additional class to this element
 881       * used errors: invalidjson, nofilesavailable, norepositoriesavailable
 882       *
 883       * @return string
 884       */
 885      private function fp_js_template_error() {
 886          $rv = '
 887  <div class="fp-content-error" ><div class="fp-error"></div></div>';
 888          return $rv;
 889      }
 890  
 891      /**
 892       * FilePicker JS template for error/info message displayed as a separate popup window.
 893       *
 894       * Must be wrapped in one element, CSS for this element must define
 895       * width and height of the window. It will be assigned with an additional class 'fp-msg-error'
 896       * or 'fp-msg-info' depending on message type;
 897       *
 898       * content of element with class 'fp-msg-text' will be replaced with error/info text;
 899       *
 900       * element with class 'fp-msg-butok' will hold onclick event
 901       *
 902       * @return string
 903       */
 904      private function fp_js_template_message() {
 905          $rv = '
 906  <div class="file-picker fp-msg" role="alertdialog" aria-live="assertive" aria-labelledby="fp-msg-labelledby">
 907      <p class="fp-msg-text" id="fp-msg-labelledby"></p>
 908      <button class="fp-msg-butok btn-primary btn">'.get_string('ok').'</button>
 909  </div>';
 910          return $rv;
 911      }
 912  
 913      /**
 914       * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists.
 915       *
 916       * Must have one top element, CSS for this element must define width and height of the window;
 917       *
 918       * content of element with class 'fp-dlg-text' will be replaced with dialog text;
 919       * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename',
 920       * 'fp-dlg-butoverwriteall', 'fp-dlg-butrenameall' and 'fp-dlg-butcancel' will
 921       * hold onclick events;
 922       *
 923       * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
 924       * (Note that it may have long text)
 925       *
 926       * @return string
 927       */
 928      private function fp_js_template_processexistingfile() {
 929          $rv = '
 930  <div class="file-picker fp-dlg">
 931      <p class="fp-dlg-text"></p>
 932      <div class="fp-dlg-buttons">
 933          <button class="fp-dlg-butoverwrite btn">'.get_string('overwrite', 'repository').'</button>
 934          <button class="fp-dlg-butrename btn"></button>
 935          <button class="fp-dlg-butcancel btn btn-cancel">'.get_string('cancel').'</button>
 936      </div>
 937  </div>';
 938          return $rv;
 939      }
 940  
 941      /**
 942       * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists (multiple-file version).
 943       *
 944       * Must have one top element, CSS for this element must define width and height of the window;
 945       *
 946       * content of element with class 'fp-dlg-text' will be replaced with dialog text;
 947       * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename' and 'fp-dlg-butcancel' will
 948       * hold onclick events;
 949       *
 950       * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
 951       * (Note that it may have long text)
 952       *
 953       * @return string
 954       */
 955      private function fp_js_template_processexistingfilemultiple() {
 956          $rv = '
 957  <div class="file-picker fp-dlg">
 958      <p class="fp-dlg-text"></p>
 959      <a class="fp-dlg-butoverwrite fp-panel-button" href="#">'.get_string('overwrite', 'repository').'</a>
 960      <a class="fp-dlg-butcancel fp-panel-button" href="#">'.get_string('cancel').'</a>
 961      <a class="fp-dlg-butrename fp-panel-button" href="#"></a>
 962      <br/>
 963      <a class="fp-dlg-butoverwriteall fp-panel-button" href="#">'.get_string('overwriteall', 'repository').'</a>
 964      <a class="fp-dlg-butrenameall fp-panel-button" href="#">'.get_string('renameall', 'repository').'</a>
 965  </div>';
 966          return $rv;
 967      }
 968  
 969      /**
 970       * FilePicker JS template for repository login form including templates for each element type
 971       *
 972       * Must contain one <form> element with templates for different input types inside:
 973       * Elements with classes 'fp-login-popup', 'fp-login-textarea', 'fp-login-select' and
 974       * 'fp-login-input' are templates for displaying respective login form elements. Inside
 975       * there must be exactly one element with type <button>, <textarea>, <select> or <input>
 976       * (i.e. fp-login-popup should have <button>, fp-login-textarea should have <textarea>, etc.);
 977       * They may also contain the <label> element and it's content will be substituted with
 978       * label;
 979       *
 980       * You can also define elements with classes 'fp-login-checkbox', 'fp-login-text'
 981       * but if they are not found, 'fp-login-input' will be used;
 982       *
 983       * Element with class 'fp-login-radiogroup' will be used for group of radio inputs. Inside
 984       * it should hava a template for one radio input (with class 'fp-login-radio');
 985       *
 986       * Element with class 'fp-login-submit' will hold on click mouse event (form submission). It
 987       * will be removed if at least one popup element is present;
 988       *
 989       * @return string
 990       */
 991      private function fp_js_template_loginform() {
 992          $rv = '
 993  <div class="fp-login-form">
 994      <div class="fp-content-center">
 995          <form class="form-horizontal">
 996              <div class="fp-formset">
 997                  <div class="fp-login-popup control-group clearfix">
 998                      <div class="controls fp-popup">
 999                          <button class="fp-login-popup-but btn-primary btn">'.get_string('login', 'repository').'</button>
1000                      </div>
1001                  </div>
1002                  <div class="fp-login-textarea control-group clearfix">
1003                      <div class="controls"><textarea></textarea></div>
1004                  </div>
1005                  <div class="fp-login-select control-group clearfix">
1006                      <label class="control-label"></label>
1007  
1008                      <div class="controls"><select></select></div>
1009                  </div>
1010                  <div class="fp-login-input control-group clearfix">
1011                      <label class="control-label"></label>
1012                      <div class="controls"><input/></div>
1013                  </div>
1014                  <div class="fp-login-radiogroup control-group clearfix">
1015                      <label class="control-label"></label>
1016                      <div class="controls fp-login-radio"><input /> <label></label></div>
1017                  </div>
1018              </div>
1019              <p><button class="fp-login-submit btn-primary btn">'.get_string('submit', 'repository').'</button></p>
1020          </form>
1021      </div>
1022  </div>';
1023          return $rv;
1024      }
1025  
1026      /**
1027       * Returns all FilePicker JavaScript templates as an array.
1028       *
1029       * @return array
1030       */
1031      public function filepicker_js_templates() {
1032          $class_methods = get_class_methods($this);
1033          $templates = array();
1034          foreach ($class_methods as $method_name) {
1035              if (preg_match('/^fp_js_template_(.*)$/', $method_name, $matches))
1036              $templates[$matches[1]] = $this->$method_name();
1037          }
1038          return $templates;
1039      }
1040  
1041      /**
1042       * Returns HTML for default repository searchform to be passed to Filepicker
1043       *
1044       * This will be used as contents for search form defined in generallayout template
1045       * (form with id {TOOLSEARCHID}).
1046       * Default contents is one text input field with name="s"
1047       */
1048      public function repository_default_searchform() {
1049          $searchinput = html_writer::label(get_string('searchrepo', 'repository'),
1050              'reposearch', false, array('class' => 'accesshide'));
1051          $searchinput .= html_writer::empty_tag('input', array('type' => 'text',
1052              'id' => 'reposearch', 'name' => 's', 'value' => get_string('search', 'repository')));
1053          $str = html_writer::tag('div', $searchinput, array('class' => "fp-def-search"));
1054  
1055          return $str;
1056      }
1057  }
1058  
1059  /**
1060   * Data structure representing a general moodle file tree viewer
1061   *
1062   * @copyright 2010 Dongsheng Cai
1063   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1064   * @since     Moodle 2.0
1065   */
1066  class files_tree_viewer implements renderable {
1067      public $tree;
1068      public $path;
1069      public $context;
1070  
1071      /**
1072       * Constructor of moodle_file_tree_viewer class
1073       * @param file_info $file_info
1074       * @param array $options
1075       */
1076      public function __construct(file_info $file_info, array $options = null) {
1077          global $CFG;
1078  
1079          //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
1080          $this->options = (array)$options;
1081          $this->context = $options['context'];
1082  
1083          $this->tree = array();
1084          $children = $file_info->get_children();
1085          $current_file_params = $file_info->get_params();
1086          $parent_info = $file_info->get_parent();
1087          $level = $parent_info;
1088          $this->path = array();
1089          while ($level) {
1090              $params = $level->get_params();
1091              $context = context::instance_by_id($params['contextid']);
1092              // $this->context is current context
1093              if ($context->id != $this->context->id or empty($params['filearea'])) {
1094                  break;
1095              }
1096              // unset unused parameters
1097              unset($params['component']);
1098              unset($params['filearea']);
1099              unset($params['filename']);
1100              unset($params['itemid']);
1101              $url = new moodle_url('/files/index.php', $params);
1102              $this->path[] = html_writer::link($url, $level->get_visible_name());
1103              $level = $level->get_parent();
1104          }
1105          $this->path = array_reverse($this->path);
1106          if ($current_file_params['filepath'] != '/') {
1107              $this->path[] = $file_info->get_visible_name();
1108          }
1109  
1110          foreach ($children as $child) {
1111              $filedate = $child->get_timemodified();
1112              $filesize = $child->get_filesize();
1113              $mimetype = $child->get_mimetype();
1114              $params = $child->get_params();
1115              unset($params['component']);
1116              unset($params['filearea']);
1117              unset($params['filename']);
1118              unset($params['itemid']);
1119              $fileitem = array(
1120                      'params'   => $params,
1121                      'filename' => $child->get_visible_name(),
1122                      'mimetype' => $child->get_mimetype(),
1123                      'filedate' => $filedate ? $filedate : '',
1124                      'filesize' => $filesize ? $filesize : ''
1125                      );
1126              $url = new moodle_url('/files/index.php', $params);
1127              if ($child->is_directory()) {
1128                  $fileitem['isdir'] = true;
1129                  $fileitem['url'] = $url->out(false);
1130              } else {
1131                  $fileitem['url'] = $child->get_url();
1132              }
1133              $this->tree[] = $fileitem;
1134          }
1135      }
1136  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1