2 require_once('include/Photo.php');
3 require_once('include/photos.php');
4 require_once('include/items.php');
5 require_once('include/acl_selectors.php');
6 require_once('include/bbcode.php');
7 require_once('include/security.php');
8 require_once('include/redir.php');
9 require_once('include/tags.php');
10 require_once('include/threads.php');
11 require_once('include/Probe.php');
13 use \Friendica\Core\Config;
15 function photos_init(App $a) {
18 auto_redir($a, $a->argv[1]);
20 if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
24 nav_set_selected('home');
28 $user = qu("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
35 $a->data['user'] = $user[0];
36 $a->profile_uid = $user[0]['uid'];
37 $is_owner = (local_user() && (local_user() == $a->profile_uid));
39 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
41 $account_type = account_type($profile);
43 $tpl = get_markup_template("vcard-widget.tpl");
45 $vcard_widget .= replace_macros($tpl, array(
46 '$name' => $profile['name'],
47 '$photo' => $profile['photo'],
48 '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
49 '$account_type' => $account_type,
50 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
53 $albums = photo_albums($a->data['user']['uid']);
55 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
57 // add various encodings to the array so we can just loop through and pick them out in a template
58 $ret = array('success' => false);
61 $a->data['albums'] = $albums;
63 $ret['success'] = true;
65 $ret['albums'] = array();
66 foreach ($albums as $k => $album) {
67 //hide profile photos to others
68 if ((! $is_owner) && (! remote_user()) && ($album['album'] == t('Profile Photos')))
71 'text' => $album['album'],
72 'total' => $album['total'],
73 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
74 'urlencode' => urlencode($album['album']),
75 'bin2hex' => bin2hex($album['album'])
77 $ret['albums'][] = $entry;
83 if (local_user() && $a->data['user']['uid'] == local_user())
86 if ($albums['success']) {
87 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array(
88 '$nick' => $a->data['user']['nickname'],
89 '$title' => t('Photo Albums'),
90 '$recent' => t('Recent Photos'),
91 '$albums' => $albums['albums'],
92 '$baseurl' => z_root(),
93 '$upload' => array( t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'),
94 '$can_post' => $can_post
99 if (! x($a->page,'aside'))
100 $a->page['aside'] = '';
101 $a->page['aside'] .= $vcard_widget;
102 $a->page['aside'] .= $photo_albums_widget;
105 $tpl = get_markup_template("photos_head.tpl");
106 $a->page['htmlhead'] .= replace_macros($tpl,array(
107 '$ispublic' => t('everybody')
117 function photos_post(App $a) {
119 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
122 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
123 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
125 $phototypes = Photo::supportedTypes();
130 $page_owner_uid = $a->data['user']['uid'];
131 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
133 if ((local_user()) && (local_user() == $page_owner_uid))
136 if ($community_page && remote_user()) {
138 if (is_array($_SESSION['remote'])) {
139 foreach ($_SESSION['remote'] as $v) {
140 if ($v['uid'] == $page_owner_uid) {
141 $contact_id = $v['cid'];
148 $r = qu("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
150 intval($page_owner_uid)
152 if (dbm::is_result($r)) {
154 $visitor = $contact_id;
161 notice( t('Permission denied.') . EOL );
165 $r = qu("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
166 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
167 intval($page_owner_uid)
170 if (! dbm::is_result($r)) {
171 notice( t('Contact information unavailable') . EOL);
172 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
176 $owner_record = $r[0];
179 if (($a->argc > 3) && ($a->argv[2] === 'album')) {
180 $album = hex2bin($a->argv[3]);
182 if ($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
183 goaway($_SESSION['photo_return']);
184 return; // NOTREACHED
187 $r = qu("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
189 intval($page_owner_uid)
191 if (!dbm::is_result($r)) {
192 notice( t('Album not found.') . EOL);
193 goaway($_SESSION['photo_return']);
194 return; // NOTREACHED
197 // Check if the user has responded to a delete confirmation query
198 if ($_REQUEST['canceled']) {
199 goaway($_SESSION['photo_return']);
206 $newalbum = notags(trim($_POST['albumname']));
207 if ($newalbum != $album) {
208 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
211 intval($page_owner_uid)
213 // Update the photo albums cache
214 photo_albums($page_owner_uid, true);
216 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
218 return; // NOTREACHED
222 * DELETE photo album and all its photos
225 if ($_POST['dropalbum'] == t('Delete Album')) {
227 // Check if we should do HTML-based delete confirmation
228 if ($_REQUEST['confirm']) {
229 $drop_url = $a->query_string;
230 $extra_inputs = array(
231 array('name' => 'albumname', 'value' => $_POST['albumname']),
233 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
235 '$message' => t('Do you really want to delete this photo album and all its photos?'),
236 '$extra_inputs' => $extra_inputs,
237 '$confirm' => t('Delete Album'),
238 '$confirm_url' => $drop_url,
239 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
240 '$cancel' => t('Cancel'),
242 $a->error = 1; // Set $a->error so the other module functions don't execute
248 // get the list of photos we are about to delete
251 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
253 intval($page_owner_uid),
257 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
258 intval(local_user()),
262 if (dbm::is_result($r)) {
263 foreach ($r as $rr) {
264 $res[] = "'" . dbesc($rr['rid']) . "'" ;
267 goaway($_SESSION['photo_return']);
268 return; // NOTREACHED
271 $str_res = implode(',', $res);
273 // remove the associated photos
275 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
276 intval($page_owner_uid)
279 // find and delete the corresponding item with all the comments and likes/dislikes
281 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
282 intval($page_owner_uid)
284 if (dbm::is_result($r)) {
285 foreach ($r as $rr) {
286 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
287 dbesc(datetime_convert()),
288 dbesc($rr['parent-uri']),
289 intval($page_owner_uid)
291 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
292 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
294 $drop_id = intval($rr['id']);
296 // send the notification upstream/downstream as the case may be
299 proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
303 // Update the photo albums cache
304 photo_albums($page_owner_uid, true);
307 goaway('photos/' . $a->data['user']['nickname']);
308 return; // NOTREACHED
312 // Check if the user has responded to a delete confirmation query for a single photo
313 if (($a->argc > 2) && $_REQUEST['canceled']) {
314 goaway($_SESSION['photo_return']);
317 if (($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
319 // same as above but remove single photo
321 // Check if we should do HTML-based delete confirmation
322 if ($_REQUEST['confirm']) {
323 $drop_url = $a->query_string;
324 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
326 '$message' => t('Do you really want to delete this photo?'),
327 '$extra_inputs' => array(),
328 '$confirm' => t('Delete Photo'),
329 '$confirm_url' => $drop_url,
330 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
331 '$cancel' => t('Cancel'),
333 $a->error = 1; // Set $a->error so the other module functions don't execute
338 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
340 intval($page_owner_uid),
344 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
345 intval(local_user()),
349 if (dbm::is_result($r)) {
350 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
351 intval($page_owner_uid),
352 dbesc($r[0]['resource-id'])
354 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
355 dbesc($r[0]['resource-id']),
356 intval($page_owner_uid)
358 if (dbm::is_result($i)) {
359 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
360 dbesc(datetime_convert()),
361 dbesc(datetime_convert()),
363 intval($page_owner_uid)
365 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
366 delete_thread_uri($i[0]['uri'], $page_owner_uid);
368 $url = App::get_baseurl();
369 $drop_id = intval($i[0]['id']);
371 // Update the photo albums cache
372 photo_albums($page_owner_uid, true);
374 if ($i[0]['visible'])
375 proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
379 goaway('photos/' . $a->data['user']['nickname']);
380 return; // NOTREACHED
383 if (($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
385 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
386 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
387 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
388 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
389 $origaname = ((x($_POST,'origaname')) ? notags(trim($_POST['origaname'])) : '');
390 $str_group_allow = perms2str($_POST['group_allow']);
391 $str_contact_allow = perms2str($_POST['contact_allow']);
392 $str_group_deny = perms2str($_POST['group_deny']);
393 $str_contact_deny = perms2str($_POST['contact_deny']);
395 $resource_id = $a->argv[2];
397 if (! strlen($albname))
398 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
401 if ((x($_POST,'rotate') !== false) &&
402 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
405 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
407 intval($page_owner_uid)
409 if (dbm::is_result($r)) {
410 $ph = new Photo($r[0]['data'], $r[0]['type']);
411 if ($ph->is_valid()) {
412 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
413 $ph->rotate($rotate_deg);
415 $width = $ph->getWidth();
416 $height = $ph->getHeight();
418 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
419 dbesc($ph->imageString()),
423 intval($page_owner_uid)
426 if ($width > 640 || $height > 640) {
427 $ph->scaleImage(640);
428 $width = $ph->getWidth();
429 $height = $ph->getHeight();
431 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
432 dbesc($ph->imageString()),
436 intval($page_owner_uid)
440 if ($width > 320 || $height > 320) {
441 $ph->scaleImage(320);
442 $width = $ph->getWidth();
443 $height = $ph->getHeight();
445 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
446 dbesc($ph->imageString()),
450 intval($page_owner_uid)
457 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
459 intval($page_owner_uid)
462 $ext = $phototypes[$p[0]['type']];
463 $r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
466 dbesc($str_contact_allow),
467 dbesc($str_group_allow),
468 dbesc($str_contact_deny),
469 dbesc($str_group_deny),
471 intval($page_owner_uid)
473 // Update the photo albums cache if album name was changed
474 if ($albname !== $origaname) {
475 photo_albums($page_owner_uid, true);
479 /* Don't make the item visible if the only change was the album name */
482 if ($p[0]['desc'] !== $desc || strlen($rawtags))
487 // Create item container
490 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
493 $arr['guid'] = get_guid(32);
494 $arr['uid'] = $page_owner_uid;
496 $arr['parent-uri'] = $uri;
497 $arr['type'] = 'photo';
499 $arr['resource-id'] = $p[0]['resource-id'];
500 $arr['contact-id'] = $owner_record['id'];
501 $arr['owner-name'] = $owner_record['name'];
502 $arr['owner-link'] = $owner_record['url'];
503 $arr['owner-avatar'] = $owner_record['thumb'];
504 $arr['author-name'] = $owner_record['name'];
505 $arr['author-link'] = $owner_record['url'];
506 $arr['author-avatar'] = $owner_record['thumb'];
507 $arr['title'] = $title;
508 $arr['allow_cid'] = $p[0]['allow_cid'];
509 $arr['allow_gid'] = $p[0]['allow_gid'];
510 $arr['deny_cid'] = $p[0]['deny_cid'];
511 $arr['deny_gid'] = $p[0]['deny_gid'];
512 $arr['last-child'] = 1;
513 $arr['visible'] = $visibility;
516 $arr['body'] = '[url=' . App::get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
517 . '[img]' . App::get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
520 $item_id = item_store($arr);
525 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
527 intval($page_owner_uid)
530 if (dbm::is_result($r)) {
531 $old_tag = $r[0]['tag'];
532 $old_inform = $r[0]['inform'];
535 if (strlen($rawtags)) {
540 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
542 $x = substr($rawtags,0,1);
543 if ($x !== '@' && $x !== '#')
544 $rawtags = '#' . $rawtags;
547 $tags = get_tags($rawtags);
550 foreach ($tags as $tag) {
553 if (strpos($tag,'@') === 0) {
554 $name = substr($tag,1);
555 if ((strpos($name,'@')) || (strpos($name,'http://'))) {
557 $links = @Probe::lrdd($name);
559 foreach ($links as $link) {
560 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
561 $profile = $link['@attributes']['href'];
562 if ($link['@attributes']['rel'] === 'salmon') {
563 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
570 $taginfo[] = array($newname,$profile,$salmon);
575 if (strrpos($newname,'+'))
576 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
579 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
584 $newname = str_replace('_',' ',$name);
586 //select someone from this user's contacts by name
587 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
589 intval($page_owner_uid)
593 //select someone by attag or nick and the name passed in
594 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
597 intval($page_owner_uid)
601 /* elseif (strstr($name,'_') || strstr($name,' ')) {
602 $newname = str_replace('_',' ',$name);
603 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
605 intval($page_owner_uid)
608 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
611 intval($page_owner_uid)
614 if (dbm::is_result($r)) {
615 $newname = $r[0]['name'];
616 $profile = $r[0]['url'];
617 $notify = 'cid:' . $r[0]['id'];
624 if (substr($notify,0,4) === 'cid:')
625 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
627 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
628 if (strlen($str_tags))
630 $profile = str_replace(',','%2c',$profile);
631 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
633 } elseif (strpos($tag,'#') === 0) {
634 $tagname = substr($tag, 1);
635 $str_tags .= '#[url='.App::get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
641 if (strlen($newtag) && strlen($str_tags))
643 $newtag .= $str_tags;
645 $newinform = $old_inform;
646 if (strlen($newinform) && strlen($inform))
648 $newinform .= $inform;
650 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
653 dbesc(datetime_convert()),
654 dbesc(datetime_convert()),
656 intval($page_owner_uid)
658 create_tags_from_item($item_id);
659 update_thread($item_id);
662 foreach ($p as $scales) {
663 if (intval($scales['scale']) == 2) {
667 if (intval($scales['scale']) == 4) {
673 if (count($taginfo)) {
674 foreach ($taginfo as $tagged) {
676 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
679 $arr['guid'] = get_guid(32);
680 $arr['uid'] = $page_owner_uid;
682 $arr['parent-uri'] = $uri;
683 $arr['type'] = 'activity';
685 $arr['contact-id'] = $owner_record['id'];
686 $arr['owner-name'] = $owner_record['name'];
687 $arr['owner-link'] = $owner_record['url'];
688 $arr['owner-avatar'] = $owner_record['thumb'];
689 $arr['author-name'] = $owner_record['name'];
690 $arr['author-link'] = $owner_record['url'];
691 $arr['author-avatar'] = $owner_record['thumb'];
693 $arr['allow_cid'] = $p[0]['allow_cid'];
694 $arr['allow_gid'] = $p[0]['allow_gid'];
695 $arr['deny_cid'] = $p[0]['deny_cid'];
696 $arr['deny_gid'] = $p[0]['deny_gid'];
697 $arr['last-child'] = 1;
699 $arr['verb'] = ACTIVITY_TAG;
700 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
701 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
702 $arr['tag'] = $tagged[4];
703 $arr['inform'] = $tagged[2];
705 $arr['body'] = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
706 $arr['body'] .= "\n\n" . '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . App::get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
708 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
709 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
711 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
712 $arr['object'] .= '</link></object>' . "\n";
714 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
715 . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
716 $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . App::get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
718 $item_id = item_store($arr);
720 proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id);
727 goaway($_SESSION['photo_return']);
728 return; // NOTREACHED
733 * default post action - upload a photo
736 call_hooks('photo_post_init', $_POST);
739 * Determine the album to use
742 $album = notags(trim($_REQUEST['album']));
743 $newalbum = notags(trim($_REQUEST['newalbum']));
745 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
747 if (! strlen($album)) {
748 if (strlen($newalbum))
751 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
756 * We create a wall item for every photo, but we don't want to
757 * overwhelm the data stream with a hundred newly uploaded photos.
758 * So we will make the first photo uploaded to this album in the last several hours
759 * visible by default, the rest will become visible over time when and if
760 * they acquire comments, likes, dislikes, and/or tags
764 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
766 intval($page_owner_uid)
768 if ((! dbm::is_result($r)) || ($album == t('Profile Photos')))
773 if (intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
776 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
777 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
778 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
779 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
781 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
783 call_hooks('photo_post_file',$ret);
785 if (x($ret,'src') && x($ret,'filesize')) {
787 $filename = $ret['filename'];
788 $filesize = $ret['filesize'];
789 $type = $ret['type'];
791 $src = $_FILES['userfile']['tmp_name'];
792 $filename = basename($_FILES['userfile']['name']);
793 $filesize = intval($_FILES['userfile']['size']);
794 $type = $_FILES['userfile']['type'];
796 if ($type=="") $type=guess_image_type($filename);
798 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
800 $maximagesize = get_config('system','maximagesize');
802 if (($maximagesize) && ($filesize > $maximagesize)) {
803 notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
806 call_hooks('photo_post_end',$foo);
811 notice( t('Image file is empty.') . EOL);
814 call_hooks('photo_post_end',$foo);
818 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
820 $imagedata = @file_get_contents($src);
823 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
826 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
827 intval($a->data['user']['uid'])
829 $size = $r[0]['total'];
831 if (($size + strlen($imagedata)) > $limit) {
832 notice( upgrade_message() . EOL );
835 call_hooks('photo_post_end',$foo);
840 $ph = new Photo($imagedata, $type);
842 if (! $ph->is_valid()) {
843 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
844 notice( t('Unable to process image.') . EOL );
847 call_hooks('photo_post_end',$foo);
851 $exif = $ph->orient($src);
854 $max_length = get_config('system','max_image_length');
856 $max_length = MAX_IMAGE_LENGTH;
858 $ph->scaleImage($max_length);
860 $width = $ph->getWidth();
861 $height = $ph->getHeight();
865 $photo_hash = photo_new_resource();
867 $r = $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
870 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
871 notice( t('Image upload failed.') . EOL );
875 if ($width > 640 || $height > 640) {
876 $ph->scaleImage(640);
877 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
881 if ($width > 320 || $height > 320) {
882 $ph->scaleImage(320);
883 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
887 $basename = basename($filename);
888 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
890 // Create item container
894 if ($exif && $exif['GPS']) {
895 if (feature_enabled($channel_id,'photo_location')) {
896 $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
897 $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
904 $arr['coord'] = $lat . ' ' . $lon;
906 $arr['guid'] = get_guid(32);
907 $arr['uid'] = $page_owner_uid;
909 $arr['parent-uri'] = $uri;
910 $arr['type'] = 'photo';
912 $arr['resource-id'] = $photo_hash;
913 $arr['contact-id'] = $owner_record['id'];
914 $arr['owner-name'] = $owner_record['name'];
915 $arr['owner-link'] = $owner_record['url'];
916 $arr['owner-avatar'] = $owner_record['thumb'];
917 $arr['author-name'] = $owner_record['name'];
918 $arr['author-link'] = $owner_record['url'];
919 $arr['author-avatar'] = $owner_record['thumb'];
921 $arr['allow_cid'] = $str_contact_allow;
922 $arr['allow_gid'] = $str_group_allow;
923 $arr['deny_cid'] = $str_contact_deny;
924 $arr['deny_gid'] = $str_group_deny;
925 $arr['last-child'] = 1;
926 $arr['visible'] = $visible;
929 $arr['body'] = '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
930 . '[img]' . App::get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
933 $item_id = item_store($arr);
934 // Update the photo albums cache
935 photo_albums($page_owner_uid, true);
938 proc_run(PRIORITY_HIGH, "include/notifier.php", 'wall-new', $item_id);
940 call_hooks('photo_post_end',intval($item_id));
942 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
943 // if they do not wish to be redirected
945 goaway($_SESSION['photo_return']);
951 function photos_content(App $a) {
955 // photos/name/upload
956 // photos/name/upload/xxxxx (xxxxx is album name)
957 // photos/name/album/xxxxx
958 // photos/name/album/xxxxx/edit
959 // photos/name/image/xxxxx
960 // photos/name/image/xxxxx/edit
963 if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
964 notice( t('Public access denied.') . EOL);
969 require_once('include/bbcode.php');
970 require_once('include/security.php');
971 require_once('include/conversation.php');
973 if (! x($a->data,'user')) {
974 notice( t('No photos selected') . EOL );
978 $phototypes = Photo::supportedTypes();
980 $_SESSION['photo_return'] = $a->cmd;
987 $datatype = $a->argv[2];
988 $datum = $a->argv[3];
989 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload'))
990 $datatype = 'upload';
992 $datatype = 'summary';
1000 // Setup permissions structures
1006 $remote_contact = false;
1009 $owner_uid = $a->data['user']['uid'];
1011 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
1013 if ((local_user()) && (local_user() == $owner_uid))
1016 if ($community_page && remote_user()) {
1017 if (is_array($_SESSION['remote'])) {
1018 foreach ($_SESSION['remote'] as $v) {
1019 if ($v['uid'] == $owner_uid) {
1020 $contact_id = $v['cid'];
1027 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1028 intval($contact_id),
1031 if (dbm::is_result($r)) {
1034 $remote_contact = true;
1035 $visitor = $contact_id;
1041 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1043 if (remote_user() && (! $visitor)) {
1045 if (is_array($_SESSION['remote'])) {
1046 foreach ($_SESSION['remote'] as $v) {
1047 if ($v['uid'] == $owner_uid) {
1048 $contact_id = $v['cid'];
1054 $groups = init_groups_visitor($contact_id);
1055 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1056 intval($contact_id),
1059 if (dbm::is_result($r)) {
1061 $remote_contact = true;
1066 if (! $remote_contact) {
1068 $contact_id = $_SESSION['cid'];
1069 $contact = $a->contact;
1073 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1074 notice( t('Access to this item is restricted.') . EOL);
1078 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
1083 $is_owner = (local_user() && (local_user() == $owner_uid));
1084 $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']);
1087 * Display upload form
1090 if ($datatype === 'upload') {
1091 if (! ($can_post)) {
1092 notice( t('Permission denied.'));
1097 $selname = (($datum) ? hex2bin($datum) : '');
1103 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1104 if (count($a->data['albums'])) {
1105 foreach ($a->data['albums'] as $album) {
1106 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
1108 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1109 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1115 $ret = array('post_url' => 'photos/' . $a->data['user']['nickname'],
1116 'addon_text' => $uploader,
1117 'default_upload' => true);
1120 call_hooks('photo_upload_form',$ret);
1122 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1123 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1124 '$submit' => t('Submit'),
1127 $usage_message = '';
1128 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1129 if ($limit !== false) {
1131 $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1132 intval($a->data['user']['uid'])
1134 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1138 // Private/public post links for the non-JS ACL form
1140 if ($_REQUEST['public'])
1143 $query_str = $a->query_string;
1144 if (strpos($query_str, 'public=1') !== false)
1145 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1147 // I think $a->query_string may never have ? in it, but I could be wrong
1148 // It looks like it's from the index.php?q=[etc] rewrite that the web
1149 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1150 if (strpos($query_str, '?') === false)
1151 $public_post_link = '?public=1';
1153 $public_post_link = '&public=1';
1157 $tpl = get_markup_template('photos_upload.tpl');
1159 if ($a->theme['template_engine'] === 'internal') {
1160 $albumselect_e = template_escape($albumselect);
1161 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
1163 $albumselect_e = $albumselect;
1164 $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
1167 $o .= replace_macros($tpl,array(
1168 '$pagename' => t('Upload Photos'),
1169 '$sessid' => session_id(),
1170 '$usage' => $usage_message,
1171 '$nickname' => $a->data['user']['nickname'],
1172 '$newalbum' => t('New album name: '),
1173 '$existalbumtext' => t('or existing album name: '),
1174 '$nosharetext' => t('Do not show a status post for this upload'),
1175 '$albumselect' => $albumselect_e,
1176 '$permissions' => t('Permissions'),
1177 '$aclselect' => $aclselect_e,
1178 '$alt_uploader' => $ret['addon_text'],
1179 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1180 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1181 '$uploadurl' => $ret['post_url'],
1183 // ACL permissions box
1184 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1185 '$group_perms' => t('Show to Groups'),
1186 '$contact_perms' => t('Show to Contacts'),
1187 '$private' => t('Private Photo'),
1188 '$public' => t('Public Photo'),
1189 '$is_private' => $private_post,
1190 '$return_path' => $query_str,
1191 '$public_link' => $public_post_link,
1199 * Display a single photo album
1202 if ($datatype === 'album') {
1204 $album = hex2bin($datum);
1206 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1207 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1211 if (dbm::is_result($r)) {
1212 $a->set_pager_total(count($r));
1213 $a->set_pager_itemspage(20);
1216 if ($_GET['order'] === 'posted')
1221 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1222 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1225 intval($a->pager['start']),
1226 intval($a->pager['itemspage'])
1230 if ($cmd === 'edit') {
1231 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1233 $edit_tpl = get_markup_template('album_edit.tpl');
1235 if ($a->theme['template_engine'] === 'internal') {
1236 $album_e = template_escape($album);
1241 $o .= replace_macros($edit_tpl,array(
1242 '$nametext' => t('New album name: '),
1243 '$nickname' => $a->data['user']['nickname'],
1244 '$album' => $album_e,
1245 '$hexalbum' => bin2hex($album),
1246 '$submit' => t('Submit'),
1247 '$dropsubmit' => t('Delete Album')
1252 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1254 $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1259 if ($_GET['order'] === 'posted')
1260 $order = array(t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1262 $order = array(t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1266 if (dbm::is_result($r))
1267 $twist = 'rotright';
1268 foreach ($r as $rr) {
1269 if ($twist == 'rotright')
1272 $twist = 'rotright';
1274 $ext = $phototypes[$rr['type']];
1276 if ($a->theme['template_engine'] === 'internal') {
1277 $imgalt_e = template_escape($rr['filename']);
1278 $desc_e = template_escape($rr['desc']);
1280 $imgalt_e = $rr['filename'];
1281 $desc_e = $rr['desc'];
1286 'twist' => ' ' . $twist . rand(2,4),
1287 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1288 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1289 'title' => t('View Photo'),
1290 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1294 'hash'=> $rr['resource_id'],
1298 $tpl = get_markup_template('photo_album.tpl');
1299 $o .= replace_macros($tpl, array(
1300 '$photos' => $photos,
1302 '$can_post' => $can_post,
1303 '$upload' => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1306 '$paginate' => paginate($a),
1317 if ($datatype === 'image') {
1320 // fetch image, item containing image, then comments
1322 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1323 $sql_extra ORDER BY `scale` ASC ",
1329 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1335 notice( t('Permission denied. Access to this item may be restricted.'));
1337 notice( t('Photo not available') . EOL );
1344 /// @todo This query is totally bad, the whole functionality has to be changed
1345 // The query leads to a really intense used index.
1346 // By now we hide it if someone wants to.
1347 if (!Config::get('system', 'no_count', false)) {
1348 if ($_GET['order'] === 'posted')
1353 $prvnxt = qu("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1354 $sql_extra ORDER BY `created` $order ",
1355 dbesc($ph[0]['album']),
1359 if (count($prvnxt)) {
1360 for($z = 0; $z < count($prvnxt); $z++) {
1361 if ($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1365 $prv = count($prvnxt) - 1;
1366 if ($nxt >= count($prvnxt))
1371 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1372 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1373 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1377 if (count($ph) == 1)
1378 $hires = $lores = $ph[0];
1379 if (count($ph) > 1) {
1380 if ($ph[1]['scale'] == 2) {
1381 // original is 640 or less, we can display it directly
1382 $hires = $lores = $ph[0];
1389 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1393 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1395 'edit' => array('photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1396 'profile'=>array('profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1400 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1401 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1402 ? t('Private Message')
1408 if ( $cmd === 'edit') {
1409 $tpl = get_markup_template('photo_edit_head.tpl');
1410 $a->page['htmlhead'] .= replace_macros($tpl,array(
1411 '$prevlink' => $prevlink,
1412 '$nextlink' => $nextlink
1417 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1420 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1421 'title'=> t('View Full Size'),
1422 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1423 'height' => $hires['height'],
1424 'width' => $hires['width'],
1425 'album' => $hires['album'],
1426 'filename' => $hires['filename'],
1430 $nextlink = array($nextlink, '<div class="icon next"></div>');
1433 // Do we have an item for this photo?
1435 // FIXME! - replace following code to display the conversation with our normal
1436 // conversation functions so that it works correctly and tracks changes
1437 // in the evolving conversation code.
1438 // The difference is that we won't be displaying the conversation head item
1439 // as a "post" but displaying instead the photo it is linked to
1441 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1447 if (count($linked_items)) {
1448 $link_item = $linked_items[0];
1449 $r = qu("SELECT COUNT(*) AS `total`
1450 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1451 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1452 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1453 AND `item`.`uid` = %d
1455 dbesc($link_item['uri']),
1456 dbesc($link_item['uri']),
1457 intval($link_item['uid'])
1461 if (dbm::is_result($r))
1462 $a->set_pager_total($r[0]['total']);
1465 $r = qu("SELECT `item`.*, `item`.`id` AS `item_id`,
1466 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1467 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1468 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1469 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1470 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1471 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1472 AND `item`.`uid` = %d
1474 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1475 dbesc($link_item['uri']),
1476 dbesc($link_item['uri']),
1477 intval($link_item['uid']),
1478 intval($a->pager['start']),
1479 intval($a->pager['itemspage'])
1483 if ((local_user()) && (local_user() == $link_item['uid'])) {
1484 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1485 intval($link_item['parent']),
1486 intval(local_user())
1488 update_thread($link_item['parent']);
1491 if ($link_item['coord']) {
1492 $map = generate_map($link_item['coord']);
1498 if (count($linked_items) && strlen($link_item['tag'])) {
1499 $arr = explode(',',$link_item['tag']);
1500 // parse tags and add links
1502 foreach ($arr as $t) {
1503 if (strlen($tag_str))
1505 $tag_str .= bbcode($t);
1507 $tags = array(t('Tags: '), $tag_str);
1508 if ($cmd === 'edit') {
1509 $tags[] = 'tagrm/' . $link_item['id'];
1510 $tags[] = t('[Remove any tag]');
1516 if (($cmd === 'edit') && ($can_post)) {
1517 $edit_tpl = get_markup_template('photo_edit.tpl');
1519 // Private/public post links for the non-JS ACL form
1521 if ($_REQUEST['public'])
1524 $query_str = $a->query_string;
1525 if (strpos($query_str, 'public=1') !== false)
1526 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1528 // I think $a->query_string may never have ? in it, but I could be wrong
1529 // It looks like it's from the index.php?q=[etc] rewrite that the web
1530 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1531 if (strpos($query_str, '?') === false)
1532 $public_post_link = '?public=1';
1534 $public_post_link = '&public=1';
1537 if ($a->theme['template_engine'] === 'internal') {
1538 $album_e = template_escape($ph[0]['album']);
1539 $caption_e = template_escape($ph[0]['desc']);
1540 $aclselect_e = template_escape(populate_acl($ph[0]));
1542 $album_e = $ph[0]['album'];
1543 $caption_e = $ph[0]['desc'];
1544 $aclselect_e = populate_acl($ph[0]);
1547 $edit = replace_macros($edit_tpl, array(
1548 '$id' => $ph[0]['id'],
1549 '$album' => array('albname', t('New album name'), $album_e,''),
1550 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1551 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1552 '$rotate_none' => array('rotate',t('Do not rotate'),0,'', true),
1553 '$rotate_cw' => array('rotate',t('Rotate CW (right)'),1,''),
1554 '$rotate_ccw' => array('rotate',t('Rotate CCW (left)'),2,''),
1556 '$nickname' => $a->data['user']['nickname'],
1557 '$resource_id' => $ph[0]['resource-id'],
1558 '$permissions' => t('Permissions'),
1559 '$aclselect' => $aclselect_e,
1561 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1562 '$submit' => t('Submit'),
1563 '$delete' => t('Delete Photo'),
1565 // ACL permissions box
1566 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1567 '$group_perms' => t('Show to Groups'),
1568 '$contact_perms' => t('Show to Contacts'),
1569 '$private' => t('Private photo'),
1570 '$public' => t('Public photo'),
1571 '$is_private' => $private_post,
1572 '$return_path' => $query_str,
1573 '$public_link' => $public_post_link,
1577 if (count($linked_items)) {
1579 $cmnt_tpl = get_markup_template('comment_item.tpl');
1580 $tpl = get_markup_template('photo_item.tpl');
1581 $return_url = $a->cmd;
1583 $like_tpl = get_markup_template('like_noshare.tpl');
1587 if ($can_post || can_write_wall($a,$owner_uid)) {
1588 $likebuttons = replace_macros($like_tpl,array(
1589 '$id' => $link_item['id'],
1590 '$likethis' => t("I like this \x28toggle\x29"),
1591 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1592 '$wait' => t('Please wait'),
1593 '$return_path' => $a->query_string,
1598 if (! dbm::is_result($r)) {
1599 if ($can_post || can_write_wall($a,$owner_uid)) {
1600 if ($link_item['last-child']) {
1601 $comments .= replace_macros($cmnt_tpl,array(
1602 '$return_path' => '',
1603 '$jsreload' => $return_url,
1604 '$type' => 'wall-comment',
1605 '$id' => $link_item['id'],
1606 '$parent' => $link_item['id'],
1607 '$profile_uid' => $owner_uid,
1608 '$mylink' => $contact['url'],
1609 '$mytitle' => t('This is you'),
1610 '$myphoto' => $contact['thumb'],
1611 '$comment' => t('Comment'),
1612 '$submit' => t('Submit'),
1613 '$preview' => t('Preview'),
1614 '$sourceapp' => t($a->sourcename),
1616 '$rand_num' => random_digits(12)
1628 $conv_responses = array(
1629 'like' => array('title' => t('Likes','title')),'dislike' => array('title' => t('Dislikes','title')),
1630 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
1636 if (dbm::is_result($r)) {
1638 foreach ($r as $item) {
1639 builtin_activity_puller($item, $conv_responses);
1642 $like = ((x($conv_responses['like'],$link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']],$conv_responses['like'][$link_item['uri'] . '-l'],'like',$link_item['id']) : '');
1643 $dislike = ((x($conv_responses['dislike'],$link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']],$conv_responses['dislike'][$link_item['uri'] . '-l'],'dislike',$link_item['id']) : '');
1647 if ($can_post || can_write_wall($a,$owner_uid)) {
1648 if ($link_item['last-child']) {
1649 $comments .= replace_macros($cmnt_tpl,array(
1650 '$return_path' => '',
1651 '$jsreload' => $return_url,
1652 '$type' => 'wall-comment',
1653 '$id' => $link_item['id'],
1654 '$parent' => $link_item['id'],
1655 '$profile_uid' => $owner_uid,
1656 '$mylink' => $contact['url'],
1657 '$mytitle' => t('This is you'),
1658 '$myphoto' => $contact['thumb'],
1659 '$comment' => t('Comment'),
1660 '$submit' => t('Submit'),
1661 '$preview' => t('Preview'),
1662 '$sourceapp' => t($a->sourcename),
1664 '$rand_num' => random_digits(12)
1670 foreach ($r as $item) {
1675 if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1678 $redirect_url = 'redir/' . $item['cid'] ;
1681 if (local_user() && ($item['contact-uid'] == local_user())
1682 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1683 $profile_url = $redirect_url;
1684 $sparkle = ' sparkle';
1686 $profile_url = $item['url'];
1690 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1692 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1693 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1695 $profile_link = $profile_url;
1699 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1701 'dropping' => $dropping,
1702 'pagedrop' => false,
1703 'select' => t('Select'),
1704 'delete' => t('Delete'),
1708 if ($a->theme['template_engine'] === 'internal') {
1709 $name_e = template_escape($profile_name);
1710 $title_e = template_escape($item['title']);
1711 $body_e = template_escape(bbcode($item['body']));
1713 $name_e = $profile_name;
1714 $title_e = $item['title'];
1715 $body_e = bbcode($item['body']);
1718 $comments .= replace_macros($template,array(
1719 '$id' => $item['item_id'],
1720 '$profile_url' => $profile_link,
1722 '$thumb' => $profile_avatar,
1723 '$sparkle' => $sparkle,
1724 '$title' => $title_e,
1726 '$ago' => relative_date($item['created']),
1727 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1729 '$comment' => $comment
1732 if ($can_post || can_write_wall($a,$owner_uid)) {
1734 if ($item['last-child']) {
1735 $comments .= replace_macros($cmnt_tpl,array(
1736 '$return_path' => '',
1737 '$jsreload' => $return_url,
1738 '$type' => 'wall-comment',
1739 '$id' => $item['item_id'],
1740 '$parent' => $item['parent'],
1741 '$profile_uid' => $owner_uid,
1742 '$mylink' => $contact['url'],
1743 '$mytitle' => t('This is you'),
1744 '$myphoto' => $contact['thumb'],
1745 '$comment' => t('Comment'),
1746 '$submit' => t('Submit'),
1747 '$preview' => t('Preview'),
1748 '$sourceapp' => t($a->sourcename),
1750 '$rand_num' => random_digits(12)
1757 $paginate = paginate($a);
1761 $response_verbs = array('like');
1762 if (feature_enabled($owner_uid,'dislike'))
1763 $response_verbs[] = 'dislike';
1764 $responses = get_responses($conv_responses,$response_verbs,'',$link_item);
1766 $photo_tpl = get_markup_template('photo_view.tpl');
1768 if ($a->theme['template_engine'] === 'internal') {
1769 $album_e = array($album_link,template_escape($ph[0]['album']));
1770 $tags_e = template_escape($tags);
1771 $like_e = template_escape($like);
1772 $dislike_e = template_escape($dislike);
1774 $album_e = array($album_link,$ph[0]['album']);
1777 $dislike_e = $dislike;
1780 $o .= replace_macros($photo_tpl, array(
1781 '$id' => $ph[0]['id'],
1782 '$album' => $album_e,
1786 '$prevlink' => $prevlink,
1787 '$nextlink' => $nextlink,
1788 '$desc' => $ph[0]['desc'],
1792 '$map_text' => t('Map'),
1793 '$likebuttons' => $likebuttons,
1795 '$dislike' => $dikslike_e,
1796 'responses' => $responses,
1797 '$comments' => $comments,
1798 '$paginate' => $paginate,
1801 $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
1802 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
1803 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
1804 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
1805 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
1810 // Default - show recent photos with upload link (if applicable)
1813 $r = qu("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1814 $sql_extra GROUP BY `resource-id`",
1815 intval($a->data['user']['uid']),
1816 dbesc('Contact Photos'),
1817 dbesc( t('Contact Photos'))
1819 if (dbm::is_result($r)) {
1820 $a->set_pager_total(count($r));
1821 $a->set_pager_itemspage(20);
1824 $r = qu("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
1825 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1826 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1827 intval($a->data['user']['uid']),
1828 dbesc('Contact Photos'),
1829 dbesc( t('Contact Photos')),
1830 intval($a->pager['start']),
1831 intval($a->pager['itemspage'])
1835 if (dbm::is_result($r)) {
1836 $twist = 'rotright';
1837 foreach ($r as $rr) {
1838 //hide profile photos to others
1839 if ((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
1842 if ($twist == 'rotright')
1845 $twist = 'rotright';
1847 $ext = $phototypes[$rr['type']];
1849 if ($a->theme['template_engine'] === 'internal') {
1850 $alt_e = template_escape($rr['filename']);
1851 $name_e = template_escape($rr['album']);
1853 $alt_e = $rr['filename'];
1854 $name_e = $rr['album'];
1859 'twist' => ' ' . $twist . rand(2,4),
1860 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1861 'title' => t('View Photo'),
1862 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1865 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1867 'alt' => t('View Album'),
1874 $tpl = get_markup_template('photos_recent.tpl');
1875 $o .= replace_macros($tpl, array(
1876 '$title' => t('Recent Photos'),
1877 '$can_post' => $can_post,
1878 '$upload' => array(t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'),
1879 '$photos' => $photos,
1880 '$paginate' => paginate($a),