-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajaxRouteur.php
executable file
·60 lines (47 loc) · 1.34 KB
/
ajaxRouteur.php
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
<?
require './blog.php';
set_include_path('./ressource/php/markdown');
spl_autoload_register(function($class){
require preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php';
});
use \Michelf\Markdown;
$blog = blog::getInstance();
//print_r($_REQUEST);
if ($_SERVER['REQUEST_METHOD']== 'POST'){
if (!empty($_POST['com']) || !empty($_POST['id'])){
$com=$_POST['com'];
$id=$_POST['id'];
$mail="";
$pseudo="";
$nbcom;
if (!empty($_POST['pseudo']) )
$pseudo = $_POST['pseudo'];
if (!empty($_POST['mail']))
$mail = $_POST['mail'];
$comm= $blog->formatCom($com,$pseudo,$mail);
// on enregistre le commentaire dans le fichier
$blog->enregistre_com($com,$pseudo,$mail,$id);
$nbcom = $blog->getNbCom($id);
$json_array = array('com'=>$comm,'id'=>$id,'nbcom'=>$nbcom);
$json_string = json_encode($json_array);
echo $json_string;
}
}
else
{
if (!empty($_GET['id'])){
$id= $_GET['id'];
//$content = $blog->getContent($id);
$content = Markdown::defaultTransform($blog->getContent($id));
$nb_com = $blog->getComSection($id);
$com = $blog->getCom($id);
if ($content != false){
//echo $content;
$json_array = array('content'=>$content,'nb_com'=>$nb_com,'com'=>$com);
//$json_array = array('content'=>$content);
$json_string = json_encode($json_array);
echo $json_string;
}
}
}
?>