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,52 +11,65 @@
|
||||
namespace IPS\Helpers\CoverPhoto;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller as DispatcherController;
|
||||
use IPS\Helpers\CoverPhoto;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Upload;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cover Photo Controller
|
||||
*/
|
||||
abstract class _Controller extends \IPS\Dispatcher\Controller
|
||||
abstract class Controller extends DispatcherController
|
||||
{
|
||||
/**
|
||||
* Upload Cover Photo
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function coverPhotoUpload()
|
||||
protected function coverPhotoUpload() : void
|
||||
{
|
||||
$photo = $this->_coverPhotoGet();
|
||||
if ( !$photo->editable )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2S216/1', 403, '' );
|
||||
Output::i()->error( 'no_module_permission', '2S216/1', 403, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'coverPhoto' );
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'cover_photo', NULL, TRUE, array( 'image' => [ 'maxWidth' => NULL, 'maxHeight' => NULL ], 'allowStockPhotos' => TRUE, 'minimize' => FALSE, 'maxFileSize' => ( $photo->maxSize and $photo->maxSize != -1 ) ? $photo->maxSize / 1024 : NULL, 'storageExtension' => $this->_coverPhotoStorageExtension() ) ) );
|
||||
$form = new Form( 'coverPhoto' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--cover-photo ipsForm--noLabels';
|
||||
$form->add( new Upload( 'cover_photo', NULL, TRUE, array( 'image' => [ 'maxWidth' => NULL, 'maxHeight' => NULL ], 'allowStockPhotos' => TRUE, 'minimize' => FALSE, 'maxFileSize' => ( $photo->maxSize and $photo->maxSize != -1 ) ? $photo->maxSize / 1024 : NULL, 'storageExtension' => $this->_coverPhotoStorageExtension() ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
try
|
||||
{
|
||||
$photo->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
$this->_coverPhotoSet( new \IPS\Helpers\CoverPhoto( $values['cover_photo'], 0 ), 'new' );
|
||||
\IPS\Output::i()->redirect( $this->_coverPhotoReturnUrl()->setQueryString( array( '_position' => 1 ) ) );
|
||||
catch ( Exception $e ) { }
|
||||
$this->_coverPhotoSet( new CoverPhoto( $values['cover_photo'], 0 ), 'new' );
|
||||
Output::i()->redirect( $this->_coverPhotoReturnUrl()->setQueryString( array( '_position' => 1 ) ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Dispatcher::hasInstance() and \IPS\Dispatcher::i()->controllerLocation == 'admin' )
|
||||
if ( Dispatcher::hasInstance() and Dispatcher::i()->controllerLocation == 'admin' )
|
||||
{
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
Output::i()->output = $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,29 +78,29 @@ abstract class _Controller extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function coverPhotoRemove()
|
||||
protected function coverPhotoRemove() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
$photo = $this->_coverPhotoGet();
|
||||
if ( !$photo->editable )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2S216/2', 403, '' );
|
||||
Output::i()->error( 'no_module_permission', '2S216/2', 403, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$photo->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
catch ( Exception $e ) { }
|
||||
|
||||
$this->_coverPhotoSet( new \IPS\Helpers\CoverPhoto( NULL, 0 ), 'remove' );
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
$this->_coverPhotoSet( new CoverPhoto( NULL, 0 ), 'remove' );
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
Output::i()->json( 'OK' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->_coverPhotoReturnUrl() );
|
||||
Output::i()->redirect( $this->_coverPhotoReturnUrl() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,25 +109,25 @@ abstract class _Controller extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function coverPhotoPosition()
|
||||
protected function coverPhotoPosition() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
$photo = $this->_coverPhotoGet();
|
||||
if ( !$photo->editable )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2S216/3', 403, '' );
|
||||
Output::i()->error( 'no_module_permission', '2S216/3', 403, '' );
|
||||
}
|
||||
|
||||
$photo->offset = \IPS\Request::i()->offset;
|
||||
$photo->offset = Request::i()->offset;
|
||||
$this->_coverPhotoSet( $photo, 'reposition' );
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
Output::i()->json( 'OK' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $this->_coverPhotoReturnUrl() );
|
||||
Output::i()->redirect( $this->_coverPhotoReturnUrl() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,30 +136,30 @@ abstract class _Controller extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function _coverPhotoStorageExtension();
|
||||
abstract protected function _coverPhotoStorageExtension(): string;
|
||||
|
||||
/**
|
||||
* Set Cover Photo
|
||||
*
|
||||
* @param \IPS\Helpers\CoverPhoto $photo New Photo
|
||||
* @param CoverPhoto $photo New Photo
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function _coverPhotoSet( \IPS\Helpers\CoverPhoto $photo );
|
||||
abstract protected function _coverPhotoSet( CoverPhoto $photo ) : void;
|
||||
|
||||
/**
|
||||
* Get Cover Photo
|
||||
*
|
||||
* @return \IPS\Helpers\CoverPhoto
|
||||
* @return CoverPhoto
|
||||
*/
|
||||
abstract protected function _coverPhotoGet();
|
||||
abstract protected function _coverPhotoGet(): CoverPhoto;
|
||||
|
||||
/**
|
||||
* Get URL to return to after editing cover photo
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url
|
||||
*/
|
||||
protected function _coverPhotoReturnUrl()
|
||||
protected function _coverPhotoReturnUrl(): Url
|
||||
{
|
||||
return \IPS\Request::i()->referrer() ?: \IPS\Request::i()->url()->stripQueryString( array( 'do', 'csrfKey' ) );
|
||||
return Request::i()->referrer() ?: Request::i()->url()->stripQueryString( array( 'do', 'csrfKey' ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user