$container_guid = elgg_extract('container_guid', $vars, elgg_get_page_owner_guid()); $entity = elgg_extract('entity', $vars); $comments_on = elgg_extract('comments_on', $vars, 'On'); $thumbnail_second = elgg_extract('thumbnail_second', $vars); $widget = ''; // inital submit options $submit_options = array('id' => 'simplekaltura-submit', 'name' => 'save', 'value' => elgg_echo('save'), 'class' => 'elgg-button-submit'); // Only include the widget and js when adding if (!$entity) { $widget = elgg_view('simplekaltura/form_elements/ksu_widget'); // Disable the submit button initially, this will be enabled later once a video is selected $submit_options['disabled'] = 'DISABLED'; $submit_options['class'] .= ' elgg-state-disabled'; } else { // Get entry to check status $entry = simplekaltura_get_entry($entity->kaltura_entryid); // Check for ready status if ($entry->status == KalturaEntryStatus::READY) { // Update local entity simplekaltura_update_video($entity); $thumbnail_input = elgg_view('input/simplekaltura_thumbs', array('entity' => $entity)); $thumbnail_content = "<div>\n \t\t\t{$thumbnail_input}\n\t\t\t</div><br />"; } else { echo "<div class='elgg-message elgg-state-notice'>" . elgg_echo('simplekaltura:notconverted') . "</div>"; } } $container_hidden = elgg_view('input/hidden', array('name' => 'container_guid', 'value' => $container_guid)); $entity_hidden = elgg_view('input/hidden', array('name' => 'guid', 'value' => $guid)); // Labels/Input $title_label = elgg_echo('title'); $title_input = elgg_view('input/text', array('id' => 'video_title', 'name' => 'video_title', 'value' => $title));
try { $client = simplekaltura_create_client(true); $entry = $client->mixing->get($v->kaltura_video_id); $xml = new SimpleXMLElement($entry->dataContent); $assets = $xml->VideoAssets->vidAsset[0]; if ($assets) { $attr = get_object_vars($xml->VideoAssets->vidAsset[0]->attributes()); $entry_id = $attr['@attributes']['k_id']; } } catch (Exception $exc) { // do nothing yet... } // if we don't have an entry_id it could be a legit video... if (!$entry_id) { try { $entry = simplekaltura_get_entry($v->kaltura_video_id, true); if ($entry) { $entry_id = $v->kaltura_video_id; } } catch (Exception $exc) { // it's not a mix, and it's not a legit video // not sure what it is so lets leave it alone $v->simplekaltura_cannot_import = 1; continue; } } $v->kaltura_guid = $entry_id; $v->kaltura_entryid = $entry_id; $v->thumbnail_second = 2; $v->comments_on = $v->kaltura_video_comments_on == 'Off' ? 0 : 1; $v->save();
/** * Helper function to update a simplekaltura video object * @param ElggObject $video - The elgg object to update * @param KalturaMediaEntry $entry - The kaltura entry, or null if none * @return bool */ function simplekaltura_update_video($video, $entry = null) { // Don't necessarily need an entry here, if updating an existing video if (!$entry) { // Assume we're grabbing the entry of the current video $entry = simplekaltura_get_entry($video->kaltura_entryid, true); } // Set up an array of metadata mappings to populate $metadata_names = array('duration', 'thumbnailUrl', 'plays', 'views', 'downloadUrl'); // Set metadata foreach ($metadata_names as $name) { create_metadata($video->getGUID(), $name, $entry->{$name}, '', $video->getOwnerGUID(), $video->access_id, FALSE); } // Store the whole shebang just in case (?? not sure if I need this..) create_metadata($video->getGUID(), 'raw_entry', serialize($entry), '', $video->getOwnerGUID(), $video->access_id, FALSE); return true; }