add activity target to items, allow multiple link relations

This commit is contained in:
Friendika 2010-11-03 16:48:21 -07:00
parent 98a508532f
commit a985ad4a54
5 changed files with 138 additions and 12 deletions

View file

@ -2,7 +2,7 @@
set_time_limit(0); set_time_limit(0);
define ( 'BUILD_ID', 1013 ); define ( 'BUILD_ID', 1014 );
define ( 'DFRN_PROTOCOL_VERSION', '2.0' ); define ( 'DFRN_PROTOCOL_VERSION', '2.0' );
define ( 'EOL', "<br />\r\n" ); define ( 'EOL', "<br />\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_TOMB' , 'http://purl.org/atompub/tombstones/1.0' );
define ( 'NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/' ); define ( 'NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/' );
define ( 'NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/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_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env' );
define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe' ); define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe' );
define ( 'NAMESPACE_GEORSS', 'http://www.georss.org/georss' ); define ( 'NAMESPACE_GEORSS', 'http://www.georss.org/georss' );

View file

@ -174,6 +174,8 @@ CREATE TABLE IF NOT EXISTS `item` (
`verb` char(255) NOT NULL, `verb` char(255) NOT NULL,
`object-type` char(255) NOT NULL, `object-type` char(255) NOT NULL,
`object` text NOT NULL, `object` text NOT NULL,
`target-type` char(255) NOT NULL,
`target` text NOT NULL,
`resource-id` char(255) NOT NULL, `resource-id` char(255) NOT NULL,
`tag` mediumtext NOT NULL, `tag` mediumtext NOT NULL,
`inform` mediumtext NOT NULL, `inform` mediumtext NOT NULL,

View file

@ -188,7 +188,7 @@ function construct_verb($item) {
return ACTIVITY_POST; return ACTIVITY_POST;
} }
function construct_activity($item) { function construct_activity_object($item) {
if($item['object']) { if($item['object']) {
$o = '<as:object>' . "\r\n"; $o = '<as:object>' . "\r\n";
@ -197,8 +197,12 @@ function construct_activity($item) {
$o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n"; $o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
if($r->id) if($r->id)
$o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n"; $o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
if($r->link) if($r->link) {
if(substr($r->link,0,1) === '&')
$o .= unxmlify($r->link);
else
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n"; $o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
}
if($r->title) if($r->title)
$o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n"; $o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
if($r->content) if($r->content)
@ -210,6 +214,32 @@ function construct_activity($item) {
return ''; return '';
} }
function construct_activity_target($item) {
if($item['target']) {
$o = '<as:target>' . "\r\n";
$r = @simplexml_load_string($item['target']);
if($r->type)
$o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
if($r->id)
$o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
if($r->link) {
if(substr($r->link,0,1) === '&')
$o .= unxmlify($r->link);
else
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
}
if($r->title)
$o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
if($r->content)
$o .= '<content type="html" >' . xmlify(bbcode($r->content)) . '</content>' . "\r\n";
$o .= '</as:target>' . "\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']) if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'])
$res['object'] .= '<id>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n"; $res['object'] .= '<id>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'])
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'][0]['attribs']['']['rel'] === 'alternate') $res['target'] .= '<link>' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n";
$res['object'] .= '<link>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'][0]['attribs']['']['href'] . '</link>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'])
$res['object'] .= '<title>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n"; $res['object'] .= '<title>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) {
@ -419,9 +448,67 @@ function get_atom_elements($feed,$item) {
$res['object'] .= '</object>' . "\n"; $res['object'] .= '</object>' . "\n";
} }
$rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'target');
if($rawobj) {
$res['target'] = '<target>' . "\n";
if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) {
$res['target'] .= '<type>' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '</type>' . "\n";
}
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'])
$res['target'] .= '<id>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'])
$res['target'] .= '<link>' . encode_rel_links($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n";
if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'])
$res['target'] .= '<title>' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\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('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#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'] .= '<content>' . $body . '</content>' . "\n";
}
$res['target'] .= '</target>' . "\n";
}
return $res; return $res;
} }
function encode_rel_links($links) {
$o = '';
if(! ((is_array($links)) && (count($links))))
return $o;
foreach($links as $link) {
$o .= '<link ';
if($link['attribs']['']['rel'])
$o .= 'rel="' . $link['attribs']['']['rel'] . '" ';
if($link['attribs']['']['type'])
$o .= 'type="' . $link['attribs']['']['type'] . '" ';
if($link['attribs']['']['href'])
$o .= 'type="' . $link['attribs']['']['href'] . '" ';
if($link['attribs'][NAMESPACE_MEDIA]['width'])
$o .= 'media:width="' . $link['attribs'][NAMESPACE_MEDIA]['width'] . '" ';
if($link['attribs'][NAMESPACE_MEDIA]['height'])
$o .= 'media:height="' . $link['attribs'][NAMESPACE_MEDIA]['height'] . '" ';
$o .= ' />' . "\n" ;
}
return xmlify($o);
}
function item_store($arr) { function item_store($arr) {
if($arr['gravity']) if($arr['gravity'])
@ -1050,9 +1137,12 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
$verb = construct_verb($item); $verb = construct_verb($item);
$o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n"; $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n";
$actobj = construct_activity($item); $actobj = construct_activity_object($item);
if(strlen($actobj)) if(strlen($actobj))
$o .= $actobj; $o .= $actobj;
$actarg = construct_activity_target($item);
if(strlen($actarg))
$o .= $actarg;
$mentioned = get_mentions($item); $mentioned = get_mentions($item);
if($mentioned) if($mentioned)

View file

@ -259,6 +259,7 @@ function photos_post(&$a) {
if($x !== '@' && $x !== '#') if($x !== '@' && $x !== '#')
$rawtags = '#' . $rawtags; $rawtags = '#' . $rawtags;
$taginfo = array();
$tags = get_tags($rawtags); $tags = get_tags($rawtags);
if(count($tags)) { if(count($tags)) {
@ -273,12 +274,14 @@ function photos_post(&$a) {
if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
$profile = $link['@attributes']['href']; $profile = $link['@attributes']['href'];
if($link['@attributes']['rel'] === 'salmon') { if($link['@attributes']['rel'] === 'salmon') {
$salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
if(strlen($inform)) if(strlen($inform))
$inform .= ','; $inform .= ',';
$inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']); $inform .= $salmon;
} }
} }
} }
$taginfo[] = array($newname,$profile,$salmon);
} }
else { else {
$newname = $name; $newname = $name;
@ -297,12 +300,14 @@ function photos_post(&$a) {
} }
if(count($r)) { if(count($r)) {
$profile = $r[0]['url']; $profile = $r[0]['url'];
$notify = 'cid:' . $r[0]['id'];
if(strlen($inform)) if(strlen($inform))
$inform .= ','; $inform .= ',';
$inform .= 'cid:' . $r[0]['id']; $inform .= $notify;
} }
} }
if($profile) { if($profile) {
$taginfo[] = array($newname,$profile,$notify);
if(strlen($str_tags)) if(strlen($str_tags))
$str_tags .= ','; $str_tags .= ',';
$profile = str_replace(',','%2c',$profile); $profile = str_replace(',','%2c',$profile);
@ -330,13 +335,36 @@ function photos_post(&$a) {
intval($item_id), intval($item_id),
intval(local_user()) 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']); goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
return; // NOTREACHED return; // NOTREACHED
} }
// default post action - upload a photo
if(! x($_FILES,'userfile')) if(! x($_FILES,'userfile'))
killme(); killme();

View file

@ -97,3 +97,8 @@ function update_1011() {
function update_1012() { function update_1012() {
q("ALTER TABLE `item` ADD `inform` MEDIUMTEXT NOT NULL AFTER `tag` "); q("ALTER TABLE `item` ADD `inform` MEDIUMTEXT NOT NULL AFTER `tag` ");
} }
function update_1013() {
q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL
AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`");
}