const TAB_PROFILE = 3;
const TAB_CONTACTS = 4;
const TAB_ADVANCED = 5;
+ const TAB_MEDIA = 6;
private static function batchActions()
{
$count_actions = 0;
foreach ($orig_records as $orig_record) {
$cdata = Model\Contact::getPublicAndUserContactID($orig_record['id'], local_user());
- if (empty($cdata)) {
+ if (empty($cdata) || public_contact() === $cdata['public']) {
+ // No action available on your own contact
continue;
}
}
if (!empty($_POST['contacts_batch_block'])) {
- self::toggleBlockContact($cdata['public']);
+ self::toggleBlockContact($cdata['public'], local_user());
$count_actions++;
}
self::toggleIgnoreContact($cdata['public']);
$count_actions++;
}
-
- if (!empty($_POST['contacts_batch_drop']) && $cdata['user']
- && self::dropContact($cdata['user'], local_user())
- ) {
- $count_actions++;
- }
}
if ($count_actions > 0) {
info(DI::l10n()->tt('%d contact edited.', '%d contacts edited.', $count_actions));
* Toggles the blocked status of a contact identified by id.
*
* @param int $contact_id Id of the contact with uid = 0
+ * @param int $owner_id Id of the user we want to block the contact for
* @throws \Exception
*/
- private static function toggleBlockContact(int $contact_id)
+ private static function toggleBlockContact(int $contact_id, int $owner_id)
{
- $blocked = !Model\Contact\User::isBlocked($contact_id, local_user());
- Model\Contact\User::setBlocked($contact_id, local_user(), $blocked);
+ $blocked = !Model\Contact\User::isBlocked($contact_id, $owner_id);
+ Model\Contact\User::setBlocked($contact_id, $owner_id, $blocked);
}
/**
Model\Contact\User::setIgnored($contact_id, local_user(), $ignored);
}
- /**
- * @param int $contact_id Id for contact with uid != 0
- * @param int $uid Id for user we want to drop the contact for
- * @return bool
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @throws \ImagickException
- */
- private static function dropContact(int $contact_id, int $uid): bool
- {
- $contact = Model\Contact::getContactForUser($contact_id, $uid);
- if (!DBA::isResult($contact)) {
- return false;
- }
-
- $owner = Model\User::getOwnerDataById($uid);
- if (!DBA::isResult($owner)) {
- return false;
- }
-
- Model\Contact::terminateFriendship($owner, $contact, true);
- Model\Contact::remove($contact['id']);
-
- return true;
- }
-
public static function content(array $parameters = [], $update = 0)
{
if (!local_user()) {
$a = DI::app();
- $search = Strings::escapeTags(trim($_GET['search'] ?? ''));
- $nets = Strings::escapeTags(trim($_GET['nets'] ?? ''));
- $rel = Strings::escapeTags(trim($_GET['rel'] ?? ''));
- $group = Strings::escapeTags(trim($_GET['group'] ?? ''));
+ $search = trim($_GET['search'] ?? '');
+ $nets = trim($_GET['nets'] ?? '');
+ $rel = trim($_GET['rel'] ?? '');
+ $group = trim($_GET['group'] ?? '');
$accounttype = $_GET['accounttype'] ?? '';
$accounttypeid = User::getAccountTypeByString($accounttype);
}
if ($cmd === 'posts') {
- return self::getPostsHTML($a, $contact_id);
+ return self::getPostsHTML($contact_id);
}
if ($cmd === 'conversations') {
if ($cmd === 'update' && $cdata['user']) {
self::updateContactFromPoll($cdata['user']);
- DI::baseUrl()->redirect('contact/' . $cdata['public']);
+ DI::baseUrl()->redirect('contact/' . $contact_id);
// NOTREACHED
}
if ($cmd === 'updateprofile' && $cdata['user']) {
self::updateContactFromProbe($cdata['user']);
- DI::baseUrl()->redirect('contact/' . $cdata['public']);
+ DI::baseUrl()->redirect('contact/' . $contact_id);
// NOTREACHED
}
throw new BadRequestException(DI::l10n()->t('You can\'t block yourself'));
}
- self::toggleBlockContact($cdata['public']);
+ self::toggleBlockContact($cdata['public'], local_user());
$blocked = Model\Contact\User::isBlocked($contact_id, local_user());
info(($blocked ? DI::l10n()->t('Contact has been blocked') : DI::l10n()->t('Contact has been unblocked')));
- DI::baseUrl()->redirect('contact/' . $cdata['public']);
+ DI::baseUrl()->redirect('contact/' . $contact_id);
// NOTREACHED
}
$ignored = Model\Contact\User::isIgnored($cdata['public'], local_user());
info(($ignored ? DI::l10n()->t('Contact has been ignored') : DI::l10n()->t('Contact has been unignored')));
- DI::baseUrl()->redirect('contact/' . $cdata['public']);
- // NOTREACHED
- }
-
- if ($cmd === 'drop' && $cdata['user']) {
- // Check if we should do HTML-based delete confirmation
- if (!empty($_REQUEST['confirm'])) {
- DI::page()['aside'] = '';
-
- return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [
- '$l10n' => [
- 'header' => DI::l10n()->t('Drop contact'),
- 'message' => DI::l10n()->t('Do you really want to delete this contact?'),
- 'confirm' => DI::l10n()->t('Yes'),
- 'cancel' => DI::l10n()->t('Cancel'),
- ],
- '$contact' => self::getContactTemplateVars($orig_record),
- '$method' => 'get',
- '$confirm_url' => DI::args()->getCommand(),
- '$confirm_name' => 't',
- '$confirm_value' => BaseModule::getFormSecurityToken('contact_action'),
- ]);
- }
- // Now check how the user responded to the confirmation query
- if (!empty($_REQUEST['canceled'])) {
- DI::baseUrl()->redirect('contact');
- }
-
- if (self::dropContact($cdata['user'], local_user())) {
- info(DI::l10n()->t('Contact has been removed.'));
- }
-
- DI::baseUrl()->redirect('contact');
+ DI::baseUrl()->redirect('contact/' . $contact_id);
// NOTREACHED
}
}
'$submit' => DI::l10n()->t('Submit'),
'$lbl_info1' => $lbl_info1,
'$lbl_info2' => DI::l10n()->t('Their personal note'),
- '$reason' => trim(Strings::escapeTags($contact['reason'])),
+ '$reason' => trim($contact['reason']),
'$infedit' => DI::l10n()->t('Edit contact notes'),
'$common_link' => 'contact/' . $contact['id'] . '/contacts/common',
'$relation_text' => $relation_text,
}
if ($group) {
- $sql_extra = " AND EXISTS(SELECT `id` FROM `group_member` WHERE `gid` = ? AND `contact`.`id` = `contact-id`)";
+ $sql_extra .= " AND EXISTS(SELECT `id` FROM `group_member` WHERE `gid` = ? AND `contact`.`id` = `contact-id`)";
$sql_values[] = $group;
}
- $total = 0;
- $stmt = DBA::p("SELECT COUNT(*) AS `total`
- FROM `contact`
- WHERE `uid` = ?
- AND `self` = 0
- AND NOT `deleted`
- $sql_extra
- " . Widget::unavailableNetworks(),
- $sql_values
- );
- if (DBA::isResult($stmt)) {
- $total = DBA::fetch($stmt)['total'];
- }
- DBA::close($stmt);
+ $networks = Widget::unavailableNetworks();
+ $sql_extra .= " AND NOT `network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")";
+ $sql_values = array_merge($sql_values, $networks);
- $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
+ $condition = ["`uid` = ? AND NOT `self` AND NOT `deleted`" . $sql_extra];
+ $condition = array_merge($condition, $sql_values);
- $sql_values[] = $pager->getStart();
- $sql_values[] = $pager->getItemsPerPage();
+ $total = DBA::count('contact', $condition);
+
+ $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$contacts = [];
- $stmt = DBA::p("SELECT *
- FROM `contact`
- WHERE `uid` = ?
- AND `self` = 0
- AND NOT `deleted`
- $sql_extra
- ORDER BY `name` ASC
- LIMIT ?, ?",
- $sql_values
- );
+ $stmt = DBA::select('contact', [], $condition, ['order' => ['name'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
+
while ($contact = DBA::fetch($stmt)) {
$contact['blocked'] = Model\Contact\User::isBlocked($contact['id'], local_user());
$contact['readonly'] = Model\Contact\User::isIgnored($contact['id'], local_user());
'$cmd' => DI::args()->getCommand(),
'$contacts' => $contacts,
'$form_security_token' => BaseModule::getFormSecurityToken('contact_batch_actions'),
- '$contact_drop_confirm' => DI::l10n()->t('Do you really want to delete this contact?'),
'multiselect' => 1,
'$batch_actions' => [
'contacts_batch_update' => DI::l10n()->t('Update'),
'contacts_batch_block' => DI::l10n()->t('Block') . '/' . DI::l10n()->t('Unblock'),
'contacts_batch_ignore' => DI::l10n()->t('Ignore') . '/' . DI::l10n()->t('Unignore'),
- 'contacts_batch_drop' => DI::l10n()->t('Delete'),
],
'$h_batch_actions' => DI::l10n()->t('Batch Actions'),
'$paginate' => $pager->renderFull($total),
'id' => 'posts-tab',
'accesskey' => 'p',
],
+ [
+ 'label' => DI::l10n()->t('Media'),
+ 'url' => 'contact/' . $pcid . '/media',
+ 'sel' => (($active_tab == self::TAB_MEDIA) ? 'active' : ''),
+ 'title' => DI::l10n()->t('Posts containing media objects'),
+ 'id' => 'media-tab',
+ 'accesskey' => 'd',
+ ],
[
'label' => DI::l10n()->t('Profile'),
'url' => 'contact/' . $cid,
return $o;
}
- private static function getPostsHTML($a, $contact_id)
+ private static function getPostsHTML(int $contact_id)
{
$contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
'id' => 'toggle-ignore',
];
- if ($contact['uid'] != 0) {
- $contact_actions['delete'] = [
- 'label' => DI::l10n()->t('Delete'),
- 'url' => 'contact/' . $contact['id'] . '/drop?t=' . $formSecurityToken,
- 'title' => DI::l10n()->t('Delete contact'),
+ if ($contact['uid'] != 0 && Protocol::supportsRevokeFollow($contact['network']) && in_array($contact['rel'], [Model\Contact::FOLLOWER, Model\Contact::FRIEND])) {
+ $contact_actions['revoke_follow'] = [
+ 'label' => DI::l10n()->t('Revoke Follow'),
+ 'url' => 'contact/' . $contact['id'] . '/revoke',
+ 'title' => DI::l10n()->t('Revoke the follow from this contact'),
'sel' => '',
- 'id' => 'delete',
+ 'id' => 'revoke_follow',
];
}