The goal is to resolve the specific syntax in the Forum to the actual URL of the Wiki, suchHttp://wiki.cwowaddon.com/Keywords
The following two types of Forum syntaxes must be supported:
- Enable the Forum to support syntax such as [wiki] keyword [/wiki.
- Make the Forum support the Wiki-specific reference syntax. For example, if moinmoin wiki is a ["keyword"] And mediawiki is a [[keyword].
The principle is to use a syntax scanner to scan the post content during page parsing and implement specific text replacement for the special syntax.
Implementation:
Viewthread. php file
Responsible for displaying postsProgramIs the viewthread. php file, open and locate more than 330 lines, you can see the followingCodeHere is where the syntax of the post content is replaced. We can add our own syntax parser below.
$ Post [ ' Message ' ] = Discuzcode ( $ Post [ ' Message ' ] , $ Post [ ' Smileyoff ' ] , $ Post [ ' Bbcodeoff ' ] , $ Post [ ' Htmlon ' ] , $ Forum [ ' Allowsmilies ' ] , $ Forum [ ' Allowbbcode ' ] , ( $ Forum [ ' Allowimgcode ' ] && $ Showimages ? 1 : 0 ) , $ Forum [ ' Allowhtml ' ] , ( $ Forum [ ' Jammer ' ] && $ Post [ ' Authorid ' ] ! = $ Discuz_uid ? 1 : 0 ) , 0 , $ Post [ ' Authorid ' ]);
This is the newly added wiki Syntax Parsing function that I added. For ease of management, it is stored independently in the Addons/dz_moinwiki.php file. Of course, the name can be determined by you.
$ Post['Message']=Moinwiki_parse ($ Post['Message']);
Do not forget to add a file reference to the start part of the file:
Include_once(Discuz_root.'./Addons/dz_moinwiki.php');
Dz_moinwiki.php File
The parsing code cyclically matches the format specified by the regular expression and replaces it with HTML. If you need the mediawiki syntax, replace the second regular expression '#\[\[(. + ?) \] # S' note that the second syntax can only be used in forums that support HTML. The first syntax is not limited.
<? PHP Function Moinwiki_parse ( $ Message ){ While ( Preg_match ( ' # \ [Wiki \] (. + ?) \ [/Wiki \] # s ' , $ Message , $ Match )){ $ Wiki_name = $ Match [ 1 ]; $ Wiki_html = ' <B> <a href = "http://wiki.cwowaddon.com/ ' . $ Wiki_name . ' "Target =" _ blank "> ' . $ Wiki_name . ' </A> </B> ' ; $ Message = Str_replace ( $ Match [ 0 ] , $ Wiki_html , $ Message );} While ( Preg_match ( ' # \ [\ "(. + ?) \ "\] # S ' , $ Message , $ Match )){ $ Wiki_name = $ Match [ 1 ]; $ Wiki_html = ' <B> <a href = "http://wiki.cwowaddon.com/ ' . $ Wiki_name . ' "Target =" _ blank "> ' . $ Wiki_name . ' </A> </B> ' ; $ Message = Str_replace ( $ Match [ 0 ] , $ Wiki_html , $ Message );} Return $ Message ;} ?>
Through this simple example, we can also see that the core wiki syntax can be supported by only a small extension of the existing html wysiwyg technology, and the layout is convenient, if wiki can also use the syntax technology such as forum, the writing threshold will be greatly reduced.