Status
Not open for further replies.
We should all know what the post thank you hack is by now so moving on..

I was trying to create an addon that would post a notification when someone pushes the "thanks" button. Anyway been working on this all morning, and currently stuck at getting the code to give me the thread title.

This is what I've done so far:

Added Phrase for notification:

name: dbtech_vbshout_notif_thanks
type: global
product: vbShout
text: has given thanks to {1} for their post in {2}!

Next I added a plugin to require the php file:

Product: vBshout
Hook Location: post_thanks_function_add_thanks_end
Title: Notification: Post Thanks
Execution Order: 5
Plugin PHP Code:
PHP:
require(DIR . '/dbtech/vbshout/includes/hooks/newthanks_complete.php');

Then I created newthanks_complete.php and placed it in the location above and this is the context:
PHP:
<?php
if (
	!$vbulletin->userinfo['dbtech_vbshout_banned']
)
	{
	if ($vbulletin->options['dbtech_vbshout_allowed_bbcode'] & 64)
	{
		// We can use BBCode
		$usern = $postinfo[username];
		//lets get thread title
		$findit = $vbulletin->db->query_read("
		SELECT title
		FROM ". TABLE_PREFIX ."thread
		WHERE threadid = " . $postinfo['threadid'] . "
		");
		$threadtitle = $findit['title'];
		$notif = '[post=' . $postinfo['postid'] . ']' . $threadtitle . '[/post]';
	}
	else
	{
		// We can't, so don't even bother
		$notif = $threadinfo['title'];
	}
	
	// Insert the notification
	$vbulletin->db->query_write("
		INSERT INTO " . TABLE_PREFIX . "dbtech_vbshout_shout
			(userid, dateline, message, type, notification)
		VALUES (
			" . $vbulletin->userinfo['userid'] . ",
			" . TIMENOW . ",
			'" . $vbulletin->db->escape_string(
				construct_phrase(
					$vbphrase["dbtech_vbshout_notif_thanks"],
					$usern,
					unhtmlspecialchars($notif)
				) . "',
			8,
			'thanks'
		)
	");
	
	// Get the shout id
	$shoutid = $vbulletin->db->insert_id();
	
	($hook = vBulletinHook::fetch_hook('dbtech_vbshout_shout_notification')) ? eval($hook) : false;
	
	// Set the latest AOP time
	switch ($vbulletin->options['dbtech_vbshout_optimisation'])
	{
		case 1:
			// File system
			touch(DIR . '/dbtech/vbshout/aop.php');
			break;
			
		case 2:// Database
			$vbulletin->db->query_write("
				UPDATE " . TABLE_PREFIX . "datastore
				SET data = IF(data < " . TIMENOW . ", " . TIMENOW . ", data)
				WHERE title = 'dbtech_vbshout_aoptime'
			");

			break;
	}
}
?>

I can get the threadid to showup using post['threadid']... but cant get it to tell me the title... wish there was a way...

BTW: I did add 'thanks' to the notification column on the database, so thats not it.
 
In your $findit query, change query_read() to query_first(), since you're expecting a result of 1 row that will fetch it, query_read() is expected to be followed by fetch_array() or other similar methods to return multiple rows. That should resolve the title issue, however keep in mind your condition for BBCode means it'll execute the query to fetch the title if BBCode is allowed but won't do the query if it's not - so the query should be outside of that condition.

Also, unless I haven't woken up properly, there seems to be a bracket missing:
PHP:
    // Insert the notification
    $vbulletin->db->query_write("
        INSERT INTO " . TABLE_PREFIX . "dbtech_vbshout_shout
            (userid, dateline, message, type, notification)
        VALUES (
            " . $vbulletin->userinfo['userid'] . ",
            " . TIMENOW . ",
            '" . $vbulletin->db->escape_string(
                construct_phrase(
                    $vbphrase["dbtech_vbshout_notif_thanks"],
                    $usern,
                    unhtmlspecialchars($notif)
                ) . "',
            8,
            'thanks'
        )
    ");

Take a look at escape_string()/construct_phrase() there. You'll see the construct_phrase has its closing parenthesis, but not escape_string (maybe it was a copy/paste issue when you made the post :)).

Hope that helps.
 
We're also looking into doing our own version of the Post Thank You Hack, if we can make it different enough to justify it. It's certainly the most requested new mod on this forum!

If we were to "finish" this, would you allow us to release it on vBulletin.org? You would of course be given full credit with a link back to a website of choice (so long as it doesn't violate vBulletin.org's rules - i.e. a porn site or something :p)
 
Yeh you can release it if you would like... all I ask is just in the credit somewhere put my account name which links to my account profile on vb.org which is DJ29Joesph. Other then that your free to do as u please with it :)

I'm going to try what Deceptor stated and will get back to you..

EDIT: Yes the escape_string was a copy/paste issue... should be:

PHP:
// Insert the notification
	$vbulletin->db->query_write("
		INSERT INTO " . TABLE_PREFIX . "dbtech_vbshout_shout
			(userid, dateline, message, type, notification)
		VALUES (
			" . $vbulletin->userinfo['userid'] . ",
			" . TIMENOW . ",
			'" . $vbulletin->db->escape_string(
				construct_phrase(
					$vbphrase["dbtech_vbshout_notif_thanks"],
					$usern,
					$postinfo['threadid']
					)
				) . "',
			8,
			'thanks'
		)
	");
 
Last edited:
Well the good news is the query works, now just to get the whole thing...

What I have so far:
PHP:
<?php
if (
	!$vbulletin->userinfo['dbtech_vbshout_banned']
)
	{
	if ($vbulletin->options['dbtech_vbshout_allowed_bbcode'] & 64)
	{
		// We can use BBCode
		$notif = '[post=' . $postinfo['postid'] . ']' . $findit . '[/post]';
	}
	else
	{
		// We can't, so don't even bother
		$notif = $threadinfo['title'];
	}
	$usern = $postinfo[username];
	//lets get thread title
	$findit = $vbulletin->db->query_first("
		SELECT title
		FROM ". TABLE_PREFIX ."thread
		WHERE threadid = " . $postinfo['threadid'] . "
	");
	// Insert the notification
	$vbulletin->db->query_write("
		INSERT INTO " . TABLE_PREFIX . "dbtech_vbshout_shout
			(userid, dateline, message, type, notification)
		VALUES (
			" . $vbulletin->userinfo['userid'] . ",
			" . TIMENOW . ",
			'" . $vbulletin->db->escape_string(
				construct_phrase(
					$vbphrase["dbtech_vbshout_notif_thanks"],
					$usern,
					$notif
					)
				) . "',
			8,
			'thanks'
		)
	");
	
	// Get the shout id
	$shoutid = $vbulletin->db->insert_id();
	
	($hook = vBulletinHook::fetch_hook('dbtech_vbshout_shout_notification')) ? eval($hook) : false;
	
	// Set the latest AOP time
	switch ($vbulletin->options['dbtech_vbshout_optimisation'])
	{
		case 1:
			// File system
			touch(DIR . '/dbtech/vbshout/aop.php');
			break;
			
		case 2:// Database
			$vbulletin->db->query_write("
				UPDATE " . TABLE_PREFIX . "datastore
				SET data = IF(data < " . TIMENOW . ", " . TIMENOW . ", data)
				WHERE title = 'dbtech_vbshout_aoptime'
			");

			break;
	}
}
?>

In the database.. it shows this after giving thanks
has given thanks to Cold Person for their post in https://xf2.dragonbyte-tech.com/posts/12530/!

but I got to get to sleep.. I have have to get up for work in 4 hours... I'll check back up on this around 3:00 PM EST

Also with the query_first syntax.. do I need to do ' . $findit['title'] . ' or am I just good with ' . $findit . '?

Sorry for double post
 
Last edited:
You're executing the query after you've defined $notif. $notif can't use $findit before it's defined. Should be more like this (assuming the query is even required, I haven't checked):

PHP:
<?php
if (
    !$vbulletin->userinfo['dbtech_vbshout_banned']
)
    {
    //lets get thread title
    $findit = $vbulletin->db->query_first("
        SELECT title
        FROM ". TABLE_PREFIX ."thread
        WHERE threadid = " . $postinfo['threadid'] . "
    ");

    if ($vbulletin->options['dbtech_vbshout_allowed_bbcode'] & 64)
    {
        // We can use BBCode
        $notif = '[post=' . $postinfo['postid'] . ']' . $findit['title'] . '[/post]';
    }
    else
    {
        // We can't, so don't even bother
        $notif = $findit['title'];
    }
    $usern = $postinfo[username];

    // Insert the notification
    $vbulletin->db->query_write("
        INSERT INTO " . TABLE_PREFIX . "dbtech_vbshout_shout
            (userid, dateline, message, type, notification)
        VALUES (
            " . $vbulletin->userinfo['userid'] . ",
            " . TIMENOW . ",
            '" . $vbulletin->db->escape_string(
                construct_phrase(
                    $vbphrase["dbtech_vbshout_notif_thanks"],
                    $usern,
                    $notif
                    )
                ) . "',
            8,
            'thanks'
        )
    ");
    
    // Get the shout id
    $shoutid = $vbulletin->db->insert_id();
    
    ($hook = vBulletinHook::fetch_hook('dbtech_vbshout_shout_notification')) ? eval($hook) : false;
    
    // Set the latest AOP time
    switch ($vbulletin->options['dbtech_vbshout_optimisation'])
    {
        case 1:
            // File system
            touch(DIR . '/dbtech/vbshout/aop.php');
            break;
            
        case 2:// Database
            $vbulletin->db->query_write("
                UPDATE " . TABLE_PREFIX . "datastore
                SET data = IF(data < " . TIMENOW . ", " . TIMENOW . ", data)
                WHERE title = 'dbtech_vbshout_aoptime'
            ");

            break;
    }
}
?>
 
Works excellent... and that query is required because the post thanks hack never goes into the thread table... with the post thank you hack you are only thanking a post, not a whole thread hence why the thread table isn't used in the code...

Well this is the output:

has given thanks to Cold Person for their post in Does this work?!

does this work? is indeed the thread name... now the last thing I want to add is the musername markup for the "thanked" person..
 
If memory serves me right, fetch_musername() is the function to fetch markup - you'll need to look inside includes/functions.php to see how it works, just search for "function fetch_musername" and you'll find it :)

However, Markup is in HTML - which won't parse inside the shoutbox AFAIK.
 
but isn't the person that does the shout using fetch_musername() which would be doing html? and it wouldn't have to be html if u did it through {vb:raw vboptions.bburl} ;)

and for convenience:

functions.php
PHP:
// #############################################################################
/**
* fetches the proper username markup and title
*
* @param	array	(ref) User info array
* @param	string	Name of the field representing displaygroupid in the User info array
* @param	string	Name of the field representing username in the User info array
*
* @return	string
*/
function fetch_musername(&$user, $displaygroupfield = 'displaygroupid', $usernamefield = 'username')
 
Last edited:
That is through HTML yes, but that's forced. The actual shout contents are not parsing HTML, that's why you don't store the shouters username. Also not sure what you mean by using template variables, don't see how they fit here?
 
Now I really got to go to bed: this is what I have so far:

PHP:
<?php
if (
    !$vbulletin->userinfo['dbtech_vbshout_banned']
)
    {
    //lets get thread title
    $findit = $vbulletin->db->query_first("
	SELECT title
	FROM " . TABLE_PREFIX . "thread
	WHERE threadid = " . $postinfo['threadid'] . "
	");
	$musergo[$postinfo['postid']][$postinfo['userid']]['username'] = fetch_musername($postinfo);
	if ($vbulletin->options['dbtech_vbshout_allowed_bbcode'] & 64)
    {
        // We can use BBCode
        $notif = '[post=' . $postinfo['postid'] . ']' . $findit['title'] . '[/post]';
    }
    else
    {
        // We can't, so don't even bother
        $notif = $findit['title'];
    }
	
    // Insert the notification
    $vbulletin->db->query_write("
        INSERT INTO " . TABLE_PREFIX . "dbtech_vbshout_shout
            (userid, dateline, message, type, notification)
        VALUES (
            " . $vbulletin->userinfo['userid'] . ",
            " . TIMENOW . ",
            '" . $vbulletin->db->escape_string(
                construct_phrase(
                    $vbphrase["dbtech_vbshout_notif_thanks"],
                    $postinfo['musername'],
                    $notif
                    )
                ) . "',
            8,
            'thanks'
        )
    ");
    
    // Get the shout id
    $shoutid = $vbulletin->db->insert_id();
    
    ($hook = vBulletinHook::fetch_hook('dbtech_vbshout_shout_notification')) ? eval($hook) : false;
    
    // Set the latest AOP time
    switch ($vbulletin->options['dbtech_vbshout_optimisation'])
    {
        case 1:
            // File system
            touch(DIR . '/dbtech/vbshout/aop.php');
            break;
            
        case 2:// Database
            $vbulletin->db->query_write("
                UPDATE " . TABLE_PREFIX . "datastore
                SET data = IF(data < " . TIMENOW . ", " . TIMENOW . ", data)
                WHERE title = 'dbtech_vbshout_aoptime'
            ");

            break;
    }
}
?>

Result:

has given thanks to <span style="color:red;font-weight:bold;">Cold Person<span> for their post in Does it work?!
 
Why the manual AOP set, did I forget to do that in the notifications area?

Le palm du face xD
I'll fix that in the next version xD
 
Now I really got to go to bed: this is what I have so far:

PHP:
<?php
if (
    !$vbulletin->userinfo['dbtech_vbshout_banned']
)
    {
    //lets get thread title
    $findit = $vbulletin->db->query_first("
	SELECT title
	FROM " . TABLE_PREFIX . "thread
	WHERE threadid = " . $postinfo['threadid'] . "
	");
	$musergo[$postinfo['postid']][$postinfo['userid']]['username'] = fetch_musername($postinfo);
	if ($vbulletin->options['dbtech_vbshout_allowed_bbcode'] & 64)
    {
        // We can use BBCode
        $notif = '[post=' . $postinfo['postid'] . ']' . $findit['title'] . '[/post]';
    }
    else
    {
        // We can't, so don't even bother
        $notif = $findit['title'];
    }
	
    // Insert the notification
    $vbulletin->db->query_write("
        INSERT INTO " . TABLE_PREFIX . "dbtech_vbshout_shout
            (userid, dateline, message, type, notification)
        VALUES (
            " . $vbulletin->userinfo['userid'] . ",
            " . TIMENOW . ",
            '" . $vbulletin->db->escape_string(
                construct_phrase(
                    $vbphrase["dbtech_vbshout_notif_thanks"],
                    $postinfo['musername'],
                    $notif
                    )
                ) . "',
            8,
            'thanks'
        )
    ");
    
    // Get the shout id
    $shoutid = $vbulletin->db->insert_id();
    
    ($hook = vBulletinHook::fetch_hook('dbtech_vbshout_shout_notification')) ? eval($hook) : false;
    
    // Set the latest AOP time
    switch ($vbulletin->options['dbtech_vbshout_optimisation'])
    {
        case 1:
            // File system
            touch(DIR . '/dbtech/vbshout/aop.php');
            break;
            
        case 2:// Database
            $vbulletin->db->query_write("
                UPDATE " . TABLE_PREFIX . "datastore
                SET data = IF(data < " . TIMENOW . ", " . TIMENOW . ", data)
                WHERE title = 'dbtech_vbshout_aoptime'
            ");

            break;
    }
}
?>

Result:

I told you previously, the HTML won't parse - that's why the markup won't work.
 
yeh I just noticed you said that, I was half asleep when I was doing all that ^_^ ... but what I do know is we can turn that into bbcode.. used to have a bbcode called 'user'.... when ever you used it, it would turn the userid or the username to link plus mark its up.... so I'll get more info later, I g2g to work....
 
Well I finished it.. and it works nicely... returns musername with link to profile and markup... plus link to thread... I'll make it a product file and u guys can see what u think.... I should be done in an hour or so...
 
Here is the Addon.. If your having issues Post it here.. but hopefully we will add it to vb.org soon! Stay tuned!

CHANGELOG:

v1.0.1 Added Dependency for vBshout and Install and Uninstall codes
Added Alter Table SQL Code to add 'thanks' as a notification type

v1.0.0 Phrase Included! - I left it out ^_^

v1: First Release
 

Attachments

Last edited:
Status
Not open for further replies.

Legacy vBShout

vBulletin 3.8.x vBulletin 4.x.x
Seller
DragonByte Technologies
Release date
Last update
Total downloads
3,179
Customer rating
5.00 star(s) 1 ratings
Back
Top