Forendaten auf externe Seite

Fragen zu allen Themen rund ums Programmieren außerhalb von phpBB können hier gestellt werden - auch zu anderen Programmiersprachen oder Software wie Webservern und Editoren.
Benutzeravatar
Scotty
Mitglied
Beiträge: 1451
Registriert: 15.06.2005 03:54
Wohnort: Neuruppin
Kontaktdaten:

Forendaten auf externe Seite

Beitrag von Scotty »

Ich habe hier bei mir folgendes Script am laufen um die letzten Beiträge aus dem Forum auf eine externe nicht phpBB Seite auszugeben, im Prinzip funktioniert das Script beim phpBB, ich habe nur Probleme mit umlauten, weiß jemand wie man das Script entrechtend anpasst?

Script:

Code: Alles auswählen

<?php
// ############         Edit below         ########################################
$topic_length = '30';	// length of topic title
$topic_limit = '8';	// limit of displayed topics
$special_forums = '1';	// specify forums ('0' = no; '1' = yes)
$forum_ids = '5,6';		// IDs of forums; separate them with a comma

$config_path = '/';	// path to config.php
$root_path = 'http://www.forum.de/';		// link path
// ############         Edit above         ########################################

$path = dirname(__FILE__);
include_once($path.$config_path .'config.php');
mysql_connect($dbhost, $dbuser, $dbpasswd) OR die('Unable to select server.');
mysql_select_db($dbname) OR die('Unable to select database.');

// ############## output ##############
echo '<table border="0" cellpadding="0" cellspacing="0" style="width: 100%" id="Table_DSF-Top5">
			<tr>
				<td colspan="4"><span class="small">Die '. $topic_limit .' letzten Themen</span></td>
			</tr>
			<tr>
				<td style="width: 28%"><span class="small"><strong>Forum</strong></span></td>
				<td style="width: 16%" align="center"><span class="small"><strong>User</strong></span></td>
				<td style="width: 16%" align="center"><span class="small"><strong>Datum</strong></span></td>
				<td style="width: 45%"><span class="small"><strong>Thema</strong></span></td>
			</tr>';
// ############## output ##############

$where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id NOT IN ('. $forum_ids .') AND ';
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time
	FROM ". $table_prefix ."topics t, ". $table_prefix ."forums f, ". $table_prefix ."users u, ". $table_prefix ."posts p, ". $table_prefix ."posts p2, ". $table_prefix ."users u2
	WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id
	ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit";
$result = mysql_query($sql);
if( !$result )
{
	die('SQL Statement Error: '. mysql_error());
	exit();
}

$line = array();
while( $row = mysql_fetch_array($result) )
{
	$line[] = $row;
}

for( $i = 0; $i < count($line); $i++ )
{
	$forum_id = $line[$i]['forum_id'];
	$forum_url = $root_path .'viewforum.php?f='. $forum_id;
	$topic_id = $line[$i]['topic_id'];
	$topic_url = $root_path .'viewtopic.php?t='. $topic_id;

	$topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...';

	$topic_type =  ( $line[$i]['topic_type'] == '2' ) ? 'Announcement ': '';
	$topic_type .= ( $line[$i]['topic_type'] == '3' ) ? 'Global Announcement ': '';
	$topic_type .= ( $line[$i]['topic_type'] == '1' ) ? 'Sticky ': '';
	$topic_type .= ( $line[$i]['topic_vote'] ) ? 'Poll ': '';

	$views = $line[$i]['topic_views'];
	$replies = $line[$i]['topic_replies'];

	$first_time = date('d.m.Y', $line[$i]['topic_time']);
	$first_author = ( $line[$i]['first_poster_id'] != '-1' ) ? '<a href="'. $root_path .'profile.php?mode=viewprofile&u='. $line[$i]['first_poster_id'] .'" target="_blank">'. $line[$i]['first_poster'] .'</a>' : ( ($line[$i]['first_poster_name'] != '' ) ? $line[$i]['first_poster_name'] : 'guest' );
	$last_time = date('d.m.Y', $line[$i]['post_time']);
	$last_author = ( $line[$i]['last_poster_id'] != '-1' ) ? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : 'guest' );
	$last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#'. $line[$i]['topic_last_post_id'] .'" target="_blank">'. $last_author .'</a>';

	// ############## output ##############
	echo '<tr>
				<td style="width: 25%"><a href="'. $forum_url .'" target="_blank">'. $line[$i]['forum_name'] .'</a></td>
				<td style="width: 15%" align="center">'. $last_url .'</td>
				<td style="width: 15%" align="center">'. $last_time .'</td>
				<td style="width: 45%"><a href="'. $topic_url .'" target="_blank">'. $topic_title .'</a></td>
	     </tr>';
	// ############## output ##############
}

echo '</table>';
mysql_close();
?>
Scotty's .NET Projekte: StarTrek Infos X10, e-hahn Updater 3.10, Easy Desktop Note 1.06
Benutzeravatar
Blauvogel
Mitglied
Beiträge: 31
Registriert: 30.05.2007 11:17

Beitrag von Blauvogel »

Hallo,

soweit ich es erkennen kann, hast Du nur die Tabelle als Output. Keine META Tags oder HTML Header oder sonst was.
Daher tippe ich auf Probleme mit der Zeichenkodierung.

Schau mal hier: Kopfdaten
Es grüßt
Blauvogel
Benutzeravatar
Scotty
Mitglied
Beiträge: 1451
Registriert: 15.06.2005 03:54
Wohnort: Neuruppin
Kontaktdaten:

Beitrag von Scotty »

Na ja das Script wird ja wiederum via include eingebunden und dann müssten die Daten ja ja da sein, wenn ich das richtig verstanden habe, beim phpBB2 ging es noch.
Scotty's .NET Projekte: StarTrek Infos X10, e-hahn Updater 3.10, Easy Desktop Note 1.06
Benutzeravatar
Blauvogel
Mitglied
Beiträge: 31
Registriert: 30.05.2007 11:17

Beitrag von Blauvogel »

Hallo,

aber die Ausgabe der eigentlichen Seite, die diese Datei einbindet ist soweit okay. Also auch von den Umlauten her?
Es grüßt
Blauvogel
Benutzeravatar
Scotty
Mitglied
Beiträge: 1451
Registriert: 15.06.2005 03:54
Wohnort: Neuruppin
Kontaktdaten:

Beitrag von Scotty »

Blauvogel hat geschrieben:aber die Ausgabe der eigentlichen Seite, die diese Datei einbindet ist soweit okay. Also auch von den Umlauten her?
Ne eben nicht, da werden Umlaute nicht korrekt ausgegeben, nicht so wie beim phpBB2, siehe hier: http://www.e-hahn.de/index.php
Scotty's .NET Projekte: StarTrek Infos X10, e-hahn Updater 3.10, Easy Desktop Note 1.06
Benutzeravatar
Root007
Mitglied
Beiträge: 260
Registriert: 14.12.2002 08:13

Beitrag von Root007 »

Ich würd mal ganz frech sagen, dass dein Forum mit UTF-8 kodiert ist, während deine "normale" Seite mit ISO-8859-1. Stell eins von beidem auf das andere um, und das Problem ist weg (nimm am Besten für beides UTF-8).

Mir ist grad kein Weg bekannt, mit dem das Skript die Kodierung ändern könnte.

Ich hab zu selbem Skript eine andere Frage: Ich hab bei dem Upgrade leider MySQLi ausgewählt, nur geht damit dieses Skript natürlich nicht mehr. Sämtliche Funktionen gibts auch als mysqli-Variante, aber ein bloses Umstellen reicht leider nicht. Vielleicht weiß da ja jemand ne Lösung?
CorniI
Mitglied
Beiträge: 42
Registriert: 19.05.2006 11:11
Wohnort: Heilbronn

Beitrag von CorniI »

umstellen auf das DBAL des phpbbs, einfach common.php inkluden, IN_PHPBB definieren und phpEx und phpbb_root_path setzen und fertig. Beschreibung des DBAL: http://www.phpbb.com/mods/documentation ... /index.php
MfG
Corni
Benutzeravatar
Scotty
Mitglied
Beiträge: 1451
Registriert: 15.06.2005 03:54
Wohnort: Neuruppin
Kontaktdaten:

Beitrag von Scotty »

So, es geht doch, eigentlich ist es sogar relativ simpel, man muss es nur erst mal wissen ;).

Umwandeln kann man ganz leicht mit "utf8_decode" in "ISO-8859-1".

Hier mal das angepasste Script:

Code: Alles auswählen

<?php
// ############         Edit below         ########################################
$topic_length = '30';	// length of topic title
$topic_limit = '8';	// limit of displayed topics
$special_forums = '1';	// specify forums ('0' = no; '1' = yes)
$forum_ids = '5,6';		// IDs of forums; separate them with a comma

$config_path = '/';	// path to config.php
$root_path = 'http://www.forum.de/';		// link path
// ############         Edit above         ########################################

$path = dirname(__FILE__);
include_once($path.$config_path .'config.php');
mysql_connect($dbhost, $dbuser, $dbpasswd) OR die('Unable to select server.');
mysql_select_db($dbname) OR die('Unable to select database.');

// ############## output ##############
echo '<table border="0" cellpadding="0" cellspacing="0" style="width: 100%" id="Table_DSF-Top5">
			<tr>
				<td colspan="4"><span class="small">Die '. $topic_limit .' letzten Themen</span></td>
			</tr>
			<tr>
				<td style="width: 28%"><span class="small"><strong>Forum</strong></span></td>
				<td style="width: 16%" align="center"><span class="small"><strong>User</strong></span></td>
				<td style="width: 16%" align="center"><span class="small"><strong>Datum</strong></span></td>
				<td style="width: 45%"><span class="small"><strong>Thema</strong></span></td>
			</tr>';
// ############## output ##############

$where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id NOT IN ('. $forum_ids .') AND ';
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time
	FROM ". $table_prefix ."topics t, ". $table_prefix ."forums f, ". $table_prefix ."users u, ". $table_prefix ."posts p, ". $table_prefix ."posts p2, ". $table_prefix ."users u2
	WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id
	ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit";
$result = mysql_query($sql);
if( !$result )
{
	die('SQL Statement Error: '. mysql_error());
	exit();
}

$line = array();
while( $row = mysql_fetch_array($result) )
{
	$line[] = $row;
}

for( $i = 0; $i < count($line); $i++ )
{
	$forum_id = $line[$i]['forum_id'];
	$forum_url = $root_path .'viewforum.php?f='. $forum_id;
	$topic_id = $line[$i]['topic_id'];
	$topic_url = $root_path .'viewtopic.php?t='. $topic_id;

	$topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...';

	$topic_type =  ( $line[$i]['topic_type'] == '2' ) ? 'Announcement ': '';
	$topic_type .= ( $line[$i]['topic_type'] == '3' ) ? 'Global Announcement ': '';
	$topic_type .= ( $line[$i]['topic_type'] == '1' ) ? 'Sticky ': '';
	$topic_type .= ( $line[$i]['topic_vote'] ) ? 'Poll ': '';

	$views = $line[$i]['topic_views'];
	$replies = $line[$i]['topic_replies'];

	$first_time = date('d.m.Y', $line[$i]['topic_time']);
	$first_author = ( $line[$i]['first_poster_id'] != '-1' ) ? '<a href="'. $root_path .'memberlist.php?mode=viewprofile&u='. $line[$i]['first_poster_id'] .'" target="_blank">'. $line[$i]['first_poster'] .'</a>' : ( ($line[$i]['first_poster_name'] != '' ) ? $line[$i]['first_poster_name'] : 'Guest' );
	$last_time = date('d.m.Y', $line[$i]['post_time']);
	$last_author = ( $line[$i]['last_poster_id'] != '-1' ) ? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : 'Guest' );
	$last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#p'. $line[$i]['topic_last_post_id'] .'" target="_blank">'. utf8_decode($last_author).'</a>';

	// ############## output ##############
	echo '<tr>
				<td style="width: 25%"><a href="'. $forum_url .'" target="_blank">'.utf8_decode($line[$i]['forum_name']).'</a></td>
				<td style="width: 15%" align="center">'. $last_url .'</td>
				<td style="width: 15%" align="center">'. $last_time .'</td>
				<td style="width: 45%"><a href="'. $topic_url .'" target="_blank">'.utf8_decode($topic_title).'</a></td>
	     </tr>';
	// ############## output ##############
}

echo '</table>';
mysql_close();
?>
Eingebunden ist es hier: http://www.e-hahn.de
Scotty's .NET Projekte: StarTrek Infos X10, e-hahn Updater 3.10, Easy Desktop Note 1.06
sunnyboy1911
Mitglied
Beiträge: 3
Registriert: 17.06.2007 13:38

Beitrag von sunnyboy1911 »

Irgendwie funktioniert es bei mir nicht. Wäre nett wenn mir Jemand die 2 Zeilen die man anpassen muss, angepasst für mich hier postet. Der Foren-Pfad ist: http://united.habbofeeling.net/
Benutzeravatar
Dr.Death
Moderator
Moderator
Beiträge: 17399
Registriert: 23.04.2003 08:22
Wohnort: Xanten
Kontaktdaten:

Beitrag von Dr.Death »

Ein bisschen Überlegen schadet doch nicht, oder ?

Schau Dir diese Zeile mal an:

Code: Alles auswählen

$root_path = 'http://www.forum.de/';      // link path 
Antworten

Zurück zu „Coding & Technik“