Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2022-11-18 08:59:10

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

Re: etc_post: post anything from the public side

Bloke wrote #330395:

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 ;)

Actually, this should be already doable via etc_post/etc_query (or smd_xml) combo:

<txp:etc_post user="guest" event="article" step="save">
{
<txp:etc_query url="your_xml_file_url" markup="xml">
"Section":"articles",
"Status":3,
"publish_now":1,
"Body":{$json_encode({//xpath/of/body/node()})}
</txp:etc_query>
}
</txp:etc_post>

Theoretically, one can import any etc_query-readable data (HTML, XML, JSON, CSV, INI, DB, lists, etc) this way and map it to txp fields.

Offline

#14 2023-01-17 07:35:59

Pemischl
Member
From: Vienna, Austria
Registered: 2012-01-14
Posts: 16
Website

Re: etc_post: post anything from the public side

Pemischl wrote #334143:

Thank you Jakob! It did the trick.

i cheered too early. yesterday i wanted to extend the functionality, but i couldn’t get etc_post to work again (no error message, but articles don’t end up in the database).

the html type form: !https://derbildpunkt.at/files/etc_post/1.png!

the article form: !https://derbildpunkt.at/files/etc_post/2.png!

the rendered page with form: !https://derbildpunkt.at/files/etc_post/3.png!

the unchanged article list: !https://derbildpunkt.at/files/etc_post/4.png!

I have spent hours testing different combinations. do you have an idea what I am doing wrong or could you other examples of etc_post usecases.
Thank you!

Offline

#15 2023-01-17 09:06:40

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

Re: etc_post: post anything from the public side

Let’s start by making sure that <txp:etc_post /> content is in ini format:

Section=program Status=3 publish_now=1

is wrong, it should be

Section=program
Status=3
publish_now=1

Another reason might be that the user pemischl has no recent (6 month?) connection to txp. In this case txp redirects him to login page, and <txp:etc_post /> tries to comply with core behaviour as much as possible, to ensure a future compatibility.

Offline

#16 2023-01-17 19:47:47

Pemischl
Member
From: Vienna, Austria
Registered: 2012-01-14
Posts: 16
Website

Re: etc_post: post anything from the public side

Thank you! The missing linebreaks did the thing.

Offline

#17 2023-01-17 20:27:38

Pemischl
Member
From: Vienna, Austria
Registered: 2012-01-14
Posts: 16
Website

Re: etc_post: post anything from the public side

My next challenge is to change the “Posted” time of a etc_post injected article based on the selection done through a datepicker-input-field. My last (not working) try looks like this.

Form

<txp:etc_post user="pemischl" event="article" step="save" post="Posted, Title, Body, Excerpt, Keywords">
  Section=programm 
  Status=4 
  publish_now=1
</txp:etc_post>
<txp:header name="Location" value='<txp:site_url />' />

Article

<form action="?f=postit" method="post">
<input name="Posted" placeholder="Date" type="date" required="required" /><br />
<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>

Last edited by Pemischl (2023-01-17 20:34:07)

Offline

#18 2023-01-17 21:38:42

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

Re: etc_post: post anything from the public side

Please look here for the full list of valid article post data.

Offline

#19 2023-01-19 07:55:51

Pemischl
Member
From: Vienna, Austria
Registered: 2012-01-14
Posts: 16
Website

Re: etc_post: post anything from the public side

Thanks to etc for the plugin and the hint!
After understanding the plugin, I managed to do it in short time.
Looking into the textpattern core (textpattern/include/txp_article.php) to understand how the article-values are processed, was helpful.

Steps

To insert a custom date I had to:

postit.txp

  • Disable “publish_now = 1” 😔
  • Process year, month, day as input values
  • time (hour, minute, second) are fixed values, so I put them into the ini

Artice form “New Article”

  • select date through an date-input field
  • when changed, extract the values with js and put them into the matching input-fields

Code

html-form postit.txp

<txp:etc_post user="pemischl" event="article" step="save" post="Title, Body, custom_8, Author, Category1, Category2, year, month, day">
  Section=programm 
  Status=4 
  hour=20
  minute=00
  second=00
  Annotate=1
</txp:etc_post>
<txp:header name="Location" value='<txp:site_url />programm/functionality-complete' />

article “Post Article”

<form action="?f=postit" method="post">
    <input name="Title" placeholder="Title"  required="required" /><br />
    <input id="js-date" name="Date"  placeholder="First day of hike" type="date"  required="required" /><br />
    <input id="js-year" name="year" placeholder="Year" /><br />
    <input id="js-month" name="month" placeholder="Month" /><br />
    <input id="js-day" name="day" placeholder="Day" /><br />
    <input type="text" id="js-author" name="Author"><br />
    <select name="Category2">
        <option value="a">A</option>
        <option value="b">B</option>
        <option value="c">C</option>
        <option value="d">D</option>
    </select>
    <input name="custom_8" placeholder="Class Extras" /><br />
    <textarea id="js-body"name="Body" placeholder="Body"></textarea>
    <input type="submit" />
    </form>
    <script>
        const inputDate = document.getElementById('js-date');
        const inputYear = document.getElementById('js-year');
        const inputMonth = document.getElementById('js-month');
        const inputDay = document.getElementById('js-day');
        inputDate.addEventListener('change', function(event){
            let val = event.target.value.replace(/\s.+/,'').split('-');
            inputYear.value = val[0];
            inputMonth.value = val[1];
            inputDay.value = val[2];
        })
    </script>

Todo

I have not managed yet to get a success-page showing a success-message and a link to the posted article or even the article itself.
How do I control the target of etc_post. My tries with with changing the <txp:header /> were not successfull.

Do you have an idea or example where I should look at? Thanks a lot!

Offline

#20 2023-01-19 20:41:42

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

Re: etc_post: post anything from the public side

As you know, etc_post does not alter txp workflow in any way. It just lets you post data from the public to the admin side via a secret door. It can read the answer, but, unfortunately, the latter is badly structured: either a full html admin page or some js code. Extracting what you need is thus cumbersome and beyond the plugin abilities.

But you can try to cheat, retrieving the latest article ID after posting a new (live) article:

<txp:etc_post ... />

<txp:article_custom sort="ID DESC" limit="1">
<txp:header name="Location" value='<txp:permlink' />
<txp:article_custom>

Offline

#21 2023-01-19 21:48:32

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

Re: etc_post: post anything from the public side

Is there any mileage in making this secret door more official and having it return something more parsable? An API, if you will.


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

#22 2023-01-20 13:24:17

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

Re: etc_post: post anything from the public side

Bloke wrote #334542:

Is there any mileage in making this secret door more official and having it return something more parsable? An API, if you will.

We have this… among a hundred of other exciting ideas. Sure, accepting/returning a json(-like) data would be cute, but it’s not a few-liner.

Offline

Board footer

Powered by FluxBB