<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
namespace Friendica\Content;
use Friendica\Core\Addon;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
-use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
-use Friendica\Model\FileTag;
-use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\Item;
-use Friendica\Model\Profile;
+use Friendica\Model\Post;
use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Strings;
use Friendica\Util\Temporal;
class Widget
$extra_sql = self::unavailableNetworks();
- $r = DBA::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND NOT `deleted` AND `network` != '' $extra_sql ORDER BY `network`",
+ $r = DBA::p("SELECT `network` FROM `contact` WHERE `uid` = ? AND NOT `deleted` AND `network` != '' $extra_sql GROUP BY `network` ORDER BY `network`",
local_user()
);
return '';
}
- $saved = DI::pConfig()->get(local_user(), 'system', 'filetags');
- if (!strlen($saved)) {
- return;
- }
-
$terms = [];
- foreach (FileTag::fileToArray($saved) as $savedFolderName) {
+ foreach (Post\Category::getArray(local_user(), Post\Category::FILE) as $savedFolderName) {
$terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName];
}
-
- usort($terms, function ($a, $b) {
- return strcmp($a['name'], $b['name']);
- });
return self::filter(
'file',
{
$a = DI::app();
- $uid = intval($a->profile['uid']);
+ $uid = intval($a->getProfileOwner());
if (!Feature::isEnabled($uid, 'categories')) {
return '';
}
- $saved = DI::pConfig()->get($uid, 'system', 'filetags');
- if (!strlen($saved)) {
- return;
- }
-
$terms = array();
- foreach (FileTag::fileToArray($saved, 'category') as $savedFolderName) {
+ foreach (Post\Category::getArray(local_user(), Post\Category::CATEGORY) as $savedFolderName) {
$terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName];
}
$entries = [];
foreach ($commonContacts as $contact) {
$entries[] = [
- 'url' => Contact::magicLink($contact['url']),
+ 'url' => Contact::magicLinkByContact($contact),
'name' => $contact['name'],
'photo' => Contact::getThumb($contact),
];
/**
* Insert a tag cloud widget for the present profile.
*
+ * @param int $uid User ID
* @param int $limit Max number of displayed tags.
* @return string HTML formatted output.
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function tagCloud($limit = 50)
+ public static function tagCloud(int $uid, int $limit = 50)
{
- $a = DI::app();
-
- $uid = intval($a->profile['uid']);
-
- if (!$uid || !$a->profile['url']) {
+ if (empty($uid)) {
return '';
}
if (Feature::isEnabled($uid, 'tagadelic')) {
- $owner_id = Contact::getIdForURL($a->profile['url'], 0, false);
+ $owner_id = Contact::getPublicIdByUserId($uid);
if (!$owner_id) {
return '';
$ret = [];
- $dthen = Item::firstPostDate($uid, $wall);
+ $cachekey = 'Widget::postedByYear' . $uid . '-' . (int)$wall;
+ $dthen = DI::cache()->get($cachekey);
+ if (empty($dthen)) {
+ $dthen = Item::firstPostDate($uid, $wall);
+ DI::cache()->set($cachekey, $dthen, Duration::HOUR);
+ }
+
if ($dthen) {
// Set the start and end date to the beginning of the month
$dnow = substr($dnow, 0, 8) . '01';
'$cutoff' => $cutoff,
'$url' => $url,
'$dates' => $ret,
+ '$showless' => DI::l10n()->t('show less'),
'$showmore' => DI::l10n()->t('show more')
]);
return $o;
}
+
+ /**
+ * Display the account types sidebar
+ * The account type value is added as a parameter to the url
+ *
+ * @param string $base Basepath
+ * @param int $accounttype Acount type
+ * @return string
+ */
+ public static function accounttypes(string $base, $accounttype)
+ {
+ $accounts = [
+ ['ref' => 'person', 'name' => DI::l10n()->t('Persons')],
+ ['ref' => 'organisation', 'name' => DI::l10n()->t('Organisations')],
+ ['ref' => 'news', 'name' => DI::l10n()->t('News')],
+ ['ref' => 'community', 'name' => DI::l10n()->t('Forums')],
+ ];
+
+ return self::filter('accounttype', DI::l10n()->t('Account Types'), '',
+ DI::l10n()->t('All'), $base, $accounts, $accounttype);
+ }
}