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');
12 function photos_init(&$a) {
15 auto_redir($a, $a->argv[1]);
17 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
21 nav_set_selected('home');
27 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
34 $a->data['user'] = $r[0];
35 $a->profile_uid = $r[0]['uid'];
36 $is_owner = (local_user() && (local_user() == $a->profile_uid));
38 $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg');
40 $tpl = get_markup_template("vcard-widget.tpl");
42 $vcard_widget .= replace_macros($tpl, array(
43 '$name' => $a->data['user']['username'],
44 '$photo' => $profilephoto
48 $sql_extra = permissions_sql($a->data['user']['uid']);
50 $albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
51 $sql_extra group by album order by created desc",
52 intval($a->data['user']['uid']),
53 dbesc('Contact Photos'),
54 dbesc( t('Contact Photos'))
57 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
59 // add various encodings to the array so we can just loop through and pick them out in a template
60 $ret = array('success' => false);
63 $a->data['albums'] = $albums;
65 $ret['success'] = true;
67 $ret['albums'] = array();
68 foreach($albums as $k => $album) {
69 //hide profile photos to others
70 if((! $is_owner) && (! remote_user()) && ($album['album'] == t('Profile Photos')))
73 'text' => $album['album'],
74 'total' => $album['total'],
75 'url' => z_root() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
76 'urlencode' => urlencode($album['album']),
77 'bin2hex' => bin2hex($album['album'])
79 $ret['albums'][] = $entry;
85 if(local_user() && $a->data['user']['uid'] == local_user())
88 if($albums['success']) {
89 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array(
90 '$nick' => $a->data['user']['nickname'],
91 '$title' => t('Photo Albums'),
92 'recent' => t('Recent Photos'),
93 '$albums' => $albums['albums'],
94 '$baseurl' => z_root(),
95 '$upload' => array( t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload'),
96 '$can_post' => $can_post
101 if(! x($a->page,'aside'))
102 $a->page['aside'] = '';
103 $a->page['aside'] .= $vcard_widget;
104 $a->page['aside'] .= $photo_albums_widget;
107 $tpl = get_markup_template("photos_head.tpl");
108 $a->page['htmlhead'] .= replace_macros($tpl,array(
109 '$ispublic' => t('everybody')
119 function photos_post(&$a) {
121 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
124 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
125 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
127 $phototypes = Photo::supportedTypes();
132 $page_owner_uid = $a->data['user']['uid'];
133 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
135 if((local_user()) && (local_user() == $page_owner_uid))
138 if($community_page && remote_user()) {
140 if(is_array($_SESSION['remote'])) {
141 foreach($_SESSION['remote'] as $v) {
142 if($v['uid'] == $page_owner_uid) {
150 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
152 intval($page_owner_uid)
163 notice( t('Permission denied.') . EOL );
167 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
168 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
169 intval($page_owner_uid)
173 notice( t('Contact information unavailable') . EOL);
174 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
178 $owner_record = $r[0];
181 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
182 $album = hex2bin($a->argv[3]);
184 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
185 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
186 return; // NOTREACHED
189 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
191 intval($page_owner_uid)
194 notice( t('Album not found.') . EOL);
195 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
196 return; // NOTREACHED
199 // Check if the user has responded to a delete confirmation query
200 if($_REQUEST['canceled']) {
201 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
208 $newalbum = notags(trim($_POST['albumname']));
209 if($newalbum != $album) {
210 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
213 intval($page_owner_uid)
215 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
216 goaway($a->get_baseurl() . '/' . $newurl);
217 return; // NOTREACHED
221 * DELETE photo album and all its photos
224 if($_POST['dropalbum'] == t('Delete Album')) {
226 // Check if we should do HTML-based delete confirmation
227 if($_REQUEST['confirm']) {
228 $drop_url = $a->query_string;
229 $extra_inputs = array(
230 array('name' => 'albumname', 'value' => $_POST['albumname']),
232 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
234 '$message' => t('Do you really want to delete this photo album and all its photos?'),
235 '$extra_inputs' => $extra_inputs,
236 '$confirm' => t('Delete Album'),
237 '$confirm_url' => $drop_url,
238 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
239 '$cancel' => t('Cancel'),
241 $a->error = 1; // Set $a->error so the other module functions don't execute
247 // get the list of photos we are about to delete
250 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
252 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()),
264 $res[] = "'" . dbesc($rr['rid']) . "'" ;
268 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
269 return; // NOTREACHED
272 $str_res = implode(',', $res);
274 // remove the associated photos
276 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
277 intval($page_owner_uid)
280 // find and delete the corresponding item with all the comments and likes/dislikes
282 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
283 intval($page_owner_uid)
287 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
288 dbesc(datetime_convert()),
289 dbesc($rr['parent-uri']),
290 intval($page_owner_uid)
292 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
293 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
295 $drop_id = intval($rr['id']);
297 // send the notification upstream/downstream as the case may be
300 proc_run('php',"include/notifier.php","drop","$drop_id");
304 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
305 return; // NOTREACHED
309 // Check if the user has responded to a delete confirmation query for a single photo
310 if(($a->argc > 2) && $_REQUEST['canceled']) {
311 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
314 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
316 // same as above but remove single photo
318 // Check if we should do HTML-based delete confirmation
319 if($_REQUEST['confirm']) {
320 $drop_url = $a->query_string;
321 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
323 '$message' => t('Do you really want to delete this photo?'),
324 '$extra_inputs' => array(),
325 '$confirm' => t('Delete Photo'),
326 '$confirm_url' => $drop_url,
327 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
328 '$cancel' => t('Cancel'),
330 $a->error = 1; // Set $a->error so the other module functions don't execute
335 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
337 intval($page_owner_uid),
342 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
343 intval(local_user()),
348 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
349 intval($page_owner_uid),
350 dbesc($r[0]['resource-id'])
352 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
353 dbesc($r[0]['resource-id']),
354 intval($page_owner_uid)
357 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
358 dbesc(datetime_convert()),
359 dbesc(datetime_convert()),
361 intval($page_owner_uid)
363 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
364 delete_thread_uri($i[0]['uri'], $page_owner_uid);
366 $url = $a->get_baseurl();
367 $drop_id = intval($i[0]['id']);
370 proc_run('php',"include/notifier.php","drop","$drop_id");
374 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
375 return; // NOTREACHED
378 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
380 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
381 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
382 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
383 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
384 $str_group_allow = perms2str($_POST['group_allow']);
385 $str_contact_allow = perms2str($_POST['contact_allow']);
386 $str_group_deny = perms2str($_POST['group_deny']);
387 $str_contact_deny = perms2str($_POST['contact_deny']);
389 $resource_id = $a->argv[2];
391 if(! strlen($albname))
392 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
395 if((x($_POST,'rotate') !== false) &&
396 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
399 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
401 intval($page_owner_uid)
404 $ph = new Photo($r[0]['data'], $r[0]['type']);
405 if($ph->is_valid()) {
406 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
407 $ph->rotate($rotate_deg);
409 $width = $ph->getWidth();
410 $height = $ph->getHeight();
412 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
413 dbesc($ph->imageString()),
417 intval($page_owner_uid)
420 if($width > 640 || $height > 640) {
421 $ph->scaleImage(640);
422 $width = $ph->getWidth();
423 $height = $ph->getHeight();
425 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
426 dbesc($ph->imageString()),
430 intval($page_owner_uid)
434 if($width > 320 || $height > 320) {
435 $ph->scaleImage(320);
436 $width = $ph->getWidth();
437 $height = $ph->getHeight();
439 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
440 dbesc($ph->imageString()),
444 intval($page_owner_uid)
451 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
453 intval($page_owner_uid)
456 $ext = $phototypes[$p[0]['type']];
457 $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",
460 dbesc($str_contact_allow),
461 dbesc($str_group_allow),
462 dbesc($str_contact_deny),
463 dbesc($str_group_deny),
465 intval($page_owner_uid)
469 /* Don't make the item visible if the only change was the album name */
472 if($p[0]['desc'] !== $desc || strlen($rawtags))
477 // Create item container
480 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
484 $arr['uid'] = $page_owner_uid;
486 $arr['parent-uri'] = $uri;
487 $arr['type'] = 'photo';
489 $arr['resource-id'] = $p[0]['resource-id'];
490 $arr['contact-id'] = $owner_record['id'];
491 $arr['owner-name'] = $owner_record['name'];
492 $arr['owner-link'] = $owner_record['url'];
493 $arr['owner-avatar'] = $owner_record['thumb'];
494 $arr['author-name'] = $owner_record['name'];
495 $arr['author-link'] = $owner_record['url'];
496 $arr['author-avatar'] = $owner_record['thumb'];
497 $arr['title'] = $title;
498 $arr['allow_cid'] = $p[0]['allow_cid'];
499 $arr['allow_gid'] = $p[0]['allow_gid'];
500 $arr['deny_cid'] = $p[0]['deny_cid'];
501 $arr['deny_gid'] = $p[0]['deny_gid'];
502 $arr['last-child'] = 1;
503 $arr['visible'] = $visibility;
506 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
507 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
510 $item_id = item_store($arr);
515 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
517 intval($page_owner_uid)
521 $old_tag = $r[0]['tag'];
522 $old_inform = $r[0]['inform'];
525 if(strlen($rawtags)) {
530 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
532 $x = substr($rawtags,0,1);
533 if($x !== '@' && $x !== '#')
534 $rawtags = '#' . $rawtags;
537 $tags = get_tags($rawtags);
540 foreach($tags as $tag) {
543 if(strpos($tag,'@') === 0) {
544 $name = substr($tag,1);
545 if((strpos($name,'@')) || (strpos($name,'http://'))) {
547 $links = @lrdd($name);
549 foreach($links as $link) {
550 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
551 $profile = $link['@attributes']['href'];
552 if($link['@attributes']['rel'] === 'salmon') {
553 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
560 $taginfo[] = array($newname,$profile,$salmon);
566 if(strrpos($newname,'+'))
567 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
570 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
576 $newname = str_replace('_',' ',$name);
578 //select someone from this user's contacts by name
579 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
581 intval($page_owner_uid)
585 //select someone by attag or nick and the name passed in
586 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
589 intval($page_owner_uid)
593 /* elseif(strstr($name,'_') || strstr($name,' ')) {
594 $newname = str_replace('_',' ',$name);
595 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
597 intval($page_owner_uid)
601 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
604 intval($page_owner_uid)
608 $newname = $r[0]['name'];
609 $profile = $r[0]['url'];
610 $notify = 'cid:' . $r[0]['id'];
617 if(substr($notify,0,4) === 'cid:')
618 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
620 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
621 if(strlen($str_tags))
623 $profile = str_replace(',','%2c',$profile);
624 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
626 } elseif (strpos($tag,'#') === 0) {
627 $tagname = substr($tag, 1);
628 $str_tags .= '#[url='.$a->get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
634 if(strlen($newtag) && strlen($str_tags))
636 $newtag .= $str_tags;
638 $newinform = $old_inform;
639 if(strlen($newinform) && strlen($inform))
641 $newinform .= $inform;
643 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
646 dbesc(datetime_convert()),
647 dbesc(datetime_convert()),
649 intval($page_owner_uid)
651 create_tags_from_item($item_id);
652 update_thread($item_id);
655 foreach($p as $scales) {
656 if(intval($scales['scale']) == 2) {
660 if(intval($scales['scale']) == 4) {
666 if(count($taginfo)) {
667 foreach($taginfo as $tagged) {
669 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
673 $arr['uid'] = $page_owner_uid;
675 $arr['parent-uri'] = $uri;
676 $arr['type'] = 'activity';
678 $arr['contact-id'] = $owner_record['id'];
679 $arr['owner-name'] = $owner_record['name'];
680 $arr['owner-link'] = $owner_record['url'];
681 $arr['owner-avatar'] = $owner_record['thumb'];
682 $arr['author-name'] = $owner_record['name'];
683 $arr['author-link'] = $owner_record['url'];
684 $arr['author-avatar'] = $owner_record['thumb'];
686 $arr['allow_cid'] = $p[0]['allow_cid'];
687 $arr['allow_gid'] = $p[0]['allow_gid'];
688 $arr['deny_cid'] = $p[0]['deny_cid'];
689 $arr['deny_gid'] = $p[0]['deny_gid'];
690 $arr['last-child'] = 1;
692 $arr['verb'] = ACTIVITY_TAG;
693 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
694 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
695 $arr['tag'] = $tagged[4];
696 $arr['inform'] = $tagged[2];
698 $arr['body'] = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
699 $arr['body'] .= "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
701 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
702 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
704 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
705 $arr['object'] .= '</link></object>' . "\n";
707 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
708 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
709 $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
711 $item_id = item_store($arr);
713 //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
714 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
715 // intval($page_owner_uid),
719 proc_run('php',"include/notifier.php","tag","$item_id");
726 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
727 return; // NOTREACHED
732 * default post action - upload a photo
735 call_hooks('photo_post_init', $_POST);
738 * Determine the album to use
741 $album = notags(trim($_REQUEST['album']));
742 $newalbum = notags(trim($_REQUEST['newalbum']));
744 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
746 if(! strlen($album)) {
747 if(strlen($newalbum))
750 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
755 * We create a wall item for every photo, but we don't want to
756 * overwhelm the data stream with a hundred newly uploaded photos.
757 * So we will make the first photo uploaded to this album in the last several hours
758 * visible by default, the rest will become visible over time when and if
759 * they acquire comments, likes, dislikes, and/or tags
763 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
765 intval($page_owner_uid)
767 if((! count($r)) || ($album == t('Profile Photos')))
772 if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
775 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
776 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
777 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
778 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
780 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
782 call_hooks('photo_post_file',$ret);
784 if(x($ret,'src') && x($ret,'filesize')) {
786 $filename = $ret['filename'];
787 $filesize = $ret['filesize'];
788 $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);
824 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
825 intval($a->data['user']['uid'])
828 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
830 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
831 notice( upgrade_message() . EOL );
834 call_hooks('photo_post_end',$foo);
839 $ph = new Photo($imagedata, $type);
841 if(! $ph->is_valid()) {
842 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
843 notice( t('Unable to process image.') . EOL );
846 call_hooks('photo_post_end',$foo);
850 $exif = $ph->orient($src);
853 $max_length = get_config('system','max_image_length');
855 $max_length = MAX_IMAGE_LENGTH;
857 $ph->scaleImage($max_length);
859 $width = $ph->getWidth();
860 $height = $ph->getHeight();
864 $photo_hash = photo_new_resource();
866 $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);
869 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
870 notice( t('Image upload failed.') . EOL );
874 if($width > 640 || $height > 640) {
875 $ph->scaleImage(640);
876 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
880 if($width > 320 || $height > 320) {
881 $ph->scaleImage(320);
882 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
886 $basename = basename($filename);
887 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
889 // Create item container
893 if($exif && $exif['GPS']) {
894 if(feature_enabled($channel_id,'photo_location')) {
895 $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
896 $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
903 $arr['coord'] = $lat . ' ' . $lon;
905 $arr['uid'] = $page_owner_uid;
907 $arr['parent-uri'] = $uri;
908 $arr['type'] = 'photo';
910 $arr['resource-id'] = $photo_hash;
911 $arr['contact-id'] = $owner_record['id'];
912 $arr['owner-name'] = $owner_record['name'];
913 $arr['owner-link'] = $owner_record['url'];
914 $arr['owner-avatar'] = $owner_record['thumb'];
915 $arr['author-name'] = $owner_record['name'];
916 $arr['author-link'] = $owner_record['url'];
917 $arr['author-avatar'] = $owner_record['thumb'];
919 $arr['allow_cid'] = $str_contact_allow;
920 $arr['allow_gid'] = $str_group_allow;
921 $arr['deny_cid'] = $str_contact_deny;
922 $arr['deny_gid'] = $str_group_deny;
923 $arr['last-child'] = 1;
924 $arr['visible'] = $visible;
927 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
928 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
931 $item_id = item_store($arr);
934 // q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
935 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
936 // intval($page_owner_uid),
942 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
944 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
949 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
955 function photos_content(&$a) {
959 // photos/name/upload
960 // photos/name/upload/xxxxx (xxxxx is album name)
961 // photos/name/album/xxxxx
962 // photos/name/album/xxxxx/edit
963 // photos/name/image/xxxxx
964 // photos/name/image/xxxxx/edit
967 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
968 notice( t('Public access denied.') . EOL);
973 require_once('include/bbcode.php');
974 require_once('include/security.php');
975 require_once('include/conversation.php');
977 if(! x($a->data,'user')) {
978 notice( t('No photos selected') . EOL );
982 $phototypes = Photo::supportedTypes();
984 $_SESSION['photo_return'] = $a->cmd;
991 $datatype = $a->argv[2];
992 $datum = $a->argv[3];
994 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
995 $datatype = 'upload';
997 $datatype = 'summary';
1005 // Setup permissions structures
1011 $remote_contact = false;
1014 $owner_uid = $a->data['user']['uid'];
1016 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
1018 if((local_user()) && (local_user() == $owner_uid))
1021 if($community_page && remote_user()) {
1022 if(is_array($_SESSION['remote'])) {
1023 foreach($_SESSION['remote'] as $v) {
1024 if($v['uid'] == $owner_uid) {
1025 $contact_id = $v['cid'];
1032 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1033 intval($contact_id),
1039 $remote_contact = true;
1046 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1048 if(remote_user() && (! $visitor)) {
1050 if(is_array($_SESSION['remote'])) {
1051 foreach($_SESSION['remote'] as $v) {
1052 if($v['uid'] == $owner_uid) {
1053 $contact_id = $v['cid'];
1059 $groups = init_groups_visitor($contact_id);
1060 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1061 intval($contact_id),
1066 $remote_contact = true;
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') {
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')))
1113 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1114 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1120 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
1121 'addon_text' => $uploader,
1122 '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 = '';
1133 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1134 if($limit !== false) {
1136 $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1137 intval($a->data['user']['uid'])
1139 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1143 // Private/public post links for the non-JS ACL form
1145 if($_REQUEST['public'])
1148 $query_str = $a->query_string;
1149 if(strpos($query_str, 'public=1') !== false)
1150 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1152 // I think $a->query_string may never have ? in it, but I could be wrong
1153 // It looks like it's from the index.php?q=[etc] rewrite that the web
1154 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1155 if(strpos($query_str, '?') === false)
1156 $public_post_link = '?public=1';
1158 $public_post_link = '&public=1';
1162 $tpl = get_markup_template('photos_upload.tpl');
1164 if($a->theme['template_engine'] === 'internal') {
1165 $albumselect_e = template_escape($albumselect);
1166 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
1169 $albumselect_e = $albumselect;
1170 $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
1173 $o .= replace_macros($tpl,array(
1174 '$pagename' => t('Upload Photos'),
1175 '$sessid' => session_id(),
1176 '$usage' => $usage_message,
1177 '$nickname' => $a->data['user']['nickname'],
1178 '$newalbum' => t('New album name: '),
1179 '$existalbumtext' => t('or existing album name: '),
1180 '$nosharetext' => t('Do not show a status post for this upload'),
1181 '$albumselect' => $albumselect_e,
1182 '$permissions' => t('Permissions'),
1183 '$aclselect' => $aclselect_e,
1184 '$alt_uploader' => $ret['addon_text'],
1185 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1186 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1187 '$uploadurl' => $ret['post_url'],
1189 // ACL permissions box
1190 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1191 '$group_perms' => t('Show to Groups'),
1192 '$contact_perms' => t('Show to Contacts'),
1193 '$private' => t('Private Photo'),
1194 '$public' => t('Public Photo'),
1195 '$is_private' => $private_post,
1196 '$return_path' => $query_str,
1197 '$public_link' => $public_post_link,
1205 * Display a single photo album
1208 if($datatype === 'album') {
1210 $album = hex2bin($datum);
1212 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1213 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1218 $a->set_pager_total(count($r));
1219 $a->set_pager_itemspage(20);
1222 if($_GET['order'] === 'posted')
1227 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1228 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1231 intval($a->pager['start']),
1232 intval($a->pager['itemspage'])
1236 if($cmd === 'edit') {
1237 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1239 $edit_tpl = get_markup_template('album_edit.tpl');
1241 if($a->theme['template_engine'] === 'internal') {
1242 $album_e = template_escape($album);
1248 $o .= replace_macros($edit_tpl,array(
1249 '$nametext' => t('New album name: '),
1250 '$nickname' => $a->data['user']['nickname'],
1251 '$album' => $album_e,
1252 '$hexalbum' => bin2hex($album),
1253 '$submit' => t('Submit'),
1254 '$dropsubmit' => t('Delete Album')
1260 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1262 $edit = array(t('Edit Album'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1267 if($_GET['order'] === 'posted')
1268 $order = array(t('Show Newest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1270 $order = array(t('Show Oldest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1275 $twist = 'rotright';
1276 foreach($r as $rr) {
1277 if($twist == 'rotright')
1280 $twist = 'rotright';
1282 $ext = $phototypes[$rr['type']];
1284 if($a->theme['template_engine'] === 'internal') {
1285 $imgalt_e = template_escape($rr['filename']);
1286 $desc_e = template_escape($rr['desc']);
1289 $imgalt_e = $rr['filename'];
1290 $desc_e = $rr['desc'];
1295 'twist' => ' ' . $twist . rand(2,4),
1296 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1297 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1298 'title' => t('View Photo'),
1299 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1303 'hash'=> $rr['resource_id'],
1307 $tpl = get_markup_template('photo_album.tpl');
1308 $o .= replace_macros($tpl, array(
1309 '$photos' => $photos,
1311 '$can_post' => $can_post,
1312 '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1327 if($datatype === 'image') {
1330 // fetch image, item containing image, then comments
1332 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1333 $sql_extra ORDER BY `scale` ASC ",
1339 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1345 notice( t('Permission denied. Access to this item may be restricted.'));
1347 notice( t('Photo not available') . EOL );
1354 if($_GET['order'] === 'posted')
1360 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1361 $sql_extra ORDER BY `created` $order ",
1362 dbesc($ph[0]['album']),
1366 if(count($prvnxt)) {
1367 for($z = 0; $z < count($prvnxt); $z++) {
1368 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1372 $prv = count($prvnxt) - 1;
1373 if($nxt >= count($prvnxt))
1378 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1379 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1380 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1385 $hires = $lores = $ph[0];
1386 if(count($ph) > 1) {
1387 if($ph[1]['scale'] == 2) {
1388 // original is 640 or less, we can display it directly
1389 $hires = $lores = $ph[0];
1397 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1401 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1403 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1404 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1408 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1409 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1410 ? t('Private Message')
1416 if( $cmd === 'edit') {
1417 $tpl = get_markup_template('photo_edit_head.tpl');
1418 $a->page['htmlhead'] .= replace_macros($tpl,array(
1419 '$prevlink' => $prevlink,
1420 '$nextlink' => $nextlink
1425 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1428 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1429 'title'=> t('View Full Size'),
1430 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1431 'height' => $hires['height'],
1432 'width' => $hires['width'],
1433 'album' => $hires['album'],
1434 'filename' => $hires['filename'],
1438 $nextlink = array($nextlink, '<div class="icon next"></div>');
1441 // Do we have an item for this photo?
1443 // FIXME! - replace following code to display the conversation with our normal
1444 // conversation functions so that it works correctly and tracks changes
1445 // in the evolving conversation code.
1446 // The difference is that we won't be displaying the conversation head item
1447 // as a "post" but displaying instead the photo it is linked to
1449 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1455 if(count($linked_items)) {
1456 $link_item = $linked_items[0];
1457 $r = q("SELECT COUNT(*) AS `total`
1458 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1459 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1460 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1461 AND `item`.`uid` = %d
1463 dbesc($link_item['uri']),
1464 dbesc($link_item['uri']),
1465 intval($link_item['uid'])
1470 $a->set_pager_total($r[0]['total']);
1473 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1474 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1475 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1476 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1477 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1478 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1479 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1480 AND `item`.`uid` = %d
1482 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1483 dbesc($link_item['uri']),
1484 dbesc($link_item['uri']),
1485 intval($link_item['uid']),
1486 intval($a->pager['start']),
1487 intval($a->pager['itemspage'])
1491 if((local_user()) && (local_user() == $link_item['uid'])) {
1492 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1493 intval($link_item['parent']),
1494 intval(local_user())
1496 update_thread($link_item['parent']);
1499 if($link_item['coord']) {
1500 $map = generate_map($link_item['coord']);
1506 if(count($linked_items) && strlen($link_item['tag'])) {
1507 $arr = explode(',',$link_item['tag']);
1508 // parse tags and add links
1510 foreach($arr as $t) {
1511 if(strlen($tag_str))
1513 $tag_str .= bbcode($t);
1515 $tags = array(t('Tags: '), $tag_str);
1516 if($cmd === 'edit') {
1517 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1518 $tags[] = t('[Remove any tag]');
1524 if(($cmd === 'edit') && ($can_post)) {
1525 $edit_tpl = get_markup_template('photo_edit.tpl');
1527 // Private/public post links for the non-JS ACL form
1529 if($_REQUEST['public'])
1532 $query_str = $a->query_string;
1533 if(strpos($query_str, 'public=1') !== false)
1534 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1536 // I think $a->query_string may never have ? in it, but I could be wrong
1537 // It looks like it's from the index.php?q=[etc] rewrite that the web
1538 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1539 if(strpos($query_str, '?') === false)
1540 $public_post_link = '?public=1';
1542 $public_post_link = '&public=1';
1545 if($a->theme['template_engine'] === 'internal') {
1546 $album_e = template_escape($ph[0]['album']);
1547 $caption_e = template_escape($ph[0]['desc']);
1548 $aclselect_e = template_escape(populate_acl($ph[0]));
1551 $album_e = $ph[0]['album'];
1552 $caption_e = $ph[0]['desc'];
1553 $aclselect_e = populate_acl($ph[0]);
1556 $edit = replace_macros($edit_tpl, array(
1557 '$id' => $ph[0]['id'],
1558 '$album' => array('albname', t('New album name'), $album_e,''),
1559 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1560 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1561 '$rotate_none' => array('rotate',t('Do not rotate'),0,'', true),
1562 '$rotate_cw' => array('rotate',t('Rotate CW (right)'),1,''),
1563 '$rotate_ccw' => array('rotate',t('Rotate CCW (left)'),2,''),
1565 '$nickname' => $a->data['user']['nickname'],
1566 '$resource_id' => $ph[0]['resource-id'],
1567 '$permissions' => t('Permissions'),
1568 '$aclselect' => $aclselect_e,
1570 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1571 '$submit' => t('Submit'),
1572 '$delete' => t('Delete Photo'),
1574 // ACL permissions box
1575 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1576 '$group_perms' => t('Show to Groups'),
1577 '$contact_perms' => t('Show to Contacts'),
1578 '$private' => t('Private photo'),
1579 '$public' => t('Public photo'),
1580 '$is_private' => $private_post,
1581 '$return_path' => $query_str,
1582 '$public_link' => $public_post_link,
1586 if(count($linked_items)) {
1588 $cmnt_tpl = get_markup_template('comment_item.tpl');
1589 $tpl = get_markup_template('photo_item.tpl');
1590 $return_url = $a->cmd;
1592 $like_tpl = get_markup_template('like_noshare.tpl');
1596 if($can_post || can_write_wall($a,$owner_uid)) {
1597 $likebuttons = replace_macros($like_tpl,array(
1598 '$id' => $link_item['id'],
1599 '$likethis' => t("I like this \x28toggle\x29"),
1600 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1601 '$share' => t('Share'),
1602 '$wait' => t('Please wait'),
1603 '$return_path' => $a->query_string,
1609 if($can_post || can_write_wall($a,$owner_uid)) {
1610 if($link_item['last-child']) {
1611 $comments .= replace_macros($cmnt_tpl,array(
1612 '$return_path' => '',
1613 '$jsreload' => $return_url,
1614 '$type' => 'wall-comment',
1615 '$id' => $link_item['id'],
1616 '$parent' => $link_item['id'],
1617 '$profile_uid' => $owner_uid,
1618 '$mylink' => $contact['url'],
1619 '$mytitle' => t('This is you'),
1620 '$myphoto' => $contact['thumb'],
1621 '$comment' => t('Comment'),
1622 '$submit' => t('Submit'),
1623 '$preview' => t('Preview'),
1624 '$sourceapp' => t($a->sourcename),
1626 '$rand_num' => random_digits(12)
1643 foreach($r as $item) {
1644 like_puller($a,$item,$alike,'like');
1645 like_puller($a,$item,$dlike,'dislike');
1648 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1649 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1653 if($can_post || can_write_wall($a,$owner_uid)) {
1654 if($link_item['last-child']) {
1655 $comments .= replace_macros($cmnt_tpl,array(
1656 '$return_path' => '',
1657 '$jsreload' => $return_url,
1658 '$type' => 'wall-comment',
1659 '$id' => $link_item['id'],
1660 '$parent' => $link_item['id'],
1661 '$profile_uid' => $owner_uid,
1662 '$mylink' => $contact['url'],
1663 '$mytitle' => t('This is you'),
1664 '$myphoto' => $contact['thumb'],
1665 '$comment' => t('Comment'),
1666 '$submit' => t('Submit'),
1667 '$preview' => t('Preview'),
1668 '$sourceapp' => t($a->sourcename),
1670 '$rand_num' => random_digits(12)
1676 foreach($r as $item) {
1681 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1684 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1687 if(local_user() && ($item['contact-uid'] == local_user())
1688 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1689 $profile_url = $redirect_url;
1690 $sparkle = ' sparkle';
1693 $profile_url = $item['url'];
1697 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1699 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1700 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1702 $profile_link = $profile_url;
1706 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1708 'dropping' => $dropping,
1709 'pagedrop' => false,
1710 'select' => t('Select'),
1711 'delete' => t('Delete'),
1715 if($a->theme['template_engine'] === 'internal') {
1716 $name_e = template_escape($profile_name);
1717 $title_e = template_escape($item['title']);
1718 $body_e = template_escape(bbcode($item['body']));
1721 $name_e = $profile_name;
1722 $title_e = $item['title'];
1723 $body_e = bbcode($item['body']);
1726 $comments .= replace_macros($template,array(
1727 '$id' => $item['item_id'],
1728 '$profile_url' => $profile_link,
1730 '$thumb' => $profile_avatar,
1731 '$sparkle' => $sparkle,
1732 '$title' => $title_e,
1734 '$ago' => relative_date($item['created']),
1735 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1737 '$comment' => $comment
1740 if($can_post || can_write_wall($a,$owner_uid)) {
1742 if($item['last-child']) {
1743 $comments .= replace_macros($cmnt_tpl,array(
1744 '$return_path' => '',
1745 '$jsreload' => $return_url,
1746 '$type' => 'wall-comment',
1747 '$id' => $item['item_id'],
1748 '$parent' => $item['parent'],
1749 '$profile_uid' => $owner_uid,
1750 '$mylink' => $contact['url'],
1751 '$mytitle' => t('This is you'),
1752 '$myphoto' => $contact['thumb'],
1753 '$comment' => t('Comment'),
1754 '$submit' => t('Submit'),
1755 '$preview' => t('Preview'),
1756 '$sourceapp' => t($a->sourcename),
1758 '$rand_num' => random_digits(12)
1765 $paginate = paginate($a);
1768 $photo_tpl = get_markup_template('photo_view.tpl');
1770 if($a->theme['template_engine'] === 'internal') {
1771 $album_e = array($album_link,template_escape($ph[0]['album']));
1772 $tags_e = template_escape($tags);
1773 $like_e = template_escape($like);
1774 $dislike_e = template_escape($dislike);
1777 $album_e = array($album_link,$ph[0]['album']);
1780 $dislike_e = $dislike;
1783 $o .= replace_macros($photo_tpl, array(
1784 '$id' => $ph[0]['id'],
1785 '$album' => $album_e,
1789 '$prevlink' => $prevlink,
1790 '$nextlink' => $nextlink,
1791 '$desc' => $ph[0]['desc'],
1795 '$map_text' => t('Map'),
1796 '$likebuttons' => $likebuttons,
1798 '$dislike' => $dikslike_e,
1799 '$comments' => $comments,
1800 '$paginate' => $paginate,
1803 $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
1804 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
1805 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
1806 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
1807 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
1812 // Default - show recent photos with upload link (if applicable)
1815 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1816 $sql_extra GROUP BY `resource-id`",
1817 intval($a->data['user']['uid']),
1818 dbesc('Contact Photos'),
1819 dbesc( t('Contact Photos'))
1822 $a->set_pager_total(count($r));
1823 $a->set_pager_itemspage(20);
1826 $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
1827 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1828 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1829 intval($a->data['user']['uid']),
1830 dbesc('Contact Photos'),
1831 dbesc( t('Contact Photos')),
1832 intval($a->pager['start']),
1833 intval($a->pager['itemspage'])
1840 $twist = 'rotright';
1841 foreach($r as $rr) {
1842 //hide profile photos to others
1843 if((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
1846 if($twist == 'rotright')
1849 $twist = 'rotright';
1850 $ext = $phototypes[$rr['type']];
1852 if($a->theme['template_engine'] === 'internal') {
1853 $alt_e = template_escape($rr['filename']);
1854 $name_e = template_escape($rr['album']);
1857 $alt_e = $rr['filename'];
1858 $name_e = $rr['album'];
1863 'twist' => ' ' . $twist . rand(2,4),
1864 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1865 'title' => t('View Photo'),
1866 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1869 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1871 'alt' => t('View Album'),
1878 $tpl = get_markup_template('photos_recent.tpl');
1879 $o .= replace_macros($tpl, array(
1880 '$title' => t('Recent Photos'),
1881 '$can_post' => $can_post,
1882 '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),
1883 '$photos' => $photos,