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,16 +12,50 @@ namespace IPS\core\Announcements;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
use InvalidArgumentException;
|
||||
use IPS\Application;
|
||||
use IPS\Content\Controller;
|
||||
use IPS\Content\Item;
|
||||
use IPS\Data\Store;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Custom;
|
||||
use IPS\Helpers\Form\Date;
|
||||
use IPS\Helpers\Form\Editor;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Helpers\Form\Url as FormUrl;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use RuntimeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Announcements Model
|
||||
*/
|
||||
class _Announcement extends \IPS\Content\Item
|
||||
class Announcement extends Item
|
||||
{
|
||||
/**
|
||||
* @brief Title-only announcement
|
||||
@@ -41,43 +75,43 @@ class _Announcement extends \IPS\Content\Item
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_announcements';
|
||||
public static ?string $databaseTable = 'core_announcements';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'announcements' );
|
||||
protected array $caches = array( 'announcements' );
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'core';
|
||||
public static string $application = 'core';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'announce_';
|
||||
public static string $databasePrefix = 'announce_';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
protected static array $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
public static array $databaseColumnMap = array(
|
||||
'title' => 'title',
|
||||
'date' => 'start',
|
||||
'author' => 'member_id',
|
||||
@@ -88,19 +122,19 @@ class _Announcement extends \IPS\Content\Item
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $title = 'announcement';
|
||||
public static string $title = 'announcement';
|
||||
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $icon = 'bullhorn';
|
||||
public static string $icon = 'bullhorn';
|
||||
|
||||
/**
|
||||
* Get page location array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_page_location()
|
||||
protected function get_page_location() : array
|
||||
{
|
||||
return explode( ',', $this->_data['page_location'] );
|
||||
}
|
||||
@@ -110,15 +144,15 @@ class _Announcement extends \IPS\Content\Item
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_seo_title()
|
||||
public function get_seo_title() : string
|
||||
{
|
||||
if( !$this->_data['seo_title'] )
|
||||
{
|
||||
$this->seo_title = \IPS\Http\Url\Friendly::seoTitle( $this->title );
|
||||
$this->seo_title = Friendly::seoTitle( $this->title );
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return $this->_data['seo_title'] ?: \IPS\Http\Url\Friendly::seoTitle( $this->title );
|
||||
return $this->_data['seo_title'] ?: Friendly::seoTitle( $this->title );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,10 +161,10 @@ class _Announcement extends \IPS\Content\Item
|
||||
* @param string $location Page location: top, content or sidebar
|
||||
* @return array
|
||||
*/
|
||||
public static function loadAllByLocation( $location )
|
||||
public static function loadAllByLocation( string $location ) : array
|
||||
{
|
||||
/* Are we banned? If so, do not return any announcements */
|
||||
if ( \IPS\Member::loggedIn()->isBanned() )
|
||||
if ( Member::loggedIn()->isBanned() )
|
||||
{
|
||||
return [];
|
||||
}
|
||||
@@ -143,7 +177,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
$announcement = static::constructFromData( $announce );
|
||||
|
||||
/* Check page location, active status and permissions */
|
||||
if( ! \in_array( $location, $announcement->page_location ) OR !$announcement->active OR ( $announcement->start !== 0 AND $announcement->start >= time() ) OR ( $announcement->end !== 0 AND $announcement->end <= time() ) OR !$announcement->canView() )
|
||||
if( ! in_array( $location, $announcement->page_location ) OR !$announcement->active OR ( $announcement->start !== 0 AND $announcement->start >= time() ) OR ( $announcement->end !== 0 AND $announcement->end <= time() ) OR !$announcement->canView() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -156,15 +190,15 @@ class _Announcement extends \IPS\Content\Item
|
||||
}
|
||||
|
||||
/* If the dispatcher did not finish loading (perhaps we hit an error that occurred early in execution) we can't check per-app locations */
|
||||
if( !\IPS\Dispatcher::i()->application )
|
||||
if( !Dispatcher::i()->application )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$extensions = \IPS\Dispatcher::i()->application->extensions( 'core', 'Announcements' );
|
||||
$extensions = Dispatcher::i()->application->extensions( 'core', 'Announcements' );
|
||||
|
||||
/* If we have no extension, we can only check the global setting */
|
||||
if ( !$extensions AND $announcement->app == \IPS\Dispatcher::i()->application->directory )
|
||||
if ( !$extensions AND $announcement->app == Dispatcher::i()->application->directory )
|
||||
{
|
||||
$return[] = $announcement;
|
||||
}
|
||||
@@ -175,37 +209,37 @@ class _Announcement extends \IPS\Content\Item
|
||||
{
|
||||
$id = $extension::$idField;
|
||||
|
||||
if ( $announcement->ids AND isset( \IPS\Request::i()->$id ) )
|
||||
if ( $announcement->ids AND isset( Request::i()->$id ) )
|
||||
{
|
||||
/* Are we viewing a content item */
|
||||
if ( \IPS\Dispatcher::i()->dispatcherController instanceof \IPS\Content\Controller )
|
||||
if ( Dispatcher::i()->dispatcherController instanceof Controller )
|
||||
{
|
||||
foreach( \IPS\Dispatcher::i()->application->extensions( 'core', 'ContentRouter' ) AS $contentRouter )
|
||||
foreach( 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 ) ) )
|
||||
if( $announcement->location == $key AND in_array( $class::load( Request::i()->$id )->mapped('container'), explode( ',', $announcement->ids ) ) )
|
||||
{
|
||||
$return[] = $announcement;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
catch( OutOfRangeException $e ){}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Or are we inside an allowed controller */
|
||||
else if (isset( \IPS\Dispatcher::i()->dispatcherController ) AND \in_array( \get_class( \IPS\Dispatcher::i()->dispatcherController ), $extension::$controllers ) )
|
||||
else if (isset( Dispatcher::i()->dispatcherController ) AND in_array( get_class( Dispatcher::i()->dispatcherController ), $extension::$controllers ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( $announcement->location == $key AND \in_array( \IPS\Request::i()->$id , explode( ',', $announcement->ids ) ) )
|
||||
if( $announcement->location == $key AND in_array( Request::i()->$id , explode( ',', $announcement->ids ) ) )
|
||||
{
|
||||
$return[] = $announcement;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
catch( OutOfRangeException $e ){}
|
||||
}
|
||||
}
|
||||
/* App specific, doesn't matter which container we're in */
|
||||
@@ -224,30 +258,31 @@ class _Announcement extends \IPS\Content\Item
|
||||
* Display Form
|
||||
*
|
||||
* @param static|NULL $announcement Existing announcement (for edits)
|
||||
* @return \IPS\Helpers\Form
|
||||
* @return Form
|
||||
*/
|
||||
public static function form( $announcement )
|
||||
public static function form( ?Announcement $announcement ) : Form
|
||||
{
|
||||
/* Build the form */
|
||||
$form = new \IPS\Helpers\Form( NULL, 'save' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form = new Form( NULL, 'save' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--edit-announcement';
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'announce_title', ( $announcement ) ? $announcement->title : NULL, TRUE, array( 'maxLength' => 255 ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'announce_start', ( $announcement ) ? \IPS\DateTime::ts( $announcement->start ) : new \IPS\DateTime ) );
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'announce_end', ( $announcement AND $announcement->end ) ? \IPS\DateTime::ts( $announcement->end ) : 0, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'indefinitely' ), function($val){
|
||||
|
||||
$form->add( new Text( 'announce_title', ( $announcement ) ? $announcement->title : NULL, TRUE, array( 'maxLength' => 255 ) ) );
|
||||
$form->add( new Date( 'announce_start', ( $announcement ) ? DateTime::ts( $announcement->start ) : new DateTime ) );
|
||||
$form->add( new Date( 'announce_end', ( $announcement AND $announcement->end ) ? DateTime::ts( $announcement->end ) : 0, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'indefinitely' ), function($val){
|
||||
|
||||
/* Compare with announce_start and make sure it's after this */
|
||||
$start = new \IPS\DateTime( \IPS\Request::i()->announce_start );
|
||||
$start = new DateTime( Request::i()->announce_start );
|
||||
if( $val and $val->getTimestamp() < $start->getTimestamp() )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'invalid_end_date' );
|
||||
throw new InvalidArgumentException( 'invalid_end_date' );
|
||||
}
|
||||
} ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'announce_type', ( $announcement ) ? $announcement->type : 'content', TRUE, array(
|
||||
|
||||
$form->add( new Radio( 'announce_type', ( $announcement ) ? $announcement->type : 'content', TRUE, array(
|
||||
'options' => array(
|
||||
static::TYPE_NONE => \IPS\Member::loggedIn()->language()->addToStack( 'announce_type_none' ),
|
||||
static::TYPE_CONTENT => \IPS\Member::loggedIn()->language()->addToStack( 'announce_type_content' ),
|
||||
static::TYPE_URL => \IPS\Member::loggedIn()->language()->addToStack( 'announce_type_url' ),
|
||||
static::TYPE_NONE => Member::loggedIn()->language()->addToStack( 'announce_type_none' ),
|
||||
static::TYPE_CONTENT => Member::loggedIn()->language()->addToStack( 'announce_type_content' ),
|
||||
static::TYPE_URL => Member::loggedIn()->language()->addToStack( 'announce_type_url' ),
|
||||
),
|
||||
'toggles' => array(
|
||||
static::TYPE_CONTENT => array( 'announce_content' ),
|
||||
@@ -255,19 +290,19 @@ class _Announcement extends \IPS\Content\Item
|
||||
),
|
||||
) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'announce_content', ( $announcement ) ? $announcement->content : NULL, NULL, array( 'app' => 'core', 'key' => 'Announcement', 'autoSaveKey' => ( $announcement ? 'editAnnouncement__' . $announcement->id : 'createAnnouncement' ), 'attachIds' => $announcement ? array( $announcement->id, NULL, 'announcement' ) : NULL ), NULL, NULL, NULL, 'announce_content' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'announce_url', ( $announcement ) ? $announcement->url : NULL, NULL, array( 'maxLength' => 2048 ), NULL, NULL, NULL, 'announce_url' ) );
|
||||
$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' ) ) ) );
|
||||
$form->add( new Editor( 'announce_content', ( $announcement ) ? $announcement->content : NULL, NULL, array( 'app' => 'core', 'key' => 'Announcement', 'autoSaveKey' => ( $announcement ? 'editAnnouncement__' . $announcement->id : 'createAnnouncement' ), 'attachIds' => $announcement ? array( $announcement->id, NULL, 'announcement' ) : NULL ), NULL, NULL, NULL, 'announce_content' ) );
|
||||
$form->add( new FormUrl( 'announce_url', ( $announcement ) ? $announcement->url : NULL, NULL, array( 'maxLength' => 2048 ), NULL, NULL, NULL, 'announce_url' ) );
|
||||
$form->add( new CheckboxSet( 'announce_page_location', ( $announcement ) ? $announcement->page_location : array(), TRUE, array( 'options' => array( 'top' => 'page_top', 'content' => 'content_top', 'sidebar' => 'sidebar' ) ) ) );
|
||||
|
||||
/* Apps */
|
||||
$apps = array();
|
||||
|
||||
foreach( \IPS\Application::applications() as $key => $data )
|
||||
foreach( Application::applications() as $key => $data )
|
||||
{
|
||||
if ( $key != 'core' )
|
||||
{
|
||||
/* Don't list apps without front modules or that are not being revealed */
|
||||
if( !\count( $data->modules( 'front' ) ) OR $data->hide_tab )
|
||||
if( !count( $data->modules( 'front' ) ) OR $data->hide_tab )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -279,21 +314,18 @@ class _Announcement extends \IPS\Content\Item
|
||||
$toggles = array();
|
||||
$formFields = array();
|
||||
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'Announcements', TRUE, 'core' ) as $key => $extension )
|
||||
foreach ( Application::allExtensions( 'core', 'Announcements', TRUE, 'core' ) as $key => $extension )
|
||||
{
|
||||
$app = mb_substr( $key, 0, mb_strpos( $key, '_' ) );
|
||||
|
||||
if( method_exists( $extension, 'getSettingField' ) )
|
||||
{
|
||||
/* Grab our fields and add to the form */
|
||||
$field = $extension->getSettingField( $announcement );
|
||||
|
||||
$toggles[ $app ][] = $field->name;
|
||||
$formFields[] = $field;
|
||||
}
|
||||
/* Grab our fields and add to the form */
|
||||
$field = $extension->getSettingField( $announcement );
|
||||
|
||||
$toggles[ $app ][] = $field->name;
|
||||
$formFields[] = $field;
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'announce_app', ( $announcement ) ? $announcement->app : '*', TRUE, array( 'options' => $apps,'toggles' => $toggles, 'unlimited' => "*", 'unlimitedLang' => "everywhere" ) ) );
|
||||
$form->add( new Select( 'announce_app', ( $announcement ) ? $announcement->app : '*', TRUE, array( 'options' => $apps,'toggles' => $toggles, 'unlimited' => "*", 'unlimitedLang' => "everywhere" ) ) );
|
||||
|
||||
foreach( $formFields as $field )
|
||||
{
|
||||
@@ -301,15 +333,15 @@ class _Announcement extends \IPS\Content\Item
|
||||
}
|
||||
|
||||
$groups = array();
|
||||
foreach ( \IPS\Member\Group::groups() as $group )
|
||||
foreach ( Group::groups() as $group )
|
||||
{
|
||||
$groups[ $group->g_id ] = $group->name;
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'announce_permissions', $announcement ? ( $announcement->permissions == '*' ? '*' : explode( ',', $announcement->permissions ) ) : '*', NULL, array( 'multiple' => TRUE, 'options' => $groups, 'unlimited' => '*', 'unlimitedLang' => 'everyone', 'impliedUnlimited' => TRUE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'announce_color', $announcement ? $announcement->color : 'information', NULL, array( 'getHtml' => function( $element )
|
||||
$form->add( new CheckboxSet( 'announce_permissions', $announcement ? ( $announcement->permissions == '*' ? '*' : explode( ',', $announcement->permissions ) ) : '*', NULL, array( 'multiple' => TRUE, 'options' => $groups, 'unlimited' => '*', 'unlimitedLang' => 'everyone', 'impliedUnlimited' => TRUE ) ) );
|
||||
$form->add( new 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 );
|
||||
return Theme::i()->getTemplate( 'forms', 'core', 'front' )->colorSelection( $element->name, $element->value );
|
||||
} ), NULL, NULL, NULL, 'announce_color' ) );
|
||||
|
||||
return $form;
|
||||
@@ -320,24 +352,24 @@ class _Announcement extends \IPS\Content\Item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStore()
|
||||
public static function getStore(): array
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->announcements ) )
|
||||
if ( !isset( Store::i()->announcements ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->announcements = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, NULL, "announce_id ASC" )->setKeyField( 'announce_id' ) );
|
||||
Store::i()->announcements = iterator_to_array( Db::i()->select( '*', static::$databaseTable, NULL, "announce_id ASC" )->setKeyField( 'announce_id' ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->announcements;
|
||||
return Store::i()->announcements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create from form
|
||||
*
|
||||
* @param array $values Values from form
|
||||
* @param \IPS\core\Announcements\Announcement|NULL $current Current announcement
|
||||
* @return \IPS\core\Announcements\Announcement
|
||||
* @param Announcement|null $current Current announcement
|
||||
* @return Announcement
|
||||
*/
|
||||
public static function _createFromForm( $values, $current )
|
||||
public static function _createFromForm( array $values, ?Announcement $current ) : static
|
||||
{
|
||||
if( $current )
|
||||
{
|
||||
@@ -346,18 +378,18 @@ class _Announcement extends \IPS\Content\Item
|
||||
else
|
||||
{
|
||||
$obj = new static;
|
||||
$obj->member_id = \IPS\Member::loggedIn()->member_id;
|
||||
$obj->member_id = Member::loggedIn()->member_id;
|
||||
}
|
||||
|
||||
$obj->title = $values['announce_title'];
|
||||
$obj->seo_title = \IPS\Http\Url\Friendly::seoTitle( $values['announce_title'] );
|
||||
$obj->seo_title = Friendly::seoTitle( $values['announce_title'] );
|
||||
$obj->type = $values['announce_type'];
|
||||
$obj->content = $values['announce_content'];
|
||||
$obj->url = $values['announce_url'];
|
||||
$obj->start = $values['announce_start'] ? $values['announce_start']->getTimestamp() : time();
|
||||
$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->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'];
|
||||
|
||||
@@ -365,24 +397,21 @@ class _Announcement extends \IPS\Content\Item
|
||||
$obj->location = "*";
|
||||
$obj->ids = NULL;
|
||||
|
||||
if( \in_array( $obj->app, array_keys(\IPS\Application::applications() ) ) )
|
||||
if( in_array( $obj->app, array_keys(Application::applications() ) ) )
|
||||
{
|
||||
foreach ( \IPS\Application::load( $obj->app )->extensions( 'core', 'Announcements' ) as $key => $extension )
|
||||
foreach ( Application::load( $obj->app )->extensions( 'core', 'Announcements' ) as $key => $extension )
|
||||
{
|
||||
if( method_exists( $extension, 'getSettingField' ) )
|
||||
{
|
||||
$field = $extension->getSettingField( array() );
|
||||
$obj->ids = \is_array( $values[ $field->name ] ) ? implode( ",", array_keys( $values[ $field->name ] ) ) : $values[ $field->name ];
|
||||
$obj->location = mb_substr( $key, mb_strpos( $key, '_' ) );
|
||||
}
|
||||
}
|
||||
$field = $extension->getSettingField( [] );
|
||||
$obj->ids = is_array( $values[ $field->name ] ) ? implode( ",", array_keys( $values[ $field->name ] ) ) : $values[ $field->name ];
|
||||
$obj->location = mb_substr( $key, mb_strpos( $key, '_' ) );
|
||||
}
|
||||
}
|
||||
|
||||
$obj->save();
|
||||
|
||||
if( !$current )
|
||||
{
|
||||
\IPS\File::claimAttachments( 'createAnnouncement', $obj->id, NULL, 'announcement' );
|
||||
File::claimAttachments( 'createAnnouncement', $obj->id, NULL, 'announcement' );
|
||||
}
|
||||
|
||||
return $obj;
|
||||
@@ -391,28 +420,28 @@ class _Announcement extends \IPS\Content\Item
|
||||
/**
|
||||
* @brief Cached URLs
|
||||
*/
|
||||
protected $_url = array();
|
||||
protected mixed $_url = array();
|
||||
|
||||
/**
|
||||
* Get URL
|
||||
*
|
||||
* @param string|NULL $action Action
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url
|
||||
*/
|
||||
public function url( $action=NULL )
|
||||
public function url( string|null $action=NULL ): Url
|
||||
{
|
||||
$_key = md5( $action );
|
||||
$_key = $action ? md5( $action ) : NULL;
|
||||
|
||||
if( !isset( $this->_url[ $_key ] ) )
|
||||
{
|
||||
if( $action )
|
||||
{
|
||||
$this->_url[ $_key ] = \IPS\Http\Url::internal( "app=core&module=modcp&controller=modcp&tab=announcements&id={$this->id}", 'front', 'modcp_announcements' );
|
||||
$this->_url[ $_key ] = Url::internal( "app=core&module=modcp&controller=modcp&tab=announcements&id={$this->id}", 'front', 'modcp_announcements' );
|
||||
$this->_url[ $_key ] = $this->_url[ $_key ]->setQueryString( 'action', $action );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_url[ $_key ] = \IPS\Http\Url::internal( "app=core&module=system&controller=announcement&id={$this->id}", 'front', 'announcement', $this->seo_title );
|
||||
$this->_url[ $_key ] = Url::internal( "app=core&module=system&controller=announcement&id={$this->id}", 'front', 'announcement', $this->seo_title );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,11 +451,11 @@ class _Announcement extends \IPS\Content\Item
|
||||
/**
|
||||
* Get owner
|
||||
*
|
||||
* @return \IPS\Member
|
||||
* @return Member
|
||||
*/
|
||||
public function owner()
|
||||
public function owner() : Member
|
||||
{
|
||||
return \IPS\Member::load( $this->member_id );
|
||||
return Member::load( $this->member_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,29 +463,29 @@ class _Announcement extends \IPS\Content\Item
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function unclaimAttachments()
|
||||
protected function unclaimAttachments(): void
|
||||
{
|
||||
\IPS\File::unclaimAttachments( 'core_Announcement', $this->id, NULL, 'announcement' );
|
||||
File::unclaimAttachments( 'core_Announcement', $this->id, NULL, 'announcement' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Moderator Permission
|
||||
*
|
||||
* @param string $type 'edit', 'hide', 'unhide', 'delete', etc.
|
||||
* @param \IPS\Member|NULL $member The member to check for or NULL for the currently logged in member
|
||||
* @param \IPS\Node\Model|NULL $container The container
|
||||
* @param Member|NULL $member The member to check for or NULL for the currently logged in member
|
||||
* @param Model|NULL $container The container
|
||||
* @return bool
|
||||
*/
|
||||
public static function modPermission( $type, \IPS\Member $member = NULL, \IPS\Node\Model $container = NULL )
|
||||
public static function modPermission( string $type, ?Member $member = NULL, ?Model $container = NULL ): bool
|
||||
{
|
||||
if( \in_array( $type, array( 'move', 'merge', 'lock', 'unlock', 'feature', 'unfeature', 'pin', 'unpin' ) ) )
|
||||
if( in_array( $type, array( 'move', 'merge', 'lock', 'unlock', 'feature', 'unfeature', 'pin', 'unpin' ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( $type == 'hide' OR $type == 'unhide' OR $type == 'active' OR $type == 'inactive' )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
return $member->modPermission( "can_manage_announcements" );
|
||||
}
|
||||
|
||||
@@ -468,7 +497,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getTableFilters()
|
||||
public static function getTableFilters(): array
|
||||
{
|
||||
return array(
|
||||
'active', 'inactive'
|
||||
@@ -480,7 +509,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function tableStates()
|
||||
public function tableStates(): string
|
||||
{
|
||||
$states = explode( ' ', parent::tableStates() );
|
||||
|
||||
@@ -500,19 +529,19 @@ class _Announcement extends \IPS\Content\Item
|
||||
* Do Moderator Action
|
||||
*
|
||||
* @param string $action The action
|
||||
* @param \IPS\Member|NULL $member The member doing the action (NULL for currently logged in member)
|
||||
* @param Member|NULL $member The member doing the action (NULL for currently logged in member)
|
||||
* @param string|NULL $reason Reason (for hides)
|
||||
* @param bool $immediately Delete immediately
|
||||
* @return void
|
||||
* @throws \OutOfRangeException|\InvalidArgumentException|\RuntimeException
|
||||
* @throws OutOfRangeException|InvalidArgumentException|RuntimeException
|
||||
*/
|
||||
public function modAction( $action, \IPS\Member $member = NULL, $reason = NULL, $immediately = FALSE )
|
||||
public function modAction( string $action, ?Member $member = NULL, mixed $reason = NULL, bool $immediately=FALSE ): void
|
||||
{
|
||||
if( static::modPermission( $action, $member ) )
|
||||
{
|
||||
if( $action == 'active' )
|
||||
{
|
||||
\IPS\Session::i()->modLog( 'modlog__action_announceactive', array( static::$title => TRUE, $this->url()->__toString() => FALSE, $this->mapped('title') => FALSE ), $this );
|
||||
Session::i()->modLog( 'modlog__action_announceactive', array( static::$title => TRUE, $this->url()->__toString() => FALSE, $this->mapped('title') => FALSE ), $this );
|
||||
|
||||
$this->active = 1;
|
||||
$this->save();
|
||||
@@ -522,7 +551,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
|
||||
if( $action == 'inactive' )
|
||||
{
|
||||
\IPS\Session::i()->modLog( 'modlog__action_announceinactive', array( static::$title => TRUE, $this->url()->__toString() => FALSE, $this->mapped('title') => FALSE ), $this );
|
||||
Session::i()->modLog( 'modlog__action_announceinactive', array( static::$title => TRUE, $this->url()->__toString() => FALSE, $this->mapped('title') => FALSE ), $this );
|
||||
|
||||
$this->active = 0;
|
||||
$this->save();
|
||||
@@ -531,7 +560,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
}
|
||||
}
|
||||
|
||||
return parent::modAction( $action, $member, $reason, $immediately );
|
||||
parent::modAction( $action, $member, $reason, $immediately );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,7 +568,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function customMultimodActions()
|
||||
public function customMultimodActions(): array
|
||||
{
|
||||
if( !$this->active )
|
||||
{
|
||||
@@ -554,10 +583,10 @@ class _Announcement extends \IPS\Content\Item
|
||||
/**
|
||||
* Can view?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for or NULL for the currently logged in member
|
||||
* @param Member|NULL $member The member to check for or NULL for the currently logged in member
|
||||
* @return bool
|
||||
*/
|
||||
public function canView( $member=NULL )
|
||||
public function canView( ?Member $member=NULL ): bool
|
||||
{
|
||||
/* If all groups have access, we can */
|
||||
if( $this->permissions == '*' )
|
||||
@@ -566,12 +595,12 @@ class _Announcement extends \IPS\Content\Item
|
||||
}
|
||||
|
||||
/* Check member */
|
||||
$member = ( $member === NULL ) ? \IPS\Member::loggedIn() : $member;
|
||||
$member = ( $member === NULL ) ? Member::loggedIn() : $member;
|
||||
$memberGroups = array_merge( array( $member->member_group_id ), array_filter( explode( ',', $member->mgroup_others ) ) );
|
||||
$accessGroups = explode( ',', $this->permissions );
|
||||
|
||||
/* Are we in an allowed group? */
|
||||
if( \count( array_intersect( $accessGroups, $memberGroups ) ) )
|
||||
if( count( array_intersect( $accessGroups, $memberGroups ) ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -585,7 +614,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
* @note Return in format of array( array( 'action' => ..., 'icon' => ..., 'language' => ... ) )
|
||||
* @return array
|
||||
*/
|
||||
public static function availableCustomMultimodActions()
|
||||
public static function availableCustomMultimodActions(): array
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
@@ -614,7 +643,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
* @param array $value Page locations: top, content and sidebar
|
||||
* @return void
|
||||
*/
|
||||
protected function set_page_location( $value )
|
||||
protected function set_page_location( array $value ) : void
|
||||
{
|
||||
$this->_data['page_location'] = implode( ',', $value );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user