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' AND `blocked` = 0 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;
53 function photos_post(&$a) {
58 $page_owner_uid = $a->data['user']['uid'];
59 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
61 if((local_user()) && (local_user() == $page_owner_uid))
64 if($community_page && remote_user()) {
65 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
66 intval(remote_user()),
67 intval($page_owner_uid)
71 $visitor = remote_user();
77 notice( t('Permission denied.') . EOL );
81 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
82 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
83 intval($page_owner_uid)
87 notice( t('Contact information unavailable') . EOL);
88 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
92 $owner_record = $r[0];
95 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
96 $album = hex2bin($a->argv[3]);
98 if($album == t('Profile Photos') || $album == t('Contact Photos')) {
99 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
100 return; // NOTREACHED
103 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
105 intval($page_owner_uid)
108 notice( t('Album not found.') . EOL);
109 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
110 return; // NOTREACHED
113 $newalbum = notags(trim($_POST['albumname']));
114 if($newalbum != $album) {
115 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
118 intval($page_owner_uid)
120 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
121 goaway($a->get_baseurl() . '/' . $newurl);
122 return; // NOTREACHED
126 if($_POST['dropalbum'] == t('Delete Album')) {
130 // get the list of photos we are about to delete
133 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
135 intval($page_owner_uid),
140 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
141 intval(local_user()),
147 $res[] = "'" . dbesc($rr['rid']) . "'" ;
151 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
152 return; // NOTREACHED
155 $str_res = implode(',', $res);
157 // remove the associated photos
159 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
160 intval($page_owner_uid)
163 // find and delete the corresponding item with all the comments and likes/dislikes
165 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
166 intval($page_owner_uid)
170 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
171 dbesc(datetime_convert()),
172 dbesc($rr['parent-uri']),
173 intval($page_owner_uid)
176 $drop_id = intval($rr['id']);
177 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
179 // send the notification upstream/downstream as the case may be
182 //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",array(),$foo));
183 proc_run($php_path,"include/notifier.php","drop","$drop_id");
187 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
188 return; // NOTREACHED
191 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
193 // same as above but remove single photo
196 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
198 intval($page_owner_uid),
203 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
204 intval(local_user()),
209 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
210 intval($page_owner_uid),
211 dbesc($r[0]['resource-id'])
213 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
214 dbesc($r[0]['resource-id']),
215 intval($page_owner_uid)
218 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
219 dbesc(datetime_convert()),
220 dbesc(datetime_convert()),
222 intval($page_owner_uid)
225 $url = $a->get_baseurl();
226 $drop_id = intval($i[0]['id']);
227 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
230 //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ", array(),$foo));
231 proc_run($php_path,"include/notifier.php","drop","$drop_id");
235 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
236 return; // NOTREACHED
239 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false))) {
241 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
242 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
243 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
244 $resource_id = $a->argv[2];
246 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
248 intval($page_owner_uid)
250 if((count($p)) && ($p[0]['desc'] !== $desc)) {
251 $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
254 intval($page_owner_uid)
259 // Create item container
262 $basename = basename($filename);
263 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
267 $arr['uid'] = $page_owner_uid;
269 $arr['parent-uri'] = $uri;
270 $arr['type'] = 'photo';
272 $arr['resource-id'] = $p[0]['resource-id'];
273 $arr['contact-id'] = $owner_record['id'];
274 $arr['owner-name'] = $owner_record['name'];
275 $arr['owner-link'] = $owner_record['url'];
276 $arr['owner-avatar'] = $owner_record['thumb'];
277 $arr['author-name'] = $owner_record['name'];
278 $arr['author-link'] = $owner_record['url'];
279 $arr['author-avatar'] = $owner_record['thumb'];
280 $arr['title'] = $title;
281 $arr['allow_cid'] = $p[0]['allow_cid'];
282 $arr['allow_gid'] = $p[0]['allow_gid'];
283 $arr['deny_cid'] = $p[0]['deny_cid'];
284 $arr['deny_gid'] = $p[0]['deny_gid'];
285 $arr['last-child'] = 1;
286 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
287 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
290 $item_id = item_store($arr);
295 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
297 intval($page_owner_uid)
301 $old_tag = $r[0]['tag'];
302 $old_inform = $r[0]['inform'];
305 if(strlen($rawtags)) {
310 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
312 $x = substr($rawtags,0,1);
313 if($x !== '@' && $x !== '#')
314 $rawtags = '#' . $rawtags;
317 $tags = get_tags($rawtags);
320 foreach($tags as $tag) {
321 if(strpos($tag,'@') === 0) {
322 $name = substr($tag,1);
323 if((strpos($name,'@')) || (strpos($name,'http://'))) {
325 $links = @lrdd($name);
327 foreach($links as $link) {
328 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
329 $profile = $link['@attributes']['href'];
330 if($link['@attributes']['rel'] === 'salmon') {
331 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
338 $taginfo[] = array($newname,$profile,$salmon);
342 if(strstr($name,'_')) {
343 $newname = str_replace('_',' ',$name);
344 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
346 intval($page_owner_uid)
350 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
352 intval($page_owner_uid)
356 $newname = $r[0]['name'];
357 $profile = $r[0]['url'];
358 $notify = 'cid:' . $r[0]['id'];
365 if(substr($notify,0,4) === 'cid:')
366 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
368 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
369 if(strlen($str_tags))
371 $profile = str_replace(',','%2c',$profile);
372 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
379 if(strlen($newtag) && strlen($str_tags))
381 $newtag .= $str_tags;
383 $newinform = $old_inform;
384 if(strlen($newinform) && strlen($inform))
386 $newinform .= $inform;
388 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
391 dbesc(datetime_convert()),
392 dbesc(datetime_convert()),
394 intval($page_owner_uid)
398 foreach($p as $scales) {
399 if(intval($scales['scale']) == 2) {
403 if(intval($scales['scale']) == 4) {
409 if(count($taginfo)) {
410 foreach($taginfo as $tagged) {
412 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
416 $arr['uid'] = $page_owner_uid;
418 $arr['parent-uri'] = $uri;
419 $arr['type'] = 'activity';
421 $arr['contact-id'] = $owner_record['id'];
422 $arr['owner-name'] = $owner_record['name'];
423 $arr['owner-link'] = $owner_record['url'];
424 $arr['owner-avatar'] = $owner_record['thumb'];
425 $arr['author-name'] = $owner_record['name'];
426 $arr['author-link'] = $owner_record['url'];
427 $arr['author-avatar'] = $owner_record['thumb'];
429 $arr['allow_cid'] = $p[0]['allow_cid'];
430 $arr['allow_gid'] = $p[0]['allow_gid'];
431 $arr['deny_cid'] = $p[0]['deny_cid'];
432 $arr['deny_gid'] = $p[0]['deny_gid'];
433 $arr['last-child'] = 1;
435 $arr['verb'] = ACTIVITY_TAG;
436 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
437 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
438 $arr['tag'] = $tagged[4];
439 $arr['inform'] = $tagged[2];
441 $arr['body'] = '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]' . ' ' . t('was tagged in a') . ' ' . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('photo') . '[/url]' . ' ' . t('by') . ' ' . '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]' ;
442 $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 . '.jpg' . '[/img][/url]' . "\n" ;
444 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
445 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
447 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
448 $arr['object'] .= '</link></object>' . "\n";
450 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
451 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
452 $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="image/jpeg" href="' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.jpg' . '" />') . '</link></target>';
454 $item_id = item_store($arr);
455 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
456 //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"tag\" \"$item_id\" & ",array(),$foo));
457 proc_run($php_path,"include/notifier.php","tag","$item_id");
463 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
464 return; // NOTREACHED
468 // default post action - upload a photo
470 if(! x($_FILES,'userfile'))
473 if($_POST['partitionCount'])
476 $java_upload = false;
478 $album = notags(trim($_POST['album']));
479 $newalbum = notags(trim($_POST['newalbum']));
481 if(! strlen($album)) {
482 if(strlen($newalbum))
485 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
488 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
490 intval($page_owner_uid)
492 if((! count($r)) || ($album == t('Profile Photos')))
498 $str_group_allow = perms2str($_POST['group_allow']);
499 $str_contact_allow = perms2str($_POST['contact_allow']);
500 $str_group_deny = perms2str($_POST['group_deny']);
501 $str_contact_deny = perms2str($_POST['contact_deny']);
503 $src = $_FILES['userfile']['tmp_name'];
504 $filename = basename($_FILES['userfile']['name']);
505 $filesize = intval($_FILES['userfile']['size']);
507 $maximagesize = get_config('system','maximagesize');
509 if(($maximagesize) && ($filesize > $maximagesize)) {
510 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
515 $imagedata = @file_get_contents($src);
516 $ph = new Photo($imagedata);
518 if(! $ph->is_valid()) {
519 notice( t('Unable to process image.') . EOL );
526 $width = $ph->getWidth();
527 $height = $ph->getHeight();
531 $photo_hash = photo_new_resource();
533 $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);
536 notice( t('Image upload failed.') . EOL );
540 if($width > 640 || $height > 640) {
541 $ph->scaleImage(640);
542 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
546 if($width > 320 || $height > 320) {
547 $ph->scaleImage(320);
548 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
552 $basename = basename($filename);
553 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
555 // Create item container
560 $arr['uid'] = $page_owner_uid;
562 $arr['parent-uri'] = $uri;
563 $arr['type'] = 'photo';
565 $arr['resource-id'] = $photo_hash;
566 $arr['contact-id'] = $owner_record['id'];
567 $arr['owner-name'] = $owner_record['name'];
568 $arr['owner-link'] = $owner_record['url'];
569 $arr['owner-avatar'] = $owner_record['thumb'];
570 $arr['author-name'] = $owner_record['name'];
571 $arr['author-link'] = $owner_record['url'];
572 $arr['author-avatar'] = $owner_record['thumb'];
574 $arr['allow_cid'] = $str_contact_allow;
575 $arr['allow_gid'] = $str_group_allow;
576 $arr['deny_cid'] = $str_contact_deny;
577 $arr['deny_gid'] = $str_group_deny;
578 $arr['last-child'] = 1;
579 $arr['visible'] = $visible;
580 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
581 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
584 $item_id = item_store($arr);
587 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
588 return; // NOTREACHED
592 return; // NOTREACHED
598 function photos_content(&$a) {
602 // photos/name/upload
603 // photos/name/album/xxxxx
604 // photos/name/album/xxxxx/edit
605 // photos/name/image/xxxxx
606 // photos/name/image/xxxxx/edit
609 if(! x($a->data,'user')) {
610 notice( t('No photos selected') . EOL );
614 $_SESSION['photo_return'] = $a->cmd;
621 $datatype = $a->argv[2];
622 $datum = $a->argv[3];
624 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
625 $datatype = 'upload';
627 $datatype = 'summary';
635 // Setup permissions structures
641 $remote_contact = false;
643 $owner_uid = $a->data['user']['uid'];
645 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
647 if((local_user()) && (local_user() == $owner_uid))
650 if($community_page && remote_user()) {
651 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
652 intval(remote_user()),
658 $remote_contact = true;
659 $visitor = remote_user();
664 // perhaps they're visiting - but not a community page, so they wouldn't have write access
666 if(remote_user() && (! $visitor)) {
667 $contact_id = $_SESSION['visitor_id'];
668 $groups = init_groups_visitor($contact_id);
669 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
670 intval(remote_user()),
675 $remote_contact = true;
679 if(! $remote_contact) {
681 $contact_id = $_SESSION['cid'];
682 $contact = $a->contact;
686 // default permissions - anonymous user
688 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
690 // Profile owner - everything is visible
692 if(local_user() && (local_user() == $owner_uid)) {
695 elseif(remote_user()) {
696 // authenticated visitor - here lie dragons
697 $gs = '<<>>'; // should be impossible to match
699 foreach($groups as $g)
700 $gs .= '|<' . intval($g) . '>';
702 $sql_extra = sprintf(
703 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
704 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
705 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
706 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
708 intval(remote_user()),
709 intval(remote_user()),
720 if($datatype === 'upload') {
722 notice( t('Permission denied.'));
725 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
727 $albumselect .= '<option value="" selected="selected" > </option>';
728 if(count($a->data['albums'])) {
729 foreach($a->data['albums'] as $album) {
730 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
732 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
736 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
738 $albumselect .= '</select>';
739 $tpl = load_view_file('view/photos_upload.tpl');
740 $o .= replace_macros($tpl,array(
741 '$pagename' => t('Upload Photos'),
742 '$sessid' => session_id(),
743 '$nickname' => $a->data['user']['nickname'],
744 '$newalbum' => t('New album name: '),
745 '$existalbumtext' => t('or existing album name: '),
746 '$filestext' => t('Select files to upload: '),
747 '$albumselect' => $albumselect,
748 '$permissions' => t('Permissions'),
749 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
750 '$archive' => $a->get_baseurl() . '/jumploader_z.jar',
751 '$nojava' => t('Use the following controls only if the Java uploader [above] fails to launch.'),
752 '$uploadurl' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
753 '$submit' => t('Submit')
759 if($datatype === 'album') {
761 $album = hex2bin($datum);
763 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
764 $sql_extra GROUP BY `resource-id`",
769 $a->set_pager_total(count($r));
770 $a->set_pager_itemspage(20);
773 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
774 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
777 intval($a->pager['start']),
778 intval($a->pager['itemspage'])
781 $o .= '<h3>' . $album . '</h3>';
783 if($cmd === 'edit') {
784 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
786 $edit_tpl = load_view_file('view/album_edit.tpl');
787 $o .= replace_macros($edit_tpl,array(
788 '$nametext' => t('New album name: '),
789 '$nickname' => $a->data['user']['nickname'],
791 '$hexalbum' => bin2hex($album),
792 '$submit' => t('Submit'),
793 '$dropsubmit' => t('Delete Album')
799 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
801 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
802 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
803 . t('Edit Album') . '</a></div>';
807 $tpl = load_view_file('view/photo_album.tpl');
810 $o .= replace_macros($tpl,array(
812 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
813 '$phototitle' => t('View Photo'),
814 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
815 '$imgalt' => $rr['filename']
819 $o .= '<div id="photo-album-end"></div>';
827 if($datatype === 'image') {
829 require_once('security.php');
830 require_once('bbcode.php');
832 $o = '<div id="live-display"></div>' . "\r\n";
833 // fetch image, item containing image, then comments
835 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
836 $sql_extra ORDER BY `scale` ASC ",
842 notice( t('Photo not available') . EOL );
847 $hires = $lores = $ph[0];
849 if($ph[1]['scale'] == 2) {
850 // original is 640 or less, we can display it directly
851 $hires = $lores = $ph[0];
860 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
862 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
863 $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>';
867 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
868 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
869 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
870 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
873 // Do we have an item for this photo?
875 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
878 if(count($linked_items)) {
879 $link_item = $linked_items[0];
880 $r = q("SELECT COUNT(*) AS `total`
881 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
882 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
883 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
884 AND `item`.`uid` = %d
886 dbesc($link_item['uri']),
887 dbesc($link_item['uri']),
888 intval($link_item['uid'])
893 $a->set_pager_total($r[0]['total']);
896 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
897 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
898 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
899 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
900 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
901 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
902 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
903 AND `item`.`uid` = %d
905 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
906 dbesc($link_item['uri']),
907 dbesc($link_item['uri']),
908 intval($link_item['uid']),
909 intval($a->pager['start']),
910 intval($a->pager['itemspage'])
914 if((local_user()) && (local_user() == $link_item['uid'])) {
915 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
916 intval($link_item['parent']),
922 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
924 if(count($linked_items) && strlen($link_item['tag'])) {
925 $arr = explode(',',$link_item['tag']);
926 // parse tags and add links
927 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
928 $o .= '<div id="in-this-photo">';
930 foreach($arr as $t) {
933 $tag_str .= bbcode($t);
935 $o .= $tag_str . '</div>';
937 $o .= '<div id="tag-remove"><a href="' . $a->get_baseurl() . '/tagrm/' . $link_item['id'] . '">' . t('[Remove any tag]') . '</a></div>';
941 if(($cmd === 'edit') && ($can_post)) {
942 $edit_tpl = load_view_file('view/photo_edit.tpl');
943 $o .= replace_macros($edit_tpl, array(
944 '$id' => $ph[0]['id'],
945 '$nickname' => $a->data['user']['nickname'],
946 '$resource_id' => $ph[0]['resource-id'],
947 '$capt_label' => t('Caption'),
948 '$caption' => $ph[0]['desc'],
949 '$tag_label' => t('Add a Tag'),
950 '$tags' => $link_item['tag'],
951 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
952 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
953 '$submit' => t('Submit'),
954 '$delete' => t('Delete Photo')
958 if(count($linked_items)) {
960 $cmnt_tpl = load_view_file('view/comment_item.tpl');
961 $tpl = load_view_file('view/photo_item.tpl');
962 $return_url = $a->cmd;
964 $like_tpl = load_view_file('view/like.tpl');
968 if($can_post || can_write_wall($a,$owner_uid))
969 $likebuttons = replace_macros($like_tpl,array('$id' => $link_item['id']));
972 $o .= '<div id="photo-like-div">';
976 if($can_post || can_write_wall($a,$owner_uid)) {
977 if($link_item['last-child']) {
978 $o .= replace_macros($cmnt_tpl,array(
979 '$return_path' => $return_url,
980 '$type' => 'wall-comment',
981 '$id' => $link_item['id'],
982 '$parent' => $link_item['id'],
983 '$profile_uid' => $owner_uid,
984 '$mylink' => $contact['url'],
985 '$mytitle' => t('This is you'),
986 '$myphoto' => $contact['thumb'],
999 foreach($r as $item) {
1000 like_puller($a,$item,$alike,'like');
1001 like_puller($a,$item,$dlike,'dislike');
1004 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1005 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1007 $o .= '<div id="photo-like-div">';
1015 if($can_post || can_write_wall($a,$owner_uid)) {
1016 if($link_item['last-child']) {
1017 $o .= replace_macros($cmnt_tpl,array(
1018 '$return_path' => $return_url,
1019 '$type' => 'wall-comment',
1020 '$id' => $link_item['id'],
1021 '$parent' => $link_item['id'],
1022 '$profile_uid' => $owner_uid,
1023 '$mylink' => $contact['url'],
1024 '$mytitle' => t('This is you'),
1025 '$myphoto' => $contact['thumb'],
1032 foreach($r as $item) {
1037 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1040 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1042 if($can_post || can_write_wall($a,$owner_uid)) {
1044 if($item['last-child']) {
1045 $comment = replace_macros($cmnt_tpl,array(
1046 '$return_path' => $return_url,
1047 '$type' => 'wall-comment',
1048 '$id' => $item['item_id'],
1049 '$parent' => $item['parent'],
1050 '$profile_uid' => $owner_uid,
1051 '$mylink' => $contact['url'],
1052 '$mytitle' => t('This is you'),
1053 '$myphoto' => $contact['thumb'],
1060 if(local_user() && ($item['contact-uid'] == local_user())
1061 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1062 $profile_url = $redirect_url;
1063 $sparkle = ' sparkle';
1066 $profile_url = $item['url'];
1070 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1072 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1073 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1075 $profile_link = $profile_url;
1079 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1080 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
1083 $o .= replace_macros($template,array(
1084 '$id' => $item['item_id'],
1085 '$profile_url' => $profile_link,
1086 '$name' => $profile_name,
1087 '$thumb' => $profile_avatar,
1088 '$sparkle' => $sparkle,
1089 '$title' => $item['title'],
1090 '$body' => bbcode($item['body']),
1091 '$ago' => relative_date($item['created']),
1092 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1094 '$comment' => $comment
1104 // Default - show recent photos with upload link (if applicable)
1107 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1108 $sql_extra GROUP BY `resource-id`",
1109 intval($a->data['user']['uid']),
1110 dbesc( t('Contact Photos'))
1113 $a->set_pager_total(count($r));
1114 $a->set_pager_itemspage(20);
1117 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1118 WHERE `uid` = %d AND `album` != '%s'
1119 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1120 intval($a->data['user']['uid']),
1121 dbesc( t('Contact Photos')),
1122 intval($a->pager['start']),
1123 intval($a->pager['itemspage'])
1126 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1129 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1130 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1133 $tpl = load_view_file('view/photo_top.tpl');
1135 foreach($r as $rr) {
1136 $o .= replace_macros($tpl,array(
1138 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
1139 . '/image/' . $rr['resource-id'],
1140 '$phototitle' => t('View Photo'),
1141 '$imgsrc' => $a->get_baseurl() . '/photo/'
1142 . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1143 '$albumlink' => $a->get_baseurl() . '/photos/'
1144 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1145 '$albumname' => $rr['album'],
1146 '$albumalt' => t('View Album'),
1147 '$imgalt' => $rr['filename']
1151 $o .= '<div id="photo-top-end"></div>';