]> git.mxchange.org Git - friendica.git/blob - mod/network.php
our implementation of "aspects" functionally complete
[friendica.git] / mod / network.php
1 <?php
2
3
4 function network_init(&$a) {
5         require_once('include/group.php');
6         $a->page['aside'] .= group_side('network','network');
7 }
8
9
10 function network_content(&$a, $update = false) {
11
12         if(! local_user())
13                 return;
14
15         require_once("include/bbcode.php");
16
17         $contact_id = $a->cid;
18
19         $group = 0;
20
21         if(! $update) {
22                         // pull out the group here because the updater might have different args
23                 if($a->argc > 1) {
24                         $group = intval($a->argv[1]);
25                         $group_acl = array('allow_gid' => '<' . $group . '>');
26                 }
27                 $_SESSION['return_url'] = $a->cmd;
28
29                 $tpl = file_get_contents('view/jot-header.tpl');
30         
31                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
32
33                 require_once('view/acl_selectors.php');
34
35                 $tpl = file_get_contents("view/jot.tpl");
36                 
37                 if(($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid'])))))
38                                 $lockstate = 'lock';
39                         else
40                                 $lockstate = 'unlock';
41
42                 $o .= replace_macros($tpl,array(
43                         '$return_path' => $a->cmd,
44                         '$baseurl' => $a->get_baseurl(),
45                         '$defloc' => $a->user['default-location'],
46                         '$visitor' => 'block',
47                         '$lockstate' => $lockstate,
48                         '$acl' => populate_acl(($group) ? $group_acl : $a->user),
49                         '$bang' => (($group) ? '!' : ''),
50                         '$profile_uid' => $_SESSION['uid']
51                 ));
52
53
54                 // The special div is needed for liveUpdate to kick in for this page.
55                 // We only launch liveUpdate if you are on the front page, you aren't
56                 // filtering by group and also you aren't writing a comment (the last
57                 // criteria is discovered in javascript).
58
59                 if($a->pager['start'] == 0 && $a->argc == 1)
60                         $o .= '<div id="live-network"></div>' . "\r\n";
61         }
62
63         // We aren't going to try and figure out at the item, group, and page level 
64         // which items you've seen and which you haven't. You're looking at some
65         // subset of items, so just mark everything seen. 
66         
67         $r = q("UPDATE `item` SET `unseen` = 0 
68                 WHERE `unseen` = 1 AND `uid` = %d",
69                 intval($_SESSION['uid'])
70         );
71
72         // We don't have to deal with ACL's on this page. You're looking at everything
73         // that belongs to you, hence you can see all of it. We will filter by group if
74         // desired. 
75
76         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
77
78         if($group) {
79                 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
80                         intval($group),
81                         intval($_SESSION['uid'])
82                 );
83                 if(! count($r)) {
84                         notice( t('No such group') . EOL );
85                         goaway($a->get_baseurl() . '/network');
86                         return; // NOTREACHED
87                 }
88
89                 $contacts = expand_groups(array($group));
90                 $contact_str = implode(',',$contacts);
91                 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
92                 $o = '<h4>' . t('Group: ') . $r[0]['name'] . '</h4>' . $o;
93
94         }
95
96         $r = q("SELECT COUNT(*) AS `total`
97                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
98                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
99                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
100                 $sql_extra ",
101                 intval($_SESSION['uid'])
102         );
103
104         if(count($r))
105                 $a->set_pager_total($r[0]['total']);
106
107         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
108                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
109                 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
110                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
111                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
112                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
113                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
114                 $sql_extra
115                 ORDER BY `parent` DESC, `gravity` ASC, `created` ASC LIMIT %d ,%d ",
116                 intval($_SESSION['uid']),
117                 intval($a->pager['start']),
118                 intval($a->pager['itemspage'])
119         );
120
121
122         $cmnt_tpl = file_get_contents('view/comment_item.tpl');
123         $like_tpl = file_get_contents('view/like.tpl');
124         $tpl = file_get_contents('view/wall_item.tpl');
125         $wallwall = file_get_contents('view/wallwall_item.tpl');
126
127         $alike = array();
128         $dlike = array();
129         
130         if(count($r)) {
131                 foreach($r as $item) {
132
133                         if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) {
134                                 $url = $item['url'];
135                                 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) 
136                                         $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
137                                 if(! is_array($alike[$item['parent'] . '-l']))
138                                         $alike[$item['parent'] . '-l'] = array();
139                                 $alike[$item['parent']] ++;
140                                 $alike[$item['parent'] . '-l'][] = '<a href="'. $url . '">' . $item['name'] . '</a>';
141                         }
142                         if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) {
143                                 $url = $item['url'];
144                                 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) 
145                                         $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
146                                 if(! is_array($dlike[$item['parent'] . '-l']))
147                                         $dlike[$item['parent'] . '-l'] = array();
148                                 $dlike[$item['parent']] ++;
149                                 $dlike[$item['parent'] . '-l'][] = '<a href="'. $url . '">' . $item['name'] . '</a>';
150                         }
151                 }
152
153                 foreach($r as $item) {
154
155                         $comment = '';
156                         $template = $tpl;
157                         $commentww = '';
158
159                         $profile_url = $item['url'];
160                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
161
162                         if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) 
163                                 continue;
164
165                         // Top-level wall post not written by the wall owner (wall-to-wall)
166                         // First figure out who owns it. 
167
168                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
169
170                                 if($item['type'] == 'wall') {
171                                         // I do. Put me on the left of the wall-to-wall notice.
172                                         $owner_url = $a->contact['url'];
173                                         $owner_photo = $a->contact['thumb'];
174                                         $owner_name = $a->contact['name'];
175                                         $template = $wallwall;
176                                         $commentww = 'ww';      
177                                 }
178                                 if($item['type'] == 'remote' && ($item['owner-link'] != $item['author-link'])) {
179                                         // Could be anybody. 
180                                         $owner_url = $item['owner-link'];
181                                         $owner_photo = $item['owner-avatar'];
182                                         $owner_name = $item['owner-name'];
183                                         $template = $wallwall;
184                                         $commentww = 'ww';
185                                         // If it is our contact, use a friendly redirect link
186                                         if(($item['owner-link'] == $item['url']) && ($item['rel'] == REL_VIP || $item['rel'] == REL_BUD))
187                                                 $owner_url = $redirect_url;
188
189                                 }
190                         }
191
192                         if($update)
193                                 $return_url = $_SESSION['return_url'];
194                         else
195                                 $return_url = $_SESSION['return_url'] = $a->cmd;
196
197                         $likebuttons = '';
198                         if($item['id'] == $item['parent']) {
199                                 $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
200                         }
201
202                         if($item['last-child']) {
203                                 $comment = replace_macros($cmnt_tpl,array(
204                                         '$return_path' => $_SESSION['return_url'],
205                                         '$type' => 'net-comment',
206                                         '$id' => $item['item_id'],
207                                         '$parent' => $item['parent'],
208                                         '$profile_uid' =>  $_SESSION['uid'],
209                                         '$mylink' => $a->contact['url'],
210                                         '$mytitle' => t('Me'),
211                                         '$myphoto' => $a->contact['thumb'],
212                                         '$ww' => $commentww
213                                 ));
214                         }
215
216
217                         $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
218
219
220         
221                         if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'] ))
222                                 $profile_url = $redirect_url;
223
224                         $photo = $item['photo'];
225                         $thumb = $item['thumb'];
226
227                         // Post was remotely authored.
228
229                         $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
230                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $thumb);
231
232                         $profile_link = $profile_url;
233
234                         // Can we use our special contact URL for this author? 
235
236                         if(strlen($item['author-link'])) {
237                                 if($item['author-link'] == $item['url'])
238                                         $profile_link = $redirect_url;
239                                 else
240                                         $profile_link = $item['author-link'];
241                         }
242
243
244                         $like    = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
245                         $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
246
247
248                         // Build the HTML
249
250                         $o .= replace_macros($template,array(
251                                 '$id' => $item['item_id'],
252                                 '$profile_url' => $profile_link,
253                                 '$name' => $profile_name,
254                                 '$thumb' => $profile_avatar,
255                                 '$title' => $item['title'],
256                                 '$body' => bbcode($item['body']),
257                                 '$ago' => relative_date($item['created']),
258                                 '$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
259                                 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
260                                 '$owner_url' => $owner_url,
261                                 '$owner_photo' => $owner_photo,
262                                 '$owner_name' => $owner_name,
263                                 '$drop' => $drop,
264                                 '$vote' => $likebuttons,
265                                 '$like' => $like,
266                                 '$dislike' => $dislike,
267                                 '$comment' => $comment
268                         ));
269                 }
270         }
271
272         if(! $update)
273                 $o .= paginate($a);
274
275         return $o;
276 }