Undefined variable in oembed.php
Posted
#3724
(In Topic #743)
Undefined variable: format_in_path in sources/hooks/systems/media_rendering/oembed.php on line 133
Greetings,On a newer install with not much content I somehow have crashed the system with an error code of :
in ADMIN area: PHP NOTICE [8] Undefined variable: format_in_path in sources/hooks/systems/media_rendering/oembed.php on line 133 (version: 10.0.12, PHP version: 7.2.1-1+ubuntu16.04.1+deb.sury.org+1, URL: /adminzone/index.php?page=admin-cleanup&type=rebuild)
main page:
PHP NOTICE [8] Undefined variable: format_in_path in sources/hooks/systems/media_rendering/oembed.php on line 133 (version: 10.0.12, PHP version: 7.2.1-1+ubuntu16.04.1+deb.sury.org+1, URL: /index.php?page=start)
History:
1. I had posted a few links to facebook pages and was surprised that the oembed did not work as usual. I ignored it and wanted to investigate in the future.
2. Today I posted a new news item with a FB link and the system crashed. I deleted that news article.
3. I am attempting to delete the sole news article but no luck.
Since this is a new install with no content I can just restart fresh but wanted to share this as maybe it is a bug or something on my end.
Thanks much
Stevyn
Posted
Anyway, re-uploading that file should fix the error.
Posted
I downloaded the latest zip and uploaded all files to be safe. Then cleared the caches and ran file integrity check and all checks out as good. I also did a check on the database and it says each table is OK.
I still have the error as you can see at (link removed by stevyn)
Should I post the full error report? (seen only when admin is logged in?
Thank you
Stevyn
PS: this is super low priority since the site is newish, I could just replace the database and start with a new database? or purge the news in the database?
Last edit: by ironfeather
Posted
If you'd like me to debug on the server itself, please send FTP access to [email protected].
I'd like to track it down.
Posted
I should mention more details
1. I had a few news articles and some had FB links
2. Under the news I edited the inner zone page and added two FB links and for a few days they worked normally, the composr oembed would display them as they should (expanded FB feed) then suddenly it didnt work and were simply just links again.
3. I was not sure why they didnt work so I left them alone but edit the zone editor again and this time manually embedded the HTML from facebook to display a feed. THis worked but the normal links stayed as links
4. I posted a new news article and in the new article had a new facebook link, thehn everything went haywire as we see now.
Could the manual useage of FB embed screw it up?
Thanks for helping
Stevyn
PS* I emailed you access info. Thank you
Posted
Posted
It's fixed now, but it's definitely a bug in a PHP extension or PHP itself. Most likely Zend OpCache, which I think is undefining a variable we are using because it incorrectly thinks it won't be used again. But your server also has a couple of non-official PHP extensions which could also potentially be causing some memory corruption (msgpack, igbinary). I can't say for sure the cause.
I worked around it by rearranging the code. Arguably my rearrangement is a bit cleaner, so I don't mind doing that.
For reference here is the change I made…
Code (Diff)
diff --git a/sources/hooks/systems/media_rendering/oembed.php b/sources/hooks/systems/media_rendering/oembed.php
index 3eabb3274..6e6763fd1 100644
--- a/sources/hooks/systems/media_rendering/oembed.php
+++ b/sources/hooks/systems/media_rendering/oembed.php
@@ -112,11 +112,6 @@ class Hook_media_rendering_oembed extends Media_renderer_with_fallback
}
// Work out the full endpoint URL to call
- $format_in_path = (strpos($endpoint, '{format}') !== false);
- $preferred_format = 'json';
- if ($format_in_path) {
- $endpoint = str_replace('{format}', $preferred_format, $endpoint);
- }
if (strpos($endpoint, '?') === false) {
$endpoint .= '?url=' . urlencode($url);
} else {
@@ -130,7 +125,11 @@ class Hook_media_rendering_oembed extends Media_renderer_with_fallback
if ((!array_key_exists('height', $attributes)) || ($attributes['height'] != '')) {
$endpoint .= '&maxheight=' . urlencode(array_key_exists('height', $attributes) ? $attributes['height'] : get_option('oembed_max_size'));
}
- if (!$format_in_path) {
+ $format_in_path = (strpos($endpoint, '{format}') !== false);
+ $preferred_format = 'json';
+ if ($format_in_path) {
+ $endpoint = str_replace('{format}', $preferred_format, $endpoint);
+ } else {
if (strpos($endpoint, '&format=') === false) {
$endpoint .= '&format=' . urlencode($preferred_format);
}
index 3eabb3274..6e6763fd1 100644
--- a/sources/hooks/systems/media_rendering/oembed.php
+++ b/sources/hooks/systems/media_rendering/oembed.php
@@ -112,11 +112,6 @@ class Hook_media_rendering_oembed extends Media_renderer_with_fallback
}
// Work out the full endpoint URL to call
- $format_in_path = (strpos($endpoint, '{format}') !== false);
- $preferred_format = 'json';
- if ($format_in_path) {
- $endpoint = str_replace('{format}', $preferred_format, $endpoint);
- }
if (strpos($endpoint, '?') === false) {
$endpoint .= '?url=' . urlencode($url);
} else {
@@ -130,7 +125,11 @@ class Hook_media_rendering_oembed extends Media_renderer_with_fallback
if ((!array_key_exists('height', $attributes)) || ($attributes['height'] != '')) {
$endpoint .= '&maxheight=' . urlencode(array_key_exists('height', $attributes) ? $attributes['height'] : get_option('oembed_max_size'));
}
- if (!$format_in_path) {
+ $format_in_path = (strpos($endpoint, '{format}') !== false);
+ $preferred_format = 'json';
+ if ($format_in_path) {
+ $endpoint = str_replace('{format}', $preferred_format, $endpoint);
+ } else {
if (strpos($endpoint, '&format=') === false) {
$endpoint .= '&format=' . urlencode($preferred_format);
}
I also noticed a simpler change worked, changing $format_in_path = (strpos($endpoint, '{format}') !== false); to $format_in_path = (strpos($endpoint, '{format}') !== false) && true;, but that was messy, I didn't like it (or understand why it could fix it).
Last edit: by Chris Graham
Posted
Ideally in a situation like this I'd isolate the issue down to a test case to report to PHP. However, I tried and failed to do that, so it must have been a somewhat complex issue, e.g. the optimizer kicking in after multiple calls into the code. Almost certainly someone will find and fix it in due to time though.
Posted
The site is back up and I am excited to continue working on it.
Thanks again, you rock!
Stevyn
Posted
I just upgraded from 12 to 13 and was surprised to see that the oembed didnt work. So did a file integrity check and got:
These files do not match the ones bundled with your version, but claim to be newer (so these might be bug fixes someone has put here):
sources/hooks/systems/media_rendering/oembed.php
which is the fix you did…. so i removed it and uploaded the newer oembed.php from the latest 13 version and still no luck sadly…
Not sure what has happened
Posted
Is it the same error message, "Undefined variable: format_in_path in sources/hooks/systems/media_rendering/oembed.php"?
Likely what has happened is that because other PHP code has changed, whatever weird PHP bug is happening has shifted. It could be some kind of memory overwrite issue in PHP, or something to do with a PHP optimiser extension, and those kinds of things are very unpredictable.
I am happy to look again. If you can get a URL for me to test case that would help (e.g. to a news post or something where this is showing). Feel free to email me.
Posted
It works fine on my main site (different server) and none else are posting about it so I think the server I setup has some php problems.... I will try and remove all php and install fresh and see if that will fix it.
Will report back
Thank you for the help, really appreciate it.
0 guests and 0 members have recently viewed this.
