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.5');
$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':
?>
echo PLUGIN_EVENT_FLICKR_IMPORT; ?>
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 htmlspecialchars($serendipity['POST']['flickr_username']).' 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 '.htmlspecialchars($serendipity['POST']['flickr_page']).'
';
// 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'] = htmlspecialchars($serendipity['POST']['flickr_sort']);
// 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(' ', htmlspecialchars($serendipity['POST']['flickr_tags'])));
// TODO: cleanup keywords
if(isset($serendipity['POST']['flickr_keywords']) && strlen(trim($serendipity['POST']['flickr_keywords'])))
$searchCriteria['text'] = htmlspecialchars($serendipity['POST']['flickr_keywords']);
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 '';
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 : */