• Revista PROGRAMAR: Já está disponível a edição #53 da revista programar. Faz já o download aqui!

Fabriziopt

Shoutbox

5 mensagens neste tópico

Boas

Estou a entrar neste tipo de programaçao e estou em duvida para o codigo shoutbox.

Ja tentei varios entre os quais de diferente tipo de ligaçoes.Como exemplo um guardava os dados numa base de dados (mysql), este dava erro da base de daddos e outra num ficheiro texto que tinha no servidor so para isso, este nao mostrava a mensagem, embra nao mostrasse erros.

Queria que alguma pessoa me ajudasse a "acertar" com o codigo B)

Abraço

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Desde ja obrigado por me responderem:

shout.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="imagetoolbar" content="no">
<link rel="stylesheet" href="common.css" type="text/css">
<base target="_self">
<title>Tran Tien Dung - Shoutbox</title>
</head>
<body class="shoutboxbody" style="overflow-x: hidden;">
<?
]
$filename = "./shoutdb.txt";

$usemask = "yes";
$link_mask = "[link]";
$email_mask = "[email]";

$smileydir = './images/';
]
$smileys = array (
"[]" => "smile.gif",
"[)]" => "lol.gif",
"[]" => "sad.gif",
);

function alter_smiley(&$item1, $key, $prefix) {
$item1 = " <img alt=\"\" src=\"$prefix$item1\" align=\"middle\" border=\"0\" />";
}
function removeBadWords(&$text) {
$badwords = array(
"/fu.ck/",
"/sh.it/"
);
for ($i=0;$i<count($badwords);$i++)
$text = preg_replace($badwords[$i], "[]", $text);
}

// This takes the post vars
extract($_POST);

$errorMsg = "";

if($submit) { 
if(!$name) $errorMsg.="You need to input a name!<br>";
elseif(!$shout) $errorMsg.="You need to make a shout!<br>";
elseif(($name=="Name") || ($shout=="Message")) $errorMsg.="Slacker! Say something mate.<br>";

else {
if($site) $author = "<a href='$site'>$name</a>";
else $author = $name;

$handle = fopen($filename,"a");

// Date...
$date = strftime("%D");
$time = strftime("%T");

$ipaddr = $REMOTE_ADDR;

removeBadWords($shout);

// this is how a shout will be stored in your database file
// you can change this to your taste but do remember to change the code reading the file
$data = "$author | $date | $time | $ipaddr | $shout\n";
fwrite($handle,"$data");
fclose($handle);
}
}

echo $errorMsg;
/************* SHOW FORM *****************/
echo "<table class=\"SB_formarea\" width=\"100%\" border=\"0\">\n";
echo "<tr><td>\n";
echo "<form method=\"post\" action=\"shout.php\">\n";
echo "<div align=\"center\"><input type=\"text\" name=\"name\" size=\"16\" value=\"Name\" maxlength=\"14\" title=\"Name\" class=\"SB_input\"><br>\n";
echo "<input type=\"text\" name=\"shout\" size=\"16\" value=\"Message\" maxlength=\"1024\" title=\"Message\" class=\"SB_input\"><br>\n";
echo "<input type=\"submit\" name=\"submit\" value=\":: send ::\" class=\"SB_button\">\n";
echo "<input type=\"button\" name=\"refresh_it\" value=\"::\" class='SB_button' onclick=\"window.open('shout.php','_self');\">\n";
echo "</div></td></tr></form></table>\n"

$shouts = file($filename); 
$rowColor = 0;
$count = 0;
array_walk ($smileys, 'alter_smiley', $smileydir);

krsort($shouts);


$link_search = array("/\</",
    "/\>/",
    "/\]/",
    "/\[/",
    "#([\n ])([a-z0-9\-_.]+?)@([^, \n\r]+)#i",
    "#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^, \n\r]*)?)#i",
    "/(?<!<a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i");
if ($usemask=='yes')
$link_replace = array("<",
    ">",
    ">",
    "<",
    "\\1<a href=\"mailto:\\2@\\3\">".$email_mask."</a>",
    "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">".$link_mask."</a>",
    "<a href=\"\\0\" target=\"_blank\">".$link_mask."</a>");
else
$link_replace = array("<",
    ">",
    ">",
    "<",
    "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>",
    "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>",
    "<a href=\"\\0\" target=\"_blank\">\\0</a>");

foreach($shouts as $sbox) {
$count++;

list($auth,$date,$time,$ipaddr,$shout) = explode(" | ", $sbox);

$shout = " ".$shout;
$shout = preg_replace($link_search, $link_replace, $shout);

$shout = strtr($shout, $smileys);

$shout = chop($shout);

echo "<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" width=\"100%\" class=\"SB_table$rowColor\"><tr><td class=\"SB_shoutbox\" title='$time $date $ipaddr'><b>$auth</b>: $shout</td></tr></table>\n";

if ($rowColor==0) $rowColor = 1;
else $rowColor = 0;
}
?>
</body>
</html>

common.css

.shoutboxbody {
background-color : #F6FAF9;
font: 8pt;
scrollbar-face-color: #F5F5F5;
scrollbar-highlight-color: #74612A;
scrollbar-shadow-color: White;
scrollbar-3d-light-color: #D1D7DC;
scrollbar-arrow-color: #756023;
scrollbar-track-color: #F8F8FF;
scrollbar-dark-shadow-color: #98AAB1;
font-family: Tahoma, Arial, Verdana, Times;
color: #2A7400;
margin: 0;
}

a:link,a:active,a:visited {
font-size : 8pt;
color : #164000;
text-decoration : none;
}

a:hover {
font-size : 8pt;
text-decoration: underline;
}

td {
font-size : 8pt;
font-family: Verdana, Arial, Tahoma, Times, sans-serif;
}

.SB_button {
background : #DDDDDD;
border : 1px solid #C0C0C0;
color : #2A7400;
font-family: Tahoma, Arial, Verdana, Times, sans-serif;
font-size : 8pt;
font-weight : bold;
}

.SB_input {
background : #F6FAF9;
border : 1px solid #DDDDDD;
color : #2A7400;
font-family: Tahoma, Arial, Verdana, Times, sans-serif;
font-size : 8pt;
}

.SB_formarea {
background-color : #F6FAF9;
border-bottom-color : #FFFFFF;
border-bottom-style : none;
border-bottom-width : 1px;
border-left-color : #FFFFFF;
border-left-style : none;
border-left-width : 1px;
border-right-style : solid;
border-right-width : 1px;
border-top-style : solid;
border-top-width : 1px;
color : #2A7400;
font-size : 8pt;
}

.SB_shoutbox {
color : #2A7400;
font-family: Tahoma, Arial, Verdana, Times, sans-serif;
font-size : 8pt;
text-align : left;
}

.SB_table0 {
background-color : #F6FAF9;
border-bottom-color : #CBE2DD;
border-bottom-style : none;
border-bottom-width : 1px;
border-left-color : #CBE2DD;
border-left-style : none;
border-left-width : 1px;
border-right-color : #CBE2DD;
border-right-style : none;
border-right-width : 1px;
border-top-color : #CBE2DD;
border-top-style : solid;
border-top-width : 1px;
color : #2A7400;
font-size : 8pt;
}

.SB_table1 {
background-color : #F6FAF9;
border-bottom-color : #CBE2DD;
border-bottom-style : none;
border-bottom-width : 1px;
border-left-color : #CBE2DD;
border-left-style : none;
border-left-width : 1px;
border-right-color : #CBE2DD;
border-right-style : none;
border-right-width : 1px;
border-top-color : #CBE2DD;
border-top-style : solid;
border-top-width : 1px;
color : #2A7400;
font-size : 8pt;
}

Obrigado por tudo
Abraço

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Tenta com este código! : D

Apenas um pormenor, devias retirar o último butão do formulário (o butão de "::" que não tem o que é necessário para funcionar correctamente)

Agora explicar o que alterei; não sei se tinhas separado ou não, mas a partir da linha "common.css" era outro ficheiro com o mesmo nome que representa o estilo da página. Agora esse pedaço de código fica no inicio da página.

Depois havia um erro muito importante, porque antes de alguem enviar algum shout, o ficheiro $filename devia ser criado. Agora está tudo automático e se copiares e colares isso deve funcionar logo á primeira :thumbsup:

Cumprimentos.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="imagetoolbar" content="no">
<base target="_self">
<title>Tran Tien Dung - Shoutbox</title>
<style type="text/css">
.shoutboxbody {
background-color : #F6FAF9;
font: 8pt;
scrollbar-face-color: #F5F5F5;
scrollbar-highlight-color: #74612A;
scrollbar-shadow-color: White;
scrollbar-3d-light-color: #D1D7DC;
scrollbar-arrow-color: #756023;
scrollbar-track-color: #F8F8FF;
scrollbar-dark-shadow-color: #98AAB1;
font-family: Tahoma, Arial, Verdana, Times;
color: #2A7400;
margin: 0;
}

a:link,a:active,a:visited {
font-size : 8pt;
color : #164000;
text-decoration : none;
}

a:hover {
font-size : 8pt;
text-decoration: underline;
}

td {
font-size : 8pt;
font-family: Verdana, Arial, Tahoma, Times, sans-serif;
}

.SB_button {
background : #DDDDDD;
border : 1px solid #C0C0C0;
color : #2A7400;
font-family: Tahoma, Arial, Verdana, Times, sans-serif;
font-size : 8pt;
font-weight : bold;
}

.SB_input {
background : #F6FAF9;
border : 1px solid #DDDDDD;
color : #2A7400;
font-family: Tahoma, Arial, Verdana, Times, sans-serif;
font-size : 8pt;
}

.SB_formarea {
background-color : #F6FAF9;
border-bottom-color : #FFFFFF;
border-bottom-style : none;
border-bottom-width : 1px;
border-left-color : #FFFFFF;
border-left-style : none;
border-left-width : 1px;
border-right-style : solid;
border-right-width : 1px;
border-top-style : solid;
border-top-width : 1px;
color : #2A7400;
font-size : 8pt;
}

.SB_shoutbox {
color : #2A7400;
font-family: Tahoma, Arial, Verdana, Times, sans-serif;
font-size : 8pt;
text-align : left;
}

.SB_table0 {
background-color : #F6FAF9;
border-bottom-color : #CBE2DD;
border-bottom-style : none;
border-bottom-width : 1px;
border-left-color : #CBE2DD;
border-left-style : none;
border-left-width : 1px;
border-right-color : #CBE2DD;
border-right-style : none;
border-right-width : 1px;
border-top-color : #CBE2DD;
border-top-style : solid;
border-top-width : 1px;
color : #2A7400;
font-size : 8pt;
}

.SB_table1 {
background-color : #F6FAF9;
border-bottom-color : #CBE2DD;
border-bottom-style : none;
border-bottom-width : 1px;
border-left-color : #CBE2DD;
border-left-style : none;
border-left-width : 1px;
border-right-color : #CBE2DD;
border-right-style : none;
border-right-width : 1px;
border-top-color : #CBE2DD;
border-top-style : solid;
border-top-width : 1px;
color : #2A7400;
font-size : 8pt;
}
</style>
</head>
<body class="shoutboxbody" style="overflow-x: hidden;">
<?php

$filename = "shoutdb.txt";

if ( !file_exists($filename) )
{
$temporary = fopen($filename, "w");
fclose($temporary);
}

$usemask = "yes";
$link_mask = "[link]";
$email_mask = "[email]";

$smileydir = './images/';

$smileys = array (
"[]" => "smile.gif",
"[)]" => "lol.gif",
"[]" => "sad.gif",
);

function alter_smiley(&$item1, $key, $prefix) {
$item1 = " <img alt=\"\" src=\"$prefix$item1\" align=\"middle\" border=\"0\" />";
}
function removeBadWords(&$text) {
$badwords = array(
"/fu.ck/",
"/sh.it/"
);
for ($i=0;$i<count($badwords);$i++)
$text = preg_replace($badwords[$i], "[]", $text);
}

// This takes the post vars
extract($_POST);

$errorMsg = "";

if($submit) { 
if(!$name) $errorMsg.="You need to input a name!<br>";
elseif(!$shout) $errorMsg.="You need to make a shout!<br>";
elseif(($name=="Name") || ($shout=="Message")) $errorMsg.="Slacker! Say something mate.<br>";

else {
if($site) $author = "<a href='$site'>$name</a>";
else $author = $name;

$handle = fopen($filename,"a");


$date = strftime("%D");
$time = strftime("%T");

$ipaddr = $REMOTE_ADDR;

removeBadWords($shout);

$data = "$author | $date | $time | $ipaddr | $shout\n";
fwrite($handle,"$data");
fclose($handle);
}
}

echo $errorMsg;

echo "<table class=\"SB_formarea\" width=\"100%\" border=\"0\">\n";
echo "<tr><td>\n";
echo "<form method=\"post\" action=\"shout.php\">\n";
echo "<div align=\"center\"><input type=\"text\" name=\"name\" size=\"16\" value=\"Name\" maxlength=\"14\" title=\"Name\" class=\"SB_input\"><br>\n";
echo "<input type=\"text\" name=\"shout\" size=\"16\" value=\"Message\" maxlength=\"1024\" title=\"Message\" class=\"SB_input\"><br>\n";
echo "<input type=\"submit\" name=\"submit\" value=\":: send ::\" class=\"SB_button\">\n";
echo "<input type=\"button\" name=\"refresh_it\" value=\"::\" class='SB_button' onclick=\"window.open('shout.php','_self');\">\n";
echo "</div></td></tr></form></table>\n";

$shouts = file($filename); 
$rowColor = 0;
$count = 0;
array_walk ($smileys, 'alter_smiley', $smileydir);

krsort($shouts);


$link_search = array("/\</",
    "/\>/",
    "/\]/",
    "/\[/",
    "#([\n ])([a-z0-9\-_.]+?)@([^, \n\r]+)#i",
    "#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^, \n\r]*)?)#i",
    "/(?<!<a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i");
if ($usemask=='yes')
$link_replace = array("<",
    ">",
    ">",
    "<",
    "\\1<a href=\"mailto:\\2@\\3\">".$email_mask."</a>",
    "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">".$link_mask."</a>",
    "<a href=\"\\0\" target=\"_blank\">".$link_mask."</a>");
else
$link_replace = array("<",
    ">",
    ">",
    "<",
    "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>",
    "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>",
    "<a href=\"\\0\" target=\"_blank\">\\0</a>");

foreach($shouts as $sbox) {
$count++;

list($auth,$date,$time,$ipaddr,$shout) = explode(" | ", $sbox);

$shout = " ".$shout;
$shout = preg_replace($link_search, $link_replace, $shout);

$shout = strtr($shout, $smileys);

$shout = chop($shout);

echo "<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" width=\"100%\" class=\"SB_table$rowColor\"><tr><td class=\"SB_shoutbox\" title='$time $date $ipaddr'><b>$auth</b>: $shout</td></tr></table>\n";

if ($rowColor==0) $rowColor = 1;
else $rowColor = 0;
}
?>
</body>
</html>
 
0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Para colocarem dúvidas existe uma secção interna em cada área denominada Dúvidas e Ajudas.

Por favor utilizem essa secção de forma a poupar trabalho aos Moderadores para moverem tópicos.

Obrigado

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!


Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.


Entrar Agora