Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-10 19:42:01

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Callback to alter article html before saving

My “authors” often import their articles from some Office application, royally ignoring Textile, TinyMCE and whatever else. The result is fubar. There is nothing I can do about it, except cleaning articles html. Would it be possible to add a callback that allows for Body_html/Excerpt_html modification right before article save?

Edit: actually, all article fields should be modifiable before save.

Last edited by etc (2012-10-18 10:42:34)

Offline

#2 2012-10-18 11:00:17

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Callback to alter article html before saving

In Textpattern 4.6 we will introduce textfilters which essentially define how raw text is translated into the final HTML. This callback textfilter / filter exists in the latest development version.

See wet_sample_textfilter_postprocessor for a sample plugin.

Offline

#3 2012-10-18 12:58:46

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: Callback to alter article html before saving

Very cute, thank you, Robert, will play with it! Will it be called only for Body and Excerpt, or in some other contexts too?

Since heavens have heard me, I would also like to have access to the whole article array at once, for example, to be able to auto-extract and save Keywords from the Body. Would article_ui callback allow for such alteration? Why $rs is passed by reference to callback_event_ref, but by value to article_validate?

Offline

#4 2012-10-18 13:59:04

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Callback to alter article html before saving

etc wrote:

Will it be called only for Body and Excerpt, or in some other contexts too?

We apply filters to the excerpt and the body and nowhere else. Look into textile_main_fields() in txp_article.php. Since this is very new code we do not have much documentation around besides the actual code. It might also change slightly until the final release.

I would also like to have access to the whole article array at once, for example, to be able to auto-extract and save Keywords from the Body.

You might want to look into article partials and how Textpattern uses AJAX on the article tab. Here’s a sample plugin. I’ve written a bit about article partials here.

Offline

#5 2012-10-18 14:15:47

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: Callback to alter article html before saving

Exciting, thank you very much!

Offline

Board footer

Powered by FluxBB