dokuwiki 的 ajax 樹狀選單+中文修復

indemenu2

indexMenu2indexMenu 的 Ajax 版本,它所採用的核心是 RemoteScript,所以必須也要安裝 RemoteScript 才能運作。

indexMenu2 的語法大致上是這樣子的

{{indexmenu>namespace[#[n][+nons]] [|js[#[theme][+ajax]]]}}

被 [] 包圍的是非必要選項,視偏好使用。
namespace
參數值:任何已存在的 NameSpace
從哪個 NameSpace 開始列出內容,如果要指定根目錄的話
可以填成  :  

#
參數值:#
總共有兩個 #
第一個 # 的使用時機是當它後面的 n 或 +nons 有設定時,就要填上去。
第二個 # 則是 theme 或 +ajax 有設定時再填。

n
參數值:數字
一開始顯示的層級

+nons
參數值:就是 +nons,不變
如果這個選項有填入語法裡的話,indexMenu2不會列出 NameSpace,只列出頁面。

|js
參數值:|js
使用 JavaScript 效果。
theme 跟 +ajax 有填寫的話,|js 也不能少。

theme
參數值:default、Simple、IndexMenu、或自訂的佈景
選擇佈景。
default:dokuwiki 預設的列表樣式
Simple:+ 跟 - 的小圖片
IndexMenu:IndexMenu 裡的資料夾圖示。
佈景可以自己製造 → 官方說明

+ajax
參數值:+ajax
開啟 ajax 動態載入,ajax啟用時,一開始的樹狀選單,只會列出剛剛設定的層級,再更下面的子項目不會載入,只有點下開合按鈕後才開始跟伺服器請求資料。

中文修復

剛安裝完成時,獲取英文 NameSpace 內容運作良好,還挺滿意這個效果的。但中文 NameSpace 竟是……:骷髏:ServerError!!

還好在 FireBug 的幫助下,終於找到問題就出在送出的 NameSpace 查詢未經過編碼,所以伺服器端接收到的東西都是亂碼,自然找不到資料可以回傳。

lib/plugins/indexmenu/syntax.php
送出查詢前先編碼

php · [高亮] · [原始]

  1. # FIND
  2. req.send ({’src’ : s});
  3. # Replace With
  4. req.send ({’src’ : encodeURIComponent(s)});
# FIND
req.send ({\'src\' : s});
# Replace With
req.send ({\'src\' : encodeURIComponent(s)});

lib/plugins/indexmenu/indexmenu.php
伺服器端還原編碼

php · [高亮] · [原始]

  1. # FIND
  2. global $conf;
  3. # Add To Next Line
  4. $ns = str_replace(‘%3A’, ‘:’, $ns);
  5.  
  6. # FIND
  7. $data = array2tree($data,$ns);
  8. # Replace With
  9. $data = array2tree($data,urldecode($ns));
# FIND
global $conf;
# Add To Next Line
$ns = str_replace(\'%3A\', \':\', $ns); 

# FIND
$data = array2tree($data,$ns);
# Replace With
$data = array2tree($data,urldecode($ns));

 
 
另外,不曉得是不是因為我把 dokuwiki 放在伺服器子目錄的關係,動態載入的連結並不會加上 dokuwiki 路徑,直接就 http://localhost/namespace/page ,找了半天也不曉得問題出在哪個 php 檔裡,只好強行把路徑附加上去。
 
lib/plugins/indexmenu/indexmenu.php
我的資料夾叫 dokuwiki,存放在根目錄裡

php · [高亮] · [原始]

  1. # FIND
  2. $data[$k][‘open’] = false;
  3. # Add To Next Line
  4. $data[$k][‘path’] = ‘dokuwiki’;
# FIND
$data[$k][\'open\'] = false;
# Add To Next Line
$data[$k][\'path\'] = \'dokuwiki\';

lib/plugins/indexmenu/syntax.php

php · [高亮] · [原始]

  1. # FIND
  2. $ret .= ‘<a href="’.wl(preg_replace("/^:+/","",$item[‘id’]),$qry).‘">’;
  3. # Replace With
  4. $ret .= ‘<a href="’.wl((isset($item[‘path’])?$item[‘path’].‘/’:).preg_replace("/^:+/","",$item[‘id’]),$qry).‘">’;
  5.  
  6. # FIND
  7. $ret .= html_wikilink(":".$item[‘id’]);
  8. # Replace With
  9. $ret .= html_wikilink($item[‘path’].":".$item[‘id’]);
# FIND
$ret .= \'<a href="\'.wl(preg_replace("/^:+/","",$item[\'id\']),$qry).\'">\';
# Replace With
$ret .= \'<a href="\'.wl((isset($item[\'path\'])?$item[\'path\'].\'/\':\'\').preg_replace("/^:+/","",$item[\'id\']),$qry).\'">\';

# FIND
$ret .= html_wikilink(":".$item[\'id\']);
# Replace With
$ret .= html_wikilink($item[\'path\'].":".$item[\'id\']);



One Response to “dokuwiki 的 ajax 樹狀選單+中文修復”

  1. 懶懶喵日記 Says:

    dokuwiki 我安裝的 Plugins…

    » ActionLink
    可以在wiki內容中使用actions的連結。
    但我發現這些action連結放在佈景主題上會比較適當,所以已經沒有使用了。
    » AddNewPage
    在dokuwiki上放置一個新增頁面的區域
    並且頁面名稱輸入欄….

Leave a Comment