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'];
33 $is_owner = (local_user() && (local_user() == $a->profile_uid));
35 $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg');
37 $tpl = get_markup_template("vcard-widget.tpl");
39 $vcard_widget .= replace_macros($tpl, array(
40 '$name' => $a->data['user']['username'],
41 '$photo' => $profilephoto
45 $sql_extra = permissions_sql($a->data['user']['uid']);
47 $albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
48 $sql_extra group by album order by created desc",
49 intval($a->data['user']['uid']),
50 dbesc('Contact Photos'),
51 dbesc( t('Contact Photos'))
54 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
56 // add various encodings to the array so we can just loop through and pick them out in a template
57 $ret = array('success' => false);
60 $a->data['albums'] = $albums;
62 $ret['success'] = true;
64 $ret['albums'] = array();
65 foreach($albums as $k => $album) {
66 //hide profile photos to others
67 if((! $is_owner) && (! remote_user()) && ($album['album'] == t('Profile Photos')))
70 'text' => $album['album'],
71 'total' => $album['total'],
72 'url' => z_root() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
73 'urlencode' => urlencode($album['album']),
74 'bin2hex' => bin2hex($album['album'])
76 $ret['albums'][] = $entry;
82 if(local_user() && $a->data['user']['uid'] == local_user())
85 if($albums['success']) {
86 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array(
87 '$nick' => $a->data['user']['nickname'],
88 '$title' => t('Photo Albums'),
89 'recent' => t('Recent Photos'),
90 '$albums' => $albums['albums'],
91 '$baseurl' => z_root(),
92 '$upload' => array( t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload'),
93 '$can_post' => $can_post
98 if(! x($a->page,'aside'))
99 $a->page['aside'] = '';
100 $a->page['aside'] .= $vcard_widget;
101 $a->page['aside'] .= $photo_albums_widget;
104 $tpl = get_markup_template("photos_head.tpl");
105 $a->page['htmlhead'] .= replace_macros($tpl,array(
106 '$ispublic' => t('everybody')
116 function photos_post(&$a) {
118 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
121 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
122 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
124 $phototypes = Photo::supportedTypes();
129 $page_owner_uid = $a->data['user']['uid'];
130 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
132 if((local_user()) && (local_user() == $page_owner_uid))
135 if($community_page && remote_user()) {
137 if(is_array($_SESSION['remote'])) {
138 foreach($_SESSION['remote'] as $v) {
139 if($v['uid'] == $page_owner_uid) {
147 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
149 intval($page_owner_uid)
160 notice( t('Permission denied.') . EOL );
164 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
165 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
166 intval($page_owner_uid)
170 notice( t('Contact information unavailable') . EOL);
171 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
175 $owner_record = $r[0];
178 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
179 $album = hex2bin($a->argv[3]);
181 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
182 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
183 return; // NOTREACHED
186 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
188 intval($page_owner_uid)
191 notice( t('Album not found.') . EOL);
192 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
193 return; // NOTREACHED
196 // Check if the user has responded to a delete confirmation query
197 if($_REQUEST['canceled']) {
198 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
201 $newalbum = notags(trim($_POST['albumname']));
202 if($newalbum != $album) {
203 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
206 intval($page_owner_uid)
208 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
209 goaway($a->get_baseurl() . '/' . $newurl);
210 return; // NOTREACHED
214 if($_POST['dropalbum'] == t('Delete Album')) {
216 // Check if we should do HTML-based delete confirmation
217 if($_REQUEST['confirm']) {
218 $drop_url = $a->query_string;
219 $extra_inputs = array(
220 array('name' => 'albumname', 'value' => $_POST['albumname']),
222 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
224 '$message' => t('Do you really want to delete this photo album and all its photos?'),
225 '$extra_inputs' => $extra_inputs,
226 '$confirm' => t('Delete Album'),
227 '$confirm_url' => $drop_url,
228 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
229 '$cancel' => t('Cancel'),
231 $a->error = 1; // Set $a->error so the other module functions don't execute
237 // get the list of photos we are about to delete
240 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
242 intval($page_owner_uid),
247 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
248 intval(local_user()),
254 $res[] = "'" . dbesc($rr['rid']) . "'" ;
258 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
259 return; // NOTREACHED
262 $str_res = implode(',', $res);
264 // remove the associated photos
266 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
267 intval($page_owner_uid)
270 // find and delete the corresponding item with all the comments and likes/dislikes
272 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
273 intval($page_owner_uid)
277 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
278 dbesc(datetime_convert()),
279 dbesc($rr['parent-uri']),
280 intval($page_owner_uid)
282 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
283 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
285 $drop_id = intval($rr['id']);
287 // send the notification upstream/downstream as the case may be
290 proc_run('php',"include/notifier.php","drop","$drop_id");
294 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
295 return; // NOTREACHED
299 // Check if the user has responded to a delete confirmation query for a single photo
300 if(($a->argc > 2) && $_REQUEST['canceled']) {
301 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
304 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
306 // same as above but remove single photo
308 // Check if we should do HTML-based delete confirmation
309 if($_REQUEST['confirm']) {
310 $drop_url = $a->query_string;
311 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
313 '$message' => t('Do you really want to delete this photo?'),
314 '$extra_inputs' => array(),
315 '$confirm' => t('Delete Photo'),
316 '$confirm_url' => $drop_url,
317 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
318 '$cancel' => t('Cancel'),
320 $a->error = 1; // Set $a->error so the other module functions don't execute
325 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
327 intval($page_owner_uid),
332 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
333 intval(local_user()),
338 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
339 intval($page_owner_uid),
340 dbesc($r[0]['resource-id'])
342 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
343 dbesc($r[0]['resource-id']),
344 intval($page_owner_uid)
347 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
348 dbesc(datetime_convert()),
349 dbesc(datetime_convert()),
351 intval($page_owner_uid)
353 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
354 delete_thread_uri($i[0]['uri'], $page_owner_uid);
356 $url = $a->get_baseurl();
357 $drop_id = intval($i[0]['id']);
360 proc_run('php',"include/notifier.php","drop","$drop_id");
364 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
365 return; // NOTREACHED
368 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
370 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
371 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
372 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
373 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
374 $str_group_allow = perms2str($_POST['group_allow']);
375 $str_contact_allow = perms2str($_POST['contact_allow']);
376 $str_group_deny = perms2str($_POST['group_deny']);
377 $str_contact_deny = perms2str($_POST['contact_deny']);
379 $resource_id = $a->argv[2];
381 if(! strlen($albname))
382 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
385 if((x($_POST,'rotate') !== false) &&
386 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
389 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
391 intval($page_owner_uid)
394 $ph = new Photo($r[0]['data'], $r[0]['type']);
395 if($ph->is_valid()) {
396 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
397 $ph->rotate($rotate_deg);
399 $width = $ph->getWidth();
400 $height = $ph->getHeight();
402 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
403 dbesc($ph->imageString()),
407 intval($page_owner_uid)
410 if($width > 640 || $height > 640) {
411 $ph->scaleImage(640);
412 $width = $ph->getWidth();
413 $height = $ph->getHeight();
415 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
416 dbesc($ph->imageString()),
420 intval($page_owner_uid)
424 if($width > 320 || $height > 320) {
425 $ph->scaleImage(320);
426 $width = $ph->getWidth();
427 $height = $ph->getHeight();
429 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
430 dbesc($ph->imageString()),
434 intval($page_owner_uid)
441 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
443 intval($page_owner_uid)
446 $ext = $phototypes[$p[0]['type']];
447 $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",
450 dbesc($str_contact_allow),
451 dbesc($str_group_allow),
452 dbesc($str_contact_deny),
453 dbesc($str_group_deny),
455 intval($page_owner_uid)
459 /* Don't make the item visible if the only change was the album name */
462 if($p[0]['desc'] !== $desc || strlen($rawtags))
467 // Create item container
470 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
474 $arr['uid'] = $page_owner_uid;
476 $arr['parent-uri'] = $uri;
477 $arr['type'] = 'photo';
479 $arr['resource-id'] = $p[0]['resource-id'];
480 $arr['contact-id'] = $owner_record['id'];
481 $arr['owner-name'] = $owner_record['name'];
482 $arr['owner-link'] = $owner_record['url'];
483 $arr['owner-avatar'] = $owner_record['thumb'];
484 $arr['author-name'] = $owner_record['name'];
485 $arr['author-link'] = $owner_record['url'];
486 $arr['author-avatar'] = $owner_record['thumb'];
487 $arr['title'] = $title;
488 $arr['allow_cid'] = $p[0]['allow_cid'];
489 $arr['allow_gid'] = $p[0]['allow_gid'];
490 $arr['deny_cid'] = $p[0]['deny_cid'];
491 $arr['deny_gid'] = $p[0]['deny_gid'];
492 $arr['last-child'] = 1;
493 $arr['visible'] = $visibility;
496 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
497 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
500 $item_id = item_store($arr);
505 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
507 intval($page_owner_uid)
511 $old_tag = $r[0]['tag'];
512 $old_inform = $r[0]['inform'];
515 if(strlen($rawtags)) {
520 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
522 $x = substr($rawtags,0,1);
523 if($x !== '@' && $x !== '#')
524 $rawtags = '#' . $rawtags;
527 $tags = get_tags($rawtags);
530 foreach($tags as $tag) {
533 if(strpos($tag,'@') === 0) {
534 $name = substr($tag,1);
535 if((strpos($name,'@')) || (strpos($name,'http://'))) {
537 $links = @lrdd($name);
539 foreach($links as $link) {
540 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
541 $profile = $link['@attributes']['href'];
542 if($link['@attributes']['rel'] === 'salmon') {
543 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
550 $taginfo[] = array($newname,$profile,$salmon);
556 if(strrpos($newname,'+'))
557 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
560 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
566 $newname = str_replace('_',' ',$name);
568 //select someone from this user's contacts by name
569 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
571 intval($page_owner_uid)
575 //select someone by attag or nick and the name passed in
576 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
579 intval($page_owner_uid)
583 /* elseif(strstr($name,'_') || strstr($name,' ')) {
584 $newname = str_replace('_',' ',$name);
585 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
587 intval($page_owner_uid)
591 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
594 intval($page_owner_uid)
598 $newname = $r[0]['name'];
599 $profile = $r[0]['url'];
600 $notify = 'cid:' . $r[0]['id'];
607 if(substr($notify,0,4) === 'cid:')
608 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
610 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
611 if(strlen($str_tags))
613 $profile = str_replace(',','%2c',$profile);
614 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
616 } elseif (strpos($tag,'#') === 0) {
617 $tagname = substr($tag, 1);
618 $str_tags .= '#[url='.$a->get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
624 if(strlen($newtag) && strlen($str_tags))
626 $newtag .= $str_tags;
628 $newinform = $old_inform;
629 if(strlen($newinform) && strlen($inform))
631 $newinform .= $inform;
633 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
636 dbesc(datetime_convert()),
637 dbesc(datetime_convert()),
639 intval($page_owner_uid)
641 create_tags_from_item($item_id);
642 update_thread($item_id);
645 foreach($p as $scales) {
646 if(intval($scales['scale']) == 2) {
650 if(intval($scales['scale']) == 4) {
656 if(count($taginfo)) {
657 foreach($taginfo as $tagged) {
659 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
663 $arr['uid'] = $page_owner_uid;
665 $arr['parent-uri'] = $uri;
666 $arr['type'] = 'activity';
668 $arr['contact-id'] = $owner_record['id'];
669 $arr['owner-name'] = $owner_record['name'];
670 $arr['owner-link'] = $owner_record['url'];
671 $arr['owner-avatar'] = $owner_record['thumb'];
672 $arr['author-name'] = $owner_record['name'];
673 $arr['author-link'] = $owner_record['url'];
674 $arr['author-avatar'] = $owner_record['thumb'];
676 $arr['allow_cid'] = $p[0]['allow_cid'];
677 $arr['allow_gid'] = $p[0]['allow_gid'];
678 $arr['deny_cid'] = $p[0]['deny_cid'];
679 $arr['deny_gid'] = $p[0]['deny_gid'];
680 $arr['last-child'] = 1;
682 $arr['verb'] = ACTIVITY_TAG;
683 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
684 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
685 $arr['tag'] = $tagged[4];
686 $arr['inform'] = $tagged[2];
688 $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]') ;
689 $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" ;
691 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
692 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
694 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
695 $arr['object'] .= '</link></object>' . "\n";
697 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
698 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
699 $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>';
701 $item_id = item_store($arr);
703 //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
704 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
705 // intval($page_owner_uid),
709 proc_run('php',"include/notifier.php","tag","$item_id");
716 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
717 return; // NOTREACHED
722 * default post action - upload a photo
725 call_hooks('photo_post_init', $_POST);
728 * Determine the album to use
731 $album = notags(trim($_REQUEST['album']));
732 $newalbum = notags(trim($_REQUEST['newalbum']));
734 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
736 if(! strlen($album)) {
737 if(strlen($newalbum))
740 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
745 * We create a wall item for every photo, but we don't want to
746 * overwhelm the data stream with a hundred newly uploaded photos.
747 * So we will make the first photo uploaded to this album in the last several hours
748 * visible by default, the rest will become visible over time when and if
749 * they acquire comments, likes, dislikes, and/or tags
753 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
755 intval($page_owner_uid)
757 if((! count($r)) || ($album == t('Profile Photos')))
762 if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
765 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
766 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
767 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
768 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
770 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
772 call_hooks('photo_post_file',$ret);
774 if(x($ret,'src') && x($ret,'filesize')) {
776 $filename = $ret['filename'];
777 $filesize = $ret['filesize'];
778 $type = $ret['type'];
781 $src = $_FILES['userfile']['tmp_name'];
782 $filename = basename($_FILES['userfile']['name']);
783 $filesize = intval($_FILES['userfile']['size']);
784 $type = $_FILES['userfile']['type'];
786 if ($type=="") $type=guess_image_type($filename);
788 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
790 $maximagesize = get_config('system','maximagesize');
792 if(($maximagesize) && ($filesize > $maximagesize)) {
793 notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
796 call_hooks('photo_post_end',$foo);
801 notice( t('Image file is empty.') . EOL);
804 call_hooks('photo_post_end',$foo);
808 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
810 $imagedata = @file_get_contents($src);
814 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
815 intval($a->data['user']['uid'])
818 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
820 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
821 notice( upgrade_message() . EOL );
824 call_hooks('photo_post_end',$foo);
829 $ph = new Photo($imagedata, $type);
831 if(! $ph->is_valid()) {
832 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
833 notice( t('Unable to process image.') . EOL );
836 call_hooks('photo_post_end',$foo);
843 $max_length = get_config('system','max_image_length');
845 $max_length = MAX_IMAGE_LENGTH;
847 $ph->scaleImage($max_length);
849 $width = $ph->getWidth();
850 $height = $ph->getHeight();
854 $photo_hash = photo_new_resource();
856 $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);
859 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
860 notice( t('Image upload failed.') . EOL );
864 if($width > 640 || $height > 640) {
865 $ph->scaleImage(640);
866 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
870 if($width > 320 || $height > 320) {
871 $ph->scaleImage(320);
872 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
876 $basename = basename($filename);
877 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
879 // Create item container
883 $arr['uid'] = $page_owner_uid;
885 $arr['parent-uri'] = $uri;
886 $arr['type'] = 'photo';
888 $arr['resource-id'] = $photo_hash;
889 $arr['contact-id'] = $owner_record['id'];
890 $arr['owner-name'] = $owner_record['name'];
891 $arr['owner-link'] = $owner_record['url'];
892 $arr['owner-avatar'] = $owner_record['thumb'];
893 $arr['author-name'] = $owner_record['name'];
894 $arr['author-link'] = $owner_record['url'];
895 $arr['author-avatar'] = $owner_record['thumb'];
897 $arr['allow_cid'] = $str_contact_allow;
898 $arr['allow_gid'] = $str_group_allow;
899 $arr['deny_cid'] = $str_contact_deny;
900 $arr['deny_gid'] = $str_group_deny;
901 $arr['last-child'] = 1;
902 $arr['visible'] = $visible;
905 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
906 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
909 $item_id = item_store($arr);
912 // q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
913 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
914 // intval($page_owner_uid),
920 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
922 call_hooks('photo_post_end',intval($item_id));
924 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
925 // if they do not wish to be redirected
927 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
933 function photos_content(&$a) {
937 // photos/name/upload
938 // photos/name/upload/xxxxx (xxxxx is album name)
939 // photos/name/album/xxxxx
940 // photos/name/album/xxxxx/edit
941 // photos/name/image/xxxxx
942 // photos/name/image/xxxxx/edit
945 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
946 notice( t('Public access denied.') . EOL);
951 require_once('include/bbcode.php');
952 require_once('include/security.php');
953 require_once('include/conversation.php');
955 if(! x($a->data,'user')) {
956 notice( t('No photos selected') . EOL );
960 $phototypes = Photo::supportedTypes();
962 $_SESSION['photo_return'] = $a->cmd;
969 $datatype = $a->argv[2];
970 $datum = $a->argv[3];
972 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
973 $datatype = 'upload';
975 $datatype = 'summary';
983 // Setup permissions structures
989 $remote_contact = false;
992 $owner_uid = $a->data['user']['uid'];
994 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
996 if((local_user()) && (local_user() == $owner_uid))
999 if($community_page && remote_user()) {
1000 if(is_array($_SESSION['remote'])) {
1001 foreach($_SESSION['remote'] as $v) {
1002 if($v['uid'] == $owner_uid) {
1003 $contact_id = $v['cid'];
1010 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1011 intval($contact_id),
1017 $remote_contact = true;
1024 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1026 if(remote_user() && (! $visitor)) {
1028 if(is_array($_SESSION['remote'])) {
1029 foreach($_SESSION['remote'] as $v) {
1030 if($v['uid'] == $owner_uid) {
1031 $contact_id = $v['cid'];
1037 $groups = init_groups_visitor($contact_id);
1038 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1039 intval($contact_id),
1044 $remote_contact = true;
1049 if(! $remote_contact) {
1051 $contact_id = $_SESSION['cid'];
1052 $contact = $a->contact;
1056 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1057 notice( t('Access to this item is restricted.') . EOL);
1061 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
1066 $is_owner = (local_user() && (local_user() == $owner_uid));
1067 $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']);
1074 if($datatype === 'upload') {
1076 notice( t('Permission denied.'));
1081 $selname = (($datum) ? hex2bin($datum) : '');
1087 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1088 if(count($a->data['albums'])) {
1089 foreach($a->data['albums'] as $album) {
1090 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
1092 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1093 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1099 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
1100 'addon_text' => $uploader,
1101 'default_upload' => true);
1104 call_hooks('photo_upload_form',$ret);
1106 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1107 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1108 '$submit' => t('Submit'),
1111 $usage_message = '';
1112 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1113 if($limit !== false) {
1115 $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1116 intval($a->data['user']['uid'])
1118 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1122 // Private/public post links for the non-JS ACL form
1124 if($_REQUEST['public'])
1127 $query_str = $a->query_string;
1128 if(strpos($query_str, 'public=1') !== false)
1129 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1131 // I think $a->query_string may never have ? in it, but I could be wrong
1132 // It looks like it's from the index.php?q=[etc] rewrite that the web
1133 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1134 if(strpos($query_str, '?') === false)
1135 $public_post_link = '?public=1';
1137 $public_post_link = '&public=1';
1141 $tpl = get_markup_template('photos_upload.tpl');
1143 if($a->theme['template_engine'] === 'internal') {
1144 $albumselect_e = template_escape($albumselect);
1145 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
1148 $albumselect_e = $albumselect;
1149 $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
1152 $o .= replace_macros($tpl,array(
1153 '$pagename' => t('Upload Photos'),
1154 '$sessid' => session_id(),
1155 '$usage' => $usage_message,
1156 '$nickname' => $a->data['user']['nickname'],
1157 '$newalbum' => t('New album name: '),
1158 '$existalbumtext' => t('or existing album name: '),
1159 '$nosharetext' => t('Do not show a status post for this upload'),
1160 '$albumselect' => $albumselect_e,
1161 '$permissions' => t('Permissions'),
1162 '$aclselect' => $aclselect_e,
1163 '$alt_uploader' => $ret['addon_text'],
1164 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1165 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1166 '$uploadurl' => $ret['post_url'],
1168 // ACL permissions box
1169 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1170 '$group_perms' => t('Show to Groups'),
1171 '$contact_perms' => t('Show to Contacts'),
1172 '$private' => t('Private Photo'),
1173 '$public' => t('Public Photo'),
1174 '$is_private' => $private_post,
1175 '$return_path' => $query_str,
1176 '$public_link' => $public_post_link,
1183 if($datatype === 'album') {
1185 $album = hex2bin($datum);
1187 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1188 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1193 $a->set_pager_total(count($r));
1194 $a->set_pager_itemspage(20);
1197 if($_GET['order'] === 'posted')
1202 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1203 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1206 intval($a->pager['start']),
1207 intval($a->pager['itemspage'])
1210 if($cmd === 'edit') {
1211 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1213 $edit_tpl = get_markup_template('album_edit.tpl');
1215 if($a->theme['template_engine'] === 'internal') {
1216 $album_e = template_escape($album);
1222 $o .= replace_macros($edit_tpl,array(
1223 '$nametext' => t('New album name: '),
1224 '$nickname' => $a->data['user']['nickname'],
1225 '$album' => $album_e,
1226 '$hexalbum' => bin2hex($album),
1227 '$submit' => t('Submit'),
1228 '$dropsubmit' => t('Delete Album')
1234 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1236 $edit = array(t('Edit Album'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1241 if($_GET['order'] === 'posted')
1242 $order = array(t('Show Newest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1244 $order = array(t('Show Oldest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1249 $twist = 'rotright';
1250 foreach($r as $rr) {
1251 if($twist == 'rotright')
1254 $twist = 'rotright';
1256 $ext = $phototypes[$rr['type']];
1258 if($a->theme['template_engine'] === 'internal') {
1259 $imgalt_e = template_escape($rr['filename']);
1260 $desc_e = template_escape($rr['desc']);
1263 $imgalt_e = $rr['filename'];
1264 $desc_e = $rr['desc'];
1269 'twist' => ' ' . $twist . rand(2,4),
1270 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1271 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1272 'title' => t('View Photo'),
1273 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1277 'hash'=> $rr['resource_id'],
1281 $tpl = get_markup_template('photo_album.tpl');
1282 $o .= replace_macros($tpl, array(
1283 '$photos' => $photos,
1285 '$can_post' => $can_post,
1286 '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1298 if($datatype === 'image') {
1303 // fetch image, item containing image, then comments
1305 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1306 $sql_extra ORDER BY `scale` ASC ",
1312 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1318 notice( t('Permission denied. Access to this item may be restricted.'));
1320 notice( t('Photo not available') . EOL );
1327 if($_GET['order'] === 'posted')
1333 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1334 $sql_extra ORDER BY `created` $order ",
1335 dbesc($ph[0]['album']),
1339 if(count($prvnxt)) {
1340 for($z = 0; $z < count($prvnxt); $z++) {
1341 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1345 $prv = count($prvnxt) - 1;
1346 if($nxt >= count($prvnxt))
1351 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1352 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1353 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1358 $hires = $lores = $ph[0];
1359 if(count($ph) > 1) {
1360 if($ph[1]['scale'] == 2) {
1361 // original is 640 or less, we can display it directly
1362 $hires = $lores = $ph[0];
1370 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1374 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1376 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1377 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1381 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1382 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1383 ? t('Private Message')
1389 if( $cmd === 'edit') {
1390 $tpl = get_markup_template('photo_edit_head.tpl');
1391 $a->page['htmlhead'] .= replace_macros($tpl,array(
1392 '$prevlink' => $prevlink,
1393 '$nextlink' => $nextlink
1398 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1401 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1402 'title'=> t('View Full Size'),
1403 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1404 'height' => $hires['height'],
1405 'width' => $hires['width'],
1406 'album' => $hires['album'],
1407 'filename' => $hires['filename'],
1411 $nextlink = array($nextlink, '<div class="icon next"></div>');
1414 // Do we have an item for this photo?
1416 // FIXME! - replace following code to display the conversation with our normal
1417 // conversation functions so that it works correctly and tracks changes
1418 // in the evolving conversation code.
1419 // The difference is that we won't be displaying the conversation head item
1420 // as a "post" but displaying instead the photo it is linked to
1422 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1425 if(count($linked_items)) {
1426 $link_item = $linked_items[0];
1427 $r = q("SELECT COUNT(*) AS `total`
1428 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1429 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1430 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1431 AND `item`.`uid` = %d
1433 dbesc($link_item['uri']),
1434 dbesc($link_item['uri']),
1435 intval($link_item['uid'])
1440 $a->set_pager_total($r[0]['total']);
1443 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1444 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1445 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1446 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1447 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1448 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1449 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1450 AND `item`.`uid` = %d
1452 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1453 dbesc($link_item['uri']),
1454 dbesc($link_item['uri']),
1455 intval($link_item['uid']),
1456 intval($a->pager['start']),
1457 intval($a->pager['itemspage'])
1461 if((local_user()) && (local_user() == $link_item['uid'])) {
1462 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1463 intval($link_item['parent']),
1464 intval(local_user())
1466 update_thread($link_item['parent']);
1472 if(count($linked_items) && strlen($link_item['tag'])) {
1473 $arr = explode(',',$link_item['tag']);
1474 // parse tags and add links
1476 foreach($arr as $t) {
1477 if(strlen($tag_str))
1479 $tag_str .= bbcode($t);
1481 $tags = array(t('Tags: '), $tag_str);
1482 if($cmd === 'edit') {
1483 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1484 $tags[] = t('[Remove any tag]');
1490 if(($cmd === 'edit') && ($can_post)) {
1491 $edit_tpl = get_markup_template('photo_edit.tpl');
1493 // Private/public post links for the non-JS ACL form
1495 if($_REQUEST['public'])
1498 $query_str = $a->query_string;
1499 if(strpos($query_str, 'public=1') !== false)
1500 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1502 // I think $a->query_string may never have ? in it, but I could be wrong
1503 // It looks like it's from the index.php?q=[etc] rewrite that the web
1504 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1505 if(strpos($query_str, '?') === false)
1506 $public_post_link = '?public=1';
1508 $public_post_link = '&public=1';
1511 if($a->theme['template_engine'] === 'internal') {
1512 $album_e = template_escape($ph[0]['album']);
1513 $caption_e = template_escape($ph[0]['desc']);
1514 $aclselect_e = template_escape(populate_acl($ph[0]));
1517 $album_e = $ph[0]['album'];
1518 $caption_e = $ph[0]['desc'];
1519 $aclselect_e = populate_acl($ph[0]);
1522 $edit = replace_macros($edit_tpl, array(
1523 '$id' => $ph[0]['id'],
1524 '$album' => array('albname', t('New album name'), $album_e,''),
1525 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1526 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1527 '$rotate_none' => array('rotate',t('Do not rotate'),0,'', true),
1528 '$rotate_cw' => array('rotate',t('Rotate CW (right)'),1,''),
1529 '$rotate_ccw' => array('rotate',t('Rotate CCW (left)'),2,''),
1531 '$nickname' => $a->data['user']['nickname'],
1532 '$resource_id' => $ph[0]['resource-id'],
1533 '$permissions' => t('Permissions'),
1534 '$aclselect' => $aclselect_e,
1536 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1537 '$submit' => t('Submit'),
1538 '$delete' => t('Delete Photo'),
1540 // ACL permissions box
1541 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1542 '$group_perms' => t('Show to Groups'),
1543 '$contact_perms' => t('Show to Contacts'),
1544 '$private' => t('Private photo'),
1545 '$public' => t('Public photo'),
1546 '$is_private' => $private_post,
1547 '$return_path' => $query_str,
1548 '$public_link' => $public_post_link,
1552 if(count($linked_items)) {
1554 $cmnt_tpl = get_markup_template('comment_item.tpl');
1555 $tpl = get_markup_template('photo_item.tpl');
1556 $return_url = $a->cmd;
1558 $like_tpl = get_markup_template('like_noshare.tpl');
1562 if($can_post || can_write_wall($a,$owner_uid)) {
1563 $likebuttons = replace_macros($like_tpl,array(
1564 '$id' => $link_item['id'],
1565 '$likethis' => t("I like this \x28toggle\x29"),
1566 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1567 '$share' => t('Share'),
1568 '$wait' => t('Please wait'),
1569 '$return_path' => $a->query_string,
1575 if($can_post || can_write_wall($a,$owner_uid)) {
1576 if($link_item['last-child']) {
1577 $comments .= replace_macros($cmnt_tpl,array(
1578 '$return_path' => '',
1579 '$jsreload' => $return_url,
1580 '$type' => 'wall-comment',
1581 '$id' => $link_item['id'],
1582 '$parent' => $link_item['id'],
1583 '$profile_uid' => $owner_uid,
1584 '$mylink' => $contact['url'],
1585 '$mytitle' => t('This is you'),
1586 '$myphoto' => $contact['thumb'],
1587 '$comment' => t('Comment'),
1588 '$submit' => t('Submit'),
1589 '$preview' => t('Preview'),
1590 '$sourceapp' => t($a->sourcename),
1592 '$rand_num' => random_digits(12)
1604 $conv_responses = array(
1605 'like' => array('title' => t('Likes','title')),'dislike' => array('title' => t('Dislikes','title')),
1606 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
1614 foreach($r as $item) {
1615 builtin_activity_puller($item, $conv_responses);
1618 $like = ((x($conv_responses['like'],$link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']],$conv_responses['like'][$link_item['uri'] . '-l'],'like',$link_item['id']) : '');
1619 $dislike = ((x($conv_responses['dislike'],$link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']],$conv_responses['dislike'][$link_item['uri'] . '-l'],'dislike',$link_item['id']) : '');
1623 if($can_post || can_write_wall($a,$owner_uid)) {
1624 if($link_item['last-child']) {
1625 $comments .= replace_macros($cmnt_tpl,array(
1626 '$return_path' => '',
1627 '$jsreload' => $return_url,
1628 '$type' => 'wall-comment',
1629 '$id' => $link_item['id'],
1630 '$parent' => $link_item['id'],
1631 '$profile_uid' => $owner_uid,
1632 '$mylink' => $contact['url'],
1633 '$mytitle' => t('This is you'),
1634 '$myphoto' => $contact['thumb'],
1635 '$comment' => t('Comment'),
1636 '$submit' => t('Submit'),
1637 '$preview' => t('Preview'),
1638 '$sourceapp' => t($a->sourcename),
1640 '$rand_num' => random_digits(12)
1646 foreach($r as $item) {
1651 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1654 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1657 if(local_user() && ($item['contact-uid'] == local_user())
1658 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1659 $profile_url = $redirect_url;
1660 $sparkle = ' sparkle';
1663 $profile_url = $item['url'];
1667 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1669 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1670 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1672 $profile_link = $profile_url;
1676 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1678 'dropping' => $dropping,
1679 'pagedrop' => false,
1680 'select' => t('Select'),
1681 'delete' => t('Delete'),
1685 if($a->theme['template_engine'] === 'internal') {
1686 $name_e = template_escape($profile_name);
1687 $title_e = template_escape($item['title']);
1688 $body_e = template_escape(bbcode($item['body']));
1691 $name_e = $profile_name;
1692 $title_e = $item['title'];
1693 $body_e = bbcode($item['body']);
1696 $comments .= replace_macros($template,array(
1697 '$id' => $item['item_id'],
1698 '$profile_url' => $profile_link,
1700 '$thumb' => $profile_avatar,
1701 '$sparkle' => $sparkle,
1702 '$title' => $title_e,
1704 '$ago' => relative_date($item['created']),
1705 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1707 '$comment' => $comment
1710 if($can_post || can_write_wall($a,$owner_uid)) {
1712 if($item['last-child']) {
1713 $comments .= replace_macros($cmnt_tpl,array(
1714 '$return_path' => '',
1715 '$jsreload' => $return_url,
1716 '$type' => 'wall-comment',
1717 '$id' => $item['item_id'],
1718 '$parent' => $item['parent'],
1719 '$profile_uid' => $owner_uid,
1720 '$mylink' => $contact['url'],
1721 '$mytitle' => t('This is you'),
1722 '$myphoto' => $contact['thumb'],
1723 '$comment' => t('Comment'),
1724 '$submit' => t('Submit'),
1725 '$preview' => t('Preview'),
1726 '$sourceapp' => t($a->sourcename),
1728 '$rand_num' => random_digits(12)
1735 $paginate = paginate($a);
1739 $response_verbs = array('like');
1740 if(feature_enabled($owner_uid,'dislike'))
1741 $response_verbs[] = 'dislike';
1742 $responses = get_responses($conv_responses,$response_verbs,'',$link_item);
1744 $photo_tpl = get_markup_template('photo_view.tpl');
1746 if($a->theme['template_engine'] === 'internal') {
1747 $album_e = array($album_link,template_escape($ph[0]['album']));
1748 $tags_e = template_escape($tags);
1749 $like_e = template_escape($like);
1750 $dislike_e = template_escape($dislike);
1753 $album_e = array($album_link,$ph[0]['album']);
1756 $dislike_e = $dislike;
1759 $o .= replace_macros($photo_tpl, array(
1760 '$id' => $ph[0]['id'],
1761 '$album' => $album_e,
1765 '$prevlink' => $prevlink,
1766 '$nextlink' => $nextlink,
1767 '$desc' => $ph[0]['desc'],
1770 '$likebuttons' => $likebuttons,
1772 '$dislike' => $dikslike_e,
1773 'responses' => $responses,
1774 '$comments' => $comments,
1775 '$paginate' => $paginate,
1778 $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
1779 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
1780 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
1781 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
1782 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
1787 // Default - show recent photos with upload link (if applicable)
1790 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1791 $sql_extra GROUP BY `resource-id`",
1792 intval($a->data['user']['uid']),
1793 dbesc('Contact Photos'),
1794 dbesc( t('Contact Photos'))
1797 $a->set_pager_total(count($r));
1798 $a->set_pager_itemspage(20);
1801 $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
1802 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1803 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1804 intval($a->data['user']['uid']),
1805 dbesc('Contact Photos'),
1806 dbesc( t('Contact Photos')),
1807 intval($a->pager['start']),
1808 intval($a->pager['itemspage'])
1815 $twist = 'rotright';
1816 foreach($r as $rr) {
1817 //hide profile photos to others
1818 if((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
1821 if($twist == 'rotright')
1824 $twist = 'rotright';
1825 $ext = $phototypes[$rr['type']];
1827 if($a->theme['template_engine'] === 'internal') {
1828 $alt_e = template_escape($rr['filename']);
1829 $name_e = template_escape($rr['album']);
1832 $alt_e = $rr['filename'];
1833 $name_e = $rr['album'];
1838 'twist' => ' ' . $twist . rand(2,4),
1839 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1840 'title' => t('View Photo'),
1841 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1844 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1846 'alt' => t('View Album'),
1853 $tpl = get_markup_template('photos_recent.tpl');
1854 $o .= replace_macros($tpl, array(
1855 '$title' => t('Recent Photos'),
1856 '$can_post' => $can_post,
1857 '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),
1858 '$photos' => $photos,