Data at Your Fingertips: Explore Our New Reporting and Statistical Capabilities By Ryan Ashbrook Yesterday at 01:29 PM
Ilya Hoilik Posted March 15, 2016 Share Posted March 15, 2016 Hello developers! Now I'm working on extended streams for my client. He want to see media (YouTube, SoundCloud, Last.fm or Image) from content in each item in the stream. In general (without custom design) he want to see something like this: I'm using \DOMDocument. It works correctly. But maybe you have a better approach how to realize it? Or suggestion how to make it easier? Because I'm not sure this is a best way. This is my code to parse YouTube video: <!-- Load content from topic row (if this is a topic) --> {{if $indexData['index_class'] == 'IPS\forums\Topic\Post'}} {{$post = \IPS\Db::i()->select( 'post', 'forums_posts', array( 'pid=?', $indexData['index_object_id'] ) )->first();}} {{endif}} <!-- Create DOMDocument --> {{$domdoc = new \DOMDocument;}} {{libxml_use_internal_errors(true);}} {{$domdoc->loadHTML( $post );}} {{libxml_use_internal_errors(false);}} <!-- Get links to video and preview image --> {{foreach $domdoc->getElementsByTagName('iframe') as $video}} {{if $domdoc->getElementsByTagName('iframe')->length}} {{$link = $video->getAttribute('src');}} {{$preview = 'http://img.youtube.com/vi/' . explode( '?', explode( '/', $video->getAttribute('src') )[4] )[0] . '/hqdefault.jpg';}} {{break;}} {{endif}} {{endforeach}} <!-- Now we can use $link to display YouTube link and $preview to display YouTube preview image --> Thank you in advance! Link to comment Share on other sites More sharing options...
bfarber Posted April 8, 2016 Share Posted April 8, 2016 I see nothing wrong with your approach, however to keep the template cleaner I might recommend creating a template plugin (under, e.g. system/Output/Plugin/ if you aren't creating a full-blown app) that does this work. It'll be easier to troubleshoot and debug if anything doesn't work properly, and it'll keep the templates cleaner and easier to read. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.