/** * Executes addComment action, which returns a form enabling the insertion of a comment * The request may include 1 fields: entry id. */ protected function executeImpl(kshow $kshow, entry &$entry) { $version = @$_REQUEST["version"]; // it's a path on the disk if (kString::beginsWith($version, ".")) { // someone is trying to hack in the system return sfView::ERROR; } // in case we're making a roughcut out of a regular invite, we start from scratch if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW || $entry->getDataPath($version) === null) { $this->xml_content = "<xml></xml>"; return; } // fetch content of file from disk - it should hold the XML $file_name = myContentStorage::getFSContentRootPath() . "/" . $entry->getDataPath($version); //echo "[$file_name]"; if (kString::endsWith($file_name, "xml")) { if (file_exists($file_name)) { $this->xml_content = kFile::getFileContent($file_name); // echo "[" . $this->xml_content . "]" ; } else { $this->xml_content = "<xml></xml>"; } myMetadataUtils::updateEntryForPending($entry, $version, $this->xml_content); } else { return sfView::ERROR; } // this is NOT an xml file we are looking for ! }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $entry_id = $this->getP("entry_id"); $kshow_id = $this->getP("kshow_id"); $show_entry_id = $this->getP("show_entry_id"); // Make sure the request is for a ready roughcut $c = entryPeer::getCriteriaFilter()->getFilter(); $c->addAnd(entryPeer::STATUS, entryStatus::READY, Criteria::EQUAL); list($kshow, $show_entry, $error, $error_obj) = myKshowUtils::getKshowAndEntry($kshow_id, $show_entry_id); if ($error_obj) { $this->addError($error_obj); return; } $entry = entryPeer::retrieveByPK($entry_id); if (!$entry) { $this->addError(APIErrors::INVALID_ENTRY_ID, "entry", $entry_id); return; } $metadata = $kshow->getMetadata(); $relevant_kshow_version = 1 + $kshow->getVersion(); // the next metadata will be the first relevant version for this new entry $version_info = array(); $version_info["KuserId"] = $puser_kuser->getKuserId(); $version_info["PuserId"] = $puser_id; $version_info["ScreenName"] = $puser_kuser->getPuserName(); $new_metadata = myMetadataUtils::addEntryToMetadata($metadata, $entry, $relevant_kshow_version, $version_info); $entry_modified = true; if ($new_metadata) { // TODO - add thumbnail only for entries that are worthy - check they are not moderated ! $thumb_modified = myKshowUtils::updateThumbnail($kshow, $entry, false); if ($thumb_modified) { $new_metadata = myMetadataUtils::updateThumbUrlFromMetadata($new_metadata, $entry->getThumbnailUrl()); } // it is very important to increment the version count because even if the entry is deferred // it will be added on the next version if (!$kshow->getHasRoughcut()) { // make sure the kshow now does have a roughcut $kshow->setHasRoughcut(true); $kshow->save(); } $kshow->setMetadata($new_metadata, true); } $this->addMsg("entry", objectWrapperBase::getWrapperClass($entry, objectWrapperBase::DETAIL_LEVEL_REGULAR)); $this->addMsg("kshow", objectWrapperBase::getWrapperClass($kshow, objectWrapperBase::DETAIL_LEVEL_REGULAR)); $this->addMsg("metadata", $new_metadata); }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { if (!$puser_kuser) { $this->addError(APIErrors::INVALID_USER_ID, $puser_id); return; } $entry_id = $this->getPM("entry_id"); $entry = entryPeer::retrieveByPK($entry_id); // TODO - verify the user is allowed to modify the entry $source_entry_id = $this->getP("source_entry_id"); if ($source_entry_id) { $source_entry = entryPeer::retrieveByPK($source_entry_id); if (!$source_entry) { return; } } else { $source_entry = $entry; } $time_offset = $this->getP("time_offset", -1); if (!myEntryUtils::createThumbnailFromEntry($entry, $source_entry, $time_offset)) { $this->addError(APIErrors::INVALID_ENTRY_TYPE, "ENTRY_TYPE_MEDIACLIP"); return; } if ($entry->getType() == entryType::MIX) { /* $roughcutPath = myContentStorage::getFSContentRootPath() . $entry->getDataPath(); // replaced__getDataPath $xml_doc = new DOMDocument(); $xml_doc->load( $roughcutPath ); if (myMetadataUtils::updateThumbUrl($xml_doc, $entry->getThumbnailUrl())) $xml_doc->save($roughcutPath); */ $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); $xml_doc = new DOMDocument(); $xml_doc->loadXML(kFileSyncUtils::file_get_contents($sync_key)); if (myMetadataUtils::updateThumbUrl($xml_doc, $entry->getThumbnailUrl())) { $entry->setMetadata(null, $xml_doc->saveXML(), true, null, null); //$entry->getVersion() ); } myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE_THUMBNAIL, $entry); } $wrapper = objectWrapperBase::getWrapperClass($entry, objectWrapperBase::DETAIL_LEVEL_DETAILED); $wrapper->removeFromCache("entry", $entry->getId()); $this->addMsg("entry", $wrapper); }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $entry_id = $this->getP("entry_id"); $kshow_id = $this->getP("kshow_id"); // Make sure the request is for a ready roughcut $c = entryPeer::getCriteriaFilter()->getFilter(); $c->addAnd(entryPeer::STATUS, entryStatus::READY, Criteria::EQUAL); list($kshow, $entry, $error, $error_obj) = myKshowUtils::getKshowAndEntry($kshow_id, $entry_id); if ($error_obj) { $this->addError($error_obj); return; } $version = $this->getP("version"); // it's a path on the disk if (kString::beginsWith($version, ".")) { // someone is trying to hack in the system return sfView::ERROR; } elseif ($version == "-1") { $version = null; } // in case we're making a roughcut out of a regular invite, we start from scratch $entry_data_path = kFileSyncUtils::getLocalFilePathForKey($entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version)); //replaced__getDataPath if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW || $entry_data_path === null) { $this->xml_content = "<xml></xml>"; return; } $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version); $file_name = kFileSyncUtils::getReadyLocalFilePathForKey($sync_key, false); // fetch content of file from disk - it should hold the XML if (kString::endsWith($file_name, "xml")) { $xml_content = kFileSyncUtils::file_get_contents($sync_key, false, false); if (!$xml_content) { $xml_content = "<xml></xml>"; } myMetadataUtils::updateEntryForPending($entry, $version, $xml_content); $this->addMsg("metadata", $xml_content); } else { $this->addError(APIErrors::INVALID_FILE_NAME, $file_name); } }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { if (!$puser_kuser) { $this->addError(APIErrors::INVALID_USER_ID, $puser_id); return; } $entry_id = $this->getPM("entry_id"); $entry = entryPeer::retrieveByPK($entry_id); // TODO - verify the user is allowed to modify the entry if ($entry->getKshowId() === kshow::SANDBOX_ID) { $this->addError(APIErrors::SANDBOX_ALERT); return; } $entry->setThumbnail(".jpg"); $entry->setCreateThumb(false); $entry->save(); if (isset($HTTP_RAW_POST_DATA)) { $thumb_data = $HTTP_RAW_POST_DATA; } else { $thumb_data = file_get_contents("php://input"); } $thumb_data_size = strlen($thumb_data); $fileSyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $fileSync = FileSync::createForFileSyncKey($fileSyncKey); kFileSyncUtils::file_put_contents($fileSyncKey, $thumb_data); // update the metadata in case of a roughcut if ($entry->getType() == entryType::MIX) { $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); $xml_doc = new DOMDocument(); $xml_doc->loadXML(kFileSyncUtils::file_get_contents($sync_key)); if (myMetadataUtils::updateThumbUrl($xml_doc, $entry->getThumbnailUrl())) { $entry->setMetadata(null, $xml_doc->saveXML(), true, null, null); //$entry->getVersion() ); } myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE_THUMBNAIL, $entry); } $this->res = $entry->getBigThumbnailUrl(); $wrapper = objectWrapperBase::getWrapperClass($entry, objectWrapperBase::DETAIL_LEVEL_REGULAR); $wrapper->removeFromCache("entry", $entry->getId()); $this->addMsg("entry", $wrapper); }
public function fixMetadata($increment_version = true, $content = null, $total_duration = null, $specific_version = null) { // check that the file of the desired version really exists $content_dir = myContentStorage::getFSContentRootPath(); if (!$content) { $content = $this->getMetadata($specific_version); } if ($increment_version) { // increment the counter of the file $this->setData(parent::getData()); } $file_name = kFileSyncUtils::getLocalFilePathForKey($this->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $specific_version)); // replaced__getDataPath $duration = $total_duration ? $total_duration : myMetadataUtils::getDuration($content); $this->setLengthInMsecs($duration * 1000); $total_duration = null; $editor_type = null; $version = myContentStorage::getVersion($file_name); $fixed_content = myFlvStreamer::fixMetadata($content, $version, $total_duration, $editor_type); $this->save(); $sync_key = $this->getSyncKey(self::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version); kFileSyncUtils::file_put_contents($sync_key, $fixed_content, false); // replaced__setFileContent return $fixed_content; }
public static function updatePendingEntries(&$xml_doc) { $really_pending_entries = array(); list($pending_str, $pending_arr) = myMetadataUtils::getPending($xml_doc); // $entries_in_roughcut = myMetadataUtils::getAllEntries( $xml_doc ); $pending_arr_not_in_roughcut = $pending_arr; //array(); // we should not attemp to match pending entries with the list in the XML - they will never be there // assuming they are really pending /* foreach ( $pending_arr as $pending ) { if ( in_array ( $pending , $entries_in_roughcut ) ) { // we need to keep this entry pending - it's used in the xml $pending_arr_not_in_roughcut[] = $pending; } } */ if (count($pending_arr_not_in_roughcut) > 0) { // get all the enrties that are really pending: $pending = entryPeer::retrievePendingEntries($pending_arr_not_in_roughcut); foreach ($pending as $entry) { $really_pending_entries[] = $entry->getId(); } } myMetadataUtils::setPending($xml_doc, $really_pending_entries); }
public static function createRoughcutThumbnail($roughcut, $source_entry, $should_force = false) { if (!$roughcut) { return false; } $res = self::createThumbnail($roughcut, $source_entry, $should_force); if ($res) { $content = $roughcut->getDataContent(); if ($content) { $new_metadata = myMetadataUtils::updateThumbUrlFromMetadata($content, $source_entry->getThumbnailUrl()); $roughcut->setMediaType(entry::ENTRY_MEDIA_TYPE_SHOW); $roughcut->setDataContent($new_metadata, false, true); $roughcut->save(); return $res; } } return false; }
public static function createKEditorMetadata($kshow, $show_entry, $entries) { $vidassets = ''; $overlays = ''; $totalTime = 0; $soundTimes = array(); $lastSoundTime = 0; $isPrevVideo = null; $addLastFadeoutTime = 0; foreach ($entries as $entry) { $assetStartTime = $totalTime; $media_type = $entry->getMediaType(); if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE || $media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) { $startTime = 0; $lenTime = $entry->getLengthInMsecs() / 1000; if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) { $isVideo = true; $media_type_str = 'VIDEO'; } else { if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) { $isVideo = false; $media_type_str = 'IMAGE'; $lenTime = 4; } else { continue; } } $addLastFadeoutTime = 1; $totalTime += $lenTime - 1; $entry_id = $entry->getId(); $media_name = $entry->getName(); $media_url = $entry->getDataUrl(); $relMedia_url = strstr($media_url, "/content"); $vidassets .= '<vidAsset k_id="' . $entry_id . '" type="' . $media_type_str . '" name="' . $media_name . '" url="' . $media_url . '">' . '<StreamInfo file_name="' . $relMedia_url . '" start_time="' . $startTime . '" len_time="' . $lenTime . '" posX="0" posY="0" start_byte="-1" end_byte="-1" total_bytes="-1" real_seek_time="-1" volume="1" pan="0" isSingleFrame="0" real_start_byte="-1" real_end_byte="-1"/>' . '<EndTransition type="dissolve" StartTime="' . ($lenTime - 1) . '" length="1">' . '<arguments>' . '<name>dissolve</name>' . '<version>1.00</version>' . '<arguments/>' . '</arguments>' . '</EndTransition>' . '</vidAsset>'; } if ($isPrevVideo === null) { $isPrevVideo = $isVideo; } if ($isVideo != $isPrevVideo) { $endTime = $isVideo ? $assetStartTime : $assetStartTime + 1; $soundTimes[] = array("type" => $isPrevVideo, "startTime" => $lastSoundTime, "endTime" => $endTime); $isPrevVideo = $isVideo; $lastSoundTime = $endTime; } } $totalTime += $addLastFadeoutTime; $soundTimes[] = array("type" => $isPrevVideo, "startTime" => $lastSoundTime, "endTime" => $totalTime); // add soundtrack //echo print_r($soundTimes, true); $audassets = ''; $entry = entryPeer::retrieveByPK(209); $loop = true; $quiet = true; $volume = 1; $quietVolume = $quiet ? $volume * 0.2 : 0; $lenTime = $entry->getLengthInMsecs() / 1000; if ($entry && $totalTime) { $entry_id = $entry->getId(); $media_name = $entry->getName(); $media_url = $entry->getDataUrl(); $relMedia_url = strstr($media_url, "/content"); $startTime = 0; $soundTime = current($soundTimes); $currentVolume = $soundTime["type"] ? $quietVolume : $volume; // the first sound time is always at the start of the first clip. // because every clip gets a volPoint at its begining and end we can just skip this entry $soundTime = next($soundTimes); while ($startTime < $totalTime) { $clippedLenTime = min($totalTime - $startTime, $lenTime); $endTime = $startTime + $clippedLenTime; // always add the required volume at the start of the clip $volPoints = '<VolumePoints><VolumePoint time="0" volume="' . $currentVolume . '"/>'; // add any volume changes found within the duration of the current clip while ($soundTime !== FALSE && $soundTime['startTime'] < $endTime) { // make a spike by putting the current volume and then the next one within 0.1 seconds $volPoints .= '<VolumePoint time="' . ($soundTime["startTime"] - $startTime - 0.1) . '" volume="' . $currentVolume . '"/>'; $currentVolume = $soundTime["type"] ? $quietVolume : $volume; $volPoints .= '<VolumePoint time="' . ($soundTime["startTime"] - $startTime) . '" volume="' . $currentVolume . '"/>'; $soundTime = next($soundTimes); } // always add the required volume at the end of the clip $volPoints .= '<VolumePoint time="' . $clippedLenTime . '" volume="' . $currentVolume . '"/></VolumePoints>'; $audassets .= '<AudAsset k_id="' . $entry_id . '" type="AUDIO" name="' . $media_name . '" url="' . $media_url . '">' . '<StreamInfo file_name="' . $relMedia_url . '" start_time="0" len_time="' . $clippedLenTime . '" posX="0" posY="0" start_byte="-1" end_byte="-1" total_bytes="-1" real_seek_time="-1" volume="' . $volume . '" pan="0" isSingleFrame="0" real_start_byte="-1" real_end_byte="-1"/>' . '<EndTransition type="None" StartTime="' . $lenTime . '" length="0"/>' . $volPoints . '</AudAsset>'; if (!$loop) { break; } $startTime += $lenTime; } } $xmlData = '<?xml version="1.0"?>' . "<xml>" . "<MetaData>" . "<SeqDuration>{$totalTime}</SeqDuration>" . "<ShowVersion></ShowVersion>" . "</MetaData>" . "<VideoAssets>{$vidassets}</VideoAssets><AudioAssets>{$audassets}</AudioAssets><VoiceAssets/><LoaderObjectAssets/>" . "<Plugins><Overlays>{$overlays}</Overlays></Plugins>" . "</xml>"; myMetadataUtils::setMetadata($xmlData, $kshow, $show_entry); }
public static function updateAllMetadataVersionsRelevantForEntry($entry) { // TODO - null entry $kshow = $entry->getKshow(); if (!$kshow) { return null; } // TODO - null kshow $show_entry = $kshow->getShowEntry(); if (!$show_entry) { return null; } $show_entry->decInCustomData("pending_entries"); $show_entry->save(); // entries can be os status ENTRY_STATUS_READY or ENTRY_STATUS_ERROR_CONVERTING $status = $entry->getStatus(); KalturaLog::log("updateAllMetadataVersionsRelevantForEntry [" . $entry->getId() . "] with status [" . $status . "]"); $metadata = $show_entry->getMetadata(); if ($metadata) { $new_metadata = myMetadataUtils::addEntryToMetadata($metadata, $entry); if ($new_metadata) { $show_entry->setDataContent($new_metadata); $show_entry->save(); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE, $entry); } } KalturaLog::log("updateAllMetadataVersionsRelevantForEntry [" . $entry->getId() . "] created a new version"); return true; }
public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { $entry_id = $this->getP("entry_id"); $kshow_id = $this->getP("kshow_id"); list($kshow, $entry, $error, $error_obj) = myKshowUtils::getKshowAndEntry($kshow_id, $entry_id); if ($error_obj) { $this->addError($error_obj); return; } $kshow_id = $kshow->getId(); if ($kshow_id === kshow::SANDBOX_ID) { $this->addError(APIErrors::SANDBOX_ALERT); return; } // TODO - think what is the best way to verify the privileges - names and parameters that are initially set by the partner at // startsession time if (!$this->isOwnedBy($kshow, $puser_kuser->getKuserId())) { $this->verifyPrivileges("edit", $kshow_id); } // user was granted explicit permissions when initiatd the ks // this part overhere should be in a more generic place - part of the services $multiple_roghcuts = Partner::allowMultipleRoughcuts($partner_id); $likuser_id = $puser_kuser->getKuserId(); $isIntro = $kshow->getIntroId() == $entry->getId(); if ($multiple_roghcuts) { // create a new entry in two cases: // 1. the user saving the roughcut isnt the owner of the entry // 2. the entry is an intro and the current entry is not show (probably an image or video) if ($entry->getKuserId() != $likuser_id || $isIntro && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW) { // TODO: add security check to whether multiple roughcuts are allowed // create a new roughcut entry by cloning the original entry $entry = myEntryUtils::deepClone($entry, $kshow_id, false); $entry->setKuserId($likuser_id); $entry->setCreatorKuserId($puser_kuser->getKuserId()); $entry->setCreatedAt(time()); $entry->setMediaType(entry::ENTRY_MEDIA_TYPE_SHOW); $entry->save(); } } $xml_content = "<xml><EntryID>" . $entry->getId() . "</EntryID></xml>"; if ($isIntro) { $kshow->setIntroId($entry->getId()); } else { $kshow->setShowEntryId($entry->getId()); $has_roughcut = $this->getP("HasRoughCut", "1", true); if ($has_roughcut === "0") { $kshow->setHasRoughcut(false); $kshow->save(); $this->addMsg("saved_entry", $entry->getId()); return; } } $content = $this->getP("xml"); $update_kshow = false; if ($content != NULL) { $version_info = array(); $version_info["KuserId"] = $puser_kuser->getKuserId(); $version_info["PuserId"] = $puser_id; $version_info["ScreenName"] = $puser_kuser->getPuserName(); list($xml_content, $comments, $update_kshow) = myMetadataUtils::setMetadata($content, $kshow, $entry, false, $version_info); } else { $comments = ""; // if there is no xml - receive it from the user $this->debug = true; return "text/html; charset=utf-8"; } $this->addMsg("xml", $xml_content); $this->addMsg("saved_entry", $entry->getId()); $this->addDebug("comment", $comments); }
/** * Executes addComment action, which returns a form enabling the insertion of a comment * The request may include 1 fields: entry id. */ protected function executeImpl(kshow $kshow, entry &$entry) { $kshow_id = $kshow->getId(); if ($this->partner_id != null) { // this part overhere should be in a more generic place - part of the services $multiple_roghcuts = Partner::allowMultipleRoughcuts($this->partner_id); $likuser_id = $this->getLoggedInUserId(); } else { // is the logged-in-user is not an admin or the producer - check if show can be published $likuser_id = $this->getLoggedInUserId(); $multiple_roghcuts = true; } if (!$likuser_id) { return $this->securityViolation($kshow->getId()); } $isIntro = $kshow->getIntroId() == $entry->getId(); if ($multiple_roghcuts) { // create a new entry in two cases: // 1. the user saving the roughcut isnt the owner of the entry // 2. the entry is an intro and the current entry is not show (probably an image or video) if ($entry->getKuserId() != $likuser_id || $isIntro && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_SHOW) { // TODO: add security check to whether multiple roughcuts are allowed // create a new roughcut entry by cloning the original entry $entry = myEntryUtils::deepClone($entry, $kshow_id, false); $entry->setKuserId($likuser_id); $entry->setCreatorKuserId($likuser_id); $entry->setCreatedAt(time()); $entry->setMediaType(entry::ENTRY_MEDIA_TYPE_SHOW); $entry->save(); } } /* $viewer_type = myKshowUtils::getViewerType($kshow, $likuser_id); if ( $viewer_type != KshowKuser::KSHOWKUSER_VIEWER_PRODUCER && ( ! $kshow->getCanPublish() ) ) { // ERROR - attempting to publish a non-publishable show return $this->securityViolation( $kshow->getId() ); } */ $this->xml_content = "<xml><EntryID>" . $entry->getId() . "</EntryID></xml>"; if ($isIntro) { $kshow->setIntroId($entry->getId()); } else { $kshow->setShowEntryId($entry->getId()); $has_roughcut = @$_REQUEST["HasRoughCut"]; if ($has_roughcut === "0") { $kshow->setHasRoughcut(false); $kshow->save(); return; } } $content = @$_REQUEST["xml"]; $update_kshow = false; if ($content != NULL) { list($xml_content, $this->comments, $update_kshow) = myMetadataUtils::setMetadata($content, $kshow, $entry); // Send an email alert to producer if ($kshow->getProducerId() != $likuser_id) { // don't send producer alerts when the producer is the editor alertPeer::sendEmailIfNeeded($kshow->getProducerId(), alert::KALTURAS_PRODUCED_ALERT_TYPE_ROUGHCUT_CREATED, array('screenname' => $this->getUser()->getAttribute('screenname'), 'kshow_name' => $kshow->getName(), 'kshow_id' => $kshow->getId())); } // TODO: efficiency: see if there is a wa to search for contributors based on some other method than full entry table scan // Send email alerts to contributors $c = new Criteria(); $c->add(entryPeer::KSHOW_ID, $kshow_id); $c->add(entryPeer::KUSER_ID, $likuser_id, Criteria::NOT_EQUAL); // the current user knows they just edited $c->addAnd(entryPeer::KUSER_ID, $kshow->getProducerId(), Criteria::NOT_EQUAL); // the producer knows they just edited $c->add(entryPeer::TYPE, entryType::MEDIA_CLIP); $c->addGroupByColumn(entryPeer::KUSER_ID); $entries = entryPeer::doSelect($c); $already_received_alert_array = array(); foreach ($entries as $entry) { alertPeer::sendEmailIfNeeded($entry->getKuserId(), alert::KALTURAS_PARTOF_ALERT_TYPE_ROUGHCUT_CREATED, array('screenname' => $this->getUser()->getAttribute('screenname'), 'kshow_name' => $kshow->getName(), 'kshow_id' => $kshow->getId())); $already_received_alert_array[$entry->getKuserId()] = true; } // send email alert to subscribers $c = new Criteria(); $c->add(KshowKuserPeer::KSHOW_ID, $kshow_id); //only subsribers of this show $c->add(KshowKuserPeer::KUSER_ID, $likuser_id, Criteria::NOT_EQUAL); // the current user knows they just edited $c->add(KshowKuserPeer::SUBSCRIPTION_TYPE, KshowKuser::KSHOW_SUBSCRIPTION_NORMAL); // this table stores other relations too $subscriptions = KshowKuserPeer::doSelect($c); foreach ($subscriptions as $subscription) { if (!isset($already_received_alert_array[$subscription->getKuserId()])) { // don't send emails to subscribed users who are also contributors alertPeer::sendEmailIfNeeded($subscription->getKuserId(), alert::KALTURAS_SUBSCRIBEDTO_ALERT_TYPE_ROUGHCUT_CREATED, array('screenname' => $this->getUser()->getAttribute('screenname'), 'kshow_name' => $kshow->getName(), 'kshow_id' => $kshow->getId())); } } if ($this->debug) { return "text/html; charset=utf-8"; } } else { $this->comments = ""; // if there is no xml - receive it from the user $this->debug = true; $file_name = myContentStorage::getFSContentRootPath() . "/" . $entry->getDataPath(); //$this->xml_content = kFile::getFileContent( $file_name ); return "text/html; charset=utf-8"; } }
/** Will allow creation of multiple entries ASSUME - the prefix of the entries is entryX_ where X is the index starting at 1 */ public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser) { // $logger = sfLogger::getInstance(); self::$escape_text = true; /* if ( !$puser_kuser ) { $this->addError( "No such user ..." ); return; } */ // TODO - validate if the user can add entries to this kshow $kshow_id = $this->getP("kshow_id"); $show_entry_id = $this->getP("show_entry_id"); $conversion_quality = $this->getP("conversionquality"); // must be all lower case // for now - by default use quick_edit $partner = PartnerPeer::retrieveByPK($partner_id); for ($i = 0; $i <= $partner->getAddEntryMaxFiles(); ++$i) { if ($i == 0) { $prefix = $this->getObjectPrefix() . "_"; } else { $prefix = $this->getObjectPrefix() . "{$i}" . "_"; } $source = $this->getP($prefix . "source"); $filename = $this->getP($prefix . "filename"); if ($source != entry::ENTRY_MEDIA_SOURCE_WEBCAM || !$filename) { continue; } $content = myContentStorage::getFSContentRootPath(); $entryFullPath = "{$content}/content/webcam/{$filename}.flv"; if (!file_exists($entryFullPath)) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()); if ($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } $this->addError(APIErrors::INVALID_FILE_NAME, $filename); return; } } if (strpos($kshow_id, 'entry-') !== false && !$show_entry_id) { $show_entry_id = substr($kshow_id, 6); } $screen_name = $this->getP("screen_name"); $site_url = $this->getP("site_url"); $null_kshow = true; if ($show_entry_id) { // in this case we have the show_entry_id (of the relevant roughcut) - it suppresses the kshow_id $show_entry = entryPeer::retrieveByPK($show_entry_id); if ($show_entry) { $kshow_id = $show_entry->getKshowId(); } else { $kshow_id = null; } } if ($kshow_id === kshow::SANDBOX_ID) { $this->addError(APIErrors::SANDBOX_ALERT); return; } $default_kshow_name = $this->getP("entry_name", null); if (!$default_kshow_name) { $default_kshow_name = $this->getP("entry1_name", null); } if ($kshow_id == kshow::KSHOW_ID_USE_DEFAULT) { // see if the partner has some default kshow to add to $kshow = myPartnerUtils::getDefaultKshow($partner_id, $subp_id, $puser_kuser, null, false, $default_kshow_name); $null_kshow = false; if ($kshow) { $kshow_id = $kshow->getId(); } } elseif ($kshow_id == kshow::KSHOW_ID_CREATE_NEW) { // if the partner allows - create a new kshow $kshow = myPartnerUtils::getDefaultKshow($partner_id, $subp_id, $puser_kuser, null, true, $default_kshow_name); $null_kshow = false; if ($kshow) { $kshow_id = $kshow->getId(); } } else { $kshow = kshowPeer::retrieveByPK($kshow_id); } if (!$kshow) { // the partner is attempting to add an entry to some invalid or non-existing kwho $this->addError(APIErrors::INVALID_KSHOW_ID, $kshow_id); return; } // find permissions from kshow $permissions = $kshow->getPermissions(); $kuser_id = $puser_kuser->getKuserId(); // TODO - once the CW $quick_edit = myPolicyMgr::getPolicyFor("allowQuickEdit", $kshow, $partner); // let the user override the quick_edit propery if ($this->getP("quick_edit") == '0' || $this->getP("quick_edit") == "false") { $quick_edit = false; } if ($quick_edit == '0' || $quick_edit === "false" || !$quick_edit || $quick_edit == false) { KalturaLog::err('$quick_edit: [' . $quick_edit . ']'); $quick_edit = false; //$quick_edit = true; } // works in one of 2 ways: // 1. get no requested name - will create a new kshow and return its details // 2. get some name - tries to fetch by name. if already exists - return it $new_entry_count = 0; $entries = array(); $notification_ids = array(); $notifications = array(); $field_level = $this->isAdmin() ? 2 : 1; $updateable_fields = null; $imported_entries_count = 0; for ($i = 0; $i <= $partner->getAddEntryMaxFiles(); ++$i) { if ($i == 0) { $prefix = $this->getObjectPrefix() . "_"; } else { $prefix = $this->getObjectPrefix() . "{$i}" . "_"; } $file_name = $this->getP($prefix . "realFilename"); if (!($this->getP($prefix . "name") || $file_name)) { continue; } // get the new properties for the kuser from the request $entry = new entry(); $obj_wrapper = objectWrapperBase::getWrapperClass($entry, 0); if (!$updateable_fields) { $updateable_fields = $obj_wrapper->getUpdateableFields($field_level); } // fill the entry from request $fields_modified = baseObjectUtils::fillObjectFromMap($this->getInputParams(), $entry, $prefix, $updateable_fields); // check that mandatory fields were set // TODO KalturaLog::err("addentry: fields_modified: " . print_r($fields_modified, true)); $entry_source = $entry->getSource(); if (!$entry->getType()) { // this is the default for backward compatiblity $entry->setType(entryType::MEDIA_CLIP); } $token = $this->getKsUniqueString(); $entry_full_path = ""; if ($entry_source == entry::ENTRY_MEDIA_SOURCE_FILE) { $entry->setSourceLink($file_name); $file_alias = $this->getP($prefix . "filename"); $file_extension = strtolower(pathinfo($this->getP($prefix . "realFilename"), PATHINFO_EXTENSION)); $entry_full_path = myUploadUtils::getUploadPath($token, $file_alias, null, $file_extension); if (!file_exists($entry_full_path)) { KalturaLog::err("Invalid UPLOAD PATH [" . $entry_full_path . "] while trying to add entry for partner id [" . $partner_id . "] with token [" . $token . "] & original name [" . $this->getP($prefix . "name") . "]"); $this->addError(APIErrors::INVALID_FILE_NAME); continue; } myEntryUtils::setEntryTypeAndMediaTypeFromFile($entry, $entry_full_path); } // No reason to rais the error // Remarked by Tan-Tan // // // when we reached this point the type and media type must be set // if ($entry->getType() == entryType::AUTOMATIC || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUTOMATIC) // { // $this->addError ( APIErrors::CANNOT_USE_ENTRY_TYPE_AUTO_IN_IMPORT ); // continue; // } // limit two kinds of media // 1. not images - video/audio which are big files // 2. media which wasnt directly uploaded by the owner (the owner real content) if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_IMAGE && $entry_source != entry::ENTRY_MEDIA_SOURCE_FILE) { if ($imported_entries_count >= 4) { continue; } ++$imported_entries_count; } // the conversion_quality is set once for the whole list of entries if ($conversion_quality) { $entry->setConversionQuality($conversion_quality); } else { // HACK - if the conversion_quality was not set in the proper way - // see if the partner_data holds a hack - string that starts with conversionQuality= - this is set when the CW is opened in the KMC // the conversionQuality is of format conversionQuality=XXX;<the rest of the text> // if (kString::beginsWith($entry->getPartnerData(), "conversionQuality:")) { $partner_data_arr = explode(";", $entry->getPartnerData(), 2); $conversion_quality_arr = explode(":", $partner_data_arr[0]); $conversion_quality = @$conversion_quality_arr[1]; // the value of the conversion_quality $entry->setPartnerData(@$partner_data_arr[1]); // the rest of the string $entry->setConversionQuality($conversion_quality); } } $insert = true; $entry_modified = false; $create_entry = true; // I don't remember why we set the kshow to null every time ... // but when we fetched it automatically - hang on to it ! if ($null_kshow) { $kshow = null; } if ($entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_USER_CLIPS || $entry_source == "100") { if ($entry_source == "100") { $entry_id = $this->getP("media{$i}_id"); } else { $entry_id = $this->getP($prefix . "id"); } // $this->getP ( $prefix . "url" ); if ($entry_id === null) { $entry_id = $entry->getMediaId(); } if ($entry_id) { $entry = entryPeer::retrieveByPK($entry_id); if ($entry) { $create_entry = false; $insert = false; } else { $this->addError(APIErrors::INVALID_ENTRY_ID, $this->getObjectPrefix(), $entry_id); return; } } } $new_entry_count++; if ($create_entry) { $entry->setPartnerId($partner_id); $entry->setSubpId($subp_id); $entry->setKuserId($kuser_id); $entry->setCreatorKuserId($kuser_id); $entry->setKshowId($kshow_id); $entry->setSiteUrl($site_url); $entry->setScreenName($screen_name); if ($this->getGroup()) { $entry->setGroupId($this->getGroup()); } if ($entry->getPermissions() === null) { $entry->setPermissions($permissions); } // inherited from the enclosing kshow $entry->setDefaultModerationStatus(); $entry->save(); $entry_modified = true; if (!$entry->getName()) { if ($file_name) { // TODO - fix the file_name to fit $entry->setName($file_name); } else { $entry->setName($partner_prefix . $entry->getId()); } $entry_modified = true; } // TODO - decide on file naming mechanism !! // there are 3 types of insert: // 1. upload - the file is assumed to be in the upload directory and it's name is explicitly set in the fname$i param // 2. webcam - the file is assumed to be in the webcam directory and it's name is explicitly set in the fname$i param // 3. URL - the url is given in the entry_url$i param /* $media_source = $this->getParam('entry_media_source'); $media_type = $this->getParam('entry_media_type'); $entry_url = $this->getParam('entry_url'); $entry_source_link = $this->getParam('entry_source_link'); $entry_fileName = $this->getParam('entry_data'); $entry_thumbNum = $this->getParam('entry_thumb_num', 0); $entry_thumbUrl = $this->getParam('entry_thumb_url', ''); $entry_from_time = $this->getParam('entry_from_time', 0); $entry_to_time = $this->getParam('entry_to_time', 0); $should_copy = $this->getParam('should_copy' , false ); $skip_conversion = $this->getParam('skip_conversion' , false ); */ $paramsArray = array('entry_media_source' => $entry->getSource(), 'entry_media_type' => $entry->getMediaType()); // $entry_source = $entry->getSource() ; if ($entry_source == entry::ENTRY_MEDIA_SOURCE_FILE) { $paramsArray["entry_full_path"] = $entry_full_path; } elseif ($entry_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) { $file_alias = $this->getP($prefix . "filename"); $paramsArray["webcam_suffix"] = $file_alias; $paramsArray['entry_from_time'] = $this->getP($prefix . "fromTime", 0); $paramsArray['entry_to_time'] = $this->getP($prefix . "toTime", 0); } elseif ($entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_PARTNER || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_PARTNER_KSHOW || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_KSHOW || $entry_source == entry::ENTRY_MEDIA_SOURCE_KALTURA_USER_CLIPS) { // optimize - no need to actually go through the import and conversion phase // find the source entry_id from the url /* $entry_url = $this->getP ( $prefix . "url" ); $entry_thumb_url = $this->getP ( $prefix . "thumbUrl" ); if ( myEntryUtils::copyData( $entry_url , $entry_thumb_url , $entry ) ) */ $source_entry_id = $this->getP("media{$i}_id"); // $this->getP ( $prefix . "url" ); if ($source_entry_id === null) { $source_entry_id = $entry->getMediaId(); } if (myEntryUtils::copyData($source_entry_id, $entry)) { // copy worked ok - no need to use insertEntryHelper //$entry->setStatus ( entryStatus::READY ); // force the data to be ready even if the policy is to moderate - this is kaltura's content and was already approved // (roman) true argument removed, so kaltura's content will be moderated according to partner's moderation settings $entry->setStatusReady(); $insert = false; $entry_modified = true; $entry->save(); } } elseif ($entry_source == entry::ENTRY_MEDIA_SOURCE_URL || in_array($entry_source, myMediaSourceFactory::getAllMediaSourceProvidersIds())) { // the URL is relevant $paramsArray["entry_url"] = $this->getP($prefix . "url"); $paramsArray["entry_thumb_url"] = $this->getP($prefix . "thumbUrl"); // TODO - these fields are already set in the entry - // the code in myInsertEntryHelper is redundant $paramsArray["entry_license"] = $entry->getLicenseType(); $paramsArray["entry_credit"] = $entry->getCredit(); $paramsArray["entry_source_link"] = $entry->getSourceLink(); $paramsArray["entry_tags"] = $entry->getTags(); } else { $this->addError(APIErrors::UNKNOWN_MEDIA_SOURCE, $entry->getSource()); $insert = false; } if ($insert) { KalturaLog::err("paramsArray" . print_r($paramsArray, true)); $insert_entry_helper = new myInsertEntryHelper($this, $kuser_id, $kshow_id, $paramsArray); $insert_entry_helper->setPartnerId($partner_id, $subp_id); $insert_entry_helper->insertEntry($token, $entry->getType(), $entry->getId(), $entry->getName(), $entry->getTags(), $entry); $insert_entry_helper->getEntry(); $this->addDebug("added_entry{$i}", $entry->getName()); } } // create_entry = true KalturaLog::err('id: ' . $entry->getId() . ' $quick_edit:' . $quick_edit); if ($quick_edit) { KalturaLog::info("quick edit with kshow_id [{$kshow_id}]"); if (!$kshow) { $kshow = kshowPeer::retrieveByPK($kshow_id); } // this i if (!$kshow) { // BAD - this shount not be ! $this->addError(APIErrors::INVALID_KSHOW_ID, $kshow_id); return; } $metadata = $kshow->getMetadata(); if ($metadata !== null) { KalturaLog::info("Having metadata"); $relevant_kshow_version = 1 + $kshow->getVersion(); // the next metadata will be the first relevant version for this new entry $version_info = array(); $version_info["KuserId"] = $puser_kuser->getKuserId(); $version_info["PuserId"] = $puser_id; $version_info["ScreenName"] = $puser_kuser->getPuserName(); $new_metadata = myMetadataUtils::addEntryToMetadata($metadata, $entry, $relevant_kshow_version, $version_info); $entry_modified = true; if ($new_metadata) { // TODO - add thumbnail only for entries that are worthy - check they are not moderated ! $thumb_modified = myKshowUtils::updateThumbnail($kshow, $entry, false); if ($thumb_modified) { $new_metadata = myMetadataUtils::updateThumbUrlFromMetadata($new_metadata, $entry->getThumbnailUrl()); } // it is very important to increment the version count because even if the entry is deferred // it will be added on the next version if (!$kshow->getHasRoughcut()) { // make sure the kshow now does have a roughcut $kshow->setHasRoughcut(true); $kshow->save(); } $kshow->setMetadata($new_metadata, true); } // no need to save kshow - the modification of the metadata was done to the show_entry which will propagate any chages to the kshow in it's own save method } } if ($entry_modified) { $entry->save(); } $not_id = null; // send a synch notification @(list($not_id, $not, $url, $params, $serialized_params) = myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $entry, null, null)); if ($not_id) { $notification_ids[] = $not_id; $notifications[] = array("url" => $url, "params" => $serialized_params); } $wrapper = objectWrapperBase::getWrapperClass($entry, objectWrapperBase::DETAIL_LEVEL_REGULAR); $entries[$prefix] = $wrapper; //$this->addMsg ( $prefix , $wrapper); // because the kshow's entrys field was changes do to this update, we have to remove object from cahce // TODO - think of some reverse way to automatically remove from the cache from within the wrapper // call some - update cache where the kshow_id plays a part in the update $wrapper->removeFromCache("kshow", $kshow_id, "entrys"); $this->addDebug("added_fields", $fields_modified, $prefix); } $this->addMsg("entries", $entries); if (count($notification_ids) > 0) { $this->addMsg("notifications", $notifications); } if ($new_entry_count < 1) { $this->addError(APIErrors::NO_ENTRIES_ADDED); $this->addDebug("no_new_entries", "You have to have at least one new entry with a field called 'entry1_name'"); } $this->addMsg("new_entry_count", $new_entry_count); }
/** * Appends a media entry to a the end of the mix timeline, this will save the mix timeline as a new version. * * @action appendMediaEntry * @param string $mixEntryId Mix entry to append to its timeline * @param string $mediaEntryId Media entry to append to the timeline * @return KalturaMixEntry The mix entry */ function appendMediaEntryAction($mixEntryId, $mediaEntryId) { $dbMixEntry = entryPeer::retrieveByPK($mixEntryId); if (!$dbMixEntry || $dbMixEntry->getType() != KalturaEntryType::MIX) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $mixEntryId); } $dbMediaEntry = entryPeer::retrieveByPK($mediaEntryId); if (!$dbMediaEntry || $dbMediaEntry->getType() != KalturaEntryType::MEDIA_CLIP) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $mediaEntryId); } $kshow = $dbMixEntry->getkshow(); if (!$kshow) { KalturaLog::CRIT("Kshow was not found for mix id [" . $mixEntryId . "]"); throw new KalturaAPIException(KalturaErrors::INTERNAL_SERVERL_ERROR); } // FIXME: temp hack - when kshow doesn't have a roughcut, and the media entry is not ready, it cannob be queued for append upon import/conversion completion if ($dbMediaEntry->getStatus() != entryStatus::READY) { $kshow->setShowEntryId($mixEntryId); $kshow->save(); $dbMediaEntry->setKshowId($kshow->getId()); $dbMediaEntry->save(); } $metadata = $kshow->getMetadata(); $relevantKshowVersion = 1 + $kshow->getVersion(); // the next metadata will be the first relevant version for this new entry $newMetadata = myMetadataUtils::addEntryToMetadata($metadata, $dbMediaEntry, $relevantKshowVersion, array()); $dbMediaEntry->save(); // FIXME: should be removed, needed for the prev hack if ($newMetadata) { // TODO - add thumbnail only for entries that are worthy - check they are not moderated ! $thumbModified = myKshowUtils::updateThumbnail($kshow, $dbMediaEntry, false); if ($thumbModified) { $newMetadata = myMetadataUtils::updateThumbUrlFromMetadata($newMetadata, $dbMixEntry->getThumbnailUrl()); } // it is very important to increment the version count because even if the entry is deferred // it will be added on the next version if (!$kshow->getHasRoughcut()) { // make sure the kshow now does have a roughcut $kshow->setHasRoughcut(true); $kshow->save(); } $kshow->setMetadata($newMetadata, true); } $mixEntry = new KalturaMixEntry(); $mixEntry->fromObject($dbMixEntry); return $mixEntry; }
protected function executeImpl(kshow $kshow, entry &$entry) { $this->res = ""; $likuser_id = $this->getLoggedInUserId(); // if we allow multiple rouchcuts - there is no reason for one suer to override someone else's thumbnail if ($this->allowMultipleRoughcuts()) { if ($likuser_id != $entry->getKuserId()) { // ERROR - attempting to update an entry which doesnt belong to the user return "<xml>!!</xml>"; //$this->securityViolation( $kshow->getId() ); } } $debug = @$_GET["debug"]; /* $kshow_id = @$_GET["kshow_id"]; $debug = @$_GET["debug"]; $this->kshow_id = $kshow_id; if ( $kshow_id == NULL || $kshow_id == 0 ) return; $kshow = kshowPeer::retrieveByPK( $kshow_id ); if ( ! $kshow ) { $this->res = "No kshow " . $kshow_id ; return; } // is the logged-in-user is not an admin or the producer - check if show can be published $likuser_id = $this->getLoggedInUserId(); $viewer_type = myKshowUtils::getViewerType($kshow, $likuser_id); if ( $viewer_type != KshowKuser::KSHOWKUSER_VIEWER_PRODUCER && ( ! $kshow->getCanPublish() ) ) { // ERROR - attempting to publish a non-publishable show return "<xml>!</xml>";//$this->securityViolation( $kshow->getId() ); } // ASSUME - the kshow & roughcut already exist $show_entry_id = $kshow->getShowEntryId(); $roughcut = entryPeer::retrieveByPK( $show_entry_id ); $roughcut = entryPeer::retrieveByPK( $entry_id ); if ( ! $roughcut) { $this->res = "No roughcut for kshow " . $kshow->getId() ; return; } */ // echo "for entry: $show_entry_id current thumb path: " . $entry->getThumbnail() ; $entry->setThumbnail(".jpg"); $entry->setCreateThumb(false); $entry->save(); //$thumb_data = $_REQUEST["ThumbData"]; if (isset($HTTP_RAW_POST_DATA)) { $thumb_data = $HTTP_RAW_POST_DATA; } else { $thumb_data = file_get_contents("php://input"); } // $thumb_data = $GLOBALS["HTTP_RAW_POST_DATA"]; $thumb_data_size = strlen($thumb_data); $bigThumbPath = myContentStorage::getFSContentRootPath() . $entry->getBigThumbnailPath(); kFile::fullMkdir($bigThumbPath); kFile::setFileContent($bigThumbPath, $thumb_data); $path = myContentStorage::getFSContentRootPath() . $entry->getThumbnailPath(); kFile::fullMkdir($path); myFileConverter::createImageThumbnail($bigThumbPath, $path); $roughcutPath = myContentStorage::getFSContentRootPath() . $entry->getDataPath(); $xml_doc = new KDOMDocument(); $xml_doc->load($roughcutPath); if (myMetadataUtils::updateThumbUrl($xml_doc, $entry->getBigThumbnailUrl())) { $xml_doc->save($roughcutPath); } $this->res = $entry->getBigThumbnailUrl(); }