3 require_once('Photo.php');
4 require_once('include/items.php');
5 require_once('view/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 $imagedata = @file_get_contents($src);
457 $ph = new Photo($imagedata);
459 if(! $ph->is_valid()) {
460 notice( t('Unable to process image.') . EOL );
467 $width = $ph->getWidth();
468 $height = $ph->getHeight();
472 $photo_hash = photo_new_resource();
474 $r = $ph->store(local_user(), 0, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
477 notice( t('Image upload failed.') . EOL );
481 if($width > 640 || $height > 640) {
482 $ph->scaleImage(640);
483 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
487 if($width > 320 || $height > 320) {
488 $ph->scaleImage(320);
489 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
493 $basename = basename($filename);
494 $uri = item_new_uri($a->get_hostname(), local_user());
496 // Create item container
501 $arr['uid'] = local_user();
503 $arr['parent-uri'] = $uri;
504 $arr['type'] = 'photo';
506 $arr['resource-id'] = $photo_hash;
507 $arr['contact-id'] = $contact_record['id'];
508 $arr['owner-name'] = $contact_record['name'];
509 $arr['owner-link'] = $contact_record['url'];
510 $arr['owner-avatar'] = $contact_record['thumb'];
511 $arr['author-name'] = $contact_record['name'];
512 $arr['author-link'] = $contact_record['url'];
513 $arr['author-avatar'] = $contact_record['thumb'];
515 $arr['allow_cid'] = $str_contact_allow;
516 $arr['allow_gid'] = $str_group_allow;
517 $arr['deny_cid'] = $str_contact_deny;
518 $arr['deny_gid'] = $str_group_deny;
519 $arr['last-child'] = 1;
520 $arr['visible'] = $visible;
521 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']'
522 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
525 $item_id = item_store($arr);
528 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
529 return; // NOTREACHED
533 return; // NOTREACHED
539 function photos_content(&$a) {
543 // photos/name/upload
544 // photos/name/album/xxxxx
545 // photos/name/album/xxxxx/edit
546 // photos/name/image/xxxxx
547 // photos/name/image/xxxxx/edit
550 if(! x($a->data,'user')) {
551 notice( t('No photos selected') . EOL );
555 $_SESSION['photo_return'] = $a->cmd;
562 $datatype = $a->argv[2];
563 $datum = $a->argv[3];
565 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
566 $datatype = 'upload';
568 $datatype = 'summary';
576 // Setup permissions structures
579 $owner_uid = $a->data['user']['uid'];
584 $remote_contact = false;
587 $contact_id = $_SESSION['visitor_id'];
588 $groups = init_groups_visitor($contact_id);
589 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
595 $remote_contact = true;
599 if(! $remote_contact) {
601 $contact_id = $_SESSION['cid'];
602 $contact = $a->contact;
607 // default permissions - anonymous user
609 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
611 // Profile owner - everything is visible
613 if(local_user() && (local_user() == $owner_uid)) {
616 elseif(remote_user()) {
617 // authenticated visitor - here lie dragons
618 $gs = '<<>>'; // should be impossible to match
620 foreach($groups as $g)
621 $gs .= '|<' . intval($g) . '>';
623 $sql_extra = sprintf(
624 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
625 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
626 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
627 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
629 intval($_SESSION['visitor_id']),
630 intval($_SESSION['visitor_id']),
641 if($datatype === 'upload') {
642 if( ! (local_user() && (local_user() == $a->data['user']['uid']))) {
643 notice( t('Permission denied.'));
646 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
648 $albumselect .= '<option value="" selected="selected" > </option>';
649 if(count($a->data['albums'])) {
650 foreach($a->data['albums'] as $album) {
651 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
653 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
657 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
659 $albumselect .= '</select>';
660 $tpl = load_view_file('view/photos_upload.tpl');
661 $o .= replace_macros($tpl,array(
662 '$pagename' => t('Upload Photos'),
663 '$sessid' => session_id(),
664 '$newalbum' => t('New album name: '),
665 '$existalbumtext' => t('or existing album name: '),
666 '$filestext' => t('Select files to upload: '),
667 '$albumselect' => $albumselect,
668 '$permissions' => t('Permissions'),
669 '$aclselect' => populate_acl($a->user, $celeb),
670 '$archive' => $a->get_baseurl() . '/jumploader_z.jar',
671 '$nojava' => t('Use the following controls only if the Java uploader [above] fails to launch.'),
672 '$uploadurl' => $a->get_baseurl() . '/photos',
673 '$submit' => t('Submit')
680 if($datatype === 'album') {
682 $album = hex2bin($datum);
684 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
685 $sql_extra GROUP BY `resource-id`",
686 intval($a->data['user']['uid']),
690 $a->set_pager_total(count($r));
693 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
694 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
695 intval($a->data['user']['uid']),
697 intval($a->pager['start']),
698 intval($a->pager['itemspage'])
701 $o .= '<h3>' . $album . '</h3>';
703 if($cmd === 'edit') {
704 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
705 if(local_user() && (local_user() == $a->data['user']['uid'])) {
706 $edit_tpl = load_view_file('view/album_edit.tpl');
707 $o .= replace_macros($edit_tpl,array(
708 '$nametext' => t('New album name: '),
710 '$hexalbum' => bin2hex($album),
711 '$submit' => t('Submit'),
712 '$dropsubmit' => t('Delete Album')
718 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
719 if(local_user() && (local_user() == $a->data['user']['uid'])) {
720 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
721 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
722 . t('Edit Album') . '</a></div>';
726 $tpl = load_view_file('view/photo_album.tpl');
729 $o .= replace_macros($tpl,array(
731 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
732 '$phototitle' => t('View Photo'),
733 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
734 '$imgalt' => $rr['filename']
738 $o .= '<div id="photo-album-end"></div>';
744 if($datatype === 'image') {
746 require_once('security.php');
747 require_once('bbcode.php');
749 $o = '<div id="live-display"></div>' . "\r\n";
750 // fetch image, item containing image, then comments
752 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
753 $sql_extra ORDER BY `scale` ASC ",
754 intval($a->data['user']['uid']),
759 notice( t('Photo not available') . EOL );
764 $hires = $lores = $ph[0];
766 if($ph[1]['scale'] == 2) {
767 // original is 640 or less, we can display it directly
768 $hires = $lores = $ph[0];
777 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
779 if(local_user() && ($ph[0]['uid'] == local_user())) {
780 $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>';
784 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
785 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
786 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
787 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
790 // Do we have an item for this photo?
792 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
795 if(count($linked_items)) {
796 $link_item = $linked_items[0];
797 $r = q("SELECT COUNT(*) AS `total`
798 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
799 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
800 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
801 AND `item`.`uid` = %d
803 dbesc($link_item['uri']),
804 dbesc($link_item['uri']),
805 intval($link_item['uid'])
810 $a->set_pager_total($r[0]['total']);
813 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
814 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
815 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
816 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
817 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
818 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
819 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
820 AND `item`.`uid` = %d
822 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
823 dbesc($link_item['uri']),
824 dbesc($link_item['uri']),
825 intval($link_item['uid']),
826 intval($a->pager['start']),
827 intval($a->pager['itemspage'])
831 if((local_user()) && (local_user() == $link_item['uid'])) {
832 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
833 intval($link_item['parent']),
839 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
841 if(count($linked_items) && strlen($link_item['tag'])) {
842 $arr = explode(',',$link_item['tag']);
843 // parse tags and add links
844 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
845 $o .= '<div id="in-this-photo">';
847 foreach($arr as $t) {
850 $tag_str .= bbcode($t);
852 $o .= $tag_str . '</div>';
854 $o .= '<div id="tag-remove"><a href="' . $a->get_baseurl() . '/tagrm/' . $link_item['id'] . '">' . t('[Remove any tag]') . '</a></div>';
858 if($cmd === 'edit') {
859 $edit_tpl = load_view_file('view/photo_edit.tpl');
860 $o .= replace_macros($edit_tpl, array(
861 '$id' => $ph[0]['id'],
862 '$resource_id' => $ph[0]['resource-id'],
863 '$capt_label' => t('Caption'),
864 '$caption' => $ph[0]['desc'],
865 '$tag_label' => t('Add a Tag'),
866 '$tags' => $link_item['tag'],
867 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
868 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
869 '$submit' => t('Submit'),
870 '$delete' => t('Delete Photo')
875 if(count($linked_items)) {
877 $cmnt_tpl = load_view_file('view/comment_item.tpl');
878 $tpl = load_view_file('view/photo_item.tpl');
879 $return_url = $a->cmd;
881 $like_tpl = load_view_file('view/like.tpl');
885 if(can_write_wall($a,$a->data['user']['uid']))
886 $likebuttons = replace_macros($like_tpl,array('$id' => $link_item['id']));
889 $o .= '<div id="photo-like-div">';
893 if(can_write_wall($a,$a->data['user']['uid'])) {
894 if($link_item['last-child']) {
895 $o .= replace_macros($cmnt_tpl,array(
896 '$return_path' => $return_url,
897 '$type' => 'wall-comment',
898 '$id' => $link_item['id'],
899 '$parent' => $link_item['id'],
900 '$profile_uid' => $a->data['user']['uid'],
901 '$mylink' => $contact['url'],
902 '$mytitle' => t('This is you'),
903 '$myphoto' => $contact['thumb'],
916 foreach($r as $item) {
917 like_puller($a,$item,$alike,'like');
918 like_puller($a,$item,$dlike,'dislike');
921 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
922 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
924 $o .= '<div id="photo-like-div">';
932 if(can_write_wall($a,$a->data['user']['uid'])) {
933 if($link_item['last-child']) {
934 $o .= replace_macros($cmnt_tpl,array(
935 '$return_path' => $return_url,
936 '$type' => 'wall-comment',
937 '$id' => $link_item['id'],
938 '$parent' => $link_item['id'],
939 '$profile_uid' => $a->data['user']['uid'],
940 '$mylink' => $contact['url'],
941 '$mytitle' => t('This is you'),
942 '$myphoto' => $contact['thumb'],
949 foreach($r as $item) {
954 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
957 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
959 if(can_write_wall($a,$a->data['user']['uid'])) {
961 if($item['last-child']) {
962 $comment = replace_macros($cmnt_tpl,array(
963 '$return_path' => $return_url,
964 '$type' => 'wall-comment',
965 '$id' => $item['item_id'],
966 '$parent' => $item['parent'],
967 '$profile_uid' => $a->data['user']['uid'],
968 '$mylink' => $contact['url'],
969 '$mytitle' => t('This is you'),
970 '$myphoto' => $contact['thumb'],
977 if(local_user() && ($item['contact-uid'] == local_user())
978 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
979 $profile_url = $redirect_url;
980 $sparkle = ' sparkle';
983 $profile_url = $item['url'];
987 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
988 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
989 $profile_link = $profile_url;
993 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
994 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
997 $o .= replace_macros($template,array(
998 '$id' => $item['item_id'],
999 '$profile_url' => $profile_link,
1000 '$name' => $profile_name,
1001 '$thumb' => $profile_avatar,
1002 '$sparkle' => $sparkle,
1003 '$title' => $item['title'],
1004 '$body' => bbcode($item['body']),
1005 '$ago' => relative_date($item['created']),
1006 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1008 '$comment' => $comment
1018 // Default - show recent photos with upload link (if applicable)
1021 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1022 $sql_extra GROUP BY `resource-id`",
1023 intval($a->data['user']['uid']),
1024 dbesc( t('Contact Photos'))
1027 $a->set_pager_total(count($r));
1030 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1031 WHERE `uid` = %d AND `album` != '%s'
1032 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1033 intval($a->data['user']['uid']),
1034 dbesc( t('Contact Photos')),
1035 intval($a->pager['start']),
1036 intval($a->pager['itemspage'])
1039 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1041 if( local_user() && (local_user() == $a->data['user']['uid'])) {
1042 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1043 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1046 $tpl = load_view_file('view/photo_top.tpl');
1048 foreach($r as $rr) {
1049 $o .= replace_macros($tpl,array(
1051 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
1052 . '/image/' . $rr['resource-id'],
1053 '$phototitle' => t('View Photo'),
1054 '$imgsrc' => $a->get_baseurl() . '/photo/'
1055 . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1056 '$albumlink' => $a->get_baseurl() . '/photos/'
1057 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1058 '$albumname' => $rr['album'],
1059 '$albumalt' => t('View Album'),
1060 '$imgalt' => $rr['filename']
1064 $o .= '<div id="photo-top-end"></div>';