//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;
-}
$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', '') );
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
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;
+ }
}
$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();
+++ /dev/null
-<script>
-
-function showHideDates() {
- if( $('#posted-date-selector-drop').is(':visible')) {
- $('#posted-date-selector-drop').hide();
- $('#posted-date-collapse').html(window.showMore);
-
- } else {
- $('#posted-date-selector-drop').show();
- $('#posted-date-collapse').html(window.showFewer);
- }
-}
-
-function dateSubmit(dateurl) {
- window.location.href = dateurl;
-}
-
-</script>
-
-
-<div id="datebrowse-sidebar" class="widget">
- <h3>{{$title}}</h3>
- <ul id="posted-date-selector" class="datebrowse-ul">
- {{foreach $dates as $y => $arr}}
-
- {{if $y == $cutoff_year}}
- </ul>
- <ul id="posted-date-selector-drop" class="datebrowse-ul" style="display: none;">
- {{/if}}
-
- <li id="posted-date-selector-year-{{$y}}" class="tool">
- <a class="datebrowse-link" href="#" onclick="openClose('posted-date-selector-{{$y}}'); return false;">{{$y}}</a>
- </li>
- <li id="posted-date-selector-{{$y}}" class="tool posted-date-selector-months" style="display: none;">
- <ul class="datebrowse-ul">
- {{foreach $arr as $d}}
- <li class="tool">
- <a class="datebrowse-link" href="#" onclick="dateSubmit('{{$url}}/{{$d.1}}/{{$d.2}}'); return false;">{{$d.0}}</a>
- </li>
- {{/foreach}}
- </ul>
- </li>
- {{/foreach}}
- </ul>
- {{if $cutoff}}
- <ul class="datebrowse-ul">
- <li onclick="showHideDates(); return false;" id="posted-date-collapse" class="fakelink tool">{{$showmore}}</li>
- </ul>
- {{/if}}
-</div>
--- /dev/null
+<script>
+function showHideDates() {
+ if( $('#posted-date-selector-drop').is(':visible')) {
+ $('#posted-date-selector-drop').hide();
+ $('#posted-date-collapse').html(window.showMore);
+
+ } else {
+ $('#posted-date-selector-drop').show();
+ $('#posted-date-collapse').html(window.showFewer);
+ }
+}
+</script>
+
+<div id="datebrowse-sidebar" class="widget">
+ <h3>{{$title}}</h3>
+ <ul id="posted-date-selector" class="datebrowse-ul">
+ {{foreach $dates as $y => $arr}}
+
+ {{if $y == $cutoff_year}}
+ </ul>
+ <ul id="posted-date-selector-drop" class="datebrowse-ul" style="display: none;">
+ {{/if}}
+
+ <li id="posted-date-selector-year-{{$y}}" class="tool">
+ <a class="datebrowse-link" href="#" onclick="openClose('posted-date-selector-{{$y}}'); return false;">{{$y}}</a>
+ </li>
+ <li id="posted-date-selector-{{$y}}" class="tool posted-date-selector-months" style="display: none;">
+ <ul class="datebrowse-ul">
+ {{foreach $arr as $d}}
+ <li class="tool">
+ <a class="datebrowse-link" href="{{$url}}/{{$d.1}}/{{$d.2}}">{{$d.0}}</a>
+ </li>
+ {{/foreach}}
+ </ul>
+ </li>
+ {{/foreach}}
+ </ul>
+ {{if $cutoff}}
+ <ul class="datebrowse-ul">
+ <li onclick="showHideDates(); return false;" id="posted-date-collapse" class="fakelink tool">{{$showmore}}</li>
+ </ul>
+ {{/if}}
+</div>