MyBB Community Forums

Full Version: Twitter-style [@name]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Cool, I like it a lot!
(2010-03-18, 01:30 AM)labrocca Wrote: [ -> ]Lines like this are written poorly.

$query2[$y] = $db->query("SELECT * FROM {$config['database']['table_prefix']}users WHERE username LIKE '%".$uinfo2[1][$y]."%' LIMIT 1");

Do this:

$query2[$y] = $db->simple_select("users", "username", "username LIKE '%".$uinfo2[1][$y]."%',array('limit' => 1));

That should work.

Really you shouldn't use LIKE imho. Basically if username doesn't exist then just display the regular code. A couple more things could be fine tuned on this plugin.

True, but simple_select escaped my mind when the base code was written. This was a modified version of my UInfo MyCode, so back then I was totally lost. And my use of LIKE is so you don't need to type out the entire username. Like if I'm lazy or something, I'd rather do [@labr] instead of [@labrocca]
Quote:And my use of LIKE is so you don't need to type out the entire username.

That's a bad idea. What if there is a user labr?

I have 100,000 members at HF. Lots of names are similar.
(2010-03-18, 03:15 AM)labrocca Wrote: [ -> ]
Quote:And my use of LIKE is so you don't need to type out the entire username.

That's a bad idea. What if there is a user labr?

I have 100,000 members at HF. Lots of names are similar.


Eh ... Wiseass.
A quick HF search for usernames lik labr gets me 5 results.

allabros
rahulabrol6
labrendant
Frankylabrule
blacklabrador88

Now what?
(2010-03-18, 03:24 AM)labrocca Wrote: [ -> ]A quick HF search for usernames lik labr gets me 5 results.

allabros
rahulabrol6
labrendant
Frankylabrule
blacklabrador88

Now what?

Already got it to need the right username. Now if build_profile_link didn't return Guest if it doesn't exist, I could remove the need for the brackets.
Maybe I could cheapen it and replace "Guest" with the original username ... Of course, that causes a problem if someone registers that name.
So now, I just need to work on the fact that it has it's own newline somewhere, and maybe work on removing the need for [@name]
Really cool plugin! I just made some changes to use on my forum:
Just use @username & ta-da!

$plugins->add_hook("parse_message", "twitter");
$plugins->add_hook("member_profile_start", "twitter_username_redirect");

function twitter(&$message2)
{
	global $mybb, $db;

	$message2 = preg_replace('/(^|[^a-z0-9_])@([a-z0-9_]+)/i', ' @<a href="member.php?action=profile&username=$2">$2</a>', $message2);

	return $message2;
}

function twitter_username_redirect()
{
	global $mybb, $db;
	
	if(!empty($mybb->input['username']))
	{
		$q = $db->simple_select('users', 'uid', 'username = "' . $mybb->input['username'] . '"');
		
		$result = $db->fetch_array($q);
		
		$mybb->input['action'] = 'profile';
		
		if(is_array($result))
		{
			//header('Location: member.php?action=profile&uid=' . $result['uid']);
			$mybb->input['uid'] = $result['uid'];
		}
		else
		{
			// User not found
			//header('Location: member.php?action=profile&uid=0');
			$mybb->input['uid'] = 0;
		}
	}
}

Works like a charm :p
Not bad, I'm still working on mine.
Nice plugin! Big Grin

I did something similar to this on my board, except it was the urls not the names. (http://www.example.com/@mykeled123)
Pages: 1 2 3 4