Browse Source

fix blog edition

Léo Serre 10 months ago
parent
commit
b5115182d5
4 changed files with 37 additions and 25 deletions
  1. 11
    9
      controllers/d.blog.php
  2. 23
    13
      models/d.blog.php
  3. 2
    2
      views/d.blog.edit.html
  4. 1
    1
      views/d.blog.view.html

+ 11
- 9
controllers/d.blog.php View File

@@ -97,21 +97,23 @@ switch ($controller->splitted_url[1]) {
97 97
 		if ($blogArticle->checkPermalink($controller->splitted_url[1],$user->rankIsHigher("premium"))) {
98 98
 			if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->rankIsHigher("moderator")) {
99 99
 				$blogArticle->delete();
100
-				header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->url);
100
+				header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink);
101 101
 			}
102 102
 			else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->rankIsHigher("moderator")) {
103 103
 				if(isset($_POST['submit'])) {
104 104
 					$blogArticle->content = $_POST['content'];
105 105
 					$blogArticle->locale = $_POST['locale'];
106
-					$blogArticle->title = $_POST['title'];
107
-					$blogArticle->comments = isset($_POST['comments'])?'t':'f';
106
+					$blogArticle->name = $_POST['name'];
107
+					$blogArticle->is_commentable = isset($_POST['is_commentable'])?'t':'f';
108 108
 					$blogArticle->author = $user->id;
109 109
 					$blogArticle->update();
110
-					header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->url);
110
+					header('Location: '.$config['rel_root_folder']."blog/".$blogArticle->permalink);
111 111
 				}
112 112
 				else {
113
-					$blogArticle->populate();
114
-					$head['title'] = $blogArticle->title;
113
+					$locales = new Kabano\Locales();
114
+					$locales->getAll();
115
+
116
+					$head['title'] = $blogArticle->name;
115 117
 					include ($config['views_folder']."d.blog.edit.html");
116 118
 				}
117 119
 			}
@@ -147,14 +149,14 @@ switch ($controller->splitted_url[1]) {
147 149
 					}
148 150
 				}
149 151
 
150
-				// Manage comment undeletion
151
-				if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="undelete_comment") {
152
+				// Manage comment restoration
153
+				if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="restore_comment") {
152 154
 					if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
153 155
 						$blogComment = new Kabano\BlogComment();
154 156
 						$blogComment->id = $controller->splitted_url[3];
155 157
 						$blogComment->populate();
156 158
 						if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author)
157
-							$blogComment->undelete();
159
+							$blogComment->restore();
158 160
 					}
159 161
 				}
160 162
 

+ 23
- 13
models/d.blog.php View File

@@ -82,41 +82,51 @@ class BlogArticle
82 82
 	/*****
83 83
 	** Edit a page by archiving the current one and inserting a new one ID
84 84
 	*****/
85
-/*	public function update() {
85
+	public function update() {
86 86
 		global $config;
87 87
 		global $user;
88
+
89
+		if($this->id == 0)
90
+			die("Cannot update entry without giving ID");
91
+
92
+		$oldId = $this->id;
88 93
 		
94
+		$this->version++;
95
+
89 96
 		$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
90 97
 			or die ("Could not connect to server\n");
91 98
 
92
-		// Archive previous article
93
-		$query = "UPDATE blog_articles SET archive = TRUE WHERE url = $1";
99
+		$query = "UPDATE contents SET is_archive = TRUE WHERE permalink = $1 AND type='blog'";
94 100
 
95 101
 		pg_prepare($con, "prepare1", $query) 
96 102
 			or die ("Cannot prepare statement\n");
97
-		$result = pg_execute($con, "prepare1", array($this->url))
103
+		$result = pg_execute($con, "prepare1", array($this->permalink))
98 104
 			or die ("Cannot execute statement\n");
99 105
 
100
-		// Publish the new one
101
-		$query = "INSERT INTO blog_articles (url, title, content, lastedit, archive, locale, author, comments) VALUES
102
-			($1, $2, $3, $4, FALSE, $5, $6, $7) RETURNING id";
106
+		$query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES
107
+			($1, $2, $3, $4, $5, $6, TRUE, FALSE, $7, 'blog', $8, $9) RETURNING id";
103 108
 
104 109
 		pg_prepare($con, "prepare2", $query) 
105 110
 			or die ("Cannot prepare statement\n");
106
-		$result = pg_execute($con, "prepare2", array($this->url, $this->title, $this->content, date('r'), $this->locale, $this->author, $this->comments))
111
+		$result = pg_execute($con, "prepare2", array($this->permalink, $this->version, $this->locale, $this->creation_date, date('r'), $this->author, $this->is_commentable, $this->name, $this->content))
107 112
 			or die ("Cannot execute statement\n");
108 113
 
109 114
 		$this->id = pg_fetch_assoc($result)['id'];
110 115
 
111
-		// Move all comments to the new one
112
-
113
-		$query = "UPDATE blog_comments bc SET article = $1 FROM blog_articles ba WHERE bc.article = ba.id AND ba.url = $2";
116
+		$query = "INSERT INTO content_contributors (content, contributor) SELECT $1, contributor FROM content_contributors AS old WHERE old.content = $2";
114 117
 
115 118
 		pg_prepare($con, "prepare3", $query) 
116 119
 			or die ("Cannot prepare statement\n");
117
-		$result = pg_execute($con, "prepare3", array($this->id, $this->url))
120
+		$result = pg_execute($con, "prepare3", array($this->id, $oldId))
118 121
 			or die ("Cannot execute statement\n");
119 122
 
123
+		$query = "INSERT INTO content_contributors (content, contributor) VALUES
124
+			($1, $2) ON CONFLICT (content, contributor) DO NOTHING";
125
+
126
+		pg_prepare($con, "prepare4", $query) 
127
+			or die ("Cannot prepare statement\n");
128
+		$result = pg_execute($con, "prepare4", array($this->id, $user->id))
129
+			or die ("Cannot execute statement\n");
120 130
 
121 131
 		pg_close($con);
122 132
 
@@ -124,7 +134,7 @@ class BlogArticle
124 134
 			date('r')." \t".$user->name." (".$user->id.") \tUPDATE \tEdit blog article '".$this->url."'\r\n",
125 135
 			3,
126 136
 			$config['logs_folder'].'blog.articles.log');
127
-	}*/
137
+	}
128 138
 
129 139
 	/*****
130 140
 	** Delete an article by archiving it

+ 2
- 2
views/d.blog.edit.html View File

@@ -34,8 +34,8 @@
34 34
 					<input type="text" value="<?=$blogArticle->permalink?>" name="permalink" id="permalink" placeholder="URL">
35 35
 				<? } ?>
36 36
 
37
-				<label for="comments">
38
-					<input type="checkbox" name="comments" id="comments" value="comments" 
37
+				<label for="is_commentable">
38
+					<input type="checkbox" name="is_commentable" id="is_commentable"
39 39
 					<? if($blogArticle->is_commentable == 't') { ?>
40 40
 						checked
41 41
 					<? } ?>

+ 1
- 1
views/d.blog.view.html View File

@@ -86,7 +86,7 @@
86 86
 									<span class="delete_link"><a href="<?=$config['rel_root_folder']?>blog/<?=$blogArticle->permalink?>/delete_comment/<?=$row->id?>"><i class="fas fa-trash"></i> Effacer le commentaire</a></span>
87 87
 								<? } ?>
88 88
 								<? if (($user->rankIsHigher("moderator") || $user->id == $row->author) && $row->archive == 't') { ?>
89
-									<span class="delete_link"><a href="<?=$config['rel_root_folder']?>blog/<?=$blogArticle->permalink?>/undelete_comment/<?=$row->id?>"><i class="fas fa-eye"></i> Réafficher le commentaire</a></span>
89
+									<span class="delete_link"><a href="<?=$config['rel_root_folder']?>blog/<?=$blogArticle->permalink?>/restore_comment/<?=$row->id?>"><i class="fas fa-eye"></i> Restaurer le commentaire</a></span>
90 90
 								<? } ?>
91 91
 							</div>
92 92
 							<div class="comment_content">

Loading…
Cancel
Save