Permalink
Browse files

added dorp removal. you have to delete your dorps db first,

since removal isn't supported on capped collections
  • Loading branch information...
1 parent 1b5cc1a commit 276a47df4dd68db9896c990cf67e68108f89a7e0 Nik Nyby committed Jun 13, 2011
Showing with 50 additions and 9 deletions.
  1. +50 −1 Chan.php
  2. +0 −8 index.php
View
@@ -43,6 +43,31 @@ public function __construct(
$route = preg_replace('/^\//', '', $route);
$this->route = preg_split('/\//', $route);
+ if (!empty($this->post)
+ && array_key_exists('ajax', $this->post)
+ && $this->post['ajax'] == 1
+ ) {
+ $message = array();
+ if (array_key_exists('method', $this->post)) {
+ switch ($this->post['method']) {
+ case 'delete_dorp':
+ $this->db->dorps->remove(array('picture' => $this->post['pic_file']));
+ $message = array(
+ 'result' => 'success',
+ 'pic_file' => $this->post['pic_file']
+ );
+ break;
+ default:
+ break;
+ }
+ }
+ header('Cache-Control: no-cache, must-revalidate');
+ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
+ header('Content-type: application/json');
+ $message = json_encode($message);
+ echo $message;
+ exit;
+ }
if (!empty($this->post) && array_key_exists('redir', $this->post)) {
$this->route[0] = $this->post['redir'];
}
@@ -108,7 +133,31 @@ private function style() {
}
})
.delegate('.delete-button', 'click', function(event) {
- $(this).closest('.pic-container').remove();
+ var $this = $(this);
+ var container = $this.closest('.pic-container');
+
+ var pic_file = container.find('img.pic:first').attr('src');
+ pic_file = pic_file.replace('<?php echo $this->site_path; ?>/d/', '');
+ var data = {
+ 'ajax': 1,
+ 'method': 'delete_dorp',
+ 'pic_file': pic_file
+ };
+ $.post('<?php echo $this->site_path; ?>/index.php',
+ data,
+ function(response) {
+ },
+ 'json'
+ );
+
+ container.find('.delete-button').remove();
+ container.find('img.pic').animate({
+ opacity: 0.25,
+ left: '+=50',
+ height: 'toggle'
+ }, 600, function() {
+ container.remove();
+ });
});
});
</script>
View
@@ -5,14 +5,6 @@
$mongo = new Mongo('mongodb://'.DB_USER.':'.DB_PASS.'@localhost/'.DB_NAME);
$db = $mongo->selectDB(DB_NAME);
-if ($db->dorps->find()->count() < 1) {
- $db->createCollection('dorps', true, 10*1024);
-}
-
-if ($db->forums->find()->count() < 1) {
- $db->createCollection('forums', true, 10*1024);
-}
-
$chan = new Chan($db, SITE_PATH, SITE_FS_PATH, $_GET, $_POST, $_FILES);
$chan->out();

0 comments on commit 276a47d

Please sign in to comment.