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

Discussion corner for Developers of Serendipity.
Post Reply
hotroast
Regular
Posts: 12
Joined: Tue Mar 28, 2006 7:04 am

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

Post 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]);
}
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

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

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
hotroast
Regular
Posts: 12
Joined: Tue Mar 28, 2006 7:04 am

Post 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!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

You're welcome! Thanks a lot for your help. :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply