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