*/ //fix for Opera XMLHttpRequests if(!count($_POST) && $HTTP_RAW_POST_DATA){ parse_str($HTTP_RAW_POST_DATA, $_POST); } if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/common.php'); require_once(DOKU_INC.'inc/auth.php'); require_once(DOKU_INC.'inc/html.php'); define(SHOW_GRAVATAR, false); define(BASE_URL, preg_replace('!(.+)(/.+){3}!', '\\1/', DOKU_BASE)); session_write_close(); header('Content-Type: text/html; charset=UTF-8'); //call the requested function $call = 'ajax_'.$_REQUEST['call']; if ($call == '') { $call = 'ajax_'.$_REQUEST['call']; } if(function_exists($call)){ $call(); }else{ print "The called function '".htmlspecialchars($call)."' does not exist!"; } function _getChatHtml($pageFN, $ltime = 0, $mtime = 0) { if (!@file_exists($pageFN)) { return; print "1,"; } // echo '        '; $file = trim(io_readFile($pageFN)); if ($file == ' ') { $file = ''; } $html = ""; // $html .= "1,"; $lines = explode("\n----\n", $file."\n"); $patterns = array( '!(\[\[((http|https|ftp)://[^\]\|]+)\]\])!', '!(\[\[((http|https|ftp)://[^\]\|]+)\|([^\]]+)\]\])!', '!(\[\[([^\]\|]+)\|([^\]]+)\]\])!', '!(\[\[([^\]\|]+)\]\])!', '!(\s)((http|https|ftp)://[^\s\n\r]+)!', '!\*{2}([^\*]+)\*{2}!', '!(\s)/{2}([^/]+)/{2}(\s)!', '!(\s)_{2}([^_]+)_{2}(\s)!' ); $replaces = array( '\\2', '\\4', '\\3', '\\2', '\\1\\2', '\\1', '\\1\\2\\3', '\\1\\2\\3' ); $smileys = getSmileys(); foreach ($smileys as $key=>$value) { $key_escaped = preg_replace( array("/\\\\/","/\*/",'/\&/','/\(/','/\)/','/\[/','/\]/','/\|/','/\=/','!/!','/\?/'), array('\\\\\\','\\*','\\&','\\(','\\)','\\[','\\]','\\|','\\=','\\/','\\?'), $key); // echo $key_escaped.'
'; // echo $value; $patterns[] = '@'.$key_escaped.'@'; $files = preg_split('/\|/', $value); if (count($files) > 1) { $file = $files[mt_rand(0,count($files)-1)]; } else { $file = $files[0]; } $replaces[] = ''.str_replace(''; } // print implode('|', array_keys($smileys)); if (true == SHOW_GRAVATAR) { @require_once(DOKU_INC.'lib/plugins/gravatar/syntax.php'); if (true == SHOW_GRAVATAR && class_exists('syntax_plugin_gravatar')) { $gravatar = true; } } $color = count($lines) % 2 == 0 ? 0 : 1; for ($i = 0; $i < count($lines); $i++) { if (trim($lines[$i]) == '') { continue; } preg_match('/\(([^\)]+)\)[\s]+([^:]+):[\s]+(.+)/', $lines[$i], $parts); if ($parts[1]*1 != 0 && $parts[1]*1 <= $ltime) { // print $ltime.'
'; // print $parts[1].'
'; break; } $uinfo = explode('|', $parts[2]); $html .= '
('.$datetime.'):
'; $html .= preg_replace($patterns, $replaces, ' '.$parts[3].' '); if ($i+1 < count($lines)) { $html .= '
';//'
'; } else { $html .= '
'; } $html .= '
'; } return $html; } /** * Get number of new comments * * @author Pavel Vitis */ function ajax_check() { global $conf; global $lang; $pageId = cleanID($_POST['pageId']); if(empty($pageId)) { return; } $ltime = (int)$_POST['time']; $pageFN = wikiFN($pageId); $mtime = @filemtime($pageFN); if ($ltime == 0 || $mtime > $ltime) { echo "1"; } } /** * Get new comments * * @author Pavel Vitis */ function ajax_checkAndGet() { global $conf; global $lang; $pageId = cleanID($_POST['pageId']); if(empty($pageId)) { return; } if ($conf['useacl'] && auth_quickAclCheck($pageId) < AUTH_READ) { print "\n"; print "

Not sufficient user rights. Please re-login to see the messages.
". "If that does not work for you from some reason, clear your browser cookies and then login again:

". "

IE: Tools->Internet options...->Delete cookies...
". "Mozilla/Firefox: Tools->Options...->Privacy->Cookies->Clear cookies now...

"; return; } $pageFN = wikiFN($pageId); $mtime = @filemtime($pageFN); $ltime = (int)$_POST['time']; // echo $time ." - " . $pageId; // echo "
$mtime"; if ($ltime == 0 || $mtime > $ltime) { print "\n"; print _getChatHtml($pageFN, $ltime, $mtime); print ' '; } } function ajax_send(){ global $conf; global $auth; global $lang; // check pageid validity $pageId = cleanID($_POST['pageId']); if(empty($pageId)) { return; } $ltime = (int)$_POST['time']; if ($ltime > 0) { while (time() - $ltime < 1) { sleep(5); } } // modified now $mtime = time(); // set modified header $html = "\n"; // check user rights if ($conf['useacl'] && auth_quickAclCheck($pageId) < AUTH_EDIT) { // and append warning if not possible to send messages $html .= "

Insufficient user rights. Please re-login to be able to send the messages.

"; } else { // $ltime = (int)$_POST['time']; $user = cleanUser($_POST['user']); $message = cleanMessage($_POST['msg']); while (checklock($pageId)) { sleep(50); } lock($pageId); $pageFN = wikiFN($pageId); $file = trim(@io_readFile($pageFN)); if ($file == ' ') { $file = ''; } $udata = $auth->getUserData($user); $line = "(".time().") ".$user; if (!empty($udata['mail'])) { $line .= "|".$udata['mail']; } if (!empty($udata['name'])) { $line .= "|".$udata['name']; } $line .= ": ".htmlspecialchars($message); $file = $line."\n----\n".$file."\n"; saveWikiText($pageId, $file, "Message added", true); unlock($pageId); } print $html . _getChatHtml($pageFN, $ltime, $mtime); } function ajax_clear(){ global $conf; global $lang; $ltime = $_POST['time']; $ltime = (int)$ltime; $pageId = $_POST['pageId']; $user = cleanUser($_POST['user']); $message = $_POST['msg']; $pageFN = wikiFN($pageId); if (!@file_exists($pageFN)) { return; } while (checklock($pageId)) { usleep(50); } lock($pageId); saveWikiText($pageId, ' ', "Messages cleared", true); // @touch($pageFN); unlock($pageId); print ' '; } function cleanUser($user) { global $conf; $user = preg_replace('/[^ .,a-zA-Z0-9_\-]/i', '', $user); $user = substr($user, 0, 40); return $user; } function cleanMessage($msg) { global $conf; $maxmsgsize = (int) $conf['chat']['max-message-size']; if ($maxmsgsize <= 0) { $maxmsgsize = 1024; } if ($maxmsgsize > 4*1024) { $maxmsgsize = 4*1024; } if (strlen($msg) > $maxmsgsize) { $msg = substr($msg, 0, $maxmsgsize); } return $msg; } //Setup VIM: ex: et ts=2 enc=utf-8 : ?>