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