commit
3e895d5a38
90 changed files with 9331 additions and 0 deletions
@ -0,0 +1 @@ |
|||
amd/src/list.js |
@ -0,0 +1,22 @@ |
|||
# Auto detect text files and perform LF normalization |
|||
* text=auto |
|||
|
|||
# Custom for Visual Studio |
|||
*.cs diff=csharp |
|||
*.sln merge=union |
|||
*.csproj merge=union |
|||
*.vbproj merge=union |
|||
*.fsproj merge=union |
|||
*.dbproj merge=union |
|||
|
|||
# Standard to msysgit |
|||
*.doc diff=astextplain |
|||
*.DOC diff=astextplain |
|||
*.docx diff=astextplain |
|||
*.DOCX diff=astextplain |
|||
*.dot diff=astextplain |
|||
*.DOT diff=astextplain |
|||
*.pdf diff=astextplain |
|||
*.PDF diff=astextplain |
|||
*.rtf diff=astextplain |
|||
*.RTF diff=astextplain |
@ -0,0 +1,42 @@ |
|||
# Windows image file caches |
|||
Thumbs.db |
|||
ehthumbs.db |
|||
|
|||
# Folder config file |
|||
Desktop.ini |
|||
|
|||
# Recycle Bin used on file shares |
|||
$RECYCLE.BIN/ |
|||
|
|||
# Windows Installer files |
|||
*.cab |
|||
*.msi |
|||
*.msm |
|||
*.msp |
|||
|
|||
# ========================= |
|||
# Operating System Files |
|||
# ========================= |
|||
|
|||
# OSX |
|||
# ========================= |
|||
|
|||
.DS_Store |
|||
.AppleDouble |
|||
.LSOverride |
|||
|
|||
# Icon must ends with two \r. |
|||
Icon |
|||
|
|||
|
|||
# Thumbnails |
|||
._* |
|||
|
|||
# Files that might appear on external disk |
|||
.Spotlight-V100 |
|||
.Trashes |
|||
.idea |
|||
|
|||
# Grunt stuff |
|||
.sass-cache |
|||
node_modules |
@ -0,0 +1 @@ |
|||
amd/src/list.js |
@ -0,0 +1,7 @@ |
|||
{ |
|||
"extends": "../../.jshintrc", |
|||
"globals": { |
|||
"$": false, |
|||
"console": false |
|||
} |
|||
} |
@ -0,0 +1,62 @@ |
|||
language: php |
|||
|
|||
# We use trusty as currently there is an issue with java and moodle-plugin-ci mustache linting which |
|||
# causes causes tests to fail on xenial and bionic. (See https://github.com/blackboard-open-source/moodle-plugin-ci/issues/91). |
|||
dist: trusty |
|||
|
|||
sudo: true |
|||
|
|||
addons: |
|||
firefox: "47.0.1" |
|||
postgresql: "9.4" |
|||
mysql: "8.0.2" |
|||
apt: |
|||
packages: |
|||
- openjdk-8-jre-headless |
|||
|
|||
services: mysql |
|||
|
|||
cache: |
|||
directories: |
|||
- $HOME/.composer/cache |
|||
- $HOME/.npm |
|||
|
|||
php: |
|||
- 7.1 |
|||
- 7.2 |
|||
|
|||
env: |
|||
- MOODLE_BRANCH=MOODLE_38_STABLE DB=pgsql |
|||
- MOODLE_BRANCH=MOODLE_38_STABLE DB=mysqli |
|||
|
|||
matrix: |
|||
exclude: |
|||
- php: 7.1 |
|||
env: MOODLE_BRANCH=MOODLE_38_STABLE DB=mysqli |
|||
- php: 7.2 |
|||
env: MOODLE_BRANCH=MOODLE_38_STABLE DB=pgsql |
|||
|
|||
before_install: |
|||
- phpenv config-rm xdebug.ini |
|||
- nvm install 8.9 |
|||
- nvm use 8.9 |
|||
- cd ../.. |
|||
- composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2 |
|||
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" |
|||
|
|||
install: |
|||
- moodle-plugin-ci install |
|||
- moodle-plugin-ci add-config '$CFG->curlsecurityallowedport = "";' |
|||
- moodle-plugin-ci add-config '$CFG->curlsecurityblockedhosts = "";' |
|||
|
|||
script: |
|||
- moodle-plugin-ci phplint |
|||
- moodle-plugin-ci phpcpd |
|||
- moodle-plugin-ci phpmd |
|||
- moodle-plugin-ci codechecker |
|||
- moodle-plugin-ci validate |
|||
- moodle-plugin-ci savepoints |
|||
- moodle-plugin-ci mustache |
|||
- moodle-plugin-ci grunt |
|||
- moodle-plugin-ci phpunit |
|||
- moodle-plugin-ci behat |
@ -0,0 +1,6 @@ |
|||
Release Notes |
|||
|
|||
Release 3.8.0 (Build 2019112600) |
|||
Updated subplugin declaration file to new subplugins.json structure. |
|||
|
|||
(see CHANGES.TXT in release 3.3 for earlier changes.) |
@ -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"]); |
|||
}; |
@ -0,0 +1,674 @@ |
|||
GNU GENERAL PUBLIC LICENSE |
|||
Version 3, 29 June 2007 |
|||
|
|||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
|||
Everyone is permitted to copy and distribute verbatim copies |
|||
of this license document, but changing it is not allowed. |
|||
|
|||
Preamble |
|||
|
|||
The GNU General Public License is a free, copyleft license for |
|||
software and other kinds of works. |
|||
|
|||
The licenses for most software and other practical works are designed |
|||
to take away your freedom to share and change the works. By contrast, |
|||
the GNU General Public License is intended to guarantee your freedom to |
|||
share and change all versions of a program--to make sure it remains free |
|||
software for all its users. We, the Free Software Foundation, use the |
|||
GNU General Public License for most of our software; it applies also to |
|||
any other work released this way by its authors. You can apply it to |
|||
your programs, too. |
|||
|
|||
When we speak of free software, we are referring to freedom, not |
|||
price. Our General Public Licenses are designed to make sure that you |
|||
have the freedom to distribute copies of free software (and charge for |
|||
them if you wish), that you receive source code or can get it if you |
|||
want it, that you can change the software or use pieces of it in new |
|||
free programs, and that you know you can do these things. |
|||
|
|||
To protect your rights, we need to prevent others from denying you |
|||
these rights or asking you to surrender the rights. Therefore, you have |
|||
certain responsibilities if you distribute copies of the software, or if |
|||
you modify it: responsibilities to respect the freedom of others. |
|||
|
|||
For example, if you distribute copies of such a program, whether |
|||
gratis or for a fee, you must pass on to the recipients the same |
|||
freedoms that you received. You must make sure that they, too, receive |
|||
or can get the source code. And you must show them these terms so they |
|||
know their rights. |
|||
|
|||
Developers that use the GNU GPL protect your rights with two steps: |
|||
(1) assert copyright on the software, and (2) offer you this License |
|||
giving you legal permission to copy, distribute and/or modify it. |
|||
|
|||
For the developers' and authors' protection, the GPL clearly explains |
|||
that there is no warranty for this free software. For both users' and |
|||
authors' sake, the GPL requires that modified versions be marked as |
|||
changed, so that their problems will not be attributed erroneously to |
|||
authors of previous versions. |
|||
|
|||
Some devices are designed to deny users access to install or run |
|||
modified versions of the software inside them, although the manufacturer |
|||
can do so. This is fundamentally incompatible with the aim of |
|||
protecting users' freedom to change the software. The systematic |
|||
pattern of such abuse occurs in the area of products for individuals to |
|||
use, which is precisely where it is most unacceptable. Therefore, we |
|||
have designed this version of the GPL to prohibit the practice for those |
|||
products. If such problems arise substantially in other domains, we |
|||
stand ready to extend this provision to those domains in future versions |
|||
of the GPL, as needed to protect the freedom of users. |
|||
|
|||
Finally, every program is threatened constantly by software patents. |
|||
States should not allow patents to restrict development and use of |
|||
software on general-purpose computers, but in those that do, we wish to |
|||
avoid the special danger that patents applied to a free program could |
|||
make it effectively proprietary. To prevent this, the GPL assures that |
|||
patents cannot be used to render the program non-free. |
|||
|
|||
The precise terms and conditions for copying, distribution and |
|||
modification follow. |
|||
|
|||
TERMS AND CONDITIONS |
|||
|
|||
0. Definitions. |
|||
|
|||
"This License" refers to version 3 of the GNU General Public License. |
|||
|
|||
"Copyright" also means copyright-like laws that apply to other kinds of |
|||
works, such as semiconductor masks. |
|||
|
|||
"The Program" refers to any copyrightable work licensed under this |
|||
License. Each licensee is addressed as "you". "Licensees" and |
|||
"recipients" may be individuals or organizations. |
|||
|
|||
To "modify" a work means to copy from or adapt all or part of the work |
|||
in a fashion requiring copyright permission, other than the making of an |
|||
exact copy. The resulting work is called a "modified version" of the |
|||
earlier work or a work "based on" the earlier work. |
|||
|
|||
A "covered work" means either the unmodified Program or a work based |
|||
on the Program. |
|||
|
|||
To "propagate" a work means to do anything with it that, without |
|||
permission, would make you directly or secondarily liable for |
|||
infringement under applicable copyright law, except executing it on a |
|||
computer or modifying a private copy. Propagation includes copying, |
|||
distribution (with or without modification), making available to the |
|||
public, and in some countries other activities as well. |
|||
|
|||
To "convey" a work means any kind of propagation that enables other |
|||
parties to make or receive copies. Mere interaction with a user through |
|||
a computer network, with no transfer of a copy, is not conveying. |
|||
|
|||
An interactive user interface displays "Appropriate Legal Notices" |
|||
to the extent that it includes a convenient and prominently visible |
|||
feature that (1) displays an appropriate copyright notice, and (2) |
|||
tells the user that there is no warranty for the work (except to the |
|||
extent that warranties are provided), that licensees may convey the |
|||
work under this License, and how to view a copy of this License. If |
|||
the interface presents a list of user commands or options, such as a |
|||
menu, a prominent item in the list meets this criterion. |
|||
|
|||
1. Source Code. |
|||
|
|||
The "source code" for a work means the preferred form of the work |
|||
for making modifications to it. "Object code" means any non-source |
|||
form of a work. |
|||
|
|||
A "Standard Interface" means an interface that either is an official |
|||
standard defined by a recognized standards body, or, in the case of |
|||
interfaces specified for a particular programming language, one that |
|||
is widely used among developers working in that language. |
|||
|
|||
The "System Libraries" of an executable work include anything, other |
|||
than the work as a whole, that (a) is included in the normal form of |
|||
packaging a Major Component, but which is not part of that Major |
|||
Component, and (b) serves only to enable use of the work with that |
|||
Major Component, or to implement a Standard Interface for which an |
|||
implementation is available to the public in source code form. A |
|||
"Major Component", in this context, means a major essential component |
|||
(kernel, window system, and so on) of the specific operating system |
|||
(if any) on which the executable work runs, or a compiler used to |
|||
produce the work, or an object code interpreter used to run it. |
|||
|
|||
The "Corresponding Source" for a work in object code form means all |
|||
the source code needed to generate, install, and (for an executable |
|||
work) run the object code and to modify the work, including scripts to |
|||
control those activities. However, it does not include the work's |
|||
System Libraries, or general-purpose tools or generally available free |
|||
programs which are used unmodified in performing those activities but |
|||
which are not part of the work. For example, Corresponding Source |
|||
includes interface definition files associated with source files for |
|||
the work, and the source code for shared libraries and dynamically |
|||
linked subprograms that the work is specifically designed to require, |
|||
such as by intimate data communication or control flow between those |
|||
subprograms and other parts of the work. |
|||
|
|||
The Corresponding Source need not include anything that users |
|||
can regenerate automatically from other parts of the Corresponding |
|||
Source. |
|||
|
|||
The Corresponding Source for a work in source code form is that |
|||
same work. |
|||
|
|||
2. Basic Permissions. |
|||
|
|||
All rights granted under this License are granted for the term of |
|||
copyright on the Program, and are irrevocable provided the stated |
|||
conditions are met. This License explicitly affirms your unlimited |
|||
permission to run the unmodified Program. The output from running a |
|||
covered work is covered by this License only if the output, given its |
|||
content, constitutes a covered work. This License acknowledges your |
|||
rights of fair use or other equivalent, as provided by copyright law. |
|||
|
|||
You may make, run and propagate covered works that you do not |
|||
convey, without conditions so long as your license otherwise remains |
|||
in force. You may convey covered works to others for the sole purpose |
|||
of having them make modifications exclusively for you, or provide you |
|||
with facilities for running those works, provided that you comply with |
|||
the terms of this License in conveying all material for which you do |
|||
not control copyright. Those thus making or running the covered works |
|||
for you must do so exclusively on your behalf, under your direction |
|||
and control, on terms that prohibit them from making any copies of |
|||
your copyrighted material outside their relationship with you. |
|||
|
|||
Conveying under any other circumstances is permitted solely under |
|||
the conditions stated below. Sublicensing is not allowed; section 10 |
|||
makes it unnecessary. |
|||
|
|||
3. Protecting Users' Legal Rights From Anti-Circumvention Law. |
|||
|
|||
No covered work shall be deemed part of an effective technological |
|||
measure under any applicable law fulfilling obligations under article |
|||
11 of the WIPO copyright treaty adopted on 20 December 1996, or |
|||
similar laws prohibiting or restricting circumvention of such |
|||
measures. |
|||
|
|||
When you convey a covered work, you waive any legal power to forbid |
|||
circumvention of technological measures to the extent such circumvention |
|||
is effected by exercising rights under this License with respect to |
|||
the covered work, and you disclaim any intention to limit operation or |
|||
modification of the work as a means of enforcing, against the work's |
|||
users, your or third parties' legal rights to forbid circumvention of |
|||
technological measures. |
|||
|
|||
4. Conveying Verbatim Copies. |
|||
|
|||
You may convey verbatim copies of the Program's source code as you |
|||
receive it, in any medium, provided that you conspicuously and |
|||
appropriately publish on each copy an appropriate copyright notice; |
|||
keep intact all notices stating that this License and any |
|||
non-permissive terms added in accord with section 7 apply to the code; |
|||
keep intact all notices of the absence of any warranty; and give all |
|||
recipients a copy of this License along with the Program. |
|||
|
|||
You may charge any price or no price for each copy that you convey, |
|||
and you may offer support or warranty protection for a fee. |
|||
|
|||
5. Conveying Modified Source Versions. |
|||
|
|||
You may convey a work based on the Program, or the modifications to |
|||
produce it from the Program, in the form of source code under the |
|||
terms of section 4, provided that you also meet all of these conditions: |
|||
|
|||
a) The work must carry prominent notices stating that you modified |
|||
it, and giving a relevant date. |
|||
|
|||
b) The work must carry prominent notices stating that it is |
|||
released under this License and any conditions added under section |
|||
7. This requirement modifies the requirement in section 4 to |
|||
"keep intact all notices". |
|||
|
|||
c) You must license the entire work, as a whole, under this |
|||
License to anyone who comes into possession of a copy. This |
|||
License will therefore apply, along with any applicable section 7 |
|||
additional terms, to the whole of the work, and all its parts, |
|||
regardless of how they are packaged. This License gives no |
|||
permission to license the work in any other way, but it does not |
|||
invalidate such permission if you have separately received it. |
|||
|
|||
d) If the work has interactive user interfaces, each must display |
|||
Appropriate Legal Notices; however, if the Program has interactive |
|||
interfaces that do not display Appropriate Legal Notices, your |
|||
work need not make them do so. |
|||
|
|||
A compilation of a covered work with other separate and independent |
|||
works, which are not by their nature extensions of the covered work, |
|||
and which are not combined with it such as to form a larger program, |
|||
in or on a volume of a storage or distribution medium, is called an |
|||
"aggregate" if the compilation and its resulting copyright are not |
|||
used to limit the access or legal rights of the compilation's users |
|||
beyond what the individual works permit. Inclusion of a covered work |
|||
in an aggregate does not cause this License to apply to the other |
|||
parts of the aggregate. |
|||
|
|||
6. Conveying Non-Source Forms. |
|||
|
|||
You may convey a covered work in object code form under the terms |
|||
of sections 4 and 5, provided that you also convey the |
|||
machine-readable Corresponding Source under the terms of this License, |
|||
in one of these ways: |
|||
|
|||
a) Convey the object code in, or embodied in, a physical product |
|||
(including a physical distribution medium), accompanied by the |
|||
Corresponding Source fixed on a durable physical medium |
|||
customarily used for software interchange. |
|||
|
|||
b) Convey the object code in, or embodied in, a physical product |
|||
(including a physical distribution medium), accompanied by a |
|||
written offer, valid for at least three years and valid for as |
|||
long as you offer spare parts or customer support for that product |
|||
model, to give anyone who possesses the object code either (1) a |
|||
copy of the Corresponding Source for all the software in the |
|||
product that is covered by this License, on a durable physical |
|||
medium customarily used for software interchange, for a price no |
|||
more than your reasonable cost of physically performing this |
|||
conveying of source, or (2) access to copy the |
|||
Corresponding Source from a network server at no charge. |
|||
|
|||
c) Convey individual copies of the object code with a copy of the |
|||
written offer to provide the Corresponding Source. This |
|||
alternative is allowed only occasionally and noncommercially, and |
|||
only if you received the object code with such an offer, in accord |
|||
with subsection 6b. |
|||
|
|||
d) Convey the object code by offering access from a designated |
|||
place (gratis or for a charge), and offer equivalent access to the |
|||
Corresponding Source in the same way through the same place at no |
|||
further charge. You need not require recipients to copy the |
|||
Corresponding Source along with the object code. If the place to |
|||
copy the object code is a network server, the Corresponding Source |
|||
may be on a different server (operated by you or a third party) |
|||
that supports equivalent copying facilities, provided you maintain |
|||
clear directions next to the object code saying where to find the |
|||
Corresponding Source. Regardless of what server hosts the |
|||
Corresponding Source, you remain obligated to ensure that it is |
|||
available for as long as needed to satisfy these requirements. |
|||
|
|||
e) Convey the object code using peer-to-peer transmission, provided |
|||
you inform other peers where the object code and Corresponding |
|||
Source of the work are being offered to the general public at no |
|||
charge under subsection 6d. |
|||
|
|||
A separable portion of the object code, whose source code is excluded |
|||
from the Corresponding Source as a System Library, need not be |
|||
included in conveying the object code work. |
|||
|
|||
A "User Product" is either (1) a "consumer product", which means any |
|||
tangible personal property which is normally used for personal, family, |
|||
or household purposes, or (2) anything designed or sold for incorporation |
|||
into a dwelling. In determining whether a product is a consumer product, |
|||
doubtful cases shall be resolved in favor of coverage. For a particular |
|||
product received by a particular user, "normally used" refers to a |
|||
typical or common use of that class of product, regardless of the status |
|||
of the particular user or of the way in which the particular user |
|||
actually uses, or expects or is expected to use, the product. A product |
|||
is a consumer product regardless of whether the product has substantial |
|||
commercial, industrial or non-consumer uses, unless such uses represent |
|||
the only significant mode of use of the product. |
|||
|
|||
"Installation Information" for a User Product means any methods, |
|||
procedures, authorization keys, or other information required to install |
|||
and execute modified versions of a covered work in that User Product from |
|||
a modified version of its Corresponding Source. The information must |
|||
suffice to ensure that the continued functioning of the modified object |
|||
code is in no case prevented or interfered with solely because |
|||
modification has been made. |
|||
|
|||
If you convey an object code work under this section in, or with, or |
|||
specifically for use in, a User Product, and the conveying occurs as |
|||
part of a transaction in which the right of possession and use of the |
|||
User Product is transferred to the recipient in perpetuity or for a |
|||
fixed term (regardless of how the transaction is characterized), the |
|||
Corresponding Source conveyed under this section must be accompanied |
|||
by the Installation Information. But this requirement does not apply |
|||
if neither you nor any third party retains the ability to install |
|||
modified object code on the User Product (for example, the work has |
|||
been installed in ROM). |
|||
|
|||
The requirement to provide Installation Information does not include a |
|||
requirement to continue to provide support service, warranty, or updates |
|||
for a work that has been modified or installed by the recipient, or for |
|||
the User Product in which it has been modified or installed. Access to a |
|||
network may be denied when the modification itself materially and |
|||
adversely affects the operation of the network or violates the rules and |
|||
protocols for communication across the network. |
|||
|
|||
Corresponding Source conveyed, and Installation Information provided, |
|||
in accord with this section must be in a format that is publicly |
|||
documented (and with an implementation available to the public in |
|||
source code form), and must require no special password or key for |
|||
unpacking, reading or copying. |
|||
|
|||
7. Additional Terms. |
|||
|
|||
"Additional permissions" are terms that supplement the terms of this |
|||
License by making exceptions from one or more of its conditions. |
|||
Additional permissions that are applicable to the entire Program shall |
|||
be treated as though they were included in this License, to the extent |
|||
that they are valid under applicable law. If additional permissions |
|||
apply only to part of the Program, that part may be used separately |
|||
under those permissions, but the entire Program remains governed by |
|||
this License without regard to the additional permissions. |
|||
|
|||
When you convey a copy of a covered work, you may at your option |
|||
remove any additional permissions from that copy, or from any part of |
|||
it. (Additional permissions may be written to require their own |
|||
removal in certain cases when you modify the work.) You may place |
|||
additional permissions on material, added by you to a covered work, |
|||
for which you have or can give appropriate copyright permission. |
|||
|
|||
Notwithstanding any other provision of this License, for material you |
|||
add to a covered work, you may (if authorized by the copyright holders of |
|||
that material) supplement the terms of this License with terms: |
|||
|
|||
a) Disclaiming warranty or limiting liability differently from the |
|||
terms of sections 15 and 16 of this License; or |
|||
|
|||
b) Requiring preservation of specified reasonable legal notices or |
|||
author attributions in that material or in the Appropriate Legal |
|||
Notices displayed by works containing it; or |
|||
|
|||
c) Prohibiting misrepresentation of the origin of that material, or |
|||
requiring that modified versions of such material be marked in |
|||
reasonable ways as different from the original version; or |
|||
|
|||
d) Limiting the use for publicity purposes of names of licensors or |
|||
authors of the material; or |
|||
|
|||
e) Declining to grant rights under trademark law for use of some |
|||
trade names, trademarks, or service marks; or |
|||
|
|||
f) Requiring indemnification of licensors and authors of that |
|||
material by anyone who conveys the material (or modified versions of |
|||
it) with contractual assumptions of liability to the recipient, for |
|||
any liability that these contractual assumptions directly impose on |
|||
those licensors and authors. |
|||
|
|||
All other non-permissive additional terms are considered "further |
|||
restrictions" within the meaning of section 10. If the Program as you |
|||
received it, or any part of it, contains a notice stating that it is |
|||
governed by this License along with a term that is a further |
|||
restriction, you may remove that term. If a license document contains |
|||
a further restriction but permits relicensing or conveying under this |
|||
License, you may add to a covered work material governed by the terms |
|||
of that license document, provided that the further restriction does |
|||
not survive such relicensing or conveying. |
|||
|
|||
If you add terms to a covered work in accord with this section, you |
|||
must place, in the relevant source files, a statement of the |
|||
additional terms that apply to those files, or a notice indicating |
|||
where to find the applicable terms. |
|||
|
|||
Additional terms, permissive or non-permissive, may be stated in the |
|||
form of a separately written license, or stated as exceptions; |
|||
the above requirements apply either way. |
|||
|
|||
8. Termination. |
|||
|
|||
You may not propagate or modify a covered work except as expressly |
|||
provided under this License. Any attempt otherwise to propagate or |
|||
modify it is void, and will automatically terminate your rights under |
|||
this License (including any patent licenses granted under the third |
|||
paragraph of section 11). |
|||
|
|||
However, if you cease all violation of this License, then your |
|||
license from a particular copyright holder is reinstated (a) |
|||
provisionally, unless and until the copyright holder explicitly and |
|||
finally terminates your license, and (b) permanently, if the copyright |
|||
holder fails to notify you of the violation by some reasonable means |
|||
prior to 60 days after the cessation. |
|||
|
|||
Moreover, your license from a particular copyright holder is |
|||
reinstated permanently if the copyright holder notifies you of the |
|||
violation by some reasonable means, this is the first time you have |
|||
received notice of violation of this License (for any work) from that |
|||
copyright holder, and you cure the violation prior to 30 days after |
|||
your receipt of the notice. |
|||
|
|||
Termination of your rights under this section does not terminate the |
|||
licenses of parties who have received copies or rights from you under |
|||
this License. If your rights have been terminated and not permanently |
|||
reinstated, you do not qualify to receive new licenses for the same |
|||
material under section 10. |
|||
|
|||
9. Acceptance Not Required for Having Copies. |
|||
|
|||
You are not required to accept this License in order to receive or |
|||
run a copy of the Program. Ancillary propagation of a covered work |
|||
occurring solely as a consequence of using peer-to-peer transmission |
|||
to receive a copy likewise does not require acceptance. However, |
|||
nothing other than this License grants you permission to propagate or |
|||
modify any covered work. These actions infringe copyright if you do |
|||
not accept this License. Therefore, by modifying or propagating a |
|||
covered work, you indicate your acceptance of this License to do so. |
|||
|
|||
10. Automatic Licensing of Downstream Recipients. |
|||
|
|||
Each time you convey a covered work, the recipient automatically |
|||
receives a license from the original licensors, to run, modify and |
|||
propagate that work, subject to this License. You are not responsible |
|||
for enforcing compliance by third parties with this License. |
|||
|
|||
An "entity transaction" is a transaction transferring control of an |
|||
organization, or substantially all assets of one, or subdividing an |
|||
organization, or merging organizations. If propagation of a covered |
|||
work results from an entity transaction, each party to that |
|||
transaction who receives a copy of the work also receives whatever |
|||
licenses to the work the party's predecessor in interest had or could |
|||
give under the previous paragraph, plus a right to possession of the |
|||
Corresponding Source of the work from the predecessor in interest, if |
|||
the predecessor has it or can get it with reasonable efforts. |
|||
|
|||
You may not impose any further restrictions on the exercise of the |
|||
rights granted or affirmed under this License. For example, you may |
|||
not impose a license fee, royalty, or other charge for exercise of |
|||
rights granted under this License, and you may not initiate litigation |
|||
(including a cross-claim or counterclaim in a lawsuit) alleging that |
|||
any patent claim is infringed by making, using, selling, offering for |
|||
sale, or importing the Program or any portion of it. |
|||
|
|||
11. Patents. |
|||
|
|||
A "contributor" is a copyright holder who authorizes use under this |
|||
License of the Program or a work on which the Program is based. The |
|||
work thus licensed is called the contributor's "contributor version". |
|||
|
|||
A contributor's "essential patent claims" are all patent claims |
|||
owned or controlled by the contributor, whether already acquired or |
|||
hereafter acquired, that would be infringed by some manner, permitted |
|||
by this License, of making, using, or selling its contributor version, |
|||
but do not include claims that would be infringed only as a |
|||
consequence of further modification of the contributor version. For |
|||
purposes of this definition, "control" includes the right to grant |
|||
patent sublicenses in a manner consistent with the requirements of |
|||
this License. |
|||
|
|||
Each contributor grants you a non-exclusive, worldwide, royalty-free |
|||
patent license under the contributor's essential patent claims, to |
|||
make, use, sell, offer for sale, import and otherwise run, modify and |
|||
propagate the contents of its contributor version. |
|||
|
|||
In the following three paragraphs, a "patent license" is any express |
|||
agreement or commitment, however denominated, not to enforce a patent |
|||
(such as an express permission to practice a patent or covenant not to |
|||
sue for patent infringement). To "grant" such a patent license to a |
|||
party means to make such an agreement or commitment not to enforce a |
|||
patent against the party. |
|||
|
|||
If you convey a covered work, knowingly relying on a patent license, |
|||
and the Corresponding Source of the work is not available for anyone |
|||
to copy, free of charge and under the terms of this License, through a |
|||
publicly available network server or other readily accessible means, |
|||
then you must either (1) cause the Corresponding Source to be so |
|||
available, or (2) arrange to deprive yourself of the benefit of the |
|||
patent license for this particular work, or (3) arrange, in a manner |
|||
consistent with the requirements of this License, to extend the patent |
|||
license to downstream recipients. "Knowingly relying" means you have |
|||
actual knowledge that, but for the patent license, your conveying the |
|||
covered work in a country, or your recipient's use of the covered work |
|||
in a country, would infringe one or more identifiable patents in that |
|||
country that you have reason to believe are valid. |
|||
|
|||
If, pursuant to or in connection with a single transaction or |
|||
arrangement, you convey, or propagate by procuring conveyance of, a |
|||
covered work, and grant a patent license to some of the parties |
|||
receiving the covered work authorizing them to use, propagate, modify |
|||
or convey a specific copy of the covered work, then the patent license |
|||
you grant is automatically extended to all recipients of the covered |
|||
work and works based on it. |
|||
|
|||
A patent license is "discriminatory" if it does not include within |
|||
the scope of its coverage, prohibits the exercise of, or is |
|||
conditioned on the non-exercise of one or more of the rights that are |
|||
specifically granted under this License. You may not convey a covered |
|||
work if you are a party to an arrangement with a third party that is |
|||
in the business of distributing software, under which you make payment |
|||
to the third party based on the extent of your activity of conveying |
|||
the work, and under which the third party grants, to any of the |
|||
parties who would receive the covered work from you, a discriminatory |
|||
patent license (a) in connection with copies of the covered work |
|||
conveyed by you (or copies made from those copies), or (b) primarily |
|||
for and in connection with specific products or compilations that |
|||
contain the covered work, unless you entered into that arrangement, |
|||
or that patent license was granted, prior to 28 March 2007. |
|||
|
|||
Nothing in this License shall be construed as excluding or limiting |
|||
any implied license or other defenses to infringement that may |
|||
otherwise be available to you under applicable patent law. |
|||
|
|||
12. No Surrender of Others' Freedom. |
|||
|
|||
If conditions are imposed on you (whether by court order, agreement or |
|||
otherwise) that contradict the conditions of this License, they do not |
|||
excuse you from the conditions of this License. If you cannot convey a |
|||
covered work so as to satisfy simultaneously your obligations under this |
|||
License and any other pertinent obligations, then as a consequence you may |
|||
not convey it at all. For example, if you agree to terms that obligate you |
|||
to collect a royalty for further conveying from those to whom you convey |
|||
the Program, the only way you could satisfy both those terms and this |
|||
License would be to refrain entirely from conveying the Program. |
|||
|
|||
13. Use with the GNU Affero General Public License. |
|||
|
|||
Notwithstanding any other provision of this License, you have |
|||
permission to link or combine any covered work with a work licensed |
|||
under version 3 of the GNU Affero General Public License into a single |
|||
combined work, and to convey the resulting work. The terms of this |
|||
License will continue to apply to the part which is the covered work, |
|||
but the special requirements of the GNU Affero General Public License, |
|||
section 13, concerning interaction through a network will apply to the |
|||
combination as such. |
|||
|
|||
14. Revised Versions of this License. |
|||
|
|||
The Free Software Foundation may publish revised and/or new versions of |
|||
the GNU General Public License from time to time. Such new versions will |
|||
be similar in spirit to the present version, but may differ in detail to |
|||
address new problems or concerns. |
|||
|
|||
Each version is given a distinguishing version number. If the |
|||
Program specifies that a certain numbered version of the GNU General |
|||
Public License "or any later version" applies to it, you have the |
|||
option of following the terms and conditions either of that numbered |
|||
version or of any later version published by the Free Software |
|||
Foundation. If the Program does not specify a version number of the |
|||
GNU General Public License, you may choose any version ever published |
|||
by the Free Software Foundation. |
|||
|
|||
If the Program specifies that a proxy can decide which future |
|||
versions of the GNU General Public License can be used, that proxy's |
|||
public statement of acceptance of a version permanently authorizes you |
|||
to choose that version for the Program. |
|||
|
|||
Later license versions may give you additional or different |
|||
permissions. However, no additional obligations are imposed on any |
|||
author or copyright holder as a result of your choosing to follow a |
|||
later version. |
|||
|
|||
15. Disclaimer of Warranty. |
|||
|
|||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY |
|||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT |
|||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY |
|||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, |
|||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM |
|||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF |
|||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
|||
|
|||
16. Limitation of Liability. |
|||
|
|||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
|||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS |
|||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY |
|||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE |
|||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF |
|||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD |
|||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), |
|||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
|||
SUCH DAMAGES. |
|||
|
|||
17. Interpretation of Sections 15 and 16. |
|||
|
|||
If the disclaimer of warranty and limitation of liability provided |
|||
above cannot be given local legal effect according to their terms, |
|||
reviewing courts shall apply local law that most closely approximates |
|||
an absolute waiver of all civil liability in connection with the |
|||
Program, unless a warranty or assumption of liability accompanies a |
|||
copy of the Program in return for a fee. |
|||
|
|||
END OF TERMS AND CONDITIONS |
|||
|
|||
How to Apply These Terms to Your New Programs |
|||
|
|||
If you develop a new program, and you want it to be of the greatest |
|||
possible use to the public, the best way to achieve this is to make it |
|||
free software which everyone can redistribute and change under these terms. |
|||
|
|||
To do so, attach the following notices to the program. It is safest |
|||
to attach them to the start of each source file to most effectively |
|||
state the exclusion of warranty; and each file should have at least |
|||
the "copyright" line and a pointer to where the full notice is found. |
|||
|
|||
<one line to give the program's name and a brief idea of what it does.> |
|||
Copyright (C) <year> <name of author> |
|||
|
|||
This program is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
Also add information on how to contact you by electronic and paper mail. |
|||
|
|||
If the program does terminal interaction, make it output a short |
|||
notice like this when it starts in an interactive mode: |
|||
|
|||
<program> Copyright (C) <year> <name of author> |
|||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
|||
This is free software, and you are welcome to redistribute it |
|||
under certain conditions; type `show c' for details. |
|||
|
|||
The hypothetical commands `show w' and `show c' should show the appropriate |
|||
parts of the General Public License. Of course, your program's commands |
|||
might be different; for a GUI interface, you would use an "about box". |
|||
|
|||
You should also get your employer (if you work as a programmer) or school, |
|||
if any, to sign a "copyright disclaimer" for the program, if necessary. |
|||
For more information on this, and how to apply and follow the GNU GPL, see |
|||
<http://www.gnu.org/licenses/>. |
|||
|
|||
The GNU General Public License does not permit incorporating your program |
|||
into proprietary programs. If your program is a subroutine library, you |
|||
may consider it more useful to permit linking proprietary applications with |
|||
the library. If this is what you want to do, use the GNU Lesser General |
|||
Public License instead of this License. But first, please read |
|||
<http://www.gnu.org/philosophy/why-not-lgpl.html>. |
@ -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. |
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
|||
define(["jquery","core/notification","core/ajax","core/templates","core/fragment","core/str","filter_oembed/list"],function(a,b,c,d,e,f,g){return{prevEditId:null,reloadRow:function(e,f,g,h){g=g?g:"reload",c.call([{methodname:"filter_oembed_provider_manage",args:{pid:e,action:g},done:function(b){d.render("filter_oembed/managementpagerow",b.providermodel).done(function(b){a(f).replaceWith(b),f=a("#oembed-display-providers_"+e),"function"==typeof h&&h(f)})},fail:function(a){b.exception(a)}}],!0,!0)},reloadProviders:function(e){c.call([{methodname:"filter_oembed_providers",args:{scope:"all"},done:function(b){d.render("filter_oembed/managementpage",b).done(function(b){var c=a(a.parseHTML(b)).html();a("#providermanagement").html(c),"function"==typeof e&&e()})},fail:function(a){b.exception(a)}}],!0,!0)},listenEnableDisable:function(){var b=this;a("#providermanagement").on("click",".oembed-provider-actions .filter-oembed-visibility",function(c){c.preventDefault();var d=a(this).parents("tr")[0],e=a(d).data("pid"),f=!a(d).hasClass("dimmed_text"),g=f?"disable":"enable";b.reloadRow(e,d,g)})},listenDelete:function(){var d=function(d){var e=a(d).data("pid");c.call([{methodname:"filter_oembed_provider_manage",args:{pid:e,action:"delete"},done:function(){a(d).remove()},fail:function(a){b.exception(a)}}],!0,!0)};a("#providermanagement").on("click",".oembed-provider-actions .filter-oembed-delete",function(c){c.preventDefault();var e=a(this).parents("tr")[0],g=a(a(this).parents("td").find(".list-providername")[0]).text();f.get_strings([{key:"deleteprovidertitle",component:"filter_oembed"},{key:"deleteproviderconfirm",component:"filter_oembed",param:g},{key:"ok",component:"core"},{key:"cancel",component:"core"}]).done(function(a){var c=a[0],f=a[1],g=a[2],h=a[3];b.confirm(c,f,g,h,function(){d(e)})})})},listenEdit:function(){var b=this,c=function(b){var c="#oembed-display-providers_"+b;a(c).removeClass("oembed-provider-editing"),a(c+" form").remove(),a(c+" td div.alert").remove()},f=function(b,c,f){var g,h=new RegExp("(?:course-)(\\S)"),i=h.exec(a("body").attr("class")),j=parseInt(i[1]);g=c?{formdata:c,pid:b}:{pid:b},e.loadFragment("filter_oembed","provider",j,g).done(function(c,e){a("#oembed-display-providers_"+b).addClass("oembed-provider-editing"),d.replaceNodeContents(a("#oembed-display-providers_"+b+" .oembed-provider-details"),c,e),"function"==typeof f&&f()})};a("#providermanagement").on("click",".oembed-provider-actions .filter-oembed-edit",function(d){d.preventDefault();var e=a(this).parents("tr")[0],g=a(e).data("pid");null!==b.prevEditId&&(c(b.prevEditId),c(g)),b.prevEditId=g,f(g)}),a("#providermanagement").on("click",".oembed-provider-details form #id_submitbutton",function(d){d.preventDefault();var e=a(this).parents("tr")[0],g=a(e).data("pid"),h=a(this).parents("form")[0],i=a(h).find('input[name="source"]').val();a(h).trigger("save-form-state");var j=a(h).serialize();f(g,j,function(){var d="#oembed-display-providers_"+g+" .oembed-provider-details",f=d+" div.alert-success",h=a(f);if(h.length){var j=h[0].outerHTML;if(c(g),i.indexOf("download::")>-1){var k=d+" .js-oembed-newprovider",l=a(k);l.length&&(g=l.data("newproviderid"))}var m=function(){var b=a("#oembed-display-providers_"+g+" td");a(b).append(j),a(b).find(" div.alert-success").attr("tabindex",-1),a(b).find(" div.alert-success").focus()};i.indexOf("download::")>-1?b.reloadProviders(m):b.reloadRow(g,e,"reload",m)}})}),a("#providermanagement").on("click",".oembed-provider-details form #id_cancel",function(b){b.preventDefault();var d=a(this).parents("tr")[0];c(a(d).data("pid"))})},init:function(){var a={valueNames:["list-providername"]};new g("providermanagement",a),this.listenEnableDisable(),this.listenDelete(),this.listenEdit()}}}); |
@ -0,0 +1 @@ |
|||
define(["jquery","filter_oembed/preloader","filter_oembed/responsivecontent"],function(a,b,c){return{init:function(){var d=function(){var b=function(b){return!!b.className&&a(b).is(".oembed-content, .oembed-card-container")},d=new MutationObserver(function(d){d.forEach(function(d){for(var e in d.addedNodes){var f=d.addedNodes[e];b(f)&&c.apply(a(f).find("> *:not(video):first-child, .oembed-card"))}})}),e={attributes:!0,childList:!0,characterData:!0,subtree:!0},f=document.body;d.observe(f,e)};d(),a(document).ready(function(){b.apply(),c.apply()})}}}); |
@ -0,0 +1 @@ |
|||
define(["jquery"],function(a){return{apply:function(){a(".oembed-card-play").on("click",function(){var b=a(this).parent(".oembed-card"),c=a(b.data("embed")),d=a(b).width(),e=a(b).height();if(a(c).find("iframe").length){var f=a(a(c).find("iframe")[0]),g=f.attr("src"),h=g.indexOf("?")>-1?"&":"?";g+=h+"autoplay=1",g+="&auto_play=1",f.attr("src",g)}c.attr("data-card-width",d),c.attr("data-card-height",e),b.parent(".oembed-card-container").replaceWith(c)})}}}); |
@ -0,0 +1 @@ |
|||
define(["jquery"],function(a){var b=function(){this.apply=function(b){if(!b){var c=".oembed-content:not(.oembed-responsive) > *:not(video):first-child,";c+=" .oembed-card:not(.oembed-processed)",b=a(c)}a(b).each(function(){var b=a(this).parent();if(!b.hasClass("oembed-responsive")){var c,d,e;e=this.getAttribute("data-aspect-ratio"),null!==e&&"0"!==e||(c=this.width||this.offsetWidth,d=this.height||this.offsetHeight,(c.indexOf("%")>-1&&d.indexOf("%")==-1||c.indexOf("%")==-1&&d.indexOf("%")>-1)&&(a(this).parent().attr("data-card-width")&&a(this).parent().attr("data-card-height")?(c=a(this).parent().attr("data-card-width"),d=a(this).parent().attr("data-card-height")):(c=this.offsetWidth,d=this.offsetHeight)),c=parseInt(c),d=parseInt(d),e=d/c,this.setAttribute("data-aspect-ratio",e));var f=this.tagName.toLowerCase();"iframe"===f&&(a(this).removeAttr("width"),a(this).removeAttr("height")),c=parseInt(this.offsetWidth);var g={width:"100%"};if(a(this).css(g),!b.find(".oembed-responsive-pad").length){var h=100*e,i='<div class="oembed-responsive-pad" style="padding-top:'+h+'%"></div>';b.append(i)}b.addClass("oembed-responsive")}})}};return new b}); |
File diff suppressed because it is too large
@ -0,0 +1,300 @@ |
|||
/** |
|||
* This file is part of Moodle - http://moodle.org/
|
|||
* |
|||
* Moodle is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* Moodle is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Guy Thomas / moodlerooms.com 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|||
*/ |
|||
|
|||
/** |
|||
* Oembed provider management module. |
|||
*/ |
|||
define(['jquery', 'core/notification', 'core/ajax', 'core/templates', 'core/fragment', 'core/str', |
|||
'filter_oembed/list'], |
|||
function($, notification, ajax, templates, fragment, str, List) { |
|||
return { |
|||
|
|||
prevEditId: null, |
|||
|
|||
/** |
|||
* Reload provider row. |
|||
* @param {int} pid |
|||
* @param {jQuery} row |
|||
* @param {string|null} action |
|||
* @param {function|null} callback |
|||
*/ |
|||
reloadRow: function(pid, row, action, callback) { |
|||
action = !action ? 'reload' : action; |
|||
ajax.call([ |
|||
{ |
|||
methodname: 'filter_oembed_provider_manage', |
|||
args: { |
|||
pid: pid, |
|||
action: action |
|||
}, |
|||
done: function(response) { |
|||
// Update row.
|
|||
templates.render('filter_oembed/managementpagerow', response.providermodel) |
|||
.done(function(result) { |
|||
$(row).replaceWith(result); |
|||
row = $('#oembed-display-providers_' + pid); |
|||
if (typeof(callback) === 'function') { |
|||
callback(row); |
|||
} |
|||
}); |
|||
}, |
|||
fail: function(response) { |
|||
notification.exception(response); |
|||
} |
|||
} |
|||
], true, true); |
|||
}, |
|||
|
|||
/** |
|||
* Reload all providers. |
|||
* @param {function|null} callback |
|||
*/ |
|||
reloadProviders: function(callback) { |
|||
ajax.call([ |
|||
{ |
|||
methodname: 'filter_oembed_providers', |
|||
args: { |
|||
scope: 'all' |
|||
}, |
|||
done: function(response) { |
|||
// Update table.
|
|||
templates.render('filter_oembed/managementpage', response) |
|||
.done(function(result) { |
|||
var resultHtml = $($.parseHTML(result)).html(); |
|||
$('#providermanagement').html(resultHtml); |
|||
if (typeof(callback) === 'function') { |
|||
callback(); |
|||
} |
|||
}); |
|||
}, |
|||
fail: function(response) { |
|||
notification.exception(response); |
|||
} |
|||
} |
|||
], true, true); |
|||
}, |
|||
|
|||
/** |
|||
* Listen for enable / disable action. |
|||
*/ |
|||
listenEnableDisable: function() { |
|||
var self = this; |
|||
$('#providermanagement').on('click', '.oembed-provider-actions .filter-oembed-visibility', function(e) { |
|||
e.preventDefault(); |
|||
|
|||
var row = $(this).parents('tr')[0]; |
|||
var pid = $(row).data('pid'); |
|||
var enabled = !$(row).hasClass('dimmed_text'); |
|||
var action = enabled ? 'disable' : 'enable'; |
|||
|
|||
self.reloadRow(pid, row, action); |
|||
}); |
|||
}, |
|||
|
|||
/** |
|||
* Listen for delete action. |
|||
*/ |
|||
listenDelete: function() { |
|||
var onConfirm = function(row) { |
|||
|
|||
var pid = $(row).data('pid'); |
|||
|
|||
ajax.call([ |
|||
{ |
|||
methodname: 'filter_oembed_provider_manage', |
|||
args: { |
|||
pid: pid, |
|||
action: 'delete' |
|||
}, |
|||
done: function() { |
|||
// Remove row.
|
|||
$(row).remove(); |
|||
}, |
|||
fail: function(response) { |
|||
notification.exception(response); |
|||
} |
|||
} |
|||
], true, true); |
|||
}; |
|||
|
|||
$('#providermanagement').on('click', '.oembed-provider-actions .filter-oembed-delete', function(e) { |
|||
e.preventDefault(); |
|||
|
|||
var row = $(this).parents('tr')[0]; |
|||
var providerName = $($(this).parents('td').find('.list-providername')[0]).text(); |
|||
|
|||
str.get_strings([ |
|||
{key: 'deleteprovidertitle', component: 'filter_oembed'}, |
|||
{key: 'deleteproviderconfirm', component: 'filter_oembed', param: providerName}, |
|||
{key: 'ok', component: 'core'}, |
|||
{key: 'cancel', component: 'core'} |
|||
]).done(function(strings) { |
|||
var delTitle = strings[0]; |
|||
var delConf = strings[1]; |
|||
var ok = strings[2]; |
|||
var cancel = strings[3]; |
|||
notification.confirm(delTitle, delConf, ok, cancel, function() { |
|||
onConfirm(row); |
|||
}); |
|||
}); |
|||
}); |
|||
}, |
|||
|
|||
/** |
|||
* Listen for edit action. |
|||
*/ |
|||
listenEdit: function() { |
|||
var self = this; |
|||
|
|||
/** |
|||
* Turn editing off for a row by id |
|||
* @param {string} providerId |
|||
*/ |
|||
var turnEditingOff = function(provderId) { |
|||
var sel = '#oembed-display-providers_' + provderId; |
|||
$(sel).removeClass('oembed-provider-editing'); |
|||
$(sel + ' form').remove(); |
|||
$(sel + ' td div.alert').remove(); |
|||
}; |
|||
|
|||
/** |
|||
* Update the provider form with data. |
|||
* @param string data - serialized form data. |
|||
*/ |
|||
var updateProviderForm = function(pid, data, callback) { |
|||
|
|||
var rx = new RegExp('(?:course-)(\\S)'); |
|||
var result = rx.exec($('body').attr('class')); |
|||
var contextid = parseInt(result[1]); |
|||
var params; |
|||
if (data) { |
|||
params = {formdata: data, pid: pid}; |
|||
} else { |
|||
params = {pid: pid}; |
|||
} |
|||
|
|||
fragment.loadFragment('filter_oembed', 'provider', contextid, params).done( |
|||
function(html, js) { |
|||
$('#oembed-display-providers_' + pid).addClass('oembed-provider-editing'); |
|||
templates.replaceNodeContents( |
|||
$('#oembed-display-providers_' + pid + ' .oembed-provider-details'), |
|||
html, |
|||
js |
|||
); |
|||
if (typeof(callback) === 'function') { |
|||
callback(); |
|||
} |
|||
} |
|||
); |
|||
}; |
|||
|
|||
// Listen for click cancel.
|
|||
$('#providermanagement').on('click', '.oembed-provider-actions .filter-oembed-edit', function(e) { |
|||
e.preventDefault(); |
|||
|
|||
var row = $(this).parents('tr')[0]; |
|||
var pid = $(row).data('pid'); |
|||
|
|||
// Remove editing class from current row / previous row and delete form.
|
|||
if (self.prevEditId !== null) { |
|||
turnEditingOff(self.prevEditId); |
|||
turnEditingOff(pid); |
|||
} |
|||
|
|||
self.prevEditId = pid; |
|||
|
|||
updateProviderForm(pid); |
|||
}); |
|||
|
|||
// Listen for form click submit.
|
|||
$('#providermanagement').on('click', '.oembed-provider-details form #id_submitbutton', function(e) { |
|||
e.preventDefault(); |
|||
var row = $(this).parents('tr')[0]; |
|||
var pid = $(row).data('pid'); |
|||
var form = $(this).parents('form')[0]; |
|||
var source = $(form).find('input[name="source"]').val(); |
|||
|
|||
$(form).trigger('save-form-state'); |
|||
var data = $(form).serialize(); |
|||
updateProviderForm(pid, data, function() { |
|||
var detailsSel = '#oembed-display-providers_' + pid + ' .oembed-provider-details'; |
|||
var successSel = detailsSel + ' div.alert-success'; |
|||
var successEl = $(successSel); |
|||
|
|||
if (successEl.length) { |
|||
var successHTML = successEl[0].outerHTML; |
|||
turnEditingOff(pid); |
|||
|
|||
// Get new provider id and set pid to it so correct row is targeted on reload.
|
|||
if (source.indexOf('download::') > -1) { |
|||
var newProviderSel = detailsSel + ' .js-oembed-newprovider'; |
|||
var newProviderEl = $(newProviderSel); |
|||
if (newProviderEl.length) { |
|||
pid = newProviderEl.data('newproviderid'); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* On reloading providers or single row append success HTML. |
|||
*/ |
|||
var onReload = function() { |
|||
var rowcell = $('#oembed-display-providers_' + pid + ' td'); |
|||
$(rowcell).append(successHTML); |
|||
$(rowcell).find(' div.alert-success').attr('tabindex', -1); |
|||
$(rowcell).find(' div.alert-success').focus(); |
|||
}; |
|||
|
|||
if (source.indexOf('download::') > -1) { |
|||
// When a downloaded provider is saved, a new one is created as a local provider, so we
|
|||
// need to reload the full list.
|
|||
self.reloadProviders(onReload); |
|||
} else { |
|||
self.reloadRow(pid, row, 'reload', onReload); |
|||
} |
|||
} |
|||
}); |
|||
}); |
|||
|
|||
// Listen for form click cancel.
|
|||
$('#providermanagement').on('click', '.oembed-provider-details form #id_cancel', function(e) { |
|||
e.preventDefault(); |
|||
var row = $(this).parents('tr')[0]; |
|||
turnEditingOff($(row).data('pid')); |
|||
}); |
|||
}, |
|||
|
|||
/** |
|||
* Initialise. |
|||
*/ |
|||
init: function() { |
|||
var options = { |
|||
valueNames: [ 'list-providername'] |
|||
}; |
|||
|
|||
new List('providermanagement', options); |
|||
|
|||
this.listenEnableDisable(); |
|||
this.listenDelete(); |
|||
this.listenEdit(); |
|||
} |
|||
}; |
|||
} |
|||
); |
@ -0,0 +1,82 @@ |
|||
/** |
|||
* This file is part of Moodle - http://moodle.org/
|
|||
* |
|||
* Moodle is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* Moodle is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Guy Thomas / moodlerooms.com 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|||
*/ |
|||
|
|||
/** |
|||
* Oembed main module. |
|||
*/ |
|||
define(['jquery', 'filter_oembed/preloader', 'filter_oembed/responsivecontent'], |
|||
function($, preloader, responsiveContent) { |
|||
return { |
|||
init: function() { |
|||
/** |
|||
* Apply a mutation observer to track oembed-content being dynamically added to the page. |
|||
*/ |
|||
var responsiveContentOnInsert = function() { |
|||
/** |
|||
* Does a node have the oembed-content class |
|||
* @param {opbject} node (dom element) |
|||
* @returns {boolean} |
|||
*/ |
|||
var hasOembedClass = function(node) { |
|||
if (!node.className) { |
|||
return false; |
|||
} |
|||
return $(node).is(".oembed-content, .oembed-card-container"); |
|||
}; |
|||
|
|||
var observer = new MutationObserver(function(mutations) { |
|||
mutations.forEach(function(mutation) { |
|||
for (var n in mutation.addedNodes) { |
|||
var node = mutation.addedNodes[n]; |
|||
if (hasOembedClass(node)) { |
|||
// Only apply responsive content to the newly added node for efficiency.
|
|||
responsiveContent.apply($(node).find('> *:not(video):first-child, .oembed-card')); |
|||
} |
|||
} |
|||
}); |
|||
}); |
|||
|
|||
var observerConfig = { |
|||
attributes: true, |
|||
childList: true, |
|||
characterData: true, |
|||
subtree: true |
|||
}; |
|||
|
|||
// Note: Currently observing mutations throughout the document body - We might want to limit scope for
|
|||
// observation at some point in the future.
|
|||
var targetNode = document.body; |
|||
observer.observe(targetNode, observerConfig); |
|||
}; |
|||
|
|||
responsiveContentOnInsert(); |
|||
|
|||
$(document).ready(function() { |
|||
// Apply preloader listeners.
|
|||
preloader.apply(); |
|||
|
|||
// Call responsive content on dom ready, to catch things that existed prior to mutation observation.
|
|||
responsiveContent.apply(); |
|||
}); |
|||
} |
|||
}; |
|||
} |
|||
); |
@ -0,0 +1,55 @@ |
|||
/** |
|||
* This file is part of Moodle - http://moodle.org/
|
|||
* |
|||
* Moodle is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* Moodle is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Guy Thomas / moodlerooms.com 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|||
*/ |
|||
|
|||
/** |
|||
* Oembed preloader. |
|||
*/ |
|||
define(['jquery'], |
|||
function($) { |
|||
return { |
|||
apply: function() { |
|||
$(".oembed-card-play").on("click", function() { |
|||
var card = $(this).parent('.oembed-card'); |
|||
var data = $(card.data('embed')); |
|||
var cardwidth = $(card).width(); |
|||
var cardheight = $(card).height(); |
|||
|
|||
// Add auto play params.
|
|||
// Because we are using a preloader we ideally want the content to play after clicking the preloader
|
|||
// play button.
|
|||
if ($(data).find('iframe').length) { |
|||
var iframe = $($(data).find('iframe')[0]); |
|||
var src = iframe.attr('src'); |
|||
var paramglue = src.indexOf('?') > -1 ? '&' : '?'; |
|||
src += paramglue + 'autoplay=1'; |
|||
src += '&' + 'auto_play=1'; |
|||
iframe.attr('src', src); |
|||
} |
|||
|
|||
// Replace card with oembed html.
|
|||
data.attr('data-card-width', cardwidth); |
|||
data.attr('data-card-height', cardheight); |
|||
card.parent('.oembed-card-container').replaceWith(data); |
|||
}); |
|||
} |
|||
}; |
|||
} |
|||
); |
@ -0,0 +1,109 @@ |
|||
/** |
|||
* This file is part of Moodle - http://moodle.org/
|
|||
* |
|||
* Moodle is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* Moodle is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Guy Thomas / moodlerooms.com 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|||
*/ |
|||
|
|||
/** |
|||
* Main responsive content function. |
|||
*/ |
|||
define(['jquery'], function($) { |
|||
|
|||
/** |
|||
* Apply responsive video to non HTML5 video elements. |
|||
*/ |
|||
var ResponsiveContent = function() { |
|||
|
|||
/** |
|||
* Apply to specific node / nodes or use selector. |
|||
* @param {jQuery|null} nodes- jquery node / collection of nodes or null |
|||
*/ |
|||
this.apply = function(nodes) { |
|||
if (!nodes){ |
|||
var selectortoprocess = '.oembed-content:not(.oembed-responsive) > *:not(video):first-child,'; |
|||
selectortoprocess += ' .oembed-card:not(.oembed-processed)'; |
|||
nodes = $(selectortoprocess); |
|||
} |
|||
// Apply aspect ratio to height for all nodes or single node.
|
|||
$(nodes).each(function() { |
|||
|
|||
var parent = $(this).parent(); |
|||
if (parent.hasClass('oembed-responsive')) { |
|||
// Already processed.
|
|||
return; |
|||
} |
|||
|
|||
var width, |
|||
height, |
|||
aspectratio; |
|||
|
|||
aspectratio = this.getAttribute('data-aspect-ratio'); |
|||
if (aspectratio === null || aspectratio === '0') { // Note, an empty attribute should evaluate to null.
|
|||
// Calculate aspect ratio.
|
|||
width = this.width || this.offsetWidth; |
|||
height = this.height || this.offsetHeight; |
|||
|
|||
// If only the width or height contains percentages then we can't use it and will have to fall back
|
|||
// on the card size OR offsets.
|
|||
if (width.indexOf('%') > -1 && height.indexOf('%') == -1 |
|||
|| width.indexOf('%') == -1 && height.indexOf('%') > -1 |
|||
) { |
|||
if ($(this).parent().attr('data-card-width') && $(this).parent().attr('data-card-height')) { |
|||
width = $(this).parent().attr('data-card-width'); |
|||
height = $(this).parent().attr('data-card-height'); |
|||
} else { |
|||
width = this.offsetWidth; |
|||
height = this.offsetHeight; |
|||
} |
|||
} |
|||
|
|||
width = parseInt(width); |
|||
height = parseInt(height); |
|||
aspectratio = height / width; |
|||
this.setAttribute('data-aspect-ratio', aspectratio); |
|||
} |
|||
|
|||
var tagname = this.tagName.toLowerCase(); |
|||
if (tagname === 'iframe') { |
|||
// Remove attributes.
|
|||
$(this).removeAttr('width'); |
|||
$(this).removeAttr('height'); |
|||
} |
|||
|
|||
// Get width again.
|
|||
width = parseInt(this.offsetWidth); |
|||
// Set width.
|
|||
var style = {width: '100%'}; |
|||
$(this).css(style); |
|||
|
|||
// Make sure parent has a padding element.
|
|||
if (!parent.find('.oembed-responsive-pad').length) { |
|||
var aspectPerc = aspectratio * 100; |
|||
var responsivePad = '<div class="oembed-responsive-pad" style="padding-top:' + aspectPerc + '%"></div>'; |
|||
parent.append(responsivePad); |
|||
} |
|||
|
|||
// Add responsive class to parent element.
|
|||
parent.addClass('oembed-responsive'); |
|||
}); |
|||
}; |
|||
|
|||
}; |
|||
|
|||
return new ResponsiveContent(); |
|||
}); |
@ -0,0 +1,54 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Base class for classes which map to db tables. |
|||
* @author Guy Thomas <gthomas@moodlerooms.com> |
|||
* @copyright Copyright (c) 2016 Blackboard Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace filter_oembed\db; |
|||
use stdClass; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class abstract_dbrow { |
|||
|
|||
/** |
|||
* anstract_dbrow constructor. |
|||
* @param stdClass $row |
|||
*/ |
|||
public function __construct($row) { |
|||
|
|||
if (!$row) { |
|||
throw new \coding_exception('$row does not exist'); |
|||
} |
|||
|
|||
if (!$row instanceof stdClass) { |
|||
throw new \coding_exception('$row must be an instance of std class', var_export($row, true)); |
|||
} |
|||
|
|||
$vars = array_keys(get_object_vars($this)); |
|||
|
|||
foreach ($row as $key => $val) { |
|||
if (!in_array($key, $vars)) { |
|||
throw new \coding_exception('Row model '.get_class($this).' is missing key '.$key); |
|||
} |
|||
$this->$key = $val; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,69 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Provider Row. |
|||
* @author Guy Thomas <gthomas@moodlerooms.com> |
|||
* @copyright Copyright (c) 2016 Blackboard Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace filter_oembed\db; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class providerrow extends abstract_dbrow{ |
|||
/** |
|||
* @var int id |
|||
*/ |
|||
public $id; |
|||
|
|||
/** |
|||
* @var str provider name |
|||
*/ |
|||
public $providername; |
|||
|
|||
/** |
|||
* @var str provider url |
|||
*/ |
|||
public $providerurl; |
|||
|
|||
/** |
|||
* @var str end points |
|||
*/ |
|||
public $endpoints; |
|||
|
|||
/** |
|||
* @var str source |
|||
*/ |
|||
public $source; |
|||
|
|||
/** |
|||
* @var bool enabled status |
|||
*/ |
|||
public $enabled; |
|||
|
|||
/** |
|||
* @var int time created |
|||
*/ |
|||
public $timecreated; |
|||
|
|||
/** |
|||
* @var int time modified |
|||
*/ |
|||
public $timemodified; |
|||
|
|||
} |
@ -0,0 +1,90 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Provider mform. |
|||
* @author Guy Thomas <gthomas@moodlerooms.com> |
|||
* @copyright Copyright (c) 2016 Blackboard Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
namespace filter_oembed\forms; |
|||
|
|||
use moodleform; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once($CFG->dirroot.'/lib/formslib.php'); |
|||
|
|||
class provider extends moodleform { |
|||
/** |
|||
* Define this form - is called from parent constructor. |
|||
*/ |
|||
public function definition() { |
|||
$mform = $this->_form; |
|||
|
|||
// Form configuration. |
|||
$config = (object)[ |
|||
'id' => ['required' => true, 'type' => 'hidden', 'paramtype' => PARAM_INT], |
|||
'providername' => ['required' => true, 'type' => 'text', 'paramtype' => PARAM_TEXT], |
|||
'providerurl' => ['required' => true, 'type' => 'text', 'paramtype' => PARAM_URL], |
|||
'endpoints' => ['required' => true, 'type' => 'textarea', 'paramtype' => PARAM_TEXT], |
|||
'enabled' => ['required' => false, 'type' => 'checkbox', 'paramtype' => PARAM_INT], |
|||
'source' => ['required' => true, 'type' => 'hidden', 'paramtype' => PARAM_TEXT], |
|||
]; |
|||
|
|||
// The source type is stored in "_customdata". |
|||
$sourcetype = $this->_customdata; |
|||
// Common attributes to be appleid to all fields. |
|||
$commonattributes = null; |
|||
if ($sourcetype === \filter_oembed\provider\provider::PROVIDER_SOURCE_PLUGIN) { |
|||
$commonattributes = 'disabled="disabled"'; |
|||
} |
|||
|
|||
// Define form according to configuration. |
|||
foreach ($config as $fieldname => $row) { |
|||
$row = (object)$row; |
|||
if ($row->type == 'hidden') { |
|||
$fieldlabel = ''; |
|||
} else { |
|||
$fieldlabel = get_string($fieldname, 'filter_oembed'); |
|||
} |
|||
$el = $mform->addElement($row->type, $fieldname, $fieldlabel); |
|||
if (!empty($commonattributes)) { |
|||
$el->updateAttributes($commonattributes); |
|||
} |
|||
$mform->setType($fieldname, $row->paramtype); |
|||
if ($row->required) { |
|||
$mform->addRule($fieldname, get_string('requiredfield', 'filter_oembed', $fieldlabel), 'required'); |
|||
} |
|||
} |
|||
|
|||
$mform->addElement('static', 'sourcetext', get_string('source', 'filter_oembed')); |
|||
|
|||
if ($sourcetype === \filter_oembed\provider\provider::PROVIDER_SOURCE_PLUGIN) { |
|||
// Plugins can't be edited. |
|||
$mform->addElement('cancel'); |
|||
} else { |
|||
if ($sourcetype == \filter_oembed\provider\provider::PROVIDER_SOURCE_DOWNLOAD) { |
|||
// Downloads can be saved as new locals. |
|||
$label = get_string('saveasnew', 'filter_oembed'); |
|||
} else { |
|||
// Locals can be edited. |
|||
$label = null; |
|||
} |
|||
$this->add_action_buttons(true, $label); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,88 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
namespace filter_oembed\output; |
|||
|
|||
use filter_oembed\db\providerrow; |
|||
use filter_oembed\provider\provider; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class managementpage implements \renderable, \templatable { |
|||
|
|||
/** |
|||
* An array of rows |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $rows; |
|||
|
|||
/** |
|||
* Construct the renderable. |
|||
* @param array $content The array of rows. |
|||
*/ |
|||
public function __construct(array $content = array()) { |
|||
if (!empty($content)) { |
|||
foreach ($content as $row) { |
|||
$this->rows[] = $row; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Export the data for template. |
|||
* @param \renderer_base $output |
|||
*/ |
|||
public function export_for_template(\renderer_base $output) { |
|||
$data = [ |
|||
'localrows' => [], |
|||
'downloadrows' => [], |
|||
'pluginrows' => [], |
|||
]; |
|||
|
|||
if (count($this->rows) < 1) { |
|||
return $data; |
|||
} |
|||
|
|||
// Separate out the rows by source for display. |
|||
foreach ($this->rows as $row) { |
|||
$sourcetype = provider::source_type($row->source); |
|||
switch ($sourcetype) { |
|||
case provider::PROVIDER_SOURCE_DOWNLOAD: |
|||
$data['downloadrows'][] = new providermodel($row); |
|||
break; |
|||
|
|||
case provider::PROVIDER_SOURCE_PLUGIN: |
|||
$data['pluginrows'][] = new providermodel($row); |
|||
break; |
|||
|
|||
case provider::PROVIDER_SOURCE_LOCAL: |
|||
default: |
|||
$data['localrows'][] = new providermodel($row); |
|||
break; |
|||
} |
|||
} |
|||
return $data; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,165 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Guy Thomas <gthomas@moodlerooms.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
namespace filter_oembed\output; |
|||
|
|||
use filter_oembed\service\oembed; |
|||
use filter_oembed\provider\provider; |
|||
use filter_oembed\db\providerrow; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Class providermodel |
|||
* @package filter_oembed\output |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
class providermodel implements \renderable { |
|||
|
|||
/** |
|||
* @var int provider row id |
|||
*/ |
|||
public $pid; |
|||
|
|||
/** |
|||
* @var string provider name |
|||
*/ |
|||
public $providername; |
|||
|
|||
/** |
|||
* @var string provider url |
|||
*/ |
|||
public $providerurl; |
|||
|
|||
/** |
|||
* @var bool is this provider enabled or not |
|||
*/ |
|||
public $enabled; |
|||
|
|||
/** |
|||
* @var string current action - enable or disable |
|||
*/ |
|||
public $enableaction; |
|||
|
|||
/** |
|||
* @var string additional row class |
|||
*/ |
|||
public $extraclass; |
|||
|
|||
/** |
|||
* @var string html for edit action |
|||
*/ |
|||
public $editaction; |
|||
|
|||
/** |
|||
* @var string html for delete action |
|||
*/ |
|||
public $deleteaction; |
|||
|
|||
/** |
|||
* @var int 1 if editing, else 0 |
|||
*/ |
|||
public $editing; |
|||
|
|||
/** |
|||
* @var string provider source |
|||
*/ |
|||
public $source; |
|||
|
|||
/** |
|||
* @var string source type - local, download, plugin |
|||
*/ |
|||
public $sourcetype; |
|||
|
|||
/** |
|||
* @var string provider scehmes |
|||
*/ |
|||
public $schemes; |
|||
|
|||
/** |
|||
* @var bool allow for discovery |
|||
*/ |
|||
public $discovery; |
|||
|
|||
/** |
|||
* @var string TODO add description |
|||
*/ |
|||
public $formats; |
|||
|
|||
/** |
|||
* providermodel constructor. |
|||
* @param mixed $provider |
|||
*/ |
|||
public function __construct($provider) { |
|||
global $PAGE, $CFG; |
|||
$PAGE->set_context(\context_system::instance()); |
|||
$output = $PAGE->get_renderer('filter_oembed', null, RENDERER_TARGET_GENERAL); |
|||
|
|||
$provider = (object)$provider; |
|||
|
|||
$this->pid = $provider->id; |
|||
$this->providername = $provider->providername; |
|||
$this->providerurl = $provider->providerurl; |
|||
$this->source = $provider->source; |
|||
$this->sourcetype = provider::source_type($provider->source); |
|||
if ($provider->enabled) { |
|||
|
|||
// Disable action. |
|||
$this->enabled = true; |
|||
$this->extraclass = ''; |
|||
$action = $CFG->wwwroot . '/filter/oembed/manageproviders.php?action=disable&pid=' . |
|||
$provider->id . '&sesskey=' . sesskey(); |
|||
$this->enableaction = $output->action_icon($action, |
|||
new \pix_icon('t/hide', get_string('hide')), null, ['class' => 'action-icon filter-oembed-visibility']); |
|||
} else { |
|||
|
|||
// Enable action. |
|||
$action = $CFG->wwwroot . '/filter/oembed/manageproviders.php?action=enable&pid=' . |
|||
$provider->id . '&sesskey=' . sesskey(); |
|||
$this->extraclass = 'dimmed_text'; |
|||
$this->enableaction = $output->action_icon($action, |
|||
new \pix_icon('t/show', get_string('show')), null, ['class' => 'action-icon filter-oembed-visibility']); |
|||
} |
|||
|
|||
// Edit action. |
|||
$action = $CFG->wwwroot . '/filter/oembed/manageproviders.php?action=edit&pid=' . |
|||
$provider->id . '&sesskey=' . sesskey(); |
|||
$this->editaction = $output->action_icon($action, |
|||
new \pix_icon('t/edit', get_string('edit')), null, ['class' => 'action-icon filter-oembed-edit']); |
|||
|
|||
// Delete action. |
|||
if ($this->sourcetype == provider::PROVIDER_SOURCE_LOCAL) { |
|||
$action = $CFG->wwwroot . '/filter/oembed/manageproviders.php?action=delete&pid=' . |
|||
$provider->id . '&sesskey=' . sesskey(); |
|||
$this->deleteaction = $output->action_icon($action, |
|||
new \pix_icon('t/delete', get_string('delete')), |
|||
null, |
|||
['class' => 'action-icon filter-oembed-delete'] |
|||
); |
|||
} else { |
|||
$this->deleteaction = ''; |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Renderer for oembed filter. |
|||
* @author gthomas2 |
|||
* @copyright Copyright (c) 2016 Moodlerooms Inc. (http://www.moodlerooms.com) |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace filter_oembed\output; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class renderer extends \plugin_renderer_base { |
|||
|
|||
/** |
|||
* Pre loader HTML. |
|||
* |
|||
* @param string $embedhtml |
|||
* @param array $json |
|||
* @return string |
|||
*/ |
|||
public function preload($embedhtml, array $json) { |
|||
$data = (object)$json; |
|||
$data->embedhtml = $embedhtml; // Has some extra processing to what is available in $json['html']. |
|||
return $this->render_from_template('filter_oembed/preload', $data); |
|||
} |
|||
|
|||
/** |
|||
* Provider management page. |
|||
* @param \templateable $page |
|||
* @return string | boolean |
|||
*/ |
|||
public function render_managementpage($page) { |
|||
$data = $page->export_for_template($this); |
|||
return $this->render_from_template('filter_oembed/managementpage', $data); |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
namespace filter_oembed\plugininfo; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class oembedprovider extends \core\plugininfo\base { |
|||
public function is_uninstall_allowed() { |
|||
return true; |
|||
} |
|||
} |
@ -0,0 +1,90 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
namespace filter_oembed\provider; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Base class for oembed endpoints. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
class endpoint { |
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $schemes = []; |
|||
|
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $url = ''; |
|||
|
|||
/** |
|||
* @var boolean |
|||
*/ |
|||
protected $discovery = false; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $formats = ['json']; |
|||
|
|||
/** |
|||
* Constructor. |
|||
* @param $data JSON decoded array or data object containing all endpoint data. |
|||
*/ |
|||
public function __construct($data = null) { |
|||
if (is_object($data)) { |
|||
$data = (array)$data; |
|||
} |
|||
if (isset($data['schemes'])) { |
|||
$this->schemes = $data['schemes']; |
|||
} |
|||
if (isset($data['url'])) { |
|||
$this->url = $data['url']; |
|||
} |
|||
if (isset($data['discovery'])) { |
|||
$this->discovery = !empty($data['discovery']); |
|||
} |
|||
if (isset($data['formats'])) { |
|||
$this->formats = $data['formats']; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Magic method for getting properties. |
|||
* @param string $name |
|||
* @return mixed |
|||
* @throws \coding_exception |
|||
*/ |
|||
public function __get($name) { |
|||
$allowed = ['schemes', 'url', 'discovery', 'formats']; |
|||
if (in_array($name, $allowed)) { |
|||
return $this->$name; |
|||
} else { |
|||
throw new \coding_exception($name.' is not a publicly accessible property of '.get_class($this)); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,258 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @author Erich M. Wappis <erich.wappis@uni-graz.at> |
|||
* @author Guy Thomas <brudinie@googlemail.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
namespace filter_oembed\provider; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Base class for oembed providers and plugins. Plugins should extend this class. |
|||
* If "filter" is provided, there is nothing else a plugin needs to implement. |
|||
* Plugins can instead / additionally override "get_oembed_request", "oembed_response" and "endpoints_regex". |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
class provider { |
|||
|
|||
/** |
|||
* @var int |
|||
*/ |
|||
protected $id; |
|||
|
|||
/** |
|||
* @var boolean |
|||
*/ |
|||
protected $enabled; |
|||
|
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $providername = ''; |
|||
|
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $providerurl = ''; |
|||
|
|||
/** |
|||
* @var endpoints |
|||
*/ |
|||
protected $endpoints = []; |
|||
|
|||
/** |
|||
* @var source |
|||
*/ |
|||
protected $source = ''; |
|||
|
|||
/** |
|||
* @var Class constant descriptions. |
|||
*/ |
|||
const PROVIDER_SOURCE_LOCAL = 'local::'; |
|||
const PROVIDER_SOURCE_DOWNLOAD = 'download::'; |
|||
const PROVIDER_SOURCE_PLUGIN = 'plugin::'; |
|||
|
|||
/** |
|||
* Constructor. |
|||
* Note - provider data is expcted to come from the moodle data (db) which excludes |
|||
* "_" in variable names. Providers coming directly from oembed (http://oembed.com/providers.json), |
|||
* include "_" in variable names, which violates the Moodle coding standard. Currently, |
|||
* this is managed by the update processes to ensure compatibility. |
|||
* |
|||
* @param $data JSON decoded array or a data object containing all provider data. |
|||
*/ |
|||
public function __construct($data = null) { |
|||
if (is_object($data)) { |
|||
$data = (array)$data; |
|||
} |
|||
if (!empty($data)) { |
|||
$this->id = isset($data['id']) ? $data['id'] : 0; |
|||
$this->enabled = isset($data['enabled']) ? $data['enabled'] : false; |
|||
$this->providername = $data['providername']; |
|||
$this->providerurl = $data['providerurl']; |
|||
|
|||
// If the endpoint data is a string, assume its a json encoded string. |
|||
if (is_string($data['endpoints'])) { |
|||
$data['endpoints'] = json_decode($data['endpoints'], true); |
|||
} |
|||
if (is_array($data['endpoints'])) { |
|||
foreach ($data['endpoints'] as $endpoint) { |
|||
$this->endpoints[] = new endpoint($endpoint); |
|||
} |
|||
} else { |
|||
throw new \coding_exception('"endpoint" data must be an array for '.get_class($this)); |
|||
} |
|||
|
|||
$this->source = isset($data['source']) ? $data['source'] : ''; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Main filter function. This should only be used by subplugins, and it is preferable |
|||
* to not use it even then. Ideally, a provider plugin should provide a JSON oembed provider |
|||
* response (http://oembed.com/#section2.3) and let the main filter handle the HTML. Use this |
|||
* only if the HTML must be determined by the plugin. If implemented, ensure FALSE is returned |
|||
* if no filtering occurred. |
|||
* |
|||
* @param string $text Incoming text. |
|||
* @return string Filtered text, or false for no changes. |
|||
*/ |
|||
public function filter($text) { |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* Return the JSON decoded provider implementation info as in http://oembed.com/providers.json. |
|||
* |
|||
* @return array JSON decoded implemenation info. |
|||
*/ |
|||
public function implementation() { |
|||
$implarr = [ |
|||
'provider_name' => $this->providername, |
|||
'provider_url' => $this->providerurl, |
|||
'endpoints' => [], |
|||
]; |
|||
foreach ($this->endpoints as $endpoint) { |
|||
$implarr['endpoints'][] = [ |
|||
'schemes' => $endpoint->schemes, |
|||
'url' => $endpoint->url, |
|||
'discovery' => $endpoint->discovery, |
|||
'formats' => $endpoint->formats, |
|||
]; |
|||
} |
|||
return $implarr; |
|||
} |
|||
/** |
|||
* If a matching endpoint scheme is found in the passed text, return a consumer request URL. |
|||
* |
|||
* @param string $text The text to look for an URL resource using provider's schemes. |
|||
* @return string Consumer request URL. |
|||
*/ |
|||
public function get_oembed_request($text) { |
|||
$requesturl = ''; |
|||
// For each endpoint, look for a matching scheme. |
|||
foreach ($this->endpoints as $endpoint) { |
|||
// Get the regex arrauy to look for matching schemes. |
|||
$regexarr = $this->endpoints_regex($endpoint); |
|||
foreach ($regexarr as $regex) { |
|||
// Endpoints may have invalid regex strings that cause preg_match to throw an exception. We need to skip them |
|||
// in that case. Eventually, need to figure out how to inform the site about this. |
|||
try { |
|||
if (preg_match($regex, $text)) { |
|||
// If {format} is in the URL, replace it with the actual format. |
|||
// At the moment, we're only supporting JSON, so this must be JSON. |
|||
$requesturl = str_replace('{format}', 'json', $endpoint->url) . |
|||
'?url=' . urlencode($text) . '&format=json'; |
|||
break 2; // Done, break out of all loops. |
|||
} |
|||
} catch (\Exception $e) { |
|||
continue; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return $requesturl; |
|||
} |
|||
|
|||
/** |
|||
* Make a consumer oembed request and return the JSON provider response. |
|||
* |
|||
* @param string $url The consumer request URL. |
|||
* @return array JSON decoded array. |
|||
*/ |
|||
public function oembed_response($url) { |
|||
$ret = download_file_content($url, null, null, true, 300, 20, false, null, false); |
|||
return json_decode($ret->results, true); |
|||
} |
|||
|
|||
/** |
|||
* Return the type of the provider source parameter (download, local, plugin). |
|||
* |
|||
* @param string $source The source value to get the type for. |
|||
* @return string One of 'download::', 'local::', 'plugin::'. |
|||
*/ |
|||
public static function source_type($source) { |
|||
$sourcetype = substr($source, 0, strpos($source, '::')); |
|||
if (empty($sourcetype)) { |
|||
$sourcetype = self::PROVIDER_SOURCE_LOCAL; |
|||
} else { |
|||
$sourcetype .= '::'; |
|||
} |
|||
return $sourcetype; |
|||
} |
|||
|
|||
/** |
|||
* Return a regular expression that can be used to search text for an endpoint's schemes. |
|||
* |
|||
* @param endpoint $endpoint |
|||
* @return array Array of regular expressions matching all endpoints and schemes. |
|||
*/ |
|||
protected function endpoints_regex(endpoint $endpoint) { |
|||
$schemes = $endpoint->schemes; |
|||
if (empty($schemes)) { |
|||
$schemes = [$this->providerurl]; |
|||
} |
|||
|
|||
foreach ($schemes as $scheme) { |
|||
// An "http[s]:" may not be present, so flag it as a non-capturing subpattern with "(?:". |
|||
$url1 = preg_split('/((?:https?:)?\/\/)/', $scheme); |
|||
if (!empty($url1[1])) { |
|||
$url2 = preg_split('/\//', $url1[1]); |
|||
$regexarr = []; |
|||
foreach ($url2 as $url) { |
|||
$find = ['.', '*']; |
|||
$replace = ['\.', '.*?']; |
|||
$url = str_replace($find, $replace, $url); |
|||
$regexarr[] = '(' . $url . ')'; |
|||
} |
|||
|
|||
$regex[] = '/(https?:\/\/)' . implode('\/', $regexarr) . '/'; |
|||
} |
|||
} |
|||
return $regex; |
|||
} |
|||
|
|||
/** |
|||
* Magic method for getting properties. |
|||
* @param string $name |
|||
* @return mixed |
|||
* @throws \coding_exception |
|||
*/ |
|||
public function __get($name) { |
|||
$allowed = ['id', 'enabled', 'providername', 'providerurl', 'endpoints', 'source']; |
|||
if (in_array($name, $allowed)) { |
|||
return $this->$name; |
|||
} else { |
|||
throw new \coding_exception($name.' is not a publicly accessible property of '.get_class($this)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Set enabled? |
|||
* @param boolean $enabled |
|||
*/ |
|||
public function set_enabled($enabled) { |
|||
$this->enabled = $enabled; |
|||
} |
|||
} |
@ -0,0 +1,743 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Filter for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @author Erich M. Wappis <erich.wappis@uni-graz.at> |
|||
* @author Guy Thomas <brudinie@googlemail.com> |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
namespace filter_oembed\service; |
|||
use filter_oembed\db\providerrow; |
|||
use filter_oembed\provider\provider; |
|||
use Exception; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once($CFG->libdir.'/filelib.php'); |
|||
|
|||
/** |
|||
* Class oembed |
|||
* @package filter_oembed\service |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* Singleton class providing function for filtering embedded content links in text. |
|||
*/ |
|||
class oembed { |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $warnings = []; |
|||
|
|||
/** |
|||
* @var provider[] |
|||
*/ |
|||
protected $providers = []; |
|||
|
|||
/** |
|||
* Constructor - protected singeton. |
|||
* |
|||
* @param string $providerstate Either 'enabled', 'disabled', or 'all'. |
|||
*/ |
|||
protected function __construct($providerstate = 'enabled') { |
|||
$this->set_providers($providerstate); |
|||
} |
|||
|
|||
/** |
|||
* Singleton |
|||
* |
|||
* @param string $providerstate Either 'enabled', 'disabled', or 'all'. |
|||
* @return oembed |
|||
*/ |
|||
public static function get_instance($providerstate = 'enabled') { |
|||
/** @var $instance oembed */ |
|||
static $instance = []; |
|||
if (!isset($instance[$providerstate])) { |
|||
$instance[$providerstate] = new oembed($providerstate); |
|||
} |
|||
return $instance[$providerstate]; |
|||
} |
|||
|
|||
/** |
|||
* Set providers property. |
|||
* |
|||
* @param string $state Either 'enabled', 'disabled', or 'all'. |
|||
*/ |
|||
protected function set_providers($state = 'enabled') { |
|||
switch ($state) { |
|||
case 'enabled': |
|||
$providers = self::get_enabled_provider_data(); |
|||
break; |
|||
|
|||
case 'disabled': |
|||
$providers = self::get_disabled_provider_data(); |
|||
break; |
|||
|
|||
case 'all': |
|||
default: |
|||
$providers = self::get_all_provider_data(); |
|||
break; |
|||
} |
|||
foreach ($providers as $provider) { |
|||
$this->providers[$provider->id] = $this->get_provider_instance($provider); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get a provider instance using appropriate provider class. |
|||
* |
|||
* @param object $provider Data record from oembed_filter table. |
|||
* @return object provider Object of provider class or extended class. |
|||
*/ |
|||
protected function get_provider_instance($provider) { |
|||
global $CFG; |
|||
|
|||
$pluginprefix = provider::PROVIDER_SOURCE_PLUGIN; |
|||
if (provider::source_type($provider->source) == $pluginprefix) { |
|||
$name = substr($provider->source, strlen($pluginprefix)); |
|||
require_once($CFG->dirroot.'/filter/oembed/provider/'.$name.'/'.$name.'.php'); |
|||
$classname = "\\filter_oembed\\provider\\{$name}"; |
|||
return new $classname($provider); |
|||
} else { |
|||
return new provider($provider); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Filter text - convert oembed divs and links into oembed code. |
|||
* |
|||
* @param string $text |
|||
* @return string |
|||
*/ |
|||
public function html_output($text) { |
|||
$lazyload = get_config('filter_oembed', 'lazyload'); |
|||
$lazyload = $lazyload == 1 || $lazyload === false; |
|||
$output = ''; |
|||
|
|||
// Loop through each provider asking for a match. |
|||
foreach ($this->providers as $provider) { |
|||
if (($completeoutput = $provider->filter($text)) !== false) { |
|||
// Plugins may provide everything required. If so, just return it. |
|||
$output = $completeoutput; |
|||
break; |
|||
} else if ($requesturl = $provider->get_oembed_request($text)) { |
|||
// Get additional url params out of original url. |
|||
$parsed = parse_url($text); |
|||
$query = isset($parsed['query']) ? $parsed['query'] : ''; |
|||
$params = []; |
|||
parse_str($query, $params); |
|||
|
|||
// If we have a consumer request, we're done searching. Try for a response. |
|||
$jsonret = $provider->oembed_response($requesturl); |
|||
if (!$jsonret) { |
|||
$output = ''; |
|||
} else if ($lazyload) { |
|||
$output = $this->oembed_getpreloadhtml($jsonret, $params); |
|||
} else { |
|||
$output = $this->oembed_gethtml($jsonret, $params); |
|||
} |
|||
break; // Done, break out of all loops. |
|||
} |
|||
} |
|||
return $output; |
|||
} |
|||
|
|||
/** |
|||
* Get oembed html. |
|||
* |
|||
* @param array $jsonarr |
|||
* @param array $params |
|||
* @return string |
|||
* @throws \coding_exception |
|||
*/ |
|||
protected function oembed_gethtml($jsonarr, $params = []) { |
|||
if ($jsonarr === null) { |
|||
$this->warnings[] = get_string('connection_error', 'filter_oembed'); |
|||
return ''; |
|||
} |
|||
|
|||
$embed = $jsonarr['html']; |
|||
|
|||
// Add original params into content url. |
|||
// This is necessary for youtube videos - e.g. preserving auto play, etc.. |
|||
if (!empty($params)) { |
|||
$paramstr = ''; |
|||
foreach ($params as $key => $val) { |
|||
$paramstr .= '&'; |
|||
$paramstr .= $key . '=' . urlencode($val); |
|||
} |
|||
$embed = str_replace('?feature=oembed', '?feature=oembed'.$paramstr, $embed); |
|||
} |
|||
|
|||
$aspectratio = 0; |
|||
|
|||
if (!empty($jsonarr['width']) && !empty($jsonarr['height'])) { |
|||
$width = $jsonarr['width']; |
|||
$height = $jsonarr['height']; |
|||
$aspectratio = $this->get_aspect_ratio($width, $height); |
|||
} |
|||
if ($aspectratio > 0) { |
|||
$padding = $aspectratio * 100; |
|||
$paddiv = '<div class="oembed-responsive-pad" style="padding-top:' . $padding . '%"></div>'; |
|||
// Wrapper for responsive processing. |
|||
$output = '<div class="oembed-content oembed-responsive">' . $embed . $paddiv . '</div>'; |
|||
} else { |
|||
// Wrapper for responsive processing. |
|||
$output = '<div class="oembed-content">' . $embed . '</div>'; |
|||
} |
|||
|
|||
return $output; |
|||
} |
|||
|
|||
/** |
|||
* Generate preloader html. |
|||
* @param array $jsonarr |
|||
* @param array $params |
|||
* @return string |
|||
*/ |
|||
protected function oembed_getpreloadhtml(array $jsonarr, $params = []) { |
|||
global $PAGE; |
|||
/** @var \filter_oembed\output\renderer $renderer */ |
|||
$renderer = $PAGE->get_renderer('filter_oembed'); |
|||
|
|||
// To surpress the loadHTML Warnings. |
|||
$dom = new \DOMDocument(); |
|||
libxml_use_internal_errors(true); |
|||
$dom->loadHTML($jsonarr['html']); |
|||
libxml_use_internal_errors(false); |
|||
|
|||
// Get aspect ratio of iframe or use width in json. |
|||
if ($dom->getElementsByTagName('iframe')->length > 0) { |
|||
$width = $dom->getElementsByTagName('iframe')->item(0)->getAttribute('width'); |
|||
$height = $dom->getElementsByTagName('iframe')->item(0)->getAttribute('height'); |
|||
$aspectratio = self::get_aspect_ratio($width, $height); |
|||
if ($aspectratio === 0) { |
|||
if (isset($jsonarr['width']) && isset($jsonarr['height'])) { |
|||
$width = $jsonarr['width']; |
|||
$height = $jsonarr['height']; |
|||
$aspectratio = self::get_aspect_ratio($width, $height); |
|||
if ($aspectratio === 0) { |
|||
// Couldn't get a decent aspect ratio, let's go with 0.5625 (16:9). |
|||
$aspectratio = 0.5625; |
|||
} |
|||
} |
|||
} |
|||
if ($aspectratio !== 0) { |
|||
$jsonarr['aspectratio'] = $aspectratio * 100; |
|||
} |
|||
|
|||
// This html is intentionally hardcoded and excluded from the mustache template as javascript relies on it. |
|||
$jsonarr['jshtml'] = ' data-aspect-ratio = "'.$aspectratio.'" '; |
|||
} |
|||
|
|||
return $renderer->preload($this->oembed_gethtml($jsonarr, $params), $jsonarr); |
|||
} |
|||
|
|||
// ---- PROVIDER DATA MANAGEMENT SECTION ---- |
|||
|
|||
/** |
|||
* Function to update provider data in database with current provider sources. |
|||
* |
|||
* @return string Any notification messages. |
|||
*/ |
|||
public static function update_provider_data() { |
|||
global $DB; |
|||
|
|||
$warnings = []; |
|||
// Is there any data currently at all? |
|||
if ($DB->count_records('filter_oembed') <= 0) { |
|||
// Initial load. |
|||
try { |
|||
self::create_initial_provider_data(); |
|||
} catch (Exception $e) { |
|||
// Handle no initial data situation. |
|||
$warnings[] = $e->getMessage(); |
|||
} |
|||
} else { |
|||
// Update all existing provider data. |
|||
try { |
|||
$providers = self::download_providers(); |
|||
} catch (Exception $e) { |
|||
$warnings[] = $e->getMessage(); |
|||
$providers = []; |
|||
} |
|||
mtrace(' Checking for updated downloads...'); |
|||
self::update_downloaded_providers($providers); |
|||
mtrace(' Checking for updated subplugins...'); |
|||
self::update_plugin_providers(self::get_plugin_providers()); |
|||
} |
|||
|
|||
// If no providers were retrieved, log the issue. |
|||
return $warnings; |
|||
} |
|||
|
|||
/** |
|||
* Get the latest provider list from http://oembed.com/providers.json |
|||
* |
|||
* @return space array |
|||
*/ |
|||
protected static function download_providers() { |
|||
global $CFG; |
|||
|
|||
// Wondering if there is any reason to make this configurable? |
|||
$www = 'http://oembed.com/providers.json'; |
|||
|
|||
$timeout = 15; |
|||
|
|||
// Ensure that the configuration doesn't prevent us from downloading. |
|||
// This is a hack caused by new settings not always existing on a new install in 3.2. |
|||
$hackedport = false; |
|||
if (!isset($CFG->curlsecurityallowedport)) { |
|||
$CFG->curlsecurityallowedport = ''; |
|||
$hackedport = true; |
|||
} |
|||
$hackedhosts = false; |
|||
if (!isset($CFG->curlsecurityblockedhosts)) { |
|||
$CFG->curlsecurityblockedhosts = ''; |
|||
$hackedhosts = true; |
|||
} |
|||
|
|||
$ret = download_file_content($www, null, null, true, $timeout, 20, false, null, false); |
|||
|
|||
if ($hackedport) { |
|||
unset($CFG->curlsecurityallowedport); |
|||
} |
|||
if ($hackedhosts) { |
|||
unset($CFG->curlsecurityblockedhosts); |
|||
} |
|||
|
|||
if ($ret->status == '200') { |
|||
$ret = $ret->results; |
|||
} else { |
|||
$ret = ''; |
|||
} |
|||
|
|||
$providers = json_decode($ret, true); |
|||
|
|||
if (!is_array($providers)) { |
|||
$providers = false; |
|||
} |
|||
|
|||
if (empty($providers)) { |
|||
throw new \moodle_exception('error:noproviders', 'filter_oembed', ''); |
|||
} |
|||
|
|||
return $providers; |
|||
} |
|||
|
|||
/** |
|||
* Function to get providers from a local, static JSON file, for last resort action. |
|||
* |
|||
* @return space array |
|||
*/ |
|||
protected static function get_local_providers() { |
|||
global $CFG; |
|||
|
|||
$ret = file_get_contents($CFG->dirroot.'/filter/oembed/provider/providers.json'); |
|||
return json_decode($ret, true); |
|||
} |
|||
|
|||
/** |
|||
* Function to return a list of providers provided by the current sub plugins. |
|||
* Since Moodle doesn't currently support subplugins for filters, do this in this plugin. |
|||
* |
|||
* @return space array |
|||
*/ |
|||
protected static function get_plugin_providers() { |
|||
global $CFG; |
|||
|
|||
$pluginproviders = []; |
|||
$path = $CFG->dirroot.'/filter/oembed/provider/'; |
|||
$thisdir = new \DirectoryIterator($path); |
|||
foreach ($thisdir as $dir) { |
|||
if ($dir->isDir()) { |
|||
$name = $dir->getFilename(); |
|||
if (($name != '.') && ($name != '..')) { |
|||
require_once($CFG->dirroot.'/filter/oembed/provider/'.$name.'/'.$name.'.php'); |
|||
$classname = "\\filter_oembed\\provider\\{$name}"; |
|||
$newplugin = new $classname(); |
|||
$pluginproviders[] = array_merge($newplugin->implementation(), ['plugin' => $name]); |
|||
} |
|||
} |
|||
} |
|||
return $pluginproviders; |
|||
} |
|||
|
|||
/** |
|||
* Create initial provider data from known provider sources. |
|||
* |
|||
*/ |
|||
protected static function create_initial_provider_data() { |
|||
global $CFG; |
|||
|
|||
$warnings = []; |
|||
try { |
|||
$providers = self::download_providers(); |
|||
$source = provider::PROVIDER_SOURCE_DOWNLOAD . 'http://oembed.com/providers.json'; |
|||
} catch (Exception $e) { |
|||
$warnings[] = $e->getMessage(); |
|||
// If no providers were retrieved, get the local, static ones. |
|||
$providers = self::get_local_providers(); |
|||
if (empty($providers)) { |
|||
throw new \moodle_exception('No initial provider data available. Oembed filter will not function properly.'); |
|||
} |
|||
$source = provider::PROVIDER_SOURCE_LOCAL . $CFG->dirroot.'/filter/oembed/provider/providers.json'; |
|||
} |
|||
|
|||
// Load each downloaded provider into the database. |
|||
self::update_downloaded_providers($providers, $source); |
|||
|
|||
// Next, add the plugin providers that exist. |
|||
$providers = self::get_plugin_providers(); |
|||
self::update_plugin_providers($providers); |
|||
|
|||
return $warnings; |
|||
} |
|||
|
|||
/** |
|||
* Update the database with the downloaded provider data. |
|||
* At this point, we can't depend on the Provider Name being unique, or consistent. |
|||
* |
|||
* @param array $providers The JSON decoded provider data. |
|||
* @param string $source The source name for the provided providers. |
|||
*/ |
|||
private static function update_downloaded_providers(array $providers, $source = null) { |
|||
global $DB; |
|||
|
|||
if ($source === null) { |
|||
$source = provider::PROVIDER_SOURCE_DOWNLOAD . 'http://oembed.com/providers.json'; |
|||
} |
|||
|
|||
// Get current providers as array indexed by id. |
|||
$currentproviders = self::get_all_provider_data(); |
|||
|
|||
foreach ($providers as $provider) { |
|||
// Get a matching provider if it exists. |
|||
$currprovider = self::match_provider_names($currentproviders, $provider); |
|||
|
|||
if ($currprovider !== false) { |
|||
// Existing provider exists; check for update. |
|||
$change = false; |
|||
|
|||
if ($currprovider->providerurl != $provider['provider_url']) { |
|||
// Perform change URL actions. |
|||
$currprovider->providerurl = $provider['provider_url']; |
|||
$change = true; |
|||
} |
|||
|
|||
$endpoints = json_encode($provider['endpoints']); |
|||
if ($currprovider->endpoints != $endpoints) { |
|||
// Perform change endpoints actions. |
|||
$currprovider->endpoints = $endpoints; |
|||
$change = true; |
|||
} |
|||
|
|||
if ($change) { |
|||
mtrace(' updating '.$currprovider->providername); |
|||
$currprovider->timemodified = time(); |
|||
$DB->update_record('filter_oembed', $currprovider); |
|||
} |
|||
unset($currentproviders[$currprovider->id]); |
|||
|
|||
} else { |
|||
// New provider. |
|||
$record = new \stdClass(); |
|||
$record->providername = $provider['provider_name']; |
|||
$record->providerurl = $provider['provider_url']; |
|||
$record->endpoints = json_encode($provider['endpoints']); |
|||
$record->source = $source; |
|||
$record->enabled = 0; // Disable everything by default. |
|||
$record->timecreated = time(); |
|||
$record->timemodified = time(); |
|||
mtrace(' creating '.$record->providername); |
|||
$DB->insert_record('filter_oembed', $record); |
|||
} |
|||
} |
|||
|
|||
// Any current providers left must have been deleted if they have the same source. |
|||
foreach ($currentproviders as $providerdata) { |
|||
if ($providerdata->source == $source) { |
|||
// Perform delete provider actions. |
|||
mtrace(' deleting '.$providerdata->providername); |
|||
$DB->delete_records('filter_oembed', ['id' => $providerdata->id]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update the database with the plugin provider data. |
|||
* |
|||
* @param array $providers The JSON decoded provider data. |
|||
*/ |
|||
private static function update_plugin_providers(array $providers) { |
|||
global $DB; |
|||
|
|||
$source = provider::PROVIDER_SOURCE_PLUGIN; |
|||
|
|||
// Get current providers as array. |
|||
$currentproviders = self::get_all_provider_data(); |
|||
|
|||
foreach ($providers as $provider) { |
|||
// Get a matching provider if it exists. |
|||
$currprovider = self::match_provider_names($currentproviders, $provider); |
|||
|
|||
if ($currprovider !== false) { |
|||
// Existing provider exists, remove for delete check. |
|||
unset($currentproviders[$currprovider->id]); |
|||
} else { |
|||
// New provider. |
|||
$record = new \stdClass(); |
|||
$record->providername = $provider['provider_name']; |
|||
$record->providerurl = $provider['provider_url']; |
|||
$record->endpoints = json_encode($provider['endpoints']); |
|||
$record->source = $source.$provider['plugin']; |
|||
$record->enabled = 1; // Enable plugins by default. |
|||
$record->timecreated = time(); |
|||
$record->timemodified = time(); |
|||
mtrace(' creating '.$record->providername); |
|||
$DB->insert_record('filter_oembed', $record); |
|||
} |
|||
} |
|||
|
|||
// Any current plugin providers left must have been deleted if they have the same source. |
|||
foreach ($currentproviders as $providerdata) { |
|||
if (provider::source_type($providerdata->source) == $source) { |
|||
// Perform delete provider actions. |
|||
mtrace(' deleting '.$providerdata->providername); |
|||
$DB->delete_records('filter_oembed', ['id' => $providerdata->id]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Static function to search an array of database records for a specific name. |
|||
* Note this is "final protected" rather than "private" so it can be unit tested. |
|||
* |
|||
* @param array $providerarray An array of provider data records. |
|||
* @param array $provider The provider information to match. |
|||
* @return object A data record object. |
|||
*/ |
|||
final protected static function match_provider_names($providerarray, $provider) { |
|||
$foundrecord = false; |
|||
$foundarray = []; |
|||
foreach ($providerarray as $providerrecord) { |
|||
if ($providerrecord->providername == $provider['provider_name']) { |
|||
$foundarray[] = $providerrecord; |
|||
} |
|||
} |
|||
if (count($foundarray) > 1) { |
|||
// If more than one with the same name, match the url. Otherwise return false. |
|||
foreach ($foundarray as $match) { |
|||
if ($match->providerurl == $provider['provider_url']) { |
|||
$foundrecord = $match; |
|||
} |
|||
} |
|||
} else if (!empty($foundarray)) { |
|||
// If only one with matching name, use it. |
|||
$foundrecord = reset($foundarray); |
|||
} |
|||
return $foundrecord; |
|||
} |
|||
|
|||
// ---- OTHER HELPER FUNCTIONS ---- |
|||
|
|||
/** |
|||
* Magic method for getting properties. |
|||
* @param string $name |
|||
* @return mixed |
|||
* @throws \coding_exception |
|||
*/ |
|||
public function __get($name) { |
|||
$allowed = ['providers', 'warnings']; |
|||
if (in_array($name, $allowed)) { |
|||
return $this->$name; |
|||
} else { |
|||
throw new \coding_exception($name.' is not a publicly accessible property of '.get_class($this)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Set the provider to "enabled". |
|||
* |
|||
* @param int | provider The provider to enable. |
|||
*/ |
|||
public function enable_provider($provider) { |
|||
$this->set_provider_enable_value($provider, 1); |
|||
} |
|||
|
|||
/** |
|||
* Set the provider to "disabled". |
|||
* |
|||
* @param int | provider The provider to disable. |
|||
*/ |
|||
public function disable_provider($provider) { |
|||
$this->set_provider_enable_value($provider, 0); |
|||
} |
|||
|
|||
/** |
|||
* Delete the local provider. |
|||
* |
|||
* @param int | provider The provider to delete. |
|||
*/ |
|||
public function delete_provider($provider) { |
|||
global $DB; |
|||
|
|||
if (is_object($provider)) { |
|||
$lookup = ['providername' => $provider->providername]; |
|||
$pid = $DB->get_field('filter_oembed', 'id', $lookup); |
|||
} else if (is_int($provider) || is_numeric($provider)) { |
|||
$pid = $provider; |
|||
} else { |
|||
throw new \coding_exception('oembed::enable_provider requires either a provider object or a data id integer.'); |
|||
} |
|||
|
|||
if (!isset($this->providers[$pid])) { |
|||
// Already deleted? |
|||
return; |
|||
} |
|||
|
|||
// Only delete local providers this way. |
|||
if (provider::source_type($this->providers[$pid]->source) == provider::PROVIDER_SOURCE_LOCAL) { |
|||
$DB->delete_records('filter_oembed', ['id' => $pid]); |
|||
unset($this->providers[$pid]); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get provider row from db. |
|||
* @param int $providerid The provider id for which we want to retrieve. |
|||
* @return providerrow |
|||
*/ |
|||
public function get_provider_row($providerid) { |
|||
global $DB; |
|||
return new providerrow($DB->get_record('filter_oembed', ['id' => $providerid])); |
|||
} |
|||
|
|||
/** |
|||
* Update provider row. |
|||
* @param array|object $providerdata |
|||
* @return bool |
|||
*/ |
|||
public function update_provider_row($providerdata) { |
|||
global $DB; |
|||
return $DB->update_record('filter_oembed', $providerdata); |
|||
} |
|||
|
|||
/** |
|||
* Copy downloaded provider row to new local row (or update). |
|||
* @param array|object $providerdata |
|||
* @return bool|int |
|||
*/ |
|||
public function copy_provider_to_local($providerdata) { |
|||
global $DB; |
|||
if (provider::source_type($providerdata['source']) != provider::PROVIDER_SOURCE_DOWNLOAD) { |
|||
return false; |
|||
} |
|||
$newsource = provider::PROVIDER_SOURCE_LOCAL . strtolower(str_replace(' ', '', $providerdata['providername'])); |
|||
if ($DB->record_exists('filter_oembed', ['source' => $newsource])) { |
|||
return false; |
|||
} |
|||
$providerdata['source'] = $newsource; |
|||
return $DB->insert_record('filter_oembed', $providerdata, true); |
|||
} |
|||
|
|||
/** |
|||
* Set the provider enabled field to the specified value. |
|||
* |
|||
* @param int | object $provider The provider to modify. |
|||
* @param int $value Value to set. |
|||
*/ |
|||
private function set_provider_enable_value($provider, $value) { |
|||
global $DB; |
|||
|
|||
if (is_object($provider)) { |
|||
$lookup = ['providername' => $provider->providername]; |
|||
$pid = $DB->get_field('filter_oembed', 'id', $lookup); |
|||
} else if (is_int($provider) || is_numeric($provider)) { |
|||
$pid = $provider; |
|||
} else { |
|||
throw new \coding_exception('oembed::enable_provider requires either a provider object or a data id integer.'); |
|||
} |
|||
|
|||
$DB->set_field('filter_oembed', 'enabled', $value, ['id' => $pid]); |
|||
$this->providers[$pid]->set_enabled($value == 1); |
|||
} |
|||
|
|||
/** |
|||
* Attempt to get aspect ratio from strings. |
|||
* @param string $width |
|||
* @param string $height |
|||
* @return float|int |
|||
*/ |
|||
protected static function get_aspect_ratio($width, $height) { |
|||
$bothperc = strpos($height, '%') !== false && strpos($width, '%') !== false; |
|||
$neitherperc = strpos($height, '%') === false && strpos($width, '%') === false; |
|||
// If both height and width use percentages or both don't then we can calculate an aspect ratio. |
|||
if ($bothperc || $neitherperc) { |
|||
// Calculate aspect ratio. |
|||
$aspectratio = intval($height) / intval($width); |
|||
} else { |
|||
$aspectratio = 0; |
|||
} |
|||
return $aspectratio; |
|||
} |
|||
|
|||
/** |
|||
* Get enabled provder data from the filter table and return as array of data records. |
|||
* Provider data is set when the plugin is installed, by scheduled tasks, by admin tools and |
|||
* by subplugins. |
|||
* @return array data records. |
|||
*/ |
|||
protected static function get_enabled_provider_data() { |
|||
global $DB; |
|||
|
|||
// Get providers from database. This includes sub-plugins. |
|||
return $DB->get_records('filter_oembed', array('enabled' => 1)); |
|||
} |
|||
|
|||
/** |
|||
* Get disabled provder data from the filter table and return as array of data records. |
|||
* Provider data is set when the plugin is installed, by scheduled tasks, by admin tools and |
|||
* by subplugins. |
|||
* @return array data records. |
|||
*/ |
|||
protected static function get_disabled_provider_data() { |
|||
global $DB; |
|||
|
|||
// Get providers from database. This includes sub-plugins. |
|||
return $DB->get_records('filter_oembed', array('enabled' => 0)); |
|||
} |
|||
|
|||
/** |
|||
* Get all provder data from the filter table and return as array of data records. |
|||
* Provider data is set when the plugin is installed, by scheduled tasks, by admin tools and |
|||
* by subplugins. |
|||
* |
|||
* @param string $fields Comma separated list of fields, the first of which is the index of the returned array. |
|||
* @return array data records. |
|||
*/ |
|||
protected static function get_all_provider_data($fields = '*') { |
|||
global $DB; |
|||
|
|||
// Get providers from database. This includes sub-plugins. |
|||
return $DB->get_records('filter_oembed', null, '', $fields); |
|||
} |
|||
} |
@ -0,0 +1,103 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* General utility class |
|||
* @author gthomas2 |
|||
* @copyright Copyright (c) 2016 Moodlerooms Inc. (http://www.moodlerooms.com) |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
namespace filter_oembed\service; |
|||
|
|||
use external_value; |
|||
use coding_exception; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once($CFG->dirroot . '/lib/externallib.php'); |
|||
|
|||
/** |
|||
* General utility class. |
|||
* @author gthomas2 |
|||
* @copyright Copyright (c) 2016 Moodlerooms Inc. (http://www.moodlerooms.com) |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class util { |
|||
/** |
|||
* Returns an array of \external_values based on a class or object for use with defining a webservice. |
|||
* |
|||
* NOTE: Current limitations - does not recurse to properties that are object instances or arrays. |
|||
* |
|||
* @param $classorobject |
|||
* @throws coding_exception |
|||
* @return external_value[] |
|||
*/ |
|||
public static function define_class_for_webservice($classorobject) { |
|||
$reflect = new \ReflectionClass($classorobject); |
|||
|
|||
$public = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC); |
|||
$singlemembers = []; |
|||
foreach ($public as $property) { |
|||
$name = $property->getName(); |
|||
$comment = $property->getDocComment(); |
|||
$regex = '/(?<=\*\s@wsparam\s)(\S*)\s(.*)/'; |
|||
$matches = []; |
|||
$haswsparamdoc = preg_match($regex, $comment, $matches); |
|||
if ($haswsparamdoc === 1) { |
|||
if (!defined($matches[1])) { |
|||
throw new coding_exception('Unknown / incompatible var type '.$matches[1].' for '.$name); |
|||
} |
|||
if (count($matches) < 3) { |
|||
throw new coding_exception('Missing description for '.$name); |
|||
} |
|||
$description = $matches[2]; |
|||
$type = constant($matches[1]); |
|||
} else { |
|||
$regex = '/(?<=\*\s@var\s)(\S*)\s(.*)/'; |
|||
$matches = []; |
|||
$aliases = [ |
|||
'bool' => PARAM_BOOL, |
|||
'str' => PARAM_RAW, |
|||
'string' => PARAM_RAW, |
|||
'int' => PARAM_INT, |
|||
'integer' => PARAM_INT |
|||
]; |
|||
$hasvardoc = preg_match($regex, $comment, $matches); |
|||
if ($hasvardoc !== 1) { |
|||
throw new coding_exception('Property without @var or @wsparam doc'); |
|||
} |
|||
if (count($matches) < 3) { |
|||
throw new coding_exception('Missing description for '.$name); |
|||
} |
|||
$description = $matches[2]; |
|||
$type = $matches[1]; |
|||
if (isset($aliases[$type])) { |
|||
$type = $aliases[$type]; |
|||
} else { |
|||
throw new coding_exception('Unknown / incompatible var type '.$type.' for '.$name); |
|||
} |
|||
} |
|||
|
|||
$regex = '/(?<=\*\s@wsrequired\s)/'; |
|||
$required = preg_match($regex, $comment, $matches); |
|||
|
|||
$singlemembers[$name] = new external_value($type, $description, $required); |
|||
|
|||
} |
|||
|
|||
return $singlemembers; |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
namespace filter_oembed\task; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
use filter_oembed\service\oembed; |
|||
|
|||
class update_providers extends \core\task\scheduled_task { |
|||
|
|||
/** |
|||
* Get a descriptive name for this task (shown to admins). |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function get_name() { |
|||
return get_string('updateproviders', 'filter_oembed'); |
|||
} |
|||
|
|||
/** |
|||
* Run forum cron. |
|||
*/ |
|||
public function execute() { |
|||
oembed::update_provider_data(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,96 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
namespace filter_oembed\webservice; |
|||
|
|||
use filter_oembed\output\providermodel; |
|||
use filter_oembed\service\util; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once(__DIR__ . '/../../../../lib/externallib.php'); |
|||
|
|||
/** |
|||
* Web service for managing provider visibility. |
|||
* @author Guy Thomas |
|||
* @copyright Copyright (c) 2016 Moodlerooms Inc. (http://www.moodlerooms.com) |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class ws_provider_manage extends \external_api { |
|||
/** |
|||
* @return \external_function_parameters |
|||
*/ |
|||
public static function service_parameters() { |
|||
$parameters = [ |
|||
'pid' => new \external_value(PARAM_INT, 'Provider id', VALUE_REQUIRED), |
|||
'action' => new \external_value(PARAM_ALPHA, 'Action: enable / disable / reload / delete', VALUE_REQUIRED) |
|||
]; |
|||
return new \external_function_parameters($parameters); |
|||
} |
|||
|
|||
/** |
|||
* @return \external_single_structure |
|||
*/ |
|||
public static function service_returns() { |
|||
$keys = [ |
|||
'visible' => new \external_value(PARAM_INT, 'Provider visibility', VALUE_REQUIRED), |
|||
'providermodel' => new \external_single_structure( |
|||
util::define_class_for_webservice('filter_oembed\output\providermodel'), |
|||
'Provider renderable', |
|||
VALUE_OPTIONAL |
|||
) |
|||
]; |
|||
|
|||
return new \external_single_structure($keys, 'provider'); |
|||
} |
|||
|
|||
/** |
|||
* @param int $pid |
|||
* @param string $action |
|||
* @return array |
|||
*/ |
|||
public static function service($pid, $action) { |
|||
$oembed = \filter_oembed\service\oembed::get_instance('all'); |
|||
|
|||
if ($action === 'enable' || $action === 'disable') { |
|||
if ($action === 'enable') { |
|||
$oembed->enable_provider($pid); |
|||
} else { |
|||
$oembed->disable_provider($pid); |
|||
} |
|||
} |
|||
|
|||
if ($action === 'delete') { |
|||
$oembed->delete_provider($pid); |
|||
return [ |
|||
'visible' => 0 |
|||
]; |
|||
} else { |
|||
$providerrow = $oembed->get_provider_row($pid); |
|||
$providermodel = new providermodel($providerrow); |
|||
$visible = intval($providerrow->enabled); |
|||
if ($action === 'enable' || $action === 'disable') { |
|||
$visible = $action === 'enable' ? 1 : 0; |
|||
} |
|||
return [ |
|||
'visible' => $visible, |
|||
'providermodel' => $providermodel |
|||
]; |
|||
} |
|||
|
|||
throw new coding_exception('Invalid action - '.$action); |
|||
} |
|||
} |
@ -0,0 +1,93 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
namespace filter_oembed\webservice; |
|||
|
|||
use filter_oembed\output\managementpage; |
|||
use filter_oembed\service\oembed; |
|||
use filter_oembed\service\util; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once(__DIR__ . '/../../../../lib/externallib.php'); |
|||
|
|||
/** |
|||
* Web service for getting array of provider models. |
|||
* @author Guy Thomas |
|||
* @copyright Copyright (c) 2016 Moodlerooms Inc. (http://www.moodlerooms.com) |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class ws_providers extends \external_api { |
|||
/** |
|||
* @return \external_function_parameters |
|||
*/ |
|||
public static function service_parameters() { |
|||
$parameters = [ |
|||
'scope' => new \external_value(PARAM_ALPHA, 'Providers scope - all, enabled, disabled', VALUE_OPTIONAL, 'all') |
|||
]; |
|||
return new \external_function_parameters($parameters); |
|||
} |
|||
|
|||
/** |
|||
* @return \external_single_structure |
|||
*/ |
|||
public static function service_returns() { |
|||
$keys = [ |
|||
'downloadrows' => new \external_multiple_structure( |
|||
new \external_single_structure( |
|||
util::define_class_for_webservice('filter_oembed\output\providermodel'), |
|||
'Provider renderable', |
|||
VALUE_REQUIRED |
|||
), 'Array of downloaded providers', VALUE_REQUIRED |
|||
), |
|||
'pluginrows' => new \external_multiple_structure( |
|||
new \external_single_structure( |
|||
util::define_class_for_webservice('filter_oembed\output\providermodel'), |
|||
'Provider renderable', |
|||
VALUE_REQUIRED |
|||
), 'Array of plugin providers', VALUE_REQUIRED |
|||
), |
|||
'localrows' => new \external_multiple_structure( |
|||
new \external_single_structure( |
|||
util::define_class_for_webservice('filter_oembed\output\providermodel'), |
|||
'Provider renderable', |
|||
VALUE_REQUIRED |
|||
), 'Array of local providers', VALUE_REQUIRED |
|||
) |
|||
|
|||
]; |
|||
|
|||
return new \external_single_structure($keys, 'Providers array.'); |
|||
} |
|||
|
|||
/** |
|||
* @param int $pid |
|||
* @param string $action |
|||
* @return array |
|||
*/ |
|||
public static function service($scope) { |
|||
global $PAGE; |
|||
$PAGE->set_context(\context_system::instance()); |
|||
$output = $PAGE->get_renderer('core', '', RENDERER_TARGET_GENERAL); |
|||
|
|||
$oembed = oembed::get_instance($scope); |
|||
|
|||
$providerrows = $oembed->providers; |
|||
|
|||
$page = new managementpage($providerrows); |
|||
return $page->export_for_template($output); |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* oEmbed cache definitions |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2016 Blackboard Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$definitions = array( |
|||
'embeddata' => array( |
|||
'mode' => cache_store::MODE_APPLICATION, |
|||
'ttl' => HOURSECS, |
|||
), |
|||
); |
|||
|
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle-oembed-Filter |
|||
// |
|||
// Moodle-oembed-Filter is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle-oembed-Filter is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle-oembed-Filter. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Filter for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft, Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
use filter_oembed\service\oembed; |
|||
/** |
|||
* Installs the OEmbed filter. |
|||
*/ |
|||
function xmldb_filter_oembed_install() { |
|||
filter_set_global_state('filter/oembed', TEXTFILTER_ON); |
|||
|
|||
// Insert the initial data elements from the instance's providers. |
|||
oembed::update_provider_data(); |
|||
} |
@ -0,0 +1,26 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<XMLDB PATH="filter/oembed/db" VERSION="20160826" COMMENT="XMLDB file for Moodle filter/oembed" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" |
|||
> |
|||
<TABLES> |
|||
<TABLE NAME="filter_oembed" COMMENT="Default comment for filter_oembed, please edit me"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="providername" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="providerurl" TYPE="char" LENGTH="1333" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="endpoints" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="JSON encoded endpoints structure."/> |
|||
<FIELD NAME="source" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Original source of provider. This may include a category code."/> |
|||
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
<INDEXES> |
|||
<INDEX NAME="providernameix" UNIQUE="false" FIELDS="providername"/> |
|||
</INDEXES> |
|||
</TABLE> |
|||
</TABLES> |
|||
</XMLDB> |
@ -0,0 +1,44 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Services |
|||
* @author Guy Thomas |
|||
* @copyright Copyright (c) 2016 Moodlerooms Inc. (http://www.moodlerooms.com) |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$functions = [ |
|||
'filter_oembed_provider_manage' => [ |
|||
'classname' => 'filter_oembed\\webservice\\ws_provider_manage', |
|||
'methodname' => 'service', |
|||
'description' => 'Manage provider visibility / reload', |
|||
'type' => 'write', |
|||
'ajax' => true, |
|||
'loginrequired' => true |
|||
], |
|||
'filter_oembed_providers' => [ |
|||
'classname' => 'filter_oembed\\webservice\\ws_providers', |
|||
'methodname' => 'service', |
|||
'description' => 'Array of providers', |
|||
'type' => 'read', |
|||
'ajax' => true, |
|||
'loginrequired' => true |
|||
] |
|||
]; |
|||
|
@ -0,0 +1,5 @@ |
|||
{ |
|||
"plugintypes": { |
|||
"oembedprovider": "filter\/oembed\/provider" |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$tasks = array( |
|||
array( |
|||
'classname' => 'filter_oembed\task\update_providers', |
|||
'blocking' => 0, |
|||
'minute' => 'R', |
|||
'hour' => '3', |
|||
'day' => '*', |
|||
'month' => '*', |
|||
'dayofweek' => '*' |
|||
) |
|||
); |
@ -0,0 +1,142 @@ |
|||
<?php |
|||
// This file is part of Moodle-oembed-Filter |
|||
// |
|||
// Moodle-oembed-Filter is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle-oembed-Filter is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle-oembed-Filter. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Filter for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft, Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
use filter_oembed\service\oembed; |
|||
use filter_oembed\provider\provider; |
|||
|
|||
/** |
|||
* Upgrades the OEmbed filter. |
|||
* |
|||
* @param $oldversion Version to be upgraded from. |
|||
* @return bool Success. |
|||
*/ |
|||
function xmldb_filter_oembed_upgrade($oldversion) { |
|||
global $DB; |
|||
|
|||
$dbman = $DB->get_manager(); |
|||
|
|||
if ($oldversion < 2016070501) { |
|||
|
|||
// Define table filter_oembed to be created. |
|||
$table = new xmldb_table('filter_oembed'); |
|||
|
|||
// Adding fields to table filter_oembed. |
|||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
|||
$table->add_field('providername', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('providerurl', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('endpoints', XMLDB_TYPE_TEXT, null, null, null, null, null); |
|||
$table->add_field('source', XMLDB_TYPE_CHAR, '255', null, null, null, null); |
|||
$table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', null, null, null, '0'); |
|||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, null, null, '0'); |
|||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, '0'); |
|||
|
|||
// Adding keys to table filter_oembed. |
|||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
|||
|
|||
// Adding indexes to table filter_oembed. |
|||
$table->add_index('providernameix', XMLDB_INDEX_NOTUNIQUE, array('providername')); |
|||
|
|||
// Conditionally launch create table for filter_oembed. |
|||
if (!$dbman->table_exists($table)) { |
|||
$dbman->create_table($table); |
|||
} |
|||
|
|||
// Insert the initial data elements from the instance's providers. |
|||
oembed::update_provider_data(); |
|||
|
|||
// Migrate old settings to new settings. Ensure all old filters are still present. |
|||
$config = get_config('filter_oembed'); |
|||
$providermap = [ |
|||
'youtube' => ['YouTube', 'http://www.youtube.com', ['http://www.youtube.com/*'], |
|||
'http://www.youtube.com/oembed'], |
|||
'vimeo' => ['Vimeo', 'http://vimeo.com', ['http://vimeo.com/*'], 'https://vimeo.com/api/omebed.json'], |
|||
'ted' => ['Ted', 'http://ted.com', ['http://ted.com/talks/*'], 'http://www.ted.com/talks/oembed.json'], |
|||
'slideshare' => ['SlideShare', 'http://www.slideshare.net', |
|||
['http://www.slideshare.net/*'], 'http://www.slideshare.net/api/oembed/2'], |
|||
'officemix' => ['Office Mix', 'http://mix.office.com', ['http://mix.office.com/*'], |
|||
'https://mix.office.com/oembed'], |
|||
'issuu' => ['ISSUU', 'http://issuu.com', ['http://issuu.com/*'], 'http://issuu.com/oembed'], |
|||
'soundcloud' => ['SoundCloud', 'http://soundcloud.com', ['http://soundcloud.com/*'], |
|||
'https://soundcloud.com/oembed'], |
|||
'pollev' => ['Poll Everywhere', 'http://polleverywhere.com', |
|||
['http://polleverywhere.com/polls/*', 'http://polleverywhere.com/multiple_choice_polls/*', |
|||
'http://polleverywhere.com/free_text_polls/*'], 'http://www.polleverywhere.com/services/oembed'], |
|||
'o365video' => ['Office365 Video', '', [''], ''], |
|||
'sway' => ['Sway', 'https://www,sway.com', ['http://www.sway.com/*'], 'https://sway.com/api/v1.0/oembed'], |
|||
'provider_docsdotcom_enabled' => ['Docs', '', [''], ''], |
|||
'provider_powerbi_enabled' => ['Power BI', '', [''], ''], |
|||
'provider_officeforms_enabled' => ['Office Forms', '', [''], ''] |
|||
]; |
|||
|
|||
foreach ($providermap as $oldprovider => $newprovider) { |
|||
// There may be more than one provider with the same name. If that happens, use the first. |
|||
$provider = $DB->get_record('filter_oembed', ['providername' => $newprovider[0]], '*', IGNORE_MULTIPLE); |
|||
|
|||
// Look for originally hard-coded plugins. If still not present, create it from old code. |
|||
// If it is present, assume that it has since been added to the oembed repo and use that. |
|||
$insert = false; |
|||
|
|||
if (empty($provider)) { |
|||
// Handle non-downloaded Oembed types. |
|||
$insert = true; |
|||
$provider = new stdClass(); |
|||
$provider->providername = $newprovider[0]; |
|||
$provider->providerurl = $newprovider[1]; |
|||
$endpoints = [ |
|||
'schemes' => $newprovider[2], |
|||
'url' => $newprovider[3], |
|||
]; |
|||
$provider->endpoints = json_encode($endpoints); |
|||
if (($oldprovider == 'provider_powerbi_enabled') || ($oldprovider == 'provider_officeforms_enabled') || |
|||
($oldprovider == 'o365video')) { |
|||
$provider->source = provider::PROVIDER_SOURCE_PLUGIN . $oldprovider; |
|||
} else { |
|||
$provider->source = provider::PROVIDER_SOURCE_LOCAL . 'oldoembed'; |
|||
} |
|||
$provider->timecreated = time(); |
|||
} |
|||
$provider->enabled = (!isset($config->$oldprovider) || empty($config->$oldprovider)) ? 0 : 1; |
|||
$provider->timemodified = time(); |
|||
if ($insert) { |
|||
$DB->insert_record('filter_oembed', $provider); |
|||
} else { |
|||
$DB->update_record('filter_oembed', $provider); |
|||
} |
|||
unset_config($oldprovider, 'filter_oembed'); |
|||
} |
|||
|
|||
// Remove other configuration settings no longer used. |
|||
unset_config('providersrestrict', 'filter_oembed'); |
|||
|
|||
// Oembed savepoint reached. |
|||
upgrade_plugin_savepoint(true, 2016070501, 'filter', 'oembed'); |
|||
} |
|||
|
|||
return true; |
|||
} |
@ -0,0 +1,101 @@ |
|||
<?php |
|||
// This file is part of Moodle-oembed-Filter |
|||
// |
|||
// Moodle-oembed-Filter is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle-oembed-Filter is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle-oembed-Filter. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Filter for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @author Mat Cannings |
|||
* @author James McQuillan |
|||
* @author Vin Bhalerao |
|||
* @author Erich M. Wappis <erich.wappis@uni-graz.at> |
|||
* @author Guy Thomas <brudinie@googlemail.com> |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
use filter_oembed\service\oembed; |
|||
|
|||
require_once($CFG->libdir.'/filelib.php'); |
|||
/** |
|||
* Main filter class for embedded remote content. |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class filter_oembed extends moodle_text_filter { |
|||
|
|||
/** |
|||
* content gets filtered, links either wrapped in an <a> tag or in a <div> tag with class="oembed" |
|||
* will be replaced by embeded content |
|||
* |
|||
* @param $text HTML to be processed. |
|||
* @param $options |
|||
* @return string String containing processed HTML. |
|||
*/ |
|||
public function filter($text, array $options = array()) { |
|||
global $PAGE; |
|||
|
|||
static $initialised = false; |
|||
|
|||
if (!$initialised) { |
|||
$PAGE->requires->js_call_amd('filter_oembed/oembed', 'init'); |
|||
$initialised = true; |
|||
} |
|||
|
|||
$targettag = get_config('filter_oembed', 'targettag'); |
|||
|
|||
if ($targettag == 'atag' && stripos($text, '</a>') === false) { |
|||
// Performance shortcut - all regexes below end with the </a> tag. |
|||
// If not present nothing can match. |
|||
return $text; |
|||
} |
|||
|
|||
$filtered = $text; // We need to return the original value if regex fails! |
|||
if ($targettag == 'divtag') { |
|||
$search = '/\<div\s[^\>]*data-oembed-href="(.*?)"(.*?)>(.*?)\<\/div\>/'; |
|||
} else { // Using 'atag'. |
|||
$search = '/\<a\s[^\>]*href="(.*?)"(?:.*?)>(?:.*?)\<\/a\>/is'; |
|||
} |
|||
|
|||
$filtered = preg_replace_callback($search, 'self::find_oembeds_callback', $filtered); |
|||
if (empty($filtered)) { |
|||
// If $filtered is emtpy return original $text. |
|||
return $text; |
|||
} else { |
|||
return $filtered; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Callback function to be used by the main filter |
|||
* |
|||
* @param $match array An array of matched groups, where [1] is the URL matched. |
|||
* |
|||
*/ |
|||
private static function find_oembeds_callback($match) { |
|||
$instance = oembed::get_instance(); |
|||
$result = $instance->html_output($match[1]); |
|||
if (empty($result)) { |
|||
$result = $match[0]; |
|||
} |
|||
return $result; |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Language strings for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'Filtr oEmbed'; |
|||
$string['youtube'] = 'Youtube'; |
|||
$string['vimeo'] = 'Vimeo'; |
|||
$string['ted'] = 'Ted Talks'; |
|||
$string['slideshare'] = 'SlideShare'; |
|||
$string['officemix'] = 'Office Mix'; |
|||
$string['issuu'] = 'Issuu'; |
|||
$string['screenr'] = 'Screenr'; |
|||
$string['soundcloud'] = 'SoundCloud'; |
|||
$string['pollev'] = 'Poll Everywhere'; |
|||
$string['lazyload'] = 'Zpozdit načítání vložených prvků (opožděné načítání)'; |
|||
$string['connection_error'] = 'Při přístupu k vloženému médiu došlo k chybě. Zkuste aktualizovat stránku.'; |
@ -0,0 +1,41 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Filter for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filter |
|||
* oEmbed filter ( Mike Churchward, James McQuillan, Vinayak (Vin) Bhalerao, Josh Gavant and Rob Dolin) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'Embed Remote Content Filter'; |
|||
$string['cachelifespan_disabled'] = 'Cache Lebensdauer deaktiviert'; |
|||
$string['cachelifespan'] = 'Cache Lebensdauer'; |
|||
$string['cachelifespan_desc'] = 'Zeitabstand nach dem die Providerliste aktualisiert wird.'; |
|||
$string['cachelifespan_daily'] = '1 Tag'; |
|||
$string['cachelifespan_weekly'] = '1 Woche'; |
|||
$string['atag'] = 'Filtere < a > tags'; |
|||
$string['divtag'] = 'Filtere < div > tags'; |
|||
$string['targettag'] = 'Ziel tag'; |
|||
$string['targettag_desc'] = 'Welche Art von tag soll gefiltert werden? Links oder divs mit der oembed Klasse.'; |
|||
$string['providersrestrict'] = 'Providerbeschränkung'; |
|||
$string['providersrestrict_desc'] = 'Beschränke Provider mit einer List zugelassener Provider'; |
|||
$string['providersallowed'] = 'Zugelassene Provider.'; |
|||
$string['providersallowed_desc'] = 'Die Provider die vor diese Moodleinstallation verfügbar sind.'; |
|||
$string['connection_error'] = 'Fehler beim Zugriff auf die integrierten Medien. Versuchen Sie, die Seite zu aktualisieren.'; |
@ -0,0 +1,64 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Filter for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filter |
|||
* oEmbed filter ( Mike Churchward, James McQuillan, Vinayak (Vin) Bhalerao, Josh Gavant and Rob Dolin) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'Oembed Filter'; |
|||
$string['atag'] = 'Filter on < a > tags'; |
|||
$string['cachelifespan_disabled'] = 'Cache lifespan disabled'; |
|||
$string['cachelifespan'] = 'Cache lifespan'; |
|||
$string['cachelifespan_desc'] = 'The duration of time before the providers list should be refreshed.'; |
|||
$string['cachelifespan_daily'] = '1 day'; |
|||
$string['cachelifespan_weekly'] = '1 week'; |
|||
$string['connection_error'] = 'Error connecting to external provider, please try reloading the page.'; |
|||
$string['copytolocal'] = 'Created new local provider definition for "{$a}".'; |
|||
$string['deleteprovidertitle'] = 'Delete provider'; |
|||
$string['deleteproviderconfirm'] = 'Are you sure you want to delete provider "{$a}"?'; |
|||
$string['divtag'] = 'Filter on < div > tags'; |
|||
$string['downloadproviders'] = 'Downloaded providers'; |
|||
$string['enabled'] = 'Enabled'; |
|||
$string['endpoints'] = 'End points'; |
|||
$string['lazyload'] = 'Delay Embed Loading (Lazyload)'; |
|||
$string['localproviders'] = 'Local providers'; |
|||
$string['manageproviders'] = 'Manage providers'; |
|||
$string['nocopytolocal'] = 'Could not create new local provider definition for "{$a}". It may already exist.'; |
|||
$string['playoembed'] = 'Play'; |
|||
$string['pluginproviders'] = 'Plugin providers'; |
|||
$string['provider'] = 'Provider'; |
|||
$string['providername'] = 'Provider Name'; |
|||
$string['providersrestrict'] = 'Restrict providers'; |
|||
$string['providersrestrict_desc'] = 'Restrict providers to a list of allowed providers'; |
|||
$string['providersallowed'] = 'Providers allowed.'; |
|||
$string['providersallowed_desc'] = 'Providers whitelisted to be used with this plugin'; |
|||
$string['providerurl'] = 'Provider URL'; |
|||
$string['requiredfield'] = 'The field "{$a}" must be completed'; |
|||
$string['subplugintype_oembedprovider'] = 'Oembed provider'; |
|||
$string['subplugintype_oembedprovider_plural'] = 'Oembed providers'; |
|||
$string['saveasnew'] = 'Save as new local'; |
|||
$string['saveok'] = 'Successfully saved provider.'; |
|||
$string['savefailed'] = 'Failed to save provider.'; |
|||
$string['source'] = 'Provider source'; |
|||
$string['targettag'] = 'Target tag'; |
|||
$string['targettag_desc'] = 'What tag type should be filtered - anchors or divs with the oembed class.'; |
|||
$string['updateproviders'] = 'Update Oembed provider information.'; |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Language strings for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'oEmbed Filter'; |
|||
$string['youtube'] = 'Youtube'; |
|||
$string['vimeo'] = 'Vimeo'; |
|||
$string['ted'] = 'Ted Talks'; |
|||
$string['slideshare'] = 'SlideShare'; |
|||
$string['officemix'] = 'Office Mix'; |
|||
$string['issuu'] = 'Issuu'; |
|||
$string['screenr'] = 'Screenr'; |
|||
$string['soundcloud'] = 'SoundCloud'; |
|||
$string['pollev'] = 'Poll Everywhere'; |
|||
$string['lazyload'] = 'Demorar carga integrada (Lazyload)'; |
|||
$string['connection_error'] = 'Error al acceder al medio integrado. Intente actualizar la página.'; |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Language strings for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'oEmbed-suodatin'; |
|||
$string['youtube'] = 'YouTube'; |
|||
$string['vimeo'] = 'Vimeo'; |
|||
$string['ted'] = 'Ted Talks'; |
|||
$string['slideshare'] = 'SlideShare'; |
|||
$string['officemix'] = 'Office Mix'; |
|||
$string['issuu'] = 'Issuu'; |
|||
$string['screenr'] = 'Screenr'; |
|||
$string['soundcloud'] = 'SoundCloud'; |
|||
$string['pollev'] = 'Poll Everywhere'; |
|||
$string['lazyload'] = 'Lykkää upotetun median lataamista'; |
|||
$string['connection_error'] = 'Virhe upotetun median käytön aikana. Kokeile päivittää sivu.'; |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Language strings for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'Filtre oEmbed'; |
|||
$string['youtube'] = 'Youtube'; |
|||
$string['vimeo'] = 'Vimeo'; |
|||
$string['ted'] = 'Chats Ted'; |
|||
$string['slideshare'] = 'SlideShare'; |
|||
$string['officemix'] = 'Combinaison Office'; |
|||
$string['issuu'] = 'Problème'; |
|||
$string['screenr'] = 'Écran'; |
|||
$string['soundcloud'] = 'SoundCloud'; |
|||
$string['pollev'] = 'Sonder partout'; |
|||
$string['lazyload'] = 'Retarder l\'intégration du chargement (Lazyload)'; |
|||
$string['connection_error'] = 'Erreur lors de l\'accès au média intégré. Veuillez actualiser la page.'; |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Language strings for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'Filtro oEmbed'; |
|||
$string['youtube'] = 'Youtube'; |
|||
$string['vimeo'] = 'Vimeo'; |
|||
$string['ted'] = 'Ted Talks'; |
|||
$string['slideshare'] = 'SlideShare'; |
|||
$string['officemix'] = 'Office Mix'; |
|||
$string['issuu'] = 'Issuu'; |
|||
$string['screenr'] = 'Screenr'; |
|||
$string['soundcloud'] = 'SoundCloud'; |
|||
$string['pollev'] = 'Poll Everywhere'; |
|||
$string['lazyload'] = 'Delay Embed Loading (Lazyload)'; |
|||
$string['connection_error'] = 'Errore durante l\'accesso al media incorporato. Prova ad aggiornare la pagina.'; |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Language strings for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'oEmbedフィルタ'; |
|||
$string['youtube'] = 'Youtube'; |
|||
$string['vimeo'] = 'Vimeo'; |
|||
$string['ted'] = 'Ted Talks'; |
|||
$string['slideshare'] = 'SlideShare'; |
|||
$string['officemix'] = 'Office Mix'; |
|||
$string['issuu'] = 'Issuu'; |
|||
$string['screenr'] = 'Screenr'; |
|||
$string['soundcloud'] = 'SoundCloud'; |
|||
$string['pollev'] = 'Poll Everywhere'; |
|||
$string['lazyload'] = '遅延埋め込みロード (Lazyload)'; |
|||
$string['connection_error'] = '埋め込みメディアへのアクセス中にエラーが発生しました。ページを再読み込みしてください。'; |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Language strings for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'oEmbed Filter'; |
|||
$string['youtube'] = 'YouTube'; |
|||
$string['vimeo'] = 'Vimeo'; |
|||
$string['ted'] = 'Ted Talks'; |
|||
$string['slideshare'] = 'SlideShare'; |
|||
$string['officemix'] = 'Office Mix'; |
|||
$string['issuu'] = 'Issuu'; |
|||
$string['screenr'] = 'Screenr'; |
|||
$string['soundcloud'] = 'SoundCloud'; |
|||
$string['pollev'] = 'Poll Everywhere'; |
|||
$string['lazyload'] = 'Delay Embed Loading (Lazyload)'; |
|||
$string['connection_error'] = 'Fout tijdens het openen van ingesloten media. Probeer de pagina te vernieuwen.'; |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Language strings for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'oEmbed Filter'; |
|||
$string['youtube'] = 'Youtube'; |
|||
$string['vimeo'] = 'Vimeo'; |
|||
$string['ted'] = 'Ted Talks'; |
|||
$string['slideshare'] = 'SlideShare'; |
|||
$string['officemix'] = 'Office Mix'; |
|||
$string['issuu'] = 'Issuu'; |
|||
$string['screenr'] = 'Screenr'; |
|||
$string['soundcloud'] = 'SoundCloud'; |
|||
$string['pollev'] = 'Poll Everywhere'; |
|||
$string['lazyload'] = 'Opóźnij ładowanie osadzania (Lazyload)'; |
|||
$string['connection_error'] = 'Błąd podczas uzyskiwania dostępu do osadzonego elementu multimedialnego. Spróbuj odświeżyć stronę.'; |
@ -0,0 +1,39 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Language strings for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright 2012 Matthew Cannings; modified 2015 by Microsoft Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filters... |
|||
* Screencast (Mark Schall) |
|||
* Soundcloud (Troy Williams) |
|||
*/ |
|||
|
|||
$string['filtername'] = 'Filtro oEmbed'; |
|||
$string['youtube'] = 'YouTube'; |
|||
$string['vimeo'] = 'Vimeo'; |
|||
$string['ted'] = 'Ted Talks'; |
|||
$string['slideshare'] = 'SlideShare'; |
|||
$string['officemix'] = 'Office Mix'; |
|||
$string['issuu'] = 'Issuu'; |
|||
$string['screenr'] = 'Screenr'; |
|||
$string['soundcloud'] = 'SoundCloud'; |
|||
$string['pollev'] = 'Poll Everywhere'; |
|||
$string['lazyload'] = 'Carregamento de incorporação com atraso (Lazy load)'; |
|||
$string['connection_error'] = 'Erro ao acessar a mídia incorporada. Tente atualizar a página.'; |
@ -0,0 +1,99 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* General lib file |
|||
* @author Guy Thomas <gthomas@moodlerooms.com> |
|||
* @copyright Copyright (c) 2016 Blackboard Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
use filter_oembed\forms\provider; |
|||
|
|||
/** |
|||
* Serve the edit form as a fragment. |
|||
* |
|||
* @param array $args List of named arguments for the fragment loader. |
|||
* @return string |
|||
*/ |
|||
function filter_oembed_output_fragment_provider($args) { |
|||
global $PAGE, $CFG; |
|||
|
|||
$output = $PAGE->get_renderer('core', '', RENDERER_TARGET_GENERAL); |
|||
|
|||
$oembed = \filter_oembed\service\oembed::get_instance('all'); |
|||
|
|||
$data = null; |
|||
$ajaxdata = null; |
|||
if (!empty($args['formdata'])) { |
|||
$data = []; |
|||
parse_str($args['formdata'], $data); |
|||
if ($data) { |
|||
$ajaxdata = $data; |
|||
} |
|||
} else { |
|||
if (!isset($args['pid'])) { |
|||
throw new coding_exception('missing "pid" param'); |
|||
} else { |
|||
$data = $oembed->get_provider_row($args['pid']); |
|||
if (!$data) { |
|||
throw new coding_exception('Invalid "pid" param', $args['pid']); |
|||
} |
|||
$data = (array)$data; |
|||
} |
|||
} |
|||
|
|||
if (!isset($ajaxdata['enabled'])) { |
|||
$ajaxdata['enabled'] = 0; |
|||
} |
|||
$actionurl = $CFG->wwwroot.'/filter/oembed/manageproviders.php'; |
|||
// Pass the source type as custom data so it can by used to detetmine the type of edit. |
|||
$form = new provider($actionurl, \filter_oembed\provider\provider::source_type($data['source']), |
|||
'post', '', null, true, $ajaxdata); |
|||
$form->validate_defined_fields(true); |
|||
$data['sourcetext'] = $data['source']; |
|||
$form->set_data($data); |
|||
|
|||
$msg = ''; |
|||
if (!empty($ajaxdata)) { |
|||
if ($form->is_validated()) { |
|||
// If editing a downloaded provider, create a new local one and disable the download one. |
|||
$sourcetype = \filter_oembed\provider\provider::source_type($ajaxdata['source']); |
|||
if ($sourcetype == \filter_oembed\provider\provider::PROVIDER_SOURCE_DOWNLOAD) { |
|||
$newpid = $oembed->copy_provider_to_local($ajaxdata); |
|||
if ($newpid) { |
|||
$msg = $output->notification(get_string('copytolocal', 'filter_oembed', $ajaxdata['providername']), |
|||
'notifysuccess'); |
|||
// Return an empty div with the new provider id in it so we can target it later with the message in $msg. |
|||
return '<div class="js-oembed-newprovider" data-newproviderid = "'.$newpid.'"></div>'.$msg; |
|||
} else { |
|||
$msg = $output->notification(get_string('nocopytolocal', 'filter_oembed', $ajaxdata['providername']), |
|||
'notifyproblem'); |
|||
} |
|||
} else { |
|||
$success = $oembed->update_provider_row($ajaxdata); |
|||
if ($success) { |
|||
$msg = $output->notification(get_string('saveok', 'filter_oembed'), 'notifysuccess'); |
|||
} else { |
|||
$msg = $output->notification(get_string('savefailed', 'filter_oembed'), 'notifyproblem'); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return $form->render().$msg; |
|||
} |
@ -0,0 +1,83 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
require_once(dirname(__FILE__) . '/../../config.php'); |
|||
require_once($CFG->libdir.'/adminlib.php'); |
|||
|
|||
require_login(); |
|||
|
|||
$systemcontext = context_system::instance(); |
|||
require_capability('moodle/site:config', $systemcontext); |
|||
admin_externalpage_setup('filter_oembed_providers'); |
|||
|
|||
$action = optional_param('action', '', PARAM_ALPHA); |
|||
$pid = optional_param('pid', 0, PARAM_INT); |
|||
|
|||
if (!empty($action)) { |
|||
require_sesskey(); |
|||
} |
|||
|
|||
$PAGE->requires->js_call_amd('filter_oembed/manageproviders', 'init'); |
|||
|
|||
$oembed = \filter_oembed\service\oembed::get_instance('all'); |
|||
|
|||
// Process actions. |
|||
switch ($action) { |
|||
case 'edit': |
|||
break; |
|||
|
|||
case 'disable': |
|||
$oembed->disable_provider($pid); |
|||
break; |
|||
|
|||
case 'enable': |
|||
$oembed->enable_provider($pid); |
|||
break; |
|||
|
|||
case 'delete': |
|||
$oembed->delete_provider($pid); |
|||
break; |
|||
} |
|||
|
|||
$PAGE->set_context($systemcontext); |
|||
$baseurl = new moodle_url('/filter/oembed/manageproviders.php'); |
|||
$PAGE->set_url($baseurl); |
|||
$PAGE->set_pagelayout('standard'); |
|||
$strmanage = get_string('manageproviders', 'filter_oembed'); |
|||
$PAGE->set_title($strmanage); |
|||
$PAGE->set_heading($strmanage); |
|||
$PAGE->requires->strings_for_js( |
|||
[ |
|||
'deleteprovidertitle', |
|||
'deleteproviderconfirm' |
|||
], |
|||
'filter_oembed' |
|||
); |
|||
|
|||
$output = $PAGE->get_renderer('filter_oembed'); |
|||
echo $output->header(); |
|||
|
|||
$managepage = new \filter_oembed\output\managementpage($oembed->providers); |
|||
echo $output->render($managepage); |
|||
|
|||
// Finish the page. |
|||
echo $output->footer(); |
@ -0,0 +1,15 @@ |
|||
{ |
|||
"description": "Grunt tasks for sass.", |
|||
"private": true, |
|||
"devDependencies": { |
|||
"grunt": "~0.4.1", |
|||
"grunt-autoprefixer": "^3.0.3", |
|||
"grunt-contrib-csslint": "^0.5.0", |
|||
"grunt-contrib-jshint": "^0.12.0", |
|||
"grunt-sass": "^1.2.1", |
|||
"grunt-cssbeautifier": "^0.1.2", |
|||
"grunt-contrib-watch": "^0.6.1", |
|||
"grunt-exec": "~0.4.2", |
|||
"grunt-load-gruntfile" : "^0.0.2" |
|||
} |
|||
} |
After Width: | Height: | Size: 271 B |
@ -0,0 +1,86 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author James McQuillan <james.mcquillan@remote-learner.net> |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright (C) 2016 onwards Microsoft, Inc. (http://microsoft.com/) |
|||
*/ |
|||
|
|||
namespace filter_oembed\provider; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* oEmbed provider implementation for Docs.com |
|||
*/ |
|||
class docsdotcom extends provider { |
|||
|
|||
/** |
|||
* Constructor. |
|||
* @param $data JSON decoded array or a data object containing all provider data. |
|||
*/ |
|||
public function __construct($data = null) { |
|||
if ($data === null) { |
|||
$data = [ |
|||
'providername' => 'Docs', |
|||
'providerurl' => 'https://docs.com', |
|||
'endpoints' => [ |
|||
['schemes' => ['https://docs.com/*', 'https://www.docs.com/*'], |
|||
'url' => 'https:\/\/docs.com\/api\/oembed', |
|||
'formats' => ['json'] |
|||
] |
|||
] |
|||
]; |
|||
} |
|||
parent::__construct($data); |
|||
} |
|||
|
|||
/** |
|||
* If a matching endpoint scheme is found in the passed text, return a consumer request URL. |
|||
* |
|||
* @param string $text The text to look for an URL resource using provider's schemes. |
|||
* @return string Consumer request URL. |
|||
*/ |
|||
public function get_oembed_request($text) { |
|||
$requesturl = ''; |
|||
// Get the regex arrauy to look for matching schemes. |
|||
$regex = $this->endpoints_regex(new endpoint()); |
|||
if (preg_match($regex, $text, $matched)) { |
|||
$params = [ |
|||
'url' => $matched[1]. $matched[3] . '/' . $matched[4] . '/' . $matched[5] . '/' . $matched[6], |
|||
'format' => 'json', |
|||
'maxwidth' => '600', |
|||
'maxheight' => '400', |
|||
]; |
|||
$oembedurl = new \moodle_url('https://docs.com/api/oembed', $params); |
|||
$requesturl = $oembedurl->out(false); |
|||
} |
|||
return $requesturl; |
|||
} |
|||
|
|||
/** |
|||
* Return a regular expression that can be used to search text for an endpoint's schemes. |
|||
* |
|||
* @param endpoint $endpoint |
|||
* @return array Array of regular expressions matching all endpoints and schemes. |
|||
*/ |
|||
protected function endpoints_regex(endpoint $endpoint) { |
|||
return '/(https?:\/\/(www\.)?)(docs\.com)\/(.+?)\/(.+?)\/(.+?)/is'; |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
$string['pluginname'] = 'Docsdotcom'; |
@ -0,0 +1,28 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$plugin->component = 'oembedprovider_docsdotcom'; |
|||
$plugin->version = 2016070500; |
|||
$plugin->requires = 2016081700; // Requires this Moodle version. |
@ -0,0 +1,51 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author James McQuillan <james.mcquillan@remote-learner.net> |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright (C) 2016 onwards Microsoft, Inc. (http://microsoft.com/) |
|||
*/ |
|||
|
|||
namespace filter_oembed\provider; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* oEmbed provider implementation for ISSUU |
|||
*/ |
|||
class issuu extends provider { |
|||
|
|||
/** |
|||
* Constructor. |
|||
* @param $data JSON decoded array or a data object containing all provider data. |
|||
*/ |
|||
public function __construct($data = null) { |
|||
if ($data === null) { |
|||
$data = [ |
|||
'providername' => 'ISSUU', |
|||
'providerurl' => 'https://issuu.com', |
|||
'endpoints' => [ |
|||
['schemes' => ['https://issuu.com/*'], |
|||
'url' => 'https://issuu.com/oembed'], |
|||
], |
|||
]; |
|||
} |
|||
parent::__construct($data); |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
$string['pluginname'] = 'ISSUU'; |
@ -0,0 +1,28 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$plugin->component = 'oembedprovider_issuu'; |
|||
$plugin->version = 2016070500; |
|||
$plugin->requires = 2016081700; // Requires this Moodle version. |
@ -0,0 +1,24 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
$string['pluginname'] = 'Office365 video'; |
@ -0,0 +1,128 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright (C) 2016 onwards Microsoft Open Technologies, Inc. (http://msopentech.com/) |
|||
*/ |
|||
|
|||
namespace filter_oembed\provider; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* oEmbed provider implementation for Docs.com |
|||
*/ |
|||
class o365video extends provider { |
|||
|
|||
/** |
|||
* Constructor. |
|||
* @param $data JSON decoded array or a data object containing all provider data. |
|||
*/ |
|||
public function __construct($data = null) { |
|||
if ($data === null) { |
|||
$data = [ |
|||
'providername' => 'Office365 Video', |
|||
'providerurl' => '', |
|||
'endpoints' => [], |
|||
]; |
|||
} |
|||
parent::__construct($data); |
|||
} |
|||
|
|||
/** |
|||
* Main filter function. This should only be used by subplugins, and it is preferable |
|||
* to not use it even then. Ideally, a provider plugin should provide a JSON oembed provider |
|||
* response (http://oembed.com/#section2.3) and let the main filter handle the HTML. Use this |
|||
* only if the HTML must be determined by the plugin. If implemented, ensure FALSE is returned |
|||
* if no filtering occurred. |
|||
* |
|||
* @param string $text Incoming text. |
|||
* @return string Filtered text, or false for no changes. |
|||
*/ |
|||
public function filter($text) { |
|||
// PowerBI depends on 'local_o365' installed. If it isn't, return false. |
|||
if (\core_plugin_manager::instance()->get_plugin_info('local_o365') == null) { |
|||
return false; |
|||
} |
|||
|
|||
$newtext = ''; |
|||
$odburl = get_config('local_o365', 'odburl'); |
|||
if (!empty($odburl)) { |
|||
$odburl = preg_replace('/^https?:\/\//', '', $odburl); |
|||
$odburl = preg_replace('/\/.*/', '', $odburl); |
|||
$trimedurl = preg_replace("/-my/", "", $odburl); |
|||
$search = '/(https?:\/\/)('.$odburl.'|'.$trimedurl.')\/(.*)/is'; |
|||
$newtext = preg_replace_callback($search, [$this, 'get_replacement'], $text); |
|||
} |
|||
return (empty($newtext) || ($newtext == $text)) ? false : $newtext; |
|||
} |
|||
|
|||
/** |
|||
* Get the replacement oembed HTML. |
|||
* |
|||
* @param array $matched Matched URL. |
|||
* @return string The replacement text/HTML. |
|||
*/ |
|||
public function get_replacement($matched) { |
|||
|
|||
if (empty($matched[3])) { |
|||
return $matched[0]; |
|||
} |
|||
$matched[3] = preg_replace("/&/", "&", $matched[3]); |
|||
$values = array(); |
|||
parse_str($matched[3], $values); |
|||
if (empty($values['chid']) || empty($values['vid'])) { |
|||
return $matched[0]; |
|||
} |
|||
if (!\local_o365\rest\sharepoint::is_configured()) { |
|||
\local_o365\utils::debug('filter_oembed share point is not configured', 'filter_oembed_o365videocallback'); |
|||
return $matched[0]; |
|||
} |
|||
try { |
|||
$spresource = \local_o365\rest\sharepoint::get_resource(); |
|||
if (!empty($spresource)) { |
|||
$httpclient = new \local_o365\httpclient(); |
|||
$clientdata = \local_o365\oauth2\clientdata::instance_from_oidc(); |
|||
$sptoken = \local_o365\oauth2\systemtoken::instance(null, $spresource, $clientdata, $httpclient); |
|||
if (!empty($sptoken)) { |
|||
$sharepoint = new \local_o365\rest\sharepoint($sptoken, $httpclient); |
|||
// Retrieve api url for video service. |
|||
$url = $sharepoint->videoservice_discover(); |
|||
if (!empty($url)) { |
|||
$sharepoint->override_resource($url); |
|||
$width = 640; |
|||
if (!empty($values['width'])) { |
|||
$width = $values['width']; |
|||
} |
|||
$height = 360; |
|||
if (!empty($values['height'])) { |
|||
$height = $values['height']; |
|||
} |
|||
// Retrieve embed code. |
|||
return $sharepoint->get_video_embed_code($values['chid'], $values['vid'], $width, $height); |
|||
} |
|||
} |
|||
} |
|||
} catch (\Exception $e) { |
|||
\local_o365\utils::debug('filter_oembed share point execption: '.$e->getMessage(), |
|||
'filter_oembed_o365videocallback', $e); |
|||
} |
|||
return $matched[0]; |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$plugin->component = 'oembedprovider_o365video'; |
|||
$plugin->version = 2016070500; |
|||
$plugin->requires = 2016081700; // Requires this Moodle version. |
|||
$plugin->dependencies = [ |
|||
'local_o365' => 2016062003, |
|||
]; |
@ -0,0 +1,24 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
$string['pluginname'] = 'Officeforms'; |
@ -0,0 +1,108 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Aashay Zajriya<aashay@introp.net> |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright (C) 2016 onwards Microsoft Open Technologies, Inc. (http://msopentech.com/) |
|||
*/ |
|||
|
|||
namespace filter_oembed\provider; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* oEmbed provider implementation for Microsoft Forms |
|||
*/ |
|||
class officeforms extends provider { |
|||
|
|||
/** |
|||
* Constructor. |
|||
* @param $data JSON decoded array or a data object containing all provider data. |
|||
*/ |
|||
public function __construct($data = null) { |
|||
if ($data === null) { |
|||
$data = [ |
|||
'providername' => 'Office Forms', |
|||
'providerurl' => 'https://forms.office.com/', |
|||
'endpoints' => [ |
|||
['schemes' => ['https://forms.office.com/Pages/ResponsePage.aspx?id=*', |
|||
'https://www.forms.office.com/Pages/ResponsePage.aspx?id=*'], |
|||
'url' => 'https://forms.office.com/Pages/ResponsePage.aspx?id=*&embed=true', |
|||
'formats' => ['json'] |
|||
] |
|||
] |
|||
]; |
|||
} |
|||
parent::__construct($data); |
|||
} |
|||
|
|||
/** |
|||
* Get the replacement oembed HTML. |
|||
* |
|||
* @param array $matched Matched URL. |
|||
* @return string The replacement text/HTML. |
|||
*/ |
|||
public function get_replacement($matched) { |
|||
if (!empty($matched) && !empty($matched[1])) { |
|||
$url = 'https://forms.office.com/Pages/ResponsePage.aspx?id='.$matched[1].'&embed=true'; |
|||
$embedhtml = $this->getembedhtml($url); |
|||
return $embedhtml; |
|||
} |
|||
return $matched[0]; |
|||
} |
|||
|
|||
/** |
|||
* Main filter function. This should only be used by subplugins, and it is preferable |
|||
* to not use it even then. Ideally, a provider plugin should provide a JSON oembed provider |
|||
* response (http://oembed.com/#section2.3) and let the main filter handle the HTML. Use this |
|||
* only if the HTML must be determined by the plugin. If implemented, ensure FALSE is returned |
|||
* if no filtering occurred. |
|||
* |
|||
* @param string $text Incoming text. |
|||
* @return string Filtered text, or false for no changes. |
|||
*/ |
|||
public function filter($text) { |
|||
$search = '/(?:https?:\/\/(?:www\.)?)(?:forms\.office\.com)\/(?:.+?)\/(?:DesignPage\.aspx)#FormId=(.+)/is'; |
|||
$newtext = preg_replace_callback($search, [$this, 'get_replacement'], $text); |
|||
return (empty($newtext) || ($newtext == $text)) ? false : $newtext; |
|||
} |
|||
|
|||
/** |
|||
* Return the HTML content to be embedded. |
|||
* |
|||
* @param string $embedurl Additional parameters to include in the embed URL. |
|||
* @return string The HTML content to be embedded in the page. |
|||
*/ |
|||
private function getembedhtml($embedurl) { |
|||
$iframeattrs = [ |
|||
'src' => $embedurl, |
|||
'height' => '768px', |
|||
'width' => '99%', |
|||
'frameborder' => '0', |
|||
'marginwidth' => '0', |
|||
'marginheight' => '0', |
|||
'style' => 'border: none; max-width: 100%; max-height: 100vh', |
|||
'allowfullscreen' => 'true', |
|||
'webkitallowfullscreen' => 'true', |
|||
'mozallowfullscreen' => 'true', |
|||
'msallowfullscreen' => 'true', |
|||
]; |
|||
return \html_writer::tag('iframe', ' ', $iframeattrs); |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$plugin->component = 'oembedprovider_officeforms'; |
|||
$plugin->version = 2016070500; |
|||
$plugin->requires = 2016081700; // Requires this Moodle version. |
@ -0,0 +1,24 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
$string['pluginname'] = 'Poll Everywhere'; |
@ -0,0 +1,55 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author James McQuillan <james.mcquillan@remote-learner.net> |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright (C) 2016 onwards Microsoft, Inc. (http://microsoft.com/) |
|||
*/ |
|||
|
|||
namespace filter_oembed\provider; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* oEmbed provider implementation for Poll Everywhere |
|||
*/ |
|||
class pollev extends provider { |
|||
|
|||
/** |
|||
* Constructor. |
|||
* @param $data JSON decoded array or a data object containing all provider data. |
|||
*/ |
|||
public function __construct($data = null) { |
|||
if ($data === null) { |
|||
$data = [ |
|||
'providername' => 'Poll Everywhere', |
|||
'providerurl' => 'https://www.polleverywhere.com', |
|||
'endpoints' => [ |
|||
['schemes' => [ |
|||
'https://www.polleverywhere.com/polls/*', |
|||
'https://www.polleverywhere.com/multiple_choice_polls/*', |
|||
'https://www.polleverywhere.com/free_text_polls/*', |
|||
], |
|||
'url' => 'https://www.polleverywhere.com/services/oembed'], |
|||
], |
|||
]; |
|||
} |
|||
parent::__construct($data); |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$plugin->component = 'oembedprovider_pollev'; |
|||
$plugin->version = 2016070500; |
|||
$plugin->requires = 2016081700; // Requires this Moodle version. |
@ -0,0 +1,24 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
$string['pluginname'] = 'Power BI'; |
@ -0,0 +1,111 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Sushant Gawali <sushant@introp.net> |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright (C) 2016 onwards Microsoft Open Technologies, Inc. (http://msopentech.com/) |
|||
*/ |
|||
|
|||
namespace filter_oembed\provider; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* oEmbed provider implementation for Docs.com |
|||
*/ |
|||
class powerbi extends provider { |
|||
|
|||
/** |
|||
* Constructor. |
|||
* @param $data JSON decoded array or a data object containing all provider data. |
|||
*/ |
|||
public function __construct($data = null) { |
|||
if ($data === null) { |
|||
$data = [ |
|||
'providername' => 'Power BI', |
|||
'providerurl' => '', |
|||
'endpoints' => [ |
|||
['schemes' => ['https://powerbi.com/*/*/*/*/*', |
|||
'https://app.powerbi.com/*/*/*/*/*'], |
|||
'url' => '', |
|||
'formats' => ['json'] |
|||
] |
|||
] |
|||
]; |
|||
} |
|||
parent::__construct($data); |
|||
} |
|||
|
|||
/** |
|||
* Main filter function. This should only be used by subplugins, and it is preferable |
|||
* to not use it even then. Ideally, a provider plugin should provide a JSON oembed provider |
|||
* response (http://oembed.com/#section2.3) and let the main filter handle the HTML. Use this |
|||
* only if the HTML must be determined by the plugin. If implemented, ensure FALSE is returned |
|||
* if no filtering occurred. |
|||
* |
|||
* @param string $text Incoming text. |
|||
* @return string Filtered text, or false for no changes. |
|||
*/ |
|||
public function filter($text) { |
|||
// PowerBI depends on 'local_o365' installed. If it isn't, return false. |
|||
if (\core_plugin_manager::instance()->get_plugin_info('local_o365') == null) { |
|||
return false; |
|||
} |
|||
|
|||
$search = '/(https?:\/\/(app\.)?)(powerbi\.com)\/(.+?)\/(.+?)\/(.+?)\/(.+?)\/(.+?)/is'; |
|||
$newtext = preg_replace_callback($search, [$this, 'get_replacement'], $text); |
|||
return (empty($newtext) || ($newtext == $text)) ? false : $newtext; |
|||
} |
|||
|
|||
/** |
|||
* Get the replacement oembed HTML. |
|||
* |
|||
* @param array $matched Matched URL. |
|||
* @return string The replacement text/HTML. |
|||
*/ |
|||
public function get_replacement($matched) { |
|||
global $CFG; |
|||
require_once($CFG->dirroot . '/filter/oembed/provider/powerbi/rest/powerbi.php'); |
|||
|
|||
$httpclient = new \local_o365\httpclient(); |
|||
try { |
|||
$clientdata = \local_o365\oauth2\clientdata::instance_from_oidc(); |
|||
$resource = \filter_oembed\provider\powerbi\rest\powerbi::get_resource(); |
|||
$token = \local_o365\oauth2\systemtoken::instance(null, $resource, $clientdata, $httpclient); |
|||
if (!empty($token)) { |
|||
$powerbi = new \filter_oembed\provider\powerbi\rest\powerbi($token, $httpclient); |
|||
if ($matched[6] == 'reports') { |
|||
$reportsdata = $powerbi->apicall('get', 'reports'); |
|||
$embedurl = $powerbi->getreportoembedurl($matched[7], $reportsdata); |
|||
$embedhtml = $this->getembedhtml($embedurl); |
|||
$embedhtml .= '<input type="hidden" class="token" value="' . $token->get_token(). '">'; |
|||
return $embedhtml; |
|||
} |
|||
} |
|||
} catch (\Exception $e) { |
|||
\local_o365\utils::debug('filter_oembed oauth2 exeception: '.$e->getMessage(), 'filter_oembed_powerbicallback', $e); |
|||
} |
|||
return $matched[0]; |
|||
} |
|||
|
|||
private function getembedhtml($embedurl) { |
|||
return '<iframe class="powerbi_iframe" src="'. $embedurl . '" ' |
|||
. 'height="768px" width="99%" frameborder="0" seamless></iframe>'; |
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Sushant Gawali <sushant@introp.net> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright (C) 2014 onwards Microsoft Open Technologies, Inc. (http://msopentech.com/) |
|||
*/ |
|||
|
|||
namespace filter_oembed\provider\powerbi\rest; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* API client for Power BI. |
|||
*/ |
|||
class powerbi extends \local_o365\rest\o365api { |
|||
/** |
|||
* Get the base URI that API calls should be sent to. |
|||
* |
|||
* @return string|bool The URI to send API calls to, or false if a precondition failed. |
|||
*/ |
|||
public function get_apiuri() { |
|||
return "https://api.powerbi.com/beta/myorg/"; |
|||
} |
|||
/** |
|||
* Get the API client's oauth2 resource. |
|||
* |
|||
* @return string The resource for oauth2 tokens. |
|||
*/ |
|||
public static function get_resource() { |
|||
return 'https://analysis.windows.net/powerbi/api'; |
|||
} |
|||
public function getreportoembedurl($reportid, $reportsdata) { |
|||
$reportsdata = $this->process_apicall_response($reportsdata); |
|||
foreach ($reportsdata['value'] as $report) { |
|||
if ($report['id'] == $reportid) { |
|||
return $report['embedUrl']; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$plugin->component = 'oembedprovider_powerbi'; |
|||
$plugin->version = 2016070500; |
|||
$plugin->requires = 2016081700; // Requires this Moodle version. |
|||
$plugin->dependencies = [ |
|||
'local_o365' => 2016062003, |
|||
]; |
@ -0,0 +1,39 @@ |
|||
YUI.add('moodle-filter_oembed-powerbiloader', function (Y) { |
|||
var ModulenameNAME = 'powerbiloader'; |
|||
var token = ''; |
|||
var MODULENAME = function () { |
|||
MODULENAME.superclass.constructor.apply(this, arguments); |
|||
}; |
|||
Y.extend(MODULENAME, Y.Base, { |
|||
initializer: function (config) { |
|||
if (document.getElementsByClassName('token').length > 0) |
|||
{ |
|||
token = document.getElementsByClassName('token')[0].value; |
|||
var iframes = document.getElementsByClassName('powerbi_iframe'); |
|||
for (var i = 0; i < iframes.length; i++) { |
|||
iframes[i].onload = postActionLoadReport; |
|||
} |
|||
} |
|||
} |
|||
}, { |
|||
NAME: ModulenameNAME, |
|||
ATTRS: { |
|||
aparam: {} |
|||
} |
|||
}); |
|||
M.filter_oembed = M.filter_oembed || {}; |
|||
|
|||
M.filter_oembed.init_powerbiloader = function (config) { |
|||
return new MODULENAME(config); |
|||
}; |
|||
|
|||
// Post the auth token to the iFrame.
|
|||
postActionLoadReport = function () { |
|||
var m = {action: "loadReport", accessToken: token}; |
|||
message = JSON.stringify(m); |
|||
// Push the message.
|
|||
this.contentWindow.postMessage(message, "*"); |
|||
}; |
|||
}, '@VERSION@', { |
|||
requires: ['base'] |
|||
}); |
File diff suppressed because it is too large
@ -0,0 +1,100 @@ |
|||
.filter_oembed_docsdotcom { |
|||
iframe { |
|||
width: 100%; |
|||
height: 400px; |
|||
} |
|||
} |
|||
|
|||
.oembed-card { |
|||
position: relative; |
|||
min-height: 10em; |
|||
background-size: cover; |
|||
transition: all 0.4s ease-in-out; |
|||
} |
|||
|
|||
.oembed-card-title { |
|||
position: absolute; |
|||
top: 0; |
|||
color: #fff; |
|||
background-color: rgba(0, 0, 0, 0.8); |
|||
padding: 0.5em 0.5em; |
|||
} |
|||
|
|||
.oembed-content { |
|||
> *:first-child { |
|||
width: 100%; |
|||
} |
|||
video { |
|||
// Responsive video for HTML5 only |
|||
height: auto; |
|||
} |
|||
} |
|||
|
|||
.btn.btn-link.oembed-card-play { |
|||
background-image: url([[pix:filter_oembed|play]]); |
|||
background-repeat: no-repeat; |
|||
position: absolute; |
|||
width: 15%; |
|||
// Center play button 50% - width / 2; |
|||
top: 42.5%; |
|||
left: 42.5%; |
|||
padding-top: 15%; |
|||
margin: 0; |
|||
background-position: 0; |
|||
opacity: 0.9; |
|||
transition: all 0.4s ease-in-out; |
|||
filter: drop-shadow(1px 1px 1px #666); |
|||
} |
|||
|
|||
.btn.btn-link.oembed-card-play:hover { |
|||
background-position: 0; |
|||
filter: drop-shadow(0 0 0 #666); |
|||
opacity: 1; |
|||
} |
|||
|
|||
.oembed-responsive { |
|||
width: 100%; |
|||
display: block; |
|||
position: relative; |
|||
> *:not(video):first-child { |
|||
position: absolute !important; |
|||
top: 0 !important; |
|||
bottom: 0 !important; |
|||
right: 0 !important; |
|||
left: 0 !important; |
|||
height: 100% !important; |
|||
width: 100% !important; |
|||
} |
|||
} |
|||
|
|||
.oembed-responsive-pad { |
|||
display: block; |
|||
} |
|||
|
|||
.oembed-provider-details { |
|||
font-size: 0.9em; |
|||
margin-top: 1em; |
|||
display: none; |
|||
} |
|||
|
|||
tr.oembed-provider-editing { |
|||
.oembed-provider-details { |
|||
display: block; |
|||
} |
|||
.oembed-provider-actions { |
|||
display: none; |
|||
} |
|||
} |
|||
|
|||
.oembed-provider-actions { |
|||
float: right; |
|||
margin-right: 1em; |
|||
} |
|||
|
|||
#oembedproviders td.provider div.alert { |
|||
margin-top: 1em; |
|||
} |
|||
|
|||
.oembed-providersource { |
|||
font-size: 90%; |
|||
} |
@ -0,0 +1,63 @@ |
|||
<?php |
|||
// This file is part of Moodle-oembed-Filter |
|||
// |
|||
// Moodle-oembed-Filter is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle-oembed-Filter is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle-oembed-Filter. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Filter for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filter |
|||
* oEmbed filter ( Mike Churchward, James McQuillan, Vinayak (Vin) Bhalerao, Josh Gavant and Rob Dolin) |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die; |
|||
|
|||
require_once(__DIR__.'/filter.php'); |
|||
require_once($CFG->libdir.'/formslib.php'); |
|||
|
|||
use filter_oembed\service\oembed; |
|||
|
|||
$ADMIN->add('filtersettings', new admin_category('filteroembedfolder', get_string('filtername', 'filter_oembed'))); |
|||
$settings = new admin_settingpage($section, get_string('settings')); |
|||
|
|||
if ($ADMIN->fulltree) { |
|||
$targettags = [ |
|||
'a' => get_string('atag', 'filter_oembed'), |
|||
'div' => get_string('divtag', 'filter_oembed') |
|||
]; |
|||
|
|||
$config = get_config('filter_oembed'); |
|||
|
|||
$item = new admin_setting_configselect( |
|||
'filter_oembed/targettag', |
|||
get_string('targettag', 'filter_oembed'), |
|||
get_string('targettag_desc', 'filter_oembed'), |
|||
'atag', |
|||
['atag' => 'atag', 'divtag' => 'divtag'] |
|||
); |
|||
$settings->add($item); |
|||
|
|||
$item = new admin_setting_configcheckbox('filter_oembed/lazyload', new lang_string('lazyload', 'filter_oembed'), '', 1); |
|||
$settings->add($item); |
|||
} |
|||
|
|||
$ADMIN->add('filteroembedfolder', $settings); |
|||
|
|||
$ADMIN->add('filteroembedfolder', new admin_externalpage('filter_oembed_providers', |
|||
get_string('manageproviders', 'filter_oembed'), new moodle_url('/filter/oembed/manageproviders.php'))); |
|||
|
|||
$settings = null; |
@ -0,0 +1,100 @@ |
|||
.filter_oembed_docsdotcom iframe { |
|||
width: 100%; |
|||
height: 400px; |
|||
} |
|||
|
|||
.oembed-card { |
|||
position: relative; |
|||
min-height: 10em; |
|||
-webkit-background-size: cover; |
|||
background-size: cover; |
|||
-webkit-transition: all 0.4s ease-in-out; |
|||
transition: all 0.4s ease-in-out; |
|||
} |
|||
|
|||
.oembed-card-title { |
|||
position: absolute; |
|||
top: 0; |
|||
color: #fff; |
|||
background-color: rgba(0, 0, 0, 0.8); |
|||
padding: 0.5em 0.5em; |
|||
} |
|||
|
|||
.oembed-content > *:first-child { |
|||
width: 100%; |
|||
} |
|||
|
|||
.oembed-content video { |
|||
height: auto; |
|||
} |
|||
|
|||
.btn.btn-link.oembed-card-play { |
|||
background-image: url([[pix:filter_oembed|play]]); |
|||
background-repeat: no-repeat; |
|||
position: absolute; |
|||
width: 15%; |
|||
top: 42.5%; |
|||
left: 42.5%; |
|||
padding-top: 15%; |
|||
margin: 0; |
|||
background-position: 0; |
|||
opacity: 0.9; |
|||
-webkit-transition: all 0.4s ease-in-out; |
|||
transition: all 0.4s ease-in-out; |
|||
-webkit-filter: drop-shadow(1px 1px 1px #666); |
|||
filter: drop-shadow(1px 1px 1px #666); |
|||
} |
|||
|
|||
.btn.btn-link.oembed-card-play:hover { |
|||
background-position: 0; |
|||
-webkit-filter: drop-shadow(0 0 0 #666); |
|||
filter: drop-shadow(0 0 0 #666); |
|||
opacity: 1; |
|||
} |
|||
|
|||
.oembed-responsive { |
|||
width: 100%; |
|||
display: block; |
|||
position: relative; |
|||
} |
|||
|
|||
.oembed-responsive > *:not(video):first-child { |
|||
position: absolute !important; |
|||
top: 0 !important; |
|||
bottom: 0 !important; |
|||
right: 0 !important; |
|||
left: 0 !important; |
|||
height: 100% !important; |
|||
width: 100% !important; |
|||
} |
|||
|
|||
.oembed-responsive-pad { |
|||
display: block; |
|||
} |
|||
|
|||
.oembed-provider-details { |
|||
font-size: 0.9em; |
|||
margin-top: 1em; |
|||
display: none; |
|||
} |
|||
|
|||
tr.oembed-provider-editing .oembed-provider-details { |
|||
display: block; |
|||
} |
|||
|
|||
tr.oembed-provider-editing .oembed-provider-actions { |
|||
display: none; |
|||
} |
|||
|
|||
.oembed-provider-actions { |
|||
float: right; |
|||
margin-right: 1em; |
|||
} |
|||
|
|||
#oembedproviders td.provider div.alert { |
|||
margin-top: 1em; |
|||
} |
|||
|
|||
.oembed-providersource { |
|||
font-size: 90%; |
|||
} |
@ -0,0 +1,84 @@ |
|||
{{! |
|||
This file is part of Moodle - http://moodle.org/ |
|||
|
|||
Moodle is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
Moodle is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
}} |
|||
{{! |
|||
@template filter_oembed/managementpage |
|||
|
|||
Template which defines an oembed filter management page. |
|||
|
|||
Classes required for JS: |
|||
* none |
|||
|
|||
Data attributes required for JS: |
|||
* none |
|||
|
|||
Context variables required for this template: |
|||
* headings - array: An array of table headings. |
|||
* rows - array: An array of content rows for the table. |
|||
|
|||
Example context (json): |
|||
{ |
|||
"rows": [ |
|||
{ |
|||
"pid": "1", |
|||
"providername": "23HQ", |
|||
"providerurl": "http://www.23hq.com/", |
|||
"enableaction": "http://localhost/moodlehq.git/filter/oembed/manageproviders.php?action=disable&pid=1&sesskey=dvBXP9rX1G", |
|||
"editaction": "http://localhost/moodlehq.git/filter/oembed/manageproviders.php?action=edit&pid=1&sesskey=dvBXP9rX1G", |
|||
"deleteaction": "http://localhost/moodlehq.git/filter/oembed/manageproviders.php?action=delete&pid=1&sesskey=dvBXP9rX1G", |
|||
"extraclass": "dimmed_text" |
|||
} |
|||
] |
|||
} |
|||
}} |
|||
{{#x}} |
|||
Displayed if x was true. |
|||
{{/x}} |
|||
<div id="providermanagement"> |
|||
<table id="oembedproviders" class="flexible generaltable generalbox" style="border-spacing: 0px;"> |
|||
<thead> |
|||
<tr> |
|||
<th class="header c0 provider" scope="col"><input class="search" placeholder="{{#str}}provider, filter_oembed{{/str}}" /></th> |
|||
</tr> |
|||
</thead> |
|||
<tbody class="list"> |
|||
<tr id="oembed-local-providers-head-row" class="oembed-local-providers"> |
|||
<th id="oembed-local-providers-head"> |
|||
{{#str}}localproviders, filter_oembed{{/str}} |
|||
</th> |
|||
</tr> |
|||
{{#localrows}} |
|||
{{> filter_oembed/managementpagerow}} |
|||
{{/localrows}} |
|||
<tr id="oembed-plugin-providers-head-row" class="oembed-plugin-providers"> |
|||
<th id="oembed-plugin-providers-head"> |
|||
{{#str}}pluginproviders, filter_oembed{{/str}} |
|||
</th> |
|||
</tr> |
|||
{{#pluginrows}} |
|||
{{> filter_oembed/managementpagerow}} |
|||
{{/pluginrows}} |
|||
<tr id="oembed-download-providers-head-row" class="oembed-download-providers"> |
|||
<th id="oembed-download-providers-head"> |
|||
{{#str}}downloadproviders, filter_oembed{{/str}} |
|||
</th> |
|||
</tr> |
|||
{{#downloadrows}} |
|||
{{> filter_oembed/managementpagerow}} |
|||
{{/downloadrows}} |
|||
</tbody> |
|||
</table> |
|||
</div> |
@ -0,0 +1,45 @@ |
|||
{{! |
|||
This file is part of Moodle - http://moodle.org/ |
|||
|
|||
Moodle is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
Moodle is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
}} |
|||
{{! |
|||
@template filter_oembed/managementpagerow |
|||
|
|||
oembed managementpagerow template. |
|||
|
|||
Renders a single oembed managementpagerow. See template filter_oembed/managementpage for details. |
|||
|
|||
Example context (json): |
|||
{ |
|||
"pid": "72", |
|||
"extraclass": "testclass", |
|||
"editing": "1", |
|||
"providerurl": "https://theprovider.com/", |
|||
"providername": "The Provider", |
|||
"enableaction": "http://enableaction.com/", |
|||
"editaction": "http://editaction.com/", |
|||
"deleteaction": "http://deleteaction.com/" |
|||
} |
|||
}} |
|||
<tr id="oembed-display-providers_{{pid}}" class="{{extraclass}}{{#editing}} oembed-provider-editing{{/editing}}" data-pid="{{pid}}"> |
|||
<td id="oembed-display-providers_{{pid}}_c0" class="cell c0 provider"> |
|||
<a href="{{providerurl}}" target="_blank" class="list-providername">{{providername}}</a> |
|||
<div class="oembed-provider-details"> |
|||
</div> |
|||
<div class="oembed-provider-actions"> |
|||
{{{enableaction}}} {{{editaction}}} {{{deleteaction}}} |
|||
</div> |
|||
</td> |
|||
</tr> |
@ -0,0 +1,38 @@ |
|||
{{! |
|||
This file is part of Moodle - http://moodle.org/ |
|||
|
|||
Moodle is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
Moodle is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
}} |
|||
{{! |
|||
@package filter_oembed |
|||
@copyright Stuart Lamour / Guy Thomas 2016 |
|||
@license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
}} |
|||
{{! |
|||
@template filter_oembed/preload |
|||
Example context (json): |
|||
{ |
|||
"aspectratio": "1", |
|||
"embedhtml": "<div>embed html</div>", |
|||
"jshtml": "data-aspect-ratio=10", |
|||
"title": "Card title" |
|||
} |
|||
}} |
|||
<div class="oembed-card-container{{#aspectratio}} oembed-responsive{{/aspectratio}}"> |
|||
<div class="oembed-card{{#aspectratio}} oembed-processed{{/aspectratio}}" style="background-image:url({{thumbnail_url}});" data-embed="{{embedhtml}}" {{#jshtml}}{{{jshtml}}}{{/jshtml}} > |
|||
<div class="oembed-card-title">{{title}}</div> |
|||
<button class="btn btn-link oembed-card-play" aria-label="{{#str}}playoembed, filter_oembed{{/str}}"></button> |
|||
</div> |
|||
{{#aspectratio}}<div class="oembed-responsive-pad" style="padding-top:{{aspectratio}}%"></div>{{/aspectratio}} |
|||
</div> |
@ -0,0 +1,163 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Oembed filter custom behat steps. |
|||
* @author Guy Thomas <gthomas@moodlerooms.com> |
|||
* @copyright Copyright (c) 2016 Blackboard Inc. |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
use Behat\Gherkin\Node\TableNode; |
|||
|
|||
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); |
|||
|
|||
class behat_filter_oembed extends behat_base { |
|||
|
|||
/** |
|||
* Get provider action xpath for specific provider and action. |
|||
* @param string $provider |
|||
* @param string $actionclass |
|||
* @return string |
|||
*/ |
|||
protected function provider_action_xpath($provider, $actionclass) { |
|||
$xpath = '//td/a[text()=\'' . $provider.'\']'; |
|||
$xpath .= '/parent::td/div/a[contains(@class,\''.$actionclass.'\')]'; |
|||
return $xpath; |
|||
} |
|||
|
|||
/** |
|||
* Provider action. |
|||
* @param string $provider |
|||
* @param string $actionclass |
|||
* @throws \Behat\Mink\Exception\ExpectationException |
|||
*/ |
|||
protected function provider_action($provider, $actionclass) { |
|||
$xpath = $this->provider_action_xpath($provider, $actionclass); |
|||
$node = $this->find('xpath', $xpath); |
|||
$this->ensure_node_is_visible($node); |
|||
$node->click(); |
|||
} |
|||
|
|||
/** |
|||
* Toggle provider enable status. |
|||
* @Given /^I toggle the provider "(?P<provider_string>[^"]*)"$/ |
|||
* @param string $provider |
|||
*/ |
|||
public function i_toggle_provider($provider) { |
|||
$this->provider_action($provider, 'filter-oembed-visibility'); |
|||
} |
|||
|
|||
/** |
|||
* Click edit action for provider. |
|||
* @Given /^I edit the provider "(?P<provider_string>[^"]*)"$/ |
|||
* @param string $provider |
|||
*/ |
|||
public function i_edit_provider($provider) { |
|||
$this->provider_action($provider, 'filter-oembed-edit'); |
|||
} |
|||
|
|||
/** |
|||
* Ensure provider status is enabled or disabled. |
|||
* @param string $provider |
|||
* @param bool $enabled |
|||
*/ |
|||
protected function ensure_provider_status($provider, $enabled = true) { |
|||
$action = $enabled ? 'disable' : 'enable'; |
|||
$xpath = $this->provider_action_xpath($provider, 'filter-oembed-visibility'); |
|||
$xpath = substr($xpath, 0, -1) . 'and contains(@href,"action='.$action.'")]'; |
|||
$this->ensure_element_exists($xpath, 'xpath_element'); |
|||
} |
|||
|
|||
/** |
|||
* @Given /^the provider "(?P<provider_string>[^"]*)" is disabled$/ |
|||
* @param string $provider |
|||
* @throws \Behat\Mink\Exception\ExpectationException |
|||
*/ |
|||
public function the_provider_is_disabled($provider) { |
|||
$this->ensure_provider_status($provider, false); |
|||
} |
|||
|
|||
/** |
|||
* @Given /^the provider "(?P<provider_string>[^"]*)" is enabled$/ |
|||
* @param string $provider |
|||
* @throws \Behat\Mink\Exception\ExpectationException |
|||
*/ |
|||
public function the_provider_is_enabled($provider) { |
|||
$this->ensure_provider_status($provider, true); |
|||
} |
|||
|
|||
/** |
|||
* @Given /^I filter the provider list to "(?P<provider_string>[^"]*)"$/ |
|||
* @param $provider |
|||
* @throws \Behat\Mink\Exception\ExpectationException |
|||
*/ |
|||
public function i_filter_provider_list($provider) { |
|||
$fieldxpath = '//input[@placeholder="Provider"]'; |
|||
$fieldnode = $this->find('xpath', $fieldxpath); |
|||
$field = behat_field_manager::get_form_field($fieldnode, $this->getSession()); |
|||
$field->set_value($provider); |
|||
} |
|||
|
|||
/** |
|||
* Xpath for provider edit form. |
|||
* @param string $provider |
|||
* @return string |
|||
*/ |
|||
protected function edit_form_xpath($provider) { |
|||
$xpath = '//td/a[text()=\'' . $provider.'\']'; |
|||
$xpath .= '/parent::td/div[contains(@class,\'oembed-provider-details\')]/form'; |
|||
return $xpath; |
|||
} |
|||
|
|||
/** |
|||
* Wait for edit form to be visible. |
|||
* @param string $provider |
|||
*/ |
|||
protected function wait_for_edit_form($provider) { |
|||
$xpath = $this->edit_form_xpath($provider); |
|||
$this->ensure_element_is_visible($xpath, 'xpath_element'); |
|||
} |
|||
|
|||
/** |
|||
* @Given /^I edit the provider "(?P<provider_string>[^"]*)" with the values:$/ |
|||
* @param string $provider |
|||
* @param TableNode $table |
|||
*/ |
|||
public function i_edit_provider_with_values($provider, TableNode $table) { |
|||
$this->i_edit_provider($provider); |
|||
|
|||
if (!$data = $table->getRowsHash()) { |
|||
return; |
|||
} |
|||
|
|||
/** @var behat_forms $formhelper */ |
|||
$formhelper = behat_context_helper::get('behat_forms'); |
|||
|
|||
// Field setting code taken from behat_admin.php. |
|||
foreach ($data as $label => $value) { |
|||
|
|||
$fieldxpath = $this->edit_form_xpath($provider); |
|||
$fieldxpath .= '//label[contains(text(),\''.$label.'\')]'; |
|||
$fieldxpath .= '/parent::div/parent::div/div[contains(@class, \'felement\')]/*'; |
|||
|
|||
$formhelper->i_set_the_field_with_xpath_to($fieldxpath, $value); |
|||
|
|||
$this->find_button(get_string('saveasnew', 'filter_oembed'))->press(); |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,45 @@ |
|||
# This file is part of Moodle - http://moodle.org/ |
|||
# |
|||
# Moodle is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation, either version 3 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# Moodle is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
# Tests for visibility of admin block by user type and page. |
|||
# |
|||
# @package filter_oembed |
|||
# @copyright 2016 Guy Thomas <gthomas@moodlerooms.com> |
|||
# @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
|
|||
@filter @filter_oembed |
|||
Feature: Admin can use the provider management page to view / edit / enable / disable providers. |
|||
|
|||
@javascript |
|||
Scenario: Admin user carries out various provider management tasks. |
|||
#This is Done as one scenario for performance. |
|||
Given I log in as "admin" |
|||
When I navigate to "Plugins > Filters > Oembed Filter > Manage providers" in site administration |
|||
Then "#providermanagement" "css_element" should exist |
|||
# Test filtering list. |
|||
And I should see "YouTube" in the "oembedproviders" "table" |
|||
When I filter the provider list to "Vimeo" |
|||
Then I should not see "YouTube" in the "oembedproviders" "table" |
|||
And I should see "Vimeo" in the "oembedproviders" "table" |
|||
And the provider "Vimeo" is disabled |
|||
# Test enable / disable |
|||
When I toggle the provider "Vimeo" |
|||
Then the provider "Vimeo" is enabled |
|||
When I toggle the provider "Vimeo" |
|||
Then the provider "Vimeo" is disabled |
|||
# Test edit |
|||
When I edit the provider "Vimeo" with the values: |
|||
| Provider Name | Zimeo | |
|||
Then I should see "Created new local provider definition for \"Zimeo\"." in the "oembedproviders" "table" |
@ -0,0 +1,152 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Unit tests for the filter_oembed. |
|||
* |
|||
* @package filter_oembed |
|||
* @author Sushant Gawali (sushant@introp.net) |
|||
* @author Erich M. Wappis <erich.wappis@uni-graz.at> |
|||
* @author Guy Thomas <brudinie@googlemail.com> |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright Microsoft, Inc. |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
global $CFG; |
|||
require_once($CFG->dirroot . '/filter/oembed/filter.php'); |
|||
|
|||
/** |
|||
* @group filter_oembed |
|||
*/ |
|||
class filter_oembed_testcase extends advanced_testcase { |
|||
|
|||
protected $filter; |
|||
|
|||
/** |
|||
* Sets up the test cases. |
|||
*/ |
|||
protected function setUp() { |
|||
parent::setUp(); |
|||
$this->filter = new filter_oembed(context_system::instance(), array()); |
|||
// Ensure all tested providers are enabled. |
|||
$oembed = \filter_oembed\service\oembed::get_instance('all'); |
|||
foreach ($oembed->providers as $pid => $provider) { |
|||
switch ($provider->providername) { |
|||
|
|||
case 'YouTube': |
|||
$oembed->enable_provider($pid); |
|||
break; |
|||
|
|||
case 'SoundCloud': |
|||
$oembed->enable_provider($pid); |
|||
break; |
|||
|
|||
case 'Office Mix': |
|||
$oembed->enable_provider($pid); |
|||
break; |
|||
|
|||
case 'Vimeo': |
|||
$oembed->enable_provider($pid); |
|||
break; |
|||
|
|||
case 'Ted': |
|||
$oembed->enable_provider($pid); |
|||
break; |
|||
|
|||
case 'Poll Everywhere': |
|||
$oembed->enable_provider($pid); |
|||
break; |
|||
|
|||
case 'SlideShare': |
|||
$oembed->enable_provider($pid); |
|||
break; |
|||
|
|||
case 'ISSUU': |
|||
$oembed->enable_provider($pid); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Performs unit tests for all services supported by the filter. |
|||
* |
|||
* Need to update this test to not contact external services. |
|||
*/ |
|||
public function test_filter() { |
|||
$this->resetAfterTest(true); |
|||
|
|||
$curl = new curl(); |
|||
try { |
|||
$out = $curl->get('https://www.youtube.com'); |
|||
} catch (Exception $e) { |
|||
$out = ''; |
|||
} |
|||
|
|||
$cancontactyoutube = stripos(trim($out), '<!DOCTYPE html') !== false; |
|||
|
|||
// Make sure that we have access to the internet. |
|||
if (!$cancontactyoutube) { |
|||
$this->markTestSkipped( |
|||
'Unable to reach youtube' |
|||
); |
|||
} |
|||
|
|||
set_config('lazyload', 0, 'filter_oembed'); |
|||
|
|||
$soundcloudlink = '<p><a href="https://soundcloud.com/forss/flickermood">soundcloud</a></p>'; |
|||
$youtubelink = '<p><a href="https://www.youtube.com/watch?v=ns6gCZI-Nj8">Youtube</a></p>'; |
|||
$vimeolink = '<p><a href="http://vimeo.com/115538038">vimeo</a></p>'; |
|||
$tedlink = '<p><a href="https://ted.com/talks/aj_jacobs_how_healthy_living_nearly_killed_me">Ted</a></p>'; |
|||
$slidesharelink = '<p><a href="https://www.slideshare.net/timbrown/ideo-values-slideshare1">slideshare</a></p>'; |
|||
$issuulink = '<p><a href="https://issuu.com/thinkuni/docs/think_issue12">issuu</a></p>'; |
|||
$polleverywherelink = '<p><a href="https://www.polleverywhere.com/multiple_choice_polls/AyCp2jkJ2HqYKXc/web">'; |
|||
$polleverywherelink .= '$popolleverywhere</a></p>'; |
|||
|
|||
$filterinput = $soundcloudlink.$youtubelink.$vimeolink.$tedlink.$slidesharelink.$issuulink.$polleverywherelink; |
|||
|
|||
$filteroutput = $this->filter->filter($filterinput); |
|||
|
|||
$youtubeoutput = '/.*<iframe .*src="https:\/\/www\.youtube\.com\/embed\/ns6gCZI-Nj8\?feature=oembed.*"/'; |
|||
$this->assertRegExp($youtubeoutput, $filteroutput, 'Youtube filter fails'); |
|||
|
|||
$soundcloudoutput = '/.*<iframe .*src="https:\/\/w\.soundcloud\.com\/player\/'. |
|||
'\?visual=true&url=https%3A%2F%2Fapi\.soundcloud\.com'. |
|||
'%2Ftracks%2F293&show_artwork=true".*/'; |
|||
$this->assertRegExp($soundcloudoutput, $filteroutput, 'Soundcloud filter fails'); |
|||
|
|||
$vimeooutput = '/.*<iframe .*src="https:\/\/player\.vimeo\.com\/video\/115538038\?.*".*/'; |
|||
$this->assertRegExp($vimeooutput, $filteroutput, 'Vimeo filter fails'); |
|||
|
|||
$tedoutput = '/.*<a href="https:\/\/ted\.com\/talks\/aj_jacobs_how_healthy_living_nearly_killed_me".*/'; |
|||
$this->assertRegExp($tedoutput, $filteroutput, 'Ted filter fails'); |
|||
|
|||
$polleverywhereoutput = '/.*<script src="https:\/\/www\.polleverywhere\.com\/'. |
|||
'multiple_choice_polls\/AyCp2jkJ2HqYKXc\/web\.js'. |
|||
'\?results_count_format=percent"><\/script>.*/'; |
|||
$this->assertRegExp($polleverywhereoutput, $filteroutput, 'Poll everywhare filter fails'); |
|||
|
|||
$slideshareoutput = '/.*<iframe .*src="https:\/\/www\.slideshare\.net\/slideshow\/embed_code\/key\/ywBrCQRAE5DZrD".*/'; |
|||
$this->assertRegExp($slideshareoutput, $filteroutput, 'Slideshare filter fails'); |
|||
|
|||
$issuuoutput = '/.*<div data-url="https:\/\/issuu\.com\/thinkuni\/docs\/think_issue12" .*'; |
|||
$issuuoutput .= 'class="issuuembed"><\/div>.*/'; |
|||
$this->assertRegExp($issuuoutput, $filteroutput, 'Issuu filter fails'); |
|||
} |
|||
} |
@ -0,0 +1,242 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Unit tests for the filter_oembed. |
|||
* |
|||
* @package filter_oembed |
|||
* @author Mike Churchward <mike.churchward@poetgroup.org> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* @copyright 2016 The POET Group |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
global $CFG; |
|||
require_once($CFG->dirroot . '/filter/oembed/tests/testable_oembed.php'); |
|||
|
|||
/** |
|||
* @group filter_oembed |
|||
*/ |
|||
class filter_oembed_service_testcase extends advanced_testcase { |
|||
|
|||
/** |
|||
* Make sure providers array is correct. |
|||
* @param array $providers |
|||
*/ |
|||
public function assert_providers_ok($providers) { |
|||
$this->assertNotEmpty($providers); |
|||
$provider = reset($providers); |
|||
if (is_object($provider)) { |
|||
// Test the provider object. |
|||
$this->assertNotEmpty($provider->providername); |
|||
$this->assertNotEmpty($provider->providerurl); |
|||
$this->assertNotEmpty($provider->endpoints); |
|||
} else if (is_array($provider)) { |
|||
// Test the provider decoded JSON array. |
|||
$this->assertArrayHasKey('provider_name', $provider); |
|||
$this->assertArrayHasKey('provider_url', $provider); |
|||
$this->assertArrayHasKey('endpoints', $provider); |
|||
} else { |
|||
// Test failed. |
|||
$this->assertTrue(false); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Test instance. |
|||
*/ |
|||
public function test_instance() { |
|||
$this->resetAfterTest(true); |
|||
$this->setAdminUser(); |
|||
$oembed = testable_oembed::get_instance(); |
|||
$this->assertNotEmpty($oembed); |
|||
} |
|||
|
|||
public function test_set_providers() { |
|||
$this->resetAfterTest(true); |
|||
$this->setAdminUser(); |
|||
$oembed = testable_oembed::get_instance(); |
|||
$oembed->empty_providers(); |
|||
$oembed->protected_set_providers('all'); |
|||
$this->assertNotEmpty($oembed->providers); |
|||
$this->assert_providers_ok($oembed->providers); |
|||
} |
|||
|
|||
/** |
|||
* Test providers. |
|||
*/ |
|||
public function test_providers() { |
|||
$this->resetAfterTest(true); |
|||
$this->setAdminUser(); |
|||
$oembed = testable_oembed::get_instance(); |
|||
$providers = $oembed->providers; |
|||
$this->assert_providers_ok($providers); |
|||
} |
|||
|
|||
/** |
|||
* Test html. |
|||
* TODO - have a local oembed service with test fixtures for performing test. |
|||
*/ |
|||
public function test_embed_html() { |
|||
$this->resetAfterTest(true); |
|||
set_config('lazyload', 0, 'filter_oembed'); |
|||
$this->setAdminUser(); |
|||
$oembed = testable_oembed::get_instance(); |
|||
$text = $oembed->html_output('https://www.youtube.com/watch?v=ns6gCZI-Nj8'); |
|||
$expectedtext = '<div class="oembed-content oembed-responsive"><iframe width="480" height="270"' . |
|||
' src="https://www.youtube.com/embed/ns6gCZI-Nj8?feature=oembed&v=ns6gCZI-Nj8"'; |
|||
$this->assertContains($expectedtext, $text); |
|||
} |
|||
|
|||
/** |
|||
* Test lazy load html. |
|||
* TODO - have a local oembed service with test fixtures for performing test. |
|||
*/ |
|||
public function test_preloader_html() { |
|||
$this->resetAfterTest(true); |
|||
set_config('lazyload', 1, 'filter_oembed'); |
|||
$this->setAdminUser(); |
|||
$oembed = testable_oembed::get_instance(); |
|||
$text = $oembed->html_output('https://www.youtube.com/watch?v=ns6gCZI-Nj8'); |
|||
$this->assertContains('<div class="oembed-card-container oembed-responsive">', $text); |
|||
$this->assertRegExp('/<div class="oembed-card oembed-processed" style="(?:.*)" data-embed="(?:.*)"(?:.*)' . |
|||
'data-aspect-ratio = "(?:.*)"(?:.*)>/is', $text); |
|||
$this->assertRegExp('/<div class="oembed-card-title">(?:.*)<\/div>/', $text); |
|||
$this->assertContains('<button class="btn btn-link oembed-card-play" aria-label="Play"></button>', $text); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* Test download providers. |
|||
*/ |
|||
public function test_download_providers() { |
|||
$this->resetAfterTest(true); |
|||
$providers = testable_oembed::protected_download_providers(); |
|||
$this->assert_providers_ok($providers); |
|||
} |
|||
|
|||
/** |
|||
* Test get local providers. |
|||
*/ |
|||
public function test_get_local_providers() { |
|||
$this->resetAfterTest(true); |
|||
$providers = testable_oembed::protected_get_local_providers(); |
|||
$this->assert_providers_ok($providers); |
|||
} |
|||
|
|||
/** |
|||
* Test get plugin providers. |
|||
*/ |
|||
public function test_get_plugin_providers() { |
|||
$this->resetAfterTest(true); |
|||
$providers = testable_oembed::protected_get_plugin_providers(); |
|||
$this->assert_providers_ok($providers); |
|||
} |
|||
|
|||
/** |
|||
* Test match_provider_names. |
|||
*/ |
|||
public function test_match_provider_names() { |
|||
$this->resetAfterTest(true); |
|||
$providerdata = [ |
|||
(object)['id' => 1, 'providername' => 'Alpha1', 'providerurl' => 'http://www.one.com', |
|||
'endpoints' => '', 'source' => '', 'enabled' => 1, 'timecreated' => 0, 'timemodified' => 0], |
|||
(object)['id' => 2, 'providername' => 'Alpha1', 'providerurl' => 'http://www.another.com', |
|||
'endpoints' => '', 'source' => '', 'enabled' => 1, 'timecreated' => 0, 'timemodified' => 0], |
|||
(object)['id' => 3, 'providername' => 'Beta1', 'providerurl' => 'http://www.two.com', |
|||
'endpoints' => '', 'source' => '', 'enabled' => 1, 'timecreated' => 0, 'timemodified' => 0], |
|||
]; |
|||
|
|||
// Test that more than one of the same name, returns matching URL. |
|||
$provider = ['provider_name' => 'Alpha1', 'provider_url' => 'http://www.another.com', |
|||
'endpoints' => [['schemes' => [''], 'url' => '', 'formats' => ['']]]]; |
|||
$matched = testable_oembed::protected_match_provider_names($providerdata, $provider); |
|||
$this->assertTrue(is_object($matched)); |
|||
$this->assertEquals(2, $matched->id); |
|||
$this->assertEquals($provider['provider_name'], $matched->providername); |
|||
|
|||
// Test that only one of the name, returns the one regardless of URL. |
|||
$provider = ['provider_name' => 'Beta1', 'provider_url' => 'http://notthesameurl.com', |
|||
'endpoints' => [['schemes' => [''], 'url' => '', 'formats' => ['']]]]; |
|||
$matched = testable_oembed::protected_match_provider_names($providerdata, $provider); |
|||
$this->assertTrue(is_object($matched)); |
|||
$this->assertEquals(3, $matched->id); |
|||
$this->assertEquals($provider['provider_name'], $matched->providername); |
|||
|
|||
// Test that more than one of the same name, and no matching URL, returns false. |
|||
$provider = ['provider_name' => 'Alpha1', 'provider_url' => 'http://www.anewone.com', |
|||
'endpoints' => [['schemes' => [''], 'url' => '', 'formats' => ['']]]]; |
|||
$matched = testable_oembed::protected_match_provider_names($providerdata, $provider); |
|||
$this->assertFalse($matched); |
|||
|
|||
// Test that no matching name returns false. |
|||
$provider = ['provider_name' => 'Delta1', 'provider_url' => 'http://www.delta.com', |
|||
'endpoints' => [['schemes' => [''], 'url' => '', 'formats' => ['']]]]; |
|||
$matched = testable_oembed::protected_match_provider_names($providerdata, $provider); |
|||
$this->assertFalse($matched); |
|||
} |
|||
|
|||
/** |
|||
* Test the "__get" magic method. |
|||
*/ |
|||
public function test_get() { |
|||
$this->resetAfterTest(true); |
|||
$oembed = testable_oembed::get_instance(); |
|||
|
|||
try { |
|||
$providers = $oembed->providers; |
|||
$this->assert_providers_ok($providers); |
|||
} catch (Exception $e) { |
|||
$this->assertTrue(false); |
|||
} |
|||
|
|||
try { |
|||
$warnings = $oembed->warnings; |
|||
$this->assertTrue(is_array($warnings)); |
|||
} catch (Exception $e) { |
|||
$this->assertTrue(false); |
|||
} |
|||
|
|||
try { |
|||
$noaccess = $oembed->noaccess; |
|||
$this->assertTrue(false); |
|||
} catch (coding_exception $e) { |
|||
$expectedmessage = 'Coding error detected, it must be fixed by a programmer: ' . |
|||
'noaccess is not a publicly accessible property of testable_oembed'; |
|||
$this->assertEquals($expectedmessage, $e->getMessage()); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Test enable and disable provider functions. |
|||
* Tests: enable_provider, disable_provider, set_provider_enable_value. |
|||
*/ |
|||
public function test_enable_disable_provider() { |
|||
$this->resetAfterTest(true); |
|||
$oembed = testable_oembed::get_instance(); |
|||
|
|||
// Test by object. |
|||
$providers = $oembed->providers; |
|||
$provider = reset($providers); |
|||
$oembed->disable_provider($provider); |
|||
$this->assertFalse($oembed->providers[$provider->id]->enabled); |
|||
|
|||
// Test by id. |
|||
$oembed->enable_provider($provider->id); |
|||
$this->assertTrue($oembed->providers[$provider->id]->enabled); |
|||
} |
|||
} |
@ -0,0 +1,102 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Filter for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
use filter_oembed\service\oembed; |
|||
|
|||
/** |
|||
* Class testable_oembed. |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class testable_oembed extends oembed { |
|||
|
|||
/** |
|||
* Singleton |
|||
* |
|||
* @param string $providerstate Either 'enabled', 'disabled', or 'all'. |
|||
* @return oembed |
|||
*/ |
|||
public static function get_instance($providerstate = 'enabled') { |
|||
/** @var $instance oembed */ |
|||
static $instance = []; |
|||
if (!isset($instance[$providerstate])) { |
|||
$instance[$providerstate] = new testable_oembed($providerstate); |
|||
} |
|||
return $instance[$providerstate]; |
|||
} |
|||
|
|||
/** |
|||
* Calls the protected set_providers function. |
|||
*/ |
|||
public function protected_set_providers($state = 'enabled') { |
|||
return self::set_providers($state); |
|||
} |
|||
|
|||
/** |
|||
* Calls the protected download_providers function. |
|||
*/ |
|||
public static function protected_download_providers() { |
|||
return self::download_providers(); |
|||
} |
|||
|
|||
/** |
|||
* Calls the protected get_local_providers function. |
|||
*/ |
|||
public static function protected_get_local_providers() { |
|||
return self::get_local_providers(); |
|||
} |
|||
|
|||
/** |
|||
* Calls the protected get_plugin_providers function. |
|||
*/ |
|||
public static function protected_get_plugin_providers() { |
|||
return self::get_plugin_providers(); |
|||
} |
|||
|
|||
/** |
|||
* Calls the protected match_provider_names function. |
|||
*/ |
|||
public static function protected_match_provider_names($providerarray, $provider) { |
|||
return self::match_provider_names($providerarray, $provider); |
|||
} |
|||
|
|||
/** |
|||
* Empty the properties variable. |
|||
*/ |
|||
public function empty_providers() { |
|||
$this->providers = []; |
|||
} |
|||
|
|||
/** |
|||
* Calls the protected get_all_provider_data function. |
|||
*/ |
|||
public static function protected_get_all_provider_data($fields = '*') { |
|||
return self::get_all_provider_data($fields); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
<?php |
|||
// This file is part of Moodle-oembed-Filter |
|||
// |
|||
// Moodle-oembed-Filter is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle-oembed-Filter is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle-oembed-Filter. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Filter for component 'filter_oembed' |
|||
* |
|||
* @package filter_oembed |
|||
* @copyright Erich M. Wappis / Guy Thomas 2016 |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* code based on the following filter |
|||
* oEmbed filter ( Mike Churchward, James McQuillan, Vinayak (Vin) Bhalerao, Josh Gavant and Rob Dolin) |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$plugin->version = 2017060100; |
|||
$plugin->requires = 2019052000; |
|||
$plugin->component = 'filter_oembed'; |
|||
$plugin->maturity = MATURITY_STABLE; |
|||
$plugin->release = '3.8.0 (Build - 2019112600)'; |
Loading…
Reference in new issue