Version Description
(2015-08-05) = * Minor Change * Launched a new WP Security Audit Log website and updated all relevant links.
Download this release
Release Info
Developer | WPWhiteSecurity |
Plugin | WP Security Audit Log |
Version | 2.0.1 |
Comparing to | |
See all releases |
Code changes from version 2.0.0 to 2.0.1
- classes/Connector/AbstractConnector.php +36 -36
- classes/Connector/ConnectorFactory.php +77 -77
- classes/Connector/ConnectorInterface.php +11 -11
- classes/Connector/MySQLDBConnector.php +134 -134
- classes/EDD_SL_Plugin_Updater.php +170 -170
- classes/Helpers/DataHelper.php +22 -22
- classes/LicenseManager.php +1 -1
- classes/Models/ActiveRecord.php +267 -267
- classes/Models/Adapters/ActiveRecordInterface.php +15 -15
- classes/Models/Adapters/MetaInterface.php +13 -13
- classes/Models/Adapters/MySQL/ActiveRecordAdapter.php +460 -460
- classes/Models/Adapters/MySQL/MetaAdapter.php +49 -49
- classes/Models/Adapters/MySQL/OccurrenceAdapter.php +170 -170
- classes/Models/Adapters/MySQL/OptionAdapter.php +80 -80
- classes/Models/Adapters/MySQL/QueryAdapter.php +216 -216
- classes/Models/Adapters/OccurrenceInterface.php +11 -11
- classes/Models/Adapters/QueryInterface.php +8 -8
- classes/Models/Meta.php +34 -34
- classes/Models/Occurrence.php +193 -193
- classes/Models/OccurrenceQuery.php +29 -29
- classes/Models/Option.php +80 -80
- classes/Models/Query.php +187 -187
- classes/Sensors/Database.php +130 -130
- classes/Views/About.php +4 -5
- classes/Views/AuditLog.php +1 -1
- classes/Views/Extensions.php +12 -12
- classes/Views/Help.php +9 -31
- classes/Views/Settings.php +3 -3
- css/install-error.css +41 -41
- css/settings.css +70 -70
- js/auditlog.js +149 -149
- js/common.js +14 -14
- js/nice_r.js +11 -11
- js/settings.js +73 -73
- languages/wp-security-audit-log-sr_RS.mo +0 -0
- readme.txt +33 -31
- wp-security-audit-log.php +3 -3
classes/Connector/AbstractConnector.php
CHANGED
@@ -1,36 +1,36 @@
|
|
1 |
-
<?php
|
2 |
-
require_once('ConnectorInterface.php');
|
3 |
-
|
4 |
-
abstract class WSAL_Connector_AbstractConnector
|
5 |
-
{
|
6 |
-
protected $connection = null;
|
7 |
-
protected $adaptersBasePath = null;
|
8 |
-
protected $adaptersDirName = null;
|
9 |
-
|
10 |
-
public function __construct($adaptersDirName = null)
|
11 |
-
{
|
12 |
-
$this->adaptersBasePath = __DIR__ . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'Models'. DIRECTORY_SEPARATOR .'Adapters'. DIRECTORY_SEPARATOR;
|
13 |
-
|
14 |
-
require_once($this->adaptersBasePath . 'ActiveRecordInterface.php');
|
15 |
-
require_once($this->adaptersBasePath . 'MetaInterface.php');
|
16 |
-
require_once($this->adaptersBasePath . 'OccurrenceInterface.php');
|
17 |
-
require_once($this->adaptersBasePath . 'QueryInterface.php');
|
18 |
-
|
19 |
-
if (!empty($adaptersDirName)) {
|
20 |
-
$this->adaptersDirName = $adaptersDirName;
|
21 |
-
require_once($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . 'ActiveRecordAdapter.php');
|
22 |
-
require_once($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . 'MetaAdapter.php');
|
23 |
-
require_once($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . 'OccurrenceAdapter.php');
|
24 |
-
require_once($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . 'QueryAdapter.php');
|
25 |
-
}
|
26 |
-
}
|
27 |
-
|
28 |
-
public function getAdaptersDirectory()
|
29 |
-
{
|
30 |
-
if (!empty($this->adaptersBasePath) && !empty($this->adaptersDirName)) {
|
31 |
-
return $this->adaptersBasePath . $this->adaptersDirName;
|
32 |
-
} else {
|
33 |
-
return false;
|
34 |
-
}
|
35 |
-
}
|
36 |
-
}
|
1 |
+
<?php
|
2 |
+
require_once('ConnectorInterface.php');
|
3 |
+
|
4 |
+
abstract class WSAL_Connector_AbstractConnector
|
5 |
+
{
|
6 |
+
protected $connection = null;
|
7 |
+
protected $adaptersBasePath = null;
|
8 |
+
protected $adaptersDirName = null;
|
9 |
+
|
10 |
+
public function __construct($adaptersDirName = null)
|
11 |
+
{
|
12 |
+
$this->adaptersBasePath = __DIR__ . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'Models'. DIRECTORY_SEPARATOR .'Adapters'. DIRECTORY_SEPARATOR;
|
13 |
+
|
14 |
+
require_once($this->adaptersBasePath . 'ActiveRecordInterface.php');
|
15 |
+
require_once($this->adaptersBasePath . 'MetaInterface.php');
|
16 |
+
require_once($this->adaptersBasePath . 'OccurrenceInterface.php');
|
17 |
+
require_once($this->adaptersBasePath . 'QueryInterface.php');
|
18 |
+
|
19 |
+
if (!empty($adaptersDirName)) {
|
20 |
+
$this->adaptersDirName = $adaptersDirName;
|
21 |
+
require_once($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . 'ActiveRecordAdapter.php');
|
22 |
+
require_once($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . 'MetaAdapter.php');
|
23 |
+
require_once($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . 'OccurrenceAdapter.php');
|
24 |
+
require_once($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . 'QueryAdapter.php');
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
public function getAdaptersDirectory()
|
29 |
+
{
|
30 |
+
if (!empty($this->adaptersBasePath) && !empty($this->adaptersDirName)) {
|
31 |
+
return $this->adaptersBasePath . $this->adaptersDirName;
|
32 |
+
} else {
|
33 |
+
return false;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
}
|
classes/Connector/ConnectorFactory.php
CHANGED
@@ -1,77 +1,77 @@
|
|
1 |
-
<?php
|
2 |
-
require_once(__DIR__ . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'Settings.php');
|
3 |
-
require_once('MySQLDBConnector.php');
|
4 |
-
|
5 |
-
abstract class WSAL_Connector_ConnectorFactory
|
6 |
-
{
|
7 |
-
public static $connector;
|
8 |
-
public static $defaultConnector;
|
9 |
-
public static $adapter;
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Returns the a default WPDB connector for saving options
|
13 |
-
*/
|
14 |
-
public static function GetDefaultConnector()
|
15 |
-
{
|
16 |
-
return new WSAL_Connector_MySQLDB();
|
17 |
-
}
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Returns a connector singleton
|
21 |
-
* @return WSAL_Connector_ConnectorInterface
|
22 |
-
*/
|
23 |
-
public static function GetConnector()
|
24 |
-
{
|
25 |
-
$connectionConfig = self::GetConfig();
|
26 |
-
//TO DO: Load connection config
|
27 |
-
|
28 |
-
if (self::$connector == null) {
|
29 |
-
switch (strtolower($connectionConfig['type'])) {
|
30 |
-
//TO DO: Add other connectors
|
31 |
-
case 'mysql':
|
32 |
-
default:
|
33 |
-
//use config
|
34 |
-
self::$connector = new WSAL_Connector_MySQLDB($connectionConfig);
|
35 |
-
}
|
36 |
-
}
|
37 |
-
return self::$connector;
|
38 |
-
}
|
39 |
-
|
40 |
-
public static function GetConfig()
|
41 |
-
{
|
42 |
-
$conf = new WSAL_Settings(new WpSecurityAuditLog());
|
43 |
-
$type = $conf->GetAdapterConfig('adapter-type');
|
44 |
-
if (empty($type)) {
|
45 |
-
return null;
|
46 |
-
} else {
|
47 |
-
return array(
|
48 |
-
'type' => $conf->GetAdapterConfig('adapter-type'),
|
49 |
-
'user' => $conf->GetAdapterConfig('adapter-user'),
|
50 |
-
'password' => $conf->GetAdapterConfig('adapter-password'),
|
51 |
-
'name' => $conf->GetAdapterConfig('adapter-name'),
|
52 |
-
'hostname' => $conf->GetAdapterConfig('adapter-hostname'),
|
53 |
-
'base_prefix' => $conf->GetAdapterConfig('adapter-base-prefix')
|
54 |
-
);
|
55 |
-
}
|
56 |
-
}
|
57 |
-
|
58 |
-
public static function CheckConfig($type, $user, $password, $name, $hostname, $base_prefix)
|
59 |
-
{
|
60 |
-
$result = false;
|
61 |
-
$config = array(
|
62 |
-
'user' => $user,
|
63 |
-
'password' => $password,
|
64 |
-
'name' => $name,
|
65 |
-
'hostname' => $hostname,
|
66 |
-
'base_prefix' => $base_prefix
|
67 |
-
);
|
68 |
-
switch (strtolower($type)) {
|
69 |
-
//TO DO: Add other connectors
|
70 |
-
case 'mysql':
|
71 |
-
default:
|
72 |
-
$test = new WSAL_Connector_MySQLDB($config);
|
73 |
-
$result = $test->TestConnection();
|
74 |
-
}
|
75 |
-
return $result;
|
76 |
-
}
|
77 |
-
}
|
1 |
+
<?php
|
2 |
+
require_once(__DIR__ . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'Settings.php');
|
3 |
+
require_once('MySQLDBConnector.php');
|
4 |
+
|
5 |
+
abstract class WSAL_Connector_ConnectorFactory
|
6 |
+
{
|
7 |
+
public static $connector;
|
8 |
+
public static $defaultConnector;
|
9 |
+
public static $adapter;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Returns the a default WPDB connector for saving options
|
13 |
+
*/
|
14 |
+
public static function GetDefaultConnector()
|
15 |
+
{
|
16 |
+
return new WSAL_Connector_MySQLDB();
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Returns a connector singleton
|
21 |
+
* @return WSAL_Connector_ConnectorInterface
|
22 |
+
*/
|
23 |
+
public static function GetConnector()
|
24 |
+
{
|
25 |
+
$connectionConfig = self::GetConfig();
|
26 |
+
//TO DO: Load connection config
|
27 |
+
|
28 |
+
if (self::$connector == null) {
|
29 |
+
switch (strtolower($connectionConfig['type'])) {
|
30 |
+
//TO DO: Add other connectors
|
31 |
+
case 'mysql':
|
32 |
+
default:
|
33 |
+
//use config
|
34 |
+
self::$connector = new WSAL_Connector_MySQLDB($connectionConfig);
|
35 |
+
}
|
36 |
+
}
|
37 |
+
return self::$connector;
|
38 |
+
}
|
39 |
+
|
40 |
+
public static function GetConfig()
|
41 |
+
{
|
42 |
+
$conf = new WSAL_Settings(new WpSecurityAuditLog());
|
43 |
+
$type = $conf->GetAdapterConfig('adapter-type');
|
44 |
+
if (empty($type)) {
|
45 |
+
return null;
|
46 |
+
} else {
|
47 |
+
return array(
|
48 |
+
'type' => $conf->GetAdapterConfig('adapter-type'),
|
49 |
+
'user' => $conf->GetAdapterConfig('adapter-user'),
|
50 |
+
'password' => $conf->GetAdapterConfig('adapter-password'),
|
51 |
+
'name' => $conf->GetAdapterConfig('adapter-name'),
|
52 |
+
'hostname' => $conf->GetAdapterConfig('adapter-hostname'),
|
53 |
+
'base_prefix' => $conf->GetAdapterConfig('adapter-base-prefix')
|
54 |
+
);
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
public static function CheckConfig($type, $user, $password, $name, $hostname, $base_prefix)
|
59 |
+
{
|
60 |
+
$result = false;
|
61 |
+
$config = array(
|
62 |
+
'user' => $user,
|
63 |
+
'password' => $password,
|
64 |
+
'name' => $name,
|
65 |
+
'hostname' => $hostname,
|
66 |
+
'base_prefix' => $base_prefix
|
67 |
+
);
|
68 |
+
switch (strtolower($type)) {
|
69 |
+
//TO DO: Add other connectors
|
70 |
+
case 'mysql':
|
71 |
+
default:
|
72 |
+
$test = new WSAL_Connector_MySQLDB($config);
|
73 |
+
$result = $test->TestConnection();
|
74 |
+
}
|
75 |
+
return $result;
|
76 |
+
}
|
77 |
+
}
|
classes/Connector/ConnectorInterface.php
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
interface WSAL_Connector_ConnectorInterface
|
4 |
-
{
|
5 |
-
public function getAdapter($class_name);
|
6 |
-
public function getConnection();
|
7 |
-
public function isInstalled();
|
8 |
-
public function canMigrate();
|
9 |
-
public function installAll();
|
10 |
-
public function uninstallAll();
|
11 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
interface WSAL_Connector_ConnectorInterface
|
4 |
+
{
|
5 |
+
public function getAdapter($class_name);
|
6 |
+
public function getConnection();
|
7 |
+
public function isInstalled();
|
8 |
+
public function canMigrate();
|
9 |
+
public function installAll();
|
10 |
+
public function uninstallAll();
|
11 |
+
}
|
classes/Connector/MySQLDBConnector.php
CHANGED
@@ -1,134 +1,134 @@
|
|
1 |
-
<?php
|
2 |
-
require_once('ConnectorInterface.php');
|
3 |
-
require_once('AbstractConnector.php');
|
4 |
-
|
5 |
-
|
6 |
-
class WSAL_Connector_MySQLDB extends WSAL_Connector_AbstractConnector implements WSAL_Connector_ConnectorInterface
|
7 |
-
{
|
8 |
-
protected $connectionConfig = null;
|
9 |
-
public function __construct($connectionConfig = null)
|
10 |
-
{
|
11 |
-
$this->connectionConfig = $connectionConfig;
|
12 |
-
parent::__construct("MySQL");
|
13 |
-
require_once($this->getAdaptersDirectory() . '/OptionAdapter.php');
|
14 |
-
}
|
15 |
-
|
16 |
-
function test_wp_die_callback() {
|
17 |
-
return array( $this, 'test_die_handler' );
|
18 |
-
}
|
19 |
-
|
20 |
-
function test_die_handler( $message, $title = '', $args = array() ) {
|
21 |
-
throw new Exception("DB Connection failed");
|
22 |
-
}
|
23 |
-
|
24 |
-
public function TestConnection()
|
25 |
-
{
|
26 |
-
error_reporting(E_ALL ^ E_WARNING);
|
27 |
-
add_filter( 'wp_die_handler', array( $this, 'test_wp_die_callback' ) );
|
28 |
-
$connection = $this->createConnection();
|
29 |
-
}
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Creates a connection and returns it
|
33 |
-
* @return Instance of WPDB
|
34 |
-
*/
|
35 |
-
private function createConnection()
|
36 |
-
{
|
37 |
-
if (!empty($this->connectionConfig)) {
|
38 |
-
//TO DO: Use the provided connection config
|
39 |
-
$connectionConfig = $this->connectionConfig;
|
40 |
-
$newWpdb = new wpdb($connectionConfig['user'], $connectionConfig['password'], $connectionConfig['name'], $connectionConfig['hostname']);
|
41 |
-
$newWpdb->set_prefix($connectionConfig['base_prefix']);
|
42 |
-
return $newWpdb;
|
43 |
-
} else {
|
44 |
-
global $wpdb;
|
45 |
-
return $wpdb;
|
46 |
-
}
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Returns a wpdb instance
|
51 |
-
*/
|
52 |
-
public function getConnection()
|
53 |
-
{
|
54 |
-
if (!empty($this->connection)) {
|
55 |
-
return $this->connection;
|
56 |
-
} else {
|
57 |
-
$this->connection = $this->createConnection();
|
58 |
-
return $this->connection;
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Gets an adapter for the specified model
|
64 |
-
*/
|
65 |
-
public function getAdapter($class_name)
|
66 |
-
{
|
67 |
-
$objName = $this->getAdapterClassName($class_name);
|
68 |
-
return new $objName($this->getConnection());
|
69 |
-
}
|
70 |
-
|
71 |
-
protected function getAdapterClassName($class_name)
|
72 |
-
{
|
73 |
-
return 'WSAL_Adapters_MySQL_'.$class_name;
|
74 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* Checks if the necessary tables are available
|
78 |
-
*/
|
79 |
-
public function isInstalled()
|
80 |
-
{
|
81 |
-
$wpdb = $this->getConnection();
|
82 |
-
$table = $wpdb->base_prefix . 'wsal_occurrences';
|
83 |
-
return ($wpdb->get_var('SHOW TABLES LIKE "'.$table.'"') == $table);
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Checks if old version tables are available
|
88 |
-
*/
|
89 |
-
public function canMigrate()
|
90 |
-
{
|
91 |
-
$wpdb = $this->getConnection();
|
92 |
-
$table = $wpdb->base_prefix . 'wordpress_auditlog_events';
|
93 |
-
return ($wpdb->get_var('SHOW TABLES LIKE "'.$table.'"') == $table);
|
94 |
-
}
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Install all DB tables.
|
98 |
-
*/
|
99 |
-
public function installAll()
|
100 |
-
{
|
101 |
-
$plugin = WpSecurityAuditLog::GetInstance();
|
102 |
-
|
103 |
-
foreach (glob($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . '*.php') as $file) {
|
104 |
-
$filePath = explode(DIRECTORY_SEPARATOR, $file);
|
105 |
-
$fileName = $filePath[count($filePath) - 1];
|
106 |
-
$className = $this->getAdapterClassName(str_replace("Adapter.php", "", $fileName));
|
107 |
-
|
108 |
-
$class = new $className($this->getConnection());
|
109 |
-
if (is_subclass_of($class, "WSAL_Adapters_MySQL_ActiveRecord")) {
|
110 |
-
$class->Install();
|
111 |
-
}
|
112 |
-
}
|
113 |
-
}
|
114 |
-
|
115 |
-
/**
|
116 |
-
* Uninstall all DB tables.
|
117 |
-
*/
|
118 |
-
public function uninstallAll()
|
119 |
-
{
|
120 |
-
$plugin = WpSecurityAuditLog::GetInstance();
|
121 |
-
|
122 |
-
foreach (glob($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . '*.php') as $file) {
|
123 |
-
$filePath = explode(DIRECTORY_SEPARATOR, $file);
|
124 |
-
$fileName = $filePath[count($filePath) - 1];
|
125 |
-
$className = $this->getAdapterClassName(str_replace("Adapter.php", "", $fileName));
|
126 |
-
|
127 |
-
$class = new $className($this->getConnection());
|
128 |
-
if (is_subclass_of($class, "WSAL_Adapters_MySQL_ActiveRecord")) {
|
129 |
-
$class->Uninstall();
|
130 |
-
}
|
131 |
-
}
|
132 |
-
}
|
133 |
-
|
134 |
-
}
|
1 |
+
<?php
|
2 |
+
require_once('ConnectorInterface.php');
|
3 |
+
require_once('AbstractConnector.php');
|
4 |
+
|
5 |
+
|
6 |
+
class WSAL_Connector_MySQLDB extends WSAL_Connector_AbstractConnector implements WSAL_Connector_ConnectorInterface
|
7 |
+
{
|
8 |
+
protected $connectionConfig = null;
|
9 |
+
public function __construct($connectionConfig = null)
|
10 |
+
{
|
11 |
+
$this->connectionConfig = $connectionConfig;
|
12 |
+
parent::__construct("MySQL");
|
13 |
+
require_once($this->getAdaptersDirectory() . '/OptionAdapter.php');
|
14 |
+
}
|
15 |
+
|
16 |
+
function test_wp_die_callback() {
|
17 |
+
return array( $this, 'test_die_handler' );
|
18 |
+
}
|
19 |
+
|
20 |
+
function test_die_handler( $message, $title = '', $args = array() ) {
|
21 |
+
throw new Exception("DB Connection failed");
|
22 |
+
}
|
23 |
+
|
24 |
+
public function TestConnection()
|
25 |
+
{
|
26 |
+
error_reporting(E_ALL ^ E_WARNING);
|
27 |
+
add_filter( 'wp_die_handler', array( $this, 'test_wp_die_callback' ) );
|
28 |
+
$connection = $this->createConnection();
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Creates a connection and returns it
|
33 |
+
* @return Instance of WPDB
|
34 |
+
*/
|
35 |
+
private function createConnection()
|
36 |
+
{
|
37 |
+
if (!empty($this->connectionConfig)) {
|
38 |
+
//TO DO: Use the provided connection config
|
39 |
+
$connectionConfig = $this->connectionConfig;
|
40 |
+
$newWpdb = new wpdb($connectionConfig['user'], $connectionConfig['password'], $connectionConfig['name'], $connectionConfig['hostname']);
|
41 |
+
$newWpdb->set_prefix($connectionConfig['base_prefix']);
|
42 |
+
return $newWpdb;
|
43 |
+
} else {
|
44 |
+
global $wpdb;
|
45 |
+
return $wpdb;
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Returns a wpdb instance
|
51 |
+
*/
|
52 |
+
public function getConnection()
|
53 |
+
{
|
54 |
+
if (!empty($this->connection)) {
|
55 |
+
return $this->connection;
|
56 |
+
} else {
|
57 |
+
$this->connection = $this->createConnection();
|
58 |
+
return $this->connection;
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Gets an adapter for the specified model
|
64 |
+
*/
|
65 |
+
public function getAdapter($class_name)
|
66 |
+
{
|
67 |
+
$objName = $this->getAdapterClassName($class_name);
|
68 |
+
return new $objName($this->getConnection());
|
69 |
+
}
|
70 |
+
|
71 |
+
protected function getAdapterClassName($class_name)
|
72 |
+
{
|
73 |
+
return 'WSAL_Adapters_MySQL_'.$class_name;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Checks if the necessary tables are available
|
78 |
+
*/
|
79 |
+
public function isInstalled()
|
80 |
+
{
|
81 |
+
$wpdb = $this->getConnection();
|
82 |
+
$table = $wpdb->base_prefix . 'wsal_occurrences';
|
83 |
+
return ($wpdb->get_var('SHOW TABLES LIKE "'.$table.'"') == $table);
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Checks if old version tables are available
|
88 |
+
*/
|
89 |
+
public function canMigrate()
|
90 |
+
{
|
91 |
+
$wpdb = $this->getConnection();
|
92 |
+
$table = $wpdb->base_prefix . 'wordpress_auditlog_events';
|
93 |
+
return ($wpdb->get_var('SHOW TABLES LIKE "'.$table.'"') == $table);
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Install all DB tables.
|
98 |
+
*/
|
99 |
+
public function installAll()
|
100 |
+
{
|
101 |
+
$plugin = WpSecurityAuditLog::GetInstance();
|
102 |
+
|
103 |
+
foreach (glob($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . '*.php') as $file) {
|
104 |
+
$filePath = explode(DIRECTORY_SEPARATOR, $file);
|
105 |
+
$fileName = $filePath[count($filePath) - 1];
|
106 |
+
$className = $this->getAdapterClassName(str_replace("Adapter.php", "", $fileName));
|
107 |
+
|
108 |
+
$class = new $className($this->getConnection());
|
109 |
+
if (is_subclass_of($class, "WSAL_Adapters_MySQL_ActiveRecord")) {
|
110 |
+
$class->Install();
|
111 |
+
}
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Uninstall all DB tables.
|
117 |
+
*/
|
118 |
+
public function uninstallAll()
|
119 |
+
{
|
120 |
+
$plugin = WpSecurityAuditLog::GetInstance();
|
121 |
+
|
122 |
+
foreach (glob($this->getAdaptersDirectory() . DIRECTORY_SEPARATOR . '*.php') as $file) {
|
123 |
+
$filePath = explode(DIRECTORY_SEPARATOR, $file);
|
124 |
+
$fileName = $filePath[count($filePath) - 1];
|
125 |
+
$className = $this->getAdapterClassName(str_replace("Adapter.php", "", $fileName));
|
126 |
+
|
127 |
+
$class = new $className($this->getConnection());
|
128 |
+
if (is_subclass_of($class, "WSAL_Adapters_MySQL_ActiveRecord")) {
|
129 |
+
$class->Uninstall();
|
130 |
+
}
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
}
|
classes/EDD_SL_Plugin_Updater.php
CHANGED
@@ -1,170 +1,170 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// uncomment this line for testing
|
4 |
-
//set_site_transient( 'update_plugins', null );
|
5 |
-
|
6 |
-
/**
|
7 |
-
* Allows plugins to use their own update API.
|
8 |
-
*
|
9 |
-
* @author Pippin Williamson
|
10 |
-
* @version 1.2
|
11 |
-
*/
|
12 |
-
class EDD_SL_Plugin_Updater {
|
13 |
-
private $api_url = '';
|
14 |
-
private $api_data = array();
|
15 |
-
private $name = '';
|
16 |
-
private $slug = '';
|
17 |
-
private $do_check = false;
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Class constructor.
|
21 |
-
*
|
22 |
-
* @uses plugin_basename()
|
23 |
-
* @uses hook()
|
24 |
-
*
|
25 |
-
* @param string $_api_url The URL pointing to the custom API endpoint.
|
26 |
-
* @param string $_plugin_file Path to the plugin file.
|
27 |
-
* @param array $_api_data Optional data to send with API calls.
|
28 |
-
* @return void
|
29 |
-
*/
|
30 |
-
function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
|
31 |
-
$this->api_url = trailingslashit( $_api_url );
|
32 |
-
$this->api_data = urlencode_deep( $_api_data );
|
33 |
-
$this->name = plugin_basename( $_plugin_file );
|
34 |
-
$this->slug = basename( $_plugin_file, '.php');
|
35 |
-
$this->version = $_api_data['version'];
|
36 |
-
|
37 |
-
// Set up hooks.
|
38 |
-
$this->hook();
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Set up WordPress filters to hook into WP's update process.
|
43 |
-
*
|
44 |
-
* @uses add_filter()
|
45 |
-
*
|
46 |
-
* @return void
|
47 |
-
*/
|
48 |
-
private function hook() {
|
49 |
-
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'pre_set_site_transient_update_plugins_filter' ) );
|
50 |
-
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
|
51 |
-
add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 );
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Check for Updates at the defined API endpoint and modify the update array.
|
56 |
-
*
|
57 |
-
* This function dives into the update API just when WordPress creates its update array,
|
58 |
-
* then adds a custom API call and injects the custom plugin data retrieved from the API.
|
59 |
-
* It is reassembled from parts of the native WordPress plugin update code.
|
60 |
-
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
|
61 |
-
*
|
62 |
-
* @uses api_request()
|
63 |
-
*
|
64 |
-
* @param array $_transient_data Update array build by WordPress.
|
65 |
-
* @return array Modified update array with custom plugin data.
|
66 |
-
*/
|
67 |
-
function pre_set_site_transient_update_plugins_filter( $_transient_data ) {
|
68 |
-
|
69 |
-
if( empty( $_transient_data ) || ! $this->do_check ) {
|
70 |
-
|
71 |
-
// This ensures that the custom API request only runs on the second time that WP fires the update check
|
72 |
-
$this->do_check = true;
|
73 |
-
|
74 |
-
return $_transient_data;
|
75 |
-
}
|
76 |
-
|
77 |
-
$to_send = array( 'slug' => $this->slug );
|
78 |
-
|
79 |
-
$api_response = $this->api_request( 'plugin_latest_version', $to_send );
|
80 |
-
|
81 |
-
if( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) {
|
82 |
-
|
83 |
-
if( version_compare( $this->version, $api_response->new_version, '<' ) ) {
|
84 |
-
$_transient_data->response[$this->name] = $api_response;
|
85 |
-
}
|
86 |
-
}
|
87 |
-
return $_transient_data;
|
88 |
-
}
|
89 |
-
|
90 |
-
|
91 |
-
/**
|
92 |
-
* Updates information on the "View version x.x details" page with custom data.
|
93 |
-
*
|
94 |
-
* @uses api_request()
|
95 |
-
*
|
96 |
-
* @param mixed $_data
|
97 |
-
* @param string $_action
|
98 |
-
* @param object $_args
|
99 |
-
* @return object $_data
|
100 |
-
*/
|
101 |
-
function plugins_api_filter( $_data, $_action = '', $_args = null ) {
|
102 |
-
if ( ( $_action != 'plugin_information' ) || !isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) return $_data;
|
103 |
-
|
104 |
-
$to_send = array( 'slug' => $this->slug );
|
105 |
-
|
106 |
-
$api_response = $this->api_request( 'plugin_information', $to_send );
|
107 |
-
if ( false !== $api_response ) $_data = $api_response;
|
108 |
-
|
109 |
-
return $_data;
|
110 |
-
}
|
111 |
-
|
112 |
-
|
113 |
-
/**
|
114 |
-
* Disable SSL verification in order to prevent download update failures
|
115 |
-
*
|
116 |
-
* @param array $args
|
117 |
-
* @param string $url
|
118 |
-
* @return object $array
|
119 |
-
*/
|
120 |
-
function http_request_args( $args, $url ) {
|
121 |
-
// If it is an https request and we are performing a package download, disable ssl verification
|
122 |
-
if( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
|
123 |
-
$args['sslverify'] = false;
|
124 |
-
}
|
125 |
-
return $args;
|
126 |
-
}
|
127 |
-
|
128 |
-
/**
|
129 |
-
* Calls the API and, if successfull, returns the object delivered by the API.
|
130 |
-
*
|
131 |
-
* @uses get_bloginfo()
|
132 |
-
* @uses wp_remote_post()
|
133 |
-
* @uses is_wp_error()
|
134 |
-
*
|
135 |
-
* @param string $_action The requested action.
|
136 |
-
* @param array $_data Parameters for the API action.
|
137 |
-
* @return false||object
|
138 |
-
*/
|
139 |
-
private function api_request( $_action, $_data ) {
|
140 |
-
|
141 |
-
global $wp_version;
|
142 |
-
|
143 |
-
$data = array_merge( $this->api_data, $_data );
|
144 |
-
|
145 |
-
if( $data['slug'] != $this->slug )
|
146 |
-
return;
|
147 |
-
|
148 |
-
if( empty( $data['license'] ) )
|
149 |
-
return;
|
150 |
-
|
151 |
-
$api_params = array(
|
152 |
-
'edd_action' => 'get_version',
|
153 |
-
'license' => $data['license'],
|
154 |
-
'name' => $data['item_name'],
|
155 |
-
'slug' => $this->slug,
|
156 |
-
'author' => $data['author'],
|
157 |
-
'url' => home_url()
|
158 |
-
);
|
159 |
-
$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
|
160 |
-
|
161 |
-
if ( ! is_wp_error( $request ) ):
|
162 |
-
$request = json_decode( wp_remote_retrieve_body( $request ) );
|
163 |
-
if( $request && isset( $request->sections ) )
|
164 |
-
$request->sections = maybe_unserialize( $request->sections );
|
165 |
-
return $request;
|
166 |
-
else:
|
167 |
-
return false;
|
168 |
-
endif;
|
169 |
-
}
|
170 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// uncomment this line for testing
|
4 |
+
//set_site_transient( 'update_plugins', null );
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Allows plugins to use their own update API.
|
8 |
+
*
|
9 |
+
* @author Pippin Williamson
|
10 |
+
* @version 1.2
|
11 |
+
*/
|
12 |
+
class EDD_SL_Plugin_Updater {
|
13 |
+
private $api_url = '';
|
14 |
+
private $api_data = array();
|
15 |
+
private $name = '';
|
16 |
+
private $slug = '';
|
17 |
+
private $do_check = false;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Class constructor.
|
21 |
+
*
|
22 |
+
* @uses plugin_basename()
|
23 |
+
* @uses hook()
|
24 |
+
*
|
25 |
+
* @param string $_api_url The URL pointing to the custom API endpoint.
|
26 |
+
* @param string $_plugin_file Path to the plugin file.
|
27 |
+
* @param array $_api_data Optional data to send with API calls.
|
28 |
+
* @return void
|
29 |
+
*/
|
30 |
+
function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
|
31 |
+
$this->api_url = trailingslashit( $_api_url );
|
32 |
+
$this->api_data = urlencode_deep( $_api_data );
|
33 |
+
$this->name = plugin_basename( $_plugin_file );
|
34 |
+
$this->slug = basename( $_plugin_file, '.php');
|
35 |
+
$this->version = $_api_data['version'];
|
36 |
+
|
37 |
+
// Set up hooks.
|
38 |
+
$this->hook();
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Set up WordPress filters to hook into WP's update process.
|
43 |
+
*
|
44 |
+
* @uses add_filter()
|
45 |
+
*
|
46 |
+
* @return void
|
47 |
+
*/
|
48 |
+
private function hook() {
|
49 |
+
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'pre_set_site_transient_update_plugins_filter' ) );
|
50 |
+
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
|
51 |
+
add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 );
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Check for Updates at the defined API endpoint and modify the update array.
|
56 |
+
*
|
57 |
+
* This function dives into the update API just when WordPress creates its update array,
|
58 |
+
* then adds a custom API call and injects the custom plugin data retrieved from the API.
|
59 |
+
* It is reassembled from parts of the native WordPress plugin update code.
|
60 |
+
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
|
61 |
+
*
|
62 |
+
* @uses api_request()
|
63 |
+
*
|
64 |
+
* @param array $_transient_data Update array build by WordPress.
|
65 |
+
* @return array Modified update array with custom plugin data.
|
66 |
+
*/
|
67 |
+
function pre_set_site_transient_update_plugins_filter( $_transient_data ) {
|
68 |
+
|
69 |
+
if( empty( $_transient_data ) || ! $this->do_check ) {
|
70 |
+
|
71 |
+
// This ensures that the custom API request only runs on the second time that WP fires the update check
|
72 |
+
$this->do_check = true;
|
73 |
+
|
74 |
+
return $_transient_data;
|
75 |
+
}
|
76 |
+
|
77 |
+
$to_send = array( 'slug' => $this->slug );
|
78 |
+
|
79 |
+
$api_response = $this->api_request( 'plugin_latest_version', $to_send );
|
80 |
+
|
81 |
+
if( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) {
|
82 |
+
|
83 |
+
if( version_compare( $this->version, $api_response->new_version, '<' ) ) {
|
84 |
+
$_transient_data->response[$this->name] = $api_response;
|
85 |
+
}
|
86 |
+
}
|
87 |
+
return $_transient_data;
|
88 |
+
}
|
89 |
+
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Updates information on the "View version x.x details" page with custom data.
|
93 |
+
*
|
94 |
+
* @uses api_request()
|
95 |
+
*
|
96 |
+
* @param mixed $_data
|
97 |
+
* @param string $_action
|
98 |
+
* @param object $_args
|
99 |
+
* @return object $_data
|
100 |
+
*/
|
101 |
+
function plugins_api_filter( $_data, $_action = '', $_args = null ) {
|
102 |
+
if ( ( $_action != 'plugin_information' ) || !isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) return $_data;
|
103 |
+
|
104 |
+
$to_send = array( 'slug' => $this->slug );
|
105 |
+
|
106 |
+
$api_response = $this->api_request( 'plugin_information', $to_send );
|
107 |
+
if ( false !== $api_response ) $_data = $api_response;
|
108 |
+
|
109 |
+
return $_data;
|
110 |
+
}
|
111 |
+
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Disable SSL verification in order to prevent download update failures
|
115 |
+
*
|
116 |
+
* @param array $args
|
117 |
+
* @param string $url
|
118 |
+
* @return object $array
|
119 |
+
*/
|
120 |
+
function http_request_args( $args, $url ) {
|
121 |
+
// If it is an https request and we are performing a package download, disable ssl verification
|
122 |
+
if( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
|
123 |
+
$args['sslverify'] = false;
|
124 |
+
}
|
125 |
+
return $args;
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Calls the API and, if successfull, returns the object delivered by the API.
|
130 |
+
*
|
131 |
+
* @uses get_bloginfo()
|
132 |
+
* @uses wp_remote_post()
|
133 |
+
* @uses is_wp_error()
|
134 |
+
*
|
135 |
+
* @param string $_action The requested action.
|
136 |
+
* @param array $_data Parameters for the API action.
|
137 |
+
* @return false||object
|
138 |
+
*/
|
139 |
+
private function api_request( $_action, $_data ) {
|
140 |
+
|
141 |
+
global $wp_version;
|
142 |
+
|
143 |
+
$data = array_merge( $this->api_data, $_data );
|
144 |
+
|
145 |
+
if( $data['slug'] != $this->slug )
|
146 |
+
return;
|
147 |
+
|
148 |
+
if( empty( $data['license'] ) )
|
149 |
+
return;
|
150 |
+
|
151 |
+
$api_params = array(
|
152 |
+
'edd_action' => 'get_version',
|
153 |
+
'license' => $data['license'],
|
154 |
+
'name' => $data['item_name'],
|
155 |
+
'slug' => $this->slug,
|
156 |
+
'author' => $data['author'],
|
157 |
+
'url' => home_url()
|
158 |
+
);
|
159 |
+
$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
|
160 |
+
|
161 |
+
if ( ! is_wp_error( $request ) ):
|
162 |
+
$request = json_decode( wp_remote_retrieve_body( $request ) );
|
163 |
+
if( $request && isset( $request->sections ) )
|
164 |
+
$request->sections = maybe_unserialize( $request->sections );
|
165 |
+
return $request;
|
166 |
+
else:
|
167 |
+
return false;
|
168 |
+
endif;
|
169 |
+
}
|
170 |
+
}
|
classes/Helpers/DataHelper.php
CHANGED
@@ -1,23 +1,23 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Helpers_DataHelper
|
4 |
-
{
|
5 |
-
|
6 |
-
/**
|
7 |
-
* A wrapper for JSON encoding that fixes potential issues.
|
8 |
-
* @param mixed $data The data to encode.
|
9 |
-
* @return string JSON string.
|
10 |
-
*/
|
11 |
-
public static function JsonEncode($data){
|
12 |
-
return @json_encode($data);
|
13 |
-
}
|
14 |
-
|
15 |
-
/**
|
16 |
-
* A wrapper for JSON encoding that fixes potential issues.
|
17 |
-
* @param string $data The JSON string to decode.
|
18 |
-
* @return mixed Decoded data.
|
19 |
-
*/
|
20 |
-
public static function JsonDecode($data){
|
21 |
-
return @json_decode($data);
|
22 |
-
}
|
23 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Helpers_DataHelper
|
4 |
+
{
|
5 |
+
|
6 |
+
/**
|
7 |
+
* A wrapper for JSON encoding that fixes potential issues.
|
8 |
+
* @param mixed $data The data to encode.
|
9 |
+
* @return string JSON string.
|
10 |
+
*/
|
11 |
+
public static function JsonEncode($data){
|
12 |
+
return @json_encode($data);
|
13 |
+
}
|
14 |
+
|
15 |
+
/**
|
16 |
+
* A wrapper for JSON encoding that fixes potential issues.
|
17 |
+
* @param string $data The JSON string to decode.
|
18 |
+
* @return mixed Decoded data.
|
19 |
+
*/
|
20 |
+
public static function JsonDecode($data){
|
21 |
+
return @json_decode($data);
|
22 |
+
}
|
23 |
}
|
classes/LicenseManager.php
CHANGED
@@ -19,7 +19,7 @@ class WSAL_LicenseManager {
|
|
19 |
}
|
20 |
|
21 |
protected function GetStoreUrl(){
|
22 |
-
return 'http://www.
|
23 |
}
|
24 |
|
25 |
public function CountPlugins(){
|
19 |
}
|
20 |
|
21 |
protected function GetStoreUrl(){
|
22 |
+
return 'http://www.wpsecurityauditlog.com/';
|
23 |
}
|
24 |
|
25 |
public function CountPlugins(){
|
classes/Models/ActiveRecord.php
CHANGED
@@ -1,267 +1,267 @@
|
|
1 |
-
<?php
|
2 |
-
require_once(__DIR__ . '/../Connector/ConnectorFactory.php');
|
3 |
-
|
4 |
-
abstract class WSAL_Models_ActiveRecord
|
5 |
-
{
|
6 |
-
|
7 |
-
/**
|
8 |
-
* @var_$connector Data connector;
|
9 |
-
*/
|
10 |
-
protected $connector;
|
11 |
-
|
12 |
-
protected $id = false;
|
13 |
-
|
14 |
-
protected $adapterName = null;
|
15 |
-
|
16 |
-
protected $useDefaultAdapter = false;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* @return array Returns this records' fields.
|
20 |
-
*/
|
21 |
-
public function GetFields()
|
22 |
-
{
|
23 |
-
if(!isset($this->_column_cache)){
|
24 |
-
$this->_column_cache = array();
|
25 |
-
foreach(array_keys(get_object_vars($this)) as $col)
|
26 |
-
if(trim($col) && $col[0] != '_')
|
27 |
-
$this->_column_cache[] = $col;
|
28 |
-
}
|
29 |
-
return $this->_column_cache;
|
30 |
-
}
|
31 |
-
|
32 |
-
public function setId($id)
|
33 |
-
{
|
34 |
-
$this->id = $id;
|
35 |
-
}
|
36 |
-
|
37 |
-
public function getId()
|
38 |
-
{
|
39 |
-
return $this->id;
|
40 |
-
}
|
41 |
-
|
42 |
-
const STATE_UNKNOWN = 'unknown';
|
43 |
-
const STATE_CREATED = 'created';
|
44 |
-
const STATE_UPDATED = 'updated';
|
45 |
-
const STATE_DELETED = 'deleted';
|
46 |
-
const STATE_LOADED = 'loaded';
|
47 |
-
|
48 |
-
protected $_state = self::STATE_UNKNOWN;
|
49 |
-
|
50 |
-
public function __construct($data = null)
|
51 |
-
{
|
52 |
-
if (!$this->adapterName) {
|
53 |
-
throw new Exception('Class "' . __CLASS__ . '" requires "adapterName" to be set.');
|
54 |
-
}
|
55 |
-
if (!is_null($data)) {
|
56 |
-
$this->LoadData($data);
|
57 |
-
$this->_state = self::STATE_LOADED;
|
58 |
-
}
|
59 |
-
}
|
60 |
-
|
61 |
-
protected function getConnector()
|
62 |
-
{
|
63 |
-
if (!empty($this->connector)) {
|
64 |
-
return $this->connector;
|
65 |
-
}
|
66 |
-
if ($this->useDefaultAdapter) {
|
67 |
-
$this->connector = WSAL_Connector_ConnectorFactory::GetDefaultConnector();
|
68 |
-
} else {
|
69 |
-
$this->connector = WSAL_Connector_ConnectorFactory::GetConnector();
|
70 |
-
}
|
71 |
-
return $this->connector;
|
72 |
-
}
|
73 |
-
|
74 |
-
public function getAdapter()
|
75 |
-
{
|
76 |
-
return $this->getConnector()->getAdapter($this->adapterName);
|
77 |
-
}
|
78 |
-
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Load record from DB.
|
82 |
-
* @param string $cond (Optional) Load condition.
|
83 |
-
* @param array $args (Optional) Load condition arguments.
|
84 |
-
*/
|
85 |
-
public function Load($cond = '%d', $args = array(1)){
|
86 |
-
$this->_state = self::STATE_UNKNOWN;
|
87 |
-
|
88 |
-
$data = $this->getAdapter()->Load($cond, $args);
|
89 |
-
if(!is_null($data)){
|
90 |
-
$this->LoadData($data);
|
91 |
-
$this->_state = self::STATE_LOADED;
|
92 |
-
}
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* Load object data from variable.
|
97 |
-
* @param array|object $data Data array or object.
|
98 |
-
*/
|
99 |
-
public function LoadData($data){
|
100 |
-
$copy = get_class($this);
|
101 |
-
$copy = new $copy;
|
102 |
-
foreach((array)$data as $key => $val){
|
103 |
-
if(isset($copy->$key)){
|
104 |
-
switch(true){
|
105 |
-
case is_array($copy->$key):
|
106 |
-
case is_object($copy->$key):
|
107 |
-
$jsonDecodedVal = WSAL_Helpers_DataHelper::JsonDecode($val);
|
108 |
-
$this->$key = ($jsonDecodedVal == null) ? $val : $jsonDecodedVal;
|
109 |
-
break;
|
110 |
-
case is_int($copy->$key):
|
111 |
-
$this->$key = (int)$val;
|
112 |
-
break;
|
113 |
-
case is_float($copy->$key):
|
114 |
-
$this->$key = (float)$val;
|
115 |
-
break;
|
116 |
-
case is_bool($copy->$key):
|
117 |
-
$this->$key = (bool)$val;
|
118 |
-
break;
|
119 |
-
case is_string($copy->$key):
|
120 |
-
$this->$key = (string)$val;
|
121 |
-
break;
|
122 |
-
default:
|
123 |
-
throw new Exception('Unsupported type "'.gettype($copy->$key).'"');
|
124 |
-
}
|
125 |
-
}
|
126 |
-
}
|
127 |
-
return $this;
|
128 |
-
}
|
129 |
-
|
130 |
-
/**
|
131 |
-
* Save this active record
|
132 |
-
* @return integer|boolean Either the number of modified/inserted rows or false on failure.
|
133 |
-
*/
|
134 |
-
public function Save()
|
135 |
-
{
|
136 |
-
$this->_state = self::STATE_UNKNOWN;
|
137 |
-
|
138 |
-
// use today's date if not set up
|
139 |
-
if (is_null($this->created_on)) {
|
140 |
-
$this->created_on = $this->GetMicrotime();
|
141 |
-
}
|
142 |
-
$updateId = $this->getId();
|
143 |
-
$result = $this->getAdapter()->Save($this);
|
144 |
-
|
145 |
-
if ($result !== false) {
|
146 |
-
$this->_state = (!empty($updateId))?self::STATE_UPDATED:self::STATE_CREATED;
|
147 |
-
}
|
148 |
-
return $result;
|
149 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Deletes this active record
|
153 |
-
*/
|
154 |
-
public function Delete()
|
155 |
-
{
|
156 |
-
$this->_state = self::STATE_UNKNOWN;
|
157 |
-
$result = $this->getAdapter()->Delete($this);
|
158 |
-
if($result !== false)
|
159 |
-
$this->_state = self::STATE_DELETED;
|
160 |
-
|
161 |
-
return $result;
|
162 |
-
}
|
163 |
-
|
164 |
-
public function Count($cond = '%d', $args = array(1)) {
|
165 |
-
$result = $this->getAdapter()->Count($cond, $args);
|
166 |
-
return $result;
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* @return boolean
|
171 |
-
*/
|
172 |
-
public function IsLoaded(){
|
173 |
-
return $this->_state == self::STATE_LOADED;
|
174 |
-
}
|
175 |
-
|
176 |
-
/**
|
177 |
-
* @return boolean
|
178 |
-
*/
|
179 |
-
public function IsSaved(){
|
180 |
-
return $this->_state == self::STATE_CREATED
|
181 |
-
|| $this->_state == self::STATE_UPDATED;
|
182 |
-
}
|
183 |
-
|
184 |
-
/**
|
185 |
-
* @return boolean
|
186 |
-
*/
|
187 |
-
public function IsCreated(){
|
188 |
-
return $this->_state == self::STATE_CREATED;
|
189 |
-
}
|
190 |
-
|
191 |
-
/**
|
192 |
-
* @return boolean
|
193 |
-
*/
|
194 |
-
public function IsUpdated()
|
195 |
-
{
|
196 |
-
return $this->_state == self::STATE_UPDATED;
|
197 |
-
}
|
198 |
-
|
199 |
-
/**
|
200 |
-
* @return boolean
|
201 |
-
*/
|
202 |
-
public function IsInstalled()
|
203 |
-
{
|
204 |
-
return $this->getAdapter()->IsInstalled();
|
205 |
-
}
|
206 |
-
|
207 |
-
public function Install()
|
208 |
-
{
|
209 |
-
return $this->getAdapter()->Install();
|
210 |
-
}
|
211 |
-
|
212 |
-
/**
|
213 |
-
* @return boolean
|
214 |
-
*/
|
215 |
-
public function IsDeleted()
|
216 |
-
{
|
217 |
-
return $this->_state == self::STATE_DELETED;
|
218 |
-
}
|
219 |
-
|
220 |
-
protected static $_cache = array();
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Load ActiveRecord from DB or cache.
|
224 |
-
* @param string $target ActiveRecord class name.
|
225 |
-
* @param string $query Load condition.
|
226 |
-
* @param array $args Arguments used in condition.
|
227 |
-
* @return WSAL_Models_ActiveRecord
|
228 |
-
*/
|
229 |
-
protected static function CacheLoad($target, $query, $args){
|
230 |
-
$index = $target . '::' . vsprintf($query, $args);
|
231 |
-
if(!isset(self::$_cache[$index])){
|
232 |
-
self::$_cache[$index] = new $target();
|
233 |
-
self::$_cache[$index]->Load($query, $args);
|
234 |
-
}
|
235 |
-
return self::$_cache[$index];
|
236 |
-
}
|
237 |
-
|
238 |
-
/**
|
239 |
-
* Remove ActiveRecord cache.
|
240 |
-
* @param string $target ActiveRecord class name.
|
241 |
-
* @param string $query Load condition.
|
242 |
-
* @param array $args Arguments used in condition.
|
243 |
-
*/
|
244 |
-
protected static function CacheRemove($target, $query, $args){
|
245 |
-
$index = $target . '::' . sprintf($query, $args);
|
246 |
-
if(!isset(self::$_cache[$index])){
|
247 |
-
unset(self::$_cache[$index]);
|
248 |
-
}
|
249 |
-
}
|
250 |
-
|
251 |
-
/**
|
252 |
-
* Clear the cache.
|
253 |
-
*/
|
254 |
-
protected static function CacheClear()
|
255 |
-
{
|
256 |
-
self::$_cache = array();
|
257 |
-
}
|
258 |
-
|
259 |
-
/**
|
260 |
-
* Function used in WSAL reporting extension
|
261 |
-
*/
|
262 |
-
public function GetReporting($_siteId, $_userId, $_roleName, $_alertCode, $_startTimestamp, $_endTimestamp)
|
263 |
-
{
|
264 |
-
return $this->getAdapter()->GetReporting($_siteId, $_userId, $_roleName, $_alertCode, $_startTimestamp, $_endTimestamp);
|
265 |
-
}
|
266 |
-
|
267 |
-
}
|
1 |
+
<?php
|
2 |
+
require_once(__DIR__ . '/../Connector/ConnectorFactory.php');
|
3 |
+
|
4 |
+
abstract class WSAL_Models_ActiveRecord
|
5 |
+
{
|
6 |
+
|
7 |
+
/**
|
8 |
+
* @var_$connector Data connector;
|
9 |
+
*/
|
10 |
+
protected $connector;
|
11 |
+
|
12 |
+
protected $id = false;
|
13 |
+
|
14 |
+
protected $adapterName = null;
|
15 |
+
|
16 |
+
protected $useDefaultAdapter = false;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* @return array Returns this records' fields.
|
20 |
+
*/
|
21 |
+
public function GetFields()
|
22 |
+
{
|
23 |
+
if(!isset($this->_column_cache)){
|
24 |
+
$this->_column_cache = array();
|
25 |
+
foreach(array_keys(get_object_vars($this)) as $col)
|
26 |
+
if(trim($col) && $col[0] != '_')
|
27 |
+
$this->_column_cache[] = $col;
|
28 |
+
}
|
29 |
+
return $this->_column_cache;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function setId($id)
|
33 |
+
{
|
34 |
+
$this->id = $id;
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getId()
|
38 |
+
{
|
39 |
+
return $this->id;
|
40 |
+
}
|
41 |
+
|
42 |
+
const STATE_UNKNOWN = 'unknown';
|
43 |
+
const STATE_CREATED = 'created';
|
44 |
+
const STATE_UPDATED = 'updated';
|
45 |
+
const STATE_DELETED = 'deleted';
|
46 |
+
const STATE_LOADED = 'loaded';
|
47 |
+
|
48 |
+
protected $_state = self::STATE_UNKNOWN;
|
49 |
+
|
50 |
+
public function __construct($data = null)
|
51 |
+
{
|
52 |
+
if (!$this->adapterName) {
|
53 |
+
throw new Exception('Class "' . __CLASS__ . '" requires "adapterName" to be set.');
|
54 |
+
}
|
55 |
+
if (!is_null($data)) {
|
56 |
+
$this->LoadData($data);
|
57 |
+
$this->_state = self::STATE_LOADED;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
protected function getConnector()
|
62 |
+
{
|
63 |
+
if (!empty($this->connector)) {
|
64 |
+
return $this->connector;
|
65 |
+
}
|
66 |
+
if ($this->useDefaultAdapter) {
|
67 |
+
$this->connector = WSAL_Connector_ConnectorFactory::GetDefaultConnector();
|
68 |
+
} else {
|
69 |
+
$this->connector = WSAL_Connector_ConnectorFactory::GetConnector();
|
70 |
+
}
|
71 |
+
return $this->connector;
|
72 |
+
}
|
73 |
+
|
74 |
+
public function getAdapter()
|
75 |
+
{
|
76 |
+
return $this->getConnector()->getAdapter($this->adapterName);
|
77 |
+
}
|
78 |
+
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Load record from DB.
|
82 |
+
* @param string $cond (Optional) Load condition.
|
83 |
+
* @param array $args (Optional) Load condition arguments.
|
84 |
+
*/
|
85 |
+
public function Load($cond = '%d', $args = array(1)){
|
86 |
+
$this->_state = self::STATE_UNKNOWN;
|
87 |
+
|
88 |
+
$data = $this->getAdapter()->Load($cond, $args);
|
89 |
+
if(!is_null($data)){
|
90 |
+
$this->LoadData($data);
|
91 |
+
$this->_state = self::STATE_LOADED;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Load object data from variable.
|
97 |
+
* @param array|object $data Data array or object.
|
98 |
+
*/
|
99 |
+
public function LoadData($data){
|
100 |
+
$copy = get_class($this);
|
101 |
+
$copy = new $copy;
|
102 |
+
foreach((array)$data as $key => $val){
|
103 |
+
if(isset($copy->$key)){
|
104 |
+
switch(true){
|
105 |
+
case is_array($copy->$key):
|
106 |
+
case is_object($copy->$key):
|
107 |
+
$jsonDecodedVal = WSAL_Helpers_DataHelper::JsonDecode($val);
|
108 |
+
$this->$key = ($jsonDecodedVal == null) ? $val : $jsonDecodedVal;
|
109 |
+
break;
|
110 |
+
case is_int($copy->$key):
|
111 |
+
$this->$key = (int)$val;
|
112 |
+
break;
|
113 |
+
case is_float($copy->$key):
|
114 |
+
$this->$key = (float)$val;
|
115 |
+
break;
|
116 |
+
case is_bool($copy->$key):
|
117 |
+
$this->$key = (bool)$val;
|
118 |
+
break;
|
119 |
+
case is_string($copy->$key):
|
120 |
+
$this->$key = (string)$val;
|
121 |
+
break;
|
122 |
+
default:
|
123 |
+
throw new Exception('Unsupported type "'.gettype($copy->$key).'"');
|
124 |
+
}
|
125 |
+
}
|
126 |
+
}
|
127 |
+
return $this;
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Save this active record
|
132 |
+
* @return integer|boolean Either the number of modified/inserted rows or false on failure.
|
133 |
+
*/
|
134 |
+
public function Save()
|
135 |
+
{
|
136 |
+
$this->_state = self::STATE_UNKNOWN;
|
137 |
+
|
138 |
+
// use today's date if not set up
|
139 |
+
if (is_null($this->created_on)) {
|
140 |
+
$this->created_on = $this->GetMicrotime();
|
141 |
+
}
|
142 |
+
$updateId = $this->getId();
|
143 |
+
$result = $this->getAdapter()->Save($this);
|
144 |
+
|
145 |
+
if ($result !== false) {
|
146 |
+
$this->_state = (!empty($updateId))?self::STATE_UPDATED:self::STATE_CREATED;
|
147 |
+
}
|
148 |
+
return $result;
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Deletes this active record
|
153 |
+
*/
|
154 |
+
public function Delete()
|
155 |
+
{
|
156 |
+
$this->_state = self::STATE_UNKNOWN;
|
157 |
+
$result = $this->getAdapter()->Delete($this);
|
158 |
+
if($result !== false)
|
159 |
+
$this->_state = self::STATE_DELETED;
|
160 |
+
|
161 |
+
return $result;
|
162 |
+
}
|
163 |
+
|
164 |
+
public function Count($cond = '%d', $args = array(1)) {
|
165 |
+
$result = $this->getAdapter()->Count($cond, $args);
|
166 |
+
return $result;
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* @return boolean
|
171 |
+
*/
|
172 |
+
public function IsLoaded(){
|
173 |
+
return $this->_state == self::STATE_LOADED;
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* @return boolean
|
178 |
+
*/
|
179 |
+
public function IsSaved(){
|
180 |
+
return $this->_state == self::STATE_CREATED
|
181 |
+
|| $this->_state == self::STATE_UPDATED;
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* @return boolean
|
186 |
+
*/
|
187 |
+
public function IsCreated(){
|
188 |
+
return $this->_state == self::STATE_CREATED;
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* @return boolean
|
193 |
+
*/
|
194 |
+
public function IsUpdated()
|
195 |
+
{
|
196 |
+
return $this->_state == self::STATE_UPDATED;
|
197 |
+
}
|
198 |
+
|
199 |
+
/**
|
200 |
+
* @return boolean
|
201 |
+
*/
|
202 |
+
public function IsInstalled()
|
203 |
+
{
|
204 |
+
return $this->getAdapter()->IsInstalled();
|
205 |
+
}
|
206 |
+
|
207 |
+
public function Install()
|
208 |
+
{
|
209 |
+
return $this->getAdapter()->Install();
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* @return boolean
|
214 |
+
*/
|
215 |
+
public function IsDeleted()
|
216 |
+
{
|
217 |
+
return $this->_state == self::STATE_DELETED;
|
218 |
+
}
|
219 |
+
|
220 |
+
protected static $_cache = array();
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Load ActiveRecord from DB or cache.
|
224 |
+
* @param string $target ActiveRecord class name.
|
225 |
+
* @param string $query Load condition.
|
226 |
+
* @param array $args Arguments used in condition.
|
227 |
+
* @return WSAL_Models_ActiveRecord
|
228 |
+
*/
|
229 |
+
protected static function CacheLoad($target, $query, $args){
|
230 |
+
$index = $target . '::' . vsprintf($query, $args);
|
231 |
+
if(!isset(self::$_cache[$index])){
|
232 |
+
self::$_cache[$index] = new $target();
|
233 |
+
self::$_cache[$index]->Load($query, $args);
|
234 |
+
}
|
235 |
+
return self::$_cache[$index];
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Remove ActiveRecord cache.
|
240 |
+
* @param string $target ActiveRecord class name.
|
241 |
+
* @param string $query Load condition.
|
242 |
+
* @param array $args Arguments used in condition.
|
243 |
+
*/
|
244 |
+
protected static function CacheRemove($target, $query, $args){
|
245 |
+
$index = $target . '::' . sprintf($query, $args);
|
246 |
+
if(!isset(self::$_cache[$index])){
|
247 |
+
unset(self::$_cache[$index]);
|
248 |
+
}
|
249 |
+
}
|
250 |
+
|
251 |
+
/**
|
252 |
+
* Clear the cache.
|
253 |
+
*/
|
254 |
+
protected static function CacheClear()
|
255 |
+
{
|
256 |
+
self::$_cache = array();
|
257 |
+
}
|
258 |
+
|
259 |
+
/**
|
260 |
+
* Function used in WSAL reporting extension
|
261 |
+
*/
|
262 |
+
public function GetReporting($_siteId, $_userId, $_roleName, $_alertCode, $_startTimestamp, $_endTimestamp)
|
263 |
+
{
|
264 |
+
return $this->getAdapter()->GetReporting($_siteId, $_userId, $_roleName, $_alertCode, $_startTimestamp, $_endTimestamp);
|
265 |
+
}
|
266 |
+
|
267 |
+
}
|
classes/Models/Adapters/ActiveRecordInterface.php
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
interface WSAL_Adapters_ActiveRecordInterface {
|
4 |
-
|
5 |
-
public function IsInstalled();
|
6 |
-
public function Install();
|
7 |
-
public function Uninstall();
|
8 |
-
public function Load($cond = '%d', $args = array(1));
|
9 |
-
public function Save($activeRecord);
|
10 |
-
public function Delete($activeRecord);
|
11 |
-
public function LoadMulti($cond, $args = array());
|
12 |
-
public function LoadAndCallForEach($callback, $cond = '%d', $args = array(1));
|
13 |
-
public function Count($cond = '%d', $args = array(1));
|
14 |
-
public function LoadMultiQuery($query, $args = array());
|
15 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
interface WSAL_Adapters_ActiveRecordInterface {
|
4 |
+
|
5 |
+
public function IsInstalled();
|
6 |
+
public function Install();
|
7 |
+
public function Uninstall();
|
8 |
+
public function Load($cond = '%d', $args = array(1));
|
9 |
+
public function Save($activeRecord);
|
10 |
+
public function Delete($activeRecord);
|
11 |
+
public function LoadMulti($cond, $args = array());
|
12 |
+
public function LoadAndCallForEach($callback, $cond = '%d', $args = array(1));
|
13 |
+
public function Count($cond = '%d', $args = array(1));
|
14 |
+
public function LoadMultiQuery($query, $args = array());
|
15 |
+
}
|
classes/Models/Adapters/MetaInterface.php
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
interface WSAL_Adapters_MetaInterface {
|
4 |
-
/**
|
5 |
-
* Create a meta object
|
6 |
-
* @param $metaData Array of meta data
|
7 |
-
* @return int ID of the new meta data
|
8 |
-
*/
|
9 |
-
public function deleteByOccurenceIds($occurenceIds);
|
10 |
-
|
11 |
-
public function loadByNameAndOccurenceId($metaName, $occurenceId);
|
12 |
-
|
13 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
interface WSAL_Adapters_MetaInterface {
|
4 |
+
/**
|
5 |
+
* Create a meta object
|
6 |
+
* @param $metaData Array of meta data
|
7 |
+
* @return int ID of the new meta data
|
8 |
+
*/
|
9 |
+
public function deleteByOccurenceIds($occurenceIds);
|
10 |
+
|
11 |
+
public function loadByNameAndOccurenceId($metaName, $occurenceId);
|
12 |
+
|
13 |
+
}
|
classes/Models/Adapters/MySQL/ActiveRecordAdapter.php
CHANGED
@@ -1,460 +1,460 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Adapters_MySQL_ActiveRecord implements WSAL_Adapters_ActiveRecordInterface {
|
4 |
-
|
5 |
-
protected $connection;
|
6 |
-
|
7 |
-
/**
|
8 |
-
* Contains the table name
|
9 |
-
* @var string
|
10 |
-
*/
|
11 |
-
protected $_table;
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Contains primary key column name, override as required.
|
15 |
-
* @var string
|
16 |
-
*/
|
17 |
-
protected $_idkey = '';
|
18 |
-
|
19 |
-
public function __construct($conn)
|
20 |
-
{
|
21 |
-
$this->connection = $conn;
|
22 |
-
}
|
23 |
-
|
24 |
-
public function GetModel()
|
25 |
-
{
|
26 |
-
return new WSAL_Models_ActiveRecord();
|
27 |
-
}
|
28 |
-
|
29 |
-
/**
|
30 |
-
* @return string Returns table name.
|
31 |
-
*/
|
32 |
-
public function GetTable()
|
33 |
-
{
|
34 |
-
//global $wpdb;
|
35 |
-
$_wpdb = $this->connection;
|
36 |
-
return $_wpdb->base_prefix . $this->_table;
|
37 |
-
}
|
38 |
-
|
39 |
-
/**
|
40 |
-
* @return string SQL table options (constraints, foreign keys, indexes etc).
|
41 |
-
*/
|
42 |
-
protected function GetTableOptions()
|
43 |
-
{
|
44 |
-
return ' PRIMARY KEY (' . $this->_idkey . ')';
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* @return array Returns this records' columns.
|
49 |
-
*/
|
50 |
-
public function GetColumns()
|
51 |
-
{
|
52 |
-
$model = $this->GetModel();
|
53 |
-
|
54 |
-
if(!isset($this->_column_cache)){
|
55 |
-
$this->_column_cache = array();
|
56 |
-
foreach(array_keys(get_object_vars($model)) as $col)
|
57 |
-
if(trim($col) && $col[0] != '_')
|
58 |
-
$this->_column_cache[] = $col;
|
59 |
-
}
|
60 |
-
return $this->_column_cache;
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* @deprecated
|
65 |
-
* @return boolean Returns whether table structure is installed or not.
|
66 |
-
*/
|
67 |
-
public function IsInstalled(){
|
68 |
-
//global $wpdb;
|
69 |
-
$_wpdb = $this->connection;
|
70 |
-
$sql = 'SHOW TABLES LIKE "' . $this->GetTable() . '"';
|
71 |
-
return $_wpdb->get_var($sql) == $this->GetTable();
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Install this ActiveRecord structure into DB.
|
76 |
-
*/
|
77 |
-
public function Install(){
|
78 |
-
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
79 |
-
dbDelta($this->_GetInstallQuery());
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Remove this ActiveRecord structure into DB.
|
84 |
-
*/
|
85 |
-
public function Uninstall()
|
86 |
-
{
|
87 |
-
//global $wpdb;
|
88 |
-
$_wpdb = $this->connection;
|
89 |
-
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
90 |
-
$_wpdb->query($this->_GetUninstallQuery());
|
91 |
-
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Save an active record to DB.
|
95 |
-
* @return integer|boolean Either the number of modified/inserted rows or false on failure.
|
96 |
-
*/
|
97 |
-
public function Save($activeRecord)
|
98 |
-
{
|
99 |
-
//global $wpdb;
|
100 |
-
$_wpdb = $this->connection;
|
101 |
-
$copy = $activeRecord;
|
102 |
-
$data = array();
|
103 |
-
$format = array();
|
104 |
-
foreach ($this->GetColumns() as $key) {
|
105 |
-
|
106 |
-
$val = $copy->$key;
|
107 |
-
$deffmt = '%s';
|
108 |
-
if (is_int($copy->$key)) {
|
109 |
-
$deffmt = '%d';
|
110 |
-
}
|
111 |
-
if (is_float($copy->$key)) {
|
112 |
-
$deffmt = '%f';
|
113 |
-
}
|
114 |
-
if (is_array($copy->$key) || is_object($copy->$key)) {
|
115 |
-
$data[$key] = WSAL_Helpers_DataHelper::JsonEncode($val);
|
116 |
-
} else {
|
117 |
-
$data[$key] = $val;
|
118 |
-
}
|
119 |
-
$format[] = $deffmt;
|
120 |
-
}
|
121 |
-
$result = $_wpdb->replace($this->GetTable(), $data, $format);
|
122 |
-
|
123 |
-
if ($result !== false) {
|
124 |
-
if ($_wpdb->insert_id) {
|
125 |
-
$copy->setId($_wpdb->insert_id);
|
126 |
-
}
|
127 |
-
}
|
128 |
-
return $result;
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Load record from DB.
|
133 |
-
* @param string $cond (Optional) Load condition.
|
134 |
-
* @param array $args (Optional) Load condition arguments.
|
135 |
-
*/
|
136 |
-
public function Load($cond = '%d', $args = array(1))
|
137 |
-
{
|
138 |
-
//global $wpdb;
|
139 |
-
$_wpdb = $this->connection;
|
140 |
-
|
141 |
-
$sql = $_wpdb->prepare('SELECT * FROM '.$this->GetTable().' WHERE '. $cond, $args);
|
142 |
-
$data = $_wpdb->get_row($sql, ARRAY_A);
|
143 |
-
|
144 |
-
return $data;
|
145 |
-
}
|
146 |
-
|
147 |
-
public function LoadArray($cond, $args = array())
|
148 |
-
{
|
149 |
-
//global $wpdb;
|
150 |
-
$_wpdb = $this->connection;
|
151 |
-
$result = array();
|
152 |
-
$sql = $_wpdb->prepare('SELECT * FROM '.$this->GetTable().' WHERE '. $cond, $args);
|
153 |
-
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
154 |
-
$result[] = $this->getModel()->LoadData($data);
|
155 |
-
}
|
156 |
-
return $result;
|
157 |
-
}
|
158 |
-
|
159 |
-
/**
|
160 |
-
* Delete DB record.
|
161 |
-
* @return int|boolean Either the amount of deleted rows or False on error.
|
162 |
-
*/
|
163 |
-
public function Delete($activeRecord)
|
164 |
-
{
|
165 |
-
//global $wpdb;
|
166 |
-
$_wpdb = $this->connection;
|
167 |
-
$result = $_wpdb->delete(
|
168 |
-
$this->GetTable(),
|
169 |
-
$activeRecord->getId()
|
170 |
-
);
|
171 |
-
return $result;
|
172 |
-
}
|
173 |
-
|
174 |
-
/**
|
175 |
-
* Delete records in DB matching a query.
|
176 |
-
* @param string $query Full SQL query.
|
177 |
-
* @param array $args (Optional) Query arguments.
|
178 |
-
*/
|
179 |
-
public function DeleteQuery($query, $args = array())
|
180 |
-
{
|
181 |
-
$_wpdb = $this->connection;
|
182 |
-
$sql = count($args) ? $_wpdb->prepare($query, $args) : $query;
|
183 |
-
$result = $_wpdb->query($sql);
|
184 |
-
return $result;
|
185 |
-
}
|
186 |
-
|
187 |
-
/**
|
188 |
-
* Load multiple records from DB.
|
189 |
-
* @param string $cond (Optional) Load condition (eg: 'some_id = %d' ).
|
190 |
-
* @param array $args (Optional) Load condition arguments (rg: array(45) ).
|
191 |
-
* @return self[] List of loaded records.
|
192 |
-
*/
|
193 |
-
public function LoadMulti($cond, $args = array())
|
194 |
-
{
|
195 |
-
//global $wpdb;
|
196 |
-
$_wpdb = $this->connection;
|
197 |
-
$result = array();
|
198 |
-
$sql = (!is_array($args) || !count($args)) // do we really need to prepare() or not?
|
199 |
-
? ($cond)
|
200 |
-
: $_wpdb->prepare($cond, $args)
|
201 |
-
;
|
202 |
-
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
203 |
-
$result[] = $this->getModel()->LoadData($data);
|
204 |
-
}
|
205 |
-
return $result;
|
206 |
-
|
207 |
-
}
|
208 |
-
|
209 |
-
/**
|
210 |
-
* Load multiple records from DB and call a callback for each record.
|
211 |
-
* This function is very memory-efficient, it doesn't load records in bulk.
|
212 |
-
* @param callable $callback The callback to invoke.
|
213 |
-
* @param string $cond (Optional) Load condition.
|
214 |
-
* @param array $args (Optional) Load condition arguments.
|
215 |
-
*/
|
216 |
-
public function LoadAndCallForEach($callback, $cond = '%d', $args = array(1))
|
217 |
-
{
|
218 |
-
//global $wpdb;
|
219 |
-
$_wpdb = $this->connection;
|
220 |
-
$class = get_called_class();
|
221 |
-
$sql = $_wpdb->prepare('SELECT * FROM ' . $this->GetTable() . ' WHERE '.$cond, $args);
|
222 |
-
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
223 |
-
call_user_func($callback, new $class($data));
|
224 |
-
}
|
225 |
-
}
|
226 |
-
|
227 |
-
/**
|
228 |
-
* Count records in the DB matching a condition.
|
229 |
-
* If no parameters are given, this counts the number of records in the DB table.
|
230 |
-
* @param string $cond (Optional) Query condition.
|
231 |
-
* @param array $args (Optional) Condition arguments.
|
232 |
-
* @return int Number of matching records.
|
233 |
-
*/
|
234 |
-
public function Count($cond = '%d', $args = array(1))
|
235 |
-
{
|
236 |
-
//global $wpdb;
|
237 |
-
$_wpdb = $this->connection;
|
238 |
-
$class = get_called_class();
|
239 |
-
$sql = $_wpdb->prepare('SELECT COUNT(*) FROM ' . $this->GetTable() . ' WHERE ' . $cond, $args);
|
240 |
-
return (int)$_wpdb->get_var($sql);
|
241 |
-
}
|
242 |
-
|
243 |
-
/**
|
244 |
-
* Count records in the DB matching a query.
|
245 |
-
* @param string $query Full SQL query.
|
246 |
-
* @param array $args (Optional) Query arguments.
|
247 |
-
* @return int Number of matching records.
|
248 |
-
*/
|
249 |
-
public function CountQuery($query, $args = array())
|
250 |
-
{
|
251 |
-
//global $wpdb;
|
252 |
-
$_wpdb = $this->connection;
|
253 |
-
$sql = count($args) ? $_wpdb->prepare($query, $args) : $query;
|
254 |
-
return (int)$_wpdb->get_var($sql);
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
* Similar to LoadMulti but allows the use of a full SQL query.
|
259 |
-
* @param string $query Full SQL query.
|
260 |
-
* @param array $args (Optional) Query arguments.
|
261 |
-
* @return self[] List of loaded records.
|
262 |
-
*/
|
263 |
-
public function LoadMultiQuery($query, $args = array())
|
264 |
-
{
|
265 |
-
//global $wpdb;
|
266 |
-
$_wpdb = $this->connection;
|
267 |
-
$class = get_called_class();
|
268 |
-
$result = array();
|
269 |
-
$sql = count($args) ? $_wpdb->prepare($query, $args) : $query;
|
270 |
-
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
271 |
-
$result[] = $this->getModel()->LoadData($data);
|
272 |
-
}
|
273 |
-
return $result;
|
274 |
-
}
|
275 |
-
|
276 |
-
/**
|
277 |
-
* @return string Must return SQL for creating table.
|
278 |
-
*/
|
279 |
-
protected function _GetInstallQuery()
|
280 |
-
{
|
281 |
-
$_wpdb = $this->connection;
|
282 |
-
|
283 |
-
$class = get_class($this);
|
284 |
-
$copy = new $class($this->connection);
|
285 |
-
|
286 |
-
$sql = 'CREATE TABLE ' . $this->GetTable() . ' (' . PHP_EOL;
|
287 |
-
|
288 |
-
foreach ($this->GetColumns() as $key) {
|
289 |
-
$sql .= ' ';
|
290 |
-
switch(true) {
|
291 |
-
case $key == $copy->_idkey:
|
292 |
-
$sql .= $key . ' BIGINT NOT NULL AUTO_INCREMENT,' . PHP_EOL;
|
293 |
-
break;
|
294 |
-
case is_integer($copy->$key):
|
295 |
-
$sql .= $key . ' BIGINT NOT NULL,' . PHP_EOL;
|
296 |
-
break;
|
297 |
-
case is_float($copy->$key):
|
298 |
-
$sql .= $key . ' DOUBLE NOT NULL,' . PHP_EOL;
|
299 |
-
break;
|
300 |
-
case is_string($copy->$key):
|
301 |
-
$maxlength = $key . '_maxlength';
|
302 |
-
if (property_exists($class, $maxlength)) {
|
303 |
-
$sql .= $key . ' VARCHAR(' . intval($class::$$maxlength) . ') NOT NULL,' . PHP_EOL;
|
304 |
-
} else {
|
305 |
-
$sql .= $key . ' TEXT NOT NULL,' . PHP_EOL;
|
306 |
-
}
|
307 |
-
break;
|
308 |
-
case is_bool($copy->$key):
|
309 |
-
$sql .= $key . ' BIT NOT NULL,' . PHP_EOL;
|
310 |
-
break;
|
311 |
-
case is_array($copy->$key):
|
312 |
-
case is_object($copy->$key):
|
313 |
-
$sql .= $key . ' LONGTEXT NOT NULL,' . PHP_EOL;
|
314 |
-
break;
|
315 |
-
}
|
316 |
-
}
|
317 |
-
|
318 |
-
$sql .= $this->GetTableOptions() . PHP_EOL;
|
319 |
-
|
320 |
-
$sql .= ')';
|
321 |
-
|
322 |
-
if (! empty($_wpdb->charset)) {
|
323 |
-
$sql .= ' DEFAULT CHARACTER SET ' . $_wpdb->charset;
|
324 |
-
}
|
325 |
-
|
326 |
-
return $sql;
|
327 |
-
|
328 |
-
}
|
329 |
-
|
330 |
-
/**
|
331 |
-
* @return string Must return SQL for removing table (at a minimum, it should be ` 'DROP TABLE ' . $this->_table `).
|
332 |
-
*/
|
333 |
-
protected function _GetUninstallQuery(){
|
334 |
-
return 'DROP TABLE ' . $this->GetTable();
|
335 |
-
}
|
336 |
-
|
337 |
-
/**
|
338 |
-
* Function used in WSAL reporting extension
|
339 |
-
*/
|
340 |
-
public function GetReporting($_siteId, $_userId, $_roleName, $_alertCode, $_startTimestamp, $_endTimestamp)
|
341 |
-
{
|
342 |
-
global $wpdb;
|
343 |
-
$tableUsers = $wpdb->users;
|
344 |
-
$_wpdb = $this->connection;
|
345 |
-
// tables
|
346 |
-
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
347 |
-
$tableMeta = $meta->GetTable(); // metadata
|
348 |
-
$occurrence = new WSAL_Adapters_MySQL_Occurrence($this->connection);
|
349 |
-
$tableOcc = $occurrence->GetTable(); // occurrences
|
350 |
-
|
351 |
-
$ids = '0';
|
352 |
-
if (!empty($_userId) && $_userId != "null") {
|
353 |
-
$sql = 'SELECT ID FROM '.$tableUsers.' WHERE find_in_set(ID, @userId) > 0';
|
354 |
-
$wpdb->query("SET @userId = $_userId");
|
355 |
-
$result = $wpdb->get_results($sql, ARRAY_A);
|
356 |
-
$arrayIds = array();
|
357 |
-
foreach ($result as $item) {
|
358 |
-
$arrayIds[] = $item['ID'];
|
359 |
-
}
|
360 |
-
$ids = implode(', ', $arrayIds);
|
361 |
-
}
|
362 |
-
|
363 |
-
$sql = "SELECT DISTINCT
|
364 |
-
occ.id,
|
365 |
-
occ.alert_id,
|
366 |
-
occ.site_id,
|
367 |
-
occ.created_on,
|
368 |
-
replace(replace(replace((
|
369 |
-
SELECT t1.value FROM $tableMeta AS t1 WHERE t1.name = 'CurrentUserRoles' AND t1.occurrence_id = occ.id), '[', ''), ']', ''), '\\'', '') AS roles,
|
370 |
-
(SELECT replace(t2.value, '\"','') FROM $tableMeta as t2 WHERE t2.name = 'ClientIP' AND t2.occurrence_id = occ.id) AS ip,
|
371 |
-
(SELECT replace(t3.value, '\"', '') FROM $tableMeta as t3 WHERE t3.name = 'UserAgent' AND t3.occurrence_id = occ.id) AS ua,
|
372 |
-
COALESCE(
|
373 |
-
(SELECT replace(t4.value, '\"', '') FROM $tableMeta as t4 WHERE t4.name = 'Username' AND t4.occurrence_id = occ.id),
|
374 |
-
(SELECT replace(t5.value, '\"', '') FROM $tableMeta as t5 WHERE t5.name = 'CurrentUserID' AND t5.occurrence_id = occ.id)
|
375 |
-
) as user_id
|
376 |
-
FROM $tableOcc AS occ
|
377 |
-
JOIN $tableMeta AS meta ON meta.occurrence_id = occ.id
|
378 |
-
WHERE
|
379 |
-
(@siteId is NULL OR find_in_set(occ.site_id, @siteId) > 0)
|
380 |
-
AND (@userId is NULL OR (
|
381 |
-
(meta.name = 'CurrentUserID' AND find_in_set(meta.value, @userId) > 0)
|
382 |
-
OR (meta.name = 'Username' AND replace(meta.value, '\"', '') IN ($ids))
|
383 |
-
))
|
384 |
-
AND (@roleName is NULL OR (meta.name = 'CurrentUserRoles'
|
385 |
-
AND replace(replace(replace(meta.value, ']', ''), '[', ''), '\\'', '') REGEXP @roleName
|
386 |
-
))
|
387 |
-
AND (@alertCode is NULL OR find_in_set(occ.alert_id, @alertCode) > 0)
|
388 |
-
AND (@startTimestamp is NULL OR occ.created_on >= @startTimestamp)
|
389 |
-
AND (@endTimestamp is NULL OR occ.created_on <= @endTimestamp)
|
390 |
-
ORDER BY
|
391 |
-
site_id, created_on DESC
|
392 |
-
";
|
393 |
-
$_wpdb->query("SET @siteId = $_siteId");
|
394 |
-
$_wpdb->query("SET @userId = $_userId");
|
395 |
-
$_wpdb->query("SET @roleName = $_roleName");
|
396 |
-
$_wpdb->query("SET @alertCode = $_alertCode");
|
397 |
-
$_wpdb->query("SET @startTimestamp = $_startTimestamp");
|
398 |
-
$_wpdb->query("SET @endTimestamp = $_endTimestamp");
|
399 |
-
$results = $_wpdb->get_results($sql);
|
400 |
-
|
401 |
-
foreach ($results as $row) {
|
402 |
-
$sql = "SELECT t6.ID FROM $tableUsers AS t6 WHERE t6.user_login = \"$row->user_id\"";
|
403 |
-
$userId = $wpdb->get_var($sql);
|
404 |
-
if ($userId == null) {
|
405 |
-
$sql = "SELECT t4.ID FROM $tableUsers AS t4 WHERE t4.ID = \"$row->user_id\"";
|
406 |
-
$userId = $wpdb->get_var($sql);
|
407 |
-
}
|
408 |
-
$row->user_id = $userId;
|
409 |
-
}
|
410 |
-
return $results;
|
411 |
-
/*
|
412 |
-
$query = <<<query
|
413 |
-
SELECT DISTINCT
|
414 |
-
occ.id,
|
415 |
-
occ.alert_id,
|
416 |
-
occ.site_id,
|
417 |
-
occ.created_on,
|
418 |
-
replace(replace(replace(replace((select t1.value from $tableMeta as t1 where t1.name = 'CurrentUserRoles' and t1.occurrence_id = occ.id), '[', ''), ']', ''), '"', ''), '\\'', '') as roles,
|
419 |
-
(select replace(t2.value, '"','') from $tableMeta as t2 where t2.name = 'ClientIP' and t2.occurrence_id = occ.id) as ip,
|
420 |
-
(select replace(t3.value, '"', '') from $tableMeta as t3 where t3.name = 'UserAgent' and t3.occurrence_id = occ.id) as ua,
|
421 |
-
|
422 |
-
COALESCE(
|
423 |
-
(select t6.ID from $tableUsers as t6 where t6.user_login = (select replace(t7.value, '"', '') from $tableMeta as t7 where t7.name = 'Username' and t7.occurrence_id = occ.id)),
|
424 |
-
(select t4.ID from $tableUsers as t4 where t4.ID = (select t5.value from $tableMeta as t5 where t5.name = 'CurrentUserID' and t5.occurrence_id = occ.id))
|
425 |
-
) as user_id
|
426 |
-
FROM
|
427 |
-
$tableOcc as occ
|
428 |
-
JOIN
|
429 |
-
$tableMeta as meta on meta.occurrence_id = occ.id
|
430 |
-
WHERE
|
431 |
-
(@siteId is null or find_in_set(occ.site_id, @siteId) > 0)
|
432 |
-
and (@userId is null or (
|
433 |
-
(meta.name = 'CurrentUserID' and find_in_set(meta.value, @userId) > 0)
|
434 |
-
or (meta.name = 'Username' and replace(meta.value, '"', '') in (select user_login from $tableUsers where find_in_set(ID, @userId) > 0))
|
435 |
-
))
|
436 |
-
and (@roleName is null or (meta.name = 'CurrentUserRoles'
|
437 |
-
and replace(replace(replace(replace(meta.value, '"', ''), ']', ''), '[', ''), '\\'', '') REGEXP @roleName
|
438 |
-
))
|
439 |
-
and (@alertCode is null or find_in_set(occ.alert_id, @alertCode) > 0)
|
440 |
-
and (@startTimestamp is null or occ.created_on >= @startTimestamp)
|
441 |
-
and (@endTimestamp is null or occ.created_on <= @endTimestamp)
|
442 |
-
order by
|
443 |
-
site_id, created_on DESC;
|
444 |
-
query;
|
445 |
-
//#! Set variables first
|
446 |
-
$_wpdb->query("SET @siteId = $_siteId");
|
447 |
-
$_wpdb->query("SET @userId = $_userId");
|
448 |
-
$_wpdb->query("SET @roleName = $_roleName");
|
449 |
-
$_wpdb->query("SET @alertCode = $_alertCode");
|
450 |
-
$_wpdb->query("SET @startTimestamp = $_startTimestamp");
|
451 |
-
$_wpdb->query("SET @endTimestamp = $_endTimestamp");
|
452 |
-
|
453 |
-
//#! Then run query
|
454 |
-
return $_wpdb->get_results($query);
|
455 |
-
*/
|
456 |
-
}
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Adapters_MySQL_ActiveRecord implements WSAL_Adapters_ActiveRecordInterface {
|
4 |
+
|
5 |
+
protected $connection;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Contains the table name
|
9 |
+
* @var string
|
10 |
+
*/
|
11 |
+
protected $_table;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Contains primary key column name, override as required.
|
15 |
+
* @var string
|
16 |
+
*/
|
17 |
+
protected $_idkey = '';
|
18 |
+
|
19 |
+
public function __construct($conn)
|
20 |
+
{
|
21 |
+
$this->connection = $conn;
|
22 |
+
}
|
23 |
+
|
24 |
+
public function GetModel()
|
25 |
+
{
|
26 |
+
return new WSAL_Models_ActiveRecord();
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* @return string Returns table name.
|
31 |
+
*/
|
32 |
+
public function GetTable()
|
33 |
+
{
|
34 |
+
//global $wpdb;
|
35 |
+
$_wpdb = $this->connection;
|
36 |
+
return $_wpdb->base_prefix . $this->_table;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* @return string SQL table options (constraints, foreign keys, indexes etc).
|
41 |
+
*/
|
42 |
+
protected function GetTableOptions()
|
43 |
+
{
|
44 |
+
return ' PRIMARY KEY (' . $this->_idkey . ')';
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @return array Returns this records' columns.
|
49 |
+
*/
|
50 |
+
public function GetColumns()
|
51 |
+
{
|
52 |
+
$model = $this->GetModel();
|
53 |
+
|
54 |
+
if(!isset($this->_column_cache)){
|
55 |
+
$this->_column_cache = array();
|
56 |
+
foreach(array_keys(get_object_vars($model)) as $col)
|
57 |
+
if(trim($col) && $col[0] != '_')
|
58 |
+
$this->_column_cache[] = $col;
|
59 |
+
}
|
60 |
+
return $this->_column_cache;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* @deprecated
|
65 |
+
* @return boolean Returns whether table structure is installed or not.
|
66 |
+
*/
|
67 |
+
public function IsInstalled(){
|
68 |
+
//global $wpdb;
|
69 |
+
$_wpdb = $this->connection;
|
70 |
+
$sql = 'SHOW TABLES LIKE "' . $this->GetTable() . '"';
|
71 |
+
return $_wpdb->get_var($sql) == $this->GetTable();
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Install this ActiveRecord structure into DB.
|
76 |
+
*/
|
77 |
+
public function Install(){
|
78 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
79 |
+
dbDelta($this->_GetInstallQuery());
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Remove this ActiveRecord structure into DB.
|
84 |
+
*/
|
85 |
+
public function Uninstall()
|
86 |
+
{
|
87 |
+
//global $wpdb;
|
88 |
+
$_wpdb = $this->connection;
|
89 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
90 |
+
$_wpdb->query($this->_GetUninstallQuery());
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Save an active record to DB.
|
95 |
+
* @return integer|boolean Either the number of modified/inserted rows or false on failure.
|
96 |
+
*/
|
97 |
+
public function Save($activeRecord)
|
98 |
+
{
|
99 |
+
//global $wpdb;
|
100 |
+
$_wpdb = $this->connection;
|
101 |
+
$copy = $activeRecord;
|
102 |
+
$data = array();
|
103 |
+
$format = array();
|
104 |
+
foreach ($this->GetColumns() as $key) {
|
105 |
+
|
106 |
+
$val = $copy->$key;
|
107 |
+
$deffmt = '%s';
|
108 |
+
if (is_int($copy->$key)) {
|
109 |
+
$deffmt = '%d';
|
110 |
+
}
|
111 |
+
if (is_float($copy->$key)) {
|
112 |
+
$deffmt = '%f';
|
113 |
+
}
|
114 |
+
if (is_array($copy->$key) || is_object($copy->$key)) {
|
115 |
+
$data[$key] = WSAL_Helpers_DataHelper::JsonEncode($val);
|
116 |
+
} else {
|
117 |
+
$data[$key] = $val;
|
118 |
+
}
|
119 |
+
$format[] = $deffmt;
|
120 |
+
}
|
121 |
+
$result = $_wpdb->replace($this->GetTable(), $data, $format);
|
122 |
+
|
123 |
+
if ($result !== false) {
|
124 |
+
if ($_wpdb->insert_id) {
|
125 |
+
$copy->setId($_wpdb->insert_id);
|
126 |
+
}
|
127 |
+
}
|
128 |
+
return $result;
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Load record from DB.
|
133 |
+
* @param string $cond (Optional) Load condition.
|
134 |
+
* @param array $args (Optional) Load condition arguments.
|
135 |
+
*/
|
136 |
+
public function Load($cond = '%d', $args = array(1))
|
137 |
+
{
|
138 |
+
//global $wpdb;
|
139 |
+
$_wpdb = $this->connection;
|
140 |
+
|
141 |
+
$sql = $_wpdb->prepare('SELECT * FROM '.$this->GetTable().' WHERE '. $cond, $args);
|
142 |
+
$data = $_wpdb->get_row($sql, ARRAY_A);
|
143 |
+
|
144 |
+
return $data;
|
145 |
+
}
|
146 |
+
|
147 |
+
public function LoadArray($cond, $args = array())
|
148 |
+
{
|
149 |
+
//global $wpdb;
|
150 |
+
$_wpdb = $this->connection;
|
151 |
+
$result = array();
|
152 |
+
$sql = $_wpdb->prepare('SELECT * FROM '.$this->GetTable().' WHERE '. $cond, $args);
|
153 |
+
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
154 |
+
$result[] = $this->getModel()->LoadData($data);
|
155 |
+
}
|
156 |
+
return $result;
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Delete DB record.
|
161 |
+
* @return int|boolean Either the amount of deleted rows or False on error.
|
162 |
+
*/
|
163 |
+
public function Delete($activeRecord)
|
164 |
+
{
|
165 |
+
//global $wpdb;
|
166 |
+
$_wpdb = $this->connection;
|
167 |
+
$result = $_wpdb->delete(
|
168 |
+
$this->GetTable(),
|
169 |
+
$activeRecord->getId()
|
170 |
+
);
|
171 |
+
return $result;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Delete records in DB matching a query.
|
176 |
+
* @param string $query Full SQL query.
|
177 |
+
* @param array $args (Optional) Query arguments.
|
178 |
+
*/
|
179 |
+
public function DeleteQuery($query, $args = array())
|
180 |
+
{
|
181 |
+
$_wpdb = $this->connection;
|
182 |
+
$sql = count($args) ? $_wpdb->prepare($query, $args) : $query;
|
183 |
+
$result = $_wpdb->query($sql);
|
184 |
+
return $result;
|
185 |
+
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Load multiple records from DB.
|
189 |
+
* @param string $cond (Optional) Load condition (eg: 'some_id = %d' ).
|
190 |
+
* @param array $args (Optional) Load condition arguments (rg: array(45) ).
|
191 |
+
* @return self[] List of loaded records.
|
192 |
+
*/
|
193 |
+
public function LoadMulti($cond, $args = array())
|
194 |
+
{
|
195 |
+
//global $wpdb;
|
196 |
+
$_wpdb = $this->connection;
|
197 |
+
$result = array();
|
198 |
+
$sql = (!is_array($args) || !count($args)) // do we really need to prepare() or not?
|
199 |
+
? ($cond)
|
200 |
+
: $_wpdb->prepare($cond, $args)
|
201 |
+
;
|
202 |
+
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
203 |
+
$result[] = $this->getModel()->LoadData($data);
|
204 |
+
}
|
205 |
+
return $result;
|
206 |
+
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Load multiple records from DB and call a callback for each record.
|
211 |
+
* This function is very memory-efficient, it doesn't load records in bulk.
|
212 |
+
* @param callable $callback The callback to invoke.
|
213 |
+
* @param string $cond (Optional) Load condition.
|
214 |
+
* @param array $args (Optional) Load condition arguments.
|
215 |
+
*/
|
216 |
+
public function LoadAndCallForEach($callback, $cond = '%d', $args = array(1))
|
217 |
+
{
|
218 |
+
//global $wpdb;
|
219 |
+
$_wpdb = $this->connection;
|
220 |
+
$class = get_called_class();
|
221 |
+
$sql = $_wpdb->prepare('SELECT * FROM ' . $this->GetTable() . ' WHERE '.$cond, $args);
|
222 |
+
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
223 |
+
call_user_func($callback, new $class($data));
|
224 |
+
}
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Count records in the DB matching a condition.
|
229 |
+
* If no parameters are given, this counts the number of records in the DB table.
|
230 |
+
* @param string $cond (Optional) Query condition.
|
231 |
+
* @param array $args (Optional) Condition arguments.
|
232 |
+
* @return int Number of matching records.
|
233 |
+
*/
|
234 |
+
public function Count($cond = '%d', $args = array(1))
|
235 |
+
{
|
236 |
+
//global $wpdb;
|
237 |
+
$_wpdb = $this->connection;
|
238 |
+
$class = get_called_class();
|
239 |
+
$sql = $_wpdb->prepare('SELECT COUNT(*) FROM ' . $this->GetTable() . ' WHERE ' . $cond, $args);
|
240 |
+
return (int)$_wpdb->get_var($sql);
|
241 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Count records in the DB matching a query.
|
245 |
+
* @param string $query Full SQL query.
|
246 |
+
* @param array $args (Optional) Query arguments.
|
247 |
+
* @return int Number of matching records.
|
248 |
+
*/
|
249 |
+
public function CountQuery($query, $args = array())
|
250 |
+
{
|
251 |
+
//global $wpdb;
|
252 |
+
$_wpdb = $this->connection;
|
253 |
+
$sql = count($args) ? $_wpdb->prepare($query, $args) : $query;
|
254 |
+
return (int)$_wpdb->get_var($sql);
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Similar to LoadMulti but allows the use of a full SQL query.
|
259 |
+
* @param string $query Full SQL query.
|
260 |
+
* @param array $args (Optional) Query arguments.
|
261 |
+
* @return self[] List of loaded records.
|
262 |
+
*/
|
263 |
+
public function LoadMultiQuery($query, $args = array())
|
264 |
+
{
|
265 |
+
//global $wpdb;
|
266 |
+
$_wpdb = $this->connection;
|
267 |
+
$class = get_called_class();
|
268 |
+
$result = array();
|
269 |
+
$sql = count($args) ? $_wpdb->prepare($query, $args) : $query;
|
270 |
+
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
271 |
+
$result[] = $this->getModel()->LoadData($data);
|
272 |
+
}
|
273 |
+
return $result;
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* @return string Must return SQL for creating table.
|
278 |
+
*/
|
279 |
+
protected function _GetInstallQuery()
|
280 |
+
{
|
281 |
+
$_wpdb = $this->connection;
|
282 |
+
|
283 |
+
$class = get_class($this);
|
284 |
+
$copy = new $class($this->connection);
|
285 |
+
|
286 |
+
$sql = 'CREATE TABLE ' . $this->GetTable() . ' (' . PHP_EOL;
|
287 |
+
|
288 |
+
foreach ($this->GetColumns() as $key) {
|
289 |
+
$sql .= ' ';
|
290 |
+
switch(true) {
|
291 |
+
case $key == $copy->_idkey:
|
292 |
+
$sql .= $key . ' BIGINT NOT NULL AUTO_INCREMENT,' . PHP_EOL;
|
293 |
+
break;
|
294 |
+
case is_integer($copy->$key):
|
295 |
+
$sql .= $key . ' BIGINT NOT NULL,' . PHP_EOL;
|
296 |
+
break;
|
297 |
+
case is_float($copy->$key):
|
298 |
+
$sql .= $key . ' DOUBLE NOT NULL,' . PHP_EOL;
|
299 |
+
break;
|
300 |
+
case is_string($copy->$key):
|
301 |
+
$maxlength = $key . '_maxlength';
|
302 |
+
if (property_exists($class, $maxlength)) {
|
303 |
+
$sql .= $key . ' VARCHAR(' . intval($class::$$maxlength) . ') NOT NULL,' . PHP_EOL;
|
304 |
+
} else {
|
305 |
+
$sql .= $key . ' TEXT NOT NULL,' . PHP_EOL;
|
306 |
+
}
|
307 |
+
break;
|
308 |
+
case is_bool($copy->$key):
|
309 |
+
$sql .= $key . ' BIT NOT NULL,' . PHP_EOL;
|
310 |
+
break;
|
311 |
+
case is_array($copy->$key):
|
312 |
+
case is_object($copy->$key):
|
313 |
+
$sql .= $key . ' LONGTEXT NOT NULL,' . PHP_EOL;
|
314 |
+
break;
|
315 |
+
}
|
316 |
+
}
|
317 |
+
|
318 |
+
$sql .= $this->GetTableOptions() . PHP_EOL;
|
319 |
+
|
320 |
+
$sql .= ')';
|
321 |
+
|
322 |
+
if (! empty($_wpdb->charset)) {
|
323 |
+
$sql .= ' DEFAULT CHARACTER SET ' . $_wpdb->charset;
|
324 |
+
}
|
325 |
+
|
326 |
+
return $sql;
|
327 |
+
|
328 |
+
}
|
329 |
+
|
330 |
+
/**
|
331 |
+
* @return string Must return SQL for removing table (at a minimum, it should be ` 'DROP TABLE ' . $this->_table `).
|
332 |
+
*/
|
333 |
+
protected function _GetUninstallQuery(){
|
334 |
+
return 'DROP TABLE ' . $this->GetTable();
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Function used in WSAL reporting extension
|
339 |
+
*/
|
340 |
+
public function GetReporting($_siteId, $_userId, $_roleName, $_alertCode, $_startTimestamp, $_endTimestamp)
|
341 |
+
{
|
342 |
+
global $wpdb;
|
343 |
+
$tableUsers = $wpdb->users;
|
344 |
+
$_wpdb = $this->connection;
|
345 |
+
// tables
|
346 |
+
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
347 |
+
$tableMeta = $meta->GetTable(); // metadata
|
348 |
+
$occurrence = new WSAL_Adapters_MySQL_Occurrence($this->connection);
|
349 |
+
$tableOcc = $occurrence->GetTable(); // occurrences
|
350 |
+
|
351 |
+
$ids = '0';
|
352 |
+
if (!empty($_userId) && $_userId != "null") {
|
353 |
+
$sql = 'SELECT ID FROM '.$tableUsers.' WHERE find_in_set(ID, @userId) > 0';
|
354 |
+
$wpdb->query("SET @userId = $_userId");
|
355 |
+
$result = $wpdb->get_results($sql, ARRAY_A);
|
356 |
+
$arrayIds = array();
|
357 |
+
foreach ($result as $item) {
|
358 |
+
$arrayIds[] = $item['ID'];
|
359 |
+
}
|
360 |
+
$ids = implode(', ', $arrayIds);
|
361 |
+
}
|
362 |
+
|
363 |
+
$sql = "SELECT DISTINCT
|
364 |
+
occ.id,
|
365 |
+
occ.alert_id,
|
366 |
+
occ.site_id,
|
367 |
+
occ.created_on,
|
368 |
+
replace(replace(replace((
|
369 |
+
SELECT t1.value FROM $tableMeta AS t1 WHERE t1.name = 'CurrentUserRoles' AND t1.occurrence_id = occ.id), '[', ''), ']', ''), '\\'', '') AS roles,
|
370 |
+
(SELECT replace(t2.value, '\"','') FROM $tableMeta as t2 WHERE t2.name = 'ClientIP' AND t2.occurrence_id = occ.id) AS ip,
|
371 |
+
(SELECT replace(t3.value, '\"', '') FROM $tableMeta as t3 WHERE t3.name = 'UserAgent' AND t3.occurrence_id = occ.id) AS ua,
|
372 |
+
COALESCE(
|
373 |
+
(SELECT replace(t4.value, '\"', '') FROM $tableMeta as t4 WHERE t4.name = 'Username' AND t4.occurrence_id = occ.id),
|
374 |
+
(SELECT replace(t5.value, '\"', '') FROM $tableMeta as t5 WHERE t5.name = 'CurrentUserID' AND t5.occurrence_id = occ.id)
|
375 |
+
) as user_id
|
376 |
+
FROM $tableOcc AS occ
|
377 |
+
JOIN $tableMeta AS meta ON meta.occurrence_id = occ.id
|
378 |
+
WHERE
|
379 |
+
(@siteId is NULL OR find_in_set(occ.site_id, @siteId) > 0)
|
380 |
+
AND (@userId is NULL OR (
|
381 |
+
(meta.name = 'CurrentUserID' AND find_in_set(meta.value, @userId) > 0)
|
382 |
+
OR (meta.name = 'Username' AND replace(meta.value, '\"', '') IN ($ids))
|
383 |
+
))
|
384 |
+
AND (@roleName is NULL OR (meta.name = 'CurrentUserRoles'
|
385 |
+
AND replace(replace(replace(meta.value, ']', ''), '[', ''), '\\'', '') REGEXP @roleName
|
386 |
+
))
|
387 |
+
AND (@alertCode is NULL OR find_in_set(occ.alert_id, @alertCode) > 0)
|
388 |
+
AND (@startTimestamp is NULL OR occ.created_on >= @startTimestamp)
|
389 |
+
AND (@endTimestamp is NULL OR occ.created_on <= @endTimestamp)
|
390 |
+
ORDER BY
|
391 |
+
site_id, created_on DESC
|
392 |
+
";
|
393 |
+
$_wpdb->query("SET @siteId = $_siteId");
|
394 |
+
$_wpdb->query("SET @userId = $_userId");
|
395 |
+
$_wpdb->query("SET @roleName = $_roleName");
|
396 |
+
$_wpdb->query("SET @alertCode = $_alertCode");
|
397 |
+
$_wpdb->query("SET @startTimestamp = $_startTimestamp");
|
398 |
+
$_wpdb->query("SET @endTimestamp = $_endTimestamp");
|
399 |
+
$results = $_wpdb->get_results($sql);
|
400 |
+
|
401 |
+
foreach ($results as $row) {
|
402 |
+
$sql = "SELECT t6.ID FROM $tableUsers AS t6 WHERE t6.user_login = \"$row->user_id\"";
|
403 |
+
$userId = $wpdb->get_var($sql);
|
404 |
+
if ($userId == null) {
|
405 |
+
$sql = "SELECT t4.ID FROM $tableUsers AS t4 WHERE t4.ID = \"$row->user_id\"";
|
406 |
+
$userId = $wpdb->get_var($sql);
|
407 |
+
}
|
408 |
+
$row->user_id = $userId;
|
409 |
+
}
|
410 |
+
return $results;
|
411 |
+
/*
|
412 |
+
$query = <<<query
|
413 |
+
SELECT DISTINCT
|
414 |
+
occ.id,
|
415 |
+
occ.alert_id,
|
416 |
+
occ.site_id,
|
417 |
+
occ.created_on,
|
418 |
+
replace(replace(replace(replace((select t1.value from $tableMeta as t1 where t1.name = 'CurrentUserRoles' and t1.occurrence_id = occ.id), '[', ''), ']', ''), '"', ''), '\\'', '') as roles,
|
419 |
+
(select replace(t2.value, '"','') from $tableMeta as t2 where t2.name = 'ClientIP' and t2.occurrence_id = occ.id) as ip,
|
420 |
+
(select replace(t3.value, '"', '') from $tableMeta as t3 where t3.name = 'UserAgent' and t3.occurrence_id = occ.id) as ua,
|
421 |
+
|
422 |
+
COALESCE(
|
423 |
+
(select t6.ID from $tableUsers as t6 where t6.user_login = (select replace(t7.value, '"', '') from $tableMeta as t7 where t7.name = 'Username' and t7.occurrence_id = occ.id)),
|
424 |
+
(select t4.ID from $tableUsers as t4 where t4.ID = (select t5.value from $tableMeta as t5 where t5.name = 'CurrentUserID' and t5.occurrence_id = occ.id))
|
425 |
+
) as user_id
|
426 |
+
FROM
|
427 |
+
$tableOcc as occ
|
428 |
+
JOIN
|
429 |
+
$tableMeta as meta on meta.occurrence_id = occ.id
|
430 |
+
WHERE
|
431 |
+
(@siteId is null or find_in_set(occ.site_id, @siteId) > 0)
|
432 |
+
and (@userId is null or (
|
433 |
+
(meta.name = 'CurrentUserID' and find_in_set(meta.value, @userId) > 0)
|
434 |
+
or (meta.name = 'Username' and replace(meta.value, '"', '') in (select user_login from $tableUsers where find_in_set(ID, @userId) > 0))
|
435 |
+
))
|
436 |
+
and (@roleName is null or (meta.name = 'CurrentUserRoles'
|
437 |
+
and replace(replace(replace(replace(meta.value, '"', ''), ']', ''), '[', ''), '\\'', '') REGEXP @roleName
|
438 |
+
))
|
439 |
+
and (@alertCode is null or find_in_set(occ.alert_id, @alertCode) > 0)
|
440 |
+
and (@startTimestamp is null or occ.created_on >= @startTimestamp)
|
441 |
+
and (@endTimestamp is null or occ.created_on <= @endTimestamp)
|
442 |
+
order by
|
443 |
+
site_id, created_on DESC;
|
444 |
+
query;
|
445 |
+
//#! Set variables first
|
446 |
+
$_wpdb->query("SET @siteId = $_siteId");
|
447 |
+
$_wpdb->query("SET @userId = $_userId");
|
448 |
+
$_wpdb->query("SET @roleName = $_roleName");
|
449 |
+
$_wpdb->query("SET @alertCode = $_alertCode");
|
450 |
+
$_wpdb->query("SET @startTimestamp = $_startTimestamp");
|
451 |
+
$_wpdb->query("SET @endTimestamp = $_endTimestamp");
|
452 |
+
|
453 |
+
//#! Then run query
|
454 |
+
return $_wpdb->get_results($query);
|
455 |
+
*/
|
456 |
+
}
|
457 |
+
|
458 |
+
|
459 |
+
|
460 |
+
}
|
classes/Models/Adapters/MySQL/MetaAdapter.php
CHANGED
@@ -1,49 +1,49 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Adapters_MySQL_Meta extends WSAL_Adapters_MySQL_ActiveRecord implements WSAL_Adapters_MetaInterface {
|
4 |
-
|
5 |
-
protected $_table = 'wsal_metadata';
|
6 |
-
protected $_idkey = 'id';
|
7 |
-
|
8 |
-
public $id = 0;
|
9 |
-
public $occurrence_id = 0;
|
10 |
-
public $name = '';
|
11 |
-
public static $name_maxlength = 100;
|
12 |
-
public $value = array(); // force mixed type
|
13 |
-
|
14 |
-
public function GetModel()
|
15 |
-
{
|
16 |
-
return new WSAL_Models_Meta();
|
17 |
-
}
|
18 |
-
|
19 |
-
public function __construct($conn) {
|
20 |
-
parent::__construct($conn);
|
21 |
-
}
|
22 |
-
|
23 |
-
protected function GetTableOptions(){
|
24 |
-
return parent::GetTableOptions() . ',' . PHP_EOL
|
25 |
-
. ' KEY occurrence_name (occurrence_id,name)';
|
26 |
-
}
|
27 |
-
|
28 |
-
public function DeleteByOccurenceIds($occurenceIds)
|
29 |
-
{
|
30 |
-
if (!empty($occurenceIds)) {
|
31 |
-
$sql = 'DELETE FROM ' . $this->GetTable() . ' WHERE occurrence_id IN (' . implode(',', $occurenceIds) . ')';
|
32 |
-
// execute query
|
33 |
-
parent::DeleteQuery($sql);
|
34 |
-
}
|
35 |
-
}
|
36 |
-
|
37 |
-
public function LoadByNameAndOccurenceId($metaName, $occurenceId)
|
38 |
-
{
|
39 |
-
return $this->Load('occurrence_id = %d AND name = %s', array($occurenceId, $metaName));
|
40 |
-
}
|
41 |
-
|
42 |
-
public function GetMatchingIPs()
|
43 |
-
{
|
44 |
-
$_wpdb = $this->connection;
|
45 |
-
$ips = $_wpdb->get_col("SELECT DISTINCT value FROM {$this->GetTable()} WHERE name = \"ClientIP\"");
|
46 |
-
return $ips;
|
47 |
-
}
|
48 |
-
|
49 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Adapters_MySQL_Meta extends WSAL_Adapters_MySQL_ActiveRecord implements WSAL_Adapters_MetaInterface {
|
4 |
+
|
5 |
+
protected $_table = 'wsal_metadata';
|
6 |
+
protected $_idkey = 'id';
|
7 |
+
|
8 |
+
public $id = 0;
|
9 |
+
public $occurrence_id = 0;
|
10 |
+
public $name = '';
|
11 |
+
public static $name_maxlength = 100;
|
12 |
+
public $value = array(); // force mixed type
|
13 |
+
|
14 |
+
public function GetModel()
|
15 |
+
{
|
16 |
+
return new WSAL_Models_Meta();
|
17 |
+
}
|
18 |
+
|
19 |
+
public function __construct($conn) {
|
20 |
+
parent::__construct($conn);
|
21 |
+
}
|
22 |
+
|
23 |
+
protected function GetTableOptions(){
|
24 |
+
return parent::GetTableOptions() . ',' . PHP_EOL
|
25 |
+
. ' KEY occurrence_name (occurrence_id,name)';
|
26 |
+
}
|
27 |
+
|
28 |
+
public function DeleteByOccurenceIds($occurenceIds)
|
29 |
+
{
|
30 |
+
if (!empty($occurenceIds)) {
|
31 |
+
$sql = 'DELETE FROM ' . $this->GetTable() . ' WHERE occurrence_id IN (' . implode(',', $occurenceIds) . ')';
|
32 |
+
// execute query
|
33 |
+
parent::DeleteQuery($sql);
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
public function LoadByNameAndOccurenceId($metaName, $occurenceId)
|
38 |
+
{
|
39 |
+
return $this->Load('occurrence_id = %d AND name = %s', array($occurenceId, $metaName));
|
40 |
+
}
|
41 |
+
|
42 |
+
public function GetMatchingIPs()
|
43 |
+
{
|
44 |
+
$_wpdb = $this->connection;
|
45 |
+
$ips = $_wpdb->get_col("SELECT DISTINCT value FROM {$this->GetTable()} WHERE name = \"ClientIP\"");
|
46 |
+
return $ips;
|
47 |
+
}
|
48 |
+
|
49 |
+
}
|
classes/Models/Adapters/MySQL/OccurrenceAdapter.php
CHANGED
@@ -1,170 +1,170 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Adapters_MySQL_Occurrence extends WSAL_Adapters_MySQL_ActiveRecord implements WSAL_Adapters_OccurrenceInterface {
|
4 |
-
|
5 |
-
protected $_table = 'wsal_occurrences';
|
6 |
-
protected $_idkey = 'id';
|
7 |
-
protected $_meta;
|
8 |
-
|
9 |
-
public $id = 0;
|
10 |
-
public $site_id = 0;
|
11 |
-
public $alert_id = 0;
|
12 |
-
public $created_on = 0.0;
|
13 |
-
public $is_read = false;
|
14 |
-
public $is_migrated = false;
|
15 |
-
|
16 |
-
public function __construct($conn) {
|
17 |
-
parent::__construct($conn);
|
18 |
-
}
|
19 |
-
|
20 |
-
protected function GetTableOptions(){
|
21 |
-
return parent::GetTableOptions() . ',' . PHP_EOL
|
22 |
-
. ' KEY site_alert_created (site_id,alert_id,created_on)';
|
23 |
-
}
|
24 |
-
|
25 |
-
public function GetModel()
|
26 |
-
{
|
27 |
-
return new WSAL_Models_Occurrence();
|
28 |
-
}
|
29 |
-
/**
|
30 |
-
* Returns all meta data related to this event.
|
31 |
-
* @return WSAL_Meta[]
|
32 |
-
*/
|
33 |
-
public function GetMeta($occurence){
|
34 |
-
if(!isset($this->_meta)){
|
35 |
-
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
36 |
-
$this->_meta = $meta->Load('occurrence_id = %d', array($occurence->id));
|
37 |
-
}
|
38 |
-
return $this->_meta;
|
39 |
-
}
|
40 |
-
|
41 |
-
public function GetMultiMeta($occurence){
|
42 |
-
if(!isset($this->_meta)){
|
43 |
-
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
44 |
-
$this->_meta = $meta->LoadArray('occurrence_id = %d', array($occurence->id));
|
45 |
-
}
|
46 |
-
return $this->_meta;
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Loads a meta item given its name.
|
51 |
-
* @param string $name Meta name.
|
52 |
-
* @return WSAL_Meta The meta item, be sure to checked if it was loaded successfully.
|
53 |
-
*/
|
54 |
-
public function GetNamedMeta($occurence, $name){
|
55 |
-
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
56 |
-
$this->_meta = $meta->Load('occurrence_id = %d AND name = %s', array($occurence->id, $name));
|
57 |
-
|
58 |
-
return $this->_meta;
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* Returns the first meta value from a given set of names. Useful when you have a mix of items that could provide a particular detail.
|
63 |
-
* @param array $names List of meta names.
|
64 |
-
* @return WSAL_Meta The first meta item that exists.
|
65 |
-
*/
|
66 |
-
public function GetFirstNamedMeta($occurence, $names){
|
67 |
-
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
68 |
-
$query = '(' . str_repeat('name = %s OR ', count($names)).'0)';
|
69 |
-
$query = 'occurrence_id = %d AND ' . $query . ' ORDER BY name DESC LIMIT 1';
|
70 |
-
array_unshift($names, $occurence->id); // prepend args with occurrence id
|
71 |
-
|
72 |
-
$this->_meta = $meta->Load($query, $names);
|
73 |
-
return $meta->getModel()->LoadData($this->_meta);
|
74 |
-
|
75 |
-
//TO DO: Do we want to reintroduce is loaded check/logic?
|
76 |
-
//return $meta->IsLoaded() ? $meta : null;
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Returns newest unique occurrences.
|
81 |
-
* @param integer $limit Maximum limit.
|
82 |
-
* @return WSAL_Occurrence[]
|
83 |
-
*/
|
84 |
-
public static function GetNewestUnique($limit = PHP_INT_MAX){
|
85 |
-
$temp = new self();
|
86 |
-
return self::LoadMultiQuery('
|
87 |
-
SELECT *, COUNT(alert_id) as count
|
88 |
-
FROM (
|
89 |
-
SELECT *
|
90 |
-
FROM ' . $temp->GetTable() . '
|
91 |
-
ORDER BY created_on DESC
|
92 |
-
) AS temp_table
|
93 |
-
GROUP BY alert_id
|
94 |
-
LIMIT %d
|
95 |
-
', array($limit));
|
96 |
-
}
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Gets occurences of the same type by IP and Username within specified time frame
|
100 |
-
* @param string $ipAddress
|
101 |
-
* @param string $username
|
102 |
-
* @param int $alertId Alert type we are lookign for
|
103 |
-
* @param int $siteId
|
104 |
-
* @param $startTime mktime
|
105 |
-
* @param $endTime mktime
|
106 |
-
*/
|
107 |
-
public function CheckKnownUsers($args = array())
|
108 |
-
{
|
109 |
-
$tt2 = new WSAL_Adapters_MySQL_Meta($this->connection);
|
110 |
-
return self::LoadMultiQuery(
|
111 |
-
'SELECT occurrence.* FROM `' . $this->GetTable() . '` occurrence
|
112 |
-
INNER JOIN `' . $tt2->GetTable() . '` ipMeta on ipMeta.occurrence_id = occurrence.id
|
113 |
-
and ipMeta.name = "ClientIP"
|
114 |
-
and ipMeta.value = %s
|
115 |
-
INNER JOIN `' . $tt2->GetTable() . '` usernameMeta on usernameMeta.occurrence_id = occurrence.id
|
116 |
-
and usernameMeta.name = "Username"
|
117 |
-
and usernameMeta.value = %s
|
118 |
-
WHERE occurrence.alert_id = %d AND occurrence.site_id = %d
|
119 |
-
AND (created_on BETWEEN %d AND %d)
|
120 |
-
GROUP BY occurrence.id',
|
121 |
-
$args
|
122 |
-
);
|
123 |
-
}
|
124 |
-
|
125 |
-
public function CheckUnKnownUsers($args = array())
|
126 |
-
{
|
127 |
-
$tt2 = new WSAL_Adapters_MySQL_Meta($this->connection);
|
128 |
-
return self::LoadMultiQuery('
|
129 |
-
SELECT occurrence.* FROM `' . $this->GetTable() . '` occurrence
|
130 |
-
INNER JOIN `' . $tt2->GetTable() . '` ipMeta on ipMeta.occurrence_id = occurrence.id
|
131 |
-
and ipMeta.name = "ClientIP" and ipMeta.value = %s
|
132 |
-
WHERE occurrence.alert_id = %d AND occurrence.site_id = %d
|
133 |
-
AND (created_on BETWEEN %d AND %d)
|
134 |
-
GROUP BY occurrence.id',
|
135 |
-
$args
|
136 |
-
);
|
137 |
-
}
|
138 |
-
|
139 |
-
protected function prepareOccurrenceQuery($query)
|
140 |
-
{
|
141 |
-
$searchQueryParameters = array();
|
142 |
-
$searchConditions = array();
|
143 |
-
$conditions = $query->getConditions();
|
144 |
-
|
145 |
-
//BUG: not all conditions are occurence related. maybe it's just a field site_id. need seperate arrays
|
146 |
-
if (!empty($conditions)) {
|
147 |
-
$tmp = new WSAL_Adapters_MySQL_Meta($this->connection);
|
148 |
-
$sWhereClause = "";
|
149 |
-
foreach ($conditions as $field => $value) {
|
150 |
-
if (!empty($sWhereClause)) {
|
151 |
-
$sWhereClause .= " AND ";
|
152 |
-
}
|
153 |
-
$sWhereClause .= "name = %s AND value = %s";
|
154 |
-
$searchQueryParameters[] = $field;
|
155 |
-
$searchQueryParameters[] = $value;
|
156 |
-
}
|
157 |
-
|
158 |
-
$searchConditions[] = 'id IN (
|
159 |
-
SELECT DISTINCT occurrence_id
|
160 |
-
FROM ' . $tmp->GetTable() . '
|
161 |
-
WHERE ' . $sWhereClause . '
|
162 |
-
)';
|
163 |
-
}
|
164 |
-
|
165 |
-
//do something with search query parameters and search conditions - give them to the query adapter?
|
166 |
-
return $searchConditions;
|
167 |
-
}
|
168 |
-
|
169 |
-
|
170 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Adapters_MySQL_Occurrence extends WSAL_Adapters_MySQL_ActiveRecord implements WSAL_Adapters_OccurrenceInterface {
|
4 |
+
|
5 |
+
protected $_table = 'wsal_occurrences';
|
6 |
+
protected $_idkey = 'id';
|
7 |
+
protected $_meta;
|
8 |
+
|
9 |
+
public $id = 0;
|
10 |
+
public $site_id = 0;
|
11 |
+
public $alert_id = 0;
|
12 |
+
public $created_on = 0.0;
|
13 |
+
public $is_read = false;
|
14 |
+
public $is_migrated = false;
|
15 |
+
|
16 |
+
public function __construct($conn) {
|
17 |
+
parent::__construct($conn);
|
18 |
+
}
|
19 |
+
|
20 |
+
protected function GetTableOptions(){
|
21 |
+
return parent::GetTableOptions() . ',' . PHP_EOL
|
22 |
+
. ' KEY site_alert_created (site_id,alert_id,created_on)';
|
23 |
+
}
|
24 |
+
|
25 |
+
public function GetModel()
|
26 |
+
{
|
27 |
+
return new WSAL_Models_Occurrence();
|
28 |
+
}
|
29 |
+
/**
|
30 |
+
* Returns all meta data related to this event.
|
31 |
+
* @return WSAL_Meta[]
|
32 |
+
*/
|
33 |
+
public function GetMeta($occurence){
|
34 |
+
if(!isset($this->_meta)){
|
35 |
+
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
36 |
+
$this->_meta = $meta->Load('occurrence_id = %d', array($occurence->id));
|
37 |
+
}
|
38 |
+
return $this->_meta;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function GetMultiMeta($occurence){
|
42 |
+
if(!isset($this->_meta)){
|
43 |
+
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
44 |
+
$this->_meta = $meta->LoadArray('occurrence_id = %d', array($occurence->id));
|
45 |
+
}
|
46 |
+
return $this->_meta;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Loads a meta item given its name.
|
51 |
+
* @param string $name Meta name.
|
52 |
+
* @return WSAL_Meta The meta item, be sure to checked if it was loaded successfully.
|
53 |
+
*/
|
54 |
+
public function GetNamedMeta($occurence, $name){
|
55 |
+
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
56 |
+
$this->_meta = $meta->Load('occurrence_id = %d AND name = %s', array($occurence->id, $name));
|
57 |
+
|
58 |
+
return $this->_meta;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Returns the first meta value from a given set of names. Useful when you have a mix of items that could provide a particular detail.
|
63 |
+
* @param array $names List of meta names.
|
64 |
+
* @return WSAL_Meta The first meta item that exists.
|
65 |
+
*/
|
66 |
+
public function GetFirstNamedMeta($occurence, $names){
|
67 |
+
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
68 |
+
$query = '(' . str_repeat('name = %s OR ', count($names)).'0)';
|
69 |
+
$query = 'occurrence_id = %d AND ' . $query . ' ORDER BY name DESC LIMIT 1';
|
70 |
+
array_unshift($names, $occurence->id); // prepend args with occurrence id
|
71 |
+
|
72 |
+
$this->_meta = $meta->Load($query, $names);
|
73 |
+
return $meta->getModel()->LoadData($this->_meta);
|
74 |
+
|
75 |
+
//TO DO: Do we want to reintroduce is loaded check/logic?
|
76 |
+
//return $meta->IsLoaded() ? $meta : null;
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Returns newest unique occurrences.
|
81 |
+
* @param integer $limit Maximum limit.
|
82 |
+
* @return WSAL_Occurrence[]
|
83 |
+
*/
|
84 |
+
public static function GetNewestUnique($limit = PHP_INT_MAX){
|
85 |
+
$temp = new self();
|
86 |
+
return self::LoadMultiQuery('
|
87 |
+
SELECT *, COUNT(alert_id) as count
|
88 |
+
FROM (
|
89 |
+
SELECT *
|
90 |
+
FROM ' . $temp->GetTable() . '
|
91 |
+
ORDER BY created_on DESC
|
92 |
+
) AS temp_table
|
93 |
+
GROUP BY alert_id
|
94 |
+
LIMIT %d
|
95 |
+
', array($limit));
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Gets occurences of the same type by IP and Username within specified time frame
|
100 |
+
* @param string $ipAddress
|
101 |
+
* @param string $username
|
102 |
+
* @param int $alertId Alert type we are lookign for
|
103 |
+
* @param int $siteId
|
104 |
+
* @param $startTime mktime
|
105 |
+
* @param $endTime mktime
|
106 |
+
*/
|
107 |
+
public function CheckKnownUsers($args = array())
|
108 |
+
{
|
109 |
+
$tt2 = new WSAL_Adapters_MySQL_Meta($this->connection);
|
110 |
+
return self::LoadMultiQuery(
|
111 |
+
'SELECT occurrence.* FROM `' . $this->GetTable() . '` occurrence
|
112 |
+
INNER JOIN `' . $tt2->GetTable() . '` ipMeta on ipMeta.occurrence_id = occurrence.id
|
113 |
+
and ipMeta.name = "ClientIP"
|
114 |
+
and ipMeta.value = %s
|
115 |
+
INNER JOIN `' . $tt2->GetTable() . '` usernameMeta on usernameMeta.occurrence_id = occurrence.id
|
116 |
+
and usernameMeta.name = "Username"
|
117 |
+
and usernameMeta.value = %s
|
118 |
+
WHERE occurrence.alert_id = %d AND occurrence.site_id = %d
|
119 |
+
AND (created_on BETWEEN %d AND %d)
|
120 |
+
GROUP BY occurrence.id',
|
121 |
+
$args
|
122 |
+
);
|
123 |
+
}
|
124 |
+
|
125 |
+
public function CheckUnKnownUsers($args = array())
|
126 |
+
{
|
127 |
+
$tt2 = new WSAL_Adapters_MySQL_Meta($this->connection);
|
128 |
+
return self::LoadMultiQuery('
|
129 |
+
SELECT occurrence.* FROM `' . $this->GetTable() . '` occurrence
|
130 |
+
INNER JOIN `' . $tt2->GetTable() . '` ipMeta on ipMeta.occurrence_id = occurrence.id
|
131 |
+
and ipMeta.name = "ClientIP" and ipMeta.value = %s
|
132 |
+
WHERE occurrence.alert_id = %d AND occurrence.site_id = %d
|
133 |
+
AND (created_on BETWEEN %d AND %d)
|
134 |
+
GROUP BY occurrence.id',
|
135 |
+
$args
|
136 |
+
);
|
137 |
+
}
|
138 |
+
|
139 |
+
protected function prepareOccurrenceQuery($query)
|
140 |
+
{
|
141 |
+
$searchQueryParameters = array();
|
142 |
+
$searchConditions = array();
|
143 |
+
$conditions = $query->getConditions();
|
144 |
+
|
145 |
+
//BUG: not all conditions are occurence related. maybe it's just a field site_id. need seperate arrays
|
146 |
+
if (!empty($conditions)) {
|
147 |
+
$tmp = new WSAL_Adapters_MySQL_Meta($this->connection);
|
148 |
+
$sWhereClause = "";
|
149 |
+
foreach ($conditions as $field => $value) {
|
150 |
+
if (!empty($sWhereClause)) {
|
151 |
+
$sWhereClause .= " AND ";
|
152 |
+
}
|
153 |
+
$sWhereClause .= "name = %s AND value = %s";
|
154 |
+
$searchQueryParameters[] = $field;
|
155 |
+
$searchQueryParameters[] = $value;
|
156 |
+
}
|
157 |
+
|
158 |
+
$searchConditions[] = 'id IN (
|
159 |
+
SELECT DISTINCT occurrence_id
|
160 |
+
FROM ' . $tmp->GetTable() . '
|
161 |
+
WHERE ' . $sWhereClause . '
|
162 |
+
)';
|
163 |
+
}
|
164 |
+
|
165 |
+
//do something with search query parameters and search conditions - give them to the query adapter?
|
166 |
+
return $searchConditions;
|
167 |
+
}
|
168 |
+
|
169 |
+
|
170 |
+
}
|
classes/Models/Adapters/MySQL/OptionAdapter.php
CHANGED
@@ -1,80 +1,80 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Adapters_MySQL_Option extends WSAL_Adapters_MySQL_ActiveRecord
|
4 |
-
{
|
5 |
-
|
6 |
-
protected $_table = 'wsal_options';
|
7 |
-
protected $_idkey = 'id';
|
8 |
-
|
9 |
-
public $id = 0;
|
10 |
-
public $option_name = '';
|
11 |
-
public static $option_name_maxlength = 100;
|
12 |
-
public $option_value = '';
|
13 |
-
|
14 |
-
public function __construct($conn)
|
15 |
-
{
|
16 |
-
parent::__construct($conn);
|
17 |
-
}
|
18 |
-
|
19 |
-
|
20 |
-
public function GetModel()
|
21 |
-
{
|
22 |
-
return new WSAL_Models_Option();
|
23 |
-
}
|
24 |
-
|
25 |
-
public function GetNamedOption($name)
|
26 |
-
{ if ($this->IsInstalled()) {
|
27 |
-
return $this->Load('option_name = %s', array($name));
|
28 |
-
} else {
|
29 |
-
return null;
|
30 |
-
}
|
31 |
-
}
|
32 |
-
|
33 |
-
public function GetNotificationsSetting($opt_prefix)
|
34 |
-
{
|
35 |
-
if ($this->IsInstalled()) {
|
36 |
-
return $this->LoadArray('option_name LIKE %s', array($opt_prefix."%"));
|
37 |
-
} else {
|
38 |
-
return null;
|
39 |
-
}
|
40 |
-
}
|
41 |
-
|
42 |
-
public function GetNotification($id)
|
43 |
-
{
|
44 |
-
if ($this->IsInstalled()) {
|
45 |
-
return $this->Load('id = %d', array($id));
|
46 |
-
} else {
|
47 |
-
return null;
|
48 |
-
}
|
49 |
-
}
|
50 |
-
|
51 |
-
public function DeleteByName($name)
|
52 |
-
{
|
53 |
-
if (!empty($name)) {
|
54 |
-
$sql = "DELETE FROM " . $this->GetTable() . " WHERE option_name = '". $name ."'";
|
55 |
-
// execute query
|
56 |
-
return parent::DeleteQuery($sql);
|
57 |
-
} else {
|
58 |
-
return false;
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
public function DeleteByPrefix($opt_prefix)
|
63 |
-
{
|
64 |
-
if (!empty($opt_prefix)) {
|
65 |
-
$sql = "DELETE FROM " . $this->GetTable() . "WHERE option_name LIKE '". $opt_prefix ."%'";
|
66 |
-
// execute query
|
67 |
-
return parent::DeleteQuery($sql);
|
68 |
-
} else {
|
69 |
-
return false;
|
70 |
-
}
|
71 |
-
}
|
72 |
-
|
73 |
-
public function CountNotifications($opt_prefix)
|
74 |
-
{
|
75 |
-
$_wpdb = $this->connection;
|
76 |
-
$sql = "SELECT COUNT(id) FROM " . $this->GetTable() . " WHERE option_name LIKE '". $opt_prefix ."%'";
|
77 |
-
return (int)$_wpdb->get_var($sql);
|
78 |
-
}
|
79 |
-
|
80 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Adapters_MySQL_Option extends WSAL_Adapters_MySQL_ActiveRecord
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $_table = 'wsal_options';
|
7 |
+
protected $_idkey = 'id';
|
8 |
+
|
9 |
+
public $id = 0;
|
10 |
+
public $option_name = '';
|
11 |
+
public static $option_name_maxlength = 100;
|
12 |
+
public $option_value = '';
|
13 |
+
|
14 |
+
public function __construct($conn)
|
15 |
+
{
|
16 |
+
parent::__construct($conn);
|
17 |
+
}
|
18 |
+
|
19 |
+
|
20 |
+
public function GetModel()
|
21 |
+
{
|
22 |
+
return new WSAL_Models_Option();
|
23 |
+
}
|
24 |
+
|
25 |
+
public function GetNamedOption($name)
|
26 |
+
{ if ($this->IsInstalled()) {
|
27 |
+
return $this->Load('option_name = %s', array($name));
|
28 |
+
} else {
|
29 |
+
return null;
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
public function GetNotificationsSetting($opt_prefix)
|
34 |
+
{
|
35 |
+
if ($this->IsInstalled()) {
|
36 |
+
return $this->LoadArray('option_name LIKE %s', array($opt_prefix."%"));
|
37 |
+
} else {
|
38 |
+
return null;
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
public function GetNotification($id)
|
43 |
+
{
|
44 |
+
if ($this->IsInstalled()) {
|
45 |
+
return $this->Load('id = %d', array($id));
|
46 |
+
} else {
|
47 |
+
return null;
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
public function DeleteByName($name)
|
52 |
+
{
|
53 |
+
if (!empty($name)) {
|
54 |
+
$sql = "DELETE FROM " . $this->GetTable() . " WHERE option_name = '". $name ."'";
|
55 |
+
// execute query
|
56 |
+
return parent::DeleteQuery($sql);
|
57 |
+
} else {
|
58 |
+
return false;
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
public function DeleteByPrefix($opt_prefix)
|
63 |
+
{
|
64 |
+
if (!empty($opt_prefix)) {
|
65 |
+
$sql = "DELETE FROM " . $this->GetTable() . " WHERE option_name LIKE '". $opt_prefix ."%'";
|
66 |
+
// execute query
|
67 |
+
return parent::DeleteQuery($sql);
|
68 |
+
} else {
|
69 |
+
return false;
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
public function CountNotifications($opt_prefix)
|
74 |
+
{
|
75 |
+
$_wpdb = $this->connection;
|
76 |
+
$sql = "SELECT COUNT(id) FROM " . $this->GetTable() . " WHERE option_name LIKE '". $opt_prefix ."%'";
|
77 |
+
return (int)$_wpdb->get_var($sql);
|
78 |
+
}
|
79 |
+
|
80 |
+
}
|
classes/Models/Adapters/MySQL/QueryAdapter.php
CHANGED
@@ -1,216 +1,216 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Adapters_MySQL_Query implements WSAL_Adapters_QueryInterface
|
4 |
-
{
|
5 |
-
protected $connection;
|
6 |
-
|
7 |
-
public function __construct($conn)
|
8 |
-
{
|
9 |
-
$this->connection = $conn;
|
10 |
-
}
|
11 |
-
|
12 |
-
/**
|
13 |
-
* @return string Generated sql.
|
14 |
-
*/
|
15 |
-
protected function GetSql($query, &$args = array())
|
16 |
-
{
|
17 |
-
$conditions = $query->getConditions();
|
18 |
-
$searchCondition = $this->SearchCondition($query);
|
19 |
-
|
20 |
-
$sWhereClause = "";
|
21 |
-
foreach ($conditions as $fieldName => $fieldValue) {
|
22 |
-
if (empty($sWhereClause)) {
|
23 |
-
$sWhereClause .= " WHERE ";
|
24 |
-
} else {
|
25 |
-
$sWhereClause .= " AND ";
|
26 |
-
}
|
27 |
-
|
28 |
-
if (is_array($fieldValue)) {
|
29 |
-
$subWhereClause = "(";
|
30 |
-
foreach($fieldValue as $orFieldName => $orFieldValue) {
|
31 |
-
if ($subWhereClause != '(') {
|
32 |
-
$subWhereClause .= " OR ";
|
33 |
-
}
|
34 |
-
$subWhereClause .= $orFieldName;
|
35 |
-
$args[] = $orFieldValue;
|
36 |
-
}
|
37 |
-
$subWhereClause .= ")";
|
38 |
-
$sWhereClause .= $subWhereClause;
|
39 |
-
} else {
|
40 |
-
$sWhereClause .= $fieldName;
|
41 |
-
$args[] = $fieldValue;
|
42 |
-
}
|
43 |
-
}
|
44 |
-
|
45 |
-
$fromDataSets = $query->getFrom();
|
46 |
-
$columns = $query->getColumns();
|
47 |
-
$orderBys = $query->getOrderBy();
|
48 |
-
|
49 |
-
$sLimitClause = "";
|
50 |
-
if ($query->getLimit()) {
|
51 |
-
$sLimitClause .= " LIMIT ";
|
52 |
-
if ($query->getOffset()) {
|
53 |
-
$sLimitClause .= $query->getOffset() . ", ";
|
54 |
-
}
|
55 |
-
$sLimitClause .= $query->getLimit();
|
56 |
-
}
|
57 |
-
$joinClause = '';
|
58 |
-
if ($query->hasMetaJoin()) {
|
59 |
-
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
60 |
-
$occurrence = new WSAL_Adapters_MySQL_Occurrence($this->connection);
|
61 |
-
$joinClause = ' LEFT JOIN '. $meta->GetTable() .' AS meta ON meta.occurrence_id = '. $occurrence->GetTable() .'.id ';
|
62 |
-
}
|
63 |
-
$fields = (empty($columns))? $fromDataSets[0] . '.*' : implode(',', $columns);
|
64 |
-
if (!empty($searchCondition)) {
|
65 |
-
$args[] = $searchCondition['args'];
|
66 |
-
}
|
67 |
-
return 'SELECT ' . $fields
|
68 |
-
. ' FROM ' . implode(',', $fromDataSets)
|
69 |
-
. $joinClause
|
70 |
-
. $sWhereClause
|
71 |
-
. (!empty($searchCondition) ? (empty($sWhereClause) ? " WHERE ".$searchCondition['sql'] : " AND ".$searchCondition['sql']) : '')
|
72 |
-
// @todo GROUP BY goes here
|
73 |
-
. (!empty($orderBys) ? (' ORDER BY ' . implode(', ', array_keys($orderBys)) . ' ' . implode(', ', array_values($orderBys))) : '')
|
74 |
-
. $sLimitClause;
|
75 |
-
}
|
76 |
-
|
77 |
-
protected function getActiveRecordAdapter()
|
78 |
-
{
|
79 |
-
return new WSAL_Adapters_MySQL_ActiveRecord($this->connection);
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* @return WSAL_Models_ActiveRecord[] Execute query and return data as $ar_cls objects.
|
84 |
-
*/
|
85 |
-
public function Execute($query)
|
86 |
-
{
|
87 |
-
$args = array();
|
88 |
-
$sql = $this->GetSql($query, $args);
|
89 |
-
|
90 |
-
$occurenceAdapter = $query->getConnector()->getAdapter("Occurrence");
|
91 |
-
|
92 |
-
if (in_array($occurenceAdapter->GetTable(), $query->getFrom())) {
|
93 |
-
return $occurenceAdapter->LoadMulti($sql, $args);
|
94 |
-
} else {
|
95 |
-
return $this->getActiveRecordAdapter()->LoadMulti($sql, $args);
|
96 |
-
}
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* @return int Use query for counting records.
|
101 |
-
*/
|
102 |
-
public function Count($query)
|
103 |
-
{
|
104 |
-
// back up columns, use COUNT as default column and generate sql
|
105 |
-
$cols = $query->getColumns();
|
106 |
-
$query->clearColumns();
|
107 |
-
$query->addColumn('COUNT(*)');
|
108 |
-
|
109 |
-
$args = array();
|
110 |
-
$sql = $this->GetSql($query, $args);
|
111 |
-
|
112 |
-
// restore columns
|
113 |
-
$query->setColumns($cols);
|
114 |
-
// execute query and return result
|
115 |
-
return $this->getActiveRecordAdapter()->CountQuery($sql, $args);
|
116 |
-
}
|
117 |
-
|
118 |
-
public function CountDelete($query)
|
119 |
-
{
|
120 |
-
$result = $this->GetSqlDelete($query, true);
|
121 |
-
// execute query and return result
|
122 |
-
return $this->getActiveRecordAdapter()->CountQuery($result['sql'], $result['args']);
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Use query for deleting records.
|
127 |
-
*/
|
128 |
-
public function Delete($query)
|
129 |
-
{
|
130 |
-
$result = $this->GetSqlDelete($query);
|
131 |
-
$this->DeleteMetas($query, $result['args']);
|
132 |
-
return $this->getActiveRecordAdapter()->DeleteQuery($result['sql'], $result['args']);
|
133 |
-
}
|
134 |
-
|
135 |
-
public function DeleteMetas($query, $args)
|
136 |
-
{
|
137 |
-
// back up columns, use COUNT as default column and generate sql
|
138 |
-
$cols = $query->getColumns();
|
139 |
-
$query->clearColumns();
|
140 |
-
$query->addColumn('id');
|
141 |
-
$sql = $this->GetSql($query);
|
142 |
-
// restore columns
|
143 |
-
$query->setColumns($cols);
|
144 |
-
|
145 |
-
$_wpdb = $this->connection;
|
146 |
-
$occ_ids = array();
|
147 |
-
$sql = (!empty($args) ? $_wpdb->prepare($sql, $args) : $sql);
|
148 |
-
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
149 |
-
$occ_ids[] = $data['id'];
|
150 |
-
}
|
151 |
-
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
152 |
-
$meta->DeleteByOccurenceIds($occ_ids);
|
153 |
-
}
|
154 |
-
|
155 |
-
public function GetSqlDelete($query, $getCount = false)
|
156 |
-
{
|
157 |
-
$result = array();
|
158 |
-
$args = array();
|
159 |
-
// back up columns, remove them for DELETE and generate sql
|
160 |
-
$cols = $query->getColumns();
|
161 |
-
$query->clearColumns();
|
162 |
-
|
163 |
-
$conditions = $query->getConditions();
|
164 |
-
|
165 |
-
$sWhereClause = "";
|
166 |
-
foreach ($conditions as $fieldName => $fieldValue) {
|
167 |
-
if (empty($sWhereClause)) {
|
168 |
-
$sWhereClause .= " WHERE ";
|
169 |
-
} else {
|
170 |
-
$sWhereClause .= " AND ";
|
171 |
-
}
|
172 |
-
$sWhereClause .= $fieldName;
|
173 |
-
$args[] = $fieldValue;
|
174 |
-
}
|
175 |
-
|
176 |
-
$fromDataSets = $query->getFrom();
|
177 |
-
$orderBys = $query->getOrderBy();
|
178 |
-
|
179 |
-
$sLimitClause = "";
|
180 |
-
if ($query->getLimit()) {
|
181 |
-
$sLimitClause .= " LIMIT ";
|
182 |
-
if ($query->getOffset()) {
|
183 |
-
$sLimitClause .= $query->getOffset() . ", ";
|
184 |
-
}
|
185 |
-
$sLimitClause .= $query->getLimit();
|
186 |
-
}
|
187 |
-
$result['sql'] = ($getCount ? 'SELECT COUNT(*) FROM ' : 'DELETE FROM ')
|
188 |
-
. implode(',', $fromDataSets)
|
189 |
-
. $sWhereClause
|
190 |
-
. (!empty($orderBys) ? (' ORDER BY ' . implode(', ', array_keys($orderBys)) . ' ' . implode(', ', array_values($orderBys))) : '')
|
191 |
-
. $sLimitClause;
|
192 |
-
$result['args'] = $args;
|
193 |
-
//restore columns
|
194 |
-
$query->setColumns($cols);
|
195 |
-
|
196 |
-
return $result;
|
197 |
-
}
|
198 |
-
|
199 |
-
public function SearchCondition($query)
|
200 |
-
{
|
201 |
-
$condition = $query->getSearchCondition();
|
202 |
-
if (empty($condition)) return null;
|
203 |
-
$searchConditions = array();
|
204 |
-
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
205 |
-
$occurrence = new WSAL_Adapters_MySQL_Occurrence($this->connection);
|
206 |
-
|
207 |
-
$searchConditions['sql'] = $occurrence->GetTable() .'.id IN (
|
208 |
-
SELECT DISTINCT occurrence_id
|
209 |
-
FROM ' . $meta->GetTable() . '
|
210 |
-
WHERE TRIM(BOTH "\"" FROM value) LIKE %s
|
211 |
-
)';
|
212 |
-
$searchConditions['args'] = "%". $condition. "%";
|
213 |
-
return $searchConditions;
|
214 |
-
}
|
215 |
-
|
216 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Adapters_MySQL_Query implements WSAL_Adapters_QueryInterface
|
4 |
+
{
|
5 |
+
protected $connection;
|
6 |
+
|
7 |
+
public function __construct($conn)
|
8 |
+
{
|
9 |
+
$this->connection = $conn;
|
10 |
+
}
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @return string Generated sql.
|
14 |
+
*/
|
15 |
+
protected function GetSql($query, &$args = array())
|
16 |
+
{
|
17 |
+
$conditions = $query->getConditions();
|
18 |
+
$searchCondition = $this->SearchCondition($query);
|
19 |
+
|
20 |
+
$sWhereClause = "";
|
21 |
+
foreach ($conditions as $fieldName => $fieldValue) {
|
22 |
+
if (empty($sWhereClause)) {
|
23 |
+
$sWhereClause .= " WHERE ";
|
24 |
+
} else {
|
25 |
+
$sWhereClause .= " AND ";
|
26 |
+
}
|
27 |
+
|
28 |
+
if (is_array($fieldValue)) {
|
29 |
+
$subWhereClause = "(";
|
30 |
+
foreach($fieldValue as $orFieldName => $orFieldValue) {
|
31 |
+
if ($subWhereClause != '(') {
|
32 |
+
$subWhereClause .= " OR ";
|
33 |
+
}
|
34 |
+
$subWhereClause .= $orFieldName;
|
35 |
+
$args[] = $orFieldValue;
|
36 |
+
}
|
37 |
+
$subWhereClause .= ")";
|
38 |
+
$sWhereClause .= $subWhereClause;
|
39 |
+
} else {
|
40 |
+
$sWhereClause .= $fieldName;
|
41 |
+
$args[] = $fieldValue;
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
$fromDataSets = $query->getFrom();
|
46 |
+
$columns = $query->getColumns();
|
47 |
+
$orderBys = $query->getOrderBy();
|
48 |
+
|
49 |
+
$sLimitClause = "";
|
50 |
+
if ($query->getLimit()) {
|
51 |
+
$sLimitClause .= " LIMIT ";
|
52 |
+
if ($query->getOffset()) {
|
53 |
+
$sLimitClause .= $query->getOffset() . ", ";
|
54 |
+
}
|
55 |
+
$sLimitClause .= $query->getLimit();
|
56 |
+
}
|
57 |
+
$joinClause = '';
|
58 |
+
if ($query->hasMetaJoin()) {
|
59 |
+
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
60 |
+
$occurrence = new WSAL_Adapters_MySQL_Occurrence($this->connection);
|
61 |
+
$joinClause = ' LEFT JOIN '. $meta->GetTable() .' AS meta ON meta.occurrence_id = '. $occurrence->GetTable() .'.id ';
|
62 |
+
}
|
63 |
+
$fields = (empty($columns))? $fromDataSets[0] . '.*' : implode(',', $columns);
|
64 |
+
if (!empty($searchCondition)) {
|
65 |
+
$args[] = $searchCondition['args'];
|
66 |
+
}
|
67 |
+
return 'SELECT ' . $fields
|
68 |
+
. ' FROM ' . implode(',', $fromDataSets)
|
69 |
+
. $joinClause
|
70 |
+
. $sWhereClause
|
71 |
+
. (!empty($searchCondition) ? (empty($sWhereClause) ? " WHERE ".$searchCondition['sql'] : " AND ".$searchCondition['sql']) : '')
|
72 |
+
// @todo GROUP BY goes here
|
73 |
+
. (!empty($orderBys) ? (' ORDER BY ' . implode(', ', array_keys($orderBys)) . ' ' . implode(', ', array_values($orderBys))) : '')
|
74 |
+
. $sLimitClause;
|
75 |
+
}
|
76 |
+
|
77 |
+
protected function getActiveRecordAdapter()
|
78 |
+
{
|
79 |
+
return new WSAL_Adapters_MySQL_ActiveRecord($this->connection);
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* @return WSAL_Models_ActiveRecord[] Execute query and return data as $ar_cls objects.
|
84 |
+
*/
|
85 |
+
public function Execute($query)
|
86 |
+
{
|
87 |
+
$args = array();
|
88 |
+
$sql = $this->GetSql($query, $args);
|
89 |
+
|
90 |
+
$occurenceAdapter = $query->getConnector()->getAdapter("Occurrence");
|
91 |
+
|
92 |
+
if (in_array($occurenceAdapter->GetTable(), $query->getFrom())) {
|
93 |
+
return $occurenceAdapter->LoadMulti($sql, $args);
|
94 |
+
} else {
|
95 |
+
return $this->getActiveRecordAdapter()->LoadMulti($sql, $args);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* @return int Use query for counting records.
|
101 |
+
*/
|
102 |
+
public function Count($query)
|
103 |
+
{
|
104 |
+
// back up columns, use COUNT as default column and generate sql
|
105 |
+
$cols = $query->getColumns();
|
106 |
+
$query->clearColumns();
|
107 |
+
$query->addColumn('COUNT(*)');
|
108 |
+
|
109 |
+
$args = array();
|
110 |
+
$sql = $this->GetSql($query, $args);
|
111 |
+
|
112 |
+
// restore columns
|
113 |
+
$query->setColumns($cols);
|
114 |
+
// execute query and return result
|
115 |
+
return $this->getActiveRecordAdapter()->CountQuery($sql, $args);
|
116 |
+
}
|
117 |
+
|
118 |
+
public function CountDelete($query)
|
119 |
+
{
|
120 |
+
$result = $this->GetSqlDelete($query, true);
|
121 |
+
// execute query and return result
|
122 |
+
return $this->getActiveRecordAdapter()->CountQuery($result['sql'], $result['args']);
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Use query for deleting records.
|
127 |
+
*/
|
128 |
+
public function Delete($query)
|
129 |
+
{
|
130 |
+
$result = $this->GetSqlDelete($query);
|
131 |
+
$this->DeleteMetas($query, $result['args']);
|
132 |
+
return $this->getActiveRecordAdapter()->DeleteQuery($result['sql'], $result['args']);
|
133 |
+
}
|
134 |
+
|
135 |
+
public function DeleteMetas($query, $args)
|
136 |
+
{
|
137 |
+
// back up columns, use COUNT as default column and generate sql
|
138 |
+
$cols = $query->getColumns();
|
139 |
+
$query->clearColumns();
|
140 |
+
$query->addColumn('id');
|
141 |
+
$sql = $this->GetSql($query);
|
142 |
+
// restore columns
|
143 |
+
$query->setColumns($cols);
|
144 |
+
|
145 |
+
$_wpdb = $this->connection;
|
146 |
+
$occ_ids = array();
|
147 |
+
$sql = (!empty($args) ? $_wpdb->prepare($sql, $args) : $sql);
|
148 |
+
foreach ($_wpdb->get_results($sql, ARRAY_A) as $data) {
|
149 |
+
$occ_ids[] = $data['id'];
|
150 |
+
}
|
151 |
+
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
152 |
+
$meta->DeleteByOccurenceIds($occ_ids);
|
153 |
+
}
|
154 |
+
|
155 |
+
public function GetSqlDelete($query, $getCount = false)
|
156 |
+
{
|
157 |
+
$result = array();
|
158 |
+
$args = array();
|
159 |
+
// back up columns, remove them for DELETE and generate sql
|
160 |
+
$cols = $query->getColumns();
|
161 |
+
$query->clearColumns();
|
162 |
+
|
163 |
+
$conditions = $query->getConditions();
|
164 |
+
|
165 |
+
$sWhereClause = "";
|
166 |
+
foreach ($conditions as $fieldName => $fieldValue) {
|
167 |
+
if (empty($sWhereClause)) {
|
168 |
+
$sWhereClause .= " WHERE ";
|
169 |
+
} else {
|
170 |
+
$sWhereClause .= " AND ";
|
171 |
+
}
|
172 |
+
$sWhereClause .= $fieldName;
|
173 |
+
$args[] = $fieldValue;
|
174 |
+
}
|
175 |
+
|
176 |
+
$fromDataSets = $query->getFrom();
|
177 |
+
$orderBys = $query->getOrderBy();
|
178 |
+
|
179 |
+
$sLimitClause = "";
|
180 |
+
if ($query->getLimit()) {
|
181 |
+
$sLimitClause .= " LIMIT ";
|
182 |
+
if ($query->getOffset()) {
|
183 |
+
$sLimitClause .= $query->getOffset() . ", ";
|
184 |
+
}
|
185 |
+
$sLimitClause .= $query->getLimit();
|
186 |
+
}
|
187 |
+
$result['sql'] = ($getCount ? 'SELECT COUNT(*) FROM ' : 'DELETE FROM ')
|
188 |
+
. implode(',', $fromDataSets)
|
189 |
+
. $sWhereClause
|
190 |
+
. (!empty($orderBys) ? (' ORDER BY ' . implode(', ', array_keys($orderBys)) . ' ' . implode(', ', array_values($orderBys))) : '')
|
191 |
+
. $sLimitClause;
|
192 |
+
$result['args'] = $args;
|
193 |
+
//restore columns
|
194 |
+
$query->setColumns($cols);
|
195 |
+
|
196 |
+
return $result;
|
197 |
+
}
|
198 |
+
|
199 |
+
public function SearchCondition($query)
|
200 |
+
{
|
201 |
+
$condition = $query->getSearchCondition();
|
202 |
+
if (empty($condition)) return null;
|
203 |
+
$searchConditions = array();
|
204 |
+
$meta = new WSAL_Adapters_MySQL_Meta($this->connection);
|
205 |
+
$occurrence = new WSAL_Adapters_MySQL_Occurrence($this->connection);
|
206 |
+
|
207 |
+
$searchConditions['sql'] = $occurrence->GetTable() .'.id IN (
|
208 |
+
SELECT DISTINCT occurrence_id
|
209 |
+
FROM ' . $meta->GetTable() . '
|
210 |
+
WHERE TRIM(BOTH "\"" FROM value) LIKE %s
|
211 |
+
)';
|
212 |
+
$searchConditions['args'] = "%". $condition. "%";
|
213 |
+
return $searchConditions;
|
214 |
+
}
|
215 |
+
|
216 |
+
}
|
classes/Models/Adapters/OccurrenceInterface.php
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
interface WSAL_Adapters_OccurrenceInterface
|
4 |
-
{
|
5 |
-
public function GetMeta($occurence);
|
6 |
-
public function GetNamedMeta($occurence, $name);
|
7 |
-
public function GetFirstNamedMeta($occurence, $names);
|
8 |
-
public static function GetNewestUnique($limit = PHP_INT_MAX);
|
9 |
-
public function CheckKnownUsers($args = array());
|
10 |
-
public function CheckUnKnownUsers($args = array());
|
11 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
interface WSAL_Adapters_OccurrenceInterface
|
4 |
+
{
|
5 |
+
public function GetMeta($occurence);
|
6 |
+
public function GetNamedMeta($occurence, $name);
|
7 |
+
public function GetFirstNamedMeta($occurence, $names);
|
8 |
+
public static function GetNewestUnique($limit = PHP_INT_MAX);
|
9 |
+
public function CheckKnownUsers($args = array());
|
10 |
+
public function CheckUnKnownUsers($args = array());
|
11 |
+
}
|
classes/Models/Adapters/QueryInterface.php
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
interface WSAL_Adapters_QueryInterface
|
4 |
-
{
|
5 |
-
public function Execute($query);
|
6 |
-
public function Count($query);
|
7 |
-
public function Delete($query);
|
8 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
interface WSAL_Adapters_QueryInterface
|
4 |
+
{
|
5 |
+
public function Execute($query);
|
6 |
+
public function Count($query);
|
7 |
+
public function Delete($query);
|
8 |
+
}
|
classes/Models/Meta.php
CHANGED
@@ -1,34 +1,34 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Models_Meta extends WSAL_Models_ActiveRecord {
|
4 |
-
|
5 |
-
protected $adapterName = "Meta";
|
6 |
-
|
7 |
-
public $id = 0;
|
8 |
-
public $occurrence_id = 0;
|
9 |
-
public $name = '';
|
10 |
-
public $value = array(); // force mixed type
|
11 |
-
|
12 |
-
public function SaveMeta()
|
13 |
-
{
|
14 |
-
$this->_state = self::STATE_UNKNOWN;
|
15 |
-
$updateId = $this->getId();
|
16 |
-
$result = $this->getAdapter()->Save($this);
|
17 |
-
|
18 |
-
if ($result !== false) {
|
19 |
-
$this->_state = (!empty($updateId))?self::STATE_UPDATED:self::STATE_CREATED;
|
20 |
-
}
|
21 |
-
return $result;
|
22 |
-
}
|
23 |
-
|
24 |
-
public function UpdateByNameAndOccurenceId($name, $value, $occurrenceId)
|
25 |
-
{
|
26 |
-
$meta = $this->getAdapter()->LoadByNameAndOccurenceId($name, $occurrenceId);
|
27 |
-
$this->id = $meta['id'];
|
28 |
-
$this->occurrence_id = $meta['occurrence_id'];
|
29 |
-
$this->name = $meta['name'];
|
30 |
-
$this->value = $value;
|
31 |
-
$this->saveMeta();
|
32 |
-
}
|
33 |
-
|
34 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Models_Meta extends WSAL_Models_ActiveRecord {
|
4 |
+
|
5 |
+
protected $adapterName = "Meta";
|
6 |
+
|
7 |
+
public $id = 0;
|
8 |
+
public $occurrence_id = 0;
|
9 |
+
public $name = '';
|
10 |
+
public $value = array(); // force mixed type
|
11 |
+
|
12 |
+
public function SaveMeta()
|
13 |
+
{
|
14 |
+
$this->_state = self::STATE_UNKNOWN;
|
15 |
+
$updateId = $this->getId();
|
16 |
+
$result = $this->getAdapter()->Save($this);
|
17 |
+
|
18 |
+
if ($result !== false) {
|
19 |
+
$this->_state = (!empty($updateId))?self::STATE_UPDATED:self::STATE_CREATED;
|
20 |
+
}
|
21 |
+
return $result;
|
22 |
+
}
|
23 |
+
|
24 |
+
public function UpdateByNameAndOccurenceId($name, $value, $occurrenceId)
|
25 |
+
{
|
26 |
+
$meta = $this->getAdapter()->LoadByNameAndOccurenceId($name, $occurrenceId);
|
27 |
+
$this->id = $meta['id'];
|
28 |
+
$this->occurrence_id = $meta['occurrence_id'];
|
29 |
+
$this->name = $meta['name'];
|
30 |
+
$this->value = $value;
|
31 |
+
$this->saveMeta();
|
32 |
+
}
|
33 |
+
|
34 |
+
}
|
classes/Models/Occurrence.php
CHANGED
@@ -1,193 +1,193 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Models_Occurrence extends WSAL_Models_ActiveRecord
|
4 |
-
{
|
5 |
-
|
6 |
-
public $id = 0;
|
7 |
-
public $site_id = 0;
|
8 |
-
public $alert_id = 0;
|
9 |
-
public $created_on = 0.0;
|
10 |
-
public $is_read = false;
|
11 |
-
public $is_migrated = false;
|
12 |
-
protected $adapterName = "Occurrence";
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Returns the alert related to this occurrence.
|
16 |
-
* @return WSAL_Alert
|
17 |
-
*/
|
18 |
-
public function GetAlert()
|
19 |
-
{
|
20 |
-
return WpSecurityAuditLog::GetInstance()->alerts->GetAlert($this->alert_id);
|
21 |
-
}
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Returns the value of a meta item.
|
25 |
-
* @param string $name Name of meta item.
|
26 |
-
* @param mixed $default Default value returned when meta does not exist.
|
27 |
-
* @return mixed The value, if meta item does not exist $default returned.
|
28 |
-
*/
|
29 |
-
public function GetMetaValue($name, $default = array())
|
30 |
-
{
|
31 |
-
//get meta adapter
|
32 |
-
//call the function ($name, $this->getId())
|
33 |
-
$meta = $this->getAdapter()->GetNamedMeta($this, $name);
|
34 |
-
return maybe_unserialize($meta['value']);
|
35 |
-
|
36 |
-
//TO DO: re-introduce add is loaded check before running query
|
37 |
-
//return $meta->IsLoaded() ? $meta->value : $default;
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Set the value of a meta item (creates or updates meta item).
|
42 |
-
* @param string $name Meta name.
|
43 |
-
* @param mixed $value Meta value.
|
44 |
-
*/
|
45 |
-
public function SetMetaValue($name, $value)
|
46 |
-
{
|
47 |
-
//get meta adapter
|
48 |
-
$model = new WSAL_Models_Meta();
|
49 |
-
$model->occurrence_id = $this->getId();
|
50 |
-
$model->name = $name;
|
51 |
-
$model->value = maybe_serialize($value);
|
52 |
-
$model->SaveMeta();
|
53 |
-
}
|
54 |
-
|
55 |
-
public function UpdateMetaValue($name, $value)
|
56 |
-
{
|
57 |
-
$model = new WSAL_Models_Meta();
|
58 |
-
$model->UpdateByNameAndOccurenceId($name, $value, $this->getId());
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* Returns a key-value pair of meta data.
|
63 |
-
* @return array
|
64 |
-
*/
|
65 |
-
public function GetMetaArray()
|
66 |
-
{
|
67 |
-
$result = array();
|
68 |
-
$metas = $this->getAdapter()->GetMultiMeta($this);
|
69 |
-
foreach ($metas as $meta) {
|
70 |
-
$result[$meta->name] = maybe_unserialize($meta->value);
|
71 |
-
}
|
72 |
-
return $result;
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Creates or updates all meta data passed as an array of meta-key/meta-value pairs.
|
77 |
-
* @param array $data New meta data.
|
78 |
-
*/
|
79 |
-
public function SetMeta($data)
|
80 |
-
{
|
81 |
-
foreach ((array)$data as $key => $val) {
|
82 |
-
$this->SetMetaValue($key, $val);
|
83 |
-
}
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* @param callable|null $metaFormatter (Optional) Meta formatter callback.
|
88 |
-
* @return string Full-formatted message.
|
89 |
-
*/
|
90 |
-
public function GetMessage($metaFormatter = null)
|
91 |
-
{
|
92 |
-
if (!isset($this->_cachedmessage)) {
|
93 |
-
// get correct message entry
|
94 |
-
if ($this->is_migrated) {
|
95 |
-
$this->_cachedmessage = $this->GetMetaValue('MigratedMesg', false);
|
96 |
-
}
|
97 |
-
if (!$this->is_migrated || !$this->_cachedmessage) {
|
98 |
-
$this->_cachedmessage = $this->GetAlert()->mesg;
|
99 |
-
}
|
100 |
-
// fill variables in message
|
101 |
-
$this->_cachedmessage = $this->GetAlert()->GetMessage($this->GetMetaArray(), $metaFormatter, $this->_cachedmessage);
|
102 |
-
}
|
103 |
-
return $this->_cachedmessage;
|
104 |
-
}
|
105 |
-
|
106 |
-
/**
|
107 |
-
* Delete occurrence as well as associated meta data.
|
108 |
-
* @return boolean True on success, false on failure.
|
109 |
-
*/
|
110 |
-
public function Delete()
|
111 |
-
{
|
112 |
-
foreach ($this->getAdapter()->GetMeta() as $meta) {
|
113 |
-
$meta->Delete();
|
114 |
-
}
|
115 |
-
return parent::Delete();
|
116 |
-
}
|
117 |
-
|
118 |
-
/**
|
119 |
-
* @return string User's username.
|
120 |
-
*/
|
121 |
-
public function GetUsername()
|
122 |
-
{
|
123 |
-
$meta = $this->getAdapter()->GetFirstNamedMeta($this, array('Username', 'CurrentUserID'));
|
124 |
-
if ($meta) {
|
125 |
-
switch(true){
|
126 |
-
case $meta->name == 'Username':
|
127 |
-
return $meta->value;
|
128 |
-
case $meta->name == 'CurrentUserID':
|
129 |
-
return ($data = get_userdata($meta->value)) ? $data->user_login : null;
|
130 |
-
}
|
131 |
-
}
|
132 |
-
return null;
|
133 |
-
}
|
134 |
-
|
135 |
-
/**
|
136 |
-
* @return string IP address of request.
|
137 |
-
*/
|
138 |
-
public function GetSourceIP()
|
139 |
-
{
|
140 |
-
return $this->GetMetaValue('ClientIP', '');
|
141 |
-
}
|
142 |
-
|
143 |
-
/**
|
144 |
-
* @return string IP address of request (from proxies etc).
|
145 |
-
*/
|
146 |
-
public function GetOtherIPs()
|
147 |
-
{
|
148 |
-
$result = array();
|
149 |
-
$data = (array)$this->GetMetaValue('OtherIPs', array());
|
150 |
-
foreach ($data as $ips) {
|
151 |
-
foreach ($ips as $ip) {
|
152 |
-
$result[] = $ip;
|
153 |
-
}
|
154 |
-
}
|
155 |
-
return array_unique($result);
|
156 |
-
}
|
157 |
-
|
158 |
-
/**
|
159 |
-
* @return array Array of user roles.
|
160 |
-
*/
|
161 |
-
public function GetUserRoles()
|
162 |
-
{
|
163 |
-
return $this->GetMetaValue('CurrentUserRoles', array());
|
164 |
-
}
|
165 |
-
|
166 |
-
/**
|
167 |
-
* @return float Number of seconds (and microseconds as fraction) since unix Day 0.
|
168 |
-
* @todo This needs some caching.
|
169 |
-
*/
|
170 |
-
protected function GetMicrotime()
|
171 |
-
{
|
172 |
-
return microtime(true);// + get_option('gmt_offset') * HOUR_IN_SECONDS;
|
173 |
-
}
|
174 |
-
|
175 |
-
/**
|
176 |
-
* Finds occurences of the same type by IP and Username within specified time frame
|
177 |
-
* @param string $ipAddress
|
178 |
-
* @param string $username
|
179 |
-
* @param int $alertId Alert type we are lookign for
|
180 |
-
* @param int $siteId
|
181 |
-
* @param $startTime mktime
|
182 |
-
* @param $endTime mktime
|
183 |
-
*/
|
184 |
-
public function CheckKnownUsers($args = array())
|
185 |
-
{
|
186 |
-
return $this->getAdapter()->CheckKnownUsers($args);
|
187 |
-
}
|
188 |
-
|
189 |
-
public function CheckUnKnownUsers($args = array())
|
190 |
-
{
|
191 |
-
return $this->getAdapter()->CheckUnKnownUsers($args);
|
192 |
-
}
|
193 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Models_Occurrence extends WSAL_Models_ActiveRecord
|
4 |
+
{
|
5 |
+
|
6 |
+
public $id = 0;
|
7 |
+
public $site_id = 0;
|
8 |
+
public $alert_id = 0;
|
9 |
+
public $created_on = 0.0;
|
10 |
+
public $is_read = false;
|
11 |
+
public $is_migrated = false;
|
12 |
+
protected $adapterName = "Occurrence";
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Returns the alert related to this occurrence.
|
16 |
+
* @return WSAL_Alert
|
17 |
+
*/
|
18 |
+
public function GetAlert()
|
19 |
+
{
|
20 |
+
return WpSecurityAuditLog::GetInstance()->alerts->GetAlert($this->alert_id);
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Returns the value of a meta item.
|
25 |
+
* @param string $name Name of meta item.
|
26 |
+
* @param mixed $default Default value returned when meta does not exist.
|
27 |
+
* @return mixed The value, if meta item does not exist $default returned.
|
28 |
+
*/
|
29 |
+
public function GetMetaValue($name, $default = array())
|
30 |
+
{
|
31 |
+
//get meta adapter
|
32 |
+
//call the function ($name, $this->getId())
|
33 |
+
$meta = $this->getAdapter()->GetNamedMeta($this, $name);
|
34 |
+
return maybe_unserialize($meta['value']);
|
35 |
+
|
36 |
+
//TO DO: re-introduce add is loaded check before running query
|
37 |
+
//return $meta->IsLoaded() ? $meta->value : $default;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Set the value of a meta item (creates or updates meta item).
|
42 |
+
* @param string $name Meta name.
|
43 |
+
* @param mixed $value Meta value.
|
44 |
+
*/
|
45 |
+
public function SetMetaValue($name, $value)
|
46 |
+
{
|
47 |
+
//get meta adapter
|
48 |
+
$model = new WSAL_Models_Meta();
|
49 |
+
$model->occurrence_id = $this->getId();
|
50 |
+
$model->name = $name;
|
51 |
+
$model->value = maybe_serialize($value);
|
52 |
+
$model->SaveMeta();
|
53 |
+
}
|
54 |
+
|
55 |
+
public function UpdateMetaValue($name, $value)
|
56 |
+
{
|
57 |
+
$model = new WSAL_Models_Meta();
|
58 |
+
$model->UpdateByNameAndOccurenceId($name, $value, $this->getId());
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Returns a key-value pair of meta data.
|
63 |
+
* @return array
|
64 |
+
*/
|
65 |
+
public function GetMetaArray()
|
66 |
+
{
|
67 |
+
$result = array();
|
68 |
+
$metas = $this->getAdapter()->GetMultiMeta($this);
|
69 |
+
foreach ($metas as $meta) {
|
70 |
+
$result[$meta->name] = maybe_unserialize($meta->value);
|
71 |
+
}
|
72 |
+
return $result;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Creates or updates all meta data passed as an array of meta-key/meta-value pairs.
|
77 |
+
* @param array $data New meta data.
|
78 |
+
*/
|
79 |
+
public function SetMeta($data)
|
80 |
+
{
|
81 |
+
foreach ((array)$data as $key => $val) {
|
82 |
+
$this->SetMetaValue($key, $val);
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* @param callable|null $metaFormatter (Optional) Meta formatter callback.
|
88 |
+
* @return string Full-formatted message.
|
89 |
+
*/
|
90 |
+
public function GetMessage($metaFormatter = null)
|
91 |
+
{
|
92 |
+
if (!isset($this->_cachedmessage)) {
|
93 |
+
// get correct message entry
|
94 |
+
if ($this->is_migrated) {
|
95 |
+
$this->_cachedmessage = $this->GetMetaValue('MigratedMesg', false);
|
96 |
+
}
|
97 |
+
if (!$this->is_migrated || !$this->_cachedmessage) {
|
98 |
+
$this->_cachedmessage = $this->GetAlert()->mesg;
|
99 |
+
}
|
100 |
+
// fill variables in message
|
101 |
+
$this->_cachedmessage = $this->GetAlert()->GetMessage($this->GetMetaArray(), $metaFormatter, $this->_cachedmessage);
|
102 |
+
}
|
103 |
+
return $this->_cachedmessage;
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Delete occurrence as well as associated meta data.
|
108 |
+
* @return boolean True on success, false on failure.
|
109 |
+
*/
|
110 |
+
public function Delete()
|
111 |
+
{
|
112 |
+
foreach ($this->getAdapter()->GetMeta() as $meta) {
|
113 |
+
$meta->Delete();
|
114 |
+
}
|
115 |
+
return parent::Delete();
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* @return string User's username.
|
120 |
+
*/
|
121 |
+
public function GetUsername()
|
122 |
+
{
|
123 |
+
$meta = $this->getAdapter()->GetFirstNamedMeta($this, array('Username', 'CurrentUserID'));
|
124 |
+
if ($meta) {
|
125 |
+
switch(true){
|
126 |
+
case $meta->name == 'Username':
|
127 |
+
return $meta->value;
|
128 |
+
case $meta->name == 'CurrentUserID':
|
129 |
+
return ($data = get_userdata($meta->value)) ? $data->user_login : null;
|
130 |
+
}
|
131 |
+
}
|
132 |
+
return null;
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* @return string IP address of request.
|
137 |
+
*/
|
138 |
+
public function GetSourceIP()
|
139 |
+
{
|
140 |
+
return $this->GetMetaValue('ClientIP', '');
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* @return string IP address of request (from proxies etc).
|
145 |
+
*/
|
146 |
+
public function GetOtherIPs()
|
147 |
+
{
|
148 |
+
$result = array();
|
149 |
+
$data = (array)$this->GetMetaValue('OtherIPs', array());
|
150 |
+
foreach ($data as $ips) {
|
151 |
+
foreach ($ips as $ip) {
|
152 |
+
$result[] = $ip;
|
153 |
+
}
|
154 |
+
}
|
155 |
+
return array_unique($result);
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* @return array Array of user roles.
|
160 |
+
*/
|
161 |
+
public function GetUserRoles()
|
162 |
+
{
|
163 |
+
return $this->GetMetaValue('CurrentUserRoles', array());
|
164 |
+
}
|
165 |
+
|
166 |
+
/**
|
167 |
+
* @return float Number of seconds (and microseconds as fraction) since unix Day 0.
|
168 |
+
* @todo This needs some caching.
|
169 |
+
*/
|
170 |
+
protected function GetMicrotime()
|
171 |
+
{
|
172 |
+
return microtime(true);// + get_option('gmt_offset') * HOUR_IN_SECONDS;
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Finds occurences of the same type by IP and Username within specified time frame
|
177 |
+
* @param string $ipAddress
|
178 |
+
* @param string $username
|
179 |
+
* @param int $alertId Alert type we are lookign for
|
180 |
+
* @param int $siteId
|
181 |
+
* @param $startTime mktime
|
182 |
+
* @param $endTime mktime
|
183 |
+
*/
|
184 |
+
public function CheckKnownUsers($args = array())
|
185 |
+
{
|
186 |
+
return $this->getAdapter()->CheckKnownUsers($args);
|
187 |
+
}
|
188 |
+
|
189 |
+
public function CheckUnKnownUsers($args = array())
|
190 |
+
{
|
191 |
+
return $this->getAdapter()->CheckUnKnownUsers($args);
|
192 |
+
}
|
193 |
+
}
|
classes/Models/OccurrenceQuery.php
CHANGED
@@ -1,29 +1,29 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Models_OccurrenceQuery extends WSAL_Models_Query
|
4 |
-
{
|
5 |
-
protected $arguments = array();
|
6 |
-
|
7 |
-
public function addArgument($field, $value)
|
8 |
-
{
|
9 |
-
$this->arguments[$field] = $value;
|
10 |
-
return $this;
|
11 |
-
}
|
12 |
-
|
13 |
-
public function clearArguments()
|
14 |
-
{
|
15 |
-
$this->arguments = array();
|
16 |
-
return $this;
|
17 |
-
}
|
18 |
-
|
19 |
-
public function __construct()
|
20 |
-
{
|
21 |
-
parent::__construct();
|
22 |
-
|
23 |
-
//TO DO: Consider if Get Table is the right method to call given that this is mysql specific
|
24 |
-
$this->addFrom(
|
25 |
-
$this->getConnector()->getAdapter("Occurrence")->GetTable()
|
26 |
-
);
|
27 |
-
}
|
28 |
-
|
29 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Models_OccurrenceQuery extends WSAL_Models_Query
|
4 |
+
{
|
5 |
+
protected $arguments = array();
|
6 |
+
|
7 |
+
public function addArgument($field, $value)
|
8 |
+
{
|
9 |
+
$this->arguments[$field] = $value;
|
10 |
+
return $this;
|
11 |
+
}
|
12 |
+
|
13 |
+
public function clearArguments()
|
14 |
+
{
|
15 |
+
$this->arguments = array();
|
16 |
+
return $this;
|
17 |
+
}
|
18 |
+
|
19 |
+
public function __construct()
|
20 |
+
{
|
21 |
+
parent::__construct();
|
22 |
+
|
23 |
+
//TO DO: Consider if Get Table is the right method to call given that this is mysql specific
|
24 |
+
$this->addFrom(
|
25 |
+
$this->getConnector()->getAdapter("Occurrence")->GetTable()
|
26 |
+
);
|
27 |
+
}
|
28 |
+
|
29 |
+
}
|
classes/Models/Option.php
CHANGED
@@ -1,80 +1,80 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Wordpress options are always loaded from the default wordpress database.
|
5 |
-
*/
|
6 |
-
class WSAL_Models_Option extends WSAL_Models_ActiveRecord
|
7 |
-
{
|
8 |
-
|
9 |
-
protected $adapterName = "Option";
|
10 |
-
public $id = '';
|
11 |
-
public $option_name = '';
|
12 |
-
public $option_value = '';
|
13 |
-
/**
|
14 |
-
* Options are always stored in WPDB. This setting ensures that
|
15 |
-
*/
|
16 |
-
protected $useDefaultAdapter = true;
|
17 |
-
|
18 |
-
public function SetOptionValue($name, $value)
|
19 |
-
{
|
20 |
-
$option = $this->getAdapter()->GetNamedOption($name);
|
21 |
-
$this->id = $option['id'];
|
22 |
-
$this->option_name = $name;
|
23 |
-
// Serialize if $value is array or object
|
24 |
-
$value = maybe_serialize($value);
|
25 |
-
$this->option_value = $value;
|
26 |
-
return $this->Save();
|
27 |
-
}
|
28 |
-
|
29 |
-
public function GetOptionValue($name, $default = array())
|
30 |
-
{
|
31 |
-
$option = $this->getAdapter()->GetNamedOption($name);
|
32 |
-
$this->option_value = (!empty($option)) ? $option['option_value'] : null;
|
33 |
-
if (!empty($this->option_value)) {
|
34 |
-
$this->_state = self::STATE_LOADED;
|
35 |
-
}
|
36 |
-
// Unerialize if $value is array or object
|
37 |
-
$this->option_value = maybe_unserialize($this->option_value);
|
38 |
-
return $this->IsLoaded() ? $this->option_value : $default;
|
39 |
-
}
|
40 |
-
|
41 |
-
public function Save()
|
42 |
-
{
|
43 |
-
$this->_state = self::STATE_UNKNOWN;
|
44 |
-
|
45 |
-
$updateId = $this->getId();
|
46 |
-
$result = $this->getAdapter()->Save($this);
|
47 |
-
|
48 |
-
if ($result !== false) {
|
49 |
-
$this->_state = (!empty($updateId))?self::STATE_UPDATED:self::STATE_CREATED;
|
50 |
-
}
|
51 |
-
return $result;
|
52 |
-
}
|
53 |
-
|
54 |
-
public function GetNotificationsSetting($opt_prefix)
|
55 |
-
{
|
56 |
-
return $this->getAdapter()->GetNotificationsSetting($opt_prefix);
|
57 |
-
}
|
58 |
-
|
59 |
-
public function GetNotification($id)
|
60 |
-
{
|
61 |
-
return $this->LoadData(
|
62 |
-
$this->getAdapter()->GetNotification($id)
|
63 |
-
);
|
64 |
-
}
|
65 |
-
|
66 |
-
public function DeleteByName($name)
|
67 |
-
{
|
68 |
-
return $this->getAdapter()->DeleteByName($name);
|
69 |
-
}
|
70 |
-
|
71 |
-
public function DeleteByPrefix($opt_prefix)
|
72 |
-
{
|
73 |
-
return $this->getAdapter()->DeleteByPrefix($opt_prefix);
|
74 |
-
}
|
75 |
-
|
76 |
-
public function CountNotifications($opt_prefix)
|
77 |
-
{
|
78 |
-
return $this->getAdapter()->CountNotifications($opt_prefix);
|
79 |
-
}
|
80 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Wordpress options are always loaded from the default wordpress database.
|
5 |
+
*/
|
6 |
+
class WSAL_Models_Option extends WSAL_Models_ActiveRecord
|
7 |
+
{
|
8 |
+
|
9 |
+
protected $adapterName = "Option";
|
10 |
+
public $id = '';
|
11 |
+
public $option_name = '';
|
12 |
+
public $option_value = '';
|
13 |
+
/**
|
14 |
+
* Options are always stored in WPDB. This setting ensures that
|
15 |
+
*/
|
16 |
+
protected $useDefaultAdapter = true;
|
17 |
+
|
18 |
+
public function SetOptionValue($name, $value)
|
19 |
+
{
|
20 |
+
$option = $this->getAdapter()->GetNamedOption($name);
|
21 |
+
$this->id = $option['id'];
|
22 |
+
$this->option_name = $name;
|
23 |
+
// Serialize if $value is array or object
|
24 |
+
$value = maybe_serialize($value);
|
25 |
+
$this->option_value = $value;
|
26 |
+
return $this->Save();
|
27 |
+
}
|
28 |
+
|
29 |
+
public function GetOptionValue($name, $default = array())
|
30 |
+
{
|
31 |
+
$option = $this->getAdapter()->GetNamedOption($name);
|
32 |
+
$this->option_value = (!empty($option)) ? $option['option_value'] : null;
|
33 |
+
if (!empty($this->option_value)) {
|
34 |
+
$this->_state = self::STATE_LOADED;
|
35 |
+
}
|
36 |
+
// Unerialize if $value is array or object
|
37 |
+
$this->option_value = maybe_unserialize($this->option_value);
|
38 |
+
return $this->IsLoaded() ? $this->option_value : $default;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function Save()
|
42 |
+
{
|
43 |
+
$this->_state = self::STATE_UNKNOWN;
|
44 |
+
|
45 |
+
$updateId = $this->getId();
|
46 |
+
$result = $this->getAdapter()->Save($this);
|
47 |
+
|
48 |
+
if ($result !== false) {
|
49 |
+
$this->_state = (!empty($updateId))?self::STATE_UPDATED:self::STATE_CREATED;
|
50 |
+
}
|
51 |
+
return $result;
|
52 |
+
}
|
53 |
+
|
54 |
+
public function GetNotificationsSetting($opt_prefix)
|
55 |
+
{
|
56 |
+
return $this->getAdapter()->GetNotificationsSetting($opt_prefix);
|
57 |
+
}
|
58 |
+
|
59 |
+
public function GetNotification($id)
|
60 |
+
{
|
61 |
+
return $this->LoadData(
|
62 |
+
$this->getAdapter()->GetNotification($id)
|
63 |
+
);
|
64 |
+
}
|
65 |
+
|
66 |
+
public function DeleteByName($name)
|
67 |
+
{
|
68 |
+
return $this->getAdapter()->DeleteByName($name);
|
69 |
+
}
|
70 |
+
|
71 |
+
public function DeleteByPrefix($opt_prefix)
|
72 |
+
{
|
73 |
+
return $this->getAdapter()->DeleteByPrefix($opt_prefix);
|
74 |
+
}
|
75 |
+
|
76 |
+
public function CountNotifications($opt_prefix)
|
77 |
+
{
|
78 |
+
return $this->getAdapter()->CountNotifications($opt_prefix);
|
79 |
+
}
|
80 |
+
}
|
classes/Models/Query.php
CHANGED
@@ -1,187 +1,187 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Models_Query
|
4 |
-
{
|
5 |
-
protected $columns = array();
|
6 |
-
protected $conditions = array();
|
7 |
-
protected $orderBy = array();
|
8 |
-
protected $offset = null;
|
9 |
-
protected $limit = null;
|
10 |
-
protected $from = array();
|
11 |
-
protected $meta_join = false;
|
12 |
-
protected $searchCondition = null;
|
13 |
-
protected $useDefaultAdapter = false;
|
14 |
-
|
15 |
-
public function __construct()
|
16 |
-
{
|
17 |
-
|
18 |
-
}
|
19 |
-
|
20 |
-
public function getConnector()
|
21 |
-
{
|
22 |
-
if (!empty($this->connector)) {
|
23 |
-
return $this->connector;
|
24 |
-
}
|
25 |
-
if ($this->useDefaultAdapter) {
|
26 |
-
$this->connector = WSAL_Connector_ConnectorFactory::GetDefaultConnector();
|
27 |
-
} else {
|
28 |
-
$this->connector = WSAL_Connector_ConnectorFactory::GetConnector();
|
29 |
-
}
|
30 |
-
return $this->connector;
|
31 |
-
}
|
32 |
-
|
33 |
-
public function getAdapter()
|
34 |
-
{
|
35 |
-
return $this->getConnector()->getAdapter('Query');
|
36 |
-
}
|
37 |
-
|
38 |
-
public function addColumn($column)
|
39 |
-
{
|
40 |
-
$this->columns[] = $column;
|
41 |
-
return $this;
|
42 |
-
}
|
43 |
-
|
44 |
-
public function clearColumns()
|
45 |
-
{
|
46 |
-
$this->columns = array();
|
47 |
-
return $this;
|
48 |
-
}
|
49 |
-
|
50 |
-
public function getColumns()
|
51 |
-
{
|
52 |
-
return $this->columns;
|
53 |
-
}
|
54 |
-
|
55 |
-
public function setColumns($columns)
|
56 |
-
{
|
57 |
-
$this->columns = $columns;
|
58 |
-
return $this;
|
59 |
-
}
|
60 |
-
|
61 |
-
public function addCondition($field, $value)
|
62 |
-
{
|
63 |
-
$this->conditions[$field] = $value;
|
64 |
-
return $this;
|
65 |
-
}
|
66 |
-
|
67 |
-
public function addORCondition($aConditions)
|
68 |
-
{
|
69 |
-
$this->conditions[] = $aConditions;
|
70 |
-
}
|
71 |
-
|
72 |
-
public function clearConditions()
|
73 |
-
{
|
74 |
-
$this->conditions = array();
|
75 |
-
return $this;
|
76 |
-
}
|
77 |
-
|
78 |
-
public function getConditions()
|
79 |
-
{
|
80 |
-
return $this->conditions;
|
81 |
-
}
|
82 |
-
|
83 |
-
public function addOrderBy($field, $isDescending = false)
|
84 |
-
{
|
85 |
-
$order = ($isDescending) ? 'DESC' : 'ASC';
|
86 |
-
$this->orderBy[$field] = $order;
|
87 |
-
return $this;
|
88 |
-
}
|
89 |
-
|
90 |
-
public function clearOrderBy()
|
91 |
-
{
|
92 |
-
$this->orderBy = array();
|
93 |
-
return $this;
|
94 |
-
}
|
95 |
-
|
96 |
-
public function getOrderBy()
|
97 |
-
{
|
98 |
-
return $this->orderBy;
|
99 |
-
}
|
100 |
-
|
101 |
-
public function addFrom($fromDataSet)
|
102 |
-
{
|
103 |
-
$this->from[] = $fromDataSet;
|
104 |
-
return $this;
|
105 |
-
}
|
106 |
-
|
107 |
-
public function clearFrom()
|
108 |
-
{
|
109 |
-
$this->from = array();
|
110 |
-
return $this;
|
111 |
-
}
|
112 |
-
|
113 |
-
public function getFrom()
|
114 |
-
{
|
115 |
-
return $this->from;
|
116 |
-
}
|
117 |
-
|
118 |
-
/**
|
119 |
-
* Gets the value of limit.
|
120 |
-
*
|
121 |
-
* @return mixed
|
122 |
-
*/
|
123 |
-
public function getLimit()
|
124 |
-
{
|
125 |
-
return $this->limit;
|
126 |
-
}
|
127 |
-
|
128 |
-
/**
|
129 |
-
* Sets the value of limit.
|
130 |
-
*
|
131 |
-
* @param mixed $limit the limit
|
132 |
-
*
|
133 |
-
* @return self
|
134 |
-
*/
|
135 |
-
public function setLimit($limit)
|
136 |
-
{
|
137 |
-
$this->limit = $limit;
|
138 |
-
|
139 |
-
return $this;
|
140 |
-
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
* Gets the value of offset.
|
144 |
-
*
|
145 |
-
* @return mixed
|
146 |
-
*/
|
147 |
-
public function getOffset()
|
148 |
-
{
|
149 |
-
return $this->offset;
|
150 |
-
}
|
151 |
-
|
152 |
-
/**
|
153 |
-
* Sets the value of offset.
|
154 |
-
*
|
155 |
-
* @param mixed $offset the offset
|
156 |
-
*
|
157 |
-
* @return self
|
158 |
-
*/
|
159 |
-
public function setOffset($offset)
|
160 |
-
{
|
161 |
-
$this->offset = $offset;
|
162 |
-
|
163 |
-
return $this;
|
164 |
-
}
|
165 |
-
|
166 |
-
public function addSearchCondition($value)
|
167 |
-
{
|
168 |
-
$this->searchCondition = $value;
|
169 |
-
return $this;
|
170 |
-
}
|
171 |
-
|
172 |
-
public function getSearchCondition()
|
173 |
-
{
|
174 |
-
return $this->searchCondition;
|
175 |
-
}
|
176 |
-
|
177 |
-
public function hasMetaJoin()
|
178 |
-
{
|
179 |
-
return $this->meta_join;
|
180 |
-
}
|
181 |
-
|
182 |
-
public function addMetaJoin()
|
183 |
-
{
|
184 |
-
$this->meta_join = true;
|
185 |
-
return $this;
|
186 |
-
}
|
187 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Models_Query
|
4 |
+
{
|
5 |
+
protected $columns = array();
|
6 |
+
protected $conditions = array();
|
7 |
+
protected $orderBy = array();
|
8 |
+
protected $offset = null;
|
9 |
+
protected $limit = null;
|
10 |
+
protected $from = array();
|
11 |
+
protected $meta_join = false;
|
12 |
+
protected $searchCondition = null;
|
13 |
+
protected $useDefaultAdapter = false;
|
14 |
+
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
|
18 |
+
}
|
19 |
+
|
20 |
+
public function getConnector()
|
21 |
+
{
|
22 |
+
if (!empty($this->connector)) {
|
23 |
+
return $this->connector;
|
24 |
+
}
|
25 |
+
if ($this->useDefaultAdapter) {
|
26 |
+
$this->connector = WSAL_Connector_ConnectorFactory::GetDefaultConnector();
|
27 |
+
} else {
|
28 |
+
$this->connector = WSAL_Connector_ConnectorFactory::GetConnector();
|
29 |
+
}
|
30 |
+
return $this->connector;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getAdapter()
|
34 |
+
{
|
35 |
+
return $this->getConnector()->getAdapter('Query');
|
36 |
+
}
|
37 |
+
|
38 |
+
public function addColumn($column)
|
39 |
+
{
|
40 |
+
$this->columns[] = $column;
|
41 |
+
return $this;
|
42 |
+
}
|
43 |
+
|
44 |
+
public function clearColumns()
|
45 |
+
{
|
46 |
+
$this->columns = array();
|
47 |
+
return $this;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function getColumns()
|
51 |
+
{
|
52 |
+
return $this->columns;
|
53 |
+
}
|
54 |
+
|
55 |
+
public function setColumns($columns)
|
56 |
+
{
|
57 |
+
$this->columns = $columns;
|
58 |
+
return $this;
|
59 |
+
}
|
60 |
+
|
61 |
+
public function addCondition($field, $value)
|
62 |
+
{
|
63 |
+
$this->conditions[$field] = $value;
|
64 |
+
return $this;
|
65 |
+
}
|
66 |
+
|
67 |
+
public function addORCondition($aConditions)
|
68 |
+
{
|
69 |
+
$this->conditions[] = $aConditions;
|
70 |
+
}
|
71 |
+
|
72 |
+
public function clearConditions()
|
73 |
+
{
|
74 |
+
$this->conditions = array();
|
75 |
+
return $this;
|
76 |
+
}
|
77 |
+
|
78 |
+
public function getConditions()
|
79 |
+
{
|
80 |
+
return $this->conditions;
|
81 |
+
}
|
82 |
+
|
83 |
+
public function addOrderBy($field, $isDescending = false)
|
84 |
+
{
|
85 |
+
$order = ($isDescending) ? 'DESC' : 'ASC';
|
86 |
+
$this->orderBy[$field] = $order;
|
87 |
+
return $this;
|
88 |
+
}
|
89 |
+
|
90 |
+
public function clearOrderBy()
|
91 |
+
{
|
92 |
+
$this->orderBy = array();
|
93 |
+
return $this;
|
94 |
+
}
|
95 |
+
|
96 |
+
public function getOrderBy()
|
97 |
+
{
|
98 |
+
return $this->orderBy;
|
99 |
+
}
|
100 |
+
|
101 |
+
public function addFrom($fromDataSet)
|
102 |
+
{
|
103 |
+
$this->from[] = $fromDataSet;
|
104 |
+
return $this;
|
105 |
+
}
|
106 |
+
|
107 |
+
public function clearFrom()
|
108 |
+
{
|
109 |
+
$this->from = array();
|
110 |
+
return $this;
|
111 |
+
}
|
112 |
+
|
113 |
+
public function getFrom()
|
114 |
+
{
|
115 |
+
return $this->from;
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Gets the value of limit.
|
120 |
+
*
|
121 |
+
* @return mixed
|
122 |
+
*/
|
123 |
+
public function getLimit()
|
124 |
+
{
|
125 |
+
return $this->limit;
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Sets the value of limit.
|
130 |
+
*
|
131 |
+
* @param mixed $limit the limit
|
132 |
+
*
|
133 |
+
* @return self
|
134 |
+
*/
|
135 |
+
public function setLimit($limit)
|
136 |
+
{
|
137 |
+
$this->limit = $limit;
|
138 |
+
|
139 |
+
return $this;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Gets the value of offset.
|
144 |
+
*
|
145 |
+
* @return mixed
|
146 |
+
*/
|
147 |
+
public function getOffset()
|
148 |
+
{
|
149 |
+
return $this->offset;
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Sets the value of offset.
|
154 |
+
*
|
155 |
+
* @param mixed $offset the offset
|
156 |
+
*
|
157 |
+
* @return self
|
158 |
+
*/
|
159 |
+
public function setOffset($offset)
|
160 |
+
{
|
161 |
+
$this->offset = $offset;
|
162 |
+
|
163 |
+
return $this;
|
164 |
+
}
|
165 |
+
|
166 |
+
public function addSearchCondition($value)
|
167 |
+
{
|
168 |
+
$this->searchCondition = $value;
|
169 |
+
return $this;
|
170 |
+
}
|
171 |
+
|
172 |
+
public function getSearchCondition()
|
173 |
+
{
|
174 |
+
return $this->searchCondition;
|
175 |
+
}
|
176 |
+
|
177 |
+
public function hasMetaJoin()
|
178 |
+
{
|
179 |
+
return $this->meta_join;
|
180 |
+
}
|
181 |
+
|
182 |
+
public function addMetaJoin()
|
183 |
+
{
|
184 |
+
$this->meta_join = true;
|
185 |
+
return $this;
|
186 |
+
}
|
187 |
+
}
|
classes/Sensors/Database.php
CHANGED
@@ -1,130 +1,130 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WSAL_Sensors_Database extends WSAL_AbstractSensor {
|
4 |
-
|
5 |
-
public function HookEvents() {
|
6 |
-
add_action('dbdelta_queries', array($this, 'EventDBDeltaQuery'));
|
7 |
-
add_action('query', array($this, 'EventDropQuery'));
|
8 |
-
}
|
9 |
-
|
10 |
-
public function EventDropQuery($query) {
|
11 |
-
$table_names = array();
|
12 |
-
$str = explode(" ", $query);
|
13 |
-
|
14 |
-
if (preg_match("|DROP TABLE ([^ ]*)|", $query)) {
|
15 |
-
if (!empty($str[4])) {
|
16 |
-
array_push($table_names, $str[4]);
|
17 |
-
} else {
|
18 |
-
array_push($table_names, $str[2]);
|
19 |
-
}
|
20 |
-
$actype = basename($_SERVER['SCRIPT_NAME'], '.php');
|
21 |
-
$alertOptions = $this->GetActionType($actype);
|
22 |
-
}
|
23 |
-
|
24 |
-
if (!empty($table_names)) {
|
25 |
-
$event_code = $this->GetEventQueryType($actype, "delete");
|
26 |
-
$alertOptions["TableNames"] = implode(",", $table_names);
|
27 |
-
$this->plugin->alerts->Trigger($event_code, $alertOptions);
|
28 |
-
}
|
29 |
-
return $query;
|
30 |
-
}
|
31 |
-
|
32 |
-
public function EventDBDeltaQuery($queries) {
|
33 |
-
|
34 |
-
$typeQueries = array(
|
35 |
-
"create" => array(),
|
36 |
-
"update" => array(),
|
37 |
-
"delete" => array()
|
38 |
-
);
|
39 |
-
global $wpdb;
|
40 |
-
|
41 |
-
foreach($queries as $qry) {
|
42 |
-
$str = explode(" ", $qry);
|
43 |
-
if (preg_match("|CREATE TABLE ([^ ]*)|", $qry)) {
|
44 |
-
if ($wpdb->get_var("SHOW TABLES LIKE '" . $str[2] . "'") != $str[2]) {
|
45 |
-
//some plugins keep trying to create tables even when they already exist- would result in too many alerts
|
46 |
-
array_push($typeQueries['create'], $str[2]);
|
47 |
-
}
|
48 |
-
} else if (preg_match("|ALTER TABLE ([^ ]*)|", $qry)) {
|
49 |
-
array_push($typeQueries['update'], $str[2]);
|
50 |
-
} else if (preg_match("|DROP TABLE ([^ ]*)|", $qry)) {
|
51 |
-
if (!empty($str[4])) {
|
52 |
-
array_push($typeQueries['delete'], $str[4]);
|
53 |
-
} else {
|
54 |
-
array_push($typeQueries['delete'], $str[2]);
|
55 |
-
}
|
56 |
-
}
|
57 |
-
}
|
58 |
-
|
59 |
-
if (!empty($typeQueries["create"]) || !empty($typeQueries["update"]) || !empty($typeQueries["delete"])) {
|
60 |
-
$actype = basename($_SERVER['SCRIPT_NAME'], '.php');
|
61 |
-
$alertOptions = $this->GetActionType($actype);
|
62 |
-
|
63 |
-
|
64 |
-
foreach($typeQueries as $queryType => $tableNames) {
|
65 |
-
if (!empty($tableNames)) {
|
66 |
-
$event_code = $this->GetEventQueryType($actype, $queryType);
|
67 |
-
$alertOptions["TableNames"] = implode(",", $tableNames);
|
68 |
-
$this->plugin->alerts->Trigger($event_code, $alertOptions);
|
69 |
-
}
|
70 |
-
}
|
71 |
-
}
|
72 |
-
|
73 |
-
return $queries;
|
74 |
-
}
|
75 |
-
|
76 |
-
protected function GetEventQueryType($type_action, $type_query) {
|
77 |
-
switch($type_action){
|
78 |
-
case 'plugins':
|
79 |
-
if ($type_query == 'create') return 5010;
|
80 |
-
else if ($type_query == 'update') return 5011;
|
81 |
-
else if ($type_query == 'delete') return 5012;
|
82 |
-
case 'themes':
|
83 |
-
if ($type_query == 'create') return 5013;
|
84 |
-
else if ($type_query == 'update') return 5014;
|
85 |
-
else if ($type_query == 'delete') return 5015;
|
86 |
-
default:
|
87 |
-
if ($type_query == 'create') return 5016;
|
88 |
-
else if ($type_query == 'update') return 5017;
|
89 |
-
else if ($type_query == 'delete') return 5018;
|
90 |
-
}
|
91 |
-
}
|
92 |
-
|
93 |
-
protected function GetActionType($actype) {
|
94 |
-
$is_themes = $actype == 'themes';
|
95 |
-
$is_plugins = $actype == 'plugins';
|
96 |
-
//Action Plugin Component
|
97 |
-
$alertOptions = array();
|
98 |
-
if ($is_plugins) {
|
99 |
-
if (isset($_REQUEST['plugin'])) {
|
100 |
-
$pluginFile = $_REQUEST['plugin'];
|
101 |
-
} else {
|
102 |
-
$pluginFile = $_REQUEST['checked'][0];
|
103 |
-
}
|
104 |
-
$pluginName = basename($pluginFile, '.php');
|
105 |
-
$pluginName = str_replace(array('_', '-', ' '), ' ', $pluginName);
|
106 |
-
$pluginName = ucwords($pluginName);
|
107 |
-
$alertOptions["Plugin"] = (object)array(
|
108 |
-
'Name' => $pluginName,
|
109 |
-
);
|
110 |
-
//Action Theme Component
|
111 |
-
} else if ($is_themes) {
|
112 |
-
if (isset($_REQUEST['theme'])) {
|
113 |
-
$themeName = $_REQUEST['theme'];
|
114 |
-
} else {
|
115 |
-
$themeName = $_REQUEST['checked'][0];
|
116 |
-
}
|
117 |
-
$themeName = str_replace(array('_', '-', ' '), ' ', $themeName);
|
118 |
-
$themeName = ucwords($themeName);
|
119 |
-
$alertOptions["Theme"] = (object)array(
|
120 |
-
'Name' => $themeName,
|
121 |
-
);
|
122 |
-
//Action Unknown Component
|
123 |
-
} else {
|
124 |
-
$alertOptions["Component"] = "Unknown";
|
125 |
-
}
|
126 |
-
|
127 |
-
return $alertOptions;
|
128 |
-
}
|
129 |
-
|
130 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WSAL_Sensors_Database extends WSAL_AbstractSensor {
|
4 |
+
|
5 |
+
public function HookEvents() {
|
6 |
+
add_action('dbdelta_queries', array($this, 'EventDBDeltaQuery'));
|
7 |
+
add_action('query', array($this, 'EventDropQuery'));
|
8 |
+
}
|
9 |
+
|
10 |
+
public function EventDropQuery($query) {
|
11 |
+
$table_names = array();
|
12 |
+
$str = explode(" ", $query);
|
13 |
+
|
14 |
+
if (preg_match("|DROP TABLE ([^ ]*)|", $query)) {
|
15 |
+
if (!empty($str[4])) {
|
16 |
+
array_push($table_names, $str[4]);
|
17 |
+
} else {
|
18 |
+
array_push($table_names, $str[2]);
|
19 |
+
}
|
20 |
+
$actype = basename($_SERVER['SCRIPT_NAME'], '.php');
|
21 |
+
$alertOptions = $this->GetActionType($actype);
|
22 |
+
}
|
23 |
+
|
24 |
+
if (!empty($table_names)) {
|
25 |
+
$event_code = $this->GetEventQueryType($actype, "delete");
|
26 |
+
$alertOptions["TableNames"] = implode(",", $table_names);
|
27 |
+
$this->plugin->alerts->Trigger($event_code, $alertOptions);
|
28 |
+
}
|
29 |
+
return $query;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function EventDBDeltaQuery($queries) {
|
33 |
+
|
34 |
+
$typeQueries = array(
|
35 |
+
"create" => array(),
|
36 |
+
"update" => array(),
|
37 |
+
"delete" => array()
|
38 |
+
);
|
39 |
+
global $wpdb;
|
40 |
+
|
41 |
+
foreach($queries as $qry) {
|
42 |
+
$str = explode(" ", $qry);
|
43 |
+
if (preg_match("|CREATE TABLE ([^ ]*)|", $qry)) {
|
44 |
+
if ($wpdb->get_var("SHOW TABLES LIKE '" . $str[2] . "'") != $str[2]) {
|
45 |
+
//some plugins keep trying to create tables even when they already exist- would result in too many alerts
|
46 |
+
array_push($typeQueries['create'], $str[2]);
|
47 |
+
}
|
48 |
+
} else if (preg_match("|ALTER TABLE ([^ ]*)|", $qry)) {
|
49 |
+
array_push($typeQueries['update'], $str[2]);
|
50 |
+
} else if (preg_match("|DROP TABLE ([^ ]*)|", $qry)) {
|
51 |
+
if (!empty($str[4])) {
|
52 |
+
array_push($typeQueries['delete'], $str[4]);
|
53 |
+
} else {
|
54 |
+
array_push($typeQueries['delete'], $str[2]);
|
55 |
+
}
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
if (!empty($typeQueries["create"]) || !empty($typeQueries["update"]) || !empty($typeQueries["delete"])) {
|
60 |
+
$actype = basename($_SERVER['SCRIPT_NAME'], '.php');
|
61 |
+
$alertOptions = $this->GetActionType($actype);
|
62 |
+
|
63 |
+
|
64 |
+
foreach($typeQueries as $queryType => $tableNames) {
|
65 |
+
if (!empty($tableNames)) {
|
66 |
+
$event_code = $this->GetEventQueryType($actype, $queryType);
|
67 |
+
$alertOptions["TableNames"] = implode(",", $tableNames);
|
68 |
+
$this->plugin->alerts->Trigger($event_code, $alertOptions);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
return $queries;
|
74 |
+
}
|
75 |
+
|
76 |
+
protected function GetEventQueryType($type_action, $type_query) {
|
77 |
+
switch($type_action){
|
78 |
+
case 'plugins':
|
79 |
+
if ($type_query == 'create') return 5010;
|
80 |
+
else if ($type_query == 'update') return 5011;
|
81 |
+
else if ($type_query == 'delete') return 5012;
|
82 |
+
case 'themes':
|
83 |
+
if ($type_query == 'create') return 5013;
|
84 |
+
else if ($type_query == 'update') return 5014;
|
85 |
+
else if ($type_query == 'delete') return 5015;
|
86 |
+
default:
|
87 |
+
if ($type_query == 'create') return 5016;
|
88 |
+
else if ($type_query == 'update') return 5017;
|
89 |
+
else if ($type_query == 'delete') return 5018;
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
protected function GetActionType($actype) {
|
94 |
+
$is_themes = $actype == 'themes';
|
95 |
+
$is_plugins = $actype == 'plugins';
|
96 |
+
//Action Plugin Component
|
97 |
+
$alertOptions = array();
|
98 |
+
if ($is_plugins) {
|
99 |
+
if (isset($_REQUEST['plugin'])) {
|
100 |
+
$pluginFile = $_REQUEST['plugin'];
|
101 |
+
} else {
|
102 |
+
$pluginFile = $_REQUEST['checked'][0];
|
103 |
+
}
|
104 |
+
$pluginName = basename($pluginFile, '.php');
|
105 |
+
$pluginName = str_replace(array('_', '-', ' '), ' ', $pluginName);
|
106 |
+
$pluginName = ucwords($pluginName);
|
107 |
+
$alertOptions["Plugin"] = (object)array(
|
108 |
+
'Name' => $pluginName,
|
109 |
+
);
|
110 |
+
//Action Theme Component
|
111 |
+
} else if ($is_themes) {
|
112 |
+
if (isset($_REQUEST['theme'])) {
|
113 |
+
$themeName = $_REQUEST['theme'];
|
114 |
+
} else {
|
115 |
+
$themeName = $_REQUEST['checked'][0];
|
116 |
+
}
|
117 |
+
$themeName = str_replace(array('_', '-', ' '), ' ', $themeName);
|
118 |
+
$themeName = ucwords($themeName);
|
119 |
+
$alertOptions["Theme"] = (object)array(
|
120 |
+
'Name' => $themeName,
|
121 |
+
);
|
122 |
+
//Action Unknown Component
|
123 |
+
} else {
|
124 |
+
$alertOptions["Component"] = "Unknown";
|
125 |
+
}
|
126 |
+
|
127 |
+
return $alertOptions;
|
128 |
+
}
|
129 |
+
|
130 |
+
}
|
classes/Views/About.php
CHANGED
@@ -46,19 +46,19 @@ class WSAL_Views_About extends WSAL_AbstractView {
|
|
46 |
<li><?php _e('and much more…', 'wp-security-audit-log'); ?></li>
|
47 |
</ul>
|
48 |
<br/>
|
49 |
-
Refer to the complete list of <a href="http://www.
|
50 |
</div>
|
51 |
</div>
|
52 |
</div>
|
53 |
|
54 |
<div style="position: absolute; right: 70px; width: 180px; top: 10px;">
|
55 |
<div class="postbox">
|
56 |
-
<h3 class="hndl"><span><?php _e('WP
|
57 |
<div class="inside">
|
58 |
<p>
|
59 |
-
<?php _e('
|
60 |
</p>
|
61 |
-
<a class="button button-primary" href="http://
|
62 |
</div>
|
63 |
</div>
|
64 |
<div class="postbox">
|
@@ -75,7 +75,6 @@ class WSAL_Views_About extends WSAL_AbstractView {
|
|
75 |
<ul>
|
76 |
<li><a href="http://www.wpwhitesecurity.com/wordpress-security-services/wordpress-security-hardening/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank">Security Hardening</a></li>
|
77 |
<li><a href="http://www.wpwhitesecurity.com/wordpress-security-services/wordpress-security-audit/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank">Security Audit</a></li>
|
78 |
-
<li><a href="http://www.wpwhitesecurity.com/wordpress-security-services/wordpress-hacker-attack-malware-virus-removal-services/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank">Hack Cleanup</a></li>
|
79 |
<li><a href="http://www.wpwhitesecurity.com/wordpress-security-services/wordpress-plugins-security-code-audit-review/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank">Plugin Security Code Audit</a></li>
|
80 |
</ul>
|
81 |
</div>
|
46 |
<li><?php _e('and much more…', 'wp-security-audit-log'); ?></li>
|
47 |
</ul>
|
48 |
<br/>
|
49 |
+
Refer to the complete list of <a href="http://www.wpsecurityauditlog.com/documentation/list-monitoring-wordpress-security-alerts-audit-log/?utm_source=wsalabt&utm_medium=txtlink&utm_campaign=wsal" target="_blank">WordPress Security Alerts</a> for more information.
|
50 |
</div>
|
51 |
</div>
|
52 |
</div>
|
53 |
|
54 |
<div style="position: absolute; right: 70px; width: 180px; top: 10px;">
|
55 |
<div class="postbox">
|
56 |
+
<h3 class="hndl"><span><?php _e('Extend the Functionality & Get More Value from WP Security Audit Log', 'wp-security-audit-log'); ?></span></h3>
|
57 |
<div class="inside">
|
58 |
<p>
|
59 |
+
<?php _e('Get more value out of WP Security Audit Log by extending the functionality of WP Security Audit Log with the premium Add-Ons.'); ?>
|
60 |
</p>
|
61 |
+
<a class="button button-primary" href="http://www.wpsecurityauditlog.com/plugin-extensions/" target="_blank"><?php _e('See Add-Ons', 'wp-security-audit-log'); ?></a>
|
62 |
</div>
|
63 |
</div>
|
64 |
<div class="postbox">
|
75 |
<ul>
|
76 |
<li><a href="http://www.wpwhitesecurity.com/wordpress-security-services/wordpress-security-hardening/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank">Security Hardening</a></li>
|
77 |
<li><a href="http://www.wpwhitesecurity.com/wordpress-security-services/wordpress-security-audit/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank">Security Audit</a></li>
|
|
|
78 |
<li><a href="http://www.wpwhitesecurity.com/wordpress-security-services/wordpress-plugins-security-code-audit-review/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank">Plugin Security Code Audit</a></li>
|
79 |
</ul>
|
80 |
</div>
|
classes/Views/AuditLog.php
CHANGED
@@ -24,7 +24,7 @@ class WSAL_Views_AuditLog extends WSAL_AbstractView {
|
|
24 |
?><div class="updated" data-notice-name="notifications-extension">
|
25 |
<p><?php _e('Get notified instantly via email of important changes on your WordPress', 'wp-security-audit-log'); ?></p>
|
26 |
<p>
|
27 |
-
<?php $url = 'http://www.
|
28 |
<a href="<?php echo esc_attr($url); ?>" target="_blank"><?php _e('Learn More', 'wp-security-audit-log'); ?></a>
|
29 |
| <a href="javascript:;" class="wsal-dismiss-notification"><?php _e('Dismiss this notice', 'wp-security-audit-log'); ?></a>
|
30 |
</p>
|
24 |
?><div class="updated" data-notice-name="notifications-extension">
|
25 |
<p><?php _e('Get notified instantly via email of important changes on your WordPress', 'wp-security-audit-log'); ?></p>
|
26 |
<p>
|
27 |
+
<?php $url = 'http://www.wpsecurityauditlog.com/extensions/wordpress-email-notifications-add-on/?utm_source=plugin&utm_medium=auditlogviewer&utm_campaign=notifications'; ?>
|
28 |
<a href="<?php echo esc_attr($url); ?>" target="_blank"><?php _e('Learn More', 'wp-security-audit-log'); ?></a>
|
29 |
| <a href="javascript:;" class="wsal-dismiss-notification"><?php _e('Dismiss this notice', 'wp-security-audit-log'); ?></a>
|
30 |
</p>
|
classes/Views/Extensions.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
class WSAL_Views_Extensions extends WSAL_AbstractView {
|
4 |
|
5 |
public function GetTitle() {
|
6 |
-
return __('WP Security Audit Log
|
7 |
}
|
8 |
|
9 |
public function GetIcon() {
|
@@ -24,28 +24,28 @@ class WSAL_Views_Extensions extends WSAL_AbstractView {
|
|
24 |
<div class="postbox" style="margin-right: 270px;">
|
25 |
<div class="inside">
|
26 |
<div class="activity-block">
|
27 |
-
<p><?php _e('The below
|
28 |
</div>
|
29 |
|
30 |
<div class="activity-block">
|
31 |
-
<h2><?php _e('
|
32 |
<strong><?php _e('Get notified instantly via email when important changes are made on your WordPress!', 'wp-security-audit-log'); ?></strong>
|
33 |
-
<p><?php _e('With the Notifications
|
34 |
-
<p><a class="button" href="http://www.
|
35 |
</div>
|
36 |
|
37 |
<div class="activity-block">
|
38 |
-
<h2><?php _e('
|
39 |
<strong><?php _e('Automatically Search for specific WordPress user and site activity in WordPress Security Audit Log.', 'wp-security-audit-log'); ?></strong>
|
40 |
-
<p><?php _e('The Search
|
41 |
-
<p><a class="button" href="http://www.
|
42 |
</div>
|
43 |
|
44 |
<div class="activity-block">
|
45 |
-
<h2><?php _e('
|
46 |
-
<strong><?php _e('Generate User, Site and
|
47 |
-
<p><?php _e('The
|
48 |
-
<p><a class="button" href="http://www.
|
49 |
</div>
|
50 |
</div>
|
51 |
</div>
|
3 |
class WSAL_Views_Extensions extends WSAL_AbstractView {
|
4 |
|
5 |
public function GetTitle() {
|
6 |
+
return __('WP Security Audit Log Add-Ons', 'wp-security-audit-log');
|
7 |
}
|
8 |
|
9 |
public function GetIcon() {
|
24 |
<div class="postbox" style="margin-right: 270px;">
|
25 |
<div class="inside">
|
26 |
<div class="activity-block">
|
27 |
+
<p><?php _e('The below add-ons allow you to extend the functionality of WP Security Audit Log plugin and enable you to get more benefits out of the WordPress security audit, such as configurable email alerts, ability to search using free text based searches & filters, and generate user activity reports to meet regulatory compliance requirements.', 'wp-security-audit-log'); ?></p>
|
28 |
</div>
|
29 |
|
30 |
<div class="activity-block">
|
31 |
+
<h2><?php _e('Email Notifications Add-On', 'wp-security-audit-log'); ?></h2>
|
32 |
<strong><?php _e('Get notified instantly via email when important changes are made on your WordPress!', 'wp-security-audit-log'); ?></strong>
|
33 |
+
<p><?php _e('With the Email Notifications Add-On you can easily configure trigger rules so when a specific change happens on your WordPress you are instantly alerted via email. For example you can configure rules to receive an email when existing content is changed, when a new user is created or when someone logs in to WordPress outside normal office hours or from an odd location.', 'wp-security-audit-log'); ?></p>
|
34 |
+
<p><a class="button" href="http://www.wpsecurityauditlog.com/extensions/wordpress-email-notifications-add-on/?utm_source=plugin&utm_medium=extensionspage&utm_campaign=notifications" target="_blank"><?php _e('More Information', 'wp-security-audit-log'); ?></a></p>
|
35 |
</div>
|
36 |
|
37 |
<div class="activity-block">
|
38 |
+
<h2><?php _e('Search Add-On', 'wp-security-audit-log'); ?></h2>
|
39 |
<strong><?php _e('Automatically Search for specific WordPress user and site activity in WordPress Security Audit Log.', 'wp-security-audit-log'); ?></strong>
|
40 |
+
<p><?php _e('The Search Add-On enables you to easily find specific WordPress activity in the Audit Log with free-text based searches. Filters can also be used in conjunction with free-text based searches to fine tune the search and find what you are looking for easily.', 'wp-security-audit-log'); ?></p>
|
41 |
+
<p><a class="button" href="http://www.wpsecurityauditlog.com/extensions/search-add-on-for-wordpress-security-audit-log/?utm_source=plugin&utm_medium=extensionspage&utm_campaign=search" target="_blank"><?php _e('More Information', 'wp-security-audit-log'); ?></a></p>
|
42 |
</div>
|
43 |
|
44 |
<div class="activity-block">
|
45 |
+
<h2><?php _e('Reports Add-Ons', 'wp-security-audit-log'); ?></h2>
|
46 |
+
<strong><?php _e('Generate User, Site and Regulatory Compliance Reports.', 'wp-security-audit-log'); ?></strong>
|
47 |
+
<p><?php _e('The Reports Add-On allows you to generate reports and keep track and record of user productivity, and meet any legal and regulatory compliance your business need to adhere to. Unlike other reporting plugins the Reports Add-On does not have any built-in templates that restrict you to specific type of reports, you can generate any type of report using all of the available data.', 'wp-security-audit-log'); ?></p>
|
48 |
+
<p><a class="button" href="http://www.wpsecurityauditlog.com/extensions/compliance-reports-add-on-for-wordpress/?utm_source=plugin&utm_medium=extensionspage&utm_campaign=reports" target="_blank"><?php _e('More Information', 'wp-security-audit-log'); ?></a></p>
|
49 |
</div>
|
50 |
</div>
|
51 |
</div>
|
classes/Views/Help.php
CHANGED
@@ -29,61 +29,39 @@ class WSAL_Views_Help extends WSAL_AbstractView {
|
|
29 |
<?php _e('Have you encountered or noticed any issues while using WP Security Audit Log plugin?', 'wp-security-audit-log'); ?>
|
30 |
<?php _e('Or you want to report something to us? Click any of the options below to post on the plugin\'s forum or contact our support directly.', 'wp-security-audit-log'); ?>
|
31 |
</p><p>
|
32 |
-
<a class="button" href="
|
33 |
|
34 |
-
<a class="button" href="
|
35 |
</p>
|
36 |
</div>
|
37 |
|
38 |
<div class="activity-block">
|
39 |
<h2><?php _e('Plugin Documentation', 'wp-security-audit-log'); ?></h2>
|
40 |
<p>
|
41 |
-
<?php _e('For more detailed information about WP Security Audit Log you can visit the
|
42 |
-
<?php _e('You can also visit the official list of WordPress Security Alerts for more information about all of the activity you can monitor with WP Security Audit Log.', 'wp-security-audit-log'); ?>
|
43 |
</p><p>
|
44 |
-
<a class="button" href="http://www.
|
45 |
|
46 |
-
<a class="button" href="http://www.
|
47 |
-
</p>
|
48 |
-
</div>
|
49 |
-
|
50 |
-
<div class="activity-block">
|
51 |
-
<h2><?php _e('Need Help Securing WordPress?', 'wp-security-audit-log'); ?></h2>
|
52 |
-
<p>
|
53 |
-
<?php _e('Is your WordPress website hackable?', 'wp-security-audit-log'); ?>
|
54 |
-
<?php _e('If you are not sure contact our WordPress security professionals to audit your WordPress or to simply secure your WordPress website.', 'wp-security-audit-log'); ?>
|
55 |
-
<?php _e('Click on any of the below service buttons for more information.', 'wp-security-audit-log'); ?>
|
56 |
-
</p><p>
|
57 |
-
<a class="button" href="http://www.wpwhitesecurity.com/wordpress-security-services/wordpress-security-hardening/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank"><?php _e('WordPress Security Hardening', 'wp-security-audit-log'); ?></a>
|
58 |
-
|
59 |
-
<a class="button" href="http://www.wpwhitesecurity.com/wordpress-security-services/wordpress-security-audit/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank"><?php _e('WordPress Security Audit', 'wp-security-audit-log'); ?></a>
|
60 |
</p>
|
61 |
</div>
|
62 |
|
63 |
<div class="">
|
64 |
-
<h2><?php _e('WordPress Security
|
65 |
<p>
|
66 |
<?php _e('New to WordPress security?', 'wp-security-audit-log'); ?>
|
67 |
<?php _e('Do not know from where to start or which is the best services for you?', 'wp-security-audit-log'); ?>
|
68 |
<?php _e('Visit our WordPress security blog or the WordPress Security category directly for more information and a number of tips and tricks about WordPress security.', 'wp-security-audit-log'); ?>
|
69 |
</p>
|
70 |
-
<a class="button" href="http://www.wpwhitesecurity.com/blog/?utm_source=
|
71 |
|
72 |
-
<a class="button" href="http://www.wpwhitesecurity.com/wordpress-security/?utm_source=
|
73 |
</div>
|
74 |
</div>
|
75 |
</div>
|
76 |
|
77 |
<div style="position: absolute; right: 70px; width: 180px; top: 10px;">
|
78 |
-
<div class="postbox">
|
79 |
-
<h3 class="hndl"><span><?php _e('WP Password Policy Manager', 'wp-security-audit-log'); ?></span></h3>
|
80 |
-
<div class="inside">
|
81 |
-
<p>
|
82 |
-
<?php _e('Easily configure WordPress password policies and ensure users use strong passwords with our plugin WP Password Policy Manager.', 'wp-security-audit-log'); ?>
|
83 |
-
</p>
|
84 |
-
<a class="button button-primary" href="http://wordpress.org/plugins/wp-password-policy-manager/" target="_blank"><?php _e('Download', 'wp-security-audit-log'); ?></a>
|
85 |
-
</div>
|
86 |
-
</div>
|
87 |
<div class="postbox">
|
88 |
<h3 class="hndl"><span><?php _e('WP Security Audit Log in your Language!', 'wp-security-audit-log'); ?></span></h3>
|
89 |
<div class="inside">
|
29 |
<?php _e('Have you encountered or noticed any issues while using WP Security Audit Log plugin?', 'wp-security-audit-log'); ?>
|
30 |
<?php _e('Or you want to report something to us? Click any of the options below to post on the plugin\'s forum or contact our support directly.', 'wp-security-audit-log'); ?>
|
31 |
</p><p>
|
32 |
+
<a class="button" href="https://wordpress.org/support/plugin/wp-security-audit-log" target="_blank"><?php _e('Free Support Forum', 'wp-security-audit-log'); ?></a>
|
33 |
|
34 |
+
<a class="button" href="http://www.wpsecurityauditlog.com/contact/" target="_blank"><?php _e('Free Support Email', 'wp-security-audit-log'); ?></a>
|
35 |
</p>
|
36 |
</div>
|
37 |
|
38 |
<div class="activity-block">
|
39 |
<h2><?php _e('Plugin Documentation', 'wp-security-audit-log'); ?></h2>
|
40 |
<p>
|
41 |
+
<?php _e('For more detailed information about WP Security Audit Log you can visit the plugin website.', 'wp-security-audit-log'); ?>
|
42 |
+
<?php _e('You can also visit the official list of WordPress Security Alerts for more information about all of the WordPress activity and changes you can monitor with WP Security Audit Log.', 'wp-security-audit-log'); ?>
|
43 |
</p><p>
|
44 |
+
<a class="button" href="http://www.wpsecurityauditlog.com/?utm_source=wpsalabt&utm_medium=txtlink&utm_campaign=wpsal" target="_blank"><?php _e('Plugin Website', 'wp-security-audit-log'); ?></a>
|
45 |
|
46 |
+
<a class="button" href="http://www.wpsecurityauditlog.com/documentation/list-monitoring-wordpress-security-alerts-audit-log/?utm_source=wsalabt&utm_medium=txtlink&utm_campaign=wsal" target="_blank"><?php _e('List of WordPress Security Alerts', 'wp-security-audit-log'); ?></a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
</p>
|
48 |
</div>
|
49 |
|
50 |
<div class="">
|
51 |
+
<h2><?php _e('WordPress Security Blog', 'wp-security-audit-log'); ?></h2>
|
52 |
<p>
|
53 |
<?php _e('New to WordPress security?', 'wp-security-audit-log'); ?>
|
54 |
<?php _e('Do not know from where to start or which is the best services for you?', 'wp-security-audit-log'); ?>
|
55 |
<?php _e('Visit our WordPress security blog or the WordPress Security category directly for more information and a number of tips and tricks about WordPress security.', 'wp-security-audit-log'); ?>
|
56 |
</p>
|
57 |
+
<a class="button" href="http://www.wpwhitesecurity.com/blog/?utm_source=wsalabt&utm_medium=txtlink&utm_campaign=wsal" target="_blank"><?php _e('WP White Security Blog', 'wp-security-audit-log'); ?></a>
|
58 |
|
59 |
+
<a class="button" href="http://www.wpwhitesecurity.com/wordpress-security/?utm_source=wsalabt&utm_medium=txtlink&utm_campaign=wsal" target="_blank"><?php _e('WordPress Security Category', 'wp-security-audit-log'); ?></a>
|
60 |
</div>
|
61 |
</div>
|
62 |
</div>
|
63 |
|
64 |
<div style="position: absolute; right: 70px; width: 180px; top: 10px;">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
<div class="postbox">
|
66 |
<h3 class="hndl"><span><?php _e('WP Security Audit Log in your Language!', 'wp-security-audit-log'); ?></span></h3>
|
67 |
<div class="inside">
|
classes/Views/Settings.php
CHANGED
@@ -140,13 +140,13 @@ class WSAL_Views_Settings extends WSAL_AbstractView {
|
|
140 |
<?php wp_nonce_field('wsal-settings'); ?>
|
141 |
|
142 |
<div id="audit-log-adverts">
|
143 |
-
<a href="http://www.
|
144 |
<img src="<?php echo $this->_plugin->GetBaseUrl(); ?>/img/notifications_250x150.gif" width="250" height="150" alt=""/>
|
145 |
</a>
|
146 |
-
<a href="http://www.
|
147 |
<img src="<?php echo $this->_plugin->GetBaseUrl(); ?>/img/search_250x150.gif" width="250" height="150" alt=""/>
|
148 |
</a>
|
149 |
-
<a href="http://www.
|
150 |
<img src="<?php echo $this->_plugin->GetBaseUrl(); ?>/img/reporting_250x150.gif" width="250" height="150" alt=""/>
|
151 |
</a>
|
152 |
</div>
|
140 |
<?php wp_nonce_field('wsal-settings'); ?>
|
141 |
|
142 |
<div id="audit-log-adverts">
|
143 |
+
<a href="http://www.wpsecurityauditlog.com/extensions/wordpress-email-notifications-add-on/?utm_source=plugin&utm_medium=settingspage&utm_campaign=notifications">
|
144 |
<img src="<?php echo $this->_plugin->GetBaseUrl(); ?>/img/notifications_250x150.gif" width="250" height="150" alt=""/>
|
145 |
</a>
|
146 |
+
<a href="http://www.wpsecurityauditlog.com/extensions/search-add-on-for-wordpress-security-audit-log/?utm_source=plugin&utm_medium=settingspage&utm_campaign=search">
|
147 |
<img src="<?php echo $this->_plugin->GetBaseUrl(); ?>/img/search_250x150.gif" width="250" height="150" alt=""/>
|
148 |
</a>
|
149 |
+
<a href="http://www.wpsecurityauditlog.com/extensions/compliance-reports-add-on-for-wordpress/?utm_source=plugin&utm_medium=settingspage&utm_campaign=reports">
|
150 |
<img src="<?php echo $this->_plugin->GetBaseUrl(); ?>/img/reporting_250x150.gif" width="250" height="150" alt=""/>
|
151 |
</a>
|
152 |
</div>
|
css/install-error.css
CHANGED
@@ -1,41 +1,41 @@
|
|
1 |
-
.warn-icon-tri {
|
2 |
-
top: 5px;
|
3 |
-
left: 5px;
|
4 |
-
position: absolute;
|
5 |
-
border-left: 16px solid #FFF;
|
6 |
-
border-right: 16px solid #FFF;
|
7 |
-
border-bottom: 28px solid #C33;
|
8 |
-
height: 3px;
|
9 |
-
width: 4px
|
10 |
-
}
|
11 |
-
|
12 |
-
.warn-icon-chr {
|
13 |
-
top: 8px;
|
14 |
-
left: 18px;
|
15 |
-
position: absolute;
|
16 |
-
color: #FFF;
|
17 |
-
font: 26px Georgia;
|
18 |
-
}
|
19 |
-
|
20 |
-
.warn-icon-cir {
|
21 |
-
top: 2px;
|
22 |
-
left: 0px;
|
23 |
-
position: absolute;
|
24 |
-
overflow: hidden;
|
25 |
-
border: 6px solid #FFF;
|
26 |
-
border-radius: 32px;
|
27 |
-
width: 34px;
|
28 |
-
height: 34px;
|
29 |
-
}
|
30 |
-
|
31 |
-
.warn-wrap {
|
32 |
-
position: relative;
|
33 |
-
color: #A00;
|
34 |
-
font: 14px Arial;
|
35 |
-
padding: 6px 48px;
|
36 |
-
}
|
37 |
-
|
38 |
-
.warn-wrap a,
|
39 |
-
.warn-wrap a:hover {
|
40 |
-
color: #F56;
|
41 |
-
}
|
1 |
+
.warn-icon-tri {
|
2 |
+
top: 5px;
|
3 |
+
left: 5px;
|
4 |
+
position: absolute;
|
5 |
+
border-left: 16px solid #FFF;
|
6 |
+
border-right: 16px solid #FFF;
|
7 |
+
border-bottom: 28px solid #C33;
|
8 |
+
height: 3px;
|
9 |
+
width: 4px
|
10 |
+
}
|
11 |
+
|
12 |
+
.warn-icon-chr {
|
13 |
+
top: 8px;
|
14 |
+
left: 18px;
|
15 |
+
position: absolute;
|
16 |
+
color: #FFF;
|
17 |
+
font: 26px Georgia;
|
18 |
+
}
|
19 |
+
|
20 |
+
.warn-icon-cir {
|
21 |
+
top: 2px;
|
22 |
+
left: 0px;
|
23 |
+
position: absolute;
|
24 |
+
overflow: hidden;
|
25 |
+
border: 6px solid #FFF;
|
26 |
+
border-radius: 32px;
|
27 |
+
width: 34px;
|
28 |
+
height: 34px;
|
29 |
+
}
|
30 |
+
|
31 |
+
.warn-wrap {
|
32 |
+
position: relative;
|
33 |
+
color: #A00;
|
34 |
+
font: 14px Arial;
|
35 |
+
padding: 6px 48px;
|
36 |
+
}
|
37 |
+
|
38 |
+
.warn-wrap a,
|
39 |
+
.warn-wrap a:hover {
|
40 |
+
color: #F56;
|
41 |
+
}
|
css/settings.css
CHANGED
@@ -1,71 +1,71 @@
|
|
1 |
-
#audit-log-settings {
|
2 |
-
padding-right: 256px;
|
3 |
-
position: relative;
|
4 |
-
}
|
5 |
-
|
6 |
-
#audit-log-adverts {
|
7 |
-
position: absolute;
|
8 |
-
top: 3px;
|
9 |
-
right: 3px;
|
10 |
-
overflow: hidden;
|
11 |
-
}
|
12 |
-
|
13 |
-
#audit-log-adverts a {
|
14 |
-
display: block;
|
15 |
-
text-decoration: none;
|
16 |
-
margin: 4px 0;
|
17 |
-
}
|
18 |
-
|
19 |
-
.sectoken-user,
|
20 |
-
.sectoken-role,
|
21 |
-
.sectoken-other {
|
22 |
-
display: inline-block;
|
23 |
-
border-width: 1px;
|
24 |
-
border-style: solid;
|
25 |
-
padding: 2px 4px;
|
26 |
-
margin: 2px 0 0 2px;
|
27 |
-
border-radius: 3px;
|
28 |
-
cursor: default;
|
29 |
-
}
|
30 |
-
.sectoken-other {
|
31 |
-
display: table;
|
32 |
-
border-collapse: separate;
|
33 |
-
}
|
34 |
-
|
35 |
-
.sectoken-user a,
|
36 |
-
.sectoken-role a,
|
37 |
-
.sectoken-other a {
|
38 |
-
text-decoration: none;
|
39 |
-
font-size: 12px;
|
40 |
-
font-weight: bold;
|
41 |
-
color: #FFF;
|
42 |
-
margin-left: 2px;
|
43 |
-
background: #BBB;
|
44 |
-
border-radius: 25px;
|
45 |
-
height: 14px;
|
46 |
-
display: inline-block;
|
47 |
-
width: 14px;
|
48 |
-
text-align: center;
|
49 |
-
line-height: 16px;
|
50 |
-
}
|
51 |
-
|
52 |
-
.sectoken-user a:hover,
|
53 |
-
.sectoken-role a:hover,
|
54 |
-
.sectoken-other a:hover {
|
55 |
-
background: #FB9;
|
56 |
-
}
|
57 |
-
|
58 |
-
.sectoken-user { background: #EFF; border-color: #5BE; }
|
59 |
-
.sectoken-role { background: #EFE; border-color: #5B5; }
|
60 |
-
.sectoken-other { background: #FFE; border-color: #ED5; }
|
61 |
-
.sectoken-del { background: #FEE; border-color: #EBB; }
|
62 |
-
|
63 |
-
.wsal-tab {
|
64 |
-
margin-top: 0px;
|
65 |
-
}
|
66 |
-
.wsal-tab th {
|
67 |
-
padding-left: 20px;
|
68 |
-
}
|
69 |
-
.wsal-tab td {
|
70 |
-
padding-left: 20px;
|
71 |
}
|
1 |
+
#audit-log-settings {
|
2 |
+
padding-right: 256px;
|
3 |
+
position: relative;
|
4 |
+
}
|
5 |
+
|
6 |
+
#audit-log-adverts {
|
7 |
+
position: absolute;
|
8 |
+
top: 3px;
|
9 |
+
right: 3px;
|
10 |
+
overflow: hidden;
|
11 |
+
}
|
12 |
+
|
13 |
+
#audit-log-adverts a {
|
14 |
+
display: block;
|
15 |
+
text-decoration: none;
|
16 |
+
margin: 4px 0;
|
17 |
+
}
|
18 |
+
|
19 |
+
.sectoken-user,
|
20 |
+
.sectoken-role,
|
21 |
+
.sectoken-other {
|
22 |
+
display: inline-block;
|
23 |
+
border-width: 1px;
|
24 |
+
border-style: solid;
|
25 |
+
padding: 2px 4px;
|
26 |
+
margin: 2px 0 0 2px;
|
27 |
+
border-radius: 3px;
|
28 |
+
cursor: default;
|
29 |
+
}
|
30 |
+
.sectoken-other {
|
31 |
+
display: table;
|
32 |
+
border-collapse: separate;
|
33 |
+
}
|
34 |
+
|
35 |
+
.sectoken-user a,
|
36 |
+
.sectoken-role a,
|
37 |
+
.sectoken-other a {
|
38 |
+
text-decoration: none;
|
39 |
+
font-size: 12px;
|
40 |
+
font-weight: bold;
|
41 |
+
color: #FFF;
|
42 |
+
margin-left: 2px;
|
43 |
+
background: #BBB;
|
44 |
+
border-radius: 25px;
|
45 |
+
height: 14px;
|
46 |
+
display: inline-block;
|
47 |
+
width: 14px;
|
48 |
+
text-align: center;
|
49 |
+
line-height: 16px;
|
50 |
+
}
|
51 |
+
|
52 |
+
.sectoken-user a:hover,
|
53 |
+
.sectoken-role a:hover,
|
54 |
+
.sectoken-other a:hover {
|
55 |
+
background: #FB9;
|
56 |
+
}
|
57 |
+
|
58 |
+
.sectoken-user { background: #EFF; border-color: #5BE; }
|
59 |
+
.sectoken-role { background: #EFE; border-color: #5B5; }
|
60 |
+
.sectoken-other { background: #FFE; border-color: #ED5; }
|
61 |
+
.sectoken-del { background: #FEE; border-color: #EBB; }
|
62 |
+
|
63 |
+
.wsal-tab {
|
64 |
+
margin-top: 0px;
|
65 |
+
}
|
66 |
+
.wsal-tab th {
|
67 |
+
padding-left: 20px;
|
68 |
+
}
|
69 |
+
.wsal-tab td {
|
70 |
+
padding-left: 20px;
|
71 |
}
|
js/auditlog.js
CHANGED
@@ -1,150 +1,150 @@
|
|
1 |
-
var WsalData;
|
2 |
-
|
3 |
-
window['WsalAuditLogRefreshed'] = function(){
|
4 |
-
// fix pagination links causing form params to get lost
|
5 |
-
jQuery('span.pagination-links a').click(function(ev){
|
6 |
-
ev.preventDefault();
|
7 |
-
var deparam = function(url){
|
8 |
-
var obj = {};
|
9 |
-
var pairs = url.split('&');
|
10 |
-
for(var i in pairs){
|
11 |
-
var split = pairs[i].split('=');
|
12 |
-
obj[decodeURIComponent(split[0])] = decodeURIComponent(split[1]);
|
13 |
-
}
|
14 |
-
return obj;
|
15 |
-
};
|
16 |
-
var paged = deparam(this.href).paged;
|
17 |
-
if (typeof paged === 'undefined') paged = 1;
|
18 |
-
jQuery('#audit-log-viewer').append(
|
19 |
-
jQuery('<input type="hidden" name="paged"/>').val(paged)
|
20 |
-
).submit();
|
21 |
-
});
|
22 |
-
};
|
23 |
-
|
24 |
-
function WsalAuditLogInit(_WsalData){
|
25 |
-
WsalData = _WsalData;
|
26 |
-
var WsalTkn = WsalData.autorefresh.token;
|
27 |
-
|
28 |
-
// list refresher
|
29 |
-
var WsalAjx = null;
|
30 |
-
var WsalChk = function(){
|
31 |
-
if(WsalAjx)WsalAjx.abort();
|
32 |
-
WsalAjx = jQuery.post(WsalData.ajaxurl, {
|
33 |
-
action: 'AjaxRefresh',
|
34 |
-
logcount: WsalTkn
|
35 |
-
}, function(data){
|
36 |
-
WsalAjx = null;
|
37 |
-
if(data && data !== 'false'){
|
38 |
-
WsalTkn = data;
|
39 |
-
jQuery('#audit-log-viewer').load(
|
40 |
-
location.href + ' #audit-log-viewer-content',
|
41 |
-
window['WsalAuditLogRefreshed']
|
42 |
-
);
|
43 |
-
}
|
44 |
-
WsalChk();
|
45 |
-
});
|
46 |
-
};
|
47 |
-
if(WsalData.autorefresh.enabled){
|
48 |
-
setInterval(WsalChk, 40000);
|
49 |
-
WsalChk();
|
50 |
-
}
|
51 |
-
|
52 |
-
WsalSsasInit();
|
53 |
-
}
|
54 |
-
|
55 |
-
var WsalIppsPrev;
|
56 |
-
|
57 |
-
function WsalIppsFocus(value){
|
58 |
-
WsalIppsPrev = value;
|
59 |
-
}
|
60 |
-
|
61 |
-
function WsalIppsChange(value){
|
62 |
-
if(value === ''){
|
63 |
-
value = window.prompt(WsalData.tr8n.numofitems, WsalIppsPrev);
|
64 |
-
if(value === null || value === WsalIppsPrev)return this.value = WsalIppsPrev; // operation canceled
|
65 |
-
}
|
66 |
-
jQuery('select.wsal-ipps').attr('disabled', true);
|
67 |
-
jQuery.post(WsalData.ajaxurl, {
|
68 |
-
action: 'AjaxSetIpp',
|
69 |
-
count: value
|
70 |
-
}, function(){
|
71 |
-
location.reload();
|
72 |
-
});
|
73 |
-
}
|
74 |
-
|
75 |
-
function WsalSsasInit(){
|
76 |
-
var SsasAjx = null;
|
77 |
-
var SsasInps = jQuery("input.wsal-ssas");
|
78 |
-
SsasInps.after('<div class="wsal-ssas-dd" style="display: none;"/>');
|
79 |
-
SsasInps.click(function(){
|
80 |
-
jQuery(this).select();
|
81 |
-
});
|
82 |
-
window['WsalAuditLogRefreshed']();
|
83 |
-
SsasInps.keyup(function(){
|
84 |
-
var SsasInp = jQuery(this);
|
85 |
-
var SsasDiv = SsasInp.next();
|
86 |
-
var SsasVal = SsasInp.val();
|
87 |
-
if(SsasAjx)SsasAjx.abort();
|
88 |
-
SsasInp.removeClass('loading');
|
89 |
-
|
90 |
-
// do a new search
|
91 |
-
if(SsasInp.attr('data-oldvalue') !== SsasVal && SsasVal.length > 2){
|
92 |
-
SsasInp.addClass('loading');
|
93 |
-
SsasAjx = jQuery.post(WsalData.ajaxurl, {
|
94 |
-
action: 'AjaxSearchSite',
|
95 |
-
search: SsasVal
|
96 |
-
}, function(data){
|
97 |
-
if(SsasAjx)SsasAjx = null;
|
98 |
-
SsasInp.removeClass('loading');
|
99 |
-
SsasDiv.hide();
|
100 |
-
SsasDiv.html('');
|
101 |
-
if(data && data.length){
|
102 |
-
var SsasReg = new RegExp(SsasVal.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'), 'gi');
|
103 |
-
for (var i = 0; i < data.length; i++){
|
104 |
-
var link = jQuery('<a href="javascript:;" onclick="WsalSsasChange(' + data[i].blog_id + ')"/>')
|
105 |
-
.text(data[i].blogname + ' (' + data[i].domain + ')');
|
106 |
-
link.html(link.text().replace(SsasReg, '<u>$&</u>'));
|
107 |
-
SsasDiv.append(link);
|
108 |
-
}
|
109 |
-
}else{
|
110 |
-
SsasDiv.append(jQuery('<span/>').text(WsalData.tr8n.searchnone));
|
111 |
-
}
|
112 |
-
SsasDiv.prepend(jQuery('<a href="javascript:;" onclick="WsalSsasChange(0)" class="allsites"/>').text(WsalData.tr8n.searchback));
|
113 |
-
SsasDiv.show();
|
114 |
-
}, 'json');
|
115 |
-
SsasInp.attr('data-oldvalue', SsasVal);
|
116 |
-
}
|
117 |
-
|
118 |
-
// handle keys
|
119 |
-
});
|
120 |
-
SsasInps.blur(function(){
|
121 |
-
setTimeout(function(){
|
122 |
-
var SsasInp = jQuery(this);
|
123 |
-
var SsasDiv = SsasInp.next();
|
124 |
-
SsasInp.attr('data-oldvalue', '');
|
125 |
-
SsasDiv.hide();
|
126 |
-
}, 200);
|
127 |
-
});
|
128 |
-
}
|
129 |
-
|
130 |
-
function WsalSsasChange(value){
|
131 |
-
jQuery('div.wsal-ssas-dd').hide();
|
132 |
-
jQuery('input.wsal-ssas').attr('disabled', true);
|
133 |
-
jQuery('#wsal-cbid').val(value);
|
134 |
-
jQuery('#audit-log-viewer').submit();
|
135 |
-
}
|
136 |
-
|
137 |
-
function WsalDisableCustom(link, meta_key){
|
138 |
-
var nfe = jQuery(this).parents('div:first');
|
139 |
-
jQuery(link).hide();
|
140 |
-
jQuery.ajax({
|
141 |
-
type: 'POST',
|
142 |
-
url: ajaxurl,
|
143 |
-
async: false,
|
144 |
-
data: { action: 'AjaxDisableCustomField', notice: meta_key },
|
145 |
-
success: function(data) {
|
146 |
-
var notice = jQuery('<div class="updated" data-notice-name="notifications-extension"></div>').html(data);
|
147 |
-
jQuery("h2:first").after(notice);
|
148 |
-
}
|
149 |
-
});
|
150 |
}
|
1 |
+
var WsalData;
|
2 |
+
|
3 |
+
window['WsalAuditLogRefreshed'] = function(){
|
4 |
+
// fix pagination links causing form params to get lost
|
5 |
+
jQuery('span.pagination-links a').click(function(ev){
|
6 |
+
ev.preventDefault();
|
7 |
+
var deparam = function(url){
|
8 |
+
var obj = {};
|
9 |
+
var pairs = url.split('&');
|
10 |
+
for(var i in pairs){
|
11 |
+
var split = pairs[i].split('=');
|
12 |
+
obj[decodeURIComponent(split[0])] = decodeURIComponent(split[1]);
|
13 |
+
}
|
14 |
+
return obj;
|
15 |
+
};
|
16 |
+
var paged = deparam(this.href).paged;
|
17 |
+
if (typeof paged === 'undefined') paged = 1;
|
18 |
+
jQuery('#audit-log-viewer').append(
|
19 |
+
jQuery('<input type="hidden" name="paged"/>').val(paged)
|
20 |
+
).submit();
|
21 |
+
});
|
22 |
+
};
|
23 |
+
|
24 |
+
function WsalAuditLogInit(_WsalData){
|
25 |
+
WsalData = _WsalData;
|
26 |
+
var WsalTkn = WsalData.autorefresh.token;
|
27 |
+
|
28 |
+
// list refresher
|
29 |
+
var WsalAjx = null;
|
30 |
+
var WsalChk = function(){
|
31 |
+
if(WsalAjx)WsalAjx.abort();
|
32 |
+
WsalAjx = jQuery.post(WsalData.ajaxurl, {
|
33 |
+
action: 'AjaxRefresh',
|
34 |
+
logcount: WsalTkn
|
35 |
+
}, function(data){
|
36 |
+
WsalAjx = null;
|
37 |
+
if(data && data !== 'false'){
|
38 |
+
WsalTkn = data;
|
39 |
+
jQuery('#audit-log-viewer').load(
|
40 |
+
location.href + ' #audit-log-viewer-content',
|
41 |
+
window['WsalAuditLogRefreshed']
|
42 |
+
);
|
43 |
+
}
|
44 |
+
WsalChk();
|
45 |
+
});
|
46 |
+
};
|
47 |
+
if(WsalData.autorefresh.enabled){
|
48 |
+
setInterval(WsalChk, 40000);
|
49 |
+
WsalChk();
|
50 |
+
}
|
51 |
+
|
52 |
+
WsalSsasInit();
|
53 |
+
}
|
54 |
+
|
55 |
+
var WsalIppsPrev;
|
56 |
+
|
57 |
+
function WsalIppsFocus(value){
|
58 |
+
WsalIppsPrev = value;
|
59 |
+
}
|
60 |
+
|
61 |
+
function WsalIppsChange(value){
|
62 |
+
if(value === ''){
|
63 |
+
value = window.prompt(WsalData.tr8n.numofitems, WsalIppsPrev);
|
64 |
+
if(value === null || value === WsalIppsPrev)return this.value = WsalIppsPrev; // operation canceled
|
65 |
+
}
|
66 |
+
jQuery('select.wsal-ipps').attr('disabled', true);
|
67 |
+
jQuery.post(WsalData.ajaxurl, {
|
68 |
+
action: 'AjaxSetIpp',
|
69 |
+
count: value
|
70 |
+
}, function(){
|
71 |
+
location.reload();
|
72 |
+
});
|
73 |
+
}
|
74 |
+
|
75 |
+
function WsalSsasInit(){
|
76 |
+
var SsasAjx = null;
|
77 |
+
var SsasInps = jQuery("input.wsal-ssas");
|
78 |
+
SsasInps.after('<div class="wsal-ssas-dd" style="display: none;"/>');
|
79 |
+
SsasInps.click(function(){
|
80 |
+
jQuery(this).select();
|
81 |
+
});
|
82 |
+
window['WsalAuditLogRefreshed']();
|
83 |
+
SsasInps.keyup(function(){
|
84 |
+
var SsasInp = jQuery(this);
|
85 |
+
var SsasDiv = SsasInp.next();
|
86 |
+
var SsasVal = SsasInp.val();
|
87 |
+
if(SsasAjx)SsasAjx.abort();
|
88 |
+
SsasInp.removeClass('loading');
|
89 |
+
|
90 |
+
// do a new search
|
91 |
+
if(SsasInp.attr('data-oldvalue') !== SsasVal && SsasVal.length > 2){
|
92 |
+
SsasInp.addClass('loading');
|
93 |
+
SsasAjx = jQuery.post(WsalData.ajaxurl, {
|
94 |
+
action: 'AjaxSearchSite',
|
95 |
+
search: SsasVal
|
96 |
+
}, function(data){
|
97 |
+
if(SsasAjx)SsasAjx = null;
|
98 |
+
SsasInp.removeClass('loading');
|
99 |
+
SsasDiv.hide();
|
100 |
+
SsasDiv.html('');
|
101 |
+
if(data && data.length){
|
102 |
+
var SsasReg = new RegExp(SsasVal.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'), 'gi');
|
103 |
+
for (var i = 0; i < data.length; i++){
|
104 |
+
var link = jQuery('<a href="javascript:;" onclick="WsalSsasChange(' + data[i].blog_id + ')"/>')
|
105 |
+
.text(data[i].blogname + ' (' + data[i].domain + ')');
|
106 |
+
link.html(link.text().replace(SsasReg, '<u>$&</u>'));
|
107 |
+
SsasDiv.append(link);
|
108 |
+
}
|
109 |
+
}else{
|
110 |
+
SsasDiv.append(jQuery('<span/>').text(WsalData.tr8n.searchnone));
|
111 |
+
}
|
112 |
+
SsasDiv.prepend(jQuery('<a href="javascript:;" onclick="WsalSsasChange(0)" class="allsites"/>').text(WsalData.tr8n.searchback));
|
113 |
+
SsasDiv.show();
|
114 |
+
}, 'json');
|
115 |
+
SsasInp.attr('data-oldvalue', SsasVal);
|
116 |
+
}
|
117 |
+
|
118 |
+
// handle keys
|
119 |
+
});
|
120 |
+
SsasInps.blur(function(){
|
121 |
+
setTimeout(function(){
|
122 |
+
var SsasInp = jQuery(this);
|
123 |
+
var SsasDiv = SsasInp.next();
|
124 |
+
SsasInp.attr('data-oldvalue', '');
|
125 |
+
SsasDiv.hide();
|
126 |
+
}, 200);
|
127 |
+
});
|
128 |
+
}
|
129 |
+
|
130 |
+
function WsalSsasChange(value){
|
131 |
+
jQuery('div.wsal-ssas-dd').hide();
|
132 |
+
jQuery('input.wsal-ssas').attr('disabled', true);
|
133 |
+
jQuery('#wsal-cbid').val(value);
|
134 |
+
jQuery('#audit-log-viewer').submit();
|
135 |
+
}
|
136 |
+
|
137 |
+
function WsalDisableCustom(link, meta_key){
|
138 |
+
var nfe = jQuery(this).parents('div:first');
|
139 |
+
jQuery(link).hide();
|
140 |
+
jQuery.ajax({
|
141 |
+
type: 'POST',
|
142 |
+
url: ajaxurl,
|
143 |
+
async: false,
|
144 |
+
data: { action: 'AjaxDisableCustomField', notice: meta_key },
|
145 |
+
success: function(data) {
|
146 |
+
var notice = jQuery('<div class="updated" data-notice-name="notifications-extension"></div>').html(data);
|
147 |
+
jQuery("h2:first").after(notice);
|
148 |
+
}
|
149 |
+
});
|
150 |
}
|
js/common.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
-
|
2 |
-
jQuery(document).ready(function(){
|
3 |
-
jQuery('a.wsal-dismiss-notification').click(function(){
|
4 |
-
var nfe = jQuery(this).parents('div:first');
|
5 |
-
var nfn = nfe.attr('data-notice-name');
|
6 |
-
jQuery.ajax({
|
7 |
-
type: 'POST',
|
8 |
-
url: ajaxurl,
|
9 |
-
async: false,
|
10 |
-
data: { action: 'AjaxDismissNotice', notice: nfn }
|
11 |
-
});
|
12 |
-
nfe.fadeOut();
|
13 |
-
});
|
14 |
-
});
|
1 |
+
|
2 |
+
jQuery(document).ready(function(){
|
3 |
+
jQuery('a.wsal-dismiss-notification').click(function(){
|
4 |
+
var nfe = jQuery(this).parents('div:first');
|
5 |
+
var nfn = nfe.attr('data-notice-name');
|
6 |
+
jQuery.ajax({
|
7 |
+
type: 'POST',
|
8 |
+
url: ajaxurl,
|
9 |
+
async: false,
|
10 |
+
data: { action: 'AjaxDismissNotice', notice: nfn }
|
11 |
+
});
|
12 |
+
nfe.fadeOut();
|
13 |
+
});
|
14 |
+
});
|
js/nice_r.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
-
function nice_r_toggle(pfx, id){
|
2 |
-
var el = document.getElementById(pfx+'_v'+id);
|
3 |
-
if(el){
|
4 |
-
if(el.style.display==='block'){
|
5 |
-
el.style.display = 'none';
|
6 |
-
document.getElementById(pfx+'_a'+id).innerHTML = '►';
|
7 |
-
}else{
|
8 |
-
el.style.display = 'block';
|
9 |
-
document.getElementById(pfx+'_a'+id).innerHTML = '▼';
|
10 |
-
}
|
11 |
-
}
|
12 |
}
|
1 |
+
function nice_r_toggle(pfx, id){
|
2 |
+
var el = document.getElementById(pfx+'_v'+id);
|
3 |
+
if(el){
|
4 |
+
if(el.style.display==='block'){
|
5 |
+
el.style.display = 'none';
|
6 |
+
document.getElementById(pfx+'_a'+id).innerHTML = '►';
|
7 |
+
}else{
|
8 |
+
el.style.display = 'block';
|
9 |
+
document.getElementById(pfx+'_a'+id).innerHTML = '▼';
|
10 |
+
}
|
11 |
+
}
|
12 |
}
|
js/settings.js
CHANGED
@@ -1,73 +1,73 @@
|
|
1 |
-
jQuery(document).ready(function(){
|
2 |
-
var RemoveSecToken = function(){
|
3 |
-
var $this = jQuery(this).parents('span:first');
|
4 |
-
$this.addClass('sectoken-del').fadeOut('fast', function(){
|
5 |
-
$this.remove();
|
6 |
-
});
|
7 |
-
};
|
8 |
-
|
9 |
-
jQuery('#ViewerQueryBox, #EditorQueryBox, #ExRoleQueryBox, #ExUserQueryBox, #CustomQueryBox').keydown(function(event){
|
10 |
-
if(event.keyCode === 13) {
|
11 |
-
var type = jQuery(this).attr('id').substr(0, 6);
|
12 |
-
jQuery('#'+type+'QueryAdd').click();
|
13 |
-
return false;
|
14 |
-
}
|
15 |
-
});
|
16 |
-
|
17 |
-
jQuery('#ViewerQueryAdd, #EditorQueryAdd, #ExRoleQueryAdd, #ExUserQueryAdd, #CustomQueryAdd').click(function(){
|
18 |
-
var type = jQuery(this).attr('id').substr(0, 6);
|
19 |
-
var value = jQuery.trim(jQuery('#'+type+'QueryBox').val());
|
20 |
-
var existing = jQuery('#'+type+'List input').filter(function() { return this.value === value; });
|
21 |
-
|
22 |
-
if(!value || existing.length)return; // if value is empty or already used, stop here
|
23 |
-
|
24 |
-
jQuery('#'+type+'QueryBox, #'+type+'QueryAdd').attr('disabled', true);
|
25 |
-
jQuery.post(jQuery('#ajaxurl').val(), {action: 'AjaxCheckSecurityToken', token: value}, function(data){
|
26 |
-
jQuery('#'+type+'QueryBox, #'+type+'QueryAdd').attr('disabled', false);
|
27 |
-
if (type != 'Custom') {
|
28 |
-
if(data==='other') {
|
29 |
-
alert('The specified token is not a user nor a role!');
|
30 |
-
jQuery('#'+type+'QueryBox').val('');
|
31 |
-
return;
|
32 |
-
}
|
33 |
-
}
|
34 |
-
jQuery('#'+type+'QueryBox').val('');
|
35 |
-
jQuery('#'+type+'List').append(jQuery('<span class="sectoken-'+data+'"/>').text(value).append(
|
36 |
-
jQuery('<input type="hidden" name="'+type+'s[]"/>').val(value),
|
37 |
-
jQuery('<a href="javascript:;" title="Remove">×</a>').click(RemoveSecToken)
|
38 |
-
));
|
39 |
-
});
|
40 |
-
});
|
41 |
-
|
42 |
-
jQuery('#ViewerList>span>a, #EditorList>span>a, #ExRoleList>span>a, #ExUserList>span>a, #CustomList>span>a').click(RemoveSecToken);
|
43 |
-
|
44 |
-
jQuery('#RestrictAdmins').change(function(){
|
45 |
-
var user = jQuery('#RestrictAdminsDefaultUser').val();
|
46 |
-
var fltr = function() { return this.value === user; };
|
47 |
-
if (this.checked && jQuery('#EditorList input').filter(fltr).length === 0) {
|
48 |
-
jQuery('#EditorList').append(
|
49 |
-
jQuery('<span class="sectoken-user"/>').text(user)
|
50 |
-
.prepend(jQuery('<input type="hidden" name="Editors[]"/>').val(user))
|
51 |
-
.append(jQuery('<a href="javascript:;" title="Remove">×</a>').click(RemoveSecToken))
|
52 |
-
);
|
53 |
-
} else {
|
54 |
-
jQuery('#EditorList').children().remove();
|
55 |
-
}
|
56 |
-
});
|
57 |
-
|
58 |
-
|
59 |
-
var usersUrl = ajaxurl + "?action=AjaxGetAllUsers";
|
60 |
-
jQuery("#ExUserQueryBox").autocomplete({
|
61 |
-
source: usersUrl,
|
62 |
-
minLength:1
|
63 |
-
});
|
64 |
-
|
65 |
-
var rolesUrl = ajaxurl + "?action=AjaxGetAllRoles";
|
66 |
-
jQuery("#ExRoleQueryBox").autocomplete({
|
67 |
-
source: rolesUrl,
|
68 |
-
minLength:1
|
69 |
-
});
|
70 |
-
|
71 |
-
});
|
72 |
-
|
73 |
-
|
1 |
+
jQuery(document).ready(function(){
|
2 |
+
var RemoveSecToken = function(){
|
3 |
+
var $this = jQuery(this).parents('span:first');
|
4 |
+
$this.addClass('sectoken-del').fadeOut('fast', function(){
|
5 |
+
$this.remove();
|
6 |
+
});
|
7 |
+
};
|
8 |
+
|
9 |
+
jQuery('#ViewerQueryBox, #EditorQueryBox, #ExRoleQueryBox, #ExUserQueryBox, #CustomQueryBox').keydown(function(event){
|
10 |
+
if(event.keyCode === 13) {
|
11 |
+
var type = jQuery(this).attr('id').substr(0, 6);
|
12 |
+
jQuery('#'+type+'QueryAdd').click();
|
13 |
+
return false;
|
14 |
+
}
|
15 |
+
});
|
16 |
+
|
17 |
+
jQuery('#ViewerQueryAdd, #EditorQueryAdd, #ExRoleQueryAdd, #ExUserQueryAdd, #CustomQueryAdd').click(function(){
|
18 |
+
var type = jQuery(this).attr('id').substr(0, 6);
|
19 |
+
var value = jQuery.trim(jQuery('#'+type+'QueryBox').val());
|
20 |
+
var existing = jQuery('#'+type+'List input').filter(function() { return this.value === value; });
|
21 |
+
|
22 |
+
if(!value || existing.length)return; // if value is empty or already used, stop here
|
23 |
+
|
24 |
+
jQuery('#'+type+'QueryBox, #'+type+'QueryAdd').attr('disabled', true);
|
25 |
+
jQuery.post(jQuery('#ajaxurl').val(), {action: 'AjaxCheckSecurityToken', token: value}, function(data){
|
26 |
+
jQuery('#'+type+'QueryBox, #'+type+'QueryAdd').attr('disabled', false);
|
27 |
+
if (type != 'Custom') {
|
28 |
+
if(data==='other') {
|
29 |
+
alert('The specified token is not a user nor a role!');
|
30 |
+
jQuery('#'+type+'QueryBox').val('');
|
31 |
+
return;
|
32 |
+
}
|
33 |
+
}
|
34 |
+
jQuery('#'+type+'QueryBox').val('');
|
35 |
+
jQuery('#'+type+'List').append(jQuery('<span class="sectoken-'+data+'"/>').text(value).append(
|
36 |
+
jQuery('<input type="hidden" name="'+type+'s[]"/>').val(value),
|
37 |
+
jQuery('<a href="javascript:;" title="Remove">×</a>').click(RemoveSecToken)
|
38 |
+
));
|
39 |
+
});
|
40 |
+
});
|
41 |
+
|
42 |
+
jQuery('#ViewerList>span>a, #EditorList>span>a, #ExRoleList>span>a, #ExUserList>span>a, #CustomList>span>a').click(RemoveSecToken);
|
43 |
+
|
44 |
+
jQuery('#RestrictAdmins').change(function(){
|
45 |
+
var user = jQuery('#RestrictAdminsDefaultUser').val();
|
46 |
+
var fltr = function() { return this.value === user; };
|
47 |
+
if (this.checked && jQuery('#EditorList input').filter(fltr).length === 0) {
|
48 |
+
jQuery('#EditorList').append(
|
49 |
+
jQuery('<span class="sectoken-user"/>').text(user)
|
50 |
+
.prepend(jQuery('<input type="hidden" name="Editors[]"/>').val(user))
|
51 |
+
.append(jQuery('<a href="javascript:;" title="Remove">×</a>').click(RemoveSecToken))
|
52 |
+
);
|
53 |
+
} else {
|
54 |
+
jQuery('#EditorList').children().remove();
|
55 |
+
}
|
56 |
+
});
|
57 |
+
|
58 |
+
|
59 |
+
var usersUrl = ajaxurl + "?action=AjaxGetAllUsers";
|
60 |
+
jQuery("#ExUserQueryBox").autocomplete({
|
61 |
+
source: usersUrl,
|
62 |
+
minLength:1
|
63 |
+
});
|
64 |
+
|
65 |
+
var rolesUrl = ajaxurl + "?action=AjaxGetAllRoles";
|
66 |
+
jQuery("#ExRoleQueryBox").autocomplete({
|
67 |
+
source: rolesUrl,
|
68 |
+
minLength:1
|
69 |
+
});
|
70 |
+
|
71 |
+
});
|
72 |
+
|
73 |
+
|
languages/wp-security-audit-log-sr_RS.mo
ADDED
Binary file
|
readme.txt
CHANGED
@@ -1,23 +1,23 @@
|
|
1 |
=== WP Security Audit Log ===
|
2 |
Contributors: WPWhiteSecurity, robert681
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=donations%40wpwhitesecurity%2ecom
|
4 |
-
Plugin URI: http://www.
|
5 |
License: GPLv3
|
6 |
License URI: http://www.gnu.org/licenses/gpl.html
|
7 |
Tags: wordpress security plugin, wordpress security audit log, audit log, wordpress log, event log wordpress, wordpress user tracking, wordpress activity log, wordpress audit, security event log, audit trail, security audit trail, wordpress security alerts, wordpress monitor, wordpress security monitor, wordpress admin, wordpress admin monitoring, analytics, activity, admin, multisite, wordpress multisite, actions, dashboard, log, notification, wordpress monitoring, email notification, wordpress email alerts, tracking, user tracking, user activity report
|
8 |
Requires at least: 3.6
|
9 |
Tested up to: 4.2.3
|
10 |
-
Stable tag: 2.0.
|
11 |
|
12 |
Keep a WordPress audit log of all users' changes and under the hood WordPress activity - Identify WordPress issues before they become security problems.
|
13 |
|
14 |
== Description ==
|
15 |
-
Keep an audit log of everything that is happening on your WordPress and [WordPress multisite](http://www.
|
16 |
|
17 |
> <strong>Free and Premium Support</strong><br>
|
18 |
>
|
19 |
> WP White Security provides support for WP Security Audit Log plugin on the WordPress forums for free, though please note that it is free support hence it is not always possible to answer all questions on a timely manner, although we do try.
|
20 |
-
> Personalized premium support is available via email to anyone who purchases any of the [Premium
|
21 |
|
22 |
= Keep A WordPress Security Audit Log & Identify WordPress Security Issues =
|
23 |
WP Security Audit Log keeps a log of everything happening on your WordPress blog or website and WordPress multisite network. By using WP Security Audit Log security plugin it is very easy to track suspicious user activity before it becomes a problem or a security issue. A security alert is generated by the plugin when:
|
@@ -37,7 +37,7 @@ WP Security Audit Log keeps a log of everything happening on your WordPress blog
|
|
37 |
* Failed login attempts
|
38 |
* and much more...
|
39 |
|
40 |
-
Refer to the complete list of [WordPress Security Audit Alerts](http://www.
|
41 |
|
42 |
= Monitor WordPress Users Activity & Productivity =
|
43 |
If you own a multi user WordPress blog or website, or a WordPress multisite network installation you can use WP Security Audit Log plugin to monitor your users' activity and productivity. With WP Security Audit Log WordPress plugin you can monitor:
|
@@ -53,27 +53,27 @@ If you own a multi user WordPress blog or website, or a WordPress multisite netw
|
|
53 |
* Uses who upload or delete any sort of files
|
54 |
* and much more...
|
55 |
|
56 |
-
Refer to the complete list of [WordPress Security Audit Alerts](http://www.
|
57 |
|
58 |
= Get Notified Instantly of Changes on Your WordPress =
|
59 |
<strong>Get notified instantly via email of important changes happening on your blogs and websites running on WordPress and WordPress multisite.</strong>
|
60 |
|
61 |
-
Use the premium [
|
62 |
|
63 |
= Use Free Text Based Searches to Search for Specific Activity on WordPress =
|
64 |
<strong>The search functionality allows you to quickly find specific WordPress activity you are looking for.</strong>
|
65 |
|
66 |
-
It is virtually impossible to find specific WordPress activity by manually browsing through thousands of WordPress security alerts. Now you can use the premium [
|
67 |
|
68 |
= Generate HTML and CSV WordPress Reports =
|
69 |
<strong>Generate WordPress activity reports to ensure users' productivity and meet any legal and regulatory compliance requirements your business needs to adhere to.</strong>
|
70 |
|
71 |
-
Use the premium [
|
72 |
|
73 |
= WP Security Audit Log for WordPress Multisite =
|
74 |
WP Security Audit Log is the first tracking and audit WordPress security monitoring plugin that supports WordPress multisite network installations and can monitor activity on such WordPress multisite network installations.
|
75 |
|
76 |
-
For more information about the features for WordPress Multisite network installation refer to [WP Security Audit Log Features for WordPress Multisite](http://www.
|
77 |
|
78 |
= WordPress Security Audit Log in your Language! =
|
79 |
We need help translating the plugin and the WordPress Security Events. If you're good at translating, please drop us an email on plugins@wpwhitesecurity.com.
|
@@ -93,7 +93,7 @@ NOTE: Developer options should NEVER be enabled on Live websites. They should on
|
|
93 |
WP Security Audit Log plugin also has a number of features that make WordPress and WordPress multisite monitoring and auditing easier, such as:
|
94 |
|
95 |
* Realtime Audit Log viewer to watch user activity as it happens without any delays
|
96 |
-
* Built-in support for reverse proxies and web application firewalls [more information](http://www.
|
97 |
* Limit who can view the security alerts by users and roles
|
98 |
* Limit who can manage the plugin by users and roles
|
99 |
* Configurable WordPress dashboard widget highlighting the most recent critical activity
|
@@ -117,11 +117,11 @@ WP Security Audit Log plugin also has a number of features that make WordPress a
|
|
117 |
= Related Links and Documentation =
|
118 |
For more information and to get started with WordPress Security, check out the following:
|
119 |
|
120 |
-
* [List of WordPress Security Alerts](http://www.
|
121 |
-
* [WordPress Multisite Features](http://www.
|
122 |
-
* [WP Security Audit Log and Reverse Proxy and WAFs Support](http://www.
|
123 |
-
* [WP Security Audit Log Database Documentation](http://www.
|
124 |
-
* [Official WP Security Audit Log
|
125 |
|
126 |
= WordPress Security Tips & Tricks =
|
127 |
Even if WordPress security is not your cup of tea, the security of your WordPress is your responsibility. Keep yourself up to date with the latest WordPress Security Tips & Tricks. WP White Security frequently publishes WordPress security tips & tricks on the [WordPress Security section](http://www.wpwhitesecurity.com/wordpress-security/) of their blog.
|
@@ -129,7 +129,7 @@ Even if WordPress security is not your cup of tea, the security of your WordPres
|
|
129 |
= Plugin Newsletter =
|
130 |
To keep yourself updated with what is new and updated in our WordPress security plugins please subscribe to the [WP White Security Plugins Newsletter](http://eepurl.com/Jn9sP).
|
131 |
|
132 |
-
**Note: This plugin requires PHP 5.3 or higher to be activated because older versions of PHP are no longer maintained by PHP themselves, which make them prone to security issues. For more information or if you need assistance with your version of PHP please get in touch with us by using our [contact form](
|
133 |
|
134 |
== Installation ==
|
135 |
|
@@ -144,23 +144,23 @@ To keep yourself updated with what is new and updated in our WordPress security
|
|
144 |
By default the plugin will keep 5,000 WordPress Security Alerts. When this limit is reached, older alerts are deleted to make place for the new ones. You can configure the plugin to keep more alerts from the settings page. You can also configure the plugin to delete alerts which are older than a number of days.
|
145 |
|
146 |
= Is there a complete list of all WordPress security audit events? =
|
147 |
-
Yes. A complete list can be found [here](http://www.
|
148 |
|
149 |
= Can I disable some WordPress security alerts? =
|
150 |
|
151 |
Yes it is possible to disable (and re-enable) specific WordPress security alerts. To do so navigate to the "Enable/Disable Alerts" node in the plugin's menu, select the category tab and untick the WordPress security alert. Tick back the alert to re-enable it.
|
152 |
|
153 |
= Can WP Security Audit Log plugin work and monitor activity on WodPress Multisite? =
|
154 |
-
Yes, WP Security Audit Log works on WordPress Multisite networks, i.e. it can monitor user and under the hood WordPress activity on WordPress multisite installations. For more information refer to the post [WP Security Audit Log Features for WordPress Multisite installation](http://www.
|
155 |
|
156 |
= Can I receive an email notification when a specific change happens on WordPress? =
|
157 |
-
Yes it is possible to do so with the [
|
158 |
|
159 |
= How can I search for a specific WordPress security alert?
|
160 |
-
You can use the premium add-on [
|
161 |
|
162 |
= Can I generate reports from the WordPress security audit log? =
|
163 |
-
Yes it is possible to do so with the premium [
|
164 |
|
165 |
= Can I exclude users or roles from being monitored? =
|
166 |
Yes it is possible to exclude both users and roles from being monitored. To exclude a user or a role specify it in the Excluded Objects section in the plugin's settings node.
|
@@ -172,14 +172,18 @@ Yes it is possible to exclude custom fields from being monitored. To exclude a c
|
|
172 |
|
173 |
1. The Audit Log Viewer from where the WordPress administrator can see all the security events generated by WP Security Audit Log WordPress plugin.
|
174 |
2. The WP Security Audit Log plugin options from where WordPress administrator can configure the auto pruning of security alerts and specific user access.
|
175 |
-
3. Configuring WordPress email alerts with the [Notifications
|
176 |
-
4. Search and filters functionality to automatically search through the WordPress security audit log with the [Search Extension](http://www.
|
177 |
5. The Enable/Disable Alerts settings node from where Administrators can disable or enable WordPress security alerts.
|
178 |
6. The Audit Log Viewer of a Super Admin in a WordPress multisite network installation with the Site selection drop down menu.
|
179 |
7. If there are more than 15 sites in a multisite, an auto complete site search shows up instead of the drop down menu (see [screenshots](https://wordpress.org/plugins/wp-security-audit-log/screenshots/) for reference)
|
180 |
|
181 |
== Changelog ==
|
182 |
|
|
|
|
|
|
|
|
|
183 |
= 2.0.0 (2015-07-16) =
|
184 |
* **New Features**
|
185 |
* New database connector allowing faster and more efficient plugin to WordPress database communication
|
@@ -221,7 +225,7 @@ Yes it is possible to exclude custom fields from being monitored. To exclude a c
|
|
221 |
* Completely removed the user of the is_admin() function to follow better security practises
|
222 |
|
223 |
* **Bug Fixes**
|
224 |
-
* Updated the licensing mechanism to correct problem where [WP Security Audit Log premium add-ons](http://www.
|
225 |
* Fixed several issues where the database tables were not being created during install or upgrade. [Support ticket](https://wordpress.org/support/topic/wp_wsal_options-not-created-with-plugin-update?replies=8) and [Support ticket 2](https://wordpress.org/support/topic/missing-database-tables-1?replies=9)
|
226 |
* Fixed an issue where the plugin did not monitor any activity in specific scenarios. [Support ticket](https://wordpress.org/support/topic/clean-install-not-reporting-when-posts-or-pages-are-creatededited?replies=4) and [Support ticket 2](https://wordpress.org/support/topic/blank-audit-log-page?replies=2)
|
227 |
* Removed duplicate options in the settings page. [Support ticket](https://wordpress.org/support/topic/refresh-audit-view-refresh-audit-log-viewer?replies=5)
|
@@ -244,7 +248,7 @@ Yes it is possible to exclude custom fields from being monitored. To exclude a c
|
|
244 |
|
245 |
= 1.4 (2015-02-24) =
|
246 |
* **New Features**
|
247 |
-
* WordPress username is now reported when a failed login is recorded - [More Details](http://www.
|
248 |
* Plugin is now available in Romanian thanks to [Artmotion](http://www.artmotion.eu)
|
249 |
|
250 |
* **Improvements**
|
@@ -257,7 +261,7 @@ Yes it is possible to exclude custom fields from being monitored. To exclude a c
|
|
257 |
|
258 |
= 1.3.3 (2015-01-21) =
|
259 |
* **New Features**
|
260 |
-
* [Premium Add-
|
261 |
|
262 |
* **Improvements**
|
263 |
* Updated some of the help text in plugin's settings page
|
@@ -269,7 +273,7 @@ Yes it is possible to exclude custom fields from being monitored. To exclude a c
|
|
269 |
|
270 |
= 1.3.2 (2014-12-16) =
|
271 |
* **New Features and Options**
|
272 |
-
* Plugin automatically retrieves user's originating IP address even if WordPress is installed behind a reverse proxy, web application firewall or load balancer. For more information refer to [WP Security Audit Log, Reverse Proxies and WAFs](http://www.
|
273 |
* New option to omit internal IP addresses from being reported in the WordPress security audit log
|
274 |
|
275 |
* **Removed Functionality**
|
@@ -461,8 +465,6 @@ Yes it is possible to exclude custom fields from being monitored. To exclude a c
|
|
461 |
* Alert 0003: PHP Notice
|
462 |
* Alert 0004: PHP Exception
|
463 |
* Alert 0005: PHP Shutdown Error
|
464 |
-
|
465 |
-
* For more information about what is new and changed in this version of the plugin refer to the [WP Security Audit Log release notes](http://www.wpwhitesecurity.com/wordpress-plugins/easy-wordpress-security-monitor-wp-security-audit-log-plugin).
|
466 |
|
467 |
= 0.6.3 (2014-02-18) =
|
468 |
* **Bug Fix**
|
@@ -479,7 +481,7 @@ Yes it is possible to exclude custom fields from being monitored. To exclude a c
|
|
479 |
|
480 |
= 0.6 (2014-01-15) =
|
481 |
* **New Plugin Feature**
|
482 |
-
* WordPress Multisite Support [Read More](http://www.
|
483 |
|
484 |
* **New WordPress Security Alerts for monitoring specific multisite activity on a WordPress multisite network installation**
|
485 |
* Alert 4008: User is granted super admin privileges (network)
|
1 |
=== WP Security Audit Log ===
|
2 |
Contributors: WPWhiteSecurity, robert681
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=donations%40wpwhitesecurity%2ecom
|
4 |
+
Plugin URI: http://www.wpsecurityauditlog.com
|
5 |
License: GPLv3
|
6 |
License URI: http://www.gnu.org/licenses/gpl.html
|
7 |
Tags: wordpress security plugin, wordpress security audit log, audit log, wordpress log, event log wordpress, wordpress user tracking, wordpress activity log, wordpress audit, security event log, audit trail, security audit trail, wordpress security alerts, wordpress monitor, wordpress security monitor, wordpress admin, wordpress admin monitoring, analytics, activity, admin, multisite, wordpress multisite, actions, dashboard, log, notification, wordpress monitoring, email notification, wordpress email alerts, tracking, user tracking, user activity report
|
8 |
Requires at least: 3.6
|
9 |
Tested up to: 4.2.3
|
10 |
+
Stable tag: 2.0.1
|
11 |
|
12 |
Keep a WordPress audit log of all users' changes and under the hood WordPress activity - Identify WordPress issues before they become security problems.
|
13 |
|
14 |
== Description ==
|
15 |
+
Keep an audit log of everything that is happening on your WordPress and [WordPress multisite](http://www.wpsecurityauditlog.com/documentation/wordpress-multisite-plugin-features-support/) with WP Security Audit Log to ensure user productivity and identify WordPress security issues before they become a security problem. WP Security Audit Log, WordPress' most comprehensive user monitoring and audit log plugin already helps thousands of WordPress administrators, owners and security professionals ensure the security of their websites and blogs. Ensure the security of your WordPress too by installing WP Security Audit Log. The community's favourite WordPress user monitoring monitoring and security auditing plugin is developed by WordPress Security Consultants and Professionals [WP White Security](http://www.wpwhitesecurity.com/).
|
16 |
|
17 |
> <strong>Free and Premium Support</strong><br>
|
18 |
>
|
19 |
> WP White Security provides support for WP Security Audit Log plugin on the WordPress forums for free, though please note that it is free support hence it is not always possible to answer all questions on a timely manner, although we do try.
|
20 |
+
> Personalized premium support is available via email to anyone who purchases any of the [Premium Add-Ons](http://www.wpsecurityauditlog.com/plugin-extensions/), such as the [Email Notifications](http://www.wpsecurityauditlog.com/extensions/wordpress-email-notifications-add-on/), [Search](http://www.wpsecurityauditlog.com/extensions/search-add-on-for-wordpress-security-audit-log/) and [Reports](http://www.wpsecurityauditlog.com/extensions/compliance-reports-add-on-for-wordpress/) Add-Ons.
|
21 |
|
22 |
= Keep A WordPress Security Audit Log & Identify WordPress Security Issues =
|
23 |
WP Security Audit Log keeps a log of everything happening on your WordPress blog or website and WordPress multisite network. By using WP Security Audit Log security plugin it is very easy to track suspicious user activity before it becomes a problem or a security issue. A security alert is generated by the plugin when:
|
37 |
* Failed login attempts
|
38 |
* and much more...
|
39 |
|
40 |
+
Refer to the complete list of [WordPress Security Audit Alerts](http://www.wpsecurityauditlog.com/documentation/list-monitoring-wordpress-security-alerts-audit-log/) for more information on what WordPress activity can be monitored with WP Security Audit Log.
|
41 |
|
42 |
= Monitor WordPress Users Activity & Productivity =
|
43 |
If you own a multi user WordPress blog or website, or a WordPress multisite network installation you can use WP Security Audit Log plugin to monitor your users' activity and productivity. With WP Security Audit Log WordPress plugin you can monitor:
|
53 |
* Uses who upload or delete any sort of files
|
54 |
* and much more...
|
55 |
|
56 |
+
Refer to the complete list of [WordPress Security Audit Alerts](http://www.wpsecurityauditlog.com/documentation/list-monitoring-wordpress-security-alerts-audit-log/) for more information on what other WordPress user activity can be monitored with the WP Security Audit Log WordPress plugin.
|
57 |
|
58 |
= Get Notified Instantly of Changes on Your WordPress =
|
59 |
<strong>Get notified instantly via email of important changes happening on your blogs and websites running on WordPress and WordPress multisite.</strong>
|
60 |
|
61 |
+
Use the premium [Email Notifications Add-On](http://www.wpsecurityauditlog.com/extensions/wordpress-email-notifications-add-on/) to configure monitoring rules and get notified via email of specific actions. For example you can setup notifications rules to be alerted via email should any WordPress user logs in to your WordPress outside office hours. The email alerts include all the details a WordPress administrator or owner might need, such as the source IP address, user, user role, date, time, details about the actual action and much more.
|
62 |
|
63 |
= Use Free Text Based Searches to Search for Specific Activity on WordPress =
|
64 |
<strong>The search functionality allows you to quickly find specific WordPress activity you are looking for.</strong>
|
65 |
|
66 |
+
It is virtually impossible to find specific WordPress activity by manually browsing through thousands of WordPress security alerts. Now you can use the premium [Search Add-On](http://www.wpsecurityauditlog.com/extensions/search-add-on-for-wordpress-security-audit-log/) to do free text based searches in the WordPress audit log, allowing you to easily pin point specific WordPress user, site, plugin, theme and other activity. The Search extension also has a number of built-in filters that you can use to fine tune your search results, hence allowing you to find the WordPress security alert you are looking for easily and quickly.
|
67 |
|
68 |
= Generate HTML and CSV WordPress Reports =
|
69 |
<strong>Generate WordPress activity reports to ensure users' productivity and meet any legal and regulatory compliance requirements your business needs to adhere to.</strong>
|
70 |
|
71 |
+
Use the premium [Reports Add-On](http://www.wpsecurityauditlog.com/extensions/compliance-reports-add-on-for-wordpress/) to generate any type of WordPress report. For example you can generate a WordPress user or group of users activity report, specific role activity report and also site activity report in case you are running WordPress multisite. Unlike other WordPress reports plugins, WSAL Reporting Extension does not have templates that restrict you to specific reports types, but it allows you to choose any data source for your reports.
|
72 |
|
73 |
= WP Security Audit Log for WordPress Multisite =
|
74 |
WP Security Audit Log is the first tracking and audit WordPress security monitoring plugin that supports WordPress multisite network installations and can monitor activity on such WordPress multisite network installations.
|
75 |
|
76 |
+
For more information about the features for WordPress Multisite network installation refer to [WP Security Audit Log Features for WordPress Multisite](http://www.wpsecurityauditlog.com/documentation/wordpress-multisite-plugin-features-support/)
|
77 |
|
78 |
= WordPress Security Audit Log in your Language! =
|
79 |
We need help translating the plugin and the WordPress Security Events. If you're good at translating, please drop us an email on plugins@wpwhitesecurity.com.
|
93 |
WP Security Audit Log plugin also has a number of features that make WordPress and WordPress multisite monitoring and auditing easier, such as:
|
94 |
|
95 |
* Realtime Audit Log viewer to watch user activity as it happens without any delays
|
96 |
+
* Built-in support for reverse proxies and web application firewalls [more information](http://www.wpsecurityauditlog.com/documentation/automatically-retrieve-originating-wordpress-user-ip-address/)
|
97 |
* Limit who can view the security alerts by users and roles
|
98 |
* Limit who can manage the plugin by users and roles
|
99 |
* Configurable WordPress dashboard widget highlighting the most recent critical activity
|
117 |
= Related Links and Documentation =
|
118 |
For more information and to get started with WordPress Security, check out the following:
|
119 |
|
120 |
+
* [List of WordPress Security Alerts](http://www.wpsecurityauditlog.com/documentation/list-monitoring-wordpress-security-alerts-audit-log/)
|
121 |
+
* [WordPress Multisite Features](http://www.wpsecurityauditlog.com/documentation/wordpress-multisite-plugin-features-support/)
|
122 |
+
* [WP Security Audit Log and Reverse Proxy and WAFs Support](http://www.wpsecurityauditlog.com/documentation/automatically-retrieve-originating-wordpress-user-ip-address/)
|
123 |
+
* [WP Security Audit Log Database Documentation](http://www.wpsecurityauditlog.com/documentation/plugin-wordpress-database-documentation/)
|
124 |
+
* [Official WP Security Audit Log Plugin Website](http://www.wpsecurityauditlog.com/)
|
125 |
|
126 |
= WordPress Security Tips & Tricks =
|
127 |
Even if WordPress security is not your cup of tea, the security of your WordPress is your responsibility. Keep yourself up to date with the latest WordPress Security Tips & Tricks. WP White Security frequently publishes WordPress security tips & tricks on the [WordPress Security section](http://www.wpwhitesecurity.com/wordpress-security/) of their blog.
|
129 |
= Plugin Newsletter =
|
130 |
To keep yourself updated with what is new and updated in our WordPress security plugins please subscribe to the [WP White Security Plugins Newsletter](http://eepurl.com/Jn9sP).
|
131 |
|
132 |
+
**Note: This plugin requires PHP 5.3 or higher to be activated because older versions of PHP are no longer maintained by PHP themselves, which make them prone to security issues. For more information or if you need assistance with your version of PHP please get in touch with us by using our [contact form](http://www.wpsecurityauditlog.com/contact/).**
|
133 |
|
134 |
== Installation ==
|
135 |
|
144 |
By default the plugin will keep 5,000 WordPress Security Alerts. When this limit is reached, older alerts are deleted to make place for the new ones. You can configure the plugin to keep more alerts from the settings page. You can also configure the plugin to delete alerts which are older than a number of days.
|
145 |
|
146 |
= Is there a complete list of all WordPress security audit events? =
|
147 |
+
Yes. A complete list can be found [here](http://www.wpsecurityauditlog.com/documentation/list-monitoring-wordpress-security-alerts-audit-log/)
|
148 |
|
149 |
= Can I disable some WordPress security alerts? =
|
150 |
|
151 |
Yes it is possible to disable (and re-enable) specific WordPress security alerts. To do so navigate to the "Enable/Disable Alerts" node in the plugin's menu, select the category tab and untick the WordPress security alert. Tick back the alert to re-enable it.
|
152 |
|
153 |
= Can WP Security Audit Log plugin work and monitor activity on WodPress Multisite? =
|
154 |
+
Yes, WP Security Audit Log works on WordPress Multisite networks, i.e. it can monitor user and under the hood WordPress activity on WordPress multisite installations. For more information refer to the post [WP Security Audit Log Features for WordPress Multisite installation](http://www.wpsecurityauditlog.com/documentation/wordpress-multisite-plugin-features-support/).
|
155 |
|
156 |
= Can I receive an email notification when a specific change happens on WordPress? =
|
157 |
+
Yes it is possible to do so with the [Email Notifications Add-On](http://www.wpsecurityauditlog.com/extensions/wordpress-email-notifications-add-on/). This plugin extension enables you to configure triggers to monitor for specific changes and when such changes take place an email is automatically sent to your email address of choice with all the details of such change such as the Alert ID, user, user role, date, time, details about the actual change and more.
|
158 |
|
159 |
= How can I search for a specific WordPress security alert?
|
160 |
+
You can use the premium add-on [Search Add-On](http://www.wpsecurityauditlog.com/extensions/search-add-on-for-wordpress-security-audit-log/) to automatically search for a specific WordPress security alert. It supports free text based searches and you can also use the built-in filters to fine tune your searches.
|
161 |
|
162 |
= Can I generate reports from the WordPress security audit log? =
|
163 |
+
Yes it is possible to do so with the premium [Reports Add-On](http://www.wpsecurityauditlog.com/extensions/compliance-reports-add-on-for-wordpress/). This plugin extension allows you to generate any type of WordPress report using any type of data source. Reports can be generated in HTML and CSV format.
|
164 |
|
165 |
= Can I exclude users or roles from being monitored? =
|
166 |
Yes it is possible to exclude both users and roles from being monitored. To exclude a user or a role specify it in the Excluded Objects section in the plugin's settings node.
|
172 |
|
173 |
1. The Audit Log Viewer from where the WordPress administrator can see all the security events generated by WP Security Audit Log WordPress plugin.
|
174 |
2. The WP Security Audit Log plugin options from where WordPress administrator can configure the auto pruning of security alerts and specific user access.
|
175 |
+
3. Configuring WordPress email alerts with the [Email Notifications Add-On](http://www.wpsecurityauditlog.com/extensions/wordpress-email-notifications-add-on/)
|
176 |
+
4. Search and filters functionality to automatically search through the WordPress security audit log with the [Search Extension](http://www.wpsecurityauditlog.com/extensions/search-add-on-for-wordpress-security-audit-log/)
|
177 |
5. The Enable/Disable Alerts settings node from where Administrators can disable or enable WordPress security alerts.
|
178 |
6. The Audit Log Viewer of a Super Admin in a WordPress multisite network installation with the Site selection drop down menu.
|
179 |
7. If there are more than 15 sites in a multisite, an auto complete site search shows up instead of the drop down menu (see [screenshots](https://wordpress.org/plugins/wp-security-audit-log/screenshots/) for reference)
|
180 |
|
181 |
== Changelog ==
|
182 |
|
183 |
+
= 2.0.1 (2015-08-05) =
|
184 |
+
* **Minor Change**
|
185 |
+
* Launched a new [WP Security Audit Log website](http://www.wpsecurityauditlog.com) and updated all relevant links.
|
186 |
+
|
187 |
= 2.0.0 (2015-07-16) =
|
188 |
* **New Features**
|
189 |
* New database connector allowing faster and more efficient plugin to WordPress database communication
|
225 |
* Completely removed the user of the is_admin() function to follow better security practises
|
226 |
|
227 |
* **Bug Fixes**
|
228 |
+
* Updated the licensing mechanism to correct problem where [WP Security Audit Log premium add-ons](http://www.wpsecurityauditlog.com/plugin-extensions/) could not be activated.
|
229 |
* Fixed several issues where the database tables were not being created during install or upgrade. [Support ticket](https://wordpress.org/support/topic/wp_wsal_options-not-created-with-plugin-update?replies=8) and [Support ticket 2](https://wordpress.org/support/topic/missing-database-tables-1?replies=9)
|
230 |
* Fixed an issue where the plugin did not monitor any activity in specific scenarios. [Support ticket](https://wordpress.org/support/topic/clean-install-not-reporting-when-posts-or-pages-are-creatededited?replies=4) and [Support ticket 2](https://wordpress.org/support/topic/blank-audit-log-page?replies=2)
|
231 |
* Removed duplicate options in the settings page. [Support ticket](https://wordpress.org/support/topic/refresh-audit-view-refresh-audit-log-viewer?replies=5)
|
248 |
|
249 |
= 1.4 (2015-02-24) =
|
250 |
* **New Features**
|
251 |
+
* WordPress username is now reported when a failed login is recorded - [More Details](http://www.wpsecurityauditlog.com/wordpress-user-monitoring-plugin-releases/wordpress-failed-logins-monitoring-improved/)
|
252 |
* Plugin is now available in Romanian thanks to [Artmotion](http://www.artmotion.eu)
|
253 |
|
254 |
* **Improvements**
|
261 |
|
262 |
= 1.3.3 (2015-01-21) =
|
263 |
* **New Features**
|
264 |
+
* [Premium Add-Ons](http://www.wpsecurityauditlog.com/plugin-extensions/) will be hidden from the WordPress plugins page when the Hide plugin option is enabled.
|
265 |
|
266 |
* **Improvements**
|
267 |
* Updated some of the help text in plugin's settings page
|
273 |
|
274 |
= 1.3.2 (2014-12-16) =
|
275 |
* **New Features and Options**
|
276 |
+
* Plugin automatically retrieves user's originating IP address even if WordPress is installed behind a reverse proxy, web application firewall or load balancer. For more information refer to [WP Security Audit Log, Reverse Proxies and WAFs](http://www.wpsecurityauditlog.com/documentation/automatically-retrieve-originating-wordpress-user-ip-address/)
|
277 |
* New option to omit internal IP addresses from being reported in the WordPress security audit log
|
278 |
|
279 |
* **Removed Functionality**
|
465 |
* Alert 0003: PHP Notice
|
466 |
* Alert 0004: PHP Exception
|
467 |
* Alert 0005: PHP Shutdown Error
|
|
|
|
|
468 |
|
469 |
= 0.6.3 (2014-02-18) =
|
470 |
* **Bug Fix**
|
481 |
|
482 |
= 0.6 (2014-01-15) =
|
483 |
* **New Plugin Feature**
|
484 |
+
* WordPress Multisite Support [Read More](http://www.wpsecurityauditlog.com/documentation/wordpress-multisite-plugin-features-support/)
|
485 |
|
486 |
* **New WordPress Security Alerts for monitoring specific multisite activity on a WordPress multisite network installation**
|
487 |
* Alert 4008: User is granted super admin privileges (network)
|
wp-security-audit-log.php
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: WP Security Audit Log
|
4 |
-
Plugin URI: http://www.
|
5 |
Description: Identify WordPress security issues before they become a problem. Keep track of everything happening on your WordPress including WordPress users activity. Similar to Windows Event Log and Linux Syslog, WP Security Audit Log generates a security alert for everything that happens on your WordPress blogs and websites. Use the Audit Log Viewer included in the plugin to see all the security alerts.
|
6 |
Author: WP White Security
|
7 |
-
Version: 2.0.
|
8 |
Text Domain: wp-security-audit-log
|
9 |
-
Author URI: http://www.
|
10 |
License: GPL2
|
11 |
|
12 |
WP Security Audit Log
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: WP Security Audit Log
|
4 |
+
Plugin URI: http://www.wpsecurityauditlog.com/
|
5 |
Description: Identify WordPress security issues before they become a problem. Keep track of everything happening on your WordPress including WordPress users activity. Similar to Windows Event Log and Linux Syslog, WP Security Audit Log generates a security alert for everything that happens on your WordPress blogs and websites. Use the Audit Log Viewer included in the plugin to see all the security alerts.
|
6 |
Author: WP White Security
|
7 |
+
Version: 2.0.1
|
8 |
Text Domain: wp-security-audit-log
|
9 |
+
Author URI: http://www.wpsecurityauditlog.com/
|
10 |
License: GPL2
|
11 |
|
12 |
WP Security Audit Log
|