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