public function checkAction()
 {
     $id = $this->_getParam('id');
     if ($id) {
         $item = $this->_helper->db->getTable('Item')->find($id);
     } else {
         $item = new Item();
     }
     $post = $_POST;
     $item->setPostData($post);
     $duplicates = item_duplicate_check_get_duplicates($item);
     $this->view->duplicates = $duplicates;
 }
 private function _getItem()
 {
     $item = get_record_by_id('Item', (int) $this->getParam('id'));
     if (is_object($item)) {
         $hasItem = true;
     }
     if (get_option('audio_recorder_attachment') == 'file' && $hasItem) {
         return $item;
     }
     //create a new item and attach it as much as possible
     $username = is_object($user = current_user()) ? "{$user->name} ({$user->email})" : "An Anonymous Contributor";
     $username = isset($_POST['audio_recorder_username']) ? $_POST['audio_recorder_username'] : $username;
     $elementTable = get_db()->getTable('Element');
     $creatorElement = $elementTable->findByElementSetNameAndElementName('Dublin Core', 'Creator');
     $elements[$creatorElement->id] = array(array('text' => $username, 'html' => "0"));
     //todo - if record relations is installed,
     //add an appropriate relation
     if (is_object($user) && $username !== $user->name) {
         $contributorElement = $elementTable->findByElementSetNameAndElementName('Dublin Core', 'Contributor');
         $elements[$contributorElement->id] = array(array('text' => "{$user->name} ({$user->email})", 'html' => "0"));
         //todo - if record relations is installed,
         //add an appropriate relation
     }
     $sourceElement = $elementTable->findByElementSetNameAndElementName('Dublin Core', 'Source');
     $elements[$sourceElement->id] = array(array('text' => "Audio Recorder plugin", 'html' => "0"));
     if ($hasItem) {
         $relationElement = $elementTable->findByElementSetNameAndElementName('Dublin Core', 'Relation');
         $elements[$relationElement->id] = array(array('text' => 'This recording describes, or is directly related to, the following item: <br> <a href="' . absolute_url('items/show/' . $item->id) . '">' . metadata($item, array('Dublin Core', 'Title')) . '</a>', 'html' => "1"));
         //todo - if record relations is installed,
         //add an appropriate relation
         $titleElement = $elementTable->findByElementSetNameAndElementName('Dublin Core', 'Title');
         $elements[$titleElement->id] = array(array('text' => "Audio Recording " . date('Y-m-d'), 'html' => "0"));
     }
     $fauxPost = array('Elements' => $elements, 'item_type_id' => '', 'public' => (bool) get_option('audio_recorder_public'));
     $recItem = new Item();
     $recItem->setPostData($fauxPost);
     $recItem->save();
     return $recItem;
 }
 /**
  * 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;
 }
 /**
  * Create a new Omeka item with information from a Flickr image
  *
  *@param string $itemID The Flickr photo ID of the photo to be added
  * @return void
  */
 private function _addPhoto($itemID)
 {
     try {
         $post = self::GetPhotoPost($itemID, $this->f, $this->collection, $this->ownerRole, $this->public);
         $files = self::GetPhotoFiles($itemID, $this->f);
     } catch (Exception $e) {
         throw $e;
     }
     if (!is_array($post) && $post == 'video') {
         return 'video';
     }
     $record = new Item();
     $record->setPostData($post);
     if (!$record->save(false)) {
         throw new Exception("Error saving new omeka item to database");
     }
     try {
         insert_files_for_item($record, 'Url', $files);
     } catch (Exception $e) {
         throw $e;
     }
 }