/**
  * If 
  */
 public static function createWidgetFromWidget($parent_widget_obj_or_id, $kshow_id, $entry_id = null, $ui_conf_id = null, $custom_data = null, $partner_data = null, $security_type = null)
 {
     if ($parent_widget_obj_or_id == null) {
         throw new Exception("Cannot createWidget from empty object");
     }
     if ($parent_widget_obj_or_id instanceof widget) {
         $source_widget = $parent_widget_obj_or_id;
     } else {
         // assume its an id
         $source_widget = widgetPeer::retrieveByPK($parent_widget_obj_or_id);
         if (!$source_widget) {
             throw new Exception("Cannot createWidget from a none-existing widget [{$parent_widget_obj_or_id}]");
         }
     }
     $kshow = null;
     $widget_kshow_id = $source_widget->getKshowId();
     if (!$widget_kshow_id) {
         // fetch the kshow/entry according to the kshow_id/entry_id rules
         list($kshow, $entry, $error, $error_obj) = myKshowUtils::getKshowAndEntry($kshow_id, $entry_id);
         $widget_kshow_id = $kshow_id;
         if ($source_widget->getEntryId()) {
             $entry_id = $source_widget->getEntryId();
         }
     }
     if (!$kshow) {
         $kshow = kshowPeer::retrieveByPK($widget_kshow_id);
         if (!$kshow) {
             return null;
         }
     }
     return self::createWidget($kshow, $entry_id, $source_widget, $ui_conf_id, $custom_data, $partner_data, $security_type);
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     $this->response_type = kalturaWebserviceRenderer::RESPONSE_TYPE_HTML;
     //
     $widget_id = $this->getP("widget_id");
     $kshow_id = $this->getP("kshow_id");
     $entry_id = $this->getP("entry_id");
     $widget_type = $this->getP("widget_type", 1);
     // TODO -decide on a good default;
     if ($widget_id) {
         $this->addMsg("<b>", $this->createGenericWidgetHtml2($partner_id, $subp_id, $puser_id));
         return;
     }
     if (in_array($partner_id, array(321, 449))) {
         $widget_type = 60;
     }
     list($kshow, $entry, $error, $error_obj) = myKshowUtils::getKshowAndEntry($kshow_id, $entry_id);
     if ($error_obj) {
         $this->addError($error_obj);
         return;
     }
     $kshow = kshowPeer::retrieveByPK($kshow_id);
     if (!$kshow) {
         $this->addMsg("<b>", "Error: no such {$kshow_id}");
         return;
     }
     $this->addMsg("<b>", $this->createGenericWidgetHtml($partner_id, $subp_id, $kshow_id, $puser_id, $widget_type));
 }
 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);
 }
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     if (!$partner_id) {
         die;
     }
     $entry_id = $this->getP("entry_id");
     // if the entry_type was sent by the client - make sure it's of type  ENTRY_TYPE_SHOW.
     // this is to prevent this service as part of a bad multirequest
     $entry_type = $this->getP("entry_type", null);
     if (!empty($entry_type) && $entry_type != entryType::MIX) {
         $this->addDebug("entry", "not of type " . entryType::MIX);
         return;
     }
     $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;
     }
     KalturaLog::log(__METHOD__ . " kshow_id [{$kshow_id}] entry_id [{$entry_id}]");
     $list_type = $this->getP("list_type", self::LIST_TYPE_ROUGHCUT);
     $version = $this->getP("version", null);
     if ((int) $version == -1) {
         $version = null;
     }
     // will retrieve the latest
     $disable_roughcut_entry_data = $this->getP("disable_roughcut_entry_data", false);
     $disable_user_data = $this->getP("disable_user_data", false);
     // will allow to optimize the cals and NOT join with the kuser table
     $merge_entry_lists = false;
     if ($this->getPartner()) {
         $merge_entry_lists = $this->getPartner()->getMergeEntryLists();
     }
     $kshow_entry_list = array();
     $kuser_entry_list = array();
     $aggrigate_id_list = array();
     $this->benchmarkStart("list_type_kshow");
     if ($list_type & self::LIST_TYPE_KSHOW && $kshow_id) {
         $c = new Criteria();
         $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP);
         //			$c->addAnd ( entryPeer::MEDIA_TYPE , entry::ENTRY_MEDIA_TYPE_SHOW , Criteria::NOT_EQUAL );
         $c->addAnd(entryPeer::KSHOW_ID, $kshow_id);
         $this->addIgnoreIdList($c, $aggrigate_id_list);
         //			$this->addOffsetAndLimit ( $c ); // fetch as many as the kshow has
         if ($disable_user_data) {
             $kshow_entry_list = entryPeer::doSelect($c);
         } else {
             $kshow_entry_list = entryPeer::doSelectJoinkuser($c);
         }
         $this->updateAggrigatedIdList($aggrigate_id_list, $kshow_entry_list);
     }
     $this->benchmarkEnd("list_type_kshow");
     $this->benchmarkStart("list_type_kuser");
     if ($list_type & self::LIST_TYPE_KUSER) {
         // try to get puserKuser - PS2
         $puser_kuser = PuserKuserPeer::retrieveByPartnerAndUid($partner_id, null, $puser_id, false);
         // try to get kuser by partnerId & puserId - PS3 - backward compatibility
         $apiv3Kuser = kuserPeer::getKuserByPartnerAndUid($partner_id, $puser_id, true);
         if ($puser_kuser && $puser_kuser->getKuserId() || $apiv3Kuser) {
             $c = new Criteria();
             $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP);
             //				$c->addAnd ( entryPeer::MEDIA_TYPE , entry::ENTRY_MEDIA_TYPE_SHOW , Criteria::NOT_EQUAL );
             $kuserIds = array();
             if ($puser_kuser && $puser_kuser->getKuserId()) {
                 $kuserIds[] = $puser_kuser->getKuserId();
             }
             if ($apiv3Kuser) {
                 if (!$puser_kuser || $puser_kuser->getKuserId() != $apiv3Kuser->getId()) {
                     $kuserIds[] = $apiv3Kuser->getId();
                 }
             }
             /*
             				if(count($kuserIds) > 1)
             				{
             					$c->addAnd ( entryPeer::KUSER_ID , $kuserIds, Criteria::IN );
             				}
             				else
             				{
             					$c->addAnd ( entryPeer::KUSER_ID , $kuserIds[0] );
             				}
             				if ( $merge_entry_lists )
             				{
             					// if will join lists - no need to fetch entries twice
             					$this->addIgnoreIdList ($c , $aggrigate_id_list);
             				}
             				$this->addOffsetAndLimit ( $c ); // limit the number of the user's clips
             				if ( $disable_user_data )
             					$kuser_entry_list = entryPeer::doSelect( $c );
             				else
             					$kuser_entry_list = entryPeer::doSelectJoinkuser( $c );
             */
             $this->addOffsetAndLimit($c);
             // limit the number of the user's clips
             if ($merge_entry_lists) {
                 // if will join lists - no need to fetch entries twice
                 $this->addIgnoreIdList($c, $aggrigate_id_list);
             }
             $kuser_entry_list = array();
             $kuserIds = array_unique($kuserIds);
             foreach ($kuserIds as $kuserId) {
                 $newC = clone $c;
                 $newC->addAnd(entryPeer::KUSER_ID, $kuserId);
                 if ($disable_user_data) {
                     $one_kuser_list = entryPeer::doSelect($newC);
                 } else {
                     $one_kuser_list = entryPeer::doSelectJoinkuser($newC);
                 }
                 $kuser_entry_list = array_merge($kuser_entry_list, $one_kuser_list);
             }
             // Since we are using 2 potential kusers, we might not have the obvious kuser from $puser_kuser
             $strEntries = "";
             if ($puser_kuser) {
                 $kuser = kuserPeer::retrieveByPk($puser_kuser->getKuserId());
                 if ($kuser) {
                     $strEntriesTemp = @unserialize($kuser->getPartnerData());
                     if ($strEntriesTemp) {
                         $strEntries .= $strEntriesTemp;
                     }
                 }
             }
             if ($apiv3Kuser) {
                 $strEntriesTemp = @unserialize($apiv3Kuser->getPartnerData());
                 if ($strEntriesTemp) {
                     $strEntries .= $strEntriesTemp;
                 }
             }
             if ($strEntries) {
                 $entries = explode(',', $strEntries);
                 $fixed_entry_list = array();
                 foreach ($entries as $entryId) {
                     $fixed_entry_list[] = trim($entryId);
                 }
                 $c = new Criteria();
                 $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP);
                 $c->addAnd(entryPeer::ID, $fixed_entry_list, Criteria::IN);
                 if ($merge_entry_lists) {
                     // if will join lists - no need to fetch entries twice
                     $this->addIgnoreIdList($c, $aggrigate_id_list);
                 }
                 if ($disable_user_data) {
                     $extra_user_entries = entryPeer::doSelect($c);
                 } else {
                     $extra_user_entries = entryPeer::doSelectJoinkuser($c);
                 }
                 if (count($extra_user_entries)) {
                     $kuser_entry_list = array_merge($extra_user_entries, $kuser_entry_list);
                 }
             }
         } else {
             $kuser_entry_list = array();
         }
         if ($merge_entry_lists) {
             $kshow_entry_list = kArray::append($kshow_entry_list, $kuser_entry_list);
             $kuser_entry_list = null;
         }
     }
     $this->benchmarkEnd("list_type_kuser");
     $this->benchmarkStart("list_type_episode");
     if ($list_type & self::LIST_TYPE_EPISODE) {
         if ($kshow && $kshow->getEpisodeId()) {
             // episode_id will point to the "parent" kshow
             // fetch the entries of the parent kshow
             $c = new Criteria();
             $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP);
             //				$c->addAnd ( entryPeer::MEDIA_TYPE , entry::ENTRY_MEDIA_TYPE_SHOW , Criteria::NOT_EQUAL );
             $c->addAnd(entryPeer::KSHOW_ID, $kshow->getEpisodeId());
             $this->addIgnoreIdList($c, $aggrigate_id_list);
             //				$this->addOffsetAndLimit ( $c ); // limit the number of the inherited entries from the episode
             if ($disable_user_data) {
                 $parent_kshow_entries = entryPeer::doSelect($c);
             } else {
                 $parent_kshow_entries = entryPeer::doSelectJoinkuser($c);
             }
             if (count($parent_kshow_entries)) {
                 $kshow_entry_list = kArray::append($kshow_entry_list, $parent_kshow_entries);
             }
         }
     }
     $this->benchmarkEnd("list_type_episode");
     // fetch all entries that were used in the roughcut - those of other kusers
     // - appeared under kuser_entry_list when someone else logged in
     $this->benchmarkStart("list_type_roughcut");
     $entry_data_from_roughcut_map = array();
     // will hold an associative array where the id is the key
     if ($list_type & self::LIST_TYPE_ROUGHCUT) {
         if ($entry->getType() == entryType::MIX) {
             $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version);
             $roughcut_file_name = kFileSyncUtils::getReadyLocalFilePathForKey($sync_key);
             $entry_data_from_roughcut = myFlvStreamer::getAllAssetsData($roughcut_file_name);
             $final_id_list = array();
             foreach ($entry_data_from_roughcut as $data) {
                 $id = $data["id"];
                 // first element is the id
                 $entry_data_from_roughcut_map[] = $data;
                 $found = false;
                 foreach ($kshow_entry_list as $entry) {
                     // see we are not fetching duplicate entries
                     if ($entry->getId() == $id) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $final_id_list[] = $id;
                 }
             }
             if (count($final_id_list) > 0) {
                 // allow deleted entries when searching for entries on the roughcut
                 // don't forget to return the status at the end of the process
                 entryPeer::allowDeletedInCriteriaFilter();
                 $c = new Criteria();
                 $c->addAnd(entryPeer::ID, $final_id_list, Criteria::IN);
                 $c->addAnd(entryPeer::TYPE, entryType::MEDIA_CLIP);
                 $this->addIgnoreIdList($c, $aggrigate_id_list);
                 //				$this->addOffsetAndLimit ( $c );
                 if ($disable_user_data) {
                     $extra_entries = entryPeer::doSelect($c);
                 } else {
                     $extra_entries = entryPeer::doSelectJoinkuser($c);
                 }
                 // return the status to the criteriaFilter
                 entryPeer::blockDeletedInCriteriaFilter();
                 // merge the 2 lists into 1:
                 $kshow_entry_list = kArray::append($kshow_entry_list, $extra_entries);
             }
         }
     }
     $this->benchmarkEnd("list_type_roughcut");
     $this->benchmarkStart("create_wrapper");
     $entry_wrapper = objectWrapperBase::getWrapperClass($kshow_entry_list, objectWrapperBase::DETAIL_LEVEL_REGULAR, -3, 0, array("contributorScreenName"));
     //$entry_wrapper->addFields ( array ( "kuser.screenName" ) );
     $this->addMsg("show", $entry_wrapper);
     // if ! $disable_roughcut_entry_data - add the roughcut_entry_data
     if (!$disable_roughcut_entry_data) {
         $this->addMsg("roughcut_entry_data", $entry_data_from_roughcut_map);
     }
     if (count($kuser_entry_list) > 0) {
         $this->addMsg("user", objectWrapperBase::getWrapperClass($kuser_entry_list, objectWrapperBase::DETAIL_LEVEL_REGULAR));
     } else {
         $this->addMsg("user", null);
     }
     $this->benchmarkEnd("create_wrapper");
 }