mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-22001 filter_text() and filter_string() now use context parameter instead of courseid, PAGE->context is used only as a fallback; moved comment stuff away from format_text() because it does not belong there; filterlib is not using courseid except for legacy filters; fixed coding style in filters;improved php docs; fixed upgrade of filters (should be in plugins, not core)
This commit is contained in:
parent
1ef927d9f9
commit
35716b8682
@ -15,7 +15,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Core global functions for Blog.
|
||||
*
|
||||
@ -25,6 +24,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Library of functions and constants for blog
|
||||
*/
|
||||
|
@ -15,7 +15,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Classes for Blogs.
|
||||
*
|
||||
@ -25,6 +24,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Blog_entry class. Represents an entry in a user's blog. Contains all methods for managing this entry.
|
||||
@ -98,8 +98,9 @@ class blog_entry {
|
||||
global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
|
||||
|
||||
$user = $DB->get_record('user', array('id'=>$this->userid));
|
||||
$options = new stdclass;
|
||||
if ($CFG->blogusecomments) {
|
||||
$cmttext = '';
|
||||
if (!empty($CFG->usecomments) and $CFG->blogusecomments) {
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
// Comments
|
||||
$cmt = new stdClass();
|
||||
$cmt->context = get_context_instance(CONTEXT_USER, $user->id);
|
||||
@ -108,11 +109,12 @@ class blog_entry {
|
||||
$cmt->env = 'blog';
|
||||
$cmt->itemid = $this->id;
|
||||
$cmt->showcount = $CFG->blogshowcommentscount;
|
||||
$options->comments = $cmt;
|
||||
$comment = new comment($cmt);
|
||||
$cmttext = $comment->output(true);
|
||||
}
|
||||
$this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog', 'post', $this->id);
|
||||
|
||||
$template['body'] = format_text($this->summary, $this->summaryformat, $options);
|
||||
$template['body'] = format_text($this->summary, $this->summaryformat).$cmttext;
|
||||
$template['title'] = format_string($this->subject);
|
||||
$template['userid'] = $user->id;
|
||||
$template['author'] = fullname($user);
|
||||
@ -481,7 +483,9 @@ class blog_entry {
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$files = $fs->get_area_files(SYSCONTEXTID, 'blog', 'attachment', $this->id);
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
|
||||
$files = $fs->get_area_files($syscontext->id, 'blog', 'attachment', $this->id);
|
||||
|
||||
$imagereturn = "";
|
||||
$output = "";
|
||||
@ -514,7 +518,7 @@ class blog_entry {
|
||||
$imagereturn .= "<br />" . $OUTPUT->pix_icon($ffurl, $filename);
|
||||
} else {
|
||||
$imagereturn .= html_writer::link($ffurl, $image);
|
||||
$imagereturn .= filter_text(html_writer::link($ffurl, $filename));
|
||||
$imagereturn .= format_text(html_writer::link($ffurl, $filename), FORMAT_HTML, array('context'=>$syscontext));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,36 @@
|
||||
<?php
|
||||
//This function provides automatic linking to
|
||||
//activities when its name (title) is found inside every Moodle text
|
||||
//It's based in the glosssary filter by Williams Castillo
|
||||
//Modifications by stronk7.
|
||||
class activitynames_filter extends moodle_text_filter {
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This filter provides automatic linking to
|
||||
* activities when its name (title) is found inside every Moodle text
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage activitynames
|
||||
* @copyright 2004 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Activity name filtering
|
||||
*/
|
||||
class filter_activitynames extends moodle_text_filter {
|
||||
// Trivial-cache - keyed on $cachedcourseid
|
||||
static $activitylist = null;
|
||||
static $cachedcourseid;
|
||||
@ -11,25 +38,25 @@ class activitynames_filter extends moodle_text_filter {
|
||||
function filter($text) {
|
||||
global $CFG, $COURSE, $DB;
|
||||
|
||||
if (empty($this->courseid)) {
|
||||
$this->courseid = SITEID;
|
||||
if (!$courseid = get_courseid_from_context($this->context)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
// Initialise/invalidate our trivial cache if dealing with a different course
|
||||
if (!isset($this->cachedcourseid) || $this->cachedcourseid !== (int)$this->courseid) {
|
||||
if (!isset($this->cachedcourseid) || $this->cachedcourseid !== (int)$courseid) {
|
||||
$this->activitylist = null;
|
||||
}
|
||||
$this->cachedcourseid = (int)$this->courseid;
|
||||
$this->cachedcourseid = (int)$courseid;
|
||||
|
||||
/// It may be cached
|
||||
|
||||
if (is_null($this->activitylist)) {
|
||||
$this->activitylist = array();
|
||||
|
||||
if ($COURSE->id == $this->courseid) {
|
||||
if ($COURSE->id == $courseid) {
|
||||
$course = $COURSE;
|
||||
} else {
|
||||
$course = $DB->get_record("course", array("id"=>$this->courseid));
|
||||
$course = $DB->get_record("course", array("id"=>$courseid));
|
||||
}
|
||||
|
||||
if (!isset($course->modinfo)) {
|
||||
@ -44,7 +71,7 @@ class activitynames_filter extends moodle_text_filter {
|
||||
$this->activitylist = array(); /// We will store all the activities here
|
||||
|
||||
//Sort modinfo by name length
|
||||
usort($modinfo, 'comparemodulenamesbylength');
|
||||
usort($modinfo, 'filter_activitynames_comparemodulenamesbylength');
|
||||
|
||||
foreach ($modinfo as $activity) {
|
||||
//Exclude labels, hidden activities and activities for group members only
|
||||
@ -76,7 +103,7 @@ class activitynames_filter extends moodle_text_filter {
|
||||
|
||||
|
||||
//This function is used to order module names from longer to shorter
|
||||
function comparemodulenamesbylength($a, $b) {
|
||||
function filter_activitynames_comparemodulenamesbylength($a, $b) {
|
||||
if (strlen($a->name) == strlen($b->name)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -214,8 +214,8 @@ function tex2image($texexp, $md5, $return=false) {
|
||||
if (file_exists($pathname)) {
|
||||
unlink($pathname);
|
||||
}
|
||||
$commandpath = tex_filter_get_executable(true);
|
||||
$cmd = tex_filter_get_cmd($pathname, $texexp);
|
||||
$commandpath = filter_tex_get_executable(true);
|
||||
$cmd = filter_tex_get_cmd($pathname, $texexp);
|
||||
system($cmd, $status);
|
||||
|
||||
if ($return) {
|
||||
|
@ -1,26 +1,33 @@
|
||||
<?PHP
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Filter for converting simple calculator-type algebraic //
|
||||
// expressions to cached gif images //
|
||||
// //
|
||||
// Copyright (C) 2004 Zbigniew Fiedorowicz fiedorow@math.ohio-state.edu //
|
||||
// Originally based on code provided by Bruno Vernier bruno@vsbeducation.ca//
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Moodle - Filter for converting simple calculator-type algebraic
|
||||
* expressions to cached gif images
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage algebra
|
||||
* @copyright 2004 Zbigniew Fiedorowicz fiedorow@math.ohio-state.edu
|
||||
* Originally based on code provided by Bruno Vernier bruno@vsbeducation.ca
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// NOTE: This Moodle text filter converts algebraic expressions delimited
|
||||
// by either @@...@@ or by <algebra...>...</algebra> tags
|
||||
@ -37,7 +44,7 @@
|
||||
// You will then need to edit your moodle/config.php to invoke mathml_filter.php
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
function string_file_picture_algebra($imagefile, $tex= "", $height="", $width="", $align="middle") {
|
||||
function filter_algebra_image($imagefile, $tex= "", $height="", $width="", $align="middle") {
|
||||
// Given the path to a picture file in a course, or a URL,
|
||||
// this function includes the picture in the page.
|
||||
global $CFG, $OUTPUT;
|
||||
@ -77,14 +84,14 @@ function string_file_picture_algebra($imagefile, $tex= "", $height="", $width=""
|
||||
$action = new popup_action('click', $link, 'popup', array('height'=>300,'width'=>240));
|
||||
}
|
||||
$output .= $OUTPUT->action_link($link, $anchorcontents, $action, array('title'=>'TeX'));
|
||||
|
||||
|
||||
} else {
|
||||
$output .= "Error: must pass URL or course";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
class algebra_filter extends moodle_text_filter {
|
||||
class filter_algebra extends moodle_text_filter {
|
||||
function filter($text){
|
||||
global $CFG, $DB;
|
||||
|
||||
@ -221,12 +228,12 @@ class algebra_filter extends moodle_text_filter {
|
||||
$texcache->rawtext = $texexp;
|
||||
$texcache->timemodified = time();
|
||||
$DB->insert_record("cache_filters", $texcache, false);
|
||||
$text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texexp, '', '', $align), $text);
|
||||
$text = str_replace( $matches[0][$i], filter_algebra_image($filename, $texexp, '', '', $align), $text);
|
||||
} else {
|
||||
$text = str_replace( $matches[0][$i],"<b>Undetermined error:</b> ",$text);
|
||||
}
|
||||
} else {
|
||||
$text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texcache->rawtext), $text);
|
||||
$text = str_replace( $matches[0][$i], filter_algebra_image($filename, $texcache->rawtext), $text);
|
||||
}
|
||||
}
|
||||
return $text;
|
||||
|
@ -42,7 +42,7 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
||||
$texexp = str_replace('>','>',$texexp);
|
||||
$texexp = preg_replace('!\r\n?!',' ',$texexp);
|
||||
$texexp = '\Large ' . $texexp;
|
||||
$cmd = tex_filter_get_cmd($pathname, $texexp);
|
||||
$cmd = filter_tex_get_cmd($pathname, $texexp);
|
||||
system($cmd, $status);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,34 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Censorship filtering
|
||||
*
|
||||
* This very simple example of a Text Filter will parse
|
||||
* printed text, blacking out words perceived to be bad
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage censor
|
||||
* @copyright 2004 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Censorship filtering
|
||||
//
|
||||
@ -9,12 +39,11 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
/// This is the filtering class. It accepts the courseid and
|
||||
/// options to be filtered (In HTML form).
|
||||
class censor_filter extends moodle_text_filter {
|
||||
class filter_censor extends moodle_text_filter {
|
||||
private function _canseecensor() {
|
||||
return is_siteadmin(); //TODO: add proper access control
|
||||
}
|
||||
|
||||
function hash(){
|
||||
$cap = "mod/filter:censor";
|
||||
if (is_siteadmin()) { //TODO: add proper access control
|
||||
@ -22,6 +51,7 @@ class censor_filter extends moodle_text_filter {
|
||||
}
|
||||
return $cap;
|
||||
}
|
||||
|
||||
function filter($text){
|
||||
static $words;
|
||||
global $CFG;
|
||||
|
@ -1,9 +1,36 @@
|
||||
<?php
|
||||
// This class looks for email addresses in Moodle text and
|
||||
// hides them using the Moodle obfuscate_text function.
|
||||
// Original code by Mike Churchward
|
||||
|
||||
class emailprotect_filter extends moodle_text_filter {
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Basic email protection filter.
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage emailprotect
|
||||
* @copyright 2004 Mike Churchward
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* This class looks for email addresses in Moodle text and
|
||||
* hides them using the Moodle obfuscate_text function.
|
||||
*/
|
||||
class filter_emailprotect extends moodle_text_filter {
|
||||
function filter($text) {
|
||||
/// Do a quick check using stripos to avoid unnecessary work
|
||||
if (strpos($text, '@') === false) {
|
||||
@ -18,21 +45,22 @@ class emailprotect_filter extends moodle_text_filter {
|
||||
|
||||
/// pattern to find a mailto link with the linked text.
|
||||
$pattern = '|(<a\s+href\s*=\s*[\'"]?mailto:)'.$emailregex.'([\'"]?\s*>)'.'(.*)'.'(</a>)|iU';
|
||||
$text = preg_replace_callback($pattern, 'alter_mailto', $text);
|
||||
$text = preg_replace_callback($pattern, 'filter_emailprotect_alter_mailto', $text);
|
||||
|
||||
/// pattern to find any other email address in the text.
|
||||
$pattern = '/(^|\s+|>)'.$emailregex.'($|\s+|\.\s+|\.$|<)/i';
|
||||
$text = preg_replace_callback($pattern, 'alter_email', $text);
|
||||
$text = preg_replace_callback($pattern, 'filter_emailprotect_alter_email', $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
function alter_email($matches) {
|
||||
|
||||
function filter_emailprotect_alter_email($matches) {
|
||||
return $matches[1].obfuscate_text($matches[2]).$matches[3];
|
||||
}
|
||||
|
||||
function alter_mailto($matches) {
|
||||
function filter_emailprotect_alter_mailto($matches) {
|
||||
return obfuscate_mailto($matches[2], $matches[4]);
|
||||
}
|
||||
|
||||
|
@ -1,37 +1,28 @@
|
||||
<?php
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.org //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* A Moodle form base class for editing local filter settings.
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package moodlecore
|
||||
*//** */
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
||||
}
|
||||
* @package core
|
||||
* @subpackage filter
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
|
||||
@ -53,7 +44,7 @@ abstract class filter_local_settings_form extends moodleform {
|
||||
* and calls definition_inner to insert the custom controls in the appropriate place.
|
||||
*/
|
||||
public function definition() {
|
||||
$mform =& $this->_form;
|
||||
$mform = $this->_form;
|
||||
|
||||
$this->definition_inner($mform);
|
||||
|
||||
|
@ -1,34 +1,27 @@
|
||||
<?php
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.org //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Lets users configure which filters are active in a sub-context.
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package moodlecore
|
||||
*//** */
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package core
|
||||
* @subpackage filter
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
@ -18,9 +18,10 @@
|
||||
/**
|
||||
* Media filter post install hook
|
||||
*
|
||||
* @package filter_mediaplugin
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package filter
|
||||
* @subpackage mediaplugin
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
function xmldb_filter_mediaplugin_install() {
|
||||
|
@ -1,23 +1,37 @@
|
||||
<?php
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Media plugin filtering
|
||||
//
|
||||
// This filter will replace any links to a media file with
|
||||
// a media plugin that plays that media inline
|
||||
//
|
||||
// To activate this filter, add a line like this to your
|
||||
// list of filters in your Filter configuration:
|
||||
//
|
||||
// filter/mediaplugin/filter.php
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
/// This is the filtering function itself. It accepts the
|
||||
/// courseid and the text to be filtered (in HTML form).
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Media plugin filtering
|
||||
*
|
||||
* This filter will replace any links to a media file with
|
||||
* a media plugin that plays that media inline
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage mediaplugin
|
||||
* @copyright 2004 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
class mediaplugin_filter extends moodle_text_filter {
|
||||
class filter_mediaplugin extends moodle_text_filter {
|
||||
private $eolas_fix_applied = false;
|
||||
function filter($text) {
|
||||
global $CFG, $PAGE;
|
||||
@ -36,78 +50,78 @@ class mediaplugin_filter extends moodle_text_filter {
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_mp3) {
|
||||
$search = '/<a.*?href="([^<]+\.mp3)"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_mp3_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_mp3_callback', $newtext);
|
||||
}
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_swf) {
|
||||
$search = '/<a.*?href="([^<]+\.swf)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_swf_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_swf_callback', $newtext);
|
||||
}
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_flv) {
|
||||
$search = '/<a.*?href="([^<]+\.flv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_flv_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_flv_callback', $newtext);
|
||||
}
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_mov) {
|
||||
$search = '/<a.*?href="([^<]+\.mov)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
|
||||
|
||||
$search = '/<a.*?href="([^<]+\.mp4)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
|
||||
|
||||
$search = '/<a.*?href="([^<]+\.m4v)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
|
||||
|
||||
$search = '/<a.*?href="([^<]+\.m4a)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
|
||||
}
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_wmv) {
|
||||
$search = '/<a.*?href="([^<]+\.wmv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_wmp_callback', $newtext);
|
||||
}
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_mpg) {
|
||||
$search = '/<a.*?href="([^<]+\.mpe?g)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
|
||||
}
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_avi) {
|
||||
$search = '/<a.*?href="([^<]+\.avi)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_wmp_callback', $newtext);
|
||||
}
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_ram) {
|
||||
$search = '/<a.*?href="([^<]+\.ram)"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_real_callback', $newtext);
|
||||
}
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_rpm) {
|
||||
$search = '/<a.*?href="([^<]+\.rpm)"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_real_callback', $newtext);
|
||||
}
|
||||
|
||||
if ($CFG->filter_mediaplugin_enable_rm) {
|
||||
$search = '/<a.*?href="([^<]+\.rm)"[^>]*>.*?<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_real_callback', $newtext);
|
||||
}
|
||||
|
||||
if (!empty($CFG->filter_mediaplugin_enable_youtube)) {
|
||||
$search = '/<a.*?href="([^<]*)youtube.com\/watch\?v=([^"]*)"[^>]*>(.*?)<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_youtube_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_callback', $newtext);
|
||||
|
||||
$search = '/<a.*?href="([^<]*)youtube.com\/v\/([^"]*)"[^>]*>(.*?)<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_youtube_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_callback', $newtext);
|
||||
}
|
||||
|
||||
if (!empty($CFG->filter_mediaplugin_enable_img)) {
|
||||
$search = '/<a.*?href="([^<]+\.jpg)"[^>]*>(.*?)<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_img_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_img_callback', $newtext);
|
||||
$search = '/<a.*?href="([^<]+\.png)"[^>]*>(.*?)<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_img_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_img_callback', $newtext);
|
||||
$search = '/<a.*?href="([^<]+\.gif)"[^>]*>(.*?)<\/a>/is';
|
||||
$newtext = preg_replace_callback($search, 'mediaplugin_filter_img_callback', $newtext);
|
||||
$newtext = preg_replace_callback($search, 'filter_mediaplugin_img_callback', $newtext);
|
||||
}
|
||||
|
||||
if (empty($newtext) or $newtext === $text) {
|
||||
@ -128,7 +142,7 @@ class mediaplugin_filter extends moodle_text_filter {
|
||||
///===========================
|
||||
/// callback filter functions
|
||||
|
||||
function mediaplugin_filter_mp3_callback($link) {
|
||||
function filter_mediaplugin_mp3_callback($link) {
|
||||
global $CFG, $OUTPUT, $PAGE;
|
||||
|
||||
$c = $OUTPUT->filter_mediaplugin_colors(); // You can set this up in your theme/xxx/config.php
|
||||
@ -155,7 +169,7 @@ function mediaplugin_filter_mp3_callback($link) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
function mediaplugin_filter_swf_callback($link) {
|
||||
function filter_mediaplugin_swf_callback($link) {
|
||||
global $PAGE;
|
||||
static $count = 0;
|
||||
$count++;
|
||||
@ -175,13 +189,13 @@ function mediaplugin_filter_swf_callback($link) {
|
||||
$args['quality'] = 'high';
|
||||
|
||||
$jsoutput = create_ufo_inline($id, $args);
|
||||
|
||||
|
||||
$output = $link[0].'<span class="mediaplugin mediaplugin_swf" id="'.$id.'">('.get_string('flashanimation', 'filter_mediaplugin').')</span>'.$jsoutput;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function mediaplugin_filter_flv_callback($link) {
|
||||
function filter_mediaplugin_flv_callback($link) {
|
||||
global $CFG, $PAGE;
|
||||
|
||||
static $count = 0;
|
||||
@ -208,7 +222,7 @@ function mediaplugin_filter_flv_callback($link) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
function mediaplugin_filter_real_callback($link, $autostart=false) {
|
||||
function filter_mediaplugin_real_callback($link, $autostart=false) {
|
||||
$url = addslashes_js($link[1]);
|
||||
$mimetype = mimeinfo('type', $url);
|
||||
$autostart = $autostart ? 'true' : 'false';
|
||||
@ -240,7 +254,7 @@ document.write(\'<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" wi
|
||||
/**
|
||||
* Change links to Youtube into embedded Youtube videos
|
||||
*/
|
||||
function mediaplugin_filter_youtube_callback($link, $autostart=false) {
|
||||
function filter_mediaplugin_youtube_callback($link, $autostart=false) {
|
||||
|
||||
$site = addslashes_js($link[1]);
|
||||
$url = addslashes_js($link[2]);
|
||||
@ -259,7 +273,7 @@ function mediaplugin_filter_youtube_callback($link, $autostart=false) {
|
||||
/**
|
||||
* Change links to images into embedded images
|
||||
*/
|
||||
function mediaplugin_filter_img_callback($link, $autostart=false) {
|
||||
function filter_mediaplugin_img_callback($link, $autostart=false) {
|
||||
$url = addslashes_js($link[1]);
|
||||
$info = addslashes_js($link[2]);
|
||||
|
||||
@ -269,7 +283,7 @@ function mediaplugin_filter_img_callback($link, $autostart=false) {
|
||||
/**
|
||||
* Embed video using window media player if available
|
||||
*/
|
||||
function mediaplugin_filter_wmp_callback($link, $autostart=false) {
|
||||
function filter_mediaplugin_wmp_callback($link, $autostart=false) {
|
||||
$url = $link[1];
|
||||
if (empty($link[3]) or empty($link[4])) {
|
||||
$mpsize = '';
|
||||
@ -312,7 +326,7 @@ function mediaplugin_filter_wmp_callback($link, $autostart=false) {
|
||||
</object></span>';
|
||||
}
|
||||
|
||||
function mediaplugin_filter_qt_callback($link, $autostart=false) {
|
||||
function filter_mediaplugin_qt_callback($link, $autostart=false) {
|
||||
$url = $link[1];
|
||||
if (empty($link[3]) or empty($link[4])) {
|
||||
$size = 'width="440" height="315"';
|
||||
|
@ -6,7 +6,7 @@ if ($ADMIN->fulltree) {
|
||||
|
||||
$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_mp3', get_string('mediapluginmp3','admin'), '', 1));
|
||||
|
||||
$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_swf', get_string('mediapluginswf','admin'), get_string('mediapluginswfnote','admin'), 0));
|
||||
$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_swf', get_string('mediapluginswf','admin'), get_string('mediapluginswfnote','admin'), 0)); // sorry, this is a big potential security hole (skodak)
|
||||
|
||||
$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_mov', get_string('mediapluginmov','admin'), '', 1));
|
||||
|
||||
|
@ -18,9 +18,12 @@
|
||||
/**
|
||||
* Media filter
|
||||
*
|
||||
* @package filter_mediaplugin
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package filter
|
||||
* @subpackage mediaplugin
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2010070900;
|
||||
|
@ -1,26 +1,29 @@
|
||||
<?php
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// This program is part of Moodle - Modular Object-Oriented Dynamic //
|
||||
// Learning Environment - http://moodle.org //
|
||||
// //
|
||||
// Copyright (C) 2004 Gaetan Frenoy <gaetan@frenoy.net> //
|
||||
// Eloy Lafuente <stronk7@moodle.org> //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package filter
|
||||
* @subpackage multilang
|
||||
* @copyright Gaetan Frenoy <gaetan@frenoy.net>
|
||||
* @copyright 2004 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Given XML multilinguage text, return relevant text according to
|
||||
// current language:
|
||||
@ -36,7 +39,7 @@
|
||||
// Following new syntax is not compatible with old one:
|
||||
// <span lang="XX" class="multilang">one lang</span><span lang="YY" class="multilang">another language</span>
|
||||
|
||||
class multilang_filter extends moodle_text_filter {
|
||||
class filter_multilang extends moodle_text_filter {
|
||||
function filter($text) {
|
||||
global $CFG;
|
||||
|
||||
@ -57,7 +60,7 @@ class multilang_filter extends moodle_text_filter {
|
||||
$search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.*?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.*?<\/(?:lang|span)>)+/is';
|
||||
}
|
||||
|
||||
$result = preg_replace_callback($search, 'multilang_filter_impl', $text);
|
||||
$result = preg_replace_callback($search, 'filter_multilang_impl', $text);
|
||||
|
||||
if (is_null($result)) {
|
||||
return $text; //error during regex processing (too many nested spans?)
|
||||
@ -67,7 +70,7 @@ class multilang_filter extends moodle_text_filter {
|
||||
}
|
||||
}
|
||||
|
||||
function multilang_filter_impl($langblock) {
|
||||
function filter_multilang_impl($langblock) {
|
||||
global $CFG;
|
||||
|
||||
$mylang = current_language();
|
||||
|
35
filter/tex/db/install.php
Normal file
35
filter/tex/db/install.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tex filter post install hook
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage tex
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
function xmldb_filter_tex_install() {
|
||||
global $CFG;
|
||||
|
||||
// purge all caches during 1.9 upgrade
|
||||
|
||||
require_once("$CFG->dirroot/filter/tex/lib.php");
|
||||
filter_tex_updatedcallback(null);
|
||||
}
|
||||
|
@ -1,25 +1,29 @@
|
||||
<?PHP
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Filter for converting TeX expressions to cached gif images //
|
||||
// //
|
||||
// Copyright (C) 2004 Zbigniew Fiedorowicz fiedorow@math.ohio-state.edu //
|
||||
// Originally based on code provided by Bruno Vernier bruno@vsbeducation.ca//
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Moodle - Filter for converting TeX expressions to cached gif images
|
||||
* @package filter
|
||||
* @subpackage tex
|
||||
* @copyright 2004 Zbigniew Fiedorowicz fiedorow@math.ohio-state.edu
|
||||
* Originally based on code provided by Bruno Vernier bruno@vsbeducation.ca
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// NOTE: This Moodle text filter converts TeX expressions delimited
|
||||
// by either $$...$$ or by <tex...>...</tex> tags to gif images using
|
||||
@ -36,7 +40,7 @@
|
||||
// filter/tex/filter.php //
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $align="middle", $alt='') {
|
||||
function filter_text_image($imagefile, $tex= "", $height="", $width="", $align="middle", $alt='') {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
if ($alt==='') {
|
||||
@ -100,7 +104,7 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a
|
||||
return $output;
|
||||
}
|
||||
|
||||
class tex_filter extends moodle_text_filter {
|
||||
class filter_tex extends moodle_text_filter {
|
||||
function filter ($text) {
|
||||
|
||||
global $CFG, $DB;
|
||||
@ -165,7 +169,7 @@ class tex_filter extends moodle_text_filter {
|
||||
$DB->insert_record("cache_filters", $texcache, false);
|
||||
}
|
||||
$filename = $md5 . ".{$CFG->filter_tex_convertformat}";
|
||||
$text = str_replace( $matches[0][$i], string_file_picture_tex($filename, $texexp, '', '', $align, $alt), $text);
|
||||
$text = str_replace( $matches[0][$i], filter_text_image($filename, $texexp, '', '', $align, $alt), $text);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
function construct_latex_document( $formula, $fontsize=12 ) {
|
||||
global $CFG;
|
||||
|
||||
$formula = tex_sanitize_formula($formula);
|
||||
$formula = filter_tex_sanitize_formula($formula);
|
||||
|
||||
// $fontsize don't affects to formula's size. $density can change size
|
||||
$doc = "\\documentclass[{$fontsize}pt]{article}\n";
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
function tex_filter_get_executable($debug=false) {
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
function filter_tex_get_executable($debug=false) {
|
||||
global $CFG;
|
||||
|
||||
$error_message1 = "Your system is not configured to run mimeTeX. You need to download the appropriate<br />"
|
||||
@ -34,7 +36,7 @@ function tex_filter_get_executable($debug=false) {
|
||||
print_error('mimetexisnotexist', 'error');
|
||||
}
|
||||
|
||||
function tex_sanitize_formula($texexp) {
|
||||
function filter_tex_sanitize_formula($texexp) {
|
||||
/// Check $texexp against blacklist (whitelisting could be more complete but also harder to maintain)
|
||||
$tex_blacklist = array(
|
||||
'include','command','loop','repeat','open','toks','output',
|
||||
@ -51,10 +53,10 @@ function tex_sanitize_formula($texexp) {
|
||||
return str_ireplace($tex_blacklist, 'forbiddenkeyword', $texexp);
|
||||
}
|
||||
|
||||
function tex_filter_get_cmd($pathname, $texexp) {
|
||||
$texexp = tex_sanitize_formula($texexp);
|
||||
function filter_tex_get_cmd($pathname, $texexp) {
|
||||
$texexp = filter_tex_sanitize_formula($texexp);
|
||||
$texexp = escapeshellarg($texexp);
|
||||
$executable = tex_filter_get_executable(false);
|
||||
$executable = filter_tex_get_executable(false);
|
||||
|
||||
if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
|
||||
$executable = str_replace(' ', '^ ', $executable);
|
||||
@ -84,7 +86,12 @@ function filter_tex_updatedcallback($name) {
|
||||
|
||||
$DB->delete_records('cache_filters', array('filter'=>'tex'));
|
||||
$DB->delete_records('cache_filters', array('filter'=>'algebra'));
|
||||
|
||||
|
||||
if (!isset($CFG->filter_tex_pathlatex)) {
|
||||
// detailed settings not present yet
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(is_file($CFG->filter_tex_pathlatex) && is_executable($CFG->filter_tex_pathlatex) &&
|
||||
is_file($CFG->filter_tex_pathdvips) && is_executable($CFG->filter_tex_pathdvips) &&
|
||||
is_file($CFG->filter_tex_pathconvert) && is_executable($CFG->filter_tex_pathconvert))) {
|
||||
|
@ -55,7 +55,7 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
||||
$texexp = str_replace('>', '>', $texexp);
|
||||
$texexp = preg_replace('!\r\n?!', ' ', $texexp);
|
||||
$texexp = '\Large '.$texexp;
|
||||
$cmd = tex_filter_get_cmd($pathname, $texexp);
|
||||
$cmd = filter_tex_get_cmd($pathname, $texexp);
|
||||
system($cmd, $status);
|
||||
}
|
||||
}
|
||||
|
@ -129,8 +129,8 @@
|
||||
}
|
||||
|
||||
$texexp = '\Large '.$texexp;
|
||||
$commandpath = tex_filter_get_executable(true);
|
||||
$cmd = tex_filter_get_cmd($pathname, $texexp);
|
||||
$commandpath = filter_tex_get_executable(true);
|
||||
$cmd = filter_tex_get_cmd($pathname, $texexp);
|
||||
system($cmd, $status);
|
||||
|
||||
if ($return) {
|
||||
|
29
filter/tex/version.php
Normal file
29
filter/tex/version.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tex filter
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage tex
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2010073000;
|
@ -1,5 +1,31 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* HTML tidy text filter.
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage tiny
|
||||
* @copyright 2004 Hannes Gassert <hannes at mediagonal dot ch>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// This class looks for text including markup and
|
||||
// applies tidy's repair function to it.
|
||||
// Tidy is a HTML clean and
|
||||
@ -11,11 +37,7 @@
|
||||
// If you want to know what you can set in $tidyoptions and what their default
|
||||
// values are, see http://php.net/manual/en/function.tidy-get-config.php.
|
||||
|
||||
class tidy_filter extends moodle_text_filter {
|
||||
/**
|
||||
* @author Hannes Gassert <hannes at mediagonal dot ch>
|
||||
* @param string text to be filtered
|
||||
*/
|
||||
class filter_tidy extends moodle_text_filter {
|
||||
function filter($text) {
|
||||
|
||||
/// Configuration for tidy. Feel free to tune for your needs, e.g. to allow
|
||||
|
@ -2269,6 +2269,36 @@ function get_context_info_array($contextid) {
|
||||
return array($context, $course, $cm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current course id or null if outside of course based on context parameter.
|
||||
* @param object $context
|
||||
* @return int|bool related course id or false
|
||||
*/
|
||||
function get_courseid_from_context($context) {
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
return $context->instanceid;
|
||||
}
|
||||
|
||||
if ($context->contextlevel < CONTEXT_COURSE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($context->contextlevel == CONTEXT_MODULE) {
|
||||
$parentcontexts = get_parent_contexts($context, false);
|
||||
$parent = reset($parentcontexts);
|
||||
$parent = get_context_instance_by_id($parent);
|
||||
return $parent->instanceid;
|
||||
}
|
||||
|
||||
if ($context->contextlevel == CONTEXT_BLOCK) {
|
||||
$parentcontexts = get_parent_contexts($context, false);
|
||||
$parent = reset($parentcontexts);
|
||||
return get_courseid_from_context($parent);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////
|
||||
// DB TABLE RELATED FUNCTIONS //
|
||||
|
@ -1283,13 +1283,6 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
|
||||
upgrade_main_savepoint(true, 2009032001);
|
||||
}
|
||||
|
||||
if ($oldversion < 2009033100) {
|
||||
require_once("$CFG->dirroot/filter/tex/lib.php");
|
||||
filter_tex_updatedcallback(null);
|
||||
/// Main savepoint reached
|
||||
upgrade_main_savepoint(true, 2009033100);
|
||||
}
|
||||
|
||||
if ($oldversion < 2009040300) {
|
||||
|
||||
/// Define table filter_active to be created
|
||||
|
@ -30,6 +30,32 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* Given some text in HTML format, this function will pass it
|
||||
* through any filters that have been configured for this context.
|
||||
*
|
||||
* @deprecated use the text formatting in a standard way instead,
|
||||
* this was abused mostly for embedding of attachments
|
||||
*
|
||||
* @param string $text The text to be passed through format filters
|
||||
* @param int $courseid The current course.
|
||||
* @return string the filtered string.
|
||||
*/
|
||||
function filter_text($text, $courseid = NULL) {
|
||||
global $CFG, $COURSE;
|
||||
|
||||
if (!$courseid) {
|
||||
$courseid = $COURSE->id;
|
||||
}
|
||||
|
||||
if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
return filter_manager::instance()->filter_text($text, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a physical path to a file, returns the URL through which it can be reached in Moodle.
|
||||
*
|
||||
|
@ -35,6 +35,14 @@ define('TEXTFILTER_OFF', -1);
|
||||
/** The states a filter can be in, stored in the filter_active table. */
|
||||
define('TEXTFILTER_DISABLED', -9999);
|
||||
|
||||
/**
|
||||
* Define one exclusive separator that we'll use in the temp saved tags
|
||||
* keys. It must be something rare enough to avoid having matches with
|
||||
* filterobjects. MDL-18165
|
||||
*/
|
||||
define('TEXTFILTER_EXCL_SEPARATOR', '-%-');
|
||||
|
||||
|
||||
/**
|
||||
* Class to manage the filtering of strings. It is intended that this class is
|
||||
* only used by weblib.php. Client code should probably be using the
|
||||
@ -42,9 +50,10 @@ define('TEXTFILTER_DISABLED', -9999);
|
||||
*
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core
|
||||
* @subpackage filter
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class filter_manager {
|
||||
/**
|
||||
@ -70,12 +79,11 @@ class filter_manager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @global object
|
||||
* @return filter_manager the singleton instance.
|
||||
*/
|
||||
public static function instance() {
|
||||
global $CFG;
|
||||
if (is_null(self::$singletoninstance)) {
|
||||
global $CFG;
|
||||
if (!empty($CFG->perfdebug)) {
|
||||
self::$singletoninstance = new performance_measuring_filter_manager();
|
||||
} else {
|
||||
@ -89,14 +97,13 @@ class filter_manager {
|
||||
* Load all the filters required by this context.
|
||||
*
|
||||
* @param object $context
|
||||
* @param int $courseid
|
||||
*/
|
||||
protected function load_filters($context, $courseid) {
|
||||
protected function load_filters($context) {
|
||||
$filters = filter_get_active_in_context($context);
|
||||
$this->textfilters[$context->id] = array();
|
||||
$this->stringfilters[$context->id] = array();
|
||||
foreach ($filters as $filtername => $localconfig) {
|
||||
$filter = $this->make_filter_object($filtername, $context, $courseid, $localconfig);
|
||||
$filter = $this->make_filter_object($filtername, $context, $localconfig);
|
||||
if (is_null($filter)) {
|
||||
continue;
|
||||
}
|
||||
@ -110,15 +117,13 @@ class filter_manager {
|
||||
/**
|
||||
* Factory method for creating a filter
|
||||
*
|
||||
* @global object
|
||||
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
|
||||
* @param object $context context object.
|
||||
* @param int $courseid course id.
|
||||
* @param array $localconfig array of local configuration variables for this filter.
|
||||
* @return object moodle_text_filter The filter, or null, if this type of filter is
|
||||
* not recognised or could not be created.
|
||||
*/
|
||||
protected function make_filter_object($filtername, $context, $courseid, $localconfig) {
|
||||
protected function make_filter_object($filtername, $context, $localconfig) {
|
||||
global $CFG;
|
||||
$path = $CFG->dirroot .'/'. $filtername .'/filter.php';
|
||||
if (!is_readable($path)) {
|
||||
@ -126,14 +131,14 @@ class filter_manager {
|
||||
}
|
||||
include_once($path);
|
||||
|
||||
$filterclassname = basename($filtername) . '_filter';
|
||||
$filterclassname = 'filter_' . basename($filtername);
|
||||
if (class_exists($filterclassname)) {
|
||||
return new $filterclassname($courseid, $context, $localconfig);
|
||||
return new $filterclassname($context, $localconfig);
|
||||
}
|
||||
|
||||
$legacyfunctionname = basename($filtername) . '_filter';
|
||||
if (function_exists($legacyfunctionname)) {
|
||||
return new legacy_filter($legacyfunctionname, $courseid, $context, $localconfig);
|
||||
return new legacy_filter($legacyfunctionname, $context, $localconfig);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -155,12 +160,11 @@ class filter_manager {
|
||||
/**
|
||||
* @todo Document this function
|
||||
* @param object $context
|
||||
* @param int $courseid
|
||||
* @return object A text filter
|
||||
*/
|
||||
protected function get_text_filters($context, $courseid) {
|
||||
protected function get_text_filters($context) {
|
||||
if (!isset($this->textfilters[$context->id])) {
|
||||
$this->load_filters($context, $courseid);
|
||||
$this->load_filters($context);
|
||||
}
|
||||
return $this->textfilters[$context->id];
|
||||
}
|
||||
@ -168,12 +172,11 @@ class filter_manager {
|
||||
/**
|
||||
* @todo Document this function
|
||||
* @param object $context
|
||||
* @param int $courseid
|
||||
* @return object A string filter
|
||||
*/
|
||||
protected function get_string_filters($context, $courseid) {
|
||||
protected function get_string_filters($context) {
|
||||
if (!isset($this->stringfilters[$context->id])) {
|
||||
$this->load_filters($context, $courseid);
|
||||
$this->load_filters($context);
|
||||
}
|
||||
return $this->stringfilters[$context->id];
|
||||
}
|
||||
@ -183,36 +186,33 @@ class filter_manager {
|
||||
*
|
||||
* @param string $text The text to filter
|
||||
* @param object $context
|
||||
* @param int $courseid
|
||||
* @return string resulting text
|
||||
*/
|
||||
public function filter_text($text, $context, $courseid) {
|
||||
$text = $this->apply_filter_chain($text, $this->get_text_filters($context, $courseid));
|
||||
public function filter_text($text, $context) {
|
||||
$text = $this->apply_filter_chain($text, $this->get_text_filters($context));
|
||||
/// <nolink> tags removed for XHTML compatibility
|
||||
$text = str_replace(array('<nolink>', '</nolink>'), '', $text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a peice of string
|
||||
* Filter a piece of string
|
||||
*
|
||||
* @param string $string The text to filter
|
||||
* @param object $context
|
||||
* @param int $courseid
|
||||
* @return string resulting string
|
||||
*/
|
||||
public function filter_string($string, $context, $courseid) {
|
||||
return $this->apply_filter_chain($string, $this->get_string_filters($context, $courseid));
|
||||
public function filter_string($string, $context) {
|
||||
return $this->apply_filter_chain($string, $this->get_string_filters($context));
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Document this function
|
||||
* @param object $context
|
||||
* @param int $courseid
|
||||
* @return object A string filter
|
||||
*/
|
||||
public function text_filtering_hash($context, $courseid) {
|
||||
$filters = $this->get_text_filters($context, $courseid);
|
||||
public function text_filtering_hash($context) {
|
||||
$filters = $this->get_text_filters($context);
|
||||
$hashes = array();
|
||||
foreach ($filters as $filter) {
|
||||
$hashes[] = $filter->hash();
|
||||
@ -227,22 +227,23 @@ class filter_manager {
|
||||
*
|
||||
* @todo Document this class
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core
|
||||
* @subpackage filter
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class null_filter_manager {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function filter_text($text, $context, $courseid) {
|
||||
public function filter_text($text, $context) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function filter_string($string, $context, $courseid) {
|
||||
public function filter_string($string, $context) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
@ -259,9 +260,10 @@ class null_filter_manager {
|
||||
*
|
||||
* @todo Document this class
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core
|
||||
* @subpackage filter
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class performance_measuring_filter_manager extends filter_manager {
|
||||
/** @var int */
|
||||
@ -272,35 +274,32 @@ class performance_measuring_filter_manager extends filter_manager {
|
||||
/**
|
||||
* @param string $filtername
|
||||
* @param object $context
|
||||
* @param int $courseid
|
||||
* @param mixed $localconfig
|
||||
* @return mixed
|
||||
*/
|
||||
protected function make_filter_object($filtername, $context, $courseid, $localconfig) {
|
||||
protected function make_filter_object($filtername, $context, $localconfig) {
|
||||
$this->filterscreated++;
|
||||
return parent::make_filter_object($filtername, $context, $courseid, $localconfig);
|
||||
return parent::make_filter_object($filtername, $context, $localconfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
* @param object $context
|
||||
* @param int $courseid
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter_text($text, $context, $courseid) {
|
||||
public function filter_text($text, $context) {
|
||||
$this->textsfiltered++;
|
||||
return parent::filter_text($text, $context, $courseid);
|
||||
return parent::filter_text($text, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param object $context
|
||||
* @param int $courseid
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter_string($string, $context, $courseid) {
|
||||
public function filter_string($string, $context) {
|
||||
$this->stringsfiltered++;
|
||||
return parent::filter_string($string, $context, $courseid);
|
||||
return parent::filter_string($string, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -325,13 +324,12 @@ class performance_measuring_filter_manager extends filter_manager {
|
||||
* Base class for text filters. You just need to override this class and
|
||||
* implement the filter method.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core
|
||||
* @subpackage filter
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class moodle_text_filter {
|
||||
/** @var int The course we are in. */
|
||||
protected $courseid;
|
||||
/** @var object The context we are in. */
|
||||
protected $context;
|
||||
/** @var object Any local configuration for this filter in this context. */
|
||||
@ -343,8 +341,7 @@ abstract class moodle_text_filter {
|
||||
* @param object $context The current context.
|
||||
* @param array $config Any context-specific configuration for this filter.
|
||||
*/
|
||||
public function __construct($courseid, $context, array $localconfig) {
|
||||
$this->courseid = $courseid;
|
||||
public function __construct($context, array $localconfig) {
|
||||
$this->context = $context;
|
||||
$this->localconfig = $localconfig;
|
||||
}
|
||||
@ -369,25 +366,27 @@ abstract class moodle_text_filter {
|
||||
* moodle_text_filter implementation that encapsulates an old-style filter that
|
||||
* only defines a function, not a class.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core
|
||||
* @subpackage filter
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class legacy_filter extends moodle_text_filter {
|
||||
/** @var string */
|
||||
protected $filterfunction;
|
||||
protected $courseid;
|
||||
|
||||
/**
|
||||
* Set any context-specific configuration for this filter.
|
||||
*
|
||||
* @param string $filterfunction
|
||||
* @param object $context The current course id.
|
||||
* @param object $context The current context.
|
||||
* @param array $config Any context-specific configuration for this filter.
|
||||
*/
|
||||
public function __construct($filterfunction, $courseid, $context, array $localconfig) {
|
||||
parent::__construct($courseid, $context, $localconfig);
|
||||
public function __construct($filterfunction, $context, array $localconfig) {
|
||||
parent::__construct($context, $localconfig);
|
||||
$this->filterfunction = $filterfunction;
|
||||
$this->courseid = get_courseid_from_context($this->context);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -395,25 +394,22 @@ class legacy_filter extends moodle_text_filter {
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter($text) {
|
||||
return call_user_func($this->filterfunction, $this->courseid, $text);
|
||||
if ($this->courseid) {
|
||||
// old filters are called only when inside courses
|
||||
return call_user_func($this->filterfunction, $this->courseid, $text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define one exclusive separator that we'll use in the temp saved tags
|
||||
* keys. It must be something rare enough to avoid having matches with
|
||||
* filterobjects. MDL-18165
|
||||
*/
|
||||
define('EXCL_SEPARATOR', '-%-');
|
||||
|
||||
/**
|
||||
* This is just a little object to define a phrase and some instructions
|
||||
* for how to process it. Filters can create an array of these to pass
|
||||
* to the filter_phrases function below.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core
|
||||
* @subpackage filter
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
**/
|
||||
class filterobject {
|
||||
/** @var string */
|
||||
@ -444,11 +440,11 @@ class filterobject {
|
||||
* @param bool $fullmatch
|
||||
* @param mixed $replacementphrase
|
||||
*/
|
||||
function filterobject($phrase, $hreftagbegin='<span class="highlight">',
|
||||
$hreftagend='</span>',
|
||||
$casesensitive=false,
|
||||
$fullmatch=false,
|
||||
$replacementphrase=NULL) {
|
||||
function filterobject($phrase, $hreftagbegin = '<span class="highlight">',
|
||||
$hreftagend = '</span>',
|
||||
$casesensitive = false,
|
||||
$fullmatch = false,
|
||||
$replacementphrase = NULL) {
|
||||
|
||||
$this->phrase = $phrase;
|
||||
$this->hreftagbegin = $hreftagbegin;
|
||||
@ -921,7 +917,6 @@ function filter_delete_all_for_filter($filter) {
|
||||
/**
|
||||
* Delete all the data in the database relating to a context, used when contexts are deleted.
|
||||
*
|
||||
* @global object
|
||||
* @param integer $contextid The id of the context being deleted.
|
||||
*/
|
||||
function filter_delete_all_for_context($contextid) {
|
||||
@ -935,7 +930,6 @@ function filter_delete_all_for_context($contextid) {
|
||||
* (The settings page for a filter must be called, for example,
|
||||
* filtersettingfiltertex or filtersettingmodglossay.)
|
||||
*
|
||||
* @global object
|
||||
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
|
||||
* @return boolean Whether there should be a 'Settings' link on the config page.
|
||||
*/
|
||||
@ -948,7 +942,6 @@ function filter_has_global_settings($filter) {
|
||||
/**
|
||||
* Does this filter have local (per-context) settings?
|
||||
*
|
||||
* @global object
|
||||
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
|
||||
* @return boolean Whether there should be a 'Settings' link on the manage filters in context page.
|
||||
*/
|
||||
@ -972,7 +965,6 @@ function filter_context_may_have_filter_settings($context) {
|
||||
/**
|
||||
* Process phrases intelligently found within a HTML text (such as adding links)
|
||||
*
|
||||
* @global object
|
||||
* @staticvar array $usedpharses
|
||||
* @param string $text the text that we are filtering
|
||||
* @param array $link_array an array of filterobjects
|
||||
@ -1206,7 +1198,7 @@ function filter_remove_duplicates($linkarray) {
|
||||
/**
|
||||
* Extract open/lose tags and their contents to avoid being processed by filters.
|
||||
* Useful to extract pieces of code like <a>...</a> tags. It returns the text
|
||||
* converted with some <#xEXCL_SEPARATORx#> codes replacing the extracted text. Such extracted
|
||||
* converted with some <#xTEXTFILTER_EXCL_SEPARATORx#> codes replacing the extracted text. Such extracted
|
||||
* texts are returned in the ignoretags array (as values), with codes as keys.
|
||||
*
|
||||
* @param string $text the text that we are filtering (in/out)
|
||||
@ -1214,7 +1206,7 @@ function filter_remove_duplicates($linkarray) {
|
||||
* @param array $filterignoretagsclose an array of close tags to end searching
|
||||
* @param array $ignoretags an array of saved strings useful to rebuild the original text (in/out)
|
||||
**/
|
||||
function filter_save_ignore_tags(&$text,$filterignoretagsopen,$filterignoretagsclose,&$ignoretags) {
|
||||
function filter_save_ignore_tags(&$text, $filterignoretagsopen, $filterignoretagsclose, &$ignoretags) {
|
||||
|
||||
/// Remove everything enclosed by the ignore tags from $text
|
||||
foreach ($filterignoretagsopen as $ikey=>$opentag) {
|
||||
@ -1227,7 +1219,7 @@ function filter_save_ignore_tags(&$text,$filterignoretagsopen,$filterignoretagsc
|
||||
preg_match_all($pregexp, $text, $list_of_ignores);
|
||||
foreach (array_unique($list_of_ignores[0]) as $key=>$value) {
|
||||
$prefix = (string)(count($ignoretags) + 1);
|
||||
$ignoretags['<#'.$prefix.EXCL_SEPARATOR.$key.'#>'] = $value;
|
||||
$ignoretags['<#'.$prefix.TEXTFILTER_EXCL_SEPARATOR.$key.'#>'] = $value;
|
||||
}
|
||||
if (!empty($ignoretags)) {
|
||||
$text = str_replace($ignoretags,array_keys($ignoretags),$text);
|
||||
@ -1237,18 +1229,18 @@ function filter_save_ignore_tags(&$text,$filterignoretagsopen,$filterignoretagsc
|
||||
|
||||
/**
|
||||
* Extract tags (any text enclosed by < and > to avoid being processed by filters.
|
||||
* It returns the text converted with some <%xEXCL_SEPARATORx%> codes replacing the extracted text. Such extracted
|
||||
* It returns the text converted with some <%xTEXTFILTER_EXCL_SEPARATORx%> codes replacing the extracted text. Such extracted
|
||||
* texts are returned in the tags array (as values), with codes as keys.
|
||||
*
|
||||
* @param string $text the text that we are filtering (in/out)
|
||||
* @param array $tags an array of saved strings useful to rebuild the original text (in/out)
|
||||
**/
|
||||
function filter_save_tags(&$text,&$tags) {
|
||||
function filter_save_tags(&$text, &$tags) {
|
||||
|
||||
preg_match_all('/<([^#%*].*?)>/is',$text,$list_of_newtags);
|
||||
foreach (array_unique($list_of_newtags[0]) as $ntkey=>$value) {
|
||||
$prefix = (string)(count($tags) + 1);
|
||||
$tags['<%'.$prefix.EXCL_SEPARATOR.$ntkey.'%>'] = $value;
|
||||
$tags['<%'.$prefix.TEXTFILTER_EXCL_SEPARATOR.$ntkey.'%>'] = $value;
|
||||
}
|
||||
if (!empty($tags)) {
|
||||
$text = str_replace($tags,array_keys($tags),$text);
|
||||
@ -1258,7 +1250,6 @@ function filter_save_tags(&$text,&$tags) {
|
||||
/**
|
||||
* Add missing openpopup javascript to HTML files.
|
||||
*
|
||||
* @global object
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
|
185
lib/weblib.php
185
lib/weblib.php
@ -912,7 +912,6 @@ function get_file_argument() {
|
||||
* @return array
|
||||
*/
|
||||
function format_text_menu() {
|
||||
|
||||
return array (FORMAT_MOODLE => get_string('formattext'),
|
||||
FORMAT_HTML => get_string('formathtml'),
|
||||
FORMAT_PLAIN => get_string('formatplain'),
|
||||
@ -928,90 +927,84 @@ function format_text_menu() {
|
||||
*
|
||||
* @todo Finish documenting this function
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @global object
|
||||
* @global object
|
||||
* @uses FORMAT_MOODLE
|
||||
* @uses FORMAT_HTML
|
||||
* @uses FORMAT_PLAIN
|
||||
* @uses FORMAT_WIKI
|
||||
* @uses FORMAT_MARKDOWN
|
||||
* @uses CLI_SCRIPT
|
||||
* @staticvar array $croncache
|
||||
* @param string $text The text to be formatted. This is raw text originally from user input.
|
||||
* @param int $format Identifier of the text format to be used
|
||||
* [FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN]
|
||||
* @param object $options ?
|
||||
* @param int $courseid The courseid to use, defaults to $COURSE->courseid
|
||||
* [FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_MARKDOWN]
|
||||
* @param object/array $options text formatting options
|
||||
* @param int $courseid_do_not_use deprecated course id, use context option instead
|
||||
* @return string
|
||||
*/
|
||||
function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL) {
|
||||
function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_do_not_use = NULL) {
|
||||
global $CFG, $COURSE, $DB, $PAGE;
|
||||
|
||||
static $croncache = array();
|
||||
|
||||
$hashstr = '';
|
||||
|
||||
if ($text === '') {
|
||||
return ''; // no need to do any filters and cleaning
|
||||
}
|
||||
if (!empty($options->comments) && !empty($CFG->usecomments)) {
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
$comment = new comment($options->comments);
|
||||
$cmt = $comment->output(true);
|
||||
} else {
|
||||
$cmt = '';
|
||||
}
|
||||
|
||||
$options = (array)$options; // detach object, we can not modify it
|
||||
|
||||
|
||||
if (!isset($options->trusted)) {
|
||||
$options->trusted = false;
|
||||
if (!isset($options['trusted'])) {
|
||||
$options['trusted'] = false;
|
||||
}
|
||||
if (!isset($options->noclean)) {
|
||||
if ($options->trusted and trusttext_active()) {
|
||||
if (!isset($options['noclean'])) {
|
||||
if ($options['trusted'] and trusttext_active()) {
|
||||
// no cleaning if text trusted and noclean not specified
|
||||
$options->noclean=true;
|
||||
$options['noclean'] = true;
|
||||
} else {
|
||||
$options->noclean=false;
|
||||
$options['noclean'] = false;
|
||||
}
|
||||
}
|
||||
if (!isset($options->nocache)) {
|
||||
$options->nocache=false;
|
||||
if (!isset($options['nocache'])) {
|
||||
$options['nocache'] = false;
|
||||
}
|
||||
if (!isset($options->smiley)) {
|
||||
$options->smiley=true;
|
||||
if (!isset($options['smiley'])) {
|
||||
$options['smiley'] = true;
|
||||
}
|
||||
if (!isset($options->filter)) {
|
||||
$options->filter=true;
|
||||
if (!isset($options['filter'])) {
|
||||
$options['filter'] = true;
|
||||
}
|
||||
if (!isset($options->para)) {
|
||||
$options->para=true;
|
||||
if (!isset($options['para'])) {
|
||||
$options['para'] = true;
|
||||
}
|
||||
if (!isset($options->newlines)) {
|
||||
$options->newlines=true;
|
||||
}
|
||||
if (empty($courseid)) {
|
||||
$courseid = $COURSE->id;
|
||||
if (!isset($options['newlines'])) {
|
||||
$options['newlines'] = true;
|
||||
}
|
||||
|
||||
if ($options->filter) {
|
||||
// Calculate best context
|
||||
if (isset($options['context'])) { // first by explicit passed context option
|
||||
if (is_object($options['context'])) {
|
||||
$context = $options['context'];
|
||||
} else {
|
||||
$context = get_context_instance_by_id($context);
|
||||
}
|
||||
} else if ($courseid_do_not_use) {
|
||||
// legacy courseid
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid_do_not_use);
|
||||
} else {
|
||||
// fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-(
|
||||
$context = $PAGE->context;
|
||||
}
|
||||
|
||||
if ($options['filter']) {
|
||||
$filtermanager = filter_manager::instance();
|
||||
} else {
|
||||
$filtermanager = new null_filter_manager();
|
||||
}
|
||||
$context = $PAGE->context;
|
||||
|
||||
if (!empty($CFG->cachetext) and empty($options->nocache)) {
|
||||
$hashstr .= $text.'-'.$filtermanager->text_filtering_hash($context, $courseid).'-'.(int)$courseid.'-'.current_language().'-'.
|
||||
(int)$format.(int)$options->trusted.(int)$options->noclean.(int)$options->smiley.
|
||||
(int)$options->filter.(int)$options->para.(int)$options->newlines;
|
||||
if (!empty($CFG->cachetext) and empty($options['nocache'])) {
|
||||
$hashstr = $text.'-'.$filtermanager->text_filtering_hash($context).'-'.$context->id.'-'.current_language().'-'.
|
||||
(int)$format.(int)$options['trusted'].(int)$options['noclean'].(int)$options['smiley'].
|
||||
(int)$options['para'].(int)$options['newlines'];
|
||||
|
||||
$time = time() - $CFG->cachetext;
|
||||
$md5key = md5($hashstr);
|
||||
if (CLI_SCRIPT) {
|
||||
if (isset($croncache[$md5key])) {
|
||||
return $croncache[$md5key].$cmt;
|
||||
return $croncache[$md5key];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1025,20 +1018,20 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
|
||||
}
|
||||
$croncache[$md5key] = $oldcacheitem->formattedtext;
|
||||
}
|
||||
return $oldcacheitem->formattedtext.$cmt;
|
||||
return $oldcacheitem->formattedtext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($format) {
|
||||
case FORMAT_HTML:
|
||||
if ($options->smiley) {
|
||||
if ($options['smiley']) {
|
||||
replace_smilies($text);
|
||||
}
|
||||
if (!$options->noclean) {
|
||||
if (!$options['noclean']) {
|
||||
$text = clean_text($text, FORMAT_HTML);
|
||||
}
|
||||
$text = $filtermanager->filter_text($text, $context, $courseid);
|
||||
$text = $filtermanager->filter_text($text, $context);
|
||||
break;
|
||||
|
||||
case FORMAT_PLAIN:
|
||||
@ -1058,21 +1051,21 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
|
||||
|
||||
case FORMAT_MARKDOWN:
|
||||
$text = markdown_to_html($text);
|
||||
if ($options->smiley) {
|
||||
if ($options['smiley']) {
|
||||
replace_smilies($text);
|
||||
}
|
||||
if (!$options->noclean) {
|
||||
if (!$options['noclean']) {
|
||||
$text = clean_text($text, FORMAT_HTML);
|
||||
}
|
||||
$text = $filtermanager->filter_text($text, $context, $courseid);
|
||||
$text = $filtermanager->filter_text($text, $context);
|
||||
break;
|
||||
|
||||
default: // FORMAT_MOODLE or anything else
|
||||
$text = text_to_html($text, $options->smiley, $options->para, $options->newlines);
|
||||
if (!$options->noclean) {
|
||||
$text = text_to_html($text, $options['smiley'], $options['para'], $options['newlines']);
|
||||
if (!$options['noclean']) {
|
||||
$text = clean_text($text, FORMAT_HTML);
|
||||
}
|
||||
$text = $filtermanager->filter_text($text, $context, $courseid);
|
||||
$text = $filtermanager->filter_text($text, $context);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1085,7 +1078,7 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
|
||||
'relies on it. Please seek out and destroy that filter code.', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
if (empty($options->nocache) and !empty($CFG->cachetext)) {
|
||||
if (empty($options['nocache']) and !empty($CFG->cachetext)) {
|
||||
if (CLI_SCRIPT) {
|
||||
// special static cron cache - no need to store it in db if its not already there
|
||||
if (count($croncache) > 150) {
|
||||
@ -1094,7 +1087,7 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
|
||||
unset($croncache[$key]);
|
||||
}
|
||||
$croncache[$md5key] = $text;
|
||||
return $text.$cmt;
|
||||
return $text;
|
||||
}
|
||||
|
||||
$newcacheitem = new object();
|
||||
@ -1122,8 +1115,8 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
|
||||
}
|
||||
}
|
||||
}
|
||||
return $text.$cmt;
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1139,7 +1132,7 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
|
||||
* @param mixed $key int 0-4 or string one of 'moodle','html','plain','markdown'
|
||||
* @return mixed as above but the other way around!
|
||||
*/
|
||||
function text_format_name( $key ) {
|
||||
function text_format_name($key) {
|
||||
$lookup = array();
|
||||
$lookup[FORMAT_MOODLE] = 'moodle';
|
||||
$lookup[FORMAT_HTML] = 'html';
|
||||
@ -1188,26 +1181,40 @@ function reset_text_filters_cache() {
|
||||
* @param string $string The string to be filtered.
|
||||
* @param boolean $striplinks To strip any link in the result text.
|
||||
Moodle 1.8 default changed from false to true! MDL-8713
|
||||
* @param int $courseid Current course as filters can, potentially, use it
|
||||
* @param array $options options array/object or courseid
|
||||
* @return string
|
||||
*/
|
||||
function format_string($string, $striplinks=true, $courseid=NULL ) {
|
||||
function format_string($string, $striplinks = true, $options = NULL) {
|
||||
global $CFG, $COURSE, $PAGE;
|
||||
|
||||
//We'll use a in-memory cache here to speed up repeated strings
|
||||
static $strcache = false;
|
||||
|
||||
if ($strcache === false or count($strcache) > 2000 ) { // this number might need some tuning to limit memory usage in cron
|
||||
if ($strcache === false or count($strcache) > 2000) { // this number might need some tuning to limit memory usage in cron
|
||||
$strcache = array();
|
||||
}
|
||||
|
||||
//init course id
|
||||
if (empty($courseid)) {
|
||||
$courseid = $COURSE->id;
|
||||
if (is_numeric($options)) {
|
||||
// legacy courseid usage
|
||||
$options = array('context'=>get_context_instance(CONTEXT_COURSE, $options));
|
||||
} else {
|
||||
$options = (array)$options; // detach object, we can not modify it
|
||||
}
|
||||
|
||||
if (empty($options['context'])) {
|
||||
// fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-(
|
||||
$options['context'] = $PAGE->context;
|
||||
} else if (is_numeric($options['context'])) {
|
||||
$options['context'] = get_context_instance_by_id($options['context']);
|
||||
}
|
||||
|
||||
if (!$options['context']) {
|
||||
// we did not find any context? weird
|
||||
return $text;
|
||||
}
|
||||
|
||||
//Calculate md5
|
||||
$md5 = md5($string.'<+>'.$striplinks.'<+>'.$courseid.'<+>'.current_language());
|
||||
$md5 = md5($string.'<+>'.$striplinks.'<+>'.$options['context']->id.'<+>'.current_language());
|
||||
|
||||
//Fetch from cache if possible
|
||||
if (isset($strcache[$md5])) {
|
||||
@ -1218,9 +1225,8 @@ function format_string($string, $striplinks=true, $courseid=NULL ) {
|
||||
// Regular expression moved to its own method for easier unit testing
|
||||
$string = replace_ampersands_not_followed_by_entity($string);
|
||||
|
||||
if (!empty($CFG->filterall) && $CFG->version >= 2009040600) { // Avoid errors during the upgrade to the new system.
|
||||
$context = $PAGE->context;
|
||||
$string = filter_manager::instance()->filter_string($string, $context, $courseid);
|
||||
if (!empty($CFG->filterall) and $CFG->version >= 2009040600) { // Avoid errors during the upgrade to the new system.
|
||||
$string = filter_manager::instance()->filter_string($string, $options['context']);
|
||||
}
|
||||
|
||||
// If the site requires it, strip ALL tags from this string
|
||||
@ -1326,28 +1332,6 @@ function format_text_email($text, $format) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given some text in HTML format, this function will pass it
|
||||
* through any filters that have been configured for this context.
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @global object
|
||||
* @param string $text The text to be passed through format filters
|
||||
* @param int $courseid The current course.
|
||||
* @return string the filtered string.
|
||||
*/
|
||||
function filter_text($text, $courseid=NULL) {
|
||||
global $CFG, $COURSE, $PAGE;
|
||||
|
||||
if (empty($courseid)) {
|
||||
$courseid = $COURSE->id; // (copied from format_text)
|
||||
}
|
||||
|
||||
$context = $PAGE->context;
|
||||
|
||||
return filter_manager::instance()->filter_text($text, $context, $courseid);
|
||||
}
|
||||
/**
|
||||
* Formats activity intro text
|
||||
*
|
||||
@ -1362,10 +1346,10 @@ function filter_text($text, $courseid=NULL) {
|
||||
function format_module_intro($module, $activity, $cmid, $filter=true) {
|
||||
global $CFG;
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
$options = (object)array('noclean'=>true, 'para'=>false, 'filter'=>true);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
$options = (object)array('noclean'=>true, 'para'=>false, 'filter'=>true, 'context'=>$context);
|
||||
$intro = file_rewrite_pluginfile_urls($activity->intro, 'pluginfile.php', $context->id, 'mod_'.$module, 'intro', null);
|
||||
return trim(format_text($intro, $activity->introformat, $options));
|
||||
return trim(format_text($intro, $activity->introformat, $options, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1437,8 +1421,6 @@ function trusttext_active() {
|
||||
* Given raw text (eg typed in by a user), this function cleans it up
|
||||
* and removes any nasty tags that could mess up Moodle pages.
|
||||
*
|
||||
* @uses FORMAT_MOODLE
|
||||
* @uses FORMAT_PLAIN
|
||||
* @global string
|
||||
* @global object
|
||||
* @param string $text The text to be cleaned
|
||||
@ -1446,8 +1428,7 @@ function trusttext_active() {
|
||||
* [FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN]
|
||||
* @return string The cleaned up text
|
||||
*/
|
||||
function clean_text($text, $format=FORMAT_MOODLE) {
|
||||
|
||||
function clean_text($text, $format = FORMAT_MOODLE) {
|
||||
global $ALLOWED_TAGS, $CFG;
|
||||
|
||||
if (empty($text) or is_numeric($text)) {
|
||||
|
@ -2596,7 +2596,7 @@ function forum_get_discussions_unread($cm) {
|
||||
|
||||
$now = round(time(), -2);
|
||||
$cutoffdate = $now - ($CFG->forum_oldpostdays*24*60*60);
|
||||
|
||||
|
||||
$params = array();
|
||||
$groupmode = groups_get_activity_groupmode($cm);
|
||||
$currentgroup = groups_get_activity_group($cm);
|
||||
@ -3810,7 +3810,7 @@ function forum_print_attachments($post, $cm, $type) {
|
||||
}
|
||||
} else {
|
||||
$output .= "<a href=\"$path\">$iconimage</a> ";
|
||||
$output .= filter_text("<a href=\"$path\">".s($filename)."</a>");
|
||||
$output .= format_text("<a href=\"$path\">".s($filename)."</a>", FORMAT_HTML, array('context'=>$context));
|
||||
if ($canexport) {
|
||||
$button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php');
|
||||
$button->set_format_by_file($file);
|
||||
|
@ -1329,7 +1329,7 @@ function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") {
|
||||
$imagereturn .= "<br /><img src=\"$path\" alt=\"\" />";
|
||||
} else {
|
||||
$output .= "<a href=\"$path\">$iconimage</a> ";
|
||||
$output .= filter_text("<a href=\"$path\">".s($filename)."</a>");
|
||||
$output .= format_text("<a href=\"$path\">".s($filename)."</a>", FORMAT_HTML, array('context'=>$context));
|
||||
$output .= '<br />';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user