Fixed a lot of responsive problems.
- Fixed auth problem - Fixed BBCode and Markdown apparition in some unnecessary parts
This commit is contained in:
@@ -64,6 +64,19 @@ class XenForoGuard implements Guard
|
||||
if ($this->hasUser())
|
||||
return $this->user;
|
||||
|
||||
$user = $this->getFromSession();
|
||||
if( $user )
|
||||
return $user;
|
||||
|
||||
$user = $this->getFromCookie();
|
||||
if( $user )
|
||||
return $user;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getFromSession(): ?XenForoUser
|
||||
{
|
||||
$sessionId = $this->request->cookie('xf_session');
|
||||
if(!$sessionId)
|
||||
return null;
|
||||
@@ -92,6 +105,64 @@ class XenForoGuard implements Guard
|
||||
return $this->user = new XenForoUser($xfUser);
|
||||
}
|
||||
|
||||
private function isCorrectCookieKey(string $key, $record): bool
|
||||
{
|
||||
$known = $record->remember_key;
|
||||
if( !$known )
|
||||
return false;
|
||||
|
||||
$check = hash('sha256', $key, true);
|
||||
return hash_equals($known, $check);
|
||||
}
|
||||
|
||||
private function getFromCookie(): ?XenForoUser
|
||||
{
|
||||
$cookie = $this->request->cookie('xf_user');
|
||||
if(!$cookie)
|
||||
return null;
|
||||
|
||||
$parts = explode(',', $cookie);
|
||||
if( count( $parts ) !== 2 )
|
||||
return null;
|
||||
|
||||
[$userId, $key] = $parts;
|
||||
$userId = (int) $userId;
|
||||
|
||||
if( !$userId || !$key )
|
||||
return null;
|
||||
|
||||
$remembers = \DB::connection('xenforo')
|
||||
->table('user_remember')
|
||||
->where('user_id', $userId)
|
||||
->get();
|
||||
|
||||
if( !$remembers )
|
||||
return null;
|
||||
|
||||
$valid = false;
|
||||
|
||||
foreach( $remembers as $remember )
|
||||
{
|
||||
if( $this->isCorrectCookieKey($key, $remember) && $remember->expiry_date >= time() ){
|
||||
$valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !$valid )
|
||||
return null;
|
||||
|
||||
$xfUser = \DB::connection('xenforo')
|
||||
->table('user')
|
||||
->where('user_id', $userId)
|
||||
->first();
|
||||
|
||||
if(!$xfUser)
|
||||
return null;
|
||||
|
||||
return $this->user = new XenForoUser($xfUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused.
|
||||
*
|
||||
|
||||
@@ -125,4 +125,18 @@ class EntryHelpers {
|
||||
session(["downloaded_file_{$entryFile->file_uuid}" => 1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function stripBbCode(?string $text): ?string
|
||||
{
|
||||
if ($text === null) return null;
|
||||
$text = preg_replace('/\[quote\b[^\]]*\](.*?)\[\/quote\]/is', '', $text);
|
||||
return preg_replace('/\[\/?\w+[^\]]*\]/i', '', $text);
|
||||
}
|
||||
|
||||
public static function stripMarkdown(?string $text): ?string
|
||||
{
|
||||
if ($text === null) return null;
|
||||
$html = Str::markdown($text);
|
||||
return html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Models\Entry;
|
||||
use App\Models\EntryReview;
|
||||
use App\Models\News;
|
||||
@@ -65,7 +66,7 @@ class ActivityService
|
||||
'user_id' => $entry->user_id,
|
||||
'badge' => EntryCard::ENTRY_TYPES_BADGE[$entry->type],
|
||||
'badge_class' => $entry->type,
|
||||
'excerpt' => $entry->description ? \Str::limit(strip_tags($entry->description), 80) : null,
|
||||
'excerpt' => $entry->description ? \Str::limit(EntryHelpers::stripMarkdown(strip_tags($entry->description)), 80) : null,
|
||||
'meta' => $entry->getRealPlatform()?->name
|
||||
];
|
||||
}
|
||||
@@ -82,7 +83,7 @@ class ActivityService
|
||||
'user_id' => $news->user_id,
|
||||
'badge' => 'News',
|
||||
'badge_class' => 'news',
|
||||
'excerpt' => $news->description ? \Str::limit(strip_tags($news->description), 80) : null,
|
||||
'excerpt' => $news->description ? \Str::limit(EntryHelpers::stripMarkdown(strip_tags($news->description)), 80) : null,
|
||||
'meta' => $news->category?->name
|
||||
];
|
||||
}
|
||||
@@ -99,7 +100,7 @@ class ActivityService
|
||||
'user_id' => $message->user_id,
|
||||
'badge' => 'Post',
|
||||
'badge_class' => 'message',
|
||||
'excerpt' => $message->message ? \Str::limit(strip_tags($message->message), 80) : null,
|
||||
'excerpt' => $message->message ? \Str::limit(EntryHelpers::stripBbCode(strip_tags($message->message)), 80) : null,
|
||||
'meta' => null
|
||||
];
|
||||
|
||||
@@ -117,7 +118,7 @@ class ActivityService
|
||||
'user_id' => $thread->user_id,
|
||||
'badge' => 'Thread',
|
||||
'badge_class' => 'thread',
|
||||
'excerpt' => $thread->message ? \Str::limit(strip_tags($thread->message), 80) : null,
|
||||
'excerpt' => $thread->message ? \Str::limit(EntryHelpers::stripBbCode(strip_tags($thread->message)), 80) : null,
|
||||
'meta' => null
|
||||
];
|
||||
|
||||
@@ -152,7 +153,7 @@ class ActivityService
|
||||
'user_id' => $review->user_id,
|
||||
'badge' => 'Review',
|
||||
'badge_class' => 'review',
|
||||
'excerpt' => $review->description ? \Str::limit(strip_tags($review->description), 80) : null,
|
||||
'excerpt' => $review->description ? \Str::limit(EntryHelpers::stripMarkdown(strip_tags($review->description)), 80) : null,
|
||||
'meta' => $review->entry()->exists() ? ( $review->entry->complete_title ?? $review->entry->title ) : null,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user