Location: PHPKode > projects > Gallery2flickr > Gallery2Flickr/FlickrImport.inc
<?php
/*
 * Gallery2Flickr
 *
 * A bridge between your gallery2 installation and flickr.com
 *
 * File:       FlickrImport.inc
 *
 *             Displays available sets for importing.
 *
 * Copyright:
 *             (c) 2006 - 2007 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-2006 Bharat
 *  Mediratta)
 *

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

/**
 * @package Gallery2Flickr
 * @subpackage UserInterface
 */
class FlickrImportController extends GalleryController {
    /**
     * @see GalleryController::handleRequest()
     */
    function handleRequest($form) {
	global $gallery;

	$itemId = GalleryUtilities::getRequestVariables('itemId');

	$redirect = array();
	$status = array();
	$error = array();
	if (isset($form['action']['import'])) {

	  $sid = array_keys($form['action']['import']);

	  /* Send the user to the set import page */
	  $redirect['view'] = 'Gallery2Flickr.FlickrImportSet';
	  $redirect['itemId'] = (int)$itemId;
	  $redirect['sid'] = $sid[0];
	} elseif (isset($form['action']['importset'])) {
	  $sid_keys = array_keys($form['action']['importset']);
	  $sid = $sid_keys[0];

	  GalleryCoreApi::requireOnce('modules/Gallery2Flickr/classes/Gallery2Flickr.class.php');
	  $f2g = new FlickrToGallery();

	  if ($f2g->import_set($sid, $itemId)) {
	    /* Send the user to the item import page */
	    $redirect['view'] = 'Gallery2Flickr.FlickrImport';
	    $redirect['itemId'] = (int)$itemId;
	    $redirect['sid'] = $sid;
	    $status['imported'] = 1;
	  } else {
	    $error[] = 'form[error][import]';
	  }
	} elseif (isset($form['action']['updateset'])) {
	  $sid_keys = array_keys($form['action']['updateset']);
	  $sid = $sid_keys[0];

	  GalleryCoreApi::requireOnce('modules/Gallery2Flickr/classes/Gallery2Flickr.class.php');
	  $f2g = new FlickrToGallery();

	  if ($f2g->update_set($sid, $itemId)) {
	    /* Send the user to the item import page */
	    $redirect['view'] = 'Gallery2Flickr.FlickrImport';
	    $redirect['itemId'] = (int)$itemId;
	    $redirect['sid'] = $sid;
	    $status['imported'] = 1;
	  } else {
	    $error[] = 'form[error][import]';
	  }
	} elseif (isset($form['action']['switch'])) {
	  $switch = $form['switch'];

	  GalleryCoreApi::requireOnce('modules/Gallery2Flickr/classes/Gallery2Flickr.class.php');
	  $f2g = new FlickrToGallery();

	  $uid = $f2g->flickr->people_findByUsername($switch);
	  /* Send the user to the item import page */
	  $redirect['view'] = 'Gallery2Flickr.FlickrImport';
	  $redirect['itemId'] = (int)$itemId;
	  if (!empty($uid['nsid'])) {
	    $redirect['uid'] = $uid['nsid'];
	  } else {
	    $error[] = 'form[error][switch]';
	  }
	} elseif (isset($form['action']['search'])) {
	  $redirect['view'] = 'Gallery2Flickr.FlickrSearch';
	  $redirect['itemId'] = (int)$itemId;
	}

	$results['status'] = $status;
	$results['error'] = $error;
	$results['redirect'] = $redirect;

	return array(null, $results);
    }
}

/**
 * @package Flickr
 * @subpackage UserInterface
 *
 */
class FlickrImportView extends GalleryView {

    /**
     * @see GalleryView::loadTemplate
     */
    function loadTemplate(&$template, &$form) {
	/* Load our item */
	list ($ret, $item) = $this->_getItem();
	if ($ret) {
	    return array($ret, null);
	}

	GalleryCoreApi::requireOnce('modules/Gallery2Flickr/classes/Gallery2Flickr.class.php');
	$f2g = new FlickrToGallery();

	$uid = GalleryUtilities::getRequestVariables('uid');

	$Flickr = array();
	$Flickr['item'] = (array)$item;
	if ($uid) {
	  $Flickr['uid'] = $f2g->flickr->people_getInfo($uid);
	} else {
	  $Flickr['uid'] = $f2g->user;
	}
	$Flickr['sets'] = $f2g->flickr->photosets_getList($uid);
	$template->setVariable('Flickr', $Flickr);

	return array(null, array('body' => 'modules/Gallery2Flickr/templates/FlickrImport.tpl'));
    }
}
?>
Return current item: Gallery2flickr