Crazy Bone - Version 0.2.0

Version Description

Download this release

Release Info

Developer wokamoto
Plugin Icon wp plugin Crazy Bone
Version 0.2.0
Comparing to
See all releases

Code changes from version 0.1.2 to 0.2.0

languages/user-login-log-ja.mo CHANGED
Binary file
languages/user-login-log-ja.po CHANGED
@@ -3,7 +3,7 @@ msgstr ""
3
  "Project-Id-Version: user-login-log\n"
4
  "Report-Msgid-Bugs-To: \n"
5
  "POT-Creation-Date: 2013-05-10 10:07+0900\n"
6
- "PO-Revision-Date: 2013-05-10 12:25+0900\n"
7
  "Last-Translator: wokamoto <wokamoto1973@gmail.com>\n"
8
  "Language-Team: JAPANESE <http://wppluginsj.sourceforge.jp/>\n"
9
  "Language: ja_JP\n"
@@ -13,6 +13,7 @@ msgstr ""
13
  "X-Poedit-SourceCharset: utf-8\n"
14
  "X-Poedit-KeywordsList: __;_e\n"
15
  "X-Poedit-Basepath: .\n"
 
16
  "X-Poedit-SearchPath-0: ..\n"
17
 
18
  msgid "Crazy Bone"
@@ -133,3 +134,15 @@ msgstr "エラー"
133
 
134
  msgid "All Users"
135
  msgstr "全て"
 
 
 
 
 
 
 
 
 
 
 
 
3
  "Project-Id-Version: user-login-log\n"
4
  "Report-Msgid-Bugs-To: \n"
5
  "POT-Creation-Date: 2013-05-10 10:07+0900\n"
6
+ "PO-Revision-Date: 2013-05-16 09:56+0900\n"
7
  "Last-Translator: wokamoto <wokamoto1973@gmail.com>\n"
8
  "Language-Team: JAPANESE <http://wppluginsj.sourceforge.jp/>\n"
9
  "Language: ja_JP\n"
13
  "X-Poedit-SourceCharset: utf-8\n"
14
  "X-Poedit-KeywordsList: __;_e\n"
15
  "X-Poedit-Basepath: .\n"
16
+ "X-Generator: Poedit 1.5.5\n"
17
  "X-Poedit-SearchPath-0: ..\n"
18
 
19
  msgid "Crazy Bone"
134
 
135
  msgid "All Users"
136
  msgstr "全て"
137
+
138
+ msgid "Caution!"
139
+ msgstr "警告!"
140
+
141
+ msgid "Someone has logged in from another IP."
142
+ msgstr "他のIPアドレスからログインされました"
143
+
144
+ msgid "The someone's IP address :"
145
+ msgstr "ログインしてきた IP アドレス:"
146
+
147
+ msgid "Your current IP address :"
148
+ msgstr "現在の IP アドレス:"
languages/user-login-log.pot CHANGED
@@ -123,4 +123,16 @@ msgid "Errors"
123
  msgstr ""
124
 
125
  msgid "All Users"
126
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
123
  msgstr ""
124
 
125
  msgid "All Users"
126
+ msgstr ""
127
+
128
+ msgid "Caution!"
129
+ msgstr ""
130
+
131
+ msgid "Someone has logged in from another IP."
132
+ msgstr ""
133
+
134
+ msgid "The someone's IP address :"
135
+ msgstr ""
136
+
137
+ msgid "Your current IP address :"
138
+ msgstr ""
plugin.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Crazy Bone
4
  Plugin URI:
5
  Description: Tracks user name, time of login, IP address and browser user agent.
6
  Author: wokamoto
7
- Version: 0.1.2
8
  Author URI: http://dogmap.jp/
9
  Text Domain: user-login-log
10
  Domain Path: /languages/
@@ -13,7 +13,7 @@ License:
13
  Released under the GPL license
14
  http://www.gnu.org/copyleft/gpl.html
15
 
16
- Copyright 2012 (email : wokamoto1973@gmail.com)
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License as published by
@@ -38,9 +38,9 @@ load_plugin_textdomain(user_login_log::TEXT_DOMAIN, false, dirname(plugin_basena
38
 
39
  class user_login_log {
40
  const USER_META_KEY = 'user_login_log';
41
- const DEBUG_MODE = true;
42
  const TEXT_DOMAIN = 'user-login-log';
43
  const LIST_PER_PAGE = 20;
 
44
 
45
  const SEC_MINUITE = 60;
46
  const SEC_HOUR = 3600;
@@ -50,23 +50,33 @@ class user_login_log {
50
 
51
  private $ull_table = 'user_login_log';
52
  private $admin_action;
 
53
 
54
  function __construct(){
55
  global $wpdb;
56
 
57
  $this->ull_table = $wpdb->prefix.$this->ull_table;
 
 
 
 
58
 
59
  add_action('wp_login', array(&$this, 'user_login_log'), 10, 2);
60
  add_action('wp_authenticate', array(&$this, 'wp_authenticate_log'), 10, 2);
61
  add_action('login_form_logout', array(&$this, 'user_logout_log'));
62
 
 
 
 
63
  add_action('admin_bar_init', array(&$this, 'admin_bar_init'), 9999);
64
- add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
65
  add_action('admin_menu', array(&$this,'add_admin_menu'));
66
 
67
  add_action('wp_ajax_ull_info', array(&$this, 'ajax_info'));
68
  add_action('wp_ajax_nopriv_ull_info', array(&$this, 'ajax_info'));
69
 
 
 
 
70
  register_activation_hook(__FILE__, array(&$this, 'activate'));
71
  register_deactivation_hook(__FILE__, array(&$this, 'deactivate'));
72
  }
@@ -105,14 +115,21 @@ CREATE TABLE `{$this->ull_table}` (
105
  }
106
  }
107
 
108
- public function admin_bar_init() {
109
- add_action('admin_bar_menu', array(&$this, 'customize_admin_bar_menu'), 9999);
110
- wp_enqueue_style('user_login_log', plugins_url('css/user_login_log.css', __FILE__), array(), '20130508');
 
 
111
  wp_enqueue_script('jquery');
 
112
  }
113
 
114
- public function enqueue_scripts(){
115
- wp_enqueue_script('jquery');
 
 
 
 
116
  }
117
 
118
  public function customize_admin_bar_menu($wp_admin_bar){
@@ -127,12 +144,9 @@ CREATE TABLE `{$this->ull_table}` (
127
  'meta' => array(),
128
  'href' => $this->admin_action,
129
  ));
130
-
131
- add_action('admin_footer', array(&$this, 'footer_js'));
132
- add_action('wp_footer', array(&$this, 'footer_js'));
133
  }
134
 
135
- private function login_info() {
136
  $user = wp_get_current_user();
137
  if (is_wp_error($user))
138
  return false;
@@ -145,6 +159,19 @@ CREATE TABLE `{$this->ull_table}` (
145
  $ip = isset($login_log['IP']) ? $login_log['IP'] : '';
146
  $ua = isset($login_log['User Agent']) ? $login_log['User Agent'] : '';
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  list($browser_name, $browser_code, $browser_ver, $os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver) = $this->detect_browser($ua);
149
  list($country_name, $country_code) = $this->detect_country($ip);
150
 
@@ -241,18 +268,58 @@ CREATE TABLE `{$this->ull_table}` (
241
  }
242
 
243
  public function ajax_info(){
244
- $content = $this->login_info();
 
 
 
 
245
  if ($content === false)
246
  wp_die('Not logged in.');
247
 
 
 
 
248
  header('Content-Type: application/json; charset='.get_option('blog_charset'));
249
- echo json_encode(array('content' => $content));
 
 
 
 
 
 
 
 
250
  die();
251
  }
252
 
 
 
 
 
 
 
 
 
 
 
253
  public function footer_js(){
254
  if (!is_user_logged_in())
255
  return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  ?>
257
  <script type="text/javascript">
258
  function get_ull_info() {
@@ -261,17 +328,29 @@ function get_ull_info() {
261
  cache: false,
262
  dataType: 'json',
263
  type: 'POST',
264
- success: function(response){
265
- <?php if (self::DEBUG_MODE) echo "console.log(response);\n" ?>
266
- jQuery('#wp-admin-bar-user-login-log a').html(response.content);
267
- setTimeout('get_ull_info()', 30000);
 
 
 
 
 
 
 
 
 
 
 
 
268
  },
269
  error: function(){
270
  setTimeout('get_ull_info()', 10000);
271
  }
272
  });
273
  }
274
- jQuery(function(){setTimeout('get_ull_info()', 30000);});
275
  </script>
276
  <?php
277
  }
@@ -282,7 +361,6 @@ jQuery(function(){setTimeout('get_ull_info()', 30000);});
282
  $page_title = __('Login Log', self::TEXT_DOMAIN);
283
  $menu_title = $page_title;
284
  $file = plugin_basename(__FILE__);
285
- $this->admin_action = admin_url($parent) . '?page=' . plugin_basename(__FILE__);
286
  $this->add_submenu_page(
287
  $parent,
288
  $page_title,
4
  Plugin URI:
5
  Description: Tracks user name, time of login, IP address and browser user agent.
6
  Author: wokamoto
7
+ Version: 0.2.0
8
  Author URI: http://dogmap.jp/
9
  Text Domain: user-login-log
10
  Domain Path: /languages/
13
  Released under the GPL license
14
  http://www.gnu.org/copyleft/gpl.html
15
 
16
+ Copyright 2013 (email : wokamoto1973@gmail.com)
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License as published by
38
 
39
  class user_login_log {
40
  const USER_META_KEY = 'user_login_log';
 
41
  const TEXT_DOMAIN = 'user-login-log';
42
  const LIST_PER_PAGE = 20;
43
+ const DEBUG_MODE = false;
44
 
45
  const SEC_MINUITE = 60;
46
  const SEC_HOUR = 3600;
50
 
51
  private $ull_table = 'user_login_log';
52
  private $admin_action;
53
+ private $plugin_version;
54
 
55
  function __construct(){
56
  global $wpdb;
57
 
58
  $this->ull_table = $wpdb->prefix.$this->ull_table;
59
+ $this->admin_action = admin_url('profile.php') . '?page=' . plugin_basename(__FILE__);
60
+
61
+ $data = get_file_data(__FILE__, array('version' => 'Version'));
62
+ $this->plugin_version = isset($data['version']) ? $data['version'] : '';
63
 
64
  add_action('wp_login', array(&$this, 'user_login_log'), 10, 2);
65
  add_action('wp_authenticate', array(&$this, 'wp_authenticate_log'), 10, 2);
66
  add_action('login_form_logout', array(&$this, 'user_logout_log'));
67
 
68
+ add_action('admin_enqueue_scripts', array(&$this,'enqueue_scripts'));
69
+ add_action('wp_enqueue_scripts', array(&$this,'enqueue_scripts'));
70
+
71
  add_action('admin_bar_init', array(&$this, 'admin_bar_init'), 9999);
 
72
  add_action('admin_menu', array(&$this,'add_admin_menu'));
73
 
74
  add_action('wp_ajax_ull_info', array(&$this, 'ajax_info'));
75
  add_action('wp_ajax_nopriv_ull_info', array(&$this, 'ajax_info'));
76
 
77
+ add_action('wp_ajax_dismiss-ull-wp-pointer', array(&$this, 'ajax_dismiss'));
78
+ add_action('wp_ajax_nopriv_dismiss-ull-wp-pointer', array(&$this, 'ajax_dismiss'));
79
+
80
  register_activation_hook(__FILE__, array(&$this, 'activate'));
81
  register_deactivation_hook(__FILE__, array(&$this, 'deactivate'));
82
  }
115
  }
116
  }
117
 
118
+ public function enqueue_scripts(){
119
+ if (!is_user_logged_in())
120
+ return;
121
+
122
+ wp_enqueue_style('wp-pointer');
123
  wp_enqueue_script('jquery');
124
+ wp_enqueue_script('wp-pointer', array('jquery'));
125
  }
126
 
127
+ public function admin_bar_init() {
128
+ add_action('admin_bar_menu', array(&$this, 'customize_admin_bar_menu'), 9999);
129
+ wp_enqueue_style('user_login_log', plugins_url('css/user_login_log.css', __FILE__), array(), $this->plugin_version);
130
+
131
+ add_action('admin_footer', array(&$this, 'footer_js'));
132
+ add_action('wp_footer', array(&$this, 'footer_js'));
133
  }
134
 
135
  public function customize_admin_bar_menu($wp_admin_bar){
144
  'meta' => array(),
145
  'href' => $this->admin_action,
146
  ));
 
 
 
147
  }
148
 
149
+ private function last_login_info() {
150
  $user = wp_get_current_user();
151
  if (is_wp_error($user))
152
  return false;
159
  $ip = isset($login_log['IP']) ? $login_log['IP'] : '';
160
  $ua = isset($login_log['User Agent']) ? $login_log['User Agent'] : '';
161
 
162
+ return array('date' => $date, 'ip' => $ip, 'ua' => $ua);
163
+ }
164
+
165
+ private function login_info($args = '') {
166
+ $user = wp_get_current_user();
167
+ if (is_wp_error($user))
168
+ return false;
169
+ if (empty($args))
170
+ $args = $this->last_login_info();
171
+ $date = isset($args['date']) ? $args['date'] : $this->time();
172
+ $ip = isset($args['ip']) ? $args['ip'] : $this->ip();
173
+ $ua = isset($args['ua']) ? $args['ua'] : $this->ua();
174
+
175
  list($browser_name, $browser_code, $browser_ver, $os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver) = $this->detect_browser($ua);
176
  list($country_name, $country_code) = $this->detect_country($ip);
177
 
268
  }
269
 
270
  public function ajax_info(){
271
+ if (!is_user_logged_in())
272
+ return;
273
+
274
+ $args = $this->last_login_info();
275
+ $content = $this->login_info($args);
276
  if ($content === false)
277
  wp_die('Not logged in.');
278
 
279
+ $transient_key = 'ull-dismiss-'.md5($this->ip().(isset($args['ip']) ? $args['ip'] : ''));
280
+ $dismiss = get_transient($transient_key);
281
+
282
  header('Content-Type: application/json; charset='.get_option('blog_charset'));
283
+ echo json_encode(array(
284
+ 'content' => $content,
285
+ 'login_IP' => isset($args['ip']) ? $args['ip'] : '',
286
+ 'login_country' => isset($args['ip']) ? $this->get_country_flag($args['ip']) : '',
287
+ 'login_time' => isset($args['date']) ? $this->nice_time($args['date']) : '',
288
+ 'IP' => $this->ip(),
289
+ 'country' => $this->get_country_flag($this->ip()),
290
+ 'dismiss' => $dismiss,
291
+ ));
292
  die();
293
  }
294
 
295
+ public function ajax_dismiss(){
296
+ if (!is_user_logged_in())
297
+ return;
298
+
299
+ $args = $this->last_login_info();
300
+ $transient_key = 'ull-dismiss-'.md5($this->ip().(isset($args['ip']) ? $args['ip'] : ''));
301
+ set_transient($transient_key, TRUE, 60 * 60);
302
+ die();
303
+ }
304
+
305
  public function footer_js(){
306
  if (!is_user_logged_in())
307
  return;
308
+
309
+ $args = $this->last_login_info();
310
+ $transient_key = 'ull-dismiss-'.md5($this->ip().(isset($args['ip']) ? $args['ip'] : ''));
311
+ $dismiss = get_transient($transient_key);
312
+ $caution = sprintf(
313
+ "<h3>%s</h3><p>%s (' + res.login_time + ')</p>".
314
+ "<p>".
315
+ "%s' + res.login_country + '<strong>' + res.login_IP + '</strong><br/>".
316
+ "%s' + res.country + '<strong>' + res.IP + '</strong>".
317
+ "</p>",
318
+ __('Caution!', self::TEXT_DOMAIN),
319
+ __('Someone has logged in from another IP.', self::TEXT_DOMAIN),
320
+ __("The someone's IP address :", self::TEXT_DOMAIN),
321
+ __('Your current IP address :', self::TEXT_DOMAIN)
322
+ );
323
  ?>
324
  <script type="text/javascript">
325
  function get_ull_info() {
328
  cache: false,
329
  dataType: 'json',
330
  type: 'POST',
331
+ success: function(res){
332
+ <?php if (self::DEBUG_MODE) echo "\t\t\tconsole.log(res);\n" ?>
333
+ if (!res.dismiss && res.IP !== res.login_IP) {
334
+ jQuery('#wp-admin-bar-my-account').pointer({
335
+ content: '<?php echo $caution; ?>',
336
+ close: function(){
337
+ jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', {
338
+ action: 'dismiss-ull-wp-pointer',
339
+ });
340
+ setTimeout('get_ull_info()', 30000);
341
+ }
342
+ }).pointer('open');
343
+ } else {
344
+ setTimeout('get_ull_info()', 30000);
345
+ }
346
+ jQuery('#wp-admin-bar-user-login-log a').html(res.content);
347
  },
348
  error: function(){
349
  setTimeout('get_ull_info()', 10000);
350
  }
351
  });
352
  }
353
+ jQuery(function(){setTimeout('get_ull_info()', 10000);});
354
  </script>
355
  <?php
356
  }
361
  $page_title = __('Login Log', self::TEXT_DOMAIN);
362
  $menu_title = $page_title;
363
  $file = plugin_basename(__FILE__);
 
364
  $this->add_submenu_page(
365
  $parent,
366
  $page_title,
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=9S8AJ
4
  Tags: log, login, users
5
  Requires at least: 3.5
6
  Tested up to: 3.5.1
7
- Stable tag: 0.1.2
8
 
9
  Tracks user name, time of login, IP address and browser user agent.
10
 
4
  Tags: log, login, users
5
  Requires at least: 3.5
6
  Tested up to: 3.5.1
7
+ Stable tag: 0.2.0
8
 
9
  Tracks user name, time of login, IP address and browser user agent.
10