*/ /** * patForms Elemenbt: chunk * * Chunk of a file * * @version 0.1.1 * @package Wombat * @subpackage patForms */ class patForms_Element_Chunk 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. * @var string */ public $elementName = 'Chunk'; /** * 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. * * @see patForms_Element::convertDefinition2Attribute() * @var array */ public $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(), 'modifiers' => array( 'insertSpecials' => 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', ), 'class' => array( 'required' => false, 'outputFormats' => array( 'html' ), 'format' => 'string', ), 'autocomplete' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), 'modifiers' => array( 'insertSpecials' => array() ) ), '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(), ), 'base64' => array( 'required' => false, 'format' => 'string', 'default' => 'yes', 'outputFormats' => array(), ), 'disabled' => array( 'required' => false, 'format' => 'string', 'default' => 'no', 'outputFormats' => array( 'html' ), ), ); /** * Initialize validation codes using gettext * * Overwrite this function to add element's error codes * * @return bool $success Always returns true. * @see $attributeDefaults */ public function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext( 'wombat', 'This field is required, please complete it.' ), 2 => patI18n::dgettext( 'wombat', 'Value is not a string.' ), 3 => patI18n::dgettext( 'wombat', 'Value is not properly base64 encoded.' ), 4 => patI18n::dgettext( 'wombat', 'The value is shorter than the minimum length of [MINLENGTH].' ), 5 => patI18n::dgettext( 'wombat', 'The value is longer than the maximum length of [MAXLENGTH].' ) ); return true; } /** * 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. */ public function serializeHtmlDefault( $value ) { if ($this->attributes['display'] == 'no') { return $this->createDisplaylessTag( $value ); } if ($this->attributes['edit'] == 'no') { $this->attributes['disabled'] = 'yes'; } return $this->createTag( 'textarea', 'full', $this->getAttributesFor($this->getFormat()), $value); } /** * 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 */ public function serializeHtmlReadonly($value) { $tag = $this->createDisplaylessTag($value); if ($this->attributes['display'] == 'no') { return $tag; } return $value.$tag; } /** * validates the element. * * * * @param stringd $value of the element * @return bool $isValid True if element could be validated, false otherwise. */ public 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; } if (strlen( $value ) == 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; } // base 64 decode if (isset($this->attributes['base64']) && $this->attributes['base64'] == 'yes') { $chunk = base64_decode($value, true); if (!$chunk) { $this->addValidationError(3); return false; } $value = $chunk; unset($chunk); } // minlength if (isset( $this->attributes['minlength'] ) && strlen($value) < $this->attributes['minlength']) { $this->addValidationError(4, array('minlength' => $this->attributes['minlength'])); return false; } // maxlength if (isset( $this->attributes['maxlength']) && strlen($value) > $this->attributes['maxlength']) { $this->addValidationError(5, array('maxlength' => $this->attributes['maxlength'])); return false; } return true; } } ?>