Commit d6446942 authored by Stacey Walker's avatar Stacey Walker
Browse files

artefact/file: new video/audio classes (bug#829136)



Change-Id: Ia6df631512795b68e1eba7906220803ca3a7f500
Signed-off-by: default avatarStacey Walker <stacey@catalyst-eu.net>
parent 9a2cfb06
......@@ -330,5 +330,75 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
}
}
if ($oldversion < 2011082200) {
// video file type
if (!get_record('artefact_installed_type', 'plugin', 'file', 'name', 'video')) {
insert_record('artefact_installed_type', (object) array('plugin' => 'file', 'name' => 'video'));
}
// update existing records
$videotypes = get_records_sql_array('
SELECT DISTINCT description
FROM {artefact_file_mime_types}
WHERE mimetype ' . db_ilike() . ' \'%video%\'', array());
if ($videotypes) {
$mimetypes = array();
foreach ($videotypes as $type) {
$mimetypes[] = $type->description;
}
$files = get_records_sql_array('
SELECT *
FROM {artefact_file_files}
WHERE filetype IN (
SELECT mimetype
FROM {artefact_file_mime_types}
WHERE description IN (' . join(',', array_map('db_quote', array_values($mimetypes))) . ')
)', array());
if ($files) {
$checked = array();
foreach ($files as $file) {
$checked[] = $file->artefact;
}
if (!empty($checked)) {
set_field_select('artefact', 'artefacttype', 'video', "artefacttype = 'file' AND id IN (" . join(',', $checked) . ')', array());
}
}
}
// audio file type
if (!get_record('artefact_installed_type', 'plugin', 'file', 'name', 'audio')) {
insert_record('artefact_installed_type', (object) array('plugin' => 'file', 'name' => 'audio'));
}
// update existing records
$audiotypes = get_records_sql_array('
SELECT DISTINCT description
FROM {artefact_file_mime_types}
WHERE mimetype ' . db_ilike() . ' \'%audio%\'', array());
if ($audiotypes) {
$mimetypes = array();
foreach ($audiotypes as $type) {
$mimetypes[] = $type->description;
}
$files = get_records_sql_array('
SELECT *
FROM {artefact_file_files}
WHERE filetype IN (
SELECT mimetype
FROM {artefact_file_mime_types}
WHERE description IN (' . join(',', array_map('db_quote', array_values($mimetypes))) . ')
)', array());
if ($files) {
$checked = array();
foreach ($files as $file) {
$checked[] = $file->artefact;
}
if (!empty($checked)) {
set_field_select('artefact', 'artefacttype', 'audio', "artefacttype = 'file' AND id IN (" . join(',', $checked) . ')', array());
}
}
}
}
return $status;
}
......@@ -36,6 +36,8 @@ class PluginArtefactFile extends PluginArtefact {
'image',
'profileicon',
'archive',
'video',
'audio',
);
}
......@@ -256,18 +258,26 @@ class PluginArtefactFile extends PluginArtefact {
'image' => array('file', 'image'),
'profileicon' => array('file', 'image'),
'archive' => array('file'),
'video' => array('file'),
'audio' => array('file'),
);
}
public static function get_attachment_types() {
return array('file', 'image', 'archive');
return array(
'file',
'image',
'archive',
'video',
'audio'
);
}
public static function recalculate_quota() {
$data = get_records_sql_assoc("
SELECT a.owner, SUM(f.size) AS bytes
FROM {artefact} a JOIN {artefact_file_files} f ON a.id = f.artefact
WHERE a.artefacttype IN ('file', 'image', 'profileicon', 'archive')
WHERE a.artefacttype IN ('file', 'image', 'profileicon', 'archive', 'video', 'audio')
AND a.owner IS NOT NULL
GROUP BY a.owner", array()
);
......@@ -834,6 +844,12 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
$data->height = $imageinfo[1];
return new ArtefactTypeImage(0, $data);
}
if ($video = ArtefactTypeVideo::new_video($data)) {
return $video;
}
if ($audio = ArtefactTypeAudio::new_audio($data)) {
return $audio;
}
if ($archive = ArtefactTypeArchive::new_archive($path, $data)) {
return $archive;
}
......@@ -2203,3 +2219,101 @@ class ArtefactTypeArchive extends ArtefactTypeFile {
}
}
class ArtefactTypeVideo extends ArtefactTypeFile {
protected $videotype;
public function __construct($id = 0, $data = null) {
parent::__construct($id, $data);
if ($this->id) {
$descriptions = self::video_file_descriptions();
$validtypes = self::video_mime_types();
$this->videotype = $descriptions[$validtypes[$this->filetype]->description];
}
}
public static function new_video($data) {
$descriptions = self::video_file_descriptions();
$validtypes = self::video_mime_types();
if (isset($validtypes[$data->filetype])) {
return new ArtefactTypeVideo(0, $data);
}
return false;
}
public static function video_file_descriptions() {
static $descriptions = null;
if (is_null($descriptions)) {
$descriptions = array(
'flv' => 'flv',
'avi' => 'avi',
'mpeg' => 'mpeg',
'wmv' => 'wmv',
'quicktime' => 'quicktime',
'sgi_movie' => 'sgi_movie',
'mp4_video' => 'mp4_video',
);
}
return $descriptions;
}
public static function video_mime_types() {
static $mimetypes = null;
if (is_null($mimetypes)) {
$descriptions = self::video_file_descriptions();
$mimetypes = PluginArtefactFile::get_mimetypes_from_description(array_keys($descriptions), true);
}
return $mimetypes;
}
public static function get_icon($options=null) {
global $THEME;
return $THEME->get_url('images/video.gif');
}
}
class ArtefactTypeAudio extends ArtefactTypeFile {
public static function new_audio($data) {
$descriptions = self::audio_file_descriptions();
$validtypes = self::audio_mime_types();
if (isset($validtypes[$data->filetype])) {
return new ArtefactTypeAudio(0, $data);
}
return false;
}
public static function audio_file_descriptions() {
static $descriptions = null;
if (is_null($descriptions)) {
$descriptions = array(
'mp3',
'mp4_audio',
'mp4',
'wav',
'ra',
'au',
'aiff',
'm3u'
);
}
return $descriptions;
}
public static function audio_mime_types() {
static $mimetypes = null;
if (is_null($mimetypes)) {
$descriptions = self::audio_file_descriptions();
$mimetypes = PluginArtefactFile::get_mimetypes_from_description(array_keys($descriptions), true);
}
return $mimetypes;
}
public static function get_icon($options=null) {
global $THEME;
return $THEME->get_url('images/audio.gif');
}
}
......@@ -28,5 +28,5 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011070700;
$config->version = 2011082200;
$config->release = '1.2.0';
......@@ -723,6 +723,8 @@ class HtmlExportOutputFilter {
case 'image':
case 'profileicon':
case 'archive':
case 'video':
case 'audio':
return '<a href="' . $this->get_export_path_for_file($artefact, array()) . '">' . $matches[5] . '</a>';
default:
return $matches[5];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment