[ 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 editor 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($CFG->dirroot.'/lib/formslib.php'); 30 require_once($CFG->dirroot.'/lib/form/textarea.php'); 31 32 class MoodleQuickForm_wikieditor extends MoodleQuickForm_textarea { 33 34 private $files; 35 36 function MoodleQuickForm_wikieditor($elementName = null, $elementLabel = null, $attributes = null) { 37 if (isset($attributes['wiki_format'])) { 38 $this->wikiformat = $attributes['wiki_format']; 39 unset($attributes['wiki_format']); 40 } 41 if (isset($attributes['files'])) { 42 $this->files = $attributes['files']; 43 unset($attributes['files']); 44 } 45 46 parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes); 47 } 48 49 function setWikiFormat($wikiformat) { 50 $this->wikiformat = $wikiformat; 51 } 52 53 function toHtml() { 54 $textarea = parent::toHtml(); 55 56 return $this->{ 57 $this->wikiformat."Editor"} 58 ($textarea); 59 } 60 61 function creoleEditor($textarea) { 62 return $this->printWikiEditor($textarea); 63 } 64 65 function nwikiEditor($textarea) { 66 return $this->printWikiEditor($textarea); 67 } 68 69 private function printWikiEditor($textarea) { 70 global $OUTPUT; 71 72 $textarea = $OUTPUT->container_start().$textarea.$OUTPUT->container_end(); 73 74 $buttons = $this->getButtons(); 75 76 return $buttons.$textarea; 77 } 78 79 private function getButtons() { 80 global $PAGE, $OUTPUT, $CFG; 81 82 $editor = $this->wikiformat; 83 84 $tag = $this->getTokens($editor, 'bold'); 85 $wiki_editor['bold'] = array('ed_bold.gif', get_string('wikiboldtext', 'wiki'), $tag[0], $tag[1], get_string('wikiboldtext', 'wiki')); 86 87 $tag = $this->getTokens($editor, 'italic'); 88 $wiki_editor['italic'] = array('ed_italic.gif', get_string('wikiitalictext', 'wiki'), $tag[0], $tag[1], get_string('wikiitalictext', 'wiki')); 89 90 $imagetag = $this->getTokens($editor, 'image'); 91 $wiki_editor['image'] = array('ed_img.gif', get_string('wikiimage', 'wiki'), $imagetag[0], $imagetag[1], get_string('wikiimage', 'wiki')); 92 93 $tag = $this->getTokens($editor, 'link'); 94 $wiki_editor['internal'] = array('ed_internal.gif', get_string('wikiinternalurl', 'wiki'), $tag[0], $tag[1], get_string('wikiinternalurl', 'wiki')); 95 96 $tag = $this->getTokens($editor, 'url'); 97 $wiki_editor['external'] = array('ed_external.gif', get_string('wikiexternalurl', 'wiki'), $tag, "", get_string('wikiexternalurl', 'wiki')); 98 99 $tag = $this->getTokens($editor, 'list'); 100 $wiki_editor['u_list'] = array('ed_ul.gif', get_string('wikiunorderedlist', 'wiki'), '\\n'.$tag[0], '', ''); 101 $wiki_editor['o_list'] = array('ed_ol.gif', get_string('wikiorderedlist', 'wiki'), '\\n'.$tag[1], '', ''); 102 103 $tag = $this->getTokens($editor, 'header'); 104 $wiki_editor['h1'] = array('ed_h1.gif', get_string('wikiheader', 'wiki', 1), '\\n'.$tag.' ', ' '.$tag.'\\n', get_string('wikiheader', 'wiki', 1)); 105 $wiki_editor['h2'] = array('ed_h2.gif', get_string('wikiheader', 'wiki', 2), '\\n'.$tag.$tag.' ', ' '.$tag.$tag.'\\n', get_string('wikiheader', 'wiki', 2)); 106 $wiki_editor['h3'] = array('ed_h3.gif', get_string('wikiheader', 'wiki', 3), '\\n'.$tag.$tag.$tag.' ', ' '.$tag.$tag.$tag.'\\n', get_string('wikiheader', 'wiki', 3)); 107 108 $tag = $this->getTokens($editor, 'line_break'); 109 $wiki_editor['hr'] = array('ed_hr.gif', get_string('wikihr', 'wiki'), '\\n'.$tag.'\\n', '', ''); 110 111 $tag = $this->getTokens($editor, 'nowiki'); 112 $wiki_editor['nowiki'] = array('ed_nowiki.gif', get_string('wikinowikitext', 'wiki'), $tag[0], $tag[1], get_string('wikinowikitext', 'wiki')); 113 114 $PAGE->requires->js('/mod/wiki/editors/wiki/buttons.js'); 115 116 $html = '<div class="wikieditor-toolbar">'; 117 foreach ($wiki_editor as $button) { 118 $html .= "<a href=\"javascript:insertTags"; 119 $html .= "('".$button[2]."','".$button[3]."','".$button[4]."');\">"; 120 $html .= html_writer::empty_tag('img', array('alt' => $button[1], 'src' => $CFG->wwwroot . '/mod/wiki/editors/wiki/images/' . $button[0])); 121 $html .= "</a>"; 122 } 123 $html .= "<label class='accesshide' for='addtags'>" . get_string('insertimage', 'wiki') . "</label>"; 124 $html .= "<select id='addtags' onchange=\"insertTags('{$imagetag[0]}', '{$imagetag[1]}', this.value)\">"; 125 $html .= "<option value='" . s(get_string('wikiimage', 'wiki')) . "'>" . get_string('insertimage', 'wiki') . '</option>'; 126 foreach ($this->files as $filename) { 127 $html .= "<option value='".s($filename)."'>"; 128 $html .= $filename; 129 $html .= '</option>'; 130 } 131 $html .= '</select>'; 132 $html .= $OUTPUT->help_icon('insertimage', 'wiki'); 133 $html .= '</div>'; 134 135 return $html; 136 } 137 138 private function getTokens($format, $token) { 139 $tokens = wiki_parser_get_token($format, $token); 140 141 if (is_array($tokens)) { 142 foreach ($tokens as & $t) { 143 $this->escapeToken($t); 144 } 145 } else { 146 $this->escapeToken($tokens); 147 } 148 149 return $tokens; 150 } 151 152 private function escapeToken(&$token) { 153 $token = urlencode(str_replace("'", "\'", $token)); 154 } 155 } 156 157 //register wikieditor 158 MoodleQuickForm::registerElementType('wikieditor', $CFG->dirroot."/mod/wiki/editors/wikieditor.php", 'MoodleQuickForm_wikieditor');
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 |