Joomla プラグインを作成しようとするのはこれが初めてで、これを機能させるには助けが必要です。プラグインは非常にシンプルです。HTTP_REFERER をキャプチャし、リクエストが Google のオーガニックまたは有料の結果から行われたかどうかを確認し、データをセッション var に渡し、値と一緒に連絡先フォームに送信します。(私のフォームには隠しフィールドがあり、セッション var 値を取得します)。参考までに、RSForms を使用してフォームを作成しています。
最初に、次のコードをサイト ルートの index.php にハードコーディングしたところ、問題なく動作しました。現在、適切なプラグインを作成しようとしていますが、ページがロードされたときにプラグインを起動できません。すべてのシステム メソッドを試しましたが、まだ実行できません。
これは私のコードです:
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgSystemRsformsGoogleReferer extends JPlugin
{
public function plgSystemRsformsGoogleReferer( &$subject, $config )
{
parent::__construct( $subject, $config );
}
function onAfterRender()
{
$session = & JFactory::getSession();
if (!$session->get('referrer', $origref, 'extref')) //If does not exist
{
$origref = $_SERVER['HTTP_REFERER'];
$session->set('referrer', $origref, 'extref');
$q = search_engine_query_string($session->get('referrer', $origref, 'extref'));
if(stristr($origref, 'aclk')) { // if referer is a google adwords link as opposed to an organic link
$type = ', paid link';
} else {
$type = ', organic result';
}
$ginfo = $q.$type;
$session->set('referrer', $ginfo, 'extref');
}
function search_engine_query_string($url = false) {
if(!$url && !$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false) {
return '';
}
$parts_url = parse_url($url);
$query = isset($parts_url['query']) ? $parts_url['query'] : (isset($parts_url['fragment']) ? $parts_url['fragment'] : '');
if(!$query) {
return '';
}
parse_str($query, $parts_query);
return isset($parts_query['q']) ? $parts_query['q'] : (isset($parts_query['p']) ? $parts_query['p'] : '');
}
}
}
そして、これはプラグインのインストール用の私のマニフェスト xml です (インストールは正常に動作します):
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="system" method="upgrade">
<name>RSForm Google Referer v1.1</name>
<author>Me</author>
<creationDate>July 2012</creationDate>
<copyright>(C) 2004-2012 www.mysite.com</copyright>
<license>Commercial</license>
<authorEmail>info@mysite.com</authorEmail>
<authorUrl>www.mysite.com</authorUrl>
<version>1.1</version>
<description><![CDATA[Track visitor's search terms and and attaches the information to the RSForm! Pro Forms emails when sent.]]></description>
<files>
<filename plugin="rsform_google_referer">rsform_google_referer.php</filename>
</files>
</install>
私は近いと感じていますが、それを実行することはできません。ありがとう!