From a985ad4a5407c3cbc0d0a3919e19ddd99bf108af Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 3 Nov 2010 16:48:21 -0700 Subject: [PATCH] add activity target to items, allow multiple link relations --- boot.php | 3 +- database.sql | 2 + include/items.php | 104 ++++++++++++++++++++++++++++++++++++++++++---- mod/photos.php | 34 +++++++++++++-- update.php | 7 +++- 5 files changed, 138 insertions(+), 12 deletions(-) diff --git a/boot.php b/boot.php index 5837f14d3c..60fccc0ea1 100644 --- a/boot.php +++ b/boot.php @@ -2,7 +2,7 @@ set_time_limit(0); -define ( 'BUILD_ID', 1013 ); +define ( 'BUILD_ID', 1014 ); define ( 'DFRN_PROTOCOL_VERSION', '2.0' ); define ( 'EOL', "
\r\n" ); @@ -61,6 +61,7 @@ define ( 'NAMESPACE_THREAD' , 'http://purl.org/syndication/thread/1.0' ) define ( 'NAMESPACE_TOMB' , 'http://purl.org/atompub/tombstones/1.0' ); define ( 'NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/' ); define ( 'NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/1.0/' ); +define ( 'NAMESPACE_MEDIA', 'http://purl.org/syndication/atommedia' ); define ( 'NAMESPACE_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env' ); define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe' ); define ( 'NAMESPACE_GEORSS', 'http://www.georss.org/georss' ); diff --git a/database.sql b/database.sql index 5b8141f7ae..33f1e79497 100644 --- a/database.sql +++ b/database.sql @@ -174,6 +174,8 @@ CREATE TABLE IF NOT EXISTS `item` ( `verb` char(255) NOT NULL, `object-type` char(255) NOT NULL, `object` text NOT NULL, + `target-type` char(255) NOT NULL, + `target` text NOT NULL, `resource-id` char(255) NOT NULL, `tag` mediumtext NOT NULL, `inform` mediumtext NOT NULL, diff --git a/include/items.php b/include/items.php index da85ed331d..b016fa180c 100644 --- a/include/items.php +++ b/include/items.php @@ -188,7 +188,7 @@ function construct_verb($item) { return ACTIVITY_POST; } -function construct_activity($item) { +function construct_activity_object($item) { if($item['object']) { $o = '' . "\r\n"; @@ -197,8 +197,12 @@ function construct_activity($item) { $o .= '' . xmlify($r->type) . '' . "\r\n"; if($r->id) $o .= '' . xmlify($r->id) . '' . "\r\n"; - if($r->link) - $o .= '' . "\r\n"; + if($r->link) { + if(substr($r->link,0,1) === '&') + $o .= unxmlify($r->link); + else + $o .= '' . "\r\n"; + } if($r->title) $o .= '' . xmlify($r->title) . '' . "\r\n"; if($r->content) @@ -210,6 +214,32 @@ function construct_activity($item) { return ''; } +function construct_activity_target($item) { + + if($item['target']) { + $o = '' . "\r\n"; + $r = @simplexml_load_string($item['target']); + if($r->type) + $o .= '' . xmlify($r->type) . '' . "\r\n"; + if($r->id) + $o .= '' . xmlify($r->id) . '' . "\r\n"; + if($r->link) { + if(substr($r->link,0,1) === '&') + $o .= unxmlify($r->link); + else + $o .= '' . "\r\n"; + } + if($r->title) + $o .= '' . xmlify($r->title) . '' . "\r\n"; + if($r->content) + $o .= '' . xmlify(bbcode($r->content)) . '' . "\r\n"; + $o .= '' . "\r\n"; + return $o; + } + + return ''; +} + @@ -391,9 +421,8 @@ function get_atom_elements($feed,$item) { } if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) $res['object'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '' . "\n"; - - if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'][0]['attribs']['']['rel'] === 'alternate') - $res['object'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'][0]['attribs']['']['href'] . '' . "\n"; + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) + $res['target'] .= '' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '' . "\n"; if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) $res['object'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '' . "\n"; if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { @@ -419,9 +448,67 @@ function get_atom_elements($feed,$item) { $res['object'] .= '' . "\n"; } + $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'target'); + + if($rawobj) { + $res['target'] = '' . "\n"; + if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) { + $res['target'] .= '' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '' . "\n"; + } + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) + $res['target'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '' . "\n"; + + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) + $res['target'] .= '' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '' . "\n"; + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) + $res['target'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '' . "\n"; + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { + $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']; + if(! $body) + $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data']; + if(strpos($body,'<')) { + + $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $body); + + $config = HTMLPurifier_Config::createDefault(); + $config->set('Cache.DefinitionImpl', null); + + $purifier = new HTMLPurifier($config); + $body = $purifier->purify($body); + } + + $body = html2bbcode($body); + $res['target'] .= '' . $body . '' . "\n"; + } + + $res['target'] .= '' . "\n"; + } + return $res; } +function encode_rel_links($links) { + $o = ''; + if(! ((is_array($links)) && (count($links)))) + return $o; + foreach($links as $link) { + $o .= '' . "\r\n"; - $actobj = construct_activity($item); + $actobj = construct_activity_object($item); if(strlen($actobj)) $o .= $actobj; + $actarg = construct_activity_target($item); + if(strlen($actarg)) + $o .= $actarg; $mentioned = get_mentions($item); if($mentioned) diff --git a/mod/photos.php b/mod/photos.php index 8d2805fdef..298bc9907b 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -259,6 +259,7 @@ function photos_post(&$a) { if($x !== '@' && $x !== '#') $rawtags = '#' . $rawtags; + $taginfo = array(); $tags = get_tags($rawtags); if(count($tags)) { @@ -273,12 +274,14 @@ function photos_post(&$a) { if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') $profile = $link['@attributes']['href']; if($link['@attributes']['rel'] === 'salmon') { + $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']); if(strlen($inform)) $inform .= ','; - $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']); + $inform .= $salmon; } } } + $taginfo[] = array($newname,$profile,$salmon); } else { $newname = $name; @@ -297,12 +300,14 @@ function photos_post(&$a) { } if(count($r)) { $profile = $r[0]['url']; + $notify = 'cid:' . $r[0]['id']; if(strlen($inform)) $inform .= ','; - $inform .= 'cid:' . $r[0]['id']; + $inform .= $notify; } } if($profile) { + $taginfo[] = array($newname,$profile,$notify); if(strlen($str_tags)) $str_tags .= ','; $profile = str_replace(',','%2c',$profile); @@ -330,13 +335,36 @@ function photos_post(&$a) { intval($item_id), intval(local_user()) ); + + if(count($taginfo)) { + foreach($taginfo as $tagged) { +// $slap = create_photo_tag(local_user(),$item_id, $tagged); + + +// + } + // call notifier on new tag activity + } + +// $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php'); + +// $proc_debug = get_config('system','proc_debug'); + + // send the notification upstream/downstream as the case may be + +// if($i[0]['visible']) +// proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" $proc_debug & ", +// array(),$foo)); + + + } goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); return; // NOTREACHED } - + // default post action - upload a photo if(! x($_FILES,'userfile')) killme(); diff --git a/update.php b/update.php index 9c5caa0b59..68367343d4 100644 --- a/update.php +++ b/update.php @@ -96,4 +96,9 @@ function update_1011() { function update_1012() { q("ALTER TABLE `item` ADD `inform` MEDIUMTEXT NOT NULL AFTER `tag` "); -} \ No newline at end of file +} + +function update_1013() { + q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL + AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`"); +} \ No newline at end of file