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
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
class Archive
|
|
|
|
{
|
2017-03-16 02:30:57 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
public function widget($arr)
|
|
|
|
{
|
2017-03-16 02:30:57 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$o = '';
|
2017-03-16 02:30:57 +00:00
|
|
|
|
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
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$wall = ((array_key_exists('wall', $arr)) ? intval($arr['wall']) : 0);
|
|
|
|
$wall = ((array_key_exists('articles', $arr)) ? 2 : $wall);
|
2018-08-22 20:30:16 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$style = ((array_key_exists('style', $arr)) ? $arr['style'] : 'select');
|
|
|
|
$showend = ((get_pconfig($uid, 'system', 'archive_show_end_date')) ? true : false);
|
|
|
|
$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;
|
|
|
|
$cutoff = ((array_key_exists($cutoff_year, $ret)) ? true : false);
|
2017-03-16 02:30:57 +00:00
|
|
|
|
2022-02-12 20:43:29 +00:00
|
|
|
$o = replace_macros(Theme::get_template('posted_date_widget.tpl'), array(
|
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
|
|
|
|
));
|
|
|
|
return $o;
|
|
|
|
}
|
2017-03-16 02:30:57 +00:00
|
|
|
}
|