How do I post a comment using an external php script in vanilla?
I have a script written with this code to get the vanilla session and user into it:
http://vanillaforums.org/discussion/comment/141122/#Comment_141122
But now I want to use that script to add a comment to a discussion, kind of like an automated reply script.
I think this would have something to do with applications/vanilla/models/class.commentmodel.php and public function Save($FormPostValues), but I simply have no idea how I would use this from an external script like that.
define('APPLICATION', 'Vanilla');
define('APPLICATION_VERSION', '2.0.16');
define('DS', '/');
define('PATH_ROOT', '/var/www/html/testsite');
ob_start();
require_once(PATH_ROOT.DS.'bootstrap.php');
ob_end_clean(); // clear any header output from vanila
$Session = Gdn::Session();
$Authenticator = Gdn::Authenticator();
$poster = 23; //Post as this user
$discussion = 12; //Discussion where to post in
$message = "Hey everybody! This is a test." //Comment content
//what now?
Comments
You just need to POST the form values for the
/post/comment
page.You will need to POST the transient key as well (
Gdn::Session()->TransientKey()
)Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Why not use an API?
http://vanillaforums.org/addon/api-application
Also why does it have to be external? You could create a plugin that responds to posts, like a bot.
grep is your friend.
https://github.com/lincolnwebs/Glue/blob/master/wp-content/plugins/glue/vanilla.php
https://github.com/lincolnwebs/Glue/blob/master/wp-content/plugins/glue/glue.php#L121-L138
Uncomment the SpamCheck = FALSE line, too.