2 require_once('include/Photo.php');
3 require_once('include/photos.php');
4 require_once('include/items.php');
5 require_once('include/acl_selectors.php');
6 require_once('include/bbcode.php');
7 require_once('include/security.php');
8 require_once('include/redir.php');
9 require_once('include/tags.php');
10 require_once('include/threads.php');
12 function photos_init(&$a) {
15 auto_redir($a, $a->argv[1]);
17 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
25 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
32 $a->data['user'] = $r[0];
33 $a->profile_uid = $r[0]['uid'];
34 $is_owner = (local_user() && (local_user() == $a->profile_uid));
36 $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg');
38 $tpl = get_markup_template("vcard-widget.tpl");
40 $vcard_widget .= replace_macros($tpl, array(
41 '$name' => $a->data['user']['username'],
42 '$photo' => $profilephoto
46 $sql_extra = permissions_sql($a->data['user']['uid']);
48 $albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
49 $sql_extra group by album order by created desc",
50 intval($a->data['user']['uid']),
51 dbesc('Contact Photos'),
52 dbesc( t('Contact Photos'))
55 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
57 // add various encodings to the array so we can just loop through and pick them out in a template
58 $ret = array('success' => false);
61 $a->data['albums'] = $albums;
63 $ret['success'] = true;
65 $ret['albums'] = array();
66 foreach($albums as $k => $album) {
67 //hide profile photos to others
68 if((! $is_owner) && (! remote_user()) && ($album['album'] == t('Profile Photos')))
71 'text' => $album['album'],
72 'total' => $album['total'],
73 'url' => z_root() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
74 'urlencode' => urlencode($album['album']),
75 'bin2hex' => bin2hex($album['album'])
77 $ret['albums'][] = $entry;
83 if(local_user() && $a->data['user']['uid'] == local_user())
86 if($albums['success']) {
87 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array(
88 '$nick' => $a->data['user']['nickname'],
89 '$title' => t('Photo Albums'),
90 'recent' => t('Recent Photos'),
91 '$albums' => $albums['albums'],
92 '$baseurl' => z_root(),
93 '$upload' => array( t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload'),
94 '$can_post' => $can_post
99 if(! x($a->page,'aside'))
100 $a->page['aside'] = '';
101 $a->page['aside'] .= $vcard_widget;
102 $a->page['aside'] .= $photo_albums_widget;
105 $tpl = get_markup_template("photos_head.tpl");
106 $a->page['htmlhead'] .= replace_macros($tpl,array(
107 '$ispublic' => t('everybody')
117 function photos_post(&$a) {
119 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
122 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
123 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
125 $phototypes = Photo::supportedTypes();
130 $page_owner_uid = $a->data['user']['uid'];
131 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
133 if((local_user()) && (local_user() == $page_owner_uid))
136 if($community_page && remote_user()) {
138 if(is_array($_SESSION['remote'])) {
139 foreach($_SESSION['remote'] as $v) {
140 if($v['uid'] == $page_owner_uid) {
148 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
150 intval($page_owner_uid)
161 notice( t('Permission denied.') . EOL );
165 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
166 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
167 intval($page_owner_uid)
171 notice( t('Contact information unavailable') . EOL);
172 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
176 $owner_record = $r[0];
179 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
180 $album = hex2bin($a->argv[3]);
182 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
183 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
184 return; // NOTREACHED
187 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
189 intval($page_owner_uid)
192 notice( t('Album not found.') . EOL);
193 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
194 return; // NOTREACHED
197 // Check if the user has responded to a delete confirmation query
198 if($_REQUEST['canceled']) {
199 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
206 $newalbum = notags(trim($_POST['albumname']));
207 if($newalbum != $album) {
208 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
211 intval($page_owner_uid)
213 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
214 goaway($a->get_baseurl() . '/' . $newurl);
215 return; // NOTREACHED
219 * DELETE photo album and all its photos
222 if($_POST['dropalbum'] == t('Delete Album')) {
224 // Check if we should do HTML-based delete confirmation
225 if($_REQUEST['confirm']) {
226 $drop_url = $a->query_string;
227 $extra_inputs = array(
228 array('name' => 'albumname', 'value' => $_POST['albumname']),
230 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
232 '$message' => t('Do you really want to delete this photo album and all its photos?'),
233 '$extra_inputs' => $extra_inputs,
234 '$confirm' => t('Delete Album'),
235 '$confirm_url' => $drop_url,
236 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
237 '$cancel' => t('Cancel'),
239 $a->error = 1; // Set $a->error so the other module functions don't execute
245 // get the list of photos we are about to delete
248 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
250 intval($page_owner_uid),
255 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
256 intval(local_user()),
262 $res[] = "'" . dbesc($rr['rid']) . "'" ;
266 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
267 return; // NOTREACHED
270 $str_res = implode(',', $res);
272 // remove the associated photos
274 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
275 intval($page_owner_uid)
278 // find and delete the corresponding item with all the comments and likes/dislikes
280 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
281 intval($page_owner_uid)
285 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
286 dbesc(datetime_convert()),
287 dbesc($rr['parent-uri']),
288 intval($page_owner_uid)
290 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
291 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
293 $drop_id = intval($rr['id']);
295 // send the notification upstream/downstream as the case may be
298 proc_run('php',"include/notifier.php","drop","$drop_id");
302 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
303 return; // NOTREACHED
307 // Check if the user has responded to a delete confirmation query for a single photo
308 if(($a->argc > 2) && $_REQUEST['canceled']) {
309 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
312 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
314 // same as above but remove single photo
316 // Check if we should do HTML-based delete confirmation
317 if($_REQUEST['confirm']) {
318 $drop_url = $a->query_string;
319 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
321 '$message' => t('Do you really want to delete this photo?'),
322 '$extra_inputs' => array(),
323 '$confirm' => t('Delete Photo'),
324 '$confirm_url' => $drop_url,
325 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
326 '$cancel' => t('Cancel'),
328 $a->error = 1; // Set $a->error so the other module functions don't execute
333 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
335 intval($page_owner_uid),
340 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
341 intval(local_user()),
346 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
347 intval($page_owner_uid),
348 dbesc($r[0]['resource-id'])
350 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
351 dbesc($r[0]['resource-id']),
352 intval($page_owner_uid)
355 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
356 dbesc(datetime_convert()),
357 dbesc(datetime_convert()),
359 intval($page_owner_uid)
361 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
362 delete_thread_uri($i[0]['uri'], $page_owner_uid);
364 $url = $a->get_baseurl();
365 $drop_id = intval($i[0]['id']);
368 proc_run('php',"include/notifier.php","drop","$drop_id");
372 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
373 return; // NOTREACHED
376 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
378 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
379 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
380 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
381 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
382 $str_group_allow = perms2str($_POST['group_allow']);
383 $str_contact_allow = perms2str($_POST['contact_allow']);
384 $str_group_deny = perms2str($_POST['group_deny']);
385 $str_contact_deny = perms2str($_POST['contact_deny']);
387 $resource_id = $a->argv[2];
389 if(! strlen($albname))
390 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
393 if((x($_POST,'rotate') !== false) &&
394 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
397 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
399 intval($page_owner_uid)
402 $ph = new Photo($r[0]['data'], $r[0]['type']);
403 if($ph->is_valid()) {
404 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
405 $ph->rotate($rotate_deg);
407 $width = $ph->getWidth();
408 $height = $ph->getHeight();
410 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
411 dbesc($ph->imageString()),
415 intval($page_owner_uid)
418 if($width > 640 || $height > 640) {
419 $ph->scaleImage(640);
420 $width = $ph->getWidth();
421 $height = $ph->getHeight();
423 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
424 dbesc($ph->imageString()),
428 intval($page_owner_uid)
432 if($width > 320 || $height > 320) {
433 $ph->scaleImage(320);
434 $width = $ph->getWidth();
435 $height = $ph->getHeight();
437 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
438 dbesc($ph->imageString()),
442 intval($page_owner_uid)
449 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
451 intval($page_owner_uid)
454 $ext = $phototypes[$p[0]['type']];
455 $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",
458 dbesc($str_contact_allow),
459 dbesc($str_group_allow),
460 dbesc($str_contact_deny),
461 dbesc($str_group_deny),
463 intval($page_owner_uid)
467 /* Don't make the item visible if the only change was the album name */
470 if($p[0]['desc'] !== $desc || strlen($rawtags))
475 // Create item container
478 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
482 $arr['uid'] = $page_owner_uid;
484 $arr['parent-uri'] = $uri;
485 $arr['type'] = 'photo';
487 $arr['resource-id'] = $p[0]['resource-id'];
488 $arr['contact-id'] = $owner_record['id'];
489 $arr['owner-name'] = $owner_record['name'];
490 $arr['owner-link'] = $owner_record['url'];
491 $arr['owner-avatar'] = $owner_record['thumb'];
492 $arr['author-name'] = $owner_record['name'];
493 $arr['author-link'] = $owner_record['url'];
494 $arr['author-avatar'] = $owner_record['thumb'];
495 $arr['title'] = $title;
496 $arr['allow_cid'] = $p[0]['allow_cid'];
497 $arr['allow_gid'] = $p[0]['allow_gid'];
498 $arr['deny_cid'] = $p[0]['deny_cid'];
499 $arr['deny_gid'] = $p[0]['deny_gid'];
500 $arr['last-child'] = 1;
501 $arr['visible'] = $visibility;
504 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
505 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
508 $item_id = item_store($arr);
513 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
515 intval($page_owner_uid)
519 $old_tag = $r[0]['tag'];
520 $old_inform = $r[0]['inform'];
523 if(strlen($rawtags)) {
528 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
530 $x = substr($rawtags,0,1);
531 if($x !== '@' && $x !== '#')
532 $rawtags = '#' . $rawtags;
535 $tags = get_tags($rawtags);
538 foreach($tags as $tag) {
541 if(strpos($tag,'@') === 0) {
542 $name = substr($tag,1);
543 if((strpos($name,'@')) || (strpos($name,'http://'))) {
545 $links = @lrdd($name);
547 foreach($links as $link) {
548 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
549 $profile = $link['@attributes']['href'];
550 if($link['@attributes']['rel'] === 'salmon') {
551 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
558 $taginfo[] = array($newname,$profile,$salmon);
564 if(strrpos($newname,'+'))
565 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
568 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
574 $newname = str_replace('_',' ',$name);
576 //select someone from this user's contacts by name
577 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
579 intval($page_owner_uid)
583 //select someone by attag or nick and the name passed in
584 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
587 intval($page_owner_uid)
591 /* elseif(strstr($name,'_') || strstr($name,' ')) {
592 $newname = str_replace('_',' ',$name);
593 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
595 intval($page_owner_uid)
599 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
602 intval($page_owner_uid)
606 $newname = $r[0]['name'];
607 $profile = $r[0]['url'];
608 $notify = 'cid:' . $r[0]['id'];
615 if(substr($notify,0,4) === 'cid:')
616 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
618 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
619 if(strlen($str_tags))
621 $profile = str_replace(',','%2c',$profile);
622 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
624 } elseif (strpos($tag,'#') === 0) {
625 $tagname = substr($tag, 1);
626 $str_tags .= '#[url='.$a->get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
632 if(strlen($newtag) && strlen($str_tags))
634 $newtag .= $str_tags;
636 $newinform = $old_inform;
637 if(strlen($newinform) && strlen($inform))
639 $newinform .= $inform;
641 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
644 dbesc(datetime_convert()),
645 dbesc(datetime_convert()),
647 intval($page_owner_uid)
649 create_tags_from_item($item_id);
650 update_thread($item_id);
653 foreach($p as $scales) {
654 if(intval($scales['scale']) == 2) {
658 if(intval($scales['scale']) == 4) {
664 if(count($taginfo)) {
665 foreach($taginfo as $tagged) {
667 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
671 $arr['uid'] = $page_owner_uid;
673 $arr['parent-uri'] = $uri;
674 $arr['type'] = 'activity';
676 $arr['contact-id'] = $owner_record['id'];
677 $arr['owner-name'] = $owner_record['name'];
678 $arr['owner-link'] = $owner_record['url'];
679 $arr['owner-avatar'] = $owner_record['thumb'];
680 $arr['author-name'] = $owner_record['name'];
681 $arr['author-link'] = $owner_record['url'];
682 $arr['author-avatar'] = $owner_record['thumb'];
684 $arr['allow_cid'] = $p[0]['allow_cid'];
685 $arr['allow_gid'] = $p[0]['allow_gid'];
686 $arr['deny_cid'] = $p[0]['deny_cid'];
687 $arr['deny_gid'] = $p[0]['deny_gid'];
688 $arr['last-child'] = 1;
690 $arr['verb'] = ACTIVITY_TAG;
691 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
692 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
693 $arr['tag'] = $tagged[4];
694 $arr['inform'] = $tagged[2];
696 $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]') ;
697 $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" ;
699 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
700 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
702 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
703 $arr['object'] .= '</link></object>' . "\n";
705 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
706 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
707 $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>';
709 $item_id = item_store($arr);
711 //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
712 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
713 // intval($page_owner_uid),
717 proc_run('php',"include/notifier.php","tag","$item_id");
724 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
725 return; // NOTREACHED
730 * default post action - upload a photo
733 call_hooks('photo_post_init', $_POST);
736 * Determine the album to use
739 $album = notags(trim($_REQUEST['album']));
740 $newalbum = notags(trim($_REQUEST['newalbum']));
742 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
744 if(! strlen($album)) {
745 if(strlen($newalbum))
748 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
753 * We create a wall item for every photo, but we don't want to
754 * overwhelm the data stream with a hundred newly uploaded photos.
755 * So we will make the first photo uploaded to this album in the last several hours
756 * visible by default, the rest will become visible over time when and if
757 * they acquire comments, likes, dislikes, and/or tags
761 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
763 intval($page_owner_uid)
765 if((! count($r)) || ($album == t('Profile Photos')))
770 if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
773 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
774 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
775 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
776 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
778 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
780 call_hooks('photo_post_file',$ret);
782 if(x($ret,'src') && x($ret,'filesize')) {
784 $filename = $ret['filename'];
785 $filesize = $ret['filesize'];
786 $type = $ret['type'];
789 $src = $_FILES['userfile']['tmp_name'];
790 $filename = basename($_FILES['userfile']['name']);
791 $filesize = intval($_FILES['userfile']['size']);
792 $type = $_FILES['userfile']['type'];
794 if ($type=="") $type=guess_image_type($filename);
796 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
798 $maximagesize = get_config('system','maximagesize');
800 if(($maximagesize) && ($filesize > $maximagesize)) {
801 notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
804 call_hooks('photo_post_end',$foo);
809 notice( t('Image file is empty.') . EOL);
812 call_hooks('photo_post_end',$foo);
816 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
818 $imagedata = @file_get_contents($src);
822 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
823 intval($a->data['user']['uid'])
826 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
828 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
829 notice( upgrade_message() . EOL );
832 call_hooks('photo_post_end',$foo);
837 $ph = new Photo($imagedata, $type);
839 if(! $ph->is_valid()) {
840 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
841 notice( t('Unable to process image.') . EOL );
844 call_hooks('photo_post_end',$foo);
848 $exif = $ph->orient($src);
851 $max_length = get_config('system','max_image_length');
853 $max_length = MAX_IMAGE_LENGTH;
855 $ph->scaleImage($max_length);
857 $width = $ph->getWidth();
858 $height = $ph->getHeight();
862 $photo_hash = photo_new_resource();
864 $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);
867 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
868 notice( t('Image upload failed.') . EOL );
872 if($width > 640 || $height > 640) {
873 $ph->scaleImage(640);
874 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
878 if($width > 320 || $height > 320) {
879 $ph->scaleImage(320);
880 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
884 $basename = basename($filename);
885 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
887 // Create item container
891 if($exif && $exif['GPS']) {
892 if(feature_enabled($channel_id,'photo_location')) {
893 $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
894 $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
901 $arr['coord'] = $lat . ' ' . $lon;
903 $arr['uid'] = $page_owner_uid;
905 $arr['parent-uri'] = $uri;
906 $arr['type'] = 'photo';
908 $arr['resource-id'] = $photo_hash;
909 $arr['contact-id'] = $owner_record['id'];
910 $arr['owner-name'] = $owner_record['name'];
911 $arr['owner-link'] = $owner_record['url'];
912 $arr['owner-avatar'] = $owner_record['thumb'];
913 $arr['author-name'] = $owner_record['name'];
914 $arr['author-link'] = $owner_record['url'];
915 $arr['author-avatar'] = $owner_record['thumb'];
917 $arr['allow_cid'] = $str_contact_allow;
918 $arr['allow_gid'] = $str_group_allow;
919 $arr['deny_cid'] = $str_contact_deny;
920 $arr['deny_gid'] = $str_group_deny;
921 $arr['last-child'] = 1;
922 $arr['visible'] = $visible;
925 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
926 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
929 $item_id = item_store($arr);
932 // q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
933 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
934 // intval($page_owner_uid),
940 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
942 call_hooks('photo_post_end',intval($item_id));
944 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
945 // if they do not wish to be redirected
947 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
953 function photos_content(&$a) {
957 // photos/name/upload
958 // photos/name/upload/xxxxx (xxxxx is album name)
959 // photos/name/album/xxxxx
960 // photos/name/album/xxxxx/edit
961 // photos/name/image/xxxxx
962 // photos/name/image/xxxxx/edit
965 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
966 notice( t('Public access denied.') . EOL);
971 require_once('include/bbcode.php');
972 require_once('include/security.php');
973 require_once('include/conversation.php');
975 if(! x($a->data,'user')) {
976 notice( t('No photos selected') . EOL );
980 $phototypes = Photo::supportedTypes();
982 $_SESSION['photo_return'] = $a->cmd;
989 $datatype = $a->argv[2];
990 $datum = $a->argv[3];
992 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
993 $datatype = 'upload';
995 $datatype = 'summary';
1003 // Setup permissions structures
1009 $remote_contact = false;
1012 $owner_uid = $a->data['user']['uid'];
1014 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
1016 if((local_user()) && (local_user() == $owner_uid))
1019 if($community_page && remote_user()) {
1020 if(is_array($_SESSION['remote'])) {
1021 foreach($_SESSION['remote'] as $v) {
1022 if($v['uid'] == $owner_uid) {
1023 $contact_id = $v['cid'];
1030 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1031 intval($contact_id),
1037 $remote_contact = true;
1044 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1046 if(remote_user() && (! $visitor)) {
1048 if(is_array($_SESSION['remote'])) {
1049 foreach($_SESSION['remote'] as $v) {
1050 if($v['uid'] == $owner_uid) {
1051 $contact_id = $v['cid'];
1057 $groups = init_groups_visitor($contact_id);
1058 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1059 intval($contact_id),
1064 $remote_contact = true;
1069 if(! $remote_contact) {
1071 $contact_id = $_SESSION['cid'];
1072 $contact = $a->contact;
1076 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1077 notice( t('Access to this item is restricted.') . EOL);
1081 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
1086 $is_owner = (local_user() && (local_user() == $owner_uid));
1087 $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']);
1090 * Display upload form
1093 if($datatype === 'upload') {
1095 notice( t('Permission denied.'));
1100 $selname = (($datum) ? hex2bin($datum) : '');
1106 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1107 if(count($a->data['albums'])) {
1108 foreach($a->data['albums'] as $album) {
1109 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
1111 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1112 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1118 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
1119 'addon_text' => $uploader,
1120 'default_upload' => true);
1123 call_hooks('photo_upload_form',$ret);
1125 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1126 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1127 '$submit' => t('Submit'),
1130 $usage_message = '';
1131 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1132 if($limit !== false) {
1134 $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1135 intval($a->data['user']['uid'])
1137 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1141 // Private/public post links for the non-JS ACL form
1143 if($_REQUEST['public'])
1146 $query_str = $a->query_string;
1147 if(strpos($query_str, 'public=1') !== false)
1148 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1150 // I think $a->query_string may never have ? in it, but I could be wrong
1151 // It looks like it's from the index.php?q=[etc] rewrite that the web
1152 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1153 if(strpos($query_str, '?') === false)
1154 $public_post_link = '?public=1';
1156 $public_post_link = '&public=1';
1160 $tpl = get_markup_template('photos_upload.tpl');
1162 if($a->theme['template_engine'] === 'internal') {
1163 $albumselect_e = template_escape($albumselect);
1164 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
1167 $albumselect_e = $albumselect;
1168 $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
1171 $o .= replace_macros($tpl,array(
1172 '$pagename' => t('Upload Photos'),
1173 '$sessid' => session_id(),
1174 '$usage' => $usage_message,
1175 '$nickname' => $a->data['user']['nickname'],
1176 '$newalbum' => t('New album name: '),
1177 '$existalbumtext' => t('or existing album name: '),
1178 '$nosharetext' => t('Do not show a status post for this upload'),
1179 '$albumselect' => $albumselect_e,
1180 '$permissions' => t('Permissions'),
1181 '$aclselect' => $aclselect_e,
1182 '$alt_uploader' => $ret['addon_text'],
1183 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1184 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1185 '$uploadurl' => $ret['post_url'],
1187 // ACL permissions box
1188 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1189 '$group_perms' => t('Show to Groups'),
1190 '$contact_perms' => t('Show to Contacts'),
1191 '$private' => t('Private Photo'),
1192 '$public' => t('Public Photo'),
1193 '$is_private' => $private_post,
1194 '$return_path' => $query_str,
1195 '$public_link' => $public_post_link,
1203 * Display a single photo album
1206 if($datatype === 'album') {
1208 $album = hex2bin($datum);
1210 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1211 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1216 $a->set_pager_total(count($r));
1217 $a->set_pager_itemspage(20);
1220 if($_GET['order'] === 'posted')
1225 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1226 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1229 intval($a->pager['start']),
1230 intval($a->pager['itemspage'])
1234 if($cmd === 'edit') {
1235 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1237 $edit_tpl = get_markup_template('album_edit.tpl');
1239 if($a->theme['template_engine'] === 'internal') {
1240 $album_e = template_escape($album);
1246 $o .= replace_macros($edit_tpl,array(
1247 '$nametext' => t('New album name: '),
1248 '$nickname' => $a->data['user']['nickname'],
1249 '$album' => $album_e,
1250 '$hexalbum' => bin2hex($album),
1251 '$submit' => t('Submit'),
1252 '$dropsubmit' => t('Delete Album')
1258 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1260 $edit = array(t('Edit Album'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1265 if($_GET['order'] === 'posted')
1266 $order = array(t('Show Newest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1268 $order = array(t('Show Oldest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1273 $twist = 'rotright';
1274 foreach($r as $rr) {
1275 if($twist == 'rotright')
1278 $twist = 'rotright';
1280 $ext = $phototypes[$rr['type']];
1282 if($a->theme['template_engine'] === 'internal') {
1283 $imgalt_e = template_escape($rr['filename']);
1284 $desc_e = template_escape($rr['desc']);
1287 $imgalt_e = $rr['filename'];
1288 $desc_e = $rr['desc'];
1293 'twist' => ' ' . $twist . rand(2,4),
1294 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1295 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1296 'title' => t('View Photo'),
1297 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1301 'hash'=> $rr['resource_id'],
1305 $tpl = get_markup_template('photo_album.tpl');
1306 $o .= replace_macros($tpl, array(
1307 '$photos' => $photos,
1309 '$can_post' => $can_post,
1310 '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1325 if($datatype === 'image') {
1328 // fetch image, item containing image, then comments
1330 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1331 $sql_extra ORDER BY `scale` ASC ",
1337 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1343 notice( t('Permission denied. Access to this item may be restricted.'));
1345 notice( t('Photo not available') . EOL );
1352 if($_GET['order'] === 'posted')
1358 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1359 $sql_extra ORDER BY `created` $order ",
1360 dbesc($ph[0]['album']),
1364 if(count($prvnxt)) {
1365 for($z = 0; $z < count($prvnxt); $z++) {
1366 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1370 $prv = count($prvnxt) - 1;
1371 if($nxt >= count($prvnxt))
1376 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1377 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1378 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1383 $hires = $lores = $ph[0];
1384 if(count($ph) > 1) {
1385 if($ph[1]['scale'] == 2) {
1386 // original is 640 or less, we can display it directly
1387 $hires = $lores = $ph[0];
1395 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1399 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1401 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1402 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1406 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1407 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1408 ? t('Private Message')
1414 if( $cmd === 'edit') {
1415 $tpl = get_markup_template('photo_edit_head.tpl');
1416 $a->page['htmlhead'] .= replace_macros($tpl,array(
1417 '$prevlink' => $prevlink,
1418 '$nextlink' => $nextlink
1423 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1426 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1427 'title'=> t('View Full Size'),
1428 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1429 'height' => $hires['height'],
1430 'width' => $hires['width'],
1431 'album' => $hires['album'],
1432 'filename' => $hires['filename'],
1436 $nextlink = array($nextlink, '<div class="icon next"></div>');
1439 // Do we have an item for this photo?
1441 // FIXME! - replace following code to display the conversation with our normal
1442 // conversation functions so that it works correctly and tracks changes
1443 // in the evolving conversation code.
1444 // The difference is that we won't be displaying the conversation head item
1445 // as a "post" but displaying instead the photo it is linked to
1447 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1453 if(count($linked_items)) {
1454 $link_item = $linked_items[0];
1455 $r = q("SELECT COUNT(*) AS `total`
1456 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1457 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1458 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1459 AND `item`.`uid` = %d
1461 dbesc($link_item['uri']),
1462 dbesc($link_item['uri']),
1463 intval($link_item['uid'])
1468 $a->set_pager_total($r[0]['total']);
1471 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1472 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1473 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1474 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1475 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1476 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1477 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1478 AND `item`.`uid` = %d
1480 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1481 dbesc($link_item['uri']),
1482 dbesc($link_item['uri']),
1483 intval($link_item['uid']),
1484 intval($a->pager['start']),
1485 intval($a->pager['itemspage'])
1489 if((local_user()) && (local_user() == $link_item['uid'])) {
1490 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1491 intval($link_item['parent']),
1492 intval(local_user())
1494 update_thread($link_item['parent']);
1497 if($link_item['coord']) {
1498 $map = generate_map($link_item['coord']);
1504 if(count($linked_items) && strlen($link_item['tag'])) {
1505 $arr = explode(',',$link_item['tag']);
1506 // parse tags and add links
1508 foreach($arr as $t) {
1509 if(strlen($tag_str))
1511 $tag_str .= bbcode($t);
1513 $tags = array(t('Tags: '), $tag_str);
1514 if($cmd === 'edit') {
1515 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1516 $tags[] = t('[Remove any tag]');
1522 if(($cmd === 'edit') && ($can_post)) {
1523 $edit_tpl = get_markup_template('photo_edit.tpl');
1525 // Private/public post links for the non-JS ACL form
1527 if($_REQUEST['public'])
1530 $query_str = $a->query_string;
1531 if(strpos($query_str, 'public=1') !== false)
1532 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1534 // I think $a->query_string may never have ? in it, but I could be wrong
1535 // It looks like it's from the index.php?q=[etc] rewrite that the web
1536 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1537 if(strpos($query_str, '?') === false)
1538 $public_post_link = '?public=1';
1540 $public_post_link = '&public=1';
1543 if($a->theme['template_engine'] === 'internal') {
1544 $album_e = template_escape($ph[0]['album']);
1545 $caption_e = template_escape($ph[0]['desc']);
1546 $aclselect_e = template_escape(populate_acl($ph[0]));
1549 $album_e = $ph[0]['album'];
1550 $caption_e = $ph[0]['desc'];
1551 $aclselect_e = populate_acl($ph[0]);
1554 $edit = replace_macros($edit_tpl, array(
1555 '$id' => $ph[0]['id'],
1556 '$album' => array('albname', t('New album name'), $album_e,''),
1557 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1558 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1559 '$rotate_none' => array('rotate',t('Do not rotate'),0,'', true),
1560 '$rotate_cw' => array('rotate',t('Rotate CW (right)'),1,''),
1561 '$rotate_ccw' => array('rotate',t('Rotate CCW (left)'),2,''),
1563 '$nickname' => $a->data['user']['nickname'],
1564 '$resource_id' => $ph[0]['resource-id'],
1565 '$permissions' => t('Permissions'),
1566 '$aclselect' => $aclselect_e,
1568 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1569 '$submit' => t('Submit'),
1570 '$delete' => t('Delete Photo'),
1572 // ACL permissions box
1573 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1574 '$group_perms' => t('Show to Groups'),
1575 '$contact_perms' => t('Show to Contacts'),
1576 '$private' => t('Private photo'),
1577 '$public' => t('Public photo'),
1578 '$is_private' => $private_post,
1579 '$return_path' => $query_str,
1580 '$public_link' => $public_post_link,
1584 if(count($linked_items)) {
1586 $cmnt_tpl = get_markup_template('comment_item.tpl');
1587 $tpl = get_markup_template('photo_item.tpl');
1588 $return_url = $a->cmd;
1590 $like_tpl = get_markup_template('like_noshare.tpl');
1594 if($can_post || can_write_wall($a,$owner_uid)) {
1595 $likebuttons = replace_macros($like_tpl,array(
1596 '$id' => $link_item['id'],
1597 '$likethis' => t("I like this \x28toggle\x29"),
1598 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1599 '$share' => t('Share'),
1600 '$wait' => t('Please wait'),
1601 '$return_path' => $a->query_string,
1607 if($can_post || can_write_wall($a,$owner_uid)) {
1608 if($link_item['last-child']) {
1609 $comments .= replace_macros($cmnt_tpl,array(
1610 '$return_path' => '',
1611 '$jsreload' => $return_url,
1612 '$type' => 'wall-comment',
1613 '$id' => $link_item['id'],
1614 '$parent' => $link_item['id'],
1615 '$profile_uid' => $owner_uid,
1616 '$mylink' => $contact['url'],
1617 '$mytitle' => t('This is you'),
1618 '$myphoto' => $contact['thumb'],
1619 '$comment' => t('Comment'),
1620 '$submit' => t('Submit'),
1621 '$preview' => t('Preview'),
1622 '$sourceapp' => t($a->sourcename),
1624 '$rand_num' => random_digits(12)
1641 foreach($r as $item) {
1642 like_puller($a,$item,$alike,'like');
1643 like_puller($a,$item,$dlike,'dislike');
1646 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1647 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1651 if($can_post || can_write_wall($a,$owner_uid)) {
1652 if($link_item['last-child']) {
1653 $comments .= replace_macros($cmnt_tpl,array(
1654 '$return_path' => '',
1655 '$jsreload' => $return_url,
1656 '$type' => 'wall-comment',
1657 '$id' => $link_item['id'],
1658 '$parent' => $link_item['id'],
1659 '$profile_uid' => $owner_uid,
1660 '$mylink' => $contact['url'],
1661 '$mytitle' => t('This is you'),
1662 '$myphoto' => $contact['thumb'],
1663 '$comment' => t('Comment'),
1664 '$submit' => t('Submit'),
1665 '$preview' => t('Preview'),
1666 '$sourceapp' => t($a->sourcename),
1668 '$rand_num' => random_digits(12)
1674 foreach($r as $item) {
1679 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1682 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1685 if(local_user() && ($item['contact-uid'] == local_user())
1686 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1687 $profile_url = $redirect_url;
1688 $sparkle = ' sparkle';
1691 $profile_url = $item['url'];
1695 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1697 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1698 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1700 $profile_link = $profile_url;
1704 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1706 'dropping' => $dropping,
1707 'pagedrop' => false,
1708 'select' => t('Select'),
1709 'delete' => t('Delete'),
1713 if($a->theme['template_engine'] === 'internal') {
1714 $name_e = template_escape($profile_name);
1715 $title_e = template_escape($item['title']);
1716 $body_e = template_escape(bbcode($item['body']));
1719 $name_e = $profile_name;
1720 $title_e = $item['title'];
1721 $body_e = bbcode($item['body']);
1724 $comments .= replace_macros($template,array(
1725 '$id' => $item['item_id'],
1726 '$profile_url' => $profile_link,
1728 '$thumb' => $profile_avatar,
1729 '$sparkle' => $sparkle,
1730 '$title' => $title_e,
1732 '$ago' => relative_date($item['created']),
1733 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1735 '$comment' => $comment
1738 if($can_post || can_write_wall($a,$owner_uid)) {
1740 if($item['last-child']) {
1741 $comments .= replace_macros($cmnt_tpl,array(
1742 '$return_path' => '',
1743 '$jsreload' => $return_url,
1744 '$type' => 'wall-comment',
1745 '$id' => $item['item_id'],
1746 '$parent' => $item['parent'],
1747 '$profile_uid' => $owner_uid,
1748 '$mylink' => $contact['url'],
1749 '$mytitle' => t('This is you'),
1750 '$myphoto' => $contact['thumb'],
1751 '$comment' => t('Comment'),
1752 '$submit' => t('Submit'),
1753 '$preview' => t('Preview'),
1754 '$sourceapp' => t($a->sourcename),
1756 '$rand_num' => random_digits(12)
1763 $paginate = paginate($a);
1766 $photo_tpl = get_markup_template('photo_view.tpl');
1768 if($a->theme['template_engine'] === 'internal') {
1769 $album_e = array($album_link,template_escape($ph[0]['album']));
1770 $tags_e = template_escape($tags);
1771 $like_e = template_escape($like);
1772 $dislike_e = template_escape($dislike);
1775 $album_e = array($album_link,$ph[0]['album']);
1778 $dislike_e = $dislike;
1781 $o .= replace_macros($photo_tpl, array(
1782 '$id' => $ph[0]['id'],
1783 '$album' => $album_e,
1787 '$prevlink' => $prevlink,
1788 '$nextlink' => $nextlink,
1789 '$desc' => $ph[0]['desc'],
1793 '$map_text' => t('Map'),
1794 '$likebuttons' => $likebuttons,
1796 '$dislike' => $dikslike_e,
1797 '$comments' => $comments,
1798 '$paginate' => $paginate,
1801 $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
1802 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
1803 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
1804 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
1805 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
1810 // Default - show recent photos with upload link (if applicable)
1813 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1814 $sql_extra GROUP BY `resource-id`",
1815 intval($a->data['user']['uid']),
1816 dbesc('Contact Photos'),
1817 dbesc( t('Contact Photos'))
1820 $a->set_pager_total(count($r));
1821 $a->set_pager_itemspage(20);
1824 $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
1825 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1826 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1827 intval($a->data['user']['uid']),
1828 dbesc('Contact Photos'),
1829 dbesc( t('Contact Photos')),
1830 intval($a->pager['start']),
1831 intval($a->pager['itemspage'])
1838 $twist = 'rotright';
1839 foreach($r as $rr) {
1840 //hide profile photos to others
1841 if((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
1844 if($twist == 'rotright')
1847 $twist = 'rotright';
1848 $ext = $phototypes[$rr['type']];
1850 if($a->theme['template_engine'] === 'internal') {
1851 $alt_e = template_escape($rr['filename']);
1852 $name_e = template_escape($rr['album']);
1855 $alt_e = $rr['filename'];
1856 $name_e = $rr['album'];
1861 'twist' => ' ' . $twist . rand(2,4),
1862 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1863 'title' => t('View Photo'),
1864 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1867 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1869 'alt' => t('View Album'),
1876 $tpl = get_markup_template('photos_recent.tpl');
1877 $o .= replace_macros($tpl, array(
1878 '$title' => t('Recent Photos'),
1879 '$can_post' => $can_post,
1880 '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),
1881 '$photos' => $photos,