profile likes
This commit is contained in:
parent
535aa28526
commit
c4c1c37bd3
@ -96,6 +96,9 @@ function localize_item(&$item){
|
|||||||
if(! $item['object'])
|
if(! $item['object'])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if($item['item_flags'] & ITEM_THREAD_TOP)
|
||||||
|
return;
|
||||||
|
|
||||||
$obj = json_decode_plus($item['object']);
|
$obj = json_decode_plus($item['object']);
|
||||||
if((! $obj) && ($item['object'])) {
|
if((! $obj) && ($item['object'])) {
|
||||||
logger('localize_item: failed to decode object: ' . print_r($item['object'],true));
|
logger('localize_item: failed to decode object: ' . print_r($item['object'],true));
|
||||||
|
@ -951,6 +951,25 @@ function advanced_profile(&$a) {
|
|||||||
|
|
||||||
if($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
|
if($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
|
||||||
|
|
||||||
|
$ob_hash = get_observer_hash();
|
||||||
|
if($ob_hash && perm_is_allowed($a->profile['profile_uid'],$ob_hash,'post_wall')) {
|
||||||
|
$profile['canlike'] = true;
|
||||||
|
$profile['likethis'] = t('Like this channel');
|
||||||
|
$profile['profile_guid'] = $a->profile['profile_guid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$likers = q("select liker, xchan.* from likes left join xchan on liker = xchan_hash where channel_id = %d and target_type = '%s' and verb = '%s'",
|
||||||
|
intval($a->profile['profile_uid']),
|
||||||
|
dbesc(ACTIVITY_OBJ_PROFILE),
|
||||||
|
dbesc(ACTIVITY_LIKE)
|
||||||
|
);
|
||||||
|
$profile['likers'] = array();
|
||||||
|
$profile['like_count'] = count($likers);
|
||||||
|
$profile['like_button_label'] = tt('Like','Likes',$profile['like_count'],'noun');
|
||||||
|
if($likers) {
|
||||||
|
foreach($likers as $l)
|
||||||
|
$profile['likers'][] = array('name' => $l['xchan_name'],'url' => zid($l['xchan_url']));
|
||||||
|
}
|
||||||
|
|
||||||
if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
|
if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
|
||||||
|
|
||||||
|
174
mod/like.php
174
mod/like.php
@ -10,7 +10,6 @@ function like_content(&$a) {
|
|||||||
|
|
||||||
$observer = $a->get_observer();
|
$observer = $a->get_observer();
|
||||||
|
|
||||||
|
|
||||||
$verb = notags(trim($_GET['verb']));
|
$verb = notags(trim($_GET['verb']));
|
||||||
|
|
||||||
if(! $verb)
|
if(! $verb)
|
||||||
@ -31,11 +30,12 @@ function like_content(&$a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$extended_like = false;
|
$extended_like = false;
|
||||||
|
$object = $target = null;
|
||||||
|
$post_type = '';
|
||||||
|
$objtype = '';
|
||||||
|
|
||||||
if(argc() == 3) {
|
if(argc() == 3) {
|
||||||
|
|
||||||
$observer = $a->get_observer();
|
|
||||||
|
|
||||||
if(! $observer)
|
if(! $observer)
|
||||||
killme();
|
killme();
|
||||||
|
|
||||||
@ -50,13 +50,13 @@ function like_content(&$a) {
|
|||||||
);
|
);
|
||||||
if(! $r)
|
if(! $r)
|
||||||
killme();
|
killme();
|
||||||
$owner_id = $r[0]['uid'];
|
$owner_uid = $r[0]['uid'];
|
||||||
if($r[0]['is_default'])
|
if($r[0]['is_default'])
|
||||||
$public = true;
|
$public = true;
|
||||||
if(! $public) {
|
if(! $public) {
|
||||||
$d = q("select abook_xchan from abook where abook_profile = '%s' and abook_channel = %d",
|
$d = q("select abook_xchan from abook where abook_profile = '%s' and abook_channel = %d",
|
||||||
dbesc($r[0]['profile_guid']),
|
dbesc($r[0]['profile_guid']),
|
||||||
intval($owner_id)
|
intval($owner_uid)
|
||||||
);
|
);
|
||||||
if(! $d) {
|
if(! $d) {
|
||||||
// forgery - illegal
|
// forgery - illegal
|
||||||
@ -68,19 +68,24 @@ function like_content(&$a) {
|
|||||||
foreach($d as $dd) {
|
foreach($d as $dd) {
|
||||||
$allow_gid .= '<' . $dd['abook_xchan'] . '>';
|
$allow_gid .= '<' . $dd['abook_xchan'] . '>';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$post_type = t('channel');
|
||||||
|
$objtype = ACTIVITY_OBJ_PROFILE;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif($obj_type == 'thing') {
|
elseif($obj_type == 'thing') {
|
||||||
$r = q("select * from obj where obj_id = %d limit 1",
|
|
||||||
intval(argv(2))
|
$r = q("select * from obj left join term on obj_obj = term_hash where term_hash != ''
|
||||||
|
and obj_type = %d and term_hash = '%s' limit 1",
|
||||||
|
intval(TERM_OBJ_THING),
|
||||||
|
dbesc(argv(2))
|
||||||
);
|
);
|
||||||
|
|
||||||
if(! $r)
|
if(! $r)
|
||||||
killme();
|
killme();
|
||||||
|
|
||||||
$owner_id = $r[0]['obj_channel'];
|
$owner_uid = $r[0]['obj_channel'];
|
||||||
|
|
||||||
$allow_cid = $r[0]['allow_cid'];
|
$allow_cid = $r[0]['allow_cid'];
|
||||||
$allow_gid = $r[0]['allow_gid'];
|
$allow_gid = $r[0]['allow_gid'];
|
||||||
@ -89,11 +94,78 @@ function like_content(&$a) {
|
|||||||
if($allow_cid || $allow_gid || $deny_cid || $deny_gid)
|
if($allow_cid || $allow_gid || $deny_cid || $deny_gid)
|
||||||
$public = false;
|
$public = false;
|
||||||
|
|
||||||
|
$post_type = t('thing');
|
||||||
|
$objtype = ACTIVITY_OBJ_PROFILE;
|
||||||
|
$tgttype = ACTIVITY_OBJ_THING;
|
||||||
|
|
||||||
|
$links = array();
|
||||||
|
$links[] = array('rel' => 'alternate', 'type' => 'text/html',
|
||||||
|
'href' => z_root() . '/thing/' . $r[0]['term_hash']);
|
||||||
|
if($r[0]['imgurl'])
|
||||||
|
$links[] = array('rel' => 'photo', 'href' => $r[0]['imgurl']);
|
||||||
|
|
||||||
|
$target = json_encode(array(
|
||||||
|
'type' => $tgttype,
|
||||||
|
'title' => $r[0]['term'],
|
||||||
|
'id' => z_root() . '/thing/' . $r[0]['term_hash'],
|
||||||
|
'link' => $links
|
||||||
|
));
|
||||||
|
|
||||||
|
$plink = '[zrl=' . z_root() . '/thing/' . $r[0]['term_hash'] . ']' . $r[0]['term'] . '[/zrl]';
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if(! ($owner_uid && $r))
|
||||||
killme();
|
killme();
|
||||||
|
|
||||||
|
// The resultant activity is going to be a wall-to-wall post, so make sure this is allowed
|
||||||
|
|
||||||
|
$perms = get_all_perms($owner_uid,$observer['xchan_hash']);
|
||||||
|
|
||||||
|
if(! ($perms['post_wall'] && $perms['view_profile']))
|
||||||
|
killme();
|
||||||
|
|
||||||
|
$ch = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
|
||||||
|
intval($owner_uid)
|
||||||
|
);
|
||||||
|
if(! $ch)
|
||||||
|
killme();
|
||||||
|
|
||||||
|
|
||||||
|
if(! $plink)
|
||||||
|
$plink = '[zrl=' . z_root() . '/profile/' . $ch[0]['channel_address'] . ']' . $post_type . '[/zrl]';
|
||||||
|
|
||||||
|
$links = array();
|
||||||
|
$links[] = array('rel' => 'alternate', 'type' => 'text/html',
|
||||||
|
'href' => z_root() . '/profile/' . $ch[0]['channel_address']);
|
||||||
|
$links[] = array('rel' => 'photo', 'type' => $ch[0]['xchan_photo_mimetype'],
|
||||||
|
'href' => $ch[0]['xchan_photo_l']);
|
||||||
|
|
||||||
|
$object = json_encode(array(
|
||||||
|
'type' => ACTIVITY_OBJ_PROFILE,
|
||||||
|
'title' => $ch[0]['channel_name'],
|
||||||
|
'id' => $ch[0]['xchan_url'] . '/' . $ch[0]['xchan_hash'],
|
||||||
|
'link' => $links
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
// second like of the same thing is "undo" for the first like
|
||||||
|
|
||||||
|
$z = q("select * from likes where channel_id = %d and liker = '%s' and verb = '%s' and target_type = '%s' and target = '%s' limit 1",
|
||||||
|
intval($ch[0]['channel_id']),
|
||||||
|
dbesc($observer['xchan_hash']),
|
||||||
|
dbesc($activity),
|
||||||
|
dbesc(($tgttype)?$tgttype:$objtype),
|
||||||
|
dbesc(json_encode(($target)?$target:$object))
|
||||||
|
);
|
||||||
|
|
||||||
|
if($z) {
|
||||||
|
q("delete from likes where id = %d limit 1",
|
||||||
|
intval($z[0]['id'])
|
||||||
|
);
|
||||||
|
drop_item($z[0]['iid'],false);
|
||||||
|
killme();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
@ -117,7 +189,6 @@ function like_content(&$a) {
|
|||||||
$owner_aid = $item['aid'];
|
$owner_aid = $item['aid'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$sys = get_sys_channel();
|
$sys = get_sys_channel();
|
||||||
|
|
||||||
|
|
||||||
@ -175,6 +246,11 @@ function like_content(&$a) {
|
|||||||
|
|
||||||
$mid = item_message_id();
|
$mid = item_message_id();
|
||||||
|
|
||||||
|
if($extended_like) {
|
||||||
|
$item_flags = ITEM_THREAD_TOP|ITEM_ORIGIN|ITEM_WALL;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
$post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status'));
|
$post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status'));
|
||||||
|
|
||||||
$links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $item['plink']));
|
$links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $item['plink']));
|
||||||
@ -182,7 +258,7 @@ function like_content(&$a) {
|
|||||||
|
|
||||||
$body = $item['body'];
|
$body = $item['body'];
|
||||||
|
|
||||||
$obj = json_encode(array(
|
$object = json_encode(array(
|
||||||
'type' => $objtype,
|
'type' => $objtype,
|
||||||
'id' => $item['mid'],
|
'id' => $item['mid'],
|
||||||
'parent' => (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']),
|
'parent' => (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']),
|
||||||
@ -205,46 +281,68 @@ function like_content(&$a) {
|
|||||||
if(! ($item['item_flags'] & ITEM_THREAD_TOP))
|
if(! ($item['item_flags'] & ITEM_THREAD_TOP))
|
||||||
$post_type = 'comment';
|
$post_type = 'comment';
|
||||||
|
|
||||||
|
$item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN;
|
||||||
|
if($item['item_flags'] & ITEM_WALL)
|
||||||
|
$item_flags |= ITEM_WALL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if($verb === 'like')
|
if($verb === 'like')
|
||||||
$bodyverb = t('%1$s likes %2$s\'s %3$s');
|
$bodyverb = t('%1$s likes %2$s\'s %3$s');
|
||||||
if($verb === 'dislike')
|
if($verb === 'dislike')
|
||||||
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
|
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
|
||||||
|
|
||||||
if(! isset($bodyverb))
|
if(! isset($bodyverb))
|
||||||
return;
|
killme();
|
||||||
|
|
||||||
$item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN;
|
|
||||||
if($item['item_flags'] & ITEM_WALL)
|
|
||||||
$item_flags |= ITEM_WALL;
|
|
||||||
|
|
||||||
|
|
||||||
$arr = array();
|
$arr = array();
|
||||||
|
|
||||||
$arr['mid'] = $mid;
|
if($extended_like) {
|
||||||
$arr['aid'] = $owner_aid;
|
$ulink = '[zrl=' . $ch[0]['xchan_url'] . ']' . $ch[0]['xchan_name'] . '[/zrl]';
|
||||||
$arr['uid'] = $owner_uid;
|
$alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]';
|
||||||
$arr['item_flags'] = $item_flags;
|
$private = (($public) ? 0 : 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
$arr['parent'] = $item['id'];
|
$arr['parent'] = $item['id'];
|
||||||
$arr['parent_mid'] = $item['mid'];
|
|
||||||
$arr['thr_parent'] = $item['mid'];
|
$arr['thr_parent'] = $item['mid'];
|
||||||
$arr['owner_xchan'] = $thread_owner['xchan_hash'];
|
|
||||||
$arr['author_xchan'] = $observer['xchan_hash'];
|
|
||||||
|
|
||||||
|
|
||||||
$ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]';
|
$ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]';
|
||||||
$alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]';
|
$alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]';
|
||||||
$plink = '[zrl=' . $a->get_baseurl() . '/display/' . $item['mid'] . ']' . $post_type . '[/zrl]';
|
$plink = '[zrl=' . $a->get_baseurl() . '/display/' . $item['mid'] . ']' . $post_type . '[/zrl]';
|
||||||
|
$allow_cid = $item['allow_cid'];
|
||||||
|
$allow_gid = $item['allow_gid'];
|
||||||
|
$deny_cid = $item['deny_cid'];
|
||||||
|
$deny_gid = $item['deny_gid'];
|
||||||
|
$private = $item['private'];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$arr['mid'] = $mid;
|
||||||
|
$arr['aid'] = (($extended_like) ? $ch[0]['channel_account_id'] : $owner_aid);
|
||||||
|
$arr['uid'] = $owner_uid;
|
||||||
|
$arr['item_flags'] = $item_flags;
|
||||||
|
$arr['parent_mid'] = (($extended_like) ? $mid : $item['mid']);
|
||||||
|
$arr['owner_xchan'] = (($extended_like) ? $ch[0]['xchan_hash'] : $thread_owner['xchan_hash']);
|
||||||
|
$arr['author_xchan'] = $observer['xchan_hash'];
|
||||||
|
|
||||||
|
|
||||||
$arr['body'] = sprintf( $bodyverb, $alink, $ulink, $plink );
|
$arr['body'] = sprintf( $bodyverb, $alink, $ulink, $plink );
|
||||||
|
|
||||||
$arr['verb'] = $activity;
|
$arr['verb'] = $activity;
|
||||||
$arr['obj_type'] = $objtype;
|
$arr['obj_type'] = $objtype;
|
||||||
$arr['object'] = $obj;
|
$arr['object'] = $object;
|
||||||
|
|
||||||
$arr['allow_cid'] = $item['allow_cid'];
|
if($target) {
|
||||||
$arr['allow_gid'] = $item['allow_gid'];
|
$arr['tgt_type'] = $tgttype;
|
||||||
$arr['deny_cid'] = $item['deny_cid'];
|
$arr['target'] = $target;
|
||||||
$arr['deny_gid'] = $item['deny_gid'];
|
}
|
||||||
|
|
||||||
|
$arr['allow_cid'] = $allow_cid;
|
||||||
|
$arr['allow_gid'] = $allow_gid;
|
||||||
|
$arr['deny_cid'] = $deny_cid;
|
||||||
|
$arr['deny_gid'] = $deny_gid;
|
||||||
|
$arr['item_private'] = $private;
|
||||||
|
|
||||||
|
|
||||||
$post = item_store($arr);
|
$post = item_store($arr);
|
||||||
@ -254,6 +352,20 @@ function like_content(&$a) {
|
|||||||
|
|
||||||
call_hooks('post_local_end', $arr);
|
call_hooks('post_local_end', $arr);
|
||||||
|
|
||||||
|
|
||||||
|
if($extended_like) {
|
||||||
|
$r = q("insert into likes (channel_id,liker,likee,iid,verb,target_type,target) values (%d,'%s','%s',%d,'%s','%s','%s')",
|
||||||
|
intval($ch[0]['channel_id']),
|
||||||
|
dbesc($observer['xchan_hash']),
|
||||||
|
dbesc($ch[0]['channel_hash']),
|
||||||
|
intval($post_id),
|
||||||
|
dbesc($activity),
|
||||||
|
dbesc(($tgttype)?$tgttype:$objtype),
|
||||||
|
dbesc(json_encode(($target)?$target:$object))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
proc_run('php',"include/notifier.php","like","$post_id");
|
proc_run('php',"include/notifier.php","like","$post_id");
|
||||||
|
|
||||||
killme();
|
killme();
|
||||||
|
@ -695,6 +695,12 @@ function updateConvItems(mode,data) {
|
|||||||
liking = 1;
|
liking = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doprofilelike(ident,verb) {
|
||||||
|
$.get('like/' + ident + '?verb=' + verb, function() { window.location.href=window.location.href; });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function dosubthread(ident) {
|
function dosubthread(ident) {
|
||||||
unpause();
|
unpause();
|
||||||
$('#like-rotator-' + ident.toString()).spin('tiny');
|
$('#like-rotator-' + ident.toString()).spin('tiny');
|
||||||
|
@ -372,6 +372,14 @@ aside li {
|
|||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#profile-like {
|
||||||
|
margin-left: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#profile-like-wrapper {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.fn {
|
.fn {
|
||||||
padding: 0px 0px 5px 0px;
|
padding: 0px 0px 5px 0px;
|
||||||
|
@ -1,6 +1,26 @@
|
|||||||
<div id="profile-content-wrapper" class="generic-content-wrapper">
|
<div id="profile-content-wrapper" class="generic-content-wrapper">
|
||||||
<h2>{{$title}}</h2>
|
<h2>{{$title}}</h2>
|
||||||
|
|
||||||
|
{{if $profile.canlike || $profile.like_count}}
|
||||||
|
<div id="profile-like-wrapper">
|
||||||
|
{{if $profile.canlike}}
|
||||||
|
<button type="button" class="btn btn-default btn-sm" onclick="doprofilelike('profile/' + '{{$profile.profile_guid}}','like'); return false;">
|
||||||
|
<i class="icon-thumbs-up-alt" title="{{$profile.likethis}}"></i>
|
||||||
|
</button>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
|
||||||
|
{{if $profile.like_count}}
|
||||||
|
<div class="btn-group">
|
||||||
|
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" id="profile-like">{{$profile.like_count}} {{$profile.like_button_label}}</button>
|
||||||
|
{{if $profile.likers}}
|
||||||
|
<ul class="dropdown-menu" role="menu" aria-labelledby="profile-like">{{foreach $profile.likers as $liker}}<li role="presentation"><a href="{{$liker.url}}">{{$liker.name}}</a></li>{{/foreach}}</ul>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<dl id="aprofile-fullname" class="aprofile">
|
<dl id="aprofile-fullname" class="aprofile">
|
||||||
<dt>{{$profile.fullname.0}}</dt>
|
<dt>{{$profile.fullname.0}}</dt>
|
||||||
<dd>{{$profile.fullname.1}}</dd>
|
<dd>{{$profile.fullname.1}}</dd>
|
||||||
|
Reference in New Issue
Block a user