Repository URL to install this package:
|
Version:
3.4.1 ▾
|
<?php
namespace Evsmash\Articles\Services;
use Evsmash\Core\Dec\Thumb;
use Evsmash\Core\Helpers\Date;
use Evsmash\Core\Helpers\H;
use Evsmash\Core\Helpers\Sanitize;
use Evsmash\Core\Input\Route;
use Evsmash\Articles\Article;
class Schema {
// article
static public function article($options = []) {
// route
if(Route::ca() == 'articles-show') {
// article
$article = Article::find(Route::id());
// schema
$schema = [];
// basic
$schema['@context'] = 'http://schema.org';
$schema['@type'] = 'BlogPosting';
$schema['@id'] = $article->id;
$schema['name'] = $article->name;
$schema['headline'] = $article->name;
$schema['description'] = Sanitize::clean($article->content);
$schema['image'] = Thumb::path($article->photo, cfg('settings-photo'));
$schema['url'] = cfg('protocol').cfg('domain').$article->link_final;
$schema['datePublished'] = Date::show($article->created_at);
$schema['dateModified'] = Date::show($article->created_at);
if(!is_null($article->type)) {
$schema['author'] = [
'@type' => 'Person',
'@id' => $article->type_id,
'name' => $article->type->name
];
}
// encode
$schema = json_encode($schema);
// output
return '<script type="application/ld+json">'.$schema.'</script>';
}
}
}