Your IP : 216.73.216.182


Current Path : /home/azimutno/www/demo/modules/mod_swmenupro/helpers/
Upload File :
Current File : /home/azimutno/www/demo/modules/mod_swmenupro/helpers/functions.php

<?php

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

function swGetMenu($menu, $id, $hybrid, $use_table, $parent_id, $levels) {
   $swmenupro_array=swGetMenuLinks($menu,$id,$hybrid,$use_table);
                        //echo $menu.$id.count($swmenupro_array);
			$final_menu=get_Final_Menu($swmenupro_array, $parent_id, $levels);
	  
       // echo count($final_menu);
        return $final_menu;
}

function get_Final_Menu($swmenupro_array, $parent_id, $levels) {
   
    $valid = 1;
    $my = JFactory::getUser();
    //$param= & JForm::bind();
    $final_menu = array();
    $group = ($my->getAuthorisedGroups());
    //print_r ($group);
    if (count($group) < 2) {
        $group[0] = 1;
        $group[1] = 1;
    }

    $access = $my->getAuthorisedViewLevels();

    for ($i = 0; $i < count($swmenupro_array); $i++) {
        $swmenu = $swmenupro_array[$i];
        if ($swmenu['SHOWITEM'] == null || $swmenu['SHOWITEM'] == 1) {
            $swmenu['SHOWITEM'] = 1;
        } else {
            $swmenu['SHOWITEM'] = 0;
        }

        //if(($swmenu['ACCESS']<=($group[1]) && $swmenu['SHOWITEM'] ) ){
        if (in_array((int) $swmenu['ACCESS'], $access) && $swmenu['SHOWITEM']) {
            if ($swmenu['PARENT'] == $parent_id) {
                $valid++;
            }


           
            if (strcasecmp(substr($swmenu['URL'], 0, 4), 'http') && (strpos($swmenu['URL'], 'index.php?') !== false))
					{
						$swmenu['URL'] = JRoute::_($swmenu['URL'], true, $swmenu['SECURE']);
					}
					else
					{
						$swmenu['URL'] = JRoute::_($swmenu['URL']);
					}
            //echo $swmenu['URL'];
            $swmenu['URL'] = str_replace('&amp;', '&', $swmenu['URL']);
            $final_menu[] = array("TITLE" => $swmenu['TITLE'], "URL" => $swmenu['URL'], "ID" => $swmenu['ID'], "PARENT" => $swmenu['PARENT'], "ORDER" => $swmenu['ORDER'], "IMAGE" => $swmenu['IMAGE'], "IMAGEOVER" => $swmenu['IMAGEOVER'], "SHOWNAME" => $swmenu['SHOWNAME'], "IMAGEALIGN" => $swmenu['IMAGEALIGN'], "TARGETLEVEL" => $swmenu['TARGETLEVEL'], "TARGET" => $swmenu['TARGET'], "ACCESS" => $swmenu['ACCESS'], "NCSS" => $swmenu['NCSS'], "OCSS" => $swmenu['OCSS'], "SHOWITEM" => $swmenu['SHOWITEM'], "HTML" => $swmenu['HTML'],"HTML_POSITION" =>$swmenu['HTML_POSITION']);
        }
    }
    //  echo count($final_menu)."ff";
    if (count($final_menu) && $valid) {
        $final_menu = chain('ID', 'PARENT', 'ORDER', $final_menu, $parent_id, 25);
    } else {
        $final_menu = array();
    }
    //echo count($final_menu);
    return $final_menu;
}

function swGetMenuLinks($menu, $id, $hybrid, $use_tables) {
   $database = JFactory::getDBO();
	$config=JFactory::getConfig();
	$time_offset=0;
	$now = date( "Y-m-d H:i:s", time()+$time_offset*60*60 );
    $swmenupro_array = array();
    //echo $use_tables;
    if ($menu == "swcontentmenu") {


        $sql = "SELECT #__categories.* , #__swmenu_extended.* 
                FROM #__categories LEFT JOIN #__swmenu_extended ON (#__categories.id) = #__swmenu_extended.menu_id
                WHERE (#__swmenu_extended.moduleID = '" . $id . "' OR #__swmenu_extended.moduleID IS NULL)
                AND #__categories.extension='com_content'
                AND #__categories.published = 1
                
                ORDER BY lft
                ";

        $database->setQuery($sql);
        $result = $database->loadObjectList();

        for ($i = 0; $i < count($result); $i++) {
            $result2 = $result[$i];


            if (!$use_tables) {
                $url = "index.php?option=com_content&view=category&id=" . $result2->id;
            } else {
                $url = "index.php?option=com_content&view=category&layout=blog&id=" . $result2->id;
            }

            $swmenupro_array[] = array("TITLE" => $result2->title, "URL" => $url, "ID" => $result2->id, "SECURE" => 0, "PARENT" => $result2->parent_id, "ORDER" => $result2->lft, "IMAGE" => $result2->image, "IMAGEOVER" => $result2->image_over, "SHOWNAME" => $result2->show_name, "IMAGEALIGN" => $result2->image_align, "TARGETLEVEL" => $result2->target_level, "TARGET" => 0, "ACCESS" => $result2->access, "NCSS" => $result2->normal_css, "OCSS" => $result2->over_css, "SHOWITEM" => $result2->show_item, "HTML" => $result2->custom_html,"HTML_POSITION" =>$result2->html_position);
        }


        $sql = "SELECT #__content.* , #__swmenu_extended.*
                FROM #__content LEFT JOIN #__swmenu_extended ON (#__content.id) = #__swmenu_extended.menu_id
                AND (#__swmenu_extended.moduleID = '" . $id . "' OR #__swmenu_extended.moduleID IS NULL)
                INNER JOIN #__categories ON #__content.catid = #__categories.id
                AND #__content.state = 1
                AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now'  )
                AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )
               ORDER BY #__content.ordering
                ";
        $database->setQuery($sql);
        $result = $database->loadObjectList();

        for ($i = 0; $i < count($result); $i++) {
            $result2 = $result[$i];


            $url = "index.php?option=com_content&view=article&id=" . $result2->id;
            $swmenupro_array[] = array("TITLE" => $result2->title, "URL" => $url, "ID" => $result2->id + 10000, "SECURE" => 0, "PARENT" => $result2->catid, "ORDER" => $result2->ordering, "IMAGE" => $result2->image, "IMAGEOVER" => $result2->image_over, "SHOWNAME" => $result2->show_name, "IMAGEALIGN" => $result2->image_align, "TARGETLEVEL" => $result2->target_level, "TARGET" => 0, "ACCESS" => $result2->access, "NCSS" => $result2->normal_css, "OCSS" => $result2->over_css, "SHOWITEM" => $result2->show_item, "HTML" => $result2->custom_html,"HTML_POSITION" =>$result2->html_position);
        }
    } else if ($menu == "virtuemart2" || $menu == "virtueprod2") {
        
        
         $sql = "SELECT  #__virtuemart_configs.config
                FROM #__virtuemart_configs
                WHERE #__virtuemart_configs.virtuemart_config_id=1";
         $database->setQuery($sql);
         $result=$database->loadResult();
        // echo "config=".$result;
         //print_r($result);
         
       $config = explode('|', $result);
			foreach($config as $item){
				$item = explode('=',$item);
				if(!empty($item[1])){
					// if($item[0]!=='offline_message' && $item[0]!=='dateformat' ){
					if($item[0]!=='offline_message' ){
						$pair[$item[0]] = unserialize($item[1] );
					} else {
						$pair[$item[0]] = unserialize(base64_decode($item[1]) );
					}

				} else {
					$pair[$item[0]] ='';
				}

			}
//$result=$jlang->getDefault();
//print_r($pair);
$vmlang= $pair['vmlang'];
        
        
        
        
        $sql = "SELECT #__virtuemart_categories_".$vmlang.".* ,#__swmenu_extended.*,#__virtuemart_category_categories.*,#__virtuemart_categories.*
 FROM #__virtuemart_categories,#__virtuemart_categories_".$vmlang." LEFT JOIN #__swmenu_extended ON #__virtuemart_categories_".$vmlang.".virtuemart_category_id+10000 = #__swmenu_extended.menu_id
                AND (#__swmenu_extended.moduleID = '" . $id . "' OR #__swmenu_extended.moduleID IS NULL)
                INNER JOIN #__virtuemart_category_categories ON #__virtuemart_category_categories.category_child_id= #__virtuemart_categories_".$vmlang.".virtuemart_category_id
                WHERE #__virtuemart_categories.virtuemart_category_id=#__virtuemart_categories_".$vmlang.".virtuemart_category_id
                AND #__virtuemart_categories.published='1'
                ORDER BY #__virtuemart_categories.ordering
                ";
        $database->setQuery($sql);
        $result = $database->loadObjectList();
        // echo "helo".count($result);
        for ($i = 0; $i < count($result); $i++) {
            $result2 = $result[$i];
            $url = "index.php?option=com_virtuemart&view=category&virtuemart_category_id=" . $result2->virtuemart_category_id;
            $swmenupro_array[] = array("TITLE" => $result2->category_name, "URL" => $url, "ID" => ($result2->virtuemart_category_id + 10000), "SECURE" => 0, "PARENT" => ($result2->category_parent_id ? (($result2->category_parent_id + 10000)) : 0), "ORDER" => $result2->ordering, "IMAGE" => $result2->image, "IMAGEOVER" => $result2->image_over, "SHOWNAME" => $result2->show_name, "IMAGEALIGN" => $result2->image_align, "TARGETLEVEL" => $result2->target_level, "TARGET" => 0, "ACCESS" => 1, "NCSS" => $result2->normal_css, "OCSS" => $result2->over_css, "SHOWITEM" => $result2->show_item, "HTML" => $result2->custom_html,"HTML_POSITION" =>$result2->html_position);

            if ($menu == "virtueprod2") {
                $sql = "SELECT #__virtuemart_products_".$vmlang.".*,#__swmenu_extended.* ,#__virtuemart_product_categories.*,#__virtuemart_products.*
                FROM #__virtuemart_products,#__virtuemart_products_".$vmlang." LEFT JOIN #__swmenu_extended ON #__virtuemart_products_".$vmlang.".virtuemart_product_id+100000 = #__swmenu_extended.menu_id
                AND (#__swmenu_extended.moduleID = '" . $id . "' OR #__swmenu_extended.moduleID IS NULL)
                INNER JOIN #__virtuemart_product_categories ON #__virtuemart_product_categories.virtuemart_product_id= #__virtuemart_products_".$vmlang.".virtuemart_product_id
                WHERE #__virtuemart_products.virtuemart_product_id=#__virtuemart_products_".$vmlang.".virtuemart_product_id
                AND #__virtuemart_product_categories.virtuemart_category_id = $result2->virtuemart_category_id
                AND #__virtuemart_products.published='1'
                
          
                ";
                $database->setQuery($sql);
                $result3 = $database->loadObjectList();
                // echo count($result3);
                for ($j = 0; $j < count($result3); $j++) {
                    $result4 = $result3[$j];
                    $url = "index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=" . $result4->virtuemart_product_id . "&virtuemart_category_id=" . $result4->virtuemart_category_id;
                    $swmenupro_array[] = array("TITLE" => $result4->product_name, "URL" => $url, "ID" => ($result4->virtuemart_product_id + 100000), "SECURE" => 0, "PARENT" => ($result2->virtuemart_category_id ? (($result2->virtuemart_category_id + 10000)) : 0), "ORDER" => $result2->ordering, "IMAGE" => $result4->image, "IMAGEOVER" => $result4->image_over, "SHOWNAME" => $result4->show_name, "IMAGEALIGN" => $result4->image_align, "TARGETLEVEL" => $result4->target_level, "TARGET" => 0, "ACCESS" => 1, "NCSS" => $result4->normal_css, "OCSS" => $result4->over_css, "SHOWITEM" => $result4->show_item, "HTML" => $result4->custom_html,"HTML_POSITION" =>$result4->html_position);
                }
            }
        }
    } else if ($menu == "mosetstree") {
        $sql = "SELECT #__mt_cats.* , #__swmenu_extended.*
                FROM #__mt_cats LEFT JOIN #__swmenu_extended ON #__mt_cats.cat_id = #__swmenu_extended.menu_id
                AND (#__swmenu_extended.moduleID = '" . $id . "' OR #__swmenu_extended.moduleID IS NULL)
                AND #__mt_cats.cat_approved = '1'
                AND #__mt_cats.cat_published = '1'
                AND #__mt_cats.cat_links > 0
                ORDER BY #__mt_cats.ordering
                ";
        $database->setQuery($sql);
        $result = $database->loadObjectList();

        for ($i = 0; $i < count($result); $i++) {
            $result2 = $result[$i];
            $url = "index.php?option=com_mtree&task=listcats&cat_id=" . $result2->cat_id . "&Itemid=" . ($result2->cat_id);
            $swmenupro_array[] = array("TITLE" => $result2->cat_name, "URL" => $url, "ID" => $result2->cat_id, "PARENT" => $result2->cat_parent, "SECURE" => 0, "ORDER" => $result2->ordering, "IMAGE" => $result2->image, "IMAGEOVER" => $result2->image_over, "SHOWNAME" => $result2->show_name, "IMAGEALIGN" => $result2->image_align, "TARGETLEVEL" => $result2->target_level, "TARGET" => 0, "ACCESS" => 0, "NCSS" => $result2->normal_css, "OCSS" => $result2->over_css, "SHOWITEM" => $result2->show_item, "HTML" => $result2->custom_html,"HTML_POSITION" =>$result2->html_position);
        }
    } else {
        if ($hybrid) {
            $sql = "SELECT #__content.*,#__swmenu_extended.* 
                FROM #__content LEFT JOIN #__swmenu_extended ON (#__content.id+100000) = #__swmenu_extended.menu_id
                AND (#__swmenu_extended.moduleID = '" . $id . "' OR #__swmenu_extended.moduleID IS NULL)
                INNER JOIN #__categories ON #__content.catid = #__categories.id
                AND #__content.state = 1
                AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now'  )
                AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )
              
                ORDER BY #__content.catid,#__content.ordering
                ";
            $database->setQuery($sql);
            $hybrid_content = $database->loadObjectList();
            //print_r($hybrid_content);


            $sql = "SELECT #__categories.id,#__categories.title,#__categories.parent_id,#__categories.lft,#__categories.published,#__categories.access,#__swmenu_extended.* 
                FROM #__categories LEFT JOIN #__swmenu_extended ON (#__categories.id+10000) = #__swmenu_extended.menu_id
                AND (#__swmenu_extended.moduleID = '" . $id . "'OR #__swmenu_extended.moduleID IS NULL)
                WHERE #__categories.published =1
                AND #__categories.extension='com_content'
               
                ORDER BY #__categories.lft
                ";
            $database->setQuery($sql);
            $hybrid_cat = $database->loadObjectList();
            //print_r($hybrid_cat);
            //print_r($hybrid_cat);
            //echo $hybrid_cat[1]->published;	
        }

        $sql = "SELECT #__menu.* , #__swmenu_extended.*
                FROM #__menu LEFT JOIN #__swmenu_extended ON #__menu.id = #__swmenu_extended.menu_id
                AND (#__swmenu_extended.moduleID = '" . $id . "' OR #__swmenu_extended.moduleID IS NULL)
                WHERE #__menu.menutype = '" . $menu . "' AND published = '1'
           
                ORDER BY parent_id
            ";

        $database->setQuery($sql);
        $result = $database->loadObjectList();
//jimport( 'joomla.html.application' );
        $swmenupro_array = array();
        //echo $preview;
        $preview = JRequest::getVar('preview', 0);
        //echo $preview;
        if (!$preview) {
            $menu_items = @ JSite::getMenu();
        }
//print_r ($menu_items);
          $language=$config->get('language');
        for ($i = 0; $i < count($result); $i++) {
            $result2 = $result[$i];


//$item       =  $menu_items->getActive();
            if (!$preview) {
                $params =  $menu_items->getParams($result2->id);
                $iSecure = $params->get('secure', 0);
            } else {
                $iSecure = 0;
            }


            switch ($result2->type) {
               case 'separator':
	       case 'heading':
                    $mylink = "javascript:void(0);";
                    break;

                case 'url':
                    $mylink = $result2->link;
                    if (preg_match("/index.php\?/i", $result2->link)) {
                        if (!preg_match("/Itemid=/i", $result2->link)) {
                            $mylink .= "&Itemid=$result2->id";
                        }
                    }
                    break;

                case 'menulink':
                    $mylink = $result2->link;
                    break;

                case 'alias':
                    if (!$preview) {
                        $alias = $params->get('aliasoptions', $result2->id);
                    } else {
                        $alias = "";
                    }
                    //$mylink = $result2->link;
                    //echo $test;
                    $mylink = "index.php?Itemid=" . $alias;
                    break;

                default:
                    $mylink = "index.php?Itemid=" . $result2->id;
                    break;
            }
             if($result2->language==$language || $result2->language=="*"){
            //echo "parent ".$result2->parent_id." order ".$result2->lft;
            $swmenupro_array[] = array("TITLE" => $result2->title, "URL" => $mylink, "ID" => $result2->id, "SECURE" => $iSecure, "PARENT" => $result2->parent_id, "ORDER" => $result2->lft, "IMAGE" => $result2->image, "IMAGEOVER" => $result2->image_over, "SHOWNAME" => $result2->show_name, "IMAGEALIGN" => $result2->image_align, "TARGETLEVEL" => $result2->target_level, "TARGET" => $result2->browserNav, "ACCESS" => $result2->access, "NCSS" => $result2->normal_css, "OCSS" => $result2->over_css, "SHOWITEM" => $result2->show_item, "HTML" => $result2->custom_html,"HTML_POSITION" =>$result2->html_position);
}
            if ($hybrid) {
                $opt = array();
                parse_str($result2->link, $opt);
                $opt['view'] = @$opt['view'] ? $opt['view'] : 0;
                $opt['id'] = @$opt['id'] ? $opt['id'] : 0;

                //echo $opt['id'];

                if ($opt['view'] == "category" || $opt['view'] == "categories") {
                    //echo "hello";

                    for ($j = 0; $j < count($hybrid_content); $j++) {
                        $row = $hybrid_content[$j];
                        //echo $row->catid;
                        if ($row->catid == $opt['id']) {
                            //echo "hello";
                            $url = "index.php?option=com_content&view=article&catid=" . $row->catid . "&id=" . $row->id . "&Itemid=" . $result2->id;
                            $swmenupro_array[] = array("TITLE" => $row->title, "URL" => $url, "ID" => $row->id + 100000, "SECURE" => $iSecure, "PARENT" => $result2->id, "ORDER" => $row->ordering, "IMAGE" => $row->image, "IMAGEOVER" => $row->image_over, "SHOWNAME" => $row->show_name, "IMAGEALIGN" => $row->image_align, "TARGETLEVEL" => $row->target_level, "TARGET" => 0, "ACCESS" => $row->access, "NCSS" => $row->normal_css, "OCSS" => $row->over_css, "SHOWITEM" => $row->show_item, "HTML" => $row->custom_html,"HTML_POSITION" =>$row->html_position);
                        }
                    }

                    for ($j = 0; $j < count($hybrid_cat); $j++) {
                        $row = $hybrid_cat[$j];
                        if ($row->parent_id == $opt['id'] && $opt['id']) {
                            //$j=count($hybrid_cat);

                            if (!$use_tables) {
                                $url = "index.php?option=com_content&view=category&id=" . $row->id . "&Itemid=" . $result2->id;
                            } else {
                                $url = "index.php?option=com_content&view=category&layout=blog&id=" . $row->id . "&Itemid=" . $result2->id;
                            }
                            $swmenupro_array[] = array("TITLE" => $row->title, "URL" => $url, "ID" => $row->id + 10000, "SECURE" => $iSecure, "PARENT" => $result2->id, "ORDER" => $row->lft, "IMAGE" => $row->image, "IMAGEOVER" => $row->image_over, "SHOWNAME" => $row->show_name, "IMAGEALIGN" => $row->image_align, "TARGETLEVEL" => $row->target_level, "TARGET" => 0, "ACCESS" => $row->access, "NCSS" => $row->normal_css, "OCSS" => $row->over_css, "SHOWITEM" => $row->show_item, "HTML" => $row->custom_html,"HTML_POSITION" =>$row->html_position);

                            for ($n = 0; $n < count($hybrid_cat); $n++) {
                                $row3 = $hybrid_cat[$n];
                                if ($row3->parent_id == $row->id) {
                                    //echo "hello";	
                                    if (!$use_tables) {
                                        $url = "index.php?option=com_content&view=category&id=" . $row3->id . "&Itemid=" . $result2->id;
                                    } else {
                                        $url = "index.php?option=com_content&view=category&layout=blog&id=" . $row3->id . "&Itemid=" . $result2->id;
                                    }
                                    $swmenupro_array[] = array("TITLE" => $row3->title, "URL" => $url, "ID" => $row3->id + 10000, "SECURE" => $iSecure, "PARENT" => $row->id + 10000, "ORDER" => $row->lft, "IMAGE" => $row->image, "IMAGEOVER" => $row->image_over, "SHOWNAME" => $row->show_name, "IMAGEALIGN" => $row->image_align, "TARGETLEVEL" => $row->target_level, "TARGET" => 0, "ACCESS" => $row->access, "NCSS" => $row->normal_css, "OCSS" => $row->over_css, "SHOWITEM" => $row->show_item, "HTML" => $row->custom_html,"HTML_POSITION" =>$row->html_position);
                                    for ($k = 0; $k < count($hybrid_content); $k++) {
                                        $row2 = $hybrid_content[$k];
                                        if ($row2->catid == $row3->id) {

                                            $url = "index.php?option=com_content&view=article&catid=" . $row->id . "&id=" . $row2->id . "&Itemid=" . $result2->id;
                                            $swmenupro_array[] = array("TITLE" => $row2->title, "URL" => $url, "ID" => $row2->id + 100000, "SECURE" => $iSecure, "PARENT" => $row3->id + 10000, "ORDER" => $row2->ordering, "IMAGE" => $row2->image, "IMAGEOVER" => $row2->image_over, "SHOWNAME" => $row2->show_name, "IMAGEALIGN" => $row2->image_align, "TARGETLEVEL" => $row2->target_level, "TARGET" => 0, "ACCESS" => $row2->access, "NCSS" => $row2->normal_css, "OCSS" => $row2->over_css, "SHOWITEM" => $row2->show_item, "HTML" => $row2->custom_html,"HTML_POSITION" =>$row2->html_position);
                                        }
                                    }
                                    for ($m = 0; $m < count($hybrid_cat); $m++) {
                                        $row4 = $hybrid_cat[$m];
                                        if ($row4->parent_id == $row3->id) {
                                            //echo "hello";	
                                            if (!$use_tables) {
                                                $url = "index.php?option=com_content&view=category&id=" . $row4->id . "&Itemid=" . $result2->id;
                                            } else {
                                                $url = "index.php?option=com_content&view=category&layout=blog&id=" . $row4->id . "&Itemid=" . $result2->id;
                                            }
                                            $swmenupro_array[] = array("TITLE" => $row4->title, "URL" => $url, "ID" => $row4->id + 10000, "SECURE" => $iSecure, "PARENT" => $row3->id + 10000, "ORDER" => $row->lft, "IMAGE" => $row->image, "IMAGEOVER" => $row->image_over, "SHOWNAME" => $row->show_name, "IMAGEALIGN" => $row->image_align, "TARGETLEVEL" => $row->target_level, "TARGET" => 0, "ACCESS" => $row->access, "NCSS" => $row->normal_css, "OCSS" => $row->over_css, "SHOWITEM" => $row->show_item, "HTML" => $row->custom_html,"HTML_POSITION" =>$row->html_position);

                                            for ($k = 0; $k < count($hybrid_content); $k++) {
                                                $row2 = $hybrid_content[$k];
                                                if ($row2->catid == $row4->id) {

                                                    $url = "index.php?option=com_content&view=article&catid=" . $row->id . "&id=" . $row2->id . "&Itemid=" . $result2->id;
                                                    $swmenupro_array[] = array("TITLE" => $row2->title, "URL" => $url, "ID" => $row2->id + 100000, "SECURE" => $iSecure, "PARENT" => $row4->id + 10000, "ORDER" => $row2->ordering, "IMAGE" => $row2->image, "IMAGEOVER" => $row2->image_over, "SHOWNAME" => $row2->show_name, "IMAGEALIGN" => $row2->image_align, "TARGETLEVEL" => $row2->target_level, "TARGET" => 0, "ACCESS" => $row2->access, "NCSS" => $row2->normal_css, "OCSS" => $row2->over_css, "SHOWITEM" => $row2->show_item, "HTML" => $row2->custom_html,"HTML_POSITION" =>$row2->html_position);
                                                }
                                            }
                                        }
                                    }
                                }
                            }




                            for ($k = 0; $k < count($hybrid_content); $k++) {
                                $row2 = $hybrid_content[$k];
                                if ($row2->catid == $row->id) {

                                    $url = "index.php?option=com_content&view=article&catid=" . $row->id . "&id=" . $row2->id . "&Itemid=" . $result2->id;
                                    $swmenupro_array[] = array("TITLE" => $row2->title, "URL" => $url, "ID" => $row2->id + 100000, "SECURE" => $iSecure, "PARENT" => $row->id + 10000, "ORDER" => $row2->ordering, "IMAGE" => $row2->image, "IMAGEOVER" => $row2->image_over, "SHOWNAME" => $row2->show_name, "IMAGEALIGN" => $row2->image_align, "TARGETLEVEL" => $row2->target_level, "TARGET" => 0, "ACCESS" => $row2->access, "NCSS" => $row2->normal_css, "OCSS" => $row2->over_css, "SHOWITEM" => $row2->show_item, "HTML" => $row2->custom_html,"HTML_POSITION" =>$row2->html_position);
                                }
                            }
                        }
                    }

                }
            }
        }
    }

    return $swmenupro_array;
}



function chain($primary_field, $parent_field, $sort_field, $rows, $root_id = 0, $maxlevel = 25) {
    $c = new chain($primary_field, $parent_field, $sort_field, $rows, $root_id, $maxlevel);
    return $c->chainmenu_table;
}

class chain {

    var $table;
    var $rows;
    var $chainmenu_table;
    var $primary_field;
    var $parent_field;
    var $sort_field;

    function chain($primary_field, $parent_field, $sort_field, $rows, $root_id, $maxlevel) {
        $this->rows = $rows;
        $this->primary_field = $primary_field;
        $this->parent_field = $parent_field;
        $this->sort_field = $sort_field;
        $this->buildchain($root_id, $maxlevel);
    }

    function buildChain($rootcatid, $maxlevel) {
        foreach ($this->rows as $row) {
            $this->table[$row[$this->parent_field]][$row[$this->primary_field]] = $row;
        }
        $this->makeBranch($rootcatid, 0, $maxlevel);
    }

    function makeBranch($parent_id, $level, $maxlevel) {
        @$rows = $this->table[$parent_id];
        if(count($rows)){
        $key_array1 = array_keys($rows);
        $key_array_size1 = sizeOf($key_array1);
        foreach ($rows as $key => $value) {
            $rows[$key]['key'] = $this->sort_field;
        }
        usort($rows, 'chainmenuCMP');
        $row_array = array_values($rows);
        $row_array_size = sizeOf($row_array);
        $i = 0;
        foreach ($rows as $item) {
            $item['ORDER'] = ($i + 1);
            $item['indent'] = $level;
            $i++;
            $this->chainmenu_table[] = $item;
            if ((isset($this->table[$item[$this->primary_field]])) && (($maxlevel > $level + 1) || ($maxlevel == 0))) {
                $this->makeBranch($item[$this->primary_field], $level + 1, $maxlevel);
            }
        }
    }
}
}

function chainmenuCMP($a, $b) {
    if ($a[$a['key']] == $b[$b['key']]) {
        return 0;
    }
    return ($a[$a['key']] < $b[$b['key']]) ? -1 : 1;
}

function findPar($ordered, $sub) {
    $submenu = chain('ID', 'PARENT', 'ORDER', $ordered, $sub['PARENT'], 1);
    if ($sub['indent'] == 1) {
        return $submenu[0]['PARENT'];
    } else {
        return $submenu[0]['ID'];
    }
}

function findParOrder($ordered, $sub) {
    $submenu = chain('ID', 'PARENT', 'ORDER', $ordered, $sub['PARENT'], 1);
    if ($sub['indent'] == 1) {
        return $submenu[0]['ORDER'];
    } else {
        return $submenu[0]['ORDER'];
    }
}

function findPar2($ordered, $sub) {
    $submenu = chain('ID', 'PARENT', 'ORDER', $ordered, $sub['PARENT'], 1);
    if ($sub['indent'] == 2) {
        return $submenu[0]['PARENT'];
    } else {
        return $submenu[0]['ID'];
    }
}

function swHassub($ordered, $top) {
    @$submenu = chain('ID', 'PARENT', 'ORDER', $ordered, $top['ID'], 1);
    if (count($submenu) > 0) {
        return true;
    } else {
        return false;
    }
}





function islast($array, $id) {
    $this_level = $array[$id]['indent'];
    $last = 0;
    $i = $id + 1;
    $do = 1;
    while ($do) {
        if (@$array[$i]['indent'] < $this_level || $i == count($array)) {
            $last = 1;
        }
        if (@$array[$i]['indent'] <= $this_level) {
            $do = 0;
        }
        $i++;
    }
    return $last;
}




function swmenu_getname($ordered) {
    global $mainframe, $Itemid;
    $admin=0;
     $database = JFactory::getDBO();
    $absolute_path = JPATH_ROOT;
    $live_site = JURI::base();
    if (substr($live_site, (strlen($live_site) - 1), 1) == "/") {
       
        $live_site = substr($live_site, 0, (strlen($live_site) - 1));
    }
    if (substr($live_site, (strlen($live_site) - 13), 13) == "administrator") {
         $admin=1;
        $live_site = substr($live_site, 0, (strlen($live_site) - 14));
    }
    $image_url = "";
    $name = "";
    $image1 = explode(",", $ordered['IMAGE']);
    $image2 = explode(",", $ordered['IMAGEOVER']);

    if (substr($live_site, (strlen($live_site) - 1), 1) == "/") {
        $live_site = substr($live_site, 0, (strlen($live_site) - 1));
    }
    //if(substr($live_site,(strlen($live_site)-13),13)=="administrator"){$live_site=substr($live_site,0,(strlen($live_site)-14));}
    if (substr($image1[0], 0, 1) == "/") {
        $image1[0] = substr($image1[0], 1, (strlen($image1[0]) - 1));
    }
    if (substr($image2[0], 0, 1) == "/") {
        $image2[0] = substr($image2[0], 1, (strlen($image2[0]) - 1));
    }

    $image1params = @$image1[0] ? " src=\"" . $live_site . "/" . $image1[0] . "\"" : "";
    $image1params .= @$image1[3] ? " vspace=\"" . $image1[3] . "\"" : " vspace=\"0\"";
    $image1params .= @$image1[4] ? " hspace=\"" . $image1[4] . "\"" : " hspace=\"0\"";
    $image2params = @$image2[0] ? " src=\"" . $live_site . "/" . $image2[0] . "\"" : "";
    $image2params .= @$image2[3] ? " vspace=\"" . $image2[3] . "\"" : " vspace=\"0\"";
    $image2params .= @$image2[4] ? " hspace=\"" . $image2[4] . "\"" : " hspace=\"0\"";
    $image1params .= @$image1[1] ? " width=\"" . $image1[1] . "\"" : "";
    $image1params .= @$image1[2] ? " height=\"" . $image1[2] . "\"" : "";
    $image2params .= @$image2[1] ? " width=\"" . $image2[1] . "\"" : "";
    $image2params .= @$image2[2] ? " height=\"" . $image2[2] . "\"" : "";
    $image1params .= $ordered['IMAGEALIGN'] ? " align=\"" . $ordered['IMAGEALIGN'] . "\"" : "";
    $image2params .= $ordered['IMAGEALIGN'] ? " align=\"" . $ordered['IMAGEALIGN'] . "\"" : "";
    if (($ordered['IMAGE'] != "") && (file_exists($absolute_path . "/" . $image1[0]))) {
        $image_url = "<img class=\"seq1\" border=\"0\" " . $image1params . " alt=\"" . $ordered['TITLE'] . "\" />";
    }
    if (($ordered['IMAGEOVER'] != "") && (file_exists($absolute_path . "/" . $image2[0]))) {
        $image_url .= "<img class=\"seq2\" border=\"0\" " . $image2params . " alt=\"" . $ordered['TITLE'] . "\" />";
    }
    if ($ordered['SHOWNAME'] || $ordered['SHOWNAME'] == null) {
        $name = $image_url . $ordered['TITLE'];
    } else {
        $name = $image_url;
    }
    
  //  jimport( 'joomla.application.module.helper' );
     if($ordered["HTML"]){
     //  $name.="hello";
       if ($admin==0){  
        $document	= JFactory::getDocument();
	              
               $style="xhtml";
		$renderer	= $document->loadRenderer('module');
	    $params		= array('style'=>$style);

	$contents = '';
	//$position='right';
	$regex = '/{swmenuload\s*.*?}/i';

 	$contents = $ordered['HTML'];
 	//echo $contents;	
        
 	preg_match_all( $regex, $contents, $matches );

	// Number of plugins
 	$count = count( $matches[0] );
//echo $count;
       
 	for ( $i=0; $i < $count; $i++ )
	{
 		$load = str_replace( 'swmenuload', '', $matches[0][$i] );
 		$load = str_replace( '{', '', $load );
 		$load = str_replace( '}', '', $load );
 		$load = trim( $load );
 	$database->setQuery( "SELECT id"
	. "\nFROM #__modules"
	//. "\nLEFT JOIN #__users AS u ON u.id = m.checked_out"
	. "\nWHERE (title='$load') "
	);
		
	$id = $database->loadResult();

	$module 	= JTable::getInstance('module' );
	    // load the row from the db table
	    $module->load( $id );

		$content = JModuleHelper::renderModule($module, $params);
		$contents 	= str_replace($matches[0][$i], $content, $contents );
               
        }
        
        }else{
          $contents = $ordered['HTML'];  
        //  echo $contents;
        }
       
       if($ordered['HTML_POSITION']=='after'){
           //  print_r($module);
            $name.=$contents;  
    //  $name.=$ordered['HTML'];     
       }else if($ordered['HTML_POSITION']=='before'){
    $name=$contents.$name;
   }else if($ordered['HTML_POSITION']=='tooltip'){
    $name="<span id='tooltipspan-".$ordered['ID']."' style='display:block;' >".$name."</span>";
   }else{
        $name.=$contents;
   }
   }
    return $name;
}



function swmenu_gettooltip($ordered)
{
  
  
    $admin=0;
     $database = JFactory::getDBO();
  
    $live_site = JURI::base();
    if (substr($live_site, (strlen($live_site) - 1), 1) == "/") {
       
        $live_site = substr($live_site, 0, (strlen($live_site) - 1));
    }
    if (substr($live_site, (strlen($live_site) - 13), 13) == "administrator") {
         $admin=1;
        $live_site = substr($live_site, 0, (strlen($live_site) - 14));
    }
       $divs="";
       $scripts="";
       if (!defined( '_swtooltip_defined')){
           
       }
      // $contents = $ordered[$j]['HTML'];
   //  if ($admin==0){ 
  
   $counter = count( $ordered );
//echo $count;
 	for ( $j=0; $j < $counter; $j++ )  {   

	$contents = '';
	//$position='right';
	

 	$contents = $ordered[$j]['HTML'];
 	//echo $contents;	
        if($admin==0){
          $document	= JFactory::getDocument();
	   $style="xhtml";
		$renderer	= $document->loadRenderer('module');
	    $params		= array('style'=>$style);
            $regex = '/{swmenuload\s*.*?}/i';
 	preg_match_all( $regex, $contents, $matches );

	// Number of plugins
 	$count = count( $matches[0] );
//echo $count;
 	for ( $i=0; $i < $count; $i++ )
	{
 		$load = str_replace( 'swmenuload', '', $matches[0][$i] );
 		$load = str_replace( '{', '', $load );
 		$load = str_replace( '}', '', $load );
 		$load = trim( $load );
 	$database->setQuery( "SELECT id"
	. "\nFROM #__modules"
	//. "\nLEFT JOIN #__users AS u ON u.id = m.checked_out"
	. "\nWHERE (title='$load') "
	);
		
	$id = $database->loadResult();

	$module 	= JTable::getInstance('module' );
	    // load the row from the db table
	    $module->load( $id );

		$content = JModuleHelper::renderModule($module, $params);
		$contents 	= str_replace($matches[0][$i], $content, $contents );
               
        }}  
        
   if($ordered[$j]['HTML_POSITION']=='tooltip'){
       $headtag="";
        if (!defined( '_swtooltip_defined')){
                 define( '_swtooltip_defined', 1 );
              
        }
    $divs.="<div id='tooltip-".$ordered[$j]['ID']."' style='display:none;'>".$contents."</div>";
    $scripts.=" jQuery(document).ready(function(){\n";
    $scripts.="jQuery(\"#tooltipspan-".$ordered[$j]['ID']."\").tooltip({\n";
     $scripts.="bodyHandler: function() {\n";
      $scripts.="return jQuery(\"#tooltip-".$ordered[$j]['ID']."\").html();";
     //$scripts.="return 'test';";
     $scripts.="},\nshowURL:false,\n";
      $scripts.="fade:100,\n";
      $scripts.="track:true,\n";
       $scripts.="opacity:1\n});\n";
       $scripts.="});\n";
   
    
   }
        }
  // }
    
   $name=$divs."\n<script type='text/javascript' >\n".$scripts."\n</script>\n";
    
    return $name;
}

function sw_getactive($ordered,$menustyle) {
    $menu_items = @ JSite::getMenu();
    $active = $menu_items->getActive();
    $current_itemid = @$active->id;

    $current_id = (JRequest::getVar('id', 0));
    $current_task = trim(JRequest::getVar('task', 0));
    $swid = trim(JRequest::getVar('swid', 0));
    $cur_option = trim(JRequest::getVar('option', ''));

    if (($cur_option == "com_virtuemart")) {

        $prod_id = trim(is_array(JRequest::getVar('virtuemart_product_id',0))?0:(JRequest::getVar('virtuemart_product_id', 0)));

        $cat_id = trim(JRequest::getVar('virtuemart_category_id', 0));
        if ($prod_id) {
            $current_itemid = $prod_id + 100000;
        } else {
            $current_itemid = $cat_id + 10000;
        }
    }
    if (!$current_itemid && $current_id) {
        if (preg_match("/category/i", $current_task)) {
            $current_itemid = $current_id + 1000;
        } elseif (preg_match("/section/i", $current_task)) {
            $current_itemid = $current_id;
        } elseif (preg_match("/view/i", $current_task)) {
            $current_itemid = $current_id + 10000;
        }
    }
    $indent = 0;
    $parent_value = $current_itemid;
    $parent = 1;
    $id = 0;
    
    if($menustyle=="treeview" || $menustyle=="treemenu"){
      $id=$current_itemid;  
       for ($i = 0; $i < count($ordered); $i++) {
            $row = $ordered[$i];
            $params =  $menu_items->getParams($row['ID']);
            $alias = $params->get('aliasoptions', $row['ID']);
            if ($row['ID'] == $parent_value || $alias == $parent_value) {
                $parent_value = $row['PARENT'];
                $indent = $row['indent'];
                $id = $row['ID'];
            }
        }
    }else{
    
    while ($parent) {
        for ($i = 0; $i < count($ordered); $i++) {
            $row = $ordered[$i];
            $params =  $menu_items->getParams($row['ID']);
            $alias = $params->get('aliasoptions', $row['ID']);
            if ($row['ID'] == $parent_value || $alias == $parent_value) {
                $parent_value = $row['PARENT'];
                $indent = $row['indent'];
                $id = $row['ID'];
            }
        }
        if (!$indent) {
            $parent = 0;
        }
    }
    }
    return ($id);
}



function sw_getsubactive($ordered) {
    $menu_items = @ JSite::getMenu();
    $active = $menu_items->getActive();
    $current_itemid = @$active->id;

   
  
      $id=$current_itemid;  
      
      
      foreach ($ordered as $row) {
            //echo $row['ID']."<br />";
            $params =  $menu_items->getParams($row['ID']);
            $alias = $params->get('aliasoptions', $row['ID']);
            if (($alias == $current_itemid)) {
                $id = $row['ID'];
            }
        }
      
      
   
    return ($id);
}


function sw_getsubmenu($ordered, $parent_level, $levels, $menu) {
    global $Itemid;
    $option2 = trim(JRequest::getVar('option', 0));
    $id = (JRequest::getVar('id', 0));
    $current_itemid = trim(JRequest::getVar('Itemid', 0));
    $menu_items = @ JSite::getMenu();
    $i = 0;
    $indent = 0;
    $menudisplay = 0;
    $parent = 1;
    if (($menu == "swcontentmenu") && ($option2 == "com_content") && $id) {
        $parent_value = $id;
    } elseif ($menu == "swcontentmenu") {
        $parent = 0;
    } else {
        $parent_value = $current_itemid;
        $menudisplay = 0;
        $parent = 1;
    }
    $id = 0;
    //echo "parent ".$parent."<br />";
    while ($parent) {
        foreach ($ordered as $row) {
            //echo $row['ID']."<br />";
            $params =  $menu_items->getParams($row['ID']);
            $alias = $params->get('aliasoptions', $row['ID']);
            if (($row['ID'] == $parent_value || $row['ID'] == $parent_value + 1000 || $row['ID'] == $parent_value + 10000 || $alias == $parent_value)) {

                $parent_value = $row['PARENT'];
                $indent = $row['indent'];
                $id = $row['ID'];
            }
        }
        if ($indent == $parent_level) {
            $parent = 0;
            $id = $parent_value;
        } elseif ($indent == $parent_level - 1) {
            $parent = 0;
            //$id=$parent_value;
        } elseif ($indent < $parent_level - 1) {
            $parent = 0;


            if ($parent_level == 2) {
                $id = $id;
            } else {
                $id = 0;
            }
        }

        $i++;
        if ($i > $levels) {
            $parent = 0;
        }
    }
    for ($i = 0; $i < count($ordered); $i++) {
        $row = $ordered[$i];
        //echo "id ".$id." PID ".$row['PARENT']."<br />";
        if (($row['PARENT'] == $id && $row['indent'] == $parent_level)) {
            $menudisplay = 1;
        }
        if (($row['PARENT'] == $id - 1000)) {
            $menudisplay = 1;
        }
        if (($row['indent'] == 0)) {
            $ordered[$i]['PARENT'] = 0;
        }
    }
    //echo "display ".$id;

    if ($menudisplay) {
        $ordered = chain('ID', 'PARENT', 'ORDER', $ordered, $id, $levels);
        $ordered[0]['mid'] = $id;
    } else {
        $ordered = array();
    }

    return $ordered;
}


function sw_stringToObject3($data)
{
   $obj= new stdClass();
   $lines = explode("\n", $data);

		// Process the lines.
		foreach ($lines as $line)
		{
			// Trim any unnecessary whitespace.
			$line = trim($line);

			// Ignore empty lines and comments.
			if (empty($line) || ($line{0} == ';'))
			{
				continue;
			}

			// Check that an equal sign exists and is not the first character of the line.
			if (!strpos($line, '='))
			{
				// Maybe throw exception?
				continue;
			}

			// Get the key and value for the line.
			list ($key, $value) = explode('=', $line, 2);

			// Validate the key.
			if (preg_match('/[^A-Z0-9_]/i', $key))
			{
				// Maybe throw exception?
				continue;
			}

			// If the value is quoted then we assume it is a string.
			$length = strlen($value);
			if ($length && ($value[0] == '"') && ($value[$length - 1] == '"'))
			{
				// Strip the quotes and Convert the new line characters.
				$value = stripcslashes(substr($value, 1, ($length - 2)));
				$value = str_replace('\n', "\n", $value);
			}
			else
			{
				// If the value is not quoted, we assume it is not a string.

				// If the value is 'false' assume boolean false.
				if ($value == 'false')
				{
					$value = false;
				}
				// If the value is 'true' assume boolean true.
				elseif ($value == 'true')
				{
					$value = true;
				}
				// If the value is numeric than it is either a float or int.
				elseif (is_numeric($value))
				{
					// If there is a period then we assume a float.
					if (strpos($value, '.') !== false)
					{
						$value = (float) $value;
					}
					else
					{
						$value = (int) $value;
					}
				}
			}

			
				$obj->$key = $value;
			
		}

		// Cache the string to save cpu cycles -- thus the world :)
		

		return $obj;
}

?>