html
[ class tree: html ] [ index: html ] [ all elements ]

Source for file WebsiteNavigation.class.php

Documentation is available at WebsiteNavigation.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package    html
  9.  * @subpackage components
  10.  */
  11. if!defined"CLASSPATH" ) )
  12. {
  13.   echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  14.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  15.   exit();
  16. }
  17.  
  18. /**
  19.  * Including the list class.
  20.  */
  21. require_once CLASSPATH."html/HTMLList.class.php";
  22. /**
  23.  * Including the link class.
  24.  */
  25. include_once CLASSPATH."html/HTMLLink.class.php";
  26.  
  27.  
  28. /**
  29.  * A class to generate the navigation of a website.
  30.  *
  31.  * @package    html
  32.  * @subpackage components
  33.  * @version    0.1.41
  34.  * @since      0.9.1.5
  35.  * @author     Daniel Plücken <daniel@debakel.net>
  36.  * @license    http://www.gnu.org/copyleft/lesser.html
  37.  *              GNU Lesser General Public License
  38.  * @copyright  Copyright (c) 2006 Daniel Plücken <daniel@debakel.net>
  39.  *
  40.  *  This library is free software; you can redistribute it and/or
  41.  *  modify it under the terms of the GNU Lesser General Public
  42.  *  License as published by the Free Software Foundation; either
  43.  *  version 2.1 of the License.
  44.  *
  45.  *  This library is distributed in the hope that it will be useful,
  46.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  47.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48.  *  GNU Lesser General Public License for more details.
  49.  *
  50.  *  You should have received a copy of the GNU Lesser General
  51.  *  Public License along with this library; if not, write to the
  52.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  53.  *  Boston, MA 02111-1307 USA
  54.  */
  55. class WebsiteNavigation extends HTMLList
  56. {
  57.    /**
  58.     * @access public
  59.     * @var    array $str_style_on_mouseup_arr 
  60.     */
  61.    var $str_style_on_mouseup_arr = array();
  62.    /**
  63.     * @access public
  64.     * @var    array $str_style_on_mouseover_arr 
  65.     */
  66.    var $str_style_on_mouseover_arr = array();
  67.    /**
  68.     * @access public
  69.     * @var    array $str_value_arr 
  70.     */
  71.    var $str_value_arr = array();
  72.    
  73.    
  74.    
  75.    
  76.    /**
  77.     * Constructor.
  78.     *
  79.     * @version 1.1
  80.     * @since   0.1.1
  81.     * @author  Daniel Plücken <daniel@debakel.net>
  82.     * @access  public
  83.     * @param   array  $label_arr 
  84.     * @param   array  $href_arr             Use the placeholder [value] to place
  85.     *                                        the the corresponding value from the
  86.     *                                        array $value_arr
  87.     * @param   array  $value_arr 
  88.     * @param   array  $style_class_arr 
  89.     * @param   array  $link_style_class_arr 
  90.     * @param   array  $freestyle_arr 
  91.     * @param   array  $link_freestyle_arr 
  92.     * @param   array  $target_arr 
  93.     * @return  WebsiteNavigation 
  94.     */
  95.    function WebsiteNavigation(
  96.                                $label_arr array(),
  97.                                $href_arr array(),
  98.                                $value_arr array(),
  99.                                $style_class_arr array(),
  100.                                $link_style_class_arr array(),
  101.                                $freestyle_arr array(),
  102.                                $link_freestyle_arr array(),
  103.                                $target_arr array()
  104.                              )
  105.    {
  106.       if is_array$label_arr ) )
  107.          foreach $label_arr as $key => $value )
  108.             $this->addElement(
  109.                                 $label_arr[$key],
  110.                                 $href_arr[$key],
  111.                                 $value_arr[$key],
  112.                                 $style_class_arr[$key],
  113.                                 $link_style_class_arr[$key],
  114.                                 $freestyle_arr[$key],
  115.                                 $link_freestyle_arr[$key],
  116.                                 $target_arr[$key]
  117.                              );
  118.    }
  119.  
  120.  
  121.  
  122.    /**
  123.     * Sets the style that should be used on mouseup for each element.
  124.     *
  125.     * @version 1.0
  126.     * @since   0.1.0
  127.     * @author  Daniel Plücken <daniel@debakel.net>
  128.     * @access  public
  129.     * @param   string  $str_style_class 
  130.     * @return  void 
  131.     */
  132.    function setStyleOnMouseUp$str_style_class )
  133.    {
  134.       foreach $this->list_arr as $key => $value )
  135.               $this->str_style_on_mouseup_arr[$key$str_style_class;
  136.    }
  137.  
  138.  
  139.  
  140.    /**
  141.     * Sets the style that should be used on mouseover for each element.
  142.     *
  143.     * @version 1.0
  144.     * @since   0.1.0
  145.     * @author  Daniel Plücken <daniel@debakel.net>
  146.     * @access  public
  147.     * @param   string  $str_style_class 
  148.     * @return  void 
  149.     */
  150.    function setStyleOnMouseOver$str_style_class )
  151.    {
  152.       foreach $this->list_arr as $key => $value )
  153.               $this->str_style_on_mouseover_arr[$key$str_style_class;
  154.    }
  155.  
  156.  
  157.  
  158.    /**
  159.     * Sets the style of the a list item identified by his given value.
  160.     *
  161.     * @version 1.0
  162.     * @since   0.1.2
  163.     * @author  Daniel Plücken <daniel@debakel.net>
  164.     * @access  public
  165.     * @param   string $str_value 
  166.     * @param   string $str_style_class 
  167.     * @param   string $str_link_style_class 
  168.     * @param   string $str_freestyle 
  169.     * @param   string $str_link_freestyle 
  170.     * @return  void 
  171.     */
  172.    function setMarkedValue(
  173.                             $str_value,
  174.                             $str_style_class "",
  175.                             $str_link_style_class "",
  176.                             $str_freestyle "",
  177.                             $str_link_freestyle ""
  178.                           )
  179.    {
  180.       foreach $this->list_arr as $key => $value )
  181.            if $this->str_value_arr[$key== $str_value )
  182.            {
  183.               $this->style_class_arr[$key$str_style_class;
  184.               $this->freestyle_arr[$key$str_freestyle;
  185.               $this->list_arr[$key]->setStyle$str_link_style_class );
  186.               $this->list_arr[$key]->setFreeStyle$str_link_freestyle );
  187.               
  188.               return;
  189.            }
  190.    }
  191.  
  192.  
  193.  
  194.    /**
  195.     * Sets the style of the a list item identified by his given value. This
  196.     * function is an alias for the function setMarkedValue.
  197.     *
  198.     * @version 1.0
  199.     * @since   0.1.3
  200.     * @author  Daniel Plücken <daniel@debakel.net>
  201.     * @access  public
  202.     * @param   string $str_value 
  203.     * @param   string $str_style_class 
  204.     * @param   string $str_link_style_class 
  205.     * @param   string $str_freestyle 
  206.     * @param   string $str_link_freestyle 
  207.     * @return  void 
  208.     */
  209.    function setSelectedValue(
  210.                               $str_value,
  211.                               $str_style_class "",
  212.                               $str_link_style_class "",
  213.                               $str_freestyle "",
  214.                               $str_link_freestyle ""
  215.                             )
  216.    {
  217.       $this->setMarkedValue(
  218.                       $str_value,
  219.                       $str_style_class,
  220.                       $str_link_style_class,
  221.                       $str_freestyle,
  222.                       $str_link_freestyle
  223.                            );
  224.    }
  225.  
  226.  
  227.  
  228.    /**
  229.     * Adds a navigation point to the list.
  230.     *
  231.     * @version 1.3
  232.     * @since   0.1.0
  233.     * @author  Daniel Plücken <daniel@debakel.net>
  234.     * @access  public
  235.     * @param   string  $str_label 
  236.     * @param   string  $str_href             Use the placeholder [value] to
  237.     *                                         place the the corresponding value.
  238.     * @param   string  $str_value 
  239.     * @param   string  $str_style_class 
  240.     * @param   string  $str_link_style_class 
  241.     * @param   string  $str_freestyle 
  242.     * @param   string  $str_link_freestyle 
  243.     * @param   string  $str_target 
  244.     * @return  integer The insert position.
  245.     */
  246.    function addElement(
  247.                         $str_label,
  248.                         $str_href,
  249.                         $str_value,
  250.                         $str_style_class "",
  251.                         $str_link_style_class "",
  252.                         $str_freestyle "",
  253.                         $str_link_freestyle "",
  254.                         $str_target ""
  255.                       )
  256.    {
  257.      $tmp_a_obj =new HTMLLink(
  258.                           $str_href,
  259.                           $str_label,
  260.                           $str_link_style_class
  261.                                );
  262.      $tmp_a_obj->setFreeStyle$str_link_freestyle );
  263.      
  264.      $this->str_value_arr[$str_value;
  265.      
  266.      return parent::addElement(
  267.                         $tmp_a_obj,
  268.                         $str_style_class,
  269.                         $str_freestyle,
  270.                         (
  271.                           preg_match"!^javascript:!i"$str_href )
  272.                           ? preg_replace"!^javascript:!i"""$str_href )
  273.                           : ""
  274.                         )
  275.                               );
  276.    }
  277.  
  278.  
  279.  
  280.    /**
  281.     * Removes the element at $int-index. All elements behind the deleted element
  282.     * moving up by one position.
  283.     *
  284.     * @version 1.11
  285.     * @since   0.1.0
  286.     * @author  Daniel Plücken <daniel@debakel.net>
  287.     * @access  public
  288.     * @param   integer $int Index of the element to remove.
  289.     * @return  void 
  290.     */
  291.    function deleteElementAt&$int )
  292.    {
  293.      parent::deleteElementAt$int );
  294.      
  295.      array_splice$this->str_style_on_mouseup_arr$int);
  296.      array_splice$this->str_style_on_mouseover_arr$int);
  297.      array_splice$this->str_value_arr$int);
  298.    }
  299.  
  300.  
  301.  
  302.    /**
  303.     * Returns a generated string based on the attributes of this HTML-Object.
  304.     *
  305.     * @version 1.2
  306.     * @since   0.1.0
  307.     * @author  Daniel Plücken <daniel@debakel.net>
  308.     * @access  public
  309.     * @return  string 
  310.     */
  311.    function get()
  312.    {
  313.       foreach $this->str_style_on_mouseup_arr as $key => $value )
  314.       {
  315.          if !preg_match"!;$!"$this->mouseup_arr[$key) )
  316.             $this->mouseup_arr[$key.= ";";
  317.          
  318.          $this->mouseup_arr[$key.= "this.className='".$value."'";
  319.       }
  320.       
  321.       foreach $this->str_style_on_mouseover_arr as $key => $value )
  322.       {
  323.          if !preg_match"!;$!"$this->mouseover_arr[$key) )
  324.             $this->mouseover_arr[$key.= ";";
  325.          
  326.          $this->mouseover_arr[$key.= "this.className='".$value."'";
  327.       }
  328.       
  329.       for $i 0$i count$this->list_arr )$i++ )
  330.           $this->list_arr[$i]->href preg_replace(
  331.                      "!\[value\]!i",
  332.                      rawurlencode$this->str_value_arr[$i),
  333.                      $this->list_arr[$i]->href
  334.                                                   );
  335.       
  336.       foreach $this->str_style_on_mouseover_arr as $key => $value )
  337.          if $this->str_value_arr[$key== $this->str_selected_value )
  338.             $style_class_arr[$key$this->str_selected_style;
  339.       
  340.       return parent::get();
  341.    }
  342. // End of class WebsiteNavigation
  343. ?>

Documentation generated on Thu, 05 Jun 2008 19:15:41 +0200 by phpDocumentor 1.4.1