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