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

+103 -60
View File
@@ -12,73 +12,96 @@
namespace IPS\blog;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use BadMethodCallException;
use IPS\Content\Item;
use IPS\Content\ViewUpdates;
use IPS\Db;
use IPS\File;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Node;
use IPS\Helpers\Form\Translatable;
use IPS\Http\Url;
use IPS\Http\Url\Friendly;
use IPS\IPS;
use IPS\Lang;
use IPS\Member;
use IPS\Node\Model;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Request;
use IPS\Theme;
use function count;
use function defined;
use function get_called_class;
use function get_class;
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;
}
/**
* Blog Category
*/
class _Category extends \IPS\Node\Model
class Category extends Model
{
use \IPS\Content\ViewUpdates;
use ViewUpdates;
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'blog_categories';
public static ?string $databaseTable = 'blog_categories';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'category_';
public static string $databasePrefix = 'category_';
/**
* @brief [Node] Parent ID Database Column
*/
public static $databaseColumnParent = 'parent';
public static ?string $databaseColumnParent = 'parent';
/**
* @brief [Node] Order Database Column
*/
public static $databaseColumnOrder = 'position';
public static ?string $databaseColumnOrder = 'position';
/**
* @brief [Node] Node Title
*/
public static $nodeTitle = 'blog_categories';
public static string $nodeTitle = 'blog_categories';
/**
* @brief [Node] Subnode class
*/
public static $subnodeClass = 'IPS\blog\Blog';
public static ?string $subnodeClass = 'IPS\blog\Blog';
/**
* @brief Content Item Class
*/
public static $contentItemClass = 'IPS\blog\Entry';
public static ?string $contentItemClass = 'IPS\blog\Entry';
/**
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
*/
public static $titleLangPrefix = 'blog_category_';
public static ?string $titleLangPrefix = 'blog_category_';
/**
* @brief [Node] Description suffix. If specified, will look for a language key with "{$titleLangPrefix}_{$id}_{$descriptionLangSuffix}" as the key
*/
public static $descriptionLangSuffix = '_desc';
public static ?string $descriptionLangSuffix = '_desc';
/**
* @brief SEO Title Column
*/
public static $seoTitleColumn = 'seo_name';
public static string $seoTitleColumn = 'seo_name';
/**
* @brief [Node] ACP Restrictions
@@ -96,7 +119,7 @@ class _Category extends \IPS\Node\Model
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
* @endcode
*/
protected static $restrictions = array(
protected static ?array $restrictions = array(
'app' => 'blog',
'module' => 'categories',
'prefix' => 'categories_',
@@ -105,21 +128,28 @@ class _Category extends \IPS\Node\Model
/**
* @brief The class of the ACP \IPS\Node\Controller that manages this node type
*/
protected static $acpController = "IPS\\blog\\modules\\admin\\blogs\\blogs";
protected static ?string $acpController = "IPS\\blog\\modules\\admin\\blogs\\blogs";
/**
* Determines if this class can be extended via UI Extension
*
* @var bool
*/
public static bool $canBeExtended = true;
/**
* [Node] Add/Edit Form
*
* @param \IPS\Helpers\Form $form The form
* @param Form $form The form
* @return void
*/
public function form( &$form )
public function form( Form &$form ) : void
{
$form->addHeader('category_basic_settings');
$form->add( new \IPS\Helpers\Form\Translatable( 'category_name', NULL, TRUE, array( 'app' => 'blog', 'key' => $this->id ? "blog_category_{$this->id}" : NULL ) ) );
$form->add( new Translatable( 'category_name', NULL, TRUE, array( 'app' => 'blog', 'key' => $this->id ? "blog_category_{$this->id}" : NULL ) ) );
\IPS\Member::loggedIn()->language()->words['category_desc'] = \IPS\Member::loggedIn()->language()->addToStack('blog_category_desc');
$form->add( new \IPS\Helpers\Form\Translatable( 'category_desc', NULL, FALSE, array(
Member::loggedIn()->language()->words['category_desc'] = Member::loggedIn()->language()->addToStack('blog_category_desc');
$form->add( new Translatable( 'category_desc', NULL, FALSE, array(
'app' => 'blog',
'key' => ( $this->id ? "blog_category_{$this->id}_desc" : NULL ),
'editor' => array(
@@ -130,17 +160,19 @@ class _Category extends \IPS\Node\Model
)
) ) );
$class = \get_called_class();
$class = get_called_class();
$form->add( new \IPS\Helpers\Form\Node( 'category_parent', $this->id ? $this->parent : 0, TRUE, array('disableCopy' => true,'class' => 'IPS\blog\Category', 'subnodes' => FALSE, 'zeroVal' => 'no_parent', 'permissionCheck' => function( $node ) use ( $class )
$form->add( new Node( 'category_parent', $this->id ? $this->parent : 0, TRUE, array( 'class' => 'IPS\blog\Category', 'subnodes' => FALSE, 'zeroVal' => 'no_parent', 'permissionCheck' => function( $node ) use ( $class )
{
if( isset( $class::$subnodeClass ) AND $class::$subnodeClass AND $node instanceof $class::$subnodeClass )
{
return FALSE;
}
return !isset( \IPS\Request::i()->id ) or ( $node->id != \IPS\Request::i()->id and !$node->isChildOf( $node::load( \IPS\Request::i()->id ) ) );
return !isset( Request::i()->id ) or ( $node->id != Request::i()->id and !$node->isChildOf( $node::load( Request::i()->id ) ) );
} ) ) );
parent::form( $form );
}
/**
@@ -149,7 +181,7 @@ class _Category extends \IPS\Node\Model
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
public function formatFormValues( array $values ): array
{
if( isset( $values['category_parent'] ) )
{
@@ -159,7 +191,7 @@ class _Category extends \IPS\Node\Model
if ( !$this->id )
{
$this->save();
\IPS\File::claimAttachments( 'blog-new-category', $this->id, NULL, 'bcategory', TRUE );
File::claimAttachments( 'blog-new-category', $this->id, NULL, 'bcategory', TRUE );
}
elseif( isset( $values['category_name'] ) OR isset( $values['category_desc'] ) )
{
@@ -168,15 +200,15 @@ class _Category extends \IPS\Node\Model
if( isset( $values['category_name'] ) )
{
\IPS\Lang::saveCustom( 'blog', "blog_category_{$this->id}", $values['category_name'] );
$values['seo_name'] = \IPS\Http\Url\Friendly::seoTitle( $values['category_name'][ \IPS\Lang::defaultLanguage() ] );
Lang::saveCustom( 'blog', "blog_category_{$this->id}", $values['category_name'] );
$values['seo_name'] = Friendly::seoTitle( $values['category_name'][ Lang::defaultLanguage() ] );
unset( $values['category_name'] );
}
if( isset( $values['category_desc'] ) )
{
\IPS\Lang::saveCustom( 'blog', "blog_category_{$this->id}_desc", $values['category_desc'] );
Lang::saveCustom( 'blog', "blog_category_{$this->id}_desc", $values['category_desc'] );
unset( $values['category_desc'] );
}
@@ -187,19 +219,19 @@ class _Category extends \IPS\Node\Model
/**
* @brief Cached URL
*/
protected $_url = NULL;
protected mixed $_url = NULL;
/**
* Get URL
*
* @return \IPS\Http\Url
* @return Url|string|null
*/
public function url()
public function url(): Url|string|null
{
if( $this->_url === NULL )
{
$seoTitleColumn = static::$seoTitleColumn;
$this->_url = \IPS\Http\Url::internal( "app=blog&module=blogs&controller=browse&id={$this->id}", 'front', 'blog_category', $this->$seoTitleColumn );
$this->_url = Url::internal( "app=blog&module=blogs&controller=browse&id={$this->id}", 'front', 'blog_category', $this->$seoTitleColumn ? $this->$seoTitleColumn : '-' );
}
return $this->_url;
@@ -210,9 +242,9 @@ class _Category extends \IPS\Node\Model
*
* @return string
*/
public function link()
public function link(): string
{
return \IPS\Theme::i()->getTemplate( 'global', 'blog' )->blogCategoryLink( $this );
return Theme::i()->getTemplate( 'global', 'blog' )->blogCategoryLink( $this );
}
/**
@@ -221,33 +253,43 @@ class _Category extends \IPS\Node\Model
* @param array $indexData Data from the search index
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
* @return \IPS\Http\Url
* @return Url
*/
public static function urlFromIndexData( $indexData, $itemData, $containerData )
public static function urlFromIndexData( array $indexData, array $itemData, ?array $containerData ): Url
{
return \IPS\Http\Url::internal( "app=blog&module=blogs&controller=browse&category={$indexData['index_container_id']}", 'front', 'blog_category', \IPS\Member::loggedIn()->language()->addToStack( 'blog_category_' . $indexData['index_container_id'], FALSE, array( 'seotitle' => TRUE ) ) );
return Url::internal( "app=blog&module=blogs&controller=browse&category={$indexData['index_container_id']}", 'front', 'blog_category', Member::loggedIn()->language()->addToStack( 'blog_category_' . $indexData['index_container_id'], FALSE, array( 'seotitle' => TRUE ) ) );
}
/**
* [Node] Get Node Icon
*
* @return string|null
*/
protected function get__icon(): string|null
{
return ( $this->parent > 0 ) ? 'caret-down' : NULL ;
}
/**
* Get output for API
*
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
* @param Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
* @return array
* @apiresponse int id ID number
* @apiresponse string name Name
* @apiresponse string url URL
* @apiresponse string class Node class
*/
public function apiOutput( \IPS\Member $authorizedMember = NULL )
public function apiOutput( Member $authorizedMember = NULL ): array
{
$return = array(
'id' => $this->id,
'name' => $this->_title,
'url' => (string) $this->url(),
'class' => \get_class( $this ),
'class' => get_class( $this ),
);
if ( \IPS\IPS::classUsesTrait( \get_called_class(), 'IPS\Content\ClubContainer' ) AND $this->club() )
if ( IPS::classUsesTrait( get_called_class(), 'IPS\Content\ClubContainer' ) AND $this->club() )
{
$return['public'] = ( $this->isPublic() ) ? 1 : 0;
}
@@ -258,16 +300,17 @@ class _Category extends \IPS\Node\Model
/**
* Retrieve the content item count
*
* @param null|array $data Data array for mass move/delete
* @param array|null $data Data array for mass move/delete
* @return null|int
*/
public function getContentItemCount( $data=NULL )
public function getContentItemCount( array $data=NULL ): ?int
{
if ( !isset( static::$contentItemClass ) )
{
return false;
return null;
}
/* @var Item $contentItemClass */
$contentItemClass = static::$contentItemClass;
$idColumn = static::$databaseColumnId;
@@ -279,7 +322,7 @@ class _Category extends \IPS\Node\Model
$where = array_merge_recursive( $where, $this->massMoveorDeleteWhere( $data ) );
}
$select = \IPS\Db::i()->select( 'COUNT(*)', $contentItemClass::$databaseTable, $where )->join( 'blog_blogs', "blog_entries.entry_blog_id=blog_blogs.blog_id" );
$select = Db::i()->select( 'COUNT(*)', $contentItemClass::$databaseTable, $where )->join( 'blog_blogs', "blog_entries.entry_blog_id=blog_blogs.blog_id" );
return (int) $select->first();
}
@@ -287,26 +330,27 @@ class _Category extends \IPS\Node\Model
/**
* Retrieve content items (if applicable) for a node.
*
* @param int $limit The limit
* @param int $offset The offset
* @param array $additional Where Additional where clauses
* @param int $countOnly If TRUE, will get the number of results
* @return \IPS\Patterns\ActiveRecordIterator|int
* @throws \BadMethodCallException
* @param int|null $limit The limit
* @param int|null $offset The offset
* @param array $additionalWhere Where Additional where clauses
* @param bool|int $countOnly If TRUE, will get the number of results
* @return ActiveRecordIterator|int
* @throws BadMethodCallException
*/
public function getContentItems( $limit, $offset, $additionalWhere = array(), $countOnly=FALSE )
public function getContentItems( ?int $limit, ?int $offset, array $additionalWhere = array(), bool|int $countOnly=FALSE ): ActiveRecordIterator|int
{
if ( !isset( static::$contentItemClass ) )
{
throw new \BadMethodCallException;
throw new BadMethodCallException;
}
/* @var Item $contentItemClass */
$contentItemClass = static::$contentItemClass;
$where = array();
$where[] = array( 'blog_blogs.blog_category_id=?', $this->_id );
if ( \count( $additionalWhere ) )
if ( count( $additionalWhere ) )
{
foreach( $additionalWhere AS $clause )
{
@@ -316,13 +360,12 @@ class _Category extends \IPS\Node\Model
if ( $countOnly )
{
return \IPS\Db::i()->select( 'COUNT(*)', $contentItemClass::$databaseTable, $where )->join( 'blog_blogs', "blog_entries.entry_blog_id=blog_blogs.blog_id" )->first();
return Db::i()->select( 'COUNT(*)', $contentItemClass::$databaseTable, $where )->join( 'blog_blogs', "blog_entries.entry_blog_id=blog_blogs.blog_id" )->first();
}
else
{
$contentItemClass = static::$contentItemClass;
$limit = ( $offset !== NULL ) ? array( $offset, $limit ) : NULL;
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', $contentItemClass::$databaseTable, $where, $contentItemClass::$databasePrefix . $contentItemClass::$databaseColumnId, $limit )->join( 'blog_blogs', "blog_entries.entry_blog_id=blog_blogs.blog_id" ), $contentItemClass );
return new ActiveRecordIterator( Db::i()->select( '*', $contentItemClass::$databaseTable, $where, $contentItemClass::$databasePrefix . $contentItemClass::$databaseColumnId, $limit )->join( 'blog_blogs', "blog_entries.entry_blog_id=blog_blogs.blog_id" ), $contentItemClass );
}
}
}