BBCode in post_text parsen? / Neuester Post auf Startseite?

Du suchst einen bestimmten Mod, weißt aber nicht genau wo bzw. ob er überhaupt existiert? Wenn dir dieser Artikel nicht weiterhilft, kannst du hier den von dir gewünschten/gesuchten Mod beschreiben ...
Falls ein Mod-Autor eine der Anfragen hier aufnimmt, um einen neuen Mod zu entwickeln, geht's in [3.0.x] Mods in Entwicklung weiter.
Forumsregeln
phpBB 3.0 hat das Ende seiner Lebenszeit überschritten
phpBB 3.0 wird nicht mehr aktiv unterstützt. Insbesondere werden - auch bei Sicherheitslücken - keine Patches mehr bereitgestellt. Der Einsatz von phpBB 3.0 erfolgt daher auf eigene Gefahr. Wir empfehlen einen Umstieg auf die neuste phpBB-Version, welches aktiv weiterentwickelt wird und für welches regelmäßig Updates zur Verfügung gestellt werden.
Antworten
Benutzeravatar
CroneKorkN
Mitglied
Beiträge: 16
Registriert: 02.07.2008 14:31
Kontaktdaten:

BBCode in post_text parsen? / Neuester Post auf Startseite?

Beitrag von CroneKorkN »

Hallo,

mithilfe eines PHP-Scriptes im root des Forums lese ich aus der Datenbank ua. den Inhalt des Startposts des aktuellesten Themas eines bestimmten Forums aus, um ihn auf der Startseite des Forums anzuzeigen. Allerdings wird der Code dann so angezeigt wie, er in der Datenbank steht und die BBCodes werden nicht geparst.

Hier das Script:

Code: Alles auswählen

<?php
// ############ Anfang Festlegung der Vorgaben ########################################

// Laenge der angezeigten Themenueberschrift in Buchstaben
$topic_length = '64';

// Maximal angezeigte Beiträge
$topic_limit = '1';

// Eingeschraenkte Forumsanzeige ('0' = Aus; '1' = Ein)
$special_forums = '1';

// IDs der zugelassenen Foren (nur wenn Forumsanzeige = "1"); Trennung der IDs mit einem Komma
$forum_ids = '3';

// Relative Pfadangabe zur config.php
$config_path = '';

// Absoluter Pfad des Forums auf dem Server, bitte eingeben !!!
$root_path = 'http://freibrief.net/';

//ckn
$table_prefix = "phpbb_";

//mysql_connect($dbhost, $dbuser, $dbpasswd) OR die('Serververbindung fehlgeschlagen');

// ############ Ende Vorgaben #######################################

//Ermittlung des aktuellen Server-Verzeichnisses für Einbindung config.php
$path = dirname(__FILE__);

// Einbinden der phpBB-Konfigurationsdatei und somit Ermittlung der MySQL-Zugangsdaten
include_once($path.$config_path .'/config.php');

// Verbindungsaufbau mit Zugangsdaten aus config.php, Fehlermeldung bei Problemen

mysql_connect("localhost", "***", "***") OR die('Serververbindung fehlgeschlagen');

// Verbindung mit der phpBB-Datenbank herstellen
mysql_select_db("***") OR die('Datenbankverbindung fehlgeschlagen!');


//Abfrage ob Foreneinschraenkung gesetzt per Verzweigung und Uebergabe der moeglichen IDS an die Variable
$where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id IN ('. $forum_ids .') AND ';

//Definition der SQL-Abfrage
$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, p.post_text AS content
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_first_post_id DESC LIMIT $topic_limit";


//Durchfuehrung der SQL-Abfrage und Ergebnisuebergabe an $result
$result = mysql_query($sql);

// Wenn Abfrafge fehlgeschlagen = Fehlermeldung
if( !$result )

{
die('SQL-Abfrage fehlgeschlagen!: '. mysql_error());
exit();
}

//Definition Array für Aufnahme der Abfragedaten
$line = array();

// Uebergabe der Daten bis zum letzten Datensatz an Array per Schleife
while( $row = mysql_fetch_array($result) )

{
$line[] = $row;
}

// Strukturiertes Auslesen des Arrays und Variablenuebergabe
for( $i = 0; $i < count($line); $i++ )
{
$forum_id = $line[$i]['forum_id']; //Forums-ID
$forum_url = $root_path .'viewforum.php?f='. $forum_id; //Forums-Link
$topic_id = $line[$i]['topic_id']; //Themen-ID
$topic_url = $root_path .'viewtopic.php?t='. $topic_id; //Themen-Link
// Ausgabeformat der Beitragsueberschrift (Thema)
$topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...';

// Themenklassifizierung
$topic_type = ( $line[$i]['topic_type'] == '2' ) ? 'Beitrag ': '';
$topic_type .= ( $line[$i]['topic_type'] == '3' ) ? 'Globaler Beitrag ': '';
$topic_type .= ( $line[$i]['topic_type'] == '1' ) ? 'Kritischer Beitrag ': '';
$topic_type .= ( $line[$i]['topic_vote'] ) ? 'Abstimmung ': '';

$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>';
$last_content = $line[$i]['content'];

// ############## Eigentliche Ausgabe der Beitraege #############

echo '<div>';
// Forumsname und Link, bei Bedarf loeschen
echo '<p><a href="'. $forum_url .'" target="_blank">'. $line[$i]['forum_name'] .'</a><br />';
// User, Bei Bedarf loeschen
echo $last_url.'<br />';
// Datum, Bei Bedarf loeschen
echo $last_time.'<br />';
// Thema und Link, Bei Bedarf loeschen
echo '<a href="'. $topic_url .'" target="_blank">'. $topic_title .'</font></a></p>
</div><br />';
echo $last_content;

// ############## Ende Eigentliche Ausgabe ##############
}

mysql_close(); // Beendigung der Datenbankverbindung
?>
-Was muss ich anstellen, damit die BBCodes geparst werden?
-gibt es dafür eine elegantere Methode? Ich musste INCLUDEPHP aktivieren um das Script vom Template zu inkludieren. Diese Anzeige brauche ich auch nur im Forum selbst, also sollte sich das anders realisieren lassen.

Vielen Dank schonmal für eure Antworten!

MFG CKN
4seven
Mitglied
Beiträge: 5869
Registriert: 21.04.2007 06:18

Re: BBCode in post_text parsen? / Neuester Post auf Startseite?

Beitrag von 4seven »

-gibt es dafür eine elegantere Methode? Ich musste INCLUDEPHP aktivieren um das Script vom Template zu inkludieren.
unnötig, wenn man die tricks zum integrieren in das template anwendet (ohne php in das template-system includieren zu müssen). einfach durchlesen:
http://www.phpbb.de/community/viewtopic ... 7&t=168403
Benutzeravatar
CroneKorkN
Mitglied
Beiträge: 16
Registriert: 02.07.2008 14:31
Kontaktdaten:

Re: BBCode in post_text parsen? / Neuester Post auf Startseite?

Beitrag von CroneKorkN »

Hallo 4seven,

danke für deine Antwort und den Thread habe ich mir schon aufmerksam durchgelesen. Du meinst wohl die JavaScript-iFrame-Methode, die für mich leider nicht in Frage kommt weil das Forum auch ohne JS funktionieren muss. Das große Problem sind die BBCodes, wegen derer ich die Funktionen jetzt in die entsprechenden Stellen der Boardsoftware einzubauen versuche.

MFG CKN
4seven
Mitglied
Beiträge: 5869
Registriert: 21.04.2007 06:18

Re: BBCode in post_text parsen? / Neuester Post auf Startseite?

Beitrag von 4seven »

dann kann ich dir nicht helfen..

zu parsing_text / *_bbcodes und co. findest du im phpbb-wiki antwort..
Benutzeravatar
CroneKorkN
Mitglied
Beiträge: 16
Registriert: 02.07.2008 14:31
Kontaktdaten:

Re: BBCode in post_text parsen? / Neuester Post auf Startseite?

Beitrag von CroneKorkN »

Nach langem gefrickel habe ich jetzt das Script in die Boardsoftware verbaut um in den Templates Variablen statt INCLUDEPHP verwenden und die BBCodes parsen zu können.

Hier die betroffenen Dateien,falls es wen interessiert:
/index.php

Code: Alles auswählen

<?php
/**
*
* @package phpBB3
* @version $Id: index.php 8638 2008-06-09 17:11:26Z acydburn $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);


// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
$seo_mark = request_var('mark', '');
$keep_mark = in_array($seo_mark, array('topics', 'forums', 'all')) ? (boolean) ($user->data['is_registered'] || $config['load_anon_lastread']) : false;
$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
	'mark' => array('val' => $seo_mark, 'keep' => $keep_mark),
);
if ( !$phpbb_seo->seo_opt['zero_dupe']['strict'] ) { // strict mode is here a bit faster
	if ( !empty($phpbb_seo->seo_static['index']) ) {
		$phpbb_seo->set_cond( (boolean) (utf8_strpos($phpbb_seo->seo_path['uri'], $phpbb_seo->seo_static['index']) === false), 'do_redir', (empty($_GET) || (!empty($seo_mark) && !$keep_mark)));
	} else {
		$phpbb_seo->set_cond( (boolean) (utf8_strpos($phpbb_seo->seo_path['uri'], "index.$phpEx") !== false), 'do_redir', (empty($_GET) || (!empty($seo_mark) && !$keep_mark)));
	}
}
$phpbb_seo->seo_chk_dupe();
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
display_forums('', $config['load_moderators']);

// Set some stats, get posts count from forums data if we... hum... retrieve all forums data
$total_posts	= $config['num_posts'];
$total_topics	= $config['num_topics'];
$total_users	= $config['num_users'];

$l_total_user_s = ($total_users == 0) ? 'TOTAL_USERS_ZERO' : 'TOTAL_USERS_OTHER';
$l_total_post_s = ($total_posts == 0) ? 'TOTAL_POSTS_ZERO' : 'TOTAL_POSTS_OTHER';
$l_total_topic_s = ($total_topics == 0) ? 'TOTAL_TOPICS_ZERO' : 'TOTAL_TOPICS_OTHER';
$user->add_lang('mods/info_acp_gallery');
$total_images = $config['num_images'];
$l_total_image_s = ($total_images == 0) ? 'TOTAL_IMAGES_ZERO' : 'TOTAL_IMAGES_OTHER';

// Grab group details for legend display
if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
{
	$sql = 'SELECT group_id, group_name, group_colour, group_type
		FROM ' . GROUPS_TABLE . '
		WHERE group_legend = 1
		ORDER BY group_name ASC';
}
else
{
	$sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type
		FROM ' . GROUPS_TABLE . ' g
		LEFT JOIN ' . USER_GROUP_TABLE . ' ug
			ON (
				g.group_id = ug.group_id
				AND ug.user_id = ' . $user->data['user_id'] . '
				AND ug.user_pending = 0
			)
		WHERE g.group_legend = 1
			AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')
		ORDER BY g.group_name ASC';
}
$result = $db->sql_query($sql);

$legend = '';
while ($row = $db->sql_fetchrow($result))
{
	$colour_text = ($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . '"' : '';

	if ($row['group_name'] == 'BOTS')
	{
		$legend .= (($legend != '') ? ', ' : '') . '<span' . $colour_text . '>' . $user->lang['G_BOTS'] . '</span>';
	}
	else
	{
		// www.phpBB-SEO.com SEO TOOLKIT BEGIN
		if ( $phpbb_seo->seo_opt['profile_inj'] && empty($phpbb_seo->seo_url['group'][$row['group_id']]) ) {
			$phpbb_seo->seo_url['group'][$row['group_id']] = $phpbb_seo->format_url($row['group_name'], $phpbb_seo->seo_static['group']);
		}
		// www.phpBB-SEO.com SEO TOOLKIT END
		$legend .= (($legend != '') ? ', ' : '') . '<a' . $colour_text . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']) . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</a>';
	}
}
$db->sql_freeresult($result);

// Generate birthday list if required ...
$birthday_list = '';
if ($config['load_birthdays'] && $config['allow_birthdays'])
{
	$now = getdate(time() + $user->timezone + $user->dst - date('Z'));
	$sql = 'SELECT user_id, username, user_colour, user_birthday
		FROM ' . USERS_TABLE . "
		WHERE user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', $now['mday'], $now['mon'])) . "%'
			AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
	$result = $db->sql_query($sql);

	while ($row = $db->sql_fetchrow($result))
	{
		$birthday_list .= (($birthday_list != '') ? ', ' : '') . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);

		if ($age = (int) substr($row['user_birthday'], -4))
		{
			$birthday_list .= ' (' . ($now['year'] - $age) . ')';
		}
	}
	$db->sql_freeresult($result);
}

page_header($user->lang['INDEX']);

$template->set_filenames(array(
	'body' => 'index_body.html')
);

include($phpbb_root_path . 'lastpost.' . $phpEx);

// Assign index specific vars
$template->assign_vars(array(
  'LASTPOST_CONTENT' => $last_content,
  'LASTPOST_TIME' => $last_time,
  'LASTPOST_AUTHOR' => $last_author,
  'LASTPOST_URL' => $last_url,
	'TOTAL_POSTS'	=> sprintf($user->lang[$l_total_post_s], $total_posts),
	'TOTAL_TOPICS'	=> sprintf($user->lang[$l_total_topic_s], $total_topics),
	'TOTAL_USERS'	=> sprintf($user->lang[$l_total_user_s], $total_users),
'TOTAL_IMAGES'	=> ($config['gallery_total_images']) ? sprintf($user->lang[$l_total_image_s], $total_images) : '',
	'NEWEST_USER'	=> sprintf($user->lang['NEWEST_USER'], get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])),

	'LEGEND'		=> $legend,
	'BIRTHDAY_LIST'	=> $birthday_list,

	'FORUM_IMG'				=> $user->img('forum_read', 'NO_NEW_POSTS'),
	'FORUM_NEW_IMG'			=> $user->img('forum_unread', 'NEW_POSTS'),
	'FORUM_LOCKED_IMG'		=> $user->img('forum_read_locked', 'NO_NEW_POSTS_LOCKED'),
	'FORUM_NEW_LOCKED_IMG'	=> $user->img('forum_unread_locked', 'NO_NEW_POSTS_LOCKED'),

	'S_LOGIN_ACTION'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
	'S_DISPLAY_BIRTHDAY_LIST'	=> ($config['load_birthdays']) ? true : false,

	'U_MARK_FORUMS'		=> ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'mark=forums') : '',
	'U_MCP'				=> ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=front', true, $user->session_id) : '')
);

// Output page
page_footer();

?>
/lastpost.php

Code: Alles auswählen

<?php

// ############ Anfang Festlegung der Vorgaben ########################################

// Laenge der angezeigten Themenueberschrift in Buchstaben
$topic_length = '64';

// Maximal angezeigte Beiträge
$topic_limit = '1';

// Eingeschraenkte Forumsanzeige ('0' = Aus; '1' = Ein)
$special_forums = '1';

// IDs der zugelassenen Foren (nur wenn Forumsanzeige = "1"); Trennung der IDs mit einem Komma
$forum_ids = '46';

//Abfrage ob Foreneinschraenkung gesetzt per Verzweigung und Uebergabe der moeglichen IDS an die Variable
$where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id IN ('. $forum_ids .') AND ';

//Definition der SQL-Abfrage
$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, p.post_text AS content, p.bbcode_bitfield AS bbcode_bitfield, p.bbcode_uid AS bbcode_uid
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_first_post_id DESC LIMIT $topic_limit";


//Durchfuehrung der SQL-Abfrage und Ergebnisuebergabe an $result
$result = mysql_query($sql);

// Wenn Abfrafge fehlgeschlagen = Fehlermeldung
if( !$result )

{
die('SQL-Abfrage fehlgeschlagen!: '. mysql_error());
exit();
}

//Definition Array für Aufnahme der Abfragedaten
$line = array();

// Uebergabe der Daten bis zum letzten Datensatz an Array per Schleife
while( $row = mysql_fetch_array($result) )

{
$line[] = $row;
}

// Strukturiertes Auslesen des Arrays und Variablenuebergabe
for( $i = 0; $i < count($line); $i++ )
{
$forum_id = $line[$i]['forum_id']; //Forums-ID
$forum_url = $root_path .'viewforum.php?f='. $forum_id; //Forums-Link
$topic_id = $line[$i]['topic_id']; //Themen-ID
$topic_url = $root_path .'viewtopic.php?t='. $topic_id; //Themen-Link
// Ausgabeformat der Beitragsueberschrift (Thema)
$topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...';

// Themenklassifizierung
$topic_type = ( $line[$i]['topic_type'] == '2' ) ? 'Beitrag ': '';
$topic_type .= ( $line[$i]['topic_type'] == '3' ) ? 'Globaler Beitrag ': '';
$topic_type .= ( $line[$i]['topic_type'] == '1' ) ? 'Kritischer Beitrag ': '';
$topic_type .= ( $line[$i]['topic_vote'] ) ? 'Abstimmung ': '';

$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>';
$bbcode = new bbcode();
$last_content = $line[$i]['content'];
$bbcode->bbcode_second_pass($last_content, $line[$i]['bbcode_uid'], $line[$i]['bbcode_bitfield']);
$last_content = bbcode_nl2br($last_content);
}
?>
Über die Variablen 'LASTPOST_CONTENT', 'LASTPOST_TIME', 'LASTPOST_AUTHOR' und 'LASTPOST_URL' lässt sich das Ganze dann in die index_body.html einbinden.

MFG CKN
Antworten

Zurück zu „[3.0.x] Mod Suche/Anfragen“