Commit 48820bf4 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Remove HTML filters from site options; add page to read new filters from disk

parent 60724ec0
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 3 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configextensions/filters');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('htmlfilters', 'admin'));
if ($filters = get_config('filters')) {
$filters = unserialize($filters);
}
else {
$filters = array();
}
$reloadform = pieform(array(
'name' => 'reloadfilters',
'renderer' => 'table',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'reload' => array(
'type' => 'submit',
'value' => get_string('install', 'admin'),
),
),
));
function reloadfilters_submit(Pieform $form, $values) {
global $SESSION;
require_once(get_config('libroot') . 'upgrade.php');
reload_html_filters();
$SESSION->add_ok_msg(get_string('filtersinstalled', 'admin'));
redirect(get_config('wwwroot') . 'admin/extensions/filter.php');
}
$smarty = smarty();
$smarty->assign('reloadform', $reloadform);
$smarty->assign('newfiltersdescription', get_string('newfiltersdescription', 'admin', get_config('libroot') . 'htmlpurifiercustom'));
$smarty->assign('filters', $filters);
$smarty->display('admin/extensions/filters.tpl');
?>
...@@ -38,15 +38,6 @@ $themeoptions = get_themes(); ...@@ -38,15 +38,6 @@ $themeoptions = get_themes();
$yesno = array(true => get_string('yes'), $yesno = array(true => get_string('yes'),
false => get_string('no')); false => get_string('no'));
$allowedfilters = array('YouTube', 'GoogleVideo', 'TeacherTube', 'SciVee', 'Skype', 'Twitter'); //@todo read from the htmlpurifiercustom directory
$enabledfilters = get_config('filters');
if ($enabledfilters) {
$enabledfilters = unserialize($enabledfilters);
}
else {
$enabledfilters = array();
}
$searchpluginoptions = get_search_plugins(); $searchpluginoptions = get_search_plugins();
$siteoptionform = array( $siteoptionform = array(
...@@ -171,52 +162,6 @@ $siteoptionform = array( ...@@ -171,52 +162,6 @@ $siteoptionform = array(
) )
); );
// List of HTML Purifier filters to enable
$siteoptionform['elements']['filters'] = array(
'type' => 'fieldset',
'legend' => get_string('embeddedcontent', 'admin'),
'collapsible' => true,
'collapsed' => true,
'elements' => array(
'embeddedcontentdescription' => array(
'type' => 'html',
'title' => get_string('trustedsites', 'admin'),
'value' => get_string('embeddedcontentdescription', 'admin'),
'help' => true,
),
'YouTube' => array(
'type' => 'checkbox',
'title' => 'http://www.youtube.com',
'defaultvalue' => in_array('YouTube', $enabledfilters),
),
'GoogleVideo' => array(
'type' => 'checkbox',
'title' => 'http://video.google.com',
'defaultvalue' => in_array('GoogleVideo', $enabledfilters),
),
'TeacherTube' => array(
'type' => 'checkbox',
'title' => 'http://www.teachertube.com',
'defaultvalue' => in_array('TeacherTube', $enabledfilters),
),
'SciVee' => array(
'type' => 'checkbox',
'title' => 'http://www.scivee.tv',
'defaultvalue' => in_array('SciVee', $enabledfilters),
),
'Skype' => array(
'type' => 'checkbox',
'title' => 'http://skype.com',
'defaultvalue' => in_array('Skype', $enabledfilters),
),
'Twitter' => array(
'type' => 'checkbox',
'title' => 'http://twitter.com',
'defaultvalue' => in_array('Twitter', $enabledfilters),
),
),
);
$siteoptionform['elements']['submit'] = array( $siteoptionform['elements']['submit'] = array(
'type' => 'submit', 'type' => 'submit',
'value' => get_string('updatesiteoptions', 'admin') 'value' => get_string('updatesiteoptions', 'admin')
...@@ -232,7 +177,6 @@ function siteoptions_fail(Pieform $form, $field) { ...@@ -232,7 +177,6 @@ function siteoptions_fail(Pieform $form, $field) {
} }
function siteoptions_submit(Pieform $form, $values) { function siteoptions_submit(Pieform $form, $values) {
global $allowedfilters;
$fields = array('sitename','lang','theme', 'pathtoclam', $fields = array('sitename','lang','theme', 'pathtoclam',
'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn', 'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
'allowpublicviews', 'allowpublicprofiles', 'createpublicgroups', 'searchplugin'); 'allowpublicviews', 'allowpublicprofiles', 'createpublicgroups', 'searchplugin');
...@@ -258,16 +202,7 @@ function siteoptions_submit(Pieform $form, $values) { ...@@ -258,16 +202,7 @@ function siteoptions_submit(Pieform $form, $values) {
siteoptions_fail($form, $checkbox); siteoptions_fail($form, $checkbox);
} }
} }
// List of filters for HTMLPurifier
$enabledfilters = array();
foreach ($allowedfilters as $filter) {
if ($values[$filter] == 'on') {
$enabledfilters[] = $filter;
}
}
if (!set_config('filters', serialize($enabledfilters))) {
siteoptions_fail($form, 'filters');
}
$message = get_string('siteoptionsset', 'admin'); $message = get_string('siteoptionsset', 'admin');
if ($oldtheme != $values['theme']) { if ($oldtheme != $values['theme']) {
$message .= ' ' . get_string('usersseenewthemeonlogin', 'admin'); $message .= ' ' . get_string('usersseenewthemeonlogin', 'admin');
......
...@@ -105,6 +105,12 @@ $string['institutionfilesdescription'] = 'Upload and manage files for use in Ins ...@@ -105,6 +105,12 @@ $string['institutionfilesdescription'] = 'Upload and manage files for use in Ins
$string['pluginadmin'] = 'Plugin Administration'; $string['pluginadmin'] = 'Plugin Administration';
$string['pluginadmindescription'] = 'Install and configure plugins'; $string['pluginadmindescription'] = 'Install and configure plugins';
$string['htmlfilters'] = 'HTML Filters';
$string['htmlfiltersdescription'] = 'Enable new filters for HTML Purifier';
$string['newfiltersdescription'] = 'If you have downloaded a new set of HTML filters, you can install them by unzipping the file into the folder %s and then clicking the button below';
$string['filtersinstalled'] = 'Filters installed.';
$string['nofiltersinstalled'] = 'No html filters installed.';
// Site options // Site options
$string['adminsonly'] = 'Administrators only'; $string['adminsonly'] = 'Administrators only';
$string['allowpublicviews'] = 'Allow public views'; $string['allowpublicviews'] = 'Allow public views';
......
<?xml version="1.0" encoding="UTF-8" ?>
<filters>
<filter>
<filename>GoogleVideo</filename>
<site>http://video.google.com</site>
</filter>
<filter>
<filename>TeacherTube</filename>
<site>http://www.teachertube.com</site>
</filter>
<filter>
<filename>SciVee</filename>
<site>http://www.scivee.tv</site>
</filter>
<filter>
<filename>Skype</filename>
<site>http://skype.com</site>
</filter>
<filter>
<filename>Twitter</filename>
<site>http://twitter.com</site>
</filter>
</filters>
...@@ -956,4 +956,24 @@ function install_view_column_widths() { ...@@ -956,4 +956,24 @@ function install_view_column_widths() {
db_commit(); db_commit();
} }
/**
* Reload htmlpurifier filters from the XML configuration file.
*/
function reload_html_filters() {
require_once('xmlize.php');
log_info('Reading HTML filters');
$newlist = xmlize(file_get_contents(get_config('libroot') . 'htmlpurifiercustom/filters.xml'));
$filters = $newlist['filters']['#']['filter'];
foreach ($filters as &$f) {
$f = (object) array(
'site' => $f['#']['site'][0]['#'],
'file' => $f['#']['filename'][0]['#']
);
log_info('- ' . $f->file);
}
$filters[] = (object) array('site' => 'http://www.youtube.com', 'file' => 'YouTube');
log_info('- YouTube');
set_config('filters', serialize($filters));
}
?> ?>
...@@ -1567,6 +1567,12 @@ function admin_nav() { ...@@ -1567,6 +1567,12 @@ function admin_nav() {
'title' => get_string('pluginadmin', 'admin'), 'title' => get_string('pluginadmin', 'admin'),
'weight' => 10, 'weight' => 10,
), ),
array(
'path' => 'configextensions/filters',
'url' => 'admin/extensions/filter.php',
'title' => get_string('htmlfilters', 'admin'),
'weight' => 20,
),
); );
return $menu; return $menu;
...@@ -2150,11 +2156,11 @@ function clean_html($text) { ...@@ -2150,11 +2156,11 @@ function clean_html($text) {
$customfilters = array(); $customfilters = array();
if (get_config('filters')) { if (get_config('filters')) {
foreach (unserialize(get_config('filters')) as $filter) { foreach (unserialize(get_config('filters')) as $filter) {
if ($filter == 'YouTube') { if ($filter->file == 'YouTube') {
$config->set('Filter', 'YouTube', true); $config->set('Filter', 'YouTube', true);
} else { } else {
require_once(get_config('libroot') . 'htmlpurifiercustom/' . $filter . '.php'); require_once(get_config('libroot') . 'htmlpurifiercustom/' . $filter->file . '.php');
$classname = 'HTMLPurifier_Filter_' . $filter; $classname = 'HTMLPurifier_Filter_' . $filter->file;
$customfilters[] = new $classname(); $customfilters[] = new $classname();
} }
} }
......
{include file='header.tpl'}
{include file="columnfullstart.tpl"}
<h2>{$heading}</h2>
<p>{str tag=htmlfiltersdescription section=admin}</p>
{if $filters}
<h3>{str tag=installed section=admin}:</h3>
<ul>
{foreach from=$filters item=filter}
<li>{$filter->site}</li>
{/foreach}
</ul>
{else}
<p>{str tag=nofiltersinstalled section=admin}</p>
{/if}
<p>{$newfiltersdescription}</p>
<div>{$reloadform}</div>
{include file="columnfullend.tpl"}
{include file='footer.tpl'}
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
<li><h3>{str tag=configextensions section=admin}</h3> <li><h3>{str tag=configextensions section=admin}</h3>
<ul> <ul>
<li><strong><a href="{$WWWROOT}admin/extensions/plugins.php">{str tag=pluginadmin section=admin}</a></strong> - {str tag=pluginadmindescription section=admin}</li> <li><strong><a href="{$WWWROOT}admin/extensions/plugins.php">{str tag=pluginadmin section=admin}</a></strong> - {str tag=pluginadmindescription section=admin}</li>
<li><strong><a href="{$WWWROOT}admin/extensions/filter.php">{str tag=htmlfilters section=admin}</a></strong> - {str tag=htmlfiltersdescription section=admin}</li>
</ul> </ul>
</li> </li>
</ul></div> </ul></div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment