Sponsored Content
The Lounge What is on Your Mind? New Icons Coming from Font Awesome Post 303020955 by Neo on Wednesday 1st of August 2018 01:33:40 AM
Old 08-01-2018
Here is the file post_thanks.php

Please review the PHP code and reply with the PHP code (or pseudo code and location in the file if you are not a PHP person), that will provide the functionality you wish about updating thanks counters. This is not something I'm working on (anytime soon) as it is not related to tables, divs, CSS etc; and I need to stay focused on the task at hand (when I get my development monitor fixed, LOL, so I can work again). The way all forum counters update are a different discussion related to core vB counters and cron and their update frequency, a task / feature which I'm not working on anytime soon, but you can certainly code this and help if you have time and want to do it (also attached):

Note: This file updates the thanks and count for posts. There is a cron which runs that goes thru all the post updated each users count. This happens with some frequency each day, but frankly I have no time for the near future to look into counters, as my plate is more than full with other forum coding tasks.


Code:
<?php
/*=====================================*\
|| ################################### ||
|| # Post Thank You Hack version 7.5 # ||
|| ################################### ||
\*=====================================*/

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'post_thanks');
define('CSRF_PROTECTION', true);
define('LOCATION_BYPASS', 1);
define('NOPMPOPUP', 1);

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
	'post_thanks_box', 
    'post_thanks_box_bit', 
    'post_thanks_button', 
    'post_thanks_postbit', 
    'post_thanks_postbit_legacy'
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_post_thanks.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$vbulletin->input->clean_array_gpc('r', array(
	'using_ajax'       => TYPE_UINT,
	'securitytoken' => TYPE_STR
));
$using_ajax = $vbulletin->GPC['using_ajax'];
$securitytoken = $vbulletin->GPC['securitytoken'];

($hook = vBulletinHook::fetch_hook('post_thanks_main_start')) ? eval($hook) : false;

if ($_REQUEST['do'] == 'post_thanks_add')
{
	($hook = vBulletinHook::fetch_hook('post_thanks_main_add_thanks_start')) ? eval($hook) : false;

	$postinfo = array_merge($postinfo, fetch_userinfo($postinfo['userid']));
	if (post_thanks_off($forumid, $postinfo, $threadinfo['firstpostid']) || 
               !can_thank_this_post($postinfo, $threadinfo['isdeleted'], true, $securitytoken) || 
               thanked_already($postinfo))
	{
       // error_log("Thanks Validate: ".$vbulletin->userinfo[username].' Enter using_ajax ' ."\n",3,'/tmp/thanks.txt');
		$using_ajax ? exit : print_no_permission();
	}

	add_thanks($postinfo);

	($hook = vBulletinHook::fetch_hook('post_thanks_main_add_thanks_end')) ? eval($hook) : false;

	if ($using_ajax)
	{
                error_log("Thanks Process: ".$vbulletin->userinfo[username].' Enter using_ajax ' ."\n",3,'/tmp/thanks.txt');
		$thanks = fetch_thanks($postid, '', true);

		$postinfo['post_thanks_bit'] = fetch_thanks_bit($forumid, $thanks);
		
		$postinfo['post_thanks_amount'] = $postinfo['post_thanks_amount'] + 1;
		$postinfo['post_thanks_amount_formatted'] = vb_number_format($postinfo['post_thanks_amount']);

		if ($vbulletin->options['post_thanks_delete_own'])
		{
			$postinfo['show_thanks_remove_option'] = true;
		}

		$echo = fetch_post_thanks_template($postinfo);
		echo "$echo";
		exit;
	}
	else
	{
		$vbulletin->url = "showthread.php?$session[sessionurl]p=$postid";
		eval(print_standard_redirect('redirect_post_thanks'));
	}

}

if ($_REQUEST['do'] == 'post_thanks_remove_all')
{
	($hook = vBulletinHook::fetch_hook('post_thanks_main_remove_all_thanks_start')) ? eval($hook) : false;

	if (!(can_delete_all_thanks()))
	{
		$using_ajax ? exit : print_no_permission();
	}

	delete_all_thanks($postinfo);

	($hook = vBulletinHook::fetch_hook('post_thanks_main_remove_all_thanks_end')) ? eval($hook) : false;

	if ($using_ajax)
	{
		exit;
	}
	else
	{
		$vbulletin->url = "showthread.php?$session[sessionurl]p=$postid";
		eval(print_standard_redirect('redirect_post_thanks'));
	}
}

if ($_REQUEST['do'] == 'post_thanks_remove_user')
{
	($hook = vBulletinHook::fetch_hook('post_thanks_main_remove_user_thanks_start')) ? eval($hook) : false;

	if (!(delete_thanks($postinfo, $vbulletin->userinfo['userid'])))
	{
		$using_ajax ? exit : print_no_permission();
	}	

	($hook = vBulletinHook::fetch_hook('post_thanks_main_remove_user_thanks_end')) ? eval($hook) : false;

	$postinfo['post_thanks_amount'] = $postinfo['post_thanks_amount'] - 1;

	if ($postinfo['post_thanks_amount'] > 0 && $using_ajax)
	{     
		$thanks = fetch_thanks($postid, '', true);

		$postinfo['post_thanks_bit'] = fetch_thanks_bit($forumid, $thanks);

		$postinfo['post_thanks_amount_formatted'] = vb_number_format($postinfo['post_thanks_amount']);
		$postinfo['post_thanks_user'] = false;
		$postinfo['ajax'] = true;

		$echo = fetch_post_thanks_template($postinfo);
		echo "$echo";
		exit;
	}
	else if ($using_ajax)
	{
		exit;
	}
	else
	{
		$vbulletin->url = "showthread.php?$session[sessionurl]p=$postid";
		eval(print_standard_redirect('redirect_post_thanks'));
	}
}

if ($_REQUEST['do'] == 'findthanks')
{
	require_once(DIR . '/includes/functions_search.php');
	require_once(DIR . '/includes/functions_misc.php');
        $action = 'findthanks';

	$vbulletin->input->clean_array_gpc('r', array(
		'userid'	=> TYPE_UINT,
	));

	// valid user id?
	if (!$vbulletin->GPC['userid'])
	{
		eval(standard_error(fetch_error('invalidid', $vbphrase['user'], $vbulletin->options['contactuslink'])));
	}

	// get user info
	if ($user = $db->query_first("SELECT userid, username, posts FROM " . TABLE_PREFIX . "user WHERE userid = " . $vbulletin->GPC['userid']))
	{
		$searchuser =& $user['username'];
	}
	// could not find specified user
	else
	{
		eval(standard_error(fetch_error('invalidid', $vbphrase['user'], $vbulletin->options['contactuslink'])));
	}

	// #############################################################################
	// build search hash
	$query = '';
	$searchuser = $user['username'];
	$exactname = 1;
	$starteronly = 0;
	$forumchoice = $foruminfo['forumid'];
	$childforums = 1;
	$titleonly = 0;
	$showposts = 1;
	$searchdate = 0;
	$beforeafter = 'after';
	$replyless = 0;
	$replylimit = 0;
	$searchthreadid = 0;

	$searchhash = md5(TIMENOW . "||" . $vbulletin->userinfo['userid'] . "||" . strtolower($searchuser) . 
              "||$exactname||$starteronly||$forumchoice||$childforums||$titleonly||$showposts||
                $searchdate||$beforeafter||$replyless||$replylimit||$searchthreadid");

	// check if search already done
	//if ($search = $db->query_first("SELECT searchid FROM " . TABLE_PREFIX . "search AS search WHERE searchhash = '" . $db->escape_string($searchhash) . "'"))
	//{
	//	$vbulletin->url = 'search.php?' . $vbulletin->session->vars['sessionurl'] . "searchid=$search[searchid]";
	//	eval(print_standard_redirect('search'));
	//}

	// start search timer
	$searchtime = microtime();

	$forumids = array();
	$noforumids = array();
	// #############################################################################
	// check to see if we should be searching in a particular forum or forums
	if ($forumids = fetch_search_forumids($vbulletin->GPC['forumchoice'], $vbulletin->GPC['childforums']))
	{
		$showforums = true;
	}
	else
	{
		foreach ($vbulletin->forumcache AS $forumid => $forum)
		{
			$fperms =& $vbulletin->userinfo['forumpermissions']["$forumid"];
			if (($fperms & $vbulletin->bf_ugp_forumpermissions['canview']))
			{
				$forumids[] = $forumid;
			}
		}
		$showforums = false;
	}

	if (empty($forumids))
	{
		eval(standard_error(fetch_error('searchnoresults', $displayCommon), '', false));
	}
	else
	{
		// query post ids in dateline DESC order...
		($_REQUEST['orderdate'])?$_ST="post_thanks.date":$_ST="post.dateline";

		$orderedids = array();
		$posts = $db->query_read("
			SELECT DISTINCT post.postid
			FROM " . TABLE_PREFIX . "post AS post
			RIGHT JOIN " . TABLE_PREFIX . "post_thanks AS post_thanks ON post_thanks.postid=post.postid
			INNER JOIN " . TABLE_PREFIX . "thread AS thread ON(thread.threadid = post.threadid)
			WHERE post.userid = $user[userid]
				AND post.post_thanks_amount != 0
				AND thread.forumid IN(" . implode(',', $forumids) . ")
			ORDER BY $_ST DESC
			LIMIT " . ($vbulletin->options['maxresults'] * 2) . "
		");
		while ($post = $db->fetch_array($posts))
		{
			$orderedids[] = $post['postid'];
		}
		unset($post);
		$db->free_result($posts);

		// did we get some results?
		if (empty($orderedids))
		{
			eval(standard_error(fetch_error('searchnoresults', $displayCommon), '', false));
		}

		// set display terms
		$display = array(
			'words' => array(),
			'highlight' => array(),
			'common' => array(),
			'users' => array($user['userid'] => $user['username']),
			'forums' => iif($showforums, $display['forums'], 0),
			'options' => array(
				'starteronly' => 0,
				'childforums' => 1,
				'action' => 'process'
			)
		);

		// end search timer
		$searchtime = number_format(fetch_microtime_difference($searchtime), 5, '.', '');

		/*insert query*/
		$db->query_write("
			REPLACE INTO " . TABLE_PREFIX . "search (userid, ipaddress, personal, searchuser, forumchoice, 
                 sortby, sortorder, searchtime, showposts, orderedids, dateline, displayterms, searchhash)
			VALUES (" . $vbulletin->userinfo['userid'] . ", '" . $db->escape_string(IPADDRESS) . "', 1, '" . 
                     $db->escape_string($user['username']) . "', '" . $db->escape_string($forumchoice) .
                     "', 'post.dateline', 'DESC', $searchtime, 1, '" . $db->escape_string(implode(',', $orderedids)) .
                     "', " . TIMENOW . ", '" . $db->escape_string(serialize($display)) . "', '" .
                     $db->escape_string($searchhash) . "')
		");
		$searchid = $db->insert_id();

		//$vbulletin->url = 'search.php?' . $vbulletin->session->vars['sessionurl'] . "searchid=$searchid&search=findthanks";
		$vbulletin->url = 'search.php?' . $vbulletin->session->vars['sessionurl'] . "searchid=$searchid";
		eval(print_standard_redirect('search'));
	}
}

if ($_REQUEST['do'] == 'findthanks_user_gave')
{
	require_once(DIR . '/includes/functions_search.php');
	require_once(DIR . '/includes/functions_misc.php');
        $action = 'findthanks_user_gave';

	$vbulletin->input->clean_array_gpc('r', array(
		'userid'	=> TYPE_UINT,
	));

	// valid user id?
	if (!$vbulletin->GPC['userid'])
	{
		eval(standard_error(fetch_error('invalidid', $vbphrase['user'], $vbulletin->options['contactuslink'])));
	}

	// get user info
	if ($user = $db->query_first("SELECT userid, username, posts FROM " . TABLE_PREFIX . "user WHERE userid = " . $vbulletin->GPC['userid']))
	{
		$searchuser =& $user['username'];
	}
	// could not find specified user
	else
	{
		eval(standard_error(fetch_error('invalidid', $vbphrase['user'], $vbulletin->options['contactuslink'])));
	}

	// #############################################################################
	// build search hash
	$query = '';
	$searchuser = $user['username'];
	$exactname = 1;
	$starteronly = 0;
	$forumchoice = $foruminfo['forumid'];
	$childforums = 1;
	$titleonly = 0;
	$showposts = 1;
	$searchdate = 0;
	$beforeafter = 'after';
	$replyless = 0;
	$replylimit = 0;
	$searchthreadid = 0;

	$searchhash = md5(TIMENOW . "||" . $vbulletin->userinfo['userid'] . "||" . strtolower($searchuser) .
             "||$exactname||$starteronly||$forumchoice||$childforums||$titleonly||$showposts||$searchdate||
             $beforeafter||$replyless||$replylimit||$searchthreadid");

	// check if search already done
	//if ($search = $db->query_first("SELECT searchid FROM " . TABLE_PREFIX . "search AS search WHERE searchhash = '" . $db->escape_string($searchhash) . "'"))
	//{
	//	$vbulletin->url = 'search.php?' . $vbulletin->session->vars['sessionurl'] . "searchid=$search[searchid]";
	//	eval(print_standard_redirect('search'));
	//}

	// start search timer
	$searchtime = microtime();

	$forumids = array();
	$noforumids = array();
	// #############################################################################
	// check to see if we should be searching in a particular forum or forums
	if ($forumids = fetch_search_forumids($vbulletin->GPC['forumchoice'], $vbulletin->GPC['childforums']))
	{
		$showforums = true;
	}
	else
	{
		foreach ($vbulletin->forumcache AS $forumid => $forum)
		{
			$fperms =& $vbulletin->userinfo['forumpermissions']["$forumid"];
			if (($fperms & $vbulletin->bf_ugp_forumpermissions['canview']))
			{
				$forumids[] = $forumid;
			}
		}
		$showforums = false;
	}

	if (empty($forumids))
	{
		eval(standard_error(fetch_error('searchnoresults', $displayCommon), '', false));
	}
	else
	{

		// query post ids in dateline DESC order...
		($_REQUEST['orderdate'])?$_ST="post_thanks.date":$_ST="post.dateline";

		$orderedids = array();
		$posts = $db->query_read("
			SELECT post_thanks.postid AS postid
			FROM " . TABLE_PREFIX . "post_thanks AS post_thanks
			LEFT JOIN " . TABLE_PREFIX . "post AS post USING (postid)
			INNER JOIN " . TABLE_PREFIX . "thread AS thread ON(thread.threadid = post.threadid)
			WHERE post_thanks.userid = $user[userid]
				AND thread.forumid IN(" . implode(',', $forumids) . ")
			ORDER BY $_ST DESC
			LIMIT " . ($vbulletin->options['maxresults'] * 2) . "
		");
		while ($post = $db->fetch_array($posts))
		{
			$orderedids[] = $post['postid'];
		}
		unset($post);
		$db->free_result($posts);

		// did we get some results?
		if (empty($orderedids))
		{
			eval(standard_error(fetch_error('searchnoresults', $displayCommon), '', false));
		}

		// set display terms
		$display = array(
			'words' => array(),
			'highlight' => array(),
			'common' => array(),
			'users' => array($user['userid'] => $user['username']),
			'forums' => iif($showforums, $display['forums'], 0),
			'options' => array(
				'starteronly' => 0,
				'childforums' => 1,
				'action' => 'process'
			)
		);

		// end search timer
		$searchtime = number_format(fetch_microtime_difference($searchtime), 5, '.', '');

		/*insert query*/
		$db->query_write("
			REPLACE INTO " . TABLE_PREFIX . "search (userid, ipaddress, personal, searchuser, forumchoice, sortby, 
                      sortorder, searchtime, showposts, orderedids, dateline, displayterms, searchhash)
			VALUES (" . $vbulletin->userinfo['userid'] . ", '" . $db->escape_string(IPADDRESS) . "', 1, '" .
                      $db->escape_string($user['username']) . "', '" . $db->escape_string($forumchoice) .
                      "', 'post.dateline', 'DESC', $searchtime, 1, '" . $db->escape_string(implode(',', $orderedids)) .
                      "', " . TIMENOW . ", '" . $db->escape_string(serialize($display)) . "', '" .
                      $db->escape_string($searchhash) . "')
		");
		$searchid = $db->insert_id();

		$vbulletin->url = 'search.php?' . $vbulletin->session->vars['sessionurl'] . "searchid=$searchid";
		eval(print_standard_redirect('search'));
	}
}

// #############################################################################
if ($_REQUEST['do'] == 'findallthanks')
{
	require_once(DIR . '/includes/functions_search.php');
	require_once(DIR . '/includes/functions_misc.php');

	// #############################################################################
	// build search hash
	$query = '';
	$searchuser = $user['username'];
	$exactname = 1;
	$starteronly = 0;
	$forumchoice = $foruminfo['forumid'];
	$childforums = 1;
	$titleonly = 0;
	$showposts = 1;
	$searchdate = 0;
	$beforeafter = 'after';
	$replyless = 0;
	$replylimit = 0;
	$searchthreadid = 0;

	$searchhash = md5(TIMENOW . "||" . $vbulletin->userinfo['userid'] . "||" . strtolower($searchuser) .
           "||$exactname||$starteronly||$forumchoice||$childforums||$titleonly||$showposts||$searchdate||
            $beforeafter||$replyless||$replylimit||$searchthreadid");

	// check if search already done
	//if ($search = $db->query_first("SELECT searchid FROM " . TABLE_PREFIX . "search AS search WHERE searchhash = '" . $db->escape_string($searchhash) . "'"))
	//{
	//	$vbulletin->url = 'search.php?' . $vbulletin->session->vars['sessionurl'] . "searchid=$search[searchid]";
	//	eval(print_standard_redirect('search'));
	//}

	// start search timer
	$searchtime = microtime();

	$forumids = array();
	$noforumids = array();
	// #############################################################################
	// check to see if we should be searching in a particular forum or forums
	if ($forumids = fetch_search_forumids($vbulletin->GPC['forumchoice'], $vbulletin->GPC['childforums']))
	{
		$showforums = true;
	}
	else
	{
		foreach ($vbulletin->forumcache AS $forumid => $forum)
		{
			$fperms =& $vbulletin->userinfo['forumpermissions']["$forumid"];
			if (($fperms & $vbulletin->bf_ugp_forumpermissions['canview']))
			{
				$forumids[] = $forumid;
			}
		}
		$showforums = false;
	}

	if (empty($forumids))
	{
		eval(standard_error(fetch_error('searchnoresults', $displayCommon), '', false));
	}
	else
	{
		// query post ids in dateline DESC order...
		$orderedids = array();
		$posts = $db->query_read("
			SELECT postid
			FROM " . TABLE_PREFIX . "post AS post
			INNER JOIN " . TABLE_PREFIX . "thread AS thread ON(thread.threadid = post.threadid)
			WHERE post.post_thanks_amount != 0
				AND thread.forumid IN(" . implode(',', $forumids) . ")
			ORDER BY post.dateline DESC
			LIMIT " . ($vbulletin->options['maxresults'] * 2) . "
		");
		while ($post = $db->fetch_array($posts))
		{
			$orderedids[] = $post['postid'];
		}
		unset($post);
		$db->free_result($posts);

		// did we get some results?
		if (empty($orderedids))
		{
			eval(standard_error(fetch_error('searchnoresults', $displayCommon), '', false));
		}

		// set display terms
		$display = array(
			'words' => array(),
			'highlight' => array(),
			'common' => array(),
			'users' => array($user['userid'] => $user['username']),
			'forums' => iif($showforums, $display['forums'], 0),
			'options' => array(
				'starteronly' => 0,
				'childforums' => 1,
				'action' => 'process'
			)
		);

		// end search timer
		$searchtime = number_format(fetch_microtime_difference($searchtime), 5, '.', '');

		/*insert query*/
		$db->query_write("
			REPLACE INTO " . TABLE_PREFIX . "search (userid, ipaddress, personal, searchuser, forumchoice, 
                sortby, sortorder, searchtime, showposts, orderedids, dateline, displayterms, searchhash)
			VALUES (" . $vbulletin->userinfo['userid'] . ", '" . $db->escape_string(IPADDRESS) . "', 1, '" .
                $db->escape_string($user['username']) . "', '" . $db->escape_string($forumchoice) . "', 'post.dateline', 
                'DESC', $searchtime, 1, '" . $db->escape_string(implode(',', $orderedids)) . "', " . TIMENOW . ", '" .
                $db->escape_string(serialize($display)) . "', '" . $db->escape_string($searchhash) . "')
		");
		$searchid = $db->insert_id();

		$vbulletin->url = 'search.php?' . $vbulletin->session->vars['sessionurl'] . "searchid=$searchid";
		eval(print_standard_redirect('search'));
	}
}

($hook = vBulletinHook::fetch_hook('post_thanks_main_end')) ? eval($hook) : false;
?>

 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

redhat 7.2 icons on desktop

Hello all, Is there a way to change the behavior of the gnome desktop manager so that when your iconify a window it will be place on the desktop intead on on the task manager (gnome-panel)? It gets confusing having to loook throught the gnome-panle for the window I want when you have alot of... (1 Reply)
Discussion started by: larry
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Dotted thread icons

Can you guys please enable the "dotted" icon option, so that the thread icon for a thread in which a user has posted in will appear with a dot in it? Thanks, Aaron (2 Replies)
Discussion started by: Spetnik
2 Replies

3. Solaris

How to get a second Icons - Window!

Hey everybody! I'd like to get a second Window for my program Icons, any Idea how to solve this problem?? :confused: thanks, Tom (3 Replies)
Discussion started by: TomStyria
3 Replies

4. Red Hat

Menu Icons for the Application

Hi All, I created an RPM for my application. After clicking the rpm, I managed to place the files in repective locations also I have "JServer" menus in the "Application" menu (The redhat one). But the problem is the icons are not appearing in that menu. I placed my icons/images in... (0 Replies)
Discussion started by: jw_amp
0 Replies

5. AIX

CDE: why no icons?

Why my cde show no icons? I have installed X11.Dt.ToolTalk 7.1.3.15 C F AIX CDE ToolTalk Support X11.Dt.adt 7.1.3.0 C F AIX CDE Application X11.Dt.bitmaps 7.1.0.0 C F AIX CDE Bitmaps X11.Dt.compat ... (8 Replies)
Discussion started by: Linusolaradm1
8 Replies

6. What is on Your Mind?

New Mobile Navbar Icons from Font Awesome

Just changed the mobile site to use Font Awesome icons. Here is the new top navbar view (unregistered users) https://www.unix.com/members/1-albums214-picture903.jpeg (2 Replies)
Discussion started by: Neo
2 Replies

7. Web Development

New Font Awesome Icons in Quick Reply Editor

Working on the Quick Reply Editor, I have replaced a number of icons (see image below) with Font Awesome Icons. Was planning to replace all of them, but for some reason, replacing a few of them causes the script / template to break (which is odd) so I left them for now. ... (6 Replies)
Discussion started by: Neo
6 Replies

8. What is on Your Mind?

Quick Update on UNIX.COM Site Renovation: Bootstrap, Font Awesome and jQuery

Here is an update on the site renovation: After a lot of analysis and example programming, including testing out a number of Javascript framework and libraries, in the short term, we are getting the most bang-for-the-buck from these three basic, core tech areas: Bootstrap (CSS and... (2 Replies)
Discussion started by: Neo
2 Replies
All times are GMT -4. The time now is 10:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy