forked from FriendsOfFlarum/sitemap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aecb314
commit 7144757
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/sitemap. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
*/ | ||
|
||
namespace FoF\Sitemap\Listeners; | ||
|
||
use Flarum\Frontend\Document; | ||
use Flarum\Settings\SettingsRepositoryInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Flarum\Extension\ExtensionManager; | ||
use Illuminate\Support\Arr; | ||
|
||
class NoIndexListener | ||
{ | ||
public function __construct(protected ExtensionManager $extensionManager) | ||
{} | ||
|
||
public function __invoke(Document $document, ServerRequestInterface $request) | ||
{ | ||
$noIndexTags = [38, 33, 35, 36]; // Add tags here so their discussions include the no-index | ||
|
||
if( ! $this->extensionManager->isEnabled('flarum-tags')){ | ||
return; | ||
} | ||
|
||
$type = Arr::get($document->getForumApiDocument(), 'data.type'); | ||
|
||
if($type != 'discussions'){ | ||
return; | ||
} | ||
|
||
$tags = Arr::get($document->getForumApiDocument(), 'data.relationships.tags.data'); | ||
|
||
foreach($tags as $tag){ | ||
if(in_array($tag['id'], $noIndexTags)){ | ||
$document->head[] = '<meta name="robots" content="noindex">'; | ||
return; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters