Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
+305
-45
@@ -11,7 +11,7 @@
|
||||
namespace IPS;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -86,16 +86,16 @@ abstract class _Widget
|
||||
$this->configuration = $configuration;
|
||||
$this->orientation = $orientation;
|
||||
|
||||
if ( $access !== null and is_string( $access ) )
|
||||
if ( $access !== null and \is_string( $access ) )
|
||||
{
|
||||
$test = json_decode( $access, true );
|
||||
|
||||
if ( is_array( $test ) AND count( $test ) )
|
||||
if ( \is_array( $test ) AND \count( $test ) )
|
||||
{
|
||||
$this->access = $test;
|
||||
}
|
||||
}
|
||||
else if ( is_array( $access ) AND count( $access ) )
|
||||
else if ( \is_array( $access ) AND \count( $access ) )
|
||||
{
|
||||
$this->access = $access;
|
||||
}
|
||||
@@ -131,13 +131,13 @@ abstract class _Widget
|
||||
*/
|
||||
public function isExecutableByApp( $app )
|
||||
{
|
||||
if ( $this->access === null or ( is_array( $this->access ) and ! count($this->access ) ) )
|
||||
if ( $this->access === null or ( \is_array( $this->access ) and ! \count($this->access ) ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( is_string( $app ) )
|
||||
if ( \is_string( $app ) )
|
||||
{
|
||||
$checkApps = array( $app );
|
||||
}
|
||||
@@ -148,7 +148,7 @@ abstract class _Widget
|
||||
|
||||
foreach( $checkApps as $check )
|
||||
{
|
||||
if ( in_array( $check, $this->access ) )
|
||||
if ( \in_array( $check, $this->access ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ abstract class _Widget
|
||||
*/
|
||||
public function getTemplateLocation()
|
||||
{
|
||||
$class = get_class( $this->template[0] );
|
||||
$class = \get_class( $this->template[0] );
|
||||
if ( $class === 'IPS\Theme\Dev\Template' )
|
||||
{
|
||||
$params = $this->template[0]->getParams();
|
||||
@@ -226,14 +226,109 @@ abstract class _Widget
|
||||
*/
|
||||
public function output()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$args = \func_get_args();
|
||||
$args[] = $this->orientation;
|
||||
|
||||
$template = $this->template;
|
||||
|
||||
$output = $template( ...$args );
|
||||
|
||||
if ( \in_array( 'IPS\Widget\Builder', class_implements( $this ) ) )
|
||||
{
|
||||
$config = array();
|
||||
foreach( $this->configuration as $key => $value )
|
||||
{
|
||||
if ( \mb_substr( $key, 0, 12 ) === 'widget_adv__' )
|
||||
{
|
||||
$config[ \mb_substr( $key, 12 ) ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$config['class'] = 'app_' . $this->app . '_' . $this->key . '_' . $this->uniqueKey;
|
||||
$config['style'] = static::buildInlineStyles( $config );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'widgets', 'core' )->builderWrapper( $output, $config );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build inline styles
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function buildInlineStyles( $config ): array
|
||||
{
|
||||
$css = array();
|
||||
|
||||
return $output;
|
||||
if ( ! empty( $config['padding'] ) and $config['padding'] === 'custom' )
|
||||
{
|
||||
$css['padding'] = $config['padding_custom'][0] . 'px ' . $config['padding_custom'][1] . 'px ' . $config['padding_custom'][2] . 'px ' . $config['padding_custom'][3] . 'px';
|
||||
}
|
||||
|
||||
if ( isset( $config['background_custom'] ) and $config['background_custom'] == 'transparent' )
|
||||
{
|
||||
$css['background-color'] = 'transparent';
|
||||
}
|
||||
elseif ( isset( $config['background_custom'] ) and $config['background_custom'] == 'image' and ! empty( $config['background_custom_image'] ) )
|
||||
{
|
||||
$css['background-image'] = 'url("' . \IPS\File::get( 'core_Attachment', $config['background_custom_image'] )->url . '")';
|
||||
$css['background-size'] = 'cover';
|
||||
$css['background-repeat'] = 'no-repeat';
|
||||
$css['background-position'] = 'center';
|
||||
$css['background-color'] = 'transparent';
|
||||
}
|
||||
elseif ( isset( $config['background_custom'] ) and $config['background_custom'] == 'custom' and ! empty( $config['background'] ) )
|
||||
{
|
||||
$css['background-color'] = $config['background'];
|
||||
}
|
||||
|
||||
if ( ! empty( $config['fontcolor'] ) )
|
||||
{
|
||||
if ( isset( $config['fontcolor_custom'] ) and $config['fontcolor_custom'] == 'custom' and ! empty( $config['fontcolor'] ) )
|
||||
{
|
||||
$css['color'] = $config['fontcolor'];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $config['fontsize'] ) )
|
||||
{
|
||||
if ( $config['fontsize'] === 'custom' )
|
||||
{
|
||||
$css['font-size'] = $config['fontsize_custom'] . 'px';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $config['font'] ) and $config['font'] !== 'inherit' )
|
||||
{
|
||||
$fontWeight = 400;
|
||||
|
||||
if ( \mb_substr( $config['font'], -6 ) === ' black' )
|
||||
{
|
||||
$fontWeight = 900;
|
||||
$config['font'] = \mb_substr( $config['font'], 0, -6 );
|
||||
}
|
||||
|
||||
$css['font-family'] = '"' . $config['font'] . '"';
|
||||
$css['font-weight'] = $fontWeight;
|
||||
}
|
||||
|
||||
if ( ! empty( $config['fontalign'] ) )
|
||||
{
|
||||
$css['text-align'] = $config['fontalign'];
|
||||
}
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach( $css as $name => $rule )
|
||||
{
|
||||
$return[ $name ] = $name . ":" . $rule . ";";
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,12 +388,31 @@ abstract class _Widget
|
||||
/* Return */
|
||||
if ( class_exists( $class ) )
|
||||
{
|
||||
if ( ! empty( $configuration['widget_adv__custom'] ) )
|
||||
{
|
||||
\IPS\Output::i()->headCss = \IPS\Output::i()->headCss . "\n" . $configuration['widget_adv__custom'];
|
||||
}
|
||||
|
||||
return new $class( $uniqueKey, $configuration, $access, $orientation );
|
||||
}
|
||||
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget Types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function widgetTypes()
|
||||
{
|
||||
return array(
|
||||
'default' => '\IPS\Widget',
|
||||
'StaticCache' => '\IPS\Widget\StaticCache',
|
||||
'PermissionCache' => '\IPS\Widget\PermissionCache',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dev Table
|
||||
*
|
||||
@@ -361,30 +475,22 @@ abstract class _Widget
|
||||
}
|
||||
} ) );
|
||||
|
||||
$classes = array( '\IPS\Widget' => '\IPS\Widget' );
|
||||
\IPS\Member::loggedIn()->language()->words[ "\\IPS\\Widget" . '_desc' ] = \IPS\Member::loggedIn()->language()->get( 'widget_class_default' );
|
||||
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . "/system/Widget" ) as $file )
|
||||
$classes = array();
|
||||
foreach ( static::widgetTypes() as $key => $class )
|
||||
{
|
||||
if ( !$file->isDot() and $file->getExtension() === 'php' and $file != 'Widget.php' )
|
||||
{
|
||||
$classes[ "\\IPS\\Widget\\" . mb_substr( $file, 0, -4 ) ] = "\\IPS\\Widget\\" . mb_substr( $file, 0, -4 );
|
||||
try
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words[ "\\IPS\\Widget\\" . mb_substr( $file, 0, -4 ) . '_desc' ] = \IPS\Member::loggedIn()->language()->get( 'widget_class_' . mb_substr( $file, 0, -4 ) );
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
}
|
||||
$classes[ $class ] = $class;
|
||||
\IPS\Member::loggedIn()->language()->words[ $class . '_desc' ] = \IPS\Member::loggedIn()->language()->get( 'widget_class_' . $key );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'dev_widget_class', ( $current ? $current['dev_widget_class'] : NULL ), TRUE, array( 'options' => $classes ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'dev_widget_class', ( \is_array( $current ) ? $current['dev_widget_class'] : NULL ), TRUE, array( 'options' => $classes ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'dev_widget_restrict', ( ( $current and !empty( $current['dev_widget_restrict'] ) ) ? $current['dev_widget_restrict'] : ( $current['dev_widget_restrict'] === FALSE ? array() : array( 'sidebar', 'cms' ) ) ), FALSE, array(
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'dev_widget_restrict', ( \is_array( $current ) and !empty( $current['dev_widget_restrict'] ) ) ? $current['dev_widget_restrict'] : array( 'sidebar', 'cms' ), FALSE, array(
|
||||
'options' => array(
|
||||
'sidebar' => \IPS\Member::loggedIn()->language()->addToStack('dev_widget_restrict_sidebar'),
|
||||
'cms' => \IPS\Member::loggedIn()->language()->addToStack('dev_widget_restrict_cms'),
|
||||
),
|
||||
'multiple' => true ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'dev_widget_default_area', ( $current ? ( $current['dev_widget_default_area'] ?: 'none' ) : 'none' ), FALSE, array(
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'dev_widget_default_area', ( \is_array( $current ) ? ( $current['dev_widget_default_area'] ?: 'none' ) : 'none' ), FALSE, array(
|
||||
'options' => array(
|
||||
'none' => \IPS\Member::loggedIn()->language()->addToStack('none'),
|
||||
'sidebar' => \IPS\Member::loggedIn()->language()->addToStack('dev_widget_default_area_sidebar'),
|
||||
@@ -394,15 +500,15 @@ abstract class _Widget
|
||||
),
|
||||
'multiple' => false ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'dev_widget_menu_style', ( $current ? $current['dev_widget_menu_style'] : 'menu' ), FALSE, array(
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'dev_widget_menu_style', ( \is_array( $current ) ? $current['dev_widget_menu_style'] : 'menu' ), FALSE, array(
|
||||
'options' => array(
|
||||
'menu' => \IPS\Member::loggedIn()->language()->addToStack('dev_widget_menu_style_menu'),
|
||||
'modal' => \IPS\Member::loggedIn()->language()->addToStack('dev_widget_menu_style_modal'),
|
||||
) ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'dev_widget_allow_reuse', ( $current ? $current['dev_widget_allow_reuse'] : 0 ), FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'dev_widget_allow_reuse', ( \is_array( $current ) ? $current['dev_widget_allow_reuse'] : 0 ), FALSE ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'dev_widget_embeddable', ( $current ? $current['dev_widget_embeddable'] : 0 ), FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'dev_widget_embeddable', ( \is_array( $current ) ? $current['dev_widget_embeddable'] : 0 ), FALSE ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
@@ -432,8 +538,8 @@ abstract class _Widget
|
||||
date( 'd M Y' ),
|
||||
$namespace,
|
||||
$values['dev_widget_class'],
|
||||
is_string( $appKeyOrPluginId ) ? $appKeyOrPluginId : NULL,
|
||||
is_numeric( $appKeyOrPluginId ) ? $appKeyOrPluginId : NULL,
|
||||
\is_string( $appKeyOrPluginId ) ? $appKeyOrPluginId : NULL,
|
||||
\is_numeric( $appKeyOrPluginId ) ? $appKeyOrPluginId : NULL,
|
||||
),
|
||||
file_get_contents( \IPS\ROOT_PATH . "/applications/core/data/defaults/Widget.txt" )
|
||||
) );
|
||||
@@ -442,11 +548,11 @@ abstract class _Widget
|
||||
|
||||
/* Add to DB */
|
||||
\IPS\Db::i()->replace( 'core_widgets', array(
|
||||
'app' => is_string( $appKeyOrPluginId ) ? $appKeyOrPluginId : NULL,
|
||||
'plugin' => is_numeric( $appKeyOrPluginId ) ? $appKeyOrPluginId : NULL,
|
||||
'app' => \is_string( $appKeyOrPluginId ) ? $appKeyOrPluginId : NULL,
|
||||
'plugin' => \is_numeric( $appKeyOrPluginId ) ? $appKeyOrPluginId : NULL,
|
||||
'key' => $values['dev_widget_key'],
|
||||
'class' => $values['dev_widget_class'],
|
||||
'restrict' => ( ! count( $values['dev_widget_restrict'] ) ? FALSE : json_encode( array_values( $values['dev_widget_restrict'] ) ) ),
|
||||
'restrict' => ( ! \count( $values['dev_widget_restrict'] ) ? FALSE : json_encode( array_values( $values['dev_widget_restrict'] ) ) ),
|
||||
'default_area' => ( $values['dev_widget_default_area'] === 'none' ) ? '' : $values['dev_widget_default_area'],
|
||||
'allow_reuse' => $values['dev_widget_allow_reuse'],
|
||||
'menu_style' => $values['dev_widget_menu_style'],
|
||||
@@ -458,7 +564,7 @@ abstract class _Widget
|
||||
$widgets = json_decode( file_get_contents( $json ), TRUE );
|
||||
$widgets[ $values['dev_widget_key'] ] = array(
|
||||
'class' => $values['dev_widget_class'],
|
||||
'restrict' => ( ! count( $values['dev_widget_restrict'] ) ? FALSE : array_values( $values['dev_widget_restrict'] ) ),
|
||||
'restrict' => ( ! \count( $values['dev_widget_restrict'] ) ? FALSE : array_values( $values['dev_widget_restrict'] ) ),
|
||||
'default_area' => ( $values['dev_widget_default_area'] === 'none' ) ? '' : $values['dev_widget_default_area'],
|
||||
'allow_reuse' => $values['dev_widget_allow_reuse'],
|
||||
'menu_style' => $values['dev_widget_menu_style'],
|
||||
@@ -474,7 +580,8 @@ abstract class _Widget
|
||||
return $form;
|
||||
|
||||
case 'delete':
|
||||
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
$widgets = json_decode( file_get_contents( $json ), TRUE );
|
||||
if ( array_key_exists( \IPS\Request::i()->key, $widgets ) )
|
||||
{
|
||||
@@ -486,7 +593,7 @@ abstract class _Widget
|
||||
unlink( $widgetDirectory . "/" . \IPS\Request::i()->key . ".php" );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'core_widgets', array( ( is_string( $appKeyOrPluginId ) ? 'app' : 'plugin' ) . '=? AND `key`=?', $appKeyOrPluginId, \IPS\Request::i()->key ) );
|
||||
\IPS\Db::i()->delete( 'core_widgets', array( ( \is_string( $appKeyOrPluginId ) ? 'app' : 'plugin' ) . '=? AND `key`=?', $appKeyOrPluginId, \IPS\Request::i()->key ) );
|
||||
unset( \IPS\Data\Store::i()->widgets );
|
||||
}
|
||||
\IPS\Output::i()->redirect( $url, 'saved' );
|
||||
@@ -499,7 +606,7 @@ abstract class _Widget
|
||||
$data[ $k ] = array(
|
||||
'dev_widget_key' => $k,
|
||||
'dev_widget_class' => $json['class'],
|
||||
'dev_widget_restrict' => $json['restrict'] === FALSE ? \IPS\Member::loggedIn()->language()->addToStack('dev_widget_nowhere') : ( ( ( count( $json['restrict'] ) > 0 and count( $json['restrict'] ) !== 2 ) ? implode( ',', array_map( function( $val ) { return \IPS\Member::loggedIn()->language()->addToStack('dev_widget_restrict_'.$val); }, $json['restrict'] ) ) : \IPS\Member::loggedIn()->language()->addToStack('everywhere') ) ),
|
||||
'dev_widget_restrict' => $json['restrict'] === FALSE ? \IPS\Member::loggedIn()->language()->addToStack('dev_widget_nowhere') : ( ( ( \count( $json['restrict'] ) > 0 and \count( $json['restrict'] ) !== 2 ) ? implode( ',', array_map( function( $val ) { return \IPS\Member::loggedIn()->language()->addToStack('dev_widget_restrict_'.$val); }, $json['restrict'] ) ) : \IPS\Member::loggedIn()->language()->addToStack('everywhere') ) ),
|
||||
'dev_widget_area' => isset($json['default_area']) ? ( $json['default_area'] ? \IPS\Member::loggedIn()->language()->addToStack( 'dev_widget_default_area_' . $json['default_area'] ) : \IPS\Member::loggedIn()->language()->addToStack('none') ) : 'sidebar',
|
||||
'dev_widget_embeddable' => isset($json['embeddable']) ? ( $json['embeddable'] ? '✓' : '✗' ) : '✗'
|
||||
);
|
||||
@@ -526,7 +633,7 @@ abstract class _Widget
|
||||
'delete' => array(
|
||||
'icon' => 'times-circle',
|
||||
'title' => 'delete',
|
||||
'link' => $url->setQueryString( 'widgetTable', 'delete' )->setQueryString( 'key', $row['dev_widget_key'] ),
|
||||
'link' => $url->setQueryString( 'widgetTable', 'delete' )->setQueryString( 'key', $row['dev_widget_key'] )->csrf(),
|
||||
'data' => array( 'delete' => '' )
|
||||
)
|
||||
);
|
||||
@@ -558,7 +665,7 @@ abstract class _Widget
|
||||
{
|
||||
$json = json_decode( $widget['caches'], TRUE );
|
||||
|
||||
if ( ! is_array( $json ) )
|
||||
if ( ! \is_array( $json ) )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
@@ -610,7 +717,7 @@ abstract class _Widget
|
||||
*/
|
||||
public static function trash( $uniqueId, $data )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_widget_trash', array( 'id=?', $uniqueId ) );
|
||||
\IPS\Db::i()->delete( 'core_widget_trash', array( 'id=?', (string) $uniqueId ) );
|
||||
\IPS\Db::i()->insert( 'core_widget_trash', array(
|
||||
'id' => $uniqueId,
|
||||
'data' => json_encode( $data ),
|
||||
@@ -702,6 +809,29 @@ abstract class _Widget
|
||||
* @brief Cached output to prevent rendering widget twice
|
||||
*/
|
||||
protected $cachedOutput = NULL;
|
||||
|
||||
/**
|
||||
* Return the widget output or an empty string if the widget shouldn't be returned on this page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _render() : string
|
||||
{
|
||||
|
||||
if( \IPS\Settings::i()->clubs AND isset( $this->configuration['clubs_visibility'] ) )
|
||||
{
|
||||
switch ( $this->configuration['clubs_visibility'] )
|
||||
{
|
||||
case 'all':
|
||||
return $this->render();
|
||||
case 'without_clubs':
|
||||
return ( \IPS\Member\Club::userIsInClub() ) ? '' : $this->render();
|
||||
case 'only_clubs':
|
||||
return ( \IPS\Member\Club::userIsInClub() ) ? $this->render() : '';
|
||||
}
|
||||
}
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the widget to HTML
|
||||
@@ -725,7 +855,7 @@ abstract class _Widget
|
||||
/* If we're not caching (e.g. dynamic blocks in Pages), just return it */
|
||||
if ( $this->neverCache === TRUE )
|
||||
{
|
||||
return static::parseOutput( $this->render() );
|
||||
return static::parseOutput( $this->_render() );
|
||||
}
|
||||
|
||||
/* Otherwise, figure out what to display. Saved in $this->cachedOutput so if this is being used twice on the same page, we only do this once */
|
||||
@@ -756,7 +886,7 @@ abstract class _Widget
|
||||
\IPS\Data\Store::i()->$cacheKey = array( 'built' => time(), 'html' => '' );
|
||||
|
||||
/* Render and store */
|
||||
$content = $this->render();
|
||||
$content = $this->_render();
|
||||
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $content );
|
||||
\IPS\Data\Store::i()->$cacheKey = array( 'built' => time(), 'html' => $content ); // Corrects the blank output written above
|
||||
|
||||
@@ -794,7 +924,7 @@ abstract class _Widget
|
||||
/* If we still don't have anything, go ahead and render */
|
||||
if( $this->cachedOutput === NULL )
|
||||
{
|
||||
$this->cachedOutput = $this->render();
|
||||
$this->cachedOutput = $this->_render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -872,7 +1002,7 @@ abstract class _Widget
|
||||
if ( ! empty( $data['app'] ) and ! empty( $data['key'] ) and ! empty( $data['unique'] ) )
|
||||
{
|
||||
/* Is this unique ID actually used elsewhere? Sometimes moving blocks around can add a row in the trash table with the same unique ID */
|
||||
if ( in_array( $data['unique'], $uniqueIds ) )
|
||||
if ( \in_array( $data['unique'], $uniqueIds ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -901,7 +1031,7 @@ abstract class _Widget
|
||||
{
|
||||
$data = json_decode( $row['widgets'], TRUE );
|
||||
|
||||
if ( count( $data ) )
|
||||
if ( \count( $data ) )
|
||||
{
|
||||
foreach( $data as $widget )
|
||||
{
|
||||
@@ -945,4 +1075,134 @@ abstract class _Widget
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify widget configuration
|
||||
*
|
||||
* @param null|\IPS\Helpers\Form $form Form object
|
||||
* @return \IPS\Helpers\Form
|
||||
*/
|
||||
public function configuration( &$form=null )
|
||||
{
|
||||
if ( $form === null )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'show_on_all_devices', isset( $this->configuration['devices_to_show'] ) ? empty( array_diff( array( 'Phone', 'Tablet', 'Desktop' ), $this->configuration['devices_to_show'] ) ) : TRUE, FALSE, array( 'togglesOff' => array( 'devices_to_show' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'devices_to_show', isset( $this->configuration['devices_to_show'] ) ? $this->configuration['devices_to_show'] : array( 'Phone', 'Tablet', 'Desktop' ), FALSE, array( 'options' => array( 'Phone' => \IPS\Member::loggedIn()->language()->addToStack( 'device_phone' ), 'Tablet' => \IPS\Member::loggedIn()->language()->addToStack( 'device_tablet' ), 'Desktop' => \IPS\Member::loggedIn()->language()->addToStack( 'device_desktop' ) ) ), NULL, NULL, NULL, 'devices_to_show' ) );
|
||||
|
||||
if( \IPS\Settings::i()->clubs AND ( ( \IPS\Request::i()->pageApp === 'core' AND \IPS\Request::i()->pageModule === 'clubs' ) OR ( \IPS\Request::i()->pageApp !== 'core' AND \IPS\Request::i()->pageApp !== 'nexus' ) ) )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'clubs_visibility', isset( $this->configuration['clubs_visibility'] ) ? $this->configuration['clubs_visibility'] : 'all', FALSE, array( 'options' => array( 'all' => 'everywhere', 'without_clubs' => 'without_clubs', 'only_clubs' => 'only_clubs')) ) );
|
||||
}
|
||||
|
||||
if ( \in_array( 'IPS\Widget\Builder', class_implements( $this ) ) )
|
||||
{
|
||||
\IPS\Output::i()->linkTags['googlefonts'] = array( 'rel' => 'stylesheet', 'href' => "https://fonts.googleapis.com/css?family=Lato|Merriweather|Open+Sans|Raleway:400,900|Roboto:400,900&display=swap" );
|
||||
|
||||
if ( ! isset( $this->configuration['widget_adv__custom'] ) and isset( \IPS\Request::i()->block ) )
|
||||
{
|
||||
$customCss = '.' . \IPS\Request::i()->block . " {\n\n}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$customCss = isset( $this->configuration['widget_adv__custom'] ) ? $this->configuration['widget_adv__custom'] : '';
|
||||
}
|
||||
|
||||
/* Box model */
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'widget_adv__border', isset( $this->configuration['widget_adv__border'] ) ? $this->configuration['widget_adv__border'] : TRUE, FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'widget_adv__padding', isset( $this->configuration['widget_adv__padding'] ) ? $this->configuration['widget_adv__padding'] : 'full', FALSE,
|
||||
array(
|
||||
'options' => array(
|
||||
'none' => 'widget_adv__padding_none',
|
||||
'half' => 'widget_adv__padding_half',
|
||||
'full' => 'widget_adv__padding_full',
|
||||
'custom' => 'custom',
|
||||
),
|
||||
'toggles' => array(
|
||||
'custom' => array( 'padding_custom' )
|
||||
)
|
||||
) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Trbl( 'widget_adv__padding_custom', ( isset( $this->configuration['widget_adv__padding_custom'] ) ? $this->configuration['widget_adv__padding_custom'] : 0 ), FALSE, array(), NULL, NULL, NULL, 'padding_custom' ) );
|
||||
|
||||
/* Font size */
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'widget_adv__fontsize', isset( $this->configuration['widget_adv__fontsize'] ) ? $this->configuration['widget_adv__fontsize'] : 'ipsType_medium', FALSE,
|
||||
array(
|
||||
'options' => array(
|
||||
'inherit' => 'widget_adv__inherit',
|
||||
'ipsType_pageTitle' => 'widget_adv__fontsize_pagetitle',
|
||||
'ipsType_large' => 'widget_adv__fontsize_large',
|
||||
'ipsType_medium' => 'widget_adv__fontsize_medium',
|
||||
'ipsType_small' => 'widget_adv__fontsize_small',
|
||||
'custom' => 'custom',
|
||||
),
|
||||
'toggles' => array(
|
||||
'custom' => array( 'font_custom' )
|
||||
)
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'widget_adv__fontsize_custom', ( isset( $this->configuration['widget_adv__fontsize_custom'] ) ? $this->configuration['widget_adv__fontsize_custom'] : 12 ), FALSE, array(), NULL, NULL, 'px', 'font_custom' ) );
|
||||
|
||||
/* Font face */
|
||||
$fontOptions = array( 'inherit' => 'widget_adv__inherit' );
|
||||
|
||||
foreach( array( 'arial', 'helvetica', 'times new roman', 'courier', 'lato', 'merriweather', 'open sans', 'raleway', 'raleway black', 'roboto', 'roboto black' ) as $font )
|
||||
{
|
||||
$fontOptions[ ucfirst( $font ) ] = 'widget_adv__font_' . str_replace( ' ', '_', $font );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'widget_adv__font', isset( $this->configuration['widget_adv__font'] ) ? $this->configuration['widget_adv__font'] : 'inherit', FALSE,
|
||||
array(
|
||||
'options' => $fontOptions
|
||||
) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'widget_adv__fontalign', isset( $this->configuration['widget_adv__fontalign'] ) ? $this->configuration['widget_adv__fontalign'] : 'left', FALSE,
|
||||
array(
|
||||
'options' => array(
|
||||
'left' => 'widget_adv__fontalign_left',
|
||||
'center' => 'widget_adv__fontalign_center',
|
||||
'right' => 'widget_adv__fontalign_right'
|
||||
)
|
||||
) ) );
|
||||
|
||||
/* Font color */
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'widget_adv__fontcolor_custom', isset( $this->configuration['widget_adv__fontcolor_custom'] ) ? $this->configuration['widget_adv__fontcolor_custom'] : FALSE, FALSE,
|
||||
array(
|
||||
'options' => array(
|
||||
'inherit' => 'widget_adv__inherit',
|
||||
'custom' => 'custom',
|
||||
),
|
||||
'toggles' => array(
|
||||
'custom' => array( 'fontcolor_custom' )
|
||||
)
|
||||
) ), NULL, NULL, NULL, 'fontcolor_selector' );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Color( 'widget_adv__fontcolor', isset( $this->configuration['widget_adv__fontcolor'] ) ? $this->configuration['widget_adv__fontcolor'] : '', FALSE, array( 'swatches' => TRUE, 'rgba' => TRUE ), NULL, NULL, NULL, 'fontcolor_custom' ) );
|
||||
|
||||
/* Background color */
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'widget_adv__background_custom', isset( $this->configuration['widget_adv__background_custom'] ) ? $this->configuration['widget_adv__background_custom'] : FALSE, FALSE,
|
||||
array(
|
||||
'options' => array(
|
||||
'inherit' => 'widget_adv__inherit',
|
||||
'transparent' => 'widget_adv__fontcolor_custom_transparent',
|
||||
'custom' => 'widget_adv__background_custom_color',
|
||||
'image' => 'widget_adv__background_custom_image',
|
||||
),
|
||||
'toggles' => array(
|
||||
'custom' => array( 'background_custom' ),
|
||||
'image' => array( 'background_image', 'background_overlay' )
|
||||
)
|
||||
) ), NULL, NULL, NULL, 'background_selector' );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'widget_adv__background_custom_image', isset( $this->configuration['widget_adv__background_custom_image'] ) ? \IPS\File::get( 'core_Attachment', $this->configuration['widget_adv__background_custom_image'] ) : '', FALSE, array( 'storageExtension' => 'core_Attachment', 'allowStockPhotos' => TRUE, 'image' => true ), NULL, NULL, NULL, 'background_image' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Color( 'widget_adv__background_custom_image_overlay', isset( $this->configuration['widget_adv__background_custom_image_overlay'] ) ? $this->configuration['widget_adv__background_custom_image_overlay'] : '', FALSE, array( 'swatches' => TRUE, 'rgba' => TRUE ), NULL, NULL, NULL, 'background_overlay' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Color( 'widget_adv__background', isset( $this->configuration['widget_adv__background'] ) ? $this->configuration['widget_adv__background'] : '', FALSE, array( 'swatches' => TRUE, 'rgba' => TRUE ), NULL, NULL, NULL, 'background_custom' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'widget_adv__custom', $customCss, FALSE, array() ) );
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user