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

Source for file URLTextInput.class.php

Documentation is available at URLTextInput.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    forms
  9.  * @subpackage items
  10.  */
  11.  
  12. if!defined"CLASSPATH" ) )
  13. {
  14.   echo "<h3>You have to define the constant CLASSPATH!</h3>\r\n";
  15.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\r\n";
  16.   exit();
  17. }
  18.  
  19. if defined"LANG" ) )
  20.    /**
  21.     * Including language specific messages.
  22.     */
  23.    include CLASSPATH."/forms/items/URLTextInput/".LANG.".inc.php";
  24. else
  25. {
  26.    echo "<h3>You have to define the constant LANG!</h3>\n";
  27.    echo "Example for german: define( 'LANG', 'de' );\n";
  28.    exit();
  29. }
  30.  
  31. /**
  32.  *
  33.  */
  34. require_once CLASSPATH."forms/items/HTMLTextInput.class.php";
  35.  
  36. /**
  37.  * A class to generate text input fields that can only carry URLs.
  38.  *
  39.  * @package    forms
  40.  * @subpackage items
  41.  * @version    0.1.0
  42.  * @since      0.9.0.9
  43.  * @author     Daniel Plücken <daniel@debakel.net>
  44.  * @license    http://www.gnu.org/copyleft/lesser.html
  45.  *              GNU Lesser General Public License
  46.  * @copyright  Copyright (C) 2006 Daniel Pluecken <daniel@debakel.net>
  47.  *
  48.  *  This library is free software; you can redistribute it and/or
  49.  *  modify it under the terms of the GNU Lesser General Public
  50.  *  License as published by the Free Software Foundation; either
  51.  *  version 2.1 of the License.
  52.  *
  53.  *  This library is distributed in the hope that it will be useful,
  54.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  55.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  56.  *  GNU Lesser General Public License for more details.
  57.  *
  58.  *  You should have received a copy of the GNU Lesser General
  59.  *  Public License along with this library; if not, write to the
  60.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  61.  *  Boston, MA 02111-1307 USA
  62.  */
  63. class URLTextInput extends HTMLTextInput
  64. {
  65.    /**
  66.     * Carries all prefixes for the protocol that are allowed to put in the
  67.     * textfield, like "http://" or/and "ftp://" etc.
  68.     * 
  69.     * @var    array  $protocol_prefix_arr 
  70.     * @access public
  71.     */
  72.    var $protocol_prefix_arr = array" " );
  73.    
  74.    
  75.    /**
  76.     * Constructor
  77.     *
  78.     * @version 1.0
  79.     * @since   0.1.0
  80.     * @author  Daniel Plücken <daniel@debakel.net>
  81.     * @access  public
  82.     * @param   string  $name 
  83.     * @param   string  $value 
  84.     * @param   integer $size 
  85.     */
  86.    function URLTextInput$name$value ""$size "" )
  87.    parent::HTMLTextInput$name$value$size255 )}
  88.  
  89.  
  90.  
  91.    /**
  92.     * Stores the value of this item's "onBlur"-attribute.
  93.     *
  94.     * @version 1.0
  95.     * @since   0.1.0
  96.     * @author  Daniel Plücken <daniel@debakel.net>
  97.     * @access  public
  98.     * @param   string $string 
  99.     * @return  void 
  100.     */
  101.    function setOnBlur$string )
  102.    {
  103.       parent::setOnBlur(
  104.                    "checkURLText( this, '".implode(
  105.                                      "|"$this->protocol_prefix_arr )
  106.                                        ."' );"
  107.                   .$string
  108.                        );
  109.    }
  110.  
  111.  
  112.  
  113.    /**
  114.     * Adds a new protocol type to the array of all prefixes for the protocol
  115.     * that are allowed to put in the textfield, like "http://" or/and "ftp://"
  116.     * etc.
  117.     *
  118.     * @version 1.0
  119.     * @since   0.1.0
  120.     * @author  Daniel Plücken <daniel@debakel.net>
  121.     * @access  public
  122.     * @param   string $string 
  123.     * @return  void 
  124.     */
  125.    function addProtocolPrefix$string )
  126.    $this->protocol_prefix_arr[$string}
  127.  
  128.  
  129.  
  130.    /**
  131.     * Returns a javascript to probe if the value, that was typed in the
  132.     * textfield, is a number.
  133.     * 
  134.     * 
  135.     * @version 1.0
  136.     * @since   0.1.0
  137.     * @author  Daniel Plücken <daniel@debakel.net>
  138.     * @access  public
  139.     * @return  void 
  140.     */
  141.    function getJSFunctionsToCheckURL()
  142.    {
  143.        global $JSTOCHECKURL;
  144.        
  145.        $out "";
  146.        ifempty$JSTOCHECKURL ) )
  147.        {
  148.           $JSTOCHECKURL true;
  149.           
  150.           $out  "\r\n\r\n<script language=\"javascript\">\r\n";
  151.           $out .= "<!--\r\n\r\n";
  152.           $out .= "  function checkURLText( which, protocol )\r\n";
  153.           $out .= "  {\r\n";
  154.           $out .= "     reg_obj = new RegExp( "
  155.                  ."'^(?:' + protocol + ')?"
  156.                    ."(?:[^\\\\s\\/?&\\\\#\\\"\\':\\\\.]{2,}\\\\.?)*" // Domain
  157.                    ."(?::" // Port
  158.                      ."(?:[0-9]" // 0-9
  159.                        ."|[1-9]\\\\d{1,3}" // 10-9999
  160.                        ."|[1-5]\\\\d{4,4}" // 10000-59999
  161.                        ."|6[0-4]\\\\d\\\\d\\\\d" // 60000-64999
  162.                        ."|65[0-4]\\\\d\\\\d" // 65000-65499
  163.                        ."|655[0-2]\\\\d" // 65500-65529
  164.                        ."|6553[0-5]" // 65530-65535
  165.                      .")"
  166.                    .")?" // Port /
  167.                    ."(?:\\/[^\\\\s\\/?&\\\\#\\\"\\':]+)*" // Folder & Files
  168.                    ."(?:"
  169.                      ."(?:\\\\?[-_a-z%0-9]+(?:=[^ &]*)?){1,1}" // First
  170.                                                              // parameter
  171.                      ."(?:&[-_a-z%0-9]+(?:=[^ &]*)?)*" // Following
  172.                                                        // parameter
  173.                    .")?"
  174.                  ."$', 'i' "
  175.                                           .");\r\n\r\n";
  176.           $out .= "     if ( reg_obj.test( which.value ) )\r\n";
  177.           $out .= "        return true;\r\n";
  178.           $out .= "     else\r\n";
  179.           $out .= "     {\r\n";
  180.           $out .= "        alert( "
  181.                             ."unescape( \"".JS_ERR_WRONG_URL_MSG."\" ) "
  182.                               .");\r\n";
  183.           $out .= "        which.focus();\r\n";
  184.           $out .= "        return false;\r\n";
  185.           $out .= "     }\r\n";
  186.           $out .= "  }\r\n";
  187.           $out .= "// -->\r\n";
  188.           $out .= "</script>\r\n\r\n\r\n";
  189.        }
  190.        return $out;
  191.    }
  192.  
  193.  
  194.  
  195.    /**
  196.     * Returns an if-order of a javascript to check whether the value of this
  197.     * item has the correct format.
  198.     *
  199.     * @version 1.0
  200.     * @since   0.1.0
  201.     * @author  Daniel Plücken <daniel@debakel.net>
  202.     * @access  public
  203.     * @param   string $formName 
  204.     * @return  string 
  205.     */
  206.    function getValidationOrder$formName "" )
  207.    {
  208.       $out "checkURLText( document."
  209.                   .(
  210.                      empty$formName )
  211.                      ? $this->parentform->getName()
  212.                      : $formName
  213.                    )."."
  214.                   .$this->getName()
  215.                                  .", '"
  216.                   .implode"|"$this->protocol_prefix_arr )
  217.                                     ."' )";
  218.       
  219.       return $out;
  220.    }
  221.    
  222.    
  223.    /**
  224.     * Returns an if-order of a javascript to check whether this item is NOT
  225.     * filled
  226.     *
  227.     * @version 1.0
  228.     * @since   0.1.0
  229.     * @author  Daniel Plücken <daniel@debakel.net>
  230.     * @access  public
  231.     * @return  string 
  232.     */
  233.    function getCheckOrder()
  234.    {
  235.       $out "document.".$this->parentform->getName()."."
  236.                         .$this->name.".value == \"\"";
  237.             
  238.       
  239.       foreach $this->protocol_prefix_arr as $str_tmp )
  240.               $out .= " || document.".$this->parentform->getName()."."
  241.                                      .$this->name.".value == \"".$str_tmp."\"";
  242.       
  243.       return $out;
  244.    }
  245.  
  246.  
  247.  
  248.    /**
  249.     * Generates the sourcecode to build this object and returns it.
  250.     *
  251.     * @version 1.1
  252.     * @since   0.1.0
  253.     * @author  Daniel Plücken <daniel@debakel.net>
  254.     * @access  public
  255.     * @return  string 
  256.     */
  257.    function getPHPSource()
  258.    {
  259.       $out  "unset( \x24value );\r\n";
  260.       $out .= "\x24value = \x24_POST[\"".$this->getName()."\"]\r\n"
  261.              ."        .\x24_GET[\"".$this->getName()."\"];\r\n";
  262.       $out .= "\x24input[] = new URLTextInput(\r\n"
  263.            ."                                 \"".$this->getName()."\",\r\n"
  264.            ."                                 \x24value,\r\n"
  265.            ."                                 \"".$this->getSize()."\"\r\n"
  266.            ."                              );\r\n";
  267.       
  268.       $tmp $this->getValue();
  269.       $out .= !empty$tmp )
  270.               ? "if( \x24value === \"\" )\r\n"
  271.                ."  \x24input[count(\x24input)-1]"
  272.                   ."->setValue( \"".$tmp."\" );\r\n\r\n"
  273.               : "\r\n";
  274.       
  275.       return $out;
  276.    }
  277.  
  278.  
  279.  
  280.    /**
  281.     * Returns a generated string based on the attributes of this object.
  282.     *
  283.     * @version 1.0
  284.     * @since   0.1.0
  285.     * @author  Daniel Plücken <daniel@debakel.net>
  286.     * @access  public
  287.     * @return  string 
  288.     */
  289.    function get()
  290.    {
  291.       $out $this->getJSFunctionsToCheckURL();
  292.       $this->setOnBlur"" );
  293.       $out .= parent::get();
  294.       
  295.       return  $out;
  296.    }
  297. // END of class NumberTextInput
  298. ?>

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