Files
IPB/applications/cms/modules/front/pages/ajax.php
T
2025-12-19 18:55:49 -08:00

91 lines
2.1 KiB
PHP

<?php
/**
* @brief ajax
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Pages
* @since 13 Dec 2023
*/
namespace IPS\cms\modules\front\pages;
use IPS\cms\Categories;
use IPS\cms\Pages\Folder;
use IPS\cms\Pages\Page;
use IPS\cms\Records;
use IPS\Db;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Theme;
use IPS\Output;
use IPS\Request;
use OutOfRangeException;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* ajax
*/
class ajax extends \IPS\cms\modules\admin\pages\ajax
{
/**
* Load navigation items
*
* @return void
*/
protected function loadItems() : void
{
if( Request::i()->navType == 'folder' )
{
try
{
$folder = Folder::load( Request::i()->container );
$items = [];
foreach( new ActiveRecordIterator(
Db::i()->select( '*', 'cms_pages', [ 'page_folder_id=?', $folder->id ] ),
Page::class
) as $item )
{
/* @var Page $item */
if( $item->canView() )
{
$items[] = $item;
}
}
Output::i()->sendOutput( Theme::i()->getTemplate( 'widgets', 'cms', 'front' )->folderNavigationItems( $items ) );
}
catch( OutOfRangeException ){}
}
else
{
/* @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;
}
}
Output::i()->sendOutput( Theme::i()->getTemplate( 'widgets', 'cms', 'front' )->databaseNavigationItems( $items ) );
}
catch( OutOfRangeException ){}
}
}
}