Current file: /home/greg/workspace/PHPDS-dev-trunk/PHPDevShell/stable/trunk/includes/legacy/navigation.class.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 10 CRAP
1.09%1.09%
1.09% 1 / 92
 
navigation
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 2
5.00%5.00%
5.00% 1 / 20
 determine_menu_name ($replacement_name = false, $menu_link, $menu_id = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 write_menu ()
0.00%0.00%
0.00% 0 / 1 90
0.00%0.00%
0.00% 0 / 17
Functions
  
   
0.00%0.00%
0.00% 0 / 8
100.00%100.00%
100.00% 0 / 0
 call_family ($menu_id = false)
0.00%0.00%
0.00% 0 / 1 42
0.00%0.00%
0.00% 0 / 10
 generate_history_tree ()
0.00%0.00%
0.00% 0 / 1 90
0.00%0.00%
0.00% 0 / 22
 callback_parent_item ($menu_id_)
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 9
 show_menu ($hide_type, $menu_id = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 create_menu_id ($path)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 load_page ($menu_id = false, $extend_url = '', $strip_trail = '')
0.00%0.00%
0.00% 0 / 1 90
0.00%0.00%
0.00% 0 / 19
 self_url ($extra_get_variables = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 generic_button ($name, $url = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1


       1                 : <?php                                                                                                                                                                    
       2                 : /**                                                                                                                                                                      
       3                 :  * PHPDevShell is a RAD Framework aimed at developing administrative applications.                                                                                       
       4                 :  *                                                                                                                                                                       
       5                 :  * @package PHPDevShell                                                                                                                                                  
       6                 :  * @link http://www.phpdevshell.org                                                                                                                                      
       7                 :  * @copyright Copyright (C) 2007 Jason Schoeman, All rights reserved.                                                                                                    
       8                 :  * @license GNU/LGPL, see readme/licensed_under_lgpl or http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html                                                           
       9                 :  * @author Jason Schoeman, Contact: titan [at] phpdevshell [dot] org.                                                                                                    
      10                 :  *                                                                                                                                                                       
      11                 :  * Copyright notice: See readme/notice                                                                                                                                   
      12                 :  * By using PHPDevShell you agree to notice and license, if you dont agree to this notice/license you are not allowed to use PHPDevShell.                                
      13                 :  */                                                                                                                                                                      
      14                 : /**                                                                                                                                                                      
      15                 :  * This class extracts and organizes the main menus from the database and displayes it to the user. Shows only where permissions apply.                                  
      16                 :  * This is the complete menu extraction class.                                                                                                                           
      17                 :  * @deprecated                                                                                                                                                           
      18                 :  * @author Jason Schoeman                                                                                                                                                
      19                 :  */                                                                                                                                                                      
      20                 : class navigation extends PHPDS_dependant                                                                                                                                 
      21               1 : {                                                                                                                                                                        
      22                 :     /**                                                                                                                                                                  
      23                 :      * Determines what the menu item should be named.                                                                                                                    
      24                 :      *                                                                                                                                                                   
      25                 :      * @param string $replacement_name                                                                                                                                   
      26                 :      * @param string $menu_link                                                                                                                                          
      27                 :      * @param int $menu_id                                                                                                                                               
      28                 :      * @return string                                                                                                                                                    
      29                 :      */                                                                                                                                                                  
      30                 :     public function determine_menu_name ($replacement_name = false, $menu_link, $menu_id = false)                                                                        
      31                 :     {                                                                                                                                                                    
      32               0 :         return $this->determineMenuName($replacement_name, $menu_link, $menu_id);                                                                                        
      33                 :     }                                                                                                                                                                    
      34                 :                                                                                                                                                                          
      35                 :     /**                                                                                                                                                                  
      36                 :      * Compiles menu items in order.                                                                                                                                     
      37                 :      *                                                                                                                                                                   
      38                 :      * @return string                                                                                                                                                    
      39                 :      * @author Jason Schoeman                                                                                                                                            
      40                 :      */                                                                                                                                                                  
      41                 :     public function write_menu ()                                                                                                                                        
      42                 :     {                                                                                                                                                                    
      43                 :         // Define.                                                                                                                                                       
      44               0 :         $menu = false;                                                                                                                                                   
      45                 :         // Make sure array is not empty, otherwise error will be produced.                                                                                               
      46               0 :         if (! empty($this->navigation)) {                                                                                                                                
      47                 :             // Get menu group to compare against.                                                                                                                        
      48               0 :             if (! empty($this->navigation[$this->configuration['m']]['is_parent'])) {                                                                                    
      49               0 :                 $menu_group = $this->configuration['m'];                                                                                                                 
      50               0 :             } else {                                                                                                                                                     
      51               0 :                 if (! empty($this->navigation[$this->configuration['m']]['parent_menu_id'])) {                                                                           
      52               0 :                     $menu_group = $this->navigation[$this->configuration['m']]['parent_menu_id'];                                                                        
      53               0 :                 } else {                                                                                                                                                 
      54               0 :                     $menu_group = 0;                                                                                                                                     
      55                 :                 }                                                                                                                                                        
      56                 :             }                                                                                                                                                            
      57                 :             // Start dynamic render engine.                                                                                                                              
      58               0 :             foreach ($this->navigation as $m) {                                                                                                                          
      59                 :                 // Check if active item is parent.                                                                                                                       
      60               0 :                 if ($this->show_menu($m['hide'], $m['menu_id']) && $this->navigation[$m['menu_id']]['parent_menu_id'] == $menu_group) {                                  
      61                 :                     // Swith menu types.                                                                                                                                 
      62               0 :                     if ($m['is_parent'] == 1) {                                                                                                                          
      63                 :                         // Root item with Children.                                                                                                                      
      64               0 :                         $menu .= "<li class=\"dir\">{$m['url']}<ul>{$this->call_family($m['menu_id'])}</ul></li>";                                                       
      65               0 :                     } else {                                                                                                                                             
      66                 :                         // Check if current looped url is active.                                                                                                        
      67               0 :                         ($m['menu_id'] == $this->configuration['m']) ? $url_active = 'active' : $url_active = 'inactive';                                                
      68                 :                         // Root item with no Children.                                                                                                                   
      69               0 :                         $menu .= "<li id=\"$url_active\">{$m['url']}</li>";                                                                                              
      70                 :                     }                                                                                                                                                    
      71               0 :                 }                                                                                                                                                        
      72               0 :             }                                                                                                                                                            
      73                 :             // If no menu item is present, at least call its parent!                                                                                                     
      74               0 :             if (empty($menu)) {                                                                                                                                          
      75               0 :                 $menu = "<li id=\"active\">{$this->navigation[$this->configuration['m']]['url']}</li>";                                                                  
      76               0 :             }                                                                                                                                                            
      77               0 :         }                                                                                                                                                                
      78                 :         // Return Menu.                                                                                                                                                  
      79               0 :         return $menu;                                                                                                                                                    
      80                 :     }                                                                                                                                                                    
      81                 :                                                                                                                                                                          
      82                 :     /**                                                                                                                                                                  
      83                 :      * Assists write_menu in calling menu children.                                                                                                                      
      84                 :      *                                                                                                                                                                   
      85                 :      * @param int $menu_id                                                                                                                                               
      86                 :      */                                                                                                                                                                  
      87                 :     public function call_family ($menu_id = false)                                                                                                                       
      88                 :     {                                                                                                                                                                    
      89                 :         // Define.                                                                                                                                                       
      90               0 :         $menu = false;                                                                                                                                                   
      91                 :         // Only loop when we have something.                                                                                                                             
      92               0 :         if (! empty($this->child[$menu_id])) {                                                                                                                           
      93                 :             // Loop menu items finding its children.                                                                                                                     
      94               0 :             foreach ($this->child[$menu_id] as $m) {                                                                                                                     
      95                 :                 // Should item be shown.                                                                                                                                 
      96               0 :                 if ($this->show_menu($this->navigation[$m]['hide'], $m)) {                                                                                               
      97                 :                     // Check if we have a parent, if we do, we need to call her children.                                                                                
      98               0 :                     if ($this->navigation[$m]['is_parent'] == 1) {                                                                                                       
      99                 :                         // Child item with Children.                                                                                                                     
     100               0 :                         $menu .= "<li class=\"dir\">{$this->navigation[$m]['url']}<ul>{$this->call_family($m)}</ul></li>";                                               
     101               0 :                     } else {                                                                                                                                             
     102                 :                         // Check if current looped url is active.                                                                                                        
     103               0 :                         ($m == $this->configuration['m']) ? $url_active = 'active' : $url_active = 'inactive';                                                           
     104                 :                         // Child item without Children.                                                                                                                  
     105               0 :                         $menu .= "<li id=\"$url_active\">{$this->navigation[$m]['url']}</li>";                                                                           
     106                 :                     }                                                                                                                                                    
     107               0 :                 }                                                                                                                                                        
     108               0 :             }                                                                                                                                                            
     109               0 :         }                                                                                                                                                                
     110               0 :         return $menu;                                                                                                                                                    
     111                 :     }                                                                                                                                                                    
     112                 :                                                                                                                                                                          
     113                 :     /**                                                                                                                                                                  
     114                 :      * This method compiles the history tree seen, this is the tree that the user sees expand when going deeper into menu levels.                                        
     115                 :      * On the default template this is the navigation link string top left above the menus.                                                                              
     116                 :      *                                                                                                                                                                   
     117                 :      * @return string                                                                                                                                                    
     118                 :      */                                                                                                                                                                  
     119                 :     public function generate_history_tree ()                                                                                                                             
     120                 :     {                                                                                                                                                                    
     121                 :         // Check if user has permission to view Jump Menu!                                                                                                               
     122               0 :         if (isset($this->navigation['940041356']['menu_id'])) {                                                                                                          
     123               0 :             $jump_menu = '<a href="' . $this->load_page(940041356) . '" id="jump_history_menu">' . $this->lang['940041356'] . '</a>';                                    
     124               0 :         } else {                                                                                                                                                         
     125               0 :             $jump_menu = false;                                                                                                                                          
     126                 :         }                                                                                                                                                                
     127                 :         // Front Page.                                                                                                                                                   
     128               0 :         $main_item = '<a href="' . $this->configuration['absolute_url'] . '" id="folder_root">' . ___('Front Page') . '</a>' . $jump_menu;                               
     129                 :         // Call breadcrumb method.                                                                                                                                       
     130               0 :         $this->callback_parent_item($this->configuration['m']);                                                                                                          
     131                 :         // Set.                                                                                                                                                          
     132               0 :         $history_url = false;                                                                                                                                            
     133               0 :         foreach (array_reverse($this->breadcrumbArray, true) as $key => $breadcrumb_id) {                                                                                
     134               0 :             if (! empty($this->navigation[$breadcrumb_id]['menu_name']) && (($breadcrumb_id != $this->configuration['m']) || ($key != 0))) {                             
     135               0 :                 $history_url .= '<a href="' . $this->load_page($breadcrumb_id) . '" id="folder_history_tree">' . $this->navigation[$breadcrumb_id]['menu_name'] . '</a>';
     136               0 :             }                                                                                                                                                            
     137               0 :         }                                                                                                                                                                
     138                 :         // Go up one level.                                                                                                                                              
     139               0 :         if (! empty($this->navigation[$this->configuration['m']]['parent_menu_id'])) {                                                                                   
     140               0 :             $up_parent_id = $this->navigation[$this->configuration['m']]['parent_menu_id'];                                                                              
     141               0 :         } else {                                                                                                                                                         
     142               0 :             $up_parent_id = 0;                                                                                                                                           
     143                 :         }                                                                                                                                                                
     144                 :         // Create Up link.                                                                                                                                               
     145               0 :         if (! empty($up_parent_id)) {                                                                                                                                    
     146                 :             // Create level up icon.                                                                                                                                     
     147               0 :             $up = '<a href="' . $this->load_page($up_parent_id) . '" id="up_history_tree">' . ___('Up') . '</a>';                                                        
     148               0 :         } else {                                                                                                                                                         
     149               0 :             $up = false;                                                                                                                                                 
     150                 :         }                                                                                                                                                                
     151                 :         // Do we have the history URL?                                                                                                                                   
     152               0 :         if (empty($history_url)) $history_url = false;                                                                                                                   
     153                 :         // Return items, in order.                                                                                                                                       
     154               0 :         return $main_item . $history_url . $up;                                                                                                                          
     155                 :     }                                                                                                                                                                    
     156                 :                                                                                                                                                                          
     157                 :     /**                                                                                                                                                                  
     158                 :      * Method assists method generate_history_tree in getting breadcrumb links.                                                                                          
     159                 :      *                                                                                                                                                                   
     160                 :      * @param integer                                                                                                                                                    
     161                 :      * @return array                                                                                                                                                     
     162                 :      */                                                                                                                                                                  
     163                 :     private function callback_parent_item ($menu_id_)                                                                                                                    
     164                 :     {                                                                                                                                                                    
     165                 :         // Check what called menu items parent id is.                                                                                                                    
     166               0 :         if (! empty($this->navigation[$menu_id_]['parent_menu_id'])) {                                                                                                   
     167               0 :             $recall_parent_menu_id = $this->navigation[$menu_id_]['parent_menu_id'];                                                                                     
     168               0 :         } else {                                                                                                                                                         
     169               0 :             $recall_parent_menu_id = 0;                                                                                                                                  
     170                 :         }                                                                                                                                                                
     171                 :         // Return results.                                                                                                                                               
     172               0 :         $this->breadcrumbArray[] = $menu_id_;                                                                                                                            
     173                 :         // Call function itself to see if this item has a parent item.                                                                                                   
     174               0 :         if ($recall_parent_menu_id != 0) {                                                                                                                               
     175               0 :             $this->callback_parent_item($recall_parent_menu_id);                                                                                                         
     176               0 :         }                                                                                                                                                                
     177               0 :     }                                                                                                                                                                    
     178                 :                                                                                                                                                                          
     179                 :     /**                                                                                                                                                                  
     180                 :      * Returns true if menu should show.                                                                                                                                 
     181                 :      *                                                                                                                                                                   
     182                 :      * @deprecated                                                                                                                                                       
     183                 :      * @param integer $hide_type                                                                                                                                         
     184                 :      * @param integer $menu_id                                                                                                                                           
     185                 :      */                                                                                                                                                                  
     186                 :     public function show_menu ($hide_type, $menu_id = false)                                                                                                             
     187                 :     {                                                                                                                                                                    
     188               0 :         return $this->showMenu($hide_type, $menu_id);                                                                                                                    
     189                 :     }                                                                                                                                                                    
     190                 :                                                                                                                                                                          
     191                 :     /**                                                                                                                                                                  
     192                 :      * Convert plugin file location to unsigned CRC32 value. This is unique and allows one to locate a menu item from location as well.                                  
     193                 :      *                                                                                                                                                                   
     194                 :      * @deprecated use createMenuId                                                                                                                                      
     195                 :      * @param string The plugin folder the file is in.                                                                                                                   
     196                 :      * @return integer                                                                                                                                                   
     197                 :      * @author Jason Schoeman                                                                                                                                            
     198                 :      */                                                                                                                                                                  
     199                 :     public function create_menu_id ($path)                                                                                                                               
     200                 :     {                                                                                                                                                                    
     201               0 :         return $this->createMenuId($path);                                                                                                                               
     202                 :     }                                                                                                                                                                    
     203                 :                                                                                                                                                                          
     204                 :     /**                                                                                                                                                                  
     205                 :      * Returns the correct string for use in href when creating a link for a menu id. Will return sef url if possible.                                                   
     206                 :      * Will return self url when no menu id is given. No starting & or ? is needed, this gets auto determined!                                                           
     207                 :      * If left empty it will return current active menu.                                                                                                                 
     208                 :      *                                                                                                                                                                   
     209                 :      * @deprecated                                                                                                                                                       
     210                 :      * @param integer The menu id to load.                                                                                                                               
     211                 :      * @param string extend_url                                                                                                                                          
     212                 :      * @param boolean strip_trail Will strip unwanted empty operators at the end.                                                                                        
     213                 :      * @return string                                                                                                                                                    
     214                 :      * @author Jason Schoeman                                                                                                                                            
     215                 :      */                                                                                                                                                                  
     216                 :     public function load_page ($menu_id = false, $extend_url = '', $strip_trail = '')                                                                                    
     217                 :     {                                                                                                                                                                    
     218                 :         // Should we assign menu id.                                                                                                                                     
     219               0 :         if (empty($menu_id)) $menu_id = $this->configuration['m'];                                                                                                       
     220                 :         // Can we use sef url?                                                                                                                                           
     221               0 :         if (! empty($this->configuration['sef_url']) && ! empty($this->navigation["$menu_id"]['alias'])) {                                                               
     222                 :             // Add extra string. Thought not 100% correct, this is for backwards compatibility.                                                                          
     223               0 :             if (! empty($extend_url)) {                                                                                                                                  
     224               0 :                 $extend_url = "?$extend_url";                                                                                                                            
     225               0 :             } else if (! empty($strip_trail)) {                                                                                                                          
     226               0 :                 $extend_url = false;                                                                                                                                     
     227               0 :             } else {                                                                                                                                                     
     228               0 :                 $extend_url = '?';                                                                                                                                       
     229                 :             }                                                                                                                                                            
     230               0 :             $url_append = empty($this->configuration['url_append']) ? '' : $this->configuration['url_append'];                                                           
     231                 :             // Menu id is set for sef mode, so return correct integer id.                                                                                                
     232               0 :             $url = $this->navigation["$menu_id"]['alias'] . $url_append . "$extend_url";                                                                                 
     233               0 :         } else {                                                                                                                                                         
     234                 :             // Add extra string.                                                                                                                                         
     235               0 :             if (! empty($extend_url)) {                                                                                                                                  
     236               0 :                 $extend_url = "&$extend_url";                                                                                                                            
     237               0 :             } else {                                                                                                                                                     
     238               0 :                 $extend_url = false;                                                                                                                                     
     239                 :             }                                                                                                                                                            
     240                 :             // Menu id is an integer.                                                                                                                                    
     241               0 :             $url = 'index.php?m=' . "$menu_id" . "$extend_url";                                                                                                          
     242                 :         }                                                                                                                                                                
     243               0 :         if (! empty($url)) {                                                                                                                                             
     244               0 :             return $this->configuration['absolute_url'] . "/$url";                                                                                                       
     245                 :         } else {                                                                                                                                                         
     246               0 :             return false;                                                                                                                                                
     247                 :         }                                                                                                                                                                
     248                 :     }                                                                                                                                                                    
     249                 :                                                                                                                                                                          
     250                 :     /**                                                                                                                                                                  
     251                 :      * This method saves the current URL with the option to add more $this->security->get variables like ("&variable1=1&variable2=2")                                    
     252                 :      * This is mostly used for when additional $this->security->get variables are required! Usefull when using forms.                                                    
     253                 :      *                                                                                                                                                                   
     254                 :      * @param string Add more $this->security->get variables like ("&variable1=1&variable2=2")                                                                           
     255                 :      * @return string                                                                                                                                                    
     256                 :      * @deprecated This method is not needed anymore.                                                                                                                    
     257                 :      * @author Jason Schoeman                                                                                                                                            
     258                 :      */                                                                                                                                                                  
     259                 :     public function self_url ($extra_get_variables = false)                                                                                                              
     260                 :     {                                                                                                                                                                    
     261                 :         // Workaround.                                                                                                                                                   
     262               0 :         return $this->load_page(false, $extra_get_variables, true);                                                                                                      
     263                 :     }                                                                                                                                                                    
     264                 :                                                                                                                                                                          
     265                 :     /**                                                                                                                                                                  
     266                 :      * Creates a link that looks like all the other submit buttons.                                                                                                      
     267                 :      *                                                                                                                                                                   
     268                 :      * @deprecated                                                                                                                                                       
     269                 :      * @param string $url                                                                                                                                                
     270                 :      * @return string                                                                                                                                                    
     271                 :      */                                                                                                                                                                  
     272                 :     public function generic_button ($name, $url = false)                                                                                                                 
     273                 :     {                                                                                                                                                                    
     274               0 :         return '<input type="button" value="' . $name . '" name="generic" onClick="window.location=\'' . $url . '\' " class="button">';                                  
     275                 :     }                                                                                                                                                                    
     276                 : }                                                                                                                                                                        

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.6 and PHPUnit 3.5.14 at Mon Aug 8 22:35:38 PDT 2011.