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
@@ -11,34 +11,50 @@
|
||||
namespace IPS\core\modules\front\system;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\core\Attachments\Table;
|
||||
use IPS\core\extensions\core\EditorMedia\Attachment;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* My Attachments Controller
|
||||
*/
|
||||
class _attachments extends \IPS\Dispatcher\Controller
|
||||
class attachments extends Controller
|
||||
{
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
/* Logged in and can upload only */
|
||||
if ( !\IPS\Member::loggedIn()->member_id or \IPS\Member::loggedIn()->group['g_attach_max'] == 0 )
|
||||
if ( !Member::loggedIn()->member_id or Member::loggedIn()->group['g_attach_max'] == 0 )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2C229/1', 403, '' );
|
||||
Output::i()->error( 'no_module_permission', '2C229/1', 403, '' );
|
||||
}
|
||||
|
||||
/* Build Table */
|
||||
$table = new \IPS\core\Attachments\Table( 'core_attachments', \IPS\Http\Url::internal( 'app=core&module=system&controller=attachments', 'front', 'attachments' ), array( array( 'attach_member_id=?', \IPS\Member::loggedIn()->member_id ) ) );
|
||||
$table = new Table( 'core_attachments', Url::internal( 'app=core&module=system&controller=attachments', 'front', 'attachments' ), array( array( 'attach_member_id=?', Member::loggedIn()->member_id ) ) );
|
||||
$table->include = array( 'attach_id', 'attach_location', 'attach_date', 'attach_file', 'attach_filesize', 'attach_is_image', 'attach_content', 'attach_hits', 'attach_security_key' );
|
||||
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate('myAttachments'), 'rows' );
|
||||
$table->rowsTemplate = array( Theme::i()->getTemplate('myAttachments'), 'rows' );
|
||||
$table->joins = array();
|
||||
|
||||
/* Sort */
|
||||
@@ -54,13 +70,13 @@ class _attachments extends \IPS\Dispatcher\Controller
|
||||
$self = $this;
|
||||
$table->parsers = array( 'attach_content' => function( $val, $row ) use ( $self )
|
||||
{
|
||||
return \IPS\core\extensions\core\EditorMedia\Attachment::getLocations( $row['attach_id'] );
|
||||
return Attachment::getLocations( $row['attach_id'] );
|
||||
} );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('my_attachments');
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack('my_attachments') );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('myAttachments')->template( (string) $table, \IPS\Db::i()->select( 'SUM(attach_filesize)', 'core_attachments', array( 'attach_member_id=?', \IPS\Member::loggedIn()->member_id ) )->first(), \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments', array( 'attach_member_id=?', \IPS\Member::loggedIn()->member_id ) )->first() );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('my_attachments');
|
||||
Output::i()->breadcrumb[] = array( NULL, Member::loggedIn()->language()->addToStack('my_attachments') );
|
||||
Output::i()->output = Theme::i()->getTemplate('myAttachments')->template( (string) $table, Db::i()->select( 'SUM(attach_filesize)', 'core_attachments', array( 'attach_member_id=?', Member::loggedIn()->member_id ) )->first(), Db::i()->select( 'COUNT(*)', 'core_attachments', array( 'attach_member_id=?', Member::loggedIn()->member_id ) )->first() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,50 +84,50 @@ class _attachments extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function rotate()
|
||||
protected function rotate() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* Get attachment to make sure it's valid */
|
||||
try
|
||||
{
|
||||
$attachment = \IPS\Db::i()->select( '*', 'core_attachments', [ 'attach_id=? and attach_is_image=?', \IPS\Request::i()->id, 1 ] )
|
||||
$attachment = Db::i()->select( '*', 'core_attachments', [ 'attach_id=? and attach_is_image=?', Request::i()->id, 1 ] )
|
||||
->join( 'core_attachments_map', 'core_attachments.attach_id=core_attachments_map.attachment_id' )
|
||||
->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'error' => 'node_error' ) );
|
||||
Output::i()->json( array( 'error' => 'node_error' ) );
|
||||
}
|
||||
|
||||
/* Check Permission */
|
||||
$exploded = explode( '_', $attachment['location_key'] );
|
||||
try
|
||||
{
|
||||
$extensions = \IPS\Application::load( $exploded[0] )->extensions( 'core', 'EditorLocations' );
|
||||
$extensions = Application::load( $exploded[0] )->extensions( 'core', 'EditorLocations' );
|
||||
if ( isset( $extensions[ $exploded[1] ] ) )
|
||||
{
|
||||
$attachmentItem = $extensions[ $exploded[1] ]->attachmentLookup( $attachment[ 'id1' ], $attachment[ 'id2' ], $attachment[ 'id3' ] );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'error' => 'no_permission' ) );
|
||||
Output::i()->json( array( 'error' => 'no_permission' ) );
|
||||
}
|
||||
|
||||
/* If we have permission to edit the post, we're going to save the rotation angle */
|
||||
if( $attachmentItem->author()->member_id == \IPS\Member::loggedIn()->member_id OR $attachmentItem->canEdit() )
|
||||
if( $attachmentItem->author()->member_id == Member::loggedIn()->member_id OR $attachmentItem->canEdit() )
|
||||
{
|
||||
$baseRotation = $attachment['attach_img_rotate'];
|
||||
$temp = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$baseRotation = \IPS\Request::i()->current ?? 0;
|
||||
$baseRotation = Request::i()->current ?? 0;
|
||||
$temp = true;
|
||||
}
|
||||
|
||||
$angle = \IPS\Request::i()->direction == 'right' ? 90 : -90;
|
||||
$angle = Request::i()->direction == 'right' ? 90 : -90;
|
||||
$rotation = $baseRotation + $angle;
|
||||
|
||||
/* Make sure we don't rotate to some stupid number */
|
||||
@@ -127,21 +143,21 @@ class _attachments extends \IPS\Dispatcher\Controller
|
||||
/* Store the angle for the future */
|
||||
if( !$temp )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_attachments', [ 'attach_img_rotate' => $rotation ], [ 'attach_id=?', $attachment[ 'attach_id' ] ] );
|
||||
Db::i()->update( 'core_attachments', [ 'attach_img_rotate' => $rotation ], [ 'attach_id=?', $attachment[ 'attach_id' ] ] );
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( [
|
||||
Output::i()->json( [
|
||||
'rotate' => $rotation,
|
||||
'message' => \IPS\Member::loggedIn()->language()->addToStack('gallery_image_rotated'),
|
||||
'fileId' => \IPS\Request::i()->id,
|
||||
'message' => Member::loggedIn()->language()->addToStack('gallery_image_rotated'),
|
||||
'fileId' => Request::i()->id,
|
||||
'saved' => $temp ? 0 : 1
|
||||
] );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $attachmentItem->url() );
|
||||
Output::i()->redirect( $attachmentItem->url() );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user