$v)
$this->$k = $vc[$k];
}
}
/**
* Parse a clip, return a VideoClip object with that info
*/
function parseClip($cvals)
{
$anchors = array();
$hrefs = array();
for( $i = 0; $i < count($cvals); $i++ )
{
$tag = $cvals[$i]["tag"];
$val = $cvals[$i]["value"];
if( $tag == "title" )
{ $clip[$tag] = $val; }
elseif( $tag == "a" )
{
array_push($anchors, $val);
if( isset($cvals[$i]['attributes']) )
{
$h = $cvals[$i]['attributes']['href'];
array_push($hrefs, $h);
}
}
elseif( $tag == "filename" )
{
$clip[$tag] = $val;
}
}
$clip["anchors"] = $anchors;
$clip["hrefs"] = $hrefs;
return new VidClip($clip);
}
/**
* read the XML database (file)
*/
function readDB( $fname, &$cindex )
{
$data = implode("", file($fname));
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
// loop through the structures
foreach ($tags as $key=>$val)
{
if ($key == "clip")
{
$cvals = $val;
// each contiguous pair of array entries are the
// lower and upper range for each videoclip definition
for( $i = 0; $i < count($cvals); $i += 2 )
{
$offset = $cvals[$i] + 1;
$len = $cvals[$i + 1] - $offset;
$vdb[] = parseClip(array_slice($values, $offset, $len));
}
}
else
{
continue;
}
}
$vcount = 0;
for( $i = 0; $i < count($values); $i++ )
{
if( isset($values[$i]['tag']) && $values[$i]['tag'] == 'clip' )
{
if( isset($values[$i]['attributes']['name']) )
{
$clipname = $values[$i]['attributes']['name'];
$clip = &$vdb[$vcount];
$clip->name = $clipname;
$cindex[$clipname] = $clip;
$vcount++;
}
}
}
return $vdb;
}
//
// Code entry point - execution starts here...
//
// Load & parse the xml 'database' of video clips
$clipindex = array();
$vdb = readDB("video.xml", $clipindex);
$num = count($vdb);
$clip = null;
if( isset($_REQUEST['clip']) )
{
$cname = $_REQUEST['clip'];
if( isset($clipindex[$cname]) )
{
$clip = $clipindex[$cname];
}
}
// Did we find a clip yet? If not go by ID #... (or default to 1st)
if( $clip == NULL && isset($_REQUEST['vid']) )
{
$vid = $_REQUEST['vid'];
if( $vid > $num || $vid < 1 )
{ $vid = 0; }
else
{ $vid--; }
$clip = &$vdb[$vid];
}
// Clip should be selected by now
$clipname = $clip->name;
$mfname = $clip->filename;
// Related links
$relLinks = $clip->anchors;
$hLinks = $clip->hrefs;
$numRel = count($relLinks);
$lCount = (int)($numRel / 2);
$rCount = $numRel - $lCount;
if( $rCount > $lCount )
{
$tmp = $lCount;
$lCount = $rCount;
$rCount = $tmp;
}
?>

Video player



= $clip->title ?>
|

|
|

Related links:
|

' . $relLinks[$i] . " \n";
echo ' ' . "\n";
}
?>
|

' . $relLinks[$i] . " \n";
echo ' ' . "\n";
}
?>
|
|
 |

More Nerve clips:


|