add('name', PLUGIN_EVENT_FLICKR_NAME); $propbag->add('description', PLUGIN_EVENT_FLICKR_DESC); $propbag->add('groups', array('IMAGES')); $propbag->add('stackable', false); $propbag->add('license', 'GPL'); $propbag->add('author', 'Jay Bertrand'); $propbag->add('version', '0.6.1'); $propbag->add('requirements', array( 'serendipity' => '0.9', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('event_hooks', array( 'backend_sidebar_entries_images' => true, 'backend_sidebar_entries_event_display_flickr' => true )); // variables for this plugin ... $propbag->add('configuration', array('api_key')); return true; } // called by the framework to configure variables function introspect_config_item($name, &$propbag) { switch($name) { case 'api_key': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_FLICKR_APIKEY); $propbag->add('description', PLUGIN_EVENT_FLICKR_APIKEY_DESC); $propbag->add('validate', '/^[0-9a-fA-F]{32}$/'); $propbag->add('validate_error', PLUGIN_EVENT_FLICKR_APIKEY_INVALID); $propbag->add('default', ''); break; default: return false; break; } return true; } // used to "show" the plugin function generate_content(&$title) { $title = $this->title; } // do the hook job function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { // called when admin sidebar is being "built" case 'backend_sidebar_entries_images': ?>

Flickr username:

>

get_config('api_key')); $i = 0; if (!empty($serendipity['POST']['flickr_username'])) { // Find the NSID of the username inputted via the form $nsid = $f->people_findByUsername($serendipity['POST']['flickr_username']); // Get the friendly URL of the user's photos $photos_url = $f->urls_getUserPhotos($nsid); echo '

Photos of '; echo (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_username']) : htmlspecialchars($serendipity['POST']['flickr_username'], ENT_COMPAT, LANG_CHARSET)).' at '; echo ''.$photos_url.'

'; // default page is number one if (empty($serendipity['POST']['flickr_page']) || !is_numeric($serendipity['POST']['flickr_page'])) { $serendipity['POST']['flickr_page'] = 1; } // make sure page is a number between 1 and 500 (range allowed by flickr API) $serendipity['POST']['flickr_page'] = min(500,max(1,(int)$serendipity['POST']['flickr_page'])); echo '
Displaying page '.(function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_page']) : htmlspecialchars($serendipity['POST']['flickr_page'], ENT_COMPAT, LANG_CHARSET)).'
'; // Search is made depending on selected criterias $searchCriteria = array(); // make sure sort order is non empty AND valid if(isset($serendipity['POST']['flickr_sort']) && strlen(trim($serendipity['POST']['flickr_sort'])) && array_key_exists($serendipity['POST']['flickr_keywords'], $flickr_goodSortOrders)) $searchCriteria['sort'] = (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_sort']) : htmlspecialchars($serendipity['POST']['flickr_sort'], ENT_COMPAT, LANG_CHARSET)); // TODO: clean up tags of unwanted characters (keep only [a-zA-Z0-9_-]) if(isset($serendipity['POST']['flickr_tags']) && strlen(trim($serendipity['POST']['flickr_tags']))) $searchCriteria['tags'] = implode(',',explode(' ', (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_tags']) : htmlspecialchars($serendipity['POST']['flickr_tags'], ENT_COMPAT, LANG_CHARSET)))); // TODO: cleanup keywords if(isset($serendipity['POST']['flickr_keywords']) && strlen(trim($serendipity['POST']['flickr_keywords']))) $searchCriteria['text'] = (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['flickr_keywords']) : htmlspecialchars($serendipity['POST']['flickr_keywords'], ENT_COMPAT, LANG_CHARSET)); if(count($searchCriteria)) { // It seems the user wants an advanced search $searchCriteria['user_id'] = $nsid; $photos = $f->photos_search($searchCriteria); } else { // No extra criteria, get the user's next 12 public photos (+1 to show > next or not !) $photos = $f->people_getPublicPhotos($nsid, NULL, 13, $serendipity['POST']['flickr_page']); // Get user's tags (if any) /*$tags = $f->tags_getListUser($nsid); if(is_array($tags['tags']['tag'])) { echo implode(',', $tags['tags']['tag']); echo "
\n"; }*/ } // Loop through the photos and output the html foreach ($photos['photo'] as $photo) { echo ''; echo ''.$photo['title'].''; echo ''; // break before the 13th photo (if any) if(++$i == 12) break; // If it reaches the sixth photo, insert a line break if ($i % 6 == 0) { echo "
\n"; } } // end foreach echo "
\n"; // navigate through pages of photos if ($serendipity['POST']['flickr_page'] > 1) { echo 'Previous'; } echo '  '; if (count($photos['photo']) > 12) { echo 'Next'; } } // end if } // end if return true; break; default: return false; break; } } else { return false; } } } // end of class /* vim: set sts=4 ts=4 expandtab : */