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