Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.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   * Moodle Component Library
  19   *
  20   * @package    tool_componentlibrary
  21   * @copyright  2021 Bas Brands <bas@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  define('CLI_SCRIPT', 1);
  27  
  28  require_once(__DIR__ . '/../../../../config.php');
  29  require_once($CFG->libdir.'/clilib.php');
  30  require_once($CFG->dirroot . '/lib/filelib.php');
  31  
  32  list($options, $unrecognized) = cli_get_params(array(
  33      'help' => false,
  34      ), array('h' => 'help'));
  35  
  36  if ($options['help']) {
  37      $help = <<<EOL
  38  Generate a json file with all core icons for the component library.
  39  
  40  Options:
  41  -h, --help                  Print out this help.
  42  
  43  Example:
  44  \$sudo -u www-data /usr/bin/php admin/tool/componentlibrary/cli/fetchicons.php\n
  45  EOL;
  46      echo $help;
  47      die;
  48  }
  49  
  50  $admin = get_admin();
  51  if (!$admin) {
  52      mtrace("Error: No admin account was found");
  53      die;
  54  }
  55  
  56  $CFG->themedesignermode = true;
  57  
  58  $output = $PAGE->get_renderer('core');
  59  $isfontawesome = \core\output\icon_system::instance(\core\output\icon_system::FONTAWESOME);
  60  $isstandard = \core\output\icon_system::instance(\core\output\icon_system::STANDARD);
  61  $map = $isfontawesome->get_icon_name_map();
  62  $icons = [];
  63  foreach ($map as $name => $icon) {
  64      $parts = explode(':', $name);
  65      if ($parts[0] === 'theme') {
  66          continue;
  67      }
  68      $imageicon = new image_icon($parts[1], $name, $parts[0], []);
  69      $i = new \stdClass();
  70      $i->name = $name;
  71      $i->icon = $icon;
  72      if ($imageicon) {
  73          $i->standardicon = str_replace($CFG->wwwroot, 'MOODLESITE', $isstandard->render_pix_icon($output, $imageicon));
  74      }
  75      $icons[] = $i;
  76  }
  77  $jsonfile = $CFG->dirroot . '/admin/tool/componentlibrary/hugo/site/data/fontawesomeicons.json';
  78  if (($fh = @fopen($jsonfile, 'w')) !== false) {
  79      fwrite($fh, json_encode($icons));
  80      fclose($fh);
  81      exit(0);
  82  } else {
  83      echo 'Could not write to ' . $jsonfile;
  84      exit(1);
  85  }