/**
  * Import a single photo in real time (not in the background).
  *
  * This function relies on the import form output being in the
  * $_POST variable. The form should be validated before calling this.
  *
  * @return bool $success true if no error, false otherwise
  */
 private static function _importSingle()
 {
     //include the import job class, whose static methods will import the photo
     require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'jobs' . DIRECTORY_SEPARATOR . 'import.php';
     //include the phpFlickr library for interfacing with the Flickr API
     require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'phpFlickr' . DIRECTORY_SEPARATOR . 'phpFlickr.php';
     //initialize a Flickr API interface with this plugin's API key
     $f = new phpFlickr(get_option('flickr_api_key'));
     //pull the Flickr url from the form post
     if (isset($_REQUEST['flickrurl'])) {
         $url = $_REQUEST['flickrurl'];
     } else {
         throw new UnexpectedValueException('URL of Flickr photo was not set');
     }
     $photoID = self::_parsePhotoUrl($url);
     if (isset($_REQUEST['flickrcollection'])) {
         $collection = $_REQUEST['flickrcollection'];
     } else {
         $collection = 0;
     }
     if (isset($_REQUEST['flickrpublic'])) {
         $public = $_REQUEST['flickrpublic'];
     } else {
         $public = false;
     }
     if (isset($_REQUEST['flickruserrole'])) {
         $userRole = $_REQUEST['flickruserrole'];
     } else {
         $userRole = 0;
     }
     try {
         //retrive the photo information in the correct format to create a new Omeka item
         $post = FlickrImport_ImportJob::GetPhotoPost($photoID, $f, $collection, $userRole, $public);
         //retrieve the files associated with this photo (the photo itself, mainly)
         //in the correct format to attach to an omeka item
         $files = FlickrImport_ImportJob::GetPhotoFiles($photoID, $f);
     } catch (Exception $e) {
         throw $e;
     }
     if ($post == "video") {
         return false;
     }
     //create the item
     $record = new Item();
     $record->setPostData($post);
     if (!$record->save(false)) {
         throw new Exception($record->getErrors());
     }
     if (!insert_files_for_item($record, 'Url', $files)) {
         throw new Exception("Error attaching files");
     }
     return true;
 }
 /**
  * Import a single video in real time (not in the background).
  *
  * This function relies on the import form output being in the
  * $_POST variable. The form should be validated before calling this.
  *
  * @return bool $success true if no error, false otherwise
  */
 private static function _importSingle()
 {
     require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'import.php';
     require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'Google' . DIRECTORY_SEPARATOR . 'Client.php';
     require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'Google' . DIRECTORY_SEPARATOR . 'Service' . DIRECTORY_SEPARATOR . 'YouTube.php';
     $client = new Google_Client();
     $client->setApplicationName("Omeka_Youtube_Import");
     $client->setDeveloperKey(YoutubeImport_ImportHelper::$youtube_api_key);
     try {
         $service = new Google_Service_YouTube($client);
     } catch (Exception $e) {
         throw $e;
     }
     if (isset($_REQUEST['youtubeurl'])) {
         $url = $_REQUEST['youtubeurl'];
     } else {
         throw new UnexpectedValueException('URL of Youtube video was not set');
     }
     if (isset($_REQUEST['youtubecollection'])) {
         $collection = $_REQUEST['youtubecollection'];
     } else {
         $collection = 0;
     }
     if (isset($_REQUEST['youtubeuserrole'])) {
         $ownerRole = $_REQUEST['youtubeuserrole'];
     } else {
         $ownerRole = 0;
     }
     if (isset($_REQUEST['youtubepublic'])) {
         $public = $_REQUEST['youtubepublic'];
     } else {
         $public = false;
     }
     try {
         $videoID = YoutubeImport_ImportHelper::ParseURL($url);
         $response = YoutubeImport_ImportHelper::GetVideo($videoID, $service, $collection, $ownerRole, $public);
         $post = $response['post'];
         $files = $response['files'];
     } catch (Exception $e) {
         throw $e;
     }
     $record = new Item();
     $record->setPostData($post);
     if (!$record->save(false)) {
         throw new Exception($record->getErrors());
     }
     if (!empty($files) && !empty($record)) {
         if (!insert_files_for_item($record, 'Url', $files)) {
             throw new Exception("Error attaching files");
         }
     }
     return true;
 }