Categories: PHP

[PHP] XOOPS 加入外部檔案驗證

XOOPS 寫模組有個問題….

假設模組需要用到 Jquery檔案,要載入

一般寫在 HEADER 下面就行了

$xoopsTpl->assign("xoops_module_header", '');

但是,XOOPS也是有佈景檔的,當佈景檔已經載入 JQUERY.JS 這時候就會發生小小衝突

寫了一個 函式,由PHP 判斷 ‘jquery/jquery.js’ 這隻程式是否被載入

下列 程式 寫入 模組公用函式 function.php 裡面 ,並在一開始先載入

function tpl_file_include($tpl_include){
if(!isset($xoopsTpl)){ $xoopsTpl = new XoopsTpl(); }
$xoopsTheme = $xoopsTpl->fetch($GLOBALS['xoTheme']->path . '/' . $GLOBALS['xoTheme']->canvasTemplate);
foreach($tpl_include as $type => $file_array){
foreach($file_array as $file){
if(strpos($xoopsTheme, $file) === FALSE){
switch($type){
case 'js':
$GLOBALS['xoTheme']->addScript(XOOPS_URL.'/browse.php?Frameworks/' . $file);
break;
case 'css':
$GLOBALS['xoTheme']->addStylesheet( XOOPS_URL.$file );
break;
case 'javascript':
$GLOBALS['xoTheme']->addScript(null,null,$file);
break;
}
}
}
}
}

在 HEADER 之前 先寫入 變數

$tpl_include['js'] = array('jquery/jquery.js','jquery/plugins/jquery-ui.js');

必須使用陣列 可以多檔案

在header 之後  直接引入 tpl_file_include($tpl_include);

前台後台 皆可以這樣用…

來個簡易範例(後台):

include 'header.php';
include '../include/function.php';
include_once XOOPS_ROOT_PATH . '/include/cp_header.php';
include_once XOOPS_ROOT_PATH . '/include/cp_functions.php';
$tpl_include['js'] = array('jquery/jquery.js','jquery/plugins/jquery-ui.js');
xoops_cp_header();
tpl_file_include($tpl_include);
xoops_cp_footer();

前台:

include_once '../../mainfile.php';
include_once 'include/function.php';
$tpl_include['js'] = array('jquery/jquery.js','jquery/plugins/jquery-ui.js');
include_once XOOPS_ROOT_PATH.'/header.php';
tpl_file_include($tpl_include);
include_once XOOPS_ROOT_PATH.'/footer.php';
Mesak

我是米薩克,想了解更多可以點選  關於我 

Disqus Comments Loading...
Share
Published by
Mesak
Tags: xoops

Recent Posts

[教學] 利用 n8n 建立 LINE 聊天機器人

n8n 有多厲害,這邊就不贅述...

3 週 ago

[開箱] IROCKS K103R 熱插拔無線機械式鍵盤

許久沒有開箱了,近年鍵盤的規格...

3 個月 ago

[開箱] IROCKS-K85R 無線機械鍵盤

最近一直想要組一把 無線的 9...

1 年 ago

[開箱] IROCKS K75M 銀色上蓋機械式鍵盤

IROCKS K75M 這款鍵...

2 年 ago

[開箱] IROCKS M31E 粉紅色光學遊戲滑鼠

喜歡粉紅色周邊產品的朋友,有一...

2 年 ago