Skip to content

Commit

Permalink
history plugin: Refactor getHistoryEntries() params
Browse files Browse the repository at this point in the history
  • Loading branch information
ophian committed Jan 6, 2024
1 parent 9ae123a commit 8522429
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions plugins/serendipity_plugin_history/serendipity_plugin_history.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function introspect(&$propbag)
$propbag->add('description', PLUGIN_HISTORY_DESC);
$propbag->add('stackable', true);
$propbag->add('author', 'Jannis Hermanns, Ian Styx');
$propbag->add('version', '1.43');
$propbag->add('version', '1.45');
$propbag->add('requirements', array(
'serendipity' => '2.0',
'smarty' => '3.1',
Expand Down Expand Up @@ -153,10 +153,15 @@ function introspect_config_item($name, &$propbag)
return true;
}

function getHistoryEntries($maxts, $mints, $max_age, $min_age, $full, $max_entries, $maxlength, $intro, $outro, $displaydate, $dateformat, $displayauthor)
function getHistoryEntries($maxts, $mints, $max_age, $min_age = null, $intro = null, $outro = null)
{
global $serendipity;

$max_entries = $this->get_config('max_entries');
if (!is_numeric($max_entries) || $max_entries < 1) {
$max_entries = 5;
}
$full = serendipity_db_bool($this->get_config('full', 'false'));
$oldLim = $serendipity['fetchLimit'];

if (!is_array($max_age) && $min_age !== null) {
Expand Down Expand Up @@ -192,6 +197,17 @@ function getHistoryEntries($maxts, $mints, $max_age, $min_age, $full, $max_entri
return false;
}

$maxlength = $this->get_config('maxlength');
$displaydate = serendipity_db_bool($this->get_config('displaydate', 'true'));
$dateformat = $this->get_config('dateformat');
$displayauthor = serendipity_db_bool($this->get_config('displayauthor', 'false'));
if (!is_numeric($maxlength) || $maxlength < 0) {
$maxlength = 30;
}
if (strlen($dateformat) < 1) {
$dateformat = '%a, %d.%m.%Y %H:%M';
}

$nowts = serendipity_serverOffsetHour();
$elday = date('md', $nowts) == '0229'; // is the current day the explicit leap day ?
$fmrch = date('md', $nowts) == '0301'; // 1st of march day ? true : false, which is the first day of "static" year rest days
Expand Down Expand Up @@ -251,18 +267,12 @@ function generate_content(&$title)
$title = $this->get_config('title', $this->title);
$intro = $this->get_config('intro');
$outro = $this->get_config('outro');
$maxlength = $this->get_config('maxlength');
$max_entries = $this->get_config('max_entries');
$min_age = $this->get_config('min_age');
$max_age = $this->get_config('max_age');
$specialage = $this->get_config('specialage');
$xyears = $this->get_config('multiyears', '1');
$xyempty = $this->get_config('isempty');
$empty_ct = $this->get_config('empty_ct', 0);
$displaydate = serendipity_db_bool($this->get_config('displaydate', 'true'));
$dateformat = $this->get_config('dateformat');
$full = serendipity_db_bool($this->get_config('full', 'false'));
$displayauthor = serendipity_db_bool($this->get_config('displayauthor', 'false'));

$nowts = serendipity_serverOffsetHour();
$maxts = mktime(23, 59, 59, (int) date('m', $nowts), (int) date('d', $nowts), (int) date('Y', $nowts)); // this is todays timestamp at last minute of day
Expand All @@ -276,18 +286,6 @@ function generate_content(&$title)
$max_age = 365 + date('L', serendipity_serverOffsetHour());
}

if (!is_numeric($max_entries) || $max_entries < 1) {
$max_entries = 5;
}

if (!is_numeric($maxlength) || $maxlength < 0) {
$maxlength = 30;
}

if (strlen($dateformat) < 1) {
$dateformat = '%a, %d.%m.%Y %H:%M';
}

if ((int)$xyears > 1 && $specialage == 'year' && (empty($serendipity['calendar']) || $serendipity['calendar'] == 'gregorian')) {
$timeout = ($maxts - $nowts); // the rest of the day
$cached = (($timeout >= 0) && ($maxts > $nowts));
Expand Down Expand Up @@ -345,7 +343,7 @@ function generate_content(&$title)
if (!empty($intro)) {
echo '<div class="serendipity_history_intro">' . $intro . "</div>\n";
}
if (false === $this->getHistoryEntries($maxts, $mints, $multiage, null, $full, $max_entries, $maxlength, null, null, $displaydate, $dateformat, $displayauthor)) {
if (false === $this->getHistoryEntries($maxts, $mints, $multiage)) {
$fallback = true;
}
if (!empty($outro)) {
Expand Down Expand Up @@ -382,7 +380,7 @@ function generate_content(&$title)
}
}
} else {
if (empty($this->getHistoryEntries($maxts, $mints, $max_age, $min_age, $full, $max_entries, $maxlength, $intro, $outro, $displaydate, $dateformat, $displayauthor))) {
if (empty($this->getHistoryEntries($maxts, $mints, $max_age, $min_age, $intro, $outro))) {
if (!empty($xyempty)) {
echo '<div class="serendipity_history_outro history_empty">' . $xyempty . "</div>\n";
}
Expand Down

0 comments on commit 8522429

Please sign in to comment.