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,53 +12,68 @@
|
||||
namespace IPS\core\Attachments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\core\extensions\core\EditorMedia\Attachment;
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use UnderflowException;
|
||||
use function count;
|
||||
use function defined;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Table Builder for attachments
|
||||
*/
|
||||
class _Table extends \IPS\Helpers\Table\Db
|
||||
class Table extends \IPS\Helpers\Table\Db
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $table Database table
|
||||
* @param \IPS\Http\Url $baseUrl Base URL
|
||||
* @param Url $baseUrl Base URL
|
||||
* @param array|null $where WHERE clause
|
||||
* @param array|null $forceIndex Index to force
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $table, \IPS\Http\Url $baseUrl, $where=NULL, $forceIndex=NULL )
|
||||
public function __construct( $table, Url $baseUrl, $where=NULL, $forceIndex=NULL )
|
||||
{
|
||||
/* Do any multi-mod */
|
||||
if ( isset( \IPS\Request::i()->modaction ) )
|
||||
if ( isset( Request::i()->modaction ) )
|
||||
{
|
||||
$this->multiMod();
|
||||
}
|
||||
|
||||
return parent::__construct( $table, $baseUrl, $where, $forceIndex );
|
||||
parent::__construct( $table, $baseUrl, $where, $forceIndex );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return table filters
|
||||
*/
|
||||
public $showFilters = TRUE;
|
||||
public bool $showFilters = TRUE;
|
||||
|
||||
/**
|
||||
* Saved Actions (for multi-moderation)
|
||||
*/
|
||||
public $savedActions = array();
|
||||
public array $savedActions = array();
|
||||
|
||||
/**
|
||||
* Return the filters that are available for selecting table rows
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFilters()
|
||||
public function getFilters() : array
|
||||
{
|
||||
return array();
|
||||
}
|
||||
@@ -69,9 +84,9 @@ class _Table extends \IPS\Helpers\Table\Db
|
||||
* @param string|null $action Specific action to check (hide/unhide, etc.) or NULL for a generic check
|
||||
* @return bool
|
||||
*/
|
||||
public function canModerate( $action=NULL )
|
||||
public function canModerate( string $action=NULL ): bool
|
||||
{
|
||||
return (bool) \IPS\Member::loggedIn()->group['gbw_delete_attachments'];
|
||||
return (bool) Member::loggedIn()->group['gbw_delete_attachments'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +94,7 @@ class _Table extends \IPS\Helpers\Table\Db
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multimodActions()
|
||||
public function multimodActions() : array
|
||||
{
|
||||
return array( 'delete' );
|
||||
}
|
||||
@@ -89,56 +104,56 @@ class _Table extends \IPS\Helpers\Table\Db
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function multimod()
|
||||
protected function multimod() : void
|
||||
{
|
||||
if( !\is_array( \IPS\Request::i()->moderate ) )
|
||||
if( !is_array( Request::i()->moderate ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
foreach (\IPS\Request::i()->moderate as $id => $status )
|
||||
foreach (Request::i()->moderate as $id => $status )
|
||||
{
|
||||
try
|
||||
{
|
||||
$attachment = \IPS\Db::i()->select( '*', 'core_attachments', array( 'attach_id=?', $id ) )->first();
|
||||
$attachment = Db::i()->select( '*', 'core_attachments', array( 'attach_id=?', $id ) )->first();
|
||||
|
||||
/* Check it belongs to us */
|
||||
if ( $attachment['attach_member_id'] !== \IPS\Member::loggedIn()->member_id )
|
||||
if ( $attachment['attach_member_id'] !== Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2C388/1', 403, '' );
|
||||
Output::i()->error( 'no_module_permission', '2C388/1', 403, '' );
|
||||
}
|
||||
|
||||
/* And we can delete it */
|
||||
if ( !\IPS\Member::loggedIn()->group['gbw_delete_attachments'] )
|
||||
if ( !Member::loggedIn()->group['gbw_delete_attachments'] )
|
||||
{
|
||||
\IPS\core\extensions\core\EditorMedia\Attachment::getLocations( $attachment['attach_id'] );
|
||||
if ( \count( \IPS\core\extensions\core\EditorMedia\Attachment::$locations[ $attachment['attach_id'] ] ) )
|
||||
Attachment::getLocations( $attachment['attach_id'] );
|
||||
if ( count( Attachment::$locations[ $attachment['attach_id'] ] ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2C388/2', 403, '' );
|
||||
Output::i()->error( 'no_module_permission', '2C388/2', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'core_Attachment', $attachment['attach_location'] )->delete();
|
||||
File::get( 'core_Attachment', $attachment['attach_location'] )->delete();
|
||||
if ( $attachment['attach_thumb_location'] )
|
||||
{
|
||||
\IPS\File::get( 'core_Attachment', $attachment['attach_thumb_location'] )->delete();
|
||||
File::get( 'core_Attachment', $attachment['attach_thumb_location'] )->delete();
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
\IPS\Db::i()->delete( 'core_attachments', array( 'attach_id=?', $attachment['attach_id'] ) );
|
||||
\IPS\Db::i()->delete( 'core_attachments_map', array( 'attachment_id=?', $attachment['attach_id'] ) );
|
||||
catch ( Exception $e ) { }
|
||||
Db::i()->delete( 'core_attachments', array( 'attach_id=?', $attachment['attach_id'] ) );
|
||||
Db::i()->delete( 'core_attachments_map', array( 'attachment_id=?', $attachment['attach_id'] ) );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C388/3', 404, '' );
|
||||
Output::i()->error( 'node_error', '2C388/3', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=system&controller=attachments', 'front', 'attachments' ), 'deleted' );
|
||||
Output::i()->redirect( Url::internal( 'app=core&module=system&controller=attachments', 'front', 'attachments' ), 'deleted' );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user