Zaznaczam z góry że chodzi mi o forum phpBB by Przemo!
Chodzi tu o pisanie postów na forum wyświetlających się jako newsy na stronie głównej.
Otóż większośc kodu gotowego jednak mam kilka problemów. Pierwsze co to to, że na stronie głównej serwisu nie widać niektórych bbcodów i co najgorsze i najważniejszę wszystko co piszę na forum jest pokazane na stronie jako jednolity tekst, chodzi mi tu o entery. Jeśli na forum napiszę post o treści
Witam
Testuje bbcode
----
na stronie głownej wyświetli się jako
Witam Testuje bbcode
O to kod:
[php]<?php
define('IN_PHPBB', true);
$phpbb_root_path = './phpBB/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
?>
<?php
function bbcode_strip($text, $uid)
{
// pad it with a space so we can distinguish between false and matching the 1st char (index 0).
// this is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$text = " " . $text;
// first: if there isn't a "[" and a "]" in the message, don't bother.
if (! (strpos($text, "[") && strpos($text, "]")) )
{
// remove padding, return.
$text = substr($text, 1);
return $text;
}
// [code] and [ /code ] for posting code (html, php, c etc etc) in your posts.
$text = str_replace("[code:1:$uid]","", $text);
$text = str_replace("[/code:1:$uid]", "", $text);
$text = str_replace("[code:$uid]", "", $text);
$text = str_replace("[/code:$uid]", "", $text);
// and for posting replies with quote, or just for quoting stuff.
$text = str_replace("[quote:1:$uid]","\"", $text);
$text = str_replace("[/quote:1:$uid]", "\"", $text);
$text = str_replace("[quote:$uid]", "\"", $text);
$text = str_replace("[/quote:$uid]", "\"", $text);
// new one liner to deal with opening quotes with usernames...
// replaces the two line version that i had here before..
$text = preg_replace("/\[quote:$uid=(?:\"?([^\"]*)\"?)\]/si", "\"", $text);
$text = preg_replace("/\[quote:1:$uid=(?:\"?([^\"]*)\"?)\]/si", "\"", $text);
// [list] and [list=x] for (un)ordered lists.
// unordered lists
$text = str_replace("[list:$uid]", "", $text);
// li tags
$text = str_replace("[*:$uid]", "", $text);
// ending tags
$text = str_replace("[/list:u:$uid]", "", $text);
$text = str_replace("[/list:o:$uid]", "", $text);
// ordered lists
$text = preg_replace("/\[list=([a1]):$uid\]/si", "", $text);
// colours
$text = preg_replace("/\[color=(\#[0-9a-f]{6}|[a-z]+):$uid\]/si", "", $text);
$text = str_replace("[/color:$uid]", "", $text);
// url #2
$text = str_replace("[url]","", $text);
$text = str_replace("[/url]", "", $text);
// url /\[url=([a-z0-9\-\.,\?!%\*_\/:;~\\&$@\/=\+]+)\](.*?)\[/url\]/si
$text = preg_replace("/\[url=([a-z0-9\-\.,\?!%\*_\/:;~\\&$@\/=\+]+)\]/si", "", $text);
$text = str_replace("[/url:$uid]", "", $text);
// img
$text = str_replace("[img:$uid]","<img src=\"", $text);
$text = str_replace("[/img:$uid]", "\" alt=\"\" border=\"0\" align=\"left\" hspace=\"10\" vspace=\"10\" />", $text);
// email
$text = str_replace("[email:$uid]","", $text);
$text = str_replace("[/email:$uid]", "", $text);
// size
$text = preg_replace("/\[size=([\-\+]?[1-2]?[0-9]):$uid\]/si", "", $text);
$text = str_replace("[/size:$uid]", "", $text);
// align
$text = preg_replace("/\[align=(left|right|center|justify):$uid\]/si", "", $text);
$text = str_replace("[/align:$uid]", "", $text);
// and for bolding text.
$text = str_replace("[b:$uid]","<b>", $text);
$text = str_replace("[/b:$uid]", "</b>", $text);
// and for underlining text.
$text = str_replace("[u:$uid]", "<u>", $text);
$text = str_replace("[/u:$uid]", "</u>", $text);
// and for italicizing text.
$text = str_replace("[i:$uid]", "<i>", $text);
$text = str_replace("[/i:$uid]", "</i>", $text);
// [strike] and [/strike] for italicizing text.
$text = str_replace("[strike:$uid]", "", $text);
$text = str_replace("[/strike:$uid]", "", $text);
// [scroll] and [/scroll] for italicizing text.
$text = str_replace("[scroll:$uid]", "", $text);
$text = str_replace("[/scroll:$uid]", "", $text);
// [center] and [/center]
$text = str_replace("[center:$uid]", "\"", $text);
$text = str_replace("[/center:$uid]", "\"", $text);
// remove our padding from the string..
$text = substr($text, 1);
return $text;
}
?>
<?php
$page = $_GET['page'];
if ( $page != '' && file_exists($page.'.php') ) { include($page.'.php'); } else {
$sql = 'SELECT
t.topic_id,
t.topic_time,
t.topic_title,
pt.post_text,
u.username,
u.user_id,
u.user_rank,
u.user_posts,
t.topic_replies,
pt.bbcode_uid,
t.forum_id,
t.topic_poster,
t.topic_first_post_id,
t.topic_status,
pt.post_id,
p.post_id,
p.enable_smilies
FROM
' . TOPICS_TABLE . ' AS t,
' . USERS_TABLE . ' AS u,
' . POSTS_TEXT_TABLE . ' AS pt,
' . POSTS_TABLE . ' AS p
WHERE
t.forum_id IN (13) AND
t.topic_time <= ' . time() . ' AND
t.topic_poster = u.user_id AND
t.topic_first_post_id = pt.post_id AND
t.topic_first_post_id = p.post_id AND
t.topic_status <> 2
ORDER BY
t.topic_time DESC';
$result = $db->sql_query($sql);
while( $row = $db->sql_fetchrow($result) )
{
$text = $row['post_text'];
$text = bbcode_strip($text, $row['bbcode_uid']);
$link = append_sid('viewtopic.' . $phpEx . '?t=' . $row['topic_id']);
if (strlen($text) > 10000)
{
$text = substr($text, 0, 5000).'... <a href="forum/'.$link.'" class="wiecej">wiecej</a>';
}
$text = str_replace('
', '<br />', $text);
echo '<div class="title">Tytuł: <a href="forum/'.append_sid('viewtopic.' . $phpEx . '?t=' . $row['topic_id']).'"class="public" >'.$row['topic_title'].'</a>';
echo ' Dodany: '.create_date($board_config['default_dateformat'], $row['topic_time'], $board_config['board_timezone']).' Przez: <a href="forum/' . append_sid('profile.'.$phpEx.'?mode=viewprofile&u='.$row['user_id'].'') . '">'.$row['username'].'</b></a></div>';
echo '<span class="ur_t"><br />'.$text;
echo '<div><br /><a href="forum/'.append_sid('viewtopic.' . $phpEx . '?t=' . $row['topic_id']).'" class="public">Komentarze: [ '.$row['topic_replies'].' ]</a>';
echo ' | <a href="forum/'.append_sid('posting.' . $phpEx . '?mode=reply&t=' . $row['topic_id']).'" class="public">Dodaj komentarz</a></span><br /><br /></div>';}
$db->sql_freeresult($result);
}
?>[/php]
[ Dodano: 28 Maj 2006 10:19 ]haaalo -.-