Merge pull request #2399 from annando/1603-default-group
Central function for default group, special setting for OStatus
This commit is contained in:
commit
1127150c79
6 changed files with 51 additions and 30 deletions
|
@ -700,12 +700,10 @@ function diaspora_request($importer,$xml) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$g = q("select def_gid from user where uid = %d limit 1",
|
$def_gid = get_default_group($importer['uid'], $ret["network"]);
|
||||||
intval($importer['uid'])
|
if (intval($def_gid)) {
|
||||||
);
|
|
||||||
if($g && intval($g[0]['def_gid'])) {
|
|
||||||
require_once('include/group.php');
|
require_once('include/group.php');
|
||||||
group_add_member($importer['uid'],'',$contact_record['id'],$g[0]['def_gid']);
|
group_add_member($importer['uid'], '', $contact_record['id'], $def_gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($importer['page-flags'] == PAGE_NORMAL) {
|
if($importer['page-flags'] == PAGE_NORMAL) {
|
||||||
|
|
|
@ -258,12 +258,10 @@ function new_contact($uid,$url,$interactive = false) {
|
||||||
$contact_id = $r[0]['id'];
|
$contact_id = $r[0]['id'];
|
||||||
$result['cid'] = $contact_id;
|
$result['cid'] = $contact_id;
|
||||||
|
|
||||||
$g = q("select def_gid from user where uid = %d limit 1",
|
$def_gid = get_default_group($uid, $contact["network"]);
|
||||||
intval($uid)
|
if (intval($def_gid)) {
|
||||||
);
|
|
||||||
if($g && intval($g[0]['def_gid'])) {
|
|
||||||
require_once('include/group.php');
|
require_once('include/group.php');
|
||||||
group_add_member($uid,'',$contact_id,$g[0]['def_gid']);
|
group_add_member($uid, '', $contact_id, $def_gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once("include/Photo.php");
|
require_once("include/Photo.php");
|
||||||
|
|
|
@ -188,7 +188,7 @@ function group_public_members($gid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function mini_group_select($uid,$gid = 0) {
|
function mini_group_select($uid,$gid = 0, $label = "") {
|
||||||
|
|
||||||
$grps = array();
|
$grps = array();
|
||||||
$o = '';
|
$o = '';
|
||||||
|
@ -205,8 +205,11 @@ function mini_group_select($uid,$gid = 0) {
|
||||||
}
|
}
|
||||||
logger('groups: ' . print_r($grps,true));
|
logger('groups: ' . print_r($grps,true));
|
||||||
|
|
||||||
|
if ($label == "")
|
||||||
|
$label = t('Default privacy group for new contacts');
|
||||||
|
|
||||||
$o = replace_macros(get_markup_template('group_selection.tpl'), array(
|
$o = replace_macros(get_markup_template('group_selection.tpl'), array(
|
||||||
'$label' => t('Default privacy group for new contacts'),
|
'$label' => $label,
|
||||||
'$groups' => $grps
|
'$groups' => $grps
|
||||||
));
|
));
|
||||||
return $o;
|
return $o;
|
||||||
|
@ -375,3 +378,28 @@ function groups_count_unseen() {
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the default group for a given user and network
|
||||||
|
*
|
||||||
|
* @param int $uid User id
|
||||||
|
* @param string $network network name
|
||||||
|
*
|
||||||
|
* @return int group id
|
||||||
|
*/
|
||||||
|
function get_default_group($uid, $network = "") {
|
||||||
|
|
||||||
|
$default_group = 0;
|
||||||
|
|
||||||
|
if ($network == NETWORK_OSTATUS)
|
||||||
|
$default_group = get_pconfig($uid, "ostatus", "default_group");
|
||||||
|
|
||||||
|
if ($default_group != 0)
|
||||||
|
return $default_group;
|
||||||
|
|
||||||
|
$g = q("SELECT `def_gid` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
|
||||||
|
if($g && intval($g[0]["def_gid"]))
|
||||||
|
$default_group = $g[0]["def_gid"];
|
||||||
|
|
||||||
|
return $default_group;
|
||||||
|
}
|
||||||
|
|
|
@ -489,13 +489,10 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$def_gid = get_default_group($uid, $contact["network"]);
|
||||||
$g = q("select def_gid from user where uid = %d limit 1",
|
if($contact && intval($def_gid)) {
|
||||||
intval($uid)
|
|
||||||
);
|
|
||||||
if($contact && $g && intval($g[0]['def_gid'])) {
|
|
||||||
require_once('include/group.php');
|
require_once('include/group.php');
|
||||||
group_add_member($uid,'',$contact['id'],$g[0]['def_gid']);
|
group_add_member($uid, '', $contact['id'], $def_gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's send our user to the contact editor in case they want to
|
// Let's send our user to the contact editor in case they want to
|
||||||
|
|
|
@ -174,18 +174,16 @@ function dfrn_request_post(&$a) {
|
||||||
info( t("Introduction complete.") . EOL);
|
info( t("Introduction complete.") . EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("select id from contact where uid = %d and url = '%s' and `site-pubkey` = '%s' limit 1",
|
$r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `site-pubkey` = '%s' LIMIT 1",
|
||||||
intval(local_user()),
|
intval(local_user()),
|
||||||
dbesc($dfrn_url),
|
dbesc($dfrn_url),
|
||||||
$parms['key'] // this was already escaped
|
$parms['key'] // this was already escaped
|
||||||
);
|
);
|
||||||
if(count($r)) {
|
if(count($r)) {
|
||||||
$g = q("select def_gid from user where uid = %d limit 1",
|
$def_gid = get_default_group(local_user(), $r[0]["network"]);
|
||||||
intval(local_user())
|
if(intval($def_gid)) {
|
||||||
);
|
|
||||||
if($g && intval($g[0]['def_gid'])) {
|
|
||||||
require_once('include/group.php');
|
require_once('include/group.php');
|
||||||
group_add_member(local_user(),'',$r[0]['id'],$g[0]['def_gid']);
|
group_add_member(local_user(), '', $r[0]['id'], $def_gid);
|
||||||
}
|
}
|
||||||
$forwardurl = $a->get_baseurl()."/contacts/".$r[0]['id'];
|
$forwardurl = $a->get_baseurl()."/contacts/".$r[0]['id'];
|
||||||
} else
|
} else
|
||||||
|
@ -388,19 +386,17 @@ function dfrn_request_post(&$a) {
|
||||||
intval($rel)
|
intval($rel)
|
||||||
);
|
);
|
||||||
|
|
||||||
$r = q("select id from contact where poll = '%s' and uid = %d limit 1",
|
$r = q("SELECT `id`, `network` FROM `contact` WHERE `poll` = '%s' AND `uid` = %d LIMIT 1",
|
||||||
dbesc($poll),
|
dbesc($poll),
|
||||||
intval($uid)
|
intval($uid)
|
||||||
);
|
);
|
||||||
if(count($r)) {
|
if(count($r)) {
|
||||||
$contact_id = $r[0]['id'];
|
$contact_id = $r[0]['id'];
|
||||||
|
|
||||||
$g = q("select def_gid from user where uid = %d limit 1",
|
$def_gid = get_default_group($uid, $r[0]["network"]);
|
||||||
intval($uid)
|
if (intval($def_gid)) {
|
||||||
);
|
|
||||||
if($g && intval($g[0]['def_gid'])) {
|
|
||||||
require_once('include/group.php');
|
require_once('include/group.php');
|
||||||
group_add_member($uid,'',$contact_id,$g[0]['def_gid']);
|
group_add_member($uid, '', $contact_id, $def_gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
$photo = avatar_img($addr);
|
$photo = avatar_img($addr);
|
||||||
|
|
|
@ -199,6 +199,7 @@ function settings_post(&$a) {
|
||||||
if(x($_POST, 'general-submit')) {
|
if(x($_POST, 'general-submit')) {
|
||||||
set_pconfig(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening']));
|
set_pconfig(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening']));
|
||||||
set_pconfig(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow']));
|
set_pconfig(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow']));
|
||||||
|
set_pconfig(local_user(), 'ostatus', 'default_group', $_POST['group-selection']);
|
||||||
set_pconfig(local_user(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']);
|
set_pconfig(local_user(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']);
|
||||||
} elseif(x($_POST, 'imap-submit')) {
|
} elseif(x($_POST, 'imap-submit')) {
|
||||||
|
|
||||||
|
@ -797,8 +798,11 @@ function settings_content(&$a) {
|
||||||
$settings_connectors .= '<span class="field_help">'.t('If you receive a message from an unknown OStatus user, this option decides what to do. If it is checked, a new contact will be created for every unknown user.').'</span>';
|
$settings_connectors .= '<span class="field_help">'.t('If you receive a message from an unknown OStatus user, this option decides what to do. If it is checked, a new contact will be created for every unknown user.').'</span>';
|
||||||
$settings_connectors .= '</div>';
|
$settings_connectors .= '</div>';
|
||||||
|
|
||||||
|
$default_group = get_pconfig(local_user(), 'ostatus', 'default_group');
|
||||||
$legacy_contact = get_pconfig(local_user(), 'ostatus', 'legacy_contact');
|
$legacy_contact = get_pconfig(local_user(), 'ostatus', 'legacy_contact');
|
||||||
|
|
||||||
|
$settings_connectors .= mini_group_select(local_user(), $default_group, t("Default group for OStatus contacts"));
|
||||||
|
|
||||||
if ($legacy_contact != "")
|
if ($legacy_contact != "")
|
||||||
$a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.$a->get_baseurl().'/ostatus_subscribe?url='.urlencode($legacy_contact).'">';
|
$a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.$a->get_baseurl().'/ostatus_subscribe?url='.urlencode($legacy_contact).'">';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue