|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZXMLInputHandler class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZXMLInputHandler ezxmlinputhandler.php 00013 \ingroup eZDatatype 00014 \brief The class eZXMLInputHandler does 00015 00016 */ 00017 00018 class eZXMLInputHandler 00019 { 00020 /*! 00021 Constructor 00022 */ 00023 function eZXMLInputHandler( $xmlData, $aliasedType, $contentObjectAttribute ) 00024 { 00025 $this->XMLData = preg_replace( '/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', '', $xmlData, -1, $count ); 00026 if ( $count > 0 ) 00027 { 00028 eZDebug::writeWarning( "$count invalid character(s) detected. They have been removed from input.", __METHOD__ ); 00029 } 00030 $this->ContentObjectAttribute = $contentObjectAttribute; 00031 $this->AliasedHandler = null; 00032 // use of $aliasedType is deprecated as of 4.1 and setting is ignored in aliased_handler 00033 $this->AliasedType = $aliasedType; 00034 } 00035 00036 /*! 00037 \return an array with attribute names. 00038 */ 00039 function attributes() 00040 { 00041 return array( 'input_xml', 00042 'aliased_type', 00043 'aliased_handler', 00044 'edit_template_name', 00045 'information_template_name' ); 00046 } 00047 00048 /*! 00049 \return true if the attribute \a $name exists. 00050 */ 00051 function hasAttribute( $name ) 00052 { 00053 return in_array( $name, $this->attributes() ); 00054 } 00055 00056 /*! 00057 \return the value of the attribute \a $name if it exists, if not returns \c null. 00058 */ 00059 function attribute( $name ) 00060 { 00061 switch ( $name ) 00062 { 00063 case 'input_xml': 00064 { 00065 return $this->inputXML(); 00066 } break; 00067 case 'edit_template_name': 00068 { 00069 return $this->editTemplateName(); 00070 }break; 00071 case 'information_template_name': 00072 { 00073 return $this->informationTemplateName(); 00074 }break; 00075 case 'aliased_type': 00076 { 00077 eZDebug::writeWarning( "'aliased_type' is deprecated as of 4.1 and not in use anymore, meaning it will always return false.", __METHOD__ ); 00078 return $this->AliasedType; 00079 }break; 00080 case 'aliased_handler': 00081 { 00082 if ( $this->AliasedHandler === null ) 00083 { 00084 $this->AliasedHandler = eZXMLText::inputHandler( $this->XMLData, 00085 $this->AliasedType, 00086 false, 00087 $this->ContentObjectAttribute ); 00088 } 00089 return $this->AliasedHandler; 00090 }break; 00091 default: 00092 { 00093 eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ ); 00094 return null; 00095 }break; 00096 } 00097 } 00098 00099 /*! 00100 \return the template name for this input handler, includes the edit suffix if any. 00101 */ 00102 function editTemplateName() 00103 { 00104 $name = 'ezxmltext'; 00105 $suffix = $this->editTemplateSuffix( $this->ContentObjectAttribute ); 00106 if ( $suffix !== false ) 00107 { 00108 $name .= '_' . $suffix; 00109 } 00110 return $name; 00111 } 00112 00113 /*! 00114 \return the template name for this input handler, includes the information suffix if any. 00115 */ 00116 function informationTemplateName() 00117 { 00118 $name = 'ezxmltext'; 00119 $suffix = $this->informationTemplateSuffix( $this->ContentObjectAttribute ); 00120 if ( $suffix !== false ) 00121 { 00122 $name .= '_' . $suffix; 00123 } 00124 return $name; 00125 } 00126 00127 /*! 00128 \pure 00129 Handles custom actions for input handler. 00130 \note Default does nothing, reimplement to check actions. 00131 */ 00132 function customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute ) 00133 { 00134 } 00135 00136 /*! 00137 \virtual 00138 \return true if the input handler is considered valid, if not the handler will not be used. 00139 \note Default returns true 00140 */ 00141 function isValid() 00142 { 00143 return true; 00144 } 00145 00146 /*! 00147 \pure 00148 \return the suffix for the attribute template, if false it is ignored. 00149 */ 00150 function editTemplateSuffix( &$contentobjectAttribute ) 00151 { 00152 return false; 00153 } 00154 00155 /*! 00156 \pure 00157 \return the suffix for the attribute template, if false it is ignored. 00158 */ 00159 function informationTemplateSuffix( &$contentobjectAttribute ) 00160 { 00161 return false; 00162 } 00163 00164 /*! 00165 \return the xml data as text. 00166 */ 00167 function xmlData() 00168 { 00169 return $this->XMLData; 00170 } 00171 00172 /*! 00173 \pure 00174 Validates user input and returns whether it can be used or not. 00175 */ 00176 function validateInput( $http, $base, $contentObjectAttribute ) 00177 { 00178 return eZInputValidator::STATE_INVALID; 00179 } 00180 00181 /*! 00182 \pure 00183 Converts text input \a $text into an XML structure and returns it. 00184 \return an array where index 0 is the xml structure and index 1 is a message. 00185 */ 00186 function convertInput( $text ) 00187 { 00188 return null; 00189 } 00190 00191 /*! 00192 \pure 00193 Returns the text representation of the XML structure, implement this to turn 00194 XML back into user input. 00195 */ 00196 function inputXML() 00197 { 00198 return null; 00199 } 00200 00201 /// \privatesection 00202 /// Contains the XML data as text 00203 public $XMLData; 00204 public $AliasedType; 00205 public $AliasedHandler; 00206 public $ContentObjectAttribute; 00207 } 00208 00209 ?>