3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
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.
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.
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.
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');
26
* Controller for the plugin packaging page.
28
* @author Jozef Selesi <selesi at gmail dot com>
30
* @version $Revision: 15513 $
31
* @package RepositoryTools
32
* @subpackage Controllers
33
* @module PackagePluginController
35
class PackagePluginControllerAndView extends RepositoryControllerAndView {
38
* Displays the available plugins that can be packaged.
40
* @return object GalleryStatus a status code
42
function showAvailablePlugins() {
43
list ($ret, $plugins) = $this->getAvailablePluginList(array(
44
'package' => array('controller' => 'PackagePlugin', 'action' => 'packagePlugin')));
49
$ret = $this->showView('PackagePlugin', array('plugins' => $plugins));
58
* Creates all packages for the selected plugin and displays a summary page when completed.
60
* @return object GalleryStatus a status code
62
function packagePlugin() {
63
list ($pluginId, $pluginType) =
64
GalleryUtilities::getRequestVariables('pluginId', 'pluginType');
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));
72
list ($ret, $pluginInfo) = $this->doPackagePlugin($pluginType, $pluginId);
77
$ret = $this->showView('PackageResults', array('results' => array($pluginInfo)));
86
* Creates packages for all plugins that match the 'filter' request variable.
88
* @return object GalleryStatus a status code
90
function packagePlugins() {
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? */
100
list ($ret, $plugins) = $this->getAvailablePluginList(array());
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);
113
$packagedPluginList[] = $pluginInfo;
116
$this->showView('PackageResults', array('results' => $packagedPluginList));
121
* Creates all packages for the specified plugin.
123
* @return array object GalleryStatus a status code
124
* array('pluginId' => ..., 'outputDir' => ...,
125
* 'packageInfo' => ..., 'errors' => ...)
127
function doPackagePlugin($pluginType, $pluginId) {
129
$outputDir = $gallery->getConfig('repository.path');
131
list ($ret, $plugin) = GalleryCoreApi::loadPlugin($pluginType, $pluginId, true);
133
return array($ret, null);
136
$outputDir .= sprintf('%ss', $pluginType);
138
$descriptor = new RepositoryDescriptor();
139
$ret = $descriptor->init($outputDir);
141
return array($ret, null);
144
$ret = $descriptor->generate($plugin);
146
return array($ret, null);
149
$integrityErrors = $descriptor->checkIntegrity();
150
$pluginInfo = array('pluginId' => $descriptor->getPluginId(),
151
'outputDir' => $descriptor->getOutputDir());
153
if (empty($integrityErrors)) {
154
$ret = $descriptor->writeToDisk(false, true);
156
return array($ret, null);
159
$package = new RepositoryPackage();
160
$ret = $package->init($descriptor, $descriptor->getOutputDir());
162
return array($ret, null);
165
list ($ret, $packagesWritten) = $package->writeAllPackagesToDisk(false, true);
167
return array($ret, null);
170
$pluginInfo['packageInfo'] = $packagesWritten;
171
$pluginInfo['errors'] = array();
173
$pluginInfo['packageInfo'] = array('packagesWritten' => array(),
174
'packagesSkipped' => array());
175
$pluginInfo['errors'] = $integrityErrors;
178
return array(null, $pluginInfo);
182
* Creates a list of all existing plugins with optional action links.
184
* @param array $links 'action' => array(UrlGeneratorParameters)
185
* @return array object GalleryStatus a status code
188
function getAvailablePluginList($links) {
190
$urlGenerator =& $gallery->getUrlGenerator();
192
$pluginTypes = array('module', 'theme');
194
foreach ($pluginTypes as $pluginType) {
195
list ($ret, $plugins) = GalleryCoreApi::fetchPluginStatus($pluginType, true);
197
return array($ret, null);
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'
207
$pluginUrlParameters = array('pluginId' => $pluginId, 'pluginType' => $pluginType);
208
foreach ($links as $link => $extraUrlParameters) {
209
$data[$pluginId]['links'][$link] =
210
$urlGenerator->generateUrl($extraUrlParameters + $pluginUrlParameters);
215
return array(null, $data);