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,77 +12,91 @@
|
||||
namespace IPS\cms\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Databases\Dispatcher;
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Member;
|
||||
use IPS\Request;
|
||||
use IPS\Widget;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function intval;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Database Widget
|
||||
*/
|
||||
class _Database extends \IPS\Widget
|
||||
class Database extends Widget
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'Database';
|
||||
public string $key = 'Database';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'cms';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
public string $app = 'cms';
|
||||
|
||||
/**
|
||||
* @brief HTML if widget is called more than once, we store it.
|
||||
*/
|
||||
protected static $html = NULL;
|
||||
protected static ?string $html = NULL;
|
||||
|
||||
/**
|
||||
* @brief Set to true if this widget must be the only one in its area
|
||||
*/
|
||||
public bool $soloWidget = true;
|
||||
|
||||
/**
|
||||
* Specify widget configuration
|
||||
*
|
||||
* @param \IPS\Helpers\Form|NULL $form Form helper
|
||||
* @return null|\IPS\Helpers\Form
|
||||
* @param Form|NULL $form Form helper
|
||||
* @return Form
|
||||
*/
|
||||
public function configuration( &$form=null )
|
||||
public function configuration( Form &$form=null ): Form
|
||||
{
|
||||
$form = parent::configuration( $form );
|
||||
|
||||
$databases = array();
|
||||
$disabled = array();
|
||||
|
||||
foreach( \IPS\cms\Databases::databases() as $db )
|
||||
foreach( Databases::databases() as $db )
|
||||
{
|
||||
$databases[ $db->id ] = $db->_title;
|
||||
|
||||
if ( $db->page_id and $db->page_id != \IPS\Request::i()->pageID )
|
||||
if ( $db->page_id and $db->page_id != Request::i()->pageID )
|
||||
{
|
||||
$disabled[] = $db->id;
|
||||
|
||||
try
|
||||
{
|
||||
$page = \IPS\cms\Pages\Page::load( $db->page_id );
|
||||
$databases[ $db->id ] = \IPS\Member::loggedIn()->language()->addToStack( 'cms_db_in_use_by_page', FALSE, array( 'sprintf' => array( $db->_title, $page->full_path ) ) );
|
||||
$page = Page::load( $db->page_id );
|
||||
$databases[ $db->id ] = Member::loggedIn()->language()->addToStack( 'cms_db_in_use_by_page', FALSE, array( 'sprintf' => array( $db->_title, $page->full_path ) ) );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
unset( $databases[ $db->id ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! \count( $databases ) )
|
||||
if ( ! count( $databases ) )
|
||||
{
|
||||
$form->addMessage('cms_err_no_databases_to_use');
|
||||
}
|
||||
else
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'database', ( isset( $this->configuration['database'] ) ? (int) $this->configuration['database'] : NULL ), FALSE, array( 'options' => $databases, 'disabled' => $disabled ) ) );
|
||||
$form->add( new Select( 'database', ( isset( $this->configuration['database'] ) ? (int) $this->configuration['database'] : NULL ), FALSE, array( 'options' => $databases, 'disabled' => $disabled ) ) );
|
||||
}
|
||||
|
||||
return $form;
|
||||
@@ -94,11 +108,11 @@ class _Database extends \IPS\Widget
|
||||
* @param array $values Form values
|
||||
* @return array
|
||||
*/
|
||||
public function preConfig( $values )
|
||||
public function preConfig( array $values ): array
|
||||
{
|
||||
if ( \IPS\Request::i()->pageID and $values['database'] )
|
||||
if ( Request::i()->pageID and $values['database'] )
|
||||
{
|
||||
\IPS\cms\Pages\Page::load( \IPS\Request::i()->pageID )->mapToDatabase( $values['database'] );
|
||||
Page::load( Request::i()->pageID )->mapToDatabase( $values['database'] );
|
||||
}
|
||||
|
||||
return $values;
|
||||
@@ -109,7 +123,7 @@ class _Database extends \IPS\Widget
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
if ( static::$html === NULL )
|
||||
{
|
||||
@@ -117,17 +131,17 @@ class _Database extends \IPS\Widget
|
||||
{
|
||||
try
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( \intval( $this->configuration['database'] ) );
|
||||
$database = Databases::load( intval( $this->configuration['database'] ) );
|
||||
|
||||
if ( ! $database->page_id and \IPS\cms\Pages\Page::$currentPage )
|
||||
if ( ! $database->page_id and Page::$currentPage )
|
||||
{
|
||||
$database->page_id = \IPS\cms\Pages\Page::$currentPage->id;
|
||||
$database->page_id = Page::$currentPage->id;
|
||||
$database->save();
|
||||
}
|
||||
|
||||
static::$html = \IPS\cms\Databases\Dispatcher::i()->setDatabase( $database->id )->run();
|
||||
static::$html = Dispatcher::i()->setDatabase( $database->id )->run();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
static::$html = '';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user