source: branches/version-2_12-dev/html/user_data/plugins/google_analytics/classes/pages/LC_Page_Admin_GoogleAnalytics.php @ 21514

Revision 21514, 4.3 KB checked in by Seasoft, 12 years ago (diff)

#1625 (typo修正・ソース整形・ソースコメントの改善)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 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_EX_REALDIR . 'page_extends/LC_Page_Ex.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_Ex {
35
36    /** プラグイン情報配列 (呼び出し元でセットする) */
37    var $arrPluginInfo;
38
39    // }}}
40    // {{{ functions
41
42    /**
43     * Page を初期化する.
44     *
45     * @return void
46     */
47    function init() {
48        parent::init();
49        $this->tpl_mainpage = $this->arrPluginInfo['fullpath'] . 'tpl/admin/index.tpl';
50        $this->tpl_mainno   = 'plugin';
51        $this->tpl_subno    = $this->arrPluginInfo['path'];
52        $this->tpl_subtitle = "プラグイン「{$this->arrPluginInfo['name']}」の設定";
53
54        if (empty($_POST['mode'])) {
55            $_POST['mode'] = '';
56        }
57
58        if (empty($_GET['mode'])) {
59            $_GET['mode'] = '';
60        }
61    }
62
63    /**
64     * Page のプロセス.
65     *
66     * POST パラメーター 'mode' が register の場合は登録処理を行う.
67     * 登録処理の後, 自ページをリロードし, GET パラメーター 'mode' を付与する.
68     * 登録に成功し, GET パラメーター 'mode' の値が success の場合は
69     * 「登録に成功しました」というメッセージをポップアップで表示する.
70     * 登録に失敗し, GET パラメーター 'mode' の値が failure の場合は
71     * 「登録に失敗しました」というメッセージをポップアップで表示する.
72     *
73     * TODO Transaction Token を使用する
74     *
75     * @return void
76     */
77    function process() {
78        // 認証可否の判定
79        SC_Utils_Ex::sfIsSuccess(new SC_Session());
80
81        switch ($_POST['mode']) {
82        case 'register':
83            if ($this->register($_POST['ga_ua'])) {
84                SC_Response_Ex::reload(array('mode' => 'success'), true);
85                exit;
86            } else {
87                SC_Response_Ex::reload(array('mode' => 'failure'), true);
88                exit;
89            }
90            break;
91
92          default:
93        }
94
95        switch ($_GET['mode']) {
96        case 'success':
97            $this->tpl_onload .= "window.alert('登録に成功しました。');";
98            break;
99
100        case 'failure':
101            $this->tpl_onload .= "window.alert('登録に失敗しました。');";
102            break;
103
104          default:
105        }
106
107        $objView = new SC_AdminView_Ex();
108        $objView->assignobj($this);
109        $objView->display(MAIN_FRAME);
110    }
111
112    /**
113     * UA の登録を行う.
114     *
115     * classes/pages/ga_config.php を読み込み, ウェブプロパティID の文字列
116     * を定数として書き出す.
117     *
118     * @param string ウェブプロパティID の文字列
119     * @return boolean 登録に成功した場合 true; 失敗した場合 false;
120     */
121    function register($ua) {
122        $data = "<?php\ndefine('GA_UA', '"
123            . htmlspecialchars($ua, ENT_QUOTES) . "');\n?>\n";
124
125        $configFile = $this->arrPluginInfo['fullpath'] . 'classes/pages/ga_config.php';
126        $handle = fopen($configFile, 'w');
127        if (!$handle) {
128            return false;
129        }
130        // ファイルの内容を書き出す.
131        if (fwrite($handle, $data) === false) {
132            return false;
133        }
134        return true;
135    }
136
137    /**
138     * デストラクタ.
139     *
140     * @return void
141     */
142    function destroy() {
143        parent::destroy();
144    }
145}
Note: See TracBrowser for help on using the repository browser.