[ Index ] |
PHP Cross Reference of Unnamed Project |
[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 marc.alier@upc.edu 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 /** 37 * Constructor 38 * 39 * @param string $elementName (optional) name of the text field 40 * @param string $elementLabel (optional) text field label 41 * @param string $attributes (optional) Either a typical HTML attribute string or an associative array 42 */ 43 function __construct($elementName = null, $elementLabel = null, $attributes = null) { 44 if (isset($attributes['wiki_format'])) { 45 $this->wikiformat = $attributes['wiki_format']; 46 unset($attributes['wiki_format']); 47 } 48 if (isset($attributes['files'])) { 49 $this->files = $attributes['files']; 50 unset($attributes['files']); 51 } 52 53 parent::__construct($elementName, $elementLabel, $attributes); 54 } 55 56 /** 57 * Old syntax of class constructor. Deprecated in PHP7. 58 * 59 * @deprecated since Moodle 3.1 60 */ 61 public function MoodleQuickForm_wikieditor($elementName = null, $elementLabel = null, $attributes = null) { 62 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER); 63 self::__construct($elementName, $elementLabel, $attributes); 64 } 65 66 function setWikiFormat($wikiformat) { 67 $this->wikiformat = $wikiformat; 68 } 69 70 function toHtml() { 71 $textarea = parent::toHtml(); 72 73 return $this->{ 74 $this->wikiformat."Editor"} 75 ($textarea); 76 } 77 78 function creoleEditor($textarea) { 79 return $this->printWikiEditor($textarea); 80 } 81 82 function nwikiEditor($textarea) { 83 return $this->printWikiEditor($textarea); 84 } 85 86 private function printWikiEditor($textarea) { 87 global $OUTPUT; 88 89 $textarea = $OUTPUT->container_start().$textarea.$OUTPUT->container_end(); 90 91 $buttons = $this->getButtons(); 92 93 return $buttons.$textarea; 94 } 95 96 private function getButtons() { 97 global $PAGE, $OUTPUT, $CFG; 98 99 $editor = $this->wikiformat; 100 101 $tag = $this->getTokens($editor, 'bold'); 102 $wiki_editor['bold'] = array('ed_bold.gif', get_string('wikiboldtext', 'wiki'), $tag[0], $tag[1], get_string('wikiboldtext', 'wiki')); 103 104 $tag = $this->getTokens($editor, 'italic'); 105 $wiki_editor['italic'] = array('ed_italic.gif', get_string('wikiitalictext', 'wiki'), $tag[0], $tag[1], get_string('wikiitalictext', 'wiki')); 106 107 $imagetag = $this->getTokens($editor, 'image'); 108 $wiki_editor['image'] = array('ed_img.gif', get_string('wikiimage', 'wiki'), $imagetag[0], $imagetag[1], get_string('wikiimage', 'wiki')); 109 110 $tag = $this->getTokens($editor, 'link'); 111 $wiki_editor['internal'] = array('ed_internal.gif', get_string('wikiinternalurl', 'wiki'), $tag[0], $tag[1], get_string('wikiinternalurl', 'wiki')); 112 113 $tag = $this->getTokens($editor, 'url'); 114 $wiki_editor['external'] = array('ed_external.gif', get_string('wikiexternalurl', 'wiki'), $tag, "", get_string('wikiexternalurl', 'wiki')); 115 116 $tag = $this->getTokens($editor, 'list'); 117 $wiki_editor['u_list'] = array('ed_ul.gif', get_string('wikiunorderedlist', 'wiki'), '\\n'.$tag[0], '', ''); 118 $wiki_editor['o_list'] = array('ed_ol.gif', get_string('wikiorderedlist', 'wiki'), '\\n'.$tag[1], '', ''); 119 120 $tag = $this->getTokens($editor, 'header'); 121 $wiki_editor['h1'] = array('ed_h1.gif', get_string('wikiheader', 'wiki', 1), '\\n'.$tag.' ', ' '.$tag.'\\n', get_string('wikiheader', 'wiki', 1)); 122 $wiki_editor['h2'] = array('ed_h2.gif', get_string('wikiheader', 'wiki', 2), '\\n'.$tag.$tag.' ', ' '.$tag.$tag.'\\n', get_string('wikiheader', 'wiki', 2)); 123 $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)); 124 125 $tag = $this->getTokens($editor, 'line_break'); 126 $wiki_editor['hr'] = array('ed_hr.gif', get_string('wikihr', 'wiki'), '\\n'.$tag.'\\n', '', ''); 127 128 $tag = $this->getTokens($editor, 'nowiki'); 129 $wiki_editor['nowiki'] = array('ed_nowiki.gif', get_string('wikinowikitext', 'wiki'), $tag[0], $tag[1], get_string('wikinowikitext', 'wiki')); 130 131 $PAGE->requires->js('/mod/wiki/editors/wiki/buttons.js'); 132 133 $html = '<div class="wikieditor-toolbar">'; 134 foreach ($wiki_editor as $button) { 135 $html .= "<a href=\"javascript:insertTags"; 136 $html .= "('".$button[2]."','".$button[3]."','".$button[4]."');\">"; 137 $html .= html_writer::empty_tag('img', array('alt' => $button[1], 'src' => $CFG->wwwroot . '/mod/wiki/editors/wiki/images/' . $button[0])); 138 $html .= "</a>"; 139 } 140 $html .= "<label class='accesshide' for='addtags'>" . get_string('insertimage', 'wiki') . "</label>"; 141 $html .= "<select id='addtags' onchange=\"insertTags('{$imagetag[0]}', '{$imagetag[1]}', this.value)\">"; 142 $html .= "<option value='" . s(get_string('wikiimage', 'wiki')) . "'>" . get_string('insertimage', 'wiki') . '</option>'; 143 foreach ($this->files as $filename) { 144 $html .= "<option value='".s($filename)."'>"; 145 $html .= $filename; 146 $html .= '</option>'; 147 } 148 $html .= '</select>'; 149 $html .= $OUTPUT->help_icon('insertimage', 'wiki'); 150 $html .= '</div>'; 151 152 return $html; 153 } 154 155 private function getTokens($format, $token) { 156 $tokens = wiki_parser_get_token($format, $token); 157 158 if (is_array($tokens)) { 159 foreach ($tokens as & $t) { 160 $this->escapeToken($t); 161 } 162 } else { 163 $this->escapeToken($tokens); 164 } 165 166 return $tokens; 167 } 168 169 private function escapeToken(&$token) { 170 $token = urlencode(str_replace("'", "\'", $token)); 171 } 172 } 173 174 //register wikieditor 175 MoodleQuickForm::registerElementType('wikieditor', $CFG->dirroot."/mod/wiki/editors/wikieditor.php", 'MoodleQuickForm_wikieditor');
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |