streams/Code/Widget/Archive.php

61 lines
1.6 KiB
PHP
Raw Normal View History

2017-03-16 02:30:57 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Widget;
2017-03-16 02:30:57 +00:00
2021-12-02 22:33:36 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Lib\Features;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2021-12-02 22:33:36 +00:00
2022-10-23 21:18:44 +00:00
class Archive implements WidgetInterface
2021-12-02 23:02:31 +00:00
{
2017-03-16 02:30:57 +00:00
2022-10-24 03:39:49 +00:00
public function widget(array $arguments): string
2021-12-02 23:02:31 +00:00
{
if (!App::$profile_uid) {
return '';
}
2017-03-16 02:30:57 +00:00
2021-12-02 23:02:31 +00:00
$uid = App::$profile_uid;
2017-03-16 02:30:57 +00:00
2022-01-25 23:20:02 +00:00
if (!Features::enabled($uid, 'archives')) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2017-03-16 02:30:57 +00:00
2021-12-03 03:01:39 +00:00
if (!perm_is_allowed($uid, get_observer_hash(), 'view_stream')) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2017-03-16 02:30:57 +00:00
2022-10-24 03:39:49 +00:00
$wall = ((array_key_exists('wall', $arguments)) ? intval($arguments['wall']) : 0);
$wall = ((array_key_exists('articles', $arguments)) ? 2 : $wall);
2018-08-22 20:30:16 +00:00
2022-10-24 03:39:49 +00:00
$style = ((array_key_exists('style', $arguments)) ? $arguments['style'] : 'select');
2022-10-23 21:18:44 +00:00
$showend = (bool)get_pconfig($uid, 'system', 'archive_show_end_date');
2021-12-02 23:02:31 +00:00
$mindate = get_pconfig($uid, 'system', 'archive_mindate');
$visible_years = get_pconfig($uid, 'system', 'archive_visible_years', 5);
2017-03-16 02:30:57 +00:00
2021-12-02 23:02:31 +00:00
$url = z_root() . '/' . App::$cmd;
2017-03-16 02:30:57 +00:00
2021-12-02 23:02:31 +00:00
$ret = list_post_dates($uid, $wall, $mindate);
2017-03-16 02:30:57 +00:00
2021-12-03 03:01:39 +00:00
if (!count($ret)) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2017-03-16 02:30:57 +00:00
2021-12-02 23:02:31 +00:00
$cutoff_year = intval(datetime_convert('', date_default_timezone_get(), 'now', 'Y')) - $visible_years;
2022-10-23 21:18:44 +00:00
$cutoff = array_key_exists($cutoff_year, $ret);
2017-03-16 02:30:57 +00:00
2022-10-23 21:18:44 +00:00
return replace_macros(Theme::get_template('posted_date_widget.tpl'), [
2021-12-02 23:02:31 +00:00
'$title' => t('Archives'),
'$size' => $visible_years,
'$cutoff_year' => $cutoff_year,
'$cutoff' => $cutoff,
'$url' => $url,
'$style' => $style,
'$showend' => $showend,
'$dates' => $ret
2022-10-23 21:18:44 +00:00
]);
2021-12-02 23:02:31 +00:00
}
2017-03-16 02:30:57 +00:00
}