source: branches/comu-ver2/patches/GoogleAnalytics_plugin.patch @ 18226

Revision 18226, 21.0 KB checked in by nanasess, 15 years ago (diff)

ramrun さんのフィードバック

RevLine 
[18223]1Index: html/user_data/plugins/plugin_menu.tpl
2===================================================================
3--- html/user_data/plugins/plugin_menu.tpl  (リビジョン 0)
4+++ html/user_data/plugins/plugin_menu.tpl  (リビジョン 0)
[18225]5@@ -0,0 +1,33 @@
[18223]6+<ul id="navi-plugin-menu" class="level1">
7+</ul>
8+<script type="text/javascript">
[18225]9+//<![CDATA[
[18223]10+$(function(){
11+   $.ajax({
12+    url: '<!--{$smarty.const.PLUGIN_URL}-->plugins.xml',
13+    type: 'GET',
14+    dataType: 'xml',
15+    timeout: 2000,
16+    error: function(){
17+        alert("xmlファイルの読み込みに失敗しました");
18+    },
19+    success: function(xml){
20+        $(xml).find("plugin").each(function(){
21+            var item_text = $(this).find("name").text();
22+            var item_path = $(this).find("path").text();
23+
24+            $("<li id='navi-plugin-index'></li>")
[18225]25+               .html("<a href='javascript:;'><span>" + item_text + "</span></a>")
[18223]26+               .appendTo('ul#navi-plugin-menu')
27+               .click(function() {
28+                   win03('<!--{$smarty.const.PLUGIN_URL}-->' + item_path
29+                          + '/index.php', 'plugins', '800','600');
30+                   return false;
31+               });
32+        });
33+        $("li.plugin_menu").html("");
34+    }
35+    });
36+});
[18225]37+//]]>
[18223]38+</script>
39Index: html/user_data/plugins/plugins.xml
40===================================================================
41--- html/user_data/plugins/plugins.xml  (リビジョン 0)
42+++ html/user_data/plugins/plugins.xml  (リビジョン 0)
43@@ -0,0 +1,7 @@
44+<?xml version="1.0" encoding="utf-8"?>
45+<plugins>
46+  <plugin>
47+    <name>Google Analytics</name>
48+    <path>google_analytics</path>
49+  </plugin>
50+</plugins>
51Index: html/user_data/plugins/google_analytics/sql/delete.sql
52===================================================================
53--- html/user_data/plugins/google_analytics/sql/delete.sql  (リビジョン 0)
54+++ html/user_data/plugins/google_analytics/sql/delete.sql  (リビジョン 0)
55@@ -0,0 +1,2 @@
56+DELETE FROM dtb_bloc WHERE filename = 'google_analytics';
57+DELETE FROM dtb_blocposition WHERE filename = 'google_analytics';
58\ No newline at end of file
59Index: html/user_data/plugins/google_analytics/sql/insert.sql
60===================================================================
61--- html/user_data/plugins/google_analytics/sql/insert.sql  (リビジョン 0)
62+++ html/user_data/plugins/google_analytics/sql/insert.sql  (リビジョン 0)
[18226]63@@ -0,0 +1,1 @@
[18223]64+INSERT INTO dtb_bloc (bloc_name, tpl_path, filename, php_path, del_flg) VALUES ('Google Analytics', 'user_data/plugins/google_analytics/tpl/ga.tpl', 'google_analytics', 'user_data/plugins/google_analytics/ga.php', 1);
65\ No newline at end of file
66Index: html/user_data/plugins/google_analytics/tpl/ga.tpl
67===================================================================
68--- html/user_data/plugins/google_analytics/tpl/ga.tpl  (リビジョン 0)
69+++ html/user_data/plugins/google_analytics/tpl/ga.tpl  (リビジョン 0)
70@@ -0,0 +1,9 @@
71+<script type="text/javascript">
72+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
73+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
74+</script>
75+<script type="text/javascript">
76+try {
77+var pageTracker = _gat._getTracker("UA-<!--{$smarty.const.GA_UA}-->");
78+pageTracker._trackPageview();
79+} catch(err) {}</script>
80Index: html/user_data/plugins/google_analytics/tpl/index.tpl
81===================================================================
82--- html/user_data/plugins/google_analytics/tpl/index.tpl   (リビジョン 0)
83+++ html/user_data/plugins/google_analytics/tpl/index.tpl   (リビジョン 0)
84@@ -0,0 +1,52 @@
85+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
86+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
87+
88+<head>
89+<meta http-equiv="content-type" content="application/xhtml+xml; charset=<!--{$smarty.const.CHAR_CODE}-->" />
90+<meta http-equiv="content-script-type" content="text/javascript" />
91+<meta http-equiv="content-style-type" content="text/css" />
92+<link rel="stylesheet" href="<!--{$TPL_DIR}-->css/admin_contents.css" type="text/css" media="all" />
93+<script type="text/javascript" src="<!--{$TPL_DIR}-->js/css.js"></script>
94+<script type="text/javascript" src="<!--{$TPL_DIR}-->js/navi.js"></script>
95+<script type="text/javascript" src="<!--{$TPL_DIR}-->js/win_op.js"></script>
96+<script type="text/javascript" src="<!--{$TPL_DIR}-->js/site.js"></script>
97+<script type="text/javascript" src="<!--{$TPL_DIR}-->js/jquery.js"></script>
98+<script type="text/javascript" src="<!--{$TPL_DIR}-->js/admin.js"></script>
99+<title><!--{$tpl_subtitle}--></title>
100+<script type="text/javascript">
101+
102+</script>
103+<style type="text/css">
104+@charset "UTF-8";
105+</style>
106+</head>
107+
108+<body onload="<!--{$tpl_onload}-->" class="authority_0" style="min_width: 400px">
109+<noscript>
110+  <p>JavaScript を有効にしてご利用下さい.</p>
111+</noscript>
112+
113+<div id="container">
114+<a name="top"></a>
115+<!--▼CONTENTS-->
116+<h1>Google Analytics Plugin</h1>
117+<div id="contents" class="clear-block">
118+  <form method="post" action="index.php">
119+    <div id="system" class="contents-main">
120+      <table class="list">
121+   <tr>
122+     <th>ウェブ プロパティ ID</th>
123+     <td>UA-<input type="text" name="ga_ua" value="<!--{$smarty.const.GA_UA}-->" /></td>
124+   </tr>
125+      </table>
126+      <div class="btn addnew">
127+   <input type="hidden" name="mode" value="register" />
128+   <button type="submit"><span>この内容で登録する</span></button>
129+      </div>
130+    </div>
131+  </form>
132+</div>
133+<!--▲CONTENTS-->
134+</div>
135+</body>
136+</html>
137Index: html/user_data/plugins/google_analytics/require.php
138===================================================================
139--- html/user_data/plugins/google_analytics/require.php (リビジョン 0)
140+++ html/user_data/plugins/google_analytics/require.php (リビジョン 0)
141@@ -0,0 +1,6 @@
142+<?php
143+/*
144+ * EC-CUBE 本体で, このプラグインの関数を使用したい場合は, ここで require する
145+ */
146+require_once(PLUGIN_PATH . "google_analytics/classes/pages/ga_config.php");
147+?>
148\ No newline at end of file
149Index: html/user_data/plugins/google_analytics/classes/pages/ga_config.php
150===================================================================
151--- html/user_data/plugins/google_analytics/classes/pages/ga_config.php (リビジョン 0)
152+++ html/user_data/plugins/google_analytics/classes/pages/ga_config.php (リビジョン 0)
153@@ -0,0 +1,3 @@
154+<?php
155+define('GA_UA', '');
156+?>
157Index: html/user_data/plugins/google_analytics/classes/pages/LC_Page_FrontParts_Bloc_GoogleAnalytics.php
158===================================================================
159--- html/user_data/plugins/google_analytics/classes/pages/LC_Page_FrontParts_Bloc_GoogleAnalytics.php   (リビジョン 0)
160+++ html/user_data/plugins/google_analytics/classes/pages/LC_Page_FrontParts_Bloc_GoogleAnalytics.php   (リビジョン 0)
161@@ -0,0 +1,70 @@
162+<?php
163+/*
164+ * This file is part of EC-CUBE
165+ *
166+ * Copyright(c) 2000-2009 LOCKON CO.,LTD. All Rights Reserved.
167+ *
168+ * http://www.lockon.co.jp/
169+ *
170+ * This program is free software; you can redistribute it and/or
171+ * modify it under the terms of the GNU General Public License
172+ * as published by the Free Software Foundation; either version 2
173+ * of the License, or (at your option) any later version.
174+ *
175+ * This program is distributed in the hope that it will be useful,
176+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
177+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
178+ * GNU General Public License for more details.
179+ *
180+ * You should have received a copy of the GNU General Public License
181+ * along with this program; if not, write to the Free Software
182+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
183+ */
184+
185+// {{{ requires
186+require_once CLASS_PATH . "pages/LC_Page.php";
187+
188+/**
189+ * Google Analytics プラグインを制御するクラス.
190+ *
191+ * @package Page
192+ * @author Kentaro Ohkouchi
193+ * @version $Id$
194+ */
195+class LC_Page_FrontParts_Bloc_GoogleAnalytics extends LC_Page {
196+
197+    // }}}
198+    // {{{ functions
199+
200+    /**
201+     * Page を初期化する.
202+     *
203+     * @return void
204+     */
205+    function init() {
206+        parent::init();
207+        $this->tpl_mainpage = USER_PATH . 'plugins/google_analytics/tpl/ga.tpl';
208+        $this->tpl_subtitle = "Google Analytics Plugin";
209+    }
210+
211+    /**
212+     * Page のプロセス.
213+     *
214+     * @return void
215+     */
216+    function process() {
217+        $objView = new SC_SiteView();
218+        $objView->assignobj($this);
219+        $objView->display($this->tpl_mainpage);
220+    }
221+
222+    /**
223+     * デストラクタ.
224+     *
225+     * @return void
226+     */
227+    function destroy() {
228+        parent::destroy();
229+    }
230+}
231+?>
232\ No newline at end of file
233Index: html/user_data/plugins/google_analytics/classes/pages/LC_Page_Admin_GoogleAnalytics.php
234===================================================================
235--- html/user_data/plugins/google_analytics/classes/pages/LC_Page_Admin_GoogleAnalytics.php (リビジョン 0)
236+++ html/user_data/plugins/google_analytics/classes/pages/LC_Page_Admin_GoogleAnalytics.php (リビジョン 0)
237@@ -0,0 +1,139 @@
238+<?php
239+/*
240+ * This file is part of EC-CUBE
241+ *
242+ * Copyright(c) 2000-2009 LOCKON CO.,LTD. All Rights Reserved.
243+ *
244+ * http://www.lockon.co.jp/
245+ *
246+ * This program is free software; you can redistribute it and/or
247+ * modify it under the terms of the GNU General Public License
248+ * as published by the Free Software Foundation; either version 2
249+ * of the License, or (at your option) any later version.
250+ *
251+ * This program is distributed in the hope that it will be useful,
252+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
253+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
254+ * GNU General Public License for more details.
255+ *
256+ * You should have received a copy of the GNU General Public License
257+ * along with this program; if not, write to the Free Software
258+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
259+ */
260+
261+// {{{ requires
262+require_once CLASS_PATH . "pages/LC_Page.php";
263+
264+/**
265+ * Google Analytics プラグインの管理画面を制御するクラス.
266+ *
267+ * @package Page
268+ * @author Kentaro Ohkouchi
269+ * @version $Id$
270+ */
271+class LC_Page_Admin_GoogleAnalytics extends LC_Page {
272+
273+    // }}}
274+    // {{{ functions
275+
276+    /**
277+     * Page を初期化する.
278+     *
279+     * @return void
280+     */
281+    function init() {
282+        parent::init();
283+        $this->tpl_mainpage = PLUGIN_PATH . 'google_analytics/tpl/index.tpl';
284+        $this->tpl_subtitle = "Google Analytics Plugin";
285+
286+        if (empty($_POST["mode"])) {
287+            $_POST["mode"] = "";
288+        }
289+
290+        if (empty($_GET["mode"])) {
291+            $_GET["mode"] = "";
292+        }
293+    }
294+
295+    /**
296+     * Page のプロセス.
297+     *
298+     * POST パラメータ "mode" が register の場合は登録処理を行う.
299+     * 登録処理の後, 自ページをリロードし, GET パラメータ "mode" を付与する.
300+     * 登録に成功し, GET パラメータ "mode" の値が success の場合は
301+     * 「登録に成功しました」というメッセージをポップアップで表示する.
302+     * 登録に失敗し, GET パラメータ "mode" の値が failure の場合は
303+     * 「登録に失敗しました」というメッセージをポップアップで表示する.
304+     *
305+     * @return void
306+     */
307+    function process() {
308+        // 認証可否の判定
309+        SC_Utils_Ex::sfIsSuccess(new SC_Session());
310+
311+        switch ($_POST["mode"]) {
312+        case "register":
313+            if ($this->register($_POST['ga_ua'])) {
314+                $this->reload(array("mode" => "success"));
315+                exit;
316+            } else {
317+                $this->reload(array("mode" => "failure"));
318+                exit;
319+            }
320+            break;
321+
322+          default:
323+        }
324+
325+        switch ($_GET["mode"]) {
326+        case "success":
327+            $this->tpl_onload .= "window.alert('登録に成功しました。');";
328+            break;
329+
330+        case "failure":
331+            $this->tpl_onload .= "window.alert('登録に失敗しました。');";
332+            break;
333+
334+          default:
335+        }
336+
337+        $objView = new SC_AdminView();
338+        $objView->assignobj($this);
339+        $objView->display($this->tpl_mainpage);
340+    }
341+
342+    /**
343+     * UA の登録を行う.
344+     *
345+     * classes/pages/ga_config.php を読み込み, ウェブプロパティID の文字列
346+     * を定数として書き出す.
347+     *
348+     * @param string ウェブプロパティID の文字列
349+     * @return boolean 登録に成功した場合 true; 失敗した場合 false;
350+     */
351+    function register($ua) {
352+        $data = "<?php\ndefine('GA_UA', '"
353+            . htmlspecialchars($ua, ENT_QUOTES) . "');\n?>\n";
354+
355+        $configFile = PLUGIN_PATH . "google_analytics/classes/pages/ga_config.php";
356+        $handle = fopen($configFile, "w");
357+        if (!$handle) {
358+            return false;
359+        }
360+        // ファイルの内容を書き出す.
361+        if (fwrite($handle, $data) === false) {
362+            return false;
363+        }
364+        return true;
365+    }
366+
367+    /**
368+     * デストラクタ.
369+     *
370+     * @return void
371+     */
372+    function destroy() {
373+        parent::destroy();
374+    }
375+}
376+?>
377\ No newline at end of file
378Index: html/user_data/plugins/google_analytics/ga.php
379===================================================================
380--- html/user_data/plugins/google_analytics/ga.php  (リビジョン 0)
381+++ html/user_data/plugins/google_analytics/ga.php  (リビジョン 0)
382@@ -0,0 +1,12 @@
383+<?php
384+// {{{ requires
385+require_once(PLUGIN_PATH . "google_analytics/classes/pages/LC_Page_FrontParts_Bloc_GoogleAnalytics.php");
386+
387+// }}}
388+// {{{ generate page
389+
390+$objPage = new LC_Page_FrontParts_Bloc_GoogleAnalytics();
391+register_shutdown_function(array($objPage, "destroy"));
392+$objPage->init();
393+$objPage->process();
394+?>
395\ No newline at end of file
396Index: html/user_data/plugins/google_analytics/index.php
397===================================================================
398--- html/user_data/plugins/google_analytics/index.php   (リビジョン 0)
399+++ html/user_data/plugins/google_analytics/index.php   (リビジョン 0)
400@@ -0,0 +1,34 @@
401+<?php
402+/*
403+ * This file is part of EC-CUBE
404+ *
405+ * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
406+ *
407+ * http://www.lockon.co.jp/
408+ *
409+ * This program is free software; you can redistribute it and/or
410+ * modify it under the terms of the GNU General Public License
411+ * as published by the Free Software Foundation; either version 2
412+ * of the License, or (at your option) any later version.
413+ *
414+ * This program is distributed in the hope that it will be useful,
415+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
416+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
417+ * GNU General Public License for more details.
418+ *
419+ * You should have received a copy of the GNU General Public License
420+ * along with this program; if not, write to the Free Software
421+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
422+ */
423+// {{{ requires
424+require_once("../../../admin/require.php");
425+require_once(USER_PATH . 'plugins/google_analytics/classes/pages/LC_Page_Admin_GoogleAnalytics.php');
426+
427+// }}}
428+// {{{ generate page
429+
430+$objPage = new LC_Page_Admin_GoogleAnalytics();
431+register_shutdown_function(array($objPage, 'destroy'));
432+$objPage->init();
433+$objPage->process();
434+?>
435\ No newline at end of file
436Index: html/install/sql/insert_data.sql
437===================================================================
438--- html/install/sql/insert_data.sql    (リビジョン 18218)
439+++ html/install/sql/insert_data.sql    (作業コピー)
440@@ -1114,5 +1114,8 @@
441 INSERT INTO mtb_constants VALUES ('OSTORE_E_C_BATCH_ERR', '"2010"', 522, 'オーナーズストア通信エラーコード');
442 INSERT INTO mtb_constants VALUES ('OPTION_FAVOFITE_PRODUCT', '1', 523, 'お気に入り商品登録(有効:1 無効:0)');
443 INSERT INTO mtb_constants VALUES ('IMAGE_RENAME', 'true', 525, '画像リネーム設定(商品画像のみ)(true:リネームする、false:リネームしない)');
444+INSERT INTO mtb_constants VALUES ('PLUGIN_DIR', '"plugins/"', 600, 'プラグインディレクトリ');
445+INSERT INTO mtb_constants VALUES ('PLUGIN_PATH', 'USER_PATH . PLUGIN_DIR', 601, 'プラグイン保存先');
446+INSERT INTO mtb_constants VALUES ('PLUGIN_URL', 'USER_URL . PLUGIN_DIR', 602, 'プラグイン URL');
447 
448 INSERT INTO dtb_module (module_id,module_code,module_name,update_date,create_date) VALUES (0,0,'patch',now(),now());
449Index: data/Smarty/templates/default/admin/main_frame.tpl
450===================================================================
451--- data/Smarty/templates/default/admin/main_frame.tpl  (リビジョン 18218)
452+++ data/Smarty/templates/default/admin/main_frame.tpl  (作業コピー)
[18225]453@@ -112,6 +112,10 @@
[18223]454     <li id="navi-ownersstore" class="<!--{if $tpl_mainno eq "ownersstore"}-->on<!--{/if}-->">
455         <a><span>OWNERS STORE</span></a>
456         <!--{include file="`$smarty.const.TEMPLATE_ADMIN_DIR`ownersstore/subnavi.tpl"}-->
[18226]457+    </li>
[18223]458+    <li id="navi-plugin" class="<!--{if $tpl_mainno eq "plugin"}-->on<!--{/if}-->">
459+      <a><span>プラグイン設定</span></a>
460+      <!--{include file="`$smarty.const.PLUGIN_PATH`plugin_menu.tpl"}-->
461     </li>
462 </ul>
463 <div style="clear: both;"></div>
464Index: data/require_plugin.php
465===================================================================
466--- data/require_plugin.php (リビジョン 18218)
467+++ data/require_plugin.php (作業コピー)
468@@ -1,5 +1,39 @@
469 <?php
470-  /*
471-   * プラグインを require するためのファイル
472-   */
473+/*
474+ * This file is part of EC-CUBE
475+ *
476+ * Copyright(c) 2000-2009 LOCKON CO.,LTD. All Rights Reserved.
477+ *
478+ * http://www.lockon.co.jp/
479+ *
480+ * This program is free software; you can redistribute it and/or
481+ * modify it under the terms of the GNU General Public License
482+ * as published by the Free Software Foundation; either version 2
483+ * of the License, or (at your option) any later version.
484+ *
485+ * This program is distributed in the hope that it will be useful,
486+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
487+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
488+ * GNU General Public License for more details.
489+ *
490+ * You should have received a copy of the GNU General Public License
491+ * along with this program; if not, write to the Free Software
492+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
493+ */
494+
495+// load plugins
496+/* -----------------------------------------------------------------------------
497+ * TODO PHP4 でも使えるように, XML パーサーをファクトリークラスで実装する
498+ * ----------------------------------------------------------------------------*/
499+if (version_compare("5", PHP_VERSION, "<")) {
500+    $plugins = file_get_contents(USER_PATH . "plugins/plugins.xml");
501+    $xml = new SimpleXMLElement($plugins);
502+    foreach ($xml->plugin as $plugin) {
503+   
504+        $requireFile = USER_PATH . "plugins/" . $plugin->path . "/require.php";
505+        if (file_exists($requireFile)) {
506+            require_once($requireFile);
507+        }
508+    }
509+}
510 ?>
511Index: data/mtb_constants_init.php
512===================================================================
513--- data/mtb_constants_init.php (リビジョン 18218)
514+++ data/mtb_constants_init.php (作業コピー)
[18224]515@@ -670,4 +670,10 @@
[18223]516 define('OPTION_FAVOFITE_PRODUCT','1');
517 /** 画像リネーム設定(商品画像のみ) */
518 define('IMAGE_RENAME', true);
519+/** プラグインディレクトリ */
520+define("PLUGIN_DIR", "plugins/");
521+/** プラグイン保存先 */
522+define("PLUGIN_PATH", USER_PATH . PLUGIN_DIR);
523+/** プラグイン URL */
524+define("PLUGIN_URL", USER_URL . PLUGIN_DIR);
525 ?>
526Index: data/class/pages/LC_Page.php
527===================================================================
528--- data/class/pages/LC_Page.php    (リビジョン 18218)
529+++ data/class/pages/LC_Page.php    (作業コピー)
530@@ -82,6 +82,9 @@
531      */
532     function init() {
533         $this->tpl_authority = $_SESSION['authority'];
534+        // XXX すべてのページで宣言するべき
535+        $layout = new SC_Helper_PageLayout_Ex();
536+        $layout->sfGetPageLayout($this, false);
537     }
538 
539     /**
540Index: data/class/helper/SC_Helper_PageLayout.php
541===================================================================
542--- data/class/helper/SC_Helper_PageLayout.php  (リビジョン 18218)
543+++ data/class/helper/SC_Helper_PageLayout.php  (作業コピー)
544@@ -61,9 +61,11 @@
545             $objPage->tpl_mainpage = USER_PATH . "templates/preview/"
546                 . TEMPLATE_NAME . "/" . $arrPageData[0]['filename'] . ".tpl";
547         }
548-               
549-        foreach($arrPageData[0] as $key => $val) {
550-            $debug_message.= "arrPageData[$key]:" . $val . "\n";
551+
552+        if (!empty($arrPageData[0])) {
553+            foreach($arrPageData[0] as $key => $val) {
554+                $debug_message.= "arrPageData[$key]:" . $val . "\n";
555+            }
556         }
557         
558         $debug_message.= "TEMPLATE_NAME:".TEMPLATE_NAME . "\n";
Note: See TracBrowser for help on using the repository browser.