3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2006 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* $Id: PackagePlugin.inc,v 1.4 2006/01/10 04:38:42 mindless Exp $
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');
28
* Controller for the plugin packaging page.
30
* @author Jozef Selesi <selesi at gmail dot com>
32
* @version $Revision: 1.4 $ $Date: 2006/01/10 04:38:42 $
33
* @package RepositoryTools
34
* @subpackage Controllers
35
* @module PackagePluginController
37
class PackagePluginControllerAndView extends RepositoryControllerAndView {
40
* Displays the available plugins that can be packaged.
42
* @return object GalleryStatus a status code
44
function showAvailablePlugins() {
45
list ($ret, $plugins) = $this->getAvailablePluginList(array(
46
'package' => array('controller' => 'PackagePlugin', 'action' => 'packagePlugin')));
48
return $ret->wrap(__FILE__, __LINE__);
51
$ret = $this->showView('PackagePlugin', array('plugins' => $plugins));
53
return $ret->wrap(__FILE__, __LINE__);
60
* Creates all packages for the selected plugin and displays a summary page when completed.
62
* @return object GalleryStatus a status code
64
function packagePlugin() {
65
list ($pluginId, $pluginType) =
66
GalleryUtilities::getRequestVariables('pluginId', 'pluginType');
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));
74
list ($ret, $pluginInfo) = $this->doPackagePlugin($pluginType, $pluginId);
76
return $ret->wrap(__FILE__, __LINE__);
79
$ret = $this->showView('PackageResults', array('results' => array($pluginInfo)));
81
return $ret->wrap(__FILE__, __LINE__);
88
* Creates packages for all plugins that match the 'filter' request variable.
90
* @return object GalleryStatus a status code
92
function packagePlugins() {
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? */
101
list ($ret, $plugins) = $this->getAvailablePluginList(array());
103
return $ret->wrap(__FILE__, __LINE__);
106
foreach ($plugins as $pluginId => $plugin) {
107
if (preg_match($filter, $pluginId)) {
108
list ($ret, $pluginInfo) = $this->doPackagePlugin($plugin['type'], $pluginId);
110
return $ret->wrap(__FILE__, __LINE__);
112
$packagedPluginList[] = $pluginInfo;
115
$this->showView('PackageResults', array('results' => $packagedPluginList));
120
* Creates all packages for the specified plugin.
122
* @return object GalleryStatus a status code
124
function doPackagePlugin($pluginType, $pluginId) {
126
$outputDir = $gallery->getConfig('repository.path');
128
list ($ret, $plugin) = GalleryCoreApi::loadPlugin($pluginType, $pluginId);
130
return array($ret->wrap(__FILE__, __LINE__), null);
133
$outputDir .= sprintf('%ss', $pluginType);
135
$descriptor = new RepositoryDescriptor();
136
$ret = $descriptor->init($outputDir);
138
return array($ret->wrap(__FILE__, __LINE__), null);
141
$ret = $descriptor->generate($plugin);
143
return array($ret->wrap(__FILE__, __LINE__), null);
146
$ret = $descriptor->writeToDisk();
148
return array($ret->wrap(__FILE__, __LINE__), null);
151
$package = new RepositoryPackage();
152
$ret = $package->init($descriptor, $descriptor->getOutputDir());
154
return array($ret->wrap(__FILE__, __LINE__), null);
157
list ($ret, $packagesWritten) = $package->writeAllPackagesToDisk();
159
return array($ret->wrap(__FILE__, __LINE__), null);
162
$pluginInfo = array('pluginId' => $descriptor->getPluginId(),
163
'outputDir' => $descriptor->getOutputDir(),
164
'packageInfo' => $packagesWritten);
166
return array(null, $pluginInfo);
170
* Creates a list of all existing plugins with optional action links.
172
* @param array 'action' => array(UrlGeneratorParameters)
173
* @return array object GalleryStatus a status code
176
function getAvailablePluginList($links) {
178
$urlGenerator =& $gallery->getUrlGenerator();
180
$pluginTypes = array('module', 'theme');
182
foreach ($pluginTypes as $pluginType) {
183
list ($ret, $plugins) = GalleryCoreApi::fetchPluginStatus($pluginType, true);
185
return array($ret->wrap(__FILE__, __LINE__), null);
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'
194
$pluginUrlParameters = array('pluginId' => $pluginId, 'pluginType' => $pluginType);
195
foreach ($links as $link => $extraUrlParameters) {
196
$data[$pluginId]['links'][$link] =
197
$urlGenerator->generateUrl($extraUrlParameters + $pluginUrlParameters);
202
return array(null, $data);
b'\\ No newline at end of file'