<?php
/**
 * slideshare 1.1.8 for Joomla! 1.5 - 17 July 2009
 * @license http://www.gnu.org/licenses/gpl.html GNU/GPL.
 * @by ot2sen
 * @Copyright (C) 2008-2009 http://www.ot2sen.dk
  */
defined( '_JEXEC' ) or die( 'Restricted access' );

class  plgContentSlideshare15 extends JPlugin
{
	/**
	 * Constructor
	 *
	 * For php4 compatability we must not use the __constructor as a constructor for plugins
	 * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
	 * This causes problems with cross-referencing necessary for the observer design pattern.
	 *
	 * @access	protected
	 * @param	object		$subject The object to observe
	 * @since	1.0
	 */
	function plgContentSlideshare (& $subject) {
		parent::__construct($subject);
	}
}
$mainframe->registerEvent( 'onPrepareContent', 'slideshare15' );

function slideshare15(&$row, &$params) {

	$regex = "#{slideshare}(.*?){/slideshare}#s";

$plugin =&JPluginHelper::getPlugin('content', 'slideshare15');
$pluginParams = new JParameter( $plugin->params );
if ( !$pluginParams->get( 'enabled', 1 ) ){ 
 //plugin not published 
}else  { 
  //plugin published 
}

	$row->text = preg_replace_callback( $regex, 'slideshare15_replacer', $row->text );
	return true;
}

/**
* @param array An array of matches
* @return string
*/
function slideshare15_replacer ( &$matches ) {
	
$slideshare = $matches[1];	


// load language files
$lang = & JFactory::getLanguage();
$lang->load('plg_content_slideshare15' , JPATH_ADMINISTRATOR );

// load plugin params info
$plugin =& JPluginHelper::getPlugin('content', 'slideshare15');
$pluginParams = new JParameter( $plugin->params );

$pluginParams->def('width', '425');
$pluginParams->def('height', '350');
$pluginParams->def('alignslide', 'center');
$pluginParams->def('related', '0');

//Input embed code that needs to be customized
$original = $slideshare;

//116 Extra replace to ensure embed urls transformed to valid xhtml (&amp;) in WISIWYG editor will be handled correctly
$tidiedoriginal = str_replace("&amp;","&", $original);
//echo "Modified original embed = $tidiedoriginal <br />";

//Explode embedded code into parts to be able to identify id of various lengths
$embedParts = explode("&", $tidiedoriginal);
//echo "Original Embed Code = $original <br />";
//echo "Left Id block = $embedParts[0]<br />";
//echo "Name block = $embedParts[1]<br />";
//echo "Type block = $embedParts[2]<br />";

//117 Extra check for type of document for pdf�s from new slideshare shortcut urls adding &type=d
//118 Adding a forgotten isset check for the possible variable for type=d
if (isset($embedParts[2]) == ('type=d]')){$player = 'ssplayerd';}
else {$player = 'ssplayer2';}
//echo "Player = $player<br />";

//Make sure trailing ] is to be removed from new type embed url without &w=425, and still keep backward compatibility of older embeds
$embedtidyup = explode("]", $embedParts[1]);
//echo "Ny namestring = $embedtidyup[0]<br />";

//Isolate unique id by removing [slideshare id= and store in $cleaned_id
$cleaned_id = explode("=", $embedParts[0]);
//echo "Original Id block = $embedParts[0]<br />";
//echo "Left side = $cleaned_id[0]<br />";
//echo "Unique id = $cleaned_id[1]";

//Unique id is same as isolated cleaned
$cleaned_id2 = $cleaned_id[1];

//Unique name is same as isolated Name Block
$cleanedstr2 = $embedtidyup[0];

$res = '<div align="'.$pluginParams->get('alignslide').'" id="__ss_'. $cleaned_id2.'">
<object type="application/x-shockwave-flash" data="http://static.slidesharecdn.com/swf/'. $player.'.swf?'. $cleanedstr2.'&amp;rel='.$pluginParams->get('related').'" width="'.$pluginParams->get('width').'" height="'.$pluginParams->get('height').'"><param name="movie" value="http://static.slidesharecdn.com/swf/'. $player.'.swf?'. $cleanedstr2.'&amp;rel='.$pluginParams->get('related').'" /><param name="allowscriptaccess" value="always" /><param name="allowfullscreen" value="true" />
</object>
</div>';
	return $res;
}
?>