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/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 `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
171 if (DBM::is_result($i)) {
172 Item::deleteById($i[0]['id']);
176 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
177 return; // NOTREACHED
180 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
186 function videos_content(App $a) {
188 // URLs (most aren't currently implemented):
190 // videos/name/upload
191 // videos/name/upload/xxxxx (xxxxx is album name)
192 // videos/name/album/xxxxx
193 // videos/name/album/xxxxx/edit
194 // videos/name/video/xxxxx
195 // videos/name/video/xxxxx/edit
198 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
199 notice(L10n::t('Public access denied.') . EOL);
203 require_once('include/security.php');
204 require_once('include/conversation.php');
206 if(! x($a->data,'user')) {
207 notice(L10n::t('No videos selected') . EOL );
211 //$phototypes = Photo::supportedTypes();
213 $_SESSION['video_return'] = $a->cmd;
220 $datatype = $a->argv[2];
221 $datum = $a->argv[3];
223 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
224 $datatype = 'upload';
226 $datatype = 'summary';
234 // Setup permissions structures
240 $remote_contact = false;
243 $owner_uid = $a->data['user']['uid'];
245 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
247 if((local_user()) && (local_user() == $owner_uid))
250 if($community_page && remote_user()) {
251 if(is_array($_SESSION['remote'])) {
252 foreach($_SESSION['remote'] as $v) {
253 if($v['uid'] == $owner_uid) {
254 $contact_id = $v['cid'];
261 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
265 if (DBM::is_result($r)) {
268 $remote_contact = true;
269 $visitor = $contact_id;
277 // perhaps they're visiting - but not a community page, so they wouldn't have write access
278 if(remote_user() && (! $visitor)) {
280 if(is_array($_SESSION['remote'])) {
281 foreach($_SESSION['remote'] as $v) {
282 if($v['uid'] == $owner_uid) {
283 $contact_id = $v['cid'];
289 $groups = Group::getIdsByContactId($contact_id);
290 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
294 if (DBM::is_result($r)) {
296 $remote_contact = true;
301 if(! $remote_contact) {
303 $contact_id = $_SESSION['cid'];
304 $contact = $a->contact;
308 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
309 notice(L10n::t('Access to this item is restricted.') . EOL);
313 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
318 $_is_owner = (local_user() && (local_user() == $owner_uid));
319 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
326 if($datatype === 'upload') {
327 return; // no uploading for now
329 // DELETED -- look at mod/photos.php if you want to implement
332 if($datatype === 'album') {
334 return; // no albums for now
336 // DELETED -- look at mod/photos.php if you want to implement
340 if($datatype === 'video') {
342 return; // no single video view for now
344 // DELETED -- look at mod/photos.php if you want to implement
347 // Default - show recent videos (no upload link for now)
350 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
351 $sql_extra GROUP BY hash",
352 intval($a->data['user']['uid'])
354 if (DBM::is_result($r)) {
355 $a->set_pager_total(count($r));
356 $a->set_pager_itemspage(20);
359 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
360 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
362 WHERE `uid` = %d AND filetype LIKE '%%video%%'
363 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
364 intval($a->data['user']['uid']),
365 intval($a->pager['start']),
366 intval($a->pager['itemspage'])
372 if (DBM::is_result($r)) {
373 foreach ($r as $rr) {
374 $alt_e = $rr['filename'];
375 $name_e = $rr['album'];
379 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
380 'title' => L10n::t('View Video'),
381 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
383 'mime' => $rr['filetype'],
385 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
387 'alt' => L10n::t('View Album'),
394 $tpl = get_markup_template('videos_recent.tpl');
395 $o .= replace_macros($tpl, [
396 '$title' => L10n::t('Recent Videos'),
397 '$can_post' => $can_post,
398 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'],
399 '$videos' => $videos,
400 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)