Version 5.0.13

This commit is contained in:
Neo committed 2025-12-19 19:04:57 -08:00
1 parent b89858b2ff
commit 5efe744c5f
1407 files changed
+69690 -30177

No files matched your search

@@ -16,9 +16,11 @@ namespace IPS\forums\modules\admin\forums;
use DomainException;
use Exception;
use IPS\Application;
use IPS\Content\Tag;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\forums\Forum;
use IPS\forums\Topic;
use IPS\Helpers\Form;
use IPS\Helpers\Form\CheckboxSet;
@@ -33,12 +35,11 @@ use IPS\Http\Url;
use IPS\IPS;
use IPS\Member;
use IPS\Output;
use IPS\Platform\Bridge;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Request;
use IPS\Session;
use IPS\Settings as SettingsClass;
use IPS\Theme;
use LengthException;
use function count;
use function defined;
use function in_array;
@@ -79,6 +80,10 @@ class settings extends Controller
{
$tabs['archiving'] = 'archiving';
}
if( Member::loggedIn()->hasAcpRestriction( 'forums', 'forums', 'autolock_settings' ) )
{
$tabs['autolock'] = 'autolock';
}
$activeTab = Request::i()->tab ?: 'settings';
$methodFunction = 'manage' . IPS::mb_ucfirst( $activeTab );
@@ -94,7 +99,7 @@ class settings extends Controller
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, Url::internal( "app=forums&module=forums&controller=settings" ) );
}
}
/**
* Archive settings
*
@@ -164,7 +169,6 @@ class settings extends Controller
case 'post':
case 'view':
case 'rating':
if ( $rule['archive_skip'] )
{
$existingValues[ "archive_not_topic_{$rule['archive_field']}" ] = array( $rule['archive_value'], $rule['archive_text'], FALSE );
@@ -209,12 +213,10 @@ class settings extends Controller
'archive_topic_poll',
'archive_topic_post',
'archive_topic_view',
'archive_topic_rating',
'archive_topic_starter',
'archive_topic_not_forums',
'archive_not_topic_post',
'archive_not_topic_view',
'archive_not_topic_rating',
'archive_not_last_post',
'archive_topic_starter_not',
'form_header_archive_topics_where',
@@ -249,7 +251,6 @@ class settings extends Controller
$form->add( new CheckboxSet( 'archive_topic_poll', $existingValues['archive_topic_poll'] ?? array( 1, 0 ), FALSE, array( 'options' => array( 1 => 'topic_has_poll', 0 => 'topic_does_not_have_poll' ) ), NULL, NULL, NULL, 'archive_topic_poll' ) );
$form->add( new Custom( 'archive_topic_post', $existingValues['archive_topic_post'] ?? array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_topic_post' ) );
$form->add( new Custom( 'archive_topic_view', $existingValues['archive_topic_view'] ?? array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_topic_view' ) );
$form->add( new Custom( 'archive_topic_rating', $existingValues['archive_topic_rating'] ?? array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_topic_rating' ) );
$form->add( new FormMember( 'archive_topic_starter', $existingValues['archive_topic_starter'] ?? array(), FALSE, array( 'multiple' => 999999 ), NULL, NULL, NULL, 'archive_topic_starter' ) );
$form->addHeader( 'archive_topics_not_where' );
$form->add( new Node( 'archive_topic_not_forums', $existingValues['archive_topic_not_forums'] ?? array(), FALSE, array( 'class' => 'IPS\forums\Forum', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
@@ -258,7 +259,6 @@ class settings extends Controller
} ), NULL, NULL, NULL, 'archive_topic_not_forums' ) );
$form->add( new Custom( 'archive_not_topic_post', $existingValues['archive_not_topic_post'] ?? array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_not_topic_post' ) );
$form->add( new Custom( 'archive_not_topic_view', $existingValues['archive_not_topic_view'] ?? array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_not_topic_view' ) );
$form->add( new Custom( 'archive_not_topic_rating', $existingValues['archive_not_topic_rating'] ?? array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_not_topic_rating' ) );
$form->add( new Custom( 'archive_not_last_post', $existingValues['archive_not_last_post'] ?? array( '>', 0, 'm', TRUE ), FALSE, array( 'getHtml' => array( $this, '_beforeAfterTimeAgo' ), 'validate' => array( $this, '_validateBeforeAfterTimeAgo' ) ), NULL, NULL, NULL, 'archive_not_last_post' ) );
$form->add( new FormMember( 'archive_topic_starter_not', $existingValues['archive_topic_starter_not'] ?? array(), FALSE, array( 'multiple' => 999999 ), NULL, NULL, NULL, 'archive_topic_starter_not' ) );
@@ -344,7 +344,7 @@ class settings extends Controller
);
}
}
elseif( in_array( $k, array( 'archive_topic_post', 'archive_topic_view', 'archive_topic_rating' ) ) )
elseif( in_array( $k, array( 'archive_topic_post', 'archive_topic_view' ) ) )
{
if ( !isset( $v[2] ) and $v[1] and $v[0] )
{
@@ -359,7 +359,7 @@ class settings extends Controller
);
}
}
elseif( in_array( $k, array( 'archive_not_topic_post', 'archive_not_topic_view', 'archive_not_topic_rating' ) ) )
elseif( in_array( $k, array( 'archive_not_topic_post', 'archive_not_topic_view' ) ) )
{
if ( !isset( $v[2] ) and $v[1] and $v[0] )
{
@@ -641,11 +641,6 @@ class settings extends Controller
$form->add( new Number( 'forums_solved_topic_reengage', SettingsClass::i()->forums_solved_topic_reengage , FALSE, array( 'min' => 1, 'max' => 365, 'unlimited' => 0, 'unlimitedLang' => 'forums_solved_topic_reengage_never' ), NULL, Member::loggedIn()->language()->addToStack('forums_solved_nudge_experts_prefix'), Member::loggedIn()->language()->addToStack('forums_solved_nudge_experts_suffix') ) );
$form->add( new Number( 'forums_helpful_highlight', SettingsClass::i()->forums_helpful_highlight , FALSE, array( 'min' => 1, 'unlimited' => 0, 'unlimitedLang' => 'forums_helpful_highlight_never' ), NULL, Member::loggedIn()->language()->addToStack('forums_helpful_highlight_prefix'), Member::loggedIn()->language()->addToStack('forums_helpful_highlight_suffix') ) );
if( Bridge::i()->featureIsEnabled( 'experts' ) )
{
$form->add( new Number( 'forums_solved_nudge_experts', SettingsClass::i()->forums_solved_nudge_experts, FALSE, array( 'min' => 1, 'max' => 365, 'unlimited' => 0, 'unlimitedLang' => 'forums_solved_nudge_experts_never' ), NULL, Member::loggedIn()->language()->addToStack('forums_solved_topic_reengage_prefix'), Member::loggedIn()->language()->addToStack('forums_solved_topic_reengage_suffix') ) );
}
$form->add( new YesNo( "forum_post_use_minimal_editor", (bool) SettingsClass::i()->forum_post_use_minimal_editor, false ) );
$form->addHeader('topic_overview_settings');
@@ -699,4 +694,93 @@ class settings extends Controller
return $form;
}
/**
* Auto-Lock topics settings
*
* @return Form|string
*/
protected function manageAutolock() : Form|string
{
$settings = SettingsClass::i()->autolock_topic_settings ? json_decode( SettingsClass::i()->autolock_topic_settings, true ) : [];
$form = new Form;
$form->add( new YesNo( 'autolock_enabled', $settings['enabled'] ?? null, false, [
'togglesOn' => [ 'autolock_days', 'autolock_pinned', 'autolock_featured', 'autolock_forums', 'autolock_members', 'autolock_tags' ]
] ) );
$form->add( new Number( 'autolock_days', $settings['days'] ?? 7, null, suffix: Member::loggedIn()->language()->addToStack( 'autolock_days_suffix' ), id: 'autolock_days' ) );
$form->add( new YesNo( 'autolock_pinned', $settings['pinned'] ?? false, false, id: 'autolock_pinned' ) );
$form->add( new YesNo( 'autolock_featured', $settings['featured'] ?? false, id: 'autolock_featured' ) );
$form->add( new Node( 'autolock_forums', $settings['forums'] ?? null, false, [
'class' => Forum::class,
'multiple' => true
], id: 'autolock_forums' ) );
$excludedMembers = [];
if( !empty( $settings['members'] ) )
{
$excludedMembers = iterator_to_array(
new ActiveRecordIterator(
Db::i()->select( '*', 'core_members', Db::i()->in( 'member_id', $settings['members'] ) ),
Member::class
)
);
}
$form->add( new FormMember( 'autolock_members', count( $excludedMembers ) ? $excludedMembers : null, false, [ 'multiple' => null ], id: 'autolock_members' ) );
$form->add( new Text( 'autolock_tags', $settings['tags'] ?? null, false, [
'autocomplete' => array(
'unique' => TRUE,
'source' => Tag::allTags(),
'resultItemTemplate' => 'core.autocomplete.tagsResultItem',
'freeChoice' => false,
'minimized' => false,
'alphabetical' => true,
'addTokenText' => Member::loggedIn()->language()->get( 'tags_optional' ),
)
], id: 'autolock_tags' ) );
if( $values = $form->values() )
{
if( $values['autolock_enabled'] )
{
$members = FormMember::stringValue( $values['autolock_members'] );
$settings = [
'enabled' => true,
'days' => $values['autolock_days'],
'pinned' => $values['autolock_pinned'],
'featured' => $values['autolock_featured'],
'members' => ( $members ? explode( "\n", $members ) : null ),
'forums' => ( !empty( $values['autolock_forums'] ) ? array_keys( $values['autolock_forums'] ) : null ),
'tags' => $values['autolock_tags']
];
}
else
{
$settings = [ 'enabled' => false ];
}
$form->saveAsSettings([
'autolock_topic_settings' => json_encode( $settings )
]);
Session::i()->log( 'acplogs__forums_autolock' );
/* And disable task if this feaure is disabled */
if( !$values['autolock_enabled'] )
{
Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'autolock' ) );
}
/* Or enable it if necessary */
else
{
Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'autolock' ) );
}
Output::i()->redirect( Url::internal( 'app=forums&module=forums&controller=settings&tab=autolock' ), 'saved' );
}
return $form;
}
}
@@ -68,7 +68,8 @@ class forums extends Controller
* @return void
*/
protected function manage() : void
{
{
Output::i()->bodyAttributes['contentClass'] = ForumClass::class;
$forum = NULL;
try
{
@@ -538,7 +539,7 @@ class forums extends Controller
}
/* Data Layer Context */
if ( !Request::i()->isAjax AND Settings::i()->core_datalayer_enabled )
if ( !Request::i()->isAjax AND DataLayer::enabled() )
{
foreach ( $forum->getDataLayerProperties() as $key => $value )
{
@@ -47,6 +47,7 @@ use function count;
use function defined;
use function in_array;
use function intval;
use function is_numeric;
use const IPS\LARGE_TOPIC_REPLIES;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
@@ -281,12 +282,12 @@ class topic extends Controller
}
array_unshift( $paginationKeys, 'queued_posts' );
$customPaginationWhere[] = array( 'topic_id=? AND queued=1', $topic->id );
$customPaginationWhere[] = array( 'topic_id=? AND queued=1', $topic->tid );
}
$customPaginationWhere = Bridge::i()->modifyTopicCommentFilter( $topic, $customPaginationWhere );
if ( !empty( $customPaginationWhere ) )
{
$customPaginationWhere[] = array( "topic_id=?", $topic->id );
$customPaginationWhere[] = array( "topic_id=?", $topic->tid );
$authorCol = Post::$databasePrefix . Post::$databaseColumnMap['author'];
if ( $topic->canViewHiddenComments() )
{
@@ -393,9 +394,6 @@ class topic extends Controller
/* A convenient hook point to do any further set up */
$this->finishManage( $topic );
$votes = array();
$topicVotes = array();
/* Online User Location */
Session::i()->setLocation( $topic->url(), ( $topic->container()->password or !$topic->container()->can_view_others ) ? 0 : $topic->onlineListPermissions(), 'loc_forums_viewing_topic', array( $topic->title => FALSE ) );
@@ -473,7 +471,6 @@ class topic extends Controller
'text' => $truncatedAnswer,
'url' => (string) $answer->url(),
'dateCreated' => DateTime::ts( $answer->$dateColumn )->format( DateTimeInterface::ATOM ),
'upvoteCount' => ( $topic->isArchived() ) ? $answer->field_int : $answer->post_field_int,
'author' => array(
'@type' => 'Person',
'name' => Member::load( $answer->$authorIdColumn )->name,
@@ -506,7 +503,6 @@ class topic extends Controller
'text' => $lastComment->truncated( TRUE, NULL ),
'url' => (string) $lastComment->url(),
'dateCreated' => DateTime::ts( $lastComment->$dateColumn )->format( DateTime::ISO8601 ),
'upvoteCount' => ( $topic->isArchived() ) ? $lastComment->field_int : $lastComment->post_field_int,
'author' => array(
'@type' => 'Person',
'name' => Member::load( $lastComment->$authorIdColumn )->name,
@@ -576,7 +572,11 @@ class topic extends Controller
if ( $truncatedComment = $comment->truncated( TRUE, NULL ) )
{
$url = $topic->url()->setPage( 'page', Request::i()->page );
$url = $topic->url();
if( isset( Request::i()->page ) and is_numeric( Request::i()->page ) )
{
$url = $url->setPage( 'page', Request::i()->page );
}
$commentJson[$i] = array(
'@type' => $isQuestion ? 'Answer' : 'Comment',
@@ -597,14 +597,7 @@ class topic extends Controller
$commentJson[$i]['author']['url'] = (string)Member::load( $comment->$authorIdColumn )->url();
}
if( $isQuestion )
{
$commentJson[$i]['upvoteCount'] = ( $topic->isArchived() ) ? $comment->field_int : $comment->post_field_int;
}
else
{
$commentJson[$i]['upvoteCount'] = $comment->reactionCount();
}
$commentJson[$i]['upvoteCount'] = $comment->reactionCount();
$i++;
}
@@ -649,6 +642,13 @@ class topic extends Controller
$current = $firstPost;
}
/* Set og:image meta tags */
if( count( $file = $topic->imageAttachments(1 ) ) )
{
$object = File::get( 'core_Attachment', $file[0]['attach_location'] );
Output::i()->metaTags['og:image'] = (string) $object->url->setScheme( ( mb_substr( Settings::i()->base_url, 0, 5 ) === 'https' ) ? 'https' : 'http' );
}
if( $current )
{
Output::i()->jsonLd['topic'] = array_merge_recursive( array(
@@ -658,8 +658,6 @@ class topic extends Controller
'dateCreated' => DateTime::ts( $topic->start_date )->format( DateTimeInterface::ATOM ),
'datePublished' => DateTime::ts( $topic->start_date )->format( DateTimeInterface::ATOM ),
'dateModified' => DateTime::ts( $topic->last_post )->format( DateTimeInterface::ATOM ),
/* Image is required, but we don't have "topic images", so we'll use topic starter's profile photo for now */
'image' => (string) Member::load( $topic->starter_id )->get_photo( TRUE, TRUE ),
'author' => array(
'@type' => 'Person',
'name' => Member::load( $topic->starter_id )->name,
@@ -678,6 +676,11 @@ class topic extends Controller
)
)
), Output::i()->jsonLd['topic'] );
if( isset( Output::i()->metaTags['og:image'] ) )
{
Output::i()->jsonLd['topic']['image'] = Output::i()->metaTags['og:image'];
}
}
if( !$topic->isArchived() )
@@ -689,13 +692,6 @@ class topic extends Controller
];
}
/* Add og:image meta tags */
if( count( $file = $topic->imageAttachments(1 ) ) )
{
$object = File::get( 'core_Attachment', $file[0]['attach_location'] );
Output::i()->metaTags['og:image'] = (string) $object->url->setScheme( ( mb_substr( Settings::i()->base_url, 0, 5 ) === 'https' ) ? 'https' : 'http' );
}
/* Noindex if helpful filter applied */
if( isset( Request::i()->show ) )
{
@@ -707,7 +703,7 @@ class topic extends Controller
/* Show topic */
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'topics.css', 'forums' ) );
Output::i()->output .= Theme::i()->getTemplate( 'topics' )->topic( $topic, $comments, $votes, $nextUnread, $pagination, $topicVotes, $firstPost, $viewerIsFollowingTheseExperts );
Output::i()->output .= Theme::i()->getTemplate( 'topics' )->topic( $topic, $comments, $nextUnread, $pagination, $firstPost, $viewerIsFollowingTheseExperts );
return null;
}
@@ -917,128 +913,6 @@ class topic extends Controller
Output::i()->redirect( $topic->url() );
}
/**
* Rate Question
*
* @return void
*/
public function rateQuestion() : void
{
/* CSRF Check */
Session::i()->csrfCheck();
/* Get the question */
try
{
$question = TopicClass::loadAndCheckPerms( Request::i()->id );
}
catch ( OutOfRangeException $e )
{
Output::i()->error( 'node_error', '2F173/8', 404, '' );
}
/* Voting up or down? */
$rating = intval( Request::i()->rating );
if ( $rating !== 1 and $rating !== -1 )
{
Output::i()->error( 'form_bad_value', '2F173/A', 403, '' );
}
/* Check we can cast this vote */
if ( !$question->canVote( $rating ) )
{
Output::i()->error( 'no_module_permission', '2F173/9', 403, '' );
}
/* If we have an existing vote, remove it first */
$ratings = $question->votes();
if ( isset( $ratings[ Member::loggedIn()->member_id ] ) )
{
Db::i()->delete( 'forums_question_ratings', array( 'topic=? AND `member`=?', $question->tid, Member::loggedIn()->member_id ) );
}
/* Revoting for the same thing you already voted for should remove your vote - so don't insert if we voted for the same thing we did before */
if ( !isset( $ratings[ Member::loggedIn()->member_id ] ) OR $ratings[ Member::loggedIn()->member_id ] != $rating )
{
Db::i()->insert( 'forums_question_ratings', array(
'topic' => $question->tid,
'forum' => $question->forum_id,
'member' => Member::loggedIn()->member_id,
'rating' => $rating,
'date' => time()
), TRUE );
}
/* Rebuild count */
$question->question_rating = Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $question->tid ), NULL, NULL, NULL, NULL, Db::SELECT_FROM_WRITE_SERVER )->first();
$question->save();
/* Redirect back */
Output::i()->redirect( $question->url() );
}
/**
* Rate Answer
*
* @return void
*/
public function rateAnswer() : void
{
Session::i()->csrfCheck();
try
{
$question = TopicClass::loadAndCheckPerms( Request::i()->id );
$answer = Post::loadAndCheckPerms( Request::i()->answer );
}
catch ( Exception $e )
{
Output::i()->error( 'node_error', '2F173/4', 404, '' );
}
$rating = intval( Request::i()->rating );
if ( !$answer->item()->can('read') or !$answer->canVote( $rating ) )
{
Output::i()->error( 'no_module_permission', '2F173/5', 403, '' );
}
$rating = intval( Request::i()->rating );
if ( $rating !== 1 and $rating !== -1 )
{
Output::i()->error( 'form_bad_value', '2F173/6', 403, '' );
}
$ratings = $question->answerVotes( Member::loggedIn() );
/* If we've already rated the answer, remove that first */
Db::i()->delete( 'forums_answer_ratings', array( 'topic=? AND post=? AND `member`=?', $question->tid, $answer->pid, Member::loggedIn()->member_id ) );
/* Revoting for the same thing you already voted for should remove your vote - so don't insert if we voted for the same thing we did before */
if ( !isset( $ratings[ $answer->pid ] ) OR $ratings[ $answer->pid ] != $rating )
{
Db::i()->insert( 'forums_answer_ratings', array(
'post' => $answer->pid,
'topic' => $question->tid,
'member' => Member::loggedIn()->member_id,
'rating' => $rating,
'date' => time()
), TRUE );
}
$answer->post_field_int = (int) Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $answer->pid ), NULL, NULL, NULL, NULL, Db::SELECT_FROM_WRITE_SERVER )->first();
$answer->save();
if ( Request::i()->isAjax() )
{
Output::i()->json( array( 'votes' => $answer->post_field_int, 'canVoteUp' => $answer->canVote(1), 'canVoteDown' => $answer->canVote(-1) ) );
}
else
{
Output::i()->redirect( $answer->url() );
}
}
/**
* Set Best Answer
*