Bywalec
Postów: 888 Pomógł: 66
Data rejestracji: 19.08.2007 19:49
|
Witam!
Chciałem stworzyć sobie shoutbox podobny do tego bartka (na moim hostingu tamten nie działa). Zaczynam więc od auto odświeżania postów i znalazłem taki kod:
<script>
var refreshPost = setInterval(function(){$('#post').fadeOut("slow").fadeIn("slow");}, 5000);
</script>
<div id="post">
Odświeżanie
</div>
Kliknij i zaczekaj na załadowanie kodu ...
Wklejone w dodatkowych stronach działa, ale jak próbuję to rozłączyć to przestaje odświeżać.
Tak więc tworzę plik func.js, w którym znajduje się:
var refreshPost = setInterval(function(){$('#post').fadeOut("slow").fadeIn("slow");}, 5000);
Kliknij i zaczekaj na załadowanie kodu ...
Includuję go do pliku shoutbox_window.php (oddzielne okienko dla shoutboxa). Otaczam divem wszystko w tym pliku prócz pola tekstowego do pisania wiadomości.
Shoutbox_window.php z dodanym divem:
<?php
require_once "../../maincore.php";
require_once "../../infusions/shoutbox_panel/header.php";
if (!defined("IN_FUSION")) { die("Access Denied"); }
$link = FUSION_SELF.(FUSION_QUERY ? "?".FUSION_QUERY : "");
$link = preg_replace("^(&|\?)s_action=(edit|delete)&shout_id=\d*^", "", $link);
$sep = stristr($link, "?") ? "&" : "?";
if (iMEMBER && (isset($_GET['s_action']) && $_GET['s_action'] == "delete") && (isset($_GET['shout_id']) && isnum($_GET['shout_id']))) {
if ((iADMIN && checkrights("S")) || (iMEMBER && dbcount("(shout_id)", DB_SHOUTBOX, "shout_id='".$_GET['shout_id']."' AND shout_name='".$userdata['user_id']."'"))) {
$result = dbquery("DELETE FROM ".DB_SHOUTBOX." WHERE shout_id='".$_GET['shout_id']."'".(iADMIN ? "" : " AND shout_name='".$userdata['user_id']."'"));
}
redirect($link);
}
function sbwrap($text) {
$i = 0; $tags = 0; $chars = 0; $res = "";
$str_len = strlen($text);
for ($i = 0; $i < $str_len; $i++) {
$chr = substr($text, $i, 1);
if ($chr == "<") {
if (substr($text, ($i + 1), 6) == "a href" || substr($text, ($i + 1), 3) == "img") {
$chr = " ".$chr;
$chars = 0;
}
$tags++;
} elseif ($chr == "&") {
if (substr($text, ($i + 1), 5) == "quot;") {
$chars = $chars - 5;
} elseif (substr($text, ($i + 1), 4) == "amp;" || substr($text, ($i + 1), 4) == "#39;" || substr($text, ($i + 1), 4) == "#92;") {
$chars = $chars - 4;
} elseif (substr($text, ($i + 1), 3) == "lt;" || substr($text, ($i + 1), 3) == "gt;") {
$chars = $chars - 3;
}
} elseif ($chr == ">") {
$tags--;
} elseif ($chr == " ") {
$chars = 0;
} elseif (!$tags) {
$chars++;
}
if (!$tags && $chars == 18) {
$chr .= "<br />";
$chars = 0;
}
$res .= $chr;
}
return $res;
}
if (iMEMBER || $settings['guestposts'] == "1") {
include_once INCLUDES."bbcode_include.php";
if (isset($_POST['post_shout'])) {
$flood = false;
if (iMEMBER) {
$shout_name = $userdata['user_id'];
} elseif ($settings['guestposts'] == "1") {
$shout_name = trim(stripinput($_POST['shout_name']));
$shout_name = preg_replace("(^[0-9]*)", "", $shout_name);
if (isnum($shout_name)) { $shout_name = ""; }
include_once INCLUDES."securimage/securimage.php";
$securimage = new Securimage();
if (!isset($_POST['sb_captcha_code']) || $securimage->check($_POST['sb_captcha_code']) == false) { redirect($link); }
}
$shout_message = str_replace("\n", " ", $_POST['shout_message']);
$shout_message = preg_replace("/^(.{255}).*$/", "$1", $shout_message);
$shout_message = trim(stripinput(censorwords($shout_message)));
if (iMEMBER && (isset($_GET['s_action']) && $_GET['s_action'] == "edit") && (isset($_GET['shout_id']) && isnum($_GET['shout_id']))) {
$comment_updated = false;
if ((iADMIN && checkrights("S")) || (iMEMBER && dbcount("(shout_id)", DB_SHOUTBOX, "shout_id='".$_GET['shout_id']."' AND shout_name='".$userdata['user_id']."'"))) {
if ($shout_message) {
$result = dbquery("UPDATE ".DB_SHOUTBOX." SET shout_message='$shout_message' WHERE shout_id='".$_GET['shout_id']."'".(iADMIN ? "" : " AND shout_name='".$userdata['user_id']."'"));
}
}
redirect($link);
} elseif ($shout_name && $shout_message) {
require_once INCLUDES."flood_include.php";
if (!flood_control("shout_datestamp", DB_SHOUTBOX, "shout_ip='".USER_IP."'")) {
$result = dbquery("INSERT INTO ".DB_SHOUTBOX." (shout_name, shout_message, shout_datestamp, shout_ip) VALUES ('$shout_name', '$shout_message', '".time()."', '".USER_IP."')");
}
}
redirect($link);
}
if (iMEMBER && (isset($_GET['s_action']) && $_GET['s_action'] == "edit") && (isset($_GET['shout_id']) && isnum($_GET['shout_id']))) {
$esresult = dbquery(
"SELECT ts.*, tu.user_id, tu.user_name FROM ".DB_SHOUTBOX." ts
LEFT JOIN ".DB_USERS." tu ON ts.shout_name=tu.user_id
WHERE ts.shout_id='".$_GET['shout_id']."'"
);
if (dbrows($esresult)) {
$esdata = dbarray($esresult);
if ((iADMIN && checkrights("S")) || (iMEMBER && $esdata['shout_name'] == $userdata['user_id'] && isset($esdata['user_name']))) {
if ((isset($_GET['s_action']) && $_GET['s_action'] == "edit") && (isset($_GET['shout_id']) && isnum($_GET['shout_id']))) {
$edit_url = $sep."s_action=edit&shout_id=".$esdata['shout_id'];
} else {
$edit_url = "";
}
$shout_link = $link.$edit_url;
$shout_message = $esdata['shout_message'];
}
} else {
$shout_link = $link;
$shout_message = "";
}
} else {
$shout_link = $link;
$shout_message = "";
}
echo "<a id='edit_shout' name='edit_shout'></a>\n";
echo "<form name='shout_form' method='post' action='".$shout_link."'>\n";
echo "<center>\n<textarea name='shout_message' rows='4' cols='20' class='sbtext'>".$shout_message."</textarea> ";
echo "<input type='submit' name='post_shout' value='".$locale['global_153']."' class='sbsubmit' />\n</center>\n";
echo "</form>\n<br />\n";
} else {
echo "<div style='text-align:center'>".$locale['global_154']."</div><br />\n";
}
$numrows = dbcount("(shout_id)", DB_SHOUTBOX);
$result = dbquery(
"SELECT ts.*, tu.user_id, tu.user_name, tu.user_avatar_sb FROM ".DB_SHOUTBOX." ts
LEFT JOIN ".DB_USERS." tu ON ts.shout_name=tu.user_id
ORDER BY ts.shout_datestamp DESC LIMIT 0,".$settings['numofshouts']);
if (dbrows($result)) {
$i = 0;
echo "<div id='post'>";
while ($data = dbarray($result)) {
echo "<div class='shoutboxdate' align='left' style='padding: 0px 0px 0px 8px;'>".showdate("longdate", $data['shout_datestamp'])."</div>";
echo "<cetner>\n";
echo "<table cellspacing='0' cellpadding='0' border='0'>\n";
echo "<tr>\n";
echo "<td class='sbp1'></td>\n";
echo "<td class='sbp2'></td>\n";
echo "<td class='sbp3'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='sbp4'></td>\n";
echo "<td class='sbp5'>\n";
echo "<table cellspacing='0' cellpadding='0' border='0'>\n";
echo "<tr>\n<td width='55' height='55' style='text-align: center;'>\n";
if ($data['user_avatar_sb']) {
echo "<img src='".BASEDIR."images/avatars_sb/".$data['user_avatar_sb']."' alt='".$data['user_name']."'>";
} else {
echo "<img src='".BASEDIR."images/no_sb.png' alt='".$data['user_name']."'>";
}
echo "</td>\n<td valign='top'>";
echo "<font style='color: #ffffff; font-size: 11px;'>Autor:</font> <a href='".BASEDIR."profile.php?lookup=".$data['shout_name']."' class='shoutboxname'>".$data['user_name']."</a>\n";
if ((iADMIN && checkrights("S")) || (iMEMBER && $data['shout_name'] == $userdata['user_id'] && isset($data['user_name']))) {
echo "[<a href='".$link.$sep."s_action=edit&shout_id=".$data['shout_id']."#edit_shout"."' style='color: #ffffff; font-size: 11px;'>E</a>|";
echo "<a href='".$link.$sep."s_action=delete&shout_id=".$data['shout_id']."' style='color: #ffffff; font-size: 11px;'>U</a>]\n";
}
echo"<br />\n";
echo "".sbwrap(parseubb(parsesmileys($data['shout_message']), "b|i|u|url|color"))."\n";
echo "</td>\n</tr>\n</table>\n";
echo "</td>\n";
echo "<td class='sbp6'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='sbp7'></td>\n";
echo "<td class='sbp8'></td>\n";
echo "<td class='sbp9'></td>\n";
echo "</tr>\n";
echo "</table>";
echo "<br />\n";
echo "</center>\n";
$i++;
if ($i != $numrows) { echo "<br />\n"; }
}
echo "<center><div class='sbarch'>\n<br />\n";
echo "<table cellspacing='0' cellpading='0' border='0'>\n<tr>\n";
echo "<td width='179'>\n";
if ($numrows > $settings['numofshouts']) {
echo "<a href='".INFUSIONS."shoutbox_panel/shoutbox_archive.php' class='side2'>Archiwum</a>\n";
}
echo "</td>\n<td align='right' width='200'>\n";
$dzis = dbcount("(shout_id)", DB_SHOUTBOX." WHERE DATE(FROM_UNIXTIME(shout_datestamp)) = CURDATE()");
echo "Dzisiaj <font color='#e0bd41'><strong>".number_format($dzis)."</strong></font> postów w SB";
echo "</td>\n</tr>\n</table>\n";
echo "</div></center>\n";
echo "</div>";
} else {
echo "<div>".$locale['global_156']."</div>\n";
}
require_once "../..//infusions/shoutbox_panel/footer.php";
?>
Kliknij i zaczekaj na załadowanie kodu ...
i plik header.php:
<?php
if (!defined("IN_FUSION")) { die("Access Denied"); }
echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n";
echo "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='".$locale['xml_lang']."' lang='".$locale['xml_lang']."'>\n";
echo "<head>\n<title>".$settings['sitename']."</title>\n";
echo "<meta http-equiv='Content-Type' content='text/html; charset=".$locale['charset']."' />\n";
echo "<meta name='description' content='".$settings['description']."' />\n";
echo "<meta name='keywords' content='".$settings['keywords']."' />\n";
echo "<link rel='stylesheet' href='".THEME."css/sb.css' type='text/css' media='screen' />\n";
echo "<script type='text/javascript' src='".INCLUDES."jquery.js'></script>\n";
echo "<script type='text/javascript' src='".INFUSIONS."shoutbox_panel/func.js'></script>\n";
echo "</head>\n<body>\n";
ob_start();
?>
Kliknij i zaczekaj na załadowanie kodu ...
Co robię nie tak? Mam bardzo mało doświadczenie z JQ.
EDIT
Jeżeli dodaję ten kod bezpośrednio do shoutbox_window.php to działa, ale mi zależy na wyodrębnieniu wszystkich kodów js do oddzielnego pliku.
<?php
require_once "../../maincore.php";
require_once "../../infusions/shoutbox_panel/header.php";
if (!defined("IN_FUSION")) { die("Access Denied"); }
$link = FUSION_SELF.(FUSION_QUERY ? "?".FUSION_QUERY : "");
$link = preg_replace("^(&|\?)s_action=(edit|delete)&shout_id=\d*^", "", $link);
$sep = stristr($link, "?") ? "&" : "?";
if (iMEMBER && (isset($_GET['s_action']) && $_GET['s_action'] == "delete") && (isset($_GET['shout_id']) && isnum($_GET['shout_id']))) {
if ((iADMIN && checkrights("S")) || (iMEMBER && dbcount("(shout_id)", DB_SHOUTBOX, "shout_id='".$_GET['shout_id']."' AND shout_name='".$userdata['user_id']."'"))) {
$result = dbquery("DELETE FROM ".DB_SHOUTBOX." WHERE shout_id='".$_GET['shout_id']."'".(iADMIN ? "" : " AND shout_name='".$userdata['user_id']."'"));
}
redirect($link);
}
function sbwrap($text) {
$i = 0; $tags = 0; $chars = 0; $res = "";
$str_len = strlen($text);
for ($i = 0; $i < $str_len; $i++) {
$chr = substr($text, $i, 1);
if ($chr == "<") {
if (substr($text, ($i + 1), 6) == "a href" || substr($text, ($i + 1), 3) == "img") {
$chr = " ".$chr;
$chars = 0;
}
$tags++;
} elseif ($chr == "&") {
if (substr($text, ($i + 1), 5) == "quot;") {
$chars = $chars - 5;
} elseif (substr($text, ($i + 1), 4) == "amp;" || substr($text, ($i + 1), 4) == "#39;" || substr($text, ($i + 1), 4) == "#92;") {
$chars = $chars - 4;
} elseif (substr($text, ($i + 1), 3) == "lt;" || substr($text, ($i + 1), 3) == "gt;") {
$chars = $chars - 3;
}
} elseif ($chr == ">") {
$tags--;
} elseif ($chr == " ") {
$chars = 0;
} elseif (!$tags) {
$chars++;
}
if (!$tags && $chars == 18) {
$chr .= "<br />";
$chars = 0;
}
$res .= $chr;
}
return $res;
}
if (iMEMBER || $settings['guestposts'] == "1") {
include_once INCLUDES."bbcode_include.php";
if (isset($_POST['post_shout'])) {
$flood = false;
if (iMEMBER) {
$shout_name = $userdata['user_id'];
} elseif ($settings['guestposts'] == "1") {
$shout_name = trim(stripinput($_POST['shout_name']));
$shout_name = preg_replace("(^[0-9]*)", "", $shout_name);
if (isnum($shout_name)) { $shout_name = ""; }
include_once INCLUDES."securimage/securimage.php";
$securimage = new Securimage();
if (!isset($_POST['sb_captcha_code']) || $securimage->check($_POST['sb_captcha_code']) == false) { redirect($link); }
}
$shout_message = str_replace("\n", " ", $_POST['shout_message']);
$shout_message = preg_replace("/^(.{255}).*$/", "$1", $shout_message);
$shout_message = trim(stripinput(censorwords($shout_message)));
if (iMEMBER && (isset($_GET['s_action']) && $_GET['s_action'] == "edit") && (isset($_GET['shout_id']) && isnum($_GET['shout_id']))) {
$comment_updated = false;
if ((iADMIN && checkrights("S")) || (iMEMBER && dbcount("(shout_id)", DB_SHOUTBOX, "shout_id='".$_GET['shout_id']."' AND shout_name='".$userdata['user_id']."'"))) {
if ($shout_message) {
$result = dbquery("UPDATE ".DB_SHOUTBOX." SET shout_message='$shout_message' WHERE shout_id='".$_GET['shout_id']."'".(iADMIN ? "" : " AND shout_name='".$userdata['user_id']."'"));
}
}
redirect($link);
} elseif ($shout_name && $shout_message) {
require_once INCLUDES."flood_include.php";
if (!flood_control("shout_datestamp", DB_SHOUTBOX, "shout_ip='".USER_IP."'")) {
$result = dbquery("INSERT INTO ".DB_SHOUTBOX." (shout_name, shout_message, shout_datestamp, shout_ip) VALUES ('$shout_name', '$shout_message', '".time()."', '".USER_IP."')");
}
}
redirect($link);
}
if (iMEMBER && (isset($_GET['s_action']) && $_GET['s_action'] == "edit") && (isset($_GET['shout_id']) && isnum($_GET['shout_id']))) {
$esresult = dbquery(
"SELECT ts.*, tu.user_id, tu.user_name FROM ".DB_SHOUTBOX." ts
LEFT JOIN ".DB_USERS." tu ON ts.shout_name=tu.user_id
WHERE ts.shout_id='".$_GET['shout_id']."'"
);
if (dbrows($esresult)) {
$esdata = dbarray($esresult);
if ((iADMIN && checkrights("S")) || (iMEMBER && $esdata['shout_name'] == $userdata['user_id'] && isset($esdata['user_name']))) {
if ((isset($_GET['s_action']) && $_GET['s_action'] == "edit") && (isset($_GET['shout_id']) && isnum($_GET['shout_id']))) {
$edit_url = $sep."s_action=edit&shout_id=".$esdata['shout_id'];
} else {
$edit_url = "";
}
$shout_link = $link.$edit_url;
$shout_message = $esdata['shout_message'];
}
} else {
$shout_link = $link;
$shout_message = "";
}
} else {
$shout_link = $link;
$shout_message = "";
}
echo "<a id='edit_shout' name='edit_shout'></a>\n";
echo "<form name='shout_form' method='post' action='".$shout_link."'>\n";
echo "<center>\n<textarea name='shout_message' rows='4' cols='20' class='sbtext'>".$shout_message."</textarea> ";
echo "<input type='submit' name='post_shout' value='".$locale['global_153']."' class='sbsubmit' />\n</center>\n";
echo "</form>\n<br />\n";
} else {
echo "<div style='text-align:center'>".$locale['global_154']."</div><br />\n";
}
$numrows = dbcount("(shout_id)", DB_SHOUTBOX);
$result = dbquery(
"SELECT ts.*, tu.user_id, tu.user_name, tu.user_avatar_sb FROM ".DB_SHOUTBOX." ts
LEFT JOIN ".DB_USERS." tu ON ts.shout_name=tu.user_id
ORDER BY ts.shout_datestamp DESC LIMIT 0,".$settings['numofshouts']);
if (dbrows($result)) {
$i = 0;
while ($data = dbarray($result)) {
echo "<div class='shoutboxdate' align='left' style='padding: 0px 0px 0px 8px;'>".showdate("longdate", $data['shout_datestamp'])."</div>";
echo "<cetner>\n";
echo "<table cellspacing='0' cellpadding='0' border='0'>\n";
echo "<tr>\n";
echo "<td class='sbp1'></td>\n";
echo "<td class='sbp2'></td>\n";
echo "<td class='sbp3'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='sbp4'></td>\n";
echo "<td class='sbp5'>\n";
echo "<table cellspacing='0' cellpadding='0' border='0'>\n";
echo "<tr>\n<td width='55' height='55' style='text-align: center;'>\n";
if ($data['user_avatar_sb']) {
echo "<img src='".BASEDIR."images/avatars_sb/".$data['user_avatar_sb']."' alt='".$data['user_name']."'>";
} else {
echo "<img src='".BASEDIR."images/no_sb.png' alt='".$data['user_name']."'>";
}
echo "</td>\n<td valign='top'>";
echo "<font style='color: #ffffff; font-size: 11px;'>Autor:</font> <a href='".BASEDIR."profile.php?lookup=".$data['shout_name']."' class='shoutboxname'>".$data['user_name']."</a>\n";
if ((iADMIN && checkrights("S")) || (iMEMBER && $data['shout_name'] == $userdata['user_id'] && isset($data['user_name']))) {
echo "[<a href='".$link.$sep."s_action=edit&shout_id=".$data['shout_id']."#edit_shout"."' style='color: #ffffff; font-size: 11px;'>E</a>|";
echo "<a href='".$link.$sep."s_action=delete&shout_id=".$data['shout_id']."' style='color: #ffffff; font-size: 11px;'>U</a>]\n";
}
echo"<br />\n";
echo "".sbwrap(parseubb(parsesmileys($data['shout_message']), "b|i|u|url|color"))."\n";
echo "</td>\n</tr>\n</table>\n";
echo "</td>\n";
echo "<td class='sbp6'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='sbp7'></td>\n";
echo "<td class='sbp8'></td>\n";
echo "<td class='sbp9'></td>\n";
echo "</tr>\n";
echo "</table>";
echo "<br />\n";
echo "</center>\n";
$i++;
if ($i != $numrows) { echo "<br />\n"; }
}
echo "<center><div class='sbarch'>\n<br />\n";
echo "<table cellspacing='0' cellpading='0' border='0'>\n<tr>\n";
echo "<td width='179'>\n";
if ($numrows > $settings['numofshouts']) {
echo "<a href='".INFUSIONS."shoutbox_panel/shoutbox_archive.php' class='side2'>Archiwum</a>\n";
}
echo "</td>\n<td align='right' width='200'>\n";
$dzis = dbcount("(shout_id)", DB_SHOUTBOX." WHERE DATE(FROM_UNIXTIME(shout_datestamp)) = CURDATE()");
echo "Dzisiaj <font color='#e0bd41'><strong>".number_format($dzis)."</strong></font> postów w SB";
echo "</td>\n</tr>\n</table>\n";
echo "</div></center>\n";
?>
<script> var refreshPost = setInterval(function(){$('#post').fadeOut("slow").fadeIn("slow");}, 5000);
</script>
<?php
echo "<div id='post2'>Odświeżanie";
echo "</div>";
} else {
echo "<div>".$locale['global_156']."</div>\n";
}
require_once "../..//infusions/shoutbox_panel/footer.php";
?>
Kliknij i zaczekaj na załadowanie kodu ...
Edytowane przez Szapko dnia 18.05.2010 13:04:57
|