[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/sitemgr/modules/ -> class.module_navigation.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare SiteMgr - Web Content Management                              *
   4      * http://www.egroupware.org                                                *
   5      * --------------------------------------------                             *
   6      *  This program is free software; you can redistribute it and/or modify it *
   7      *  under the terms of the GNU General Public License as published by the   *
   8      *  Free Software Foundation; either version 2 of the License, or (at your  *
   9      *  option) any later version.                                              *
  10      \**************************************************************************/
  11  
  12      /* $Id: class.module_navigation.inc.php 20985 2006-04-06 11:02:49Z ralfbecker $ */
  13  
  14      /**
  15       * Navigation framework module
  16       * The idea behind this module is, just to have ONE highly configurable module FOR ALL navigation elements
  17       * If it's possible, we don't use extra functions for different views to reduce code
  18       * There are some predefined views wich are quite commen or are needed for backward compability
  19       *
  20       * The views are customizeable by css. See default.css in folder sitemgr-site/templates/default/style/
  21       *
  22       *  There is a horde of options to control the generation engine:
  23       * - category_id
  24       * - current_section_only
  25       * - expand
  26       * - highlight_current_page
  27       * - max_cat_depth -> could be ablolute ('number')  or relative (+number)
  28       * - max_pages_depth -> could be ablolute ('number')  or relative (+number)
  29       * - nav_title
  30       * - no_full_index
  31       * - path_only
  32       * - show_cat_description
  33       * - show_edit_icons
  34       * - show_page_description
  35       * - show_subcats_above
  36       * - showhidden
  37       * - sub_cats
  38       * - suppress_current_cat
  39       * - suppress_main_cats
  40       * - suppress_cat_link
  41       * - suppress_current_page
  42       * - suppress_parent
  43       * - suppress_show_all
  44       *
  45       * @author Cornelius Weiss<egw@von-und-zu-weiss.de>
  46       * @package sitemgr
  47       * 
  48       */
  49      class module_navigation extends Module
  50      {
  51  		function module_navigation()
  52          {
  53              $this->arguments = array(
  54                  'nav_type' => array(
  55                      'type' => 'select', 
  56                      'label' => lang('Select type of Navigation'),
  57                      'options' => array(
  58                          0 => lang('Select one'),
  59                          1 => 'currentsection',
  60                          2 => 'index',
  61                          3 => 'index_block',
  62                          4 => 'navigation',
  63                          5 => 'sitetree',
  64                          6 => 'toc',
  65                          7 => 'toc_block',
  66                          8 => 'path',
  67                          9 => lang('custom')
  68                      )
  69                  )    
  70              );
  71              $this->nav_args = array(
  72                  1 => array( // Currentsection
  73                      'description' => lang('This block displays the current section\'s table of contents'),
  74                      'suppress_current_page' => array(
  75                          'type' => 'checkbox',
  76                          'label' => lang('Suppress the current page')
  77                      ),
  78                      'suppress_parent' => array(
  79                          'type' => 'checkbox',
  80                          'label' => lang('Suppress link to parent category')
  81                      ),
  82                      'suppress_show_all' => array(
  83                          'type' => 'checkbox',
  84                          'label' => lang('Suppress link to index (show all)')
  85                      )),
  86                  2 => array( // Index
  87                      'description' => lang('This module provides the site index, it is automatically used by the index GET parameter')
  88                      ),
  89                  3 => array( // Index_block
  90                      'description' => lang('This module displays the root categories, its pages and evtl. subcategories. It is meant for side areas'),
  91                      'sub_cats' => array(
  92                          'type' => 'checkbox',
  93                          'label' => lang('Show subcategories')
  94                      ),
  95                      'no_full_index' => array(
  96                          'type' => 'checkbox',
  97                          'label' => lang('No link to full index')
  98                      ),
  99                      'expand' => array(
 100                          'type' => 'checkbox',
 101                          'label' => lang('Expand current category')
 102                      )),
 103                  4 => array( // Navigation
 104                      'description' => lang("This module displays the root categories in one block each, with pages and subcategories (incl. their pages if activated).")
 105                      ),
 106                  5 => array( // Sitetree
 107                      'description' => lang('This block displays a javascript based tree menu')
 108                      ),
 109                  6 => array( // Toc
 110                      'description' => lang('This module provides a complete table of contents, it is automatically used by the toc and category_id GET parameters'),
 111                      'category_id' =>array(
 112                          'type' => 'textfield', 
 113                          'label' => lang('The category to display, 0 for complete table of contents')
 114                      )),
 115                  7 => array( // Toc_block
 116                      'description' => lang('This module provides a condensed table of contents, meant for side areas')
 117                      ),
 118                  8 => array( // Path
 119                      'description' => lang('This module provides the path to the element currently shown')
 120                      ),
 121                  9 => array( //Custom
 122                      'description' => lang('This module is a customisable navigation element'),
 123                      'allingment' => array(
 124                          'type' => 'select',
 125                          'label' => lang('Allignment of navigation elements'),
 126                          'options' => array(
 127                              'vertical' => lang('Vertical'),
 128                              'horizontal' => lang('Horizontal'))
 129                      ),
 130                      'textallign' => array(
 131                          'type' => 'select',
 132                          'label' => lang('Text allignment'),
 133                          'options' => array(
 134                              'left' => lang('Left'),
 135                              'center' => lang('Center'),
 136                              'right' => lang('Right'))),
 137                      'max_cat_depth' => array(
 138                          'type' => 'textfield',
 139                          'label' => lang('Maximal category depth to be shown'),
 140                      ),
 141                      'max_pages_depth' => array(
 142                          'type' => 'textfield',
 143                          'label' => lang('Maximal page depth to be shown'),
 144                      ),
 145                      'sub_cats' => array(
 146                          'type' => 'checkbox',
 147                          'label' => lang('Show subcategories')
 148                      ),
 149                      'expand' => array(
 150                          'type' => 'checkbox',
 151                          'label' => lang('Expand current category'),
 152                      ),
 153                      'current_section_only' => array(
 154                          'type' => 'checkbox',
 155                          'label' => lang('Show current section only')
 156                      ),
 157                      'suppress_parent' => array(
 158                          'type' => 'checkbox',
 159                          'label' => lang('Suppress link to parent category')
 160                      ),
 161                      'suppress_current_cat' => array(
 162                          'type' => 'checkbox',
 163                          'label' => lang('Suppress the current category')
 164                      ),
 165                      'suppress_main_cats' => array(
 166                          'type' => 'checkbox',
 167                          'label' => lang('Suppress main categories')
 168                      ),
 169                      'suppress_show_all' => array(
 170                          'type' => 'checkbox',
 171                          'label' => lang('Suppress link to index (show all)')
 172                      ),
 173                      'no_full_index' => array(
 174                          'type' => 'checkbox',
 175                          'label' => lang('No link to full index')
 176                      ),
 177                  ));
 178              $this->title = 'Navigation element';
 179              $this->description = lang("This module displays any kind of navigation element.");
 180          }
 181          
 182  		function get_user_interface()
 183          {
 184              if(!@is_object($GLOBALS['egw']->js))
 185              {
 186                  $GLOBALS['egw']->js =& CreateObject('phpgwapi.javascript');
 187              }
 188              $GLOBALS['egw']->js->validate_file('tabs','tabs');
 189                  
 190              // I know, this is ugly. If you find a better solution for this, please help!
 191              $interface[] = array(
 192                  'label' => "
 193                  <style type=\"text/css\">
 194                      div.activetab{ display:inline; position: relative; left: -0px; text-align:left;}
 195                      div.inactivetab{ display:none; }
 196                  </style>
 197                  <script type=\"text/javascript\">
 198                      var tab = new Tabs('".(string)(count($this->arguments['nav_type']['options']) -1)."',
 199                      'activetab','inactivetab','tab','tabcontent','','','tabpage');
 200                      tab.init();
 201                  </script>",
 202              );
 203              $this->arguments['nav_type']['params'] = array(
 204                  'onchange' => 'javascript:tab.display(this.value)'
 205              );
 206              
 207              $elementname = 'element[' . $this->block->version . '][nav_type]';
 208              $interface[] = array(
 209                  'label' => '<b>'.$this->arguments['nav_type']['label'].'</b>'.
 210                      parent::build_input_element($this->arguments['nav_type'],$this->block->arguments['nav_type'],$elementname)
 211              );
 212              
 213              // build the tab elements
 214              $tabs = '';
 215              for($id = 1; $id < count($this->arguments['nav_type']['options']); $id++)
 216              {
 217                  $description = $this->nav_args[$id]['description'];
 218                  unset($this->nav_args[$id]['description']);
 219                  
 220                  $tmpargs = $this->arguments;
 221                  $this->arguments = $this->nav_args[$id];
 222                  $tabs .= '<div id="tabcontent'. $id. '" class="inactivetab"><table>';
 223                  $tabs .= '<tr><td colspan="2"><i>'. $description. '</i></td></tr>';
 224                  if(count($this->nav_args[$id]) >= 1)
 225                  {
 226                      foreach (parent::get_user_interface() as $param)
 227                      {
 228                          $tabs .= '<tr><td>'.$param['label'].'</td><td>'.$param['form'].'</td></tr>';
 229                      }
 230                  }
 231                  else
 232                  {
 233                      $tabs .= '<td>'. lang('No additional arguments required'). '</td><td></td>';
 234                  }
 235                  $tabs .= '</table></div>';
 236                  $this->arguments = $tmpargs;
 237              }
 238              $interface[] = array('label' => $tabs);
 239              
 240              // show current tab
 241              $interface[] = array(
 242                  'label' => "
 243                  <script type=\"text/javascript\">
 244                      tab.display(". $this->block->arguments['nav_type']. ");
 245                  </script>",
 246              );
 247  
 248              return $interface;
 249          }
 250          
 251          // strip options from other nav_types
 252  		function validate(&$data)
 253          {
 254              $val_data = array('nav_type' => $data['nav_type']);
 255              foreach($data as $key => $val)
 256              {
 257                  if($this->nav_args[$data['nav_type']][$key]) $val_data[$key] = $val;
 258              }
 259              $data = $val_data;
 260              return true;
 261          }
 262          
 263  		function get_content(&$arguments,$properties)
 264          {
 265              $out =  "<!-- navigation-context begins here -->\n".
 266                  "<div id=\"navigation-context\">\n".
 267                  "  <div id=\"navigation-";
 268              switch ($arguments['nav_type'])
 269              {
 270                  case 1 : // Currentsection
 271                      $out .= "currentsection\">\n";
 272                      $arguments = array_merge($arguments, array(
 273                          'nav_title' => lang('Pages:'),
 274                          'current_section_only' => true,
 275                          'suppress_current_cat' => true,
 276                          'highlight_current_page' => true,
 277                          'max_cat_depth' => '+0',
 278                          'max_pages_depth' => '+0',
 279                          'showhidden' => false,
 280                          'no_full_index' => true,
 281                          'show_subcats_above' => true,
 282                      ));
 283                      break;
 284                  case 2 : // Index
 285                      $out .= "index\">\n";
 286                      $arguments = array_merge($arguments, array(
 287                          'max_cat_depth' => '2',
 288                          'max_pages_depth' => '2',
 289                          'showhidden' => false,
 290                          'suppress_parent' => true,
 291                          'suppress_show_all' => true,
 292                          'suppress_cat_link' => true,
 293                          'show_edit_icons' => true,
 294                          'show_cat_description' => true,
 295                          'show_page_description' => true,
 296                          'no_full_index' => true,
 297                      ));
 298                      break;
 299                  case 3 : // Index_Block
 300                      $out .= "index_block\">\n";
 301                      $arguments = array_merge($arguments, array(
 302                          'max_cat_depth' => $arguments['sub_cats'] ? '2' : '1',
 303                          'max_pages_depth' => '1',
 304                          'showhidden' => false,
 305                          'suppress_parent' => true,
 306                          'suppress_show_all' => true,
 307                      ));
 308                      break;
 309                  case 5 : // Sitetree
 310                      $out .= "sitetree\">\n";
 311                      $out .= $this->type_sitetree($arguments,$properties);
 312                      $out .= "  </div>\n<!-- navigation context ends here -->\n</div>\n";
 313                      return $out;
 314                  case 6 : // Toc
 315                      $out .= "toc\">\n";
 316                      $arguments = array_merge($arguments, array(
 317                          'suppress_show_all' => true,
 318                          'show_edit_icons' => true,
 319                          'show_cat_description' => true,
 320                          'suppress_parent' => true,
 321                          ));
 322                      // Topic overview
 323                      if((int)$arguments['category_id'] == 0)
 324                      {
 325                          $arguments = array_merge($arguments, array(
 326                              'nav_title' => lang('Choose a category'),
 327                              'max_cat_depth' => '10',
 328                              'max_pages_depth' => '0',
 329                              'no_full_index' => true,
 330                              
 331                          ));
 332                      }
 333                      // like currentsection of a certain cat
 334                      else
 335                      {
 336                          $arguments = array_merge($arguments, array(
 337                              'nav_title' => lang('Pages:'),
 338                              'suppress_current_cat' => true,
 339                              'max_cat_depth' => '+0',
 340                              'max_pages_depth' => '+0',
 341                              'show_page_description' => true,
 342                              'show_subcats_above' => true,
 343                          ));
 344                      }
 345                      break;
 346                  case 7 : // Toc_block
 347                      $out .= "toc_block\">\n";
 348                      $arguments = array_merge($arguments, array(
 349                          'suppress_show_all' => true,
 350                          'no_full_index' => true,
 351                          'suppress_parent' => true,
 352                          'max_cat_depth' => '10',
 353                          'max_pages_depth' => '0',
 354                      ));
 355                      break;
 356                  case 8 : // Path
 357                      $out .= "path\">\n";
 358                      $arguments = array_merge($arguments, array(
 359                          'suppress_parent' => true,
 360                          'suppress_show_all' => true,
 361                          'path_only' => true,
 362                          'no_full_index' => true,
 363                      ));
 364                      break;
 365                      
 366                  case 9 : // Custom
 367                      $out .= "custrom\" ";
 368                      $out .= "class=\"allingment-". $arguments['allingment']."\" ";
 369                      $out .= "class=\"textallign-". $arguments['textallign']."\"";
 370                      $out .= ">\n";
 371                      break;
 372                  case 4 : // Navigation
 373                  default:
 374                      $out .= "navigation\">\n";
 375                      $out .= $this->type_navigation($arguments,$properties);
 376                      $out .= "  </div>\n<!-- navigation context ends here -->\n</div>\n";
 377                      return $out;
 378              }
 379                  
 380              $this->objbo =& $GLOBALS['objbo'];
 381              $this->page =& $GLOBALS['page'];
 382              $this->category =& $this->objbo->getcatwrapper($this->page->cat_id);
 383              
 384              if (!$arguments['suppress_parent'])
 385              {
 386                  $parent = $this->category->parent;
 387                  if ($parent && $parent != CURRENT_SITE_ID) // do we have a parent?
 388                  {
 389                      $p = $this->objbo->getcatwrapper($parent);
 390                      $entry['link'] = '<a href="'.sitemgr_link2('/index.php','category_id='.$parent).'" title="'.$p->description.'">'.$p->name.'</a>';
 391                      $out .= "\n<div class=\"nav-header-parent\">".lang('Parent Section:')."</div>\n";
 392                      $out .= $this->encapsulate($arguments,array($parent => $entry),'cat',$parent);
 393                      $out .= "\n<br />\n";
 394                  }
 395              }
 396              
 397              if($arguments['show_subcats_above'])
 398              {
 399                  $catlinks = $arguments['category_id'] ?
 400                      $this->objbo->getCatLinks((int)$arguments['category_id'],False,True) :
 401                      $this->objbo->getCatLinks((int)$this->page->cat_id,False,True);
 402                  if(count($catlinks))
 403                  {
 404                      $out .= "\n<div class=\"nav-header-subsection\">".lang('Subsections:')."</div>\n";
 405                      $out .= $arguments['category_id'] ?
 406                          $this->encapsulate($arguments,$catlinks,'cat',(int)$arguments['category_id']) :
 407                          $this->encapsulate($arguments,$catlinks,'cat',(int)$this->page->cat_id);
 408                      $out .= "\n<br />\n";
 409                  }
 410                  
 411              }
 412              
 413              if($arguments['nav_title'])
 414              {
 415                  $out .= "\n<span class=\"nav-title\">".$arguments['nav_title']."</span>\n";
 416              }
 417              
 418              if (!$arguments['suppress_show_all'])
 419              {
 420                  $out .= ' (<a href="'.sitemgr_link2('/index.php','category_id='.$this->page->cat_id).
 421                      '"><i>'.lang('show all').'</i></a>)'."\n";
 422              }
 423              
 424              // relative cat or pages depth ?
 425              if (strpos($arguments['max_cat_depth'],'+') === 0) (int)$arguments['max_cat_depth'] += $this->category->depth;
 426              if (strpos($arguments['max_pages_depth'],'+') === 0) (int)$arguments['max_pages_depth'] += $this->category->depth;
 427              
 428              $cat_tree = $cat_tree_data = array('root');
 429              foreach($this->objbo->getCatLinks(0,true,true) as $cat_id => $cat)
 430              {
 431                  if(array_key_exists($cat['depth'],$cat_tree))
 432                  {
 433                      $pop_depth = count($cat_tree);
 434                      for($depth=$cat['depth']; $depth < $pop_depth; $depth++)
 435                      {
 436                          array_pop($cat_tree); array_pop($cat_tree_data);
 437                      }
 438                  }
 439                  array_push($cat_tree,$cat_id); array_push($cat_tree_data,$cat);
 440  
 441                  if($arguments['expand'] && $cat_id == $this->page->cat_id && $cat['depth'] >= $arguments['max_cat_depth'])
 442                  {
 443                      //strip allready displayed contets of cat_tree
 444                      unset($cat_tree[0]); unset($cat_tree_data[0]);
 445                      foreach($cat_tree_data as $num => $category)
 446                      {
 447                          if($category['depth'] < $arguments['max_cat_depth'])
 448                          {
 449                              unset($cat_tree[$num]); unset($cat_tree_data[$num]);
 450                          }
 451                          // we need only pages of this cat, but not cat itseve!
 452                          if($category['depth'] ==  $arguments['max_cat_depth'] && $this->page->cat_id != $cat_tree[$num])
 453                          {
 454                              $cat_tree_data[$num]['pages_only'] = true;
 455                          }
 456                      }
 457                      
 458                      //expand rest
 459                      $cat_tree = array_reverse($cat_tree); $cat_tree_data = array_reverse($cat_tree_data);
 460                      $outstack = array($cat_tree[count($cat_tree) -1]); $outstack_data = array($cat_tree_data[count($cat_tree) -1]);
 461                      $popcat = array_pop($outstack); $popcat_data = array_pop($outstack_data);
 462                      while($popcat)
 463                      {
 464                          if(!$popcat_data['pages_only'] && !($arguments['suppress_main_cats'] && $popcat_data['depth'] == 1))
 465                          {
 466                              $out .= $this->encapsulate($arguments,array($popcat => $popcat_data),'cat',$popcat,$popcat_data['depth']);
 467                          }
 468                          if(array_search($popcat,$cat_tree) !== false)
 469                          {
 470                              $pages = $this->objbo->getPageLinks($popcat,$arguments['showhidden'],true);
 471                              $out .= $this->encapsulate($arguments,$pages,'page',$popcat,$popcat_data['depth'] +1);
 472                          }
 473                          $subcats = array_reverse($this->objbo->getCatLinks($popcat,false,true),true);
 474                          foreach($subcats as $subcat_id => $subcat)
 475                          {
 476                              array_push($outstack,$subcat_id); array_push($outstack_data,$subcat);
 477                          }
 478                          $popcat = array_pop($outstack); $popcat_data = array_pop($outstack_data);
 479                      }
 480                      continue;
 481                  }
 482                  
 483                  if($arguments['path_only'])
 484                  {
 485                      if($cat_id != $this->page->cat_id) continue;
 486                      unset($cat_tree_data[0]);
 487                      $pages = $this->objbo->getPageLinks($cat_id,true,true);
 488                      if($this->page->id) $cat_tree_data[] = $pages[$this->page->id];
 489                      $out .= $this->encapsulate($arguments,$cat_tree_data,'cat',$cat_id);
 490                      break;
 491                  }
 492                  
 493  //                 if($arguments['current_section_only'] && $this->page->cat_id != $cat_id) continue;
 494                   if($arguments['current_section_only'] && array_search($this->page->cat_id,$cat_tree) === false) continue;
 495                  if((int)$arguments['category_id'] > 0 && (int)$arguments['category_id'] != $cat_id) continue;
 496  //                  _debug_array($cat_tree);
 497                  if($cat['depth'] <= $arguments['max_cat_depth'])
 498                  {
 499                      if(!($arguments['suppress_current_cat'] && $this->page->cat_id == $cat_id) && 
 500                          !($arguments['suppress_main_cats'] && $cat['depth'] == 1))
 501                      {
 502                          if($arguments['suppress_cat_link'])
 503                          {
 504                              $cat['link'] = $cat['name'];
 505                          }
 506                          $out .= $this->encapsulate($arguments,array($cat_id => $cat),'cat',$cat_id,$cat['depth']);
 507                      }
 508                  }
 509                      if($cat['depth'] <= $arguments['max_pages_depth'])
 510                      {
 511                          $pages = $this->objbo->getPageLinks($cat_id,$arguments['showhidden'],true);
 512                          if($arguments['suppress_current_page']) unset($pages[$this->page->id]);
 513                          $out .= $this->encapsulate($arguments,$pages,'page',$cat_id,$cat['depth'] +1);
 514                      }
 515                  
 516              }
 517              if (!$arguments['no_full_index'])
 518              {
 519                  $out .= "    <div class=\"nav-full-index\">\n";
 520                  $out .= "      <a href=\"".sitemgr_link2('/index.php','index=1')."\">". lang('View full index') . "</a>\n";
 521                  $out .= "    </div>\n";
 522              }
 523  
 524              $out .= "  </div>\n<!-- navigation context ends here -->\n</div>\n";
 525              return $out;
 526          }
 527          
 528          /**
 529           * encapsulates navigation elements
 530           *
 531           * @param $arguments of module.
 532           * @param $data 
 533           * @param $type string 'cat' or 'page'
 534           * @param $cat_id of cat itselve or of cat page belongs to.
 535           * @param $depth logical deps of cat or page.
 536           *
 537           */
 538  		function encapsulate($arguments,$data,$type,$cat_id,$depth=1)
 539          {
 540              $out  = "    <div class=\"nav-".$type."-entry depth-".$depth."\">\n";
 541              $out .= "      <ul>\n";
 542              if (is_array($data))
 543              foreach($data as $id => $entry)
 544              {
 545                  if($arguments['highlight_current_page'] && $id == $this->page->id && $type == 'page')
 546                  {
 547                      $entry['link'] = "<div class=\"nav-highlight_current_page\">".$entry['link'].'</div>';
 548                  }
 549  
 550                  $out .= "        <li>\n";
 551                  $out .= "          ".$entry['link']."\n";
 552                  
 553                  if($arguments['show_edit_icons'])
 554                  {
 555                      $out .= "<span class=\"nav-edit-icons\">";
 556                      $out .= $type == 'cat' ? 
 557                          $this->objbo->getEditIconsCat($id) :
 558                          $this->objbo->getEditIconsPage($id,$cat_id);
 559                      $out .= "</span>\n";
 560                  }
 561  //                 _debug_array($entry);
 562                  if(($arguments['show_cat_description'] && $type == 'cat') || ($arguments['show_page_description'] && $type == 'page'))
 563                  {
 564                      $out .= "<span class=\"nav-".$type."-description\">";
 565                      $out .= $type =='cat' ? $entry['description'] : $entry['subtitle'];
 566                      $out .= "</span>\n";
 567                  }
 568                  
 569                  $out .= "        </li>\n";
 570              }
 571              $out .= "      </ul>\n";
 572              $out .= "    </div>\n";
 573              return $out;
 574          }
 575          
 576  		function type_navigation(&$arguments,$properties)
 577          {
 578              global $objbo,$page;
 579              $index_pages = $objbo->getIndex(False,False,True);
 580  
 581              if (!count($index_pages))
 582              {
 583                  return lang('You do not have access to any content on this site.');
 584              }
 585              $index_pages[] = array(    // this is used to correctly finish the last block
 586                  'cat_id'    => 0,
 587                  'catdepth'    => 1,
 588              );
 589  
 590              $this->template =& CreateObject('phpgwapi.Template',$this->find_template_dir());
 591              $this->template->set_file('cat_block','navigation.tpl');
 592              $this->template->set_block('cat_block','block_start');
 593              $this->template->set_block('cat_block','level1');
 594              $this->template->set_block('cat_block','level2');
 595              $this->template->set_block('cat_block','block_end');
 596              
 597              $last_cat_id = 0;
 598              foreach($index_pages as $ipage)
 599              {
 600                  preg_match('/href="([^"]+)"/i',$ipage['catlink'],$matches);
 601                  $this->template->set_var(array(
 602                      'item_link' => $matches[1],
 603                      'item_name' => $ipage['catname'],
 604                      'item_desc' => $ipage['catdescrip'],
 605                  ));
 606                  if ($ipage['cat_id'] != $last_cat_id)    // new category
 607                  {
 608                      switch ($ipage['catdepth'])
 609                      {
 610                          case 1:    // start of a new level-1 block
 611                              if ($last_cat_id)    // if there was a previous block, finish that one first
 612                              {
 613                                  $content .= $this->template->parse('out','block_end');
 614                              }
 615                              // start the new block
 616                              if ($ipage['cat_id'])
 617                              {
 618                                  $content .= $this->template->parse('out','block_start');
 619                              }
 620                              break;
 621                          case 2:
 622                              $content .= $this->template->parse('out','level1');
 623                      }
 624                  }
 625                  $last_cat_id = $ipage['cat_id'];
 626                  
 627                  // show the pages of the active cat or first-level pages
 628                  if ($ipage['page_id'] && ($ipage['cat_id'] == $page->cat_id || $ipage['catdepth'] == 1))
 629                  {
 630                      preg_match('/href="([^"]+)"/i',$ipage['pagelink'],$matches);
 631                      $this->template->set_var(array(
 632                          'item_link'        => $matches[1],
 633                          'item_name'        => $ipage['pagesubtitle'],
 634                          'item_desc'        => $ipage['pagetitle'],
 635                      ));
 636                      $content .= $this->template->parse('out',$ipage['catdepth'] == 1 ? 'level1' : 'level2');
 637                  }
 638              }
 639              return $content;
 640          }
 641          
 642  		function type_sitetree(&$arguments,$properties)
 643          {
 644              $title = '';
 645              if ($arguments['menutree'])
 646              {
 647                  $this->expandedcats = array_keys($arguments['menutree']);
 648              }
 649              else
 650              {
 651                  $this->expandedcats = Array();
 652              }
 653              $topcats = $GLOBALS['objbo']->getCatLinks(0,False);
 654      
 655              $content = "<script type='text/javascript'>
 656                  // the whole thing only works in a DOM capable browser or IE 4*/
 657                  
 658  				function add(catid)
 659                  {
 660                      document.cookie = 'block[" . $this->block->id . "][menutree][' + catid + ']=';
 661                  }    
 662                  
 663  				function remove(catid)
 664                  {
 665                      var now = new Date();
 666                      document.cookie = 'block[" . $this->block->id . "][menutree][' + catid + ']=; expires=' + now.toGMTString();
 667                  }
 668                  
 669  				function toggle(image, catid)
 670                  {
 671                      if (document.getElementById)
 672                      { //DOM capable
 673                          styleObj = document.getElementById(catid);
 674                      }
 675                      else //we're helpless
 676                      {
 677                          return;
 678                      }
 679                  
 680                      if (styleObj.style.display == 'none')
 681                      {
 682                          add(catid);
 683                          image.src = 'images/tree_collapse.gif';
 684                          styleObj.style.display = 'block';
 685                      }
 686                      else
 687                      {
 688                          remove(catid);
 689                          image.src = 'images/tree_expand.gif';
 690                          styleObj.style.display = 'none';
 691                      }
 692                  }
 693                  </script>";
 694                  
 695              if (count($topcats)==0)
 696              {
 697                  $content=lang('You do not have access to any content on this site.');
 698              }
 699              else
 700              {
 701                  $content .= "\n" . 
 702                      '<table border="0" cellspacing="0" cellpadding="0" width="100%">' .
 703                      $this->showcat($topcats) .
 704                      '</table>' .
 705                      "\n";
 706                  $content .= '<br><a href="'.sitemgr_link('toc=1').'"><font size="1">(' . lang('Table of contents') . ')</font></a>';
 707              }
 708              return $content;
 709          }
 710          
 711  		function showcat($cats)
 712          {
 713              foreach($cats as $cat_id => $cat)
 714              {
 715                  $status = in_array($cat_id,$this->expandedcats);
 716                  $childrenandself = array_keys($GLOBALS['objbo']->getCatLinks($cat_id));
 717                  $childrenandself[] = $cat_id;
 718                  $catcolour = in_array($GLOBALS['page']->cat_id,$childrenandself) ? "red" : "black";
 719                  $tree .= "\n" . 
 720                      '<tr><td width="10%">' . 
 721                      '<img src="images/tree_' .
 722                      ($status ? "collapse" : "expand") .
 723                      '.gif" onclick="toggle(this, \'' . 
 724                      $cat_id . 
 725                      '\')"></td><td><b title="' .
 726                      $cat['description'] .
 727                      '" style="color:' .
 728                      $catcolour .
 729                      '">'.
 730                      $cat['name'] . 
 731                      '</b></td></tr>' . 
 732                      "\n";
 733                  $subcats = $GLOBALS['objbo']->getCatLinks($cat_id,False);
 734                  $pages = $GLOBALS['objbo']->getPageLinks($cat_id);
 735                  if ($subcats || $pages)
 736                  {
 737                      $tree .= '<tr><td></td><td><table style="display:' .
 738                          ($status ? "block" : "none") .
 739                          '" border="0" cellspacing="0" cellpadding="0" width="100%" id="'.
 740                          $cat_id .
 741                          '">';
 742                      if (is_array($pages))
 743                      foreach($pages as $page_id => $page)
 744                      {
 745                          //we abuse the subtitle in a nonstandard way: we want it to serve as a *short title* that is displayed
 746                          //in the tree menu, so that we can have long titles on the page that would not be nice in the tree menu
 747                          $title = $page['subtitle'] ? $page['subtitle'] : $page['title'];
 748                          $tree .= '<tr><td colspan="2">' . 
 749                              (($page_id == $GLOBALS['page']->id) ? 
 750                                  ('<span style="color:red">' . $title . '</span>') :
 751                                  ('<a href="' . sitemgr_link('page_name='. $page['name']) . '">' . $title . '</a>')
 752                              ) . 
 753                              '</td></tr>';
 754                      }
 755                      if ($subcats)
 756                      {
 757                          $tree .= $this->showcat($subcats);
 758                      }
 759      
 760                      $tree .= '</table></td></tr>';
 761                  }
 762              }
 763              return $tree;
 764          }
 765      }
 766  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7