Version 5.0.13

This commit is contained in:
Neo committed 2025-12-19 19:04:57 -08:00
1 parent b89858b2ff
commit 5efe744c5f
1407 files changed
+69690 -30177

No files matched your search

@@ -41,6 +41,7 @@ use OutOfRangeException;
use function defined;
use function in_array;
use const IPS\Helpers\Table\SEARCH_NODE;
use const IPS\Helpers\Table\SEARCH_NUMERIC_TEXT;
use const IPS\Helpers\Table\SEARCH_SELECT;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
@@ -139,18 +140,13 @@ class records extends Controller
Member::loggedIn()->language()->words['content_db_table_field_' . $database->field_title ] = Member::loggedIn()->language()->addToStack( 'content_db_table_title' );
$table->advancedSearch = array(
'category_id' => array( SEARCH_NODE, array(
'category_id' => [SEARCH_NODE, [
'class' => '\IPS\cms\Categories' . $database->id,
'disabled' => false,
'zeroVal' => 'content_db_table_as_no_cat'
),
),
'record_comments'=> array( SEARCH_SELECT, array( 'options' => array(
'null' => 'content_db_table_as_comments_null',
1 => 'content_db_table_as_comments_yes',
2 => 'content_db_table_as_comments_no'
)
) ),
],
],
'record_comments'=> [SEARCH_NUMERIC_TEXT, [] ],
);
/* Buttons */
+171 -5
View File
@@ -14,16 +14,21 @@ namespace IPS\cms\modules\admin\pages;
/* To prevent PHP errors (extending class does not exist) revealing path */
use DomainException;
use IPS\cms\Pages\Folder;
use IPS\cms\Pages\Page;
use IPS\Data\Store;
use IPS\DateTime;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Helpers\Form;
use IPS\Helpers\Form\CheckboxSet;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Table\Db as TableDb;
use IPS\Helpers\Tree\Tree;
use IPS\Http\Url;
use IPS\Member;
use IPS\Member\Group;
use IPS\Node\Controller;
use IPS\Node\Model;
use IPS\Output;
@@ -36,6 +41,7 @@ use UnderflowException;
use function count;
use function defined;
use function strpos;
use const IPS\REBUILD_QUICK;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
@@ -260,7 +266,7 @@ FILE;
protected function form() : void
{
/* If this is a database page, redirect to database form */
if( isset( static::$pageToDatabaseMap[ Request::i()->id ] ) )
if( isset( static::$pageToDatabaseMap[ Request::i()->id ] ) and isset( Request::i()->subnode ) and Request::i()->subnode )
{
Output::i()->redirect( Url::internal( "app=cms&module=databases&controller=databases&do=form&id=" . static::$pageToDatabaseMap[ Request::i()->id ] ) );
}
@@ -317,9 +323,77 @@ FILE;
*/
protected function setAsDefault() : void
{
Session::i()->csrfCheck();
Page::load( Request::i()->id )->setAsDefault();
Output::i()->redirect( Url::internal( "app=cms&module=pages&controller=pages" ), 'saved' );
$page = Page::load( Request::i()->id );
$defaults = Page::loadDefaultsPerGroup()[ $page->folder_id ] ?? [];
$options = [];
$selected = [];
$descriptions = [];
foreach( Group::groups() as $group )
{
$options[ $group->g_id ] = $group->name;
if( isset( $defaults[ $group->g_id ] ) )
{
if( $defaults[ $group->g_id ] == $page->id )
{
$selected[] = $group->g_id;
}
else
{
$descriptions[ $group->g_id ] = Page::load( $defaults[ $group->g_id ] )->seo_name;
}
}
}
$form = new Form;
$form->addMessage( 'set_page_default_info', 'info' );
$form->add( new Form\YesNo( 'set_page_default', $page->default == Page::PAGE_DEFAULT, false, [
'togglesOff' => [ 'set_group_defaults' ]
] ) );
$form->add( new CheckboxSet( 'set_group_defaults', $selected, false, [
'options' => $options,
'descriptions' => $descriptions,
'noDefault' => true
], function( $val ) use ( $page, $defaults ) {
/* If this was the default page, make sure we don't leave any groups stranded! */
if( $page->default == Page::PAGE_DEFAULT )
{
foreach( $defaults as $groupId => $groupPage )
{
try
{
$group = Group::load( $groupId );
}
catch( OutOfRangeException )
{
continue;
}
if( $groupPage == $page->id and !in_array( $groupId, $val ) )
{
throw new DomainException( Member::loggedIn()->language()->addToStack( 'err__no_page_default', true, [ 'sprintf' => [ $group->name ] ] ) );
}
}
}
}, id: 'set_group_defaults' ) );
if( $values = $form->values() )
{
if( $values['set_page_default'] )
{
$page->setAsDefault();
}
else
{
$page->setAsDefaultForGroups( $values['set_group_defaults'] );
}
Session::i()->log( 'acplogs__cms_page_set_default', [ 'cms_page_' . $page->id => TRUE, $page->parent()?->_title ?? 'root' => FALSE ] );
Output::i()->redirect( Url::internal( "app=cms&module=pages&controller=pages" ), 'saved' );
}
Output::i()->output = (string) $form;
}
/**
@@ -334,6 +408,84 @@ FILE;
Output::i()->redirect( Url::internal( "app=cms&module=pages&controller=pages" ), 'saved' );
}
/**
* Show all page history
*
* @return void
*/
protected function history() : void
{
try
{
if( !isset( Request::i()->subnode ) or !Request::i()->subnode )
{
throw new OutOfRangeException;
}
$page = Page::load( Request::i()->id );
}
catch( OutOfRangeException )
{
Output::i()->error( 'node_error', '3T260/2', 404 );
}
$table = new TableDb( 'cms_page_revisions', $this->url->setQueryString( [ 'id' => $page->id, 'do' => 'history', 'subnode' => Request::i()->subnode ] ), [ [ 'revision_page_id=?', $page->id ] ] );
$table->joins[] = [ 'from' => 'core_members', 'where' => 'revision_member_id=member_id' ];
$table->sortBy = $table->sortBy ?: 'revision_date';
$table->sortDirection = $table->sortDirection ?: 'desc';
$table->include = [ 'revision_date', 'revision_member_id' ];
$table->noSort = [ 'revision_member_id' ];
/* Filters */
$table->filters = [
'revision_page_manual' => [ '( revision_manual_save=1 )' ]
];
try
{
$previousManualSave = Db::i()->select( 'revision_id', 'cms_page_revisions', [ 'revision_page_id=? AND revision_manual_save=1', $page->id ], 'revision_id DESC', [ 1,1 ] )->first();
if ( $previousManualSave > 0 )
{
$table->filters['revision_page_last_session'] = ['( revision_id > ' . $previousManualSave . ' )'];
}
}
catch( UnderflowException $e )
{
}
$table->parsers = [
'revision_date' => function( $val, $row )
{
return Theme::i()->getTemplate( 'pages', 'cms', 'admin' )->revisionDate( DateTime::ts( $val ), $row['revision_manual_save'] );
},
'revision_member_id' => function( $val, $row )
{
$member = Member::constructFromData( $row );
return Theme::i()->getTemplate( 'global', 'core' )->userLink( $member );
}
];
$table->rowButtons = function( $row ) use ( $page )
{
return [
'view' => [
'icon' => 'search',
'title' => 'view_page_revision',
'link' => $page->url()->setQueryString( 'version', $row['revision_id'] ),
'target' => '_blank'
]
];
};
Output::i()->title = $page->_title;
Output::i()->breadcrumb[] = [ $this->url, Member::loggedIn()->language()->addToStack( 'menu__cms_pages_pages' ) ];
Output::i()->breadcrumb[] = [ Url::internal('app=cms&module=pages&controller=pages&do=form&subnode=' . Request::i()->subnode . '&id=' . $page->_id ), $page->_title ];
Output::i()->breadcrumb[] = [ null, Member::loggedIn()->language()->addToStack( 'content_page_history' ) ];
Output::i()->output = (string) $table;
}
/**
* Tree Search
*
@@ -380,7 +532,21 @@ FILE;
'sprintf' => array( Url::internal( "app=cms&module=databases&controller=databases&do=form&id=" . static::$pageToDatabaseMap[ $page->id ] ) )
) );
}
return Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $page->id, $page->seo_name, false, $page->getButtons( Url::internal('app=cms&module=pages&controller=pages'), true ), Member::loggedIn()->language()->addToStack( 'num_views_with_number', NULL, array( 'pluralize' => array( $page->views ) ) ), 'file-text-o', NULL, FALSE, NULL, NULL, $badge, FALSE, FALSE, FALSE );
$names = [];
if( $page->default == Page::PAGE_DEFAULT_OVERRIDE and !empty( $page->group_defaults ) )
{
foreach( explode( ",", $page->group_defaults ) as $groupId )
{
try
{
$names[] = Group::load( $groupId )->name;
}
catch( OutOfRangeException ){}
}
}
return Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $page->id, $page->seo_name, false, $page->getButtons( Url::internal('app=cms&module=pages&controller=pages'), true ), Member::loggedIn()->language()->addToStack( 'num_views_with_number', NULL, array( 'pluralize' => array( $page->views ) ) ), 'file-text-o', NULL, FALSE, NULL, NULL, $badge, FALSE, FALSE, FALSE, true, Theme::i()->getTemplate( 'pages' )->pageRowHtml( $page, implode( ", ", $names ) ) );
}
@@ -98,7 +98,7 @@ class templates extends Controller
];
foreach( Databases::$templateGroups as $key => $group )
{
$groups[ $key ] = Member::loggedIn()->language()->addToStack( 'cms_new_db_template_group_' . $key );
$groups[ $group ] = Member::loggedIn()->language()->addToStack( 'cms_new_db_template_group_' . $key );
}
/* Build a list of all custom directories */
@@ -623,7 +623,7 @@ class templates extends Controller
try
{
$count = Db::i()->select( 'COUNT(*)', 'cms_templates', array( "LOWER(template_title)=?", mb_strtolower( str_replace( ' ', '_', $val ) ) ) )->first();
$count = Db::i()->select( 'COUNT(*)', 'cms_templates', array( "LOWER(template_group)=?", mb_strtolower( str_replace( ' ', '_', $val ) ) ) )->first();
if ( $count )
{
@@ -665,12 +665,6 @@ class category extends Controller
}
else
{
Output::i()->metaTags['title'] = $category->metaTitle();
Output::i()->metaTags['description'] = $category->metaDescription();
Output::i()->metaTags['og:title'] = $category->metaTitle();
Output::i()->metaTags['og:description'] = $category->metaDescription();
Output::i()->linkTags['canonical'] = (string) $category->url();
/* Set breadcrumb */
if ( $club = $category->_club )
{
@@ -687,6 +681,12 @@ class category extends Controller
}
}
Output::i()->metaTags['title'] = $category->metaTitle();
Output::i()->metaTags['description'] = $category->metaDescription();
Output::i()->metaTags['og:title'] = $category->metaTitle();
Output::i()->metaTags['og:description'] = $category->metaDescription();
Output::i()->linkTags['canonical'] = (string) $category->url();
/* Node handler does not support keywords, so we need to do it manually */
if ( $category->meta_keywords )
{
@@ -772,7 +772,6 @@ class category extends Controller
}
$this->showClubHeader( $category );
Output::i()->allowDefaultWidgets = FALSE;
Output::i()->sidebar['enabled'] = FALSE;
Output::i()->output = $form->customTemplate( array( \IPS\cms\Theme::i()->getTemplate( $database->template_form, 'cms', 'database' ), 'recordForm' ), NULL, $category, $database, Page::$currentPage, $title, $hasModOptions );
Dispatcher::i()->output .= Output::i()->output;
@@ -88,6 +88,7 @@ class record extends Controller
protected function manage() : mixed
{
/* Load record */
/** @var Records $record */
try
{
$record = parent::manage();
@@ -318,11 +319,11 @@ class record extends Controller
}
$logo = NULL;
if( Theme::i()->logo['front'] )
if( !empty( Theme::i()->logo['front']['url'] ) )
{
try
{
$logo = File::get( 'core_Theme', Theme::i()->logo['front']['url'] )->url;
$logo = Theme::i()->logo['front']['url'];
}
/* File doesn't exist */
catch ( RuntimeException | DomainException $e ){}
@@ -795,7 +796,6 @@ class record extends Controller
Output::i()->redirect( $record->url() );
}
Output::i()->allowDefaultWidgets = FALSE;
Output::i()->sidebar['enabled'] = FALSE;
Output::i()->title = Member::loggedIn()->language()->addToStack( $title );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'records/form.css', 'cms', 'front' ) );
@@ -220,6 +220,7 @@ class topic extends Controller
$fakeRecord->$titleField = $this->topic->mapped('title');
$fakeRecord->$contentField = $this->topic->content();
$fakeRecord->category_id = Request::i()->category_id;
Request::i()->tags = $this->topic->tags();
if( $fakeRecord->_forum_record AND $fakeRecord->_forum_comments )
{
@@ -322,6 +323,12 @@ class topic extends Controller
$obj->rebuildFirstAndLastCommentData();
}
/* Remove tags from the original topic, so that we don't have duplicates on the tag page */
$this->topic->setTags( [] );
/* Now we want to update the original topic in case we made any changes */
$record->syncTopic();
try
{
/* If the database is on a page, go to the record */
+13 -10
View File
@@ -16,6 +16,7 @@ use IPS\cms\Categories;
use IPS\cms\Pages\Folder;
use IPS\cms\Pages\Page;
use IPS\cms\Records;
use IPS\Content\Filter;
use IPS\Db;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Theme;
@@ -69,19 +70,21 @@ class ajax extends \IPS\cms\modules\admin\pages\ajax
{
/* @var Categories $containerClass */
$containerClass = 'IPS\cms\Categories' . Request::i()->navId;
try
{
$container = $containerClass::load( Request::i()->container );
$items = [];
foreach( $container->getContentItems( null, null ) as $item )
{
/* Only show items that we can actually see, and if they're not pending deletion */
/* @var Records $item */
if( $item->canView() and $item->hidden() !== -2 )
{
$items[] = $item;
}
}
/* @var Records $itemClass */
$itemClass = $containerClass::$contentItemClass;
$sort = ( $container::database()->field_sort ? $itemClass::$databaseTable . '.' . $itemClass::$databasePrefix . $container::database()->field_sort : 'record_last_comment' ) . ' ' . ( $container::database()->field_direction ?? 'desc' );
$items = iterator_to_array(
$itemClass::getItemsWithPermission( [
[ $itemClass::$databaseTable . '.category_id=?', $container->_id ]
], $sort, null )
);
Output::i()->sendOutput( Theme::i()->getTemplate( 'widgets', 'cms', 'front' )->databaseNavigationItems( $items ) );
}
@@ -168,15 +168,7 @@ class builder extends widgets
try
{
$block = Block::load( Request::i()->id );
try
{
$widget = $block->widget();
}
catch ( OutOfRangeException )
{
$widget = new Blocks( "", ['cms_widget_custom_block' => $block->key] );
}
$widget = new Blocks( "", ['cms_widget_custom_block' => $block->key] );
Output::i()->json( [ "content" => (string) $widget, "configuration" => $widget->dataAttributes(), 'block_key' => $block->key ], 200 );
}
catch ( UnderFlowException|OutOfRangeException $e )
+75 -3
View File
@@ -13,8 +13,10 @@ namespace IPS\cms\modules\front\pages;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Member;
use IPS\cms\Databases\Dispatcher;
use IPS\cms\Pages\Page as PageClass;
use IPS\cms\Pages\Revision;
use IPS\Dispatcher\Controller;
use IPS\Http\Url;
use IPS\IPS;
@@ -46,9 +48,32 @@ class page extends Controller
*/
public function manage() : void
{
Output::i()->bodyAttributes['contentClass'] = PageClass::class;
$this->view();
}
/**
* @return void
* @throws Exception
*/
public function storeRevision(): void
{
if( ! Member::loggedIn()->modPermission('can_manage_sidebar') )
{
Output::i()->error( 'content_err_page_403', '2T187/5', 403 );
}
try
{
$page = static::getPage();
Revision::store( $page, true );
Output::i()->json( [ 'result' => 'ok' ] );
}
catch( OutOfRangeException $e )
{
Output::i()->error( 'content_err_page_404', '2T187/6', 404 );
}
}
/**
* Display a page. Sounds simple doesn't it? Well it's not.
*
@@ -57,6 +82,11 @@ class page extends Controller
protected function view() : void
{
$page = $this::getPage();
if( isset( Request::i()->version ) and Member::loggedIn()->modPermission('can_manage_sidebar') )
{
$page->setVersion( Request::i()->version );
}
/* Database specific checks */
if ( isset( Request::i()->advancedSearchForm ) AND isset( Request::i()->d ) )
@@ -150,7 +180,7 @@ class page extends Controller
else if ( isset( Request::i()->path ) AND Request::i()->path != '/' )
{
/* Sort out pagination for pages */
list( $path, $pageNumber ) = PageClass::getStrippedPagePath( Request::i()->path );
[ $path, $pageNumber ] = PageClass::getStrippedPagePath( Request::i()->path );
if( $pageNumber AND !Request::i()->page )
{
Request::i()->page = $pageNumber;
@@ -183,7 +213,7 @@ class page extends Controller
{
try
{
$page = PageClass::getDefaultPage();
$page = PageClass::getDefaultForMember();
}
catch ( OutOfRangeException $e )
{
@@ -211,6 +241,48 @@ class page extends Controller
return $page;
}
/**
* Revert a page to a specific version
*
* @return void
*/
protected function revertToVersion() : void
{
Request::i()->confirmedDelete();
if( !\IPS\Dispatcher::i()->application->canManageWidgets() )
{
Output::i()->error( 'content_err_page_403', '2T187/8', 403 );
}
$page = static::getPage();
$version = null;
if( isset( Request::i()->version ) )
{
try
{
$version = Revision::load( Request::i()->version );
}
catch( OutOfRangeException )
{
Output::i()->error( 'content_err_page_404', '2T187/6', 404 );
}
}
else
{
$version = Revision::previousVersion( $page );
if( $version === null )
{
Output::i()->error( 'content_err_page_404', '2T187/7', 404 );
}
}
$version->revert();
Output::i()->redirect( $page->url() );
}
/**
* Capture database specific things