2 require_once('include/Photo.php');
3 require_once('include/items.php');
4 require_once('include/acl_selectors.php');
5 require_once('include/bbcode.php');
6 require_once('include/security.php');
7 require_once('include/redir.php');
8 require_once('include/tags.php');
9 require_once('include/threads.php');
11 function photos_init(&$a) {
14 auto_redir($a, $a->argv[1]);
16 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
24 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
31 $a->data['user'] = $r[0];
33 $o .= '<div class="vcard">';
34 $o .= '<div class="fn">' . $a->data['user']['username'] . '</div>';
35 $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg') . '" alt="' . $a->data['user']['username'] . '" /></div>';
39 $sql_extra = permissions_sql($a->data['user']['uid']);
41 $albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
42 $sql_extra group by album order by created desc",
43 intval($a->data['user']['uid']),
44 dbesc('Contact Photos'),
45 dbesc( t('Contact Photos'))
48 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
50 // add various encodings to the array so we can just loop through and pick them out in a template
51 $ret = array('success' => false);
54 $a->data['albums'] = $albums;
56 $ret['success'] = true;
58 $ret['albums'] = array();
59 foreach($albums as $k => $album) {
61 'text' => $album['album'],
62 'total' => $album['total'],
63 'url' => z_root() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
64 'urlencode' => urlencode($album['album']),
65 'bin2hex' => bin2hex($album['album'])
67 $ret['albums'][] = $entry;
73 if(local_user() && $a->data['user']['uid'] == local_user())
76 if($albums['success']) {
77 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array(
78 '$nick' => $a->data['user']['nickname'],
79 '$title' => t('Photo Albums'),
80 'recent' => t('Recent Photos'),
81 '$albums' => $albums['albums'],
82 '$baseurl' => z_root(),
83 '$upload' => array( t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
84 '$can_post' => $can_post
89 if(! x($a->page,'aside'))
90 $a->page['aside'] = '';
91 $a->page['aside'] .= $o;
92 $a->page['aside'] .= $photo_albums_widget;
95 $tpl = get_markup_template("photos_head.tpl");
96 $a->page['htmlhead'] .= replace_macros($tpl,array(
97 '$ispublic' => t('everybody')
107 function photos_post(&$a) {
109 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
112 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
113 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
115 $phototypes = Photo::supportedTypes();
120 $page_owner_uid = $a->data['user']['uid'];
121 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
123 if((local_user()) && (local_user() == $page_owner_uid))
126 if($community_page && remote_user()) {
128 if(is_array($_SESSION['remote'])) {
129 foreach($_SESSION['remote'] as $v) {
130 if($v['uid'] == $page_owner_uid) {
138 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
140 intval($page_owner_uid)
151 notice( t('Permission denied.') . EOL );
155 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
156 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
157 intval($page_owner_uid)
161 notice( t('Contact information unavailable') . EOL);
162 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
166 $owner_record = $r[0];
169 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
170 $album = hex2bin($a->argv[3]);
172 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
173 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
174 return; // NOTREACHED
177 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
179 intval($page_owner_uid)
182 notice( t('Album not found.') . EOL);
183 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
184 return; // NOTREACHED
187 // Check if the user has responded to a delete confirmation query
188 if($_REQUEST['canceled']) {
189 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
192 $newalbum = notags(trim($_POST['albumname']));
193 if($newalbum != $album) {
194 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
197 intval($page_owner_uid)
199 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
200 goaway($a->get_baseurl() . '/' . $newurl);
201 return; // NOTREACHED
205 if($_POST['dropalbum'] == t('Delete Album')) {
207 // Check if we should do HTML-based delete confirmation
208 if($_REQUEST['confirm']) {
209 $drop_url = $a->query_string;
210 $extra_inputs = array(
211 array('name' => 'albumname', 'value' => $_POST['albumname']),
213 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
215 '$message' => t('Do you really want to delete this photo album and all its photos?'),
216 '$extra_inputs' => $extra_inputs,
217 '$confirm' => t('Delete Album'),
218 '$confirm_url' => $drop_url,
219 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
220 '$cancel' => t('Cancel'),
222 $a->error = 1; // Set $a->error so the other module functions don't execute
228 // get the list of photos we are about to delete
231 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
233 intval($page_owner_uid),
238 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
239 intval(local_user()),
245 $res[] = "'" . dbesc($rr['rid']) . "'" ;
249 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
250 return; // NOTREACHED
253 $str_res = implode(',', $res);
255 // remove the associated photos
257 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
258 intval($page_owner_uid)
261 // find and delete the corresponding item with all the comments and likes/dislikes
263 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
264 intval($page_owner_uid)
268 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
269 dbesc(datetime_convert()),
270 dbesc($rr['parent-uri']),
271 intval($page_owner_uid)
273 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
274 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
276 $drop_id = intval($rr['id']);
278 // send the notification upstream/downstream as the case may be
281 proc_run('php',"include/notifier.php","drop","$drop_id");
285 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
286 return; // NOTREACHED
290 // Check if the user has responded to a delete confirmation query for a single photo
291 if(($a->argc > 2) && $_REQUEST['canceled']) {
292 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
295 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
297 // same as above but remove single photo
299 // Check if we should do HTML-based delete confirmation
300 if($_REQUEST['confirm']) {
301 $drop_url = $a->query_string;
302 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
304 '$message' => t('Do you really want to delete this photo?'),
305 '$extra_inputs' => array(),
306 '$confirm' => t('Delete Photo'),
307 '$confirm_url' => $drop_url,
308 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
309 '$cancel' => t('Cancel'),
311 $a->error = 1; // Set $a->error so the other module functions don't execute
316 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
318 intval($page_owner_uid),
323 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
324 intval(local_user()),
329 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
330 intval($page_owner_uid),
331 dbesc($r[0]['resource-id'])
333 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
334 dbesc($r[0]['resource-id']),
335 intval($page_owner_uid)
338 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
339 dbesc(datetime_convert()),
340 dbesc(datetime_convert()),
342 intval($page_owner_uid)
344 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
345 delete_thread_uri($i[0]['uri'], $page_owner_uid);
347 $url = $a->get_baseurl();
348 $drop_id = intval($i[0]['id']);
351 proc_run('php',"include/notifier.php","drop","$drop_id");
355 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
356 return; // NOTREACHED
359 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
361 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
362 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
363 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
364 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
365 $str_group_allow = perms2str($_POST['group_allow']);
366 $str_contact_allow = perms2str($_POST['contact_allow']);
367 $str_group_deny = perms2str($_POST['group_deny']);
368 $str_contact_deny = perms2str($_POST['contact_deny']);
370 $resource_id = $a->argv[2];
372 if(! strlen($albname))
373 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
376 if((x($_POST,'rotate') !== false) &&
377 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
380 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
382 intval($page_owner_uid)
385 $ph = new Photo($r[0]['data'], $r[0]['type']);
386 if($ph->is_valid()) {
387 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
388 $ph->rotate($rotate_deg);
390 $width = $ph->getWidth();
391 $height = $ph->getHeight();
393 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
394 dbesc($ph->imageString()),
398 intval($page_owner_uid)
401 if($width > 640 || $height > 640) {
402 $ph->scaleImage(640);
403 $width = $ph->getWidth();
404 $height = $ph->getHeight();
406 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
407 dbesc($ph->imageString()),
411 intval($page_owner_uid)
415 if($width > 320 || $height > 320) {
416 $ph->scaleImage(320);
417 $width = $ph->getWidth();
418 $height = $ph->getHeight();
420 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
421 dbesc($ph->imageString()),
425 intval($page_owner_uid)
432 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
434 intval($page_owner_uid)
437 $ext = $phototypes[$p[0]['type']];
438 $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",
441 dbesc($str_contact_allow),
442 dbesc($str_group_allow),
443 dbesc($str_contact_deny),
444 dbesc($str_group_deny),
446 intval($page_owner_uid)
450 /* Don't make the item visible if the only change was the album name */
453 if($p[0]['desc'] !== $desc || strlen($rawtags))
458 // Create item container
461 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
465 $arr['uid'] = $page_owner_uid;
467 $arr['parent-uri'] = $uri;
468 $arr['type'] = 'photo';
470 $arr['resource-id'] = $p[0]['resource-id'];
471 $arr['contact-id'] = $owner_record['id'];
472 $arr['owner-name'] = $owner_record['name'];
473 $arr['owner-link'] = $owner_record['url'];
474 $arr['owner-avatar'] = $owner_record['thumb'];
475 $arr['author-name'] = $owner_record['name'];
476 $arr['author-link'] = $owner_record['url'];
477 $arr['author-avatar'] = $owner_record['thumb'];
478 $arr['title'] = $title;
479 $arr['allow_cid'] = $p[0]['allow_cid'];
480 $arr['allow_gid'] = $p[0]['allow_gid'];
481 $arr['deny_cid'] = $p[0]['deny_cid'];
482 $arr['deny_gid'] = $p[0]['deny_gid'];
483 $arr['last-child'] = 1;
484 $arr['visible'] = $visibility;
487 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
488 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
491 $item_id = item_store($arr);
496 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
498 intval($page_owner_uid)
502 $old_tag = $r[0]['tag'];
503 $old_inform = $r[0]['inform'];
506 if(strlen($rawtags)) {
511 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
513 $x = substr($rawtags,0,1);
514 if($x !== '@' && $x !== '#')
515 $rawtags = '#' . $rawtags;
518 $tags = get_tags($rawtags);
521 foreach($tags as $tag) {
524 if(strpos($tag,'@') === 0) {
525 $name = substr($tag,1);
526 if((strpos($name,'@')) || (strpos($name,'http://'))) {
528 $links = @lrdd($name);
530 foreach($links as $link) {
531 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
532 $profile = $link['@attributes']['href'];
533 if($link['@attributes']['rel'] === 'salmon') {
534 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
541 $taginfo[] = array($newname,$profile,$salmon);
547 if(strrpos($newname,'+'))
548 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
551 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
557 $newname = str_replace('_',' ',$name);
559 //select someone from this user's contacts by name
560 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
562 intval($page_owner_uid)
566 //select someone by attag or nick and the name passed in
567 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
570 intval($page_owner_uid)
574 /* elseif(strstr($name,'_') || strstr($name,' ')) {
575 $newname = str_replace('_',' ',$name);
576 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
578 intval($page_owner_uid)
582 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
585 intval($page_owner_uid)
589 $newname = $r[0]['name'];
590 $profile = $r[0]['url'];
591 $notify = 'cid:' . $r[0]['id'];
598 if(substr($notify,0,4) === 'cid:')
599 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
601 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
602 if(strlen($str_tags))
604 $profile = str_replace(',','%2c',$profile);
605 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
607 } elseif (strpos($tag,'#') === 0) {
608 $tagname = substr($tag, 1);
609 $str_tags .= '#[url='.$a->get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
615 if(strlen($newtag) && strlen($str_tags))
617 $newtag .= $str_tags;
619 $newinform = $old_inform;
620 if(strlen($newinform) && strlen($inform))
622 $newinform .= $inform;
624 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
627 dbesc(datetime_convert()),
628 dbesc(datetime_convert()),
630 intval($page_owner_uid)
632 create_tags_from_item($item_id);
633 update_thread($item_id);
636 foreach($p as $scales) {
637 if(intval($scales['scale']) == 2) {
641 if(intval($scales['scale']) == 4) {
647 if(count($taginfo)) {
648 foreach($taginfo as $tagged) {
650 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
654 $arr['uid'] = $page_owner_uid;
656 $arr['parent-uri'] = $uri;
657 $arr['type'] = 'activity';
659 $arr['contact-id'] = $owner_record['id'];
660 $arr['owner-name'] = $owner_record['name'];
661 $arr['owner-link'] = $owner_record['url'];
662 $arr['owner-avatar'] = $owner_record['thumb'];
663 $arr['author-name'] = $owner_record['name'];
664 $arr['author-link'] = $owner_record['url'];
665 $arr['author-avatar'] = $owner_record['thumb'];
667 $arr['allow_cid'] = $p[0]['allow_cid'];
668 $arr['allow_gid'] = $p[0]['allow_gid'];
669 $arr['deny_cid'] = $p[0]['deny_cid'];
670 $arr['deny_gid'] = $p[0]['deny_gid'];
671 $arr['last-child'] = 1;
673 $arr['verb'] = ACTIVITY_TAG;
674 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
675 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
676 $arr['tag'] = $tagged[4];
677 $arr['inform'] = $tagged[2];
679 $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]') ;
680 $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" ;
682 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
683 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
685 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
686 $arr['object'] .= '</link></object>' . "\n";
688 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
689 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
690 $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>';
692 $item_id = item_store($arr);
694 //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
695 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
696 // intval($page_owner_uid),
700 proc_run('php',"include/notifier.php","tag","$item_id");
707 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
708 return; // NOTREACHED
713 * default post action - upload a photo
716 call_hooks('photo_post_init', $_POST);
719 * Determine the album to use
722 $album = notags(trim($_REQUEST['album']));
723 $newalbum = notags(trim($_REQUEST['newalbum']));
725 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
727 if(! strlen($album)) {
728 if(strlen($newalbum))
731 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
736 * We create a wall item for every photo, but we don't want to
737 * overwhelm the data stream with a hundred newly uploaded photos.
738 * So we will make the first photo uploaded to this album in the last several hours
739 * visible by default, the rest will become visible over time when and if
740 * they acquire comments, likes, dislikes, and/or tags
744 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
746 intval($page_owner_uid)
748 if((! count($r)) || ($album == t('Profile Photos')))
753 if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
756 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
757 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
758 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
759 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
761 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
763 call_hooks('photo_post_file',$ret);
765 if(x($ret,'src') && x($ret,'filesize')) {
767 $filename = $ret['filename'];
768 $filesize = $ret['filesize'];
769 $type = $ret['type'];
772 $src = $_FILES['userfile']['tmp_name'];
773 $filename = basename($_FILES['userfile']['name']);
774 $filesize = intval($_FILES['userfile']['size']);
775 $type = $_FILES['userfile']['type'];
777 if ($type=="") $type=guess_image_type($filename);
779 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
781 $maximagesize = get_config('system','maximagesize');
783 if(($maximagesize) && ($filesize > $maximagesize)) {
784 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
787 call_hooks('photo_post_end',$foo);
792 notice( t('Image file is empty.') . EOL);
795 call_hooks('photo_post_end',$foo);
799 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
801 $imagedata = @file_get_contents($src);
805 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
806 intval($a->data['user']['uid'])
809 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
811 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
812 notice( upgrade_message() . EOL );
815 call_hooks('photo_post_end',$foo);
820 $ph = new Photo($imagedata, $type);
822 if(! $ph->is_valid()) {
823 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
824 notice( t('Unable to process image.') . EOL );
827 call_hooks('photo_post_end',$foo);
834 $max_length = get_config('system','max_image_length');
836 $max_length = MAX_IMAGE_LENGTH;
838 $ph->scaleImage($max_length);
840 $width = $ph->getWidth();
841 $height = $ph->getHeight();
845 $photo_hash = photo_new_resource();
847 $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);
850 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
851 notice( t('Image upload failed.') . EOL );
855 if($width > 640 || $height > 640) {
856 $ph->scaleImage(640);
857 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
861 if($width > 320 || $height > 320) {
862 $ph->scaleImage(320);
863 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
867 $basename = basename($filename);
868 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
870 // Create item container
874 $arr['uid'] = $page_owner_uid;
876 $arr['parent-uri'] = $uri;
877 $arr['type'] = 'photo';
879 $arr['resource-id'] = $photo_hash;
880 $arr['contact-id'] = $owner_record['id'];
881 $arr['owner-name'] = $owner_record['name'];
882 $arr['owner-link'] = $owner_record['url'];
883 $arr['owner-avatar'] = $owner_record['thumb'];
884 $arr['author-name'] = $owner_record['name'];
885 $arr['author-link'] = $owner_record['url'];
886 $arr['author-avatar'] = $owner_record['thumb'];
888 $arr['allow_cid'] = $str_contact_allow;
889 $arr['allow_gid'] = $str_group_allow;
890 $arr['deny_cid'] = $str_contact_deny;
891 $arr['deny_gid'] = $str_group_deny;
892 $arr['last-child'] = 1;
893 $arr['visible'] = $visible;
896 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
897 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
900 $item_id = item_store($arr);
903 // q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
904 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
905 // intval($page_owner_uid),
911 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
913 call_hooks('photo_post_end',intval($item_id));
915 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
916 // if they do not wish to be redirected
918 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
924 function photos_content(&$a) {
928 // photos/name/upload
929 // photos/name/upload/xxxxx (xxxxx is album name)
930 // photos/name/album/xxxxx
931 // photos/name/album/xxxxx/edit
932 // photos/name/image/xxxxx
933 // photos/name/image/xxxxx/edit
936 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
937 notice( t('Public access denied.') . EOL);
942 require_once('include/bbcode.php');
943 require_once('include/security.php');
944 require_once('include/conversation.php');
946 if(! x($a->data,'user')) {
947 notice( t('No photos selected') . EOL );
951 $phototypes = Photo::supportedTypes();
953 $_SESSION['photo_return'] = $a->cmd;
960 $datatype = $a->argv[2];
961 $datum = $a->argv[3];
963 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
964 $datatype = 'upload';
966 $datatype = 'summary';
974 // Setup permissions structures
980 $remote_contact = false;
983 $owner_uid = $a->data['user']['uid'];
985 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
987 if((local_user()) && (local_user() == $owner_uid))
990 if($community_page && remote_user()) {
991 if(is_array($_SESSION['remote'])) {
992 foreach($_SESSION['remote'] as $v) {
993 if($v['uid'] == $owner_uid) {
994 $contact_id = $v['cid'];
1001 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1002 intval($contact_id),
1008 $remote_contact = true;
1015 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1017 if(remote_user() && (! $visitor)) {
1019 if(is_array($_SESSION['remote'])) {
1020 foreach($_SESSION['remote'] as $v) {
1021 if($v['uid'] == $owner_uid) {
1022 $contact_id = $v['cid'];
1028 $groups = init_groups_visitor($contact_id);
1029 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1030 intval($contact_id),
1035 $remote_contact = true;
1040 if(! $remote_contact) {
1042 $contact_id = $_SESSION['cid'];
1043 $contact = $a->contact;
1047 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1048 notice( t('Access to this item is restricted.') . EOL);
1052 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
1057 $_is_owner = (local_user() && (local_user() == $owner_uid));
1058 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
1065 if($datatype === 'upload') {
1067 notice( t('Permission denied.'));
1072 $selname = (($datum) ? hex2bin($datum) : '');
1078 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1079 if(count($a->data['albums'])) {
1080 foreach($a->data['albums'] as $album) {
1081 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
1083 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1084 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1088 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
1092 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
1093 'addon_text' => $uploader,
1094 'default_upload' => true);
1097 call_hooks('photo_upload_form',$ret);
1099 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1100 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1101 '$submit' => t('Submit'),
1104 $usage_message = '';
1105 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1106 if($limit !== false) {
1108 $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1109 intval($a->data['user']['uid'])
1111 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1115 // Private/public post links for the non-JS ACL form
1117 if($_REQUEST['public'])
1120 $query_str = $a->query_string;
1121 if(strpos($query_str, 'public=1') !== false)
1122 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1124 // I think $a->query_string may never have ? in it, but I could be wrong
1125 // It looks like it's from the index.php?q=[etc] rewrite that the web
1126 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1127 if(strpos($query_str, '?') === false)
1128 $public_post_link = '?public=1';
1130 $public_post_link = '&public=1';
1134 $tpl = get_markup_template('photos_upload.tpl');
1136 if($a->theme['template_engine'] === 'internal') {
1137 $albumselect_e = template_escape($albumselect);
1138 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb)));
1141 $albumselect_e = $albumselect;
1142 $aclselect_e = (($visitor) ? '' : populate_acl($a->user, $celeb));
1145 $o .= replace_macros($tpl,array(
1146 '$pagename' => t('Upload Photos'),
1147 '$sessid' => session_id(),
1148 '$usage' => $usage_message,
1149 '$nickname' => $a->data['user']['nickname'],
1150 '$newalbum' => t('New album name: '),
1151 '$existalbumtext' => t('or existing album name: '),
1152 '$nosharetext' => t('Do not show a status post for this upload'),
1153 '$albumselect' => $albumselect_e,
1154 '$permissions' => t('Permissions'),
1155 '$aclselect' => $aclselect_e,
1156 '$alt_uploader' => $ret['addon_text'],
1157 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1158 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1159 '$uploadurl' => $ret['post_url'],
1161 // ACL permissions box
1162 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1163 '$group_perms' => t('Show to Groups'),
1164 '$contact_perms' => t('Show to Contacts'),
1165 '$private' => t('Private Photo'),
1166 '$public' => t('Public Photo'),
1167 '$is_private' => $private_post,
1168 '$return_path' => $query_str,
1169 '$public_link' => $public_post_link,
1176 if($datatype === 'album') {
1178 $album = hex2bin($datum);
1180 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1181 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1186 $a->set_pager_total(count($r));
1187 $a->set_pager_itemspage(20);
1190 if($_GET['order'] === 'posted')
1195 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1196 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1199 intval($a->pager['start']),
1200 intval($a->pager['itemspage'])
1203 if($cmd === 'edit') {
1204 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1206 $edit_tpl = get_markup_template('album_edit.tpl');
1208 if($a->theme['template_engine'] === 'internal') {
1209 $album_e = template_escape($album);
1215 $o .= replace_macros($edit_tpl,array(
1216 '$nametext' => t('New album name: '),
1217 '$nickname' => $a->data['user']['nickname'],
1218 '$album' => $album_e,
1219 '$hexalbum' => bin2hex($album),
1220 '$submit' => t('Submit'),
1221 '$dropsubmit' => t('Delete Album')
1227 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1229 $edit = array(t('Edit Album'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1234 if($_GET['order'] === 'posted')
1235 $order = array(t('Show Newest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1237 $order = array(t('Show Oldest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1242 $twist = 'rotright';
1243 foreach($r as $rr) {
1244 if($twist == 'rotright')
1247 $twist = 'rotright';
1249 $ext = $phototypes[$rr['type']];
1251 if($a->theme['template_engine'] === 'internal') {
1252 $imgalt_e = template_escape($rr['filename']);
1253 $desc_e = template_escape($rr['desc']);
1256 $imgalt_e = $rr['filename'];
1257 $desc_e = $rr['desc'];
1262 'twist' => ' ' . $twist . rand(2,4),
1263 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1264 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1265 'title' => t('View Photo'),
1266 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1270 'hash'=> $rr['resource_id'],
1274 $tpl = get_markup_template('photo_album.tpl');
1275 $o .= replace_macros($tpl, array(
1276 '$photos' => $photos,
1278 '$can_post' => $can_post,
1279 '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1291 if($datatype === 'image') {
1296 // fetch image, item containing image, then comments
1298 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1299 $sql_extra ORDER BY `scale` ASC ",
1305 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1311 notice( t('Permission denied. Access to this item may be restricted.'));
1313 notice( t('Photo not available') . EOL );
1320 if($_GET['order'] === 'posted')
1326 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1327 $sql_extra ORDER BY `created` $order ",
1328 dbesc($ph[0]['album']),
1332 if(count($prvnxt)) {
1333 for($z = 0; $z < count($prvnxt); $z++) {
1334 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1338 $prv = count($prvnxt) - 1;
1339 if($nxt >= count($prvnxt))
1344 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1345 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1346 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1351 $hires = $lores = $ph[0];
1352 if(count($ph) > 1) {
1353 if($ph[1]['scale'] == 2) {
1354 // original is 640 or less, we can display it directly
1355 $hires = $lores = $ph[0];
1363 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1367 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1369 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1370 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1374 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1375 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1376 ? t('Private Message')
1382 if( $cmd === 'edit') {
1383 $tpl = get_markup_template('photo_edit_head.tpl');
1384 $a->page['htmlhead'] .= replace_macros($tpl,array(
1385 '$prevlink' => $prevlink,
1386 '$nextlink' => $nextlink
1391 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1394 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1395 'title'=> t('View Full Size'),
1396 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1397 'height' => $hires['height'],
1398 'width' => $hires['width'],
1399 'album' => $hires['album'],
1400 'filename' => $hires['filename'],
1404 $nextlink = array($nextlink, '<div class="icon next"></div>');
1407 // Do we have an item for this photo?
1409 // FIXME! - replace following code to display the conversation with our normal
1410 // conversation functions so that it works correctly and tracks changes
1411 // in the evolving conversation code.
1412 // The difference is that we won't be displaying the conversation head item
1413 // as a "post" but displaying instead the photo it is linked to
1415 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1418 if(count($linked_items)) {
1419 $link_item = $linked_items[0];
1420 $r = q("SELECT COUNT(*) AS `total`
1421 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1422 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1423 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1424 AND `item`.`uid` = %d
1426 dbesc($link_item['uri']),
1427 dbesc($link_item['uri']),
1428 intval($link_item['uid'])
1433 $a->set_pager_total($r[0]['total']);
1436 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1437 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1438 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1439 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1440 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1441 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1442 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1443 AND `item`.`uid` = %d
1445 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1446 dbesc($link_item['uri']),
1447 dbesc($link_item['uri']),
1448 intval($link_item['uid']),
1449 intval($a->pager['start']),
1450 intval($a->pager['itemspage'])
1454 if((local_user()) && (local_user() == $link_item['uid'])) {
1455 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1456 intval($link_item['parent']),
1457 intval(local_user())
1459 update_thread($link_item['parent']);
1465 if(count($linked_items) && strlen($link_item['tag'])) {
1466 $arr = explode(',',$link_item['tag']);
1467 // parse tags and add links
1469 foreach($arr as $t) {
1470 if(strlen($tag_str))
1472 $tag_str .= bbcode($t);
1474 $tags = array(t('Tags: '), $tag_str);
1475 if($cmd === 'edit') {
1476 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1477 $tags[] = t('[Remove any tag]');
1483 if(($cmd === 'edit') && ($can_post)) {
1484 $edit_tpl = get_markup_template('photo_edit.tpl');
1486 // Private/public post links for the non-JS ACL form
1488 if($_REQUEST['public'])
1491 $query_str = $a->query_string;
1492 if(strpos($query_str, 'public=1') !== false)
1493 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1495 // I think $a->query_string may never have ? in it, but I could be wrong
1496 // It looks like it's from the index.php?q=[etc] rewrite that the web
1497 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1498 if(strpos($query_str, '?') === false)
1499 $public_post_link = '?public=1';
1501 $public_post_link = '&public=1';
1504 if($a->theme['template_engine'] === 'internal') {
1505 $album_e = template_escape($ph[0]['album']);
1506 $caption_e = template_escape($ph[0]['desc']);
1507 $aclselect_e = template_escape(populate_acl($ph[0]));
1510 $album_e = $ph[0]['album'];
1511 $caption_e = $ph[0]['desc'];
1512 $aclselect_e = populate_acl($ph[0]);
1515 $edit = replace_macros($edit_tpl, array(
1516 '$id' => $ph[0]['id'],
1517 '$rotatecw' => t('Rotate CW (right)'),
1518 '$rotateccw' => t('Rotate CCW (left)'),
1519 '$album' => $album_e,
1520 '$newalbum' => t('New album name'),
1521 '$nickname' => $a->data['user']['nickname'],
1522 '$resource_id' => $ph[0]['resource-id'],
1523 '$capt_label' => t('Caption'),
1524 '$caption' => $caption_e,
1525 '$tag_label' => t('Add a Tag'),
1526 '$tags' => $link_item['tag'],
1527 '$permissions' => t('Permissions'),
1528 '$aclselect' => $aclselect_e,
1529 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1530 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1531 '$submit' => t('Submit'),
1532 '$delete' => t('Delete Photo'),
1534 // ACL permissions box
1535 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1536 '$group_perms' => t('Show to Groups'),
1537 '$contact_perms' => t('Show to Contacts'),
1538 '$private' => t('Private photo'),
1539 '$public' => t('Public photo'),
1540 '$is_private' => $private_post,
1541 '$return_path' => $query_str,
1542 '$public_link' => $public_post_link,
1546 if(count($linked_items)) {
1548 $cmnt_tpl = get_markup_template('comment_item.tpl');
1549 $tpl = get_markup_template('photo_item.tpl');
1550 $return_url = $a->cmd;
1552 $like_tpl = get_markup_template('like_noshare.tpl');
1556 if($can_post || can_write_wall($a,$owner_uid)) {
1557 $likebuttons = replace_macros($like_tpl,array(
1558 '$id' => $link_item['id'],
1559 '$likethis' => t("I like this \x28toggle\x29"),
1560 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1561 '$share' => t('Share'),
1562 '$wait' => t('Please wait'),
1563 '$return_path' => $a->query_string,
1569 if($can_post || can_write_wall($a,$owner_uid)) {
1570 if($link_item['last-child']) {
1571 $comments .= replace_macros($cmnt_tpl,array(
1572 '$return_path' => '',
1573 '$jsreload' => $return_url,
1574 '$type' => 'wall-comment',
1575 '$id' => $link_item['id'],
1576 '$parent' => $link_item['id'],
1577 '$profile_uid' => $owner_uid,
1578 '$mylink' => $contact['url'],
1579 '$mytitle' => t('This is you'),
1580 '$myphoto' => $contact['thumb'],
1581 '$comment' => t('Comment'),
1582 '$submit' => t('Submit'),
1583 '$preview' => t('Preview'),
1584 '$sourceapp' => t($a->sourcename),
1586 '$rand_num' => random_digits(12)
1603 foreach($r as $item) {
1604 like_puller($a,$item,$alike,'like');
1605 like_puller($a,$item,$dlike,'dislike');
1608 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1609 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1613 if($can_post || can_write_wall($a,$owner_uid)) {
1614 if($link_item['last-child']) {
1615 $comments .= replace_macros($cmnt_tpl,array(
1616 '$return_path' => '',
1617 '$jsreload' => $return_url,
1618 '$type' => 'wall-comment',
1619 '$id' => $link_item['id'],
1620 '$parent' => $link_item['id'],
1621 '$profile_uid' => $owner_uid,
1622 '$mylink' => $contact['url'],
1623 '$mytitle' => t('This is you'),
1624 '$myphoto' => $contact['thumb'],
1625 '$comment' => t('Comment'),
1626 '$submit' => t('Submit'),
1627 '$preview' => t('Preview'),
1628 '$sourceapp' => t($a->sourcename),
1630 '$rand_num' => random_digits(12)
1636 foreach($r as $item) {
1641 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1644 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1647 if(local_user() && ($item['contact-uid'] == local_user())
1648 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1649 $profile_url = $redirect_url;
1650 $sparkle = ' sparkle';
1653 $profile_url = $item['url'];
1657 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1659 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1660 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1662 $profile_link = $profile_url;
1666 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1668 'dropping' => $dropping,
1669 'pagedrop' => false,
1670 'select' => t('Select'),
1671 'delete' => t('Delete'),
1675 if($a->theme['template_engine'] === 'internal') {
1676 $name_e = template_escape($profile_name);
1677 $title_e = template_escape($item['title']);
1678 $body_e = template_escape(bbcode($item['body']));
1681 $name_e = $profile_name;
1682 $title_e = $item['title'];
1683 $body_e = bbcode($item['body']);
1686 $comments .= replace_macros($template,array(
1687 '$id' => $item['item_id'],
1688 '$profile_url' => $profile_link,
1690 '$thumb' => $profile_avatar,
1691 '$sparkle' => $sparkle,
1692 '$title' => $title_e,
1694 '$ago' => relative_date($item['created']),
1695 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1697 '$comment' => $comment
1700 if($can_post || can_write_wall($a,$owner_uid)) {
1702 if($item['last-child']) {
1703 $comments .= replace_macros($cmnt_tpl,array(
1704 '$return_path' => '',
1705 '$jsreload' => $return_url,
1706 '$type' => 'wall-comment',
1707 '$id' => $item['item_id'],
1708 '$parent' => $item['parent'],
1709 '$profile_uid' => $owner_uid,
1710 '$mylink' => $contact['url'],
1711 '$mytitle' => t('This is you'),
1712 '$myphoto' => $contact['thumb'],
1713 '$comment' => t('Comment'),
1714 '$submit' => t('Submit'),
1715 '$preview' => t('Preview'),
1716 '$sourceapp' => t($a->sourcename),
1718 '$rand_num' => random_digits(12)
1725 $paginate = paginate($a);
1728 $photo_tpl = get_markup_template('photo_view.tpl');
1730 if($a->theme['template_engine'] === 'internal') {
1731 $album_e = array($album_link,template_escape($ph[0]['album']));
1732 $tags_e = template_escape($tags);
1733 $like_e = template_escape($like);
1734 $dislike_e = template_escape($dislike);
1737 $album_e = array($album_link,$ph[0]['album']);
1740 $dislike_e = $dislike;
1743 $o .= replace_macros($photo_tpl, array(
1744 '$id' => $ph[0]['id'],
1745 '$album' => $album_e,
1749 '$prevlink' => $prevlink,
1750 '$nextlink' => $nextlink,
1751 '$desc' => $ph[0]['desc'],
1754 '$likebuttons' => $likebuttons,
1756 '$dislike' => $dikslike_e,
1757 '$comments' => $comments,
1758 '$paginate' => $paginate,
1761 $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
1762 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
1763 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
1764 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
1765 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
1770 // Default - show recent photos with upload link (if applicable)
1773 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1774 $sql_extra GROUP BY `resource-id`",
1775 intval($a->data['user']['uid']),
1776 dbesc('Contact Photos'),
1777 dbesc( t('Contact Photos'))
1780 $a->set_pager_total(count($r));
1781 $a->set_pager_itemspage(20);
1784 $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
1785 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1786 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1787 intval($a->data['user']['uid']),
1788 dbesc('Contact Photos'),
1789 dbesc( t('Contact Photos')),
1790 intval($a->pager['start']),
1791 intval($a->pager['itemspage'])
1798 $twist = 'rotright';
1799 foreach($r as $rr) {
1800 if($twist == 'rotright')
1803 $twist = 'rotright';
1804 $ext = $phototypes[$rr['type']];
1806 if($a->theme['template_engine'] === 'internal') {
1807 $alt_e = template_escape($rr['filename']);
1808 $name_e = template_escape($rr['album']);
1811 $alt_e = $rr['filename'];
1812 $name_e = $rr['album'];
1817 'twist' => ' ' . $twist . rand(2,4),
1818 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1819 'title' => t('View Photo'),
1820 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1823 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1825 'alt' => t('View Album'),
1832 $tpl = get_markup_template('photos_recent.tpl');
1833 $o .= replace_macros($tpl, array(
1834 '$title' => t('Recent Photos'),
1835 '$can_post' => $can_post,
1836 '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),
1837 '$photos' => $photos,