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