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