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 * Atto admin setting stuff. 19 * 20 * @package editor_atto 21 * @copyright 2014 Jerome Mouneyrac 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 /** 28 * Admin setting for toolbar. 29 * 30 * @package editor_atto 31 * @copyright 2014 Frédéric Massart 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class editor_atto_toolbar_setting extends admin_setting_configtextarea { 35 36 /** 37 * Validate data. 38 * 39 * This ensures that: 40 * - Plugins are only used once, 41 * - Group names are unique, 42 * - Lines match: group = plugin[, plugin[, plugin ...]], 43 * - There are some groups and plugins defined, 44 * - The plugins used are installed. 45 * 46 * @param string $data 47 * @return mixed True on success, else error message. 48 */ 49 public function validate($data) { 50 $result = parent::validate($data); 51 if ($result !== true) { 52 return $result; 53 } 54 55 $lines = explode("\n", $data); 56 $groups = array(); 57 $plugins = array(); 58 59 foreach ($lines as $line) { 60 if (!trim($line)) { 61 continue; 62 } 63 64 $matches = array(); 65 if (!preg_match('/^\s*([a-z0-9]+)\s*=\s*([a-z0-9]+(\s*,\s*[a-z0-9]+)*)+\s*$/', $line, $matches)) { 66 $result = get_string('errorcannotparseline', 'editor_atto', $line); 67 break; 68 } 69 70 $group = $matches[1]; 71 if (isset($groups[$group])) { 72 $result = get_string('errorgroupisusedtwice', 'editor_atto', $group); 73 break; 74 } 75 $groups[$group] = true; 76 77 $lineplugins = array_map('trim', explode(',', $matches[2])); 78 foreach ($lineplugins as $plugin) { 79 if (isset($plugins[$plugin])) { 80 $result = get_string('errorpluginisusedtwice', 'editor_atto', $plugin); 81 break 2; 82 } else if (!core_component::get_component_directory('atto_' . $plugin)) { 83 $result = get_string('errorpluginnotfound', 'editor_atto', $plugin); 84 break 2; 85 } 86 $plugins[$plugin] = true; 87 } 88 } 89 90 // We did not find any groups or plugins. 91 if (empty($groups) || empty($plugins)) { 92 $result = get_string('errornopluginsorgroupsfound', 'editor_atto'); 93 } 94 95 return $result; 96 } 97 98 } 99 100 /** 101 * Special class for Atto plugins administration. 102 * 103 * @package editor_atto 104 * @copyright 2014 Jerome Mouneyrac 105 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 106 */ 107 class editor_atto_subplugins_setting extends admin_setting { 108 109 /** 110 * Constructor. 111 */ 112 public function __construct() { 113 $this->nosave = true; 114 parent::__construct('attosubplugins', get_string('subplugintype_atto_plural', 'editor_atto'), '', ''); 115 } 116 117 /** 118 * Returns current value of this setting. 119 * Always returns true, does nothing. 120 * 121 * @return true 122 */ 123 public function get_setting() { 124 return true; 125 } 126 127 /** 128 * Returns default setting if exists. 129 * Always returns true, does nothing. 130 * 131 * @return true 132 */ 133 public function get_defaultsetting() { 134 return true; 135 } 136 137 /** 138 * Store new setting. 139 * Always returns '', does not write anything. 140 * 141 * @param string $data string or array, must not be NULL. 142 * @return string Always returns ''. 143 */ 144 public function write_setting($data) { 145 // Do not write any setting. 146 return ''; 147 } 148 149 /** 150 * Checks if $query is one of the available subplugins. 151 * 152 * @param string $query The string to search for. 153 * @return bool Returns true if found, false if not. 154 */ 155 public function is_related($query) { 156 if (parent::is_related($query)) { 157 return true; 158 } 159 160 $subplugins = core_component::get_plugin_list('atto'); 161 foreach ($subplugins as $name => $dir) { 162 if (stripos($name, $query) !== false) { 163 return true; 164 } 165 166 $namestr = get_string('pluginname', 'atto_' . $name); 167 if (strpos(core_text::strtolower($namestr), core_text::strtolower($query)) !== false) { 168 return true; 169 } 170 } 171 return false; 172 } 173 174 /** 175 * Builds the XHTML to display the control. 176 * 177 * @param mixed $data Unused. 178 * @param string $query 179 * @return string highlight. 180 */ 181 public function output_html($data, $query = '') { 182 global $CFG, $OUTPUT, $PAGE; 183 require_once($CFG->libdir . "/editorlib.php"); 184 require_once (__DIR__ . '/lib.php'); 185 $pluginmanager = core_plugin_manager::instance(); 186 187 // Display strings. 188 $strtoolbarconfig = get_string('toolbarconfig', 'editor_atto'); 189 $strname = get_string('name'); 190 $strsettings = get_string('settings'); 191 $struninstall = get_string('uninstallplugin', 'core_admin'); 192 $strversion = get_string('version'); 193 194 $subplugins = core_component::get_plugin_list('atto'); 195 196 $return = $OUTPUT->heading(get_string('subplugintype_atto_plural', 'editor_atto'), 3, 'main', true); 197 $return .= $OUTPUT->box_start('generalbox attosubplugins'); 198 199 $table = new html_table(); 200 $table->head = array($strname, $strversion, $strtoolbarconfig, $strsettings, $struninstall); 201 $table->align = array('left', 'left', 'center', 'center', 'center', 'center'); 202 $table->data = array(); 203 $table->attributes['class'] = 'admintable generaltable'; 204 205 // Iterate through subplugins. 206 foreach ($subplugins as $name => $dir) { 207 $namestr = get_string('pluginname', 'atto_' . $name); 208 $version = get_config('atto_' . $name, 'version'); 209 if ($version === false) { 210 $version = ''; 211 } 212 $plugininfo = $pluginmanager->get_plugin_info('atto_' . $name); 213 214 $toolbarconfig = $name; 215 216 $displayname = $namestr; 217 218 // Check if there is an icon in the atto plugin pix/ folder. 219 if ($PAGE->theme->resolve_image_location('icon', 'atto_' . $name, false)) { 220 $icon = $OUTPUT->pix_icon('icon', '', 'atto_' . $name, array('class' => 'icon pluginicon')); 221 } else { 222 // No icon found. 223 $icon = $OUTPUT->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon')); 224 } 225 $displayname = $icon . $displayname; 226 227 // Add settings link. 228 if (!$version) { 229 $settings = ''; 230 } else if ($url = $plugininfo->get_settings_url()) { 231 $settings = html_writer::link($url, $strsettings); 232 } else { 233 $settings = ''; 234 } 235 236 // Add uninstall info. 237 $uninstall = ''; 238 if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('atto_' . $name, 'manage')) { 239 $uninstall = html_writer::link($uninstallurl, $struninstall); 240 } 241 242 // Add a row to the table. 243 $row = new html_table_row(array($displayname, $version, $toolbarconfig, $settings, $uninstall)); 244 $table->data[] = $row; 245 } 246 $return .= html_writer::table($table); 247 $return .= html_writer::tag('p', get_string('tablenosave', 'admin')); 248 $return .= $OUTPUT->box_end(); 249 return highlight($query, $return); 250 } 251 } 252
title
Description
Body
title
Description
Body
title
Description
Body
title
Body