Search moodle.org's
Developer Documentation


Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
  •    1  <?php
       2        // This function fetches math. images from the data directory
       3        // If not, it obtains the corresponding TeX expression from the cache_tex db table
       4        // and uses mimeTeX to create the image file
       5  
       6  // disable moodle specific debug messages and any errors in output
       7  define('NO_DEBUG_DISPLAY', true);
       8  define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
       9  
      10      require_once('../../config.php');
      11  
      12      if (!filter_is_enabled('algebra')) {
      13          print_error('filternotenabled');
      14      }
      15  
      16      require_once($CFG->libdir.'/filelib.php');
      17      require_once($CFG->dirroot.'/filter/tex/lib.php');
      18  
      19      $cmd    = '';               // Initialise these variables
      20      $status = '';
      21  
      22      $relativepath = get_file_argument();
      23  
      24      $args = explode('/', trim($relativepath, '/'));
      25  
      26      if (count($args) == 1) {
      27          $image    = $args[0];
      28          $pathname = $CFG->dataroot.'/filter/algebra/'.$image;
      29      } else {
      30          print_error('invalidarguments', 'error');
      31      }
      32  
      33      if (!file_exists($pathname)) {
      34          $md5 = str_replace('.gif','',$image);
      35          if ($texcache = $DB->get_record('cache_filters', array('filter'=>'algebra', 'md5key'=>$md5))) {
      36              if (!file_exists($CFG->dataroot.'/filter/algebra')) {
      37                  make_upload_directory('filter/algebra');
      38              }
      39  
      40              $texexp = $texcache->rawtext;
      41              $texexp = str_replace('&lt;','<',$texexp);
      42              $texexp = str_replace('&gt;','>',$texexp);
      43              $texexp = preg_replace('!\r\n?!',' ',$texexp);
      44              $texexp = '\Large ' . $texexp;
      45              $cmd = filter_tex_get_cmd($pathname, $texexp);
      46              system($cmd, $status);
      47          }
      48      }
      49  
      50      if (file_exists($pathname)) {
      51          send_file($pathname, $image);
      52      } else {
      53          if (debugging()) {
      54              echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
      55              echo "Image not found!<br />";
      56              echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a>";
      57          } else {
      58              echo "Image not found!<br />";
      59              echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a><br />";
      60              echo "Please turn on debug mode in site configuration to see more info here.";
      61          }
      62      }
      63  
    

    Search This Site: