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

Source for file HTMLLink.class.php

Documentation is available at HTMLLink.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.  */
  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 base class for html-tags.
  20.  */
  21. require_onceCLASSPATH."html/ABSTHTMLTag.class.php" );
  22.  
  23. /**
  24.  *
  25.  */
  26. include_onceCLASSPATH."html/JavaScript.class.php" );
  27.  
  28. /**
  29.  * Creating HTML-Tags
  30.  *
  31.  * @package html
  32.  * @final
  33.  * @version   0.2.01
  34.  * @author    Daniel Plücken <daniel@debakel.net>
  35.  * @license   http://www.gnu.org/copyleft/lesser.html
  36.  *             GNU Lesser General Public License
  37.  * @copyright Copyright (c) 2004 Daniel Plücken <daniel@debakel.net>
  38.  *
  39.  *  This library is free software; you can redistribute it and/or
  40.  *  modify it under the terms of the GNU Lesser General Public
  41.  *  License as published by the Free Software Foundation; either
  42.  *  version 2.1 of the License.
  43.  *
  44.  *  This library is distributed in the hope that it will be useful,
  45.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  46.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  47.  *  GNU Lesser General Public License for more details.
  48.  *
  49.  *  You should have received a copy of the GNU Lesser General
  50.  *  Public License along with this library; if not, write to the
  51.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  52.  *  Boston, MA 02111-1307 USA
  53.  */
  54. class HTMLLink extends ABSTHTMLTag
  55. {
  56.    /**
  57.     * @var    string $href 
  58.     * @access public
  59.     */
  60.    var $href;
  61.    /**
  62.     * @var    string $label 
  63.     * @access public
  64.     */
  65.    var $label;
  66.    /**
  67.     * @var    string $target 
  68.     * @access public
  69.     */
  70.    var $target;
  71.    /**
  72.     * @var    string $str_parameter_add_on_mouseover 
  73.     * @access public
  74.     */
  75.  
  76.  
  77.  
  78.    /**
  79.     * Constructor.
  80.     *
  81.     * @version 1.2
  82.     * @since   0.1.0
  83.     * @author  Daniel Plücken <daniel@debakel.net>
  84.     * @access  public
  85.     * @param   string $href        The value of the href-attribute of this
  86.     *                               anker.
  87.     * @param   string $label       The label of this anker.
  88.     * @param   string $style_class 
  89.     * @param   string $target 
  90.     * @return  void 
  91.     */
  92.    function HTMLLink$href$label$style_class ""$target "" )
  93.    {
  94.      $this->href        = $href;
  95.      $this->label       = $label;
  96.      $this->style_class = $style_class;
  97.      $this->target      = $target;
  98.    }
  99.  
  100.  
  101.  
  102.    /**
  103.     * Sets the value of the href-attribute of this link.
  104.     *
  105.     * @version 1.0
  106.     * @since   0.1.0
  107.     * @author  Daniel Plücken <daniel@debakel.net>
  108.     * @access  public
  109.     * @param   string $string The value of the href-attribute of this anker.
  110.     * @return  void 
  111.     */
  112.    function setHREF$string )
  113.    $this->href = $string}
  114.  
  115.  
  116.  
  117.    /**
  118.     * Sets the label of this link.
  119.     *
  120.     * @version 1.0
  121.     * @since   0.1.0
  122.     * @author  Daniel Plücken <daniel@debakel.net>
  123.     * @access  public
  124.     * @param   string $string The value of the label of this anker.
  125.     * @return  void 
  126.     */
  127.    function setLabel$string )
  128.    $this->label = $string}
  129.  
  130.  
  131.  
  132.    /**
  133.     * Sets the target of this link.
  134.     *
  135.     * @version 1.0
  136.     * @since   0.1.6
  137.     * @author  Daniel Plücken <daniel@debakel.net>
  138.     * @access  public
  139.     * @param   string $string The value of the label of this anker.
  140.     * @return  void 
  141.     */
  142.    function setTarget$string )
  143.    $this->target = $string}
  144.  
  145.  
  146.  
  147.    /**
  148.     * Sets the mouseup that should add to all anker, that is defined in a
  149.     * script. It will concatenate befor the instance specified mouseup.
  150.     *
  151.     * @version 1.0
  152.     * @since   0.1.8
  153.     * @static
  154.     * @author  Daniel Plücken <daniel@debakel.net>
  155.     * @access  public
  156.     * @param   string $str_mouse_up The static value of "onMouseup"-Attribute.
  157.     * @return  string 
  158.     */
  159.    function manageStaticMouseUp$str_mouse_up "" )
  160.    {
  161.       static $str_stat_mouse_up "";
  162.  
  163.       if !empty$str_mouse_up ) )
  164.          $str_stat_mouse_up $str_mouse_up;
  165.  
  166.       return $str_stat_mouse_up;
  167.    }
  168.  
  169.  
  170.  
  171.    /**
  172.     * Sets the parameter that should be add on each link by a javascript on
  173.     * mouseover. This is useful to carry a session-id through all scripts.
  174.     *
  175.     * @version 1.0
  176.     * @since   0.2.0
  177.     * @static
  178.     * @author  Daniel Plücken <daniel@debakel.net>
  179.     * @access  public
  180.     * @param   string $str_mouse_up The static value of "onMouseup"-Attribute.
  181.     * @return  string 
  182.     */
  183.    function manageStaticParameterAdd$str_parameter_add "" )
  184.    {
  185.       static $str_stat_parameter_add "";
  186.  
  187.       if !empty$str_parameter_add ) )
  188.          $str_stat_parameter_add $str_parameter_add;
  189.  
  190.       return $str_stat_parameter_add;
  191.    }
  192.  
  193.  
  194.  
  195.    /**
  196.     * Adds a javascript that adds parameter to the hyper reference of this
  197.     * anker. This is useful for search engine optimated sites. For example you
  198.     * can add a session-id or parameter that should hide from search-spiders.
  199.     *
  200.     * @version 1.0
  201.     * @since   0.1.9
  202.     * @static
  203.     * @author  Daniel Plücken <daniel@debakel.net>
  204.     * @access  public
  205.     * @param   string $withJSdeclaration 
  206.     * @return  void 
  207.     */
  208.    function getJavaScriptToAddParameterToHREF$withJSdeclaration false )
  209.    {
  210.       static $alreadyIncluded false;
  211.  
  212.       if !$alreadyIncluded )
  213.       {
  214.          $str_out = <<<JSCODE
  215.   function addParameter( which_obj, str_param )
  216.   {
  217.      if ( which_obj.getAttribute( 'parameterAdded' ) != 'true' )
  218.      {
  219.         str_href = which_obj.getAttribute( 'href' );
  220.         which_obj.setAttribute( 'href', str_href + str_param );
  221.         which_obj.setAttribute( 'parameterAdded', 'true' );
  222.      }
  223.   }
  224.  
  225. JSCODE;
  226.  
  227.          if $withJSdeclaration === true )
  228.          {
  229.             $js new JavaScript();
  230.             $js->add$str_out );
  231.  
  232.             $str_out $js->get();
  233.          }
  234.          $alreadyIncluded true;
  235.       }
  236.  
  237.       return $str_out;
  238.    }
  239.  
  240.  
  241.  
  242.    /**
  243.     * Adds a javascript that adds parameter to the hyper reference of this
  244.     * anker. This is useful for search engine optimated sites. For example you
  245.     * can add a session-id or parameter that should hide from search-spiders.
  246.     *
  247.     * @version 1.0
  248.     * @since   0.1.9
  249.     * @author  Daniel Plücken <daniel@debakel.net>
  250.     * @access  public
  251.     * @param   string $str_parameter 
  252.     * @return  void 
  253.     */
  254.    function addParameterOnMouseOver$str_parameter )
  255.    $this->str_parameter_add_on_mouseover $str_parameter}
  256.  
  257.  
  258.  
  259.    /**
  260.     * Returns a generated string based on the attributes of this HTML-Object.
  261.     *
  262.     * @version 1.62
  263.     * @since   0.1.0
  264.     * @author  Daniel Plücken <daniel@debakel.net>
  265.     * @access  public
  266.     * @return  string 
  267.     */
  268.    function get()
  269.    {
  270.       $outputstr "";
  271.       if (
  272.            !empty$this->str_parameter_add_on_mouseover )
  273.         && $this->href != "#"
  274.          )
  275.          if class_exists"HTMLDocument"  ) )
  276.             $GLOBALS["javascript_content"][]
  277.                = $this->getJavaScriptToAddParameterToHREF();
  278.          else
  279.             $outputstr .= $this->getJavaScriptToAddParameterToHREFtrue );
  280.  
  281.       $this->idExists$this->idtrue );
  282.  
  283.  
  284.       $str_stat_mouse_up HTMLLink::manageStaticMouseUp();
  285.       if (
  286.            !empty$str_stat_mouse_up )
  287.         && strpos$this->mouseup$str_stat_mouse_up === false
  288.         && $this->href != "#"
  289.          )
  290.          $this->mouseup $str_stat_mouse_up.";".$this->mouseup;
  291.  
  292.  
  293.       $str_stat_parameter_add HTMLLink::manageStaticParameterAdd();
  294.       if (
  295.            !empty$str_stat_parameter_add )
  296.         && $this->href != "#"
  297.          )
  298.       {
  299.          if preg_match"!^[^?&]!"$str_stat_parameter_add ) )
  300.             if empty$this->str_parameter_add_on_mouseover ) )
  301.                $this->str_parameter_add_on_mouseover "?";
  302.             else
  303.                $this->str_parameter_add_on_mouseover .= "&";
  304.  
  305.  
  306.          $this->str_parameter_add_on_mouseover .= $str_stat_parameter_add;
  307.       }
  308.  
  309.  
  310.       $outputstr .= "<a ".(
  311.                             !empty$this->href )
  312.                             ? "href=\"".$this->href."\" "
  313.                             : ""
  314.                           )
  315.                      ."onFocus=\"if(this.blur)this.blur()\""
  316.                      .!empty$this->name )
  317.                         ? " name=\"".$this->name."\""
  318.                         : ""
  319.                       )
  320.                      .!empty$this->id )
  321.                         ? " id=\"".$this->id."\""
  322.                         : ""
  323.                       )
  324.                      .(
  325.                         !empty$this->freestyle )
  326.                         ? " style=\"".$this->freestyle."\""
  327.                         : ""
  328.                       )
  329.                      .!empty$this->blur )
  330.                         ? " onBlur=\"".$this->blur."\""
  331.                         : ""
  332.                       )
  333.                      .!empty$this->click )
  334.                         ? " onClick=\"".$this->click."\""
  335.                         : ""
  336.                       )
  337.                      .!empty$this->mousemove )
  338.                         ? " onMousemove=\"".$this->mousemove."\""
  339.                         : ""
  340.                       )
  341.                      .!empty$this->mouseup )
  342.                         ? " onMouseup=\"".$this->mouseup."\""
  343.                         : ""
  344.                       )
  345.                      .!empty$this->mouseout )
  346.                         ? " onMouseout=\"".$this->mouseout."\""
  347.                         : ""
  348.                       )
  349.                      .(
  350.                         !empty$this->mouseover )
  351.                      || !empty$this->str_parameter_add_on_mouseover )
  352.                         ? " onMouseover=\"".(
  353.                                  !empty$this->str_parameter_add_on_mouseover )
  354.                               && $this->href != "#"
  355.                                  ? "addParameter( "
  356.                                     ."this, '"
  357.                                     .$this->str_parameter_add_on_mouseover."'"
  358.                                              ." );"
  359.                                  : ""
  360.                                             ).$this->mouseover."\""
  361.                         : ""
  362.                       )
  363.                      .!empty$this->style_class )
  364.                         ? " class=\"".$this->style_class."\""
  365.                         : ""
  366.                       )
  367.                      .!empty$this->target )
  368.                         ? " target=\"".$this->target."\""
  369.                         : ""
  370.                       )
  371.                   .">"
  372.                   .$this->label."</a"
  373.                   .(
  374.                      $this->no_format
  375.                      ? ""
  376.                      : "\r\n"
  377.                    ).">";
  378.  
  379.       return $outputstr;
  380.    }
  381. // END of class HTMLLink
  382. ?>

Documentation generated on Thu, 05 Jun 2008 19:12:39 +0200 by phpDocumentor 1.4.1