Recent Topics

1 Mar 29, 2007 16:32    

/**
* This plugin makes a toolbar that allows easy insertion of the tags required
* to link to various sites that the youtube plugin can embed videos from.
*
* Credits go to b2evolution.net for the quicktags plugin,
* and to Danny Ferguson ( http://www.brendoman.com/dbc )
* for the youtube plugin ( http://manual.b2evolution.net/Plugins/youtube_plugin )
*
* Without the youtube plugin this plugin will serve no purpose.
*
* @package plugins
*/

<?php
/**
 * This plugin makes a toolbar that allows easy insertion of the tags required
 * to link to various sites that the youtube plugin can embed videos from.
 *
 * Credits go to b2evolution.net for the quicktags plugin,
 * and to Danny Ferguson ( http://www.brendoman.com/dbc ) 
 * for the youtube plugin ( http://manual.b2evolution.net/Plugins/youtube_plugin )
 *
 * Without the youtube plugin this plugin will serve no purpose.
 *
 * @package plugins
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

/**
 * @package plugins
 */
class youtubequicktags_plugin extends Plugin
{
	var $code = 'youQTags';
	var $name = 'Youtube Quick Tags';
	var $priority = 31;
	var $version = '1';

	/**
	 * Init
	 */
	function PluginInit( & $params )
	{
		$this->short_desc = T_('Easy video tags inserting');
		$this->long_desc = T_('This plugin will display a toolbar with buttons to quickly insert video links in conjunction with the youtube plugin.');
	}


	/**
	 * Display a toolbar
	 *
	 * @param array Associative array of parameters
	 * @return boolean did we display a toolbar?
	 */
	function AdminDisplayToolbar( & $params )
	{
		global $Hit;

		if( $params['edit_layout'] == 'simple' )
		{	// Thsi is too complex for simple mode, don't display it:
			return false;
		}

		if( $Hit->is_lynx )
		{ // let's deactivate quicktags on Lynx, because they don't work there.
			return false;
		}
		?>

		<script type="text/javascript">
		//<![CDATA[
		var ytqtButtons = new Array();
		var ytqtLinks = new Array();
		var ytqtOpenTags = new Array();

		function ytqtButton(id, display, tagStart, tagEnd, access, tit, open) {
			this.id = id;							// used to name the toolbar button
			this.display = display;		// label on button
			this.tagStart = tagStart; // open tag
			this.tagEnd = tagEnd;			// close tag
			this.access = access;			// access key
			this.tit = tit;						// title
			this.open = open;					// set to -1 if tag does not need to be closed
		}

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_youtube'
				,'youtube'
				,'[youtube]','[/youtube]'
				,'1'
				,'<?php echo T_('youtube [Alt-1]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_ifilm'
				,'ifilm'
				,'[ifilm]','[/ifilm]'
				,'2'
				,'<?php echo T_('ifilm [Alt-2]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_gvid'
				,'gvid'
				,'[gvid]','[/gvid]'
				,'3'
				,'<?php echo T_('gvid [Alt-3]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_current'
				,'current'
				,'[current]','[/current]'
				,'4'
				,'<?php echo T_('current [Alt-4]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_dailymotion'
				,'dailymotion'
				,'[dailymotion]','[/dailymotion]'
				,'5'
				,'<?php echo T_('dailymotion [Alt-5]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_jumpcut'
				,'jumpcut'
				,'[jumpcut]','[/jumpcut]'
				,'6'
				,'<?php echo T_('jumpcut [Alt-6]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_revver'
				,'revver'
				,'[revver]','[/revver]'
				,'7'
				,'<?php echo T_('revver [Alt-7]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_vsocial'
				,'vsocial'
				,'[vsocial]','[/vsocial]'
				,'8'
				,'<?php echo T_('vsocial [Alt-8]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_blip'
				,'blip'
				,'[blip]','[/blip]'
				,'9'
				,'<?php echo T_('blip [Alt-9]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_metacafe'
				,'metacafe'
				,'[metacafe]','[/metacafe]'
				,'0'
				,'<?php echo T_('metacafe [Alt-0]') ?>'
			);

		ytqtButtons[ytqtButtons.length] = new ytqtButton(
				'b2evo_break'
				,'break'
				,'[break]','[/break]'
				,'q'
				,'<?php echo T_('break [Alt-Q]') ?>'
			);

		function b2evoLink() {
			this.display = '';
			this.URL = '';
			this.newWin = 0;
		}

		function ytqtShowButton(button, i)
		{
			if (button.id == 'spacer')
			{
				document.write( button.tagStart );
			}
			else if (button.id == 'b2evo_img')
			{
				document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit + '" class="quicktags" onclick="ytqtInsertImage(b2evoCanvas);" value="' + button.display + '" />');
			}
			else if (button.id == 'b2evo_link')
			{
				document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit + '" class="quicktags" onclick="ytqtInsertLink(b2evoCanvas, ' + i + ');" value="' + button.display + '" />');
			}
			else
			{
				document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit + '" class="quicktags" onclick="ytqtInsertTag(b2evoCanvas, ' + i + ');" value="' + button.display + '"  />');
			}
		}

		function ytqtAddTag(button) {
			if (ytqtButtons[button].tagEnd != '') {
				ytqtOpenTags[ytqtOpenTags.length] = button;
				document.getElementById(ytqtButtons[button].id).value = '/' + document.getElementById(ytqtButtons[button].id).value;
			}
		}

		function ytqtRemoveTag(button) {
			for (i = 0; i < ytqtOpenTags.length; i++) {
				if (ytqtOpenTags[i] == button) {
					ytqtOpenTags.splice(i, 1);
					document.getElementById(ytqtButtons[button].id).value = 		document.getElementById(ytqtButtons[button].id).value.replace('/', '');
				}
			}
		}

		function ytqtCheckOpenTags(button) {
			var tag = 0;
			for (i = 0; i < ytqtOpenTags.length; i++) {
				if (ytqtOpenTags[i] == button) {
					tag++;
				}
			}
			if (tag > 0) {
				return true; // tag found
			}
			else {
				return false; // tag not found
			}
		}

		function ytqtCloseAllTags() {
			var count = ytqtOpenTags.length;
			for (o = 0; o < count; o++) {
				ytqtInsertTag(b2evoCanvas, ytqtOpenTags[ytqtOpenTags.length - 1]);
			}
		}

		function ytqtToolbar() {
			document.write('<div>');
			for (var i = 0; i < ytqtButtons.length; i++) {
				ytqtShowButton(ytqtButtons[i], i);
			}
			document.write('<input type="button" id="b2evo_close" class="quicktags" onclick="ytqtCloseAllTags();" title="<?php echo T_('Close all tags') ?>" value="X" />');
			document.write('</div>');
		}

		// insertion code
		function ytqtInsertTag(myField, i)
		{
			if( typeof b2evo_Callbacks == 'object' )
			{ // see if there's a callback registered that should handle this:
				if (!ytqtCheckOpenTags(i) || ytqtButtons[i].tagEnd == '') {
					if( b2evo_Callbacks.trigger_callback("insert_raw_into_"+myField.id, ytqtButtons[i].tagStart) )
					{
						ytqtAddTag(i);
						return;
					}
				}
				else {
					if( b2evo_Callbacks.trigger_callback("insert_raw_into_"+myField.id, ytqtButtons[i].tagEnd) )
					{
						ytqtRemoveTag(i);
						return;
					}
				}

			}

			//IE support
			if (document.selection)
			{
				myField.focus();
					sel = document.selection.createRange();
				if (sel.text.length > 0) {
					sel.text = ytqtButtons[i].tagStart + sel.text + ytqtButtons[i].tagEnd;
				}
				else {
					if (!ytqtCheckOpenTags(i) || ytqtButtons[i].tagEnd == '') {
						sel.text = ytqtButtons[i].tagStart;
						ytqtAddTag(i);
					}
					else {
						sel.text = ytqtButtons[i].tagEnd;
						ytqtRemoveTag(i);
					}
				}
				myField.focus();
			}
			//MOZILLA/NETSCAPE support
			else if (myField.selectionStart || myField.selectionStart == '0')
			{
				var startPos = myField.selectionStart;
				var endPos = myField.selectionEnd;
				var cursorPos = endPos;

				var scrollTop, scrollLeft;
				if( myField.type == 'textarea' && typeof myField.scrollTop != 'undefined' )
				{ // remember old position
					scrollTop = myField.scrollTop;
					scrollLeft = myField.scrollLeft;
				}

				if (startPos != endPos)
				{ // some text selected
					myField.value = myField.value.substring(0, startPos)
												+ ytqtButtons[i].tagStart
												+ myField.value.substring(startPos, endPos)
												+ ytqtButtons[i].tagEnd
												+ myField.value.substring(endPos, myField.value.length);
					cursorPos += ytqtButtons[i].tagStart.length + ytqtButtons[i].tagEnd.length;
				}
				else
				{
					if (!ytqtCheckOpenTags(i) || ytqtButtons[i].tagEnd == '')
					{
						myField.value = myField.value.substring(0, startPos)
													+ ytqtButtons[i].tagStart
													+ myField.value.substring(endPos, myField.value.length);
						ytqtAddTag(i);
						cursorPos = startPos + ytqtButtons[i].tagStart.length;
					}
					else
					{
						myField.value = myField.value.substring(0, startPos)
													+ ytqtButtons[i].tagEnd
													+ myField.value.substring(endPos, myField.value.length);
						ytqtRemoveTag(i);
						cursorPos = startPos + ytqtButtons[i].tagEnd.length;
					}
				}

				if( typeof scrollTop != 'undefined' )
				{ // scroll to old position
					myField.scrollTop = scrollTop;
					myField.scrollLeft = scrollLeft;
				}

				myField.focus();
				myField.selectionStart = cursorPos;
				myField.selectionEnd = cursorPos;
			}
			else
			{ // Browser not especially supported
				if (!ytqtCheckOpenTags(i) || ytqtButtons[i].tagEnd == '') {
					myField.value += ytqtButtons[i].tagStart;
					ytqtAddTag(i);
				}
				else {
					myField.value += ytqtButtons[i].tagEnd;
					ytqtRemoveTag(i);
				}
				myField.focus();
			}
		}

		function ytqtInsertContent(myField, myValue) {
			if( typeof b2evo_Callbacks == 'object' )
			{ // see if there's a callback registered that should handle this:
				if( b2evo_Callbacks.trigger_callback("insert_raw_into_"+myField.id, myValue) )
				{
					return;
				}
			}

			//IE support
			if (document.selection) {
				myField.focus();
				sel = document.selection.createRange();
				sel.text = myValue;
				myField.focus();
			}
			//MOZILLA/NETSCAPE support
			else if (myField.selectionStart || myField.selectionStart == '0') {
				var startPos = myField.selectionStart;
				var endPos = myField.selectionEnd;
				myField.value = myField.value.substring(0, startPos)
											+ myValue
											+ myField.value.substring(endPos, myField.value.length);
				myField.focus();
				myField.selectionStart = startPos + myValue.length;
				myField.selectionEnd = startPos + myValue.length;
			} else {
				myField.value += myValue;
				myField.focus();
			}
		}

		function ytqtInsertLink(myField, i, defaultValue) {
			if (!defaultValue) {
				defaultValue = 'http://';
			}
			if (!ytqtCheckOpenTags(i)) {
				var URL = prompt('<?php echo T_('URL') ?>:' ,defaultValue);
				if (URL) {
					ytqtButtons[i].tagStart = '<a href="' + URL + '">';
					ytqtInsertTag(myField, i);
				}
			}
			else {
				ytqtInsertTag(myField, i);
			}
		}

		function ytqtInsertImage(myField) {
			var myValue = prompt('<?php echo T_('URL') ?>:', 'http://');
			if (myValue) {
				myValue = '<img src="'
						+ myValue
						+ '" alt="' + prompt('<?php echo T_('ALTernate text') ?>:', '')
						+ '" title="' + prompt('<?php echo T_('Title') ?>:', '')
						+ '" />';
				ytqtInsertContent(myField, myValue);
			}
		}
		//]]>
		</script>

		<div class="edit_toolbar"><script type="text/javascript">ytqtToolbar();</script></div>

		<?php
		return true;
	}
}

/*
 nolog */
?>


Form is loading...