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