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');
8 require_once('include/tags.php');
9 require_once('include/threads.php');
11 function photos_init(&$a) {
14 auto_redir($a, $a->argv[1]);
16 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
24 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
31 $a->data['user'] = $r[0];
33 $o .= '<div class="vcard">';
34 $o .= '<div class="fn">' . $a->data['user']['username'] . '</div>';
35 $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>';
39 $sql_extra = permissions_sql($a->data['user']['uid']);
41 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
42 intval($a->data['user']['uid'])
46 $a->data['albums'] = $albums;
48 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
51 $o .= '<div id="side-bar-photos-albums" class="widget">';
52 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
55 foreach($albums as $album) {
57 // don't show contact photos. We once translated this name, but then you could still access it under
58 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
60 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
62 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
66 if(local_user() && $a->data['user']['uid'] == local_user()) {
67 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
73 if(! x($a->page,'aside'))
74 $a->page['aside'] = '';
75 $a->page['aside'] .= $o;
78 $tpl = get_markup_template("photos_head.tpl");
79 $a->page['htmlhead'] .= replace_macros($tpl,array(
80 '$ispublic' => t('everybody')
90 function photos_post(&$a) {
92 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
95 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
96 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
98 $phototypes = Photo::supportedTypes();
103 $page_owner_uid = $a->data['user']['uid'];
104 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
106 if((local_user()) && (local_user() == $page_owner_uid))
109 if($community_page && remote_user()) {
111 if(is_array($_SESSION['remote'])) {
112 foreach($_SESSION['remote'] as $v) {
113 if($v['uid'] == $page_owner_uid) {
121 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
123 intval($page_owner_uid)
134 notice( t('Permission denied.') . EOL );
138 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
139 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
140 intval($page_owner_uid)
144 notice( t('Contact information unavailable') . EOL);
145 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
149 $owner_record = $r[0];
152 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
153 $album = hex2bin($a->argv[3]);
155 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
156 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
157 return; // NOTREACHED
160 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
162 intval($page_owner_uid)
165 notice( t('Album not found.') . EOL);
166 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
167 return; // NOTREACHED
170 // Check if the user has responded to a delete confirmation query
171 if($_REQUEST['canceled']) {
172 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
175 $newalbum = notags(trim($_POST['albumname']));
176 if($newalbum != $album) {
177 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
180 intval($page_owner_uid)
182 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
183 goaway($a->get_baseurl() . '/' . $newurl);
184 return; // NOTREACHED
188 if($_POST['dropalbum'] == t('Delete Album')) {
190 // Check if we should do HTML-based delete confirmation
191 if($_REQUEST['confirm']) {
192 $drop_url = $a->query_string;
193 $extra_inputs = array(
194 array('name' => 'albumname', 'value' => $_POST['albumname']),
196 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
198 '$message' => t('Do you really want to delete this photo album and all its photos?'),
199 '$extra_inputs' => $extra_inputs,
200 '$confirm' => t('Delete Album'),
201 '$confirm_url' => $drop_url,
202 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
203 '$cancel' => t('Cancel'),
205 $a->error = 1; // Set $a->error so the other module functions don't execute
211 // get the list of photos we are about to delete
214 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
216 intval($page_owner_uid),
221 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
222 intval(local_user()),
228 $res[] = "'" . dbesc($rr['rid']) . "'" ;
232 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
233 return; // NOTREACHED
236 $str_res = implode(',', $res);
238 // remove the associated photos
240 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
241 intval($page_owner_uid)
244 // find and delete the corresponding item with all the comments and likes/dislikes
246 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
247 intval($page_owner_uid)
251 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
252 dbesc(datetime_convert()),
253 dbesc($rr['parent-uri']),
254 intval($page_owner_uid)
256 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
257 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
259 $drop_id = intval($rr['id']);
261 // send the notification upstream/downstream as the case may be
264 proc_run('php',"include/notifier.php","drop","$drop_id");
268 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
269 return; // NOTREACHED
273 // Check if the user has responded to a delete confirmation query for a single photo
274 if(($a->argc > 2) && $_REQUEST['canceled']) {
275 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
278 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
280 // same as above but remove single photo
282 // Check if we should do HTML-based delete confirmation
283 if($_REQUEST['confirm']) {
284 $drop_url = $a->query_string;
285 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
287 '$message' => t('Do you really want to delete this photo?'),
288 '$extra_inputs' => array(),
289 '$confirm' => t('Delete Photo'),
290 '$confirm_url' => $drop_url,
291 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
292 '$cancel' => t('Cancel'),
294 $a->error = 1; // Set $a->error so the other module functions don't execute
299 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
301 intval($page_owner_uid),
306 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
307 intval(local_user()),
312 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
313 intval($page_owner_uid),
314 dbesc($r[0]['resource-id'])
316 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
317 dbesc($r[0]['resource-id']),
318 intval($page_owner_uid)
321 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
322 dbesc(datetime_convert()),
323 dbesc(datetime_convert()),
325 intval($page_owner_uid)
327 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
328 delete_thread_uri($i[0]['uri'], $page_owner_uid);
330 $url = $a->get_baseurl();
331 $drop_id = intval($i[0]['id']);
334 proc_run('php',"include/notifier.php","drop","$drop_id");
338 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
339 return; // NOTREACHED
342 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
344 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
345 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
346 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
347 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
348 $str_group_allow = perms2str($_POST['group_allow']);
349 $str_contact_allow = perms2str($_POST['contact_allow']);
350 $str_group_deny = perms2str($_POST['group_deny']);
351 $str_contact_deny = perms2str($_POST['contact_deny']);
353 $resource_id = $a->argv[2];
355 if(! strlen($albname))
356 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
359 if((x($_POST,'rotate') !== false) &&
360 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
363 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
365 intval($page_owner_uid)
368 $ph = new Photo($r[0]['data'], $r[0]['type']);
369 if($ph->is_valid()) {
370 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
371 $ph->rotate($rotate_deg);
373 $width = $ph->getWidth();
374 $height = $ph->getHeight();
376 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
377 dbesc($ph->imageString()),
381 intval($page_owner_uid)
384 if($width > 640 || $height > 640) {
385 $ph->scaleImage(640);
386 $width = $ph->getWidth();
387 $height = $ph->getHeight();
389 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
390 dbesc($ph->imageString()),
394 intval($page_owner_uid)
398 if($width > 320 || $height > 320) {
399 $ph->scaleImage(320);
400 $width = $ph->getWidth();
401 $height = $ph->getHeight();
403 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
404 dbesc($ph->imageString()),
408 intval($page_owner_uid)
415 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
417 intval($page_owner_uid)
420 $ext = $phototypes[$p[0]['type']];
421 $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",
424 dbesc($str_contact_allow),
425 dbesc($str_group_allow),
426 dbesc($str_contact_deny),
427 dbesc($str_group_deny),
429 intval($page_owner_uid)
433 /* Don't make the item visible if the only change was the album name */
436 if($p[0]['desc'] !== $desc || strlen($rawtags))
441 // Create item container
444 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
448 $arr['uid'] = $page_owner_uid;
450 $arr['parent-uri'] = $uri;
451 $arr['type'] = 'photo';
453 $arr['resource-id'] = $p[0]['resource-id'];
454 $arr['contact-id'] = $owner_record['id'];
455 $arr['owner-name'] = $owner_record['name'];
456 $arr['owner-link'] = $owner_record['url'];
457 $arr['owner-avatar'] = $owner_record['thumb'];
458 $arr['author-name'] = $owner_record['name'];
459 $arr['author-link'] = $owner_record['url'];
460 $arr['author-avatar'] = $owner_record['thumb'];
461 $arr['title'] = $title;
462 $arr['allow_cid'] = $p[0]['allow_cid'];
463 $arr['allow_gid'] = $p[0]['allow_gid'];
464 $arr['deny_cid'] = $p[0]['deny_cid'];
465 $arr['deny_gid'] = $p[0]['deny_gid'];
466 $arr['last-child'] = 1;
467 $arr['visible'] = $visibility;
470 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
471 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
474 $item_id = item_store($arr);
479 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
481 intval($page_owner_uid)
485 $old_tag = $r[0]['tag'];
486 $old_inform = $r[0]['inform'];
489 if(strlen($rawtags)) {
494 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
496 $x = substr($rawtags,0,1);
497 if($x !== '@' && $x !== '#')
498 $rawtags = '#' . $rawtags;
501 $tags = get_tags($rawtags);
504 foreach($tags as $tag) {
507 if(strpos($tag,'@') === 0) {
508 $name = substr($tag,1);
509 if((strpos($name,'@')) || (strpos($name,'http://'))) {
511 $links = @lrdd($name);
513 foreach($links as $link) {
514 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
515 $profile = $link['@attributes']['href'];
516 if($link['@attributes']['rel'] === 'salmon') {
517 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
524 $taginfo[] = array($newname,$profile,$salmon);
530 if(strrpos($newname,'+'))
531 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
534 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
540 $newname = str_replace('_',' ',$name);
542 //select someone from this user's contacts by name
543 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
545 intval($page_owner_uid)
549 //select someone by attag or nick and the name passed in
550 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
553 intval($page_owner_uid)
557 /* elseif(strstr($name,'_') || strstr($name,' ')) {
558 $newname = str_replace('_',' ',$name);
559 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
561 intval($page_owner_uid)
565 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
568 intval($page_owner_uid)
572 $newname = $r[0]['name'];
573 $profile = $r[0]['url'];
574 $notify = 'cid:' . $r[0]['id'];
581 if(substr($notify,0,4) === 'cid:')
582 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
584 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
585 if(strlen($str_tags))
587 $profile = str_replace(',','%2c',$profile);
588 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
590 } elseif (strpos($tag,'#') === 0) {
591 $tagname = substr($tag, 1);
592 $str_tags .= '#[url='.$a->get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
598 if(strlen($newtag) && strlen($str_tags))
600 $newtag .= $str_tags;
602 $newinform = $old_inform;
603 if(strlen($newinform) && strlen($inform))
605 $newinform .= $inform;
607 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
610 dbesc(datetime_convert()),
611 dbesc(datetime_convert()),
613 intval($page_owner_uid)
615 create_tags_from_item($item_id);
616 update_thread($item_id);
619 foreach($p as $scales) {
620 if(intval($scales['scale']) == 2) {
624 if(intval($scales['scale']) == 4) {
630 if(count($taginfo)) {
631 foreach($taginfo as $tagged) {
633 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
637 $arr['uid'] = $page_owner_uid;
639 $arr['parent-uri'] = $uri;
640 $arr['type'] = 'activity';
642 $arr['contact-id'] = $owner_record['id'];
643 $arr['owner-name'] = $owner_record['name'];
644 $arr['owner-link'] = $owner_record['url'];
645 $arr['owner-avatar'] = $owner_record['thumb'];
646 $arr['author-name'] = $owner_record['name'];
647 $arr['author-link'] = $owner_record['url'];
648 $arr['author-avatar'] = $owner_record['thumb'];
650 $arr['allow_cid'] = $p[0]['allow_cid'];
651 $arr['allow_gid'] = $p[0]['allow_gid'];
652 $arr['deny_cid'] = $p[0]['deny_cid'];
653 $arr['deny_gid'] = $p[0]['deny_gid'];
654 $arr['last-child'] = 1;
656 $arr['verb'] = ACTIVITY_TAG;
657 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
658 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
659 $arr['tag'] = $tagged[4];
660 $arr['inform'] = $tagged[2];
662 $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]') ;
663 $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" ;
665 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
666 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
668 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
669 $arr['object'] .= '</link></object>' . "\n";
671 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
672 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
673 $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>';
675 $item_id = item_store($arr);
677 //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
678 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
679 // intval($page_owner_uid),
683 proc_run('php',"include/notifier.php","tag","$item_id");
690 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
691 return; // NOTREACHED
696 * default post action - upload a photo
699 call_hooks('photo_post_init', $_POST);
702 * Determine the album to use
705 $album = notags(trim($_REQUEST['album']));
706 $newalbum = notags(trim($_REQUEST['newalbum']));
708 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
710 if(! strlen($album)) {
711 if(strlen($newalbum))
714 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
719 * We create a wall item for every photo, but we don't want to
720 * overwhelm the data stream with a hundred newly uploaded photos.
721 * So we will make the first photo uploaded to this album in the last several hours
722 * visible by default, the rest will become visible over time when and if
723 * they acquire comments, likes, dislikes, and/or tags
727 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
729 intval($page_owner_uid)
731 if((! count($r)) || ($album == t('Profile Photos')))
736 if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
739 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
740 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
741 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
742 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
744 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
746 call_hooks('photo_post_file',$ret);
748 if(x($ret,'src') && x($ret,'filesize')) {
750 $filename = $ret['filename'];
751 $filesize = $ret['filesize'];
752 $type = $ret['type'];
755 $src = $_FILES['userfile']['tmp_name'];
756 $filename = basename($_FILES['userfile']['name']);
757 $filesize = intval($_FILES['userfile']['size']);
758 $type = $_FILES['userfile']['type'];
760 if ($type=="") $type=guess_image_type($filename);
762 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
764 $maximagesize = get_config('system','maximagesize');
766 if(($maximagesize) && ($filesize > $maximagesize)) {
767 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
770 call_hooks('photo_post_end',$foo);
775 notice( t('Image file is empty.') . EOL);
778 call_hooks('photo_post_end',$foo);
782 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
784 $imagedata = @file_get_contents($src);
788 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
789 intval($a->data['user']['uid'])
792 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
794 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
795 notice( upgrade_message() . EOL );
798 call_hooks('photo_post_end',$foo);
803 $ph = new Photo($imagedata, $type);
805 if(! $ph->is_valid()) {
806 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
807 notice( t('Unable to process image.') . EOL );
810 call_hooks('photo_post_end',$foo);
817 $max_length = get_config('system','max_image_length');
819 $max_length = MAX_IMAGE_LENGTH;
821 $ph->scaleImage($max_length);
823 $width = $ph->getWidth();
824 $height = $ph->getHeight();
828 $photo_hash = photo_new_resource();
830 $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);
833 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
834 notice( t('Image upload failed.') . EOL );
838 if($width > 640 || $height > 640) {
839 $ph->scaleImage(640);
840 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
844 if($width > 320 || $height > 320) {
845 $ph->scaleImage(320);
846 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
850 $basename = basename($filename);
851 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
853 // Create item container
857 $arr['uid'] = $page_owner_uid;
859 $arr['parent-uri'] = $uri;
860 $arr['type'] = 'photo';
862 $arr['resource-id'] = $photo_hash;
863 $arr['contact-id'] = $owner_record['id'];
864 $arr['owner-name'] = $owner_record['name'];
865 $arr['owner-link'] = $owner_record['url'];
866 $arr['owner-avatar'] = $owner_record['thumb'];
867 $arr['author-name'] = $owner_record['name'];
868 $arr['author-link'] = $owner_record['url'];
869 $arr['author-avatar'] = $owner_record['thumb'];
871 $arr['allow_cid'] = $str_contact_allow;
872 $arr['allow_gid'] = $str_group_allow;
873 $arr['deny_cid'] = $str_contact_deny;
874 $arr['deny_gid'] = $str_group_deny;
875 $arr['last-child'] = 1;
876 $arr['visible'] = $visible;
879 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
880 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
883 $item_id = item_store($arr);
886 // q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
887 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
888 // intval($page_owner_uid),
894 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
896 call_hooks('photo_post_end',intval($item_id));
898 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
899 // if they do not wish to be redirected
901 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
907 function photos_content(&$a) {
911 // photos/name/upload
912 // photos/name/upload/xxxxx (xxxxx is album name)
913 // photos/name/album/xxxxx
914 // photos/name/album/xxxxx/edit
915 // photos/name/image/xxxxx
916 // photos/name/image/xxxxx/edit
919 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
920 notice( t('Public access denied.') . EOL);
925 require_once('include/bbcode.php');
926 require_once('include/security.php');
927 require_once('include/conversation.php');
929 if(! x($a->data,'user')) {
930 notice( t('No photos selected') . EOL );
934 $phototypes = Photo::supportedTypes();
936 $_SESSION['photo_return'] = $a->cmd;
943 $datatype = $a->argv[2];
944 $datum = $a->argv[3];
946 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
947 $datatype = 'upload';
949 $datatype = 'summary';
957 // Setup permissions structures
963 $remote_contact = false;
966 $owner_uid = $a->data['user']['uid'];
968 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
970 if((local_user()) && (local_user() == $owner_uid))
973 if($community_page && remote_user()) {
974 if(is_array($_SESSION['remote'])) {
975 foreach($_SESSION['remote'] as $v) {
976 if($v['uid'] == $owner_uid) {
977 $contact_id = $v['cid'];
984 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
991 $remote_contact = true;
998 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1000 if(remote_user() && (! $visitor)) {
1002 if(is_array($_SESSION['remote'])) {
1003 foreach($_SESSION['remote'] as $v) {
1004 if($v['uid'] == $owner_uid) {
1005 $contact_id = $v['cid'];
1011 $groups = init_groups_visitor($contact_id);
1012 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1013 intval($contact_id),
1018 $remote_contact = true;
1023 if(! $remote_contact) {
1025 $contact_id = $_SESSION['cid'];
1026 $contact = $a->contact;
1030 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1031 notice( t('Access to this item is restricted.') . EOL);
1035 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
1040 $_is_owner = (local_user() && (local_user() == $owner_uid));
1041 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
1048 if($datatype === 'upload') {
1050 notice( t('Permission denied.'));
1055 $selname = (($datum) ? hex2bin($datum) : '');
1061 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1062 if(count($a->data['albums'])) {
1063 foreach($a->data['albums'] as $album) {
1064 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
1066 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1067 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1071 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
1075 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
1076 'addon_text' => $uploader,
1077 'default_upload' => true);
1080 call_hooks('photo_upload_form',$ret);
1082 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1083 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1084 '$submit' => t('Submit'),
1087 $usage_message = '';
1088 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1089 if($limit !== false) {
1091 $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1092 intval($a->data['user']['uid'])
1094 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1098 // Private/public post links for the non-JS ACL form
1100 if($_REQUEST['public'])
1103 $query_str = $a->query_string;
1104 if(strpos($query_str, 'public=1') !== false)
1105 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1107 // I think $a->query_string may never have ? in it, but I could be wrong
1108 // It looks like it's from the index.php?q=[etc] rewrite that the web
1109 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1110 if(strpos($query_str, '?') === false)
1111 $public_post_link = '?public=1';
1113 $public_post_link = '&public=1';
1117 $tpl = get_markup_template('photos_upload.tpl');
1119 if($a->theme['template_engine'] === 'internal') {
1120 $albumselect_e = template_escape($albumselect);
1121 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb)));
1124 $albumselect_e = $albumselect;
1125 $aclselect_e = (($visitor) ? '' : populate_acl($a->user, $celeb));
1128 $o .= replace_macros($tpl,array(
1129 '$pagename' => t('Upload Photos'),
1130 '$sessid' => session_id(),
1131 '$usage' => $usage_message,
1132 '$nickname' => $a->data['user']['nickname'],
1133 '$newalbum' => t('New album name: '),
1134 '$existalbumtext' => t('or existing album name: '),
1135 '$nosharetext' => t('Do not show a status post for this upload'),
1136 '$albumselect' => $albumselect_e,
1137 '$permissions' => t('Permissions'),
1138 '$aclselect' => $aclselect_e,
1139 '$alt_uploader' => $ret['addon_text'],
1140 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1141 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1142 '$uploadurl' => $ret['post_url'],
1144 // ACL permissions box
1145 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1146 '$group_perms' => t('Show to Groups'),
1147 '$contact_perms' => t('Show to Contacts'),
1148 '$private' => t('Private Photo'),
1149 '$public' => t('Public Photo'),
1150 '$is_private' => $private_post,
1151 '$return_path' => $query_str,
1152 '$public_link' => $public_post_link,
1159 if($datatype === 'album') {
1161 $album = hex2bin($datum);
1163 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1164 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1169 $a->set_pager_total(count($r));
1170 $a->set_pager_itemspage(20);
1173 if($_GET['order'] === 'posted')
1178 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1179 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1182 intval($a->pager['start']),
1183 intval($a->pager['itemspage'])
1186 $o .= '<h3>' . $album . '</h3>';
1188 if($cmd === 'edit') {
1189 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1191 $edit_tpl = get_markup_template('album_edit.tpl');
1193 if($a->theme['template_engine'] === 'internal') {
1194 $album_e = template_escape($album);
1200 $o .= replace_macros($edit_tpl,array(
1201 '$nametext' => t('New album name: '),
1202 '$nickname' => $a->data['user']['nickname'],
1203 '$album' => $album_e,
1204 '$hexalbum' => bin2hex($album),
1205 '$submit' => t('Submit'),
1206 '$dropsubmit' => t('Delete Album')
1212 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1214 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
1215 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
1216 . t('Edit Album') . '</a></div>';
1221 if($_GET['order'] === 'posted')
1222 $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>';
1224 $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>';
1228 $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>';
1232 $tpl = get_markup_template('photo_album.tpl');
1234 $twist = 'rotright';
1235 foreach($r as $rr) {
1236 if($twist == 'rotright')
1239 $twist = 'rotright';
1241 $ext = $phototypes[$rr['type']];
1243 if($a->theme['template_engine'] === 'internal') {
1244 $imgalt_e = template_escape($rr['filename']);
1245 $desc_e = template_escape($rr['desc']);
1248 $imgalt_e = $rr['filename'];
1249 $desc_e = $rr['desc'];
1252 $o .= replace_macros($tpl,array(
1254 '$twist' => ' ' . $twist . rand(2,4),
1255 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1256 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1257 '$phototitle' => t('View Photo'),
1258 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1259 '$imgalt' => $imgalt_e,
1264 $o .= '<div id="photo-album-end"></div>';
1272 if($datatype === 'image') {
1277 // fetch image, item containing image, then comments
1279 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1280 $sql_extra ORDER BY `scale` ASC ",
1286 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1292 notice( t('Permission denied. Access to this item may be restricted.'));
1294 notice( t('Photo not available') . EOL );
1301 if($_GET['order'] === 'posted')
1307 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1308 $sql_extra ORDER BY `created` $order ",
1309 dbesc($ph[0]['album']),
1313 if(count($prvnxt)) {
1314 for($z = 0; $z < count($prvnxt); $z++) {
1315 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1319 $prv = count($prvnxt) - 1;
1320 if($nxt >= count($prvnxt))
1325 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1326 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1327 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1332 $hires = $lores = $ph[0];
1333 if(count($ph) > 1) {
1334 if($ph[1]['scale'] == 2) {
1335 // original is 640 or less, we can display it directly
1336 $hires = $lores = $ph[0];
1344 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1348 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1350 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1351 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1355 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1356 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1357 ? t('Private Message')
1363 if( $cmd === 'edit') {
1364 $tpl = get_markup_template('photo_edit_head.tpl');
1365 $a->page['htmlhead'] .= replace_macros($tpl,array(
1366 '$prevlink' => $prevlink,
1367 '$nextlink' => $nextlink
1372 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1375 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1376 'title'=> t('View Full Size'),
1377 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1378 'height' => $hires['height'],
1379 'width' => $hires['width'],
1380 'album' => $hires['album'],
1381 'filename' => $hires['filename'],
1385 $nextlink = array($nextlink, '<div class="icon next"></div>');
1388 // Do we have an item for this photo?
1390 // FIXME! - replace following code to display the conversation with our normal
1391 // conversation functions so that it works correctly and tracks changes
1392 // in the evolving conversation code.
1393 // The difference is that we won't be displaying the conversation head item
1394 // as a "post" but displaying instead the photo it is linked to
1396 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1399 if(count($linked_items)) {
1400 $link_item = $linked_items[0];
1401 $r = q("SELECT COUNT(*) AS `total`
1402 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1403 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1404 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1405 AND `item`.`uid` = %d
1407 dbesc($link_item['uri']),
1408 dbesc($link_item['uri']),
1409 intval($link_item['uid'])
1414 $a->set_pager_total($r[0]['total']);
1417 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1418 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1419 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1420 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1421 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1422 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1423 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1424 AND `item`.`uid` = %d
1426 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1427 dbesc($link_item['uri']),
1428 dbesc($link_item['uri']),
1429 intval($link_item['uid']),
1430 intval($a->pager['start']),
1431 intval($a->pager['itemspage'])
1435 if((local_user()) && (local_user() == $link_item['uid'])) {
1436 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1437 intval($link_item['parent']),
1438 intval(local_user())
1440 update_thread($link_item['parent']);
1446 if(count($linked_items) && strlen($link_item['tag'])) {
1447 $arr = explode(',',$link_item['tag']);
1448 // parse tags and add links
1450 foreach($arr as $t) {
1451 if(strlen($tag_str))
1453 $tag_str .= bbcode($t);
1455 $tags = array(t('Tags: '), $tag_str);
1456 if($cmd === 'edit') {
1457 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1458 $tags[] = t('[Remove any tag]');
1464 if(($cmd === 'edit') && ($can_post)) {
1465 $edit_tpl = get_markup_template('photo_edit.tpl');
1467 // Private/public post links for the non-JS ACL form
1469 if($_REQUEST['public'])
1472 $query_str = $a->query_string;
1473 if(strpos($query_str, 'public=1') !== false)
1474 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1476 // I think $a->query_string may never have ? in it, but I could be wrong
1477 // It looks like it's from the index.php?q=[etc] rewrite that the web
1478 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1479 if(strpos($query_str, '?') === false)
1480 $public_post_link = '?public=1';
1482 $public_post_link = '&public=1';
1485 if($a->theme['template_engine'] === 'internal') {
1486 $album_e = template_escape($ph[0]['album']);
1487 $caption_e = template_escape($ph[0]['desc']);
1488 $aclselect_e = template_escape(populate_acl($ph[0]));
1491 $album_e = $ph[0]['album'];
1492 $caption_e = $ph[0]['desc'];
1493 $aclselect_e = populate_acl($ph[0]);
1496 $edit = replace_macros($edit_tpl, array(
1497 '$id' => $ph[0]['id'],
1498 '$rotatecw' => t('Rotate CW (right)'),
1499 '$rotateccw' => t('Rotate CCW (left)'),
1500 '$album' => $album_e,
1501 '$newalbum' => t('New album name'),
1502 '$nickname' => $a->data['user']['nickname'],
1503 '$resource_id' => $ph[0]['resource-id'],
1504 '$capt_label' => t('Caption'),
1505 '$caption' => $caption_e,
1506 '$tag_label' => t('Add a Tag'),
1507 '$tags' => $link_item['tag'],
1508 '$permissions' => t('Permissions'),
1509 '$aclselect' => $aclselect_e,
1510 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1511 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1512 '$submit' => t('Submit'),
1513 '$delete' => t('Delete Photo'),
1515 // ACL permissions box
1516 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1517 '$group_perms' => t('Show to Groups'),
1518 '$contact_perms' => t('Show to Contacts'),
1519 '$private' => t('Private photo'),
1520 '$public' => t('Public photo'),
1521 '$is_private' => $private_post,
1522 '$return_path' => $query_str,
1523 '$public_link' => $public_post_link,
1527 if(count($linked_items)) {
1529 $cmnt_tpl = get_markup_template('comment_item.tpl');
1530 $tpl = get_markup_template('photo_item.tpl');
1531 $return_url = $a->cmd;
1533 $like_tpl = get_markup_template('like_noshare.tpl');
1537 if($can_post || can_write_wall($a,$owner_uid)) {
1538 $likebuttons = replace_macros($like_tpl,array(
1539 '$id' => $link_item['id'],
1540 '$likethis' => t("I like this \x28toggle\x29"),
1541 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1542 '$share' => t('Share'),
1543 '$wait' => t('Please wait'),
1544 '$return_path' => $a->query_string,
1550 if($can_post || can_write_wall($a,$owner_uid)) {
1551 if($link_item['last-child']) {
1552 $comments .= replace_macros($cmnt_tpl,array(
1553 '$return_path' => '',
1554 '$jsreload' => $return_url,
1555 '$type' => 'wall-comment',
1556 '$id' => $link_item['id'],
1557 '$parent' => $link_item['id'],
1558 '$profile_uid' => $owner_uid,
1559 '$mylink' => $contact['url'],
1560 '$mytitle' => t('This is you'),
1561 '$myphoto' => $contact['thumb'],
1562 '$comment' => t('Comment'),
1563 '$submit' => t('Submit'),
1564 '$preview' => t('Preview'),
1565 '$sourceapp' => t($a->sourcename),
1567 '$rand_num' => random_digits(12)
1584 foreach($r as $item) {
1585 like_puller($a,$item,$alike,'like');
1586 like_puller($a,$item,$dlike,'dislike');
1589 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1590 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1594 if($can_post || can_write_wall($a,$owner_uid)) {
1595 if($link_item['last-child']) {
1596 $comments .= replace_macros($cmnt_tpl,array(
1597 '$return_path' => '',
1598 '$jsreload' => $return_url,
1599 '$type' => 'wall-comment',
1600 '$id' => $link_item['id'],
1601 '$parent' => $link_item['id'],
1602 '$profile_uid' => $owner_uid,
1603 '$mylink' => $contact['url'],
1604 '$mytitle' => t('This is you'),
1605 '$myphoto' => $contact['thumb'],
1606 '$comment' => t('Comment'),
1607 '$submit' => t('Submit'),
1608 '$preview' => t('Preview'),
1609 '$sourceapp' => t($a->sourcename),
1611 '$rand_num' => random_digits(12)
1617 foreach($r as $item) {
1622 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1625 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1628 if(local_user() && ($item['contact-uid'] == local_user())
1629 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1630 $profile_url = $redirect_url;
1631 $sparkle = ' sparkle';
1634 $profile_url = $item['url'];
1638 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1640 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1641 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1643 $profile_link = $profile_url;
1647 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1649 'dropping' => $dropping,
1650 'pagedrop' => false,
1651 'select' => t('Select'),
1652 'delete' => t('Delete'),
1656 if($a->theme['template_engine'] === 'internal') {
1657 $name_e = template_escape($profile_name);
1658 $title_e = template_escape($item['title']);
1659 $body_e = template_escape(bbcode($item['body']));
1662 $name_e = $profile_name;
1663 $title_e = $item['title'];
1664 $body_e = bbcode($item['body']);
1667 $comments .= replace_macros($template,array(
1668 '$id' => $item['item_id'],
1669 '$profile_url' => $profile_link,
1671 '$thumb' => $profile_avatar,
1672 '$sparkle' => $sparkle,
1673 '$title' => $title_e,
1675 '$ago' => relative_date($item['created']),
1676 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1678 '$comment' => $comment
1681 if($can_post || can_write_wall($a,$owner_uid)) {
1683 if($item['last-child']) {
1684 $comments .= replace_macros($cmnt_tpl,array(
1685 '$return_path' => '',
1686 '$jsreload' => $return_url,
1687 '$type' => 'wall-comment',
1688 '$id' => $item['item_id'],
1689 '$parent' => $item['parent'],
1690 '$profile_uid' => $owner_uid,
1691 '$mylink' => $contact['url'],
1692 '$mytitle' => t('This is you'),
1693 '$myphoto' => $contact['thumb'],
1694 '$comment' => t('Comment'),
1695 '$submit' => t('Submit'),
1696 '$preview' => t('Preview'),
1697 '$sourceapp' => t($a->sourcename),
1699 '$rand_num' => random_digits(12)
1706 $paginate = paginate($a);
1709 $photo_tpl = get_markup_template('photo_view.tpl');
1711 if($a->theme['template_engine'] === 'internal') {
1712 $album_e = array($album_link,template_escape($ph[0]['album']));
1713 $tags_e = template_escape($tags);
1714 $like_e = template_escape($like);
1715 $dislike_e = template_escape($dislike);
1718 $album_e = array($album_link,$ph[0]['album']);
1721 $dislike_e = $dislike;
1724 $o .= replace_macros($photo_tpl, array(
1725 '$id' => $ph[0]['id'],
1726 '$album' => $album_e,
1730 '$prevlink' => $prevlink,
1731 '$nextlink' => $nextlink,
1732 '$desc' => $ph[0]['desc'],
1735 '$likebuttons' => $likebuttons,
1737 '$dislike' => $dikslike_e,
1738 '$comments' => $comments,
1739 '$paginate' => $paginate,
1742 $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
1743 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
1744 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
1745 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
1746 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
1751 // Default - show recent photos with upload link (if applicable)
1754 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1755 $sql_extra GROUP BY `resource-id`",
1756 intval($a->data['user']['uid']),
1757 dbesc('Contact Photos'),
1758 dbesc( t('Contact Photos'))
1761 $a->set_pager_total(count($r));
1762 $a->set_pager_itemspage(20);
1765 $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
1766 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1767 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1768 intval($a->data['user']['uid']),
1769 dbesc('Contact Photos'),
1770 dbesc( t('Contact Photos')),
1771 intval($a->pager['start']),
1772 intval($a->pager['itemspage'])
1779 $twist = 'rotright';
1780 foreach($r as $rr) {
1781 if($twist == 'rotright')
1784 $twist = 'rotright';
1785 $ext = $phototypes[$rr['type']];
1787 if($a->theme['template_engine'] === 'internal') {
1788 $alt_e = template_escape($rr['filename']);
1789 $name_e = template_escape($rr['album']);
1792 $alt_e = $rr['filename'];
1793 $name_e = $rr['album'];
1798 'twist' => ' ' . $twist . rand(2,4),
1799 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1800 'title' => t('View Photo'),
1801 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1804 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1806 'alt' => t('View Album'),
1813 $tpl = get_markup_template('photos_recent.tpl');
1814 $o .= replace_macros($tpl, array(
1815 '$title' => t('Recent Photos'),
1816 '$can_post' => $can_post,
1817 '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),
1818 '$photos' => $photos,