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

@@ -12,56 +12,78 @@
namespace IPS\cms\extensions\core\FrontNavigation;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\cms\Categories;
use IPS\cms\Databases\Dispatcher;
use IPS\cms\Pages\Page;
use IPS\core\FrontNavigation\FrontNavigationAbstract;
use IPS\Db;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Form\Select;
use IPS\Helpers\Form\Translatable;
use IPS\Http\Url;
use IPS\Lang;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use OutOfBoundsException;
use OutOfRangeException;
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;
}
/**
* Front Navigation Extension: Pages
*/
class _Pages extends \IPS\core\FrontNavigation\FrontNavigationAbstract
class Pages extends FrontNavigationAbstract
{
/**
* @var string Default icon
*/
public string $defaultIcon = '\f15c';
/**
* Get Type Title which will display in the AdminCP Menu Manager
*
* @return string
*/
public static function typeTitle()
public static function typeTitle(): string
{
return \IPS\Member::loggedIn()->language()->addToStack('menu_content_page');
return Member::loggedIn()->language()->addToStack('menu_content_page');
}
/**
* Allow multiple instances?
*
* @return bool
* @return bool
*/
public static function allowMultiple()
public static function allowMultiple(): bool
{
return TRUE;
}
/**
* Get configuration fields
*
* @param array $existingConfiguration The existing configuration, if editing an existing item
* @param int $id The ID number of the existing item, if editing
* @return array
* @param array $existingConfiguration The existing configuration, if editing an existing item
* @param int|null $id The ID number of the existing item, if editing
* @return array
*/
public static function configuration( $existingConfiguration, $id = NULL )
public static function configuration(array $existingConfiguration, ?int $id = NULL ): array
{
$pages = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'cms_pages' ), 'IPS\cms\Pages\Page' ) as $page )
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'cms_pages' ), 'IPS\cms\Pages\Page' ) as $page )
{
$pages[ $page->id ] = $page->full_path;
}
return array(
new \IPS\Helpers\Form\Select( 'menu_content_page', isset( $existingConfiguration['menu_content_page'] ) ? $existingConfiguration['menu_content_page'] : NULL, NULL, array( 'options' => $pages ), NULL, NULL, NULL, 'menu_content_page' ),
new \IPS\Helpers\Form\Radio( 'menu_title_page_type', isset( $existingConfiguration['menu_title_page_type'] ) ? $existingConfiguration['menu_title_page_type'] : 0, NULL, array( 'options' => array( 0 => 'menu_title_page_inherit', 1 => 'menu_title_page_custom' ), 'toggles' => array( 1 => array( 'menu_title_page' ) ) ), NULL, NULL, NULL, 'menu_title_page_type' ),
new \IPS\Helpers\Form\Translatable( 'menu_title_page', NULL, NULL, array( 'app' => 'cms', 'key' => $id ? "cms_menu_title_{$id}" : NULL ), NULL, NULL, NULL, 'menu_title_page' ),
new Select( 'menu_content_page', $existingConfiguration['menu_content_page'] ?? NULL, NULL, array( 'options' => $pages ), NULL, NULL, NULL, 'menu_content_page' ),
new Radio( 'menu_title_page_type', $existingConfiguration['menu_title_page_type'] ?? 0, NULL, array( 'options' => array( 0 => 'menu_title_page_inherit', 1 => 'menu_title_page_custom' ), 'toggles' => array( 1 => array( 'menu_title_page' ) ) ), NULL, NULL, NULL, 'menu_title_page_type' ),
new Translatable( 'menu_title_page', NULL, NULL, array( 'app' => 'cms', 'key' => $id ? "cms_menu_title_{$id}" : NULL ), NULL, NULL, NULL, 'menu_title_page' ),
);
}
@@ -70,17 +92,17 @@ class _Pages extends \IPS\core\FrontNavigation\FrontNavigationAbstract
*
* @param array $configuration The values received from the form
* @param int $id The ID number of the existing item, if editing
* @return array
* @return array
*/
public static function parseConfiguration( $configuration, $id )
public static function parseConfiguration( array $configuration, int $id ): array
{
if ( $configuration['menu_title_page_type'] )
{
\IPS\Lang::saveCustom( 'cms', "cms_menu_title_{$id}", $configuration['menu_title_page'] );
Lang::saveCustom( 'cms', "cms_menu_title_{$id}", $configuration['menu_title_page'] );
}
else
{
\IPS\Lang::deleteCustom( 'cms', "cms_menu_title_{$id}" );
Lang::deleteCustom( 'cms', "cms_menu_title_{$id}" );
}
unset( $configuration['menu_title_page'] );
@@ -91,28 +113,28 @@ class _Pages extends \IPS\core\FrontNavigation\FrontNavigationAbstract
/**
* Can access?
*
* @return bool
* @return bool
*/
public function canView()
public function canView(): bool
{
if ( $this->permissions )
{
if ( $this->permissions != '*' )
{
return \IPS\Member::loggedIn()->inGroup( explode( ',', $this->permissions ) );
return Member::loggedIn()->inGroup( explode( ',', $this->permissions ) );
}
return TRUE;
}
/* Inherit from page */
$store = \IPS\cms\Pages\Page::getStore();
$store = Page::getStore();
if ( isset( $store[ $this->configuration['menu_content_page'] ] ) )
{
if ( $store[ $this->configuration['menu_content_page'] ]['perm'] != '*' )
{
return \IPS\Member::loggedIn()->inGroup( explode( ',', $store[ $this->configuration['menu_content_page'] ]['perm'] ) );
return Member::loggedIn()->inGroup( explode( ',', $store[ $this->configuration['menu_content_page'] ]['perm'] ) );
}
return TRUE;
@@ -124,17 +146,17 @@ class _Pages extends \IPS\core\FrontNavigation\FrontNavigationAbstract
/**
* Get Title
*
* @return string
* @return string
*/
public function title()
public function title(): string
{
if ( $this->configuration['menu_title_page_type'] )
{
return \IPS\Member::loggedIn()->language()->addToStack( "cms_menu_title_{$this->id}" );
return Member::loggedIn()->language()->addToStack( "cms_menu_title_{$this->id}" );
}
else
{
$page = \IPS\cms\Pages\Page::load( $this->configuration['menu_content_page'] );
$page = Page::load( $this->configuration['menu_content_page'] );
if( $database = $page->getDatabase() and $database->pageTitle() )
{
@@ -142,7 +164,7 @@ class _Pages extends \IPS\core\FrontNavigation\FrontNavigationAbstract
}
else
{
return \IPS\Member::loggedIn()->language()->addToStack( "cms_page_{$this->configuration['menu_content_page']}" );
return Member::loggedIn()->language()->addToStack( "cms_page_{$this->configuration['menu_content_page']}" );
}
}
}
@@ -150,29 +172,29 @@ class _Pages extends \IPS\core\FrontNavigation\FrontNavigationAbstract
/**
* Get Link
*
* @return \IPS\Http\Url
* @return string|Url|null
*/
public function link()
public function link(): Url|string|null
{
$store = \IPS\cms\Pages\Page::getStore();
$store = Page::getStore();
if ( isset( $store[ $this->configuration['menu_content_page'] ] ) )
{
return $store[ $this->configuration['menu_content_page'] ]['url'];
return Url::external( $store[ $this->configuration['menu_content_page'] ]['url'] );
}
/* Fall back here */
return \IPS\cms\Pages\Page::load( $this->configuration['menu_content_page'] )->url();
return Page::load( $this->configuration['menu_content_page'] )->url();
}
/**
* Is Active?
*
* @return bool
* @return bool
*/
public function active()
public function active(): bool
{
$page = \IPS\cms\Pages\Page::$currentPage;
$page = Page::$currentPage;
if ( !$page )
{
return false;
@@ -180,24 +202,14 @@ class _Pages extends \IPS\core\FrontNavigation\FrontNavigationAbstract
try
{
if ( $db = $page->getDatabase() and $db->allow_club_categories and $categoryClass = '\\IPS\\cms\\Categories' . $db->id and \IPS\cms\Databases\Dispatcher::i()->categoryId and $categoryClass::load( \IPS\cms\Databases\Dispatcher::i()->categoryId )->club() )
/* @var $categoryClass Categories */
if ( $db = $page->getDatabase() and $db->allow_club_categories and $categoryClass = '\\IPS\\cms\\Categories' . $db->id and Dispatcher::i()->categoryId and $categoryClass::load( Dispatcher::i()->categoryId )->club() )
{
return false;
}
}
catch ( \OutOfRangeException|\OutOfBoundsException ) {}
catch ( OutOfRangeException|OutOfBoundsException ) {}
return $page->id == $this->configuration['menu_content_page'];
}
/**
* Children
*
* @param bool $noStore If true, will skip datastore and get from DB (used for ACP preview)
* @return array
*/
public function children( $noStore=FALSE )
{
return array();
}
}