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
+101
-7
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Lockable Interface for Content Models/Comments
|
||||
* @brief Lockable Trait for Content Models/Comments
|
||||
* @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/
|
||||
@@ -10,18 +10,112 @@
|
||||
|
||||
namespace IPS\Content;
|
||||
|
||||
use BadMethodCallException;
|
||||
use IPS\Member;
|
||||
|
||||
use function defined;
|
||||
use function get_class;
|
||||
use function header;
|
||||
use function explode;
|
||||
use function in_array;
|
||||
|
||||
/* 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' );
|
||||
header( ($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0') . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lockable Interface for Content Models/Comments
|
||||
*
|
||||
* @note Content classes will gain special functionality by implementing this interface
|
||||
* Lockable Trait for Content Models/Comments
|
||||
*/
|
||||
interface Lockable
|
||||
trait Lockable
|
||||
{
|
||||
/**
|
||||
* Is locked?
|
||||
*
|
||||
* @return bool
|
||||
* @throws BadMethodCallException: bool
|
||||
*/
|
||||
public function locked(): bool
|
||||
{
|
||||
if ( isset( static::$databaseColumnMap['locked'] ) )
|
||||
{
|
||||
return (bool) $this->mapped('locked');
|
||||
}
|
||||
|
||||
if( isset( static::$databaseColumnMap['status'] ) )
|
||||
{
|
||||
return ( $this->mapped('status') == 'closed' );
|
||||
}
|
||||
|
||||
throw new BadMethodCallException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can lock?
|
||||
*
|
||||
* @param Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return bool
|
||||
*/
|
||||
public function canLock( ?Member $member=NULL ): bool
|
||||
{
|
||||
if( !$this->actionEnabled( 'lock', $member ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->locked() === TRUE )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
if( $member->member_id and static::modPermission( 'lock', $member, $this->containerWrapper() ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if( ( $member->group['g_lock_unlock_own'] == '1' or in_array( get_class( $this ), explode( ',', $member->group['g_lock_unlock_own'] ) ) ) AND $member->member_id == $this->author()->member_id )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can unlock?
|
||||
*
|
||||
* @param Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return bool
|
||||
*/
|
||||
public function canUnlock( ?Member $member=NULL ): bool
|
||||
{
|
||||
if( !$this->actionEnabled( 'unlock', $member ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->locked() === FALSE )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
if( $member->member_id and static::modPermission( 'unlock', $member, $this->containerWrapper() ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if( $member->group['g_lock_unlock_own'] AND $member->member_id == $this->author()->member_id )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user