]> git.mxchange.org Git - friendica.git/blob - mod/network.php
"display list of status items" moved to include/conversation.php,
[friendica.git] / mod / network.php
1 <?php
2
3
4 function network_init(&$a) {
5         if(! local_user()) {
6                 notice( t('Permission denied.') . EOL);
7                 return;
8         }
9   
10   
11         require_once('include/group.php');
12         if(! x($a->page,'aside'))
13                 $a->page['aside'] = '';
14
15         $a->page['aside'] .= '<div id="network-new-link">';
16
17         if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new'))
18                 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '">' . t('Normal View') . '</a>';
19         else 
20                 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . '">' . t('New Item View') . '</a>';
21
22         $a->page['aside'] .= '</div>';
23
24         $a->page['aside'] .= group_side('network','network');
25 }
26
27
28 function network_content(&$a, $update = 0) {
29
30         if(! local_user())
31         return login(false);
32
33         $o = '';
34
35         $contact_id = $a->cid;
36
37         $group = 0;
38
39         $nouveau = false;
40         require_once('include/acl_selectors.php');
41
42         if(($a->argc > 2) && $a->argv[2] === 'new')
43                 $nouveau = true;
44
45         if($a->argc > 1) {
46                 if($a->argv[1] === 'new')
47                         $nouveau = true;
48                 else {
49                         $group = intval($a->argv[1]);
50                         $group_acl = array('allow_gid' => '<' . $group . '>');
51                 }
52         }
53
54         if(! $update) {
55                 if(group) {
56                         if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
57                                 $plural_form = sprintf( tt('%d member', '%d members', $t), $t);
58                                 notice( sprintf( t('Warning: This group contains %s from an insecure network.'), $plural_form ) . EOL);
59                                 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
60                         }
61                 }
62
63                 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
64
65                 $_SESSION['return_url'] = $a->cmd;
66
67                 $geotag = (($a->user['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
68
69                 $tpl = load_view_file('view/jot-header.tpl');
70         
71                 $a->page['htmlhead'] .= replace_macros($tpl, array(
72                         '$baseurl' => $a->get_baseurl(),
73                         '$geotag' => $geotag,
74                         '$nickname' => $a->user['nickname'],
75                         '$linkurl' => t('Please enter a link URL:'),
76                         '$utubeurl' => t('Please enter a YouTube link:'),
77                         '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
78                         '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
79                         '$whereareu' => t('Where are you right now?'),
80                         '$title' => t('Enter a title for this item') 
81                 ));
82
83
84                 $tpl = load_view_file("view/jot.tpl");
85                 
86                 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'])))))
87                                 $lockstate = 'lock';
88                         else
89                                 $lockstate = 'unlock';
90
91                 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
92
93                 $jotplugins = '';
94                 $jotnets = '';
95                 call_hooks('jot_tool', $jotplugins);
96                 call_hooks('jot_networks', $jotnets);
97
98                 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
99
100                 $o .= replace_macros($tpl,array(
101                         '$return_path' => $a->cmd,
102                         '$action' => 'item',
103                         '$share' => t('Share'),
104                         '$upload' => t('Upload photo'),
105                         '$weblink' => t('Insert web link'),
106                         '$youtube' => t('Insert YouTube video'),
107                         '$video' => t('Insert Vorbis [.ogg] video'),
108                         '$audio' => t('Insert Vorbis [.ogg] audio'),
109                         '$setloc' => t('Set your location'),
110                         '$noloc' => t('Clear browser location'),
111                         '$title' => t('Set title'),
112                         '$wait' => t('Please wait'),
113                         '$permset' => t('Permission settings'),
114                         '$content' => '',
115                         '$post_id' => '',
116                         '$baseurl' => $a->get_baseurl(),
117                         '$defloc' => $a->user['default-location'],
118                         '$visitor' => 'block',
119                         '$emailcc' => t('CC: email addresses'),
120                         '$jotnets' => $jotnets,
121                         '$emtitle' => t('Example: bob@example.com, mary@example.com'),
122                         '$lockstate' => $lockstate,
123                         '$acl' => populate_acl((($group) ? $group_acl : $a->user), $celeb),
124                         '$bang' => (($group) ? '!' : ''),
125                         '$profile_uid' => local_user()
126                 ));
127
128
129                 // The special div is needed for liveUpdate to kick in for this page.
130                 // We only launch liveUpdate if you are on the front page, you aren't
131                 // filtering by group and also you aren't writing a comment (the last
132                 // criteria is discovered in javascript).
133
134                         $o .= '<div id="live-network"></div>' . "\r\n";
135                         $o .= "<script> var profile_uid = " . $_SESSION['uid'] 
136                                 . "; var netargs = '" . substr($a->cmd,8) 
137                                 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
138
139         }
140
141         // We aren't going to try and figure out at the item, group, and page level 
142         // which items you've seen and which you haven't. You're looking at some
143         // subset of items, so just mark everything seen. 
144         
145         $r = q("UPDATE `item` SET `unseen` = 0 
146                 WHERE `unseen` = 1 AND `uid` = %d",
147                 intval($_SESSION['uid'])
148         );
149
150         // We don't have to deal with ACL's on this page. You're looking at everything
151         // that belongs to you, hence you can see all of it. We will filter by group if
152         // desired. 
153
154         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
155
156         if($group) {
157                 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
158                         intval($group),
159                         intval($_SESSION['uid'])
160                 );
161                 if(! count($r)) {
162                         if($update)
163                                 killme();
164                         notice( t('No such group') . EOL );
165                         goaway($a->get_baseurl() . '/network');
166                         return; // NOTREACHED
167                 }
168
169                 $contacts = expand_groups(array($group));
170                 if((is_array($contacts)) && count($contacts)) {
171                         $contact_str = implode(',',$contacts);
172                 }
173                 else {
174                                 $contact_str = ' 0 ';
175                                 notice( t('Group is empty'));
176                 }
177
178                 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
179                 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
180         }
181
182         if((! $group) && (! $update))
183                 $o .= get_birthdays();
184
185
186         $r = q("SELECT COUNT(*) AS `total`
187                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
188                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
189                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
190                 $sql_extra ",
191                 intval($_SESSION['uid'])
192         );
193
194         if(count($r)) {
195                 $a->set_pager_total($r[0]['total']);
196                 $a->set_pager_itemspage(40);
197         }
198
199
200         if($nouveau) {
201
202                 // "New Item View" - show all items unthreaded in reverse created date order
203
204                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
205                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
206                         `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
207                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
208                         FROM `item`, `contact`
209                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
210                         AND `contact`.`id` = `item`.`contact-id`
211                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
212                         $sql_extra
213                         ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
214                         intval($_SESSION['uid']),
215                         intval($a->pager['start']),
216                         intval($a->pager['itemspage'])
217                 );
218                 
219         }
220         else {
221
222                 // Normal conversation view
223                 // First fetch a known number of parent items
224
225                 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
226                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
227                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
228                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
229                         AND `item`.`parent` = `item`.`id`
230                         $sql_extra
231                         ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
232                         intval(local_user()),
233                         intval($a->pager['start']),
234                         intval($a->pager['itemspage'])
235                 );
236
237
238                 // Then fetch all the children of the parents that are on this page
239
240                 $parents_arr = array();
241                 $parents_str = '';
242
243                 if(count($r)) {
244                         foreach($r as $rr)
245                                 $parents_arr[] = $rr['item_id'];
246                         $parents_str = implode(', ', $parents_arr);
247
248                         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
249                                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
250                                 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
251                                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
252                                 FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
253                                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
254                                 AND `contact`.`id` = `item`.`contact-id`
255                                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
256                                 AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
257                                 $sql_extra
258                                 ORDER BY `parentitem`.`created`  DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
259                                 intval(local_user()),
260                                 dbesc($parents_str)
261                         );
262                 }
263         }
264
265         $mode = (($nouveau) ? 'network-new' : 'network');
266
267         require_once('include/conversation.php');
268
269         $o .= conversation($a,$r,$mode,$update);
270
271         if(! $update) {
272
273                 $o .= paginate($a);
274                 $o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
275         }
276
277         return $o;
278 }