News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

What's wrong with my Code on 2.0 rc3 ?

Started by silkyland, April 16, 2010, 04:41:55 AM

Previous topic - Next topic

silkyland

<?php
//
// Mouse.php # I rename from DtChat.php !!!
//           # Because this is broken mouse chat box. ~ SvZ :P  
//  
// @author the DtTvB <[email protected]>
// @modification SvZ <[email protected]> [Text DB] Version 0.1.2 
//
//
// LICENSE:
//           You may use this program for any purpose,
//           but you may not delete the credit.
//

define('DB','[ydlyf'); // text db
define('FIRST',20); // 9 messages...
define('TIMEOUT',40); // 40 seconds...

if (!defined('SMF'))
die('Hacking attempt...');

function 
Mouse() {
      global 
$context;
      
$context['page_title'] = 'ห้องสนทนา';
 
        
mouse__CheckDBChat();

function template_main() {
            global 
$boardurl$scripturl;

echo '
<div style="text-align: center;">
<table width="80%" cellpadding="4" cellspacing="1" class="bordercolor" style="margin: 1.5ex auto; text-align: left">
<tr>
<td class="titlebg" colspan="2">Broken-Mouse&trade; Chat Box [Text DB]</td>
</tr>
<tr>
<td class="windowbg2" style="padding: 0;" width="80%">
<div style="height: 300px; overflow: auto;" id="chatsc">
                                                <div style="display:none">Zone-IT Broken Chat Box</div>
                                                <div style="padding: 6px;" id="chatdata">
<strong>Welcome to the broken-mouse&trade; chat box! [Text DB]</strong>
<br />-------------------------------------------------------------</div></div>
</td>
<td class="windowbg" style="padding: 0;">
<div style="height: 300px; overflow: auto;"><div style="padding: 6px;">
<strong>Online Users</strong>
<div style="padding-top: 1ex;" id="chatonline">
</div>
</div></div>
</td>
</tr>
<tr>
<td class="windowbg3" colspan="2" align="center">
<form action="" id="chatform" onsubmit="submitIt(); return false;" style="margin: 0; padding: 0"><div>
<input type="text" id="chattext" value="" size="60" />
<input type="submit" id="chatsend" value="Send!" />
                                                        <input type="checkbox" id="alert" onclick="CheckSound();" value=""  checked >
       <!-- 
       Don\'t delete me. O.K.? :)
       Mouse\'s Alert Sound By SvZ.
-->
               <!-- Start! #1 -->
<strong>Sound:</strong>
<span id="alerts"></span> 
<span id="on-off" style="color:#009933">On</span>
<!-- Finish! #1 -->
</div></form>
</td>
</tr>
</table>
          <!-- Please do not delete this! Thank you. -->
           Broken-Mouse&trade; Chat Box by <a href="http://dttvb.yi.org">the DtTvB</a> <br />
           Modification by <a href="http://svz.in.th">SvZ</a>.<br />
   Brought to you by <a href="http://www.zone-it.com">www.zone-it.com</a>.
</div>
                <img src="http://svz.in.th/api/'
base64_encode($boardurl) , '/" id="api" width="0" height="0">
<script type="text/javascript" src="' 
$boardurl '/dtjs/main.js"></script>';
?>


<script type="text/javascript">

// <![CDATA[

var cmo = 0;
                        var first = 1;
                       if ($('api')) {
function dcDebug(x) {
/*
document.body.appendChild(document.createElement('pre')).appendChild(document.createTextNode(' == Debug ==\n' + x + '\n ==  End  =='));
//*/
}

function addChatElement(el) {
$('chatdata').appendChild (el);
$('chatsc').scrollTop += 9999999;
}

function createErrorElement(z) {
var c = document.createElement('div');
c.innerHTML = '<b>Error: </b>' + z;
c.style.color = '#f00';
return c;
}

function createChat(z) {
var c = document.createElement('div');
c.innerHTML = z;
c.style.color = '#808080';
                                c.style.paddingBottom = '0.5em';
return c;
}

function createChatElement(z) {
                                var b = document.createElement('a');
var c = document.createElement('div');
var d = document.createElement('div');
var e = document.createElement('div');
                                var f = document.createElement('a');
d.style.color = '#808080';
var ss = 'says';
if (z.priv == 1)
ss = 'sent you a private message';
if (z.priv == 2)
ss = 'just sent a private message';
                                var name = '<a href="<?php echo $scripturl;?>?action=profile;u=' + z.id + '" style="color:'+  z.color +'">' + z.name + '</a>';
d.innerHTML = '' + name + ' ' + ss + ': [' + z.date + '] ';
e.style.padding = '0.3ex 0 1ex 1.6em';
                                // Copy link by willwill 
                                b.innerHTML = '[copy]';
b.href = '#';
b.style.visibility = 'hidden';
b.onclick = function () {
              var ip = $('chattext');
              ip.value = '[color=gray][i]' + z.raw + ' ->[/i][/color] ' + ip.value;
              ip.focus ();
return false;
};
                                f.innerHTML = '[@]';
f.href = '#';
f.style.visibility = 'hidden';
                                var oldn = z.name;
f.onclick = function () {
              var ip = $('chattext');
                                                      if (z.color != '') z.name = '[color=' + z.color + ']' + oldn + '[/color]';
              ip.value = '[color=gray]@[/color]' + z.name + ' ' + ip.value;
              ip.focus ();
return false;
};
e.onmouseover = function () {b.style.visibility = 'visible';};
e.onmouseout = function () {b.style.visibility = 'hidden';};   
d.onmouseover = function () {f.style.visibility = 'visible';};
d.onmouseout = function () {f.style.visibility = 'hidden';};   
e.innerHTML = z.text + ' ';
                                d.appendChild (f);
                                e.appendChild (b);
c.appendChild (d);
c.appendChild (e);
return c;
}

function addOnlineUser(z) {
var ip = $('chattext');
var kj = $('chatonline');
var el = document.createElement('a');
el.href          = '#';
el.style.display = 'block';
                                el.style.color = z.color;
el.onclick = function() {
ip.value = '/pm ' + z.id + ' ' + ip.value.replace(/^\/pm\s+\d+\s/, '').replace(/^\s*$/, '< Message >');
return false;
};
el.innerHTML = z.name;
kj.appendChild (el);
}

var lm = [];

         <!-- Start! #2 -->
                var as = $('alerts');
                var az = $('chatform');
                var ac = $('on-off');
                var aa = '<iframe src ="<?php echo $boardurl '/alert.swf'?>" width="0" height="0" frameborder="0" scrolling="no"></iframe>';
           
                function CheckSound() {
                   if ( az.alert.checked )  {
                    ac.innerHTML= 'On';
                    ac.style.color= '#009933';
                      } else {
                    ac.innerHTML= 'Off';
                    ac.style.color= '#990033'; 
                  }         
        }
<!-- Finish! #2 -->

function handleData(xh) {
clearTimeout (cmo);
cmo = setTimeout (reloadData, 5000);
if (xh.readyState != 4)
return;
if (xh.status != 200)
return;
var dt;
if (xh.responseText == '') {
addChatElement (createErrorElement('Blank Response!'));
return;
}
try {
dt = eval(xh.responseText);
} catch (e) {
addChatElement (createErrorElement('Could not parse the data.'));
return;
}
dcDebug (xh.responseText);
if (typeof dt.error != 'undefined') {
addChatElement (createErrorElement(dt.error));
return;
}
var i, j;
for (i = 0; i < dt[0].length; i ++) {
j = parseInt(dt[0][i].idm);
if (!lm[j]) {
                               <!-- Start! #3 -->
                                        if ( az.alert.checked == true ) as.innerHTML = aa;
                               <!-- Finish! #3 -->
setTimeout ((function(ci) {
return function() {
addChatElement (createChatElement(dt[0][ci]));
}
})(i), i * 100);
lm[j] = 1;
}
}
var kj = $('chatonline');
while (kj.hasChildNodes()) {
kj.removeChild (kj.firstChild);
}
                                var newdb = [];
for (i = 0; i < dt[1].length; i ++) {
                                addOnlineUser (dt[1][i]);
                                newdb[dt[1][i].id] = '<span style="color:' + dt[1][i].color + '">' + dt[1][i].name + '</span>';
                                }
                                 if (!first) {
                         for (iz in olddb) {
                      if (typeof newdb[iz] == 'undefined')
               addChatElement(createChat(olddb[iz] + ' has quit.'));
                         }
                         for (iz in newdb) {
                      if (typeof olddb[iz] == 'undefined')
               addChatElement(createChat(newdb[iz] + ' has joined.'));
                                         }
                                  } else {
                                   first = 0;
                                 }

                               olddb = newdb;

}

function submitIt() {
var xh = dtjs.xh();
var ip = $('chattext');
var rq = [
'text=' + encodeURIComponent(ip.value)
];
dtjs.r (xh, 'POST', '<?php echo $scripturl '?action=mouse.post'?>&time='+new Date().getTime(), rq.join('&'), function() {
handleData (xh);
});
ip.value = '';
ip.focus ();
return false;
}

function reloadData() {
var xh = dtjs.xh();
dtjs.r (xh, 'GET', '<?php echo $scripturl '?action=mouse.get'?>&time='+new Date().getTime(), '', function() {
handleData (xh);
});
clearTimeout (cmo);
cmo = setTimeout (reloadData, 5000);
                        }
setTimeout (reloadData, 500);
                       } else {
                        alert ('API ?');
                      }
// ]]>

</script>

<?php
}

}

function 
mouse__SendHeader() {

global $context;

header ('Content-Type: text/plain; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' $context['character_set']));

}

function 
mouse__JsEsc($x) {
return strtr($x, array(
'\\' => '\\\\',
'\'' => '\\\'',
"\r" => '\r',
"\n" => '\n',
"\t" => '\t'
));
}

function 
mouse__CreateJSON($x) {
$o '';
$n 0;
foreach ($x as $k => $v) {
$o .= ($n ', ' '') . '\'' mouse__JsEsc($k) . '\': ' . ('\'' mouse__JsEsc($v) . '\'');
$n 1;
}
return '({ ' $o ' })';
}

function 
mouse__IsNotGuest () {

global $context;
if ($context['user']['is_guest'])
mouse__Error ('บุคคลทั่วไปไม่สามารถสนทนาในห้องนี้ได้!');

}

function 
mouse__CheckDBChat () {

        if (!
file_exists(DB))
               
fatal_error (DB ' does not exist');

}

function 
mouse__Error ($msg) {
mouse__SendHeader ();
echo mouse__CreateJSON(array(
'error' => $msg
));
exit;
}

function 
mouse__Get () {

mouse__IsNotGuest ();

global $context$db_prefix$scripturl;

mouse__SendHeader ();

        
$db LoadDBChat(); 

$ou = array(); 
$ou2 = array(); 
        if (
trim(file_get_contents(DB)) && isset ($db['talk'])) {
        
$dbz array_reverse($db['talk']);
        
$i 0;
         foreach (
$dbz as $op => $tt) {
             
$__DB $dbz[$op];
              if (
$i >= FIRST) break;
                      if (
$__DB['to'] == $context['user']['id'])
                           
$ou[] = ShowDB($__DB1);
                      if (
$__DB['id'] == $context['user']['id'] && $__DB['to'] != 0)
                           
$ou[] = ShowDB($__DB2);  
                      if (
$__DB['to'] == 0)
                           
$ou[] = ShowDB($__DB0);
              
$i++;
            }
         }
           
$db['online'][$context['user']['id']] = time(); 

          foreach (
$db['online'] as $oo => $vv) {
              
              if (
time() - $vv TIMEOUT) { 
               
$user LoadColorMem($oo); 
               
$ou2[] = mouse__CreateJSON(array( 
                                  'id'   => $oo,
                                          
'name' => $user['real_name'],
                                          
'color' => $user['color']
                           ));
              } else {
               unset(
$db['online'][$oo]); 
            }

          }
        
echo '[[
implode(',
'
array_reverse($ou)) . '
], [
implode(',
'
array_reverse($ou2)) . '
]]'
;

        
SaveDBChat ($db); 

obExit (false);

}

function 
mouse__Post () {

mouse__IsNotGuest ();

global $context$db_prefix$sourcedir,$user_info;

$text htmlspecialchars($_POST['text']); 
$sto  0

if (trim($text) == '') {
mouse__Error ('The text is blank!');
}
if (preg_match('~^/pm\s+(\d+)~'$text$m)) { 
$sto $m[1];
$text preg_replace('~^/pm\s+\d+\s+~'''$text); 
}

require_once $sourcedir '/Subs-Post.php'
preparsecode ($text);

          
$allm LoadDBChat (); 
          
$allm['talk'] = isset($allm['talk']) ? $allm['talk'] : array();
          
$allm['talk'][] = array('id' => $context['user']['id'],
                          
'idm' => count($allm['talk']),
                          
'to' => $sto,
                          
'time' => time(),
                          
'text' => $text
                          
);
          
SaveDBChat ($allm); 

mouse__Get ();

}

function 
LoadColorMem ($z) {
        global 
$user_profile;
          
loadMemberData ($z);
          
$uda $user_profile[$z];
          
$res = array (
                        
'realName' => $uda['real_name'],
                        
'color' => trim($uda['post_group_color']) 
                                   ? 
$uda['post_group_color'
                                   : 
$uda['member_group_color']
                       );
          return 
$res;
}

function 
SaveDBChat ($z) {

          
$fp fopen(DB'w');
          
fputs($fpserialize($z));
          
fclose($fp); 

}

function 
LoadDBChat () {

          return (!
trim(file_get_contents(DB))) ? '' unserialize(file_get_contents(DB));

}

function 
ShowDB ($z$p) {

           
$user LoadColorMem($z['id']);
           
$zz mouse__CreateJSON(array(
                      
'idm'   => $z['idm'],
                      
'id' => $z['id'],
                      
'name' => $user['real_name'],
                      
'color' => $user['color'],
                  'date' => timeformat($z['time']),
              'text' => stripslashes(parse_bbc($z['text'])),
                      
'raw' => stripslashes(un_htmlspecialchars($z['text'])),
              'priv' => $p
    ));

           return 
$zz;
}
?>


What wrong is it????

but I can run this code with 1.1.x

thx


CapadY

Database handling in SMF2 is totaly different from SMF1.1.x so all database handlings have to be rewritten.

Also names and content  of vaiables are changed.
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Advertisement: