ログイン: パスワード:   新規登録  パスワード紛失
 
メインメニュー
検索
オンライン状況
登録ユーザ: 0
ゲスト: 19
テーマ選択

(4 テーマ)
Top / XOOPS / tinyD / サブメニューをファイル名にする

tinyD/サブメニューをファイル名にする

tinyDで静的コンテンツを WRAP3でページラップをして、modules/のない rewriteモードにしてもサブメニューのリンク先が tc_??.html になってしまってかっこ悪い(?)ので ファイル名でページラップできるように改造してみた。

但し、この改造を行ってWRAP3以外のモードでもうまく動くかどうかは検証していないのでご注意を。

以下に修正個所を書く。(改行位置は一部変更している)

xoops_version.phpの修正

xoops_version.php (もちろん tinyDのやつね) を修正してサブメニューがファイル名でリンクされるようにする。 79行目付近から次の修正を行う。

// Submenu Items
// 次の行で select文に address を追加
$result = $db->query("SELECT storyid,title,link,address 
                      FROM ".$db->prefix( "tinycontent{$mydirnumber}" )." 
                      WHERE submenu='1' AND visible ORDER BY blockid" ) ;
$i = 1 ;
// 次の行で $address を追加
while( list( $storyid , $title , $link, $address ) = $db->fetchRow( $result ) )
{
  $modversion['sub'][$i]['name'] = $myts->makeTboxData4Show( $title ) ;
	
  if( ! empty( $config['tc_force_mod_rewrite'] ) || $link == TC_WRAPTYPE_USEREWRITE ) {
    if( empty( $config['tc_modulesless_dir'] ) ) { 
      $wraproot = TC_REWRITE_DIR ;
      //次の行はコメントアウト(改行位置を変えてます)
      //$modversion['sub'][$i]['url'] = 
         TC_REWRITE_DIR . sprintf( TC_REWRITE_FILENAME_FMT , $storyid ) ;
      //次の行を追加
      $modversion['sub'][$i]['url'] = TC_REWRITE_DIR . $address;
    } else {
      $wraproot = '' ;
      //次の行はコメントアウト(改行位置を変えてます)
      //$modversion['sub'][$i]['url'] = 
           '../../'.$config['tc_modulesless_dir'].'/'
           .sprintf( TC_REWRITE_FILENAME_FMT , $storyid ) ;
      //次の行を追加(改行位置を変えてます)
      $modversion['sub'][$i]['url'] = 
            '../../'.$config['tc_modulesless_dir'].'/'. $address;
    }
  } else {
    $wraproot = $link == TC_WRAPTYPE_CONTENTBASE ? "content/" : '' ;
    $modversion['sub'][$i]['url'] = "{$wraproot}index.php?id=$storyid" ;
  }
  $i++ ;
}

この修正だけでも、rewriteモードの設定が正しくされていれば、ページが表示されるはずだが、このままでは 常に rewrite.php でページが表示されるのでパフォーマンスが悪い。(多分)

そこで、index.phpと.htaccessも修正することにする。

index.phpの修正

index.phpを修正してファイル名でのページラップを受付けるようにする。 65行目付近から次を追加。

list( $homepage_id , $homepage_link_type ) = $xoopsDB->fetchRow( $result ) ;

//---- ここから追加
if (!empty( $_GET['name'] )) {
  $result = $xoopsDB->query("SELECT storyid,title,text,visible,
                                    nohtml,nosmiley,nobreaks,nocomments,link,
                                    address,
                                    UNIX_TIMESTAMP(last_modified) AS last_modified,
                                    html_header
                             FROM $mytablename 
                             WHERE address='$name' AND visible" ) ;
  if ( ($result_array = $xoopsDB->fetchArray($result)) == false ) {
    redirect_header(XOOPS_URL, 2, _TC_FILENOTFOUND );
    exit;
  }
  $id = $result_array['storyid'];
  $_REQUEST['id'] = $_GET['id'] = $id;
} else {
//---- ここまで追加
  // check if $_GET['id'] is specified
  $id = empty( $_GET['id'] ) ? 0 : intval( $_GET['id'] ) ;
  if( $id <= 0 )  {
    $_REQUEST['id'] = $_GET['id'] = $id = $homepage_id ;
  }

  // main query
  $result = $xoopsDB->query( "SELECT storyid,title,text,visible,
                                     nohtml,nosmiley,nobreaks,nocomments,link,
                                     address,
                                     UNIX_TIMESTAMP(last_modified) AS last_modified,
                                     html_header
                              FROM $mytablename 
                              WHERE storyid='$id' AND visible" ) ;
  if( ( $result_array = $xoopsDB->fetchArray( $result ) ) == false ) {
    redirect_header( XOOPS_URL , 2 , _TC_FILENOTFOUND ) ;
    exit ;
  }
}  //この行も追加

// redirect if its base of wrapping is wrap_path (content)

.htaccessの修正

xoopsルートディレクトリ(modules/ なしの rewriteモードの時)、もしくは、tinyDディレクトリ(moudles/ ありの rewriteモードの時) の .htaccess を修正して、ファイル名でも index.php で表示されるようにする。

次の例は modules/ なしの rewriteモードの場合の例。

RewriteEngine on

RewriteRule ^toto/$                       /modules/toto1/index.php [L]
RewriteRule ^toto$                        /modules/toto1/index.php [L]
RewriteRule ^toto/tc_(.*)\.html$          /modules/toto1/index.php?id=$1 [L]
RewriteRule ^toto/(.*\.html?)$            /modules/toto1/index.php?name=$1 [L]
#RewriteRule ^toto/(.*\.html?)$            /modules/toto1/rewrite.php?wrap=$1 [L]
RewriteRule ^toto/index.php(.*)$          /modules/toto1/index.php$1 [L]
RewriteRule ^toto/comment_new.php(.*)$    /modules/toto1/comment_new.php$1 [L]
RewriteRule ^toto/comment_post.php(.*)$   /modules/toto1/comment_post.php$1 [L]
RewriteRule ^toto/comment_reply.php(.*)$  /modules/toto1/comment_reply.php$1  [L]
RewriteRule ^toto/comment_edit.php(.*)$   /modules/toto1/comment_edit.php$1 [L]
RewriteRule ^toto/comment_delete.php(.*)$ /modules/toto1/comment_delete.php$1 [L]
RewriteRule ^toto/(.*)$                   /modules/toto1/content/$1 [L]
  • totoディレクトリは tinyDの一般設定で指定したディレクトリ名
  • toto1は実際のtinyDのディレクトリ名
  • index.php?name=$1 が新たに追加したルール

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Counter: 5058, today: 1, yesterday: 0
Last-modified: Sun, 05 Feb 2006 16:19:48 JST (6648d)
PR