Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+5 -9
View File
@@ -12,7 +12,7 @@
namespace IPS\cms\widgets;
/* 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;
@@ -41,12 +41,10 @@ class _Blocks extends \IPS\Widget\PermissionCache
/**
* Constructor
*
* @param String $uniqueKey Unique key for this specific instance
* @param string $uniqueKey Unique key for this specific instance
* @param array $configuration Widget custom configuration
* @param null|string|array $access Array/JSON string of executable apps (core=sidebar only, content=IP.Content only, etc)
* @param null|string $orientation Orientation (top, bottom, right, left)
* @param boolean $allowReuse If true, when the block is used, it will remain in the sidebar so it can be used again.
* @param string $menuStyle Menu is a drop down menu, modal is a bigger modal panel.
* @return void
*/
public function __construct( $uniqueKey, array $configuration, $access=null, $orientation=null )
@@ -85,10 +83,7 @@ class _Blocks extends \IPS\Widget\PermissionCache
*/
public function configuration( &$form=null )
{
if ( $form === null )
{
$form = new \IPS\Helpers\Form;
}
$form = parent::configuration( $form );
/* A block may be deleted on the back end */
$block = NULL;
@@ -103,6 +98,7 @@ class _Blocks extends \IPS\Widget\PermissionCache
$form->add( new \IPS\Helpers\Form\Node( 'cms_widget_custom_block', $block, FALSE, array(
'class' => '\IPS\cms\Blocks\Container',
'showAllNodes' => TRUE,
'permissionCheck' => function( $node )
{
if ( $node instanceof \IPS\cms\Blocks\Container )
@@ -125,7 +121,7 @@ class _Blocks extends \IPS\Widget\PermissionCache
*/
public function preConfig( $values )
{
$newValues = array();
$newValues = $values;
if ( isset( $values['cms_widget_custom_block'] ) )
{
+1 -1
View File
@@ -12,7 +12,7 @@
namespace IPS\cms\widgets;
/* 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;
+8 -10
View File
@@ -12,7 +12,7 @@
namespace IPS\cms\widgets;
/* 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;
@@ -46,14 +46,12 @@ class _Database extends \IPS\Widget
/**
* Specify widget configuration
*
* @param \IPS\Helpers\Form|NULL $form Form helper
* @return null|\IPS\Helpers\Form
*/
public function configuration( &$form=null )
{
if ( $form === null )
{
$form = new \IPS\Helpers\Form;
}
$form = parent::configuration( $form );
$databases = array();
$disabled = array();
@@ -62,7 +60,7 @@ class _Database extends \IPS\Widget
{
$databases[ $db->id ] = $db->_title;
if ( $db->page_id )
if ( $db->page_id and $db->page_id != \IPS\Request::i()->pageID )
{
$disabled[] = $db->id;
@@ -78,13 +76,13 @@ class _Database extends \IPS\Widget
}
}
if ( ! count( $databases ) )
if ( ! \count( $databases ) )
{
$form->addMessage('cms_err_no_databases_to_use');
}
else
{
$form->add( new \IPS\Helpers\Form\Select( 'database', ( isset( $this->configuration['database'] ) ? $this->configuration['database'] : NULL ), FALSE, array( 'options' => $databases, 'disabled' => $disabled ) ) );
$form->add( new \IPS\Helpers\Form\Select( 'database', ( isset( $this->configuration['database'] ) ? (int) $this->configuration['database'] : NULL ), FALSE, array( 'options' => $databases, 'disabled' => $disabled ) ) );
}
return $form;
@@ -119,14 +117,14 @@ class _Database extends \IPS\Widget
{
try
{
$database = \IPS\cms\Databases::load( intval( $this->configuration['database'] ) );
$database = \IPS\cms\Databases::load( \intval( $this->configuration['database'] ) );
if ( ! $database->page_id and \IPS\cms\Pages\Page::$currentPage )
{
$database->page_id = \IPS\cms\Pages\Page::$currentPage->id;
$database->save();
}
static::$html = \IPS\cms\Databases\Dispatcher::i()->setDatabase( $database->id )->run();
}
catch ( \OutOfRangeException $e )
+85 -12
View File
@@ -12,7 +12,7 @@
namespace IPS\cms\widgets;
/* 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;
@@ -85,9 +85,10 @@ class _DatabaseFilters extends \IPS\Widget
$fields = array();
$cookie = $category->getFilterCookie();
$cookieValues = ( $cookie !== NULL ) ? array_combine( array_map( function( $k ) { return "field_" . $k; }, array_keys( $cookie ) ), $cookie ) : array();
$databaseFields = $fieldClass::roots();
$urlValues = array();
foreach( \IPS\Request::i() as $k => $v )
{
if( mb_strpos( $k, 'content_field_' ) !== FALSE )
@@ -98,18 +99,47 @@ class _DatabaseFilters extends \IPS\Widget
$k = mb_substr( $k, 0, -9 );
}
$urlValues[ str_replace( 'content_', '', $k ) ] = is_array( $v ) ? implode( ',', $v ) : $v;
$fieldId = str_replace( 'content_field_', '', $k );
if ( isset( $databaseFields[ $fieldId ] ) and $databaseFields[ $fieldId ]->type == 'Member' )
{
$urlValues[ str_replace( 'content_', '', $k ) ] = \is_array( $v ) ? implode( '\n', $v ) : $v;
}
else
{
$urlValues[ str_replace( 'content_', '', $k ) ] = \is_array( $v ) ? implode( ',', $v ) : $v;
}
}
}
$cookieValues = array_merge( $urlValues, $cookieValues );
foreach( $databaseFields as $field )
{
/* If we pass in what is stored in the database, eg: 1\n20, \IPS\Helpers\Form\Member() actually tries to load via name, not ID */
if ( $field->type === 'Member' and isset( $cookieValues[ 'field_' . $field->id ] ) )
{
$members = array();
$memberArray = \is_array( $cookieValues[ 'field_' . $field->id ] ) ? $cookieValues[ 'field_' . $field->id ] : explode( '\n', $cookieValues[ 'field_' . $field->id ] );
foreach( $memberArray as $id )
{
try
{
$members[] = \IPS\Member::load( $id );
}
catch( \Exception $e ) { }
}
$cookieValues[ 'field_' . $field->id ] = $members;
}
}
foreach( $fieldClass::fields( $cookieValues, 'view', $category, $fieldClass::FIELD_SKIP_TITLE_CONTENT | $fieldClass::FIELD_DISPLAY_FILTERS ) as $id => $field )
{
$fields[ $id ] = $field;
}
if ( count( $fields ) )
if ( \count( $fields ) )
{
$form = new \IPS\Helpers\Form( 'category_filters', 'update', $category->url() );
$form->class = 'ipsForm_vertical';
@@ -131,9 +161,26 @@ class _DatabaseFilters extends \IPS\Widget
{
$form->add( $field );
}
$form->add( new \IPS\Helpers\Form\Checkbox( 'cms_widget_filters_remember', ( $cookie !== NULL ) ? TRUE : FALSE , FALSE, array( 'label' => 'cms_widget_filters_remember_text') ) );
if ( \IPS\Member::loggedIn()->member_id )
{
$iStarted = FALSE;
if ( isset( $cookie['cms_record_i_started'] ) and $cookie['cms_record_i_started'] )
{
$iStarted = TRUE;
}
/* Form submission takes preference over any previously stored cookie values */
if ( ( isset( \IPS\Request::i()->cms_record_i_started ) and \IPS\Request::i()->cms_record_i_started ) )
{
$iStarted = TRUE;
}
$form->add( new \IPS\Helpers\Form\Checkbox( 'cms_record_i_started', $iStarted, FALSE ) );
}
$form->add( new \IPS\Helpers\Form\Checkbox( 'cms_widget_filters_remember', ( $cookie !== NULL ) ? TRUE : FALSE, FALSE, array( 'label' => 'cms_widget_filters_remember_text') ) );
if ( $values = $form->values() )
{
$url = $category->url()->setQueryString( array( 'advanced_search_submitted' => 1, 'csrfKey' => \IPS\Session::i()->csrfKey ) );
@@ -158,23 +205,49 @@ class _DatabaseFilters extends \IPS\Widget
else if ( isset( $fields[ $id ] ) and $fields[ $id ] instanceof \IPS\Helpers\Form\DateRange )
{
/* We need to reformat this a little */
$start = ( $v['start'] instanceof \IPS\DateTime ) ? $v['start']->getTimestamp() : intval( $v['start'] );
$end = ( $v['end'] instanceof \IPS\DateTime ) ? $v['end']->getTimestamp() : intval( $v['end'] );
$start = ( $v['start'] instanceof \IPS\DateTime ) ? $v['start']->getTimestamp() : \intval( $v['start'] );
$end = ( $v['end'] instanceof \IPS\DateTime ) ? $v['end']->getTimestamp() : \intval( $v['end'] );
$v = array( 'start' => $start, 'end' => $end );
}
else if ( isset( $fields[ $id ] ) and $fields[ $id ] instanceof \IPS\Helpers\Form\Member )
{
$ids = array();
if ( \is_array( $v ) )
{
foreach( $v as $member )
{
if ( $member instanceof \IPS\Member )
{
$ids[] = $member->member_id;
}
}
$v = $ids;
}
else if ( $v instanceof \IPS\Member )
{
$v = $v->member_id;
}
}
$cookie[ $id ] = $v;
$params[ $k ] = $v;
}
if ( ! empty( $values['cms_record_i_started_checkbox'] ) or ! empty( $values['cms_record_i_started'] ) )
{
$cookie['cms_record_i_started'] = 1;
$params['cms_record_i_started'] = 1;
}
}
if ( count( $form->hiddenValues ) )
if ( \count( $form->hiddenValues ) )
{
foreach( $form->hiddenValues as $k => $v )
{
if ( $k !== 'csrfKey' )
{
if ( !in_array( $k, array( 'sortby', 'sortdirection' ) ) )
if ( !\in_array( $k, array( 'sortby', 'sortdirection' ) ) )
{
$cookie[ $k ] = $v;
}
@@ -193,7 +266,7 @@ class _DatabaseFilters extends \IPS\Widget
\IPS\Output::i()->redirect( $url->setQueryString( $params ) );
}
}
return $this->output( $database, $category, $form );
}
else
+14 -15
View File
@@ -12,7 +12,7 @@
namespace IPS\cms\widgets;
/* 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;
@@ -51,11 +51,6 @@ class _RecordFeed extends \IPS\Content\Widget
*/
public function configuration( &$form=null )
{
if ( $form === null )
{
$form = new \IPS\Helpers\Form;
}
$databases = array();
$database = NULL;
foreach( \IPS\cms\Databases::databases() as $obj )
@@ -71,6 +66,8 @@ class _RecordFeed extends \IPS\Content\Widget
static::$class = '\IPS\cms\Records' . $database->id;
}
}
$form = parent::configuration( $form );
if ( isset( $this->configuration['cms_rf_database'] ) )
{
@@ -115,7 +112,7 @@ class _RecordFeed extends \IPS\Content\Widget
foreach( $FieldsClass::data() as $id => $field )
{
if ( in_array( $field->type, array( 'checkbox', 'multiselect', 'attachments' ) ) )
if ( \in_array( $field->type, array( 'checkbox', 'multiselect', 'attachments' ) ) )
{
continue;
}
@@ -202,10 +199,10 @@ class _RecordFeed extends \IPS\Content\Widget
foreach( $values as $k => $v )
{
/* We need to reformat this a little */
if ( is_array( $v ) and isset( $v['start'] ) and isset( $v['end'] ) )
if ( \is_array( $v ) and isset( $v['start'] ) and isset( $v['end'] ) )
{
$start = ( $v['start'] instanceof \IPS\DateTime ) ? $v['start']->getTimestamp() : intval( $v['start'] );
$end = ( $v['end'] instanceof \IPS\DateTime ) ? $v['end']->getTimestamp() : intval( $v['end'] );
$start = ( $v['start'] instanceof \IPS\DateTime ) ? $v['start']->getTimestamp() : \intval( $v['start'] );
$end = ( $v['end'] instanceof \IPS\DateTime ) ? $v['end']->getTimestamp() : \intval( $v['end'] );
$values[ $k ] = array( 'start' => $start, 'end' => $end );
}
@@ -221,6 +218,8 @@ class _RecordFeed extends \IPS\Content\Widget
*/
protected function buildWhere()
{
static::$class = '\IPS\cms\Records' . $this->configuration['cms_rf_database'];
$where = parent::buildWhere();
$fieldClass = 'IPS\cms\Fields' . $this->configuration['cms_rf_database'];
@@ -231,12 +230,12 @@ class _RecordFeed extends \IPS\Content\Widget
$k = 'field_' . $f;
if ( isset( $customFields[ $f ] ) and $v !== '___any___' AND $v !== NULL )
{
if ( is_array( $v ) )
if ( \is_array( $v ) )
{
if ( array_key_exists( 'start', $v ) or array_key_exists( 'end', $v ) )
{
$start = ( $v['start'] instanceof \IPS\DateTime ) ? $v['start']->getTimestamp() : intval( $v['start'] );
$end = ( $v['end'] instanceof \IPS\DateTime ) ? $v['end']->getTimestamp() : intval( $v['end'] );
$start = ( $v['start'] instanceof \IPS\DateTime ) ? $v['start']->getTimestamp() : \intval( $v['start'] );
$end = ( $v['end'] instanceof \IPS\DateTime ) ? $v['end']->getTimestamp() : \intval( $v['end'] );
if ( $start or $end )
{
@@ -246,7 +245,7 @@ class _RecordFeed extends \IPS\Content\Widget
else
{
$like = array();
if ( count( $v ) )
if ( \count( $v ) )
{
foreach( $v as $val )
{
@@ -256,7 +255,7 @@ class _RecordFeed extends \IPS\Content\Widget
}
}
$where[] = array( '( ' . \IPS\Db::i()->in( $k, $v ) . ( count( $like ) ? " OR (" . implode( ' OR ', $like ) . ') )' : ')' ) );
$where[] = array( '( ' . \IPS\Db::i()->in( $k, $v ) . ( \count( $like ) ? " OR (" . implode( ' OR ', $like ) . ') )' : ')' ) );
}
}
}
+2 -5
View File
@@ -12,7 +12,7 @@
namespace IPS\cms\widgets;
/* 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;
@@ -46,10 +46,7 @@ class _Rss extends \IPS\Widget\StaticCache
*/
public function configuration( &$form=null )
{
if ( $form === null )
{
$form = new \IPS\Helpers\Form;
}
$form = parent::configuration( $form );
$form->add( new \IPS\Helpers\Form\Text( 'block_rss_import_title', ( isset( $this->configuration['block_rss_import_title'] ) ? $this->configuration['block_rss_import_title'] : NULL ), TRUE ) );
$form->add( new \IPS\Helpers\Form\Url( 'block_rss_import_url', ( isset( $this->configuration['block_rss_import_url'] ) ? $this->configuration['block_rss_import_url'] : NULL ), TRUE ) );
+3 -5
View File
@@ -12,7 +12,7 @@
namespace IPS\cms\widgets;
/* 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;
@@ -41,14 +41,12 @@ class _Wysiwyg extends \IPS\Widget\StaticCache
/**
* Specify widget configuration
*
* @param \IPS\Helpers\Form|NULL $form Form helper
* @return null|\IPS\Helpers\Form
*/
public function configuration( &$form=null )
{
if ( $form === null )
{
$form = new \IPS\Helpers\Form;
}
$form = parent::configuration( $form );
$form->add( new \IPS\Helpers\Form\Editor( 'content', ( isset( $this->configuration['content'] ) ? $this->configuration['content'] : NULL ), FALSE, array(
'app' => $this->app,
@@ -0,0 +1,85 @@
<?php
/**
* @brief oembed Widget
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 30 Sep 2019
*/
namespace IPS\cms\widgets;
/* 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;
}
/**
* oembed Widget
*/
class _pagebuilderoembed extends \IPS\Widget\StaticCache implements \IPS\Widget\Builder
{
/**
* @brief Widget Key
*/
public $key = 'pagebuilderoembed';
/**
* @brief App
*/
public $app = 'cms';
/**
* @brief Plugin
*/
public $plugin = '';
/**
* Specify widget configuration
*
* @param null|\IPS\Helpers\Form $form Form object
* @return null|\IPS\Helpers\Form
*/
public function configuration( &$form=null )
{
$form = parent::configuration( $form );
$form->add( new \IPS\Helpers\Form\Url( 'video_url', ( isset( $this->configuration['video_url'] ) )? $this->configuration['video_url'] : NULL, TRUE, array(), function( $url ) {
if ( \IPS\Text\Parser::embeddableMedia( \IPS\Http\Url::external( $url ) ) === NULL )
{
throw new \DomainException('video_cannot_embed');
}
} ) );
return $form;
}
/**
* Ran before saving widget configuration
*
* @param array $values Values from form
* @return array
*/
public function preConfig( $values )
{
$values['video_url'] = (string) $values['video_url'];
return $values;
}
/**
* Render a widget
*
* @return string
*/
public function render()
{
if ( isset( $this->configuration['video_url'] ) AND $embed = \IPS\Text\Parser::embeddableMedia( \IPS\Http\Url::external( $this->configuration['video_url'] ) ) )
{
return $this->output( $embed );
}
return '';
}
}
@@ -0,0 +1,68 @@
<?php
/**
* @brief pagebuildertext Widget
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 11 Feb 2020
*/
namespace IPS\cms\widgets;
/* 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;
}
/**
* pagebuildertext Widget
*/
class _pagebuildertext extends \IPS\Widget\StaticCache implements \IPS\Widget\Builder
{
/**
* @brief Widget Key
*/
public $key = 'pagebuildertext';
/**
* @brief App
*/
public $app = 'cms';
/**
* @brief Plugin
*/
public $plugin = '';
/**
* Specify widget configuration
*
* @param null|\IPS\Helpers\Form $form Form object
* @return null|\IPS\Helpers\Form
*/
public function configuration( &$form=null )
{
$form = parent::configuration( $form );
$form->add( new \IPS\Helpers\Form\TextArea( 'pagebuilder_text', ( isset( $this->configuration['pagebuilder_text'] ) ? $this->configuration['pagebuilder_text'] : '' ), FALSE, array( 'rows' => 10 ) ) );
return $form;
}
/**
* Render a widget
*
* @return string
*/
public function render()
{
if ( ! empty( $this->configuration['pagebuilder_text'] ) )
{
return $this->output( $this->configuration['pagebuilder_text'] );
}
return '';
}
}
@@ -0,0 +1,155 @@
<?php
/**
* @brief pagebuilderupload Widget
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 11 Feb 2020
*/
namespace IPS\cms\widgets;
/* 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;
}
/**
* pagebuilderupload Widget
*/
class _pagebuilderupload extends \IPS\Widget\StaticCache implements \IPS\Widget\Builder
{
/**
* @brief Widget Key
*/
public $key = 'pagebuilderupload';
/**
* @brief App
*/
public $app = 'cms';
/**
* @brief Plugin
*/
public $plugin = '';
/**
* Specify widget configuration
*
* @param null|\IPS\Helpers\Form $form Form object
* @return null|\IPS\Helpers\Form
*/
public function configuration( &$form=null )
{
$form = parent::configuration( $form );
$images = array();
$captions = array();
$urls = array();
if ( ! empty( $this->configuration['pagebuilderupload_upload'] ) )
{
foreach( explode( ',', $this->configuration['pagebuilderupload_upload'] ) as $img )
{
$images[] = \IPS\File::get( 'core_Attachment', $img );
}
}
if ( ! empty( $this->configuration['pagebuilderupload_captions'] ) )
{
foreach( $this->configuration['pagebuilderupload_captions'] as $caption )
{
$captions[] = $caption;
}
}
if ( ! empty( $this->configuration['pagebuilderupload_urls'] ) )
{
foreach( json_decode( $this->configuration['pagebuilderupload_urls'], TRUE ) as $url )
{
$urls[] = $url;
}
}
$form->add( new \IPS\Helpers\Form\Upload( 'pagebuilderupload_upload', $images, FALSE, array( 'multiple' => true, 'storageExtension' => 'core_Attachment', 'allowStockPhotos' => TRUE, 'image' => true ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'pagebuilderupload_slideshow', ( isset( $this->configuration['pagebuilderupload_slideshow'] ) ? $this->configuration['pagebuilderupload_slideshow'] : FALSE ) ) );
$form->add( new \IPS\Helpers\Form\Stack( 'pagebuilderupload_captions', $captions, FALSE, array( 'stackFieldType' => 'Text' ) ) );
$form->add( new \IPS\Helpers\Form\Stack( 'pagebuilderupload_urls', $urls, FALSE, array( 'stackFieldType' => 'Url' ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'pagebuilderupload_height', ( isset( $this->configuration['pagebuilderupload_height'] ) ? $this->configuration['pagebuilderupload_height'] : 300 ), FALSE, array( 'unlimited' => 0 ) ) );
return $form;
}
/**
* Before the widget is removed, we can do some clean up
*
* @return void
*/
public function delete()
{
foreach( explode( ',', $this->configuration['pagebuilderupload_upload'] ) as $img )
{
try
{
\IPS\File::get( 'core_Attachment', $img )->delete();
}
catch( \Exception $e ) { }
}
}
/**
* Ran before saving widget configuration
*
* @param array $values Values from form
* @return array
*/
public function preConfig( $values )
{
$images = array();
$urls = array();
foreach( $values['pagebuilderupload_upload'] as $img )
{
$images[] = (string) $img;
}
foreach( $values['pagebuilderupload_urls'] as $url )
{
$urls[] = (string) $url;
}
$values['pagebuilderupload_upload'] = implode( ',', $images );
$values['pagebuilderupload_urls'] = json_encode( $urls );
return $values;
}
/**
* Render a widget
*
* @return string
*/
public function render()
{
$images = array();
$captions = ( isset( $this->configuration['pagebuilderupload_captions'] ) ) ? $this->configuration['pagebuilderupload_captions'] : array();
$urls = ( isset( $this->configuration['pagebuilderupload_urls'] ) ) ? json_decode( $this->configuration['pagebuilderupload_urls'], TRUE ) : array();
$autoPlay = ( isset( $this->configuration['pagebuilderupload_slideshow'] ) ) ? $this->configuration['pagebuilderupload_slideshow'] : FALSE;
$maxHeight = ( isset( $this->configuration['pagebuilderupload_height'] ) ) ? $this->configuration['pagebuilderupload_height'] : FALSE;
if ( isset( $this->configuration['pagebuilderupload_upload'] ) )
{
foreach( explode( ',', $this->configuration['pagebuilderupload_upload'] ) as $img )
{
$images[] = (string) \IPS\File::get( 'core_Attachment', $img )->url;
}
return $this->output( ( \count( $images ) === 1 ? $images[0] : $images ), $captions, $urls, $autoPlay, $maxHeight );
}
return '';
}
}