Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions app/Concerns/RendersContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Concerns;

use DOMElement;
use App\Libraries\TextFormatter;
use DOMDocument;

Expand Down Expand Up @@ -36,14 +37,16 @@ public function render(): string
*/
public function stripAnchors(string $html): string
{
$xml = new DOMDocument();
$xml->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->loadHTML(mb_encode_numericentity($html, [0x80, 0x10FFFF, 0, ~0], 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

foreach ($xml->getElementsByTagName('a') as $anchor) {
$anchor->parentNode->replaceChild($xml->createTextNode($anchor->nodeValue), $anchor);
}

return $xml->saveHTML();
return html_entity_decode(
mb_decode_numericentity($xml->saveHTML(), [0x80, 0x10FFFF, 0, ~0], 'UTF-8')
);
}

/**
Expand All @@ -54,14 +57,19 @@ public function stripAnchors(string $html): string
*/
public function nofollowLinks(string $html): string
{
$xml = new DOMDocument();
$xml->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->loadHTML(mb_encode_numericentity($html, [0x80, 0x10FFFF, 0, ~0], 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

/**
* @var DOMElement $anchor
*/
foreach ($xml->getElementsByTagName('a') as $anchor) {
$anchor->setAttribute('rel', 'nofollow');
$anchor->setAttribute('target', '_blank');
}

return $xml->saveHTML();
return html_entity_decode(
mb_decode_numericentity($xml->saveHTML(), [0x80, 0x10FFFF, 0, ~0], 'UTF-8')
);
}
}
1 change: 0 additions & 1 deletion app/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Concerns\RendersContent;
use App\Libraries\TextFormatter;
use App\Models\ReactionModel;
use CodeIgniter\Database\RawSql;
use CodeIgniter\HTTP\Files\UploadedFile;
use CodeIgniter\Shield\Entities\Login;
use CodeIgniter\Shield\Entities\User as ShieldUser;
Expand Down
5 changes: 2 additions & 3 deletions app/Managers/CategoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Managers;

use App\Entities\Category;
use App\Entities\User;
use App\Models\CategoryModel;

class CategoryManager
Expand All @@ -16,7 +14,8 @@ public function loadCategoryPermissions(?int $categoryId = null, bool $permissio
$cacheKey = 'category-permissions-' . (int) $permissionsOnly;

if (! $permissions = cache($cacheKey)) {
$categories = model(CategoryModel::class)->findAllPermissions();
$permissions = [];
$categories = model(CategoryModel::class)->findAllPermissions();

foreach ($categories as $category) {
if ($permissionsOnly) {
Expand Down
16 changes: 12 additions & 4 deletions app/Models/CategoryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public function children()
*/
public function findAllNested(array $categoryIds): array
{
if ($categoryIds === []) {
return [[], []];
}

$selects = [
'categories.*',
'threads.title as last_thread_title',
Expand All @@ -87,17 +91,17 @@ public function findAllNested(array $categoryIds): array
->parents()
->whereIn("{$this->table}.id", $categoryIds)
->select(implode(', ', $selects))
->join('threads', 'threads.id = categories.last_thread_id')
->join('users', 'users.id = threads.author_id')
->join('threads', 'threads.id = categories.last_thread_id', 'LEFT')
->join('users', 'users.id = threads.author_id', 'LEFT')
->findAll();

$allChildren = $this
->active()
->children()
->whereIn("{$this->table}.id", $categoryIds)
->select(implode(', ', $selects))
->join('threads', 'threads.id = categories.last_thread_id')
->join('users', 'users.id = threads.author_id')
->join('threads', 'threads.id = categories.last_thread_id', 'LEFT')
->join('users', 'users.id = threads.author_id', 'LEFT')
->orderBy('order', 'asc')
->findAll();

Expand All @@ -109,6 +113,10 @@ public function findAllNested(array $categoryIds): array
*/
public function findAllNestedDropdown(array $categoryIds): array
{
if ($categoryIds === []) {
return [];
}

$selects = [
'id', 'title', 'parent_id', 'permissions',
];
Expand Down
2 changes: 2 additions & 0 deletions app/Views/pager/default_full.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$pager->setSurroundCount(2);
?>

<?php if ($pager->getPageCount() > 1): ?>
<nav aria-label="<?= lang('Pager.pageNavigation') ?>">
<div class="join">
<?php if ($pager->hasPrevious()) : ?>
Expand Down Expand Up @@ -35,3 +36,4 @@
<?php endif ?>
</div>
</nav>
<?php endif; ?>
6 changes: 6 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,9 @@ imageupload.fileSize = 2048
#--------------------------------------------------------------------

# curlrequest.shareOptions = true

#--------------------------------------------------------------------
# Cache
#--------------------------------------------------------------------

cache.handler = file
2 changes: 1 addition & 1 deletion themes/admin/_top_nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</div>

<!-- Site Name -->
<a class="btn btn-ghost normal-case text-xl text-primary-content">
<a href="<?= site_url() ?>" class="btn btn-ghost normal-case text-xl text-primary-content">
<?= config('App')->siteName ?>
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/default/_app_nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</div>

<!-- Site Name -->
<a class="btn btn-ghost normal-case text-xl text-primary-content">
<a href="<?= site_url() ?>" class="btn btn-ghost normal-case text-xl text-primary-content">
<?= config('App')->siteName ?>
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/default/discussions/threads/_thread.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="thread px-6 pb-4">
<div id="thread" class="thread px-6 pb-4">
<h3 class="text-3xl leading-loose font-bold pb-2">
<a href="<?= esc($thread->link(), 'attr') ?>">
<?= esc($thread->title) ?>
Expand Down
Loading