]> git.mxchange.org Git - friendica.git/blob - mod/display.php
639a30eb7d24aed29345d2e333a9d910065a6dbb
[friendica.git] / mod / display.php
1 <?php
2
3
4 function display_content(&$a) {
5
6         require_once('mod/profile.php');
7         profile_init($a);
8
9         $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
10
11         if(! $item_id) {
12                 $a->error = 404;
13                 notice( t('Item not found.') . EOL);
14                 return;
15         }
16
17         require_once("include/bbcode.php");
18         require_once('include/security.php');
19
20
21         $groups = array();
22
23         $tab = 'posts';
24
25
26         $contact = null;
27         $remote_contact = false;
28
29         if(remote_user()) {
30                 $contact_id = $_SESSION['visitor_id'];
31                 $groups = init_groups_visitor($contact_id);
32                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
33                         intval($contact_id),
34                         intval($a->profile['uid'])
35                 );
36                 if(count($r)) {
37                         $contact = $r[0];
38                         $remote_contact = true;
39                 }
40         }
41
42         if(! $remote_contact) {
43                 if(local_user()) {
44                         $contact_id = $_SESSION['cid'];
45                         $contact = $a->contact;
46                 }
47         }
48
49
50         $sql_extra = "
51                 AND `allow_cid` = '' 
52                 AND `allow_gid` = '' 
53                 AND `deny_cid`  = '' 
54                 AND `deny_gid`  = '' 
55         ";
56
57
58         // Profile owner - everything is visible
59
60         if(local_user() && (get_uid() == $a->profile['uid'])) {
61                 $sql_extra = '';                
62         }
63
64         // authenticated visitor - here lie dragons
65         // If $remotecontact is true, we know that not only is this a remotely authenticated
66         // person, but that it is *our* contact, which is important in multi-user mode.
67
68         elseif($remote_contact) {
69                 $gs = '<<>>'; // should be impossible to match
70                 if(count($groups)) {
71                         foreach($groups as $g)
72                                 $gs .= '|<' . intval($g) . '>';
73                 } 
74                 $sql_extra = sprintf(
75                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
76                           AND ( `deny_cid`  = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
77                           AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
78                           AND ( `deny_gid`  = '' OR  NOT `deny_gid` REGEXP '%s') ",
79
80                         intval($_SESSION['visitor_id']),
81                         intval($_SESSION['visitor_id']),
82                         dbesc($gs),
83                         dbesc($gs)
84                 );
85         }
86
87         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
88                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, 
89                 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
90                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
91                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
92                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
93                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
94                 AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' ))
95                 $sql_extra
96                 ORDER BY `parent` DESC, `id` ASC ",
97                 intval($a->profile['uid']),
98                 dbesc($item_id),
99                 dbesc($item_id)
100         );
101
102
103         $cmnt_tpl = file_get_contents('view/comment_item.tpl');
104
105         $tpl = file_get_contents('view/wall_item.tpl');
106         $wallwall = file_get_contents('view/wallwall_item.tpl');
107
108         $return_url = $_SESSION['return_url'] = $a->cmd;
109
110         if(count($r)) {
111                 foreach($r as $item) {
112                         $comment = '';
113                         $template = $tpl;
114                         
115                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
116                         
117
118                         if(can_write_wall($a,$a->profile['uid'])) {
119                                 if($item['last-child']) {
120                                         $comment = replace_macros($cmnt_tpl,array(
121                                                 '$return_path' => $_SESSION['return_url'],
122                                                 '$type' => 'wall-comment',
123                                                 '$id' => $item['item_id'],
124                                                 '$parent' => $item['parent'],
125                                                 '$profile_uid' =>  $a->profile['uid'],
126                                                 '$mylink' => $contact['url'],
127                                                 '$mytitle' => t('Me'),
128                                                 '$myphoto' => $contact['thumb'],
129                                                 '$ww' => ''
130                                         ));
131                                 }
132                         }
133
134
135                         $profile_url = $item['url'];
136
137
138                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
139
140
141                         // Top-level wall post not written by the wall owner (wall-to-wall)
142                         // First figure out who owns it. 
143
144                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
145                                 
146                                 if($item['type'] == 'wall') {
147                                         // I do. Put me on the left of the wall-to-wall notice.
148                                         $owner_url = $a->contact['url'];
149                                         $owner_photo = $a->contact['thumb'];
150                                         $owner_name = $a->contact['name'];
151                                         $template = $wallwall;
152                                         $commentww = 'ww';      
153                                 }
154                                 if($item['type'] == 'remote' && ($item['owner-link'] != $item['author-link'])) {
155                                         // Could be anybody. 
156                                         $owner_url = $item['owner-link'];
157                                         $owner_photo = $item['owner-avatar'];
158                                         $owner_name = $item['owner-name'];
159                                         $template = $wallwall;
160                                         $commentww = 'ww';
161                                         // If it is our contact, use a friendly redirect link
162                                         if(($item['owner-link'] == $item['url']) && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH))
163                                                 $owner_url = $redirect_url;
164                                                 $owner_url = $redirect_url;
165
166                                 }
167                         }
168
169                         $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
170                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
171                         $profile_link = $profile_url;
172
173                         $drop = '';
174
175                         if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == get_uid()))
176                                 $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
177
178
179                         $o .= replace_macros($template,array(
180                                 '$id' => $item['item_id'],
181                                 '$profile_url' => $profile_link,
182                                 '$name' => $profile_name,
183                                 '$thumb' => $profile_avatar,
184                                 '$title' => $item['title'],
185                                 '$body' => bbcode($item['body']),
186                                 '$ago' => relative_date($item['created']),
187                                 '$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
188                                 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
189                                 '$owner_url' => $owner_url,
190                                 '$owner_photo' => $owner_photo,
191                                 '$owner_name' => $owner_name,
192                                 '$drop' => $drop,
193                                 '$comment' => $comment
194                         ));
195
196                 }
197         }
198         return $o;
199 }