2012-07-02, 04:17 PM
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:
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:
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...
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...