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