Forum Activity for @tig

TiG
@tig
04/28/20 09:18:54AM
184 posts

Fixing Errant HTML Content


Jamroom Developers

Brian

jrCore_clean_html($malformed_html);


I did try this function before writing my original post and found that its algorithm for closing tags basically closes them at the end. In my case, I have an unclosed div right in the middle of the HTML. The semantic effect of this unclosed div is to cause the main section of the article to be incorrectly enclosed within an aside block. This is how DOMDocument perceives this flaw and it is also how the clean_html resolves the unclosed tag. (My logic already makes heavy use of DOMDocument.) Since I prune off all aside blocks, this malformed HTML causes the article content (in this case) to be tossed along with the asides.

I can write a routine to fix the HTML as needed, but that seems like reinventing the wheel. Ergo my question about being able to install the Tidy extension to PHP. Tidy claims to have this problem solved.

On another note, I will absolutely switch to
jrUrlScan_get_url_with_wget()
since I have experienced the ill effects of being viewed as a mere bot. So that promises to help substantially.

Thanks yet again to you and Michael for the great info.
TiG
@tig
04/27/20 09:20:56PM
184 posts

Fixing Errant HTML Content


Jamroom Developers

Michael

You have guessed correctly. We are acquiring content from a URL provided by the user and populating articles (e.g. discussions and group discussions). The user then will do some editing, add their own commentary and publish to the NT site for comments.

Tidy is an installed PHP extension:
 https://www.php.net/manual/en/book.tidy.php 

There likely is a reason it was not opted to be installed (HTML Purifier makes use of it when installed). Maybe Brian will weigh in since I think we are moving into his area of focus.

Thanks
TiG
@tig
04/27/20 08:45:15PM
184 posts

Fixing Errant HTML Content


Jamroom Developers

Michael

I have already investigated that functionality. The HTML tag closing is what I described, it works if the closing can be accomplished by simply adding closing tags to the end. In arbitrary HTML that is typically not sufficient - the errant tags are within the document.

We might be unique in the Jamroom community in our use of HTML, but if you folks ever consider installing Tidy functionality we would make use of it. :)

Thanks!
TiG
@tig
04/27/20 07:58:30PM
184 posts

Fixing Errant HTML Content


Jamroom Developers

We are coming across bad content from various sites. This is HTML that is technically wrong - in particular missing end tags. An ideal PHP solution would be to tap into Tidy functionality but that does not seem to be installed. The existing JR functions such as jrCore_closetags() are only good for small fragments where adding tags to the end is semantically correct.

Our problem deals with the raw content of an arbitrary web-page captured via cURL. We are making extensive use of HTMLPurifier but there seems to be no JR-resident function available to configure HTMLPurifier to deal with unclosed tags. DOMDocument, by the way, parses the incorrect HTML and produces an incorrect DOM; so it does not help here.

My question: is there a way within the Jamroom platform to correctly fix unclosed HTML tags in an arbitrary (and typically large) string of HTML?

Thanks
updated by @tig: 07/29/20 05:09:32PM
TiG
@tig
04/13/20 07:39:20PM
184 posts

Javascript Form Message


Jamroom Developers

Michael

All good. That is the info I was asking for. I just do not want to reinvent the wheel (of course).

As always, much appreciated.

TiG
TiG
@tig
04/13/20 04:23:10PM
184 posts

Javascript Form Message


Jamroom Developers

Michael

Here is what I created in lieu of an existing function:

/**
 * Set the contents of the argument form message_id to message as an error or success
 * @param {string}  message_id - the HTML id of the element containing the message
 * @param {string}  message - the HTML to include as the message
 * @param {boolean} error - if true, mark this as an error message
 */
function ntCore_set_form_message(message_id, message, error){
    var selector = '#'+message_id;

    if ($(selector).length)                                             // ensure message_id element exists
    {
        if (typeof error === 'undefined' || error == false)
                $(selector).html(message).removeClass('error').show();
        else $(selector).html(message).addClass('error').show();
    }
}

This of course works fine, but it is based on knowing that the 'error' class is used for severity and the caller must know the exact HTML id of the form element that contains the message. What I would prefer to use is a function like jrFormMessages() but nobody seems to use it and it does not appear to work. Ideally the Javascript client simply calls a function to display a message on the designated message area of a form but is not bound to the exact ID and specific class behavior.

What I have works fine, but I always like to check to see if there is a more future-proof method in cases like this.

Thanks,
TiG
TiG
@tig
04/13/20 10:18:08AM
184 posts

Javascript Form Message


Jamroom Developers

I have a need to set messages in a form via a Javascript function. While it is easy enough to directly address the message area using the id of
id="{$form_name}_msg"
this seems like a hack.

I cannot seem to find a suitable Jamroom javascript function that will set/clear the message. Does one exist? If not, what would be a recommended future-proof method to set the form message via javascript? (Note: there is no server interaction here.)
updated by @tig: 07/14/20 04:26:03AM
TiG
@tig
03/28/20 07:53:30AM
184 posts

Downloading web image directly into a media file


Jamroom Developers

Michael

jrUrlScan_save_url_image() is a perfect exemplar for what I need to build.

Thanks for saving me a ton of research time!
TiG
@tig
03/27/20 08:51:30PM
184 posts

Downloading web image directly into a media file


Jamroom Developers

Looking for guidance to avoid doing this any number of wrong ways.

What we would like to do is give our users the ability to fetch the contents of an article from a webpage and use same to engage in discussion. Transferring the content of the article is clear (albeit complex), but the proper way to transfer the image is not clear. Rather than have the user manually download an image to their local machine and then upload into the article using the Image SELECT button, we want to simply pull the image (from a url we have parsed from the content) and directly save the image as an appropriate media file.

The end result would be the same - an image media file properly linked to the article in Jamroom style - but the user would not even know what took place.

My question of course is how to best accomplish this in Jamroom. What is a future-safe practice for storing an image pulled from the web via a url into a Jamroom media file for ongoing use with an article (discussion or group discussion)?

Thanks.
updated by @tig: 06/28/20 10:13:06AM
TiG
@tig
01/22/20 11:47:58AM
184 posts

Max-width for img tags


Jamroom Developers

Thanks for responding Nate.

CSS for presentation would indeed work as a fix. I will probably resort to that if there is no way to more surgically (i.e. acting only when necessary) address the problem in the stored content. My preference is to prevent max-width from being filtered out so that I can programmatically inject it where necessary (selectively).

As a side point, max-width:100% is legal and accomplishes exactly what I seek.

Thanks.
  4