I’m going slightly crazy here, this here code below works real nice when I run it straight as php code but as soon as I save it as a snippet it doesnt work.
<?php
$ypp_feed_url = "http://gdata.youtube.com/feeds/playlists/4A4F1225777AD974";
$ypp_video_width=300;
$ypp_video_height=251;
$ypp_headline_key = "*FEED*ENTRY*TITLE"; //custom title
$ypp_description_key = "*FEED*ENTRY*YT:DESCRIPTION"; //custom description
$ypp_original_title = "*FEED*ENTRY*MEDIA:GROUP*MEDIA:TITLE";//original title ATTRIBUTE
$ypp_original_description_key = "*FEED*ENTRY*MEDIA:GROUP*MEDIA:DESCRIPTION"; //original description ATTRIBUTE
$ypp_player_url_key = "*FEED*ENTRY*MEDIA:GROUP*MEDIA:PLAYER"; //player url ATTRIBUTE
$ypp_player_entry_key = "*FEED*ENTRY"; //EACH VIDEO IS IN ONE ENTRY WRAPPER
$ypp_video_array = array();
$ypp_counter = 0;
$output = ''; //final output
function ypp_showVideo($url){
global $ypp_video_width, $ypp_video_height;
$t=explode("=", $url);
$file = $t[1];
$out = '<object width="'.$ypp_video_width.'" height="'.$ypp_video_height.'">
<param name="movie" value="http://www.youtube.com/v/'.$file.'" />
<param name="wmode" value="transparent" />
<embed src="http://www.youtube.com/v/'.$file.'&color1=0x5d1719&color2=0xcd311b&border=1" width="'.$ypp_video_width.'" height="'.$ypp_video_height.'" type="application/x-shockwave-flash" wmode="transparent" />
</object>';
return $out;
}
function ypp_startTag($ypp_parser, $ypp_data, $ypp_attributes){
global $ypp_current_tag, $ypp_counter, $ypp_video_array;
global $ypp_player_entry_key, $ypp_player_url_key;
$ypp_current_tag .= "*$ypp_data";
if($ypp_current_tag == $ypp_player_url_key){
$ypp_video_array[$ypp_counter]['player_url'] = $ypp_attributes['URL'];
}
}
function ypp_endTag($ypp_parser, $ypp_data){
global $ypp_current_tag, $ypp_counter, $ypp_player_entry_key;
if($ypp_current_tag == $ypp_player_entry_key){
$ypp_counter++;
}
$tag_key = strrpos($ypp_current_tag, '*');
$ypp_current_tag = substr($ypp_current_tag, 0, $tag_key);
}
function ypp_contents($ypp_parser, $ypp_data){
global $ypp_current_tag;
global $ypp_player_url_key, $ypp_headline_key;
global $ypp_description_key, $ypp_counter;
global $ypp_video_array, $ypp_original_title_key;
global $ypp_original_description_key, $ypp_player_entry_key;
switch($ypp_current_tag){
case $ypp_player_entry_key:
break;
$ypp_video_array[$ypp_counter]['headline'] = $ypp_data;
break;
case $ypp_original_title:
$ypp_video_array[$ypp_counter]['original_title'] = $ypp_data;
break;
case $ypp_original_description_key:
$ypp_video_array[$ypp_counter]['original_description'] = $ypp_data;
break;
case $ypp_description_key:
$ypp_video_array[$ypp_counter]['description'] = $ypp_data;
break;
}
}
$ypp_parser = xml_parser_create();
xml_set_element_handler($ypp_parser, 'ypp_startTag', 'ypp_endTag');
xml_set_character_data_handler($ypp_parser, 'ypp_contents');
if( !($ypp_datastream = fopen($ypp_feed_url, 'r'))){
$output .='<p>Could not open file</p>';
}
if ( !($ypp_data = stream_get_contents($ypp_datastream) )){
$output .='<p>Could not read file</p>';
}
if( !(xml_parse($ypp_parser, $ypp_data, feof($ypp_datastream) ) ) ){
$output .= '<p>Error on line ' . xml_get_current_line_number($ypp_parser) .'</p>' ;
}
fclose($ypp_datastream);
$output .= "\n";
for($x=0; $x < count($ypp_video_array); $x++){
if($ypp_video_array[$x]['description'] != ""){
$ypp_t_desc = $ypp_video_array[$x]['description'];
}else{
$ypp_t_desc = $ypp_video_array[$x]['original_description'];
}
if($ypp_video_array[$x]['headline'] != ""){
$ypp_t_title = $ypp_video_array[$x]['headline'];
}else{
$ypp_t_title = $ypp_video_array[$x]['original_title'];
}
$ypp_t_video = ypp_showVideo($ypp_video_array[$x]['player_url']);
$output_chunkArr = array('video' => $ypp_t_video,'title' => $ypp_t_title,'description' => $ypp_t_desc);
$output .= $modx->parseChunk('YouTubePlaylist', $output_chunkArr, '[+', '+]');
}//end for
return $output;
?>
The only changes period from the raw script which works and the snippet is this:
$output_chunkArr = array('video' => $ypp_t_video,'title' => $ypp_t_title,'description' => $ypp_t_desc);
$output .= $modx->parseChunk('YouTubePlaylist', $output_chunkArr, '[+', '+]');
and even when I take those lines out and print the output directly or return the output preformatted without the chunk it still doesnt work as a snippet.
any help would be greatly appreciated!