Page 1 of 1

Related Links - BAD BAD BUG! .. and fix .. and new feature

Posted: Sun Apr 30, 2006 3:00 am
by hotroast
Glad to help with the last one Garvin, and of course keep up the great work with everything. This one really had me spinning for a bit but I got it - and solved 2 issues in one shot. I noticed that for some reason, if you add links to a new post, previous posts no longer had any Related Links left in the "Edit Entries" section (though they would still show on the post) - but they could no longer easily be editted. This is because the plugin apparently keeps a record of the original entries in "post_relatedentries" and the viewable ones in "relatedentries". The problem here was in the sql code they left out the () and on each save they were wiping out EVERY PAST "post_relatedentries" from the database!!!

The original line from "serendipity_event_relatedlinks.php":

$q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = ". (int)$eventData['id'] . " AND property = 'relatedentries' or property = 'post_relatedentries'";


The CORRECT line should be [notice it should be AND (.. or ..) ]:

$q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = ". (int)$eventData['id'] . " AND (property = 'relatedentries' or property = 'post_relatedentries')";

A second issue I corrected... Many URLs included "=" and this plugin would not accept URLs with "=" signs in them. Since I can't recall seeing a URL with a "~" in it, if a tilda is passed in, it will be converted to an = in the final rendering for any URLs that need to include an "=" sign (it's the last few lines of the following code snippet):


case 'backend_save':
if (!isset($serendipity['POST']['properties']) || !is_array($serendipity['POST']['properties']) || !isset($eventData['id'])) {
return true;
}

$links = (array)explode("\n", str_replace("\r", '', $serendipity['POST']['properties']['relatedentries']));

$html_links = array();
foreach ($links AS $link) {
if (empty($link)) {
continue;
}

$parts = explode('=', $link);
if (empty($parts[1])) {
$parts[1] = $parts[0];
}

$html_links[] = array(
'url' => $parts[0],
'title' => htmlspecialchars($parts[1])
);
}

//converts any case of "~" to "=" in URL
for ($j=0;$j<count($html_links);$j++){
$html_links[$j] = str_replace("~","=",$html_links[$j]);
}

Re: Related Links - BAD BAD BUG! .. and fix .. and new featu

Posted: Sun Apr 30, 2006 12:26 pm
by garvinhicking
Hi!

Thanks a lot for this fix! However I wonder when is a bug a simple bug, when is it a bad bug, and when a BAD BAD BUG ;-)))

I also made the "=" character configurable instead, so that you can now choose to use "|" to split your links. I think that is the more workable approach?

(BTW, "~" does in fact happen to be contained in URLs!)

Many thanks,
Garvin

Posted: Mon May 01, 2006 6:53 am
by hotroast
funny - I had actually thought of using | too but decided to use ~ since I couldn't recall seeing it recently in any of the many URLs I've seen lately. Your solution is of course the best - make it configurable! Regarding BAD BAD bug - I qualified it as such because it would actually lead to corruption/deletion of data that people thought was safely stored away in the database. Thanks again for all your great work with serendipity!

Posted: Mon May 01, 2006 2:11 pm
by garvinhicking
You're welcome! Thanks a lot for your help. :)

Regards,
Garvin