Enable the use of slug in the embed - #144
Conversation
|
@icc, can you review this or somebody else? |
otacke
left a comment
There was a problem hiding this comment.
Hi! I was made a community maintainer for H5P Group's repositories a few weeks ago, and I am still in the process trying to tackle all the open issues and pull requests.
I am terribly sorry that you have not received a reply before.
So, a late thank you in the name of H5P Group (I am not associated with them though). I'd have some small change requests, see comments. But your code absolutely does what it is supposed to, and it definitely makes sense to add it IMHO.
|
|
||
| if (!empty($slug)) { | ||
| $q=$wpdb->prepare( | ||
| "SELECT id ". |
There was a problem hiding this comment.
Could you please use the formatting of other queries for consistency, see .e.g. https://github.com/katalysteducation/h5p-wordpress-plugin/blob/d9fa94a9b48f7124dab2fd34e7536a563d781730/admin/class-h5p-plugin-admin.php#L791-L798
| '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>', |
There was a problem hiding this comment.
The $title should still be passed through esc_attr to prevent broken HTML from being exploited (to mitigate XSS attacks).
$identifier should be passed through esc_attr as well. I know that the slug will have been processed before anyway, but anything that's user-provided should be sanitized. It's part of automated checks that Automattic runs against plugin code and they will complain about it.
|
|
||
| // Find content | ||
| $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); | ||
| $slug = filter_input(INPUT_GET, 'slug', FILTER_SANITIZE_ADD_SLASHES); |
There was a problem hiding this comment.
Is FILTER_SANITIZE_ADD_SLASHES the right choice here? The $slug is run through $wpdb->prepare later and will be escaped again, won't it? I think that could cause trouble with retrieval. FILTER_SANITIZE_STRING should suffice, right?
Hold the press ... I just checked https://www.php.net/manual/en/filter.constants.php#constant.filter-sanitize-string to be sure and noticed that it has been deprecated. Seems like
$slug = filter_input(INPUT_GET, 'slug', FILTER_DEFAULT, FILTER_FLAG_NO_ENCODE_QUOTES);
would be the way to go here?!
There was a problem hiding this comment.
Or maybe in that way:
$slug = filter_input(INPUT_GET, 'slug', FILTER_VALIDATE_REGEXP, [
'options' => ['regexp' => '/^[a-z0-9-]+$/i']
]);
There was a problem hiding this comment.
That should even work better, yes! I am just nor entirely sure: Can WordPress slugs use underscores, too? If yes, then that would be missing, right?
There was a problem hiding this comment.
Yes, you are absolutely right. Done.
| '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), |
There was a problem hiding this comment.
I think $identifier should also run through esc_attr(), see above.
|
@tomekstach Hope you're still around and interested? |
|
@otacke Best regards, |
|
@tomekstach Thanks for your reply! And there's no reason to hurry, really. This has been dormant for years now - sorry for that again. I'm just following up to learn whether pull requests could be closed meanwhile, because the contributors lost interest. As someone with 100+ open pull requests myself, some dating back to the last decade, I could fully understand. I'll keep the pull request in the "waiting for contributor" column for now then (H5P Open Source Project). Once you're done, this will go to "verified by community maintainer", and then the ball is in H5P Group's court eventually. They hopefully won't require years to empty that column ... |
|
@tomekstach I don't want to push, just set a reminding "ping" after 4 weeks. |
|
@otacke please, review my changes. |
|
Just that one comment about characters used in slugs ... |
otacke
left a comment
There was a problem hiding this comment.
Excellent! I'll move the request to the status "verified by community maintainer" (see https://github.com/orgs/h5p/projects/6/views/7), meaning the pull request is to be picked up by H5P Group once it has been prioritized. Please note, however, that I don't know when they are going to handle this. My powers end here.
Info for H5P GroupThis pull request implements the user story:
|
|
@otacke Thank you so much! |
Insert method option might be used in the embed to get an item by slug or ID.