Source for file ja_splitmenu.php

Documentation is available at ja_splitmenu.php

  1. <?php
  2.     
  3.     defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  4.     
  5.     $hilightid = -1;
  6.     $menuname "";
  7.     $color "default"// default color for orphan (no parent menu) links
  8.     $tab_index 0;
  9.     
  10.     define'JA_CURRENT_MENU'"active_menu");
  11.     
  12.     if (!defined('_JA_SUBMENU_')) {
  13.         define('_JA_SUBMENU_'1);
  14.         
  15.         function ja_topNav$menu$colors {
  16.             global $mosConfig_absolute_path$mosConfig_shownoauth$my$database$Itemid$hilightid;
  17.             
  18.             $r "";
  19.             
  20.             if ($mosConfig_shownoauth{
  21.                 $sql "SELECT * FROM #__menu"
  22.                 . "\nWHERE menutype='"$menu ."' AND published='1' AND parent=0"
  23.                 . "\nORDER BY ordering";
  24.             else {
  25.                 $sql "SELECT * FROM #__menu"
  26.                 . "\nWHERE menutype='"$menu ."' AND published='1' AND access <= '"$my->gid"' AND parent=0"
  27.                 . "\nORDER BY ordering";
  28.             }
  29.             
  30.             $database->setQuery$sql );
  31.             $topmenu $database->loadObjectList'id' );
  32.             
  33.             $sql "SELECT * FROM #__menu"
  34.             . "\nWHERE menutype='"$menu ."' AND published='1'"
  35.             $database->setQuery$sql );
  36.             $subrows $database->loadObjectList'id' );
  37.             $recurse 5;
  38.             $parentid $Itemid;
  39.             while ($recurse-- > 0{
  40.                 $parentid ja_getParentRow($subrows$parentid);
  41.                 if (isset($parentid&& $parentid >= && $subrows[$parentid]{
  42.                     $hilightid $parentid;
  43.                 else {
  44.                     break;    
  45.                 }
  46.             }
  47.             
  48.             $links array();
  49.             $i 0;
  50.             if (count$topmenu )) {
  51.             foreach ($topmenu as $menuitem{
  52.                 $hilight ($menuitem->id == $hilightid);
  53.                 $links[ja_getSubmenu$menuitem0$colors$hilighttrue );
  54.             }}
  55.             
  56.             $menuclass 'mainlevel';
  57.             if (count$links )) {
  58.                 $r .= '<ul id="ja-splitmenu" class="'$menuclass .'">';
  59.                 foreach ($links as $link{
  60.                     $r .= $link;
  61.                 }
  62.                 $r .= '</ul>';            
  63.             }
  64.             
  65.             return $r;
  66.         }
  67.         
  68.         function ja_getParentRow($rows$id{
  69.             if (isset($rows[$id]&& $rows[$id]{
  70.                 if($rows[$id]->parent 0{
  71.                     return $rows[$id]->parent;
  72.                 }    
  73.             }
  74.             return -1;
  75.         }
  76.         
  77.         function ja_getSubmenu$menuitem$depth$colors null$hilight false$color_index false{
  78.             global $mainframe$tab_index$color$hilightid$menuname;
  79.             $r "";
  80.             $id "";
  81.         
  82.             switch ($menuitem->type{
  83.                 case 'separator':
  84.                 case 'component_item_link':
  85.                     break;
  86.                     
  87.                 case 'url':
  88.                     if eregi'index.php\?'$menuitem->link ) ) {
  89.                         if !eregi'Itemid='$menuitem->link ) ) {
  90.                             $menuitem->link .= '&Itemid='$menuitem->id;
  91.                         }
  92.                     }
  93.                     break;
  94.                     
  95.                 case 'content_item_link':
  96.                 case 'content_typed':
  97.                     // load menu params
  98.                     $menuparams new mosParameters$menuitem->params$mainframe->getPath'menu_xml'$menuitem->type )'menu' );
  99.                     
  100.                     $unique_itemid $menuparams->get'unique_itemid');
  101.                     
  102.                     if $unique_itemid {
  103.                         $menuitem->link .= '&Itemid='$menuitem->id;
  104.                     else {
  105.                         $temp split('&task=view&id='$menuitem->link);
  106.                         
  107.                         if $menuitem->type == 'content_typed' {
  108.                             $menuitem->link .= '&Itemid='$mainframe->getItemid($temp[1]10);
  109.                         else {
  110.                             $menuitem->link .= '&Itemid='$mainframe->getItemid($temp[1]01);
  111.                         }
  112.                     }
  113.                     break;
  114.  
  115.                 default:
  116.                     $menuitem->link .= '&Itemid='$menuitem->id;
  117.                     break;
  118.             }
  119.             
  120.             if ($color_index{
  121.                 $id .= $colors[($tab_index)%count($colors)];
  122.                 $tab_index++;
  123.             }
  124.             
  125.             $current_itemid trimmosGetParam$_REQUEST'Itemid') );
  126.             if !$current_itemid && !$hilight {
  127.                 //$id = '';
  128.             else if ($hilight || ($current_itemid == $menuitem->id)) {
  129.                 if ($depth == 0{
  130.                     $color $id;
  131.                     $menuname $menuitem->name;
  132.                     $hilightid $menuitem->id;
  133.                 
  134.                 $id JA_CURRENT_MENU;
  135.             }
  136.  
  137.             if ($id == JA_CURRENT_MENU$id ' class="' $id '"';
  138.             else $id "";
  139.             $menuitem->link ampReplace$menuitem->link );
  140.             if strcasecmpsubstr$menuitem->link,0,)'http' ) ) {
  141.                 $menuitem->link sefRelToAbs$menuitem->link );
  142.             }
  143.                    
  144.             $title "title=\"{$menuitem->name}\"";
  145.             switch ($menuitem->browserNav{
  146.                 case 1:
  147.                     // open in a new window
  148.                     $r '<li'$id '><a href="'$menuitem->link .'" target="_blank" '.$title.'><span>'$menuitem->name ."</span></a></li>\n";
  149.                     break;
  150.                 case 2:
  151.                     // open in a popup window
  152.                     $r "<li"$id "><a href=\"#\" onclick=\"javascript: window.open('"$menuitem->link ."', '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550'); return false\" $title><span>"$menuitem->name ."</span></a></li>\n";
  153.                     break;
  154.                 case 3:
  155.                     // don't link it
  156.                     $r '<li'$id '><span class="seperator">'$menuitem->name ."</span></li>\n";
  157.                     break;
  158.                 default:
  159.                     // open in parent window
  160.                     $r '<li'$id '><a href="'$menuitem->link .'" '.$title.'><span>'$menuitem->name ."</span></a></li>\n";
  161.                     break;
  162.             }
  163.             
  164.             return $r;
  165.         }
  166.         
  167.         function ja_subNav($menutype$pre NULL$post NULL{
  168.             global $my$mosConfig_shownoauth$Itemid$database;
  169.         
  170.             $sub "";            
  171.             $user 0;
  172.             if ($my->gid{
  173.                 switch ($my->usertype{
  174.                     case "Super Administrator":
  175.                         $user 0;
  176.                         break;
  177.                     case "Administrator":
  178.                         $user 1;
  179.                         break;
  180.                     case "Editor":
  181.                         $user 2;
  182.                         break;
  183.                     case "Registered":
  184.                         $user 3;
  185.                         break;
  186.                     case "Author":
  187.                         $user 4;
  188.                         break;
  189.                     case "Publisher":
  190.                         $user 5;
  191.                         break;
  192.                     case "Manager":
  193.                         $user 6;
  194.                         break;
  195.                 }
  196.             }
  197.             
  198.             if ($mosConfig_shownoauth{
  199.                 $sql "SELECT * FROM #__menu"
  200.                 . "\nWHERE menutype='"$menutype ."' AND published='1'"
  201.                 . "\nAND parent > 0"
  202.                 . "\nORDER BY parent,ordering";
  203.             else {
  204.                 $sql "SELECT * FROM #__menu"
  205.                 . "\nWHERE menutype='"$menutype ."' AND published='1' AND access <= '$my->gid'"
  206.                 . "\nAND parent > 0"
  207.                 . "\nORDER BY parent,ordering";
  208.             }
  209.             
  210.             $database->setQuery$sql );
  211.             $rows $database->loadObjectList'id' );
  212.             
  213.             $subs array();
  214.             if ($rows){
  215.             foreach ($rows as $v {
  216.                 $pt $v->parent;
  217.                 $list @$subs[$pt$subs[$ptarray();
  218.                 array_push$list$v );
  219.                 $subs[$pt$list;
  220.             }
  221.             }
  222.             $open array$Itemid );
  223.             $count 20// maximum levels - to prevent runaway loop
  224.             $id $Itemid;
  225.             while (--$count{
  226.                 if (isset($rows[$id]&& $rows[$id]->parent 0{
  227.                     $id $rows[$id]->parent;
  228.                     $open[$id;
  229.                 else {
  230.                     break;
  231.                 }
  232.             }
  233.             
  234.             if (isset($subs[$id]&& $subs[$id]{
  235.                 $sub ja_findSubmenu$id1$subs$open);
  236.             }
  237.             
  238.             return $sub;
  239.         }
  240.         
  241.         function ja_findSubmenu$id$depth&$subs&$open{
  242.             global $Itemid$menuname;
  243.             
  244.             $r "";
  245.             $sub_class "submenu";
  246.             
  247.             if (@$subs[$id&& $depth<2{
  248.                 //$n = min( $depth, count( $indents )-1 );
  249.                 if ($depth == {
  250.                     $r .= "<ul class=\"" $sub_class "\">\n";
  251.                 else {
  252.                     $r .= "<ul>\n";
  253.                 }
  254.  
  255.                 
  256.                 foreach ($subs[$idas $row{
  257.                     $r .= ja_getSubmenu$row$depth );
  258.                     if in_array$row->id$open )) {
  259.                         $r .= ja_findSubmenu$row->id$depth+1$subs$open );
  260.                     }
  261.                 }
  262.                 $r .= "</ul>\n";
  263.  
  264.             }
  265.             return $r;
  266.         }
  267.     }    
  268. ?>

Documentation generated on Mon, 05 May 2008 16:20:47 +0400 by phpDocumentor 1.4.0