PDA

View Full Version : Release: news-section including comments


Projektil
07-04-2001, 10:00 PM
hi, i'v got a small hack for you. the script reads the content of a forum directly from the database and displays the threads and replys. the hack is based on (i forgot that) a old hack.
you can enter the length of the message after it is shortent.

sorry, no demo, we use it in out extranet.

the code:



<?
error_reporting(0);

$DBhost = "db.host";
$DBuser = "db.user";
$DBpass = "db.password";
$DBName = "db.name";
$RipNumber = "10"; // rip of comments after...
$path = "http://path.to.server/forum";

$DBTable = "thread"; // db_table (standard)
$DBForum = 2; // nr. of forum

$newsPath = "http://path.to.server/forum";

$cutLength = 300; // cut comments and message after $cutLength chars

function sstr($str){
$u = 300;
if ( strlen($str)<$u ){
return $str;
} else {
do {$u++;} while(substr("$str",$u,1)==" ");
return trim(substr($str, 0, $u).$u);
$u = 300;
}
}

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database");
mysql_select_db("$DBName") or die("Unable to access the News");
$sqlquery = "SELECT * FROM $DBTable WHERE forumid = $DBForum AND visible !=0 ORDER by dateline DESC LIMIT 0,$RipNumber";
$result = mysql_query($sqlquery);
$number = mysql_numrows($result);

$i = 0;
$daycheck = niltz;

if ($number < 1) {
print "<CENTER><P>There Is NO News!</CENTER>";
}
else {
print "
<head>
<title>News</title>
</head>
<link rel=STYLESHEET type=text/css href=ns_format_02.css disabled>
<script language=JavaScript type=text/javascript> if (document.all) document.createStyleSheet(\"ie_format_02.css\");</script>
<body bgcolor=#CEDFFF>
<table width=300 cellspacing=2 cellpadding=0 align=LEFT valign=TOP>";
while ($number > $i) {
$title = mysql_result($result,$i,"title");
$theid = mysql_result($result,$i,"threadid");
$name = mysql_result($result,$i,"postusername");
$time = mysql_result($result,$i,"dateline");
$time2 = date("d-m-Y",$time);
$time3 = date("H:i",$time);

$story = mysql_result(mysql_query("SELECT pagetext FROM post where threadid = $theid order by dateline limit 0,1"),"pagetext");

$post = mysql_result(mysql_query("SELECT postid FROM post where threadid = $theid order by dateline limit 0,1"),"postid");

$userid = mysql_result(mysql_query("SELECT userid FROM post where threadid = $theid order by dateline limit 0,1"),"userid");

$numcheck = mysql_result($result,$i,"replycount");
$numie = ($numcheck);

// replace vbul-coding
$search = array ("/(\[URL=http:\/\/)(.*)(\])(.*)(\[\/URL\])/U",
"/(\[EMAIL=mailto:)(.*)(\])(.*)(\[\/EMAIL\])/U",
"/(\[SIZE=)(.*)(\])(.*)(\[\/SIZE\])/U",
"/(\[FONT=)(.*)(\])(.*)(\[\/FONT\])/U",
"/(\[COLOR=)(.*)(\])(.*)(\[\/COLOR\])/U",
"'\'",
"'\[list=1]'",
"'\[list=a]'",
"'\'",
"'\[/list=1]'",
"'\[/list=a]'",
"'\[\*\]'",
"'\[B\]'",
"'\[/B\]'",
"'\[I\]'",
"'\[/I\]'",
"'\[U\]'",
"'\[/U\]'");

$replace = array ("<a href=http:\/\\2>\\4</a>",
"<a href=mailto:\\2>\\2</a>",
"<font size=\\2 >\\2</font>",
"<font face=\\2 >\\2</font>",
"<font color=\\2 >\\2</font>",
"<ul>",
"<ol type=1>",
"<ol type=a>",
"</ul>",
"</ol>",
"</ol>",
"<li>",
"<b>",
"</b>",
"<i>",
"</i>",
"<u>",
"</u>");

$tmpStory = preg_replace ($search, $replace, $story);


$firstReply = mysql_result(mysql_query("SELECT pagetext FROM post where threadid = $theid order by dateline limit 1, $numcheck"),"pagetext");

if (!$firstReply) {
$enterReply = "";
} else {
$enterReply = "<tr><td bgcolor=$txtbgcolor>Antworten: $firstReply</td></tr>";
}

$br = '<BR>';
$p='<P>';
$chr = "\n";


if ( strlen($tmpStory)<$cutLength ){
$newstoryShort = $tmpStory;
} else {
$u = 300;
do {$u++;} while(substr($tmpStory,$u,1)==" ");
$newstoryShort = trim(substr($tmpStory, 0, $u)." ... ");
}


if (strlen($newstoryShort) > $cutLength) {
$showMore = "<A href=$newsPath/news.php?action=detail&message=$i&subID=0 class=content-bold-orange>[weiter]</a>";
} else {
$showMore = "";
}

if ($action=="detail") {

if ($message==$i){
print "
<tr><td><font class=content-bold-black>[ $title ]</font></td></tr>
<tr><td><hr noshade size=1 color=black></td></tr>
<tr><td><font class=content-regular-black>";

if ($subID!=0){
print $newstoryShort;
print $showMore;
} else {
print $tmpStory;
}

print "
<tr><td><hr noshade size=1 color=black></td></tr>
<tr><td><font class=content-regular-black>$name, $time2, $time3.";
// reply
if ($numie!=0) {
$maxReply = $numie+1;
for ( $i = 1 ; $i < $maxReply ; $i++){
print "<tr><td><hr noshade size=1 color=black></td></tr>";
$thisThread = mysql_result(mysql_query("SELECT postid FROM post where threadid = $theid order by dateline limit $i, 1"),"reply");
print "<tr><td><font class=content-regular-black>--> ";
print mysql_result(mysql_query("SELECT username FROM post where threadid = $theid order by dateline limit $i, 1"),"reply");
print ": <A href=$newsPath/news.php?action=detail&message=$message&subID=$thisThread class=content-bold-orange>";
print mysql_result(mysql_query("SELECT title FROM post where threadid = $theid order by dateline limit $i, 1"),"reply");
print "</a></td></tr>";
if ($subID == $thisThread){
print "<tr><td><font class=content-regular-black><br>";
print preg_replace ($search, $replace, mysql_result(mysql_query("SELECT pagetext FROM post where threadid = $theid order by dateline limit $i, 1"),"reply") );
print "</font></td></tr>";
}
}
}
// reply

print "<tr><td><hr noshade size=1 color=black></td></tr>";
print "
<tr><td><a href=$newsPath/news.php class=content-bold-orange>[ Back ]</a></td></tr>
</table><p>
";
break;
}
} else {
print "
<tr><td><font class=content-bold-black>[ $title ]</font></td></tr>
<tr><td><hr noshade size=1 color=black></td></tr>
<tr><td><font class=content-regular-black>$newstoryShort</font>$showMore</td></tr>
<tr><td><hr noshade size=1 color=black></td></tr>
<tr><td><font class=content-regular-black>$name, $time2, $time3.";


if ($numie!=0) {
print "
Comments: $numie</font></td></tr>
<tr><td><hr noshade size=1 color=black></td></tr>
<tr><td><font class=content-bold-black>Comments:</font></td></tr>";
$maxReply = $numie+1;
for ( $j = 1 ; $j < $maxReply ; $j++){
$thisThread = mysql_result(mysql_query("SELECT postid FROM post where threadid = $theid order by dateline limit $j, 1"),"reply");
print "<tr><td><font class=content-regular-black>--> ";
print mysql_result(mysql_query("SELECT username FROM post where threadid = $theid order by dateline limit $j, 1"),"reply");
print ": <A href=$newsPath/news.php?action=detail&message=$i&subID=$thisThread class=content-bold-orange>";
print mysql_result(mysql_query("SELECT title FROM post where threadid = $theid order by dateline limit $j, 1"),"reply");
print "</a></td></tr>";
}
}
print "<tr><td height=40>&nbsp;</td></tr>";
}
$i++;
}
print "
</table>
";
}

?>




just save it as xxx.php:p

Projektil
07-05-2001, 09:45 AM
look at it

Projektil
07-05-2001, 09:46 AM
single news display

dost
07-05-2001, 11:41 AM
Great hack thanks!

ztsky
07-05-2001, 02:24 PM
It seemed an error:
Parse error: parse error, expecting `')'' in c:\apache\htdocs\vb201\shownews.php on line 69

JohnM
07-05-2001, 03:44 PM
lol

$story = mysql_result(mysql_query("SELECT pagetext FROM post where threadid = $theid order by dateline limit 0,1"),"pagetext");

$post = mysql_result(mysql_query("SELECT postid FROM post where threadid = $theid order by dateline limit 0,1"),"postid");

$userid = mysql_result(mysql_query("SELECT userid FROM post where threadid = $theid order by dateline limit 0,1"),"userid");

try:


list($story,$post,$userid) = mysql_fetch_row(mysql_query("SELECT pagetext,postid,userid FROM post where threadid = $theid order by dateline limit 0,1"));

JohnM
07-05-2001, 03:50 PM
$title = mysql_result($result,$i,"title");
$theid = mysql_result($result,$i,"threadid");
$name = mysql_result($result,$i,"postusername");
$time = mysql_result($result,$i,"dateline");

$a = mysql_fetch_array($result);
list ($title,$theid,$name,$time) = list($a['title'],$a['threadid'],$a['postusername'],$a['dateline']);

Projektil
07-06-2001, 07:28 AM
but this was the first time i used php and mysql because i´m a flash5-actionscript/javascript/dhtml developer. TKS for your input...