From: Bharat M. <bh...@us...> - 2002-11-05 07:16:52
|
Update of /cvsroot/gallery/gallery2/modules/core In directory usw-pr-cvs1:/tmp/cvs-serv11298/modules/core Modified Files: SiteAdmin.inc module.inc Added Files: ItemAdmin.inc ItemEditGeneral.inc Log Message: * Added partial Dutch translations (courtesy of Marcel van Groenigen). Marcel actually translated everything, but his translation exposed a bug in the text-extraction code, which I fixed .. leading to more strings that require translation. * First pass at creating item admin views, with a partial implementation of general item support. * Added a few useful permission methods to GalleryUserHelper --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class ItemAdminView extends GalleryView { /** * @see GalleryView::renderHead */ function renderHead() { global $gallery; /* Get our theme in place */ $ret = $this->_activateTheme(); if ($ret->isError()) { return $ret; } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Render the HTML head */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('ItemAdminHead.tpl'); return array(GalleryStatus::success(), $html); } /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; /* Get our theme in place */ $ret = $this->_activateTheme(); if ($ret->isError()) { return $ret; } /* Figure out the item we're referring to */ $itemId = GalleryUtilities::getRequestVariables('itemId'); list ($ret, $item) = $gallery->loadEntitiesById($itemId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Load the module list */ list ($ret, $moduleStatus) = $gallery->getModuleStatus(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Get a list of all the admin views for each module */ $subViewChoices = array(); foreach ($moduleStatus as $moduleName => $status) { if (empty($status['active'])) { continue; } /* Get the selected module's admin view */ list($ret, $module) = $gallery->loadModule($moduleName); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } list ($ret, $moduleViews) = $module->getItemAdminViews($item); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $subViewChoices = array_merge($subViewChoices, $moduleViews); } /* If we have a specific sub view, render it now */ $subViewName = GalleryUtilities::getRequestVariables('subView'); if (empty($subViewName) && !empty($subViewChoices)) { $subViewName = $subViewChoices[0]['view']; } if (!empty($subViewName)) { list ($ret, $subView) = GalleryView::loadView($subViewName); list ($ret, $subViewHtml) = $subView->renderBody(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } } else { $subViewHtml = ''; } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Render our HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('itemId', $itemId); $smarty->assign('subViewChoices', $subViewChoices); $smarty->assign('subViewHtml', $subViewHtml); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('ItemAdmin.tpl'); return array(GalleryStatus::success(), $html); } } ?> --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class ItemEditGeneralController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest() { global $gallery; $itemId = GalleryUtilities::getRequestVariables('itemId'); $form = GalleryUtilities::getFormVariables('form.'); /* Make sure we have permission do edit this item */ $ret = GalleryUserHelper::assertHasItemPermission($itemId, $gallery->getActiveUserId(), array('core.all', 'core.changeText')); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* ... take action here ... */ /* Figure out where to redirect upon success */ $urlParams['view'] = 'core:SiteAdmin'; $urlParams['subView'] = 'core:ItemEditGeneral'; $templateAdapter = $gallery->getTemplateAdapter(); $results['redirect'] = $templateAdapter->url($urlParams); return array(GalleryStatus::success(), $results); } } class ItemEditGeneralView extends GalleryView { /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; $itemId = GalleryUtilities::getRequestVariables('itemId'); $form = GalleryUtilities::getFormVariables('form.'); /* Make sure we have permission do edit this item */ $ret = GalleryUserHelper::assertHasItemPermission($itemId, $gallery->getActiveUserId(), array('core.all', 'core.changeText')); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } list ($ret, $item) = $gallery->loadEntitiesById($itemId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $form['item'] = $item->getMemberData(); /* Render the HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('form', $form); $smarty->assign('controller', 'core:ItemEditGeneral'); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('ItemEditGeneral.tpl'); return array(GalleryStatus::success(), $html); } } ?> Index: SiteAdmin.inc =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/SiteAdmin.inc,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- SiteAdmin.inc 28 Oct 2002 18:51:03 -0000 1.10 +++ SiteAdmin.inc 5 Nov 2002 07:16:48 -0000 1.11 @@ -110,7 +110,7 @@ return array($ret->wrap(__FILE__, __LINE__), null); } } else { - $subViewHtml = ""; + $subViewHtml = ''; } /* Specify our translation module */ Index: module.inc =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/module.inc,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- module.inc 2 Nov 2002 06:25:23 -0000 1.14 +++ module.inc 5 Nov 2002 07:16:48 -0000 1.15 @@ -259,24 +259,15 @@ return array($ret->wrap(__FILE__, __LINE__), null); } - if (!$isSiteAdmin) { - list ($ret, $groupIds) = - GalleryUserGroupMap::fetchGroupsForUser($gallery->getActiveUserId()); - if ($ret->isError()) { - return array($ret->wrap(__FILE__, __LINE__), null); - } - } - $links = array(); foreach ($items as $item) { if ($isSiteAdmin) { $hasPermission = true; } else { list ($ret, $hasPermission) = - GalleryPermissionMap::hasPermission($item->getId(), - array($gallery->getActiveUserId()), - $groupIds, - $adminPermissions); + GalleryPermissionMap::hasItemPermission($item->getId(), + $gallery->getActiveUserId(), + $adminPermissions); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } @@ -350,6 +341,29 @@ 'view' => 'core:AdminModules'))); } + /** + * @see GalleryModule::getItemAdminViews(); + */ + function getItemAdminViews($item) { + global $gallery; + + $views = array(); + list ($ret, $hasPermission) = + GalleryUserHelper::hasItemPermission($item->getId(), + $gallery->getActiveUserId(), + array('core.all', 'core.changeText')); + if ($ret->isError()) { + return array(GalleryStatus::success(), null); + } + + if ($hasPermission) { + $views[] = array('name' => $this->translate('General'), + 'view' => 'core:ItemEditGeneral'); + } + + return array(GalleryStatus::success(), $views); + } + /** * Create the initial All Users group * |