Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+51 -38
View File
@@ -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' ) );
}
}
+24 -17
View File
@@ -11,55 +11,62 @@
namespace IPS\Helpers;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\File;
use IPS\Output;
use IPS\Request;
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 Helper
*/
class _CoverPhoto
class CoverPhoto
{
/**
* File
*/
public $file;
public ?File $file = NULL;
/**
* Offset
*/
public $offset = 0;
public int $offset = 0;
/**
* Editable
*/
public $editable = FALSE;
public bool $editable = FALSE;
/**
* Maximum file size
*/
public $maxSize = NULL;
public ?int $maxSize = NULL;
/**
* Overlay
*/
public $overlay;
public ?string $overlay = null;
/**
* Object
*/
public $object;
public ?object $object;
/**
* Constructor
*
* @param \IPS\File|NULL $file The file
* @param int $offset The offset
* @param bool $editable User can edit?
* @param File|NULL $file The file
* @param int $offset The offset
* @param bool $editable User can edit?
*/
public function __construct( \IPS\File $file = NULL, $offset = 0, $editable = FALSE )
public function __construct( File $file = NULL, int $offset = 0, bool $editable=FALSE )
{
$this->file = $file;
$this->offset = $offset;
@@ -72,12 +79,12 @@ class _CoverPhoto
*/
public function __toString()
{
if( !\IPS\Request::i()->isAjax() )
if( !Request::i()->isAjax() )
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_core.js', 'core' ) );
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'front_core.js', 'core' ) );
}
return \IPS\Theme::i()->getTemplate( 'global', 'core' )->coverPhoto( $this->object->url(), $this );
return Theme::i()->getTemplate( 'global', 'core' )->coverPhoto( $this->object->url(), $this );
}
/**
@@ -85,7 +92,7 @@ class _CoverPhoto
*
* @return void
*/
public function delete()
public function delete() : void
{
if ( $this->file )
{