3 require_once('include/security.php');
4 require_once('include/bbcode.php');
5 require_once('include/items.php');
8 function tagger_content(&$a) {
10 if(! local_user() && ! remote_user()) {
14 $term= notags(trim($_GET['term']));
19 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
21 logger('tagger: tag ' . $term . ' item ' . $item_id);
24 $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
28 if(! $item_id || (! count($r))) {
29 logger('tagger: no item ' . $item_id);
35 $owner_uid = $item['uid'];
37 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
41 $owner_nick = $r[0]['nickname'];
42 $blocktags = $r[0]['blocktags'];
45 if(local_user() != $owner_uid)
49 $r = q("select * from contact where id = %d AND `uid` = %d limit 1",
50 intval(remote_user()),
55 $r = q("select * from contact where self = 1 and uid = %d limit 1",
62 logger('tagger: no contact_id');
66 $uri = item_new_uri($a->get_hostname(),$owner_uid);
68 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
69 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
71 $link = xmlify('<link rel="alternate" type="text/html" href="'
72 . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
74 $body = $item['body'];
78 <type>$targettype</type>
80 <id>{$item['uri']}</id>
83 <content>$body</content>
87 $tagid = $a->get_baseurl() . '/search?search=' . $term;
88 $objtype = ACTIVITY_OBJ_TAGTERM;
97 <content>$term</content>
101 $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
103 if(! isset($bodyverb))
106 $termlink = '#[url=' . $a->get_baseurl() . '/search?search=' . urlencode($term) . ']'. $term . '[/url]';
111 $arr['uid'] = $owner_uid;
112 $arr['contact-id'] = $contact['id'];
113 $arr['type'] = 'activity';
114 $arr['wall'] = $item['wall'];
115 $arr['gravity'] = GRAVITY_COMMENT;
116 $arr['parent'] = $item['id'];
117 $arr['parent-uri'] = $item['uri'];
118 $arr['owner-name'] = $item['author-name'];
119 $arr['owner-link'] = $item['author-link'];
120 $arr['owner-avatar'] = $item['author-avatar'];
121 $arr['author-name'] = $contact['name'];
122 $arr['author-link'] = $contact['url'];
123 $arr['author-avatar'] = $contact['thumb'];
125 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
126 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
127 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
128 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
130 $arr['verb'] = ACTIVITY_TAG;
131 $arr['target-type'] = $targettype;
132 $arr['target'] = $target;
133 $arr['object-type'] = $objtype;
134 $arr['object'] = $obj;
135 $arr['allow_cid'] = $item['allow_cid'];
136 $arr['allow_gid'] = $item['allow_gid'];
137 $arr['deny_cid'] = $item['deny_cid'];
138 $arr['deny_gid'] = $item['deny_gid'];
141 $arr['last-child'] = 1;
144 $post_id = item_store($arr);
146 q("UPDATE `item` set plink = '%s' where id = %d limit 1",
147 dbesc($a->get_baseurl() . '/display/' . $owner_nick . '/' . $post_id),
152 if(! $item['visible']) {
153 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
159 if((! $blocktags) && (! stristr($item['tag'], ']' . $term . '[' ))) {
160 q("update item set tag = '%s' where id = %d limit 1",
161 dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?search=' . $term . ']'. $term . '[/url]'),
166 // if the original post is on this site, update it.
168 $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
172 $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
175 if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
176 q("update item set tag = '%s' where id = %d limit 1",
177 dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?search=' . $term . ']'. $term . '[/url]'),
185 $arr['id'] = $post_id;
187 call_hooks('post_local_end', $arr);
189 proc_run('php',"include/notifier.php","tag","$post_id");
193 return; // NOTREACHED