~ubuntu-branches/ubuntu/maverick/gallery2/maverick

« 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: 2007-09-10 20:22:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070910202219-0jsuntvqge4ade6b
Tags: 2.2.3-2
Add Slovak translation of Debconf templates.  (Thanks to 
Ivan Masá.  Closes: #441671)

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-2007 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., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
19
 
 */
20
 
 
21
 
GalleryCoreApi::requireOnce('lib/tools/repository/classes/RepositoryObject.class');
22
 
GalleryCoreApi::requireOnce('lib/tools/repository/classes/RepositoryDescriptor.class');
23
 
GalleryCoreApi::requireOnce('lib/tools/repository/classes/RepositoryPackage.class');
24
 
 
25
 
/**
26
 
 * Controller for the plugin packaging page.
27
 
 *
28
 
 * @author Jozef Selesi <selesi at gmail dot com>
29
 
 *
30
 
 * @version $Revision: 15513 $
31
 
 * @package RepositoryTools
32
 
 * @subpackage Controllers
33
 
 * @module PackagePluginController
34
 
 */
35
 
class PackagePluginControllerAndView extends RepositoryControllerAndView {
36
 
 
37
 
    /**
38
 
     * Displays the available plugins that can be packaged.
39
 
     *
40
 
     * @return object GalleryStatus a status code
41
 
     */
42
 
    function showAvailablePlugins() {
43
 
        list ($ret, $plugins) = $this->getAvailablePluginList(array(
44
 
            'package' => array('controller' => 'PackagePlugin', 'action' => 'packagePlugin')));
45
 
        if ($ret) {
46
 
            return $ret;
47
 
        }
48
 
 
49
 
        $ret = $this->showView('PackagePlugin', array('plugins' => $plugins));
50
 
        if ($ret) {
51
 
            return $ret;
52
 
        }
53
 
 
54
 
        return null;
55
 
    }
56
 
 
57
 
    /**
58
 
     * Creates all packages for the selected plugin and displays a summary page when completed.
59
 
     *
60
 
     * @return object GalleryStatus a status code
61
 
     */
62
 
    function packagePlugin() {
63
 
        list ($pluginId, $pluginType) =
64
 
            GalleryUtilities::getRequestVariables('pluginId', 'pluginType');
65
 
 
66
 
        if (empty($pluginId) || empty($pluginType)) {
67
 
            return GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__,
68
 
                                        sprintf('pluginId [%s] and/or pluginType [%s] not set.',
69
 
                                                $pluginId, $pluginType));
70
 
        }
71
 
 
72
 
        list ($ret, $pluginInfo) = $this->doPackagePlugin($pluginType, $pluginId);
73
 
        if ($ret) {
74
 
            return $ret;
75
 
        }
76
 
 
77
 
        $ret = $this->showView('PackageResults', array('results' => array($pluginInfo)));
78
 
        if ($ret) {
79
 
            return $ret;
80
 
        }
81
 
 
82
 
        return null;
83
 
    }
84
 
 
85
 
    /**
86
 
     * Creates packages for all plugins that match the 'filter' request variable.
87
 
     *
88
 
     * @return object GalleryStatus a status code
89
 
     */
90
 
    function packagePlugins() {
91
 
        global $gallery;
92
 
        $pluginsPackaged = 0;
93
 
 
94
 
        /* Set default filter if none is provided. */
95
 
        $filter = GalleryUtilities::getRequestVariables('filter');
96
 
        if (strlen($filter) < 3) { /* Is there a check to see if a regexp is valid? */
97
 
            $filter = '/.*/';
98
 
        }
99
 
 
100
 
        list ($ret, $plugins) = $this->getAvailablePluginList(array());
101
 
        if ($ret) {
102
 
            return $ret;
103
 
        }
104
 
 
105
 
        $packagedPluginList = array();
106
 
        foreach ($plugins as $pluginId => $plugin) {
107
 
            $gallery->guaranteeTimeLimit(60);
108
 
            if (preg_match($filter, $pluginId)) {
109
 
                list ($ret, $pluginInfo) = $this->doPackagePlugin($plugin['type'], $pluginId);
110
 
                if ($ret) {
111
 
                    return $ret;
112
 
                }
113
 
                $packagedPluginList[] = $pluginInfo;
114
 
            }
115
 
        }
116
 
        $this->showView('PackageResults', array('results' => $packagedPluginList));
117
 
        return null;
118
 
    }
119
 
 
120
 
    /**
121
 
     * Creates all packages for the specified plugin.
122
 
     *
123
 
     * @return array object GalleryStatus a status code
124
 
     *               array('pluginId' => ..., 'outputDir' => ...,
125
 
     *                     'packageInfo' => ..., 'errors' => ...)
126
 
     */
127
 
    function doPackagePlugin($pluginType, $pluginId) {
128
 
        global $gallery;
129
 
        $outputDir = $gallery->getConfig('repository.path');
130
 
 
131
 
        list ($ret, $plugin) = GalleryCoreApi::loadPlugin($pluginType, $pluginId, true);
132
 
        if ($ret) {
133
 
            return array($ret, null);
134
 
        }
135
 
 
136
 
        $outputDir .= sprintf('%ss', $pluginType);
137
 
 
138
 
        $descriptor = new RepositoryDescriptor();
139
 
        $ret = $descriptor->init($outputDir);
140
 
        if ($ret) {
141
 
            return array($ret, null);
142
 
        }
143
 
 
144
 
        $ret = $descriptor->generate($plugin);
145
 
        if ($ret) {
146
 
            return array($ret, null);
147
 
        }
148
 
 
149
 
        $integrityErrors = $descriptor->checkIntegrity();
150
 
        $pluginInfo = array('pluginId' => $descriptor->getPluginId(),
151
 
                            'outputDir' => $descriptor->getOutputDir());
152
 
 
153
 
        if (empty($integrityErrors)) {
154
 
            $ret = $descriptor->writeToDisk(false, true);
155
 
            if ($ret) {
156
 
                return array($ret, null);
157
 
            }
158
 
 
159
 
            $package = new RepositoryPackage();
160
 
            $ret = $package->init($descriptor, $descriptor->getOutputDir());
161
 
            if ($ret) {
162
 
                return array($ret, null);
163
 
            }
164
 
 
165
 
            list ($ret, $packagesWritten) = $package->writeAllPackagesToDisk(false, true);
166
 
            if ($ret) {
167
 
                return array($ret, null);
168
 
            }
169
 
 
170
 
            $pluginInfo['packageInfo'] = $packagesWritten;
171
 
            $pluginInfo['errors'] = array();
172
 
        } else {
173
 
            $pluginInfo['packageInfo'] = array('packagesWritten' => array(),
174
 
                                               'packagesSkipped' => array());
175
 
            $pluginInfo['errors'] = $integrityErrors;
176
 
        }
177
 
 
178
 
        return array(null, $pluginInfo);
179
 
    }
180
 
 
181
 
    /**
182
 
     * Creates a list of all existing plugins with optional action links.
183
 
     *
184
 
     * @param array $links 'action' => array(UrlGeneratorParameters)
185
 
     * @return array object GalleryStatus a status code
186
 
     *               array plugin list
187
 
     */
188
 
    function getAvailablePluginList($links) {
189
 
        global $gallery;
190
 
        $urlGenerator =& $gallery->getUrlGenerator();
191
 
        $data = array();
192
 
        $pluginTypes = array('module', 'theme');
193
 
 
194
 
        foreach ($pluginTypes as $pluginType) {
195
 
            list ($ret, $plugins) = GalleryCoreApi::fetchPluginStatus($pluginType, true);
196
 
            if ($ret) {
197
 
                return array($ret, null);
198
 
            }
199
 
 
200
 
            ksort($plugins);
201
 
            foreach ($plugins as $pluginId => $plugin) {
202
 
                $data[$pluginId]['type'] = $pluginType;
203
 
                $data[$pluginId]['active'] = isset($plugin['active']) ? 'active' : 'inactive';
204
 
                $data[$pluginId]['available'] = isset($plugin['available']) ? 'available'
205
 
                                                                            : 'unavailable';
206
 
 
207
 
                $pluginUrlParameters = array('pluginId' => $pluginId, 'pluginType' => $pluginType);
208
 
                foreach ($links as $link => $extraUrlParameters) {
209
 
                    $data[$pluginId]['links'][$link] =
210
 
                        $urlGenerator->generateUrl($extraUrlParameters + $pluginUrlParameters);
211
 
                }
212
 
            }
213
 
        }
214
 
 
215
 
        return array(null, $data);
216
 
    }
217
 
}
218
 
?>