From d27d4d892796de250d723b1ae620d70dc20f9b2d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 25 May 2019 19:08:15 -0400 Subject: [PATCH 1/2] Move posted date widget to Content\Widget --- include/items.php | 77 ------------------- mod/network.php | 2 +- src/Content/Widget.php | 73 ++++++++++++++++++ src/Module/Profile.php | 2 +- .../posted_date.tpl} | 9 +-- 5 files changed, 76 insertions(+), 87 deletions(-) rename view/templates/{posted_date_widget.tpl => widget/posted_date.tpl} (86%) diff --git a/include/items.php b/include/items.php index a28e19a05a..25c857f115 100644 --- a/include/items.php +++ b/include/items.php @@ -446,80 +446,3 @@ function drop_item($id, $return = '') //NOTREACHED } } - -/* arrange the list in years */ -function list_post_dates($uid, $wall) -{ - $dnow = DateTimeFormat::localNow('Y-m-d'); - - $dthen = Item::firstPostDate($uid, $wall); - if (!$dthen) { - return []; - } - - // Set the start and end date to the beginning of the month - $dnow = substr($dnow, 0, 8) . '01'; - $dthen = substr($dthen, 0, 8) . '01'; - - $ret = []; - - /* - * Starting with the current month, get the first and last days of every - * month down to and including the month of the first post - */ - while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { - $dyear = intval(substr($dnow, 0, 4)); - $dstart = substr($dnow, 0, 8) . '01'; - $dend = substr($dnow, 0, 8) . Temporal::getDaysInMonth(intval($dnow), intval(substr($dnow, 5))); - $start_month = DateTimeFormat::utc($dstart, 'Y-m-d'); - $end_month = DateTimeFormat::utc($dend, 'Y-m-d'); - $str = L10n::getDay(DateTimeFormat::utc($dnow, 'F')); - - if (empty($ret[$dyear])) { - $ret[$dyear] = []; - } - - $ret[$dyear][] = [$str, $end_month, $start_month]; - $dnow = DateTimeFormat::utc($dnow . ' -1 month', 'Y-m-d'); - } - return $ret; -} - -function posted_date_widget($url, $uid, $wall) -{ - $o = ''; - - if (!Feature::isEnabled($uid, 'archives')) { - return $o; - } - - // For former Facebook folks that left because of "timeline" - /* - * @TODO old-lost code? - if ($wall && intval(PConfig::get($uid, 'system', 'no_wall_archive_widget'))) - return $o; - */ - - $visible_years = PConfig::get($uid, 'system', 'archive_visible_years', 5); - - $ret = list_post_dates($uid, $wall); - - if (!DBA::isResult($ret)) { - return $o; - } - - $cutoff_year = intval(DateTimeFormat::localNow('Y')) - $visible_years; - $cutoff = ((array_key_exists($cutoff_year, $ret))? true : false); - - $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('posted_date_widget.tpl'),[ - '$title' => L10n::t('Archives'), - '$size' => $visible_years, - '$cutoff_year' => $cutoff_year, - '$cutoff' => $cutoff, - '$url' => $url, - '$dates' => $ret, - '$showmore' => L10n::t('show more') - - ]); - return $o; -} diff --git a/mod/network.php b/mod/network.php index 30e31cea3c..c8786b2f7b 100644 --- a/mod/network.php +++ b/mod/network.php @@ -154,7 +154,7 @@ function network_init(App $a) $a->page['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id); $a->page['aside'] .= ForumManager::widget(local_user(), $cid); - $a->page['aside'] .= posted_date_widget('network', local_user(), false); + $a->page['aside'] .= Widget::postedByYear('network', local_user(), false); $a->page['aside'] .= Widget::networks('network', defaults($_GET, 'nets', '') ); $a->page['aside'] .= saved_searches($search); $a->page['aside'] .= Widget::fileAs('network', defaults($_GET, 'file', '') ); diff --git a/src/Content/Widget.php b/src/Content/Widget.php index e89245cd2b..066c17413a 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -15,9 +15,12 @@ use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\FileTag; use Friendica\Model\GContact; +use Friendica\Model\Item; use Friendica\Model\Profile; +use Friendica\Util\DateTimeFormat; use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Strings; +use Friendica\Util\Temporal; use Friendica\Util\XML; class Widget @@ -444,4 +447,74 @@ class Widget return ''; } + + /** + * @param string $url Base page URL + * @param int $uid User ID consulting/publishing posts + * @param bool $wall True: Posted by User; False: Posted to User (network timeline) + * @return string + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public static function postedByYear(string $url, int $uid, bool $wall) + { + $o = ''; + + if (!Feature::isEnabled($uid, 'archives')) { + return $o; + } + + $visible_years = PConfig::get($uid, 'system', 'archive_visible_years', 5); + + /* arrange the list in years */ + $dnow = DateTimeFormat::localNow('Y-m-d'); + + $ret = []; + + $dthen = Item::firstPostDate($uid, $wall); + if ($dthen) { + // Set the start and end date to the beginning of the month + $dnow = substr($dnow, 0, 8) . '01'; + $dthen = substr($dthen, 0, 8) . '01'; + + /* + * Starting with the current month, get the first and last days of every + * month down to and including the month of the first post + */ + while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { + $dyear = intval(substr($dnow, 0, 4)); + $dstart = substr($dnow, 0, 8) . '01'; + $dend = substr($dnow, 0, 8) . Temporal::getDaysInMonth(intval($dnow), intval(substr($dnow, 5))); + $start_month = DateTimeFormat::utc($dstart, 'Y-m-d'); + $end_month = DateTimeFormat::utc($dend, 'Y-m-d'); + $str = L10n::getDay(DateTimeFormat::utc($dnow, 'F')); + + if (empty($ret[$dyear])) { + $ret[$dyear] = []; + } + + $ret[$dyear][] = [$str, $end_month, $start_month]; + $dnow = DateTimeFormat::utc($dnow . ' -1 month', 'Y-m-d'); + } + } + + if (!DBA::isResult($ret)) { + return $o; + } + + + $cutoff_year = intval(DateTimeFormat::localNow('Y')) - $visible_years; + $cutoff = array_key_exists($cutoff_year, $ret); + + $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/posted_date.tpl'),[ + '$title' => L10n::t('Archives'), + '$size' => $visible_years, + '$cutoff_year' => $cutoff_year, + '$cutoff' => $cutoff, + '$url' => $url, + '$dates' => $ret, + '$showmore' => L10n::t('show more') + ]); + + return $o; + } } diff --git a/src/Module/Profile.php b/src/Module/Profile.php index 1a515073dd..30dee0cb56 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -193,7 +193,7 @@ class Profile extends BaseModule $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY; $commvisitor = $commpage && $remote_contact; - $a->page['aside'] .= posted_date_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true); + $a->page['aside'] .= Widget::postedByYear(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true); $a->page['aside'] .= Widget::categories(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (!empty($category) ? XML::escape($category) : '')); $a->page['aside'] .= Widget::tagCloud(); diff --git a/view/templates/posted_date_widget.tpl b/view/templates/widget/posted_date.tpl similarity index 86% rename from view/templates/posted_date_widget.tpl rename to view/templates/widget/posted_date.tpl index 7833aee4cb..42c04d2266 100644 --- a/view/templates/posted_date_widget.tpl +++ b/view/templates/widget/posted_date.tpl @@ -1,5 +1,4 @@ -

{{$title}}