예제 #1
0
 /**
  * @param string $string
  * @return string
  */
 private static function stringToSafeXml($string)
 {
     $string = @iconv('utf-8', 'utf-8', $string);
     $partially_safe = kString::xmlEncode($string);
     $safe = str_replace(array('*', '/', '[', ']'), '', $partially_safe);
     return $safe;
 }
예제 #2
0
 protected function writeFullXmlNode($nodeName, $value, $level, $attributes = array())
 {
     $res = '';
     $res .= $this->writeOpenXmlNode($nodeName, $level, $attributes, false);
     $res .= kString::xmlEncode(kString::xmlDecode("{$value}"));
     //to create a valid XML (without unescaped special chars)
     //we decode before encoding to avoid breaking an xml which its special chars had already been escaped
     $res .= $this->writeClosingXmlNode($nodeName, 0);
     return $res;
 }
예제 #3
0
 public static function rebuildUsersListXml($users)
 {
     //"<contributor uid='$puser_id' name='$name' pic='$pic' sex='$sex'/>";
     $data = "";
     foreach ($users as $user) {
         $puser_id = $user['uid'];
         $name = $user['name'];
         $pic = $user['pic'];
         $sex = $user['sex'];
         $data .= "<contributor uid='{$puser_id}' name='" . kString::xmlEncode($name) . "' pic='{$pic}' sex='{$sex}'/>";
     }
     return $data;
 }
예제 #4
0
 function serializePrimitive($object)
 {
     $this->_serializedString .= kString::xmlEncode($object);
 }
예제 #5
0
    public static function addEntryToMetadata($content, $entry, $current_kshow_version = null, $version_info = null)
    {
        if (!$entry) {
            return null;
        }
        $media_type = $entry->getMediaType();
        if (!($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO || $media_type == entry::ENTRY_MEDIA_TYPE_IMAGE)) {
            // ignote enatiers that are not images or video
            return null;
        }
        if (isset($version_info)) {
            $content = self::addVersionInfo($content, $version_info);
        }
        $xml_doc = new DOMDocument();
        $xml_doc->loadXML($content);
        //return $xml_doc->saveXML();
        $xpath = new DOMXPath($xml_doc);
        $totalTime = 0;
        $seqDuarations = $xpath->query("//MetaData/SeqDuration");
        $one_and_only_seqDuaration = null;
        if ($seqDuarations) {
            $one_and_only_seqDuaration = $seqDuarations->item(0);
            if ($one_and_only_seqDuaration) {
                $totalTime = $one_and_only_seqDuaration->nodeValue;
            } else {
                $totalTime = 0;
                $one_and_only_seqDuaration = null;
            }
        } else {
            $totalTime = 0;
        }
        $should_save = false;
        $host_name = null;
        // set the updated list in the xml
        $host_elem = kXml::getFirstElement($xml_doc, "Host");
        if ($host_elem == null || empty($host_elem->nodeValue) || strlen($host_elem->nodeValue) < 6) {
            $host_name = requestUtils::getHost();
            $metadata = kXml::getFirstElement($xml_doc, "MetaData");
            kXml::setChildElement($xml_doc, $metadata, "Host", $host_name, false);
            $should_save = true;
        } else {
            $host_name = $host_elem->nodeValue;
        }
        $prev_transition_duration = 0;
        $vidAsset_parentNode = kXml::getFirstElement($xml_doc, "VideoAssets");
        $vidAssets = $xpath->query("//VideoAssets/vidAsset");
        $vidAssets_count = 0;
        foreach ($vidAssets as $vidAsset) {
            if ($vidAssets_count == 0) {
                if ($vidAsset_parentNode == null) {
                    $vidAsset_parentNode = $vidAsset->parentNode;
                }
            }
            $end_transition = kXml::getFirstElement($vidAsset, "EndTransition");
            if ($end_transition) {
                // by the end of the loop we'll have the last transisiotn in hand
                $cross = $end_transition->getAttribute("cross");
                if ($cross == "1") {
                    $prev_transition_duration = $end_transition->getAttribute("length");
                } else {
                    $prev_transition_duration = 0;
                }
            }
            $vidAssets_count++;
        }
        $entry_id = $entry->getId();
        // if the entry has an error - remove the pending
        if ($entry->getStatus() == entryStatus::ERROR_CONVERTING) {
            // return the XML - new if modified and the original if not
            if ($current_kshow_version != null) {
                //				$entry->setUpdateWhenReady ( $current_kshow_version );
                $should_save = self::updatePending($xml_doc, $entry_id, false);
                // increment the count on the show entry
            }
            if ($should_save) {
                return $xml_doc->saveXML();
            }
            // this is if the host has been added
            return $content;
        }
        if ($entry->getStatus() != entryStatus::READY) {
            // return the XML - new if modified and the original if not
            if ($current_kshow_version != null) {
                $entry->setUpdateWhenReady($current_kshow_version);
                $should_save = self::updatePending($xml_doc, $entry_id, true);
                // increment the count on the show entry
                $show_entry = $entry->getKshow()->getShowEntry();
                if ($show_entry) {
                    $show_entry->incInCustomData("pending_entries");
                    $show_entry->incInCustomData("moderated_entries");
                    $show_entry->save();
                }
            }
            if ($should_save) {
                return $xml_doc->saveXML();
            }
            // this is if the host has been added
            return $content;
        }
        if ($vidAssets_count >= self::MAX_ENTRIES_IN_METADATA) {
            KalturaLog::log("Exceeded number of entries in metadata [" . self::MAX_ENTRIES_IN_METADATA . "]. Will not add entry [{$entry_id}] to file.");
            $should_save = false;
            return null;
        }
        // staart at the beginning of the asset
        $startTime = 0;
        if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) {
            $isVideo = true;
            $media_type_str = 'VIDEO';
            $real_length = $entry->getLengthInMsecs() / 1000;
            if ($real_length <= 0) {
                $lenTime = 10;
                // hard-coded first 10 seconds
            } else {
                $lenTime = $real_length;
            }
        } else {
            if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) {
                $isVideo = false;
                $media_type_str = 'IMAGE';
                $lenTime = 4;
            } else {
                return $content;
                // leave untouched
            }
        }
        $addLastFadeoutTime = 1;
        $media_name = $entry->getName();
        $media_url = $entry->getDataUrl();
        $relMedia_url = strstr($media_url, "/content");
        if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) {
            // for video - change the URL of the asset to use the clipper
            /* http://www6.localhost.com/index.php/keditorservices/flvclipper?entry_id=12353 */
            $clipper_path = $host_name . "/index.php/keditorservices/flvclipper?entry_id={$entry_id}";
            $media_url = $clipper_path;
        }
        $transition_duration = 1;
        $host_id = 1 + $media_url % 7;
        // make sure that the media_url is formated properly otherwize the editor wrongly modifies the URL
        $media_url = str_replace("/localhost/", "/www{$host_id}.localhost.com/", $media_url);
        $transition_type = "dissolve";
        // the dissolve transition is from the cross family. It should not be used with the simple editor
        $fixed_media_name = kString::xmlEncode($media_name);
        $newVidasset = "\n" . '		<vidAsset k_id="' . $entry_id . '" type="' . $media_type_str . '" name="' . $fixed_media_name . '" url="' . $media_url . '">' . "\n" . '			<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" Clipped_Start="0" Clipped_Len="' . $lenTime . '"/>' . "\n" . '			<EndTransition cross="0" type="' . $transition_type . '" StartTime="' . ($lenTime - $transition_duration) . '" length="' . $transition_duration . '">' . "\n" . '				<arguments>' . "\n" . '					<name>' . $transition_type . '</name>' . "\n" . '					<version>1.00</version>' . "\n" . '					<arguments/>' . "\n" . '				</arguments>' . "\n" . '			</EndTransition>' . "\n" . '		</vidAsset>' . "\n";
        // 	if there is a transition for the previous asset - calculate it's length
        $totalTime = $totalTime + $lenTime - $prev_transition_duration;
        // update the pending element if needed
        $should_save = self::updatePending($xml_doc, $entry_id, true);
        KalturaLog::log("Will append to xml\n{$newVidasset}");
        $temp_xml_doc = new DOMDocument();
        $temp_xml_doc->loadXML($newVidasset);
        //		echo $temp_xml_doc->saveXML( );
        $new_node = $temp_xml_doc->documentElement;
        $new_vid_asset = $xml_doc->importNode($new_node, true);
        if (!$vidAsset_parentNode) {
            KalturaLog::log("No VideoAssets parent node for entry [{$entry_id}] content [{$content}].");
            return null;
        }
        // insert the new video asset as the last one in the "vidAssets" element
        $vidAsset_parentNode->appendChild($new_vid_asset);
        $one_and_only_seqDuaration->nodeValue = $totalTime;
        return $xml_doc->saveXML();
    }
예제 #6
0
 /**
  * param_names is the list of fields to add as attributes to the xml node.
  * each element in the array can either be a field name or a pair of name=>alias.
  * if name - the name will be used as the attribute name.
  * if name=>alias - the 'alias' will be used as the attribute name instead. 
  */
 public static function objToXml(BaseObject $obj, array $param_names, $xml_element_name = NULL, $close_xml_element = true, $map_to_add = NULL, $envoke_method = false)
 {
     if ($obj == NULL) {
         return NULL;
     }
     if (!$obj instanceof BaseObject) {
         throw new Exception("objToXml should have the first parameter an object of type BaseObject");
     }
     $res = $xml_element_name == NULL ? "" : "<" . $xml_element_name . " ";
     foreach ($param_names as $param_name => $param_alias) {
         // this is to be compatible both for flat arrays & associative ones
         // it ASSUMEs there are no fields that are numbers in a BaseObject
         $name = is_numeric($param_name) ? $param_alias : $param_name;
         if ($envoke_method) {
             //
             $raw_value = myBaseObject::envokeMethod($obj, $name);
         } else {
             $raw_value = $obj->getByName($name, BasePeer::TYPE_FIELDNAME);
         }
         // escape the value of the attribute
         $value = kString::xmlEncode($raw_value);
         $res .= ' ' . $param_alias . '="' . $value . '"';
     }
     if ($map_to_add != NULL) {
         foreach ($map_to_add as $attr => $val) {
             $res .= ' ' . $attr . '="' . kString::xmlEncode($val) . '"';
         }
     }
     $res .= $xml_element_name == NULL ? "" : $close_xml_element ? "/>\n" : ">\n";
     return $res;
 }
예제 #7
0
 /**
  * @param string $string
  * @return string
  */
 private static function stringToSafeXml($string)
 {
     $string = @iconv('utf-8', 'utf-8', $string);
     $safe = kString::xmlEncode($string);
     return $safe;
 }
 public function renderMrssFeed($list, $page = null, $result_count = null)
 {
     //print_r ( $list );
     $str = $this->startMrss();
     $str .= "<channel>";
     $str .= "<description>Kaltura's mRss" . ($page ? ", page: {$page}" : "") . ($result_count ? ", results: {$result_count}" : "") . "</description>" . "<title>Kaltura's mRss</title>" . "<link>" . kString::xmlEncode($_SERVER["REQUEST_URI"]) . "</link>";
     $str .= $this->recursiveRenderMrssFeed($list, 3);
     $str .= "</channel>";
     $str .= $this->endMrss();
     return $str;
 }
 protected function array2xmlImpl($array, $num_prefix = "num_", $depth = 0)
 {
     $depth++;
     //		echo ( "[$depth]array2xmlImpl:" . print_r ( $array , true ) . "<br>");
     //		echo ( "[$depth]--array2xmlImpl: $num_prefix <br>");
     $result = "";
     if ($array instanceof myBaseObject) {
         /*
         * 			$obj =  objectWrapperBase::toArrayImpl ( $array  );
         		    $result.= self::array2xmlImpl( $array, $num_prefix , $depth);
         */
         $result = null;
         $fields = $array->getFieldNames();
         foreach ($fields as $key) {
             if (empty($key)) {
                 continue;
             }
             $val = $array->get($key);
             // TODO - think if want to compare to === null -
             // this will return 0 and empty strings (doesn't happen now)
             //if ( empty ( $val ) && ( $val !== 0 ) ) continue;
             if (!self::shouldDisplayValue($val)) {
                 continue;
             }
             try {
                 $key = self::tagNameFromField($key, $num_prefix);
                 // fix key if needed
                 $result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">";
             } catch (Exception $ex) {
                 $result .= "<" . $key . ">ERROR</" . $key . ">";
             }
         }
     } else {
         if ($array instanceof objectWrapperBase) {
             /*
                 	$obj =  $array->toArray();
             	    $result.= self::array2xmlImpl( $array, $num_prefix , $depth);
             */
             $result = "";
             $fields = $array->getFieldNames();
             $i = 0;
             foreach ($fields as $key) {
                 if (empty($key)) {
                     continue;
                 }
                 $val = $array->get($key);
                 if (!self::shouldDisplayValue($val)) {
                     continue;
                 }
                 try {
                     $key = self::tagNameFromField($key, $num_prefix);
                     // fix key if needed
                     $result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">";
                 } catch (Exception $ex) {
                     $result .= "<" . $key . ">ERROR</" . $key . ">";
                 }
             }
         } elseif (is_array($array)) {
             $result = "";
             if (kArray::array_is_associative($array)) {
                 foreach ($array as $key => $val) {
                     try {
                         $key = self::tagNameFromField($key, $num_prefix);
                         // fix key if needed
                         $result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">";
                     } catch (Exception $ex) {
                         $result .= "<" . $key . ">ERROR</" . $key . ">";
                     }
                 }
             } else {
                 $array_size = count($array);
                 for ($i = 0; $i < $array_size; ++$i) {
                     if (key_exists($i, $array)) {
                         $val = $array[$i];
                     } else {
                     }
                     try {
                         $key = self::tagNameFromField($i, $num_prefix);
                         // fix key if needed
                         $result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">";
                     } catch (Exception $ex) {
                         $result .= "<" . $key . ">ERROR</" . $key . ">";
                     }
                 }
             }
         } elseif (is_object($array)) {
             return "ERROR fromating object of type [" . get_class($array) . "]";
             //echo ( "[$depth]array2xmlImpl:is_object " . get_class ( $array ) . "<br>" );
         } else {
             //cho ( "[$depth]array2xmlImpl: " . get_class ( $array ) . "<br>");
             //return htmlentities ( $array );
             if ($this->escape_text) {
                 // TODO - decide whether to encode or cdata or nothing - according to the name of the field
                 $escaped = kString::xmlEncode($array);
                 return $escaped;
                 /*
                 if ( $escaped != $array )
                 {
                 	return "<![CDATA[$array]]>";
                 }
                 */
             }
             return $array;
         }
     }
     return $result;
 }
예제 #10
0
&entry_id=<?php 
echo $entry_id;
?>
">investigate</a>
<br>	
<?php 
if (!empty($metadata)) {
    ?>

Pending string: <input type="input" id="pending" name="pending" value="<?php 
    echo $pending;
    ?>
"/>
Remove Pending all together: <input type="checkbox" id="remove_pending" name="remove_pending" />
<?php 
}
?>
	
<input type="submit" id="Go" name="Go" value="Go"/>


</form>

</div>

<pre style="background-color: lightyellow; width: 80%;">
<?php 
echo kString::xmlEncode($metadata);
?>
</pre>
예제 #11
0
 function serializeObject($object)
 {
     if ($object instanceof Exception) {
         echo '<error>';
         $this->writeTag('code', kString::xmlEncode($object->getCode()));
         $this->writeTag('message', kString::xmlEncode($object->getMessage()));
         $this->writeTag('objectType', get_class($object));
         $this->writeKalturaAPIExceptionArgsTag($object);
         echo '</error>';
     } else {
         // get object class
         $reflectObject = new ReflectionObject($object);
         $class = $reflectObject->getName();
         // write the object type
         $this->writeTag('objectType', $class);
         // load class reflection
         $typeReflector = KalturaTypeReflectorCacher::get($class);
         if (!$typeReflector) {
             echo '<error>';
             $this->writeTag('message', 'Type reflector not found');
             echo '</error>';
             return;
         }
         $properties = $typeReflector->getProperties();
         foreach ($properties as $property) {
             $name = $property->getName();
             $value = $object->{$name};
             if ($this->_ignoreNull === true && $value === null) {
                 continue;
             }
             echo '<' . $name . '>';
             $this->serializeByType($value);
             echo '</' . $name . '>';
         }
     }
 }
 function serializePrimitive($object)
 {
     echo kString::xmlEncode($object);
 }