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

@@ -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
*