~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to lib/tools/repository/PackagePlugin.inc

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * Gallery - a web based photo album viewer and editor
 
4
 * Copyright (C) 2000-2006 Bharat Mediratta
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or (at
 
9
 * your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 *
 
20
 * $Id: PackagePlugin.inc,v 1.4 2006/01/10 04:38:42 mindless Exp $
 
21
 */
 
22
 
 
23
GalleryCoreApi::requireOnce('lib/tools/repository/classes/RepositoryObject.class');
 
24
GalleryCoreApi::requireOnce('lib/tools/repository/classes/RepositoryDescriptor.class');
 
25
GalleryCoreApi::requireOnce('lib/tools/repository/classes/RepositoryPackage.class');
 
26
 
 
27
/**
 
28
 * Controller for the plugin packaging page.
 
29
 *
 
30
 * @author Jozef Selesi <selesi at gmail dot com>
 
31
 *
 
32
 * @version $Revision: 1.4 $ $Date: 2006/01/10 04:38:42 $
 
33
 * @package RepositoryTools
 
34
 * @subpackage Controllers
 
35
 * @module PackagePluginController
 
36
 */
 
37
class PackagePluginControllerAndView extends RepositoryControllerAndView {
 
38
 
 
39
    /**
 
40
     * Displays the available plugins that can be packaged.
 
41
     *
 
42
     * @return object GalleryStatus a status code
 
43
     */
 
44
    function showAvailablePlugins() {
 
45
        list ($ret, $plugins) = $this->getAvailablePluginList(array(
 
46
            'package' => array('controller' => 'PackagePlugin', 'action' => 'packagePlugin')));
 
47
        if ($ret) {
 
48
            return $ret->wrap(__FILE__, __LINE__);
 
49
        }
 
50
 
 
51
        $ret = $this->showView('PackagePlugin', array('plugins' => $plugins));
 
52
        if ($ret) {
 
53
            return $ret->wrap(__FILE__, __LINE__);
 
54
        }
 
55
 
 
56
        return null;
 
57
    }
 
58
 
 
59
    /**
 
60
     * Creates all packages for the selected plugin and displays a summary page when completed.
 
61
     *
 
62
     * @return object GalleryStatus a status code
 
63
     */
 
64
    function packagePlugin() {
 
65
        list ($pluginId, $pluginType) =
 
66
            GalleryUtilities::getRequestVariables('pluginId', 'pluginType');
 
67
 
 
68
        if (empty($pluginId) || empty($pluginType)) {
 
69
            return GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__,
 
70
                                        sprintf('pluginId [%s] and/or pluginType [%s] not set.',
 
71
                                                $pluginId, $pluginType));
 
72
        }
 
73
 
 
74
        list ($ret, $pluginInfo) = $this->doPackagePlugin($pluginType, $pluginId);
 
75
        if ($ret) {
 
76
            return $ret->wrap(__FILE__, __LINE__);
 
77
        }
 
78
 
 
79
        $ret = $this->showView('PackageResults', array('results' => array($pluginInfo)));
 
80
        if ($ret) {
 
81
            return $ret->wrap(__FILE__, __LINE__);
 
82
        }
 
83
 
 
84
        return null;
 
85
    }
 
86
 
 
87
    /**
 
88
     * Creates packages for all plugins that match the 'filter' request variable.
 
89
     *
 
90
     * @return object GalleryStatus a status code
 
91
     */
 
92
    function packagePlugins() {
 
93
        $pluginsPackaged = 0;
 
94
 
 
95
        /* Set default filter if none is provided. */
 
96
        $filter = GalleryUtilities::getRequestVariables('filter');
 
97
        if (strlen($filter) < 3) { /* Is there a check to see if a regexp is valid? */
 
98
            $filter = '/.*/';
 
99
        }
 
100
 
 
101
        list ($ret, $plugins) = $this->getAvailablePluginList(array());
 
102
        if ($ret) {
 
103
            return $ret->wrap(__FILE__, __LINE__);
 
104
        }
 
105
 
 
106
        foreach ($plugins as $pluginId => $plugin) {
 
107
            if (preg_match($filter, $pluginId)) {
 
108
                list ($ret, $pluginInfo) = $this->doPackagePlugin($plugin['type'], $pluginId);
 
109
                if ($ret) {
 
110
                    return $ret->wrap(__FILE__, __LINE__);
 
111
                }
 
112
                $packagedPluginList[] = $pluginInfo;
 
113
            }
 
114
        }
 
115
        $this->showView('PackageResults', array('results' => $packagedPluginList));
 
116
        return null;
 
117
    }
 
118
 
 
119
    /**
 
120
     * Creates all packages for the specified plugin.
 
121
     *
 
122
     * @return object GalleryStatus a status code
 
123
     */
 
124
    function doPackagePlugin($pluginType, $pluginId) {
 
125
        global $gallery;
 
126
        $outputDir = $gallery->getConfig('repository.path');
 
127
 
 
128
        list ($ret, $plugin) = GalleryCoreApi::loadPlugin($pluginType, $pluginId);
 
129
        if ($ret) {
 
130
            return array($ret->wrap(__FILE__, __LINE__), null);
 
131
        }
 
132
 
 
133
        $outputDir .= sprintf('%ss', $pluginType);
 
134
 
 
135
        $descriptor = new RepositoryDescriptor();
 
136
        $ret = $descriptor->init($outputDir);
 
137
        if ($ret) {
 
138
            return array($ret->wrap(__FILE__, __LINE__), null);
 
139
        }
 
140
 
 
141
        $ret = $descriptor->generate($plugin);
 
142
        if ($ret) {
 
143
            return array($ret->wrap(__FILE__, __LINE__), null);
 
144
        }
 
145
 
 
146
        $ret = $descriptor->writeToDisk();
 
147
        if ($ret) {
 
148
            return array($ret->wrap(__FILE__, __LINE__), null);
 
149
        }
 
150
 
 
151
        $package = new RepositoryPackage();
 
152
        $ret = $package->init($descriptor, $descriptor->getOutputDir());
 
153
        if ($ret) {
 
154
            return array($ret->wrap(__FILE__, __LINE__), null);
 
155
        }
 
156
 
 
157
        list ($ret, $packagesWritten) = $package->writeAllPackagesToDisk();
 
158
        if ($ret) {
 
159
            return array($ret->wrap(__FILE__, __LINE__), null);
 
160
        }
 
161
 
 
162
        $pluginInfo = array('pluginId' => $descriptor->getPluginId(),
 
163
                            'outputDir' => $descriptor->getOutputDir(),
 
164
                            'packageInfo' => $packagesWritten);
 
165
 
 
166
        return array(null, $pluginInfo);
 
167
    }
 
168
 
 
169
    /**
 
170
     * Creates a list of all existing plugins with optional action links.
 
171
     *
 
172
     * @param array 'action' => array(UrlGeneratorParameters)
 
173
     * @return array object GalleryStatus a status code
 
174
     *               array plugin list
 
175
     */
 
176
    function getAvailablePluginList($links) {
 
177
        global $gallery;
 
178
        $urlGenerator =& $gallery->getUrlGenerator();
 
179
        $data = array();
 
180
        $pluginTypes = array('module', 'theme');
 
181
 
 
182
        foreach ($pluginTypes as $pluginType) {
 
183
            list ($ret, $plugins) = GalleryCoreApi::fetchPluginStatus($pluginType, true);
 
184
            if ($ret) {
 
185
                return array($ret->wrap(__FILE__, __LINE__), null);
 
186
            }
 
187
 
 
188
            foreach ($plugins as $pluginId => $plugin) {
 
189
                $data[$pluginId]['type'] = $pluginType;
 
190
                $data[$pluginId]['active'] = isset($plugin['active']) ? 'active' : 'inactive';
 
191
                $data[$pluginId]['available'] = isset($plugin['available']) ? 'available'
 
192
                                                                            : 'unavailable';
 
193
 
 
194
                $pluginUrlParameters = array('pluginId' => $pluginId, 'pluginType' => $pluginType);
 
195
                foreach ($links as $link => $extraUrlParameters) {
 
196
                    $data[$pluginId]['links'][$link] =
 
197
                        $urlGenerator->generateUrl($extraUrlParameters + $pluginUrlParameters);
 
198
                }
 
199
            }
 
200
        }
 
201
 
 
202
        return array(null, $data);
 
203
    }
 
204
}
 
205
?>
 
 
b'\\ No newline at end of file'