summaryrefslogtreecommitdiffstats
path: root/admin/plugins.php
blob: 81b4df8fc75a75976c28903f0eaa7dfd6f03a074 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/******************************
 * EQdkp
 * Copyright 2002-2003
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * plugins.php
 * Began: Mon January 13 2003
 * 
 * $Id: plugins.php 46 2007-06-19 07:29:11Z tsigo $
 * 
 ******************************/

define('EQDKP_INC', true);
define('IN_ADMIN', true);
$eqdkp_root_path = './../';
include_once($eqdkp_root_path . 'common.php');

$user->check_auth('a_plugins_man');

$mode = ( isset($_GET['mode']) ) ? $_GET['mode'] : 'list';
$code = ( isset($_GET['code']) ) ? $_GET['code'] : '';

if ( (!empty($code)) && (!is_dir($eqdkp_root_path . 'plugins/' . $code)) )
{
    message_die($user->lang['error_invalid_plugin']);
}

switch ( $mode )
{
    case 'install':
        $pm->install($code);
        $pm->do_hooks('/admin/plugins.php?mode=install');
        
        $plugin_object = $pm->get_plugin($code);
        $plugin_object->message(SQL_INSTALL);
        
        break;
    case 'uninstall':
        $pm->uninstall($code);
        $pm->do_hooks('/admin/plugins.php?mode=uninstall');
        
        $plugin_object = $pm->get_plugin($code);
        $plugin_object->message(SQL_UNINSTALL);
        
        break;
    case 'list':
        // Register any new plugins before we list the available ones
        $pm->register();
        
        $unset_array = array();
        $plugins_array = $pm->get_plugins(PLUGIN_ALL);
        foreach ( $plugins_array as $plugin_code => $plugin_object )
        {
            $installed = $pm->check(PLUGIN_INSTALLED, $plugin_code);
            
            // Initialize the object if we need to
            if ( !$pm->check(PLUGIN_INITIALIZED, $plugin_code) )
            {
                if ( $pm->initialize($plugin_code) )
                {
                    $unset_array[] = $plugin_code;
                }
            }
            
            $contact = $pm->get_data($plugin_code, 'contact');
            $version = $pm->get_data($plugin_code, 'version');
            
            $tpl->assign_block_vars('plugins_row', array(
                'ROW_CLASS' => $eqdkp->switch_row_class(),
                'NAME'      => $pm->get_data($plugin_code, 'name'),
                'CODE'      => $plugin_code,
                'VERSION'   => ( !empty($version) ) ? $version : '&nbsp;',
                'U_ACTION'  => 'plugins.php' . $SID . '&amp;mode=' . (( $installed ) ? 'uninstall' : 'install') . '&amp;code=' . $plugin_code,
                'ACTION'    => ( $installed ) ? $user->lang['uninstall'] : $user->lang['install'],
                'CONTACT'   => ( !is_null($contact) ) ? '<a href="mailto:' . $contact . '">' . $contact . '</a>' : '&nbsp;')
            );
            unset($contact, $installed, $version);
        }
        
        // Return uninitialized objects to their previous state
        foreach ( $unset_array as $plugin_code )
        {
            unset($pm->plugins[$plugin_code]);
        }
        
        $tpl->assign_vars(array(
            'L_NAME'    => $user->lang['name'],
            'L_CODE'    => $user->lang['code'],
            'L_VERSION' => $user->lang['version'],
            'L_ACTION'  => $user->lang['action'],
            'L_CONTACT' => $user->lang['contact'])
        );
        
        $eqdkp->set_vars(array(
            'page_title'    => sprintf($user->lang['admin_title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['plugins_title'],
            'template_file' => 'admin/plugins.html',
            'display'       => true)
        );
 
        break;
}
?>