3 $ROSPatterns['/\\(:chat(\\s+(.*))?:\\)/e'] = "CreateChat('$2')";
4 $HandleActions['chat'] = 'HandleChat';
6 Markup('chatBegin','inline','/\\(:chatBegin (\\w+):\\)/','');
7 Markup('chatEnd','inline','/\\(:chatEnd (\\w+):\\)/','<br/>');
8 Markup('chatNext','inline','/\\(:chatNext:\\)/','<br/>');
9 Markup('chatTalk','inline','/\\(:chatTalk (\\w+) (\\w+):\\)/e',"ChatTalk('$1', '$2')");
11 function CreateChat($size = 10) {
12 $idchat = substr(md5(rand()),0,4);
13 if (!$size) { $size = 10; }
15 '(:chatBegin '.$idchat.':)'."\n".
16 '(:chatEnd '.$idchat.':)'."\n\n".
17 '(:if auth edit:)(:chatTalk '.$idchat.' '.$size.':)(:if:)';
20 function ChatTalk($idchat, $size = 10) {
22 '<form method="post" id="chat-'.$idchat.'">
23 <input type="text" name="postchat" size="50"/>
24 <input type="hidden" name="chatId" value="'.$idchat.'"/>
25 <input type="hidden" name="size" value="'.$size.'"/>
26 <input type="hidden" name="action" value="chat"/>
28 <script type="text/javascript">
29 document.getElementById("chat-'.$idchat.'").postchat.focus();
33 function HandleChat() {
34 global $pagename, $CurrentTime, $Author;
36 if (isset($_REQUEST['postchat']) && $_REQUEST['postchat'] &&
37 ($page = RetrieveAuthPage($pagename, 'edit', true
))) {
38 $postchat = stripmagic($_REQUEST['postchat']);
39 $idchat = stripmagic($_REQUEST['chatId']);
40 $size = stripmagic($_REQUEST['size']);
42 $origine = array('(:chatNext:)');
43 $destination = array('');
44 $chatsyntax = RetrieveAuthPage('Site.ChatSyntax', 'read', false
);
46 $chatsyntax = explode("\n",$chatsyntax['text']);
47 foreach($chatsyntax as $s) if (preg_match('/^(.*) => (.*)$/', trim($s), $matches)) {
48 $origine[] = $matches[1];
49 $destination[] = $matches[2];
53 $newchat = $CurrentTime.' [[~'.$Author.']] : '.str_replace($origine, $destination, $postchat);
55 $talkpos = strpos($page['text'], '(:chatTalk '.$idchat.' ');
56 $beginpos = strpos($page['text'], '(:chatBegin '.$idchat.':)');
57 $endpos = strpos($page['text'], '(:chatEnd '.$idchat.':)');
59 $beginpos +
= strlen('(:chatBegin '.$idchat.':)');
60 $lignes = explode('(:chatNext:)',substr($page['text'], $beginpos, $endpos - $beginpos));
62 if ($talkpos > $beginpos) {
63 $afac = count($lignes) - $size - 1;
65 for ($i = 0; $i < $afac; $i++
) {
69 $nouvelleslignes = array($newchat);
70 for ($i = 0; $i < count($lignes) && $i < $size - 1; $i++
) {
71 $nouvelleslignes[] = $lignes[$i];
73 $lignes = $nouvelleslignes;
75 $chatcontent = implode('(:chatNext:)', $lignes);
76 $page['text'] = substr($page['text'],0,$beginpos).$chatcontent.substr($page['text'],$endpos);
77 WritePage($pagename,$page);
85 global $pagename, $Author, $CurrentTime;
86 if (isset($_REQUEST['postchat']) && $_REQUEST['postchat']) {
88 $page = RetrieveAuthPage($pagename, 'edit', false
);
97 $poschat = strpos($page['text'],'(:beginchat:)');
98 $finchat = strpos($page['text'],'(:chat');
99 if ($poschat === false
) {
101 $page['text'] = substr($page['text'],0,$poschat).'(:beginchat:)'.substr($page['text'],$poschat);
102 $finchat +
= strlen('(:beginchat:)');
104 $poschat +
= strlen('(:beginchat:)');
106 $avantchat = substr($page['text'],0,$poschat);
107 $chatcontent = substr($page['text'], $poschat, $finchat - $poschat);
108 $aprechat = substr($page['text'],$finchat);
110 $lignes = explode("\n\n",$chatcontent);
111 $page['text'] = $avantchat.implode("\n\n", $lignes)."\n\n".$CurrentTime.' [[~'.$Author.']] : '.$newchat.$aprechat;
112 WritePage($pagename,$page);
117 $page = RetrieveAuthPage($pagename, 'edit', false
);
121 return '<form method="post"><input type="text" name="postchat" size="50"/></form><script type="text/javascript">document.getElementsByName("postchat")[0].focus();</script>';