4 use Friendica\Core\System;
5 use Friendica\Core\Config;
6 use Friendica\Core\Worker;
7 use Friendica\Database\DBM;
8 use Friendica\Network\Probe;
9 use Friendica\Object\Contact;
11 require_once 'include/Photo.php';
12 require_once 'include/photos.php';
13 require_once 'include/items.php';
14 require_once 'include/acl_selectors.php';
15 require_once 'include/bbcode.php';
16 require_once 'include/security.php';
17 require_once 'include/redir.php';
18 require_once 'include/tags.php';
19 require_once 'include/threads.php';
21 function photos_init(App $a) {
24 auto_redir($a, $a->argv[1]);
27 if ((Config::get('system', 'block_public')) && (! local_user()) && (! remote_user())) {
31 nav_set_selected('home');
35 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
39 if (! DBM::is_result($user)) {
43 $a->data['user'] = $user[0];
44 $a->profile_uid = $user[0]['uid'];
45 $is_owner = (local_user() && (local_user() == $a->profile_uid));
47 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
49 $account_type = Contact::getAccountType($profile);
51 $tpl = get_markup_template("vcard-widget.tpl");
53 $vcard_widget .= replace_macros($tpl, array(
54 '$name' => $profile['name'],
55 '$photo' => $profile['photo'],
56 '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
57 '$account_type' => $account_type,
58 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
61 $albums = photo_albums($a->data['user']['uid']);
63 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
65 // add various encodings to the array so we can just loop through and pick them out in a template
66 $ret = array('success' => false);
69 $a->data['albums'] = $albums;
70 if ($albums_visible) {
71 $ret['success'] = true;
74 $ret['albums'] = array();
75 foreach ($albums as $k => $album) {
76 //hide profile photos to others
77 if ((! $is_owner) && (! remote_user()) && ($album['album'] == t('Profile Photos')))
80 'text' => $album['album'],
81 'total' => $album['total'],
82 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
83 'urlencode' => urlencode($album['album']),
84 'bin2hex' => bin2hex($album['album'])
86 $ret['albums'][] = $entry;
92 if (local_user() && $a->data['user']['uid'] == local_user()) {
96 if ($albums['success']) {
97 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), array(
98 '$nick' => $a->data['user']['nickname'],
99 '$title' => t('Photo Albums'),
100 '$recent' => t('Recent Photos'),
101 '$albums' => $albums['albums'],
102 '$baseurl' => System::baseUrl(),
103 '$upload' => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'),
104 '$can_post' => $can_post
109 if (! x($a->page, 'aside')) {
110 $a->page['aside'] = '';
112 $a->page['aside'] .= $vcard_widget;
113 $a->page['aside'] .= $photo_albums_widget;
116 $tpl = get_markup_template("photos_head.tpl");
117 $a->page['htmlhead'] .= replace_macros($tpl,array(
118 '$ispublic' => t('everybody')
128 function photos_post(App $a) {
130 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
133 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
134 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
136 $phototypes = Photo::supportedTypes();
141 $page_owner_uid = $a->data['user']['uid'];
142 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
144 if ((local_user()) && (local_user() == $page_owner_uid)) {
147 if ($community_page && remote_user()) {
149 if (is_array($_SESSION['remote'])) {
150 foreach ($_SESSION['remote'] as $v) {
151 if ($v['uid'] == $page_owner_uid) {
152 $contact_id = $v['cid'];
159 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
161 intval($page_owner_uid)
163 if (DBM::is_result($r)) {
165 $visitor = $contact_id;
172 notice( t('Permission denied.') . EOL );
176 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
177 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
178 intval($page_owner_uid)
181 if (! DBM::is_result($r)) {
182 notice( t('Contact information unavailable') . EOL);
183 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
187 $owner_record = $r[0];
190 if (($a->argc > 3) && ($a->argv[2] === 'album')) {
191 $album = hex2bin($a->argv[3]);
193 if ($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
194 goaway($_SESSION['photo_return']);
195 return; // NOTREACHED
198 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
200 intval($page_owner_uid)
202 if (!DBM::is_result($r)) {
203 notice( t('Album not found.') . EOL);
204 goaway($_SESSION['photo_return']);
205 return; // NOTREACHED
208 // Check if the user has responded to a delete confirmation query
209 if ($_REQUEST['canceled']) {
210 goaway($_SESSION['photo_return']);
217 $newalbum = notags(trim($_POST['albumname']));
218 if ($newalbum != $album) {
219 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
222 intval($page_owner_uid)
224 // Update the photo albums cache
225 photo_albums($page_owner_uid, true);
227 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
229 return; // NOTREACHED
233 * DELETE photo album and all its photos
236 if ($_POST['dropalbum'] == t('Delete Album')) {
238 // Check if we should do HTML-based delete confirmation
239 if ($_REQUEST['confirm']) {
240 $drop_url = $a->query_string;
241 $extra_inputs = array(
242 array('name' => 'albumname', 'value' => $_POST['albumname']),
244 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
246 '$message' => t('Do you really want to delete this photo album and all its photos?'),
247 '$extra_inputs' => $extra_inputs,
248 '$confirm' => t('Delete Album'),
249 '$confirm_url' => $drop_url,
250 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
251 '$cancel' => t('Cancel'),
253 $a->error = 1; // Set $a->error so the other module functions don't execute
259 // get the list of photos we are about to delete
262 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
264 intval($page_owner_uid),
268 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
269 intval(local_user()),
273 if (DBM::is_result($r)) {
274 foreach ($r as $rr) {
275 $res[] = "'" . dbesc($rr['rid']) . "'" ;
278 goaway($_SESSION['photo_return']);
279 return; // NOTREACHED
282 $str_res = implode(',', $res);
284 // remove the associated photos
286 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
287 intval($page_owner_uid)
290 // find and delete the corresponding item with all the comments and likes/dislikes
292 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
293 intval($page_owner_uid)
295 if (DBM::is_result($r)) {
296 foreach ($r as $rr) {
297 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
298 dbesc(datetime_convert()),
299 dbesc($rr['parent-uri']),
300 intval($page_owner_uid)
302 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
303 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
305 $drop_id = intval($rr['id']);
307 // send the notification upstream/downstream as the case may be
309 if ($rr['visible']) {
310 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
315 // Update the photo albums cache
316 photo_albums($page_owner_uid, true);
319 goaway('photos/' . $a->data['user']['nickname']);
320 return; // NOTREACHED
324 // Check if the user has responded to a delete confirmation query for a single photo
325 if (($a->argc > 2) && $_REQUEST['canceled']) {
326 goaway($_SESSION['photo_return']);
329 if (($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
331 // same as above but remove single photo
333 // Check if we should do HTML-based delete confirmation
334 if ($_REQUEST['confirm']) {
335 $drop_url = $a->query_string;
336 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
338 '$message' => t('Do you really want to delete this photo?'),
339 '$extra_inputs' => array(),
340 '$confirm' => t('Delete Photo'),
341 '$confirm_url' => $drop_url,
342 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
343 '$cancel' => t('Cancel'),
345 $a->error = 1; // Set $a->error so the other module functions don't execute
350 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
352 intval($page_owner_uid),
356 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
357 intval(local_user()),
361 if (DBM::is_result($r)) {
362 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
363 intval($page_owner_uid),
364 dbesc($r[0]['resource-id'])
366 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
367 dbesc($r[0]['resource-id']),
368 intval($page_owner_uid)
370 if (DBM::is_result($i)) {
371 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
372 dbesc(datetime_convert()),
373 dbesc(datetime_convert()),
375 intval($page_owner_uid)
377 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
378 delete_thread_uri($i[0]['uri'], $page_owner_uid);
380 $url = System::baseUrl();
381 $drop_id = intval($i[0]['id']);
383 // Update the photo albums cache
384 photo_albums($page_owner_uid, true);
386 if ($i[0]['visible']) {
387 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
392 goaway('photos/' . $a->data['user']['nickname']);
393 return; // NOTREACHED
396 if (($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
398 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
399 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
400 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
401 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
402 $origaname = ((x($_POST,'origaname')) ? notags(trim($_POST['origaname'])) : '');
403 $str_group_allow = perms2str($_POST['group_allow']);
404 $str_contact_allow = perms2str($_POST['contact_allow']);
405 $str_group_deny = perms2str($_POST['group_deny']);
406 $str_contact_deny = perms2str($_POST['contact_deny']);
408 $resource_id = $a->argv[2];
410 if (! strlen($albname)) {
411 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
415 if ((x($_POST,'rotate') !== false) &&
416 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
419 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
421 intval($page_owner_uid)
423 if (DBM::is_result($r)) {
424 $ph = new Photo($r[0]['data'], $r[0]['type']);
425 if ($ph->is_valid()) {
426 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
427 $ph->rotate($rotate_deg);
429 $width = $ph->getWidth();
430 $height = $ph->getHeight();
432 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
433 dbesc($ph->imageString()),
437 intval($page_owner_uid)
440 if ($width > 640 || $height > 640) {
441 $ph->scaleImage(640);
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` = 1",
446 dbesc($ph->imageString()),
450 intval($page_owner_uid)
454 if ($width > 320 || $height > 320) {
455 $ph->scaleImage(320);
456 $width = $ph->getWidth();
457 $height = $ph->getHeight();
459 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
460 dbesc($ph->imageString()),
464 intval($page_owner_uid)
471 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
473 intval($page_owner_uid)
475 if (DBM::is_result($p)) {
476 $ext = $phototypes[$p[0]['type']];
477 $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",
480 dbesc($str_contact_allow),
481 dbesc($str_group_allow),
482 dbesc($str_contact_deny),
483 dbesc($str_group_deny),
485 intval($page_owner_uid)
488 // Update the photo albums cache if album name was changed
489 if ($albname !== $origaname) {
490 photo_albums($page_owner_uid, true);
494 /* Don't make the item visible if the only change was the album name */
497 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
503 // Create item container
506 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
509 $arr['guid'] = get_guid(32);
510 $arr['uid'] = $page_owner_uid;
512 $arr['parent-uri'] = $uri;
513 $arr['type'] = 'photo';
515 $arr['resource-id'] = $p[0]['resource-id'];
516 $arr['contact-id'] = $owner_record['id'];
517 $arr['owner-name'] = $owner_record['name'];
518 $arr['owner-link'] = $owner_record['url'];
519 $arr['owner-avatar'] = $owner_record['thumb'];
520 $arr['author-name'] = $owner_record['name'];
521 $arr['author-link'] = $owner_record['url'];
522 $arr['author-avatar'] = $owner_record['thumb'];
523 $arr['title'] = $title;
524 $arr['allow_cid'] = $p[0]['allow_cid'];
525 $arr['allow_gid'] = $p[0]['allow_gid'];
526 $arr['deny_cid'] = $p[0]['deny_cid'];
527 $arr['deny_gid'] = $p[0]['deny_gid'];
528 $arr['last-child'] = 1;
529 $arr['visible'] = $visibility;
532 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
533 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
536 $item_id = item_store($arr);
541 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
543 intval($page_owner_uid)
546 if (DBM::is_result($r)) {
547 $old_tag = $r[0]['tag'];
548 $old_inform = $r[0]['inform'];
551 if (strlen($rawtags)) {
556 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
558 $x = substr($rawtags,0,1);
559 if ($x !== '@' && $x !== '#') {
560 $rawtags = '#' . $rawtags;
564 $tags = get_tags($rawtags);
567 foreach ($tags as $tag) {
568 if (isset($profile)) {
571 if (strpos($tag, '@') === 0) {
572 $name = substr($tag,1);
573 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
575 $links = @Probe::lrdd($name);
577 foreach ($links as $link) {
578 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
579 $profile = $link['@attributes']['href'];
581 if ($link['@attributes']['rel'] === 'salmon') {
582 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
583 if (strlen($inform)) {
590 $taginfo[] = array($newname, $profile, $salmon);
595 if (strrpos($newname, '+')) {
596 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
600 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
605 $newname = str_replace('_',' ',$name);
607 //select someone from this user's contacts by name
608 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
610 intval($page_owner_uid)
613 if (! DBM::is_result($r)) {
614 //select someone by attag or nick and the name passed in
615 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
618 intval($page_owner_uid)
623 if (DBM::is_result($r)) {
624 $newname = $r[0]['name'];
625 $profile = $r[0]['url'];
626 $notify = 'cid:' . $r[0]['id'];
627 if (strlen($inform)) {
634 if (substr($notify, 0, 4) === 'cid:') {
635 $taginfo[] = array($newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
637 $taginfo[] = array($newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
639 if (strlen($str_tags)) {
642 $profile = str_replace(',', '%2c', $profile);
643 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
645 } elseif (strpos($tag, '#') === 0) {
646 $tagname = substr($tag, 1);
647 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
653 if (strlen($newtag) && strlen($str_tags)) {
656 $newtag .= $str_tags;
658 $newinform = $old_inform;
659 if (strlen($newinform) && strlen($inform)) {
662 $newinform .= $inform;
664 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
667 dbesc(datetime_convert()),
668 dbesc(datetime_convert()),
670 intval($page_owner_uid)
672 create_tags_from_item($item_id);
673 update_thread($item_id);
676 foreach ($p as $scales) {
677 if (intval($scales['scale']) == 2) {
681 if (intval($scales['scale']) == 4) {
687 if (count($taginfo)) {
688 foreach ($taginfo as $tagged) {
690 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
693 $arr['guid'] = get_guid(32);
694 $arr['uid'] = $page_owner_uid;
696 $arr['parent-uri'] = $uri;
697 $arr['type'] = 'activity';
699 $arr['contact-id'] = $owner_record['id'];
700 $arr['owner-name'] = $owner_record['name'];
701 $arr['owner-link'] = $owner_record['url'];
702 $arr['owner-avatar'] = $owner_record['thumb'];
703 $arr['author-name'] = $owner_record['name'];
704 $arr['author-link'] = $owner_record['url'];
705 $arr['author-avatar'] = $owner_record['thumb'];
707 $arr['allow_cid'] = $p[0]['allow_cid'];
708 $arr['allow_gid'] = $p[0]['allow_gid'];
709 $arr['deny_cid'] = $p[0]['deny_cid'];
710 $arr['deny_gid'] = $p[0]['deny_gid'];
711 $arr['last-child'] = 1;
713 $arr['verb'] = ACTIVITY_TAG;
714 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
715 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
716 $arr['tag'] = $tagged[4];
717 $arr['inform'] = $tagged[2];
719 $arr['body'] = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
720 $arr['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . System::baseUrl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
722 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
723 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
725 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
727 $arr['object'] .= '</link></object>' . "\n";
729 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
730 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
731 $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . System::baseUrl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
733 $item_id = item_store($arr);
735 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
740 goaway($_SESSION['photo_return']);
741 return; // NOTREACHED
746 * default post action - upload a photo
749 call_hooks('photo_post_init', $_POST);
752 * Determine the album to use
755 $album = notags(trim($_REQUEST['album']));
756 $newalbum = notags(trim($_REQUEST['newalbum']));
758 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
760 if (! strlen($album)) {
761 if (strlen($newalbum)) {
764 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
769 * We create a wall item for every photo, but we don't want to
770 * overwhelm the data stream with a hundred newly uploaded photos.
771 * So we will make the first photo uploaded to this album in the last several hours
772 * visible by default, the rest will become visible over time when and if
773 * they acquire comments, likes, dislikes, and/or tags
776 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
778 intval($page_owner_uid)
780 if ((! DBM::is_result($r)) || ($album == t('Profile Photos'))) {
786 if (intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true') {
790 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',', $_REQUEST['group_allow'])));
791 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',', $_REQUEST['contact_allow'])));
792 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',', $_REQUEST['group_deny'])));
793 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',', $_REQUEST['contact_deny'])));
795 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
797 call_hooks('photo_post_file',$ret);
799 if (x($ret,'src') && x($ret,'filesize')) {
801 $filename = $ret['filename'];
802 $filesize = $ret['filesize'];
803 $type = $ret['type'];
805 $src = $_FILES['userfile']['tmp_name'];
806 $filename = basename($_FILES['userfile']['name']);
807 $filesize = intval($_FILES['userfile']['size']);
808 $type = $_FILES['userfile']['type'];
811 $type = guess_image_type($filename);
814 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
816 $maximagesize = Config::get('system','maximagesize');
818 if (($maximagesize) && ($filesize > $maximagesize)) {
819 notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
822 call_hooks('photo_post_end',$foo);
827 notice( t('Image file is empty.') . EOL);
830 call_hooks('photo_post_end',$foo);
834 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
836 $imagedata = @file_get_contents($src);
838 $ph = new Photo($imagedata, $type);
840 if (! $ph->is_valid()) {
841 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
842 notice( t('Unable to process image.') . EOL );
845 call_hooks('photo_post_end',$foo);
849 $exif = $ph->orient($src);
852 $max_length = Config::get('system', 'max_image_length');
854 $max_length = MAX_IMAGE_LENGTH;
856 if ($max_length > 0) {
857 $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 /// @TODO merge these 2 if() into one?
895 if ($exif && $exif['GPS']) {
896 if (feature_enabled($channel_id,'photo_location')) {
897 $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
898 $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
905 $arr['coord'] = $lat . ' ' . $lon;
908 $arr['guid'] = get_guid(32);
909 $arr['uid'] = $page_owner_uid;
911 $arr['parent-uri'] = $uri;
912 $arr['type'] = 'photo';
914 $arr['resource-id'] = $photo_hash;
915 $arr['contact-id'] = $owner_record['id'];
916 $arr['owner-name'] = $owner_record['name'];
917 $arr['owner-link'] = $owner_record['url'];
918 $arr['owner-avatar'] = $owner_record['thumb'];
919 $arr['author-name'] = $owner_record['name'];
920 $arr['author-link'] = $owner_record['url'];
921 $arr['author-avatar'] = $owner_record['thumb'];
923 $arr['allow_cid'] = $str_contact_allow;
924 $arr['allow_gid'] = $str_group_allow;
925 $arr['deny_cid'] = $str_contact_deny;
926 $arr['deny_gid'] = $str_group_deny;
927 $arr['last-child'] = 1;
928 $arr['visible'] = $visible;
931 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
932 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
935 $item_id = item_store($arr);
936 // Update the photo albums cache
937 photo_albums($page_owner_uid, true);
940 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
943 call_hooks('photo_post_end',intval($item_id));
946 * addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
947 * if they do not wish to be redirected
950 goaway($_SESSION['photo_return']);
954 function photos_content(App $a) {
958 // photos/name/upload
959 // photos/name/upload/xxxxx (xxxxx is album name)
960 // photos/name/album/xxxxx
961 // photos/name/album/xxxxx/edit
962 // photos/name/image/xxxxx
963 // photos/name/image/xxxxx/edit
966 if ((Config::get('system', 'block_public')) && (! local_user()) && (! remote_user())) {
967 notice( t('Public access denied.') . EOL);
971 require_once 'include/bbcode.php';
972 require_once 'include/security.php';
973 require_once 'include/conversation.php';
975 if (! x($a->data,'user')) {
976 notice( t('No photos selected') . EOL );
980 $phototypes = Photo::supportedTypes();
982 $_SESSION['photo_return'] = $a->cmd;
989 $datatype = $a->argv[2];
990 $datum = $a->argv[3];
991 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
992 $datatype = 'upload';
994 $datatype = 'summary';
1004 // Setup permissions structures
1010 $remote_contact = false;
1013 $owner_uid = $a->data['user']['uid'];
1015 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
1017 if ((local_user()) && (local_user() == $owner_uid)) {
1020 if ($community_page && remote_user()) {
1021 if (is_array($_SESSION['remote'])) {
1022 foreach ($_SESSION['remote'] as $v) {
1023 if ($v['uid'] == $owner_uid) {
1024 $contact_id = $v['cid'];
1031 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1032 intval($contact_id),
1035 if (DBM::is_result($r)) {
1038 $remote_contact = true;
1039 $visitor = $contact_id;
1045 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1047 if (remote_user() && (! $visitor)) {
1049 if (is_array($_SESSION['remote'])) {
1050 foreach ($_SESSION['remote'] as $v) {
1051 if ($v['uid'] == $owner_uid) {
1052 $contact_id = $v['cid'];
1058 $groups = init_groups_visitor($contact_id);
1059 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1060 intval($contact_id),
1063 if (DBM::is_result($r)) {
1065 $remote_contact = true;
1070 /// @TODO merge these 2 if() into one?
1071 if (! $remote_contact) {
1073 $contact_id = $_SESSION['cid'];
1074 $contact = $a->contact;
1078 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1079 notice( t('Access to this item is restricted.') . EOL);
1083 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
1088 $is_owner = (local_user() && (local_user() == $owner_uid));
1089 $o .= profile_tabs($a, $is_owner, $a->data['user']['nickname']);
1092 * Display upload form
1095 if ($datatype === 'upload') {
1096 if (! ($can_post)) {
1097 notice(t('Permission denied.'));
1102 $selname = (($datum) ? hex2bin($datum) : '');
1108 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1109 if (count($a->data['albums'])) {
1110 foreach ($a->data['albums'] as $album) {
1111 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos'))) {
1114 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1115 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1121 $ret = array('post_url' => 'photos/' . $a->data['user']['nickname'],
1122 'addon_text' => $uploader,
1123 'default_upload' => true);
1125 call_hooks('photo_upload_form',$ret);
1127 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1128 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1129 '$submit' => t('Submit'),
1132 $usage_message = '';
1134 // Private/public post links for the non-JS ACL form
1136 if ($_REQUEST['public']) {
1140 $query_str = $a->query_string;
1141 if (strpos($query_str, 'public=1') !== false) {
1142 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1146 * I think $a->query_string may never have ? in it, but I could be wrong
1147 * It looks like it's from the index.php?q=[etc] rewrite that the web
1148 * 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';
1156 $tpl = get_markup_template('photos_upload.tpl');
1158 $albumselect_e = $albumselect;
1159 $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
1161 $o .= replace_macros($tpl,array(
1162 '$pagename' => t('Upload Photos'),
1163 '$sessid' => session_id(),
1164 '$usage' => $usage_message,
1165 '$nickname' => $a->data['user']['nickname'],
1166 '$newalbum' => t('New album name: '),
1167 '$existalbumtext' => t('or existing album name: '),
1168 '$nosharetext' => t('Do not show a status post for this upload'),
1169 '$albumselect' => $albumselect_e,
1170 '$permissions' => t('Permissions'),
1171 '$aclselect' => $aclselect_e,
1172 '$alt_uploader' => $ret['addon_text'],
1173 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1174 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1175 '$uploadurl' => $ret['post_url'],
1177 // ACL permissions box
1178 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1179 '$group_perms' => t('Show to Groups'),
1180 '$contact_perms' => t('Show to Contacts'),
1181 '$private' => t('Private Photo'),
1182 '$public' => t('Public Photo'),
1183 '$is_private' => $private_post,
1184 '$return_path' => $query_str,
1185 '$public_link' => $public_post_link,
1193 * Display a single photo album
1196 if ($datatype === 'album') {
1198 $album = hex2bin($datum);
1200 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1201 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1205 if (DBM::is_result($r)) {
1206 $a->set_pager_total(count($r));
1207 $a->set_pager_itemspage(20);
1210 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1211 if ($_GET['order'] === 'posted') {
1217 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1218 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1219 ANY_VALUE(`created`) as `created`
1220 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1221 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1224 intval($a->pager['start']),
1225 intval($a->pager['itemspage'])
1229 if ($cmd === 'edit') {
1230 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1232 $edit_tpl = get_markup_template('album_edit.tpl');
1236 $o .= replace_macros($edit_tpl,array(
1237 '$nametext' => t('New album name: '),
1238 '$nickname' => $a->data['user']['nickname'],
1239 '$album' => $album_e,
1240 '$hexalbum' => bin2hex($album),
1241 '$submit' => t('Submit'),
1242 '$dropsubmit' => t('Delete Album')
1247 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos')) && $can_post) {
1248 $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1252 if ($_GET['order'] === 'posted') {
1253 $order = array(t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1255 $order = array(t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1260 if (DBM::is_result($r))
1261 $twist = 'rotright';
1262 foreach ($r as $rr) {
1263 if ($twist == 'rotright') {
1266 $twist = 'rotright';
1269 $ext = $phototypes[$rr['type']];
1271 $imgalt_e = $rr['filename'];
1272 $desc_e = $rr['desc'];
1276 'twist' => ' ' . $twist . rand(2,4),
1277 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1278 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1279 'title' => t('View Photo'),
1280 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1284 'hash'=> $rr['resource_id'],
1288 $tpl = get_markup_template('photo_album.tpl');
1289 $o .= replace_macros($tpl, array(
1290 '$photos' => $photos,
1292 '$can_post' => $can_post,
1293 '$upload' => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1296 '$paginate' => paginate($a),
1306 if ($datatype === 'image') {
1309 // fetch image, item containing image, then comments
1311 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1312 $sql_extra ORDER BY `scale` ASC ",
1317 if (! DBM::is_result($ph)) {
1318 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1323 if (DBM::is_result($ph)) {
1324 notice(t('Permission denied. Access to this item may be restricted.'));
1326 notice(t('Photo not available') . EOL );
1334 /// @todo This query is totally bad, the whole functionality has to be changed
1335 // The query leads to a really intense used index.
1336 // By now we hide it if someone wants to.
1337 if (!Config::get('system', 'no_count', false)) {
1338 if ($_GET['order'] === 'posted')
1343 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1344 $sql_extra ORDER BY `created` $order ",
1345 dbesc($ph[0]['album']),
1349 if (DBM::is_result($prvnxt)) {
1350 foreach ($prvnxt as $z => $entry) {
1351 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1355 $prv = count($prvnxt) - 1;
1357 if ($nxt >= count($prvnxt)) {
1363 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1364 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1365 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1369 if (count($ph) == 1)
1370 $hires = $lores = $ph[0];
1371 if (count($ph) > 1) {
1372 if ($ph[1]['scale'] == 2) {
1373 // original is 640 or less, we can display it directly
1374 $hires = $lores = $ph[0];
1381 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1385 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1387 'edit' => array('photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1388 'profile'=>array('profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1392 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1393 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1394 ? t('Private Message')
1400 if ( $cmd === 'edit') {
1401 $tpl = get_markup_template('photo_edit_head.tpl');
1402 $a->page['htmlhead'] .= replace_macros($tpl,array(
1403 '$prevlink' => $prevlink,
1404 '$nextlink' => $nextlink
1409 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1412 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1413 'title'=> t('View Full Size'),
1414 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1415 'height' => $hires['height'],
1416 'width' => $hires['width'],
1417 'album' => $hires['album'],
1418 'filename' => $hires['filename'],
1422 $nextlink = array($nextlink, '<div class="icon next"></div>');
1426 // Do we have an item for this photo?
1428 // FIXME! - replace following code to display the conversation with our normal
1429 // conversation functions so that it works correctly and tracks changes
1430 // in the evolving conversation code.
1431 // The difference is that we won't be displaying the conversation head item
1432 // as a "post" but displaying instead the photo it is linked to
1434 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1440 if (DBM::is_result($linked_items)) {
1441 $link_item = $linked_items[0];
1443 $r = q("SELECT COUNT(*) AS `total`
1444 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1445 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1446 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1447 AND `item`.`uid` = %d
1449 dbesc($link_item['uri']),
1450 dbesc($link_item['uri']),
1451 intval($link_item['uid'])
1455 if (DBM::is_result($r)) {
1456 $a->set_pager_total($r[0]['total']);
1460 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1461 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1462 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1463 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1464 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1465 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1466 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1467 AND `item`.`uid` = %d
1469 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1470 dbesc($link_item['uri']),
1471 dbesc($link_item['uri']),
1472 intval($link_item['uid']),
1473 intval($a->pager['start']),
1474 intval($a->pager['itemspage'])
1478 if ((local_user()) && (local_user() == $link_item['uid'])) {
1479 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1480 intval($link_item['parent']),
1481 intval(local_user())
1483 update_thread($link_item['parent']);
1486 if ($link_item['coord']) {
1487 $map = generate_map($link_item['coord']);
1493 if (count($linked_items) && strlen($link_item['tag'])) {
1494 $arr = explode(',', $link_item['tag']);
1495 // parse tags and add links
1497 foreach ($arr as $t) {
1498 if (strlen($tag_str)) {
1501 $tag_str .= bbcode($t);
1503 $tags = array(t('Tags: '), $tag_str);
1504 if ($cmd === 'edit') {
1505 $tags[] = 'tagrm/' . $link_item['id'];
1506 $tags[] = t('[Remove any tag]');
1512 if (($cmd === 'edit') && ($can_post)) {
1513 $edit_tpl = get_markup_template('photo_edit.tpl');
1515 // Private/public post links for the non-JS ACL form
1517 if ($_REQUEST['public']) {
1521 $query_str = $a->query_string;
1522 if (strpos($query_str, 'public=1') !== false) {
1523 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1527 * I think $a->query_string may never have ? in it, but I could be wrong
1528 * It looks like it's from the index.php?q=[etc] rewrite that the web
1529 * 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 $album_e = $ph[0]['album'];
1538 $caption_e = $ph[0]['desc'];
1539 $aclselect_e = populate_acl($ph[0]);
1541 $edit = replace_macros($edit_tpl, array(
1542 '$id' => $ph[0]['id'],
1543 '$album' => array('albname', t('New album name'), $album_e,''),
1544 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1545 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1546 '$rotate_none' => array('rotate', t('Do not rotate'),0,'', true),
1547 '$rotate_cw' => array('rotate', t('Rotate CW (right)'),1,''),
1548 '$rotate_ccw' => array('rotate', t('Rotate CCW (left)'),2,''),
1550 '$nickname' => $a->data['user']['nickname'],
1551 '$resource_id' => $ph[0]['resource-id'],
1552 '$permissions' => t('Permissions'),
1553 '$aclselect' => $aclselect_e,
1555 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1556 '$submit' => t('Submit'),
1557 '$delete' => t('Delete Photo'),
1559 // ACL permissions box
1560 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1561 '$group_perms' => t('Show to Groups'),
1562 '$contact_perms' => t('Show to Contacts'),
1563 '$private' => t('Private photo'),
1564 '$public' => t('Public photo'),
1565 '$is_private' => $private_post,
1566 '$return_path' => $query_str,
1567 '$public_link' => $public_post_link,
1571 if (count($linked_items)) {
1573 $cmnt_tpl = get_markup_template('comment_item.tpl');
1574 $tpl = get_markup_template('photo_item.tpl');
1575 $return_url = $a->cmd;
1577 $like_tpl = get_markup_template('like_noshare.tpl');
1581 if ($can_post || can_write_wall($a, $owner_uid)) {
1582 $likebuttons = replace_macros($like_tpl, array(
1583 '$id' => $link_item['id'],
1584 '$likethis' => t("I like this \x28toggle\x29"),
1585 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1586 '$wait' => t('Please wait'),
1587 '$return_path' => $a->query_string,
1592 if (! DBM::is_result($r)) {
1593 if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) {
1594 $comments .= replace_macros($cmnt_tpl, array(
1595 '$return_path' => '',
1596 '$jsreload' => $return_url,
1597 '$type' => 'wall-comment',
1598 '$id' => $link_item['id'],
1599 '$parent' => $link_item['id'],
1600 '$profile_uid' => $owner_uid,
1601 '$mylink' => $contact['url'],
1602 '$mytitle' => t('This is you'),
1603 '$myphoto' => $contact['thumb'],
1604 '$comment' => t('Comment'),
1605 '$submit' => t('Submit'),
1606 '$preview' => t('Preview'),
1607 '$sourceapp' => t($a->sourcename),
1609 '$rand_num' => random_digits(12)
1620 $conv_responses = array(
1621 'like' => array('title' => t('Likes','title')),'dislike' => array('title' => t('Dislikes','title')),
1622 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
1626 if (DBM::is_result($r)) {
1628 foreach ($r as $item) {
1629 builtin_activity_puller($item, $conv_responses);
1632 $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']) : '');
1633 $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']) : '');
1635 if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) {
1636 $comments .= replace_macros($cmnt_tpl,array(
1637 '$return_path' => '',
1638 '$jsreload' => $return_url,
1639 '$type' => 'wall-comment',
1640 '$id' => $link_item['id'],
1641 '$parent' => $link_item['id'],
1642 '$profile_uid' => $owner_uid,
1643 '$mylink' => $contact['url'],
1644 '$mytitle' => t('This is you'),
1645 '$myphoto' => $contact['thumb'],
1646 '$comment' => t('Comment'),
1647 '$submit' => t('Submit'),
1648 '$preview' => t('Preview'),
1649 '$sourceapp' => t($a->sourcename),
1651 '$rand_num' => random_digits(12)
1656 foreach ($r as $item) {
1661 if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1664 $redirect_url = 'redir/' . $item['cid'];
1667 if (local_user() && ($item['contact-uid'] == local_user())
1668 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1669 $profile_url = $redirect_url;
1670 $sparkle = ' sparkle';
1672 $profile_url = $item['url'];
1676 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1678 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1679 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1681 $profile_link = $profile_url;
1683 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1685 'dropping' => $dropping,
1686 'pagedrop' => false,
1687 'select' => t('Select'),
1688 'delete' => t('Delete'),
1691 $name_e = $profile_name;
1692 $title_e = $item['title'];
1693 $body_e = bbcode($item['body']);
1695 $comments .= replace_macros($template,array(
1696 '$id' => $item['item_id'],
1697 '$profile_url' => $profile_link,
1699 '$thumb' => $profile_avatar,
1700 '$sparkle' => $sparkle,
1701 '$title' => $title_e,
1703 '$ago' => relative_date($item['created']),
1704 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1706 '$comment' => $comment
1709 if (($can_post || can_write_wall($a, $owner_uid)) && $item['last-child']) {
1710 $comments .= replace_macros($cmnt_tpl, array(
1711 '$return_path' => '',
1712 '$jsreload' => $return_url,
1713 '$type' => 'wall-comment',
1714 '$id' => $item['item_id'],
1715 '$parent' => $item['parent'],
1716 '$profile_uid' => $owner_uid,
1717 '$mylink' => $contact['url'],
1718 '$mytitle' => t('This is you'),
1719 '$myphoto' => $contact['thumb'],
1720 '$comment' => t('Comment'),
1721 '$submit' => t('Submit'),
1722 '$preview' => t('Preview'),
1723 '$sourceapp' => t($a->sourcename),
1725 '$rand_num' => random_digits(12)
1731 $paginate = paginate($a);
1735 $response_verbs = array('like');
1736 if (feature_enabled($owner_uid, 'dislike')) {
1737 $response_verbs[] = 'dislike';
1739 $responses = get_responses($conv_responses,$response_verbs, '', $link_item);
1741 $photo_tpl = get_markup_template('photo_view.tpl');
1743 $album_e = array($album_link, $ph[0]['album']);
1746 $dislike_e = $dislike;
1748 $o .= replace_macros($photo_tpl, array(
1749 '$id' => $ph[0]['id'],
1750 '$album' => $album_e,
1754 '$prevlink' => $prevlink,
1755 '$nextlink' => $nextlink,
1756 '$desc' => $ph[0]['desc'],
1760 '$map_text' => t('Map'),
1761 '$likebuttons' => $likebuttons,
1763 '$dislike' => $dikslike_e,
1764 'responses' => $responses,
1765 '$comments' => $comments,
1766 '$paginate' => $paginate,
1769 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1770 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1771 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1772 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1773 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1778 // Default - show recent photos with upload link (if applicable)
1781 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1782 $sql_extra GROUP BY `resource-id`",
1783 intval($a->data['user']['uid']),
1784 dbesc('Contact Photos'),
1785 dbesc( t('Contact Photos'))
1787 if (DBM::is_result($r)) {
1788 $a->set_pager_total(count($r));
1789 $a->set_pager_itemspage(20);
1792 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1793 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1794 ANY_VALUE(`created`) AS `created` FROM `photo`
1795 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1796 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1797 intval($a->data['user']['uid']),
1798 dbesc('Contact Photos'),
1799 dbesc( t('Contact Photos')),
1800 intval($a->pager['start']),
1801 intval($a->pager['itemspage'])
1805 if (DBM::is_result($r)) {
1806 $twist = 'rotright';
1807 foreach ($r as $rr) {
1808 //hide profile photos to others
1809 if ((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
1812 if ($twist == 'rotright')
1815 $twist = 'rotright';
1817 $ext = $phototypes[$rr['type']];
1819 $alt_e = $rr['filename'];
1820 $name_e = $rr['album'];
1824 'twist' => ' ' . $twist . rand(2,4),
1825 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1826 'title' => t('View Photo'),
1827 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1830 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1832 'alt' => t('View Album'),
1839 $tpl = get_markup_template('photos_recent.tpl');
1840 $o .= replace_macros($tpl, array(
1841 '$title' => t('Recent Photos'),
1842 '$can_post' => $can_post,
1843 '$upload' => array(t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'),
1844 '$photos' => $photos,
1845 '$paginate' => paginate($a),