Viewing file: chat.php (7.82 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
/** * Ajax Chat plugin code * Some functions borrowed from Esther Brunner's Discussion plugin. * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Pavel Vitis <pavel [dot] vitis [at] seznam [dot] cz> * @author Dave Lawson <dlawson@masterytech.com> * @author Esther Brunner <esther@kaffeehaus.ch> */
global $ID; global $REV; global $ACT;
if (chat_plugin::isChatID($ID) && file_exists(wikiFN($ID))) { session_write_close(); if ($ACT == 'show') { print "Redirecting...<script type='text/javascript'>document.location='".wl(chat_plugin::stripChatNS($ID), true)."#chat';</script>"; exit(); } }
class chat_plugin {
/** * @author Esther Brunner <esther@kaffeehaus.ch> * @author Pavel Vitis <pavel [dot] vitis [at] seznam [dot] cz> */ function chatHtml() { global $ID; global $ACT; global $conf; global $lang;
$dID = chat_plugin::addChatNS($ID);
// check mode and existing page if (($ACT !== 'show' && $ACT !== 'export_xhtml') || !file_exists(wikiFN($ID))) { return ''; }
// check for existing chat page if automatic is disabled. if (!$conf['chat']['automatic'] && !file_exists(wikiFN($dID))) return '';
// check for existing chat page. if (!file_exists(wikiFN($dID))) { if ($conf['chat']['automatic']) { // automatic mode - don't try to recreate a deleted discussion page. $revs = getRevisions($dID); if (count($revs) != 0) return ''; } else { // manual mode - don't create non-existing discussion pages. return ''; } }
$html = '';
if (!$_REQUEST['nosound'] && $conf['chat']['audio-notify']) { $html .= "<applet code=\"ChatNotify.class\" ". "codebase=\"".DOKU_BASE."lib/plugins/chat/\" ". "id=\"newmsg_sound\" width=\"1\" height=\"1\" hspace=\"0\" vspace=\"0\" style=\"height:0px;\">". "<param name=\"audio\" value=\"newmsg\"></applet>\n"; } else { } $html .= '<div class="chat">'; // $html .= '<h2 style="margin-left:0px !important;">'.$lang['chat_title'].'</h2>';
if ($conf['chat']['recentfirst']) { $html .= chat_plugin::chatFormHtml($dID); $html .= chat_plugin::chatPageHtml($dID); } else { $html .= chat_plugin::chatPageHtml($dID); $html .= chat_plugin::chatFormHtml($dID); } $html .= '</div><!-- chat -->';
return $html; }
/** * Is specified page ID in a chat namespace? * * @author Dave Lawson <dlawson@masterytech.com> */ function isChatID($ID) { global $conf; $dNS = $conf['chat']['namespace']; $pID = noNS($ID); return strpos($ID, "$dNS:$pID") !== false; }
/** * Convert a chat page ID to a normal page ID. * * @author Dave Lawson <dlawson@masterytech.com> */ function stripChatNS($ID) { global $conf; $dNS = $conf['chat']['namespace']; return str_replace("$dNS:", '', $ID); }
/** * Convert a normal page ID to a chat page ID. * * @author Dave Lawson <dlawson@masterytech.com> */ function addChatNS($ID) { global $conf; $dNS = $conf['chat']['namespace']; if (chat_plugin::isChatID($ID)) { return $ID; } $dID = getNS($ID); if ($dID !== '') { $dID .= ':'; } $dID .= $dNS.':'.noNS($ID); return $dID; }
/** * Display existing comments if availaible * * @author Esther Brunner <esther@kaffeehaus.ch> */ function chatPageHtml($dID) { global $ID;
$html = '';
$dFN = wikiFN($dID); if (file_exists($dFN)) { $html .= '<div id="chatListSentMessage" class="chat-line chat-message-sending" style="display:none;height:0px;"></div>'; $html .= '<div id="chatList" class="chat-list">'; $html .= '<em>Loading messages...</em>'; // $html .= html_secedit(p_cached_xhtml($dFN), false); $html .= "</div>"; }
return $html; }
/** * @author Pavel Vitis <pavel [dot] vitis [at] seznam [dot] cz> */ function chatFormHtml($chatID) { global $DATE; global $INFO; global $USERINFO; global $PRE; global $SUF; global $SUM; global $lang; global $conf; global $auth; global $ID; global $commentId;
$maxmsgsize = 1 * $conf['chat']['max-message-size']; if ($maxmsgsize <= 0) { $maxmsgsize = 256; } if ($masmsgsize > 2*1024) { $maxmsgsize = 2*1024; }
if ($conf['useacl'] && $_SERVER['REMOTE_USER'] /*&& auth_quickaclcheck($dID) >= AUTH_EDIT*/) { $anonymous = false; } else { $anonymous = true; }
// only if we are NOT in a comment page itself if (chat_plugin::isChatID($ID)) { $mainID = chat_plugin::stripChatNS($ID); echo '<hr noshade="noshade" size="1" />'; echo '<div class="level1">'.html_wikilink($mainID,$lang['comments_back'].' '.$mainID).'</div>'; return true; }
// guest comments must be allowed or you need to be logged in if (!$conf['chat']['allowguests'] && $_SERVER['REMOTE_USER'] == '') return '';
$refreshURL = wl(chat_plugin::stripChatNS($ID), 'rid='.time(), true).'#chat';
if ($anonymous) { $user = $_COOKIE['chatName']; if (empty($user)) { $user = "guest".date(time(),'hms'); } } else { $user = $INFO['userinfo']['name']; } $volume = (int)$_COOKIE['chatVolume']; if ($volume < 0) { $volume = 0; } if ($volume > 4) { $volume = 4; }
//echo $_SERVER['REMOTE_USER']; $html = '';
$html .= '<div class="chat-form">'. '<form action="" method="post" id="chatForm" name="chatForm" onsubmit="return false;">'. '<input type="hidden" name="pageId" value="'.$chatID.'" />'; if ($conf['useacl'] && auth_quickaclcheck($chatID) >= AUTH_EDIT) { $html .= ($anonymous ? '<input type="text" name="user" id="user" maxlength="30" autocomplete="off" value="'.$user.'" class="edit chat" style="width:100px !important;margin-right:5px;" />' : '<input type="hidden" name="user" value="'.$user.'" />' ). '<input type="text" name="chatMessage" id="chatMessage" maxlength="'.$maxmsgsize.'" class="edit chat" autocomplete="off" style="margin-right:2px;" />';
$html .= '<input type="submit" value="Send" class="button" />'; } if ($conf['useacl'] && $_SERVER['REMOTE_USER'] && auth_quickaclcheck($ID) >= AUTH_EDIT) { $html .= '<input type="button" name="clearButton" value="Clear messages" class="button" />'; } $html .= '</form>';
if (!$_REQUEST['nosound'] && $conf['chat']['audio-notify']) { $html .= '<br /><div style="display:inline;padding-top:0px;margin-top:0px;margin-left:0px;padding-left:0px;vertical-align:middle;">'. '<div title="Set notify volume" style="display:inline;cursor:pointer;">'. '<img id="chatVolumeIcon" src="'.DOKU_BASE.'lib/images/blank.gif" style="cursor:pointer;width:0px;margin-top:2px;" border="0" onclick="chatToggleVolume();" alt="" />'. '</div>'. '<script type="text/javascript">'. 'var vol = getCookie("chatVolume")*1;'. 'chatSetVolume(vol,true,false);'. '</script></div>'; } else { $html .= "<br />"; }
if ($conf['chat']['show-progress']) { $html .= '<form action="" id="chat-info-pad" onsubmit="return false;" style="display:inline;">'. '<input class="edit" style="border:0px;" type="text" name="ajaxActive" id="ajaxActive" />'. '<input class="edit" style="border:0px;" type="text" name="ajaxRefreshInterval" id="ajaxRefreshInterval" />'. '<input class="edit" style="border:0px;width:90pt;" type="text" name="ajaxLastStatus" id="ajaxLastStatus" />'. '<input class="edit" style="border:0px;width:90pt;" type="text" name="requestTimerInfo" id="requestTimerInfo" />'. '<input class="edit" style="border:0px;width:90pt;" type="text" name="ajaxNextCheck" id="ajaxNextCheck" />'. '</form>'; }
$html .= '</div>'; return $html; } }
//Setup VIM: ex: et ts=4 enc=utf-8 :
|