Getion des commentaires dans un modèle spécial
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?
|
||||
|
||||
require_once($config['models_folder']."d.blog.php");
|
||||
require_once($config['models_folder']."d.comments.php");
|
||||
require_once($config['models_folder']."d.users.php");
|
||||
|
||||
$head['css'] = "d.index.css;d.blog.css";
|
||||
@@ -129,32 +130,32 @@ switch ($controller->splitted_url[1]) {
|
||||
// Manage comment creation
|
||||
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="new_comment") {
|
||||
if (isset($_POST['submit']) && $user->rankIsHigher("registered")) {
|
||||
$blogComment = new Kabano\BlogComment();
|
||||
$blogComment->locale = $user->locale;
|
||||
$blogComment->author = $user->id;
|
||||
$blogComment->content = $blogArticle->content_id;
|
||||
$blogComment->comment = $_POST['comment'];
|
||||
$blogComment->insert();
|
||||
$Comment = new Kabano\Comment();
|
||||
$Comment->locale = $user->locale;
|
||||
$Comment->author = $user->id;
|
||||
$Comment->content = $blogArticle->content_id;
|
||||
$Comment->comment = $_POST['comment'];
|
||||
$Comment->insert();
|
||||
}
|
||||
}
|
||||
|
||||
// Manage comment deletion
|
||||
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="delete_comment") {
|
||||
if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
|
||||
$blogComment = new Kabano\BlogComment();
|
||||
if($blogComment->checkId($controller->splitted_url[3]))
|
||||
if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
|
||||
$blogComment->delete();
|
||||
$Comment = new Kabano\Comment();
|
||||
if($Comment->checkId($controller->splitted_url[3]))
|
||||
if ($user->rankIsHigher("moderator") || $user->id == $Comment->author)
|
||||
$Comment->delete();
|
||||
}
|
||||
}
|
||||
|
||||
// Manage comment restoration
|
||||
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="restore_comment") {
|
||||
if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
|
||||
$blogComment = new Kabano\BlogComment();
|
||||
if($blogComment->checkId($controller->splitted_url[3]))
|
||||
if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
|
||||
$blogComment->restore();
|
||||
$Comment = new Kabano\Comment();
|
||||
if($Comment->checkId($controller->splitted_url[3]))
|
||||
if ($user->rankIsHigher("moderator") || $user->id == $Comment->author)
|
||||
$Comment->restore();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +163,7 @@ switch ($controller->splitted_url[1]) {
|
||||
|
||||
// Manage comments
|
||||
if ($blogArticle->is_commentable == "t") {
|
||||
$blogArticles_comments = new Kabano\BlogComments();
|
||||
$blogArticles_comments = new Kabano\Comments();
|
||||
$blogArticles_comments->listComments($blogArticle->content_id, ($user->rankIsHigher("premium")));
|
||||
|
||||
$i = 0;
|
||||
|
||||
@@ -61,104 +61,104 @@ switch ($controller->splitted_url[1]) {
|
||||
$notfound = 1;
|
||||
}
|
||||
default:
|
||||
// // If the page exists
|
||||
// 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->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'];
|
||||
// $blogArticle->locale = $_POST['locale'];
|
||||
// $blogArticle->name = $_POST['name'];
|
||||
// $blogArticle->is_commentable = isset($_POST['is_commentable'])?'t':'f';
|
||||
// $blogArticle->author = $user->id;
|
||||
// $blogArticle->update();
|
||||
// header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink);
|
||||
// }
|
||||
// else {
|
||||
// $locales = new Kabano\Locales();
|
||||
// $locales->getAll();
|
||||
// If the page exists
|
||||
if ($poi->checkPermalink($controller->splitted_url[1],$user->rankIsHigher("premium"))) {
|
||||
// if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->rankIsHigher("moderator")) {
|
||||
// $poi->delete();
|
||||
// header('Location: '.$config['rel_root_folder']."blog/".$poi->permalink);
|
||||
// }
|
||||
// else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "restore" && $user->rankIsHigher("moderator")) {
|
||||
// $poi->restore();
|
||||
// header('Location: '.$config['rel_root_folder']."blog/".$poi->permalink);
|
||||
// }
|
||||
// else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->rankIsHigher("moderator")) {
|
||||
// if(isset($_POST['submit'])) {
|
||||
// $poi->content = $_POST['content'];
|
||||
// $poi->locale = $_POST['locale'];
|
||||
// $poi->name = $_POST['name'];
|
||||
// $poi->is_commentable = $_POST['is_commentable'];
|
||||
// $poi->author = $user->id;
|
||||
// $poi->update();
|
||||
// header('Location: '.$config['rel_root_folder']."blog/".$poi->permalink);
|
||||
// }
|
||||
// else {
|
||||
// $locales = new Kabano\Locales();
|
||||
// $locales->getAll();
|
||||
|
||||
// $head['title'] = $blogArticle->name;
|
||||
// include ($config['views_folder']."d.blog.edit.html");
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// // Manage history of an article
|
||||
// if($user->rankIsHigher("premium")) {
|
||||
// $blogHistory = new Kabano\BlogArticles();
|
||||
// $blogHistory->getHistory($controller->splitted_url[1]);
|
||||
// }
|
||||
// if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2]))
|
||||
// $blogArticle->checkPermalink($controller->splitted_url[1],$user->rankIsHigher("premium"),$controller->splitted_url[2]);
|
||||
// $head['title'] = $poi->name;
|
||||
// include ($config['views_folder']."d.blog.edit.html");
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// Manage history of an article
|
||||
if($user->rankIsHigher("premium")) {
|
||||
$blogHistory = new Kabano\pois();
|
||||
$blogHistory->getHistory($controller->splitted_url[1]);
|
||||
}
|
||||
if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2]))
|
||||
$poi->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") {
|
||||
// if (isset($_POST['submit']) && $user->rankIsHigher("registered")) {
|
||||
// $blogComment = new Kabano\BlogComment();
|
||||
// $blogComment->locale = $user->locale;
|
||||
// $blogComment->author = $user->id;
|
||||
// $blogComment->content = $blogArticle->content_id;
|
||||
// $blogComment->comment = $_POST['comment'];
|
||||
// $blogComment->insert();
|
||||
// }
|
||||
// }
|
||||
// Manage comment creation
|
||||
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="new_comment") {
|
||||
if (isset($_POST['submit']) && $user->rankIsHigher("registered")) {
|
||||
$blogComment = new Kabano\BlogComment();
|
||||
$blogComment->locale = $user->locale;
|
||||
$blogComment->author = $user->id;
|
||||
$blogComment->content = $poi->content_id;
|
||||
$blogComment->comment = $_POST['comment'];
|
||||
$blogComment->insert();
|
||||
}
|
||||
}
|
||||
|
||||
// // Manage comment deletion
|
||||
// if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="delete_comment") {
|
||||
// if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
|
||||
// $blogComment = new Kabano\BlogComment();
|
||||
// if($blogComment->checkId($controller->splitted_url[3]))
|
||||
// if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
|
||||
// $blogComment->delete();
|
||||
// }
|
||||
// }
|
||||
// Manage comment deletion
|
||||
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="delete_comment") {
|
||||
if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
|
||||
$blogComment = new Kabano\BlogComment();
|
||||
if($blogComment->checkId($controller->splitted_url[3]))
|
||||
if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
|
||||
$blogComment->delete();
|
||||
}
|
||||
}
|
||||
|
||||
// // Manage comment restoration
|
||||
// if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="restore_comment") {
|
||||
// if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
|
||||
// $blogComment = new Kabano\BlogComment();
|
||||
// if($blogComment->checkId($controller->splitted_url[3]))
|
||||
// if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
|
||||
// $blogComment->restore();
|
||||
// }
|
||||
// }
|
||||
// Manage comment restoration
|
||||
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="restore_comment") {
|
||||
if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
|
||||
$blogComment = new Kabano\BlogComment();
|
||||
if($blogComment->checkId($controller->splitted_url[3]))
|
||||
if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
|
||||
$blogComment->restore();
|
||||
}
|
||||
}
|
||||
|
||||
// $blogArticle->md2html();
|
||||
$poi->md2html();
|
||||
|
||||
// // Manage comments
|
||||
// if ($blogArticle->is_commentable == "t") {
|
||||
// $blogArticles_comments = new Kabano\BlogComments();
|
||||
// $blogArticles_comments->listComments($blogArticle->content_id, ($user->rankIsHigher("premium")));
|
||||
// Manage comments
|
||||
if ($poi->is_commentable == "t") {
|
||||
$pois_comments = new Kabano\BlogComments();
|
||||
$pois_comments->listComments($poi->content_id, ($user->rankIsHigher("premium")));
|
||||
|
||||
// $i = 0;
|
||||
// foreach ($blogArticles_comments->objs as $comment) {
|
||||
// $comment->md2html();
|
||||
// $comment->author_obj = new Kabano\User();
|
||||
// $comment->author_obj->checkId($comment->author);
|
||||
// }
|
||||
// }
|
||||
$i = 0;
|
||||
foreach ($pois_comments->objs as $comment) {
|
||||
$comment->md2html();
|
||||
$comment->author_obj = new Kabano\User();
|
||||
$comment->author_obj->checkId($comment->author);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// $tempUser = new Kabano\User();
|
||||
// $tempUser->checkId($blogArticle->author);
|
||||
// $blogArticle->author_name = $tempUser->name;
|
||||
// unset($tempUser);
|
||||
$tempUser = new Kabano\User();
|
||||
$tempUser->checkId($poi->author);
|
||||
$poi->author_name = $tempUser->name;
|
||||
unset($tempUser);
|
||||
|
||||
// $head['title'] = $blogArticle->name;
|
||||
// include ($config['views_folder']."d.blog.view.html");
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// $notfound = 1;
|
||||
// }
|
||||
// break;
|
||||
$head['title'] = $poi->name;
|
||||
include ($config['views_folder']."d.blog.view.html");
|
||||
// }
|
||||
}
|
||||
else {
|
||||
$notfound = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -371,205 +371,4 @@ class BlogArticles
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************
|
||||
***********************************************************
|
||||
**
|
||||
** This class is to manage a blog comment object
|
||||
**
|
||||
***********************************************************
|
||||
**********************************************************/
|
||||
|
||||
class BlogComment
|
||||
{
|
||||
public $id = NULL;
|
||||
public $version = 0;
|
||||
public $creation_date = NULL;
|
||||
public $update_date = NULL;
|
||||
public $author = NULL;
|
||||
public $is_public = NULL;
|
||||
public $is_archive = NULL;
|
||||
public $content = NULL;
|
||||
public $comment = NULL;
|
||||
public $locale = NULL;
|
||||
public $comment_html = NULL;
|
||||
public $author_obj = NULL;
|
||||
|
||||
|
||||
/*****
|
||||
** Connect to correct account using ID and stores its ID
|
||||
*****/
|
||||
public function checkID($id) {
|
||||
global $config;
|
||||
|
||||
$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 = "SELECT * FROM content_comments WHERE id=$1";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array($id))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
pg_close($con);
|
||||
|
||||
if(pg_num_rows($result) == 1) {
|
||||
$row = pg_fetch_assoc($result);
|
||||
$this->populate($row);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*****
|
||||
** Populate the object using its ID
|
||||
*****/
|
||||
public function populate($row) {
|
||||
$this->id = $row['id'];
|
||||
$this->version = $row['version'];
|
||||
$this->creation_date = $row['creation_date'];
|
||||
$this->update_date = $row['update_date'];
|
||||
$this->author = $row['author'];
|
||||
$this->is_public = $row['is_public'];
|
||||
$this->is_archive = $row['is_archive'];
|
||||
$this->content = $row['content'];
|
||||
$this->comment = $row['comment'];
|
||||
$this->locale = $row['locale'];
|
||||
}
|
||||
|
||||
/*****
|
||||
** Create a new comment
|
||||
*****/
|
||||
public function insert() {
|
||||
global $config;
|
||||
|
||||
$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 content_comments (version, creation_date, update_date, author, is_public, is_archive, content, comment, locale) VALUES
|
||||
('0', $1, $2, $3, TRUE, FALSE, $4, $5, $6) RETURNING id";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array(date('r'), date('r'), $this->author, $this->content, $this->comment, $this->locale))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
$this->id = pg_fetch_assoc($result)['id'];
|
||||
|
||||
pg_close($con);
|
||||
}
|
||||
|
||||
/*****
|
||||
** Archive a comment
|
||||
*****/
|
||||
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 content_comments SET is_public = FALSE WHERE id = $1";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array($this->id))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
pg_close($con);
|
||||
|
||||
error_log(
|
||||
date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive comment ".$this->id."\r\n",
|
||||
3,
|
||||
$config['logs_folder'].'blog.comments.log');
|
||||
}
|
||||
|
||||
/*****
|
||||
** Restore a comment
|
||||
*****/
|
||||
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 content_comments SET is_public = TRUE WHERE id = $1";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array($this->id))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
pg_close($con);
|
||||
|
||||
error_log(
|
||||
date('r')." \t".$user->name." (".$user->id.") \tPUBLISH \tUn archive comment ".$this->id."\r\n",
|
||||
3,
|
||||
$config['logs_folder'].'blog.comments.log');
|
||||
}
|
||||
|
||||
/*****
|
||||
** Converts the Markdown comment to HTML
|
||||
*****/
|
||||
public function md2html() {
|
||||
$this->comment_html = \Michelf\MarkdownExtra::defaultTransform($this->comment);
|
||||
}
|
||||
|
||||
/*****
|
||||
** Converts the Markdown comment to text
|
||||
*****/
|
||||
public function md2txt() {
|
||||
$this->md2html();
|
||||
$this->comment_txt = strip_tags($this->comment_html);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************
|
||||
***********************************************************
|
||||
**
|
||||
** This class is to manage a list of blog comments
|
||||
**
|
||||
***********************************************************
|
||||
**********************************************************/
|
||||
|
||||
class BlogComments
|
||||
{
|
||||
public $objs = array();
|
||||
public $number = NULL;
|
||||
|
||||
/*****
|
||||
** Return the list of different articles
|
||||
*****/
|
||||
public function listComments($id, $archive=0) {
|
||||
global $config;
|
||||
|
||||
$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 = "SELECT * FROM content_comments WHERE content = $1 ";
|
||||
if ($archive == 0)
|
||||
$query .= "AND is_archive IS FALSE AND is_public IS TRUE ";
|
||||
$query .= "ORDER BY update_date DESC";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array($id))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
pg_close($con);
|
||||
|
||||
$this->number = pg_num_rows($result);
|
||||
|
||||
for($i = 0; $i < pg_num_rows($result); $i++) {
|
||||
$row = pg_fetch_assoc($result, $i);
|
||||
$this->objs[$i] = new BlogComment;
|
||||
$this->objs[$i]->populate($row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
208
models/d.comments.php
Normal file
208
models/d.comments.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
namespace Kabano;
|
||||
|
||||
/**********************************************************
|
||||
***********************************************************
|
||||
**
|
||||
** This class is to manage a comment object
|
||||
**
|
||||
***********************************************************
|
||||
**********************************************************/
|
||||
|
||||
require_once($config['third_folder']."Md/MarkdownExtra.inc.php");
|
||||
|
||||
class Comment
|
||||
{
|
||||
public $id = NULL;
|
||||
public $version = 0;
|
||||
public $creation_date = NULL;
|
||||
public $update_date = NULL;
|
||||
public $author = NULL;
|
||||
public $is_public = NULL;
|
||||
public $is_archive = NULL;
|
||||
public $content = NULL;
|
||||
public $comment = NULL;
|
||||
public $locale = NULL;
|
||||
public $comment_html = NULL;
|
||||
public $author_obj = NULL;
|
||||
|
||||
|
||||
/*****
|
||||
** Connect to correct account using ID and stores its ID
|
||||
*****/
|
||||
public function checkID($id) {
|
||||
global $config;
|
||||
|
||||
$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 = "SELECT * FROM content_comments WHERE id=$1";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array($id))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
pg_close($con);
|
||||
|
||||
if(pg_num_rows($result) == 1) {
|
||||
$row = pg_fetch_assoc($result);
|
||||
$this->populate($row);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*****
|
||||
** Populate the object using its ID
|
||||
*****/
|
||||
public function populate($row) {
|
||||
$this->id = $row['id'];
|
||||
$this->version = $row['version'];
|
||||
$this->creation_date = $row['creation_date'];
|
||||
$this->update_date = $row['update_date'];
|
||||
$this->author = $row['author'];
|
||||
$this->is_public = $row['is_public'];
|
||||
$this->is_archive = $row['is_archive'];
|
||||
$this->content = $row['content'];
|
||||
$this->comment = $row['comment'];
|
||||
$this->locale = $row['locale'];
|
||||
}
|
||||
|
||||
/*****
|
||||
** Create a new comment
|
||||
*****/
|
||||
public function insert() {
|
||||
global $config;
|
||||
|
||||
$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 content_comments (version, creation_date, update_date, author, is_public, is_archive, content, comment, locale) VALUES
|
||||
('0', $1, $2, $3, TRUE, FALSE, $4, $5, $6) RETURNING id";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array(date('r'), date('r'), $this->author, $this->content, $this->comment, $this->locale))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
$this->id = pg_fetch_assoc($result)['id'];
|
||||
|
||||
pg_close($con);
|
||||
}
|
||||
|
||||
/*****
|
||||
** Archive a comment
|
||||
*****/
|
||||
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 content_comments SET is_public = FALSE WHERE id = $1";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array($this->id))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
pg_close($con);
|
||||
|
||||
error_log(
|
||||
date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive comment ".$this->id."\r\n",
|
||||
3,
|
||||
$config['logs_folder'].'blog.comments.log');
|
||||
}
|
||||
|
||||
/*****
|
||||
** Restore a comment
|
||||
*****/
|
||||
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 content_comments SET is_public = TRUE WHERE id = $1";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array($this->id))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
pg_close($con);
|
||||
|
||||
error_log(
|
||||
date('r')." \t".$user->name." (".$user->id.") \tPUBLISH \tUn archive comment ".$this->id."\r\n",
|
||||
3,
|
||||
$config['logs_folder'].'blog.comments.log');
|
||||
}
|
||||
|
||||
/*****
|
||||
** Converts the Markdown comment to HTML
|
||||
*****/
|
||||
public function md2html() {
|
||||
$this->comment_html = \Michelf\MarkdownExtra::defaultTransform($this->comment);
|
||||
}
|
||||
|
||||
/*****
|
||||
** Converts the Markdown comment to text
|
||||
*****/
|
||||
public function md2txt() {
|
||||
$this->md2html();
|
||||
$this->comment_txt = strip_tags($this->comment_html);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************
|
||||
***********************************************************
|
||||
**
|
||||
** This class is to manage a list of blog comments
|
||||
**
|
||||
***********************************************************
|
||||
**********************************************************/
|
||||
|
||||
class Comments
|
||||
{
|
||||
public $objs = array();
|
||||
public $number = NULL;
|
||||
|
||||
/*****
|
||||
** Return the list of different articles
|
||||
*****/
|
||||
public function listComments($id, $archive=0) {
|
||||
global $config;
|
||||
|
||||
$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 = "SELECT * FROM content_comments WHERE content = $1 ";
|
||||
if ($archive == 0)
|
||||
$query .= "AND is_archive IS FALSE AND is_public IS TRUE ";
|
||||
$query .= "ORDER BY update_date DESC";
|
||||
|
||||
pg_prepare($con, "prepare1", $query)
|
||||
or die ("Cannot prepare statement\n");
|
||||
$result = pg_execute($con, "prepare1", array($id))
|
||||
or die ("Cannot execute statement\n");
|
||||
|
||||
pg_close($con);
|
||||
|
||||
$this->number = pg_num_rows($result);
|
||||
|
||||
for($i = 0; $i < pg_num_rows($result); $i++) {
|
||||
$row = pg_fetch_assoc($result, $i);
|
||||
$this->objs[$i] = new Comment;
|
||||
$this->objs[$i]->populate($row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
176
models/d.poi.php
176
models/d.poi.php
@@ -165,9 +165,183 @@ class Poi
|
||||
error_log(
|
||||
date('r')." \t".$user->name." (".$user->id.") \tINSERT \tCreate new poi '".$this->permalink."'\r\n",
|
||||
3,
|
||||
$config['logs_folder'].'wiki.log');
|
||||
$config['logs_folder'].'poi.log');
|
||||
}
|
||||
|
||||
/*****
|
||||
** Edit a POI by archiving the current version and inserting a new one
|
||||
*****/
|
||||
public function update() {
|
||||
global $config;
|
||||
global $user;
|
||||
|
||||
if ($this->content_id == 0 || $this->locale_id == 0 || $this->version_id == 0)
|
||||
die("Cannot update entry without giving ID");
|
||||
|
||||
$this->version++;
|
||||
|
||||
$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");
|
||||
|
||||
pg_query($con, "BEGIN");
|
||||
|
||||
// 1) Archive old versions
|
||||
$query = "UPDATE content_versions SET is_archive = TRUE WHERE locale_id = $1";
|
||||
pg_prepare($con, "poi_update_archive", $query);
|
||||
pg_execute($con, "poi_update_archive", array($this->locale_id));
|
||||
|
||||
// 2) Insert new version
|
||||
$query = "INSERT INTO content_versions (version, update_date, is_archive, name, content, locale_id) VALUES
|
||||
($1, $2, FALSE, $3, $4, $5) RETURNING id";
|
||||
|
||||
pg_prepare($con, "poi_update_newversion", $query);
|
||||
|
||||
$result = pg_execute($con, "poi_update_newversion", array($this->version, date('r'), $this->name, json_encode($this->parameters), $this->locale_id));
|
||||
|
||||
$this->version_id = pg_fetch_assoc($result)['id'];
|
||||
|
||||
// 3) Insert new geometry + source info for this new version
|
||||
$query = "INSERT INTO content_version_poi_specifications,(content_version_id, geom, source_id, remote_source_id) VALUES
|
||||
($1, ST_SetSRID(ST_MakePoint($2, $3, $4), 4326), $5, $6)";
|
||||
|
||||
pg_prepare($con, "poi_insert_specs_update", $query);
|
||||
pg_execute($con, "poi_insert_specs_update", array( $this->version_id, $this->lon, $this->lat, $this->ele, $this->source, $this->remote_source_id ));
|
||||
|
||||
// 4) Update is_commentable
|
||||
$query = "UPDATE contents SET is_commentable = $1 WHERE id = $2";
|
||||
pg_prepare($con, "poi_update_commentable", $query);
|
||||
pg_execute($con, "poi_update_commentable", array( $this->is_commentable ? 't' : 'f', $this->content_id));
|
||||
|
||||
// 5) Add contributor
|
||||
$query = "INSERT INTO content_contributors (content, contributor)
|
||||
VALUES ($1, $2) ON CONFLICT (content, contributor) DO NOTHING";
|
||||
|
||||
pg_prepare($con, "poi_update_contrib", $query);
|
||||
pg_execute($con, "poi_update_contrib", array($this->content_id, $user->id));
|
||||
|
||||
pg_query($con, "COMMIT");
|
||||
pg_close($con);
|
||||
|
||||
error_log(
|
||||
date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit POI '".$this->permalink."'\r\n",
|
||||
3,
|
||||
$config['logs_folder'].'poi.log'
|
||||
);
|
||||
}
|
||||
|
||||
/*****
|
||||
** Archive a POI
|
||||
*****/
|
||||
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 contents SET is_public = FALSE WHERE id = $1";
|
||||
|
||||
pg_prepare($con, "poi_delete", $query);
|
||||
pg_execute($con, "poi_delete", array($this->content_id));
|
||||
|
||||
pg_close($con);
|
||||
|
||||
error_log(
|
||||
date('r')." \t".$user->name." (".$user->id.") \tDELETE \tArchive POI '".$this->permalink."'\r\n",
|
||||
3,
|
||||
$config['logs_folder'].'poi.log'
|
||||
);
|
||||
}
|
||||
|
||||
/*****
|
||||
** Restore a POI
|
||||
*****/
|
||||
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 id = $1";
|
||||
|
||||
pg_prepare($con, "poi_restore", $query);
|
||||
pg_execute($con, "poi_restore", array($this->content_id));
|
||||
|
||||
pg_close($con);
|
||||
|
||||
error_log(
|
||||
date('r')." \t".$user->name." (".$user->id.") \tRESTORE \tPublish POI '".$this->permalink."'\r\n",
|
||||
3,
|
||||
$config['logs_folder'].'poi.log'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Pois
|
||||
{
|
||||
public $objs = [];
|
||||
public $number = 0;
|
||||
|
||||
public function listPois($first, $count, $archive=0) {
|
||||
global $config;
|
||||
|
||||
$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 = "
|
||||
SELECT content_versions.id AS version_id, *
|
||||
FROM contents
|
||||
INNER JOIN content_locales ON contents.id = content_locales.content_id
|
||||
INNER JOIN content_versions ON content_locales.id = content_versions.locale_id
|
||||
WHERE type='poi' AND is_archive=FALSE
|
||||
";
|
||||
|
||||
if ($archive != 1)
|
||||
$query .= " AND is_public=TRUE ";
|
||||
|
||||
$query .= " ORDER BY update_date DESC LIMIT $1 OFFSET $2";
|
||||
|
||||
pg_prepare($con, "pois_list", $query);
|
||||
$result = pg_execute($con, "pois_list", array($count, $first));
|
||||
|
||||
pg_close($con);
|
||||
|
||||
for ($i = 0; $i < pg_num_rows($result); $i++) {
|
||||
$row = pg_fetch_assoc($result, $i);
|
||||
$this->objs[$i] = new Poi;
|
||||
$this->objs[$i]->populate($row);
|
||||
}
|
||||
}
|
||||
|
||||
public function getHistory($permalink) {
|
||||
global $config;
|
||||
|
||||
$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 = "
|
||||
SELECT content_versions.id AS version_id, *
|
||||
FROM contents
|
||||
INNER JOIN content_locales ON contents.id = content_locales.content_id
|
||||
INNER JOIN content_versions ON content_locales.id = content_versions.locale_id
|
||||
WHERE permalink=$1 AND type='poi'
|
||||
ORDER BY update_date DESC
|
||||
";
|
||||
|
||||
pg_prepare($con, "poi_history", $query);
|
||||
$result = pg_execute($con, "poi_history", array($permalink));
|
||||
|
||||
pg_close($con);
|
||||
|
||||
$this->number = pg_num_rows($result);
|
||||
|
||||
for ($i = 0; $i < $this->number; $i++) {
|
||||
$row = pg_fetch_assoc($result, $i);
|
||||
$this->objs[$i] = new Poi;
|
||||
$this->objs[$i]->populate($row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user