2 require_once('include/Photo.php');
3 require_once('include/items.php');
4 require_once('include/acl_selectors.php');
5 require_once('include/bbcode.php');
6 require_once('include/security.php');
7 require_once('include/redir.php');
10 function photos_init(&$a) {
13 auto_redir($a, $a->argv[1]);
15 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
23 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
30 $a->data['user'] = $r[0];
32 $sql_extra = permissions_sql($a->data['user']['uid']);
34 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
35 intval($a->data['user']['uid'])
39 $a->data['albums'] = $albums;
41 $o .= '<div class="vcard">';
42 $o .= '<div class="fn">' . $a->data['user']['username'] . '</div>';
43 $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg') . '" alt="' . $a->data['user']['username'] . '" /></div>';
46 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
49 $o .= '<div id="side-bar-photos-albums" class="widget">';
50 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
53 foreach($albums as $album) {
55 // don't show contact photos. We once translated this name, but then you could still access it under
56 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
58 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
60 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
64 if(local_user() && $a->data['user']['uid'] == local_user()) {
65 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
71 if(! x($a->page,'aside'))
72 $a->page['aside'] = '';
73 $a->page['aside'] .= $o;
76 $tpl = get_markup_template("photos_head.tpl");
77 $a->page['htmlhead'] .= replace_macros($tpl,array(
78 '$ispublic' => t('everybody')
88 function photos_post(&$a) {
90 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
93 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
94 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
96 $phototypes = Photo::supportedTypes();
101 $page_owner_uid = $a->data['user']['uid'];
102 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
104 if((local_user()) && (local_user() == $page_owner_uid))
107 if($community_page && remote_user()) {
109 if(is_array($_SESSION['remote'])) {
110 foreach($_SESSION['remote'] as $v) {
111 if($v['uid'] == $page_owner_uid) {
119 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
121 intval($page_owner_uid)
132 notice( t('Permission denied.') . EOL );
136 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
137 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
138 intval($page_owner_uid)
142 notice( t('Contact information unavailable') . EOL);
143 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
147 $owner_record = $r[0];
150 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
151 $album = hex2bin($a->argv[3]);
153 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
154 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
155 return; // NOTREACHED
158 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
160 intval($page_owner_uid)
163 notice( t('Album not found.') . EOL);
164 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
165 return; // NOTREACHED
168 $newalbum = notags(trim($_POST['albumname']));
169 if($newalbum != $album) {
170 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
173 intval($page_owner_uid)
175 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
176 goaway($a->get_baseurl() . '/' . $newurl);
177 return; // NOTREACHED
181 if($_POST['dropalbum'] == t('Delete Album')) {
185 // get the list of photos we are about to delete
188 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
190 intval($page_owner_uid),
195 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
196 intval(local_user()),
202 $res[] = "'" . dbesc($rr['rid']) . "'" ;
206 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
207 return; // NOTREACHED
210 $str_res = implode(',', $res);
212 // remove the associated photos
214 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
215 intval($page_owner_uid)
218 // find and delete the corresponding item with all the comments and likes/dislikes
220 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
221 intval($page_owner_uid)
225 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
226 dbesc(datetime_convert()),
227 dbesc($rr['parent-uri']),
228 intval($page_owner_uid)
231 $drop_id = intval($rr['id']);
233 // send the notification upstream/downstream as the case may be
236 proc_run('php',"include/notifier.php","drop","$drop_id");
240 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
241 return; // NOTREACHED
244 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
246 // same as above but remove single photo
249 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
251 intval($page_owner_uid),
256 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
257 intval(local_user()),
262 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
263 intval($page_owner_uid),
264 dbesc($r[0]['resource-id'])
266 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
267 dbesc($r[0]['resource-id']),
268 intval($page_owner_uid)
271 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
272 dbesc(datetime_convert()),
273 dbesc(datetime_convert()),
275 intval($page_owner_uid)
278 $url = $a->get_baseurl();
279 $drop_id = intval($i[0]['id']);
282 proc_run('php',"include/notifier.php","drop","$drop_id");
286 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
287 return; // NOTREACHED
290 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
293 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
294 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
295 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
296 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
297 $str_group_allow = perms2str($_POST['group_allow']);
298 $str_contact_allow = perms2str($_POST['contact_allow']);
299 $str_group_deny = perms2str($_POST['group_deny']);
300 $str_contact_deny = perms2str($_POST['contact_deny']);
302 $resource_id = $a->argv[2];
304 if(! strlen($albname))
305 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
308 if((x($_POST,'rotate') !== false) &&
309 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
312 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
314 intval($page_owner_uid)
317 $ph = new Photo($r[0]['data'], $r[0]['type']);
318 if($ph->is_valid()) {
319 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
320 $ph->rotate($rotate_deg);
322 $width = $ph->getWidth();
323 $height = $ph->getHeight();
325 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
326 dbesc($ph->imageString()),
330 intval($page_owner_uid)
333 if($width > 640 || $height > 640) {
334 $ph->scaleImage(640);
335 $width = $ph->getWidth();
336 $height = $ph->getHeight();
338 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1 limit 1",
339 dbesc($ph->imageString()),
343 intval($page_owner_uid)
347 if($width > 320 || $height > 320) {
348 $ph->scaleImage(320);
349 $width = $ph->getWidth();
350 $height = $ph->getHeight();
352 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2 limit 1",
353 dbesc($ph->imageString()),
357 intval($page_owner_uid)
364 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
366 intval($page_owner_uid)
369 $ext = $phototypes[$p[0]['type']];
370 $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",
373 dbesc($str_contact_allow),
374 dbesc($str_group_allow),
375 dbesc($str_contact_deny),
376 dbesc($str_group_deny),
378 intval($page_owner_uid)
382 /* Don't make the item visible if the only change was the album name */
385 if($p[0]['desc'] !== $desc || strlen($rawtags))
390 // Create item container
393 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
397 $arr['uid'] = $page_owner_uid;
399 $arr['parent-uri'] = $uri;
400 $arr['type'] = 'photo';
402 $arr['resource-id'] = $p[0]['resource-id'];
403 $arr['contact-id'] = $owner_record['id'];
404 $arr['owner-name'] = $owner_record['name'];
405 $arr['owner-link'] = $owner_record['url'];
406 $arr['owner-avatar'] = $owner_record['thumb'];
407 $arr['author-name'] = $owner_record['name'];
408 $arr['author-link'] = $owner_record['url'];
409 $arr['author-avatar'] = $owner_record['thumb'];
410 $arr['title'] = $title;
411 $arr['allow_cid'] = $p[0]['allow_cid'];
412 $arr['allow_gid'] = $p[0]['allow_gid'];
413 $arr['deny_cid'] = $p[0]['deny_cid'];
414 $arr['deny_gid'] = $p[0]['deny_gid'];
415 $arr['last-child'] = 1;
416 $arr['visible'] = $visibility;
419 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
420 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
423 $item_id = item_store($arr);
428 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
430 intval($page_owner_uid)
434 $old_tag = $r[0]['tag'];
435 $old_inform = $r[0]['inform'];
438 if(strlen($rawtags)) {
443 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
445 $x = substr($rawtags,0,1);
446 if($x !== '@' && $x !== '#')
447 $rawtags = '#' . $rawtags;
450 $tags = get_tags($rawtags);
453 foreach($tags as $tag) {
456 if(strpos($tag,'@') === 0) {
457 $name = substr($tag,1);
458 if((strpos($name,'@')) || (strpos($name,'http://'))) {
460 $links = @lrdd($name);
462 foreach($links as $link) {
463 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
464 $profile = $link['@attributes']['href'];
465 if($link['@attributes']['rel'] === 'salmon') {
466 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
473 $taginfo[] = array($newname,$profile,$salmon);
479 if(strrpos($newname,'+'))
480 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
483 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
489 $newname = str_replace('_',' ',$name);
491 //select someone from this user's contacts by name
492 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
494 intval($page_owner_uid)
498 //select someone by attag or nick and the name passed in
499 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
502 intval($page_owner_uid)
506 /* elseif(strstr($name,'_') || strstr($name,' ')) {
507 $newname = str_replace('_',' ',$name);
508 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
510 intval($page_owner_uid)
514 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
517 intval($page_owner_uid)
521 $newname = $r[0]['name'];
522 $profile = $r[0]['url'];
523 $notify = 'cid:' . $r[0]['id'];
530 if(substr($notify,0,4) === 'cid:')
531 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
533 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
534 if(strlen($str_tags))
536 $profile = str_replace(',','%2c',$profile);
537 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
544 if(strlen($newtag) && strlen($str_tags))
546 $newtag .= $str_tags;
548 $newinform = $old_inform;
549 if(strlen($newinform) && strlen($inform))
551 $newinform .= $inform;
553 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
556 dbesc(datetime_convert()),
557 dbesc(datetime_convert()),
559 intval($page_owner_uid)
563 foreach($p as $scales) {
564 if(intval($scales['scale']) == 2) {
568 if(intval($scales['scale']) == 4) {
574 if(count($taginfo)) {
575 foreach($taginfo as $tagged) {
577 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
581 $arr['uid'] = $page_owner_uid;
583 $arr['parent-uri'] = $uri;
584 $arr['type'] = 'activity';
586 $arr['contact-id'] = $owner_record['id'];
587 $arr['owner-name'] = $owner_record['name'];
588 $arr['owner-link'] = $owner_record['url'];
589 $arr['owner-avatar'] = $owner_record['thumb'];
590 $arr['author-name'] = $owner_record['name'];
591 $arr['author-link'] = $owner_record['url'];
592 $arr['author-avatar'] = $owner_record['thumb'];
594 $arr['allow_cid'] = $p[0]['allow_cid'];
595 $arr['allow_gid'] = $p[0]['allow_gid'];
596 $arr['deny_cid'] = $p[0]['deny_cid'];
597 $arr['deny_gid'] = $p[0]['deny_gid'];
598 $arr['last-child'] = 1;
600 $arr['verb'] = ACTIVITY_TAG;
601 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
602 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
603 $arr['tag'] = $tagged[4];
604 $arr['inform'] = $tagged[2];
606 $arr['body'] = '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]' . ' ' . t('was tagged in a') . ' ' . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('photo') . '[/url]' . ' ' . t('by') . ' ' . '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]' ;
607 $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" ;
609 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
610 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
612 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
613 $arr['object'] .= '</link></object>' . "\n";
615 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
616 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
617 $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>';
619 $item_id = item_store($arr);
621 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
622 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
623 intval($page_owner_uid),
627 proc_run('php',"include/notifier.php","tag","$item_id");
634 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
635 return; // NOTREACHED
640 * default post action - upload a photo
643 call_hooks('photo_post_init', $_POST);
646 * Determine the album to use
649 $album = notags(trim($_REQUEST['album']));
650 $newalbum = notags(trim($_REQUEST['newalbum']));
652 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
654 if(! strlen($album)) {
655 if(strlen($newalbum))
658 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
663 * We create a wall item for every photo, but we don't want to
664 * overwhelm the data stream with a hundred newly uploaded photos.
665 * So we will make the first photo uploaded to this album in the last several hours
666 * visible by default, the rest will become visible over time when and if
667 * they acquire comments, likes, dislikes, and/or tags
671 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
673 intval($page_owner_uid)
675 if((! count($r)) || ($album == t('Profile Photos')))
680 if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
683 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
684 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
685 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
686 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
688 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
690 call_hooks('photo_post_file',$ret);
692 if(x($ret,'src') && x($ret,'filesize')) {
694 $filename = $ret['filename'];
695 $filesize = $ret['filesize'];
696 $type = $ret['type'];
699 $src = $_FILES['userfile']['tmp_name'];
700 $filename = basename($_FILES['userfile']['name']);
701 $filesize = intval($_FILES['userfile']['size']);
702 $type = $_FILES['userfile']['type'];
704 if ($type=="") $type=guess_image_type($filename);
706 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
708 $maximagesize = get_config('system','maximagesize');
710 if(($maximagesize) && ($filesize > $maximagesize)) {
711 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
714 call_hooks('photo_post_end',$foo);
719 notice( t('Image file is empty.') . EOL);
722 call_hooks('photo_post_end',$foo);
726 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
728 $imagedata = @file_get_contents($src);
732 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
733 intval($a->data['user']['uid'])
736 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
738 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
739 notice( upgrade_message() . EOL );
742 call_hooks('photo_post_end',$foo);
747 $ph = new Photo($imagedata, $type);
749 if(! $ph->is_valid()) {
750 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
751 notice( t('Unable to process image.') . EOL );
754 call_hooks('photo_post_end',$foo);
761 $max_length = get_config('system','max_image_length');
763 $max_length = MAX_IMAGE_LENGTH;
765 $ph->scaleImage($max_length);
767 $width = $ph->getWidth();
768 $height = $ph->getHeight();
772 $photo_hash = photo_new_resource();
774 $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);
777 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
778 notice( t('Image upload failed.') . EOL );
782 if($width > 640 || $height > 640) {
783 $ph->scaleImage(640);
784 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
788 if($width > 320 || $height > 320) {
789 $ph->scaleImage(320);
790 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
794 $basename = basename($filename);
795 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
797 // Create item container
801 $arr['uid'] = $page_owner_uid;
803 $arr['parent-uri'] = $uri;
804 $arr['type'] = 'photo';
806 $arr['resource-id'] = $photo_hash;
807 $arr['contact-id'] = $owner_record['id'];
808 $arr['owner-name'] = $owner_record['name'];
809 $arr['owner-link'] = $owner_record['url'];
810 $arr['owner-avatar'] = $owner_record['thumb'];
811 $arr['author-name'] = $owner_record['name'];
812 $arr['author-link'] = $owner_record['url'];
813 $arr['author-avatar'] = $owner_record['thumb'];
815 $arr['allow_cid'] = $str_contact_allow;
816 $arr['allow_gid'] = $str_group_allow;
817 $arr['deny_cid'] = $str_contact_deny;
818 $arr['deny_gid'] = $str_group_deny;
819 $arr['last-child'] = 1;
820 $arr['visible'] = $visible;
823 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
824 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
827 $item_id = item_store($arr);
830 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
831 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
832 intval($page_owner_uid),
838 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
840 call_hooks('photo_post_end',intval($item_id));
842 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
843 // if they do not wish to be redirected
845 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
851 function photos_content(&$a) {
855 // photos/name/upload
856 // photos/name/upload/xxxxx (xxxxx is album name)
857 // photos/name/album/xxxxx
858 // photos/name/album/xxxxx/edit
859 // photos/name/image/xxxxx
860 // photos/name/image/xxxxx/edit
863 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
864 notice( t('Public access denied.') . EOL);
869 require_once('include/bbcode.php');
870 require_once('include/security.php');
871 require_once('include/conversation.php');
873 if(! x($a->data,'user')) {
874 notice( t('No photos selected') . EOL );
878 $phototypes = Photo::supportedTypes();
880 $_SESSION['photo_return'] = $a->cmd;
887 $datatype = $a->argv[2];
888 $datum = $a->argv[3];
890 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
891 $datatype = 'upload';
893 $datatype = 'summary';
901 // Setup permissions structures
907 $remote_contact = false;
910 $owner_uid = $a->data['user']['uid'];
912 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
914 if((local_user()) && (local_user() == $owner_uid))
917 if($community_page && remote_user()) {
918 if(is_array($_SESSION['remote'])) {
919 foreach($_SESSION['remote'] as $v) {
920 if($v['uid'] == $owner_uid) {
921 $contact_id = $v['cid'];
928 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
935 $remote_contact = true;
942 // perhaps they're visiting - but not a community page, so they wouldn't have write access
944 if(remote_user() && (! $visitor)) {
946 if(is_array($_SESSION['remote'])) {
947 foreach($_SESSION['remote'] as $v) {
948 if($v['uid'] == $owner_uid) {
949 $contact_id = $v['cid'];
955 $groups = init_groups_visitor($contact_id);
956 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
962 $remote_contact = true;
967 if(! $remote_contact) {
969 $contact_id = $_SESSION['cid'];
970 $contact = $a->contact;
974 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
975 notice( t('Access to this item is restricted.') . EOL);
979 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
984 $_is_owner = (local_user() && (local_user() == $owner_uid));
985 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
992 if($datatype === 'upload') {
994 notice( t('Permission denied.'));
999 $selname = (($datum) ? hex2bin($datum) : '');
1005 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1006 if(count($a->data['albums'])) {
1007 foreach($a->data['albums'] as $album) {
1008 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
1010 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1011 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1015 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
1019 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
1020 'addon_text' => $uploader,
1021 'default_upload' => true);
1024 call_hooks('photo_upload_form',$ret);
1026 $default_upload = '<input id="photos-upload-choose" type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
1027 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
1030 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1031 intval($a->data['user']['uid'])
1035 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1036 if($limit !== false) {
1037 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1040 $usage_message = sprintf( t('You have used %1$.2f Mbytes of photo storage.'), $r[0]['total'] / 1024000 );
1044 $tpl = get_markup_template('photos_upload.tpl');
1045 $o .= replace_macros($tpl,array(
1046 '$pagename' => t('Upload Photos'),
1047 '$sessid' => session_id(),
1048 '$usage' => $usage_message,
1049 '$nickname' => $a->data['user']['nickname'],
1050 '$newalbum' => t('New album name: '),
1051 '$existalbumtext' => t('or existing album name: '),
1052 '$nosharetext' => t('Do not show a status post for this upload'),
1053 '$albumselect' => template_escape($albumselect),
1054 '$permissions' => t('Permissions'),
1055 '$aclselect' => (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb))),
1056 '$uploader' => $ret['addon_text'],
1057 '$default' => (($ret['default_upload']) ? $default_upload : ''),
1058 '$uploadurl' => $ret['post_url']
1065 if($datatype === 'album') {
1067 $album = hex2bin($datum);
1069 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1070 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1075 $a->set_pager_total(count($r));
1076 $a->set_pager_itemspage(20);
1079 if($_GET['order'] === 'posted')
1084 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1085 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1088 intval($a->pager['start']),
1089 intval($a->pager['itemspage'])
1092 $o .= '<h3>' . $album . '</h3>';
1094 if($cmd === 'edit') {
1095 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1097 $edit_tpl = get_markup_template('album_edit.tpl');
1098 $o .= replace_macros($edit_tpl,array(
1099 '$nametext' => t('New album name: '),
1100 '$nickname' => $a->data['user']['nickname'],
1101 '$album' => template_escape($album),
1102 '$hexalbum' => bin2hex($album),
1103 '$submit' => t('Submit'),
1104 '$dropsubmit' => t('Delete Album')
1110 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1112 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
1113 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
1114 . t('Edit Album') . '</a></div>';
1119 if($_GET['order'] === 'posted')
1120 $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '" >' . t('Show Newest First') . '</a></div>';
1122 $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted" >' . t('Show Oldest First') . '</a></div>';
1126 $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album) . '" >' . t('Upload New Photos') . '</a></div>';
1130 $tpl = get_markup_template('photo_album.tpl');
1132 $twist = 'rotright';
1133 foreach($r as $rr) {
1134 if($twist == 'rotright')
1137 $twist = 'rotright';
1139 $ext = $phototypes[$rr['type']];
1141 $o .= replace_macros($tpl,array(
1143 '$twist' => ' ' . $twist . rand(2,4),
1144 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1145 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1146 '$phototitle' => t('View Photo'),
1147 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1148 '$imgalt' => template_escape($rr['filename']),
1149 '$desc'=> template_escape($rr['desc'])
1153 $o .= '<div id="photo-album-end"></div>';
1161 if($datatype === 'image') {
1166 // fetch image, item containing image, then comments
1168 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1169 $sql_extra ORDER BY `scale` ASC ",
1175 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1181 notice( t('Permission denied. Access to this item may be restricted.'));
1183 notice( t('Photo not available') . EOL );
1190 if($_GET['order'] === 'posted')
1196 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1197 $sql_extra ORDER BY `created` $order ",
1198 dbesc($ph[0]['album']),
1202 if(count($prvnxt)) {
1203 for($z = 0; $z < count($prvnxt); $z++) {
1204 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1208 $prv = count($prvnxt) - 1;
1209 if($nxt >= count($prvnxt))
1214 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1215 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1216 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1221 $hires = $lores = $ph[0];
1222 if(count($ph) > 1) {
1223 if($ph[1]['scale'] == 2) {
1224 // original is 640 or less, we can display it directly
1225 $hires = $lores = $ph[0];
1233 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1237 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1239 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1240 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1244 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1245 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1246 ? t('Private Message')
1252 if( $cmd === 'edit') {
1253 $tpl = get_markup_template('photo_edit_head.tpl');
1254 $a->page['htmlhead'] .= replace_macros($tpl,array(
1255 '$prevlink' => $prevlink,
1256 '$nextlink' => $nextlink
1261 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1264 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1265 'title'=> t('View Full Size'),
1266 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis')
1270 $nextlink = array($nextlink, '<div class="icon next"></div>');
1273 // Do we have an item for this photo?
1275 // FIXME! - replace following code to display the conversation with our normal
1276 // conversation functions so that it works correctly and tracks changes
1277 // in the evolving conversation code.
1278 // The difference is that we won't be displaying the conversation head item
1279 // as a "post" but displaying instead the photo it is linked to
1281 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1284 if(count($linked_items)) {
1285 $link_item = $linked_items[0];
1286 $r = q("SELECT COUNT(*) AS `total`
1287 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1288 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1289 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1290 AND `item`.`uid` = %d
1292 dbesc($link_item['uri']),
1293 dbesc($link_item['uri']),
1294 intval($link_item['uid'])
1299 $a->set_pager_total($r[0]['total']);
1302 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1303 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1304 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1305 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1306 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1307 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1308 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1309 AND `item`.`uid` = %d
1311 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1312 dbesc($link_item['uri']),
1313 dbesc($link_item['uri']),
1314 intval($link_item['uid']),
1315 intval($a->pager['start']),
1316 intval($a->pager['itemspage'])
1320 if((local_user()) && (local_user() == $link_item['uid'])) {
1321 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1322 intval($link_item['parent']),
1323 intval(local_user())
1330 if(count($linked_items) && strlen($link_item['tag'])) {
1331 $arr = explode(',',$link_item['tag']);
1332 // parse tags and add links
1334 foreach($arr as $t) {
1335 if(strlen($tag_str))
1337 $tag_str .= bbcode($t);
1339 $tags = array(t('Tags: '), $tag_str);
1340 if($cmd === 'edit') {
1341 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1342 $tags[] = t('[Remove any tag]');
1348 if(($cmd === 'edit') && ($can_post)) {
1349 $edit_tpl = get_markup_template('photo_edit.tpl');
1350 $edit = replace_macros($edit_tpl, array(
1351 '$id' => $ph[0]['id'],
1352 '$rotatecw' => t('Rotate CW (right)'),
1353 '$rotateccw' => t('Rotate CCW (left)'),
1354 '$album' => template_escape($ph[0]['album']),
1355 '$newalbum' => t('New album name'),
1356 '$nickname' => $a->data['user']['nickname'],
1357 '$resource_id' => $ph[0]['resource-id'],
1358 '$capt_label' => t('Caption'),
1359 '$caption' => template_escape($ph[0]['desc']),
1360 '$tag_label' => t('Add a Tag'),
1361 '$tags' => $link_item['tag'],
1362 '$permissions' => t('Permissions'),
1363 '$aclselect' => template_escape(populate_acl($ph[0])),
1364 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1365 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1366 '$submit' => t('Submit'),
1367 '$delete' => t('Delete Photo')
1371 if(count($linked_items)) {
1373 $cmnt_tpl = get_markup_template('comment_item.tpl');
1374 $tpl = get_markup_template('photo_item.tpl');
1375 $return_url = $a->cmd;
1377 $like_tpl = get_markup_template('like_noshare.tpl');
1381 if($can_post || can_write_wall($a,$owner_uid)) {
1382 $likebuttons = replace_macros($like_tpl,array(
1383 '$id' => $link_item['id'],
1384 '$likethis' => t("I like this \x28toggle\x29"),
1385 '$nolike' => t("I don't like this \x28toggle\x29"),
1386 '$share' => t('Share'),
1387 '$wait' => t('Please wait')
1393 if($can_post || can_write_wall($a,$owner_uid)) {
1394 if($link_item['last-child']) {
1395 $comments .= replace_macros($cmnt_tpl,array(
1396 '$return_path' => '',
1397 '$jsreload' => $return_url,
1398 '$type' => 'wall-comment',
1399 '$id' => $link_item['id'],
1400 '$parent' => $link_item['id'],
1401 '$profile_uid' => $owner_uid,
1402 '$mylink' => $contact['url'],
1403 '$mytitle' => t('This is you'),
1404 '$myphoto' => $contact['thumb'],
1405 '$comment' => t('Comment'),
1406 '$submit' => t('Submit'),
1407 '$preview' => t('Preview'),
1408 '$sourceapp' => t($a->sourcename),
1426 foreach($r as $item) {
1427 like_puller($a,$item,$alike,'like');
1428 like_puller($a,$item,$dlike,'dislike');
1431 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1432 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1436 if($can_post || can_write_wall($a,$owner_uid)) {
1437 if($link_item['last-child']) {
1438 $comments .= replace_macros($cmnt_tpl,array(
1439 '$return_path' => '',
1440 '$jsreload' => $return_url,
1441 '$type' => 'wall-comment',
1442 '$id' => $link_item['id'],
1443 '$parent' => $link_item['id'],
1444 '$profile_uid' => $owner_uid,
1445 '$mylink' => $contact['url'],
1446 '$mytitle' => t('This is you'),
1447 '$myphoto' => $contact['thumb'],
1448 '$comment' => t('Comment'),
1449 '$submit' => t('Submit'),
1450 '$preview' => t('Preview'),
1451 '$sourceapp' => t($a->sourcename),
1458 foreach($r as $item) {
1463 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1466 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1469 if(local_user() && ($item['contact-uid'] == local_user())
1470 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1471 $profile_url = $redirect_url;
1472 $sparkle = ' sparkle';
1475 $profile_url = $item['url'];
1479 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1481 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1482 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1484 $profile_link = $profile_url;
1488 if(($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()))
1489 $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
1492 $comments .= replace_macros($template,array(
1493 '$id' => $item['item_id'],
1494 '$profile_url' => $profile_link,
1495 '$name' => template_escape($profile_name),
1496 '$thumb' => $profile_avatar,
1497 '$sparkle' => $sparkle,
1498 '$title' => template_escape($item['title']),
1499 '$body' => template_escape(bbcode($item['body'])),
1500 '$ago' => relative_date($item['created']),
1501 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1503 '$comment' => $comment
1506 if($can_post || can_write_wall($a,$owner_uid)) {
1508 if($item['last-child']) {
1509 $comments .= replace_macros($cmnt_tpl,array(
1510 '$return_path' => '',
1511 '$jsreload' => $return_url,
1512 '$type' => 'wall-comment',
1513 '$id' => $item['item_id'],
1514 '$parent' => $item['parent'],
1515 '$profile_uid' => $owner_uid,
1516 '$mylink' => $contact['url'],
1517 '$mytitle' => t('This is you'),
1518 '$myphoto' => $contact['thumb'],
1519 '$comment' => t('Comment'),
1520 '$submit' => t('Submit'),
1521 '$preview' => t('Preview'),
1522 '$sourceapp' => t($a->sourcename),
1530 $paginate = paginate($a);
1533 $photo_tpl = get_markup_template('photo_view.tpl');
1534 $o .= replace_macros($photo_tpl, array(
1535 '$id' => $ph[0]['id'],
1536 '$album' => array($album_link,template_escape($ph[0]['album'])),
1540 '$prevlink' => $prevlink,
1541 '$nextlink' => $nextlink,
1542 '$desc' => $ph[0]['desc'],
1543 '$tags' => template_escape($tags),
1545 '$likebuttons' => $likebuttons,
1546 '$like' => template_escape($like),
1547 '$dislike' => template_escape($dislike),
1548 '$comments' => $comments,
1549 '$paginate' => $paginate,
1555 // Default - show recent photos with upload link (if applicable)
1558 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1559 $sql_extra GROUP BY `resource-id`",
1560 intval($a->data['user']['uid']),
1561 dbesc('Contact Photos'),
1562 dbesc( t('Contact Photos'))
1565 $a->set_pager_total(count($r));
1566 $a->set_pager_itemspage(20);
1569 $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
1570 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1571 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1572 intval($a->data['user']['uid']),
1573 dbesc('Contact Photos'),
1574 dbesc( t('Contact Photos')),
1575 intval($a->pager['start']),
1576 intval($a->pager['itemspage'])
1583 $twist = 'rotright';
1584 foreach($r as $rr) {
1585 if($twist == 'rotright')
1588 $twist = 'rotright';
1589 $ext = $phototypes[$rr['type']];
1593 'twist' => ' ' . $twist . rand(2,4),
1594 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1595 'title' => t('View Photo'),
1596 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1597 'alt' => template_escape($rr['filename']),
1599 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1600 'name' => template_escape($rr['album']),
1601 'alt' => t('View Album'),
1608 $tpl = get_markup_template('photos_recent.tpl');
1609 $o .= replace_macros($tpl,array(
1610 '$title' => t('Recent Photos'),
1611 '$can_post' => $can_post,
1612 '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),
1613 '$photos' => $photos,