Permalink
Browse files

fragment deletion. ping table. minor edits

  • Loading branch information...
1 parent dd9007a commit 40048b8f8853ca490eaad4bc97c159ddfcc90a7d @Roj committed Dec 29, 2011
View
14 README
@@ -1,4 +1,4 @@
-Mootales version 0.5 (alpha release) (development status) 12/december/11 4:27 am
+Mootales version 0.5 (alpha release) (development status) 29/12/11 3:40 pm
uses kohana.
install:
@@ -22,6 +22,7 @@ SQL
[+] forum_categories table
[+] forum_threads table
[+] forum_comments table
+[+] pings table
[ ] messages table
[ ] friends table
etc
@@ -37,12 +38,12 @@ OTHER
[+] bbcode
[+] add thread
[+] add thread_comment
-[-] frontpage (add threads, etc)
+[+] frontpage
+[+] delete fragments
[-] dashboard (need to add notifications, etc)
[-] user profiles (- need to do the stats thing, threads, user info, ping, etc)
[-] update user stats all the time
-[ ] manage blogs (mark as draft, rename, edit, delete)
-[ ] delete fragments
+[-] manage blogs (mark as draft, rename, edit, delete)
[ ] textarea buttons (bbcode, emoticons, etc)
[ ] picture blogs
[ ] mail
@@ -60,13 +61,12 @@ Specific things to do
[+] make blog/thread does not exist error
[+] do not display comment form if user ain't logged in
[+] proper unicode support
+[+] pagination
[-] prevent code repetition
-[ ] pagination
[ ] do not submit comments full of spaces
[ ] add info of user in views/blog.php and views/thread.php
[ ] css tidy-up
[ ] general code tidy-up
[ ] use table instead of... whatever that is on views/forum_category
[ ] beautify views (especially forum_category and forum_categories)
-[ ] take advantage of cascading filesystem
-[ ] API
+[ ] take advantage of cascading filesystem
@@ -263,14 +263,14 @@ public function action_delete_blog()
public function action_delete_thread()
{
// This function actually handles two pages.
- // The first one asks the user if (s)he does want to delete the blog,
+ // The first one asks the user if (s)he does want to delete the thread,
// and also prevents some hacking by implementing POST to confirm
// if the request is valid.
- // The second one actually deletes the blog.
+ // The second one actually deletes the thread.
$id = $this->request->param("id");
$forum_model = Model::factory("forum");
$thread = $forum_model->get_thread($id);
- if (intval($thread->get("id")) == 0)
+ if ( ! intval($thread->get("id")))
{
$this->errors=" That blog does not exist.";
$this->action_index();
@@ -24,4 +24,44 @@ public function action_view()
->set("user",$user);
$this->response->body($view);
}
+ public function action_delete()
+ {
+ // This function actually handles two pages.
+ // The first one asks the user if (s)he does want to delete the frag,
+ // and also prevents some hacking by implementing POST to confirm
+ // if the request is valid.
+ // The second one actually deletes the frag.
+ if( ! $this->logged_in)
+ {
+ $this->request->redirect("login");
+ return 0;
+ }
+ $id = intval($this->request->param("id"));
+ $frag_model = Model::factory("fragment");
+ $frag = $frag_model->get_fragment($id);
+ if ( ! intval($frag->get("id")))
+ {
+ $view = View::factory("fragment_notexist");
+ $this->response->body($view);
+ return 0;
+ }
+ if ( $frag->get("author_id") != $this->session->get("user_id") AND
+ $this->session->get("rank") < 2)
+ {
+ //i.e. the user is not the author nor a moderator
+ $this->request->redirect("fragment/{$id}");
+ return 0;
+ }
+ if ($_POST == array() OR
+ intval($_POST['confirm']) != 1)
+ {
+ $view = View::factory("confirm_frag_delete")
+ ->set("frag",$frag);
+ $this->response->body($view);
+ return 0;
+ }
+ $frag_model->delete($id, $frag->get("author_id"));
+ $this->request->redirect("home");
+ return 1;
+ }
}
@@ -10,6 +10,12 @@ public function create($user_id,$content) {
DB::update("users")->set(array("count_fragments"=>intval($amount_frags)+1))->where("id","=",$info["author_id"])->execute();
return DB::insert("fragments",array_keys($info))->values($info)->execute();
}
+ public function delete($id,$user_id)
+ {
+ $amount_frags = DB::select("count_fragments")->from("users")->where("id","=",$user_id)->execute()->get("count_fragments");
+ DB::update("users")->set(array("count_fragments"=>intval($amount_frags)-1))->where("id","=",$user_id)->execute();
+ return DB::delete("fragments")->where("author_id","=",$user_id)->and_where("id","=",$id)->execute();
+ }
public function get_fragment($id)
{
return DB::select()->from("fragments")->where("id","=",intval($id))->execute();
@@ -0,0 +1,49 @@
+<?php defined('SYSPATH') or die('No direct script access.'); ?>
+
+2011-12-29 12:13:18 --- ERROR: HTTP_Exception_404 [ 404 ]: The requested URL fragment/delete/31 was not found on this server. ~ SYSPATH\classes\kohana\request\client\internal.php [ 113 ]
+2011-12-29 12:13:18 --- STRACE: HTTP_Exception_404 [ 404 ]: The requested URL fragment/delete/31 was not found on this server. ~ SYSPATH\classes\kohana\request\client\internal.php [ 113 ]
+--
+#0 C:\xampp\htdocs\mootales\system\classes\kohana\request\client.php(64): Kohana_Request_Client_Internal->execute_request(Object(Request))
+#1 C:\xampp\htdocs\mootales\system\classes\kohana\request.php(1138): Kohana_Request_Client->execute(Object(Request))
+#2 C:\xampp\htdocs\mootales\index.php(109): Kohana_Request->execute()
+#3 {main}
+2011-12-29 12:26:24 --- ERROR: ErrorException [ 2 ]: Missing argument 2 for Model_Fragment::delete(), called in C:\xampp\htdocs\mootales\application\classes\controller\fragment.php on line 55 and defined ~ APPPATH\classes\model\fragment.php [ 13 ]
+2011-12-29 12:26:24 --- STRACE: ErrorException [ 2 ]: Missing argument 2 for Model_Fragment::delete(), called in C:\xampp\htdocs\mootales\application\classes\controller\fragment.php on line 55 and defined ~ APPPATH\classes\model\fragment.php [ 13 ]
+--
+#0 C:\xampp\htdocs\mootales\application\classes\model\fragment.php(13): Kohana_Core::error_handler(2, 'Missing argumen...', 'C:\xampp\htdocs...', 13, Array)
+#1 C:\xampp\htdocs\mootales\application\classes\controller\fragment.php(55): Model_Fragment->delete(31)
+#2 [internal function]: Controller_Fragment->action_delete()
+#3 C:\xampp\htdocs\mootales\system\classes\kohana\request\client\internal.php(118): ReflectionMethod->invoke(Object(Controller_Fragment))
+#4 C:\xampp\htdocs\mootales\system\classes\kohana\request\client.php(64): Kohana_Request_Client_Internal->execute_request(Object(Request))
+#5 C:\xampp\htdocs\mootales\system\classes\kohana\request.php(1138): Kohana_Request_Client->execute(Object(Request))
+#6 C:\xampp\htdocs\mootales\index.php(109): Kohana_Request->execute()
+#7 {main}
+2011-12-29 12:26:25 --- ERROR: ErrorException [ 2 ]: Missing argument 2 for Model_Fragment::delete(), called in C:\xampp\htdocs\mootales\application\classes\controller\fragment.php on line 55 and defined ~ APPPATH\classes\model\fragment.php [ 13 ]
+2011-12-29 12:26:25 --- STRACE: ErrorException [ 2 ]: Missing argument 2 for Model_Fragment::delete(), called in C:\xampp\htdocs\mootales\application\classes\controller\fragment.php on line 55 and defined ~ APPPATH\classes\model\fragment.php [ 13 ]
+--
+#0 C:\xampp\htdocs\mootales\application\classes\model\fragment.php(13): Kohana_Core::error_handler(2, 'Missing argumen...', 'C:\xampp\htdocs...', 13, Array)
+#1 C:\xampp\htdocs\mootales\application\classes\controller\fragment.php(55): Model_Fragment->delete(31)
+#2 [internal function]: Controller_Fragment->action_delete()
+#3 C:\xampp\htdocs\mootales\system\classes\kohana\request\client\internal.php(118): ReflectionMethod->invoke(Object(Controller_Fragment))
+#4 C:\xampp\htdocs\mootales\system\classes\kohana\request\client.php(64): Kohana_Request_Client_Internal->execute_request(Object(Request))
+#5 C:\xampp\htdocs\mootales\system\classes\kohana\request.php(1138): Kohana_Request_Client->execute(Object(Request))
+#6 C:\xampp\htdocs\mootales\index.php(109): Kohana_Request->execute()
+#7 {main}
+2011-12-29 12:26:26 --- ERROR: ErrorException [ 2 ]: Missing argument 2 for Model_Fragment::delete(), called in C:\xampp\htdocs\mootales\application\classes\controller\fragment.php on line 55 and defined ~ APPPATH\classes\model\fragment.php [ 13 ]
+2011-12-29 12:26:26 --- STRACE: ErrorException [ 2 ]: Missing argument 2 for Model_Fragment::delete(), called in C:\xampp\htdocs\mootales\application\classes\controller\fragment.php on line 55 and defined ~ APPPATH\classes\model\fragment.php [ 13 ]
+--
+#0 C:\xampp\htdocs\mootales\application\classes\model\fragment.php(13): Kohana_Core::error_handler(2, 'Missing argumen...', 'C:\xampp\htdocs...', 13, Array)
+#1 C:\xampp\htdocs\mootales\application\classes\controller\fragment.php(55): Model_Fragment->delete(31)
+#2 [internal function]: Controller_Fragment->action_delete()
+#3 C:\xampp\htdocs\mootales\system\classes\kohana\request\client\internal.php(118): ReflectionMethod->invoke(Object(Controller_Fragment))
+#4 C:\xampp\htdocs\mootales\system\classes\kohana\request\client.php(64): Kohana_Request_Client_Internal->execute_request(Object(Request))
+#5 C:\xampp\htdocs\mootales\system\classes\kohana\request.php(1138): Kohana_Request_Client->execute(Object(Request))
+#6 C:\xampp\htdocs\mootales\index.php(109): Kohana_Request->execute()
+#7 {main}
+2011-12-29 12:34:39 --- ERROR: HTTP_Exception_404 [ 404 ]: The requested URL fragment/delete21 was not found on this server. ~ SYSPATH\classes\kohana\request\client\internal.php [ 113 ]
+2011-12-29 12:34:39 --- STRACE: HTTP_Exception_404 [ 404 ]: The requested URL fragment/delete21 was not found on this server. ~ SYSPATH\classes\kohana\request\client\internal.php [ 113 ]
+--
+#0 C:\xampp\htdocs\mootales\system\classes\kohana\request\client.php(64): Kohana_Request_Client_Internal->execute_request(Object(Request))
+#1 C:\xampp\htdocs\mootales\system\classes\kohana\request.php(1138): Kohana_Request_Client->execute(Object(Request))
+#2 C:\xampp\htdocs\mootales\index.php(109): Kohana_Request->execute()
+#3 {main}
@@ -9,6 +9,4 @@
<form action="<?php echo URL::base().'dashboard/manage'; ?>" method="POST">
<input type="submit" value="No, I do not want to delete this blog." />
</form>
-
-
<?php include Kohana::find_file('views', 'footer'); ?>
@@ -0,0 +1,12 @@
+<?php include Kohana::find_file('views', 'header'); ?>
+ <div class="main_wrap">
+ <h3>Confirm frag deletion?</h3>
+ <p>Do you really want to delete the fragment "<?php echo $frag->get("content"); ?>"?</p>
+ <form action="<?php echo URL::base().'fragment/delete/'.$frag->get('id')?>" method="POST">
+ <input type="hidden" name="confirm" value="1"/>
+ <input type="submit" value="Yes, I do want to delete this fragment." />
+ </form>
+ <form action="<?php echo URL::base().'home'; ?>" method="POST">
+ <input type="submit" value="No, I do not want to delete this fragment." />
+ </form>
+<?php include Kohana::find_file('views', 'footer'); ?>
@@ -1 +1 @@
-<?php include Kohana::find_file('views', 'header'); ?> <div class="fragment_wrap"> <p class="user_link"> <img src="<?php echo $user->get("avatar");?>" height="50px" width="85px" /> <?php echo Link::user($user->get("username"),'',"@".$user->get("username")); ?><span></span></p> <p class="fragment_content"><?php echo $frag->get('content'); ?></p> <p class="fragment_info"><?php echo DateHelper::human_readable($frag->get("when")); ?></p> </div><?php include Kohana::find_file('views', 'footer'); ?>
+<?php include Kohana::find_file('views', 'header'); ?> <div class="fragment_wrap"> <p class="user_link"> <img src="<?php echo $user->get("avatar");?>" height="50px" width="85px" /> <?php echo Link::user($user->get("username"),'',"@".$user->get("username")); ?><span></span></p> <p class="fragment_content"><?php echo $frag->get('content'); ?></p> <p class="fragment_info"><?php echo DateHelper::human_readable($frag->get("when")); ?><?php if ($logged_in): ?> &middot; <a href="#reply">reply</a><?php if ($user_rank > 1 OR $user_id == $frag->get('author_id')): ?> &middot; <?php echo HTML::anchor("fragment/delete/".$frag->get("id"),"delete",null,null,false); ?><?php endif; ?><?php endif; ?> </p> </div><?php include Kohana::find_file('views', 'footer'); ?>
@@ -37,6 +37,7 @@
</div>
<?php endforeach; ?>
<?php endif; ?>
+ <?php echo Pagination::thread_page_links($actual_page,$total_pages,$thread); ?>
<h4>Leave a comment</h4>
<?php if ($show_comment_form): ?>
<form action="<?php echo URL::base();?>thread/comment/<?php echo $thread['id']; ?>" method="POST">
View
@@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Servidor: localhost
--- Tiempo de generación: 29-12-2011 a las 03:57:33
+-- Tiempo de generación: 29-12-2011 a las 19:41:21
-- Versión del servidor: 5.5.8
-- Versión de PHP: 5.3.5
@@ -231,21 +231,33 @@ INSERT INTO `fragments` (`id`, `content`, `author_id`, `when`) VALUES
(5, '&lt;b&gt;xss&lt;/b&gt;?', 7, '2011-12-09 14:47:26'),
(6, 'html_entities &lt;3', 7, '2011-12-09 14:47:37'),
(7, 'i noticed all frags in the frontpage were by admin. jojo''s jealous', 10, '2011-12-09 16:23:01'),
-(8, 'ajaosdfjaoisfj aiosdfasdfasf', 10, '2011-12-09 18:33:42'),
-(9, '&lt;b&gt;xss&lt;/b&gt;?', 10, '2011-12-09 19:25:04'),
-(11, 'I&Atilde;&plusmn;t&Atilde;&laquo;rn&Atilde;&cent;ti&Atilde;&acute;n&Atilde;&nbsp;liz&Atilde;&brvbar;ti&Atilde;&cedil;n', 7, '2011-12-20 09:18:22'),
-(15, 'Iñtërnâtiônàlizætiøn', 7, '2011-12-20 09:25:21'),
-(21, 'I?t?rn?ti?n?liz?ti?n', 7, '2011-12-20 09:34:20'),
-(22, 'Iñtërnâtiônàlizætiøn', 7, '2011-12-20 09:37:16'),
-(23, 'Iñtërnâtiônàlizætiøn', 7, '2011-12-20 09:39:22'),
(24, 'Iñtërnâtiônàlizætiøn', 7, '2011-12-20 09:39:38'),
(25, 'Iñtërnâtiônàlizætiøn', 7, '2011-12-20 10:11:35'),
(26, 'I&ntilde;t&euml;rn&acirc;ti&ocirc;n&agrave;liz&aelig;ti&oslash;n', 7, '2011-12-20 10:15:45'),
(27, 'I&ntilde;t&euml;rn&acirc;ti&ocirc;n&agrave;liz&aelig;ti&oslash;n', 7, '2011-12-20 10:24:54'),
(28, 'testing the date system', 7, '2011-12-20 12:01:12'),
(29, 'testing a quite long fragment. it''s funny how at nite you become a super programmer! ', 7, '2011-12-20 12:32:40'),
-(30, '', 7, '2011-12-23 21:32:56'),
-(31, 'today''s april fools where I live', 7, '2011-12-28 09:14:18');
+(30, '', 7, '2011-12-23 21:32:56');
+
+-- --------------------------------------------------------
+
+--
+-- Estructura de tabla para la tabla `pings`
+--
+
+CREATE TABLE IF NOT EXISTS `pings` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `pinged_id` int(11) NOT NULL,
+ `author_id` int(11) NOT NULL,
+ `fragment_id` int(11) NOT NULL,
+ `when` datetime NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
+--
+-- Volcar la base de datos para la tabla `pings`
+--
+
-- --------------------------------------------------------
@@ -278,8 +290,8 @@ CREATE TABLE IF NOT EXISTS `users` (
--
INSERT INTO `users` (`id`, `username`, `password`, `avatar`, `name`, `age`, `country`, `gender`, `email`, `count_blogs`, `count_fragments`, `count_pageviews`, `count_friends`, `date_joined`, `date_last_seen`, `rank`) VALUES
-(7, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 'http://i.imgur.com/DLpg4.jpg', 'unknown', -1, 'unknown', 'unknown', 'joa.dev@live.com', 3, 30, 0, 0, '2011-12-08', '2011-12-08 19:01:39', 3),
-(10, 'jojo', '7f1d2b3a4016c460a93cdca536f3acce', 'http://i.imgur.com/Wrado.png', 'unknown', -1, 'unknown', 'unknown', 'joa.dev@live.com', 3, 3, 0, 0, '2011-12-09', '2011-12-09 03:02:11', 1),
+(7, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 'http://i.imgur.com/DLpg4.jpg', 'unknown', -1, 'unknown', 'unknown', 'joa.dev@live.com', 3, 24, 0, 0, '2011-12-08', '2011-12-08 19:01:39', 3),
+(10, 'jojo', '7f1d2b3a4016c460a93cdca536f3acce', 'http://i.imgur.com/Wrado.png', 'unknown', -1, 'unknown', 'unknown', 'joa.dev@live.com', 3, 1, 0, 0, '2011-12-09', '2011-12-09 03:02:11', 1),
(11, 'username', '5f4dcc3b5aa765d61d8327deb882cf99', 'http://i.imgur.com/Wrado.png', 'unknown', -1, 'unknown', 'unknown', 'me@example.com', 0, 0, 0, 0, '2011-12-09', '2011-12-09 03:22:14', 1);
-- --------------------------------------------------------
Oops, something went wrong.

0 comments on commit 40048b8

Please sign in to comment.