+ $hash = null;
+
+ if (!empty($_REQUEST[$formname])) {
+ /// @TODO Careful, not secured!
+ $hash = $_REQUEST[$formname];
+ }
+
+ if (!empty($_SERVER['HTTP_X_CSRF_TOKEN'])) {
+ /// @TODO Careful, not secured!
+ $hash = $_SERVER['HTTP_X_CSRF_TOKEN'];
+ }
+
+ if (empty($hash)) {
+ return false;
+ }
+
+ $max_livetime = 10800; // 3 hours
+
+ $a = DI::app();
+
+ $x = explode('.', $hash);
+ if (time() > (intval($x[0]) + $max_livetime)) {
+ return false;
+ }
+
+ $sec_hash = hash('whirlpool', ($a->user['guid'] ?? '') . ($a->user['prvkey'] ?? '') . session_id() . $x[0] . $typename);
+
+ return ($sec_hash == $x[1]);
+ }
+
+ public static function getFormSecurityStandardErrorMessage()
+ {
+ return DI::l10n()->t("The form security token was not correct. This probably happened because the form has been opened for too long \x28>3 hours\x29 before submitting it.") . EOL;
+ }
+
+ public static function checkFormSecurityTokenRedirectOnError($err_redirect, $typename = '', $formname = 'form_security_token')
+ {
+ if (!self::checkFormSecurityToken($typename, $formname)) {
+ $a = DI::app();
+ Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
+ Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA);
+ notice(self::getFormSecurityStandardErrorMessage());
+ DI::baseUrl()->redirect($err_redirect);
+ }
+ }
+
+ public static function checkFormSecurityTokenForbiddenOnError($typename = '', $formname = 'form_security_token')
+ {
+ if (!self::checkFormSecurityToken($typename, $formname)) {
+ $a = DI::app();
+ Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
+ Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA);
+
+ throw new \Friendica\Network\HTTPException\ForbiddenException();
+ }
+ }
+
+ protected static function getContactFilterTabs(string $baseUrl, string $current, bool $displayCommonTab)
+ {
+ $tabs = [
+ [
+ 'label' => DI::l10n()->t('All contacts'),
+ 'url' => $baseUrl . '/contacts',
+ 'sel' => !$current || $current == 'all' ? 'active' : '',
+ ],
+ [
+ 'label' => DI::l10n()->t('Followers'),
+ 'url' => $baseUrl . '/contacts/followers',
+ 'sel' => $current == 'followers' ? 'active' : '',
+ ],
+ [
+ 'label' => DI::l10n()->t('Following'),
+ 'url' => $baseUrl . '/contacts/following',
+ 'sel' => $current == 'following' ? 'active' : '',
+ ],
+ [
+ 'label' => DI::l10n()->t('Mutual friends'),
+ 'url' => $baseUrl . '/contacts/mutuals',
+ 'sel' => $current == 'mutuals' ? 'active' : '',
+ ],
+ ];
+
+ if ($displayCommonTab) {
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Common'),
+ 'url' => $baseUrl . '/contacts/common',
+ 'sel' => $current == 'common' ? 'active' : '',
+ ];
+ }