1<?php 2/* 3 * Gallery - a web based photo album viewer and editor 4 * Copyright (C) 2000-2008 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/** 22 * Photo printing at photoworks.com 23 * 24 * @package PhotoAccess 25 * @author Bharat Mediratta <bharat@menalto.com> 26 * @version $Revision: 18172 $ 27 */ 28class PhotoAccessModule extends GalleryModule { 29 30 function PhotoAccessModule() { 31 global $gallery; 32 33 $this->setId('photoaccess'); 34 $this->setName($gallery->i18n('PhotoWorks')); 35 $this->setDescription($gallery->i18n('PhotoWorks Photo Printing Module')); 36 $this->setVersion('1.0.13'); /* Update upgrade() too */ 37 $this->_templateVersion = 1; 38 $this->setGroup('commerce', $gallery->i18n('Commerce')); 39 $this->setCallbacks('getItemLinks'); 40 $this->setRequiredCoreApi(array(7, 43)); 41 $this->setRequiredModuleApi(array(3, 9)); 42 } 43 44 /** 45 * @see GalleryModule::upgrade 46 */ 47 function upgrade($currentVersion) { 48 global $gallery; 49 if (!isset($currentVersion)) { 50 $currentVersion = '0'; 51 } else if (version_compare($currentVersion, '1.0.0', '<')) { 52 /* Instead of enumerating all previous versions... */ 53 $currentVersion = '1.0.0'; 54 } 55 list ($ret, $coreParams) = GalleryCoreApi::fetchAllPluginParameters('module', 'core'); 56 if ($ret) { 57 return $ret; 58 } 59 60 switch ($currentVersion) { 61 case '0': 62 /* Register our permission */ 63 $ret = GalleryCoreApi::registerPermission($this->getId(), 'photoaccess.print', 64 $gallery->i18n('[photoworks] Print')); 65 if ($ret) { 66 return $ret; 67 } 68 /* Give everybody print permission by default */ 69 $gallery->guaranteeTimeLimit(300); 70 $ret = GalleryCoreApi::addGroupPermission( 71 $coreParams['id.rootAlbum'], $coreParams['id.everybodyGroup'], 72 'photoaccess.print', true); 73 if ($ret) { 74 return $ret; 75 } 76 break; 77 78 case '1.0.0': 79 $ret = GalleryCoreApi::registerPermission($this->getId(), 'photoaccess.print', 80 $gallery->i18n('[photoworks] Print')); 81 if ($ret) { 82 return $ret; 83 } 84 $gallery->guaranteeTimeLimit(300); 85 $ret = GalleryCoreApi::addGroupPermission( 86 $coreParams['id.rootAlbum'], $coreParams['id.everybodyGroup'], 87 'photoaccess.print', true); 88 if ($ret) { 89 return $ret; 90 } 91 92 case '1.0.1': 93 case '1.0.2': 94 case '1.0.3': 95 case '1.0.4': 96 case '1.0.5': 97 case '1.0.6': 98 case '1.0.7': 99 case '1.0.7.1': 100 /* .mo file migration */ 101 case '1.0.8': 102 case '1.0.9': 103 /* Implementing new version of the cart plugin interface */ 104 case '1.0.10': 105 case '1.0.11': 106 case '1.0.12': 107 108 case 'end of upgrade path': 109 break; 110 111 default: 112 return GalleryCoreApi::error(ERROR_BAD_PLUGIN, __FILE__, __LINE__, 113 sprintf('Unknown module version %s', $currentVersion)); 114 } 115 116 return null; 117 } 118 119 /** 120 * @see GalleryModule::performFactoryRegistrations 121 */ 122 function performFactoryRegistrations() { 123 foreach (array('1_0', '1_1') as $version) { 124 $ret = GalleryCoreApi::registerFactoryImplementation( 125 'CartPluginInterface_' . $version, 'PhotoAccessCartPlugin', 'photoaccess', 126 'modules/photoaccess/classes/PhotoAccessCartPlugin.class', 'photoaccess', null); 127 if ($ret) { 128 return $ret; 129 } 130 } 131 132 return null; 133 } 134 135 /** 136 * @see GalleryModule::getItemLinks 137 */ 138 function getItemLinks($items, $wantsDetailedLinks, $permissions) { 139 $links = array(); 140 141 foreach ($items as $item) { 142 $itemId = $item->getId(); 143 if (isset($wantsDetailedLinks[$itemId]) && 144 isset($permissions[$itemId]['photoaccess.print']) && 145 GalleryUtilities::isA($item, 'GalleryPhotoItem')) { 146 $links[$itemId][] = 147 array('text' => $this->translate('Print on PhotoWorks.com'), 148 'params' => array('controller' => 'photoaccess.PrintPhoto', 149 'itemId' => $itemId, 'returnUrl' => '%CURRENT_URL%')); 150 } 151 } 152 153 return array(null, $links); 154 } 155} 156?> 157