plugins.php 5.42 KB
Newer Older
Penny Leach's avatar
Penny Leach committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
/**
 * This program is part of Mahara
 *
 *  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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 * @package    mahara
 * @subpackage admin
 * @author     Penny Leach <penny@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

define('INTERNAL', 1);
define('ADMIN', 1);
29
30
define('MENUITEM', 'configextensions');
define('SUBMENUITEM', 'pluginadmin');
Penny Leach's avatar
Penny Leach committed
31
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
Martyn Smith's avatar
Martyn Smith committed
32
define('TITLE', get_string('pluginadmin', 'admin'));
Penny Leach's avatar
Penny Leach committed
33
34
35
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'plugins');
36
require('upgrade.php');
Penny Leach's avatar
Penny Leach committed
37
38
39
40
41
42
43

$plugins = array();

foreach (plugin_types()  as $plugin) {
    $plugins[$plugin] = array();
    $plugins[$plugin]['installed'] = array();
    $plugins[$plugin]['notinstalled'] = array();
44
    if ($installed = get_records_array($plugin . '_installed')) {
Penny Leach's avatar
Penny Leach committed
45
46
47
48
        foreach ($installed as $i) {
            $plugins[$plugin]['installed'][$i->name] = array();
            if ($plugin == 'artefact') {
                $plugins[$plugin]['installed'][$i->name]['types'] = array();
49
50
51
52
53
54
55
56
57
58
59
                safe_require('artefact',$i->name);
                if ($types = call_static_method(generate_class_name('artefact', $i->name), 'get_artefact_types')) {
                    foreach ($types as $t) {
                        $classname = generate_artefact_class_name($t);
                        if ($collapseto = call_static_method($classname, 'collapse_config')) {
                            $plugins[$plugin]['installed'][$i->name]['types'][$collapseto] = true;
                        }
                        else {
                            $plugins[$plugin]['installed'][$i->name]['types'][$t] = 
                                call_static_method($classname, 'has_config');
                        }
Penny Leach's avatar
Penny Leach committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
                    }
                }
            } 
            else {
                $classname = generate_class_name($plugin, $i->name);
                safe_require($plugin, $i->name);
                if (call_static_method($classname, 'has_config')) {
                    $plugins[$plugin]['installed'][$i->name]['config'] = true;
                }
            }
        }
    }
    
    $dirhandle = opendir(get_config('docroot') . $plugin);
    while (false !== ($dir = readdir($dirhandle))) {
        if (strpos($dir, '.') === 0) {
            continue;
        }
        if (!is_dir(get_config('docroot') . $plugin . '/' . $dir)) {
            continue;
        }
        if (array_key_exists($dir, $plugins[$plugin]['installed'])) {
            continue;
        }
84
        $plugins[$plugin]['notinstalled'][$dir] = array();
85
        require_once('artefact.php');
86
87
88
89
90
91
92
93
94
        $funname = $plugin . '_check_plugin_sanity';
        if (function_exists($funname)) {
            try {
                $funname($dir);
            }
            catch (InstallationException $e) {
                $plugins[$plugin]['notinstalled'][$dir]['notinstallable'] = $e->GetMessage();
            }
        }
Penny Leach's avatar
Penny Leach committed
95
96
97
    }
}

98
99
100
$loadingicon = theme_get_url('images/loading.gif');
$successicon = theme_get_url('images/success.gif');
$failureicon = theme_get_url('images/failure.gif');
101

102
103
104
$loadingstring = json_encode(get_string('upgradeloading', 'admin'));
$successstring = json_encode(get_string('upgradesuccesstoversion', 'admin'));
$failurestring = json_encode(get_string('upgradefailure', 'admin'));
105
106
107
108

$javascript = <<<JAVASCRIPT

function installplugin(name) {
109
    $(name + '.message').innerHTML = '<img src="{$loadingicon}" alt=' + {$loadingstring} + '" />';
110

111
    sendjsonrequest('../upgrade.json.php', { 'name': name }, 'GET', function (data) {
Penny Leach's avatar
Penny Leach committed
112
        if (!data.error) {
113
            var message = {$successstring} + data.newversion;
Penny Leach's avatar
Penny Leach committed
114
            $(name + '.message').innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
115
            $(name + '.install').innerHTML = '';
Penny Leach's avatar
Penny Leach committed
116
117
118
119
120
            // move the whole thing into the list of installed plugins 
            // new parent node
            var bits = name.split('\.');
            var newparent = $(bits[0] + '.installed');
            appendChildNodes(newparent, $(name));
121
        }
Penny Leach's avatar
Penny Leach committed
122
        else {
123
            var message = '';
124
125
            if (data.errormessage) {
                message = data.errormessage;
126
127
            } 
            else {
128
                message = {$failurestring};
129
130
131
132
            }
            $(name).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
        }
    },
133
    function () {
134
        message = {$failurestring};
135
136
137
        $(name).innerHTML = message;
    },
    true);
138
139
140
141
}
JAVASCRIPT;


Penny Leach's avatar
Penny Leach committed
142
$smarty = smarty();
143
$smarty->assign('INLINEJAVASCRIPT', $javascript);
Penny Leach's avatar
Penny Leach committed
144
$smarty->assign('plugins', $plugins);
145
$smarty->assign('installlink', 'installplugin');
146
$smarty->display('admin/extensions/plugins.tpl');
Penny Leach's avatar
Penny Leach committed
147
148

?>