ver1.2.0 いじくってみました
スクリーンショット
viewtopicページ におけるメッセージの見栄え(bbcodeとかsmileyとか)を viewforumページでも表示されるようにしてみました。
あと、viewforum.php において
//config for Post Excerpt
$img_height = 150; //サムネイルの大きさ
$topictitle_fontsize = 15; //トピックタイトルのフォントサイズ
$char_limit = '500'; //トピックのメッセージが表示される最大文字数
$row_limit = '10'; //トピックのメッセージが表示される最大行数 |
いろいろカスタマイズしやすくなってます
phpBB2.0.21 で動作確認済み
インストール↓
#
#-----[ OPEN ]------------------------------
#
viewforum.php
#
#-----[ FIND ]-----------------------------------
#
include($phpbb_root_path . 'common.'.$phpEx);
#
#-----[ AFTER, ADD ]-------------------------------------------
#
/* Post Excerpt - Begin */
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
/* Post Excerpt - End */
#
#-----[ FIND ]-----------------------------------
#
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
#
#-----[ AFTER, ADD ]-------------------------------------------
#
/* Post Excerpt - Begin */
//config for Post Excerpt
$img_height = 150; //サムネイルの大きさ
$topictitle_fontsize = 15; //トピックタイトルのフォントサイズ
$char_limit = '500'; //トピックのメッセージが表示される最大文字数
$row_limit = '10'; //トピックのメッセージが表示される最大行数
$sql = "SELECT p.enable_smilies, pt.post_text, pt.bbcode_uid
FROM " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt
WHERE pt.post_id=" . $topic_rowset[$i]['topic_first_post_id'] . "
AND pt.post_id = p.post_id ";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$excerpt_post = $row['post_text'];
// insert image thumbnails
$imagepreview = "";
if(preg_match("#\[url=(.+)\]\[img:(.+)\](.+)\[/img
:(.+)\]\[/url\]#", $excerpt_post, $matches)){
$imagepreview = "<a href=\"$matches[1]\" target=\"_blank\"><img src=\"$matches[3]\" alt=\"$matches[1]\" height =\"$img_height\"></a>";
} else if(preg_match("#\[img:(.+)\](.+)\[/img:(..+)\]#", $excerpt_post, $matches)){
$imagepreview = "<a href=\"$matches[2]\" target=\"_blank\"><img src=\"$matches[2]\" alt=\"$matches[2]\" height =\"$img_height\"></a>";
}
//
//limit max charcters
//
if (strlen($excerpt_post) > $char_limit)
{
$excerpt_post=substr($excerpt_post, 0, $char_limit) . "....";
}
//
//limit max rows
//
$excerpt_post_row = preg_split( '#\n#', $excerpt_post);
if ( count($excerpt_post_row) > $row_limit )
{
$assemble = '';
for ( $j=0; $row_limit-1>$j; $j++ )
{
$assemble .= $excerpt_post_row[$j] . "\n";
}
$assemble .= $excerpt_post_row[$row_limit-1];
$excerpt_post = $assemble . "....";
}
//delete [img:...] and [/img:...]
$excerpt_post = preg_replace("#\[/?img:[a-z0-9]*\]#i", '', $excerpt_post);
////////////////////////////////////////////////////////////////////
//Parse $excerpt_post to html
//
// Parse message for BBCode if reqd
//
$bbcode_uid = $row['bbcode_uid'];
if ($bbcode_uid != '')
{
$excerpt_post = ($board_config['allow_bbcode']) ? bbencode_second_pass($excerpt_post, $bbcode_uid) : preg_replace("/\:$bbcode_uid/si", '', $excerpt_post);
}
$excerpt_post = make_clickable($excerpt_post);
//modify the html code of code and quote bbcodes
$excerpt_post = preg_replace('#width="90%"#', 'width="50%"', $excerpt_post);
$excerpt_post = preg_replace('#class="postbody#', 'class="postdetails"', $excerpt_post);
//
// Parse smilies
//
if ( $board_config['allow_smilies'] )
{
if ( $row['enable_smilies'] )
{
$excerpt_post = smilies_pass($excerpt_post);
}
}
//
// Replace naughty words
//
$excerpt_post = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $excerpt_post . '<'), 1, -1));
//
// Replace newlines (we use this rather than nl2br because
// till recently it wasn't XHTML compliant)
//
$excerpt_post = str_replace("\n", "\n<br />\n", $excerpt_post);
//
/////////////////////////////////////////////////////////////////
// trim long urls
$excerpt_post=preg_replace_callback('#http://[^\s]+#i','trim_url',$excerpt_post);
/* Post Excerpt - End */
#
#
#-----[ FIND ]-----------------------------------
#
'LAST_POST_TIME' => $last_post_time,
#
#-----[ AFTER, ADD ]-------------------------------------------
#
/* Post Excerpt - Begin */
'EXCERPT_POST' => $excerpt_post,
'IMAGE_PREVIEW' => $imagepreview,
'TOPICTITLE_FONTSIZE' => 'style="font-size: ' . $topictitle_fontsize . 'pt;"',
/* Post Excerpt - End */
#
#-----[ FIND ]-----------------------------------
#
?>
#
#-----[ BEFORE, ADD ]-------------------------------------------
#
/* Post Excerpt - Begin */
function trim_url($matches_s)
{
if(strlen($matches_s[0])>50){
return substr($matches_s[0],0,30)."...";
}else
return $matches_s[0];
}
/* Post Excerpt - End */
#
#-----[ OPEN ]------------------------------
#
templates/subSilver/viewforum_body.tpl
#
#-----[ FIND ]-----------------------------------
#
<td class="row1" width="100%"><span class="topictitle">{topicrow.NEWEST_POST_IMG}{topicrow.TOPIC_TYPE}<a href="{topicrow.U_VIEW_TOPIC}" class="topictitle">{topicrow.TOPIC_TITLE}</a></span><span class="gensmall"><br />
#
#
#-----[ IN-LINE FIND ]-----------------------------------
#
{topicrow.TOPIC_TYPE}
#
#-----[ IN-LINE AFTER, ADD ]-------------------------------------------
#
<span style="float: right;">{topicrow.IMAGE_PREVIEW}</span>
#
#-----[ IN-LINE FIND ]-----------------------------------
#
<a href="{topicrow.U_VIEW_TOPIC}" class="topictitle"
#
#-----[ IN-LINE AFTER, ADD ]-------------------------------------------
#
{topicrow.TOPICTITLE_FONTSIZE}
#
#
#-----[ IN-LINE FIND ]-----------------------------------
#
{topicrow.TOPIC_TITLE}</a></span>
#
#-----[ IN-LINE AFTER, ADD ]-------------------------------------------
#
<br><span
class="postdetails">{topicrow.EXCERPT_POST}</span>
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# That's it!
赤い所は ver1.2.0 からの追加or修正部分です。 ver1.2.0 の数行は削除してるところもあります。ver1.2.0 からアップデートするなら気をつけてください。
-----追記-----
| ごぅ の記述を引用: |
| 今回カスタム関数を使ったのですが、viewforum.phpの最後に配置させました。というのも、これをループの中に入れると動作してくれませんでした。これはなぜなのでしょうか? |
お互いおつかれさまです
単純に複数回同じ関数を呼び出したから?なのかしら・・
----追記2----
ちょこっとコードの修正しました