Skip to content

Commit

Permalink
MED-100: Add Vimeo source
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Apr 19, 2024
1 parent 541beb2 commit 5313179
Show file tree
Hide file tree
Showing 48 changed files with 6,707 additions and 46 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.1'
- php: '8.3'
moodle-branch: 'master'
database: 'pgsql'
- php: '8.2'
moodle-branch: 'master'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
Expand All @@ -39,7 +45,7 @@ jobs:
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
database: 'pgsql'

steps:
- name: Check out repository code
Expand Down
11 changes: 7 additions & 4 deletions classes/media_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@
*/
class media_manager implements renderable, templatable {
/** @var array $media List of media resources to display */
protected $media;
protected $media = null;

/** @var int $page Paging offset */
protected int $page = 0;

/** @var $source Source manager */
protected $source = null;

/** @var $page Search form */
protected $search = null;

Expand All @@ -71,7 +74,6 @@ public function __construct(string $source, ?stdClass $record = null, int $page
require_capability('tool/mediatime:view', context_system::instance());
if ($record) {
$source = $record->source;
$record->content = json_decode($record->content);
}

$plugins = plugininfo\mediatimesrc::get_enabled_plugins();
Expand All @@ -98,7 +100,7 @@ public function __construct(string $source, ?stdClass $record = null, int $page
$rs = self::search((array)$this->search->get_data());
foreach ($rs as $media) {
if (in_array($media->source, $plugins)) {
$media->content = json_decode($media->content);
$media->content = $media->content ?? '{}';
$this->media[] = $media;
}
}
Expand Down Expand Up @@ -136,7 +138,8 @@ public function export_for_template(renderer_base $output): array {
'imageurl' => $resource->image_url($output),
'tags' => $resource->tags($output),
'url' => $url->out(),
'content' => $record->content,
'name' => $record->name,
'title' => $resource->get_title(),
'removeurl' => $removeurl->out(),
];
}
Expand Down
12 changes: 12 additions & 0 deletions classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,16 @@ public function image_url($output) {
public function video_file_content($output) {
return $this->resource->video_file_content($output);
}

/**
* Return resource title
*
* @return string
*/
public function get_title() {
if (method_exists($this->resource, 'get_title')) {
return $this->resource->get_title();
}
return json_decode($this->record->content)->title ?? '';
}
}
2 changes: 2 additions & 0 deletions lang/en/tool_mediatime.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@
$string['tagarea_tool_mediatime'] = 'Media resources';
$string['title'] = 'Title';
$string['title_help'] = 'The title may be displayed by the video player when used';
$string['subplugintype_mediatimesrc_plural'] = 'Media Time sources';
$string['filelinks'] = 'File links';
1 change: 0 additions & 1 deletion source/streamio/classes/form/delete_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_resource extends \tool_mediatime\form\delete_resource {

/**
* Definition
*/
Expand Down
3 changes: 1 addition & 2 deletions source/streamio/classes/form/edit_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_resource extends \tool_mediatime\form\edit_resource {

/**
* Definition
*/
Expand Down Expand Up @@ -93,7 +92,7 @@ public function definition_after_data() {
$record = $DB->get_record('tool_mediatime', ['id' => $id]);
$context = context_system::instance();
if ($record) {
$record->content = json_decode($record->content);
$content = json_decode($record->content);
$resource = new media_resource($record);

$videourl = $resource->video_url($OUTPUT);
Expand Down
4 changes: 2 additions & 2 deletions source/streamio/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ protected function save_file($id, $video) {
'tool_mediatime',
'm3u8',
$id,
'id DESC', false
'id DESC',
false
);
foreach ($files as $file) {
$file->delete();
}
if ($video->transcodings) {

$fileinfo = [
'contextid' => SYSCONTEXTID,
'component' => 'tool_mediatime',
Expand Down
5 changes: 2 additions & 3 deletions source/streamio/classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function __construct(stdClass $record) {
*/
public function export_for_template(renderer_base $output) {
global $DB, $USER;
$content = (array)$this->record->content;
$context = \context_system::instance();
$videourl = $this->video_url($output);

Expand Down Expand Up @@ -96,7 +95,7 @@ public function export_for_template(renderer_base $output) {
* @return string url
*/
public function image_url(renderer_base $output) {
return 'https://' . $this->record->content->screenshot->normal;
return 'https://' . json_decode($this->record->content)->screenshot->normal;
}

/**
Expand All @@ -108,7 +107,7 @@ public function image_url(renderer_base $output) {
public function video_url($output) {
$this->videourl = '';

$id = $this->record->content->id;
$id = json_decod($this->record->content)->id;

return "https://streamio.com/api/v1/videos/$id/public_show.m3u8";
}
Expand Down
3 changes: 1 addition & 2 deletions source/streamio/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
8 changes: 4 additions & 4 deletions source/streamio/lang/en/mediatimesrc_streamio.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@

defined('MOODLE_INTERNAL') || die();

$string['pluginname'] = 'Streamio';
$string['event_resource_created'] = 'Streamio resource created';
$string['event_resource_deleted'] = 'Streamio resource deleted';
$string['event_resource_updated'] = 'Streamio resource updated';
$string['keepstreamiofiles'] = 'Keep Streamio files';
$string['password'] = 'Password';
$string['password_help'] = 'Streamio password for administrative access';
$string['pluginname'] = 'Streamio';
$string['privacy:metadata'] = 'The Streamio plugin for Media Time does not store personal data. It does transmit files associated with educational video content that normally does not contain user data. If it is used for personal data, a separate agreement with the provider may be required.';
$string['removestreamiofiles'] = 'Remove Streamio files';
$string['selectexistingfile'] = 'Select existing file';
$string['streamiofileaction'] = 'Streamio file action';
$string['streamiofileaction_help'] = 'Select whether the file should be deleted on Streamio when the local content is deleted. If the file is used in other local resources, it will no longer be available to users.';
$string['streamio:upload'] = 'Upload files to Streamio';
$string['streamio:viewall'] = 'View all files available';
$string['streamiofileaction'] = 'Streamio file action';
$string['streamiofileaction_help'] = 'Select whether the file should be deleted on Streamio when the local content is deleted. If the file is used in other local resources, it will no longer be available to users.';
$string['uploadnewfile'] = 'Upload new file';
$string['username'] = 'Username';
$string['username_help'] = 'Streamio user name for administrative access found in Streamio settings';
$string['videofile'] = 'Video file';
$string['videofile_help'] = 'Choose to upload a new video, or choose to use an existing one that you select';
$string['privacy:metadata'] = 'The Streamio plugin for Media Time does not store personal data. It does transmit files associated with educational video content that normally does not contain user data. If it is used for personal data, a separate agreement with the provider may be required.';
2 changes: 1 addition & 1 deletion source/streamio/templates/file_upload.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="progress bg-primary" style="width: 0%; height: 1em;"></div>
</div>
<div class="p-3">
<button name="upload" type="button" class="btn btn-primary">{{# str }} upload {{/ str }}</button>
<button name="upload" type="button" class="btn btn-primary" accept="video/*">{{# str }} upload {{/ str }}</button>
<button name="cancel" value="true" class="btn btn-secondary">{{# str }} cancel {{/ str }}</button>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion source/videotime/classes/form/delete_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_resource extends \tool_mediatime\form\delete_resource {

/**
* Definition
*/
Expand Down
1 change: 0 additions & 1 deletion source/videotime/classes/form/edit_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_resource extends \tool_mediatime\form\edit_resource {

/**
* Definition
*/
Expand Down
2 changes: 1 addition & 1 deletion source/videotime/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct($record = null) {
}

if ($record) {
$this->content = $record->content;
$this->content = json_decode($record->content);
}

$maxbytes = get_config('mediatimesrc_videotime', 'maxbytes');
Expand Down
11 changes: 10 additions & 1 deletion source/videotime/classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class media_resource implements renderable, templatable {
/** @var $context System context */
protected $context = null;

/** @var $context Poster image url */
protected $poster = null;

/** @var ?stdClass $record Media Time resource record */
protected $record;

/** @var $context Video url */
protected $videourl = null;

/**
* Constructor
*
Expand Down Expand Up @@ -83,7 +92,7 @@ public function export_for_template(renderer_base $output) {
'canedit' => has_capability('moodle/tag:edit', $this->context) || $USER->id == $this->record->usermodified,
'id' => $this->record->id,
'libraryhome' => new moodle_url('/admin/tool/mediatime/index.php'),
'resource' => $this->record->content,
'resource' => json_decode($this->record->content),
'video' => $output->render_from_template('mediatimesrc_videotime/video', $content),
];
}
Expand Down
3 changes: 1 addition & 2 deletions source/videotime/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
6 changes: 3 additions & 3 deletions source/videotime/lang/en/mediatimesrc_videotime.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

defined('MOODLE_INTERNAL') || die();

$string['pluginname'] = 'Video Time resource';
$string['configmaxbytes'] = 'Default maximum file size for all files uploaded';
$string['event_resource_created'] = 'Video Time resource created';
$string['event_resource_deleted'] = 'Video Time resource deleted';
$string['event_resource_updated'] = 'Video Time resource updated';
$string['maxbytes'] = 'Maximum size of file uploads';
$string['pluginname'] = 'Video Time resource';
$string['posterimage'] = 'Poster image';
$string['posterimage_help'] = 'Select an image to displayed before the video is played or as a thumbnail image.';
$string['privacy:metadata'] = 'The Video Time resource does not store or transmit any personal data.';
$string['videofile'] = 'Video file';
$string['videofile_help'] = 'Video file to be displayed';
$string['configmaxbytes'] = 'Default maximum file size for all files uploaded';
$string['privacy:metadata'] = 'The Video Time resource does not store or transmit any personal data.';
20 changes: 12 additions & 8 deletions source/videotime/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,29 @@
* @param array $options additional options affecting the file serving
* @return bool false if the file was not found, just send the file otherwise and do not return anything
*/
function mediatimesrc_videotime_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=[]) {
function mediatimesrc_videotime_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) {
if ($context->contextlevel != CONTEXT_SYSTEM) {
return false;
}

require_login();

if (in_array($filearea, [
'posterimage',
if (
in_array($filearea, [
'videofile',
])) {
])
) {
$itemid = array_shift($args);
$contenthash = array_shift($args);

$relativepath = implode('/', $args);

$fullpath = "/$context->id/mediatimesrc_videotime/$filearea/$itemid/$relativepath";

$fs = get_file_storage();
if ((!$file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
if (
(!$file = $fs->get_file_by_hash(sha1($fullpath)))
|| $file->is_directory()
|| $file->get_contenthash() != $contenthash
) {
return false;
}

Expand All @@ -72,6 +76,6 @@ function mediatimesrc_videotime_pluginfile($course, $cm, $context, $filearea, $a
function mediatimesrc_videotime_config_file_areas() {
return [
'posterimage',
'videotile',
'videofile',
];
}
3 changes: 3 additions & 0 deletions source/vimeo/amd/build/file_upload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions source/vimeo/amd/build/file_upload.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions source/vimeo/amd/build/tus.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions source/vimeo/amd/build/tus.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 5313179

Please sign in to comment.