CMSimple Drupal Yii 內容管理系統三方案 - 提升台灣中小企業競爭力

目前位置:   首頁 > License > CMSimple Forum > 加入MimeTex

加入MimeTex

function rmnl($text){
//2006.12.08修改
global $action;
$text=preg_replace("/(rn|r|n)+/","n",$text);
//處理在內容編輯與存檔時的狀態
if($action=="edit"||$action=="save")
{
//假如編輯相關設定檔,不代換分隔符號
//這裡假設當$action為edit或save值時,就是在編輯相關設定檔案
}
else
{
//進入這裡表示針對一般內容儲存,經過代換,就可以有效處理分隔符號
$text=preg_replace("/()/","",$text);
//先前採用{[作為分隔符號時的代換處理
/*
$new_text1=preg_replace("/([)/","[",$text);
$new_text2=preg_replace("/(])/","]",$new_text1);
$new_text3=preg_replace("/({)/","{",$new_text2);
$new_text=preg_replace("/(})/","}",$new_text3);
*/
//開始處理MimeTex相關符號
  $text = str_replace("r"," ",$text);
  $text=str_replace("n"," " ,$text);
  $text = str_replace(" "," ",$text);
    preg_match_all ("|{[(.*)]}|U", $text, $mathmatch, PREG_PATTERN_ORDER);
     foreach($mathmatch[1] as $math_code) {
        //以下利用is_ascii函式判斷,數學式內容為ascii才進行處理
        if(is_ascii($math_code))
        {
        $math_replace= renderMath($math_code);
        $text=str_replace("{[".$math_code."]}", $math_replace, $text);
        }
    }
//第一階段的MimeTex處理,到此為止
}
return $text;
}
//is_ascii函式是用來判斷內容是否為ascii
function is_ascii($s) {
 if (preg_match('/[^x09x0ax0d -~]/', $s))
 {
     return false;
 }
 else
 {
     return true;
 }
}
//新增renderMath函式處理工程符號的處理
function renderMath($tex) {
$MimetexCmd="c:/app/mimetex.exe";
//請注意假如要使用在各種語系,以下的$ImgCacheDir路徑,要使用絕對路徑,若使用相對路徑,除主語系外,其他語系無法使用!
$ImgCacheDir="c:/htdocs/twcmsimple/pub/cache";
$PubDirUrl="http://localhost/twcmsimple/pub";
$ImgCacheUrl="$PubDirUrl/cache";
  $tex = trim($tex);
  $imgname = md5($tex).".gif"; 
  mkgiddir($ImgCacheDir);
  if (!file_exists("$ImgCacheDir/$imgname") &&  
      system("$MimetexCmd -d ".escapeshellarg($tex)." >$ImgCacheDir/$imgname")=== false)
    return "mimetex-failed: $tex";
  return "<img class='mimetex' src='$ImgCacheUrl/$imgname' alt='".str_replace("'","&#039;",$tex)."' />";
}
//以下也是處理工程符號所需的函式
function mkgiddir($dir) {
  global $ForceMkdir;
  $dir = preg_replace('!/$!','',$dir);
  if (is_dir($dir)) return;
  if (!$ForceMkdir) {
    $parent = dirname($dir);
    $rparent = realpath($parent);
    $perms = fileperms($parent);
    if (umask()!=0 && posix_getegid()!=filegroup($parent) &&
        ($perms & 02000)==0)
      Abort("twcmsimple wants setgid permissions enabled on <tt>$rparent</tt><br />
        before it creates the <tt>$dir</tt> directory.  <br />
        Try executing <pre>    chmod 2777 $rparent</pre>
        on your server and reloading this page.  Afterwards, you
        can restore the permissions<br />to their current setting by executing
        <pre>    chmod ".decoct($perms & 03777)." $rparent</pre>If this
        doesn't work for you, see the link below.","Setgid");
  }
  mkdir($dir,0777) or
    Abort("Cannot create <tt>$dir</tt><br />
      Current directory is <tt>".getcwd()."</tt>","Mkdir");
}
//以下這個rmanl(),用於oedit.php中,列出以下函式主要用來定位上列程式碼
function rmanl($t){return preg_replace("/(rn|r|n)+/","",$t);}

 



Powered by CMSimple_XH| Template: ge-webdesign.de| 登入