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

Source for file NewsTicker.class.php

Documentation is available at NewsTicker.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.  * A pool of regular expressions.
  20.  */
  21. require_onceCLASSPATH."html/HTMLLayer.class.php" );
  22.  
  23. /**
  24.  * 
  25.  */
  26. require_onceCLASSPATH."html/JavaScript.class.php" );
  27.  
  28. /**
  29.  * A class to generate "<div>"-Layer-News-Ticker.
  30.  *
  31.  * @package   html
  32.  * @version   1.0
  33.  * @author    Daniel Plücken <daniel@debakel.net>
  34.  * @license   http://www.gnu.org/copyleft/lesser.html
  35.  *             GNU Lesser General Public License
  36.  * @copyright Copyright (c) 2005 Daniel Plücken <daniel@debakel.net>
  37.  *
  38.  *  This library is free software; you can redistribute it and/or
  39.  *  modify it under the terms of the GNU Lesser General Public
  40.  *  License as published by the Free Software Foundation; either
  41.  *  version 2.1 of the License.
  42.  *
  43.  *  This library is distributed in the hope that it will be useful,
  44.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  45.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  46.  *  GNU Lesser General Public License for more details.
  47.  *
  48.  *  You should have received a copy of the GNU Lesser General
  49.  *  Public License along with this library; if not, write to the
  50.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  51.  *  Boston, MA 02111-1307 USA
  52.  */
  53. class NewsTicker extends HTMLLayer
  54. {
  55.   /**
  56.    * @var string $ticker_text 
  57.    */
  58.   var $ticker_text =
  59.   "This is the standard ticker text! Please give an custom text.";
  60.   /**
  61.    * @var integer $clip_width 
  62.    */
  63.   var $clip_width = 200;
  64.   /**
  65.    * @var integer $clip_height 
  66.    */
  67.   var $clip_height = 15;
  68.   /**
  69.    * @var integer $gap 
  70.    */
  71.   var $gap = 20;
  72.   /**
  73.    * @var integer $step_width 
  74.    */
  75.   var $step_width = 1;
  76.   /**
  77.    * @var integer $refresh_rate 
  78.    */
  79.   var $refresh_rate = 25;
  80.   /**
  81.    * @var string $name_suffix 
  82.    */
  83.   var $name_suffix = "";
  84.   /**
  85.    * @var boolean $use_marquee 
  86.    */
  87.   var $use_marquee = true;
  88.   
  89.   /**
  90.    * Constructor.
  91.    *
  92.    * @version 1.0
  93.    * @since   1.0
  94.    * @author  Daniel Plücken <daniel@debakel.net>
  95.    * @access  public
  96.    * @param   $ticker_text 
  97.    * @param   $style_class 
  98.    * @param   $name        The value of the name- and id-attribute of the layer.
  99.    * @return  void 
  100.    */
  101.   function NewsTicker$ticker_text$name "DPTicker" )
  102.   {
  103.     $this->id = "tickerlayout".$name;
  104.     $this->name = "tickerlayout".$name;
  105.     $this->name_suffix = $name;
  106.     $this->ticker_text = $ticker_text;
  107.   }
  108.  
  109.  
  110.  
  111.   /**
  112.    * Stores the value of this tag's "name"-attribute with the suffix
  113.    * "tickerlayout_".
  114.    *
  115.    * @version 1.0
  116.    * @since   1.0
  117.    * @author  Daniel Plücken <daniel@debakel.net>
  118.    * @access  public
  119.    * @param   string $string 
  120.    * @return  void 
  121.    */
  122.   function setName$string )
  123.   $this->name = "tickerlayout".$string}
  124.  
  125.  
  126.  
  127.   /**
  128.    * Stores the text of this ticker text.
  129.    *
  130.    * @version 1.0
  131.    * @since   1.0
  132.    * @author  Daniel Plücken <daniel@debakel.net>
  133.    * @access  public
  134.    * @param   string $string 
  135.    * @return  void 
  136.    */
  137.   function setText$string )
  138.   $this->ticker_text = $string}
  139.  
  140.  
  141.  
  142.   /**
  143.    * Stores the value of this item's "id"-attribute with the suffix
  144.    * "tickerlayout_".
  145.    *
  146.    * @version 1.0
  147.    * @since   1.0
  148.    * @author  Daniel Plücken <daniel@debakel.net>
  149.    * @access  public
  150.    * @param   string $string 
  151.    * @return  void 
  152.    */
  153.   function setId$string )
  154.   $this->id = "tickerlayout".$string}
  155.  
  156.  
  157.  
  158.   /**
  159.    * Stores the step width in pixel per each refresh of the ticker.
  160.    *
  161.    * @version 1.0
  162.    * @since   1.0
  163.    * @author  Daniel Plücken <daniel@debakel.net>
  164.    * @access  public
  165.    * @param   integer $int 
  166.    * @return  void 
  167.    */
  168.   function setStepWidth$int )
  169.   {
  170.     if preg_match"!^".INTEGER."$!"$int ) )
  171.        $this->step_width = $int;
  172.   }
  173.  
  174.  
  175.  
  176.   /**
  177.    * Stores the period in milliseconds between the refreshes of the ticker.
  178.    *
  179.    * @version 1.0
  180.    * @since   1.0
  181.    * @author  Daniel Plücken <daniel@debakel.net>
  182.    * @access  public
  183.    * @param   integer $int 
  184.    * @return  void 
  185.    */
  186.   function setRefreshRate$int )
  187.   {
  188.     if preg_match"!^".INTEGER."$!"$int ) )
  189.        $this->refresh_rate = $int;
  190.   }
  191.  
  192.  
  193.  
  194.   /**
  195.    * Stores the width of the ticker.
  196.    *
  197.    * @version 1.0
  198.    * @since   1.0
  199.    * @author  Daniel Plücken <daniel@debakel.net>
  200.    * @access  public
  201.    * @param   integer $int 
  202.    * @return  void 
  203.    */
  204.   function setWidth$int )
  205.   {
  206.     if preg_match"!^".INTEGER."$!"$int ) )
  207.        $this->clip_width = $int;
  208.   }
  209.  
  210.  
  211.  
  212.   /**
  213.    * Stores the height of the ticker.
  214.    *
  215.    * @version 1.0
  216.    * @since   1.0
  217.    * @author  Daniel Plücken <daniel@debakel.net>
  218.    * @access  public
  219.    * @param   integer $int 
  220.    * @return  void 
  221.    */
  222.   function setHeight$int )
  223.   {
  224.     if preg_match"!^".INTEGER."$!"$int ) )
  225.        $this->clip_height = $int;
  226.   }
  227.  
  228.  
  229.  
  230.   /**
  231.    * Stores the gap between the two text-<div> of the ticker. This function is
  232.    * an alias for the function setGap().
  233.    *
  234.    * @version 1.0
  235.    * @since   1.0
  236.    * @author  Daniel Plücken <daniel@debakel.net>
  237.    * @access  public
  238.    * @param   integer $int 
  239.    * @return  void 
  240.    */
  241.   function setGapBetweenText$int )
  242.   $this->setGap$int )}
  243.  
  244.  
  245.  
  246.   /**
  247.    * Stores the gap between the two text-<div> of the ticker.
  248.    *
  249.    * @version 1.0
  250.    * @since   1.0
  251.    * @author  Daniel Plücken <daniel@debakel.net>
  252.    * @access  public
  253.    * @param   integer $int 
  254.    * @return  void 
  255.    */
  256.   function setGap$int )
  257.   {
  258.     if preg_match"!^".INTEGER."$!"$int ) )
  259.        $this->gap = $int;
  260.   }
  261.  
  262.  
  263.  
  264.   /**
  265.    * Returns a generated string based on the attributes of this HTML-Object.
  266.    *
  267.    * @version 1.0
  268.    * @since   1.0
  269.    * @author  Daniel Plücken <daniel@debakel.net>
  270.    * @access  public
  271.    * @return  string 
  272.    */
  273.   function get()
  274.   {
  275.     if$this->use_marquee )
  276.     {
  277.       return "  <style type=\"text/css\">\r\n"
  278.             ."  #ticker_".$this->name_suffix."\r\n"
  279.             ."  {\r\n"
  280.             ."     width: ".(
  281.                               empty$this->clip_width )
  282.                               ? "100%"
  283.                               : $this->clip_width."px"
  284.                             ).";\r\n"
  285.             ."  }\r\n"
  286.             ."  </style>\r\n"
  287.             ."  <marquee id=\"ticker_".$this->name_suffix."\" "
  288.                        ."scrollamount=\"".$this->step_width."\" "
  289.                        ."scrolldelay=\"".$this->refresh_rate."\">\r\n"
  290.              .$this->ticker_text."\r\n"
  291.             ."  </marquee>\r\n";
  292.     }
  293.     else
  294.     {
  295.       $js new JavaScript();
  296.       
  297.       $js->add(
  298.          "ticker_text_".$this->name_suffix." = '".$this->ticker_text."';\r\n"
  299.         ."ticker_width_".$this->name_suffix." = ".$this->clip_width.";\r\n"
  300.         ."ticker_height_".$this->name_suffix." = ".$this->clip_height.";\r\n"
  301.         ."ticker_gap2next_".$this->name_suffix." = ".$this->gap.";\r\n"
  302.         ."ticker_step_width_".$this->name_suffix." = ".$this->step_width.";\r\n"
  303.         ."ticker_refresh_rate_".$this->name_suffix." = ".$this->refresh_rate
  304.         .";\r\n\r\n"
  305.         
  306.         ."document.getElementById('tickerlayout".$this->name_suffix."')"
  307.                                                 .".style.clip =\r\n"
  308.         ."     'rect( 0, ' + ticker_width_".$this->name_suffix." + 'px, ' "
  309.                          ."+ ticker_height_".$this->name_suffix." "
  310.                                                  ."+ 'px, 0 )';\r\n\r\n"
  311.         
  312.         ."// Ticker initialization\r\n"
  313.         ."document.getElementById( 'ticker1".$this->name_suffix."' )"
  314.                        .".innerHTML = ticker_text_".$this->name_suffix.";\r\n"
  315.         ."document.getElementById( 'ticker2".$this->name_suffix."' )"
  316.                        .".innerHTML = ticker_text_".$this->name_suffix.";"
  317.                                                                     ."\r\n\r\n"
  318.         
  319.         ."ticker_text_width_".$this->name_suffix." = document.getElementById( "
  320.                         ."'ticker1".$this->name_suffix."' ).offsetWidth;"
  321.                                                                     ."\r\n\r\n"
  322.         
  323.         ."document.getElementById('ticker1".$this->name_suffix."')"
  324.                                        .".style.position = 'relative';\r\n"
  325.         ."document.getElementById('ticker2".$this->name_suffix."')"
  326.                                        .".style.position = 'relative';\r\n"
  327.         ."document.getElementById('ticker1".$this->name_suffix."')"
  328.                                        .".style.display = 'inline';\r\n"
  329.         ."document.getElementById('ticker2".$this->name_suffix."')"
  330.                                        .".style.display = 'inline';\r\n"
  331.         ."document.getElementById('ticker1".$this->name_suffix."')"
  332.                                        .".style.left = '0';\r\n"
  333.         ."document.getElementById('ticker2".$this->name_suffix."')"
  334.                      .".style.left = ticker_gap2next_".$this->name_suffix
  335.                                                           ." + 'px';\r\n\r\n"
  336.         ."function tick".$this->name_suffix."()\r\n"
  337.         ."{\r\n"
  338.         ."  pos_x_1_".$this->name_suffix." = parseInt( document.getElementById"
  339.                         ."('ticker1".$this->name_suffix."').style.left );\r\n"
  340.         ."  pos_x_2_".$this->name_suffix." = parseInt( document.getElementById"
  341.                         ."('ticker2".$this->name_suffix."').style.left );\r\n"
  342.         
  343.         ."  if ( ticker_text_width_".$this->name_suffix." < "
  344.                ."pos_x_1_".$this->name_suffix." * -1 )\r\n"
  345.         ."     pos_x_1_".$this->name_suffix." = pos_x_2_".$this->name_suffix." "
  346.                                ."+ ticker_text_width_".$this->name_suffix."*2 "
  347.                                ."+ ticker_gap2next_".$this->name_suffix." + 6;"
  348.                                                                      ."\r\n\r\n"
  349.       
  350.         ."  if ( ticker_text_width_".$this->name_suffix."*2 < "
  351.                ."pos_x_2_".$this->name_suffix." * -1 )\r\n"
  352.         ."     pos_x_2_".$this->name_suffix." = pos_x_2_".$this->name_suffix." "
  353.                              ."+ (ticker_text_width_".$this->name_suffix." "
  354.                              ."+ ticker_gap2next_".$this->name_suffix.")*2 + 6;"
  355.                                                                   ."\r\n\r\n"
  356.       
  357.         ."  document.getElementById( 'ticker1".$this->name_suffix."' )"
  358.                                                               .".style.left = "
  359.             ."pos_x_1_".$this->name_suffix." - ticker_step_width_"
  360.                                                      .$this->name_suffix.";\r\n"
  361.         ."  document.getElementById( 'ticker2".$this->name_suffix."' )"
  362.                                                               .".style.left = "
  363.             ."pos_x_2_".$this->name_suffix." - ticker_step_width_"
  364.                                                      .$this->name_suffix.";"
  365.                                                                      ."\r\n\r\n"
  366.         ."}\r\n\r\n"
  367.         
  368.         ."inv_".$this->name_suffix." = "
  369.         ."window.setInterval( 'tick".$this->name_suffix."()', "
  370.                              ."ticker_refresh_rate_".$this->name_suffix." );"
  371.                              ."\r\n"
  372.               );
  373.        
  374.        $this->setBody(
  375.                "  <div id=\"ticker1".$this->name_suffix."\">[init]</div>\r\n"
  376.               ."  <div id=\"ticker2".$this->name_suffix."\">[init]</div>\r\n"
  377.                      );
  378.        
  379.        $this->setVisible();
  380.        $this->setPosition"absolute" );
  381.        
  382.        $out  parent::get();
  383.        $out .= $js->get();
  384.        
  385.        
  386.        return $out;
  387.      }
  388.    }
  389. // END of class NewsTicker
  390. ?>

Documentation generated on Thu, 05 Jun 2008 19:14:32 +0200 by phpDocumentor 1.4.1