diff --git a/controllers/d.blog.php b/controllers/d.blog.php index 75cd8e6..3335b88 100755 --- a/controllers/d.blog.php +++ b/controllers/d.blog.php @@ -99,6 +99,10 @@ switch ($controller->splitted_url[1]) { $blogArticle->delete(); header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink); } + else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "restore" && $user->rankIsHigher("moderator")) { + $blogArticle->restore(); + header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink); + } else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->rankIsHigher("moderator")) { if(isset($_POST['submit'])) { $blogArticle->content = $_POST['content']; diff --git a/models/d.blog.php b/models/d.blog.php index bd329c6..af758ad 100755 --- a/models/d.blog.php +++ b/models/d.blog.php @@ -131,7 +131,7 @@ class BlogArticle pg_close($con); error_log( - date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit blog article '".$this->url."'\r\n", + date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit blog article '".$this->permalink."'\r\n", 3, $config['logs_folder'].'blog.articles.log'); } @@ -139,27 +139,52 @@ class BlogArticle /***** ** Delete an article by archiving it *****/ -/* public function delete() { + public function delete() { global $config; global $user; $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass']) or die ("Could not connect to server\n"); - $query = "UPDATE blog_articles SET archive = TRUE WHERE url = $1"; + $query = "UPDATE contents SET is_public=FALSE WHERE permalink=$1 AND type='blog'"; pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); - $result = pg_execute($con, "prepare1", array($this->url)) + $result = pg_execute($con, "prepare1", array($this->permalink)) or die ("Cannot execute statement\n"); pg_close($con); error_log( - date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive blog article '".$this->url."'\r\n", + date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive blog article '".$this->permalink."'\r\n", 3, $config['logs_folder'].'blog.articles.log'); - }*/ + } + + /***** + ** Restore a page from unpublishing it + *****/ + public function restore() { + global $config; + global $user; + + $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass']) + or die ("Could not connect to server\n"); + + $query = "UPDATE contents SET is_public=TRUE WHERE permalink=$1 AND type='blog'"; + + pg_prepare($con, "prepare1", $query) + or die ("Cannot prepare statement\n"); + $result = pg_execute($con, "prepare1", array($this->permalink)) + or die ("Cannot execute statement\n"); + + pg_close($con); + + error_log( + date('r')." \t".$user->name." (".$user->id.") \tRESTORE \tPublish blog article '".$this->permalink."'\r\n", + 3, + $config['logs_folder'].'blog.articles.log'); + } /***** ** Create an article @@ -192,7 +217,7 @@ class BlogArticle pg_close($con); error_log( - date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new blog article '".$this->url."'\r\n", + date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new blog article '".$this->permalink."'\r\n", 3, $config['logs_folder'].'blog.articles.log'); }