?
Current File : /home/c/i/d/cideo/www/wp-includesVIp/js/crop/images/Element.tar
Reference/Table.php000066600000011123151253457770010224 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/**
 * PDF file reference table
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Pdf_Element_Reference_Table
{
    /**
     * Parent reference table
     *
     * @var Zend_Pdf_Element_Reference_Table
     */
    private $_parent;

    /**
     * Free entries
     * 'reference' => next free object number
     *
     * @var array
     */
    private $_free;

    /**
     * Generation numbers for free objects.
     * Array: objNum => nextGeneration
     *
     * @var array
     */
    private $_generations;

    /**
     * In use entries
     * 'reference' => offset
     *
     * @var array
     */
    private $_inuse;

    /**
     * Generation numbers for free objects.
     * Array: objNum => objGeneration
     *
     * @var array
     */
    private $_usedObjects;



    /**
     * Object constructor
     */
    public function  __construct()
    {
        $this->_parent = null;
        $this->_free   = array();  $this->_generations = array();
        $this->_inuse  = array();  $this->_usedObjects = array();
    }


    /**
     * Add reference to the reference table
     *
     * @param string $ref
     * @param integer $offset
     * @param boolean $inuse
     */
    public function addReference($ref, $offset, $inuse = true)
    {
        $refElements = explode(' ', $ref);
        if (!is_numeric($refElements[0]) || !is_numeric($refElements[1]) || $refElements[2] != 'R') {
            throw new Zend_Pdf_Exception("Incorrect reference: '$ref'");
        }
        $objNum = (int)$refElements[0];
        $genNum = (int)$refElements[1];

        if ($inuse) {
            $this->_inuse[$ref]          = $offset;
            $this->_usedObjects[$objNum] = $objNum;
        } else {
            $this->_free[$ref]           = $offset;
            $this->_generations[$objNum] = $genNum;
        }
    }


    /**
     * Set parent reference table
     *
     * @param Zend_Pdf_Element_Reference_Table $parent
     */
    public function setParent(self $parent)
    {
        $this->_parent = $parent;
    }


    /**
     * Get object offset
     *
     * @param string $ref
     * @return integer
     */
    public function getOffset($ref)
    {
        if (isset($this->_inuse[$ref])) {
            return $this->_inuse[$ref];
        }

        if (isset($this->_free[$ref])) {
            return null;
        }

        if (isset($this->_parent)) {
            return $this->_parent->getOffset($ref);
        }

        return null;
    }


    /**
     * Get next object from a list of free objects.
     *
     * @param string $ref
     * @return integer
     * @throws Zend_Pdf_Exception
     */
    public function getNextFree($ref)
    {
        if (isset($this->_inuse[$ref])) {
            throw new Zend_Pdf_Exception('Object is not free');
        }

        if (isset($this->_free[$ref])) {
            return $this->_free[$ref];
        }

        if (isset($this->_parent)) {
            return $this->_parent->getNextFree($ref);
        }

        throw new Zend_Pdf_Exception('Object not found.');
    }


    /**
     * Get next generation number for free object
     *
     * @param integer $objNum
     * @return unknown
     */
    public function getNewGeneration($objNum)
    {
        if (isset($this->_usedObjects[$objNum])) {
            throw new Zend_Pdf_Exception('Object is not free');
        }

        if (isset($this->_generations[$objNum])) {
            return $this->_generations[$objNum];
        }

        if (isset($this->_parent)) {
            return $this->_parent->getNewGeneration($objNum);
        }

        throw new Zend_Pdf_Exception('Object not found.');
    }
}

Reference/Context.php000066600000004310151253457770010621 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** Zend_Pdf_StringParser */
require_once 'Zend/Pdf/StringParser.php';

/** Zend_Pdf_Element_Reference_Table */
require_once 'Zend/Pdf/Element/Reference/Table.php';


/**
 * PDF reference object context
 * Reference context is defined by PDF parser and PDF Refernce table
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Pdf_Element_Reference_Context
{
    /**
     * PDF parser object.
     *
     * @var Zend_Pdf_Parser
     */
    private $_stringParser;

    /**
     * Reference table
     *
     * @var Zend_Pdf_Element_Reference_Table
     */
    private $_refTable;

    /**
     * Object constructor
     *
     * @param Zend_Pdf_StringParser $parser
     * @param Zend_Pdf_Element_Reference_Table $refTable
     */
    public function __construct(Zend_Pdf_StringParser $parser,
                                Zend_Pdf_Element_Reference_Table $refTable)
    {
        $this->_stringParser = $parser;
        $this->_refTable     = $refTable;
    }


    /**
     * Context parser
     *
     * @return Zend_Pdf_Parser
     */
    public function getParser()
    {
        return $this->_stringParser;
    }


    /**
     * Context reference table
     *
     * @return Zend_Pdf_Element_Reference_Table
     */
    public function getRefTable()
    {
        return $this->_refTable;
    }
}

Null.php000066600000003263151253457770006217 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';


/**
 * PDF file 'null' element implementation
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Pdf_Element_Null extends Zend_Pdf_Element
{
    /**
     * Object value. Always null.
     *
     * @var mixed
     */
    public $value;


    /**
     * Object constructor
     */
    public function __construct()
    {
        $this->value = null;
    }


    /**
     * Return type of the element.
     *
     * @return integer
     */
    public function getType()
    {
        return Zend_Pdf_Element::TYPE_NULL;
    }


    /**
     * Return object as string
     *
     * @param Zend_Pdf_Factory $factory
     * @return string
     */
    public function toString($factory = null)
    {
        return 'null';
    }
}
Numeric.php000066600000004366151253457770006714 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';


/**
 * PDF file 'numeric' element implementation
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Pdf_Element_Numeric extends Zend_Pdf_Element
{
    /**
     * Object value
     *
     * @var numeric
     */
    public $value;


    /**
     * Object constructor
     *
     * @param numeric $val
     * @throws Zend_Pdf_Exception
     */
    public function __construct($val)
    {
        if ( !is_numeric($val) ) {
            throw new Zend_Pdf_Exception('Argument must be numeric');
        }

        $this->value   = $val;
    }


    /**
     * Return type of the element.
     *
     * @return integer
     */
    public function getType()
    {
        return Zend_Pdf_Element::TYPE_NUMERIC;
    }


    /**
     * Return object as string
     *
     * @param Zend_Pdf_Factory $factory
     * @return string
     */
    public function toString($factory = null)
    {
        if (is_integer($this->value)) {
            return (string)$this->value;
        }

        /**
         * PDF doesn't support exponental format.
         * Fixed point format must be used instead
         */
        $prec = 0; $v = $this->value;
        while (abs( floor($v) - $v ) > 1e-10) {
            $prec++; $v *= 10;
        }
        return sprintf("%.{$prec}F", $this->value);
    }
}
String.php000066600000015624151253457770006557 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';


/**
 * PDF file 'string' element implementation
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Pdf_Element_String extends Zend_Pdf_Element
{
    /**
     * Object value
     *
     * @var string
     */
    public $value;

    /**
     * Object constructor
     *
     * @param string $val
     */
    public function __construct($val)
    {
        $this->value   = (string)$val;
    }


    /**
     * Return type of the element.
     *
     * @return integer
     */
    public function getType()
    {
        return Zend_Pdf_Element::TYPE_STRING;
    }


    /**
     * Return object as string
     *
     * @param Zend_Pdf_Factory $factory
     * @return string
     */
    public function toString($factory = null)
    {
        return '(' . self::escape((string)$this->value) . ')';
    }


    /**
     * Escape string according to the PDF rules
     *
     * @param string $inStr
     * @return string
     */
    public static function escape($inStr)
    {
        $outStr = '';
        $lastNL = 0;

        for ($count = 0; $count < strlen($inStr); $count++) {
            if (strlen($outStr) - $lastNL > 128)  {
                $outStr .= "\\\n";
                $lastNL = strlen($outStr);
            }

            $nextCode = ord($inStr[$count]);
            switch ($nextCode) {
                // "\n" - line feed (LF)
                case 10:
                    $outStr .= '\\n';
                    break;

                // "\r" - carriage return (CR)
                case 13:
                    $outStr .= '\\r';
                    break;

                // "\t" - horizontal tab (HT)
                case 9:
                    $outStr .= '\\t';
                    break;

                // "\b" - backspace (BS)
                case 8:
                    $outStr .= '\\b';
                    break;

                // "\f" - form feed (FF)
                case 12:
                    $outStr .= '\\f';
                    break;

                // '(' - left paranthesis
                case 40:
                    $outStr .= '\\(';
                    break;

                // ')' - right paranthesis
                case 41:
                    $outStr .= '\\)';
                    break;

                // '\' - backslash
                case 92:
                    $outStr .= '\\\\';
                    break;

                default:
                    // Don't use non-ASCII characters escaping
                    // if ($nextCode >= 32 && $nextCode <= 126 ) {
                    //     // Visible ASCII symbol
                    //     $outStr .= $inStr[$count];
                    // } else {
                    //     $outStr .= sprintf('\\%03o', $nextCode);
                    // }
                    $outStr .= $inStr[$count];

                    break;
            }
        }

        return $outStr;
    }


    /**
     * Unescape string according to the PDF rules
     *
     * @param string $inStr
     * @return string
     */
    public static function unescape($inStr)
    {
        $outStr = '';

        for ($count = 0; $count < strlen($inStr); $count++) {
            if ($inStr[$count] != '\\' || $count == strlen($inStr)-1)  {
                $outStr .= $inStr[$count];
            } else { // Escape sequence
                switch ($inStr{++$count}) {
                    // '\\n' - line feed (LF)
                    case 'n':
                        $outStr .= "\n";
                        break;

                    // '\\r' - carriage return (CR)
                    case 'r':
                        $outStr .= "\r";
                        break;

                    // '\\t' - horizontal tab (HT)
                    case 't':
                        $outStr .= "\t";
                        break;

                    // '\\b' - backspace (BS)
                    case 'b':
                        $outStr .= "\x08";
                        break;

                    // '\\f' - form feed (FF)
                    case 'f':
                        $outStr .= "\x0C";
                        break;

                    // '\\(' - left paranthesis
                    case '(':
                        $outStr .= '(';
                        break;

                    // '\\)' - right paranthesis
                    case ')':
                        $outStr .= ')';
                        break;

                    // '\\\\' - backslash
                    case '\\':
                        $outStr .= '\\';
                        break;

                    // "\\\n" or "\\\n\r"
                    case "\n":
                        // skip new line symbol
                        if ($inStr[$count+1] == "\r") {
                            $count++;
                        }
                        break;

                    default:
                        if (ord($inStr[$count]) >= ord('0') &&
                            ord($inStr[$count]) <= ord('9')) {
                            // Character in octal representation
                            // '\\xxx'
                            $nextCode = '0' . $inStr[$count];

                            if (ord($inStr[$count+1]) >= ord('0') &&
                                ord($inStr[$count+1]) <= ord('9')) {
                                $nextCode .= $inStr{++$count};

                                if (ord($inStr[$count+1]) >= ord('0') &&
                                    ord($inStr[$count+1]) <= ord('9')) {
                                    $nextCode .= $inStr{++$count};
                                }
                            }

                            $outStr .= chr($nextCode);
                        } else {
                            $outStr .= $inStr[$count];
                        }
                        break;
                }
            }
        }

        return $outStr;
    }

}
Dictionary.php000066600000010730151253457770007407 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';


/**
 * PDF file 'dictionary' element implementation
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Pdf_Element_Dictionary extends Zend_Pdf_Element
{
    /**
     * Dictionary elements
     * Array of Zend_Pdf_Element objects ('name' => Zend_Pdf_Element)
     *
     * @var array
     */
    private $_items = array();


    /**
     * Object constructor
     *
     * @param array $val   - array of Zend_Pdf_Element objects
     * @throws Zend_Pdf_Exception
     */
    public function __construct($val = null)
    {
        if ($val === null) {
            return;
        } else if (!is_array($val)) {
            throw new Zend_Pdf_Exception('Argument must be an array');
        }

        foreach ($val as $name => $element) {
            if (!$element instanceof Zend_Pdf_Element) {
                throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
            }
            if (!is_string($name)) {
                throw new Zend_Pdf_Exception('Array keys must be strings');
            }
            $this->_items[$name] = $element;
        }
    }


    /**
     * Add element to an array
     *
     * @name Zend_Pdf_Element_Name $name
     * @param Zend_Pdf_Element $val   - Zend_Pdf_Element object
     * @throws Zend_Pdf_Exception
     */
    public function add(Zend_Pdf_Element_Name $name, Zend_Pdf_Element $val)
    {
        $this->_items[$name->value] = $val;
    }

    /**
     * Return dictionary keys
     *
     * @return array
     */
    public function getKeys()
    {
        return array_keys($this->_items);
    }


    /**
     * Get handler
     *
     * @param string $property
     * @return Zend_Pdf_Element | null
     */
    public function __get($item)
    {
        $element = isset($this->_items[$item]) ? $this->_items[$item]
                                               : null;

        return $element;
    }

    /**
     * Set handler
     *
     * @param string $property
     * @param  mixed $value
     */
    public function __set($item, $value)
    {
        if ($value === null) {
            unset($this->_items[$item]);
        } else {
            $this->_items[$item] = $value;
        }
    }

    /**
     * Return type of the element.
     *
     * @return integer
     */
    public function getType()
    {
        return Zend_Pdf_Element::TYPE_DICTIONARY;
    }


    /**
     * Return object as string
     *
     * @param Zend_Pdf_Factory $factory
     * @return string
     */
    public function toString($factory = null)
    {
        $outStr = '<<';
        $lastNL = 0;

        foreach ($this->_items as $name => $element) {
            if (!is_object($element)) {
                throw new Zend_Pdf_Exception('Wrong data');
            }

            if (strlen($outStr) - $lastNL > 128)  {
                $outStr .= "\n";
                $lastNL = strlen($outStr);
            }

            $nameObj = new Zend_Pdf_Element_Name($name);
            $outStr .= $nameObj->toString($factory) . ' ' . $element->toString($factory) . ' ';
        }
        $outStr .= '>>';

        return $outStr;
    }


    /**
     * Convert PDF element to PHP type.
     *
     * Dictionary is returned as an associative array
     *
     * @return mixed
     */
    public function toPhp()
    {
        $phpArray = array();

        foreach ($this->_items as $itemName => $item) {
            $phpArray[$itemName] = $item->toPhp();
        }

        return $phpArray;
    }
}
Boolean.php000066600000003610151253457770006660 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';


/**
 * PDF file 'boolean' element implementation
 *
 * @category   Zend
 * @package    Zend_Pdf
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Pdf_Element_Boolean extends Zend_Pdf_Element
{
    /**
     * Object value
     *
     * @var boolean
     */
    public $value;


    /**
     * Object constructor
     *
     * @param boolean $val
     * @throws Zend_Pdf_Exception
     */
    public function __construct($val)
    {
        if (! is_bool($val)) {
            throw new Zend_Pdf_Exception('Argument must be boolean.');
        }

        $this->value   = $val;
    }


    /**
     * Return type of the element.
     *
     * @return integer
     */
    public function getType()
    {
        return Zend_Pdf_Element::TYPE_BOOL;
    }


    /**
     * Return object as string
     *
     * @param Zend_Pdf_Factory $factory
     * @return string
     */
    public function toString($factory = null)
    {
        return $this->value ? 'true' : 'false';
    }
}
Interface.php000066600000002670151254624020007167 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_InfoCard
 * @subpackage Zend_InfoCard_Xml
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Interface.php 9094 2008-03-30 18:36:55Z thomas $
 */

/**
 * The Interface used to represent an XML Data Type
 *
 * @category   Zend
 * @package    Zend_InfoCard
 * @subpackage Zend_InfoCard_Xml
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
interface Zend_InfoCard_Xml_Element_Interface
{
    /**
     * Return the data within the object as an XML document
     */
    public function asXML();

    /**
     * Magic function which allows us to treat the object as a string to return XML
     * (same as the asXML() method)
     */
    public function __toString();
}
DijitMulti.php000066600000017253151254723460007360 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_Dijit */
require_once 'Zend/Dojo/Form/Element/Dijit.php';

/**
 * CheckBox dijit
 *
 * Note: this would be easier with mixins or traits...
 * 
 * @uses       Zend_Dojo_Form_Element_Dijit
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: DijitMulti.php 10646 2008-08-04 20:24:37Z matthew $
 */
abstract class Zend_Dojo_Form_Element_DijitMulti extends Zend_Dojo_Form_Element_Dijit
{
    /**
     * Array of options for multi-item
     * @var array
     */
    public $options = array();

    /**
     * Flag: autoregister inArray validator?
     * @var bool
     */
    protected $_registerInArrayValidator = true;

    /**
     * Separator to use between options; defaults to '<br />'.
     * @var string
     */
    protected $_separator = '<br />';

    /**
     * Which values are translated already?
     * @var array
     */
    protected $_translated = array();

    /**
     * Retrieve separator
     *
     * @return mixed
     */
    public function getSeparator()
    {
        return $this->_separator;
    }

    /**
     * Set separator
     *
     * @param mixed $separator
     * @return self
     */
    public function setSeparator($separator)
    {
        $this->_separator = $separator;
        return $this;
    }

    /**
     * Retrieve options array
     * 
     * @return array
     */
    protected function _getMultiOptions()
    {
        if (null === $this->options || !is_array($this->options)) {
            $this->options = array();
        }

        return $this->options;
    }

    /**
     * Add an option
     * 
     * @param  string $option 
     * @param  string $value
     * @return Zend_Form_Element_Multi
     */
    public function addMultiOption($option, $value = '')
    {
        $option  = (string) $option;
        $this->_getMultiOptions();
        if (!$this->_translateOption($option, $value)) {
            $this->options[$option] = $value;
        }

        return $this;
    }

    /**
     * Add many options at once
     * 
     * @param  array $options 
     * @return Zend_Form_Element_Multi
     */
    public function addMultiOptions(array $options)
    {
        foreach ($options as $option => $value) {
            if (is_array($value) 
                && array_key_exists('key', $value)
                && array_key_exists('value', $value)
            ) {
                $this->addMultiOption($value['key'], $value['value']);
            } else {
                $this->addMultiOption($option, $value);
            }
        }
        return $this;
    }

    /**
     * Set all options at once (overwrites)
     *
     * @param  array $options
     * @return Zend_Form_Element_Multi
     */
    public function setMultiOptions(array $options)
    {
        $this->clearMultiOptions();
        return $this->addMultiOptions($options);
    }

    /**
     * Retrieve single multi option
     * 
     * @param  string $option 
     * @return mixed
     */
    public function getMultiOption($option)
    {
        $option  = (string) $option;
        $this->_getMultiOptions();
        if (isset($this->options[$option])) {
            $this->_translateOption($option, $this->options[$option]);
            return $this->options[$option];
        }

        return null;
    }

    /**
     * Retrieve options
     *
     * @return array
     */
    public function getMultiOptions()
    {
        $this->_getMultiOptions();
        foreach ($this->options as $option => $value) {
            $this->_translateOption($option, $value);
        }
        return $this->options;
    }

    /**
     * Remove a single multi option
     * 
     * @param  string $option 
     * @return bool
     */
    public function removeMultiOption($option)
    {
        $option  = (string) $option;
        $this->_getMultiOptions();
        if (isset($this->options[$option])) {
            unset($this->options[$option]);
            if (isset($this->_translated[$option])) {
                unset($this->_translated[$option]);
            }
            return true;
        }

        return false;
    }

    /**
     * Clear all options
     * 
     * @return Zend_Form_Element_Multi
     */
    public function clearMultiOptions()
    {
        $this->options = array();
        $this->_translated = array();
        return $this;
    }

    /**
     * Set flag indicating whether or not to auto-register inArray validator
     * 
     * @param  bool $flag 
     * @return Zend_Form_Element_Multi
     */
    public function setRegisterInArrayValidator($flag)
    {
        $this->_registerInArrayValidator = (bool) $flag;
        return $this;
    }

    /**
     * Get status of auto-register inArray validator flag
     * 
     * @return bool
     */
    public function registerInArrayValidator()
    {
        return $this->_registerInArrayValidator;
    }

    /**
     * Is the value provided valid?
     *
     * Autoregisters InArray validator if necessary.
     * 
     * @param  string $value 
     * @param  mixed $context 
     * @return bool
     */
    public function isValid($value, $context = null)
    {
        if ($this->registerInArrayValidator()) {
            if (!$this->getValidator('InArray')) {
                $options = $this->getMultiOptions();
                $this->addValidator(
                    'InArray',
                    true,
                    array(array_keys($options))
                );
            }
        }
        return parent::isValid($value, $context);
    }

    /**
     * Translate an option
     * 
     * @param  string $option 
     * @param  string $value
     * @return bool
     */
    protected function _translateOption($option, $value)
    {
        if (!isset($this->_translated[$option])) {
            $this->options[$option] = $this->_translateValue($value);
            if ($this->options[$option] === $value) {
                return false;
            }
            $this->_translated[$option] = true;
            return true;
        } 

        return false;
    }

    /**
     * Translate a value
     * 
     * @param  array|string $value 
     * @return array|string
     */
    protected function _translateValue($value)
    {
        if (is_array($value)) {
            foreach ($value as $key => $val) {
                $value[$key] = $this->_translateValue($val);
            }
            return $value;
        } else {
            if (null !== ($translator = $this->getTranslator())) {
                if ($translator->isTranslated($value)) {
                    return $translator->translate($value);
                }
            }
            return $value;
        }
    }
}
Editor.php000066600000035466151254723460006536 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_Dijit */
require_once 'Zend/Dojo/Form/Element/Dijit.php';

/**
 * Editor dijit
 * 
 * @uses       Zend_Dojo_Form_Element_Dijit
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Dojo_Form_Element_Editor extends Zend_Dojo_Form_Element_Dijit
{
    /**
     * @var string View helper
     */
    public $helper = 'Editor';

    /**
     * Add a single event to connect to the editing area
     * 
     * @param  string $event 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function addCaptureEvent($event)
    {
        $event = (string) $event;
        $captureEvents = $this->getCaptureEvents();
        if (in_array($event, $captureEvents)) {
            return $this;
        }

        $captureEvents[] = (string) $event;
        $this->setDijitParam('captureEvents', $captureEvents);
        return $this;
    }

    /**
     * Add multiple capture events
     * 
     * @param  array $events 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function addCaptureEvents(array $events)
    {
        foreach ($events as $event) {
            $this->addCaptureEvent($event);
        }
        return $this;
    }

    /**
     * Overwrite many capture events at once
     * 
     * @param  array $events 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setCaptureEvents(array $events)
    {
        $this->clearCaptureEvents();
        $this->addCaptureEvents($events);
        return $this;
    }

    /**
     * Get all capture events
     * 
     * @return array
     */
    public function getCaptureEvents()
    {
        if (!$this->hasDijitParam('captureEvents')) {
            return array();
        }
        return $this->getDijitParam('captureEvents');
    }

    /**
     * Is a given capture event registered?
     * 
     * @param  string $event
     * @return bool
     */
    public function hasCaptureEvent($event)
    {
        $captureEvents = $this->getCaptureEvents();
        return in_array((string) $event, $captureEvents);
    }

    /**
     * Remove a given capture event
     * 
     * @param  string $event
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function removeCaptureEvent($event)
    {
        $event = (string) $event;
        $captureEvents = $this->getCaptureEvents();
        if (false === ($index = array_search($event, $captureEvents))) {
            return $this;
        }
        unset($captureEvents[$index]);
        $this->setDijitParam('captureEvents', $captureEvents);
        return $this;
    }

    /**
     * Clear all capture events
     * 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function clearCaptureEvents()
    {
        return $this->removeDijitParam('captureEvents');
    }

    /**
     * Add a single event to the dijit
     * 
     * @param  string $event 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function addEvent($event)
    {
        $event = (string) $event;
        $events = $this->getEvents();
        if (in_array($event, $events)) {
            return $this;
        }

        $events[] = (string) $event;
        $this->setDijitParam('events', $events);
        return $this;
    }

    /**
     * Add multiple events
     * 
     * @param  array $events 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function addEvents(array $events)
    {
        foreach ($events as $event) {
            $this->addEvent($event);
        }
        return $this;
    }

    /**
     * Overwrite many events at once
     * 
     * @param  array $events 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setEvents(array $events)
    {
        $this->clearEvents();
        $this->addEvents($events);
        return $this;
    }

    /**
     * Get all events
     * 
     * @return array
     */
    public function getEvents()
    {
        if (!$this->hasDijitParam('events')) {
            return array();
        }
        return $this->getDijitParam('events');
    }

    /**
     * Is a given event registered?
     * 
     * @param  string $event
     * @return bool
     */
    public function hasEvent($event)
    {
        $events = $this->getEvents();
        return in_array((string) $event, $events);
    }

    /**
     * Remove a given event
     * 
     * @param  string $event
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function removeEvent($event)
    {
        $events = $this->getEvents();
        if (false === ($index = array_search($event, $events))) {
            return $this;
        }
        unset($events[$index]);
        $this->setDijitParam('events', $events);
        return $this;
    }

    /**
     * Clear all events
     * 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function clearEvents()
    {
        return $this->removeDijitParam('events');
    }

    /**
     * Add a single editor plugin
     * 
     * @param  string $plugin 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function addPlugin($plugin)
    {
        $plugin = (string) $plugin;
        $plugins = $this->getPlugins();
        if (in_array($plugin, $plugins)) {
            return $this;
        }

        $plugins[] = (string) $plugin;
        $this->setDijitParam('plugins', $plugins);
        return $this;
    }

    /**
     * Add multiple plugins
     * 
     * @param  array $plugins 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function addPlugins(array $plugins)
    {
        foreach ($plugins as $plugin) {
            $this->addPlugin($plugin);
        }
        return $this;
    }

    /**
     * Overwrite many plugins at once
     * 
     * @param  array $plugins 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setPlugins(array $plugins)
    {
        $this->clearPlugins();
        $this->addPlugins($plugins);
        return $this;
    }

    /**
     * Get all plugins
     * 
     * @return array
     */
    public function getPlugins()
    {
        if (!$this->hasDijitParam('plugins')) {
            return array();
        }
        return $this->getDijitParam('plugins');
    }

    /**
     * Is a given plugin registered?
     * 
     * @param  string $plugin
     * @return bool
     */
    public function hasPlugin($plugin)
    {
        $plugins = $this->getPlugins();
        return in_array((string) $plugin, $plugins);
    }

    /**
     * Remove a given plugin
     * 
     * @param  string $plugin
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function removePlugin($plugin)
    {
        $plugins = $this->getPlugins();
        if (false === ($index = array_search($plugin, $plugins))) {
            return $this;
        }
        unset($plugins[$index]);
        $this->setDijitParam('plugins', $plugins);
        return $this;
    }

    /**
     * Clear all plugins
     * 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function clearPlugins()
    {
        return $this->removeDijitParam('plugins');
    }

    /**
     * Set edit action interval
     * 
     * @param  int $interval 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setEditActionInterval($interval)
    {
        return $this->setDijitParam('editActionInterval', (int) $interval);
    }

    /**
     * Get edit action interval; defaults to 3
     * 
     * @return int
     */
    public function getEditActionInterval()
    {
        if (!$this->hasDijitParam('editActionInterval')) {
            $this->setEditActionInterval(3);
        }
        return $this->getDijitParam('editActionInterval');
    }

    /**
     * Set focus on load flag
     * 
     * @param  bool $flag 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setFocusOnLoad($flag)
    {
        return $this->setDijitParam('focusOnLoad', (bool) $flag);
    }

    /**
     * Retrieve focus on load flag
     * 
     * @return bool
     */
    public function getFocusOnLoad()
    {
        if (!$this->hasDijitParam('focusOnLoad')) {
             return false;
        }
        return $this->getDijitParam('focusOnLoad');
    }

    /**
     * Set editor height
     * 
     * @param  string|int $height 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setHeight($height)
    {
        if (!preg_match('/^\d+(em|px|%)?$/i', $height)) {
            require_once 'Zend/Form/Element/Exception.php';
            throw new Zend_Form_Element_Exception('Invalid height provided; must be integer or CSS measurement');
        }
        if (!preg_match('/(em|px|%)$/', $height)) {
            $height .= 'px';
        }
        return $this->setDijitParam('height', $height);
    }

    /**
     * Retrieve height
     * 
     * @return string
     */
    public function getHeight()
    {
        if (!$this->hasDijitParam('height')) {
            return '300px';
        }
        return $this->getDijitParam('height');
    }

    /**
     * Set whether or not to inherit parent's width
     * 
     * @param  bool $flag 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setInheritWidth($flag)
    {
        return $this->setDijitParam('inheritWidth', (bool) $flag);
    }

    /**
     * Whether or not to inherit the parent's width
     * 
     * @return bool
     */
    public function getInheritWidth()
    {
        if (!$this->hasDijitParam('inheritWidth')) {
            return false;
        }
        return $this->getDijitParam('inheritWidth');
    }

    /**
     * Set minimum height of editor
     * 
     * @param  string|int $minHeight 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setMinHeight($minHeight)
    {
        if (!preg_match('/^\d+(em)?$/i', $minHeight)) {
            require_once 'Zend/Form/Element/Exception.php';
            throw new Zend_Form_Element_Exception('Invalid minHeight provided; must be integer or CSS measurement');
        }
        if ('em' != substr($minHeight, -2)) {
            $minHeight .= 'em';
        }
        return $this->setDijitParam('minHeight', $minHeight);
    }

    /**
     * Get minimum height of editor
     * 
     * @return string
     */
    public function getMinHeight()
    {
        if (!$this->hasDijitParam('minHeight')) {
            return '1em';
        }
        return $this->getDijitParam('minHeight');
    }

    /**
     * Add a custom stylesheet
     * 
     * @param  string $styleSheet 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function addStyleSheet($styleSheet)
    {
        $stylesheets = $this->getStyleSheets();
        if (strstr($stylesheets, ';')) {
            $stylesheets = explode(';', $stylesheets);
        } elseif (!empty($stylesheets)) {
            $stylesheets = (array) $stylesheets;
        } else {
            $stylesheets = array();
        }
        if (!in_array($styleSheet, $stylesheets)) {
            $stylesheets[] = (string) $styleSheet;
        }
        return $this->setDijitParam('styleSheets', implode(';', $stylesheets));
    }

    /**
     * Add multiple custom stylesheets
     * 
     * @param  array $styleSheets 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function addStyleSheets(array $styleSheets)
    {
        foreach ($styleSheets as $styleSheet) {
            $this->addStyleSheet($styleSheet);
        }
        return $this;
    }

    /**
     * Overwrite all stylesheets
     * 
     * @param  array $styleSheets 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setStyleSheets(array $styleSheets)
    {
        $this->clearStyleSheets();
        return $this->addStyleSheets($styleSheets);
    }

    /**
     * Get all stylesheets
     * 
     * @return string
     */
    public function getStyleSheets()
    {
        if (!$this->hasDijitParam('styleSheets')) {
            return '';
        }
        return $this->getDijitParam('styleSheets');
    }

    /**
     * Is a given stylesheet registered?
     * 
     * @param  string $styleSheet 
     * @return bool
     */
    public function hasStyleSheet($styleSheet)
    {
        $styleSheets = $this->getStyleSheets();
        $styleSheets = explode(';', $styleSheets);
        return in_array($styleSheet, $styleSheets);
    }

    /**
     * Remove a single stylesheet
     * 
     * @param  string $styleSheet 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function removeStyleSheet($styleSheet)
    {
        $styleSheets = $this->getStyleSheets();
        $styleSheets = explode(';', $styleSheets);
        if (false !== ($index = array_search($styleSheet, $styleSheets))) {
            unset($styleSheets[$index]);
            $this->setDijitParam('styleSheets', implode(';', $styleSheets));
        }
        return $this;
    }

    /**
     * Clear all stylesheets
     * 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function clearStyleSheets()
    {
        if ($this->hasDijitParam('styleSheets')) {
            $this->removeDijitParam('styleSheets');
        }
        return $this;
    }

    /**
     * Set update interval
     * 
     * @param  int $interval 
     * @return Zend_Dojo_Form_Element_Editor
     */
    public function setUpdateInterval($interval)
    {
        return $this->setDijitParam('updateInterval', (int) $interval);
    }

    /**
     * Get update interval
     * 
     * @return int
     */
    public function getUpdateInterval()
    {
        if (!$this->hasDijitParam('updateInterval')) {
             return 200;
        }
        return $this->getDijitParam('updateInterval');
    }
}
Dijit.php000066600000011637151254723460006345 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Form_Element */
require_once 'Zend/Form/Element.php';

/**
 * Base element for dijit elements
 * 
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Dijit.php 13261 2008-12-15 14:32:20Z matthew $
 */
abstract class Zend_Dojo_Form_Element_Dijit extends Zend_Form_Element
{
    /**
     * Dijit parameters
     * @var array
     */
    public $dijitParams = array();

    /**
     * View helper to use
     * @var string
     */
    public $helper;

    /**
     * Constructor
     * 
     * @todo Should we set dojo view helper paths here?
     * @param  mixed $spec 
     * @param  mixed $options 
     * @return void
     */
    public function __construct($spec, $options = null)
    {
        $this->addPrefixPath('Zend_Dojo_Form_Decorator', 'Zend/Dojo/Form/Decorator', 'decorator');
        parent::__construct($spec, $options);
    }

    /**
     * Set a dijit parameter
     * 
     * @param  string $key 
     * @param  mixed $value 
     * @return Zend_Dojo_Form_Element_Dijit
     */
    public function setDijitParam($key, $value)
    {
        $key = (string) $key;
        $this->dijitParams[$key] = $value;
        return $this;
    }

    /**
     * Set multiple dijit params at once
     * 
     * @param  array $params 
     * @return Zend_Dojo_Form_Element_Dijit
     */
    public function setDijitParams(array $params)
    {
        $this->dijitParams = array_merge($this->dijitParams, $params);
        return $this;
    }

    /**
     * Does the given dijit parameter exist?
     * 
     * @param  string $key 
     * @return bool
     */
    public function hasDijitParam($key)
    {
        return array_key_exists($key, $this->dijitParams);
    }

    /**
     * Get a single dijit parameter
     * 
     * @param  string $key 
     * @return mixed
     */
    public function getDijitParam($key)
    {
        $key = (string) $key;
        if ($this->hasDijitParam($key)) {
            return $this->dijitParams[$key];
        }
        return null;
    }

    /**
     * Retrieve all dijit parameters
     * 
     * @return array
     */
    public function getDijitParams()
    {
        return $this->dijitParams;
    }

    /**
     * Remove a single dijit parameter
     * 
     * @param  string $key 
     * @return Zend_Dojo_Form_Element_Dijit
     */
    public function removeDijitParam($key)
    {
        $key = (string) $key;
        if (array_key_exists($key, $this->dijitParams)) {
            unset($this->dijitParams[$key]);
        }
        return $this;
    }

    /**
     * Clear all dijit parameters
     * 
     * @return Zend_Dojo_Form_Element_Dijit
     */
    public function clearDijitParams()
    {
        $this->dijitParams = array();
        return $this;
    }

    /**
     * Load default decorators
     * 
     * @return void
     */
    public function loadDefaultDecorators()
    {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return;
        }

        $decorators = $this->getDecorators();
        if (empty($decorators)) {
            $this->addDecorator('DijitElement')
                 ->addDecorator('Errors')
                 ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
                 ->addDecorator('HtmlTag', array('tag' => 'dd'))
                 ->addDecorator('Label', array('tag' => 'dt'));
        }
    }

    /**
     * Set the view object
     *
     * Ensures that the view object has the dojo view helper path set.
     * 
     * @param  Zend_View_Interface $view 
     * @return Zend_Dojo_Form_Element_Dijit
     */
    public function setView(Zend_View_Interface $view = null)
    {
        if (null !== $view) {
            if (false === $view->getPluginLoader('helper')->getPaths('Zend_Dojo_View_Helper')) {
                $view->addHelperPath('Zend/Dojo/View/Helper', 'Zend_Dojo_View_Helper');
            }
        }
        return parent::setView($view);
    }
}
SubmitButton.php000066600000002545151254723460007737 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_Button */
require_once 'Zend/Dojo/Form/Element/Button.php';

/**
 * Submit button dijit
 * 
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: SubmitButton.php 10621 2008-08-04 00:05:33Z matthew $
 */
class Zend_Dojo_Form_Element_SubmitButton extends Zend_Dojo_Form_Element_Button
{
    /**
     * Use SubmitButton dijit view helper
     * @var string
     */
    public $helper = 'SubmitButton';
}
CheckBox.php000066600000012533151254723460006764 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_Dijit */
require_once 'Zend/Dojo/Form/Element/Dijit.php';

/**
 * CheckBox dijit
 *
 * Note: this would be easier with mixins or traits...
 * 
 * @uses       Zend_Dojo_Form_Element_Dijit
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: CheckBox.php 10001 2008-07-08 21:26:09Z matthew $
 */
class Zend_Dojo_Form_Element_CheckBox extends Zend_Dojo_Form_Element_Dijit
{
    /**
     * Is the checkbox checked?
     * @var bool
     */
    public $checked = false;

    /**
     * Use formCheckbox view helper by default
     * @var string
     */
    public $helper = 'CheckBox';

    /**
     * Value when checked
     * @var string
     */
    protected $_checkedValue = '1';

    /**
     * Value when not checked
     * @var string
     */
    protected $_uncheckedValue = '0';

    /**
     * Current value
     * @var string 0 or 1
     */
    protected $_value = '0';

    /**
     * Set options
     *
     * Intercept checked and unchecked values and set them early; test stored 
     * value against checked and unchecked values after configuration.
     * 
     * @param  array $options 
     * @return Zend_Form_Element_Checkbox
     */
    public function setOptions(array $options)
    {
        if (array_key_exists('checkedValue', $options)) {
            $this->setCheckedValue($options['checkedValue']);
            unset($options['checkedValue']);
        }
        if (array_key_exists('uncheckedValue', $options)) {
            $this->setUncheckedValue($options['uncheckedValue']);
            unset($options['uncheckedValue']);
        }
        parent::setOptions($options);

        $curValue = $this->getValue();
        $test     = array($this->getCheckedValue(), $this->getUncheckedValue());
        if (!in_array($curValue, $test)) {
            $this->setValue($curValue);
        }

        return $this;
    }

    /**
     * Set value
     *
     * If value matches checked value, sets to that value, and sets the checked
     * flag to true.
     *
     * Any other value causes the unchecked value to be set as the current 
     * value, and the checked flag to be set as false.
     *
     * 
     * @param  mixed $value 
     * @return Zend_Form_Element_Checkbox
     */
    public function setValue($value)
    {
        if ($value == $this->getCheckedValue()) {
            parent::setValue($value);
            $this->checked = true;
        } else {
            parent::setValue($this->getUncheckedValue());
            $this->checked = false;
        }
        return $this;
    }

    /**
     * Set checked value
     * 
     * @param  string $value 
     * @return Zend_Form_Element_Checkbox
     */
    public function setCheckedValue($value)
    {
        $this->_checkedValue = (string) $value;
        return $this;
    }

    /**
     * Get value when checked
     * 
     * @return string
     */
    public function getCheckedValue()
    {
        return $this->_checkedValue;
    }

    /**
     * Set unchecked value
     * 
     * @param  string $value 
     * @return Zend_Form_Element_Checkbox
     */
    public function setUncheckedValue($value)
    {
        $this->_uncheckedValue = (string) $value;
        return $this;
    }

    /**
     * Get value when not checked
     * 
     * @return string
     */
    public function getUncheckedValue()
    {
        return $this->_uncheckedValue;
    }

    /**
     * Set checked flag
     * 
     * @param  bool $flag 
     * @return Zend_Form_Element_Checkbox
     */
    public function setChecked($flag)
    {
        $this->checked = (bool) $flag;
        if ($this->checked) {
            $this->setValue($this->getCheckedValue());
        } else {
            $this->setValue($this->getUncheckedValue());
        }
        return $this;
    }

    /**
     * Get checked flag
     * 
     * @return bool
     */
    public function isChecked()
    {
        return $this->checked;
    }

    /**
     * Render
     *
     * Ensure that options property is set when rendering.
     * 
     * @param  Zend_View_Interface $view 
     * @return string
     */
    public function render(Zend_View_Interface $view = null)
    {
        $this->options = array(
            'checked'   => $this->getCheckedValue(),
            'unChecked' => $this->getUncheckedValue(),
        );
        return parent::render($view);
    }
}

TextBox.php000066600000007531151254723460006675 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_Dijit */
require_once 'Zend/Dojo/Form/Element/Dijit.php';

/**
 * TextBox dijit
 * 
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: TextBox.php 10003 2008-07-09 02:40:49Z matthew $
 */
class Zend_Dojo_Form_Element_TextBox extends Zend_Dojo_Form_Element_Dijit
{
    /**
     * Use TextBox dijit view helper
     * @var string
     */
    public $helper = 'TextBox';

    /**
     * Set lowercase flag
     *
     * @param  bool $lowercase
     * @return Zend_Dojo_Form_Element_TextBox
     */
    public function setLowercase($flag)
    {
        $this->setDijitParam('lowercase', (bool) $flag);
        return $this;
    }

    /**
     * Retrieve lowercase flag
     *
     * @return bool
     */
    public function getLowercase()
    {
        if (!$this->hasDijitParam('lowercase')) {
            return false;
        }
        return $this->getDijitParam('lowercase');
    }

    /**
     * Set propercase flag
     *
     * @param  bool $propercase
     * @return Zend_Dojo_Form_Element_TextBox
     */
    public function setPropercase($flag)
    {
        $this->setDijitParam('propercase', (bool) $flag);
        return $this;
    }

    /**
     * Retrieve propercase flag
     *
     * @return bool
     */
    public function getPropercase()
    {
        if (!$this->hasDijitParam('propercase')) {
            return false;
        }
        return $this->getDijitParam('propercase');
    }

    /**
     * Set uppercase flag
     *
     * @param  bool $uppercase
     * @return Zend_Dojo_Form_Element_TextBox
     */
    public function setUppercase($flag)
    {
        $this->setDijitParam('uppercase', (bool) $flag);
        return $this;
    }

    /**
     * Retrieve uppercase flag
     *
     * @return bool
     */
    public function getUppercase()
    {
        if (!$this->hasDijitParam('uppercase')) {
            return false;
        }
        return $this->getDijitParam('uppercase');
    }

    /**
     * Set trim flag
     *
     * @param  bool $trim
     * @return Zend_Dojo_Form_Element_TextBox
     */
    public function setTrim($flag)
    {
        $this->setDijitParam('trim', (bool) $flag);
        return $this;
    }

    /**
     * Retrieve trim flag
     *
     * @return bool
     */
    public function getTrim()
    {
        if (!$this->hasDijitParam('trim')) {
            return false;
        }
        return $this->getDijitParam('trim');
    }

    /**
     * Set maxLength
     *
     * @param  int $length
     * @return Zend_Dojo_Form_Element_TextBox
     */
    public function setMaxLength($length)
    {
        $this->setDijitParam('maxLength', (int) $length);
        return $this;
    }

    /**
     * Retrieve maxLength
     *
     * @return int|null
     */
    public function getMaxLength()
    {
        return $this->getDijitParam('maxLength');
    }
}
TimeTextBox.php000066600000010047151254723460007510 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_DateTextBox */
require_once 'Zend/Dojo/Form/Element/DateTextBox.php';

/**
 * TimeTextBox dijit
 * 
 * @uses       Zend_Dojo_Form_Element_DateTextBox
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: TimeTextBox.php 10079 2008-07-14 10:56:37Z matthew $
 */
class Zend_Dojo_Form_Element_TimeTextBox extends Zend_Dojo_Form_Element_DateTextBox
{
    /**
     * Use TimeTextBox dijit view helper
     * @var string
     */
    public $helper = 'TimeTextBox';

    /**
     * Validate ISO 8601 time format
     * 
     * @param  string $format 
     * @return true
     * @throws Zend_Form_Element_Exception
     */
    protected function _validateIso8601($format)
    {
        if (!preg_match('/^T\d{2}:\d{2}:\d{2}$/', $format)) {
            require_once 'Zend/Form/Element/Exception.php';
            throw new Zend_Form_Element_Exception(sprintf('Invalid format "%s" provided; must match T:00:00:00 format', $format));
        }
        return true;
    }

    /**
     * Set time format pattern
     *
     * @param  string $pattern
     * @return Zend_Dojo_Form_Element_NumberTextBox
     */
    public function setTimePattern($pattern)
    {
        $this->setConstraint('timePattern', (string) $pattern);
        return $this;
    }

    /**
     * Retrieve time format pattern
     *
     * @return string|null
     */
    public function getTimePattern()
    {
        return $this->getConstraint('timePattern');
    }

    /**
     * Set clickableIncrement
     *
     * @param  string $format
     * @return Zend_Dojo_Form_Element_NumberTextBox
     */
    public function setClickableIncrement($format)
    {
        $format = (string) $format;
        $this->_validateIso8601($format);
        $this->setConstraint('clickableIncrement', $format);
        return $this;
    }

    /**
     * Retrieve clickableIncrement
     *
     * @return string|null
     */
    public function getClickableIncrement()
    {
        return $this->getConstraint('clickableIncrement');
    }

    /**
     * Set visibleIncrement
     *
     * @param  string $format
     * @return Zend_Dojo_Form_Element_NumberTextBox
     */
    public function setVisibleIncrement($format)
    {
        $format = (string) $format;
        $this->_validateIso8601($format);
        $this->setConstraint('visibleIncrement', $format);
        return $this;
    }

    /**
     * Retrieve visibleIncrement
     *
     * @return string|null
     */
    public function getVisibleIncrement()
    {
        return $this->getConstraint('visibleIncrement');
    }

    /**
     * Set visibleRange
     *
     * @param  string $format
     * @return Zend_Dojo_Form_Element_NumberTextBox
     */
    public function setVisibleRange($format)
    {
        $format = (string) $format;
        $this->_validateIso8601($format);
        $this->setConstraint('visibleRange', $format);
        return $this;
    }

    /**
     * Retrieve visibleRange
     *
     * @return string|null
     */
    public function getVisibleRange()
    {
        return $this->getConstraint('visibleRange');
    }
}
Textarea.php000066600000002501151254723460007045 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Form
 * @subpackage Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';

/**
 * Textarea form element
 * 
 * @category   Zend
 * @package    Zend_Form
 * @subpackage Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Textarea.php 8064 2008-02-16 10:58:39Z thomas $
 */
class Zend_Form_Element_Textarea extends Zend_Form_Element_Xhtml
{
    /**
     * Use formTextarea view helper by default
     * @var string
     */
    public $helper = 'formTextarea';
}
ComboBox.php000066600000011242151254723460007002 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_DijitMulti */
require_once 'Zend/Dojo/Form/Element/DijitMulti.php';

/**
 * ComboBox dijit
 * 
 * @uses       Zend_Dojo_Form_Element_DijitMulti
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: ComboBox.php 10723 2008-08-06 15:30:18Z matthew $
 */
class Zend_Dojo_Form_Element_ComboBox extends Zend_Dojo_Form_Element_DijitMulti
{
    /**
     * Use ComboBox dijit view helper
     * @var string
     */
    public $helper = 'ComboBox';

    /**
     * Flag: autoregister inArray validator?
     * @var bool
     */
    protected $_registerInArrayValidator = false;

    /**
     * Get datastore information 
     * 
     * @return array
     */
    public function getStoreInfo()
    {
        if (!$this->hasDijitParam('store')) {
            $this->dijitParams['store'] = array();
        }
        return $this->dijitParams['store'];
    }

    /**
     * Set datastore identifier
     * 
     * @param  string $identifier 
     * @return Zend_Dojo_Form_Element_ComboBox
     */
    public function setStoreId($identifier)
    {
        $store = $this->getStoreInfo();
        $store['store'] = (string) $identifier;
        $this->setDijitParam('store', $store);
        return $this;
    }

    /**
     * Get datastore identifier 
     * 
     * @return string|null
     */
    public function getStoreId()
    {
        $store = $this->getStoreInfo();
        if (array_key_exists('store', $store)) {
            return $store['store'];
        }
        return null;
    }

    /**
     * Set datastore dijit type
     * 
     * @param  string $dojoType 
     * @return Zend_Dojo_Form_Element_ComboBox
     */
    public function setStoreType($dojoType)
    {
        $store = $this->getStoreInfo();
        $store['type'] = (string) $dojoType;
        $this->setDijitParam('store', $store);
        return $this;
    }

    /**
     * Get datastore dijit type 
     * 
     * @return string|null
     */
    public function getStoreType()
    {
        $store = $this->getStoreInfo();
        if (array_key_exists('type', $store)) {
            return $store['type'];
        }
        return null;
    }

    /**
     * Set datastore parameters
     * 
     * @param  array $params 
     * @return Zend_Dojo_Form_Element_ComboBox
     */
    public function setStoreParams(array $params)
    {
        $store = $this->getStoreInfo();
        $store['params'] = $params;
        $this->setDijitParam('store', $store);
        return $this;
    }

    /**
     * Get datastore params
     * 
     * @return array
     */
    public function getStoreParams()
    {
        $store = $this->getStoreInfo();
        if (array_key_exists('params', $store)) {
            return $store['params'];
        }
        return array();
    }

    /**
     * Set autocomplete flag
     * 
     * @param  bool $flag 
     * @return Zend_Dojo_Form_Element_ComboBox
     */
    public function setAutocomplete($flag)
    {
        $this->setDijitParam('autocomplete', (bool) $flag);
        return $this;
    }

    /**
     * Get autocomplete flag
     * 
     * @return bool
     */
    public function getAutocomplete()
    {
        if (!$this->hasDijitParam('autocomplete')) {
            return false;
        }
        return $this->getDijitParam('autocomplete');
    }

    /**
     * Is the value valid?
     * 
     * @param  string $value 
     * @param  mixed $context 
     * @return bool
     */
    public function isValid($value, $context = null)
    {
        $storeInfo = $this->getStoreInfo();
        if (!empty($storeInfo)) {
            $this->setRegisterInArrayValidator(false);
        }
        return parent::isValid($value, $context);
    }
}
Button.php000066600000006246151254723460006555 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_Dijit */
require_once 'Zend/Dojo/Form/Element/Dijit.php';

/**
 * Button dijit
 * 
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Button.php 10091 2008-07-15 03:46:37Z matthew $
 */
class Zend_Dojo_Form_Element_Button extends Zend_Dojo_Form_Element_Dijit
{
    /**
     * Use Button dijit view helper
     * @var string
     */
    public $helper = 'Button';

    /**
     * Constructor
     * 
     * @param  string|array|Zend_Config $spec Element name or configuration
     * @param  string|array|Zend_Config $options Element value or configuration
     * @return void
     */
    public function __construct($spec, $options = null)
    {
        if (is_string($spec) && ((null !== $options) && is_string($options))) {
            $options = array('label' => $options);
        }

        parent::__construct($spec, $options);
    }

    /**
     * Return label
     *
     * If no label is present, returns the currently set name.
     *
     * If a translator is present, returns the translated label.
     * 
     * @return string
     */
    public function getLabel()
    {
        $value = parent::getLabel();

        if (null === $value) {
            $value = $this->getName();
        }

        if (null !== ($translator = $this->getTranslator())) {
            return $translator->translate($value);
        }

        return $value;
    }

    /**
     * Has this submit button been selected?
     * 
     * @return bool
     */
    public function isChecked()
    {
        $value = $this->getValue();

        if (empty($value)) {
            return false;
        }
        if ($value != $this->getLabel()) {
            return false;
        }

        return true;
    }

    /**
     * Default decorators
     *
     * Uses only 'DijitElement' and 'DtDdWrapper' decorators by default.
     * 
     * @return void
     */
    public function loadDefaultDecorators()
    {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return;
        }

        $decorators = $this->getDecorators();
        if (empty($decorators)) {
            $this->addDecorator('DijitElement')
                 ->addDecorator('DtDdWrapper');
        }
    }
}
RadioButton.php000066600000002610151254723460007523 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_DijitMulti */
require_once 'Zend/Dojo/Form/Element/DijitMulti.php';

/**
 * RadioButton dijit
 * 
 * @uses       Zend_Dojo_Form_Element_DijitMulti
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: RadioButton.php 10003 2008-07-09 02:40:49Z matthew $
 */
class Zend_Dojo_Form_Element_RadioButton extends Zend_Dojo_Form_Element_DijitMulti
{
    /**
     * Use RadioButton dijit view helper
     * @var string
     */
    public $helper = 'RadioButton';
}
DateTextBox.php000066600000012471151254723460007472 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_ValidationTextBox */
require_once 'Zend/Dojo/Form/Element/ValidationTextBox.php';

/**
 * DateTextBox dijit
 * 
 * @uses       Zend_Dojo_Form_Element_ValidationTextBox
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: DateTextBox.php 10079 2008-07-14 10:56:37Z matthew $
 */
class Zend_Dojo_Form_Element_DateTextBox extends Zend_Dojo_Form_Element_ValidationTextBox
{
    /**
     * Use DateTextBox dijit view helper
     * @var string
     */
    public $helper = 'DateTextBox';

    /**
     * Allowed formatLength types
     * @var array
     */
    protected $_allowedFormatTypes = array(
        'long',
        'short',
        'medium',
        'full',
    );

    /**
     * Allowed selector types
     * @var array
     */
    protected $_allowedSelectorTypes = array(
        'time',
        'date',
    );

    /**
     * Set am,pm flag
     *
     * @param  bool $am,pm
     * @return Zend_Dojo_Form_Element_DateTextBox
     */
    public function setAmPm($flag)
    {
        $this->setConstraint('am,pm', (bool) $flag);
        return $this;
    }

    /**
     * Retrieve am,pm flag
     *
     * @return bool
     */
    public function getAmPm()
    {
        if (!$this->hasConstraint('am,pm')) {
            return false;
        }
        return ('true' ==$this->getConstraint('am,pm'));
    }

    /**
     * Set strict flag
     *
     * @param  bool $strict
     * @return Zend_Dojo_Form_Element_DateTextBox
     */
    public function setStrict($flag)
    {
        $this->setConstraint('strict', (bool) $flag);
        return $this;
    }

    /**
     * Retrieve strict flag
     *
     * @return bool
     */
    public function getStrict()
    {
        if (!$this->hasConstraint('strict')) {
            return false;
        }
        return ('true' == $this->getConstraint('strict'));
    }

    /**
     * Set locale
     *
     * @param  string $locale
     * @return Zend_Dojo_Form_Element_DateTextBox
     */
    public function setLocale($locale)
    {
        $this->setConstraint('locale', (string) $locale);
        return $this;
    }

    /**
     * Retrieve locale
     *
     * @return string|null
     */
    public function getLocale()
    {
        return $this->getConstraint('locale');
    }

    /**
     * Set date format pattern
     *
     * @param  string $pattern
     * @return Zend_Dojo_Form_Element_NumberTextBox
     */
    public function setDatePattern($pattern)
    {
        $this->setConstraint('datePattern', (string) $pattern);
        return $this;
    }

    /**
     * Retrieve date format pattern
     *
     * @return string|null
     */
    public function getDatePattern()
    {
        return $this->getConstraint('datePattern');
    }

    /**
     * Set numeric format formatLength
     *
     * @see    $_allowedFormatTypes
     * @param  string $formatLength
     * @return Zend_Dojo_Form_Element_NumberTextBox
     */
    public function setFormatLength($formatLength)
    {
        $formatLength = strtolower($formatLength);
        if (!in_array($formatLength, $this->_allowedFormatTypes)) {
            require_once 'Zend/Form/Element/Exception.php';
            throw new Zend_Form_Element_Exception(sprintf('Invalid formatLength "%s" specified', $formatLength));
        }

        $this->setConstraint('formatLength', $formatLength);
        return $this;
    }

    /**
     * Retrieve formatLength
     *
     * @return string|null
     */
    public function getFormatLength()
    {
        return $this->getConstraint('formatLength');
    }

    /**
     * Set numeric format Selector
     *
     * @see    $_allowedSelectorTypes
     * @param  string $selector
     * @return Zend_Dojo_Form_Element_NumberTextBox
     */
    public function setSelector($selector)
    {
        $selector = strtolower($selector);
        if (!in_array($selector, $this->_allowedSelectorTypes)) {
            require_once 'Zend/Form/Element/Exception.php';
            throw new Zend_Form_Element_Exception(sprintf('Invalid Selector "%s" specified', $selector));
        }

        $this->setConstraint('selector', $selector);
        return $this;
    }

    /**
     * Retrieve selector
     *
     * @return string|null
     */
    public function getSelector()
    {
        return $this->getConstraint('selector');
    }
}
ValidationTextBox.php000066600000012713151254723460010706 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Dojo_Form_Element_TextBox */
require_once 'Zend/Dojo/Form/Element/TextBox.php';

/**
 * ValidationTextBox dijit
 * 
 * @uses       Zend_Dojo_Form_Element_TextBox
 * @package    Zend_Dojo
 * @subpackage Form_Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: ValidationTextBox.php 10079 2008-07-14 10:56:37Z matthew $
 */
class Zend_Dojo_Form_Element_ValidationTextBox extends Zend_Dojo_Form_Element_TextBox
{
    /**
     * Use ValidationTextBox dijit view helper
     * @var string
     */
    public $helper = 'ValidationTextBox';

    /**
     * Set invalidMessage
     *
     * @param  string $message
     * @return Zend_Dojo_Form_Element_ValidationTextBox
     */
    public function setInvalidMessage($message)
    {
        $this->setDijitParam('invalidMessage', (string) $message);
        return $this;
    }

    /**
     * Retrieve invalidMessage
     *
     * @return string|null
     */
    public function getInvalidMessage()
    {
        return $this->getDijitParam('invalidMessage');
    }

    /**
     * Set promptMessage
     *
     * @param  string $message
     * @return Zend_Dojo_Form_Element_ValidationTextBox
     */
    public function setPromptMessage($message)
    {
        $this->setDijitParam('promptMessage', (string) $message);
        return $this;
    }

    /**
     * Retrieve promptMessage
     *
     * @return string|null
     */
    public function getPromptMessage()
    {
        return $this->getDijitParam('promptMessage');
    }

    /**
     * Set regExp
     *
     * @param  string $regexp
     * @return Zend_Dojo_Form_Element_ValidationTextBox
     */
    public function setRegExp($regexp)
    {
        $this->setDijitParam('regExp', (string) $regexp);
        return $this;
    }

    /**
     * Retrieve regExp
     *
     * @return string|null
     */
    public function getRegExp()
    {
        return $this->getDijitParam('regExp');
    }

    /**
     * Set an individual constraint
     * 
     * @param  string $key 
     * @param  mixed $value 
     * @return Zend_Dojo_Form_Element_ValidationTextBox
     */
    public function setConstraint($key, $value)
    {
        $constraints = $this->getConstraints();
        $constraints[(string) $key] = $value;
        $this->setConstraints($constraints);
        return $this;
    }

    /**
     * Set validation constraints
     *
     * Refer to Dojo dijit.form.ValidationTextBox documentation for valid 
     * structure.
     * 
     * @param  array $constraints 
     * @return Zend_Dojo_Form_Element_ValidationTextBox
     */
    public function setConstraints(array $constraints)
    {
        array_walk_recursive($constraints, array($this, '_castBoolToString'));
        $this->setDijitParam('constraints', $constraints);
        return $this;
    }

    /**
     * Is the given constraint set?
     * 
     * @param  string $key 
     * @return bool
     */
    public function hasConstraint($key)
    {
        $constraints = $this->getConstraints();
        return array_key_exists((string)$key, $constraints);
    }

    /**
     * Get an individual constraint
     * 
     * @param  string $key 
     * @return mixed
     */
    public function getConstraint($key)
    {
        $key = (string) $key;
        if (!$this->hasConstraint($key)) {
            return null;
        }
        return $this->dijitParams['constraints'][$key];
    }

    /**
     * Get constraints
     * 
     * @return array
     */
    public function getConstraints()
    {
        if ($this->hasDijitParam('constraints')) {
            return $this->getDijitParam('constraints');
        }
        return array();
    }

    /**
     * Remove a single constraint
     * 
     * @param  string $key 
     * @return Zend_Dojo_Form_Element_ValidationTextBox
     */
    public function removeConstraint($key)
    {
        $key = (string) $key;
        if ($this->hasConstraint($key)) {
            unset($this->dijitParams['constraints'][$key]);
        }
        return $this;
    }

    /**
     * Clear all constraints
     * 
     * @return Zend_Dojo_Form_Element_ValidationTextBox
     */
    public function clearConstraints()
    {
        return $this->removeDijitParam('constraints');
    }

    /**
     * Cast a boolean value to a string
     * 
     * @param  mixed $item 
     * @param  string $key 
     * @return void
     */
    protected function _castBoolToString(&$item, $key)
    {
        if (is_bool($item)) {
            $item = ($item) ? 'true' : 'false';
        }
    }
}
Submit.php000066600000006210151255747300006534 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Form
 * @subpackage Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';

/**
 * Submit form element
 * 
 * @category   Zend
 * @package    Zend_Form
 * @subpackage Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Submit.php 8585 2008-03-06 19:32:34Z matthew $
 */
class Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
{
    /**
     * Default view helper to use
     * @var string
     */
    public $helper = 'formSubmit';

    /**
     * Constructor
     * 
     * @param  string|array|Zend_Config $spec Element name or configuration
     * @param  string|array|Zend_Config $options Element value or configuration
     * @return void
     */
    public function __construct($spec, $options = null)
    {
        if (is_string($spec) && ((null !== $options) && is_string($options))) {
            $options = array('label' => $options);
        }

        parent::__construct($spec, $options);
    }

    /**
     * Return label
     *
     * If no label is present, returns the currently set name.
     *
     * If a translator is present, returns the translated label.
     * 
     * @return string
     */
    public function getLabel()
    {
        $value = parent::getLabel();

        if (null === $value) {
            $value = $this->getName();
        }

        if (null !== ($translator = $this->getTranslator())) {
            return $translator->translate($value);
        }

        return $value;
    }

    /**
     * Has this submit button been selected?
     * 
     * @return bool
     */
    public function isChecked()
    {
        $value = $this->getValue();

        if (empty($value)) {
            return false;
        }
        if ($value != $this->getLabel()) {
            return false;
        }

        return true;
    }

    /**
     * Default decorators
     *
     * Uses only 'Submit' and 'DtDdWrapper' decorators by default.
     * 
     * @return void
     */
    public function loadDefaultDecorators()
    {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return;
        }

        $decorators = $this->getDecorators();
        if (empty($decorators)) {
            $this->addDecorator('ViewHelper')
                 ->addDecorator('DtDdWrapper');
        }
    }
}
Hash.php000066600000014003151255747300006153 0ustar00<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Form
 * @subpackage Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';

/**
 * CSRF form protection
 * 
 * @category   Zend
 * @package    Zend_Form
 * @subpackage Element
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Hash.php 11332 2008-09-10 16:35:45Z matthew $
 */
class Zend_Form_Element_Hash extends Zend_Form_Element_Xhtml
{
    /**
     * Use formHidden view helper by default
     * @var string
     */
    public $helper = 'formHidden';

    /**
     * Actual hash used.
     * 
     * @var mixed
     */
    protected $_hash;

    /**
     * Salt for CSRF token
     * @var string
     */
    protected $_salt = 'salt';

    /**
     * @var Zend_Session_Namespace
     */
    protected $_session;

    /**
     * TTL for CSRF token
     * @var int
     */
    protected $_timeout = 300;

    /**
     * Constructor
     *
     * Creates session namespace for CSRF token, and adds validator for CSRF 
     * token.
     * 
     * @param  string|array|Zend_Config $spec 
     * @param  array|Zend_Config $options 
     * @return void
     */
    public function __construct($spec, $options = null)
    {
        parent::__construct($spec, $options);

        $this->setAllowEmpty(false)
             ->setRequired(true)
             ->initCsrfValidator();
    }

    /**
     * Set session object
     * 
     * @param  Zend_Session_Namespace $session 
     * @return Zend_Form_Element_Hash
     */
    public function setSession($session)
    {
        $this->_session = $session;
        return $this;
    }

    /**
     * Get session object
     *
     * Instantiate session object if none currently exists
     * 
     * @return Zend_Session_Namespace
     */
    public function getSession()
    {
        if (null === $this->_session) {
            require_once 'Zend/Session/Namespace.php';
            $this->_session = new Zend_Session_Namespace($this->getSessionName());
        }
        return $this->_session;
    }

    /**
     * Initialize CSRF validator
     *
     * Creates Session namespace, and initializes CSRF token in session. 
     * Additionally, adds validator for validating CSRF token.
     * 
     * @return Zend_Form_Element_Hash
     */
    public function initCsrfValidator()
    {
        $session = $this->getSession();
        if (isset($session->hash)) {
            $rightHash = $session->hash;
        } else {
            $rightHash = null;
        }

        $this->addValidator('Identical', true, array($rightHash));
        return $this;
    }

    /**
     * Salt for CSRF token
     *
     * @param  string $salt
     * @return Zend_Form_Element_Hash
     */
    public function setSalt($salt)
    {
        $this->_salt = (string) $salt;
        return $this;
    }

    /**
     * Retrieve salt for CSRF token
     *
     * @return string
     */
    public function getSalt()
    {
        return $this->_salt;
    }

    /**
     * Retrieve CSRF token
     *
     * If no CSRF token currently exists, generates one.
     * 
     * @return string
     */
    public function getHash()
    {
        if (null === $this->_hash) {
            $this->_generateHash();
        }
        return $this->_hash;
    }

    /**
     * Get session namespace for CSRF token
     *
     * Generates a session namespace based on salt, element name, and class.
     * 
     * @return string
     */
    public function getSessionName()
    {
        return __CLASS__ . '_' . $this->getSalt() . '_' . $this->getName();
    }

    /**
     * Set timeout for CSRF session token
     * 
     * @param  int $ttl 
     * @return Zend_Form_Element_Hash
     */
    public function setTimeout($ttl)
    {
        $this->_timeout = (int) $ttl;
        return $this;
    }

    /**
     * Get CSRF session token timeout
     * 
     * @return int
     */
    public function getTimeout()
    {
        return $this->_timeout;
    }

    /**
     * Override getLabel() to always be empty
     * 
     * @return null
     */
    public function getLabel()
    {
        return null;
    }

    /**
     * Initialize CSRF token in session
     * 
     * @return void
     */
    public function initCsrfToken()
    {
        $session = $this->getSession();
        $session->setExpirationHops(1, null, true);
        $session->setExpirationSeconds($this->getTimeout());
        $session->hash = $this->getHash();
    }

    /**
     * Render CSRF token in form
     * 
     * @param  Zend_View_Interface $view 
     * @return string
     */
    public function render(Zend_View_Interface $view = null)
    {
        $this->initCsrfToken();
        return parent::render($view);
    }

    /**
     * Generate CSRF token
     *
     * Generates CSRF token and stores both in {@link $_hash} and element 
     * value.
     * 
     * @return void
     */
    protected function _generateHash()
    {
        $this->_hash = md5(
            mt_rand(1,1000000) 
            .  $this->getSalt() 
            .  $this->getName() 
            .  mt_rand(1,1000000)
        );
        $this->setValue($this->_hash);
    }
}