Move contact_select to Acl

- Simplify Acl::getMessageContactSelectHTML parameters
This commit is contained in:
Hypolite Petovan 2018-02-25 19:56:53 -05:00
parent eef25a3259
commit 113ea38d50
3 changed files with 12 additions and 41 deletions

View file

@ -9,10 +9,6 @@ use Friendica\Model\Contact;
require_once "mod/proxy.php"; require_once "mod/proxy.php";
function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false, $tabindex = null) {
return Acl::getMessageContactSelectHTML($selname, $selclass, defaults($preselected, []), $size, $privmail, $celeb, $privatenet, $tabindex);
}
function prune_deadguys($arr) { function prune_deadguys($arr) {
Contact::pruneUnavailable($arr); Contact::pruneUnavailable($arr);
return $arr; return $arr;

View file

@ -7,6 +7,7 @@ use Friendica\App;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Content\Smilies; use Friendica\Content\Smilies;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Core\Acl;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
@ -236,14 +237,14 @@ function message_content(App $a)
$preid = $r[0]['id']; $preid = $r[0]['id'];
$preselect = [$preid]; $preselect = [$preid];
} else { } else {
$preselect = false; $preselect = [];
} }
} }
$prefill = $preselect ? $prename : ''; $prefill = $preselect ? $prename : '';
// the ugly select box // the ugly select box
$select = contact_select('messageto', 'message-to-select', $preselect, 4, true, false, false, 10); $select = Acl::getMessageContactSelectHTML('messageto', 'message-to-select', $preselect, 4, 10);
$tpl = get_markup_template('prv_message.tpl'); $tpl = get_markup_template('prv_message.tpl');
$o .= replace_macros($tpl, [ $o .= replace_macros($tpl, [

View file

@ -153,17 +153,12 @@ class Acl extends BaseObject
* *
* @param string $selname Name attribute of the select input tag * @param string $selname Name attribute of the select input tag
* @param string $selclass Class attribute of the select input tag * @param string $selclass Class attribute of the select input tag
* @param array $preselected Contact ID that should be already selected * @param array $preselected Contact IDs that should be already selected
* @param int $size Length of the select box * @param int $size Length of the select box
* @param bool $privmail
* @param bool $celeb
* @param bool $privatenet
* @param int $tabindex Select input tag tabindex attribute * @param int $tabindex Select input tag tabindex attribute
* @return string * @return string
*/ */
public static function getMessageContactSelectHTML( public static function getMessageContactSelectHTML($selname, $selclass, array $preselected = [], $size = 4, $tabindex = null)
$selname, $selclass, array $preselected = [], $size = 4, $privmail = false, $celeb = false, $privatenet = false,
$tabindex = null)
{ {
$a = self::getApp(); $a = self::getApp();
@ -171,34 +166,18 @@ class Acl extends BaseObject
// When used for private messages, we limit correspondence to mutual DFRN/Friendica friends and the selector // 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. // 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 = '';
if ($privmail || $celeb) {
$sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
}
if ($privmail) {
$sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ", NETWORK_DFRN, NETWORK_DIASPORA); $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ", NETWORK_DFRN, NETWORK_DIASPORA);
} elseif ($privatenet) {
$sql_extra .= sprintf(" AND `network` IN ('%s' , '%s', '%s', '%s') ", NETWORK_DFRN, NETWORK_MAIL, NETWORK_FACEBOOK,
NETWORK_DIASPORA);
}
$tabindex_attr = !empty($tabindex) ? ' tabindex="' . intval($tabindex) . '"' : ''; $tabindex_attr = !empty($tabindex) ? ' tabindex="' . intval($tabindex) . '"' : '';
if ($privmail && $preselected) { $hidepreselected = '';
if ($preselected) {
$sql_extra .= " AND `id` IN (" . implode(",", $preselected) . ")"; $sql_extra .= " AND `id` IN (" . implode(",", $preselected) . ")";
$hidepreselected = ' style="display: none;"'; $hidepreselected = ' style="display: none;"';
} else {
$hidepreselected = '';
} }
if ($privmail) {
$o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\"$tabindex_attr$hidepreselected>\r\n"; $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\"$tabindex_attr$hidepreselected>\r\n";
} else {
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\"$tabindex_attr>\r\n";
}
$stmt = dba::p("SELECT `id`, `name`, `url`, `network` FROM `contact` $stmt = dba::p("SELECT `id`, `name`, `url`, `network` FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
@ -211,7 +190,6 @@ class Acl extends BaseObject
$arr = ['contact' => $contacts, 'entry' => $o]; $arr = ['contact' => $contacts, 'entry' => $o];
// e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow' // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
Addon::callHooks($a->module . '_pre_' . $selname, $arr); Addon::callHooks($a->module . '_pre_' . $selname, $arr);
$receiverlist = []; $receiverlist = [];
@ -224,11 +202,7 @@ class Acl extends BaseObject
$selected = ''; $selected = '';
} }
if ($privmail) {
$trimmed = Protocol::formatMention($contact['url'], $contact['name']); $trimmed = Protocol::formatMention($contact['url'], $contact['name']);
} else {
$trimmed = mb_substr($contact['name'], 0, 20);
}
$receiverlist[] = $trimmed; $receiverlist[] = $trimmed;
@ -238,7 +212,7 @@ class Acl extends BaseObject
$o .= '</select>' . PHP_EOL; $o .= '</select>' . PHP_EOL;
if ($privmail && $preselected) { if ($preselected) {
$o .= implode(', ', $receiverlist); $o .= implode(', ', $receiverlist);
} }