*/ /** * simple textfield patForms element that builds and validates text input fields. * * @access protected * @package patForms * @subpackage patForms_Element * @author gERD Schaufelberger * @license LGPL, see license.txt for details */ class patForms_Element_WBCmXml extends patForms_Element { /** * Stores the name of the element - this is used mainly by the patForms * error management and should be set in every element class. * @access public */ var $elementName = 'WBCmXml'; /** * the type of the element - set this to the type of element you are creating * if you want to use the {@link patForms_Element::element2html()} method to * create the final HTML tag for your element. * * @access public * @see patForms_Element::element2html() */ var $elementType = array( 'html' => 'textarea', ); /** * set here which attributes you want to include in the element if you want to use * the {@link patForms_Element::convertDefinition2Attributes()} method to automatically * convert the values from your element definition into element attributes. * * @access protected * @see patForms_Element::convertDefinition2Attribute() */ var $attributeDefinition = array( 'id' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), ), 'name' => array( 'required' => true, 'format' => 'string', 'outputFormats' => array( 'html' ), 'modifiers' => array( 'insertSpecials' => array() ), ), 'title' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), 'modifiers' => array( 'insertSpecials' => array() ), ), 'description' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(), 'modifiers' => array( 'insertSpecials' => array() ), ), 'default' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(), ), 'label' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(), ), 'edit' => array( 'required' => false, 'format' => 'string', 'default' => 'yes', 'outputFormats' => array(), ), 'display' => array( 'required' => false, 'format' => 'string', 'default' => 'yes', 'outputFormats' => array(), ), 'required' => array( 'required' => false, 'format' => 'string', 'default' => 'yes', 'outputFormats' => array(), ), 'value' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), ), 'style' => array( 'required' => false, 'outputFormats' => array( 'html' ), 'format' => 'string', 'default' => 'width:100%;' ), 'class' => array( 'required' => false, 'outputFormats' => array( 'html' ), 'format' => 'string', ), 'onchange' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), 'modifiers' => array( 'insertSpecials' => array() ), ), 'onclick' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), 'modifiers' => array( 'insertSpecials' => array() ), ), 'onfocus' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), 'modifiers' => array( 'insertSpecials' => array() ), ), 'onmouseover' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), 'modifiers' => array( 'insertSpecials' => array() ), ), 'onmouseout' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), 'modifiers' => array( 'insertSpecials' => array() ), ), 'onblur' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), 'modifiers' => array( 'insertSpecials' => array() ), ), 'accesskey' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), ), 'position' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array(), ), 'tabindex' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array( 'html' ), ), 'maxlength' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array(), ), 'minlength' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array(), ), 'rows' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array( 'html' ), ), 'cols' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array( 'html' ), ), 'disabled' => array( 'required' => false, 'format' => 'string', 'default' => 'no', 'outputFormats' => array( 'html' ), ), 'config' => array( 'required' => false, 'format' => 'string', 'default' => '_default.js', 'outputFormats' => array(), ), ); /** * define error codes and messages for each form element * * @access private * @var array $validatorErrorCodes */ var $validatorErrorCodes = array( 'C' => array( 1 => 'This field is required, please complete it.', 2 => 'Value is not a string.', 3 => 'The value is shorter than the minimum length of [MINLENGTH].', 4 => 'The value is longer than the maximum length of [MAXLENGTH].', 5 => 'Markup tags are not allowed', 6 => 'The value contains some tags that are not allowed - only \'[ALLOWEDTAGS]\' are allowed here' ), 'de' => array( 1 => 'Pflichtfeld. Bitte vervollst�ndigen Sie Ihre Angabe.', 2 => 'Wert ist keine Zeichenkette.', 3 => 'Eingabe zu kurz, bitte geben Sie mindestens [MINLENGTH] Zeichen ein.', 4 => 'Eingabe zu lang, bitte geben Sie maximal [MAXLENGTH] Zeichen ein.', 5 => 'Tags sind nicht erlaubt.', 6 => 'Der Text enth�lt unbekannte Tags; es sind nur \'[ALLOWEDTAGS]\' erlaubt.' ), 'fr' => array( 1 => 'Ce champ est obligatoire.', 2 => 'Pas une cha�ne de caract�res valide.', 3 => 'Valeur trop courte. Longueur minimum: [MINLENGTH] caract�res.', 4 => 'Valeur trop longue. Longueur maximum: [MAXLENGTH] caract�res.', 5 => 'Les balises ne sont pas autoris�es.', 6 => 'Le texte contient des balises non autoris�es - les balises autoris�es sont \'[ALLOWEDTAGS]\'.' ) ); /** * element creation method for the 'HTML' format in the 'default' form mode. * * @access public * @param mixed value of the element * @return mixed $element The element, or false if failed. */ function serializeHtmlDefault( $value ) { $sess = wbFactory::Singleton( 'patSession' ); $lang = patForms::getStaticProperty( 'locale' ); if( $this->attributes['display'] == 'no' ) { return $this->createDisplaylessTag( $value ); } if( $this->attributes['edit'] == 'no' ) { $this->attributes['disabled'] = 'yes'; } $path = dirname( $_SERVER['PHP_SELF'] ); if( $path == '/' ) { $path = ''; } $editorBase = sprintf( '_editor_url = "%s/xinha/"; _editor_lang = "%s";', $path, $lang ); wbJSTools::includeJavascript( "wbDialog_Session = '". $sess->GetSID() ."'", 'onload' ); wbJSTools::includeJavascript( $editorBase, 'code' ); wbJSTools::includeJavascript( 'wbDialog.js' ); wbJSTools::includeJavascript( '/xinha/XinhaCore.js' ); $configFile = wbFactory::getParam( 'baseDir' ) . '/' . wbFactory::getParam( 'configDir' ) . '/xinha/' . $this->attributes['config']; $html = array(); $cm = wbFactory::create( 'wbContentManager' ); $value = $cm->transform( $value, 'fake' ); $html[] = $this->createTag( 'textarea', 'full', $this->getAttributesFor( $this->getFormat() ), $value ); $html[] = ''; return implode( "\n", $html ); } /** * element creation method for the 'HTML' format in the 'readonly' form mode. * Very simple; just returns the stored element value. * * @access public * @param mixed value of the element * @return string $value The element's value */ function serializeHtmlReadonly( $value ) { $tag = $this->createDisplaylessTag( $value ); if( $this->attributes['display'] == 'no' ) { return $tag; } return $value.$tag; } /** * validates the element. * * @access public * @param mixed value of the element * @return bool $isValid True if element could be validated, false otherwise. */ function validateElement( $value ) { $required = false; $empty = false; // store the required flag for easy access if( isset( $this->attributes['required'] ) && $this->attributes['required'] == 'yes' ) { $required = true; } $stripedValue = strip_tags( $value ); if( strlen( $stripedValue ) == 0 ) { $empty = true; } if( $empty && $required ) { $this->addValidationError( 1 ); return false; } if( $empty && !$required ) { return true; } // is it a string? if( !is_string( $value ) ) { $this->addValidationError( 2 ); return false; } // minlength if( isset( $this->attributes['minlength'] ) && strlen( $stripedValue ) < $this->attributes['minlength'] ) { $this->addValidationError( 3, array( 'minlength' => $this->attributes['minlength'] ) ); return false; } // maxlength if( isset( $this->attributes['maxlength'] ) && strlen( $stripedValue ) > $this->attributes['maxlength'] ) { $this->addValidationError( 4, array( 'maxlength' => $this->attributes['maxlength'] ) ); return false; } $cm = wbFactory::create( 'wbContentManager' ); $this->value = $cm->transform( $value, 'xml' ); return true; } } ?>