From 0bcd5522315649c8d4652b8bfaa9bec328b9d548 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Sun, 8 Aug 2010 17:08:39 -0700 Subject: [PATCH] photo album finish, general cleanup begins --- database.sql | 2 +- images/dislike.gif | Bin 0 -> 133 bytes images/like.gif | Bin 0 -> 1184 bytes mod/photos.php | 365 +++++++++++++++++++++++++++++-------- mod/profile.php | 1 + mod/regmod.php | 15 +- view/album_edit.tpl | 15 ++ view/photo_edit.tpl | 10 +- view/profile_selectors.php | 11 +- view/style.css | 16 +- 10 files changed, 339 insertions(+), 96 deletions(-) create mode 100644 images/dislike.gif create mode 100644 images/like.gif create mode 100644 view/album_edit.tpl diff --git a/database.sql b/database.sql index 8493e9d145..1411ec6da9 100644 --- a/database.sql +++ b/database.sql @@ -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`), diff --git a/images/dislike.gif b/images/dislike.gif new file mode 100644 index 0000000000000000000000000000000000000000..2b6d01e3ae3c3469dace7415fd1b8c53baf63ba2 GIT binary patch literal 133 zcmZ?wbhEHb6krfwIK;s4|NsA)GtZ;}QQA!7w3$FI1StMwVPs%nXV75)0+3n;X0M7} zcX*mT1Q{lztVzrjn88ryk{+k@v3I%alBV0cHrT8_m_2)j$q}HmxDA8nK`-|No2g!E d&n_N%=rVhmhqu*jxv)hWB18&iNOCe*0|1&wHva$s literal 0 HcmV?d00001 diff --git a/images/like.gif b/images/like.gif new file mode 100644 index 0000000000000000000000000000000000000000..39b1c86d241fbc2fdefab9ad0efba8f20416b33c GIT binary patch literal 1184 zcmZ?wbhEHb6krfwSj5Wk|NsA)GtZ;}QQA!7w3$FI0~jd&=Z^3VP;f~sNd(e1_7w$* z$=RtT3Q4KynR&KK?|1K4QpilPRSGxtHSjHPPR+>ls47YguJQ{>uF6ifOi{A8Q?RM9 zs>m(KO)W`OsL0L9E4HezRZ2|BPfE1{vO&W7N(x{lCE2!0jvxsIke$x?MX3s=dIq}5 z24)5dW`=r(#wOnqF1_laHpait7C?(A*$i)q67m#PG zlu=SrV5P5LUS6(OZmgGIl&)`RX=w>E!^lV%s6w~6GOr}DLN~8i8D@e@YH@N=W?$S+WE z4mMTrO-#QEUIa|mjQ{`r z{qy_R&mZ5vef{$J)5j0*-@SeF`qj%9&!0Vg^7zri2lwyYy>t84%^TORUA=Po(!~qs z&z(JU`qar2$B!L7a`@1}1N-;w-Lrew&K=vgZQZhY)5ZeMTG_V zdAT{+S(zE>X{jm6Nr?&Zaj`McQIQehVWAmo_rKzE=rmCW>q^KY-Co3Z@B`F~;CMqH&FX#K^#)_>%=lvNGs^N(xXp!ochqvFnbM(kV@6L50_Ak3MBEERfsQ`#7w~#iLH@ z$*O{DZ7hjg&hMJd85IR~Fd84~nAm!S({Yargc > 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 .= '

' . $album . '

'; - + + 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 .= ''; + } + } + } $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 .= '
' . $ph[0]['desc'] . '
'; - $o .= '
' . $ph[0]['desc'] . '
'; + if(count($i1) && strlen($i1[0]['tag'])) { + // parse tags and add links + $o .= '
' . t('In this photo: ') . '
'; + $o .= '
' . $i1[0]['tag'] . '
'; + } - if(strlen($i1[0]['tag'])) { - // parse tags and add links - $o .= '
' . t('In this photo: ') . '
'; - $o .= '
' . $i1[0]['tag'] . '
'; - } + 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'); diff --git a/mod/profile.php b/mod/profile.php index 9d9eb05b6b..6e04724beb 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -284,6 +284,7 @@ function profile_content(&$a, $update = false) { '$drop' => $drop, '$comment' => $comment )); + } } diff --git a/mod/regmod.php b/mod/regmod.php index f03c2a3fe5..abf673a929 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -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; } - } } \ No newline at end of file diff --git a/view/album_edit.tpl b/view/album_edit.tpl new file mode 100644 index 0000000000..44b541607c --- /dev/null +++ b/view/album_edit.tpl @@ -0,0 +1,15 @@ +
+
+ + + + + +
+ + + + +
+
+
diff --git a/view/photo_edit.tpl b/view/photo_edit.tpl index e506375781..176ad3244a 100644 --- a/view/photo_edit.tpl +++ b/view/photo_edit.tpl @@ -1,17 +1,19 @@ -
+ - +
- +
- + + +
diff --git a/view/profile_selectors.php b/view/profile_selectors.php index 902f6a1a54..03dd2aacd2 100644 --- a/view/profile_selectors.php +++ b/view/profile_selectors.php @@ -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 .= ""; 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 .= "'; return $o; } - - -//function birthday_selector($current = '') { -// if($current && (strlen($current) -//} \ No newline at end of file diff --git a/view/style.css b/view/style.css index c590b53174..777f938b82 100644 --- a/view/style.css +++ b/view/style.css @@ -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; -} \ No newline at end of file +} + +#photo-album-edit-submit, #photo-album-edit-drop { + margin-top: 15px; + margin-bottom: 15px; +} + +#photo-album-edit-drop { + margin-left: 200px; +} +