MyBB Community Forums

Full Version: Random link bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
So I've been facing a problem with a bug that occurs seemingly randomly in my MyAlerts plugin where outputted links are showing up incorrectly. Here's the code I'm using:

 try
{
    $alertsList = $Alerts->getAlerts($start);
}
catch (Exception $e)
{
    error_no_permission();
    die();
}

$readAlerts = array();

if ($numAlerts > 0)
{
    foreach ($alertsList as $alert)
    {
        $alert['user'] = build_profile_link($alert['username'], $alert['uid']);
        $alert['dateline'] = my_date($mybb->settings['dateformat'], $alert['dateline'])." ".my_date($mybb->settings['timeformat'], $alert['dateline']);

        if ($alert['type'] == 'quoted' AND $mybb->settings['myalerts_alert_quoted'])
        {
            $alert['postLink'] = $mybb->settings['bburl'].'/'.get_post_link($alert['content']['pid'], $alert['content']['tid']).'#pid'.$alert['content']['pid'];
            $alert['message'] = $lang->sprintf($lang->myalerts_quoted, $alert['user'], $alert['postLink'], $alert['dateline']);
        }

        $alertinfo = $alert['message'];

        eval("\$alertsListing .= \"".$templates->get('myalerts_alert_row')."\";");

        $readAlerts[] = $alert['id'];
    }
}
else
{
    $alertinfo = $lang->myalerts_no_alerts;
    eval("\$alertsListing = \"".$templates->get('myalerts_alert_row')."\";");
}

$Alerts->markRead($readAlerts);

I have cut some stuff out, but that's the basic content of one of the output function. This should work (in my eyes) but occasionally it seems the $alert['content'] array key isn't unserialized or something as the $alert['postlink'] variable becomes the following:

http://mybb.euantor.com/post-a.html#pida

I have no idea of the cause. I reckon there's something wrong with unserialize as the $Alerts->getAlerts() method actually runs the unserialize function itself too but I noticed the contents weren't always unserialized for some reason.

Anybody got any ideas? Maybe I should store the contents in another form rather than as a serialized array...
I might have just found the solution in the form of base64_encode. Here's hoping it'll work.
I'm now getting http://mybb.euantor.com/post-c.html#pidc so we've gone from A to C! Sad
Great. So my solution didn't fix it. Back to the drawing board I guess.
happen to be running 64-bit PHP pre-5.2.0?
Nope. Running PHP 5.3. I can't work out the cause at all.

EDIT: Also, here's the getAlerts() method and I've updated the above code.

/**
	 *	Fetch all alerts for the currently logged in user
	 *
	 *	@param Integer - the start point (used for multipaging alerts)
	 *	@return Array
	 */
	public function getAlerts($start = 0)
	{
		if ((int) $this->mybb->user['uid'] > 0)	// check the user is a user and not a guest - no point wasting queries on guests afterall
		{
			$alerts = $this->db->write_query("SELECT a.*, u.uid, u.username, u.avatar FROM ".TABLE_PREFIX."alerts a INNER JOIN ".TABLE_PREFIX."users u ON (a.from = u.uid) WHERE a.uid = ".(int) $this->mybb->user['uid']." ORDER BY a.id DESC LIMIT ".(int) $start.", ".$this->mybb->settings['myalerts_perpage'].";");
			if ($this->db->num_rows($alerts) > 0)
			{
				$return = array();
				while ($alert = $this->db->fetch_array($alerts))
				{
					$alert['content'] = unserialize(base64_decode($alert['content']));
					$return[] = $alert;
				}

				return $return;
			}
			else
			{
				return false;
			}
		}
		else
		{
			throw new Exception('Guests have not got access to the Alerts functionality');
		}
	}
so the "a" in your link example is actually an "a"?

perhaps serializing the data twice perhaps, thus pulling the "a" from the still serialized data from the first pass.

does the bad link alway happen with quote alerts or other types as well?
Yeah, it's actually an A. Since I started using base64 though it shows up as a Y and a few other letters.

It seems only to happen to quote alerts for some odd reason. I've var_dumped the input before it's inserted to the database and it looks perfectly fine so I'm completely stumped.

Also, it doesn't always happen for quote alerts. I have a hunch that it's only happening on nested quotes or when there are multiple quotes from the same user though. here's a post which causes the issue: http://mybb.euantor.com/thread-1-post-386.html#pid386
can you PM the value of the content field in the alerts table for pid 386?
Sure can. I'll just grab it.

PMed you, then tested it. It seems a bit... broken haha
Pages: 1 2