私はあなたがJoomla1.0を使用していると仮定していますか?
JoomlaはPHP出力バッファを使用してコンテンツをバッファします。すなわち:ob_start()。
次のようにしてコンテンツを取得できます。ob_get_contents();
したがって、JQueryをチェックする正規表現を使用できます。次のようなものがあります。
$jquery_loaded = preg_match("/<script.*?src=[\"']jquery[^\"']\"/i", ob_get_contents());
は十分です。 (私はそれをテストしていない)。
PHP出力バッファをネストすることができるため、ob_get_contents()を使用すると状況に応じて動作しないことがあります。バッファー内でいくつでもバッファーを開始することができます。
Joomla1.5の場合は、常にJoomlaの出力を取得するAPIを介してバッファを取得できます。
$Document =& JFactory::getDocument();
$buffer = $Document->getBuffer();
かどうかJoomla1.0または1.5あなたはそれが出力をレンダリングする前に、Joomlaのは、任意の時点でバッファに追加できることに注意しなければならない((ob_flush呼び出す)または同等のもの)。したがって、JQueryのチェックでは、チェックの後にJQueryをロードできることを考慮する必要があります。
Joomlaのバッファは、HTMLだけでなく、CSS、JavaScript、XML、JSONなどでも作成できることに注意してください.JQueryのテストを行う前に、HTMLをチェックしたいと思うかもしれません。また、管理パネルをテストすることもできます。ここでは参考のため
$mainframe =& JFactory::getApplication();
$doctype = $document->getType();
// deactivate for backend
if ($mainframe->isAdmin() || $doctype != 'html') {
return false;
}
の一部は、あなたが欲しいものを行う例のシステムプラグインです。これはMooTools1.2の互換性プラグインです。
<?php
/**
* MooTools1.2 w/ 1.1 compat for AjaxChat
* @copyright www.fijiwebdesign.com
* @author [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/
// included only
defined('_JEXEC') or die('Direct Access to this location is not allowed!');
jimport('joomla.plugin.plugin');
/**
* Joomla PHP Speedy Integration
*
* @author [email protected]
*/
class plgSystemAjaxchat extends JPlugin
{
/**
* Constructor
*
* For php4 compatability we must not use the __constructor as a constructor for plugins
* because func_get_args (void) returns a copy of all passed arguments NOT references.
* This causes problems with cross-referencing necessary for the observer design pattern.
*
* @access protected
* @param object $subject The object to observe
* @param array $config An array that holds the plugin configuration
* @since 1.0
*/
function plgSystemAjaxchat(& $subject, $config)
{
parent::__construct($subject, $config);
$mainframe =& JFactory::getApplication();
$document =& JFactory::getDocument();
$doctype = $document->getType();
// deactivate for backend
if ($mainframe->isAdmin()) {
return false;
}
// add mootools 1.2
if ($doctype == 'html') {
$document->addScript('components/com_ajaxchat/js/mootools-1.2-core.js');
$document->addScript('components/com_ajaxchat/js/mootools-1.2-more.js');
$document->addScript('components/com_ajaxchat/js/mootools-1.2-core-compat.js');
$document->addScript('components/com_ajaxchat/js/mootools-1.2-more-compat.js');
}
}
/**
* After Templte output is in buffer
*/
function onAfterRender() {
$mainframe =& JFactory::getApplication();
$document =& JFactory::getDocument();
$doctype = $document->getType();
// deactivate for backend
if ($mainframe->isAdmin()) {
return false;
}
// Only render for HTML output
if ($doctype !== 'html') {
return;
}
// get the output buffer
$body = JResponse::getBody();
// remove mootools if not needed
if (stristr($body, 'mootools.js') || stristr($body, 'mootools-uncompressed.js')) {
$body = preg_replace("/<script.*?mootools(-uncompressed)?\.js.*?<\/script>/i", '', $body);
} else {
$body = preg_replace("/<script.*?mootools-1\.2\-.*?\.js.*?<\/script>[\s\t\r\n]*/i", "\n", $body);
}
JResponse::setBody($body);
}
}
?>
この質問は、「JoomlaでヘッダーにjQueryが含まれているかどうかを確認する」と言い換えることができます。 – deceze