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
Post to forum + detect if they have a post in the forum (If they do, use this post and reply instead of post to forum)
Avatar
Ryan
Member
sp_UserOfflineSmall Offline
Jan 15, 2015 - 5:31 pm

Hey All,

I'm not quite sure how this would work but I'm trying to call the api from a standalone page and do the following:

Check if current user has posted in subforum "autoposts"

If they haven't got a post in that subforum with the title: "Username's Set" then it needs to create a post with that title and post the contents of $postcontents to it.

If they have got a post in that subforum with the title: "Username's Set" then it should reply to that topic with the replies post content being $postcontents.

That's it, pretty simple but I can't work it out, I've found sph_post_create and I've had a look under spFunctions.php but nothing helps :/

Any ideas?

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Jan 15, 2015 - 8:30 pm

not exactly sure what you want to do, but lets try breaking into pieces and build up to it...  so first, how to check if user has posted in forum 'autoposts'...

no api per se, but you can query the db:

sp_forum_api_support(); # lets load some more api stuff
global $spThisUser; # access current user

$data = spdb_query('SELECT * FROM '.SFPOSTS." WHERE user_id=$spThisUser->ID AND forum_id=x"); # replace x with appropriate forum id
if ($data) {
    # user has posted in forum
} else {
    # user has not posted in forum
}

and let me suggest some reading for creating a forum post...  you will want to use our post class..  just instantiate it, fill it with data and submit...

Take a look at the our sp-post.php file in simple-press/forum/library...  will give you example of using the class... or for more focused, smaller example, see

post multiple plugin, file post-multiple/library/sp-post-multiple-components.php around line 104

blog linking plugin, file blog-linking/library/sp-linking-blog.php around line 108

for a couple of examples of plugins we use the post class... there are more too if you search for "= new spPost"

so get started and come on back with any more questions...

Avatar
Ryan
Member
sp_UserOfflineSmall Offline
Jan 15, 2015 - 8:55 pm

Cheers Mr Papa,

That query should help me do what I want to do :)

Is it possible to post to a sub-forum via the api even if they don't have access to the forum, for a logging purpose?

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Jan 15, 2015 - 10:00 pm

requirements checks for pemissions will be in force... you can bypass those by using hooks...  or posting as an admin, then changing the poster after creating it...

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: 649
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 618
Members: 17356
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10122
Posts: 79610