Merge pull request #10628 from MrPetovan/bug/fatal-errors
Set profile fields for system user in Model\User::getOwnerDataById
This commit is contained in:
commit
9aca4b515f
4 changed files with 46 additions and 27 deletions
|
@ -35,6 +35,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -204,11 +205,13 @@ class Profile
|
|||
* the theme is chosen before the _init() function of a theme is run, which will usually
|
||||
* load a lot of theme-specific content
|
||||
*
|
||||
* @param App $a
|
||||
* @param string $nickname string
|
||||
*
|
||||
* @param App $a
|
||||
* @param string $nickname string
|
||||
* @param bool $show_contacts
|
||||
* @return array Profile
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function load(App $a, string $nickname, bool $show_contacts = true)
|
||||
|
@ -219,6 +222,12 @@ class Profile
|
|||
return [];
|
||||
}
|
||||
|
||||
// System user, aborting
|
||||
if ($profile['uid'] === 0) {
|
||||
DI::logger()->warning('System user found in Profile::load', ['nickname' => $nickname, 'callstack' => System::callstack(20)]);
|
||||
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
||||
}
|
||||
|
||||
$a->setProfileOwner($profile['uid']);
|
||||
|
||||
DI::page()['title'] = $profile['name'] . ' @ ' . DI::config()->get('config', 'sitename');
|
||||
|
@ -246,7 +255,7 @@ class Profile
|
|||
* By now, the contact block isn't shown, when a different profile is given
|
||||
* But: When this profile was on the same server, then we could display the contacts
|
||||
*/
|
||||
DI::page()['aside'] .= self::sidebar($profile, $block, $show_contacts);
|
||||
DI::page()['aside'] .= self::getVCardHtml($profile, $block, $show_contacts);
|
||||
|
||||
return $profile;
|
||||
}
|
||||
|
@ -272,7 +281,7 @@ class Profile
|
|||
* @hooks 'profile_sidebar'
|
||||
* array $arr
|
||||
*/
|
||||
private static function sidebar(array $profile, bool $block, bool $show_contacts)
|
||||
public static function getVCardHtml(array $profile, bool $block, bool $show_contacts)
|
||||
{
|
||||
$o = '';
|
||||
$location = false;
|
||||
|
|
|
@ -149,14 +149,20 @@ class User
|
|||
$system['page-flags'] = User::PAGE_FLAGS_SOAPBOX;
|
||||
$system['account-type'] = $system['contact-type'];
|
||||
$system['guid'] = '';
|
||||
$system['nickname'] = $system['nick'];
|
||||
$system['pubkey'] = $system['pubkey'];
|
||||
$system['locality'] = '';
|
||||
$system['region'] = '';
|
||||
$system['country-name'] = '';
|
||||
$system['net-publish'] = false;
|
||||
$system['picdate'] = '';
|
||||
$system['theme'] = '';
|
||||
$system['publish'] = false;
|
||||
$system['net-publish'] = false;
|
||||
$system['hide-friends'] = true;
|
||||
$system['prv_keywords'] = '';
|
||||
$system['pub_keywords'] = '';
|
||||
$system['address'] = '';
|
||||
$system['locality'] = '';
|
||||
$system['region'] = '';
|
||||
$system['postal-code'] = '';
|
||||
$system['country-name'] = '';
|
||||
$system['homepage'] = DI::baseUrl()->get();
|
||||
$system['dob'] = '0000-00-00';
|
||||
|
||||
// Ensure that the user contains data
|
||||
$user = DBA::selectFirst('user', ['prvkey', 'guid'], ['uid' => 0]);
|
||||
|
|
|
@ -34,13 +34,11 @@ use Friendica\Network\HTTPException;
|
|||
*/
|
||||
class HCard extends BaseModule
|
||||
{
|
||||
public static function rawContent(array $parameters = [])
|
||||
public static function content(array $parameters = [])
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
if ((local_user()) && ($parameters['action'] ?? '') === 'view') {
|
||||
// A logged in user views a profile of a user
|
||||
$nickname = $a->getLoggedInUserNickname();
|
||||
$nickname = DI::app()->getLoggedInUserNickname();
|
||||
} elseif (empty($parameters['action'])) {
|
||||
// Show the profile hCard
|
||||
$nickname = $parameters['profile'];
|
||||
|
@ -48,7 +46,7 @@ class HCard extends BaseModule
|
|||
throw new HTTPException\NotFoundException(DI::l10n()->t('No profile'));
|
||||
}
|
||||
|
||||
$profile = Profile::load($a, $nickname, false);
|
||||
$profile = User::getOwnerDataByNick($nickname);
|
||||
|
||||
if (empty($profile)) {
|
||||
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
||||
|
@ -67,15 +65,6 @@ class HCard extends BaseModule
|
|||
$page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
|
||||
}
|
||||
|
||||
// check if blocked
|
||||
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
|
||||
$keywords = $profile['pub_keywords'] ?? '';
|
||||
$keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
|
||||
if (strlen($keywords)) {
|
||||
$page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
$baseUrl = DI::baseUrl();
|
||||
|
||||
$uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
|
||||
|
@ -88,5 +77,20 @@ class HCard extends BaseModule
|
|||
foreach (['request', 'confirm', 'notify', 'poll'] as $dfrn) {
|
||||
$page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"" . $baseUrl->get() . "/dfrn_{$dfrn}/{$nickname}\" />\r\n";
|
||||
}
|
||||
|
||||
$block = (DI::config()->get('system', 'block_public') && !Session::isAuthenticated());
|
||||
|
||||
// check if blocked
|
||||
if ($block) {
|
||||
$keywords = $profile['pub_keywords'] ?? '';
|
||||
$keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
|
||||
if (strlen($keywords)) {
|
||||
$page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
$page['aside'] = Profile::getVCardHtml($profile, $block, false);
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class Contacts extends Module\BaseProfile
|
|||
|
||||
$is_owner = $profile['uid'] == local_user();
|
||||
|
||||
if (!empty($profile['hide-friends']) && !$is_owner) {
|
||||
if ($profile['hide-friends'] && !$is_owner) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue