LoginSignup
1
1

More than 5 years have passed since last update.

ドメイン名やXOOPS_URLの変更時に使う HTML一括置換preload

Posted at

ドメイン変更やXOOPSインストール先の階層変更等でXOOPS_URLを変更することがあります。

そんなときにDBに保存されてるコンテンツのURLもダンプデータを一括置換等するのですが、いろいろ事情があってダンプデータの置換ができないときにhtmlの置換preloadでしのいだことがあります。

仕組みとしてはSmartyのOutputフィルタプラグインを使ってるだけです。

XOOPS_ROOT_PATH/preload/htmlReplace.class.php

<?php
if (!defined('XOOPS_ROOT_PATH')) exit();

class htmlReplace extends XCube_ActionFilter
{
    function preFilter()
    {
        $this->mRoot->mDelegateManager->add('XoopsTpl.New', array( &$this , 'xoopsTplHook' ) ) ;
    }

    function xoopsTplHook( &$xoopsTpl )
    {
        $xoopsTpl->register_outputfilter("htmlReplaceFilter");
    }
}

function htmlReplaceFilter($tpl_output, &$smarty)
{
    // ここで置換
    $replaced = preg_replace('/http:\/\/old_domain\.com/', 'https://new_domain.com', $tpl_output);
    return $replaced;
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1