source: branches/comu-ver2/html/user_data/plugins/google_analytics/classes/pages/LC_Page_Admin_GoogleAnalytics.php @ 18345

Revision 18345, 4.0 KB checked in by nanasess, 14 years ago (diff)

プラグイン機能をコミット(#494)

  • 使用する場合は data/require_base.php 96行目 と, data/Smarty/templates/default/admin/main_frame.tpl 116行目〜121行目のコメントをはずすこと
  • Property svn:keywords set to Id
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2009 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once CLASS_PATH . "pages/LC_Page.php";
26
27/**
28 * Google Analytics プラグインの管理画面を制御するクラス.
29 *
30 * @package Page
31 * @author Kentaro Ohkouchi
32 * @version $Id$
33 */
34class LC_Page_Admin_GoogleAnalytics extends LC_Page {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = PLUGIN_PATH . 'google_analytics/tpl/index.tpl';
47        $this->tpl_subtitle = "Google Analytics Plugin";
48
49        if (empty($_POST["mode"])) {
50            $_POST["mode"] = "";
51        }
52
53        if (empty($_GET["mode"])) {
54            $_GET["mode"] = "";
55        }
56    }
57
58    /**
59     * Page のプロセス.
60     *
61     * POST パラメータ "mode" が register の場合は登録処理を行う.
62     * 登録処理の後, 自ページをリロードし, GET パラメータ "mode" を付与する.
63     * 登録に成功し, GET パラメータ "mode" の値が success の場合は
64     * 「登録に成功しました」というメッセージをポップアップで表示する.
65     * 登録に失敗し, GET パラメータ "mode" の値が failure の場合は
66     * 「登録に失敗しました」というメッセージをポップアップで表示する.
67     *
68     * TODO Transaction Token を使用する
69     *
70     * @return void
71     */
72    function process() {
73        // 認証可否の判定
74        SC_Utils_Ex::sfIsSuccess(new SC_Session());
75
76        switch ($_POST["mode"]) {
77        case "register":
78            if ($this->register($_POST['ga_ua'])) {
79                $this->reload(array("mode" => "success"));
80                exit;
81            } else {
82                $this->reload(array("mode" => "failure"));
83                exit;
84            }
85            break;
86
87          default:
88        }
89
90        switch ($_GET["mode"]) {
91        case "success":
92            $this->tpl_onload .= "window.alert('登録に成功しました。');";
93            break;
94
95        case "failure":
96            $this->tpl_onload .= "window.alert('登録に失敗しました。');";
97            break;
98
99          default:
100        }
101
102        $objView = new SC_AdminView();
103        $objView->assignobj($this);
104        $objView->display($this->tpl_mainpage);
105    }
106
107    /**
108     * UA の登録を行う.
109     *
110     * classes/pages/ga_config.php を読み込み, ウェブプロパティID の文字列
111     * を定数として書き出す.
112     *
113     * @param string ウェブプロパティID の文字列
114     * @return boolean 登録に成功した場合 true; 失敗した場合 false;
115     */
116    function register($ua) {
117        $data = "<?php\ndefine('GA_UA', '"
118            . htmlspecialchars($ua, ENT_QUOTES) . "');\n?>\n";
119
120        $configFile = PLUGIN_PATH . "google_analytics/classes/pages/ga_config.php";
121        $handle = fopen($configFile, "w");
122        if (!$handle) {
123            return false;
124        }
125        // ファイルの内容を書き出す.
126        if (fwrite($handle, $data) === false) {
127            return false;
128        }
129        return true;
130    }
131
132    /**
133     * デストラクタ.
134     *
135     * @return void
136     */
137    function destroy() {
138        parent::destroy();
139    }
140}
141?>
Note: See TracBrowser for help on using the repository browser.