Version 4.2.0

This commit is contained in:
Neo committed 2025-12-19 05:44:59 -08:00
1 parent 0dc2aee5ed
commit 96997ddd8e
2074 files changed
+125454 -55780

No files matched your search

+167 -57
View File
@@ -1,13 +1,12 @@
<?php
/**
* @brief Forum Node
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @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 Forums
* @since 7 Jan 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\forums;
@@ -24,6 +23,9 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
{
use \IPS\Content\ClubContainer;
use \IPS\Node\Colorize;
/**
* @brief [ActiveRecord] Multiton Store
*/
@@ -302,7 +304,7 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
public function get__sortBy()
{
return $this->sort_key;
}
}
/**
* Last Poster ID Column
@@ -570,6 +572,7 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$return[] = 'password';
$return[] = 'password_override';
$return[] = 'min_posts_view';
$return[] = 'club_id';
return $return;
}
@@ -1022,6 +1025,10 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$form->add( new \IPS\Helpers\Form\Translatable( 'forum_rules_title', NULL, FALSE, array( 'app' => 'forums', 'key' => ( $this->id ? "forums_forum_{$this->id}_rulestitle" : NULL ) ), NULL, NULL, NULL, 'forum_rules_title' ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'forum_rules_text', NULL, FALSE, array( 'app' => 'forums', 'key' => ( $this->id ? "forums_forum_{$this->id}_rules" : NULL ), 'editor' => array( 'app' => 'forums', 'key' => 'Forums', 'autoSaveKey' => ( $this->id ? "forums-rules-{$this->id}" : "forums-new-rules" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'rules' ) : NULL ) ), NULL, NULL, NULL, 'forum_rules_text' ) );
/* Color */
$form->add( new \IPS\Helpers\Form\YesNo( 'forum_use_feature_color', $this->feature_color ? 1 : 0, FALSE, array( 'togglesOn' => array( 'forum_feature_color' ) ), NULL, NULL, NULL, 'forum_use_feature_color' ) );
$form->add( new \IPS\Helpers\Form\Color( 'forum_feature_color', $this->feature_color ?: '', FALSE, array(), NULL, NULL, NULL, 'forum_feature_color' ) );
$form->addHeader( 'forum_display_topic' );
$form->addHeader( 'forum_display_question' );
$form->add( new \IPS\Helpers\Form\YesNo( 'bw_enable_answers_member', $this->id ? $this->forums_bitoptions['bw_enable_answers_member'] : TRUE, FALSE, array(), NULL, NULL, NULL, 'bw_enable_answers_member' ) );
@@ -1217,7 +1224,18 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$values['preview_posts'] = 0;
}
}
/* Feature color */
if ( isset( $values['use_feature_color'] ) )
{
if ( ! $values['use_feature_color'] )
{
$values['feature_color'] = NULL;
}
unset( $values['use_feature_color'] );
}
if ( !$this->id )
{
$this->save();
@@ -1397,58 +1415,9 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
*/
public static function theOnlyForum()
{
if ( count( \IPS\forums\Forum::roots() ) === 1 )
{
foreach ( \IPS\forums\Forum::roots() as $root )
{
if ( $root->childrenCount() === 1 )
{
foreach ( $root->children() as $forum )
{
if ( !$forum->redirect_url and !$forum->password )
{
return $forum;
}
}
}
}
}
return NULL;
return static::theOnlyNode( array( 'redirect_url' => FALSE, 'password' => FALSE, 'club_id' => 0 ), FALSE );
}
/**
* Search Index Permissions
* Overloaded here so we can discard categories as they should not influence permissions overall.
*
* @return string Comma-delimited values or '*'
* @li Number indicates a group
* @li Number prepended by "m" indicates a member
* @li Number prepended by "s" indicates a social group
*/
public function searchIndexPermissions()
{
/* Compare both read and view */
$result = static::_getPermissions( $this );
/* And then loop up the parents too... */
foreach ( $this->parents() as $parent )
{
$parentResult = static::_getPermissions( $parent );
if( $result == '*' )
{
$result = $parentResult;
}
else if( $parentResult != '*' )
{
$result = implode( ',', array_intersect( explode( ',', $result ), explode( ',', $parentResult ) ) );
}
}
return $result;
}
/**
* Get which permission keys can access all topics in a forum which
* can normally only show topics to the author
@@ -1746,4 +1715,145 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
'url' => (string) $this->url()
);
}
/* !Clubs */
/**
* Set form for creating a node of this type in a club
*
* @param \IPS\Helpers\Form $form Form object
* @return void
*/
public function clubForm( \IPS\Helpers\Form $form )
{
$itemClass = static::$contentItemClass;
$form->add( new \IPS\Helpers\Form\Text( 'club_node_name', $this->_id ? $this->_title : \IPS\Member::loggedIn()->language()->addToStack( $itemClass::$title . '_pl' ), TRUE, array( 'maxLength' => 255 ) ) );
$form->add( new \IPS\Helpers\Form\Editor( 'club_node_description', $this->_id ? \IPS\Member::loggedIn()->language()->get( static::$titleLangPrefix . $this->_id . '_desc' ) : NULL, FALSE, array( 'app' => 'forums', 'key' => 'Forums', 'autoSaveKey' => ( $this->id ? "forums-forum-{$this->id}" : "forums-new-forum" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'description' ) : NULL, 'minimize' => 'forum_description_placeholder' ) ) );
}
/**
* Class-specific routine when saving club form
*
* @param \IPS\Member\Club $club The club
* @param array $values Values
* @return void
*/
public function _saveClubForm( \IPS\Member\Club $club, $values )
{
if ( $values['club_node_name'] )
{
$this->name_seo = \IPS\Http\Url\Friendly::seoTitle( $values['club_node_name'] );
}
}
/* !Simple view */
/**
* Is simple view one? Calculates admin settings and user's choice
*
* @param \IPS\forums\Forum|NULL $forum The forum objectr
* @return boolean
*/
public static function isSimpleView( $forum=NULL )
{
$simpleView = false;
/* Clubs cannot be simple mode or it breaks out of the club container */
if ( $forum and $forum->club() )
{
return false;
}
/* Guests are locked to the admin choice */
if ( ! \IPS\Member::loggedIn()->member_id )
{
return \IPS\Settings::i()->forums_default_view === 'fluid' ? true : false;
}
if ( \IPS\Settings::i()->forums_default_view === 'fluid' )
{
$simpleView = true;
}
$method = static::getMemberView();
if ( $method !== 'fluid' )
{
$simpleView = false;
}
else if ( $method === 'fluid' )
{
$simpleView = true;
}
return $simpleView;
}
/**
* Get the member's view method
*
* @return string
*/
public static function getMemberView()
{
$method = ( isset( \IPS\Request::i()->cookie['forum_view'] ) ) ? \IPS\Request::i()->cookie['forum_view'] : NULL;
$chooseable = \IPS\Settings::i()->forums_default_view_choose ? json_decode( \IPS\Settings::i()->forums_default_view_choose , TRUE ) : FALSE;
if ( ! $chooseable )
{
return \IPS\Settings::i()->forums_default_view;
}
if ( ! $method )
{
try
{
$method = \IPS\Db::i()->select( 'method', 'forums_view_method', array( 'member_id=?', \IPS\Member::loggedIn()->member_id ) )->first();
/* Attempt to set the cookie again */
\IPS\Request::i()->setCookie( 'forum_view', $method, ( new \IPS\DateTime )->add( new \DateInterval( 'P1Y' ) ) );
}
catch( \UnderFlowException $e ){ }
}
if ( ! $method or ( $chooseable != '*' AND ! in_array( $method, $chooseable ) ) )
{
$method = \IPS\Settings::i()->forums_default_view;
}
return $method;
}
/**
* Get URL
*
* @return \IPS\Http\Url
*/
public function url()
{
if ( static::isSimpleView() and ! $this->club() )
{
return \IPS\Http\Url::internal( 'app=forums&module=forums&controller=index&forumId=' . $this->id, 'front', 'forums' );
}
return parent::url();
}
/**
* Get URL from index data
*
* @param array $indexData Data from the search index
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
* @return \IPS\Http\Url
*/
public static function urlFromIndexData( $indexData, $itemData, $containerData )
{
if ( static::isSimpleView() and ! $containerData['club_id'] )
{
return \IPS\Http\Url::internal( 'app=forums&module=forums&controller=index&forumId=' . $indexData['index_container_id'], 'front', 'forums' );
}
return parent::urlFromIndexData( $indexData, $itemData, $containerData );
}
}