diff --git a/blog/lib.php b/blog/lib.php
index b14644e4a98bb..df07ae49d7d80 100755
--- a/blog/lib.php
+++ b/blog/lib.php
@@ -15,7 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
/**
* 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
*/
diff --git a/blog/locallib.php b/blog/locallib.php
index 99aa225f31f2d..6e92068ff9e5c 100644
--- a/blog/locallib.php
+++ b/blog/locallib.php
@@ -15,7 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
/**
* 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 @@ public function print_html($return=false) {
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 @@ public function print_html($return=false) {
$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 @@ public function print_attachments($return=false) {
$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 @@ public function print_attachments($return=false) {
$imagereturn .= "
" . $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));
}
}
}
diff --git a/filter/activitynames/filter.php b/filter/activitynames/filter.php
index 35cd7a299a7f6..e4bf1f102898b 100644
--- a/filter/activitynames/filter.php
+++ b/filter/activitynames/filter.php
@@ -1,9 +1,36 @@
.
+
+/**
+ * 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 @@ function filter($text) {
$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 @@ function filter($text) {
//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;
}
diff --git a/filter/algebra/algebradebug.php b/filter/algebra/algebradebug.php
index 5f2c195c08015..05853b42a13d1 100644
--- a/filter/algebra/algebradebug.php
+++ b/filter/algebra/algebradebug.php
@@ -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) {
diff --git a/filter/algebra/filter.php b/filter/algebra/filter.php
index aa66f4abebb3f..c913b245ba1f7 100644
--- a/filter/algebra/filter.php
+++ b/filter/algebra/filter.php
@@ -1,26 +1,33 @@
-.
+
+/**
+ * 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 ... 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 @@ function filter($text){
$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],"Undetermined error: ",$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;
diff --git a/filter/algebra/pix.php b/filter/algebra/pix.php
index 063da52e0314f..a4f58435d5fab 100644
--- a/filter/algebra/pix.php
+++ b/filter/algebra/pix.php
@@ -42,7 +42,7 @@
$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);
}
}
diff --git a/filter/censor/filter.php b/filter/censor/filter.php
index 8466e57e9e82b..a458ae70c2f2f 100644
--- a/filter/censor/filter.php
+++ b/filter/censor/filter.php
@@ -1,4 +1,34 @@
.
+
+/**
+ * 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 @@ function hash(){
}
return $cap;
}
+
function filter($text){
static $words;
global $CFG;
diff --git a/filter/emailprotect/filter.php b/filter/emailprotect/filter.php
index bd0ceb021e61d..a8d266f0605d9 100644
--- a/filter/emailprotect/filter.php
+++ b/filter/emailprotect/filter.php
@@ -1,9 +1,36 @@
.
+
+/**
+ * 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 @@ function filter($text) {
/// pattern to find a mailto link with the linked text.
$pattern = '|()'.'(.*)'.'()|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]);
}
diff --git a/filter/local_settings_form.php b/filter/local_settings_form.php
index 17aedba47fad0..7c67b9fbdbcb5 100644
--- a/filter/local_settings_form.php
+++ b/filter/local_settings_form.php
@@ -1,37 +1,28 @@
.
/**
* 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 @@ public function __construct($submiturl, $filter, $context) {
* 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);
diff --git a/filter/manage.php b/filter/manage.php
index 4f02641b44664..7df6d709c5d6c 100644
--- a/filter/manage.php
+++ b/filter/manage.php
@@ -1,34 +1,27 @@
.
/**
* 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');
diff --git a/filter/mediaplugin/db/install.php b/filter/mediaplugin/db/install.php
index f1e08f6a2d9d5..d2c99b48c0a12 100644
--- a/filter/mediaplugin/db/install.php
+++ b/filter/mediaplugin/db/install.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() {
diff --git a/filter/mediaplugin/filter.php b/filter/mediaplugin/filter.php
index 4058cd64d4d35..837583248d7e1 100644
--- a/filter/mediaplugin/filter.php
+++ b/filter/mediaplugin/filter.php
@@ -1,23 +1,37 @@
.
+
+/**
+ * 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
+ */
-/// This is the filtering function itself. It accepts the
-/// courseid and the text to be filtered (in HTML form).
+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 @@ function filter($text) {
if ($CFG->filter_mediaplugin_enable_mp3) {
$search = '/]*>.*?<\/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>/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>/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>/is';
- $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
+ $newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
$search = '/]*>.*?<\/a>/is';
- $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
+ $newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
$search = '/]*>.*?<\/a>/is';
- $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
+ $newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
$search = '/]*>.*?<\/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>/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>/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>/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>/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>/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>/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>/is';
- $newtext = preg_replace_callback($search, 'mediaplugin_filter_youtube_callback', $newtext);
+ $newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_callback', $newtext);
$search = '/]*>(.*?)<\/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>/is';
- $newtext = preg_replace_callback($search, 'mediaplugin_filter_img_callback', $newtext);
+ $newtext = preg_replace_callback($search, 'filter_mediaplugin_img_callback', $newtext);
$search = '/]*>(.*?)<\/a>/is';
- $newtext = preg_replace_callback($search, 'mediaplugin_filter_img_callback', $newtext);
+ $newtext = preg_replace_callback($search, 'filter_mediaplugin_img_callback', $newtext);
$search = '/]*>(.*?)<\/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 @@ function filter($text) {
///===========================
/// 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].'('.get_string('flashanimation', 'filter_mediaplugin').')'.$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 @@ function mediaplugin_filter_real_callback($link, $autostart=false) {
/**
* 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 @@ class="mediaplugin mediaplugin_youtube" type="application/x-shockwave-flash"
/**
* 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) {
';
}
-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"';
diff --git a/filter/mediaplugin/filtersettings.php b/filter/mediaplugin/filtersettings.php
index 42e38791e5600..86cee95a2dc13 100644
--- a/filter/mediaplugin/filtersettings.php
+++ b/filter/mediaplugin/filtersettings.php
@@ -6,7 +6,7 @@
$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));
diff --git a/filter/mediaplugin/version.php b/filter/mediaplugin/version.php
index 907733d357767..283afd70c52a6 100644
--- a/filter/mediaplugin/version.php
+++ b/filter/mediaplugin/version.php
@@ -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;
diff --git a/filter/multilang/filter.php b/filter/multilang/filter.php
index adf5b31ff8950..d2a237239d84b 100644
--- a/filter/multilang/filter.php
+++ b/filter/multilang/filter.php
@@ -1,26 +1,29 @@
//
-// Eloy Lafuente //
-// //
-// 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 .
+
+/**
+ * @package filter
+ * @subpackage multilang
+ * @copyright Gaetan Frenoy
+ * @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:
// one langanother language
-class multilang_filter extends moodle_text_filter {
+class filter_multilang extends moodle_text_filter {
function filter($text) {
global $CFG;
@@ -57,7 +60,7 @@ function filter($text) {
$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 @@ function filter($text) {
}
}
-function multilang_filter_impl($langblock) {
+function filter_multilang_impl($langblock) {
global $CFG;
$mylang = current_language();
diff --git a/filter/tex/db/install.php b/filter/tex/db/install.php
new file mode 100644
index 0000000000000..c0b030ad4e73c
--- /dev/null
+++ b/filter/tex/db/install.php
@@ -0,0 +1,35 @@
+.
+
+/**
+ * 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);
+}
+
diff --git a/filter/tex/filter.php b/filter/tex/filter.php
index 3992a61499735..5287b4bf69e41 100644
--- a/filter/tex/filter.php
+++ b/filter/tex/filter.php
@@ -1,25 +1,29 @@
-.
+
+/**
+ * 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 ... 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 @@ function filter ($text) {
$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;
}
diff --git a/filter/tex/latex.php b/filter/tex/latex.php
index 4deb513b16463..442ae32882e34 100644
--- a/filter/tex/latex.php
+++ b/filter/tex/latex.php
@@ -46,7 +46,7 @@ function supported() {
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";
diff --git a/filter/tex/lib.php b/filter/tex/lib.php
index a2cb6d1cc4a68..a0b7d1c51cc10 100644
--- a/filter/tex/lib.php
+++ b/filter/tex/lib.php
@@ -1,6 +1,8 @@
"
@@ -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))) {
diff --git a/filter/tex/pix.php b/filter/tex/pix.php
index c01e884827c44..45b1b79b6731f 100644
--- a/filter/tex/pix.php
+++ b/filter/tex/pix.php
@@ -55,7 +55,7 @@
$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);
}
}
diff --git a/filter/tex/texdebug.php b/filter/tex/texdebug.php
index eace9122bb0ef..30bc12c616b55 100644
--- a/filter/tex/texdebug.php
+++ b/filter/tex/texdebug.php
@@ -129,8 +129,8 @@ function tex2image($texexp, $return=false) {
}
$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) {
diff --git a/filter/tex/version.php b/filter/tex/version.php
new file mode 100644
index 0000000000000..d7ceba5cdd026
--- /dev/null
+++ b/filter/tex/version.php
@@ -0,0 +1,29 @@
+.
+
+/**
+ * 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;
diff --git a/filter/tidy/filter.php b/filter/tidy/filter.php
index c57fc14e90a91..f38d3a19d3d1f 100644
--- a/filter/tidy/filter.php
+++ b/filter/tidy/filter.php
@@ -1,5 +1,31 @@
.
+
+/**
+ * HTML tidy text filter.
+ *
+ * @package filter
+ * @subpackage tiny
+ * @copyright 2004 Hannes Gassert
+ * @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
- * @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
diff --git a/lib/accesslib.php b/lib/accesslib.php
index 325ebccdf435d..3ada12662b3d2 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -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 //
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php
index 860557947da3a..1993b7f1a1324 100644
--- a/lib/db/upgrade.php
+++ b/lib/db/upgrade.php
@@ -1283,13 +1283,6 @@ function xmldb_main_upgrade($oldversion) {
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
diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php
index 4f052c31f698d..6578b6e46a8a7 100644
--- a/lib/deprecatedlib.php
+++ b/lib/deprecatedlib.php
@@ -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.
*
diff --git a/lib/filterlib.php b/lib/filterlib.php
index d6cc68b5faa48..559dbebdef172 100644
--- a/lib/filterlib.php
+++ b/lib/filterlib.php
@@ -35,6 +35,14 @@
/** 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 @@
*
* 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 @@ protected function __construct() {
}
/**
- * @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 @@ public static function instance() {
* 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 @@ protected function load_filters($context, $courseid) {
/**
* 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 @@ protected function make_filter_object($filtername, $context, $courseid, $localco
}
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 @@ protected function apply_filter_chain($text, $filterchain) {
/**
* @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 @@ protected function get_text_filters($context, $courseid) {
/**
* @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 @@ protected function get_string_filters($context, $courseid) {
*
* @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));
/// tags removed for XHTML compatibility
$text = str_replace(array('', ''), '', $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 @@ public function text_filtering_hash($context, $courseid) {
*
* @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 @@ public function text_filtering_hash() {
*
* @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 @@ public function get_performance_summary() {
* 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 @@ public abstract function filter($text);
* 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 @@ public function __construct($filterfunction, $courseid, $context, array $localco
* @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='',
- $hreftagend='',
- $casesensitive=false,
- $fullmatch=false,
- $replacementphrase=NULL) {
+ function filterobject($phrase, $hreftagbegin = '',
+ $hreftagend = '',
+ $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 ... 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
*/
diff --git a/lib/weblib.php b/lib/weblib.php
index 62689d1709808..b9be816b69ced 100644
--- a/lib/weblib.php
+++ b/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 (!isset($options['newlines'])) {
+ $options['newlines'] = true;
}
- if (empty($courseid)) {
- $courseid = $COURSE->id;
+
+ // 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) {
+ 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)) {
diff --git a/mod/forum/lib.php b/mod/forum/lib.php
index 4edacf067fcfd..871a9df4727de 100644
--- a/mod/forum/lib.php
+++ b/mod/forum/lib.php
@@ -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 .= "$iconimage ";
- $output .= filter_text("".s($filename)."");
+ $output .= format_text("".s($filename)."", 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);
diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php
index e8b745ebbdcb4..8ba490c20470c 100644
--- a/mod/glossary/lib.php
+++ b/mod/glossary/lib.php
@@ -1329,7 +1329,7 @@ function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") {
$imagereturn .= "
";
} else {
$output .= "$iconimage ";
- $output .= filter_text("".s($filename)."");
+ $output .= format_text("".s($filename)."", FORMAT_HTML, array('context'=>$context));
$output .= '
';
}
}