<?php
/*
* Gallery2Flickr
*
* A bridge between your gallery2 installation and flickr.com
*
* File: Gallery2FlickrUserAdmin.inc
*
* Handle the site admin settings.
*
* Copyright:
* (c) 2006 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: Gallery2FlickrUserAdmin.inc 10 2008-01-18 09:39:31Z luciferc $
* @author Gunnar Wrobel <hide@address.com>
*/
/**
* @package Gallery2Flickr
* @subpackage UserInterface
*/
class Gallery2FlickrUserAdminController extends GalleryController
{
/**
* @see GalleryController::handleRequest()
*/
function handleRequest($form) {
GalleryCoreApi::requireOnce('modules/Gallery2Flickr/classes/Gallery2Flickr.class.php');
list($ret, $allowed) = FlickrToGalleryHelper::adminAccessAllowed();
if ($ret) {
return array($ret, null);
}
$status = $error = array();
if (isset($form['action']['link'])) {
$f2g = new FlickrToGallery();
$res = $f2g->auth_link();
if ($res['error']) {
$error[] = 'form[error][flickr]';
//var_dump('(' . $res['error']['code'] . ') ' . $res['error']['message']);
} else {
// generate and store the link the user can use to give
// Gallery2Flickr access
$status['link'] = $res['link'];
// Store the frob
$ret = FlickrToGalleryHelper::storeFrob($res['frob']);
if ($ret) {
return array($ret, null);
}
}
} elseif (isset($form['action']['save'])) {
// We need the frob again
list ($ret, $flickr_api_frob) = FlickrToGalleryHelper::retrieveFrob();
if ($ret) {
return array($ret, null);
}
$f2g = new FlickrToGallery();
// Get token from frob
$flickr_api_token = $f2g->flickr->auth_getToken($flickr_api_frob);
// generate the token from the frob. This will only work if the user
// really gave us access
if (empty($flickr_api_token['token'])) {
$error[] = 'form[error][frob]';
} else {
// store the token
$ret = FlickrToGalleryHelper::storeToken($flickr_api_token['token']);
if ($ret) {
return array($ret, null);
}
$status['saved'] = 1;
}
} elseif (isset($form['action']['delete'])) {
// We need the frob again
list ($ret, $flickr_api_frob) = FlickrToGalleryHelper::deleteFrob();
if ($ret) {
return array($ret, null);
}
list ($ret, $flickr_api_frob) = FlickrToGalleryHelper::deleteToken();
if ($ret) {
return array($ret, null);
}
}
/* Figure out where to redirect upon success */
$method = empty($error) ? 'redirect' : 'delegate';
$results[$method]['view'] = 'core.UserAdmin';
$results[$method]['subView'] = 'Gallery2Flickr.Gallery2FlickrUserAdmin';
$results['status'] = $status;
$results['error'] = $error;
return array(null, $results);
}
}
/**
* @package Gallery2Flickr
* @subpackage UserInterface
*/
class Gallery2FlickrUserAdminView extends GalleryView {
/**
* @see GalleryView::loadTemplate
*/
function loadTemplate(&$template, &$form) {
GalleryCoreApi::requireOnce('modules/Gallery2Flickr/classes/Gallery2Flickr.class.php');
list($ret, $allowed) = FlickrToGalleryHelper::adminAccessAllowed();
if ($ret) {
return array($ret, null);
}
if ($form['formName'] != 'Gallery2FlickrUserAdmin') {
$form['formName'] = 'Gallery2FlickrUserAdmin';
}
if (FlickrToGalleryHelper::hasFrob()) {
$template->setVariable('hasfrob', '1');
}
$template->setVariable('controller', 'Gallery2Flickr.Gallery2FlickrUserAdmin');
return array(null, array('body' =>
'modules/Gallery2Flickr/templates/Gallery2FlickrUserAdmin.tpl'));
}
}
?>