95 lines
2.6 KiB
PHP
Executable File
95 lines
2.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Model;
|
|
|
|
require_once "NewsImage.php";
|
|
|
|
class Podcast extends Model {
|
|
public $id;
|
|
public $title;
|
|
public $content;
|
|
protected $soundfilename;
|
|
public $created;
|
|
public $program;
|
|
public $url;
|
|
public $auth;
|
|
public $download;
|
|
public $duration;
|
|
public $image;
|
|
public $metadata;
|
|
public $waveform;
|
|
private $key;
|
|
|
|
public function __construct($data) {
|
|
parent::__construct($data);
|
|
parent::ConvertToDateTime($this->created);
|
|
|
|
$this->url = '/' . $this->id . '/' . parent::url_slug($this->title) . '.mp3';
|
|
if($this->soundfilename) {
|
|
// Only generate when not constructing from a JSON object
|
|
$this->key = sha1($this->id . ':' . date('Y-m-d') . ':' . $this->soundfilename);
|
|
$this->auth = $this->key;
|
|
}
|
|
|
|
if(isset($data->program)) {
|
|
$this->program = null;
|
|
if(is_object($data->program)) {
|
|
$this->program = new \Model\Program($data->program);
|
|
} elseif($data->program) {
|
|
$this->program = new \Model\Program(['id' => $data->program, 'name' => $data->program_name, 'description' => $data->program_description]);
|
|
}
|
|
}
|
|
|
|
if(isset($data->imagefile)) {
|
|
$imagedata = new \stdClass();
|
|
$imagedata->id = $this->id;
|
|
$imagedata->file = $data->imagefile;
|
|
$imagedata->title = $data->imagecaption;
|
|
$this->image = new NewsImage($imagedata, '/img/podcast/');
|
|
}
|
|
|
|
if(isset($data->metadata, $data->metadata->waveform)){
|
|
$this->waveform = $data->metadata->waveform;
|
|
}
|
|
|
|
$this->metadata = (new MetaData())
|
|
->set('title', $this->title)
|
|
->set('description', strip_tags($this->excerpt()))
|
|
->set('image', isset($this->image) ? $this->image->url : null )
|
|
->set('audio', $this->url)
|
|
;
|
|
}
|
|
|
|
public function titleWithoutProgram() {
|
|
if(!$this->program) { return $this->title; }
|
|
return trim(str_replace($this->program->name, '', $this->title), "- \t\n\r\0\x0B");
|
|
}
|
|
|
|
public function isValidAuth($key) {
|
|
return ($key == $this->key);
|
|
}
|
|
|
|
public function getSoundfile() {
|
|
return '/var/audio/podcast/' . $this->soundfilename;
|
|
}
|
|
|
|
public function formatDuration() {
|
|
$seconds = $this->duration / 1000;
|
|
$milliseconds = $this->duration % 1000;
|
|
|
|
$hours = ($seconds > 3600) ? floor($seconds / 3600) : 0;
|
|
$seconds %= 3600;
|
|
return str_pad($hours, 2, '0', STR_PAD_LEFT)
|
|
. gmdate(':i:s', $seconds)
|
|
;//. ($milliseconds ? ".$milliseconds" : '') ;
|
|
}
|
|
|
|
public function excerpt() {
|
|
$maxLength = 500;
|
|
return '<p class="news-excerpt long">' .
|
|
substr($this->content, 0, $maxLength) .
|
|
(strlen($this->content) > $maxLength ? '...' : '') .
|
|
'</p>';
|
|
}
|
|
}
|