Perforce Chronicle 2012.2/486814
API Documentation

Youtube_Form_VideoWidget Class Reference

This is the yotube video widget config form, which accepts configuration options for the youtube video stream. More...

Inheritance diagram for Youtube_Form_VideoWidget:
P4Cms_Form_SubForm

List of all members.

Public Member Functions

 init ()
 Defines the elements that make up the widget config form.
 isValid ($data)
 Perform extra, form-specific validation on the form data.
 setDefaults (array $defaults)
 Whenever values are set on the form, show/hide the video size fieldset as appropriate.

Static Public Member Functions

static getHeight ($size)
 Accessor for the set height for a given size.
static getWidth ($size)
 Accessor for the set width for a given size.
static hasDimension ($size)
 Verifies whether or not $size is a valid video dimension.

Public Attributes

const CONTROLS_ALWAYS_SHOW = 0
const CONTROLS_FADE_ALL = 1
const CONTROLS_FADE_BAR = 2
const CONTROLS_NEVER_SHOW = 3
const DIMENSION_CUSTOM = 'custom'
const DIMENSION_EXTRA_LARGE = 'extra-large'
const DIMENSION_LARGE = 'large'
const DIMENSION_MEDIUM = 'medium'
const DIMENSION_SMALL = 'small'
const DIMENSION_WIDE_EXTRA_LARGE = 'wide-extra-large'
const DIMENSION_WIDE_LARGE = 'wide-large'
const DIMENSION_WIDE_MEDIUM = 'wide-medium'
const DIMENSION_WIDE_SMALL = 'wide-small'

Detailed Description

This is the yotube video widget config form, which accepts configuration options for the youtube video stream.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

static Youtube_Form_VideoWidget::getHeight ( size) [static]

Accessor for the set height for a given size.

Parameters:
string$sizethe size for which to retrieve the height
Returns:
string the set height for this size of video
    {
        return self::$_dimensions[$size]['height'];
    }
static Youtube_Form_VideoWidget::getWidth ( size) [static]

Accessor for the set width for a given size.

Parameters:
string$sizethe size for which to retrieve the width
Returns:
string the set width for this size of video
    {
        return self::$_dimensions[$size]['width'];
    }
static Youtube_Form_VideoWidget::hasDimension ( size) [static]

Verifies whether or not $size is a valid video dimension.

Parameters:
string$sizethe size to check for a dimension
Returns:
boolean whether or not $size is a valid video dimension
    {
        return array_key_exists($size, self::$_dimensions);
    }
Youtube_Form_VideoWidget::init ( )

Defines the elements that make up the widget config form.

Default values are based off of youtube player default settings.

This method is called automatically when the form object is created.

    {
        $this->addElement(
            'text',
            'videoUrl',
            array(
                'label'         => 'Video Url',
                'size'          => 40,
                'required'      => true
            )
        );

        // Append height and width dimensions to the size displayed to the user.
        // Do this dynamically, so that if the dimensions are adjusted, there's only one place
        // to maintain it.
        $sizeOptions = array();
        foreach ($this->_dimensionOptions as $key => $options) {
            $sizeOptions[$key] = array();
            if (is_array($options)) {
                foreach ($options as $size => $option) {
                    $sizeOptions[$key][$size] = $option;
                    if (self::hasDimension($size)) {
                        $sizeOptions[$key][$size] .= ' ('
                                                  . $this->getWidth($size) . 'x'
                                                  . $this->getHeight($size) . ')';
                    }
                }
            } else {
                $sizeOptions[$key] = $options;
            }
        }

        $this->addElement(
            'select',
            'videoSize',
            array(
                'label'         => 'Size',
                'autocomplete'  => false,
                'multiOptions'  => $sizeOptions,
                'onChange'      =>
                       "var prefix = this.id.replace(/[^-]+-videoSize$/, '');"
                    .  "if (this.value == '" . self::DIMENSION_CUSTOM . "') {"
                    .  "    p4cms.ui.show(prefix + 'config-videoCustomSize');"
                    .  "} else {"
                    .  "    p4cms.ui.hide(prefix + 'config-videoCustomSize', {duration: 0});"
                    .  "}"
                    .  "var ds = dijit._dialogStack;"
                    .  "for (var index = ds.length; index > 0; index--) {"
                    .  "    if (dojo.query('#' + this.id, ds[index-1].domNode).length) {"
                    .  "        ds[index-1].updateLayout();"
                    .  "        break;"
                    .  "    }"
                    .  "}",
                'value'         => $this->_defaultVideoSize
            )
        );

        $this->addElement(
            'text',
            'videoWidth',
            array(
                'label'         => 'Width',
                'validators'    => array(
                    'digits'
                )
            )
        );

        $this->addElement(
            'text',
            'videoHeight',
            array(
                'label'         => 'Height',
                'validators'    => array(
                    'digits'
                )
            )
        );

        $this->addDisplayGroup(
            array('videoWidth', 'videoHeight'),
            'videoCustomSize',
            array('style' => 'display: none;')
        );

        $this->addElement(
            'select',
            'controls',
            array(
                'label'         => 'Show Controls',
                'multiOptions'  => $this->_controlOptions,
                'onChange'      =>
                        "var prefix     = this.id.replace(/[^-]+-controls/, '');"
                    .   "var fullscreen = dojo.query('#'+prefix+'config-allowFullscreen')[0];"
                    .   "if (this.value == " . self::CONTROLS_NEVER_SHOW . ") {"
                    .   "   dojo.attr(fullscreen, 'checked', false);"
                    .   "   dojo.attr(fullscreen, 'disabled', true);"
                    .   "} else {"
                    .   "   dojo.attr(fullscreen, 'checked', true);"
                    .   "   dojo.attr(fullscreen, 'disabled', false);"
                    .   "}",
                'value'         => $this->_defaultControlOption
            )
        );

        $this->addElement(
            'checkbox',
            'autoplay',
            array(
                'label'         => 'Play Automatically',
                'value'         => true
            )
        );

        $this->addElement(
            'checkbox',
            'loop',
            array(
                'label'         => 'Loop Video',
                'value'         => false
            )
        );

        $this->addElement(
            'checkbox',
            'allowFullscreen',
            array(
                'label'         => 'Allow Fullscreen',
                'value'         => true
            )
        );


        $this->addElement(
            'checkbox',
            'playHd',
            array(
                'label'         => 'Default to HD',
                'value'         => true
            )
        );

        $this->addElement(
            'checkbox',
            'showAnnotations',
            array(
                'label'         => 'Show Annotations',
                'value'         => false
            )
        );

        $this->addElement(
            'checkbox',
            'showRelated',
            array(
                'label'         => 'Show Related Videos',
                'value'         => false
            )
        );
    }
Youtube_Form_VideoWidget::isValid ( data)

Perform extra, form-specific validation on the form data.

Ensures the url provided is hosted on youtube, and that a video id is provided.

Parameters:
array$datathe array of form submission data to validate
Returns:
boolean whether or not $data is valid
    {
        if (!parent::isValid($data)) {
            return false;
        }

        // ensure url is valid
        try {
            $uri = Zend_Uri::factory($data['config']['videoUrl']);
        }
        catch (Exception $e) {
            // any exception invalidates the url
            $this->getElement('videoUrl')->addError(
                "Invalid video URL."
            );
            return false;
        }

        // ensure video id is set and not empty
        $query = $uri->getQueryAsArray();
        if (!array_key_exists('v', $query) || empty($query['v'])) {
            $this->getElement('videoUrl')->addError(
                "Invalid video URL - no video id found."
            );
            return false;
        }

        // ensure domain is youtube
        $host = explode('.', $uri->getHost());
        if ($host[0] == 'www') {
            array_shift($host);
        }
        // verify the host has at least one youtube in it.
        // usual format is youtube.com, so it should return right away
        foreach ($host as $segment) {
            if ($segment == 'youtube') {
                return true;
            }
        }
        
        // no youtube in domain
        $this->getElement('videoUrl')->addError(
            "Invalid video URL - must be on youtube domain."
        );
        return false;
    }
Youtube_Form_VideoWidget::setDefaults ( array $  defaults)

Whenever values are set on the form, show/hide the video size fieldset as appropriate.

Parameters:
array$defaultsthe values to populate the form
Returns:
Widget_Form_ImageWidget provides fluent interface
    {
        if (isset($defaults['config']['videoSize'])
            && $defaults['config']['videoSize'] == self::DIMENSION_CUSTOM
        ) {
            $this->getDisplayGroup('videoCustomSize')->setAttrib('style', 'display: block;');
        }

        if (isset($defaults['config']['controls'])
            && $defaults['config']['controls'] == self::CONTROLS_NEVER_SHOW
        ) {
            $this->getElement('allowFullscreen')->setAttrib('disabled', true);
        }

        return parent::setDefaults($defaults);
    }

Member Data Documentation


The documentation for this class was generated from the following file: