]> git.mxchange.org Git - friendica.git/blob - mod/network.php
cdd8a4976be41ac864d8f9fbd846c12306469e17
[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 = false) {
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                         // pull out the group here because the updater might have different args
23                 if($a->argc > 1)
24                         $group = intval($a->argv[1]);
25
26                 $_SESSION['return_url'] = $a->cmd;
27
28                 $tpl = file_get_contents('view/jot-header.tpl');
29         
30                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
31
32                 require_once('view/acl_selectors.php');
33
34                 $tpl = file_get_contents("view/jot.tpl");
35
36                 $o .= replace_macros($tpl,array(
37                         '$return_path' => $a->cmd,
38                         '$baseurl' => $a->get_baseurl(),
39                         '$defloc' => $a->user['default-location'],
40                         '$visitor' => 'block',
41                         '$lockstate' => 'unlock',
42                         '$acl' => populate_acl($a->user),
43                         '$profile_uid' => $_SESSION['uid']
44                 ));
45
46
47                 // The special div is needed for liveUpdate to kick in for this page.
48                 // We only launch liveUpdate if you are on the front page, you aren't
49                 // filtering by group and also you aren't writing a comment (the last
50                 // criteria is discovered in javascript).
51
52                 if($a->pager['start'] == 0 && $a->argc == 1)
53                         $o .= '<div id="live-network"></div>' . "\r\n";
54         }
55
56         // We aren't going to try and figure out at the item, group, and page level 
57         // which items you've seen and which you haven't. You're looking at some
58         // subset of items, so just mark everything seen. 
59         
60         $r = q("UPDATE `item` SET `unseen` = 0 
61                 WHERE `unseen` = 1 AND `uid` = %d",
62                 intval($_SESSION['uid'])
63         );
64
65         // We don't have to deal with ACL's on this page. You're looking at everything
66         // that belongs to you, hence you can see all of it. We will filter by group if
67         // desired. 
68
69         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `type` IN ('wall', 'photo', 'remote' )) ";
70
71         if($group) {
72                 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
73                         intval($group),
74                         intval($_SESSION['uid'])
75                 );
76                 if(! count($r)) {
77                         notice( t('No such group') . EOL );
78                         goaway($a->get_baseurl() . '/network');
79                         return; // NOTREACHED
80                 }
81
82                 $contacts = expand_groups(array($group));
83                 $contact_str = implode(',',$contacts);
84                 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `type` IN ('wall', 'photo', 'remote') AND `contact-id` IN ( $contact_str )) ";
85                 $o = '<h4>' . t('Group: ') . $r[0]['name'] . '</h4>' . $o;
86
87         }
88
89         $r = q("SELECT COUNT(*) AS `total`
90                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
91                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
92                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
93                 $sql_extra ",
94                 intval($_SESSION['uid'])
95         );
96
97         if(count($r))
98                 $a->set_pager_total($r[0]['total']);
99
100         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
101                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, 
102                 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
103                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
104                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
105                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
106                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
107                 $sql_extra
108                 ORDER BY `parent` DESC, `created` ASC LIMIT %d ,%d ",
109                 intval($_SESSION['uid']),
110                 intval($a->pager['start']),
111                 intval($a->pager['itemspage'])
112         );
113
114
115         $cmnt_tpl = file_get_contents('view/comment_item.tpl');
116
117         $tpl = file_get_contents('view/wall_item.tpl');
118         $wallwall = file_get_contents('view/wallwall_item.tpl');
119
120         if(count($r)) {
121                 foreach($r as $item) {
122
123                         $comment = '';
124                         $template = $tpl;
125                         $commentww = '';
126
127                         $profile_url = $item['url'];
128                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
129
130
131                         // Top-level wall post not written by the wall owner (wall-to-wall)
132                         // First figure out who owns it. 
133
134                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
135                                 
136                                 if($item['type'] == 'wall') {
137                                         // I do. Put me on the left of the wall-to-wall notice.
138                                         $owner_url = $a->contact['url'];
139                                         $owner_photo = $a->contact['thumb'];
140                                         $owner_name = $a->contact['name'];
141                                         $template = $wallwall;
142                                         $commentww = 'ww';      
143                                 }
144                                 if($item['type'] == 'remote' && ($item['owner-link'] != $item['author-link'])) {
145                                         // Could be anybody. 
146                                         $owner_url = $item['owner-link'];
147                                         $owner_photo = $item['owner-avatar'];
148                                         $owner_name = $item['owner-name'];
149                                         $template = $wallwall;
150                                         $commentww = 'ww';
151                                         // If it is our contact, use a friendly redirect link
152                                         if(($item['owner-link'] == $item['url']) && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH))
153                                                 $owner_url = $redirect_url;
154                                                 $owner_url = $redirect_url;
155
156                                 }
157                         }
158
159                         if($update)
160                                 $return_url = $_SESSION['return_url'];
161                         else
162                                 $return_url = $_SESSION['return_url'] = $a->cmd;
163
164
165                         if($item['last-child']) {
166                                 $comment = replace_macros($cmnt_tpl,array(
167                                         '$return_path' => $_SESSION['return_url'],
168                                         '$type' => 'net-comment',
169                                         '$id' => $item['item_id'],
170                                         '$parent' => $item['parent'],
171                                         '$profile_uid' =>  $_SESSION['uid'],
172                                         '$mylink' => $a->contact['url'],
173                                         '$mytitle' => t('Me'),
174                                         '$myphoto' => $a->contact['thumb'],
175                                         '$ww' => $commentww
176                                 ));
177                         }
178
179
180                         $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
181
182
183         
184                         if(($item['contact-uid'] == $_SESSION['uid']) && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH) && (! $item['self'] ))
185                                 $profile_url = $redirect_url;
186
187                         $photo = $item['photo'];
188                         $thumb = $item['thumb'];
189
190                         // Post was remotely authored.
191
192                         $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
193                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $thumb);
194
195                         $profile_link = $profile_url;
196
197                         // Can we use our special contact URL for this author? 
198
199                         if(strlen($item['author-link'])) {
200                                 if($item['author-link'] == $item['url'])
201                                         $profile_link = $redirect_url;
202                                 else
203                                         $profile_link = $item['author-link'];
204                         }
205
206                         // Build the HTML
207
208                         $o .= replace_macros($template,array(
209                                 '$id' => $item['item_id'],
210                                 '$profile_url' => $profile_link,
211                                 '$name' => $profile_name,
212                                 '$thumb' => $profile_avatar,
213                                 '$title' => $item['title'],
214                                 '$body' => bbcode($item['body']),
215                                 '$ago' => relative_date($item['created']),
216                                 '$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
217                                 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
218                                 '$owner_url' => $owner_url,
219                                 '$owner_photo' => $owner_photo,
220                                 '$owner_name' => $owner_name,
221                                 '$drop' => $drop,
222                                 '$comment' => $comment
223                         ));
224                 }
225         }
226
227         if(! $update)
228                 $o .= paginate($a);
229
230         return $o;
231 }