PDA

View Full Version : Creating a Visitor Message from external script


Calash
03-01-2011, 11:51 AM
My site bridges eFiction, a story archive software, and vBulletin. The bridge calls global.php to pull session variables and pass this to the eFiction side for authentication.

My current project is to improve upon the review system that eFiction currently has. My though it to leverage the Visitor Message and conversation system to create a more interactive review/response system.

Here is where I am stuck. I have code for creating a forum thread thanks to the article posted here but I cannot find any such guidance for the Visitor Message system. My goal is that on a author reply to a Review it will create a visitor message on the reviewers profile, then add a link to the conversation on the review.

Can anybody guide me in the right direction for creating visitor messages via an external script? Should I just dump the data in the table or is there a better solution?

Calash
03-02-2011, 11:59 AM
I ended up pulling some code from a plugin to get this done by directly dumping the info into the database, then updating the unread vm count for the users. Quick and it works fairly well.

Here is the code if anybody else runs into this.


$vbulletin->db->query_write("INSERT INTO " . TABLE_PREFIX . "visitormessage
(userid, postuserid, dateline, state, pagetext, allowsmilie)
VALUES
('" . $uid . "','" .$reviewerid . "','" . TIMENOW . "','visible','" . $vm_text. "','1')
");

list($unread) = $vbulletin->db->query_first("
SELECT COUNT(*) AS unread
FROM " . TABLE_PREFIX . "visitormessage
WHERE userid = $authoruid AND state = 'visible' AND messageread = 0", DBARRAY_NUM
);

$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET vmunreadcount = " . intval($unread) . "
WHERE userid = $authoruid
");

BirdOPrey5
03-03-2011, 08:15 PM
Very cool of you to share the answer :up: thanks.