For reasons unknown, after a migration to another domain on the same server (same PHP version and everything), I started receiving this warning 4 times on my Timeline embedded:
Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 1 in views_timelinejs_plugin_style_timelinejs->extract_url() (line 596 of /sites/all/modules/views_timelinejs/views_timelinejs_plugin_style_timelinejs.inc).
I first tried making sure any of my special fields with URL's didn't have any special characters, e.g. & vs. & but that didn't seem to fix it. I was able to evaporate the warning by adding two lines into this views_timelinejs_plugin_style_timelinejs.inc function:
/**
* Searches a string for HTML attributes that contain URLs and returns them.
*
* This will search a string which is presumed to contain HTML for anchor or
* image tags. It will return the href or src attribute of the first one it
* finds.
*
* This is basically special handling for core Image fields. There is no
* built-in field formatter for outputting a raw URL from an image. This
* method allows image fields to "just work" as sources for TimelineJS media
* and background image URLs. Anchor tag handling was added for people who
* forget to output link fields as plain text URLs.
*
* @param string $html
* A string that contains HTML.
*
* @return string
* A URL if one was found in the input string, the original string if not.
*/
protected function extract_url($html) {
if (!empty($html)) {
$document = new DOMDocument();
$internalErrors = libxml_use_internal_errors(true); // <------ #1
$document->loadHTML($html);
libxml_use_internal_errors($internalErrors); // <------- #2
// Check for anchor tags.
$anchor_tags = $document->getElementsByTagName('a');
if ($anchor_tags->length) {
return $anchor_tags->item(0)->getAttribute('href');
}
// Check for image tags.
$image_tags = $document->getElementsByTagName('img');
if ($image_tags->length) {
return $image_tags->item(0)->getAttribute('src');
}
}
return $html;
}
Source of the solution at this StackOverflow post:
http://stackoverflow.com/questions/1685277
Again, I don't know why this error started happening but wanted to report this in case it would be useful for others, or if it would possibly help to be committed.
Cheers
Comments
Comment #2
ownage commentedComment #3
dcam commentedAre you working with the latest dev build, the one from July 26? Also, if you are using it do you have the Thumbnail field mapped?
Comment #4
ownage commenteddcam, nope to both questions. I am using 7.x-3.0-beta2.
Comment #5
dcam commentedI've given this issue some thought and I'm not comfortable simply suppressing the errors. That's usually regarded as not being a good practice. The errors probably need to be handled by the application so that they can generate more meaningful messages, perhaps even telling you which output row has the issue.
It would help to have samples of the input that is causing the problem, if you could provide it. I could mock up some HTML that generates the same warning, but I'd rather know what specifically is causing it in a real world situation. You could probably insert this code:
into the function in order to see what HTML is causing the issue. You would have to remove your error-suppression lines too.
Comment #6
ownage commentedJust a quick update: I haven't forgot about this but have been buried with other crap lately. Will get back when able!
Comment #9
dcam commentedI've updated the plugin so that it will properly handle these errors. I still don't think that it's a good idea to just make them disappear. Instead of that, Drupal warning messages will be issued. They will include specific information about the problem including the result row that has the error, the error message, and the HTML that has the problem.