summaryrefslogtreecommitdiff
path: root/plugindata.php
blob: 58c5bacda9e26094cfc253e3c2bc61e1dcd0715e (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
<?php
/**
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2010 Free Software Foundation, Inc
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category StatusNet
 * @package  StatusNet
 * @author   Luke Shumaker <lukeshu@sbcglobal.net>
 * @copyright 2010 Free Software Foundation, Inc http://www.fsf.org
 *
 * @license  GNU Affero General Public License http://www.gnu.org/licenses/
 */

require('include.php');

function main() {
    // Check permissions

    if (!common_logged_in()) {
        // TRANS: Client error message thrown when trying to load plugin data while not logged in.
        echo(_('Not logged in.')."\n");
        return false;
    }
    $user = common_current_user();
    assert(!empty($user));
    if (!$user->hasRight(Right::CONFIGURESITE)) {
        // TRANS: Client error message thrown when a user tries to load plugin data but has no access rights.
        echo(_('You cannot make changes to this site.')."\n");
        return false;
    }

    // Do stuff
    
    $possibleFiles = StatusNet::pluginFiles('*');
    foreach ($possibleFiles as $pattern) {
        $regex = '/'.str_replace('/','\/',str_replace('*','(.*)',$pattern)).'/';
        $matches = glob($pattern);
        foreach ($matches as $file) {
            $name = preg_replace($regex,'\1',$file);
            loadPlugin($name,$file,$data);
        }
    }
    $redirect = isset($_SERVER['HTTP_REFERER']);

    $fileName = 'plugindata.out.php';
    $fh = fopen($fileName, 'w');
    if (!$fh) {
        $redirect = false;
        // TRANS: Client error message thrown when plugindata.out.php can't be opened
        echo(_("ERROR: cannot open 'plugindata.out.php' for writing.")."\n");
    }
    fwrite($fh, "<?php\n".
                "function common_plugindata() {\n".
                "    return ".var_export($data,true).";\n".
                "}\n"
          );
    fclose($fh);
    if ($redirect) {
        header('Location: '.$_SERVER['HTTP_REFERER']);
    } else {
        header('Content-type: text/plain');
        // TRANS: Plain text divider between mesages and plugin data.
        echo("\n"._('---- Raw Plugin Data ----')."\n\n");
        var_export($data);
    }
}

function loadPlugin($pluginName,$file,&$data) {
    if (!class_exists($pluginName.'Plugin')) {
        if (@file_exists($file)) {
            include_once($file);
        }
    }
    if (class_exists($pluginName.'Plugin')) {
        $className = $pluginName.'Plugin';
        $obj = new $className;

        $newData = array();
        $obj->onPluginVersion($newData);
        foreach ($newData as $pluginInfo) {
            $data[$pluginName] = $pluginInfo;
        }
    }
}

main();