Skip to content

Commit

Permalink
Merge pull request #58 from v17development/dev
Browse files Browse the repository at this point in the history
Version 1.8.0
  • Loading branch information
jaspervriends authored May 29, 2021
2 parents 877e8bb + f4dd395 commit cbbe884
Show file tree
Hide file tree
Showing 9 changed files with 1,174 additions and 651 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
},
"require": {
"flarum/core": "^0.1.0-beta.16",
"flarum/core": "^1.0.0",
"ext-json": "*"
},
"conflict": {
Expand Down
6 changes: 0 additions & 6 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
namespace V17Development\FlarumSeo;

use Flarum\Extend;
use Extend\Locales;
use Extend\Routes;
use Illuminate\Contracts\Events\Dispatcher;
use V17Development\FlarumSeo\ConfigureLinks;
use V17Development\FlarumSeo\Api\DeleteSocialMediaImageController;
use V17Development\FlarumSeo\Api\UploadSocialMediaImageController;
use V17Development\FlarumSeo\Controller\Robots;
use V17Development\FlarumSeo\Formatter\FormatLinks;
use V17Development\FlarumSeo\Listeners\PageListener;
use V17Development\FlarumSeo\Listeners\BeforePageRenders;

return [
(new Extend\Frontend('forum'))
Expand All @@ -31,6 +27,4 @@
(new Extend\Formatter)
->render(FormatLinks::class)
->configure(ConfigureLinks::class),

// new BeforePageRenders()
];
2 changes: 1 addition & 1 deletion js/dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

1,759 changes: 1,135 additions & 624 deletions js/package-lock.json

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions src/Controller/Robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

use Flarum\Settings\SettingsRepositoryInterface;

use Illuminate\View\Factory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Laminas\Diactoros\Response;
use Flarum\Http\UrlGenerator;

/**
* Class Robots
Expand All @@ -16,14 +16,19 @@
class Robots implements RequestHandlerInterface
{
protected $settings;
protected $url;

/**
* Robots constructor.
* @param SettingsRepositoryInterface $settings
*/
public function __construct(SettingsRepositoryInterface $settings)
public function __construct(
SettingsRepositoryInterface $settings,
UrlGenerator $url
)
{
$this->settings = $settings;
$this->url = $url;
}

/**
Expand All @@ -44,9 +49,7 @@ private function output()
// If sitemap extension is enabled, add sitemap.xml
if (in_array('fof-sitemap', $extensionsEnabled))
{
$url = app('flarum.config')['url'];

$output .= PHP_EOL . "Sitemap: ". $url ."/sitemap.xml" . PHP_EOL;
$output .= PHP_EOL . "Sitemap: ". $this->url->to('forum')->base() . "/sitemap.xml" . PHP_EOL;
}

// Custom robots txt
Expand Down
27 changes: 20 additions & 7 deletions src/Formatter/FormatLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class FormatLinks
protected $settings;

/**
* @var internalDomain array
* @var string Current domain
*/
protected $internalDomain = [];
protected $internalDomain = '';

/**
* @var urls
* @var array List of allowed links to follow
*/
protected $doFollowList = [];

Expand Down Expand Up @@ -72,7 +72,7 @@ public function __invoke(Renderer $renderer, $context, $xml, Request $request =

/**
* Do we need to add a nofollow to this link?
*
*
* @param string $domain
*/
private function addNofollow(string $domain) {
Expand All @@ -81,7 +81,7 @@ private function addNofollow(string $domain) {

/**
* Is the link an internal link?
*
*
* @param string $domain
*/
private function openInNewTab(string $domain) {
Expand All @@ -108,7 +108,20 @@ private function urlToDomain($url) {
return '';
}

// Strip subdomains
return implode('.', array_slice(explode(".", $url['host']), -2, 2, true));
$domain = $url['host'];

// Strip subdomains if Flarum is not installed in a subdomain
if (!empty($this->internalDomain) && $this->isSubdomain($domain) && $domain !== $this->internalDomain) {
$domain = implode('.', array_slice(explode(".", $domain), -2, 2, true));
}

return $domain;
}

/**
* Check if this domain is a subdomain
*/
private function isSubdomain($domain) {
return substr_count($domain, '.') > 1;
}
}
9 changes: 4 additions & 5 deletions src/Managers/Profile.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace V17Development\FlarumSeo\Managers;

use Flarum\Discussion\DiscussionRepository;
use Flarum\User\UserRepository;
use Symfony\Contracts\Translation\TranslatorInterface;
use V17Development\FlarumSeo\Listeners\PageListener;
Expand Down Expand Up @@ -68,14 +67,14 @@ private function createTags($user)

// Profile title
$profileTitle = $this->translator->trans("v17development-flarum-seo.forum.profile_title", [
'{username}' => $user->getAttribute('display_name'),
'username' => $user->getAttribute('display_name'),
]);

// Profile description
$profileDescription = $this->translator->trans("v17development-flarum-seo.forum.profile_description", [
'{username}' => $user->getAttribute('display_name'),
'{discussion_count}' => $user->getAttribute('discussion_count'),
'{comment_count}' => $user->getAttribute('comment_count')
'username' => $user->getAttribute('display_name'),
'discussion_count' => $user->getAttribute('discussion_count'),
'comment_count' => $user->getAttribute('comment_count')
]);

$this->parent
Expand Down
5 changes: 4 additions & 1 deletion src/Managers/QADiscussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ private function createTags($discussion)
$this->parent->setSchemaBreadcrumb($discussion);
}

$mainEntity['suggestedAnswer'] = $posts;
// Only add suggested answers property if there are posts
if(count($posts) > 0) {
$mainEntity['suggestedAnswer'] = $posts;
}

// $discussion->getAttribute('tags')

Expand Down

0 comments on commit cbbe884

Please sign in to comment.