<?php
require_once('Photo.php');
+require_once('include/items.php');
require_once('view/acl_selectors.php');
function photos_init(&$a) {
}
$a->page['aside'] .= $o;
}
-
-
+ return;
}
killme();
}
+
+
+ $r = q("SELECT `contact`.* `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
+ WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
+ intval(get_uid())
+ );
+
+ $contact_record = $r[0];
+
+
+ if(($a->argc > 2) && ($a->argv[1] == 'album')) {
+ $album = hex2bin($a->argv[2]);
+
+ if($album == t('Profile Photos') || $album == t('Contact Photos')) {
+ goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
+ return; // NOTREACHED
+ }
+
+ $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
+ dbesc($album),
+ intval(get_uid())
+ );
+ if(! count($r)) {
+ notice( t('Album not found.') . EOL);
+ goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
+ return; // NOTREACHED
+ }
+
+ $newalbum = notags(trim($_POST['albumname']));
+ if($newalbum != $album) {
+ q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
+ dbesc($newalbum),
+ dbesc($album),
+ intval(get_uid())
+ );
+ $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
+ goaway($a->get_baseurl() . '/' . $newurl);
+ return; // NOTREACHED
+ }
+
+ if($_POST['dropalbum'] == t('Delete Album')) {
+
+ $res = array();
+ $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
+ intval(get_uid()),
+ dbesc($album)
+ );
+ if(count($r)) {
+ foreach($r as $rr) {
+ $res[] = "'" . dbesc($rr['rid']) . "'" ;
+ }
+ }
+ else {
+ goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
+ return; // NOTREACHED
+ }
+ $str_res = implode(',', $res);
+
+ q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
+ intval(get_uid())
+ );
+ $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
+ intval(get_uid())
+ );
+ if(count($r)) {
+ foreach($r as $rr) {
+ q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
+ dbesc(datetime_convert()),
+ dbesc($rr['parent-uri']),
+ intval(get_uid())
+ );
+
+ $drop_id = intval($rr['id']);
+ $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
+
+ // send the notification upstream/downstream as the case may be
+
+ if($rr['visible'])
+ proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",
+ array(),$foo));
+
+ }
+ }
+ }
+ goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
+ return; // NOTREACHED
+ }
+
+ if(($a->argc > 1) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
+ $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
+ intval(get_uid()),
+ dbesc($a->argv[1])
+ );
+ if(count($r)) {
+ q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
+ intval(get_uid()),
+ dbesc($r[0]['resource-id'])
+ );
+ $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($r[0]['resource-id']),
+ intval(get_uid())
+ );
+ if(count($i)) {
+ q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($i[0]['uri']),
+ intval(get_uid())
+ );
+
+ $url = $a->get_baseurl();
+ $drop_id = intval($i[0]['id']);
+ $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
+
+ // send the notification upstream/downstream as the case may be
+
+ if($i[0]['visible'])
+ proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",
+ array(),$foo));
+ }
+ }
+
+ goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
+ return; // NOTREACHED
+ }
+
+
+
if(($a->argc > 1) && (x($_POST,'desc') !== false)) {
$desc = notags(trim($_POST['desc']));
$tags = notags(trim($_POST['tags']));
$item_id = intval($_POST['item_id']);
- $id = $a->argv[1];
+ $resource_id = $a->argv[1];
- $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
- dbesc($desc),
- intval($id),
- intval($_SESSION['uid'])
+ $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
+ dbesc($resource_id),
+ intval(get_uid())
);
- $r = q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ if(count($r)) {
+ $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
+ dbesc($desc),
+ dbesc($resource_id),
+ intval(get_uid())
+ );
+ }
+ if(! $item_id) {
+
+ $title = '';
+ $basename = basename($filename);
+ $uri = item_new_uri($a->get_hostname(),get_uid());
+ // Create item container
+
+ $arr = array();
+
+ $arr['uid'] = get_uid();
+ $arr['uri'] = $uri;
+ $arr['parent-uri'] = $uri;
+ $arr['type'] = 'photo';
+ $arr['wall'] = 1;
+ $arr['resource-id'] = $p[0]['resource-id'];
+ $arr['contact-id'] = $contact_record['id'];
+ $arr['owner-name'] = $contact_record['name'];
+ $arr['owner-link'] = $contact_record['url'];
+ $arr['owner-avatar'] = $contact_record['thumb'];
+ $arr['title'] = $title;
+ $arr['allow_cid'] = $p[0]['allow_cid'];
+ $arr['allow_gid'] = $p[0]['allow_gid'];
+ $arr['deny_cid'] = $p[0]['deny_cid'];
+ $arr['deny_gid'] = $p[0]['deny_gid'];
+ $arr['last-child'] = 1;
+ $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
+ . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
+ . '[/url]';
+
+ $item_id = item_store($arr);
+
+ }
+
+ $r = q("UPDATE `item` SET `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
dbesc($tags),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
intval($item_id),
- intval($_SESSION['uid'])
+ intval(get_uid())
);
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
- $r = q("SELECT * FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
- intval($_SESSION['uid'])
- );
-
- $contact_record = $r[0];
if(! x($_FILES,'userfile'))
killme();
$album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
}
- $str_group_allow = '';
- $group_allow = $_POST['group_allow'];
- if(is_array($group_allow)) {
- array_walk($group_allow,'sanitise_acl');
- $str_group_allow = implode('',$group_allow);
- }
-
- $str_contact_allow = '';
- $contact_allow = $_POST['contact_allow'];
- if(is_array($contact_allow)) {
- array_walk($contact_allow,'sanitise_acl');
- $str_contact_allow = implode('',$contact_allow);
- }
-
- $str_group_deny = '';
- $group_deny = $_POST['group_deny'];
- if(is_array($group_deny)) {
- array_walk($group_deny,'sanitise_acl');
- $str_group_deny = implode('',$group_deny);
- }
+ $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
+ dbesc($album),
+ intval(get_uid())
+ );
+ if((! count($r)) || ($album == t('Profile Photos')))
+ $visible = 1;
+ else
+ $visibile = 0;
- $str_contact_deny = '';
- $contact_deny = $_POST['contact_deny'];
- if(is_array($contact_deny)) {
- array_walk($contact_deny,'sanitise_acl');
- $str_contact_deny = implode('',$contact_deny);
- }
+ $str_group_allow = perms2str($_POST['group_allow']);
+ $str_contact_allow = perms2str($_POST['contact_allow']);
+ $str_group_deny = perms2str($_POST['group_deny']);
+ $str_contact_deny = perms2str($_POST['contact_deny']);
- $src = $_FILES['userfile']['tmp_name'];
- $filename = basename($_FILES['userfile']['name']);
- $filesize = intval($_FILES['userfile']['size']);
+ $src = $_FILES['userfile']['tmp_name'];
+ $filename = basename($_FILES['userfile']['name']);
+ $filesize = intval($_FILES['userfile']['size']);
$imagedata = @file_get_contents($src);
$ph = new Photo($imagedata);
$smallest = 0;
- $photo_hash = hash('md5',uniqid(mt_rand(),true));
-
- $r = $ph->store($_SESSION['uid'], 0, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+ $photo_hash = photo_new_resource();
+
+ $r = $ph->store(get_uid(), 0, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
if(! $r) {
notice( t('Image upload failed.') . EOL );
if($width > 640 || $height > 640) {
$ph->scaleImage(640);
- $ph->store($_SESSION['uid'], 0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+ $ph->store(get_uid(), 0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
$smallest = 1;
}
if($width > 320 || $height > 320) {
$ph->scaleImage(320);
- $ph->store($_SESSION['uid'], 0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+ $ph->store(get_uid(), 0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
$smallest = 2;
}
$basename = basename($filename);
+ $uri = item_new_uri($a->get_hostname(), get_uid());
// Create item container
- $body = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']'
- . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
- . '[/url]';
-
- do {
- $dups = false;
- $item_hash = random_string();
-
- $uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $profile_uid . ':' . $item_hash;
-
- $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
- dbesc($uri));
- if(count($r))
- $dups = true;
- } while($dups == true);
-
-
- $r = q("INSERT INTO `item` (`uid`, `type`, `resource-id`, `contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,
- `edited`, `uri`, `parent-uri`, `title`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
- VALUES( %d, '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
- intval($_SESSION['uid']),
- dbesc('photo'),
- dbesc($photo_hash),
- intval($contact_record['id']),
- dbesc($contact_record['name']),
- dbesc($contact_record['url']),
- dbesc($contact_record['thumb']),
- datetime_convert(),
- datetime_convert(),
- dbesc($uri),
- dbesc($uri),
- dbesc($title),
- dbesc($body),
- dbesc($str_contact_allow),
- dbesc($str_group_allow),
- dbesc($str_contact_deny),
- dbesc($str_group_deny)
-
- );
- if($r) {
-
- $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
- dbesc($uri)
- );
- if(count($r))
- q("UPDATE `item` SET `parent` = %d, `last-child` = 1 WHERE `id` = %d LIMIT 1",
- intval($r[0]['id']),
- intval($r[0]['id'])
- );
-
- }
-
- // if album has no featured photo, promote one.
+ $arr = array();
+
+ $arr['uid'] = get_uid();
+ $arr['uri'] = $uri;
+ $arr['parent-uri'] = $uri;
+ $arr['type'] = 'photo';
+ $arr['wall'] = 1;
+ $arr['resource-id'] = $photo_hash;
+ $arr['contact-id'] = $contact_record['id'];
+ $arr['owner-name'] = $contact_record['name'];
+ $arr['owner-link'] = $contact_record['url'];
+ $arr['owner-avatar'] = $contact_record['thumb'];
+ $arr['title'] = $title;
+ $arr['allow_cid'] = $str_contact_allow;
+ $arr['allow_gid'] = $str_group_allow;
+ $arr['deny_cid'] = $str_contact_deny;
+ $arr['deny_gid'] = $str_group_deny;
+ $arr['last-child'] = 1;
+ $arr['visible'] = $visible;
+ $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']'
+ . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
+ . '[/url]';
+
+ $item_id = item_store($arr);
if(! $java_upload) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
// photos/name/upload
// photos/name/album/xxxxx
// photos/name/album/xxxxx/edit
- // photos/name/album/xxxxx/drop
// photos/name/image/xxxxx
// photos/name/image/xxxxx/edit
- // photos/name/image/xxxxx/drop
+
if(! x($a->data,'user')) {
notice( t('No photos selected') . EOL );
// Profile owner - everything is visible
- if(local_user() && ($_SESSION['uid'] == $owner_uid)) {
+ if(local_user() && (get_uid() == $owner_uid)) {
$sql_extra = '';
}
elseif(remote_user()) {
if($datatype == 'upload') {
- if( ! (local_user() && ($_SESSION['uid'] == $a->data['user']['uid']))) {
+ if( ! (local_user() && (get_uid() == $a->data['user']['uid']))) {
notice( t('Permission denied.'));
return;
}
);
$o .= '<h3>' . $album . '</h3>';
-
+
+ if($cmd == 'edit') {
+ if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
+ if(local_user() && (get_uid() == $a->data['user']['uid'])) {
+ $edit_tpl = file_get_contents('view/album_edit.tpl');
+ $o .= replace_macros($edit_tpl,array(
+ '$nametext' => t('New album name: '),
+ '$album' => $album,
+ '$hexalbum' => bin2hex($album),
+ '$submit' => t('Submit'),
+ '$dropsubmit' => t('Delete Album')
+ ));
+ }
+ }
+ }
+ else {
+ if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
+ if(local_user() && (get_uid() == $a->data['user']['uid'])) {
+ $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
+ . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
+ . t('Edit Album') . '</a></div>';
+ }
+ }
+ }
$tpl = file_get_contents('view/photo_album.tpl');
if(count($r))
foreach($r as $rr) {
$o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
- if(local_user() && ($ph[0]['uid'] == $_SESSION['uid'])) {
+ if(local_user() && ($ph[0]['uid'] == get_uid())) {
$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>';
}
dbesc($datum)
);
if(count($i1)) {
-//dbg(2);
+
$r = q("SELECT COUNT(*) AS `total`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
intval($a->pager['itemspage'])
);
+ }
+ $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
- $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
-
- if(strlen($i1[0]['tag'])) {
- // parse tags and add links
- $o .= '<div id="in-this-photo-text">' . t('In this photo: ') . '</div>';
- $o .= '<div id="in-this-photo">' . $i1[0]['tag'] . '</div>';
- }
+ if(count($i1) && strlen($i1[0]['tag'])) {
+ // parse tags and add links
+ $o .= '<div id="in-this-photo-text">' . t('In this photo: ') . '</div>';
+ $o .= '<div id="in-this-photo">' . $i1[0]['tag'] . '</div>';
+ }
- if($cmd == 'edit') {
- $edit_tpl = file_get_contents('view/photo_edit.tpl');
- $o .= replace_macros($edit_tpl, array(
- '$id' => $ph[0]['id'],
- '$capt_label' => t('Caption'),
- '$caption' => $ph[0]['desc'],
- '$tag_label' => t('Tags'),
- '$tags' => $i1[0]['tag'],
- '$item_id' => $i1[0]['id'],
- '$submit' => t('Submit')
+ if($cmd == 'edit') {
+ $edit_tpl = file_get_contents('view/photo_edit.tpl');
+ $o .= replace_macros($edit_tpl, array(
+ '$id' => $ph[0]['id'],
+ '$resource_id' => $ph[0]['resource-id'],
+ '$capt_label' => t('Caption'),
+ '$caption' => $ph[0]['desc'],
+ '$tag_label' => t('Tags'),
+ '$tags' => $i1[0]['tag'],
+ '$item_id' => ((count($i1)) ? $i1[0]['id'] : 0),
+ '$submit' => t('Submit'),
+ '$delete' => t('Delete Photo')
- ));
- }
+ ));
+ }
+ if(count($i1)) {
// pull out how many people like the photo
$cmnt_tpl = file_get_contents('view/comment_item.tpl');
$profile_url = $item['url'];
-
- if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) && (strlen($item['dfrn-id'])) && (! $item['self'] ))
+ if(local_user() && ($item['contact-uid'] == get_uid())
+ && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH) && (! $item['self'] ))
$profile_url = $redirect_url;
-
$profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
$profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
$drop = '';
- if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == $_SESSION['uid']))
+ if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == get_uid()))
$drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
$o .= '<h3>' . t('Recent Photos') . '</h3>';
- if( local_user() && ($_SESSION['uid'] == $a->data['user']['uid'])) {
+ if( local_user() && (get_uid() == $a->data['user']['uid'])) {
$o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
. $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
}