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   * Tiny equation plugin.
  19   *
  20   * @package    tiny_equation
  21   * @copyright  2022 Huong Nguyen <huongnv13@gmail.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tiny_equation;
  26  
  27  use context;
  28  use context_system;
  29  use editor_tiny\editor;
  30  use editor_tiny\plugin;
  31  use editor_tiny\plugin_with_buttons;
  32  use editor_tiny\plugin_with_configuration;
  33  use editor_tiny\plugin_with_menuitems;
  34  use filter_manager;
  35  
  36  /**
  37   * Tiny equation plugin.
  38   *
  39   * @package    tiny_equation
  40   * @copyright  2022 Huong Nguyen <huongnv13@gmail.com>
  41   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class plugininfo extends plugin implements plugin_with_buttons, plugin_with_menuitems, plugin_with_configuration {
  44  
  45      public static function get_available_buttons(): array {
  46          return [
  47              'tiny_equation/equation',
  48          ];
  49      }
  50  
  51      public static function get_available_menuitems(): array {
  52          return [
  53              'tiny_equation/equation',
  54          ];
  55      }
  56  
  57      public static function get_plugin_configuration_for_context(context $context, array $options, array $fpoptions,
  58          ?editor $editor = null): array {
  59          $texexample = '$$\pi$$';
  60          // Format a string with the active filter set.
  61          // If it is modified - we assume that some sort of text filter is working in this context.
  62          $result = format_text($texexample, true, $options);
  63          $texfilteractive = ($texexample !== $result);
  64  
  65          if (isset($options['context'])) {
  66              $context = $options['context'];
  67          } else {
  68              $context = context_system::instance();
  69          }
  70  
  71          $libraries = [
  72              [
  73                  'key' => 'group1',
  74                  'groupname' => get_string('librarygroup1', 'tiny_equation'),
  75                  'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup1'))),
  76                  'active' => true,
  77              ],
  78              [
  79                  'key' => 'group2',
  80                  'groupname' => get_string('librarygroup2', 'tiny_equation'),
  81                  'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup2'))),
  82              ],
  83              [
  84                  'key' => 'group3',
  85                  'groupname' => get_string('librarygroup3', 'tiny_equation'),
  86                  'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup3'))),
  87              ],
  88              [
  89                  'key' => 'group4',
  90                  'groupname' => get_string('librarygroup4', 'tiny_equation'),
  91                  'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup4'))),
  92              ]
  93          ];
  94  
  95          return [
  96              'texfilter' => $texfilteractive,
  97              'contextid' => $context->id,
  98              'libraries' => $libraries,
  99              'texdocsurl' => get_docs_url('Using_TeX_Notation'),
 100          ];
 101      }
 102  }