Location: PHPKode > projects > Gallery2flickr > Gallery2Flickr/module.inc
<?php
/*
 * Gallery2Flickr
 *
 * A bridge between your gallery2 installation and flickr.com
 *
 * File:       module.inc
 *
 *             Defines the components 
 *
 * Copyright:
 *             (c) 2006 - 2008 hide@address.com
 *             Distributed under the terms of the GNU General Public License v2
 *
 * Author(s):
 *             Gunnar Wrobel <hide@address.com>
 *
 * 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., 51 Franklin Street - Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 * (Gallery2Flickr is a module for Gallery2 - a web based photo album
 *  viewer and editor - Copyright for Gallery2: (C) 2000-2008 Bharat
 *  Mediratta)
 *

 */
/**
 * @package Gallery2Flickr
 * @version $Id: module.inc 10 2008-01-18 09:39:31Z luciferc $
 * @author Gunnar Wrobel <hide@address.com>
 */

/**
 * @package Gallery2Flickr
 */
class Gallery2FlickrModule extends GalleryModule 
{
    
    function Gallery2FlickrModule() {
	global $gallery;
	$this->setId('Gallery2Flickr');
	$this->setName($gallery->i18n('Gallery2Flickr'));
	$this->setDescription($gallery->i18n('A bridge between your gallery2' .
					     ' installation and flickr.com'));
	$this->setVersion('0.9.1');
	$this->setCallbacks('getItemLinks|getUserAdminViews');
	$this->setGroup('import', $gallery->i18n('Import'));
	$this->setRequiredCoreApi(array(7, 4));
	$this->setRequiredModuleApi(array(3, 0));
    }
  
    /**
     * @see GalleryModule::getItemLinks()
     */
    function getItemLinks($items, $wantsDetailedLinks, $permissions) {
	GalleryCoreApi::requireOnce('modules/Gallery2Flickr/classes/Gallery2Flickr.class.php');

	list($ret, $allowed) = FlickrToGalleryHelper::accessAllowed();

	$links = array();

	foreach ($items as $item) {
	    $views = array();

	    if ($allowed) {
		$views[] = array('text' => $this->translate('Export to Flickr'), 
				 'params' => array('view' => 'Gallery2Flickr.FlickrExport',
						   'itemId' => $item->getId()));

		if ($item->getCanContainChildren()) {
		    $views[] = array('text' => $this->translate('Import from Flickr'),
				     'params' => array('view' => 'Gallery2Flickr.FlickrImport',
						       'itemId' => $item->getId()));
		} 
	    }

	    $links[$item->getId()] = $views;
	}
	
	return array(null, $links);
    }
    
    /**
     * @see GalleryModule::getUserAdminViews()
     */
    function getUserAdminViews($user) {
	GalleryCoreApi::requireOnce('modules/Gallery2Flickr/classes/Gallery2Flickr.class.php');

	list($ret, $allowed) = FlickrToGalleryHelper::adminAccessAllowed();
	if ($ret) {
	    return array(null, array());
	}
	return array(null, array(array('name' => $this->translate('Gallery2Flickr'),
				       'view' => 'Gallery2Flickr.Gallery2FlickrUserAdmin')));
    }
    
    /**
     * @see GalleryModule::upgrade()
     */
    function upgrade($currentVersion) {
	global $gallery;
	
	list ($ret, $params) =
	    GalleryCoreApi::fetchAllPluginParameters('module', 'Gallery2Flickr');
	if ($ret) {
	    return $ret;
	}
	foreach (array('frobs' => 'a:0:{}',
		       'tokens' => 'a:0:{}') as $key => $value) {
	    if (!isset($params[$key])) {
		$ret = $this->setParameter($key, $value);
		if ($ret) {
		    return $ret;
		}
	    }
	}
	
	if (!empty($currentVersion)) {
	    switch ($currentVersion) {
	    case '0.1.0':
		
	    case '0.1.1':
		
	    case '0.2.0':
		
	    case '0.2.9':
		GalleryCoreApi::requireOnce('modules/Gallery2Flickr/classes/Gallery2Flickr.class.php');

		list ($ret, $adminGroupId) =
		    GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup');
		if ($ret) {
		    return array($ret, null);
		}

		list ($ret, $users) = GalleryCoreApi::fetchUsersForGroup($adminGroupId, $count=1);
		if ($ret) {
		    return array($ret, null);
		}

		list($ret, $frob) = GalleryCoreApi::getPluginParameter('module', 'Gallery2Flickr', 'frob');
		if ($ret) {
		    return array($ret, null);
		}
		
		list($ret, $token) = GalleryCoreApi::getPluginParameter('module', 'Gallery2Flickr', 'token');
		if ($ret) {
		    return array($ret, null);
		}
		
		foreach ($users as $id => $name) {
		    FlickrToGalleryHelper::storeFrob($frob, $id);
		    FlickrToGalleryHelper::storeToken($token, $id);
		}

		$ret = GalleryCoreApi::removePluginParameter('module', 'Gallery2Flickr', 'frob');
		$ret = GalleryCoreApi::removePluginParameter('module', 'Gallery2Flickr', 'token');

	    case '0.9.0':
		
	    case '0.9.1':
		
	    case 'end of upgrade path':
		break;
		
	    default:
		return GalleryCoreApi::error(ERROR_BAD_PLUGIN, __FILE__, __LINE__,
					     sprintf('Unknown module version %s', $currentVersion));
	    }
	}
	
	return null;
    }
    
}
?>
Return current item: Gallery2flickr