Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/filter/tex/lib.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 function filter_tex_get_executable($debug=false) {
00030     global $CFG;
00031 
00032     $error_message1 = "Your system is not configured to run mimeTeX. You need to download the appropriate<br />"
00033                      ."executable for you ".PHP_OS." platform from <a href=\"http://moodle.org/download/mimetex/\">"
00034                      ."http://moodle.org/download/mimetex/</a>, or obtain the C source<br /> "
00035                      ."from <a href=\"http://www.forkosh.com/mimetex.zip\">"
00036                      ."http://www.forkosh.com/mimetex.zip</a>, compile it and "
00037                      ."put the executable into your<br /> moodle/filter/tex/ directory.";
00038 
00039     $error_message2 = "Custom mimetex is not executable!<br /><br />";
00040 
00041     if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
00042         return "$CFG->dirroot/filter/tex/mimetex.exe";
00043     }
00044 
00045     $custom_commandpath = "$CFG->dirroot/filter/tex/mimetex";
00046     if (file_exists($custom_commandpath)) {
00047         if (is_executable($custom_commandpath)) {
00048             return $custom_commandpath;
00049         } else {
00050             print_error('mimetexnotexecutable', 'error');
00051         }
00052     }
00053 
00054     switch (PHP_OS) {
00055         case "Linux":   return "$CFG->dirroot/filter/tex/mimetex.linux";
00056         case "Darwin":  return "$CFG->dirroot/filter/tex/mimetex.darwin";
00057         case "FreeBSD": return "$CFG->dirroot/filter/tex/mimetex.freebsd";
00058     }
00059 
00060     print_error('mimetexisnotexist', 'error');
00061 }
00062 
00063 function filter_tex_sanitize_formula($texexp) {
00065     $tex_blacklist = array(
00066         'include','command','loop','repeat','open','toks','output',
00067         'input','catcode','name','^^',
00068         '\def','\edef','\gdef','\xdef',
00069         '\every','\errhelp','\errorstopmode','\scrollmode','\nonstopmode',
00070         '\batchmode','\read','\write','csname','\newhelp','\uppercase',
00071         '\lowercase','\relax','\aftergroup',
00072         '\afterassignment','\expandafter','\noexpand','\special',
00073         '\let', '\futurelet','\else','\fi','\chardef','\makeatletter','\afterground',
00074         '\noexpand','\line','\mathcode','\item','\section','\mbox','\declarerobustcommand'
00075     );
00076 
00077     return  str_ireplace($tex_blacklist, 'forbiddenkeyword', $texexp);
00078 }
00079 
00080 function filter_tex_get_cmd($pathname, $texexp) {
00081     $texexp = filter_tex_sanitize_formula($texexp);
00082     $texexp = escapeshellarg($texexp);
00083     $executable = filter_tex_get_executable(false);
00084 
00085     if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
00086         $executable = str_replace(' ', '^ ', $executable);
00087         return "$executable ++ -e  \"$pathname\" -- $texexp";
00088 
00089     } else {
00090         return "\"$executable\" -e \"$pathname\" -- $texexp";
00091     }
00092 }
00093 
00097 function filter_tex_updatedcallback($name) {
00098     global $CFG, $DB;
00099     reset_text_filters_cache();
00100 
00101     if (file_exists("$CFG->dataroot/filter/tex")) {
00102         remove_dir("$CFG->dataroot/filter/tex");
00103     }
00104     if (file_exists("$CFG->dataroot/filter/algebra")) {
00105         remove_dir("$CFG->dataroot/filter/algebra");
00106     }
00107     if (file_exists("$CFG->tempdir/latex")) {
00108         remove_dir("$CFG->tempdir/latex");
00109     }
00110 
00111     $DB->delete_records('cache_filters', array('filter'=>'tex'));
00112     $DB->delete_records('cache_filters', array('filter'=>'algebra'));
00113 
00114     if (!isset($CFG->filter_tex_pathlatex)) {
00115         // detailed settings not present yet
00116         return;
00117     }
00118 
00119     if (!(is_file($CFG->filter_tex_pathlatex) && is_executable($CFG->filter_tex_pathlatex) &&
00120           is_file($CFG->filter_tex_pathdvips) && is_executable($CFG->filter_tex_pathdvips) &&
00121           is_file($CFG->filter_tex_pathconvert) && is_executable($CFG->filter_tex_pathconvert))) {
00122         // LaTeX, dvips or convert are not available, and mimetex can only produce GIFs so...
00123         set_config('filter_tex_convertformat', 'gif');
00124     }
00125 }
00126 
00127 
 All Data Structures Namespaces Files Functions Variables Enumerations