photo album finish, general cleanup begins

This commit is contained in:
Mike Macgirvin 2010-08-08 17:08:39 -07:00
parent c9d8211ae7
commit 0bcd552231
10 changed files with 339 additions and 96 deletions

View file

@ -142,6 +142,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`body` text NOT NULL,
`resource-id` char(255) NOT NULL,
`like` mediumtext NOT NULL,
`dislike` mediumtext NOT NULL,
`tag` mediumtext NOT NULL,
`allow_cid` mediumtext NOT NULL,
`allow_gid` mediumtext NOT NULL,
@ -164,7 +165,6 @@ CREATE TABLE IF NOT EXISTS `item` (
KEY `deleted` (`deleted`),
KEY `last-child` (`last-child`),
KEY `unseen` (`unseen`),
KEY `unseen_2` (`unseen`),
FULLTEXT KEY `title` (`title`),
FULLTEXT KEY `body` (`body`),
FULLTEXT KEY `allow_cid` (`allow_cid`),

BIN
images/dislike.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

BIN
images/like.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -51,17 +51,208 @@ function photos_post(&$a) {
killme();
}
$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(($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($_SESSION['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($_SESSION['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($_SESSION['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($_SESSION['uid'])
);
$r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
intval($_SESSION['uid'])
);
if(count($r)) {
foreach($r as $rr) {
q("UPDATE `item` SET `deleted` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
dbesc($rr['parent-uri']),
intval($_SESSION['uid'])
);
$url = $a->get_baseurl();
$drop_id = intval($rr['id']);
// send the notification upstream/downstream as the case may be
if($rr['visible'])
proc_close(proc_open("php include/notifier.php \"$url\" \"drop\" \"$drop_id\" ",
array(),$foo));
}
}
}
goaway($a->get_baseurl() . '/photos/' . $a->data['user']['uid']);
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($_SESSION['uid']),
dbesc($a->argv[1])
);
if(count($r)) {
q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
intval($_SESSION['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($_SESSION['uid'])
);
if(count($i)) {
q("UPDATE `item` SET `deleted` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
dbesc($i[0]['uri']),
intval($_SESSION['uid'])
);
$url = $a->get_baseurl();
$drop_id = intval($i[0]['id']);
// send the notification upstream/downstream as the case may be
if($i[0]['visible'])
proc_close(proc_open("php include/notifier.php \"$url\" \"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),
$p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
dbesc($resource_id),
intval($_SESSION['uid'])
);
if(count($r)) {
$r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
dbesc($desc),
dbesc($resource_id),
intval($_SESSION['uid'])
);
}
if(! $item_id) {
$title = '';
$basename = basename($filename);
// Create item container
$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]';
do {
$dups = false;
$item_hash = random_string();
$uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $_SESSION['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($p[0]['resource-id']),
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($p[0]['allow_cid']),
dbesc($p[0]['allow_gid']),
dbesc($p[0]['deny_cid']),
dbesc($p[0]['deny_gid'])
);
if($r) {
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($uri)
);
if(count($r))
$item_id = $r[0]['id'];
q("UPDATE `item` SET `parent` = %d, `last-child` = 1 WHERE `id` = %d LIMIT 1",
intval($r[0]['id']),
intval($r[0]['id'])
);
}
}
$r = q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
dbesc($tags),
intval($item_id),
@ -74,11 +265,6 @@ function photos_post(&$a) {
$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();
@ -98,6 +284,15 @@ function photos_post(&$a) {
$album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
}
$r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
dbesc($album),
intval($_SESSION['uid'])
);
if((! count($r)) || ($album == t('Profile Photos')))
$visible = 1;
else
$visibile = 0;
$str_group_allow = '';
$group_allow = $_POST['group_allow'];
if(is_array($group_allow)) {
@ -176,56 +371,53 @@ function photos_post(&$a) {
. '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
. '[/url]';
do {
$dups = false;
$item_hash = random_string();
do {
$dups = false;
$item_hash = random_string();
$uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $profile_uid . ':' . $item_hash;
$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("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)
$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`, `visible`)
VALUES( %d, '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )",
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),
intval($visible)
);
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($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.
}
if(! $java_upload) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
@ -246,10 +438,9 @@ function photos_content(&$a) {
// 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 );
@ -379,7 +570,30 @@ function photos_content(&$a) {
);
$o .= '<h3>' . $album . '</h3>';
if($cmd == 'edit') {
if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
if(local_user() && ($_SESSION['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() && ($_SESSION['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) {
@ -481,30 +695,33 @@ function photos_content(&$a) {
intval($a->pager['itemspage'])
);
}
$o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
$o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</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(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'],
'$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($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(count($i1)) {
// pull out how many people like the photo
$cmnt_tpl = file_get_contents('view/comment_item.tpl');

View file

@ -284,6 +284,7 @@ function profile_content(&$a, $update = false) {
'$drop' => $drop,
'$comment' => $comment
));
}
}

View file

@ -25,31 +25,32 @@ function regmod_content(&$a) {
if(! count($register))
killme();
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($register[0]['uid'])
);
if($cmd == 'deny') {
$r = q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
intval($register[0]['uid'])
);
$r = q("DELETE FROM `contact` WHERE `uid` = %d",
$r = q("DELETE FROM `contact` WHERE `uid` = %d LIMIT 1",
intval($register[0]['uid'])
);
$r = q("DELETE FROM `profile` WHERE `uid` = %d",
$r = q("DELETE FROM `profile` WHERE `uid` = %d LIMIT 1",
intval($register[0]['uid'])
);
$r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
dbesc($register[0]['hash'])
);
notice( t('Registration revoked.') . EOL);
notice( t('Registration revoked for ') . $user[0]['username'] . EOL);
return;
}
if($cmd == 'allow') {
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($register[0]['uid'])
);
if(! count($user))
killme();
@ -75,11 +76,9 @@ function regmod_content(&$a) {
$res = mail($user[0]['email'], t('Registration details for '). $a->config['sitename'],
$email_tpl,'From: ' . t('Administrator@') . $_SERVER[SERVER_NAME] );
if($res) {
notice( t('Account approved.') . EOL );
return;
}
}
}

15
view/album_edit.tpl Normal file
View file

@ -0,0 +1,15 @@
<div id="photo-album-edit-wrapper">
<form name="photo-album-edit-form" id="photo-album-edit-form" action="photos/album/$hexalbum" method="post" >
<label id="photo-album-edit-name-label" for="photo-album-edit-name" >$nametext</label>
<input type="text" size="64" name="albumname" value="$album" >
<div id="photo-album-edit-name-end"></div>
<input id="photo-album-edit-submit" type="submit" name="submit" value="$submit" />
<input id="photo-album-edit-drop" type="submit" name="dropalbum" value="$dropsubmit" onclick="return confirmDelete();" />
</form>
</div>
<div id="photo-album-edit-end" ></div>

View file

@ -1,17 +1,19 @@
<form action="photos/$id" method="post" id="photo_edit_form" >
<form action="photos/$resource_id" method="post" id="photo_edit_form" >
<input type="hidden" name="item_id" value="$item_id" />
<label id="photo-edit-caption-label" for="photo-edit-caption">$capt_label</label>
<input id="photo-edit-caption" type="text" size="64" name="desc" value="$caption" />
<input id="photo-edit-caption" type="text" size="84" name="desc" value="$caption" />
<div id="photo-edit-caption-end"></div>
<label id="photo-edit-tags-label" for="photo-edit-tags-textarea" >$tag_label</label>
<textarea name="tags" id="photo-edit-tags-textarea">$tags</textarea>
<textarea name="tags" id="photo-edit-tags-textarea" rows="3" cols="64" >$tags</textarea>
<div id="photo-edit-tags-end"></div>
<input type="submit" name="submit" value="$submit" />
<input id="photo-edit-submit-button" type="submit" name="submit" value="$submit" />
<input id="photo-edit-delete-button" type="submit" name="delete" value="$delete" onclick="return confirmDelete()"; />
<div id="photo-edit-end"></div>
</form>

View file

@ -2,7 +2,7 @@
function gender_selector($current="",$suffix="") {
$select = array('','Male', 'Female', 'Transsexual', 'Hermaphrodite', 'Neuter', 'Other', 'Undecided');
$select = array('', t('Male'), t('Female'), t('Transsexual'), t('Hermaphrodite'), t('Neuter'), t('Other'), t('Undecided'));
$o .= "<select name=\"gender$suffix\" id=\"gender-select$suffix\" size=\"1\" >";
foreach($select as $selection) {
@ -14,7 +14,7 @@ function gender_selector($current="",$suffix="") {
}
function sexpref_selector($current="",$suffix="") {
$select = array('','Males', 'Females', 'Bisexual', 'Autosexual', 'Abstinent', 'Virgin', 'Nonsexual');
$select = array('', t('Males'), t('Females'), t('Bisexual'), t('Autosexual'), t('Abstinent'), t('Virgin'), t('Nonsexual'));
$o .= "<select name=\"sexual$suffix\" id=\"sexual-select$suffix\" size=\"1\" >";
foreach($select as $selection) {
@ -27,7 +27,7 @@ function sexpref_selector($current="",$suffix="") {
function marital_selector($current="",$suffix="") {
$select = array('','Single', 'Lonely', 'Available', 'Unavailable', 'Dating', 'Unfaithful', 'Sex Addict', 'Friends', 'Friends/Benefits', 'Casual', 'Engaged', 'Married', 'Partners', 'Cohabiting', 'Happy', 'Not Looking', 'Swinger', 'Betrayed', 'Separated', 'Unstable', 'Divorced', 'Widowed', 'Uncertain', 'Complicated', 'Don\'t care', 'Ask me' );
$select = array('', t('Single'), t('Lonely'), t('Available'), t('Unavailable'), t('Dating'), t('Unfaithful'), t('Sex Addict'), t('Friends'), t('Friends/Benefits'), t('Casual'), t('Engaged'), t('Married'), t('Partners'), t('Cohabiting'), t('Happy'), t('Not Looking'), t('Swinger'), t('Betrayed'), t('Separated'), t('Unstable'), t('Divorced'), t('Widowed'), t('Uncertain'), t('Complicated'), t('Don\'t care'), t('Ask me') );
$o .= "<select name=\"marital[]\" id=\"marital-select\" multiple=\"multiple\" size=\"2\" >";
foreach($select as $selection) {
@ -37,8 +37,3 @@ function marital_selector($current="",$suffix="") {
$o .= '</select>';
return $o;
}
//function birthday_selector($current = '') {
// if($current && (strlen($current)
//}

View file

@ -1346,12 +1346,16 @@ input#dfrn-url {
}
#photo-edit-caption, #photo-edit-tags-textarea {
float: left;
margin-bottom: 15px;
}
#photo-edit-caption-end, #photo-edit-tags-end {
clear: both;
}
#photo-edit-delete-button {
margin-left: 200px;
}
#photo-caption {
font-size: 110%;
font-weight: bold;
@ -1368,4 +1372,14 @@ input#dfrn-url {
margin-left: 60px;
margin-top: 10px;
margin-bottom: 20px;
}
}
#photo-album-edit-submit, #photo-album-edit-drop {
margin-top: 15px;
margin-bottom: 15px;
}
#photo-album-edit-drop {
margin-left: 200px;
}