Merge pull request #7186 from MrPetovan/bug/7183-archives-profile-widget
Restore profile archives widget
This commit is contained in:
		
				commit
				
					
						ea218438d2
					
				
			
		
					 6 changed files with 77 additions and 87 deletions
				
			
		| 
						 | 
				
			
			@ -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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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', '') );
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -187,6 +187,7 @@ class Router
 | 
			
		|||
		$this->routeCollector->addRoute(['GET'],         '/probe',               Module\Debug\Probe::class);
 | 
			
		||||
		$this->routeCollector->addGroup('/profile', function (RouteCollector $collector) {
 | 
			
		||||
			$collector->addRoute(['GET'], '/{nickname}',                         Module\Profile::class);
 | 
			
		||||
			$collector->addRoute(['GET'], '/{nickname}/{to:\d{4}-\d{2}-\d{2}}/{from:\d{4}-\d{2}-\d{2}}', Module\Profile::class);
 | 
			
		||||
			$collector->addRoute(['GET'], '/{nickname}/contacts[/{type}]',       Module\Profile\Contacts::class);
 | 
			
		||||
			$collector->addRoute(['GET'], '/{profile:\d+}/view',                 Module\Profile::class);
 | 
			
		||||
		});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
<script>
 | 
			
		||||
 | 
			
		||||
function showHideDates() {
 | 
			
		||||
	if( $('#posted-date-selector-drop').is(':visible')) {
 | 
			
		||||
		$('#posted-date-selector-drop').hide();
 | 
			
		||||
| 
						 | 
				
			
			@ -10,14 +9,8 @@ function showHideDates() {
 | 
			
		|||
		$('#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">
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +28,7 @@ function dateSubmit(dateurl) {
 | 
			
		|||
			<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>
 | 
			
		||||
					<a class="datebrowse-link" href="{{$url}}/{{$d.1}}/{{$d.2}}">{{$d.0}}</a>
 | 
			
		||||
				</li>
 | 
			
		||||
				{{/foreach}}
 | 
			
		||||
			</ul>
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue