Add wiki syntax for discuz Forum

Source: Internet
Author: User
Tags mediawiki

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:

    1. Enable the Forum to support syntax such as [wiki] keyword [/wiki.
    2. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.