. * * @package mahara * @subpackage blocktype-internalmedia * @author Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz * */ defined('INTERNAL') || die(); class PluginBlocktypeInternalmedia extends PluginBlocktype { public static function get_title() { return get_string('title', 'blocktype.file/internalmedia'); } public static function get_description() { return get_string('description', 'blocktype.file/internalmedia'); } public static function get_categories() { return array('fileimagevideo'); } public static function has_config() { return true; } public static function postinst($oldversion) { if ($oldversion == 0) { set_config_plugin('blocktype', 'internalmedia', 'enabledtypes', serialize(array('flv'))); } } public static function render_instance(BlockInstance $instance, $editing=false) { $configdata = $instance->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']); $width = (!empty($configdata['width'])) ? hsc($configdata['width']) : '300'; $height = (!empty($configdata['height'])) ? hsc($configdata['height']) : '300'; $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 .= '
' . call_static_method('PluginBlocktypeInternalmedia', $callbacks[$mimetypefiletypes[$mimetype]], $artefact, $instance, $width, $height) . '
'; return $result; } public static function has_instance_config() { return true; } 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'] : '', ), 'height' => array( 'type' => 'text', 'title' => get_string('height'), 'size' => 3, 'defaultvalue' => (isset($configdata['height'])) ? $configdata['height'] : '', ), ); } 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'), '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'), '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)); } 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"];')); $filetypes = array_merge( array( 'description' => array( 'value' => get_string('configdesc', 'blocktype.file/internalmedia'), ), ), $filetypes ); return array( 'elements' => $filetypes, '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' => 'qt_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 = str_replace('&', '%26', $url); // Flash needs these escaped $playerurl = get_config('wwwroot') . 'lib/flowplayer/flowplayer-3.2.4.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: "'.get_config('wwwroot').'lib/flowplayer.audio/flowplayer.audio-3.2.1.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')) . '
' . ' ' /* 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() { if (defined('BLOCKTYPE_INTERNALMEDIA_JS_INCLUDED')) { return ''; } define('BLOCKTYPE_INTERNALMEDIA_JS_INCLUDED', true); return ' '; } public static function default_copy_type() { return 'full'; } } ?>