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)
50 $r = q("select * from contact where self = 1 and uid = %d limit 1",
56 logger('tagger: no contact_id');
60 $uri = item_new_uri($a->get_hostname(),$owner_uid);
61 $xterm = xmlify($term);
62 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
63 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
65 $link = xmlify('<link rel="alternate" type="text/html" href="'
66 . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
68 $body = xmlify($item['body']);
72 <type>$targettype</type>
74 <id>{$item['uri']}</id>
77 <content>$body</content>
81 $tagid = $a->get_baseurl() . '/search?tag=' . $term;
82 $objtype = ACTIVITY_OBJ_TAGTERM;
91 <content>$xterm</content>
95 $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
97 if(! isset($bodyverb))
100 $termlink = html_entity_decode('⌗') . '[url=' . $a->get_baseurl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
105 $arr['uid'] = $owner_uid;
106 $arr['contact-id'] = $contact['id'];
107 $arr['type'] = 'activity';
108 $arr['wall'] = $item['wall'];
109 $arr['gravity'] = GRAVITY_COMMENT;
110 $arr['parent'] = $item['id'];
111 $arr['parent-uri'] = $item['uri'];
112 $arr['owner-name'] = $item['author-name'];
113 $arr['owner-link'] = $item['author-link'];
114 $arr['owner-avatar'] = $item['author-avatar'];
115 $arr['author-name'] = $contact['name'];
116 $arr['author-link'] = $contact['url'];
117 $arr['author-avatar'] = $contact['thumb'];
119 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
120 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
121 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
122 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
124 $arr['verb'] = ACTIVITY_TAG;
125 $arr['target-type'] = $targettype;
126 $arr['target'] = $target;
127 $arr['object-type'] = $objtype;
128 $arr['object'] = $obj;
129 $arr['private'] = $item['private'];
130 $arr['allow_cid'] = $item['allow_cid'];
131 $arr['allow_gid'] = $item['allow_gid'];
132 $arr['deny_cid'] = $item['deny_cid'];
133 $arr['deny_gid'] = $item['deny_gid'];
136 $arr['last-child'] = 1;
139 $post_id = item_store($arr);
141 // q("UPDATE `item` set plink = '%s' where id = %d",
142 // dbesc($a->get_baseurl() . '/display/' . $owner_nick . '/' . $post_id),
147 if(! $item['visible']) {
148 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
154 $term_objtype = (($item['resource-id']) ? TERM_OBJ_PHOTO : TERM_OBJ_POST );
155 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
159 if((! $blocktags) && $t[0]['tcount']==0 ) {
160 /*q("update item set tag = '%s' where id = %d",
161 dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
165 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
170 dbesc($a->get_baseurl() . '/search?tag=' . $term),
175 // if the original post is on this site, update it.
177 $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
181 $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
184 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
188 if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
189 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
194 dbesc($a->get_baseurl() . '/search?tag=' . $term),
199 /*if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
200 q("update item set tag = '%s' where id = %d",
201 dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
209 $arr['id'] = $post_id;
211 call_hooks('post_local_end', $arr);
213 proc_run('php',"include/notifier.php","tag","$post_id");
217 return; // NOTREACHED