[ Index ]
 

Code source de CMS made simple 1.0.5

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

title

Body

[fermer]

/plugins/ -> function.bulletmenu.php (source)

   1  <?php
   2  #CMS - CMS Made Simple
   3  #(c)2004 by Ted Kulp (wishy@users.sf.net)
   4  #This project's homepage is: http://cmsmadesimple.sf.net
   5  #
   6  #This program is free software; you can redistribute it and/or modify
   7  #it under the terms of the GNU General Public License as published by
   8  #the Free Software Foundation; either version 2 of the License, or
   9  #(at your option) any later version.
  10  #
  11  #This program is distributed in the hope that it will be useful,
  12  #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  #GNU General Public License for more details.
  15  #You should have received a copy of the GNU General Public License
  16  #along with this program; if not, write to the Free Software
  17  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18  
  19  function smarty_cms_function_bulletmenu($params, &$smarty) {
  20  
  21      global $gCms;
  22      global $config;
  23  
  24      # getting menu parameters
  25      $showadmin = isset($params['showadmin']) ? $params['showadmin'] : 0 ;
  26      $collapse = isset($params['collapse']) ? $params['collapse'] : 0 ;
  27  
  28      $contentops =& $gCms->GetContentOperations();
  29      $allcontent =& $contentops->GetAllContent(false);
  30  
  31      # defining variables
  32      $menu = "";
  33      $last_level = 0;
  34      $count = 0;
  35      $in_hr = 0;
  36  
  37      # array to hold hierarchy postitions of disabled pages
  38      $disabled = array();
  39  
  40      if (count($allcontent))
  41      {
  42          $basedepth = 0;
  43          $menu .= "<div class=\"bulletmenu\">\n";
  44  
  45          #Reset the base depth if necessary...
  46          if (isset($params['start_page']))
  47          {
  48              #foreach( $allcontent as $onecontent )
  49              reset($allcontent);
  50              while (list($key) = each($allcontent))
  51              {
  52                  $onecontent =& $allcontent[$key];
  53                  if( $onecontent->Alias() == $params['start_page'] || $onecontent->Id() == $params['start_page'])
  54                  {
  55                      $params['start_element'] = $onecontent->Hierarchy();
  56                      break;
  57                  }
  58              }
  59          }
  60  
  61          #Reset the base depth if necessary...
  62          if (isset($params['start_element']))
  63          {
  64              $basedepth = count(split('\.', (string)$params['start_element'])) - 1;
  65          }
  66  
  67          #foreach ($allcontent as &$onecontent)
  68          reset($allcontent);
  69          while (list($key) = each($allcontent))
  70          {
  71              $onecontent =& $allcontent[$key];
  72  
  73              #Handy little trick to figure out how deep in the tree we are
  74              #Remember, content comes to use in order of how it should be displayed in the tree already
  75              $depth = count(split('\.', $onecontent->Hierarchy()));
  76  
  77              #If hierarchy starts with the start_element (if it's set), then continue on
  78              if (isset($params['start_element']))
  79              {
  80                  if ((strpos($onecontent->Hierarchy(), (string)$params['start_element']) === FALSE) || (strpos($onecontent->Hierarchy(), (string)$params['start_element']) != 0))
  81                  {
  82                      if (isset($params['show_root_siblings']) && $params['show_root_siblings'] == '1')
  83                      {
  84                          # Find direct parent of current item
  85                          $curparent = substr($onecontent->Hierarchy(), 0, strrpos($onecontent->Hierarchy(), "."));
  86                          if ($curparent != '')
  87                          {
  88                              $curparent = $curparent . ".";
  89                          }
  90  
  91                          # Find direct parent of start_element
  92                          $otherparent = substr((string)$params['start_element'], 0, strrpos((string)$params['start_element'], "."));
  93                          if ($otherparent != '')
  94                          {
  95                              $otherparent = $otherparent . ".";
  96                          }
  97  
  98                          # Make sure the parents match
  99                          if ($curparent != $otherparent)
 100                          {
 101                              # Show the submenus of siblings, that is everything whose beginning matches parent
 102                              if (substr($curparent,0,strlen($otherparent))!=$otherparent) continue;
 103                          }
 104                      }
 105                      else
 106                      {
 107                          continue;
 108                      }
 109                  }
 110              }
 111  
 112              #Now check to make sure we're not too many levels deep if number_of_levels is set
 113              if (isset($params['number_of_levels']))
 114              {
 115                  $number_of_levels = $params['number_of_levels'] - 1;
 116  
 117                  #If this element's level is more than base_level + number_of_levels, then scratch it
 118                  if ($basedepth + $number_of_levels < $depth)
 119                  {
 120                      continue;
 121                  }
 122              }
 123  
 124              # Check for inactive items or items set not to show in the menu
 125              if (!$onecontent->Active() || !$onecontent->ShowInMenu())
 126              {
 127                  # Stuff the hierarchy position into that array, so we can test for
 128                  # children that shouldn't be showing.  Put the dot on the end
 129                  # since it will only affect children anyway...  saves from a
 130                  # .1 matching .11
 131                  $disabled[] = $onecontent->Hierarchy() . ".";
 132                  continue;
 133              }
 134  
 135              $disableme = false;
 136  
 137              # Loop through disabled array to see if this is a child that
 138              # shouldn't be showing -- we check this by seeing if the current
 139              # hierarhcy postition starts with one of the disabled positions
 140              foreach ($disabled as $onepos)
 141              {
 142                  # Why php doesn't have a starts_with function is beyond me...
 143                  if (strstr($onecontent->Hierarchy() . '.', $onepos) == $onecontent->Hierarchy() . '.')
 144                  {
 145                      $disableme = true;
 146                      continue; # Break from THIS foreach
 147                  }
 148              }
 149  
 150              if ($disableme)
 151              {
 152                  continue; # Break from main foreach
 153              }
 154  
 155              # Set depth to be the relative position
 156              $depth = $depth - $basedepth;
 157  
 158              # Now try to remove items that shouldn't be shown, based on current location
 159              if ($collapse == 1)
 160              {
 161                  if ($depth > 1) # All root level items should show
 162                  {
 163                      $curpos = $gCms->variables['position'];
 164                      $curdepth = count(split('\.', $curpos)) - $basedepth;
 165                      $curparent = substr($gCms->variables['position'], 0, strrpos($gCms->variables['position'], "."));
 166                      if ($curparent != '')
 167                      {
 168                          $curparent = $curparent . ".";
 169                      }
 170  
 171                      $skipme = true;
 172  
 173                      # Are we the currently selected page?
 174                      if ($onecontent->Hierarchy() == $curpos)
 175                      {
 176                          $skipme = false;
 177                      }
 178  
 179                      # First, are we a direct decendant of the current position?
 180                      if (strstr($onecontent->Hierarchy() . '.', $curpos . '.') == $onecontent->Hierarchy() . '.' && $curdepth == ($depth - 1))
 181                      {
 182                          $skipme = false;
 183                      }
 184  
 185                      # Now for the nasty part...  loop through all parents and show them and direct siblings
 186                      if ($skipme)
 187                      {
 188                          $blah = '';
 189                          $count = 1;
 190                          foreach (split('\.', $curpos) as $level)
 191                          {
 192                              $blah .= $level . '.';
 193                              global $gCms;
 194                              $contentops =& $gCms->GetContentOperations();
 195                              if (strstr($onecontent->Hierarchy() . '.', $contentops->CreateFriendlyHierarchyPosition($blah) . '.') == $onecontent->Hierarchy() . '.')
 196                              {
 197                                  if ($depth == ($count + 1))
 198                                  {
 199                                      $skipme = false;
 200                                      continue;
 201                                  }
 202                              }
 203                              $count++;
 204                          }
 205                      }
 206  
 207                      # Ok, so should we skip this thing already?
 208                      if ($skipme)
 209                      {
 210                          continue;
 211                      }
 212                  }
 213              }
 214  
 215              if ($depth < $last_level)
 216              {
 217                  for ($i = $depth; $i < $last_level; $i++)
 218                  {
 219                      $menu .= "\n</li>\n</ul>\n";
 220                  }
 221  
 222                  if ($depth > 0)
 223                  {
 224                      $menu .= "</li>\n";
 225                  }
 226              }
 227  
 228              if ($depth > $last_level)
 229              {
 230                  for ($i = $depth; $i > $last_level; $i--)
 231                  {
 232                      $menu .= "\n<ul>\n";
 233                  }
 234              }
 235  
 236              if ($depth == $last_level)
 237              {
 238                  $menu .= "</li>\n";
 239              }
 240  
 241              if ($onecontent->Type() == 'separator')
 242              {
 243                  $menu .= "<li style=\"list-style-type: none;\"><hr class=\"separator\" />";
 244              }
 245              else if ($onecontent->Type() == 'sectionheader')
 246              {
 247                  $menu .= '<li><span class="bullet_sectionheader">'.$onecontent->MenuText()."</span>\n";
 248              }
 249              else
 250              {
 251                  $menu .= "<li><a href=\"".$onecontent->GetURL()."\"";
 252                  if (isset($gCms->variables['content_id']) && $onecontent->Id() == $gCms->variables['content_id'])
 253                  {
 254                      $menu .= " class=\"currentpage\"";
 255                  }
 256                  if (method_exists($onecontent, 'HasProperty'))
 257                  {
 258                      if ($onecontent->HasProperty('target') && $onecontent->GetPropertyValue('target') != '')
 259                      {
 260                          $menu .= ' target="'.$onecontent->GetPropertyValue('target').'"';
 261                      }
 262                  }
 263                  $menu .= ">".$onecontent->MenuText()."</a>";
 264              }
 265  
 266              $in_hr = 1;
 267              $last_level = $depth;
 268              $count++;
 269          }
 270  
 271          for ($i = 0; $i < $last_level; $i++) $menu .= "</li></ul>";
 272  
 273          if ($showadmin == 1)
 274          {
 275              $menu .= "<ul><li><a href='".$config['admin_dir']."/'>Admin</a></li></ul>\n";
 276          }
 277          $menu .= "</div>\n";
 278      }
 279  
 280      return $menu;
 281  
 282  }
 283  
 284  function smarty_cms_help_function_bulletmenu() {
 285      ?>
 286      <h3>What does this do?</h3>
 287      <p>Prints a bullet menu.</p>
 288      <h3>How do I use it?</h3>
 289      <p>Just insert the tag into your template/page like: <code>{bulletmenu}</code></p>
 290      <h3>What parameters does it take?</h3>
 291      <p>
 292      <ul>
 293          <li><em>(optional)</em> <tt>showadmin</tt> - 1/0, whether you want to show or not the admin link.</li>
 294          <li><em>(optional)</em> <tt>collapse</tt> - 1/0, whether you want to collapse sub items that shouldn't be shown.  Defaults to 0.</li>
 295          <li><em>(optional)</em> <tt>start_page</tt> - the page id or alias (ie : 1.2 or 3.5.1 for example). This parameter sets the root node of the menu and only shows it and it's children. (a replacement for start_element)</li>
 296          <li><em>(optional)</em> <tt>start_element</tt> - the hierarchy of your element (ie : 1.2 or 3.5.1 for example). This parameter sets the root node of the menu and only shows it and it's children.</li>
 297          <li><em>(optional)</em> <tt>show_root_siblings</tt> - 1/0, if start_element (above) is given, then show direct siblings of the give start_element as well.</li>
 298          <li><em>(optional)</em> <tt>number_of_levels</tt> - an integer, the number of levels you want to show in your menu.</li>
 299      </ul>
 300      </p>
 301  
 302      <?php
 303  }
 304  
 305  function smarty_cms_about_function_bulletmenu() {
 306      ?>
 307      <p>Author: Julien Lancien&lt;calexico@cmsmadesimple.org&gt;</p>
 308      <p>Version: 1.0</p>
 309      <p>
 310      Change History:<br/>
 311      None
 312      </p>
 313      <?php
 314  }
 315  
 316  # vim:ts=4 sw=4 noet
 317  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7