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.
22 * Settings for Embed Video
24 * @subpackage UserInterface
25 * @author Alan J. Pippin <apippin@pippins.net>
26 * @version $Revision: 1 $
28 class EmbedVideoSiteAdminController extends GalleryController {
31 * @see GalleryController::handleRequest
33 function handleRequest($form) {
34 $ret = GalleryCoreApi::assertUserIsSiteAdministrator();
36 return array($ret, null);
39 $status = $error = array();
40 if (isset($form['action']['add'])) {
41 $type = $form['variable']['type'];
43 if (empty($form[$type]['name']) || empty($form[$type]['value'])) {
44 $error[] = "form[error][$type]";
46 list ($ret, $variables) = $this->getVariables($type);
48 return array($ret, null);
52 $variables[$form[$type]['name']] = $form[$type]['value'];
54 /* serialize it again */
55 $ret = $this->setVariables($type, $variables);
57 return array($ret, null);
60 } else if (isset($form['action']['delete'])) {
61 $type = $form['variable']['type'];
62 if (empty($form['delete']['variable'])) {
63 return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER), null);
66 list ($ret, $variables) = $this->getVariables($type);
68 return array($ret, null);
70 if (!isset($variables[$form['delete']['variable']])) {
71 return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER), null);
75 unset($variables[$form['delete']['variable']]);
77 /* serialize it again */
78 $ret = $this->setVariables($type, $variables);
80 return array($ret, null);
85 /* Figure out where to redirect upon success */
86 $method = empty($error) ? 'redirect' : 'delegate';
87 $results[$method]['view'] = 'core.SiteAdmin';
88 $results[$method]['subView'] = 'embedvideo.EmbedVideoSiteAdmin';
89 $results['status'] = $status;
90 $results['error'] = $error;
92 return array(null, $results);
95 function implode_with_key($assoc, $inglue = '=', $outglue = '&') {
98 foreach ($assoc as $tk => $tv) {
99 $return = ($return != '' ? $return . $outglue : '') .
106 function getVariables($type) {
107 list ($ret, $variables) = GalleryCoreApi::getPluginParameter('module', 'embedvideo',
108 'embedvideo' . $type . 'Variables');
110 return array($ret, null);
113 /* unserialize the plugin parameter */
114 if (!empty($variables)) {
115 $variables1 = explode('|', $variables);
116 foreach ($variables1 as $variable) {
117 list ($key, $value) = explode('=', $variable);
118 $variables2[$key] = $value;
121 return array(null, $variables2);
124 return array(null, null);
127 function setVariables($type, $variables) {
128 $params = $this->implode_with_key($variables, '=', '|');
130 return GalleryCoreApi::setPluginParameter('module', 'embedvideo',
131 'embedvideo' . $type . 'Variables', $params);
136 * Settings for Embed Video
138 class EmbedVideoSiteAdminView extends GalleryView {
141 * @see GalleryView::loadTemplate
143 function loadTemplate(&$template, &$form) {
144 $AdminEmbedVideo = array();
146 $ret = GalleryCoreApi::assertUserIsSiteAdministrator();
148 return array($ret, null);
151 list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'embedvideo');
153 return array($ret, null);
155 foreach ($params as $key => $value) {
156 $form[$key] = $value;
159 foreach (array('embedvideodefaultVariables', 'embedvideooverrideVariables') as $key) {
160 if (!empty($form[$key])) {
161 $variablesArray = explode('|', $form[$key]);
162 $variables = array();
163 foreach ($variablesArray as $variable) {
164 $variables[] = $variable;
166 $form[$key] = $variables;
170 $template->setVariable('AdminEmbedVideo', $AdminEmbedVideo);
171 $template->setVariable('controller', 'embedvideo.EmbedVideoSiteAdmin');
173 array('body' => 'modules/embedvideo/templates/EmbedVideoSiteAdmin.tpl'));