[ Index ]
 

Code source de SPIP Agora 1.4

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

title

Body

[fermer]

/Pear/DB/docs/ -> TigraMenu_example.php (source)

   1  <?php
   2  /**
   3   * $Id: TigraMenu_example.php,v 1.2 2003/05/15 16:23:09 jrust Exp $
   4   * This example shows how to use the TigraMenu output driver
   5   *
   6   * @author Daniel Khan <dk@webcluster.at>
   7   */
   8  
   9  // This example assumes that you have allready set up DB_NestedSet and allready
  10  // inserted nodes.
  11  
  12  // First you have to get TigraMenu
  13  // It's available for free at http://www.softcomplex.com/products/tigra_menu/
  14  // Please read the docs for TigraMenu - they are nice and verbose and will help
  15  // you to understand the params passed to the driver
  16  // No - I'll do no JavaScript support ;)
  17  
  18  
  19  /*
  20  Content of test.php:
  21  ------------------------
  22  
  23  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  24  <html>
  25  <head>
  26  <title>{sitename}</title>
  27  
  28  <script language="JavaScript" src="/js/menu_items.php">
  29  <!--
  30  //--> 
  31  </script>
  32  
  33  <script language="JavaScript" src="/js/menu.js">
  34  <!--
  35  //--> 
  36  </script>
  37  
  38  </head>
  39  <body>
  40  
  41  <b>Just testing</b>
  42  <script language="JavaScript">
  43  
  44  <!--
  45      new menu (MENU_ITEMS1, MENU_POS1, MENU_STYLES1); 
  46  //--> 
  47  
  48  </script> 
  49  </body>
  50  </html>
  51  
  52  
  53  /*
  54  Content of menu_items.php:
  55  ------------------------
  56  */
  57  
  58  require_once('DB/NestedSet.php');
  59  require_once('DB/NestedSet/Output.php');
  60  
  61  // Choose a database abstraction layer. 'DB' and 'MDB' are supported.
  62  $nese_driver = 'DB';
  63  
  64  // Set the DSN - see http://pear.php.net/manual/en/core.db.tut_dsn.php for details
  65  $nese_dsn = 'mysql://user:password@localhost/test';
  66  
  67  // Specify the database columns which will be used to specify a node
  68  // Use an associative array. On the left side write down the name of the column.
  69  // On the right side write down how the property will be called in a node object
  70  // Some params are needed
  71  $nese_params = array
  72  (
  73  "STRID"         =>      "id",      // "id" must exist
  74  "ROOTID"        =>      "rootid",  // "rootid" must exist
  75  "l"             =>      "l",       // "l" must exist
  76  "r"             =>      "r",       // "r" must exist
  77  "STREH"         =>      "norder",  // "order" must exist
  78  "LEVEL"         =>      "level",   // "level" must exist
  79  "STRNA"         =>      "name",
  80  "STLNK"         =>      "link"     // Custom - specify as many fields you want
  81  );
  82  
  83  // Now create an instance of DB_NestedSet
  84  $NeSe = & DB_NestedSet::factory($nese_driver, $nese_dsn, $nese_params);
  85  if(PEAR::isError($NeSe)) {
  86      echo $NeSe->getCode().": ".$NeSe->getMessage();
  87  }
  88  
  89  // Fetch the tree as array
  90  $nodes = $NeSe->getAllNodes(true);
  91  
  92  // Set the basic params
  93  $params = array(
  94  'structure' => $nodes,
  95  'options' => array(
  96  ),
  97  'textField' => 'name', // Use the name column for the menu names
  98  'linkField' => 'link', // Use the link column for the links
  99  'currentLevel' => 1       // Start the ouput with this level
 100  );
 101  
 102  // This array contains the options needed
 103  // for printing out the menu.
 104  $options = array
 105  (
 106  // The style properties for the top level
 107  'rootStyles' => array(
 108  
 109      'onmouseout' => array(
 110          'color'=>'#FF0000',
 111          'background'=>'#000000',
 112          'textDecoration'=>'none',
 113          'border'=>"1px solid #FFFFFF",
 114          'fontSize' => '11px',
 115          'fontFamily' => 'Verdana, Arial, Helvetica, sans-serif',
 116          'fontWeight' => 'bold',
 117          'textAlign' => 'center',
 118          'padding' => '2px'
 119      // Set any JavaScript compatible style params here
 120      // Note that this properties also have to exist in
 121      // the child menu.
 122      // Set them to 'none' or other values there
 123      // to get another output
 124      ),
 125      'onmouseover' => array(
 126          'color'=>'#FFFFFF',
 127          'background'=>'#000000',
 128          'textDecoration'=>'none'
 129  
 130      ),
 131      'onmousedown' => array(
 132          'color'=>'#FFFFFF',
 133          'background'=>'#000000',
 134          'textDecoration'=>'none'
 135  
 136  )
 137  ),
 138      'childStyles' => array(
 139          'onmouseout' => array(
 140          'color'=>'#000000',
 141          'background'=>'#CCCCCC',
 142          'textDecoration'=>'none',
 143          'border'=>"1px solid #FFFFFF",
 144          'fontSize' => '11px',
 145          'fontFamily' => 'Verdana, Arial, Helvetica, sans-serif',
 146          'fontWeight' => 'normal',
 147          'textAlign' => 'left',
 148          'padding' => '2px'
 149      ),
 150          'onmouseover' => array(
 151              'color'=>'#FFFFFF',
 152              'background'=>'#EEEEEE',
 153              'textDecoration'=>'none'
 154  
 155      ),
 156      'onmousedown' => array(
 157              'color'=>'#FFFFFF',
 158              'background'=>'#EEEEEE',
 159              'textDecoration'=>'none'
 160  
 161      )
 162  ),
 163      // Geometry sets the positioning and the
 164      // proportions of the menu
 165      // It can also be set for the top level and the sublevels
 166      // Note that this properties also have to exist in
 167      // the child menu.
 168      // Please look at the fine TigraMenu docs
 169      // They have nice pictures describing the properties below
 170      // Special settings are explained here
 171      'rootGeometry' => array(
 172          'width' => '120',
 173          'height' => '21',
 174          'left' => '119', 
 175          'top' => '0',
 176          'block_left' => '169',
 177          'block_top' => '121',
 178          'hide_delay' => '200'
 179  
 180      ),
 181      'childGeometry' => array(
 182      
 183          // If you use '*' the width is considered to be x * max chars within this submenu
 184          // e.g. 6 * 12
 185          // This is useful if you want that the menu auto sizes with the menu item name's length
 186          // The item width will can not be smaller than the root items with.
 187          // You will have to try different values depending on the font/size you use
 188          // If you want fixed with just remove the '*' 
 189          // e.g. 'width' => '100'
 190          'width' => '*6',
 191          'height' => '21',
 192          'left' => '0',
 193          'top' => '20',
 194          
 195          // Sets the horizontal offset between different levels
 196          // In this case the first submenu level after the root will have no offset
 197          // After that we will have -5 offset (overlapping) between the items
 198          'block_left' => '0,-5', 
 199          
 200          // Sets the vertical offset between different levels
 201          // In this case the first submenu level after the root will have 20px offset
 202          // After that we will have -10px offset (overlapping) between the items        
 203          'block_top' => '20,10',
 204          'hide_delay' => '2000'
 205      ),
 206  'menu_id'=>1     // This is the menu id used to call the menu from JavaScript: 
 207                  // new menu (MENU_ITEMS1, MENU_POS1, MENU_STYLES1);
 208  );
 209  
 210  
 211  // Now create the menu object, set the options and do the output
 212  $menu =& DB_NestedSet_Output::factory($params, 'TigraMenu');
 213  $menu->setOptions('printTree', $options);
 214  $menu->printTree();
 215  
 216  
 217  // Have fun!
 218  ?>
 219  
 220  


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7