Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2006
    Location
    London
    Posts
    342
    Tokens
    0

    Default Chatroom for forums.

    This is a basic chatroom, although the code isnt.

    Ok, i have used this on my own forum which i have closed. it is compat with any forum (VB, MYBB, PunBB, invasion) all you have to do is change the username var ($mybbusername) and the paths to your forum, i dont think there is any more to change. this one is made for MYBB 1.x and if that is what you are using you can just paste it, ifyou are using MYBB 2.x look on the website as i posted about how to change it about 1 month ago (i cant remember the username var but it is somthing like $username=>somthig)

    you will need to have basic php skills to change the code, but i tried to make it as simple as possible, all you really need to edit is the login boxes so they will work with your forums, the paths to do things like send messages (without the username/id at the end) and the $username.
    --------

    Ok, i will try to make it as simple as pos. first make a page, call it MESSAGES.HTM.

    This is the page the messages will write to. you do not need to put any code here.

    CHAT2.PHP

    ok, make a page, call it chat2.php change the $username var, the path to the different pages, e.g. /forums/global.php, make sure the login boxes will work with your forums, just change like the path to the pages.
    also where you see a url like:
    forums/private.php?action=send&uid=$mybbuser[uid]
    what you have to do is change the url to the forums, and the url to send a PM or what ever, do not include the userid, include the uid var, for MYBB 1.x it is $mybbuser[uid].

    paste and edit this code to CHAT2.PHP
    Code:
    <?php
    /*-----------FIRST GET THE OLD MESSAGES FROM messages.htm-----------*/
    // Read file into an array
    $message_array = file("messages.htm");
    // Compile the string
    for ($counter = 1; $counter < 20; $counter++) {/*INSTEAD OF 20 WRITE SOMETHING ELSE, SAY 30*/
        $old_messages .= $message_array[$counter];
    }
    /*-----------SECOND GET AND MODIFY THE NEW MESSAGE-----------*/
    //ADD TIME
    $time = date("H:i");
    //ADD URL
    if($url)
        $link_html .= " <?php
    chdir('forums'); // path to MyBB
    require './global.php';
    ?><a href='forums/private.php?action=send&uid=$mybbuser[uid]' target=\"_new\"><font color=\"$color\" face=\"wingdings\">$url</font></a></a>".
            "";
    //ADD name chat
    if($name)
        $name_html .="&nbsp;&gt $name".
            "";
            
    //ADD to name chat
    if($name)
        $name_html2 .= "<i>".
            "";
            
    //ADD email
    if($email)
        $link_html .= " <?php
    chdir('forums'); // path to MyBB
    require './global.php';
    ?><a href='forums/member.php?action=emailuser&uid=$mybbuser[uid]' target=\"_new\"><font color=\"$color\" face=\"wingdings\">$email</font></a></a>".
            "";
    //ADD EMAIL
    if($mail)
        $link2_html .= "<img border=\"0\" src=\"$mail\">".
            "";
    $new_message = " <?php
    chdir('forums'); // path to MyBB
    require './global.php';
    ?>
     $link2_html $name_html2 <b><a target='_blank' href='/forums/member.php?action=profile&uid=$mybbuser[uid]'><font color=\"$color\">$mybbuser[username]</font></a></b>".
        "$name_html<b>:</b> <font color=\"$color\">$message</i></font><font size=\"1\"><i>&nbsp;Sent at:($time)</i></font>$link_html <br>\n";
    
    /*-----------THIRD MAKE THE HEADER AND THE FOOTER-----------*/
    // It's important that there are no newline
    // characters except at the end of the string.
    // This keeps all the headers together.
    $header = "<html><head><meta http-equiv=\"refresh\" content=\"8\">". /*INCREASE THE REFRESH TIME FROM 8 TO 20*/
        "<meta name=\"robots\" content=\"noindex\"> <style type=\"text/css\">A:link {TEXT-DECORATION: none}A:active {TEXT-DECORATION: none} A:visited {TEXT-DECORATION: none}A:hover {TEXT-DECORATION: none} </style></head>".
        "<body bgcolor=\"#ffffff\" text=\"#000000\">\n";
    
    $footer = "<font color=\"#000000\">".
        "<br><p align=\"center\">&copy; Site Name 2006. All Rights Reserved.</a></font></p></body></html>";
    // Opens file for writing and truncates file length to zero.
    $open_file = fopen("messages.htm", "w");
    /*-----------FOURTH UPDATE THE messages.htm-----------*/
    // write file header...
    fputs($open_file, $header);
    // ... new line...
    // (stripSlashes because we don't want all
    // our escape characters appearing in the
    // message file)
    fputs($open_file, stripslashes($new_message));
    // ... old lines ...
    fputs($open_file, $old_messages);
    // ... and footer.
    fputs($open_file, $footer);
    // Close the file when you're done. Don't forget to wash your hands
    fclose($open_file);
    
    ?>
    <html>
    <head>
    <!-- div --->
    <script type="text/javascript">
      
    var horizontal_offset="9px" //horizontal offset of hint box from anchor link
    /////No further editting needed
    var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
    var ie=document.all
    var ns6=document.getElementById&&!document.all
    function getposOffset(what, offsettype){
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
    var parentEl=what.offsetParent;
    while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
    }
    return totaloffset;
    }
    function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }
    function clearbrowseredge(obj, whichedge){
    var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
    if (whichedge=="rightedge"){
    var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
    dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
    if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
    edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
    }
    else{
    var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
    dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
    if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
    edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
    }
    return edgeoffset
    }
    function showhint(menucontents, obj, e, tipwidth){
    if ((ie||ns6) && document.getElementById("hintbox")){
    dropmenuobj=document.getElementById("hintbox")
    dropmenuobj.innerHTML=menucontents
    dropmenuobj.style.left=dropmenuobj.style.top=-500
    if (tipwidth!=""){
    dropmenuobj.widthobj=dropmenuobj.style
    dropmenuobj.widthobj.width=tipwidth
    }
    dropmenuobj.x=getposOffset(obj, "left")
    dropmenuobj.y=getposOffset(obj, "top")
    dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
    dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
    dropmenuobj.style.visibility="visible"
    obj.onmouseout=hidetip
    }
    }
    function hidetip(e){
    dropmenuobj.style.visibility="hidden"
    dropmenuobj.style.left="-500px"
    }
    function createhintbox(){
    var divblock=document.createElement("div")
    divblock.setAttribute("id", "hintbox")
    document.body.appendChild(divblock)
    }
    if (window.addEventListener)
    window.addEventListener("load", createhintbox, false)
    else if (window.attachEvent)
    window.attachEvent("onload", createhintbox)
    else if (document.getElementById)
    window.onload=createhintbox
    </script>
    <!-- div --->
    <!-- style ~ max= 10 then ~div--->
    <style type="text/css">
    .progress{
     width: 1px;
     height: 14px;
     color: white;
     font-size: 12px;
      overflow: hidden;
     background-color: navy;
     padding-left: 5px;
    }
    #hintbox{ /*CSS for pop up hint box */
    position:absolute;
    top: 0;
    background-color: lightyellow;
    width: 150px; /*Default width of hint.*/ 
    padding: 3px;
    border:1px solid black;
    font:normal 11px Verdana;
    line-height:18px;
    z-index:100;
    border-right: 3px solid black;
    border-bottom: 3px solid black;
    visibility: hidden;
    }
    .hintanchor{ /*CSS for link that shows hint onmouseover*/
    font-weight: bold;
    color: navy;
    margin: 3px 8px;
    }
    </style>
    <!-- max --->
    <script type="text/JavaScript">
    function textCounter(field,counter,maxlimit,linecounter) {
     // text width//
     var fieldWidth =  parseInt(field.offsetWidth);
     var charcnt = field.value.length;        
     // trim the extra text
     if (charcnt > maxlimit) { 
      field.value = field.value.substring(0, maxlimit);
     }
     else { 
     // progress bar percentage
     var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
     document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
     document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
     // color correction on style from CCFFF -> CC0000
     setcolor(document.getElementById(counter),percentage,"background-color");
     }
    }
    function setcolor(obj,percentage,prop){
     obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
    }
    </script>
    <!-- max --->
    </head>
    <body>
    <form name="inpform" action="chat2.php" method="post" onSubmit="html2entities(this.message)">
    <!-- no html --->
    <script type="text/javascript">
    function html2entities(){
    var re=/[(<>"'&]/g
    for (i=0; i<arguments.length; i++)
    arguments[i].value=arguments[i].value.replace(re, function(m){return replacechar(m)})
    }
    function replacechar(match){
    if (match=="<")
    return " "
    else if (match==">")
    return " "
    else if (match=="\"")
    return " "
    else if (match=="'")
    return " "
    else if (match=="&")
    return " "
    }
    </script>
    <!-- no html --->
    <table>
      <tr>
        <td>Name : 
        </td>
        <td><input type="text" name="name" value="<?php echo $name?>"><!-- name help ---> <a href="#" class="hintanchor" onMouseover="showhint('Please choose a username. Should consist of alphanumeric characters only.', this, event, '150px')">[?]</a> <!--namehelp--->
        </td>
      </tr>
      <tr>
        <td>Color: 
        </td>
        <td><select size='1' name='color' value='<?php echo $color?>'>
     
     <option>Black</option>
     <option>White</option>
     <option>Brown</option>
     <option>Red</option>
     <option>Pink</option>
     <option>Orange</option>
     <option>Gold</option>
     <option>Yellow</option>
     <option>Green</option>
     <option>Blue</option>
     <option>Sky Blue</option>
     <option>Purple</option>
     </select>
        </td>
        </td>
      </tr>
      <tr>
        <td>Message : 
        </td>
        <td><textarea rows='6' name='message' cols='60' id="maxcharfield" 
    onKeyDown="textCounter(this,'progressbar1',300)" 
    onKeyUp="textCounter(this,'progressbar1',300)" 
    onFocus="textCounter(this,'progressbar1',300)"></textarea>
    <div id="progressbar1" class="progress"></div>
    <script>textCounter(document.getElementById("maxcharfield"),"progressbar1",300)</script>
        </td>
      </tr>
      <tr>
        <td><input type="submit" value="Send">
        </td>
        <td>&nbsp;
        </td>
      </tr>
      
      <tr>
        <td>&nbsp;
        </td>
        <td>&nbsp;
        </td>
      </tr>
      <tr>
        <td>URL : 
        </td>
        <td><select name="mail" value="<?php echo $mail?>" size="1">
    <option value="/images/flags/gb.gif">UK</option>
    </select>    </td>
      </tr>
      
      <tr>
        <td>Allow members to send me personal messages: 
        </td>
        <td><select name="url" value="<?php echo $url?>" size="1">
    <option value="2">Yes</option>
    <option value="">No</option>
    </select>
        </td>
      </tr>
      <tr>
        <td>Allow members to send e-mails: 
        </td>
        <td><select name="email" value="<?php echo $email?>" size="1">
    <option value="*">Yes</option>
    <option value="">No</option>
    </select>
        </td>
      </tr>
    </table>
    </form> 
    <script language="javascript">
      document.inpform.message.focus();
    </script>
    </body>
    </html>
    edit it as you wish with things like CSS, i suggest using refs instead of pasting css as it will make it easy to change in the future. also make sure you put the CSS in the right page so it doesnt write to the messages.htm page.

    this code in the one above:

    Code:
    <select name="mail" value="<?php echo $mail?>" size="1">
    <option value="/images/flags/gb.gif">UK</option>
    lets the user choose a country flag from a list, and this will write to the page. you can add more flags or delete it it wont matter (also the option value must be the url to the flags, betwene the option is the flag name.)

    Make a page and call it CHATROOM2.HTM

    The first bit you need to edit is marked with // path to MyBB, just change it to the path to your forum. the next is the login boxes, make sure they work with your forum. if not ask someone on your forums forum and ask them to make you a code, im sure they will be happy to,

    Code:
    <?php
    chdir('../forums'); // path to MyBB
    require './global.php';
    ?>
    <html>
      <head>
        <title> Chat room </title>
      </head>
      
      <body>
    <?php
    if($mybb->user['uid'])
    {
    // The user is logged in, say Hi
    echo "<iframe name='messages' width="100%" height=70% src='messages.htm'>This page requires frames, but your browser does not support them.</iframe><iframe name='sendinp' width="100%" height=30% src='chat2.php'>This page requires frames, but your browser does not support them.</iframe";
    }
    else
    {
    // The user is not logged in, Display the form
    echo "<form action='forums/member.php' method='post'>
    <input type='hidden' name='url' value='chatroom2.htm' />
    <input type='hidden' name='action' value='do_login'>
    Username: <input type='text' name='username' size='17' maxlength='30' /><br />
    Password: <input type='password' name='password' size='17' /><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type='submit' class='submit' name='submit' value='Login' /><br><br>
    <p align='center'><a href='forums/member.php?action=register'>
    <font size='1'>Sign up</font></a><font size='1'>
    <br>
    <a target='_blank' href='forums/member.php?action=lostpw'>Forgot password</a></font></p>
    </form><br>";
    }
    ?>
    </body>
    </html>
    You cant view this clientside so you need to upload it. i made everything in this code, except the login boxes which MYBB released the code for.


    *make sure all the pages above are in the same directory
    *Make sure to CHMOD MESSAGES.HTM to 7777 or 0777 so the php can write to them.
    *I havnt given you the full version. what i have given you is one that will work with most different versions and with all the styles removed so you can make yourown.
    *any non-noob help Qs just PM me
    *look at the online.php page of your forum (dont vieew source look at the origanal page) and look at the code to see who is where, addapt it to the forum page and add it to CHATROOM.HTM page.

    i hope someone will use this and i diddnt waste my time doing this :s
    As soon as my rubbish server is back up (zeeblo.com) i will paste a link to my forums :S

  2. #2
    Join Date
    Sep 2006
    Posts
    918
    Tokens
    0

    Default

    Wont it need a db? (Only skim read so may have missed it)

  3. #3
    Join Date
    Oct 2006
    Location
    London
    Posts
    342
    Tokens
    0

    Default

    Nope, you dont need the SQL db, it is done using the global.php page

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •