3 require_once('include/Photo.php');
4 require_once('include/items.php');
5 require_once('include/acl_selectors.php');
6 require_once('include/bbcode.php');
8 function photos_init(&$a) {
14 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1",
21 $a->data['user'] = $r[0];
23 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d",
24 intval($a->data['user']['uid'])
28 $a->data['albums'] = $albums;
30 $o .= '<h4><a href="' . $a->get_baseurl() . '/profile/' . $a->data['user']['nickname'] . '">' . $a->data['user']['username'] . '</a></h4>';
31 $o .= '<h4>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h4>';
34 foreach($albums as $album) {
35 if((! strlen($album['album'])) || ($album['album'] == t('Contact Photos')))
37 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" />' . $album['album'] . '</a></li>';
42 if(! x($a->page,'aside'))
43 $a->page['aside'] = '';
44 $a->page['aside'] .= $o;
52 function photos_post(&$a) {
56 notice( t('Permission denied.') . EOL );
60 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
61 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
66 notice( t('Contact information unavailable') . EOL);
67 logger('photos_post: unable to locate contact record for logged in user. uid=' . local_user());
71 $contact_record = $r[0];
74 if(($a->argc > 2) && ($a->argv[1] === 'album')) {
75 $album = hex2bin($a->argv[2]);
77 if($album == t('Profile Photos') || $album == t('Contact Photos')) {
78 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
82 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
87 notice( t('Album not found.') . EOL);
88 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
92 $newalbum = notags(trim($_POST['albumname']));
93 if($newalbum != $album) {
94 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
99 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
100 goaway($a->get_baseurl() . '/' . $newurl);
101 return; // NOTREACHED
104 if($_POST['dropalbum'] == t('Delete Album')) {
107 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
108 intval(local_user()),
113 $res[] = "'" . dbesc($rr['rid']) . "'" ;
117 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
118 return; // NOTREACHED
120 $str_res = implode(',', $res);
122 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
125 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
130 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
131 dbesc(datetime_convert()),
132 dbesc($rr['parent-uri']),
136 $drop_id = intval($rr['id']);
137 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
139 // send the notification upstream/downstream as the case may be
142 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",
148 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
149 return; // NOTREACHED
152 if(($a->argc > 1) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
153 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
154 intval(local_user()),
158 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
159 intval(local_user()),
160 dbesc($r[0]['resource-id'])
162 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
163 dbesc($r[0]['resource-id']),
167 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
168 dbesc(datetime_convert()),
169 dbesc(datetime_convert()),
174 $url = $a->get_baseurl();
175 $drop_id = intval($i[0]['id']);
176 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
179 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",
184 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
185 return; // NOTREACHED
188 if(($a->argc > 1) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false))) {
190 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
191 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
192 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
193 $resource_id = $a->argv[1];
195 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
199 if((count($p)) && ($p[0]['desc'] !== $desc)) {
200 $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
208 // Create item container
211 $basename = basename($filename);
212 $uri = item_new_uri($a->get_hostname(),local_user());
216 $arr['uid'] = local_user();
218 $arr['parent-uri'] = $uri;
219 $arr['type'] = 'photo';
221 $arr['resource-id'] = $p[0]['resource-id'];
222 $arr['contact-id'] = $contact_record['id'];
223 $arr['owner-name'] = $contact_record['name'];
224 $arr['owner-link'] = $contact_record['url'];
225 $arr['owner-avatar'] = $contact_record['thumb'];
226 $arr['author-name'] = $contact_record['name'];
227 $arr['author-link'] = $contact_record['url'];
228 $arr['author-avatar'] = $contact_record['thumb'];
229 $arr['title'] = $title;
230 $arr['allow_cid'] = $p[0]['allow_cid'];
231 $arr['allow_gid'] = $p[0]['allow_gid'];
232 $arr['deny_cid'] = $p[0]['deny_cid'];
233 $arr['deny_gid'] = $p[0]['deny_gid'];
234 $arr['last-child'] = 1;
235 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
236 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
239 $item_id = item_store($arr);
244 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
250 $old_tag = $r[0]['tag'];
251 $old_inform = $r[0]['inform'];
254 if(strlen($rawtags)) {
259 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
261 $x = substr($rawtags,0,1);
262 if($x !== '@' && $x !== '#')
263 $rawtags = '#' . $rawtags;
266 $tags = get_tags($rawtags);
269 foreach($tags as $tag) {
270 if(strpos($tag,'@') === 0) {
271 $name = substr($tag,1);
272 if((strpos($name,'@')) || (strpos($name,'http://'))) {
274 $links = @lrdd($name);
276 foreach($links as $link) {
277 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
278 $profile = $link['@attributes']['href'];
279 if($link['@attributes']['rel'] === 'salmon') {
280 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
287 $taginfo[] = array($newname,$profile,$salmon);
291 if(strstr($name,'_')) {
292 $newname = str_replace('_',' ',$name);
293 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
299 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
305 $newname = $r[0]['name'];
306 $profile = $r[0]['url'];
307 $notify = 'cid:' . $r[0]['id'];
314 if(substr($notify,0,4) === 'cid:')
315 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
317 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
318 if(strlen($str_tags))
320 $profile = str_replace(',','%2c',$profile);
321 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
328 if(strlen($newtag) && strlen($str_tags))
330 $newtag .= $str_tags;
332 $newinform = $old_inform;
333 if(strlen($newinform) && strlen($inform))
335 $newinform .= $inform;
337 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
340 dbesc(datetime_convert()),
341 dbesc(datetime_convert()),
347 foreach($p as $scales) {
348 if(intval($scales['scale']) == 2) {
352 if(intval($scales['scale']) == 4) {
358 if(count($taginfo)) {
359 foreach($taginfo as $tagged) {
361 $uri = item_new_uri($a->get_hostname(),local_user());
365 $arr['uid'] = local_user();
367 $arr['parent-uri'] = $uri;
368 $arr['type'] = 'activity';
370 $arr['contact-id'] = $contact_record['id'];
371 $arr['owner-name'] = $contact_record['name'];
372 $arr['owner-link'] = $contact_record['url'];
373 $arr['owner-avatar'] = $contact_record['thumb'];
374 $arr['author-name'] = $contact_record['name'];
375 $arr['author-link'] = $contact_record['url'];
376 $arr['author-avatar'] = $contact_record['thumb'];
378 $arr['allow_cid'] = $p[0]['allow_cid'];
379 $arr['allow_gid'] = $p[0]['allow_gid'];
380 $arr['deny_cid'] = $p[0]['deny_cid'];
381 $arr['deny_gid'] = $p[0]['deny_gid'];
382 $arr['last-child'] = 1;
384 $arr['verb'] = ACTIVITY_TAG;
385 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
386 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
387 $arr['tag'] = $tagged[4];
388 $arr['inform'] = $tagged[2];
390 $arr['body'] = '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]' . ' ' . t('was tagged in a') . ' ' . '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('photo') . '[/url]' . ' ' . t('by') . ' ' . '[url=' . $contact_record['url'] . ']' . $contact_record['name'] . '[/url]' ;
391 $arr['body'] .= "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.jpg' . '[/img][/url]' . "\n" ;
393 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
394 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
396 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
397 $arr['object'] .= '</link></object>' . "\n";
399 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
400 . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
401 $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="image/jpeg" href="' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.jpg' . '" />') . '</link></target>';
403 $item_id = item_store($arr);
404 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
405 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"tag\" \"$item_id\" & ",
412 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
413 return; // NOTREACHED
417 // default post action - upload a photo
419 if(! x($_FILES,'userfile'))
422 if($_POST['partitionCount'])
425 $java_upload = false;
427 $album = notags(trim($_POST['album']));
428 $newalbum = notags(trim($_POST['newalbum']));
430 if(! strlen($album)) {
431 if(strlen($newalbum))
434 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
437 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
441 if((! count($r)) || ($album == t('Profile Photos')))
447 $str_group_allow = perms2str($_POST['group_allow']);
448 $str_contact_allow = perms2str($_POST['contact_allow']);
449 $str_group_deny = perms2str($_POST['group_deny']);
450 $str_contact_deny = perms2str($_POST['contact_deny']);
452 $src = $_FILES['userfile']['tmp_name'];
453 $filename = basename($_FILES['userfile']['name']);
454 $filesize = intval($_FILES['userfile']['size']);
456 $maximagesize = get_config('system','maximagesize');
458 if(($maximagesize) && ($filesize > $maximagesize)) {
459 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
464 $imagedata = @file_get_contents($src);
465 $ph = new Photo($imagedata);
467 if(! $ph->is_valid()) {
468 notice( t('Unable to process image.') . EOL );
475 $width = $ph->getWidth();
476 $height = $ph->getHeight();
480 $photo_hash = photo_new_resource();
482 $r = $ph->store(local_user(), 0, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
485 notice( t('Image upload failed.') . EOL );
489 if($width > 640 || $height > 640) {
490 $ph->scaleImage(640);
491 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
495 if($width > 320 || $height > 320) {
496 $ph->scaleImage(320);
497 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
501 $basename = basename($filename);
502 $uri = item_new_uri($a->get_hostname(), local_user());
504 // Create item container
509 $arr['uid'] = local_user();
511 $arr['parent-uri'] = $uri;
512 $arr['type'] = 'photo';
514 $arr['resource-id'] = $photo_hash;
515 $arr['contact-id'] = $contact_record['id'];
516 $arr['owner-name'] = $contact_record['name'];
517 $arr['owner-link'] = $contact_record['url'];
518 $arr['owner-avatar'] = $contact_record['thumb'];
519 $arr['author-name'] = $contact_record['name'];
520 $arr['author-link'] = $contact_record['url'];
521 $arr['author-avatar'] = $contact_record['thumb'];
523 $arr['allow_cid'] = $str_contact_allow;
524 $arr['allow_gid'] = $str_group_allow;
525 $arr['deny_cid'] = $str_contact_deny;
526 $arr['deny_gid'] = $str_group_deny;
527 $arr['last-child'] = 1;
528 $arr['visible'] = $visible;
529 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']'
530 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
533 $item_id = item_store($arr);
536 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
537 return; // NOTREACHED
541 return; // NOTREACHED
547 function photos_content(&$a) {
551 // photos/name/upload
552 // photos/name/album/xxxxx
553 // photos/name/album/xxxxx/edit
554 // photos/name/image/xxxxx
555 // photos/name/image/xxxxx/edit
558 if(! x($a->data,'user')) {
559 notice( t('No photos selected') . EOL );
563 $_SESSION['photo_return'] = $a->cmd;
570 $datatype = $a->argv[2];
571 $datum = $a->argv[3];
573 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
574 $datatype = 'upload';
576 $datatype = 'summary';
584 // Setup permissions structures
587 $owner_uid = $a->data['user']['uid'];
592 $remote_contact = false;
595 $contact_id = $_SESSION['visitor_id'];
596 $groups = init_groups_visitor($contact_id);
597 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
603 $remote_contact = true;
607 if(! $remote_contact) {
609 $contact_id = $_SESSION['cid'];
610 $contact = $a->contact;
615 // default permissions - anonymous user
617 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
619 // Profile owner - everything is visible
621 if(local_user() && (local_user() == $owner_uid)) {
624 elseif(remote_user()) {
625 // authenticated visitor - here lie dragons
626 $gs = '<<>>'; // should be impossible to match
628 foreach($groups as $g)
629 $gs .= '|<' . intval($g) . '>';
631 $sql_extra = sprintf(
632 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
633 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
634 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
635 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
637 intval($_SESSION['visitor_id']),
638 intval($_SESSION['visitor_id']),
649 if($datatype === 'upload') {
650 if( ! (local_user() && (local_user() == $a->data['user']['uid']))) {
651 notice( t('Permission denied.'));
654 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
656 $albumselect .= '<option value="" selected="selected" > </option>';
657 if(count($a->data['albums'])) {
658 foreach($a->data['albums'] as $album) {
659 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
661 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
665 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
667 $albumselect .= '</select>';
668 $tpl = load_view_file('view/photos_upload.tpl');
669 $o .= replace_macros($tpl,array(
670 '$pagename' => t('Upload Photos'),
671 '$sessid' => session_id(),
672 '$newalbum' => t('New album name: '),
673 '$existalbumtext' => t('or existing album name: '),
674 '$filestext' => t('Select files to upload: '),
675 '$albumselect' => $albumselect,
676 '$permissions' => t('Permissions'),
677 '$aclselect' => populate_acl($a->user, $celeb),
678 '$archive' => $a->get_baseurl() . '/jumploader_z.jar',
679 '$nojava' => t('Use the following controls only if the Java uploader [above] fails to launch.'),
680 '$uploadurl' => $a->get_baseurl() . '/photos',
681 '$submit' => t('Submit')
688 if($datatype === 'album') {
690 $album = hex2bin($datum);
692 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
693 $sql_extra GROUP BY `resource-id`",
694 intval($a->data['user']['uid']),
698 $a->set_pager_total(count($r));
701 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
702 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
703 intval($a->data['user']['uid']),
705 intval($a->pager['start']),
706 intval($a->pager['itemspage'])
709 $o .= '<h3>' . $album . '</h3>';
711 if($cmd === 'edit') {
712 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
713 if(local_user() && (local_user() == $a->data['user']['uid'])) {
714 $edit_tpl = load_view_file('view/album_edit.tpl');
715 $o .= replace_macros($edit_tpl,array(
716 '$nametext' => t('New album name: '),
718 '$hexalbum' => bin2hex($album),
719 '$submit' => t('Submit'),
720 '$dropsubmit' => t('Delete Album')
726 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
727 if(local_user() && (local_user() == $a->data['user']['uid'])) {
728 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
729 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
730 . t('Edit Album') . '</a></div>';
734 $tpl = load_view_file('view/photo_album.tpl');
737 $o .= replace_macros($tpl,array(
739 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
740 '$phototitle' => t('View Photo'),
741 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
742 '$imgalt' => $rr['filename']
746 $o .= '<div id="photo-album-end"></div>';
752 if($datatype === 'image') {
754 require_once('security.php');
755 require_once('bbcode.php');
757 $o = '<div id="live-display"></div>' . "\r\n";
758 // fetch image, item containing image, then comments
760 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
761 $sql_extra ORDER BY `scale` ASC ",
762 intval($a->data['user']['uid']),
767 notice( t('Photo not available') . EOL );
772 $hires = $lores = $ph[0];
774 if($ph[1]['scale'] == 2) {
775 // original is 640 or less, we can display it directly
776 $hires = $lores = $ph[0];
785 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
787 if(local_user() && ($ph[0]['uid'] == local_user())) {
788 $o .= '<div id="photo-edit-link-wrap" ><a id="photo-edit-link" href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit' . '">' . t('Edit photo') . '</a></div>';
792 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
793 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
794 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
795 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
798 // Do we have an item for this photo?
800 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
803 if(count($linked_items)) {
804 $link_item = $linked_items[0];
805 $r = q("SELECT COUNT(*) AS `total`
806 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
807 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
808 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
809 AND `item`.`uid` = %d
811 dbesc($link_item['uri']),
812 dbesc($link_item['uri']),
813 intval($link_item['uid'])
818 $a->set_pager_total($r[0]['total']);
821 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
822 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
823 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
824 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
825 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
826 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
827 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
828 AND `item`.`uid` = %d
830 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
831 dbesc($link_item['uri']),
832 dbesc($link_item['uri']),
833 intval($link_item['uid']),
834 intval($a->pager['start']),
835 intval($a->pager['itemspage'])
839 if((local_user()) && (local_user() == $link_item['uid'])) {
840 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
841 intval($link_item['parent']),
847 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
849 if(count($linked_items) && strlen($link_item['tag'])) {
850 $arr = explode(',',$link_item['tag']);
851 // parse tags and add links
852 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
853 $o .= '<div id="in-this-photo">';
855 foreach($arr as $t) {
858 $tag_str .= bbcode($t);
860 $o .= $tag_str . '</div>';
862 $o .= '<div id="tag-remove"><a href="' . $a->get_baseurl() . '/tagrm/' . $link_item['id'] . '">' . t('[Remove any tag]') . '</a></div>';
866 if($cmd === 'edit') {
867 $edit_tpl = load_view_file('view/photo_edit.tpl');
868 $o .= replace_macros($edit_tpl, array(
869 '$id' => $ph[0]['id'],
870 '$resource_id' => $ph[0]['resource-id'],
871 '$capt_label' => t('Caption'),
872 '$caption' => $ph[0]['desc'],
873 '$tag_label' => t('Add a Tag'),
874 '$tags' => $link_item['tag'],
875 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
876 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
877 '$submit' => t('Submit'),
878 '$delete' => t('Delete Photo')
883 if(count($linked_items)) {
885 $cmnt_tpl = load_view_file('view/comment_item.tpl');
886 $tpl = load_view_file('view/photo_item.tpl');
887 $return_url = $a->cmd;
889 $like_tpl = load_view_file('view/like.tpl');
893 if(can_write_wall($a,$a->data['user']['uid']))
894 $likebuttons = replace_macros($like_tpl,array('$id' => $link_item['id']));
897 $o .= '<div id="photo-like-div">';
901 if(can_write_wall($a,$a->data['user']['uid'])) {
902 if($link_item['last-child']) {
903 $o .= replace_macros($cmnt_tpl,array(
904 '$return_path' => $return_url,
905 '$type' => 'wall-comment',
906 '$id' => $link_item['id'],
907 '$parent' => $link_item['id'],
908 '$profile_uid' => $a->data['user']['uid'],
909 '$mylink' => $contact['url'],
910 '$mytitle' => t('This is you'),
911 '$myphoto' => $contact['thumb'],
924 foreach($r as $item) {
925 like_puller($a,$item,$alike,'like');
926 like_puller($a,$item,$dlike,'dislike');
929 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
930 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
932 $o .= '<div id="photo-like-div">';
940 if(can_write_wall($a,$a->data['user']['uid'])) {
941 if($link_item['last-child']) {
942 $o .= replace_macros($cmnt_tpl,array(
943 '$return_path' => $return_url,
944 '$type' => 'wall-comment',
945 '$id' => $link_item['id'],
946 '$parent' => $link_item['id'],
947 '$profile_uid' => $a->data['user']['uid'],
948 '$mylink' => $contact['url'],
949 '$mytitle' => t('This is you'),
950 '$myphoto' => $contact['thumb'],
957 foreach($r as $item) {
962 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
965 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
967 if(can_write_wall($a,$a->data['user']['uid'])) {
969 if($item['last-child']) {
970 $comment = replace_macros($cmnt_tpl,array(
971 '$return_path' => $return_url,
972 '$type' => 'wall-comment',
973 '$id' => $item['item_id'],
974 '$parent' => $item['parent'],
975 '$profile_uid' => $a->data['user']['uid'],
976 '$mylink' => $contact['url'],
977 '$mytitle' => t('This is you'),
978 '$myphoto' => $contact['thumb'],
985 if(local_user() && ($item['contact-uid'] == local_user())
986 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
987 $profile_url = $redirect_url;
988 $sparkle = ' sparkle';
991 $profile_url = $item['url'];
995 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
996 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
997 $profile_link = $profile_url;
1001 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1002 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
1005 $o .= replace_macros($template,array(
1006 '$id' => $item['item_id'],
1007 '$profile_url' => $profile_link,
1008 '$name' => $profile_name,
1009 '$thumb' => $profile_avatar,
1010 '$sparkle' => $sparkle,
1011 '$title' => $item['title'],
1012 '$body' => bbcode($item['body']),
1013 '$ago' => relative_date($item['created']),
1014 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1016 '$comment' => $comment
1026 // Default - show recent photos with upload link (if applicable)
1029 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1030 $sql_extra GROUP BY `resource-id`",
1031 intval($a->data['user']['uid']),
1032 dbesc( t('Contact Photos'))
1035 $a->set_pager_total(count($r));
1038 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1039 WHERE `uid` = %d AND `album` != '%s'
1040 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1041 intval($a->data['user']['uid']),
1042 dbesc( t('Contact Photos')),
1043 intval($a->pager['start']),
1044 intval($a->pager['itemspage'])
1047 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1049 if( local_user() && (local_user() == $a->data['user']['uid'])) {
1050 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1051 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1054 $tpl = load_view_file('view/photo_top.tpl');
1056 foreach($r as $rr) {
1057 $o .= replace_macros($tpl,array(
1059 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
1060 . '/image/' . $rr['resource-id'],
1061 '$phototitle' => t('View Photo'),
1062 '$imgsrc' => $a->get_baseurl() . '/photo/'
1063 . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1064 '$albumlink' => $a->get_baseurl() . '/photos/'
1065 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1066 '$albumname' => $rr['album'],
1067 '$albumalt' => t('View Album'),
1068 '$imgalt' => $rr['filename']
1072 $o .= '<div id="photo-top-end"></div>';