Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
evsmash/articles / libs / Services / Schema.php
Size: Mime:
<?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>';

		}

	}

}