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