筍子工作雜記

7月 29, 2006

主選單生成分析

歸類於: xoops — shinnlu @ 8:08 pm

系統主選單是如何產生的呢,下面是分析步驟
由 index.php 引入 header.php 開始
/header.php

// Get blocks
  $block_handler =& xoops_gethandler('block');(註1)
  $block_handler->assignBlocks();

/kernel/block.php

  1. function assignBlocks() //取得區塊供樣板引擎使用
  2.   $bcontent = $xoopsTpl->fetch( "db:$btpl", "blk_$instanceid" );//取得區塊內容,經由 smarty 執行 system_blocks.php
  3.   $xoopsTpl->clear_assign('block');
  4.   $querycount = count( $xoopsLogger->queries[$xoopsLogger->context] ) - $querycountbefore;
  5.   $xoopsLogger->addBlock( $block_arr[$i]->block->getVar('name'), false, 0, $querycount );
  6. //$block_arr[$i]->block->getVar('name')  區塊名稱
資料庫參考資料 table:xoops_block_instance
instid bid options  title    side weight visible bctime
     1   1 a:0:{} 使用者選單    0      0       1      0
     2   2 a:0:{} 登入          0      0       1      0
     3   5 a:0:{} 主選單        0      0       1      0

/modules/system/blocks/system_blocks.php(註2)

  1. function b_system_main_show(){
  2.      $module_handler =& xoops_gethandler('module');<strong>(註1)</strong>//取得模組物件(xoops_config, xoops_session, privileges(user,group), modules, config, 選單區塊)
  3.      $modules =& $module_handler->getObjects($criteria, true);//取得該模組物件下的選單資料(在此只注意主選單區塊)
  4.     foreach (array_keys($modules) as $i) {
  5.         if (in_array($i, $read_allowed)) {
  6.             $block['modules'][$i]['name'] = $modules[$i]->getVar('name');//模組名稱
  7.             $block['modules'][$i]['name'] = $modules[$i]->getVar('name');
資料庫參考資料 table:xoops_block_module_link
block_id  module_id  pageid
       6          0       0
       6          2       0
       6          3       0
       6          4       0
       6          5       0
       6          6       0

補充說明
註1:呼叫 &xoops_gethandler 時,都會動態載入相對應的物件
/includes/functions.php

  1. function &xoops_gethandler($name, $optional = false )
  2.         if ( file_exists( $hnd_file = XOOPS_ROOT_PATH.'/kernel/'.$name.'.php' ) ) {//載入 {module}.php
  3.         if (class_exists($class)) {
  4.             $handlers[$name] =& new $class($GLOBALS['xoopsDB']);
  5.             $handlers[$name] =& new XoopsModuleHandler(object(xoopsmysqldatabaseproxy));
  6.         }

註2:為什麼上面追到一半,會跑去 b_system_main_show() 去呢?原因如下

  1. 資料庫參考資料 table:xoops_newblocks
  2. bid mid           options   name isactive dirname         func_file          show_func         edit_func template
  3.   5   1 a:1:{i:0;s:0:"";} 主選單        1  system system_blocks.php b_system_main_show system_block_mainmenu.html

尚無評論 »

尚無評論。

RSS feed 此篇文章的評論。 TrackBack URL

發表您的評論

Powered by WordPress