<?php
/*------------------------------------------------------------------------
# mod_textmenufx.php - Text Menu FX
# ------------------------------------------------------------------------
# author    FlashXML.net
# copyright Copyright (C) 2011 flashxml.net. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.flashxml.net
# Technical Support:  Forum - http://www.flashxml.net/text-menu.html#comments
-------------------------------------------------------------------------*/
// no direct access
defined('_JEXEC') or die('Restricted access');

$textmenufx_path = $params->get('textmenufx_path');
if (strpos($textmenufx_path, '/') !== 0) {
	$textmenufx_path = '/'.$textmenufx_path;
	$params->def('textmenufx_path', $textmenufx_path);
}

$textmenufx_wmode = $params->get('textmenufx_wmode');
if (empty($textmenufx_wmode)) {
	$textmenufx_wmode = 'transparent';
	$params->def('textmenufx_wmode', $textmenufx_wmode);
}

$textmenufx_width = $textmenufx_height = 0;

switch (true) {
	case function_exists('simplexml_load_file') && file_exists(JPATH_BASE.$textmenufx_path.'settings.xml'):
		$xml = simplexml_load_file(JPATH_BASE.$textmenufx_path.'settings.xml');
		if ($xml) {
			$textmenufx_width_attributes_array = $xml->General_Properties->componentWidth->attributes();
				$textmenufx_width = !empty($textmenufx_width_attributes_array) ? (int)$textmenufx_width_attributes_array['value'] : 0;
				$textmenufx_height_attributes_array = $xml->General_Properties->componentHeight->attributes();
				$textmenufx_height = !empty($textmenufx_height_attributes_array) ? (int)$textmenufx_height_attributes_array['value'] : 0;
		}
	break;

	case (int)$params->get('textmenufx_width') > 0 && (int)$params->get('textmenufx_height') > 0:
		$textmenufx_width = (int)$params->get('textmenufx_width');
		$textmenufx_height = (int)$params->get('textmenufx_height');
	break;

	default:
		echo '<!--  invalid path to the settings XML file, please use valid module parameter values -->';
	break;
}

if ($textmenufx_width > 0 && $textmenufx_height > 0) {
	$joomla_install_dir_in_url = rtrim(JURI::root(true), '/');
	if (!empty($joomla_install_dir_in_url) && strpos($joomla_install_dir_in_url, '/') !== 0) {
		$joomla_install_dir_in_url = '/' . $joomla_install_dir_in_url;
	}

	$doc =& JFactory::getDocument();
	$doc->addScript('http'.(!empty($_SERVER['HTTPS']) ? 's' : '').'://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js');

	echo '<div id="flashxmltextmenu"></div><script type="text/javascript">'."swfobject.embedSWF('{$joomla_install_dir_in_url}{$textmenufx_path}TextMenuFX.swf', 'flashxmltextmenu', '{$textmenufx_width}', '{$textmenufx_height}', '9.0.0.0', '', { folderPath: '{$joomla_install_dir_in_url}{$textmenufx_path}' }, { scale: 'noscale', salign: 'tl', wmode: '{$textmenufx_wmode}', allowScriptAccess: 'sameDomain', allowFullScreen: true }, {});</script>";
} else {
	echo '<!--  invalid Text Menu FX width / height -->';
}