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