[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file contains all necessary code to define a wiki file table form element 19 * 20 * @package mod_wiki 21 * @copyright 2009 Marc Alier, Jordi Piguillem [email protected] 22 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu 23 * 24 * @author Josep Arus 25 * 26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 27 */ 28 29 require_once('HTML/QuickForm/element.php'); 30 require_once($CFG->dirroot.'/lib/filelib.php'); 31 32 class MoodleQuickForm_wikifiletable extends HTML_QuickForm_element { 33 34 private $_contextid; 35 private $_filearea; 36 private $_fileareaitemid; 37 private $_fileinfo; 38 private $_value = array(); 39 40 function MoodleQuickForm_wikifiletable($elementName = null, $elementLabel = null, $attributes = null, $fileinfo = null, $format = null) { 41 42 parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes); 43 $this->_fileinfo = $fileinfo; 44 $this->_format = $format; 45 } 46 47 function onQuickFormEvent($event, $arg, &$caller) { 48 global $OUTPUT; 49 50 switch ($event) { 51 case 'addElement': 52 $this->_contextid = $arg[3]['contextid']; 53 $this->_filearea = $arg[3]['filearea']; 54 $this->_fileareaitemid = $arg[3]['itemid']; 55 $this->_format = $arg[4]; 56 break; 57 } 58 59 return parent::onQuickFormEvent($event, $arg, $caller); 60 } 61 62 function setName($name) { 63 $this->updateAttributes(array('name' => $name)); 64 } 65 66 function getName() { 67 return $this->getAttribute('name'); 68 } 69 70 function setValue($value) { 71 $this->_value = $value; 72 } 73 74 function getValue() { 75 return $this->_value; 76 } 77 78 function toHtml() { 79 global $CFG, $OUTPUT; 80 81 $htmltable = new html_table(); 82 83 $htmltable->head = array(get_string('deleteupload', 'wiki'), get_string('uploadname', 'wiki'), get_string('uploadactions', 'wiki')); 84 85 $fs = get_file_storage(); 86 87 $files = $fs->get_area_files($this->_fileinfo['contextid'], 'mod_wiki', 'attachments', $this->_fileinfo['itemid']); //TODO: verify where this is coming from, all params must be validated (skodak) 88 89 if (count($files) < 2) { 90 return get_string('noattachments', 'wiki'); 91 } 92 93 //get tags 94 foreach (array('image', 'attach', 'link') as $tag) { 95 $tags[$tag] = wiki_parser_get_token($this->_format, $tag); 96 } 97 98 foreach ($files as $file) { 99 if (!$file->is_directory()) { 100 $checkbox = '<input type="checkbox" name="'.$this->_attributes['name'].'[]" value="'.$file->get_pathnamehash().'"'; 101 102 if (in_array($file->get_pathnamehash(), $this->_value)) { 103 $checkbox .= ' checked="checked"'; 104 } 105 $checkbox .= " />"; 106 107 //actions 108 $icon = file_file_icon($file); 109 $file_url = file_encode_url($CFG->wwwroot.'/pluginfile.php', "/{$this->_contextid}/mod_wiki/attachments/{$this->_fileareaitemid}/".$file->get_filename()); 110 111 $action_icons = ""; 112 if(!empty($tags['attach'])) { 113 $action_icons .= "<a href=\"javascript:void(0)\" class=\"wiki-attachment-attach\" ".$this->printInsertTags($tags['attach'], $file->get_filename())." title=\"".get_string('attachmentattach', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Attach")."</a>"; //TODO: localize 114 } 115 116 $action_icons .= " <a href=\"javascript:void(0)\" class=\"wiki-attachment-link\" ".$this->printInsertTags($tags['link'], $file_url)." title=\"".get_string('attachmentlink', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Link")."</a>"; 117 118 if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) { 119 $action_icons .= " <a href=\"javascript:void(0)\" class=\"wiki-attachment-image\" ".$this->printInsertTags($tags['image'], $file->get_filename())." title=\"".get_string('attachmentimage', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Image")."</a>"; //TODO: localize 120 } 121 122 $htmltable->data[] = array($checkbox, '<a href="'.$file_url.'">'.$file->get_filename().'</a>', $action_icons); 123 } 124 } 125 126 return html_writer::table($htmltable); 127 } 128 129 private function printInsertTags($tags, $value) { 130 return "onclick=\"javascript:insertTags('{$tags[0]}', '{$tags[1]}', '$value');\""; 131 } 132 } 133 134 //register wikieditor 135 MoodleQuickForm::registerElementType('wikifiletable', $CFG->dirroot."/mod/wiki/editors/wikifiletable.php", 'MoodleQuickForm_wikifiletable'); 136 137
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |