Link to the X.org production environement.
[wikifarm.git] / install / cookbook / faq.php
CommitLineData
b1b3c24c
DB
1<?php
2
3$ROSPatterns['/\\(:faq:\\)/e'] = 'CreateFAQ()';
4$HandleActions['faq'] = 'HandleFAQ';
5$HandleActions['faqAnswer'] = 'HandleFAQAnswer';
6
7Markup('faqNewQuestion','inline','/\\(:faqNewQuestion (\\w+) (\\w+):\\)/e',"newFAQ('$1', '$2')");
8Markup('faqNewAnswer','inline','/\\(:faqNewAnswer (\\w+) (\\w+) (\\w+):\\)/e',"newFAQAnswer('$1', '$2', '$3')");
9Markup('faqList','inline','/\\(:faqList (\\w+):\\)/','');
10
11function CreateFAQ() {
12 $idfaq = substr(md5(rand()),0,4);
13 return "\n".
14 '!Foire aux questions'."\n".
15 '(:faqList '.$idfaq.':)'."\n".
16 '(:if auth edit:)(:faqNewQuestion '.$idfaq.' 1:)(:if:)';
17}
18
19function newFAQ($idfaq, $numquestion) {
20 return Keep('<h3>Poser une nouvelle question :</h3>
21 <form method="post">
22 <input type="hidden" name="action" value="faq"/>
23 <input type="hidden" name="faqId" value="'.$idfaq.'"/>
24 <input type="hidden" name="numQuestion" value="'.$numquestion.'"/>
25 <input type="text" name="question" size="80"/>
26 </form>');
27}
28
29function newFAQAnswer($idfaq, $numquestion, $numanswer) {
30 $idfaqanswer = 'faqAnswer-'.$idfaq.'-'.$numquestion.'-'.$numanswer;
31 return Keep('<blockquote>
32 <input type="button" value="Répondre" onclick="
33 this.style.display=\'none\';
34 var f = document.getElementById(\''.$idfaqanswer.'\');
35 f.style.display=\'\';
36 f.answer.focus()"/>
37 <form method="post" id="'.$idfaqanswer.'" style="display:none">
38 <input type="hidden" name="action" value="faqAnswer"/>
39 <input type="hidden" name="faqId" value="'.$idfaq.'"/>
40 <input type="hidden" name="numQuestion" value="'.$numquestion.'"/>
41 <input type="hidden" name="numAnswer" value="'.$numanswer.'"/>
42 <textarea name="answer" rows="3" cols="80"></textarea>
43 <br/>
44 <input type="submit" value="Envoyer la réponse"/>
45 </form>
46 </blockquote>');
47}
48
49function HandleFAQ() {
50 global $pagename, $CurrentTime, $Author;
51 Lock(2);
52 if (isset($_REQUEST['question']) && $_REQUEST['question'] &&
53 ($page = RetrieveAuthPage($pagename, 'edit', true))) {
54 $idfaq = stripmagic($_REQUEST['faqId']);
55 $question = stripmagic($_REQUEST['question']);
56 $numquestion = stripmagic($_REQUEST['numQuestion']);
57 $titre = $question;
58 if (strlen($titre) > 30) {
59 $titre = substr($question, 0, 50).'...';
60 $question = $titre."\n".$question;
61 }
62 $page['text'] = preg_replace(
63 ',(\(:faqList '.$idfaq.':\)),',
64 "\n".'*[[{$FullName}#faq'.$idfaq.'-'.$numquestion.' | '.$titre.']]$1',
65 $page['text']);
66 $page['text'] = preg_replace(
67 ',(\(:if auth edit:\)\(:faqNewQuestion '.$idfaq.') '.$numquestion.':\),',
68 '!![[#faq'.$idfaq.'-'.$numquestion.']]Q : '.$question.'\\\\\\\\'."\n".
69 '[-\'\'question posée le '.$CurrentTime.($Author?(' par [[~ '.$Author.' ]]\'\'-]'):'')."\n".
70 '(:if auth edit:)(:faqNewAnswer '.$idfaq.' '.$numquestion.' 1:)(:if:)'."\n".
71 '$1 '.($numquestion + 1).':)',
72 $page['text']);
73 WritePage($pagename,$page);
74 Redirect($pagename);
75 }
76 Lock(0);
77 return "";
78}
79
80function HandleFAQAnswer() {
81 global $pagename, $CurrentTime, $Author;
82 Lock(2);
83 if (isset($_REQUEST['answer']) && $_REQUEST['answer'] &&
84 ($page = RetrieveAuthPage($pagename, 'edit', true))) {
85 $idfaq = stripmagic($_REQUEST['faqId']);
86 $answer = str_replace("\n", "\n->", stripmagic($_REQUEST['answer']));
87 $numanswer = stripmagic($_REQUEST['numAnswer']);
88 $numquestion = stripmagic($_REQUEST['numQuestion']);
89 $page['text'] = preg_replace(
90 ',(\(:if auth edit:\)\(:faqNewAnswer '.$idfaq.' '.$numquestion.') '.$numanswer.':\),',
91 '->[[#faq'.$idfaq.'-'.$numquestion.'-'.$numanswer.']]R : '.$answer."\n".
92 '->[-\'\'réponse le '.$CurrentTime.($Author?(' par [[~ '.$Author.' ]]\'\'-]'):'')."\n".
93 '$1 '.($numanswer + 1).':)',
94 $page['text']);
95 WritePage($pagename,$page);
96 Redirect($pagename);
97 }
98 Lock(0);
99 return "";
100}
101
102?>