mirror of
https://github.com/friendica/friendica
synced 2024-12-23 07:20:15 +00:00
Move posted date widget to Content\Widget
This commit is contained in:
parent
5c2cca432f
commit
d27d4d8927
5 changed files with 76 additions and 87 deletions
|
@ -446,80 +446,3 @@ function drop_item($id, $return = '')
|
||||||
//NOTREACHED
|
//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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ function network_init(App $a)
|
||||||
|
|
||||||
$a->page['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
|
$a->page['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
|
||||||
$a->page['aside'] .= ForumManager::widget(local_user(), $cid);
|
$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'] .= Widget::networks('network', defaults($_GET, 'nets', '') );
|
||||||
$a->page['aside'] .= saved_searches($search);
|
$a->page['aside'] .= saved_searches($search);
|
||||||
$a->page['aside'] .= Widget::fileAs('network', defaults($_GET, 'file', '') );
|
$a->page['aside'] .= Widget::fileAs('network', defaults($_GET, 'file', '') );
|
||||||
|
|
|
@ -15,9 +15,12 @@ use Friendica\Database\DBA;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\FileTag;
|
use Friendica\Model\FileTag;
|
||||||
use Friendica\Model\GContact;
|
use Friendica\Model\GContact;
|
||||||
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Proxy as ProxyUtils;
|
use Friendica\Util\Proxy as ProxyUtils;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
use Friendica\Util\Temporal;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
|
||||||
class Widget
|
class Widget
|
||||||
|
@ -444,4 +447,74 @@ class Widget
|
||||||
|
|
||||||
return '';
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,7 @@ class Profile extends BaseModule
|
||||||
$commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
|
$commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
|
||||||
$commvisitor = $commpage && $remote_contact;
|
$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::categories(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (!empty($category) ? XML::escape($category) : ''));
|
||||||
$a->page['aside'] .= Widget::tagCloud();
|
$a->page['aside'] .= Widget::tagCloud();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function showHideDates() {
|
function showHideDates() {
|
||||||
if( $('#posted-date-selector-drop').is(':visible')) {
|
if( $('#posted-date-selector-drop').is(':visible')) {
|
||||||
$('#posted-date-selector-drop').hide();
|
$('#posted-date-selector-drop').hide();
|
||||||
|
@ -10,14 +9,8 @@ function showHideDates() {
|
||||||
$('#posted-date-collapse').html(window.showFewer);
|
$('#posted-date-collapse').html(window.showFewer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateSubmit(dateurl) {
|
|
||||||
window.location.href = dateurl;
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<div id="datebrowse-sidebar" class="widget">
|
<div id="datebrowse-sidebar" class="widget">
|
||||||
<h3>{{$title}}</h3>
|
<h3>{{$title}}</h3>
|
||||||
<ul id="posted-date-selector" class="datebrowse-ul">
|
<ul id="posted-date-selector" class="datebrowse-ul">
|
||||||
|
@ -35,7 +28,7 @@ function dateSubmit(dateurl) {
|
||||||
<ul class="datebrowse-ul">
|
<ul class="datebrowse-ul">
|
||||||
{{foreach $arr as $d}}
|
{{foreach $arr as $d}}
|
||||||
<li class="tool">
|
<li class="tool">
|
||||||
<a class="datebrowse-link" href="#" onclick="dateSubmit('{{$url}}/{{$d.1}}/{{$d.2}}'); return false;">{{$d.0}}</a>
|
<a class="datebrowse-link" href="{{$url}}/{{$d.1}}/{{$d.2}}">{{$d.0}}</a>
|
||||||
</li>
|
</li>
|
||||||
{{/foreach}}
|
{{/foreach}}
|
||||||
</ul>
|
</ul>
|
Loading…
Reference in a new issue