Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Programmatically create new posts
Avatar
systemguy
Rookie
Free Members
sp_UserOfflineSmall Offline
Dec 17, 2012 - 2:02 pm

Hello,

I have a requirement to create new posts automatically based on data I have stored in a MSSQL database.  I am interested in suggestions on the best way to do this.  

Ideally I would push data directly out my database to Simple:Press.  I have a linked server setup from MSSQL to the SimplePress database and can generally figure out your data structure, however, I assume it's not safe to perform inserts into the SP database directly.  I could not find any docs on sph_post_create or sph_pre_post_create which I assume might help me with the inserts.  

Any suggestions for a path forward would be greatly appreciated.

Thanks,

Mike

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Dec 17, 2012 - 2:11 pm

the hook you reference is fired just prior to us creating a post in the forum...  based on your description, not likely what you want...

I would suggest taking a look at the class we have created for new posts...  simple-press/sp-api/sp-api-class-post.php... sorry, documentation on that not done yet either, though the class stuff is high on the list once we finish the display template functions...

Now, we dont have anything built in to do what you want, but via the api, you could certainly add an interface for doing this...  you could look at the admin bar plugin, the post by email plugin to see how to use that class for creating a forum post...  the latter being how we create a post via email so quite representative...  and of course, we can help walk you through any questions you might have...

Avatar
Shay Michael
Rookie
Free Members
sp_UserOfflineSmall Offline
Nov 25, 2015 - 5:46 am

Hi Mr Papa!

I am also interested in adding new posts and new topics via API. I was not able to find it anywhere. Please give me a clue in this matter. Thanks.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Nov 25, 2015 - 8:12 am

I would take a look at the code in /forum/library/sp-post.php. This is what gets called when a new topic and/or new post gets sent to the server. You can see from this what data items need to be set up before the first validate method is called and how to progress through the stages until completion. The post class itself does all the heavy lifting, data saving, validation, permissions checking and post-save tasks.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Nov 25, 2015 - 5:57 pm

and as mentioned, blog linking, admin bar and post by email plugins would be good example of using the post class to programmatically create a post...

Avatar
Shay Michael
Rookie
Free Members
sp_UserOfflineSmall Offline
Nov 26, 2015 - 2:42 am

Plugins that you have mentioned are paid. So, I do not prefer to purchase another plugin as I have already paid you for the forum/api subscription.

Moreover, /forum/library/sp-post.php seems my target. Do I need to call this file on form post OR what? Please explain a little bit. Thanks.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Nov 26, 2015 - 4:01 am

It could certainly act as the target of a standard html POST form - that is how it is used within the forum. However - your form would still need to use the same named POST variables to pass the necessary values.

To find out those then probably your best approach would be to examine the new topic form itself -

forum/content/forms/sp-form-topic.php

and track down all of the input controls. Obviously for a new topic then there are no key values to pass as they have not yet been created so that is a little easier. If creating posts in an existing topic then you do need to fill the current forum/topic IDs and slugs.

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626