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

+119 -66
View File
@@ -11,10 +11,33 @@
namespace IPS\forums;
use DateInterval;
use Exception;
use IPS\Application as SystemApplication;
use IPS\Content\Filter;
use IPS\Content\Search\Index;
use IPS\DateTime;
use IPS\Dispatcher;
use IPS\forums\Topic\Post;
use IPS\Http\Url;
use IPS\Http\Url\Friendly;
use IPS\Log;
use IPS\Login;
use IPS\Member;
use IPS\Output;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
use IPS\Xml\Rss;
use OutOfRangeException;
use function array_merge;
use function IPS\Cicloud\getForumArchiveWhere;
use function is_numeric;
/**
* Forums Application Class
*/
class _Application extends \IPS\Application
class Application extends SystemApplication
{
/**
@@ -22,26 +45,26 @@ class _Application extends \IPS\Application
*
* @return void
*/
public function init()
public function init() : void
{
/* Handle RSS requests */
if ( \IPS\Request::i()->module == 'forums' and \IPS\Request::i()->controller == 'forums' and isset( \IPS\Request::i()->rss ) )
if ( Request::i()->module == 'forums' and Request::i()->controller == 'forums' and isset( Request::i()->rss ) )
{
$member = NULL;
if( \IPS\Request::i()->member AND \IPS\Request::i()->key )
if( Request::i()->member AND Request::i()->key )
{
$member = \IPS\Member::load( \IPS\Request::i()->member );
if( !\IPS\Login::compareHashes( $member->getUniqueMemberHash(), (string) \IPS\Request::i()->key ) )
$member = Member::load( Request::i()->member );
if( !Login::compareHashes( $member->getUniqueMemberHash(), (string) Request::i()->key ) )
{
$member = NULL;
}
}
$this->sendForumRss( $member ?? new \IPS\Member );
$this->sendForumRss( $member ?? new Member );
if( !\IPS\Member::loggedIn()->group['g_view_board'] )
if( !Member::loggedIn()->group['g_view_board'] )
{
\IPS\Output::i()->error( 'node_error', '2F219/1', 404, '' );
Output::i()->error( 'node_error', '2F219/1', 404, '' );
}
}
}
@@ -49,28 +72,28 @@ class _Application extends \IPS\Application
/**
* Send the forum's RSS feed for the indicated member
*
* @param \IPS\Member $member Member
* @param Member $member Member
* @return void
*/
protected function sendForumRss( $member )
protected function sendForumRss( Member $member ) : void
{
try
{
$forum = \IPS\forums\Forum::load( \IPS\Request::i()->id );
$forum = Forum::load( Request::i()->id );
if( !$forum->can( 'view', $member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
/* We'll let the regular controller handle the error */
return;
}
/* RSS feeds are not available if the setting is off, or there is nothing to include */
if ( !\IPS\Settings::i()->forums_rss OR !$forum->topics )
if ( !Settings::i()->forums_rss OR !$forum->topics )
{
return;
}
@@ -83,23 +106,16 @@ class _Application extends \IPS\Application
}
/* Init table (it won't show anything until after the password check, but it sets navigation and titles) */
$iterator = \IPS\forums\Topic::getItemsWithPermission( $where, 'forums_topics.last_post DESC', \IPS\Settings::i()->forums_topics_per_page, 'view', \IPS\Content\Hideable::FILTER_PUBLIC_ONLY, 0, $member, FALSE, FALSE, FALSE, FALSE, NULL, $forum, TRUE, TRUE, TRUE, FALSE );
$iterator = Topic::getItemsWithPermission( $where, 'forums_topics.last_post DESC', Settings::i()->forums_topics_per_page, 'view', Filter::FILTER_PUBLIC_ONLY, 0, $member, FALSE, FALSE, FALSE, FALSE, NULL, $forum, TRUE, TRUE, TRUE, FALSE );
/* Set the title, either topics or questions */
if ( $forum->forums_bitoptions['bw_enable_answers'] )
{
$rssTitle = sprintf( $member->language()->get( 'forum_rss_title_questions'), $member->language()->get( "forums_forum_{$forum->id}" ) );
}
else
{
$rssTitle = sprintf( $member->language()->get( 'forum_rss_title_topics'), $member->language()->get( "forums_forum_{$forum->id}" ) );
}
/* Set the title */
$rssTitle = sprintf( $member->language()->get( 'forum_rss_title_topics'), $member->language()->get( "forums_forum_{$forum->id}" ) );
/* Can we view the content (permission_showtopic may allow us to view the list, but not the content)? */
$canViewContent = $forum->can('read', $member );
/* Build the document */
$document = \IPS\Xml\Rss::newDocument( $forum->url(), $rssTitle, $rssTitle );
$document = Rss::newDocument( $forum->url(), $rssTitle, $rssTitle );
foreach ( $iterator as $topic )
{
try
@@ -107,31 +123,33 @@ class _Application extends \IPS\Application
$content = NULL;
if ( $canViewContent )
{
/* @var $topic Topic */
$content = $topic->content();
\IPS\Output::i()->parseFileObjectUrls( $content );
Output::i()->parseFileObjectUrls( $content );
}
$document->addItem( $topic->title, $topic->url(), $content, \IPS\DateTime::ts( $topic->start_date ), $topic->tid );
$document->addItem( $topic->title, $topic->url(), $canViewContent ? $topic->content() : NULL, DateTime::ts( $topic->start_date ), $topic->tid );
}
catch ( \Exception $e ) { }
catch ( Exception $e ) { }
}
/* Display - 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', array(), TRUE );
}
/**
* Archive Query
*
* @param array $rules Rules
* @param array $rules Rules
* @return array
*/
public static function archiveWhere( $rules )
public static function archiveWhere( array $rules ): array
{
$where = array();
if ( \IPS\CIC )
if ( Application::appIsEnabled('cloud') )
{
return \IPS\Cicloud\getForumArchiveWhere();
return getForumArchiveWhere();
}
foreach ( $rules as $rule )
@@ -144,12 +162,12 @@ class _Application extends \IPS\Application
/* If the data is bad, log and don't throw an error, but don't allow anything to be archived. */
if( !$rule['archive_text'] OR !$rule['archive_unit'] )
{
\IPS\Log::log( 'Forum archiving missing time period or archive unit', 'forum_archive' );
Log::log( 'Forum archiving missing time period or archive unit', 'forum_archive' );
$clause = array( '0=?', '1' );
}
else
{
$clause = array( '(last_post > 0 AND last_post ' . $rule['archive_value'] . ' ?)', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . trim( $rule['archive_text'] ) . mb_strtoupper( $rule['archive_unit'] ) ) )->getTimestamp() );
$clause = array( '(last_post > 0 AND last_post ' . $rule['archive_value'] . ' ?)', DateTime::create()->sub( new DateInterval( 'P' . trim( $rule['archive_text'] ) . mb_strtoupper( $rule['archive_unit'] ) ) )->getTimestamp() );
}
break;
@@ -198,12 +216,8 @@ class _Application extends \IPS\Application
if ( $rule['archive_skip'] )
{
$clause[0] = ( '!(' . $clause[0] . ')' );
$where[] = $clause;
}
else
{
$where[] = $clause;
}
$where[] = $clause;
}
}
@@ -214,9 +228,9 @@ class _Application extends \IPS\Application
* [Node] Get Icon for tree
*
* @note Return the class for the icon (e.g. 'globe')
* @return string|null
* @return string
*/
protected function get__icon()
protected function get__icon(): string
{
return 'comments';
}
@@ -226,10 +240,10 @@ class _Application extends \IPS\Application
*
* @return void
*/
public function installOther()
public function installOther() : void
{
\IPS\Content\Search\Index::i()->index( \IPS\forums\Topic::load( 1 ) );
\IPS\Content\Search\Index::i()->index( \IPS\forums\Topic\Post::load( 1 ) );
Index::i()->index( Topic::load( 1 ) );
Index::i()->index( Post::load( 1 ) );
}
/**
@@ -255,7 +269,7 @@ class _Application extends \IPS\Application
* @endcode
* @return array
*/
public function defaultFrontNavigation()
public function defaultFrontNavigation(): array
{
return array(
'rootTabs' => array(),
@@ -270,10 +284,10 @@ class _Application extends \IPS\Application
*
* @return void
*/
public function convertLegacyParameters()
public function convertLegacyParameters() : void
{
/* Convert &showtopic= (link) */
if ( isset( \IPS\Request::i()->showtopic ) and \is_numeric( \IPS\Request::i()->showtopic ) )
if ( isset( Request::i()->showtopic ) and is_numeric( Request::i()->showtopic ) )
{
$base = NULL;
$seoTemplate = NULL;
@@ -281,7 +295,7 @@ class _Application extends \IPS\Application
try
{
$topic = \IPS\forums\Topic::load( \IPS\Request::i()->showtopic );
$topic = Topic::load( Request::i()->showtopic );
if ( $topic->canView() )
{
@@ -289,23 +303,23 @@ class _Application extends \IPS\Application
$seoTemplate = 'forums_topic';
$seoTitles = array( $topic->title_seo );
}
} catch( \Exception $e ) {}
} catch( Exception $e ) {}
$url = \IPS\Http\Url::internal( 'app=forums&module=forums&controller=topic&id=' . \IPS\Request::i()->showtopic, $base, $seoTemplate, $seoTitles );
$url = Url::internal( 'app=forums&module=forums&controller=topic&id=' . Request::i()->showtopic, $base, $seoTemplate, $seoTitles );
if ( isset( \IPS\Request::i()->p ) or isset( \IPS\Request::i()->findpost ) or isset( \IPS\Request::i()->comment ) )
if ( isset( Request::i()->p ) or isset( Request::i()->findpost ) or isset( Request::i()->comment ) )
{
$url = $url->setQueryString( array( 'do' => 'findComment', 'comment' => \IPS\Request::i()->p ?: ( \IPS\Request::i()->findpost ?: \IPS\Request::i()->comment ) ) );
$url = $url->setQueryString( array( 'do' => 'findComment', 'comment' => Request::i()->p ?: ( Request::i()->findpost ?: Request::i()->comment ) ) );
}
elseif ( isset( \IPS\Request::i()->page ) )
elseif ( isset( Request::i()->page ) )
{
$url = $url->setPage( 'page', \IPS\Request::i()->page );
$url = $url->setPage( 'page', Request::i()->page );
}
\IPS\Output::i()->redirect( $url );
Output::i()->redirect( $url );
}
/* Convert &showforum= */
if ( isset( \IPS\Request::i()->showforum ) and \is_numeric( \IPS\Request::i()->showforum ) )
if ( isset( Request::i()->showforum ) and is_numeric( Request::i()->showforum ) )
{
$base = NULL;
$seoTemplate = NULL;
@@ -313,7 +327,7 @@ class _Application extends \IPS\Application
try
{
$forum = \IPS\forums\Forum::load( \IPS\Request::i()->showforum );
$forum = Forum::load( Request::i()->showforum );
if ( $forum->can( 'view' ) )
{
@@ -321,22 +335,22 @@ class _Application extends \IPS\Application
$seoTemplate = 'forums_forum';
$seoTitles = array( $forum->name_seo );
}
} catch ( \Exception $e ) {}
} catch ( Exception $e ) {}
$url = \IPS\Http\Url::internal( 'app=forums&module=forums&controller=forums&id=' . \IPS\Request::i()->showforum, $base, $seoTemplate, $seoTitles );
\IPS\Output::i()->redirect( $url );
$url = Url::internal( 'app=forums&module=forums&controller=forums&id=' . Request::i()->showforum, $base, $seoTemplate, $seoTitles );
Output::i()->redirect( $url );
}
/* Convert /topic/123-example/&p= */
if ( isset( \IPS\Request::i()->p ) AND \is_numeric( \IPS\Request::i()->p ) AND ( \IPS\Request::i()->url() instanceof \IPS\Http\Url\Friendly ) AND \IPS\Request::i()->url()->seoTemplate == 'forums_topic' )
if ( isset( Request::i()->p ) AND is_numeric( Request::i()->p ) AND ( Request::i()->url() instanceof Friendly ) AND Request::i()->url()->seoTemplate == 'forums_topic' )
{
/* We do this a little differently as the topic seo title is already known at this point */
try
{
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( \IPS\Request::i()->p );
\IPS\Output::i()->redirect( $post->url() );
$post = Post::loadAndCheckPerms( Request::i()->p );
Output::i()->redirect( $post->url() );
}
catch( \Exception $e ) {}
catch( Exception $e ) {}
}
}
@@ -350,4 +364,43 @@ class _Application extends \IPS\Application
{
return [ 'forumpass_*' ];
}
/**
* Get all possible layout values for this page and app
*
* @return array
*/
public function getThemeLayoutOptionsForThisPage(): array
{
$return = [];
if ( Dispatcher::i()->application->directory === 'forums' and Dispatcher::i()->module->key === 'forums' and Dispatcher::i()->controller === 'index' )
{
$return[] = 'forums_forum';
}
else if ( Dispatcher::i()->application->directory === 'forums' and Dispatcher::i()->module->key === 'forums' and Dispatcher::i()->controller === 'forums' )
{
$return[] = 'forums_topic';
}
else if ( Dispatcher::i()->application->directory === 'forums' and Dispatcher::i()->module->key === 'forums' and Dispatcher::i()->controller === 'topic' )
{
$return[] = 'forums_post';
$return[] = 'forum_topic_view_firstpost';
}
return $return;
}
/**
* Output CSS files
*
* @return void
*/
public static function outputCss() : void
{
if ( Dispatcher::hasInstance() and Dispatcher::i()->controllerLocation === 'front' )
{
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'forums.css', 'forums', 'front' ) );
}
}
}