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 * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
172 //echo "<pre>"; var_dump($i); killme();
173 if (DBM::is_result($i)) {
174 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
175 dbesc(DateTimeFormat::utcNow()),
176 dbesc(DateTimeFormat::utcNow()),
180 Term::insertFromTagFieldByItemUri($i[0]['uri'], local_user());
181 Item::deleteThreadByUri($i[0]['uri'], local_user());
183 $url = System::baseUrl();
184 $drop_id = intval($i[0]['id']);
186 if ($i[0]['visible']) {
187 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
192 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
193 return; // NOTREACHED
196 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
202 function videos_content(App $a) {
204 // URLs (most aren't currently implemented):
206 // videos/name/upload
207 // videos/name/upload/xxxxx (xxxxx is album name)
208 // videos/name/album/xxxxx
209 // videos/name/album/xxxxx/edit
210 // videos/name/video/xxxxx
211 // videos/name/video/xxxxx/edit
214 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
215 notice(L10n::t('Public access denied.') . EOL);
220 require_once('include/bbcode.php');
221 require_once('include/security.php');
222 require_once('include/conversation.php');
224 if(! x($a->data,'user')) {
225 notice(L10n::t('No videos selected') . EOL );
229 //$phototypes = Photo::supportedTypes();
231 $_SESSION['video_return'] = $a->cmd;
238 $datatype = $a->argv[2];
239 $datum = $a->argv[3];
241 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
242 $datatype = 'upload';
244 $datatype = 'summary';
252 // Setup permissions structures
258 $remote_contact = false;
261 $owner_uid = $a->data['user']['uid'];
263 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
265 if((local_user()) && (local_user() == $owner_uid))
268 if($community_page && remote_user()) {
269 if(is_array($_SESSION['remote'])) {
270 foreach($_SESSION['remote'] as $v) {
271 if($v['uid'] == $owner_uid) {
272 $contact_id = $v['cid'];
279 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
283 if (DBM::is_result($r)) {
286 $remote_contact = true;
287 $visitor = $contact_id;
295 // perhaps they're visiting - but not a community page, so they wouldn't have write access
296 if(remote_user() && (! $visitor)) {
298 if(is_array($_SESSION['remote'])) {
299 foreach($_SESSION['remote'] as $v) {
300 if($v['uid'] == $owner_uid) {
301 $contact_id = $v['cid'];
307 $groups = Group::getIdsByContactId($contact_id);
308 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
312 if (DBM::is_result($r)) {
314 $remote_contact = true;
319 if(! $remote_contact) {
321 $contact_id = $_SESSION['cid'];
322 $contact = $a->contact;
326 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
327 notice(L10n::t('Access to this item is restricted.') . EOL);
331 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
336 $_is_owner = (local_user() && (local_user() == $owner_uid));
337 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
344 if($datatype === 'upload') {
345 return; // no uploading for now
347 // DELETED -- look at mod/photos.php if you want to implement
350 if($datatype === 'album') {
352 return; // no albums for now
354 // DELETED -- look at mod/photos.php if you want to implement
358 if($datatype === 'video') {
360 return; // no single video view for now
362 // DELETED -- look at mod/photos.php if you want to implement
365 // Default - show recent videos (no upload link for now)
368 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
369 $sql_extra GROUP BY hash",
370 intval($a->data['user']['uid'])
372 if (DBM::is_result($r)) {
373 $a->set_pager_total(count($r));
374 $a->set_pager_itemspage(20);
377 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
378 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
380 WHERE `uid` = %d AND filetype LIKE '%%video%%'
381 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
382 intval($a->data['user']['uid']),
383 intval($a->pager['start']),
384 intval($a->pager['itemspage'])
390 if (DBM::is_result($r)) {
391 foreach ($r as $rr) {
392 $alt_e = $rr['filename'];
393 $name_e = $rr['album'];
397 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
398 'title' => L10n::t('View Video'),
399 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
401 'mime' => $rr['filetype'],
403 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
405 'alt' => L10n::t('View Album'),
412 $tpl = get_markup_template('videos_recent.tpl');
413 $o .= replace_macros($tpl, [
414 '$title' => L10n::t('Recent Videos'),
415 '$can_post' => $can_post,
416 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'],
417 '$videos' => $videos,
418 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)