6 use Friendica\Core\Config;
7 use Friendica\Core\System;
8 use Friendica\Core\Worker;
9 use Friendica\Database\DBM;
10 use Friendica\Model\Contact;
11 use Friendica\Model\Group;
12 use Friendica\Model\Profile;
13 use Friendica\Protocol\DFRN;
15 require_once 'include/items.php';
16 require_once 'include/acl_selectors.php';
17 require_once 'include/bbcode.php';
18 require_once 'include/security.php';
20 function videos_init(App $a) {
23 DFRN::autoRedir($a, $a->argv[1]);
25 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
29 nav_set_selected('home');
35 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
42 $a->data['user'] = $user[0];
43 $a->profile_uid = $user[0]['uid'];
45 $profile = Profile::getByNickname($nick, $a->profile_uid);
47 $account_type = Contact::getAccountType($profile);
49 $tpl = get_markup_template("vcard-widget.tpl");
51 $vcard_widget = replace_macros($tpl, array(
52 '$name' => $profile['name'],
53 '$photo' => $profile['photo'],
54 '$addr' => defaults($profile, 'addr', ''),
55 '$account_type' => $account_type,
56 '$pdesc' => defaults($profile, 'pdesc', ''),
60 /*$sql_extra = permissions_sql($a->data['user']['uid']);
62 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
63 intval($a->data['user']['uid'])
67 $a->data['albums'] = $albums;
69 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
72 $o .= '<div id="sidebar-photos-albums" class="widget">';
73 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
76 foreach($albums as $album) {
78 // don't show contact photos. We once translated this name, but then you could still access it under
79 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
81 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
83 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
87 if(local_user() && $a->data['user']['uid'] == local_user()) {
88 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
94 if(! x($a->page,'aside'))
95 $a->page['aside'] = '';
96 $a->page['aside'] .= $vcard_widget;
99 $tpl = get_markup_template("videos_head.tpl");
100 $a->page['htmlhead'] .= replace_macros($tpl,array(
101 '$baseurl' => System::baseUrl(),
104 $tpl = get_markup_template("videos_end.tpl");
105 $a->page['end'] .= replace_macros($tpl,array(
106 '$baseurl' => System::baseUrl(),
116 function videos_post(App $a) {
118 $owner_uid = $a->data['user']['uid'];
120 if (local_user() != $owner_uid) {
121 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
124 if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
126 // Check if we should do HTML-based delete confirmation
127 if (!x($_REQUEST,'confirm')) {
128 if (x($_REQUEST,'canceled')) {
129 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
132 $drop_url = $a->query_string;
133 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
135 '$message' => t('Do you really want to delete this video?'),
136 '$extra_inputs' => array(
137 array('name'=>'id', 'value'=> $_POST['id']),
138 array('name'=>'delete', 'value'=>'x')
140 '$confirm' => t('Delete Video'),
141 '$confirm_url' => $drop_url,
142 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
143 '$cancel' => t('Cancel'),
146 $a->error = 1; // Set $a->error so the other module functions don't execute
150 $video_id = $_POST['id'];
152 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
153 intval(local_user()),
157 if (DBM::is_result($r)) {
158 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
159 intval(local_user()),
162 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
166 //echo "<pre>"; var_dump($i); killme();
167 if (DBM::is_result($i)) {
168 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
169 dbesc(datetime_convert()),
170 dbesc(datetime_convert()),
174 create_tags_from_itemuri($i[0]['uri'], local_user());
175 delete_thread_uri($i[0]['uri'], local_user());
177 $url = System::baseUrl();
178 $drop_id = intval($i[0]['id']);
180 if ($i[0]['visible']) {
181 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
186 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
187 return; // NOTREACHED
190 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
196 function videos_content(App $a) {
198 // URLs (most aren't currently implemented):
200 // videos/name/upload
201 // videos/name/upload/xxxxx (xxxxx is album name)
202 // videos/name/album/xxxxx
203 // videos/name/album/xxxxx/edit
204 // videos/name/video/xxxxx
205 // videos/name/video/xxxxx/edit
208 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
209 notice( t('Public access denied.') . EOL);
214 require_once('include/bbcode.php');
215 require_once('include/security.php');
216 require_once('include/conversation.php');
218 if(! x($a->data,'user')) {
219 notice( t('No videos selected') . EOL );
223 //$phototypes = Photo::supportedTypes();
225 $_SESSION['video_return'] = $a->cmd;
232 $datatype = $a->argv[2];
233 $datum = $a->argv[3];
235 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
236 $datatype = 'upload';
238 $datatype = 'summary';
246 // Setup permissions structures
252 $remote_contact = false;
255 $owner_uid = $a->data['user']['uid'];
257 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
259 if((local_user()) && (local_user() == $owner_uid))
262 if($community_page && remote_user()) {
263 if(is_array($_SESSION['remote'])) {
264 foreach($_SESSION['remote'] as $v) {
265 if($v['uid'] == $owner_uid) {
266 $contact_id = $v['cid'];
273 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
277 if (DBM::is_result($r)) {
280 $remote_contact = true;
281 $visitor = $contact_id;
289 // perhaps they're visiting - but not a community page, so they wouldn't have write access
290 if(remote_user() && (! $visitor)) {
292 if(is_array($_SESSION['remote'])) {
293 foreach($_SESSION['remote'] as $v) {
294 if($v['uid'] == $owner_uid) {
295 $contact_id = $v['cid'];
301 $groups = Group::getIdsByContactId($contact_id);
302 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
306 if (DBM::is_result($r)) {
308 $remote_contact = true;
313 if(! $remote_contact) {
315 $contact_id = $_SESSION['cid'];
316 $contact = $a->contact;
320 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
321 notice( t('Access to this item is restricted.') . EOL);
325 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
330 $_is_owner = (local_user() && (local_user() == $owner_uid));
331 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
338 if($datatype === 'upload') {
339 return; // no uploading for now
341 // DELETED -- look at mod/photos.php if you want to implement
344 if($datatype === 'album') {
346 return; // no albums for now
348 // DELETED -- look at mod/photos.php if you want to implement
352 if($datatype === 'video') {
354 return; // no single video view for now
356 // DELETED -- look at mod/photos.php if you want to implement
359 // Default - show recent videos (no upload link for now)
362 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
363 $sql_extra GROUP BY hash",
364 intval($a->data['user']['uid'])
366 if (DBM::is_result($r)) {
367 $a->set_pager_total(count($r));
368 $a->set_pager_itemspage(20);
371 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
372 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
374 WHERE `uid` = %d AND filetype LIKE '%%video%%'
375 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
376 intval($a->data['user']['uid']),
377 intval($a->pager['start']),
378 intval($a->pager['itemspage'])
384 if (DBM::is_result($r)) {
385 foreach ($r as $rr) {
386 $alt_e = $rr['filename'];
387 $name_e = $rr['album'];
391 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
392 'title' => t('View Video'),
393 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
395 'mime' => $rr['filetype'],
397 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
399 'alt' => t('View Album'),
406 $tpl = get_markup_template('videos_recent.tpl');
407 $o .= replace_macros($tpl, array(
408 '$title' => t('Recent Videos'),
409 '$can_post' => $can_post,
410 '$upload' => array(t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'),
411 '$videos' => $videos,
412 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)