]> git.mxchange.org Git - friendica.git/blob - mod/network.php
more live update
[friendica.git] / mod / network.php
1 <?php
2
3
4 function network_init(&$a) {
5
6 }
7
8
9 function network_content(&$a, $update = false) {
10
11         if(! local_user())
12                 return;
13
14         require_once("include/bbcode.php");
15
16         $contact_id = $a->cid;
17
18
19         if(! $update) {
20
21
22                 $tpl = file_get_contents('view/jot-header.tpl');
23         
24                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
25
26                 require_once('view/acl_selectors.php');
27
28                 $tpl = file_get_contents("view/jot.tpl");
29
30                 $o .= replace_macros($tpl,array(
31                         '$return_path' => $a->cmd,
32                         '$baseurl' => $a->get_baseurl(),
33                         '$visitor' => 'block',
34                         '$lockstate' => 'unlock',
35                         '$acl' => populate_acl(),
36                         '$profile_uid' => $_SESSION['uid']
37                 ));
38
39
40                 $o .= '<div id="live-network"></div>' . "\r\n";
41         }
42
43         $r = q("UPDATE `item` SET `unseen` = 0 
44                 WHERE `unseen` = 1 AND `uid` = %d",
45                 intval($_SESSION['uid'])
46         );
47
48
49
50         $sql_extra = ''; 
51
52
53         $r = q("SELECT COUNT(*) AS `total`
54                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
55                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
56                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
57                 $sql_extra ",
58                 intval($_SESSION['uid'])
59         );
60
61         if(count($r))
62                 $a->set_pager_total($r[0]['total']);
63
64         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
65                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, 
66                 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
67                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
68                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
69                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
70                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
71                 $sql_extra
72                 ORDER BY `parent` DESC, `created` ASC LIMIT %d ,%d ",
73                 intval($_SESSION['uid']),
74                 intval($a->pager['start']),
75                 intval($a->pager['itemspage'])
76         );
77
78
79         $cmnt_tpl = file_get_contents('view/comment_item.tpl');
80
81         $tpl = file_get_contents('view/wall_item.tpl');
82         $wallwall = file_get_contents('view/wallwall_item.tpl');
83
84         if(count($r)) {
85                 foreach($r as $item) {
86
87                         $comment = '';
88                         $template = $tpl;
89                         $commentww = '';
90
91                         $profile_url = $item['url'];
92                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
93
94
95                         // Top-level wall post not written by the wall owner (wall-to-wall)
96                         // First figure out who owns it. 
97
98                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
99                                 
100                                 if($item['type'] == 'wall') {
101                                         // I do. Put me on the left of the wall-to-wall notice.
102                                         $owner_url = $a->contact['url'];
103                                         $owner_photo = $a->contact['thumb'];
104                                         $owner_name = $a->contact['name'];
105                                         $template = $wallwall;
106                                         $commentww = 'ww';      
107                                 }
108                                 if($item['type'] == 'remote' && ($item['owner-link'] != $item['author-link'])) {
109                                         // Could be anybody. 
110                                         $owner_url = $item['owner-link'];
111                                         $owner_photo = $item['owner-avatar'];
112                                         $owner_name = $item['owner-name'];
113                                         $template = $wallwall;
114                                         $commentww = 'ww';
115                                         // If it is our contact, use a friendly redirect link
116                                         if($item['owner-link'] == $item['url'])
117                                                 $owner_url = $redirect_url;
118
119                                 }
120                         }
121
122                         if($item['last-child']) {
123                                 $comment = replace_macros($cmnt_tpl,array(
124                                         '$return_path' => $a->cmd,
125                                         '$id' => $item['item_id'],
126                                         '$parent' => $item['parent'],
127                                         '$profile_uid' =>  $_SESSION['uid'],
128                                         '$ww' => $commentww
129                                 ));
130                         }
131
132         
133                         if(($item['contact-uid'] == $_SESSION['uid']) && (strlen($item['dfrn-id'])) && (! $item['self'] ))
134                                 $profile_url = $redirect_url;
135
136                         $photo = $item['photo'];
137                         $thumb = $item['thumb'];
138
139                         // Post was remotely authored.
140
141                         $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
142                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $thumb);
143
144                         $profile_link = $profile_url;
145
146                         // Can we use our special contact URL for this author? 
147
148                         if(strlen($item['author-link'])) {
149                                 if($item['author-link'] == $item['url'])
150                                         $profile_link = $redirect_url;
151                                 else
152                                         $profile_link = $item['author-link'];
153                         }
154
155                         // Build the HTML
156
157                         $o .= replace_macros($template,array(
158                                 '$id' => $item['item_id'],
159                                 '$profile_url' => $profile_link,
160                                 '$name' => $profile_name,
161                                 '$thumb' => $profile_avatar,
162                                 '$body' => bbcode($item['body']),
163                                 '$ago' => relative_date($item['created']),
164                                 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
165                                 '$owner_url' => $owner_url,
166                                 '$owner_photo' => $owner_photo,
167                                 '$owner_name' => $owner_name,
168                                 '$comment' => $comment
169                         ));
170                 }
171         }
172
173         if(! $update)
174                 $o .= paginate($a);
175
176         return $o;
177 }