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