Skip to content

Commit

Permalink
upgrade filter_oembed from its source
Browse files Browse the repository at this point in the history
  • Loading branch information
weilai-irl committed Jul 15, 2020
1 parent 184a596 commit 0eb4d66
Show file tree
Hide file tree
Showing 82 changed files with 7,711 additions and 963 deletions.
30 changes: 30 additions & 0 deletions filter/oembed/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Release Notes

Release 3.3.2 (Build - 2018120300)
Verified 3.6 compatibility.
Added an exception handler to ignore malformed regex expressions that the plugin has no control over.
Removed Office Mix tests as Office Mix has been discontinued.
Updated Behat tests to access site administration in the new way.
Updated Travis file to test multiple installs.

Release 3.3.1 (Build - 2018051500)
Fixed a unit test issue for Vimeo.
An extra check to deal with potential malformed provider endpoint URL.

For release 3.3.0, an xpath change was required in the Behat tests in order to get Behat to pass due to changes in Moodle's output.

For release 3.2, the plugin was rewritten to utilize the oembed provider definitions from http://oembed.com/providers.json.
The previous provider definitions that were hardcoded, but not present in the oembed provider list, were added as "local"
definitions to avoid regression errors.

Release 3.2.0.0 (Alpha)
Change highlights:
- Oembed providers defintions are downloaded from http://oembed.com/providers.json and stored in the Moodle database, rather than
code.
- Oembed defintions are refreshed nightly with new additions and deletions.
- Management screen allows for administrators to save provider defintions as local overrides not refreshed by oembed.com.
- Two types of tags can be used for filtering. The one desired can be configured.
- Lazy loading can be turned on or off; default is on. This can improve site performance.
- Provider management screen allows enable/disable, and edit as local as well as providing all of the provider information.
- A subplugin system is in place to allow providers not stored at oembed.com to define oembed information. Some of the existing
Microsoft providers have been rewritten as these.
144 changes: 144 additions & 0 deletions filter/oembed/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
* Gruntfile for compiling theme_bootstrap .less files.
*
* This file configures tasks to be run by Grunt
* http://gruntjs.com/ for the current theme.
*
* Requirements:
* nodejs, npm, grunt-cli.
*
* Installation:
* node and npm: instructions at http://nodejs.org/
* grunt-cli: `[sudo] npm install -g grunt-cli`
* node dependencies: run `npm install` in the root directory.
*
* Usage:
* Default behaviour is to watch all .less files and compile
* into compressed CSS when a change is detected to any and then
* clear the theme's caches. Invoke either `grunt` or `grunt watch`
* in the theme's root directory.
*
* To separately compile only moodle or editor .less files
* run `grunt less:moodle` or `grunt less:editor` respectively.
*
* To only clear the theme caches invoke `grunt exec:decache` in
* the theme's root directory.
*
* @package filter
* @subpackage oembed
* @author Joby Harding / David Scotson / Stuart Lamour / Guy Thomas
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

module.exports = function(grunt) {

// We need to include the core Moodle grunt file too, otherwise we can't run tasks like "amd".
require("grunt-load-gruntfile")(grunt);
grunt.loadGruntfile("../../Gruntfile.js");

// PHP strings for exec task.
var moodleroot = 'dirname(dirname(__DIR__))',
configfile = moodleroot + ' . "/config.php"',
decachephp = '';

decachephp += "define(\"CLI_SCRIPT\", true);";
decachephp += "require(" + configfile + ");";

// The previously used theme_reset_all_caches() stopped working for us, we investigated but couldn't figure out why.
// Using purge_all_caches() is a bit of a nuclear option, as it clears more than we should need to
// but it gets the job done.
decachephp += "purge_all_caches();";

grunt.mergeConfig = grunt.config.merge;

grunt.mergeConfig({
sass: {
oembed: {
options: {
compress: false
},
files: {
"styles.css": "sass/styles.scss",
}
}
},
csslint: {
src: "styles.css",
options: {
"adjoining-classes": false,
"box-sizing": false,
"box-model": false,
"overqualified-elements": false,
"bulletproof-font-face": false,
"compatible-vendor-prefixes": false,
"selector-max-approaching": false,
"fallback-colors": false,
"floats": false,
"ids": false,
"qualified-headings": false,
"selector-max": false,
"unique-headings": false,
"gradients": false,
"important": false,
"font-sizes": false,
}
},
cssbeautifier : {
files : ["styles.css"]
},
autoprefixer: {
options: {
browsers: [
'Android 2.3',
'Android >= 4',
'Chrome >= 20',
'Firefox >= 24', // Firefox 24 is the latest ESR.
'Explorer >= 9',
'iOS >= 6',
'Opera >= 12.1',
'Safari >= 6'
]
},
core: {
options: {
map: false
},
src: ['styles.css'],
},
},
exec: {
decache: {
cmd: "php -r '" + decachephp + "'",
callback: function(error, stdout, stderror) {
// Exec will output error messages.
// Just add one to confirm success.
if (!error) {
grunt.log.writeln("Moodle theme cache reset.");
}
}
}
},
watch: {
// Watch for any changes to sass files and compile.
files: ["sass/*.scss"],
tasks: ["compile"],
options: {
spawn: false
}
}
});

// Load contrib tasks.
grunt.loadNpmTasks("grunt-autoprefixer");
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-cssbeautifier');
grunt.loadNpmTasks('grunt-contrib-csslint');
grunt.loadNpmTasks("grunt-sass");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-exec");

// Register tasks.
grunt.registerTask("default", ["watch"]);
grunt.registerTask("compile", ["sass:oembed", "autoprefixer", "cssbeautifier", "decache"]);
grunt.registerTask("decache", ["exec:decache"]);
};
52 changes: 0 additions & 52 deletions filter/oembed/README.md

This file was deleted.

33 changes: 33 additions & 0 deletions filter/oembed/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Description:
This is a text filter for Moodle that converts urls from many different media sites into embeded content.
Embed code is retrieved from the original site so should work even if the site changes embed format.

Installation:
Download the source files. (zip file is available under download section)
Unzip the package
Copy the "oembed" folder to moodle/filter on the Moodle server.
Login as an admin on the Moodle site and install the filter.

Upgrading from earlier versions:
Upgrade per normal procedures. Your settings from earlier plugins will be preserved.
NOTE - Embed providers may change the text that identifies them. It is possible that media embedded previously on your site no
longer meets the provider text definitions, and as such, may not show up as embedded media. Check the provider definition to see
if the media link needs to change.

To use:
Under Plugins > Filters > Oembed Filter / Settings, you can choose:
- The type of tag to identify the embedded media.
- To delay the media loading or load it immediately.
By default the oembed filter disables all providers.
You can change this under Plugins > Filters > Oembed Filter / Manage providers.

When inserting a media link url into a discussion, create a hyperlink and insert the url as the target.
When the discussion is posted the url will be changed into the embed content.
N.B. if you enable the "Convert URLs into links and images" filter ahead of this then it is easier for users to embed media.

The embedded media providers are in three groups:
- Downloaded from http://oembed.com/providers.json. This is the main repository that manages Oembed provider definitions.
These are updated regularly in the cron job, and can change.
- Plugins provided to extend media providers provided in earlier versions of the plugin, but not contained in the provider repo.
- Local providers which allow a site administrator to save a downloaded one locally, so that it does not change with download
updates. This also allows new providers to be created that are not part of the omebed repo.
Loading

0 comments on commit 0eb4d66

Please sign in to comment.