ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文

  メンテナンス 前画面に戻る

対象スレッド 件名: 本文の再加工
名前: lightbox
処理選択
パスワード

件名 本文の再加工
名前 lightbox
コメント
@DIV
これは、こうされる事を想定して作られていたようなコードでした。
本文に対する専用マクロはみなここで改造できます

@C:red(wp-includes/post-template.php の the_content関数を変更しています。)
@END

SyntaxHighligter を埋め込むマクロを実装しています。

[[以下専用構文]]
@DIV
@CODE(vb,vb_7_01.txt)
@CODE(php,php_7_02.txt)
@CODESET
@END
※ @CODESET は、SyntaxHighligter の実行文の埋め込みです。
※ http://code.google.com/p/syntaxhighlighter/wiki/Usage(オリジナルの説明)では、.js をページの最後に書く必要があります。
※ また、世間のサンプルではページのロードイベントを使用しているものがありますが、それでは正しく動かない場合もあります。
※ 外部 js、css -> head、実行文 -> 最後のソースコード以降の任意の場所、が管理上理想的です。

@DIV
function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
	$content = get_the_content($more_link_text, $stripteaser, $more_file);
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]>', ']]>', $content);


	# **************************************************
	# ここから改造
	# 専用マクロを正規表現で検索して置き換え処理
	# ここでは、外部ファイルからソースコードを取り出して
	# http://code.google.com/p/syntaxhighlighter/(SyntaxHighligter) の構文に置き換え
	# **************************************************
	$matches = array();
	mb_ereg_search_init( $content, "@CODE\(([^\)]*),([^\)]*)\)", "i" );
	while( TRUE === mb_ereg_search() ) {
		$work = mb_ereg_search_getregs();
		$matches[] = $work;
	}

	foreach( $matches as $key => $value ) {
		$repl_file = file_get_contents( "codetext/" . $value[2] );
		$repl_file = str_replace('<', '&lt;', $repl_file);
		$repl_file = str_replace('>', '&gt;', $repl_file);

		$content = str_replace($value[0], "<pre name='code' class='{$value[1]}'>{$repl_file}</pre>", $content);
	}

	$content = str_replace(
		'@' . 'CODESET', 
		'<script type="text/javascript">dp.SyntaxHighlighter.ClipboardSwf = "/clipboard.swf"; dp.SyntaxHighlighter.HighlightAll("code");</script>',
		 $content);

	# **************************************************
	# ここまで改造
	# **************************************************

	echo $content;
}
@END

↓実装サンプル
http://winofsql.sakura.ne.jp/wordpress/?page_id=7