PluginProbe
DoLogin Security / trunk
DoLogin Security vtrunk
5.0.10 4.8.3 trunk 1.0 1.1 1.1.1 1.2 1.2.1 1.2.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 1.6 All 64 releases
dologin / src / conf.cls.php

conf.cls.php in DoLogin Security trunk, at src/conf.cls.php

154 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Config class
4 *
5 * @since 1.0
6 */
7 namespace dologin;
8
9 defined( 'WPINC' ) || exit;
10
11 class Conf extends Instance {
12 private $_options = array();
13
14 public static $_default_options = array(
15 '_ver' => '',
16 '_pk' => '',
17 '_sk' => '',
18 'max_retries' => 6,
19 'duration' => 10,
20 'gdpr' => false,
21 '2fa' => false,
22 '2fa_force' => false,
23 'kl_sso' => false,
24 'kl_sso_force' => false,
25 'kl_sso_svc_id' => '',
26 'cf' => false,
27 'cf_pub_key' => '',
28 'cf_priv_key' => '',
29 'recapt_register' => false,
30 'recapt_forget' => false,
31 'whitelist' => array(),
32 'blacklist' => array(),
33 );
34
35 /**
36 * Init config
37 *
38 * @since 1.0
39 * @access public
40 */
41 public function init() {
42 // Load all options
43 $options = array();
44 foreach ( self::$_default_options as $k => $v ) {
45 $options[ $k ] = $this->_get_option( $k, $v );
46 }
47
48 $this->_options = $options;
49
50 // Update options if not exists
51 ! defined( 'DOLOGIN_CUR_V' ) && define( 'DOLOGIN_CUR_V', $this->_options['_ver'] );
52
53 if ( ! DOLOGIN_CUR_V || DOLOGIN_CUR_V != Core::VER ) {
54 if ( ! DOLOGIN_CUR_V ) {
55 Util::version_check( 'new' );
56 } else {
57 // DB update
58 $this->cls( 'Data' )->conf_upgrade();
59 }
60
61 foreach ( self::$_default_options as $k => $v ) {
62 self::add( $k, $v );
63 }
64
65 self::update( '_ver', Core::VER );
66 }
67 }
68
69 /**
70 * Get one current option
71 *
72 * @since 1.0
73 * @access public
74 */
75 public static function val( $id ) {
76 $instance = self::cls();
77 if ( isset( $instance->_options[ $id ] ) ) {
78 return $instance->_options[ $id ];
79 }
80
81 return null;
82 }
83
84 /**
85 * Get all options
86 *
87 * @since 1.1
88 * @access private
89 */
90 public function get_options() {
91 return $this->_options;
92 }
93
94 /**
95 * Add one option
96 *
97 * @since 1.4.1
98 * @access public
99 */
100 public static function add( $id, $v ) {
101 add_option( 'dologin.' . $id, $v );
102 }
103
104 /**
105 * Delete one option
106 *
107 * @since 1.4.1
108 * @access public
109 */
110 public static function delete( $id ) {
111 delete_option( 'dologin.' . $id );
112 }
113
114 /**
115 * Get option from DB
116 *
117 * @since 1.0
118 * @access private
119 */
120 private function _get_option( $id, $default_v = false ) {
121 return get_option( 'dologin.' . $id, $default_v );
122 }
123
124 /**
125 * Update option of dologin
126 *
127 * @since 1.0
128 * @access public
129 */
130 public static function update( $id, $data ) {
131 if ( ! array_key_exists( $id, self::$_default_options ) ) {
132 return;
133 }
134
135 // typecast
136 $default_v = self::$_default_options[ $id ];
137 if ( is_bool( $default_v ) ) {
138 $data = (bool) $data;
139 } elseif ( is_array( $default_v ) ) {
140 if ( ! is_array( $data ) ) {
141 $data = explode( "\n", $data );
142 $data = array_filter( $data );
143 }
144 } elseif ( ! is_string( $default_v ) ) {
145 $data = (int) $data;
146 }
147
148 update_option( 'dologin.' . $id, $data );
149
150 // Change current setting
151 self::cls()->_options[ $id ] = $data;
152 }
153 }
154