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,16 +12,40 @@
|
||||
namespace IPS\cms\modules\front\database;
|
||||
|
||||
/* 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;
|
||||
use IPS\cms\Databases\Controller;
|
||||
use IPS\cms\Databases\Dispatcher;
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\cms\Records;
|
||||
use IPS\Content\Filter;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use IPS\Xml\Rss;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function intval;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* List
|
||||
*/
|
||||
class _index extends \IPS\cms\Databases\Controller
|
||||
class index extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -29,23 +53,25 @@ class _index extends \IPS\cms\Databases\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
/* If the Databases module is set as default we end up here, but not routed through the database dispatcher which means the
|
||||
database ID isn't set. In that case, just re-route back through the pages controller which handles everything. */
|
||||
if( \IPS\cms\Databases\Dispatcher::i()->databaseId === NULL )
|
||||
if( Dispatcher::i()->databaseId === NULL )
|
||||
{
|
||||
$pages = new \IPS\cms\modules\front\pages\page;
|
||||
return $pages->manage();
|
||||
$pages->manage();
|
||||
return;
|
||||
}
|
||||
|
||||
$database = \IPS\cms\Databases::load( \IPS\cms\Databases\Dispatcher::i()->databaseId );
|
||||
$database = Databases::load( Dispatcher::i()->databaseId );
|
||||
|
||||
/* Not using categories? */
|
||||
if ( ! $database->use_categories AND $database->cat_index_type === 0 )
|
||||
if ( ! $database->use_categories AND $database->display_settings['index']['type'] == 'categories' )
|
||||
{
|
||||
$controller = new \IPS\cms\modules\front\database\category( $this->url );
|
||||
return $controller->view();
|
||||
$controller = new category( $this->url );
|
||||
$controller->view();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->view();
|
||||
@@ -56,25 +82,26 @@ class _index extends \IPS\cms\Databases\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function view()
|
||||
protected function view() : void
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( \IPS\cms\Databases\Dispatcher::i()->databaseId );
|
||||
$recordClass = 'IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=page&path=" . \IPS\cms\Pages\Page::$currentPage->full_path, 'front', 'content_page_path', \IPS\cms\Pages\Page::$currentPage->full_path );
|
||||
$database = Databases::load( Dispatcher::i()->databaseId );
|
||||
$recordClass = 'IPS\cms\Records' . Dispatcher::i()->databaseId;
|
||||
$url = Url::internal( "app=cms&module=pages&controller=page&path=" . Page::$currentPage->full_path, 'front', 'content_page_path', Page::$currentPage->full_path );
|
||||
|
||||
/* RSS */
|
||||
if ( $database->rss )
|
||||
{
|
||||
/* Show the link */
|
||||
\IPS\Output::i()->rssFeeds[ $database->_title ] = $url->setQueryString( 'rss', 1 );
|
||||
Output::i()->rssFeeds[ $database->_title ] = $url->setQueryString( 'rss', 1 );
|
||||
|
||||
/* Or actually show RSS feed */
|
||||
if ( isset( \IPS\Request::i()->rss ) )
|
||||
if ( isset( Request::i()->rss ) )
|
||||
{
|
||||
$document = \IPS\Xml\Rss::newDocument( $url, \IPS\Member::loggedIn()->language()->get('content_db_' . $database->id ), \IPS\Member::loggedIn()->language()->get('content_db_' . $database->id . '_desc' ) );
|
||||
$document = Rss::newDocument( $url, Member::loggedIn()->language()->get('content_db_' . $database->id ), Member::loggedIn()->language()->get('content_db_' . $database->id . '_desc' ) );
|
||||
$contentField = 'field_' . $database->field_content;
|
||||
|
||||
foreach ( $recordClass::getItemsWithPermission( array(), $database->field_sort . ' ' . $database->field_direction, $database->rss, 'read' ) as $record )
|
||||
|
||||
/* @var Records $recordClass */
|
||||
foreach ( $recordClass::getItemsWithPermission( array(), $database->field_sort . ' ' . $database->field_direction, $database->rss ) as $record )
|
||||
{
|
||||
$content = $record->$contentField;
|
||||
|
||||
@@ -83,67 +110,96 @@ class _index extends \IPS\cms\Databases\Controller
|
||||
$content = \IPS\cms\Theme::i()->getTemplate( 'listing', 'cms', 'database' )->rssItemWithImage( $content, $record->record_image );
|
||||
}
|
||||
|
||||
$document->addItem( $record->_title, $record->url(), $content, \IPS\DateTime::ts( $record->_publishDate ), $record->_id );
|
||||
$document->addItem( $record->_title, $record->url(), $content, DateTime::ts( $record->_publishDate ), $record->_id );
|
||||
}
|
||||
|
||||
/* @note application/rss+xml is not a registered IANA mime-type so we need to stick with text/xml for RSS */
|
||||
\IPS\Output::i()->sendOutput( $document->asXML(), 200, 'text/xml', array(), TRUE );
|
||||
Output::i()->sendOutput( $document->asXML(), 200, 'text/xml' );
|
||||
}
|
||||
}
|
||||
|
||||
$page = isset( \IPS\Request::i()->page ) ? \intval( \IPS\Request::i()->page ) : 1;
|
||||
$page = isset( Request::i()->page ) ? intval( Request::i()->page ) : 1;
|
||||
|
||||
if( $page < 1 )
|
||||
{
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if ( $database->cat_index_type === 1 and ! isset( \IPS\Request::i()->show ) )
|
||||
if ( $database->display_settings['index']['type'] != 'categories' and ! isset( Request::i()->show ) )
|
||||
{
|
||||
/* Featured */
|
||||
$limit = 0;
|
||||
$count = 0;
|
||||
$perPage = ( $database->field_perpage ?? 25 );
|
||||
|
||||
if ( isset( \IPS\Request::i()->page ) )
|
||||
if ( isset( Request::i()->page ) )
|
||||
{
|
||||
$limit = $database->featured_settings['perpage'] * ( $page - 1 );
|
||||
$limit = $perPage * ( $page - 1 );
|
||||
}
|
||||
|
||||
$where = ( $database->featured_settings['featured'] ) ? array( array( 'record_featured=?', 1 ) ) : NULL;
|
||||
|
||||
if ( isset( $database->featured_settings['categories'] ) and \is_array( $database->featured_settings['categories'] ) and \count( $database->featured_settings['categories'] ) )
|
||||
{
|
||||
$categoryField = "`cms_custom_database_{$database->_id}`.`category_id`";
|
||||
$where[] = array( \IPS\Db::i()->in( $categoryField, array_values( $database->featured_settings['categories'] ) ) );
|
||||
}
|
||||
|
||||
$articles = $recordClass::getItemsWithPermission( $where, 'record_pinned DESC, ' . $database->featured_settings['sort'] . ' ' . $database->featured_settings['direction'], array( $limit, $database->featured_settings['perpage'] ), 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, TRUE, FALSE, FALSE, FALSE );
|
||||
$where = [];
|
||||
|
||||
if ( $database->featured_settings['pagination'] )
|
||||
/** @var Categories $categoryClass */
|
||||
$categoryClass = 'IPS\cms\Categories' . $database->id;
|
||||
$category = $categoryClass::load( $database->_default_category );
|
||||
$cookie = $category->getFilterCookie();
|
||||
if( $cookie !== null )
|
||||
{
|
||||
$count = $recordClass::getItemsWithPermission( $where, 'record_pinned DESC, ' . $database->featured_settings['sort'] . ' ' . $database->featured_settings['direction'], $database->featured_settings['perpage'], 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
|
||||
$where = $category->buildWhereFromCookie( $cookie );
|
||||
}
|
||||
elseif( isset( Request::i()->advanced_search_submitted ) and Request::i()->advanced_search_submitted )
|
||||
{
|
||||
$cookie = [];
|
||||
foreach( Request::i() as $k => $v )
|
||||
{
|
||||
if( $k == 'cms_record_i_started' )
|
||||
{
|
||||
$cookie[ $k ] = $v;
|
||||
}
|
||||
elseif( str_starts_with( $k, 'content_field_' ) )
|
||||
{
|
||||
$cookie[ mb_substr( $k, 14 ) ] = $v;
|
||||
}
|
||||
}
|
||||
if( count( $cookie ) )
|
||||
{
|
||||
$where = $category->buildWhereFromCookie( $cookie );
|
||||
}
|
||||
}
|
||||
|
||||
if( $database->display_settings['index']['type'] == 'featured' )
|
||||
{
|
||||
$where[] = [ 'record_featured=?', 1 ];
|
||||
}
|
||||
|
||||
$sort = ( $database->field_sort ? $recordClass::$databaseTable . '.' . $recordClass::$databasePrefix . $database->field_sort : 'record_last_comment' );
|
||||
$sortDirection = $database->field_direction ?? 'desc';
|
||||
|
||||
$articles = $recordClass::getItemsWithPermission( $where, 'record_pinned DESC, ' . $sort . ' ' . $sortDirection, array( $limit, $perPage ), 'read', Filter::FILTER_AUTOMATIC, 0, NULL, TRUE );
|
||||
|
||||
$count = $recordClass::getItemsWithPermission( $where, 'record_pinned DESC, ' . $sort . ' ' . $sortDirection, $perPage, 'read', Filter::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
|
||||
|
||||
/* Pagination */
|
||||
$pagination = array(
|
||||
'page' => $page,
|
||||
'pages' => ( $count > 0 ) ? ceil( $count / $database->featured_settings['perpage'] ) : 1
|
||||
'pages' => ( $count > 0 ) ? ceil( $count / $perPage ) : 1
|
||||
);
|
||||
|
||||
/* Make sure we are viewing a real page */
|
||||
if ( $page > $pagination['pages'] )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Request::i()->url()->setPage( 'page', 1 ), NULL, 303 );
|
||||
Output::i()->redirect( Request::i()->url()->setPage( 'page', 1 ), NULL, 303 );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'database_index/featured.css', 'cms', 'front' ) );
|
||||
\IPS\Output::i()->title = ( $page > 1 ) ? \IPS\Member::loggedIn()->language()->addToStack( 'title_with_page_number', FALSE, array( 'sprintf' => array( $database->pageTitle(), $page ) ) ) : $database->pageTitle();
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'database_index/featured.css', 'cms', 'front' ) );
|
||||
Output::i()->title = ( $page > 1 ) ? Member::loggedIn()->language()->addToStack( 'title_with_page_number', FALSE, array( 'sprintf' => array( $database->pageTitle(), $page ) ) ) : $database->pageTitle();
|
||||
|
||||
\IPS\cms\Databases\Dispatcher::i()->output .= \IPS\Output::i()->output = \IPS\cms\Theme::i()->getTemplate( $database->template_featured, 'cms', 'database' )->index( $database, $articles, $url, $pagination );
|
||||
Dispatcher::i()->output .= Output::i()->output = \IPS\cms\Theme::i()->getTemplate( $database->template_featured, 'cms', 'database' )->index( $database, $articles, $url, $pagination );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Category view */
|
||||
/* @var Categories $class */
|
||||
$class = '\IPS\cms\Categories' . $database->id;
|
||||
|
||||
/* Load into memory */
|
||||
@@ -159,9 +215,8 @@ class _index extends \IPS\cms\Databases\Controller
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'records/index.css', 'cms', 'front' ) );
|
||||
\IPS\Output::i()->title = $database->pageTitle();
|
||||
\IPS\cms\Databases\Dispatcher::i()->output .= \IPS\Output::i()->output = \IPS\cms\Theme::i()->getTemplate( $database->template_categories, 'cms', 'database' )->index( $database, $categories, $url );
|
||||
Output::i()->title = $database->pageTitle();
|
||||
Dispatcher::i()->output .= Output::i()->output = \IPS\cms\Theme::i()->getTemplate( $database->template_categories, 'cms', 'database' )->index( $database, $categories, $url );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,32 +225,31 @@ class _index extends \IPS\cms\Databases\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form()
|
||||
protected function form() : void
|
||||
{
|
||||
/* If the page is the default page and Pages is the default app, the node selector cannot find the page as it bypasses the Database dispatcher */
|
||||
if ( \IPS\cms\Pages\Page::$currentPage === NULL and \IPS\cms\Databases\Dispatcher::i()->databaseId === NULL and isset( \IPS\Request::i()->page_id ) )
|
||||
if ( Page::$currentPage === NULL and Dispatcher::i()->databaseId === NULL and isset( Request::i()->page_id ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\cms\Pages\Page::$currentPage = \IPS\cms\Pages\Page::load( \IPS\Request::i()->page_id );
|
||||
$database = \IPS\cms\Pages\Page::$currentPage->getDatabase();
|
||||
|
||||
Page::$currentPage = Page::load( Request::i()->page_id );
|
||||
$database = Page::$currentPage->getDatabase();
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'content_err_page_404', '2T389/1', 404, '' );
|
||||
Output::i()->error( 'content_err_page_404', '2T389/1', 404, '' );
|
||||
}
|
||||
}
|
||||
else if ( \IPS\cms\Pages\Page::$currentPage === NULL and \IPS\cms\Databases\Dispatcher::i()->databaseId === NULL and isset( \IPS\Request::i()->d ) )
|
||||
else if ( Page::$currentPage === NULL and Dispatcher::i()->databaseId === NULL and isset( Request::i()->d ) )
|
||||
{
|
||||
\IPS\cms\Pages\Page::$currentPage = \IPS\cms\Pages\Page::loadByDatabaseId( \IPS\Request::i()->d );
|
||||
Page::$currentPage = Page::loadByDatabaseId( Request::i()->d );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'select_category', 'continue' );
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'category', NULL, TRUE, array(
|
||||
'url' => \IPS\cms\Pages\Page::$currentPage->url()->setQueryString( array( 'do' => 'form', 'page_id' => \IPS\cms\Pages\Page::$currentPage->id ) ),
|
||||
'class' => 'IPS\cms\Categories' . \IPS\cms\Pages\Page::$currentPage->getDatabase()->_id,
|
||||
$form = new Form( 'select_category', 'continue' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--select-database-category ipsForm--noLabels';
|
||||
$form->add( new Node( 'category', NULL, TRUE, array(
|
||||
'url' => Page::$currentPage->url()->setQueryString( array( 'do' => 'form', 'page_id' => Page::$currentPage->id ) ),
|
||||
'class' => 'IPS\cms\Categories' . Page::$currentPage->getDatabase()->_id,
|
||||
'permissionCheck' => function( $node )
|
||||
{
|
||||
if ( $node->can( 'view' ) )
|
||||
@@ -214,11 +268,11 @@ class _index extends \IPS\cms\Databases\Controller
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $values['category']->url()->setQueryString( 'do', 'form' ) );
|
||||
Output::i()->redirect( $values['category']->url()->setQueryString( 'do', 'form' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'cms_select_category' );
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'cms_select_category' ) );
|
||||
\IPS\cms\Databases\Dispatcher::i()->output = \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'records' )->categorySelector( $form );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'cms_select_category' );
|
||||
Output::i()->breadcrumb[] = array( NULL, Member::loggedIn()->language()->addToStack( 'cms_select_category' ) );
|
||||
Dispatcher::i()->output = Output::i()->output = Theme::i()->getTemplate( 'records' )->categorySelector( $form );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user