Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-06-07 12:53:54

etc
Developer
Registered: 2010-11-11
Posts: 4,331
Website GitHub

etc_post: post anything from the public side

Have you ever needed to edit some txp data (articles, users, etc) on the public side, or even import them automatically from external sources? Then welcome etc_post!

It registers <txp:etc_post /> tag that serves as entry point to the admin side. To give an example, suppose we want to allow the site visitors to submit draft articles in articles section.

  • Create a Freelancer user, say guest.
  • Create an article or rather a custom HTML-type form, say postit:
<txp:etc_post user="guest" event="article" step="save" post="Title, Body, Excerpt, Keywords">
Section=articles
Status=3
publish_now=1
</txp:etc_post>
<txp:header name="Location" value='<txp:site_url />' />
  • Create an article (or even a static web page) with a HTML form like
<form action="?f=postit" method="post">
<input name="Title" placeholder="Title" required="required" /><br />
<input name="Keywords" placeholder="Keywords" /><br />
<textarea name="Body" placeholder="Body"></textarea>
<textarea name="Excerpt" placeholder="Excerpt"></textarea>
<input type="submit" />
</form>

Now everyone can use it to submit draft articles under guest account. Which means use it with much caution :-)

You can also send this form data to ?f=postit via some automated script. And you are not limited to article posting, unlike with some specialized plugins. It suffices to change event and step attributes to trigger any (core or plugin) admin-side action (upload an image, register a new user, etc). The plugin does not write directly to db, but uses the standard txp workflow instead. Enjoy!

Homepage and download.

Offline

#2 2021-06-07 14:20:40

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,387
Website GitHub

Re: etc_post: post anything from the public side

This is simply insane. Love it! Thank you. This is the basis of an import plugin we need since we axed the core feature a few versions ago.

Could the plugin support (hook into?) the Import/TxpXML so we could also import XML files from other CMSs via your plugin?

Or how about CSV somehow one day? Y’know, for completeness ;)

Since it’s event/step based, I guess there’s nothing to stop a companion plugin opening up a new panel on the back-end with a browse… button. Pick file(s) to import – CSV, XML, JSON, INI, … – pick a pre-defined template from a set in your Forms arsenal to squirt the incoming data through (maybe ones with a prefix defined in the plugin’s prefs so there’s some control over which ones are used?) and the data is transmogrified from the input to Txp table data, thrown at your pluign to insert.

Essentially, it’d treat the incoming data stream as a set of delimted records. Pluck out the fields from each record named in the Form, DB-safe them and insert. Repeat. That would neatly handle data mapping too.

And there’s nothing to stop such a companion plugin from offering ‘transforms’ for each chosen field. e.g. split an incoming field into two components, destined for two database columns; combine two or more fields into one database field; pass a field through a textfilter; …

:)

The only thing that would make this even more super awesome would be to insert into more than one table at once. e.g. if someone was to add an image browser, image category and caption fields to an input form (or data stream) then the image would be uploaded, imported, and assigned via ID to the article_image in one step.

That might be a stage too far though as the event/step nature of the plugin would be violated. No biggie to have two panels – one for images, one for articles – and import them separately. The linking would need to be done by hand though.

Or, as I implied above, write a dedicated companion plugin and hook your plugin into its event/step. That way, it could call your plugin multiple times for each incoming file type.

Extremely flexible possibilities!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2021-06-07 15:02:51

gaekwad
Multi-hyphenate
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,559
GitHub

Re: etc_post: post anything from the public side

Woah.

Offline

#4 2021-06-07 15:43:12

etc
Developer
Registered: 2010-11-11
Posts: 4,331
Website GitHub

Re: etc_post: post anything from the public side

Thank you, but this plugin is actually too basic to do something by itself. It just posts the supplied data to the admin side, pretending it’s a logged-in user action. As for the data itself, no mapping is done, one needs to provide the exact fields that event/step can handle.

Dunno how it might evolute, but it’s current role is simply to allow for a custom public interface to the admin side.

Bloke wrote #330395:

That might be a stage too far though as the event/step nature of the plugin would be violated.

True, more sophisticated admin-side plugins often make use of JS for data association, and that’s beyond of etc_post abilities, since it acts on the public side.

Or, as I implied above, write a dedicated companion plugin and hook your plugin into its event/step.

That’s actually as companion plugin that etc_post was born :-)

Offline

#5 2021-06-07 15:55:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,387
Website GitHub

Re: etc_post: post anything from the public side

Ha, I forgot about etc_import! I’ll get back in my box.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2021-06-08 16:30:08

etc
Developer
Registered: 2010-11-11
Posts: 4,331
Website GitHub

Re: etc_post: post anything from the public side

Version 0.3 supports CSV format (for completeness, thanks Stef) and requires <txp:php /> privileges (you really shouldn’t put it in anyone’s hands).

BTW, if your favourite text editor supports http posting on save, just create a secret <txp:etc_post /> backdoor, and flat edit you go.

Offline

#7 2021-06-15 18:27:30

Myusername
Member
Registered: 2019-12-12
Posts: 110

Re: etc_post: post anything from the public side

I would like to add some sections, but I was unsuccessful. Can anyone show me how to do this?

Offline

#8 2021-06-15 19:48:31

etc
Developer
Registered: 2010-11-11
Posts: 4,331
Website GitHub

Re: etc_post: post anything from the public side

Myusername wrote #330490:

I would like to add some sections, but I was unsuccessful.

Can you tell us what have you tried?

Offline

Board footer

Powered by FluxBB