Mercurial > defr > DualBlog
comparison admin_xml.php @ 0:629389204276
Import initial
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Sat, 20 Oct 2007 14:15:10 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:629389204276 |
---|---|
1 <?php | |
2 require("classes.php"); | |
3 | |
4 $Req = new Requete(); | |
5 $Data = new DataAccess; | |
6 | |
7 header("Content-Type: application/xml; charset=utf-8"); | |
8 $doc = new DOMDocument('1.0', 'utf-8'); | |
9 $root = $doc->createElementNS('http://defr.org/2005/blog-post', 'post'); | |
10 $doc->appendChild($root); | |
11 | |
12 $mode = $Req->get('mode', 'GET', 'get'); | |
13 $type = $Req->get('type', 'GET', 'post'); | |
14 $id = $Req->get('id'); | |
15 | |
16 $root->appendChild($doc->createElement('id', $id)); | |
17 $root->appendChild(DOMUtils::createCDATAWrapper($doc, 'debug', var_export($Req, true))); | |
18 switch($mode . '-' . $type) | |
19 { | |
20 case 'edit-post': | |
21 $nvTitre = $Req->get('title'); | |
22 $nvContenu = $Req->get('content'); | |
23 $nvMood = $Req->get('mood'); | |
24 $Data->Query | |
25 (" | |
26 UPDATE Mess | |
27 SET Titre='{$nvTitre}', Message='{$nvContenu}', Emot='{$nvMood}' | |
28 WHERE num_mess={$id} | |
29 "); | |
30 // Récuperation des nouveaux tags à appliquer | |
31 $arTags = TextUtils::splitTags($Req->get('tags')); | |
32 // Récuperation des anciens tags | |
33 $Data->Query | |
34 (" | |
35 SELECT T.idTag, T.Tag | |
36 FROM Lien_Tags_Posts L | |
37 LEFT JOIN Tags T ON L.idTag = T.idTag | |
38 WHERE L.idMess = {$id} | |
39 "); | |
40 | |
41 $oldTags = array(); | |
42 while(0 !== ($row = $Data->GetRow())) | |
43 { | |
44 $oldTags[] = $row['Tag']; | |
45 $mapOld[$row['Tag']] = $row['idTag']; | |
46 } | |
47 // Calcul des différences | |
48 $tagsSupprimes = array_diff($oldTags, $arTags); | |
49 $tagsAjoutes = array_diff($arTags, $oldTags); | |
50 // Suppression des tags non affectés | |
51 if(is_array($tagsSupprimes)) | |
52 { | |
53 foreach($tagsSupprimes as $tagSuppr) | |
54 { | |
55 $supprIDs .= $mapOld[$tagSuppr] . ','; | |
56 } | |
57 $Data->Query | |
58 (" | |
59 DELETE FROM Lien_Tags_Posts | |
60 WHERE idMess={$id} AND idTag IN ({$supprIDs}0) | |
61 "); | |
62 } | |
63 // Ajout des tags ajoutés | |
64 if(is_array($tagsAjoutes)) | |
65 { | |
66 foreach($tagsAjoutes as $tagAj) | |
67 { | |
68 $n = $Data->Query("SELECT idTag FROM Tags WHERE Tag='{$tagAj}'"); | |
69 if($n == 0) | |
70 { | |
71 // Si le tag n'existe pas, on le crée | |
72 $Data->Query("INSERT INTO Tags SET Tag='{$tagAj}'"); | |
73 $Data->Query("SELECT idTag FROM Tags WHERE Tag='{$tagAj}'"); | |
74 } | |
75 $row = $Data->GetRow(); | |
76 $Data->Query | |
77 (" | |
78 INSERT INTO Lien_Tags_Posts | |
79 SET idMess={$id}, idTag={$row['idTag']} | |
80 "); | |
81 } | |
82 } | |
83 case 'get-post': | |
84 $Data->Query | |
85 (" | |
86 SELECT Titre, Message, Emot | |
87 FROM Mess | |
88 WHERE num_mess={$id} | |
89 "); | |
90 $row = $Data->GetRow(); | |
91 $titre_CDATA = $doc->createCDATASection($row['Titre']); | |
92 $root->appendChild(DOMUtils::createCDATAWrapper($doc, 'titre', $row['Titre'])); | |
93 $root->appendChild(DOMUtils::createCDATAWrapper($doc, 'contenu', $row['Message'])); | |
94 $root->appendChild($doc->createElement('mood', $row['Emot'])); | |
95 // Obtention des tags | |
96 $Data->Query | |
97 (" | |
98 SELECT T.idTag, T.Tag | |
99 FROM Lien_Tags_Posts L | |
100 LEFT JOIN Tags T ON L.idTag = T.idTag | |
101 WHERE L.idMess = {$id} | |
102 "); | |
103 while(0 !== ($row = $Data->GetRow())) | |
104 $root->appendChild($doc->createElement('tag', $row['Tag'])); | |
105 break; | |
106 case 'edit-brouillon': | |
107 $nvTitre = $Req->get('title'); | |
108 $nvContenu = $Req->get('content'); | |
109 $Data->Query | |
110 (" | |
111 UPDATE Brouillons | |
112 SET Titre='{$nvTitre}', Contenu='{$nvContenu}' | |
113 WHERE id_brouillon={$id} | |
114 "); | |
115 case 'get-brouillon': | |
116 $Data->Query | |
117 (" | |
118 SELECT Titre, Contenu | |
119 FROM Brouillons | |
120 WHERE id_brouillon={$id} | |
121 "); | |
122 $row = $Data->GetRow(); | |
123 $root->appendChild(DOMUtils::createCDATAWrapper($doc, 'titre', $row['Titre'])); | |
124 $root->appendChild(DOMUtils::createCDATAWrapper($doc, 'contenu', $row['Contenu'])); | |
125 break; | |
126 } | |
127 echo $doc->saveXML(); | |
128 ?> |