2019-05-01 19:29:04 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2023-01-01 14:36:24 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-02-09 15:18:46 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
2019-05-01 19:29:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Module;
|
|
|
|
|
|
|
|
use Friendica\BaseModule;
|
2023-07-22 10:49:42 +00:00
|
|
|
use Friendica\Content\Widget;
|
2019-05-01 19:29:04 +00:00
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Core\System;
|
|
|
|
use Friendica\Database\DBA;
|
2019-12-15 21:34:11 +00:00
|
|
|
use Friendica\DI;
|
2019-05-01 19:29:04 +00:00
|
|
|
use Friendica\Model;
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
class Circle extends BaseModule
|
2019-05-01 19:29:04 +00:00
|
|
|
{
|
2021-11-28 12:44:42 +00:00
|
|
|
protected function post(array $request = [])
|
2019-05-01 19:29:04 +00:00
|
|
|
{
|
2019-12-15 23:30:39 +00:00
|
|
|
if (DI::mode()->isAjax()) {
|
2021-11-26 14:48:05 +00:00
|
|
|
$this->ajaxPost();
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-20 20:59:12 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2022-10-17 18:55:22 +00:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
|
2019-12-15 23:28:31 +00:00
|
|
|
DI::baseUrl()->redirect();
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @TODO: Replace with parameter from router
|
2021-07-25 15:23:37 +00:00
|
|
|
if ((DI::args()->getArgc() == 2) && (DI::args()->getArgv()[1] === 'new')) {
|
2023-05-13 23:54:35 +00:00
|
|
|
BaseModule::checkFormSecurityTokenRedirectOnError('/circle/new', 'circle_edit');
|
2019-05-01 19:29:04 +00:00
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$name = trim($request['circle_name']);
|
|
|
|
$r = Model\Circle::create(DI::userSession()->getLocalUserId(), $name);
|
2019-05-01 19:29:04 +00:00
|
|
|
if ($r) {
|
2023-05-13 23:54:35 +00:00
|
|
|
$r = Model\Circle::getIdByName(DI::userSession()->getLocalUserId(), $name);
|
2019-05-01 19:29:04 +00:00
|
|
|
if ($r) {
|
2023-05-13 23:54:35 +00:00
|
|
|
DI::baseUrl()->redirect('circle/' . $r);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-05-13 23:54:35 +00:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Could not create circle.'));
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
2023-05-13 23:54:35 +00:00
|
|
|
DI::baseUrl()->redirect('circle');
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @TODO: Replace with parameter from router
|
2021-07-25 15:23:37 +00:00
|
|
|
if ((DI::args()->getArgc() == 2) && intval(DI::args()->getArgv()[1])) {
|
2023-05-13 23:54:35 +00:00
|
|
|
BaseModule::checkFormSecurityTokenRedirectOnError('/circle', 'circle_edit');
|
2019-05-01 19:29:04 +00:00
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$circle = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => DI::userSession()->getLocalUserId()]);
|
|
|
|
if (!DBA::isResult($circle)) {
|
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Circle not found.'));
|
2019-12-15 23:28:31 +00:00
|
|
|
DI::baseUrl()->redirect('contact');
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
2023-05-13 23:54:35 +00:00
|
|
|
$circlename = trim($_POST['circle_name']);
|
|
|
|
if (strlen($circlename) && ($circlename != $circle['name'])) {
|
|
|
|
if (!Model\Circle::update($circle['id'], $circlename)) {
|
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Circle name was not changed.'));
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-26 14:48:05 +00:00
|
|
|
public function ajaxPost()
|
2019-05-01 19:29:04 +00:00
|
|
|
{
|
|
|
|
try {
|
2022-10-20 20:59:12 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2020-01-18 19:52:34 +00:00
|
|
|
throw new \Exception(DI::l10n()->t('Permission denied.'), 403);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-26 14:48:05 +00:00
|
|
|
if (isset($this->parameters['command'])) {
|
2023-05-13 23:54:35 +00:00
|
|
|
$circle_id = $this->parameters['circle'];
|
2021-11-26 14:48:05 +00:00
|
|
|
$contact_id = $this->parameters['contact'];
|
2019-05-01 19:29:04 +00:00
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
if (!Model\Circle::exists($circle_id, DI::userSession()->getLocalUserId())) {
|
|
|
|
throw new \Exception(DI::l10n()->t('Unknown circle.'), 404);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-26 14:48:37 +00:00
|
|
|
// @TODO Backward compatibility with user contacts, remove by version 2022.03
|
2022-10-20 20:59:12 +00:00
|
|
|
$cdata = Model\Contact::getPublicAndUserContactID($contact_id, DI::userSession()->getLocalUserId());
|
2021-11-26 14:48:37 +00:00
|
|
|
if (empty($cdata['public'])) {
|
|
|
|
throw new \Exception(DI::l10n()->t('Contact not found.'), 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($cdata['user'])) {
|
|
|
|
throw new \Exception(DI::l10n()->t('Invalid contact.'), 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$contact = Model\Contact::getById($cdata['user'], ['deleted']);
|
2019-05-01 19:29:04 +00:00
|
|
|
if (!DBA::isResult($contact)) {
|
2020-01-18 19:52:34 +00:00
|
|
|
throw new \Exception(DI::l10n()->t('Contact not found.'), 404);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($contact['deleted']) {
|
2020-01-18 19:52:34 +00:00
|
|
|
throw new \Exception(DI::l10n()->t('Contact is deleted.'), 410);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-26 14:48:05 +00:00
|
|
|
switch($this->parameters['command']) {
|
2019-05-01 19:29:04 +00:00
|
|
|
case 'add':
|
2023-05-13 23:54:35 +00:00
|
|
|
if (!Model\Circle::addMember($circle_id, $cdata['user'])) {
|
|
|
|
throw new \Exception(DI::l10n()->t('Unable to add the contact to the circle.'), 500);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
2019-12-24 21:44:43 +00:00
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$message = DI::l10n()->t('Contact successfully added to circle.');
|
2019-05-01 19:29:04 +00:00
|
|
|
break;
|
|
|
|
case 'remove':
|
2023-05-13 23:54:35 +00:00
|
|
|
if (!Model\Circle::removeMember($circle_id, $cdata['user'])) {
|
|
|
|
throw new \Exception(DI::l10n()->t('Unable to remove the contact from the circle.'), 500);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
2019-12-24 21:44:43 +00:00
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$message = DI::l10n()->t('Contact successfully removed from circle.');
|
2019-05-01 19:29:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2020-01-18 19:52:34 +00:00
|
|
|
throw new \Exception(DI::l10n()->t('Bad request.'), 400);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 18:55:22 +00:00
|
|
|
DI::sysmsg()->addInfo($message);
|
2023-09-21 16:16:17 +00:00
|
|
|
$this->jsonExit(['status' => 'OK', 'message' => $message]);
|
2019-05-01 19:29:04 +00:00
|
|
|
} catch (\Exception $e) {
|
2022-10-17 18:55:22 +00:00
|
|
|
DI::sysmsg()->addNotice($e->getMessage());
|
2023-09-21 16:27:15 +00:00
|
|
|
$this->jsonError($e->getCode(), ['status' => 'error', 'message' => $e->getMessage()]);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-20 14:38:03 +00:00
|
|
|
protected function content(array $request = []): string
|
2019-05-01 19:29:04 +00:00
|
|
|
{
|
|
|
|
$change = false;
|
|
|
|
|
2022-10-20 20:59:12 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2019-05-02 03:16:10 +00:00
|
|
|
throw new \Friendica\Network\HTTPException\ForbiddenException();
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
DI::page()['aside'] = Model\Circle::sidebarWidget('contact', 'circle', 'extended', ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : 'everyone'));
|
2019-05-01 19:29:04 +00:00
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
// With no circle number provided we jump to the unassigned contacts as a starting point
|
2019-05-01 19:29:04 +00:00
|
|
|
// @TODO: Replace with parameter from router
|
2021-07-25 15:23:37 +00:00
|
|
|
if (DI::args()->getArgc() == 1) {
|
2023-05-13 23:54:35 +00:00
|
|
|
DI::baseUrl()->redirect('circle/none');
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
// Switch to text mode interface if we have more than 'n' contacts or circle members
|
|
|
|
$switchtotext = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'circle_edit_image_limit') ??
|
|
|
|
DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'groupedit_image_limit');
|
2019-05-01 19:29:04 +00:00
|
|
|
if (is_null($switchtotext)) {
|
2023-05-13 23:54:35 +00:00
|
|
|
$switchtotext = DI::config()->get('system', 'groupedit_image_limit') ??
|
|
|
|
DI::config()->get('system', 'circle_edit_image_limit');
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$tpl = Renderer::getMarkupTemplate('circle_edit.tpl');
|
2019-05-01 19:29:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
$context = [
|
2023-05-13 23:54:35 +00:00
|
|
|
'$submit' => DI::l10n()->t('Save Circle'),
|
2020-01-18 19:52:34 +00:00
|
|
|
'$submit_filter' => DI::l10n()->t('Filter'),
|
2019-05-01 19:29:04 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// @TODO: Replace with parameter from router
|
2021-07-25 15:23:37 +00:00
|
|
|
if ((DI::args()->getArgc() == 2) && (DI::args()->getArgv()[1] === 'new')) {
|
2019-05-01 19:29:04 +00:00
|
|
|
return Renderer::replaceMacros($tpl, $context + [
|
2023-05-13 23:54:35 +00:00
|
|
|
'$title' => DI::l10n()->t('Create a circle of contacts/friends.'),
|
|
|
|
'$gname' => ['circle_name', DI::l10n()->t('Circle Name: '), '', ''],
|
2019-05-01 19:29:04 +00:00
|
|
|
'$gid' => 'new',
|
2023-05-13 23:54:35 +00:00
|
|
|
'$form_security_token' => BaseModule::getFormSecurityToken('circle_edit'),
|
2019-05-01 19:29:04 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$nocircle = false;
|
2019-05-01 19:29:04 +00:00
|
|
|
|
2019-05-03 06:50:17 +00:00
|
|
|
// @TODO: Replace with parameter from router
|
2021-07-25 15:23:37 +00:00
|
|
|
if ((DI::args()->getArgc() == 2) && (DI::args()->getArgv()[1] === 'none') ||
|
2023-05-13 23:54:35 +00:00
|
|
|
(DI::args()->getArgc() == 1) && (DI::args()->getArgv()[0] === 'nocircle')) {
|
2019-05-01 19:29:04 +00:00
|
|
|
$id = -1;
|
2023-05-13 23:54:35 +00:00
|
|
|
$nocircle = true;
|
|
|
|
$circle = [
|
2019-05-01 19:29:04 +00:00
|
|
|
'id' => $id,
|
2023-05-13 23:54:35 +00:00
|
|
|
'name' => DI::l10n()->t('Contacts not in any circle'),
|
2019-05-01 19:29:04 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$members = [];
|
|
|
|
$preselected = [];
|
|
|
|
|
|
|
|
$context = $context + [
|
2023-05-13 23:54:35 +00:00
|
|
|
'$title' => $circle['name'],
|
|
|
|
'$gname' => ['circle_name', DI::l10n()->t('Circle Name: '), $circle['name'], ''],
|
2019-05-01 19:29:04 +00:00
|
|
|
'$gid' => $id,
|
|
|
|
'$editable' => 0,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
// @TODO: Replace with parameter from router
|
2021-07-25 15:23:37 +00:00
|
|
|
if ((DI::args()->getArgc() == 3) && (DI::args()->getArgv()[1] === 'drop')) {
|
2023-05-13 23:54:35 +00:00
|
|
|
BaseModule::checkFormSecurityTokenRedirectOnError('/circle', 'circle_drop', 't');
|
2019-05-01 19:29:04 +00:00
|
|
|
|
|
|
|
// @TODO: Replace with parameter from router
|
2021-07-25 15:23:37 +00:00
|
|
|
if (intval(DI::args()->getArgv()[2])) {
|
2023-05-13 23:54:35 +00:00
|
|
|
if (!Model\Circle::exists(DI::args()->getArgv()[2], DI::userSession()->getLocalUserId())) {
|
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Circle not found.'));
|
2019-12-15 23:28:31 +00:00
|
|
|
DI::baseUrl()->redirect('contact');
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
if (!Model\Circle::remove(DI::args()->getArgv()[2])) {
|
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Unable to remove circle.'));
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-13 23:54:35 +00:00
|
|
|
DI::baseUrl()->redirect('circle');
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @TODO: Replace with parameter from router
|
2021-07-25 15:23:37 +00:00
|
|
|
if ((DI::args()->getArgc() > 2) && intval(DI::args()->getArgv()[1]) && intval(DI::args()->getArgv()[2])) {
|
2023-05-13 23:54:35 +00:00
|
|
|
BaseModule::checkFormSecurityTokenForbiddenOnError('circle_member_change', 't');
|
2019-05-01 19:29:04 +00:00
|
|
|
|
2022-10-20 20:59:12 +00:00
|
|
|
if (DBA::exists('contact', ['id' => DI::args()->getArgv()[2], 'uid' => DI::userSession()->getLocalUserId(), 'self' => false, 'pending' => false, 'blocked' => false])) {
|
2021-07-25 15:23:37 +00:00
|
|
|
$change = intval(DI::args()->getArgv()[2]);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @TODO: Replace with parameter from router
|
2021-07-25 15:23:37 +00:00
|
|
|
if ((DI::args()->getArgc() > 1) && intval(DI::args()->getArgv()[1])) {
|
2023-05-13 23:54:35 +00:00
|
|
|
$circle = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => DI::userSession()->getLocalUserId(), 'deleted' => false]);
|
|
|
|
if (!DBA::isResult($circle)) {
|
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Circle not found.'));
|
2019-12-15 23:28:31 +00:00
|
|
|
DI::baseUrl()->redirect('contact');
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$members = Model\Contact\Circle::getById($circle['id']);
|
2019-05-01 19:29:04 +00:00
|
|
|
$preselected = [];
|
|
|
|
|
|
|
|
if (count($members)) {
|
|
|
|
foreach ($members as $member) {
|
|
|
|
$preselected[] = $member['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($change) {
|
|
|
|
if (in_array($change, $preselected)) {
|
2023-05-13 23:54:35 +00:00
|
|
|
Model\Circle::removeMember($circle['id'], $change);
|
2019-05-01 19:29:04 +00:00
|
|
|
} else {
|
2023-05-13 23:54:35 +00:00
|
|
|
Model\Circle::addMember($circle['id'], $change);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$members = Model\Contact\Circle::getById($circle['id']);
|
2019-05-01 19:29:04 +00:00
|
|
|
$preselected = [];
|
|
|
|
if (count($members)) {
|
|
|
|
foreach ($members as $member) {
|
|
|
|
$preselected[] = $member['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$drop_tpl = Renderer::getMarkupTemplate('circle_drop.tpl');
|
2019-05-01 19:29:04 +00:00
|
|
|
$drop_txt = Renderer::replaceMacros($drop_tpl, [
|
2023-05-13 23:54:35 +00:00
|
|
|
'$id' => $circle['id'],
|
|
|
|
'$delete' => DI::l10n()->t('Delete Circle'),
|
|
|
|
'$form_security_token' => BaseModule::getFormSecurityToken('circle_drop'),
|
2019-05-01 19:29:04 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$context = $context + [
|
2023-05-13 23:54:35 +00:00
|
|
|
'$title' => $circle['name'],
|
|
|
|
'$gname' => ['circle_name', DI::l10n()->t('Circle Name: '), $circle['name'], ''],
|
|
|
|
'$gid' => $circle['id'],
|
2019-05-01 19:29:04 +00:00
|
|
|
'$drop' => $drop_txt,
|
2023-05-13 23:54:35 +00:00
|
|
|
'$form_security_token' => BaseModule::getFormSecurityToken('circle_edit'),
|
|
|
|
'$edit_name' => DI::l10n()->t('Edit Circle Name'),
|
2019-05-01 19:29:04 +00:00
|
|
|
'$editable' => 1,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
if (!isset($circle)) {
|
2019-05-02 03:16:10 +00:00
|
|
|
throw new \Friendica\Network\HTTPException\BadRequestException();
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$circle_editor = [
|
2020-01-18 19:52:34 +00:00
|
|
|
'label_members' => DI::l10n()->t('Members'),
|
2019-05-01 19:29:04 +00:00
|
|
|
'members' => [],
|
2020-01-18 19:52:34 +00:00
|
|
|
'label_contacts' => DI::l10n()->t('All Contacts'),
|
2023-05-13 23:54:35 +00:00
|
|
|
'circle_is_empty' => DI::l10n()->t('Circle is empty'),
|
2019-05-01 19:29:04 +00:00
|
|
|
'contacts' => [],
|
|
|
|
];
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$sec_token = addslashes(BaseModule::getFormSecurityToken('circle_member_change'));
|
2019-05-01 19:29:04 +00:00
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
// Format the data of the circle members
|
2019-05-01 19:29:04 +00:00
|
|
|
foreach ($members as $member) {
|
|
|
|
if ($member['url']) {
|
|
|
|
$entry = Contact::getContactTemplateVars($member);
|
|
|
|
$entry['label'] = 'members';
|
|
|
|
$entry['photo_menu'] = '';
|
|
|
|
$entry['change_member'] = [
|
2023-05-13 23:54:35 +00:00
|
|
|
'title' => DI::l10n()->t('Remove contact from circle'),
|
|
|
|
'gid' => $circle['id'],
|
2019-05-01 19:29:04 +00:00
|
|
|
'cid' => $member['id'],
|
|
|
|
'sec_token' => $sec_token
|
|
|
|
];
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$circle_editor['members'][] = $entry;
|
2019-05-01 19:29:04 +00:00
|
|
|
} else {
|
2023-05-13 23:54:35 +00:00
|
|
|
Model\Circle::removeMember($circle['id'], $member['id']);
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
if ($nocircle) {
|
|
|
|
$contacts = Model\Contact\Circle::listUncircled(DI::userSession()->getLocalUserId());
|
2019-05-01 19:29:04 +00:00
|
|
|
} else {
|
2023-07-22 10:49:42 +00:00
|
|
|
$networks = Widget::unavailableNetworks();
|
|
|
|
$query = "`uid` = ? AND NOT `self` AND NOT `deleted` AND NOT `blocked` AND NOT `pending` AND NOT `failed`
|
|
|
|
AND `rel` IN (?, ?, ?)
|
|
|
|
AND NOT `network` IN (" . substr(str_repeat('?, ', count($networks)), 0, -2) . ")";
|
|
|
|
$condition = array_merge([$query], [DI::userSession()->getLocalUserId(), Model\Contact::FOLLOWER, Model\Contact::FRIEND, Model\Contact::SHARING], $networks);
|
|
|
|
|
|
|
|
$contacts_stmt = DBA::select('contact', [], $condition, ['order' => ['name']]);
|
2019-05-01 19:29:04 +00:00
|
|
|
$contacts = DBA::toArray($contacts_stmt);
|
2020-01-18 19:52:34 +00:00
|
|
|
$context['$desc'] = DI::l10n()->t('Click on a contact to add or remove.');
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DBA::isResult($contacts)) {
|
2023-05-13 23:54:35 +00:00
|
|
|
// Format the data of the contacts who aren't in the contact circle
|
2019-05-01 19:29:04 +00:00
|
|
|
foreach ($contacts as $member) {
|
|
|
|
if (!in_array($member['id'], $preselected)) {
|
|
|
|
$entry = Contact::getContactTemplateVars($member);
|
|
|
|
$entry['label'] = 'contacts';
|
2023-05-13 23:54:35 +00:00
|
|
|
if (!$nocircle)
|
2019-05-01 19:29:04 +00:00
|
|
|
$entry['photo_menu'] = [];
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
if (!$nocircle) {
|
2019-05-01 19:29:04 +00:00
|
|
|
$entry['change_member'] = [
|
2023-05-13 23:54:35 +00:00
|
|
|
'title' => DI::l10n()->t('Add contact to circle'),
|
|
|
|
'gid' => $circle['id'],
|
2019-05-01 19:29:04 +00:00
|
|
|
'cid' => $member['id'],
|
|
|
|
'sec_token' => $sec_token
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$circle_editor['contacts'][] = $entry;
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-13 23:54:35 +00:00
|
|
|
$context['$circle_editor'] = $circle_editor;
|
2019-05-01 19:29:04 +00:00
|
|
|
|
|
|
|
// If there are to many contacts we could provide an alternative view mode
|
2023-05-13 23:54:35 +00:00
|
|
|
$total = count($circle_editor['members']) + count($circle_editor['contacts']);
|
2019-05-01 19:29:04 +00:00
|
|
|
$context['$shortmode'] = (($switchtotext && ($total > $switchtotext)) ? true : false);
|
|
|
|
|
|
|
|
if ($change) {
|
2023-05-13 23:54:35 +00:00
|
|
|
$tpl = Renderer::getMarkupTemplate('circle_editor.tpl');
|
2019-05-01 19:29:04 +00:00
|
|
|
echo Renderer::replaceMacros($tpl, $context);
|
2022-05-18 02:13:54 +00:00
|
|
|
System::exit();
|
2019-05-01 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Renderer::replaceMacros($tpl, $context);
|
|
|
|
}
|
2023-05-13 23:54:35 +00:00
|
|
|
}
|