eZ Publish  [4.0]
ezregexpvalidator.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZRegExpValidator class
00004 //
00005 // Created on: <08-Jul-2002 16:17:15 amos>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezregexpvalidator.php
00032 */
00033 
00034 /*!
00035   \class eZRegExpValidator ezregexpvalidator.php
00036   \brief Input validation using regexps
00037 
00038 */
00039 
00040 //include_once( "lib/ezutils/classes/ezinputvalidator.php" );
00041 
00042 class eZRegExpValidator extends eZInputValidator
00043 {
00044     /*!
00045     */
00046     function eZRegExpValidator( $rule = null )
00047     {
00048         $this->eZInputValidator();
00049         $this->RegExpRule = $rule;
00050     }
00051 
00052     function setRegExpRule( $rule )
00053     {
00054         $this->RegExpRule = $rule;
00055     }
00056 
00057     function validate( $text )
00058     {
00059         if ( !is_array( $this->RegExpRule ) )
00060             return eZInputValidator::STATE_INVALID;
00061         $accepted =& $this->RegExpRule["accepted"];
00062         if ( preg_match( $accepted, $text ) )
00063             return eZInputValidator::STATE_ACCEPTED;
00064         $intermediate =& $this->RegExpRule["intermediate"];
00065         if ( preg_match( $intermediate, $text ) )
00066             return eZInputValidator::STATE_INTERMEDIATE;
00067         return eZInputValidator::STATE_INVALID;
00068     }
00069 
00070     function fixup( $text )
00071     {
00072         if ( !is_array( $this->RegExpRule ) )
00073             return $text;
00074         $intermediate =& $this->RegExpRule["intermediate"];
00075         $fixup =& $this->RegExpRule["fixup"];
00076         if ( is_array( $fixup ) )
00077         {
00078             $intermediate = $fixup["match"];
00079             $fixup = $fixup["replace"];
00080         }
00081         $text = preg_replace( $intermediate, $fixup, $text );
00082         return $text;
00083     }
00084 
00085     /// \privatesection
00086     public $RegExpRule;
00087 }
00088 
00089 ?>