czat.php
Kod: Zaznacz cały
<div id="daddy-shoutbox">
<script type="text/javascript" src="/bbcode.js"></script>
<script type="text/javascript" src="/adds.js"></script>
<script language="Javascript" src="editor.js"></script>
<div id="daddy-shoutbox-list"></div>
<br />
<form id="daddy-shoutbox-form" action="/shoutbox/daddy-shoutbox.php?action=add" method="post">
<fieldset>
<div>
<div class="bbcode">
<button type="button" onclick="Format('bold')">B</button>
<button type="button" onclick="Format('italic')">I</button>
<button type="button" onclick="Format('underline')">U</button>
<select onchange="if (this.selectedIndex > 0) Colour(this.options[this.selectedIndex].value)">
<option>Kolor</option>
<option value="darkred" style="color:darkred">Ciemnoczerwony</option>
<option value="red" style="color:red">Czerwony</option>
<option value="orange" style="color:orange">Pomarańczowy</option>
<option value="brown" style="color:brown">Brązowy</option>
<option value="yellow" style="color:yellow">Żółty</option>
<option value="green" style="color:green">Zielony</option>
<option value="olive" style="color:olive">Oliwkowy</option>
<option value="cyan" style="color:cyan">Błękitny</option>
<option value="blue" style="color:blue">Niebieski</option>
<option value="darkblue" style="color:darkblue">Ciemnoniebieski</option>
<option value="indigo" style="color:indigo">Purpurowy</option>
<option value="violet" style="color:violet">Fioletowy</option>
<option value="white" style="color:white">Biały</option>
<option value="black" style="color:black">Czarny</option>
</select>
<button type="button" onclick="return pokazPasekEmotek();">Emotki</button>
</div>
<div id="lista-emotek" style="display: none">
<?php
$listaEmotek=array();
$listaEmotek['graph']=array('biggrin','confused','cool','cry','curve','eek','evil','exclaim','idea','lol','mad','mrgreen','neutral','razz','eusathink','redface','rolleyes','sad','smile','smile2','square','surprised','wink','question','arrow');
$listaEmotek['text']=array(':-D',':-?','8-)',':cry:',':-/',':shock:',':evil:',':!:',':idea:',':lol:',':-x',':mrgreen:',':-}',':-P',':-k',':oops:',':roll:',':-(',':-)',':->',':-]',':-o',';-)',':?:',':arrow:');
for ($i=0;$i<count($listaEmotek['graph']);$i++)
echo '<img class="emotka" src="/shoutbox/images/emotki/icon_'. $listaEmotek['graph'][$i] .'.gif" onclick="InsertImage(\''. $listaEmotek['graph'][$i] .'\');" title=" '.$listaEmotek['text'][$i].' ">';
?>
</div>
<iframe id="message" scrolling="no"></iframe>
<input type="hidden" name="message" value="">
<input type="hidden" name="nickname" value="<?php echo _e($_SESSION['username']); ?>">
<span id="daddy-shoutbox-response"></span>
<input type="submit" value="Wyślij" />
</fieldset>
</form>
</div>
<script type="text/javascript" src="/shoutbox/javascript/jquery.js"></script>
<script type="text/javascript" src="/shoutbox/javascript/jquery.form.js"></script>
<script type="text/javascript">
var adminNickName = 'NorthAngel';
var count = 0;
var files = '/shoutbox/';
var lastTime = 0;
var Editor;
function Format(action)
{
Editor.execCommand(action, false, null);
}
function Colour(colour)
{
Editor.execCommand("forecolor",false, colour);
}
function InsertImage(image)
{
image = '/shoutbox/images/emotki/icon_'+image+'.gif';
if (!Editor.execCommand('insertImage',false, image))
{
Editor.body.focus();
range = Editor.selection.createRange();
range.pasteHTML('<img src="'+image+'">');
}
}
function pokazPasekEmotek()
{
if (document.getElementById('lista-emotek').style.display=='none')
document.getElementById('lista-emotek').style.display='block';
else
document.getElementById('lista-emotek').style.display='none';
return false;
}
function konwertujEmotki(text)
{
text=text.replace(/ /gi,' ');
<?php
for ($i=0;$i<count($listaEmotek['graph']);$i++)
echo ' text=text.replace(/'. preg_replace('/([\/\\\?\:\(\)\|\-])/mi','\\\\$1',$listaEmotek['text'][$i]) .'/gi,\'<img class="emotka" src="/shoutbox/images/emotki/icon_'. $listaEmotek['graph'][$i] .'.gif" title=" '.$listaEmotek['text'][$i].' ">\');' ."\n";
?>
text=text.replace(/\:\->/gi,'<img class="emotka" src="/shoutbox/images/emotki/icon_smile2.gif" title=" :-> ">');
return text;
}
function html2bbcode(text)
{
for (var i=0;i<9;i++)
{
text=text.replace(/<br>/gi,'');
text=text.replace(/<p>/gi,'');
text=text.replace(/<\/p>/gi,'');
text=text.replace(/<span>/gi,'');
text=text.replace(/<\/span>/gi,'');
text=text.replace(/<div>/gi,'');
text=text.replace(/<\/div>/gi,'');
text=text.replace(/<b>(.*?)<\/b>/gi,'[b]$1[/b]');
text=text.replace(/<i>(.*?)<\/i>/gi,'[i]$1[/i]');
text=text.replace(/<u>(.*?)<\/u>/gi,'[u]$1[/u]');
text=text.replace(/<strong>(.*?)<\/strong>/gi,'[b]$1[/b]');
text=text.replace(/<em>(.*?)<\/em>/gi,'[i]$1[/i]');
text=text.replace(/<font color="(.*?)">(.*?)<\/font>/gi,'[color=$1]$2[/color]');
text=text.replace(/<b style="color:\s*(.*?);*">(.*?)<\/b>/gi,'[b][color=$1]$2[/color][/b]');
text=text.replace(/<i style="color:\s*(.*?);*">(.*?)<\/i>/gi,'[i][color=$1]$2[/color][/i]');
text=text.replace(/<u style="color:\s*(.*?);*">(.*?)<\/u>/gi,'[u][color=$1]$2[/color][/u]');
text=text.replace(/<u style="font-weight:\s*bold;\s*color:\s*(.*?);*">(.*?)<\/u>/gi,'[u][b][color=$1]$2[/color][b][/u]');
text=text.replace(/<i style="font-weight:\s*bold;\s*color:\s*(.*?);*">(.*?)<\/i>/gi,'[i][b][color=$1]$2[/color][b][/i]');
text=text.replace(/<span style="color:\s*(.*?)(;[^"]*?)">(.*?)<\/u>/gi,'[color=$1]$3[/color]');
text=text.replace(/<span[^>]*?>/gi,'$1');
}
<?php
for ($i=0;$i<count($listaEmotek['graph']);$i++)
echo ' text=text.replace(/<img src="\/shoutbox\/images\/emotki\/icon_'.$listaEmotek['graph'][$i].'\.gif">/gi,\''.preg_replace('/>/mi','>',$listaEmotek['text'][$i]).'\');'."\n";
?>
return text;
}
function pressedEnter(e)
{
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13)
{
e.preventDefault();
e.stopPropagation();
$('#daddy-shoutbox-form').submit();
}
}
function prepare(response, pozycja) {
var d = new Date();
count++;
d.setTime(response.time*1000);
var godzina = d.getHours();
var minuta = d.getMinutes();
var mytime = ['(', godzina > 9 ? '' : '0', godzina, ':', minuta > 9 ? '' : '0', minuta, ')'].join('');
var string = '<div class="shoutbox-list' + (pozycja % 2 ? ' co_drugi_wpis' : '') + '" id="list-'+count+'">'
+ '<span class="shoutbox-list-time">'+mytime+'</span>'
+ '<span class="shoutbox-list-nick'+(response.nickname==adminNickName?' admin':(response.nickname=='<?php echo _e($_SESSION['username']); ?>'?' thisuser':''))+'">'+response.nickname+':</span>'
+ '<span class="shoutbox-list-message">'+konwertujEmotki(response.message)+'</span>'
+'</div>';
return string;
}
function success(response, status) {
if(status == 'success') {
lastTime = response.time;
$('#daddy-shoutbox-response').html('<img src="'+files+'images/accept.png" />');
$('#daddy-shoutbox-list').append(prepare(response, $('#daddy-shoutbox-list').children().length));
$('input[@name=message]').attr('value', '').focus();
Editor.body.innerHTML='';
$('#list-'+count).fadeIn('slow');
var a = document.getElementById('daddy-shoutbox-list');
a.scrollTop = a.scrollHeight;
timeoutID = setTimeout(refresh, 3000);
}
}
function validate(formData, jqForm, options) {
formData[0].value=html2bbcode(Editor.body.innerHTML);
$('input[@name=message]').val('');
for (var i=0; i < formData.length; i++) {
if (!formData[i].value) {
alert('Please fill in all the fields');
$('input[@name='+formData[i].name+']').css('background', 'red');
return false;
}
}
$('#daddy-shoutbox-response').html('<img src="'+files+'images/loader.gif" />');
clearTimeout(timeoutID);
}
function refresh() {
$.getJSON(files+"daddy-shoutbox.php?action=view&time="+lastTime, function(json) {
if(json.length) {
for(i=0; i < json.length; i++) {
$('#daddy-shoutbox-list').append(prepare(json[i], $('#daddy-shoutbox-list').children().length));
$('#list-' + count).fadeIn('slow');
}
var j = i-1;
lastTime = json[j].time;
}
//alert(lastTime);
});
var a = document.getElementById('daddy-shoutbox-list');
a.scrollTop = a.scrollHeight;
timeoutID = setTimeout(refresh, 3000);
}
// wait for the DOM to be loaded
$(document).ready(function() {
var options = {
dataType: 'json',
beforeSubmit: validate,
success: success
};
$('#daddy-shoutbox-form').ajaxForm(options);
var a = document.getElementById('daddy-shoutbox-list');
a.scrollTop = a.scrollHeight;
timeoutID = setTimeout(refresh, 100);
Editor = document.getElementById('message').contentWindow.document;
Editor.body.contentEditable = true;
Editor.body.onkeypress=pressedEnter;
Editor.parentNode.onkeydown=pressedEnter;
Editor.designMode = "on";
});
</script>
Login: Test
hasło: lkjuio7