premium/restricted channel connections implemented, configure at yoursite/channel/nickname - this basically redirects "follow" requests to a premium channel's sell page if it has one configured. You can still click through and create a connection request (introduction), but this provides a means for the channel owner to state their terms. If you don't abide by the terms, you will likely be blocked or the channel deleted. This facility is extensible in a number of ways.

This commit is contained in:
friendica 2013-08-21 22:10:08 -07:00
parent 6cea04eb44
commit 925b046794
8 changed files with 82 additions and 15 deletions

View File

@ -1623,13 +1623,20 @@ function profile_sidebar($profile, $block = 0, $show_connect = true) {
require_once('include/Contact.php');
if($show_connect) {
$connect_url = (($show_connect) ? rconnect_url($profile['uid'],get_observer_hash()) : '');
$connect = (($connect_url) ? t('Connect') : '');
// This will return an empty string if we're already connected.
if($connect_url)
$connect_url = $connect_url . '/follow?f=1&url=' . urlencode($profile['channel_address'] . '@' . $a->get_hostname());
$connect_url = rconnect_url($profile['uid'],get_observer_hash());
$connect = (($connect_url) ? t('Connect') : '');
if($connect_url)
$connect_url = sprintf($connect_url,urlencode($profile['channel_address'] . '@' . $a->get_hostname()));
// premium channel - over-ride
if($profile['channel_pageflags'] & PAGE_PREMIUM)
$connect_url = z_root() . '/connect/' . $profile['channel_address'];
}
// show edit profile to yourself
if($is_owner) {

View File

@ -15,13 +15,20 @@ function rconnect_url($channel_id,$xchan) {
if($r)
return '';
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($xchan)
);
if(($r) && ($r[0]['xchan_follow']))
return $r[0]['xchan_follow'];
$r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and ( hubloc_flags & %d ) limit 1",
dbesc($xchan),
intval(HUBLOC_FLAGS_PRIMARY)
);
if($r)
return $r[0]['hubloc_url'];
return $r[0]['hubloc_url'] . '/follow?f=&url=%s';
return '';
}

View File

@ -11,7 +11,7 @@
require_once('include/zot.php');
function new_contact($uid,$url,$channel,$interactive = false) {
function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) {
$result = array('success' => false,'message' => '');
@ -60,6 +60,11 @@ function new_contact($uid,$url,$channel,$interactive = false) {
return $result;
}
// Premium channel, set confirm before callback to avoid recursion
if(array_key_exists('connect_url',$j) && (! $confirm))
goaway($j['connect_url']);
// check service class limits

View File

@ -31,12 +31,13 @@ function connect_post(&$a) {
$channel = $a->get_channel();
if(($channel['channel_pageflags'] & PAGE_PREMIUM) != $premium)
$r = q("update channel set channel_flags = channel_flags ^ %d where channel_id = %d limit 1",
$r = q("update channel set channel_pageflags = channel_pageflags ^ %d where channel_id = %d limit 1",
intval(PAGE_PREMIUM),
intval(local_user())
);
set_pconfig($a->profile['profile_uid'],'system','selltext',$text);
return;
goaway(z_root() . '/' . $a->query_string);
}
$url = '';
@ -53,7 +54,7 @@ function connect_post(&$a) {
}
}
if($url)
goaway($url);
goaway($url . '&confirm=1');
else
notice('Unable to connect to your home hub location.');
@ -68,20 +69,34 @@ function connect_content(&$a) {
$text = get_pconfig($a->profile['profile_uid'],'system','selltext');
if($edit) {
$channel = $a->get_channel();
$o = replace_macros(get_markup_template('sellpage_edit.tpl'),array(
'$header' => t('Premium Channel Setup'),
'$address' => $a->profile['channel_address'],
'$premium' => array('premium', t('Enable premium channel connection restrictions'),(($channel['channel_pageflags'] & PAGE_PREMIUM) ? '1' : ''),''),
'$lbl_about' => t('Please enter your restrictions or conditions, such as paypal receipt, usage guidelines, etc.'),
'$text' => $text,
'$desc' => t('This channel may require additional steps or acknowledgement of the following conditions prior to connecting:'),
'$lbl2' => t('Potential connections will then see the following text before proceeding:'),
'$desc2' => t('By continuing, I certify that I have complied with any instructions provided on this page.'),
'$submit' => t('Submit'),
));
return $o;
}
else {
if(! $text)
$text = t('(No specific instructions have been provided by the channel owner.)');
$submit = replace_macros(get_markup_template('sellpage_submit.tpl'), array(
'$continue' => t('Continue'),
'$address' => $a->profile['channel_address']
));
$o = replace_macros(get_markup_template('sellpage_view.tpl'),array(
'$header' => t('Restricted Channel'),
'$header' => t('Restricted or Premium Channel'),
'$desc' => t('This channel may require additional steps or acknowledgement of the following conditions prior to connecting:'),
'$text' => prepare_text($text),
@ -90,8 +105,9 @@ function connect_content(&$a) {
));
$arr = array('profile' => $a->profile,'observer' => $a->get_observer(), 'sellpage' => $o, 'submit' => $submit);
call_hooks('connect_premium', $arr);
$o = $arr['sellpage'];
}

View File

@ -12,8 +12,9 @@ function follow_init(&$a) {
$uid = local_user();
$url = notags(trim($_REQUEST['url']));
$return_url = $_SESSION['return_url'];
$confirm = intval($_REQUEST['confirm']);
$result = new_contact($uid,$url,$a->get_channel(),true);
$result = new_contact($uid,$url,$a->get_channel(),true,$confirm);
if($result['success'] == false) {
if($result['message'])

View File

@ -140,7 +140,7 @@ function zfinger_init(&$a) {
// This is a template - %s will be replaced with the follow_url we discover for the return channel.
if($special_channel)
$ret['connect_url'] = z_root() . '/connect/' . $e['channel_address'] . '?f=&follow=%s';
$ret['connect_url'] = z_root() . '/connect/' . $e['channel_address'];
// This is a template for our follow url, %s will be replaced with a webbie

View File

@ -1,3 +1,11 @@
.sellpage-body {
margin-top: 25px;
}
.sellpage-final {
margin-top: 25px;
}
#sellpage-edit label{
width: 300px;
}

View File

@ -0,0 +1,23 @@
<h1>{{$header}}</h1>
<form id="sellpage-edit" action="connect/{{$address}}" method="post">
{{include file="field_checkbox.tpl" field=$premium}}
<div class="descriptive-text">{{$desc}}</div>
<div class="sellpage-editbody">
<p id="sellpage-bodydesc" >
{{$lbl_about}}
</p>
<textarea rows="10" cols="72" id="sellpage-textinp" name="text" >{{$text}}</textarea>
</div>
<div id="sellpage-editbody-end"></div>
<div class="descriptive-text">{{$lbl2}}</div>
<div class="sellpage-final">{{$desc2}}</div>
<input type="submit" name="submit" value="{{$submit}}" />
</form>