Completed
Branch BUG/3575-event-deletion-previe... (bbeda1)
by
unknown
06:40 queued 04:49
created
core/services/encryption/Base64Encoder.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -15,148 +15,148 @@
 block discarded – undo
15 15
 class Base64Encoder
16 16
 {
17 17
 
18
-    /**
19
-     * @var boolean
20
-     */
21
-    protected $use_base64_encode;
22
-
23
-
24
-    public function __construct()
25
-    {
26
-        $this->use_base64_encode = function_exists('base64_encode');
27
-    }
28
-
29
-
30
-    /**
31
-     * encodes string with PHP's base64 encoding
32
-     *
33
-     * @see http://php.net/manual/en/function.base64-encode.php
34
-     * @param string $text_string the text to be encoded
35
-     * @return string
36
-     */
37
-    public function encodeString($text_string = '')
38
-    {
39
-        // you give me nothing??? GET OUT !
40
-        if (empty($text_string) || ! $this->use_base64_encode) {
41
-            return $text_string;
42
-        }
43
-        // encode
44
-        return base64_encode($text_string);
45
-    }
46
-
47
-
48
-    /**
49
-     * decodes string that has been encoded with PHP's base64 encoding
50
-     *
51
-     * @see http://php.net/manual/en/function.base64-encode.php
52
-     * @param string $encoded_string the text to be decoded
53
-     * @return string
54
-     * @throws RuntimeException
55
-     */
56
-    public function decodeString($encoded_string = '')
57
-    {
58
-        // you give me nothing??? GET OUT !
59
-        if (empty($encoded_string)) {
60
-            return $encoded_string;
61
-        }
62
-        $this->isValidBase64OrFail($encoded_string);
63
-        return $this->decode($encoded_string);
64
-    }
65
-
66
-
67
-    /**
68
-     * @param string $encoded_string the text to be decoded
69
-     * @return string
70
-     * @throws RuntimeException
71
-     */
72
-    private function decode($encoded_string)
73
-    {
74
-        $decoded_string = base64_decode($encoded_string);
75
-        if ($decoded_string === false) {
76
-            throw new RuntimeException(
77
-                esc_html__('Base 64 decoding failed.', 'event_espresso')
78
-            );
79
-        }
80
-        return $decoded_string;
81
-    }
82
-
83
-
84
-    /**
85
-     * encodes  url string with PHP's base64 encoding
86
-     *
87
-     * @see http://php.net/manual/en/function.base64-encode.php
88
-     * @param string $text_string the text to be encoded
89
-     * @return string
90
-     */
91
-    public function encodeUrl($text_string = '')
92
-    {
93
-        // you give me nothing??? GET OUT !
94
-        if (empty($text_string) || ! $this->use_base64_encode) {
95
-            return $text_string;
96
-        }
97
-        // encode
98
-        $encoded_string = base64_encode($text_string);
99
-        // remove some chars to make encoding more URL friendly
100
-        return rtrim(strtr($encoded_string, '+/', '-_'), '=');
101
-    }
102
-
103
-
104
-    /**
105
-     * decodes  url string that has been encoded with PHP's base64 encoding
106
-     *
107
-     * @see http://php.net/manual/en/function.base64-encode.php
108
-     * @param string $encoded_string the text to be decoded
109
-     * @return string
110
-     * @throws RuntimeException
111
-     */
112
-    public function decodeUrl($encoded_string = '')
113
-    {
114
-        // you give me nothing??? GET OUT !
115
-        if (empty($encoded_string)) {
116
-            return $encoded_string;
117
-        }
118
-        // replace previously removed characters
119
-        $encoded_string = strtr($encoded_string, '-_', '+/');
120
-        $encoded_string .= str_repeat('=', 3 - (3 + strlen($encoded_string)) % 4);
121
-        $this->isValidBase64OrFail($encoded_string);
122
-        return $this->decode($encoded_string);
123
-    }
124
-
125
-
126
-    /**
127
-     * @param string $encoded_string the text to be decoded
128
-     * @throws RuntimeException
129
-     */
130
-    public function isValidBase64OrFail($encoded_string)
131
-    {
132
-        if (! $this->isValidBase64($encoded_string)) {
133
-            throw new RuntimeException(
134
-                esc_html__(
135
-                    'Base 64 decoding failed because the supplied string is not valid or was not base64 encoded.',
136
-                    'event_espresso'
137
-                )
138
-            );
139
-        }
140
-    }
141
-
142
-
143
-    /**
144
-     * @see https://stackoverflow.com/a/51877882
145
-     * @param $string
146
-     * @return bool
147
-     */
148
-    public function isValidBase64($string)
149
-    {
150
-        // ensure data is a string
151
-        if (! is_string($string) || ! $this->use_base64_encode) {
152
-            return false;
153
-        }
154
-        // first check if we're dealing with an actual valid base64 encoded string
155
-        $decoded = base64_decode($string, true);
156
-        if ($decoded === false) {
157
-            return false;
158
-        }
159
-        // finally, re-encode and compare it to original one
160
-        return base64_encode($decoded) === $string;
161
-    }
18
+	/**
19
+	 * @var boolean
20
+	 */
21
+	protected $use_base64_encode;
22
+
23
+
24
+	public function __construct()
25
+	{
26
+		$this->use_base64_encode = function_exists('base64_encode');
27
+	}
28
+
29
+
30
+	/**
31
+	 * encodes string with PHP's base64 encoding
32
+	 *
33
+	 * @see http://php.net/manual/en/function.base64-encode.php
34
+	 * @param string $text_string the text to be encoded
35
+	 * @return string
36
+	 */
37
+	public function encodeString($text_string = '')
38
+	{
39
+		// you give me nothing??? GET OUT !
40
+		if (empty($text_string) || ! $this->use_base64_encode) {
41
+			return $text_string;
42
+		}
43
+		// encode
44
+		return base64_encode($text_string);
45
+	}
46
+
47
+
48
+	/**
49
+	 * decodes string that has been encoded with PHP's base64 encoding
50
+	 *
51
+	 * @see http://php.net/manual/en/function.base64-encode.php
52
+	 * @param string $encoded_string the text to be decoded
53
+	 * @return string
54
+	 * @throws RuntimeException
55
+	 */
56
+	public function decodeString($encoded_string = '')
57
+	{
58
+		// you give me nothing??? GET OUT !
59
+		if (empty($encoded_string)) {
60
+			return $encoded_string;
61
+		}
62
+		$this->isValidBase64OrFail($encoded_string);
63
+		return $this->decode($encoded_string);
64
+	}
65
+
66
+
67
+	/**
68
+	 * @param string $encoded_string the text to be decoded
69
+	 * @return string
70
+	 * @throws RuntimeException
71
+	 */
72
+	private function decode($encoded_string)
73
+	{
74
+		$decoded_string = base64_decode($encoded_string);
75
+		if ($decoded_string === false) {
76
+			throw new RuntimeException(
77
+				esc_html__('Base 64 decoding failed.', 'event_espresso')
78
+			);
79
+		}
80
+		return $decoded_string;
81
+	}
82
+
83
+
84
+	/**
85
+	 * encodes  url string with PHP's base64 encoding
86
+	 *
87
+	 * @see http://php.net/manual/en/function.base64-encode.php
88
+	 * @param string $text_string the text to be encoded
89
+	 * @return string
90
+	 */
91
+	public function encodeUrl($text_string = '')
92
+	{
93
+		// you give me nothing??? GET OUT !
94
+		if (empty($text_string) || ! $this->use_base64_encode) {
95
+			return $text_string;
96
+		}
97
+		// encode
98
+		$encoded_string = base64_encode($text_string);
99
+		// remove some chars to make encoding more URL friendly
100
+		return rtrim(strtr($encoded_string, '+/', '-_'), '=');
101
+	}
102
+
103
+
104
+	/**
105
+	 * decodes  url string that has been encoded with PHP's base64 encoding
106
+	 *
107
+	 * @see http://php.net/manual/en/function.base64-encode.php
108
+	 * @param string $encoded_string the text to be decoded
109
+	 * @return string
110
+	 * @throws RuntimeException
111
+	 */
112
+	public function decodeUrl($encoded_string = '')
113
+	{
114
+		// you give me nothing??? GET OUT !
115
+		if (empty($encoded_string)) {
116
+			return $encoded_string;
117
+		}
118
+		// replace previously removed characters
119
+		$encoded_string = strtr($encoded_string, '-_', '+/');
120
+		$encoded_string .= str_repeat('=', 3 - (3 + strlen($encoded_string)) % 4);
121
+		$this->isValidBase64OrFail($encoded_string);
122
+		return $this->decode($encoded_string);
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param string $encoded_string the text to be decoded
128
+	 * @throws RuntimeException
129
+	 */
130
+	public function isValidBase64OrFail($encoded_string)
131
+	{
132
+		if (! $this->isValidBase64($encoded_string)) {
133
+			throw new RuntimeException(
134
+				esc_html__(
135
+					'Base 64 decoding failed because the supplied string is not valid or was not base64 encoded.',
136
+					'event_espresso'
137
+				)
138
+			);
139
+		}
140
+	}
141
+
142
+
143
+	/**
144
+	 * @see https://stackoverflow.com/a/51877882
145
+	 * @param $string
146
+	 * @return bool
147
+	 */
148
+	public function isValidBase64($string)
149
+	{
150
+		// ensure data is a string
151
+		if (! is_string($string) || ! $this->use_base64_encode) {
152
+			return false;
153
+		}
154
+		// first check if we're dealing with an actual valid base64 encoded string
155
+		$decoded = base64_decode($string, true);
156
+		if ($decoded === false) {
157
+			return false;
158
+		}
159
+		// finally, re-encode and compare it to original one
160
+		return base64_encode($decoded) === $string;
161
+	}
162 162
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public function isValidBase64OrFail($encoded_string)
131 131
     {
132
-        if (! $this->isValidBase64($encoded_string)) {
132
+        if ( ! $this->isValidBase64($encoded_string)) {
133 133
             throw new RuntimeException(
134 134
                 esc_html__(
135 135
                     'Base 64 decoding failed because the supplied string is not valid or was not base64 encoded.',
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
     public function isValidBase64($string)
149 149
     {
150 150
         // ensure data is a string
151
-        if (! is_string($string) || ! $this->use_base64_encode) {
151
+        if ( ! is_string($string) || ! $this->use_base64_encode) {
152 152
             return false;
153 153
         }
154 154
         // first check if we're dealing with an actual valid base64 encoded string
Please login to merge, or discard this patch.
core/EE_Encryption.core.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     protected function __construct()
105 105
     {
106
-        if (! defined('ESPRESSO_ENCRYPT')) {
106
+        if ( ! defined('ESPRESSO_ENCRYPT')) {
107 107
             define('ESPRESSO_ENCRYPT', true);
108 108
         }
109 109
         if (extension_loaded('openssl')) {
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
     public static function instance()
126 126
     {
127 127
         // check if class object is instantiated
128
-        if (! EE_Encryption::$_instance instanceof EE_Encryption) {
128
+        if ( ! EE_Encryption::$_instance instanceof EE_Encryption) {
129 129
             EE_Encryption::$_instance = new self();
130 130
         }
131 131
         return EE_Encryption::$_instance;
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
             $iv
333 333
         );
334 334
         // append the initialization vector
335
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
335
+        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER.$iv;
336 336
         // trim and maybe encode
337 337
         return $this->_use_base64_encode
338 338
             ? trim(base64_encode($encrypted_text))
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
         if (empty($text_string)) {
516 516
             return $text_string;
517 517
         }
518
-        $key_bits    = str_split(
518
+        $key_bits = str_split(
519 519
             str_pad(
520 520
                 '',
521 521
                 strlen($text_string),
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
         );
526 526
         $string_bits = str_split($text_string);
527 527
         foreach ($string_bits as $k => $v) {
528
-            $temp              = ord($v) + ord($key_bits[ $k ]);
529
-            $string_bits[ $k ] = chr($temp > 255 ? ($temp - 256) : $temp);
528
+            $temp              = ord($v) + ord($key_bits[$k]);
529
+            $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp);
530 530
         }
531 531
         $encrypted_text = implode('', $string_bits);
532 532
         $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG;
@@ -568,10 +568,10 @@  discard block
 block discarded – undo
568 568
                 STR_PAD_RIGHT
569 569
             )
570 570
         );
571
-        $string_bits    = str_split($encrypted_text);
571
+        $string_bits = str_split($encrypted_text);
572 572
         foreach ($string_bits as $k => $v) {
573
-            $temp              = ord($v) - ord($key_bits[ $k ]);
574
-            $string_bits[ $k ] = chr($temp < 0 ? ($temp + 256) : $temp);
573
+            $temp              = ord($v) - ord($key_bits[$k]);
574
+            $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp);
575 575
         }
576 576
         return implode('', $string_bits);
577 577
     }
@@ -585,16 +585,16 @@  discard block
 block discarded – undo
585 585
     protected function valid_base_64($string)
586 586
     {
587 587
         // ensure data is a string
588
-        if (! is_string($string) || ! $this->_use_base64_encode) {
588
+        if ( ! is_string($string) || ! $this->_use_base64_encode) {
589 589
             return false;
590 590
         }
591 591
         $decoded = base64_decode($string, true);
592 592
         // Check if there is no invalid character in string
593
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
593
+        if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
594 594
             return false;
595 595
         }
596 596
         // Decode the string in strict mode and send the response
597
-        if (! base64_decode($string, true)) {
597
+        if ( ! base64_decode($string, true)) {
598 598
             return false;
599 599
         }
600 600
         // Encode and compare it to original one
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
         $iterations    = ceil($length / 40);
615 615
         $random_string = '';
616 616
         for ($i = 0; $i < $iterations; $i++) {
617
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
617
+            $random_string .= sha1(microtime(true).mt_rand(10000, 90000));
618 618
         }
619 619
         $random_string = substr($random_string, 0, $length);
620 620
         return $random_string;
Please login to merge, or discard this patch.
Indentation   +672 added lines, -672 removed lines patch added patch discarded remove patch
@@ -40,676 +40,676 @@
 block discarded – undo
40 40
 class EE_Encryption implements InterminableInterface
41 41
 {
42 42
 
43
-    /**
44
-     * key used for saving the encryption key to the wp_options table
45
-     */
46
-    const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
47
-
48
-    /**
49
-     * the OPENSSL cipher method used
50
-     */
51
-    const OPENSSL_CIPHER_METHOD = 'AES-128-CBC';
52
-
53
-    /**
54
-     * WP "options_name" used to store a verified available cipher method
55
-     */
56
-    const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method';
57
-
58
-    /**
59
-     * the OPENSSL digest method used
60
-     */
61
-    const OPENSSL_DIGEST_METHOD = 'sha512';
62
-
63
-    /**
64
-     * separates the encrypted text from the initialization vector
65
-     */
66
-    const OPENSSL_IV_DELIMITER = ':iv:';
67
-
68
-    /**
69
-     * appended to text encrypted using the acme encryption
70
-     */
71
-    const ACME_ENCRYPTION_FLAG = '::ae';
72
-
73
-
74
-    /**
75
-     * instance of the EE_Encryption object
76
-     */
77
-    protected static $_instance;
78
-
79
-    /**
80
-     * @var string $_encryption_key
81
-     */
82
-    protected $_encryption_key;
83
-
84
-    /**
85
-     * @var string $cipher_method
86
-     */
87
-    private $cipher_method = '';
88
-
89
-    /**
90
-     * @var array $cipher_methods
91
-     */
92
-    private $cipher_methods = [];
93
-
94
-    /**
95
-     * @var array $digest_methods
96
-     */
97
-    private $digest_methods = [];
98
-
99
-    /**
100
-     * @var boolean $_use_openssl_encrypt
101
-     */
102
-    protected $_use_openssl_encrypt = false;
103
-
104
-    /**
105
-     * @var boolean $_use_mcrypt
106
-     */
107
-    protected $_use_mcrypt = false;
108
-
109
-    /**
110
-     * @var boolean $_use_base64_encode
111
-     */
112
-    protected $_use_base64_encode = false;
113
-
114
-
115
-    /**
116
-     * protected constructor to prevent direct creation
117
-     */
118
-    protected function __construct()
119
-    {
120
-        if (! defined('ESPRESSO_ENCRYPT')) {
121
-            define('ESPRESSO_ENCRYPT', true);
122
-        }
123
-        if (extension_loaded('openssl')) {
124
-            $this->_use_openssl_encrypt = true;
125
-        } elseif (extension_loaded('mcrypt')) {
126
-            $this->_use_mcrypt = true;
127
-        }
128
-        if (function_exists('base64_encode')) {
129
-            $this->_use_base64_encode = true;
130
-        }
131
-    }
132
-
133
-
134
-    /**
135
-     * singleton method used to instantiate class object
136
-     *
137
-     * @return EE_Encryption
138
-     */
139
-    public static function instance()
140
-    {
141
-        // check if class object is instantiated
142
-        if (! EE_Encryption::$_instance instanceof EE_Encryption) {
143
-            EE_Encryption::$_instance = new self();
144
-        }
145
-        return EE_Encryption::$_instance;
146
-    }
147
-
148
-
149
-    /**
150
-     * get encryption key
151
-     *
152
-     * @return string
153
-     */
154
-    public function get_encryption_key()
155
-    {
156
-        // if encryption key has not been set
157
-        if (empty($this->_encryption_key)) {
158
-            // retrieve encryption_key from db
159
-            $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
160
-            // WHAT?? No encryption_key in the db ??
161
-            if ($this->_encryption_key === '') {
162
-                // let's make one. And md5 it to make it just the right size for a key
163
-                $new_key = md5($this->generate_random_string());
164
-                // now save it to the db for later
165
-                add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
166
-                // here's the key - FINALLY !
167
-                $this->_encryption_key = $new_key;
168
-            }
169
-        }
170
-        return $this->_encryption_key;
171
-    }
172
-
173
-
174
-    /**
175
-     * encrypts data
176
-     *
177
-     * @param string $text_string - the text to be encrypted
178
-     * @return string
179
-     * @throws RuntimeException
180
-     */
181
-    public function encrypt($text_string = '')
182
-    {
183
-        // you give me nothing??? GET OUT !
184
-        if (empty($text_string)) {
185
-            return $text_string;
186
-        }
187
-        if ($this->_use_openssl_encrypt) {
188
-            $encrypted_text = $this->openssl_encrypt($text_string);
189
-        } else {
190
-            $encrypted_text = $this->acme_encrypt($text_string);
191
-        }
192
-        return $encrypted_text;
193
-    }
194
-
195
-
196
-    /**
197
-     * decrypts data
198
-     *
199
-     * @param string $encrypted_text - the text to be decrypted
200
-     * @return string
201
-     * @throws RuntimeException
202
-     */
203
-    public function decrypt($encrypted_text = '')
204
-    {
205
-        // you give me nothing??? GET OUT !
206
-        if (empty($encrypted_text)) {
207
-            return $encrypted_text;
208
-        }
209
-        // if PHP's mcrypt functions are installed then we'll use them
210
-        if ($this->_use_openssl_encrypt) {
211
-            $decrypted_text = $this->openssl_decrypt($encrypted_text);
212
-        } else {
213
-            $decrypted_text = $this->acme_decrypt($encrypted_text);
214
-        }
215
-        return $decrypted_text;
216
-    }
217
-
218
-
219
-    /**
220
-     * encodes string with PHP's base64 encoding
221
-     *
222
-     * @see http://php.net/manual/en/function.base64-encode.php
223
-     * @param string $text_string the text to be encoded
224
-     * @return string
225
-     */
226
-    public function base64_string_encode($text_string = '')
227
-    {
228
-        // you give me nothing??? GET OUT !
229
-        if (empty($text_string) || ! $this->_use_base64_encode) {
230
-            return $text_string;
231
-        }
232
-        // encode
233
-        return base64_encode($text_string);
234
-    }
235
-
236
-
237
-    /**
238
-     * decodes string that has been encoded with PHP's base64 encoding
239
-     *
240
-     * @see http://php.net/manual/en/function.base64-encode.php
241
-     * @param string $encoded_string the text to be decoded
242
-     * @return string
243
-     * @throws RuntimeException
244
-     */
245
-    public function base64_string_decode($encoded_string = '')
246
-    {
247
-        // you give me nothing??? GET OUT !
248
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
249
-            return $encoded_string;
250
-        }
251
-        // decode
252
-        $decoded_string = base64_decode($encoded_string);
253
-        if ($decoded_string === false) {
254
-            throw new RuntimeException(
255
-                esc_html__('Base 64 decoding failed.', 'event_espresso')
256
-            );
257
-        }
258
-        return $decoded_string;
259
-    }
260
-
261
-
262
-    /**
263
-     * encodes  url string with PHP's base64 encoding
264
-     *
265
-     * @see http://php.net/manual/en/function.base64-encode.php
266
-     * @param string $text_string the text to be encoded
267
-     * @return string
268
-     */
269
-    public function base64_url_encode($text_string = '')
270
-    {
271
-        // you give me nothing??? GET OUT !
272
-        if (empty($text_string) || ! $this->_use_base64_encode) {
273
-            return $text_string;
274
-        }
275
-        // encode
276
-        $encoded_string = base64_encode($text_string);
277
-        // remove chars to make encoding more URL friendly
278
-        return strtr($encoded_string, '+/=', '-_,');
279
-    }
280
-
281
-
282
-    /**
283
-     * decodes  url string that has been encoded with PHP's base64 encoding
284
-     *
285
-     * @see http://php.net/manual/en/function.base64-encode.php
286
-     * @param string $encoded_string the text to be decoded
287
-     * @return string
288
-     * @throws RuntimeException
289
-     */
290
-    public function base64_url_decode($encoded_string = '')
291
-    {
292
-        // replace previously removed characters
293
-        $encoded_string = strtr($encoded_string, '-_,', '+/=');
294
-        // you give me nothing??? GET OUT !
295
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
296
-            return $encoded_string;
297
-        }
298
-        // decode
299
-        $decoded_string = base64_decode($encoded_string);
300
-        if ($decoded_string === false) {
301
-            throw new RuntimeException(
302
-                esc_html__('Base 64 decoding failed.', 'event_espresso')
303
-            );
304
-        }
305
-        return $decoded_string;
306
-    }
307
-
308
-
309
-    /**
310
-     * encrypts data using PHP's openssl functions
311
-     *
312
-     * @param string $text_string the text to be encrypted
313
-     * @param string $cipher_method
314
-     * @param string $encryption_key
315
-     * @return string
316
-     * @throws RuntimeException
317
-     */
318
-    protected function openssl_encrypt(
319
-        $text_string = '',
320
-        $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD,
321
-        $encryption_key = ''
322
-    ) {
323
-        // you give me nothing??? GET OUT !
324
-        if (empty($text_string)) {
325
-            return $text_string;
326
-        }
327
-        $this->cipher_method = $this->getCipherMethod($cipher_method);
328
-        // get initialization vector size
329
-        $iv_size = openssl_cipher_iv_length($this->cipher_method);
330
-        // generate initialization vector.
331
-        // The second parameter ("crypto_strong") is passed by reference,
332
-        // and is used to determines if the algorithm used was "cryptographically strong"
333
-        // openssl_random_pseudo_bytes() will toggle it to either true or false
334
-        $iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
335
-        if ($iv === false || $is_strong === false) {
336
-            throw new RuntimeException(
337
-                esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
338
-            );
339
-        }
340
-        // encrypt it
341
-        $encrypted_text = openssl_encrypt(
342
-            $text_string,
343
-            $this->cipher_method,
344
-            $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key),
345
-            0,
346
-            $iv
347
-        );
348
-        // append the initialization vector
349
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
350
-        // trim and maybe encode
351
-        return $this->_use_base64_encode
352
-            ? trim(base64_encode($encrypted_text))
353
-            : trim($encrypted_text);
354
-    }
355
-
356
-
357
-    /**
358
-     * Returns a cipher method that has been verified to work.
359
-     * First checks if the cached cipher has been set already and if so, returns that.
360
-     * Then tests the incoming default and returns that if it's good.
361
-     * If not, then it retrieves the previously tested and saved cipher method.
362
-     * But if that doesn't exist, then calls getAvailableCipherMethod()
363
-     * to see what is available on the server, and returns the results.
364
-     *
365
-     * @param string $cipher_method
366
-     * @return string
367
-     * @throws RuntimeException
368
-     */
369
-    protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD)
370
-    {
371
-        if ($this->cipher_method !== '') {
372
-            return $this->cipher_method;
373
-        }
374
-        // verify that the default cipher method can produce an initialization vector
375
-        if (openssl_cipher_iv_length($cipher_method) === false) {
376
-            // nope? okay let's get what we found in the past to work
377
-            $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, '');
378
-            // oops... haven't tested available cipher methods yet
379
-            if ($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) {
380
-                $cipher_method = $this->getAvailableCipherMethod($cipher_method);
381
-            }
382
-        }
383
-        return $cipher_method;
384
-    }
385
-
386
-
387
-    /**
388
-     * @param string $cipher_method
389
-     * @return string
390
-     * @throws \RuntimeException
391
-     */
392
-    protected function getAvailableCipherMethod($cipher_method)
393
-    {
394
-        // verify that the incoming cipher method can produce an initialization vector
395
-        if (openssl_cipher_iv_length($cipher_method) === false) {
396
-            // nope? then check the next cipher in the list of available cipher methods
397
-            $cipher_method = next($this->cipher_methods);
398
-            // what? there's no list? then generate that list and cache it,
399
-            if (empty($this->cipher_methods)) {
400
-                $this->cipher_methods = openssl_get_cipher_methods();
401
-                // then grab the first item from the list
402
-                $cipher_method = reset($this->cipher_methods);
403
-            }
404
-            if ($cipher_method === false) {
405
-                throw new RuntimeException(
406
-                    esc_html__(
407
-                        'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.',
408
-                        'event_espresso'
409
-                    )
410
-                );
411
-            }
412
-            // verify that the next cipher method works
413
-            return $this->getAvailableCipherMethod($cipher_method);
414
-        }
415
-        // if we've gotten this far, then we found an available cipher method that works
416
-        // so save that for next time
417
-        update_option(
418
-            EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME,
419
-            $cipher_method
420
-        );
421
-        return $cipher_method;
422
-    }
423
-
424
-
425
-    /**
426
-     * decrypts data that has been encrypted with PHP's openssl functions
427
-     *
428
-     * @param string $encrypted_text the text to be decrypted
429
-     * @param string $cipher_method
430
-     * @param string $encryption_key
431
-     * @return string
432
-     * @throws RuntimeException
433
-     */
434
-    protected function openssl_decrypt(
435
-        $encrypted_text = '',
436
-        $cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD,
437
-        $encryption_key = ''
438
-    ) {
439
-        // you give me nothing??? GET OUT !
440
-        if (empty($encrypted_text)) {
441
-            return $encrypted_text;
442
-        }
443
-        // decode
444
-        $encrypted_text       = $this->valid_base_64($encrypted_text)
445
-            ? $this->base64_url_decode($encrypted_text)
446
-            : $encrypted_text;
447
-        $encrypted_components = explode(
448
-            EE_Encryption::OPENSSL_IV_DELIMITER,
449
-            $encrypted_text,
450
-            2
451
-        );
452
-        // check that iv exists, and if not, maybe text was encoded using mcrypt?
453
-        if ($this->_use_mcrypt && ! isset($encrypted_components[1])) {
454
-            return $this->m_decrypt($encrypted_text);
455
-        }
456
-        // decrypt it
457
-        $decrypted_text = openssl_decrypt(
458
-            $encrypted_components[0],
459
-            $this->getCipherMethod($cipher_method),
460
-            $this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key),
461
-            0,
462
-            $encrypted_components[1]
463
-        );
464
-        $decrypted_text = trim($decrypted_text);
465
-        return $decrypted_text;
466
-    }
467
-
468
-
469
-    /**
470
-     * Computes the digest hash value using the specified digest method.
471
-     * If that digest method fails to produce a valid hash value,
472
-     * then we'll grab the next digest method and recursively try again until something works.
473
-     *
474
-     * @param string $digest_method
475
-     * @param string $encryption_key
476
-     * @return string
477
-     * @throws RuntimeException
478
-     */
479
-    protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key = '')
480
-    {
481
-        $encryption_key    = $encryption_key !== ''
482
-            ? $encryption_key
483
-            : $this->get_encryption_key();
484
-        $digest_hash_value = openssl_digest($encryption_key, $digest_method);
485
-        if ($digest_hash_value === false) {
486
-            return $this->getDigestHashValue($this->getDigestMethod());
487
-        }
488
-        return $digest_hash_value;
489
-    }
490
-
491
-
492
-    /**
493
-     * Returns the NEXT element in the $digest_methods array.
494
-     * If the $digest_methods array is empty, then we populate it
495
-     * with the available values returned from openssl_get_md_methods().
496
-     *
497
-     * @return string
498
-     * @throws \RuntimeException
499
-     */
500
-    protected function getDigestMethod()
501
-    {
502
-        $digest_method = prev($this->digest_methods);
503
-        if (empty($this->digest_methods)) {
504
-            $this->digest_methods = openssl_get_md_methods();
505
-            $digest_method        = end($this->digest_methods);
506
-        }
507
-        if ($digest_method === false) {
508
-            throw new RuntimeException(
509
-                esc_html__(
510
-                    'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.',
511
-                    'event_espresso'
512
-                )
513
-            );
514
-        }
515
-        return $digest_method;
516
-    }
517
-
518
-
519
-    /**
520
-     * encrypts data for acme servers that didn't bother to install PHP mcrypt
521
-     *
522
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
523
-     * @param string $text_string the text to be decrypted
524
-     * @return string
525
-     */
526
-    protected function acme_encrypt($text_string = '')
527
-    {
528
-        // you give me nothing??? GET OUT !
529
-        if (empty($text_string)) {
530
-            return $text_string;
531
-        }
532
-        $key_bits    = str_split(
533
-            str_pad(
534
-                '',
535
-                strlen($text_string),
536
-                $this->get_encryption_key(),
537
-                STR_PAD_RIGHT
538
-            )
539
-        );
540
-        $string_bits = str_split($text_string);
541
-        foreach ($string_bits as $k => $v) {
542
-            $temp              = ord($v) + ord($key_bits[ $k ]);
543
-            $string_bits[ $k ] = chr($temp > 255 ? ($temp - 256) : $temp);
544
-        }
545
-        $encrypted_text = implode('', $string_bits);
546
-        $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG;
547
-        return $this->_use_base64_encode
548
-            ? base64_encode($encrypted_text)
549
-            : $encrypted_text;
550
-    }
551
-
552
-
553
-    /**
554
-     * decrypts data for acme servers that didn't bother to install PHP mcrypt
555
-     *
556
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
557
-     * @param string $encrypted_text the text to be decrypted
558
-     * @return string
559
-     * @throws RuntimeException
560
-     */
561
-    protected function acme_decrypt($encrypted_text = '')
562
-    {
563
-        // you give me nothing??? GET OUT !
564
-        if (empty($encrypted_text)) {
565
-            return $encrypted_text;
566
-        }
567
-        // decode the data ?
568
-        $encrypted_text = $this->valid_base_64($encrypted_text)
569
-            ? $this->base64_url_decode($encrypted_text)
570
-            : $encrypted_text;
571
-        if (
572
-            $this->_use_mcrypt
573
-            && strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false
574
-        ) {
575
-            return $this->m_decrypt($encrypted_text);
576
-        }
577
-        $encrypted_text = substr($encrypted_text, 0, -4);
578
-        $key_bits       = str_split(
579
-            str_pad(
580
-                '',
581
-                strlen($encrypted_text),
582
-                $this->get_encryption_key(),
583
-                STR_PAD_RIGHT
584
-            )
585
-        );
586
-        $string_bits    = str_split($encrypted_text);
587
-        foreach ($string_bits as $k => $v) {
588
-            $temp              = ord($v) - ord($key_bits[ $k ]);
589
-            $string_bits[ $k ] = chr($temp < 0 ? ($temp + 256) : $temp);
590
-        }
591
-        return implode('', $string_bits);
592
-    }
593
-
594
-
595
-    /**
596
-     * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
597
-     * @param $string
598
-     * @return bool
599
-     */
600
-    protected function valid_base_64($string)
601
-    {
602
-        // ensure data is a string
603
-        if (! is_string($string) || ! $this->_use_base64_encode) {
604
-            return false;
605
-        }
606
-        $decoded = base64_decode($string, true);
607
-        // Check if there is no invalid character in string
608
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
609
-            return false;
610
-        }
611
-        // Decode the string in strict mode and send the response
612
-        if (! base64_decode($string, true)) {
613
-            return false;
614
-        }
615
-        // Encode and compare it to original one
616
-        return base64_encode($decoded) === $string;
617
-    }
618
-
619
-
620
-    /**
621
-     * generate random string
622
-     *
623
-     * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
624
-     * @param int $length number of characters for random string
625
-     * @return string
626
-     */
627
-    public function generate_random_string($length = 40)
628
-    {
629
-        $iterations    = ceil($length / 40);
630
-        $random_string = '';
631
-        for ($i = 0; $i < $iterations; $i++) {
632
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
633
-        }
634
-        $random_string = substr($random_string, 0, $length);
635
-        return $random_string;
636
-    }
637
-
638
-
639
-    /**
640
-     * encrypts data using PHP's mcrypt functions
641
-     *
642
-     * @param string $text_string
643
-     * @return string
644
-     * @throws RuntimeException
645
-     * @deprecated 4.9.39
646
-     * @internal   param $string - the text to be encrypted
647
-     */
648
-    protected function m_encrypt($text_string = '')
649
-    {
650
-        // you give me nothing??? GET OUT !
651
-        if (empty($text_string)) {
652
-            return $text_string;
653
-        }
654
-        // get the initialization vector size
655
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
656
-        // initialization vector
657
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
658
-        if ($iv === false) {
659
-            throw new RuntimeException(
660
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
661
-            );
662
-        }
663
-        // encrypt it
664
-        $encrypted_text = mcrypt_encrypt(
665
-            MCRYPT_RIJNDAEL_256,
666
-            $this->get_encryption_key(),
667
-            $text_string,
668
-            MCRYPT_MODE_ECB,
669
-            $iv
670
-        );
671
-        // trim and maybe encode
672
-        return $this->_use_base64_encode
673
-            ? trim(base64_encode($encrypted_text))
674
-            : trim($encrypted_text);
675
-    }
676
-
677
-
678
-    /**
679
-     * decrypts data that has been encrypted with PHP's mcrypt functions
680
-     *
681
-     * @param string $encrypted_text the text to be decrypted
682
-     * @return string
683
-     * @throws RuntimeException
684
-     * @deprecated 4.9.39
685
-     */
686
-    protected function m_decrypt($encrypted_text = '')
687
-    {
688
-        // you give me nothing??? GET OUT !
689
-        if (empty($encrypted_text)) {
690
-            return $encrypted_text;
691
-        }
692
-        // decode
693
-        $encrypted_text = $this->valid_base_64($encrypted_text)
694
-            ? $this->base64_url_decode($encrypted_text)
695
-            : $encrypted_text;
696
-        // get the initialization vector size
697
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
698
-        $iv      = mcrypt_create_iv($iv_size, MCRYPT_RAND);
699
-        if ($iv === false) {
700
-            throw new RuntimeException(
701
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
702
-            );
703
-        }
704
-        // decrypt it
705
-        $decrypted_text = mcrypt_decrypt(
706
-            MCRYPT_RIJNDAEL_256,
707
-            $this->get_encryption_key(),
708
-            $encrypted_text,
709
-            MCRYPT_MODE_ECB,
710
-            $iv
711
-        );
712
-        $decrypted_text = trim($decrypted_text);
713
-        return $decrypted_text;
714
-    }
43
+	/**
44
+	 * key used for saving the encryption key to the wp_options table
45
+	 */
46
+	const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
47
+
48
+	/**
49
+	 * the OPENSSL cipher method used
50
+	 */
51
+	const OPENSSL_CIPHER_METHOD = 'AES-128-CBC';
52
+
53
+	/**
54
+	 * WP "options_name" used to store a verified available cipher method
55
+	 */
56
+	const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method';
57
+
58
+	/**
59
+	 * the OPENSSL digest method used
60
+	 */
61
+	const OPENSSL_DIGEST_METHOD = 'sha512';
62
+
63
+	/**
64
+	 * separates the encrypted text from the initialization vector
65
+	 */
66
+	const OPENSSL_IV_DELIMITER = ':iv:';
67
+
68
+	/**
69
+	 * appended to text encrypted using the acme encryption
70
+	 */
71
+	const ACME_ENCRYPTION_FLAG = '::ae';
72
+
73
+
74
+	/**
75
+	 * instance of the EE_Encryption object
76
+	 */
77
+	protected static $_instance;
78
+
79
+	/**
80
+	 * @var string $_encryption_key
81
+	 */
82
+	protected $_encryption_key;
83
+
84
+	/**
85
+	 * @var string $cipher_method
86
+	 */
87
+	private $cipher_method = '';
88
+
89
+	/**
90
+	 * @var array $cipher_methods
91
+	 */
92
+	private $cipher_methods = [];
93
+
94
+	/**
95
+	 * @var array $digest_methods
96
+	 */
97
+	private $digest_methods = [];
98
+
99
+	/**
100
+	 * @var boolean $_use_openssl_encrypt
101
+	 */
102
+	protected $_use_openssl_encrypt = false;
103
+
104
+	/**
105
+	 * @var boolean $_use_mcrypt
106
+	 */
107
+	protected $_use_mcrypt = false;
108
+
109
+	/**
110
+	 * @var boolean $_use_base64_encode
111
+	 */
112
+	protected $_use_base64_encode = false;
113
+
114
+
115
+	/**
116
+	 * protected constructor to prevent direct creation
117
+	 */
118
+	protected function __construct()
119
+	{
120
+		if (! defined('ESPRESSO_ENCRYPT')) {
121
+			define('ESPRESSO_ENCRYPT', true);
122
+		}
123
+		if (extension_loaded('openssl')) {
124
+			$this->_use_openssl_encrypt = true;
125
+		} elseif (extension_loaded('mcrypt')) {
126
+			$this->_use_mcrypt = true;
127
+		}
128
+		if (function_exists('base64_encode')) {
129
+			$this->_use_base64_encode = true;
130
+		}
131
+	}
132
+
133
+
134
+	/**
135
+	 * singleton method used to instantiate class object
136
+	 *
137
+	 * @return EE_Encryption
138
+	 */
139
+	public static function instance()
140
+	{
141
+		// check if class object is instantiated
142
+		if (! EE_Encryption::$_instance instanceof EE_Encryption) {
143
+			EE_Encryption::$_instance = new self();
144
+		}
145
+		return EE_Encryption::$_instance;
146
+	}
147
+
148
+
149
+	/**
150
+	 * get encryption key
151
+	 *
152
+	 * @return string
153
+	 */
154
+	public function get_encryption_key()
155
+	{
156
+		// if encryption key has not been set
157
+		if (empty($this->_encryption_key)) {
158
+			// retrieve encryption_key from db
159
+			$this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
160
+			// WHAT?? No encryption_key in the db ??
161
+			if ($this->_encryption_key === '') {
162
+				// let's make one. And md5 it to make it just the right size for a key
163
+				$new_key = md5($this->generate_random_string());
164
+				// now save it to the db for later
165
+				add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
166
+				// here's the key - FINALLY !
167
+				$this->_encryption_key = $new_key;
168
+			}
169
+		}
170
+		return $this->_encryption_key;
171
+	}
172
+
173
+
174
+	/**
175
+	 * encrypts data
176
+	 *
177
+	 * @param string $text_string - the text to be encrypted
178
+	 * @return string
179
+	 * @throws RuntimeException
180
+	 */
181
+	public function encrypt($text_string = '')
182
+	{
183
+		// you give me nothing??? GET OUT !
184
+		if (empty($text_string)) {
185
+			return $text_string;
186
+		}
187
+		if ($this->_use_openssl_encrypt) {
188
+			$encrypted_text = $this->openssl_encrypt($text_string);
189
+		} else {
190
+			$encrypted_text = $this->acme_encrypt($text_string);
191
+		}
192
+		return $encrypted_text;
193
+	}
194
+
195
+
196
+	/**
197
+	 * decrypts data
198
+	 *
199
+	 * @param string $encrypted_text - the text to be decrypted
200
+	 * @return string
201
+	 * @throws RuntimeException
202
+	 */
203
+	public function decrypt($encrypted_text = '')
204
+	{
205
+		// you give me nothing??? GET OUT !
206
+		if (empty($encrypted_text)) {
207
+			return $encrypted_text;
208
+		}
209
+		// if PHP's mcrypt functions are installed then we'll use them
210
+		if ($this->_use_openssl_encrypt) {
211
+			$decrypted_text = $this->openssl_decrypt($encrypted_text);
212
+		} else {
213
+			$decrypted_text = $this->acme_decrypt($encrypted_text);
214
+		}
215
+		return $decrypted_text;
216
+	}
217
+
218
+
219
+	/**
220
+	 * encodes string with PHP's base64 encoding
221
+	 *
222
+	 * @see http://php.net/manual/en/function.base64-encode.php
223
+	 * @param string $text_string the text to be encoded
224
+	 * @return string
225
+	 */
226
+	public function base64_string_encode($text_string = '')
227
+	{
228
+		// you give me nothing??? GET OUT !
229
+		if (empty($text_string) || ! $this->_use_base64_encode) {
230
+			return $text_string;
231
+		}
232
+		// encode
233
+		return base64_encode($text_string);
234
+	}
235
+
236
+
237
+	/**
238
+	 * decodes string that has been encoded with PHP's base64 encoding
239
+	 *
240
+	 * @see http://php.net/manual/en/function.base64-encode.php
241
+	 * @param string $encoded_string the text to be decoded
242
+	 * @return string
243
+	 * @throws RuntimeException
244
+	 */
245
+	public function base64_string_decode($encoded_string = '')
246
+	{
247
+		// you give me nothing??? GET OUT !
248
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
249
+			return $encoded_string;
250
+		}
251
+		// decode
252
+		$decoded_string = base64_decode($encoded_string);
253
+		if ($decoded_string === false) {
254
+			throw new RuntimeException(
255
+				esc_html__('Base 64 decoding failed.', 'event_espresso')
256
+			);
257
+		}
258
+		return $decoded_string;
259
+	}
260
+
261
+
262
+	/**
263
+	 * encodes  url string with PHP's base64 encoding
264
+	 *
265
+	 * @see http://php.net/manual/en/function.base64-encode.php
266
+	 * @param string $text_string the text to be encoded
267
+	 * @return string
268
+	 */
269
+	public function base64_url_encode($text_string = '')
270
+	{
271
+		// you give me nothing??? GET OUT !
272
+		if (empty($text_string) || ! $this->_use_base64_encode) {
273
+			return $text_string;
274
+		}
275
+		// encode
276
+		$encoded_string = base64_encode($text_string);
277
+		// remove chars to make encoding more URL friendly
278
+		return strtr($encoded_string, '+/=', '-_,');
279
+	}
280
+
281
+
282
+	/**
283
+	 * decodes  url string that has been encoded with PHP's base64 encoding
284
+	 *
285
+	 * @see http://php.net/manual/en/function.base64-encode.php
286
+	 * @param string $encoded_string the text to be decoded
287
+	 * @return string
288
+	 * @throws RuntimeException
289
+	 */
290
+	public function base64_url_decode($encoded_string = '')
291
+	{
292
+		// replace previously removed characters
293
+		$encoded_string = strtr($encoded_string, '-_,', '+/=');
294
+		// you give me nothing??? GET OUT !
295
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
296
+			return $encoded_string;
297
+		}
298
+		// decode
299
+		$decoded_string = base64_decode($encoded_string);
300
+		if ($decoded_string === false) {
301
+			throw new RuntimeException(
302
+				esc_html__('Base 64 decoding failed.', 'event_espresso')
303
+			);
304
+		}
305
+		return $decoded_string;
306
+	}
307
+
308
+
309
+	/**
310
+	 * encrypts data using PHP's openssl functions
311
+	 *
312
+	 * @param string $text_string the text to be encrypted
313
+	 * @param string $cipher_method
314
+	 * @param string $encryption_key
315
+	 * @return string
316
+	 * @throws RuntimeException
317
+	 */
318
+	protected function openssl_encrypt(
319
+		$text_string = '',
320
+		$cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD,
321
+		$encryption_key = ''
322
+	) {
323
+		// you give me nothing??? GET OUT !
324
+		if (empty($text_string)) {
325
+			return $text_string;
326
+		}
327
+		$this->cipher_method = $this->getCipherMethod($cipher_method);
328
+		// get initialization vector size
329
+		$iv_size = openssl_cipher_iv_length($this->cipher_method);
330
+		// generate initialization vector.
331
+		// The second parameter ("crypto_strong") is passed by reference,
332
+		// and is used to determines if the algorithm used was "cryptographically strong"
333
+		// openssl_random_pseudo_bytes() will toggle it to either true or false
334
+		$iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
335
+		if ($iv === false || $is_strong === false) {
336
+			throw new RuntimeException(
337
+				esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
338
+			);
339
+		}
340
+		// encrypt it
341
+		$encrypted_text = openssl_encrypt(
342
+			$text_string,
343
+			$this->cipher_method,
344
+			$this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key),
345
+			0,
346
+			$iv
347
+		);
348
+		// append the initialization vector
349
+		$encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
350
+		// trim and maybe encode
351
+		return $this->_use_base64_encode
352
+			? trim(base64_encode($encrypted_text))
353
+			: trim($encrypted_text);
354
+	}
355
+
356
+
357
+	/**
358
+	 * Returns a cipher method that has been verified to work.
359
+	 * First checks if the cached cipher has been set already and if so, returns that.
360
+	 * Then tests the incoming default and returns that if it's good.
361
+	 * If not, then it retrieves the previously tested and saved cipher method.
362
+	 * But if that doesn't exist, then calls getAvailableCipherMethod()
363
+	 * to see what is available on the server, and returns the results.
364
+	 *
365
+	 * @param string $cipher_method
366
+	 * @return string
367
+	 * @throws RuntimeException
368
+	 */
369
+	protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD)
370
+	{
371
+		if ($this->cipher_method !== '') {
372
+			return $this->cipher_method;
373
+		}
374
+		// verify that the default cipher method can produce an initialization vector
375
+		if (openssl_cipher_iv_length($cipher_method) === false) {
376
+			// nope? okay let's get what we found in the past to work
377
+			$cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, '');
378
+			// oops... haven't tested available cipher methods yet
379
+			if ($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) {
380
+				$cipher_method = $this->getAvailableCipherMethod($cipher_method);
381
+			}
382
+		}
383
+		return $cipher_method;
384
+	}
385
+
386
+
387
+	/**
388
+	 * @param string $cipher_method
389
+	 * @return string
390
+	 * @throws \RuntimeException
391
+	 */
392
+	protected function getAvailableCipherMethod($cipher_method)
393
+	{
394
+		// verify that the incoming cipher method can produce an initialization vector
395
+		if (openssl_cipher_iv_length($cipher_method) === false) {
396
+			// nope? then check the next cipher in the list of available cipher methods
397
+			$cipher_method = next($this->cipher_methods);
398
+			// what? there's no list? then generate that list and cache it,
399
+			if (empty($this->cipher_methods)) {
400
+				$this->cipher_methods = openssl_get_cipher_methods();
401
+				// then grab the first item from the list
402
+				$cipher_method = reset($this->cipher_methods);
403
+			}
404
+			if ($cipher_method === false) {
405
+				throw new RuntimeException(
406
+					esc_html__(
407
+						'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.',
408
+						'event_espresso'
409
+					)
410
+				);
411
+			}
412
+			// verify that the next cipher method works
413
+			return $this->getAvailableCipherMethod($cipher_method);
414
+		}
415
+		// if we've gotten this far, then we found an available cipher method that works
416
+		// so save that for next time
417
+		update_option(
418
+			EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME,
419
+			$cipher_method
420
+		);
421
+		return $cipher_method;
422
+	}
423
+
424
+
425
+	/**
426
+	 * decrypts data that has been encrypted with PHP's openssl functions
427
+	 *
428
+	 * @param string $encrypted_text the text to be decrypted
429
+	 * @param string $cipher_method
430
+	 * @param string $encryption_key
431
+	 * @return string
432
+	 * @throws RuntimeException
433
+	 */
434
+	protected function openssl_decrypt(
435
+		$encrypted_text = '',
436
+		$cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD,
437
+		$encryption_key = ''
438
+	) {
439
+		// you give me nothing??? GET OUT !
440
+		if (empty($encrypted_text)) {
441
+			return $encrypted_text;
442
+		}
443
+		// decode
444
+		$encrypted_text       = $this->valid_base_64($encrypted_text)
445
+			? $this->base64_url_decode($encrypted_text)
446
+			: $encrypted_text;
447
+		$encrypted_components = explode(
448
+			EE_Encryption::OPENSSL_IV_DELIMITER,
449
+			$encrypted_text,
450
+			2
451
+		);
452
+		// check that iv exists, and if not, maybe text was encoded using mcrypt?
453
+		if ($this->_use_mcrypt && ! isset($encrypted_components[1])) {
454
+			return $this->m_decrypt($encrypted_text);
455
+		}
456
+		// decrypt it
457
+		$decrypted_text = openssl_decrypt(
458
+			$encrypted_components[0],
459
+			$this->getCipherMethod($cipher_method),
460
+			$this->getDigestHashValue(EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key),
461
+			0,
462
+			$encrypted_components[1]
463
+		);
464
+		$decrypted_text = trim($decrypted_text);
465
+		return $decrypted_text;
466
+	}
467
+
468
+
469
+	/**
470
+	 * Computes the digest hash value using the specified digest method.
471
+	 * If that digest method fails to produce a valid hash value,
472
+	 * then we'll grab the next digest method and recursively try again until something works.
473
+	 *
474
+	 * @param string $digest_method
475
+	 * @param string $encryption_key
476
+	 * @return string
477
+	 * @throws RuntimeException
478
+	 */
479
+	protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD, $encryption_key = '')
480
+	{
481
+		$encryption_key    = $encryption_key !== ''
482
+			? $encryption_key
483
+			: $this->get_encryption_key();
484
+		$digest_hash_value = openssl_digest($encryption_key, $digest_method);
485
+		if ($digest_hash_value === false) {
486
+			return $this->getDigestHashValue($this->getDigestMethod());
487
+		}
488
+		return $digest_hash_value;
489
+	}
490
+
491
+
492
+	/**
493
+	 * Returns the NEXT element in the $digest_methods array.
494
+	 * If the $digest_methods array is empty, then we populate it
495
+	 * with the available values returned from openssl_get_md_methods().
496
+	 *
497
+	 * @return string
498
+	 * @throws \RuntimeException
499
+	 */
500
+	protected function getDigestMethod()
501
+	{
502
+		$digest_method = prev($this->digest_methods);
503
+		if (empty($this->digest_methods)) {
504
+			$this->digest_methods = openssl_get_md_methods();
505
+			$digest_method        = end($this->digest_methods);
506
+		}
507
+		if ($digest_method === false) {
508
+			throw new RuntimeException(
509
+				esc_html__(
510
+					'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.',
511
+					'event_espresso'
512
+				)
513
+			);
514
+		}
515
+		return $digest_method;
516
+	}
517
+
518
+
519
+	/**
520
+	 * encrypts data for acme servers that didn't bother to install PHP mcrypt
521
+	 *
522
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
523
+	 * @param string $text_string the text to be decrypted
524
+	 * @return string
525
+	 */
526
+	protected function acme_encrypt($text_string = '')
527
+	{
528
+		// you give me nothing??? GET OUT !
529
+		if (empty($text_string)) {
530
+			return $text_string;
531
+		}
532
+		$key_bits    = str_split(
533
+			str_pad(
534
+				'',
535
+				strlen($text_string),
536
+				$this->get_encryption_key(),
537
+				STR_PAD_RIGHT
538
+			)
539
+		);
540
+		$string_bits = str_split($text_string);
541
+		foreach ($string_bits as $k => $v) {
542
+			$temp              = ord($v) + ord($key_bits[ $k ]);
543
+			$string_bits[ $k ] = chr($temp > 255 ? ($temp - 256) : $temp);
544
+		}
545
+		$encrypted_text = implode('', $string_bits);
546
+		$encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG;
547
+		return $this->_use_base64_encode
548
+			? base64_encode($encrypted_text)
549
+			: $encrypted_text;
550
+	}
551
+
552
+
553
+	/**
554
+	 * decrypts data for acme servers that didn't bother to install PHP mcrypt
555
+	 *
556
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
557
+	 * @param string $encrypted_text the text to be decrypted
558
+	 * @return string
559
+	 * @throws RuntimeException
560
+	 */
561
+	protected function acme_decrypt($encrypted_text = '')
562
+	{
563
+		// you give me nothing??? GET OUT !
564
+		if (empty($encrypted_text)) {
565
+			return $encrypted_text;
566
+		}
567
+		// decode the data ?
568
+		$encrypted_text = $this->valid_base_64($encrypted_text)
569
+			? $this->base64_url_decode($encrypted_text)
570
+			: $encrypted_text;
571
+		if (
572
+			$this->_use_mcrypt
573
+			&& strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false
574
+		) {
575
+			return $this->m_decrypt($encrypted_text);
576
+		}
577
+		$encrypted_text = substr($encrypted_text, 0, -4);
578
+		$key_bits       = str_split(
579
+			str_pad(
580
+				'',
581
+				strlen($encrypted_text),
582
+				$this->get_encryption_key(),
583
+				STR_PAD_RIGHT
584
+			)
585
+		);
586
+		$string_bits    = str_split($encrypted_text);
587
+		foreach ($string_bits as $k => $v) {
588
+			$temp              = ord($v) - ord($key_bits[ $k ]);
589
+			$string_bits[ $k ] = chr($temp < 0 ? ($temp + 256) : $temp);
590
+		}
591
+		return implode('', $string_bits);
592
+	}
593
+
594
+
595
+	/**
596
+	 * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
597
+	 * @param $string
598
+	 * @return bool
599
+	 */
600
+	protected function valid_base_64($string)
601
+	{
602
+		// ensure data is a string
603
+		if (! is_string($string) || ! $this->_use_base64_encode) {
604
+			return false;
605
+		}
606
+		$decoded = base64_decode($string, true);
607
+		// Check if there is no invalid character in string
608
+		if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
609
+			return false;
610
+		}
611
+		// Decode the string in strict mode and send the response
612
+		if (! base64_decode($string, true)) {
613
+			return false;
614
+		}
615
+		// Encode and compare it to original one
616
+		return base64_encode($decoded) === $string;
617
+	}
618
+
619
+
620
+	/**
621
+	 * generate random string
622
+	 *
623
+	 * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
624
+	 * @param int $length number of characters for random string
625
+	 * @return string
626
+	 */
627
+	public function generate_random_string($length = 40)
628
+	{
629
+		$iterations    = ceil($length / 40);
630
+		$random_string = '';
631
+		for ($i = 0; $i < $iterations; $i++) {
632
+			$random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
633
+		}
634
+		$random_string = substr($random_string, 0, $length);
635
+		return $random_string;
636
+	}
637
+
638
+
639
+	/**
640
+	 * encrypts data using PHP's mcrypt functions
641
+	 *
642
+	 * @param string $text_string
643
+	 * @return string
644
+	 * @throws RuntimeException
645
+	 * @deprecated 4.9.39
646
+	 * @internal   param $string - the text to be encrypted
647
+	 */
648
+	protected function m_encrypt($text_string = '')
649
+	{
650
+		// you give me nothing??? GET OUT !
651
+		if (empty($text_string)) {
652
+			return $text_string;
653
+		}
654
+		// get the initialization vector size
655
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
656
+		// initialization vector
657
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
658
+		if ($iv === false) {
659
+			throw new RuntimeException(
660
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
661
+			);
662
+		}
663
+		// encrypt it
664
+		$encrypted_text = mcrypt_encrypt(
665
+			MCRYPT_RIJNDAEL_256,
666
+			$this->get_encryption_key(),
667
+			$text_string,
668
+			MCRYPT_MODE_ECB,
669
+			$iv
670
+		);
671
+		// trim and maybe encode
672
+		return $this->_use_base64_encode
673
+			? trim(base64_encode($encrypted_text))
674
+			: trim($encrypted_text);
675
+	}
676
+
677
+
678
+	/**
679
+	 * decrypts data that has been encrypted with PHP's mcrypt functions
680
+	 *
681
+	 * @param string $encrypted_text the text to be decrypted
682
+	 * @return string
683
+	 * @throws RuntimeException
684
+	 * @deprecated 4.9.39
685
+	 */
686
+	protected function m_decrypt($encrypted_text = '')
687
+	{
688
+		// you give me nothing??? GET OUT !
689
+		if (empty($encrypted_text)) {
690
+			return $encrypted_text;
691
+		}
692
+		// decode
693
+		$encrypted_text = $this->valid_base_64($encrypted_text)
694
+			? $this->base64_url_decode($encrypted_text)
695
+			: $encrypted_text;
696
+		// get the initialization vector size
697
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
698
+		$iv      = mcrypt_create_iv($iv_size, MCRYPT_RAND);
699
+		if ($iv === false) {
700
+			throw new RuntimeException(
701
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
702
+			);
703
+		}
704
+		// decrypt it
705
+		$decrypted_text = mcrypt_decrypt(
706
+			MCRYPT_RIJNDAEL_256,
707
+			$this->get_encryption_key(),
708
+			$encrypted_text,
709
+			MCRYPT_MODE_ECB,
710
+			$iv
711
+		);
712
+		$decrypted_text = trim($decrypted_text);
713
+		return $decrypted_text;
714
+	}
715 715
 }
Please login to merge, or discard this patch.
core/services/encryption/EncryptionKeyManagerInterface.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -12,85 +12,85 @@
 block discarded – undo
12 12
  */
13 13
 interface EncryptionKeyManagerInterface
14 14
 {
15
-    /**
16
-     * add an encryption key
17
-     *
18
-     * @param string $encryption_key_identifier - name of the encryption key to use
19
-     * @param string $encryption_key            - cryptographically secure passphrase. will generate if necessary
20
-     * @param bool   $overwrite                 - prevents accidental overwriting of an existing key which would be bad
21
-     * @return bool
22
-     */
23
-    public function addEncryptionKey($encryption_key_identifier, $encryption_key = '', $overwrite = false);
24
-
25
-
26
-    /**
27
-     * returns true if encryption key has already been generated
28
-     *
29
-     * @param string $encryption_key_identifier - encryption key name
30
-     * @return bool
31
-     */
32
-    public function encryptionKeyExists($encryption_key_identifier = '');
33
-
34
-
35
-    /**
36
-     * returns cryptographically secure passphrase. will use default if necessary
37
-     *
38
-     * @param string $encryption_key_identifier - encryption key name. will use default if necessary
39
-     * @param bool   $generate                  - will generate a new key if the requested one does not exist
40
-     * @param bool   $throw_exception           - if TRUE (default), will throw an exception if key is not found
41
-     * @return string
42
-     */
43
-    public function getEncryptionKey($encryption_key_identifier = '', $generate = false, $throw_exception = true);
44
-
45
-
46
-    /**
47
-     * creates a new encryption key
48
-     *
49
-     * @param bool $strong if true (default) will attempt to generate a cryptographically secure key
50
-     * @return string
51
-     */
52
-    public function generateEncryptionKey($strong = true);
53
-
54
-
55
-    /**
56
-     * @return int
57
-     */
58
-    public function bitDepth();
59
-
60
-
61
-    /**
62
-     * @param int $bit_depth options are 64, 128, 192, or 256
63
-     */
64
-    public function setBitDepth($bit_depth);
65
-
66
-
67
-    /**
68
-     * @return int
69
-     */
70
-    public function keyLength();
71
-
72
-
73
-    /**
74
-     * @param int $key_length
75
-     */
76
-    public function setKeyLength($key_length);
77
-
78
-
79
-    /**
80
-     * deletes ALL existing encryption keys from the db
81
-     *
82
-     * @return bool true if keys successfully deleted, false otherwise.
83
-     */
84
-    public function removeAllEncryptionKeys();
85
-
86
-
87
-    /**
88
-     * deletes an existing encryption key from those saved in the db
89
-     *
90
-     * @param string $encryption_key_identifier encryption key name
91
-     * @return int  1: key removed successfully.
92
-     *              0: key did not exist.
93
-     *             -1: failed to remove key
94
-     */
95
-    public function removeEncryptionKey($encryption_key_identifier = '');
15
+	/**
16
+	 * add an encryption key
17
+	 *
18
+	 * @param string $encryption_key_identifier - name of the encryption key to use
19
+	 * @param string $encryption_key            - cryptographically secure passphrase. will generate if necessary
20
+	 * @param bool   $overwrite                 - prevents accidental overwriting of an existing key which would be bad
21
+	 * @return bool
22
+	 */
23
+	public function addEncryptionKey($encryption_key_identifier, $encryption_key = '', $overwrite = false);
24
+
25
+
26
+	/**
27
+	 * returns true if encryption key has already been generated
28
+	 *
29
+	 * @param string $encryption_key_identifier - encryption key name
30
+	 * @return bool
31
+	 */
32
+	public function encryptionKeyExists($encryption_key_identifier = '');
33
+
34
+
35
+	/**
36
+	 * returns cryptographically secure passphrase. will use default if necessary
37
+	 *
38
+	 * @param string $encryption_key_identifier - encryption key name. will use default if necessary
39
+	 * @param bool   $generate                  - will generate a new key if the requested one does not exist
40
+	 * @param bool   $throw_exception           - if TRUE (default), will throw an exception if key is not found
41
+	 * @return string
42
+	 */
43
+	public function getEncryptionKey($encryption_key_identifier = '', $generate = false, $throw_exception = true);
44
+
45
+
46
+	/**
47
+	 * creates a new encryption key
48
+	 *
49
+	 * @param bool $strong if true (default) will attempt to generate a cryptographically secure key
50
+	 * @return string
51
+	 */
52
+	public function generateEncryptionKey($strong = true);
53
+
54
+
55
+	/**
56
+	 * @return int
57
+	 */
58
+	public function bitDepth();
59
+
60
+
61
+	/**
62
+	 * @param int $bit_depth options are 64, 128, 192, or 256
63
+	 */
64
+	public function setBitDepth($bit_depth);
65
+
66
+
67
+	/**
68
+	 * @return int
69
+	 */
70
+	public function keyLength();
71
+
72
+
73
+	/**
74
+	 * @param int $key_length
75
+	 */
76
+	public function setKeyLength($key_length);
77
+
78
+
79
+	/**
80
+	 * deletes ALL existing encryption keys from the db
81
+	 *
82
+	 * @return bool true if keys successfully deleted, false otherwise.
83
+	 */
84
+	public function removeAllEncryptionKeys();
85
+
86
+
87
+	/**
88
+	 * deletes an existing encryption key from those saved in the db
89
+	 *
90
+	 * @param string $encryption_key_identifier encryption key name
91
+	 * @return int  1: key removed successfully.
92
+	 *              0: key did not exist.
93
+	 *             -1: failed to remove key
94
+	 */
95
+	public function removeEncryptionKey($encryption_key_identifier = '');
96 96
 }
Please login to merge, or discard this patch.
core/services/encryption/EncryptionKeyManager.php 2 patches
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -16,301 +16,301 @@
 block discarded – undo
16 16
  */
17 17
 class EncryptionKeyManager implements EncryptionKeyManagerInterface
18 18
 {
19
-    /**
20
-     * @var Base64Encoder
21
-     */
22
-    protected $base64_encoder;
23
-
24
-    /**
25
-     * name used for a default encryption key in case no others are set
26
-     *
27
-     * @var string
28
-     */
29
-    private $default_encryption_key_id;
30
-
31
-    /**
32
-     * name used for saving encryption keys to the wp_options table
33
-     *
34
-     * @var string
35
-     */
36
-    private $encryption_keys_option_name;
37
-
38
-    /**
39
-     * @var array
40
-     */
41
-    private $encryption_keys = null;
42
-
43
-    /**
44
-     * number of bits used when generating cryptographically secure keys
45
-     *
46
-     * @var int
47
-     */
48
-    private $bit_depth = 128;
49
-
50
-    /**
51
-     * @var int[]
52
-     */
53
-    private $bit_depth_options = [64, 128, 192, 256];
54
-
55
-    /**
56
-     * number of characters used when generating cryptographically weak keys
57
-     *
58
-     * @var int
59
-     */
60
-    private $key_length = 40;
61
-
62
-
63
-    /**
64
-     * @param Base64Encoder $base64_encoder
65
-     * @param string        $default_encryption_key_id
66
-     * @param string        $encryption_keys_option_name
67
-     */
68
-    public function __construct(Base64Encoder $base64_encoder, $default_encryption_key_id, $encryption_keys_option_name)
69
-    {
70
-        $this->base64_encoder              = $base64_encoder;
71
-        $this->default_encryption_key_id   = $default_encryption_key_id;
72
-        $this->encryption_keys_option_name = $encryption_keys_option_name;
73
-    }
74
-
75
-
76
-    /**
77
-     * add an encryption key
78
-     *
79
-     * @param string $encryption_key_identifier - name of the encryption key to use
80
-     * @param string $encryption_key            - cryptographically secure passphrase. will generate if necessary
81
-     * @param bool   $overwrite                 - prevents accidental overwriting of an existing key which would be bad
82
-     * @return bool
83
-     * @throws Exception
84
-     */
85
-    public function addEncryptionKey($encryption_key_identifier, $encryption_key = '', $overwrite = false)
86
-    {
87
-        $encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id;
88
-        if ($this->encryptionKeyExists($encryption_key_identifier) && ! $overwrite) {
89
-            // WOAH!!! that key already exists and we don't want to overwrite it
90
-            throw new RuntimeException(
91
-                sprintf(
92
-                    esc_html__(
93
-                        'The "%1$s" encryption key already exists and can not be overwritten because previously encrypted values would no longer be capable of being decrypted.',
94
-                        'event_espresso'
95
-                    ),
96
-                    $encryption_key_identifier
97
-                )
98
-            );
99
-        }
100
-        $this->encryption_keys[ $encryption_key_identifier ] = $encryption_key ?: $this->generateEncryptionKey();
101
-        return $this->saveEncryptionKeys();
102
-    }
103
-
104
-
105
-    /**
106
-     * returns true if encryption key has already been generated
107
-     *
108
-     * @param string $encryption_key_identifier - encryption key name
109
-     * @return bool
110
-     * @throws Exception
111
-     * @throws OutOfBoundsException
112
-     */
113
-    public function encryptionKeyExists($encryption_key_identifier = '')
114
-    {
115
-        // ensure keys are loaded
116
-        $this->retrieveEncryptionKeys();
117
-        return isset($this->encryption_keys[ $encryption_key_identifier ]);
118
-    }
119
-
120
-
121
-    /**
122
-     * returns cryptographically secure passphrase. will use default if necessary
123
-     *
124
-     * @param string $encryption_key_identifier - encryption key name. will use default if necessary
125
-     * @param bool   $generate                  - will generate a new key if the requested one does not exist
126
-     * @param bool   $throw_exception           - if TRUE (default), will throw an exception if key is not found
127
-     * @return string
128
-     * @throws Exception
129
-     */
130
-    public function getEncryptionKey($encryption_key_identifier = '', $generate = true, $throw_exception = true)
131
-    {
132
-        $encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id;
133
-        // if encryption key has not been set
134
-        if (! $this->encryptionKeyExists($encryption_key_identifier)) {
135
-            if ($generate) {
136
-                $this->addEncryptionKey($encryption_key_identifier);
137
-            } else {
138
-                if (! $throw_exception) {
139
-                    return '';
140
-                }
141
-                throw new OutOfBoundsException(
142
-                    sprintf(
143
-                        esc_html__('The "%1$s" encryption key was not found or is invalid.', 'event_espresso'),
144
-                        $encryption_key_identifier
145
-                    )
146
-                );
147
-            }
148
-        }
149
-        return $this->encryption_keys[ $encryption_key_identifier ];
150
-    }
151
-
152
-
153
-    /**
154
-     * creates a new encryption key
155
-     *
156
-     * @param bool $strong if true (default) will attempt to generate a cryptographically secure key
157
-     * @return string
158
-     * @throws Exception
159
-     */
160
-    public function generateEncryptionKey($strong = true)
161
-    {
162
-        return $strong && PHP_VERSION_ID >= 70100
163
-            ? $this->generateStrongEncryptionKey()
164
-            : $this->generateWeakEncryptionKey();
165
-    }
166
-
167
-
168
-    /**
169
-     * creates a new cryptographically secure encryption key
170
-     *
171
-     * @return string
172
-     * @throws Exception
173
-     */
174
-    protected function generateStrongEncryptionKey()
175
-    {
176
-        // bit_depth needs to be divided by 8 to convert to bytes
177
-        return $this->base64_encoder->encodeString(random_bytes($this->bit_depth / 8));
178
-    }
179
-
180
-
181
-    /**
182
-     * creates a new encryption key that should not be trusted to be cryptographically secure
183
-     *
184
-     * @return string
185
-     * @throws Exception
186
-     */
187
-    protected function generateWeakEncryptionKey()
188
-    {
189
-        // @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
190
-        $iterations    = ceil($this->key_length / 40);
191
-        $random_string = '';
192
-        for ($i = 0; $i < $iterations; $i++) {
193
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
194
-        }
195
-        $random_string = (string) substr($random_string, 0, $this->key_length);
196
-        return $this->base64_encoder->encodeString($random_string);
197
-    }
198
-
199
-
200
-    /**
201
-     * @return int
202
-     */
203
-    public function bitDepth()
204
-    {
205
-        return $this->bit_depth;
206
-    }
207
-
208
-
209
-    /**
210
-     * @param int $bit_depth options are 64, 128, 192, or 256
211
-     */
212
-    public function setBitDepth($bit_depth)
213
-    {
214
-        $bit_depth       = absint($bit_depth);
215
-        $this->bit_depth = in_array($bit_depth, $this->bit_depth_options, true) ? $bit_depth : 128;
216
-    }
217
-
218
-
219
-    /**
220
-     * @return int
221
-     */
222
-    public function keyLength()
223
-    {
224
-        return $this->key_length;
225
-    }
226
-
227
-
228
-    /**
229
-     * @param int $key_length
230
-     */
231
-    public function setKeyLength($key_length)
232
-    {
233
-        // let's not let the key length go below 8 or above 128
234
-        $this->key_length = min(max(absint($key_length), 8), 128);
235
-    }
236
-
237
-
238
-    /**
239
-     * deletes ALL existing encryption keys from the db
240
-     *
241
-     * @return bool true if keys successfully deleted, false otherwise.
242
-     */
243
-    public function removeAllEncryptionKeys()
244
-    {
245
-        return delete_option($this->encryption_keys_option_name);
246
-    }
247
-
248
-
249
-    /**
250
-     * deletes an existing encryption key from those saved in the db
251
-     *
252
-     * @param string $encryption_key_identifier encryption key name
253
-     * @return int  1: key removed successfully.
254
-     *              0: key did not exist.
255
-     *             -1: failed to remove key
256
-     * @throws Exception
257
-     */
258
-    public function removeEncryptionKey($encryption_key_identifier = '')
259
-    {
260
-        // if encryption key has not been set
261
-        if (! $this->encryptionKeyExists($encryption_key_identifier)) {
262
-            return 0;
263
-        }
264
-        unset($this->encryption_keys[ $encryption_key_identifier ]);
265
-        return $this->saveEncryptionKeys() ? 1 : -1;
266
-    }
267
-
268
-
269
-    /**
270
-     * retrieves encryption keys from db
271
-     *
272
-     * @return array
273
-     * @throws Exception
274
-     * @throws RuntimeException
275
-     */
276
-    protected function retrieveEncryptionKeys()
277
-    {
278
-        // if encryption key has not been set
279
-        if (empty($this->encryption_keys)) {
280
-            // retrieve encryption_key from db
281
-            $this->encryption_keys = get_option($this->encryption_keys_option_name, null);
282
-            // WHAT?? No encryption keys in the db ??
283
-            if ($this->encryption_keys === null) {
284
-                $this->encryption_keys = [];
285
-                // let's create the default key and save it
286
-                $new_key                                                   = $this->generateEncryptionKey();
287
-                $this->encryption_keys[ $this->default_encryption_key_id ] = $new_key;
288
-                if (! $this->saveEncryptionKeys(true)) {
289
-                    throw new RuntimeException(
290
-                        sprintf(
291
-                            esc_html__(
292
-                                'Failed to save the "%1$s" encryption keys array to the database.',
293
-                                'event_espresso'
294
-                            ),
295
-                            $this->encryption_keys_option_name
296
-                        )
297
-                    );
298
-                }
299
-            }
300
-        }
301
-        return $this->encryption_keys;
302
-    }
303
-
304
-
305
-    /**
306
-     * saves encryption keys from db
307
-     *
308
-     * @return bool
309
-     */
310
-    protected function saveEncryptionKeys($initialize = false)
311
-    {
312
-        return $initialize
313
-            ? add_option($this->encryption_keys_option_name, $this->encryption_keys, '', false)
314
-            : update_option($this->encryption_keys_option_name, $this->encryption_keys, false);
315
-    }
19
+	/**
20
+	 * @var Base64Encoder
21
+	 */
22
+	protected $base64_encoder;
23
+
24
+	/**
25
+	 * name used for a default encryption key in case no others are set
26
+	 *
27
+	 * @var string
28
+	 */
29
+	private $default_encryption_key_id;
30
+
31
+	/**
32
+	 * name used for saving encryption keys to the wp_options table
33
+	 *
34
+	 * @var string
35
+	 */
36
+	private $encryption_keys_option_name;
37
+
38
+	/**
39
+	 * @var array
40
+	 */
41
+	private $encryption_keys = null;
42
+
43
+	/**
44
+	 * number of bits used when generating cryptographically secure keys
45
+	 *
46
+	 * @var int
47
+	 */
48
+	private $bit_depth = 128;
49
+
50
+	/**
51
+	 * @var int[]
52
+	 */
53
+	private $bit_depth_options = [64, 128, 192, 256];
54
+
55
+	/**
56
+	 * number of characters used when generating cryptographically weak keys
57
+	 *
58
+	 * @var int
59
+	 */
60
+	private $key_length = 40;
61
+
62
+
63
+	/**
64
+	 * @param Base64Encoder $base64_encoder
65
+	 * @param string        $default_encryption_key_id
66
+	 * @param string        $encryption_keys_option_name
67
+	 */
68
+	public function __construct(Base64Encoder $base64_encoder, $default_encryption_key_id, $encryption_keys_option_name)
69
+	{
70
+		$this->base64_encoder              = $base64_encoder;
71
+		$this->default_encryption_key_id   = $default_encryption_key_id;
72
+		$this->encryption_keys_option_name = $encryption_keys_option_name;
73
+	}
74
+
75
+
76
+	/**
77
+	 * add an encryption key
78
+	 *
79
+	 * @param string $encryption_key_identifier - name of the encryption key to use
80
+	 * @param string $encryption_key            - cryptographically secure passphrase. will generate if necessary
81
+	 * @param bool   $overwrite                 - prevents accidental overwriting of an existing key which would be bad
82
+	 * @return bool
83
+	 * @throws Exception
84
+	 */
85
+	public function addEncryptionKey($encryption_key_identifier, $encryption_key = '', $overwrite = false)
86
+	{
87
+		$encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id;
88
+		if ($this->encryptionKeyExists($encryption_key_identifier) && ! $overwrite) {
89
+			// WOAH!!! that key already exists and we don't want to overwrite it
90
+			throw new RuntimeException(
91
+				sprintf(
92
+					esc_html__(
93
+						'The "%1$s" encryption key already exists and can not be overwritten because previously encrypted values would no longer be capable of being decrypted.',
94
+						'event_espresso'
95
+					),
96
+					$encryption_key_identifier
97
+				)
98
+			);
99
+		}
100
+		$this->encryption_keys[ $encryption_key_identifier ] = $encryption_key ?: $this->generateEncryptionKey();
101
+		return $this->saveEncryptionKeys();
102
+	}
103
+
104
+
105
+	/**
106
+	 * returns true if encryption key has already been generated
107
+	 *
108
+	 * @param string $encryption_key_identifier - encryption key name
109
+	 * @return bool
110
+	 * @throws Exception
111
+	 * @throws OutOfBoundsException
112
+	 */
113
+	public function encryptionKeyExists($encryption_key_identifier = '')
114
+	{
115
+		// ensure keys are loaded
116
+		$this->retrieveEncryptionKeys();
117
+		return isset($this->encryption_keys[ $encryption_key_identifier ]);
118
+	}
119
+
120
+
121
+	/**
122
+	 * returns cryptographically secure passphrase. will use default if necessary
123
+	 *
124
+	 * @param string $encryption_key_identifier - encryption key name. will use default if necessary
125
+	 * @param bool   $generate                  - will generate a new key if the requested one does not exist
126
+	 * @param bool   $throw_exception           - if TRUE (default), will throw an exception if key is not found
127
+	 * @return string
128
+	 * @throws Exception
129
+	 */
130
+	public function getEncryptionKey($encryption_key_identifier = '', $generate = true, $throw_exception = true)
131
+	{
132
+		$encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id;
133
+		// if encryption key has not been set
134
+		if (! $this->encryptionKeyExists($encryption_key_identifier)) {
135
+			if ($generate) {
136
+				$this->addEncryptionKey($encryption_key_identifier);
137
+			} else {
138
+				if (! $throw_exception) {
139
+					return '';
140
+				}
141
+				throw new OutOfBoundsException(
142
+					sprintf(
143
+						esc_html__('The "%1$s" encryption key was not found or is invalid.', 'event_espresso'),
144
+						$encryption_key_identifier
145
+					)
146
+				);
147
+			}
148
+		}
149
+		return $this->encryption_keys[ $encryption_key_identifier ];
150
+	}
151
+
152
+
153
+	/**
154
+	 * creates a new encryption key
155
+	 *
156
+	 * @param bool $strong if true (default) will attempt to generate a cryptographically secure key
157
+	 * @return string
158
+	 * @throws Exception
159
+	 */
160
+	public function generateEncryptionKey($strong = true)
161
+	{
162
+		return $strong && PHP_VERSION_ID >= 70100
163
+			? $this->generateStrongEncryptionKey()
164
+			: $this->generateWeakEncryptionKey();
165
+	}
166
+
167
+
168
+	/**
169
+	 * creates a new cryptographically secure encryption key
170
+	 *
171
+	 * @return string
172
+	 * @throws Exception
173
+	 */
174
+	protected function generateStrongEncryptionKey()
175
+	{
176
+		// bit_depth needs to be divided by 8 to convert to bytes
177
+		return $this->base64_encoder->encodeString(random_bytes($this->bit_depth / 8));
178
+	}
179
+
180
+
181
+	/**
182
+	 * creates a new encryption key that should not be trusted to be cryptographically secure
183
+	 *
184
+	 * @return string
185
+	 * @throws Exception
186
+	 */
187
+	protected function generateWeakEncryptionKey()
188
+	{
189
+		// @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
190
+		$iterations    = ceil($this->key_length / 40);
191
+		$random_string = '';
192
+		for ($i = 0; $i < $iterations; $i++) {
193
+			$random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
194
+		}
195
+		$random_string = (string) substr($random_string, 0, $this->key_length);
196
+		return $this->base64_encoder->encodeString($random_string);
197
+	}
198
+
199
+
200
+	/**
201
+	 * @return int
202
+	 */
203
+	public function bitDepth()
204
+	{
205
+		return $this->bit_depth;
206
+	}
207
+
208
+
209
+	/**
210
+	 * @param int $bit_depth options are 64, 128, 192, or 256
211
+	 */
212
+	public function setBitDepth($bit_depth)
213
+	{
214
+		$bit_depth       = absint($bit_depth);
215
+		$this->bit_depth = in_array($bit_depth, $this->bit_depth_options, true) ? $bit_depth : 128;
216
+	}
217
+
218
+
219
+	/**
220
+	 * @return int
221
+	 */
222
+	public function keyLength()
223
+	{
224
+		return $this->key_length;
225
+	}
226
+
227
+
228
+	/**
229
+	 * @param int $key_length
230
+	 */
231
+	public function setKeyLength($key_length)
232
+	{
233
+		// let's not let the key length go below 8 or above 128
234
+		$this->key_length = min(max(absint($key_length), 8), 128);
235
+	}
236
+
237
+
238
+	/**
239
+	 * deletes ALL existing encryption keys from the db
240
+	 *
241
+	 * @return bool true if keys successfully deleted, false otherwise.
242
+	 */
243
+	public function removeAllEncryptionKeys()
244
+	{
245
+		return delete_option($this->encryption_keys_option_name);
246
+	}
247
+
248
+
249
+	/**
250
+	 * deletes an existing encryption key from those saved in the db
251
+	 *
252
+	 * @param string $encryption_key_identifier encryption key name
253
+	 * @return int  1: key removed successfully.
254
+	 *              0: key did not exist.
255
+	 *             -1: failed to remove key
256
+	 * @throws Exception
257
+	 */
258
+	public function removeEncryptionKey($encryption_key_identifier = '')
259
+	{
260
+		// if encryption key has not been set
261
+		if (! $this->encryptionKeyExists($encryption_key_identifier)) {
262
+			return 0;
263
+		}
264
+		unset($this->encryption_keys[ $encryption_key_identifier ]);
265
+		return $this->saveEncryptionKeys() ? 1 : -1;
266
+	}
267
+
268
+
269
+	/**
270
+	 * retrieves encryption keys from db
271
+	 *
272
+	 * @return array
273
+	 * @throws Exception
274
+	 * @throws RuntimeException
275
+	 */
276
+	protected function retrieveEncryptionKeys()
277
+	{
278
+		// if encryption key has not been set
279
+		if (empty($this->encryption_keys)) {
280
+			// retrieve encryption_key from db
281
+			$this->encryption_keys = get_option($this->encryption_keys_option_name, null);
282
+			// WHAT?? No encryption keys in the db ??
283
+			if ($this->encryption_keys === null) {
284
+				$this->encryption_keys = [];
285
+				// let's create the default key and save it
286
+				$new_key                                                   = $this->generateEncryptionKey();
287
+				$this->encryption_keys[ $this->default_encryption_key_id ] = $new_key;
288
+				if (! $this->saveEncryptionKeys(true)) {
289
+					throw new RuntimeException(
290
+						sprintf(
291
+							esc_html__(
292
+								'Failed to save the "%1$s" encryption keys array to the database.',
293
+								'event_espresso'
294
+							),
295
+							$this->encryption_keys_option_name
296
+						)
297
+					);
298
+				}
299
+			}
300
+		}
301
+		return $this->encryption_keys;
302
+	}
303
+
304
+
305
+	/**
306
+	 * saves encryption keys from db
307
+	 *
308
+	 * @return bool
309
+	 */
310
+	protected function saveEncryptionKeys($initialize = false)
311
+	{
312
+		return $initialize
313
+			? add_option($this->encryption_keys_option_name, $this->encryption_keys, '', false)
314
+			: update_option($this->encryption_keys_option_name, $this->encryption_keys, false);
315
+	}
316 316
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
                 )
98 98
             );
99 99
         }
100
-        $this->encryption_keys[ $encryption_key_identifier ] = $encryption_key ?: $this->generateEncryptionKey();
100
+        $this->encryption_keys[$encryption_key_identifier] = $encryption_key ?: $this->generateEncryptionKey();
101 101
         return $this->saveEncryptionKeys();
102 102
     }
103 103
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     {
115 115
         // ensure keys are loaded
116 116
         $this->retrieveEncryptionKeys();
117
-        return isset($this->encryption_keys[ $encryption_key_identifier ]);
117
+        return isset($this->encryption_keys[$encryption_key_identifier]);
118 118
     }
119 119
 
120 120
 
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
     {
132 132
         $encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id;
133 133
         // if encryption key has not been set
134
-        if (! $this->encryptionKeyExists($encryption_key_identifier)) {
134
+        if ( ! $this->encryptionKeyExists($encryption_key_identifier)) {
135 135
             if ($generate) {
136 136
                 $this->addEncryptionKey($encryption_key_identifier);
137 137
             } else {
138
-                if (! $throw_exception) {
138
+                if ( ! $throw_exception) {
139 139
                     return '';
140 140
                 }
141 141
                 throw new OutOfBoundsException(
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
                 );
147 147
             }
148 148
         }
149
-        return $this->encryption_keys[ $encryption_key_identifier ];
149
+        return $this->encryption_keys[$encryption_key_identifier];
150 150
     }
151 151
 
152 152
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         $iterations    = ceil($this->key_length / 40);
191 191
         $random_string = '';
192 192
         for ($i = 0; $i < $iterations; $i++) {
193
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
193
+            $random_string .= sha1(microtime(true).mt_rand(10000, 90000));
194 194
         }
195 195
         $random_string = (string) substr($random_string, 0, $this->key_length);
196 196
         return $this->base64_encoder->encodeString($random_string);
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
     public function removeEncryptionKey($encryption_key_identifier = '')
259 259
     {
260 260
         // if encryption key has not been set
261
-        if (! $this->encryptionKeyExists($encryption_key_identifier)) {
261
+        if ( ! $this->encryptionKeyExists($encryption_key_identifier)) {
262 262
             return 0;
263 263
         }
264
-        unset($this->encryption_keys[ $encryption_key_identifier ]);
264
+        unset($this->encryption_keys[$encryption_key_identifier]);
265 265
         return $this->saveEncryptionKeys() ? 1 : -1;
266 266
     }
267 267
 
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
                 $this->encryption_keys = [];
285 285
                 // let's create the default key and save it
286 286
                 $new_key                                                   = $this->generateEncryptionKey();
287
-                $this->encryption_keys[ $this->default_encryption_key_id ] = $new_key;
288
-                if (! $this->saveEncryptionKeys(true)) {
287
+                $this->encryption_keys[$this->default_encryption_key_id] = $new_key;
288
+                if ( ! $this->saveEncryptionKeys(true)) {
289 289
                     throw new RuntimeException(
290 290
                         sprintf(
291 291
                             esc_html__(
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_venues-details.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,43 +1,43 @@
 block discarded – undo
1 1
 <?php //echo '<h1>' . __FILE__ . '</h1>'; ?>
2 2
 <?php global $post; ?>
3 3
 <div class="venue-content">
4
-<?php if ( apply_filters( 'FHEE__content_espresso_venues_details_template__display_entry_meta', TRUE )): ?>
4
+<?php if (apply_filters('FHEE__content_espresso_venues_details_template__display_entry_meta', TRUE)): ?>
5 5
 	<div class="entry-meta">
6
-		<span class="tags-links"><?php espresso_venue_categories( $post->ID, TRUE, TRUE ); ?></span>
6
+		<span class="tags-links"><?php espresso_venue_categories($post->ID, TRUE, TRUE); ?></span>
7 7
 		<?php
8
-			if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) :
8
+			if ( ! post_password_required() && (comments_open() || get_comments_number())) :
9 9
 		?>
10
-		<span class="comments-link"><?php comments_popup_link( esc_html__( 'Leave a comment', 'event_espresso' ), esc_html__( '1 Comment', 'event_espresso' ), esc_html__( '% Comments', 'event_espresso' ) ); ?></span>
10
+		<span class="comments-link"><?php comments_popup_link(esc_html__('Leave a comment', 'event_espresso'), esc_html__('1 Comment', 'event_espresso'), esc_html__('% Comments', 'event_espresso')); ?></span>
11 11
 		<?php
12 12
 			endif;
13 13
 
14
-			edit_post_link( esc_html__( 'Edit', 'event_espresso' ), '<span class="edit-link">', '</span>' );
14
+			edit_post_link(esc_html__('Edit', 'event_espresso'), '<span class="edit-link">', '</span>');
15 15
 		?>
16 16
 	</div>
17 17
 <?php  endif; ?>
18 18
 	
19 19
 	<h3 class="event-venues-h3 ee-event-h3">
20
-		<?php esc_html_e( 'Details', 'event_espresso' ); ?>
20
+		<?php esc_html_e('Details', 'event_espresso'); ?>
21 21
 	</h3>
22 22
 
23
-	<?php if ( $venue_phone = espresso_venue_phone( $post->ID, FALSE )) : ?>
23
+	<?php if ($venue_phone = espresso_venue_phone($post->ID, FALSE)) : ?>
24 24
 	<p>
25
-		<span class="small-text"><strong><?php esc_html_e( 'Venue Phone:', 'event_espresso' ); ?> </strong></span><?php echo $venue_phone; ?>
25
+		<span class="small-text"><strong><?php esc_html_e('Venue Phone:', 'event_espresso'); ?> </strong></span><?php echo $venue_phone; ?>
26 26
 	</p>
27 27
 	<?php endif; ?>
28
-	<?php if ( $venue_website = espresso_venue_website( $post->ID, FALSE )) : ?>
28
+	<?php if ($venue_website = espresso_venue_website($post->ID, FALSE)) : ?>
29 29
 	<p>
30
-		<span class="small-text"><strong><?php esc_html_e( 'Venue Website:', 'event_espresso' ); ?> </strong></span><?php echo $venue_website; ?>
30
+		<span class="small-text"><strong><?php esc_html_e('Venue Website:', 'event_espresso'); ?> </strong></span><?php echo $venue_website; ?>
31 31
 	</p>
32 32
 	<?php endif; ?>
33 33
 	<?php 
34
-	do_action( 'AHEE__content_espresso_venues_details_template__before_the_content', $post ); 
35
-	if ( is_archive() && has_excerpt( $post->ID )) {
34
+	do_action('AHEE__content_espresso_venues_details_template__before_the_content', $post); 
35
+	if (is_archive() && has_excerpt($post->ID)) {
36 36
 		the_excerpt();
37 37
 	} else {
38 38
 		the_content();
39 39
 	}
40
-	do_action( 'AHEE__content_espresso_venues_details_template__after_the_content', $post ); 
40
+	do_action('AHEE__content_espresso_venues_details_template__after_the_content', $post); 
41 41
 	?>
42 42
 </div>
43 43
 <!-- .venue-content -->
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_venues-thumbnail.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@  discard block
 block discarded – undo
3 3
 
4 4
 global $post;
5 5
 
6
-do_action( 'AHEE__content_espresso_venues_template__before_featured_img', $post );
6
+do_action('AHEE__content_espresso_venues_template__before_featured_img', $post);
7 7
 
8
-if ( has_post_thumbnail( $post->ID )) :
9
-	if ( $img_ID = get_post_thumbnail_id( $post->ID )) :
10
-		if ( $featured_img = wp_get_attachment_image_src( $img_ID, 'large' )) :
11
-			$caption = get_post( get_post( $img_ID ))->post_excerpt;
8
+if (has_post_thumbnail($post->ID)) :
9
+	if ($img_ID = get_post_thumbnail_id($post->ID)) :
10
+		if ($featured_img = wp_get_attachment_image_src($img_ID, 'large')) :
11
+			$caption = get_post(get_post($img_ID))->post_excerpt;
12 12
 			$wrap_class .= ' has-img';
13 13
 			?>
14 14
 <div id="ee-venue-img-dv-<?php echo esc_attr($post->ID); ?>" class="ee-venue-img-dv">
@@ -26,5 +26,5 @@  discard block
 block discarded – undo
26 26
 	endif;
27 27
 endif;
28 28
 ?>		
29
-<?php do_action( 'AHEE__content_espresso_venues_template__after_featured_img', $post );?>
29
+<?php do_action('AHEE__content_espresso_venues_template__after_featured_img', $post); ?>
30 30
 <!-- .venue-content -->
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_events-details.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,20 +13,20 @@
 block discarded – undo
13 13
 	    <?php if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : ?>
14 14
 	    <span class="comments-link">
15 15
         <?php comments_popup_link(
16
-            esc_html__( 'Leave a comment', 'event_espresso' ),
17
-            esc_html__( '1 Comment', 'event_espresso' ),
18
-            esc_html__( '% Comments', 'event_espresso' )
19
-        ); ?>
16
+			esc_html__( 'Leave a comment', 'event_espresso' ),
17
+			esc_html__( '1 Comment', 'event_espresso' ),
18
+			esc_html__( '% Comments', 'event_espresso' )
19
+		); ?>
20 20
         </span>
21 21
 
22 22
         <?php
23
-            endif;
24
-            edit_post_link(
25
-                esc_html__( 'Edit', 'event_espresso' ),
26
-                '<span class="edit-link">',
27
-                '</span>'
28
-            );
29
-        ?>
23
+			endif;
24
+			edit_post_link(
25
+				esc_html__( 'Edit', 'event_espresso' ),
26
+				'<span class="edit-link">',
27
+				'</span>'
28
+			);
29
+		?>
30 30
 	</div>
31 31
 
32 32
 <?php endif;
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -2,27 +2,27 @@  discard block
 block discarded – undo
2 2
 global $post;
3 3
 ?>
4 4
 <div class="event-content">
5
-<?php if ( apply_filters( 'FHEE__content_espresso_events_details_template__display_entry_meta', TRUE )): ?>
5
+<?php if (apply_filters('FHEE__content_espresso_events_details_template__display_entry_meta', TRUE)): ?>
6 6
 
7 7
 	<div class="entry-meta">
8 8
 
9 9
 		<span class="tags-links">
10
-            <?php espresso_event_categories( $post->ID, TRUE, TRUE ); ?>
10
+            <?php espresso_event_categories($post->ID, TRUE, TRUE); ?>
11 11
         </span>
12 12
 
13
-	    <?php if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : ?>
13
+	    <?php if ( ! post_password_required() && (comments_open() || get_comments_number())) : ?>
14 14
 	    <span class="comments-link">
15 15
         <?php comments_popup_link(
16
-            esc_html__( 'Leave a comment', 'event_espresso' ),
17
-            esc_html__( '1 Comment', 'event_espresso' ),
18
-            esc_html__( '% Comments', 'event_espresso' )
16
+            esc_html__('Leave a comment', 'event_espresso'),
17
+            esc_html__('1 Comment', 'event_espresso'),
18
+            esc_html__('% Comments', 'event_espresso')
19 19
         ); ?>
20 20
         </span>
21 21
 
22 22
         <?php
23 23
             endif;
24 24
             edit_post_link(
25
-                esc_html__( 'Edit', 'event_espresso' ),
25
+                esc_html__('Edit', 'event_espresso'),
26 26
                 '<span class="edit-link">',
27 27
                 '</span>'
28 28
             );
@@ -30,25 +30,25 @@  discard block
 block discarded – undo
30 30
 	</div>
31 31
 
32 32
 <?php endif;
33
-	$event_phone = espresso_event_phone( $post->ID, FALSE );
33
+	$event_phone = espresso_event_phone($post->ID, FALSE);
34 34
 
35
-	if ( $event_phone != '' ) : ?>
35
+	if ($event_phone != '') : ?>
36 36
 	<p class="event-phone">
37 37
 		<span class="small-text">
38
-            <strong><?php esc_html_e( 'Event Phone:', 'event_espresso' ); ?> </strong>
38
+            <strong><?php esc_html_e('Event Phone:', 'event_espresso'); ?> </strong>
39 39
         </span>
40 40
         <?php echo $event_phone; // already escaped ?>
41 41
 	</p>
42
-<?php endif;  ?>
42
+<?php endif; ?>
43 43
 
44 44
 <?php
45
-	if ( apply_filters( 'FHEE__content_espresso_events_details_template__display_the_content', true ) ) {
46
-		do_action( 'AHEE_event_details_before_the_content', $post );
45
+	if (apply_filters('FHEE__content_espresso_events_details_template__display_the_content', true)) {
46
+		do_action('AHEE_event_details_before_the_content', $post);
47 47
 		echo apply_filters(
48 48
 			'FHEE__content_espresso_events_details_template__the_content',
49
-			espresso_event_content_or_excerpt( 55, null, false ) 
49
+			espresso_event_content_or_excerpt(55, null, false) 
50 50
 		);
51
-		do_action( 'AHEE_event_details_after_the_content', $post );
51
+		do_action('AHEE_event_details_after_the_content', $post);
52 52
 	}
53 53
  ?>
54 54
 </div>
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_venues-location.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php //echo '<h1>' . __FILE__ . '</h1>'; 
2 2
 global $post; 
3
-if ( espresso_venue_has_address( $post->ID )) :
3
+if (espresso_venue_has_address($post->ID)) :
4 4
 ?>
5 5
 <div class="venue-location">
6 6
 	
7 7
 	<h3 class="venue-address-h3 ee-venue-h3">
8
-		<span class="dashicons dashicons-location-alt"></span><?php esc_html_e( 'Location', 'event_espresso' ); ?>
8
+		<span class="dashicons dashicons-location-alt"></span><?php esc_html_e('Location', 'event_espresso'); ?>
9 9
 	</h3>
10
-	<span class="small-text"><strong><?php esc_html_e( 'Address:', 'event_espresso' ); ?></strong></span><?php espresso_venue_address( 'inline', $post->ID ); ?>
10
+	<span class="small-text"><strong><?php esc_html_e('Address:', 'event_espresso'); ?></strong></span><?php espresso_venue_address('inline', $post->ID); ?>
11 11
 	<div class="clear"></div>
12 12
 
13
-	<div class="venue-gmap"><?php espresso_venue_gmap( $post->ID ); ?></div>
13
+	<div class="venue-gmap"><?php espresso_venue_gmap($post->ID); ?></div>
14 14
 	<div class="clear"></div>
15 15
 	
16 16
 </div>
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_events-shortcode.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -21,21 +21,21 @@  discard block
 block discarded – undo
21 21
  * and/or use any of the template tags functions found in:
22 22
  * \wp-content\plugins\event-espresso-core\public\template_tags.php
23 23
  ************************** IMPORTANT **************************/
24
-add_filter( 'FHEE__content_espresso_events__template_loaded', '__return_false' );
24
+add_filter('FHEE__content_espresso_events__template_loaded', '__return_false');
25 25
 
26 26
 
27 27
 global $post;
28
-$event_class = has_excerpt( $post->ID ) ? ' has-excerpt' : '';
29
-$event_class = apply_filters( 'FHEE__content_espresso_events__event_class', $event_class );
28
+$event_class = has_excerpt($post->ID) ? ' has-excerpt' : '';
29
+$event_class = apply_filters('FHEE__content_espresso_events__event_class', $event_class);
30 30
 ?>
31
-<?php do_action( 'AHEE_event_details_before_post', $post ); ?>
32
-<article id="post-<?php the_ID(); ?>" <?php post_class( $event_class ); ?>>
31
+<?php do_action('AHEE_event_details_before_post', $post); ?>
32
+<article id="post-<?php the_ID(); ?>" <?php post_class($event_class); ?>>
33 33
 
34
-<?php if ( is_single() ) : ?>
34
+<?php if (is_single()) : ?>
35 35
 
36
-	<div id="espresso-event-header-dv-<?php echo esc_attr($post->ID);?>" class="espresso-event-header-dv">
37
-		<?php espresso_get_template_part( 'content', 'espresso_events-thumbnail' ); ?>
38
-		<?php espresso_get_template_part( 'content', 'espresso_events-header' ); ?>
36
+	<div id="espresso-event-header-dv-<?php echo esc_attr($post->ID); ?>" class="espresso-event-header-dv">
37
+		<?php espresso_get_template_part('content', 'espresso_events-thumbnail'); ?>
38
+		<?php espresso_get_template_part('content', 'espresso_events-header'); ?>
39 39
 	</div>
40 40
 
41 41
 	<div class="espresso-event-wrapper-dv">
@@ -45,16 +45,16 @@  discard block
 block discarded – undo
45 45
 		<?php //espresso_get_template_part( 'content', 'espresso_events-details' ); ?>
46 46
 		<?php //espresso_get_template_part( 'content', 'espresso_events-venues' ); ?>
47 47
 		<footer class="event-meta">
48
-			<?php do_action( 'AHEE_event_details_footer_top', $post ); ?>
49
-			<?php do_action( 'AHEE_event_details_footer_bottom', $post ); ?>
48
+			<?php do_action('AHEE_event_details_footer_top', $post); ?>
49
+			<?php do_action('AHEE_event_details_footer_bottom', $post); ?>
50 50
 		</footer>
51 51
 	</div>
52 52
 
53
-<?php elseif ( is_archive() ) : ?>
53
+<?php elseif (is_archive()) : ?>
54 54
 
55
-	<div id="espresso-event-list-header-dv-<?php echo $post->ID;?>" class="espresso-event-header-dv">
56
-		<?php espresso_get_template_part( 'content', 'espresso_events-thumbnail' ); ?>
57
-		<?php espresso_get_template_part( 'content', 'espresso_events-header' ); ?>
55
+	<div id="espresso-event-list-header-dv-<?php echo $post->ID; ?>" class="espresso-event-header-dv">
56
+		<?php espresso_get_template_part('content', 'espresso_events-thumbnail'); ?>
57
+		<?php espresso_get_template_part('content', 'espresso_events-header'); ?>
58 58
 	</div>
59 59
 
60 60
 	<div class="espresso-event-list-wrapper-dv">
@@ -69,5 +69,5 @@  discard block
 block discarded – undo
69 69
 
70 70
 </article>
71 71
 <!-- #post -->
72
-<?php do_action( 'AHEE_event_details_after_post', $post );
72
+<?php do_action('AHEE_event_details_after_post', $post);
73 73
 
Please login to merge, or discard this patch.