Ticket #1629: licqweb-history.patch

File licqweb-history.patch, 16.1 kB (added by cuchac, 5 months ago)
  • viewHistory.php

     
     1<? 
     2/* 
     3 * licqweb. Copyright 2005, Philip Nelson 
     4 * 
     5 * This file is part of licqweb. 
     6 * 
     7 * licqweb is free software; you can redistribute it and/or modify 
     8 * it under the terms of the GNU General Public License as published by 
     9 * the Free Software Foundation; either version 2 of the License, or 
     10 * (at your option) any later version. 
     11 * 
     12 * licqweb is distributed in the hope that it will be useful, 
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     15 * GNU General Public License for more details. 
     16 * 
     17 * You should have received a copy of the GNU General Public License 
     18 * along with licqweb; if not, write to the Free Software 
     19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
     20 */ 
     21require_once('config.php'); 
     22require_once('rms.php'); 
     23 
     24session_start(); 
     25$uin = $_SESSION['uin']; 
     26$password = $_SESSION['password']; 
     27session_write_close(); 
     28 
     29if (!rmsLogin("$uin\r\n", "$password\r\n")) { 
     30    header('Content-Type: text/xml'); 
     31    echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"; 
     32    echo "<response><method>loginFailed</method><result>Couldn't log in to rms plugin!</result></response>"; 
     33    exit; 
     34} 
     35 
     36$messagesXML=""; 
     37 
     38$messages = rmsViewHistory($_GET['id'], $_GET['pp'], $_GET["lenght"], $_GET["offset"]); 
     39foreach ($messages as $message) 
     40    $messagesXML .= "<message>" . xmlentities($message['msg']) . "</message><from>".$message['from']."</from><time>" . $message['time'] . "</time>"; 
     41 
     42 
     43header('Content-Type: text/xml'); 
     44echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"; 
     45echo " 
     46<response> 
     47  <method>viewHistory</method> 
     48  <result><id>" . $_GET['id'] . "</id><pp>" . $_GET['pp'] . "</pp><messages>$messagesXML</messages></result> 
     49</response> 
     50"; 
     51?> 
  • rms.php

    Property changes on: viewHistory.php
    ___________________________________________________________________
    Name: svn:executable
       + *
    
     
    259259function xmlentities ($string) { 
    260260   return str_replace (array('&', '"', "'", '<', '>'), array ('&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;'), $string); 
    261261} 
     262 
     263function rmsViewHistory($id, $pp, $lenght = 10, $offset = 0) { 
     264    global $sock; 
     265    $result = array(); 
     266     
     267    $cmd = "HISTORY " . $id . "." . $pp . " " . $lenght . " " . $offset . "\r\n"; 
     268    sendData($cmd); 
     269 
     270    $packet = socket_read($sock, 1024, PHP_NORMAL_READ); 
     271    if (substr($packet, 0, 3) >= 400) { 
     272        return false; 
     273    } 
     274     
     275   // kses input filtering 
     276    $allowed = array('b' => array(), 
     277                     'i' => array(), 
     278                     'a' => array('href' => 1, 'title' => 1), 
     279                     'p' => array('align' => 1), 
     280                     'br' => array(), 
     281                     'font' => array('size' => 1, 'color' => 1, 'face' => 1) 
     282                    ); 
     283     
     284    while(!preg_match("/^232 /", $packet)) { 
     285     
     286       $msg = ""; 
     287       $from = substr($packet, 16); 
     288       $packet = socket_read($sock, 1024, PHP_NORMAL_READ); 
     289    $snttime = substr($packet, 12); 
     290    
     291    $packet = socket_read($sock, 1024, PHP_NORMAL_READ); 
     292    $packet = socket_read($sock, 1024, PHP_NORMAL_READ); 
     293     
     294    while(!preg_match("/^223 /", $packet)){ 
     295      $msg .= (($msg!="")?"<br/>":"").$packet; 
     296      $packet = socket_read($sock, 1024, PHP_NORMAL_READ); 
     297    } 
     298     
     299    if (get_magic_quotes_gpc()) { 
     300        $msg = stripslashes($msg); 
     301    } 
     302    $result[] = array('msg' => kses($msg, $allowed), 'time' => trim($snttime), 'from' => trim($from)); 
     303     
     304    $packet = socket_read($sock, 1024, PHP_NORMAL_READ); 
     305    } 
     306    return $result; 
     307} 
     308 
    262309?> 
  • index.php

     
    44        <title>licq</title> 
    55        <link rel="StyleSheet" type="text/css" href="licqweb.css" /> 
    66        <link rel="shortcut icon" href="images/favicon.ico"> 
     7        <script type="text/javascript" src="licqweb.js" /> 
    78    </head> 
    8     <body onload="checkSession()"> 
     9    <body onload="init()"> 
    910    <div id="tooltip"></div> 
    10     <script type="text/javascript" src="licqweb.js" /> 
     11 
    1112    <h1>licq<i><font color="#5555ff">web</font></i></h1> 
    1213    <div id="login" class="loginwin"> 
    1314        <div class="bar">licqweb login</div> 
     
    2021    <div id="contactList" class="box" style="left:10px;top:150px;display:none;"> 
    2122        <div class="bar" onmousedown="init_drag(event, 'contactList')" id="nick">licqweb</div> 
    2223        <div id="contacts"></div> 
    23         <div id="ownerStatus"></div> 
     24        <div style="display:box;height:18px"> 
     25         <div id="ownerStatus"></div> 
     26         <div class="resizer" onmousedown="init_resize(event, 'contacts', 100, 100)"> 
     27            <img class="resizerImage" src="images/resizer.png" /> 
     28         </div> 
     29        </div> 
    2430    </div> 
    2531    <div id="statusMenu"></div> 
    2632    <div id="windows"></div> 
  • licqweb.js

     
    1919 */ 
    2020 
    2121//option vars 
    22 var showOffline = false; 
     22var showOffline = true; 
    2323var maxLogLines = 20; 
     24var showHistory = true; 
    2425 
    2526var xmlhttp = new XMLHttpRequest(); //for serverpush connection 
    2627xmlhttp.multipart = true; 
     
    116117    var messages = response.getElementsByTagName('message'); 
    117118    var times = response.getElementsByTagName('time'); 
    118119    for (var i = 0; i < messages.length; ++i) { 
    119         txtdiv.innerHTML += '(' + times[i].firstChild.data + ') ' + contacts[pp][id].nick + ': ' + messages[i].firstChild.data + "<br/>"; 
     120        txtdiv.innerHTML += '(<span class="msgDate">' + times[i].firstChild.data + '</span>) <span class="msgNick">' + contacts[pp][id].nick + '</span>: <span class="msgText">' + messages[i].firstChild.data + "</span><br/>"; 
    120121    } 
    121122    txtdiv.scrollTop = txtdiv.scrollHeight; 
    122123} 
     
    168169            } else { 
    169170                pp = contact.pp.toLowerCase(); 
    170171            } 
    171             var imgsrc = "images/" + pp + "." + contact.status.toLowerCase() + ".png"; 
     172            var imgsrc = "images/" + pp + "." + contact.status.toLowerCase().replace(" ","") + ".png"; 
    172173            if (parseInt(contact.nummsgs) > 0) { 
    173174                uclass = "newmessage"; 
    174175                imgsrc = "images/msg.png"; 
     
    192193        contacts[pp][id].status = status; 
    193194        contacts[pp][id].nummsgs = messages; 
    194195        contacts[pp][id].nick = nick; 
     196        contacts[pp][id].historyShowed = false; 
    195197    } else { 
    196198        contacts[pp][id] = new Contact(id, pp, nick, status, messages); 
    197199        var newcontact = document.createElement('div'); 
     
    205207 
    206208function getWindowHtml(id, pp, nick) { 
    207209    var key = id + '-' + pp; 
    208     return "<div class=\"window\" style=\"left:300px;top:150px\" id=\"" + key + "-w\">" + 
     210    return "<div onClick=\"set_focus(event, '" + key + "')\" class=\"window\" style=\"left:300px;top:150px\" id=\"" + key + "-w\">" + 
    209211                "<div onmousedown=\"init_drag(event, '" + key + "-w')\" class=\"bar\">" + 
    210212                    "<div class=\"wintitle\">" + nick + " (" + pp + ")</div>" + 
    211213                    "<div onclick=\"showContactWindow('" + id + "', '" + pp + "')\" class=\"close\">[close]</div>" + 
    212214                "</div>" + 
    213215                "<div class=\"convo\" id=\"" + key + "-txt\"></div>" +  
    214                 "<div class=\"msginput\"><textarea id=\"" + key + "-input\" onKeyPress=\"textarea_keypress(event, '" + id + "', '" + pp + "')\"></textarea><br>" + 
     216                "<div class=\"msginput\"><textarea id=\"" + key + "-input\" onKeyPress=\"textarea_keypress(event, '" + id + "', '" + pp + "')\" ></textarea><br>" + 
    215217                    "<input type=\"submit\" class=\"button\" value=\"Send\" onclick=\"sendMessage('" + id + "', '" + pp + "'); return false\" />" + 
     218                    "<div class=\"resizer\" onmousedown=\"init_resize(event, '" + key + "-txt', 150, 50)\"><img class=\"resizerImage\" src=\"images/resizerMsg.png\" /></div>" + 
    216219                "</div>" + 
    217220            "</div>"; 
    218221} 
     
    250253    var message = ackMessages[uid]; 
    251254    var txt = document.getElementById(message.id + '-' + message.pp + '-txt'); 
    252255    if (res == "done.") { 
    253         txt.innerHTML += "(" + ts + ") " + nick + ": " + message.message.replace(/[\r\n]+/g, "<br/>") + "<br/>"; 
     256        txt.innerHTML += "(<span class=\"msgDate\">" + ts + "</span>) <span class=\"msgNick\">" + nick + "</span>: <span class=\"msgText\">" + message.message.replace(/[\r\n]+/g, "<br/>") + "</span><br/>"; 
    254257    } else { 
    255258        txt.innerHTML += "--- Message failed!<br/>"; 
    256259    } 
     
    264267    if (contacts[pp][id].nummsgs > 0) { 
    265268        requestViewEvent(id, pp); 
    266269    } 
     270    if(showHistory==true && contacts[pp][id].historyShowed != true){ 
     271       requestViewHistory(id, pp); 
     272       contacts[pp][id].historyShowed = true; 
     273    } 
     274        
    267275    win = document.getElementById(id + '-' + pp + '-w'); 
    268276    if (win.style.display == 'block') { 
    269277        win.style.display = 'none'; 
     
    272280    } 
    273281    var txtdiv = document.getElementById(id + '-' + pp + '-txt'); 
    274282    txtdiv.scrollTop = txtdiv.scrollHeight; 
    275     //win.style.zIndex = ++dragwin.win.style.zIndex; 
     283    win.style.zIndex = ++dragwin.zIndex; 
    276284    //dragwin.win = win; 
    277285} 
    278286 
     
    315323            document.getElementById(key + '-i').src = "images/msg.png"; 
    316324        } else { 
    317325            document.getElementById(key + '-s').className = contacts[pp][id].status; 
    318             document.getElementById(key + '-i').src = "images/" + pp.toLowerCase() + "." + contacts[pp][id].status.toLowerCase() + '.png'; 
     326            document.getElementById(key + '-i').src = "images/" + pp.toLowerCase() + "." + contacts[pp][id].status.toLowerCase().replace(" ","") + '.png'; 
    319327        } 
    320328    } else { 
    321329    } 
     
    340348function _updateOwners() { 
    341349    var statushtml = ""; 
    342350    for (var pp in owners) { 
    343         statushtml += "<img onclick=\"showSelectStatus(event, '" + owners[pp].id + "', '" + pp + "'); return false\" src=\"images/" + pp.toLowerCase() + "." + owners[pp].status.toLowerCase() + ".png\"/> "; 
     351        statushtml += "<img onclick=\"showSelectStatus(event, '" + owners[pp].id + "', '" + pp + "'); return false\" src=\"images/" + pp.toLowerCase() + "." + owners[pp].status.toLowerCase().replace(" ","") + ".png\"/> "; 
    344352    } 
    345353    document.getElementById('ownerStatus').innerHTML = statushtml; 
    346354} 
     
    352360    statuss["MSN"] = new Array('Online', 'Away', 'Occupied'); 
    353361    var statushtml = ""; 
    354362    for (var i = 0; i < statuss[pp].length; ++i) { 
    355         statushtml += "<div onclick=\"changeStatus('" + pp + "', '" + statuss[pp][i] + "')\"><img src=\"images/" + pp.toLowerCase() + "." + statuss[pp][i].toLowerCase() + ".png\">" + statuss[pp][i] + "</div>"; 
     363        statushtml += "<div onclick=\"changeStatus('" + pp + "', '" + statuss[pp][i] + "')\"><img src=\"images/" + pp.toLowerCase() + "." + statuss[pp][i].toLowerCase().replace(" ","") + ".png\">" + statuss[pp][i] + "</div>"; 
    356364    } 
    357365    statusMenu.innerHTML = statushtml; 
    358366    statusMenu.style.left = e.pageX; 
     
    428436 
    429437/* Tool tip stuff */ 
    430438var enabletip = false; 
    431 var tooltip = document.getElementById('tooltip'); 
     439var tooltip = null; 
    432440 
    433441function showToolTip(pp, id){ 
    434442    tooltip.innerHTML = contacts[pp][id].id + ' (' + contacts[pp][id].pp + ')<br>' + contacts[pp][id].status + '<br>Messages: ' + contacts[pp][id].nummsgs; 
     
    460468dragwin.zIndex = 0; 
    461469 
    462470function init_drag(event, id) { 
    463     var el; 
    464     var x, y; 
    465471 
    466     dragwin.win = document.getElementById(id); 
     472   dragwin.win = document.getElementById(id); 
    467473 
    468474    dragwin.startX = event.clientX + window.scrollX; 
    469475    dragwin.startY = event.clientY + window.scrollY; 
     
    494500    document.removeEventListener("mousemove", start_drag, true); 
    495501    document.removeEventListener("mouseup", stop_drag, true); 
    496502} 
     503 
     504function set_focus(event, key){ 
     505   win = document.getElementById(key + "-w"); 
     506   win.style.zIndex = ++dragwin.zIndex; 
     507   event.preventDefault(); 
     508    
     509   /*input = document.getElementById(key + "-input"); 
     510   input.focus();*/ 
     511    
     512   //stop_propagate(event); 
     513} 
     514 
     515function stop_propagate(event){ 
     516   if (!event) var event = window.event; 
     517    event.cancelBubble = true; 
     518    if (event.stopPropagation) event.stopPropagation(); 
     519} 
     520 
     521/* Window resizing stuff */ 
     522var resizewin = new Object(); 
     523 
     524function init_resize(event, id, minW, minH) { 
     525    resizewin.win = document.getElementById(id); 
     526    resizewin.minW = minW; 
     527    resizewin.minH = minH; 
     528 
     529    resizewin.startX = event.clientX + window.scrollX; 
     530    resizewin.startY = event.clientY + window.scrollY; 
     531    resizewin.startWidth = parseInt(resizewin.win.style.width, 10); 
     532    resizewin.startHeight = parseInt(resizewin.win.style.height,  10); 
     533 
     534    if (isNaN(resizewin.startWidth)) resizewin.startWidth = resizewin.win.offsetWidth; 
     535    if (isNaN(resizewin.startHeight)) resizewin.startHeight = resizewin.win.offsetHeight; 
     536 
     537    //resizewin.win.style.zIndex = ++resizewin.zIndex; 
     538 
     539    document.addEventListener("mousemove", do_resize, true); 
     540    document.addEventListener("mouseup", stop_resize, true); 
     541    event.preventDefault(); 
     542} 
     543 
     544function do_resize(event) { 
     545    var x, y; 
     546    x = event.clientX + window.scrollX; 
     547    y = event.clientY + window.scrollY; 
     548 
     549     
     550    if(resizewin.minW < (resizewin.startWidth + x - resizewin.startX)){ 
     551      resizewin.win.style.width = (resizewin.startWidth + x - resizewin.startX) + "px"; 
     552       
     553      /*Sorry for this hack. Mozilla does not shrink parent DIV according to the content (until redraw).*/ 
     554      resizewin.win.parentNode.style.width = (resizewin.startWidth + x - resizewin.startX) + "px"; 
     555    } 
     556   if(resizewin.minH < (resizewin.startHeight + y - resizewin.startY)){ 
     557      resizewin.win.style.height = (resizewin.startHeight + y - resizewin.startY) + "px"; 
     558   } 
     559     
     560    event.preventDefault(); 
     561} 
     562 
     563function stop_resize(event) { 
     564    document.removeEventListener("mousemove", do_resize, true); 
     565    document.removeEventListener("mouseup", stop_resize, true); 
     566} 
     567 
     568function init(){ 
     569   checkSession(); 
     570    
     571   tooltip = document.getElementById('tooltip'); //Sometimes tooltip variable was null 
     572} 
     573 
     574function requestViewHistory(id, pp) { 
     575    xmlhttp2 = new XMLHttpRequest(); 
     576    xmlhttp2.onreadystatechange = acceptResponse2; 
     577    xmlhttp2.open("GET", baseurl + "/viewHistory.php?id=" + id + "&pp=" + pp + "&lenght=10&offset=0", true); 
     578    xmlhttp2.send(null); 
     579} 
     580 
     581function viewHistory(response) { 
     582    var id = response.getElementsByTagName('id')[0].firstChild.data; 
     583    var pp = response.getElementsByTagName('pp')[0].firstChild.data; 
     584    var txtdiv = document.getElementById(id + '-' + pp + '-txt'); 
     585    var messages = response.getElementsByTagName('message'); 
     586    var times = response.getElementsByTagName('time'); 
     587    var froms = response.getElementsByTagName('from'); 
     588    for (var i = messages.length-1; i >=0 ; --i) { 
     589        txtdiv.innerHTML += '(<span class="msgDate">' + times[i].firstChild.data + '</span>) <span class="msgNick">' + froms[i].firstChild.data + '</span>: <span class="msgText">' + messages[i].firstChild.data + "</span><br/>"; 
     590    } 
     591    txtdiv.scrollTop = txtdiv.scrollHeight; 
     592} 
     593 No newline at end of file 
  • licqweb.css

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: images/resizer.png
    ___________________________________________________________________
    Name: svn:executable
       + *
    Name: svn:mime-type
       + application/octet-stream
    
    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: images/resizerMsg.png
    ___________________________________________________________________
    Name: svn:executable
       + *
    Name: svn:mime-type
       + application/octet-stream
    
     
    108108    left: 300px; 
    109109} 
    110110 
     111#ownerStatus { 
     112   left:0px; 
     113   width:20px; 
     114   position:absolute; 
     115} 
     116 
     117.resizer { 
     118   right:0px; 
     119   bottom:0px; 
     120   width:18px; 
     121   height:18px; 
     122   position:absolute; 
     123} 
     124 
     125.resizerImage { 
     126   bottom:0px; 
     127   position:absolute; 
     128   right:0px; 
     129} 
     130 
    111131.box { 
    112132    background-color: #eee; 
    113133    border: 1px solid #000000; 
     
    128148    max-width: 350px; 
    129149    overflow: hidden; 
    130150    float: left; 
     151    cursor: Default; 
    131152} 
    132153 
    133154.close { 
    134155    background-color: #333355; 
    135156    float: right;    
    136     cursor: pointer; 
     157   cursor: pointer; 
    137158} 
    138159 
    139160.content { 
     
    218239    border: 1px solid #8ca8cf; 
    219240    width: 100px; 
    220241} 
     242 
     243.msgText { 
     244   color: #000000; 
     245} 
     246 
     247.msgDate { 
     248   color: #FF0000; 
     249} 
     250 
     251.msgNick { 
     252   color: #0000FF; 
     253   font-weight: bold; 
     254} 
     255 No newline at end of file