api_key= Options::get( 'skippyflickr__api_key' );
$this->person_id= Options::get( 'skippyflickr__person' );
}
function info()
{
return array(
'name' => 'Skippy Flickr',
'url' => 'http://skippy.net/',
'author' => 'Scott Merrill',
'authorurl' => 'http://skippy.net/',
'version' => '1.2',
'license' => 'Apache License 2.0',
'description' => 'provides some Flickr functionality'
);
}
public function action_plugin_activation( $file )
{
if ( realpath( $file ) == __FILE__ ) {
CronTab::add_hourly_cron( 'skippyflickr', 'skippyflickr', 'Selects a couple random photos from Flickr based on tags used on the site' );
}
}
function action_plugin_deactivation( $file )
{
if ( Plugins::id_from_file($file) == Plugins::id_from_file(__FILE__) ) {
CronTab::delete_cronjob( 'skippyflickr' );
}
}
public function filter_plugin_config( $actions, $plugin_id )
{
if ( $plugin_id == $this->plugin_id() ) {
$actions[]= _t('Configure');
$actions[]= _t('Refresh');
}
return $actions;
}
public function action_plugin_ui( $plugin_id, $action )
{
if ( $plugin_id == $this->plugin_id() ) {
switch ( $action ) {
case _t('Configure') :
$ui = new FormUI( strtolower( get_class( $this ) ) );
$api_key= $ui->append( 'text', 'api_key', 'skippyflickr__api_key', _t('API key: ') );
$person= $ui->append( 'text', 'person', 'skippyflickr__person', _t('Person ID: ' ) );
// $ui->on_success( array( $this, 'updated_config' ) );
$ui->append( 'submit', 'save', _t('Save') );
$ui->out();
break;
case _t('Refresh') :
$this->filter_skippyflickr();
Utils::redirect( URL::get('admin', 'page=plugins') );
break;
}
}
}
public function updated_config( $ui )
{
return true;
}
public function filter_dash_modules( $modules )
{
array_push( $modules, 'Skippy Flickr' );
return $modules;
}
public function filter_dash_module_skippy_flickr( $module, $module_id, $theme )
{
$this->api_key= Options::get( 'skippyflickr__api_key' );
$this->person_id= Options::get( 'skippyflickr__person' );
$all_tags= Tags::get();
$t= array();
for ( $i= 0; $i < 3; $i++ ) {
$rand= rand( 1, count( $all_tags ) );
$tag= $all_tags[$rand];
$t[]= urlencode($tag->tag);
}
$tags= implode( ',', $t );
$request= new RemoteRequest( 'http://api.flickr.com/services/rest/?method=flickr.photos.search&format=rest&api_key=' . $this->api_key . '&user_id=' . $this->person_id . '&tags=' . $tags . '&sort=relevance&media=photos&per_page=1' );
$request->set_timeout( 5 );
$result= $request->execute();
$response= $request->get_response_body();
$xml= new SimpleXMLElement( $response );
$photo=$xml->photos->photo;
$photo= '
';
$content= var_export( $xml, true );
$module['title']= 'Skippy Flickr';
$module['content']= $photo;
return $module;
}
// the workhouse method, which gets invoked hourly by cron
public function filter_skippyflickr()
{
$this->api_key= Options::get( 'skippyflickr__api_key' );
$this->person_id= Options::get( 'skippyflickr__person' );
// lets fetch a couple of random tags
$all_tags= Tags::get();
$t= array();
for ( $i= 0; $i < 3; $i++ ) {
$rand= rand( 1, count( $all_tags ) );
$tag= $all_tags[$rand];
$t[]= urlencode($tag->tag);
}
$tags= implode( ',', $t );
$request= new RemoteRequest( 'http://api.flickr.com/services/rest/?method=flickr.photos.search&format=rest&api_key=' . $this->api_key . '&user_id=' . $this->person_id . '&tags=' . $tags . '&sort=relevance&media=photos&per_page=1' );
$request->set_timeout( 5 );
$result= $request->execute();
if ( Error::is_error( $result ) ) {
// this is a cronjob, so no sense displaying an error
EventLog::log( 'Error getting photo from Flickr', 'err', 'default', 'habari' );
return;
}
$response= $request->get_response_body();
$xml= new SimpleXMLElement( $response );
if ( ! $xml ) { return; }
$photo=$xml->photos->photo;
if ( ! $photo ) { return; }
if ( ! $photo['id'] ) { return; }
$newphoto= '
';
Options::set( 'skippyflickr__photo', $newphoto );
EventLog::log( 'Updated photo: ' . $photo['title'], 'info', 'default', 'habari' );
}
public function theme_recent_photo()
{
$photo= Options::get( 'skippyflickr__photo' );
if ( '' != $photo ) {
echo $photo;
}
}
}
?>