Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,40 +12,49 @@
|
||||
namespace IPS\cms\Fields;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use InvalidArgumentException;
|
||||
use IPS\cms\Fields;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Youtube input class for Form Builder
|
||||
* YouTube input class for Form Builder
|
||||
*/
|
||||
class _Youtube extends \IPS\Helpers\Form\Text
|
||||
class Youtube extends Text
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
*/
|
||||
public $childDefaultOptions = array(
|
||||
public array $childDefaultOptions = array(
|
||||
'parameters' => array()
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param mixed $defaultValue Default value
|
||||
* @param bool|NULL $required Required? (NULL for not required, but appears to be so)
|
||||
* @param array $options Type-specific options
|
||||
* @param callback $customValidationCode Custom validation code
|
||||
* @param string $prefix HTML to show before input field
|
||||
* @param string $suffix HTML to show after input field
|
||||
* @param string $id The ID to add to the row
|
||||
* @return void
|
||||
* @param string $name Name
|
||||
* @param mixed $defaultValue Default value
|
||||
* @param bool|null $required Required? (NULL for not required, but appears to be so)
|
||||
* @param array $options Type-specific options
|
||||
* @param callable|null $customValidationCode Custom validation code
|
||||
* @param string|null $prefix HTML to show before input field
|
||||
* @param string|null $suffix HTML to show after input field
|
||||
* @param string|null $id The ID to add to the row
|
||||
*/
|
||||
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
|
||||
public function __construct( string $name, mixed $defaultValue=NULL, bool $required=FALSE, array $options=array(), callable $customValidationCode=NULL, string $prefix=NULL, string $suffix=NULL, string $id=NULL )
|
||||
{
|
||||
$this->childDefaultOptions['placeholder'] = \IPS\Member::loggedIn()->language()->addToStack('field_placeholder_youtube');
|
||||
$this->childDefaultOptions['placeholder'] = Member::loggedIn()->language()->addToStack('field_placeholder_youtube');
|
||||
|
||||
/* Call parent constructor */
|
||||
parent::__construct( $name, $defaultValue, $required, $options, $customValidationCode, $prefix, $suffix, $id );
|
||||
@@ -57,17 +66,17 @@ class _Youtube extends \IPS\Helpers\Form\Text
|
||||
* Get the display value
|
||||
*
|
||||
* @param mixed $value Stored value from form
|
||||
* @param \IPS\cms\Field $customField Custom Field Object
|
||||
* @return string
|
||||
* @param Fields $customField Custom Field Object
|
||||
* @return string|null
|
||||
*/
|
||||
public static function displayValue( $value, $customField )
|
||||
public static function displayValue( mixed $value, Fields $customField ): ?string
|
||||
{
|
||||
if( !$value )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$url = new \IPS\Http\Url( $value );
|
||||
$url = new Url( $value );
|
||||
|
||||
if ( isset( $url->queryString['v'] ) )
|
||||
{
|
||||
@@ -95,36 +104,38 @@ class _Youtube extends \IPS\Helpers\Form\Text
|
||||
$params['height'] = ( $params['width'] * ( 9 / 16 ) ) + 30;
|
||||
}
|
||||
|
||||
$url = \IPS\Http\Url::external( $url )->setQueryString( $params );
|
||||
$url = Url::external( $url )->setQueryString( $params );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'records', 'cms', 'global' )->youtube( $url, array( 'width' => $params['width'], 'height' => $params['height'] ) );
|
||||
return Theme::i()->getTemplate( 'records', 'cms', 'global' )->youtube( $url, array( 'width' => $params['width'], 'height' => $params['height'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \DomainException
|
||||
* @return TRUE
|
||||
* @throws InvalidArgumentException
|
||||
* @throws DomainException
|
||||
* @return bool
|
||||
*/
|
||||
public function validate()
|
||||
public function validate(): bool
|
||||
{
|
||||
parent::validate();
|
||||
|
||||
if ( $this->value )
|
||||
{
|
||||
/* Check the URL is valid */
|
||||
if ( !( $this->value instanceof \IPS\Http\Url ) )
|
||||
if ( !( $this->value instanceof Url ) )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_url_bad');
|
||||
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');
|
||||
throw new InvalidArgumentException('form_url_bad');
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,12 +143,12 @@ class _Youtube extends \IPS\Helpers\Form\Text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
public function getValue(): mixed
|
||||
{
|
||||
$val = parent::getValue();
|
||||
if ( $val and !mb_strpos( $val, '://' ) )
|
||||
{
|
||||
$val = "http://{$val}";
|
||||
$val = "https://{$val}";
|
||||
}
|
||||
|
||||
return $val;
|
||||
@@ -146,17 +157,17 @@ class _Youtube extends \IPS\Helpers\Form\Text
|
||||
/**
|
||||
* Format Value
|
||||
*
|
||||
* @return \IPS\Http\Url|string
|
||||
* @return Url|string
|
||||
*/
|
||||
public function formatValue()
|
||||
public function formatValue(): mixed
|
||||
{
|
||||
if ( $this->value and !( $this->value instanceof \IPS\Http\Url ) )
|
||||
if ( $this->value and !( $this->value instanceof Url ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\Http\Url( $this->value );
|
||||
return new Url( $this->value );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
catch ( InvalidArgumentException $e )
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user