From 0cfcb023118444bac29014e06a14fc1af2d0cf75 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 23 Jun 2014 05:19:28 -0700 Subject: [PATCH] ability to like things --- boot.php | 2 +- include/identity.php | 4 +++- include/taxonomy.php | 16 ++++++++++++++-- install/database.sql | 4 +++- install/update.php | 10 +++++++++- mod/like.php | 11 ++++++++--- view/theme/redbasic/css/style.css | 8 ++++++++ view/tpl/profile_advanced.tpl | 15 ++++++++++++++- view/tpl/show_thing.tpl | 4 ++-- 9 files changed, 62 insertions(+), 12 deletions(-) diff --git a/boot.php b/boot.php index 4c93cd117..db2401847 100755 --- a/boot.php +++ b/boot.php @@ -47,7 +47,7 @@ define ( 'RED_PLATFORM', 'Red Matrix' ); define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'ZOT_REVISION', 1 ); -define ( 'DB_UPDATE_VERSION', 1114 ); +define ( 'DB_UPDATE_VERSION', 1115 ); define ( 'EOL', '
' . "\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/include/identity.php b/include/identity.php index b086da94f..1cbe43b1e 100644 --- a/include/identity.php +++ b/include/identity.php @@ -1044,10 +1044,12 @@ function advanced_profile(&$a) { $things = get_things($a->profile['profile_guid'],$a->profile['profile_uid']); - logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA); +// logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA); return replace_macros($tpl, array( '$title' => t('Profile'), + '$canlike' => (($profile['canlike'])? true : false), + '$likethis' => t('Like this thing'), '$profile' => $profile, '$things' => $things )); diff --git a/include/taxonomy.php b/include/taxonomy.php index 4f2b5e8fd..803e1ae0a 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -322,9 +322,21 @@ function get_things($profile_hash,$uid) { foreach($v as $k => $foo) $things[$k] = null; foreach($r as $rr) { + + $l = q("select xchan_name, xchan_url from likes left join xchan on likee = xchan_hash where + target_type = '%s' and target_id = '%s' and channel_id = %d", + dbesc(ACTIVITY_OBJ_THING), + dbesc($rr['term_hash']), + intval($uid) + ); + + for($x = 0; $x < count($l); $x ++) + $l[$x]['xchan_url'] = zid($l[$x]['xchan_url']); + if(! $things[$rr['obj_verb']]) $things[$rr['obj_verb']] = array(); - $things[$rr['obj_verb']][] = array('term' => $rr['term'],'url' => $rr['url'],'img' => $rr['imgurl'], 'profile' => $rr['profile_name']); + $things[$rr['obj_verb']][] = array('term' => $rr['term'],'url' => $rr['url'],'img' => $rr['imgurl'], 'profile' => $rr['profile_name'],'term_hash' => $rr['term_hash'], 'likes' => $l,'like_count' => count($l),'like_label' => tt('Like','Likes',count($l),'noun')); + } $sorted_things = array(); if($things) { @@ -335,7 +347,7 @@ function get_things($profile_hash,$uid) { } } } - +//logger('things: ' . print_r($sorted_things,true)); return $sorted_things; } \ No newline at end of file diff --git a/install/database.sql b/install/database.sql index cb4846b52..e2b814067 100644 --- a/install/database.sql +++ b/install/database.sql @@ -581,6 +581,7 @@ CREATE TABLE IF NOT EXISTS `likes` ( `iid` int(10) unsigned NOT NULL DEFAULT '0', `verb` char(255) NOT NULL DEFAULT '', `target_type` char(255) NOT NULL DEFAULT '', + `target_id` char(128) NOT NULL DEFAULT '', `target` mediumtext NOT NULL, PRIMARY KEY (`id`), KEY `channel_id` (`channel_id`), @@ -588,7 +589,8 @@ CREATE TABLE IF NOT EXISTS `likes` ( KEY `likee` (`likee`), KEY `iid` (`iid`), KEY `verb` (`verb`), - KEY `target_type` (`target_type`) + KEY `target_type` (`target_type`), + KEY `target_id` (`target_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `mail` ( diff --git a/install/update.php b/install/update.php index b6bcfa237..bdf84144c 100644 --- a/install/update.php +++ b/install/update.php @@ -1,6 +1,6 @@ {{if $profile.canlike}} - {{/if}} @@ -200,6 +200,19 @@ {{foreach $items as $item}}
  • {{if $item.img}}{{$item.term}}{{/if}} {{$item.term}} +{{if $profile.canlike}}
    + +{{/if}} +{{if $item.like_count}} +
    + +{{if $item.likes}} + +{{/if}} +
    +{{/if}}
  • {{/foreach}} diff --git a/view/tpl/show_thing.tpl b/view/tpl/show_thing.tpl index 2a8c06076..c48912918 100644 --- a/view/tpl/show_thing.tpl +++ b/view/tpl/show_thing.tpl @@ -6,8 +6,8 @@ {{if $canedit}} {{/if}}