Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\Announcements;
|
||||
|
||||
/* 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;
|
||||
@@ -22,11 +22,32 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _Announcement extends \IPS\Content\Item
|
||||
{
|
||||
/**
|
||||
* @brief Title-only announcement
|
||||
*/
|
||||
const TYPE_NONE = 0;
|
||||
|
||||
/**
|
||||
* @brief Standard announcement (title and body)
|
||||
*/
|
||||
const TYPE_CONTENT = 1;
|
||||
|
||||
/**
|
||||
* @brief URL announcement (title and link)
|
||||
*/
|
||||
const TYPE_URL = 2;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_announcements';
|
||||
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'announcements' );
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
@@ -115,7 +136,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;
|
||||
}
|
||||
@@ -158,7 +179,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
{
|
||||
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( \IPS\Request::i()->$id )->mapped('container'), explode( ',', $announcement->ids ) ) )
|
||||
{
|
||||
$return[] = $announcement;
|
||||
}
|
||||
@@ -168,11 +189,11 @@ class _Announcement extends \IPS\Content\Item
|
||||
}
|
||||
}
|
||||
/* Or are we inside an allowed controller */
|
||||
else if ( in_array( get_class( \IPS\Dispatcher::i()->dispatcherController ), $extension::$controllers ) )
|
||||
else if ( \in_array( \get_class( \IPS\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( \IPS\Request::i()->$id , explode( ',', $announcement->ids ) ) )
|
||||
{
|
||||
$return[] = $announcement;
|
||||
}
|
||||
@@ -195,6 +216,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
/**
|
||||
* Display Form
|
||||
*
|
||||
* @param static|NULL $announcement Existing announcement (for edits)
|
||||
* @return \IPS\Helpers\Form
|
||||
*/
|
||||
public static function form( $announcement )
|
||||
@@ -204,9 +226,23 @@ class _Announcement extends \IPS\Content\Item
|
||||
$form->class = 'ipsForm_vertical';
|
||||
|
||||
$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 ) ? $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\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' ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\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' ),
|
||||
),
|
||||
'toggles' => array(
|
||||
static::TYPE_CONTENT => array( 'announce_content' ),
|
||||
static::TYPE_URL => array( 'announce_url' )
|
||||
),
|
||||
) ) );
|
||||
|
||||
$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' ) ) ) );
|
||||
|
||||
/* Apps */
|
||||
@@ -217,7 +253,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
if ( $key != 'core' )
|
||||
{
|
||||
/* Don't list apps without front modules */
|
||||
if( !count( $data->modules( 'front' ) ) )
|
||||
if( !\count( $data->modules( 'front' ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -301,11 +337,13 @@ class _Announcement extends \IPS\Content\Item
|
||||
|
||||
$obj->title = $values['announce_title'];
|
||||
$obj->seo_title = \IPS\Http\Url\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->permissions = \is_array( $values['announce_permissions'] ) ? implode( ',', $values['announce_permissions'] ) : '*';
|
||||
$obj->page_location = $values['announce_page_location'];
|
||||
$obj->color = $values['announce_color'];
|
||||
|
||||
@@ -313,14 +351,14 @@ 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(\IPS\Application::applications() ) ) )
|
||||
{
|
||||
foreach ( \IPS\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->ids = \is_array( $values[ $field->name ] ) ? implode( ",", array_keys( $values[ $field->name ] ) ) : $values[ $field->name ];
|
||||
$obj->location = mb_substr( $key, mb_strpos( $key, '_' ) );
|
||||
}
|
||||
}
|
||||
@@ -397,7 +435,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
*/
|
||||
public static function modPermission( $type, \IPS\Member $member = NULL, \IPS\Node\Model $container = NULL )
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -519,7 +557,7 @@ class _Announcement extends \IPS\Content\Item
|
||||
$accessGroups = explode( ',', $this->permissions );
|
||||
|
||||
/* Are we in an allowed group? */
|
||||
if( count( array_intersect( $accessGroups, $memberGroups ) ) )
|
||||
if( \count( array_intersect( $accessGroups, $memberGroups ) ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -555,37 +593,15 @@ class _Announcement extends \IPS\Content\Item
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
parent::save();
|
||||
unset( \IPS\Data\Store::i()->announcements );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set page location array
|
||||
*
|
||||
* @param array Page locations: top, content and sidebar
|
||||
* @param array $value Page locations: top, content and sidebar
|
||||
* @return void
|
||||
*/
|
||||
protected function set_page_location( $value )
|
||||
{
|
||||
$this->_data['page_location'] = implode( ',', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
parent::delete();
|
||||
unset( \IPS\Data\Store::i()->announcements );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user