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