History plugin improvement

Discussion corner for Developers of Serendipity.
Post Reply
gimmel
Regular
Posts: 118
Joined: Tue Jul 25, 2006 2:44 pm
Location: Quickborn/Germany
Contact:

History plugin improvement

Post by gimmel »

The new version of the history plugin (v1.5, shipped with s9y 1.4) has a little „bug“. If author and date are suppressed, the (X)HTML output contains empty spans although.

I changed this

Code: Select all

$date   = ($displaydate=='0') ? '' : serendipity_strftime($dateformat,$e[$x]['timestamp']);
$author = ($displayauthor) ? $e[$x]['author'] . ': ' : '';
$t = ($maxlength==0 || strlen($e[$x]['title'])<=$maxlength) ?
    $e[$x]['title'] :
    (trim(serendipity_mb('substr', $e[$x]['title'], 0, $maxlength-3)).' [...]');
echo '<div class="serendipity_history_info"><span class="serendipity_history_author">' . $author . '</span> <span class="serendipity_history_date">'. $date . "</span> <a href='$url' title='".str_replace("'", '`', htmlspecialchars($e[$x]['title']))."'>". htmlspecialchars($t) . '</a></div>' . '<div class="serendipity_history_body">' .
    strip_tags($e[$x]['body']) . '</div>';
to that

Code: Select all

echo '<div class="serendipity_history_info">';
if ($displayauthor)
    { echo '<span class="serendipity_history_author">' . $e[$x]['author'] . ': </span>'; }
if ($displaydate)
    { echo '<span class="serendipity_history_date">'. serendipity_strftime($dateformat,$e[$x]['timestamp']) . ' </span>'; }
$t = ($maxlength==0 || strlen($e[$x]['title'])<=$maxlength) ?
    $e[$x]['title'] :
    (trim(serendipity_mb('substr', $e[$x]['title'], 0, $maxlength-3)).' [...]');
echo "<a href=" . $url . " title='".str_replace("'", "`", htmlspecialchars($e[$x]['title']))."'>". htmlspecialchars($t) . "</a></div>";
echo '<div class="serendipity_history_body">' . strip_tags($e[$x]['body']) . '</div>';
to correct that problem.

Yes, I am the other one who uses this plugin, yellowled… ;-)
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: History plugin improvement

Post by yellowled »

gimmel wrote:Yes, I am the other one who uses this plugin, yellowled… ;-)
Sweet $DEITY, I'm not alone out there :wink:

I'll submit those to svn asap. Thanks!

YL
gimmel
Regular
Posts: 118
Joined: Tue Jul 25, 2006 2:44 pm
Location: Quickborn/Germany
Contact:

Wrong year in history plugin

Post by gimmel »

Another little bug: „One year ago“ calculates one day to late.

Code: Select all

if (!is_numeric($min_age) || $min_age < 0 || $specialage == 'year') {
    $min_age = 365 + date('L', serendipity_serverOffsetHour());
}
A year has 365 days, that's right. But if you start e.g. on 1.1.2008 the 365th day is 31.12.2008. To get the 1.1.2009 you need an offset of 366.

Anyway, the date should not be generated by offset, because of leap years. Why not calculating the date by DD.MM.YYYY-1 ?
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: History plugin improvement

Post by yellowled »

Another little bug here. This:

Code: Select all

echo "<a href=" . $url . " title='".str_replace("'", "`", htmlspecialchars($e[$x]['title']))."'>". htmlspecialchars($t) . "</a></div>";
emits invalid HTML since the URL is not included in " - probably due to incorrectly masked instances of those. I'm not sure I understand the PHP code here fully, so someone please help me out.

Also, we should probably add a check whether this:

Code: Select all

echo '<div class="serendipity_history_body">' . strip_tags($e[$x]['body']) . '</div>';
is actually supposed to be emitted (there's a config option for that now, right?).

YL
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: History plugin improvement

Post by yellowled »

Resolved. (Both of them.) :)

YL
gimmel
Regular
Posts: 118
Joined: Tue Jul 25, 2006 2:44 pm
Location: Quickborn/Germany
Contact:

Re: History plugin improvement

Post by gimmel »

Thanks a lot!
Do you still use an offset (366) or a search for the date?
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: History plugin improvement

Post by yellowled »

gimmel wrote:Do you still use an offset (366) or a search for the date?
I have not interfered with the actual functionality of the plugin at all, so it's still using whatever it was using before :)

YL
Post Reply