Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+84 -65
View File
@@ -12,59 +12,37 @@
namespace IPS\cms;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Data\Store;
use IPS\Db;
use IPS\Widget as SystemWidget;
use IPS\Widget\Area;
use function count;
use function defined;
use function in_array;
use function is_array;
use function json_decode;
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;
}
/**
* CMS Widgets
*/
class _Widget extends \IPS\Widget
class Widget extends SystemWidget
{
/**
* Fetch the configuration for this unqiue ID. Looks in active tables and trash. When a widget is moved, saveOrder is called twice,
* once to remove the widget from column A and again to add it to column B. We store the widget removed from column A into the trash
* table.
*
* @param string $uniqueId Widget's unique ID
* @return array
*/
public static function getConfiguration( $uniqueId )
{
foreach( \IPS\Db::i()->select( '*', 'cms_page_widget_areas' ) as $item )
{
$widgets = json_decode( $item['area_widgets'], TRUE );
if( \is_array( $widgets ) )
{
foreach( $widgets as $widget )
{
if ( $widget['unique'] == $uniqueId )
{
if ( isset( $widget['configuration'] ) )
{
return $widget['configuration'];
}
}
}
}
}
/* Still here? rummage in the trash */
return parent::getConfiguration( $uniqueId );
}
/**
* Delete caches. We need a different name from the parent class otherwise the Pages app hook will get stuck in infinite recursion
*
* @param String $key Widget key
* @param String $app Parent application
* @param String $plugin Parent plugin
* @param String|null $key Widget key
* @param String|null $app Parent application
* @param String|null $plugin Parent plugin
* @return void
*/
static public function deleteCachesForBlocks( $key=NULL, $app=NULL, $plugin=NULL )
static public function deleteCachesForBlocks( string $key=NULL, string $app=NULL, string $plugin=NULL ) : void
{
/* Delete any custom block caches relevant to this plug in */
if ( $key OR $app )
@@ -82,23 +60,36 @@ class _Widget extends \IPS\Widget
}
$blocks = array();
foreach( \IPS\Db::i()->select( '*', 'cms_blocks', $where ) as $row )
foreach( Db::i()->select( '*', 'cms_blocks', $where ) as $row )
{
$blocks[ $row['block_key'] ] = $row;
}
if ( \count( $blocks ) )
if ( count( $blocks ) )
{
$uniqueIds = array();
foreach( \IPS\Db::i()->select( '*', 'cms_page_widget_areas' ) as $item )
foreach( Db::i()->select( '*', 'cms_page_widget_areas' ) as $item )
{
$widgets = json_decode( $item['area_widgets'], TRUE );
if( $item['area_widgets'] )
{
$widgets = json_decode( $item['area_widgets'], TRUE );
}
else
{
$area = new Area( json_decode( $item['area_tree'], true ), $item['area_area'] );
$widgets = $area->getAllWidgets();
}
if( !is_array( $widgets ) or !count( $widgets ) )
{
continue;
}
foreach( $widgets as $widget )
{
if ( ( isset( $widget['app'] ) and $widget['app'] === 'cms' ) and $widget['key'] === 'Blocks' and isset( $widget['unique'] ) and isset( $widget['configuration'] ) and isset( $widget['configuration']['cms_widget_custom_block'] ) )
{
if ( \in_array( $widget['configuration']['cms_widget_custom_block'], array_keys( $blocks ) ) )
if ( in_array( $widget['configuration']['cms_widget_custom_block'], array_keys( $blocks ) ) )
{
$uniqueIds[] = $widget['unique'];
}
@@ -106,15 +97,28 @@ class _Widget extends \IPS\Widget
}
}
foreach( \IPS\Db::i()->select( '*', 'core_widget_areas' ) as $item )
foreach( Db::i()->select( '*', 'core_widget_areas' ) as $item )
{
$widgets = json_decode( $item['widgets'], TRUE );
if( $item['widgets'] )
{
$widgets = json_decode( $item['widgets'], TRUE );
}
else
{
$area = new Area( $item['area'], json_decode( $item['tree'], true ) );
$widgets = $area->getAllWidgets();
}
if( !is_array( $widgets ) or !count( $widgets ) )
{
continue;
}
foreach( $widgets as $widget )
{
if ( ( isset( $widget['app'] ) and $widget['app'] === 'cms' ) and $widget['key'] === 'Blocks' and isset( $widget['unique'] ) and isset( $widget['configuration'] ) and isset( $widget['configuration']['cms_widget_custom_block'] ) )
{
if ( \in_array( $widget['configuration']['cms_widget_custom_block'], array_keys( $blocks ) ) )
if ( in_array( $widget['configuration']['cms_widget_custom_block'], array_keys( $blocks ) ) )
{
$uniqueIds[] = $widget['unique'];
}
@@ -122,15 +126,15 @@ class _Widget extends \IPS\Widget
}
}
if ( \count( $uniqueIds ) )
if ( count( $uniqueIds ) )
{
$widgetRow = \IPS\Db::i()->select( '*', 'core_widgets', array( '`key`=? and app=?', 'Blocks', 'cms' ) )->first();
$widgetRow = Db::i()->select( '*', 'core_widgets', array( '`key`=? and app=?', 'Blocks', 'cms' ) )->first();
if ( ! empty( $widgetRow['caches'] ) )
{
$caches = json_decode( $widgetRow['caches'], TRUE );
if ( \is_array( $caches ) )
if ( is_array( $caches ) )
{
$save = $caches;
foreach( $caches as $key => $time )
@@ -139,9 +143,9 @@ class _Widget extends \IPS\Widget
{
if ( mb_stristr( $key, 'widget_Blocks_' . $id ) )
{
if ( isset( \IPS\Data\Store::i()->$key ) )
if ( isset( Store::i()->$key ) )
{
unset( \IPS\Data\Store::i()->$key );
unset( Store::i()->$key );
}
unset( $save[ $key ] );
@@ -149,10 +153,10 @@ class _Widget extends \IPS\Widget
}
}
if ( \count( $save ) !== \count( $caches ) )
if ( count( $save ) !== count( $caches ) )
{
\IPS\Db::i()->update( 'core_widgets', array( 'caches' => ( \count( $save ) ? json_encode( $save ) : NULL ) ), array( 'id=?', $widgetRow['id'] ) );
unset( \IPS\Data\Store::i()->widgets );
Db::i()->update( 'core_widgets', array( 'caches' => ( count( $save ) ? json_encode( $save ) : NULL ) ), array( 'id=?', $widgetRow['id'] ) );
unset( Store::i()->widgets );
}
}
}
@@ -166,25 +170,40 @@ class _Widget extends \IPS\Widget
*
* @return array
*/
public static function getUniqueIds()
public static function getUniqueIds(): array
{
$uniqueIds = parent::getUniqueIds();
foreach ( \IPS\Db::i()->select( '*', 'cms_page_widget_areas' ) as $row )
foreach ( Db::i()->select( '*', 'cms_page_widget_areas' ) as $row )
{
$data = json_decode( $row['area_widgets'], TRUE );
if ( is_countable( $data ) AND \count( $data ) )
if( $row['area_widgets'] )
{
foreach( $data as $widget )
$data = json_decode( $row['area_widgets'], TRUE );
if ( is_countable( $data ) AND count( $data ) )
{
if ( isset( $widget['unique'] ) )
{
foreach( $data as $widget )
{
if ( isset( $widget['unique'] ) )
{
$uniqueIds[] = $widget['unique'];
}
}
}
}
if( $row['area_tree'] )
{
$area = new Area( json_decode( $row['area_tree'], true ), $row['area_area'] );
foreach( $area->getAllWidgets() as $widget )
{
if( isset( $widget['unique'] ) )
{
$uniqueIds[] = $widget['unique'];
}
}
}
}
return $uniqueIds;
return array_unique( $uniqueIds );
}
}