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\Profile;
16 use Friendica\Protocol\DFRN;
17 use Friendica\Util\Temporal;
19 require_once 'include/items.php';
20 require_once 'include/acl_selectors.php';
21 require_once 'include/bbcode.php';
22 require_once 'include/security.php';
24 function videos_init(App $a) {
27 DFRN::autoRedir($a, $a->argv[1]);
29 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
33 Nav::setSelected('home');
39 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
46 $a->data['user'] = $user[0];
47 $a->profile_uid = $user[0]['uid'];
49 $profile = Profile::getByNickname($nick, $a->profile_uid);
51 $account_type = Contact::getAccountType($profile);
53 $tpl = get_markup_template("vcard-widget.tpl");
55 $vcard_widget = replace_macros($tpl, [
56 '$name' => $profile['name'],
57 '$photo' => $profile['photo'],
58 '$addr' => defaults($profile, 'addr', ''),
59 '$account_type' => $account_type,
60 '$pdesc' => defaults($profile, 'pdesc', ''),
64 /*$sql_extra = permissions_sql($a->data['user']['uid']);
66 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
67 intval($a->data['user']['uid'])
71 $a->data['albums'] = $albums;
73 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
76 $o .= '<div id="sidebar-photos-albums" class="widget">';
77 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';
80 foreach($albums as $album) {
82 // don't show contact photos. We once translated this name, but then you could still access it under
83 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
85 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
87 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
91 if(local_user() && $a->data['user']['uid'] == local_user()) {
92 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
98 if(! x($a->page,'aside'))
99 $a->page['aside'] = '';
100 $a->page['aside'] .= $vcard_widget;
103 $tpl = get_markup_template("videos_head.tpl");
104 $a->page['htmlhead'] .= replace_macros($tpl,[
105 '$baseurl' => System::baseUrl(),
108 $tpl = get_markup_template("videos_end.tpl");
109 $a->page['end'] .= replace_macros($tpl,[
110 '$baseurl' => System::baseUrl(),
120 function videos_post(App $a) {
122 $owner_uid = $a->data['user']['uid'];
124 if (local_user() != $owner_uid) {
125 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
128 if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
130 // Check if we should do HTML-based delete confirmation
131 if (!x($_REQUEST,'confirm')) {
132 if (x($_REQUEST,'canceled')) {
133 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
136 $drop_url = $a->query_string;
137 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
139 '$message' => L10n::t('Do you really want to delete this video?'),
141 ['name'=>'id', 'value'=> $_POST['id']],
142 ['name'=>'delete', 'value'=>'x']
144 '$confirm' => L10n::t('Delete Video'),
145 '$confirm_url' => $drop_url,
146 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
147 '$cancel' => L10n::t('Cancel'),
150 $a->error = 1; // Set $a->error so the other module functions don't execute
154 $video_id = $_POST['id'];
156 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
157 intval(local_user()),
161 if (DBM::is_result($r)) {
162 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
163 intval(local_user()),
166 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
170 //echo "<pre>"; var_dump($i); killme();
171 if (DBM::is_result($i)) {
172 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
173 dbesc(Temporal::convert()),
174 dbesc(Temporal::convert()),
178 create_tags_from_itemuri($i[0]['uri'], local_user());
179 delete_thread_uri($i[0]['uri'], local_user());
181 $url = System::baseUrl();
182 $drop_id = intval($i[0]['id']);
184 if ($i[0]['visible']) {
185 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
190 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
191 return; // NOTREACHED
194 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
200 function videos_content(App $a) {
202 // URLs (most aren't currently implemented):
204 // videos/name/upload
205 // videos/name/upload/xxxxx (xxxxx is album name)
206 // videos/name/album/xxxxx
207 // videos/name/album/xxxxx/edit
208 // videos/name/video/xxxxx
209 // videos/name/video/xxxxx/edit
212 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
213 notice(L10n::t('Public access denied.') . EOL);
218 require_once('include/bbcode.php');
219 require_once('include/security.php');
220 require_once('include/conversation.php');
222 if(! x($a->data,'user')) {
223 notice(L10n::t('No videos selected') . EOL );
227 //$phototypes = Photo::supportedTypes();
229 $_SESSION['video_return'] = $a->cmd;
236 $datatype = $a->argv[2];
237 $datum = $a->argv[3];
239 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
240 $datatype = 'upload';
242 $datatype = 'summary';
250 // Setup permissions structures
256 $remote_contact = false;
259 $owner_uid = $a->data['user']['uid'];
261 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
263 if((local_user()) && (local_user() == $owner_uid))
266 if($community_page && remote_user()) {
267 if(is_array($_SESSION['remote'])) {
268 foreach($_SESSION['remote'] as $v) {
269 if($v['uid'] == $owner_uid) {
270 $contact_id = $v['cid'];
277 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
281 if (DBM::is_result($r)) {
284 $remote_contact = true;
285 $visitor = $contact_id;
293 // perhaps they're visiting - but not a community page, so they wouldn't have write access
294 if(remote_user() && (! $visitor)) {
296 if(is_array($_SESSION['remote'])) {
297 foreach($_SESSION['remote'] as $v) {
298 if($v['uid'] == $owner_uid) {
299 $contact_id = $v['cid'];
305 $groups = Group::getIdsByContactId($contact_id);
306 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
310 if (DBM::is_result($r)) {
312 $remote_contact = true;
317 if(! $remote_contact) {
319 $contact_id = $_SESSION['cid'];
320 $contact = $a->contact;
324 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
325 notice(L10n::t('Access to this item is restricted.') . EOL);
329 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
334 $_is_owner = (local_user() && (local_user() == $owner_uid));
335 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
342 if($datatype === 'upload') {
343 return; // no uploading for now
345 // DELETED -- look at mod/photos.php if you want to implement
348 if($datatype === 'album') {
350 return; // no albums for now
352 // DELETED -- look at mod/photos.php if you want to implement
356 if($datatype === 'video') {
358 return; // no single video view for now
360 // DELETED -- look at mod/photos.php if you want to implement
363 // Default - show recent videos (no upload link for now)
366 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
367 $sql_extra GROUP BY hash",
368 intval($a->data['user']['uid'])
370 if (DBM::is_result($r)) {
371 $a->set_pager_total(count($r));
372 $a->set_pager_itemspage(20);
375 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
376 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
378 WHERE `uid` = %d AND filetype LIKE '%%video%%'
379 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
380 intval($a->data['user']['uid']),
381 intval($a->pager['start']),
382 intval($a->pager['itemspage'])
388 if (DBM::is_result($r)) {
389 foreach ($r as $rr) {
390 $alt_e = $rr['filename'];
391 $name_e = $rr['album'];
395 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
396 'title' => L10n::t('View Video'),
397 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
399 'mime' => $rr['filetype'],
401 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
403 'alt' => L10n::t('View Album'),
410 $tpl = get_markup_template('videos_recent.tpl');
411 $o .= replace_macros($tpl, [
412 '$title' => L10n::t('Recent Videos'),
413 '$can_post' => $can_post,
414 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'],
415 '$videos' => $videos,
416 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)