OverRideハック
提供: GeeklogJpWiki
- 開発 kino
以下1,2,3の手順でハックします。
目次 |
system/classese/template.class.phpを修正する
※このファイルのハックは,日本語版標準パッケージ2007.7.30版から対策済みのものが配布されています。
非公開領域のsystem/classese/にある template.class.php を下記のように変更します。
クラス内変数にベースとなるテーマの名称を保持する変数を追加
修正前
var $root = ".";
修正後
var $root = "."; var $base = ".";
クラス初期化時に $base が設定されるように変更
修正前
function Template($root = ".", $unknowns = "remove") {
if ($this->debug & 4) {
echo "<p><b>Template:</b> root = $root, unknowns = $unknowns</p>\n";
}
$this->set_root($root);
$this->set_unknowns($unknowns);
}
修正後
function Template($root = ".", $unknowns = "remove") {
global $_BASE_TEMPLATE;
$this->set_base($_BASE_TEMPLATE);
if ($this->debug & 4) {
echo "<p><b>Template:</b> root = $root, unknowns = $unknowns</p>\n";
}
$this->set_root($root);
$this->set_unknowns($unknowns);
}
function set_base($base) {
global $_CONF;
if ($this->debug & 4) {
echo "<p><b>set_base:</b> base = $base</p>\n";
}
if (substr ($base, -1) == '/') {
$base = substr ($base, 0, -1);
}
if (!is_dir($_CONF['path_themes'] . $base)){
return false;
}
$this->base = $_CONF['path_themes'] . $base;
return true;
}
root設定時に設定すべきディレクトリが存在しない場合は $base に設定されているテンプレートの該当ディレクトリが設定されるよう変更
修正前
function set_root($root) {
global $_CONF;
if ($this->debug & 4) {
echo "<p><b>set_root:</b> root = $root</p>\n";
}
if (substr ($root, -1) == '/') {
$root = substr ($root, 0, -1);
}
if (!is_dir($root)) {
$this->halt("set_root: $root is not a directory.");
return false;
}
$this->root = $root;
return true;
}
修正後
function set_root($root) {
global $_CONF;
if ($this->debug & 4) {
echo "<p><b>set_root:</b> root = $root</p>\n";
}
if (substr ($root, -1) == '/') {
$root = substr ($root, 0, -1);
}
if (!is_dir($root)) {
$root = str_replace($_CONF['path_layout'],$this->base .'/',$root);
if (!is_dir($root)) {
$this->halt("set_root: $root is not a directory.");
return false;
}
}
$this->root = $root;
return true;
}
ファイル名取得時に $root で指定されているディレクトリ下にファイルが存在しない場合 $base配下のディレクトリのファイル名を返すように変更
修正前
function filename($filename) {
if ($this->debug & 4) {
echo "<p><b>filename:</b> filename = $filename</p>\n";
}
if (substr($filename, 0, 1) != "/") {
$filename = $this->root."/".$filename;
}
if (!file_exists($filename)) {
$this->halt("filename: file $filename does not exist.");
}
return $filename;
}
修正後
function filename($filename) {
if ($this->debug & 4) {
echo "<p><b>filename:</b> filename = $filename</p>\n";
}
if (substr($filename, 0, 1) != "/"){
if (file_exists($this->root."/".$filename)) {
$filename = $this->root."/".$filename;
} else {
if (file_exists($this->base."/".$filename)) {
$filename = $this->base."/".$filename;
}
}
}
if ($this->debug & 4) {
echo "<p><b>real filename:</b> filename = $filename</p>\n";
}
// if (substr($filename, 0, 1) != "/") {
// $filename = $this->root."/".$filename;
// }
// if (!file_exists($filename)) {
// $this->halt("filename: file $filename does not exist.");
// }
return $filename;
}