" . $str . "
"); } function mdl_exit_with_error($str) { global $MDLerr, $body; if ($str) mdl_error($str); if ($body) echo "OAI response parsed into " . print_r($assoc) . "" ); return(0); } /* start by putting the institution name in the tags */ if ($config[$config['use']]['tag']) $meta['tags'][] = '"'.$config[$config['use']]['tag'].'"'; if ($overall_tag) $meta['tags'][] = "\"$overall_tag\""; $usedtags[$config[$config['use']]['tag']] = true; /* this is a very peculiar dive into a particular point in the returned array */ foreach($assoc[0]['value'][2]['value'][0]['value'][1]['value'][0]['value'] as $item) { if($item['value']) { switch($item['tag']) { case 'dc:format': if ($item['value'] != "image/tiff") { $meta[$item['tag']][] = $item['value']; } break; case 'dc:identifier': if (!strncmp($item['value'], "http://", 7)) { $meta['url'][] = $item['value']; } else { $meta[$item['tag']][] = $item['value']; } break; case 'dc:subject': case 'dc:coverage': /* case 'dc:publisher': // it appears this is NOT the owner */ $meta[$item['tag']][] = $item['value']; $tags = preg_split("/--|;\s*|:\s*/", $item['value']); foreach($tags as $tag) { $cleantag = clean_up($tag); if ($cleantag && (!$usedtags[$cleantag])) { $meta['tags'][] = "\"".$cleantag."\""; $usedtags[$cleantag] = true; } } break; default: $meta[$item['tag']][] = clean_up($item['value']); } } } $record_meta['Title'] = join("; ", $meta['dc:title']); $record_meta['Tags'] = join(" ", $meta['tags']); $record_meta['Description'] = join("; ", $meta["dc:description"]) . "\n\n"; foreach($desc_fields as $key => $value) { if ($key == "dc:description") continue; if ($meta[$key]) { $record_meta['Description'] = $record_meta['Description'] . "$value: " . join("; ", $meta[$key]) . "\n"; } } $record_meta['Description'] = $record_meta['Description'] . "Link to our record: "; foreach ($meta['url'] as $url) { $record_meta['Description'] = $record_meta['Description'] . "$url"; } $record_meta['Description'] = $record_meta['Description'] . "\n\n"; $record_meta['Description'] = $record_meta['Description'] . $config[$config['use']]['statement']; // mdl_exit_with_error(print_r($meta, true).print_r($record_meta, true)); return(1); } function check_flickr() { global $flickr, $flickr_meta, $config; if (! ($config['apikey'] && $config['secret'] && $config[$config['use']]['token'])) { mdl_error("Settings for ".$config['use']." are missing Flickr configuration information."); return(0); } // Create new phpFlickr object $flickr = new phpFlickr($config['apikey'],$config['secret']); // $flickr->enableCache("db","mysql://[username]:[password]@[server]/[database]"); $flickr->setToken($config[$config['use']]['token']); $token = $flickr->auth_checkToken(); // Find the NSID of the username inputted via the form $flickr_meta['NSID'] = $token['user']['nsid']; // Get the friendly URL of the user's photos $flickr_meta['PhotosURL'] = $flickr->urls_getUserPhotos($flickr_meta['NSID']); $flickr_meta['Username'] = $token['user']['username']; // find our target photo set $targetsetname = $config[$config['use']]['photoset']; $photosets = $flickr->photosets_getList($flickr_meta['NSID']); foreach ((array)$photosets['photoset'] as $photoset) { if ($photoset['title'] == $targetsetname) { $targetsetid = $photoset['id']; } } if ($targetsetid) { $flickr_meta['Set'] = $targetsetid; return(1); } else { mdl_error("Flickr set \"".$config[$config['use']]['photoset']."\" not found " . "on " . $flickr_meta['Username'] . "'s account." ); return(0); } } function get_target_image ($collection, $pointer) { global $fsdir, $record_meta, $target_dim, $contentdm_server; $record_meta['Image'] = ""; // mdl_error("seeing $collection/$pointer"); return(0); // debugging placeholder /* calculate and retrieve image */ $scale = 10; $filename = "http://$contentdm_server/cgi-bin/getimage.exe?CISOROOT=/$collection&CISOPTR=$pointer&DMSCALE=$scale&DMWIDTH=20000&DMHEIGHT=20000"; // Get an initial image from which we learn the dimensions $jpeg_header_data = get_jpeg_header_data( $filename ); $jpeg_intrinsic_array = get_jpeg_intrinsic_values($jpeg_header_data); $width = $jpeg_intrinsic_array['Image Width']; $height = $jpeg_intrinsic_array['Image Height']; $largest_dimension = ($width > $height) ? $width : $height; $new_scale = ($target_dim * $scale) / $largest_dimension; // Now aim for the image at our target resolution $filename = "http://$contentdm_server/cgi-bin/getimage.exe?CISOROOT=/$collection&CISOPTR=$pointer&DMSCALE=$new_scale&DMWIDTH=20000&DMHEIGHT=20000"; $jpeg_header_data = get_jpeg_header_data( $filename ); $jpeg_intrinsic_array = get_jpeg_intrinsic_values($jpeg_header_data); $record_meta['Width'] = $jpeg_intrinsic_array['Image Width']; $record_meta['Height'] = $jpeg_intrinsic_array['Image Height']; // grab a local copy of the target file $newname = "$collection$pointer-" . date('ymd') . "-$target_dim.jpg"; $ch = curl_init ($filename); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec ($ch); curl_close ($ch); $fp = fopen("$fsdir$newname",'w'); fwrite($fp, $rawdata); fclose($fp); $record_meta['Image'] = $newname; return(1); } function add_record_to_flickr () { global $fsdir, $record_meta, $flickr_meta, $flickr; if(! $flickr) { if (! check_flickr()) { mdl_exit_with_error(); } } $photoid = $flickr->sync_upload( $fsdir.$record_meta['Image'], $record_meta['Title'], $record_meta['Description'], $record_meta['Tags'], 0, 1, 1 ); if ($flickr->getErrorCode()) { mdl_error($flickr->getErrorMsg()); return(0); } $flickr->photosets_addPhoto($flickr_meta['Set'], $photoid); if ($flickr->getErrorCode()) { mdl_error($flickr->getErrorMsg()); return(0); } $record_meta['FlickrPhoto'] = $flickr->photos_getInfo($photoid); $record_meta['FlickrURL'] = $record_meta['FlickrPhoto']['urls']['url'][0]['_content']; $record_meta['FlickrSquare'] = $flickr->buildPhotoURL($record_meta['FlickrPhoto'], "Square"); return(1); }