<?php



 /**

 * @package Folder Menu

 * @author Web-Dorado

 * @copyright (C) 2011 Web-Dorado. All rights reserved.

 * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html

 **/

 

defined( '_JEXEC' ) or die( 'Restricted access' );



class modFolderMenuHelper

{



 	function getMenus(&$params) 

	{

	 

	   jimport( 'joomla.html.parameter' );

		$items = &JSite::getMenu();

		

		

		// Get Menu Items

		$rows = $items->getItems('menutype', $params->get('menutype'));

		$xml_content='<dropdown>

	<settings

		closeMenuOnClick= "yes"

		menuColor = "0x'.$params->get('menuColor').'"

		menuFontColor = "0x'.$params->get('menuFontColor').'"

		menuFontGlowColor = "0x'.$params->get('menuFontGlowColor').'"

		subMenuFontColor = "0x'.$params->get('subMenuFontColor').'"

		subMenuFontGlowColor = "0x'.$params->get('subMenuFontGlowColor').'"

		> 	



	</settings>';

	

				if ( is_array($rows)) {

			while (count($rows) && !is_null($row = array_shift($rows)))

			{

			$id=$row->id;

			

						

			

			switch ($row->type)

		{

			case 'separator' :

				

				break;



			case 'url' :

				if ((strpos($row->link, 'index.php?') === 0) && (strpos($row->link, 'Itemid=') === false)) {

					$row->url = $row->link.'&amp;Itemid='.$row->id;

				} else {

					$row->url = $row->link;

				}

				break;



			default :

				$router = JSite::getRouter();

				$row->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$row->id : $row->link.'&Itemid='.$row->id;

				break;

		}

			

			

			

			

			

			$iParams = new JParameter($row->params);

			$iSecure = $iParams->def('secure', 0);

if($row->type!='separator')	

			if ($row->home == 1) {

				$row->url = JURI::base();

			} else if (strcasecmp(substr($row->url , 0, 4), 'http') && (strpos($row->url, 'index.php?') !== false)) {

				$row->url  = JRoute::_($row->url , true, $iSecure);

			} else {

				$row->url  = str_replace('&', '&amp;', $row->link );

			}

			

			

			

			

			if($row->type!='separator')	{	

			

			

			if (strcasecmp(substr($row->url, 0, 4), 'http') && (strpos($row->url, 'index.php?') !== false)) {

					$link = JRoute::_($row->url, true, $iSecure);

				}

				else {

					$link = JRoute::_($row->url);

				}

				

				

				if( $row->type=='url' and strcasecmp(substr($row->url, 0, 4), 'http') && (strpos($row->url, 'index.php?') === false) )

				{

				$link=JURI::base().$row->url;

				

				}

				

				

			//$link=JRoute::_($row->url, true, $iSecure);

			

			}

			else

			$link='javascript:;';

			

			

			

			

			

			$parent=$row->parent_id;

			$name=$row->title;

			

			$menu1[$id]=$parent;

			

			$menu[$parent][$id]=array($name,$link,$row->browserNav); 

			if($parent!=1 and $parent!=$id)

			$spets[$parent]=1;	



			}

				}

				

				

				if(isset($menu))

				{

				$xml_content.=modFolderMenuHelper::getMenuXML($menu,1);

				$session =& JFactory::getSession();

				$session->set('submenu_it', 0);

				}

			 $xml_content.='</dropdown>';



			 return $xml_content;

	}

	

	

		function getMenuXML($menu,$key) {

										

					 $xml_content="";

					 

					$session =& JFactory::getSession();

					



					foreach($menu[$key] as $key1 => $value){

		

					if($key==1)

								{

						$xml_content.='<menu cap="'.$value[0].'"

								url = "'.$value[1].' "

								window = "'.($value[2]?"_blank":"_self").'" >';

						

						$session->set('submenu_it', 0);

								}

					else

								{

						$session->set('submenu_it', ($session->get('submenu_it')+1));

								

						if($session->get('submenu_it')<=22)

						$xml_content.='<submenu cap="'.$value[0].'"		

								url = "'.$value[1].'" 	 

								window = "'.($value[2]?"_blank":"_self").'" >

								</submenu>

							';

					

										

								

								}

							

	             

								

				 if(isset($menu[$key1])){

				 	  $xml_content.=modFolderMenuHelper::getMenuXML($menu,$key1);

				}



				

					  if($key==1)

					   $xml_content.='</menu>';

					 }

				

					 

					return $xml_content;

				

				

				}

	

		function writeinXML(&$params,&$module) {

					$stringData=modFolderMenuHelper::getMenus($params);

					$session =& JFactory::getSession();

                    $module_id=$module->id;

                    $session->set('xml_content_foldermenu_'.$module_id, $stringData);

					

				}



}

?>