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\" & ",
188 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
189 return; // NOTREACHED
192 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
194 // same as above but remove single photo
197 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
199 intval($page_owner_uid),
204 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
205 intval(local_user()),
210 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
211 intval($page_owner_uid),
212 dbesc($r[0]['resource-id'])
214 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
215 dbesc($r[0]['resource-id']),
216 intval($page_owner_uid)
219 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
220 dbesc(datetime_convert()),
221 dbesc(datetime_convert()),
223 intval($page_owner_uid)
226 $url = $a->get_baseurl();
227 $drop_id = intval($i[0]['id']);
228 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
231 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",
236 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
237 return; // NOTREACHED
240 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false))) {
242 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
243 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
244 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
245 $resource_id = $a->argv[2];
247 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
249 intval($page_owner_uid)
251 if((count($p)) && ($p[0]['desc'] !== $desc)) {
252 $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
255 intval($page_owner_uid)
260 // Create item container
263 $basename = basename($filename);
264 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
268 $arr['uid'] = $page_owner_uid;
270 $arr['parent-uri'] = $uri;
271 $arr['type'] = 'photo';
273 $arr['resource-id'] = $p[0]['resource-id'];
274 $arr['contact-id'] = $owner_record['id'];
275 $arr['owner-name'] = $owner_record['name'];
276 $arr['owner-link'] = $owner_record['url'];
277 $arr['owner-avatar'] = $owner_record['thumb'];
278 $arr['author-name'] = $owner_record['name'];
279 $arr['author-link'] = $owner_record['url'];
280 $arr['author-avatar'] = $owner_record['thumb'];
281 $arr['title'] = $title;
282 $arr['allow_cid'] = $p[0]['allow_cid'];
283 $arr['allow_gid'] = $p[0]['allow_gid'];
284 $arr['deny_cid'] = $p[0]['deny_cid'];
285 $arr['deny_gid'] = $p[0]['deny_gid'];
286 $arr['last-child'] = 1;
287 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
288 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
291 $item_id = item_store($arr);
296 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
298 intval($page_owner_uid)
302 $old_tag = $r[0]['tag'];
303 $old_inform = $r[0]['inform'];
306 if(strlen($rawtags)) {
311 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
313 $x = substr($rawtags,0,1);
314 if($x !== '@' && $x !== '#')
315 $rawtags = '#' . $rawtags;
318 $tags = get_tags($rawtags);
321 foreach($tags as $tag) {
322 if(strpos($tag,'@') === 0) {
323 $name = substr($tag,1);
324 if((strpos($name,'@')) || (strpos($name,'http://'))) {
326 $links = @lrdd($name);
328 foreach($links as $link) {
329 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
330 $profile = $link['@attributes']['href'];
331 if($link['@attributes']['rel'] === 'salmon') {
332 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
339 $taginfo[] = array($newname,$profile,$salmon);
343 if(strstr($name,'_')) {
344 $newname = str_replace('_',' ',$name);
345 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
347 intval($page_owner_uid)
351 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
353 intval($page_owner_uid)
357 $newname = $r[0]['name'];
358 $profile = $r[0]['url'];
359 $notify = 'cid:' . $r[0]['id'];
366 if(substr($notify,0,4) === 'cid:')
367 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
369 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
370 if(strlen($str_tags))
372 $profile = str_replace(',','%2c',$profile);
373 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
380 if(strlen($newtag) && strlen($str_tags))
382 $newtag .= $str_tags;
384 $newinform = $old_inform;
385 if(strlen($newinform) && strlen($inform))
387 $newinform .= $inform;
389 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
392 dbesc(datetime_convert()),
393 dbesc(datetime_convert()),
395 intval($page_owner_uid)
399 foreach($p as $scales) {
400 if(intval($scales['scale']) == 2) {
404 if(intval($scales['scale']) == 4) {
410 if(count($taginfo)) {
411 foreach($taginfo as $tagged) {
413 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
417 $arr['uid'] = $page_owner_uid;
419 $arr['parent-uri'] = $uri;
420 $arr['type'] = 'activity';
422 $arr['contact-id'] = $owner_record['id'];
423 $arr['owner-name'] = $owner_record['name'];
424 $arr['owner-link'] = $owner_record['url'];
425 $arr['owner-avatar'] = $owner_record['thumb'];
426 $arr['author-name'] = $owner_record['name'];
427 $arr['author-link'] = $owner_record['url'];
428 $arr['author-avatar'] = $owner_record['thumb'];
430 $arr['allow_cid'] = $p[0]['allow_cid'];
431 $arr['allow_gid'] = $p[0]['allow_gid'];
432 $arr['deny_cid'] = $p[0]['deny_cid'];
433 $arr['deny_gid'] = $p[0]['deny_gid'];
434 $arr['last-child'] = 1;
436 $arr['verb'] = ACTIVITY_TAG;
437 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
438 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
439 $arr['tag'] = $tagged[4];
440 $arr['inform'] = $tagged[2];
442 $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]' ;
443 $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" ;
445 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
446 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
448 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
449 $arr['object'] .= '</link></object>' . "\n";
451 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
452 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
453 $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>';
455 $item_id = item_store($arr);
456 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
457 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"tag\" \"$item_id\" & ",
464 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
465 return; // NOTREACHED
469 // default post action - upload a photo
471 if(! x($_FILES,'userfile'))
474 if($_POST['partitionCount'])
477 $java_upload = false;
479 $album = notags(trim($_POST['album']));
480 $newalbum = notags(trim($_POST['newalbum']));
482 if(! strlen($album)) {
483 if(strlen($newalbum))
486 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
489 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
491 intval($page_owner_uid)
493 if((! count($r)) || ($album == t('Profile Photos')))
499 $str_group_allow = perms2str($_POST['group_allow']);
500 $str_contact_allow = perms2str($_POST['contact_allow']);
501 $str_group_deny = perms2str($_POST['group_deny']);
502 $str_contact_deny = perms2str($_POST['contact_deny']);
504 $src = $_FILES['userfile']['tmp_name'];
505 $filename = basename($_FILES['userfile']['name']);
506 $filesize = intval($_FILES['userfile']['size']);
508 $maximagesize = get_config('system','maximagesize');
510 if(($maximagesize) && ($filesize > $maximagesize)) {
511 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
516 $imagedata = @file_get_contents($src);
517 $ph = new Photo($imagedata);
519 if(! $ph->is_valid()) {
520 notice( t('Unable to process image.') . EOL );
527 $width = $ph->getWidth();
528 $height = $ph->getHeight();
532 $photo_hash = photo_new_resource();
534 $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);
537 notice( t('Image upload failed.') . EOL );
541 if($width > 640 || $height > 640) {
542 $ph->scaleImage(640);
543 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
547 if($width > 320 || $height > 320) {
548 $ph->scaleImage(320);
549 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
553 $basename = basename($filename);
554 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
556 // Create item container
561 $arr['uid'] = $page_owner_uid;
563 $arr['parent-uri'] = $uri;
564 $arr['type'] = 'photo';
566 $arr['resource-id'] = $photo_hash;
567 $arr['contact-id'] = $owner_record['id'];
568 $arr['owner-name'] = $owner_record['name'];
569 $arr['owner-link'] = $owner_record['url'];
570 $arr['owner-avatar'] = $owner_record['thumb'];
571 $arr['author-name'] = $owner_record['name'];
572 $arr['author-link'] = $owner_record['url'];
573 $arr['author-avatar'] = $owner_record['thumb'];
575 $arr['allow_cid'] = $str_contact_allow;
576 $arr['allow_gid'] = $str_group_allow;
577 $arr['deny_cid'] = $str_contact_deny;
578 $arr['deny_gid'] = $str_group_deny;
579 $arr['last-child'] = 1;
580 $arr['visible'] = $visible;
581 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
582 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
585 $item_id = item_store($arr);
588 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
589 return; // NOTREACHED
593 return; // NOTREACHED
599 function photos_content(&$a) {
603 // photos/name/upload
604 // photos/name/album/xxxxx
605 // photos/name/album/xxxxx/edit
606 // photos/name/image/xxxxx
607 // photos/name/image/xxxxx/edit
610 if(! x($a->data,'user')) {
611 notice( t('No photos selected') . EOL );
615 $_SESSION['photo_return'] = $a->cmd;
622 $datatype = $a->argv[2];
623 $datum = $a->argv[3];
625 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
626 $datatype = 'upload';
628 $datatype = 'summary';
636 // Setup permissions structures
642 $remote_contact = false;
644 $owner_uid = $a->data['user']['uid'];
646 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
648 if((local_user()) && (local_user() == $owner_uid))
651 if($community_page && remote_user()) {
652 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
653 intval(remote_user()),
659 $remote_contact = true;
660 $visitor = remote_user();
665 // perhaps they're visiting - but not a community page, so they wouldn't have write access
667 if(remote_user() && (! $visitor)) {
668 $contact_id = $_SESSION['visitor_id'];
669 $groups = init_groups_visitor($contact_id);
670 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
671 intval(remote_user()),
676 $remote_contact = true;
680 if(! $remote_contact) {
682 $contact_id = $_SESSION['cid'];
683 $contact = $a->contact;
687 // default permissions - anonymous user
689 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
691 // Profile owner - everything is visible
693 if(local_user() && (local_user() == $owner_uid)) {
696 elseif(remote_user()) {
697 // authenticated visitor - here lie dragons
698 $gs = '<<>>'; // should be impossible to match
700 foreach($groups as $g)
701 $gs .= '|<' . intval($g) . '>';
703 $sql_extra = sprintf(
704 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
705 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
706 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
707 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
709 intval(remote_user()),
710 intval(remote_user()),
721 if($datatype === 'upload') {
723 notice( t('Permission denied.'));
726 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
728 $albumselect .= '<option value="" selected="selected" > </option>';
729 if(count($a->data['albums'])) {
730 foreach($a->data['albums'] as $album) {
731 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
733 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
737 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
739 $albumselect .= '</select>';
740 $tpl = load_view_file('view/photos_upload.tpl');
741 $o .= replace_macros($tpl,array(
742 '$pagename' => t('Upload Photos'),
743 '$sessid' => session_id(),
744 '$nickname' => $a->data['user']['nickname'],
745 '$newalbum' => t('New album name: '),
746 '$existalbumtext' => t('or existing album name: '),
747 '$filestext' => t('Select files to upload: '),
748 '$albumselect' => $albumselect,
749 '$permissions' => t('Permissions'),
750 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
751 '$archive' => $a->get_baseurl() . '/jumploader_z.jar',
752 '$nojava' => t('Use the following controls only if the Java uploader [above] fails to launch.'),
753 '$uploadurl' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
754 '$submit' => t('Submit')
760 if($datatype === 'album') {
762 $album = hex2bin($datum);
764 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
765 $sql_extra GROUP BY `resource-id`",
770 $a->set_pager_total(count($r));
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>';
825 if($datatype === 'image') {
827 require_once('security.php');
828 require_once('bbcode.php');
830 $o = '<div id="live-display"></div>' . "\r\n";
831 // fetch image, item containing image, then comments
833 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
834 $sql_extra ORDER BY `scale` ASC ",
840 notice( t('Photo not available') . EOL );
845 $hires = $lores = $ph[0];
847 if($ph[1]['scale'] == 2) {
848 // original is 640 or less, we can display it directly
849 $hires = $lores = $ph[0];
858 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
860 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
861 $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>';
865 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
866 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
867 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
868 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
871 // Do we have an item for this photo?
873 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
876 if(count($linked_items)) {
877 $link_item = $linked_items[0];
878 $r = q("SELECT COUNT(*) AS `total`
879 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
880 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
881 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
882 AND `item`.`uid` = %d
884 dbesc($link_item['uri']),
885 dbesc($link_item['uri']),
886 intval($link_item['uid'])
891 $a->set_pager_total($r[0]['total']);
894 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
895 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
896 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
897 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
898 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
899 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
900 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
901 AND `item`.`uid` = %d
903 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
904 dbesc($link_item['uri']),
905 dbesc($link_item['uri']),
906 intval($link_item['uid']),
907 intval($a->pager['start']),
908 intval($a->pager['itemspage'])
912 if((local_user()) && (local_user() == $link_item['uid'])) {
913 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
914 intval($link_item['parent']),
920 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
922 if(count($linked_items) && strlen($link_item['tag'])) {
923 $arr = explode(',',$link_item['tag']);
924 // parse tags and add links
925 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
926 $o .= '<div id="in-this-photo">';
928 foreach($arr as $t) {
931 $tag_str .= bbcode($t);
933 $o .= $tag_str . '</div>';
935 $o .= '<div id="tag-remove"><a href="' . $a->get_baseurl() . '/tagrm/' . $link_item['id'] . '">' . t('[Remove any tag]') . '</a></div>';
939 if(($cmd === 'edit') && ($can_post)) {
940 $edit_tpl = load_view_file('view/photo_edit.tpl');
941 $o .= replace_macros($edit_tpl, array(
942 '$id' => $ph[0]['id'],
943 '$nickname' => $a->data['user']['nickname'],
944 '$resource_id' => $ph[0]['resource-id'],
945 '$capt_label' => t('Caption'),
946 '$caption' => $ph[0]['desc'],
947 '$tag_label' => t('Add a Tag'),
948 '$tags' => $link_item['tag'],
949 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
950 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
951 '$submit' => t('Submit'),
952 '$delete' => t('Delete Photo')
956 if(count($linked_items)) {
958 $cmnt_tpl = load_view_file('view/comment_item.tpl');
959 $tpl = load_view_file('view/photo_item.tpl');
960 $return_url = $a->cmd;
962 $like_tpl = load_view_file('view/like.tpl');
966 if($can_post || can_write_wall($a,$owner_uid))
967 $likebuttons = replace_macros($like_tpl,array('$id' => $link_item['id']));
970 $o .= '<div id="photo-like-div">';
974 if($can_post || can_write_wall($a,$owner_uid)) {
975 if($link_item['last-child']) {
976 $o .= replace_macros($cmnt_tpl,array(
977 '$return_path' => $return_url,
978 '$type' => 'wall-comment',
979 '$id' => $link_item['id'],
980 '$parent' => $link_item['id'],
981 '$profile_uid' => $owner_uid,
982 '$mylink' => $contact['url'],
983 '$mytitle' => t('This is you'),
984 '$myphoto' => $contact['thumb'],
997 foreach($r as $item) {
998 like_puller($a,$item,$alike,'like');
999 like_puller($a,$item,$dlike,'dislike');
1002 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1003 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1005 $o .= '<div id="photo-like-div">';
1013 if($can_post || can_write_wall($a,$owner_uid)) {
1014 if($link_item['last-child']) {
1015 $o .= replace_macros($cmnt_tpl,array(
1016 '$return_path' => $return_url,
1017 '$type' => 'wall-comment',
1018 '$id' => $link_item['id'],
1019 '$parent' => $link_item['id'],
1020 '$profile_uid' => $owner_uid,
1021 '$mylink' => $contact['url'],
1022 '$mytitle' => t('This is you'),
1023 '$myphoto' => $contact['thumb'],
1030 foreach($r as $item) {
1035 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1038 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1040 if($can_post || can_write_wall($a,$owner_uid)) {
1042 if($item['last-child']) {
1043 $comment = replace_macros($cmnt_tpl,array(
1044 '$return_path' => $return_url,
1045 '$type' => 'wall-comment',
1046 '$id' => $item['item_id'],
1047 '$parent' => $item['parent'],
1048 '$profile_uid' => $owner_uid,
1049 '$mylink' => $contact['url'],
1050 '$mytitle' => t('This is you'),
1051 '$myphoto' => $contact['thumb'],
1058 if(local_user() && ($item['contact-uid'] == local_user())
1059 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1060 $profile_url = $redirect_url;
1061 $sparkle = ' sparkle';
1064 $profile_url = $item['url'];
1068 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1070 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1071 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1073 $profile_link = $profile_url;
1077 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1078 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
1081 $o .= replace_macros($template,array(
1082 '$id' => $item['item_id'],
1083 '$profile_url' => $profile_link,
1084 '$name' => $profile_name,
1085 '$thumb' => $profile_avatar,
1086 '$sparkle' => $sparkle,
1087 '$title' => $item['title'],
1088 '$body' => bbcode($item['body']),
1089 '$ago' => relative_date($item['created']),
1090 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1092 '$comment' => $comment
1102 // Default - show recent photos with upload link (if applicable)
1105 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1106 $sql_extra GROUP BY `resource-id`",
1107 intval($a->data['user']['uid']),
1108 dbesc( t('Contact Photos'))
1111 $a->set_pager_total(count($r));
1114 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1115 WHERE `uid` = %d AND `album` != '%s'
1116 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1117 intval($a->data['user']['uid']),
1118 dbesc( t('Contact Photos')),
1119 intval($a->pager['start']),
1120 intval($a->pager['itemspage'])
1123 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1126 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1127 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1130 $tpl = load_view_file('view/photo_top.tpl');
1132 foreach($r as $rr) {
1133 $o .= replace_macros($tpl,array(
1135 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
1136 . '/image/' . $rr['resource-id'],
1137 '$phototitle' => t('View Photo'),
1138 '$imgsrc' => $a->get_baseurl() . '/photo/'
1139 . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1140 '$albumlink' => $a->get_baseurl() . '/photos/'
1141 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1142 '$albumname' => $rr['album'],
1143 '$albumalt' => t('View Album'),
1144 '$imgalt' => $rr['filename']
1148 $o .= '<div id="photo-top-end"></div>';