7 use Friendica\Content\Nav;
8 use Friendica\Core\Config;
9 use Friendica\Core\L10n;
10 use Friendica\Core\System;
11 use Friendica\Core\Worker;
12 use Friendica\Database\DBM;
13 use Friendica\Model\Contact;
14 use Friendica\Model\Group;
15 use Friendica\Model\Item;
16 use Friendica\Model\Profile;
17 use Friendica\Model\Term;
18 use Friendica\Protocol\DFRN;
19 use Friendica\Util\DateTimeFormat;
21 require_once 'include/items.php';
22 require_once 'include/acl_selectors.php';
23 require_once 'include/bbcode.php';
24 require_once 'include/security.php';
26 function videos_init(App $a) {
29 DFRN::autoRedir($a, $a->argv[1]);
31 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
35 Nav::setSelected('home');
41 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
48 $a->data['user'] = $user[0];
49 $a->profile_uid = $user[0]['uid'];
51 $profile = Profile::getByNickname($nick, $a->profile_uid);
53 $account_type = Contact::getAccountType($profile);
55 $tpl = get_markup_template("vcard-widget.tpl");
57 $vcard_widget = replace_macros($tpl, [
58 '$name' => $profile['name'],
59 '$photo' => $profile['photo'],
60 '$addr' => defaults($profile, 'addr', ''),
61 '$account_type' => $account_type,
62 '$pdesc' => defaults($profile, 'pdesc', ''),
66 /*$sql_extra = permissions_sql($a->data['user']['uid']);
68 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
69 intval($a->data['user']['uid'])
73 $a->data['albums'] = $albums;
75 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
78 $o .= '<div id="sidebar-photos-albums" class="widget">';
79 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';
82 foreach($albums as $album) {
84 // don't show contact photos. We once translated this name, but then you could still access it under
85 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
87 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
89 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
93 if(local_user() && $a->data['user']['uid'] == local_user()) {
94 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
100 if(! x($a->page,'aside'))
101 $a->page['aside'] = '';
102 $a->page['aside'] .= $vcard_widget;
105 $tpl = get_markup_template("videos_head.tpl");
106 $a->page['htmlhead'] .= replace_macros($tpl,[
107 '$baseurl' => System::baseUrl(),
110 $tpl = get_markup_template("videos_end.tpl");
111 $a->page['end'] .= replace_macros($tpl,[
112 '$baseurl' => System::baseUrl(),
122 function videos_post(App $a) {
124 $owner_uid = $a->data['user']['uid'];
126 if (local_user() != $owner_uid) {
127 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
130 if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
132 // Check if we should do HTML-based delete confirmation
133 if (!x($_REQUEST,'confirm')) {
134 if (x($_REQUEST,'canceled')) {
135 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
138 $drop_url = $a->query_string;
139 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
141 '$message' => L10n::t('Do you really want to delete this video?'),
143 ['name'=>'id', 'value'=> $_POST['id']],
144 ['name'=>'delete', 'value'=>'x']
146 '$confirm' => L10n::t('Delete Video'),
147 '$confirm_url' => $drop_url,
148 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
149 '$cancel' => L10n::t('Cancel'),
152 $a->error = 1; // Set $a->error so the other module functions don't execute
156 $video_id = $_POST['id'];
158 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
159 intval(local_user()),
163 if (DBM::is_result($r)) {
164 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
165 intval(local_user()),
168 $i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
173 if (DBM::is_result($i)) {
174 Item::deleteById($i[0]['id']);
178 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
179 return; // NOTREACHED
182 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
188 function videos_content(App $a) {
190 // URLs (most aren't currently implemented):
192 // videos/name/upload
193 // videos/name/upload/xxxxx (xxxxx is album name)
194 // videos/name/album/xxxxx
195 // videos/name/album/xxxxx/edit
196 // videos/name/video/xxxxx
197 // videos/name/video/xxxxx/edit
200 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
201 notice(L10n::t('Public access denied.') . EOL);
206 require_once('include/bbcode.php');
207 require_once('include/security.php');
208 require_once('include/conversation.php');
210 if(! x($a->data,'user')) {
211 notice(L10n::t('No videos selected') . EOL );
215 //$phototypes = Photo::supportedTypes();
217 $_SESSION['video_return'] = $a->cmd;
224 $datatype = $a->argv[2];
225 $datum = $a->argv[3];
227 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
228 $datatype = 'upload';
230 $datatype = 'summary';
238 // Setup permissions structures
244 $remote_contact = false;
247 $owner_uid = $a->data['user']['uid'];
249 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
251 if((local_user()) && (local_user() == $owner_uid))
254 if($community_page && remote_user()) {
255 if(is_array($_SESSION['remote'])) {
256 foreach($_SESSION['remote'] as $v) {
257 if($v['uid'] == $owner_uid) {
258 $contact_id = $v['cid'];
265 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
269 if (DBM::is_result($r)) {
272 $remote_contact = true;
273 $visitor = $contact_id;
281 // perhaps they're visiting - but not a community page, so they wouldn't have write access
282 if(remote_user() && (! $visitor)) {
284 if(is_array($_SESSION['remote'])) {
285 foreach($_SESSION['remote'] as $v) {
286 if($v['uid'] == $owner_uid) {
287 $contact_id = $v['cid'];
293 $groups = Group::getIdsByContactId($contact_id);
294 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
298 if (DBM::is_result($r)) {
300 $remote_contact = true;
305 if(! $remote_contact) {
307 $contact_id = $_SESSION['cid'];
308 $contact = $a->contact;
312 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
313 notice(L10n::t('Access to this item is restricted.') . EOL);
317 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
322 $_is_owner = (local_user() && (local_user() == $owner_uid));
323 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
330 if($datatype === 'upload') {
331 return; // no uploading for now
333 // DELETED -- look at mod/photos.php if you want to implement
336 if($datatype === 'album') {
338 return; // no albums for now
340 // DELETED -- look at mod/photos.php if you want to implement
344 if($datatype === 'video') {
346 return; // no single video view for now
348 // DELETED -- look at mod/photos.php if you want to implement
351 // Default - show recent videos (no upload link for now)
354 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
355 $sql_extra GROUP BY hash",
356 intval($a->data['user']['uid'])
358 if (DBM::is_result($r)) {
359 $a->set_pager_total(count($r));
360 $a->set_pager_itemspage(20);
363 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
364 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
366 WHERE `uid` = %d AND filetype LIKE '%%video%%'
367 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
368 intval($a->data['user']['uid']),
369 intval($a->pager['start']),
370 intval($a->pager['itemspage'])
376 if (DBM::is_result($r)) {
377 foreach ($r as $rr) {
378 $alt_e = $rr['filename'];
379 $name_e = $rr['album'];
383 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
384 'title' => L10n::t('View Video'),
385 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
387 'mime' => $rr['filetype'],
389 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
391 'alt' => L10n::t('View Album'),
398 $tpl = get_markup_template('videos_recent.tpl');
399 $o .= replace_macros($tpl, [
400 '$title' => L10n::t('Recent Videos'),
401 '$can_post' => $can_post,
402 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'],
403 '$videos' => $videos,
404 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)