Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-07-11 12:14:23

Saldacenkaw
Member
Registered: 2006-12-28
Posts: 30

Creating and updating articles from JSON source on other website

Hi,

I have a little bit weird and complicated task. One section of our TXP-site should be updated from another website. Do we have any possibilities to create articles and, more important, update its from Json-files that generates in another server?


I know, my english is horrible

Offline

#2 2019-07-11 13:07:58

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,514
Website

Re: Creating and updating articles from JSON source on other website

Do you actually need to update the content of your site from another installation, or would it suffice to simply show information from the other server?

For the latter, you can use rah_swap to temporarily switch the database connection to another database. Then you can either use txp:article to retrieve information from the other installation or smd_query/etc_query to bring in data from a database in another format. That may be enough. I’ve used that before for a firms directory.

etc_query and smd_xml can also retrieve information from another source. In conjunction with smd_query (see example 6 on the smd_xml page) you can put that information into a Textpattern article in your target installation.

The same principle could be used with json I guess. As far as I remember etc_query will read json for you. For outputting a json feed, you can simply use the regular textpattern tags to output the json in the desired format. Place that code in a page template or form and use txp_header to make it output the correct Content-Type for json. Then assign your page template to your desired feed url.

Remember, you need to be very diligent about sanitizing data from an external source before you insert it into the database, or you run the risk of making your site vulnerable.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2019-07-11 20:18:03

Saldacenkaw
Member
Registered: 2006-12-28
Posts: 30

Re: Creating and updating articles from JSON source on other website

Jakob, thank you!

It’s kind of weird scheme, but I need to update one section on TXP-website from another website (it working on custom php-solution). From that website, we’ll create\update articles with specific custom fields\excertp and title. I’m trying to understand how to do it, looks like etc_query is a good solution.


I know, my english is horrible

Offline

#4 2019-07-12 08:04:14

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,514
Website

Re: Creating and updating articles from JSON source on other website

Thanks for the feedback. Would you be able to document how you achieve it as I can imagine it could be of interest to other people. If you need assistance with correcting your English, we can help with that. Maybe we can abstract the solution and make a textpattern.tip out of it…


TXP Builders – finely-crafted code, design and txp

Offline

#5 2019-07-15 08:21:12

Saldacenkaw
Member
Registered: 2006-12-28
Posts: 30

Re: Creating and updating articles from JSON source on other website

it’s good idea! i’ll be back when solution will be ready


I know, my english is horrible

Offline

#6 2019-07-27 10:52:45

Saldacenkaw
Member
Registered: 2006-12-28
Posts: 30

Re: Creating and updating articles from JSON source on other website

All our pains have been failed. Etc_query is a good plugin, but we coudn’t sync all section and articles inside it. Thereby we are developing our own custom solution without txp. unfortunately I can’t share any positive case :(


I know, my english is horrible

Offline

Board footer

Powered by FluxBB