From 71b4d8c3c3343455552a76756e5aaacd82034c4e Mon Sep 17 00:00:00 2001 From: Greg Froese Date: Fri, 9 Oct 2009 03:23:52 +0000 Subject: flickr integration updates --- actions/flickrImportPhotoset.php | 9 ++------- actions/flickrSetup.php | 6 ++++++ lib/flickr.php | 2 +- pages/flickr/error_log | 1 + pages/flickr/importPhotosets.php | 8 +++++++- start.php | 2 +- views/default/tidypics/forms/setupFlickr.php | 27 ++++++++++++++++++++++++++- 7 files changed, 44 insertions(+), 11 deletions(-) diff --git a/actions/flickrImportPhotoset.php b/actions/flickrImportPhotoset.php index 315d1009d..d28ea8564 100644 --- a/actions/flickrImportPhotoset.php +++ b/actions/flickrImportPhotoset.php @@ -11,6 +11,7 @@ require_once dirname(dirname(__FILE__)) . "/lib/phpFlickr/phpFlickr.php"; $f = new phpFlickr("26b2abba37182aca62fe0eb2c7782050"); $set_id = get_input( "set_id" ); +$album_id = get_input( "album_id" ); $page_pp = get_input( "page" ); $return_url = get_input( "return_url" ); $user = get_loggedin_user(); @@ -25,9 +26,6 @@ if( empty( $flickr_id )) { // Get the friendly URL of the user's photos $photos_url = $f->urls_getUserPhotos( $flickr_id->value ); $photos = $f->photosets_getPhotos( $set_id, null, null, 10, $page_pp ); -/* TODO: -* 1. create album if a matching one doesn't exist -*/ $photos_to_upload = array(); foreach( $photos["photoset"]["photo"] as $photo ) { @@ -76,10 +74,7 @@ gatekeeper(); // Get common variables $access_id = (int) get_input("access_id"); $container_guid = (int) get_input('container_guid', 0); -$container_guid = 990; //force it to my test album for now - -if (!$container_guid) - $container_guid == $_SESSION['user']->getGUID(); +$container_guid = intval ($album_id); $album = get_entity($container_guid); diff --git a/actions/flickrSetup.php b/actions/flickrSetup.php index e272ee141..2a1f82315 100644 --- a/actions/flickrSetup.php +++ b/actions/flickrSetup.php @@ -6,6 +6,7 @@ require_once dirname(dirname(__FILE__)) . "/lib/phpFlickr/phpFlickr.php"; $f = new phpFlickr("26b2abba37182aca62fe0eb2c7782050"); $flickr_username = get_input( "flickr_username" ); +$album_id = get_input( "album_id" ); $return_url = get_input( "return_url" ); $user = get_loggedin_user(); @@ -18,9 +19,14 @@ if( empty( $flickr_username )) { if( !empty( $flickr_user["id"] )) { create_metadata( $user->guid, "flickr_username", $flickr_username, "text", $user->guid, ACCESS_PUBLIC ); create_metadata( $user->guid, "flickr_id", $flickr_user["id"], "text", $user->guid, ACCESS_PUBLIC ); + if( $album_id ) { + create_metadata( $user->guid, "flickr_album_id", $album_id, "text", $user->guid, ACCESS_PUBLIC ); + $album = get_entity( $album_id ); + } system_message( "Successfully saved Flickr username of $flickr_username" ); system_message( "flickr user id: $flickr_user[id]" ); + system_message( "Album saved - $album->title" ); } else { register_error( "Username $flickr_username not found on Flickr" ); } diff --git a/lib/flickr.php b/lib/flickr.php index ec54e2867..48872c31f 100644 --- a/lib/flickr.php +++ b/lib/flickr.php @@ -1,7 +1,7 @@ function.require-once]: failed to open stream: No such file or directory" in file /home/gfroese/public_html/mod/tidypics/views/default/tidypics/forms/setupFlickr.php (line 2) [06-Oct-2009 23:30:08] PHP Fatal error: require_once() [function.require]: Failed opening required '/home/gfroese/public_html/mod/tidypics/views/lib/flickr.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/gfroese/public_html/mod/tidypics/views/default/tidypics/forms/setupFlickr.php on line 2 +[08-Oct-2009 20:05:02] PHP Parse error: syntax error, unexpected ')' in /home/gfroese/public_html/mod/tidypics/pages/flickr/importPhotosets.php on line 23 diff --git a/pages/flickr/importPhotosets.php b/pages/flickr/importPhotosets.php index c9b4416e4..fe241439e 100644 --- a/pages/flickr/importPhotosets.php +++ b/pages/flickr/importPhotosets.php @@ -18,6 +18,12 @@ $viewer = get_loggedin_user(); $flickr_username = get_metadata_byname( $viewer->guid, "flickr_username" ); $flickr_id = get_metadata_byname( $viewer->guid, "flickr_id" ); + $album_id = get_metadata_byname( $viewer->guid, "flickr_album_id" ); + + if( intval( $album_id->value ) <= 0 ) { + register_error( "No album selected. Please choose and save an album: $album_id->value" ); + forward( "/mod/tidypics/pages/flickr/setup.php" ); + } $photosets = $f->photosets_getList( $flickr_id->value ); foreach( $photosets["photoset"] as $photoset ) { @@ -29,7 +35,7 @@ //create links to import photos 10 at a time while( $photoset["photos"] > $count ) { $looper++; - $body .= " $looper"; + $body .= " $looper"; $count = $count + 10; } $body .= "
$photoset[photos] images"; diff --git a/start.php b/start.php index 76daca066..9648915bd 100644 --- a/start.php +++ b/start.php @@ -458,6 +458,6 @@ register_action("tidypics/download", true, $CONFIG->pluginspath . "tidypics/actions/download.php"); register_action("tidypics/addtag", true, $CONFIG->pluginspath . "tidypics/actions/addtag.php"); register_action("tidypics/deletetag", true, $CONFIG->pluginspath . "tidypics/actions/deletetag.php"); - register_action("tidypics/setupFlickr", true, $CONFIG->pluginspath . "tidypics/actions/setupFlickr.php"); + register_action("tidypics/flickrSetup", true, $CONFIG->pluginspath . "tidypics/actions/flickrSetup.php"); ?> \ No newline at end of file diff --git a/views/default/tidypics/forms/setupFlickr.php b/views/default/tidypics/forms/setupFlickr.php index cee94058e..8ae7c27bb 100644 --- a/views/default/tidypics/forms/setupFlickr.php +++ b/views/default/tidypics/forms/setupFlickr.php @@ -3,12 +3,37 @@ require_once( dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . "/lib/fli $user = get_loggedin_user(); $flickr_username = get_metadata_byname( $user->guid, "flickr_username" ); +$flickr_album_id = get_metadata_byname( $user->guid, "flickr_album_id" ); $action = $vars['url'] . 'action/tidypics/flickrSetup'; $form_body = "

"; -$form_body .= "Please enter your Flickr username here:

"; +$form_body .= "Please enter your Flickr username here:
"; $form_body .= ""; + +$albums = get_entities( "object", "album", $user->guid ); +$options = array( 0 => "Select album" ); +foreach( $albums as $album ) { + $title = $album->title; + switch( $album->access_id ) { + case ACCESS_PRIVATE: + $title .= " (private)"; + break; + case ACCESS_PUBLIC: + $title .= " (public)"; + break; + default: + $title .= " (not sure)"; + break; + } + $options[$album->guid] = $title; +} + +$form_body .= "
Album to import photos to: "; +$form_body .= elgg_view('input/pulldown', array('internalname' => 'album_id', + 'options_values' => $options, + 'value' => $flickr_album_id->value )); +$form_body .= "
"; $form_body .= elgg_view('input/submit', array('value' => elgg_echo("save"))); flickr_menu(); -- cgit v1.2.3