So, wie versprochen werde ich nun mal meinen Lösungsansatz dazu hier veröffentlichen.
Problematik:
man möchte die letzten 5 oder auch mehr Topics/Posts auf seiner Homepage anzeigen lassen, diese ist jedoch auf einem anderen Server und man hat keinen Datenbankzugriff auf den MySQL Server des Forums.
Dazu erstellt man sich zunächst eine neue Funktion und packt diese in eine Datei mit dem Namen functions_last_posts_extern.php
Code: Alles auswählen
<?php
/**
* Make xml File
*/
function makeXML(){
global $db;
$xml_sql = 'SELECT t.topic_id, t.forum_id, t.icon_id, t.topic_title, t.topic_views, t.topic_replies, t.topic_type, t.topic_first_poster_name, t.topic_last_post_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time, p.post_id
FROM ' . TOPICS_TABLE . ' t LEFT JOIN ' . POSTS_TABLE . " p ON t.topic_last_post_id = p.post_id
WHERE p.post_id <> ''
ORDER BY t.topic_last_post_time DESC LIMIT 5";
$xml_res = $db->sql_query($xml_sql);
$fh = fopen( "../forum.xml", "w" );
fputs( $fh, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
fputs( $fh, "<ResultSet>\n");
while ($data = $db->sql_fetchrow($xml_res)){
fputs( $fh, "<topic>\n<icon>".$data['icon_id']."</icon>\n<typ>".$data['topic_type']."</typ>\n<subject>".$data['topic_title']."</subject>\n<zeit>".$data['topic_last_post_time']."</zeit>\n<starter>".$data['topic_first_poster_name']."</starter>\n<poster>".$data['topic_last_poster_name']."</poster>\n<colour>".$data['topic_last_poster_colour']."</colour>\n<p_id>".$data['topic_last_post_id']."</p_id>\n<t_id>".$data['topic_id']."</t_id>\n<f_id>".$data['forum_id']."</f_id>\n<views>".$data['topic_views']."</views>\n<replies>".$data['topic_replies']."</replies>\n</topic>\n" );
}
fputs( $fh, "</ResultSet>");
fclose( $fh );
}
?>
Die Pfadangabe in fopen sollte zum Rootverzeichnis verweisen. Diese Datei abspeichern und in den includes Ordner kopieren.
Als nächstes öffnen wir die Datei functions_posting.php ebenfalls im Verzeichnis includes zu finden.
Dort fügen wir an folgenden Stellen folgendes ein:
Suche:
Füge danach in einer neuen Zeile ein:
Suche:
Code: Alles auswählen
// $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : '';
Füge danach in einer neuen Zeile ein:
Suche:
Füge in der Zeile davor ein:
Das war alles in der Datei functions_posting.php, will man nun auch Moderatorenaktionen berücksichtigen, öffnet man die Datei includes/mcp/mcp_main.php
Suche:
Füge danach in einer neuen Zeile ein:
Code: Alles auswählen
include_once("includes/functions_last_posts_extern.php");
Suche:
In diesen Code Block fügt man dann makeXML(); ein, das Ganze sieht dann so aus:
Code: Alles auswählen
if (sizeof($post_ids) == 1)
{
if ($deleted_topics)
{
// We deleted the only post of a topic, which in turn has
// been removed from the database
$success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
makeXML();
}
else
{
$success_msg = $user->lang['POST_DELETED_SUCCESS'];
makeXML();
}
}
else
{
if ($deleted_topics)
{
// Some of topics disappeared
$success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
makeXML();
}
else
{
$success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
makeXML();
}
}
Das war es dann auch in dieser Datei. Als nächstes braucht man dann noch die Datei, die auf dem Server der Homepage die Daten der erstellten Datei forum.xml ausliest und ausgibt an einer Stelle Eurer Wahl auf Eurer HP. Ich habe die Datei last_topics.php genannt
Code: Alles auswählen
<div style="padding:3px;background-color:transparent;">
<?php
function object2array($object){
$return = NULL;
if(is_array($object)) {
foreach($object as $key => $value) $return[$key] = object2array($value);
}
else{
$var = get_object_vars($object);
if($var) {
foreach($var as $key => $value)
$return[$key] = object2array($value);
}
else
return strval($object);
}
return $return;
}
$xml_filename="Pfad zur/forum.xml";
if(!$xml_content = @simplexml_load_file($xml_filename)) {
echo "Keine Daten verfügbar";
}
else {
$inhalt = object2array($xml_content);
for($i=0;$i<5;$i++){
switch ($inhalt['topic'][$i]['typ']){
case 3: $icon = "announce_unread.gif"; $title = "Announcement"; break;
case 2: $icon = "announce_unread.gif"; $title = "Global Announcement"; break;
case 1: $icon = "sticky_unread.gif"; $title = "Sticky"; break;
default: $icon = "topic_unread.gif"; $title = "Topic";
}
echo "<img src=\"images/".$icon."\" width=\"14\" height=\"15\" alt=\"".$title."\" /> <a style=\"color:#0B4A70;\" href=\"http://tortisoft.uttx.net/board/viewtopic.php?f=".$inhalt['topic'][$i]['f_id']."&t=".$inhalt['topic'][$i]['t_id']."&p=".$inhalt['topic'][$i]['p_id']."#p".$inhalt['topic'][$i]['p_id']."\" title=\"".$inhalt['topic'][$i]['subject']."\" onclick=\"window.open(this.href); return false;\">".((strlen($inhalt['topic'][$i]['subject'])>40)?utf8_substr($inhalt['topic'][$i]['subject'],0 , 40)."...":$inhalt['topic'][$i]['subject'])."<img src=\"images/pfeil.gif\" width=\"16\" height=\"7\" alt=\"zum Beitrag\" /></a><br />\n<span style=\"font-size:x-small;\">by: <strong><span style=\"color:".(($inhalt['topic'][$i]['colour'])?"#".$inhalt['topic'][$i]['colour']:"black").";\">".$inhalt['topic'][$i]['poster']."</span></strong> started by: ".$inhalt['topic'][$i]['starter']." (Replies: ".$inhalt['topic'][$i]['replies'].", Views: ".$inhalt['topic'][$i]['views'].")<br />\n".date("D d.M Y, H:i a", $inhalt['topic'][$i]['zeit'])."</span><br />\n\n";
}
}
?>
</div>
Diese Datei bindet man dann mittels der PHP Funktion include("last_topics.php"); an beliebiger Stelle in die HP ein.
Sollte es noch Fragen geben bitte hier dann posten.
Man könnte daraus vllt.auch einen Mod machen aber dazu fehlt mir momentan die Zeit, sollte jemand Lust haben daraus was zu machen, so bitte ich zumindest darüber informiert zu werden, da der Code von mir stammt!
PS: die fertigen Dateien werde ich auf Wunsch auch zum Download bereitstellen
mfg Kendoo