56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Model;
|
|
|
|
require "Program.php";
|
|
|
|
class Podcast extends Model {
|
|
public $id;
|
|
public $title;
|
|
public $content;
|
|
protected $soundfilename;
|
|
public $created;
|
|
public $program;
|
|
public $url;
|
|
public $auth;
|
|
public $download;
|
|
private $key;
|
|
|
|
public function __construct($data) {
|
|
parent::__construct($data);
|
|
parent::ConvertToDateTime($this->created);
|
|
|
|
$this->url = $this->id . '/' . parent::url_slug($this->title);
|
|
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) && $data->program) {
|
|
if(is_object($data->program)) {
|
|
$this->program = new \Model\Program($data->program);
|
|
} else {
|
|
$this->program = new \Model\Program(['id' => $this->program, 'name' => $data->program_name, 'description' => $data->program_description]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function isValidAuth($key) {
|
|
return ($key == $this->key);
|
|
}
|
|
|
|
public function getSoundfile() {
|
|
return '/var/audio/podcast/' . $this->soundfilename;
|
|
}
|
|
|
|
public function excerpt() {
|
|
$hasImages = count($this->images) > 0;
|
|
$maxLength = $hasImages ? 200 : 500;
|
|
return '<p class="news-excerpt ' . ($hasImages ? 'short' : 'long') . '">' .
|
|
substr($this->content, 0, $maxLength) .
|
|
(strlen($this->content) > $maxLength ? '...' : '') .
|
|
'</p>';
|
|
}
|
|
}
|