Commit aa9619cb authored by Penny Leach's avatar Penny Leach Committed by Richard Mansfield
Browse files

first cut at being able to enable and disable plugins.

NEEDS TESTING!!!
parent 1dfa95f9
......@@ -39,6 +39,23 @@ define('SECTION_PLUGINNAME', $pluginname);
define('SECTION_PAGE', 'pluginconfig');
safe_require($plugintype, $pluginname);
if ($sesskey = param_alphanum('sesskey', '')) {
if ($sesskey != $USER->get('sesskey')) {
throw new UserException('Invalid sesskey');
}
}
$enable = param_integer('enable', 0);
$disable = param_integer('disable', 0);
if ($enable || $disable) {
if ($plugintype == 'blocktype') {
$pluginname = blocktype_namespaced_to_single($pluginname);
}
set_field($plugintype . '_installed', 'active', $enable, 'name', $pluginname);
$SESSION->add_ok_msg(get_string('plugin' . (($enable) ? 'enabled' : 'disabled')));
redirect('/admin/extensions/plugins.php');
}
if ($plugintype == 'artefact') {
$type = param_alpha('type');
$classname = generate_artefact_class_name($type);
......
......@@ -48,13 +48,13 @@ foreach (plugin_types() as $plugin) {
}
foreach (array_keys($plugins) as $plugin) {
if (table_exists(new XMLDBTable($plugin . '_installed'))) {
if ($installed = get_records_array($plugin . '_installed')) {
if ($installed = plugins_installed($plugin, true)) {
foreach ($installed as $i) {
$key = $i->name;
if ($plugin == 'blocktype') {
$key = blocktype_single_to_namespaced($i->name, $i->artefactplugin);
}
$plugins[$plugin]['installed'][$key] = array();
$plugins[$plugin]['installed'][$key] = array('active' => $i->active);
if ($plugin == 'artefact') {
$plugins[$plugin]['installed'][$key]['types'] = array();
safe_require('artefact', $key);
......
......@@ -156,7 +156,7 @@ abstract class PluginBlocktype extends Plugin {
$sql = 'SELECT bti.name, bti.artefactplugin
FROM {blocktype_installed} bti
JOIN {blocktype_installed_category} btic ON btic.blocktype = bti.name
WHERE btic.category = ?
WHERE btic.category = ? AND bti.active = 1
ORDER BY bti.name';
if (!$bts = get_records_sql_array($sql, array($category))) {
return false;
......
......@@ -57,6 +57,11 @@ $string['From'] = 'From';
$string['To'] = 'To';
$string['All'] = 'All';
$string['enable'] = 'Enable';
$string['disable'] = 'Disable';
$string['pluginenabled'] = 'Plugin enabled';
$string['plugindisabled'] = 'Plugin disabled';
$string['next'] = 'Next';
$string['nextpage'] = 'Next page';
$string['previous'] = 'Previous';
......
......@@ -961,10 +961,14 @@ function plugin_types_installed() {
* @param string $plugintype type of plugin
*/
function plugins_installed($plugintype, $all=false) {
$sort = 'name';
if ($plugintype == 'blocktype') {
$sort = 'artefactplugin,name';
}
if ($all) {
return get_records_array($plugintype . '_installed');
return get_records_array($plugintype . '_installed', '', '', $sort);
}
return get_records_array($plugintype . '_installed', 'active', 1);
return get_records_array($plugintype . '_installed', 'active', 1, $sort);
}
/**
......
......@@ -702,7 +702,9 @@ class View {
require_once(get_config('docroot') . '/blocktype/lib.php');
$categories = array();
foreach (get_records_array('blocktype_installed_category') as $blocktypecategory) {
$sql = 'SELECT bic.* FROM {blocktype_installed_category} bic
JOIN {blocktype_installed} bi ON bic.blocktype = bi.name WHERE bi.active = 1';
foreach (get_records_sql_array($sql, array()) as $blocktypecategory) {
safe_require('blocktype', $blocktypecategory->blocktype);
if (call_static_method(generate_class_name("blocktype", $blocktypecategory->blocktype), "allowed_in_view", $this)) {
if (!isset($categories[$blocktypecategory->category])) {
......@@ -1016,6 +1018,11 @@ class View {
public function build_column($column, $editing=false) {
global $USER;
$data = $this->get_column_datastructure($column);
static $installed = array();
if (empty($installed)) {
$installed = plugins_installed('blocktype');
$installed = array_map(create_function('$a', 'return $a->name;'), $installed);
}
if ($editing) {
$renderfunction = 'render_editing';
......@@ -1025,6 +1032,9 @@ class View {
}
$blockcontent = '';
foreach($data['blockinstances'] as $blockinstance) {
if (!in_array($blockinstance->get('blocktype'), $installed)) {
continue; // this plugin has been disabled
}
$configure = ($blockinstance->get('id') == $this->blockinstance_currently_being_configured);
$result = $blockinstance->$renderfunction($configure, false);
if ($editing) {
......
......@@ -13,14 +13,22 @@
<ul id="{$plugintype}.installed">
{foreach from=$installed key='plugin' item='data'}
<li id="{$plugintype}.{$plugin}">{$plugin}
{if $plugin != 'internal'}
{if $data.active}
[ <a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}&amp;disable=1&amp;sesskey={$SESSKEY}">{str tag='disable'}</a>
{else}
[ <a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}&amp;enable=1&amp;sesskey={$SESSKEY}">{str tag='enable'}</a>
{/if}
{/if}
{if $data.config}
(<a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}">{str tag='config'}</a>)
{/if}</li>
{if $plugin == 'internal'} [ {else} | {/if}
<a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}">{str tag='config'}</a>
{/if} {if $data.config || $plugin != 'internal'} ] {/if} </li>
{if $data.types}
<ul>
{foreach from=$data.types key='type' item='config'}
<li>{$type}
{if $config} (<a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}&amp;type={$type}">{str tag='config'}</a>){/if}</li>
{if $config} [ <a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}&amp;type={$type}">{str tag='config'}</a> ]{/if}</li>
{/foreach}
</ul>
{/if}
......
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