Zur Navigation

Neue Beiträge außerhalb des Forums anzeigen

1 Jörg

Mit dem folgenden Script können (in der Forenversion JKBB 2.0) die neuesten Beiträge auch außerhalb des Forums angezeigt werden. Voraussetzung ist, dass sich die betreffende Seite im selben Webspace befindet, so dass die Dateien /includes/config.php und /includes/main/functions.php includiert werden können und auf die Forendatenbank zugegriffen werden kann.

<?php

/* Konfiguration */

// Anzahl der Themen, die ausgegeben werden sollen:
$i_threads = 5;

// Pfad des Forums, inkl. "http://" am Anfang und Slash am Ende, z.B. "http://example.com/forum/"
$u_board_l = 'http://example.com/forum/';

// Codierung der Webseite ('UTF-8' oder 'ISO-8859-1')
$charset = 'UTF-8';

/* die Dateien config.php und functions.php includen */

include('/path-to-forum/includes/config.php');
include('/path-to-forum/includes/main/functions.php');

/* ab hier muss nichts mehr geändert werden */

$dbconnect = @mysql_connect($dbhost,$dbuser,$dbpassword);
$dbselect = @mysql_select_db($dbdatabase);
if (! $dbconnect || ! $dbselect) {
    echo 'Keine Datenbankverbindung';
} else {
    if ($charset == 'UTF-8') {
        mysql_query("SET NAMES 'utf8'");
    }
    if (! isset($dbprefix)) {
        $dbprefix = 'jkf';
    }
    $r_config = mysql_query("SELECT name, content FROM " . $dbprefix . "_config WHERE name IN ('postsptp', 'b_htmlextension')");
    while ($crow = mysql_fetch_array($r_config)) {
        $$crow[0] = $crow[1];
    }
    $rext = ($b_htmlextension) ? '.html' : '';
    $result = mysql_query("SELECT t.id, t.fid, t.zeit2, t.name AS tname, t.uname2, t.pzahl, f.name AS fname FROM " . $dbprefix . "_threads AS t INNER JOIN " . $dbprefix . "_foren AS f ON t.fid = f.id WHERE f.frstatus <= 1 ORDER BY t.zeit2 DESC LIMIT " . $i_threads);
    echo '<table>' . "\n";
    echo '<tr>' . "\n";
    echo '<th>Forum</th>' . "\n";
    echo '<th>Thema</th>' . "\n";
    echo '<th>Beitrag</th>' . "\n";
    echo '<th>von</th>' . "\n";
    echo '<th>Datum</th>' . "\n";
    echo '</tr>' . "\n";
    while (list($tid, $fid, $i_lastpost, $tname, $uname2, $i_posts, $fname) = mysql_fetch_row($result)) {
        echo '<tr>' . "\n";
        echo '<td><a href="' . $u_board_l . str4url($fname) . '-f-' . $fid . '-1' . $rext . '">' . htmlspecialchars($fname) . '</a></td>' . "\n";
        echo '<td><a href="' . $u_board_l . str4url($tname) . '-t-' . $tid . '-' . ceil($i_posts / $postsptp) . $rext . '#p' . $i_posts . '">' . htmlspecialchars($tname) . '</a></td>' . "\n";
        echo '<td>' . $i_posts . '</td>' . "\n";
        echo '<td>' . htmlspecialchars($uname2) . '</td>' . "\n";
        echo '<td>' . date("d.m. H:i", $i_lastpost) . '</td>' . "\n";
        echo '</tr>' . "\n";
    }
    echo '</table>' . "\n";
}
?>

23.07.2010 00:53 | geändert: 23.07.2010 02:02

... 1 Jahr und 5 Monate später ...

2 Jörg

Für JKBB 2.1 muss die SQL-Query etwas angepasst werden, das Script schaut dann so aus (Änderung fett markiert):

<?php

/* Konfiguration */

// Anzahl der Themen, die ausgegeben werden sollen:
$i_threads = 5;

// Pfad des Forums, inkl. "http://" am Anfang und Slash am Ende, z.B. "http://example.com/forum/"
$u_board_l = 'http://example.com/forum/';

// Codierung der Webseite ('UTF-8' oder 'ISO-8859-1')
$charset = 'UTF-8';

/* die Dateien config.php und functions.php includen */

include('/path-to-forum/includes/config.php');
include('/path-to-forum/includes/main/functions.php');

/* ab hier muss nichts mehr geändert werden */

$dbconnect = @mysql_connect($dbhost,$dbuser,$dbpassword);
$dbselect = @mysql_select_db($dbdatabase);
if (! $dbconnect || ! $dbselect) {
    echo 'Keine Datenbankverbindung';
} else {
    if ($charset == 'UTF-8') {
        mysql_query("SET NAMES 'utf8'");
    }
    if (! isset($dbprefix)) {
        $dbprefix = 'jkf';
    }
    $r_config = mysql_query("SELECT name, content FROM " . $dbprefix . "_config WHERE name IN ('postsptp', 'b_htmlextension')");
    while ($crow = mysql_fetch_array($r_config)) {
        $$crow[0] = $crow[1];
    }
    $rext = ($b_htmlextension) ? '.html' : '';
    $result = mysql_query("SELECT t.id, t.fid, t.zeit2, t.name AS tname, t.uname2, t.pzahl, f.name AS fname FROM " . $dbprefix . "_threads AS t INNER JOIN " . $dbprefix . "_foren AS f ON t.fid = f.id WHERE f.i_read >= 7 ORDER BY t.zeit2 DESC LIMIT " . $i_threads);
    echo '<table>' . "\n";
    echo '<tr>' . "\n";
    echo '<th>Forum</th>' . "\n";
    echo '<th>Thema</th>' . "\n";
    echo '<th>Beitrag</th>' . "\n";
    echo '<th>von</th>' . "\n";
    echo '<th>Datum</th>' . "\n";
    echo '</tr>' . "\n";
    while (list($tid, $fid, $i_lastpost, $tname, $uname2, $i_posts, $fname) = mysql_fetch_row($result)) {
        echo '<tr>' . "\n";
        echo '<td><a href="' . $u_board_l . str4url($fname) . '-f-' . $fid . '-1' . $rext . '">' . htmlspecialchars($fname) . '</a></td>' . "\n";
        echo '<td><a href="' . $u_board_l . str4url($tname) . '-t-' . $tid . '-' . ceil($i_posts / $postsptp) . $rext . '#p' . $i_posts . '">' . htmlspecialchars($tname) . '</a></td>' . "\n";
        echo '<td>' . $i_posts . '</td>' . "\n";
        echo '<td>' . htmlspecialchars($uname2) . '</td>' . "\n";
        echo '<td>' . date("d.m. H:i", $i_lastpost) . '</td>' . "\n";
        echo '</tr>' . "\n";
    }
    echo '</table>' . "\n";
}
?>

02.01.2012 19:23 | geändert: 02.01.2012 19:23

... 4 Jahre und 1 Monat später ...

3 Jörg

Ab JKBB 3.0 + PHP 7:

<?php

/* Konfiguration */

// Anzahl der Themen, die ausgegeben werden sollen:
$i_threads = 5;

// Pfad des Forums, inkl. "http://" am Anfang und Slash am Ende, z.B. "http://example.com/forum/"
$u_board_l = 'http://example.com/forum/';

// Codierung der Webseite ('UTF-8' oder 'ISO-8859-1')
$charset = 'UTF-8';

/* die Dateien config.php und functions.php includen */

include('/path-to-forum/includes/config.php');
include('/path-to-forum/includes/main/functions.php');

/* ab hier muss nichts mehr geändert werden */

$b_database = false;
$db_driver = new mysqli_driver();
$db_driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
try {
    $db = new mysqli($dbhost, $dbuser, $dbpassword, $dbdatabase);
    if (! $db->connect_error) {
        $b_database = true;
    }
} catch (Exception $e) {
    $content .= 'Keine Datenbankverbindung';
}
if ($b_database) {
    if ($charset == 'UTF-8') {
        $db->set_charset("utf8");
    }
    if (! isset($dbprefix)) {
        $dbprefix = 'jkf';
    }
    $r_config = $db->query("SELECT name, content FROM " . $dbprefix . "_config WHERE name IN ('postsptp', 'i_old_extension')");
    while ($row = $r_config->fetch_assoc()) {
        $a_config[$row['name']] = $row['content'];
    }
    $rext = ($a_config['i_old_extension'] == 2) ? '.html' : '';
    $result = $db->query("SELECT t.id, t.fid, t.zeit2, t.name AS tname, t.uname2, t.pzahl, f.name AS fname FROM " . $dbprefix . "_threads AS t INNER JOIN " . $dbprefix . "_foren AS f ON t.fid = f.id WHERE f.i_read >= 7 ORDER BY t.zeit2 DESC LIMIT " . $i_threads);
    $content .= '<table>' . "\n";
    $content .= '<caption>Neueste Beiträge im Forum</caption>' . "\n";
    $content .= '<tr>' . "\n";
    $content .= '<th>Forum</th>' . "\n";
    $content .= '<th>Thema</th>' . "\n";
    $content .= '<th>Beitrag</th>' . "\n";
    $content .= '<th>von</th>' . "\n";
    $content .= '<th>Datum</th>' . "\n";
    $content .= '<th>Datum</th>' . "\n";
    $content .= '</tr>' . "\n";
    while (list($tid, $fid, $i_lastpost, $tname, $uname2, $i_posts, $fname) = $result->fetch_row()) {
        $content .= '<tr>' . "\n";
        $content .= '<td class="forum"><a href="' . $u_board_l . str4url($fname) . '-f-' . $fid . '-1' . $rext . '">' . htmlspecialchars($fname) . '</a></td>' . "\n";
        $content .= '<td class="thread"><a href="' . $u_board_l . str4url($tname) . '-t-' . $tid . '-' . ceil($i_posts / $a_config['postsptp']) . $rext . '#p' . $i_posts . '">' . htmlspecialchars($tname) . '</a></td>' . "\n";
        $content .= '<td class="post">' . $i_posts . '</td>' . "\n";
        $content .= '<td class="author">' . htmlspecialchars($uname2) . '</td>' . "\n";
        $content .= '<td class="date">' . date("d.m. H:i", $i_lastpost) . '</td>' . "\n";
        $content .= '</tr>' . "\n";
    }
    $content .= '</table>' . "\n";
}
?>

16.02.2016 20:11 | geändert: 16.02.2016 20:44

Nur Mitglieder können in diesem Forum Antworten schreiben.

Login | Registrieren