Documentation here.'; // Function that will handle the wizard-like behaviour function dispatch() { if (empty ($_GET['step'])) $step = 0; else $step = (int) $_GET['step']; // load the header $this->header(); switch ($step) { case 0 : $this->greet(); break; case 1 : $this->flickr_start(); break; case 2: $this->flickr_pickphotos(); break; case 3: $this->flickr_harvestphotos(); break; case 4: $this->ktnxbye(); break; } // load the footer $this->footer(); } function header() { echo '
'; echo '

'.__('Scriblio flickr Importer').'

'; } function footer() { echo '
'; } function greet() { echo '
'; echo '

'.__('Howdy! Start here to import photos from flickr into Scriblio.').'

'; echo '

'.__('This has not been tested much. Mileage may vary.').'

'; echo '
'; echo '

'; echo '
'; echo '

'; echo '
'; echo '

or jump immediately to
'. __('(goes to default Scriblio importer)').'

'; echo '
'; echo '
'; } function ktnxbye() { echo '
'; echo '

'.__('All done.').'

'; echo '
'; } function flickr_start() { // Inspiration and whole blocks of code for this taken from // Jon Baker's WP-Flickr WordPress plugin // used under the terms of the GPL echo '
'; $prefs = get_option( 'scrib_flickrmporter' ); // logout if( isset( $_REQUEST['logout'] )){ $prefs['token'] = FALSE; update_option( 'scrib_flickrmporter', $prefs ); } if( $_REQUEST['frob'] != '' ){ $params = array( 'method' => 'flickr.auth.getToken', 'frob' => $_REQUEST['frob'] ); if( $r = $this->flickr_api( $params, false )){ $prefs['token'] = $r['auth']['token']['_content']; update_option( 'scrib_flickrmporter', $prefs ); } } // check authentication token for validity $current_user = FALSE; if( $prefs['token'] ) { $params = array( 'method' => 'flickr.auth.checkToken' ); if( $current_user = $this->flickr_api( $params, FALSE, TRUE )){ if ( $prefs['nsid'] != $current_user['auth']['user']['nsid'] ){ $prefs['nsid'] = $current_user['auth']['user']['nsid']; update_option( 'scrib_flickrmporter', $prefs ); } $params = array( 'method' => 'flickr.people.getInfo', 'user_id' => $prefs['nsid'] ); $r = $this->flickr_api( $params, false, true ); $prefs['photopage'] = $r['person']['photosurl']['_content']; update_option( 'scrib_flickrmporter', $prefs ); } } /* if( !$current_user ) { echo '

You need to authorised this plugin with Flickr before it can be used. Please complete the steps below to authorise this plugin.

Please Note: You will need an account with Flickr to use this plugin.

'; } */ if($current_user) { ?>

Currently logged in to Flickr as (logout)

'.__('All Scriblio records have a 'sourceid,' a unique alphanumeric string that's used to avoid creating duplicate records and, in some installations, link back to the source system for current availability information.').'

'; echo '

'.__('The sourceid is made up of two parts: the prefix that you assign, and the bib number from the Innopac. Theoretically, you chould gather records from 1,296 different systems, it's a big world.').'

'; echo '
'; ?>

'; echo '
'; } else { $prefs['token'] = null; $params = array( 'method' => 'flickr.auth.getFrob' ); $r = $this->flickr_api( $params, false ); $frob = $r['frob']['_content']; if($frob) { $flickr_url = "http://www.flickr.com/services/auth/"; $flickr_url .= "?api_key=" . SCRIBFLICKR_API_KEY; $flickr_url .= "&perms=read"; $flickr_url .= "&frob=" . $frob; $flickr_url .= "&api_sig=" . md5(SCRIBFLICKR_API_KEY_SS . "api_key" . SCRIBFLICKR_API_KEY . "frob" . $frob . "permsread"); ?>

Authorizing the Scriblio flickr Importer is a simple, two step process:

  1. Authorize this application to access flickr. This will open a new window. When you are finished, come back to this page.
  2. After authorizing this application with Flickr in the popup window, click here to complete the authorization process.
'; } function flickr_pickphotos(){ $prefs = get_option( 'scrib_flickrmporter' ); if( isset( $_POST['sourceprefix'] )) $prefs['sourceprefix'] = strtolower( ereg_replace( '[^a-z|A-Z|0-9]', '', $_POST['sourceprefix'] )); if( strlen( ereg_replace( '[^a-z|A-Z|0-9]', '', $prefs['sourceprefix'] )) <> 2 ){ echo '

'.__('Sorry, there has been an error.').'

'; echo '

Please complete all fields

'; return; } update_option( 'scrib_flickrmporter', $prefs ); if( !$_REQUEST['min_date'] || ( strtotime( $_REQUEST['min_date'] ) === FALSE )) $min_date = '-1 month'; else $min_date = $_REQUEST['min_date']; if( !$_REQUEST['page'] ) $page = '1'; else $page = (int) $_REQUEST['page']; if( !$_REQUEST['perpage'] || ( $_REQUEST['perpage'] > 500 )) $perpage = '100'; else $perpage = (int) $_REQUEST['perpage']; $params = array( 'method' => 'flickr.photos.recentlyUpdated', 'page' => $page, 'per_page' => $perpage, 'min_date' => strtotime( $min_date ) ); $photos = $this->flickr_api( $params, false, true ); echo '
'; echo '
'; echo '

'. $photos['photos']['total'] .' photos uploaded or changed since . Showing page of '. $photos['photos']['pages'] .', photos per page.

'; echo '
'; //print_r($photos); if($photos) { //print_r($prefs); echo '
'; foreach($photos['photos']['photo'] as $number=>$photo) { ?>


$v){ if( substr( $k, 0, 19 ) == 'scrib_flickr_photo-' ) $photo_ids[] = substr( $k, 19 ); } //print_r( $photo_ids ); echo '
'; foreach( $photo_ids as $photo_id ){ $params = array( 'method' => 'flickr.photos.getInfo', 'photo_id' => $photo_id ); $photo_details = $this->flickr_api( $params, false, true ); //print_r( $photo_details ); $atomic = FALSE; $atomic['the_sourceid'] = $prefs['sourceprefix'] . $photo_details['photo']['id']; $params = array( 'method' => 'flickr.photos.getSizes', 'photo_id' => $photo_id ); $photo_sizes = $this->flickr_api( $params, false, true ); $atomic['img']['thumb']['width'] = $photo_sizes['sizes']['size'][1]['width']; $atomic['img']['thumb']['height'] = $photo_sizes['sizes']['size'][1]['height']; $atomic['img']['thumb']['url'] = $this->flickr_cacheimage( $this->flickr_photourl( $photo_details['photo']['farm'], $photo_details['photo']['server'], $photo_details['photo']['id'], $photo_details['photo']['secret']) .'_t.jpg', $photo_details['photo']['id'] .'_t' ); $atomic['img']['large']['width'] = $photo_sizes['sizes']['size'][3]['width']; $atomic['img']['large']['height'] = $photo_sizes['sizes']['size'][3]['height']; $atomic['img']['large']['url'] = $this->flickr_cacheimage( $this->flickr_photourl( $photo_details['photo']['farm'], $photo_details['photo']['server'], $photo_details['photo']['id'], $photo_details['photo']['secret']) .'.jpg', $photo_details['photo']['id'] ); if( strlen( $photo_details['photo']['description']['_content'] )) $atomic['notes'][] = $photo_details['photo']['description']['_content']; foreach( $photo_details['photo']['tags']['tag'] as $tag){ $parsed_tag = $bsuite->machtag_parse_tag( $tag['raw'] ); $parsed_tag['taxonomy'] = strtolower( $parsed_tag['taxonomy'] ); switch( $parsed_tag['taxonomy'] ){ case 'parent' : preg_match('/\/photos\/[^\/]*\/([0-9]*)\//', $parsed_tag['term'], $match); $atomic['parent'][] = $prefs['sourceprefix'] . $match[1]; continue; case 'child' : preg_match('/\/photos\/[^\/]*\/([0-9]*)\//', $parsed_tag['term'], $match); $atomic['child'][] = $prefs['sourceprefix'] . $match[1]; continue; case 'reverse' : preg_match('/\/photos\/[^\/]*\/([0-9]*)\//', $parsed_tag['term'], $match); $atomic['reverse'][] = $prefs['sourceprefix'] . $match[1]; continue; case 'subject' : $atomic['tags']['subj'][] = $parsed_tag['term']; continue; case 'year' : $atomic['tags']['dy'][] = $parsed_tag['term']; continue; case 'month' : $atomic['tags']['dm'][] = $parsed_tag['term']; continue; default: $atomic['tags'][$parsed_tag['taxonomy']][] = $parsed_tag['term']; } } $atomic['the_title'] = eregi_replace('^Img', 'Item #', eregi_replace('\.jpg$', '', $photo_details['photo']['title']['_content'])); $atomic['tags']['title'][] = $atomic['the_title']; $atomic['the_pubdate'] = $photo_details['photo']['dates']['taken']; $atomic['the_acqdate'] = date('Y-m-d H:i:s', $photo_details['photo']['dates']['posted']); $atomic['cformatter'] = 'scribflickr_importer_content'; $atomic['eformatter'] = 'scribflickr_importer_excerpt'; $scrib_import->insert_harvest($atomic); ?>
Harvested
'. $scrib_import->get_the_excerpt( $atomic ) .'
'; //echo '
'. $scrib_import->get_the_content( $atomic ) .'
'; } echo '
'; echo '

'.__('Processing complete.').'

'; echo '

'.__('Continue to the next step to publish those harvested catalog entries.').'

'; echo '
'; echo '


'. __('(goes to default Scriblio importer)').'

'; echo '
'; echo '
'; } function the_content( $atomic ) { $content = '[[bookjacket|'. str_replace(array('[',']'), array('{','}'), htmlentities($atomic['title'][0], ENT_QUOTES, UTF-8)) .']]'; if($atomic['notes']) foreach($atomic['notes'] as $temp) $content .= '

'. $temp .'

'; if($atomic['tags']){ $content .= ''; } if($atomic['parent']){ $content .= '

Parent:

'; } if($atomic['child']){ $content .= '

Child:

'; } if($atomic['reverse']){ $content .= '

Reverse:

'; } return($content); } function the_excerpt( $atomic ) { $content = '[[bookjacket|'. str_replace(array('[',']'), array('{','}'), htmlentities($atomic['title'][0], ENT_QUOTES, UTF-8)) .']]'; return($content); } function flickr_cacheimage($url, $filename, $dl = TRUE){ $dirpath = substr($filename, 4, 1); $extension = substr($url, strripos($url, '.')); $path = $dirpath .'/'. $filename . $extension; if(!is_dir( SCRIBFLICKR_IMGDIR_PATH . $dirpath )){ mkdir( SCRIBFLICKR_IMGDIR_PATH . $dirpath, 0775 ); } if( $dl ) exec( 'curl -o '. escapeshellarg( SCRIBFLICKR_IMGDIR_PATH. $path ) .' '. escapeshellarg( $url )); return( get_settings( 'siteurl' ) .'/'. SCRIBFLICKR_IMGDIR .'/'. $path); } function flickr_photourl( $farm, $server, $id, $secret ) { return $img_url = 'http://farm' . $farm . '.static.flickr.com/' . $server . '/' . $id . '_' . $secret; } function flickr_api( $params, $cache = true, $sign = true ) { // Inspiration and whole blocks of code for this taken from // Jeffrey Maki's Flickr Tag WordPress plugin // used under the terms of the GPL $prefs = get_option( 'scrib_flickrmporter' ); $params['format'] = 'php_serial'; $params['api_key'] = SCRIBFLICKR_API_KEY; if( $prefs['token'] ) $params['auth_token'] = $prefs['token']; ksort($params); // important for generating the correct signature $cache_key = md5( implode( $params )); $signature_raw = ''; $encoded_params = array(); foreach($params as $k=>$v) { $encoded_params[] = urlencode($k) . '=' . urlencode($v); $signature_raw .= $k . $v; } if( $sign ) array_push($encoded_params, 'api_sig=' . md5(SCRIBFLICKR_API_KEY_SS . $signature_raw)); //print_r( $encoded_params ); @$c = curl_init(); if( $c ){ curl_setopt( $c, CURLOPT_URL, 'http://api.flickr.com/services/rest/' ); curl_setopt( $c, CURLOPT_POST, 1 ); curl_setopt( $c, CURLOPT_POSTFIELDS, implode( '&', $encoded_params )); curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $c, CURLOPT_CONNECTTIMEOUT, 10 ); $r = curl_exec($c); }else // no curl, try fopen... $r = file_get_contents( 'http://api.flickr.com/services/rest/?' . implode( '&', $encoded_params )); if( !$r ) die( 'Darn. It no worky. Perhaps flickr is down? Perhaps this host does not have curl or fopen wrappers?' ); $o = unserialize( $r ); //print_r( $o ); if( $o['stat'] != 'ok' ) return(FALSE); return $o; } // Default constructor function ScribFlickr_import() { // nothing } } // Instantiate and register the importer include_once(ABSPATH . 'wp-admin/includes/import.php'); if(function_exists('register_importer')) { $scribflickr_import = new ScribFlickr_import(); register_importer($scribflickr_import->importer_code, $scribflickr_import->importer_name, $scribflickr_import->importer_desc, array (&$scribflickr_import, 'dispatch')); } add_action('activate_'.plugin_basename(__FILE__), 'scribflickr_importer_activate'); function scribflickr_importer_content( $atomic ) { global $scribflickr_import; return( $scribflickr_import->the_content( $atomic )); } function scribflickr_importer_excerpt( $atomic ) { global $scribflickr_import; return( $scribflickr_import->the_excerpt( $atomic )); } function scribflickr_importer_activate() { global $wp_db_version, $scribflickr_import; // Deactivate on pre 2.3 blogs if($wp_db_version<6075) { $current = get_settings('active_plugins'); array_splice($current, array_search( plugin_basename(__FILE__), $current), 1 ); update_option('active_plugins', $current); do_action('deactivate_'.plugin_basename(__FILE__)); return(FALSE); } } ?>