Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Youtube Embed Plugin
- *
- * Based on Cory Webb's Youtube Embedding plugin ( http://www.corywebbmedia.com/ )
- *
- * - improved regular expression
- * - override default width & height by adding #width,height to the youtube link
- * - don't parse youtube url inside a link
- *
- * @version $Id: youtubeembed.php 5 2011-03-12 21:40:29Z kotuha $
- * @author Steven Rombauts ( @kotuhaweb )
- * @email [email protected]
- */
- defined( '_JEXEC' ) or die( 'Restricted access' );
- jimport( 'joomla.plugin.plugin' );
- class plgContentYoutubeEmbed extends JPlugin
- {
- function plgContentYoutubeEmbed(&$subject, $params)
- {
- parent::__construct($subject, $params);
- }
- function onPrepareContent(&$article, &$params, $limitstart)
- {
- if(strpos($article->text, 'http://www.youtube.com/') === false && strpos($article->text, 'http://youtube.com/') === false) {
- return;
- }
- $pattern = '/(?<!href\=\"|\')(http:\/\/w{0,3}\.{0,1}youtube\.com\/watch\?([a-zA-Z0-9=&;]+)(\#?([0-9,]+))?)/ie';
- $article->text = preg_replace($pattern,
- '$this->getEmbedCode("\2", "\4")',
- $article->text
- );
- return;
- }
- function getEmbedCode($query, $hash)
- {
- $query = str_replace('&', '&', $query);
- $pairs = explode('&', $query);
- $arguments = array();
- foreach($pairs as $pair)
- {
- $parts = explode('=', $pair);
- $arguments[$parts[0]] = $parts[1];
- }
- $dimension = $this->getDimension($hash);
- return '<object width="'.$dimension->width.'" height="'.$dimension->height.'"><param name="movie" value="http://www.youtube.com/v/'.$arguments['v'].'"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'.$arguments['v'].'" type="application/x-shockwave-flash" allowfullscreen="true" width="'.$dimension->width.'" height="'.$dimension->height.'"></embed></object>';
- }
- function getDimension($hash)
- {
- $plugin =& JPluginHelper::getPlugin('content', 'youtubeembed');
- $params = new JParameter( $plugin->params );
- $dimension = new stdClass();
- $dimension->width = $params->get('width', 425);
- $dimension->height = $params->get('height', 344);
- if(strpos($hash, ',') !== false)
- {
- $dimensions = explode(',', $hash);
- $dimension->width = $dimensions[0];
- $dimension->height = $dimensions[1];
- }
- return $dimension;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement