├── .gitignore
├── .travis.yml
├── LICENSE.txt
├── README.txt
├── composer.json
├── doc
└── spec_en.html
├── embed.php
├── fonts
├── h5p-core-29.eot
├── h5p-core-29.svg
├── h5p-core-29.ttf
├── h5p-core-29.woff
├── h5p-core-29.woff2
├── h5p-core-30.eot
├── h5p-core-30.svg
├── h5p-core-30.ttf
├── h5p-core-30.woff
├── h5p-core-30.woff2
├── h5p-hub-publish.eot
├── h5p-hub-publish.svg
├── h5p-hub-publish.ttf
├── h5p-hub-publish.woff
└── open-sans
│ ├── LICENSE-2.0.txt
│ ├── opensans-400-600-700-v28-cyrillic-ext.woff2
│ ├── opensans-400-600-700-v28-cyrillic.woff2
│ ├── opensans-400-600-700-v28-greek-ext.woff2
│ ├── opensans-400-600-700-v28-greek.woff2
│ ├── opensans-400-600-700-v28-hebrew.woff2
│ ├── opensans-400-600-700-v28-latin-ext.woff2
│ ├── opensans-400-600-700-v28-latin.woff2
│ ├── opensans-400-600-700-v28-vietnamese.woff2
│ ├── opensans-italic-400-600-700-v28-cyrillic-ext.woff2
│ ├── opensans-italic-400-600-700-v28-cyrillic.woff2
│ ├── opensans-italic-400-600-700-v28-greek-ext.woff2
│ ├── opensans-italic-400-600-700-v28-greek.woff2
│ ├── opensans-italic-400-600-700-v28-hebrew.woff2
│ ├── opensans-italic-400-600-700-v28-latin-ext.woff2
│ ├── opensans-italic-400-600-700-v28-latin.woff2
│ └── opensans-italic-400-600-700-v28-vietnamese.woff2
├── h5p-default-storage.class.php
├── h5p-development.class.php
├── h5p-event-base.class.php
├── h5p-file-storage.interface.php
├── h5p-metadata.class.php
├── h5p.classes.php
├── images
├── h5p.svg
└── throbber.gif
├── js
├── h5p-action-bar.js
├── h5p-confirmation-dialog.js
├── h5p-content-type.js
├── h5p-content-upgrade-process.js
├── h5p-content-upgrade-worker.js
├── h5p-content-upgrade.js
├── h5p-data-view.js
├── h5p-display-options.js
├── h5p-embed.js
├── h5p-event-dispatcher.js
├── h5p-hub-registration.js
├── h5p-hub-sharing.js
├── h5p-library-details.js
├── h5p-library-list.js
├── h5p-resizer.js
├── h5p-tooltip.js
├── h5p-utils.js
├── h5p-version.js
├── h5p-x-api-event.js
├── h5p-x-api.js
├── h5p.js
├── jquery.js
├── request-queue.js
└── settings
│ └── h5p-disable-hub.js
└── styles
├── font-open-sans.css
├── h5p-admin.css
├── h5p-confirmation-dialog.css
├── h5p-core-button.css
├── h5p-hub-registration.css
├── h5p-hub-sharing.css
├── h5p-table.css
├── h5p-tooltip.css
└── h5p.css
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | vendor
3 | *~
4 | .idea
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | # At present the only jobs to run are a php lint.
4 | # Run this against all supported versions of PHP.
5 | jobs:
6 | include:
7 | # Bionic supports PHP 7.1, 7.2, 7.3, and 7.4.
8 | # https://docs.travis-ci.com/user/reference/bionic/#php-support
9 | - php: 7.4
10 | dist: bionic
11 | - php: 7.3
12 | dist: bionic
13 | - php: 7.2
14 | dist: bionic
15 | - php: 7.1
16 | dist: bionic
17 |
18 | # Xenial was the last Travis distribution to support PHP 5.6, and 7.0.
19 | # https://docs.travis-ci.com/user/reference/xenial/#php-support
20 | - php: 7.0
21 | dist: xenial
22 | - php: 5.6
23 | dist: xenial
24 |
25 | # Trusty was the last Travis distribution to support PHP 5.4, and 5.5.
26 | # https://docs.travis-ci.com/user/languages/php/#php-54x---55x-support-is-available-on-precise-and-trusty-only
27 | - php: 5.5
28 | dist: trusty
29 | - php: 5.4
30 | dist: trusty
31 |
32 |
33 | # Precise was the last Travis distribution to support PHP 5.2, and 5.3.
34 | # https://docs.travis-ci.com/user/languages/php/#php-52x---53x-support-is-available-on-precise-only
35 | - php: 5.3
36 | dist: precise
37 |
38 | script:
39 | # Run a php lint across all PHP files.
40 | - find . -type f -name '*\.php' -print0 | xargs -0 -n1 php -l
41 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | This folder contains the general H5P library. The files within this folder are not specific to any framework.
2 |
3 | Any interaction with an LMS, CMS or other frameworks is done through interfaces. Platforms need to implement
4 | the H5PFrameworkInterface(in h5p.classes.php) and also do the following:
5 |
6 | - Provide a form for uploading H5P packages.
7 | - Place the uploaded H5P packages in a temporary directory
8 | +++
9 |
10 | See existing implementations for details. For instance the Drupal H5P module located at drupal.org/project/h5p
11 |
12 | We will make available documentation and tutorials for creating platform integrations in the future.
13 |
14 | The H5P PHP library is GPL licensed due to GPL code being used for purifying HTML provided by authors.
15 |
16 | ## License
17 |
18 | Open Sans font is licensed under Apache license, Version 2.0
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "h5p/h5p-core",
3 | "type": "library",
4 | "description": "H5P Core functionality in PHP",
5 | "keywords": ["h5p","hvp","interactive","content","quiz"],
6 | "homepage": "https://h5p.org",
7 | "license": "GPL-3.0",
8 | "authors": [
9 | {
10 | "name": "Svein-Tore Griff With",
11 | "email": "with@joubel.com",
12 | "homepage": "http://joubel.com",
13 | "role": "CEO"
14 | },
15 | {
16 | "name": "Frode Petterson",
17 | "email": "frode.petterson@joubel.com",
18 | "homepage": "http://joubel.com",
19 | "role": "Developer"
20 | }
21 | ],
22 | "require": {
23 | "php": ">=7.0.0"
24 | },
25 | "autoload": {
26 | "files": [
27 | "h5p.classes.php",
28 | "h5p-development.class.php",
29 | "h5p-file-storage.interface.php",
30 | "h5p-default-storage.class.php",
31 | "h5p-event-base.class.php",
32 | "h5p-metadata.class.php"
33 | ]
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/doc/spec_en.html:
--------------------------------------------------------------------------------
1 |
Overview
2 |
H5P is a file format for content/applications made using modern, open web technologies (HTML5). The format enables easy installation and transfer of applications/content on different CMSes, LMSes and other platforms. An H5P can be uploaded and published on a platform in mostly the same way one would publish a Flash file today. H5P files may also be updated by simply uploading a new version of the file, the same way as one would using Flash.
3 |
H5P opens for extensive reuse of code and wide flexibility regarding what may be developed as an H5P.
4 |
The system uses package files containing all necessary files and libraries for the application to function. These files are based on open formats.
5 |
Overview of package files
6 |
Package files are normal zip files, with a naming convention of <filename>.h5p to distinguish from any random zip file. This zip file then requires a specific file structure as described below.
7 |
There will be a file in JSON format named h5p.json describing the contents of the package and how the system should interpret and use it. This file contains information about title, content type, usage, copyright, licensing, version, language etc. This is described in detail below.
8 |
There shall be a folder for each included H5P library used by the package. These generic libraries may be reused by other H5P packages. As an example, a multi-choice question task may be used as a standalone block, or be included in a larger H5P package generating a game with quizzes.
9 |
Package file structure
10 |
A package contains the following elements:
11 |
12 |
A mandatory file in the root folder named h5p.json
13 |
An optional image file named h5p.jpg. This is an icon or an image of the application, 512 × 512 pixels. This image may be used by the platform as a preview of the application, and could be included in OG meta tags for use with social media.
14 |
One content folder, named content. This will contain the preset configuration for the application, as well as any required media files.
15 |
One or more library directories named the same as the library's internal name.
16 |
17 |
h5p.json
18 |
The h5p.json file is a normal JSON text file containing a JSON object with the following predefined properties.
19 |
Mandatory properties:
20 |
21 |
title - Name of the package. Would typically be used as header for a page displaying the package.
22 |
language - Standard language code. Use 'en' for english, 'nb' for norwegian "bokmål". Neutral content use "und".
23 |
machineName - Machine readable name of the library. This is the name that will be used for the library folder in the package too.
24 |
preloadedDependencies - Libraries that must be loaded on init. Specified as a list of objects with machineName, majorVersion and minorVersion. One would normally list all dependencies here to allow the platform displaying the package to merge JS and CSS files before returning the page.
25 |
embedTypes - List of ways to embed the package in the web page. Currently "div" and "iframe" are supported.
26 |
Optional properties:
27 |
contentType - Textual description of the type of content.
28 |
description - Textual description of the package.
29 |
author - Name of author.
30 |
license - Code for the content license. Use the following Creative Commons codes: cc-by, cc-by-sa, cc-by-nd, cc-by-nc, cc-by-nc-sa, cc-by-nc-nd. In addition for public domain: pd, and closed license: cr. More may be added later.
31 |
dynamicDependencies - Libraries that may be loaded dynamically during execution.
32 |
width - Width of the package content in cases where the package is not dynamically resizable.
33 |
height - Height of the package content.
34 |
metaKeywords - Suggestion for keywords for the application, as a string. May be used for OG meta tags for social media.
35 |
metaDescription - Suggestion for application metaDescription. May be used for OG meta tags for social media.
Contains all the content for the package and its libraries. There shall be no content inside the library folders. The content folder shall contain a file named content.json, containing the JSON object that will be passed to the initializer for the main package library.
68 |
69 |
Content required by libraries invoked from the main package library will get their contents passed from the main library. The JSON for this will be found within the main content.json for the package, and passed during initialization.
70 |
71 |
Library folders
72 |
73 |
A library folder contains all logic, stylesheets and graphics that will be common for all instances of a library. There shall be no content or interface text directly in these folders. All text displayed to the end user shall be passed as part of the library configuration. This make the libraries language independent.
74 |
75 |
The root of a library folder shall contain a file name library.json formatted similar to the package's hp5.json, but with a few differences. The library shall also have one or more images in the root folder, named library.jpg, library1.jpg etc. Image sizes 512px × 512px, and will be used in the H5P editor tool.
76 |
77 |
Libraries are not allowed to modify the document tree in ways that will have consequences for the web site or will be noticeable by the user without the library explicitly being initialized from the main package library or another invoked library.
78 |
79 |
The library shall always include a JavaScript object function named the same as the defined library machineName (defined in library.json and used as the library folder name). This object will be instantiated with the library options as parameter. The resulting object must contain a function attach(target) that will be called after instantiation to attach the library DOM to the main DOM inside target
80 |
81 |
Example
82 |
A library called H5P.multichoice would typically be instantiated and attached to the page like this:
83 | var multichoice = new H5P.multichoice(contentFromJson, contentId);
84 | multichoice.attach($multichoiceContainer);
85 |
86 |
library.json
87 |
Mandatory properties:
88 |
89 |
title - Human readable name of the library. May be used in the H5P editor and overviews of installed libraries.
90 |
majorVersion - Version major number. (The x in x.y.z). Positive integer.
91 |
minorVersion - Version minor number. (The y in x.y.z). Positive integer.
92 |
patchVersion - Version patch number. (The z in x.y.z). Positive integer. The system will automatically update to the latest patchVersion installed for all packages that use the library with the same major and minor version number. A new patch version must therefore not change any behaviour of the library, only fix errors.
93 |
machineName - Machine readable name for the library. Same as the folder name used.
94 |
preloadedJs - List of path to the javascript files required for the library. At least one file need to be present (the one defining the library object). Paths are relative to the library root folder.
95 |
96 |
Optional properties:
97 |
98 |
author - Author name as text.
99 |
license - Code describing the library license. Use the following creative commons codes: cc-by, cc-by-sa, cc-by-nd, cc-by-nc, cc-by-nc-sa, cc-by-nc-nd. In addition use pd for public domain, and cr for closed source
100 |
description - Textual description of the library.
101 |
preloadedDependencies - Libraries that need to be loaded for this library to work. Specified as a list of objects with machineName, majorVersion and minorVersion for the required libraries.
102 |
dynamicDependencies - Libraries that may be loaded dynamically during library execution. Specified as a list of objects like preloadedDependencies above.
103 |
preloadedCss - List of paths to CSS files to be loaded with the library. Paths are relative to the library root folder.
104 |
w - Width in pixels for libraries that use a fixed width. Mandatory if the library shall be embedded in an iframe (see embedTypes below).
105 |
h - Height in pixels for libraries that use a fixed height. Mandatory if the library shall be embedded in an iframe (see embedTypes below).
106 |
embedTypes - List of possible ways to embed the package in the page. Available values are div and iframe.
Files that require server side execution or that cannot be regarded an open standard shall not be used. Allowed file types: js, json, png, jpg, gif, svg, css, mp3, wav (audio: PCM), m4a (audio: AAC), mp4 (video: H.264, audio: AAC/MP3), ogg (video: Theora, audio: Vorbis) and webm (video VP8, audio: Vorbis). Administrators of web sites implementing H5P may open for accepting further formats. HTML files shall not be used. HTML for each library shall be inserted from the library scripts to ease code reuse. (By avoiding content being defined in said HTML).
140 |
API functions
141 |
The following JavaScript functions are available through h5p:
142 |
143 |
H5P.getUserData(namespace, variable)
144 |
H5P.setUserData(namespace, variable, data)
145 |
H5P.getUserStart(namespace)
146 |
H5P.setUserStop(namespace)
147 |
H5P.deleteUserData(namespace, variable)
148 |
H5P.getGlobalData(namespace, variable)
149 |
H5P.setGlobalData(namespace, variable, data)
150 |
H5P.deleteGlobalData(namespace, variable)
151 |
152 |
I tillegg er følgende api funksjoner tilgjengelig via ndla:
153 |
154 |
H5P.setUserScore(contentId, score, maxScore)
155 |
156 |
Best practices
157 |
H5P is a very open standard. This is positive for flexibility. Most content may be produces as H5P. But this also allows for bad code, security weaknesses, code that may be difficult to reuse. Therefore the following best practices should be followed to get the most from H5P:
158 |
159 |
Think reusability when creating a library. H5P support dependencies between libraries, so the same small quiz-library may be used in various larger packages or libraries.
160 |
H5P supports library updates. This enables all content using a common library to be updated at once. This must be accounted for when writing new libraries. A library should be as general as possible. The content format should be thought out so there are no changes to the required content data when a library is updated. Note: Multiple versions of a library may exists at the same time, only patch level updates will be automatically installed.
161 |
An H5P should not interact directly with the containing web site. It shall only affect elements within its own generated DOM tree. Elements shall also only be injected within the target defined on initialization. This is to avoid dependencies to a specific platform or web page.
162 |
Prefix objects, global functions, etc with h5p to minimize the chance of namespace conflicts with the rest of the web page. Remember that there may also be multiple H5P objects inserted on a page, so plan ahead to avoid conflicts.
163 |
Content should be responsive.
164 |
Content should be WCAG 2 AA compliant
165 |
All generated HTML should validate.
166 |
All CSS should validate (some browser specific non-standard CSS may at times be required)
167 |
Best practices for JavaScript, HTML, etc. should of course also be followed when writing an H5P.
168 |
169 |
--------------------------------------------------------------------------------
/embed.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/fonts/h5p-core-29.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-core-29.eot
--------------------------------------------------------------------------------
/fonts/h5p-core-29.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-core-29.ttf
--------------------------------------------------------------------------------
/fonts/h5p-core-29.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-core-29.woff
--------------------------------------------------------------------------------
/fonts/h5p-core-29.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-core-29.woff2
--------------------------------------------------------------------------------
/fonts/h5p-core-30.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-core-30.eot
--------------------------------------------------------------------------------
/fonts/h5p-core-30.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-core-30.ttf
--------------------------------------------------------------------------------
/fonts/h5p-core-30.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-core-30.woff
--------------------------------------------------------------------------------
/fonts/h5p-core-30.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-core-30.woff2
--------------------------------------------------------------------------------
/fonts/h5p-hub-publish.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-hub-publish.eot
--------------------------------------------------------------------------------
/fonts/h5p-hub-publish.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/fonts/h5p-hub-publish.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-hub-publish.ttf
--------------------------------------------------------------------------------
/fonts/h5p-hub-publish.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/h5p-hub-publish.woff
--------------------------------------------------------------------------------
/fonts/open-sans/LICENSE-2.0.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-400-600-700-v28-cyrillic-ext.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-400-600-700-v28-cyrillic-ext.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-400-600-700-v28-cyrillic.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-400-600-700-v28-cyrillic.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-400-600-700-v28-greek-ext.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-400-600-700-v28-greek-ext.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-400-600-700-v28-greek.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-400-600-700-v28-greek.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-400-600-700-v28-hebrew.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-400-600-700-v28-hebrew.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-400-600-700-v28-latin-ext.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-400-600-700-v28-latin-ext.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-400-600-700-v28-latin.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-400-600-700-v28-latin.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-400-600-700-v28-vietnamese.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-400-600-700-v28-vietnamese.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-italic-400-600-700-v28-cyrillic-ext.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-italic-400-600-700-v28-cyrillic-ext.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-italic-400-600-700-v28-cyrillic.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-italic-400-600-700-v28-cyrillic.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-italic-400-600-700-v28-greek-ext.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-italic-400-600-700-v28-greek-ext.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-italic-400-600-700-v28-greek.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-italic-400-600-700-v28-greek.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-italic-400-600-700-v28-hebrew.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-italic-400-600-700-v28-hebrew.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-italic-400-600-700-v28-latin-ext.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-italic-400-600-700-v28-latin-ext.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-italic-400-600-700-v28-latin.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-italic-400-600-700-v28-latin.woff2
--------------------------------------------------------------------------------
/fonts/open-sans/opensans-italic-400-600-700-v28-vietnamese.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/fonts/open-sans/opensans-italic-400-600-700-v28-vietnamese.woff2
--------------------------------------------------------------------------------
/h5p-development.class.php:
--------------------------------------------------------------------------------
1 | h5pF = $H5PFramework;
26 | $this->language = $language;
27 | $this->filesPath = $filesPath;
28 | if ($libraries !== NULL) {
29 | $this->libraries = $libraries;
30 | }
31 | else {
32 | $this->findLibraries($filesPath . '/development');
33 | }
34 | }
35 |
36 | /**
37 | * Get contents of file.
38 | *
39 | * @param string $file File path.
40 | * @return mixed String on success or NULL on failure.
41 | */
42 | private function getFileContents($file) {
43 | if (file_exists($file) === FALSE) {
44 | return NULL;
45 | }
46 |
47 | $contents = file_get_contents($file);
48 | if ($contents === FALSE) {
49 | return NULL;
50 | }
51 |
52 | return $contents;
53 | }
54 |
55 | /**
56 | * Scans development directory and find all libraries.
57 | *
58 | * @param string $path Libraries development folder
59 | */
60 | private function findLibraries($path) {
61 | $this->libraries = array();
62 |
63 | if (is_dir($path) === FALSE) {
64 | return;
65 | }
66 |
67 | $contents = scandir($path);
68 |
69 | for ($i = 0, $s = count($contents); $i < $s; $i++) {
70 | if ($contents[$i][0] === '.') {
71 | continue; // Skip hidden stuff.
72 | }
73 |
74 | $libraryPath = $path . '/' . $contents[$i];
75 | $libraryJSON = $this->getFileContents($libraryPath . '/library.json');
76 | if ($libraryJSON === NULL) {
77 | continue; // No JSON file, skip.
78 | }
79 |
80 | $library = json_decode($libraryJSON, TRUE);
81 | if ($library === NULL) {
82 | continue; // Invalid JSON.
83 | }
84 |
85 | // TODO: Validate props? Not really needed, is it? this is a dev site.
86 |
87 | $library['libraryId'] = $this->h5pF->getLibraryId($library['machineName'], $library['majorVersion'], $library['minorVersion']);
88 |
89 | // Convert metadataSettings values to boolean & json_encode it before saving
90 | $library['metadataSettings'] = isset($library['metadataSettings']) ?
91 | H5PMetadata::boolifyAndEncodeSettings($library['metadataSettings']) :
92 | NULL;
93 |
94 | // Save/update library.
95 | $this->h5pF->saveLibraryData($library, $library['libraryId'] === FALSE);
96 |
97 | // Need to decode it again, since it is served from here.
98 | $library['metadataSettings'] = isset($library['metadataSettings'])
99 | ? json_decode($library['metadataSettings'])
100 | : NULL;
101 |
102 | $library['path'] = 'development/' . $contents[$i];
103 | $this->libraries[H5PDevelopment::libraryToString($library['machineName'], $library['majorVersion'], $library['minorVersion'])] = $library;
104 | }
105 |
106 | // TODO: Should we remove libraries without files? Not really needed, but must be cleaned up some time, right?
107 |
108 | // Go trough libraries and insert dependencies. Missing deps. will just be ignored and not available. (I guess?!)
109 | $this->h5pF->lockDependencyStorage();
110 | foreach ($this->libraries as $library) {
111 | $this->h5pF->deleteLibraryDependencies($library['libraryId']);
112 | // This isn't optimal, but without it we would get duplicate warnings.
113 | // TODO: You might get PDOExceptions if two or more requests does this at the same time!!
114 | $types = array('preloaded', 'dynamic', 'editor');
115 | foreach ($types as $type) {
116 | if (isset($library[$type . 'Dependencies'])) {
117 | $this->h5pF->saveLibraryDependencies($library['libraryId'], $library[$type . 'Dependencies'], $type);
118 | }
119 | }
120 | }
121 | $this->h5pF->unlockDependencyStorage();
122 | // TODO: Deps must be inserted into h5p_nodes_libraries as well... ? But only if they are used?!
123 | }
124 |
125 | /**
126 | * @return array Libraries in development folder.
127 | */
128 | public function getLibraries() {
129 | return $this->libraries;
130 | }
131 |
132 | /**
133 | * Get library
134 | *
135 | * @param string $name of the library.
136 | * @param int $majorVersion of the library.
137 | * @param int $minorVersion of the library.
138 | * @return array library.
139 | */
140 | public function getLibrary($name, $majorVersion, $minorVersion) {
141 | $library = H5PDevelopment::libraryToString($name, $majorVersion, $minorVersion);
142 | return isset($this->libraries[$library]) === TRUE ? $this->libraries[$library] : NULL;
143 | }
144 |
145 | /**
146 | * Get semantics for the given library.
147 | *
148 | * @param string $name of the library.
149 | * @param int $majorVersion of the library.
150 | * @param int $minorVersion of the library.
151 | * @return string Semantics
152 | */
153 | public function getSemantics($name, $majorVersion, $minorVersion) {
154 | $library = H5PDevelopment::libraryToString($name, $majorVersion, $minorVersion);
155 | if (isset($this->libraries[$library]) === FALSE) {
156 | return NULL;
157 | }
158 | return $this->getFileContents($this->filesPath . $this->libraries[$library]['path'] . '/semantics.json');
159 | }
160 |
161 | /**
162 | * Get translations for the given library.
163 | *
164 | * @param string $name of the library.
165 | * @param int $majorVersion of the library.
166 | * @param int $minorVersion of the library.
167 | * @param $language
168 | * @return string Translation
169 | */
170 | public function getLanguage($name, $majorVersion, $minorVersion, $language) {
171 | $library = H5PDevelopment::libraryToString($name, $majorVersion, $minorVersion);
172 |
173 | if (isset($this->libraries[$library]) === FALSE) {
174 | return NULL;
175 | }
176 |
177 | return $this->getFileContents($this->filesPath . $this->libraries[$library]['path'] . '/language/' . $language . '.json');
178 | }
179 |
180 | /**
181 | * Writes library as string on the form "name majorVersion.minorVersion"
182 | *
183 | * @param string $name Machine readable library name
184 | * @param integer $majorVersion
185 | * @param $minorVersion
186 | * @return string Library identifier.
187 | */
188 | public static function libraryToString($name, $majorVersion, $minorVersion) {
189 | return $name . ' ' . $majorVersion . '.' . $minorVersion;
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/h5p-event-base.class.php:
--------------------------------------------------------------------------------
1 | – content view
28 | * embed – viewed through embed code
29 | * shortcode – viewed through internal shortcode
30 | * edit – opened in editor
31 | * delete – deleted
32 | * create – created through editor
33 | * create upload – created through upload
34 | * update – updated through editor
35 | * update upload – updated through upload
36 | * upgrade – upgraded
37 | *
38 | * results, – view own results
39 | * content – view results for content
40 | * set – new results inserted or updated
41 | *
42 | * settings, – settings page loaded
43 | *
44 | * library, – loaded in editor
45 | * create – new library installed
46 | * update – old library updated
47 | *
48 | * @param string $type
49 | * Name of event type
50 | * @param string $sub_type
51 | * Name of event sub type
52 | * @param string $content_id
53 | * Identifier for content affected by the event
54 | * @param string $content_title
55 | * Content title (makes it easier to know which content was deleted etc.)
56 | * @param string $library_name
57 | * Name of the library affected by the event
58 | * @param string $library_version
59 | * Library version
60 | */
61 | function __construct($type, $sub_type = NULL, $content_id = NULL, $content_title = NULL, $library_name = NULL, $library_version = NULL) {
62 | $this->type = $type;
63 | $this->sub_type = $sub_type;
64 | $this->content_id = $content_id;
65 | $this->content_title = $content_title;
66 | $this->library_name = $library_name;
67 | $this->library_version = $library_version;
68 | $this->time = time();
69 |
70 | if (self::validLogLevel($type, $sub_type)) {
71 | $this->save();
72 | }
73 | if (self::validStats($type, $sub_type)) {
74 | $this->saveStats();
75 | }
76 | }
77 |
78 | /**
79 | * Determines if the event type should be saved/logged.
80 | *
81 | * @param string $type
82 | * Name of event type
83 | * @param string $sub_type
84 | * Name of event sub type
85 | * @return boolean
86 | */
87 | private static function validLogLevel($type, $sub_type) {
88 | switch (self::$log_level) {
89 | default:
90 | case self::LOG_NONE:
91 | return FALSE;
92 | case self::LOG_ALL:
93 | return TRUE; // Log everything
94 | case self::LOG_ACTIONS:
95 | if (self::isAction($type, $sub_type)) {
96 | return TRUE; // Log actions
97 | }
98 | return FALSE;
99 | }
100 | }
101 |
102 | /**
103 | * Check if the event should be included in the statistics counter.
104 | *
105 | * @param string $type
106 | * Name of event type
107 | * @param string $sub_type
108 | * Name of event sub type
109 | * @return boolean
110 | */
111 | private static function validStats($type, $sub_type) {
112 | if ( ($type === 'content' && $sub_type === 'shortcode insert') || // Count number of shortcode inserts
113 | ($type === 'library' && $sub_type === NULL) || // Count number of times library is loaded in editor
114 | ($type === 'results' && $sub_type === 'content') ) { // Count number of times results page has been opened
115 | return TRUE;
116 | }
117 | elseif (self::isAction($type, $sub_type)) { // Count all actions
118 | return TRUE;
119 | }
120 | return FALSE;
121 | }
122 |
123 | /**
124 | * Check if event type is an action.
125 | *
126 | * @param string $type
127 | * Name of event type
128 | * @param string $sub_type
129 | * Name of event sub type
130 | * @return boolean
131 | */
132 | private static function isAction($type, $sub_type) {
133 | if ( ($type === 'content' && in_array($sub_type, array('create', 'create upload', 'update', 'update upload', 'upgrade', 'delete'))) ||
134 | ($type === 'library' && in_array($sub_type, array('create', 'update'))) ) {
135 | return TRUE; // Log actions
136 | }
137 | return FALSE;
138 | }
139 |
140 | /**
141 | * A helper which makes it easier for systems to save the data.
142 | * Add all relevant properties to a assoc. array.
143 | * There are no NULL values. Empty string or 0 is used instead.
144 | * Used by both Drupal and WordPress.
145 | *
146 | * @return array with keyed values
147 | */
148 | protected function getDataArray() {
149 | return array(
150 | 'created_at' => $this->time,
151 | 'type' => $this->type,
152 | 'sub_type' => empty($this->sub_type) ? '' : $this->sub_type,
153 | 'content_id' => empty($this->content_id) ? 0 : $this->content_id,
154 | 'content_title' => empty($this->content_title) ? '' : $this->content_title,
155 | 'library_name' => empty($this->library_name) ? '' : $this->library_name,
156 | 'library_version' => empty($this->library_version) ? '' : $this->library_version
157 | );
158 | }
159 |
160 | /**
161 | * A helper which makes it easier for systems to save the data.
162 | * Used in WordPress.
163 | *
164 | * @return array with strings
165 | */
166 | protected function getFormatArray() {
167 | return array(
168 | '%d',
169 | '%s',
170 | '%s',
171 | '%d',
172 | '%s',
173 | '%s',
174 | '%s'
175 | );
176 | }
177 |
178 | /**
179 | * Stores the event data in the database.
180 | *
181 | * Must be overridden by plugin.
182 | */
183 | abstract protected function save();
184 |
185 | /**
186 | * Add current event data to statistics counter.
187 | *
188 | * Must be overridden by plugin.
189 | */
190 | abstract protected function saveStats();
191 | }
192 |
--------------------------------------------------------------------------------
/h5p-file-storage.interface.php:
--------------------------------------------------------------------------------
1 | array(
9 | 'type' => 'text',
10 | 'maxLength' => 255
11 | ),
12 | 'a11yTitle' => array(
13 | 'type' => 'text',
14 | 'maxLength' => 255,
15 | ),
16 | 'authors' => array(
17 | 'type' => 'json'
18 | ),
19 | 'changes' => array(
20 | 'type' => 'json'
21 | ),
22 | 'source' => array(
23 | 'type' => 'text',
24 | 'maxLength' => 255
25 | ),
26 | 'license' => array(
27 | 'type' => 'text',
28 | 'maxLength' => 32
29 | ),
30 | 'licenseVersion' => array(
31 | 'type' => 'text',
32 | 'maxLength' => 10
33 | ),
34 | 'licenseExtras' => array(
35 | 'type' => 'text',
36 | 'maxLength' => 5000
37 | ),
38 | 'authorComments' => array(
39 | 'type' => 'text',
40 | 'maxLength' => 5000
41 | ),
42 | 'yearFrom' => array(
43 | 'type' => 'int'
44 | ),
45 | 'yearTo' => array(
46 | 'type' => 'int'
47 | ),
48 | 'defaultLanguage' => array(
49 | 'type' => 'text',
50 | 'maxLength' => 32,
51 | )
52 | );
53 |
54 | /**
55 | * JSON encode metadata
56 | *
57 | * @param object $content
58 | * @return string
59 | */
60 | public static function toJSON($content) {
61 | // Note: deliberatly creating JSON string "manually" to improve performance
62 | return
63 | '{"title":' . (isset($content->title) ? json_encode($content->title) : 'null') .
64 | ',"a11yTitle":' . (isset($content->a11y_title) ? $content->a11y_title : 'null') .
65 | ',"authors":' . (isset($content->authors) ? $content->authors : 'null') .
66 | ',"source":' . (isset($content->source) ? '"' . $content->source . '"' : 'null') .
67 | ',"license":' . (isset($content->license) ? '"' . $content->license . '"' : 'null') .
68 | ',"licenseVersion":' . (isset($content->license_version) ? '"' . $content->license_version . '"' : 'null') .
69 | ',"licenseExtras":' . (isset($content->license_extras) ? json_encode($content->license_extras) : 'null') .
70 | ',"yearFrom":' . (isset($content->year_from) ? $content->year_from : 'null') .
71 | ',"yearTo":' . (isset($content->year_to) ? $content->year_to : 'null') .
72 | ',"changes":' . (isset($content->changes) ? $content->changes : 'null') .
73 | ',"defaultLanguage":' . (isset($content->default_language) ? '"' . $content->default_language . '"' : 'null') .
74 | ',"authorComments":' . (isset($content->author_comments) ? json_encode($content->author_comments) : 'null') . '}';
75 | }
76 |
77 | /**
78 | * Make the metadata into an associative array keyed by the property names
79 | * @param mixed $metadata Array or object containing metadata
80 | * @param bool $include_title
81 | * @param bool $include_missing For metadata fields not being set, skip 'em.
82 | * Relevant for content upgrade
83 | * @param array $types
84 | * @return array
85 | */
86 | public static function toDBArray($metadata, $include_title = true, $include_missing = true, &$types = array()) {
87 | $fields = array();
88 |
89 | if (!is_array($metadata)) {
90 | $metadata = (array) $metadata;
91 | }
92 |
93 | foreach (self::$fields as $key => $config) {
94 |
95 | // Ignore title?
96 | if ($key === 'title' && !$include_title) {
97 | continue;
98 | }
99 |
100 | $exists = array_key_exists($key, $metadata);
101 |
102 | // Don't include missing fields
103 | if (!$include_missing && !$exists) {
104 | continue;
105 | }
106 |
107 | $value = $exists ? $metadata[$key] : null;
108 |
109 | // lowerCamelCase to snake_case
110 | $db_field_name = strtolower(preg_replace('/(? $config['maxLength']) {
115 | $value = mb_substr($value, 0, $config['maxLength']);
116 | }
117 | $types[] = '%s';
118 | break;
119 |
120 | case 'int':
121 | $value = ($value !== null) ? intval($value) : null;
122 | $types[] = '%d';
123 | break;
124 |
125 | case 'json':
126 | $value = ($value !== null) ? json_encode($value) : null;
127 | $types[] = '%s';
128 | break;
129 | }
130 |
131 | $fields[$db_field_name] = $value;
132 | }
133 |
134 | return $fields;
135 | }
136 |
137 | /**
138 | * The metadataSettings field in libraryJson uses 1 for true and 0 for false.
139 | * Here we are converting these to booleans, and also doing JSON encoding.
140 | * This is invoked before the library data is beeing inserted/updated to DB.
141 | *
142 | * @param array $metadataSettings
143 | * @return string
144 | */
145 | public static function boolifyAndEncodeSettings($metadataSettings) {
146 | // Convert metadataSettings values to boolean
147 | if (isset($metadataSettings['disable'])) {
148 | $metadataSettings['disable'] = $metadataSettings['disable'] === 1;
149 | }
150 | if (isset($metadataSettings['disableExtraTitleField'])) {
151 | $metadataSettings['disableExtraTitleField'] = $metadataSettings['disableExtraTitleField'] === 1;
152 | }
153 |
154 | return json_encode($metadataSettings);
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/images/h5p.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
--------------------------------------------------------------------------------
/images/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h5p/h5p-php-library/b5f527e140c17da2792283d369f621e9b3f969ff/images/throbber.gif
--------------------------------------------------------------------------------
/js/h5p-action-bar.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @class
3 | * @augments H5P.EventDispatcher
4 | * @param {Object} displayOptions
5 | * @param {boolean} displayOptions.export Triggers the display of the 'Download' button
6 | * @param {boolean} displayOptions.copyright Triggers the display of the 'Copyright' button
7 | * @param {boolean} displayOptions.embed Triggers the display of the 'Embed' button
8 | * @param {boolean} displayOptions.icon Triggers the display of the 'H5P icon' link
9 | */
10 | H5P.ActionBar = (function ($, EventDispatcher) {
11 | "use strict";
12 |
13 | function ActionBar(displayOptions) {
14 | EventDispatcher.call(this);
15 |
16 | /** @alias H5P.ActionBar# */
17 | var self = this;
18 |
19 | var hasActions = false;
20 |
21 | // Create action bar
22 | var $actions = H5P.jQuery('