diff --git a/controllers/d.blog.php b/controllers/d.blog.php index b9d6baa..3d88ae5 100755 --- a/controllers/d.blog.php +++ b/controllers/d.blog.php @@ -68,30 +68,33 @@ switch ($controller->splitted_url[1]) { if(isset($_POST['submit'])) { $blogArticle->content = $_POST['content']; $blogArticle->locale = $_POST['locale']; - $blogArticle->title = $_POST['title']; - $blogArticle->comments = isset($_POST['comments'])?'t':'f'; + $blogArticle->name = $_POST['name']; + $blogArticle->is_commentable = isset($_POST['is_commentable'])?'t':'f'; $blogArticle->author = $user->id; - if(!$blogArticle->checkUrl($_POST['url'],1)) { + if(!$blogArticle->checkPermalink($_POST['permalink'],1)) { + $blogArticle->permalink = $_POST['permalink']; $blogArticle->insert(); - header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->url); + header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink); } else { - $head['title'] = $blogArticle->title; - $error = "url"; - $new = 1; - include ($config['views_folder']."d.blog.edit.html"); + $head['title'] = $blogArticle->name; + $error = "permalink"; } } else { $head['title'] = "Nouvel article"; - $new = 1; - include ($config['views_folder']."d.blog.edit.html"); } + + $locales = new Kabano\Locales(); + $locales->getAll(); + + $new = 1; + include ($config['views_folder']."d.blog.edit.html"); break; } default: // If the page exists - if ($blogArticle->checkUrl($controller->splitted_url[1],$user->rankIsHigher("premium"))) { + if ($blogArticle->checkPermalink($controller->splitted_url[1],$user->rankIsHigher("premium"))) { if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->rankIsHigher("moderator")) { $blogArticle->delete(); header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->url); @@ -127,7 +130,7 @@ switch ($controller->splitted_url[1]) { } } if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2])) - $blogArticle->checkUrl($controller->splitted_url[1],$user->rankIsHigher("premium"),$controller->splitted_url[2]); + $blogArticle->checkPermalink($controller->splitted_url[1],$user->rankIsHigher("premium"),$controller->splitted_url[2]); // Manage comment creation if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="new_comment") { diff --git a/models/d.blog.php b/models/d.blog.php index 1588d2f..ce22e5d 100755 --- a/models/d.blog.php +++ b/models/d.blog.php @@ -14,8 +14,8 @@ require_once($config['third_folder']."Md/MarkdownExtra.inc.php"); class BlogArticle { - public $id = 0; - public $permalink = 0; + public $id = NULL; + public $permalink = NULL; public $version = 0; public $locale = NULL; public $creation_date = NULL; @@ -82,7 +82,7 @@ class BlogArticle /***** ** Edit a page by archiving the current one and inserting a new one ID *****/ - public function update() { +/* public function update() { global $config; global $user; @@ -124,12 +124,12 @@ class BlogArticle date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit blog article '".$this->url."'\r\n", 3, $config['logs_folder'].'blog.articles.log'); - } + }*/ /***** ** Delete an article by archiving it *****/ - public function delete() { +/* public function delete() { global $config; global $user; @@ -149,7 +149,7 @@ class BlogArticle date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive blog article '".$this->url."'\r\n", 3, $config['logs_folder'].'blog.articles.log'); - } + }*/ /***** ** Create an article @@ -161,16 +161,18 @@ class BlogArticle $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 = "INSERT INTO blog_articles (url, title, content, lastedit, archive, locale, author, comments) VALUES - ($1, $2, $3, $4, FALSE, $5, $6, $7)"; + $query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES + ($1, '0', $2, $3, $4, $5, TRUE, FALSE, $6, 'blog', $7, $8) RETURNING id"; - pg_prepare($con, "prepare2", $query) + pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); - $result = pg_execute($con, "prepare2", array($this->url, $this->title, $this->content, date('r'), $this->locale, $this->author, $this->comments)) + $result = pg_execute($con, "prepare1", array($this->permalink, $this->locale, date('r'), date('r'), $user->id, $this->is_commentable, $this->name, $this->content)) or die ("Cannot execute statement\n"); pg_close($con); + $this->id = pg_fetch_assoc($result)['id']; + error_log( date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new blog article '".$this->url."'\r\n", 3, @@ -269,7 +271,7 @@ class BlogArticles /***** ** Return the list of archived version of a blog article *****/ - public function getHistory($url) { +/* public function getHistory($url) { global $config; $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass']) @@ -290,7 +292,7 @@ class BlogArticles $row = pg_fetch_assoc($result, $i); $this->ids[$i] = $row['id']; } - } + }*/ } diff --git a/models/d.wiki.php b/models/d.wiki.php index 2201108..128d1cb 100755 --- a/models/d.wiki.php +++ b/models/d.wiki.php @@ -14,8 +14,8 @@ require_once($config['third_folder']."Md/MarkdownExtra.inc.php"); class WikiPage { - public $id = 0; - public $permalink = 0; + public $id = NULL; + public $permalink = NULL; public $version = 0; public $locale = NULL; public $creation_date = NULL; @@ -204,10 +204,10 @@ class WikiPage $result = pg_execute($con, "prepare1", array($this->permalink, $this->locale, date('r'), date('r'), $user->id, $this->name, $this->content)) or die ("Cannot execute statement\n"); - $this->id = pg_fetch_assoc($result)['id']; - pg_close($con); + $this->id = pg_fetch_assoc($result)['id']; + error_log( date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new wiki page '".$this->permalink."'\r\n", 3, diff --git a/views/d.blog.edit.html b/views/d.blog.edit.html index 95830ed..e34a717 100755 --- a/views/d.blog.edit.html +++ b/views/d.blog.edit.html @@ -53,7 +53,7 @@ $( "#name" ).keyup(function() { permalink = permalink.replace(/ /g,'_'); permalink = permalink.toLowerCase(); permalink = permalink.replace(/[^a-z0-9_]/g,'-'); - permalink = permalink.replace(/[_$]/g,'-'); + permalink = permalink.replace(/[_-]+$/g,''); $( "#permalink" ).val(permalink); }); $( "#name" ).change(function() { @@ -61,7 +61,7 @@ $( "#name" ).change(function() { permalink = permalink.replace(/ /g,'_'); permalink = permalink.toLowerCase(); permalink = permalink.replace(/[^a-z0-9_]/g,'-'); - permalink = permalink.replace(/[_$]/g,'-'); + permalink = permalink.replace(/[_-]+$/g,''); $( "#permalink" ).val(permalink); });