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