]> git.mxchange.org Git - friendica.git/blob - mod/videos.php
Merge pull request #2132 from rabuzarus/0112_vier_css
[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         nav_set_selected('home');
19
20         $o = '';
21
22         if($a->argc > 1) {
23                 $nick = $a->argv[1];
24                 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
25                         dbesc($nick)
26                 );
27
28                 if(! count($r))
29                         return;
30
31                 $a->data['user'] = $r[0];
32                 $a->profile_uid = $r[0]['uid'];
33
34                 $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg');
35
36                 $tpl = get_markup_template("vcard-widget.tpl");
37
38                 $vcard_widget = replace_macros($tpl, array(
39                         '$name' => $a->data['user']['username'],
40                         '$photo' => $profilephoto
41                 ));
42
43
44                 /*$sql_extra = permissions_sql($a->data['user']['uid']);
45
46                 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
47                         intval($a->data['user']['uid'])
48                 );
49
50                 if(count($albums)) {
51                         $a->data['albums'] = $albums;
52
53                         $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
54
55                         if($albums_visible) {
56                                 $o .= '<div id="sidebar-photos-albums" class="widget">';
57                                 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
58
59                                 $o .= '<ul>';
60                                 foreach($albums as $album) {
61
62                                         // don't show contact photos. We once translated this name, but then you could still access it under
63                                         // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
64
65                                         if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
66                                                 continue;
67                                         $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
68                                 }
69                                 $o .= '</ul>';
70                         }
71                         if(local_user() && $a->data['user']['uid'] == local_user()) {
72                                 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
73                         }
74
75                         $o .= '</div>';
76                 }*/
77
78                 if(! x($a->page,'aside'))
79                         $a->page['aside'] = '';
80                 $a->page['aside'] .= $vcard_widget;
81
82
83                 $tpl = get_markup_template("videos_head.tpl");
84                 $a->page['htmlhead'] .= replace_macros($tpl,array(
85                         '$baseurl' => $a->get_baseurl(),
86                 ));
87
88                 $tpl = get_markup_template("videos_end.tpl");
89                 $a->page['end'] .= replace_macros($tpl,array(
90                         '$baseurl' => $a->get_baseurl(),
91                 ));
92
93         }
94
95         return;
96 }
97
98
99
100 function videos_post(&$a) {
101
102         $owner_uid = $a->data['user']['uid'];
103
104         if (local_user() != $owner_uid) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
105
106         if(($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
107
108                 // Check if we should do HTML-based delete confirmation
109                 if(!x($_REQUEST,'confirm')) {
110                         if(x($_REQUEST,'canceled')) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
111
112                         $drop_url = $a->query_string;
113                         $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
114                                 '$method' => 'post',
115                                 '$message' => t('Do you really want to delete this video?'),
116                                 '$extra_inputs' => array(
117                                         array('name'=>'id', 'value'=> $_POST['id']),
118                                         array('name'=>'delete', 'value'=>'x')
119                                 ),
120                                 '$confirm' => t('Delete Video'),
121                                 '$confirm_url' => $drop_url,
122                                 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
123                                 '$cancel' => t('Cancel'),
124
125                         ));
126                         $a->error = 1; // Set $a->error so the other module functions don't execute
127                         return;
128                 }
129
130                 $video_id = $_POST['id'];
131
132
133                 $r = q("SELECT `id`  FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
134                         intval(local_user()),
135                         dbesc($video_id)
136                 );
137
138                 if(count($r)) {
139                         q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
140                                 intval(local_user()),
141                                 dbesc($video_id)
142                         );
143                         $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
144                                 dbesc($video_id),
145                                 intval(local_user())
146                         );
147                         #echo "<pre>"; var_dump($i); killme();
148                         if(count($i)) {
149                                 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
150                                         dbesc(datetime_convert()),
151                                         dbesc(datetime_convert()),
152                                         dbesc($i[0]['uri']),
153                                         intval(local_user())
154                                 );
155                                 create_tags_from_itemuri($i[0]['uri'], local_user());
156                                 delete_thread_uri($i[0]['uri'], local_user());
157
158                                 $url = $a->get_baseurl();
159                                 $drop_id = intval($i[0]['id']);
160
161                                 if($i[0]['visible'])
162                                         proc_run('php',"include/notifier.php","drop","$drop_id");
163                         }
164                 }
165
166                 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
167                 return; // NOTREACHED
168         }
169
170     goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
171
172 }
173
174
175
176 function videos_content(&$a) {
177
178         // URLs (most aren't currently implemented):
179         // videos/name
180         // videos/name/upload
181         // videos/name/upload/xxxxx (xxxxx is album name)
182         // videos/name/album/xxxxx
183         // videos/name/album/xxxxx/edit
184         // videos/name/video/xxxxx
185         // videos/name/video/xxxxx/edit
186
187
188         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
189                 notice( t('Public access denied.') . EOL);
190                 return;
191         }
192
193
194         require_once('include/bbcode.php');
195         require_once('include/security.php');
196         require_once('include/conversation.php');
197
198         if(! x($a->data,'user')) {
199                 notice( t('No videos selected') . EOL );
200                 return;
201         }
202
203         //$phototypes = Photo::supportedTypes();
204
205         $_SESSION['video_return'] = $a->cmd;
206
207         //
208         // Parse arguments
209         //
210
211         if($a->argc > 3) {
212                 $datatype = $a->argv[2];
213                 $datum = $a->argv[3];
214         }
215         elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
216                 $datatype = 'upload';
217         else
218                 $datatype = 'summary';
219
220         if($a->argc > 4)
221                 $cmd = $a->argv[4];
222         else
223                 $cmd = 'view';
224
225         //
226         // Setup permissions structures
227         //
228
229         $can_post       = false;
230         $visitor        = 0;
231         $contact        = null;
232         $remote_contact = false;
233         $contact_id     = 0;
234
235         $owner_uid = $a->data['user']['uid'];
236
237         $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
238
239         if((local_user()) && (local_user() == $owner_uid))
240                 $can_post = true;
241         else {
242                 if($community_page && remote_user()) {
243                         if(is_array($_SESSION['remote'])) {
244                                 foreach($_SESSION['remote'] as $v) {
245                                         if($v['uid'] == $owner_uid) {
246                                                 $contact_id = $v['cid'];
247                                                 break;
248                                         }
249                                 }
250                         }
251                         if($contact_id) {
252
253                                 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
254                                         intval($contact_id),
255                                         intval($owner_uid)
256                                 );
257                                 if(count($r)) {
258                                         $can_post = true;
259                                         $contact = $r[0];
260                                         $remote_contact = true;
261                                         $visitor = $cid;
262                                 }
263                         }
264                 }
265         }
266
267         // perhaps they're visiting - but not a community page, so they wouldn't have write access
268
269         if(remote_user() && (! $visitor)) {
270                 $contact_id = 0;
271                 if(is_array($_SESSION['remote'])) {
272                         foreach($_SESSION['remote'] as $v) {
273                                 if($v['uid'] == $owner_uid) {
274                                         $contact_id = $v['cid'];
275                                         break;
276                                 }
277                         }
278                 }
279                 if($contact_id) {
280                         $groups = init_groups_visitor($contact_id);
281                         $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
282                                 intval($contact_id),
283                                 intval($owner_uid)
284                         );
285                         if(count($r)) {
286                                 $contact = $r[0];
287                                 $remote_contact = true;
288                         }
289                 }
290         }
291
292         if(! $remote_contact) {
293                 if(local_user()) {
294                         $contact_id = $_SESSION['cid'];
295                         $contact = $a->contact;
296                 }
297         }
298
299         if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
300                 notice( t('Access to this item is restricted.') . EOL);
301                 return;
302         }
303
304         $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
305
306         $o = "";
307
308         // tabs
309         $_is_owner = (local_user() && (local_user() == $owner_uid));
310         $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
311
312         //
313         // dispatch request
314         //
315
316
317         if($datatype === 'upload') {
318                 return; // no uploading for now
319
320                 // DELETED -- look at mod/photos.php if you want to implement
321         }
322
323         if($datatype === 'album') {
324
325                 return; // no albums for now
326
327                 // DELETED -- look at mod/photos.php if you want to implement
328         }
329
330
331         if($datatype === 'video') {
332
333                 return; // no single video view for now
334
335                 // DELETED -- look at mod/photos.php if you want to implement
336         }
337
338         // Default - show recent videos (no upload link for now)
339         //$o = '';
340
341         $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
342                 $sql_extra GROUP BY hash",
343                 intval($a->data['user']['uid'])
344         );
345         if(count($r)) {
346                 $a->set_pager_total(count($r));
347                 $a->set_pager_itemspage(20);
348         }
349
350         $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`
351                 WHERE `uid` = %d AND filetype LIKE '%%video%%'
352                 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
353                 intval($a->data['user']['uid']),
354                 intval($a->pager['start']),
355                 intval($a->pager['itemspage'])
356         );
357
358
359
360         $videos = array();
361         if(count($r)) {
362                 foreach($r as $rr) {
363                         if($a->theme['template_engine'] === 'internal') {
364                                 $alt_e = template_escape($rr['filename']);
365                                 $name_e = template_escape($rr['album']);
366                         }
367                         else {
368                                 $alt_e = $rr['filename'];
369                                 $name_e = $rr['album'];
370                         }
371
372                         $videos[] = array(
373                                 'id'       => $rr['id'],
374                                 'link'          => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
375                                 'title'         => t('View Video'),
376                                 'src'           => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
377                                 'alt'           => $alt_e,
378                                 'mime'          => $rr['filetype'],
379                                 'album' => array(
380                                         'link'  => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
381                                         'name'  => $name_e,
382                                         'alt'   => t('View Album'),
383                                 ),
384
385                         );
386                 }
387         }
388
389         $tpl = get_markup_template('videos_recent.tpl');
390         $o .= replace_macros($tpl, array(
391                 '$title' => t('Recent Videos'),
392                 '$can_post' => $can_post,
393                 '$upload' => array(t('Upload New Videos'), $a->get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
394                 '$videos' => $videos,
395         '$delete_url' => (($can_post)?$a->get_baseurl().'/videos/'.$a->data['user']['nickname']:False)
396         ));
397
398
399         $o .= paginate($a);
400         return $o;
401 }
402