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,26 +12,47 @@
|
||||
namespace IPS\cms\Pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function func_get_args;
|
||||
use function get_called_class;
|
||||
use function get_class;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Folder Model
|
||||
*/
|
||||
class _Folder extends \IPS\Node\Model
|
||||
class Folder extends Model
|
||||
{
|
||||
/**
|
||||
* Munge different record types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function munge()
|
||||
public static function munge() : array
|
||||
{
|
||||
$rows = array();
|
||||
$args = \func_get_args();
|
||||
$args = func_get_args();
|
||||
|
||||
foreach( $args as $arg )
|
||||
{
|
||||
@@ -49,73 +70,73 @@ class _Folder extends \IPS\Node\Model
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'cms_folders';
|
||||
public static ?string $databaseTable = 'cms_folders';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'folder_';
|
||||
public static string $databasePrefix = 'folder_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array('folder_name', 'folder_path');
|
||||
protected static array $databaseIdFields = array('folder_name', 'folder_path');
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
protected static array $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent ID Database Column
|
||||
*/
|
||||
public static $databaseColumnParent = 'parent_id';
|
||||
public static ?string $databaseColumnParent = 'parent_id';
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent ID Root Value
|
||||
* @note This normally doesn't need changing though some legacy areas use -1 to indicate a root node
|
||||
*/
|
||||
public static $databaseColumnParentRootValue = 0;
|
||||
public static int $databaseColumnParentRootValue = 0;
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'path';
|
||||
public static ?string $databaseColumnOrder = 'path';
|
||||
|
||||
/**
|
||||
* @brief [Node] Automatically set position for new nodes
|
||||
*/
|
||||
public static $automaticPositionDetermination = FALSE;
|
||||
public static bool $automaticPositionDetermination = FALSE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'folder';
|
||||
public static string $nodeTitle = 'folder';
|
||||
|
||||
/**
|
||||
* @brief [Node] Subnode class
|
||||
*/
|
||||
public static $subnodeClass = 'IPS\cms\Pages\Page';
|
||||
public static ?string $subnodeClass = 'IPS\cms\Pages\Page';
|
||||
|
||||
/**
|
||||
* @brief [Node] Show forms modally?
|
||||
*/
|
||||
public static $modalForms = TRUE;
|
||||
public static bool $modalForms = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Restrictions
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
protected static ?array $restrictions = array(
|
||||
'app' => 'cms',
|
||||
'module' => 'pages',
|
||||
'all' => 'page_manage',
|
||||
@@ -125,9 +146,9 @@ class _Folder extends \IPS\Node\Model
|
||||
/**
|
||||
* [Node] Get Title
|
||||
*
|
||||
* @return string|null
|
||||
* @return string
|
||||
*/
|
||||
protected function get__title()
|
||||
protected function get__title(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
@@ -137,7 +158,7 @@ class _Folder extends \IPS\Node\Model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSortableName()
|
||||
public function getSortableName() : string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
@@ -145,11 +166,11 @@ class _Folder extends \IPS\Node\Model
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
*
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
* @param Url $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
*/
|
||||
public function getButtons( $url, $subnode=FALSE )
|
||||
public function getButtons( Url $url, bool $subnode=FALSE ): array
|
||||
{
|
||||
$buttons = parent::getButtons( $url, $subnode );
|
||||
$return = array();
|
||||
@@ -163,14 +184,13 @@ class _Folder extends \IPS\Node\Model
|
||||
{
|
||||
$buttons['add']['icon'] = 'folder-open';
|
||||
$buttons['add']['title'] = 'content_add_folder';
|
||||
$buttons['add']['data'] = array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_folder') );
|
||||
$buttons['add']['data'] = array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('content_add_folder') );
|
||||
$buttons['add']['link'] = $url->setQueryString( array( 'subnode' => 0, 'do' => 'form', 'parent' => $this->_id ) );
|
||||
|
||||
$buttons['add_page'] = array(
|
||||
'icon' => 'plus-circle',
|
||||
'title' => 'content_add_page',
|
||||
'link' => $url->setQueryString( array( 'subnode' => 1, 'do' => 'add', 'parent' => $this->_id ) ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_page') )
|
||||
'link' => $url->setQueryString( array( 'subnode' => 1, 'do' => 'form', 'parent' => $this->_id ) )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -195,10 +215,10 @@ class _Folder extends \IPS\Node\Model
|
||||
if ( $this->getItemCount() )
|
||||
{
|
||||
$return['delete'] = array(
|
||||
'icon' => 'trash-o',
|
||||
'icon' => 'trash',
|
||||
'title' => 'empty',
|
||||
'link' => $url->setQueryString( array( 'do' => 'delete', 'id' => $this->_id ) ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('empty') ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('empty') ),
|
||||
'hotkey'=> 'd'
|
||||
);
|
||||
}
|
||||
@@ -214,52 +234,52 @@ class _Folder extends \IPS\Node\Model
|
||||
/**
|
||||
* [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
|
||||
{
|
||||
/* Build form */
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'folder_name', $this->id ? $this->name : '', TRUE, array( 'maxLength' => 64 ), function( $val )
|
||||
$form->add( new Text( 'folder_name', $this->id ? $this->name : '', TRUE, array( 'maxLength' => 64 ), function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
$testPage = \IPS\cms\Pages\Page::load( $val, 'page_seo_name' );
|
||||
$testPage = Page::load( $val, 'page_seo_name' );
|
||||
|
||||
/* Ok, we have a folder, but is it on the same tree as us ?*/
|
||||
if ( \intval( \IPS\Request::i()->folder_parent_id ) == $testPage->folder_id )
|
||||
if ( intval( Request::i()->folder_parent_id ) == $testPage->folder_id )
|
||||
{
|
||||
/* Yep, this will break designers' mode and may confuse the FURL engine so we cannot allow this */
|
||||
throw new \InvalidArgumentException('content_folder_name_furl_collision_folder');
|
||||
throw new InvalidArgumentException('content_folder_name_furl_collision_folder');
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
/* Nothing with the same name, so that's proper good that is */
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$test = \IPS\cms\Pages\Folder::load( ( $val === '.well-known' ) ? $val : \IPS\Http\Url\Friendly::seoTitle( $val ), 'folder_name' );
|
||||
$test = Folder::load( ( $val === '.well-known' ) ? $val : Friendly::seoTitle( $val ), 'folder_name' );
|
||||
|
||||
if ( empty( \IPS\Request::i()->id ) or $test->id != \IPS\Request::i()->id )
|
||||
if ( empty( Request::i()->id ) or $test->id != Request::i()->id )
|
||||
{
|
||||
throw new \InvalidArgumentException('content_folder_name_in_use');
|
||||
throw new InvalidArgumentException('content_folder_name_in_use');
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
/* If we hit here, we don't have an existing folder by that name so check for a collision */
|
||||
if ( \IPS\Request::i()->folder_parent_id == 0 AND \IPS\cms\Pages\Page::isFurlCollision( ( $val === '.well-known' ) ? $val : \IPS\Http\Url\Friendly::seoTitle( $val ) ) )
|
||||
if ( Request::i()->folder_parent_id == 0 AND Page::isFurlCollision( ( $val === '.well-known' ) ? $val : Friendly::seoTitle( $val ) ) )
|
||||
{
|
||||
throw new \InvalidArgumentException('content_folder_name_furl_collision');
|
||||
throw new InvalidArgumentException('content_folder_name_furl_collision');
|
||||
}
|
||||
}
|
||||
} ) );
|
||||
|
||||
$class = \get_called_class();
|
||||
$class = get_called_class();
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'folder_parent_id', $this->parent_id ? $this->parent_id : 0, FALSE, array(
|
||||
$form->add( new Node( 'folder_parent_id', $this->parent_id ? $this->parent_id : 0, FALSE, array(
|
||||
'class' => '\IPS\cms\Pages\Folder',
|
||||
'zeroVal' => 'node_no_parent',
|
||||
'permissionCheck' => function( $node ) use ( $class )
|
||||
@@ -269,7 +289,7 @@ class _Folder extends \IPS\Node\Model
|
||||
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 ) ) );
|
||||
}
|
||||
) ) );
|
||||
}
|
||||
@@ -280,7 +300,7 @@ class _Folder extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
$isNew = $this->_new;
|
||||
|
||||
@@ -307,7 +327,7 @@ class _Folder extends \IPS\Node\Model
|
||||
}
|
||||
else
|
||||
{
|
||||
$values['name'] = \IPS\Http\Url\Friendly::seoTitle( $values['folder_name'] );
|
||||
$values['name'] = Friendly::seoTitle( $values['folder_name'] );
|
||||
}
|
||||
unset( $values['folder_name'] );
|
||||
}
|
||||
@@ -323,12 +343,12 @@ class _Folder extends \IPS\Node\Model
|
||||
/**
|
||||
* @brief Original parent ID
|
||||
*/
|
||||
protected $origParentId;
|
||||
protected ?int $origParentId = null;
|
||||
|
||||
/**
|
||||
* @brief Original Name
|
||||
*/
|
||||
protected $origName;
|
||||
protected ?string $origName = null;
|
||||
|
||||
/**
|
||||
* [Node] Perform actions after saving the form
|
||||
@@ -336,7 +356,7 @@ class _Folder extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return void
|
||||
*/
|
||||
public function postSaveForm( $values )
|
||||
public function postSaveForm( array $values ) : void
|
||||
{
|
||||
if ( $this->origParentId !== $values['parent_id'] OR $this->origName !== $values['name'] )
|
||||
{
|
||||
@@ -349,9 +369,9 @@ class _Folder extends \IPS\Node\Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function storeUrl()
|
||||
public function storeUrl() : void
|
||||
{
|
||||
\IPS\Db::i()->insert( 'cms_url_store', array(
|
||||
Db::i()->insert( 'cms_url_store', array(
|
||||
'store_path' => $this->path,
|
||||
'store_current_id' => $this->_id,
|
||||
'store_type' => 'folder'
|
||||
@@ -363,7 +383,7 @@ class _Folder extends \IPS\Node\Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
$this->last_modified = time();
|
||||
|
||||
@@ -373,12 +393,12 @@ class _Folder extends \IPS\Node\Model
|
||||
/**
|
||||
* Retrieve item \count(if applicable) for a node.
|
||||
*
|
||||
* @return int|bool
|
||||
* @return int
|
||||
*/
|
||||
public function getItemCount()
|
||||
public function getItemCount() : int
|
||||
{
|
||||
$pages = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_pages', array( 'page_folder_id=?', $this->id ) )->first();
|
||||
$subFolders = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_folders', array( 'folder_parent_id=?', $this->id ) )->first();
|
||||
$pages = (int) Db::i()->select( 'COUNT(*)', 'cms_pages', array( 'page_folder_id=?', $this->id ) )->first();
|
||||
$subFolders = (int) Db::i()->select( 'COUNT(*)', 'cms_folders', array( 'folder_parent_id=?', $this->id ) )->first();
|
||||
|
||||
return $pages + $subFolders;
|
||||
}
|
||||
@@ -387,19 +407,19 @@ class _Folder extends \IPS\Node\Model
|
||||
* Form to delete or move content
|
||||
*
|
||||
* @param bool $showMoveToChildren If TRUE, will show "move to children" even if there are no children
|
||||
* @return \IPS\Helpers\Form
|
||||
* @return Form
|
||||
*/
|
||||
public function deleteOrMoveForm( $showMoveToChildren=FALSE )
|
||||
public function deleteOrMoveForm( bool $showMoveToChildren=FALSE ): Form
|
||||
{
|
||||
$hasContent = $this->getItemCount();
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'form', 'delete' );
|
||||
$form = new Form( 'form', 'delete' );
|
||||
|
||||
if ( $hasContent )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'cms_move_pages', 0, TRUE, array( 'class' => \get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'cms_move_to_root', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
|
||||
$form->add( new Node( 'cms_move_pages', 0, TRUE, array( 'class' => get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'cms_move_to_root', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
|
||||
{
|
||||
return \IPS\Request::i()->id != $node->id;
|
||||
return Request::i()->id != $node->id;
|
||||
} ) ) );
|
||||
}
|
||||
|
||||
@@ -412,7 +432,7 @@ class _Folder extends \IPS\Node\Model
|
||||
* @param array $values Values from form
|
||||
* @return void
|
||||
*/
|
||||
public function deleteOrMoveFormSubmit( $values )
|
||||
public function deleteOrMoveFormSubmit( array $values ) : void
|
||||
{
|
||||
if ( $values['cms_move_pages'] )
|
||||
{
|
||||
@@ -423,17 +443,17 @@ class _Folder extends \IPS\Node\Model
|
||||
$folderId = 0;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'cms_pages', array( 'page_folder_id' => $folderId ), array( 'page_folder_id=?', $this->_id ) );
|
||||
\IPS\Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $folderId ), array( 'folder_id=?', $this->_id ) );
|
||||
\IPS\Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $folderId ), array( 'folder_parent_id=?', $this->_id ) );
|
||||
Db::i()->update( 'cms_pages', array( 'page_folder_id' => $folderId ), array( 'page_folder_id=?', $this->_id ) );
|
||||
Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $folderId ), array( 'folder_id=?', $this->_id ) );
|
||||
Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $folderId ), array( 'folder_parent_id=?', $this->_id ) );
|
||||
|
||||
unset( \IPS\Data\Store::i()->pages_page_urls );
|
||||
unset( Store::i()->pages_page_urls );
|
||||
|
||||
/* Update pages */
|
||||
\IPS\cms\Pages\Page::resetPath( $folderId );
|
||||
Page::resetPath( $folderId );
|
||||
|
||||
/* Delete it */
|
||||
\IPS\Session::i()->log( 'acplog__node_deleted', array( $this->title => TRUE, $this->titleForLog() => FALSE ) );
|
||||
Session::i()->log( 'acplog__node_deleted', array( $this->title => TRUE, $this->titleForLog() => FALSE ) );
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
@@ -443,7 +463,7 @@ class _Folder extends \IPS\Node\Model
|
||||
* @param boolean $recursivelyCheck Recursively reset up and down the tree
|
||||
* @return void
|
||||
*/
|
||||
public function resetPath( $recursivelyCheck=true )
|
||||
public function resetPath( bool $recursivelyCheck=true ) : void
|
||||
{
|
||||
$path = array();
|
||||
|
||||
@@ -452,13 +472,13 @@ class _Folder extends \IPS\Node\Model
|
||||
$path[] = $obj->name;
|
||||
}
|
||||
|
||||
$this->path = ( \count( $path ) ) ? implode( '/', $path ) . '/' . $this->name : $this->name;
|
||||
$this->path = ( count( $path ) ) ? implode( '/', $path ) . '/' . $this->name : $this->name;
|
||||
|
||||
/* Save path update */
|
||||
parent::save();
|
||||
|
||||
/* Update pages */
|
||||
\IPS\cms\Pages\Page::resetPath( $this->id );
|
||||
Page::resetPath( $this->id );
|
||||
|
||||
if ( $recursivelyCheck === true )
|
||||
{
|
||||
@@ -482,7 +502,7 @@ class _Folder extends \IPS\Node\Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _recursivelyResetChildPaths()
|
||||
protected function _recursivelyResetChildPaths() : void
|
||||
{
|
||||
foreach( $this->children( NULL, NULL, FALSE ) as $child )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user