質問編集履歴

10

コードの修正

2018/09/09 08:10

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -350,7 +350,7 @@
350
350
 
351
351
  ```ここに言語を入力
352
352
 
353
- if (isset($_GET['page'] && $_POST['page'] == "{$this->DIR}_reset_page")){
353
+ if (isset($_GET['page'] && $_GET['page'] == "{$this->DIR}_reset_page")){
354
354
 
355
355
  ```
356
356
 

9

文章の修正

2018/09/09 08:10

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -378,7 +378,7 @@
378
378
 
379
379
  ```
380
380
 
381
- 「Notice: Undefined index: page in」エラーのまま
381
+ の場合、「Notice: Undefined index: page in」エラーのまま
382
382
 
383
383
 
384
384
 

8

コードの修正

2018/09/08 11:05

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -350,7 +350,7 @@
350
350
 
351
351
  ```ここに言語を入力
352
352
 
353
- if (isset($_GET['page'] && $_POST['page'] == "{$this->DIR}_reset_page"){
353
+ if (isset($_GET['page'] && $_POST['page'] == "{$this->DIR}_reset_page")){
354
354
 
355
355
  ```
356
356
 

7

文章が見にくいので修正

2018/09/08 11:03

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -354,7 +354,9 @@
354
354
 
355
355
  ```
356
356
 
357
+ の場合、エラー内容
358
+
357
- の場合、エラー内容:Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
359
+ Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
358
360
 
359
361
 
360
362
 
@@ -364,7 +366,9 @@
364
366
 
365
367
  ```
366
368
 
369
+ の場合、エラー内容
370
+
367
- の場合、エラー内容:Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
371
+ Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
368
372
 
369
373
 
370
374
 

6

エラー表示の追加

2018/09/08 10:58

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -330,44 +330,64 @@
330
330
 
331
331
  }
332
332
 
333
- function getreposrt($name = 'GoogleAnalyticsRankingData'){
333
+
334
-
335
- $data = get_option($name);
336
-
337
- $today = date('Y-m-d',strtotime('-1 hour'));
338
-
339
- $yesterday = date('Y-m-d',strtotime('-25 hour'));
340
-
341
- if(empty($data) || (is_array($data) && (empty($data[$today]) || !count($data[$today])))){
342
-
343
- $task_time = strtotime(date('2018-01-01 1:00:00'));
344
-
345
- if ( !wp_next_scheduled('get_ranking_cron')) {
346
-
347
- wp_schedule_event( $task_time, 'daily', 'get_ranking_cron');
348
-
349
- }
350
-
351
- if(!empty($data[$today])){
352
-
353
- return $data[$today];
354
-
355
- }elseif(!empty($data[$yesterday])){
356
-
357
- return $data[$yesterday];
358
-
359
- }else{
360
-
361
- return array();
362
-
363
- }
364
-
365
- }
366
-
367
- $GLOBALS['GoogleAnalyticsRanking'] = new GoogleAnalyticsRanking();
368
334
 
369
335
  ```
370
336
 
371
337
  ※追記です。
372
338
 
339
+ デバッグモードでプラグインを有効化すると
340
+
341
+ 「Notice: Undefined index: page in」で次の箇所にエラーが表示されます。
342
+
343
+ ```ここに言語を入力
344
+
345
+ if($_GET['page'] === "{$this->DIR}_reset_page")
346
+
347
+ ```
348
+
349
+ Notice: Undefined indexのエラー対策として3パターン編集してみました。
350
+
351
+ ```ここに言語を入力
352
+
373
- どうもアカウントと紐付けはできているけど、データをとってきていないようです。色々調べると配列の値が空という結果になりました。アナリティクスAPIを利用したサンプルから見つけるしかなさそうですが、一番シンプルなものはないですかねぇ…。
353
+ if (isset($_GET['page'] && $_POST['page'] == "{$this->DIR}_reset_page"){
354
+
355
+ ```
356
+
357
+ の場合、エラー内容:Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
358
+
359
+
360
+
361
+ ```ここに言語を入力
362
+
363
+ if (isset($_GET['page'] === "{$this->DIR}_reset_page")){
364
+
365
+ ```
366
+
367
+ の場合、エラー内容:Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
368
+
369
+
370
+
371
+ ```ここに言語を入力
372
+
373
+ if (!empty($_GET['page'] === "{$this->DIR}_reset_page")){
374
+
375
+ ```
376
+
377
+ 「Notice: Undefined index: page in」エラーのまま
378
+
379
+
380
+
381
+ その他、edumpというデバッグプラグインでは
382
+
383
+ 「Only variables should be passed by reference」というエラーが
384
+
385
+ ```ここに言語を入力
386
+
387
+ $this->DIR = @array_pop(explode("/",dirname(__FILE__)));
388
+
389
+ ```
390
+
391
+ に出ます。
392
+
393
+ こちらの対処方法も分からない状態です。

5

追記の変更

2018/09/08 10:56

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -370,14 +370,4 @@
370
370
 
371
371
  ※追記です。
372
372
 
373
- edumpというデバッグプラグインを使用したところ、
374
-
375
- 「Only variables should be passed by reference~」というエラーが
376
-
377
- ```ここに言語を入力
378
-
379
- $this->DIR = @array_pop(explode("/",dirname(__FILE__)));
373
+ どうもアカウントと紐付けはできているけど、データをとってきていないようです。色々調べると配列の値が空という結果になりました。アナリティクスAPIを利用したサンプルから見つけるしかなさそうですが、一番シンプルなものはないですかねぇ…。
380
-
381
- ```
382
-
383
- の部分で出ていました。解決策がお分かりになりますでしょうか?

4

追記です

2018/09/07 13:37

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -368,4 +368,16 @@
368
368
 
369
369
  ```
370
370
 
371
+ ※追記です。
372
+
371
- ここが原因ではないかという箇所指摘頂ければ存じます
373
+ edumpというデバッグプラグイン使用したころ、
374
+
375
+ 「Only variables should be passed by reference~」というエラーが
376
+
377
+ ```ここに言語を入力
378
+
379
+ $this->DIR = @array_pop(explode("/",dirname(__FILE__)));
380
+
381
+ ```
382
+
383
+ の部分で出ていました。解決策がお分かりになりますでしょうか?

3

リンクの修正

2018/09/07 12:18

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  このプラグインは「Google Analyticator」というプラグインを改良されて作られたらしく、APIライブラリは全く同じものでした。
6
6
 
7
- Google Analyticator](https://ja.wordpress.org/plugins/google-analyticator/Google Analytics)
7
+ [Google Analyticator](https://ja.wordpress.org/plugins/google-analyticator/Google Analytics)
8
8
 
9
9
  メインのphp
10
10
 

2

コードの追加

2018/09/07 06:27

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -1,25 +1,371 @@
1
- お世話になりま
2
-
3
-
4
-
5
- Google アナリティクス APIを使用したWordpressプラグインを数年前に人にって頂いのですが、1週間ぐい前から動作をなりました。
6
-
7
- そのプラグインは、Googleアナリティクスと連携して、ページビューが多い順に並べてランキング形式で表示させるものなのですが、操作をしてもページビュー数等が表示されなくなりました。
8
-
9
-
10
-
11
- Wordpressをデバッグモードにしてみましたが、原因となるエラーは見つからず、プラグインに備わったデバッグモードでは数値が表示されると「FALSE」と表示されます。
12
-
13
-
14
-
15
- 色々調べてみるとこのプラグインは「Google Analyticator」というプラグインを改良されて作られたもののようで、APIライブラリは全く同じものでした。
16
-
17
- ただ、「Google Analyticator」は動くのですが、当方のプラグインは動きません。
18
-
19
- [Google Analyticator](https://ja.wordpress.org/plugins/google-analyticator/Google Analytics)
20
-
21
-
22
-
23
- 興味がある、またはアドバイスを頂ける方がおられましたら以下のリンクでDL出来ますので、大きな修正が必要なのか少しパラメータを変更するだけで動くものなのかお知らせ頂ければと存じます。
24
-
25
- [プラグインのダウンロード(ギガファイル便)](https://33.gigafile.nu/0914-bd9919c3db49c0d58c39fbe3aeb5eb176)
1
+ アナリティクス APIを使用したWPプラグインを数年前人に作って頂いたのですが、1週間ぐらい前から動作をしくなりました
2
+
3
+ アナリティクスAPIと連携して、ランキング形式で表示させるものなのですが、操作をしてもページビュー数等が表示されなくなりました。
4
+
5
+ このプラグインは「Google Analyticator」というプラグインを改良されてられたらしく、APIライブラリは全く同じものでした。
6
+
7
+ Google Analyticator](https://ja.wordpress.org/plugins/google-analyticator/Google Analytics)
8
+
9
+ メインのphp
10
+
11
+ ```言語を入力
12
+
13
+ <?php
14
+
15
+ define('GARCODE',"GoogleAnalyticsRankingCode");
16
+
17
+ define('GARTOKEN',"GoogleAnalyticsRankingToken");
18
+
19
+ define('GARWPID',"GoogleAnalyticsRankingWebPropertyID");
20
+
21
+ define('GARVID',"GoogleAnalyticsRankingViewID");
22
+
23
+ define('HIDDEN_IDS',"GoogleAnalyticsRankingHiddenIDs");
24
+
25
+ function GoogleAnalyticsRanking_Uninstall(){
26
+
27
+ delete_option(GARCODE);
28
+
29
+ delete_option(GARTOKEN);
30
+
31
+ delete_option(GARWPID);
32
+
33
+ delete_option(GARVID);
34
+
35
+ delete_option(HIDDEN_IDS);
36
+
37
+ wp_clear_scheduled_hook('get_ranking_cron');
38
+
39
+ }
40
+
41
+ class GoogleAnalyticsRanking {
42
+
43
+ function __construct(){
44
+
45
+ if(!class_exists('Google_Client')){
46
+
47
+ require_once(dirname(__FILE__).'/google-api-php-client/src/Google_Client.php');
48
+
49
+ }
50
+
51
+ if(!class_exists('Google_AnalyticsService')){
52
+
53
+ require_once(dirname(__FILE__).'/google-api-php-client/src/contrib/Google_AnalyticsService.php');
54
+
55
+ }
56
+
57
+ foreach(json_decode(file_get_contents(dirname(__FILE__).'/client_id/client_id.json'),true) as $k => $v){
58
+
59
+ if(is_array($v)){
60
+
61
+ foreach($v as $k2 => $v2){
62
+
63
+ $this->$k2 = $v2;
64
+
65
+ }
66
+
67
+ }else{
68
+
69
+ $this->$k = $v;
70
+
71
+ }
72
+
73
+ }
74
+
75
+ $this->DIR = @array_pop(explode("/",dirname(__FILE__)));
76
+
77
+ $this->NONCE = md5(dirname(__FILE__));
78
+
79
+ if(function_exists('register_uninstall_hook'))register_uninstall_hook(__FILE__, 'GoogleAnalyticsRanking_Uninstall');
80
+
81
+ add_action('init', array($this,'init'));
82
+
83
+ add_action('wp_ajax_get_posts_googleanalyticsranking',array($this,'wp_ajax_get_posts'));
84
+
85
+ add_action('get_ranking_cron', array($this, 'get_ranking'));
86
+
87
+ }
88
+
89
+ function init(){
90
+
91
+ $this->client = new Google_Client();
92
+
93
+ $this->client->setApprovalPrompt('force');
94
+
95
+ $this->client->setAccessType('offline');
96
+
97
+ $this->client->setClientId($this->client_id);
98
+
99
+ $this->client->setClientSecret($this->client_secret);
100
+
101
+ $this->client->setRedirectUri($this->redirect_uris[0]);
102
+
103
+ $this->client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
104
+
105
+ $this->token = get_option(GARTOKEN);
106
+
107
+ $this->WebPropertyID = get_option(GARWPID);
108
+
109
+ $this->ViewID = get_option(GARVID);
110
+
111
+ if(!empty($this->token)){
112
+
113
+ $this->client->setAccessToken(json_encode($this->token));
114
+
115
+ $this->analytics = new Google_AnalyticsService($this->client);
116
+
117
+ }
118
+
119
+ add_action('admin_menu',array($this,'admin_menu'));
120
+
121
+ }
122
+
123
+ function wp_enqueue(){
124
+
125
+ wp_enqueue_script('googleclient','https://apis.google.com/js/client.js?onload=googleApiClientReady',array('jquery'),'',true);
126
+
127
+ wp_enqueue_script('option_page',plugins_url($this->DIR).'/assets/js/option_page.js',array('jquery','googleclient'),'',true);
128
+
129
+ }
130
+
131
+ function admin_menu(){
132
+
133
+ $hook = add_menu_page('ランキング','ランキング','edit_others_posts',"{$this->DIR}_options_page",array($this,'options_page'));
134
+
135
+ add_submenu_page("{$this->DIR}_options_page",'初期設定','初期設定','edit_others_posts',"{$this->DIR}_options_page",array($this,'options_page'));
136
+
137
+ add_action('load-'.$hook,array($this,'options_page_update'));
138
+
139
+ add_action('load-'.$hook,array($this,'wp_enqueue'));
140
+
141
+ if(empty($this->token)){
142
+
143
+ add_action('load-'.$hook,array($this,'redirect_client_setting_page'));
144
+
145
+ $hook = add_submenu_page("{$this->DIR}_options_page",'認証コード設定','認証コード設定','edit_others_posts',"{$this->DIR}_client_setting_page",array($this,'client_setting_page'));
146
+
147
+ add_action('load-'.$hook,array($this,'client_setting_page_update'));
148
+
149
+ }else{
150
+
151
+ remove_action('load-'.$hook,array($this,'redirect_client_setting_page'));
152
+
153
+ }
154
+
155
+ if($_GET['page'] === "{$this->DIR}_reset_page"){
156
+
157
+ delete_option('GoogleAnalyticsRankingData');
158
+
159
+ delete_option(GARCODE);
160
+
161
+ delete_option(GARTOKEN);
162
+
163
+ delete_option(GARWPID);
164
+
165
+ delete_option(GARVID);
166
+
167
+ wp_safe_redirect(admin_url("admin.php?page={$this->DIR}_client_setting_page&update=reset"));
168
+
169
+ exit;
170
+
171
+ }
172
+
173
+ function options_page(){
174
+
175
+ require_once(dirname(__FILE__).'/assets/views/options_page.php');
176
+
177
+ }
178
+
179
+ function options_page_update(){
180
+
181
+ if($_SERVER["REQUEST_METHOD"] == "POST"){
182
+
183
+ if(!empty($this->token)){
184
+
185
+ $my_nonce = filter_input(INPUT_POST,$this->NONCE)?filter_input(INPUT_POST,$this->NONCE):null;
186
+
187
+ if(wp_verify_nonce($my_nonce, wp_create_nonce($this->DIR))){
188
+
189
+ $webproperty_id = filter_input(INPUT_POST,'webproperty_id');
190
+
191
+ if(!empty($webproperty_id)){
192
+
193
+ update_option(GARWPID,$webproperty_id);
194
+
195
+ if($view_id = filter_input(INPUT_POST,'view_id')){
196
+
197
+ update_option(GARVID,$view_id);
198
+
199
+ }else{
200
+
201
+ list($pre, $account_id, $post) = explode('-',$webproperty_id);
202
+
203
+ $profiles = $this->analytics->management_profiles->listManagementProfiles($account_id,$webproperty_id);
204
+
205
+ update_option(GARVID,$profiles['items'][0]['id']);
206
+
207
+ }
208
+
209
+ delete_option('GoogleAnalyticsRankingData');
210
+
211
+ exec("nohup php -c '' '".dirname(__FILE__)."/background.php' > /dev/null &");
212
+
213
+ wp_safe_redirect(admin_url("admin.php?page={$_GET['page']}&update=ok"));
214
+
215
+ exit;
216
+
217
+ }else{
218
+
219
+ wp_safe_redirect(admin_url("admin.php?page={$_GET['page']}&update=error"));
220
+
221
+ exit;
222
+
223
+ }
224
+
225
+ }else{
226
+
227
+ wp_safe_redirect(admin_url("admin.php?page={$_GET['page']}&update=error"));
228
+
229
+ exit;
230
+
231
+ }
232
+
233
+ }else{
234
+
235
+ wp_safe_redirect(admin_url("admin.php?page={$this->DIR}_client_setting_page"));
236
+
237
+ exit;
238
+
239
+ }
240
+
241
+ }
242
+
243
+ }
244
+
245
+ function client_setting_page(){
246
+
247
+ require_once(dirname(__FILE__).'/assets/views/client_setting_page.php');
248
+
249
+ }
250
+
251
+ function redirect_client_setting_page(){
252
+
253
+ wp_safe_redirect(admin_url("admin.php?page={$this->DIR}_client_setting_page"));
254
+
255
+ exit;
256
+
257
+ }
258
+
259
+ function client_setting_page_update(){
260
+
261
+ if($_SERVER["REQUEST_METHOD"] == "POST"){
262
+
263
+ $my_nonce = filter_input(INPUT_POST,$this->NONCE)?filter_input(INPUT_POST,$this->NONCE):null;
264
+
265
+ if(wp_verify_nonce($my_nonce, wp_create_nonce($this->DIR))){
266
+
267
+ $code = filter_input(INPUT_POST,'token_key');
268
+
269
+ if(!empty($code)){
270
+
271
+ $res = file_get_contents($this->token_uri, false, stream_context_create(array('http' => array(
272
+
273
+ 'method' => 'POST',
274
+
275
+ 'content' => http_build_query(array(
276
+
277
+ 'code' => $code,
278
+
279
+ 'grant_type' => 'authorization_code',
280
+
281
+ 'redirect_uri' => $this->redirect_uris[0],
282
+
283
+ 'client_id' => $this->client_id,
284
+
285
+ 'client_secret' => $this->client_secret,
286
+
287
+ )),
288
+
289
+ ))));
290
+
291
+ $token = json_decode($res, true);
292
+
293
+ if(isset($token['error']) || empty($token)){
294
+
295
+ wp_safe_redirect(admin_url("admin.php?page={$this->DIR}_client_setting_page&update=error"));
296
+
297
+ exit;
298
+
299
+ }
300
+
301
+ delete_option(GARCODE);
302
+
303
+ delete_option(GARTOKEN);
304
+
305
+ if(!add_option(GARCODE,$code,'','no')){
306
+
307
+ wp_safe_redirect(admin_url("admin.php?page={$this->DIR}_client_setting_page&update=error"));
308
+
309
+ exit;
310
+
311
+ }
312
+
313
+ if(!add_option(GARTOKEN,$token,'','no')){
314
+
315
+ wp_safe_redirect(admin_url("admin.php?page={$this->DIR}_client_setting_page&update=error"));
316
+
317
+ exit;
318
+
319
+ }
320
+
321
+ }
322
+
323
+ wp_safe_redirect(admin_url("admin.php?page={$this->DIR}_options_page"));
324
+
325
+ exit;
326
+
327
+ }
328
+
329
+ }
330
+
331
+ }
332
+
333
+ function getreposrt($name = 'GoogleAnalyticsRankingData'){
334
+
335
+ $data = get_option($name);
336
+
337
+ $today = date('Y-m-d',strtotime('-1 hour'));
338
+
339
+ $yesterday = date('Y-m-d',strtotime('-25 hour'));
340
+
341
+ if(empty($data) || (is_array($data) && (empty($data[$today]) || !count($data[$today])))){
342
+
343
+ $task_time = strtotime(date('2018-01-01 1:00:00'));
344
+
345
+ if ( !wp_next_scheduled('get_ranking_cron')) {
346
+
347
+ wp_schedule_event( $task_time, 'daily', 'get_ranking_cron');
348
+
349
+ }
350
+
351
+ if(!empty($data[$today])){
352
+
353
+ return $data[$today];
354
+
355
+ }elseif(!empty($data[$yesterday])){
356
+
357
+ return $data[$yesterday];
358
+
359
+ }else{
360
+
361
+ return array();
362
+
363
+ }
364
+
365
+ }
366
+
367
+ $GLOBALS['GoogleAnalyticsRanking'] = new GoogleAnalyticsRanking();
368
+
369
+ ```
370
+
371
+ ここが原因ではないかという箇所を指摘頂ければと存じます

1

文章の編集

2018/09/07 06:25

投稿

MyQuestioner
MyQuestioner

スコア57

test CHANGED
File without changes
test CHANGED
@@ -22,4 +22,4 @@
22
22
 
23
23
  興味がある、またはアドバイスを頂ける方がおられましたら以下のリンクでDL出来ますので、大きな修正が必要なのか少しパラメータを変更するだけで動くものなのかお知らせ頂ければと存じます。
24
24
 
25
- [プラグインのダウンロード(ギガファイル便)](https://38.gigafile.nu/0914-c0cd66c344a73d22fd87a5e7fed696608)
25
+ [プラグインのダウンロード(ギガファイル便)](https://33.gigafile.nu/0914-bd9919c3db49c0d58c39fbe3aeb5eb176)