Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Youtube input class for Form Builder
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 11 Mar 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\cms\Fields;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Youtube input class for Form Builder
|
||||
*/
|
||||
class _Youtube extends \IPS\Helpers\Form\Text
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
*/
|
||||
public $childDefaultOptions = array(
|
||||
'parameters' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Sets that the field is required if there is a minimum length and vice-versa
|
||||
*
|
||||
* @see \IPS\Helpers\Form\Abstract::__construct
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->childDefaultOptions['placeholder'] = \IPS\Member::loggedIn()->language()->addToStack('field_placeholder_youtube');
|
||||
|
||||
/* Call parent constructor */
|
||||
call_user_func_array( 'parent::__construct', func_get_args() );
|
||||
|
||||
$this->formType = 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display value
|
||||
*
|
||||
* @param mixed $value Stored value from form
|
||||
* @param \IPS\cms\Field $customField Custom Field Object
|
||||
* @return string
|
||||
*/
|
||||
public static function displayValue( $value, $customField )
|
||||
{
|
||||
$url = new \IPS\Http\Url( $value );
|
||||
|
||||
if ( isset( $url->queryString['v'] ) )
|
||||
{
|
||||
$url = 'https://www.youtube.com/embed/' . $url->queryString['v'];
|
||||
}
|
||||
else if ( $url->data['host'] === 'youtu.be' and ! mb_strpos( $url->data['path'], 'embed' ) )
|
||||
{
|
||||
$url = 'https://www.youtube.com/embed/' . trim( $url->data['path'], '/' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = $value;
|
||||
}
|
||||
|
||||
$params = $customField->extra;
|
||||
|
||||
if ( ! isset( $params['width'] ) )
|
||||
{
|
||||
$params['width'] = 640;
|
||||
}
|
||||
|
||||
if ( ! isset( $params['height'] ) )
|
||||
{
|
||||
$params['height'] = 390;
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'records', 'cms', 'global' )->youtube( $url, $params );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \DomainException
|
||||
* @return TRUE
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
parent::validate();
|
||||
|
||||
if ( $this->value )
|
||||
{
|
||||
/* Check the URL is valid */
|
||||
if ( !( $this->value instanceof \IPS\Http\Url ) )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_url_bad');
|
||||
}
|
||||
|
||||
/* Check its a valid Youtube URL */
|
||||
if ( ! mb_stristr( $this->value->data['host'], 'youtube.' ) and ! mb_stristr( $this->value->data['host'], 'youtu.be' ) )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_url_bad');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
$val = parent::getValue();
|
||||
if ( $val and !mb_strpos( $val, '://' ) )
|
||||
{
|
||||
$val = "http://{$val}";
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format Value
|
||||
*
|
||||
* @return \IPS\Http\Url|string
|
||||
*/
|
||||
public function formatValue()
|
||||
{
|
||||
if ( $this->value and !( $this->value instanceof \IPS\Http\Url ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Http\Url( $this->value );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user