path
node
menuroute
無障礙
1.改寫Render 模組 (非常費時費力)
2.改寫最後結果 (使用版型)
中文化
http://drupaltaiwan.org/localized
http://drupaltaiwan.org/forum/20110728/5398
1.把下列程式碼 加入 template.php 讓輸出結果 符合無障礙
drupal\themes\bartik\template.php
------------------
$tab_index = 1;
function 版型名稱_for_taiwan($content) {
global $tab_index;$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'.$content);
$images = $dom->getElementsByTagName('img');
$links = $dom->getElementsByTagName('a');
$objs = $dom->getElementsByTagName('object');
$applets = $dom->getElementsByTagName('applet');
$img_maps = $dom->getElementsByTagName('area');
$ems = $dom->getElementsByTagName('i');
$strongs = $dom->getElementsByTagName('b');
$tables = $dom->getElementsByTagName('table');
$table_headers = $dom->getElementsByTagName('th');
foreach ($images as $img) {
$myalt=$img->getAttribute('alt');
if (!$myalt) $img->setAttribute('alt','排版用裝飾圖片');}foreach ($links as $lnk)
{
$mytitle=$lnk->getAttribute('title');
if (!$mytitle) $lnk->setAttribute('title', $lnk->nodeValue);
$lnk->setAttribute('tabindex', $tab_index);
$tab_index++;
}
foreach ($links as $lnk) {
$mytitle=$lnk->getAttribute('title');
if (!$mytitle) $lnk->setAttribute('title', $lnk->nodeValue);
$lnk->setAttribute('tabindex', $tab_index);
$tab_index++;
}
foreach ($objs as $obj) {
$myalt=$obj->nodeValue;
if (!$myalt) $obj->nodeValue=$obj->getAttribute('data');
}
foreach ($applets as $app) {
$myalt=$app->nodeValue;
if (!$myalt) {
$app->setAttribute('alt', '多媒體互動物件');
$app->nodeValue='多媒體互動物件';
}
else {
$app->setAttribute('alt', $myalt);
}
}
foreach ($img_maps as $area) {
$myalt=$area->getAttribute('alt');
if (!$myalt) $area->setAttribute('alt',$area->getAttribute('href'));
}
foreach ($ems as $em) {
$newem=$dom->createElement('em',$em->nodeValue);
$em->parentNode->replaceChild($newem, $em);
}
foreach ($strongs as $strong) {
$newstrong=$dom->createElement('strong',$strong->nodeValue);
$strong->parentNode->replaceChild($newstrong, $strong);
}
foreach ($tables as $table) {
$mytitle=$table->getAttribute('title');
$mysummary=$table->getAttribute('summary');
$caption=FALSE;
if ($table->hasChildNodes()) {
if ($table->firstChild->nodeName=='caption') $caption=$table->firstChild->nodeValue;
}
if (!$mytitle && $caption) $table->setAttribute('title',$caption);
if (!$mysummary && $caption) $table->setAttribute('summary',$caption);
if (!$mytitle && !$mysummary && !$caption) $table->setAttribute('summary','排版用表格');
}
foreach ($table_headers as $myth) {
$myscope=$myth->getAttribute('scope');
$myheaders=$myth->getAttribute('headers');
if (!$myscope && !$myheaders) $myth->setAttribute('scope','col');
}
$content = $dom->saveHTML();
$content = preg_replace('/<!DOCTYPE .+>/', '', preg_replace('/<meta .+?>/', '', str_replace( array('<html>', '</html>', '<head>', '</head>', '<body>', '</body>'), array('', '', '', '', '', ''), $content)));
return $content;
}
------------------
2.在相同檔案中 將版型名稱_process_html加入下列程式碼
function 版型名稱_process_html(&$vars) {
$vars['page_top'] = 版型名稱_for_taiwan($vars['page_top']);
$vars['page_bottom'] = 版型名稱_for_taiwan($vars['page_bottom']);
$vars['page'] = 版型名稱_for_taiwan($vars['page']);
}