Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion admin/class-h5p-plugin-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,37 @@ function add_settings_link($links) {
* @since 1.3.0
*/
public function embed() {
global $wpdb;
// Allow other sites to embed
header_remove('X-Frame-Options');

// Find content
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
$slug = filter_input(INPUT_GET, 'slug', FILTER_SANITIZE_ADD_SLASHES);

$id = NULL;

if (!empty($slug)) {
$q=$wpdb->prepare(
"SELECT id ".
"FROM {$wpdb->prefix}h5p_contents ".
"WHERE slug=%s",
$slug
);
$row=$wpdb->get_row($q,ARRAY_A);

if ($wpdb->last_error) {
return sprintf(__('Database error: %s.', $this->plugin_slug), $wpdb->last_error);
}

if (isset($row['id'])) {
$id = (int) $row['id'];
}
}

if ($id === NULL) {
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
}

if ($id !== NULL) {
$plugin = H5P_Plugin::get_instance();
$content = $plugin->get_content($id);
Expand Down
8 changes: 6 additions & 2 deletions public/class-h5p-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ public function get_content_settings($content) {
global $wpdb;
$core = $this->get_h5p_instance('core');

$insert_method = get_option('h5p_insert_method', 'id');

$safe_parameters = $core->filterParameters($content);
if (has_action('h5p_alter_filtered_parameters')) {
// Parse the JSON parameters
Expand Down Expand Up @@ -969,15 +971,17 @@ public function get_content_settings($content) {
: ''
);

$identifier = ($insert_method === 'slug' and !empty($content['slug'])) ? 'slug=' . $content['slug'] : 'id=' . $content['id'];

// Add JavaScript settings for this content
$settings = array(
'library' => H5PCore::libraryToString($content['library']),
'jsonContent' => $safe_parameters,
'fullScreen' => $content['library']['fullscreen'],
'exportUrl' => get_option('h5p_export', TRUE) ? $this->get_h5p_url() . '/exports/' . ($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p' : '',
'embedCode' => '<iframe src="' . admin_url('admin-ajax.php?action=h5p_embed&id=' . $content['id']) . '" width=":w" height=":h" frameborder="0" allowfullscreen="allowfullscreen" title="' . esc_attr($title) . '"></iframe>',
'embedCode' => '<iframe src="' . admin_url('admin-ajax.php?action=h5p_embed&' . $identifier) . '" width=":w" height=":h" frameborder="0" allowfullscreen="allowfullscreen" title="' . $title . '"></iframe>',
'resizeCode' => '<script src="' . plugins_url('h5p/h5p-php-library/js/h5p-resizer.js') . '" charset="UTF-8"></script>',
'url' => admin_url('admin-ajax.php?action=h5p_embed&id=' . $content['id']),
'url' => admin_url('admin-ajax.php?action=h5p_embed&' . $identifier),
'title' => $content['title'],
'displayOptions' => $core->getDisplayOptionsForView($content['disable'], $author_id),
'metadata' => $metadata,
Expand Down