-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblog.php
More file actions
executable file
·380 lines (312 loc) · 12.6 KB
/
blog.php
File metadata and controls
executable file
·380 lines (312 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?
require './article.php';
class blog {
//DONE Faire un Singleton et une classe ajaxrouter qui recupere le requete ajax, fait un getInstance sur le blog et recupere le content d'un article*/
//DONE finir l'enregistrement des commentaires
//DONE augementer le nombre de commentaire quand on en rajoute un V1
//DONE gerer les caracteres hmtl, quote et double quote dans les commentaires V1
//DONE vider le formulaire apres soumission V1
//DONE afficher le mail dans les commentaires.
//DONE Pouvoir "refermer" un commentaire avec une fleche vers le haut, et les reouvrir, etc.. V2
//==> Mettre un attribut first pour savoir s'il y a besoin de recharger ou pas l'article ou juste de le montrer (unhide)
//DONE gerer les DIV et autres tag html dans les articles V2 --> markdown
//GIVEUP gerer les DIV et autres tag html dans les commentaires V2 --> mardown
//DONE classer les articles par date avant de les afficher V2
//DONE enregistrer la date et l'heure des commmentaires, et l'afficher aussi V2
//DONE classer les commentaires par date avant de les afficher V2
//DONE faire un truc Années-->mois--> articles (commes le tag ) pour retrouver les articles chronologiquement
//DONE Afficher les tags (dans le titre et/ou à la fin de l'article ou du resume)
//TODO javascripter le formulaire de commentaire onfocus, onload pour cacher/afficher le commentaire par défaut
//TODO LATER afficher le nombre de commentaire avec le resume au début V2
//TODO Gere les filtre par date V2 (argument needed)
//TODO Gere le filtre par TAG V2 (argument needed)
//TODO si visible == true et date == null mettre la date du jour et l'enregistrer dans le fichier V2
//TODO V3 : faire un fork full XML->XSLT->HTLM avec tout les articles préchargés, et cachés
public static $_instance;
const article_rep ="articles/";
const com_rep ="comments/";
private $art_array = array();
private $tag_array = array();
private $date_array = array();
private $year_array = array();
private function __clone () {
}
private function sortByDate( article $a, article $b ) {
return strtotime($b->getWDate()) - strtotime($a->getWDate());
}
private function __construct(){
date_default_timezone_set('Europe/Paris');
$this->xml_parser = xml_parser_create();
xml_set_object ( $this->xml_parser, $this );
xml_set_element_handler($this->xml_parser, "startTagArticle", "endTagArticle");
xml_set_character_data_handler($this->xml_parser, "contentsArticle");
$dir = opendir(blog::article_rep);
$i=1;
while ($f = readdir($dir)) {
if(is_file(blog::article_rep.$f)) {
$article = new article();
$article->init(blog::article_rep.$f,blog::com_rep,$i++);
if ($article->isVisible() == 'true'){
array_push($this->art_array,$article);
foreach ($article->getTags() as $tag){
if(!in_array($tag,$this->tag_array))
array_push($this->tag_array,$tag);
}
array_push($this->date_array, $article->getWDate());
$year = date('Y', strtotime($article->getWDate()));
if (!(in_array($year, $this->year_array))) {
array_push($this->year_array, $year);
}
}
}
}
//sort blog article array by date
usort($this->art_array, array($this,"sortByDate"));
}
public static function getInstance () {
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function affiche(){
echo '<html><link rel="stylesheet" href="css/blog.css" type="text/css" /><body>';
echo $this->js();
echo '<DIV class="blog"><DIV class="global">';
foreach ($this->art_array as $article)
{
$article->affiche();
}
echo '</DIV>';
$self = $_SERVER['PHP_SELF'];
echo '<DIV class="tag"><UL>';
foreach ($this->tag_array as $tag){
echo '<LI>'. $tag .'</LI>';
}
echo '</UL></DIV>';
echo '<DIV class="year"><UL>';
foreach ($this->year_array as $year){
echo '<LI><span class="signe"></span><a class=\'yearmenu\' href='.$self. '?y='. $year .'>'.$year .'</a><UL>';
//foreach ($this->date_array as $date)
foreach ($this->art_array as $article){
$artdate = $article->getWDate();
$yearofdate = date('Y', strtotime($artdate));
if ($yearofdate == $year){
echo '<LI><a class=\'datemenu\' href='.$self. '?id='. $article->getId() .'> * '. $artdate . ' : ' . $article->getTitle() . '</a></LI>';
}
}
echo '</UL></LI>';
}
echo '</UL></DIV>';
echo '</DIV>';
echo '</DIV>';
echo '</body></html>';
}
function getArticleContent($id){
foreach ($this->art_array as $article)
{
if ($article->id == $id)
return $article->getArticleContent();
}
}
static function getSection(){
return $this->articleSection;
}
public function getContent($id)
{
foreach ($this->art_array as $article){
if ($article->getId() == $id)
return $article->getArticleContent();
}
return false;
}
public function getComSection($id){
foreach ($this->art_array as $article){
if ($article->getId() == $id)
return $article->getComSection();
}
}
public function getNbCom($id){
foreach ($this->art_array as $article){
if ($article->getId() == $id)
return $article->getNbCom();
}
}
public function formatCom($com,$pseudo,$mail){
return commentaire::formatCom($com,$pseudo,$mail);
}
public function getCom($id){
foreach ($this->art_array as $article){
if ($article->getId() == $id)
return $article->getCom();
}
}
public function enregistre_com($com, $pseudo, $mail, $id){
$article_trouve;
foreach ($this->art_array as $article)
{
if ($article->getId() == $id){
$article_trouve = $article;
break;
}
}
$article->enregistre_com($com,$pseudo,$mail);
}
function dd($date) {
return date("d/m/Y H:i:s",$date);
}
function js(){
return '<script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function loadXMLDoc(id)
{
var xmlhttp;
article = id;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//document.getElementById(id).innerHTML=xmlhttp.responseText;
var myobject ;
myobject = JSON.parse(xmlhttp.responseText);
$("#" + article).children(".content").append(myobject.content);
$("#" + article).children(".content").append(myobject.nb_com);
$("#" + article).children(".comment").append(myobject.com);
}
}
xmlhttp.open("GET","ajaxRouteur.php?id=" + id,true);
xmlhttp.send();
}
$(document).ready( function()
{
// $(".year a").next().hide();
$("a.yearmenu").next().hide();
$("span.signe").append("+ ");
$("span.signe").css("cursor", "pointer");
$("span.signe").click(function() {
//$(this).next().toggle(1000);
// switch the plus to a minus sign or vice-versa
var v = $(this).html().substring( 0, 1 );
if ( v == "+" ){
$(this).html( "-" + $(this).html().substring( 1 ) );
$(this).parent().children("a.yearmenu").next().show();
}
else if ( v == "-" ){
$(this).html( "+" + $(this).html().substring( 1 ) );
$(this).parent().children("a.yearmenu").next().hide();
}
});
$(".fleche a").click(function()
{
var open = $(this).parent().parent().parent().attr("state");
var first = $(this).parent().parent().parent().attr("first");
var Myid = $(this).parent().parent().parent().attr("id");
if (first == "false"){
// this aritcle was never open
if (open == "close"){
// this article is close, open it
loadXMLDoc(Myid);
//hide resume
$(this).parent().parent().parent().children().children(".resumeContent").hide();
//hide right arrow
//$(this).parent().parent().children(".fleche").children().remove();
$(this).parent().parent().children(".fleche").children("[sens=droit]").hide();
//unhide down arrow to fleche.
//$("[id=" + Myid +"]").children(".titre").children(".fleche").append(" <a href=\"#\"><img src=\"./ressource/fleche-bas.png\"/></a>");
$(this).parent().parent().children(".fleche").children("[sens=bas]").show();
$("[id=" + Myid +"]").attr("state","open");
$("[id=" + Myid +"]").attr("first","true");
}
else{
// this article is open, close it, hide it, show resume
// remove down arrow to fleche.
//$(this).parent().parent().children(".fleche").children().remove();
$(this).parent().parent().children(".fleche").children("[sens=bas]").hide();
//add right arrow
// $("[id=" + Myid +"]").children(".titre").children(".fleche").append(" <a href=\"#\"><img src=\"./ressource/fleche-droite.png\"/></a>");
$(this).parent().parent().children(".fleche").children("[sens=droit]").show();
//show resume
$(this).parent().parent().parent().children().children(".resumeContent").show();
$(this).parent().parent().parent().children(".content").show();
$(this).parent().parent().parent().children(".comment").show();
$("[id=" + Myid +"]").attr("state","close");
}
}
else{
//this article was open once upon a time,
if (open == "close"){
// this article is close, open it, hide resume
//hide resume
$(this).parent().parent().parent().children().children(".resumeContent").hide();
//remove right arrow
$(this).parent().parent().children(".fleche").children("[sens=droit]").hide();
//add down arrow to fleche.
$(this).parent().parent().children(".fleche").children("[sens=bas]").show();
$(this).parent().parent().parent().children(".content").show();
$(this).parent().parent().parent().children(".comment").show();
$("[id=" + Myid +"]").attr("state","open");
}
else{
// this article is open, close it, hide it, show resume
// remove down arrow to fleche.
$(this).parent().parent().children(".fleche").children("[sens=bas]").hide();
//add right arrow
// $("[id=" + Myid +"]").children(".titre").children(".fleche").append(" <a href=\"#\"><img src=\"./ressource/fleche-droite.png\"/></a>");
$(this).parent().parent().children(".fleche").children("[sens=droit]").show();
//show resume
$(this).parent().parent().parent().children().children(".resumeContent").show();
$(this).parent().parent().parent().children(".content").hide();
$(this).parent().parent().parent().children(".comment").hide();
$("[id=" + Myid +"]").attr("state","close");
}
}
});
});
function enregistre_com(com,pseudo,mail,id){
var xmlhttp;
if (!pseudo){
alert ("pseudo obligatoire!");
return;
}
if (!com){
alert ("commentaire obligatoire!");
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var myobject ;
myobject = JSON.parse(xmlhttp.responseText);
//dynamicilly update current coms.
//$("#" + myobject.id).parent().next("div").next("div").prepend(myobject.com );
//$("#" + myobject.id).closest(".article").find(".nb_com").replaceWith(myobject.nbcom);
$("#" + myobject.id).children(".comment").append(myobject.com );
$("#" + myobject.id).children(".content").children(".nb_com").replaceWith(myobject.nbcom);
}
}
xmlhttp.open("POST","ajaxRouteur.php",true);
var params = "id=" + id + "&com=" + encodeURIComponent(com) + "&pseudo=" + encodeURIComponent(pseudo)+ "&mail=" + encodeURIComponent(mail);
//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(params);
}
</script>';
}
}
?>