|
|
Mời bạn đăng ký để giao lưu kết bạn nhé <3
Bạn phải đăng nhập để xem được nội dung, nếu bạn chưa có tài khoản? hãy Đăng ký
x
Tình hình diễn đàn của mình học tập về C++, php,... nên việc phân biệt màu sắc giữa hàm, biến, chuỗi… rất quan trọng. Discuz cũng hỗ trợ bbcode CODE nhưng mà với giao diện của nó thì các bạn cũng biết chuối quá. Ở Việt Nam mình chưa thấy nhắc đến mod Syntax HighLight cho discuz. Cũng may mắn search google tìm ra mod này. Nay mình viết TUT hướng dẫn các bạn hack mod. Ai thấy hay thanks động viên nhé!
Demo:
Demo From web: http://tin32.com/diendan/viewthread.php?tid=451489
Tính năng: HightLight tất cả các loại ngôn ngữ: C/C++, C#, HTML, CSS, JAVASCRIPT, PHP, JAVA, DELPHI, RUBY, SQL, VB, XML,….
Sử dụng luôn thẻ CODE mà discuz hỗ trợ
Các files cần chỉnh sửa: Ở đây TUT tôi hướng dẫn trên Discuz version 7.2
- ROOT_DZ/viewthread.php
- ROOT_DZ/include/discuzcode.func.php
- ROOT_DZ/templates/default/header.htm hoặc ROOT_DZ/templates/your_dir_template/header.htm
Chúng ta bắt đầu:
1) Các bạn mở ROOT_DZ/viewthread.php
Tìm:- $postlist = $attachtags = $attachlist = $threadstamp = array();
Sao chép mã Thay thế:- $codeclasses = $postlist = $attachtags = $attachlist = array();
Sao chép mã 2) Tiếp theo ROOT_DZ/include/discuzcode.func.php (Nhớ backup file này trước khi modify nhé!)
Tìm:
- function codedisp($code) {
- global $discuzcodes;
- $discuzcodes['pcodecount']++;
- $code = dhtmlspecialchars(str_replace('\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code)));
- $code = str_replace("\n", "<li>", $code);
- $discuzcodes['codehtml'][$discuzcodes['pcodecount']] = tpl_codedisp($discuzcodes, $code);
- $discuzcodes['codecount']++;
- return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";
- }
-
Sao chép mã Thêm dưới nó:
- function jscodedisp($code, $para) {
- global $codeclasses;
- if ($para == "") $para = "javascript";
- $class = split(":", $para);
- $codeclasses[strtolower($class[0])] = 1;
- $code = jscode_br_encode($code);
- return "<pre name="code" class="$para">$code</pre>";
- }
- function jscode_br_encode($str) {
- $str = str_replace("\r\n", "[JSCODE_RN]", $str);
- $str = str_replace("\r", "[JSCODE_R]", $str);
- $str = str_replace("\n", "[JSCODE_N]", $str);
- return $str;
- }
- function jscode_br_decode($str) {
- $str = str_replace("[JSCODE_RN]", "\r\n", $str);
- $str = str_replace("[JSCODE_R]", "\r", $str);
- $str = str_replace("[JSCODE_N]", "\n", $str);
- return $str;
- }
-
Sao chép mã Tiếp tục tìm:
- if($parsetype != 1 && !$bbcodeoff && $allowbbcode && (strpos($message, '[/co.de]') || strpos($message, '[/CO.DE]')) !== FALSE) {
- $message = preg_replace("/\s?\[co.de\](.+?)\[\/co.de\]\s?/ies", "codedisp('\\1')", $message);
- }
- $msglower = strtolower($message);
- //$htmlon = $htmlon && $allowhtml ? 1 : 0;
- if(!$htmlon) {
- $message = $jammer ? preg_replace("/\r\n|\n|\r/e", "jammer()", dhtmlspecialchars($message)) : dhtmlspecialchars($message);
- }
Sao chép mã Lưu ý: đoạn code trên từ khoá CODE và code không có dấu "chấm" ở giữa từ (CO.DE và co.de) . Vì BBcode nhận nhầm!
Thay thế bằng :
- if(!$htmlon && !$allowhtml) {
- $message = $jammer ? preg_replace("/\r\n|\n|\r/e", "jammer()", dhtmlspecialchars($message)) : dhtmlspecialchars($message);
- }
- $msglower = strtolower($message);
- if($parsetype != 1 && !$bbcodeoff && $allowbbcode) {
- $message = preg_replace("/\s*\[code\s*(class=)?"?([^]"]*)"?\](.+?)\[\/code\]\s*/ies", "jscodedisp('\\3', '\\2')", $message);
- }
Sao chép mã Tìm tiếp :
- return $htmlon ? $message : nl2br(str_replace(array("\t", ' ', ' '), array(' ', ' ', ' '), $message));
Sao chép mã Thay thế :
- return $htmlon || $allowhtml ? $message : jscode_br_decode(nl2br(str_replace(array("\t", ' ', ' '), array(' ', ' ', ' '), $message)));
Sao chép mã 3) Mở template ROOT_DZ/templates/default/header.htm hoặc ROOT_DZ/templates/your_dir_template/header.htm
Tìm:Thêm dưới nó:- <? include('Plugins/syntax_highlight/jscode.php'); ?>
Sao chép mã 4) Ấn nút thanks nếu bạn thấy mod này hay hjhj!
File đính kèm: (Bao gồm file ROOT_DZ/include/discuzcode.func.php đã hack sẵn)
DOWNLOAD
Hoặc
plugin_discuz_high_light.rar
(35.09 KB, Lượt tải về: 8)
|
Cảm ơn
-
Xem tất cả
|