Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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   * TinyMCE admin setting stuff.
  19   *
  20   * @package   editor_tinymce
  21   * @copyright 2012 Petr Skoda {@link http://skodak.org}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  
  28  /**
  29   * Special class for TinyMCE subplugin administration.
  30   *
  31   * @package   editor_tinymce
  32   * @copyright 2012 Petr Skoda {@link http://skodak.org}
  33   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class tiynce_subplugins_settings extends admin_setting {
  36      public function __construct() {
  37          $this->nosave = true;
  38          parent::__construct('tinymcesubplugins', get_string('subplugintype_tinymce_plural', 'editor_tinymce'), '', '');
  39      }
  40  
  41      /**
  42       * Always returns true, does nothing.
  43       *
  44       * @return true
  45       */
  46      public function get_setting() {
  47          return true;
  48      }
  49  
  50      /**
  51       * Always returns true, does nothing.
  52       *
  53       * @return true
  54       */
  55      public function get_defaultsetting() {
  56          return true;
  57      }
  58  
  59      /**
  60       * Always returns '', does not write anything.
  61       *
  62       * @param string $data
  63       * @return string Always returns ''
  64       */
  65      public function write_setting($data) {
  66          // Do not write any setting.
  67          return '';
  68      }
  69  
  70      /**
  71       * Checks if $query is one of the available subplugins.
  72       *
  73       * @param string $query The string to search for
  74       * @return bool Returns true if found, false if not
  75       */
  76      public function is_related($query) {
  77          if (parent::is_related($query)) {
  78              return true;
  79          }
  80  
  81          $subplugins = core_component::get_plugin_list('tinymce');
  82          foreach ($subplugins as $name=>$dir) {
  83              if (stripos($name, $query) !== false) {
  84                  return true;
  85              }
  86  
  87              $namestr = get_string('pluginname', 'tinymce_'.$name);
  88              if (strpos(core_text::strtolower($namestr), core_text::strtolower($query)) !== false) {
  89                  return true;
  90              }
  91          }
  92          return false;
  93      }
  94  
  95      /**
  96       * Builds the XHTML to display the control.
  97       *
  98       * @param string $data Unused
  99       * @param string $query
 100       * @return string
 101       */
 102      public function output_html($data, $query='') {
 103          global $CFG, $OUTPUT, $PAGE;
 104          require_once("$CFG->libdir/editorlib.php");
 105          require_once (__DIR__.'/lib.php');
 106          $tinymce = new tinymce_texteditor();
 107          $pluginmanager = core_plugin_manager::instance();
 108  
 109          // display strings
 110          $strbuttons = get_string('availablebuttons', 'editor_tinymce');
 111          $strdisable = get_string('disable');
 112          $strenable = get_string('enable');
 113          $strname = get_string('name');
 114          $strsettings = get_string('settings');
 115          $struninstall = get_string('uninstallplugin', 'core_admin');
 116          $strversion = get_string('version');
 117  
 118          $subplugins = core_component::get_plugin_list('tinymce');
 119  
 120          $return = $OUTPUT->heading(get_string('subplugintype_tinymce_plural', 'editor_tinymce'), 3, 'main', true);
 121          $return .= $OUTPUT->box_start('generalbox tinymcesubplugins');
 122  
 123          $table = new html_table();
 124          $table->head  = array($strname, $strbuttons, $strversion, $strenable, $strsettings, $struninstall);
 125          $table->align = array('left', 'left', 'center', 'center', 'center', 'center');
 126          $table->data  = array();
 127          $table->attributes['class'] = 'admintable generaltable';
 128  
 129          // Iterate through subplugins.
 130          foreach ($subplugins as $name => $dir) {
 131              $namestr = get_string('pluginname', 'tinymce_'.$name);
 132              $version = get_config('tinymce_'.$name, 'version');
 133              if ($version === false) {
 134                  $version = '';
 135              }
 136              $plugin = $tinymce->get_plugin($name);
 137              $plugininfo = $pluginmanager->get_plugin_info('tinymce_'.$name);
 138  
 139              // Add hide/show link.
 140              $class = '';
 141              if (!$version) {
 142                  $hideshow = '';
 143                  $displayname = html_writer::tag('span', $name, array('class'=>'error'));
 144              } else if ($plugininfo->is_enabled()) {
 145                  $url = new moodle_url('/lib/editor/tinymce/subplugins.php', array('sesskey'=>sesskey(), 'return'=>'settings', 'disable'=>$name));
 146                  $hideshow = $OUTPUT->pix_icon('t/hide', $strdisable);
 147                  $hideshow = html_writer::link($url, $hideshow);
 148                  $displayname = $namestr;
 149              } else {
 150                  $url = new moodle_url('/lib/editor/tinymce/subplugins.php', array('sesskey'=>sesskey(), 'return'=>'settings', 'enable'=>$name));
 151                  $hideshow = $OUTPUT->pix_icon('t/show', $strenable);
 152                  $hideshow = html_writer::link($url, $hideshow);
 153                  $displayname = $namestr;
 154                  $class = 'dimmed_text';
 155              }
 156  
 157              if ($PAGE->theme->resolve_image_location('icon', 'tinymce_' . $name, false)) {
 158                  $icon = $OUTPUT->pix_icon('icon', '', 'tinymce_' . $name, array('class' => 'icon pluginicon'));
 159              } else {
 160                  $icon = $OUTPUT->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
 161              }
 162              $displayname  = $icon . ' ' . $displayname;
 163  
 164              // Add available buttons.
 165              $buttons = implode(', ', $plugin->get_buttons());
 166              $buttons = html_writer::tag('span', $buttons, array('class'=>'tinymcebuttons'));
 167  
 168              // Add settings link.
 169              if (!$version) {
 170                  $settings = '';
 171              } else if ($url = $plugininfo->get_settings_url()) {
 172                  $settings = html_writer::link($url, $strsettings);
 173              } else {
 174                  $settings = '';
 175              }
 176  
 177              // Add uninstall info.
 178              $uninstall = '';
 179              if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('tinymce_' . $name, 'manage')) {
 180                  $uninstall = html_writer::link($uninstallurl, $struninstall);
 181              }
 182  
 183              // Add a row to the table.
 184              $row = new html_table_row(array($displayname, $buttons, $version, $hideshow, $settings, $uninstall));
 185              if ($class) {
 186                  $row->attributes['class'] = $class;
 187              }
 188              $table->data[] = $row;
 189          }
 190          $return .= html_writer::table($table);
 191          $return .= html_writer::tag('p', get_string('tablenosave', 'admin'));
 192          $return .= $OUTPUT->box_end();
 193          return highlight($query, $return);
 194      }
 195  }
 196  
 197  class editor_tinymce_json_setting_textarea extends admin_setting_configtextarea {
 198      /**
 199       * Returns an XHTML string for the editor
 200       *
 201       * @param string $data
 202       * @param string $query
 203       * @return string XHTML string for the editor
 204       */
 205      public function output_html($data, $query='') {
 206          $result = parent::output_html($data, $query);
 207  
 208          $data = trim($data);
 209          if ($data) {
 210              $decoded = json_decode($data, true);
 211              // Note: it is not very nice to abuse these file classes, but anyway...
 212              if (is_array($decoded)) {
 213                  $valid = '<span class="pathok">&#x2714;</span>';
 214              } else {
 215                  $valid = '<span class="patherror">&#x2718;</span>';
 216              }
 217              $result = str_replace('</textarea>', '</textarea>'.$valid, $result);
 218          }
 219  
 220          return $result;
 221      }
 222  }