/**
  *When the plugin loads on the admin side, 
  *queue the css file
  *
  *@return void
  */
 public function hookAdminHead()
 {
     if (element_exists(ElementSet::ITEM_TYPE_NAME, 'Player')) {
         $playerElement = $this->_db->getTable("Element")->findByElementSetNameAndElementName("Item Type Metadata", "Player");
         queue_js_string("var playerElementId = " . $playerElement->id . ';');
         queue_js_file('YoutubeImport');
     }
     queue_css_file('YoutubeImport');
 }
Exemplo n.º 2
0
 /**
  *Fetch metadata from a Youtube video and prepare it
  *
  *@param string $itemID The Youtube video ID from which to extract metadata
  *@param object $service The youtube API php interface instance
  *@param int $collection The ID of the collection to which to add the new item
  *@param string $ownerRole The name of the dublin core field to which to 
  *add the Youtube user info
  *@param boolean public Indicates whether the new omeka item should be public
  *@return array An array containing metadata associated with the 
  *given youtube video in the correct format to save as an omeka item,
  *and urls of files associated
  */
 public static function GetVideo($itemID, $service, $collection = 0, $ownerRole = 'Publisher', $public = 0)
 {
     $part = "id,snippet,contentDetails,player,status,recordingDetails";
     $response = $service->videos->listVideos($part, array('id' => $itemID, 'maxResults' => 1));
     if (empty($response)) {
         throw new Exception("No video found.");
     }
     $items = $response->items;
     if (empty($items)) {
         throw new Exception('No video found for itemID ' . $itemID);
     }
     $video = $items[0];
     //todo format date if necessary
     $datePublished = $video['snippet']['publishedAt'];
     try {
         $recordingDetails = $video['recordingDetails'];
     } catch (Exception $e) {
         die('exception');
         $recordingDetails = array();
     }
     //recordingDetails are only returned for authenticated requests, apparently!
     //or maybe users can hide them from the public.
     $dateRecorded = "";
     if (!empty($recordingDetails['RecordingDate'])) {
         $dateRecorded = $recordingDetails['RecordingDate'];
     }
     $spatialCoverage = "";
     if (!empty($recordingDetails['locationDescription'])) {
         $spatialCoverage .= $recordingDetails['locationDescription'] . "<br>";
     }
     if (!empty($recordingDetails['locationDescription'])) {
         $spatialCoverage .= $recordingDetails['locationDescription'] . "<br>";
     }
     if (!empty($recordingDetails['location'])) {
         foreach ($recordingDetails['location'] as $label => $number) {
             $spatialCoverage .= "{$label} = {$number}<br>";
         }
     }
     $publisher = "";
     if (!empty($video['snippet']['channelTitle'])) {
         $publisher .= $video['snippet']['channelTitle'] . "<br>published via YouTube.com";
     }
     if (isset($video['status']['license'])) {
         switch ($video['status']['license']) {
             case "youtube":
                 $license = '<a href="https://www.youtube.com/static?template=terms">Standard YouTube License</a>';
                 break;
             case "creativeCommon":
                 $license = '<a href="http://creativecommons.org/licenses/by/3.0/legalcode">Creative Commons License</a>';
                 break;
             default:
                 $license = "";
         }
     } else {
         $license = "";
     }
     if ($video['contentDetails']['licensedContent']) {
         $license .= "<br>This video represents licensed content on YouTube, meaning that the content has been claimed by a YouTube content partner.";
         $rightsHolder = "Rights reserved by a third party";
     } else {
         $rightsHolder = "";
     }
     $maps = array("Dublin Core" => array("Title" => array($video['snippet']['title']), "Description" => array($video['snippet']['description']), "Date" => array($datePublished), "Source" => array('http://YouTube.com'), "Rights" => array($license)));
     if (!empty($ownerRole)) {
         $maps['Dublin Core'][$ownerRole] = array($publisher);
     }
     if (plugin_is_active('DublinCoreExtended')) {
         $maps["Dublin Core"]["License"] = array($license);
         $maps["Dublin Core"]["Rights Holder"] = array($rightsHolder);
         $maps["Dublin Core"]["Date Submitted"] = array($datePublished);
         //$maps["Dublin Core"]["Date Created"]=array($dateRecorded);
         //$maps["Dublin Core"]["Spatial Coverage"]=array($spatialCoverage);
     }
     if (!element_exists(ElementSet::ITEM_TYPE_NAME, 'Player')) {
         static::_addPlayerElement();
     }
     //      throw new Exception('Metadata element missing for embedded video html');
     $playerHtml = str_replace('/>', '></iframe>', $video['player']['embedHtml']);
     $maps[ElementSet::ITEM_TYPE_NAME]["Player"] = array($playerHtml);
     $Elements = array();
     $db = get_db();
     $elementTable = $db->getTable('Element');
     foreach ($maps as $elementSet => $elements) {
         foreach ($elements as $elementName => $elementTexts) {
             $element = $elementTable->findByElementSetNameAndElementName($elementSet, $elementName);
             $elementID = $element->id;
             $Elements[$elementID] = array();
             if (is_array($elementTexts)) {
                 foreach ($elementTexts as $elementText) {
                     //check for html tags
                     if ($elementText != strip_tags($elementText)) {
                         //element text has html tags
                         $html = "1";
                     } else {
                         //plain text or other non-html object
                         $html = "0";
                     }
                     $Elements[$elementID][] = array('text' => $elementText, 'html' => $html);
                 }
             }
         }
     }
     $tags = "";
     if (isset($video['snippet']->tags)) {
         foreach ($video['snippet']->tags as $tag) {
             $tags .= $tag;
             $tags .= ",";
         }
         $tags = substr($tags, 0, -2);
     }
     $returnPost = array('Elements' => $Elements, 'item_type_id' => '3', 'tags-to-add' => $tags, 'tags-to-delete' => '', 'collection_id' => $collection);
     if ($public) {
         $returnPost['public'] = "1";
     }
     $i = 0;
     $maxwidth = 0;
     foreach ($video['snippet']->thumbnails as $key => $file) {
         if ($file['width'] > $maxwidth) {
             $i = $key;
         }
     }
     $returnFiles = array($video['snippet']->thumbnails->default->url);
     return array('post' => $returnPost, 'files' => $returnFiles);
 }
Exemplo n.º 3
0
 public function testLowerCaseElementName()
 {
     $this->assertFalse(element_exists('Dublin Core', 'title'));
 }