get('configdata');
if (empty($configdata['artefactid'])) {
return '';
}
$result = self::get_js_source();
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = $instance->get_artefact_instance($configdata['artefactid']);
$defaultwidth = get_config_plugin('blocktype', 'internalmedia', 'width') ?
get_config_plugin('blocktype', 'internalmedia', 'width') : 300;
$defaultheight = get_config_plugin('blocktype', 'internalmedia', 'height') ?
get_config_plugin('blocktype', 'internalmedia', 'height') : 300;
$width = (!empty($configdata['width'])) ? hsc($configdata['width']) : $defaultwidth;
$height = (!empty($configdata['height'])) ? hsc($configdata['height']) : $defaultheight;
$mimetype = $artefact->get('filetype');
$mimetypefiletypes = self::get_allowed_mimetype_filetypes();
if (!isset($mimetypefiletypes[$mimetype])) {
return get_string('typeremoved', 'blocktype.file/internalmedia');
}
$callbacks = self::get_all_filetype_players();
$result .= '
';
return $result;
}
public static function has_instance_config() {
return true;
}
public static function get_instance_config_javascript() {
$result = self::get_js_source(true);
if (!empty($result)) {
return $result;
}
}
public static function instance_config_form($instance) {
$configdata = $instance->get('configdata');
safe_require('artefact', 'file');
$instance->set('artefactplugin', 'file');
return array(
'artefactid' => self::filebrowser_element($instance, (isset($configdata['artefactid'])) ? array($configdata['artefactid']) : null),
'width' => array(
'type' => 'text',
'title' => get_string('width'),
'size' => 3,
'defaultvalue' => (isset($configdata['width'])) ? $configdata['width'] : '',
'rules' => array('minvalue' => 1, 'maxvalue' => 2000),
),
'height' => array(
'type' => 'text',
'title' => get_string('height'),
'size' => 3,
'defaultvalue' => (isset($configdata['height'])) ? $configdata['height'] : '',
'rules' => array('minvalue' => 1, 'maxvalue' => 2000),
),
);
}
public static function filebrowser_element(&$instance, $default=array()) {
$element = ArtefactTypeFileBase::blockconfig_filebrowser_element($instance, $default);
$element['title'] = get_string('media', 'blocktype.file/internalmedia');
$element['name'] = 'artefactid';
$element['config']['selectone'] = true;
$element['filters'] = array(
'artefacttype' => array('file', 'audio', 'video'),
'filetype' => self::get_allowed_mimetypes(),
);
return $element;
}
public static function artefactchooser_element($default=null) {
return array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('media', 'blocktype.file/internalmedia'),
'defaultvalue' => $default,
'blocktype' => 'internalmedia',
'limit' => 5,
'selectone' => true,
'artefacttypes' => array('file', 'audio', 'video'),
'template' => 'artefact:file:artefactchooser-element.tpl',
);
}
public static function artefactchooser_get_element_data($artefact) {
$artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id));
return $artefact;
}
public static function save_config_options($values) {
$enabledtypes = array();
foreach ($values as $type => $enabled) {
if (!in_array($type, self::get_all_filetypes())) {
continue;
}
if (!empty($enabled)) {
$enabledtypes[] = $type;
}
}
set_config_plugin('blocktype', 'internalmedia', 'enabledtypes', serialize($enabledtypes));
set_config_plugin('blocktype', 'internalmedia', 'height', $values['height']);
set_config_plugin('blocktype', 'internalmedia', 'width', $values['width']);
}
public static function get_config_options() {
$elements = array();
// Allowed file types
$filetypes = array();
$currenttypes = self::get_allowed_filetypes();
foreach (self::get_all_filetypes() as $filetype) {
$filetypes[$filetype] = array(
'type' => 'checkbox',
'title' => get_string($filetype, 'artefact.file'),
'defaultvalue' => in_array($filetype, $currenttypes),
);
}
uasort($filetypes, create_function('$a, $b', 'return $a["title"] > $b["title"];'));
$options = array_merge(
array(
'description' => array(
'value' => get_string('configdesc', 'blocktype.file/internalmedia'),
),
),
$filetypes
);
$options['height'] = array(
'type' => 'text',
'title' => get_string('height'),
'rules' => array('integer' => true, 'minvalue' => 120, 'maxvalue' => 3072),
'defaultvalue' => get_config_plugin('blocktype', 'internalmedia', 'height')
? get_config_plugin('blocktype', 'internalmedia', 'height') : 240,
);
$options['width'] = array(
'type' => 'text',
'title' => get_string('width'),
'rules' => array('integer' => true, 'minvalue' => 160, 'maxvalue' => 4096),
'defaultvalue' => get_config_plugin('blocktype', 'internalmedia', 'width')
? get_config_plugin('blocktype', 'internalmedia', 'width') : 320,
);
return array(
'elements' => $options,
'renderer' => 'table'
);
}
private static function get_allowed_filetypes() {
if ($data = get_config_plugin('blocktype', 'internalmedia', 'enabledtypes')) {
return unserialize($data);
}
return array();
}
private static function get_allowed_mimetypes() {
return array_keys(self::get_allowed_mimetype_filetypes());
}
private static function get_allowed_mimetype_filetypes() {
if ($data = self::get_allowed_filetypes()) {
if ($mimetypes = get_records_sql_assoc('
SELECT mimetype, description
FROM {artefact_file_mime_types}
WHERE description IN (' . join(',', array_map('db_quote', $data)) . ')', array())) {
foreach ($mimetypes as &$m) {
$m = $m->description;
}
return $mimetypes;
}
}
return array();
}
private static function get_all_filetypes() {
return array_keys(self::get_all_filetype_players());
}
private static function get_all_filetype_players() {
/* Keyed by the file type descriptions from the artefact_file_mime_types table */
return array(
'mp3' => 'flow_player', // tested
'swf' => 'flash_player', // tested
'flv' => 'flow_player', // tested
'quicktime' => 'qt_player', // tested
'wmv' => 'wmp_player', // tested
'mpeg' => 'qt_player', // tested
'avi' => 'wmp_player', // tested
'mp4_video' => 'flow_player', // tested
/* commenting out for now
'ram' => 'real_player',
'rm' => 'real_player',
'rpm' => 'real_player',
*/
);
}
public static function flash_player($artefact, $block, $width, $height) {
static $count = 0;
$count++;
$id = 'blocktype_internalmedia_flash_' . time() . $count;
$url = self::get_download_link($artefact, $block);
$params = array('play' => 'true');
$html = '' . hsc($artefact->get('title')) . '
('
. get_string('flashanimation', 'blocktype.file/internalmedia') . ')
';
return $html;
}
public static function flow_player($artefact, $block, $width, $height) {
static $count = 0;
$count++;
$extn = $artefact->get('oldextension');
$id = 'blocktype_internalmedia_flow_' . time() . $count;
$url = self::get_download_link($artefact, $block);
$url = parse_url($url, PHP_URL_PATH) . '?' . parse_url($url, PHP_URL_QUERY);
$escapedurl = str_replace('&', '%26', $url); // Flash needs these escaped
$baseurlpath = parse_url(get_config('wwwroot'), PHP_URL_PATH);
$baseurl = $baseurlpath . 'artefact/file/blocktype/internalmedia/';
$playerurl = $baseurl . 'mahara-flashplayer/mahara-flashplayer.swf';
$autohide = 'true';
$type = '';
$audio = '';
$buffering = 'true';
if ($extn == 'mp3') {
$height = 25; // only show the controls
$autohide = 'false';
$type = 'type: "audio",'; // force the player to use the audio plugin
$buffering = 'false'; // without this autoPlay will also be set to true
$audio = ', audio: {
url: "' . $baseurl . 'flowplayer.audio/flowplayer.audio-3.2.2.swf"
}';
}
$html = '' . hsc($artefact->get('title')) . '
' . get_string('flashanimation', 'blocktype.file/internalmedia') . '
';
return $html;
}
public static function real_player($artefact, $block, $width, $height) {
$url = self::get_download_link($artefact, $block);
require_once('file.php');
$mimetype = $artefact->get('filetype');
$autostart = 'false';
return '' . hsc($artefact->get('title')) . '
'
. '
';
}
public static function wmp_player($artefact, $block, $width, $height) {
$url = hsc(self::get_download_link($artefact, $block, true));
$size = 'width="' . $width . '" height="' . $height . '"';
$autosize = 'false';
$mimetype = 'video/x-ms-wmv'; // hardcode this
$autostart = 'false';
return '' . hsc($artefact->get('title')) . '
'
. '
';
}
public static function qt_player($artefact, $block, $width, $height) {
$url = self::get_download_link($artefact, $block);
$size = 'width="' . $width . '" height="' . $height . '"';
require_once('file.php');
$mimetype = $artefact->get('filetype');
$autostart = 'false';
return '' . hsc($artefact->get('title')) . '
'
. '
';
}
private static function get_download_link(ArtefactTypeFile $artefact, BlockInstance $instance, $wmp=false) {
return get_config('wwwroot') . 'artefact/file/download.php?file='
. $artefact->get('id') . '&view=' . $instance->get('view')
. ($wmp ? '&download=1' : '');
}
private static function get_js_source($asarray = false) {
if (defined('BLOCKTYPE_INTERNALMEDIA_JS_INCLUDED')) {
return '';
}
define('BLOCKTYPE_INTERNALMEDIA_JS_INCLUDED', true);
if ($asarray) {
return array(get_config('wwwroot').'artefact/file/blocktype/internalmedia/mahara-flashplayer/mahara-flashplayer-3.2.6.js',
get_config('wwwroot') . 'artefact/file/blocktype/internalmedia/swfobject.js',
);
}
return '
';
}
public static function default_copy_type() {
return 'full';
}
}