Ejemplo n.º 1
0
 /**
  * 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 !
 }
 /**
  * Will forward to the regular swf player according to the widget_id 
  */
 public function execute()
 {
     $uiconf_id = $this->getRequestParameter('uiconf_id');
     if (!$uiconf_id) {
         KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'uiconf_id');
     }
     $uiConf = uiConfPeer::retrieveByPK($uiconf_id);
     if (!$uiConf) {
         KExternalErrors::dieError(KExternalErrors::UI_CONF_NOT_FOUND);
     }
     $partner_id = $this->getRequestParameter('partner_id', $uiConf->getPartnerId());
     if (!$partner_id) {
         KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'partner_id');
     }
     $partner_host = myPartnerUtils::getHost($partner_id);
     $partner_cdnHost = myPartnerUtils::getCdnHost($partner_id);
     $use_cdn = $uiConf->getUseCdn();
     $host = $use_cdn ? $partner_cdnHost : $partner_host;
     $ui_conf_html5_url = $uiConf->getHtml5Url();
     if (kConf::hasMap("optimized_playback")) {
         $optimizedPlayback = kConf::getMap("optimized_playback");
         if (array_key_exists($partner_id, $optimizedPlayback)) {
             // force a specific kdp for the partner
             $params = $optimizedPlayback[$partner_id];
             if (array_key_exists('html5_url', $params)) {
                 $ui_conf_html5_url = $params['html5_url'];
             }
         }
     }
     if (kString::beginsWith($ui_conf_html5_url, "http")) {
         $url = $ui_conf_html5_url;
         // absolute URL
     } else {
         if ($ui_conf_html5_url) {
             $url = $host . $ui_conf_html5_url;
         } else {
             $html5_version = kConf::get('html5_version');
             $url = "{$host}/html5/html5lib/{$html5_version}/mwEmbedLoader.php";
         }
     }
     // append uiconf_id and partner id for optimizing loading of html5 library. append them only for "standard" urls by looking for the mwEmbedLoader.php suffix
     if (kString::endsWith($url, "mwEmbedLoader.php")) {
         $url .= "/p/{$partner_id}/uiconf_id/{$uiconf_id}";
         $entry_id = $this->getRequestParameter('entry_id');
         if ($entry_id) {
             $url .= "/entry_id/{$entry_id}";
         }
     }
     requestUtils::sendCachingHeaders(60);
     header("Pragma:");
     kFile::cacheRedirect($url);
     header("Location:{$url}");
     die;
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 /**
  * returns the number of field set
  * WARNING - this method's params are different from fillObjectFromRequest due to the structure of the xml 
  * The second parameter $prefix_to_add represents the string to append as prefix to each of the elements names.
  */
 public function fillObjectFromXml(SimpleXMLElement $simple_xml_node, $prefix_to_add, $exclude_params = null)
 {
     $set_field_count = 0;
     // iterate over all the paramters of the request
     foreach ($simple_xml_node as $param => $value) {
         // ignore empty strings in the filter !
         if ($value == NULL || strlen($value) == 0) {
             continue;
         }
         if ($exclude_params != NULL && in_array($param, $exclude_params)) {
             continue;
         }
         // the field name is the rest of the string coming after the prefix
         $param_name = $prefix_to_add . $param;
         // TODO - should add a reg-exp array rather than this hard-coded logic in the base class !!
         // dont' fill the properties ending with backgroundImage (the avlues are WRONG!)
         if (kString::endsWith($param_name, "Image")) {
             continue;
         }
         $this->setByName($param_name, (string) html_entity_decode($value));
         // cast the SimpleXMLElement to string !!
         $set_field_count++;
     }
     return $set_field_count;
 }
 private function fixRequestContainer(&$arr)
 {
     foreach ($arr as $param_name => $param_value) {
         $param_name = strtolower($param_name);
         if (strlen($param_name) > self::MAX_VALID_PARAM_NAME) {
             // remove !
             unset($arr[$param_name]);
             $this->m_invalid_params[$param_name] = $param_value;
         }
         if (in_array($param_name, self::$special_params)) {
             continue;
         }
         $valid = false;
         foreach (self::$special_suffix as $allowed_suffix) {
             // the match can be case insensitive
             if (kString::endsWith(strtolower($param_name), $allowed_suffix)) {
                 $valid = true;
                 break;
             }
         }
         if ($valid) {
             continue;
         }
         if (is_array($param_value)) {
             $this->fixRequestContainer($param_value);
             continue;
         }
         $found = 0;
         // for now - replace the characters < >
         $fixed_param_value = preg_replace("/[<>]/", "", $param_value, -1, $found);
         if ($found > 0) {
             $arr[$param_name] = $fixed_param_value;
             $this->m_invalid_params[$param_name] = $param_value;
         }
     }
 }
Ejemplo n.º 6
0
 private function attachCriterionToCriteria($criteria, $criterion, $add_or_to_criterion, $operator_str, $value, $colname)
 {
     //echo ( " operator_str " . $operator_str );
     list($criteria_operator, $value_to_set, $query_append_method) = $criteria_operator = baseObjectFilter::getCriteriaOperatorFromStr($operator_str, $value, $colname);
     //				echo ( "<br>Adding to criteria [" . $colname . "] = [" . $value . "] , " . $criteria_operator . "<br>");
     // TODO - is this huristics OK ? can we really say for sure that fields that end with _date are time objects ?
     if (kString::endsWith($colname, "_date")) {
         $value_to_set = strtotime($value);
     }
     // special case where match can be used
     if ($criteria_operator == self::MATCH_AND) {
         self::addMatchToCriteria($criteria, null, $value_to_set, $colname, $criteria_operator, true);
     } elseif ($criteria_operator == self::MATCH_OR) {
         self::addMatchToCriteria($criteria, null, $value_to_set, $colname, $criteria_operator, true);
     } elseif ($criteria_operator == Criteria::IN || $criteria_operator == Criteria::NOT_IN || !is_array($value_to_set)) {
         if ($add_or_to_criterion) {
             $new_crit = $criteria->getNewCriterion($colname, $value_to_set, $criteria_operator);
             if ($criterion == null) {
                 // need to create a new criterion for the colname
                 $criterion = $new_crit;
             } else {
                 $criterion->addOr($new_crit);
             }
         } else {
             // add or null
             if (in_array($operator_str, array(self::LT_OR_NULL, self::GT_OR_NULL, self::LTE_OR_NULL, self::GTE_OR_NULL))) {
                 $accumulated_criterion = $criteria->getNewCriterion($colname, $value_to_set, $criteria_operator);
                 $or_null_criterion = $criteria->getNewCriterion($colname, null);
                 $accumulated_criterion->addOr($or_null_criterion);
                 $criteria->addAnd($accumulated_criterion);
             } else {
                 // simply addAnd to the criteria
                 $criteria->addAnd($colname, $value_to_set, $criteria_operator);
             }
         }
     } else {
         $accumulated_criterion = null;
         foreach ($value_to_set as $single_value) {
             // here use the $criteria object
             $single_crit = $criteria->getNewCriterion($colname, $single_value, $criteria_operator);
             if ($accumulated_criterion == NULL) {
                 $accumulated_criterion = $single_crit;
             } else {
                 if ($query_append_method == self::QUERY_OR) {
                     $accumulated_criterion->addOr($single_crit);
                 } else {
                     $accumulated_criterion->addAnd($single_crit);
                 }
             }
         }
         if ($add_or_to_criterion) {
             if ($criterion == null) {
                 // need to create a new criterion for the colname - use the one just created
                 $criterion = $accumulated_criterion;
             } else {
                 $criterion->addOr($accumulated_criterion);
             }
         } else {
             // simply addAnd to the criteria
             $criteria->addAnd($accumulated_criterion);
         }
     }
     return $criterion;
 }
Ejemplo n.º 7
0
 static function buildMultilineString($description, $indent = "")
 {
     $description = trim($description);
     if (!$description) {
         return "";
     }
     $description = str_replace("\n", "\n{$indent}", $description);
     # make sure the description does not start or end with '"'
     if (kString::beginsWith($description, '"')) {
         $description = " " . $description;
     }
     if (kString::endsWith($description, '"')) {
         $description .= " ";
     }
     return $indent . '"""' . $description . '"""';
 }
Ejemplo n.º 8
0
 /**
  * Will forward to the regular swf player according to the widget_id
  */
 public function execute()
 {
     $uiconf_id = $this->getRequestParameter('uiconf_id');
     if (!$uiconf_id) {
         KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'uiconf_id');
     }
     $uiConf = uiConfPeer::retrieveByPK($uiconf_id);
     if (!$uiConf) {
         KExternalErrors::dieError(KExternalErrors::UI_CONF_NOT_FOUND);
     }
     $partner_id = $this->getRequestParameter('partner_id', $uiConf->getPartnerId());
     if (!$partner_id) {
         KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'partner_id');
     }
     $widget_id = $this->getRequestParameter("widget_id", '_' . $partner_id);
     $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "https" : "http";
     $host = myPartnerUtils::getCdnHost($partner_id, $protocol, 'api');
     $ui_conf_html5_url = $uiConf->getHtml5Url();
     if (kConf::hasMap("optimized_playback")) {
         $optimizedPlayback = kConf::getMap("optimized_playback");
         if (array_key_exists($partner_id, $optimizedPlayback)) {
             // force a specific kdp for the partner
             $params = $optimizedPlayback[$partner_id];
             if (array_key_exists('html5_url', $params)) {
                 $ui_conf_html5_url = $params['html5_url'];
             }
         }
     }
     $autoEmbed = $this->getRequestParameter('autoembed');
     $iframeEmbed = $this->getRequestParameter('iframeembed');
     $scriptName = $iframeEmbed ? 'mwEmbedFrame.php' : 'mwEmbedLoader.php';
     if ($ui_conf_html5_url && $iframeEmbed) {
         $ui_conf_html5_url = str_replace('mwEmbedLoader.php', 'mwEmbedFrame.php', $ui_conf_html5_url);
     }
     $relativeUrl = true;
     // true if ui_conf html5_url is relative (doesnt start with an http prefix)
     if (kString::beginsWith($ui_conf_html5_url, "http")) {
         $relativeUrl = false;
         $url = $ui_conf_html5_url;
         // absolute URL
     } else {
         if (!$iframeEmbed) {
             $host = "{$protocol}://" . kConf::get('html5lib_host') . "/";
         }
         if ($ui_conf_html5_url) {
             $url = $host . $ui_conf_html5_url;
         } else {
             $html5_version = kConf::get('html5_version');
             $url = "{$host}/html5/html5lib/{$html5_version}/" . $scriptName;
         }
     }
     // append uiconf_id and partner id for optimizing loading of html5 library. append them only for "standard" urls by looking for the mwEmbedLoader.php/mwEmbedFrame.php suffix
     if (kString::endsWith($url, $scriptName)) {
         $url .= "/p/{$partner_id}/uiconf_id/{$uiconf_id}";
         if (!$autoEmbed) {
             $entry_id = $this->getRequestParameter('entry_id');
             if ($entry_id) {
                 $url .= "/entry_id/{$entry_id}";
             }
         }
     }
     header("pragma:");
     if ($iframeEmbed) {
         $url .= (strpos($url, "?") === false ? "?" : "&") . 'wid=' . $widget_id . '&' . $_SERVER["QUERY_STRING"];
     } else {
         $params = "protocol={$protocol}&" . $_SERVER["QUERY_STRING"];
         $url .= (strpos($url, "?") === false ? "?" : "&") . $params;
         if ($relativeUrl) {
             header('Content-Type: application/javascript');
             kFileUtils::dumpUrl($url, true, false, array("X-Forwarded-For" => requestUtils::getRemoteAddress()));
         }
     }
     requestUtils::sendCachingHeaders(60, true, time());
     kFile::cacheRedirect($url);
     header("Location:{$url}");
     KExternalErrors::dieGracefully();
 }
Ejemplo n.º 9
0
 private function buildObject(KalturaTypeReflector $typeReflector, array &$params, $objectName)
 {
     // if objectType was specified, we will use it only if the anotation type is it's base type
     if (array_key_exists("objectType", $params)) {
         $possibleType = $params["objectType"];
         if (strtolower($possibleType) !== strtolower($typeReflector->getType())) {
             if ($typeReflector->isParentOf($possibleType)) {
                 $newTypeReflector = KalturaTypeReflectorCacher::get($possibleType);
                 if ($newTypeReflector) {
                     $typeReflector = $newTypeReflector;
                 }
             }
         }
     }
     if ($typeReflector->isAbstract()) {
         throw new KalturaAPIException(KalturaErrors::OBJECT_TYPE_ABSTRACT, $typeReflector->getType());
     }
     $class = $typeReflector->getType();
     $obj = new $class();
     $properties = $typeReflector->getProperties();
     foreach ($params as $name => $value) {
         $isNull = false;
         if (kString::endsWith($name, '__null')) {
             $name = str_replace('__null', '', $name);
             $isNull = true;
         }
         if (!array_key_exists($name, $properties)) {
             continue;
         }
         $property = $properties[$name];
         /* @var $property KalturaPropertyInfo */
         $type = $property->getType();
         if ($isNull && !$property->isArray()) {
             $obj->{$name} = new KalturaNullField();
             continue;
         }
         if ($property->isSimpleType()) {
             if ($property->isTime()) {
                 $type = "time";
             }
             $value = $this->castSimpleType($type, $value);
             if (!kXml::isXMLValidContent($value)) {
                 throw new KalturaAPIException(KalturaErrors::INVALID_PARAMETER_CHAR, $name);
             }
             $this->validateParameter($name, $value, $property);
             $obj->{$name} = $value;
             continue;
         }
         if ($property->isEnum()) {
             if (strtolower($value) == 'true') {
                 $value = 1;
             }
             if (strtolower($value) == 'false') {
                 $value = 0;
             }
             if (!$property->getTypeReflector()->checkEnumValue($value)) {
                 throw new KalturaAPIException(KalturaErrors::INVALID_ENUM_VALUE, $value, $name, $property->getType());
             }
             if ($type == 'KalturaNullableBoolean') {
                 $obj->{$name} = KalturaNullableBoolean::toBoolean($value);
                 continue;
             }
             $obj->{$name} = $this->castSimpleType("int", $value);
             continue;
         }
         if ($property->isStringEnum()) {
             if (!$property->getTypeReflector()->checkStringEnumValue($value)) {
                 throw new KalturaAPIException(KalturaErrors::INVALID_ENUM_VALUE, $value, $name, $property->getType());
             }
             $value = $this->castSimpleType("string", $value);
             if (!kXml::isXMLValidContent($value)) {
                 throw new KalturaAPIException(KalturaErrors::INVALID_PARAMETER_CHAR, $name);
             }
             $obj->{$name} = $value;
             continue;
         }
         if ($property->isArray() && is_array($value)) {
             $arrayObj = new $type();
             if ($property->isAssociativeArray()) {
                 foreach ($value as $arrayItemKey => $arrayItemParams) {
                     if ($arrayItemKey === '-') {
                         break;
                     }
                     $arrayObj[$arrayItemKey] = $this->buildObject($property->getArrayTypeReflector(), $arrayItemParams, "{$objectName}:{$name}");
                 }
             } else {
                 ksort($value);
                 foreach ($value as $arrayItemKey => $arrayItemParams) {
                     if ($arrayItemKey === '-') {
                         break;
                     }
                     $arrayObj[] = $this->buildObject($property->getArrayTypeReflector(), $arrayItemParams, "{$objectName}:{$name}");
                 }
             }
             $obj->{$name} = $arrayObj;
             continue;
         }
         if ($property->isComplexType() && is_array($value)) {
             $obj->{$name} = $this->buildObject($property->getTypeReflector(), $value, "{$objectName}:{$name}");
             continue;
         }
         if ($property->isFile()) {
             $obj->{$name} = $value;
             continue;
         }
     }
     return $obj;
 }
 private static function parseMemorySize($size_str)
 {
     $fixed_str = strtolower($size_str);
     if (kString::endsWith($fixed_str, "m")) {
         return $size_str * 1024 * 1024;
     }
     if (kString::endsWith($fixed_str, "k")) {
         return $size_str * 1024;
     }
     return $size_str;
 }