]> git.mxchange.org Git - friendica.git/blob - mod/tagger.php
tagging
[friendica.git] / mod / tagger.php
1 <?php
2
3 require_once('include/security.php');
4 require_once('include/bbcode.php');
5 require_once('include/items.php');
6
7
8 function tagger_content(&$a) {
9
10         if(! local_user() && ! remote_user()) {
11                 return;
12         }
13
14         $term= notags(trim($_GET['term']));
15
16         if(! $term)
17                 return;
18
19         $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
20
21         logger('tagger: tag ' . $term . ' item ' . $item_id);
22
23
24         $r = q("SELECT * FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s') LIMIT 1",
25                 dbesc($item_id),
26                 dbesc($item_id)
27         );
28
29         if(! $item_id || (! count($r))) {
30                 logger('tagger: no item ' . $item_id);
31                 return;
32         }
33
34         $item = $r[0];
35
36         $owner_uid = $item['uid'];
37
38         $r = q("select `nickname` from user where uid = %d limit 1",
39                 intval($owner_uid)
40         );
41         if(count($r))
42                 $owner_nick = $r[0]['nickname'];
43
44
45 //      if(local_user() != $owner_uid)
46 //              return;
47
48         if(remote_user()) {
49                 $r = q("select * from contact where id = %d AND `uid` = %d limit 1",
50                         intval(remote_user()),
51                         intval($item['uid'])
52                 );
53         }
54         else {
55                 $r = q("select * from contact where self = 1 and uid = %d limit 1",
56                         intval(local_user())
57                 );
58         }
59         if(count($r))
60                         $contact = $r[0];
61         else {
62                 logger('tagger: no contact_id');
63                 return;
64         }
65
66         $uri = item_new_uri($a->get_hostname(),$owner_uid);
67
68         $post_type = (($item['resource-id']) ? t('photo') : t('status'));
69         $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); 
70
71         $link = xmlify('<link rel="alternate" type="text/html" href="' 
72                 . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
73
74         $body = $item['body'];
75
76         $target = <<< EOT
77         <target>
78                 <type>$targettype</type>
79                 <local>1</local>
80                 <id>{$item['uri']}</id>
81                 <link>$link</link>
82                 <title></title>
83                 <content>$body</content>
84         </target>
85 EOT;
86
87         $tagid = $a->get_baseurl() . '/search?search=' . $term;
88         $objtype = ACTIVITY_OBJ_TAGTERM;
89
90         $obj = <<< EOT
91         <object>
92                 <type>$objtype</type>
93                 <local>1</local>
94                 <id>$tagid</id>
95                 <link>$tagid</link>
96                 <title>$term</title>
97                 <content>$term</content>
98         </object>
99 EOT;
100
101         $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
102
103         if(! isset($bodyverb))
104                         return; 
105
106         $termlink = '#[url=' . $a->get_baseurl() . '/search?search=' . urlencode($term) . ']'. $term . '[/url]';
107
108         $arr = array();
109
110         $arr['uri'] = $uri;
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'];
124         
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 );
129
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'];
139         $arr['visible'] = 1;
140         $arr['unseen'] = 1;
141         $arr['last-child'] = 1;
142         $arr['origin'] = 1;
143
144         $post_id = item_store($arr);    
145
146         q("UPDATE `item` set plink = '%s' where id = %d limit 1",
147                 dbesc($a->get_baseurl() . '/display/' . $owner_nick . '/' . $post_id),
148                 intval($post_id)
149         );
150                 
151
152         if(! $item['visible']) {
153                 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
154                         intval($item['id']),
155                         intval($owner_uid)
156                 );
157         }                       
158
159
160
161         $arr['id'] = $post_id;
162
163         call_hooks('post_local_end', $arr);
164
165         proc_run('php',"include/notifier.php","like","$post_id");
166
167         return; // NOTREACHED
168
169
170 }