[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/system/classes/ -> navbar.class.php (source)

   1  <?php
   2  /* Reminder: always indent with 4 spaces (no tabs). */
   3  // +-------------------------------------------------------------------------+
   4  // | Geeklog 1.3                                                             |
   5  // +-------------------------------------------------------------------------+
   6  // | navbar.class.php                                                        |
   7  // |                                                                         |
   8  // | class to create and display a CSS based Navbar for site navigation      |
   9  // +-------------------------------------------------------------------------+
  10  // | Copyright (C) 2004 by Consult4Hire Inc.                                 |
  11  // |                                                                         |
  12  // | Author:                                                                 |
  13  // | Blaine Lang                 -    blaine@portalparts.com                 |
  14  // +-------------------------------------------------------------------------+
  15  // |                                                                         |
  16  // | This program is free software; you can redistribute it and/or           |
  17  // | modify it under the terms of the GNU General Public License             |
  18  // | as published by the Free Software Foundation; either version 2          |
  19  // | of the License, or (at your option) any later version.                  |
  20  // |                                                                         |
  21  // | This program is distributed in the hope that it will be useful,         |
  22  // | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
  23  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    |
  24  // | See the GNU General Public License for more details.                    |
  25  // |                                                                         |
  26  // | You should have received a copy of the GNU General Public License       |
  27  // | along with this program; if not, write to the Free Software Foundation, |
  28  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         |
  29  // |                                                                         |
  30  // +-------------------------------------------------------------------------+
  31  //
  32  
  33  /**
  34  * This class will allow you to setup and generate a CSS Tab Menu and breadcrumb link trail
  35  * Version 1.1 June 4, 2006
  36  *
  37  * @author       Blaine Lang <blaine@portalparts.com>
  38  *
  39  */
  40  
  41  /* Example Use 
  42      include ($_CONF['path_system'] . 'classes/navbar.class.php');
  43  
  44      $menuitems = array (
  45          'Site Links' => $_CONF['site_url'] .'/links.php',
  46          'My Calendar'=> $_CONF['site_url'] .'/calendar.php',
  47          'Polls'      => $_CONF['site_url'] .'/pollbooth.php'
  48      );
  49  
  50      $navbar = new navbar;
  51      $navbar->set_menuitems($menuitems);
  52  
  53      // Add a menuitem if user has access
  54      if (SEC_inGroup('Root')) {
  55          $navbar->add_menuitem('Admin Home',$_CONF['site_admin_url'] . '/moderation.php');
  56      }
  57  
  58      // Add a Menuitem which activates a Javascript function when the onClick event is triggered
  59      $navbar->add_menuitem('On click test','alert("This works");',true);
  60  
  61      // Add a new Menuitem which may or may not have a URL to redirect to but also triggers an onClick JS function
  62      $navbar->add_menuitem('Search Engine','http://www.google.com');
  63      // Pass in the label to attach the onClick function to
  64      $navbar->set_onclick('Search Engine','return confirm("Do you want to leave this site?");');
  65  
  66      // Set the current selected tab
  67      $navbar->set_selected('My Calendar');
  68      echo $navbar->generate();
  69  
  70      // Generate a breadcrumb trail
  71      $navbar->openBreadcrumbs();
  72      $navbar->add_breadcrumbs("{$_CONF['site_url']}/index.php",'home']);
  73  
  74     // Adds just a label, not a link as the last breadcrumb
  75      $navbar->add_lastBreadcrumb('myplugin');
  76  
  77      // Close and generate the breakcrumb trail
  78      echo $navbar->closeBreadcrumbs();
  79  
  80  */
  81  
  82  
  83  class navbar  {
  84  
  85      // Private Properties
  86      /**
  87      * @access private
  88      */
  89      var $_menuitems;      // Array
  90      /**
  91      * @access private
  92      */
  93      var $_selected = '';      // string
  94      /**
  95      * @access private
  96      */
  97      var $_parms = '';      // string
  98      /**
  99      * @access private
 100      */
 101      var $_onclick;      // Array
 102      
 103      var $_bctemplate = NULL;     // Template to use for Breadcrumbs
 104      
 105      var $_numbreadcrumbs = 0;   // Number of Breadcrumb links added
 106  
 107      /**
 108      * Constructor
 109      *
 110      */
 111      function navbar()
 112      {
 113      }
 114  
 115      function set_menuitems($menuitems)
 116      {
 117         $this->_menuitems = $menuitems;
 118      }
 119  
 120      function add_menuitem($label,$link,$onclick=false)
 121      {
 122          if ($onclick) {
 123              $this->_menuitems[$label] = '#';
 124              $this->set_onClick($label, $link);
 125          } else {
 126              $this->_menuitems[$label] = $link;
 127          }
 128      }
 129  
 130  
 131      function set_selected($selected)
 132      {
 133          $this->_selected = $selected;
 134      }
 135  
 136      function set_defaultparms($parms)
 137      {
 138          $this->_parms = $parms;
 139      }
 140  
 141      function set_onClick($item, $option)
 142      {
 143          $this->_onclick[$item] = $option;
 144      }
 145  
 146      function generate() {
 147          global $_CONF;
 148          $navtemplate = new Template($_CONF['path_layout'] . 'navbar');
 149          $navtemplate->set_file (array (
 150              'navbar'       => 'navbar.thtml',
 151              'menuitem'     => 'menuitem.thtml'));
 152  
 153          if ($this->_parms != '') {
 154              $navtemplate->set_var( 'parms',  $this->_parms);
 155          }
 156  
 157          for ($i=1; $i <= count($this->_menuitems); $i++)  {
 158              $label = key($this->_menuitems);
 159              $linkurl = current($this->_menuitems);
 160              if ( is_array($this->_onclick) AND array_key_exists($label,$this->_onclick) ) {
 161                  $onclick = " onClick='{$this->_onclick[$label]}'";
 162                  $navtemplate->set_var( 'onclick', $onclick);
 163                  $navtemplate->set_var( 'link', ($linkurl == '') ? '#' : $linkurl);
 164              } else {
 165                  $navtemplate->set_var( 'onclick', '');
 166                  $navtemplate->set_var( 'link', $linkurl);
 167              }
 168              if ($label == $this->_selected) {
 169                  $navtemplate->set_var( 'cssactive', ' id="active"');
 170                  $navtemplate->set_var( 'csscurrent',' id="current"');
 171              } else {
 172                  $navtemplate->set_var( 'cssactive', '');
 173                  $navtemplate->set_var( 'csscurrent','');
 174              }
 175              $navtemplate->set_var( 'label',  $label);
 176              $navtemplate->parse( 'menuitems', 'menuitem', true );
 177              next($this->_menuitems);
 178          }
 179          $navtemplate->parse ('output', 'navbar');
 180          $retval = $navtemplate->finish($navtemplate->get_var('output'));
 181          return $retval;
 182      }
 183      
 184      function openBreadcrumbs() {
 185          global $_CONF;
 186          $this->_bctemplate = new Template($_CONF['path_layout'] . 'navbar');
 187          $this->_bctemplate->set_file (array (
 188              'breadcrumbs'   => 'breadcrumbs.thtml',
 189              'link'          => 'breadcrumb_link.thtml'));
 190      }
 191      
 192      function add_breadcrumbs($url,$label,$title='') {
 193          if ($this->_numbreadcrumbs == '') {
 194              $this->_numbreadcrumbs = 0;
 195          }
 196          $this->_bctemplate->set_var('link_url',$url);
 197          $this->_bctemplate->set_var('link_label',$label);
 198          $this->_bctemplate->set_var('link_title',$title);
 199          if ($this->_numbreadcrumbs > 0) {
 200              $this->_bctemplate->set_var('link_separator','/&nbsp;');
 201       
 202          }  else {
 203              $this->_bctemplate->set_var('link_separator','');
 204          }            
 205          $this->_bctemplate->parse('breadcrumb_links','link',true);
 206          $this->_numbreadcrumbs = $this->_numbreadcrumbs + 1;
 207      }
 208      
 209      function add_lastBreadcrumb($label) {
 210          if (trim($label) != '') {
 211              $label = "/&nbsp;$label";
 212              $this->_bctemplate->set_var('last_label',$label);
 213          }           
 214      }      
 215  
 216      function closeBreadcrumbs() {
 217          $this->_bctemplate->parse('output', 'breadcrumbs');
 218          return $this->_bctemplate->finish ($this->_bctemplate->get_var('output'));         
 219      }    
 220      
 221  
 222  }
 223  
 224  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics