From 438473529c667f151aefcede1d7fa6b8b22f2d91 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 5 Apr 2011 17:41:02 -0700 Subject: atom categories and tag import --- include/items.php | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index a9ac85969..b17eadba2 100644 --- a/include/items.php +++ b/include/items.php @@ -456,7 +456,22 @@ function get_atom_elements($feed,$item) { if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) $res['verb'] = ACTIVITY_UNFOLLOW; - + + $cats = $item->get_categories(); + if($cats) { + $tag_arr = array(); + foreach($cats as $cat) { + $term = $cat->get_term(); + if(! $term) + $term = $cat->get_label(); + $scheme = $cat->get_scheme(); + if($scheme && $term && stristr($scheme,'X-DFRN:')) + $tag_arr[] = substr($scheme,7,1) . '[url=' . unxmlify(substr($scheme,9)) . ']' . unxmlify($term) . '[/url]'; + elseif($term) + $tag_arr[] = $term; + } + $res['tag'] = implode(',', $tag_arr); + } $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); @@ -614,6 +629,7 @@ function item_store($arr,$force_parent = false) { $arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : ''); $arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0 ); $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); + $arr['tag'] = ((x($arr,'tag')) ? notags(trim($arr['tag'])) : ''); if($arr['parent-uri'] === $arr['uri']) { $parent_id = 0; @@ -1503,6 +1519,13 @@ function atom_entry($item,$type,$author,$owner,$comment = false) { if(strlen($actarg)) $o .= $actarg; + $tags = item_getfeedtags($item); + if(count($tags)) { + foreach($tags as $t) { + $o .= '' . "\r\n"; + } + } + $mentioned = get_mentions($item); if($mentioned) $o .= $mentioned; @@ -1513,6 +1536,29 @@ function atom_entry($item,$type,$author,$owner,$comment = false) { return $o; } + +function item_getfeedtags($item) { + $ret = array(); + $matches = false; + $cnt = preg_match_all('|\#\[url\=(.+?)\](.+?)\[\/url\]|',$item['tag'],$matches); + if($cnt) { + for($x = 0; $x < count($matches); $x ++) { + if($matches[1][$x]) + $ret[] = array('#',$matches[1][$x], $matches[2][$x]); + } + } + $matches = false; + $cnt = preg_match_all('|\@\[url\=(.+?)\](.+?)\[\/url\]|',$item['tag'],$matches); + if($cnt) { + for($x = 0; $x < count($matches); $x ++) { + if($matches[1][$x]) + $ret[] = array('#',$matches[1][$x], $matches[2][$x]); + } + } + return $ret; +} + + function item_expire($uid,$days) { -- cgit v1.2.3