streams/Code/Module/Profperm.php

184 lines
5.3 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2019-04-17 23:54:06 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Libprofile;
2019-04-17 23:54:06 +00:00
2016-04-19 03:38:38 +00:00
require_once('include/photos.php');
2021-12-02 23:02:31 +00:00
class Profperm extends Controller
{
public function init()
{
2021-12-03 03:01:39 +00:00
if (!local_channel()) {
2021-12-02 23:02:31 +00:00
return;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$channel = App::get_channel();
$which = $channel['channel_address'];
$profile = App::$argv[1];
Libprofile::load($which, $profile);
}
public function get()
{
if (!local_channel()) {
notice(t('Permission denied') . EOL);
return;
}
if (argc() < 2) {
notice(t('Invalid profile identifier.') . EOL);
return;
}
// Switch to text mod interface if we have more than 'n' contacts or group members
$switchtotext = get_pconfig(local_channel(), 'system', 'groupedit_image_limit');
2021-12-03 03:01:39 +00:00
if ($switchtotext === false) {
2021-12-02 23:02:31 +00:00
$switchtotext = get_config('system', 'groupedit_image_limit');
2021-12-03 03:01:39 +00:00
}
if ($switchtotext === false) {
2021-12-02 23:02:31 +00:00
$switchtotext = 400;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
if ((argc() > 2) && intval(argv(1)) && intval(argv(2))) {
2021-12-03 03:01:39 +00:00
$r = q(
"SELECT abook_id FROM abook WHERE abook_id = %d and abook_channel = %d limit 1",
2021-12-02 23:02:31 +00:00
intval(argv(2)),
intval(local_channel())
);
2021-12-03 03:01:39 +00:00
if ($r) {
2021-12-02 23:02:31 +00:00
$change = intval(argv(2));
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
if ((argc() > 1) && (intval(argv(1)))) {
2021-12-03 03:01:39 +00:00
$r = q(
"SELECT * FROM profile WHERE id = %d AND uid = %d AND is_default = 0 LIMIT 1",
2021-12-02 23:02:31 +00:00
intval(argv(1)),
intval(local_channel())
);
if (!$r) {
notice(t('Invalid profile identifier.') . EOL);
return;
}
$profile = $r[0];
2021-12-03 03:01:39 +00:00
$r = q(
"SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'",
2021-12-02 23:02:31 +00:00
intval(local_channel()),
dbesc($profile['profile_guid'])
);
$ingroup = [];
2021-12-03 03:01:39 +00:00
if ($r) {
foreach ($r as $member) {
2021-12-02 23:02:31 +00:00
$ingroup[] = $member['abook_id'];
2021-12-03 03:01:39 +00:00
}
}
2021-12-02 23:02:31 +00:00
$members = $r;
if ($change) {
if (in_array($change, $ingroup)) {
2021-12-03 03:01:39 +00:00
q(
"UPDATE abook SET abook_profile = '' WHERE abook_id = %d AND abook_channel = %d",
2021-12-02 23:02:31 +00:00
intval($change),
intval(local_channel())
);
} else {
2021-12-03 03:01:39 +00:00
q(
"UPDATE abook SET abook_profile = '%s' WHERE abook_id = %d AND abook_channel = %d",
2021-12-02 23:02:31 +00:00
dbesc($profile['profile_guid']),
intval($change),
intval(local_channel())
);
}
2021-12-03 03:01:39 +00:00
$r = q(
"SELECT * FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = %d AND abook_profile = '%s'",
2021-12-02 23:02:31 +00:00
intval(local_channel()),
dbesc($profile['profile_guid'])
);
$members = $r;
$ingroup = [];
2021-12-03 03:01:39 +00:00
if (count($r)) {
foreach ($r as $member) {
2021-12-02 23:02:31 +00:00
$ingroup[] = $member['abook_id'];
2021-12-03 03:01:39 +00:00
}
}
2021-12-02 23:02:31 +00:00
}
$o .= '<h2>' . t('Profile Visibility Editor') . '</h2>';
$o .= '<h3>' . t('Profile') . ' \'' . $profile['profile_name'] . '\'</h3>';
$o .= '<div id="prof-edit-desc">' . t('Click on a contact to add or remove.') . '</div>';
}
$o .= '<div id="prof-update-wrapper">';
2021-12-03 03:01:39 +00:00
if ($change) {
2021-12-02 23:02:31 +00:00
$o = '';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$o .= '<div id="prof-members-title">';
$o .= '<h3>' . t('Visible To') . '</h3>';
$o .= '</div>';
$o .= '<div id="prof-members">';
$textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
foreach ($members as $member) {
if ($member['xchan_url']) {
$member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['abook_id'] . '); return false;';
$o .= micropro($member, true, 'mpprof', $textmode);
}
}
$o .= '</div><div id="prof-members-end"></div>';
$o .= '<hr id="prof-separator" />';
$o .= '<div id="prof-all-contcts-title">';
$o .= '<h3>' . t("All Connections") . '</h3>';
$o .= '</div>';
$o .= '<div id="prof-all-contacts">';
$r = abook_connections(local_channel());
if ($r) {
$textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
foreach ($r as $member) {
if (!in_array($member['abook_id'], $ingroup)) {
$member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['abook_id'] . '); return false;';
$o .= micropro($member, true, 'mpprof', $textmode);
}
}
}
$o .= '</div><div id="prof-all-contacts-end"></div>';
if ($change) {
echo $o;
killme();
}
$o .= '</div>';
return $o;
}
2016-04-19 03:38:38 +00:00
}