About timed text captions plugin';
$content .= '
This is the ultimate WordPress timed text captions plugin
';
echo $content;
}
//TODO write a xml reader for the caption file
//http://de.php.net/manual/de/refs.xml.php
//http://de.php.net/manual/de/class.xmlreader.php
function xml2assoc($xml) {
$tree = null;
while($xml->read())
switch ($xml->nodeType) {
case XMLReader::END_ELEMENT: return $tree;
case XMLReader::ELEMENT:
$node = array('tag' => $xml->name, 'value' => $xml->isEmptyElement ? '' : xml2assoc($xml));
if($xml->hasAttributes)
while($xml->moveToNextAttribute())
$node['attributes'][$xml->name] = $xml->value;
$tree[] = $node;
break;
case XMLReader::TEXT:
case XMLReader::CDATA:
$tree .= $xml->value;
}
return $tree;
}
/*
@param: (array) $captions["URI"]="xmlfileURI";
@return: (array) $captions
@description: create captions array out of a xml-file give by the captions URL
*/
function readCaptionsXMLtoArray($captions){
$xml = new XMLReader();
$xml->open($captions["URI"]);
$assoc = xml2assoc($xml);
$xml->close();
if(!isset($assoc[0][value][0][value][0][value]))
writeCaptionsDefaultToXML();
$styles_count = count($assoc[0][value][0][value][0][value]);
for($style_nr=0; $style_nr <= $styles_count-1; $style_nr++){
$captions["styles"][$style_nr]["fontFamily"] = $assoc[0][value][0][value][0][value][$style_nr]["attributes"]["tts:fontFamily"];
$captions["styles"][$style_nr]["fontSize"] = $assoc[0][value][0][value][0][value][$style_nr]["attributes"]["tts:fontSize"];
$captions["styles"][$style_nr]["fontStyle"] = $assoc[0][value][0][value][0][value][$style_nr]["attributes"]["tts:fontStyle"];
$captions["styles"][$style_nr]["color"] = $assoc[0][value][0][value][0][value][$style_nr]["attributes"]["tts:color"];
$captions["styles"][$style_nr]["textAlign"] = $assoc[0][value][0][value][0][value][$style_nr]["attributes"]["tts:textAlign"];
}
//write all captions in the caption array
$captions_count = count($assoc[0][value][0][value][0][value]);
for($caption_nr=0; $caption_nr <= $captions_count-1; $caption_nr++){
$captions[$caption_nr]["begin"] = $assoc[0][value][1][value][0][value][$caption_nr]["attributes"]["begin"];
$captions[$caption_nr]["dur"] = $assoc[0][value][1][value][0][value][$caption_nr]["attributes"]["dur"];
$captions[$caption_nr]["style"] = $assoc[0][value][1][value][0][value][$caption_nr]["attributes"]["style"];
$captions[$caption_nr]["content"] = $assoc[0][value][1][value][0][value][$caption_nr]["value"];
}
return $captions;
}
/*
@param: (array) $captios["URI"]="xmlfileURI";
@return: void
@description: write given captions array back to a xml-file
*/
function writeCaptionsArrayToXML($captions){
//reservice the memory
$xml = xmlwriter_open_memory();
//enable indents
xmlwriter_set_indent($xml, TRUE);
//open new XML-documents with XML-Version 1.0 of encoding="UTF-8"
xmlwriter_start_document($xml,"1.0", 'UTF-8');
//start root-element
xmlwriter_start_element($xml,'tt');
//Zuweisung eines Attributes und des dazugehörigen Wertes
xmlwriter_write_attribute($xml, 'xml:lang', 'en');
//Zuweisung eines Attributes und des dazugehörigen Wertes
xmlwriter_write_attribute($xml, 'xmlns', 'http://www.w3.org/2006/10/ttaf1');
//Zuweisung eines Attributes und des dazugehörigen Wertes
xmlwriter_write_attribute($xml, 'xmlns:tts', 'http://www.w3.org/2006/10/ttaf1#styling');
//start element
xmlwriter_start_element($xml,"head");
//start element
xmlwriter_start_element($xml,"styling");
$style_id = 1;
/* http://www.w3.org/TR/2003/WD-tt-af-1-0-req-20030915/#model */
/* R306 – Style Parameters – Visual */
//todo
/*not yet implemented:
-opacity
-visibility
-background color
*/
$styles_numbers= ( count($captions["styles"]) - 1);
for ($style_id=1; $style_id <= $styles_numbers; $style_id++){
//start element