Version 4.6.0

This commit is contained in:
Neo committed 2025-12-19 05:55:31 -08:00
1 parent f79dcf067a
commit 517a5e1f70
2036 files changed
+110041 -26162

No files matched your search

+98 -30
View File
@@ -25,7 +25,8 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
{
use \IPS\Content\ClubContainer;
use \IPS\Node\Colorize;
use \IPS\Node\Statistics;
/**
* @brief [ActiveRecord] Multiton Store
*/
@@ -304,7 +305,7 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
*/
public function get__sortBy()
{
return $this->sort_key;
return $this->sort_key ?: 'last_post';
}
/**
@@ -352,6 +353,7 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$this->last_title = $topic->title;
$this->seo_last_title = \IPS\Http\Url\Friendly::seoTitle( $this->last_title );
$this->last_id = $topic->tid;
$this->last_poster_anon = $topic->last_poster_anon;
return;
}
catch ( \UnderflowException $e )
@@ -361,6 +363,7 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$this->last_poster_name = '';
$this->last_title = NULL;
$this->last_id = NULL;
$this->last_poster_anon = 0;
return;
}
}
@@ -372,21 +375,24 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$this->last_title = $comment->item()->title;
$this->seo_last_title = \IPS\Http\Url\Friendly::seoTitle( $this->last_title );
$this->last_id = $comment->item()->tid;
$this->last_poster_anon = $comment->isAnonymous();
}
/**
* Get last comment time
*
* @note This should return the last comment time for this node only, not for children nodes
* @param \IPS\Member|NULL $member MemberObject
* @return \IPS\DateTime|NULL
*/
public function getLastCommentTime()
public function getLastCommentTime( \IPS\Member $member = NULL )
{
if( !$this->memberCanAccessOthersTopics( \IPS\Member::loggedIn() ) )
$member = $member ?: \IPS\Member::loggedIn();
if( !$this->memberCanAccessOthersTopics( $member ) )
{
try
{
$select = \IPS\Db::i()->select('*', 'forums_posts', array("forums_posts.queued=0 AND forums_topics.forum_id={$this->id} AND forums_topics.approved=1 AND forums_topics.starter_id=?", \IPS\Member::loggedIn()->member_id), 'forums_posts.post_date DESC', 1)->join('forums_topics', 'forums_topics.tid=forums_posts.topic_id')->first();
$select = \IPS\Db::i()->select('*', 'forums_posts', array("forums_posts.queued=0 AND forums_topics.forum_id={$this->id} AND forums_topics.approved=1 AND forums_topics.starter_id=?", $member->member_id), 'forums_posts.post_date DESC', 1)->join('forums_topics', 'forums_topics.tid=forums_posts.topic_id')->first();
}
catch ( \UnderflowException $e )
{
@@ -697,21 +703,24 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
if ( \in_array( $permissionCheck, array( 'read', 'add' ) ) )
{
$whereString = 'password=? OR ' . \IPS\Db::i()->findInSet( 'forums_forums.password_override', $member->groups );
$whereParams = array( NULL );
if ( $member->member_id === \IPS\Member::loggedIn()->member_id )
if ( static::hasPasswordForums() )
{
foreach ( \IPS\Request::i()->cookie as $k => $v )
$whereString = 'password=? OR ' . \IPS\Db::i()->findInSet( 'forums_forums.password_override', $member->groups );
$whereParams = array( NULL );
if ( $member->member_id === \IPS\Member::loggedIn()->member_id )
{
if ( mb_substr( $k, 0, 13 ) === 'ipbforumpass_' )
foreach ( \IPS\Request::i()->cookie as $k => $v )
{
$whereString .= ' OR ( forums_forums.id=? AND MD5(forums_forums.password)=? )';
$whereParams[] = (int) mb_substr( $k, 13 );
$whereParams[] = $v;
if ( mb_substr( $k, 0, 13 ) === 'ipbforumpass_' )
{
$whereString .= ' OR ( forums_forums.id=? AND MD5(forums_forums.password)=? )';
$whereParams[] = (int) mb_substr( $k, 13 );
$whereParams[] = $v;
}
}
}
$where[] = array_merge( array( '( ' . $whereString . ' )' ), $whereParams );
}
$where[] = array_merge( array( '( ' . $whereString . ' )' ), $whereParams );
}
return parent::loadIntoMemory( $permissionCheck, $member, $where );
@@ -897,7 +906,8 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
'category' => array(
"form_{$id}_tab_forum_display",
'forum_rules_title',
'forum_rules_text'
'forum_rules_text',
'forum_use_feature_color'
),
'redirect' => array(
'forum_password_on',
@@ -938,14 +948,14 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$form->add( new \IPS\Helpers\Form\Color( 'forum_feature_color', $this->feature_color ?: '', FALSE, array(), NULL, NULL, NULL, 'forum_feature_color' ) );
$form->add( new \IPS\Helpers\Form\Upload( 'forum_icon', $this->icon ? \IPS\File::get( 'forums_Icons', $this->icon ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'forums_Icons' ), NULL, NULL, NULL, 'forum_icon' ) );
$form->add( new \IPS\Helpers\Form\Upload( 'forum_card_image', $this->card_image ? \IPS\File::get( 'forums_Cards', $this->card_image ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'forums_Cards', 'allowStockPhotos' => TRUE ), NULL, NULL, NULL, 'forum_card_image' ) );
$form->add( new \IPS\Helpers\Form\Upload( 'forum_card_image', $this->card_image ? \IPS\File::get( 'forums_Cards', $this->card_image ) : NULL, FALSE, array( 'image' => array( 'maxWidth' => 800, 'maxHeight' => 800 ), 'storageExtension' => 'forums_Cards', 'allowStockPhotos' => TRUE ), NULL, NULL, NULL, 'forum_card_image' ) );
$form->add( new \IPS\Helpers\Form\Url( 'forum_redirect_url', $this->id ? $this->redirect_url : array(), FALSE, array( 'placeholder' => 'http://www.example.com/' ), NULL, NULL, NULL, 'forum_redirect_url' ) );
$form->add( new \IPS\Helpers\Form\Number( 'forum_redirect_hits', $this->id ? $this->redirect_hits : 0, FALSE, array(), NULL, NULL, NULL, 'forum_redirect_hits' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'forum_password_on', $this->id ? ( $this->password !== NULL ) : FALSE, FALSE, array( 'togglesOn' => array( 'forum_password', 'forum_password_override' ) ), NULL, NULL, NULL, 'forum_password_on' ) );
$form->add( new \IPS\Helpers\Form\Password( 'forum_password', $this->password, FALSE, array(), NULL, NULL, NULL, 'forum_password' ) );
$form->add( new \IPS\Helpers\Form\Select( 'forum_password_override', $this->id ? explode( ',', $this->password_override ) : array(), FALSE, array( 'options' => $groups, 'multiple' => TRUE ), NULL, NULL, NULL, 'forum_password_override' ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'forum_password_override', $this->id ? explode( ',', $this->password_override ) : array(), FALSE, array( 'options' => $groups, 'multiple' => TRUE ), NULL, NULL, NULL, 'forum_password_override' ) );
if ( \count( \IPS\Theme::themes() ) > 1 )
{
$themes = array( 0 => 'forum_skin_id_default' );
@@ -1018,8 +1028,8 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$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' ) );
$form->add( new \IPS\Helpers\Form\Select( 'forum_qa_rate_questions', $this->id ? ( ( $this->qa_rate_questions == '*' or $this->qa_rate_questions === NULL ) ? '*' : explode( ',', $this->qa_rate_questions ) ) : '*', FALSE, array( 'options' => $groupsNoGuests, 'unlimited' => '*', 'multiple' => TRUE ), NULL, NULL, NULL, 'forum_qa_rate_questions' ) );
$form->add( new \IPS\Helpers\Form\Select( 'forum_qa_rate_answers', $this->id ? ( ( $this->qa_rate_answers == '*' or $this->qa_rate_answers === NULL ) ? '*' : explode( ',', $this->qa_rate_answers ) ) : '*', FALSE, array( 'options' => $groupsNoGuests, 'unlimited' => '*', 'multiple' => TRUE ), NULL, NULL, NULL, 'forum_qa_rate_answers' ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'forum_qa_rate_questions', $this->id ? ( ( $this->qa_rate_questions == '*' or $this->qa_rate_questions === NULL ) ? '*' : explode( ',', $this->qa_rate_questions ) ) : '*', FALSE, array( 'options' => $groupsNoGuests, 'unlimited' => '*', 'multiple' => TRUE, 'impliedUnlimited' => TRUE ), NULL, NULL, NULL, 'forum_qa_rate_questions' ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'forum_qa_rate_answers', $this->id ? ( ( $this->qa_rate_answers == '*' or $this->qa_rate_answers === NULL ) ? '*' : explode( ',', $this->qa_rate_answers ) ) : '*', FALSE, array( 'options' => $groupsNoGuests, 'unlimited' => '*', 'multiple' => TRUE, 'impliedUnlimited' => TRUE ), NULL, NULL, NULL, 'forum_qa_rate_answers' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'forum_forum_allow_rating', $this->id ? $this->forum_allow_rating : FALSE, FALSE, array(), NULL, NULL, NULL, 'forum_allow_rating' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'forum_disable_sharelinks', $this->id ? !$this->disable_sharelinks : TRUE, FALSE, array(), NULL, NULL, NULL, 'forum_disable_sharelinks' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'bw_enable_answers_moderator', $this->id ? $this->forums_bitoptions['bw_enable_answers_moderator'] : FALSE, FALSE, array( 'togglesOn' => array( 'bw_enable_answers__member' ) ), NULL, NULL, NULL, 'forum_best_answer' ) );
@@ -1048,6 +1058,7 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'forum_preview_posts', $previewPosts, FALSE, array( 'options' => array( 'topics' => 'forum_preview_posts_topics', 'posts' => 'forum_preview_posts_posts' ) ), NULL, NULL, NULL, 'forum_preview_posts' ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'forum_preview_posts_qa', $previewPosts, FALSE, array( 'options' => array( 'topics' => 'forum_preview_posts_questions', 'posts' => 'forum_preview_posts_answers' ) ), NULL, NULL, NULL, 'forum_preview_posts_qa' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'forum_inc_postcount', $this->id ? $this->inc_postcount : TRUE, FALSE, array() ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'allow_anonymous', $this->id ? $this->allow_anonymous : FALSE, FALSE, array() ) );
$form->addHeader( 'polls' );
$form->add( new \IPS\Helpers\Form\YesNo( 'forum_allow_poll', $this->id ? $this->allow_poll : TRUE, FALSE, array() ) );
$form->addHeader( 'posting_requirements' );
@@ -1290,6 +1301,8 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
*/
public function postSaveForm( $values )
{
unset( \IPS\Data\Store::i()->forumsHavePasswords );
\IPS\File::claimAttachments( 'forums-new-forum', $this->id, NULL, 'description', TRUE );
\IPS\File::claimAttachments( 'forums-new-permerror', $this->id, NULL, 'permerror', TRUE );
\IPS\File::claimAttachments( 'forums-new-rules', $this->id, NULL, 'rules', TRUE );
@@ -1343,7 +1356,9 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
\IPS\File::get( 'forums_Icons', $this->icon )->delete();
}
catch( \Exception $ex ) { }
unset( \IPS\Data\Store::i()->forumsHavePasswords );
parent::delete();
foreach ( array( 'rules_title' => "forums_forum_{$this->id}_rulestitle", 'rules_text' => "forums_forum_{$this->id}_rules", 'permission_custom_error' => "forums_forum_{$this->id}_permerror" ) as $fieldKey => $langKey )
@@ -1386,6 +1401,7 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$oldId = $this->id;
$oldIcon = $this->icon;
$oldGridImage = $this->card_image;
$this->show_rules = 0;
@@ -1412,6 +1428,22 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
$this->save();
}
if ( $oldGridImage )
{
try
{
$gridImg = \IPS\File::get( 'forums_Cards', $oldGridImage );
$newImage = \IPS\File::create( 'forums_Cards', $gridImg->originalFilename, $gridImg->contents() );
$this->card_image = (string) $newImage;
}
catch ( \Exception $e )
{
$this->card_image = NULL;
}
$this->save();
}
}
/**
@@ -1449,7 +1481,7 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
{
$forumsTheMemberIsModeratorOf = $member->modPermission('forums');
if ( $forumsTheMemberIsModeratorOf === TRUE ) // All forums
if ( $forumsTheMemberIsModeratorOf === TRUE OR $forumsTheMemberIsModeratorOf == -1 ) // All forums
{
return TRUE;
}
@@ -1490,7 +1522,12 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
{
foreach ( \IPS\Db::i()->select( '*', 'core_moderators' ) as $moderator )
{
if ( $moderator['perms'] === '*' or \in_array( 'can_read_all_topics', explode( ',', $moderator['perms'] ) ) )
$json = json_decode( $moderator['perms'], TRUE );
if ( $moderator['perms'] === '*' OR
(
!empty( $json['can_read_all_topics'] ) AND ( isset( $json['forums'] ) AND ( $json['forums'] === -1 OR \in_array( $this->_id, $json['forums'] ) ) )
) )
{
if( $moderator['type'] === 'g' )
{
@@ -1503,7 +1540,7 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
}
}
}
$return = ( $normal == '*' ) ? array_unique( $return ) : array_intersect( explode( ',', $normal ), array_unique( $return ) );
if( \count( $members ) )
@@ -1761,9 +1798,10 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
* @apiresponse int id ID number
* @apiresponse string name Forum name
* @apiresponse string path Forum name including parents (e.g. "Example Category > Example Forum")
* @apiresponse string type The type of forum: "discussions", "questions", "category", or "redirect"
* @apiresponse int topics Number of topics in forum
* @apiresponse string url URL
* @apiresponse int|null parentId Parent Node ID
* @apiresponse int|null parentId Parent Node ID
* @clientapiresponse object|null permissions Node permissions
*/
public function apiOutput( \IPS\Member $authorizedMember = NULL )
@@ -1775,12 +1813,27 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
}
$path[] = $this->_title;
$type = 'discussions';
if ( $this->redirect_url )
{
$type = 'redirect';
}
elseif ( !$this->sub_can_post )
{
$type = 'category';
}
elseif ( $this->forums_bitoptions['bw_enable_answers'] )
{
$type = 'questions';
}
$return = array(
'id' => $this->id,
'name' => $this->_title,
'path' => implode( ' > ', $path ),
'topics' => $this->topics,
'url' => (string) $this->url(),
'id' => $this->id,
'name' => $this->_title,
'path' => implode( ' > ', $path ),
'type' => $type,
'topics' => $this->topics,
'url' => (string) $this->url(),
'parentId' => static::$databaseColumnParent ? $this->{static::$databaseColumnParent} : NULL
);
@@ -1963,6 +2016,21 @@ class _Forum extends \IPS\Node\Model implements \IPS\Node\Permissions
return $method;
}
/**
* Return if this forum has a password set or not
*
* @return boolean
*/
public static function hasPasswordForums()
{
if ( ! isset( \IPS\Data\Store::i()->forumsHavePasswords ) )
{
\IPS\Data\Store::i()->forumsHavePasswords = (bool) \IPS\Db::i()->select( 'COUNT(*)', 'forums_forums', array( 'password IS NOT NULL' ) )->first();
}
return \IPS\Data\Store::i()->forumsHavePasswords;
}
/**
* Get URL
*