use Friendica\Content\ForumManager;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
+use Friendica\Content\Widget\ContactBlock;
use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
-use Friendica\Model\Contact;
use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
if (!DBA::isResult($user) && empty($profiledata)) {
Logger::log('profile error: ' . $a->query_string, Logger::DEBUG);
notice(L10n::t('Requested account is not available.') . EOL);
- $a->error = 404;
return;
}
if (empty($pdata) && empty($profiledata)) {
Logger::log('profile error: ' . $a->query_string, Logger::DEBUG);
notice(L10n::t('Requested profile is not available.') . EOL);
- $a->error = 404;
return;
}
$contact_block = '';
$updated = '';
- $contacts = 0;
+ $contact_count = 0;
if (!$block) {
- $contact_block = HTML::contactBlock();
+ $contact_block = ContactBlock::getHTML($a->profile);
if (is_array($a->profile) && !$a->profile['hide-friends']) {
$r = q(
$updated = date('c', strtotime($r[0]['updated']));
}
- $r = q(
- "SELECT COUNT(*) AS `total` FROM `contact`
- WHERE `uid` = %d
- AND NOT `self` AND NOT `blocked` AND NOT `pending`
- AND NOT `hidden` AND NOT `archive`
- AND `network` IN ('%s', '%s', '%s', '')",
- intval($profile['uid']),
- DBA::escape(Protocol::DFRN),
- DBA::escape(Protocol::DIASPORA),
- DBA::escape(Protocol::OSTATUS)
- );
- if (DBA::isResult($r)) {
- $contacts = intval($r[0]['total']);
- }
+ $contact_count = DBA::count('contact', [
+ 'uid' => $profile['uid'],
+ 'self' => false,
+ 'blocked' => false,
+ 'pending' => false,
+ 'hidden' => false,
+ 'archive' => false,
+ 'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA],
+ ]);
}
}
'$homepage' => $homepage,
'$about' => $about,
'$network' => L10n::t('Network:'),
- '$contacts' => $contacts,
+ '$contacts' => $contact_count,
'$updated' => $updated,
'$diaspora' => $diaspora,
'$contact_block' => $contact_block,
}
$tpl = Renderer::getMarkupTemplate('birthdays_reminder.tpl');
return Renderer::replaceMacros($tpl, [
- '$baseurl' => System::baseUrl(),
'$classtoday' => $classtoday,
'$count' => $total,
'$event_reminders' => L10n::t('Birthday Reminders'),
}
$tpl = Renderer::getMarkupTemplate('events_reminder.tpl');
return Renderer::replaceMacros($tpl, [
- '$baseurl' => System::baseUrl(),
'$classtoday' => $classtoday,
'$count' => count($r),
'$event_reminders' => L10n::t('Event Reminders'),
public static function getAdvanced(App $a)
{
- $o = '';
$uid = $a->profile['uid'];
- $o .= Renderer::replaceMacros(
- Renderer::getMarkupTemplate('section_title.tpl'),
- ['$title' => L10n::t('Profile')]
- );
-
if ($a->profile['name']) {
$tpl = Renderer::getMarkupTemplate('profile_advanced.tpl');
$profile['marital']['with'] = $a->profile['with'];
}
- if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= DBA::NULL_DATETIME) {
+ if (strlen($a->profile['howlong']) && $a->profile['howlong'] > DBA::NULL_DATETIME) {
$profile['howlong'] = Temporal::getRelativeDate($a->profile['howlong'], L10n::t('for %1$d %2$s'));
}
}
/**
- * OpenWebAuth authentication.
+ * Set the visitor cookies (see remote_user()) for the given handle
*
- * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/zid.php
- *
- * @param string $token
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @throws \ImagickException
+ * @param string $handle Visitor handle
+ * @return array Visitor contact array
*/
- public static function openWebAuthInit($token)
+ public static function addVisitorCookieForHandle($handle)
{
$a = \get_app();
- // Clean old OpenWebAuthToken entries.
- OpenWebAuthToken::purge('owt', '3 MINUTE');
-
- // Check if the token we got is the same one
- // we have stored in the database.
- $visitor_handle = OpenWebAuthToken::getMeta('owt', 0, $token);
-
- if($visitor_handle === false) {
- return;
- }
-
// Try to find the public contact entry of the visitor.
- $cid = Contact::getIdForURL($visitor_handle);
- if(!$cid) {
- Logger::log('owt: unable to finger ' . $visitor_handle, Logger::DEBUG);
- return;
+ $cid = Contact::getIdForURL($handle);
+ if (!$cid) {
+ Logger::log('unable to finger ' . $handle, Logger::DEBUG);
+ return [];
}
$visitor = DBA::selectFirst('contact', [], ['id' => $cid]);
$_SESSION['remote'][] = ['cid' => $contact['id'], 'uid' => $contact['uid'], 'url' => $visitor['url']];
}
+
+ $a->contact = $visitor;
+
+ Logger::info('Authenticated visitor', ['url' => $visitor['url']]);
+
+ return $visitor;
+ }
+
+ /**
+ * OpenWebAuth authentication.
+ *
+ * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/zid.php
+ *
+ * @param string $token
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ public static function openWebAuthInit($token)
+ {
+ $a = \get_app();
+
+ // Clean old OpenWebAuthToken entries.
+ OpenWebAuthToken::purge('owt', '3 MINUTE');
+
+ // Check if the token we got is the same one
+ // we have stored in the database.
+ $visitor_handle = OpenWebAuthToken::getMeta('owt', 0, $token);
+
+ if ($visitor_handle === false) {
+ return;
+ }
+
+ $visitor = self::addVisitorCookieForHandle($visitor_handle);
+ if (empty($visitor)) {
+ return;
+ }
+
$arr = [
'visitor' => $visitor,
'url' => $a->query_string