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