X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FACL.php;h=9abd259acd0550f60c59f924aafed59f24ed5115;hb=4bf27019125f0426aef952f3bbb166b3bd12ca46;hp=b822d1f31d74b0eb72536a5c65a07ebfb85d84ac;hpb=ecea7425f8ad11ace4af39d476919e3203bff44f;p=friendica.git diff --git a/src/Core/ACL.php b/src/Core/ACL.php index b822d1f31d..9abd259acd 100644 --- a/src/Core/ACL.php +++ b/src/Core/ACL.php @@ -8,6 +8,8 @@ namespace Friendica\Core; use Friendica\BaseObject; use Friendica\Content\Feature; +use Friendica\Core\Protocol; +use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\GContact; @@ -16,7 +18,7 @@ use Friendica\Util\Network; /** * Handle ACL management and display * - * @author Hypolite Petovan + * @author Hypolite Petovan */ class ACL extends BaseObject { @@ -46,22 +48,21 @@ class ACL extends BaseObject switch (defaults($options, 'networks', Protocol::PHANTOM)) { case 'DFRN_ONLY': - $networks = [NETWORK_DFRN]; + $networks = [Protocol::DFRN]; break; + case 'PRIVATE': - if (!empty($a->user['prvnets'])) { - $networks = [NETWORK_DFRN, NETWORK_MAIL, NETWORK_DIASPORA]; - } else { - $networks = [NETWORK_DFRN, NETWORK_FACEBOOK, NETWORK_MAIL, NETWORK_DIASPORA]; - } + $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]; break; + case 'TWO_WAY': if (!empty($a->user['prvnets'])) { - $networks = [NETWORK_DFRN, NETWORK_MAIL, NETWORK_DIASPORA]; + $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]; } else { - $networks = [NETWORK_DFRN, NETWORK_FACEBOOK, NETWORK_MAIL, NETWORK_DIASPORA, NETWORK_OSTATUS]; + $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA, Protocol::OSTATUS]; } break; + default: /// @TODO Maybe log this call? break; } @@ -75,7 +76,7 @@ class ACL extends BaseObject $sql_extra = ''; if (!empty($x['mutual'])) { - $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND)); + $sql_extra .= sprintf(" AND `rel` = %d ", intval(Contact::FRIEND)); } if (!empty($x['exclude'])) { @@ -85,7 +86,7 @@ class ACL extends BaseObject if (!empty($x['networks'])) { /// @TODO rewrite to foreach() array_walk($x['networks'], function (&$value) { - $value = "'" . dbesc($value) . "'"; + $value = "'" . DBA::escape($value) . "'"; }); $str_nets = implode(',', $x['networks']); $sql_extra .= " AND `network` IN ( $str_nets ) "; @@ -151,8 +152,8 @@ class ACL extends BaseObject // When used for private messages, we limit correspondence to mutual DFRN/Friendica friends and the selector // to one recipient. By default our selector allows multiple selects amongst all contacts. - $sql_extra = sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND)); - $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ", NETWORK_DFRN, NETWORK_DIASPORA); + $sql_extra = sprintf(" AND `rel` = %d ", intval(Contact::FRIEND)); + $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ", Protocol::DFRN, Protocol::DIASPORA); $tabindex_attr = !empty($tabindex) ? ' tabindex="' . intval($tabindex) . '"' : ''; @@ -251,19 +252,18 @@ class ACL extends BaseObject /** * Return the full jot ACL selector HTML * - * @param array $user + * @param array $user User array + * @param array $default_permissions Static defaults permission array: ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''] * @param bool $show_jotnets * @return string */ - public static function getFullSelectorHTML(array $user = null, $show_jotnets = false) + public static function getFullSelectorHTML(array $user, $show_jotnets = false, array $default_permissions = []) { - - if (empty($user['uid'])) { - return ''; + // Defaults user permissions + if (empty($default_permissions)) { + $default_permissions = self::getDefaultUserPermissions($user); } - $perms = self::getDefaultUserPermissions($user); - $jotnets = ''; if ($show_jotnets) { $imap_disabled = !function_exists('imap_open') || Config::get('system', 'imap_disabled'); @@ -279,7 +279,7 @@ class ACL extends BaseObject } } - if (empty($user['hidewall'])) { + if (empty($default_permissions['hidewall'])) { if ($mail_enabled) { $selected = $pubmail_enabled ? ' checked="checked"' : ''; $jotnets .= '
' . L10n::t("Post to Email") . '
'; @@ -292,15 +292,15 @@ class ACL extends BaseObject } } - $tpl = get_markup_template('acl_selector.tpl'); - $o = replace_macros($tpl, [ + $tpl = Renderer::getMarkupTemplate('acl_selector.tpl'); + $o = Renderer::replaceMacros($tpl, [ '$showall' => L10n::t('Visible to everybody'), '$show' => L10n::t('show'), '$hide' => L10n::t('don\'t show'), - '$allowcid' => json_encode($perms['allow_cid']), - '$allowgid' => json_encode($perms['allow_gid']), - '$denycid' => json_encode($perms['deny_cid']), - '$denygid' => json_encode($perms['deny_gid']), + '$allowcid' => json_encode(defaults($default_permissions, 'allow_cid', '')), + '$allowgid' => json_encode(defaults($default_permissions, 'allow_gid', '')), + '$denycid' => json_encode(defaults($default_permissions, 'deny_cid', '')), + '$denygid' => json_encode(defaults($default_permissions, 'deny_gid', '')), '$networks' => $show_jotnets, '$emailcc' => L10n::t('CC: email addresses'), '$emtitle' => L10n::t('Example: bob@example.com, mary@example.com'), @@ -325,7 +325,7 @@ class ACL extends BaseObject */ public static function contactAutocomplete($search, $mode) { - if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) { + if (Config::get('system', 'block_public') && !local_user() && !remote_user()) { return []; } @@ -342,12 +342,11 @@ class ACL extends BaseObject if (Config::get('system', 'poco_local_search')) { $return = GContact::searchByName($search, $mode); } else { - $a = self::getApp(); - $p = $a->pager['page'] != 1 ? '&p=' . $a->pager['page'] : ''; + $p = defaults($_GET, 'page', 1) != 1 ? '&p=' . defaults($_GET, 'page', 1) : ''; - $response = Network::curl(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); - if ($response['success']) { - $lsearch = json_decode($response['body'], true); + $curlResult = Network::curl(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); + if ($curlResult->isSuccess()) { + $lsearch = json_decode($curlResult->getBody(), true); if (!empty($lsearch['results'])) { $return = $lsearch['results']; }