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];
32 $a->profile_uid = $r[0]['uid'];
34 $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg');
36 $tpl = get_markup_template("vcard-widget.tpl");
38 $vcard_widget .= replace_macros($tpl, array(
39 '$name' => $a->data['user']['username'],
40 '$photo' => $profilephoto
44 $sql_extra = permissions_sql($a->data['user']['uid']);
46 $albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
47 $sql_extra group by album order by created desc",
48 intval($a->data['user']['uid']),
49 dbesc('Contact Photos'),
50 dbesc( t('Contact Photos'))
53 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
55 // add various encodings to the array so we can just loop through and pick them out in a template
56 $ret = array('success' => false);
59 $a->data['albums'] = $albums;
61 $ret['success'] = true;
63 $ret['albums'] = array();
64 foreach($albums as $k => $album) {
66 'text' => $album['album'],
67 'total' => $album['total'],
68 'url' => z_root() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
69 'urlencode' => urlencode($album['album']),
70 'bin2hex' => bin2hex($album['album'])
72 $ret['albums'][] = $entry;
78 if(local_user() && $a->data['user']['uid'] == local_user())
81 if($albums['success']) {
82 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array(
83 '$nick' => $a->data['user']['nickname'],
84 '$title' => t('Photo Albums'),
85 'recent' => t('Recent Photos'),
86 '$albums' => $albums['albums'],
87 '$baseurl' => z_root(),
88 '$upload' => array( t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload'),
89 '$can_post' => $can_post
94 if(! x($a->page,'aside'))
95 $a->page['aside'] = '';
96 $a->page['aside'] .= $vcard_widget;
97 $a->page['aside'] .= $photo_albums_widget;
100 $tpl = get_markup_template("photos_head.tpl");
101 $a->page['htmlhead'] .= replace_macros($tpl,array(
102 '$ispublic' => t('everybody')
112 function photos_post(&$a) {
114 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
117 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
118 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
120 $phototypes = Photo::supportedTypes();
125 $page_owner_uid = $a->data['user']['uid'];
126 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
128 if((local_user()) && (local_user() == $page_owner_uid))
131 if($community_page && remote_user()) {
133 if(is_array($_SESSION['remote'])) {
134 foreach($_SESSION['remote'] as $v) {
135 if($v['uid'] == $page_owner_uid) {
143 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
145 intval($page_owner_uid)
156 notice( t('Permission denied.') . EOL );
160 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
161 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
162 intval($page_owner_uid)
166 notice( t('Contact information unavailable') . EOL);
167 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
171 $owner_record = $r[0];
174 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
175 $album = hex2bin($a->argv[3]);
177 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
178 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
179 return; // NOTREACHED
182 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
184 intval($page_owner_uid)
187 notice( t('Album not found.') . EOL);
188 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
189 return; // NOTREACHED
192 // Check if the user has responded to a delete confirmation query
193 if($_REQUEST['canceled']) {
194 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
197 $newalbum = notags(trim($_POST['albumname']));
198 if($newalbum != $album) {
199 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
202 intval($page_owner_uid)
204 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
205 goaway($a->get_baseurl() . '/' . $newurl);
206 return; // NOTREACHED
210 if($_POST['dropalbum'] == t('Delete Album')) {
212 // Check if we should do HTML-based delete confirmation
213 if($_REQUEST['confirm']) {
214 $drop_url = $a->query_string;
215 $extra_inputs = array(
216 array('name' => 'albumname', 'value' => $_POST['albumname']),
218 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
220 '$message' => t('Do you really want to delete this photo album and all its photos?'),
221 '$extra_inputs' => $extra_inputs,
222 '$confirm' => t('Delete Album'),
223 '$confirm_url' => $drop_url,
224 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
225 '$cancel' => t('Cancel'),
227 $a->error = 1; // Set $a->error so the other module functions don't execute
233 // get the list of photos we are about to delete
236 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
238 intval($page_owner_uid),
243 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
244 intval(local_user()),
250 $res[] = "'" . dbesc($rr['rid']) . "'" ;
254 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
255 return; // NOTREACHED
258 $str_res = implode(',', $res);
260 // remove the associated photos
262 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
263 intval($page_owner_uid)
266 // find and delete the corresponding item with all the comments and likes/dislikes
268 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
269 intval($page_owner_uid)
273 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
274 dbesc(datetime_convert()),
275 dbesc($rr['parent-uri']),
276 intval($page_owner_uid)
278 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
279 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
281 $drop_id = intval($rr['id']);
283 // send the notification upstream/downstream as the case may be
286 proc_run('php',"include/notifier.php","drop","$drop_id");
290 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
291 return; // NOTREACHED
295 // Check if the user has responded to a delete confirmation query for a single photo
296 if(($a->argc > 2) && $_REQUEST['canceled']) {
297 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
300 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
302 // same as above but remove single photo
304 // Check if we should do HTML-based delete confirmation
305 if($_REQUEST['confirm']) {
306 $drop_url = $a->query_string;
307 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
309 '$message' => t('Do you really want to delete this photo?'),
310 '$extra_inputs' => array(),
311 '$confirm' => t('Delete Photo'),
312 '$confirm_url' => $drop_url,
313 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
314 '$cancel' => t('Cancel'),
316 $a->error = 1; // Set $a->error so the other module functions don't execute
321 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
323 intval($page_owner_uid),
328 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
329 intval(local_user()),
334 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
335 intval($page_owner_uid),
336 dbesc($r[0]['resource-id'])
338 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
339 dbesc($r[0]['resource-id']),
340 intval($page_owner_uid)
343 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
344 dbesc(datetime_convert()),
345 dbesc(datetime_convert()),
347 intval($page_owner_uid)
349 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
350 delete_thread_uri($i[0]['uri'], $page_owner_uid);
352 $url = $a->get_baseurl();
353 $drop_id = intval($i[0]['id']);
356 proc_run('php',"include/notifier.php","drop","$drop_id");
360 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
361 return; // NOTREACHED
364 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
366 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
367 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
368 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
369 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
370 $str_group_allow = perms2str($_POST['group_allow']);
371 $str_contact_allow = perms2str($_POST['contact_allow']);
372 $str_group_deny = perms2str($_POST['group_deny']);
373 $str_contact_deny = perms2str($_POST['contact_deny']);
375 $resource_id = $a->argv[2];
377 if(! strlen($albname))
378 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
381 if((x($_POST,'rotate') !== false) &&
382 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
385 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
387 intval($page_owner_uid)
390 $ph = new Photo($r[0]['data'], $r[0]['type']);
391 if($ph->is_valid()) {
392 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
393 $ph->rotate($rotate_deg);
395 $width = $ph->getWidth();
396 $height = $ph->getHeight();
398 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
399 dbesc($ph->imageString()),
403 intval($page_owner_uid)
406 if($width > 640 || $height > 640) {
407 $ph->scaleImage(640);
408 $width = $ph->getWidth();
409 $height = $ph->getHeight();
411 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
412 dbesc($ph->imageString()),
416 intval($page_owner_uid)
420 if($width > 320 || $height > 320) {
421 $ph->scaleImage(320);
422 $width = $ph->getWidth();
423 $height = $ph->getHeight();
425 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
426 dbesc($ph->imageString()),
430 intval($page_owner_uid)
437 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
439 intval($page_owner_uid)
442 $ext = $phototypes[$p[0]['type']];
443 $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",
446 dbesc($str_contact_allow),
447 dbesc($str_group_allow),
448 dbesc($str_contact_deny),
449 dbesc($str_group_deny),
451 intval($page_owner_uid)
455 /* Don't make the item visible if the only change was the album name */
458 if($p[0]['desc'] !== $desc || strlen($rawtags))
463 // Create item container
466 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
470 $arr['uid'] = $page_owner_uid;
472 $arr['parent-uri'] = $uri;
473 $arr['type'] = 'photo';
475 $arr['resource-id'] = $p[0]['resource-id'];
476 $arr['contact-id'] = $owner_record['id'];
477 $arr['owner-name'] = $owner_record['name'];
478 $arr['owner-link'] = $owner_record['url'];
479 $arr['owner-avatar'] = $owner_record['thumb'];
480 $arr['author-name'] = $owner_record['name'];
481 $arr['author-link'] = $owner_record['url'];
482 $arr['author-avatar'] = $owner_record['thumb'];
483 $arr['title'] = $title;
484 $arr['allow_cid'] = $p[0]['allow_cid'];
485 $arr['allow_gid'] = $p[0]['allow_gid'];
486 $arr['deny_cid'] = $p[0]['deny_cid'];
487 $arr['deny_gid'] = $p[0]['deny_gid'];
488 $arr['last-child'] = 1;
489 $arr['visible'] = $visibility;
492 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
493 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
496 $item_id = item_store($arr);
501 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
503 intval($page_owner_uid)
507 $old_tag = $r[0]['tag'];
508 $old_inform = $r[0]['inform'];
511 if(strlen($rawtags)) {
516 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
518 $x = substr($rawtags,0,1);
519 if($x !== '@' && $x !== '#')
520 $rawtags = '#' . $rawtags;
523 $tags = get_tags($rawtags);
526 foreach($tags as $tag) {
529 if(strpos($tag,'@') === 0) {
530 $name = substr($tag,1);
531 if((strpos($name,'@')) || (strpos($name,'http://'))) {
533 $links = @lrdd($name);
535 foreach($links as $link) {
536 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
537 $profile = $link['@attributes']['href'];
538 if($link['@attributes']['rel'] === 'salmon') {
539 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
546 $taginfo[] = array($newname,$profile,$salmon);
552 if(strrpos($newname,'+'))
553 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
556 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
562 $newname = str_replace('_',' ',$name);
564 //select someone from this user's contacts by name
565 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
567 intval($page_owner_uid)
571 //select someone by attag or nick and the name passed in
572 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
575 intval($page_owner_uid)
579 /* elseif(strstr($name,'_') || strstr($name,' ')) {
580 $newname = str_replace('_',' ',$name);
581 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
583 intval($page_owner_uid)
587 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
590 intval($page_owner_uid)
594 $newname = $r[0]['name'];
595 $profile = $r[0]['url'];
596 $notify = 'cid:' . $r[0]['id'];
603 if(substr($notify,0,4) === 'cid:')
604 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
606 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
607 if(strlen($str_tags))
609 $profile = str_replace(',','%2c',$profile);
610 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
612 } elseif (strpos($tag,'#') === 0) {
613 $tagname = substr($tag, 1);
614 $str_tags .= '#[url='.$a->get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
620 if(strlen($newtag) && strlen($str_tags))
622 $newtag .= $str_tags;
624 $newinform = $old_inform;
625 if(strlen($newinform) && strlen($inform))
627 $newinform .= $inform;
629 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
632 dbesc(datetime_convert()),
633 dbesc(datetime_convert()),
635 intval($page_owner_uid)
637 create_tags_from_item($item_id);
638 update_thread($item_id);
641 foreach($p as $scales) {
642 if(intval($scales['scale']) == 2) {
646 if(intval($scales['scale']) == 4) {
652 if(count($taginfo)) {
653 foreach($taginfo as $tagged) {
655 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
659 $arr['uid'] = $page_owner_uid;
661 $arr['parent-uri'] = $uri;
662 $arr['type'] = 'activity';
664 $arr['contact-id'] = $owner_record['id'];
665 $arr['owner-name'] = $owner_record['name'];
666 $arr['owner-link'] = $owner_record['url'];
667 $arr['owner-avatar'] = $owner_record['thumb'];
668 $arr['author-name'] = $owner_record['name'];
669 $arr['author-link'] = $owner_record['url'];
670 $arr['author-avatar'] = $owner_record['thumb'];
672 $arr['allow_cid'] = $p[0]['allow_cid'];
673 $arr['allow_gid'] = $p[0]['allow_gid'];
674 $arr['deny_cid'] = $p[0]['deny_cid'];
675 $arr['deny_gid'] = $p[0]['deny_gid'];
676 $arr['last-child'] = 1;
678 $arr['verb'] = ACTIVITY_TAG;
679 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
680 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
681 $arr['tag'] = $tagged[4];
682 $arr['inform'] = $tagged[2];
684 $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]') ;
685 $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" ;
687 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
688 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
690 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
691 $arr['object'] .= '</link></object>' . "\n";
693 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
694 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
695 $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>';
697 $item_id = item_store($arr);
699 //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
700 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
701 // intval($page_owner_uid),
705 proc_run('php',"include/notifier.php","tag","$item_id");
712 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
713 return; // NOTREACHED
718 * default post action - upload a photo
721 call_hooks('photo_post_init', $_POST);
724 * Determine the album to use
727 $album = notags(trim($_REQUEST['album']));
728 $newalbum = notags(trim($_REQUEST['newalbum']));
730 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
732 if(! strlen($album)) {
733 if(strlen($newalbum))
736 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
741 * We create a wall item for every photo, but we don't want to
742 * overwhelm the data stream with a hundred newly uploaded photos.
743 * So we will make the first photo uploaded to this album in the last several hours
744 * visible by default, the rest will become visible over time when and if
745 * they acquire comments, likes, dislikes, and/or tags
749 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
751 intval($page_owner_uid)
753 if((! count($r)) || ($album == t('Profile Photos')))
758 if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
761 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
762 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
763 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
764 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
766 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
768 call_hooks('photo_post_file',$ret);
770 if(x($ret,'src') && x($ret,'filesize')) {
772 $filename = $ret['filename'];
773 $filesize = $ret['filesize'];
774 $type = $ret['type'];
777 $src = $_FILES['userfile']['tmp_name'];
778 $filename = basename($_FILES['userfile']['name']);
779 $filesize = intval($_FILES['userfile']['size']);
780 $type = $_FILES['userfile']['type'];
782 if ($type=="") $type=guess_image_type($filename);
784 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
786 $maximagesize = get_config('system','maximagesize');
788 if(($maximagesize) && ($filesize > $maximagesize)) {
789 notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
792 call_hooks('photo_post_end',$foo);
797 notice( t('Image file is empty.') . EOL);
800 call_hooks('photo_post_end',$foo);
804 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
806 $imagedata = @file_get_contents($src);
810 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
811 intval($a->data['user']['uid'])
814 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
816 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
817 notice( upgrade_message() . EOL );
820 call_hooks('photo_post_end',$foo);
825 $ph = new Photo($imagedata, $type);
827 if(! $ph->is_valid()) {
828 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
829 notice( t('Unable to process image.') . EOL );
832 call_hooks('photo_post_end',$foo);
839 $max_length = get_config('system','max_image_length');
841 $max_length = MAX_IMAGE_LENGTH;
843 $ph->scaleImage($max_length);
845 $width = $ph->getWidth();
846 $height = $ph->getHeight();
850 $photo_hash = photo_new_resource();
852 $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);
855 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
856 notice( t('Image upload failed.') . EOL );
860 if($width > 640 || $height > 640) {
861 $ph->scaleImage(640);
862 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
866 if($width > 320 || $height > 320) {
867 $ph->scaleImage(320);
868 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
872 $basename = basename($filename);
873 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
875 // Create item container
879 $arr['uid'] = $page_owner_uid;
881 $arr['parent-uri'] = $uri;
882 $arr['type'] = 'photo';
884 $arr['resource-id'] = $photo_hash;
885 $arr['contact-id'] = $owner_record['id'];
886 $arr['owner-name'] = $owner_record['name'];
887 $arr['owner-link'] = $owner_record['url'];
888 $arr['owner-avatar'] = $owner_record['thumb'];
889 $arr['author-name'] = $owner_record['name'];
890 $arr['author-link'] = $owner_record['url'];
891 $arr['author-avatar'] = $owner_record['thumb'];
893 $arr['allow_cid'] = $str_contact_allow;
894 $arr['allow_gid'] = $str_group_allow;
895 $arr['deny_cid'] = $str_contact_deny;
896 $arr['deny_gid'] = $str_group_deny;
897 $arr['last-child'] = 1;
898 $arr['visible'] = $visible;
901 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
902 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
905 $item_id = item_store($arr);
908 // q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
909 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
910 // intval($page_owner_uid),
916 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
918 call_hooks('photo_post_end',intval($item_id));
920 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
921 // if they do not wish to be redirected
923 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
929 function photos_content(&$a) {
933 // photos/name/upload
934 // photos/name/upload/xxxxx (xxxxx is album name)
935 // photos/name/album/xxxxx
936 // photos/name/album/xxxxx/edit
937 // photos/name/image/xxxxx
938 // photos/name/image/xxxxx/edit
941 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
942 notice( t('Public access denied.') . EOL);
947 require_once('include/bbcode.php');
948 require_once('include/security.php');
949 require_once('include/conversation.php');
951 if(! x($a->data,'user')) {
952 notice( t('No photos selected') . EOL );
956 $phototypes = Photo::supportedTypes();
958 $_SESSION['photo_return'] = $a->cmd;
965 $datatype = $a->argv[2];
966 $datum = $a->argv[3];
968 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
969 $datatype = 'upload';
971 $datatype = 'summary';
979 // Setup permissions structures
985 $remote_contact = false;
988 $owner_uid = $a->data['user']['uid'];
990 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
992 if((local_user()) && (local_user() == $owner_uid))
995 if($community_page && remote_user()) {
996 if(is_array($_SESSION['remote'])) {
997 foreach($_SESSION['remote'] as $v) {
998 if($v['uid'] == $owner_uid) {
999 $contact_id = $v['cid'];
1006 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1007 intval($contact_id),
1013 $remote_contact = true;
1020 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1022 if(remote_user() && (! $visitor)) {
1024 if(is_array($_SESSION['remote'])) {
1025 foreach($_SESSION['remote'] as $v) {
1026 if($v['uid'] == $owner_uid) {
1027 $contact_id = $v['cid'];
1033 $groups = init_groups_visitor($contact_id);
1034 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1035 intval($contact_id),
1040 $remote_contact = true;
1045 if(! $remote_contact) {
1047 $contact_id = $_SESSION['cid'];
1048 $contact = $a->contact;
1052 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1053 notice( t('Access to this item is restricted.') . EOL);
1057 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
1062 $_is_owner = (local_user() && (local_user() == $owner_uid));
1063 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
1070 if($datatype === 'upload') {
1072 notice( t('Permission denied.'));
1077 $selname = (($datum) ? hex2bin($datum) : '');
1083 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1084 if(count($a->data['albums'])) {
1085 foreach($a->data['albums'] as $album) {
1086 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
1088 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1089 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1095 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
1096 'addon_text' => $uploader,
1097 'default_upload' => true);
1100 call_hooks('photo_upload_form',$ret);
1102 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1103 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1104 '$submit' => t('Submit'),
1107 $usage_message = '';
1108 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1109 if($limit !== false) {
1111 $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1112 intval($a->data['user']['uid'])
1114 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1118 // Private/public post links for the non-JS ACL form
1120 if($_REQUEST['public'])
1123 $query_str = $a->query_string;
1124 if(strpos($query_str, 'public=1') !== false)
1125 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1127 // I think $a->query_string may never have ? in it, but I could be wrong
1128 // It looks like it's from the index.php?q=[etc] rewrite that the web
1129 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1130 if(strpos($query_str, '?') === false)
1131 $public_post_link = '?public=1';
1133 $public_post_link = '&public=1';
1137 $tpl = get_markup_template('photos_upload.tpl');
1139 if($a->theme['template_engine'] === 'internal') {
1140 $albumselect_e = template_escape($albumselect);
1141 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
1144 $albumselect_e = $albumselect;
1145 $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
1148 $o .= replace_macros($tpl,array(
1149 '$pagename' => t('Upload Photos'),
1150 '$sessid' => session_id(),
1151 '$usage' => $usage_message,
1152 '$nickname' => $a->data['user']['nickname'],
1153 '$newalbum' => t('New album name: '),
1154 '$existalbumtext' => t('or existing album name: '),
1155 '$nosharetext' => t('Do not show a status post for this upload'),
1156 '$albumselect' => $albumselect_e,
1157 '$permissions' => t('Permissions'),
1158 '$aclselect' => $aclselect_e,
1159 '$alt_uploader' => $ret['addon_text'],
1160 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1161 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1162 '$uploadurl' => $ret['post_url'],
1164 // ACL permissions box
1165 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1166 '$group_perms' => t('Show to Groups'),
1167 '$contact_perms' => t('Show to Contacts'),
1168 '$private' => t('Private Photo'),
1169 '$public' => t('Public Photo'),
1170 '$is_private' => $private_post,
1171 '$return_path' => $query_str,
1172 '$public_link' => $public_post_link,
1179 if($datatype === 'album') {
1181 $album = hex2bin($datum);
1183 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1184 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1189 $a->set_pager_total(count($r));
1190 $a->set_pager_itemspage(20);
1193 if($_GET['order'] === 'posted')
1198 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1199 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1202 intval($a->pager['start']),
1203 intval($a->pager['itemspage'])
1206 if($cmd === 'edit') {
1207 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1209 $edit_tpl = get_markup_template('album_edit.tpl');
1211 if($a->theme['template_engine'] === 'internal') {
1212 $album_e = template_escape($album);
1218 $o .= replace_macros($edit_tpl,array(
1219 '$nametext' => t('New album name: '),
1220 '$nickname' => $a->data['user']['nickname'],
1221 '$album' => $album_e,
1222 '$hexalbum' => bin2hex($album),
1223 '$submit' => t('Submit'),
1224 '$dropsubmit' => t('Delete Album')
1230 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1232 $edit = array(t('Edit Album'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1237 if($_GET['order'] === 'posted')
1238 $order = array(t('Show Newest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1240 $order = array(t('Show Oldest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1245 $twist = 'rotright';
1246 foreach($r as $rr) {
1247 if($twist == 'rotright')
1250 $twist = 'rotright';
1252 $ext = $phototypes[$rr['type']];
1254 if($a->theme['template_engine'] === 'internal') {
1255 $imgalt_e = template_escape($rr['filename']);
1256 $desc_e = template_escape($rr['desc']);
1259 $imgalt_e = $rr['filename'];
1260 $desc_e = $rr['desc'];
1265 'twist' => ' ' . $twist . rand(2,4),
1266 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1267 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1268 'title' => t('View Photo'),
1269 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1273 'hash'=> $rr['resource_id'],
1277 $tpl = get_markup_template('photo_album.tpl');
1278 $o .= replace_macros($tpl, array(
1279 '$photos' => $photos,
1281 '$can_post' => $can_post,
1282 '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1294 if($datatype === 'image') {
1299 // fetch image, item containing image, then comments
1301 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1302 $sql_extra ORDER BY `scale` ASC ",
1308 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1314 notice( t('Permission denied. Access to this item may be restricted.'));
1316 notice( t('Photo not available') . EOL );
1323 if($_GET['order'] === 'posted')
1329 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1330 $sql_extra ORDER BY `created` $order ",
1331 dbesc($ph[0]['album']),
1335 if(count($prvnxt)) {
1336 for($z = 0; $z < count($prvnxt); $z++) {
1337 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1341 $prv = count($prvnxt) - 1;
1342 if($nxt >= count($prvnxt))
1347 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1348 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1349 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1354 $hires = $lores = $ph[0];
1355 if(count($ph) > 1) {
1356 if($ph[1]['scale'] == 2) {
1357 // original is 640 or less, we can display it directly
1358 $hires = $lores = $ph[0];
1366 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1370 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1372 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1373 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1377 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1378 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1379 ? t('Private Message')
1385 if( $cmd === 'edit') {
1386 $tpl = get_markup_template('photo_edit_head.tpl');
1387 $a->page['htmlhead'] .= replace_macros($tpl,array(
1388 '$prevlink' => $prevlink,
1389 '$nextlink' => $nextlink
1394 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1397 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1398 'title'=> t('View Full Size'),
1399 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1400 'height' => $hires['height'],
1401 'width' => $hires['width'],
1402 'album' => $hires['album'],
1403 'filename' => $hires['filename'],
1407 $nextlink = array($nextlink, '<div class="icon next"></div>');
1410 // Do we have an item for this photo?
1412 // FIXME! - replace following code to display the conversation with our normal
1413 // conversation functions so that it works correctly and tracks changes
1414 // in the evolving conversation code.
1415 // The difference is that we won't be displaying the conversation head item
1416 // as a "post" but displaying instead the photo it is linked to
1418 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1421 if(count($linked_items)) {
1422 $link_item = $linked_items[0];
1423 $r = q("SELECT COUNT(*) AS `total`
1424 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1425 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1426 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1427 AND `item`.`uid` = %d
1429 dbesc($link_item['uri']),
1430 dbesc($link_item['uri']),
1431 intval($link_item['uid'])
1436 $a->set_pager_total($r[0]['total']);
1439 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1440 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1441 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1442 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1443 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1444 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1445 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1446 AND `item`.`uid` = %d
1448 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1449 dbesc($link_item['uri']),
1450 dbesc($link_item['uri']),
1451 intval($link_item['uid']),
1452 intval($a->pager['start']),
1453 intval($a->pager['itemspage'])
1457 if((local_user()) && (local_user() == $link_item['uid'])) {
1458 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1459 intval($link_item['parent']),
1460 intval(local_user())
1462 update_thread($link_item['parent']);
1468 if(count($linked_items) && strlen($link_item['tag'])) {
1469 $arr = explode(',',$link_item['tag']);
1470 // parse tags and add links
1472 foreach($arr as $t) {
1473 if(strlen($tag_str))
1475 $tag_str .= bbcode($t);
1477 $tags = array(t('Tags: '), $tag_str);
1478 if($cmd === 'edit') {
1479 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1480 $tags[] = t('[Remove any tag]');
1486 if(($cmd === 'edit') && ($can_post)) {
1487 $edit_tpl = get_markup_template('photo_edit.tpl');
1489 // Private/public post links for the non-JS ACL form
1491 if($_REQUEST['public'])
1494 $query_str = $a->query_string;
1495 if(strpos($query_str, 'public=1') !== false)
1496 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1498 // I think $a->query_string may never have ? in it, but I could be wrong
1499 // It looks like it's from the index.php?q=[etc] rewrite that the web
1500 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1501 if(strpos($query_str, '?') === false)
1502 $public_post_link = '?public=1';
1504 $public_post_link = '&public=1';
1507 if($a->theme['template_engine'] === 'internal') {
1508 $album_e = template_escape($ph[0]['album']);
1509 $caption_e = template_escape($ph[0]['desc']);
1510 $aclselect_e = template_escape(populate_acl($ph[0]));
1513 $album_e = $ph[0]['album'];
1514 $caption_e = $ph[0]['desc'];
1515 $aclselect_e = populate_acl($ph[0]);
1518 $edit = replace_macros($edit_tpl, array(
1519 '$id' => $ph[0]['id'],
1520 '$album' => array('albname', t('New album name'), $album_e,''),
1521 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1522 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1523 '$rotate_none' => array('rotate',t('Do not rotate'),0,'', true),
1524 '$rotate_cw' => array('rotate',t('Rotate CW (right)'),1,''),
1525 '$rotate_ccw' => array('rotate',t('Rotate CCW (left)'),2,''),
1527 '$nickname' => $a->data['user']['nickname'],
1528 '$resource_id' => $ph[0]['resource-id'],
1529 '$permissions' => t('Permissions'),
1530 '$aclselect' => $aclselect_e,
1532 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1533 '$submit' => t('Submit'),
1534 '$delete' => t('Delete Photo'),
1536 // ACL permissions box
1537 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1538 '$group_perms' => t('Show to Groups'),
1539 '$contact_perms' => t('Show to Contacts'),
1540 '$private' => t('Private photo'),
1541 '$public' => t('Public photo'),
1542 '$is_private' => $private_post,
1543 '$return_path' => $query_str,
1544 '$public_link' => $public_post_link,
1548 if(count($linked_items)) {
1550 $cmnt_tpl = get_markup_template('comment_item.tpl');
1551 $tpl = get_markup_template('photo_item.tpl');
1552 $return_url = $a->cmd;
1554 $like_tpl = get_markup_template('like_noshare.tpl');
1558 if($can_post || can_write_wall($a,$owner_uid)) {
1559 $likebuttons = replace_macros($like_tpl,array(
1560 '$id' => $link_item['id'],
1561 '$likethis' => t("I like this \x28toggle\x29"),
1562 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1563 '$share' => t('Share'),
1564 '$wait' => t('Please wait'),
1565 '$return_path' => $a->query_string,
1571 if($can_post || can_write_wall($a,$owner_uid)) {
1572 if($link_item['last-child']) {
1573 $comments .= replace_macros($cmnt_tpl,array(
1574 '$return_path' => '',
1575 '$jsreload' => $return_url,
1576 '$type' => 'wall-comment',
1577 '$id' => $link_item['id'],
1578 '$parent' => $link_item['id'],
1579 '$profile_uid' => $owner_uid,
1580 '$mylink' => $contact['url'],
1581 '$mytitle' => t('This is you'),
1582 '$myphoto' => $contact['thumb'],
1583 '$comment' => t('Comment'),
1584 '$submit' => t('Submit'),
1585 '$preview' => t('Preview'),
1586 '$sourceapp' => t($a->sourcename),
1588 '$rand_num' => random_digits(12)
1605 foreach($r as $item) {
1606 like_puller($a,$item,$alike,'like');
1607 like_puller($a,$item,$dlike,'dislike');
1610 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1611 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1615 if($can_post || can_write_wall($a,$owner_uid)) {
1616 if($link_item['last-child']) {
1617 $comments .= replace_macros($cmnt_tpl,array(
1618 '$return_path' => '',
1619 '$jsreload' => $return_url,
1620 '$type' => 'wall-comment',
1621 '$id' => $link_item['id'],
1622 '$parent' => $link_item['id'],
1623 '$profile_uid' => $owner_uid,
1624 '$mylink' => $contact['url'],
1625 '$mytitle' => t('This is you'),
1626 '$myphoto' => $contact['thumb'],
1627 '$comment' => t('Comment'),
1628 '$submit' => t('Submit'),
1629 '$preview' => t('Preview'),
1630 '$sourceapp' => t($a->sourcename),
1632 '$rand_num' => random_digits(12)
1638 foreach($r as $item) {
1643 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1646 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1649 if(local_user() && ($item['contact-uid'] == local_user())
1650 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1651 $profile_url = $redirect_url;
1652 $sparkle = ' sparkle';
1655 $profile_url = $item['url'];
1659 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1661 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1662 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1664 $profile_link = $profile_url;
1668 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1670 'dropping' => $dropping,
1671 'pagedrop' => false,
1672 'select' => t('Select'),
1673 'delete' => t('Delete'),
1677 if($a->theme['template_engine'] === 'internal') {
1678 $name_e = template_escape($profile_name);
1679 $title_e = template_escape($item['title']);
1680 $body_e = template_escape(bbcode($item['body']));
1683 $name_e = $profile_name;
1684 $title_e = $item['title'];
1685 $body_e = bbcode($item['body']);
1688 $comments .= replace_macros($template,array(
1689 '$id' => $item['item_id'],
1690 '$profile_url' => $profile_link,
1692 '$thumb' => $profile_avatar,
1693 '$sparkle' => $sparkle,
1694 '$title' => $title_e,
1696 '$ago' => relative_date($item['created']),
1697 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1699 '$comment' => $comment
1702 if($can_post || can_write_wall($a,$owner_uid)) {
1704 if($item['last-child']) {
1705 $comments .= replace_macros($cmnt_tpl,array(
1706 '$return_path' => '',
1707 '$jsreload' => $return_url,
1708 '$type' => 'wall-comment',
1709 '$id' => $item['item_id'],
1710 '$parent' => $item['parent'],
1711 '$profile_uid' => $owner_uid,
1712 '$mylink' => $contact['url'],
1713 '$mytitle' => t('This is you'),
1714 '$myphoto' => $contact['thumb'],
1715 '$comment' => t('Comment'),
1716 '$submit' => t('Submit'),
1717 '$preview' => t('Preview'),
1718 '$sourceapp' => t($a->sourcename),
1720 '$rand_num' => random_digits(12)
1727 $paginate = paginate($a);
1730 $photo_tpl = get_markup_template('photo_view.tpl');
1732 if($a->theme['template_engine'] === 'internal') {
1733 $album_e = array($album_link,template_escape($ph[0]['album']));
1734 $tags_e = template_escape($tags);
1735 $like_e = template_escape($like);
1736 $dislike_e = template_escape($dislike);
1739 $album_e = array($album_link,$ph[0]['album']);
1742 $dislike_e = $dislike;
1745 $o .= replace_macros($photo_tpl, array(
1746 '$id' => $ph[0]['id'],
1747 '$album' => $album_e,
1751 '$prevlink' => $prevlink,
1752 '$nextlink' => $nextlink,
1753 '$desc' => $ph[0]['desc'],
1756 '$likebuttons' => $likebuttons,
1758 '$dislike' => $dikslike_e,
1759 '$comments' => $comments,
1760 '$paginate' => $paginate,
1763 $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
1764 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
1765 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
1766 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
1767 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
1772 // Default - show recent photos with upload link (if applicable)
1775 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1776 $sql_extra GROUP BY `resource-id`",
1777 intval($a->data['user']['uid']),
1778 dbesc('Contact Photos'),
1779 dbesc( t('Contact Photos'))
1782 $a->set_pager_total(count($r));
1783 $a->set_pager_itemspage(20);
1786 $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
1787 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1788 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1789 intval($a->data['user']['uid']),
1790 dbesc('Contact Photos'),
1791 dbesc( t('Contact Photos')),
1792 intval($a->pager['start']),
1793 intval($a->pager['itemspage'])
1800 $twist = 'rotright';
1801 foreach($r as $rr) {
1802 if($twist == 'rotright')
1805 $twist = 'rotright';
1806 $ext = $phototypes[$rr['type']];
1808 if($a->theme['template_engine'] === 'internal') {
1809 $alt_e = template_escape($rr['filename']);
1810 $name_e = template_escape($rr['album']);
1813 $alt_e = $rr['filename'];
1814 $name_e = $rr['album'];
1819 'twist' => ' ' . $twist . rand(2,4),
1820 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1821 'title' => t('View Photo'),
1822 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1825 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1827 'alt' => t('View Album'),
1834 $tpl = get_markup_template('photos_recent.tpl');
1835 $o .= replace_macros($tpl, array(
1836 '$title' => t('Recent Photos'),
1837 '$can_post' => $can_post,
1838 '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),
1839 '$photos' => $photos,