Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

@@ -73,6 +73,16 @@ class _Announcement extends \IPS\Content\Item
*/
public static $icon = 'bullhorn';
/**
* Get page location array
*
* @return array
*/
protected function get_page_location()
{
return explode( ',', $this->_data['page_location'] );
}
/**
* Get SEO name
*
@@ -89,6 +99,71 @@ class _Announcement extends \IPS\Content\Item
return $this->_data['seo_title'] ?: \IPS\Http\Url\Friendly::seoTitle( $this->title );
}
/**
* Load announcements by page location
*
* @param string $location Page location: top, content or sidebar
* @return array
*/
public static function loadAllByLocation( $location )
{
$announcements = static::getStore();
$return = array();
foreach( $announcements as $announce )
{
$announcement = static::constructFromData( $announce );
/* Check page location, active status and permissions */
if( !in_array( $location, $announcement->page_location ) OR !$announcement->active OR ( $announcement->end !== 0 AND $announcement->end <= time() ) OR !$announcement->canView() )
{
continue;
}
/* Is this a global announcement? */
if( $announcement->app == '*' )
{
$return[] = $announcement;
continue;
}
/* App and container specific announcements */
foreach ( \IPS\Dispatcher::i()->application->extensions( 'core', 'Announcements' ) as $key => $extension )
{
$id = $extension::$idField;
if ( isset( \IPS\Request::i()->$id ) )
{
if ( \IPS\Dispatcher::i()->dispatcherController instanceof \IPS\Content\Controller )
{
foreach( \IPS\Dispatcher::i()->application->extensions( 'core', 'ContentRouter' ) AS $contentRouter )
{
foreach( $contentRouter->classes AS $class )
{
try
{
if( $announcement->location == $key AND in_array( $class::load( \IPS\Request::i()->$id )->mapped('container'), explode( ',', $announcement->ids ) ) )
{
$return[] = $announcement;
}
}
catch( \OutOfRangeException $e ){}
break 2;
}
}
}
}
/* App specific, doesn't matter which container we're in */
elseif( $announcement->location == $key )
{
$return[] = $announcement;
}
}
}
return $return;
}
/**
* Display Form
*
@@ -104,7 +179,8 @@ class _Announcement extends \IPS\Content\Item
$form->add( new \IPS\Helpers\Form\Date( 'announce_start', ( $announcement ) ? $announcement->start : new \IPS\DateTime ) );
$form->add( new \IPS\Helpers\Form\Date( 'announce_end', ( $announcement ) ? $announcement->end : 0, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'indefinitely' ) ) );
$form->add( new \IPS\Helpers\Form\Editor( 'announce_content', ( $announcement ) ? $announcement->content : NULL, TRUE, array( 'app' => 'core', 'key' => 'Announcement', 'autoSaveKey' => ( $announcement ? 'editAnnouncement__' . $announcement->id : 'createAnnouncement' ), 'attachIds' => $announcement ? array( $announcement->id, NULL, 'announcement' ) : NULL ) ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'announce_page_location', ( $announcement ) ? $announcement->page_location : array(), TRUE, array( 'options' => array( 'top' => 'page_top', 'content' => 'content_top', 'sidebar' => 'sidebar' ) ) ) );
/* Apps */
$apps = array();
@@ -112,6 +188,11 @@ class _Announcement extends \IPS\Content\Item
{
if ( $key != 'core' )
{
/* Don't list apps without front modules */
if( !count( $data->modules( 'front' ) ) )
{
continue;
}
$apps[ $key ] = $data->_title;
}
}
@@ -148,10 +229,28 @@ class _Announcement extends \IPS\Content\Item
}
$form->add( new \IPS\Helpers\Form\Select( 'announce_permissions', $announcement ? ( $announcement->permissions == '*' ? '*' : explode( ',', $announcement->permissions ) ) : '*', NULL, array( 'multiple' => TRUE, 'options' => $groups, 'unlimited' => '*', 'unlimitedLang' => 'everyone' ) ) );
$form->add( new \IPS\Helpers\Form\Custom( 'announce_color', $announcement ? $announcement->color : 'information', NULL, array( 'getHtml' => function( $element )
{
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'front' )->colorSelection( $element->name, $element->value );
} ), NULL, NULL, NULL, 'announce_color' ) );
return $form;
}
/**
* Get data store
*
* @return array
*/
public static function getStore()
{
if ( !isset( \IPS\Data\Store::i()->announcements ) )
{
\IPS\Data\Store::i()->announcements = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, NULL, "announce_id ASC" )->setKeyField( 'announce_id' ) );
}
return \IPS\Data\Store::i()->announcements;
}
/**
* Create from form
@@ -179,7 +278,8 @@ class _Announcement extends \IPS\Content\Item
$obj->end = $values['announce_end'] ? $values['announce_end']->getTimestamp() : 0;
$obj->app = $values['announce_app'] ? $values['announce_app'] : "*";
$obj->permissions = is_array( $values['announce_permissions'] ) ? implode( ',', $values['announce_permissions'] ) : '*';
$obj->page_location = $values['announce_page_location'];
$obj->color = $values['announce_color'];
if( in_array( $obj->app, array_keys(\IPS\Application::applications() ) ) )
{
@@ -337,8 +437,6 @@ class _Announcement extends \IPS\Content\Item
$this->active = 1;
$this->save();
\IPS\Widget::deleteCaches( 'announcements', 'core' );
return;
}
@@ -349,8 +447,6 @@ class _Announcement extends \IPS\Content\Item
$this->active = 0;
$this->save();
\IPS\Widget::deleteCaches( 'announcements', 'core' );
return;
}
}
@@ -440,7 +536,18 @@ class _Announcement extends \IPS\Content\Item
public function save()
{
parent::save();
static::rebuildAnnouncementsExist();
unset( \IPS\Data\Store::i()->announcements );
}
/**
* Set page location array
*
* @param array Page locations: top, content and sidebar
* @return void
*/
protected function set_page_location( $value )
{
$this->_data['page_location'] = implode( ',', $value );
}
/**
@@ -451,30 +558,6 @@ class _Announcement extends \IPS\Content\Item
public function delete()
{
parent::delete();
static::rebuildAnnouncementsExist();
}
/**
* Rebuild \IPS\Settings::i()->announcements_exist which is sued to flag if any announcements
* exist to save a query if we know there aren't any
*
* @return void
*/
protected static function rebuildAnnouncementsExist()
{
if ( \IPS\Db::i()->select( 'COUNT(*)', 'core_announcements', 'announce_active=1' )->first() )
{
$value = 1;
}
else
{
$value = 0;
}
if ( $value != \IPS\Settings::i()->announcements_exist )
{
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => $value ), array( 'conf_key=?', 'announcements_exist' ) );
unset( \IPS\Data\Store::i()->settings );
}
unset( \IPS\Data\Store::i()->announcements );
}
}