Commit ae4fcdaf authored by Marcelo Rivera's avatar Marcelo Rivera

(feat): SEO

1 merge request!308WIP: (feat): Minds Pro
Pipeline #81134320 running with stages
......@@ -6,6 +6,7 @@ use Minds\Core;
use Minds\Entities;
use Minds\Helpers;
use Minds\Helpers\Counters;
use Zend\Diactoros\ServerRequestFactory;
class SEO
{
......@@ -76,18 +77,30 @@ class SEO
$params = $event->getParameters();
$slugs = $params['slugs'];
if ((count($slugs) < 3) || ($slugs[1] != 'blog')) {
/** @var Core\Pro\Domain $proDomain */
$proDomain = Core\Di\Di::_()->get('Pro\Domain');
$request = ServerRequestFactory::fromGlobals();
$serverParams = $request->getServerParams() ?? [];
$host = parse_url($serverParams['HTTP_ORIGIN'] ?? '', PHP_URL_HOST) ?: $serverParams['HTTP_HOST'];
$proSettings = $proDomain->lookup($host);
if ($proSettings && (count($slugs) < 2 || $slugs[0] === 'blog')) {
$slugParts = explode('-', $slugs[1]);
} elseif (!$proSettings && count($slugs) >= 3 && $slugs[1] === 'blog') {
$slugParts = explode('-', $slugs[2]);
} else {
return;
}
$slugParts = explode('-', $slugs[2]);
$guid = $slugParts[count($slugParts) - 1];
if (!is_numeric($guid)) {
return;
}
$event->setResponse($this->viewHandler([ $guid ]));
$event->setResponse($this->viewHandler([$guid]));
});
}
......
......@@ -66,16 +66,9 @@ class SEO
'og:image' => $this->user->getIconURL('large'),
]);
Manager::add('/feed', [$this, 'activityHandler']);
Manager::add('/videos', [$this, 'entityHandler']);
Manager::add('/images', [$this, 'entityHandler']);
Manager::add('/articles', [$this, 'entityHandler']);
Manager::add('/groups', [$this, 'entityHandler']);
// Manager::add('/login', [$this, 'entityHandler']);
// blog slugs
// media slugs
Manager::add('/newsfeed', [$this, 'activityHandler']);
Manager::add('/media', [$this, 'entityHandler']);
// blog route added in Blogs\SEO
}
function activityHandler($slugs = [])
......@@ -124,7 +117,14 @@ class SEO
function getEntityProperty($entity, $prop)
{
$getter = "get${$prop}";
return Helpers\MagicAttributes::getterExists($entity, $getter) ? $entity->{$getter}() : $entity->{$prop};
if (isset($entity->{$prop})) {
return $entity->{$prop};
} else if (Helpers\MagicAttributes::getterExists($entity, $getter)) {
return $entity->{$getter}();
}
return null;
}
function entityHandler($slugs = [])
......@@ -144,11 +144,11 @@ class SEO
$owner = $this->getEntityProperty($entity, 'ownerObj');
$title = $this->getEntityProperty($entity, 'title') ?: $this->getEntityProperty($entity, 'message');
$title = $this->getEntityProperty($entity, 'title') ?: $this->getEntityProperty($entity, 'description');
$siteName = $this->config->site_name;
$description = $this->getEntityProperty($entity, 'blurb') ?: "@{$owner['username']} on {$siteName}";
$description = $title ?? $this->getEntityProperty($entity, 'blurb') ?? "@{$owner['username']} on {$siteName}";
$meta = [
'title' => $title,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment