<?php
foreach ((array)$this->info[&#039;dbtech_usertag&#039;][&#039;mention&#039;] AS $usertaginfo)
{
	// Write tags
	if ($usertaginfo[&#039;userid&#039;] != $userinfo[&#039;userid&#039;] AND (in_array($post[&#039;forumid&#039;], USERTAG::forumIds($usertaginfo)) OR $type == &#039;blog&#039;))
	{
		$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET dbtech_usertag_mentioncount = dbtech_usertag_mentioncount + 1, dbtech_usertag_mentions = dbtech_usertag_mentions + 1 WHERE userid = " . intval($usertaginfo[&#039;userid&#039;]));

		$cansendemail = ($vbulletin->options[&#039;enableemail&#039;] AND ($userinfo[&#039;permissions&#039;][&#039;genericpermissions&#039;] & $vbulletin->bf_ugp_genericpermissions[&#039;canemailmember&#039;]) AND !($vbulletin->options[&#039;dbtech_usertag_disabledemails&#039;] & 1));
		$canreceiveemail = (($usertaginfo[&#039;adminemail&#039;] OR $usertaginfo[&#039;showemail&#039;]) AND ($vbulletin->options[&#039;dbtech_usertag_emaildefault&#039;] ? !($usertaginfo[&#039;dbtech_usertag_settings&#039;] & 128) : ($usertaginfo[&#039;dbtech_usertag_settings&#039;] & 128)));
		if ($cansendemail AND $canreceiveemail)
		{
			// Send the mail
			eval(fetch_email_phrases(&#039;dbtech_usertag_mention_received_email&#039;, $usertaginfo[&#039;languageid&#039;]));
			require_once(DIR . &#039;/includes/class_bbcode_alt.php&#039;);
			$plaintext_parser = new vB_BbCodeParser_PlainText($vbulletin, fetch_tag_list());
			$plaintext_parser->set_parsing_language($usertaginfo[&#039;languageid&#039;]);
			$message = $plaintext_parser->parse($message, &#039;privatemessage&#039;);
			vbmail($usertaginfo[&#039;email&#039;], $subject, $message, true);
		}
	}
	$vbulletin->db->query_write("
		INSERT IGNORE INTO " . TABLE_PREFIX . "dbtech_usertag_mention
			(userid, mentionedid, postid, type, dateline)
		VALUES (
			" . $vbulletin->db->sql_prepare($userinfo[&#039;userid&#039;]) . ",
			" . $vbulletin->db->sql_prepare($usertaginfo[&#039;userid&#039;]) . ",
			" . $vbulletin->db->sql_prepare($post[&#039;postid&#039;]) . ",
			" . $vbulletin->db->sql_prepare($type) . ",
			" . $vbulletin->db->sql_prepare(TIMENOW) . "
		)
	");
	$mentionId = $vbulletin->db->insert_id();

	if (!empty($vbulletin->products[&#039;dbtech_vbshout&#039;]) AND class_exists(&#039;VBSHOUT&#039;))
	{
		foreach ((array)VBSHOUT::$cache[&#039;instance&#039;] as $instanceid => $instance)
		{
			// Initialise BBCode Permissions
			$permarray = array(
				&#039;bbcode&#039; => (method_exists(&#039;VBSHOUT&#039;, &#039;loadInstanceBbcodePermissions&#039;) ? VBSHOUT::loadInstanceBbcodePermissions($instance, $userinfo) : VBSHOUT::load_instance_bbcodepermissions($instance, $userinfo))
			);

			// Fix AOP
			VBSHOUT::set_aop(&#039;usertags_&#039; . $usertaginfo[&#039;userid&#039;] . &#039;_&#039;, $instanceid, false, true);

			if ((int)$permarray[&#039;bbcode&#039;][&#039;bit&#039;] & 64)
			{
				switch ($type)
				{
					case &#039;post&#039;:
						$text = &#039;[post=&#039; . $post[&#039;postid&#039;] . &#039;]&#039; . $title . &#039;[/post]&#039;;
						break;

					case &#039;blog&#039;:
						$text = &#039;Blog: [URL="&#039; . $vbulletin->options[&#039;bburl&#039;] . &#039;/blog.php?blogtextid=&#039; . intval($post[&#039;postid&#039;]) . &#039;"]&#039; . $title . &#039;[/URL]&#039;;
						break;
				}
			}
			else
			{
				$text = $title;
			}

			// Init the Shout DM
			$shout = VBSHOUT::initDataManager(&#039;Shout&#039;, $vbulletin, ERRTYPE_SILENT);
				$shout->set_info(&#039;automated&#039;, true);
				$shout->set(&#039;message&#039;, construct_phrase($vbphrase[&#039;dbtech_usertag_me_mentioned_y_in_z&#039;],
					$usertaginfo[&#039;username&#039;],
					$text
				))
				->set(&#039;userid&#039;, $userinfo[&#039;userid&#039;])
				->set(&#039;id&#039;, $usertaginfo[&#039;userid&#039;])
				->set(&#039;type&#039;, VBSHOUT::$shouttypes[&#039;mention&#039;])
				->set(&#039;instanceid&#039;, $instanceid);

			// Get the shout id
			$shoutid = $shout->save();
			unset($shout);
		}
	}

	if (!empty($vbulletin->products[&#039;notification_vbsocial&#039;]) AND class_exists(&#039;vBSocial_Notification_Core&#039;))
	{
		$manager = vBSocial_Notification_Core::getNotificationManager(&#039;dbtech_usertag_mention&#039;);
		if (is_object($manager))
		{
			$manager->info = array(
				&#039;source&#039; => $userinfo,
				&#039;target&#039; => $usertaginfo,
				&#039;contentid&#039; => $mentionId,
				&#039;type&#039; => $type,
				&#039;title&#039; => $title
			);
			$manager->notify();
		}
	}

	($hook = vBulletinHook::fetch_hook(&#039;dbtech_usertag_mention_postsave&#039;)) ? eval($hook) : false;
}
?>

Add a code snippet to your website: www.paste.org