关于吾爱论坛新增IL语言支持的原理和测试与使用
本帖最后由 lizhirui 于 2018-10-27 18:32 编辑恭喜吾爱论坛支持新的语言——IL语言(我干的),即.net中间语言的语法着色。{:301_986:}
望大家看完觉得本帖好的话不要忘记评个热心值。{:301_997:}
使用方法如下:
如果使用过程中出现如下提示:
其原因是浏览器缓存未刷新,请清空浏览器缓存后再次尝试,或者打开https://avatar.52pojie.cn/mw_syn ... ushIL.js?ver=3.0.83这个链接,查看“Brush.aliases = ['il'];”行中的il是否为小写,此处原因是因为刷子文件缓存的原因,导致新版本js文件未加载。
以下是测试代码,希望大家可以对着色效果提出一些意见或者建议:
.method public hidebysig instance bool
VerifyRegisterCode(string productid,
string key,
valuetype System.DateTime& 'date',
string& msg,
int32& interval) cil managed
{
// Code size 240 (0xf0)
.maxstack3
.locals init (class System.Security.Cryptography.RSACryptoServiceProvider V_0,
uint8[] V_1,
uint8[] V_2,
string V_3,
bool V_4,
valuetype System.DateTime V_5)
IL_0000:call class System.Text.Encoding System.Text.Encoding::get_UTF8()
IL_0005:ldarg.1
IL_0006:callvirt instance uint8[] System.Text.Encoding::GetBytes(string)
IL_000b:pop
IL_000c:newobj instance void System.Security.Cryptography.RSACryptoServiceProvider::.ctor()
IL_0011:stloc.0
IL_0012:ldloc.0
IL_0013:ldsfld string Wuyou.Exam.Activations.Activation::PublicKey
IL_0018:callvirt instance void System.Security.Cryptography.AsymmetricAlgorithm::FromXmlString(string)
IL_001d:ldarg.3
IL_001e:initobj System.DateTime
.try
{
IL_0024:ldarg.2
IL_0025:call uint8[] System.Convert::FromBase64String(string)
IL_002a:stloc.1
IL_002b:ldloc.0
IL_002c:ldloc.1
IL_002d:call uint8[] Inm.Security.Cryptography.RSAPrivateEncryption::PublicDecryption(class System.Security.Cryptography.RSACryptoServiceProvider,
uint8[])
IL_0032:stloc.2
IL_0033:call class System.Text.Encoding System.Text.Encoding::get_UTF8()
IL_0038:ldloc.2
IL_0039:callvirt instance string System.Text.Encoding::GetString(uint8[])
IL_003e:stloc.3
IL_003f:ldloc.3
IL_0040:callvirt instance int32 System.String::get_Length()
IL_0045:ldc.i4.s 15
IL_0047:bge.s IL_005d
IL_0049:ldarg.s msg
IL_004b:ldstr bytearray (E0 65 48 65 84 76 C0 6F 3B 6D 01 78 ) // .eHe.v.o;m.x
IL_0050:stind.ref
IL_0051:ldarg.s interval
IL_0053:ldc.i4.0
IL_0054:stind.i4
IL_0055:ldc.i4.0
IL_0056:stloc.s V_4
IL_0058:leave IL_00ed
IL_005d:ldloc.3
IL_005e:ldc.i4.0
IL_005f:ldc.i4.s 10
IL_0061:callvirt instance string System.String::Substring(int32,
int32)
IL_0066:ldarg.3
IL_0067:call bool System.DateTime::TryParse(string,
valuetype System.DateTime&)
IL_006c:brfalse.sIL_007e
IL_006e:ldloc.3
IL_006f:ldc.i4.s 15
IL_0071:callvirt instance string System.String::Substring(int32)
IL_0076:ldarg.1
IL_0077:call bool System.String::op_Equality(string,
string)
IL_007c:br.s IL_007f
IL_007e:ldc.i4.0
IL_007f:brfalse.sIL_00ca
IL_0081:ldloc.3
IL_0082:ldc.i4.s 11
IL_0084:ldc.i4.3
IL_0085:callvirt instance string System.String::Substring(int32,
int32)
IL_008a:ldarg.s interval
IL_008c:call bool System.Int32::TryParse(string,
int32&)
IL_0091:brfalse.sIL_00bd
IL_0093:ldarg.3
IL_0094:ldarg.3
IL_0095:ldarg.s interval
IL_0097:ldind.i4
IL_0098:conv.r8
IL_0099:call instance valuetype System.DateTime System.DateTime::AddDays(float64)
IL_009e:dup
IL_009f:stloc.s V_5
IL_00a1:stobj System.DateTime
IL_00a6:ldloc.s V_5
IL_00a8:call valuetype System.DateTime System.DateTime::get_Now()
IL_00ad:stloc.s V_5
IL_00af:ldloca.s V_5
IL_00b1:call instance valuetype System.DateTime System.DateTime::get_Date()
IL_00b6:call bool System.DateTime::op_GreaterThanOrEqual(valuetype System.DateTime,
valuetype System.DateTime)
IL_00bb:br.s IL_00be
IL_00bd:ldc.i4.0
IL_00be:ldarg.s msg
IL_00c0:ldstr bytearray (C0 6F 3B 6D 01 78 F2 5D C7 8F 1F 67 ) // .o;m.x.]...g
IL_00c5:stind.ref
IL_00c6:stloc.s V_4
IL_00c8:leave.s IL_00ed
IL_00ca:ldarg.s msg
IL_00cc:ldstr bytearray (E0 65 48 65 84 76 C0 6F 3B 6D 01 78 ) // .eHe.v.o;m.x
IL_00d1:stind.ref
IL_00d2:ldarg.s interval
IL_00d4:ldc.i4.0
IL_00d5:stind.i4
IL_00d6:ldc.i4.0
IL_00d7:stloc.s V_4
IL_00d9:leave.s IL_00ed
}// end .try
catch System.Object
{
IL_00db:pop
IL_00dc:ldarg.s msg
IL_00de:ldstr bytearray (A8 60 93 8F 65 51 84 76 C0 6F 3B 6D 01 78 0D 4E // .`..eQ.v.o;m.x.N
63 6B 6E 78 0C FF F7 8B CD 91 B0 65 93 8F 65 51 // cknx.......e..eQ
02 30 ) // .0
IL_00e3:stind.ref
IL_00e4:ldarg.s interval
IL_00e6:ldc.i4.0
IL_00e7:stind.i4
IL_00e8:ldc.i4.0
IL_00e9:stloc.s V_4
IL_00eb:leave.s IL_00ed
}// end handler
IL_00ed:ldloc.s V_4
IL_00ef:ret
} // end of method Activation::VerifyRegisterCode
原理如下:
论坛使用的是mw_syntaxhighlighter插件,
我们打开源码目录(默认位于discuz论坛下的source/plugin/mw_syntaxhighlighter目录下)看到如下文件:
我们打开discuz_plugin_mw_syntaxhighlighter_SC_UTF8.xml文件,看到如下内容:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<item id="Title"><!]></item>
<item id="Version"><!]></item>
<item id="Time"><!]></item>
<item id="From"><!http://testdzx.discuz.com/)]]></item>
<item id="Data">
<item id="plugin">
<item id="available"><!]></item>
<item id="adminid"><!]></item>
<item id="name"><!]></item>
<item id="identifier"><!]></item>
<item id="description"><!]></item>
<item id="datatables"><!]></item>
<item id="directory"><!]></item>
<item id="copyright"><!]></item>
<item id="version"><!]></item>
<item id="__modules">
<item id="0">
<item id="name"><!]></item>
<item id="menu"><!]></item>
<item id="url"><!]></item>
<item id="type"><!]></item>
<item id="adminid"><!]></item>
<item id="displayorder"><!]></item>
<item id="navtitle"><!]></item>
<item id="navicon"><!]></item>
<item id="navsubname"><!]></item>
<item id="navsuburl"><!]></item>
</item>
</item>
</item>
<item id="version"><!]></item>
<item id="var">
<item id="0">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><![CDATA[1 = 3.0.83
2 = 2.1.382]]></item>
</item>
<item id="1">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><![CDATA[Default = Default
Django = Django
Eclipse = Eclipse
Emacs = Emacs
FadeToGrey = FadeToGrey
MDUltra = MDUltra
Midnight = Midnight
RDark = RDark
None = None
Random = Random]]></item>
</item>
<item id="2">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><![CDATA[选择支持的语言,按住Ctrl键可多选
注意:AppleScript、Sass、Scss三种语言仅在3.x高亮版本库中支持]]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="extra"><![CDATA[applescript = AppleScript
actionscript3 = Actionscript3
bash = Bash shell
coldfusion = ColdFusion
c = C
cpp = C++
csharp = C#
css = CSS
delphi = Delphi
diff = Diff
erlang = Erlang
groovy = Groovy
html = HTML
java = Java
javafx = JavaFX
javascript = JavaScript
pascal = Pascal
patch = Patch
perl = Perl
php = PHP
text = Plain Text
powershell = PowerShell
python = Python
ruby = Ruby
rails = Ruby on Rails
sass = Sass
scala = Scala
scss = Scss
shell = Shell
sql = SQL
vb = Visual Basic
vbnet = Visual Basic .NET
xhtml = XHTML
xml = XML
xslt = XSLT
objc = Objective-C
asm = Asm
aauto = AAuto
golang = Golang
il = IL
lua = Lua]]></item>
<item id="__value">
<item id="0"><!]></item>
<item id="1"><!]></item>
<item id="2"><!]></item>
<item id="3"><!]></item>
<item id="4"><!]></item>
<item id="5"><!]></item>
<item id="6"><!]></item>
<item id="7"><!]></item>
<item id="8"><!]></item>
<item id="9"><!]></item>
<item id="10"><!]></item>
<item id="11"><!]></item>
<item id="12"><!]></item>
<item id="13"><!]></item>
<item id="14"><!]></item>
<item id="15"><!]></item>
<item id="16"><!]></item>
<item id="17"><!]></item>
<item id="18"><!]></item>
<item id="19"><!]></item>
<item id="20"><!]></item>
<item id="21"><!]></item>
<item id="22"><!]></item>
<item id="23"><!]></item>
<item id="24"><!]></item>
<item id="25"><!]></item>
<item id="26"><!]></item>
<item id="27"><!]></item>
<item id="28"><!]></item>
<item id="29"><!]></item>
<item id="30"><!]></item>
<item id="31"><!]></item>
<item id="32"><!]></item>
<item id="33"><!]></item>
<item id="34"><!]></item>
<item id="35"><!]></item>
<item id="36"><!]></item>
<item id="37"><!]></item>
<item id="38"><!]></item>
<item id="39"><!]></item>
<item id="40"><!]></item>
</item>
</item>
<item id="3">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="4">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><![CDATA[仅适用于3.x版本,快速复制代码将使得复制代码到剪切板更加方便。
在高亮代码区域任意双击,区域所有代码将可以直接复制。]]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="5">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="6">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="7">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><![CDATA[1 = None
2 = Auto
3 = 1
4 = 2
5 = 3
6 = 4
7 = 5]]></item>
</item>
<item id="8">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="9">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><![CDATA[代码框自动收缩。如果要使用此选项,必须开启“显示工具条”。
开启此项,“显示工具条”将自动开启。]]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="10">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="11">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="12">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="13">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
<item id="14">
<item id="displayorder"><!]></item>
<item id="title"><!]></item>
<item id="description"><!]></item>
<item id="variable"><!]></item>
<item id="type"><!]></item>
<item id="value"><!]></item>
<item id="extra"><!]></item>
</item>
</item>
<item id="language">
<item id="scriptlang">
<item id="syntaxhighlighter_viewsource"><!]></item>
<item id="syntaxhighlighter_copycode"><!]></item>
</item>
<item id="templatelang">
<item id="syntaxhighlighter_select_lang"><!]></item>
<item id="syntaxhighlighter_show_gutter"><!]></item>
<item id="syntaxhighlighter_your_code"><!]></item>
<item id="syntaxhighlighter_close"><!]></item>
<item id="syntaxhighlighter_submit"><!]></item>
<item id="syntaxhighlighter_cancle"><!]></item>
<item id="syntaxhighlighter_copyed"><!]></item>
</item>
</item>
</item>
</root>
其中的“IL = IL”与“<item id="40"><!]></item>”是我增添的项,其他文件也一样修改(后来发现,此处似乎没什么用,只是插件初次安装时的配置,真正的配置在数据库中)
我们打开syntaxhighlighter3目录,看到一个“scripts”目录,打开看到如下画面:
我们随便打开一个文件(本例为shBrushJScript.js),看到如下内容:
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
;(function()
{
// CommonJS
typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
function Brush()
{
var keywords = 'break case catch continue ' +
'default delete do else false' +
'for function if in instanceof ' +
'new null return super switch ' +
'this throw true try typeof var while with'
;
var r = SyntaxHighlighter.regexLib;
this.regexList = [
{ regex: r.multiLineDoubleQuotedString, css: 'string' }, // double quoted strings
{ regex: r.multiLineSingleQuotedString, css: 'string' }, // single quoted strings
{ regex: r.singleLineCComments, css: 'comments' }, // one line comments
{ regex: r.multiLineCComments, css: 'comments' }, // multiline comments
{ regex: /\s*#.*/gm, css: 'preprocessor' }, // preprocessor tags like #region and #endregion
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' } // keywords
];
this.forHtmlScript(r.scriptScriptTags);
};
Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases = ['js', 'jscript', 'javascript'];
SyntaxHighlighter.brushes.JScript = Brush;
// CommonJS
typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
})();
我们很容易可以看出,此处是根据正则表达式去匹配文本,匹配的文本会应用对应的CSS样式,且越靠前的规则越优先。
我们在论坛HTML源码中很容易就可以看出论坛使用的是RDark主题:
我仿照shBrushJScript.js编写了shBrushIL.js,内容如下:
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
;(function()
{
// CommonJS
typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
function Brush()
{
//此函数与SyntaxHighlighter3的原生函数getKeywords相比支持了符号开头的关键字
function getKeywordsIL(str)
{
str = str
.replace(/^\s+|\s+$/g, '')
.replace(/\s+/g, '|')
;
return '(?<=([^A-Za-z0-9_.]|^|$))(?:' + str + ')(?=([^A-Za-z0-9_.]|^|$))';
}
//这堆关键字,一部分是我从网上的IL语言指令集里抓出来的,另一部分是C#的关键字,不知道还有没有缺的,欢迎大家评论发表意见和建议
var keywords = 'nop break ldarg.0 ldarg.1 ldarg.2 ldarg.3 ldloc.0 ldloc.1 ldloc.2 ldloc.3 stloc.0 ' +
'stloc.1 stloc.2 stloc.3 ldarg.s ldarga.s starg.s ldloc.s ldloca.s stloc.s ldnull ldc.i4.m1 ' +
'ldc.i4.M1 ldc.i4.0 ldc.i4.1 ldc.i4.2 ldc.i4.3 ldc.i4.4 ldc.i4.5 ldc.i4.6 ldc.i4.7 ldc.i4.8 ' +
'ldc.i4.s ldc.i4 ldc.i8 ldc.r4 ldc.r8 dup pop jmp call calli ret br.s brfalse.s brnull.s brzero.s ' +
'brinst.s brtrue.s beq.s bge.s bgt.s ble.s blt.s bne.un.s bge.un.s bgt.un.s ble.un.s blt.un.s ' +
'br brfalse brnull brzero brinst brtrue beq bge bgt ble blt bne.un bge.un bgt.un ble.un blt.un ' +
'switch ldind.i1 ldind.u1 ldind.i2 ldind.u2 ldind.i4 ldind.u4 ldind.i8 ldind.u8 ldind.i ldind.r4 ' +
'ldind.r8 ldind.ref stind.ref stind.i1 stind.i2 stind.i4 stind.i8 stind.r4 stind.r8 add sub mul div ' +
'div.un rem rem.un and or xor shl shr shr.un neg not conv.i1 conv.i2 conv.i4 conv.i8 conv.r4 ' +
'conv.r8 conv.u4 conv.u8 callvirt cpobj ldobj ldstr newobj castclass isinst conv.r.un unbox ' +
'throw ldfld ldflda stfld ldsfld ldsflda stsfld stobj conv.ovf.i1.un conv.ovf.i2.un conv.ovf.i4.un ' +
'conv.ovf.i8.un conv.ovf.u1.un conv.ovf.u2.un conv.ovf.u4.un conv.ovf.u8.un conv.ovf.i.un conv.ovf.u.un ' +
'box newarr ldlen ldelema ldelem.i1 ldelem.u1 ldelem.i2 ldelem.u2 ldelem.i4 ldelem.u4 ldelem.i8 ldelem.u8 ' +
'ldelem.i ldelem.r4 ldelem.r8 ldelem.ref stelem.i stelem.i1 stelem.i2 stelem.i4 stelem.i8 stelem.r4 ' +
'stelem.r8 stelem.ref ldelem stelem unbox.any conv.ovf.i1 conv.ovf.u1 conv.ovf.i2 conv.ovf.u2 conv.ovf.i4 ' +
'conv.ovf.u4 conv.ovf.i8 conv.ovf.u8 refanyval ckfinite mkrefany ldtoken conv.u2 conv.u1 conv.i conv.ovf.i ' +
'conv.ovf.u add.ovf add.ovf.un mul.ovf mul.ovf.un sub.ovf sub.ovf.un endfault endfinally leave leave.s ' +
'stind.i conv.u arglist ceq cgt cgt.un clt clt.un ldftn ldvirtftn ldarg ldarga starg ldloc ldloca stloc ' +
'localloc endfilter (alignment) volatile tail initobj constrained cpblk initblk rethrow sizeof refanytype ' +
'readonly .try catch .locals .method public bool instance valuetype string int32 cil managed hidebysig .maxstack ' +
'class uint8 void private protected internal bytearray privatescope famandassem assembly family famorassem final newslot specialname pinvokeimpl ' +
'rtspecialname native runtime unmanaged internalcall synchronized noinlining box unbox ' +
'br.s nearer ' +
'abstract as base bool break byte case catch char checked class const ' +
'continue decimal default delegate do double else enum event explicit ' +
'extern false finally fixed float for foreach get goto if implicit in int ' +
'interface internal is lock long namespace new null object operator out ' +
'override params private protected public readonly ref return sbyte sealed set ' +
'short sizeof stackalloc static string struct switch this throw true try ' +
'typeof uint ulong unchecked unsafe ushort using virtual void while';
var r = SyntaxHighlighter.regexLib;
this.regexList = [
{ regex: r.multiLineDoubleQuotedString, css: 'string' }, // double quoted strings 双引号字符串
{ regex: r.multiLineSingleQuotedString, css: 'string' }, // single quoted strings 单引号字符串
{ regex: r.singleLineCComments, css: 'comments' }, // one line comments 单行注释
{ regex: r.multiLineCComments, css: 'comments' }, // multiline comments 多行注释
{ regex: new RegExp(getKeywordsIL(keywords), 'gm'), css: 'keyword' }, // keywords 关键字
{ regex: /\[[^\[\]]+\]/gm, css: 'color3' },//匹配方括号括起来的库名
{ regex: /IL_+\:/gm, css: 'preprocessor'},//IL开头的行号
{ regex: /IL_+/gm, css: 'preprocessor'},//IL开头的跳转参数
{ regex: /\b+\b/gm, css: 'value'},//十六进制/十进制数值
{ regex: /V_+/gm, css: 'variable'},//变量
];
this.forHtmlScript(r.scriptScriptTags);
};
Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases = ['il'];//刷子名
SyntaxHighlighter.brushes.il = Brush;
// CommonJS
typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
})();
然后我又修改了插件根目录下的mw_syntaxhighlighter.class.php文件,修改后内容如下:
<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class plugin_mw_syntaxhighlighter {
var $libversion = '';//note 使用高亮版本
var $theme = '';//note 颜色主题
var $libfolder = '';//note 高亮库所在目录
var $autolinks = '';
var $quickcodecopy = '';
var $gutter = '';
var $startlinenumber = '';
var $linenumberpadding = '';
var $toolbar = '';
var $collapse = '';
var $smarttabs = '';
var $tabsize = '';
var $wraplines = '';
var $title = '';
var $maxheight = '';
var $legacy_enable = '';
var $legacy = '';
var $collapse_lable_text = '';
var $collapse_lable = '';
var $pluginurl = '';
var $brush_files = '';
var $sh_lang_3 = '';
var $sh_lang_2 = '';
var $select_language = '';
public function __construct() {
global $_G;
$this->pluginurl = "https://avatar.52pojie.cn/mw_syntaxhighlighter/";//此处是插件目录,根据需要修改,这个文件中还有一处,我忘了在哪了,用52pojie作为关键字搜索即可
$this->sh_lang_3 = array(
"asm" => array('Asm', 'true'),
"applescript" => array('AppleScript', 'true'),
"actionscript3" => array('Actionscript3', 'true'),
"bash" => array('Bash shell', 'true'),
"coldfusion" => array('ColdFusion', 'true'),
"c" => array('C', 'true'),
"cpp" => array('C++', 'true'),
"csharp" => array('C#', 'true'),
"css" => array('CSS', 'true'),
"delphi" => array('Delphi', 'true'),
"diff" => array('Diff', 'true'),
"erlang" => array('Erlang', 'true'),
"groovy" => array('Groovy', 'true'),
"html" => array('HTML', 'true'),
"il" => array('IL', 'true'),
"java" => array('Java', 'true'),
"javafx" => array('JavaFX', 'true'),
"javascript" => array('JavaScript', 'true'),
"pascal" => array('Pascal', 'true'),
"patch" => array('Patch', 'true'),
"perl" => array('Perl', 'true'),
"php" => array('PHP', 'true'),
"text" => array('Plain Text', 'true'),
"powershell" => array('PowerShell', 'true'),
"python" => array('Python', 'true'),
"ruby" => array('Ruby', 'true'),
"rails" => array('Ruby on Rails', 'true'),
"sass" => array('Sass', 'true'),
"scala" => array('Scala', 'true'),
"scss" => array('Scss', 'true'),
"shell" => array('Shell', 'true'),
"sql" => array('SQL', 'true'),
"vb" => array('Visual Basic', 'true'),
"vbnet" => array('Visual Basic .NET', 'true'),
"xhtml" => array('XHTML', 'true'),
"xml" => array('XML', 'true'),
"xslt" => array('XSLT', 'true'),
"objc" => array('Objective-C', 'true'),
"asm" => array('Asm', 'true'),
"aauto" => array('AAuto', 'true'),
"golang" => array('Golang', 'true'),
"lua" => array('Lua', 'true'),
);
$this->sh_lang_2 = array(
"asm" => array('Asm', 'true'),
"actionscript3" => array('Actionscript3', 'true'),
"bash" => array('Bash shell', 'true'),
"coldfusion" => array('ColdFusion', 'true'),
"c" => array('C', 'true'),
"cpp" => array('C++', 'true'),
"csharp" => array('C#', 'true'),
"css" => array('CSS', 'true'),
"delphi" => array('Delphi', 'true'),
"diff" => array('Diff', 'true'),
"erlang" => array('Erlang', 'true'),
"groovy" => array('Groovy', 'true'),
"html" => array('HTML', 'true'),
"java" => array('Java', 'true'),
"javafx" => array('JavaFX', 'true'),
"javascript" => array('JavaScript', 'true'),
"pascal" => array('Pascal', 'true'),
"patch" => array('Patch', 'true'),
"perl" => array('Perl', 'true'),
"php" => array('PHP', 'true'),
"text" => array('Plain Text', 'true'),
"powershell" => array('PowerShell', 'true'),
"python" => array('Python', 'true'),
"ruby" => array('Ruby', 'true'),
"rails" => array('Ruby on Rails', 'true'),
"scala" => array('Scala', 'true'),
"shell" => array('Shell', 'true'),
"sql" => array('SQL', 'true'),
"vb" => array('Visual Basic', 'true'),
"vbnet" => array('Visual Basic .NET', 'true'),
"xhtml" => array('XHTML', 'true'),
"xml" => array('XML', 'true'),
"xslt" => array('XSLT', 'true'),
"objc" => array('Objective-C', 'true'),
"asm" => array('Asm', 'true'),
"aauto" => array('AAuto', 'true'),
"golang" => array('Golang', 'true'),
"lua" => array('Lua', 'true'),
);
$this->brush_files = array(
"Asm" => array('shBrushAsm.js', 'asm', '2.1', 'true'),
"AppleScript" => array('shBrushAppleScript.js', 'applescript', '3.0', 'true'),
"ActionScript3" => array('shBrushAS3.js', 'as3 actionscript3', '2.1', 'true'),
"Bash" => array('shBrushBash.js', 'bash shell', '2.1', 'true'),
"ColdFusion" => array('shBrushColdFusion.js', 'cf coldfusion', '2.1', 'true'),
"C++" => array('shBrushCpp.js', 'cpp c', '1.5', 'true'),
"C#" => array('shBrushCSharp.js', 'c# c-sharp csharp', '1.5', 'true'),
"CSS" => array('shBrushCss.js', 'css', '1.5', 'true'),
"Delphi" => array('shBrushDelphi.js', 'delphi pas pascal', '1.5', 'true'),
"Diff" => array('shBrushDiff.js', 'diff patch', '2.1', 'true'),
"Erlang" => array('shBrushErlang.js', 'erl erlang', '2.1', 'true'),
"Groovy" => array('shBrushGroovy.js', 'groovy', '2.1', 'true'),
"IL" => array('shBrushIL.js', 'il', '3.0', 'true'),
"Java" => array('shBrushJava.js', 'java', '1.5', 'true'),
"JavaFX" => array('shBrushJavaFX.js', 'jfx javafx', '2.1', 'true'),
"JavaScript" => array('shBrushJScript.js', 'js jscript javascript', '1.5', 'true'),
"Perl" => array('shBrushPerl.js', 'perl pl', '2.1', 'true'),
"PHP" => array('shBrushPhp.js', 'php', '1.5', 'true'),
"PlainText" => array('shBrushPlain.js', 'plain text', '2.1', 'true'),
"PowerShell" => array('shBrushPowerShell.js', 'ps powershell', '2.1', 'true'),
"Python" => array('shBrushPython.js', 'py python', '1.5', 'true'),
"Ruby" => array('shBrushRuby.js', 'rails ror ruby rb', '1.5', 'true'),
"Sass" => array('shBrushSass.js', 'sass scss', '3.0', 'true'),
"Scala" => array('shBrushScala.js', 'scala', '2.1', 'true'),
"SQL" => array('shBrushSql.js', 'sql', '1.5', 'true'),
"VisualBasic" => array('shBrushVb.js', 'vb vbnet', '1.5', 'true'),
"XML" => array('shBrushXml.js', 'xml xhtml xslt html', '1.5', 'true'),
"Objective-C" => array('shBrushObjC.js', 'objc', '2.1', 'true'),
"Asm" => array('shBrushAsm.js', 'asm', '2.1', 'true'),
"AAuto" => array('shBrushAAuto.js', 'aauto', '2.1', 'true'),
"Golang" => array('shBrushGo.js', 'go golang', '2.1', 'true'),
"Lua" => array('shBrushLua.js', 'lua', '2.1', 'true'),
);
if($_G['cache']['plugin']['mw_syntaxhighlighter']['libversion'] == 2) {
$this->libversion = '2.1.382';
$this->libfolder = 'syntaxhighlighter2';
} else {
$this->libversion = '3.0.83';
$this->libfolder = 'syntaxhighlighter3';
}
$this->theme = $_G['cache']['plugin']['mw_syntaxhighlighter']['theme'] ? $_G['cache']['plugin']['mw_syntaxhighlighter']['theme'] : 'Random';//note 没有选择则随机显示
$this->select_language = unserialize($_G['cache']['plugin']['mw_syntaxhighlighter']['language']);
$this->autolinks = $_G['cache']['plugin']['mw_syntaxhighlighter']['autolinks'];
$this->quickcodecopy = $_G['cache']['plugin']['mw_syntaxhighlighter']['quickcodecopy'];
$this->gutter = $_G['cache']['plugin']['mw_syntaxhighlighter']['gutter'];
$this->startlinenumber = intval($_G['cache']['plugin']['mw_syntaxhighlighter']['startlinenumber']);
$this->linenumberpadding = $_G['cache']['plugin']['mw_syntaxhighlighter']['linenumberpadding'];
$this->toolbar = $_G['cache']['plugin']['mw_syntaxhighlighter']['toolbar'];
$this->collapse = $_G['cache']['plugin']['mw_syntaxhighlighter']['collapse'];
$this->smarttabs = $_G['cache']['plugin']['mw_syntaxhighlighter']['smarttabs'];
$this->tabsize = intval($_G['cache']['plugin']['mw_syntaxhighlighter']['tabsize']);
$this->wraplines = $_G['cache']['plugin']['mw_syntaxhighlighter']['wraplines'];
$this->title = str_replace('\'', ''', $_G['cache']['plugin']['mw_syntaxhighlighter']['title']);
$this->maxheight = $_G['cache']['plugin']['mw_syntaxhighlighter']['maxheight'];
$this->legacy_enable = $_G['cache']['plugin']['mw_syntaxhighlighter']['legacy'];//note 暂时未做表单提交
if($this->legacy_enable == 1) {
$this->legacy = "dp.SyntaxHighlighter.HighlightAll('code')";
} else {
$this->legacy = '';
}
$this->collapse_lable_text = str_replace('\'', ''', $_G['cache']['plugin']['mw_syntaxhighlighter']['collapse_lable_text']);//note 暂时未做表单提交
if($this->libversion == '3.0.83') {
if($this->collapse_lable_text != '' && $this->title == '') {
$this->collapse_lable = $this->collapse_lable_text;
} else {
$this->collapse_lable = '+ expand source';
}
} elseif($this->libversion == '2.1.382') {
if($this->collapse_lable_text != '') {
$this->collapse_lable = $this->collapse_lable_text;
} else {
$this->collapse_lable = 'show source';
}
}
foreach($this->brush_files as $lang => $val) {
$intersectarray = array_intersect(explode(' ', $val), $this->select_language);
if(empty($intersectarray)) {
unset($this->brush_files[$lang]);
}
}
}
function global_header() {
global $_G;
if(CURMODULE == 'viewthread') {
if($_G['mw_flag']) {
return $this->_syntaxhighlighter_load_header_css();
}
}
}
function global_footer() {
global $_G;
$codebox = $syntaxhighlighter = $codbox_script = '';
if(CURMODULE == 'viewthread') {
$codebox = $this->_mw_shl_codebox_script('fastpost');
} elseif(CURMODULE == 'forumdisplay') {
$codebox = $this->_mw_shl_codebox_script('fastpost');
} elseif(CURMODULE == 'post') {
$codebox = $this->_mw_shl_codebox_script('newthread');
}
if(CURMODULE == 'viewthread' && $_G['mw_flag']) {
include_once template('mw_syntaxhighlighter:module');
$syntaxhighlighter = $this->_syntaxhighlighter_load_footer_script();
$syntaxhighlighter .= mw_code_toolbar_handler($this->libversion);
}
if(CURMODULE == 'viewthread' || CURMODULE == 'forumdisplay' || CURMODULE == 'post') {
include_once template('mw_syntaxhighlighter:module');
if($this->libversion == '3.0.83') {
$sh_lang = $this->sh_lang_3;
} elseif($this->libversion == '2.1.382') {
$sh_lang = $this->sh_lang_2;
} else {
return;
}
if($this->select_language) {
foreach($sh_lang as $lang => $val) {
if(!in_array($lang, $this->select_language)) {
unset($sh_lang[$lang]);
}
}
} else {
return;
}
$codbox_script = mw_syntaxhighlighter_shl_codebox($sh_lang, $this->gutter).
'<script type="text/javascript" src="https://avatar.52pojie.cn/mw_syntaxhighlighter/js/mw_syntaxhighlighter.js?'.VERHASH.'"></script>';
}
return $codbox_script.$codebox.$syntaxhighlighter;
}
function _syntaxhighlighter_load_header_css() {
global $_G;
$theme_css_list['Default'] = array('1', 'shCoreDefault.css', 'shThemeDefault.css');
$theme_css_list['Django'] = array('2', 'shCoreDjango.css', 'shThemeDjango.css');
$theme_css_list['Eclipse'] = array('3', 'shCoreEclipse.css', 'shThemeEclipse.css');
$theme_css_list['Emacs'] = array('4', 'shCoreEmacs.css', 'shThemeEmacs.css');
$theme_css_list['FadeToGrey'] = array('5', 'shCoreFadeToGrey.css', 'shThemeFadeToGrey.css');
$theme_css_list['MDUltra'] = array('8', 'shCoreMDUltra.css', 'shThemeMDUltra.css');
$theme_css_list['Midnight'] = array('6', 'shCoreMidnight.css', 'shThemeMidnight.css');
$theme_css_list['RDark'] = array('7', 'shCoreRDark.css', 'shThemeRDark.css');
//$csslink = '<link rel="stylesheet" type="text/css" href="'.$this->pluginurl.$this->libfolder.'/styles/shCore.css?ver='.$this->libversion.'&'.VERHASH.'" />';
$csslink = '<style type="text/css">'."\r\n";
$csslink .= '@import url(\''.$this->pluginurl.$this->libfolder.'/styles/shCore.css?ver='.$this->libversion.'\');'."\r\n";
if($this->theme == 'Random') {
if($this->libversion == '3.0.83') {
$theme_no = mt_rand(1, 8);
foreach($theme_css_list as $themename => $val) {
if($theme_no == $val) {
//$csslink .= '<link rel="stylesheet" type="text/css" href="'.$this->pluginurl.$this->libfolder.'/styles/'.$val.'?ver='.$this->libversion.'&'.VERHASH.'" />';
//$csslink .= '<link rel="stylesheet" type="text/css" href="'.$this->pluginurl.$this->libfolder.'/styles/'.$val.'?ver='.$this->libversion.'&'.VERHASH.'" />';
$csslink .= '@import url(\''.$this->pluginurl.$this->libfolder.'/styles/'.$val.'?ver='.$this->libversion.'\');'."\r\n";
$csslink .= '@import url(\''.$this->pluginurl.$this->libfolder.'/styles/'.$val.'?ver='.$this->libversion.'\');'."\r\n";
}
}
}
if($this->libversion == '2.1.382') {
$theme_no = mt_rand(1, 7);
foreach($theme_css_list as $themename => $val) {
if($theme_no == $val) {
//$csslink .= '<link rel="stylesheet" type="text/css" href="'.$this->pluginurl.$this->libfolder.'/styles/'.$val.'?ver='.$this->libversion.'&'.VERHASH.'" />';
$csslink .= '@import url(\''.$this->pluginurl.$this->libfolder.'/styles/'.$val.'?ver='.$this->libversion.'\');'."\r\n";
}
}
}
} else {
if($this->libversion == '2.1.382' && $this->theme == 'MDUltra') {
//$csslink .= '<link rel="stylesheet" type="text/css" href="'.$this->pluginurl.$this->libfolder.'/styles/shThemeDefault.css?ver='.$this->libversion.'&'.VERHASH.'" />';
$csslink .= '@import url(\''.$this->pluginurl.$this->libfolder.'/styles/shThemeDefault.css?ver='.$this->libversion.'\');'."\r\n";
} else {
if($this->libversion == '3.0.83') {
//$csslink .= '<link rel="stylesheet" type="text/css" href="'.$this->pluginurl.$this->libfolder.'/styles/'.$theme_css_list[$this->theme].'?ver='.$this->libversion.'&'.VERHASH.'" />';
$csslink .= '@import url(\''.$this->pluginurl.$this->libfolder.'/styles/'.$theme_css_list[$this->theme].'?ver='.$this->libversion.'\');'."\r\n";
}
//$csslink .= '<link rel="stylesheet" type="text/css" href="'.$this->pluginurl.$this->libfolder.'/styles/'.$theme_css_list[$this->theme].'?ver='.$this->libversion.'&'.VERHASH.'" />';
$csslink .= '@import url(\''.$this->pluginurl.$this->libfolder.'/styles/'.$theme_css_list[$this->theme].'?ver='.$this->libversion.'\');'."\r\n";
}
}
//$csslink .= '<meta id="syntaxhighlighteranchor" name="syntaxhighlighter-version" content="3.1.3" />';
$csslink .= '.syntaxhighlighter,
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
font-size: 14px !important; /* Set the font size in pixels */
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; /* Set the font type */
}
.syntaxhighlighter table caption {
/* For Title(Caption) */
font-size: 14px !important; /* Set the font size in pixels */
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; /* Set the font type */
}
.syntaxhighlighter.nogutter td.code .line {
/* Set the left padding space when no-gutter in ver. 3.0 */
padding-left: 3px !important;
}
.syntaxhighlighter .lines {
padding: 5px 0px 5px 0px !important;
}
.syntaxhighlighter .line .number {
padding: 5px 5px 5px 0 !important;
}
.syntaxhighlighter .line .content {
padding: 5px 0px 5px 10px !important;
}
/* For gutter */
.syntaxhighlighter table td.code {
width:auto !important;
}
.syntaxhighlighter table td.gutter .line {
padding: 0 0.5em !important;
}
.syntaxhighlighter .gutter {
width: 40px !important;
}
.syntaxhighlighter table td.gutter .line {
padding: 5px 5px 5px 0 !important;
}
.syntaxhighlighter table td.code .line {
padding: 5px 0px 5px 10px !important;
}
.syntaxhighlighter {
/* For Chrome/Safari(WebKit) */
/* Hide the superfluous vertical scrollbar in ver. 3.0 */
/*overflow-y: hidden !important;*/
padding: 1px !important;
}
.syntaxhighlighter {
width: 99.7% !important;
'.($this->maxheight ? 'max-height: '.$this->maxheight.'px !important;' : '').'
'.($this->maxheight ? 'height:expression(this.scrollHeight > '.$this->maxheight.' ? "'.$this->maxheight.'px" : "auto");' : '').'
overflow-y: auto;
}
/* For Title(Caption) */
font-size: 10px !important; /* Set the font size in pixels */
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; /* Set the font type */
}';
$csslink .= "\r\n".'</style>'."\r\n";
return $csslink;
}
function _syntaxhighlighter_load_footer_script() {
global $_G;
$script = "\n<!-- mw_syntaxhighlighter ver.".$this->libversion." Begin -->\n";
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/shCore.js?ver=".$this->libversion."\"></script>\n";
if($this->legacy_enable == 1) {
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/shLegacy.js?ver=".$this->libversion."\"></script>\n";
}
if($this->libversion == '3.0.83' && $this->legacy_enable == 0) {
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/shAutoloader.js?ver=".$this->libversion."\"></script>\n";
if($this->brush_files == 'true' || $_G['adminid'] == 1) {
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/shBrushXml.js?ver=".$this->libversion."\"></script>\n";
}
} elseif($this->libversion == '3.0.83' && $this->legacy_enable == 1) {
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/shAutoloader.js?ver=".$this->libversion."\"></script>\n";
foreach($this->brush_files as $lang => $val) {
$brush_file = $val;
$brush_ver = $val;
$brush_enable = $val;
if(($brush_ver == '3.0' || $brush_ver == '2.1' || $brush_ver == '1.5') && $brush_enable == 'true') {
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/".$brush_file."?ver=".$this->libversion."\"></script>\n";
} elseif (($brush_ver == '3.0' || $brush_ver == 'all') && $brush_enable == 'added') {
$script .= "<script type=\"text/javascript\" src=\"".$brush_file."?ver=".$this->libversion."\"></script>\n";
}
}
if($_G['adminid'] == 1 && $this->brush_files == 'false') {
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/shBrushXml.js?ver=".$this->libversion."\"></script>\n";
}
} elseif($this->libversion == '2.1.382') {
foreach($this->brush_files as $lang => $val) {
$brush_file = $val;
$brush_ver = $val;
$brush_enable = $val;
if (($brush_ver == '2.1' || $brush_ver == '1.5') && $brush_enable == 'true') {
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/".$brush_file."?ver=".$this->libversion."\"></script>\n";
} elseif (($brush_ver == '2.1' || $brush_ver == 'all') && $brush_enable == 'added') {
$script .= "<script type=\"text/javascript\" src=\"".$brush_file."?ver=".$this->libversion."\"></script>\n";
}
}
if($_G['adminid'] == 1 && $this->brush_files == 'false') {
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/shBrushPhp.js?ver=".$this->libversion."\"></script>\n";
}
if($_G['adminid'] == 1 && $this->brush_files == 'false') {
$script .= "<script type=\"text/javascript\" src=\"".$this->pluginurl.$this->libfolder."/scripts/shBrushXml.js?ver=".$this->libversion."\"></script>\n";
}
}
if($this->libversion == '3.0.83') {
$script .= "<script type=\"text/javascript\">//<![CDATA[
SyntaxHighlighter.autoloader(\n";
$count = 0;
foreach($this->brush_files as $lang => $val) {
$brush_file = $val;
$brush_alias = $val;
$brush_ver = $val;
$brush_enable = $val;
if ($brush_enable == 'true' || ($_G['adminid'] == 1 && $lang == "PHP")) {
$count = $count + 1;
if ($count == 1) {
$script .= " \"".$brush_alias." ".$this->pluginurl.$this->libfolder."/scripts/".$brush_file."?ver=".$this->libversion."\"\n";
} else {
$script .= " ,\"".$brush_alias." ".$this->pluginurl.$this->libfolder."/scripts/".$brush_file."?ver=".$this->libversion."\"\n";
}
} elseif (($brush_ver == '3.0' || $brush_ver == 'all') && $brush_enable == 'added') {
$count = $count + 1;
if ($count == 1) {
$script .= " \"".$brush_alias." ".$brush_file."?ver=".$this->libversion."\"\n";
} else {
$script .= " ,\"".$brush_alias." ".$brush_file."?ver=".$this->libversion."\"\n";
}
}
}
$script .= " );
SyntaxHighlighter.defaults['auto-links'] = ".($this->autolinks ? 'true' : 'false').";
SyntaxHighlighter.defaults['quick-code'] = ".($this->quickcodecopy ? 'true' : 'false').";
SyntaxHighlighter.defaults['title'] = '".$this->title."';
SyntaxHighlighter.defaults['class-name'] = 'notranslate';
SyntaxHighlighter.defaults['collapse'] = ".($this->collapse ? 'true' : 'false').";
SyntaxHighlighter.defaults['first-line'] = ".$this->startlinenumber.";
SyntaxHighlighter.defaults['gutter'] = ".($this->gutter ? 'true' : 'false').";
SyntaxHighlighter.defaults['pad-line-numbers'] = ".($this->linenumberpadding ? $this->linenumberpadding : 'false').";
SyntaxHighlighter.defaults['smart-tabs'] = ".($this->smarttabs ? 'true' : 'false').";
SyntaxHighlighter.defaults['tab-size'] = ".$this->tabsize.";
SyntaxHighlighter.defaults['toolbar'] = ".($this->toolbar ? 'true' : 'false').";\n";
//echo $script;
if($this->legacy_enable == 1) {
$script .= " SyntaxHighlighter.config.stripBrs = true;\n";
}
$script .= " SyntaxHighlighter.config.strings.expandSource = '".$this->collapse_lable."';
SyntaxHighlighter.config.strings.help = '?';
SyntaxHighlighter.config.strings.alert = 'SyntaxHighlighter';
SyntaxHighlighter.config.strings.noBrush = \"Can\'t find brush for: \";
SyntaxHighlighter.config.strings.brushNotHtmlScript = \"Brush wasn\'t configured for html-script option: \";
SyntaxHighlighter.all();
".$this->legacy."
//]]></script>
<!-- mw_syntaxhighlighter ver.".$this->libversion." End -->\n";
} elseif($this->libversion == '2.1.382') {
$script.= "<script type=\"text/javascript\">//<![CDATA[
SyntaxHighlighter.config.clipboardSwf = '".$this->pluginurl.$this->libfolder."/scripts/clipboard.swf';
SyntaxHighlighter.defaults['auto-links'] = ".$this->autolinks.";
SyntaxHighlighter.defaults['class-name'] = '';
SyntaxHighlighter.defaults['collapse'] = ".$this->collapse.";
SyntaxHighlighter.defaults['first-line'] = ".$this->startlinenumber.";
SyntaxHighlighter.defaults['gutter'] = ".$this->gutter.";
SyntaxHighlighter.defaults['pad-line-numbers'] = ".$this->linenumberpadding.";
SyntaxHighlighter.defaults['smart-tabs'] = ".$this->smarttabs.";
SyntaxHighlighter.defaults['tab-size'] = ".$this->tabsize.";
SyntaxHighlighter.defaults['toolbar'] = ".$this->toolbar.";
SyntaxHighlighter.defaults['wrap-lines'] = ".$this->wraplines.";\n";
if ($this->legacy_enable == 1) {
$script .= " SyntaxHighlighter.config.stripBrs = true;\n";
}
$script .= " SyntaxHighlighter.config.strings.expandSource = '".$this->collapse_lable."';
SyntaxHighlighter.config.strings.viewSource = 'view source';
SyntaxHighlighter.config.strings.copyToClipboard = 'copy to clipboard';
SyntaxHighlighter.config.strings.copyToClipboardConfirmation = 'The code is in your clipboard now';
SyntaxHighlighter.config.strings.print = 'print';
SyntaxHighlighter.config.strings.help = '?';
SyntaxHighlighter.config.strings.alert = 'SyntaxHighlighter';
SyntaxHighlighter.config.strings.noBrush = \"Can\'t find brush for: \";
SyntaxHighlighter.config.strings.brushNotHtmlScript = \"Brush wasn\'t configured for html-script option: \";
SyntaxHighlighter.all();
".$this->legacy."
//]]></script>
<!-- mw_syntaxhighlighter ver.".$this->libversion." End -->\n";
}
return $script;
}
function _mw_shl_codebox_script($textareaid) {
return '<script type="text/javascript" reload="1">mw_syntaxhighlighter("'.$textareaid.'");</script>';
}
function discuzcode($param) {
global $_G;
if(strpos($_G['discuzcodemessage'], 'mw_shl_code') !== false) {
$_G['mw_flag'] = true;
}
if($param['caller'] == 'discuzcode') {
$_G['discuzcodemessage'] = preg_replace_callback('/\(.*?)\[\/mw_shl_code\]/is', array($this, '_mw_shl_code_to_pre'), $_G['discuzcodemessage']);
}
if($param['caller'] == 'messagecutstr') {
$_G['discuzcodemessage'] = preg_replace('/\(.*?)\[\/mw_shl_code\]/is', '', $_G['discuzcodemessage']);
}
}
function _mw_shl_code_to_pre($matches) {
global $_G, $post;
$brush = $matches;
$gutter = $matches;
$code = $matches;
if($this->libversion == '3.0.83') {
$sh_lang = $this->sh_lang_3;
} elseif($this->libversion == '2.1.382') {
$sh_lang = $this->sh_lang_2;
} else {
return;
}
$code = str_replace(array('<br />', '<br>'), '', $code);
//$code = dhtmlspecialchars(str_replace('\\"', '"', $code));
$_G['mw_code'][$post['pid']][] = $code;
$toolbarstr = '<div style="font-size:12px;">['.$sh_lang[$brush].'] <em class="viewsource" style="cursor:pointer;font-size:12px;color:#369 !important;">'.lang('plugin/mw_syntaxhighlighter', 'syntaxhighlighter_viewsource').'</em> <em class="copycode" style="cursor:pointer;font-size:12px;color:#369 !important;">'.lang('plugin/mw_syntaxhighlighter', 'syntaxhighlighter_copycode').'</em></div>';
return '<div style="padding:15px 0;">'.$toolbarstr.'<pre class="brush: '.strtolower($brush).'; gutter: '.$gutter.'">'.$code.'</pre></div>';
}
}
class plugin_mw_syntaxhighlighter_forum extends plugin_mw_syntaxhighlighter {
function viewthread_bottom_output() {
global $postlist;
foreach($postlist as $pid => $post) {
$post['message'] = preg_replace_callback('/<pre[^>](.*?)>(.*?)<\/pre>/is', create_function('$matches', 'return plugin_mw_syntaxhighlighter_forum::_brreplace($matches, $matches, '.intval($pid).');'), $post['message']);
$postlist[$pid] = $post;
}
return '';
}
function _brreplace($param, $codecontent, $pid) {
global $_G;
return '<pre '.stripslashes($param).'>'.str_replace(array('<br>', '<br />'), '', array_shift($_G['mw_code'][$pid])).'</pre>';
}
function post_infloat_btn_extra_output() {
if(CURMODULE == 'post') {
return $this->_mw_shl_codebox_script('post');
} else {
return '';
}
}
}
?>
我在其中的sh_lang_3和brush_files中新添了IL的项,注意刷子名称要小写,此插件不支持大写刷子名称,原因暂时没有深究。
另外,刚才的那些着色CSS样式来源于主题文件shThemeRDark.css(位于/syntaxhighlighter3/styles下)
内容如下:
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: #1b2426 !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #1b2426 !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #1b2426 !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #323e41 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: #b9bdb6 !important;
}
.syntaxhighlighter table caption {
color: #b9bdb6 !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #435a5f !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #435a5f !important;
color: #1b2426 !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #5ba1cf !important;
background: black !important;
border: 1px solid #435a5f !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #5ba1cf !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #5ce638 !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #435a5f !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #e0e8ff !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #b9bdb6 !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #878a85 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #5ce638 !important;
}
.syntaxhighlighter .keyword {
color: #5ba1cf !important;
}
.syntaxhighlighter .preprocessor {
color: #435a5f !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #ffaa3e !important;
}
.syntaxhighlighter .constants {
color: #e0e8ff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #5ba1cf !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #e0e8ff !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: white !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #ffaa3e !important;
}
这样修改完后,还需要修改discuz数据库:
我们在discuz数据库中找到表"pre_common_pluginvar"(其中pre_为discuz论坛安装时的表前缀)
会发现这么一项:
我们修改description字段为:
选择支持的语言,按住Ctrl键可多选
注意:AppleScript、Sass、Scss、IL四种语言仅在3.x高亮版本库中支持
修改value字段为:
a:41:{i:0;s:11:"applescript";i:1;s:13:"actionscript3";i:2;s:4:"bash";i:3;s:10:"coldfusion";i:4;s:1:"c";i:5;s:3:"cpp";i:6;s:6:"csharp";i:7;s:3:"css";i:8;s:6:"delphi";i:9;s:4:"diff";i:10;s:6:"erlang";i:11;s:6:"groovy";i:12;s:4:"html";i:13;s:4:"java";i:14;s:6:"javafx";i:15;s:10:"javascript";i:16;s:6:"pascal";i:17;s:5:"patch";i:18;s:4:"perl";i:19;s:3:"php";i:20;s:4:"text";i:21;s:10:"powershell";i:22;s:6:"python";i:23;s:4:"ruby";i:24;s:5:"rails";i:25;s:4:"sass";i:26;s:5:"scala";i:27;s:4:"scss";i:28;s:5:"shell";i:29;s:3:"sql";i:30;s:2:"vb";i:31;s:5:"vbnet";i:32;s:5:"xhtml";i:33;s:3:"xml";i:34;s:4:"xslt";i:35;s:4:"objc";i:36;s:3:"asm";i:37;s:5:"aauto";i:38;s:6:"golang";i:39;s:3:"lua";i:40;s:2:"il";}
修改extra字段为:
applescript = AppleScript
actionscript3 = Actionscript3
bash = Bash shell
coldfusion = ColdFusion
c = C
cpp = C++
csharp = C#
css = CSS
delphi = Delphi
diff = Diff
erlang = Erlang
groovy = Groovy
html = HTML
java = Java
javafx = JavaFX
javascript = JavaScript
pascal = Pascal
patch = Patch
perl = Perl
php = PHP
text = Plain Text
powershell = PowerShell
python = Python
ruby = Ruby
rails = Ruby on Rails
sass = Sass
scala = Scala
scss = Scss
shell = Shell
sql = SQL
vb = Visual Basic
vbnet = Visual Basic .NET
xhtml = XHTML
xml = XML
xslt = XSLT
objc = Objective-C
asm = Asm
aauto = AAuto
golang = Golang
lua = Lua
il = IL
然后保存即可,我们进入discuz后台,进入插件配置,这么修改:
然后提交修改后,刷新网站缓存即可。 思路很赞!补充一点数据库其实不用手动修改,把 xml 里的版本号改大,覆盖原插件文件后在dz后台选择“升级”即可。 沙发,嘿嘿嘿 板凳,嘿嘿嘿 板凳,嘿嘿嘿
还是没也挺看懂。 Coxxs 发表于 2018-10-27 13:37
思路很赞!补充一点数据库其实不用手动修改,把 xml 里的版本号改大,覆盖原插件文件后在dz后台选择“升级 ...
感谢!!!!!! 大神你好,我好像有一个C++的软件,韩国的加密,不知您能否破解? @lizhirui 请问我上一个帖子被认为广告贴https://www.52pojie.cn/thread-821318-1-1.html
是因为我发帖的内容,还是帖子附件里进游戏的封面带QQ什么的? 能指明一下吗?很多人等着我再发一波呢,我都不敢搞了。
页:
[1]