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

Source for file HTMLImage.class.php

Documentation is available at HTMLImage.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 basic class of all HTML-tags.
  20.  */
  21. require_onceCLASSPATH."html/ABSTSourceObject.class.php" );
  22.  
  23. /**
  24.  * Creating HTML-Images
  25.  *
  26.  * @package   html
  27.  * @version   0.1.51
  28.  * @author    Daniel Plücken <daniel@debakel.net>
  29.  * @license   http://www.gnu.org/copyleft/lesser.html
  30.  *             GNU Lesser General Public License
  31.  * @copyright Copyright (c) 2004 Daniel Plücken <daniel@debakel.net>
  32.  *
  33.  *  This library is free software; you can redistribute it and/or
  34.  *  modify it under the terms of the GNU Lesser General Public
  35.  *  License as published by the Free Software Foundation; either
  36.  *  version 2.1 of the License.
  37.  *
  38.  *  This library is distributed in the hope that it will be useful,
  39.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  40.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  41.  *  GNU Lesser General Public License for more details.
  42.  *
  43.  *  You should have received a copy of the GNU Lesser General
  44.  *  Public License along with this library; if not, write to the
  45.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  46.  *  Boston, MA 02111-1307 USA
  47.  */
  48. class HTMLImage extends ABSTSourceObject
  49. {
  50.    /**
  51.     * The alt-attribute of the image-tag.
  52.     *
  53.     * @var    string $alt 
  54.     * @access public
  55.     */
  56.    var $alt;
  57.    /**
  58.     * The title-attribute of the image-tag.
  59.     *
  60.     * @var    string $title 
  61.     * @access public
  62.     */
  63.    var $title;
  64.    /**
  65.     * The path of the source to the image on mouseover.
  66.     *
  67.     * @var    boolean $over_src_set 
  68.     * @access public
  69.     */
  70.    var $over_src_set  = false;
  71.    /**
  72.     * Stores the value of the border-attribute of this image.
  73.     *
  74.     * @var   integer $border 
  75.     *  access public
  76.     */
  77.    var $border;
  78.    /**
  79.     * Stores whether the image should be a gallery image.
  80.     *
  81.     * @var   boolean $gallery_img 
  82.     *  access public
  83.     */
  84.    var $gallery_img = false;
  85.  
  86.  
  87.  
  88.    /**
  89.     * Constructor
  90.     * Note: you can set the value of $validate_path for last parameter; you
  91.     *       don't need to give values of $width, $height or $border if they have
  92.     *       no value!
  93.     *
  94.     * @version 1.1
  95.     * @since   0.1.0
  96.     * @author  Daniel Plücken <daniel@debakel.net>
  97.     * @access  public
  98.     * @param   string  $src    Source of the image.
  99.     * @param   integer $width 
  100.     * @param   integer $height 
  101.     * @param   boolean $validate_path 
  102.     * @return  void 
  103.     */
  104.    function HTMLImage(
  105.                         $src$width 0$height 0,
  106.                         $border 0$validate_path true
  107.                      )
  108.    {
  109.      // Get the value of $validate_path. Do not check the first parameter!
  110.      for $i 1$i func_num_args()$i++ )
  111.        if is_boolfunc_get_arg$i ) ) )
  112.        {
  113.          $validate_path func_get_arg$i );
  114.          break;
  115.        }
  116.  
  117.      $this->setSRC$src$validate_path );
  118.      $this->setWidth$width );
  119.      $this->setHeight$height );
  120.      $this->setBorder$border );
  121.    }
  122.  
  123.  
  124.  
  125.    /**
  126.     * Sets the source of this image.
  127.     *
  128.     * @version 1.4
  129.     * @since   0.1.0
  130.     * @author  Daniel Plücken <daniel@debakel.net>
  131.     * @access  public
  132.     * @param   string  $string 
  133.     * @param   boolean $validate_path 
  134.     * @return  void 
  135.     */
  136.    function setSRC$string$validate_path true )
  137.    {
  138.      if (
  139.           !$validate_path
  140.        || preg_match"!\.(?:gif|jpg|jpeg|png)$!i"$string )
  141.         )
  142.         parent::setSRC$string$validate_path );
  143.      else
  144.      if !empty$string ) )
  145.      {
  146.         echo "<pre>\r\n";
  147.         echo "<b>The value \"".$string."\" is not valid for the source of an "
  148.             ."image.<br>"
  149.             ."The value has to be a path to an image!</b><br>\r\n";
  150.         $debugArr debug_backtrace();
  151.         print_r$debugArr[count$debugArr )-1);
  152.         echo "</pre>\r\n";
  153.  
  154.         exit();
  155.      }
  156.    }
  157.  
  158.  
  159.  
  160.    /**
  161.     * Sets the source of this image on mouseover.
  162.     *
  163.     * @version 1.0
  164.     * @since   0.1.2
  165.     * @author  Daniel Plücken <daniel@debakel.net>
  166.     * @access  public
  167.     * @param   string $string 
  168.     * @return  void 
  169.     */
  170.    function setOverSRC$string )
  171.    {
  172.      if(
  173.          $this->over_src_set
  174.       && defined"DEBUG" )
  175.        )
  176.      {
  177.        echo "<pre>\r\n";
  178.        echo "<b>The over state of this image is already set.</b><br>\r\n";
  179.        $debugArr debug_backtrace();
  180.        print_r$debugArr[count$debugArr )-1);
  181.        echo "</pre>\r\n";
  182.  
  183.        exit();
  184.      }
  185.  
  186.      if(
  187.          preg_match(
  188.                       "!^(?:[-._A-Za-z0-9]+/)*"
  189.                         ."[-._A-Za-z0-9]+\."
  190.                      ."(?:gif|jpg|jpeg|png)$!"$string
  191.                    )
  192.        )
  193.      {
  194.        $this->mouseover = "swapImage( this, '".$string."' )"
  195.                          .$this->mouseover;
  196.        $this->mouseout  = "swapImage( this, '".$this->src."' )"
  197.                          .$this->mouseout;
  198.        $this->over_src_set = true;
  199.      }
  200.      else
  201.      if!empty$string ) )
  202.      {
  203.        echo "<pre>\r\n";
  204.        echo "<b>The value \"".$string."\" is not valid for the source of an "
  205.            ."image.<br>"
  206.            ."The value has to be a path to an image!</b><br>\r\n";
  207.        $debugArr debug_backtrace();
  208.        print_r$debugArr[count$debugArr )-1);
  209.        echo "</pre>\r\n";
  210.  
  211.        exit();
  212.      }
  213.    }
  214.  
  215.  
  216.  
  217.    /**
  218.     * Sets the border of this image.
  219.     *
  220.     * @version 1.0
  221.     * @since   0.1.1
  222.     * @author  Daniel Plücken <daniel@debakel.net>
  223.     * @access  public
  224.     * @param   integer $int 
  225.     * @return  void 
  226.     */
  227.    function setBorder$int )
  228.    {
  229.      ifpreg_match"!^".UNSIGNEDINTEGER."$!"$int ) )
  230.        $this->border = $int;
  231.      else
  232.        die(
  233.             "The value \"".$int."\" is not valid for the border of an "
  234.            ."image.<br>"
  235.            ."The value has to be a number!"
  236.           );
  237.    }
  238.  
  239.  
  240.  
  241.    /**
  242.     * Sets the alt-attribute of this image.
  243.     *
  244.     * @version 1.0
  245.     * @since   0.1.0
  246.     * @author  Daniel Plücken <daniel@debakel.net>
  247.     * @access  public
  248.     * @param   string $string 
  249.     * @return  void 
  250.     */
  251.    function setAlt$string "" )
  252.    {
  253.      $this->alt = $string;
  254.      $this->setTitle$stringtrue );
  255.    }
  256.  
  257.  
  258.  
  259.    /**
  260.     * Sets the title-attribute of this image.
  261.     *
  262.     * @version 1.0
  263.     * @since   0.1.5
  264.     * @author  Daniel Plücken <daniel@debakel.net>
  265.     * @access  public
  266.     * @param   string $string 
  267.     * @param   string $invoke_from_alt 
  268.     * @return  void 
  269.     */
  270.    function setTitle$string ""$invoke_from_alt false )
  271.    {
  272.       static $tset false;
  273.  
  274.       if (
  275.            !$tset
  276.         || !$invoke_from_alt
  277.          )
  278.          $this->title $string;
  279.  
  280.       $tset false;
  281.    }
  282.  
  283.  
  284.  
  285.    /**
  286. /**
  287.     * Returns a javascript-function to swap a given image to given source.
  288.     *
  289.     * @static
  290.     * @version 1.0
  291.     * @since   0.1.8
  292.     * @author  Daniel Plücken <daniel@debakel.net>
  293.     * @access  public
  294.     * @param   boolean $withJSdeclaration 
  295.     * @return  string 
  296.     */
  297.    function getJS2swapImages$withJSdeclaration false )
  298.    {
  299.       if!$withJSdeclaration )
  300.         $out JavaScript::getInArray();
  301.       else
  302.       {
  303.         $js new Javascript();
  304.         $js->setInArray();
  305.       }
  306.  
  307.       # Put this function in the onMouseup-attribute of the img-tag!
  308.       # Use this function never before using the function swapImage,
  309.       # this will cause no changing-effect.
  310.       $js1 "  stateIMG = undefined;\r\n"
  311.             ."  imgObj = new Array();\r\n"
  312.             ."  function swapImage( which, path )\r\n"
  313.             ."  {\r\n"
  314.             ."    if( !in_array( which, imgObj ) )\r\n"
  315.             ."    {\r\n"
  316.             ."      imgObj[imgObj.length] = new Array();\r\n"
  317.             ."      imgObj[imgObj.length - 1][0] = which;\r\n"
  318.             ."      imgObj[imgObj.length - 1][1] = which.src;\r\n"
  319.             ."    }\r\n\r\n"
  320.  
  321.             ."    if( !stateIMG || which != stateIMG )\r\n"
  322.             ."      which.src = path;\r\n"
  323.             ."  }\r\n\r\n";
  324.  
  325.       $js2 "  function stateImage( which )\r\n"
  326.             ."  {\r\n"
  327.             ."    for( i = 0; i < imgObj.length; i++ )\r\n"
  328.             ."       if( imgObj[i][0] == stateIMG )\r\n"
  329.             ."       {\r\n"
  330.             ."          imgObj[i][0].src = imgObj[i][1];\r\n"
  331.             ."          break;\r\n"
  332.             ."       }\r\n\r\n"
  333.             ."    stateIMG = which;\r\n"
  334.             ."  }\r\n\r\n";
  335.  
  336.       # Put this function in the onMouseout-attribute of the img-tag!
  337.       $js3 "  function restoreImage( which )\r\n"
  338.             ."  {\r\n"
  339.             ."    for( i = 0; i < imgObj.length; i++ )\r\n"
  340.             ."       if( which != stateIMG "
  341.                     ."&& imgObj[i][0] == which )\r\n"
  342.             ."       {\r\n"
  343.             ."          imgObj[i][0].src = imgObj[i][1];\r\n"
  344.             ."          return;\r\n"
  345.             ."       }\r\n"
  346.             ."  }\r\n\r\n";
  347.  
  348.       if!$withJSdeclaration )
  349.         $out .= $js1.$js2.$js3;
  350.       else
  351.       {
  352.         $js->add$js1 );
  353.         $js->add$js2 );
  354.         $js->add$js3 );
  355.         $out $js->get();
  356.       }
  357.  
  358.       return $out;
  359.    }
  360.  
  361.  
  362.  
  363.    /**
  364.     * Returns a generated string based on the attributes of this HTML-Object.
  365.     *
  366.     * @version 1.43
  367.     * @since   0.1.0
  368.     * @author  Daniel Plücken <daniel@debakel.net>
  369.     * @access  public
  370.     * @return  string 
  371.     */
  372.    function get()
  373.    {
  374.       static $overJSoutput false;
  375.  
  376.       $out "";
  377.       if(
  378.           !$overJSoutput
  379.        && preg_match "!swapImage\(!"$this->mouseover )
  380.         )
  381.       {
  382.         if class_exists"HTMLDocument"  ) )
  383.            $GLOBALS["javascript_content"][HTMLImage::getJS2swapImages();
  384.         else
  385.            $out .= HTMLImage::getJS2swapImagestrue );
  386.  
  387.         $overJSoutput true;
  388.       }
  389.  
  390.       $out .= "<img alt=\"".$this->alt."\" "
  391.                      .!empty$this->title )
  392.                         ? "title=\"".$this->title."\" "
  393.                         : ""
  394.                       )
  395.                      .!empty$this->src )
  396.                         ? "src=\"".$this->src."\" "
  397.                         : ""
  398.                       )
  399.                      .(
  400.                         (
  401.                           !empty$this->width )
  402.                        && preg_match"!^".UNSIGNEDINTEGER."%?$!"$this->width )
  403.                         )
  404.                         ? "width=\"".$this->width."\" "
  405.                         : ""
  406.                       )
  407.                      .(
  408.                         (
  409.                           !empty$this->height )
  410.                        && preg_match"!^".UNSIGNEDINTEGER."%?$!"$this->height )
  411.                         )
  412.                         ? "height=\"".$this->height."\" "
  413.                         : ""
  414.                       )
  415.                      .(
  416.                         $this->gallery_img
  417.                         ? ""
  418.                         : "galleryimg=\"no\" "
  419.                       )
  420.                      .!empty$this->name )
  421.                         ? "name=\"".$this->name."\" "
  422.                         : ""
  423.                       )
  424.                      .!empty$this->id )
  425.                         ? "id=\"".$this->id."\" "
  426.                         : ""
  427.                       )
  428.                      .!empty$this->style_class )
  429.                         ? "class=\"".$this->style_class."\" "
  430.                         : ""
  431.                       )
  432.                      .!empty$this->click )
  433.                         ? "onClick=\"".$this->click."\" "
  434.                         : ""
  435.                       )
  436.                      .!empty$this->mouseup )
  437.                         ? "onMouseup=\"".$this->mouseup."\" "
  438.                         : ""
  439.                       )
  440.                      .!empty$this->mouseout )
  441.                         ? "onMouseout=\"".$this->mouseout."\" "
  442.                         : ""
  443.                       )
  444.                      .!empty$this->mouseover )
  445.                         ? "onMouseover=\"".$this->mouseover."\" "
  446.                         : ""
  447.                       )
  448.                      .!empty$this->freestyle )
  449.                         ? "style=\"".$this->freestyle."\" "
  450.                         : ""
  451.                       )
  452.                      .preg_match"!^".UNSIGNEDINTEGER."$!"$this->border )
  453.                         ? "border=\"".$this->border."\" "
  454.                         : ""
  455.                       )
  456.                      .!empty$this->other_attributes )
  457.                         ? " ".$this->other_attributes." "
  458.                         : ""
  459.                       )
  460.              ."/>";
  461.  
  462.       return $out;
  463.    }
  464. // End of class HTMLImages
  465. ?>

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