Meta data (OpenGraph) toegevoegd.
This commit is contained in:
@@ -14,6 +14,7 @@ class CalendarEvent extends Model {
|
|||||||
public $video;
|
public $video;
|
||||||
public $keywords;
|
public $keywords;
|
||||||
public $url;
|
public $url;
|
||||||
|
public $metadata;
|
||||||
|
|
||||||
public function __construct($data, $images = null, $podcast = null) {
|
public function __construct($data, $images = null, $podcast = null) {
|
||||||
parent::__construct($data);
|
parent::__construct($data);
|
||||||
@@ -46,6 +47,12 @@ class CalendarEvent extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->url = "/agenda/{$this->id}/" . parent::url_slug($this->title);
|
$this->url = "/agenda/{$this->id}/" . parent::url_slug($this->title);
|
||||||
|
$this->metadata = (new MetaData())
|
||||||
|
->set('title', $this->title)
|
||||||
|
->set('description', strip_tags($this->excerpt()))
|
||||||
|
->set('image', isset($this->images) && count($this->images) ? $this->images[0]->url : null )
|
||||||
|
->set('audio', isset($this->podcast) ? $this->podcast->url : null)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function excerpt() {
|
public function excerpt() {
|
||||||
|
|||||||
35
common/classes/MetaData.php
Normal file
35
common/classes/MetaData.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
namespace Model;
|
||||||
|
|
||||||
|
class MetaData {
|
||||||
|
private $data = ['type' => 'article', 'locale' => 'nl-nl'];
|
||||||
|
|
||||||
|
public function set($prop, $val) {
|
||||||
|
if($val) {
|
||||||
|
$this->data[$prop] = $val;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function append($prop, $val) {
|
||||||
|
if(array_key_exists($prop, $this->data)) {
|
||||||
|
$this->data[$prop] .= $val;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepend($prop, $val) {
|
||||||
|
if(array_key_exists($prop, $this->data)) {
|
||||||
|
$this->data[$prop] = $val . $this->data[$prop];
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function metaTags() {
|
||||||
|
foreach($this->data as $prop => $val) {
|
||||||
|
if($val) {
|
||||||
|
echo "<meta property=\"og:$prop\" content=\"" . htmlentities($val) . "\" />\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace Model;
|
|||||||
|
|
||||||
require_once "NewsImage.php";
|
require_once "NewsImage.php";
|
||||||
require_once "NewsSource.php";
|
require_once "NewsSource.php";
|
||||||
|
require_once "MetaData.php";
|
||||||
|
|
||||||
class NewsItem extends Model {
|
class NewsItem extends Model {
|
||||||
public $id;
|
public $id;
|
||||||
@@ -24,6 +25,7 @@ class NewsItem extends Model {
|
|||||||
public $video;
|
public $video;
|
||||||
|
|
||||||
public $url;
|
public $url;
|
||||||
|
public $metadata;
|
||||||
|
|
||||||
public function __construct($data, $images = null, $podcast = null) {
|
public function __construct($data, $images = null, $podcast = null) {
|
||||||
parent::__construct($data);
|
parent::__construct($data);
|
||||||
@@ -88,6 +90,15 @@ class NewsItem extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->url = "/nieuws/{$this->id}/" . parent::url_slug($this->title);
|
$this->url = "/nieuws/{$this->id}/" . parent::url_slug($this->title);
|
||||||
|
$this->metadata = (new MetaData())
|
||||||
|
->set('title', $this->title)
|
||||||
|
->set('description', strip_tags($this->excerpt()))
|
||||||
|
->set('image', isset($this->images) && count($this->images) ? $this->images[0]->url : null )
|
||||||
|
->set('video', isset($this->video) ? $this->video : null)
|
||||||
|
->set('audio', isset($this->podcast) ? $this->podcast->url : null)
|
||||||
|
->set('article:published_time', $this->published->format('r'))
|
||||||
|
->set('article:modified_time', $this->edited ? $this->edited->format('r') : null)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function excerpt() {
|
public function excerpt() {
|
||||||
|
|||||||
@@ -16,13 +16,14 @@ class Podcast extends Model {
|
|||||||
public $download;
|
public $download;
|
||||||
public $duration;
|
public $duration;
|
||||||
public $image;
|
public $image;
|
||||||
|
public $metadata;
|
||||||
private $key;
|
private $key;
|
||||||
|
|
||||||
public function __construct($data) {
|
public function __construct($data) {
|
||||||
parent::__construct($data);
|
parent::__construct($data);
|
||||||
parent::ConvertToDateTime($this->created);
|
parent::ConvertToDateTime($this->created);
|
||||||
|
|
||||||
$this->url = $this->id . '/' . parent::url_slug($this->title);
|
$this->url = '/' . $this->id . '/' . parent::url_slug($this->title);
|
||||||
if($this->soundfilename) {
|
if($this->soundfilename) {
|
||||||
// Only generate when not constructing from a JSON object
|
// Only generate when not constructing from a JSON object
|
||||||
$this->key = sha1($this->id . ':' . date('Y-m-d') . ':' . $this->soundfilename);
|
$this->key = sha1($this->id . ':' . date('Y-m-d') . ':' . $this->soundfilename);
|
||||||
@@ -45,6 +46,13 @@ class Podcast extends Model {
|
|||||||
$imagedata->title = $data->imagecaption;
|
$imagedata->title = $data->imagecaption;
|
||||||
$this->image = new NewsImage($imagedata, '/img/podcast/');
|
$this->image = new NewsImage($imagedata, '/img/podcast/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->metadata = (new MetaData())
|
||||||
|
->set('title', $this->title)
|
||||||
|
->set('description', strip_tags($this->excerpt()))
|
||||||
|
->set('image', isset($this->images) && count($this->images) ? $this->images[0]->url : null )
|
||||||
|
->set('audio', $this->url)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function titleWithoutProgram() {
|
public function titleWithoutProgram() {
|
||||||
|
|||||||
Reference in New Issue
Block a user