]> git.mxchange.org Git - friendica.git/blob - mod/videos.php
Merge pull request #1338 from annando/1501-global-contacts
[friendica.git] / mod / videos.php
1 <?php
2 require_once('include/items.php');
3 require_once('include/acl_selectors.php');
4 require_once('include/bbcode.php');
5 require_once('include/security.php');
6 require_once('include/redir.php');
7
8
9 function videos_init(&$a) {
10
11         if($a->argc > 1)
12                 auto_redir($a, $a->argv[1]);
13
14         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
15                 return;
16         }
17
18         $o = '';
19
20         if($a->argc > 1) {
21                 $nick = $a->argv[1];
22                 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
23                         dbesc($nick)
24                 );
25
26                 if(! count($r))
27                         return;
28
29                 $a->data['user'] = $r[0];
30
31                 $o .= '<div class="vcard">';
32                 $o .= '<div class="fn">' . $a->data['user']['username'] . '</div>';
33                 $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg') . '" alt="' . $a->data['user']['username'] . '" /></div>';
34                 $o .= '</div>';
35
36
37                 /*$sql_extra = permissions_sql($a->data['user']['uid']);
38
39                 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
40                         intval($a->data['user']['uid'])
41                 );
42
43                 if(count($albums)) {
44                         $a->data['albums'] = $albums;
45
46                         $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);     
47
48                         if($albums_visible) {
49                                 $o .= '<div id="side-bar-photos-albums" class="widget">';
50                                 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
51                                         
52                                 $o .= '<ul>';
53                                 foreach($albums as $album) {
54
55                                         // don't show contact photos. We once translated this name, but then you could still access it under
56                                         // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
57
58                                         if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
59                                                 continue;
60                                         $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>'; 
61                                 }
62                                 $o .= '</ul>';
63                         }
64                         if(local_user() && $a->data['user']['uid'] == local_user()) {
65                                 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
66                         }
67
68                         $o .= '</div>';
69                 }*/
70
71                 if(! x($a->page,'aside'))
72                         $a->page['aside'] = '';
73                 $a->page['aside'] .= $o;
74
75
76                 $tpl = get_markup_template("videos_head.tpl");
77                 $a->page['htmlhead'] .= replace_macros($tpl,array(
78                         '$baseurl' => $a->get_baseurl(),
79                 ));
80
81                 $tpl = get_markup_template("videos_end.tpl");
82                 $a->page['end'] .= replace_macros($tpl,array(
83                         '$baseurl' => $a->get_baseurl(),
84                 ));
85
86         }
87
88         return;
89 }
90
91
92
93 function videos_post(&$a) {
94
95         return;
96
97         // DELETED -- look at mod/photos.php if you want to implement
98 }
99
100
101
102 function videos_content(&$a) {
103
104         // URLs (most aren't currently implemented):
105         // videos/name
106         // videos/name/upload
107         // videos/name/upload/xxxxx (xxxxx is album name)
108         // videos/name/album/xxxxx
109         // videos/name/album/xxxxx/edit
110         // videos/name/video/xxxxx
111         // videos/name/video/xxxxx/edit
112
113
114         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
115                 notice( t('Public access denied.') . EOL);
116                 return;
117         }
118         
119         
120         require_once('include/bbcode.php');
121         require_once('include/security.php');
122         require_once('include/conversation.php');
123
124         if(! x($a->data,'user')) {
125                 notice( t('No videos selected') . EOL );
126                 return;
127         }
128
129         //$phototypes = Photo::supportedTypes();
130
131         $_SESSION['video_return'] = $a->cmd;
132
133         //
134         // Parse arguments 
135         //
136
137         if($a->argc > 3) {
138                 $datatype = $a->argv[2];
139                 $datum = $a->argv[3];
140         }
141         elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
142                 $datatype = 'upload';
143         else
144                 $datatype = 'summary';
145
146         if($a->argc > 4)
147                 $cmd = $a->argv[4];
148         else
149                 $cmd = 'view';
150
151         //
152         // Setup permissions structures
153         //
154
155         $can_post       = false;
156         $visitor        = 0;
157         $contact        = null;
158         $remote_contact = false;
159         $contact_id     = 0;
160
161         $owner_uid = $a->data['user']['uid'];
162
163         $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
164
165         if((local_user()) && (local_user() == $owner_uid))
166                 $can_post = true;
167         else {
168                 if($community_page && remote_user()) {
169                         if(is_array($_SESSION['remote'])) {
170                                 foreach($_SESSION['remote'] as $v) {
171                                         if($v['uid'] == $owner_uid) {
172                                                 $contact_id = $v['cid'];
173                                                 break;
174                                         }
175                                 }
176                         }
177                         if($contact_id) {
178
179                                 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
180                                         intval($contact_id),
181                                         intval($owner_uid)
182                                 );
183                                 if(count($r)) {
184                                         $can_post = true;
185                                         $contact = $r[0];
186                                         $remote_contact = true;
187                                         $visitor = $cid;
188                                 }
189                         }
190                 }
191         }
192
193         // perhaps they're visiting - but not a community page, so they wouldn't have write access
194
195         if(remote_user() && (! $visitor)) {
196                 $contact_id = 0;
197                 if(is_array($_SESSION['remote'])) {
198                         foreach($_SESSION['remote'] as $v) {
199                                 if($v['uid'] == $owner_uid) {
200                                         $contact_id = $v['cid'];
201                                         break;
202                                 }
203                         }
204                 }
205                 if($contact_id) {
206                         $groups = init_groups_visitor($contact_id);
207                         $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
208                                 intval($contact_id),
209                                 intval($owner_uid)
210                         );
211                         if(count($r)) {
212                                 $contact = $r[0];
213                                 $remote_contact = true;
214                         }
215                 }
216         }
217
218         if(! $remote_contact) {
219                 if(local_user()) {
220                         $contact_id = $_SESSION['cid'];
221                         $contact = $a->contact;
222                 }
223         }
224
225         if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
226                 notice( t('Access to this item is restricted.') . EOL);
227                 return;
228         }
229
230         $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
231
232         $o = "";
233
234         // tabs
235         $_is_owner = (local_user() && (local_user() == $owner_uid));
236         $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);        
237
238         //
239         // dispatch request
240         //
241
242
243         if($datatype === 'upload') {
244                 return; // no uploading for now
245
246                 // DELETED -- look at mod/photos.php if you want to implement
247         }
248
249         if($datatype === 'album') {
250
251                 return; // no albums for now
252
253                 // DELETED -- look at mod/photos.php if you want to implement
254         }       
255
256
257         if($datatype === 'video') {
258
259                 return; // no single video view for now
260
261                 // DELETED -- look at mod/photos.php if you want to implement
262         }
263
264         // Default - show recent videos (no upload link for now)
265         //$o = '';
266
267         $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
268                 $sql_extra GROUP BY hash",
269                 intval($a->data['user']['uid'])
270         );
271         if(count($r)) {
272                 $a->set_pager_total(count($r));
273                 $a->set_pager_itemspage(20);
274         }
275
276         $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`
277                 WHERE `uid` = %d AND filetype LIKE '%%video%%'
278                 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
279                 intval($a->data['user']['uid']),
280                 intval($a->pager['start']),
281                 intval($a->pager['itemspage'])
282         );
283
284
285
286         $videos = array();
287         if(count($r)) {
288                 foreach($r as $rr) {
289                         if($a->theme['template_engine'] === 'internal') {
290                                 $alt_e = template_escape($rr['filename']);
291                                 $name_e = template_escape($rr['album']);
292                         }
293                         else {
294                                 $alt_e = $rr['filename'];
295                                 $name_e = $rr['album'];
296                         }
297
298                         $videos[] = array(
299                                 'id'       => $rr['id'],
300                                 'link'          => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
301                                 'title'         => t('View Video'),
302                                 'src'           => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
303                                 'alt'           => $alt_e,
304                                 'mime'          => $rr['filetype'],
305                                 'album' => array(
306                                         'link'  => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
307                                         'name'  => $name_e,
308                                         'alt'   => t('View Album'),
309                                 ),
310                                 
311                         );
312                 }
313         }
314         
315         $tpl = get_markup_template('videos_recent.tpl'); 
316         $o .= replace_macros($tpl, array(
317                 '$title' => t('Recent Videos'),
318                 '$can_post' => $can_post,
319                 '$upload' => array(t('Upload New Videos'), $a->get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
320                 '$videos' => $videos,
321         ));
322
323         
324         $o .= paginate($a);
325         return $o;
326 }
327