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']));
16 $term = str_replace(array(',',' '),array('','_'),$term);
21 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
23 logger('tagger: tag ' . $term . ' item ' . $item_id);
26 $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
30 if(! $item_id || (! count($r))) {
31 logger('tagger: no item ' . $item_id);
37 $owner_uid = $item['uid'];
39 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
43 $owner_nick = $r[0]['nickname'];
44 $blocktags = $r[0]['blocktags'];
47 if(local_user() != $owner_uid)
51 $r = q("select * from contact where id = %d AND `uid` = %d limit 1",
52 intval(remote_user()),
57 $r = q("select * from contact where self = 1 and uid = %d limit 1",
64 logger('tagger: no contact_id');
68 $uri = item_new_uri($a->get_hostname(),$owner_uid);
69 $xterm = xmlify($term);
70 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
71 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
73 $link = xmlify('<link rel="alternate" type="text/html" href="'
74 . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
76 $body = xmlify($item['body']);
80 <type>$targettype</type>
82 <id>{$item['uri']}</id>
85 <content>$body</content>
89 $tagid = $a->get_baseurl() . '/search?tag=' . $term;
90 $objtype = ACTIVITY_OBJ_TAGTERM;
99 <content>$xterm</content>
103 $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
105 if(! isset($bodyverb))
108 $termlink = html_entity_decode('⌗') . '[url=' . $a->get_baseurl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
113 $arr['uid'] = $owner_uid;
114 $arr['contact-id'] = $contact['id'];
115 $arr['type'] = 'activity';
116 $arr['wall'] = $item['wall'];
117 $arr['gravity'] = GRAVITY_COMMENT;
118 $arr['parent'] = $item['id'];
119 $arr['parent-uri'] = $item['uri'];
120 $arr['owner-name'] = $item['author-name'];
121 $arr['owner-link'] = $item['author-link'];
122 $arr['owner-avatar'] = $item['author-avatar'];
123 $arr['author-name'] = $contact['name'];
124 $arr['author-link'] = $contact['url'];
125 $arr['author-avatar'] = $contact['thumb'];
127 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
128 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
129 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
130 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
132 $arr['verb'] = ACTIVITY_TAG;
133 $arr['target-type'] = $targettype;
134 $arr['target'] = $target;
135 $arr['object-type'] = $objtype;
136 $arr['object'] = $obj;
137 $arr['private'] = $item['private'];
138 $arr['allow_cid'] = $item['allow_cid'];
139 $arr['allow_gid'] = $item['allow_gid'];
140 $arr['deny_cid'] = $item['deny_cid'];
141 $arr['deny_gid'] = $item['deny_gid'];
144 $arr['last-child'] = 1;
147 $post_id = item_store($arr);
149 q("UPDATE `item` set plink = '%s' where id = %d limit 1",
150 dbesc($a->get_baseurl() . '/display/' . $owner_nick . '/' . $post_id),
155 if(! $item['visible']) {
156 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
162 if((! $blocktags) && (! stristr($item['tag'], ']' . $term . '[' ))) {
163 q("update item set tag = '%s' where id = %d limit 1",
164 dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
169 // if the original post is on this site, update it.
171 $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
175 $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
178 if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
179 q("update item set tag = '%s' where id = %d limit 1",
180 dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
188 $arr['id'] = $post_id;
190 call_hooks('post_local_end', $arr);
192 proc_run('php',"include/notifier.php","tag","$post_id");
196 return; // NOTREACHED