@@ -17,261 +17,261 @@ |
||
| 17 | 17 | class EE_Log |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - private $_logs_folder = ''; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - private $_log_file = ''; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - private $_log = ''; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private $_debug_file = ''; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - private $_debug_log = ''; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Used for remote logging |
|
| 47 | - * |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 50 | - private $_remote_logging_url = ''; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - private $_remote_log = ''; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var EE_Log |
|
| 59 | - */ |
|
| 60 | - private static $_instance; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @return EE_Log |
|
| 65 | - */ |
|
| 66 | - public static function instance() |
|
| 67 | - { |
|
| 68 | - if (! self::$_instance instanceof EE_Log) { |
|
| 69 | - self::$_instance = new self(); |
|
| 70 | - } |
|
| 71 | - return self::$_instance; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @access private |
|
| 76 | - * @return EE_Log |
|
| 77 | - */ |
|
| 78 | - private function __construct() |
|
| 79 | - { |
|
| 80 | - |
|
| 81 | - if (! EE_Registry::instance()->CFG->admin->use_full_logging |
|
| 82 | - && ! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'; |
|
| 87 | - $this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name(); |
|
| 88 | - $this->_log = ''; |
|
| 89 | - $this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name(); |
|
| 90 | - $this->_debug_log = ''; |
|
| 91 | - $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url; |
|
| 92 | - $this->_remote_log = ''; |
|
| 93 | - |
|
| 94 | - add_action('admin_init', array($this, 'verify_filesystem'), -10); |
|
| 95 | - add_action('AHEE_log', array($this, 'log'), 10, 4); |
|
| 96 | - if (EE_Registry::instance()->CFG->admin->use_full_logging) { |
|
| 97 | - add_action('shutdown', array($this, 'write_log'), 9999); |
|
| 98 | - // if WP_DEBUG |
|
| 99 | - add_action('shutdown', array($this, 'write_debug'), 9999); |
|
| 100 | - } |
|
| 101 | - if (EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
| 102 | - add_action('shutdown', array($this, 'send_log'), 9999); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * verify_filesystem |
|
| 109 | - * tests that the required files and folders exist and are writable |
|
| 110 | - * |
|
| 111 | - */ |
|
| 112 | - public function verify_filesystem() |
|
| 113 | - { |
|
| 114 | - try { |
|
| 115 | - EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file); |
|
| 116 | - EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file); |
|
| 117 | - EEH_File::add_htaccess_deny_from_all($this->_logs_folder); |
|
| 118 | - } catch (EE_Error $e) { |
|
| 119 | - EE_Error::add_error( |
|
| 120 | - sprintf( |
|
| 121 | - __('Event Espresso logging could not be setup because: %s', 'event_espresso'), |
|
| 122 | - ' ' . $e->getMessage() |
|
| 123 | - ), |
|
| 124 | - __FILE__, |
|
| 125 | - __FUNCTION__, |
|
| 126 | - __LINE__ |
|
| 127 | - ); |
|
| 128 | - return; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * _format_message |
|
| 135 | - * makes yer log entries look all purdy |
|
| 136 | - * |
|
| 137 | - * @param string $file |
|
| 138 | - * @param string $function |
|
| 139 | - * @param string $message |
|
| 140 | - * @param string $type |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - private function _format_message($file = '', $function = '', $message = '', $type = '') |
|
| 144 | - { |
|
| 145 | - $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
| 146 | - $msg .= '[' . current_time('mysql') . '] '; |
|
| 147 | - $msg .= ! empty($file) ? basename($file) : ''; |
|
| 148 | - $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
|
| 149 | - $msg .= ! empty($function) ? $function . '()' : ''; |
|
| 150 | - $msg .= PHP_EOL; |
|
| 151 | - $type = ! empty($type) ? $type : 'log message'; |
|
| 152 | - $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
| 153 | - return $msg; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * log |
|
| 159 | - * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the |
|
| 160 | - * EE_Log::write_log() callback |
|
| 161 | - * |
|
| 162 | - * @param string $file |
|
| 163 | - * @param string $function |
|
| 164 | - * @param string $message |
|
| 165 | - * @param string $type |
|
| 166 | - */ |
|
| 167 | - public function log($file = '', $function = '', $message = '', $type = '') |
|
| 168 | - { |
|
| 169 | - $this->_log .= $this->_format_message($file, $function, $message, $type); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * write_log |
|
| 175 | - * appends the results of the 'AHEE_log' filter to the espresso log file |
|
| 176 | - */ |
|
| 177 | - public function write_log() |
|
| 178 | - { |
|
| 179 | - try { |
|
| 180 | - // get existing log file and append new log info |
|
| 181 | - $this->_log = EEH_File::get_file_contents($this->_logs_folder . $this->_log_file) . $this->_log; |
|
| 182 | - EEH_File::write_to_file($this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log'); |
|
| 183 | - } catch (EE_Error $e) { |
|
| 184 | - EE_Error::add_error( |
|
| 185 | - sprintf( |
|
| 186 | - __('Could not write to the Event Espresso log file because: %s', 'event_espresso'), |
|
| 187 | - ' ' . $e->getMessage() |
|
| 188 | - ), |
|
| 189 | - __FILE__, |
|
| 190 | - __FUNCTION__, |
|
| 191 | - __LINE__ |
|
| 192 | - ); |
|
| 193 | - return; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * send_log |
|
| 200 | - * sends the espresso log to a remote URL via a PHP cURL request |
|
| 201 | - */ |
|
| 202 | - public function send_log() |
|
| 203 | - { |
|
| 204 | - |
|
| 205 | - if (empty($this->_remote_logging_url)) { |
|
| 206 | - return; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - $data = 'domain=' . $_SERVER['HTTP_HOST']; |
|
| 210 | - $data .= '&ip=' . $_SERVER['SERVER_ADDR']; |
|
| 211 | - $data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE']; |
|
| 212 | - $data .= '&time=' . time(); |
|
| 213 | - $data .= '&remote_log=' . $this->_log; |
|
| 214 | - $data .= '&request_array=' . json_encode($_REQUEST); |
|
| 215 | - $data .= '&action=save'; |
|
| 216 | - |
|
| 217 | - if (defined('EELOGGING_PASS')) { |
|
| 218 | - $data .= '&pass=' . EELOGGING_PASS; |
|
| 219 | - } |
|
| 220 | - if (defined('EELOGGING_KEY')) { |
|
| 221 | - $data .= '&key=' . EELOGGING_KEY; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $c = curl_init($this->_remote_logging_url); |
|
| 225 | - curl_setopt($c, CURLOPT_POST, true); |
|
| 226 | - curl_setopt($c, CURLOPT_POSTFIELDS, $data); |
|
| 227 | - curl_setopt($c, CURLOPT_RETURNTRANSFER, true); |
|
| 228 | - curl_exec($c); |
|
| 229 | - curl_close($c); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * write_debug |
|
| 235 | - * writes the contents of the current request's $_GET and $_POST arrays to a log file. |
|
| 236 | - * previous entries are overwritten |
|
| 237 | - */ |
|
| 238 | - public function write_debug() |
|
| 239 | - { |
|
| 240 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 241 | - $this->_debug_log = ''; |
|
| 242 | - foreach ($_GET as $key => $value) { |
|
| 243 | - $this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
| 244 | - } |
|
| 245 | - foreach ($_POST as $key => $value) { |
|
| 246 | - $this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
| 247 | - } |
|
| 248 | - try { |
|
| 249 | - EEH_File::write_to_file( |
|
| 250 | - $this->_logs_folder . $this->_debug_file, |
|
| 251 | - $this->_debug_log, |
|
| 252 | - 'Event Espresso Debug Log' |
|
| 253 | - ); |
|
| 254 | - } catch (EE_Error $e) { |
|
| 255 | - EE_Error::add_error( |
|
| 256 | - sprintf( |
|
| 257 | - __('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'), |
|
| 258 | - ' ' . $e->getMessage() |
|
| 259 | - ), |
|
| 260 | - __FILE__, |
|
| 261 | - __FUNCTION__, |
|
| 262 | - __LINE__ |
|
| 263 | - ); |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * __clone |
|
| 272 | - */ |
|
| 273 | - public function __clone() |
|
| 274 | - { |
|
| 275 | - trigger_error(__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR); |
|
| 276 | - } |
|
| 20 | + /** |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + private $_logs_folder = ''; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + private $_log_file = ''; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + private $_log = ''; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private $_debug_file = ''; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + private $_debug_log = ''; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Used for remote logging |
|
| 47 | + * |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | + private $_remote_logging_url = ''; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + private $_remote_log = ''; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var EE_Log |
|
| 59 | + */ |
|
| 60 | + private static $_instance; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @return EE_Log |
|
| 65 | + */ |
|
| 66 | + public static function instance() |
|
| 67 | + { |
|
| 68 | + if (! self::$_instance instanceof EE_Log) { |
|
| 69 | + self::$_instance = new self(); |
|
| 70 | + } |
|
| 71 | + return self::$_instance; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @access private |
|
| 76 | + * @return EE_Log |
|
| 77 | + */ |
|
| 78 | + private function __construct() |
|
| 79 | + { |
|
| 80 | + |
|
| 81 | + if (! EE_Registry::instance()->CFG->admin->use_full_logging |
|
| 82 | + && ! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'; |
|
| 87 | + $this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name(); |
|
| 88 | + $this->_log = ''; |
|
| 89 | + $this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name(); |
|
| 90 | + $this->_debug_log = ''; |
|
| 91 | + $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url; |
|
| 92 | + $this->_remote_log = ''; |
|
| 93 | + |
|
| 94 | + add_action('admin_init', array($this, 'verify_filesystem'), -10); |
|
| 95 | + add_action('AHEE_log', array($this, 'log'), 10, 4); |
|
| 96 | + if (EE_Registry::instance()->CFG->admin->use_full_logging) { |
|
| 97 | + add_action('shutdown', array($this, 'write_log'), 9999); |
|
| 98 | + // if WP_DEBUG |
|
| 99 | + add_action('shutdown', array($this, 'write_debug'), 9999); |
|
| 100 | + } |
|
| 101 | + if (EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
| 102 | + add_action('shutdown', array($this, 'send_log'), 9999); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * verify_filesystem |
|
| 109 | + * tests that the required files and folders exist and are writable |
|
| 110 | + * |
|
| 111 | + */ |
|
| 112 | + public function verify_filesystem() |
|
| 113 | + { |
|
| 114 | + try { |
|
| 115 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file); |
|
| 116 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file); |
|
| 117 | + EEH_File::add_htaccess_deny_from_all($this->_logs_folder); |
|
| 118 | + } catch (EE_Error $e) { |
|
| 119 | + EE_Error::add_error( |
|
| 120 | + sprintf( |
|
| 121 | + __('Event Espresso logging could not be setup because: %s', 'event_espresso'), |
|
| 122 | + ' ' . $e->getMessage() |
|
| 123 | + ), |
|
| 124 | + __FILE__, |
|
| 125 | + __FUNCTION__, |
|
| 126 | + __LINE__ |
|
| 127 | + ); |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * _format_message |
|
| 135 | + * makes yer log entries look all purdy |
|
| 136 | + * |
|
| 137 | + * @param string $file |
|
| 138 | + * @param string $function |
|
| 139 | + * @param string $message |
|
| 140 | + * @param string $type |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + private function _format_message($file = '', $function = '', $message = '', $type = '') |
|
| 144 | + { |
|
| 145 | + $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
| 146 | + $msg .= '[' . current_time('mysql') . '] '; |
|
| 147 | + $msg .= ! empty($file) ? basename($file) : ''; |
|
| 148 | + $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
|
| 149 | + $msg .= ! empty($function) ? $function . '()' : ''; |
|
| 150 | + $msg .= PHP_EOL; |
|
| 151 | + $type = ! empty($type) ? $type : 'log message'; |
|
| 152 | + $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
| 153 | + return $msg; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * log |
|
| 159 | + * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the |
|
| 160 | + * EE_Log::write_log() callback |
|
| 161 | + * |
|
| 162 | + * @param string $file |
|
| 163 | + * @param string $function |
|
| 164 | + * @param string $message |
|
| 165 | + * @param string $type |
|
| 166 | + */ |
|
| 167 | + public function log($file = '', $function = '', $message = '', $type = '') |
|
| 168 | + { |
|
| 169 | + $this->_log .= $this->_format_message($file, $function, $message, $type); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * write_log |
|
| 175 | + * appends the results of the 'AHEE_log' filter to the espresso log file |
|
| 176 | + */ |
|
| 177 | + public function write_log() |
|
| 178 | + { |
|
| 179 | + try { |
|
| 180 | + // get existing log file and append new log info |
|
| 181 | + $this->_log = EEH_File::get_file_contents($this->_logs_folder . $this->_log_file) . $this->_log; |
|
| 182 | + EEH_File::write_to_file($this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log'); |
|
| 183 | + } catch (EE_Error $e) { |
|
| 184 | + EE_Error::add_error( |
|
| 185 | + sprintf( |
|
| 186 | + __('Could not write to the Event Espresso log file because: %s', 'event_espresso'), |
|
| 187 | + ' ' . $e->getMessage() |
|
| 188 | + ), |
|
| 189 | + __FILE__, |
|
| 190 | + __FUNCTION__, |
|
| 191 | + __LINE__ |
|
| 192 | + ); |
|
| 193 | + return; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * send_log |
|
| 200 | + * sends the espresso log to a remote URL via a PHP cURL request |
|
| 201 | + */ |
|
| 202 | + public function send_log() |
|
| 203 | + { |
|
| 204 | + |
|
| 205 | + if (empty($this->_remote_logging_url)) { |
|
| 206 | + return; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + $data = 'domain=' . $_SERVER['HTTP_HOST']; |
|
| 210 | + $data .= '&ip=' . $_SERVER['SERVER_ADDR']; |
|
| 211 | + $data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE']; |
|
| 212 | + $data .= '&time=' . time(); |
|
| 213 | + $data .= '&remote_log=' . $this->_log; |
|
| 214 | + $data .= '&request_array=' . json_encode($_REQUEST); |
|
| 215 | + $data .= '&action=save'; |
|
| 216 | + |
|
| 217 | + if (defined('EELOGGING_PASS')) { |
|
| 218 | + $data .= '&pass=' . EELOGGING_PASS; |
|
| 219 | + } |
|
| 220 | + if (defined('EELOGGING_KEY')) { |
|
| 221 | + $data .= '&key=' . EELOGGING_KEY; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $c = curl_init($this->_remote_logging_url); |
|
| 225 | + curl_setopt($c, CURLOPT_POST, true); |
|
| 226 | + curl_setopt($c, CURLOPT_POSTFIELDS, $data); |
|
| 227 | + curl_setopt($c, CURLOPT_RETURNTRANSFER, true); |
|
| 228 | + curl_exec($c); |
|
| 229 | + curl_close($c); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * write_debug |
|
| 235 | + * writes the contents of the current request's $_GET and $_POST arrays to a log file. |
|
| 236 | + * previous entries are overwritten |
|
| 237 | + */ |
|
| 238 | + public function write_debug() |
|
| 239 | + { |
|
| 240 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 241 | + $this->_debug_log = ''; |
|
| 242 | + foreach ($_GET as $key => $value) { |
|
| 243 | + $this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
| 244 | + } |
|
| 245 | + foreach ($_POST as $key => $value) { |
|
| 246 | + $this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
| 247 | + } |
|
| 248 | + try { |
|
| 249 | + EEH_File::write_to_file( |
|
| 250 | + $this->_logs_folder . $this->_debug_file, |
|
| 251 | + $this->_debug_log, |
|
| 252 | + 'Event Espresso Debug Log' |
|
| 253 | + ); |
|
| 254 | + } catch (EE_Error $e) { |
|
| 255 | + EE_Error::add_error( |
|
| 256 | + sprintf( |
|
| 257 | + __('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'), |
|
| 258 | + ' ' . $e->getMessage() |
|
| 259 | + ), |
|
| 260 | + __FILE__, |
|
| 261 | + __FUNCTION__, |
|
| 262 | + __LINE__ |
|
| 263 | + ); |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * __clone |
|
| 272 | + */ |
|
| 273 | + public function __clone() |
|
| 274 | + { |
|
| 275 | + trigger_error(__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR); |
|
| 276 | + } |
|
| 277 | 277 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public static function instance() |
| 67 | 67 | { |
| 68 | - if (! self::$_instance instanceof EE_Log) { |
|
| 68 | + if ( ! self::$_instance instanceof EE_Log) { |
|
| 69 | 69 | self::$_instance = new self(); |
| 70 | 70 | } |
| 71 | 71 | return self::$_instance; |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | private function __construct() |
| 79 | 79 | { |
| 80 | 80 | |
| 81 | - if (! EE_Registry::instance()->CFG->admin->use_full_logging |
|
| 81 | + if ( ! EE_Registry::instance()->CFG->admin->use_full_logging |
|
| 82 | 82 | && ! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'; |
|
| 86 | + $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR.'logs/'; |
|
| 87 | 87 | $this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name(); |
| 88 | 88 | $this->_log = ''; |
| 89 | 89 | $this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name(); |
@@ -112,14 +112,14 @@ discard block |
||
| 112 | 112 | public function verify_filesystem() |
| 113 | 113 | { |
| 114 | 114 | try { |
| 115 | - EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file); |
|
| 116 | - EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file); |
|
| 115 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder.$this->_log_file); |
|
| 116 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder.$this->_debug_file); |
|
| 117 | 117 | EEH_File::add_htaccess_deny_from_all($this->_logs_folder); |
| 118 | 118 | } catch (EE_Error $e) { |
| 119 | 119 | EE_Error::add_error( |
| 120 | 120 | sprintf( |
| 121 | 121 | __('Event Espresso logging could not be setup because: %s', 'event_espresso'), |
| 122 | - ' ' . $e->getMessage() |
|
| 122 | + ' '.$e->getMessage() |
|
| 123 | 123 | ), |
| 124 | 124 | __FILE__, |
| 125 | 125 | __FUNCTION__, |
@@ -142,14 +142,14 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | private function _format_message($file = '', $function = '', $message = '', $type = '') |
| 144 | 144 | { |
| 145 | - $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
| 146 | - $msg .= '[' . current_time('mysql') . '] '; |
|
| 145 | + $msg = '----------------------------------------------------------------------------------------'.PHP_EOL; |
|
| 146 | + $msg .= '['.current_time('mysql').'] '; |
|
| 147 | 147 | $msg .= ! empty($file) ? basename($file) : ''; |
| 148 | 148 | $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
| 149 | - $msg .= ! empty($function) ? $function . '()' : ''; |
|
| 149 | + $msg .= ! empty($function) ? $function.'()' : ''; |
|
| 150 | 150 | $msg .= PHP_EOL; |
| 151 | 151 | $type = ! empty($type) ? $type : 'log message'; |
| 152 | - $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
| 152 | + $msg .= ! empty($message) ? "\t".'['.$type.'] '.$message.PHP_EOL : ''; |
|
| 153 | 153 | return $msg; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -178,13 +178,13 @@ discard block |
||
| 178 | 178 | { |
| 179 | 179 | try { |
| 180 | 180 | // get existing log file and append new log info |
| 181 | - $this->_log = EEH_File::get_file_contents($this->_logs_folder . $this->_log_file) . $this->_log; |
|
| 182 | - EEH_File::write_to_file($this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log'); |
|
| 181 | + $this->_log = EEH_File::get_file_contents($this->_logs_folder.$this->_log_file).$this->_log; |
|
| 182 | + EEH_File::write_to_file($this->_logs_folder.$this->_log_file, $this->_log, 'Event Espresso Log'); |
|
| 183 | 183 | } catch (EE_Error $e) { |
| 184 | 184 | EE_Error::add_error( |
| 185 | 185 | sprintf( |
| 186 | 186 | __('Could not write to the Event Espresso log file because: %s', 'event_espresso'), |
| 187 | - ' ' . $e->getMessage() |
|
| 187 | + ' '.$e->getMessage() |
|
| 188 | 188 | ), |
| 189 | 189 | __FILE__, |
| 190 | 190 | __FUNCTION__, |
@@ -206,19 +206,19 @@ discard block |
||
| 206 | 206 | return; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - $data = 'domain=' . $_SERVER['HTTP_HOST']; |
|
| 210 | - $data .= '&ip=' . $_SERVER['SERVER_ADDR']; |
|
| 211 | - $data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE']; |
|
| 212 | - $data .= '&time=' . time(); |
|
| 213 | - $data .= '&remote_log=' . $this->_log; |
|
| 214 | - $data .= '&request_array=' . json_encode($_REQUEST); |
|
| 209 | + $data = 'domain='.$_SERVER['HTTP_HOST']; |
|
| 210 | + $data .= '&ip='.$_SERVER['SERVER_ADDR']; |
|
| 211 | + $data .= '&server_type='.$_SERVER['SERVER_SOFTWARE']; |
|
| 212 | + $data .= '&time='.time(); |
|
| 213 | + $data .= '&remote_log='.$this->_log; |
|
| 214 | + $data .= '&request_array='.json_encode($_REQUEST); |
|
| 215 | 215 | $data .= '&action=save'; |
| 216 | 216 | |
| 217 | 217 | if (defined('EELOGGING_PASS')) { |
| 218 | - $data .= '&pass=' . EELOGGING_PASS; |
|
| 218 | + $data .= '&pass='.EELOGGING_PASS; |
|
| 219 | 219 | } |
| 220 | 220 | if (defined('EELOGGING_KEY')) { |
| 221 | - $data .= '&key=' . EELOGGING_KEY; |
|
| 221 | + $data .= '&key='.EELOGGING_KEY; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | $c = curl_init($this->_remote_logging_url); |
@@ -240,14 +240,14 @@ discard block |
||
| 240 | 240 | if (defined('WP_DEBUG') && WP_DEBUG) { |
| 241 | 241 | $this->_debug_log = ''; |
| 242 | 242 | foreach ($_GET as $key => $value) { |
| 243 | - $this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
| 243 | + $this->_debug_log .= '$_GET["'.$key.'"] = "'.serialize($value).'"'.PHP_EOL; |
|
| 244 | 244 | } |
| 245 | 245 | foreach ($_POST as $key => $value) { |
| 246 | - $this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
| 246 | + $this->_debug_log .= '$_POST["'.$key.'"] = "'.serialize($value).'"'.PHP_EOL; |
|
| 247 | 247 | } |
| 248 | 248 | try { |
| 249 | 249 | EEH_File::write_to_file( |
| 250 | - $this->_logs_folder . $this->_debug_file, |
|
| 250 | + $this->_logs_folder.$this->_debug_file, |
|
| 251 | 251 | $this->_debug_log, |
| 252 | 252 | 'Event Espresso Debug Log' |
| 253 | 253 | ); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | EE_Error::add_error( |
| 256 | 256 | sprintf( |
| 257 | 257 | __('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'), |
| 258 | - ' ' . $e->getMessage() |
|
| 258 | + ' '.$e->getMessage() |
|
| 259 | 259 | ), |
| 260 | 260 | __FILE__, |
| 261 | 261 | __FUNCTION__, |
@@ -11,670 +11,670 @@ discard block |
||
| 11 | 11 | class EEH_Debug_Tools |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * instance of the EEH_Autoloader object |
|
| 16 | - * |
|
| 17 | - * @var $_instance |
|
| 18 | - * @access private |
|
| 19 | - */ |
|
| 20 | - private static $_instance; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - protected $_memory_usage_points = array(); |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @singleton method used to instantiate class object |
|
| 31 | - * @access public |
|
| 32 | - * @return EEH_Debug_Tools |
|
| 33 | - */ |
|
| 34 | - public static function instance() |
|
| 35 | - { |
|
| 36 | - // check if class object is instantiated, and instantiated properly |
|
| 37 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 38 | - self::$_instance = new self(); |
|
| 39 | - } |
|
| 40 | - return self::$_instance; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * private class constructor |
|
| 47 | - */ |
|
| 48 | - private function __construct() |
|
| 49 | - { |
|
| 50 | - // load Kint PHP debugging library |
|
| 51 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
| 52 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 53 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 54 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 55 | - // so we've moved it to our test folder so that it is not included with production releases |
|
| 56 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 57 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
| 58 | - } |
|
| 59 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 60 | - // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 61 | - // } |
|
| 62 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 63 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 64 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 65 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * show_db_name |
|
| 72 | - * |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 75 | - public static function show_db_name() |
|
| 76 | - { |
|
| 77 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 78 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 79 | - . DB_NAME |
|
| 80 | - . '</p>'; |
|
| 81 | - } |
|
| 82 | - if (EE_DEBUG) { |
|
| 83 | - Benchmark::displayResults(); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * dump EE_Session object at bottom of page after everything else has happened |
|
| 91 | - * |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public function espresso_session_footer_dump() |
|
| 95 | - { |
|
| 96 | - if ((defined('WP_DEBUG') && WP_DEBUG) |
|
| 97 | - && ! defined('DOING_AJAX') |
|
| 98 | - && class_exists('Kint') |
|
| 99 | - && function_exists('wp_get_current_user') |
|
| 100 | - && current_user_can('update_core') |
|
| 101 | - && class_exists('EE_Registry') |
|
| 102 | - ) { |
|
| 103 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 104 | - Kint::dump(EE_Registry::instance()->SSN); |
|
| 105 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 106 | - $this->espresso_list_hooked_functions(); |
|
| 107 | - Benchmark::displayResults(); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * List All Hooked Functions |
|
| 115 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 116 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 117 | - * |
|
| 118 | - * @param string $tag |
|
| 119 | - * @return void |
|
| 120 | - */ |
|
| 121 | - public function espresso_list_hooked_functions($tag = '') |
|
| 122 | - { |
|
| 123 | - global $wp_filter; |
|
| 124 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 125 | - if ($tag) { |
|
| 126 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
| 127 | - if (! is_array($hook[ $tag ])) { |
|
| 128 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 129 | - return; |
|
| 130 | - } |
|
| 131 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 132 | - } else { |
|
| 133 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 134 | - ksort($hook); |
|
| 135 | - } |
|
| 136 | - foreach ($hook as $tag_name => $priorities) { |
|
| 137 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 138 | - ksort($priorities); |
|
| 139 | - foreach ($priorities as $priority => $function) { |
|
| 140 | - echo $priority; |
|
| 141 | - foreach ($function as $name => $properties) { |
|
| 142 | - echo "\t$name<br />"; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * registered_filter_callbacks |
|
| 152 | - * |
|
| 153 | - * @param string $hook_name |
|
| 154 | - * @return array |
|
| 155 | - */ |
|
| 156 | - public static function registered_filter_callbacks($hook_name = '') |
|
| 157 | - { |
|
| 158 | - $filters = array(); |
|
| 159 | - global $wp_filter; |
|
| 160 | - if (isset($wp_filter[ $hook_name ])) { |
|
| 161 | - $filters[ $hook_name ] = array(); |
|
| 162 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
| 163 | - $filters[ $hook_name ][ $priority ] = array(); |
|
| 164 | - foreach ($callbacks as $callback) { |
|
| 165 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - return $filters; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * captures plugin activation errors for debugging |
|
| 176 | - * |
|
| 177 | - * @return void |
|
| 178 | - * @throws EE_Error |
|
| 179 | - */ |
|
| 180 | - public static function ee_plugin_activation_errors() |
|
| 181 | - { |
|
| 182 | - if (WP_DEBUG) { |
|
| 183 | - $activation_errors = ob_get_contents(); |
|
| 184 | - if (! empty($activation_errors)) { |
|
| 185 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 186 | - } |
|
| 187 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 188 | - if (class_exists('EEH_File')) { |
|
| 189 | - try { |
|
| 190 | - EEH_File::ensure_file_exists_and_is_writable( |
|
| 191 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
| 192 | - ); |
|
| 193 | - EEH_File::write_to_file( |
|
| 194 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 195 | - $activation_errors |
|
| 196 | - ); |
|
| 197 | - } catch (EE_Error $e) { |
|
| 198 | - EE_Error::add_error( |
|
| 199 | - sprintf( |
|
| 200 | - __( |
|
| 201 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 202 | - 'event_espresso' |
|
| 203 | - ), |
|
| 204 | - $e->getMessage() |
|
| 205 | - ), |
|
| 206 | - __FILE__, |
|
| 207 | - __FUNCTION__, |
|
| 208 | - __LINE__ |
|
| 209 | - ); |
|
| 210 | - } |
|
| 211 | - } else { |
|
| 212 | - // old school attempt |
|
| 213 | - file_put_contents( |
|
| 214 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 215 | - $activation_errors |
|
| 216 | - ); |
|
| 217 | - } |
|
| 218 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 219 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 227 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 228 | - * or we want to make sure they use something the right way. |
|
| 229 | - * |
|
| 230 | - * @access public |
|
| 231 | - * @param string $function The function that was called |
|
| 232 | - * @param string $message A message explaining what has been done incorrectly |
|
| 233 | - * @param string $version The version of Event Espresso where the error was added |
|
| 234 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 235 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 236 | - * but not have any notices appear until a later version. This allows developers |
|
| 237 | - * extra time to update their code before notices appear. |
|
| 238 | - * @param int $error_type |
|
| 239 | - * @uses trigger_error() |
|
| 240 | - */ |
|
| 241 | - public function doing_it_wrong( |
|
| 242 | - $function, |
|
| 243 | - $message, |
|
| 244 | - $version, |
|
| 245 | - $applies_when = '', |
|
| 246 | - $error_type = null |
|
| 247 | - ) { |
|
| 248 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 249 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 250 | - // because we swapped the parameter order around for the last two params, |
|
| 251 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
| 252 | - if (is_int($applies_when)) { |
|
| 253 | - $error_type = $applies_when; |
|
| 254 | - $applies_when = espresso_version(); |
|
| 255 | - } |
|
| 256 | - // if not displaying notices yet, then just leave |
|
| 257 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 258 | - return; |
|
| 259 | - } |
|
| 260 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 261 | - $version = $version === null |
|
| 262 | - ? '' |
|
| 263 | - : sprintf( |
|
| 264 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 265 | - $version |
|
| 266 | - ); |
|
| 267 | - $error_message = sprintf( |
|
| 268 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 269 | - $function, |
|
| 270 | - '<strong>', |
|
| 271 | - '</strong>', |
|
| 272 | - $message, |
|
| 273 | - $version |
|
| 274 | - ); |
|
| 275 | - // don't trigger error if doing ajax, |
|
| 276 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 277 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 278 | - $error_message .= ' ' . esc_html__( |
|
| 279 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 280 | - 'event_espresso' |
|
| 281 | - ); |
|
| 282 | - $error_message .= '<ul><li>'; |
|
| 283 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 284 | - $error_message .= '</ul>'; |
|
| 285 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 286 | - // now we set this on the transient so it shows up on the next request. |
|
| 287 | - EE_Error::get_notices(false, true); |
|
| 288 | - } else { |
|
| 289 | - trigger_error($error_message, $error_type); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Logger helpers |
|
| 298 | - */ |
|
| 299 | - /** |
|
| 300 | - * debug |
|
| 301 | - * |
|
| 302 | - * @param string $class |
|
| 303 | - * @param string $func |
|
| 304 | - * @param string $line |
|
| 305 | - * @param array $info |
|
| 306 | - * @param bool $display_request |
|
| 307 | - * @param string $debug_index |
|
| 308 | - * @param string $debug_key |
|
| 309 | - * @throws EE_Error |
|
| 310 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 311 | - */ |
|
| 312 | - public static function log( |
|
| 313 | - $class = '', |
|
| 314 | - $func = '', |
|
| 315 | - $line = '', |
|
| 316 | - $info = array(), |
|
| 317 | - $display_request = false, |
|
| 318 | - $debug_index = '', |
|
| 319 | - $debug_key = 'EE_DEBUG_SPCO' |
|
| 320 | - ) { |
|
| 321 | - if (WP_DEBUG) { |
|
| 322 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 323 | - $debug_data = get_option($debug_key, array()); |
|
| 324 | - $default_data = array( |
|
| 325 | - $class => $func . '() : ' . $line, |
|
| 326 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
| 327 | - ); |
|
| 328 | - // don't serialize objects |
|
| 329 | - $info = self::strip_objects($info); |
|
| 330 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 331 | - if (! isset($debug_data[ $index ])) { |
|
| 332 | - $debug_data[ $index ] = array(); |
|
| 333 | - } |
|
| 334 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
| 335 | - update_option($debug_key, $debug_data); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * strip_objects |
|
| 343 | - * |
|
| 344 | - * @param array $info |
|
| 345 | - * @return array |
|
| 346 | - */ |
|
| 347 | - public static function strip_objects($info = array()) |
|
| 348 | - { |
|
| 349 | - foreach ($info as $key => $value) { |
|
| 350 | - if (is_array($value)) { |
|
| 351 | - $info[ $key ] = self::strip_objects($value); |
|
| 352 | - } elseif (is_object($value)) { |
|
| 353 | - $object_class = get_class($value); |
|
| 354 | - $info[ $object_class ] = array(); |
|
| 355 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 356 | - if (method_exists($value, 'ID')) { |
|
| 357 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
| 358 | - } |
|
| 359 | - if (method_exists($value, 'status')) { |
|
| 360 | - $info[ $object_class ]['status'] = $value->status(); |
|
| 361 | - } elseif (method_exists($value, 'status_ID')) { |
|
| 362 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
| 363 | - } |
|
| 364 | - unset($info[ $key ]); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - return (array) $info; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @param mixed $var |
|
| 374 | - * @param string $var_name |
|
| 375 | - * @param string $file |
|
| 376 | - * @param int|string $line |
|
| 377 | - * @param int|string $heading_tag |
|
| 378 | - * @param bool $die |
|
| 379 | - * @param string $margin |
|
| 380 | - */ |
|
| 381 | - public static function printv( |
|
| 382 | - $var, |
|
| 383 | - $var_name = '', |
|
| 384 | - $file = '', |
|
| 385 | - $line = '', |
|
| 386 | - $heading_tag = 5, |
|
| 387 | - $die = false, |
|
| 388 | - $margin = '' |
|
| 389 | - ) { |
|
| 390 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
| 391 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 392 | - $is_method = method_exists($var_name, $var); |
|
| 393 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 394 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
| 395 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
| 396 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 397 | - $result .= $is_method |
|
| 398 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 399 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 400 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
| 401 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 402 | - if ($die) { |
|
| 403 | - die($result); |
|
| 404 | - } |
|
| 405 | - echo $result; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - protected static function headingTag($heading_tag) |
|
| 410 | - { |
|
| 411 | - $heading_tag = absint($heading_tag); |
|
| 412 | - return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - protected static function headingSpacer($heading_tag) |
|
| 417 | - { |
|
| 418 | - return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
| 419 | - ? "\n" |
|
| 420 | - : ''; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - protected static function plainOutput() |
|
| 425 | - { |
|
| 426 | - return defined('EE_TESTS_DIR') |
|
| 427 | - || (defined('DOING_AJAX') && DOING_AJAX) |
|
| 428 | - || ( |
|
| 429 | - isset($_SERVER['REQUEST_URI']) |
|
| 430 | - && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
| 431 | - ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * @param string $var_name |
|
| 437 | - * @param string $heading_tag |
|
| 438 | - * @param string $margin |
|
| 439 | - * @param int $line |
|
| 440 | - * @return string |
|
| 441 | - */ |
|
| 442 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
| 443 | - { |
|
| 444 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 445 | - $heading = ''; |
|
| 446 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
| 447 | - $heading .= "\n"; |
|
| 448 | - } |
|
| 449 | - $heading .= "\n{$line}) {$var_name}"; |
|
| 450 | - return $heading; |
|
| 451 | - } |
|
| 452 | - $margin = "25px 0 0 {$margin}"; |
|
| 453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @param string $heading_tag |
|
| 460 | - * @return string |
|
| 461 | - */ |
|
| 462 | - protected static function headingX($heading_tag = 'h5') |
|
| 463 | - { |
|
| 464 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 465 | - return ''; |
|
| 466 | - } |
|
| 467 | - return '</' . $heading_tag . '>'; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * @param string $content |
|
| 474 | - * @return string |
|
| 475 | - */ |
|
| 476 | - protected static function grey_span($content = '') |
|
| 477 | - { |
|
| 478 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 479 | - return $content; |
|
| 480 | - } |
|
| 481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @param string $file |
|
| 488 | - * @param int $line |
|
| 489 | - * @return string |
|
| 490 | - */ |
|
| 491 | - protected static function file_and_line($file, $line, $heading_tag) |
|
| 492 | - { |
|
| 493 | - if ($file === '' || $line === '') { |
|
| 494 | - return ''; |
|
| 495 | - } |
|
| 496 | - $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
| 497 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 498 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
| 499 | - return " ({$file})"; |
|
| 500 | - } |
|
| 501 | - return ''; |
|
| 502 | - } |
|
| 503 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 504 | - . $file |
|
| 505 | - . '<br />line no: ' |
|
| 506 | - . $line |
|
| 507 | - . '</span>'; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * @param string $content |
|
| 514 | - * @return string |
|
| 515 | - */ |
|
| 516 | - protected static function orange_span($content = '') |
|
| 517 | - { |
|
| 518 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 519 | - return $content; |
|
| 520 | - } |
|
| 521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * @param mixed $var |
|
| 528 | - * @return string |
|
| 529 | - */ |
|
| 530 | - protected static function pre_span($var) |
|
| 531 | - { |
|
| 532 | - ob_start(); |
|
| 533 | - var_dump($var); |
|
| 534 | - $var = ob_get_clean(); |
|
| 535 | - if (EEH_Debug_Tools::plainOutput()) { |
|
| 536 | - return $var; |
|
| 537 | - } |
|
| 538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * @param mixed $var |
|
| 545 | - * @param string $var_name |
|
| 546 | - * @param string $file |
|
| 547 | - * @param int|string $line |
|
| 548 | - * @param int|string $heading_tag |
|
| 549 | - * @param bool $die |
|
| 550 | - */ |
|
| 551 | - public static function printr( |
|
| 552 | - $var, |
|
| 553 | - $var_name = '', |
|
| 554 | - $file = '', |
|
| 555 | - $line = '', |
|
| 556 | - $heading_tag = 5, |
|
| 557 | - $die = false |
|
| 558 | - ) { |
|
| 559 | - // return; |
|
| 560 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 561 | - $margin = is_admin() ? ' 180px' : '0'; |
|
| 562 | - // $print_r = false; |
|
| 563 | - if (is_string($var)) { |
|
| 564 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 565 | - return; |
|
| 566 | - } |
|
| 567 | - if (is_object($var)) { |
|
| 568 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
| 569 | - // $print_r = true; |
|
| 570 | - } elseif (is_array($var)) { |
|
| 571 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
| 572 | - // $print_r = true; |
|
| 573 | - } elseif (is_numeric($var)) { |
|
| 574 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 575 | - } elseif ($var === null) { |
|
| 576 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
| 577 | - } |
|
| 578 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 579 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
| 580 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
| 581 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 583 | - EEH_Debug_Tools::pre_span($var) |
|
| 584 | - ); |
|
| 585 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
| 586 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 587 | - if ($die) { |
|
| 588 | - die($result); |
|
| 589 | - } |
|
| 590 | - echo $result; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /******************** deprecated ********************/ |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * @deprecated 4.9.39.rc.034 |
|
| 601 | - */ |
|
| 602 | - public function reset_times() |
|
| 603 | - { |
|
| 604 | - Benchmark::resetTimes(); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * @deprecated 4.9.39.rc.034 |
|
| 611 | - * @param null $timer_name |
|
| 612 | - */ |
|
| 613 | - public function start_timer($timer_name = null) |
|
| 614 | - { |
|
| 615 | - Benchmark::startTimer($timer_name); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * @deprecated 4.9.39.rc.034 |
|
| 622 | - * @param string $timer_name |
|
| 623 | - */ |
|
| 624 | - public function stop_timer($timer_name = '') |
|
| 625 | - { |
|
| 626 | - Benchmark::stopTimer($timer_name); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * @deprecated 4.9.39.rc.034 |
|
| 633 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 634 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 635 | - * @return void |
|
| 636 | - */ |
|
| 637 | - public function measure_memory($label, $output_now = false) |
|
| 638 | - { |
|
| 639 | - Benchmark::measureMemory($label, $output_now); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * @deprecated 4.9.39.rc.034 |
|
| 646 | - * @param int $size |
|
| 647 | - * @return string |
|
| 648 | - */ |
|
| 649 | - public function convert($size) |
|
| 650 | - { |
|
| 651 | - return Benchmark::convert($size); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * @deprecated 4.9.39.rc.034 |
|
| 658 | - * @param bool $output_now |
|
| 659 | - * @return string |
|
| 660 | - */ |
|
| 661 | - public function show_times($output_now = true) |
|
| 662 | - { |
|
| 663 | - return Benchmark::displayResults($output_now); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * @deprecated 4.9.39.rc.034 |
|
| 670 | - * @param string $timer_name |
|
| 671 | - * @param float $total_time |
|
| 672 | - * @return string |
|
| 673 | - */ |
|
| 674 | - public function format_time($timer_name, $total_time) |
|
| 675 | - { |
|
| 676 | - return Benchmark::formatTime($timer_name, $total_time); |
|
| 677 | - } |
|
| 14 | + /** |
|
| 15 | + * instance of the EEH_Autoloader object |
|
| 16 | + * |
|
| 17 | + * @var $_instance |
|
| 18 | + * @access private |
|
| 19 | + */ |
|
| 20 | + private static $_instance; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + protected $_memory_usage_points = array(); |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @singleton method used to instantiate class object |
|
| 31 | + * @access public |
|
| 32 | + * @return EEH_Debug_Tools |
|
| 33 | + */ |
|
| 34 | + public static function instance() |
|
| 35 | + { |
|
| 36 | + // check if class object is instantiated, and instantiated properly |
|
| 37 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 38 | + self::$_instance = new self(); |
|
| 39 | + } |
|
| 40 | + return self::$_instance; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * private class constructor |
|
| 47 | + */ |
|
| 48 | + private function __construct() |
|
| 49 | + { |
|
| 50 | + // load Kint PHP debugging library |
|
| 51 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
| 52 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 53 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 54 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 55 | + // so we've moved it to our test folder so that it is not included with production releases |
|
| 56 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 57 | + require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
| 58 | + } |
|
| 59 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 60 | + // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 61 | + // } |
|
| 62 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 63 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 64 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 65 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * show_db_name |
|
| 72 | + * |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | + public static function show_db_name() |
|
| 76 | + { |
|
| 77 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 78 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 79 | + . DB_NAME |
|
| 80 | + . '</p>'; |
|
| 81 | + } |
|
| 82 | + if (EE_DEBUG) { |
|
| 83 | + Benchmark::displayResults(); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * dump EE_Session object at bottom of page after everything else has happened |
|
| 91 | + * |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public function espresso_session_footer_dump() |
|
| 95 | + { |
|
| 96 | + if ((defined('WP_DEBUG') && WP_DEBUG) |
|
| 97 | + && ! defined('DOING_AJAX') |
|
| 98 | + && class_exists('Kint') |
|
| 99 | + && function_exists('wp_get_current_user') |
|
| 100 | + && current_user_can('update_core') |
|
| 101 | + && class_exists('EE_Registry') |
|
| 102 | + ) { |
|
| 103 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 104 | + Kint::dump(EE_Registry::instance()->SSN); |
|
| 105 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 106 | + $this->espresso_list_hooked_functions(); |
|
| 107 | + Benchmark::displayResults(); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * List All Hooked Functions |
|
| 115 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 116 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 117 | + * |
|
| 118 | + * @param string $tag |
|
| 119 | + * @return void |
|
| 120 | + */ |
|
| 121 | + public function espresso_list_hooked_functions($tag = '') |
|
| 122 | + { |
|
| 123 | + global $wp_filter; |
|
| 124 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 125 | + if ($tag) { |
|
| 126 | + $hook[ $tag ] = $wp_filter[ $tag ]; |
|
| 127 | + if (! is_array($hook[ $tag ])) { |
|
| 128 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 129 | + return; |
|
| 130 | + } |
|
| 131 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 132 | + } else { |
|
| 133 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 134 | + ksort($hook); |
|
| 135 | + } |
|
| 136 | + foreach ($hook as $tag_name => $priorities) { |
|
| 137 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 138 | + ksort($priorities); |
|
| 139 | + foreach ($priorities as $priority => $function) { |
|
| 140 | + echo $priority; |
|
| 141 | + foreach ($function as $name => $properties) { |
|
| 142 | + echo "\t$name<br />"; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * registered_filter_callbacks |
|
| 152 | + * |
|
| 153 | + * @param string $hook_name |
|
| 154 | + * @return array |
|
| 155 | + */ |
|
| 156 | + public static function registered_filter_callbacks($hook_name = '') |
|
| 157 | + { |
|
| 158 | + $filters = array(); |
|
| 159 | + global $wp_filter; |
|
| 160 | + if (isset($wp_filter[ $hook_name ])) { |
|
| 161 | + $filters[ $hook_name ] = array(); |
|
| 162 | + foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
| 163 | + $filters[ $hook_name ][ $priority ] = array(); |
|
| 164 | + foreach ($callbacks as $callback) { |
|
| 165 | + $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + return $filters; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * captures plugin activation errors for debugging |
|
| 176 | + * |
|
| 177 | + * @return void |
|
| 178 | + * @throws EE_Error |
|
| 179 | + */ |
|
| 180 | + public static function ee_plugin_activation_errors() |
|
| 181 | + { |
|
| 182 | + if (WP_DEBUG) { |
|
| 183 | + $activation_errors = ob_get_contents(); |
|
| 184 | + if (! empty($activation_errors)) { |
|
| 185 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 186 | + } |
|
| 187 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 188 | + if (class_exists('EEH_File')) { |
|
| 189 | + try { |
|
| 190 | + EEH_File::ensure_file_exists_and_is_writable( |
|
| 191 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
| 192 | + ); |
|
| 193 | + EEH_File::write_to_file( |
|
| 194 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 195 | + $activation_errors |
|
| 196 | + ); |
|
| 197 | + } catch (EE_Error $e) { |
|
| 198 | + EE_Error::add_error( |
|
| 199 | + sprintf( |
|
| 200 | + __( |
|
| 201 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 202 | + 'event_espresso' |
|
| 203 | + ), |
|
| 204 | + $e->getMessage() |
|
| 205 | + ), |
|
| 206 | + __FILE__, |
|
| 207 | + __FUNCTION__, |
|
| 208 | + __LINE__ |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | + } else { |
|
| 212 | + // old school attempt |
|
| 213 | + file_put_contents( |
|
| 214 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 215 | + $activation_errors |
|
| 216 | + ); |
|
| 217 | + } |
|
| 218 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 219 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 227 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 228 | + * or we want to make sure they use something the right way. |
|
| 229 | + * |
|
| 230 | + * @access public |
|
| 231 | + * @param string $function The function that was called |
|
| 232 | + * @param string $message A message explaining what has been done incorrectly |
|
| 233 | + * @param string $version The version of Event Espresso where the error was added |
|
| 234 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 235 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 236 | + * but not have any notices appear until a later version. This allows developers |
|
| 237 | + * extra time to update their code before notices appear. |
|
| 238 | + * @param int $error_type |
|
| 239 | + * @uses trigger_error() |
|
| 240 | + */ |
|
| 241 | + public function doing_it_wrong( |
|
| 242 | + $function, |
|
| 243 | + $message, |
|
| 244 | + $version, |
|
| 245 | + $applies_when = '', |
|
| 246 | + $error_type = null |
|
| 247 | + ) { |
|
| 248 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 249 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 250 | + // because we swapped the parameter order around for the last two params, |
|
| 251 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
| 252 | + if (is_int($applies_when)) { |
|
| 253 | + $error_type = $applies_when; |
|
| 254 | + $applies_when = espresso_version(); |
|
| 255 | + } |
|
| 256 | + // if not displaying notices yet, then just leave |
|
| 257 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 258 | + return; |
|
| 259 | + } |
|
| 260 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 261 | + $version = $version === null |
|
| 262 | + ? '' |
|
| 263 | + : sprintf( |
|
| 264 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 265 | + $version |
|
| 266 | + ); |
|
| 267 | + $error_message = sprintf( |
|
| 268 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 269 | + $function, |
|
| 270 | + '<strong>', |
|
| 271 | + '</strong>', |
|
| 272 | + $message, |
|
| 273 | + $version |
|
| 274 | + ); |
|
| 275 | + // don't trigger error if doing ajax, |
|
| 276 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 277 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 278 | + $error_message .= ' ' . esc_html__( |
|
| 279 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 280 | + 'event_espresso' |
|
| 281 | + ); |
|
| 282 | + $error_message .= '<ul><li>'; |
|
| 283 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 284 | + $error_message .= '</ul>'; |
|
| 285 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 286 | + // now we set this on the transient so it shows up on the next request. |
|
| 287 | + EE_Error::get_notices(false, true); |
|
| 288 | + } else { |
|
| 289 | + trigger_error($error_message, $error_type); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Logger helpers |
|
| 298 | + */ |
|
| 299 | + /** |
|
| 300 | + * debug |
|
| 301 | + * |
|
| 302 | + * @param string $class |
|
| 303 | + * @param string $func |
|
| 304 | + * @param string $line |
|
| 305 | + * @param array $info |
|
| 306 | + * @param bool $display_request |
|
| 307 | + * @param string $debug_index |
|
| 308 | + * @param string $debug_key |
|
| 309 | + * @throws EE_Error |
|
| 310 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 311 | + */ |
|
| 312 | + public static function log( |
|
| 313 | + $class = '', |
|
| 314 | + $func = '', |
|
| 315 | + $line = '', |
|
| 316 | + $info = array(), |
|
| 317 | + $display_request = false, |
|
| 318 | + $debug_index = '', |
|
| 319 | + $debug_key = 'EE_DEBUG_SPCO' |
|
| 320 | + ) { |
|
| 321 | + if (WP_DEBUG) { |
|
| 322 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 323 | + $debug_data = get_option($debug_key, array()); |
|
| 324 | + $default_data = array( |
|
| 325 | + $class => $func . '() : ' . $line, |
|
| 326 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
| 327 | + ); |
|
| 328 | + // don't serialize objects |
|
| 329 | + $info = self::strip_objects($info); |
|
| 330 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 331 | + if (! isset($debug_data[ $index ])) { |
|
| 332 | + $debug_data[ $index ] = array(); |
|
| 333 | + } |
|
| 334 | + $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
| 335 | + update_option($debug_key, $debug_data); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * strip_objects |
|
| 343 | + * |
|
| 344 | + * @param array $info |
|
| 345 | + * @return array |
|
| 346 | + */ |
|
| 347 | + public static function strip_objects($info = array()) |
|
| 348 | + { |
|
| 349 | + foreach ($info as $key => $value) { |
|
| 350 | + if (is_array($value)) { |
|
| 351 | + $info[ $key ] = self::strip_objects($value); |
|
| 352 | + } elseif (is_object($value)) { |
|
| 353 | + $object_class = get_class($value); |
|
| 354 | + $info[ $object_class ] = array(); |
|
| 355 | + $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 356 | + if (method_exists($value, 'ID')) { |
|
| 357 | + $info[ $object_class ]['ID'] = $value->ID(); |
|
| 358 | + } |
|
| 359 | + if (method_exists($value, 'status')) { |
|
| 360 | + $info[ $object_class ]['status'] = $value->status(); |
|
| 361 | + } elseif (method_exists($value, 'status_ID')) { |
|
| 362 | + $info[ $object_class ]['status'] = $value->status_ID(); |
|
| 363 | + } |
|
| 364 | + unset($info[ $key ]); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + return (array) $info; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @param mixed $var |
|
| 374 | + * @param string $var_name |
|
| 375 | + * @param string $file |
|
| 376 | + * @param int|string $line |
|
| 377 | + * @param int|string $heading_tag |
|
| 378 | + * @param bool $die |
|
| 379 | + * @param string $margin |
|
| 380 | + */ |
|
| 381 | + public static function printv( |
|
| 382 | + $var, |
|
| 383 | + $var_name = '', |
|
| 384 | + $file = '', |
|
| 385 | + $line = '', |
|
| 386 | + $heading_tag = 5, |
|
| 387 | + $die = false, |
|
| 388 | + $margin = '' |
|
| 389 | + ) { |
|
| 390 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
| 391 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 392 | + $is_method = method_exists($var_name, $var); |
|
| 393 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 394 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
| 395 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
| 396 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 397 | + $result .= $is_method |
|
| 398 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 399 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 400 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
| 401 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 402 | + if ($die) { |
|
| 403 | + die($result); |
|
| 404 | + } |
|
| 405 | + echo $result; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + protected static function headingTag($heading_tag) |
|
| 410 | + { |
|
| 411 | + $heading_tag = absint($heading_tag); |
|
| 412 | + return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + protected static function headingSpacer($heading_tag) |
|
| 417 | + { |
|
| 418 | + return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
| 419 | + ? "\n" |
|
| 420 | + : ''; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + protected static function plainOutput() |
|
| 425 | + { |
|
| 426 | + return defined('EE_TESTS_DIR') |
|
| 427 | + || (defined('DOING_AJAX') && DOING_AJAX) |
|
| 428 | + || ( |
|
| 429 | + isset($_SERVER['REQUEST_URI']) |
|
| 430 | + && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
| 431 | + ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * @param string $var_name |
|
| 437 | + * @param string $heading_tag |
|
| 438 | + * @param string $margin |
|
| 439 | + * @param int $line |
|
| 440 | + * @return string |
|
| 441 | + */ |
|
| 442 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
| 443 | + { |
|
| 444 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 445 | + $heading = ''; |
|
| 446 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
| 447 | + $heading .= "\n"; |
|
| 448 | + } |
|
| 449 | + $heading .= "\n{$line}) {$var_name}"; |
|
| 450 | + return $heading; |
|
| 451 | + } |
|
| 452 | + $margin = "25px 0 0 {$margin}"; |
|
| 453 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @param string $heading_tag |
|
| 460 | + * @return string |
|
| 461 | + */ |
|
| 462 | + protected static function headingX($heading_tag = 'h5') |
|
| 463 | + { |
|
| 464 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 465 | + return ''; |
|
| 466 | + } |
|
| 467 | + return '</' . $heading_tag . '>'; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * @param string $content |
|
| 474 | + * @return string |
|
| 475 | + */ |
|
| 476 | + protected static function grey_span($content = '') |
|
| 477 | + { |
|
| 478 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 479 | + return $content; |
|
| 480 | + } |
|
| 481 | + return '<span style="color:#999">' . $content . '</span>'; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * @param string $file |
|
| 488 | + * @param int $line |
|
| 489 | + * @return string |
|
| 490 | + */ |
|
| 491 | + protected static function file_and_line($file, $line, $heading_tag) |
|
| 492 | + { |
|
| 493 | + if ($file === '' || $line === '') { |
|
| 494 | + return ''; |
|
| 495 | + } |
|
| 496 | + $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
| 497 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 498 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
| 499 | + return " ({$file})"; |
|
| 500 | + } |
|
| 501 | + return ''; |
|
| 502 | + } |
|
| 503 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 504 | + . $file |
|
| 505 | + . '<br />line no: ' |
|
| 506 | + . $line |
|
| 507 | + . '</span>'; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * @param string $content |
|
| 514 | + * @return string |
|
| 515 | + */ |
|
| 516 | + protected static function orange_span($content = '') |
|
| 517 | + { |
|
| 518 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 519 | + return $content; |
|
| 520 | + } |
|
| 521 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * @param mixed $var |
|
| 528 | + * @return string |
|
| 529 | + */ |
|
| 530 | + protected static function pre_span($var) |
|
| 531 | + { |
|
| 532 | + ob_start(); |
|
| 533 | + var_dump($var); |
|
| 534 | + $var = ob_get_clean(); |
|
| 535 | + if (EEH_Debug_Tools::plainOutput()) { |
|
| 536 | + return $var; |
|
| 537 | + } |
|
| 538 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * @param mixed $var |
|
| 545 | + * @param string $var_name |
|
| 546 | + * @param string $file |
|
| 547 | + * @param int|string $line |
|
| 548 | + * @param int|string $heading_tag |
|
| 549 | + * @param bool $die |
|
| 550 | + */ |
|
| 551 | + public static function printr( |
|
| 552 | + $var, |
|
| 553 | + $var_name = '', |
|
| 554 | + $file = '', |
|
| 555 | + $line = '', |
|
| 556 | + $heading_tag = 5, |
|
| 557 | + $die = false |
|
| 558 | + ) { |
|
| 559 | + // return; |
|
| 560 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 561 | + $margin = is_admin() ? ' 180px' : '0'; |
|
| 562 | + // $print_r = false; |
|
| 563 | + if (is_string($var)) { |
|
| 564 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 565 | + return; |
|
| 566 | + } |
|
| 567 | + if (is_object($var)) { |
|
| 568 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
| 569 | + // $print_r = true; |
|
| 570 | + } elseif (is_array($var)) { |
|
| 571 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
| 572 | + // $print_r = true; |
|
| 573 | + } elseif (is_numeric($var)) { |
|
| 574 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 575 | + } elseif ($var === null) { |
|
| 576 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
| 577 | + } |
|
| 578 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 579 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
| 580 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
| 581 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
| 582 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 583 | + EEH_Debug_Tools::pre_span($var) |
|
| 584 | + ); |
|
| 585 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
| 586 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 587 | + if ($die) { |
|
| 588 | + die($result); |
|
| 589 | + } |
|
| 590 | + echo $result; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /******************** deprecated ********************/ |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * @deprecated 4.9.39.rc.034 |
|
| 601 | + */ |
|
| 602 | + public function reset_times() |
|
| 603 | + { |
|
| 604 | + Benchmark::resetTimes(); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * @deprecated 4.9.39.rc.034 |
|
| 611 | + * @param null $timer_name |
|
| 612 | + */ |
|
| 613 | + public function start_timer($timer_name = null) |
|
| 614 | + { |
|
| 615 | + Benchmark::startTimer($timer_name); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * @deprecated 4.9.39.rc.034 |
|
| 622 | + * @param string $timer_name |
|
| 623 | + */ |
|
| 624 | + public function stop_timer($timer_name = '') |
|
| 625 | + { |
|
| 626 | + Benchmark::stopTimer($timer_name); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * @deprecated 4.9.39.rc.034 |
|
| 633 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 634 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 635 | + * @return void |
|
| 636 | + */ |
|
| 637 | + public function measure_memory($label, $output_now = false) |
|
| 638 | + { |
|
| 639 | + Benchmark::measureMemory($label, $output_now); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * @deprecated 4.9.39.rc.034 |
|
| 646 | + * @param int $size |
|
| 647 | + * @return string |
|
| 648 | + */ |
|
| 649 | + public function convert($size) |
|
| 650 | + { |
|
| 651 | + return Benchmark::convert($size); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * @deprecated 4.9.39.rc.034 |
|
| 658 | + * @param bool $output_now |
|
| 659 | + * @return string |
|
| 660 | + */ |
|
| 661 | + public function show_times($output_now = true) |
|
| 662 | + { |
|
| 663 | + return Benchmark::displayResults($output_now); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * @deprecated 4.9.39.rc.034 |
|
| 670 | + * @param string $timer_name |
|
| 671 | + * @param float $total_time |
|
| 672 | + * @return string |
|
| 673 | + */ |
|
| 674 | + public function format_time($timer_name, $total_time) |
|
| 675 | + { |
|
| 676 | + return Benchmark::formatTime($timer_name, $total_time); |
|
| 677 | + } |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | |
@@ -684,31 +684,31 @@ discard block |
||
| 684 | 684 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 685 | 685 | */ |
| 686 | 686 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
| 687 | - function dump_wp_query() |
|
| 688 | - { |
|
| 689 | - global $wp_query; |
|
| 690 | - d($wp_query); |
|
| 691 | - } |
|
| 687 | + function dump_wp_query() |
|
| 688 | + { |
|
| 689 | + global $wp_query; |
|
| 690 | + d($wp_query); |
|
| 691 | + } |
|
| 692 | 692 | } |
| 693 | 693 | /** |
| 694 | 694 | * borrowed from Kint Debugger |
| 695 | 695 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 696 | 696 | */ |
| 697 | 697 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
| 698 | - function dump_wp() |
|
| 699 | - { |
|
| 700 | - global $wp; |
|
| 701 | - d($wp); |
|
| 702 | - } |
|
| 698 | + function dump_wp() |
|
| 699 | + { |
|
| 700 | + global $wp; |
|
| 701 | + d($wp); |
|
| 702 | + } |
|
| 703 | 703 | } |
| 704 | 704 | /** |
| 705 | 705 | * borrowed from Kint Debugger |
| 706 | 706 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 707 | 707 | */ |
| 708 | 708 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
| 709 | - function dump_post() |
|
| 710 | - { |
|
| 711 | - global $post; |
|
| 712 | - d($post); |
|
| 713 | - } |
|
| 709 | + function dump_post() |
|
| 710 | + { |
|
| 711 | + global $post; |
|
| 712 | + d($post); |
|
| 713 | + } |
|
| 714 | 714 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | public static function instance() |
| 35 | 35 | { |
| 36 | 36 | // check if class object is instantiated, and instantiated properly |
| 37 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 37 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 38 | 38 | self::$_instance = new self(); |
| 39 | 39 | } |
| 40 | 40 | return self::$_instance; |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | private function __construct() |
| 49 | 49 | { |
| 50 | 50 | // load Kint PHP debugging library |
| 51 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
| 51 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php')) { |
|
| 52 | 52 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
| 53 | 53 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
| 54 | 54 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
| 55 | 55 | // so we've moved it to our test folder so that it is not included with production releases |
| 56 | 56 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
| 57 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
| 57 | + require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php'); |
|
| 58 | 58 | } |
| 59 | 59 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
| 60 | 60 | // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public static function show_db_name() |
| 76 | 76 | { |
| 77 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 77 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 78 | 78 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
| 79 | 79 | . DB_NAME |
| 80 | 80 | . '</p>'; |
@@ -123,12 +123,12 @@ discard block |
||
| 123 | 123 | global $wp_filter; |
| 124 | 124 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
| 125 | 125 | if ($tag) { |
| 126 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
| 127 | - if (! is_array($hook[ $tag ])) { |
|
| 126 | + $hook[$tag] = $wp_filter[$tag]; |
|
| 127 | + if ( ! is_array($hook[$tag])) { |
|
| 128 | 128 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 131 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
| 132 | 132 | } else { |
| 133 | 133 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
| 134 | 134 | ksort($hook); |
@@ -157,12 +157,12 @@ discard block |
||
| 157 | 157 | { |
| 158 | 158 | $filters = array(); |
| 159 | 159 | global $wp_filter; |
| 160 | - if (isset($wp_filter[ $hook_name ])) { |
|
| 161 | - $filters[ $hook_name ] = array(); |
|
| 162 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
| 163 | - $filters[ $hook_name ][ $priority ] = array(); |
|
| 160 | + if (isset($wp_filter[$hook_name])) { |
|
| 161 | + $filters[$hook_name] = array(); |
|
| 162 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 163 | + $filters[$hook_name][$priority] = array(); |
|
| 164 | 164 | foreach ($callbacks as $callback) { |
| 165 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
| 165 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -181,17 +181,17 @@ discard block |
||
| 181 | 181 | { |
| 182 | 182 | if (WP_DEBUG) { |
| 183 | 183 | $activation_errors = ob_get_contents(); |
| 184 | - if (! empty($activation_errors)) { |
|
| 185 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 184 | + if ( ! empty($activation_errors)) { |
|
| 185 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
| 186 | 186 | } |
| 187 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 187 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
| 188 | 188 | if (class_exists('EEH_File')) { |
| 189 | 189 | try { |
| 190 | 190 | EEH_File::ensure_file_exists_and_is_writable( |
| 191 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
| 191 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html' |
|
| 192 | 192 | ); |
| 193 | 193 | EEH_File::write_to_file( |
| 194 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 194 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
| 195 | 195 | $activation_errors |
| 196 | 196 | ); |
| 197 | 197 | } catch (EE_Error $e) { |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | } else { |
| 212 | 212 | // old school attempt |
| 213 | 213 | file_put_contents( |
| 214 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
| 214 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
| 215 | 215 | $activation_errors |
| 216 | 216 | ); |
| 217 | 217 | } |
| 218 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 218 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
| 219 | 219 | update_option('ee_plugin_activation_errors', $activation_errors); |
| 220 | 220 | } |
| 221 | 221 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | // don't trigger error if doing ajax, |
| 276 | 276 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
| 277 | 277 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 278 | - $error_message .= ' ' . esc_html__( |
|
| 278 | + $error_message .= ' '.esc_html__( |
|
| 279 | 279 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
| 280 | 280 | 'event_espresso' |
| 281 | 281 | ); |
@@ -319,19 +319,19 @@ discard block |
||
| 319 | 319 | $debug_key = 'EE_DEBUG_SPCO' |
| 320 | 320 | ) { |
| 321 | 321 | if (WP_DEBUG) { |
| 322 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 322 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
| 323 | 323 | $debug_data = get_option($debug_key, array()); |
| 324 | 324 | $default_data = array( |
| 325 | - $class => $func . '() : ' . $line, |
|
| 325 | + $class => $func.'() : '.$line, |
|
| 326 | 326 | 'REQ' => $display_request ? $_REQUEST : '', |
| 327 | 327 | ); |
| 328 | 328 | // don't serialize objects |
| 329 | 329 | $info = self::strip_objects($info); |
| 330 | 330 | $index = ! empty($debug_index) ? $debug_index : 0; |
| 331 | - if (! isset($debug_data[ $index ])) { |
|
| 332 | - $debug_data[ $index ] = array(); |
|
| 331 | + if ( ! isset($debug_data[$index])) { |
|
| 332 | + $debug_data[$index] = array(); |
|
| 333 | 333 | } |
| 334 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
| 334 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 335 | 335 | update_option($debug_key, $debug_data); |
| 336 | 336 | } |
| 337 | 337 | } |
@@ -348,20 +348,20 @@ discard block |
||
| 348 | 348 | { |
| 349 | 349 | foreach ($info as $key => $value) { |
| 350 | 350 | if (is_array($value)) { |
| 351 | - $info[ $key ] = self::strip_objects($value); |
|
| 351 | + $info[$key] = self::strip_objects($value); |
|
| 352 | 352 | } elseif (is_object($value)) { |
| 353 | 353 | $object_class = get_class($value); |
| 354 | - $info[ $object_class ] = array(); |
|
| 355 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 354 | + $info[$object_class] = array(); |
|
| 355 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 356 | 356 | if (method_exists($value, 'ID')) { |
| 357 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
| 357 | + $info[$object_class]['ID'] = $value->ID(); |
|
| 358 | 358 | } |
| 359 | 359 | if (method_exists($value, 'status')) { |
| 360 | - $info[ $object_class ]['status'] = $value->status(); |
|
| 360 | + $info[$object_class]['status'] = $value->status(); |
|
| 361 | 361 | } elseif (method_exists($value, 'status_ID')) { |
| 362 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
| 362 | + $info[$object_class]['status'] = $value->status_ID(); |
|
| 363 | 363 | } |
| 364 | - unset($info[ $key ]); |
|
| 364 | + unset($info[$key]); |
|
| 365 | 365 | } |
| 366 | 366 | } |
| 367 | 367 | return (array) $info; |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
| 396 | 396 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
| 397 | 397 | $result .= $is_method |
| 398 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 399 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 398 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
| 399 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
| 400 | 400 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
| 401 | 401 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
| 402 | 402 | if ($die) { |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | return $heading; |
| 451 | 451 | } |
| 452 | 452 | $margin = "25px 0 0 {$margin}"; |
| 453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 453 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | if (EEH_Debug_Tools::plainOutput()) { |
| 465 | 465 | return ''; |
| 466 | 466 | } |
| 467 | - return '</' . $heading_tag . '>'; |
|
| 467 | + return '</'.$heading_tag.'>'; |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | if (EEH_Debug_Tools::plainOutput()) { |
| 479 | 479 | return $content; |
| 480 | 480 | } |
| 481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 481 | + return '<span style="color:#999">'.$content.'</span>'; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | if (EEH_Debug_Tools::plainOutput()) { |
| 519 | 519 | return $content; |
| 520 | 520 | } |
| 521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 521 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | if (EEH_Debug_Tools::plainOutput()) { |
| 536 | 536 | return $var; |
| 537 | 537 | } |
| 538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 538 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
| 580 | 580 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
| 581 | 581 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
| 582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 582 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
| 583 | 583 | EEH_Debug_Tools::pre_span($var) |
| 584 | 584 | ); |
| 585 | 585 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
@@ -5,35 +5,35 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\services\loaders\LoaderFactory; |
| 6 | 6 | |
| 7 | 7 | if (! function_exists('espresso_get_template_part')) { |
| 8 | - /** |
|
| 9 | - * espresso_get_template_part |
|
| 10 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
| 11 | - * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
| 12 | - * |
|
| 13 | - * @param string $slug The slug name for the generic template. |
|
| 14 | - * @param string $name The name of the specialised template. |
|
| 15 | - * @return string the html output for the formatted money value |
|
| 16 | - */ |
|
| 17 | - function espresso_get_template_part($slug = null, $name = null) |
|
| 18 | - { |
|
| 19 | - EEH_Template::get_template_part($slug, $name); |
|
| 20 | - } |
|
| 8 | + /** |
|
| 9 | + * espresso_get_template_part |
|
| 10 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
| 11 | + * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
| 12 | + * |
|
| 13 | + * @param string $slug The slug name for the generic template. |
|
| 14 | + * @param string $name The name of the specialised template. |
|
| 15 | + * @return string the html output for the formatted money value |
|
| 16 | + */ |
|
| 17 | + function espresso_get_template_part($slug = null, $name = null) |
|
| 18 | + { |
|
| 19 | + EEH_Template::get_template_part($slug, $name); |
|
| 20 | + } |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | if (! function_exists('espresso_get_object_css_class')) { |
| 25 | - /** |
|
| 26 | - * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 27 | - * |
|
| 28 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 29 | - * @param string $prefix added to the beginning of the generated class |
|
| 30 | - * @param string $suffix added to the end of the generated class |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 34 | - { |
|
| 35 | - return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
| 36 | - } |
|
| 25 | + /** |
|
| 26 | + * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 27 | + * |
|
| 28 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 29 | + * @param string $prefix added to the beginning of the generated class |
|
| 30 | + * @param string $suffix added to the end of the generated class |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 34 | + { |
|
| 35 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | |
@@ -48,672 +48,672 @@ discard block |
||
| 48 | 48 | class EEH_Template |
| 49 | 49 | { |
| 50 | 50 | |
| 51 | - private static $_espresso_themes = array(); |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
| 56 | - * |
|
| 57 | - * @return boolean |
|
| 58 | - */ |
|
| 59 | - public static function is_espresso_theme() |
|
| 60 | - { |
|
| 61 | - return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 66 | - * load it's functions.php file ( if not already loaded ) |
|
| 67 | - * |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - public static function load_espresso_theme_functions() |
|
| 71 | - { |
|
| 72 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 73 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
| 74 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
| 82 | - * |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 85 | - public static function get_espresso_themes() |
|
| 86 | - { |
|
| 87 | - if (empty(EEH_Template::$_espresso_themes)) { |
|
| 88 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 89 | - if (empty($espresso_themes)) { |
|
| 90 | - return array(); |
|
| 91 | - } |
|
| 92 | - if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
| 93 | - unset($espresso_themes[ $key ]); |
|
| 94 | - } |
|
| 95 | - EEH_Template::$_espresso_themes = array(); |
|
| 96 | - foreach ($espresso_themes as $espresso_theme) { |
|
| 97 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - return EEH_Template::$_espresso_themes; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * EEH_Template::get_template_part |
|
| 106 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
| 107 | - * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
| 108 | - * filtering based off of the entire template part name |
|
| 109 | - * |
|
| 110 | - * @param string $slug The slug name for the generic template. |
|
| 111 | - * @param string $name The name of the specialised template. |
|
| 112 | - * @param array $template_args |
|
| 113 | - * @param bool $return_string |
|
| 114 | - * @return string the html output for the formatted money value |
|
| 115 | - */ |
|
| 116 | - public static function get_template_part( |
|
| 117 | - $slug = null, |
|
| 118 | - $name = null, |
|
| 119 | - $template_args = array(), |
|
| 120 | - $return_string = false |
|
| 121 | - ) { |
|
| 122 | - do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
| 123 | - $templates = array(); |
|
| 124 | - $name = (string) $name; |
|
| 125 | - if ($name != '') { |
|
| 126 | - $templates[] = "{$slug}-{$name}.php"; |
|
| 127 | - } |
|
| 128 | - // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
| 129 | - if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
| 130 | - EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * locate_template |
|
| 137 | - * locate a template file by looking in the following places, in the following order: |
|
| 138 | - * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
| 139 | - * <assumed full absolute server path> |
|
| 140 | - * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
| 141 | - * <server path up to>/wp-content/uploads/espresso/templates/ |
|
| 142 | - * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
| 143 | - * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
| 144 | - * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
| 145 | - * as soon as the template is found in one of these locations, it will be returned or loaded |
|
| 146 | - * Example: |
|
| 147 | - * You are using the WordPress Twenty Sixteen theme, |
|
| 148 | - * and you want to customize the "some-event.template.php" template, |
|
| 149 | - * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
| 150 | - * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
| 151 | - * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
| 152 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 153 | - * /relative/path/to/some-event.template.php |
|
| 154 | - * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 155 | - * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
| 156 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 157 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 158 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
| 159 | - * Had you passed an absolute path to your template that was in some other location, |
|
| 160 | - * ie: "/absolute/path/to/some-event.template.php" |
|
| 161 | - * then the search would have been : |
|
| 162 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 163 | - * /absolute/path/to/some-event.template.php |
|
| 164 | - * and stopped there upon finding it in the second location |
|
| 165 | - * |
|
| 166 | - * @param array|string $templates array of template file names including extension (or just a single string) |
|
| 167 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 168 | - * @param boolean $load whether to pass the located template path on to the |
|
| 169 | - * EEH_Template::display_template() method or simply return it |
|
| 170 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 171 | - * string |
|
| 172 | - * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
| 173 | - * generate a custom template or not. Used in places where you don't actually |
|
| 174 | - * load the template, you just want to know if there's a custom version of it. |
|
| 175 | - * @return mixed |
|
| 176 | - * @throws DomainException |
|
| 177 | - * @throws InvalidArgumentException |
|
| 178 | - * @throws InvalidDataTypeException |
|
| 179 | - * @throws InvalidInterfaceException |
|
| 180 | - */ |
|
| 181 | - public static function locate_template( |
|
| 182 | - $templates = array(), |
|
| 183 | - $template_args = array(), |
|
| 184 | - $load = true, |
|
| 185 | - $return_string = true, |
|
| 186 | - $check_if_custom = false |
|
| 187 | - ) { |
|
| 188 | - // first use WP locate_template to check for template in the current theme folder |
|
| 189 | - $template_path = locate_template($templates); |
|
| 190 | - |
|
| 191 | - if ($check_if_custom && ! empty($template_path)) { |
|
| 192 | - return true; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // not in the theme |
|
| 196 | - if (empty($template_path)) { |
|
| 197 | - // not even a template to look for ? |
|
| 198 | - if (empty($templates)) { |
|
| 199 | - // get post_type |
|
| 200 | - $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
| 201 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 202 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
| 203 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 204 | - ); |
|
| 205 | - // get array of EE Custom Post Types |
|
| 206 | - $EE_CPTs = $custom_post_types->getDefinitions(); |
|
| 207 | - // build template name based on request |
|
| 208 | - if (isset($EE_CPTs[ $post_type ])) { |
|
| 209 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
| 210 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
| 211 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - // currently active EE template theme |
|
| 215 | - $current_theme = EE_Config::get_current_theme(); |
|
| 216 | - |
|
| 217 | - // array of paths to folders that may contain templates |
|
| 218 | - $template_folder_paths = array( |
|
| 219 | - // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
| 220 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 221 | - // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
| 222 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 223 | - ); |
|
| 224 | - |
|
| 225 | - // add core plugin folders for checking only if we're not $check_if_custom |
|
| 226 | - if (! $check_if_custom) { |
|
| 227 | - $core_paths = array( |
|
| 228 | - // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
| 229 | - EE_PUBLIC . $current_theme, |
|
| 230 | - // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
| 231 | - EE_TEMPLATES . $current_theme, |
|
| 232 | - // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
| 233 | - EE_PLUGIN_DIR_PATH, |
|
| 234 | - ); |
|
| 235 | - $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - // now filter that array |
|
| 239 | - $template_folder_paths = apply_filters( |
|
| 240 | - 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
| 241 | - $template_folder_paths |
|
| 242 | - ); |
|
| 243 | - $templates = is_array($templates) ? $templates : array($templates); |
|
| 244 | - $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
| 245 | - // array to hold all possible template paths |
|
| 246 | - $full_template_paths = array(); |
|
| 247 | - |
|
| 248 | - // loop through $templates |
|
| 249 | - foreach ($templates as $template) { |
|
| 250 | - // normalize directory separators |
|
| 251 | - $template = EEH_File::standardise_directory_separators($template); |
|
| 252 | - $file_name = basename($template); |
|
| 253 | - $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
| 254 | - // while looping through all template folder paths |
|
| 255 | - foreach ($template_folder_paths as $template_folder_path) { |
|
| 256 | - // normalize directory separators |
|
| 257 | - $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
| 258 | - // determine if any common base path exists between the two paths |
|
| 259 | - $common_base_path = EEH_Template::_find_common_base_path( |
|
| 260 | - array($template_folder_path, $template_path_minus_file_name) |
|
| 261 | - ); |
|
| 262 | - if ($common_base_path !== '') { |
|
| 263 | - // both paths have a common base, so just tack the filename onto our search path |
|
| 264 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 265 | - } else { |
|
| 266 | - // no common base path, so let's just concatenate |
|
| 267 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 268 | - } |
|
| 269 | - // build up our template locations array by adding our resolved paths |
|
| 270 | - $full_template_paths[] = $resolved_path; |
|
| 271 | - } |
|
| 272 | - // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
| 273 | - array_unshift($full_template_paths, $template); |
|
| 274 | - // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
| 275 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
| 276 | - } |
|
| 277 | - // filter final array of full template paths |
|
| 278 | - $full_template_paths = apply_filters( |
|
| 279 | - 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
| 280 | - $full_template_paths, |
|
| 281 | - $file_name |
|
| 282 | - ); |
|
| 283 | - // now loop through our final array of template location paths and check each location |
|
| 284 | - foreach ((array) $full_template_paths as $full_template_path) { |
|
| 285 | - if (is_readable($full_template_path)) { |
|
| 286 | - $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
| 287 | - break; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - // hook that can be used to display the full template path that will be used |
|
| 293 | - do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
| 294 | - |
|
| 295 | - // if we got it and you want to see it... |
|
| 296 | - if ($template_path && $load && ! $check_if_custom) { |
|
| 297 | - if ($return_string) { |
|
| 298 | - return EEH_Template::display_template($template_path, $template_args, true); |
|
| 299 | - } else { |
|
| 300 | - EEH_Template::display_template($template_path, $template_args, false); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * _find_common_base_path |
|
| 309 | - * given two paths, this determines if there is a common base path between the two |
|
| 310 | - * |
|
| 311 | - * @param array $paths |
|
| 312 | - * @return string |
|
| 313 | - */ |
|
| 314 | - protected static function _find_common_base_path($paths) |
|
| 315 | - { |
|
| 316 | - $last_offset = 0; |
|
| 317 | - $common_base_path = ''; |
|
| 318 | - while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
| 319 | - $dir_length = $index - $last_offset + 1; |
|
| 320 | - $directory = substr($paths[0], $last_offset, $dir_length); |
|
| 321 | - foreach ($paths as $path) { |
|
| 322 | - if (substr($path, $last_offset, $dir_length) != $directory) { |
|
| 323 | - return $common_base_path; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - $common_base_path .= $directory; |
|
| 327 | - $last_offset = $index + 1; |
|
| 328 | - } |
|
| 329 | - return substr($common_base_path, 0, -1); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * load and display a template |
|
| 335 | - * |
|
| 336 | - * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
| 337 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 338 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
| 339 | - * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
| 340 | - * not found or is not readable |
|
| 341 | - * @return mixed string |
|
| 342 | - * @throws \DomainException |
|
| 343 | - */ |
|
| 344 | - public static function display_template( |
|
| 345 | - $template_path = false, |
|
| 346 | - $template_args = array(), |
|
| 347 | - $return_string = false, |
|
| 348 | - $throw_exceptions = false |
|
| 349 | - ) { |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
| 353 | - * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
| 354 | - * the display_template method are templates we DON'T want modified (usually because of js |
|
| 355 | - * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
| 356 | - * using this. |
|
| 357 | - * |
|
| 358 | - * @since 4.6.0 |
|
| 359 | - */ |
|
| 360 | - $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
| 361 | - $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
| 362 | - |
|
| 363 | - // you gimme nuttin - YOU GET NUTTIN !! |
|
| 364 | - if (! $template_path || ! is_readable($template_path)) { |
|
| 365 | - return ''; |
|
| 366 | - } |
|
| 367 | - // if $template_args are not in an array, then make it so |
|
| 368 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
| 369 | - $template_args = array($template_args); |
|
| 370 | - } |
|
| 371 | - extract($template_args, EXTR_SKIP); |
|
| 372 | - // ignore whether template is accessible ? |
|
| 373 | - if ($throw_exceptions && ! is_readable($template_path)) { |
|
| 374 | - throw new \DomainException( |
|
| 375 | - esc_html__( |
|
| 376 | - 'Invalid, unreadable, or missing file.', |
|
| 377 | - 'event_espresso' |
|
| 378 | - ) |
|
| 379 | - ); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - if ($return_string) { |
|
| 384 | - // because we want to return a string, we are going to capture the output |
|
| 385 | - ob_start(); |
|
| 386 | - include($template_path); |
|
| 387 | - return ob_get_clean(); |
|
| 388 | - } else { |
|
| 389 | - include($template_path); |
|
| 390 | - } |
|
| 391 | - return ''; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 397 | - * |
|
| 398 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 399 | - * @param string $prefix added to the beginning of the generated class |
|
| 400 | - * @param string $suffix added to the end of the generated class |
|
| 401 | - * @return string |
|
| 402 | - */ |
|
| 403 | - public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 404 | - { |
|
| 405 | - // in the beginning... |
|
| 406 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 407 | - // da muddle |
|
| 408 | - $class = ''; |
|
| 409 | - // the end |
|
| 410 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 411 | - // is the passed object an EE object ? |
|
| 412 | - if ($object instanceof EE_Base_Class) { |
|
| 413 | - // grab the exact type of object |
|
| 414 | - $obj_class = get_class($object); |
|
| 415 | - // depending on the type of object... |
|
| 416 | - switch ($obj_class) { |
|
| 417 | - // no specifics just yet... |
|
| 418 | - default: |
|
| 419 | - $class = strtolower(str_replace('_', '-', $obj_class)); |
|
| 420 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - return $prefix . $class . $suffix; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * EEH_Template::format_currency |
|
| 430 | - * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
| 431 | - * the country currency settings from the supplied country ISO code |
|
| 432 | - * |
|
| 433 | - * @param float $amount raw money value |
|
| 434 | - * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
| 435 | - * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
| 436 | - * @param string $CNT_ISO 2 letter ISO code for a country |
|
| 437 | - * @param string $cur_code_span_class |
|
| 438 | - * @return string the html output for the formatted money value |
|
| 439 | - * @throws \EE_Error |
|
| 440 | - */ |
|
| 441 | - public static function format_currency( |
|
| 442 | - $amount = null, |
|
| 443 | - $return_raw = false, |
|
| 444 | - $display_code = true, |
|
| 445 | - $CNT_ISO = '', |
|
| 446 | - $cur_code_span_class = 'currency-code' |
|
| 447 | - ) { |
|
| 448 | - // ensure amount was received |
|
| 449 | - if ($amount === null) { |
|
| 450 | - $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
| 451 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 452 | - return ''; |
|
| 453 | - } |
|
| 454 | - // ensure amount is float |
|
| 455 | - $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
| 456 | - $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
| 457 | - // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
| 458 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
| 459 | - // still a number or was amount converted to a string like "free" ? |
|
| 460 | - if (is_float($amount_formatted)) { |
|
| 461 | - // was a country ISO code passed ? if so generate currency config object for that country |
|
| 462 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
| 463 | - // verify results |
|
| 464 | - if (! $mny instanceof EE_Currency_Config) { |
|
| 465 | - // set default config country currency settings |
|
| 466 | - $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
| 467 | - ? EE_Registry::instance()->CFG->currency |
|
| 468 | - : new EE_Currency_Config(); |
|
| 469 | - } |
|
| 470 | - // format float |
|
| 471 | - $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
| 472 | - // add formatting ? |
|
| 473 | - if (! $return_raw) { |
|
| 474 | - // add currency sign |
|
| 475 | - if ($mny->sign_b4) { |
|
| 476 | - if ($amount >= 0) { |
|
| 477 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
| 478 | - } else { |
|
| 479 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 480 | - } |
|
| 481 | - } else { |
|
| 482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - // filter to allow global setting of display_code |
|
| 486 | - $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
| 487 | - |
|
| 488 | - // add currency code ? |
|
| 489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
| 490 | - } |
|
| 491 | - // filter results |
|
| 492 | - $amount_formatted = apply_filters( |
|
| 493 | - 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
| 494 | - $amount_formatted, |
|
| 495 | - $mny, |
|
| 496 | - $return_raw |
|
| 497 | - ); |
|
| 498 | - } |
|
| 499 | - // clean up vars |
|
| 500 | - unset($mny); |
|
| 501 | - // return formatted currency amount |
|
| 502 | - return $amount_formatted; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
| 508 | - * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
| 509 | - * related status model or model object (i.e. in documentation etc.) |
|
| 510 | - * |
|
| 511 | - * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
| 512 | - * match, then 'Unknown' will be returned. |
|
| 513 | - * @param boolean $plural Whether to return plural or not |
|
| 514 | - * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
| 515 | - * @return string The localized label for the status id. |
|
| 516 | - */ |
|
| 517 | - public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
| 518 | - { |
|
| 519 | - /** @type EEM_Status $EEM_Status */ |
|
| 520 | - $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
| 521 | - $status = $EEM_Status->localized_status( |
|
| 522 | - array($status_id => __('unknown', 'event_espresso')), |
|
| 523 | - $plural, |
|
| 524 | - $schema |
|
| 525 | - ); |
|
| 526 | - return $status[ $status_id ]; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * This helper just returns a button or link for the given parameters |
|
| 532 | - * |
|
| 533 | - * @param string $url the url for the link, note that `esc_url` will be called on it |
|
| 534 | - * @param string $label What is the label you want displayed for the button |
|
| 535 | - * @param string $class what class is used for the button (defaults to 'button-primary') |
|
| 536 | - * @param string $icon |
|
| 537 | - * @param string $title |
|
| 538 | - * @return string the html output for the button |
|
| 539 | - */ |
|
| 540 | - public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
| 541 | - { |
|
| 542 | - $icon_html = ''; |
|
| 543 | - if (! empty($icon)) { |
|
| 544 | - $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
| 545 | - $dashicons = array_filter($dashicons); |
|
| 546 | - $count = count($dashicons); |
|
| 547 | - $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
| 548 | - foreach ($dashicons as $dashicon) { |
|
| 549 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 550 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 551 | - } |
|
| 552 | - $icon_html .= $count > 1 ? '</span>' : ''; |
|
| 553 | - } |
|
| 554 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
| 555 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
| 556 | - return $button; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * This returns a generated link that will load the related help tab on admin pages. |
|
| 562 | - * |
|
| 563 | - * @param string $help_tab_id the id for the connected help tab |
|
| 564 | - * @param bool|string $page The page identifier for the page the help tab is on |
|
| 565 | - * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
| 566 | - * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 567 | - * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 568 | - * @return string generated link |
|
| 569 | - */ |
|
| 570 | - public static function get_help_tab_link( |
|
| 571 | - $help_tab_id, |
|
| 572 | - $page = false, |
|
| 573 | - $action = false, |
|
| 574 | - $icon_style = false, |
|
| 575 | - $help_text = false |
|
| 576 | - ) { |
|
| 577 | - |
|
| 578 | - if (! $page) { |
|
| 579 | - $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - if (! $action) { |
|
| 583 | - $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - $action = empty($action) ? 'default' : $action; |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 590 | - $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
| 591 | - $help_text = ! $help_text ? '' : $help_text; |
|
| 592 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__( |
|
| 593 | - 'Click to open the \'Help\' tab for more information about this feature.', |
|
| 594 | - 'event_espresso' |
|
| 595 | - ) . '" > ' . $help_text . ' </a>'; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
| 601 | - * |
|
| 602 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 603 | - * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
| 604 | - * @param EE_Help_Tour |
|
| 605 | - * @return string html |
|
| 606 | - */ |
|
| 607 | - public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
| 608 | - { |
|
| 609 | - $id = $tour->get_slug(); |
|
| 610 | - $stops = $tour->get_stops(); |
|
| 611 | - |
|
| 612 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
| 613 | - |
|
| 614 | - foreach ($stops as $stop) { |
|
| 615 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
| 616 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
| 617 | - |
|
| 618 | - // if container is set to modal then let's make sure we set the options accordingly |
|
| 619 | - if (empty($data_id) && empty($data_class)) { |
|
| 620 | - $stop['options']['modal'] = true; |
|
| 621 | - $stop['options']['expose'] = true; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
| 625 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
| 626 | - $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
| 627 | - |
|
| 628 | - // options |
|
| 629 | - if (isset($stop['options']) && is_array($stop['options'])) { |
|
| 630 | - $options = ' data-options="'; |
|
| 631 | - foreach ($stop['options'] as $option => $value) { |
|
| 632 | - $options .= $option . ':' . $value . ';'; |
|
| 633 | - } |
|
| 634 | - $options .= '"'; |
|
| 635 | - } else { |
|
| 636 | - $options = ''; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - // let's put all together |
|
| 640 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - $content .= '</ol>'; |
|
| 644 | - return $content; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * This is a helper method to generate a status legend for a given status array. |
|
| 650 | - * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
| 651 | - * status_array. |
|
| 652 | - * |
|
| 653 | - * @param array $status_array array of statuses that will make up the legend. In format: |
|
| 654 | - * array( |
|
| 655 | - * 'status_item' => 'status_name' |
|
| 656 | - * ) |
|
| 657 | - * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
| 658 | - * the legend. |
|
| 659 | - * @throws EE_Error |
|
| 660 | - * @return string html structure for status. |
|
| 661 | - */ |
|
| 662 | - public static function status_legend($status_array, $active_status = '') |
|
| 663 | - { |
|
| 664 | - if (! is_array($status_array)) { |
|
| 665 | - throw new EE_Error(esc_html__( |
|
| 666 | - 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
| 667 | - 'event_espresso' |
|
| 668 | - )); |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - $setup_array = array(); |
|
| 672 | - foreach ($status_array as $item => $status) { |
|
| 673 | - $setup_array[ $item ] = array( |
|
| 674 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
| 675 | - 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 676 | - 'status' => $status, |
|
| 677 | - ); |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
| 681 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
| 682 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
| 683 | - foreach ($setup_array as $item => $details) { |
|
| 684 | - $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
| 685 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
| 686 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
| 687 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
| 688 | - $content .= '</dt>' . "\n"; |
|
| 689 | - } |
|
| 690 | - $content .= '</dl>' . "\n"; |
|
| 691 | - $content .= '</div>' . "\n"; |
|
| 692 | - return $content; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
| 698 | - * that's nice for presenting in the wp admin |
|
| 699 | - * |
|
| 700 | - * @param mixed $data |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - public static function layout_array_as_table($data) |
|
| 704 | - { |
|
| 705 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 706 | - $data = (array) $data; |
|
| 707 | - } |
|
| 708 | - ob_start(); |
|
| 709 | - if (is_array($data)) { |
|
| 710 | - if (EEH_Array::is_associative_array($data)) { |
|
| 711 | - ?> |
|
| 51 | + private static $_espresso_themes = array(); |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
| 56 | + * |
|
| 57 | + * @return boolean |
|
| 58 | + */ |
|
| 59 | + public static function is_espresso_theme() |
|
| 60 | + { |
|
| 61 | + return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 66 | + * load it's functions.php file ( if not already loaded ) |
|
| 67 | + * |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + public static function load_espresso_theme_functions() |
|
| 71 | + { |
|
| 72 | + if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 73 | + if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
| 74 | + require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
| 82 | + * |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | + public static function get_espresso_themes() |
|
| 86 | + { |
|
| 87 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
| 88 | + $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 89 | + if (empty($espresso_themes)) { |
|
| 90 | + return array(); |
|
| 91 | + } |
|
| 92 | + if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
| 93 | + unset($espresso_themes[ $key ]); |
|
| 94 | + } |
|
| 95 | + EEH_Template::$_espresso_themes = array(); |
|
| 96 | + foreach ($espresso_themes as $espresso_theme) { |
|
| 97 | + EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + return EEH_Template::$_espresso_themes; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * EEH_Template::get_template_part |
|
| 106 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
| 107 | + * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
| 108 | + * filtering based off of the entire template part name |
|
| 109 | + * |
|
| 110 | + * @param string $slug The slug name for the generic template. |
|
| 111 | + * @param string $name The name of the specialised template. |
|
| 112 | + * @param array $template_args |
|
| 113 | + * @param bool $return_string |
|
| 114 | + * @return string the html output for the formatted money value |
|
| 115 | + */ |
|
| 116 | + public static function get_template_part( |
|
| 117 | + $slug = null, |
|
| 118 | + $name = null, |
|
| 119 | + $template_args = array(), |
|
| 120 | + $return_string = false |
|
| 121 | + ) { |
|
| 122 | + do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
| 123 | + $templates = array(); |
|
| 124 | + $name = (string) $name; |
|
| 125 | + if ($name != '') { |
|
| 126 | + $templates[] = "{$slug}-{$name}.php"; |
|
| 127 | + } |
|
| 128 | + // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
| 129 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
| 130 | + EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * locate_template |
|
| 137 | + * locate a template file by looking in the following places, in the following order: |
|
| 138 | + * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
| 139 | + * <assumed full absolute server path> |
|
| 140 | + * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
| 141 | + * <server path up to>/wp-content/uploads/espresso/templates/ |
|
| 142 | + * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
| 143 | + * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
| 144 | + * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
| 145 | + * as soon as the template is found in one of these locations, it will be returned or loaded |
|
| 146 | + * Example: |
|
| 147 | + * You are using the WordPress Twenty Sixteen theme, |
|
| 148 | + * and you want to customize the "some-event.template.php" template, |
|
| 149 | + * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
| 150 | + * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
| 151 | + * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
| 152 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 153 | + * /relative/path/to/some-event.template.php |
|
| 154 | + * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 155 | + * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
| 156 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 157 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 158 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
| 159 | + * Had you passed an absolute path to your template that was in some other location, |
|
| 160 | + * ie: "/absolute/path/to/some-event.template.php" |
|
| 161 | + * then the search would have been : |
|
| 162 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 163 | + * /absolute/path/to/some-event.template.php |
|
| 164 | + * and stopped there upon finding it in the second location |
|
| 165 | + * |
|
| 166 | + * @param array|string $templates array of template file names including extension (or just a single string) |
|
| 167 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 168 | + * @param boolean $load whether to pass the located template path on to the |
|
| 169 | + * EEH_Template::display_template() method or simply return it |
|
| 170 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 171 | + * string |
|
| 172 | + * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
| 173 | + * generate a custom template or not. Used in places where you don't actually |
|
| 174 | + * load the template, you just want to know if there's a custom version of it. |
|
| 175 | + * @return mixed |
|
| 176 | + * @throws DomainException |
|
| 177 | + * @throws InvalidArgumentException |
|
| 178 | + * @throws InvalidDataTypeException |
|
| 179 | + * @throws InvalidInterfaceException |
|
| 180 | + */ |
|
| 181 | + public static function locate_template( |
|
| 182 | + $templates = array(), |
|
| 183 | + $template_args = array(), |
|
| 184 | + $load = true, |
|
| 185 | + $return_string = true, |
|
| 186 | + $check_if_custom = false |
|
| 187 | + ) { |
|
| 188 | + // first use WP locate_template to check for template in the current theme folder |
|
| 189 | + $template_path = locate_template($templates); |
|
| 190 | + |
|
| 191 | + if ($check_if_custom && ! empty($template_path)) { |
|
| 192 | + return true; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // not in the theme |
|
| 196 | + if (empty($template_path)) { |
|
| 197 | + // not even a template to look for ? |
|
| 198 | + if (empty($templates)) { |
|
| 199 | + // get post_type |
|
| 200 | + $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
| 201 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 202 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
| 203 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 204 | + ); |
|
| 205 | + // get array of EE Custom Post Types |
|
| 206 | + $EE_CPTs = $custom_post_types->getDefinitions(); |
|
| 207 | + // build template name based on request |
|
| 208 | + if (isset($EE_CPTs[ $post_type ])) { |
|
| 209 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
| 210 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
| 211 | + $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + // currently active EE template theme |
|
| 215 | + $current_theme = EE_Config::get_current_theme(); |
|
| 216 | + |
|
| 217 | + // array of paths to folders that may contain templates |
|
| 218 | + $template_folder_paths = array( |
|
| 219 | + // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
| 220 | + EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 221 | + // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
| 222 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 223 | + ); |
|
| 224 | + |
|
| 225 | + // add core plugin folders for checking only if we're not $check_if_custom |
|
| 226 | + if (! $check_if_custom) { |
|
| 227 | + $core_paths = array( |
|
| 228 | + // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
| 229 | + EE_PUBLIC . $current_theme, |
|
| 230 | + // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
| 231 | + EE_TEMPLATES . $current_theme, |
|
| 232 | + // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
| 233 | + EE_PLUGIN_DIR_PATH, |
|
| 234 | + ); |
|
| 235 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + // now filter that array |
|
| 239 | + $template_folder_paths = apply_filters( |
|
| 240 | + 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
| 241 | + $template_folder_paths |
|
| 242 | + ); |
|
| 243 | + $templates = is_array($templates) ? $templates : array($templates); |
|
| 244 | + $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
| 245 | + // array to hold all possible template paths |
|
| 246 | + $full_template_paths = array(); |
|
| 247 | + |
|
| 248 | + // loop through $templates |
|
| 249 | + foreach ($templates as $template) { |
|
| 250 | + // normalize directory separators |
|
| 251 | + $template = EEH_File::standardise_directory_separators($template); |
|
| 252 | + $file_name = basename($template); |
|
| 253 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
| 254 | + // while looping through all template folder paths |
|
| 255 | + foreach ($template_folder_paths as $template_folder_path) { |
|
| 256 | + // normalize directory separators |
|
| 257 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
| 258 | + // determine if any common base path exists between the two paths |
|
| 259 | + $common_base_path = EEH_Template::_find_common_base_path( |
|
| 260 | + array($template_folder_path, $template_path_minus_file_name) |
|
| 261 | + ); |
|
| 262 | + if ($common_base_path !== '') { |
|
| 263 | + // both paths have a common base, so just tack the filename onto our search path |
|
| 264 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 265 | + } else { |
|
| 266 | + // no common base path, so let's just concatenate |
|
| 267 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 268 | + } |
|
| 269 | + // build up our template locations array by adding our resolved paths |
|
| 270 | + $full_template_paths[] = $resolved_path; |
|
| 271 | + } |
|
| 272 | + // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
| 273 | + array_unshift($full_template_paths, $template); |
|
| 274 | + // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
| 275 | + array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
| 276 | + } |
|
| 277 | + // filter final array of full template paths |
|
| 278 | + $full_template_paths = apply_filters( |
|
| 279 | + 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
| 280 | + $full_template_paths, |
|
| 281 | + $file_name |
|
| 282 | + ); |
|
| 283 | + // now loop through our final array of template location paths and check each location |
|
| 284 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
| 285 | + if (is_readable($full_template_path)) { |
|
| 286 | + $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
| 287 | + break; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + // hook that can be used to display the full template path that will be used |
|
| 293 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
| 294 | + |
|
| 295 | + // if we got it and you want to see it... |
|
| 296 | + if ($template_path && $load && ! $check_if_custom) { |
|
| 297 | + if ($return_string) { |
|
| 298 | + return EEH_Template::display_template($template_path, $template_args, true); |
|
| 299 | + } else { |
|
| 300 | + EEH_Template::display_template($template_path, $template_args, false); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * _find_common_base_path |
|
| 309 | + * given two paths, this determines if there is a common base path between the two |
|
| 310 | + * |
|
| 311 | + * @param array $paths |
|
| 312 | + * @return string |
|
| 313 | + */ |
|
| 314 | + protected static function _find_common_base_path($paths) |
|
| 315 | + { |
|
| 316 | + $last_offset = 0; |
|
| 317 | + $common_base_path = ''; |
|
| 318 | + while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
| 319 | + $dir_length = $index - $last_offset + 1; |
|
| 320 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
| 321 | + foreach ($paths as $path) { |
|
| 322 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
| 323 | + return $common_base_path; |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + $common_base_path .= $directory; |
|
| 327 | + $last_offset = $index + 1; |
|
| 328 | + } |
|
| 329 | + return substr($common_base_path, 0, -1); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * load and display a template |
|
| 335 | + * |
|
| 336 | + * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
| 337 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 338 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
| 339 | + * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
| 340 | + * not found or is not readable |
|
| 341 | + * @return mixed string |
|
| 342 | + * @throws \DomainException |
|
| 343 | + */ |
|
| 344 | + public static function display_template( |
|
| 345 | + $template_path = false, |
|
| 346 | + $template_args = array(), |
|
| 347 | + $return_string = false, |
|
| 348 | + $throw_exceptions = false |
|
| 349 | + ) { |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
| 353 | + * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
| 354 | + * the display_template method are templates we DON'T want modified (usually because of js |
|
| 355 | + * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
| 356 | + * using this. |
|
| 357 | + * |
|
| 358 | + * @since 4.6.0 |
|
| 359 | + */ |
|
| 360 | + $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
| 361 | + $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
| 362 | + |
|
| 363 | + // you gimme nuttin - YOU GET NUTTIN !! |
|
| 364 | + if (! $template_path || ! is_readable($template_path)) { |
|
| 365 | + return ''; |
|
| 366 | + } |
|
| 367 | + // if $template_args are not in an array, then make it so |
|
| 368 | + if (! is_array($template_args) && ! is_object($template_args)) { |
|
| 369 | + $template_args = array($template_args); |
|
| 370 | + } |
|
| 371 | + extract($template_args, EXTR_SKIP); |
|
| 372 | + // ignore whether template is accessible ? |
|
| 373 | + if ($throw_exceptions && ! is_readable($template_path)) { |
|
| 374 | + throw new \DomainException( |
|
| 375 | + esc_html__( |
|
| 376 | + 'Invalid, unreadable, or missing file.', |
|
| 377 | + 'event_espresso' |
|
| 378 | + ) |
|
| 379 | + ); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + if ($return_string) { |
|
| 384 | + // because we want to return a string, we are going to capture the output |
|
| 385 | + ob_start(); |
|
| 386 | + include($template_path); |
|
| 387 | + return ob_get_clean(); |
|
| 388 | + } else { |
|
| 389 | + include($template_path); |
|
| 390 | + } |
|
| 391 | + return ''; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 397 | + * |
|
| 398 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 399 | + * @param string $prefix added to the beginning of the generated class |
|
| 400 | + * @param string $suffix added to the end of the generated class |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 404 | + { |
|
| 405 | + // in the beginning... |
|
| 406 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 407 | + // da muddle |
|
| 408 | + $class = ''; |
|
| 409 | + // the end |
|
| 410 | + $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 411 | + // is the passed object an EE object ? |
|
| 412 | + if ($object instanceof EE_Base_Class) { |
|
| 413 | + // grab the exact type of object |
|
| 414 | + $obj_class = get_class($object); |
|
| 415 | + // depending on the type of object... |
|
| 416 | + switch ($obj_class) { |
|
| 417 | + // no specifics just yet... |
|
| 418 | + default: |
|
| 419 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
| 420 | + $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + return $prefix . $class . $suffix; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * EEH_Template::format_currency |
|
| 430 | + * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
| 431 | + * the country currency settings from the supplied country ISO code |
|
| 432 | + * |
|
| 433 | + * @param float $amount raw money value |
|
| 434 | + * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
| 435 | + * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
| 436 | + * @param string $CNT_ISO 2 letter ISO code for a country |
|
| 437 | + * @param string $cur_code_span_class |
|
| 438 | + * @return string the html output for the formatted money value |
|
| 439 | + * @throws \EE_Error |
|
| 440 | + */ |
|
| 441 | + public static function format_currency( |
|
| 442 | + $amount = null, |
|
| 443 | + $return_raw = false, |
|
| 444 | + $display_code = true, |
|
| 445 | + $CNT_ISO = '', |
|
| 446 | + $cur_code_span_class = 'currency-code' |
|
| 447 | + ) { |
|
| 448 | + // ensure amount was received |
|
| 449 | + if ($amount === null) { |
|
| 450 | + $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
| 451 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 452 | + return ''; |
|
| 453 | + } |
|
| 454 | + // ensure amount is float |
|
| 455 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
| 456 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
| 457 | + // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
| 458 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
| 459 | + // still a number or was amount converted to a string like "free" ? |
|
| 460 | + if (is_float($amount_formatted)) { |
|
| 461 | + // was a country ISO code passed ? if so generate currency config object for that country |
|
| 462 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
| 463 | + // verify results |
|
| 464 | + if (! $mny instanceof EE_Currency_Config) { |
|
| 465 | + // set default config country currency settings |
|
| 466 | + $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
| 467 | + ? EE_Registry::instance()->CFG->currency |
|
| 468 | + : new EE_Currency_Config(); |
|
| 469 | + } |
|
| 470 | + // format float |
|
| 471 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
| 472 | + // add formatting ? |
|
| 473 | + if (! $return_raw) { |
|
| 474 | + // add currency sign |
|
| 475 | + if ($mny->sign_b4) { |
|
| 476 | + if ($amount >= 0) { |
|
| 477 | + $amount_formatted = $mny->sign . $amount_formatted; |
|
| 478 | + } else { |
|
| 479 | + $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 480 | + } |
|
| 481 | + } else { |
|
| 482 | + $amount_formatted = $amount_formatted . $mny->sign; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + // filter to allow global setting of display_code |
|
| 486 | + $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
| 487 | + |
|
| 488 | + // add currency code ? |
|
| 489 | + $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
| 490 | + } |
|
| 491 | + // filter results |
|
| 492 | + $amount_formatted = apply_filters( |
|
| 493 | + 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
| 494 | + $amount_formatted, |
|
| 495 | + $mny, |
|
| 496 | + $return_raw |
|
| 497 | + ); |
|
| 498 | + } |
|
| 499 | + // clean up vars |
|
| 500 | + unset($mny); |
|
| 501 | + // return formatted currency amount |
|
| 502 | + return $amount_formatted; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
| 508 | + * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
| 509 | + * related status model or model object (i.e. in documentation etc.) |
|
| 510 | + * |
|
| 511 | + * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
| 512 | + * match, then 'Unknown' will be returned. |
|
| 513 | + * @param boolean $plural Whether to return plural or not |
|
| 514 | + * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
| 515 | + * @return string The localized label for the status id. |
|
| 516 | + */ |
|
| 517 | + public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
| 518 | + { |
|
| 519 | + /** @type EEM_Status $EEM_Status */ |
|
| 520 | + $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
| 521 | + $status = $EEM_Status->localized_status( |
|
| 522 | + array($status_id => __('unknown', 'event_espresso')), |
|
| 523 | + $plural, |
|
| 524 | + $schema |
|
| 525 | + ); |
|
| 526 | + return $status[ $status_id ]; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * This helper just returns a button or link for the given parameters |
|
| 532 | + * |
|
| 533 | + * @param string $url the url for the link, note that `esc_url` will be called on it |
|
| 534 | + * @param string $label What is the label you want displayed for the button |
|
| 535 | + * @param string $class what class is used for the button (defaults to 'button-primary') |
|
| 536 | + * @param string $icon |
|
| 537 | + * @param string $title |
|
| 538 | + * @return string the html output for the button |
|
| 539 | + */ |
|
| 540 | + public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
| 541 | + { |
|
| 542 | + $icon_html = ''; |
|
| 543 | + if (! empty($icon)) { |
|
| 544 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
| 545 | + $dashicons = array_filter($dashicons); |
|
| 546 | + $count = count($dashicons); |
|
| 547 | + $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
| 548 | + foreach ($dashicons as $dashicon) { |
|
| 549 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 550 | + $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 551 | + } |
|
| 552 | + $icon_html .= $count > 1 ? '</span>' : ''; |
|
| 553 | + } |
|
| 554 | + $label = ! empty($icon) ? $icon_html . $label : $label; |
|
| 555 | + $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
| 556 | + return $button; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * This returns a generated link that will load the related help tab on admin pages. |
|
| 562 | + * |
|
| 563 | + * @param string $help_tab_id the id for the connected help tab |
|
| 564 | + * @param bool|string $page The page identifier for the page the help tab is on |
|
| 565 | + * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
| 566 | + * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 567 | + * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 568 | + * @return string generated link |
|
| 569 | + */ |
|
| 570 | + public static function get_help_tab_link( |
|
| 571 | + $help_tab_id, |
|
| 572 | + $page = false, |
|
| 573 | + $action = false, |
|
| 574 | + $icon_style = false, |
|
| 575 | + $help_text = false |
|
| 576 | + ) { |
|
| 577 | + |
|
| 578 | + if (! $page) { |
|
| 579 | + $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + if (! $action) { |
|
| 583 | + $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + $action = empty($action) ? 'default' : $action; |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 590 | + $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
| 591 | + $help_text = ! $help_text ? '' : $help_text; |
|
| 592 | + return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__( |
|
| 593 | + 'Click to open the \'Help\' tab for more information about this feature.', |
|
| 594 | + 'event_espresso' |
|
| 595 | + ) . '" > ' . $help_text . ' </a>'; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
| 601 | + * |
|
| 602 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 603 | + * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
| 604 | + * @param EE_Help_Tour |
|
| 605 | + * @return string html |
|
| 606 | + */ |
|
| 607 | + public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
| 608 | + { |
|
| 609 | + $id = $tour->get_slug(); |
|
| 610 | + $stops = $tour->get_stops(); |
|
| 611 | + |
|
| 612 | + $content = '<ol style="display:none" id="' . $id . '">'; |
|
| 613 | + |
|
| 614 | + foreach ($stops as $stop) { |
|
| 615 | + $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
| 616 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
| 617 | + |
|
| 618 | + // if container is set to modal then let's make sure we set the options accordingly |
|
| 619 | + if (empty($data_id) && empty($data_class)) { |
|
| 620 | + $stop['options']['modal'] = true; |
|
| 621 | + $stop['options']['expose'] = true; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
| 625 | + $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
| 626 | + $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
| 627 | + |
|
| 628 | + // options |
|
| 629 | + if (isset($stop['options']) && is_array($stop['options'])) { |
|
| 630 | + $options = ' data-options="'; |
|
| 631 | + foreach ($stop['options'] as $option => $value) { |
|
| 632 | + $options .= $option . ':' . $value . ';'; |
|
| 633 | + } |
|
| 634 | + $options .= '"'; |
|
| 635 | + } else { |
|
| 636 | + $options = ''; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + // let's put all together |
|
| 640 | + $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + $content .= '</ol>'; |
|
| 644 | + return $content; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * This is a helper method to generate a status legend for a given status array. |
|
| 650 | + * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
| 651 | + * status_array. |
|
| 652 | + * |
|
| 653 | + * @param array $status_array array of statuses that will make up the legend. In format: |
|
| 654 | + * array( |
|
| 655 | + * 'status_item' => 'status_name' |
|
| 656 | + * ) |
|
| 657 | + * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
| 658 | + * the legend. |
|
| 659 | + * @throws EE_Error |
|
| 660 | + * @return string html structure for status. |
|
| 661 | + */ |
|
| 662 | + public static function status_legend($status_array, $active_status = '') |
|
| 663 | + { |
|
| 664 | + if (! is_array($status_array)) { |
|
| 665 | + throw new EE_Error(esc_html__( |
|
| 666 | + 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
| 667 | + 'event_espresso' |
|
| 668 | + )); |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + $setup_array = array(); |
|
| 672 | + foreach ($status_array as $item => $status) { |
|
| 673 | + $setup_array[ $item ] = array( |
|
| 674 | + 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
| 675 | + 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 676 | + 'status' => $status, |
|
| 677 | + ); |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
| 681 | + $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
| 682 | + $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
| 683 | + foreach ($setup_array as $item => $details) { |
|
| 684 | + $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
| 685 | + $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
| 686 | + $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
| 687 | + $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
| 688 | + $content .= '</dt>' . "\n"; |
|
| 689 | + } |
|
| 690 | + $content .= '</dl>' . "\n"; |
|
| 691 | + $content .= '</div>' . "\n"; |
|
| 692 | + return $content; |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
| 698 | + * that's nice for presenting in the wp admin |
|
| 699 | + * |
|
| 700 | + * @param mixed $data |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + public static function layout_array_as_table($data) |
|
| 704 | + { |
|
| 705 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 706 | + $data = (array) $data; |
|
| 707 | + } |
|
| 708 | + ob_start(); |
|
| 709 | + if (is_array($data)) { |
|
| 710 | + if (EEH_Array::is_associative_array($data)) { |
|
| 711 | + ?> |
|
| 712 | 712 | <table class="widefat"> |
| 713 | 713 | <tbody> |
| 714 | 714 | <?php |
| 715 | - foreach ($data as $data_key => $data_values) { |
|
| 716 | - ?> |
|
| 715 | + foreach ($data as $data_key => $data_values) { |
|
| 716 | + ?> |
|
| 717 | 717 | <tr> |
| 718 | 718 | <td> |
| 719 | 719 | <?php echo $data_key; ?> |
@@ -723,291 +723,291 @@ discard block |
||
| 723 | 723 | </td> |
| 724 | 724 | </tr> |
| 725 | 725 | <?php |
| 726 | - } ?> |
|
| 726 | + } ?> |
|
| 727 | 727 | </tbody> |
| 728 | 728 | </table> |
| 729 | 729 | <?php |
| 730 | - } else { |
|
| 731 | - ?> |
|
| 730 | + } else { |
|
| 731 | + ?> |
|
| 732 | 732 | <ul> |
| 733 | 733 | <?php |
| 734 | - foreach ($data as $datum) { |
|
| 735 | - echo "<li>"; |
|
| 736 | - echo self::layout_array_as_table($datum); |
|
| 737 | - echo "</li>"; |
|
| 738 | - } ?> |
|
| 734 | + foreach ($data as $datum) { |
|
| 735 | + echo "<li>"; |
|
| 736 | + echo self::layout_array_as_table($datum); |
|
| 737 | + echo "</li>"; |
|
| 738 | + } ?> |
|
| 739 | 739 | </ul> |
| 740 | 740 | <?php |
| 741 | - } |
|
| 742 | - } else { |
|
| 743 | - // simple value |
|
| 744 | - echo esc_html($data); |
|
| 745 | - } |
|
| 746 | - return ob_get_clean(); |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
| 752 | - * |
|
| 753 | - * @since 4.4.0 |
|
| 754 | - * @see self:get_paging_html() for argument docs. |
|
| 755 | - * @param $total_items |
|
| 756 | - * @param $current |
|
| 757 | - * @param $per_page |
|
| 758 | - * @param $url |
|
| 759 | - * @param bool $show_num_field |
|
| 760 | - * @param string $paged_arg_name |
|
| 761 | - * @param array $items_label |
|
| 762 | - * @return string |
|
| 763 | - */ |
|
| 764 | - public static function paging_html( |
|
| 765 | - $total_items, |
|
| 766 | - $current, |
|
| 767 | - $per_page, |
|
| 768 | - $url, |
|
| 769 | - $show_num_field = true, |
|
| 770 | - $paged_arg_name = 'paged', |
|
| 771 | - $items_label = array() |
|
| 772 | - ) { |
|
| 773 | - echo self::get_paging_html( |
|
| 774 | - $total_items, |
|
| 775 | - $current, |
|
| 776 | - $per_page, |
|
| 777 | - $url, |
|
| 778 | - $show_num_field, |
|
| 779 | - $paged_arg_name, |
|
| 780 | - $items_label |
|
| 781 | - ); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - |
|
| 785 | - /** |
|
| 786 | - * A method for generating paging similar to WP_List_Table |
|
| 787 | - * |
|
| 788 | - * @since 4.4.0 |
|
| 789 | - * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
| 790 | - * @param integer $total_items How many total items there are to page. |
|
| 791 | - * @param integer $current What the current page is. |
|
| 792 | - * @param integer $per_page How many items per page. |
|
| 793 | - * @param string $url What the base url for page links is. |
|
| 794 | - * @param boolean $show_num_field Whether to show the input for changing page number. |
|
| 795 | - * @param string $paged_arg_name The name of the key for the paged query argument. |
|
| 796 | - * @param array $items_label An array of singular/plural values for the items label: |
|
| 797 | - * array( |
|
| 798 | - * 'single' => 'item', |
|
| 799 | - * 'plural' => 'items' |
|
| 800 | - * ) |
|
| 801 | - * @return string |
|
| 802 | - */ |
|
| 803 | - public static function get_paging_html( |
|
| 804 | - $total_items, |
|
| 805 | - $current, |
|
| 806 | - $per_page, |
|
| 807 | - $url, |
|
| 808 | - $show_num_field = true, |
|
| 809 | - $paged_arg_name = 'paged', |
|
| 810 | - $items_label = array() |
|
| 811 | - ) { |
|
| 812 | - $page_links = array(); |
|
| 813 | - $disable_first = $disable_last = ''; |
|
| 814 | - $total_items = (int) $total_items; |
|
| 815 | - $per_page = (int) $per_page; |
|
| 816 | - $current = (int) $current; |
|
| 817 | - $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
| 818 | - |
|
| 819 | - // filter items_label |
|
| 820 | - $items_label = apply_filters( |
|
| 821 | - 'FHEE__EEH_Template__get_paging_html__items_label', |
|
| 822 | - $items_label |
|
| 823 | - ); |
|
| 824 | - |
|
| 825 | - if (empty($items_label) |
|
| 826 | - || ! is_array($items_label) |
|
| 827 | - || ! isset($items_label['single']) |
|
| 828 | - || ! isset($items_label['plural']) |
|
| 829 | - ) { |
|
| 830 | - $items_label = array( |
|
| 831 | - 'single' => __('1 item', 'event_espresso'), |
|
| 832 | - 'plural' => __('%s items', 'event_espresso'), |
|
| 833 | - ); |
|
| 834 | - } else { |
|
| 835 | - $items_label = array( |
|
| 836 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
| 837 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 838 | - ); |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - $total_pages = ceil($total_items / $per_page); |
|
| 842 | - |
|
| 843 | - if ($total_pages <= 1) { |
|
| 844 | - return ''; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
| 848 | - |
|
| 849 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 850 | - |
|
| 851 | - if ($current === 1) { |
|
| 852 | - $disable_first = ' disabled'; |
|
| 853 | - } |
|
| 854 | - if ($current == $total_pages) { |
|
| 855 | - $disable_last = ' disabled'; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - $page_links[] = sprintf( |
|
| 859 | - "<a class='%s' title='%s' href='%s'>%s</a>", |
|
| 860 | - 'first-page' . $disable_first, |
|
| 861 | - esc_attr__('Go to the first page', 'event_espresso'), |
|
| 862 | - esc_url(remove_query_arg($paged_arg_name, $url)), |
|
| 863 | - '«' |
|
| 864 | - ); |
|
| 865 | - |
|
| 866 | - $page_links[] = sprintf( |
|
| 867 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 868 | - 'prev-page' . $disable_first, |
|
| 869 | - esc_attr__('Go to the previous page', 'event_espresso'), |
|
| 870 | - esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
| 871 | - '‹' |
|
| 872 | - ); |
|
| 873 | - |
|
| 874 | - if (! $show_num_field) { |
|
| 875 | - $html_current_page = $current; |
|
| 876 | - } else { |
|
| 877 | - $html_current_page = sprintf( |
|
| 878 | - "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
| 879 | - esc_attr__('Current page', 'event_espresso'), |
|
| 880 | - $current, |
|
| 881 | - strlen($total_pages) |
|
| 882 | - ); |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - $html_total_pages = sprintf( |
|
| 886 | - '<span class="total-pages">%s</span>', |
|
| 887 | - number_format_i18n($total_pages) |
|
| 888 | - ); |
|
| 889 | - $page_links[] = sprintf( |
|
| 890 | - _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
| 891 | - $html_current_page, |
|
| 892 | - $html_total_pages, |
|
| 893 | - '<span class="paging-input">', |
|
| 894 | - '</span>' |
|
| 895 | - ); |
|
| 896 | - |
|
| 897 | - $page_links[] = sprintf( |
|
| 898 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 899 | - 'next-page' . $disable_last, |
|
| 900 | - esc_attr__('Go to the next page', 'event_espresso'), |
|
| 901 | - esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
| 902 | - '›' |
|
| 903 | - ); |
|
| 904 | - |
|
| 905 | - $page_links[] = sprintf( |
|
| 906 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 907 | - 'last-page' . $disable_last, |
|
| 908 | - esc_attr__('Go to the last page', 'event_espresso'), |
|
| 909 | - esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
| 910 | - '»' |
|
| 911 | - ); |
|
| 912 | - |
|
| 913 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 914 | - // set page class |
|
| 915 | - if ($total_pages) { |
|
| 916 | - $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
| 917 | - } else { |
|
| 918 | - $page_class = ' no-pages'; |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * @param string $wrap_class |
|
| 927 | - * @param string $wrap_id |
|
| 928 | - * @return string |
|
| 929 | - */ |
|
| 930 | - public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
| 931 | - { |
|
| 932 | - $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
| 933 | - if (! $admin && |
|
| 934 | - ! apply_filters( |
|
| 935 | - 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
| 936 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 937 | - ) |
|
| 938 | - ) { |
|
| 939 | - return ''; |
|
| 940 | - } |
|
| 941 | - $tag = $admin ? 'span' : 'div'; |
|
| 942 | - $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
| 943 | - $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
| 944 | - $attributes .= ! empty($wrap_class) |
|
| 945 | - ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
| 946 | - : ' class="powered-by-event-espresso-credit"'; |
|
| 947 | - $query_args = array_merge( |
|
| 948 | - array( |
|
| 949 | - 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
| 950 | - 'utm_source' => 'powered_by_event_espresso', |
|
| 951 | - 'utm_medium' => 'link', |
|
| 952 | - 'utm_campaign' => 'powered_by', |
|
| 953 | - ), |
|
| 954 | - $query_args |
|
| 955 | - ); |
|
| 956 | - $powered_by = apply_filters( |
|
| 957 | - 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
| 958 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 959 | - ); |
|
| 960 | - $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
| 961 | - $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
| 962 | - return (string) apply_filters( |
|
| 963 | - 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
| 964 | - sprintf( |
|
| 965 | - esc_html_x( |
|
| 966 | - '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
| 967 | - 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
| 968 | - 'event_espresso' |
|
| 969 | - ), |
|
| 970 | - "<{$tag}{$attributes}>", |
|
| 971 | - "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
| 972 | - $admin ? '' : '<br />' |
|
| 973 | - ), |
|
| 974 | - $wrap_class, |
|
| 975 | - $wrap_id |
|
| 976 | - ); |
|
| 977 | - } |
|
| 741 | + } |
|
| 742 | + } else { |
|
| 743 | + // simple value |
|
| 744 | + echo esc_html($data); |
|
| 745 | + } |
|
| 746 | + return ob_get_clean(); |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
| 752 | + * |
|
| 753 | + * @since 4.4.0 |
|
| 754 | + * @see self:get_paging_html() for argument docs. |
|
| 755 | + * @param $total_items |
|
| 756 | + * @param $current |
|
| 757 | + * @param $per_page |
|
| 758 | + * @param $url |
|
| 759 | + * @param bool $show_num_field |
|
| 760 | + * @param string $paged_arg_name |
|
| 761 | + * @param array $items_label |
|
| 762 | + * @return string |
|
| 763 | + */ |
|
| 764 | + public static function paging_html( |
|
| 765 | + $total_items, |
|
| 766 | + $current, |
|
| 767 | + $per_page, |
|
| 768 | + $url, |
|
| 769 | + $show_num_field = true, |
|
| 770 | + $paged_arg_name = 'paged', |
|
| 771 | + $items_label = array() |
|
| 772 | + ) { |
|
| 773 | + echo self::get_paging_html( |
|
| 774 | + $total_items, |
|
| 775 | + $current, |
|
| 776 | + $per_page, |
|
| 777 | + $url, |
|
| 778 | + $show_num_field, |
|
| 779 | + $paged_arg_name, |
|
| 780 | + $items_label |
|
| 781 | + ); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + |
|
| 785 | + /** |
|
| 786 | + * A method for generating paging similar to WP_List_Table |
|
| 787 | + * |
|
| 788 | + * @since 4.4.0 |
|
| 789 | + * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
| 790 | + * @param integer $total_items How many total items there are to page. |
|
| 791 | + * @param integer $current What the current page is. |
|
| 792 | + * @param integer $per_page How many items per page. |
|
| 793 | + * @param string $url What the base url for page links is. |
|
| 794 | + * @param boolean $show_num_field Whether to show the input for changing page number. |
|
| 795 | + * @param string $paged_arg_name The name of the key for the paged query argument. |
|
| 796 | + * @param array $items_label An array of singular/plural values for the items label: |
|
| 797 | + * array( |
|
| 798 | + * 'single' => 'item', |
|
| 799 | + * 'plural' => 'items' |
|
| 800 | + * ) |
|
| 801 | + * @return string |
|
| 802 | + */ |
|
| 803 | + public static function get_paging_html( |
|
| 804 | + $total_items, |
|
| 805 | + $current, |
|
| 806 | + $per_page, |
|
| 807 | + $url, |
|
| 808 | + $show_num_field = true, |
|
| 809 | + $paged_arg_name = 'paged', |
|
| 810 | + $items_label = array() |
|
| 811 | + ) { |
|
| 812 | + $page_links = array(); |
|
| 813 | + $disable_first = $disable_last = ''; |
|
| 814 | + $total_items = (int) $total_items; |
|
| 815 | + $per_page = (int) $per_page; |
|
| 816 | + $current = (int) $current; |
|
| 817 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
| 818 | + |
|
| 819 | + // filter items_label |
|
| 820 | + $items_label = apply_filters( |
|
| 821 | + 'FHEE__EEH_Template__get_paging_html__items_label', |
|
| 822 | + $items_label |
|
| 823 | + ); |
|
| 824 | + |
|
| 825 | + if (empty($items_label) |
|
| 826 | + || ! is_array($items_label) |
|
| 827 | + || ! isset($items_label['single']) |
|
| 828 | + || ! isset($items_label['plural']) |
|
| 829 | + ) { |
|
| 830 | + $items_label = array( |
|
| 831 | + 'single' => __('1 item', 'event_espresso'), |
|
| 832 | + 'plural' => __('%s items', 'event_espresso'), |
|
| 833 | + ); |
|
| 834 | + } else { |
|
| 835 | + $items_label = array( |
|
| 836 | + 'single' => '1 ' . esc_html($items_label['single']), |
|
| 837 | + 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 838 | + ); |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + $total_pages = ceil($total_items / $per_page); |
|
| 842 | + |
|
| 843 | + if ($total_pages <= 1) { |
|
| 844 | + return ''; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
| 848 | + |
|
| 849 | + $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 850 | + |
|
| 851 | + if ($current === 1) { |
|
| 852 | + $disable_first = ' disabled'; |
|
| 853 | + } |
|
| 854 | + if ($current == $total_pages) { |
|
| 855 | + $disable_last = ' disabled'; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + $page_links[] = sprintf( |
|
| 859 | + "<a class='%s' title='%s' href='%s'>%s</a>", |
|
| 860 | + 'first-page' . $disable_first, |
|
| 861 | + esc_attr__('Go to the first page', 'event_espresso'), |
|
| 862 | + esc_url(remove_query_arg($paged_arg_name, $url)), |
|
| 863 | + '«' |
|
| 864 | + ); |
|
| 865 | + |
|
| 866 | + $page_links[] = sprintf( |
|
| 867 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 868 | + 'prev-page' . $disable_first, |
|
| 869 | + esc_attr__('Go to the previous page', 'event_espresso'), |
|
| 870 | + esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
| 871 | + '‹' |
|
| 872 | + ); |
|
| 873 | + |
|
| 874 | + if (! $show_num_field) { |
|
| 875 | + $html_current_page = $current; |
|
| 876 | + } else { |
|
| 877 | + $html_current_page = sprintf( |
|
| 878 | + "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
| 879 | + esc_attr__('Current page', 'event_espresso'), |
|
| 880 | + $current, |
|
| 881 | + strlen($total_pages) |
|
| 882 | + ); |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + $html_total_pages = sprintf( |
|
| 886 | + '<span class="total-pages">%s</span>', |
|
| 887 | + number_format_i18n($total_pages) |
|
| 888 | + ); |
|
| 889 | + $page_links[] = sprintf( |
|
| 890 | + _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
| 891 | + $html_current_page, |
|
| 892 | + $html_total_pages, |
|
| 893 | + '<span class="paging-input">', |
|
| 894 | + '</span>' |
|
| 895 | + ); |
|
| 896 | + |
|
| 897 | + $page_links[] = sprintf( |
|
| 898 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 899 | + 'next-page' . $disable_last, |
|
| 900 | + esc_attr__('Go to the next page', 'event_espresso'), |
|
| 901 | + esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
| 902 | + '›' |
|
| 903 | + ); |
|
| 904 | + |
|
| 905 | + $page_links[] = sprintf( |
|
| 906 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 907 | + 'last-page' . $disable_last, |
|
| 908 | + esc_attr__('Go to the last page', 'event_espresso'), |
|
| 909 | + esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
| 910 | + '»' |
|
| 911 | + ); |
|
| 912 | + |
|
| 913 | + $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 914 | + // set page class |
|
| 915 | + if ($total_pages) { |
|
| 916 | + $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
| 917 | + } else { |
|
| 918 | + $page_class = ' no-pages'; |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * @param string $wrap_class |
|
| 927 | + * @param string $wrap_id |
|
| 928 | + * @return string |
|
| 929 | + */ |
|
| 930 | + public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
| 931 | + { |
|
| 932 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
| 933 | + if (! $admin && |
|
| 934 | + ! apply_filters( |
|
| 935 | + 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
| 936 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 937 | + ) |
|
| 938 | + ) { |
|
| 939 | + return ''; |
|
| 940 | + } |
|
| 941 | + $tag = $admin ? 'span' : 'div'; |
|
| 942 | + $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
| 943 | + $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
| 944 | + $attributes .= ! empty($wrap_class) |
|
| 945 | + ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
| 946 | + : ' class="powered-by-event-espresso-credit"'; |
|
| 947 | + $query_args = array_merge( |
|
| 948 | + array( |
|
| 949 | + 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
| 950 | + 'utm_source' => 'powered_by_event_espresso', |
|
| 951 | + 'utm_medium' => 'link', |
|
| 952 | + 'utm_campaign' => 'powered_by', |
|
| 953 | + ), |
|
| 954 | + $query_args |
|
| 955 | + ); |
|
| 956 | + $powered_by = apply_filters( |
|
| 957 | + 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
| 958 | + $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 959 | + ); |
|
| 960 | + $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
| 961 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
| 962 | + return (string) apply_filters( |
|
| 963 | + 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
| 964 | + sprintf( |
|
| 965 | + esc_html_x( |
|
| 966 | + '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
| 967 | + 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
| 968 | + 'event_espresso' |
|
| 969 | + ), |
|
| 970 | + "<{$tag}{$attributes}>", |
|
| 971 | + "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
| 972 | + $admin ? '' : '<br />' |
|
| 973 | + ), |
|
| 974 | + $wrap_class, |
|
| 975 | + $wrap_id |
|
| 976 | + ); |
|
| 977 | + } |
|
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | |
| 981 | 981 | |
| 982 | 982 | |
| 983 | 983 | if (! function_exists('espresso_pagination')) { |
| 984 | - /** |
|
| 985 | - * espresso_pagination |
|
| 986 | - * |
|
| 987 | - * @access public |
|
| 988 | - * @return void |
|
| 989 | - */ |
|
| 990 | - function espresso_pagination() |
|
| 991 | - { |
|
| 992 | - global $wp_query; |
|
| 993 | - $big = 999999999; // need an unlikely integer |
|
| 994 | - $pagination = paginate_links( |
|
| 995 | - array( |
|
| 996 | - 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 997 | - 'format' => '?paged=%#%', |
|
| 998 | - 'current' => max(1, get_query_var('paged')), |
|
| 999 | - 'total' => $wp_query->max_num_pages, |
|
| 1000 | - 'show_all' => true, |
|
| 1001 | - 'end_size' => 10, |
|
| 1002 | - 'mid_size' => 6, |
|
| 1003 | - 'prev_next' => true, |
|
| 1004 | - 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
| 1005 | - 'next_text' => __('NEXT ›', 'event_espresso'), |
|
| 1006 | - 'type' => 'plain', |
|
| 1007 | - 'add_args' => false, |
|
| 1008 | - 'add_fragment' => '', |
|
| 1009 | - ) |
|
| 1010 | - ); |
|
| 1011 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
| 1012 | - } |
|
| 984 | + /** |
|
| 985 | + * espresso_pagination |
|
| 986 | + * |
|
| 987 | + * @access public |
|
| 988 | + * @return void |
|
| 989 | + */ |
|
| 990 | + function espresso_pagination() |
|
| 991 | + { |
|
| 992 | + global $wp_query; |
|
| 993 | + $big = 999999999; // need an unlikely integer |
|
| 994 | + $pagination = paginate_links( |
|
| 995 | + array( |
|
| 996 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 997 | + 'format' => '?paged=%#%', |
|
| 998 | + 'current' => max(1, get_query_var('paged')), |
|
| 999 | + 'total' => $wp_query->max_num_pages, |
|
| 1000 | + 'show_all' => true, |
|
| 1001 | + 'end_size' => 10, |
|
| 1002 | + 'mid_size' => 6, |
|
| 1003 | + 'prev_next' => true, |
|
| 1004 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
| 1005 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
| 1006 | + 'type' => 'plain', |
|
| 1007 | + 'add_args' => false, |
|
| 1008 | + 'add_fragment' => '', |
|
| 1009 | + ) |
|
| 1010 | + ); |
|
| 1011 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
| 1012 | + } |
|
| 1013 | 1013 | } |
| 1014 | 1014 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 5 | 5 | use EventEspresso\core\services\loaders\LoaderFactory; |
| 6 | 6 | |
| 7 | -if (! function_exists('espresso_get_template_part')) { |
|
| 7 | +if ( ! function_exists('espresso_get_template_part')) { |
|
| 8 | 8 | /** |
| 9 | 9 | * espresso_get_template_part |
| 10 | 10 | * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | -if (! function_exists('espresso_get_object_css_class')) { |
|
| 24 | +if ( ! function_exists('espresso_get_object_css_class')) { |
|
| 25 | 25 | /** |
| 26 | 26 | * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
| 27 | 27 | * |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public static function load_espresso_theme_functions() |
| 71 | 71 | { |
| 72 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 73 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
| 74 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
| 72 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 73 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) { |
|
| 74 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php'); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -85,16 +85,16 @@ discard block |
||
| 85 | 85 | public static function get_espresso_themes() |
| 86 | 86 | { |
| 87 | 87 | if (empty(EEH_Template::$_espresso_themes)) { |
| 88 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 88 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
| 89 | 89 | if (empty($espresso_themes)) { |
| 90 | 90 | return array(); |
| 91 | 91 | } |
| 92 | 92 | if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
| 93 | - unset($espresso_themes[ $key ]); |
|
| 93 | + unset($espresso_themes[$key]); |
|
| 94 | 94 | } |
| 95 | 95 | EEH_Template::$_espresso_themes = array(); |
| 96 | 96 | foreach ($espresso_themes as $espresso_theme) { |
| 97 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
| 97 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | return EEH_Template::$_espresso_themes; |
@@ -205,10 +205,10 @@ discard block |
||
| 205 | 205 | // get array of EE Custom Post Types |
| 206 | 206 | $EE_CPTs = $custom_post_types->getDefinitions(); |
| 207 | 207 | // build template name based on request |
| 208 | - if (isset($EE_CPTs[ $post_type ])) { |
|
| 208 | + if (isset($EE_CPTs[$post_type])) { |
|
| 209 | 209 | $archive_or_single = is_archive() ? 'archive' : ''; |
| 210 | 210 | $archive_or_single = is_single() ? 'single' : $archive_or_single; |
| 211 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 211 | + $templates = $archive_or_single.'-'.$post_type.'.php'; |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | // currently active EE template theme |
@@ -217,18 +217,18 @@ discard block |
||
| 217 | 217 | // array of paths to folders that may contain templates |
| 218 | 218 | $template_folder_paths = array( |
| 219 | 219 | // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
| 220 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 220 | + EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme, |
|
| 221 | 221 | // then in the root of the /wp-content/uploads/espresso/templates/ folder |
| 222 | 222 | EVENT_ESPRESSO_TEMPLATE_DIR, |
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | 225 | // add core plugin folders for checking only if we're not $check_if_custom |
| 226 | - if (! $check_if_custom) { |
|
| 227 | - $core_paths = array( |
|
| 226 | + if ( ! $check_if_custom) { |
|
| 227 | + $core_paths = array( |
|
| 228 | 228 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
| 229 | - EE_PUBLIC . $current_theme, |
|
| 229 | + EE_PUBLIC.$current_theme, |
|
| 230 | 230 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
| 231 | - EE_TEMPLATES . $current_theme, |
|
| 231 | + EE_TEMPLATES.$current_theme, |
|
| 232 | 232 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
| 233 | 233 | EE_PLUGIN_DIR_PATH, |
| 234 | 234 | ); |
@@ -261,10 +261,10 @@ discard block |
||
| 261 | 261 | ); |
| 262 | 262 | if ($common_base_path !== '') { |
| 263 | 263 | // both paths have a common base, so just tack the filename onto our search path |
| 264 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 264 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
| 265 | 265 | } else { |
| 266 | 266 | // no common base path, so let's just concatenate |
| 267 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 267 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
| 268 | 268 | } |
| 269 | 269 | // build up our template locations array by adding our resolved paths |
| 270 | 270 | $full_template_paths[] = $resolved_path; |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
| 273 | 273 | array_unshift($full_template_paths, $template); |
| 274 | 274 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
| 275 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
| 275 | + array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name); |
|
| 276 | 276 | } |
| 277 | 277 | // filter final array of full template paths |
| 278 | 278 | $full_template_paths = apply_filters( |
@@ -361,11 +361,11 @@ discard block |
||
| 361 | 361 | $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
| 362 | 362 | |
| 363 | 363 | // you gimme nuttin - YOU GET NUTTIN !! |
| 364 | - if (! $template_path || ! is_readable($template_path)) { |
|
| 364 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
| 365 | 365 | return ''; |
| 366 | 366 | } |
| 367 | 367 | // if $template_args are not in an array, then make it so |
| 368 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
| 368 | + if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
| 369 | 369 | $template_args = array($template_args); |
| 370 | 370 | } |
| 371 | 371 | extract($template_args, EXTR_SKIP); |
@@ -403,11 +403,11 @@ discard block |
||
| 403 | 403 | public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
| 404 | 404 | { |
| 405 | 405 | // in the beginning... |
| 406 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 406 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
| 407 | 407 | // da muddle |
| 408 | 408 | $class = ''; |
| 409 | 409 | // the end |
| 410 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 410 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
| 411 | 411 | // is the passed object an EE object ? |
| 412 | 412 | if ($object instanceof EE_Base_Class) { |
| 413 | 413 | // grab the exact type of object |
@@ -417,10 +417,10 @@ discard block |
||
| 417 | 417 | // no specifics just yet... |
| 418 | 418 | default: |
| 419 | 419 | $class = strtolower(str_replace('_', '-', $obj_class)); |
| 420 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 420 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | - return $prefix . $class . $suffix; |
|
| 423 | + return $prefix.$class.$suffix; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | // was a country ISO code passed ? if so generate currency config object for that country |
| 462 | 462 | $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
| 463 | 463 | // verify results |
| 464 | - if (! $mny instanceof EE_Currency_Config) { |
|
| 464 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
| 465 | 465 | // set default config country currency settings |
| 466 | 466 | $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
| 467 | 467 | ? EE_Registry::instance()->CFG->currency |
@@ -470,23 +470,23 @@ discard block |
||
| 470 | 470 | // format float |
| 471 | 471 | $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
| 472 | 472 | // add formatting ? |
| 473 | - if (! $return_raw) { |
|
| 473 | + if ( ! $return_raw) { |
|
| 474 | 474 | // add currency sign |
| 475 | 475 | if ($mny->sign_b4) { |
| 476 | 476 | if ($amount >= 0) { |
| 477 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
| 477 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
| 478 | 478 | } else { |
| 479 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 479 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
| 480 | 480 | } |
| 481 | 481 | } else { |
| 482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
| 482 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | // filter to allow global setting of display_code |
| 486 | 486 | $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
| 487 | 487 | |
| 488 | 488 | // add currency code ? |
| 489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
| 489 | + $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted; |
|
| 490 | 490 | } |
| 491 | 491 | // filter results |
| 492 | 492 | $amount_formatted = apply_filters( |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | $plural, |
| 524 | 524 | $schema |
| 525 | 525 | ); |
| 526 | - return $status[ $status_id ]; |
|
| 526 | + return $status[$status_id]; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | |
@@ -540,19 +540,19 @@ discard block |
||
| 540 | 540 | public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
| 541 | 541 | { |
| 542 | 542 | $icon_html = ''; |
| 543 | - if (! empty($icon)) { |
|
| 543 | + if ( ! empty($icon)) { |
|
| 544 | 544 | $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
| 545 | 545 | $dashicons = array_filter($dashicons); |
| 546 | 546 | $count = count($dashicons); |
| 547 | 547 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
| 548 | 548 | foreach ($dashicons as $dashicon) { |
| 549 | 549 | $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
| 550 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 550 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
| 551 | 551 | } |
| 552 | 552 | $icon_html .= $count > 1 ? '</span>' : ''; |
| 553 | 553 | } |
| 554 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
| 555 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
| 554 | + $label = ! empty($icon) ? $icon_html.$label : $label; |
|
| 555 | + $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.esc_url($url).'" class="'.$class.'" title="'.$title.'">'.$label.'</a>'; |
|
| 556 | 556 | return $button; |
| 557 | 557 | } |
| 558 | 558 | |
@@ -575,24 +575,24 @@ discard block |
||
| 575 | 575 | $help_text = false |
| 576 | 576 | ) { |
| 577 | 577 | |
| 578 | - if (! $page) { |
|
| 578 | + if ( ! $page) { |
|
| 579 | 579 | $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - if (! $action) { |
|
| 582 | + if ( ! $action) { |
|
| 583 | 583 | $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | $action = empty($action) ? 'default' : $action; |
| 587 | 587 | |
| 588 | 588 | |
| 589 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 589 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
| 590 | 590 | $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
| 591 | 591 | $help_text = ! $help_text ? '' : $help_text; |
| 592 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__( |
|
| 592 | + return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__( |
|
| 593 | 593 | 'Click to open the \'Help\' tab for more information about this feature.', |
| 594 | 594 | 'event_espresso' |
| 595 | - ) . '" > ' . $help_text . ' </a>'; |
|
| 595 | + ).'" > '.$help_text.' </a>'; |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | |
@@ -609,11 +609,11 @@ discard block |
||
| 609 | 609 | $id = $tour->get_slug(); |
| 610 | 610 | $stops = $tour->get_stops(); |
| 611 | 611 | |
| 612 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
| 612 | + $content = '<ol style="display:none" id="'.$id.'">'; |
|
| 613 | 613 | |
| 614 | 614 | foreach ($stops as $stop) { |
| 615 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
| 616 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
| 615 | + $data_id = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : ''; |
|
| 616 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : ''; |
|
| 617 | 617 | |
| 618 | 618 | // if container is set to modal then let's make sure we set the options accordingly |
| 619 | 619 | if (empty($data_id) && empty($data_class)) { |
@@ -621,15 +621,15 @@ discard block |
||
| 621 | 621 | $stop['options']['expose'] = true; |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
| 625 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
| 624 | + $custom_class = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : ''; |
|
| 625 | + $button_text = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : ''; |
|
| 626 | 626 | $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
| 627 | 627 | |
| 628 | 628 | // options |
| 629 | 629 | if (isset($stop['options']) && is_array($stop['options'])) { |
| 630 | 630 | $options = ' data-options="'; |
| 631 | 631 | foreach ($stop['options'] as $option => $value) { |
| 632 | - $options .= $option . ':' . $value . ';'; |
|
| 632 | + $options .= $option.':'.$value.';'; |
|
| 633 | 633 | } |
| 634 | 634 | $options .= '"'; |
| 635 | 635 | } else { |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | // let's put all together |
| 640 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
| 640 | + $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>'; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | $content .= '</ol>'; |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | */ |
| 662 | 662 | public static function status_legend($status_array, $active_status = '') |
| 663 | 663 | { |
| 664 | - if (! is_array($status_array)) { |
|
| 664 | + if ( ! is_array($status_array)) { |
|
| 665 | 665 | throw new EE_Error(esc_html__( |
| 666 | 666 | 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
| 667 | 667 | 'event_espresso' |
@@ -670,25 +670,25 @@ discard block |
||
| 670 | 670 | |
| 671 | 671 | $setup_array = array(); |
| 672 | 672 | foreach ($status_array as $item => $status) { |
| 673 | - $setup_array[ $item ] = array( |
|
| 674 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
| 673 | + $setup_array[$item] = array( |
|
| 674 | + 'class' => 'ee-status-legend ee-status-legend-'.$status, |
|
| 675 | 675 | 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
| 676 | 676 | 'status' => $status, |
| 677 | 677 | ); |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
| 681 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
| 682 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
| 680 | + $content = '<div class="ee-list-table-legend-container">'."\n"; |
|
| 681 | + $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n"; |
|
| 682 | + $content .= '<dl class="ee-list-table-legend">'."\n\t"; |
|
| 683 | 683 | foreach ($setup_array as $item => $details) { |
| 684 | 684 | $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
| 685 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
| 686 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
| 687 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
| 688 | - $content .= '</dt>' . "\n"; |
|
| 685 | + $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t"; |
|
| 686 | + $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t"; |
|
| 687 | + $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t"; |
|
| 688 | + $content .= '</dt>'."\n"; |
|
| 689 | 689 | } |
| 690 | - $content .= '</dl>' . "\n"; |
|
| 691 | - $content .= '</div>' . "\n"; |
|
| 690 | + $content .= '</dl>'."\n"; |
|
| 691 | + $content .= '</div>'."\n"; |
|
| 692 | 692 | return $content; |
| 693 | 693 | } |
| 694 | 694 | |
@@ -833,8 +833,8 @@ discard block |
||
| 833 | 833 | ); |
| 834 | 834 | } else { |
| 835 | 835 | $items_label = array( |
| 836 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
| 837 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 836 | + 'single' => '1 '.esc_html($items_label['single']), |
|
| 837 | + 'plural' => '%s '.esc_html($items_label['plural']), |
|
| 838 | 838 | ); |
| 839 | 839 | } |
| 840 | 840 | |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | |
| 847 | 847 | $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
| 848 | 848 | |
| 849 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 849 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
| 850 | 850 | |
| 851 | 851 | if ($current === 1) { |
| 852 | 852 | $disable_first = ' disabled'; |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | |
| 858 | 858 | $page_links[] = sprintf( |
| 859 | 859 | "<a class='%s' title='%s' href='%s'>%s</a>", |
| 860 | - 'first-page' . $disable_first, |
|
| 860 | + 'first-page'.$disable_first, |
|
| 861 | 861 | esc_attr__('Go to the first page', 'event_espresso'), |
| 862 | 862 | esc_url(remove_query_arg($paged_arg_name, $url)), |
| 863 | 863 | '«' |
@@ -865,13 +865,13 @@ discard block |
||
| 865 | 865 | |
| 866 | 866 | $page_links[] = sprintf( |
| 867 | 867 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 868 | - 'prev-page' . $disable_first, |
|
| 868 | + 'prev-page'.$disable_first, |
|
| 869 | 869 | esc_attr__('Go to the previous page', 'event_espresso'), |
| 870 | 870 | esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
| 871 | 871 | '‹' |
| 872 | 872 | ); |
| 873 | 873 | |
| 874 | - if (! $show_num_field) { |
|
| 874 | + if ( ! $show_num_field) { |
|
| 875 | 875 | $html_current_page = $current; |
| 876 | 876 | } else { |
| 877 | 877 | $html_current_page = sprintf( |
@@ -886,7 +886,7 @@ discard block |
||
| 886 | 886 | '<span class="total-pages">%s</span>', |
| 887 | 887 | number_format_i18n($total_pages) |
| 888 | 888 | ); |
| 889 | - $page_links[] = sprintf( |
|
| 889 | + $page_links[] = sprintf( |
|
| 890 | 890 | _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
| 891 | 891 | $html_current_page, |
| 892 | 892 | $html_total_pages, |
@@ -896,7 +896,7 @@ discard block |
||
| 896 | 896 | |
| 897 | 897 | $page_links[] = sprintf( |
| 898 | 898 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 899 | - 'next-page' . $disable_last, |
|
| 899 | + 'next-page'.$disable_last, |
|
| 900 | 900 | esc_attr__('Go to the next page', 'event_espresso'), |
| 901 | 901 | esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
| 902 | 902 | '›' |
@@ -904,13 +904,13 @@ discard block |
||
| 904 | 904 | |
| 905 | 905 | $page_links[] = sprintf( |
| 906 | 906 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 907 | - 'last-page' . $disable_last, |
|
| 907 | + 'last-page'.$disable_last, |
|
| 908 | 908 | esc_attr__('Go to the last page', 'event_espresso'), |
| 909 | 909 | esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
| 910 | 910 | '»' |
| 911 | 911 | ); |
| 912 | 912 | |
| 913 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 913 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
| 914 | 914 | // set page class |
| 915 | 915 | if ($total_pages) { |
| 916 | 916 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | $page_class = ' no-pages'; |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 921 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | |
@@ -930,7 +930,7 @@ discard block |
||
| 930 | 930 | public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
| 931 | 931 | { |
| 932 | 932 | $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
| 933 | - if (! $admin && |
|
| 933 | + if ( ! $admin && |
|
| 934 | 934 | ! apply_filters( |
| 935 | 935 | 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
| 936 | 936 | EE_Registry::instance()->CFG->admin->show_reg_footer |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | ); |
| 956 | 956 | $powered_by = apply_filters( |
| 957 | 957 | 'FHEE__EEH_Template__powered_by_event_espresso_text', |
| 958 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 958 | + $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 959 | 959 | ); |
| 960 | 960 | $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
| 961 | 961 | $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | |
| 981 | 981 | |
| 982 | 982 | |
| 983 | -if (! function_exists('espresso_pagination')) { |
|
| 983 | +if ( ! function_exists('espresso_pagination')) { |
|
| 984 | 984 | /** |
| 985 | 985 | * espresso_pagination |
| 986 | 986 | * |
@@ -1008,6 +1008,6 @@ discard block |
||
| 1008 | 1008 | 'add_fragment' => '', |
| 1009 | 1009 | ) |
| 1010 | 1010 | ); |
| 1011 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
| 1011 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
| 1012 | 1012 | } |
| 1013 | 1013 | } |
| 1014 | 1014 | \ No newline at end of file |
@@ -24,666 +24,666 @@ |
||
| 24 | 24 | class EEH_File extends EEH_Base implements EEHI_File |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var string $_credentials_form |
|
| 29 | - */ |
|
| 30 | - private static $_credentials_form; |
|
| 31 | - |
|
| 32 | - protected static $_wp_filesystem_direct; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @param string|null $filepath the filepath we want to work in. If its in the |
|
| 36 | - * wp uploads directory, we'll want to just use the filesystem directly. |
|
| 37 | - * If not provided, we have to assume its not in the uploads directory |
|
| 38 | - * @throws EE_Error if filesystem credentials are required |
|
| 39 | - * @return WP_Filesystem_Base |
|
| 40 | - */ |
|
| 41 | - private static function _get_wp_filesystem($filepath = null) |
|
| 42 | - { |
|
| 43 | - if (apply_filters( |
|
| 44 | - 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
|
| 45 | - $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
| 46 | - $filepath |
|
| 47 | - ) ) { |
|
| 48 | - if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
| 49 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
| 50 | - $method = 'direct'; |
|
| 51 | - $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); |
|
| 52 | - // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
|
| 53 | - if (! defined('FS_CHMOD_DIR')) { |
|
| 54 | - define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 )); |
|
| 55 | - } |
|
| 56 | - if (! defined('FS_CHMOD_FILE')) { |
|
| 57 | - define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 )); |
|
| 58 | - } |
|
| 59 | - require_once($wp_filesystem_direct_file); |
|
| 60 | - EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
| 61 | - } |
|
| 62 | - return EEH_File::$_wp_filesystem_direct; |
|
| 63 | - } |
|
| 64 | - global $wp_filesystem; |
|
| 65 | - // no filesystem setup ??? |
|
| 66 | - if (! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
| 67 | - // if some eager beaver's just trying to get in there too early... |
|
| 68 | - // let them do it, because we are one of those eager beavers! :P |
|
| 69 | - /** |
|
| 70 | - * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base |
|
| 71 | - * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process |
|
| 72 | - * is setup to mostly happen on 'init', and refactoring to have it happen on |
|
| 73 | - * 'wp_loaded' is too much work on a BETA milestone. |
|
| 74 | - * So this fix is expected to work if the WP files are owned by the server user, |
|
| 75 | - * but probably not if the user needs to enter their FTP credentials to modify files |
|
| 76 | - * and there may be troubles if the WP files are owned by a different user |
|
| 77 | - * than the server user. But both of these issues should exist in 4.4 and earlier too |
|
| 78 | - */ |
|
| 79 | - if (false && ! did_action('wp_loaded')) { |
|
| 80 | - $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
|
| 81 | - if (WP_DEBUG) { |
|
| 82 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
| 83 | - } |
|
| 84 | - throw new EE_Error($msg); |
|
| 85 | - } else { |
|
| 86 | - // should be loaded if we are past the wp_loaded hook... |
|
| 87 | - if (! function_exists('WP_Filesystem')) { |
|
| 88 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
| 89 | - require_once(ABSPATH . 'wp-admin/includes/template.php'); |
|
| 90 | - } |
|
| 91 | - // turn on output buffering so that we can capture the credentials form |
|
| 92 | - ob_start(); |
|
| 93 | - $credentials = request_filesystem_credentials(''); |
|
| 94 | - // store credentials form for the time being |
|
| 95 | - EEH_File::$_credentials_form = ob_get_clean(); |
|
| 96 | - // basically check for direct or previously configured access |
|
| 97 | - if (! WP_Filesystem($credentials)) { |
|
| 98 | - // if credentials do NOT exist |
|
| 99 | - if ($credentials === false) { |
|
| 100 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
| 101 | - throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
| 102 | - } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
| 103 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
| 104 | - throw new EE_Error( |
|
| 105 | - sprintf( |
|
| 106 | - __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
| 107 | - $wp_filesystem->errors->get_error_message() |
|
| 108 | - ) |
|
| 109 | - ); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - return $wp_filesystem; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * display_request_filesystem_credentials_form |
|
| 119 | - */ |
|
| 120 | - public static function display_request_filesystem_credentials_form() |
|
| 121 | - { |
|
| 122 | - if (! empty(EEH_File::$_credentials_form)) { |
|
| 123 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * verify_filepath_and_permissions |
|
| 131 | - * checks that a file is readable and has sufficient file permissions set to access |
|
| 132 | - * |
|
| 133 | - * @access public |
|
| 134 | - * @param string $full_file_path - full server path to the folder or file |
|
| 135 | - * @param string $file_name - name of file if checking a file |
|
| 136 | - * @param string $file_ext - file extension (ie: "php") if checking a file |
|
| 137 | - * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
| 138 | - * @throws EE_Error if filesystem credentials are required |
|
| 139 | - * @return bool |
|
| 140 | - */ |
|
| 141 | - public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') |
|
| 142 | - { |
|
| 143 | - // load WP_Filesystem and set file permissions |
|
| 144 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 145 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 146 | - if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 147 | - $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name; |
|
| 148 | - $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
| 149 | - $msg = sprintf( |
|
| 150 | - __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
| 151 | - $file_name, |
|
| 152 | - '<br />' |
|
| 153 | - ); |
|
| 154 | - if (EEH_File::exists($full_file_path)) { |
|
| 155 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
| 156 | - } else { |
|
| 157 | - // no file permissions means the file was not found |
|
| 158 | - $msg .= sprintf( |
|
| 159 | - __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
| 160 | - $full_file_path |
|
| 161 | - ); |
|
| 162 | - } |
|
| 163 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 164 | - throw new EE_Error($msg . '||' . $msg); |
|
| 165 | - } |
|
| 166 | - return false; |
|
| 167 | - } |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder |
|
| 175 | - * |
|
| 176 | - * @access private |
|
| 177 | - * @param string $full_file_path - full server path to the folder or file |
|
| 178 | - * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
| 179 | - * @throws EE_Error if filesystem credentials are required |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') |
|
| 183 | - { |
|
| 184 | - // load WP_Filesystem and set file permissions |
|
| 185 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 186 | - // check file permissions |
|
| 187 | - $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
| 188 | - if ($perms) { |
|
| 189 | - // file permissions exist, but way be set incorrectly |
|
| 190 | - $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : ''; |
|
| 191 | - $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
| 192 | - return sprintf( |
|
| 193 | - __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
| 194 | - $type_of_file, |
|
| 195 | - $perms |
|
| 196 | - ); |
|
| 197 | - } else { |
|
| 198 | - // file exists but file permissions could not be read ?!?! |
|
| 199 | - return sprintf( |
|
| 200 | - __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
| 201 | - $full_file_path |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * ensure_folder_exists_and_is_writable |
|
| 210 | - * ensures that a folder exists and is writable, will attempt to create folder if it does not exist |
|
| 211 | - * Also ensures all the parent folders exist, and if not tries to create them. |
|
| 212 | - * Also, if this function creates the folder, adds a .htaccess file and index.html file |
|
| 213 | - * @param string $folder |
|
| 214 | - * @throws EE_Error if the folder exists and is writeable, but for some reason we |
|
| 215 | - * can't write to it |
|
| 216 | - * @return bool false if folder isn't writable; true if it exists and is writeable, |
|
| 217 | - */ |
|
| 218 | - public static function ensure_folder_exists_and_is_writable($folder = '') |
|
| 219 | - { |
|
| 220 | - if (empty($folder)) { |
|
| 221 | - return false; |
|
| 222 | - } |
|
| 223 | - // remove ending / |
|
| 224 | - $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
| 225 | - $parent_folder = EEH_File::get_parent_folder($folder); |
|
| 226 | - // add / to folder |
|
| 227 | - $folder = EEH_File::end_with_directory_separator($folder); |
|
| 228 | - $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
| 229 | - if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 230 | - // ok so it doesn't exist. Does its parent? Can we write to it? |
|
| 231 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 232 | - return false; |
|
| 233 | - } |
|
| 234 | - if (! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
| 235 | - return false; |
|
| 236 | - } else { |
|
| 237 | - if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 238 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 239 | - $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
| 240 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
| 241 | - throw new EE_Error($msg); |
|
| 242 | - } |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - EEH_File::add_index_file($folder); |
|
| 246 | - } |
|
| 247 | - } elseif (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 250 | - return true; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * verify_is_writable - checks if a file or folder is writable |
|
| 257 | - * @param string $full_path - full server path to file or folder |
|
| 258 | - * @param string $file_or_folder - whether checking a file or folder |
|
| 259 | - * @throws EE_Error if filesystem credentials are required |
|
| 260 | - * @return bool |
|
| 261 | - */ |
|
| 262 | - public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') |
|
| 263 | - { |
|
| 264 | - // load WP_Filesystem and set file permissions |
|
| 265 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
| 266 | - $full_path = EEH_File::standardise_directory_separators($full_path); |
|
| 267 | - if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
| 268 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 269 | - $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
| 270 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
| 271 | - throw new EE_Error($msg); |
|
| 272 | - } |
|
| 273 | - return false; |
|
| 274 | - } |
|
| 275 | - return true; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * ensure_file_exists_and_is_writable |
|
| 282 | - * ensures that a file exists and is writable, will attempt to create file if it does not exist. |
|
| 283 | - * Also ensures all the parent folders exist, and if not tries to create them. |
|
| 284 | - * @param string $full_file_path |
|
| 285 | - * @throws EE_Error if filesystem credentials are required |
|
| 286 | - * @return bool |
|
| 287 | - */ |
|
| 288 | - public static function ensure_file_exists_and_is_writable($full_file_path = '') |
|
| 289 | - { |
|
| 290 | - // load WP_Filesystem and set file permissions |
|
| 291 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 292 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 293 | - $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
| 294 | - if (! EEH_File::exists($full_file_path)) { |
|
| 295 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 296 | - return false; |
|
| 297 | - } |
|
| 298 | - if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 299 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 300 | - $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
| 301 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
| 302 | - throw new EE_Error($msg); |
|
| 303 | - } |
|
| 304 | - return false; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - if (! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
| 308 | - return false; |
|
| 309 | - } |
|
| 310 | - return true; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Gets the parent folder. If provided with file, gets the folder that contains it. |
|
| 315 | - * If provided a folder, gets its parent folder. |
|
| 316 | - * @param string $file_or_folder_path |
|
| 317 | - * @return string parent folder, ENDING with a directory separator |
|
| 318 | - */ |
|
| 319 | - public static function get_parent_folder($file_or_folder_path) |
|
| 320 | - { |
|
| 321 | - // find the last /, ignoring a / on the very end |
|
| 322 | - // eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
|
| 323 | - // parent folder, "/var/something/" |
|
| 324 | - $ds = strlen($file_or_folder_path) > 1 |
|
| 325 | - ? strrpos($file_or_folder_path, '/', -2) |
|
| 326 | - : strlen($file_or_folder_path); |
|
| 327 | - return substr($file_or_folder_path, 0, $ds + 1); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - // public static function ensure_folder_exists_recursively( $folder ) { |
|
| 331 | - // |
|
| 332 | - // } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * get_file_contents |
|
| 338 | - * @param string $full_file_path |
|
| 339 | - * @throws EE_Error if filesystem credentials are required |
|
| 340 | - * @return string |
|
| 341 | - */ |
|
| 342 | - public static function get_file_contents($full_file_path = '') |
|
| 343 | - { |
|
| 344 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 345 | - if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
| 346 | - // load WP_Filesystem and set file permissions |
|
| 347 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 348 | - return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
| 349 | - } |
|
| 350 | - return ''; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * write_file |
|
| 357 | - * @param string $full_file_path |
|
| 358 | - * @param string $file_contents - the content to be written to the file |
|
| 359 | - * @param string $file_type |
|
| 360 | - * @throws EE_Error if filesystem credentials are required |
|
| 361 | - * @return bool |
|
| 362 | - */ |
|
| 363 | - public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') |
|
| 364 | - { |
|
| 365 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 366 | - $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : ''; |
|
| 367 | - $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
| 368 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 369 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 370 | - $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
| 371 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
| 372 | - throw new EE_Error($msg); |
|
| 373 | - } |
|
| 374 | - return false; |
|
| 375 | - } |
|
| 376 | - // load WP_Filesystem and set file permissions |
|
| 377 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 378 | - // write the file |
|
| 379 | - if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
| 380 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 381 | - $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
| 382 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
| 383 | - throw new EE_Error($msg); |
|
| 384 | - } |
|
| 385 | - return false; |
|
| 386 | - } |
|
| 387 | - return true; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Wrapper for WP_Filesystem_Base::delete |
|
| 392 | - * |
|
| 393 | - * @param string $filepath |
|
| 394 | - * @param boolean $recursive |
|
| 395 | - * @param boolean|string $type 'd' for directory, 'f' for file |
|
| 396 | - * @throws EE_Error if filesystem credentials are required |
|
| 397 | - * @return boolean |
|
| 398 | - */ |
|
| 399 | - public static function delete($filepath, $recursive = false, $type = false) |
|
| 400 | - { |
|
| 401 | - $wp_filesystem = EEH_File::_get_wp_filesystem(); |
|
| 402 | - return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * exists |
|
| 409 | - * checks if a file exists using the WP filesystem |
|
| 410 | - * @param string $full_file_path |
|
| 411 | - * @throws EE_Error if filesystem credentials are required |
|
| 412 | - * @return bool |
|
| 413 | - */ |
|
| 414 | - public static function exists($full_file_path = '') |
|
| 415 | - { |
|
| 416 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 417 | - return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * is_readable |
|
| 424 | - * checks if a file is_readable using the WP filesystem |
|
| 425 | - * |
|
| 426 | - * @param string $full_file_path |
|
| 427 | - * @throws EE_Error if filesystem credentials are required |
|
| 428 | - * @return bool |
|
| 429 | - */ |
|
| 430 | - public static function is_readable($full_file_path = '') |
|
| 431 | - { |
|
| 432 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 433 | - if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 434 | - return true; |
|
| 435 | - } else { |
|
| 436 | - return false; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * remove_filename_from_filepath |
|
| 444 | - * given a full path to a file including the filename itself, this removes the filename and returns the path, up to, but NOT including the filename OR slash |
|
| 445 | - * |
|
| 446 | - * @param string $full_file_path |
|
| 447 | - * @return string |
|
| 448 | - */ |
|
| 449 | - public static function remove_filename_from_filepath($full_file_path = '') |
|
| 450 | - { |
|
| 451 | - return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * get_filename_from_filepath. Arguably the same as basename() |
|
| 457 | - * |
|
| 458 | - * @param string $full_file_path |
|
| 459 | - * @return string |
|
| 460 | - */ |
|
| 461 | - public static function get_filename_from_filepath($full_file_path = '') |
|
| 462 | - { |
|
| 463 | - return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * get_file_extension |
|
| 469 | - * |
|
| 470 | - * @param string $full_file_path |
|
| 471 | - * @return string |
|
| 472 | - */ |
|
| 473 | - public static function get_file_extension($full_file_path = '') |
|
| 474 | - { |
|
| 475 | - return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * add_htaccess_deny_from_all so the webserver cannot access this folder |
|
| 482 | - * @param string $folder |
|
| 483 | - * @throws EE_Error if filesystem credentials are required |
|
| 484 | - * @return bool |
|
| 485 | - */ |
|
| 486 | - public static function add_htaccess_deny_from_all($folder = '') |
|
| 487 | - { |
|
| 488 | - $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
| 489 | - if (! EEH_File::exists($folder . '.htaccess')) { |
|
| 490 | - if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) { |
|
| 491 | - return false; |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - return true; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Adds an index file to this folder, so folks can't list all the file's contents |
|
| 500 | - * @param string $folder |
|
| 501 | - * @throws EE_Error if filesystem credentials are required |
|
| 502 | - * @return boolean |
|
| 503 | - */ |
|
| 504 | - public static function add_index_file($folder) |
|
| 505 | - { |
|
| 506 | - $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
| 507 | - if (! EEH_File::exists($folder . 'index.php')) { |
|
| 508 | - if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
| 509 | - return false; |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - return true; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php), |
|
| 519 | - * extract that classname. |
|
| 520 | - * @param string $file_path |
|
| 521 | - * @return string |
|
| 522 | - */ |
|
| 523 | - public static function get_classname_from_filepath_with_standard_filename($file_path) |
|
| 524 | - { |
|
| 525 | - // extract file from path |
|
| 526 | - $filename = basename($file_path); |
|
| 527 | - // now remove the first period and everything after |
|
| 528 | - $pos_of_first_period = strpos($filename, '.'); |
|
| 529 | - return substr($filename, 0, $pos_of_first_period); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * standardise_directory_separators |
|
| 536 | - * convert all directory separators in a file path. |
|
| 537 | - * @param string $file_path |
|
| 538 | - * @return string |
|
| 539 | - */ |
|
| 540 | - public static function standardise_directory_separators($file_path) |
|
| 541 | - { |
|
| 542 | - return str_replace(array( '\\', '/' ), '/', $file_path); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * end_with_directory_separator |
|
| 549 | - * ensures that file path ends with '/' |
|
| 550 | - * @param string $file_path |
|
| 551 | - * @return string |
|
| 552 | - */ |
|
| 553 | - public static function end_with_directory_separator($file_path) |
|
| 554 | - { |
|
| 555 | - return rtrim($file_path, '/\\') . '/'; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators |
|
| 562 | - * @param $file_path |
|
| 563 | - * @return string |
|
| 564 | - */ |
|
| 565 | - public static function standardise_and_end_with_directory_separator($file_path) |
|
| 566 | - { |
|
| 567 | - return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * takes the folder name (with or without trailing slash) and finds the files it in, |
|
| 574 | - * and what the class's name inside of each should be. |
|
| 575 | - * @param array $folder_paths |
|
| 576 | - * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically; |
|
| 577 | - * if FALSE (Default), returned array will be indexed by the filenames minus extensions. |
|
| 578 | - * Set it TRUE if you know there are files in the directory with the same name but different extensions |
|
| 579 | - * @throws EE_Error if filesystem credentials are required |
|
| 580 | - * @return array if $index_numerically == TRUE keys are numeric , |
|
| 581 | - * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
|
| 582 | - * and values are their filepaths |
|
| 583 | - */ |
|
| 584 | - public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false) |
|
| 585 | - { |
|
| 586 | - $class_to_folder_path = array(); |
|
| 587 | - foreach ($folder_paths as $folder_path) { |
|
| 588 | - $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
| 589 | - // load WP_Filesystem and set file permissions |
|
| 590 | - $files_in_folder = glob($folder_path . '*'); |
|
| 591 | - $class_to_folder_path = array(); |
|
| 592 | - if ($files_in_folder) { |
|
| 593 | - foreach ($files_in_folder as $file_path) { |
|
| 594 | - // only add files, not folders |
|
| 595 | - if (! is_dir($file_path)) { |
|
| 596 | - if ($index_numerically) { |
|
| 597 | - $class_to_folder_path[] = $file_path; |
|
| 598 | - } else { |
|
| 599 | - $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
| 600 | - $class_to_folder_path[ $classname ] = $file_path; |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - } |
|
| 606 | - return $class_to_folder_path; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Copies a file. Mostly a wrapper of WP_Filesystem::copy |
|
| 613 | - * @param string $source_file |
|
| 614 | - * @param string $destination_file |
|
| 615 | - * @param boolean $overwrite |
|
| 616 | - * @throws EE_Error if filesystem credentials are required |
|
| 617 | - * @return boolean success |
|
| 618 | - */ |
|
| 619 | - public static function copy($source_file, $destination_file, $overwrite = false) |
|
| 620 | - { |
|
| 621 | - $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
| 622 | - if (! EEH_File::exists($full_source_path)) { |
|
| 623 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 624 | - $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
| 625 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
| 626 | - throw new EE_Error($msg); |
|
| 627 | - } |
|
| 628 | - return false; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
| 632 | - $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
| 633 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 634 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 635 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 636 | - $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
| 637 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
| 638 | - throw new EE_Error($msg); |
|
| 639 | - } |
|
| 640 | - return false; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - // load WP_Filesystem and set file permissions |
|
| 644 | - $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
| 645 | - // write the file |
|
| 646 | - if (! $wp_filesystem->copy( |
|
| 647 | - EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
| 648 | - EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
| 649 | - $overwrite |
|
| 650 | - )) { |
|
| 651 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 652 | - $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
| 653 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
| 654 | - throw new EE_Error($msg); |
|
| 655 | - } |
|
| 656 | - return false; |
|
| 657 | - } |
|
| 658 | - return true; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * Reports whether or not the filepath is in the EE uploads folder or not |
|
| 663 | - * @param string $filepath |
|
| 664 | - * @return boolean |
|
| 665 | - */ |
|
| 666 | - public static function is_in_uploads_folder($filepath) |
|
| 667 | - { |
|
| 668 | - $uploads = wp_upload_dir(); |
|
| 669 | - return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Given a "local" filepath (what you probably thought was the only filepath), |
|
| 674 | - * converts it into a "remote" filepath (the filepath the currently-in-use |
|
| 675 | - * $wp_filesystem needs to use access the folder or file). |
|
| 676 | - * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins |
|
| 677 | - * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one |
|
| 678 | - * is in use, so you need to provide it |
|
| 679 | - * @param string $local_filepath the filepath to the folder/file locally |
|
| 680 | - * @throws EE_Error if filesystem credentials are required |
|
| 681 | - * @return string the remote filepath (eg the filepath the filesystem method, eg |
|
| 682 | - * ftp or ssh, will use to access the folder |
|
| 683 | - */ |
|
| 684 | - public static function convert_local_filepath_to_remote_filepath($local_filepath) |
|
| 685 | - { |
|
| 686 | - $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
| 687 | - return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
| 688 | - } |
|
| 27 | + /** |
|
| 28 | + * @var string $_credentials_form |
|
| 29 | + */ |
|
| 30 | + private static $_credentials_form; |
|
| 31 | + |
|
| 32 | + protected static $_wp_filesystem_direct; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @param string|null $filepath the filepath we want to work in. If its in the |
|
| 36 | + * wp uploads directory, we'll want to just use the filesystem directly. |
|
| 37 | + * If not provided, we have to assume its not in the uploads directory |
|
| 38 | + * @throws EE_Error if filesystem credentials are required |
|
| 39 | + * @return WP_Filesystem_Base |
|
| 40 | + */ |
|
| 41 | + private static function _get_wp_filesystem($filepath = null) |
|
| 42 | + { |
|
| 43 | + if (apply_filters( |
|
| 44 | + 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
|
| 45 | + $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
| 46 | + $filepath |
|
| 47 | + ) ) { |
|
| 48 | + if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
| 49 | + require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
| 50 | + $method = 'direct'; |
|
| 51 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); |
|
| 52 | + // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
|
| 53 | + if (! defined('FS_CHMOD_DIR')) { |
|
| 54 | + define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 )); |
|
| 55 | + } |
|
| 56 | + if (! defined('FS_CHMOD_FILE')) { |
|
| 57 | + define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 )); |
|
| 58 | + } |
|
| 59 | + require_once($wp_filesystem_direct_file); |
|
| 60 | + EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
| 61 | + } |
|
| 62 | + return EEH_File::$_wp_filesystem_direct; |
|
| 63 | + } |
|
| 64 | + global $wp_filesystem; |
|
| 65 | + // no filesystem setup ??? |
|
| 66 | + if (! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
| 67 | + // if some eager beaver's just trying to get in there too early... |
|
| 68 | + // let them do it, because we are one of those eager beavers! :P |
|
| 69 | + /** |
|
| 70 | + * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base |
|
| 71 | + * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process |
|
| 72 | + * is setup to mostly happen on 'init', and refactoring to have it happen on |
|
| 73 | + * 'wp_loaded' is too much work on a BETA milestone. |
|
| 74 | + * So this fix is expected to work if the WP files are owned by the server user, |
|
| 75 | + * but probably not if the user needs to enter their FTP credentials to modify files |
|
| 76 | + * and there may be troubles if the WP files are owned by a different user |
|
| 77 | + * than the server user. But both of these issues should exist in 4.4 and earlier too |
|
| 78 | + */ |
|
| 79 | + if (false && ! did_action('wp_loaded')) { |
|
| 80 | + $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
|
| 81 | + if (WP_DEBUG) { |
|
| 82 | + $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
| 83 | + } |
|
| 84 | + throw new EE_Error($msg); |
|
| 85 | + } else { |
|
| 86 | + // should be loaded if we are past the wp_loaded hook... |
|
| 87 | + if (! function_exists('WP_Filesystem')) { |
|
| 88 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
| 89 | + require_once(ABSPATH . 'wp-admin/includes/template.php'); |
|
| 90 | + } |
|
| 91 | + // turn on output buffering so that we can capture the credentials form |
|
| 92 | + ob_start(); |
|
| 93 | + $credentials = request_filesystem_credentials(''); |
|
| 94 | + // store credentials form for the time being |
|
| 95 | + EEH_File::$_credentials_form = ob_get_clean(); |
|
| 96 | + // basically check for direct or previously configured access |
|
| 97 | + if (! WP_Filesystem($credentials)) { |
|
| 98 | + // if credentials do NOT exist |
|
| 99 | + if ($credentials === false) { |
|
| 100 | + add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
| 101 | + throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
| 102 | + } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
| 103 | + add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
| 104 | + throw new EE_Error( |
|
| 105 | + sprintf( |
|
| 106 | + __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
| 107 | + $wp_filesystem->errors->get_error_message() |
|
| 108 | + ) |
|
| 109 | + ); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + return $wp_filesystem; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * display_request_filesystem_credentials_form |
|
| 119 | + */ |
|
| 120 | + public static function display_request_filesystem_credentials_form() |
|
| 121 | + { |
|
| 122 | + if (! empty(EEH_File::$_credentials_form)) { |
|
| 123 | + echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * verify_filepath_and_permissions |
|
| 131 | + * checks that a file is readable and has sufficient file permissions set to access |
|
| 132 | + * |
|
| 133 | + * @access public |
|
| 134 | + * @param string $full_file_path - full server path to the folder or file |
|
| 135 | + * @param string $file_name - name of file if checking a file |
|
| 136 | + * @param string $file_ext - file extension (ie: "php") if checking a file |
|
| 137 | + * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
| 138 | + * @throws EE_Error if filesystem credentials are required |
|
| 139 | + * @return bool |
|
| 140 | + */ |
|
| 141 | + public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') |
|
| 142 | + { |
|
| 143 | + // load WP_Filesystem and set file permissions |
|
| 144 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 145 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 146 | + if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 147 | + $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name; |
|
| 148 | + $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
| 149 | + $msg = sprintf( |
|
| 150 | + __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
| 151 | + $file_name, |
|
| 152 | + '<br />' |
|
| 153 | + ); |
|
| 154 | + if (EEH_File::exists($full_file_path)) { |
|
| 155 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
| 156 | + } else { |
|
| 157 | + // no file permissions means the file was not found |
|
| 158 | + $msg .= sprintf( |
|
| 159 | + __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
| 160 | + $full_file_path |
|
| 161 | + ); |
|
| 162 | + } |
|
| 163 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 164 | + throw new EE_Error($msg . '||' . $msg); |
|
| 165 | + } |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder |
|
| 175 | + * |
|
| 176 | + * @access private |
|
| 177 | + * @param string $full_file_path - full server path to the folder or file |
|
| 178 | + * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
| 179 | + * @throws EE_Error if filesystem credentials are required |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') |
|
| 183 | + { |
|
| 184 | + // load WP_Filesystem and set file permissions |
|
| 185 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 186 | + // check file permissions |
|
| 187 | + $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
| 188 | + if ($perms) { |
|
| 189 | + // file permissions exist, but way be set incorrectly |
|
| 190 | + $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : ''; |
|
| 191 | + $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
| 192 | + return sprintf( |
|
| 193 | + __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
| 194 | + $type_of_file, |
|
| 195 | + $perms |
|
| 196 | + ); |
|
| 197 | + } else { |
|
| 198 | + // file exists but file permissions could not be read ?!?! |
|
| 199 | + return sprintf( |
|
| 200 | + __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
| 201 | + $full_file_path |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * ensure_folder_exists_and_is_writable |
|
| 210 | + * ensures that a folder exists and is writable, will attempt to create folder if it does not exist |
|
| 211 | + * Also ensures all the parent folders exist, and if not tries to create them. |
|
| 212 | + * Also, if this function creates the folder, adds a .htaccess file and index.html file |
|
| 213 | + * @param string $folder |
|
| 214 | + * @throws EE_Error if the folder exists and is writeable, but for some reason we |
|
| 215 | + * can't write to it |
|
| 216 | + * @return bool false if folder isn't writable; true if it exists and is writeable, |
|
| 217 | + */ |
|
| 218 | + public static function ensure_folder_exists_and_is_writable($folder = '') |
|
| 219 | + { |
|
| 220 | + if (empty($folder)) { |
|
| 221 | + return false; |
|
| 222 | + } |
|
| 223 | + // remove ending / |
|
| 224 | + $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
| 225 | + $parent_folder = EEH_File::get_parent_folder($folder); |
|
| 226 | + // add / to folder |
|
| 227 | + $folder = EEH_File::end_with_directory_separator($folder); |
|
| 228 | + $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
| 229 | + if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 230 | + // ok so it doesn't exist. Does its parent? Can we write to it? |
|
| 231 | + if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 232 | + return false; |
|
| 233 | + } |
|
| 234 | + if (! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
| 235 | + return false; |
|
| 236 | + } else { |
|
| 237 | + if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 238 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 239 | + $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
| 240 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
| 241 | + throw new EE_Error($msg); |
|
| 242 | + } |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + EEH_File::add_index_file($folder); |
|
| 246 | + } |
|
| 247 | + } elseif (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + return true; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * verify_is_writable - checks if a file or folder is writable |
|
| 257 | + * @param string $full_path - full server path to file or folder |
|
| 258 | + * @param string $file_or_folder - whether checking a file or folder |
|
| 259 | + * @throws EE_Error if filesystem credentials are required |
|
| 260 | + * @return bool |
|
| 261 | + */ |
|
| 262 | + public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') |
|
| 263 | + { |
|
| 264 | + // load WP_Filesystem and set file permissions |
|
| 265 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
| 266 | + $full_path = EEH_File::standardise_directory_separators($full_path); |
|
| 267 | + if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
| 268 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 269 | + $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
| 270 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
| 271 | + throw new EE_Error($msg); |
|
| 272 | + } |
|
| 273 | + return false; |
|
| 274 | + } |
|
| 275 | + return true; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * ensure_file_exists_and_is_writable |
|
| 282 | + * ensures that a file exists and is writable, will attempt to create file if it does not exist. |
|
| 283 | + * Also ensures all the parent folders exist, and if not tries to create them. |
|
| 284 | + * @param string $full_file_path |
|
| 285 | + * @throws EE_Error if filesystem credentials are required |
|
| 286 | + * @return bool |
|
| 287 | + */ |
|
| 288 | + public static function ensure_file_exists_and_is_writable($full_file_path = '') |
|
| 289 | + { |
|
| 290 | + // load WP_Filesystem and set file permissions |
|
| 291 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 292 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 293 | + $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
| 294 | + if (! EEH_File::exists($full_file_path)) { |
|
| 295 | + if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 296 | + return false; |
|
| 297 | + } |
|
| 298 | + if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 299 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 300 | + $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
| 301 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
| 302 | + throw new EE_Error($msg); |
|
| 303 | + } |
|
| 304 | + return false; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + if (! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
| 308 | + return false; |
|
| 309 | + } |
|
| 310 | + return true; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Gets the parent folder. If provided with file, gets the folder that contains it. |
|
| 315 | + * If provided a folder, gets its parent folder. |
|
| 316 | + * @param string $file_or_folder_path |
|
| 317 | + * @return string parent folder, ENDING with a directory separator |
|
| 318 | + */ |
|
| 319 | + public static function get_parent_folder($file_or_folder_path) |
|
| 320 | + { |
|
| 321 | + // find the last /, ignoring a / on the very end |
|
| 322 | + // eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
|
| 323 | + // parent folder, "/var/something/" |
|
| 324 | + $ds = strlen($file_or_folder_path) > 1 |
|
| 325 | + ? strrpos($file_or_folder_path, '/', -2) |
|
| 326 | + : strlen($file_or_folder_path); |
|
| 327 | + return substr($file_or_folder_path, 0, $ds + 1); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + // public static function ensure_folder_exists_recursively( $folder ) { |
|
| 331 | + // |
|
| 332 | + // } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * get_file_contents |
|
| 338 | + * @param string $full_file_path |
|
| 339 | + * @throws EE_Error if filesystem credentials are required |
|
| 340 | + * @return string |
|
| 341 | + */ |
|
| 342 | + public static function get_file_contents($full_file_path = '') |
|
| 343 | + { |
|
| 344 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 345 | + if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
| 346 | + // load WP_Filesystem and set file permissions |
|
| 347 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 348 | + return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
| 349 | + } |
|
| 350 | + return ''; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * write_file |
|
| 357 | + * @param string $full_file_path |
|
| 358 | + * @param string $file_contents - the content to be written to the file |
|
| 359 | + * @param string $file_type |
|
| 360 | + * @throws EE_Error if filesystem credentials are required |
|
| 361 | + * @return bool |
|
| 362 | + */ |
|
| 363 | + public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') |
|
| 364 | + { |
|
| 365 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 366 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : ''; |
|
| 367 | + $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
| 368 | + if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 369 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 370 | + $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
| 371 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
| 372 | + throw new EE_Error($msg); |
|
| 373 | + } |
|
| 374 | + return false; |
|
| 375 | + } |
|
| 376 | + // load WP_Filesystem and set file permissions |
|
| 377 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 378 | + // write the file |
|
| 379 | + if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
| 380 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 381 | + $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
| 382 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
| 383 | + throw new EE_Error($msg); |
|
| 384 | + } |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 387 | + return true; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Wrapper for WP_Filesystem_Base::delete |
|
| 392 | + * |
|
| 393 | + * @param string $filepath |
|
| 394 | + * @param boolean $recursive |
|
| 395 | + * @param boolean|string $type 'd' for directory, 'f' for file |
|
| 396 | + * @throws EE_Error if filesystem credentials are required |
|
| 397 | + * @return boolean |
|
| 398 | + */ |
|
| 399 | + public static function delete($filepath, $recursive = false, $type = false) |
|
| 400 | + { |
|
| 401 | + $wp_filesystem = EEH_File::_get_wp_filesystem(); |
|
| 402 | + return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * exists |
|
| 409 | + * checks if a file exists using the WP filesystem |
|
| 410 | + * @param string $full_file_path |
|
| 411 | + * @throws EE_Error if filesystem credentials are required |
|
| 412 | + * @return bool |
|
| 413 | + */ |
|
| 414 | + public static function exists($full_file_path = '') |
|
| 415 | + { |
|
| 416 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 417 | + return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * is_readable |
|
| 424 | + * checks if a file is_readable using the WP filesystem |
|
| 425 | + * |
|
| 426 | + * @param string $full_file_path |
|
| 427 | + * @throws EE_Error if filesystem credentials are required |
|
| 428 | + * @return bool |
|
| 429 | + */ |
|
| 430 | + public static function is_readable($full_file_path = '') |
|
| 431 | + { |
|
| 432 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
| 433 | + if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 434 | + return true; |
|
| 435 | + } else { |
|
| 436 | + return false; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * remove_filename_from_filepath |
|
| 444 | + * given a full path to a file including the filename itself, this removes the filename and returns the path, up to, but NOT including the filename OR slash |
|
| 445 | + * |
|
| 446 | + * @param string $full_file_path |
|
| 447 | + * @return string |
|
| 448 | + */ |
|
| 449 | + public static function remove_filename_from_filepath($full_file_path = '') |
|
| 450 | + { |
|
| 451 | + return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * get_filename_from_filepath. Arguably the same as basename() |
|
| 457 | + * |
|
| 458 | + * @param string $full_file_path |
|
| 459 | + * @return string |
|
| 460 | + */ |
|
| 461 | + public static function get_filename_from_filepath($full_file_path = '') |
|
| 462 | + { |
|
| 463 | + return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * get_file_extension |
|
| 469 | + * |
|
| 470 | + * @param string $full_file_path |
|
| 471 | + * @return string |
|
| 472 | + */ |
|
| 473 | + public static function get_file_extension($full_file_path = '') |
|
| 474 | + { |
|
| 475 | + return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * add_htaccess_deny_from_all so the webserver cannot access this folder |
|
| 482 | + * @param string $folder |
|
| 483 | + * @throws EE_Error if filesystem credentials are required |
|
| 484 | + * @return bool |
|
| 485 | + */ |
|
| 486 | + public static function add_htaccess_deny_from_all($folder = '') |
|
| 487 | + { |
|
| 488 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
| 489 | + if (! EEH_File::exists($folder . '.htaccess')) { |
|
| 490 | + if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) { |
|
| 491 | + return false; |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + return true; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Adds an index file to this folder, so folks can't list all the file's contents |
|
| 500 | + * @param string $folder |
|
| 501 | + * @throws EE_Error if filesystem credentials are required |
|
| 502 | + * @return boolean |
|
| 503 | + */ |
|
| 504 | + public static function add_index_file($folder) |
|
| 505 | + { |
|
| 506 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
| 507 | + if (! EEH_File::exists($folder . 'index.php')) { |
|
| 508 | + if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
| 509 | + return false; |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + return true; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php), |
|
| 519 | + * extract that classname. |
|
| 520 | + * @param string $file_path |
|
| 521 | + * @return string |
|
| 522 | + */ |
|
| 523 | + public static function get_classname_from_filepath_with_standard_filename($file_path) |
|
| 524 | + { |
|
| 525 | + // extract file from path |
|
| 526 | + $filename = basename($file_path); |
|
| 527 | + // now remove the first period and everything after |
|
| 528 | + $pos_of_first_period = strpos($filename, '.'); |
|
| 529 | + return substr($filename, 0, $pos_of_first_period); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * standardise_directory_separators |
|
| 536 | + * convert all directory separators in a file path. |
|
| 537 | + * @param string $file_path |
|
| 538 | + * @return string |
|
| 539 | + */ |
|
| 540 | + public static function standardise_directory_separators($file_path) |
|
| 541 | + { |
|
| 542 | + return str_replace(array( '\\', '/' ), '/', $file_path); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * end_with_directory_separator |
|
| 549 | + * ensures that file path ends with '/' |
|
| 550 | + * @param string $file_path |
|
| 551 | + * @return string |
|
| 552 | + */ |
|
| 553 | + public static function end_with_directory_separator($file_path) |
|
| 554 | + { |
|
| 555 | + return rtrim($file_path, '/\\') . '/'; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators |
|
| 562 | + * @param $file_path |
|
| 563 | + * @return string |
|
| 564 | + */ |
|
| 565 | + public static function standardise_and_end_with_directory_separator($file_path) |
|
| 566 | + { |
|
| 567 | + return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * takes the folder name (with or without trailing slash) and finds the files it in, |
|
| 574 | + * and what the class's name inside of each should be. |
|
| 575 | + * @param array $folder_paths |
|
| 576 | + * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically; |
|
| 577 | + * if FALSE (Default), returned array will be indexed by the filenames minus extensions. |
|
| 578 | + * Set it TRUE if you know there are files in the directory with the same name but different extensions |
|
| 579 | + * @throws EE_Error if filesystem credentials are required |
|
| 580 | + * @return array if $index_numerically == TRUE keys are numeric , |
|
| 581 | + * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
|
| 582 | + * and values are their filepaths |
|
| 583 | + */ |
|
| 584 | + public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false) |
|
| 585 | + { |
|
| 586 | + $class_to_folder_path = array(); |
|
| 587 | + foreach ($folder_paths as $folder_path) { |
|
| 588 | + $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
| 589 | + // load WP_Filesystem and set file permissions |
|
| 590 | + $files_in_folder = glob($folder_path . '*'); |
|
| 591 | + $class_to_folder_path = array(); |
|
| 592 | + if ($files_in_folder) { |
|
| 593 | + foreach ($files_in_folder as $file_path) { |
|
| 594 | + // only add files, not folders |
|
| 595 | + if (! is_dir($file_path)) { |
|
| 596 | + if ($index_numerically) { |
|
| 597 | + $class_to_folder_path[] = $file_path; |
|
| 598 | + } else { |
|
| 599 | + $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
| 600 | + $class_to_folder_path[ $classname ] = $file_path; |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + } |
|
| 606 | + return $class_to_folder_path; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * Copies a file. Mostly a wrapper of WP_Filesystem::copy |
|
| 613 | + * @param string $source_file |
|
| 614 | + * @param string $destination_file |
|
| 615 | + * @param boolean $overwrite |
|
| 616 | + * @throws EE_Error if filesystem credentials are required |
|
| 617 | + * @return boolean success |
|
| 618 | + */ |
|
| 619 | + public static function copy($source_file, $destination_file, $overwrite = false) |
|
| 620 | + { |
|
| 621 | + $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
| 622 | + if (! EEH_File::exists($full_source_path)) { |
|
| 623 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 624 | + $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
| 625 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
| 626 | + throw new EE_Error($msg); |
|
| 627 | + } |
|
| 628 | + return false; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
| 632 | + $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
| 633 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 634 | + if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 635 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 636 | + $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
| 637 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
| 638 | + throw new EE_Error($msg); |
|
| 639 | + } |
|
| 640 | + return false; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + // load WP_Filesystem and set file permissions |
|
| 644 | + $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
| 645 | + // write the file |
|
| 646 | + if (! $wp_filesystem->copy( |
|
| 647 | + EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
| 648 | + EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
| 649 | + $overwrite |
|
| 650 | + )) { |
|
| 651 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 652 | + $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
| 653 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
| 654 | + throw new EE_Error($msg); |
|
| 655 | + } |
|
| 656 | + return false; |
|
| 657 | + } |
|
| 658 | + return true; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * Reports whether or not the filepath is in the EE uploads folder or not |
|
| 663 | + * @param string $filepath |
|
| 664 | + * @return boolean |
|
| 665 | + */ |
|
| 666 | + public static function is_in_uploads_folder($filepath) |
|
| 667 | + { |
|
| 668 | + $uploads = wp_upload_dir(); |
|
| 669 | + return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Given a "local" filepath (what you probably thought was the only filepath), |
|
| 674 | + * converts it into a "remote" filepath (the filepath the currently-in-use |
|
| 675 | + * $wp_filesystem needs to use access the folder or file). |
|
| 676 | + * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins |
|
| 677 | + * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one |
|
| 678 | + * is in use, so you need to provide it |
|
| 679 | + * @param string $local_filepath the filepath to the folder/file locally |
|
| 680 | + * @throws EE_Error if filesystem credentials are required |
|
| 681 | + * @return string the remote filepath (eg the filepath the filesystem method, eg |
|
| 682 | + * ftp or ssh, will use to access the folder |
|
| 683 | + */ |
|
| 684 | + public static function convert_local_filepath_to_remote_filepath($local_filepath) |
|
| 685 | + { |
|
| 686 | + $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
| 687 | + return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
| 688 | + } |
|
| 689 | 689 | } |
@@ -44,17 +44,17 @@ discard block |
||
| 44 | 44 | 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
| 45 | 45 | $filepath && EEH_File::is_in_uploads_folder($filepath), |
| 46 | 46 | $filepath |
| 47 | - ) ) { |
|
| 48 | - if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
| 49 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
| 47 | + )) { |
|
| 48 | + if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
| 49 | + require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php'); |
|
| 50 | 50 | $method = 'direct'; |
| 51 | - $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); |
|
| 51 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method); |
|
| 52 | 52 | // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
| 53 | - if (! defined('FS_CHMOD_DIR')) { |
|
| 54 | - define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 )); |
|
| 53 | + if ( ! defined('FS_CHMOD_DIR')) { |
|
| 54 | + define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755)); |
|
| 55 | 55 | } |
| 56 | - if (! defined('FS_CHMOD_FILE')) { |
|
| 57 | - define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 )); |
|
| 56 | + if ( ! defined('FS_CHMOD_FILE')) { |
|
| 57 | + define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644)); |
|
| 58 | 58 | } |
| 59 | 59 | require_once($wp_filesystem_direct_file); |
| 60 | 60 | EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | global $wp_filesystem; |
| 65 | 65 | // no filesystem setup ??? |
| 66 | - if (! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
| 66 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
| 67 | 67 | // if some eager beaver's just trying to get in there too early... |
| 68 | 68 | // let them do it, because we are one of those eager beavers! :P |
| 69 | 69 | /** |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | if (false && ! did_action('wp_loaded')) { |
| 80 | 80 | $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
| 81 | 81 | if (WP_DEBUG) { |
| 82 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
| 82 | + $msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
| 83 | 83 | } |
| 84 | 84 | throw new EE_Error($msg); |
| 85 | 85 | } else { |
| 86 | 86 | // should be loaded if we are past the wp_loaded hook... |
| 87 | - if (! function_exists('WP_Filesystem')) { |
|
| 88 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
| 89 | - require_once(ABSPATH . 'wp-admin/includes/template.php'); |
|
| 87 | + if ( ! function_exists('WP_Filesystem')) { |
|
| 88 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
| 89 | + require_once(ABSPATH.'wp-admin/includes/template.php'); |
|
| 90 | 90 | } |
| 91 | 91 | // turn on output buffering so that we can capture the credentials form |
| 92 | 92 | ob_start(); |
@@ -94,13 +94,13 @@ discard block |
||
| 94 | 94 | // store credentials form for the time being |
| 95 | 95 | EEH_File::$_credentials_form = ob_get_clean(); |
| 96 | 96 | // basically check for direct or previously configured access |
| 97 | - if (! WP_Filesystem($credentials)) { |
|
| 97 | + if ( ! WP_Filesystem($credentials)) { |
|
| 98 | 98 | // if credentials do NOT exist |
| 99 | 99 | if ($credentials === false) { |
| 100 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
| 100 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
| 101 | 101 | throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
| 102 | 102 | } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
| 103 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
| 103 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
| 104 | 104 | throw new EE_Error( |
| 105 | 105 | sprintf( |
| 106 | 106 | __('WP Filesystem Error: $1%s', 'event_espresso'), |
@@ -119,8 +119,8 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public static function display_request_filesystem_credentials_form() |
| 121 | 121 | { |
| 122 | - if (! empty(EEH_File::$_credentials_form)) { |
|
| 123 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
| 122 | + if ( ! empty(EEH_File::$_credentials_form)) { |
|
| 123 | + echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>'; |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | // load WP_Filesystem and set file permissions |
| 144 | 144 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
| 145 | 145 | $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
| 146 | - if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 147 | - $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name; |
|
| 146 | + if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 147 | + $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name; |
|
| 148 | 148 | $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
| 149 | 149 | $msg = sprintf( |
| 150 | 150 | __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | ); |
| 162 | 162 | } |
| 163 | 163 | if (defined('WP_DEBUG') && WP_DEBUG) { |
| 164 | - throw new EE_Error($msg . '||' . $msg); |
|
| 164 | + throw new EE_Error($msg.'||'.$msg); |
|
| 165 | 165 | } |
| 166 | 166 | return false; |
| 167 | 167 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
| 188 | 188 | if ($perms) { |
| 189 | 189 | // file permissions exist, but way be set incorrectly |
| 190 | - $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : ''; |
|
| 190 | + $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : ''; |
|
| 191 | 191 | $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
| 192 | 192 | return sprintf( |
| 193 | 193 | __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
@@ -226,15 +226,15 @@ discard block |
||
| 226 | 226 | // add / to folder |
| 227 | 227 | $folder = EEH_File::end_with_directory_separator($folder); |
| 228 | 228 | $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
| 229 | - if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 229 | + if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 230 | 230 | // ok so it doesn't exist. Does its parent? Can we write to it? |
| 231 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 231 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 232 | 232 | return false; |
| 233 | 233 | } |
| 234 | - if (! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
| 234 | + if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
| 235 | 235 | return false; |
| 236 | 236 | } else { |
| 237 | - if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 237 | + if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
| 238 | 238 | if (defined('WP_DEBUG') && WP_DEBUG) { |
| 239 | 239 | $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
| 240 | 240 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | } |
| 245 | 245 | EEH_File::add_index_file($folder); |
| 246 | 246 | } |
| 247 | - } elseif (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 247 | + } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 248 | 248 | return false; |
| 249 | 249 | } |
| 250 | 250 | return true; |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | // load WP_Filesystem and set file permissions |
| 265 | 265 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
| 266 | 266 | $full_path = EEH_File::standardise_directory_separators($full_path); |
| 267 | - if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
| 267 | + if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
| 268 | 268 | if (defined('WP_DEBUG') && WP_DEBUG) { |
| 269 | 269 | $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
| 270 | 270 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
@@ -291,11 +291,11 @@ discard block |
||
| 291 | 291 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
| 292 | 292 | $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
| 293 | 293 | $parent_folder = EEH_File::get_parent_folder($full_file_path); |
| 294 | - if (! EEH_File::exists($full_file_path)) { |
|
| 295 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 294 | + if ( ! EEH_File::exists($full_file_path)) { |
|
| 295 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
| 296 | 296 | return false; |
| 297 | 297 | } |
| 298 | - if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 298 | + if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
| 299 | 299 | if (defined('WP_DEBUG') && WP_DEBUG) { |
| 300 | 300 | $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
| 301 | 301 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | return false; |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | - if (! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
| 307 | + if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
| 308 | 308 | return false; |
| 309 | 309 | } |
| 310 | 310 | return true; |
@@ -363,9 +363,9 @@ discard block |
||
| 363 | 363 | public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') |
| 364 | 364 | { |
| 365 | 365 | $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
| 366 | - $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : ''; |
|
| 366 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : ''; |
|
| 367 | 367 | $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
| 368 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 368 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 369 | 369 | if (defined('WP_DEBUG') && WP_DEBUG) { |
| 370 | 370 | $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
| 371 | 371 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | // load WP_Filesystem and set file permissions |
| 377 | 377 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
| 378 | 378 | // write the file |
| 379 | - if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
| 379 | + if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
| 380 | 380 | if (defined('WP_DEBUG') && WP_DEBUG) { |
| 381 | 381 | $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
| 382 | 382 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
@@ -486,8 +486,8 @@ discard block |
||
| 486 | 486 | public static function add_htaccess_deny_from_all($folder = '') |
| 487 | 487 | { |
| 488 | 488 | $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
| 489 | - if (! EEH_File::exists($folder . '.htaccess')) { |
|
| 490 | - if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) { |
|
| 489 | + if ( ! EEH_File::exists($folder.'.htaccess')) { |
|
| 490 | + if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) { |
|
| 491 | 491 | return false; |
| 492 | 492 | } |
| 493 | 493 | } |
@@ -504,8 +504,8 @@ discard block |
||
| 504 | 504 | public static function add_index_file($folder) |
| 505 | 505 | { |
| 506 | 506 | $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
| 507 | - if (! EEH_File::exists($folder . 'index.php')) { |
|
| 508 | - if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
| 507 | + if ( ! EEH_File::exists($folder.'index.php')) { |
|
| 508 | + if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
| 509 | 509 | return false; |
| 510 | 510 | } |
| 511 | 511 | } |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | */ |
| 540 | 540 | public static function standardise_directory_separators($file_path) |
| 541 | 541 | { |
| 542 | - return str_replace(array( '\\', '/' ), '/', $file_path); |
|
| 542 | + return str_replace(array('\\', '/'), '/', $file_path); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | */ |
| 553 | 553 | public static function end_with_directory_separator($file_path) |
| 554 | 554 | { |
| 555 | - return rtrim($file_path, '/\\') . '/'; |
|
| 555 | + return rtrim($file_path, '/\\').'/'; |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | |
@@ -587,17 +587,17 @@ discard block |
||
| 587 | 587 | foreach ($folder_paths as $folder_path) { |
| 588 | 588 | $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
| 589 | 589 | // load WP_Filesystem and set file permissions |
| 590 | - $files_in_folder = glob($folder_path . '*'); |
|
| 590 | + $files_in_folder = glob($folder_path.'*'); |
|
| 591 | 591 | $class_to_folder_path = array(); |
| 592 | 592 | if ($files_in_folder) { |
| 593 | 593 | foreach ($files_in_folder as $file_path) { |
| 594 | 594 | // only add files, not folders |
| 595 | - if (! is_dir($file_path)) { |
|
| 595 | + if ( ! is_dir($file_path)) { |
|
| 596 | 596 | if ($index_numerically) { |
| 597 | 597 | $class_to_folder_path[] = $file_path; |
| 598 | 598 | } else { |
| 599 | 599 | $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
| 600 | - $class_to_folder_path[ $classname ] = $file_path; |
|
| 600 | + $class_to_folder_path[$classname] = $file_path; |
|
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | } |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | public static function copy($source_file, $destination_file, $overwrite = false) |
| 620 | 620 | { |
| 621 | 621 | $full_source_path = EEH_File::standardise_directory_separators($source_file); |
| 622 | - if (! EEH_File::exists($full_source_path)) { |
|
| 622 | + if ( ! EEH_File::exists($full_source_path)) { |
|
| 623 | 623 | if (defined('WP_DEBUG') && WP_DEBUG) { |
| 624 | 624 | $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
| 625 | 625 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
| 632 | 632 | $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
| 633 | 633 | EEH_File::ensure_folder_exists_and_is_writable($folder); |
| 634 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 634 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 635 | 635 | if (defined('WP_DEBUG') && WP_DEBUG) { |
| 636 | 636 | $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
| 637 | 637 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | // load WP_Filesystem and set file permissions |
| 644 | 644 | $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
| 645 | 645 | // write the file |
| 646 | - if (! $wp_filesystem->copy( |
|
| 646 | + if ( ! $wp_filesystem->copy( |
|
| 647 | 647 | EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
| 648 | 648 | EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
| 649 | 649 | $overwrite |
@@ -684,6 +684,6 @@ discard block |
||
| 684 | 684 | public static function convert_local_filepath_to_remote_filepath($local_filepath) |
| 685 | 685 | { |
| 686 | 686 | $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
| 687 | - return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
| 687 | + return str_replace(WP_CONTENT_DIR.'/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
| 688 | 688 | } |
| 689 | 689 | } |
@@ -15,296 +15,296 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * instance of the EE_System object |
|
| 20 | - * |
|
| 21 | - * @var $_instance |
|
| 22 | - * @access private |
|
| 23 | - */ |
|
| 24 | - private static $_instance = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * $_autoloaders |
|
| 28 | - * @var array $_autoloaders |
|
| 29 | - * @access private |
|
| 30 | - */ |
|
| 31 | - private static $_autoloaders; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * set to "paths" to display autoloader class => path mappings |
|
| 35 | - * set to "times" to display autoloader loading times |
|
| 36 | - * set to "all" to display both |
|
| 37 | - * |
|
| 38 | - * @var string $debug |
|
| 39 | - * @access private |
|
| 40 | - */ |
|
| 41 | - public static $debug = false; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * class constructor |
|
| 46 | - * |
|
| 47 | - * @access private |
|
| 48 | - * @return \EEH_Autoloader |
|
| 49 | - * @throws Exception |
|
| 50 | - */ |
|
| 51 | - private function __construct() |
|
| 52 | - { |
|
| 53 | - if (self::$_autoloaders === null) { |
|
| 54 | - self::$_autoloaders = array(); |
|
| 55 | - $this->_register_custom_autoloaders(); |
|
| 56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @access public |
|
| 64 | - * @return EEH_Autoloader |
|
| 65 | - */ |
|
| 66 | - public static function instance() |
|
| 67 | - { |
|
| 68 | - // check if class object is instantiated |
|
| 69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
| 70 | - self::$_instance = new self(); |
|
| 71 | - } |
|
| 72 | - return self::$_instance; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * espresso_autoloader |
|
| 79 | - * |
|
| 80 | - * @access public |
|
| 81 | - * @param $class_name |
|
| 82 | - * @internal param $className |
|
| 83 | - * @internal param string $class_name - simple class name ie: session |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public static function espresso_autoloader($class_name) |
|
| 87 | - { |
|
| 88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * register_autoloader |
|
| 97 | - * |
|
| 98 | - * @access public |
|
| 99 | - * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
| 100 | - * @param bool $read_check true if we need to check whether the file is readable or not. |
|
| 101 | - * @param bool $debug **deprecated** |
|
| 102 | - * @throws \EE_Error |
|
| 103 | - */ |
|
| 104 | - public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
| 105 | - { |
|
| 106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
| 107 | - foreach ($class_paths as $class => $path) { |
|
| 108 | - // skip all files that are not PHP |
|
| 109 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
| 110 | - continue; |
|
| 111 | - } |
|
| 112 | - // don't give up! you gotta... |
|
| 113 | - // get some class |
|
| 114 | - if (empty($class)) { |
|
| 115 | - throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
| 116 | - } |
|
| 117 | - // one day you will find the path young grasshopper |
|
| 118 | - if (empty($path)) { |
|
| 119 | - throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
| 120 | - } |
|
| 121 | - // is file readable ? |
|
| 122 | - if ($read_check && ! is_readable($path)) { |
|
| 123 | - throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
| 124 | - } |
|
| 125 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
| 126 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path); |
|
| 127 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
| 128 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * get_autoloaders |
|
| 139 | - * |
|
| 140 | - * @access public |
|
| 141 | - * @return array |
|
| 142 | - */ |
|
| 143 | - public static function get_autoloaders() |
|
| 144 | - { |
|
| 145 | - return self::$_autoloaders; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * register core, model and class 'autoloaders' |
|
| 151 | - * |
|
| 152 | - * @access private |
|
| 153 | - * @return void |
|
| 154 | - * @throws EE_Error |
|
| 155 | - */ |
|
| 156 | - private function _register_custom_autoloaders() |
|
| 157 | - { |
|
| 158 | - EEH_Autoloader::$debug = ''; |
|
| 159 | - \EEH_Autoloader::register_helpers_autoloaders(); |
|
| 160 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
| 161 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
| 162 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
| 163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
| 164 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
| 165 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
| 166 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
| 167 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 168 | - EEH_Debug_Tools::instance()->show_times(); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * register core, model and class 'autoloaders' |
|
| 176 | - * |
|
| 177 | - * @access public |
|
| 178 | - */ |
|
| 179 | - public static function register_helpers_autoloaders() |
|
| 180 | - { |
|
| 181 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * register core, model and class 'autoloaders' |
|
| 189 | - * |
|
| 190 | - * @access public |
|
| 191 | - * @return void |
|
| 192 | - */ |
|
| 193 | - public static function register_form_sections_autoloaders() |
|
| 194 | - { |
|
| 195 | - // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * register core, model and class 'autoloaders' |
|
| 201 | - * |
|
| 202 | - * @access public |
|
| 203 | - * @return void |
|
| 204 | - * @throws EE_Error |
|
| 205 | - */ |
|
| 206 | - public static function register_line_item_display_autoloaders() |
|
| 207 | - { |
|
| 208 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * register core, model and class 'autoloaders' |
|
| 214 | - * |
|
| 215 | - * @access public |
|
| 216 | - * @return void |
|
| 217 | - * @throws EE_Error |
|
| 218 | - */ |
|
| 219 | - public static function register_line_item_filter_autoloaders() |
|
| 220 | - { |
|
| 221 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * register template part 'autoloaders' |
|
| 227 | - * |
|
| 228 | - * @access public |
|
| 229 | - * @return void |
|
| 230 | - * @throws EE_Error |
|
| 231 | - */ |
|
| 232 | - public static function register_template_part_autoloaders() |
|
| 233 | - { |
|
| 234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @return void |
|
| 240 | - * @throws EE_Error |
|
| 241 | - */ |
|
| 242 | - public static function register_business_classes() |
|
| 243 | - { |
|
| 244 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
| 251 | - * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
| 252 | - * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
| 253 | - * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
| 254 | - * time the autoloader is used |
|
| 255 | - * |
|
| 256 | - * @param string $folder name, with or without trailing /, doesn't matter |
|
| 257 | - * @param bool $recursive |
|
| 258 | - * @param bool $debug **deprecated** |
|
| 259 | - * @throws \EE_Error |
|
| 260 | - */ |
|
| 261 | - public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
| 262 | - { |
|
| 263 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
| 264 | - EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
| 265 | - } |
|
| 266 | - // make sure last char is a / |
|
| 267 | - $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : ''; |
|
| 268 | - $class_to_filepath_map = array(); |
|
| 269 | - $exclude = array( 'index' ); |
|
| 270 | - // get all the files in that folder that end in php |
|
| 271 | - $filepaths = glob($folder.'*'); |
|
| 272 | - |
|
| 273 | - if (empty($filepaths)) { |
|
| 274 | - return; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - foreach ($filepaths as $filepath) { |
|
| 278 | - if (substr($filepath, -4, 4) === '.php') { |
|
| 279 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
| 280 | - if (! in_array($class_name, $exclude)) { |
|
| 281 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
| 282 | - } |
|
| 283 | - } elseif ($recursive) { |
|
| 284 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
| 288 | - self::register_autoloader($class_to_filepath_map, false, $debug); |
|
| 289 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 290 | - EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * add_alias |
|
| 298 | - * register additional autoloader based on variation of the classname for an existing autoloader |
|
| 299 | - * |
|
| 300 | - * @access public |
|
| 301 | - * @param string $class_name - simple class name ie: EE_Session |
|
| 302 | - * @param string $alias - variation on class name ie: EE_session, session, etc |
|
| 303 | - */ |
|
| 304 | - public static function add_alias($class_name, $alias) |
|
| 305 | - { |
|
| 306 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 307 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
| 308 | - } |
|
| 309 | - } |
|
| 18 | + /** |
|
| 19 | + * instance of the EE_System object |
|
| 20 | + * |
|
| 21 | + * @var $_instance |
|
| 22 | + * @access private |
|
| 23 | + */ |
|
| 24 | + private static $_instance = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * $_autoloaders |
|
| 28 | + * @var array $_autoloaders |
|
| 29 | + * @access private |
|
| 30 | + */ |
|
| 31 | + private static $_autoloaders; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * set to "paths" to display autoloader class => path mappings |
|
| 35 | + * set to "times" to display autoloader loading times |
|
| 36 | + * set to "all" to display both |
|
| 37 | + * |
|
| 38 | + * @var string $debug |
|
| 39 | + * @access private |
|
| 40 | + */ |
|
| 41 | + public static $debug = false; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * class constructor |
|
| 46 | + * |
|
| 47 | + * @access private |
|
| 48 | + * @return \EEH_Autoloader |
|
| 49 | + * @throws Exception |
|
| 50 | + */ |
|
| 51 | + private function __construct() |
|
| 52 | + { |
|
| 53 | + if (self::$_autoloaders === null) { |
|
| 54 | + self::$_autoloaders = array(); |
|
| 55 | + $this->_register_custom_autoloaders(); |
|
| 56 | + spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @access public |
|
| 64 | + * @return EEH_Autoloader |
|
| 65 | + */ |
|
| 66 | + public static function instance() |
|
| 67 | + { |
|
| 68 | + // check if class object is instantiated |
|
| 69 | + if (! self::$_instance instanceof EEH_Autoloader) { |
|
| 70 | + self::$_instance = new self(); |
|
| 71 | + } |
|
| 72 | + return self::$_instance; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * espresso_autoloader |
|
| 79 | + * |
|
| 80 | + * @access public |
|
| 81 | + * @param $class_name |
|
| 82 | + * @internal param $className |
|
| 83 | + * @internal param string $class_name - simple class name ie: session |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public static function espresso_autoloader($class_name) |
|
| 87 | + { |
|
| 88 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 89 | + require_once(self::$_autoloaders[ $class_name ]); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * register_autoloader |
|
| 97 | + * |
|
| 98 | + * @access public |
|
| 99 | + * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
| 100 | + * @param bool $read_check true if we need to check whether the file is readable or not. |
|
| 101 | + * @param bool $debug **deprecated** |
|
| 102 | + * @throws \EE_Error |
|
| 103 | + */ |
|
| 104 | + public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
| 105 | + { |
|
| 106 | + $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
| 107 | + foreach ($class_paths as $class => $path) { |
|
| 108 | + // skip all files that are not PHP |
|
| 109 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
| 110 | + continue; |
|
| 111 | + } |
|
| 112 | + // don't give up! you gotta... |
|
| 113 | + // get some class |
|
| 114 | + if (empty($class)) { |
|
| 115 | + throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
| 116 | + } |
|
| 117 | + // one day you will find the path young grasshopper |
|
| 118 | + if (empty($path)) { |
|
| 119 | + throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
| 120 | + } |
|
| 121 | + // is file readable ? |
|
| 122 | + if ($read_check && ! is_readable($path)) { |
|
| 123 | + throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
| 124 | + } |
|
| 125 | + if (! isset(self::$_autoloaders[ $class ])) { |
|
| 126 | + self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path); |
|
| 127 | + if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
| 128 | + EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * get_autoloaders |
|
| 139 | + * |
|
| 140 | + * @access public |
|
| 141 | + * @return array |
|
| 142 | + */ |
|
| 143 | + public static function get_autoloaders() |
|
| 144 | + { |
|
| 145 | + return self::$_autoloaders; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * register core, model and class 'autoloaders' |
|
| 151 | + * |
|
| 152 | + * @access private |
|
| 153 | + * @return void |
|
| 154 | + * @throws EE_Error |
|
| 155 | + */ |
|
| 156 | + private function _register_custom_autoloaders() |
|
| 157 | + { |
|
| 158 | + EEH_Autoloader::$debug = ''; |
|
| 159 | + \EEH_Autoloader::register_helpers_autoloaders(); |
|
| 160 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
| 161 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
| 162 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
| 163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
| 164 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
| 165 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
| 166 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
| 167 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 168 | + EEH_Debug_Tools::instance()->show_times(); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * register core, model and class 'autoloaders' |
|
| 176 | + * |
|
| 177 | + * @access public |
|
| 178 | + */ |
|
| 179 | + public static function register_helpers_autoloaders() |
|
| 180 | + { |
|
| 181 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * register core, model and class 'autoloaders' |
|
| 189 | + * |
|
| 190 | + * @access public |
|
| 191 | + * @return void |
|
| 192 | + */ |
|
| 193 | + public static function register_form_sections_autoloaders() |
|
| 194 | + { |
|
| 195 | + // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * register core, model and class 'autoloaders' |
|
| 201 | + * |
|
| 202 | + * @access public |
|
| 203 | + * @return void |
|
| 204 | + * @throws EE_Error |
|
| 205 | + */ |
|
| 206 | + public static function register_line_item_display_autoloaders() |
|
| 207 | + { |
|
| 208 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * register core, model and class 'autoloaders' |
|
| 214 | + * |
|
| 215 | + * @access public |
|
| 216 | + * @return void |
|
| 217 | + * @throws EE_Error |
|
| 218 | + */ |
|
| 219 | + public static function register_line_item_filter_autoloaders() |
|
| 220 | + { |
|
| 221 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * register template part 'autoloaders' |
|
| 227 | + * |
|
| 228 | + * @access public |
|
| 229 | + * @return void |
|
| 230 | + * @throws EE_Error |
|
| 231 | + */ |
|
| 232 | + public static function register_template_part_autoloaders() |
|
| 233 | + { |
|
| 234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @return void |
|
| 240 | + * @throws EE_Error |
|
| 241 | + */ |
|
| 242 | + public static function register_business_classes() |
|
| 243 | + { |
|
| 244 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
| 251 | + * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
| 252 | + * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
| 253 | + * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
| 254 | + * time the autoloader is used |
|
| 255 | + * |
|
| 256 | + * @param string $folder name, with or without trailing /, doesn't matter |
|
| 257 | + * @param bool $recursive |
|
| 258 | + * @param bool $debug **deprecated** |
|
| 259 | + * @throws \EE_Error |
|
| 260 | + */ |
|
| 261 | + public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
| 262 | + { |
|
| 263 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
| 264 | + EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
| 265 | + } |
|
| 266 | + // make sure last char is a / |
|
| 267 | + $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : ''; |
|
| 268 | + $class_to_filepath_map = array(); |
|
| 269 | + $exclude = array( 'index' ); |
|
| 270 | + // get all the files in that folder that end in php |
|
| 271 | + $filepaths = glob($folder.'*'); |
|
| 272 | + |
|
| 273 | + if (empty($filepaths)) { |
|
| 274 | + return; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + foreach ($filepaths as $filepath) { |
|
| 278 | + if (substr($filepath, -4, 4) === '.php') { |
|
| 279 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
| 280 | + if (! in_array($class_name, $exclude)) { |
|
| 281 | + $class_to_filepath_map [ $class_name ] = $filepath; |
|
| 282 | + } |
|
| 283 | + } elseif ($recursive) { |
|
| 284 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
| 288 | + self::register_autoloader($class_to_filepath_map, false, $debug); |
|
| 289 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 290 | + EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * add_alias |
|
| 298 | + * register additional autoloader based on variation of the classname for an existing autoloader |
|
| 299 | + * |
|
| 300 | + * @access public |
|
| 301 | + * @param string $class_name - simple class name ie: EE_Session |
|
| 302 | + * @param string $alias - variation on class name ie: EE_session, session, etc |
|
| 303 | + */ |
|
| 304 | + public static function add_alias($class_name, $alias) |
|
| 305 | + { |
|
| 306 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 307 | + self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | 310 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | if (self::$_autoloaders === null) { |
| 54 | 54 | self::$_autoloaders = array(); |
| 55 | 55 | $this->_register_custom_autoloaders(); |
| 56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
| 56 | + spl_autoload_register(array($this, 'espresso_autoloader')); |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public static function instance() |
| 67 | 67 | { |
| 68 | 68 | // check if class object is instantiated |
| 69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
| 69 | + if ( ! self::$_instance instanceof EEH_Autoloader) { |
|
| 70 | 70 | self::$_instance = new self(); |
| 71 | 71 | } |
| 72 | 72 | return self::$_instance; |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public static function espresso_autoloader($class_name) |
| 87 | 87 | { |
| 88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
| 88 | + if (isset(self::$_autoloaders[$class_name])) { |
|
| 89 | + require_once(self::$_autoloaders[$class_name]); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
| 105 | 105 | { |
| 106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
| 106 | + $class_paths = is_array($class_paths) ? $class_paths : array($class_paths); |
|
| 107 | 107 | foreach ($class_paths as $class => $path) { |
| 108 | 108 | // skip all files that are not PHP |
| 109 | 109 | if (substr($path, strlen($path) - 3) !== 'php') { |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | if ($read_check && ! is_readable($path)) { |
| 123 | 123 | throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
| 124 | 124 | } |
| 125 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
| 126 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path); |
|
| 127 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
| 128 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
| 125 | + if ( ! isset(self::$_autoloaders[$class])) { |
|
| 126 | + self::$_autoloaders[$class] = str_replace(array('/', '\\'), '/', $path); |
|
| 127 | + if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
| 128 | + EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -157,13 +157,13 @@ discard block |
||
| 157 | 157 | { |
| 158 | 158 | EEH_Autoloader::$debug = ''; |
| 159 | 159 | \EEH_Autoloader::register_helpers_autoloaders(); |
| 160 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
| 160 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces'); |
|
| 161 | 161 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
| 162 | 162 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
| 163 | 163 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
| 164 | 164 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
| 165 | 165 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
| 166 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
| 166 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages'); |
|
| 167 | 167 | if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
| 168 | 168 | EEH_Debug_Tools::instance()->show_times(); |
| 169 | 169 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public static function register_line_item_display_autoloaders() |
| 207 | 207 | { |
| 208 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
| 208 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | public static function register_line_item_filter_autoloaders() |
| 220 | 220 | { |
| 221 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
| 221 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | public static function register_template_part_autoloaders() |
| 233 | 233 | { |
| 234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
| 234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | */ |
| 242 | 242 | public static function register_business_classes() |
| 243 | 243 | { |
| 244 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
| 244 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business'); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
| 265 | 265 | } |
| 266 | 266 | // make sure last char is a / |
| 267 | - $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : ''; |
|
| 267 | + $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : ''; |
|
| 268 | 268 | $class_to_filepath_map = array(); |
| 269 | - $exclude = array( 'index' ); |
|
| 269 | + $exclude = array('index'); |
|
| 270 | 270 | // get all the files in that folder that end in php |
| 271 | 271 | $filepaths = glob($folder.'*'); |
| 272 | 272 | |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | foreach ($filepaths as $filepath) { |
| 278 | 278 | if (substr($filepath, -4, 4) === '.php') { |
| 279 | 279 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
| 280 | - if (! in_array($class_name, $exclude)) { |
|
| 281 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
| 280 | + if ( ! in_array($class_name, $exclude)) { |
|
| 281 | + $class_to_filepath_map [$class_name] = $filepath; |
|
| 282 | 282 | } |
| 283 | 283 | } elseif ($recursive) { |
| 284 | 284 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public static function add_alias($class_name, $alias) |
| 305 | 305 | { |
| 306 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 307 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
| 306 | + if (isset(self::$_autoloaders[$class_name])) { |
|
| 307 | + self::$_autoloaders[$alias] = self::$_autoloaders[$class_name]; |
|
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | } |
@@ -15,232 +15,232 @@ discard block |
||
| 15 | 15 | class EEH_Activation implements ResettableInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * constant used to indicate a cron task is no longer in use |
|
| 20 | - */ |
|
| 21 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * WP_User->ID |
|
| 25 | - * |
|
| 26 | - * @var int |
|
| 27 | - */ |
|
| 28 | - private static $_default_creator_id; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * indicates whether or not we've already verified core's default data during this request, |
|
| 32 | - * because after migrations are done, any addons activated while in maintenance mode |
|
| 33 | - * will want to setup their own default data, and they might hook into core's default data |
|
| 34 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 35 | - * This prevents doing that for EVERY single addon. |
|
| 36 | - * |
|
| 37 | - * @var boolean |
|
| 38 | - */ |
|
| 39 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 43 | - */ |
|
| 44 | - private static $table_analysis; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 48 | - */ |
|
| 49 | - private static $table_manager; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 54 | - */ |
|
| 55 | - public static function getTableAnalysis() |
|
| 56 | - { |
|
| 57 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 58 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 59 | - } |
|
| 60 | - return self::$table_analysis; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @return \EventEspresso\core\services\database\TableManager |
|
| 66 | - */ |
|
| 67 | - public static function getTableManager() |
|
| 68 | - { |
|
| 69 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 70 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 71 | - } |
|
| 72 | - return self::$table_manager; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * _ensure_table_name_has_prefix |
|
| 78 | - * |
|
| 79 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 80 | - * @access public |
|
| 81 | - * @static |
|
| 82 | - * @param $table_name |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public static function ensure_table_name_has_prefix($table_name) |
|
| 86 | - { |
|
| 87 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * system_initialization |
|
| 93 | - * ensures the EE configuration settings are loaded with at least default options set |
|
| 94 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 95 | - * |
|
| 96 | - * @access public |
|
| 97 | - * @static |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public static function system_initialization() |
|
| 101 | - { |
|
| 102 | - EEH_Activation::reset_and_update_config(); |
|
| 103 | - // which is fired BEFORE activation of plugin anyways |
|
| 104 | - EEH_Activation::verify_default_pages_exist(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Sets the database schema and creates folders. This should |
|
| 110 | - * be called on plugin activation and reactivation |
|
| 111 | - * |
|
| 112 | - * @return boolean success, whether the database and folders are setup properly |
|
| 113 | - * @throws \EE_Error |
|
| 114 | - */ |
|
| 115 | - public static function initialize_db_and_folders() |
|
| 116 | - { |
|
| 117 | - return EEH_Activation::create_database_tables(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * assuming we have an up-to-date database schema, this will populate it |
|
| 123 | - * with default and initial data. This should be called |
|
| 124 | - * upon activation of a new plugin, reactivation, and at the end |
|
| 125 | - * of running migration scripts |
|
| 126 | - * |
|
| 127 | - * @throws \EE_Error |
|
| 128 | - */ |
|
| 129 | - public static function initialize_db_content() |
|
| 130 | - { |
|
| 131 | - // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 132 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 133 | - return; |
|
| 134 | - } |
|
| 135 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 136 | - |
|
| 137 | - EEH_Activation::initialize_system_questions(); |
|
| 138 | - EEH_Activation::insert_default_status_codes(); |
|
| 139 | - EEH_Activation::generate_default_message_templates(); |
|
| 140 | - EEH_Activation::create_no_ticket_prices_array(); |
|
| 141 | - |
|
| 142 | - EEH_Activation::validate_messages_system(); |
|
| 143 | - EEH_Activation::insert_default_payment_methods(); |
|
| 144 | - // in case we've |
|
| 145 | - EEH_Activation::remove_cron_tasks(); |
|
| 146 | - EEH_Activation::create_cron_tasks(); |
|
| 147 | - // remove all TXN locks since that is being done via extra meta now |
|
| 148 | - delete_option('ee_locked_transactions'); |
|
| 149 | - // also, check for CAF default db content |
|
| 150 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 151 | - // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 152 | - // which users really won't care about on initial activation |
|
| 153 | - EE_Error::overwrite_success(); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 159 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 160 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 161 | - * (null) |
|
| 162 | - * |
|
| 163 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 164 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 165 | - * @return array |
|
| 166 | - * @throws \EE_Error |
|
| 167 | - */ |
|
| 168 | - public static function get_cron_tasks($which_to_include) |
|
| 169 | - { |
|
| 170 | - $cron_tasks = apply_filters( |
|
| 171 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 172 | - array( |
|
| 173 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 174 | - // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
| 175 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 176 | - // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 177 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 178 | - ) |
|
| 179 | - ); |
|
| 180 | - if ($which_to_include === 'old') { |
|
| 181 | - $cron_tasks = array_filter( |
|
| 182 | - $cron_tasks, |
|
| 183 | - function ($value) { |
|
| 184 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 185 | - } |
|
| 186 | - ); |
|
| 187 | - } elseif ($which_to_include === 'current') { |
|
| 188 | - $cron_tasks = array_filter($cron_tasks); |
|
| 189 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 190 | - throw new EE_Error( |
|
| 191 | - sprintf( |
|
| 192 | - __( |
|
| 193 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 194 | - 'event_espresso' |
|
| 195 | - ), |
|
| 196 | - $which_to_include |
|
| 197 | - ) |
|
| 198 | - ); |
|
| 199 | - } |
|
| 200 | - return $cron_tasks; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 206 | - * |
|
| 207 | - * @throws \EE_Error |
|
| 208 | - */ |
|
| 209 | - public static function create_cron_tasks() |
|
| 210 | - { |
|
| 211 | - |
|
| 212 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 213 | - if (! wp_next_scheduled($hook_name)) { |
|
| 214 | - /** |
|
| 215 | - * This allows client code to define the initial start timestamp for this schedule. |
|
| 216 | - */ |
|
| 217 | - if (is_array($frequency) |
|
| 218 | - && count($frequency) === 2 |
|
| 219 | - && isset($frequency[0], $frequency[1]) |
|
| 220 | - ) { |
|
| 221 | - $start_timestamp = $frequency[0]; |
|
| 222 | - $frequency = $frequency[1]; |
|
| 223 | - } else { |
|
| 224 | - $start_timestamp = time(); |
|
| 225 | - } |
|
| 226 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Remove the currently-existing and now-removed cron tasks. |
|
| 234 | - * |
|
| 235 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 236 | - * @throws \EE_Error |
|
| 237 | - */ |
|
| 238 | - public static function remove_cron_tasks($remove_all = true) |
|
| 239 | - { |
|
| 240 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 241 | - $crons = _get_cron_array(); |
|
| 242 | - $crons = is_array($crons) ? $crons : array(); |
|
| 243 | - /* reminder of what $crons look like: |
|
| 18 | + /** |
|
| 19 | + * constant used to indicate a cron task is no longer in use |
|
| 20 | + */ |
|
| 21 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * WP_User->ID |
|
| 25 | + * |
|
| 26 | + * @var int |
|
| 27 | + */ |
|
| 28 | + private static $_default_creator_id; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * indicates whether or not we've already verified core's default data during this request, |
|
| 32 | + * because after migrations are done, any addons activated while in maintenance mode |
|
| 33 | + * will want to setup their own default data, and they might hook into core's default data |
|
| 34 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 35 | + * This prevents doing that for EVERY single addon. |
|
| 36 | + * |
|
| 37 | + * @var boolean |
|
| 38 | + */ |
|
| 39 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 43 | + */ |
|
| 44 | + private static $table_analysis; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 48 | + */ |
|
| 49 | + private static $table_manager; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 54 | + */ |
|
| 55 | + public static function getTableAnalysis() |
|
| 56 | + { |
|
| 57 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 58 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 59 | + } |
|
| 60 | + return self::$table_analysis; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @return \EventEspresso\core\services\database\TableManager |
|
| 66 | + */ |
|
| 67 | + public static function getTableManager() |
|
| 68 | + { |
|
| 69 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 70 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 71 | + } |
|
| 72 | + return self::$table_manager; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * _ensure_table_name_has_prefix |
|
| 78 | + * |
|
| 79 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 80 | + * @access public |
|
| 81 | + * @static |
|
| 82 | + * @param $table_name |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public static function ensure_table_name_has_prefix($table_name) |
|
| 86 | + { |
|
| 87 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * system_initialization |
|
| 93 | + * ensures the EE configuration settings are loaded with at least default options set |
|
| 94 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 95 | + * |
|
| 96 | + * @access public |
|
| 97 | + * @static |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public static function system_initialization() |
|
| 101 | + { |
|
| 102 | + EEH_Activation::reset_and_update_config(); |
|
| 103 | + // which is fired BEFORE activation of plugin anyways |
|
| 104 | + EEH_Activation::verify_default_pages_exist(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Sets the database schema and creates folders. This should |
|
| 110 | + * be called on plugin activation and reactivation |
|
| 111 | + * |
|
| 112 | + * @return boolean success, whether the database and folders are setup properly |
|
| 113 | + * @throws \EE_Error |
|
| 114 | + */ |
|
| 115 | + public static function initialize_db_and_folders() |
|
| 116 | + { |
|
| 117 | + return EEH_Activation::create_database_tables(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * assuming we have an up-to-date database schema, this will populate it |
|
| 123 | + * with default and initial data. This should be called |
|
| 124 | + * upon activation of a new plugin, reactivation, and at the end |
|
| 125 | + * of running migration scripts |
|
| 126 | + * |
|
| 127 | + * @throws \EE_Error |
|
| 128 | + */ |
|
| 129 | + public static function initialize_db_content() |
|
| 130 | + { |
|
| 131 | + // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 132 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 136 | + |
|
| 137 | + EEH_Activation::initialize_system_questions(); |
|
| 138 | + EEH_Activation::insert_default_status_codes(); |
|
| 139 | + EEH_Activation::generate_default_message_templates(); |
|
| 140 | + EEH_Activation::create_no_ticket_prices_array(); |
|
| 141 | + |
|
| 142 | + EEH_Activation::validate_messages_system(); |
|
| 143 | + EEH_Activation::insert_default_payment_methods(); |
|
| 144 | + // in case we've |
|
| 145 | + EEH_Activation::remove_cron_tasks(); |
|
| 146 | + EEH_Activation::create_cron_tasks(); |
|
| 147 | + // remove all TXN locks since that is being done via extra meta now |
|
| 148 | + delete_option('ee_locked_transactions'); |
|
| 149 | + // also, check for CAF default db content |
|
| 150 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 151 | + // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 152 | + // which users really won't care about on initial activation |
|
| 153 | + EE_Error::overwrite_success(); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 159 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 160 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 161 | + * (null) |
|
| 162 | + * |
|
| 163 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 164 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 165 | + * @return array |
|
| 166 | + * @throws \EE_Error |
|
| 167 | + */ |
|
| 168 | + public static function get_cron_tasks($which_to_include) |
|
| 169 | + { |
|
| 170 | + $cron_tasks = apply_filters( |
|
| 171 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 172 | + array( |
|
| 173 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 174 | + // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
| 175 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 176 | + // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 177 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 178 | + ) |
|
| 179 | + ); |
|
| 180 | + if ($which_to_include === 'old') { |
|
| 181 | + $cron_tasks = array_filter( |
|
| 182 | + $cron_tasks, |
|
| 183 | + function ($value) { |
|
| 184 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 185 | + } |
|
| 186 | + ); |
|
| 187 | + } elseif ($which_to_include === 'current') { |
|
| 188 | + $cron_tasks = array_filter($cron_tasks); |
|
| 189 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 190 | + throw new EE_Error( |
|
| 191 | + sprintf( |
|
| 192 | + __( |
|
| 193 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 194 | + 'event_espresso' |
|
| 195 | + ), |
|
| 196 | + $which_to_include |
|
| 197 | + ) |
|
| 198 | + ); |
|
| 199 | + } |
|
| 200 | + return $cron_tasks; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 206 | + * |
|
| 207 | + * @throws \EE_Error |
|
| 208 | + */ |
|
| 209 | + public static function create_cron_tasks() |
|
| 210 | + { |
|
| 211 | + |
|
| 212 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 213 | + if (! wp_next_scheduled($hook_name)) { |
|
| 214 | + /** |
|
| 215 | + * This allows client code to define the initial start timestamp for this schedule. |
|
| 216 | + */ |
|
| 217 | + if (is_array($frequency) |
|
| 218 | + && count($frequency) === 2 |
|
| 219 | + && isset($frequency[0], $frequency[1]) |
|
| 220 | + ) { |
|
| 221 | + $start_timestamp = $frequency[0]; |
|
| 222 | + $frequency = $frequency[1]; |
|
| 223 | + } else { |
|
| 224 | + $start_timestamp = time(); |
|
| 225 | + } |
|
| 226 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Remove the currently-existing and now-removed cron tasks. |
|
| 234 | + * |
|
| 235 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 236 | + * @throws \EE_Error |
|
| 237 | + */ |
|
| 238 | + public static function remove_cron_tasks($remove_all = true) |
|
| 239 | + { |
|
| 240 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 241 | + $crons = _get_cron_array(); |
|
| 242 | + $crons = is_array($crons) ? $crons : array(); |
|
| 243 | + /* reminder of what $crons look like: |
|
| 244 | 244 | * Top-level keys are timestamps, and their values are arrays. |
| 245 | 245 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
| 246 | 246 | * and their values are arrays. |
@@ -257,909 +257,909 @@ discard block |
||
| 257 | 257 | * ... |
| 258 | 258 | * ... |
| 259 | 259 | */ |
| 260 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 261 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 262 | - if (is_array($hooks_to_fire_at_time)) { |
|
| 263 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 264 | - if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 265 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 266 | - ) { |
|
| 267 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - // also take care of any empty cron timestamps. |
|
| 271 | - if (empty($hooks_to_fire_at_time)) { |
|
| 272 | - unset($crons[ $timestamp ]); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - _set_cron_array($crons); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * CPT_initialization |
|
| 282 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 283 | - * |
|
| 284 | - * @access public |
|
| 285 | - * @static |
|
| 286 | - * @return void |
|
| 287 | - */ |
|
| 288 | - public static function CPT_initialization() |
|
| 289 | - { |
|
| 290 | - // register Custom Post Types |
|
| 291 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 292 | - flush_rewrite_rules(); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * reset_and_update_config |
|
| 299 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 300 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
| 301 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 302 | - * |
|
| 303 | - * @access public |
|
| 304 | - * @static |
|
| 305 | - * @return void |
|
| 306 | - */ |
|
| 307 | - public static function reset_and_update_config() |
|
| 308 | - { |
|
| 309 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 310 | - add_filter( |
|
| 311 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 312 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
| 313 | - 10, |
|
| 314 | - 3 |
|
| 315 | - ); |
|
| 316 | - // EE_Config::reset(); |
|
| 317 | - if (! EE_Config::logging_enabled()) { |
|
| 318 | - delete_option(EE_Config::LOG_NAME); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * load_calendar_config |
|
| 325 | - * |
|
| 326 | - * @access public |
|
| 327 | - * @return void |
|
| 328 | - */ |
|
| 329 | - public static function load_calendar_config() |
|
| 330 | - { |
|
| 331 | - // grab array of all plugin folders and loop thru it |
|
| 332 | - $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
| 333 | - if (empty($plugins)) { |
|
| 334 | - return; |
|
| 335 | - } |
|
| 336 | - foreach ($plugins as $plugin_path) { |
|
| 337 | - // grab plugin folder name from path |
|
| 338 | - $plugin = basename($plugin_path); |
|
| 339 | - // drill down to Espresso plugins |
|
| 340 | - // then to calendar related plugins |
|
| 341 | - if (strpos($plugin, 'espresso') !== false |
|
| 342 | - || strpos($plugin, 'Espresso') !== false |
|
| 343 | - || strpos($plugin, 'ee4') !== false |
|
| 344 | - || strpos($plugin, 'EE4') !== false |
|
| 345 | - || strpos($plugin, 'calendar') !== false |
|
| 346 | - ) { |
|
| 347 | - // this is what we are looking for |
|
| 348 | - $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
| 349 | - // does it exist in this folder ? |
|
| 350 | - if (is_readable($calendar_config)) { |
|
| 351 | - // YEAH! let's load it |
|
| 352 | - require_once($calendar_config); |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * _migrate_old_config_data |
|
| 362 | - * |
|
| 363 | - * @access public |
|
| 364 | - * @param array|stdClass $settings |
|
| 365 | - * @param string $config |
|
| 366 | - * @param \EE_Config $EE_Config |
|
| 367 | - * @return \stdClass |
|
| 368 | - */ |
|
| 369 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 370 | - { |
|
| 371 | - $convert_from_array = array('addons'); |
|
| 372 | - // in case old settings were saved as an array |
|
| 373 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 374 | - // convert existing settings to an object |
|
| 375 | - $config_array = $settings; |
|
| 376 | - $settings = new stdClass(); |
|
| 377 | - foreach ($config_array as $key => $value) { |
|
| 378 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 379 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 380 | - } else { |
|
| 381 | - $settings->{$key} = $value; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 385 | - } |
|
| 386 | - return $settings; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * deactivate_event_espresso |
|
| 392 | - * |
|
| 393 | - * @access public |
|
| 394 | - * @static |
|
| 395 | - * @return void |
|
| 396 | - */ |
|
| 397 | - public static function deactivate_event_espresso() |
|
| 398 | - { |
|
| 399 | - // check permissions |
|
| 400 | - if (current_user_can('activate_plugins')) { |
|
| 401 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * verify_default_pages_exist |
|
| 409 | - * |
|
| 410 | - * @access public |
|
| 411 | - * @static |
|
| 412 | - * @return void |
|
| 413 | - * @throws InvalidDataTypeException |
|
| 414 | - */ |
|
| 415 | - public static function verify_default_pages_exist() |
|
| 416 | - { |
|
| 417 | - $critical_page_problem = false; |
|
| 418 | - $critical_pages = array( |
|
| 419 | - array( |
|
| 420 | - 'id' => 'reg_page_id', |
|
| 421 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 422 | - 'post' => null, |
|
| 423 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
| 424 | - ), |
|
| 425 | - array( |
|
| 426 | - 'id' => 'txn_page_id', |
|
| 427 | - 'name' => __('Transactions', 'event_espresso'), |
|
| 428 | - 'post' => null, |
|
| 429 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 430 | - ), |
|
| 431 | - array( |
|
| 432 | - 'id' => 'thank_you_page_id', |
|
| 433 | - 'name' => __('Thank You', 'event_espresso'), |
|
| 434 | - 'post' => null, |
|
| 435 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
| 436 | - ), |
|
| 437 | - array( |
|
| 438 | - 'id' => 'cancel_page_id', |
|
| 439 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 440 | - 'post' => null, |
|
| 441 | - 'code' => 'ESPRESSO_CANCELLED', |
|
| 442 | - ), |
|
| 443 | - ); |
|
| 444 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 445 | - foreach ($critical_pages as $critical_page) { |
|
| 446 | - // is critical page ID set in config ? |
|
| 447 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 448 | - // attempt to find post by ID |
|
| 449 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 450 | - } |
|
| 451 | - // no dice? |
|
| 452 | - if ($critical_page['post'] === null) { |
|
| 453 | - // attempt to find post by title |
|
| 454 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 455 | - // still nothing? |
|
| 456 | - if ($critical_page['post'] === null) { |
|
| 457 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 458 | - // REALLY? Still nothing ??!?!? |
|
| 459 | - if ($critical_page['post'] === null) { |
|
| 460 | - $msg = __( |
|
| 461 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 462 | - 'event_espresso' |
|
| 463 | - ); |
|
| 464 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 465 | - break; |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - // check that Post ID matches critical page ID in config |
|
| 470 | - if (isset($critical_page['post']->ID) |
|
| 471 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 472 | - ) { |
|
| 473 | - // update Config with post ID |
|
| 474 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 475 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 476 | - $msg = __( |
|
| 477 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 478 | - 'event_espresso' |
|
| 479 | - ); |
|
| 480 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - $critical_page_problem = |
|
| 484 | - ! isset($critical_page['post']->post_status) |
|
| 485 | - || $critical_page['post']->post_status !== 'publish' |
|
| 486 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 487 | - ? true |
|
| 488 | - : $critical_page_problem; |
|
| 489 | - } |
|
| 490 | - if ($critical_page_problem) { |
|
| 491 | - new PersistentAdminNotice( |
|
| 492 | - 'critical_page_problem', |
|
| 493 | - sprintf( |
|
| 494 | - esc_html__( |
|
| 495 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 496 | - 'event_espresso' |
|
| 497 | - ), |
|
| 498 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
| 499 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 500 | - . '</a>' |
|
| 501 | - ) |
|
| 502 | - ); |
|
| 503 | - } |
|
| 504 | - if (EE_Error::has_notices()) { |
|
| 505 | - EE_Error::get_notices(false, true, true); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Returns the first post which uses the specified shortcode |
|
| 513 | - * |
|
| 514 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 515 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 516 | - * "[ESPRESSO_THANK_YOU" |
|
| 517 | - * (we don't search for the closing shortcode bracket because they might have added |
|
| 518 | - * parameter to the shortcode |
|
| 519 | - * @return WP_Post or NULl |
|
| 520 | - */ |
|
| 521 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 522 | - { |
|
| 523 | - global $wpdb; |
|
| 524 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 525 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 526 | - if ($post_id) { |
|
| 527 | - return get_post($post_id); |
|
| 528 | - } else { |
|
| 529 | - return null; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * This function generates a post for critical espresso pages |
|
| 536 | - * |
|
| 537 | - * @access public |
|
| 538 | - * @static |
|
| 539 | - * @param array $critical_page |
|
| 540 | - * @return array |
|
| 541 | - */ |
|
| 542 | - public static function create_critical_page($critical_page) |
|
| 543 | - { |
|
| 544 | - |
|
| 545 | - $post_args = array( |
|
| 546 | - 'post_title' => $critical_page['name'], |
|
| 547 | - 'post_status' => 'publish', |
|
| 548 | - 'post_type' => 'page', |
|
| 549 | - 'comment_status' => 'closed', |
|
| 550 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 551 | - ); |
|
| 552 | - |
|
| 553 | - $post_id = wp_insert_post($post_args); |
|
| 554 | - if (! $post_id) { |
|
| 555 | - $msg = sprintf( |
|
| 556 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 557 | - $critical_page['name'] |
|
| 558 | - ); |
|
| 559 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 560 | - return $critical_page; |
|
| 561 | - } |
|
| 562 | - // get newly created post's details |
|
| 563 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
| 564 | - $msg = sprintf( |
|
| 565 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 566 | - $critical_page['name'] |
|
| 567 | - ); |
|
| 568 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - return $critical_page; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 579 | - * The role being used to check is filterable. |
|
| 580 | - * |
|
| 581 | - * @since 4.6.0 |
|
| 582 | - * @global WPDB $wpdb |
|
| 583 | - * @return mixed null|int WP_user ID or NULL |
|
| 584 | - */ |
|
| 585 | - public static function get_default_creator_id() |
|
| 586 | - { |
|
| 587 | - global $wpdb; |
|
| 588 | - if (! empty(self::$_default_creator_id)) { |
|
| 589 | - return self::$_default_creator_id; |
|
| 590 | - }/**/ |
|
| 591 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 592 | - // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 593 | - $pre_filtered_id = apply_filters( |
|
| 594 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 595 | - false, |
|
| 596 | - $role_to_check |
|
| 597 | - ); |
|
| 598 | - if ($pre_filtered_id !== false) { |
|
| 599 | - return (int) $pre_filtered_id; |
|
| 600 | - } |
|
| 601 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 602 | - $query = $wpdb->prepare( |
|
| 603 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 604 | - '%' . $role_to_check . '%' |
|
| 605 | - ); |
|
| 606 | - $user_id = $wpdb->get_var($query); |
|
| 607 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 608 | - if ($user_id && (int) $user_id) { |
|
| 609 | - self::$_default_creator_id = (int) $user_id; |
|
| 610 | - return self::$_default_creator_id; |
|
| 611 | - } else { |
|
| 612 | - return null; |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * used by EE and EE addons during plugin activation to create tables. |
|
| 620 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 621 | - * but includes extra logic regarding activations. |
|
| 622 | - * |
|
| 623 | - * @access public |
|
| 624 | - * @static |
|
| 625 | - * @param string $table_name without the $wpdb->prefix |
|
| 626 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 627 | - * table query) |
|
| 628 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 629 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 630 | - * and new once this function is done (ie, you really do want to CREATE a |
|
| 631 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 632 | - * you just want to verify the table exists and matches this definition |
|
| 633 | - * (and if it HAS data in it you want to leave it be) |
|
| 634 | - * @return void |
|
| 635 | - * @throws EE_Error if there are database errors |
|
| 636 | - */ |
|
| 637 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 638 | - { |
|
| 639 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 640 | - return; |
|
| 641 | - } |
|
| 642 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 643 | - if (! function_exists('dbDelta')) { |
|
| 644 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 645 | - } |
|
| 646 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 647 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 648 | - // do we need to first delete an existing version of this table ? |
|
| 649 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 650 | - // ok, delete the table... but ONLY if it's empty |
|
| 651 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 652 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 653 | - if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 654 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 655 | - } elseif (! $deleted_safely) { |
|
| 656 | - // so we should be more cautious rather than just dropping tables so easily |
|
| 657 | - error_log( |
|
| 658 | - sprintf( |
|
| 659 | - __( |
|
| 660 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 661 | - 'event_espresso' |
|
| 662 | - ), |
|
| 663 | - $wp_table_name, |
|
| 664 | - '<br/>', |
|
| 665 | - 'espresso_db_update' |
|
| 666 | - ) |
|
| 667 | - ); |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - $engine = str_replace('ENGINE=', '', $engine); |
|
| 671 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * add_column_if_it_doesn't_exist |
|
| 678 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 679 | - * |
|
| 680 | - * @access public |
|
| 681 | - * @static |
|
| 682 | - * @deprecated instead use TableManager::addColumn() |
|
| 683 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 684 | - * @param string $column_name |
|
| 685 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 686 | - * 'VARCHAR(10)' |
|
| 687 | - * @return bool|int |
|
| 688 | - */ |
|
| 689 | - public static function add_column_if_it_doesnt_exist( |
|
| 690 | - $table_name, |
|
| 691 | - $column_name, |
|
| 692 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
| 693 | - ) { |
|
| 694 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * get_fields_on_table |
|
| 700 | - * Gets all the fields on the database table. |
|
| 701 | - * |
|
| 702 | - * @access public |
|
| 703 | - * @deprecated instead use TableManager::getTableColumns() |
|
| 704 | - * @static |
|
| 705 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
| 706 | - * @return array of database column names |
|
| 707 | - */ |
|
| 708 | - public static function get_fields_on_table($table_name = null) |
|
| 709 | - { |
|
| 710 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - |
|
| 714 | - /** |
|
| 715 | - * db_table_is_empty |
|
| 716 | - * |
|
| 717 | - * @access public\ |
|
| 718 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 719 | - * @static |
|
| 720 | - * @param string $table_name |
|
| 721 | - * @return bool |
|
| 722 | - */ |
|
| 723 | - public static function db_table_is_empty($table_name) |
|
| 724 | - { |
|
| 725 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * delete_db_table_if_empty |
|
| 731 | - * |
|
| 732 | - * @access public |
|
| 733 | - * @static |
|
| 734 | - * @param string $table_name |
|
| 735 | - * @return bool | int |
|
| 736 | - */ |
|
| 737 | - public static function delete_db_table_if_empty($table_name) |
|
| 738 | - { |
|
| 739 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 740 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 741 | - } |
|
| 742 | - return false; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * delete_unused_db_table |
|
| 748 | - * |
|
| 749 | - * @access public |
|
| 750 | - * @static |
|
| 751 | - * @deprecated instead use TableManager::dropTable() |
|
| 752 | - * @param string $table_name |
|
| 753 | - * @return bool | int |
|
| 754 | - */ |
|
| 755 | - public static function delete_unused_db_table($table_name) |
|
| 756 | - { |
|
| 757 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * drop_index |
|
| 763 | - * |
|
| 764 | - * @access public |
|
| 765 | - * @static |
|
| 766 | - * @deprecated instead use TableManager::dropIndex() |
|
| 767 | - * @param string $table_name |
|
| 768 | - * @param string $index_name |
|
| 769 | - * @return bool | int |
|
| 770 | - */ |
|
| 771 | - public static function drop_index($table_name, $index_name) |
|
| 772 | - { |
|
| 773 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * create_database_tables |
|
| 780 | - * |
|
| 781 | - * @access public |
|
| 782 | - * @static |
|
| 783 | - * @throws EE_Error |
|
| 784 | - * @return boolean success (whether database is setup properly or not) |
|
| 785 | - */ |
|
| 786 | - public static function create_database_tables() |
|
| 787 | - { |
|
| 788 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 789 | - // find the migration script that sets the database to be compatible with the code |
|
| 790 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 791 | - if ($dms_name) { |
|
| 792 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 793 | - $current_data_migration_script->set_migrating(false); |
|
| 794 | - $current_data_migration_script->schema_changes_before_migration(); |
|
| 795 | - $current_data_migration_script->schema_changes_after_migration(); |
|
| 796 | - if ($current_data_migration_script->get_errors()) { |
|
| 797 | - if (WP_DEBUG) { |
|
| 798 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 799 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 800 | - } |
|
| 801 | - } else { |
|
| 802 | - EE_Error::add_error( |
|
| 803 | - __( |
|
| 804 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 260 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 261 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 262 | + if (is_array($hooks_to_fire_at_time)) { |
|
| 263 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 264 | + if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 265 | + && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 266 | + ) { |
|
| 267 | + unset($crons[ $timestamp ][ $hook_name ]); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + // also take care of any empty cron timestamps. |
|
| 271 | + if (empty($hooks_to_fire_at_time)) { |
|
| 272 | + unset($crons[ $timestamp ]); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + _set_cron_array($crons); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * CPT_initialization |
|
| 282 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 283 | + * |
|
| 284 | + * @access public |
|
| 285 | + * @static |
|
| 286 | + * @return void |
|
| 287 | + */ |
|
| 288 | + public static function CPT_initialization() |
|
| 289 | + { |
|
| 290 | + // register Custom Post Types |
|
| 291 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 292 | + flush_rewrite_rules(); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * reset_and_update_config |
|
| 299 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 300 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
| 301 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 302 | + * |
|
| 303 | + * @access public |
|
| 304 | + * @static |
|
| 305 | + * @return void |
|
| 306 | + */ |
|
| 307 | + public static function reset_and_update_config() |
|
| 308 | + { |
|
| 309 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 310 | + add_filter( |
|
| 311 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 312 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
| 313 | + 10, |
|
| 314 | + 3 |
|
| 315 | + ); |
|
| 316 | + // EE_Config::reset(); |
|
| 317 | + if (! EE_Config::logging_enabled()) { |
|
| 318 | + delete_option(EE_Config::LOG_NAME); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * load_calendar_config |
|
| 325 | + * |
|
| 326 | + * @access public |
|
| 327 | + * @return void |
|
| 328 | + */ |
|
| 329 | + public static function load_calendar_config() |
|
| 330 | + { |
|
| 331 | + // grab array of all plugin folders and loop thru it |
|
| 332 | + $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
| 333 | + if (empty($plugins)) { |
|
| 334 | + return; |
|
| 335 | + } |
|
| 336 | + foreach ($plugins as $plugin_path) { |
|
| 337 | + // grab plugin folder name from path |
|
| 338 | + $plugin = basename($plugin_path); |
|
| 339 | + // drill down to Espresso plugins |
|
| 340 | + // then to calendar related plugins |
|
| 341 | + if (strpos($plugin, 'espresso') !== false |
|
| 342 | + || strpos($plugin, 'Espresso') !== false |
|
| 343 | + || strpos($plugin, 'ee4') !== false |
|
| 344 | + || strpos($plugin, 'EE4') !== false |
|
| 345 | + || strpos($plugin, 'calendar') !== false |
|
| 346 | + ) { |
|
| 347 | + // this is what we are looking for |
|
| 348 | + $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
| 349 | + // does it exist in this folder ? |
|
| 350 | + if (is_readable($calendar_config)) { |
|
| 351 | + // YEAH! let's load it |
|
| 352 | + require_once($calendar_config); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * _migrate_old_config_data |
|
| 362 | + * |
|
| 363 | + * @access public |
|
| 364 | + * @param array|stdClass $settings |
|
| 365 | + * @param string $config |
|
| 366 | + * @param \EE_Config $EE_Config |
|
| 367 | + * @return \stdClass |
|
| 368 | + */ |
|
| 369 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 370 | + { |
|
| 371 | + $convert_from_array = array('addons'); |
|
| 372 | + // in case old settings were saved as an array |
|
| 373 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 374 | + // convert existing settings to an object |
|
| 375 | + $config_array = $settings; |
|
| 376 | + $settings = new stdClass(); |
|
| 377 | + foreach ($config_array as $key => $value) { |
|
| 378 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 379 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 380 | + } else { |
|
| 381 | + $settings->{$key} = $value; |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 385 | + } |
|
| 386 | + return $settings; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * deactivate_event_espresso |
|
| 392 | + * |
|
| 393 | + * @access public |
|
| 394 | + * @static |
|
| 395 | + * @return void |
|
| 396 | + */ |
|
| 397 | + public static function deactivate_event_espresso() |
|
| 398 | + { |
|
| 399 | + // check permissions |
|
| 400 | + if (current_user_can('activate_plugins')) { |
|
| 401 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * verify_default_pages_exist |
|
| 409 | + * |
|
| 410 | + * @access public |
|
| 411 | + * @static |
|
| 412 | + * @return void |
|
| 413 | + * @throws InvalidDataTypeException |
|
| 414 | + */ |
|
| 415 | + public static function verify_default_pages_exist() |
|
| 416 | + { |
|
| 417 | + $critical_page_problem = false; |
|
| 418 | + $critical_pages = array( |
|
| 419 | + array( |
|
| 420 | + 'id' => 'reg_page_id', |
|
| 421 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 422 | + 'post' => null, |
|
| 423 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
| 424 | + ), |
|
| 425 | + array( |
|
| 426 | + 'id' => 'txn_page_id', |
|
| 427 | + 'name' => __('Transactions', 'event_espresso'), |
|
| 428 | + 'post' => null, |
|
| 429 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 430 | + ), |
|
| 431 | + array( |
|
| 432 | + 'id' => 'thank_you_page_id', |
|
| 433 | + 'name' => __('Thank You', 'event_espresso'), |
|
| 434 | + 'post' => null, |
|
| 435 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
| 436 | + ), |
|
| 437 | + array( |
|
| 438 | + 'id' => 'cancel_page_id', |
|
| 439 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 440 | + 'post' => null, |
|
| 441 | + 'code' => 'ESPRESSO_CANCELLED', |
|
| 442 | + ), |
|
| 443 | + ); |
|
| 444 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 445 | + foreach ($critical_pages as $critical_page) { |
|
| 446 | + // is critical page ID set in config ? |
|
| 447 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 448 | + // attempt to find post by ID |
|
| 449 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 450 | + } |
|
| 451 | + // no dice? |
|
| 452 | + if ($critical_page['post'] === null) { |
|
| 453 | + // attempt to find post by title |
|
| 454 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 455 | + // still nothing? |
|
| 456 | + if ($critical_page['post'] === null) { |
|
| 457 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 458 | + // REALLY? Still nothing ??!?!? |
|
| 459 | + if ($critical_page['post'] === null) { |
|
| 460 | + $msg = __( |
|
| 461 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 462 | + 'event_espresso' |
|
| 463 | + ); |
|
| 464 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 465 | + break; |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + // check that Post ID matches critical page ID in config |
|
| 470 | + if (isset($critical_page['post']->ID) |
|
| 471 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 472 | + ) { |
|
| 473 | + // update Config with post ID |
|
| 474 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 475 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 476 | + $msg = __( |
|
| 477 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 478 | + 'event_espresso' |
|
| 479 | + ); |
|
| 480 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + $critical_page_problem = |
|
| 484 | + ! isset($critical_page['post']->post_status) |
|
| 485 | + || $critical_page['post']->post_status !== 'publish' |
|
| 486 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 487 | + ? true |
|
| 488 | + : $critical_page_problem; |
|
| 489 | + } |
|
| 490 | + if ($critical_page_problem) { |
|
| 491 | + new PersistentAdminNotice( |
|
| 492 | + 'critical_page_problem', |
|
| 493 | + sprintf( |
|
| 494 | + esc_html__( |
|
| 495 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 496 | + 'event_espresso' |
|
| 497 | + ), |
|
| 498 | + '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
| 499 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 500 | + . '</a>' |
|
| 501 | + ) |
|
| 502 | + ); |
|
| 503 | + } |
|
| 504 | + if (EE_Error::has_notices()) { |
|
| 505 | + EE_Error::get_notices(false, true, true); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Returns the first post which uses the specified shortcode |
|
| 513 | + * |
|
| 514 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 515 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 516 | + * "[ESPRESSO_THANK_YOU" |
|
| 517 | + * (we don't search for the closing shortcode bracket because they might have added |
|
| 518 | + * parameter to the shortcode |
|
| 519 | + * @return WP_Post or NULl |
|
| 520 | + */ |
|
| 521 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 522 | + { |
|
| 523 | + global $wpdb; |
|
| 524 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 525 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 526 | + if ($post_id) { |
|
| 527 | + return get_post($post_id); |
|
| 528 | + } else { |
|
| 529 | + return null; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * This function generates a post for critical espresso pages |
|
| 536 | + * |
|
| 537 | + * @access public |
|
| 538 | + * @static |
|
| 539 | + * @param array $critical_page |
|
| 540 | + * @return array |
|
| 541 | + */ |
|
| 542 | + public static function create_critical_page($critical_page) |
|
| 543 | + { |
|
| 544 | + |
|
| 545 | + $post_args = array( |
|
| 546 | + 'post_title' => $critical_page['name'], |
|
| 547 | + 'post_status' => 'publish', |
|
| 548 | + 'post_type' => 'page', |
|
| 549 | + 'comment_status' => 'closed', |
|
| 550 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 551 | + ); |
|
| 552 | + |
|
| 553 | + $post_id = wp_insert_post($post_args); |
|
| 554 | + if (! $post_id) { |
|
| 555 | + $msg = sprintf( |
|
| 556 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 557 | + $critical_page['name'] |
|
| 558 | + ); |
|
| 559 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 560 | + return $critical_page; |
|
| 561 | + } |
|
| 562 | + // get newly created post's details |
|
| 563 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
| 564 | + $msg = sprintf( |
|
| 565 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 566 | + $critical_page['name'] |
|
| 567 | + ); |
|
| 568 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + return $critical_page; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 579 | + * The role being used to check is filterable. |
|
| 580 | + * |
|
| 581 | + * @since 4.6.0 |
|
| 582 | + * @global WPDB $wpdb |
|
| 583 | + * @return mixed null|int WP_user ID or NULL |
|
| 584 | + */ |
|
| 585 | + public static function get_default_creator_id() |
|
| 586 | + { |
|
| 587 | + global $wpdb; |
|
| 588 | + if (! empty(self::$_default_creator_id)) { |
|
| 589 | + return self::$_default_creator_id; |
|
| 590 | + }/**/ |
|
| 591 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 592 | + // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 593 | + $pre_filtered_id = apply_filters( |
|
| 594 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 595 | + false, |
|
| 596 | + $role_to_check |
|
| 597 | + ); |
|
| 598 | + if ($pre_filtered_id !== false) { |
|
| 599 | + return (int) $pre_filtered_id; |
|
| 600 | + } |
|
| 601 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 602 | + $query = $wpdb->prepare( |
|
| 603 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 604 | + '%' . $role_to_check . '%' |
|
| 605 | + ); |
|
| 606 | + $user_id = $wpdb->get_var($query); |
|
| 607 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 608 | + if ($user_id && (int) $user_id) { |
|
| 609 | + self::$_default_creator_id = (int) $user_id; |
|
| 610 | + return self::$_default_creator_id; |
|
| 611 | + } else { |
|
| 612 | + return null; |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * used by EE and EE addons during plugin activation to create tables. |
|
| 620 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 621 | + * but includes extra logic regarding activations. |
|
| 622 | + * |
|
| 623 | + * @access public |
|
| 624 | + * @static |
|
| 625 | + * @param string $table_name without the $wpdb->prefix |
|
| 626 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 627 | + * table query) |
|
| 628 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 629 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 630 | + * and new once this function is done (ie, you really do want to CREATE a |
|
| 631 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 632 | + * you just want to verify the table exists and matches this definition |
|
| 633 | + * (and if it HAS data in it you want to leave it be) |
|
| 634 | + * @return void |
|
| 635 | + * @throws EE_Error if there are database errors |
|
| 636 | + */ |
|
| 637 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 638 | + { |
|
| 639 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 640 | + return; |
|
| 641 | + } |
|
| 642 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 643 | + if (! function_exists('dbDelta')) { |
|
| 644 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 645 | + } |
|
| 646 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 647 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 648 | + // do we need to first delete an existing version of this table ? |
|
| 649 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 650 | + // ok, delete the table... but ONLY if it's empty |
|
| 651 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 652 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 653 | + if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 654 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 655 | + } elseif (! $deleted_safely) { |
|
| 656 | + // so we should be more cautious rather than just dropping tables so easily |
|
| 657 | + error_log( |
|
| 658 | + sprintf( |
|
| 659 | + __( |
|
| 660 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 661 | + 'event_espresso' |
|
| 662 | + ), |
|
| 663 | + $wp_table_name, |
|
| 664 | + '<br/>', |
|
| 665 | + 'espresso_db_update' |
|
| 666 | + ) |
|
| 667 | + ); |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + $engine = str_replace('ENGINE=', '', $engine); |
|
| 671 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * add_column_if_it_doesn't_exist |
|
| 678 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 679 | + * |
|
| 680 | + * @access public |
|
| 681 | + * @static |
|
| 682 | + * @deprecated instead use TableManager::addColumn() |
|
| 683 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 684 | + * @param string $column_name |
|
| 685 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 686 | + * 'VARCHAR(10)' |
|
| 687 | + * @return bool|int |
|
| 688 | + */ |
|
| 689 | + public static function add_column_if_it_doesnt_exist( |
|
| 690 | + $table_name, |
|
| 691 | + $column_name, |
|
| 692 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
| 693 | + ) { |
|
| 694 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * get_fields_on_table |
|
| 700 | + * Gets all the fields on the database table. |
|
| 701 | + * |
|
| 702 | + * @access public |
|
| 703 | + * @deprecated instead use TableManager::getTableColumns() |
|
| 704 | + * @static |
|
| 705 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
| 706 | + * @return array of database column names |
|
| 707 | + */ |
|
| 708 | + public static function get_fields_on_table($table_name = null) |
|
| 709 | + { |
|
| 710 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + |
|
| 714 | + /** |
|
| 715 | + * db_table_is_empty |
|
| 716 | + * |
|
| 717 | + * @access public\ |
|
| 718 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 719 | + * @static |
|
| 720 | + * @param string $table_name |
|
| 721 | + * @return bool |
|
| 722 | + */ |
|
| 723 | + public static function db_table_is_empty($table_name) |
|
| 724 | + { |
|
| 725 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * delete_db_table_if_empty |
|
| 731 | + * |
|
| 732 | + * @access public |
|
| 733 | + * @static |
|
| 734 | + * @param string $table_name |
|
| 735 | + * @return bool | int |
|
| 736 | + */ |
|
| 737 | + public static function delete_db_table_if_empty($table_name) |
|
| 738 | + { |
|
| 739 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 740 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 741 | + } |
|
| 742 | + return false; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * delete_unused_db_table |
|
| 748 | + * |
|
| 749 | + * @access public |
|
| 750 | + * @static |
|
| 751 | + * @deprecated instead use TableManager::dropTable() |
|
| 752 | + * @param string $table_name |
|
| 753 | + * @return bool | int |
|
| 754 | + */ |
|
| 755 | + public static function delete_unused_db_table($table_name) |
|
| 756 | + { |
|
| 757 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * drop_index |
|
| 763 | + * |
|
| 764 | + * @access public |
|
| 765 | + * @static |
|
| 766 | + * @deprecated instead use TableManager::dropIndex() |
|
| 767 | + * @param string $table_name |
|
| 768 | + * @param string $index_name |
|
| 769 | + * @return bool | int |
|
| 770 | + */ |
|
| 771 | + public static function drop_index($table_name, $index_name) |
|
| 772 | + { |
|
| 773 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * create_database_tables |
|
| 780 | + * |
|
| 781 | + * @access public |
|
| 782 | + * @static |
|
| 783 | + * @throws EE_Error |
|
| 784 | + * @return boolean success (whether database is setup properly or not) |
|
| 785 | + */ |
|
| 786 | + public static function create_database_tables() |
|
| 787 | + { |
|
| 788 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 789 | + // find the migration script that sets the database to be compatible with the code |
|
| 790 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 791 | + if ($dms_name) { |
|
| 792 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 793 | + $current_data_migration_script->set_migrating(false); |
|
| 794 | + $current_data_migration_script->schema_changes_before_migration(); |
|
| 795 | + $current_data_migration_script->schema_changes_after_migration(); |
|
| 796 | + if ($current_data_migration_script->get_errors()) { |
|
| 797 | + if (WP_DEBUG) { |
|
| 798 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 799 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 800 | + } |
|
| 801 | + } else { |
|
| 802 | + EE_Error::add_error( |
|
| 803 | + __( |
|
| 804 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 805 | 805 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
| 806 | - 'event_espresso' |
|
| 807 | - ) |
|
| 808 | - ); |
|
| 809 | - } |
|
| 810 | - return false; |
|
| 811 | - } |
|
| 812 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 813 | - } else { |
|
| 814 | - EE_Error::add_error( |
|
| 815 | - __( |
|
| 816 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 806 | + 'event_espresso' |
|
| 807 | + ) |
|
| 808 | + ); |
|
| 809 | + } |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 813 | + } else { |
|
| 814 | + EE_Error::add_error( |
|
| 815 | + __( |
|
| 816 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 817 | 817 | structure. So database is probably not setup properly', |
| 818 | - 'event_espresso' |
|
| 819 | - ), |
|
| 820 | - __FILE__, |
|
| 821 | - __FUNCTION__, |
|
| 822 | - __LINE__ |
|
| 823 | - ); |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - return true; |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - |
|
| 830 | - |
|
| 831 | - /** |
|
| 832 | - * initialize_system_questions |
|
| 833 | - * |
|
| 834 | - * @access public |
|
| 835 | - * @static |
|
| 836 | - * @return void |
|
| 837 | - */ |
|
| 838 | - public static function initialize_system_questions() |
|
| 839 | - { |
|
| 840 | - // QUESTION GROUPS |
|
| 841 | - global $wpdb; |
|
| 842 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 843 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 844 | - // what we have |
|
| 845 | - $question_groups = $wpdb->get_col($SQL); |
|
| 846 | - // check the response |
|
| 847 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 848 | - // what we should have |
|
| 849 | - $QSG_systems = array(1, 2); |
|
| 850 | - // loop thru what we should have and compare to what we have |
|
| 851 | - foreach ($QSG_systems as $QSG_system) { |
|
| 852 | - // reset values array |
|
| 853 | - $QSG_values = array(); |
|
| 854 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 855 | - if (! in_array("$QSG_system", $question_groups)) { |
|
| 856 | - // add it |
|
| 857 | - switch ($QSG_system) { |
|
| 858 | - case 1: |
|
| 859 | - $QSG_values = array( |
|
| 860 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 861 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 862 | - 'QSG_desc' => '', |
|
| 863 | - 'QSG_order' => 1, |
|
| 864 | - 'QSG_show_group_name' => 1, |
|
| 865 | - 'QSG_show_group_desc' => 1, |
|
| 866 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 867 | - 'QSG_deleted' => 0, |
|
| 868 | - ); |
|
| 869 | - break; |
|
| 870 | - case 2: |
|
| 871 | - $QSG_values = array( |
|
| 872 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 873 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 874 | - 'QSG_desc' => '', |
|
| 875 | - 'QSG_order' => 2, |
|
| 876 | - 'QSG_show_group_name' => 1, |
|
| 877 | - 'QSG_show_group_desc' => 1, |
|
| 878 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
| 879 | - 'QSG_deleted' => 0, |
|
| 880 | - ); |
|
| 881 | - break; |
|
| 882 | - } |
|
| 883 | - // make sure we have some values before inserting them |
|
| 884 | - if (! empty($QSG_values)) { |
|
| 885 | - // insert system question |
|
| 886 | - $wpdb->insert( |
|
| 887 | - $table_name, |
|
| 888 | - $QSG_values, |
|
| 889 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 890 | - ); |
|
| 891 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - } |
|
| 895 | - // QUESTIONS |
|
| 896 | - global $wpdb; |
|
| 897 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 898 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 899 | - // what we have |
|
| 900 | - $questions = $wpdb->get_col($SQL); |
|
| 901 | - // what we should have |
|
| 902 | - $QST_systems = array( |
|
| 903 | - 'fname', |
|
| 904 | - 'lname', |
|
| 905 | - 'email', |
|
| 906 | - 'address', |
|
| 907 | - 'address2', |
|
| 908 | - 'city', |
|
| 909 | - 'country', |
|
| 910 | - 'state', |
|
| 911 | - 'zip', |
|
| 912 | - 'phone', |
|
| 913 | - ); |
|
| 914 | - $order_for_group_1 = 1; |
|
| 915 | - $order_for_group_2 = 1; |
|
| 916 | - // loop thru what we should have and compare to what we have |
|
| 917 | - foreach ($QST_systems as $QST_system) { |
|
| 918 | - // reset values array |
|
| 919 | - $QST_values = array(); |
|
| 920 | - // if we don't have what we should have |
|
| 921 | - if (! in_array($QST_system, $questions)) { |
|
| 922 | - // add it |
|
| 923 | - switch ($QST_system) { |
|
| 924 | - case 'fname': |
|
| 925 | - $QST_values = array( |
|
| 926 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 927 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 928 | - 'QST_system' => 'fname', |
|
| 929 | - 'QST_type' => 'TEXT', |
|
| 930 | - 'QST_required' => 1, |
|
| 931 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 932 | - 'QST_order' => 1, |
|
| 933 | - 'QST_admin_only' => 0, |
|
| 934 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 935 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 936 | - 'QST_deleted' => 0, |
|
| 937 | - ); |
|
| 938 | - break; |
|
| 939 | - case 'lname': |
|
| 940 | - $QST_values = array( |
|
| 941 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 942 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 943 | - 'QST_system' => 'lname', |
|
| 944 | - 'QST_type' => 'TEXT', |
|
| 945 | - 'QST_required' => 1, |
|
| 946 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 947 | - 'QST_order' => 2, |
|
| 948 | - 'QST_admin_only' => 0, |
|
| 949 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 950 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 951 | - 'QST_deleted' => 0, |
|
| 952 | - ); |
|
| 953 | - break; |
|
| 954 | - case 'email': |
|
| 955 | - $QST_values = array( |
|
| 956 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 957 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 958 | - 'QST_system' => 'email', |
|
| 959 | - 'QST_type' => 'EMAIL', |
|
| 960 | - 'QST_required' => 1, |
|
| 961 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 962 | - 'QST_order' => 3, |
|
| 963 | - 'QST_admin_only' => 0, |
|
| 964 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 965 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 966 | - 'QST_deleted' => 0, |
|
| 967 | - ); |
|
| 968 | - break; |
|
| 969 | - case 'address': |
|
| 970 | - $QST_values = array( |
|
| 971 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 972 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 973 | - 'QST_system' => 'address', |
|
| 974 | - 'QST_type' => 'TEXT', |
|
| 975 | - 'QST_required' => 0, |
|
| 976 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 977 | - 'QST_order' => 4, |
|
| 978 | - 'QST_admin_only' => 0, |
|
| 979 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 980 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 981 | - 'QST_deleted' => 0, |
|
| 982 | - ); |
|
| 983 | - break; |
|
| 984 | - case 'address2': |
|
| 985 | - $QST_values = array( |
|
| 986 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 987 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 988 | - 'QST_system' => 'address2', |
|
| 989 | - 'QST_type' => 'TEXT', |
|
| 990 | - 'QST_required' => 0, |
|
| 991 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 992 | - 'QST_order' => 5, |
|
| 993 | - 'QST_admin_only' => 0, |
|
| 994 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 995 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 996 | - 'QST_deleted' => 0, |
|
| 997 | - ); |
|
| 998 | - break; |
|
| 999 | - case 'city': |
|
| 1000 | - $QST_values = array( |
|
| 1001 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1002 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1003 | - 'QST_system' => 'city', |
|
| 1004 | - 'QST_type' => 'TEXT', |
|
| 1005 | - 'QST_required' => 0, |
|
| 1006 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1007 | - 'QST_order' => 6, |
|
| 1008 | - 'QST_admin_only' => 0, |
|
| 1009 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1010 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1011 | - 'QST_deleted' => 0, |
|
| 1012 | - ); |
|
| 1013 | - break; |
|
| 1014 | - case 'country': |
|
| 1015 | - $QST_values = array( |
|
| 1016 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1017 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1018 | - 'QST_system' => 'country', |
|
| 1019 | - 'QST_type' => 'COUNTRY', |
|
| 1020 | - 'QST_required' => 0, |
|
| 1021 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1022 | - 'QST_order' => 7, |
|
| 1023 | - 'QST_admin_only' => 0, |
|
| 1024 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1025 | - 'QST_deleted' => 0, |
|
| 1026 | - ); |
|
| 1027 | - break; |
|
| 1028 | - case 'state': |
|
| 1029 | - $QST_values = array( |
|
| 1030 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1031 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1032 | - 'QST_system' => 'state', |
|
| 1033 | - 'QST_type' => 'STATE', |
|
| 1034 | - 'QST_required' => 0, |
|
| 1035 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1036 | - 'QST_order' => 8, |
|
| 1037 | - 'QST_admin_only' => 0, |
|
| 1038 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1039 | - 'QST_deleted' => 0, |
|
| 1040 | - ); |
|
| 1041 | - break; |
|
| 1042 | - case 'zip': |
|
| 1043 | - $QST_values = array( |
|
| 1044 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1045 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1046 | - 'QST_system' => 'zip', |
|
| 1047 | - 'QST_type' => 'TEXT', |
|
| 1048 | - 'QST_required' => 0, |
|
| 1049 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1050 | - 'QST_order' => 9, |
|
| 1051 | - 'QST_admin_only' => 0, |
|
| 1052 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1053 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1054 | - 'QST_deleted' => 0, |
|
| 1055 | - ); |
|
| 1056 | - break; |
|
| 1057 | - case 'phone': |
|
| 1058 | - $QST_values = array( |
|
| 1059 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1060 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1061 | - 'QST_system' => 'phone', |
|
| 1062 | - 'QST_type' => 'TEXT', |
|
| 1063 | - 'QST_required' => 0, |
|
| 1064 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1065 | - 'QST_order' => 10, |
|
| 1066 | - 'QST_admin_only' => 0, |
|
| 1067 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1068 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1069 | - 'QST_deleted' => 0, |
|
| 1070 | - ); |
|
| 1071 | - break; |
|
| 1072 | - } |
|
| 1073 | - if (! empty($QST_values)) { |
|
| 1074 | - // insert system question |
|
| 1075 | - $wpdb->insert( |
|
| 1076 | - $table_name, |
|
| 1077 | - $QST_values, |
|
| 1078 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1079 | - ); |
|
| 1080 | - $QST_ID = $wpdb->insert_id; |
|
| 1081 | - // QUESTION GROUP QUESTIONS |
|
| 1082 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1083 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1084 | - } else { |
|
| 1085 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1086 | - } |
|
| 1087 | - if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
| 1088 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
| 1089 | - } else { |
|
| 1090 | - $id_col = EEM_Question_Group::instance() |
|
| 1091 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1092 | - if (is_array($id_col)) { |
|
| 1093 | - $QSG_ID = reset($id_col); |
|
| 1094 | - } else { |
|
| 1095 | - // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1096 | - EE_Log::instance()->log( |
|
| 1097 | - __FILE__, |
|
| 1098 | - __FUNCTION__, |
|
| 1099 | - sprintf( |
|
| 1100 | - __( |
|
| 1101 | - 'Could not associate question %1$s to a question group because no system question |
|
| 818 | + 'event_espresso' |
|
| 819 | + ), |
|
| 820 | + __FILE__, |
|
| 821 | + __FUNCTION__, |
|
| 822 | + __LINE__ |
|
| 823 | + ); |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + return true; |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | + * initialize_system_questions |
|
| 833 | + * |
|
| 834 | + * @access public |
|
| 835 | + * @static |
|
| 836 | + * @return void |
|
| 837 | + */ |
|
| 838 | + public static function initialize_system_questions() |
|
| 839 | + { |
|
| 840 | + // QUESTION GROUPS |
|
| 841 | + global $wpdb; |
|
| 842 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 843 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 844 | + // what we have |
|
| 845 | + $question_groups = $wpdb->get_col($SQL); |
|
| 846 | + // check the response |
|
| 847 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 848 | + // what we should have |
|
| 849 | + $QSG_systems = array(1, 2); |
|
| 850 | + // loop thru what we should have and compare to what we have |
|
| 851 | + foreach ($QSG_systems as $QSG_system) { |
|
| 852 | + // reset values array |
|
| 853 | + $QSG_values = array(); |
|
| 854 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 855 | + if (! in_array("$QSG_system", $question_groups)) { |
|
| 856 | + // add it |
|
| 857 | + switch ($QSG_system) { |
|
| 858 | + case 1: |
|
| 859 | + $QSG_values = array( |
|
| 860 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 861 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
| 862 | + 'QSG_desc' => '', |
|
| 863 | + 'QSG_order' => 1, |
|
| 864 | + 'QSG_show_group_name' => 1, |
|
| 865 | + 'QSG_show_group_desc' => 1, |
|
| 866 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 867 | + 'QSG_deleted' => 0, |
|
| 868 | + ); |
|
| 869 | + break; |
|
| 870 | + case 2: |
|
| 871 | + $QSG_values = array( |
|
| 872 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 873 | + 'QSG_identifier' => 'address-information-' . time(), |
|
| 874 | + 'QSG_desc' => '', |
|
| 875 | + 'QSG_order' => 2, |
|
| 876 | + 'QSG_show_group_name' => 1, |
|
| 877 | + 'QSG_show_group_desc' => 1, |
|
| 878 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
| 879 | + 'QSG_deleted' => 0, |
|
| 880 | + ); |
|
| 881 | + break; |
|
| 882 | + } |
|
| 883 | + // make sure we have some values before inserting them |
|
| 884 | + if (! empty($QSG_values)) { |
|
| 885 | + // insert system question |
|
| 886 | + $wpdb->insert( |
|
| 887 | + $table_name, |
|
| 888 | + $QSG_values, |
|
| 889 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 890 | + ); |
|
| 891 | + $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + } |
|
| 895 | + // QUESTIONS |
|
| 896 | + global $wpdb; |
|
| 897 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 898 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 899 | + // what we have |
|
| 900 | + $questions = $wpdb->get_col($SQL); |
|
| 901 | + // what we should have |
|
| 902 | + $QST_systems = array( |
|
| 903 | + 'fname', |
|
| 904 | + 'lname', |
|
| 905 | + 'email', |
|
| 906 | + 'address', |
|
| 907 | + 'address2', |
|
| 908 | + 'city', |
|
| 909 | + 'country', |
|
| 910 | + 'state', |
|
| 911 | + 'zip', |
|
| 912 | + 'phone', |
|
| 913 | + ); |
|
| 914 | + $order_for_group_1 = 1; |
|
| 915 | + $order_for_group_2 = 1; |
|
| 916 | + // loop thru what we should have and compare to what we have |
|
| 917 | + foreach ($QST_systems as $QST_system) { |
|
| 918 | + // reset values array |
|
| 919 | + $QST_values = array(); |
|
| 920 | + // if we don't have what we should have |
|
| 921 | + if (! in_array($QST_system, $questions)) { |
|
| 922 | + // add it |
|
| 923 | + switch ($QST_system) { |
|
| 924 | + case 'fname': |
|
| 925 | + $QST_values = array( |
|
| 926 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 927 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 928 | + 'QST_system' => 'fname', |
|
| 929 | + 'QST_type' => 'TEXT', |
|
| 930 | + 'QST_required' => 1, |
|
| 931 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 932 | + 'QST_order' => 1, |
|
| 933 | + 'QST_admin_only' => 0, |
|
| 934 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 935 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 936 | + 'QST_deleted' => 0, |
|
| 937 | + ); |
|
| 938 | + break; |
|
| 939 | + case 'lname': |
|
| 940 | + $QST_values = array( |
|
| 941 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 942 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 943 | + 'QST_system' => 'lname', |
|
| 944 | + 'QST_type' => 'TEXT', |
|
| 945 | + 'QST_required' => 1, |
|
| 946 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 947 | + 'QST_order' => 2, |
|
| 948 | + 'QST_admin_only' => 0, |
|
| 949 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 950 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 951 | + 'QST_deleted' => 0, |
|
| 952 | + ); |
|
| 953 | + break; |
|
| 954 | + case 'email': |
|
| 955 | + $QST_values = array( |
|
| 956 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 957 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 958 | + 'QST_system' => 'email', |
|
| 959 | + 'QST_type' => 'EMAIL', |
|
| 960 | + 'QST_required' => 1, |
|
| 961 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 962 | + 'QST_order' => 3, |
|
| 963 | + 'QST_admin_only' => 0, |
|
| 964 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 965 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 966 | + 'QST_deleted' => 0, |
|
| 967 | + ); |
|
| 968 | + break; |
|
| 969 | + case 'address': |
|
| 970 | + $QST_values = array( |
|
| 971 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 972 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 973 | + 'QST_system' => 'address', |
|
| 974 | + 'QST_type' => 'TEXT', |
|
| 975 | + 'QST_required' => 0, |
|
| 976 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 977 | + 'QST_order' => 4, |
|
| 978 | + 'QST_admin_only' => 0, |
|
| 979 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 980 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 981 | + 'QST_deleted' => 0, |
|
| 982 | + ); |
|
| 983 | + break; |
|
| 984 | + case 'address2': |
|
| 985 | + $QST_values = array( |
|
| 986 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 987 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 988 | + 'QST_system' => 'address2', |
|
| 989 | + 'QST_type' => 'TEXT', |
|
| 990 | + 'QST_required' => 0, |
|
| 991 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 992 | + 'QST_order' => 5, |
|
| 993 | + 'QST_admin_only' => 0, |
|
| 994 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 995 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 996 | + 'QST_deleted' => 0, |
|
| 997 | + ); |
|
| 998 | + break; |
|
| 999 | + case 'city': |
|
| 1000 | + $QST_values = array( |
|
| 1001 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1002 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1003 | + 'QST_system' => 'city', |
|
| 1004 | + 'QST_type' => 'TEXT', |
|
| 1005 | + 'QST_required' => 0, |
|
| 1006 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1007 | + 'QST_order' => 6, |
|
| 1008 | + 'QST_admin_only' => 0, |
|
| 1009 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1010 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1011 | + 'QST_deleted' => 0, |
|
| 1012 | + ); |
|
| 1013 | + break; |
|
| 1014 | + case 'country': |
|
| 1015 | + $QST_values = array( |
|
| 1016 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1017 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1018 | + 'QST_system' => 'country', |
|
| 1019 | + 'QST_type' => 'COUNTRY', |
|
| 1020 | + 'QST_required' => 0, |
|
| 1021 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1022 | + 'QST_order' => 7, |
|
| 1023 | + 'QST_admin_only' => 0, |
|
| 1024 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1025 | + 'QST_deleted' => 0, |
|
| 1026 | + ); |
|
| 1027 | + break; |
|
| 1028 | + case 'state': |
|
| 1029 | + $QST_values = array( |
|
| 1030 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1031 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1032 | + 'QST_system' => 'state', |
|
| 1033 | + 'QST_type' => 'STATE', |
|
| 1034 | + 'QST_required' => 0, |
|
| 1035 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1036 | + 'QST_order' => 8, |
|
| 1037 | + 'QST_admin_only' => 0, |
|
| 1038 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1039 | + 'QST_deleted' => 0, |
|
| 1040 | + ); |
|
| 1041 | + break; |
|
| 1042 | + case 'zip': |
|
| 1043 | + $QST_values = array( |
|
| 1044 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1045 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1046 | + 'QST_system' => 'zip', |
|
| 1047 | + 'QST_type' => 'TEXT', |
|
| 1048 | + 'QST_required' => 0, |
|
| 1049 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1050 | + 'QST_order' => 9, |
|
| 1051 | + 'QST_admin_only' => 0, |
|
| 1052 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1053 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1054 | + 'QST_deleted' => 0, |
|
| 1055 | + ); |
|
| 1056 | + break; |
|
| 1057 | + case 'phone': |
|
| 1058 | + $QST_values = array( |
|
| 1059 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1060 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1061 | + 'QST_system' => 'phone', |
|
| 1062 | + 'QST_type' => 'TEXT', |
|
| 1063 | + 'QST_required' => 0, |
|
| 1064 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1065 | + 'QST_order' => 10, |
|
| 1066 | + 'QST_admin_only' => 0, |
|
| 1067 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1068 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1069 | + 'QST_deleted' => 0, |
|
| 1070 | + ); |
|
| 1071 | + break; |
|
| 1072 | + } |
|
| 1073 | + if (! empty($QST_values)) { |
|
| 1074 | + // insert system question |
|
| 1075 | + $wpdb->insert( |
|
| 1076 | + $table_name, |
|
| 1077 | + $QST_values, |
|
| 1078 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1079 | + ); |
|
| 1080 | + $QST_ID = $wpdb->insert_id; |
|
| 1081 | + // QUESTION GROUP QUESTIONS |
|
| 1082 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1083 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1084 | + } else { |
|
| 1085 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1086 | + } |
|
| 1087 | + if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
| 1088 | + $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
| 1089 | + } else { |
|
| 1090 | + $id_col = EEM_Question_Group::instance() |
|
| 1091 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1092 | + if (is_array($id_col)) { |
|
| 1093 | + $QSG_ID = reset($id_col); |
|
| 1094 | + } else { |
|
| 1095 | + // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1096 | + EE_Log::instance()->log( |
|
| 1097 | + __FILE__, |
|
| 1098 | + __FUNCTION__, |
|
| 1099 | + sprintf( |
|
| 1100 | + __( |
|
| 1101 | + 'Could not associate question %1$s to a question group because no system question |
|
| 1102 | 1102 | group existed', |
| 1103 | - 'event_espresso' |
|
| 1104 | - ), |
|
| 1105 | - $QST_ID |
|
| 1106 | - ), |
|
| 1107 | - 'error' |
|
| 1108 | - ); |
|
| 1109 | - continue; |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - // add system questions to groups |
|
| 1113 | - $wpdb->insert( |
|
| 1114 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1115 | - array( |
|
| 1116 | - 'QSG_ID' => $QSG_ID, |
|
| 1117 | - 'QST_ID' => $QST_ID, |
|
| 1118 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1119 | - ), |
|
| 1120 | - array('%d', '%d', '%d') |
|
| 1121 | - ); |
|
| 1122 | - } |
|
| 1123 | - } |
|
| 1124 | - } |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - |
|
| 1128 | - /** |
|
| 1129 | - * Makes sure the default payment method (Invoice) is active. |
|
| 1130 | - * This used to be done automatically as part of constructing the old gateways config |
|
| 1131 | - * |
|
| 1132 | - * @throws \EE_Error |
|
| 1133 | - */ |
|
| 1134 | - public static function insert_default_payment_methods() |
|
| 1135 | - { |
|
| 1136 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1137 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1138 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1139 | - } else { |
|
| 1140 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1141 | - } |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * insert_default_status_codes |
|
| 1146 | - * |
|
| 1147 | - * @access public |
|
| 1148 | - * @static |
|
| 1149 | - * @return void |
|
| 1150 | - */ |
|
| 1151 | - public static function insert_default_status_codes() |
|
| 1152 | - { |
|
| 1153 | - |
|
| 1154 | - global $wpdb; |
|
| 1155 | - |
|
| 1156 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1157 | - $table_name = EEM_Status::instance()->table(); |
|
| 1158 | - |
|
| 1159 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1160 | - $wpdb->query($SQL); |
|
| 1161 | - |
|
| 1162 | - $SQL = "INSERT INTO $table_name |
|
| 1103 | + 'event_espresso' |
|
| 1104 | + ), |
|
| 1105 | + $QST_ID |
|
| 1106 | + ), |
|
| 1107 | + 'error' |
|
| 1108 | + ); |
|
| 1109 | + continue; |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + // add system questions to groups |
|
| 1113 | + $wpdb->insert( |
|
| 1114 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1115 | + array( |
|
| 1116 | + 'QSG_ID' => $QSG_ID, |
|
| 1117 | + 'QST_ID' => $QST_ID, |
|
| 1118 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1119 | + ), |
|
| 1120 | + array('%d', '%d', '%d') |
|
| 1121 | + ); |
|
| 1122 | + } |
|
| 1123 | + } |
|
| 1124 | + } |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + |
|
| 1128 | + /** |
|
| 1129 | + * Makes sure the default payment method (Invoice) is active. |
|
| 1130 | + * This used to be done automatically as part of constructing the old gateways config |
|
| 1131 | + * |
|
| 1132 | + * @throws \EE_Error |
|
| 1133 | + */ |
|
| 1134 | + public static function insert_default_payment_methods() |
|
| 1135 | + { |
|
| 1136 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1137 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1138 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1139 | + } else { |
|
| 1140 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1141 | + } |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * insert_default_status_codes |
|
| 1146 | + * |
|
| 1147 | + * @access public |
|
| 1148 | + * @static |
|
| 1149 | + * @return void |
|
| 1150 | + */ |
|
| 1151 | + public static function insert_default_status_codes() |
|
| 1152 | + { |
|
| 1153 | + |
|
| 1154 | + global $wpdb; |
|
| 1155 | + |
|
| 1156 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1157 | + $table_name = EEM_Status::instance()->table(); |
|
| 1158 | + |
|
| 1159 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1160 | + $wpdb->query($SQL); |
|
| 1161 | + |
|
| 1162 | + $SQL = "INSERT INTO $table_name |
|
| 1163 | 1163 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
| 1164 | 1164 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
| 1165 | 1165 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1199,457 +1199,457 @@ discard block |
||
| 1199 | 1199 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
| 1200 | 1200 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
| 1201 | 1201 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
| 1202 | - $wpdb->query($SQL); |
|
| 1203 | - } |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - |
|
| 1207 | - /** |
|
| 1208 | - * generate_default_message_templates |
|
| 1209 | - * |
|
| 1210 | - * @static |
|
| 1211 | - * @throws EE_Error |
|
| 1212 | - * @return bool true means new templates were created. |
|
| 1213 | - * false means no templates were created. |
|
| 1214 | - * This is NOT an error flag. To check for errors you will want |
|
| 1215 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1216 | - */ |
|
| 1217 | - public static function generate_default_message_templates() |
|
| 1218 | - { |
|
| 1219 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1220 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1221 | - /* |
|
| 1202 | + $wpdb->query($SQL); |
|
| 1203 | + } |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + |
|
| 1207 | + /** |
|
| 1208 | + * generate_default_message_templates |
|
| 1209 | + * |
|
| 1210 | + * @static |
|
| 1211 | + * @throws EE_Error |
|
| 1212 | + * @return bool true means new templates were created. |
|
| 1213 | + * false means no templates were created. |
|
| 1214 | + * This is NOT an error flag. To check for errors you will want |
|
| 1215 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1216 | + */ |
|
| 1217 | + public static function generate_default_message_templates() |
|
| 1218 | + { |
|
| 1219 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1220 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1221 | + /* |
|
| 1222 | 1222 | * This first method is taking care of ensuring any default messengers |
| 1223 | 1223 | * that should be made active and have templates generated are done. |
| 1224 | 1224 | */ |
| 1225 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1226 | - $message_resource_manager |
|
| 1227 | - ); |
|
| 1228 | - /** |
|
| 1229 | - * This method is verifying there are no NEW default message types |
|
| 1230 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1231 | - */ |
|
| 1232 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1233 | - $message_resource_manager |
|
| 1234 | - ); |
|
| 1235 | - // after all is done, let's persist these changes to the db. |
|
| 1236 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1237 | - $message_resource_manager->update_active_messengers_option(); |
|
| 1238 | - // will return true if either of these are true. Otherwise will return false. |
|
| 1239 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - |
|
| 1244 | - /** |
|
| 1245 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1246 | - * @return array|bool |
|
| 1247 | - * @throws \EE_Error |
|
| 1248 | - */ |
|
| 1249 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1250 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1251 | - ) { |
|
| 1252 | - /** @type EE_messenger[] $active_messengers */ |
|
| 1253 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1254 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1255 | - $templates_created = false; |
|
| 1256 | - foreach ($active_messengers as $active_messenger) { |
|
| 1257 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1258 | - $default_message_type_names_to_activate = array(); |
|
| 1259 | - // looping through each default message type reported by the messenger |
|
| 1260 | - // and setup the actual message types to activate. |
|
| 1261 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1262 | - // if already active or has already been activated before we skip |
|
| 1263 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1264 | - // we also skip if the message type is not installed. |
|
| 1265 | - if ($message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1266 | - $default_message_type_name_for_messenger, |
|
| 1267 | - $active_messenger->name |
|
| 1268 | - ) |
|
| 1269 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1270 | - $active_messenger->name, |
|
| 1271 | - $default_message_type_name_for_messenger |
|
| 1272 | - ) |
|
| 1273 | - || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
| 1274 | - ) { |
|
| 1275 | - continue; |
|
| 1276 | - } |
|
| 1277 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1278 | - } |
|
| 1279 | - // let's activate! |
|
| 1280 | - $message_resource_manager->ensure_message_types_are_active( |
|
| 1281 | - $default_message_type_names_to_activate, |
|
| 1282 | - $active_messenger->name, |
|
| 1283 | - false |
|
| 1284 | - ); |
|
| 1285 | - // activate the templates for these message types |
|
| 1286 | - if (! empty($default_message_type_names_to_activate)) { |
|
| 1287 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1288 | - $active_messenger->name, |
|
| 1289 | - $default_message_type_names_for_messenger, |
|
| 1290 | - '', |
|
| 1291 | - true |
|
| 1292 | - ); |
|
| 1293 | - } |
|
| 1294 | - } |
|
| 1295 | - return $templates_created; |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - |
|
| 1299 | - |
|
| 1300 | - /** |
|
| 1301 | - * This will activate and generate default messengers and default message types for those messengers. |
|
| 1302 | - * |
|
| 1303 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1304 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1305 | - * False means that there were no templates generated |
|
| 1306 | - * (which could simply mean there are no default message types for a messenger). |
|
| 1307 | - * @throws EE_Error |
|
| 1308 | - */ |
|
| 1309 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1310 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1311 | - ) { |
|
| 1312 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1313 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1314 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1315 | - $templates_generated = false; |
|
| 1316 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1317 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1318 | - // verify the default message types match an installed message type. |
|
| 1319 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1320 | - if (! isset($installed_message_types[ $name ]) |
|
| 1321 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1322 | - $name, |
|
| 1323 | - $messenger_to_generate->name |
|
| 1324 | - ) |
|
| 1325 | - ) { |
|
| 1326 | - unset($default_message_type_names_for_messenger[ $key ]); |
|
| 1327 | - } |
|
| 1328 | - } |
|
| 1329 | - // in previous iterations, the active_messengers option in the db |
|
| 1330 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1331 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1332 | - // passing off to create templates (after the refactor is done). |
|
| 1333 | - // @todo remove this comment when determined not necessary. |
|
| 1334 | - $message_resource_manager->activate_messenger( |
|
| 1335 | - $messenger_to_generate->name, |
|
| 1336 | - $default_message_type_names_for_messenger, |
|
| 1337 | - false |
|
| 1338 | - ); |
|
| 1339 | - // create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1340 | - if (! empty($default_message_type_names_for_messenger)) { |
|
| 1341 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1342 | - $messenger_to_generate->name, |
|
| 1343 | - $default_message_type_names_for_messenger, |
|
| 1344 | - '', |
|
| 1345 | - true |
|
| 1346 | - ); |
|
| 1347 | - } |
|
| 1348 | - } |
|
| 1349 | - return $templates_generated; |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - |
|
| 1353 | - /** |
|
| 1354 | - * This returns the default messengers to generate templates for on activation of EE. |
|
| 1355 | - * It considers: |
|
| 1356 | - * - whether a messenger is already active in the db. |
|
| 1357 | - * - whether a messenger has been made active at any time in the past. |
|
| 1358 | - * |
|
| 1359 | - * @static |
|
| 1360 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1361 | - * @return EE_messenger[] |
|
| 1362 | - */ |
|
| 1363 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1364 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1365 | - ) { |
|
| 1366 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1367 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1368 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1369 | - |
|
| 1370 | - $messengers_to_generate = array(); |
|
| 1371 | - foreach ($installed_messengers as $installed_messenger) { |
|
| 1372 | - // if installed messenger is a messenger that should be activated on install |
|
| 1373 | - // and is not already active |
|
| 1374 | - // and has never been activated |
|
| 1375 | - if (! $installed_messenger->activate_on_install |
|
| 1376 | - || isset($active_messengers[ $installed_messenger->name ]) |
|
| 1377 | - || isset($has_activated[ $installed_messenger->name ]) |
|
| 1378 | - ) { |
|
| 1379 | - continue; |
|
| 1380 | - } |
|
| 1381 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
| 1382 | - } |
|
| 1383 | - return $messengers_to_generate; |
|
| 1384 | - } |
|
| 1385 | - |
|
| 1386 | - |
|
| 1387 | - /** |
|
| 1388 | - * This simply validates active message types to ensure they actually match installed |
|
| 1389 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1390 | - * rows are set inactive. |
|
| 1391 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1392 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1393 | - * are still handled in here. |
|
| 1394 | - * |
|
| 1395 | - * @since 4.3.1 |
|
| 1396 | - * @return void |
|
| 1397 | - */ |
|
| 1398 | - public static function validate_messages_system() |
|
| 1399 | - { |
|
| 1400 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1401 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1402 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1403 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - |
|
| 1407 | - /** |
|
| 1408 | - * create_no_ticket_prices_array |
|
| 1409 | - * |
|
| 1410 | - * @access public |
|
| 1411 | - * @static |
|
| 1412 | - * @return void |
|
| 1413 | - */ |
|
| 1414 | - public static function create_no_ticket_prices_array() |
|
| 1415 | - { |
|
| 1416 | - // this creates an array for tracking events that have no active ticket prices created |
|
| 1417 | - // this allows us to warn admins of the situation so that it can be corrected |
|
| 1418 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1419 | - if (! $espresso_no_ticket_prices) { |
|
| 1420 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - |
|
| 1425 | - /** |
|
| 1426 | - * plugin_deactivation |
|
| 1427 | - * |
|
| 1428 | - * @access public |
|
| 1429 | - * @static |
|
| 1430 | - * @return void |
|
| 1431 | - */ |
|
| 1432 | - public static function plugin_deactivation() |
|
| 1433 | - { |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - |
|
| 1437 | - /** |
|
| 1438 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1439 | - * (like post meta or term relations) |
|
| 1440 | - * |
|
| 1441 | - * @global wpdb $wpdb |
|
| 1442 | - * @throws \EE_Error |
|
| 1443 | - */ |
|
| 1444 | - public static function delete_all_espresso_cpt_data() |
|
| 1445 | - { |
|
| 1446 | - global $wpdb; |
|
| 1447 | - // get all the CPT post_types |
|
| 1448 | - $ee_post_types = array(); |
|
| 1449 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1450 | - if (method_exists($model_name, 'instance')) { |
|
| 1451 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1452 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1453 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1454 | - } |
|
| 1455 | - } |
|
| 1456 | - } |
|
| 1457 | - // get all our CPTs |
|
| 1458 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1459 | - $cpt_ids = $wpdb->get_col($query); |
|
| 1460 | - // delete each post meta and term relations too |
|
| 1461 | - foreach ($cpt_ids as $post_id) { |
|
| 1462 | - wp_delete_post($post_id, true); |
|
| 1463 | - } |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * Deletes all EE custom tables |
|
| 1468 | - * |
|
| 1469 | - * @return array |
|
| 1470 | - */ |
|
| 1471 | - public static function drop_espresso_tables() |
|
| 1472 | - { |
|
| 1473 | - $tables = array(); |
|
| 1474 | - // load registry |
|
| 1475 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1476 | - if (method_exists($model_name, 'instance')) { |
|
| 1477 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1478 | - if ($model_obj instanceof EEM_Base) { |
|
| 1479 | - foreach ($model_obj->get_tables() as $table) { |
|
| 1480 | - if (strpos($table->get_table_name(), 'esp_') |
|
| 1481 | - && |
|
| 1482 | - ( |
|
| 1483 | - is_main_site()// main site? nuke them all |
|
| 1484 | - || ! $table->is_global()// not main site,but not global either. nuke it |
|
| 1485 | - ) |
|
| 1486 | - ) { |
|
| 1487 | - $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
| 1488 | - } |
|
| 1489 | - } |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - // there are some tables whose models were removed. |
|
| 1495 | - // they should be removed when removing all EE core's data |
|
| 1496 | - $tables_without_models = array( |
|
| 1497 | - 'esp_promotion', |
|
| 1498 | - 'esp_promotion_applied', |
|
| 1499 | - 'esp_promotion_object', |
|
| 1500 | - 'esp_promotion_rule', |
|
| 1501 | - 'esp_rule', |
|
| 1502 | - ); |
|
| 1503 | - foreach ($tables_without_models as $table) { |
|
| 1504 | - $tables[ $table ] = $table; |
|
| 1505 | - } |
|
| 1506 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - |
|
| 1510 | - |
|
| 1511 | - /** |
|
| 1512 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1513 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1514 | - * Returns the list actually deleted |
|
| 1515 | - * |
|
| 1516 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1517 | - * @global WPDB $wpdb |
|
| 1518 | - * @param array $table_names |
|
| 1519 | - * @return array of table names which we deleted |
|
| 1520 | - */ |
|
| 1521 | - public static function drop_tables($table_names) |
|
| 1522 | - { |
|
| 1523 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - |
|
| 1527 | - |
|
| 1528 | - /** |
|
| 1529 | - * plugin_uninstall |
|
| 1530 | - * |
|
| 1531 | - * @access public |
|
| 1532 | - * @static |
|
| 1533 | - * @param bool $remove_all |
|
| 1534 | - * @return void |
|
| 1535 | - */ |
|
| 1536 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1537 | - { |
|
| 1538 | - global $wpdb; |
|
| 1539 | - self::drop_espresso_tables(); |
|
| 1540 | - $wp_options_to_delete = array( |
|
| 1541 | - 'ee_no_ticket_prices' => true, |
|
| 1542 | - 'ee_active_messengers' => true, |
|
| 1543 | - 'ee_has_activated_messenger' => true, |
|
| 1544 | - RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
| 1545 | - 'ee_config' => false, |
|
| 1546 | - 'ee_data_migration_current_db_state' => true, |
|
| 1547 | - 'ee_data_migration_mapping_' => false, |
|
| 1548 | - 'ee_data_migration_script_' => false, |
|
| 1549 | - 'ee_data_migrations' => true, |
|
| 1550 | - 'ee_dms_map' => false, |
|
| 1551 | - 'ee_notices' => true, |
|
| 1552 | - 'lang_file_check_' => false, |
|
| 1553 | - 'ee_maintenance_mode' => true, |
|
| 1554 | - 'ee_ueip_optin' => true, |
|
| 1555 | - 'ee_ueip_has_notified' => true, |
|
| 1556 | - 'ee_plugin_activation_errors' => true, |
|
| 1557 | - 'ee_id_mapping_from' => false, |
|
| 1558 | - 'espresso_persistent_admin_notices' => true, |
|
| 1559 | - 'ee_encryption_key' => true, |
|
| 1560 | - 'pue_force_upgrade_' => false, |
|
| 1561 | - 'pue_json_error_' => false, |
|
| 1562 | - 'pue_install_key_' => false, |
|
| 1563 | - 'pue_verification_error_' => false, |
|
| 1564 | - 'pu_dismissed_upgrade_' => false, |
|
| 1565 | - 'external_updates-' => false, |
|
| 1566 | - 'ee_extra_data' => true, |
|
| 1567 | - 'ee_ssn_' => false, |
|
| 1568 | - 'ee_rss_' => false, |
|
| 1569 | - 'ee_rte_n_tx_' => false, |
|
| 1570 | - 'ee_pers_admin_notices' => true, |
|
| 1571 | - 'ee_job_parameters_' => false, |
|
| 1572 | - 'ee_upload_directories_incomplete' => true, |
|
| 1573 | - 'ee_verified_db_collations' => true, |
|
| 1574 | - ); |
|
| 1575 | - if (is_main_site()) { |
|
| 1576 | - $wp_options_to_delete['ee_network_config'] = true; |
|
| 1577 | - } |
|
| 1578 | - $undeleted_options = array(); |
|
| 1579 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1580 | - if ($no_wildcard) { |
|
| 1581 | - if (! delete_option($option_name)) { |
|
| 1582 | - $undeleted_options[] = $option_name; |
|
| 1583 | - } |
|
| 1584 | - } else { |
|
| 1585 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1586 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1587 | - if (! delete_option($option_name_from_wildcard)) { |
|
| 1588 | - $undeleted_options[] = $option_name_from_wildcard; |
|
| 1589 | - } |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - } |
|
| 1593 | - // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1594 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1595 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1596 | - $db_update_sans_ee4 = array(); |
|
| 1597 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1598 | - if ((string) $version[0] === '3') {// if its NON EE4 |
|
| 1599 | - $db_update_sans_ee4[ $version ] = $times_activated; |
|
| 1600 | - } |
|
| 1601 | - } |
|
| 1602 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1603 | - } |
|
| 1604 | - $errors = ''; |
|
| 1605 | - if (! empty($undeleted_options)) { |
|
| 1606 | - $errors .= sprintf( |
|
| 1607 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1608 | - '<br/>', |
|
| 1609 | - implode(',<br/>', $undeleted_options) |
|
| 1610 | - ); |
|
| 1611 | - } |
|
| 1612 | - if (! empty($errors)) { |
|
| 1613 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1614 | - } |
|
| 1615 | - } |
|
| 1616 | - |
|
| 1617 | - /** |
|
| 1618 | - * Gets the mysql error code from the last used query by wpdb |
|
| 1619 | - * |
|
| 1620 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1621 | - */ |
|
| 1622 | - public static function last_wpdb_error_code() |
|
| 1623 | - { |
|
| 1624 | - // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved |
|
| 1625 | - global $wpdb; |
|
| 1626 | - if ($wpdb->use_mysqli) { |
|
| 1627 | - return mysqli_errno($wpdb->dbh); |
|
| 1628 | - } else { |
|
| 1629 | - return mysql_errno($wpdb->dbh); |
|
| 1630 | - } |
|
| 1631 | - // phpcs:enable |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - /** |
|
| 1635 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1636 | - * |
|
| 1637 | - * @global wpdb $wpdb |
|
| 1638 | - * @deprecated instead use TableAnalysis::tableExists() |
|
| 1639 | - * @param string $table_name with or without $wpdb->prefix |
|
| 1640 | - * @return boolean |
|
| 1641 | - */ |
|
| 1642 | - public static function table_exists($table_name) |
|
| 1643 | - { |
|
| 1644 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1645 | - } |
|
| 1646 | - |
|
| 1647 | - /** |
|
| 1648 | - * Resets the cache on EEH_Activation |
|
| 1649 | - */ |
|
| 1650 | - public static function reset() |
|
| 1651 | - { |
|
| 1652 | - self::$_default_creator_id = null; |
|
| 1653 | - self::$_initialized_db_content_already_in_this_request = false; |
|
| 1654 | - } |
|
| 1225 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1226 | + $message_resource_manager |
|
| 1227 | + ); |
|
| 1228 | + /** |
|
| 1229 | + * This method is verifying there are no NEW default message types |
|
| 1230 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1231 | + */ |
|
| 1232 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1233 | + $message_resource_manager |
|
| 1234 | + ); |
|
| 1235 | + // after all is done, let's persist these changes to the db. |
|
| 1236 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1237 | + $message_resource_manager->update_active_messengers_option(); |
|
| 1238 | + // will return true if either of these are true. Otherwise will return false. |
|
| 1239 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + |
|
| 1244 | + /** |
|
| 1245 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1246 | + * @return array|bool |
|
| 1247 | + * @throws \EE_Error |
|
| 1248 | + */ |
|
| 1249 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1250 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1251 | + ) { |
|
| 1252 | + /** @type EE_messenger[] $active_messengers */ |
|
| 1253 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1254 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1255 | + $templates_created = false; |
|
| 1256 | + foreach ($active_messengers as $active_messenger) { |
|
| 1257 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1258 | + $default_message_type_names_to_activate = array(); |
|
| 1259 | + // looping through each default message type reported by the messenger |
|
| 1260 | + // and setup the actual message types to activate. |
|
| 1261 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1262 | + // if already active or has already been activated before we skip |
|
| 1263 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1264 | + // we also skip if the message type is not installed. |
|
| 1265 | + if ($message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1266 | + $default_message_type_name_for_messenger, |
|
| 1267 | + $active_messenger->name |
|
| 1268 | + ) |
|
| 1269 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1270 | + $active_messenger->name, |
|
| 1271 | + $default_message_type_name_for_messenger |
|
| 1272 | + ) |
|
| 1273 | + || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
| 1274 | + ) { |
|
| 1275 | + continue; |
|
| 1276 | + } |
|
| 1277 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1278 | + } |
|
| 1279 | + // let's activate! |
|
| 1280 | + $message_resource_manager->ensure_message_types_are_active( |
|
| 1281 | + $default_message_type_names_to_activate, |
|
| 1282 | + $active_messenger->name, |
|
| 1283 | + false |
|
| 1284 | + ); |
|
| 1285 | + // activate the templates for these message types |
|
| 1286 | + if (! empty($default_message_type_names_to_activate)) { |
|
| 1287 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1288 | + $active_messenger->name, |
|
| 1289 | + $default_message_type_names_for_messenger, |
|
| 1290 | + '', |
|
| 1291 | + true |
|
| 1292 | + ); |
|
| 1293 | + } |
|
| 1294 | + } |
|
| 1295 | + return $templates_created; |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + |
|
| 1299 | + |
|
| 1300 | + /** |
|
| 1301 | + * This will activate and generate default messengers and default message types for those messengers. |
|
| 1302 | + * |
|
| 1303 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1304 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1305 | + * False means that there were no templates generated |
|
| 1306 | + * (which could simply mean there are no default message types for a messenger). |
|
| 1307 | + * @throws EE_Error |
|
| 1308 | + */ |
|
| 1309 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1310 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1311 | + ) { |
|
| 1312 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1313 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1314 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1315 | + $templates_generated = false; |
|
| 1316 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1317 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1318 | + // verify the default message types match an installed message type. |
|
| 1319 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1320 | + if (! isset($installed_message_types[ $name ]) |
|
| 1321 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1322 | + $name, |
|
| 1323 | + $messenger_to_generate->name |
|
| 1324 | + ) |
|
| 1325 | + ) { |
|
| 1326 | + unset($default_message_type_names_for_messenger[ $key ]); |
|
| 1327 | + } |
|
| 1328 | + } |
|
| 1329 | + // in previous iterations, the active_messengers option in the db |
|
| 1330 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1331 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1332 | + // passing off to create templates (after the refactor is done). |
|
| 1333 | + // @todo remove this comment when determined not necessary. |
|
| 1334 | + $message_resource_manager->activate_messenger( |
|
| 1335 | + $messenger_to_generate->name, |
|
| 1336 | + $default_message_type_names_for_messenger, |
|
| 1337 | + false |
|
| 1338 | + ); |
|
| 1339 | + // create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1340 | + if (! empty($default_message_type_names_for_messenger)) { |
|
| 1341 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1342 | + $messenger_to_generate->name, |
|
| 1343 | + $default_message_type_names_for_messenger, |
|
| 1344 | + '', |
|
| 1345 | + true |
|
| 1346 | + ); |
|
| 1347 | + } |
|
| 1348 | + } |
|
| 1349 | + return $templates_generated; |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + |
|
| 1353 | + /** |
|
| 1354 | + * This returns the default messengers to generate templates for on activation of EE. |
|
| 1355 | + * It considers: |
|
| 1356 | + * - whether a messenger is already active in the db. |
|
| 1357 | + * - whether a messenger has been made active at any time in the past. |
|
| 1358 | + * |
|
| 1359 | + * @static |
|
| 1360 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1361 | + * @return EE_messenger[] |
|
| 1362 | + */ |
|
| 1363 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1364 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1365 | + ) { |
|
| 1366 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1367 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1368 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1369 | + |
|
| 1370 | + $messengers_to_generate = array(); |
|
| 1371 | + foreach ($installed_messengers as $installed_messenger) { |
|
| 1372 | + // if installed messenger is a messenger that should be activated on install |
|
| 1373 | + // and is not already active |
|
| 1374 | + // and has never been activated |
|
| 1375 | + if (! $installed_messenger->activate_on_install |
|
| 1376 | + || isset($active_messengers[ $installed_messenger->name ]) |
|
| 1377 | + || isset($has_activated[ $installed_messenger->name ]) |
|
| 1378 | + ) { |
|
| 1379 | + continue; |
|
| 1380 | + } |
|
| 1381 | + $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
| 1382 | + } |
|
| 1383 | + return $messengers_to_generate; |
|
| 1384 | + } |
|
| 1385 | + |
|
| 1386 | + |
|
| 1387 | + /** |
|
| 1388 | + * This simply validates active message types to ensure they actually match installed |
|
| 1389 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1390 | + * rows are set inactive. |
|
| 1391 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1392 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1393 | + * are still handled in here. |
|
| 1394 | + * |
|
| 1395 | + * @since 4.3.1 |
|
| 1396 | + * @return void |
|
| 1397 | + */ |
|
| 1398 | + public static function validate_messages_system() |
|
| 1399 | + { |
|
| 1400 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1401 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1402 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1403 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + |
|
| 1407 | + /** |
|
| 1408 | + * create_no_ticket_prices_array |
|
| 1409 | + * |
|
| 1410 | + * @access public |
|
| 1411 | + * @static |
|
| 1412 | + * @return void |
|
| 1413 | + */ |
|
| 1414 | + public static function create_no_ticket_prices_array() |
|
| 1415 | + { |
|
| 1416 | + // this creates an array for tracking events that have no active ticket prices created |
|
| 1417 | + // this allows us to warn admins of the situation so that it can be corrected |
|
| 1418 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1419 | + if (! $espresso_no_ticket_prices) { |
|
| 1420 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + |
|
| 1425 | + /** |
|
| 1426 | + * plugin_deactivation |
|
| 1427 | + * |
|
| 1428 | + * @access public |
|
| 1429 | + * @static |
|
| 1430 | + * @return void |
|
| 1431 | + */ |
|
| 1432 | + public static function plugin_deactivation() |
|
| 1433 | + { |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + |
|
| 1437 | + /** |
|
| 1438 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1439 | + * (like post meta or term relations) |
|
| 1440 | + * |
|
| 1441 | + * @global wpdb $wpdb |
|
| 1442 | + * @throws \EE_Error |
|
| 1443 | + */ |
|
| 1444 | + public static function delete_all_espresso_cpt_data() |
|
| 1445 | + { |
|
| 1446 | + global $wpdb; |
|
| 1447 | + // get all the CPT post_types |
|
| 1448 | + $ee_post_types = array(); |
|
| 1449 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1450 | + if (method_exists($model_name, 'instance')) { |
|
| 1451 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1452 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1453 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1454 | + } |
|
| 1455 | + } |
|
| 1456 | + } |
|
| 1457 | + // get all our CPTs |
|
| 1458 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1459 | + $cpt_ids = $wpdb->get_col($query); |
|
| 1460 | + // delete each post meta and term relations too |
|
| 1461 | + foreach ($cpt_ids as $post_id) { |
|
| 1462 | + wp_delete_post($post_id, true); |
|
| 1463 | + } |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * Deletes all EE custom tables |
|
| 1468 | + * |
|
| 1469 | + * @return array |
|
| 1470 | + */ |
|
| 1471 | + public static function drop_espresso_tables() |
|
| 1472 | + { |
|
| 1473 | + $tables = array(); |
|
| 1474 | + // load registry |
|
| 1475 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1476 | + if (method_exists($model_name, 'instance')) { |
|
| 1477 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1478 | + if ($model_obj instanceof EEM_Base) { |
|
| 1479 | + foreach ($model_obj->get_tables() as $table) { |
|
| 1480 | + if (strpos($table->get_table_name(), 'esp_') |
|
| 1481 | + && |
|
| 1482 | + ( |
|
| 1483 | + is_main_site()// main site? nuke them all |
|
| 1484 | + || ! $table->is_global()// not main site,but not global either. nuke it |
|
| 1485 | + ) |
|
| 1486 | + ) { |
|
| 1487 | + $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
| 1488 | + } |
|
| 1489 | + } |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + // there are some tables whose models were removed. |
|
| 1495 | + // they should be removed when removing all EE core's data |
|
| 1496 | + $tables_without_models = array( |
|
| 1497 | + 'esp_promotion', |
|
| 1498 | + 'esp_promotion_applied', |
|
| 1499 | + 'esp_promotion_object', |
|
| 1500 | + 'esp_promotion_rule', |
|
| 1501 | + 'esp_rule', |
|
| 1502 | + ); |
|
| 1503 | + foreach ($tables_without_models as $table) { |
|
| 1504 | + $tables[ $table ] = $table; |
|
| 1505 | + } |
|
| 1506 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + |
|
| 1510 | + |
|
| 1511 | + /** |
|
| 1512 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1513 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1514 | + * Returns the list actually deleted |
|
| 1515 | + * |
|
| 1516 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1517 | + * @global WPDB $wpdb |
|
| 1518 | + * @param array $table_names |
|
| 1519 | + * @return array of table names which we deleted |
|
| 1520 | + */ |
|
| 1521 | + public static function drop_tables($table_names) |
|
| 1522 | + { |
|
| 1523 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + |
|
| 1527 | + |
|
| 1528 | + /** |
|
| 1529 | + * plugin_uninstall |
|
| 1530 | + * |
|
| 1531 | + * @access public |
|
| 1532 | + * @static |
|
| 1533 | + * @param bool $remove_all |
|
| 1534 | + * @return void |
|
| 1535 | + */ |
|
| 1536 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1537 | + { |
|
| 1538 | + global $wpdb; |
|
| 1539 | + self::drop_espresso_tables(); |
|
| 1540 | + $wp_options_to_delete = array( |
|
| 1541 | + 'ee_no_ticket_prices' => true, |
|
| 1542 | + 'ee_active_messengers' => true, |
|
| 1543 | + 'ee_has_activated_messenger' => true, |
|
| 1544 | + RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
| 1545 | + 'ee_config' => false, |
|
| 1546 | + 'ee_data_migration_current_db_state' => true, |
|
| 1547 | + 'ee_data_migration_mapping_' => false, |
|
| 1548 | + 'ee_data_migration_script_' => false, |
|
| 1549 | + 'ee_data_migrations' => true, |
|
| 1550 | + 'ee_dms_map' => false, |
|
| 1551 | + 'ee_notices' => true, |
|
| 1552 | + 'lang_file_check_' => false, |
|
| 1553 | + 'ee_maintenance_mode' => true, |
|
| 1554 | + 'ee_ueip_optin' => true, |
|
| 1555 | + 'ee_ueip_has_notified' => true, |
|
| 1556 | + 'ee_plugin_activation_errors' => true, |
|
| 1557 | + 'ee_id_mapping_from' => false, |
|
| 1558 | + 'espresso_persistent_admin_notices' => true, |
|
| 1559 | + 'ee_encryption_key' => true, |
|
| 1560 | + 'pue_force_upgrade_' => false, |
|
| 1561 | + 'pue_json_error_' => false, |
|
| 1562 | + 'pue_install_key_' => false, |
|
| 1563 | + 'pue_verification_error_' => false, |
|
| 1564 | + 'pu_dismissed_upgrade_' => false, |
|
| 1565 | + 'external_updates-' => false, |
|
| 1566 | + 'ee_extra_data' => true, |
|
| 1567 | + 'ee_ssn_' => false, |
|
| 1568 | + 'ee_rss_' => false, |
|
| 1569 | + 'ee_rte_n_tx_' => false, |
|
| 1570 | + 'ee_pers_admin_notices' => true, |
|
| 1571 | + 'ee_job_parameters_' => false, |
|
| 1572 | + 'ee_upload_directories_incomplete' => true, |
|
| 1573 | + 'ee_verified_db_collations' => true, |
|
| 1574 | + ); |
|
| 1575 | + if (is_main_site()) { |
|
| 1576 | + $wp_options_to_delete['ee_network_config'] = true; |
|
| 1577 | + } |
|
| 1578 | + $undeleted_options = array(); |
|
| 1579 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1580 | + if ($no_wildcard) { |
|
| 1581 | + if (! delete_option($option_name)) { |
|
| 1582 | + $undeleted_options[] = $option_name; |
|
| 1583 | + } |
|
| 1584 | + } else { |
|
| 1585 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1586 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1587 | + if (! delete_option($option_name_from_wildcard)) { |
|
| 1588 | + $undeleted_options[] = $option_name_from_wildcard; |
|
| 1589 | + } |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + } |
|
| 1593 | + // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1594 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1595 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1596 | + $db_update_sans_ee4 = array(); |
|
| 1597 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1598 | + if ((string) $version[0] === '3') {// if its NON EE4 |
|
| 1599 | + $db_update_sans_ee4[ $version ] = $times_activated; |
|
| 1600 | + } |
|
| 1601 | + } |
|
| 1602 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1603 | + } |
|
| 1604 | + $errors = ''; |
|
| 1605 | + if (! empty($undeleted_options)) { |
|
| 1606 | + $errors .= sprintf( |
|
| 1607 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1608 | + '<br/>', |
|
| 1609 | + implode(',<br/>', $undeleted_options) |
|
| 1610 | + ); |
|
| 1611 | + } |
|
| 1612 | + if (! empty($errors)) { |
|
| 1613 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1614 | + } |
|
| 1615 | + } |
|
| 1616 | + |
|
| 1617 | + /** |
|
| 1618 | + * Gets the mysql error code from the last used query by wpdb |
|
| 1619 | + * |
|
| 1620 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1621 | + */ |
|
| 1622 | + public static function last_wpdb_error_code() |
|
| 1623 | + { |
|
| 1624 | + // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved |
|
| 1625 | + global $wpdb; |
|
| 1626 | + if ($wpdb->use_mysqli) { |
|
| 1627 | + return mysqli_errno($wpdb->dbh); |
|
| 1628 | + } else { |
|
| 1629 | + return mysql_errno($wpdb->dbh); |
|
| 1630 | + } |
|
| 1631 | + // phpcs:enable |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + /** |
|
| 1635 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1636 | + * |
|
| 1637 | + * @global wpdb $wpdb |
|
| 1638 | + * @deprecated instead use TableAnalysis::tableExists() |
|
| 1639 | + * @param string $table_name with or without $wpdb->prefix |
|
| 1640 | + * @return boolean |
|
| 1641 | + */ |
|
| 1642 | + public static function table_exists($table_name) |
|
| 1643 | + { |
|
| 1644 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1645 | + } |
|
| 1646 | + |
|
| 1647 | + /** |
|
| 1648 | + * Resets the cache on EEH_Activation |
|
| 1649 | + */ |
|
| 1650 | + public static function reset() |
|
| 1651 | + { |
|
| 1652 | + self::$_default_creator_id = null; |
|
| 1653 | + self::$_initialized_db_content_already_in_this_request = false; |
|
| 1654 | + } |
|
| 1655 | 1655 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public static function getTableAnalysis() |
| 56 | 56 | { |
| 57 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 57 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 58 | 58 | self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
| 59 | 59 | } |
| 60 | 60 | return self::$table_analysis; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public static function getTableManager() |
| 68 | 68 | { |
| 69 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 69 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 70 | 70 | self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
| 71 | 71 | } |
| 72 | 72 | return self::$table_manager; |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | if ($which_to_include === 'old') { |
| 181 | 181 | $cron_tasks = array_filter( |
| 182 | 182 | $cron_tasks, |
| 183 | - function ($value) { |
|
| 183 | + function($value) { |
|
| 184 | 184 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
| 185 | 185 | } |
| 186 | 186 | ); |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | { |
| 211 | 211 | |
| 212 | 212 | foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
| 213 | - if (! wp_next_scheduled($hook_name)) { |
|
| 213 | + if ( ! wp_next_scheduled($hook_name)) { |
|
| 214 | 214 | /** |
| 215 | 215 | * This allows client code to define the initial start timestamp for this schedule. |
| 216 | 216 | */ |
@@ -261,15 +261,15 @@ discard block |
||
| 261 | 261 | foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
| 262 | 262 | if (is_array($hooks_to_fire_at_time)) { |
| 263 | 263 | foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
| 264 | - if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 265 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 264 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 265 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 266 | 266 | ) { |
| 267 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
| 267 | + unset($crons[$timestamp][$hook_name]); |
|
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | // also take care of any empty cron timestamps. |
| 271 | 271 | if (empty($hooks_to_fire_at_time)) { |
| 272 | - unset($crons[ $timestamp ]); |
|
| 272 | + unset($crons[$timestamp]); |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | 3 |
| 315 | 315 | ); |
| 316 | 316 | // EE_Config::reset(); |
| 317 | - if (! EE_Config::logging_enabled()) { |
|
| 317 | + if ( ! EE_Config::logging_enabled()) { |
|
| 318 | 318 | delete_option(EE_Config::LOG_NAME); |
| 319 | 319 | } |
| 320 | 320 | } |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | public static function load_calendar_config() |
| 330 | 330 | { |
| 331 | 331 | // grab array of all plugin folders and loop thru it |
| 332 | - $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
| 332 | + $plugins = glob(WP_PLUGIN_DIR.'/*', GLOB_ONLYDIR); |
|
| 333 | 333 | if (empty($plugins)) { |
| 334 | 334 | return; |
| 335 | 335 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | || strpos($plugin, 'calendar') !== false |
| 346 | 346 | ) { |
| 347 | 347 | // this is what we are looking for |
| 348 | - $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
| 348 | + $calendar_config = $plugin_path.'/EE_Calendar_Config.php'; |
|
| 349 | 349 | // does it exist in this folder ? |
| 350 | 350 | if (is_readable($calendar_config)) { |
| 351 | 351 | // YEAH! let's load it |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | ) { |
| 473 | 473 | // update Config with post ID |
| 474 | 474 | $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
| 475 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 475 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 476 | 476 | $msg = __( |
| 477 | 477 | 'The Event Espresso critical page configuration settings could not be updated.', |
| 478 | 478 | 'event_espresso' |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
| 496 | 496 | 'event_espresso' |
| 497 | 497 | ), |
| 498 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
| 498 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">' |
|
| 499 | 499 | . __('Event Espresso Critical Pages Settings', 'event_espresso') |
| 500 | 500 | . '</a>' |
| 501 | 501 | ) |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | public static function get_page_by_ee_shortcode($ee_shortcode) |
| 522 | 522 | { |
| 523 | 523 | global $wpdb; |
| 524 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 524 | + $shortcode_and_opening_bracket = '['.$ee_shortcode; |
|
| 525 | 525 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
| 526 | 526 | if ($post_id) { |
| 527 | 527 | return get_post($post_id); |
@@ -547,11 +547,11 @@ discard block |
||
| 547 | 547 | 'post_status' => 'publish', |
| 548 | 548 | 'post_type' => 'page', |
| 549 | 549 | 'comment_status' => 'closed', |
| 550 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 550 | + 'post_content' => '['.$critical_page['code'].']', |
|
| 551 | 551 | ); |
| 552 | 552 | |
| 553 | 553 | $post_id = wp_insert_post($post_args); |
| 554 | - if (! $post_id) { |
|
| 554 | + if ( ! $post_id) { |
|
| 555 | 555 | $msg = sprintf( |
| 556 | 556 | __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
| 557 | 557 | $critical_page['name'] |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | return $critical_page; |
| 561 | 561 | } |
| 562 | 562 | // get newly created post's details |
| 563 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
| 563 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
| 564 | 564 | $msg = sprintf( |
| 565 | 565 | __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
| 566 | 566 | $critical_page['name'] |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | public static function get_default_creator_id() |
| 586 | 586 | { |
| 587 | 587 | global $wpdb; |
| 588 | - if (! empty(self::$_default_creator_id)) { |
|
| 588 | + if ( ! empty(self::$_default_creator_id)) { |
|
| 589 | 589 | return self::$_default_creator_id; |
| 590 | 590 | }/**/ |
| 591 | 591 | $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
| 602 | 602 | $query = $wpdb->prepare( |
| 603 | 603 | "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
| 604 | - '%' . $role_to_check . '%' |
|
| 604 | + '%'.$role_to_check.'%' |
|
| 605 | 605 | ); |
| 606 | 606 | $user_id = $wpdb->get_var($query); |
| 607 | 607 | $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
@@ -640,8 +640,8 @@ discard block |
||
| 640 | 640 | return; |
| 641 | 641 | } |
| 642 | 642 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 643 | - if (! function_exists('dbDelta')) { |
|
| 644 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 643 | + if ( ! function_exists('dbDelta')) { |
|
| 644 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 645 | 645 | } |
| 646 | 646 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
| 647 | 647 | $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
@@ -650,9 +650,9 @@ discard block |
||
| 650 | 650 | // ok, delete the table... but ONLY if it's empty |
| 651 | 651 | $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
| 652 | 652 | // table is NOT empty, are you SURE you want to delete this table ??? |
| 653 | - if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 653 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 654 | 654 | \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
| 655 | - } elseif (! $deleted_safely) { |
|
| 655 | + } elseif ( ! $deleted_safely) { |
|
| 656 | 656 | // so we should be more cautious rather than just dropping tables so easily |
| 657 | 657 | error_log( |
| 658 | 658 | sprintf( |
@@ -852,13 +852,13 @@ discard block |
||
| 852 | 852 | // reset values array |
| 853 | 853 | $QSG_values = array(); |
| 854 | 854 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
| 855 | - if (! in_array("$QSG_system", $question_groups)) { |
|
| 855 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
| 856 | 856 | // add it |
| 857 | 857 | switch ($QSG_system) { |
| 858 | 858 | case 1: |
| 859 | 859 | $QSG_values = array( |
| 860 | 860 | 'QSG_name' => __('Personal Information', 'event_espresso'), |
| 861 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 861 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
| 862 | 862 | 'QSG_desc' => '', |
| 863 | 863 | 'QSG_order' => 1, |
| 864 | 864 | 'QSG_show_group_name' => 1, |
@@ -870,7 +870,7 @@ discard block |
||
| 870 | 870 | case 2: |
| 871 | 871 | $QSG_values = array( |
| 872 | 872 | 'QSG_name' => __('Address Information', 'event_espresso'), |
| 873 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 873 | + 'QSG_identifier' => 'address-information-'.time(), |
|
| 874 | 874 | 'QSG_desc' => '', |
| 875 | 875 | 'QSG_order' => 2, |
| 876 | 876 | 'QSG_show_group_name' => 1, |
@@ -881,14 +881,14 @@ discard block |
||
| 881 | 881 | break; |
| 882 | 882 | } |
| 883 | 883 | // make sure we have some values before inserting them |
| 884 | - if (! empty($QSG_values)) { |
|
| 884 | + if ( ! empty($QSG_values)) { |
|
| 885 | 885 | // insert system question |
| 886 | 886 | $wpdb->insert( |
| 887 | 887 | $table_name, |
| 888 | 888 | $QSG_values, |
| 889 | 889 | array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
| 890 | 890 | ); |
| 891 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
| 891 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 892 | 892 | } |
| 893 | 893 | } |
| 894 | 894 | } |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | // reset values array |
| 919 | 919 | $QST_values = array(); |
| 920 | 920 | // if we don't have what we should have |
| 921 | - if (! in_array($QST_system, $questions)) { |
|
| 921 | + if ( ! in_array($QST_system, $questions)) { |
|
| 922 | 922 | // add it |
| 923 | 923 | switch ($QST_system) { |
| 924 | 924 | case 'fname': |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | ); |
| 1071 | 1071 | break; |
| 1072 | 1072 | } |
| 1073 | - if (! empty($QST_values)) { |
|
| 1073 | + if ( ! empty($QST_values)) { |
|
| 1074 | 1074 | // insert system question |
| 1075 | 1075 | $wpdb->insert( |
| 1076 | 1076 | $table_name, |
@@ -1084,8 +1084,8 @@ discard block |
||
| 1084 | 1084 | } else { |
| 1085 | 1085 | $system_question_we_want = EEM_Question_Group::system_address; |
| 1086 | 1086 | } |
| 1087 | - if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
| 1088 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
| 1087 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1088 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1089 | 1089 | } else { |
| 1090 | 1090 | $id_col = EEM_Question_Group::instance() |
| 1091 | 1091 | ->get_col(array(array('QSG_system' => $system_question_we_want))); |
@@ -1133,7 +1133,7 @@ discard block |
||
| 1133 | 1133 | */ |
| 1134 | 1134 | public static function insert_default_payment_methods() |
| 1135 | 1135 | { |
| 1136 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1136 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1137 | 1137 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
| 1138 | 1138 | EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
| 1139 | 1139 | } else { |
@@ -1270,7 +1270,7 @@ discard block |
||
| 1270 | 1270 | $active_messenger->name, |
| 1271 | 1271 | $default_message_type_name_for_messenger |
| 1272 | 1272 | ) |
| 1273 | - || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
| 1273 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1274 | 1274 | ) { |
| 1275 | 1275 | continue; |
| 1276 | 1276 | } |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | false |
| 1284 | 1284 | ); |
| 1285 | 1285 | // activate the templates for these message types |
| 1286 | - if (! empty($default_message_type_names_to_activate)) { |
|
| 1286 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1287 | 1287 | $templates_created = EEH_MSG_Template::generate_new_templates( |
| 1288 | 1288 | $active_messenger->name, |
| 1289 | 1289 | $default_message_type_names_for_messenger, |
@@ -1317,13 +1317,13 @@ discard block |
||
| 1317 | 1317 | $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
| 1318 | 1318 | // verify the default message types match an installed message type. |
| 1319 | 1319 | foreach ($default_message_type_names_for_messenger as $key => $name) { |
| 1320 | - if (! isset($installed_message_types[ $name ]) |
|
| 1320 | + if ( ! isset($installed_message_types[$name]) |
|
| 1321 | 1321 | || $message_resource_manager->has_message_type_been_activated_for_messenger( |
| 1322 | 1322 | $name, |
| 1323 | 1323 | $messenger_to_generate->name |
| 1324 | 1324 | ) |
| 1325 | 1325 | ) { |
| 1326 | - unset($default_message_type_names_for_messenger[ $key ]); |
|
| 1326 | + unset($default_message_type_names_for_messenger[$key]); |
|
| 1327 | 1327 | } |
| 1328 | 1328 | } |
| 1329 | 1329 | // in previous iterations, the active_messengers option in the db |
@@ -1337,7 +1337,7 @@ discard block |
||
| 1337 | 1337 | false |
| 1338 | 1338 | ); |
| 1339 | 1339 | // create any templates needing created (or will reactivate templates already generated as necessary). |
| 1340 | - if (! empty($default_message_type_names_for_messenger)) { |
|
| 1340 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1341 | 1341 | $templates_generated = EEH_MSG_Template::generate_new_templates( |
| 1342 | 1342 | $messenger_to_generate->name, |
| 1343 | 1343 | $default_message_type_names_for_messenger, |
@@ -1372,13 +1372,13 @@ discard block |
||
| 1372 | 1372 | // if installed messenger is a messenger that should be activated on install |
| 1373 | 1373 | // and is not already active |
| 1374 | 1374 | // and has never been activated |
| 1375 | - if (! $installed_messenger->activate_on_install |
|
| 1376 | - || isset($active_messengers[ $installed_messenger->name ]) |
|
| 1377 | - || isset($has_activated[ $installed_messenger->name ]) |
|
| 1375 | + if ( ! $installed_messenger->activate_on_install |
|
| 1376 | + || isset($active_messengers[$installed_messenger->name]) |
|
| 1377 | + || isset($has_activated[$installed_messenger->name]) |
|
| 1378 | 1378 | ) { |
| 1379 | 1379 | continue; |
| 1380 | 1380 | } |
| 1381 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
| 1381 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1382 | 1382 | } |
| 1383 | 1383 | return $messengers_to_generate; |
| 1384 | 1384 | } |
@@ -1416,7 +1416,7 @@ discard block |
||
| 1416 | 1416 | // this creates an array for tracking events that have no active ticket prices created |
| 1417 | 1417 | // this allows us to warn admins of the situation so that it can be corrected |
| 1418 | 1418 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
| 1419 | - if (! $espresso_no_ticket_prices) { |
|
| 1419 | + if ( ! $espresso_no_ticket_prices) { |
|
| 1420 | 1420 | add_option('ee_no_ticket_prices', array(), '', false); |
| 1421 | 1421 | } |
| 1422 | 1422 | } |
@@ -1455,7 +1455,7 @@ discard block |
||
| 1455 | 1455 | } |
| 1456 | 1456 | } |
| 1457 | 1457 | // get all our CPTs |
| 1458 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1458 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
| 1459 | 1459 | $cpt_ids = $wpdb->get_col($query); |
| 1460 | 1460 | // delete each post meta and term relations too |
| 1461 | 1461 | foreach ($cpt_ids as $post_id) { |
@@ -1484,7 +1484,7 @@ discard block |
||
| 1484 | 1484 | || ! $table->is_global()// not main site,but not global either. nuke it |
| 1485 | 1485 | ) |
| 1486 | 1486 | ) { |
| 1487 | - $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
| 1487 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
| 1488 | 1488 | } |
| 1489 | 1489 | } |
| 1490 | 1490 | } |
@@ -1501,7 +1501,7 @@ discard block |
||
| 1501 | 1501 | 'esp_rule', |
| 1502 | 1502 | ); |
| 1503 | 1503 | foreach ($tables_without_models as $table) { |
| 1504 | - $tables[ $table ] = $table; |
|
| 1504 | + $tables[$table] = $table; |
|
| 1505 | 1505 | } |
| 1506 | 1506 | return \EEH_Activation::getTableManager()->dropTables($tables); |
| 1507 | 1507 | } |
@@ -1578,13 +1578,13 @@ discard block |
||
| 1578 | 1578 | $undeleted_options = array(); |
| 1579 | 1579 | foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
| 1580 | 1580 | if ($no_wildcard) { |
| 1581 | - if (! delete_option($option_name)) { |
|
| 1581 | + if ( ! delete_option($option_name)) { |
|
| 1582 | 1582 | $undeleted_options[] = $option_name; |
| 1583 | 1583 | } |
| 1584 | 1584 | } else { |
| 1585 | 1585 | $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
| 1586 | 1586 | foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
| 1587 | - if (! delete_option($option_name_from_wildcard)) { |
|
| 1587 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1588 | 1588 | $undeleted_options[] = $option_name_from_wildcard; |
| 1589 | 1589 | } |
| 1590 | 1590 | } |
@@ -1596,20 +1596,20 @@ discard block |
||
| 1596 | 1596 | $db_update_sans_ee4 = array(); |
| 1597 | 1597 | foreach ($espresso_db_update as $version => $times_activated) { |
| 1598 | 1598 | if ((string) $version[0] === '3') {// if its NON EE4 |
| 1599 | - $db_update_sans_ee4[ $version ] = $times_activated; |
|
| 1599 | + $db_update_sans_ee4[$version] = $times_activated; |
|
| 1600 | 1600 | } |
| 1601 | 1601 | } |
| 1602 | 1602 | update_option('espresso_db_update', $db_update_sans_ee4); |
| 1603 | 1603 | } |
| 1604 | 1604 | $errors = ''; |
| 1605 | - if (! empty($undeleted_options)) { |
|
| 1605 | + if ( ! empty($undeleted_options)) { |
|
| 1606 | 1606 | $errors .= sprintf( |
| 1607 | 1607 | __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
| 1608 | 1608 | '<br/>', |
| 1609 | 1609 | implode(',<br/>', $undeleted_options) |
| 1610 | 1610 | ); |
| 1611 | 1611 | } |
| 1612 | - if (! empty($errors)) { |
|
| 1612 | + if ( ! empty($errors)) { |
|
| 1613 | 1613 | EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
| 1614 | 1614 | } |
| 1615 | 1615 | } |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
| 13 | 13 | $class_to_filepath = array(); |
| 14 | 14 | if (! empty($stages)) { |
| 15 | - foreach ($stages as $filepath) { |
|
| 16 | - $matches = array(); |
|
| 17 | - preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 18 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 19 | - } |
|
| 15 | + foreach ($stages as $filepath) { |
|
| 16 | + $matches = array(); |
|
| 17 | + preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 18 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 19 | + } |
|
| 20 | 20 | } |
| 21 | 21 | // give addons a chance to autoload their stages too |
| 22 | 22 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_1_0__autoloaded_stages', $class_to_filepath); |
@@ -44,91 +44,91 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * EE_DMS_Core_4_1_0 constructor. |
|
| 49 | - * |
|
| 50 | - * @param TableManager $table_manager |
|
| 51 | - * @param TableAnalysis $table_analysis |
|
| 52 | - */ |
|
| 53 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 54 | - { |
|
| 55 | - $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
| 56 | - $this->_priority = 10; |
|
| 57 | - $this->_migration_stages = array( |
|
| 58 | - new EE_DMS_4_1_0_org_options(), |
|
| 59 | - new EE_DMS_4_1_0_shortcodes(), |
|
| 60 | - new EE_DMS_4_1_0_gateways(), |
|
| 61 | - new EE_DMS_4_1_0_events(), |
|
| 62 | - new EE_DMS_4_1_0_prices(), |
|
| 63 | - new EE_DMS_4_1_0_category_details(), |
|
| 64 | - new EE_DMS_4_1_0_event_category(), |
|
| 65 | - new EE_DMS_4_1_0_venues(), |
|
| 66 | - new EE_DMS_4_1_0_event_venue(), |
|
| 67 | - new EE_DMS_4_1_0_question_groups(), |
|
| 68 | - new EE_DMS_4_1_0_questions(), |
|
| 69 | - new EE_DMS_4_1_0_question_group_question(), |
|
| 70 | - new EE_DMS_4_1_0_event_question_group(), |
|
| 71 | - new EE_DMS_4_1_0_attendees(), |
|
| 72 | - new EE_DMS_4_1_0_line_items(), |
|
| 73 | - new EE_DMS_4_1_0_answers(), |
|
| 74 | - new EE_DMS_4_1_0_checkins(), |
|
| 75 | - ); |
|
| 76 | - parent::__construct($table_manager, $table_analysis); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
| 83 | - * |
|
| 84 | - * @global wpdb $wpdb |
|
| 85 | - * @return boolean |
|
| 86 | - */ |
|
| 87 | - private function _checkin_table_exists() |
|
| 88 | - { |
|
| 89 | - global $wpdb; |
|
| 90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 91 | - if ($results) { |
|
| 92 | - return true; |
|
| 93 | - } else { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - public function can_migrate_from_version($version_array) |
|
| 101 | - { |
|
| 102 | - $version_string = $version_array['Core']; |
|
| 103 | - if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
| 47 | + /** |
|
| 48 | + * EE_DMS_Core_4_1_0 constructor. |
|
| 49 | + * |
|
| 50 | + * @param TableManager $table_manager |
|
| 51 | + * @param TableAnalysis $table_analysis |
|
| 52 | + */ |
|
| 53 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 54 | + { |
|
| 55 | + $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
| 56 | + $this->_priority = 10; |
|
| 57 | + $this->_migration_stages = array( |
|
| 58 | + new EE_DMS_4_1_0_org_options(), |
|
| 59 | + new EE_DMS_4_1_0_shortcodes(), |
|
| 60 | + new EE_DMS_4_1_0_gateways(), |
|
| 61 | + new EE_DMS_4_1_0_events(), |
|
| 62 | + new EE_DMS_4_1_0_prices(), |
|
| 63 | + new EE_DMS_4_1_0_category_details(), |
|
| 64 | + new EE_DMS_4_1_0_event_category(), |
|
| 65 | + new EE_DMS_4_1_0_venues(), |
|
| 66 | + new EE_DMS_4_1_0_event_venue(), |
|
| 67 | + new EE_DMS_4_1_0_question_groups(), |
|
| 68 | + new EE_DMS_4_1_0_questions(), |
|
| 69 | + new EE_DMS_4_1_0_question_group_question(), |
|
| 70 | + new EE_DMS_4_1_0_event_question_group(), |
|
| 71 | + new EE_DMS_4_1_0_attendees(), |
|
| 72 | + new EE_DMS_4_1_0_line_items(), |
|
| 73 | + new EE_DMS_4_1_0_answers(), |
|
| 74 | + new EE_DMS_4_1_0_checkins(), |
|
| 75 | + ); |
|
| 76 | + parent::__construct($table_manager, $table_analysis); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
| 83 | + * |
|
| 84 | + * @global wpdb $wpdb |
|
| 85 | + * @return boolean |
|
| 86 | + */ |
|
| 87 | + private function _checkin_table_exists() |
|
| 88 | + { |
|
| 89 | + global $wpdb; |
|
| 90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 91 | + if ($results) { |
|
| 92 | + return true; |
|
| 93 | + } else { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + public function can_migrate_from_version($version_array) |
|
| 101 | + { |
|
| 102 | + $version_string = $version_array['Core']; |
|
| 103 | + if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
| 104 | 104 | // echo "$version_string can be migrated fro"; |
| 105 | - return true; |
|
| 106 | - } elseif (! $version_string) { |
|
| 105 | + return true; |
|
| 106 | + } elseif (! $version_string) { |
|
| 107 | 107 | // echo "no version string provided: $version_string"; |
| 108 | - // no version string provided... this must be pre 4.1 |
|
| 109 | - // because since 4.1 we're |
|
| 110 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | - } else { |
|
| 108 | + // no version string provided... this must be pre 4.1 |
|
| 109 | + // because since 4.1 we're |
|
| 110 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | + } else { |
|
| 112 | 112 | // echo "$version_string doesnt apply"; |
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - } |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | |
| 119 | - public function schema_changes_before_migration() |
|
| 120 | - { |
|
| 121 | - // relies on 4.1's EEH_Activation::create_table |
|
| 122 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 123 | - $table_name = 'esp_answer'; |
|
| 124 | - $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 119 | + public function schema_changes_before_migration() |
|
| 120 | + { |
|
| 121 | + // relies on 4.1's EEH_Activation::create_table |
|
| 122 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 123 | + $table_name = 'esp_answer'; |
|
| 124 | + $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 125 | 125 | REG_ID int(10) unsigned NOT NULL, |
| 126 | 126 | QST_ID int(10) unsigned NOT NULL, |
| 127 | 127 | ANS_value text NOT NULL, |
| 128 | 128 | PRIMARY KEY (ANS_ID)"; |
| 129 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 130 | - $table_name = 'esp_attendee_meta'; |
|
| 131 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 129 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 130 | + $table_name = 'esp_attendee_meta'; |
|
| 131 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 132 | 132 | ATT_ID bigint(20) unsigned NOT NULL, |
| 133 | 133 | ATT_fname varchar(45) NOT NULL, |
| 134 | 134 | ATT_lname varchar(45) NOT NULL, |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | KEY ATT_fname (ATT_fname), |
| 145 | 145 | KEY ATT_lname (ATT_lname), |
| 146 | 146 | KEY ATT_email (ATT_email(191))"; |
| 147 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 148 | - $table_name = 'esp_country'; |
|
| 149 | - $sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL, |
|
| 147 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 148 | + $table_name = 'esp_country'; |
|
| 149 | + $sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL, |
|
| 150 | 150 | CNT_ISO3 varchar(3) COLLATE utf8_bin NOT NULL, |
| 151 | 151 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
| 152 | 152 | CNT_name varchar(45) COLLATE utf8_bin NOT NULL, |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | CNT_is_EU tinyint(1) DEFAULT '0', |
| 163 | 163 | CNT_active tinyint(1) DEFAULT '0', |
| 164 | 164 | PRIMARY KEY (CNT_ISO)"; |
| 165 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 166 | - $table_name = 'esp_datetime'; |
|
| 167 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 165 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 166 | + $table_name = 'esp_datetime'; |
|
| 167 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 168 | 168 | EVT_ID bigint(20) unsigned NOT NULL, |
| 169 | 169 | DTT_EVT_start datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 170 | 170 | DTT_EVT_end datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | PRIMARY KEY (DTT_ID), |
| 178 | 178 | KEY EVT_ID (EVT_ID), |
| 179 | 179 | KEY DTT_is_primary (DTT_is_primary)"; |
| 180 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 181 | - $table_name = 'esp_event_meta'; |
|
| 182 | - $sql = " |
|
| 180 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 181 | + $table_name = 'esp_event_meta'; |
|
| 182 | + $sql = " |
|
| 183 | 183 | EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
| 184 | 184 | EVT_ID bigint(20) unsigned NOT NULL, |
| 185 | 185 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -194,31 +194,31 @@ discard block |
||
| 194 | 194 | EVT_external_URL varchar(200) NULL, |
| 195 | 195 | EVT_donations tinyint(1) NULL, |
| 196 | 196 | PRIMARY KEY (EVTM_ID)"; |
| 197 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 198 | - $table_name = 'esp_event_question_group'; |
|
| 199 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 197 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 198 | + $table_name = 'esp_event_question_group'; |
|
| 199 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 200 | 200 | EVT_ID bigint(20) unsigned NOT NULL, |
| 201 | 201 | QSG_ID int(10) unsigned NOT NULL, |
| 202 | 202 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 203 | 203 | PRIMARY KEY (EQG_ID)"; |
| 204 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 205 | - $table_name = 'esp_event_venue'; |
|
| 206 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 204 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 205 | + $table_name = 'esp_event_venue'; |
|
| 206 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 207 | 207 | EVT_ID bigint(20) unsigned NOT NULL, |
| 208 | 208 | VNU_ID bigint(20) unsigned NOT NULL, |
| 209 | 209 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 210 | 210 | PRIMARY KEY (EVV_ID)"; |
| 211 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 212 | - $table_name = 'esp_extra_meta'; |
|
| 213 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 211 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 212 | + $table_name = 'esp_extra_meta'; |
|
| 213 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 214 | 214 | OBJ_ID int(11) DEFAULT NULL, |
| 215 | 215 | EXM_type varchar(45) DEFAULT NULL, |
| 216 | 216 | EXM_key varchar(45) DEFAULT NULL, |
| 217 | 217 | EXM_value text, |
| 218 | 218 | PRIMARY KEY (EXM_ID)"; |
| 219 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 220 | - $table_name = 'esp_line_item'; |
|
| 221 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 219 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 220 | + $table_name = 'esp_line_item'; |
|
| 221 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 222 | 222 | LIN_code varchar(245) NOT NULL DEFAULT '', |
| 223 | 223 | TXN_ID int(11) DEFAULT NULL, |
| 224 | 224 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -234,18 +234,18 @@ discard block |
||
| 234 | 234 | OBJ_ID int(11) DEFAULT NULL, |
| 235 | 235 | OBJ_type varchar(45)DEFAULT NULL, |
| 236 | 236 | PRIMARY KEY (LIN_ID)"; |
| 237 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 238 | - $table_name = 'esp_message_template'; |
|
| 239 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 237 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 238 | + $table_name = 'esp_message_template'; |
|
| 239 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 240 | 240 | GRP_ID int(10) unsigned NOT NULL, |
| 241 | 241 | MTP_context varchar(50) NOT NULL, |
| 242 | 242 | MTP_template_field varchar(30) NOT NULL, |
| 243 | 243 | MTP_content text NOT NULL, |
| 244 | 244 | PRIMARY KEY (MTP_ID), |
| 245 | 245 | KEY GRP_ID (GRP_ID)"; |
| 246 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 247 | - $table_name = 'esp_message_template_group'; |
|
| 248 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 246 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 247 | + $table_name = 'esp_message_template_group'; |
|
| 248 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 249 | 249 | EVT_ID bigint(20) unsigned DEFAULT NULL, |
| 250 | 250 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
| 251 | 251 | MTP_messenger varchar(30) NOT NULL, |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | PRIMARY KEY (GRP_ID), |
| 258 | 258 | KEY EVT_ID (EVT_ID), |
| 259 | 259 | KEY MTP_user_id (MTP_user_id)"; |
| 260 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 261 | - $table_name = 'esp_payment'; |
|
| 262 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 260 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 261 | + $table_name = 'esp_payment'; |
|
| 262 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 263 | 263 | TXN_ID int(10) unsigned DEFAULT NULL, |
| 264 | 264 | STS_ID varchar(3) COLLATE utf8_bin DEFAULT NULL, |
| 265 | 265 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -275,9 +275,9 @@ discard block |
||
| 275 | 275 | PRIMARY KEY (PAY_ID), |
| 276 | 276 | KEY TXN_ID (TXN_ID), |
| 277 | 277 | KEY PAY_timestamp (PAY_timestamp)"; |
| 278 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 279 | - $table_name = "esp_ticket"; |
|
| 280 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 278 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 279 | + $table_name = "esp_ticket"; |
|
| 280 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 281 | 281 | TTM_ID int(10) unsigned NOT NULL, |
| 282 | 282 | TKT_name varchar(245) NOT NULL DEFAULT '', |
| 283 | 283 | TKT_description text NOT NULL, |
@@ -296,28 +296,28 @@ discard block |
||
| 296 | 296 | TKT_parent int(10) unsigned DEFAULT '0', |
| 297 | 297 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
| 298 | 298 | PRIMARY KEY (TKT_ID)"; |
| 299 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 300 | - $table_name = "esp_ticket_price"; |
|
| 301 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 299 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 300 | + $table_name = "esp_ticket_price"; |
|
| 301 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 302 | 302 | TKT_ID int(10) unsigned NOT NULL, |
| 303 | 303 | PRC_ID int(10) unsigned NOT NULL, |
| 304 | 304 | PRIMARY KEY (TKP_ID)"; |
| 305 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 306 | - $table_name = "esp_datetime_ticket"; |
|
| 307 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 305 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 306 | + $table_name = "esp_datetime_ticket"; |
|
| 307 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 308 | 308 | DTT_ID int(10) unsigned NOT NULL, |
| 309 | 309 | TKT_ID int(10) unsigned NOT NULL, |
| 310 | 310 | PRIMARY KEY (DTK_ID)"; |
| 311 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 312 | - $table_name = "esp_ticket_template"; |
|
| 313 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 311 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 312 | + $table_name = "esp_ticket_template"; |
|
| 313 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 314 | 314 | TTM_name varchar(45) NOT NULL, |
| 315 | 315 | TTM_description text, |
| 316 | 316 | TTM_file varchar(45), |
| 317 | 317 | PRIMARY KEY (TTM_ID)"; |
| 318 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 319 | - $table_name = "esp_price"; |
|
| 320 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 318 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 319 | + $table_name = "esp_price"; |
|
| 320 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 321 | 321 | PRT_ID tinyint(3) unsigned NOT NULL, |
| 322 | 322 | PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00', |
| 323 | 323 | PRC_name varchar(245) NOT NULL, |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | PRC_order tinyint(3) unsigned NOT NULL DEFAULT '0', |
| 329 | 329 | PRC_parent int(10) unsigned DEFAULT 0, |
| 330 | 330 | PRIMARY KEY (PRC_ID)"; |
| 331 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 332 | - $table_name = "esp_price_type"; |
|
| 333 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
| 331 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 332 | + $table_name = "esp_price_type"; |
|
| 333 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
| 334 | 334 | PRT_name varchar(45) NOT NULL, |
| 335 | 335 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
| 336 | 336 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
| 339 | 339 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
| 340 | 340 | PRIMARY KEY (PRT_ID)"; |
| 341 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 342 | - $table_name = 'esp_question'; |
|
| 343 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 341 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 342 | + $table_name = 'esp_question'; |
|
| 343 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 344 | 344 | QST_display_text text NOT NULL, |
| 345 | 345 | QST_admin_label varchar(255) NOT NULL, |
| 346 | 346 | QST_system varchar(25) DEFAULT NULL, |
@@ -352,10 +352,10 @@ discard block |
||
| 352 | 352 | QST_wp_user bigint(20) unsigned NULL, |
| 353 | 353 | QST_deleted tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 354 | 354 | PRIMARY KEY (QST_ID)'; |
| 355 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 356 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 357 | - $table_name = 'esp_question_group'; |
|
| 358 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 355 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 356 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 357 | + $table_name = 'esp_question_group'; |
|
| 358 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 359 | 359 | QSG_name varchar(255) NOT NULL, |
| 360 | 360 | QSG_identifier varchar(100) NOT NULL, |
| 361 | 361 | QSG_desc text NULL, |
@@ -366,23 +366,23 @@ discard block |
||
| 366 | 366 | QSG_deleted tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 367 | 367 | PRIMARY KEY (QSG_ID), |
| 368 | 368 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
| 369 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 370 | - $table_name = 'esp_question_group_question'; |
|
| 371 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 369 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 370 | + $table_name = 'esp_question_group_question'; |
|
| 371 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 372 | 372 | QSG_ID int(10) unsigned NOT NULL, |
| 373 | 373 | QST_ID int(10) unsigned NOT NULL, |
| 374 | 374 | PRIMARY KEY (QGQ_ID) "; |
| 375 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 376 | - $table_name = 'esp_question_option'; |
|
| 377 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 375 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 376 | + $table_name = 'esp_question_option'; |
|
| 377 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 378 | 378 | QSO_value varchar(255) NOT NULL, |
| 379 | 379 | QSO_desc text NOT NULL, |
| 380 | 380 | QST_ID int(10) unsigned NOT NULL, |
| 381 | 381 | QSO_deleted tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 382 | 382 | PRIMARY KEY (QSO_ID)"; |
| 383 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 384 | - $table_name = 'esp_registration'; |
|
| 385 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 383 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 384 | + $table_name = 'esp_registration'; |
|
| 385 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 386 | 386 | EVT_ID bigint(20) unsigned NOT NULL, |
| 387 | 387 | ATT_ID bigint(20) unsigned NOT NULL, |
| 388 | 388 | TXN_ID int(10) unsigned NOT NULL, |
@@ -405,25 +405,25 @@ discard block |
||
| 405 | 405 | KEY STS_ID (STS_ID), |
| 406 | 406 | KEY REG_url_link (REG_url_link), |
| 407 | 407 | KEY REG_code (REG_code)"; |
| 408 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 409 | - $table_name = 'esp_checkin'; |
|
| 410 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 408 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 409 | + $table_name = 'esp_checkin'; |
|
| 410 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 411 | 411 | REG_ID int(10) unsigned NOT NULL, |
| 412 | 412 | DTT_ID int(10) unsigned NOT NULL, |
| 413 | 413 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
| 414 | 414 | CHK_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 415 | 415 | PRIMARY KEY (CHK_ID)"; |
| 416 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 417 | - $table_name = 'esp_state'; |
|
| 418 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
| 416 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 417 | + $table_name = 'esp_state'; |
|
| 418 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
| 419 | 419 | CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL, |
| 420 | 420 | STA_abbrev varchar(6) COLLATE utf8_bin NOT NULL, |
| 421 | 421 | STA_name varchar(100) COLLATE utf8_bin NOT NULL, |
| 422 | 422 | STA_active tinyint(1) DEFAULT '1', |
| 423 | 423 | PRIMARY KEY (STA_ID)"; |
| 424 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 425 | - $table_name = 'esp_status'; |
|
| 426 | - $sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL, |
|
| 424 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 425 | + $table_name = 'esp_status'; |
|
| 426 | + $sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL, |
|
| 427 | 427 | STS_code varchar(45) COLLATE utf8_bin NOT NULL, |
| 428 | 428 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
| 429 | 429 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -431,9 +431,9 @@ discard block |
||
| 431 | 431 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
| 432 | 432 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
| 433 | 433 | KEY STS_type (STS_type)"; |
| 434 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 435 | - $table_name = 'esp_transaction'; |
|
| 436 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 434 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 435 | + $table_name = 'esp_transaction'; |
|
| 436 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 437 | 437 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 438 | 438 | TXN_total decimal(10,3) DEFAULT '0.00', |
| 439 | 439 | TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00', |
@@ -443,9 +443,9 @@ discard block |
||
| 443 | 443 | PRIMARY KEY (TXN_ID), |
| 444 | 444 | KEY TXN_timestamp (TXN_timestamp), |
| 445 | 445 | KEY STS_ID (STS_ID)"; |
| 446 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 447 | - $table_name = 'esp_venue_meta'; |
|
| 448 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 446 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 447 | + $table_name = 'esp_venue_meta'; |
|
| 448 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 449 | 449 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
| 450 | 450 | VNU_address varchar(255) DEFAULT NULL, |
| 451 | 451 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -463,52 +463,52 @@ discard block |
||
| 463 | 463 | PRIMARY KEY (VNUM_ID), |
| 464 | 464 | KEY STA_ID (STA_ID), |
| 465 | 465 | KEY CNT_ISO (CNT_ISO)"; |
| 466 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 467 | - // setting up the default stats and countries is also essential for the data migrations to run |
|
| 468 | - // (because many need to convert old string states to foreign keys into the states table) |
|
| 469 | - $this->insert_default_states(); |
|
| 470 | - $this->insert_default_countries(); |
|
| 471 | - // setting up default prices, price types, and tickets is also essential for the price migrations |
|
| 472 | - $this->insert_default_price_types(); |
|
| 473 | - $this->insert_default_prices(); |
|
| 474 | - $this->insert_default_tickets(); |
|
| 475 | - // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
| 476 | - EE_Config::instance()->update_espresso_config(false, true); |
|
| 477 | - return true; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
| 484 | - * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
| 485 | - * leave them for now. Mayeb remove them in 4.5 or something. |
|
| 486 | - * |
|
| 487 | - * @return boolean |
|
| 488 | - */ |
|
| 489 | - public function schema_changes_after_migration() |
|
| 490 | - { |
|
| 491 | - return true; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * insert_default_states |
|
| 498 | - * |
|
| 499 | - * @access public |
|
| 500 | - * @static |
|
| 501 | - * @return void |
|
| 502 | - */ |
|
| 503 | - public function insert_default_states() |
|
| 504 | - { |
|
| 505 | - global $wpdb; |
|
| 506 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 507 | - if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
| 508 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 509 | - $states = $wpdb->get_var($SQL); |
|
| 510 | - if (! $states) { |
|
| 511 | - $SQL = "INSERT INTO " . $state_table . " |
|
| 466 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 467 | + // setting up the default stats and countries is also essential for the data migrations to run |
|
| 468 | + // (because many need to convert old string states to foreign keys into the states table) |
|
| 469 | + $this->insert_default_states(); |
|
| 470 | + $this->insert_default_countries(); |
|
| 471 | + // setting up default prices, price types, and tickets is also essential for the price migrations |
|
| 472 | + $this->insert_default_price_types(); |
|
| 473 | + $this->insert_default_prices(); |
|
| 474 | + $this->insert_default_tickets(); |
|
| 475 | + // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
| 476 | + EE_Config::instance()->update_espresso_config(false, true); |
|
| 477 | + return true; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
| 484 | + * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
| 485 | + * leave them for now. Mayeb remove them in 4.5 or something. |
|
| 486 | + * |
|
| 487 | + * @return boolean |
|
| 488 | + */ |
|
| 489 | + public function schema_changes_after_migration() |
|
| 490 | + { |
|
| 491 | + return true; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * insert_default_states |
|
| 498 | + * |
|
| 499 | + * @access public |
|
| 500 | + * @static |
|
| 501 | + * @return void |
|
| 502 | + */ |
|
| 503 | + public function insert_default_states() |
|
| 504 | + { |
|
| 505 | + global $wpdb; |
|
| 506 | + $state_table = $wpdb->prefix . "esp_state"; |
|
| 507 | + if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
| 508 | + $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 509 | + $states = $wpdb->get_var($SQL); |
|
| 510 | + if (! $states) { |
|
| 511 | + $SQL = "INSERT INTO " . $state_table . " |
|
| 512 | 512 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
| 513 | 513 | (1, 'US', 'AK', 'Alaska', 1), |
| 514 | 514 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -579,29 +579,29 @@ discard block |
||
| 579 | 579 | (67, 'CA', 'PE', 'Prince Edward Island', 1), |
| 580 | 580 | (68, 'CA', 'QC', 'Quebec', 1), |
| 581 | 581 | (69, 'CA', 'SK', 'Saskatchewan', 1);"; |
| 582 | - $wpdb->query($SQL); |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * insert_default_countries |
|
| 591 | - * |
|
| 592 | - * @access public |
|
| 593 | - * @static |
|
| 594 | - * @return void |
|
| 595 | - */ |
|
| 596 | - public function insert_default_countries() |
|
| 597 | - { |
|
| 598 | - global $wpdb; |
|
| 599 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 600 | - if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
| 601 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 602 | - $countries = $wpdb->get_var($SQL); |
|
| 603 | - if (! $countries) { |
|
| 604 | - $SQL = "INSERT INTO " . $country_table . " |
|
| 582 | + $wpdb->query($SQL); |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * insert_default_countries |
|
| 591 | + * |
|
| 592 | + * @access public |
|
| 593 | + * @static |
|
| 594 | + * @return void |
|
| 595 | + */ |
|
| 596 | + public function insert_default_countries() |
|
| 597 | + { |
|
| 598 | + global $wpdb; |
|
| 599 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 600 | + if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
| 601 | + $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 602 | + $countries = $wpdb->get_var($SQL); |
|
| 603 | + if (! $countries) { |
|
| 604 | + $SQL = "INSERT INTO " . $country_table . " |
|
| 605 | 605 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
| 606 | 606 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
| 607 | 607 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -829,984 +829,984 @@ discard block |
||
| 829 | 829 | ('ZA', 'ZAF', 0, 'South Africa', 'ZAR', 'Rand', 'Rands', 'R', 1, 2, '+27', 0, 0), |
| 830 | 830 | ('ZM', 'ZMB', 0, 'Zambia', 'ZMK', 'Kwacha', 'Kwachas', '', 1, 2, '+260', 0, 0), |
| 831 | 831 | ('ZW', 'ZWE', 0, 'Zimbabwe', 'ZWD', 'Dollar', 'Dollars', 'Z$', 1, 2, '+263', 0, 0);"; |
| 832 | - $wpdb->query($SQL); |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * insert_default_price_types |
|
| 841 | - * |
|
| 842 | - * @access public |
|
| 843 | - * @static |
|
| 844 | - * @return void |
|
| 845 | - */ |
|
| 846 | - public function insert_default_price_types() |
|
| 847 | - { |
|
| 848 | - global $wpdb; |
|
| 849 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 850 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 851 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 852 | - $price_types_exist = $wpdb->get_var($SQL); |
|
| 853 | - if (! $price_types_exist) { |
|
| 854 | - $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
| 832 | + $wpdb->query($SQL); |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * insert_default_price_types |
|
| 841 | + * |
|
| 842 | + * @access public |
|
| 843 | + * @static |
|
| 844 | + * @return void |
|
| 845 | + */ |
|
| 846 | + public function insert_default_price_types() |
|
| 847 | + { |
|
| 848 | + global $wpdb; |
|
| 849 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 850 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 851 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 852 | + $price_types_exist = $wpdb->get_var($SQL); |
|
| 853 | + if (! $price_types_exist) { |
|
| 854 | + $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
| 855 | 855 | (1, '" . esc_html__('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
| 856 | 856 | (2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
| 857 | 857 | (3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
| 858 | 858 | (4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
| 859 | 859 | (5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
| 860 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
| 861 | - $wpdb->query($SQL); |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * insert_default_prices. We assume we're upgrading to regular here. |
|
| 870 | - * If we're INSTALLING 4.1 CAF, then we add a few extra default prices |
|
| 871 | - * when EEH_Activaion's initialize_db_content is called via ahook in |
|
| 872 | - * EE_BRewing_regular |
|
| 873 | - * |
|
| 874 | - * @access public |
|
| 875 | - * @static |
|
| 876 | - * @return void |
|
| 877 | - */ |
|
| 878 | - public function insert_default_prices() |
|
| 879 | - { |
|
| 880 | - global $wpdb; |
|
| 881 | - $price_table = $wpdb->prefix . "esp_price"; |
|
| 882 | - if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
| 883 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 884 | - $prices_exist = $wpdb->get_var($SQL); |
|
| 885 | - if (! $prices_exist) { |
|
| 886 | - $SQL = "INSERT INTO $price_table |
|
| 860 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
| 861 | + $wpdb->query($SQL); |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * insert_default_prices. We assume we're upgrading to regular here. |
|
| 870 | + * If we're INSTALLING 4.1 CAF, then we add a few extra default prices |
|
| 871 | + * when EEH_Activaion's initialize_db_content is called via ahook in |
|
| 872 | + * EE_BRewing_regular |
|
| 873 | + * |
|
| 874 | + * @access public |
|
| 875 | + * @static |
|
| 876 | + * @return void |
|
| 877 | + */ |
|
| 878 | + public function insert_default_prices() |
|
| 879 | + { |
|
| 880 | + global $wpdb; |
|
| 881 | + $price_table = $wpdb->prefix . "esp_price"; |
|
| 882 | + if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
| 883 | + $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 884 | + $prices_exist = $wpdb->get_var($SQL); |
|
| 885 | + if (! $prices_exist) { |
|
| 886 | + $SQL = "INSERT INTO $price_table |
|
| 887 | 887 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES |
| 888 | 888 | (1, 1, '0.00', 'Free Admission', '', 1, null, 0, 0, 0);"; |
| 889 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
| 890 | - $wpdb->query($SQL); |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * insert default ticket |
|
| 899 | - * |
|
| 900 | - * @access public |
|
| 901 | - * @static |
|
| 902 | - * @return void |
|
| 903 | - */ |
|
| 904 | - public function insert_default_tickets() |
|
| 905 | - { |
|
| 906 | - global $wpdb; |
|
| 907 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 908 | - if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
| 909 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 910 | - $tickets_exist = $wpdb->get_var($SQL); |
|
| 911 | - if (! $tickets_exist) { |
|
| 912 | - $SQL = "INSERT INTO $ticket_table |
|
| 889 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
| 890 | + $wpdb->query($SQL); |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * insert default ticket |
|
| 899 | + * |
|
| 900 | + * @access public |
|
| 901 | + * @static |
|
| 902 | + * @return void |
|
| 903 | + */ |
|
| 904 | + public function insert_default_tickets() |
|
| 905 | + { |
|
| 906 | + global $wpdb; |
|
| 907 | + $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 908 | + if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
| 909 | + $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 910 | + $tickets_exist = $wpdb->get_var($SQL); |
|
| 911 | + if (! $tickets_exist) { |
|
| 912 | + $SQL = "INSERT INTO $ticket_table |
|
| 913 | 913 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
| 914 | 914 | ( 1, 0, '" |
| 915 | - . esc_html__("Free Ticket", "event_espresso") |
|
| 916 | - . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
| 917 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
| 918 | - $wpdb->query($SQL); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 922 | - if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
| 923 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 924 | - $ticket_prc_exist = $wpdb->get_var($SQL); |
|
| 925 | - if (! $ticket_prc_exist) { |
|
| 926 | - $SQL = "INSERT INTO $ticket_price_table |
|
| 915 | + . esc_html__("Free Ticket", "event_espresso") |
|
| 916 | + . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
| 917 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
| 918 | + $wpdb->query($SQL); |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 922 | + if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
| 923 | + $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 924 | + $ticket_prc_exist = $wpdb->get_var($SQL); |
|
| 925 | + if (! $ticket_prc_exist) { |
|
| 926 | + $SQL = "INSERT INTO $ticket_price_table |
|
| 927 | 927 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
| 928 | 928 | ( 1, 1, 1 ) |
| 929 | 929 | "; |
| 930 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
| 931 | - $wpdb->query($SQL); |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
| 940 | - * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
| 941 | - * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
| 942 | - * |
|
| 943 | - * @global type $wpdb |
|
| 944 | - * @param string $country_name |
|
| 945 | - * @return array where keys are columns, values are column values |
|
| 946 | - */ |
|
| 947 | - public function get_or_create_country($country_name) |
|
| 948 | - { |
|
| 949 | - if (! $country_name) { |
|
| 950 | - throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
| 951 | - } |
|
| 952 | - global $wpdb; |
|
| 953 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 954 | - if (is_int($country_name)) { |
|
| 955 | - $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
| 956 | - } |
|
| 957 | - $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
| 930 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
| 931 | + $wpdb->query($SQL); |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
| 940 | + * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
| 941 | + * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
| 942 | + * |
|
| 943 | + * @global type $wpdb |
|
| 944 | + * @param string $country_name |
|
| 945 | + * @return array where keys are columns, values are column values |
|
| 946 | + */ |
|
| 947 | + public function get_or_create_country($country_name) |
|
| 948 | + { |
|
| 949 | + if (! $country_name) { |
|
| 950 | + throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
| 951 | + } |
|
| 952 | + global $wpdb; |
|
| 953 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 954 | + if (is_int($country_name)) { |
|
| 955 | + $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
| 956 | + } |
|
| 957 | + $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
| 958 | 958 | CNT_ISO LIKE %s OR |
| 959 | 959 | CNT_ISO3 LIKE %s OR |
| 960 | 960 | CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A); |
| 961 | - if (! $country) { |
|
| 962 | - // insert a new one then |
|
| 963 | - $cols_n_values = array( |
|
| 964 | - 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
| 965 | - 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
| 966 | - 'RGN_ID' => 0, |
|
| 967 | - 'CNT_name' => $country_name, |
|
| 968 | - 'CNT_cur_code' => 'USD', |
|
| 969 | - 'CNT_cur_single' => 'Dollar', |
|
| 970 | - 'CNT_cur_plural' => 'Dollars', |
|
| 971 | - 'CNT_cur_sign' => '$', |
|
| 972 | - 'CNT_cur_sign_b4' => true, |
|
| 973 | - 'CNT_cur_dec_plc' => 2, |
|
| 974 | - 'CNT_cur_dec_mrk' => '.', |
|
| 975 | - 'CNT_cur_thsnds' => ',', |
|
| 976 | - 'CNT_tel_code' => '+1', |
|
| 977 | - 'CNT_is_EU' => false, |
|
| 978 | - 'CNT_active' => true, |
|
| 979 | - ); |
|
| 980 | - $data_types = array( |
|
| 981 | - '%s',// CNT_ISO |
|
| 982 | - '%s',// CNT_ISO3 |
|
| 983 | - '%d',// RGN_ID |
|
| 984 | - '%s',// CNT_name |
|
| 985 | - '%s',// CNT_cur_code |
|
| 986 | - '%s',// CNT_cur_single |
|
| 987 | - '%s',// CNT_cur_plural |
|
| 988 | - '%s',// CNT_cur_sign |
|
| 989 | - '%d',// CNT_cur_sign_b4 |
|
| 990 | - '%d',// CNT_cur_dec_plc |
|
| 991 | - '%s',// CNT_cur_dec_mrk |
|
| 992 | - '%s',// CNT_cur_thsnds |
|
| 993 | - '%s',// CNT_tel_code |
|
| 994 | - '%d',// CNT_is_EU |
|
| 995 | - '%d',// CNT_active |
|
| 996 | - ); |
|
| 997 | - $success = $wpdb->insert( |
|
| 998 | - $country_table, |
|
| 999 | - $cols_n_values, |
|
| 1000 | - $data_types |
|
| 1001 | - ); |
|
| 1002 | - if (! $success) { |
|
| 1003 | - throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
| 1004 | - 'N/A', |
|
| 1005 | - array('country_id' => $country_name), |
|
| 1006 | - $country_table, |
|
| 1007 | - $cols_n_values, |
|
| 1008 | - $data_types |
|
| 1009 | - )); |
|
| 1010 | - } |
|
| 1011 | - $country = $cols_n_values; |
|
| 1012 | - } |
|
| 1013 | - return $country; |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * finds a country iso which hasnt been used yet |
|
| 1020 | - * |
|
| 1021 | - * @global type $wpdb |
|
| 1022 | - * @return string |
|
| 1023 | - */ |
|
| 1024 | - private function _find_available_country_iso($num_letters = 2) |
|
| 1025 | - { |
|
| 1026 | - global $wpdb; |
|
| 1027 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 1028 | - $attempts = 0; |
|
| 1029 | - do { |
|
| 1030 | - $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
| 1031 | - $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
| 1032 | - . $country_table |
|
| 1033 | - . " WHERE CNT_ISO=%s", $current_iso)); |
|
| 1034 | - $attempts++; |
|
| 1035 | - // keep going until we find an available country code, or we arbitrarily |
|
| 1036 | - // decide we've tried this enough. Somehow they have way too many countries |
|
| 1037 | - // (probably because they're mis-using the EE3 country_id like a custom question) |
|
| 1038 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1039 | - return $current_iso; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
| 1046 | - * is independent of outside code which can change in future versions of EE |
|
| 1047 | - * |
|
| 1048 | - * @global type $wpdb |
|
| 1049 | - * @param string $state_name |
|
| 1050 | - * @return array where keys are columns, values are column values |
|
| 1051 | - */ |
|
| 1052 | - public function get_or_create_state($state_name, $country_name = '') |
|
| 1053 | - { |
|
| 1054 | - if (! $state_name) { |
|
| 1055 | - throw new EE_Error(esc_html__( |
|
| 1056 | - "Could not get-or-create state because no state name was provided", |
|
| 1057 | - "event_espresso" |
|
| 1058 | - )); |
|
| 1059 | - } |
|
| 1060 | - try { |
|
| 1061 | - $country = $this->get_or_create_country($country_name); |
|
| 1062 | - $country_iso = $country['CNT_ISO']; |
|
| 1063 | - } catch (EE_Error $e) { |
|
| 1064 | - $country_iso = $this->get_default_country_iso(); |
|
| 1065 | - } |
|
| 1066 | - global $wpdb; |
|
| 1067 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 1068 | - $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
| 961 | + if (! $country) { |
|
| 962 | + // insert a new one then |
|
| 963 | + $cols_n_values = array( |
|
| 964 | + 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
| 965 | + 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
| 966 | + 'RGN_ID' => 0, |
|
| 967 | + 'CNT_name' => $country_name, |
|
| 968 | + 'CNT_cur_code' => 'USD', |
|
| 969 | + 'CNT_cur_single' => 'Dollar', |
|
| 970 | + 'CNT_cur_plural' => 'Dollars', |
|
| 971 | + 'CNT_cur_sign' => '$', |
|
| 972 | + 'CNT_cur_sign_b4' => true, |
|
| 973 | + 'CNT_cur_dec_plc' => 2, |
|
| 974 | + 'CNT_cur_dec_mrk' => '.', |
|
| 975 | + 'CNT_cur_thsnds' => ',', |
|
| 976 | + 'CNT_tel_code' => '+1', |
|
| 977 | + 'CNT_is_EU' => false, |
|
| 978 | + 'CNT_active' => true, |
|
| 979 | + ); |
|
| 980 | + $data_types = array( |
|
| 981 | + '%s',// CNT_ISO |
|
| 982 | + '%s',// CNT_ISO3 |
|
| 983 | + '%d',// RGN_ID |
|
| 984 | + '%s',// CNT_name |
|
| 985 | + '%s',// CNT_cur_code |
|
| 986 | + '%s',// CNT_cur_single |
|
| 987 | + '%s',// CNT_cur_plural |
|
| 988 | + '%s',// CNT_cur_sign |
|
| 989 | + '%d',// CNT_cur_sign_b4 |
|
| 990 | + '%d',// CNT_cur_dec_plc |
|
| 991 | + '%s',// CNT_cur_dec_mrk |
|
| 992 | + '%s',// CNT_cur_thsnds |
|
| 993 | + '%s',// CNT_tel_code |
|
| 994 | + '%d',// CNT_is_EU |
|
| 995 | + '%d',// CNT_active |
|
| 996 | + ); |
|
| 997 | + $success = $wpdb->insert( |
|
| 998 | + $country_table, |
|
| 999 | + $cols_n_values, |
|
| 1000 | + $data_types |
|
| 1001 | + ); |
|
| 1002 | + if (! $success) { |
|
| 1003 | + throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
| 1004 | + 'N/A', |
|
| 1005 | + array('country_id' => $country_name), |
|
| 1006 | + $country_table, |
|
| 1007 | + $cols_n_values, |
|
| 1008 | + $data_types |
|
| 1009 | + )); |
|
| 1010 | + } |
|
| 1011 | + $country = $cols_n_values; |
|
| 1012 | + } |
|
| 1013 | + return $country; |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * finds a country iso which hasnt been used yet |
|
| 1020 | + * |
|
| 1021 | + * @global type $wpdb |
|
| 1022 | + * @return string |
|
| 1023 | + */ |
|
| 1024 | + private function _find_available_country_iso($num_letters = 2) |
|
| 1025 | + { |
|
| 1026 | + global $wpdb; |
|
| 1027 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 1028 | + $attempts = 0; |
|
| 1029 | + do { |
|
| 1030 | + $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
| 1031 | + $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
| 1032 | + . $country_table |
|
| 1033 | + . " WHERE CNT_ISO=%s", $current_iso)); |
|
| 1034 | + $attempts++; |
|
| 1035 | + // keep going until we find an available country code, or we arbitrarily |
|
| 1036 | + // decide we've tried this enough. Somehow they have way too many countries |
|
| 1037 | + // (probably because they're mis-using the EE3 country_id like a custom question) |
|
| 1038 | + } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1039 | + return $current_iso; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
| 1046 | + * is independent of outside code which can change in future versions of EE |
|
| 1047 | + * |
|
| 1048 | + * @global type $wpdb |
|
| 1049 | + * @param string $state_name |
|
| 1050 | + * @return array where keys are columns, values are column values |
|
| 1051 | + */ |
|
| 1052 | + public function get_or_create_state($state_name, $country_name = '') |
|
| 1053 | + { |
|
| 1054 | + if (! $state_name) { |
|
| 1055 | + throw new EE_Error(esc_html__( |
|
| 1056 | + "Could not get-or-create state because no state name was provided", |
|
| 1057 | + "event_espresso" |
|
| 1058 | + )); |
|
| 1059 | + } |
|
| 1060 | + try { |
|
| 1061 | + $country = $this->get_or_create_country($country_name); |
|
| 1062 | + $country_iso = $country['CNT_ISO']; |
|
| 1063 | + } catch (EE_Error $e) { |
|
| 1064 | + $country_iso = $this->get_default_country_iso(); |
|
| 1065 | + } |
|
| 1066 | + global $wpdb; |
|
| 1067 | + $state_table = $wpdb->prefix . "esp_state"; |
|
| 1068 | + $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
| 1069 | 1069 | (STA_abbrev LIKE %s OR |
| 1070 | 1070 | STA_name LIKE %s) AND |
| 1071 | 1071 | CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A); |
| 1072 | - if (! $state) { |
|
| 1073 | - // insert a new one then |
|
| 1074 | - $cols_n_values = array( |
|
| 1075 | - 'CNT_ISO' => $country_iso, |
|
| 1076 | - 'STA_abbrev' => substr($state_name, 0, 6), |
|
| 1077 | - 'STA_name' => $state_name, |
|
| 1078 | - 'STA_active' => true, |
|
| 1079 | - ); |
|
| 1080 | - $data_types = array( |
|
| 1081 | - '%s',// CNT_ISO |
|
| 1082 | - '%s',// STA_abbrev |
|
| 1083 | - '%s',// STA_name |
|
| 1084 | - '%d',// STA_active |
|
| 1085 | - ); |
|
| 1086 | - $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
| 1087 | - if (! $success) { |
|
| 1088 | - throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
| 1089 | - 'N/A', |
|
| 1090 | - array('state' => $state_name, 'country_id' => $country_name), |
|
| 1091 | - $state_table, |
|
| 1092 | - $cols_n_values, |
|
| 1093 | - $data_types |
|
| 1094 | - )); |
|
| 1095 | - } |
|
| 1096 | - $state = $cols_n_values; |
|
| 1097 | - $state['STA_ID'] = $wpdb->insert_id; |
|
| 1098 | - } |
|
| 1099 | - return $state; |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
| 1106 | - * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
| 1107 | - * |
|
| 1108 | - * @param type $timeString |
|
| 1109 | - * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
| 1110 | - * with leading zeros) |
|
| 1111 | - */ |
|
| 1112 | - public function convertTimeFromAMPM($timeString) |
|
| 1113 | - { |
|
| 1114 | - $matches = array(); |
|
| 1115 | - preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
| 1116 | - if (! $matches || count($matches) < 3) { |
|
| 1117 | - $hour = '00'; |
|
| 1118 | - $minutes = '00'; |
|
| 1119 | - } else { |
|
| 1120 | - $hour = intval($matches[1]); |
|
| 1121 | - $minutes = $matches[2]; |
|
| 1122 | - } |
|
| 1123 | - if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
| 1124 | - $hour = intval($hour) + 12; |
|
| 1125 | - } |
|
| 1126 | - $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
| 1127 | - $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
| 1128 | - return "$hour:$minutes"; |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * Gets the ISO3 fora country given its 3.1 country ID. |
|
| 1135 | - * |
|
| 1136 | - * @param int $country_id |
|
| 1137 | - * @return string the country's ISO3 code |
|
| 1138 | - */ |
|
| 1139 | - public function get_iso_from_3_1_country_id($country_id) |
|
| 1140 | - { |
|
| 1141 | - $old_countries = array( |
|
| 1142 | - array(64, 'United States', 'US', 'USA', 1), |
|
| 1143 | - array(15, 'Australia', 'AU', 'AUS', 1), |
|
| 1144 | - array(39, 'Canada', 'CA', 'CAN', 1), |
|
| 1145 | - array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
| 1146 | - array(70, 'France', 'FR', 'FRA', 2), |
|
| 1147 | - array(111, 'Italy', 'IT', 'ITA', 2), |
|
| 1148 | - array(63, 'Spain', 'ES', 'ESP', 2), |
|
| 1149 | - array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
| 1150 | - array(2, 'Albania', 'AL', 'ALB', 1), |
|
| 1151 | - array(3, 'Germany', 'DE', 'DEU', 2), |
|
| 1152 | - array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
| 1153 | - array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
| 1154 | - array(197, 'Sweden', 'SE', 'SWE', 1), |
|
| 1155 | - array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
| 1156 | - array(4, 'Andorra', 'AD', 'AND', 2), |
|
| 1157 | - array(5, 'Angola', 'AO', 'AGO', 1), |
|
| 1158 | - array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
| 1159 | - array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
| 1160 | - array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
| 1161 | - array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
| 1162 | - array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
| 1163 | - array(12, 'Argentina', 'AR', 'ARG', 1), |
|
| 1164 | - array(13, 'Armenia', 'AM', 'ARM', 1), |
|
| 1165 | - array(14, 'Aruba', 'AW', 'ABW', 1), |
|
| 1166 | - array(16, 'Austria', 'AT', 'AUT', 2), |
|
| 1167 | - array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
| 1168 | - array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
| 1169 | - array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
| 1170 | - array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
| 1171 | - array(21, 'Barbados', 'BB', 'BRB', 1), |
|
| 1172 | - array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
| 1173 | - array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
| 1174 | - array(24, 'Benin', 'BJ', 'BEN', 1), |
|
| 1175 | - array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
| 1176 | - array(26, 'Belarus', 'BY', 'BLR', 1), |
|
| 1177 | - array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
| 1178 | - array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
| 1179 | - array(29, 'Botswana', 'BW', 'BWA', 1), |
|
| 1180 | - array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
| 1181 | - array(30, 'Brazil', 'BR', 'BRA', 1), |
|
| 1182 | - array(31, 'Brunei', 'BN', 'BRN', 1), |
|
| 1183 | - array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
| 1184 | - array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
| 1185 | - array(34, 'Burundi', 'BI', 'BDI', 1), |
|
| 1186 | - array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
| 1187 | - array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
| 1188 | - array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
| 1189 | - array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
| 1190 | - array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
| 1191 | - array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
| 1192 | - array(40, 'Chad', 'TD', 'TCD', 1), |
|
| 1193 | - array(41, 'Chile', 'CL', 'CHL', 1), |
|
| 1194 | - array(42, 'China', 'CN', 'CHN', 1), |
|
| 1195 | - array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
| 1196 | - array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
| 1197 | - array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
| 1198 | - array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
| 1199 | - array(44, 'Colombia', 'CO', 'COL', 1), |
|
| 1200 | - array(45, 'Comoros', 'KM', 'COM', 1), |
|
| 1201 | - array(46, 'Congo', 'CG', 'COG', 1), |
|
| 1202 | - array(47, 'North Korea', 'KP', 'PRK', 1), |
|
| 1203 | - array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
| 1204 | - array(51, 'Croatia', 'HR', 'HRV', 1), |
|
| 1205 | - array(52, 'Cuba', 'CU', 'CUB', 1), |
|
| 1206 | - array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
| 1207 | - array(53, 'Denmark', 'DK', 'DNK', 1), |
|
| 1208 | - array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
| 1209 | - array(55, 'Dominica', 'DM', 'DMA', 1), |
|
| 1210 | - array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
| 1211 | - array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
| 1212 | - array(57, 'Egypt', 'EG', 'EGY', 1), |
|
| 1213 | - array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
| 1214 | - array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
| 1215 | - array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
| 1216 | - array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
| 1217 | - array(65, 'Estonia', 'EE', 'EST', 2), |
|
| 1218 | - array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
| 1219 | - array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
| 1220 | - array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
| 1221 | - array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
| 1222 | - array(69, 'Finland', 'FI', 'FIN', 2), |
|
| 1223 | - array(71, 'Gabon', 'GA', 'GAB', 1), |
|
| 1224 | - array(72, 'Gambia', 'GM', 'GMB', 1), |
|
| 1225 | - array(73, 'Georgia', 'GE', 'GEO', 1), |
|
| 1226 | - array(74, 'Ghana', 'GH', 'GHA', 1), |
|
| 1227 | - array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
| 1228 | - array(76, 'Greece', 'GR', 'GRC', 2), |
|
| 1229 | - array(77, 'Grenada', 'GD', 'GRD', 1), |
|
| 1230 | - array(78, 'Greenland', 'GL', 'GRL', 1), |
|
| 1231 | - array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
| 1232 | - array(80, 'Guam', 'GU', 'GUM', 1), |
|
| 1233 | - array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
| 1234 | - array(82, 'Guinea', 'GN', 'GIN', 1), |
|
| 1235 | - array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
| 1236 | - array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
| 1237 | - array(85, 'Guyana', 'GY', 'GUY', 1), |
|
| 1238 | - array(86, 'Haiti', 'HT', 'HTI', 1), |
|
| 1239 | - array(88, 'Honduras', 'HN', 'HND', 1), |
|
| 1240 | - array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
| 1241 | - array(90, 'Hungary', 'HU', 'HUN', 1), |
|
| 1242 | - array(91, 'India', 'IN', 'IND', 1), |
|
| 1243 | - array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
| 1244 | - array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
| 1245 | - array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
| 1246 | - array(94, 'Iran', 'IR', 'IRN', 1), |
|
| 1247 | - array(95, 'Ireland', 'IE', 'IRL', 2), |
|
| 1248 | - array(97, 'Iceland', 'IS', 'ISL', 1), |
|
| 1249 | - array(110, 'Israel', 'IL', 'ISR', 1), |
|
| 1250 | - array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
| 1251 | - array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
| 1252 | - array(113, 'Japan', 'JP', 'JPN', 1), |
|
| 1253 | - array(114, 'Jordan', 'JO', 'JOR', 1), |
|
| 1254 | - array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
| 1255 | - array(116, 'Kenya', 'KE', 'KEN', 1), |
|
| 1256 | - array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
| 1257 | - array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
| 1258 | - array(48, 'South Korea', 'KR', 'KOR', 1), |
|
| 1259 | - array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
| 1260 | - // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
| 1261 | - array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
| 1262 | - array(120, 'Laos', 'LA', 'LAO', 1), |
|
| 1263 | - array(121, 'Latvia', 'LV', 'LVA', 2), |
|
| 1264 | - array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
| 1265 | - array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
| 1266 | - array(124, 'Liberia', 'LR', 'LBR', 1), |
|
| 1267 | - array(125, 'Libya', 'LY', 'LBY', 1), |
|
| 1268 | - array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
| 1269 | - array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
| 1270 | - array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
| 1271 | - array(129, 'Macao', 'MO', 'MAC', 1), |
|
| 1272 | - array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
| 1273 | - array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
| 1274 | - array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
| 1275 | - array(133, 'Malawi', 'MW', 'MWI', 1), |
|
| 1276 | - array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
| 1277 | - array(135, 'Mali', 'ML', 'MLI', 1), |
|
| 1278 | - array(136, 'Malta', 'MT', 'MLT', 2), |
|
| 1279 | - array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
| 1280 | - array(137, 'Morocco', 'MA', 'MAR', 1), |
|
| 1281 | - array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
| 1282 | - array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
| 1283 | - array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
| 1284 | - array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
| 1285 | - array(141, 'Mayote', 'YT', 'MYT', 2), |
|
| 1286 | - array(142, 'Mexico', 'MX', 'MEX', 1), |
|
| 1287 | - array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
| 1288 | - array(144, 'Moldova', 'MD', 'MDA', 1), |
|
| 1289 | - array(145, 'Monaco', 'MC', 'MCO', 2), |
|
| 1290 | - array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
| 1291 | - array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
| 1292 | - array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
| 1293 | - array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
| 1294 | - array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
| 1295 | - array(150, 'Namibia', 'NA', 'NAM', 1), |
|
| 1296 | - array(151, 'Nauru', 'NR', 'NRU', 1), |
|
| 1297 | - array(152, 'Nepal', 'NP', 'NPL', 1), |
|
| 1298 | - array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
| 1299 | - array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
| 1300 | - array(154, 'Niger', 'NE', 'NER', 1), |
|
| 1301 | - array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
| 1302 | - array(156, 'Niue', 'NU', 'NIU', 1), |
|
| 1303 | - array(157, 'Norway', 'NO', 'NOR', 1), |
|
| 1304 | - array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
| 1305 | - array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
| 1306 | - array(160, 'Oman', 'OM', 'OMN', 1), |
|
| 1307 | - array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
| 1308 | - array(162, 'Palau', 'PW', 'PLW', 1), |
|
| 1309 | - array(163, 'Panama', 'PA', 'PAN', 1), |
|
| 1310 | - array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
| 1311 | - array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
| 1312 | - array(166, 'Peru', 'PE', 'PER', 1), |
|
| 1313 | - array(68, 'Philippines', 'PH', 'PHL', 1), |
|
| 1314 | - array(167, 'Poland', 'PL', 'POL', 1), |
|
| 1315 | - array(168, 'Portugal', 'PT', 'PRT', 2), |
|
| 1316 | - array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
| 1317 | - array(170, 'Qatar', 'QA', 'QAT', 1), |
|
| 1318 | - array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
| 1319 | - array(177, 'Romania', 'RO', 'ROM', 2), |
|
| 1320 | - array(178, 'Russia', 'RU', 'RUS', 1), |
|
| 1321 | - array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
| 1322 | - array(180, 'Samoa', 'WS', 'WSM', 1), |
|
| 1323 | - array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
| 1324 | - array(183, 'San Marino', 'SM', 'SMR', 2), |
|
| 1325 | - array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
| 1326 | - array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
| 1327 | - array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
| 1328 | - array(188, 'Senegal', 'SN', 'SEN', 1), |
|
| 1329 | - array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
| 1330 | - array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
| 1331 | - array(191, 'Singapore', 'SG', 'SGP', 1), |
|
| 1332 | - array(192, 'Syria', 'SY', 'SYR', 1), |
|
| 1333 | - array(193, 'Somalia', 'SO', 'SOM', 1), |
|
| 1334 | - array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
| 1335 | - array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
| 1336 | - array(196, 'Sudan', 'SD', 'SDN', 1), |
|
| 1337 | - array(199, 'Suriname', 'SR', 'SUR', 1), |
|
| 1338 | - array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
| 1339 | - array(201, 'Thailand', 'TH', 'THA', 1), |
|
| 1340 | - array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
| 1341 | - array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
| 1342 | - array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
| 1343 | - array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
| 1344 | - array(207, 'Togo', 'TG', 'TGO', 1), |
|
| 1345 | - array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
| 1346 | - array(209, 'Tonga', 'TO', 'TON', 1), |
|
| 1347 | - array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
| 1348 | - array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
| 1349 | - array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
| 1350 | - array(213, 'Turkey', 'TR', 'TUR', 1), |
|
| 1351 | - array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
| 1352 | - array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
| 1353 | - array(216, 'Uganda', 'UG', 'UGA', 1), |
|
| 1354 | - array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
| 1355 | - array(217, 'Uruguay', 'UY', 'URY', 1), |
|
| 1356 | - array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
| 1357 | - array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
| 1358 | - array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
| 1359 | - array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
| 1360 | - array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
| 1361 | - array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
| 1362 | - array(223, 'Yemen', 'YE', 'YEM', 1), |
|
| 1363 | - array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
| 1364 | - array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
| 1365 | - ); |
|
| 1366 | - $country_iso = 'US'; |
|
| 1367 | - foreach ($old_countries as $country_array) { |
|
| 1368 | - // note: index 0 is the 3.1 country ID |
|
| 1369 | - if ($country_array[0] == $country_id) { |
|
| 1370 | - // note: index 2 is the ISO |
|
| 1371 | - $country_iso = $country_array[2]; |
|
| 1372 | - break; |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - return $country_iso; |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - |
|
| 1379 | - |
|
| 1380 | - /** |
|
| 1381 | - * Gets the ISO3 for the |
|
| 1382 | - * |
|
| 1383 | - * @return string |
|
| 1384 | - */ |
|
| 1385 | - public function get_default_country_iso() |
|
| 1386 | - { |
|
| 1387 | - $old_org_options = get_option('events_organization_settings'); |
|
| 1388 | - $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
| 1389 | - return $iso; |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
| 1396 | - * |
|
| 1397 | - * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
| 1398 | - * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
| 1399 | - * default payment status, the event's default payment status, or |
|
| 1400 | - * the attendee's payment status) required pre-approval. |
|
| 1401 | - * @return string STS_ID for use in 4.1 |
|
| 1402 | - */ |
|
| 1403 | - public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
| 1404 | - { |
|
| 1405 | - // EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
| 1406 | - if ($this_thing_required_pre_approval) { |
|
| 1407 | - return 'RNA'; |
|
| 1408 | - } else { |
|
| 1409 | - $mapping = $default_reg_stati_conversions = array( |
|
| 1410 | - 'Completed' => 'RAP', |
|
| 1411 | - '' => 'RPP', |
|
| 1412 | - 'Incomplete' => 'RPP', |
|
| 1413 | - 'Pending' => 'RAP', |
|
| 1414 | - // stati that only occurred on 3.1 attendees: |
|
| 1415 | - 'Payment Declined' => 'RPP', |
|
| 1416 | - 'Not Completed' => 'RPP', |
|
| 1417 | - 'Cancelled' => 'RPP', |
|
| 1418 | - 'Declined' => 'RPP', |
|
| 1419 | - ); |
|
| 1420 | - } |
|
| 1421 | - return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
| 1428 | - * and sets it as the featured image on the CPT event |
|
| 1429 | - * |
|
| 1430 | - * @param type $old_event |
|
| 1431 | - * @param type $new_cpt_id |
|
| 1432 | - * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
| 1433 | - * @return boolean whether or not we had to do the big job of creating an image attachment |
|
| 1434 | - */ |
|
| 1435 | - public function convert_image_url_to_attachment_and_attach_to_post( |
|
| 1436 | - $guid, |
|
| 1437 | - $new_cpt_id, |
|
| 1438 | - EE_Data_Migration_Script_Stage $migration_stage |
|
| 1439 | - ) { |
|
| 1440 | - $created_attachment_post = false; |
|
| 1441 | - $guid = $this->_get_original_guid($guid); |
|
| 1442 | - if ($guid) { |
|
| 1443 | - // check for an existing attachment post with this guid |
|
| 1444 | - $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
| 1445 | - if (! $attachment_post_id) { |
|
| 1446 | - // post thumbnail with that GUID doesn't exist, we should create one |
|
| 1447 | - $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
| 1448 | - $created_attachment_post = true; |
|
| 1449 | - } |
|
| 1450 | - // double-check we actually have an attachment post |
|
| 1451 | - if ($attachment_post_id) { |
|
| 1452 | - update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
| 1453 | - } else { |
|
| 1454 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1455 | - "Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
| 1456 | - "event_espresso" |
|
| 1457 | - ), $guid, $new_cpt_id, $attachment_post_id)); |
|
| 1458 | - } |
|
| 1459 | - } |
|
| 1460 | - return $created_attachment_post; |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - |
|
| 1464 | - |
|
| 1465 | - /** |
|
| 1466 | - * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
| 1467 | - * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
| 1468 | - * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
| 1469 | - * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
| 1470 | - * exists |
|
| 1471 | - * |
|
| 1472 | - * @param string $guid_in_old_event |
|
| 1473 | - * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
| 1474 | - */ |
|
| 1475 | - private function _get_original_guid($guid_in_old_event) |
|
| 1476 | - { |
|
| 1477 | - $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
| 1478 | - // do a head request to verify the file exists |
|
| 1479 | - $head_response = wp_remote_head($original_guid); |
|
| 1480 | - if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1481 | - return $original_guid; |
|
| 1482 | - } else { |
|
| 1483 | - return $guid_in_old_event; |
|
| 1484 | - } |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - |
|
| 1488 | - |
|
| 1489 | - /** |
|
| 1490 | - * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
| 1491 | - * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
| 1492 | - * thumbnails) |
|
| 1493 | - * |
|
| 1494 | - * @param type $guid |
|
| 1495 | - * @param EE_Data_Migration_Script_Stage $migration_stage |
|
| 1496 | - * @return int |
|
| 1497 | - */ |
|
| 1498 | - private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
| 1499 | - { |
|
| 1500 | - if (! $guid) { |
|
| 1501 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1502 | - "Cannot create image attachment for a blank GUID!", |
|
| 1503 | - "event_espresso" |
|
| 1504 | - ))); |
|
| 1505 | - return 0; |
|
| 1506 | - } |
|
| 1507 | - $wp_filetype = wp_check_filetype(basename($guid), null); |
|
| 1508 | - $wp_upload_dir = wp_upload_dir(); |
|
| 1509 | - // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
| 1510 | - if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
| 1511 | - // image is located remotely. download it and place it in the uploads directory |
|
| 1512 | - if (! is_readable($guid)) { |
|
| 1513 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1514 | - "Could not create image attachment from non-existent file: %s", |
|
| 1515 | - "event_espresso" |
|
| 1516 | - ), $guid)); |
|
| 1517 | - return 0; |
|
| 1518 | - } |
|
| 1519 | - $contents = file_get_contents($guid); |
|
| 1520 | - if ($contents === false) { |
|
| 1521 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1522 | - "Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
| 1523 | - "event_espresso" |
|
| 1524 | - ), $guid)); |
|
| 1525 | - return false; |
|
| 1526 | - } |
|
| 1527 | - $local_filepath = $wp_upload_dir['path'] . '/' . basename($guid); |
|
| 1528 | - $savefile = fopen($local_filepath, 'w'); |
|
| 1529 | - fwrite($savefile, $contents); |
|
| 1530 | - fclose($savefile); |
|
| 1531 | - $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
| 1532 | - } else { |
|
| 1533 | - $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
| 1534 | - } |
|
| 1535 | - $attachment = array( |
|
| 1536 | - 'guid' => $guid, |
|
| 1537 | - 'post_mime_type' => $wp_filetype['type'], |
|
| 1538 | - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
| 1539 | - 'post_content' => '', |
|
| 1540 | - 'post_status' => 'inherit', |
|
| 1541 | - ); |
|
| 1542 | - $attach_id = wp_insert_attachment($attachment, $guid); |
|
| 1543 | - if (! $attach_id) { |
|
| 1544 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1545 | - "Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
| 1546 | - "event_espresso" |
|
| 1547 | - ), $guid, $this->_json_encode($attachment))); |
|
| 1548 | - return $attach_id; |
|
| 1549 | - } |
|
| 1550 | - // you must first include the image.php file |
|
| 1551 | - // for the function wp_generate_attachment_metadata() to work |
|
| 1552 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1553 | - $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
| 1554 | - if (! $attach_data) { |
|
| 1555 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1556 | - "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
| 1557 | - "event_espresso" |
|
| 1558 | - ), $attach_id, $local_filepath, $guid)); |
|
| 1559 | - return $attach_id; |
|
| 1560 | - } |
|
| 1561 | - $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1562 | - if (! $metadata_save_result) { |
|
| 1563 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1564 | - "Could not update attachment metadata for attachment %d with data %s", |
|
| 1565 | - "event_espresso" |
|
| 1566 | - ), $attach_id, $this->_json_encode($attach_data))); |
|
| 1567 | - } |
|
| 1568 | - return $attach_id; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - |
|
| 1572 | - |
|
| 1573 | - /** |
|
| 1574 | - * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
| 1575 | - * and returns its ID. |
|
| 1576 | - * |
|
| 1577 | - * @global type $wpdb |
|
| 1578 | - * @param string $guid |
|
| 1579 | - * @return int |
|
| 1580 | - */ |
|
| 1581 | - private function _get_image_attachment_id_by_GUID($guid) |
|
| 1582 | - { |
|
| 1583 | - global $wpdb; |
|
| 1584 | - $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
| 1585 | - return $attachment_id; |
|
| 1586 | - } |
|
| 1587 | - |
|
| 1588 | - |
|
| 1589 | - |
|
| 1590 | - /** |
|
| 1591 | - * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
| 1592 | - * (and optionally a timezone; if none is given, the wp default is used) |
|
| 1593 | - * |
|
| 1594 | - * @param EE_Data_Migration_Script_base $stage |
|
| 1595 | - * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
| 1596 | - * UTC time for |
|
| 1597 | - * @param string $DATETIME_string |
|
| 1598 | - * @param string $timezone |
|
| 1599 | - * @return string |
|
| 1600 | - */ |
|
| 1601 | - public function convert_date_string_to_utc( |
|
| 1602 | - EE_Data_Migration_Script_Stage $stage, |
|
| 1603 | - $row_of_data, |
|
| 1604 | - $DATETIME_string, |
|
| 1605 | - $timezone = null |
|
| 1606 | - ) { |
|
| 1607 | - $original_tz = $timezone; |
|
| 1608 | - if (! $timezone) { |
|
| 1609 | - $timezone = $this->_get_wp_timezone(); |
|
| 1610 | - } |
|
| 1611 | - if (! $timezone) { |
|
| 1612 | - $stage->add_error(sprintf( |
|
| 1613 | - esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
|
| 1614 | - $original_tz, |
|
| 1615 | - $row_of_data |
|
| 1616 | - )); |
|
| 1617 | - $timezone = 'UTC'; |
|
| 1618 | - } |
|
| 1619 | - try { |
|
| 1620 | - $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
| 1621 | - EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC')); |
|
| 1622 | - } catch (Exception $e) { |
|
| 1623 | - $stage->add_error(sprintf(esc_html__( |
|
| 1624 | - "Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
| 1625 | - "event_espresso" |
|
| 1626 | - ), $DATETIME_string, $timezone)); |
|
| 1627 | - $date_obj = new DateTime(); |
|
| 1628 | - } |
|
| 1629 | - return $date_obj->format('Y-m-d H:i:s'); |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - /** |
|
| 1635 | - * Gets the default timezone string from wordpress (even if they set a gmt offset) |
|
| 1636 | - * |
|
| 1637 | - * @return string |
|
| 1638 | - */ |
|
| 1639 | - private function _get_wp_timezone() |
|
| 1640 | - { |
|
| 1641 | - $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
| 1642 | - // if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
| 1643 | - if (empty($timezone)) { |
|
| 1644 | - // let's get a the WordPress UTC offset |
|
| 1645 | - $offset = get_option('gmt_offset'); |
|
| 1646 | - $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
| 1647 | - } |
|
| 1648 | - return $timezone; |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - |
|
| 1652 | - |
|
| 1653 | - /** |
|
| 1654 | - * Gets the wordpress timezone string from a UTC offset |
|
| 1655 | - * |
|
| 1656 | - * @param int $offset |
|
| 1657 | - * @return boolean |
|
| 1658 | - */ |
|
| 1659 | - private function timezone_convert_to_string_from_offset($offset) |
|
| 1660 | - { |
|
| 1661 | - // shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did not work as expected - its not reliable |
|
| 1662 | - $offset *= 3600; // convert hour offset to seconds |
|
| 1663 | - $abbrarray = timezone_abbreviations_list(); |
|
| 1664 | - foreach ($abbrarray as $abbr) { |
|
| 1665 | - foreach ($abbr as $city) { |
|
| 1666 | - if ($city['offset'] == $offset) { |
|
| 1667 | - return $city['timezone_id']; |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - } |
|
| 1671 | - return false; |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - |
|
| 1675 | - |
|
| 1676 | - public function migration_page_hooks() |
|
| 1677 | - { |
|
| 1678 | - add_filter( |
|
| 1679 | - 'FHEE__ee_migration_page__header', |
|
| 1680 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1681 | - 10, |
|
| 1682 | - 3 |
|
| 1683 | - ); |
|
| 1684 | - add_filter( |
|
| 1685 | - 'FHEE__ee_migration_page__p_after_header', |
|
| 1686 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1687 | - 10, |
|
| 1688 | - 2 |
|
| 1689 | - ); |
|
| 1690 | - add_filter( |
|
| 1691 | - 'FHEE__ee_migration_page__option_1_main', |
|
| 1692 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1693 | - 10, |
|
| 1694 | - 3 |
|
| 1695 | - ); |
|
| 1696 | - add_filter( |
|
| 1697 | - 'FHEE__ee_migration_page__option_1_button_text', |
|
| 1698 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1699 | - 10, |
|
| 1700 | - 3 |
|
| 1701 | - ); |
|
| 1702 | - add_action( |
|
| 1703 | - 'AHEE__ee_migration_page__option_1_extra_details', |
|
| 1704 | - array($this, '_migration_page_hook_option_1_extra_details'), |
|
| 1705 | - 10, |
|
| 1706 | - 3 |
|
| 1707 | - ); |
|
| 1708 | - add_filter( |
|
| 1709 | - 'FHEE__ee_migration_page__option_2_main', |
|
| 1710 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1711 | - 10, |
|
| 1712 | - 4 |
|
| 1713 | - ); |
|
| 1714 | - add_filter( |
|
| 1715 | - 'FHEE__ee_migration_page__option_2_button_text', |
|
| 1716 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1717 | - 10, |
|
| 1718 | - 2 |
|
| 1719 | - ); |
|
| 1720 | - add_filter( |
|
| 1721 | - 'FHEE__ee_migration_page__option_2_details', |
|
| 1722 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1723 | - 10, |
|
| 1724 | - 2 |
|
| 1725 | - ); |
|
| 1726 | - add_action( |
|
| 1727 | - 'AHEE__ee_migration_page__after_migration_options_table', |
|
| 1728 | - array($this, '_migration_page_hook_after_migration_options_table') |
|
| 1729 | - ); |
|
| 1730 | - add_filter( |
|
| 1731 | - 'FHEE__ee_migration_page__done_migration_header', |
|
| 1732 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1733 | - 10, |
|
| 1734 | - 2 |
|
| 1735 | - ); |
|
| 1736 | - add_filter( |
|
| 1737 | - 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 1738 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1739 | - 10, |
|
| 1740 | - 2 |
|
| 1741 | - ); |
|
| 1742 | - add_filter( |
|
| 1743 | - 'FHEE__ee_migration_page__migration_options_template', |
|
| 1744 | - array($this,'use_migration_options_from_ee3_template') |
|
| 1745 | - ); |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - |
|
| 1749 | - |
|
| 1750 | - public function _migrate_page_hook_simplify_version_strings( |
|
| 1751 | - $old_content, |
|
| 1752 | - $current_db_state, |
|
| 1753 | - $next_db_state, |
|
| 1754 | - $ultimate_db_state = null |
|
| 1755 | - ) { |
|
| 1756 | - return str_replace( |
|
| 1757 | - array($current_db_state, $next_db_state, $ultimate_db_state), |
|
| 1758 | - array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
| 1759 | - $old_content |
|
| 1760 | - ); |
|
| 1761 | - } |
|
| 1762 | - |
|
| 1763 | - |
|
| 1764 | - |
|
| 1765 | - public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
| 1766 | - { |
|
| 1767 | - return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
| 1768 | - } |
|
| 1769 | - |
|
| 1770 | - |
|
| 1771 | - |
|
| 1772 | - public function _migration_page_hook_option_1_extra_details() |
|
| 1773 | - { |
|
| 1774 | - ?> |
|
| 1072 | + if (! $state) { |
|
| 1073 | + // insert a new one then |
|
| 1074 | + $cols_n_values = array( |
|
| 1075 | + 'CNT_ISO' => $country_iso, |
|
| 1076 | + 'STA_abbrev' => substr($state_name, 0, 6), |
|
| 1077 | + 'STA_name' => $state_name, |
|
| 1078 | + 'STA_active' => true, |
|
| 1079 | + ); |
|
| 1080 | + $data_types = array( |
|
| 1081 | + '%s',// CNT_ISO |
|
| 1082 | + '%s',// STA_abbrev |
|
| 1083 | + '%s',// STA_name |
|
| 1084 | + '%d',// STA_active |
|
| 1085 | + ); |
|
| 1086 | + $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
| 1087 | + if (! $success) { |
|
| 1088 | + throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
| 1089 | + 'N/A', |
|
| 1090 | + array('state' => $state_name, 'country_id' => $country_name), |
|
| 1091 | + $state_table, |
|
| 1092 | + $cols_n_values, |
|
| 1093 | + $data_types |
|
| 1094 | + )); |
|
| 1095 | + } |
|
| 1096 | + $state = $cols_n_values; |
|
| 1097 | + $state['STA_ID'] = $wpdb->insert_id; |
|
| 1098 | + } |
|
| 1099 | + return $state; |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
| 1106 | + * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
| 1107 | + * |
|
| 1108 | + * @param type $timeString |
|
| 1109 | + * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
| 1110 | + * with leading zeros) |
|
| 1111 | + */ |
|
| 1112 | + public function convertTimeFromAMPM($timeString) |
|
| 1113 | + { |
|
| 1114 | + $matches = array(); |
|
| 1115 | + preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
| 1116 | + if (! $matches || count($matches) < 3) { |
|
| 1117 | + $hour = '00'; |
|
| 1118 | + $minutes = '00'; |
|
| 1119 | + } else { |
|
| 1120 | + $hour = intval($matches[1]); |
|
| 1121 | + $minutes = $matches[2]; |
|
| 1122 | + } |
|
| 1123 | + if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
| 1124 | + $hour = intval($hour) + 12; |
|
| 1125 | + } |
|
| 1126 | + $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
| 1127 | + $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
| 1128 | + return "$hour:$minutes"; |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * Gets the ISO3 fora country given its 3.1 country ID. |
|
| 1135 | + * |
|
| 1136 | + * @param int $country_id |
|
| 1137 | + * @return string the country's ISO3 code |
|
| 1138 | + */ |
|
| 1139 | + public function get_iso_from_3_1_country_id($country_id) |
|
| 1140 | + { |
|
| 1141 | + $old_countries = array( |
|
| 1142 | + array(64, 'United States', 'US', 'USA', 1), |
|
| 1143 | + array(15, 'Australia', 'AU', 'AUS', 1), |
|
| 1144 | + array(39, 'Canada', 'CA', 'CAN', 1), |
|
| 1145 | + array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
| 1146 | + array(70, 'France', 'FR', 'FRA', 2), |
|
| 1147 | + array(111, 'Italy', 'IT', 'ITA', 2), |
|
| 1148 | + array(63, 'Spain', 'ES', 'ESP', 2), |
|
| 1149 | + array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
| 1150 | + array(2, 'Albania', 'AL', 'ALB', 1), |
|
| 1151 | + array(3, 'Germany', 'DE', 'DEU', 2), |
|
| 1152 | + array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
| 1153 | + array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
| 1154 | + array(197, 'Sweden', 'SE', 'SWE', 1), |
|
| 1155 | + array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
| 1156 | + array(4, 'Andorra', 'AD', 'AND', 2), |
|
| 1157 | + array(5, 'Angola', 'AO', 'AGO', 1), |
|
| 1158 | + array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
| 1159 | + array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
| 1160 | + array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
| 1161 | + array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
| 1162 | + array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
| 1163 | + array(12, 'Argentina', 'AR', 'ARG', 1), |
|
| 1164 | + array(13, 'Armenia', 'AM', 'ARM', 1), |
|
| 1165 | + array(14, 'Aruba', 'AW', 'ABW', 1), |
|
| 1166 | + array(16, 'Austria', 'AT', 'AUT', 2), |
|
| 1167 | + array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
| 1168 | + array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
| 1169 | + array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
| 1170 | + array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
| 1171 | + array(21, 'Barbados', 'BB', 'BRB', 1), |
|
| 1172 | + array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
| 1173 | + array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
| 1174 | + array(24, 'Benin', 'BJ', 'BEN', 1), |
|
| 1175 | + array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
| 1176 | + array(26, 'Belarus', 'BY', 'BLR', 1), |
|
| 1177 | + array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
| 1178 | + array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
| 1179 | + array(29, 'Botswana', 'BW', 'BWA', 1), |
|
| 1180 | + array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
| 1181 | + array(30, 'Brazil', 'BR', 'BRA', 1), |
|
| 1182 | + array(31, 'Brunei', 'BN', 'BRN', 1), |
|
| 1183 | + array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
| 1184 | + array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
| 1185 | + array(34, 'Burundi', 'BI', 'BDI', 1), |
|
| 1186 | + array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
| 1187 | + array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
| 1188 | + array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
| 1189 | + array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
| 1190 | + array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
| 1191 | + array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
| 1192 | + array(40, 'Chad', 'TD', 'TCD', 1), |
|
| 1193 | + array(41, 'Chile', 'CL', 'CHL', 1), |
|
| 1194 | + array(42, 'China', 'CN', 'CHN', 1), |
|
| 1195 | + array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
| 1196 | + array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
| 1197 | + array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
| 1198 | + array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
| 1199 | + array(44, 'Colombia', 'CO', 'COL', 1), |
|
| 1200 | + array(45, 'Comoros', 'KM', 'COM', 1), |
|
| 1201 | + array(46, 'Congo', 'CG', 'COG', 1), |
|
| 1202 | + array(47, 'North Korea', 'KP', 'PRK', 1), |
|
| 1203 | + array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
| 1204 | + array(51, 'Croatia', 'HR', 'HRV', 1), |
|
| 1205 | + array(52, 'Cuba', 'CU', 'CUB', 1), |
|
| 1206 | + array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
| 1207 | + array(53, 'Denmark', 'DK', 'DNK', 1), |
|
| 1208 | + array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
| 1209 | + array(55, 'Dominica', 'DM', 'DMA', 1), |
|
| 1210 | + array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
| 1211 | + array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
| 1212 | + array(57, 'Egypt', 'EG', 'EGY', 1), |
|
| 1213 | + array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
| 1214 | + array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
| 1215 | + array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
| 1216 | + array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
| 1217 | + array(65, 'Estonia', 'EE', 'EST', 2), |
|
| 1218 | + array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
| 1219 | + array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
| 1220 | + array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
| 1221 | + array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
| 1222 | + array(69, 'Finland', 'FI', 'FIN', 2), |
|
| 1223 | + array(71, 'Gabon', 'GA', 'GAB', 1), |
|
| 1224 | + array(72, 'Gambia', 'GM', 'GMB', 1), |
|
| 1225 | + array(73, 'Georgia', 'GE', 'GEO', 1), |
|
| 1226 | + array(74, 'Ghana', 'GH', 'GHA', 1), |
|
| 1227 | + array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
| 1228 | + array(76, 'Greece', 'GR', 'GRC', 2), |
|
| 1229 | + array(77, 'Grenada', 'GD', 'GRD', 1), |
|
| 1230 | + array(78, 'Greenland', 'GL', 'GRL', 1), |
|
| 1231 | + array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
| 1232 | + array(80, 'Guam', 'GU', 'GUM', 1), |
|
| 1233 | + array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
| 1234 | + array(82, 'Guinea', 'GN', 'GIN', 1), |
|
| 1235 | + array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
| 1236 | + array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
| 1237 | + array(85, 'Guyana', 'GY', 'GUY', 1), |
|
| 1238 | + array(86, 'Haiti', 'HT', 'HTI', 1), |
|
| 1239 | + array(88, 'Honduras', 'HN', 'HND', 1), |
|
| 1240 | + array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
| 1241 | + array(90, 'Hungary', 'HU', 'HUN', 1), |
|
| 1242 | + array(91, 'India', 'IN', 'IND', 1), |
|
| 1243 | + array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
| 1244 | + array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
| 1245 | + array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
| 1246 | + array(94, 'Iran', 'IR', 'IRN', 1), |
|
| 1247 | + array(95, 'Ireland', 'IE', 'IRL', 2), |
|
| 1248 | + array(97, 'Iceland', 'IS', 'ISL', 1), |
|
| 1249 | + array(110, 'Israel', 'IL', 'ISR', 1), |
|
| 1250 | + array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
| 1251 | + array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
| 1252 | + array(113, 'Japan', 'JP', 'JPN', 1), |
|
| 1253 | + array(114, 'Jordan', 'JO', 'JOR', 1), |
|
| 1254 | + array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
| 1255 | + array(116, 'Kenya', 'KE', 'KEN', 1), |
|
| 1256 | + array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
| 1257 | + array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
| 1258 | + array(48, 'South Korea', 'KR', 'KOR', 1), |
|
| 1259 | + array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
| 1260 | + // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
| 1261 | + array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
| 1262 | + array(120, 'Laos', 'LA', 'LAO', 1), |
|
| 1263 | + array(121, 'Latvia', 'LV', 'LVA', 2), |
|
| 1264 | + array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
| 1265 | + array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
| 1266 | + array(124, 'Liberia', 'LR', 'LBR', 1), |
|
| 1267 | + array(125, 'Libya', 'LY', 'LBY', 1), |
|
| 1268 | + array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
| 1269 | + array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
| 1270 | + array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
| 1271 | + array(129, 'Macao', 'MO', 'MAC', 1), |
|
| 1272 | + array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
| 1273 | + array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
| 1274 | + array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
| 1275 | + array(133, 'Malawi', 'MW', 'MWI', 1), |
|
| 1276 | + array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
| 1277 | + array(135, 'Mali', 'ML', 'MLI', 1), |
|
| 1278 | + array(136, 'Malta', 'MT', 'MLT', 2), |
|
| 1279 | + array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
| 1280 | + array(137, 'Morocco', 'MA', 'MAR', 1), |
|
| 1281 | + array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
| 1282 | + array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
| 1283 | + array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
| 1284 | + array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
| 1285 | + array(141, 'Mayote', 'YT', 'MYT', 2), |
|
| 1286 | + array(142, 'Mexico', 'MX', 'MEX', 1), |
|
| 1287 | + array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
| 1288 | + array(144, 'Moldova', 'MD', 'MDA', 1), |
|
| 1289 | + array(145, 'Monaco', 'MC', 'MCO', 2), |
|
| 1290 | + array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
| 1291 | + array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
| 1292 | + array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
| 1293 | + array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
| 1294 | + array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
| 1295 | + array(150, 'Namibia', 'NA', 'NAM', 1), |
|
| 1296 | + array(151, 'Nauru', 'NR', 'NRU', 1), |
|
| 1297 | + array(152, 'Nepal', 'NP', 'NPL', 1), |
|
| 1298 | + array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
| 1299 | + array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
| 1300 | + array(154, 'Niger', 'NE', 'NER', 1), |
|
| 1301 | + array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
| 1302 | + array(156, 'Niue', 'NU', 'NIU', 1), |
|
| 1303 | + array(157, 'Norway', 'NO', 'NOR', 1), |
|
| 1304 | + array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
| 1305 | + array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
| 1306 | + array(160, 'Oman', 'OM', 'OMN', 1), |
|
| 1307 | + array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
| 1308 | + array(162, 'Palau', 'PW', 'PLW', 1), |
|
| 1309 | + array(163, 'Panama', 'PA', 'PAN', 1), |
|
| 1310 | + array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
| 1311 | + array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
| 1312 | + array(166, 'Peru', 'PE', 'PER', 1), |
|
| 1313 | + array(68, 'Philippines', 'PH', 'PHL', 1), |
|
| 1314 | + array(167, 'Poland', 'PL', 'POL', 1), |
|
| 1315 | + array(168, 'Portugal', 'PT', 'PRT', 2), |
|
| 1316 | + array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
| 1317 | + array(170, 'Qatar', 'QA', 'QAT', 1), |
|
| 1318 | + array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
| 1319 | + array(177, 'Romania', 'RO', 'ROM', 2), |
|
| 1320 | + array(178, 'Russia', 'RU', 'RUS', 1), |
|
| 1321 | + array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
| 1322 | + array(180, 'Samoa', 'WS', 'WSM', 1), |
|
| 1323 | + array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
| 1324 | + array(183, 'San Marino', 'SM', 'SMR', 2), |
|
| 1325 | + array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
| 1326 | + array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
| 1327 | + array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
| 1328 | + array(188, 'Senegal', 'SN', 'SEN', 1), |
|
| 1329 | + array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
| 1330 | + array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
| 1331 | + array(191, 'Singapore', 'SG', 'SGP', 1), |
|
| 1332 | + array(192, 'Syria', 'SY', 'SYR', 1), |
|
| 1333 | + array(193, 'Somalia', 'SO', 'SOM', 1), |
|
| 1334 | + array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
| 1335 | + array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
| 1336 | + array(196, 'Sudan', 'SD', 'SDN', 1), |
|
| 1337 | + array(199, 'Suriname', 'SR', 'SUR', 1), |
|
| 1338 | + array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
| 1339 | + array(201, 'Thailand', 'TH', 'THA', 1), |
|
| 1340 | + array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
| 1341 | + array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
| 1342 | + array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
| 1343 | + array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
| 1344 | + array(207, 'Togo', 'TG', 'TGO', 1), |
|
| 1345 | + array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
| 1346 | + array(209, 'Tonga', 'TO', 'TON', 1), |
|
| 1347 | + array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
| 1348 | + array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
| 1349 | + array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
| 1350 | + array(213, 'Turkey', 'TR', 'TUR', 1), |
|
| 1351 | + array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
| 1352 | + array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
| 1353 | + array(216, 'Uganda', 'UG', 'UGA', 1), |
|
| 1354 | + array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
| 1355 | + array(217, 'Uruguay', 'UY', 'URY', 1), |
|
| 1356 | + array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
| 1357 | + array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
| 1358 | + array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
| 1359 | + array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
| 1360 | + array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
| 1361 | + array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
| 1362 | + array(223, 'Yemen', 'YE', 'YEM', 1), |
|
| 1363 | + array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
| 1364 | + array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
| 1365 | + ); |
|
| 1366 | + $country_iso = 'US'; |
|
| 1367 | + foreach ($old_countries as $country_array) { |
|
| 1368 | + // note: index 0 is the 3.1 country ID |
|
| 1369 | + if ($country_array[0] == $country_id) { |
|
| 1370 | + // note: index 2 is the ISO |
|
| 1371 | + $country_iso = $country_array[2]; |
|
| 1372 | + break; |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + return $country_iso; |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + |
|
| 1379 | + |
|
| 1380 | + /** |
|
| 1381 | + * Gets the ISO3 for the |
|
| 1382 | + * |
|
| 1383 | + * @return string |
|
| 1384 | + */ |
|
| 1385 | + public function get_default_country_iso() |
|
| 1386 | + { |
|
| 1387 | + $old_org_options = get_option('events_organization_settings'); |
|
| 1388 | + $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
| 1389 | + return $iso; |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
| 1396 | + * |
|
| 1397 | + * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
| 1398 | + * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
| 1399 | + * default payment status, the event's default payment status, or |
|
| 1400 | + * the attendee's payment status) required pre-approval. |
|
| 1401 | + * @return string STS_ID for use in 4.1 |
|
| 1402 | + */ |
|
| 1403 | + public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
| 1404 | + { |
|
| 1405 | + // EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
| 1406 | + if ($this_thing_required_pre_approval) { |
|
| 1407 | + return 'RNA'; |
|
| 1408 | + } else { |
|
| 1409 | + $mapping = $default_reg_stati_conversions = array( |
|
| 1410 | + 'Completed' => 'RAP', |
|
| 1411 | + '' => 'RPP', |
|
| 1412 | + 'Incomplete' => 'RPP', |
|
| 1413 | + 'Pending' => 'RAP', |
|
| 1414 | + // stati that only occurred on 3.1 attendees: |
|
| 1415 | + 'Payment Declined' => 'RPP', |
|
| 1416 | + 'Not Completed' => 'RPP', |
|
| 1417 | + 'Cancelled' => 'RPP', |
|
| 1418 | + 'Declined' => 'RPP', |
|
| 1419 | + ); |
|
| 1420 | + } |
|
| 1421 | + return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
| 1428 | + * and sets it as the featured image on the CPT event |
|
| 1429 | + * |
|
| 1430 | + * @param type $old_event |
|
| 1431 | + * @param type $new_cpt_id |
|
| 1432 | + * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
| 1433 | + * @return boolean whether or not we had to do the big job of creating an image attachment |
|
| 1434 | + */ |
|
| 1435 | + public function convert_image_url_to_attachment_and_attach_to_post( |
|
| 1436 | + $guid, |
|
| 1437 | + $new_cpt_id, |
|
| 1438 | + EE_Data_Migration_Script_Stage $migration_stage |
|
| 1439 | + ) { |
|
| 1440 | + $created_attachment_post = false; |
|
| 1441 | + $guid = $this->_get_original_guid($guid); |
|
| 1442 | + if ($guid) { |
|
| 1443 | + // check for an existing attachment post with this guid |
|
| 1444 | + $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
| 1445 | + if (! $attachment_post_id) { |
|
| 1446 | + // post thumbnail with that GUID doesn't exist, we should create one |
|
| 1447 | + $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
| 1448 | + $created_attachment_post = true; |
|
| 1449 | + } |
|
| 1450 | + // double-check we actually have an attachment post |
|
| 1451 | + if ($attachment_post_id) { |
|
| 1452 | + update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
| 1453 | + } else { |
|
| 1454 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1455 | + "Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
| 1456 | + "event_espresso" |
|
| 1457 | + ), $guid, $new_cpt_id, $attachment_post_id)); |
|
| 1458 | + } |
|
| 1459 | + } |
|
| 1460 | + return $created_attachment_post; |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + |
|
| 1464 | + |
|
| 1465 | + /** |
|
| 1466 | + * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
| 1467 | + * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
| 1468 | + * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
| 1469 | + * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
| 1470 | + * exists |
|
| 1471 | + * |
|
| 1472 | + * @param string $guid_in_old_event |
|
| 1473 | + * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
| 1474 | + */ |
|
| 1475 | + private function _get_original_guid($guid_in_old_event) |
|
| 1476 | + { |
|
| 1477 | + $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
| 1478 | + // do a head request to verify the file exists |
|
| 1479 | + $head_response = wp_remote_head($original_guid); |
|
| 1480 | + if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1481 | + return $original_guid; |
|
| 1482 | + } else { |
|
| 1483 | + return $guid_in_old_event; |
|
| 1484 | + } |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + |
|
| 1488 | + |
|
| 1489 | + /** |
|
| 1490 | + * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
| 1491 | + * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
| 1492 | + * thumbnails) |
|
| 1493 | + * |
|
| 1494 | + * @param type $guid |
|
| 1495 | + * @param EE_Data_Migration_Script_Stage $migration_stage |
|
| 1496 | + * @return int |
|
| 1497 | + */ |
|
| 1498 | + private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
| 1499 | + { |
|
| 1500 | + if (! $guid) { |
|
| 1501 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1502 | + "Cannot create image attachment for a blank GUID!", |
|
| 1503 | + "event_espresso" |
|
| 1504 | + ))); |
|
| 1505 | + return 0; |
|
| 1506 | + } |
|
| 1507 | + $wp_filetype = wp_check_filetype(basename($guid), null); |
|
| 1508 | + $wp_upload_dir = wp_upload_dir(); |
|
| 1509 | + // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
| 1510 | + if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
| 1511 | + // image is located remotely. download it and place it in the uploads directory |
|
| 1512 | + if (! is_readable($guid)) { |
|
| 1513 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1514 | + "Could not create image attachment from non-existent file: %s", |
|
| 1515 | + "event_espresso" |
|
| 1516 | + ), $guid)); |
|
| 1517 | + return 0; |
|
| 1518 | + } |
|
| 1519 | + $contents = file_get_contents($guid); |
|
| 1520 | + if ($contents === false) { |
|
| 1521 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1522 | + "Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
| 1523 | + "event_espresso" |
|
| 1524 | + ), $guid)); |
|
| 1525 | + return false; |
|
| 1526 | + } |
|
| 1527 | + $local_filepath = $wp_upload_dir['path'] . '/' . basename($guid); |
|
| 1528 | + $savefile = fopen($local_filepath, 'w'); |
|
| 1529 | + fwrite($savefile, $contents); |
|
| 1530 | + fclose($savefile); |
|
| 1531 | + $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
| 1532 | + } else { |
|
| 1533 | + $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
| 1534 | + } |
|
| 1535 | + $attachment = array( |
|
| 1536 | + 'guid' => $guid, |
|
| 1537 | + 'post_mime_type' => $wp_filetype['type'], |
|
| 1538 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
| 1539 | + 'post_content' => '', |
|
| 1540 | + 'post_status' => 'inherit', |
|
| 1541 | + ); |
|
| 1542 | + $attach_id = wp_insert_attachment($attachment, $guid); |
|
| 1543 | + if (! $attach_id) { |
|
| 1544 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1545 | + "Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
| 1546 | + "event_espresso" |
|
| 1547 | + ), $guid, $this->_json_encode($attachment))); |
|
| 1548 | + return $attach_id; |
|
| 1549 | + } |
|
| 1550 | + // you must first include the image.php file |
|
| 1551 | + // for the function wp_generate_attachment_metadata() to work |
|
| 1552 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1553 | + $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
| 1554 | + if (! $attach_data) { |
|
| 1555 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1556 | + "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
| 1557 | + "event_espresso" |
|
| 1558 | + ), $attach_id, $local_filepath, $guid)); |
|
| 1559 | + return $attach_id; |
|
| 1560 | + } |
|
| 1561 | + $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1562 | + if (! $metadata_save_result) { |
|
| 1563 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1564 | + "Could not update attachment metadata for attachment %d with data %s", |
|
| 1565 | + "event_espresso" |
|
| 1566 | + ), $attach_id, $this->_json_encode($attach_data))); |
|
| 1567 | + } |
|
| 1568 | + return $attach_id; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + |
|
| 1572 | + |
|
| 1573 | + /** |
|
| 1574 | + * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
| 1575 | + * and returns its ID. |
|
| 1576 | + * |
|
| 1577 | + * @global type $wpdb |
|
| 1578 | + * @param string $guid |
|
| 1579 | + * @return int |
|
| 1580 | + */ |
|
| 1581 | + private function _get_image_attachment_id_by_GUID($guid) |
|
| 1582 | + { |
|
| 1583 | + global $wpdb; |
|
| 1584 | + $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
| 1585 | + return $attachment_id; |
|
| 1586 | + } |
|
| 1587 | + |
|
| 1588 | + |
|
| 1589 | + |
|
| 1590 | + /** |
|
| 1591 | + * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
| 1592 | + * (and optionally a timezone; if none is given, the wp default is used) |
|
| 1593 | + * |
|
| 1594 | + * @param EE_Data_Migration_Script_base $stage |
|
| 1595 | + * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
| 1596 | + * UTC time for |
|
| 1597 | + * @param string $DATETIME_string |
|
| 1598 | + * @param string $timezone |
|
| 1599 | + * @return string |
|
| 1600 | + */ |
|
| 1601 | + public function convert_date_string_to_utc( |
|
| 1602 | + EE_Data_Migration_Script_Stage $stage, |
|
| 1603 | + $row_of_data, |
|
| 1604 | + $DATETIME_string, |
|
| 1605 | + $timezone = null |
|
| 1606 | + ) { |
|
| 1607 | + $original_tz = $timezone; |
|
| 1608 | + if (! $timezone) { |
|
| 1609 | + $timezone = $this->_get_wp_timezone(); |
|
| 1610 | + } |
|
| 1611 | + if (! $timezone) { |
|
| 1612 | + $stage->add_error(sprintf( |
|
| 1613 | + esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
|
| 1614 | + $original_tz, |
|
| 1615 | + $row_of_data |
|
| 1616 | + )); |
|
| 1617 | + $timezone = 'UTC'; |
|
| 1618 | + } |
|
| 1619 | + try { |
|
| 1620 | + $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
| 1621 | + EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC')); |
|
| 1622 | + } catch (Exception $e) { |
|
| 1623 | + $stage->add_error(sprintf(esc_html__( |
|
| 1624 | + "Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
| 1625 | + "event_espresso" |
|
| 1626 | + ), $DATETIME_string, $timezone)); |
|
| 1627 | + $date_obj = new DateTime(); |
|
| 1628 | + } |
|
| 1629 | + return $date_obj->format('Y-m-d H:i:s'); |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + |
|
| 1633 | + |
|
| 1634 | + /** |
|
| 1635 | + * Gets the default timezone string from wordpress (even if they set a gmt offset) |
|
| 1636 | + * |
|
| 1637 | + * @return string |
|
| 1638 | + */ |
|
| 1639 | + private function _get_wp_timezone() |
|
| 1640 | + { |
|
| 1641 | + $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
| 1642 | + // if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
| 1643 | + if (empty($timezone)) { |
|
| 1644 | + // let's get a the WordPress UTC offset |
|
| 1645 | + $offset = get_option('gmt_offset'); |
|
| 1646 | + $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
| 1647 | + } |
|
| 1648 | + return $timezone; |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + |
|
| 1652 | + |
|
| 1653 | + /** |
|
| 1654 | + * Gets the wordpress timezone string from a UTC offset |
|
| 1655 | + * |
|
| 1656 | + * @param int $offset |
|
| 1657 | + * @return boolean |
|
| 1658 | + */ |
|
| 1659 | + private function timezone_convert_to_string_from_offset($offset) |
|
| 1660 | + { |
|
| 1661 | + // shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did not work as expected - its not reliable |
|
| 1662 | + $offset *= 3600; // convert hour offset to seconds |
|
| 1663 | + $abbrarray = timezone_abbreviations_list(); |
|
| 1664 | + foreach ($abbrarray as $abbr) { |
|
| 1665 | + foreach ($abbr as $city) { |
|
| 1666 | + if ($city['offset'] == $offset) { |
|
| 1667 | + return $city['timezone_id']; |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + } |
|
| 1671 | + return false; |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + |
|
| 1675 | + |
|
| 1676 | + public function migration_page_hooks() |
|
| 1677 | + { |
|
| 1678 | + add_filter( |
|
| 1679 | + 'FHEE__ee_migration_page__header', |
|
| 1680 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1681 | + 10, |
|
| 1682 | + 3 |
|
| 1683 | + ); |
|
| 1684 | + add_filter( |
|
| 1685 | + 'FHEE__ee_migration_page__p_after_header', |
|
| 1686 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1687 | + 10, |
|
| 1688 | + 2 |
|
| 1689 | + ); |
|
| 1690 | + add_filter( |
|
| 1691 | + 'FHEE__ee_migration_page__option_1_main', |
|
| 1692 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1693 | + 10, |
|
| 1694 | + 3 |
|
| 1695 | + ); |
|
| 1696 | + add_filter( |
|
| 1697 | + 'FHEE__ee_migration_page__option_1_button_text', |
|
| 1698 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1699 | + 10, |
|
| 1700 | + 3 |
|
| 1701 | + ); |
|
| 1702 | + add_action( |
|
| 1703 | + 'AHEE__ee_migration_page__option_1_extra_details', |
|
| 1704 | + array($this, '_migration_page_hook_option_1_extra_details'), |
|
| 1705 | + 10, |
|
| 1706 | + 3 |
|
| 1707 | + ); |
|
| 1708 | + add_filter( |
|
| 1709 | + 'FHEE__ee_migration_page__option_2_main', |
|
| 1710 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1711 | + 10, |
|
| 1712 | + 4 |
|
| 1713 | + ); |
|
| 1714 | + add_filter( |
|
| 1715 | + 'FHEE__ee_migration_page__option_2_button_text', |
|
| 1716 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1717 | + 10, |
|
| 1718 | + 2 |
|
| 1719 | + ); |
|
| 1720 | + add_filter( |
|
| 1721 | + 'FHEE__ee_migration_page__option_2_details', |
|
| 1722 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1723 | + 10, |
|
| 1724 | + 2 |
|
| 1725 | + ); |
|
| 1726 | + add_action( |
|
| 1727 | + 'AHEE__ee_migration_page__after_migration_options_table', |
|
| 1728 | + array($this, '_migration_page_hook_after_migration_options_table') |
|
| 1729 | + ); |
|
| 1730 | + add_filter( |
|
| 1731 | + 'FHEE__ee_migration_page__done_migration_header', |
|
| 1732 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1733 | + 10, |
|
| 1734 | + 2 |
|
| 1735 | + ); |
|
| 1736 | + add_filter( |
|
| 1737 | + 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 1738 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1739 | + 10, |
|
| 1740 | + 2 |
|
| 1741 | + ); |
|
| 1742 | + add_filter( |
|
| 1743 | + 'FHEE__ee_migration_page__migration_options_template', |
|
| 1744 | + array($this,'use_migration_options_from_ee3_template') |
|
| 1745 | + ); |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + |
|
| 1749 | + |
|
| 1750 | + public function _migrate_page_hook_simplify_version_strings( |
|
| 1751 | + $old_content, |
|
| 1752 | + $current_db_state, |
|
| 1753 | + $next_db_state, |
|
| 1754 | + $ultimate_db_state = null |
|
| 1755 | + ) { |
|
| 1756 | + return str_replace( |
|
| 1757 | + array($current_db_state, $next_db_state, $ultimate_db_state), |
|
| 1758 | + array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
| 1759 | + $old_content |
|
| 1760 | + ); |
|
| 1761 | + } |
|
| 1762 | + |
|
| 1763 | + |
|
| 1764 | + |
|
| 1765 | + public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
| 1766 | + { |
|
| 1767 | + return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
| 1768 | + } |
|
| 1769 | + |
|
| 1770 | + |
|
| 1771 | + |
|
| 1772 | + public function _migration_page_hook_option_1_extra_details() |
|
| 1773 | + { |
|
| 1774 | + ?> |
|
| 1775 | 1775 | <p><?php printf(esc_html__( |
| 1776 | - "Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
|
| 1777 | - "event_espresso" |
|
| 1778 | - )); ?></p><?php |
|
| 1779 | - } |
|
| 1776 | + "Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
|
| 1777 | + "event_espresso" |
|
| 1778 | + )); ?></p><?php |
|
| 1779 | + } |
|
| 1780 | 1780 | |
| 1781 | 1781 | |
| 1782 | 1782 | |
| 1783 | - public function _migration_page_hook_after_migration_options_table() |
|
| 1784 | - { |
|
| 1785 | - ?><p class="ee-attention"> |
|
| 1783 | + public function _migration_page_hook_after_migration_options_table() |
|
| 1784 | + { |
|
| 1785 | + ?><p class="ee-attention"> |
|
| 1786 | 1786 | <strong><span class="reminder-spn"> |
| 1787 | 1787 | <?php _e( |
| 1788 | - "Important note to those using Event Espresso 3 addons: ", |
|
| 1789 | - "event_espresso" |
|
| 1790 | - ); ?></span></strong> |
|
| 1788 | + "Important note to those using Event Espresso 3 addons: ", |
|
| 1789 | + "event_espresso" |
|
| 1790 | + ); ?></span></strong> |
|
| 1791 | 1791 | <br/> |
| 1792 | 1792 | <?php _e( |
| 1793 | - "Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
|
| 1794 | - "event_espresso" |
|
| 1795 | - ); ?> |
|
| 1793 | + "Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
|
| 1794 | + "event_espresso" |
|
| 1795 | + ); ?> |
|
| 1796 | 1796 | </p><?php |
| 1797 | - } |
|
| 1797 | + } |
|
| 1798 | 1798 | |
| 1799 | 1799 | |
| 1800 | 1800 | |
| 1801 | - /** |
|
| 1802 | - * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
| 1803 | - * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
| 1804 | - * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
| 1805 | - * @param $template_filepath |
|
| 1806 | - * @return string |
|
| 1807 | - */ |
|
| 1808 | - public function use_migration_options_from_ee3_template($template_filepath) |
|
| 1809 | - { |
|
| 1810 | - return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
| 1811 | - } |
|
| 1801 | + /** |
|
| 1802 | + * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
| 1803 | + * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
| 1804 | + * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
| 1805 | + * @param $template_filepath |
|
| 1806 | + * @return string |
|
| 1807 | + */ |
|
| 1808 | + public function use_migration_options_from_ee3_template($template_filepath) |
|
| 1809 | + { |
|
| 1810 | + return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
| 1811 | + } |
|
| 1812 | 1812 | } |
@@ -9,13 +9,13 @@ discard block |
||
| 9 | 9 | // unfortunately, this needs to be done upon INCLUSION of this file, |
| 10 | 10 | // instead of construction, because it only gets constructed on first page load |
| 11 | 11 | // (all other times it gets resurrected from a wordpress option) |
| 12 | -$stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
|
| 12 | +$stages = glob(EE_CORE.'data_migration_scripts/4_1_0_stages/*'); |
|
| 13 | 13 | $class_to_filepath = array(); |
| 14 | -if (! empty($stages)) { |
|
| 14 | +if ( ! empty($stages)) { |
|
| 15 | 15 | foreach ($stages as $filepath) { |
| 16 | 16 | $matches = array(); |
| 17 | 17 | preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
| 18 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 18 | + $class_to_filepath[$matches[1]] = $filepath; |
|
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | // give addons a chance to autoload their stages too |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | private function _checkin_table_exists() |
| 88 | 88 | { |
| 89 | 89 | global $wpdb; |
| 90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '".$wpdb->prefix."events_attendee_checkin"."'"); |
|
| 91 | 91 | if ($results) { |
| 92 | 92 | return true; |
| 93 | 93 | } else { |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
| 104 | 104 | // echo "$version_string can be migrated fro"; |
| 105 | 105 | return true; |
| 106 | - } elseif (! $version_string) { |
|
| 106 | + } elseif ( ! $version_string) { |
|
| 107 | 107 | // echo "no version string provided: $version_string"; |
| 108 | 108 | // no version string provided... this must be pre 4.1 |
| 109 | 109 | // because since 4.1 we're |
| 110 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
| 110 | + return false; // changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | 111 | } else { |
| 112 | 112 | // echo "$version_string doesnt apply"; |
| 113 | 113 | return false; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function schema_changes_before_migration() |
| 120 | 120 | { |
| 121 | 121 | // relies on 4.1's EEH_Activation::create_table |
| 122 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 122 | + require_once(EE_HELPERS.'EEH_Activation.helper.php'); |
|
| 123 | 123 | $table_name = 'esp_answer'; |
| 124 | 124 | $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
| 125 | 125 | REG_ID int(10) unsigned NOT NULL, |
@@ -503,12 +503,12 @@ discard block |
||
| 503 | 503 | public function insert_default_states() |
| 504 | 504 | { |
| 505 | 505 | global $wpdb; |
| 506 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 506 | + $state_table = $wpdb->prefix."esp_state"; |
|
| 507 | 507 | if ($this->_get_table_analysis()->tableExists($state_table)) { |
| 508 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 508 | + $SQL = "SELECT COUNT('STA_ID') FROM ".$state_table; |
|
| 509 | 509 | $states = $wpdb->get_var($SQL); |
| 510 | - if (! $states) { |
|
| 511 | - $SQL = "INSERT INTO " . $state_table . " |
|
| 510 | + if ( ! $states) { |
|
| 511 | + $SQL = "INSERT INTO ".$state_table." |
|
| 512 | 512 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
| 513 | 513 | (1, 'US', 'AK', 'Alaska', 1), |
| 514 | 514 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -596,12 +596,12 @@ discard block |
||
| 596 | 596 | public function insert_default_countries() |
| 597 | 597 | { |
| 598 | 598 | global $wpdb; |
| 599 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 599 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 600 | 600 | if ($this->_get_table_analysis()->tableExists($country_table)) { |
| 601 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 601 | + $SQL = "SELECT COUNT('CNT_ISO') FROM ".$country_table; |
|
| 602 | 602 | $countries = $wpdb->get_var($SQL); |
| 603 | - if (! $countries) { |
|
| 604 | - $SQL = "INSERT INTO " . $country_table . " |
|
| 603 | + if ( ! $countries) { |
|
| 604 | + $SQL = "INSERT INTO ".$country_table." |
|
| 605 | 605 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
| 606 | 606 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
| 607 | 607 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -846,17 +846,17 @@ discard block |
||
| 846 | 846 | public function insert_default_price_types() |
| 847 | 847 | { |
| 848 | 848 | global $wpdb; |
| 849 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 849 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
| 850 | 850 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
| 851 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 851 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table; |
|
| 852 | 852 | $price_types_exist = $wpdb->get_var($SQL); |
| 853 | - if (! $price_types_exist) { |
|
| 853 | + if ( ! $price_types_exist) { |
|
| 854 | 854 | $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
| 855 | - (1, '" . esc_html__('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
|
| 856 | - (2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
|
| 857 | - (3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
|
| 858 | - (4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
|
| 859 | - (5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
|
| 855 | + (1, '".esc_html__('Base Price', 'event_espresso')."', 1, 0, 0, 0), |
|
| 856 | + (2, '" . esc_html__('Percent Discount', 'event_espresso')."', 2, 1, 20, 0), |
|
| 857 | + (3, '" . esc_html__('Fixed Discount', 'event_espresso')."', 2, 0, 30, 0), |
|
| 858 | + (4, '" . esc_html__('Percent Surcharge', 'event_espresso')."', 3, 1, 40, 0), |
|
| 859 | + (5, '" . esc_html__('Fixed Surcharge', 'event_espresso')."', 3, 0, 50, 0);"; |
|
| 860 | 860 | $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
| 861 | 861 | $wpdb->query($SQL); |
| 862 | 862 | } |
@@ -878,11 +878,11 @@ discard block |
||
| 878 | 878 | public function insert_default_prices() |
| 879 | 879 | { |
| 880 | 880 | global $wpdb; |
| 881 | - $price_table = $wpdb->prefix . "esp_price"; |
|
| 881 | + $price_table = $wpdb->prefix."esp_price"; |
|
| 882 | 882 | if ($this->_get_table_analysis()->tableExists($price_table)) { |
| 883 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 883 | + $SQL = 'SELECT COUNT(PRC_ID) FROM '.$price_table; |
|
| 884 | 884 | $prices_exist = $wpdb->get_var($SQL); |
| 885 | - if (! $prices_exist) { |
|
| 885 | + if ( ! $prices_exist) { |
|
| 886 | 886 | $SQL = "INSERT INTO $price_table |
| 887 | 887 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES |
| 888 | 888 | (1, 1, '0.00', 'Free Admission', '', 1, null, 0, 0, 0);"; |
@@ -904,11 +904,11 @@ discard block |
||
| 904 | 904 | public function insert_default_tickets() |
| 905 | 905 | { |
| 906 | 906 | global $wpdb; |
| 907 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 907 | + $ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 908 | 908 | if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
| 909 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 909 | + $SQL = 'SELECT COUNT(TKT_ID) FROM '.$ticket_table; |
|
| 910 | 910 | $tickets_exist = $wpdb->get_var($SQL); |
| 911 | - if (! $tickets_exist) { |
|
| 911 | + if ( ! $tickets_exist) { |
|
| 912 | 912 | $SQL = "INSERT INTO $ticket_table |
| 913 | 913 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
| 914 | 914 | ( 1, 0, '" |
@@ -918,11 +918,11 @@ discard block |
||
| 918 | 918 | $wpdb->query($SQL); |
| 919 | 919 | } |
| 920 | 920 | } |
| 921 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 921 | + $ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 922 | 922 | if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
| 923 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 923 | + $SQL = 'SELECT COUNT(TKP_ID) FROM '.$ticket_price_table; |
|
| 924 | 924 | $ticket_prc_exist = $wpdb->get_var($SQL); |
| 925 | - if (! $ticket_prc_exist) { |
|
| 925 | + if ( ! $ticket_prc_exist) { |
|
| 926 | 926 | $SQL = "INSERT INTO $ticket_price_table |
| 927 | 927 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
| 928 | 928 | ( 1, 1, 1 ) |
@@ -946,11 +946,11 @@ discard block |
||
| 946 | 946 | */ |
| 947 | 947 | public function get_or_create_country($country_name) |
| 948 | 948 | { |
| 949 | - if (! $country_name) { |
|
| 949 | + if ( ! $country_name) { |
|
| 950 | 950 | throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
| 951 | 951 | } |
| 952 | 952 | global $wpdb; |
| 953 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 953 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 954 | 954 | if (is_int($country_name)) { |
| 955 | 955 | $country_name = $this->get_iso_from_3_1_country_id($country_name); |
| 956 | 956 | } |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | CNT_ISO LIKE %s OR |
| 959 | 959 | CNT_ISO3 LIKE %s OR |
| 960 | 960 | CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A); |
| 961 | - if (! $country) { |
|
| 961 | + if ( ! $country) { |
|
| 962 | 962 | // insert a new one then |
| 963 | 963 | $cols_n_values = array( |
| 964 | 964 | 'CNT_ISO' => $this->_find_available_country_iso(2), |
@@ -978,28 +978,28 @@ discard block |
||
| 978 | 978 | 'CNT_active' => true, |
| 979 | 979 | ); |
| 980 | 980 | $data_types = array( |
| 981 | - '%s',// CNT_ISO |
|
| 982 | - '%s',// CNT_ISO3 |
|
| 983 | - '%d',// RGN_ID |
|
| 984 | - '%s',// CNT_name |
|
| 985 | - '%s',// CNT_cur_code |
|
| 986 | - '%s',// CNT_cur_single |
|
| 987 | - '%s',// CNT_cur_plural |
|
| 988 | - '%s',// CNT_cur_sign |
|
| 989 | - '%d',// CNT_cur_sign_b4 |
|
| 990 | - '%d',// CNT_cur_dec_plc |
|
| 991 | - '%s',// CNT_cur_dec_mrk |
|
| 992 | - '%s',// CNT_cur_thsnds |
|
| 993 | - '%s',// CNT_tel_code |
|
| 994 | - '%d',// CNT_is_EU |
|
| 995 | - '%d',// CNT_active |
|
| 981 | + '%s', // CNT_ISO |
|
| 982 | + '%s', // CNT_ISO3 |
|
| 983 | + '%d', // RGN_ID |
|
| 984 | + '%s', // CNT_name |
|
| 985 | + '%s', // CNT_cur_code |
|
| 986 | + '%s', // CNT_cur_single |
|
| 987 | + '%s', // CNT_cur_plural |
|
| 988 | + '%s', // CNT_cur_sign |
|
| 989 | + '%d', // CNT_cur_sign_b4 |
|
| 990 | + '%d', // CNT_cur_dec_plc |
|
| 991 | + '%s', // CNT_cur_dec_mrk |
|
| 992 | + '%s', // CNT_cur_thsnds |
|
| 993 | + '%s', // CNT_tel_code |
|
| 994 | + '%d', // CNT_is_EU |
|
| 995 | + '%d', // CNT_active |
|
| 996 | 996 | ); |
| 997 | 997 | $success = $wpdb->insert( |
| 998 | 998 | $country_table, |
| 999 | 999 | $cols_n_values, |
| 1000 | 1000 | $data_types |
| 1001 | 1001 | ); |
| 1002 | - if (! $success) { |
|
| 1002 | + if ( ! $success) { |
|
| 1003 | 1003 | throw new EE_Error($this->_create_error_message_for_db_insertion( |
| 1004 | 1004 | 'N/A', |
| 1005 | 1005 | array('country_id' => $country_name), |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | private function _find_available_country_iso($num_letters = 2) |
| 1025 | 1025 | { |
| 1026 | 1026 | global $wpdb; |
| 1027 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 1027 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 1028 | 1028 | $attempts = 0; |
| 1029 | 1029 | do { |
| 1030 | 1030 | $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
@@ -1035,7 +1035,7 @@ discard block |
||
| 1035 | 1035 | // keep going until we find an available country code, or we arbitrarily |
| 1036 | 1036 | // decide we've tried this enough. Somehow they have way too many countries |
| 1037 | 1037 | // (probably because they're mis-using the EE3 country_id like a custom question) |
| 1038 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1038 | + }while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1039 | 1039 | return $current_iso; |
| 1040 | 1040 | } |
| 1041 | 1041 | |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | */ |
| 1052 | 1052 | public function get_or_create_state($state_name, $country_name = '') |
| 1053 | 1053 | { |
| 1054 | - if (! $state_name) { |
|
| 1054 | + if ( ! $state_name) { |
|
| 1055 | 1055 | throw new EE_Error(esc_html__( |
| 1056 | 1056 | "Could not get-or-create state because no state name was provided", |
| 1057 | 1057 | "event_espresso" |
@@ -1064,12 +1064,12 @@ discard block |
||
| 1064 | 1064 | $country_iso = $this->get_default_country_iso(); |
| 1065 | 1065 | } |
| 1066 | 1066 | global $wpdb; |
| 1067 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 1067 | + $state_table = $wpdb->prefix."esp_state"; |
|
| 1068 | 1068 | $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
| 1069 | 1069 | (STA_abbrev LIKE %s OR |
| 1070 | 1070 | STA_name LIKE %s) AND |
| 1071 | 1071 | CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A); |
| 1072 | - if (! $state) { |
|
| 1072 | + if ( ! $state) { |
|
| 1073 | 1073 | // insert a new one then |
| 1074 | 1074 | $cols_n_values = array( |
| 1075 | 1075 | 'CNT_ISO' => $country_iso, |
@@ -1078,13 +1078,13 @@ discard block |
||
| 1078 | 1078 | 'STA_active' => true, |
| 1079 | 1079 | ); |
| 1080 | 1080 | $data_types = array( |
| 1081 | - '%s',// CNT_ISO |
|
| 1082 | - '%s',// STA_abbrev |
|
| 1083 | - '%s',// STA_name |
|
| 1084 | - '%d',// STA_active |
|
| 1081 | + '%s', // CNT_ISO |
|
| 1082 | + '%s', // STA_abbrev |
|
| 1083 | + '%s', // STA_name |
|
| 1084 | + '%d', // STA_active |
|
| 1085 | 1085 | ); |
| 1086 | 1086 | $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
| 1087 | - if (! $success) { |
|
| 1087 | + if ( ! $success) { |
|
| 1088 | 1088 | throw new EE_Error($this->_create_error_message_for_db_insertion( |
| 1089 | 1089 | 'N/A', |
| 1090 | 1090 | array('state' => $state_name, 'country_id' => $country_name), |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | { |
| 1114 | 1114 | $matches = array(); |
| 1115 | 1115 | preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
| 1116 | - if (! $matches || count($matches) < 3) { |
|
| 1116 | + if ( ! $matches || count($matches) < 3) { |
|
| 1117 | 1117 | $hour = '00'; |
| 1118 | 1118 | $minutes = '00'; |
| 1119 | 1119 | } else { |
@@ -1418,7 +1418,7 @@ discard block |
||
| 1418 | 1418 | 'Declined' => 'RPP', |
| 1419 | 1419 | ); |
| 1420 | 1420 | } |
| 1421 | - return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
| 1421 | + return isset($mapping[$payment_status]) ? $mapping[$payment_status] : 'RNA'; |
|
| 1422 | 1422 | } |
| 1423 | 1423 | |
| 1424 | 1424 | |
@@ -1442,7 +1442,7 @@ discard block |
||
| 1442 | 1442 | if ($guid) { |
| 1443 | 1443 | // check for an existing attachment post with this guid |
| 1444 | 1444 | $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
| 1445 | - if (! $attachment_post_id) { |
|
| 1445 | + if ( ! $attachment_post_id) { |
|
| 1446 | 1446 | // post thumbnail with that GUID doesn't exist, we should create one |
| 1447 | 1447 | $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
| 1448 | 1448 | $created_attachment_post = true; |
@@ -1477,7 +1477,7 @@ discard block |
||
| 1477 | 1477 | $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
| 1478 | 1478 | // do a head request to verify the file exists |
| 1479 | 1479 | $head_response = wp_remote_head($original_guid); |
| 1480 | - if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1480 | + if ( ! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1481 | 1481 | return $original_guid; |
| 1482 | 1482 | } else { |
| 1483 | 1483 | return $guid_in_old_event; |
@@ -1497,7 +1497,7 @@ discard block |
||
| 1497 | 1497 | */ |
| 1498 | 1498 | private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
| 1499 | 1499 | { |
| 1500 | - if (! $guid) { |
|
| 1500 | + if ( ! $guid) { |
|
| 1501 | 1501 | $migration_stage->add_error(sprintf(esc_html__( |
| 1502 | 1502 | "Cannot create image attachment for a blank GUID!", |
| 1503 | 1503 | "event_espresso" |
@@ -1509,7 +1509,7 @@ discard block |
||
| 1509 | 1509 | // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
| 1510 | 1510 | if (strpos($guid, $wp_upload_dir['url']) === false) { |
| 1511 | 1511 | // image is located remotely. download it and place it in the uploads directory |
| 1512 | - if (! is_readable($guid)) { |
|
| 1512 | + if ( ! is_readable($guid)) { |
|
| 1513 | 1513 | $migration_stage->add_error(sprintf(esc_html__( |
| 1514 | 1514 | "Could not create image attachment from non-existent file: %s", |
| 1515 | 1515 | "event_espresso" |
@@ -1524,7 +1524,7 @@ discard block |
||
| 1524 | 1524 | ), $guid)); |
| 1525 | 1525 | return false; |
| 1526 | 1526 | } |
| 1527 | - $local_filepath = $wp_upload_dir['path'] . '/' . basename($guid); |
|
| 1527 | + $local_filepath = $wp_upload_dir['path'].'/'.basename($guid); |
|
| 1528 | 1528 | $savefile = fopen($local_filepath, 'w'); |
| 1529 | 1529 | fwrite($savefile, $contents); |
| 1530 | 1530 | fclose($savefile); |
@@ -1540,7 +1540,7 @@ discard block |
||
| 1540 | 1540 | 'post_status' => 'inherit', |
| 1541 | 1541 | ); |
| 1542 | 1542 | $attach_id = wp_insert_attachment($attachment, $guid); |
| 1543 | - if (! $attach_id) { |
|
| 1543 | + if ( ! $attach_id) { |
|
| 1544 | 1544 | $migration_stage->add_error(sprintf(esc_html__( |
| 1545 | 1545 | "Could not create image attachment post from image '%s'. Attachment data was %s.", |
| 1546 | 1546 | "event_espresso" |
@@ -1549,9 +1549,9 @@ discard block |
||
| 1549 | 1549 | } |
| 1550 | 1550 | // you must first include the image.php file |
| 1551 | 1551 | // for the function wp_generate_attachment_metadata() to work |
| 1552 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1552 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
| 1553 | 1553 | $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
| 1554 | - if (! $attach_data) { |
|
| 1554 | + if ( ! $attach_data) { |
|
| 1555 | 1555 | $migration_stage->add_error(sprintf(esc_html__( |
| 1556 | 1556 | "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
| 1557 | 1557 | "event_espresso" |
@@ -1559,7 +1559,7 @@ discard block |
||
| 1559 | 1559 | return $attach_id; |
| 1560 | 1560 | } |
| 1561 | 1561 | $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
| 1562 | - if (! $metadata_save_result) { |
|
| 1562 | + if ( ! $metadata_save_result) { |
|
| 1563 | 1563 | $migration_stage->add_error(sprintf(esc_html__( |
| 1564 | 1564 | "Could not update attachment metadata for attachment %d with data %s", |
| 1565 | 1565 | "event_espresso" |
@@ -1605,10 +1605,10 @@ discard block |
||
| 1605 | 1605 | $timezone = null |
| 1606 | 1606 | ) { |
| 1607 | 1607 | $original_tz = $timezone; |
| 1608 | - if (! $timezone) { |
|
| 1608 | + if ( ! $timezone) { |
|
| 1609 | 1609 | $timezone = $this->_get_wp_timezone(); |
| 1610 | 1610 | } |
| 1611 | - if (! $timezone) { |
|
| 1611 | + if ( ! $timezone) { |
|
| 1612 | 1612 | $stage->add_error(sprintf( |
| 1613 | 1613 | esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
| 1614 | 1614 | $original_tz, |
@@ -1741,7 +1741,7 @@ discard block |
||
| 1741 | 1741 | ); |
| 1742 | 1742 | add_filter( |
| 1743 | 1743 | 'FHEE__ee_migration_page__migration_options_template', |
| 1744 | - array($this,'use_migration_options_from_ee3_template') |
|
| 1744 | + array($this, 'use_migration_options_from_ee3_template') |
|
| 1745 | 1745 | ); |
| 1746 | 1746 | } |
| 1747 | 1747 | |
@@ -1807,6 +1807,6 @@ discard block |
||
| 1807 | 1807 | */ |
| 1808 | 1808 | public function use_migration_options_from_ee3_template($template_filepath) |
| 1809 | 1809 | { |
| 1810 | - return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
| 1810 | + return EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee3.template.php'; |
|
| 1811 | 1811 | } |
| 1812 | 1812 | } |
@@ -14,2509 +14,2509 @@ discard block |
||
| 14 | 14 | final class EE_Config implements ResettableInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const OPTION_NAME = 'ee_config'; |
|
| 18 | - |
|
| 19 | - const LOG_NAME = 'ee_config_log'; |
|
| 20 | - |
|
| 21 | - const LOG_LENGTH = 100; |
|
| 22 | - |
|
| 23 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * instance of the EE_Config object |
|
| 27 | - * |
|
| 28 | - * @var EE_Config $_instance |
|
| 29 | - * @access private |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var boolean $_logging_enabled |
|
| 35 | - */ |
|
| 36 | - private static $_logging_enabled = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | - */ |
|
| 41 | - private $legacy_shortcodes_manager; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * An StdClass whose property names are addon slugs, |
|
| 45 | - * and values are their config classes |
|
| 46 | - * |
|
| 47 | - * @var StdClass |
|
| 48 | - */ |
|
| 49 | - public $addons; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var EE_Admin_Config |
|
| 53 | - */ |
|
| 54 | - public $admin; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var EE_Core_Config |
|
| 58 | - */ |
|
| 59 | - public $core; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var EE_Currency_Config |
|
| 63 | - */ |
|
| 64 | - public $currency; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var EE_Organization_Config |
|
| 68 | - */ |
|
| 69 | - public $organization; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var EE_Registration_Config |
|
| 73 | - */ |
|
| 74 | - public $registration; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var EE_Template_Config |
|
| 78 | - */ |
|
| 79 | - public $template_settings; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Holds EE environment values. |
|
| 83 | - * |
|
| 84 | - * @var EE_Environment_Config |
|
| 85 | - */ |
|
| 86 | - public $environment; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * settings pertaining to Google maps |
|
| 90 | - * |
|
| 91 | - * @var EE_Map_Config |
|
| 92 | - */ |
|
| 93 | - public $map_settings; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * settings pertaining to Taxes |
|
| 97 | - * |
|
| 98 | - * @var EE_Tax_Config |
|
| 99 | - */ |
|
| 100 | - public $tax_settings; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Settings pertaining to global messages settings. |
|
| 104 | - * |
|
| 105 | - * @var EE_Messages_Config |
|
| 106 | - */ |
|
| 107 | - public $messages; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated |
|
| 111 | - * @var EE_Gateway_Config |
|
| 112 | - */ |
|
| 113 | - public $gateway; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var array $_addon_option_names |
|
| 117 | - * @access private |
|
| 118 | - */ |
|
| 119 | - private $_addon_option_names = array(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @var array $_module_route_map |
|
| 123 | - * @access private |
|
| 124 | - */ |
|
| 125 | - private static $_module_route_map = array(); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var array $_module_forward_map |
|
| 129 | - * @access private |
|
| 130 | - */ |
|
| 131 | - private static $_module_forward_map = array(); |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @var array $_module_view_map |
|
| 135 | - * @access private |
|
| 136 | - */ |
|
| 137 | - private static $_module_view_map = array(); |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @singleton method used to instantiate class object |
|
| 142 | - * @access public |
|
| 143 | - * @return EE_Config instance |
|
| 144 | - */ |
|
| 145 | - public static function instance() |
|
| 146 | - { |
|
| 147 | - // check if class object is instantiated, and instantiated properly |
|
| 148 | - if (! self::$_instance instanceof EE_Config) { |
|
| 149 | - self::$_instance = new self(); |
|
| 150 | - } |
|
| 151 | - return self::$_instance; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Resets the config |
|
| 157 | - * |
|
| 158 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | - * reflect its state in the database |
|
| 161 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | - * site was put into maintenance mode) |
|
| 165 | - * @return EE_Config |
|
| 166 | - */ |
|
| 167 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | - { |
|
| 169 | - if (self::$_instance instanceof EE_Config) { |
|
| 170 | - if ($hard_reset) { |
|
| 171 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | - self::$_instance->_addon_option_names = array(); |
|
| 173 | - self::$_instance->_initialize_config(); |
|
| 174 | - self::$_instance->update_espresso_config(); |
|
| 175 | - } |
|
| 176 | - self::$_instance->update_addon_option_names(); |
|
| 177 | - } |
|
| 178 | - self::$_instance = null; |
|
| 179 | - // we don't need to reset the static properties imo because those should |
|
| 180 | - // only change when a module is added or removed. Currently we don't |
|
| 181 | - // support removing a module during a request when it previously existed |
|
| 182 | - if ($reinstantiate) { |
|
| 183 | - return self::instance(); |
|
| 184 | - } else { |
|
| 185 | - return null; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * class constructor |
|
| 192 | - * |
|
| 193 | - * @access private |
|
| 194 | - */ |
|
| 195 | - private function __construct() |
|
| 196 | - { |
|
| 197 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | - // setup empty config classes |
|
| 200 | - $this->_initialize_config(); |
|
| 201 | - // load existing EE site settings |
|
| 202 | - $this->_load_core_config(); |
|
| 203 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | - $this->_verify_config(); |
|
| 205 | - // register shortcodes and modules |
|
| 206 | - add_action( |
|
| 207 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | - array($this, 'register_shortcodes_and_modules'), |
|
| 209 | - 999 |
|
| 210 | - ); |
|
| 211 | - // initialize shortcodes and modules |
|
| 212 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | - // register widgets |
|
| 214 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | - // shutdown |
|
| 216 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | - // construct__end hook |
|
| 218 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | - // hardcoded hack |
|
| 220 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @return boolean |
|
| 226 | - */ |
|
| 227 | - public static function logging_enabled() |
|
| 228 | - { |
|
| 229 | - return self::$_logging_enabled; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * use to get the current theme if needed from static context |
|
| 235 | - * |
|
| 236 | - * @return string current theme set. |
|
| 237 | - */ |
|
| 238 | - public static function get_current_theme() |
|
| 239 | - { |
|
| 240 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * _initialize_config |
|
| 247 | - * |
|
| 248 | - * @access private |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - private function _initialize_config() |
|
| 252 | - { |
|
| 253 | - EE_Config::trim_log(); |
|
| 254 | - // set defaults |
|
| 255 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | - $this->addons = new stdClass(); |
|
| 257 | - // set _module_route_map |
|
| 258 | - EE_Config::$_module_route_map = array(); |
|
| 259 | - // set _module_forward_map |
|
| 260 | - EE_Config::$_module_forward_map = array(); |
|
| 261 | - // set _module_view_map |
|
| 262 | - EE_Config::$_module_view_map = array(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * load core plugin configuration |
|
| 268 | - * |
|
| 269 | - * @access private |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - private function _load_core_config() |
|
| 273 | - { |
|
| 274 | - // load_core_config__start hook |
|
| 275 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | - $espresso_config = $this->get_espresso_config(); |
|
| 277 | - foreach ($espresso_config as $config => $settings) { |
|
| 278 | - // load_core_config__start hook |
|
| 279 | - $settings = apply_filters( |
|
| 280 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | - $settings, |
|
| 282 | - $config, |
|
| 283 | - $this |
|
| 284 | - ); |
|
| 285 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | - // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | - if (method_exists($settings, 'populate')) { |
|
| 289 | - $this->{$config}->populate(); |
|
| 290 | - } |
|
| 291 | - if (method_exists($settings, 'do_hooks')) { |
|
| 292 | - $this->{$config}->do_hooks(); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | - $this->update_espresso_config(); |
|
| 298 | - } |
|
| 299 | - // load_core_config__end hook |
|
| 300 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * _verify_config |
|
| 306 | - * |
|
| 307 | - * @access protected |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - protected function _verify_config() |
|
| 311 | - { |
|
| 312 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | - ? $this->core |
|
| 314 | - : new EE_Core_Config(); |
|
| 315 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | - ? $this->organization |
|
| 318 | - : new EE_Organization_Config(); |
|
| 319 | - $this->organization = apply_filters( |
|
| 320 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | - $this->organization |
|
| 322 | - ); |
|
| 323 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | - ? $this->currency |
|
| 325 | - : new EE_Currency_Config(); |
|
| 326 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | - ? $this->registration |
|
| 329 | - : new EE_Registration_Config(); |
|
| 330 | - $this->registration = apply_filters( |
|
| 331 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | - $this->registration |
|
| 333 | - ); |
|
| 334 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | - ? $this->admin |
|
| 336 | - : new EE_Admin_Config(); |
|
| 337 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | - ? $this->template_settings |
|
| 340 | - : new EE_Template_Config(); |
|
| 341 | - $this->template_settings = apply_filters( |
|
| 342 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | - $this->template_settings |
|
| 344 | - ); |
|
| 345 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | - ? $this->map_settings |
|
| 347 | - : new EE_Map_Config(); |
|
| 348 | - $this->map_settings = apply_filters( |
|
| 349 | - 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | - $this->map_settings |
|
| 351 | - ); |
|
| 352 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | - ? $this->environment |
|
| 354 | - : new EE_Environment_Config(); |
|
| 355 | - $this->environment = apply_filters( |
|
| 356 | - 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | - $this->environment |
|
| 358 | - ); |
|
| 359 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | - ? $this->tax_settings |
|
| 361 | - : new EE_Tax_Config(); |
|
| 362 | - $this->tax_settings = apply_filters( |
|
| 363 | - 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | - $this->tax_settings |
|
| 365 | - ); |
|
| 366 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | - ? $this->messages |
|
| 369 | - : new EE_Messages_Config(); |
|
| 370 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | - ? $this->gateway |
|
| 372 | - : new EE_Gateway_Config(); |
|
| 373 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | - $this->legacy_shortcodes_manager = null; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * get_espresso_config |
|
| 380 | - * |
|
| 381 | - * @access public |
|
| 382 | - * @return array of espresso config stuff |
|
| 383 | - */ |
|
| 384 | - public function get_espresso_config() |
|
| 385 | - { |
|
| 386 | - // grab espresso configuration |
|
| 387 | - return apply_filters( |
|
| 388 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * double_check_config_comparison |
|
| 396 | - * |
|
| 397 | - * @access public |
|
| 398 | - * @param string $option |
|
| 399 | - * @param $old_value |
|
| 400 | - * @param $value |
|
| 401 | - */ |
|
| 402 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | - { |
|
| 404 | - // make sure we're checking the ee config |
|
| 405 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | - if ($value != $old_value) { |
|
| 409 | - // if they are NOT the same, then remove the hook, |
|
| 410 | - // which means the subsequent update results will be based solely on the update query results |
|
| 411 | - // the reason we do this is because, as stated above, |
|
| 412 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | - // If values are found to match their previous old value, |
|
| 415 | - // then WP bails before performing any update. |
|
| 416 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | - // MySQL MAY ALSO NOT perform the update because |
|
| 420 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * update_espresso_config |
|
| 431 | - * |
|
| 432 | - * @access public |
|
| 433 | - */ |
|
| 434 | - protected function _reset_espresso_addon_config() |
|
| 435 | - { |
|
| 436 | - $this->_addon_option_names = array(); |
|
| 437 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | - } |
|
| 442 | - $this->addons->{$addon_name} = null; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * update_espresso_config |
|
| 449 | - * |
|
| 450 | - * @access public |
|
| 451 | - * @param bool $add_success |
|
| 452 | - * @param bool $add_error |
|
| 453 | - * @return bool |
|
| 454 | - */ |
|
| 455 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | - { |
|
| 457 | - // don't allow config updates during WP heartbeats |
|
| 458 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | - return false; |
|
| 460 | - } |
|
| 461 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | - // $clone = clone( self::$_instance ); |
|
| 463 | - // self::$_instance = NULL; |
|
| 464 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | - $this->_reset_espresso_addon_config(); |
|
| 466 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | - // but BEFORE the actual update occurs |
|
| 468 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | - $this->legacy_shortcodes_manager = null; |
|
| 472 | - // now update "ee_config" |
|
| 473 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | - // if not saved... check if the hook we just added still exists; |
|
| 477 | - // if it does, it means one of two things: |
|
| 478 | - // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | - // or... |
|
| 480 | - // the db update query returned 0 rows affected |
|
| 481 | - // (probably because the data value was the same from it's perspective) |
|
| 482 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | - // but just means no update occurred, so don't display an error to the user. |
|
| 484 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | - // then it means that something truly went wrong |
|
| 486 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | - // remove our action since we don't want it in the system anymore |
|
| 488 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | - // self::$_instance = $clone; |
|
| 491 | - // unset( $clone ); |
|
| 492 | - // if config remains the same or was updated successfully |
|
| 493 | - if ($saved) { |
|
| 494 | - if ($add_success) { |
|
| 495 | - EE_Error::add_success( |
|
| 496 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | - __FILE__, |
|
| 498 | - __FUNCTION__, |
|
| 499 | - __LINE__ |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - return true; |
|
| 503 | - } else { |
|
| 504 | - if ($add_error) { |
|
| 505 | - EE_Error::add_error( |
|
| 506 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | - __FILE__, |
|
| 508 | - __FUNCTION__, |
|
| 509 | - __LINE__ |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * _verify_config_params |
|
| 519 | - * |
|
| 520 | - * @access private |
|
| 521 | - * @param string $section |
|
| 522 | - * @param string $name |
|
| 523 | - * @param string $config_class |
|
| 524 | - * @param EE_Config_Base $config_obj |
|
| 525 | - * @param array $tests_to_run |
|
| 526 | - * @param bool $display_errors |
|
| 527 | - * @return bool TRUE on success, FALSE on fail |
|
| 528 | - */ |
|
| 529 | - private function _verify_config_params( |
|
| 530 | - $section = '', |
|
| 531 | - $name = '', |
|
| 532 | - $config_class = '', |
|
| 533 | - $config_obj = null, |
|
| 534 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | - $display_errors = true |
|
| 536 | - ) { |
|
| 537 | - try { |
|
| 538 | - foreach ($tests_to_run as $test) { |
|
| 539 | - switch ($test) { |
|
| 540 | - // TEST #1 : check that section was set |
|
| 541 | - case 1: |
|
| 542 | - if (empty($section)) { |
|
| 543 | - if ($display_errors) { |
|
| 544 | - throw new EE_Error( |
|
| 545 | - sprintf( |
|
| 546 | - __( |
|
| 547 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | - 'event_espresso' |
|
| 549 | - ), |
|
| 550 | - $config_class |
|
| 551 | - ) |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - return false; |
|
| 555 | - } |
|
| 556 | - break; |
|
| 557 | - // TEST #2 : check that settings section exists |
|
| 558 | - case 2: |
|
| 559 | - if (! isset($this->{$section})) { |
|
| 560 | - if ($display_errors) { |
|
| 561 | - throw new EE_Error( |
|
| 562 | - sprintf( |
|
| 563 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | - $section |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - } |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - break; |
|
| 571 | - // TEST #3 : check that section is the proper format |
|
| 572 | - case 3: |
|
| 573 | - if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | - ) { |
|
| 575 | - if ($display_errors) { |
|
| 576 | - throw new EE_Error( |
|
| 577 | - sprintf( |
|
| 578 | - __( |
|
| 579 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | - 'event_espresso' |
|
| 581 | - ), |
|
| 582 | - $section |
|
| 583 | - ) |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - return false; |
|
| 587 | - } |
|
| 588 | - break; |
|
| 589 | - // TEST #4 : check that config section name has been set |
|
| 590 | - case 4: |
|
| 591 | - if (empty($name)) { |
|
| 592 | - if ($display_errors) { |
|
| 593 | - throw new EE_Error( |
|
| 594 | - __( |
|
| 595 | - 'No name has been provided for the specific configuration section.', |
|
| 596 | - 'event_espresso' |
|
| 597 | - ) |
|
| 598 | - ); |
|
| 599 | - } |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - break; |
|
| 603 | - // TEST #5 : check that a config class name has been set |
|
| 604 | - case 5: |
|
| 605 | - if (empty($config_class)) { |
|
| 606 | - if ($display_errors) { |
|
| 607 | - throw new EE_Error( |
|
| 608 | - __( |
|
| 609 | - 'No class name has been provided for the specific configuration section.', |
|
| 610 | - 'event_espresso' |
|
| 611 | - ) |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - return false; |
|
| 615 | - } |
|
| 616 | - break; |
|
| 617 | - // TEST #6 : verify config class is accessible |
|
| 618 | - case 6: |
|
| 619 | - if (! class_exists($config_class)) { |
|
| 620 | - if ($display_errors) { |
|
| 621 | - throw new EE_Error( |
|
| 622 | - sprintf( |
|
| 623 | - __( |
|
| 624 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | - 'event_espresso' |
|
| 626 | - ), |
|
| 627 | - $config_class |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - break; |
|
| 634 | - // TEST #7 : check that config has even been set |
|
| 635 | - case 7: |
|
| 636 | - if (! isset($this->{$section}->{$name})) { |
|
| 637 | - if ($display_errors) { |
|
| 638 | - throw new EE_Error( |
|
| 639 | - sprintf( |
|
| 640 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | - $section, |
|
| 642 | - $name |
|
| 643 | - ) |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - return false; |
|
| 647 | - } else { |
|
| 648 | - // and make sure it's not serialized |
|
| 649 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | - } |
|
| 651 | - break; |
|
| 652 | - // TEST #8 : check that config is the requested type |
|
| 653 | - case 8: |
|
| 654 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | - if ($display_errors) { |
|
| 656 | - throw new EE_Error( |
|
| 657 | - sprintf( |
|
| 658 | - __( |
|
| 659 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | - 'event_espresso' |
|
| 661 | - ), |
|
| 662 | - $section, |
|
| 663 | - $name, |
|
| 664 | - $config_class |
|
| 665 | - ) |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - return false; |
|
| 669 | - } |
|
| 670 | - break; |
|
| 671 | - // TEST #9 : verify config object |
|
| 672 | - case 9: |
|
| 673 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | - if ($display_errors) { |
|
| 675 | - throw new EE_Error( |
|
| 676 | - sprintf( |
|
| 677 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | - print_r($config_obj, true) |
|
| 679 | - ) |
|
| 680 | - ); |
|
| 681 | - } |
|
| 682 | - return false; |
|
| 683 | - } |
|
| 684 | - break; |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - } catch (EE_Error $e) { |
|
| 688 | - $e->get_error(); |
|
| 689 | - } |
|
| 690 | - // you have successfully run the gauntlet |
|
| 691 | - return true; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * _generate_config_option_name |
|
| 697 | - * |
|
| 698 | - * @access protected |
|
| 699 | - * @param string $section |
|
| 700 | - * @param string $name |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | - { |
|
| 705 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * _set_config_class |
|
| 711 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | - * |
|
| 713 | - * @access private |
|
| 714 | - * @param string $config_class |
|
| 715 | - * @param string $name |
|
| 716 | - * @return string |
|
| 717 | - */ |
|
| 718 | - private function _set_config_class($config_class = '', $name = '') |
|
| 719 | - { |
|
| 720 | - return ! empty($config_class) |
|
| 721 | - ? $config_class |
|
| 722 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * set_config |
|
| 728 | - * |
|
| 729 | - * @access protected |
|
| 730 | - * @param string $section |
|
| 731 | - * @param string $name |
|
| 732 | - * @param string $config_class |
|
| 733 | - * @param EE_Config_Base $config_obj |
|
| 734 | - * @return EE_Config_Base |
|
| 735 | - */ |
|
| 736 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | - { |
|
| 738 | - // ensure config class is set to something |
|
| 739 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | - return null; |
|
| 743 | - } |
|
| 744 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | - $this->update_addon_option_names(); |
|
| 749 | - } |
|
| 750 | - // verify the incoming config object but suppress errors |
|
| 751 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | - $config_obj = new $config_class(); |
|
| 753 | - } |
|
| 754 | - if (get_option($config_option_name)) { |
|
| 755 | - EE_Config::log($config_option_name); |
|
| 756 | - update_option($config_option_name, $config_obj); |
|
| 757 | - $this->{$section}->{$name} = $config_obj; |
|
| 758 | - return $this->{$section}->{$name}; |
|
| 759 | - } else { |
|
| 760 | - // create a wp-option for this config |
|
| 761 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | - return $this->{$section}->{$name}; |
|
| 764 | - } else { |
|
| 765 | - EE_Error::add_error( |
|
| 766 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | - __FILE__, |
|
| 768 | - __FUNCTION__, |
|
| 769 | - __LINE__ |
|
| 770 | - ); |
|
| 771 | - return null; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * update_config |
|
| 779 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | - * |
|
| 781 | - * @access public |
|
| 782 | - * @param string $section |
|
| 783 | - * @param string $name |
|
| 784 | - * @param EE_Config_Base|string $config_obj |
|
| 785 | - * @param bool $throw_errors |
|
| 786 | - * @return bool |
|
| 787 | - */ |
|
| 788 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | - { |
|
| 790 | - // don't allow config updates during WP heartbeats |
|
| 791 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | - return false; |
|
| 793 | - } |
|
| 794 | - $config_obj = maybe_unserialize($config_obj); |
|
| 795 | - // get class name of the incoming object |
|
| 796 | - $config_class = get_class($config_obj); |
|
| 797 | - // run tests 1-5 and 9 to verify config |
|
| 798 | - if (! $this->_verify_config_params( |
|
| 799 | - $section, |
|
| 800 | - $name, |
|
| 801 | - $config_class, |
|
| 802 | - $config_obj, |
|
| 803 | - array(1, 2, 3, 4, 7, 9) |
|
| 804 | - ) |
|
| 805 | - ) { |
|
| 806 | - return false; |
|
| 807 | - } |
|
| 808 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | - // save new config to db |
|
| 812 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | - return true; |
|
| 814 | - } |
|
| 815 | - } else { |
|
| 816 | - // first check if the record already exists |
|
| 817 | - $existing_config = get_option($config_option_name); |
|
| 818 | - $config_obj = serialize($config_obj); |
|
| 819 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | - if ($existing_config == $config_obj) { |
|
| 821 | - $this->{$section}->{$name} = $config_obj; |
|
| 822 | - return true; |
|
| 823 | - } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | - EE_Config::log($config_option_name); |
|
| 825 | - // update wp-option for this config class |
|
| 826 | - $this->{$section}->{$name} = $config_obj; |
|
| 827 | - return true; |
|
| 828 | - } elseif ($throw_errors) { |
|
| 829 | - EE_Error::add_error( |
|
| 830 | - sprintf( |
|
| 831 | - __( |
|
| 832 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | - 'event_espresso' |
|
| 834 | - ), |
|
| 835 | - $config_class, |
|
| 836 | - 'EE_Config->' . $section . '->' . $name |
|
| 837 | - ), |
|
| 838 | - __FILE__, |
|
| 839 | - __FUNCTION__, |
|
| 840 | - __LINE__ |
|
| 841 | - ); |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - return false; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * get_config |
|
| 850 | - * |
|
| 851 | - * @access public |
|
| 852 | - * @param string $section |
|
| 853 | - * @param string $name |
|
| 854 | - * @param string $config_class |
|
| 855 | - * @return mixed EE_Config_Base | NULL |
|
| 856 | - */ |
|
| 857 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | - { |
|
| 859 | - // ensure config class is set to something |
|
| 860 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | - return null; |
|
| 864 | - } |
|
| 865 | - // now test if the requested config object exists, but suppress errors |
|
| 866 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | - // config already exists, so pass it back |
|
| 868 | - return $this->{$section}->{$name}; |
|
| 869 | - } |
|
| 870 | - // load config option from db if it exists |
|
| 871 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | - // verify the newly retrieved config object, but suppress errors |
|
| 873 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | - // config is good, so set it and pass it back |
|
| 875 | - $this->{$section}->{$name} = $config_obj; |
|
| 876 | - return $this->{$section}->{$name}; |
|
| 877 | - } |
|
| 878 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | - // verify the newly created config object |
|
| 881 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | - return $this->{$section}->{$name}; |
|
| 883 | - } else { |
|
| 884 | - EE_Error::add_error( |
|
| 885 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | - __FILE__, |
|
| 887 | - __FUNCTION__, |
|
| 888 | - __LINE__ |
|
| 889 | - ); |
|
| 890 | - } |
|
| 891 | - return null; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * get_config_option |
|
| 897 | - * |
|
| 898 | - * @access public |
|
| 899 | - * @param string $config_option_name |
|
| 900 | - * @return mixed EE_Config_Base | FALSE |
|
| 901 | - */ |
|
| 902 | - public function get_config_option($config_option_name = '') |
|
| 903 | - { |
|
| 904 | - // retrieve the wp-option for this config class. |
|
| 905 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | - if (empty($config_option)) { |
|
| 907 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | - } |
|
| 909 | - return $config_option; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * log |
|
| 915 | - * |
|
| 916 | - * @param string $config_option_name |
|
| 917 | - */ |
|
| 918 | - public static function log($config_option_name = '') |
|
| 919 | - { |
|
| 920 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | - // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | - $_request = $_REQUEST; |
|
| 924 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | - $config_log[ (string) microtime(true) ] = array( |
|
| 926 | - 'config_name' => $config_option_name, |
|
| 927 | - 'request' => $_request, |
|
| 928 | - ); |
|
| 929 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * trim_log |
|
| 936 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | - */ |
|
| 938 | - public static function trim_log() |
|
| 939 | - { |
|
| 940 | - if (! EE_Config::logging_enabled()) { |
|
| 941 | - return; |
|
| 942 | - } |
|
| 943 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | - $log_length = count($config_log); |
|
| 945 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | - ksort($config_log); |
|
| 947 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * get_page_for_posts |
|
| 955 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | - * |
|
| 958 | - * @access public |
|
| 959 | - * @return string |
|
| 960 | - */ |
|
| 961 | - public static function get_page_for_posts() |
|
| 962 | - { |
|
| 963 | - $page_for_posts = get_option('page_for_posts'); |
|
| 964 | - if (! $page_for_posts) { |
|
| 965 | - return 'posts'; |
|
| 966 | - } |
|
| 967 | - /** @type WPDB $wpdb */ |
|
| 968 | - global $wpdb; |
|
| 969 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * register_shortcodes_and_modules. |
|
| 976 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | - * so they can help trigger maintenance mode if it's needed |
|
| 979 | - * |
|
| 980 | - * @access public |
|
| 981 | - * @return void |
|
| 982 | - */ |
|
| 983 | - public function register_shortcodes_and_modules() |
|
| 984 | - { |
|
| 985 | - // allow modules to set hooks for the rest of the system |
|
| 986 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * initialize_shortcodes_and_modules |
|
| 992 | - * meaning they can start adding their hooks to get stuff done |
|
| 993 | - * |
|
| 994 | - * @access public |
|
| 995 | - * @return void |
|
| 996 | - */ |
|
| 997 | - public function initialize_shortcodes_and_modules() |
|
| 998 | - { |
|
| 999 | - // allow modules to set hooks for the rest of the system |
|
| 1000 | - $this->_initialize_modules(); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * widgets_init |
|
| 1006 | - * |
|
| 1007 | - * @access private |
|
| 1008 | - * @return void |
|
| 1009 | - */ |
|
| 1010 | - public function widgets_init() |
|
| 1011 | - { |
|
| 1012 | - // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | - // on frontend when not in any maintenance mode |
|
| 1014 | - if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | - || ( |
|
| 1016 | - is_admin() |
|
| 1017 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | - ) |
|
| 1019 | - ) { |
|
| 1020 | - // grab list of installed widgets |
|
| 1021 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | - // filter list of modules to register |
|
| 1023 | - $widgets_to_register = apply_filters( |
|
| 1024 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | - $widgets_to_register |
|
| 1026 | - ); |
|
| 1027 | - if (! empty($widgets_to_register)) { |
|
| 1028 | - // cycle thru widget folders |
|
| 1029 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | - // add to list of installed widget modules |
|
| 1031 | - EE_Config::register_ee_widget($widget_path); |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - // filter list of installed modules |
|
| 1035 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | - EE_Registry::instance()->widgets |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * register_ee_widget - makes core aware of this widget |
|
| 1045 | - * |
|
| 1046 | - * @access public |
|
| 1047 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - public static function register_ee_widget($widget_path = null) |
|
| 1051 | - { |
|
| 1052 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | - $widget_ext = '.widget.php'; |
|
| 1054 | - // make all separators match |
|
| 1055 | - $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | - $file_name = explode('.', basename($widget_path)); |
|
| 1060 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | - // sanitize shortcode directory name |
|
| 1063 | - $widget = sanitize_key($widget); |
|
| 1064 | - // now we need to rebuild the shortcode path |
|
| 1065 | - $widget_path = explode('/', $widget_path); |
|
| 1066 | - // remove last segment |
|
| 1067 | - array_pop($widget_path); |
|
| 1068 | - // glue it back together |
|
| 1069 | - $widget_path = implode(DS, $widget_path); |
|
| 1070 | - } else { |
|
| 1071 | - // grab and sanitize widget directory name |
|
| 1072 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | - } |
|
| 1074 | - // create classname from widget directory name |
|
| 1075 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | - // add class prefix |
|
| 1077 | - $widget_class = 'EEW_' . $widget; |
|
| 1078 | - // does the widget exist ? |
|
| 1079 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1080 | - $msg = sprintf( |
|
| 1081 | - __( |
|
| 1082 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | - 'event_espresso' |
|
| 1084 | - ), |
|
| 1085 | - $widget_class, |
|
| 1086 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1087 | - ); |
|
| 1088 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | - return; |
|
| 1090 | - } |
|
| 1091 | - // load the widget class file |
|
| 1092 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1093 | - // verify that class exists |
|
| 1094 | - if (! class_exists($widget_class)) { |
|
| 1095 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | - return; |
|
| 1098 | - } |
|
| 1099 | - register_widget($widget_class); |
|
| 1100 | - // add to array of registered widgets |
|
| 1101 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * _register_modules |
|
| 1107 | - * |
|
| 1108 | - * @access private |
|
| 1109 | - * @return array |
|
| 1110 | - */ |
|
| 1111 | - private function _register_modules() |
|
| 1112 | - { |
|
| 1113 | - // grab list of installed modules |
|
| 1114 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | - // filter list of modules to register |
|
| 1116 | - $modules_to_register = apply_filters( |
|
| 1117 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | - $modules_to_register |
|
| 1119 | - ); |
|
| 1120 | - if (! empty($modules_to_register)) { |
|
| 1121 | - // loop through folders |
|
| 1122 | - foreach ($modules_to_register as $module_path) { |
|
| 1123 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | - if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | - ) { |
|
| 1127 | - // add to list of installed modules |
|
| 1128 | - EE_Config::register_module($module_path); |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - // filter list of installed modules |
|
| 1133 | - return apply_filters( |
|
| 1134 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | - EE_Registry::instance()->modules |
|
| 1136 | - ); |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - |
|
| 1140 | - /** |
|
| 1141 | - * register_module - makes core aware of this module |
|
| 1142 | - * |
|
| 1143 | - * @access public |
|
| 1144 | - * @param string $module_path - full path up to and including module folder |
|
| 1145 | - * @return bool |
|
| 1146 | - */ |
|
| 1147 | - public static function register_module($module_path = null) |
|
| 1148 | - { |
|
| 1149 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | - $module_ext = '.module.php'; |
|
| 1151 | - // make all separators match |
|
| 1152 | - $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1153 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | - $module_file = explode('.', basename($module_path)); |
|
| 1157 | - // now we need to rebuild the shortcode path |
|
| 1158 | - $module_path = explode('/', $module_path); |
|
| 1159 | - // remove last segment |
|
| 1160 | - array_pop($module_path); |
|
| 1161 | - // glue it back together |
|
| 1162 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1163 | - // take first segment from file name pieces and sanitize it |
|
| 1164 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | - // ensure class prefix is added |
|
| 1166 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | - } else { |
|
| 1168 | - // we need to generate the filename based off of the folder name |
|
| 1169 | - // grab and sanitize module name |
|
| 1170 | - $module = strtolower(basename($module_path)); |
|
| 1171 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | - // like trailingslashit() |
|
| 1173 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1174 | - // create classname from module directory name |
|
| 1175 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | - // add class prefix |
|
| 1177 | - $module_class = 'EED_' . $module; |
|
| 1178 | - } |
|
| 1179 | - // does the module exist ? |
|
| 1180 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1181 | - $msg = sprintf( |
|
| 1182 | - __( |
|
| 1183 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | - 'event_espresso' |
|
| 1185 | - ), |
|
| 1186 | - $module |
|
| 1187 | - ); |
|
| 1188 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | - return false; |
|
| 1190 | - } |
|
| 1191 | - // load the module class file |
|
| 1192 | - require_once($module_path . $module_class . $module_ext); |
|
| 1193 | - // verify that class exists |
|
| 1194 | - if (! class_exists($module_class)) { |
|
| 1195 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | - return false; |
|
| 1198 | - } |
|
| 1199 | - // add to array of registered modules |
|
| 1200 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | - do_action( |
|
| 1202 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | - $module_class, |
|
| 1204 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | - ); |
|
| 1206 | - return true; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * _initialize_modules |
|
| 1212 | - * allow modules to set hooks for the rest of the system |
|
| 1213 | - * |
|
| 1214 | - * @access private |
|
| 1215 | - * @return void |
|
| 1216 | - */ |
|
| 1217 | - private function _initialize_modules() |
|
| 1218 | - { |
|
| 1219 | - // cycle thru shortcode folders |
|
| 1220 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | - // which set hooks ? |
|
| 1223 | - if (is_admin()) { |
|
| 1224 | - // fire immediately |
|
| 1225 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | - } else { |
|
| 1227 | - // delay until other systems are online |
|
| 1228 | - add_action( |
|
| 1229 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | - array($module_class, 'set_hooks') |
|
| 1231 | - ); |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - |
|
| 1237 | - /** |
|
| 1238 | - * register_route - adds module method routes to route_map |
|
| 1239 | - * |
|
| 1240 | - * @access public |
|
| 1241 | - * @param string $route - "pretty" public alias for module method |
|
| 1242 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | - * @param string $method_name - the actual module method to be routed to |
|
| 1244 | - * @param string $key - url param key indicating a route is being called |
|
| 1245 | - * @return bool |
|
| 1246 | - */ |
|
| 1247 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | - { |
|
| 1249 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | - $module = str_replace('EED_', '', $module); |
|
| 1251 | - $module_class = 'EED_' . $module; |
|
| 1252 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | - return false; |
|
| 1256 | - } |
|
| 1257 | - if (empty($route)) { |
|
| 1258 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | - return false; |
|
| 1261 | - } |
|
| 1262 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | - $msg = sprintf( |
|
| 1264 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | - $route |
|
| 1266 | - ); |
|
| 1267 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | - return false; |
|
| 1269 | - } |
|
| 1270 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | - return true; |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - |
|
| 1275 | - /** |
|
| 1276 | - * get_route - get module method route |
|
| 1277 | - * |
|
| 1278 | - * @access public |
|
| 1279 | - * @param string $route - "pretty" public alias for module method |
|
| 1280 | - * @param string $key - url param key indicating a route is being called |
|
| 1281 | - * @return string |
|
| 1282 | - */ |
|
| 1283 | - public static function get_route($route = null, $key = 'ee') |
|
| 1284 | - { |
|
| 1285 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | - $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | - } |
|
| 1290 | - return null; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - /** |
|
| 1295 | - * get_routes - get ALL module method routes |
|
| 1296 | - * |
|
| 1297 | - * @access public |
|
| 1298 | - * @return array |
|
| 1299 | - */ |
|
| 1300 | - public static function get_routes() |
|
| 1301 | - { |
|
| 1302 | - return EE_Config::$_module_route_map; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - |
|
| 1306 | - /** |
|
| 1307 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | - * |
|
| 1309 | - * @access public |
|
| 1310 | - * @param string $route - "pretty" public alias for module method |
|
| 1311 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | - * class, allows different forwards to be served based on status |
|
| 1313 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | - * @param string $key - url param key indicating a route is being called |
|
| 1315 | - * @return bool |
|
| 1316 | - */ |
|
| 1317 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | - { |
|
| 1319 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | - $msg = sprintf( |
|
| 1322 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | - $route |
|
| 1324 | - ); |
|
| 1325 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | - return false; |
|
| 1327 | - } |
|
| 1328 | - if (empty($forward)) { |
|
| 1329 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | - return false; |
|
| 1332 | - } |
|
| 1333 | - if (is_array($forward)) { |
|
| 1334 | - if (! isset($forward[1])) { |
|
| 1335 | - $msg = sprintf( |
|
| 1336 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | - $route |
|
| 1338 | - ); |
|
| 1339 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | - return false; |
|
| 1341 | - } |
|
| 1342 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | - $msg = sprintf( |
|
| 1344 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | - $forward[1], |
|
| 1346 | - $route |
|
| 1347 | - ); |
|
| 1348 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | - return false; |
|
| 1350 | - } |
|
| 1351 | - } elseif (! function_exists($forward)) { |
|
| 1352 | - $msg = sprintf( |
|
| 1353 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | - $forward, |
|
| 1355 | - $route |
|
| 1356 | - ); |
|
| 1357 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | - return false; |
|
| 1359 | - } |
|
| 1360 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | - return true; |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - /** |
|
| 1366 | - * get_forward - get forwarding route |
|
| 1367 | - * |
|
| 1368 | - * @access public |
|
| 1369 | - * @param string $route - "pretty" public alias for module method |
|
| 1370 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | - * allows different forwards to be served based on status |
|
| 1372 | - * @param string $key - url param key indicating a route is being called |
|
| 1373 | - * @return string |
|
| 1374 | - */ |
|
| 1375 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | - { |
|
| 1377 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | - return apply_filters( |
|
| 1380 | - 'FHEE__EE_Config__get_forward', |
|
| 1381 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | - $route, |
|
| 1383 | - $status |
|
| 1384 | - ); |
|
| 1385 | - } |
|
| 1386 | - return null; |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - |
|
| 1390 | - /** |
|
| 1391 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | - * results |
|
| 1393 | - * |
|
| 1394 | - * @access public |
|
| 1395 | - * @param string $route - "pretty" public alias for module method |
|
| 1396 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | - * allows different views to be served based on status |
|
| 1398 | - * @param string $view |
|
| 1399 | - * @param string $key - url param key indicating a route is being called |
|
| 1400 | - * @return bool |
|
| 1401 | - */ |
|
| 1402 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | - { |
|
| 1404 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | - $msg = sprintf( |
|
| 1407 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | - $route |
|
| 1409 | - ); |
|
| 1410 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | - return false; |
|
| 1412 | - } |
|
| 1413 | - if (! is_readable($view)) { |
|
| 1414 | - $msg = sprintf( |
|
| 1415 | - __( |
|
| 1416 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | - 'event_espresso' |
|
| 1418 | - ), |
|
| 1419 | - $view |
|
| 1420 | - ); |
|
| 1421 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | - return false; |
|
| 1423 | - } |
|
| 1424 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | - return true; |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * get_view - get view for route and status |
|
| 1431 | - * |
|
| 1432 | - * @access public |
|
| 1433 | - * @param string $route - "pretty" public alias for module method |
|
| 1434 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | - * allows different views to be served based on status |
|
| 1436 | - * @param string $key - url param key indicating a route is being called |
|
| 1437 | - * @return string |
|
| 1438 | - */ |
|
| 1439 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | - { |
|
| 1441 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | - return apply_filters( |
|
| 1444 | - 'FHEE__EE_Config__get_view', |
|
| 1445 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | - $route, |
|
| 1447 | - $status |
|
| 1448 | - ); |
|
| 1449 | - } |
|
| 1450 | - return null; |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - |
|
| 1454 | - public function update_addon_option_names() |
|
| 1455 | - { |
|
| 1456 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - public function shutdown() |
|
| 1461 | - { |
|
| 1462 | - $this->update_addon_option_names(); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * @return LegacyShortcodesManager |
|
| 1468 | - */ |
|
| 1469 | - public static function getLegacyShortcodesManager() |
|
| 1470 | - { |
|
| 1471 | - |
|
| 1472 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | - EE_Registry::instance() |
|
| 1475 | - ); |
|
| 1476 | - } |
|
| 1477 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * register_shortcode - makes core aware of this shortcode |
|
| 1483 | - * |
|
| 1484 | - * @deprecated 4.9.26 |
|
| 1485 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | - * @return bool |
|
| 1487 | - */ |
|
| 1488 | - public static function register_shortcode($shortcode_path = null) |
|
| 1489 | - { |
|
| 1490 | - EE_Error::doing_it_wrong( |
|
| 1491 | - __METHOD__, |
|
| 1492 | - __( |
|
| 1493 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | - 'event_espresso' |
|
| 1495 | - ), |
|
| 1496 | - '4.9.26' |
|
| 1497 | - ); |
|
| 1498 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | - } |
|
| 1500 | -} |
|
| 1501 | - |
|
| 1502 | -/** |
|
| 1503 | - * Base class used for config classes. These classes should generally not have |
|
| 1504 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | - * basically, they should just be well-defined stdClasses |
|
| 1506 | - */ |
|
| 1507 | -class EE_Config_Base |
|
| 1508 | -{ |
|
| 1509 | - |
|
| 1510 | - /** |
|
| 1511 | - * Utility function for escaping the value of a property and returning. |
|
| 1512 | - * |
|
| 1513 | - * @param string $property property name (checks to see if exists). |
|
| 1514 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | - * @throws \EE_Error |
|
| 1516 | - */ |
|
| 1517 | - public function get_pretty($property) |
|
| 1518 | - { |
|
| 1519 | - if (! property_exists($this, $property)) { |
|
| 1520 | - throw new EE_Error( |
|
| 1521 | - sprintf( |
|
| 1522 | - __( |
|
| 1523 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | - 'event_espresso' |
|
| 1525 | - ), |
|
| 1526 | - get_class($this), |
|
| 1527 | - $property |
|
| 1528 | - ) |
|
| 1529 | - ); |
|
| 1530 | - } |
|
| 1531 | - // just handling escaping of strings for now. |
|
| 1532 | - if (is_string($this->{$property})) { |
|
| 1533 | - return stripslashes($this->{$property}); |
|
| 1534 | - } |
|
| 1535 | - return $this->{$property}; |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - |
|
| 1539 | - public function populate() |
|
| 1540 | - { |
|
| 1541 | - // grab defaults via a new instance of this class. |
|
| 1542 | - $class_name = get_class($this); |
|
| 1543 | - $defaults = new $class_name; |
|
| 1544 | - // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | - // default from our $defaults object. |
|
| 1546 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | - if ($this->{$property} === null) { |
|
| 1548 | - $this->{$property} = $value; |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - // cleanup |
|
| 1552 | - unset($defaults); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * __isset |
|
| 1558 | - * |
|
| 1559 | - * @param $a |
|
| 1560 | - * @return bool |
|
| 1561 | - */ |
|
| 1562 | - public function __isset($a) |
|
| 1563 | - { |
|
| 1564 | - return false; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * __unset |
|
| 1570 | - * |
|
| 1571 | - * @param $a |
|
| 1572 | - * @return bool |
|
| 1573 | - */ |
|
| 1574 | - public function __unset($a) |
|
| 1575 | - { |
|
| 1576 | - return false; |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - |
|
| 1580 | - /** |
|
| 1581 | - * __clone |
|
| 1582 | - */ |
|
| 1583 | - public function __clone() |
|
| 1584 | - { |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * __wakeup |
|
| 1590 | - */ |
|
| 1591 | - public function __wakeup() |
|
| 1592 | - { |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * __destruct |
|
| 1598 | - */ |
|
| 1599 | - public function __destruct() |
|
| 1600 | - { |
|
| 1601 | - } |
|
| 1602 | -} |
|
| 1603 | - |
|
| 1604 | -/** |
|
| 1605 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | - */ |
|
| 1607 | -class EE_Core_Config extends EE_Config_Base |
|
| 1608 | -{ |
|
| 1609 | - |
|
| 1610 | - const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | - |
|
| 1612 | - |
|
| 1613 | - public $current_blog_id; |
|
| 1614 | - |
|
| 1615 | - public $ee_ueip_optin; |
|
| 1616 | - |
|
| 1617 | - public $ee_ueip_has_notified; |
|
| 1618 | - |
|
| 1619 | - /** |
|
| 1620 | - * Not to be confused with the 4 critical page variables (See |
|
| 1621 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | - * |
|
| 1625 | - * @var array |
|
| 1626 | - */ |
|
| 1627 | - public $post_shortcodes; |
|
| 1628 | - |
|
| 1629 | - public $module_route_map; |
|
| 1630 | - |
|
| 1631 | - public $module_forward_map; |
|
| 1632 | - |
|
| 1633 | - public $module_view_map; |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | - * |
|
| 1638 | - * @var int |
|
| 1639 | - */ |
|
| 1640 | - public $reg_page_id; |
|
| 1641 | - |
|
| 1642 | - public $txn_page_id; |
|
| 1643 | - |
|
| 1644 | - public $thank_you_page_id; |
|
| 1645 | - |
|
| 1646 | - public $cancel_page_id; |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | - * |
|
| 1651 | - * @var int |
|
| 1652 | - */ |
|
| 1653 | - public $reg_page_url; |
|
| 1654 | - |
|
| 1655 | - public $txn_page_url; |
|
| 1656 | - |
|
| 1657 | - public $thank_you_page_url; |
|
| 1658 | - |
|
| 1659 | - public $cancel_page_url; |
|
| 1660 | - |
|
| 1661 | - /** |
|
| 1662 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | - */ |
|
| 1664 | - public $event_cpt_slug; |
|
| 1665 | - |
|
| 1666 | - /** |
|
| 1667 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | - * request across blog switches in a multisite context. |
|
| 1669 | - * Avoids extra queries to the db for this option. |
|
| 1670 | - * |
|
| 1671 | - * @var bool |
|
| 1672 | - */ |
|
| 1673 | - public static $ee_ueip_option; |
|
| 1674 | - |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * class constructor |
|
| 1678 | - * |
|
| 1679 | - * @access public |
|
| 1680 | - */ |
|
| 1681 | - public function __construct() |
|
| 1682 | - { |
|
| 1683 | - // set default organization settings |
|
| 1684 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | - $this->post_shortcodes = array(); |
|
| 1689 | - $this->module_route_map = array(); |
|
| 1690 | - $this->module_forward_map = array(); |
|
| 1691 | - $this->module_view_map = array(); |
|
| 1692 | - // critical EE page IDs |
|
| 1693 | - $this->reg_page_id = 0; |
|
| 1694 | - $this->txn_page_id = 0; |
|
| 1695 | - $this->thank_you_page_id = 0; |
|
| 1696 | - $this->cancel_page_id = 0; |
|
| 1697 | - // critical EE page URLs |
|
| 1698 | - $this->reg_page_url = ''; |
|
| 1699 | - $this->txn_page_url = ''; |
|
| 1700 | - $this->thank_you_page_url = ''; |
|
| 1701 | - $this->cancel_page_url = ''; |
|
| 1702 | - // cpt slugs |
|
| 1703 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | - // ueip constant check |
|
| 1705 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | - $this->ee_ueip_optin = false; |
|
| 1707 | - $this->ee_ueip_has_notified = true; |
|
| 1708 | - } |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * @return array |
|
| 1714 | - */ |
|
| 1715 | - public function get_critical_pages_array() |
|
| 1716 | - { |
|
| 1717 | - return array( |
|
| 1718 | - $this->reg_page_id, |
|
| 1719 | - $this->txn_page_id, |
|
| 1720 | - $this->thank_you_page_id, |
|
| 1721 | - $this->cancel_page_id, |
|
| 1722 | - ); |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - |
|
| 1726 | - /** |
|
| 1727 | - * @return array |
|
| 1728 | - */ |
|
| 1729 | - public function get_critical_pages_shortcodes_array() |
|
| 1730 | - { |
|
| 1731 | - return array( |
|
| 1732 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | - ); |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * gets/returns URL for EE reg_page |
|
| 1742 | - * |
|
| 1743 | - * @access public |
|
| 1744 | - * @return string |
|
| 1745 | - */ |
|
| 1746 | - public function reg_page_url() |
|
| 1747 | - { |
|
| 1748 | - if (! $this->reg_page_url) { |
|
| 1749 | - $this->reg_page_url = add_query_arg( |
|
| 1750 | - array('uts' => time()), |
|
| 1751 | - get_permalink($this->reg_page_id) |
|
| 1752 | - ) . '#checkout'; |
|
| 1753 | - } |
|
| 1754 | - return $this->reg_page_url; |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - |
|
| 1758 | - /** |
|
| 1759 | - * gets/returns URL for EE txn_page |
|
| 1760 | - * |
|
| 1761 | - * @param array $query_args like what gets passed to |
|
| 1762 | - * add_query_arg() as the first argument |
|
| 1763 | - * @access public |
|
| 1764 | - * @return string |
|
| 1765 | - */ |
|
| 1766 | - public function txn_page_url($query_args = array()) |
|
| 1767 | - { |
|
| 1768 | - if (! $this->txn_page_url) { |
|
| 1769 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | - } |
|
| 1771 | - if ($query_args) { |
|
| 1772 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | - } else { |
|
| 1774 | - return $this->txn_page_url; |
|
| 1775 | - } |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - |
|
| 1779 | - /** |
|
| 1780 | - * gets/returns URL for EE thank_you_page |
|
| 1781 | - * |
|
| 1782 | - * @param array $query_args like what gets passed to |
|
| 1783 | - * add_query_arg() as the first argument |
|
| 1784 | - * @access public |
|
| 1785 | - * @return string |
|
| 1786 | - */ |
|
| 1787 | - public function thank_you_page_url($query_args = array()) |
|
| 1788 | - { |
|
| 1789 | - if (! $this->thank_you_page_url) { |
|
| 1790 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | - } |
|
| 1792 | - if ($query_args) { |
|
| 1793 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | - } else { |
|
| 1795 | - return $this->thank_you_page_url; |
|
| 1796 | - } |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * gets/returns URL for EE cancel_page |
|
| 1802 | - * |
|
| 1803 | - * @access public |
|
| 1804 | - * @return string |
|
| 1805 | - */ |
|
| 1806 | - public function cancel_page_url() |
|
| 1807 | - { |
|
| 1808 | - if (! $this->cancel_page_url) { |
|
| 1809 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | - } |
|
| 1811 | - return $this->cancel_page_url; |
|
| 1812 | - } |
|
| 1813 | - |
|
| 1814 | - |
|
| 1815 | - /** |
|
| 1816 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | - * |
|
| 1818 | - * @since 4.7.5 |
|
| 1819 | - */ |
|
| 1820 | - protected function _reset_urls() |
|
| 1821 | - { |
|
| 1822 | - $this->reg_page_url = ''; |
|
| 1823 | - $this->txn_page_url = ''; |
|
| 1824 | - $this->cancel_page_url = ''; |
|
| 1825 | - $this->thank_you_page_url = ''; |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | - * on the main site only. |
|
| 1833 | - * |
|
| 1834 | - * @return bool |
|
| 1835 | - */ |
|
| 1836 | - protected function _get_main_ee_ueip_optin() |
|
| 1837 | - { |
|
| 1838 | - // if this is the main site then we can just bypass our direct query. |
|
| 1839 | - if (is_main_site()) { |
|
| 1840 | - return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | - } |
|
| 1842 | - // is this already cached for this request? If so use it. |
|
| 1843 | - if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | - } |
|
| 1846 | - global $wpdb; |
|
| 1847 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | - $option = self::OPTION_NAME_UXIP; |
|
| 1850 | - // set correct table for query |
|
| 1851 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | - // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | - // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | - // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | - // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | - // for the purpose of caching. |
|
| 1857 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | - if (false !== $pre) { |
|
| 1859 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | - } |
|
| 1862 | - $row = $wpdb->get_row( |
|
| 1863 | - $wpdb->prepare( |
|
| 1864 | - "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | - $option |
|
| 1866 | - ) |
|
| 1867 | - ); |
|
| 1868 | - if (is_object($row)) { |
|
| 1869 | - $value = $row->option_value; |
|
| 1870 | - } else { // option does not exist so use default. |
|
| 1871 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | - } |
|
| 1874 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - /** |
|
| 1880 | - * Utility function for escaping the value of a property and returning. |
|
| 1881 | - * |
|
| 1882 | - * @param string $property property name (checks to see if exists). |
|
| 1883 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | - * @throws \EE_Error |
|
| 1885 | - */ |
|
| 1886 | - public function get_pretty($property) |
|
| 1887 | - { |
|
| 1888 | - if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | - } |
|
| 1891 | - return parent::get_pretty($property); |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - |
|
| 1895 | - /** |
|
| 1896 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | - * on the object. |
|
| 1898 | - * |
|
| 1899 | - * @return array |
|
| 1900 | - */ |
|
| 1901 | - public function __sleep() |
|
| 1902 | - { |
|
| 1903 | - // reset all url properties |
|
| 1904 | - $this->_reset_urls(); |
|
| 1905 | - // return what to save to db |
|
| 1906 | - return array_keys(get_object_vars($this)); |
|
| 1907 | - } |
|
| 1908 | -} |
|
| 1909 | - |
|
| 1910 | -/** |
|
| 1911 | - * Config class for storing info on the Organization |
|
| 1912 | - */ |
|
| 1913 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | -{ |
|
| 1915 | - |
|
| 1916 | - /** |
|
| 1917 | - * @var string $name |
|
| 1918 | - * eg EE4.1 |
|
| 1919 | - */ |
|
| 1920 | - public $name; |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * @var string $address_1 |
|
| 1924 | - * eg 123 Onna Road |
|
| 1925 | - */ |
|
| 1926 | - public $address_1 = ''; |
|
| 1927 | - |
|
| 1928 | - /** |
|
| 1929 | - * @var string $address_2 |
|
| 1930 | - * eg PO Box 123 |
|
| 1931 | - */ |
|
| 1932 | - public $address_2 = ''; |
|
| 1933 | - |
|
| 1934 | - /** |
|
| 1935 | - * @var string $city |
|
| 1936 | - * eg Inna City |
|
| 1937 | - */ |
|
| 1938 | - public $city = ''; |
|
| 1939 | - |
|
| 1940 | - /** |
|
| 1941 | - * @var int $STA_ID |
|
| 1942 | - * eg 4 |
|
| 1943 | - */ |
|
| 1944 | - public $STA_ID = 0; |
|
| 1945 | - |
|
| 1946 | - /** |
|
| 1947 | - * @var string $CNT_ISO |
|
| 1948 | - * eg US |
|
| 1949 | - */ |
|
| 1950 | - public $CNT_ISO = ''; |
|
| 1951 | - |
|
| 1952 | - /** |
|
| 1953 | - * @var string $zip |
|
| 1954 | - * eg 12345 or V1A 2B3 |
|
| 1955 | - */ |
|
| 1956 | - public $zip = ''; |
|
| 1957 | - |
|
| 1958 | - /** |
|
| 1959 | - * @var string $email |
|
| 1960 | - * eg [email protected] |
|
| 1961 | - */ |
|
| 1962 | - public $email; |
|
| 1963 | - |
|
| 1964 | - /** |
|
| 1965 | - * @var string $phone |
|
| 1966 | - * eg. 111-111-1111 |
|
| 1967 | - */ |
|
| 1968 | - public $phone = ''; |
|
| 1969 | - |
|
| 1970 | - /** |
|
| 1971 | - * @var string $vat |
|
| 1972 | - * VAT/Tax Number |
|
| 1973 | - */ |
|
| 1974 | - public $vat = ''; |
|
| 1975 | - |
|
| 1976 | - /** |
|
| 1977 | - * @var string $logo_url |
|
| 1978 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | - */ |
|
| 1980 | - public $logo_url = ''; |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | - * |
|
| 1985 | - * @var string |
|
| 1986 | - */ |
|
| 1987 | - /** |
|
| 1988 | - * facebook (facebook.com/profile.name) |
|
| 1989 | - * |
|
| 1990 | - * @var string |
|
| 1991 | - */ |
|
| 1992 | - public $facebook = ''; |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * twitter (twitter.com/twitter_handle) |
|
| 1996 | - * |
|
| 1997 | - * @var string |
|
| 1998 | - */ |
|
| 1999 | - public $twitter = ''; |
|
| 2000 | - |
|
| 2001 | - /** |
|
| 2002 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | - * |
|
| 2004 | - * @var string |
|
| 2005 | - */ |
|
| 2006 | - public $linkedin = ''; |
|
| 2007 | - |
|
| 2008 | - /** |
|
| 2009 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | - * |
|
| 2011 | - * @var string |
|
| 2012 | - */ |
|
| 2013 | - public $pinterest = ''; |
|
| 2014 | - |
|
| 2015 | - /** |
|
| 2016 | - * google+ (google.com/+profileName) |
|
| 2017 | - * |
|
| 2018 | - * @var string |
|
| 2019 | - */ |
|
| 2020 | - public $google = ''; |
|
| 2021 | - |
|
| 2022 | - /** |
|
| 2023 | - * instagram (instagram.com/handle) |
|
| 2024 | - * |
|
| 2025 | - * @var string |
|
| 2026 | - */ |
|
| 2027 | - public $instagram = ''; |
|
| 2028 | - |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * class constructor |
|
| 2032 | - * |
|
| 2033 | - * @access public |
|
| 2034 | - */ |
|
| 2035 | - public function __construct() |
|
| 2036 | - { |
|
| 2037 | - // set default organization settings |
|
| 2038 | - // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | - $this->email = get_bloginfo('admin_email'); |
|
| 2041 | - } |
|
| 2042 | -} |
|
| 2043 | - |
|
| 2044 | -/** |
|
| 2045 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2046 | - */ |
|
| 2047 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2048 | -{ |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * @var string $code |
|
| 2052 | - * eg 'US' |
|
| 2053 | - */ |
|
| 2054 | - public $code; |
|
| 2055 | - |
|
| 2056 | - /** |
|
| 2057 | - * @var string $name |
|
| 2058 | - * eg 'Dollar' |
|
| 2059 | - */ |
|
| 2060 | - public $name; |
|
| 2061 | - |
|
| 2062 | - /** |
|
| 2063 | - * plural name |
|
| 2064 | - * |
|
| 2065 | - * @var string $plural |
|
| 2066 | - * eg 'Dollars' |
|
| 2067 | - */ |
|
| 2068 | - public $plural; |
|
| 2069 | - |
|
| 2070 | - /** |
|
| 2071 | - * currency sign |
|
| 2072 | - * |
|
| 2073 | - * @var string $sign |
|
| 2074 | - * eg '$' |
|
| 2075 | - */ |
|
| 2076 | - public $sign; |
|
| 2077 | - |
|
| 2078 | - /** |
|
| 2079 | - * Whether the currency sign should come before the number or not |
|
| 2080 | - * |
|
| 2081 | - * @var boolean $sign_b4 |
|
| 2082 | - */ |
|
| 2083 | - public $sign_b4; |
|
| 2084 | - |
|
| 2085 | - /** |
|
| 2086 | - * How many digits should come after the decimal place |
|
| 2087 | - * |
|
| 2088 | - * @var int $dec_plc |
|
| 2089 | - */ |
|
| 2090 | - public $dec_plc; |
|
| 2091 | - |
|
| 2092 | - /** |
|
| 2093 | - * Symbol to use for decimal mark |
|
| 2094 | - * |
|
| 2095 | - * @var string $dec_mrk |
|
| 2096 | - * eg '.' |
|
| 2097 | - */ |
|
| 2098 | - public $dec_mrk; |
|
| 2099 | - |
|
| 2100 | - /** |
|
| 2101 | - * Symbol to use for thousands |
|
| 2102 | - * |
|
| 2103 | - * @var string $thsnds |
|
| 2104 | - * eg ',' |
|
| 2105 | - */ |
|
| 2106 | - public $thsnds; |
|
| 2107 | - |
|
| 2108 | - |
|
| 2109 | - /** |
|
| 2110 | - * class constructor |
|
| 2111 | - * |
|
| 2112 | - * @access public |
|
| 2113 | - * @param string $CNT_ISO |
|
| 2114 | - * @throws \EE_Error |
|
| 2115 | - */ |
|
| 2116 | - public function __construct($CNT_ISO = '') |
|
| 2117 | - { |
|
| 2118 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2119 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2120 | - // get country code from organization settings or use default |
|
| 2121 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2122 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2123 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2124 | - : ''; |
|
| 2125 | - // but override if requested |
|
| 2126 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2127 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2128 | - if (! empty($CNT_ISO) |
|
| 2129 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2130 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2131 | - ) { |
|
| 2132 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2133 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2134 | - if ($country instanceof EE_Country) { |
|
| 2135 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | - $this->sign_b4 = $country->currency_sign_before( |
|
| 2140 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | - $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2143 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | - $this->thsnds = $country->currency_thousands_separator( |
|
| 2145 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | - } |
|
| 2147 | - } |
|
| 2148 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2149 | - if (empty($this->code)) { |
|
| 2150 | - // set default currency settings |
|
| 2151 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | - $this->sign = '$'; // currency sign: $ |
|
| 2155 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | - } |
|
| 2160 | - } |
|
| 2161 | -} |
|
| 2162 | - |
|
| 2163 | -/** |
|
| 2164 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2165 | - */ |
|
| 2166 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2167 | -{ |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * Default registration status |
|
| 2171 | - * |
|
| 2172 | - * @var string $default_STS_ID |
|
| 2173 | - * eg 'RPP' |
|
| 2174 | - */ |
|
| 2175 | - public $default_STS_ID; |
|
| 2176 | - |
|
| 2177 | - /** |
|
| 2178 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2179 | - * registrations) |
|
| 2180 | - * |
|
| 2181 | - * @var int |
|
| 2182 | - */ |
|
| 2183 | - public $default_maximum_number_of_tickets; |
|
| 2184 | - |
|
| 2185 | - /** |
|
| 2186 | - * level of validation to apply to email addresses |
|
| 2187 | - * |
|
| 2188 | - * @var string $email_validation_level |
|
| 2189 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2190 | - */ |
|
| 2191 | - public $email_validation_level; |
|
| 2192 | - |
|
| 2193 | - /** |
|
| 2194 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2195 | - * |
|
| 2196 | - * @var boolean $show_pending_payment_options |
|
| 2197 | - */ |
|
| 2198 | - public $show_pending_payment_options; |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * Whether to skip the registration confirmation page |
|
| 2202 | - * |
|
| 2203 | - * @var boolean $skip_reg_confirmation |
|
| 2204 | - */ |
|
| 2205 | - public $skip_reg_confirmation; |
|
| 2206 | - |
|
| 2207 | - /** |
|
| 2208 | - * an array of SPCO reg steps where: |
|
| 2209 | - * the keys denotes the reg step order |
|
| 2210 | - * each element consists of an array with the following elements: |
|
| 2211 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2212 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2213 | - * "slug" => the URL param used to trigger the reg step |
|
| 2214 | - * |
|
| 2215 | - * @var array $reg_steps |
|
| 2216 | - */ |
|
| 2217 | - public $reg_steps; |
|
| 2218 | - |
|
| 2219 | - /** |
|
| 2220 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2221 | - * |
|
| 2222 | - * @var boolean $reg_confirmation_last |
|
| 2223 | - */ |
|
| 2224 | - public $reg_confirmation_last; |
|
| 2225 | - |
|
| 2226 | - /** |
|
| 2227 | - * Whether or not to enable the EE Bot Trap |
|
| 2228 | - * |
|
| 2229 | - * @var boolean $use_bot_trap |
|
| 2230 | - */ |
|
| 2231 | - public $use_bot_trap; |
|
| 2232 | - |
|
| 2233 | - /** |
|
| 2234 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2235 | - * |
|
| 2236 | - * @var boolean $use_encryption |
|
| 2237 | - */ |
|
| 2238 | - public $use_encryption; |
|
| 2239 | - |
|
| 2240 | - /** |
|
| 2241 | - * Whether or not to use ReCaptcha |
|
| 2242 | - * |
|
| 2243 | - * @var boolean $use_captcha |
|
| 2244 | - */ |
|
| 2245 | - public $use_captcha; |
|
| 2246 | - |
|
| 2247 | - /** |
|
| 2248 | - * ReCaptcha Theme |
|
| 2249 | - * |
|
| 2250 | - * @var string $recaptcha_theme |
|
| 2251 | - * options: 'dark', 'light', 'invisible' |
|
| 2252 | - */ |
|
| 2253 | - public $recaptcha_theme; |
|
| 2254 | - |
|
| 2255 | - /** |
|
| 2256 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2257 | - * |
|
| 2258 | - * @var string $recaptcha_badge |
|
| 2259 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2260 | - */ |
|
| 2261 | - public $recaptcha_badge; |
|
| 17 | + const OPTION_NAME = 'ee_config'; |
|
| 18 | + |
|
| 19 | + const LOG_NAME = 'ee_config_log'; |
|
| 20 | + |
|
| 21 | + const LOG_LENGTH = 100; |
|
| 22 | + |
|
| 23 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * instance of the EE_Config object |
|
| 27 | + * |
|
| 28 | + * @var EE_Config $_instance |
|
| 29 | + * @access private |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var boolean $_logging_enabled |
|
| 35 | + */ |
|
| 36 | + private static $_logging_enabled = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | + */ |
|
| 41 | + private $legacy_shortcodes_manager; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * An StdClass whose property names are addon slugs, |
|
| 45 | + * and values are their config classes |
|
| 46 | + * |
|
| 47 | + * @var StdClass |
|
| 48 | + */ |
|
| 49 | + public $addons; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var EE_Admin_Config |
|
| 53 | + */ |
|
| 54 | + public $admin; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var EE_Core_Config |
|
| 58 | + */ |
|
| 59 | + public $core; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var EE_Currency_Config |
|
| 63 | + */ |
|
| 64 | + public $currency; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var EE_Organization_Config |
|
| 68 | + */ |
|
| 69 | + public $organization; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var EE_Registration_Config |
|
| 73 | + */ |
|
| 74 | + public $registration; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var EE_Template_Config |
|
| 78 | + */ |
|
| 79 | + public $template_settings; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Holds EE environment values. |
|
| 83 | + * |
|
| 84 | + * @var EE_Environment_Config |
|
| 85 | + */ |
|
| 86 | + public $environment; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * settings pertaining to Google maps |
|
| 90 | + * |
|
| 91 | + * @var EE_Map_Config |
|
| 92 | + */ |
|
| 93 | + public $map_settings; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * settings pertaining to Taxes |
|
| 97 | + * |
|
| 98 | + * @var EE_Tax_Config |
|
| 99 | + */ |
|
| 100 | + public $tax_settings; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Settings pertaining to global messages settings. |
|
| 104 | + * |
|
| 105 | + * @var EE_Messages_Config |
|
| 106 | + */ |
|
| 107 | + public $messages; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated |
|
| 111 | + * @var EE_Gateway_Config |
|
| 112 | + */ |
|
| 113 | + public $gateway; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var array $_addon_option_names |
|
| 117 | + * @access private |
|
| 118 | + */ |
|
| 119 | + private $_addon_option_names = array(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @var array $_module_route_map |
|
| 123 | + * @access private |
|
| 124 | + */ |
|
| 125 | + private static $_module_route_map = array(); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var array $_module_forward_map |
|
| 129 | + * @access private |
|
| 130 | + */ |
|
| 131 | + private static $_module_forward_map = array(); |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @var array $_module_view_map |
|
| 135 | + * @access private |
|
| 136 | + */ |
|
| 137 | + private static $_module_view_map = array(); |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @singleton method used to instantiate class object |
|
| 142 | + * @access public |
|
| 143 | + * @return EE_Config instance |
|
| 144 | + */ |
|
| 145 | + public static function instance() |
|
| 146 | + { |
|
| 147 | + // check if class object is instantiated, and instantiated properly |
|
| 148 | + if (! self::$_instance instanceof EE_Config) { |
|
| 149 | + self::$_instance = new self(); |
|
| 150 | + } |
|
| 151 | + return self::$_instance; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Resets the config |
|
| 157 | + * |
|
| 158 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | + * reflect its state in the database |
|
| 161 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | + * site was put into maintenance mode) |
|
| 165 | + * @return EE_Config |
|
| 166 | + */ |
|
| 167 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | + { |
|
| 169 | + if (self::$_instance instanceof EE_Config) { |
|
| 170 | + if ($hard_reset) { |
|
| 171 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | + self::$_instance->_addon_option_names = array(); |
|
| 173 | + self::$_instance->_initialize_config(); |
|
| 174 | + self::$_instance->update_espresso_config(); |
|
| 175 | + } |
|
| 176 | + self::$_instance->update_addon_option_names(); |
|
| 177 | + } |
|
| 178 | + self::$_instance = null; |
|
| 179 | + // we don't need to reset the static properties imo because those should |
|
| 180 | + // only change when a module is added or removed. Currently we don't |
|
| 181 | + // support removing a module during a request when it previously existed |
|
| 182 | + if ($reinstantiate) { |
|
| 183 | + return self::instance(); |
|
| 184 | + } else { |
|
| 185 | + return null; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * class constructor |
|
| 192 | + * |
|
| 193 | + * @access private |
|
| 194 | + */ |
|
| 195 | + private function __construct() |
|
| 196 | + { |
|
| 197 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | + // setup empty config classes |
|
| 200 | + $this->_initialize_config(); |
|
| 201 | + // load existing EE site settings |
|
| 202 | + $this->_load_core_config(); |
|
| 203 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | + $this->_verify_config(); |
|
| 205 | + // register shortcodes and modules |
|
| 206 | + add_action( |
|
| 207 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | + array($this, 'register_shortcodes_and_modules'), |
|
| 209 | + 999 |
|
| 210 | + ); |
|
| 211 | + // initialize shortcodes and modules |
|
| 212 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | + // register widgets |
|
| 214 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | + // shutdown |
|
| 216 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | + // construct__end hook |
|
| 218 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | + // hardcoded hack |
|
| 220 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @return boolean |
|
| 226 | + */ |
|
| 227 | + public static function logging_enabled() |
|
| 228 | + { |
|
| 229 | + return self::$_logging_enabled; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * use to get the current theme if needed from static context |
|
| 235 | + * |
|
| 236 | + * @return string current theme set. |
|
| 237 | + */ |
|
| 238 | + public static function get_current_theme() |
|
| 239 | + { |
|
| 240 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * _initialize_config |
|
| 247 | + * |
|
| 248 | + * @access private |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + private function _initialize_config() |
|
| 252 | + { |
|
| 253 | + EE_Config::trim_log(); |
|
| 254 | + // set defaults |
|
| 255 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | + $this->addons = new stdClass(); |
|
| 257 | + // set _module_route_map |
|
| 258 | + EE_Config::$_module_route_map = array(); |
|
| 259 | + // set _module_forward_map |
|
| 260 | + EE_Config::$_module_forward_map = array(); |
|
| 261 | + // set _module_view_map |
|
| 262 | + EE_Config::$_module_view_map = array(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * load core plugin configuration |
|
| 268 | + * |
|
| 269 | + * @access private |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + private function _load_core_config() |
|
| 273 | + { |
|
| 274 | + // load_core_config__start hook |
|
| 275 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | + $espresso_config = $this->get_espresso_config(); |
|
| 277 | + foreach ($espresso_config as $config => $settings) { |
|
| 278 | + // load_core_config__start hook |
|
| 279 | + $settings = apply_filters( |
|
| 280 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | + $settings, |
|
| 282 | + $config, |
|
| 283 | + $this |
|
| 284 | + ); |
|
| 285 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | + // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | + if (method_exists($settings, 'populate')) { |
|
| 289 | + $this->{$config}->populate(); |
|
| 290 | + } |
|
| 291 | + if (method_exists($settings, 'do_hooks')) { |
|
| 292 | + $this->{$config}->do_hooks(); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | + $this->update_espresso_config(); |
|
| 298 | + } |
|
| 299 | + // load_core_config__end hook |
|
| 300 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * _verify_config |
|
| 306 | + * |
|
| 307 | + * @access protected |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + protected function _verify_config() |
|
| 311 | + { |
|
| 312 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | + ? $this->core |
|
| 314 | + : new EE_Core_Config(); |
|
| 315 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | + ? $this->organization |
|
| 318 | + : new EE_Organization_Config(); |
|
| 319 | + $this->organization = apply_filters( |
|
| 320 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | + $this->organization |
|
| 322 | + ); |
|
| 323 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | + ? $this->currency |
|
| 325 | + : new EE_Currency_Config(); |
|
| 326 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | + ? $this->registration |
|
| 329 | + : new EE_Registration_Config(); |
|
| 330 | + $this->registration = apply_filters( |
|
| 331 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | + $this->registration |
|
| 333 | + ); |
|
| 334 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | + ? $this->admin |
|
| 336 | + : new EE_Admin_Config(); |
|
| 337 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | + ? $this->template_settings |
|
| 340 | + : new EE_Template_Config(); |
|
| 341 | + $this->template_settings = apply_filters( |
|
| 342 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | + $this->template_settings |
|
| 344 | + ); |
|
| 345 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | + ? $this->map_settings |
|
| 347 | + : new EE_Map_Config(); |
|
| 348 | + $this->map_settings = apply_filters( |
|
| 349 | + 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | + $this->map_settings |
|
| 351 | + ); |
|
| 352 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | + ? $this->environment |
|
| 354 | + : new EE_Environment_Config(); |
|
| 355 | + $this->environment = apply_filters( |
|
| 356 | + 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | + $this->environment |
|
| 358 | + ); |
|
| 359 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | + ? $this->tax_settings |
|
| 361 | + : new EE_Tax_Config(); |
|
| 362 | + $this->tax_settings = apply_filters( |
|
| 363 | + 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | + $this->tax_settings |
|
| 365 | + ); |
|
| 366 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | + ? $this->messages |
|
| 369 | + : new EE_Messages_Config(); |
|
| 370 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | + ? $this->gateway |
|
| 372 | + : new EE_Gateway_Config(); |
|
| 373 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | + $this->legacy_shortcodes_manager = null; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * get_espresso_config |
|
| 380 | + * |
|
| 381 | + * @access public |
|
| 382 | + * @return array of espresso config stuff |
|
| 383 | + */ |
|
| 384 | + public function get_espresso_config() |
|
| 385 | + { |
|
| 386 | + // grab espresso configuration |
|
| 387 | + return apply_filters( |
|
| 388 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * double_check_config_comparison |
|
| 396 | + * |
|
| 397 | + * @access public |
|
| 398 | + * @param string $option |
|
| 399 | + * @param $old_value |
|
| 400 | + * @param $value |
|
| 401 | + */ |
|
| 402 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | + { |
|
| 404 | + // make sure we're checking the ee config |
|
| 405 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | + if ($value != $old_value) { |
|
| 409 | + // if they are NOT the same, then remove the hook, |
|
| 410 | + // which means the subsequent update results will be based solely on the update query results |
|
| 411 | + // the reason we do this is because, as stated above, |
|
| 412 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | + // If values are found to match their previous old value, |
|
| 415 | + // then WP bails before performing any update. |
|
| 416 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | + // MySQL MAY ALSO NOT perform the update because |
|
| 420 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * update_espresso_config |
|
| 431 | + * |
|
| 432 | + * @access public |
|
| 433 | + */ |
|
| 434 | + protected function _reset_espresso_addon_config() |
|
| 435 | + { |
|
| 436 | + $this->_addon_option_names = array(); |
|
| 437 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | + } |
|
| 442 | + $this->addons->{$addon_name} = null; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * update_espresso_config |
|
| 449 | + * |
|
| 450 | + * @access public |
|
| 451 | + * @param bool $add_success |
|
| 452 | + * @param bool $add_error |
|
| 453 | + * @return bool |
|
| 454 | + */ |
|
| 455 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | + { |
|
| 457 | + // don't allow config updates during WP heartbeats |
|
| 458 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 461 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | + // $clone = clone( self::$_instance ); |
|
| 463 | + // self::$_instance = NULL; |
|
| 464 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | + $this->_reset_espresso_addon_config(); |
|
| 466 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | + // but BEFORE the actual update occurs |
|
| 468 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | + $this->legacy_shortcodes_manager = null; |
|
| 472 | + // now update "ee_config" |
|
| 473 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | + // if not saved... check if the hook we just added still exists; |
|
| 477 | + // if it does, it means one of two things: |
|
| 478 | + // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | + // or... |
|
| 480 | + // the db update query returned 0 rows affected |
|
| 481 | + // (probably because the data value was the same from it's perspective) |
|
| 482 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | + // but just means no update occurred, so don't display an error to the user. |
|
| 484 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | + // then it means that something truly went wrong |
|
| 486 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | + // remove our action since we don't want it in the system anymore |
|
| 488 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | + // self::$_instance = $clone; |
|
| 491 | + // unset( $clone ); |
|
| 492 | + // if config remains the same or was updated successfully |
|
| 493 | + if ($saved) { |
|
| 494 | + if ($add_success) { |
|
| 495 | + EE_Error::add_success( |
|
| 496 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | + __FILE__, |
|
| 498 | + __FUNCTION__, |
|
| 499 | + __LINE__ |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + return true; |
|
| 503 | + } else { |
|
| 504 | + if ($add_error) { |
|
| 505 | + EE_Error::add_error( |
|
| 506 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | + __FILE__, |
|
| 508 | + __FUNCTION__, |
|
| 509 | + __LINE__ |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * _verify_config_params |
|
| 519 | + * |
|
| 520 | + * @access private |
|
| 521 | + * @param string $section |
|
| 522 | + * @param string $name |
|
| 523 | + * @param string $config_class |
|
| 524 | + * @param EE_Config_Base $config_obj |
|
| 525 | + * @param array $tests_to_run |
|
| 526 | + * @param bool $display_errors |
|
| 527 | + * @return bool TRUE on success, FALSE on fail |
|
| 528 | + */ |
|
| 529 | + private function _verify_config_params( |
|
| 530 | + $section = '', |
|
| 531 | + $name = '', |
|
| 532 | + $config_class = '', |
|
| 533 | + $config_obj = null, |
|
| 534 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | + $display_errors = true |
|
| 536 | + ) { |
|
| 537 | + try { |
|
| 538 | + foreach ($tests_to_run as $test) { |
|
| 539 | + switch ($test) { |
|
| 540 | + // TEST #1 : check that section was set |
|
| 541 | + case 1: |
|
| 542 | + if (empty($section)) { |
|
| 543 | + if ($display_errors) { |
|
| 544 | + throw new EE_Error( |
|
| 545 | + sprintf( |
|
| 546 | + __( |
|
| 547 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | + 'event_espresso' |
|
| 549 | + ), |
|
| 550 | + $config_class |
|
| 551 | + ) |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + return false; |
|
| 555 | + } |
|
| 556 | + break; |
|
| 557 | + // TEST #2 : check that settings section exists |
|
| 558 | + case 2: |
|
| 559 | + if (! isset($this->{$section})) { |
|
| 560 | + if ($display_errors) { |
|
| 561 | + throw new EE_Error( |
|
| 562 | + sprintf( |
|
| 563 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | + $section |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + } |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + break; |
|
| 571 | + // TEST #3 : check that section is the proper format |
|
| 572 | + case 3: |
|
| 573 | + if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | + ) { |
|
| 575 | + if ($display_errors) { |
|
| 576 | + throw new EE_Error( |
|
| 577 | + sprintf( |
|
| 578 | + __( |
|
| 579 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | + 'event_espresso' |
|
| 581 | + ), |
|
| 582 | + $section |
|
| 583 | + ) |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + return false; |
|
| 587 | + } |
|
| 588 | + break; |
|
| 589 | + // TEST #4 : check that config section name has been set |
|
| 590 | + case 4: |
|
| 591 | + if (empty($name)) { |
|
| 592 | + if ($display_errors) { |
|
| 593 | + throw new EE_Error( |
|
| 594 | + __( |
|
| 595 | + 'No name has been provided for the specific configuration section.', |
|
| 596 | + 'event_espresso' |
|
| 597 | + ) |
|
| 598 | + ); |
|
| 599 | + } |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + break; |
|
| 603 | + // TEST #5 : check that a config class name has been set |
|
| 604 | + case 5: |
|
| 605 | + if (empty($config_class)) { |
|
| 606 | + if ($display_errors) { |
|
| 607 | + throw new EE_Error( |
|
| 608 | + __( |
|
| 609 | + 'No class name has been provided for the specific configuration section.', |
|
| 610 | + 'event_espresso' |
|
| 611 | + ) |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + return false; |
|
| 615 | + } |
|
| 616 | + break; |
|
| 617 | + // TEST #6 : verify config class is accessible |
|
| 618 | + case 6: |
|
| 619 | + if (! class_exists($config_class)) { |
|
| 620 | + if ($display_errors) { |
|
| 621 | + throw new EE_Error( |
|
| 622 | + sprintf( |
|
| 623 | + __( |
|
| 624 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | + 'event_espresso' |
|
| 626 | + ), |
|
| 627 | + $config_class |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + break; |
|
| 634 | + // TEST #7 : check that config has even been set |
|
| 635 | + case 7: |
|
| 636 | + if (! isset($this->{$section}->{$name})) { |
|
| 637 | + if ($display_errors) { |
|
| 638 | + throw new EE_Error( |
|
| 639 | + sprintf( |
|
| 640 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | + $section, |
|
| 642 | + $name |
|
| 643 | + ) |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + return false; |
|
| 647 | + } else { |
|
| 648 | + // and make sure it's not serialized |
|
| 649 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | + } |
|
| 651 | + break; |
|
| 652 | + // TEST #8 : check that config is the requested type |
|
| 653 | + case 8: |
|
| 654 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | + if ($display_errors) { |
|
| 656 | + throw new EE_Error( |
|
| 657 | + sprintf( |
|
| 658 | + __( |
|
| 659 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | + 'event_espresso' |
|
| 661 | + ), |
|
| 662 | + $section, |
|
| 663 | + $name, |
|
| 664 | + $config_class |
|
| 665 | + ) |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + return false; |
|
| 669 | + } |
|
| 670 | + break; |
|
| 671 | + // TEST #9 : verify config object |
|
| 672 | + case 9: |
|
| 673 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | + if ($display_errors) { |
|
| 675 | + throw new EE_Error( |
|
| 676 | + sprintf( |
|
| 677 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | + print_r($config_obj, true) |
|
| 679 | + ) |
|
| 680 | + ); |
|
| 681 | + } |
|
| 682 | + return false; |
|
| 683 | + } |
|
| 684 | + break; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + } catch (EE_Error $e) { |
|
| 688 | + $e->get_error(); |
|
| 689 | + } |
|
| 690 | + // you have successfully run the gauntlet |
|
| 691 | + return true; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * _generate_config_option_name |
|
| 697 | + * |
|
| 698 | + * @access protected |
|
| 699 | + * @param string $section |
|
| 700 | + * @param string $name |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | + { |
|
| 705 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * _set_config_class |
|
| 711 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | + * |
|
| 713 | + * @access private |
|
| 714 | + * @param string $config_class |
|
| 715 | + * @param string $name |
|
| 716 | + * @return string |
|
| 717 | + */ |
|
| 718 | + private function _set_config_class($config_class = '', $name = '') |
|
| 719 | + { |
|
| 720 | + return ! empty($config_class) |
|
| 721 | + ? $config_class |
|
| 722 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * set_config |
|
| 728 | + * |
|
| 729 | + * @access protected |
|
| 730 | + * @param string $section |
|
| 731 | + * @param string $name |
|
| 732 | + * @param string $config_class |
|
| 733 | + * @param EE_Config_Base $config_obj |
|
| 734 | + * @return EE_Config_Base |
|
| 735 | + */ |
|
| 736 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | + { |
|
| 738 | + // ensure config class is set to something |
|
| 739 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | + return null; |
|
| 743 | + } |
|
| 744 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | + $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | + $this->update_addon_option_names(); |
|
| 749 | + } |
|
| 750 | + // verify the incoming config object but suppress errors |
|
| 751 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | + $config_obj = new $config_class(); |
|
| 753 | + } |
|
| 754 | + if (get_option($config_option_name)) { |
|
| 755 | + EE_Config::log($config_option_name); |
|
| 756 | + update_option($config_option_name, $config_obj); |
|
| 757 | + $this->{$section}->{$name} = $config_obj; |
|
| 758 | + return $this->{$section}->{$name}; |
|
| 759 | + } else { |
|
| 760 | + // create a wp-option for this config |
|
| 761 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | + return $this->{$section}->{$name}; |
|
| 764 | + } else { |
|
| 765 | + EE_Error::add_error( |
|
| 766 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | + __FILE__, |
|
| 768 | + __FUNCTION__, |
|
| 769 | + __LINE__ |
|
| 770 | + ); |
|
| 771 | + return null; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * update_config |
|
| 779 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | + * |
|
| 781 | + * @access public |
|
| 782 | + * @param string $section |
|
| 783 | + * @param string $name |
|
| 784 | + * @param EE_Config_Base|string $config_obj |
|
| 785 | + * @param bool $throw_errors |
|
| 786 | + * @return bool |
|
| 787 | + */ |
|
| 788 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | + { |
|
| 790 | + // don't allow config updates during WP heartbeats |
|
| 791 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 794 | + $config_obj = maybe_unserialize($config_obj); |
|
| 795 | + // get class name of the incoming object |
|
| 796 | + $config_class = get_class($config_obj); |
|
| 797 | + // run tests 1-5 and 9 to verify config |
|
| 798 | + if (! $this->_verify_config_params( |
|
| 799 | + $section, |
|
| 800 | + $name, |
|
| 801 | + $config_class, |
|
| 802 | + $config_obj, |
|
| 803 | + array(1, 2, 3, 4, 7, 9) |
|
| 804 | + ) |
|
| 805 | + ) { |
|
| 806 | + return false; |
|
| 807 | + } |
|
| 808 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | + // save new config to db |
|
| 812 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | + return true; |
|
| 814 | + } |
|
| 815 | + } else { |
|
| 816 | + // first check if the record already exists |
|
| 817 | + $existing_config = get_option($config_option_name); |
|
| 818 | + $config_obj = serialize($config_obj); |
|
| 819 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | + if ($existing_config == $config_obj) { |
|
| 821 | + $this->{$section}->{$name} = $config_obj; |
|
| 822 | + return true; |
|
| 823 | + } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | + EE_Config::log($config_option_name); |
|
| 825 | + // update wp-option for this config class |
|
| 826 | + $this->{$section}->{$name} = $config_obj; |
|
| 827 | + return true; |
|
| 828 | + } elseif ($throw_errors) { |
|
| 829 | + EE_Error::add_error( |
|
| 830 | + sprintf( |
|
| 831 | + __( |
|
| 832 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | + 'event_espresso' |
|
| 834 | + ), |
|
| 835 | + $config_class, |
|
| 836 | + 'EE_Config->' . $section . '->' . $name |
|
| 837 | + ), |
|
| 838 | + __FILE__, |
|
| 839 | + __FUNCTION__, |
|
| 840 | + __LINE__ |
|
| 841 | + ); |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + return false; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * get_config |
|
| 850 | + * |
|
| 851 | + * @access public |
|
| 852 | + * @param string $section |
|
| 853 | + * @param string $name |
|
| 854 | + * @param string $config_class |
|
| 855 | + * @return mixed EE_Config_Base | NULL |
|
| 856 | + */ |
|
| 857 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | + { |
|
| 859 | + // ensure config class is set to something |
|
| 860 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | + return null; |
|
| 864 | + } |
|
| 865 | + // now test if the requested config object exists, but suppress errors |
|
| 866 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | + // config already exists, so pass it back |
|
| 868 | + return $this->{$section}->{$name}; |
|
| 869 | + } |
|
| 870 | + // load config option from db if it exists |
|
| 871 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | + // verify the newly retrieved config object, but suppress errors |
|
| 873 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | + // config is good, so set it and pass it back |
|
| 875 | + $this->{$section}->{$name} = $config_obj; |
|
| 876 | + return $this->{$section}->{$name}; |
|
| 877 | + } |
|
| 878 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | + // verify the newly created config object |
|
| 881 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | + return $this->{$section}->{$name}; |
|
| 883 | + } else { |
|
| 884 | + EE_Error::add_error( |
|
| 885 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | + __FILE__, |
|
| 887 | + __FUNCTION__, |
|
| 888 | + __LINE__ |
|
| 889 | + ); |
|
| 890 | + } |
|
| 891 | + return null; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * get_config_option |
|
| 897 | + * |
|
| 898 | + * @access public |
|
| 899 | + * @param string $config_option_name |
|
| 900 | + * @return mixed EE_Config_Base | FALSE |
|
| 901 | + */ |
|
| 902 | + public function get_config_option($config_option_name = '') |
|
| 903 | + { |
|
| 904 | + // retrieve the wp-option for this config class. |
|
| 905 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | + if (empty($config_option)) { |
|
| 907 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | + } |
|
| 909 | + return $config_option; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * log |
|
| 915 | + * |
|
| 916 | + * @param string $config_option_name |
|
| 917 | + */ |
|
| 918 | + public static function log($config_option_name = '') |
|
| 919 | + { |
|
| 920 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | + // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | + $_request = $_REQUEST; |
|
| 924 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | + $config_log[ (string) microtime(true) ] = array( |
|
| 926 | + 'config_name' => $config_option_name, |
|
| 927 | + 'request' => $_request, |
|
| 928 | + ); |
|
| 929 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * trim_log |
|
| 936 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | + */ |
|
| 938 | + public static function trim_log() |
|
| 939 | + { |
|
| 940 | + if (! EE_Config::logging_enabled()) { |
|
| 941 | + return; |
|
| 942 | + } |
|
| 943 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | + $log_length = count($config_log); |
|
| 945 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | + ksort($config_log); |
|
| 947 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * get_page_for_posts |
|
| 955 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | + * |
|
| 958 | + * @access public |
|
| 959 | + * @return string |
|
| 960 | + */ |
|
| 961 | + public static function get_page_for_posts() |
|
| 962 | + { |
|
| 963 | + $page_for_posts = get_option('page_for_posts'); |
|
| 964 | + if (! $page_for_posts) { |
|
| 965 | + return 'posts'; |
|
| 966 | + } |
|
| 967 | + /** @type WPDB $wpdb */ |
|
| 968 | + global $wpdb; |
|
| 969 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * register_shortcodes_and_modules. |
|
| 976 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | + * so they can help trigger maintenance mode if it's needed |
|
| 979 | + * |
|
| 980 | + * @access public |
|
| 981 | + * @return void |
|
| 982 | + */ |
|
| 983 | + public function register_shortcodes_and_modules() |
|
| 984 | + { |
|
| 985 | + // allow modules to set hooks for the rest of the system |
|
| 986 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * initialize_shortcodes_and_modules |
|
| 992 | + * meaning they can start adding their hooks to get stuff done |
|
| 993 | + * |
|
| 994 | + * @access public |
|
| 995 | + * @return void |
|
| 996 | + */ |
|
| 997 | + public function initialize_shortcodes_and_modules() |
|
| 998 | + { |
|
| 999 | + // allow modules to set hooks for the rest of the system |
|
| 1000 | + $this->_initialize_modules(); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * widgets_init |
|
| 1006 | + * |
|
| 1007 | + * @access private |
|
| 1008 | + * @return void |
|
| 1009 | + */ |
|
| 1010 | + public function widgets_init() |
|
| 1011 | + { |
|
| 1012 | + // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | + // on frontend when not in any maintenance mode |
|
| 1014 | + if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | + || ( |
|
| 1016 | + is_admin() |
|
| 1017 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | + ) |
|
| 1019 | + ) { |
|
| 1020 | + // grab list of installed widgets |
|
| 1021 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | + // filter list of modules to register |
|
| 1023 | + $widgets_to_register = apply_filters( |
|
| 1024 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | + $widgets_to_register |
|
| 1026 | + ); |
|
| 1027 | + if (! empty($widgets_to_register)) { |
|
| 1028 | + // cycle thru widget folders |
|
| 1029 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | + // add to list of installed widget modules |
|
| 1031 | + EE_Config::register_ee_widget($widget_path); |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + // filter list of installed modules |
|
| 1035 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | + EE_Registry::instance()->widgets |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * register_ee_widget - makes core aware of this widget |
|
| 1045 | + * |
|
| 1046 | + * @access public |
|
| 1047 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + public static function register_ee_widget($widget_path = null) |
|
| 1051 | + { |
|
| 1052 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | + $widget_ext = '.widget.php'; |
|
| 1054 | + // make all separators match |
|
| 1055 | + $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | + $file_name = explode('.', basename($widget_path)); |
|
| 1060 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | + // sanitize shortcode directory name |
|
| 1063 | + $widget = sanitize_key($widget); |
|
| 1064 | + // now we need to rebuild the shortcode path |
|
| 1065 | + $widget_path = explode('/', $widget_path); |
|
| 1066 | + // remove last segment |
|
| 1067 | + array_pop($widget_path); |
|
| 1068 | + // glue it back together |
|
| 1069 | + $widget_path = implode(DS, $widget_path); |
|
| 1070 | + } else { |
|
| 1071 | + // grab and sanitize widget directory name |
|
| 1072 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | + } |
|
| 1074 | + // create classname from widget directory name |
|
| 1075 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | + // add class prefix |
|
| 1077 | + $widget_class = 'EEW_' . $widget; |
|
| 1078 | + // does the widget exist ? |
|
| 1079 | + if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1080 | + $msg = sprintf( |
|
| 1081 | + __( |
|
| 1082 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | + 'event_espresso' |
|
| 1084 | + ), |
|
| 1085 | + $widget_class, |
|
| 1086 | + $widget_path . '/' . $widget_class . $widget_ext |
|
| 1087 | + ); |
|
| 1088 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | + return; |
|
| 1090 | + } |
|
| 1091 | + // load the widget class file |
|
| 1092 | + require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1093 | + // verify that class exists |
|
| 1094 | + if (! class_exists($widget_class)) { |
|
| 1095 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | + return; |
|
| 1098 | + } |
|
| 1099 | + register_widget($widget_class); |
|
| 1100 | + // add to array of registered widgets |
|
| 1101 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * _register_modules |
|
| 1107 | + * |
|
| 1108 | + * @access private |
|
| 1109 | + * @return array |
|
| 1110 | + */ |
|
| 1111 | + private function _register_modules() |
|
| 1112 | + { |
|
| 1113 | + // grab list of installed modules |
|
| 1114 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | + // filter list of modules to register |
|
| 1116 | + $modules_to_register = apply_filters( |
|
| 1117 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | + $modules_to_register |
|
| 1119 | + ); |
|
| 1120 | + if (! empty($modules_to_register)) { |
|
| 1121 | + // loop through folders |
|
| 1122 | + foreach ($modules_to_register as $module_path) { |
|
| 1123 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | + if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | + ) { |
|
| 1127 | + // add to list of installed modules |
|
| 1128 | + EE_Config::register_module($module_path); |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + // filter list of installed modules |
|
| 1133 | + return apply_filters( |
|
| 1134 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | + EE_Registry::instance()->modules |
|
| 1136 | + ); |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + |
|
| 1140 | + /** |
|
| 1141 | + * register_module - makes core aware of this module |
|
| 1142 | + * |
|
| 1143 | + * @access public |
|
| 1144 | + * @param string $module_path - full path up to and including module folder |
|
| 1145 | + * @return bool |
|
| 1146 | + */ |
|
| 1147 | + public static function register_module($module_path = null) |
|
| 1148 | + { |
|
| 1149 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | + $module_ext = '.module.php'; |
|
| 1151 | + // make all separators match |
|
| 1152 | + $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1153 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | + $module_file = explode('.', basename($module_path)); |
|
| 1157 | + // now we need to rebuild the shortcode path |
|
| 1158 | + $module_path = explode('/', $module_path); |
|
| 1159 | + // remove last segment |
|
| 1160 | + array_pop($module_path); |
|
| 1161 | + // glue it back together |
|
| 1162 | + $module_path = implode('/', $module_path) . '/'; |
|
| 1163 | + // take first segment from file name pieces and sanitize it |
|
| 1164 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | + // ensure class prefix is added |
|
| 1166 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | + } else { |
|
| 1168 | + // we need to generate the filename based off of the folder name |
|
| 1169 | + // grab and sanitize module name |
|
| 1170 | + $module = strtolower(basename($module_path)); |
|
| 1171 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | + // like trailingslashit() |
|
| 1173 | + $module_path = rtrim($module_path, '/') . '/'; |
|
| 1174 | + // create classname from module directory name |
|
| 1175 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | + // add class prefix |
|
| 1177 | + $module_class = 'EED_' . $module; |
|
| 1178 | + } |
|
| 1179 | + // does the module exist ? |
|
| 1180 | + if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1181 | + $msg = sprintf( |
|
| 1182 | + __( |
|
| 1183 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | + 'event_espresso' |
|
| 1185 | + ), |
|
| 1186 | + $module |
|
| 1187 | + ); |
|
| 1188 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | + return false; |
|
| 1190 | + } |
|
| 1191 | + // load the module class file |
|
| 1192 | + require_once($module_path . $module_class . $module_ext); |
|
| 1193 | + // verify that class exists |
|
| 1194 | + if (! class_exists($module_class)) { |
|
| 1195 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | + return false; |
|
| 1198 | + } |
|
| 1199 | + // add to array of registered modules |
|
| 1200 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | + do_action( |
|
| 1202 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | + $module_class, |
|
| 1204 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | + ); |
|
| 1206 | + return true; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * _initialize_modules |
|
| 1212 | + * allow modules to set hooks for the rest of the system |
|
| 1213 | + * |
|
| 1214 | + * @access private |
|
| 1215 | + * @return void |
|
| 1216 | + */ |
|
| 1217 | + private function _initialize_modules() |
|
| 1218 | + { |
|
| 1219 | + // cycle thru shortcode folders |
|
| 1220 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | + // which set hooks ? |
|
| 1223 | + if (is_admin()) { |
|
| 1224 | + // fire immediately |
|
| 1225 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | + } else { |
|
| 1227 | + // delay until other systems are online |
|
| 1228 | + add_action( |
|
| 1229 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | + array($module_class, 'set_hooks') |
|
| 1231 | + ); |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + |
|
| 1237 | + /** |
|
| 1238 | + * register_route - adds module method routes to route_map |
|
| 1239 | + * |
|
| 1240 | + * @access public |
|
| 1241 | + * @param string $route - "pretty" public alias for module method |
|
| 1242 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | + * @param string $method_name - the actual module method to be routed to |
|
| 1244 | + * @param string $key - url param key indicating a route is being called |
|
| 1245 | + * @return bool |
|
| 1246 | + */ |
|
| 1247 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | + { |
|
| 1249 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | + $module = str_replace('EED_', '', $module); |
|
| 1251 | + $module_class = 'EED_' . $module; |
|
| 1252 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | + return false; |
|
| 1256 | + } |
|
| 1257 | + if (empty($route)) { |
|
| 1258 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | + return false; |
|
| 1261 | + } |
|
| 1262 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | + $msg = sprintf( |
|
| 1264 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | + $route |
|
| 1266 | + ); |
|
| 1267 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | + return false; |
|
| 1269 | + } |
|
| 1270 | + EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | + return true; |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + |
|
| 1275 | + /** |
|
| 1276 | + * get_route - get module method route |
|
| 1277 | + * |
|
| 1278 | + * @access public |
|
| 1279 | + * @param string $route - "pretty" public alias for module method |
|
| 1280 | + * @param string $key - url param key indicating a route is being called |
|
| 1281 | + * @return string |
|
| 1282 | + */ |
|
| 1283 | + public static function get_route($route = null, $key = 'ee') |
|
| 1284 | + { |
|
| 1285 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | + if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | + return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | + } |
|
| 1290 | + return null; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + /** |
|
| 1295 | + * get_routes - get ALL module method routes |
|
| 1296 | + * |
|
| 1297 | + * @access public |
|
| 1298 | + * @return array |
|
| 1299 | + */ |
|
| 1300 | + public static function get_routes() |
|
| 1301 | + { |
|
| 1302 | + return EE_Config::$_module_route_map; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + |
|
| 1306 | + /** |
|
| 1307 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | + * |
|
| 1309 | + * @access public |
|
| 1310 | + * @param string $route - "pretty" public alias for module method |
|
| 1311 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | + * class, allows different forwards to be served based on status |
|
| 1313 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | + * @param string $key - url param key indicating a route is being called |
|
| 1315 | + * @return bool |
|
| 1316 | + */ |
|
| 1317 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | + { |
|
| 1319 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | + $msg = sprintf( |
|
| 1322 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | + $route |
|
| 1324 | + ); |
|
| 1325 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | + return false; |
|
| 1327 | + } |
|
| 1328 | + if (empty($forward)) { |
|
| 1329 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | + return false; |
|
| 1332 | + } |
|
| 1333 | + if (is_array($forward)) { |
|
| 1334 | + if (! isset($forward[1])) { |
|
| 1335 | + $msg = sprintf( |
|
| 1336 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | + $route |
|
| 1338 | + ); |
|
| 1339 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | + return false; |
|
| 1341 | + } |
|
| 1342 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | + $msg = sprintf( |
|
| 1344 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | + $forward[1], |
|
| 1346 | + $route |
|
| 1347 | + ); |
|
| 1348 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | + return false; |
|
| 1350 | + } |
|
| 1351 | + } elseif (! function_exists($forward)) { |
|
| 1352 | + $msg = sprintf( |
|
| 1353 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | + $forward, |
|
| 1355 | + $route |
|
| 1356 | + ); |
|
| 1357 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | + return false; |
|
| 1359 | + } |
|
| 1360 | + EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | + return true; |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + /** |
|
| 1366 | + * get_forward - get forwarding route |
|
| 1367 | + * |
|
| 1368 | + * @access public |
|
| 1369 | + * @param string $route - "pretty" public alias for module method |
|
| 1370 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | + * allows different forwards to be served based on status |
|
| 1372 | + * @param string $key - url param key indicating a route is being called |
|
| 1373 | + * @return string |
|
| 1374 | + */ |
|
| 1375 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | + { |
|
| 1377 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | + if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | + return apply_filters( |
|
| 1380 | + 'FHEE__EE_Config__get_forward', |
|
| 1381 | + EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | + $route, |
|
| 1383 | + $status |
|
| 1384 | + ); |
|
| 1385 | + } |
|
| 1386 | + return null; |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + |
|
| 1390 | + /** |
|
| 1391 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | + * results |
|
| 1393 | + * |
|
| 1394 | + * @access public |
|
| 1395 | + * @param string $route - "pretty" public alias for module method |
|
| 1396 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | + * allows different views to be served based on status |
|
| 1398 | + * @param string $view |
|
| 1399 | + * @param string $key - url param key indicating a route is being called |
|
| 1400 | + * @return bool |
|
| 1401 | + */ |
|
| 1402 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | + { |
|
| 1404 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | + $msg = sprintf( |
|
| 1407 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | + $route |
|
| 1409 | + ); |
|
| 1410 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | + return false; |
|
| 1412 | + } |
|
| 1413 | + if (! is_readable($view)) { |
|
| 1414 | + $msg = sprintf( |
|
| 1415 | + __( |
|
| 1416 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | + 'event_espresso' |
|
| 1418 | + ), |
|
| 1419 | + $view |
|
| 1420 | + ); |
|
| 1421 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | + return false; |
|
| 1423 | + } |
|
| 1424 | + EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | + return true; |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * get_view - get view for route and status |
|
| 1431 | + * |
|
| 1432 | + * @access public |
|
| 1433 | + * @param string $route - "pretty" public alias for module method |
|
| 1434 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | + * allows different views to be served based on status |
|
| 1436 | + * @param string $key - url param key indicating a route is being called |
|
| 1437 | + * @return string |
|
| 1438 | + */ |
|
| 1439 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | + { |
|
| 1441 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | + if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | + return apply_filters( |
|
| 1444 | + 'FHEE__EE_Config__get_view', |
|
| 1445 | + EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | + $route, |
|
| 1447 | + $status |
|
| 1448 | + ); |
|
| 1449 | + } |
|
| 1450 | + return null; |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + |
|
| 1454 | + public function update_addon_option_names() |
|
| 1455 | + { |
|
| 1456 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + public function shutdown() |
|
| 1461 | + { |
|
| 1462 | + $this->update_addon_option_names(); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * @return LegacyShortcodesManager |
|
| 1468 | + */ |
|
| 1469 | + public static function getLegacyShortcodesManager() |
|
| 1470 | + { |
|
| 1471 | + |
|
| 1472 | + if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | + EE_Registry::instance() |
|
| 1475 | + ); |
|
| 1476 | + } |
|
| 1477 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * register_shortcode - makes core aware of this shortcode |
|
| 1483 | + * |
|
| 1484 | + * @deprecated 4.9.26 |
|
| 1485 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | + * @return bool |
|
| 1487 | + */ |
|
| 1488 | + public static function register_shortcode($shortcode_path = null) |
|
| 1489 | + { |
|
| 1490 | + EE_Error::doing_it_wrong( |
|
| 1491 | + __METHOD__, |
|
| 1492 | + __( |
|
| 1493 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | + 'event_espresso' |
|
| 1495 | + ), |
|
| 1496 | + '4.9.26' |
|
| 1497 | + ); |
|
| 1498 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | + } |
|
| 1500 | +} |
|
| 2262 | 1501 | |
| 2263 | - /** |
|
| 2264 | - * ReCaptcha Type |
|
| 2265 | - * |
|
| 2266 | - * @var string $recaptcha_type |
|
| 2267 | - * options: 'audio', 'image' |
|
| 2268 | - */ |
|
| 2269 | - public $recaptcha_type; |
|
| 1502 | +/** |
|
| 1503 | + * Base class used for config classes. These classes should generally not have |
|
| 1504 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | + * basically, they should just be well-defined stdClasses |
|
| 1506 | + */ |
|
| 1507 | +class EE_Config_Base |
|
| 1508 | +{ |
|
| 2270 | 1509 | |
| 2271 | - /** |
|
| 2272 | - * ReCaptcha language |
|
| 2273 | - * |
|
| 2274 | - * @var string $recaptcha_language |
|
| 2275 | - * eg 'en' |
|
| 2276 | - */ |
|
| 2277 | - public $recaptcha_language; |
|
| 1510 | + /** |
|
| 1511 | + * Utility function for escaping the value of a property and returning. |
|
| 1512 | + * |
|
| 1513 | + * @param string $property property name (checks to see if exists). |
|
| 1514 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | + * @throws \EE_Error |
|
| 1516 | + */ |
|
| 1517 | + public function get_pretty($property) |
|
| 1518 | + { |
|
| 1519 | + if (! property_exists($this, $property)) { |
|
| 1520 | + throw new EE_Error( |
|
| 1521 | + sprintf( |
|
| 1522 | + __( |
|
| 1523 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | + 'event_espresso' |
|
| 1525 | + ), |
|
| 1526 | + get_class($this), |
|
| 1527 | + $property |
|
| 1528 | + ) |
|
| 1529 | + ); |
|
| 1530 | + } |
|
| 1531 | + // just handling escaping of strings for now. |
|
| 1532 | + if (is_string($this->{$property})) { |
|
| 1533 | + return stripslashes($this->{$property}); |
|
| 1534 | + } |
|
| 1535 | + return $this->{$property}; |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + |
|
| 1539 | + public function populate() |
|
| 1540 | + { |
|
| 1541 | + // grab defaults via a new instance of this class. |
|
| 1542 | + $class_name = get_class($this); |
|
| 1543 | + $defaults = new $class_name; |
|
| 1544 | + // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | + // default from our $defaults object. |
|
| 1546 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | + if ($this->{$property} === null) { |
|
| 1548 | + $this->{$property} = $value; |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + // cleanup |
|
| 1552 | + unset($defaults); |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * __isset |
|
| 1558 | + * |
|
| 1559 | + * @param $a |
|
| 1560 | + * @return bool |
|
| 1561 | + */ |
|
| 1562 | + public function __isset($a) |
|
| 1563 | + { |
|
| 1564 | + return false; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * __unset |
|
| 1570 | + * |
|
| 1571 | + * @param $a |
|
| 1572 | + * @return bool |
|
| 1573 | + */ |
|
| 1574 | + public function __unset($a) |
|
| 1575 | + { |
|
| 1576 | + return false; |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + |
|
| 1580 | + /** |
|
| 1581 | + * __clone |
|
| 1582 | + */ |
|
| 1583 | + public function __clone() |
|
| 1584 | + { |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * __wakeup |
|
| 1590 | + */ |
|
| 1591 | + public function __wakeup() |
|
| 1592 | + { |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * __destruct |
|
| 1598 | + */ |
|
| 1599 | + public function __destruct() |
|
| 1600 | + { |
|
| 1601 | + } |
|
| 1602 | +} |
|
| 2278 | 1603 | |
| 2279 | - /** |
|
| 2280 | - * ReCaptcha public key |
|
| 2281 | - * |
|
| 2282 | - * @var string $recaptcha_publickey |
|
| 2283 | - */ |
|
| 2284 | - public $recaptcha_publickey; |
|
| 1604 | +/** |
|
| 1605 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | + */ |
|
| 1607 | +class EE_Core_Config extends EE_Config_Base |
|
| 1608 | +{ |
|
| 2285 | 1609 | |
| 2286 | - /** |
|
| 2287 | - * ReCaptcha private key |
|
| 2288 | - * |
|
| 2289 | - * @var string $recaptcha_privatekey |
|
| 2290 | - */ |
|
| 2291 | - public $recaptcha_privatekey; |
|
| 1610 | + const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | + |
|
| 1612 | + |
|
| 1613 | + public $current_blog_id; |
|
| 1614 | + |
|
| 1615 | + public $ee_ueip_optin; |
|
| 1616 | + |
|
| 1617 | + public $ee_ueip_has_notified; |
|
| 1618 | + |
|
| 1619 | + /** |
|
| 1620 | + * Not to be confused with the 4 critical page variables (See |
|
| 1621 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | + * |
|
| 1625 | + * @var array |
|
| 1626 | + */ |
|
| 1627 | + public $post_shortcodes; |
|
| 1628 | + |
|
| 1629 | + public $module_route_map; |
|
| 1630 | + |
|
| 1631 | + public $module_forward_map; |
|
| 1632 | + |
|
| 1633 | + public $module_view_map; |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | + * |
|
| 1638 | + * @var int |
|
| 1639 | + */ |
|
| 1640 | + public $reg_page_id; |
|
| 1641 | + |
|
| 1642 | + public $txn_page_id; |
|
| 1643 | + |
|
| 1644 | + public $thank_you_page_id; |
|
| 1645 | + |
|
| 1646 | + public $cancel_page_id; |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | + * |
|
| 1651 | + * @var int |
|
| 1652 | + */ |
|
| 1653 | + public $reg_page_url; |
|
| 1654 | + |
|
| 1655 | + public $txn_page_url; |
|
| 1656 | + |
|
| 1657 | + public $thank_you_page_url; |
|
| 1658 | + |
|
| 1659 | + public $cancel_page_url; |
|
| 1660 | + |
|
| 1661 | + /** |
|
| 1662 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | + */ |
|
| 1664 | + public $event_cpt_slug; |
|
| 1665 | + |
|
| 1666 | + /** |
|
| 1667 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | + * request across blog switches in a multisite context. |
|
| 1669 | + * Avoids extra queries to the db for this option. |
|
| 1670 | + * |
|
| 1671 | + * @var bool |
|
| 1672 | + */ |
|
| 1673 | + public static $ee_ueip_option; |
|
| 1674 | + |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * class constructor |
|
| 1678 | + * |
|
| 1679 | + * @access public |
|
| 1680 | + */ |
|
| 1681 | + public function __construct() |
|
| 1682 | + { |
|
| 1683 | + // set default organization settings |
|
| 1684 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | + $this->post_shortcodes = array(); |
|
| 1689 | + $this->module_route_map = array(); |
|
| 1690 | + $this->module_forward_map = array(); |
|
| 1691 | + $this->module_view_map = array(); |
|
| 1692 | + // critical EE page IDs |
|
| 1693 | + $this->reg_page_id = 0; |
|
| 1694 | + $this->txn_page_id = 0; |
|
| 1695 | + $this->thank_you_page_id = 0; |
|
| 1696 | + $this->cancel_page_id = 0; |
|
| 1697 | + // critical EE page URLs |
|
| 1698 | + $this->reg_page_url = ''; |
|
| 1699 | + $this->txn_page_url = ''; |
|
| 1700 | + $this->thank_you_page_url = ''; |
|
| 1701 | + $this->cancel_page_url = ''; |
|
| 1702 | + // cpt slugs |
|
| 1703 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | + // ueip constant check |
|
| 1705 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | + $this->ee_ueip_optin = false; |
|
| 1707 | + $this->ee_ueip_has_notified = true; |
|
| 1708 | + } |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * @return array |
|
| 1714 | + */ |
|
| 1715 | + public function get_critical_pages_array() |
|
| 1716 | + { |
|
| 1717 | + return array( |
|
| 1718 | + $this->reg_page_id, |
|
| 1719 | + $this->txn_page_id, |
|
| 1720 | + $this->thank_you_page_id, |
|
| 1721 | + $this->cancel_page_id, |
|
| 1722 | + ); |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + |
|
| 1726 | + /** |
|
| 1727 | + * @return array |
|
| 1728 | + */ |
|
| 1729 | + public function get_critical_pages_shortcodes_array() |
|
| 1730 | + { |
|
| 1731 | + return array( |
|
| 1732 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | + ); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * gets/returns URL for EE reg_page |
|
| 1742 | + * |
|
| 1743 | + * @access public |
|
| 1744 | + * @return string |
|
| 1745 | + */ |
|
| 1746 | + public function reg_page_url() |
|
| 1747 | + { |
|
| 1748 | + if (! $this->reg_page_url) { |
|
| 1749 | + $this->reg_page_url = add_query_arg( |
|
| 1750 | + array('uts' => time()), |
|
| 1751 | + get_permalink($this->reg_page_id) |
|
| 1752 | + ) . '#checkout'; |
|
| 1753 | + } |
|
| 1754 | + return $this->reg_page_url; |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + |
|
| 1758 | + /** |
|
| 1759 | + * gets/returns URL for EE txn_page |
|
| 1760 | + * |
|
| 1761 | + * @param array $query_args like what gets passed to |
|
| 1762 | + * add_query_arg() as the first argument |
|
| 1763 | + * @access public |
|
| 1764 | + * @return string |
|
| 1765 | + */ |
|
| 1766 | + public function txn_page_url($query_args = array()) |
|
| 1767 | + { |
|
| 1768 | + if (! $this->txn_page_url) { |
|
| 1769 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | + } |
|
| 1771 | + if ($query_args) { |
|
| 1772 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | + } else { |
|
| 1774 | + return $this->txn_page_url; |
|
| 1775 | + } |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + |
|
| 1779 | + /** |
|
| 1780 | + * gets/returns URL for EE thank_you_page |
|
| 1781 | + * |
|
| 1782 | + * @param array $query_args like what gets passed to |
|
| 1783 | + * add_query_arg() as the first argument |
|
| 1784 | + * @access public |
|
| 1785 | + * @return string |
|
| 1786 | + */ |
|
| 1787 | + public function thank_you_page_url($query_args = array()) |
|
| 1788 | + { |
|
| 1789 | + if (! $this->thank_you_page_url) { |
|
| 1790 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | + } |
|
| 1792 | + if ($query_args) { |
|
| 1793 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | + } else { |
|
| 1795 | + return $this->thank_you_page_url; |
|
| 1796 | + } |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * gets/returns URL for EE cancel_page |
|
| 1802 | + * |
|
| 1803 | + * @access public |
|
| 1804 | + * @return string |
|
| 1805 | + */ |
|
| 1806 | + public function cancel_page_url() |
|
| 1807 | + { |
|
| 1808 | + if (! $this->cancel_page_url) { |
|
| 1809 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | + } |
|
| 1811 | + return $this->cancel_page_url; |
|
| 1812 | + } |
|
| 1813 | + |
|
| 1814 | + |
|
| 1815 | + /** |
|
| 1816 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | + * |
|
| 1818 | + * @since 4.7.5 |
|
| 1819 | + */ |
|
| 1820 | + protected function _reset_urls() |
|
| 1821 | + { |
|
| 1822 | + $this->reg_page_url = ''; |
|
| 1823 | + $this->txn_page_url = ''; |
|
| 1824 | + $this->cancel_page_url = ''; |
|
| 1825 | + $this->thank_you_page_url = ''; |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | + * on the main site only. |
|
| 1833 | + * |
|
| 1834 | + * @return bool |
|
| 1835 | + */ |
|
| 1836 | + protected function _get_main_ee_ueip_optin() |
|
| 1837 | + { |
|
| 1838 | + // if this is the main site then we can just bypass our direct query. |
|
| 1839 | + if (is_main_site()) { |
|
| 1840 | + return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | + } |
|
| 1842 | + // is this already cached for this request? If so use it. |
|
| 1843 | + if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | + } |
|
| 1846 | + global $wpdb; |
|
| 1847 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | + $option = self::OPTION_NAME_UXIP; |
|
| 1850 | + // set correct table for query |
|
| 1851 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | + // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | + // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | + // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | + // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | + // for the purpose of caching. |
|
| 1857 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | + if (false !== $pre) { |
|
| 1859 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | + } |
|
| 1862 | + $row = $wpdb->get_row( |
|
| 1863 | + $wpdb->prepare( |
|
| 1864 | + "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | + $option |
|
| 1866 | + ) |
|
| 1867 | + ); |
|
| 1868 | + if (is_object($row)) { |
|
| 1869 | + $value = $row->option_value; |
|
| 1870 | + } else { // option does not exist so use default. |
|
| 1871 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | + } |
|
| 1874 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + /** |
|
| 1880 | + * Utility function for escaping the value of a property and returning. |
|
| 1881 | + * |
|
| 1882 | + * @param string $property property name (checks to see if exists). |
|
| 1883 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | + * @throws \EE_Error |
|
| 1885 | + */ |
|
| 1886 | + public function get_pretty($property) |
|
| 1887 | + { |
|
| 1888 | + if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | + } |
|
| 1891 | + return parent::get_pretty($property); |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + |
|
| 1895 | + /** |
|
| 1896 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | + * on the object. |
|
| 1898 | + * |
|
| 1899 | + * @return array |
|
| 1900 | + */ |
|
| 1901 | + public function __sleep() |
|
| 1902 | + { |
|
| 1903 | + // reset all url properties |
|
| 1904 | + $this->_reset_urls(); |
|
| 1905 | + // return what to save to db |
|
| 1906 | + return array_keys(get_object_vars($this)); |
|
| 1907 | + } |
|
| 1908 | +} |
|
| 2292 | 1909 | |
| 2293 | - /** |
|
| 2294 | - * array of form names protected by ReCaptcha |
|
| 2295 | - * |
|
| 2296 | - * @var array $recaptcha_protected_forms |
|
| 2297 | - */ |
|
| 2298 | - public $recaptcha_protected_forms; |
|
| 1910 | +/** |
|
| 1911 | + * Config class for storing info on the Organization |
|
| 1912 | + */ |
|
| 1913 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | +{ |
|
| 2299 | 1915 | |
| 2300 | - /** |
|
| 2301 | - * ReCaptcha width |
|
| 2302 | - * |
|
| 2303 | - * @var int $recaptcha_width |
|
| 2304 | - * @deprecated |
|
| 2305 | - */ |
|
| 2306 | - public $recaptcha_width; |
|
| 1916 | + /** |
|
| 1917 | + * @var string $name |
|
| 1918 | + * eg EE4.1 |
|
| 1919 | + */ |
|
| 1920 | + public $name; |
|
| 1921 | + |
|
| 1922 | + /** |
|
| 1923 | + * @var string $address_1 |
|
| 1924 | + * eg 123 Onna Road |
|
| 1925 | + */ |
|
| 1926 | + public $address_1 = ''; |
|
| 1927 | + |
|
| 1928 | + /** |
|
| 1929 | + * @var string $address_2 |
|
| 1930 | + * eg PO Box 123 |
|
| 1931 | + */ |
|
| 1932 | + public $address_2 = ''; |
|
| 1933 | + |
|
| 1934 | + /** |
|
| 1935 | + * @var string $city |
|
| 1936 | + * eg Inna City |
|
| 1937 | + */ |
|
| 1938 | + public $city = ''; |
|
| 1939 | + |
|
| 1940 | + /** |
|
| 1941 | + * @var int $STA_ID |
|
| 1942 | + * eg 4 |
|
| 1943 | + */ |
|
| 1944 | + public $STA_ID = 0; |
|
| 1945 | + |
|
| 1946 | + /** |
|
| 1947 | + * @var string $CNT_ISO |
|
| 1948 | + * eg US |
|
| 1949 | + */ |
|
| 1950 | + public $CNT_ISO = ''; |
|
| 1951 | + |
|
| 1952 | + /** |
|
| 1953 | + * @var string $zip |
|
| 1954 | + * eg 12345 or V1A 2B3 |
|
| 1955 | + */ |
|
| 1956 | + public $zip = ''; |
|
| 1957 | + |
|
| 1958 | + /** |
|
| 1959 | + * @var string $email |
|
| 1960 | + * eg [email protected] |
|
| 1961 | + */ |
|
| 1962 | + public $email; |
|
| 1963 | + |
|
| 1964 | + /** |
|
| 1965 | + * @var string $phone |
|
| 1966 | + * eg. 111-111-1111 |
|
| 1967 | + */ |
|
| 1968 | + public $phone = ''; |
|
| 1969 | + |
|
| 1970 | + /** |
|
| 1971 | + * @var string $vat |
|
| 1972 | + * VAT/Tax Number |
|
| 1973 | + */ |
|
| 1974 | + public $vat = ''; |
|
| 1975 | + |
|
| 1976 | + /** |
|
| 1977 | + * @var string $logo_url |
|
| 1978 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | + */ |
|
| 1980 | + public $logo_url = ''; |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | + * |
|
| 1985 | + * @var string |
|
| 1986 | + */ |
|
| 1987 | + /** |
|
| 1988 | + * facebook (facebook.com/profile.name) |
|
| 1989 | + * |
|
| 1990 | + * @var string |
|
| 1991 | + */ |
|
| 1992 | + public $facebook = ''; |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * twitter (twitter.com/twitter_handle) |
|
| 1996 | + * |
|
| 1997 | + * @var string |
|
| 1998 | + */ |
|
| 1999 | + public $twitter = ''; |
|
| 2000 | + |
|
| 2001 | + /** |
|
| 2002 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | + * |
|
| 2004 | + * @var string |
|
| 2005 | + */ |
|
| 2006 | + public $linkedin = ''; |
|
| 2007 | + |
|
| 2008 | + /** |
|
| 2009 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | + * |
|
| 2011 | + * @var string |
|
| 2012 | + */ |
|
| 2013 | + public $pinterest = ''; |
|
| 2014 | + |
|
| 2015 | + /** |
|
| 2016 | + * google+ (google.com/+profileName) |
|
| 2017 | + * |
|
| 2018 | + * @var string |
|
| 2019 | + */ |
|
| 2020 | + public $google = ''; |
|
| 2021 | + |
|
| 2022 | + /** |
|
| 2023 | + * instagram (instagram.com/handle) |
|
| 2024 | + * |
|
| 2025 | + * @var string |
|
| 2026 | + */ |
|
| 2027 | + public $instagram = ''; |
|
| 2028 | + |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * class constructor |
|
| 2032 | + * |
|
| 2033 | + * @access public |
|
| 2034 | + */ |
|
| 2035 | + public function __construct() |
|
| 2036 | + { |
|
| 2037 | + // set default organization settings |
|
| 2038 | + // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | + $this->email = get_bloginfo('admin_email'); |
|
| 2041 | + } |
|
| 2042 | +} |
|
| 2307 | 2043 | |
| 2308 | - /** |
|
| 2309 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2310 | - * |
|
| 2311 | - * @var boolean $track_invalid_checkout_access |
|
| 2312 | - */ |
|
| 2313 | - protected $track_invalid_checkout_access = true; |
|
| 2044 | +/** |
|
| 2045 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2046 | + */ |
|
| 2047 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2048 | +{ |
|
| 2314 | 2049 | |
| 2315 | - /** |
|
| 2316 | - * Whether or not to show the privacy policy consent checkbox |
|
| 2317 | - * |
|
| 2318 | - * @var bool |
|
| 2319 | - */ |
|
| 2320 | - public $consent_checkbox_enabled; |
|
| 2050 | + /** |
|
| 2051 | + * @var string $code |
|
| 2052 | + * eg 'US' |
|
| 2053 | + */ |
|
| 2054 | + public $code; |
|
| 2055 | + |
|
| 2056 | + /** |
|
| 2057 | + * @var string $name |
|
| 2058 | + * eg 'Dollar' |
|
| 2059 | + */ |
|
| 2060 | + public $name; |
|
| 2061 | + |
|
| 2062 | + /** |
|
| 2063 | + * plural name |
|
| 2064 | + * |
|
| 2065 | + * @var string $plural |
|
| 2066 | + * eg 'Dollars' |
|
| 2067 | + */ |
|
| 2068 | + public $plural; |
|
| 2069 | + |
|
| 2070 | + /** |
|
| 2071 | + * currency sign |
|
| 2072 | + * |
|
| 2073 | + * @var string $sign |
|
| 2074 | + * eg '$' |
|
| 2075 | + */ |
|
| 2076 | + public $sign; |
|
| 2077 | + |
|
| 2078 | + /** |
|
| 2079 | + * Whether the currency sign should come before the number or not |
|
| 2080 | + * |
|
| 2081 | + * @var boolean $sign_b4 |
|
| 2082 | + */ |
|
| 2083 | + public $sign_b4; |
|
| 2084 | + |
|
| 2085 | + /** |
|
| 2086 | + * How many digits should come after the decimal place |
|
| 2087 | + * |
|
| 2088 | + * @var int $dec_plc |
|
| 2089 | + */ |
|
| 2090 | + public $dec_plc; |
|
| 2091 | + |
|
| 2092 | + /** |
|
| 2093 | + * Symbol to use for decimal mark |
|
| 2094 | + * |
|
| 2095 | + * @var string $dec_mrk |
|
| 2096 | + * eg '.' |
|
| 2097 | + */ |
|
| 2098 | + public $dec_mrk; |
|
| 2099 | + |
|
| 2100 | + /** |
|
| 2101 | + * Symbol to use for thousands |
|
| 2102 | + * |
|
| 2103 | + * @var string $thsnds |
|
| 2104 | + * eg ',' |
|
| 2105 | + */ |
|
| 2106 | + public $thsnds; |
|
| 2107 | + |
|
| 2108 | + |
|
| 2109 | + /** |
|
| 2110 | + * class constructor |
|
| 2111 | + * |
|
| 2112 | + * @access public |
|
| 2113 | + * @param string $CNT_ISO |
|
| 2114 | + * @throws \EE_Error |
|
| 2115 | + */ |
|
| 2116 | + public function __construct($CNT_ISO = '') |
|
| 2117 | + { |
|
| 2118 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2119 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2120 | + // get country code from organization settings or use default |
|
| 2121 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2122 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2123 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2124 | + : ''; |
|
| 2125 | + // but override if requested |
|
| 2126 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2127 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2128 | + if (! empty($CNT_ISO) |
|
| 2129 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2130 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2131 | + ) { |
|
| 2132 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2133 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2134 | + if ($country instanceof EE_Country) { |
|
| 2135 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | + $this->sign_b4 = $country->currency_sign_before( |
|
| 2140 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | + $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2143 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | + $this->thsnds = $country->currency_thousands_separator( |
|
| 2145 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | + } |
|
| 2147 | + } |
|
| 2148 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2149 | + if (empty($this->code)) { |
|
| 2150 | + // set default currency settings |
|
| 2151 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | + $this->sign = '$'; // currency sign: $ |
|
| 2155 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | + } |
|
| 2160 | + } |
|
| 2161 | +} |
|
| 2321 | 2162 | |
| 2322 | - /** |
|
| 2323 | - * Label text to show on the checkbox |
|
| 2324 | - * |
|
| 2325 | - * @var string |
|
| 2326 | - */ |
|
| 2327 | - public $consent_checkbox_label_text; |
|
| 2163 | +/** |
|
| 2164 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2165 | + */ |
|
| 2166 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2167 | +{ |
|
| 2328 | 2168 | |
| 2329 | - /* |
|
| 2169 | + /** |
|
| 2170 | + * Default registration status |
|
| 2171 | + * |
|
| 2172 | + * @var string $default_STS_ID |
|
| 2173 | + * eg 'RPP' |
|
| 2174 | + */ |
|
| 2175 | + public $default_STS_ID; |
|
| 2176 | + |
|
| 2177 | + /** |
|
| 2178 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2179 | + * registrations) |
|
| 2180 | + * |
|
| 2181 | + * @var int |
|
| 2182 | + */ |
|
| 2183 | + public $default_maximum_number_of_tickets; |
|
| 2184 | + |
|
| 2185 | + /** |
|
| 2186 | + * level of validation to apply to email addresses |
|
| 2187 | + * |
|
| 2188 | + * @var string $email_validation_level |
|
| 2189 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2190 | + */ |
|
| 2191 | + public $email_validation_level; |
|
| 2192 | + |
|
| 2193 | + /** |
|
| 2194 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2195 | + * |
|
| 2196 | + * @var boolean $show_pending_payment_options |
|
| 2197 | + */ |
|
| 2198 | + public $show_pending_payment_options; |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * Whether to skip the registration confirmation page |
|
| 2202 | + * |
|
| 2203 | + * @var boolean $skip_reg_confirmation |
|
| 2204 | + */ |
|
| 2205 | + public $skip_reg_confirmation; |
|
| 2206 | + |
|
| 2207 | + /** |
|
| 2208 | + * an array of SPCO reg steps where: |
|
| 2209 | + * the keys denotes the reg step order |
|
| 2210 | + * each element consists of an array with the following elements: |
|
| 2211 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2212 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2213 | + * "slug" => the URL param used to trigger the reg step |
|
| 2214 | + * |
|
| 2215 | + * @var array $reg_steps |
|
| 2216 | + */ |
|
| 2217 | + public $reg_steps; |
|
| 2218 | + |
|
| 2219 | + /** |
|
| 2220 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2221 | + * |
|
| 2222 | + * @var boolean $reg_confirmation_last |
|
| 2223 | + */ |
|
| 2224 | + public $reg_confirmation_last; |
|
| 2225 | + |
|
| 2226 | + /** |
|
| 2227 | + * Whether or not to enable the EE Bot Trap |
|
| 2228 | + * |
|
| 2229 | + * @var boolean $use_bot_trap |
|
| 2230 | + */ |
|
| 2231 | + public $use_bot_trap; |
|
| 2232 | + |
|
| 2233 | + /** |
|
| 2234 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2235 | + * |
|
| 2236 | + * @var boolean $use_encryption |
|
| 2237 | + */ |
|
| 2238 | + public $use_encryption; |
|
| 2239 | + |
|
| 2240 | + /** |
|
| 2241 | + * Whether or not to use ReCaptcha |
|
| 2242 | + * |
|
| 2243 | + * @var boolean $use_captcha |
|
| 2244 | + */ |
|
| 2245 | + public $use_captcha; |
|
| 2246 | + |
|
| 2247 | + /** |
|
| 2248 | + * ReCaptcha Theme |
|
| 2249 | + * |
|
| 2250 | + * @var string $recaptcha_theme |
|
| 2251 | + * options: 'dark', 'light', 'invisible' |
|
| 2252 | + */ |
|
| 2253 | + public $recaptcha_theme; |
|
| 2254 | + |
|
| 2255 | + /** |
|
| 2256 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2257 | + * |
|
| 2258 | + * @var string $recaptcha_badge |
|
| 2259 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2260 | + */ |
|
| 2261 | + public $recaptcha_badge; |
|
| 2262 | + |
|
| 2263 | + /** |
|
| 2264 | + * ReCaptcha Type |
|
| 2265 | + * |
|
| 2266 | + * @var string $recaptcha_type |
|
| 2267 | + * options: 'audio', 'image' |
|
| 2268 | + */ |
|
| 2269 | + public $recaptcha_type; |
|
| 2270 | + |
|
| 2271 | + /** |
|
| 2272 | + * ReCaptcha language |
|
| 2273 | + * |
|
| 2274 | + * @var string $recaptcha_language |
|
| 2275 | + * eg 'en' |
|
| 2276 | + */ |
|
| 2277 | + public $recaptcha_language; |
|
| 2278 | + |
|
| 2279 | + /** |
|
| 2280 | + * ReCaptcha public key |
|
| 2281 | + * |
|
| 2282 | + * @var string $recaptcha_publickey |
|
| 2283 | + */ |
|
| 2284 | + public $recaptcha_publickey; |
|
| 2285 | + |
|
| 2286 | + /** |
|
| 2287 | + * ReCaptcha private key |
|
| 2288 | + * |
|
| 2289 | + * @var string $recaptcha_privatekey |
|
| 2290 | + */ |
|
| 2291 | + public $recaptcha_privatekey; |
|
| 2292 | + |
|
| 2293 | + /** |
|
| 2294 | + * array of form names protected by ReCaptcha |
|
| 2295 | + * |
|
| 2296 | + * @var array $recaptcha_protected_forms |
|
| 2297 | + */ |
|
| 2298 | + public $recaptcha_protected_forms; |
|
| 2299 | + |
|
| 2300 | + /** |
|
| 2301 | + * ReCaptcha width |
|
| 2302 | + * |
|
| 2303 | + * @var int $recaptcha_width |
|
| 2304 | + * @deprecated |
|
| 2305 | + */ |
|
| 2306 | + public $recaptcha_width; |
|
| 2307 | + |
|
| 2308 | + /** |
|
| 2309 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2310 | + * |
|
| 2311 | + * @var boolean $track_invalid_checkout_access |
|
| 2312 | + */ |
|
| 2313 | + protected $track_invalid_checkout_access = true; |
|
| 2314 | + |
|
| 2315 | + /** |
|
| 2316 | + * Whether or not to show the privacy policy consent checkbox |
|
| 2317 | + * |
|
| 2318 | + * @var bool |
|
| 2319 | + */ |
|
| 2320 | + public $consent_checkbox_enabled; |
|
| 2321 | + |
|
| 2322 | + /** |
|
| 2323 | + * Label text to show on the checkbox |
|
| 2324 | + * |
|
| 2325 | + * @var string |
|
| 2326 | + */ |
|
| 2327 | + public $consent_checkbox_label_text; |
|
| 2328 | + |
|
| 2329 | + /* |
|
| 2330 | 2330 | * String describing how long to keep payment logs. Passed into DateTime constructor |
| 2331 | 2331 | * @var string |
| 2332 | 2332 | */ |
| 2333 | - public $gateway_log_lifespan = '1 week'; |
|
| 2334 | - |
|
| 2335 | - |
|
| 2336 | - /** |
|
| 2337 | - * class constructor |
|
| 2338 | - * |
|
| 2339 | - * @access public |
|
| 2340 | - */ |
|
| 2341 | - public function __construct() |
|
| 2342 | - { |
|
| 2343 | - // set default registration settings |
|
| 2344 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2345 | - $this->email_validation_level = 'wp_default'; |
|
| 2346 | - $this->show_pending_payment_options = true; |
|
| 2347 | - $this->skip_reg_confirmation = true; |
|
| 2348 | - $this->reg_steps = array(); |
|
| 2349 | - $this->reg_confirmation_last = false; |
|
| 2350 | - $this->use_bot_trap = true; |
|
| 2351 | - $this->use_encryption = true; |
|
| 2352 | - $this->use_captcha = false; |
|
| 2353 | - $this->recaptcha_theme = 'light'; |
|
| 2354 | - $this->recaptcha_badge = 'bottomleft'; |
|
| 2355 | - $this->recaptcha_type = 'image'; |
|
| 2356 | - $this->recaptcha_language = 'en'; |
|
| 2357 | - $this->recaptcha_publickey = null; |
|
| 2358 | - $this->recaptcha_privatekey = null; |
|
| 2359 | - $this->recaptcha_protected_forms = array(); |
|
| 2360 | - $this->recaptcha_width = 500; |
|
| 2361 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2362 | - $this->consent_checkbox_enabled = false; |
|
| 2363 | - $this->consent_checkbox_label_text = ''; |
|
| 2364 | - $this->gateway_log_lifespan = '7 days'; |
|
| 2365 | - } |
|
| 2366 | - |
|
| 2367 | - |
|
| 2368 | - /** |
|
| 2369 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2370 | - * |
|
| 2371 | - * @since 4.8.8.rc.019 |
|
| 2372 | - */ |
|
| 2373 | - public function do_hooks() |
|
| 2374 | - { |
|
| 2375 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2376 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2377 | - add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2378 | - } |
|
| 2379 | - |
|
| 2380 | - |
|
| 2381 | - /** |
|
| 2382 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2383 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2384 | - */ |
|
| 2385 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2386 | - { |
|
| 2387 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2388 | - } |
|
| 2389 | - |
|
| 2390 | - |
|
| 2391 | - /** |
|
| 2392 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2393 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2394 | - */ |
|
| 2395 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2396 | - { |
|
| 2397 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2398 | - } |
|
| 2399 | - |
|
| 2400 | - |
|
| 2401 | - /** |
|
| 2402 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2403 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2404 | - * |
|
| 2405 | - * @throws InvalidArgumentException |
|
| 2406 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2407 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2408 | - */ |
|
| 2409 | - public function setDefaultCheckboxLabelText() |
|
| 2410 | - { |
|
| 2411 | - if ($this->getConsentCheckboxLabelText() === null |
|
| 2412 | - || $this->getConsentCheckboxLabelText() === '') { |
|
| 2413 | - $opening_a_tag = ''; |
|
| 2414 | - $closing_a_tag = ''; |
|
| 2415 | - if (function_exists('get_privacy_policy_url')) { |
|
| 2416 | - $privacy_page_url = get_privacy_policy_url(); |
|
| 2417 | - if (! empty($privacy_page_url)) { |
|
| 2418 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2419 | - $closing_a_tag = '</a>'; |
|
| 2420 | - } |
|
| 2421 | - } |
|
| 2422 | - $loader = LoaderFactory::getLoader(); |
|
| 2423 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2424 | - /** |
|
| 2425 | - * @var $org_config EE_Organization_Config |
|
| 2426 | - */ |
|
| 2427 | - |
|
| 2428 | - $this->setConsentCheckboxLabelText( |
|
| 2429 | - sprintf( |
|
| 2430 | - esc_html__( |
|
| 2431 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2432 | - 'event_espresso' |
|
| 2433 | - ), |
|
| 2434 | - $org_config->name, |
|
| 2435 | - $opening_a_tag, |
|
| 2436 | - $closing_a_tag |
|
| 2437 | - ) |
|
| 2438 | - ); |
|
| 2439 | - } |
|
| 2440 | - } |
|
| 2441 | - |
|
| 2442 | - |
|
| 2443 | - /** |
|
| 2444 | - * @return boolean |
|
| 2445 | - */ |
|
| 2446 | - public function track_invalid_checkout_access() |
|
| 2447 | - { |
|
| 2448 | - return $this->track_invalid_checkout_access; |
|
| 2449 | - } |
|
| 2450 | - |
|
| 2451 | - |
|
| 2452 | - /** |
|
| 2453 | - * @param boolean $track_invalid_checkout_access |
|
| 2454 | - */ |
|
| 2455 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2456 | - { |
|
| 2457 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2458 | - $track_invalid_checkout_access, |
|
| 2459 | - FILTER_VALIDATE_BOOLEAN |
|
| 2460 | - ); |
|
| 2461 | - } |
|
| 2462 | - |
|
| 2463 | - |
|
| 2464 | - /** |
|
| 2465 | - * Gets the options to make availalbe for the gateway log lifespan |
|
| 2466 | - * @return array |
|
| 2467 | - */ |
|
| 2468 | - public function gatewayLogLifespanOptions() |
|
| 2469 | - { |
|
| 2470 | - return (array) apply_filters( |
|
| 2471 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2472 | - array( |
|
| 2473 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2474 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2475 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2476 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2477 | - '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2478 | - ) |
|
| 2479 | - ); |
|
| 2480 | - } |
|
| 2481 | - |
|
| 2482 | - |
|
| 2483 | - /** |
|
| 2484 | - * @return bool |
|
| 2485 | - */ |
|
| 2486 | - public function isConsentCheckboxEnabled() |
|
| 2487 | - { |
|
| 2488 | - return $this->consent_checkbox_enabled; |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - /** |
|
| 2493 | - * @param bool $consent_checkbox_enabled |
|
| 2494 | - */ |
|
| 2495 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2496 | - { |
|
| 2497 | - $this->consent_checkbox_enabled = filter_var( |
|
| 2498 | - $consent_checkbox_enabled, |
|
| 2499 | - FILTER_VALIDATE_BOOLEAN |
|
| 2500 | - ); |
|
| 2501 | - } |
|
| 2502 | - |
|
| 2503 | - |
|
| 2504 | - /** |
|
| 2505 | - * @return string |
|
| 2506 | - */ |
|
| 2507 | - public function getConsentCheckboxLabelText() |
|
| 2508 | - { |
|
| 2509 | - return $this->consent_checkbox_label_text; |
|
| 2510 | - } |
|
| 2511 | - |
|
| 2512 | - |
|
| 2513 | - /** |
|
| 2514 | - * @param string $consent_checkbox_label_text |
|
| 2515 | - */ |
|
| 2516 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2517 | - { |
|
| 2518 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2519 | - } |
|
| 2333 | + public $gateway_log_lifespan = '1 week'; |
|
| 2334 | + |
|
| 2335 | + |
|
| 2336 | + /** |
|
| 2337 | + * class constructor |
|
| 2338 | + * |
|
| 2339 | + * @access public |
|
| 2340 | + */ |
|
| 2341 | + public function __construct() |
|
| 2342 | + { |
|
| 2343 | + // set default registration settings |
|
| 2344 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2345 | + $this->email_validation_level = 'wp_default'; |
|
| 2346 | + $this->show_pending_payment_options = true; |
|
| 2347 | + $this->skip_reg_confirmation = true; |
|
| 2348 | + $this->reg_steps = array(); |
|
| 2349 | + $this->reg_confirmation_last = false; |
|
| 2350 | + $this->use_bot_trap = true; |
|
| 2351 | + $this->use_encryption = true; |
|
| 2352 | + $this->use_captcha = false; |
|
| 2353 | + $this->recaptcha_theme = 'light'; |
|
| 2354 | + $this->recaptcha_badge = 'bottomleft'; |
|
| 2355 | + $this->recaptcha_type = 'image'; |
|
| 2356 | + $this->recaptcha_language = 'en'; |
|
| 2357 | + $this->recaptcha_publickey = null; |
|
| 2358 | + $this->recaptcha_privatekey = null; |
|
| 2359 | + $this->recaptcha_protected_forms = array(); |
|
| 2360 | + $this->recaptcha_width = 500; |
|
| 2361 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2362 | + $this->consent_checkbox_enabled = false; |
|
| 2363 | + $this->consent_checkbox_label_text = ''; |
|
| 2364 | + $this->gateway_log_lifespan = '7 days'; |
|
| 2365 | + } |
|
| 2366 | + |
|
| 2367 | + |
|
| 2368 | + /** |
|
| 2369 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2370 | + * |
|
| 2371 | + * @since 4.8.8.rc.019 |
|
| 2372 | + */ |
|
| 2373 | + public function do_hooks() |
|
| 2374 | + { |
|
| 2375 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2376 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2377 | + add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2378 | + } |
|
| 2379 | + |
|
| 2380 | + |
|
| 2381 | + /** |
|
| 2382 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2383 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2384 | + */ |
|
| 2385 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2386 | + { |
|
| 2387 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2388 | + } |
|
| 2389 | + |
|
| 2390 | + |
|
| 2391 | + /** |
|
| 2392 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2393 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2394 | + */ |
|
| 2395 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2396 | + { |
|
| 2397 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2398 | + } |
|
| 2399 | + |
|
| 2400 | + |
|
| 2401 | + /** |
|
| 2402 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2403 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2404 | + * |
|
| 2405 | + * @throws InvalidArgumentException |
|
| 2406 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2407 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2408 | + */ |
|
| 2409 | + public function setDefaultCheckboxLabelText() |
|
| 2410 | + { |
|
| 2411 | + if ($this->getConsentCheckboxLabelText() === null |
|
| 2412 | + || $this->getConsentCheckboxLabelText() === '') { |
|
| 2413 | + $opening_a_tag = ''; |
|
| 2414 | + $closing_a_tag = ''; |
|
| 2415 | + if (function_exists('get_privacy_policy_url')) { |
|
| 2416 | + $privacy_page_url = get_privacy_policy_url(); |
|
| 2417 | + if (! empty($privacy_page_url)) { |
|
| 2418 | + $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2419 | + $closing_a_tag = '</a>'; |
|
| 2420 | + } |
|
| 2421 | + } |
|
| 2422 | + $loader = LoaderFactory::getLoader(); |
|
| 2423 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2424 | + /** |
|
| 2425 | + * @var $org_config EE_Organization_Config |
|
| 2426 | + */ |
|
| 2427 | + |
|
| 2428 | + $this->setConsentCheckboxLabelText( |
|
| 2429 | + sprintf( |
|
| 2430 | + esc_html__( |
|
| 2431 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2432 | + 'event_espresso' |
|
| 2433 | + ), |
|
| 2434 | + $org_config->name, |
|
| 2435 | + $opening_a_tag, |
|
| 2436 | + $closing_a_tag |
|
| 2437 | + ) |
|
| 2438 | + ); |
|
| 2439 | + } |
|
| 2440 | + } |
|
| 2441 | + |
|
| 2442 | + |
|
| 2443 | + /** |
|
| 2444 | + * @return boolean |
|
| 2445 | + */ |
|
| 2446 | + public function track_invalid_checkout_access() |
|
| 2447 | + { |
|
| 2448 | + return $this->track_invalid_checkout_access; |
|
| 2449 | + } |
|
| 2450 | + |
|
| 2451 | + |
|
| 2452 | + /** |
|
| 2453 | + * @param boolean $track_invalid_checkout_access |
|
| 2454 | + */ |
|
| 2455 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2456 | + { |
|
| 2457 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2458 | + $track_invalid_checkout_access, |
|
| 2459 | + FILTER_VALIDATE_BOOLEAN |
|
| 2460 | + ); |
|
| 2461 | + } |
|
| 2462 | + |
|
| 2463 | + |
|
| 2464 | + /** |
|
| 2465 | + * Gets the options to make availalbe for the gateway log lifespan |
|
| 2466 | + * @return array |
|
| 2467 | + */ |
|
| 2468 | + public function gatewayLogLifespanOptions() |
|
| 2469 | + { |
|
| 2470 | + return (array) apply_filters( |
|
| 2471 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2472 | + array( |
|
| 2473 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2474 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2475 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2476 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2477 | + '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2478 | + ) |
|
| 2479 | + ); |
|
| 2480 | + } |
|
| 2481 | + |
|
| 2482 | + |
|
| 2483 | + /** |
|
| 2484 | + * @return bool |
|
| 2485 | + */ |
|
| 2486 | + public function isConsentCheckboxEnabled() |
|
| 2487 | + { |
|
| 2488 | + return $this->consent_checkbox_enabled; |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + /** |
|
| 2493 | + * @param bool $consent_checkbox_enabled |
|
| 2494 | + */ |
|
| 2495 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2496 | + { |
|
| 2497 | + $this->consent_checkbox_enabled = filter_var( |
|
| 2498 | + $consent_checkbox_enabled, |
|
| 2499 | + FILTER_VALIDATE_BOOLEAN |
|
| 2500 | + ); |
|
| 2501 | + } |
|
| 2502 | + |
|
| 2503 | + |
|
| 2504 | + /** |
|
| 2505 | + * @return string |
|
| 2506 | + */ |
|
| 2507 | + public function getConsentCheckboxLabelText() |
|
| 2508 | + { |
|
| 2509 | + return $this->consent_checkbox_label_text; |
|
| 2510 | + } |
|
| 2511 | + |
|
| 2512 | + |
|
| 2513 | + /** |
|
| 2514 | + * @param string $consent_checkbox_label_text |
|
| 2515 | + */ |
|
| 2516 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2517 | + { |
|
| 2518 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2519 | + } |
|
| 2520 | 2520 | } |
| 2521 | 2521 | |
| 2522 | 2522 | /** |
@@ -2525,157 +2525,157 @@ discard block |
||
| 2525 | 2525 | class EE_Admin_Config extends EE_Config_Base |
| 2526 | 2526 | { |
| 2527 | 2527 | |
| 2528 | - /** |
|
| 2529 | - * @var boolean $use_personnel_manager |
|
| 2530 | - */ |
|
| 2531 | - public $use_personnel_manager; |
|
| 2532 | - |
|
| 2533 | - /** |
|
| 2534 | - * @var boolean $use_dashboard_widget |
|
| 2535 | - */ |
|
| 2536 | - public $use_dashboard_widget; |
|
| 2537 | - |
|
| 2538 | - /** |
|
| 2539 | - * @var int $events_in_dashboard |
|
| 2540 | - */ |
|
| 2541 | - public $events_in_dashboard; |
|
| 2542 | - |
|
| 2543 | - /** |
|
| 2544 | - * @var boolean $use_event_timezones |
|
| 2545 | - */ |
|
| 2546 | - public $use_event_timezones; |
|
| 2547 | - |
|
| 2548 | - /** |
|
| 2549 | - * @var boolean $use_full_logging |
|
| 2550 | - */ |
|
| 2551 | - public $use_full_logging; |
|
| 2552 | - |
|
| 2553 | - /** |
|
| 2554 | - * @var string $log_file_name |
|
| 2555 | - */ |
|
| 2556 | - public $log_file_name; |
|
| 2557 | - |
|
| 2558 | - /** |
|
| 2559 | - * @var string $debug_file_name |
|
| 2560 | - */ |
|
| 2561 | - public $debug_file_name; |
|
| 2562 | - |
|
| 2563 | - /** |
|
| 2564 | - * @var boolean $use_remote_logging |
|
| 2565 | - */ |
|
| 2566 | - public $use_remote_logging; |
|
| 2567 | - |
|
| 2568 | - /** |
|
| 2569 | - * @var string $remote_logging_url |
|
| 2570 | - */ |
|
| 2571 | - public $remote_logging_url; |
|
| 2572 | - |
|
| 2573 | - /** |
|
| 2574 | - * @var boolean $show_reg_footer |
|
| 2575 | - */ |
|
| 2576 | - public $show_reg_footer; |
|
| 2577 | - |
|
| 2578 | - /** |
|
| 2579 | - * @var string $affiliate_id |
|
| 2580 | - */ |
|
| 2581 | - public $affiliate_id; |
|
| 2582 | - |
|
| 2583 | - /** |
|
| 2584 | - * help tours on or off (global setting) |
|
| 2585 | - * |
|
| 2586 | - * @var boolean |
|
| 2587 | - */ |
|
| 2588 | - public $help_tour_activation; |
|
| 2589 | - |
|
| 2590 | - /** |
|
| 2591 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2592 | - * but is incompatible with some server configuration errors |
|
| 2593 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2594 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2595 | - * |
|
| 2596 | - * @var boolean $encode_session_data |
|
| 2597 | - */ |
|
| 2598 | - private $encode_session_data = false; |
|
| 2599 | - |
|
| 2600 | - |
|
| 2601 | - /** |
|
| 2602 | - * class constructor |
|
| 2603 | - * |
|
| 2604 | - * @access public |
|
| 2605 | - */ |
|
| 2606 | - public function __construct() |
|
| 2607 | - { |
|
| 2608 | - // set default general admin settings |
|
| 2609 | - $this->use_personnel_manager = true; |
|
| 2610 | - $this->use_dashboard_widget = true; |
|
| 2611 | - $this->events_in_dashboard = 30; |
|
| 2612 | - $this->use_event_timezones = false; |
|
| 2613 | - $this->use_full_logging = false; |
|
| 2614 | - $this->use_remote_logging = false; |
|
| 2615 | - $this->remote_logging_url = null; |
|
| 2616 | - $this->show_reg_footer = apply_filters( |
|
| 2617 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2618 | - false |
|
| 2619 | - ); |
|
| 2620 | - $this->affiliate_id = 'default'; |
|
| 2621 | - $this->help_tour_activation = true; |
|
| 2622 | - $this->encode_session_data = false; |
|
| 2623 | - } |
|
| 2624 | - |
|
| 2625 | - |
|
| 2626 | - /** |
|
| 2627 | - * @param bool $reset |
|
| 2628 | - * @return string |
|
| 2629 | - */ |
|
| 2630 | - public function log_file_name($reset = false) |
|
| 2631 | - { |
|
| 2632 | - if (empty($this->log_file_name) || $reset) { |
|
| 2633 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2634 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2635 | - } |
|
| 2636 | - return $this->log_file_name; |
|
| 2637 | - } |
|
| 2638 | - |
|
| 2639 | - |
|
| 2640 | - /** |
|
| 2641 | - * @param bool $reset |
|
| 2642 | - * @return string |
|
| 2643 | - */ |
|
| 2644 | - public function debug_file_name($reset = false) |
|
| 2645 | - { |
|
| 2646 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2647 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2648 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2649 | - } |
|
| 2650 | - return $this->debug_file_name; |
|
| 2651 | - } |
|
| 2652 | - |
|
| 2653 | - |
|
| 2654 | - /** |
|
| 2655 | - * @return string |
|
| 2656 | - */ |
|
| 2657 | - public function affiliate_id() |
|
| 2658 | - { |
|
| 2659 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2660 | - } |
|
| 2661 | - |
|
| 2662 | - |
|
| 2663 | - /** |
|
| 2664 | - * @return boolean |
|
| 2665 | - */ |
|
| 2666 | - public function encode_session_data() |
|
| 2667 | - { |
|
| 2668 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2669 | - } |
|
| 2670 | - |
|
| 2671 | - |
|
| 2672 | - /** |
|
| 2673 | - * @param boolean $encode_session_data |
|
| 2674 | - */ |
|
| 2675 | - public function set_encode_session_data($encode_session_data) |
|
| 2676 | - { |
|
| 2677 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2678 | - } |
|
| 2528 | + /** |
|
| 2529 | + * @var boolean $use_personnel_manager |
|
| 2530 | + */ |
|
| 2531 | + public $use_personnel_manager; |
|
| 2532 | + |
|
| 2533 | + /** |
|
| 2534 | + * @var boolean $use_dashboard_widget |
|
| 2535 | + */ |
|
| 2536 | + public $use_dashboard_widget; |
|
| 2537 | + |
|
| 2538 | + /** |
|
| 2539 | + * @var int $events_in_dashboard |
|
| 2540 | + */ |
|
| 2541 | + public $events_in_dashboard; |
|
| 2542 | + |
|
| 2543 | + /** |
|
| 2544 | + * @var boolean $use_event_timezones |
|
| 2545 | + */ |
|
| 2546 | + public $use_event_timezones; |
|
| 2547 | + |
|
| 2548 | + /** |
|
| 2549 | + * @var boolean $use_full_logging |
|
| 2550 | + */ |
|
| 2551 | + public $use_full_logging; |
|
| 2552 | + |
|
| 2553 | + /** |
|
| 2554 | + * @var string $log_file_name |
|
| 2555 | + */ |
|
| 2556 | + public $log_file_name; |
|
| 2557 | + |
|
| 2558 | + /** |
|
| 2559 | + * @var string $debug_file_name |
|
| 2560 | + */ |
|
| 2561 | + public $debug_file_name; |
|
| 2562 | + |
|
| 2563 | + /** |
|
| 2564 | + * @var boolean $use_remote_logging |
|
| 2565 | + */ |
|
| 2566 | + public $use_remote_logging; |
|
| 2567 | + |
|
| 2568 | + /** |
|
| 2569 | + * @var string $remote_logging_url |
|
| 2570 | + */ |
|
| 2571 | + public $remote_logging_url; |
|
| 2572 | + |
|
| 2573 | + /** |
|
| 2574 | + * @var boolean $show_reg_footer |
|
| 2575 | + */ |
|
| 2576 | + public $show_reg_footer; |
|
| 2577 | + |
|
| 2578 | + /** |
|
| 2579 | + * @var string $affiliate_id |
|
| 2580 | + */ |
|
| 2581 | + public $affiliate_id; |
|
| 2582 | + |
|
| 2583 | + /** |
|
| 2584 | + * help tours on or off (global setting) |
|
| 2585 | + * |
|
| 2586 | + * @var boolean |
|
| 2587 | + */ |
|
| 2588 | + public $help_tour_activation; |
|
| 2589 | + |
|
| 2590 | + /** |
|
| 2591 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2592 | + * but is incompatible with some server configuration errors |
|
| 2593 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2594 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2595 | + * |
|
| 2596 | + * @var boolean $encode_session_data |
|
| 2597 | + */ |
|
| 2598 | + private $encode_session_data = false; |
|
| 2599 | + |
|
| 2600 | + |
|
| 2601 | + /** |
|
| 2602 | + * class constructor |
|
| 2603 | + * |
|
| 2604 | + * @access public |
|
| 2605 | + */ |
|
| 2606 | + public function __construct() |
|
| 2607 | + { |
|
| 2608 | + // set default general admin settings |
|
| 2609 | + $this->use_personnel_manager = true; |
|
| 2610 | + $this->use_dashboard_widget = true; |
|
| 2611 | + $this->events_in_dashboard = 30; |
|
| 2612 | + $this->use_event_timezones = false; |
|
| 2613 | + $this->use_full_logging = false; |
|
| 2614 | + $this->use_remote_logging = false; |
|
| 2615 | + $this->remote_logging_url = null; |
|
| 2616 | + $this->show_reg_footer = apply_filters( |
|
| 2617 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2618 | + false |
|
| 2619 | + ); |
|
| 2620 | + $this->affiliate_id = 'default'; |
|
| 2621 | + $this->help_tour_activation = true; |
|
| 2622 | + $this->encode_session_data = false; |
|
| 2623 | + } |
|
| 2624 | + |
|
| 2625 | + |
|
| 2626 | + /** |
|
| 2627 | + * @param bool $reset |
|
| 2628 | + * @return string |
|
| 2629 | + */ |
|
| 2630 | + public function log_file_name($reset = false) |
|
| 2631 | + { |
|
| 2632 | + if (empty($this->log_file_name) || $reset) { |
|
| 2633 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2634 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2635 | + } |
|
| 2636 | + return $this->log_file_name; |
|
| 2637 | + } |
|
| 2638 | + |
|
| 2639 | + |
|
| 2640 | + /** |
|
| 2641 | + * @param bool $reset |
|
| 2642 | + * @return string |
|
| 2643 | + */ |
|
| 2644 | + public function debug_file_name($reset = false) |
|
| 2645 | + { |
|
| 2646 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2647 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2648 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2649 | + } |
|
| 2650 | + return $this->debug_file_name; |
|
| 2651 | + } |
|
| 2652 | + |
|
| 2653 | + |
|
| 2654 | + /** |
|
| 2655 | + * @return string |
|
| 2656 | + */ |
|
| 2657 | + public function affiliate_id() |
|
| 2658 | + { |
|
| 2659 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2660 | + } |
|
| 2661 | + |
|
| 2662 | + |
|
| 2663 | + /** |
|
| 2664 | + * @return boolean |
|
| 2665 | + */ |
|
| 2666 | + public function encode_session_data() |
|
| 2667 | + { |
|
| 2668 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2669 | + } |
|
| 2670 | + |
|
| 2671 | + |
|
| 2672 | + /** |
|
| 2673 | + * @param boolean $encode_session_data |
|
| 2674 | + */ |
|
| 2675 | + public function set_encode_session_data($encode_session_data) |
|
| 2676 | + { |
|
| 2677 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2678 | + } |
|
| 2679 | 2679 | } |
| 2680 | 2680 | |
| 2681 | 2681 | /** |
@@ -2684,70 +2684,70 @@ discard block |
||
| 2684 | 2684 | class EE_Template_Config extends EE_Config_Base |
| 2685 | 2685 | { |
| 2686 | 2686 | |
| 2687 | - /** |
|
| 2688 | - * @var boolean $enable_default_style |
|
| 2689 | - */ |
|
| 2690 | - public $enable_default_style; |
|
| 2691 | - |
|
| 2692 | - /** |
|
| 2693 | - * @var string $custom_style_sheet |
|
| 2694 | - */ |
|
| 2695 | - public $custom_style_sheet; |
|
| 2696 | - |
|
| 2697 | - /** |
|
| 2698 | - * @var boolean $display_address_in_regform |
|
| 2699 | - */ |
|
| 2700 | - public $display_address_in_regform; |
|
| 2701 | - |
|
| 2702 | - /** |
|
| 2703 | - * @var int $display_description_on_multi_reg_page |
|
| 2704 | - */ |
|
| 2705 | - public $display_description_on_multi_reg_page; |
|
| 2706 | - |
|
| 2707 | - /** |
|
| 2708 | - * @var boolean $use_custom_templates |
|
| 2709 | - */ |
|
| 2710 | - public $use_custom_templates; |
|
| 2711 | - |
|
| 2712 | - /** |
|
| 2713 | - * @var string $current_espresso_theme |
|
| 2714 | - */ |
|
| 2715 | - public $current_espresso_theme; |
|
| 2716 | - |
|
| 2717 | - /** |
|
| 2718 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2719 | - */ |
|
| 2720 | - public $EED_Ticket_Selector; |
|
| 2721 | - |
|
| 2722 | - /** |
|
| 2723 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2724 | - */ |
|
| 2725 | - public $EED_Event_Single; |
|
| 2726 | - |
|
| 2727 | - /** |
|
| 2728 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2729 | - */ |
|
| 2730 | - public $EED_Events_Archive; |
|
| 2731 | - |
|
| 2732 | - |
|
| 2733 | - /** |
|
| 2734 | - * class constructor |
|
| 2735 | - * |
|
| 2736 | - * @access public |
|
| 2737 | - */ |
|
| 2738 | - public function __construct() |
|
| 2739 | - { |
|
| 2740 | - // set default template settings |
|
| 2741 | - $this->enable_default_style = true; |
|
| 2742 | - $this->custom_style_sheet = null; |
|
| 2743 | - $this->display_address_in_regform = true; |
|
| 2744 | - $this->display_description_on_multi_reg_page = false; |
|
| 2745 | - $this->use_custom_templates = false; |
|
| 2746 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2747 | - $this->EED_Event_Single = null; |
|
| 2748 | - $this->EED_Events_Archive = null; |
|
| 2749 | - $this->EED_Ticket_Selector = null; |
|
| 2750 | - } |
|
| 2687 | + /** |
|
| 2688 | + * @var boolean $enable_default_style |
|
| 2689 | + */ |
|
| 2690 | + public $enable_default_style; |
|
| 2691 | + |
|
| 2692 | + /** |
|
| 2693 | + * @var string $custom_style_sheet |
|
| 2694 | + */ |
|
| 2695 | + public $custom_style_sheet; |
|
| 2696 | + |
|
| 2697 | + /** |
|
| 2698 | + * @var boolean $display_address_in_regform |
|
| 2699 | + */ |
|
| 2700 | + public $display_address_in_regform; |
|
| 2701 | + |
|
| 2702 | + /** |
|
| 2703 | + * @var int $display_description_on_multi_reg_page |
|
| 2704 | + */ |
|
| 2705 | + public $display_description_on_multi_reg_page; |
|
| 2706 | + |
|
| 2707 | + /** |
|
| 2708 | + * @var boolean $use_custom_templates |
|
| 2709 | + */ |
|
| 2710 | + public $use_custom_templates; |
|
| 2711 | + |
|
| 2712 | + /** |
|
| 2713 | + * @var string $current_espresso_theme |
|
| 2714 | + */ |
|
| 2715 | + public $current_espresso_theme; |
|
| 2716 | + |
|
| 2717 | + /** |
|
| 2718 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2719 | + */ |
|
| 2720 | + public $EED_Ticket_Selector; |
|
| 2721 | + |
|
| 2722 | + /** |
|
| 2723 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2724 | + */ |
|
| 2725 | + public $EED_Event_Single; |
|
| 2726 | + |
|
| 2727 | + /** |
|
| 2728 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2729 | + */ |
|
| 2730 | + public $EED_Events_Archive; |
|
| 2731 | + |
|
| 2732 | + |
|
| 2733 | + /** |
|
| 2734 | + * class constructor |
|
| 2735 | + * |
|
| 2736 | + * @access public |
|
| 2737 | + */ |
|
| 2738 | + public function __construct() |
|
| 2739 | + { |
|
| 2740 | + // set default template settings |
|
| 2741 | + $this->enable_default_style = true; |
|
| 2742 | + $this->custom_style_sheet = null; |
|
| 2743 | + $this->display_address_in_regform = true; |
|
| 2744 | + $this->display_description_on_multi_reg_page = false; |
|
| 2745 | + $this->use_custom_templates = false; |
|
| 2746 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2747 | + $this->EED_Event_Single = null; |
|
| 2748 | + $this->EED_Events_Archive = null; |
|
| 2749 | + $this->EED_Ticket_Selector = null; |
|
| 2750 | + } |
|
| 2751 | 2751 | } |
| 2752 | 2752 | |
| 2753 | 2753 | /** |
@@ -2756,114 +2756,114 @@ discard block |
||
| 2756 | 2756 | class EE_Map_Config extends EE_Config_Base |
| 2757 | 2757 | { |
| 2758 | 2758 | |
| 2759 | - /** |
|
| 2760 | - * @var boolean $use_google_maps |
|
| 2761 | - */ |
|
| 2762 | - public $use_google_maps; |
|
| 2763 | - |
|
| 2764 | - /** |
|
| 2765 | - * @var string $api_key |
|
| 2766 | - */ |
|
| 2767 | - public $google_map_api_key; |
|
| 2768 | - |
|
| 2769 | - /** |
|
| 2770 | - * @var int $event_details_map_width |
|
| 2771 | - */ |
|
| 2772 | - public $event_details_map_width; |
|
| 2773 | - |
|
| 2774 | - /** |
|
| 2775 | - * @var int $event_details_map_height |
|
| 2776 | - */ |
|
| 2777 | - public $event_details_map_height; |
|
| 2778 | - |
|
| 2779 | - /** |
|
| 2780 | - * @var int $event_details_map_zoom |
|
| 2781 | - */ |
|
| 2782 | - public $event_details_map_zoom; |
|
| 2783 | - |
|
| 2784 | - /** |
|
| 2785 | - * @var boolean $event_details_display_nav |
|
| 2786 | - */ |
|
| 2787 | - public $event_details_display_nav; |
|
| 2788 | - |
|
| 2789 | - /** |
|
| 2790 | - * @var boolean $event_details_nav_size |
|
| 2791 | - */ |
|
| 2792 | - public $event_details_nav_size; |
|
| 2793 | - |
|
| 2794 | - /** |
|
| 2795 | - * @var string $event_details_control_type |
|
| 2796 | - */ |
|
| 2797 | - public $event_details_control_type; |
|
| 2798 | - |
|
| 2799 | - /** |
|
| 2800 | - * @var string $event_details_map_align |
|
| 2801 | - */ |
|
| 2802 | - public $event_details_map_align; |
|
| 2803 | - |
|
| 2804 | - /** |
|
| 2805 | - * @var int $event_list_map_width |
|
| 2806 | - */ |
|
| 2807 | - public $event_list_map_width; |
|
| 2808 | - |
|
| 2809 | - /** |
|
| 2810 | - * @var int $event_list_map_height |
|
| 2811 | - */ |
|
| 2812 | - public $event_list_map_height; |
|
| 2813 | - |
|
| 2814 | - /** |
|
| 2815 | - * @var int $event_list_map_zoom |
|
| 2816 | - */ |
|
| 2817 | - public $event_list_map_zoom; |
|
| 2818 | - |
|
| 2819 | - /** |
|
| 2820 | - * @var boolean $event_list_display_nav |
|
| 2821 | - */ |
|
| 2822 | - public $event_list_display_nav; |
|
| 2823 | - |
|
| 2824 | - /** |
|
| 2825 | - * @var boolean $event_list_nav_size |
|
| 2826 | - */ |
|
| 2827 | - public $event_list_nav_size; |
|
| 2828 | - |
|
| 2829 | - /** |
|
| 2830 | - * @var string $event_list_control_type |
|
| 2831 | - */ |
|
| 2832 | - public $event_list_control_type; |
|
| 2833 | - |
|
| 2834 | - /** |
|
| 2835 | - * @var string $event_list_map_align |
|
| 2836 | - */ |
|
| 2837 | - public $event_list_map_align; |
|
| 2838 | - |
|
| 2839 | - |
|
| 2840 | - /** |
|
| 2841 | - * class constructor |
|
| 2842 | - * |
|
| 2843 | - * @access public |
|
| 2844 | - */ |
|
| 2845 | - public function __construct() |
|
| 2846 | - { |
|
| 2847 | - // set default map settings |
|
| 2848 | - $this->use_google_maps = true; |
|
| 2849 | - $this->google_map_api_key = ''; |
|
| 2850 | - // for event details pages (reg page) |
|
| 2851 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2852 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2853 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2854 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2855 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2856 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2857 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2858 | - // for event list pages |
|
| 2859 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2860 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2861 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2862 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2863 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2864 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2865 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2866 | - } |
|
| 2759 | + /** |
|
| 2760 | + * @var boolean $use_google_maps |
|
| 2761 | + */ |
|
| 2762 | + public $use_google_maps; |
|
| 2763 | + |
|
| 2764 | + /** |
|
| 2765 | + * @var string $api_key |
|
| 2766 | + */ |
|
| 2767 | + public $google_map_api_key; |
|
| 2768 | + |
|
| 2769 | + /** |
|
| 2770 | + * @var int $event_details_map_width |
|
| 2771 | + */ |
|
| 2772 | + public $event_details_map_width; |
|
| 2773 | + |
|
| 2774 | + /** |
|
| 2775 | + * @var int $event_details_map_height |
|
| 2776 | + */ |
|
| 2777 | + public $event_details_map_height; |
|
| 2778 | + |
|
| 2779 | + /** |
|
| 2780 | + * @var int $event_details_map_zoom |
|
| 2781 | + */ |
|
| 2782 | + public $event_details_map_zoom; |
|
| 2783 | + |
|
| 2784 | + /** |
|
| 2785 | + * @var boolean $event_details_display_nav |
|
| 2786 | + */ |
|
| 2787 | + public $event_details_display_nav; |
|
| 2788 | + |
|
| 2789 | + /** |
|
| 2790 | + * @var boolean $event_details_nav_size |
|
| 2791 | + */ |
|
| 2792 | + public $event_details_nav_size; |
|
| 2793 | + |
|
| 2794 | + /** |
|
| 2795 | + * @var string $event_details_control_type |
|
| 2796 | + */ |
|
| 2797 | + public $event_details_control_type; |
|
| 2798 | + |
|
| 2799 | + /** |
|
| 2800 | + * @var string $event_details_map_align |
|
| 2801 | + */ |
|
| 2802 | + public $event_details_map_align; |
|
| 2803 | + |
|
| 2804 | + /** |
|
| 2805 | + * @var int $event_list_map_width |
|
| 2806 | + */ |
|
| 2807 | + public $event_list_map_width; |
|
| 2808 | + |
|
| 2809 | + /** |
|
| 2810 | + * @var int $event_list_map_height |
|
| 2811 | + */ |
|
| 2812 | + public $event_list_map_height; |
|
| 2813 | + |
|
| 2814 | + /** |
|
| 2815 | + * @var int $event_list_map_zoom |
|
| 2816 | + */ |
|
| 2817 | + public $event_list_map_zoom; |
|
| 2818 | + |
|
| 2819 | + /** |
|
| 2820 | + * @var boolean $event_list_display_nav |
|
| 2821 | + */ |
|
| 2822 | + public $event_list_display_nav; |
|
| 2823 | + |
|
| 2824 | + /** |
|
| 2825 | + * @var boolean $event_list_nav_size |
|
| 2826 | + */ |
|
| 2827 | + public $event_list_nav_size; |
|
| 2828 | + |
|
| 2829 | + /** |
|
| 2830 | + * @var string $event_list_control_type |
|
| 2831 | + */ |
|
| 2832 | + public $event_list_control_type; |
|
| 2833 | + |
|
| 2834 | + /** |
|
| 2835 | + * @var string $event_list_map_align |
|
| 2836 | + */ |
|
| 2837 | + public $event_list_map_align; |
|
| 2838 | + |
|
| 2839 | + |
|
| 2840 | + /** |
|
| 2841 | + * class constructor |
|
| 2842 | + * |
|
| 2843 | + * @access public |
|
| 2844 | + */ |
|
| 2845 | + public function __construct() |
|
| 2846 | + { |
|
| 2847 | + // set default map settings |
|
| 2848 | + $this->use_google_maps = true; |
|
| 2849 | + $this->google_map_api_key = ''; |
|
| 2850 | + // for event details pages (reg page) |
|
| 2851 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2852 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2853 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2854 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2855 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2856 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2857 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2858 | + // for event list pages |
|
| 2859 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2860 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2861 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2862 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2863 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2864 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2865 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2866 | + } |
|
| 2867 | 2867 | } |
| 2868 | 2868 | |
| 2869 | 2869 | /** |
@@ -2872,46 +2872,46 @@ discard block |
||
| 2872 | 2872 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2873 | 2873 | { |
| 2874 | 2874 | |
| 2875 | - public $display_status_banner; |
|
| 2875 | + public $display_status_banner; |
|
| 2876 | 2876 | |
| 2877 | - public $display_description; |
|
| 2877 | + public $display_description; |
|
| 2878 | 2878 | |
| 2879 | - public $display_ticket_selector; |
|
| 2879 | + public $display_ticket_selector; |
|
| 2880 | 2880 | |
| 2881 | - public $display_datetimes; |
|
| 2881 | + public $display_datetimes; |
|
| 2882 | 2882 | |
| 2883 | - public $display_venue; |
|
| 2883 | + public $display_venue; |
|
| 2884 | 2884 | |
| 2885 | - public $display_expired_events; |
|
| 2885 | + public $display_expired_events; |
|
| 2886 | 2886 | |
| 2887 | - public $use_sortable_display_order; |
|
| 2887 | + public $use_sortable_display_order; |
|
| 2888 | 2888 | |
| 2889 | - public $display_order_tickets; |
|
| 2889 | + public $display_order_tickets; |
|
| 2890 | 2890 | |
| 2891 | - public $display_order_datetimes; |
|
| 2891 | + public $display_order_datetimes; |
|
| 2892 | 2892 | |
| 2893 | - public $display_order_event; |
|
| 2893 | + public $display_order_event; |
|
| 2894 | 2894 | |
| 2895 | - public $display_order_venue; |
|
| 2895 | + public $display_order_venue; |
|
| 2896 | 2896 | |
| 2897 | 2897 | |
| 2898 | - /** |
|
| 2899 | - * class constructor |
|
| 2900 | - */ |
|
| 2901 | - public function __construct() |
|
| 2902 | - { |
|
| 2903 | - $this->display_status_banner = 0; |
|
| 2904 | - $this->display_description = 1; |
|
| 2905 | - $this->display_ticket_selector = 0; |
|
| 2906 | - $this->display_datetimes = 1; |
|
| 2907 | - $this->display_venue = 0; |
|
| 2908 | - $this->display_expired_events = 0; |
|
| 2909 | - $this->use_sortable_display_order = false; |
|
| 2910 | - $this->display_order_tickets = 100; |
|
| 2911 | - $this->display_order_datetimes = 110; |
|
| 2912 | - $this->display_order_event = 120; |
|
| 2913 | - $this->display_order_venue = 130; |
|
| 2914 | - } |
|
| 2898 | + /** |
|
| 2899 | + * class constructor |
|
| 2900 | + */ |
|
| 2901 | + public function __construct() |
|
| 2902 | + { |
|
| 2903 | + $this->display_status_banner = 0; |
|
| 2904 | + $this->display_description = 1; |
|
| 2905 | + $this->display_ticket_selector = 0; |
|
| 2906 | + $this->display_datetimes = 1; |
|
| 2907 | + $this->display_venue = 0; |
|
| 2908 | + $this->display_expired_events = 0; |
|
| 2909 | + $this->use_sortable_display_order = false; |
|
| 2910 | + $this->display_order_tickets = 100; |
|
| 2911 | + $this->display_order_datetimes = 110; |
|
| 2912 | + $this->display_order_event = 120; |
|
| 2913 | + $this->display_order_venue = 130; |
|
| 2914 | + } |
|
| 2915 | 2915 | } |
| 2916 | 2916 | |
| 2917 | 2917 | /** |
@@ -2920,34 +2920,34 @@ discard block |
||
| 2920 | 2920 | class EE_Event_Single_Config extends EE_Config_Base |
| 2921 | 2921 | { |
| 2922 | 2922 | |
| 2923 | - public $display_status_banner_single; |
|
| 2923 | + public $display_status_banner_single; |
|
| 2924 | 2924 | |
| 2925 | - public $display_venue; |
|
| 2925 | + public $display_venue; |
|
| 2926 | 2926 | |
| 2927 | - public $use_sortable_display_order; |
|
| 2927 | + public $use_sortable_display_order; |
|
| 2928 | 2928 | |
| 2929 | - public $display_order_tickets; |
|
| 2929 | + public $display_order_tickets; |
|
| 2930 | 2930 | |
| 2931 | - public $display_order_datetimes; |
|
| 2931 | + public $display_order_datetimes; |
|
| 2932 | 2932 | |
| 2933 | - public $display_order_event; |
|
| 2933 | + public $display_order_event; |
|
| 2934 | 2934 | |
| 2935 | - public $display_order_venue; |
|
| 2935 | + public $display_order_venue; |
|
| 2936 | 2936 | |
| 2937 | 2937 | |
| 2938 | - /** |
|
| 2939 | - * class constructor |
|
| 2940 | - */ |
|
| 2941 | - public function __construct() |
|
| 2942 | - { |
|
| 2943 | - $this->display_status_banner_single = 0; |
|
| 2944 | - $this->display_venue = 1; |
|
| 2945 | - $this->use_sortable_display_order = false; |
|
| 2946 | - $this->display_order_tickets = 100; |
|
| 2947 | - $this->display_order_datetimes = 110; |
|
| 2948 | - $this->display_order_event = 120; |
|
| 2949 | - $this->display_order_venue = 130; |
|
| 2950 | - } |
|
| 2938 | + /** |
|
| 2939 | + * class constructor |
|
| 2940 | + */ |
|
| 2941 | + public function __construct() |
|
| 2942 | + { |
|
| 2943 | + $this->display_status_banner_single = 0; |
|
| 2944 | + $this->display_venue = 1; |
|
| 2945 | + $this->use_sortable_display_order = false; |
|
| 2946 | + $this->display_order_tickets = 100; |
|
| 2947 | + $this->display_order_datetimes = 110; |
|
| 2948 | + $this->display_order_event = 120; |
|
| 2949 | + $this->display_order_venue = 130; |
|
| 2950 | + } |
|
| 2951 | 2951 | } |
| 2952 | 2952 | |
| 2953 | 2953 | /** |
@@ -2956,172 +2956,172 @@ discard block |
||
| 2956 | 2956 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 2957 | 2957 | { |
| 2958 | 2958 | |
| 2959 | - /** |
|
| 2960 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2961 | - */ |
|
| 2962 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2963 | - |
|
| 2964 | - /** |
|
| 2965 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2966 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2967 | - */ |
|
| 2968 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2969 | - |
|
| 2970 | - /** |
|
| 2971 | - * @var boolean $show_ticket_sale_columns |
|
| 2972 | - */ |
|
| 2973 | - public $show_ticket_sale_columns; |
|
| 2974 | - |
|
| 2975 | - /** |
|
| 2976 | - * @var boolean $show_ticket_details |
|
| 2977 | - */ |
|
| 2978 | - public $show_ticket_details; |
|
| 2979 | - |
|
| 2980 | - /** |
|
| 2981 | - * @var boolean $show_expired_tickets |
|
| 2982 | - */ |
|
| 2983 | - public $show_expired_tickets; |
|
| 2984 | - |
|
| 2985 | - /** |
|
| 2986 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 2987 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 2988 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2989 | - * |
|
| 2990 | - * @var string $show_datetime_selector |
|
| 2991 | - */ |
|
| 2992 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2993 | - |
|
| 2994 | - /** |
|
| 2995 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2996 | - * |
|
| 2997 | - * @var int $datetime_selector_threshold |
|
| 2998 | - */ |
|
| 2999 | - private $datetime_selector_threshold = 3; |
|
| 3000 | - |
|
| 3001 | - /** |
|
| 3002 | - * determines the maximum number of "checked" dates in the date and time filter |
|
| 3003 | - * |
|
| 3004 | - * @var int $datetime_selector_checked |
|
| 3005 | - */ |
|
| 3006 | - private $datetime_selector_max_checked = 10; |
|
| 3007 | - |
|
| 3008 | - |
|
| 3009 | - /** |
|
| 3010 | - * class constructor |
|
| 3011 | - */ |
|
| 3012 | - public function __construct() |
|
| 3013 | - { |
|
| 3014 | - $this->show_ticket_sale_columns = true; |
|
| 3015 | - $this->show_ticket_details = true; |
|
| 3016 | - $this->show_expired_tickets = true; |
|
| 3017 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3018 | - $this->datetime_selector_threshold = 3; |
|
| 3019 | - $this->datetime_selector_max_checked = 10; |
|
| 3020 | - } |
|
| 3021 | - |
|
| 3022 | - |
|
| 3023 | - /** |
|
| 3024 | - * returns true if a datetime selector should be displayed |
|
| 3025 | - * |
|
| 3026 | - * @param array $datetimes |
|
| 3027 | - * @return bool |
|
| 3028 | - */ |
|
| 3029 | - public function showDatetimeSelector(array $datetimes) |
|
| 3030 | - { |
|
| 3031 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3032 | - return ! ( |
|
| 3033 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3034 | - || ( |
|
| 3035 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3036 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3037 | - ) |
|
| 3038 | - ); |
|
| 3039 | - } |
|
| 3040 | - |
|
| 3041 | - |
|
| 3042 | - /** |
|
| 3043 | - * @return string |
|
| 3044 | - */ |
|
| 3045 | - public function getShowDatetimeSelector() |
|
| 3046 | - { |
|
| 3047 | - return $this->show_datetime_selector; |
|
| 3048 | - } |
|
| 3049 | - |
|
| 3050 | - |
|
| 3051 | - /** |
|
| 3052 | - * @param bool $keys_only |
|
| 3053 | - * @return array |
|
| 3054 | - */ |
|
| 3055 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3056 | - { |
|
| 3057 | - return $keys_only |
|
| 3058 | - ? array( |
|
| 3059 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3060 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3061 | - ) |
|
| 3062 | - : array( |
|
| 3063 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3064 | - 'Do not show date & time filter', |
|
| 3065 | - 'event_espresso' |
|
| 3066 | - ), |
|
| 3067 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3068 | - 'Maybe show date & time filter', |
|
| 3069 | - 'event_espresso' |
|
| 3070 | - ), |
|
| 3071 | - ); |
|
| 3072 | - } |
|
| 3073 | - |
|
| 3074 | - |
|
| 3075 | - /** |
|
| 3076 | - * @param string $show_datetime_selector |
|
| 3077 | - */ |
|
| 3078 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3079 | - { |
|
| 3080 | - $this->show_datetime_selector = in_array( |
|
| 3081 | - $show_datetime_selector, |
|
| 3082 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3083 | - true |
|
| 3084 | - ) |
|
| 3085 | - ? $show_datetime_selector |
|
| 3086 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3087 | - } |
|
| 3088 | - |
|
| 3089 | - |
|
| 3090 | - /** |
|
| 3091 | - * @return int |
|
| 3092 | - */ |
|
| 3093 | - public function getDatetimeSelectorThreshold() |
|
| 3094 | - { |
|
| 3095 | - return $this->datetime_selector_threshold; |
|
| 3096 | - } |
|
| 3097 | - |
|
| 3098 | - |
|
| 3099 | - /** |
|
| 3100 | - * @param int $datetime_selector_threshold |
|
| 3101 | - */ |
|
| 3102 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3103 | - { |
|
| 3104 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3105 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3106 | - } |
|
| 3107 | - |
|
| 3108 | - |
|
| 3109 | - /** |
|
| 3110 | - * @return int |
|
| 3111 | - */ |
|
| 3112 | - public function getDatetimeSelectorMaxChecked() |
|
| 3113 | - { |
|
| 3114 | - return $this->datetime_selector_max_checked; |
|
| 3115 | - } |
|
| 3116 | - |
|
| 3117 | - |
|
| 3118 | - /** |
|
| 3119 | - * @param int $datetime_selector_max_checked |
|
| 3120 | - */ |
|
| 3121 | - public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3122 | - { |
|
| 3123 | - $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3124 | - } |
|
| 2959 | + /** |
|
| 2960 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2961 | + */ |
|
| 2962 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2963 | + |
|
| 2964 | + /** |
|
| 2965 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2966 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2967 | + */ |
|
| 2968 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2969 | + |
|
| 2970 | + /** |
|
| 2971 | + * @var boolean $show_ticket_sale_columns |
|
| 2972 | + */ |
|
| 2973 | + public $show_ticket_sale_columns; |
|
| 2974 | + |
|
| 2975 | + /** |
|
| 2976 | + * @var boolean $show_ticket_details |
|
| 2977 | + */ |
|
| 2978 | + public $show_ticket_details; |
|
| 2979 | + |
|
| 2980 | + /** |
|
| 2981 | + * @var boolean $show_expired_tickets |
|
| 2982 | + */ |
|
| 2983 | + public $show_expired_tickets; |
|
| 2984 | + |
|
| 2985 | + /** |
|
| 2986 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 2987 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 2988 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2989 | + * |
|
| 2990 | + * @var string $show_datetime_selector |
|
| 2991 | + */ |
|
| 2992 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2993 | + |
|
| 2994 | + /** |
|
| 2995 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2996 | + * |
|
| 2997 | + * @var int $datetime_selector_threshold |
|
| 2998 | + */ |
|
| 2999 | + private $datetime_selector_threshold = 3; |
|
| 3000 | + |
|
| 3001 | + /** |
|
| 3002 | + * determines the maximum number of "checked" dates in the date and time filter |
|
| 3003 | + * |
|
| 3004 | + * @var int $datetime_selector_checked |
|
| 3005 | + */ |
|
| 3006 | + private $datetime_selector_max_checked = 10; |
|
| 3007 | + |
|
| 3008 | + |
|
| 3009 | + /** |
|
| 3010 | + * class constructor |
|
| 3011 | + */ |
|
| 3012 | + public function __construct() |
|
| 3013 | + { |
|
| 3014 | + $this->show_ticket_sale_columns = true; |
|
| 3015 | + $this->show_ticket_details = true; |
|
| 3016 | + $this->show_expired_tickets = true; |
|
| 3017 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3018 | + $this->datetime_selector_threshold = 3; |
|
| 3019 | + $this->datetime_selector_max_checked = 10; |
|
| 3020 | + } |
|
| 3021 | + |
|
| 3022 | + |
|
| 3023 | + /** |
|
| 3024 | + * returns true if a datetime selector should be displayed |
|
| 3025 | + * |
|
| 3026 | + * @param array $datetimes |
|
| 3027 | + * @return bool |
|
| 3028 | + */ |
|
| 3029 | + public function showDatetimeSelector(array $datetimes) |
|
| 3030 | + { |
|
| 3031 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3032 | + return ! ( |
|
| 3033 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3034 | + || ( |
|
| 3035 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3036 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3037 | + ) |
|
| 3038 | + ); |
|
| 3039 | + } |
|
| 3040 | + |
|
| 3041 | + |
|
| 3042 | + /** |
|
| 3043 | + * @return string |
|
| 3044 | + */ |
|
| 3045 | + public function getShowDatetimeSelector() |
|
| 3046 | + { |
|
| 3047 | + return $this->show_datetime_selector; |
|
| 3048 | + } |
|
| 3049 | + |
|
| 3050 | + |
|
| 3051 | + /** |
|
| 3052 | + * @param bool $keys_only |
|
| 3053 | + * @return array |
|
| 3054 | + */ |
|
| 3055 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3056 | + { |
|
| 3057 | + return $keys_only |
|
| 3058 | + ? array( |
|
| 3059 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3060 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3061 | + ) |
|
| 3062 | + : array( |
|
| 3063 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3064 | + 'Do not show date & time filter', |
|
| 3065 | + 'event_espresso' |
|
| 3066 | + ), |
|
| 3067 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3068 | + 'Maybe show date & time filter', |
|
| 3069 | + 'event_espresso' |
|
| 3070 | + ), |
|
| 3071 | + ); |
|
| 3072 | + } |
|
| 3073 | + |
|
| 3074 | + |
|
| 3075 | + /** |
|
| 3076 | + * @param string $show_datetime_selector |
|
| 3077 | + */ |
|
| 3078 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3079 | + { |
|
| 3080 | + $this->show_datetime_selector = in_array( |
|
| 3081 | + $show_datetime_selector, |
|
| 3082 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3083 | + true |
|
| 3084 | + ) |
|
| 3085 | + ? $show_datetime_selector |
|
| 3086 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3087 | + } |
|
| 3088 | + |
|
| 3089 | + |
|
| 3090 | + /** |
|
| 3091 | + * @return int |
|
| 3092 | + */ |
|
| 3093 | + public function getDatetimeSelectorThreshold() |
|
| 3094 | + { |
|
| 3095 | + return $this->datetime_selector_threshold; |
|
| 3096 | + } |
|
| 3097 | + |
|
| 3098 | + |
|
| 3099 | + /** |
|
| 3100 | + * @param int $datetime_selector_threshold |
|
| 3101 | + */ |
|
| 3102 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3103 | + { |
|
| 3104 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3105 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3106 | + } |
|
| 3107 | + |
|
| 3108 | + |
|
| 3109 | + /** |
|
| 3110 | + * @return int |
|
| 3111 | + */ |
|
| 3112 | + public function getDatetimeSelectorMaxChecked() |
|
| 3113 | + { |
|
| 3114 | + return $this->datetime_selector_max_checked; |
|
| 3115 | + } |
|
| 3116 | + |
|
| 3117 | + |
|
| 3118 | + /** |
|
| 3119 | + * @param int $datetime_selector_max_checked |
|
| 3120 | + */ |
|
| 3121 | + public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3122 | + { |
|
| 3123 | + $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3124 | + } |
|
| 3125 | 3125 | } |
| 3126 | 3126 | |
| 3127 | 3127 | /** |
@@ -3134,86 +3134,86 @@ discard block |
||
| 3134 | 3134 | class EE_Environment_Config extends EE_Config_Base |
| 3135 | 3135 | { |
| 3136 | 3136 | |
| 3137 | - /** |
|
| 3138 | - * Hold any php environment variables that we want to track. |
|
| 3139 | - * |
|
| 3140 | - * @var stdClass; |
|
| 3141 | - */ |
|
| 3142 | - public $php; |
|
| 3143 | - |
|
| 3144 | - |
|
| 3145 | - /** |
|
| 3146 | - * constructor |
|
| 3147 | - */ |
|
| 3148 | - public function __construct() |
|
| 3149 | - { |
|
| 3150 | - $this->php = new stdClass(); |
|
| 3151 | - $this->_set_php_values(); |
|
| 3152 | - } |
|
| 3153 | - |
|
| 3154 | - |
|
| 3155 | - /** |
|
| 3156 | - * This sets the php environment variables. |
|
| 3157 | - * |
|
| 3158 | - * @since 4.4.0 |
|
| 3159 | - * @return void |
|
| 3160 | - */ |
|
| 3161 | - protected function _set_php_values() |
|
| 3162 | - { |
|
| 3163 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3164 | - $this->php->version = phpversion(); |
|
| 3165 | - } |
|
| 3166 | - |
|
| 3167 | - |
|
| 3168 | - /** |
|
| 3169 | - * helper method for determining whether input_count is |
|
| 3170 | - * reaching the potential maximum the server can handle |
|
| 3171 | - * according to max_input_vars |
|
| 3172 | - * |
|
| 3173 | - * @param int $input_count the count of input vars. |
|
| 3174 | - * @return array { |
|
| 3175 | - * An array that represents whether available space and if no available space the error |
|
| 3176 | - * message. |
|
| 3177 | - * @type bool $has_space whether more inputs can be added. |
|
| 3178 | - * @type string $msg Any message to be displayed. |
|
| 3179 | - * } |
|
| 3180 | - */ |
|
| 3181 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3182 | - { |
|
| 3183 | - if (! empty($this->php->max_input_vars) |
|
| 3184 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3185 | - ) { |
|
| 3186 | - // check the server setting because the config value could be stale |
|
| 3187 | - $max_input_vars = ini_get('max_input_vars'); |
|
| 3188 | - if ($input_count >= $max_input_vars) { |
|
| 3189 | - return sprintf( |
|
| 3190 | - esc_html__( |
|
| 3191 | - 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3192 | - 'event_espresso' |
|
| 3193 | - ), |
|
| 3194 | - '<br>', |
|
| 3195 | - $input_count, |
|
| 3196 | - $max_input_vars |
|
| 3197 | - ); |
|
| 3198 | - } else { |
|
| 3199 | - return ''; |
|
| 3200 | - } |
|
| 3201 | - } else { |
|
| 3202 | - return ''; |
|
| 3203 | - } |
|
| 3204 | - } |
|
| 3205 | - |
|
| 3206 | - |
|
| 3207 | - /** |
|
| 3208 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3209 | - * |
|
| 3210 | - * @since 4.4.1 |
|
| 3211 | - * @return void |
|
| 3212 | - */ |
|
| 3213 | - public function recheck_values() |
|
| 3214 | - { |
|
| 3215 | - $this->_set_php_values(); |
|
| 3216 | - } |
|
| 3137 | + /** |
|
| 3138 | + * Hold any php environment variables that we want to track. |
|
| 3139 | + * |
|
| 3140 | + * @var stdClass; |
|
| 3141 | + */ |
|
| 3142 | + public $php; |
|
| 3143 | + |
|
| 3144 | + |
|
| 3145 | + /** |
|
| 3146 | + * constructor |
|
| 3147 | + */ |
|
| 3148 | + public function __construct() |
|
| 3149 | + { |
|
| 3150 | + $this->php = new stdClass(); |
|
| 3151 | + $this->_set_php_values(); |
|
| 3152 | + } |
|
| 3153 | + |
|
| 3154 | + |
|
| 3155 | + /** |
|
| 3156 | + * This sets the php environment variables. |
|
| 3157 | + * |
|
| 3158 | + * @since 4.4.0 |
|
| 3159 | + * @return void |
|
| 3160 | + */ |
|
| 3161 | + protected function _set_php_values() |
|
| 3162 | + { |
|
| 3163 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3164 | + $this->php->version = phpversion(); |
|
| 3165 | + } |
|
| 3166 | + |
|
| 3167 | + |
|
| 3168 | + /** |
|
| 3169 | + * helper method for determining whether input_count is |
|
| 3170 | + * reaching the potential maximum the server can handle |
|
| 3171 | + * according to max_input_vars |
|
| 3172 | + * |
|
| 3173 | + * @param int $input_count the count of input vars. |
|
| 3174 | + * @return array { |
|
| 3175 | + * An array that represents whether available space and if no available space the error |
|
| 3176 | + * message. |
|
| 3177 | + * @type bool $has_space whether more inputs can be added. |
|
| 3178 | + * @type string $msg Any message to be displayed. |
|
| 3179 | + * } |
|
| 3180 | + */ |
|
| 3181 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3182 | + { |
|
| 3183 | + if (! empty($this->php->max_input_vars) |
|
| 3184 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3185 | + ) { |
|
| 3186 | + // check the server setting because the config value could be stale |
|
| 3187 | + $max_input_vars = ini_get('max_input_vars'); |
|
| 3188 | + if ($input_count >= $max_input_vars) { |
|
| 3189 | + return sprintf( |
|
| 3190 | + esc_html__( |
|
| 3191 | + 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3192 | + 'event_espresso' |
|
| 3193 | + ), |
|
| 3194 | + '<br>', |
|
| 3195 | + $input_count, |
|
| 3196 | + $max_input_vars |
|
| 3197 | + ); |
|
| 3198 | + } else { |
|
| 3199 | + return ''; |
|
| 3200 | + } |
|
| 3201 | + } else { |
|
| 3202 | + return ''; |
|
| 3203 | + } |
|
| 3204 | + } |
|
| 3205 | + |
|
| 3206 | + |
|
| 3207 | + /** |
|
| 3208 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3209 | + * |
|
| 3210 | + * @since 4.4.1 |
|
| 3211 | + * @return void |
|
| 3212 | + */ |
|
| 3213 | + public function recheck_values() |
|
| 3214 | + { |
|
| 3215 | + $this->_set_php_values(); |
|
| 3216 | + } |
|
| 3217 | 3217 | } |
| 3218 | 3218 | |
| 3219 | 3219 | /** |
@@ -3226,21 +3226,21 @@ discard block |
||
| 3226 | 3226 | class EE_Tax_Config extends EE_Config_Base |
| 3227 | 3227 | { |
| 3228 | 3228 | |
| 3229 | - /* |
|
| 3229 | + /* |
|
| 3230 | 3230 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3231 | 3231 | * |
| 3232 | 3232 | * @var boolean $prices_displayed_including_taxes |
| 3233 | 3233 | */ |
| 3234 | - public $prices_displayed_including_taxes; |
|
| 3234 | + public $prices_displayed_including_taxes; |
|
| 3235 | 3235 | |
| 3236 | 3236 | |
| 3237 | - /** |
|
| 3238 | - * class constructor |
|
| 3239 | - */ |
|
| 3240 | - public function __construct() |
|
| 3241 | - { |
|
| 3242 | - $this->prices_displayed_including_taxes = true; |
|
| 3243 | - } |
|
| 3237 | + /** |
|
| 3238 | + * class constructor |
|
| 3239 | + */ |
|
| 3240 | + public function __construct() |
|
| 3241 | + { |
|
| 3242 | + $this->prices_displayed_including_taxes = true; |
|
| 3243 | + } |
|
| 3244 | 3244 | } |
| 3245 | 3245 | |
| 3246 | 3246 | /** |
@@ -3254,19 +3254,19 @@ discard block |
||
| 3254 | 3254 | class EE_Messages_Config extends EE_Config_Base |
| 3255 | 3255 | { |
| 3256 | 3256 | |
| 3257 | - /** |
|
| 3258 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3259 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3260 | - * |
|
| 3261 | - * @var integer |
|
| 3262 | - */ |
|
| 3263 | - public $delete_threshold; |
|
| 3257 | + /** |
|
| 3258 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3259 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3260 | + * |
|
| 3261 | + * @var integer |
|
| 3262 | + */ |
|
| 3263 | + public $delete_threshold; |
|
| 3264 | 3264 | |
| 3265 | 3265 | |
| 3266 | - public function __construct() |
|
| 3267 | - { |
|
| 3268 | - $this->delete_threshold = 0; |
|
| 3269 | - } |
|
| 3266 | + public function __construct() |
|
| 3267 | + { |
|
| 3268 | + $this->delete_threshold = 0; |
|
| 3269 | + } |
|
| 3270 | 3270 | } |
| 3271 | 3271 | |
| 3272 | 3272 | /** |
@@ -3277,31 +3277,31 @@ discard block |
||
| 3277 | 3277 | class EE_Gateway_Config extends EE_Config_Base |
| 3278 | 3278 | { |
| 3279 | 3279 | |
| 3280 | - /** |
|
| 3281 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3282 | - * with any config info the gateway wants to store |
|
| 3283 | - * |
|
| 3284 | - * @var array |
|
| 3285 | - */ |
|
| 3286 | - public $payment_settings; |
|
| 3287 | - |
|
| 3288 | - /** |
|
| 3289 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3290 | - * the gateway is stored in the uploads directory |
|
| 3291 | - * |
|
| 3292 | - * @var array |
|
| 3293 | - */ |
|
| 3294 | - public $active_gateways; |
|
| 3295 | - |
|
| 3296 | - |
|
| 3297 | - /** |
|
| 3298 | - * class constructor |
|
| 3299 | - * |
|
| 3300 | - * @deprecated |
|
| 3301 | - */ |
|
| 3302 | - public function __construct() |
|
| 3303 | - { |
|
| 3304 | - $this->payment_settings = array(); |
|
| 3305 | - $this->active_gateways = array('Invoice' => false); |
|
| 3306 | - } |
|
| 3280 | + /** |
|
| 3281 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3282 | + * with any config info the gateway wants to store |
|
| 3283 | + * |
|
| 3284 | + * @var array |
|
| 3285 | + */ |
|
| 3286 | + public $payment_settings; |
|
| 3287 | + |
|
| 3288 | + /** |
|
| 3289 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3290 | + * the gateway is stored in the uploads directory |
|
| 3291 | + * |
|
| 3292 | + * @var array |
|
| 3293 | + */ |
|
| 3294 | + public $active_gateways; |
|
| 3295 | + |
|
| 3296 | + |
|
| 3297 | + /** |
|
| 3298 | + * class constructor |
|
| 3299 | + * |
|
| 3300 | + * @deprecated |
|
| 3301 | + */ |
|
| 3302 | + public function __construct() |
|
| 3303 | + { |
|
| 3304 | + $this->payment_settings = array(); |
|
| 3305 | + $this->active_gateways = array('Invoice' => false); |
|
| 3306 | + } |
|
| 3307 | 3307 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | public static function instance() |
| 146 | 146 | { |
| 147 | 147 | // check if class object is instantiated, and instantiated properly |
| 148 | - if (! self::$_instance instanceof EE_Config) { |
|
| 148 | + if ( ! self::$_instance instanceof EE_Config) { |
|
| 149 | 149 | self::$_instance = new self(); |
| 150 | 150 | } |
| 151 | 151 | return self::$_instance; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | $this |
| 284 | 284 | ); |
| 285 | 285 | if (is_object($settings) && property_exists($this, $config)) { |
| 286 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 286 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings); |
|
| 287 | 287 | // call configs populate method to ensure any defaults are set for empty values. |
| 288 | 288 | if (method_exists($settings, 'populate')) { |
| 289 | 289 | $this->{$config}->populate(); |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | break; |
| 557 | 557 | // TEST #2 : check that settings section exists |
| 558 | 558 | case 2: |
| 559 | - if (! isset($this->{$section})) { |
|
| 559 | + if ( ! isset($this->{$section})) { |
|
| 560 | 560 | if ($display_errors) { |
| 561 | 561 | throw new EE_Error( |
| 562 | 562 | sprintf( |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | break; |
| 571 | 571 | // TEST #3 : check that section is the proper format |
| 572 | 572 | case 3: |
| 573 | - if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 573 | + if ( ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | 574 | ) { |
| 575 | 575 | if ($display_errors) { |
| 576 | 576 | throw new EE_Error( |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | break; |
| 617 | 617 | // TEST #6 : verify config class is accessible |
| 618 | 618 | case 6: |
| 619 | - if (! class_exists($config_class)) { |
|
| 619 | + if ( ! class_exists($config_class)) { |
|
| 620 | 620 | if ($display_errors) { |
| 621 | 621 | throw new EE_Error( |
| 622 | 622 | sprintf( |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | break; |
| 634 | 634 | // TEST #7 : check that config has even been set |
| 635 | 635 | case 7: |
| 636 | - if (! isset($this->{$section}->{$name})) { |
|
| 636 | + if ( ! isset($this->{$section}->{$name})) { |
|
| 637 | 637 | if ($display_errors) { |
| 638 | 638 | throw new EE_Error( |
| 639 | 639 | sprintf( |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | break; |
| 652 | 652 | // TEST #8 : check that config is the requested type |
| 653 | 653 | case 8: |
| 654 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 654 | + if ( ! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | 655 | if ($display_errors) { |
| 656 | 656 | throw new EE_Error( |
| 657 | 657 | sprintf( |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | break; |
| 671 | 671 | // TEST #9 : verify config object |
| 672 | 672 | case 9: |
| 673 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 673 | + if ( ! $config_obj instanceof EE_Config_Base) { |
|
| 674 | 674 | if ($display_errors) { |
| 675 | 675 | throw new EE_Error( |
| 676 | 676 | sprintf( |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | private function _generate_config_option_name($section = '', $name = '') |
| 704 | 704 | { |
| 705 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 705 | + return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | { |
| 720 | 720 | return ! empty($config_class) |
| 721 | 721 | ? $config_class |
| 722 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 722 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config'; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | |
@@ -738,17 +738,17 @@ discard block |
||
| 738 | 738 | // ensure config class is set to something |
| 739 | 739 | $config_class = $this->_set_config_class($config_class, $name); |
| 740 | 740 | // run tests 1-4, 6, and 7 to verify all config params are set and valid |
| 741 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 741 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | 742 | return null; |
| 743 | 743 | } |
| 744 | 744 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 745 | 745 | // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
| 746 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 746 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 747 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 748 | 748 | $this->update_addon_option_names(); |
| 749 | 749 | } |
| 750 | 750 | // verify the incoming config object but suppress errors |
| 751 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 751 | + if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | 752 | $config_obj = new $config_class(); |
| 753 | 753 | } |
| 754 | 754 | if (get_option($config_option_name)) { |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | // get class name of the incoming object |
| 796 | 796 | $config_class = get_class($config_obj); |
| 797 | 797 | // run tests 1-5 and 9 to verify config |
| 798 | - if (! $this->_verify_config_params( |
|
| 798 | + if ( ! $this->_verify_config_params( |
|
| 799 | 799 | $section, |
| 800 | 800 | $name, |
| 801 | 801 | $config_class, |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | } |
| 808 | 808 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 809 | 809 | // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
| 810 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 810 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 811 | 811 | // save new config to db |
| 812 | 812 | if ($this->set_config($section, $name, $config_class, $config_obj)) { |
| 813 | 813 | return true; |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | 'event_espresso' |
| 834 | 834 | ), |
| 835 | 835 | $config_class, |
| 836 | - 'EE_Config->' . $section . '->' . $name |
|
| 836 | + 'EE_Config->'.$section.'->'.$name |
|
| 837 | 837 | ), |
| 838 | 838 | __FILE__, |
| 839 | 839 | __FUNCTION__, |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | // ensure config class is set to something |
| 860 | 860 | $config_class = $this->_set_config_class($config_class, $name); |
| 861 | 861 | // run tests 1-4, 6 and 7 to verify that all params have been set |
| 862 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 862 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | 863 | return null; |
| 864 | 864 | } |
| 865 | 865 | // now test if the requested config object exists, but suppress errors |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | // retrieve the wp-option for this config class. |
| 905 | 905 | $config_option = maybe_unserialize(get_option($config_option_name, array())); |
| 906 | 906 | if (empty($config_option)) { |
| 907 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 907 | + EE_Config::log($config_option_name.'-NOT-FOUND'); |
|
| 908 | 908 | } |
| 909 | 909 | return $config_option; |
| 910 | 910 | } |
@@ -922,7 +922,7 @@ discard block |
||
| 922 | 922 | // copy incoming $_REQUEST and sanitize it so we can save it |
| 923 | 923 | $_request = $_REQUEST; |
| 924 | 924 | array_walk_recursive($_request, 'sanitize_text_field'); |
| 925 | - $config_log[ (string) microtime(true) ] = array( |
|
| 925 | + $config_log[(string) microtime(true)] = array( |
|
| 926 | 926 | 'config_name' => $config_option_name, |
| 927 | 927 | 'request' => $_request, |
| 928 | 928 | ); |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | */ |
| 938 | 938 | public static function trim_log() |
| 939 | 939 | { |
| 940 | - if (! EE_Config::logging_enabled()) { |
|
| 940 | + if ( ! EE_Config::logging_enabled()) { |
|
| 941 | 941 | return; |
| 942 | 942 | } |
| 943 | 943 | $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | public static function get_page_for_posts() |
| 962 | 962 | { |
| 963 | 963 | $page_for_posts = get_option('page_for_posts'); |
| 964 | - if (! $page_for_posts) { |
|
| 964 | + if ( ! $page_for_posts) { |
|
| 965 | 965 | return 'posts'; |
| 966 | 966 | } |
| 967 | 967 | /** @type WPDB $wpdb */ |
@@ -1011,20 +1011,20 @@ discard block |
||
| 1011 | 1011 | { |
| 1012 | 1012 | // only init widgets on admin pages when not in complete maintenance, and |
| 1013 | 1013 | // on frontend when not in any maintenance mode |
| 1014 | - if (! EE_Maintenance_Mode::instance()->level() |
|
| 1014 | + if ( ! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | 1015 | || ( |
| 1016 | 1016 | is_admin() |
| 1017 | 1017 | && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
| 1018 | 1018 | ) |
| 1019 | 1019 | ) { |
| 1020 | 1020 | // grab list of installed widgets |
| 1021 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1021 | + $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR); |
|
| 1022 | 1022 | // filter list of modules to register |
| 1023 | 1023 | $widgets_to_register = apply_filters( |
| 1024 | 1024 | 'FHEE__EE_Config__register_widgets__widgets_to_register', |
| 1025 | 1025 | $widgets_to_register |
| 1026 | 1026 | ); |
| 1027 | - if (! empty($widgets_to_register)) { |
|
| 1027 | + if ( ! empty($widgets_to_register)) { |
|
| 1028 | 1028 | // cycle thru widget folders |
| 1029 | 1029 | foreach ($widgets_to_register as $widget_path) { |
| 1030 | 1030 | // add to list of installed widget modules |
@@ -1074,31 +1074,31 @@ discard block |
||
| 1074 | 1074 | // create classname from widget directory name |
| 1075 | 1075 | $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
| 1076 | 1076 | // add class prefix |
| 1077 | - $widget_class = 'EEW_' . $widget; |
|
| 1077 | + $widget_class = 'EEW_'.$widget; |
|
| 1078 | 1078 | // does the widget exist ? |
| 1079 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1079 | + if ( ! is_readable($widget_path.'/'.$widget_class.$widget_ext)) { |
|
| 1080 | 1080 | $msg = sprintf( |
| 1081 | 1081 | __( |
| 1082 | 1082 | 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
| 1083 | 1083 | 'event_espresso' |
| 1084 | 1084 | ), |
| 1085 | 1085 | $widget_class, |
| 1086 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1086 | + $widget_path.'/'.$widget_class.$widget_ext |
|
| 1087 | 1087 | ); |
| 1088 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1088 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | 1089 | return; |
| 1090 | 1090 | } |
| 1091 | 1091 | // load the widget class file |
| 1092 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1092 | + require_once($widget_path.'/'.$widget_class.$widget_ext); |
|
| 1093 | 1093 | // verify that class exists |
| 1094 | - if (! class_exists($widget_class)) { |
|
| 1094 | + if ( ! class_exists($widget_class)) { |
|
| 1095 | 1095 | $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
| 1096 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1096 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | 1097 | return; |
| 1098 | 1098 | } |
| 1099 | 1099 | register_widget($widget_class); |
| 1100 | 1100 | // add to array of registered widgets |
| 1101 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1101 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path.'/'.$widget_class.$widget_ext; |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
@@ -1111,18 +1111,18 @@ discard block |
||
| 1111 | 1111 | private function _register_modules() |
| 1112 | 1112 | { |
| 1113 | 1113 | // grab list of installed modules |
| 1114 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1114 | + $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR); |
|
| 1115 | 1115 | // filter list of modules to register |
| 1116 | 1116 | $modules_to_register = apply_filters( |
| 1117 | 1117 | 'FHEE__EE_Config__register_modules__modules_to_register', |
| 1118 | 1118 | $modules_to_register |
| 1119 | 1119 | ); |
| 1120 | - if (! empty($modules_to_register)) { |
|
| 1120 | + if ( ! empty($modules_to_register)) { |
|
| 1121 | 1121 | // loop through folders |
| 1122 | 1122 | foreach ($modules_to_register as $module_path) { |
| 1123 | 1123 | /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
| 1124 | - if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1124 | + if ($module_path !== EE_MODULES.'zzz-copy-this-module-template' |
|
| 1125 | + && $module_path !== EE_MODULES.'gateways' |
|
| 1126 | 1126 | ) { |
| 1127 | 1127 | // add to list of installed modules |
| 1128 | 1128 | EE_Config::register_module($module_path); |
@@ -1159,25 +1159,25 @@ discard block |
||
| 1159 | 1159 | // remove last segment |
| 1160 | 1160 | array_pop($module_path); |
| 1161 | 1161 | // glue it back together |
| 1162 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1162 | + $module_path = implode('/', $module_path).'/'; |
|
| 1163 | 1163 | // take first segment from file name pieces and sanitize it |
| 1164 | 1164 | $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
| 1165 | 1165 | // ensure class prefix is added |
| 1166 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1166 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module; |
|
| 1167 | 1167 | } else { |
| 1168 | 1168 | // we need to generate the filename based off of the folder name |
| 1169 | 1169 | // grab and sanitize module name |
| 1170 | 1170 | $module = strtolower(basename($module_path)); |
| 1171 | 1171 | $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
| 1172 | 1172 | // like trailingslashit() |
| 1173 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1173 | + $module_path = rtrim($module_path, '/').'/'; |
|
| 1174 | 1174 | // create classname from module directory name |
| 1175 | 1175 | $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
| 1176 | 1176 | // add class prefix |
| 1177 | - $module_class = 'EED_' . $module; |
|
| 1177 | + $module_class = 'EED_'.$module; |
|
| 1178 | 1178 | } |
| 1179 | 1179 | // does the module exist ? |
| 1180 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1180 | + if ( ! is_readable($module_path.'/'.$module_class.$module_ext)) { |
|
| 1181 | 1181 | $msg = sprintf( |
| 1182 | 1182 | __( |
| 1183 | 1183 | 'The requested %s module file could not be found or is not readable due to file permissions.', |
@@ -1185,19 +1185,19 @@ discard block |
||
| 1185 | 1185 | ), |
| 1186 | 1186 | $module |
| 1187 | 1187 | ); |
| 1188 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1188 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | 1189 | return false; |
| 1190 | 1190 | } |
| 1191 | 1191 | // load the module class file |
| 1192 | - require_once($module_path . $module_class . $module_ext); |
|
| 1192 | + require_once($module_path.$module_class.$module_ext); |
|
| 1193 | 1193 | // verify that class exists |
| 1194 | - if (! class_exists($module_class)) { |
|
| 1194 | + if ( ! class_exists($module_class)) { |
|
| 1195 | 1195 | $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
| 1196 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1196 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | 1197 | return false; |
| 1198 | 1198 | } |
| 1199 | 1199 | // add to array of registered modules |
| 1200 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1200 | + EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext; |
|
| 1201 | 1201 | do_action( |
| 1202 | 1202 | 'AHEE__EE_Config__register_module__complete', |
| 1203 | 1203 | $module_class, |
@@ -1248,26 +1248,26 @@ discard block |
||
| 1248 | 1248 | { |
| 1249 | 1249 | do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
| 1250 | 1250 | $module = str_replace('EED_', '', $module); |
| 1251 | - $module_class = 'EED_' . $module; |
|
| 1252 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1251 | + $module_class = 'EED_'.$module; |
|
| 1252 | + if ( ! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | 1253 | $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
| 1254 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1254 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | 1255 | return false; |
| 1256 | 1256 | } |
| 1257 | 1257 | if (empty($route)) { |
| 1258 | 1258 | $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
| 1259 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1259 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | 1260 | return false; |
| 1261 | 1261 | } |
| 1262 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1262 | + if ( ! method_exists('EED_'.$module, $method_name)) { |
|
| 1263 | 1263 | $msg = sprintf( |
| 1264 | 1264 | __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
| 1265 | 1265 | $route |
| 1266 | 1266 | ); |
| 1267 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1267 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | 1268 | return false; |
| 1269 | 1269 | } |
| 1270 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1270 | + EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name); |
|
| 1271 | 1271 | return true; |
| 1272 | 1272 | } |
| 1273 | 1273 | |
@@ -1284,8 +1284,8 @@ discard block |
||
| 1284 | 1284 | { |
| 1285 | 1285 | do_action('AHEE__EE_Config__get_route__begin', $route); |
| 1286 | 1286 | $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
| 1287 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1287 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1288 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1289 | 1289 | } |
| 1290 | 1290 | return null; |
| 1291 | 1291 | } |
@@ -1317,47 +1317,47 @@ discard block |
||
| 1317 | 1317 | public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
| 1318 | 1318 | { |
| 1319 | 1319 | do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
| 1320 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1320 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1321 | 1321 | $msg = sprintf( |
| 1322 | 1322 | __('The module route %s for this forward has not been registered.', 'event_espresso'), |
| 1323 | 1323 | $route |
| 1324 | 1324 | ); |
| 1325 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1325 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | 1326 | return false; |
| 1327 | 1327 | } |
| 1328 | 1328 | if (empty($forward)) { |
| 1329 | 1329 | $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
| 1330 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1330 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | 1331 | return false; |
| 1332 | 1332 | } |
| 1333 | 1333 | if (is_array($forward)) { |
| 1334 | - if (! isset($forward[1])) { |
|
| 1334 | + if ( ! isset($forward[1])) { |
|
| 1335 | 1335 | $msg = sprintf( |
| 1336 | 1336 | __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
| 1337 | 1337 | $route |
| 1338 | 1338 | ); |
| 1339 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1339 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | 1340 | return false; |
| 1341 | 1341 | } |
| 1342 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1342 | + if ( ! method_exists($forward[0], $forward[1])) { |
|
| 1343 | 1343 | $msg = sprintf( |
| 1344 | 1344 | __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1345 | 1345 | $forward[1], |
| 1346 | 1346 | $route |
| 1347 | 1347 | ); |
| 1348 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1348 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | 1349 | return false; |
| 1350 | 1350 | } |
| 1351 | - } elseif (! function_exists($forward)) { |
|
| 1351 | + } elseif ( ! function_exists($forward)) { |
|
| 1352 | 1352 | $msg = sprintf( |
| 1353 | 1353 | __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1354 | 1354 | $forward, |
| 1355 | 1355 | $route |
| 1356 | 1356 | ); |
| 1357 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1357 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | 1358 | return false; |
| 1359 | 1359 | } |
| 1360 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1360 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1361 | 1361 | return true; |
| 1362 | 1362 | } |
| 1363 | 1363 | |
@@ -1375,10 +1375,10 @@ discard block |
||
| 1375 | 1375 | public static function get_forward($route = null, $status = 0, $key = 'ee') |
| 1376 | 1376 | { |
| 1377 | 1377 | do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
| 1378 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1378 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1379 | 1379 | return apply_filters( |
| 1380 | 1380 | 'FHEE__EE_Config__get_forward', |
| 1381 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1381 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1382 | 1382 | $route, |
| 1383 | 1383 | $status |
| 1384 | 1384 | ); |
@@ -1402,15 +1402,15 @@ discard block |
||
| 1402 | 1402 | public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
| 1403 | 1403 | { |
| 1404 | 1404 | do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
| 1405 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1405 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1406 | 1406 | $msg = sprintf( |
| 1407 | 1407 | __('The module route %s for this view has not been registered.', 'event_espresso'), |
| 1408 | 1408 | $route |
| 1409 | 1409 | ); |
| 1410 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1410 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | 1411 | return false; |
| 1412 | 1412 | } |
| 1413 | - if (! is_readable($view)) { |
|
| 1413 | + if ( ! is_readable($view)) { |
|
| 1414 | 1414 | $msg = sprintf( |
| 1415 | 1415 | __( |
| 1416 | 1416 | 'The %s view file could not be found or is not readable due to file permissions.', |
@@ -1418,10 +1418,10 @@ discard block |
||
| 1418 | 1418 | ), |
| 1419 | 1419 | $view |
| 1420 | 1420 | ); |
| 1421 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1421 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | 1422 | return false; |
| 1423 | 1423 | } |
| 1424 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1424 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1425 | 1425 | return true; |
| 1426 | 1426 | } |
| 1427 | 1427 | |
@@ -1439,10 +1439,10 @@ discard block |
||
| 1439 | 1439 | public static function get_view($route = null, $status = 0, $key = 'ee') |
| 1440 | 1440 | { |
| 1441 | 1441 | do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
| 1442 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1442 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1443 | 1443 | return apply_filters( |
| 1444 | 1444 | 'FHEE__EE_Config__get_view', |
| 1445 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1445 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1446 | 1446 | $route, |
| 1447 | 1447 | $status |
| 1448 | 1448 | ); |
@@ -1469,7 +1469,7 @@ discard block |
||
| 1469 | 1469 | public static function getLegacyShortcodesManager() |
| 1470 | 1470 | { |
| 1471 | 1471 | |
| 1472 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1472 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | 1473 | EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
| 1474 | 1474 | EE_Registry::instance() |
| 1475 | 1475 | ); |
@@ -1516,7 +1516,7 @@ discard block |
||
| 1516 | 1516 | */ |
| 1517 | 1517 | public function get_pretty($property) |
| 1518 | 1518 | { |
| 1519 | - if (! property_exists($this, $property)) { |
|
| 1519 | + if ( ! property_exists($this, $property)) { |
|
| 1520 | 1520 | throw new EE_Error( |
| 1521 | 1521 | sprintf( |
| 1522 | 1522 | __( |
@@ -1745,11 +1745,11 @@ discard block |
||
| 1745 | 1745 | */ |
| 1746 | 1746 | public function reg_page_url() |
| 1747 | 1747 | { |
| 1748 | - if (! $this->reg_page_url) { |
|
| 1748 | + if ( ! $this->reg_page_url) { |
|
| 1749 | 1749 | $this->reg_page_url = add_query_arg( |
| 1750 | 1750 | array('uts' => time()), |
| 1751 | 1751 | get_permalink($this->reg_page_id) |
| 1752 | - ) . '#checkout'; |
|
| 1752 | + ).'#checkout'; |
|
| 1753 | 1753 | } |
| 1754 | 1754 | return $this->reg_page_url; |
| 1755 | 1755 | } |
@@ -1765,7 +1765,7 @@ discard block |
||
| 1765 | 1765 | */ |
| 1766 | 1766 | public function txn_page_url($query_args = array()) |
| 1767 | 1767 | { |
| 1768 | - if (! $this->txn_page_url) { |
|
| 1768 | + if ( ! $this->txn_page_url) { |
|
| 1769 | 1769 | $this->txn_page_url = get_permalink($this->txn_page_id); |
| 1770 | 1770 | } |
| 1771 | 1771 | if ($query_args) { |
@@ -1786,7 +1786,7 @@ discard block |
||
| 1786 | 1786 | */ |
| 1787 | 1787 | public function thank_you_page_url($query_args = array()) |
| 1788 | 1788 | { |
| 1789 | - if (! $this->thank_you_page_url) { |
|
| 1789 | + if ( ! $this->thank_you_page_url) { |
|
| 1790 | 1790 | $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
| 1791 | 1791 | } |
| 1792 | 1792 | if ($query_args) { |
@@ -1805,7 +1805,7 @@ discard block |
||
| 1805 | 1805 | */ |
| 1806 | 1806 | public function cancel_page_url() |
| 1807 | 1807 | { |
| 1808 | - if (! $this->cancel_page_url) { |
|
| 1808 | + if ( ! $this->cancel_page_url) { |
|
| 1809 | 1809 | $this->cancel_page_url = get_permalink($this->cancel_page_id); |
| 1810 | 1810 | } |
| 1811 | 1811 | return $this->cancel_page_url; |
@@ -1848,13 +1848,13 @@ discard block |
||
| 1848 | 1848 | $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
| 1849 | 1849 | $option = self::OPTION_NAME_UXIP; |
| 1850 | 1850 | // set correct table for query |
| 1851 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1851 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options'; |
|
| 1852 | 1852 | // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
| 1853 | 1853 | // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
| 1854 | 1854 | // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
| 1855 | 1855 | // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
| 1856 | 1856 | // for the purpose of caching. |
| 1857 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1857 | + $pre = apply_filters('pre_option_'.$option, false, $option); |
|
| 1858 | 1858 | if (false !== $pre) { |
| 1859 | 1859 | EE_Core_Config::$ee_ueip_option = $pre; |
| 1860 | 1860 | return EE_Core_Config::$ee_ueip_option; |
@@ -1868,10 +1868,10 @@ discard block |
||
| 1868 | 1868 | if (is_object($row)) { |
| 1869 | 1869 | $value = $row->option_value; |
| 1870 | 1870 | } else { // option does not exist so use default. |
| 1871 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1871 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option); |
|
| 1872 | 1872 | return EE_Core_Config::$ee_ueip_option; |
| 1873 | 1873 | } |
| 1874 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1874 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option); |
|
| 1875 | 1875 | return EE_Core_Config::$ee_ueip_option; |
| 1876 | 1876 | } |
| 1877 | 1877 | |
@@ -2125,37 +2125,37 @@ discard block |
||
| 2125 | 2125 | // but override if requested |
| 2126 | 2126 | $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
| 2127 | 2127 | // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
| 2128 | - if (! empty($CNT_ISO) |
|
| 2128 | + if ( ! empty($CNT_ISO) |
|
| 2129 | 2129 | && EE_Maintenance_Mode::instance()->models_can_query() |
| 2130 | 2130 | && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
| 2131 | 2131 | ) { |
| 2132 | 2132 | // retrieve the country settings from the db, just in case they have been customized |
| 2133 | 2133 | $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
| 2134 | 2134 | if ($country instanceof EE_Country) { |
| 2135 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2135 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | 2139 | $this->sign_b4 = $country->currency_sign_before( |
| 2140 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2140 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | 2142 | $this->dec_mrk = $country->currency_decimal_mark( |
| 2143 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2143 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | 2144 | $this->thsnds = $country->currency_thousands_separator( |
| 2145 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2145 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | 2146 | } |
| 2147 | 2147 | } |
| 2148 | 2148 | // fallback to hardcoded defaults, in case the above failed |
| 2149 | 2149 | if (empty($this->code)) { |
| 2150 | 2150 | // set default currency settings |
| 2151 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | - $this->sign = '$'; // currency sign: $ |
|
| 2155 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2151 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | + $this->sign = '$'; // currency sign: $ |
|
| 2155 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | 2159 | } |
| 2160 | 2160 | } |
| 2161 | 2161 | } |
@@ -2414,8 +2414,8 @@ discard block |
||
| 2414 | 2414 | $closing_a_tag = ''; |
| 2415 | 2415 | if (function_exists('get_privacy_policy_url')) { |
| 2416 | 2416 | $privacy_page_url = get_privacy_policy_url(); |
| 2417 | - if (! empty($privacy_page_url)) { |
|
| 2418 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2417 | + if ( ! empty($privacy_page_url)) { |
|
| 2418 | + $opening_a_tag = '<a href="'.$privacy_page_url.'" target="_blank">'; |
|
| 2419 | 2419 | $closing_a_tag = '</a>'; |
| 2420 | 2420 | } |
| 2421 | 2421 | } |
@@ -2630,7 +2630,7 @@ discard block |
||
| 2630 | 2630 | public function log_file_name($reset = false) |
| 2631 | 2631 | { |
| 2632 | 2632 | if (empty($this->log_file_name) || $reset) { |
| 2633 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2633 | + $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt'; |
|
| 2634 | 2634 | EE_Config::instance()->update_espresso_config(false, false); |
| 2635 | 2635 | } |
| 2636 | 2636 | return $this->log_file_name; |
@@ -2644,7 +2644,7 @@ discard block |
||
| 2644 | 2644 | public function debug_file_name($reset = false) |
| 2645 | 2645 | { |
| 2646 | 2646 | if (empty($this->debug_file_name) || $reset) { |
| 2647 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2647 | + $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt'; |
|
| 2648 | 2648 | EE_Config::instance()->update_espresso_config(false, false); |
| 2649 | 2649 | } |
| 2650 | 2650 | return $this->debug_file_name; |
@@ -2848,21 +2848,21 @@ discard block |
||
| 2848 | 2848 | $this->use_google_maps = true; |
| 2849 | 2849 | $this->google_map_api_key = ''; |
| 2850 | 2850 | // for event details pages (reg page) |
| 2851 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2852 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2853 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2854 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2855 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2856 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2857 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2851 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2852 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2853 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2854 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2855 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2856 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2857 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2858 | 2858 | // for event list pages |
| 2859 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2860 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2861 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2862 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2863 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2864 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2865 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2859 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2860 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2861 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2862 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2863 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2864 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2865 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2866 | 2866 | } |
| 2867 | 2867 | } |
| 2868 | 2868 | |
@@ -3180,7 +3180,7 @@ discard block |
||
| 3180 | 3180 | */ |
| 3181 | 3181 | public function max_input_vars_limit_check($input_count = 0) |
| 3182 | 3182 | { |
| 3183 | - if (! empty($this->php->max_input_vars) |
|
| 3183 | + if ( ! empty($this->php->max_input_vars) |
|
| 3184 | 3184 | && ($input_count >= $this->php->max_input_vars) |
| 3185 | 3185 | ) { |
| 3186 | 3186 | // check the server setting because the config value could be stale |
@@ -7,16 +7,16 @@ discard block |
||
| 7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
| 8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
| 9 | 9 | if (! defined('DS')) { |
| 10 | - define('DS', '/'); |
|
| 10 | + define('DS', '/'); |
|
| 11 | 11 | } |
| 12 | 12 | if (! defined('PS')) { |
| 13 | - define('PS', PATH_SEPARATOR); |
|
| 13 | + define('PS', PATH_SEPARATOR); |
|
| 14 | 14 | } |
| 15 | 15 | if (! defined('SP')) { |
| 16 | - define('SP', ' '); |
|
| 16 | + define('SP', ' '); |
|
| 17 | 17 | } |
| 18 | 18 | if (! defined('EENL')) { |
| 19 | - define('EENL', "\n"); |
|
| 19 | + define('EENL', "\n"); |
|
| 20 | 20 | } |
| 21 | 21 | // define the plugin directory and URL |
| 22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
@@ -70,16 +70,16 @@ discard block |
||
| 70 | 70 | define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/'); |
| 71 | 71 | // check for DOMPDF fonts in uploads |
| 72 | 72 | if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) { |
| 73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
| 73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
| 74 | 74 | } |
| 75 | 75 | // ajax constants |
| 76 | 76 | define( |
| 77 | - 'EE_FRONT_AJAX', |
|
| 78 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) |
|
| 77 | + 'EE_FRONT_AJAX', |
|
| 78 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) |
|
| 79 | 79 | ); |
| 80 | 80 | define( |
| 81 | - 'EE_ADMIN_AJAX', |
|
| 82 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) |
|
| 81 | + 'EE_ADMIN_AJAX', |
|
| 82 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) |
|
| 83 | 83 | ); |
| 84 | 84 | // just a handy constant occasionally needed for finding values representing infinity in the DB |
| 85 | 85 | // you're better to use this than its straight value (currently -1) in case you ever |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | define('EE_INF_IN_DB', -1); |
| 88 | 88 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
| 89 | 89 | if (! defined('EE_DEBUG')) { |
| 90 | - define('EE_DEBUG', false); |
|
| 90 | + define('EE_DEBUG', false); |
|
| 91 | 91 | } |
| 92 | 92 | // for older WP versions |
| 93 | 93 | if (! defined('MONTH_IN_SECONDS')) { |
| 94 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 94 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 95 | 95 | } |
@@ -6,71 +6,71 @@ discard block |
||
| 6 | 6 | define('EE_MIN_PHP_VER_RECOMMENDED', '5.6.32'); |
| 7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
| 8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
| 9 | -if (! defined('DS')) { |
|
| 9 | +if ( ! defined('DS')) { |
|
| 10 | 10 | define('DS', '/'); |
| 11 | 11 | } |
| 12 | -if (! defined('PS')) { |
|
| 12 | +if ( ! defined('PS')) { |
|
| 13 | 13 | define('PS', PATH_SEPARATOR); |
| 14 | 14 | } |
| 15 | -if (! defined('SP')) { |
|
| 15 | +if ( ! defined('SP')) { |
|
| 16 | 16 | define('SP', ' '); |
| 17 | 17 | } |
| 18 | -if (! defined('EENL')) { |
|
| 18 | +if ( ! defined('EENL')) { |
|
| 19 | 19 | define('EENL', "\n"); |
| 20 | 20 | } |
| 21 | 21 | // define the plugin directory and URL |
| 22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
| 23 | -define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE) . '/'); |
|
| 23 | +define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE).'/'); |
|
| 24 | 24 | define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
| 25 | 25 | // main root folder paths |
| 26 | -define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages/'); |
|
| 27 | -define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core/'); |
|
| 28 | -define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules/'); |
|
| 29 | -define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public/'); |
|
| 30 | -define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes/'); |
|
| 31 | -define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets/'); |
|
| 32 | -define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods/'); |
|
| 33 | -define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated/'); |
|
| 26 | +define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages/'); |
|
| 27 | +define('EE_CORE', EE_PLUGIN_DIR_PATH.'core/'); |
|
| 28 | +define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules/'); |
|
| 29 | +define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public/'); |
|
| 30 | +define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes/'); |
|
| 31 | +define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets/'); |
|
| 32 | +define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods/'); |
|
| 33 | +define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated/'); |
|
| 34 | 34 | // core system paths |
| 35 | -define('EE_ADMIN', EE_CORE . 'admin/'); |
|
| 36 | -define('EE_CPTS', EE_CORE . 'CPTs/'); |
|
| 37 | -define('EE_CLASSES', EE_CORE . 'db_classes/'); |
|
| 38 | -define('EE_INTERFACES', EE_CORE . 'interfaces/'); |
|
| 39 | -define('EE_BUSINESS', EE_CORE . 'business/'); |
|
| 40 | -define('EE_MODELS', EE_CORE . 'db_models/'); |
|
| 41 | -define('EE_HELPERS', EE_CORE . 'helpers/'); |
|
| 42 | -define('EE_LIBRARIES', EE_CORE . 'libraries/'); |
|
| 43 | -define('EE_TEMPLATES', EE_CORE . 'templates/'); |
|
| 44 | -define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs/'); |
|
| 45 | -define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets/'); |
|
| 46 | -define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections/'); |
|
| 35 | +define('EE_ADMIN', EE_CORE.'admin/'); |
|
| 36 | +define('EE_CPTS', EE_CORE.'CPTs/'); |
|
| 37 | +define('EE_CLASSES', EE_CORE.'db_classes/'); |
|
| 38 | +define('EE_INTERFACES', EE_CORE.'interfaces/'); |
|
| 39 | +define('EE_BUSINESS', EE_CORE.'business/'); |
|
| 40 | +define('EE_MODELS', EE_CORE.'db_models/'); |
|
| 41 | +define('EE_HELPERS', EE_CORE.'helpers/'); |
|
| 42 | +define('EE_LIBRARIES', EE_CORE.'libraries/'); |
|
| 43 | +define('EE_TEMPLATES', EE_CORE.'templates/'); |
|
| 44 | +define('EE_THIRD_PARTY', EE_CORE.'third_party_libs/'); |
|
| 45 | +define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets/'); |
|
| 46 | +define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections/'); |
|
| 47 | 47 | // gateways |
| 48 | -define('EE_GATEWAYS', EE_MODULES . 'gateways/'); |
|
| 49 | -define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules/gateways/'); |
|
| 48 | +define('EE_GATEWAYS', EE_MODULES.'gateways/'); |
|
| 49 | +define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules/gateways/'); |
|
| 50 | 50 | // asset URL paths |
| 51 | -define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core/templates/'); |
|
| 52 | -define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets/'); |
|
| 53 | -define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images/'); |
|
| 54 | -define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core/third_party_libs/'); |
|
| 55 | -define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 56 | -define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 51 | +define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core/templates/'); |
|
| 52 | +define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets/'); |
|
| 53 | +define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images/'); |
|
| 54 | +define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core/third_party_libs/'); |
|
| 55 | +define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/'); |
|
| 56 | +define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/'); |
|
| 57 | 57 | // define upload paths |
| 58 | 58 | $uploads = wp_upload_dir(); |
| 59 | 59 | // define the uploads directory and URL |
| 60 | -define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . '/espresso/'); |
|
| 61 | -define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . '/espresso/'); |
|
| 60 | +define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].'/espresso/'); |
|
| 61 | +define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].'/espresso/'); |
|
| 62 | 62 | // define the templates directory and URL |
| 63 | -define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . '/espresso/templates/'); |
|
| 64 | -define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . '/espresso/templates/'); |
|
| 63 | +define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].'/espresso/templates/'); |
|
| 64 | +define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].'/espresso/templates/'); |
|
| 65 | 65 | // define the gateway directory and URL |
| 66 | -define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . '/espresso/gateways/'); |
|
| 67 | -define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . '/espresso/gateways/'); |
|
| 66 | +define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].'/espresso/gateways/'); |
|
| 67 | +define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].'/espresso/gateways/'); |
|
| 68 | 68 | // languages folder/path |
| 69 | -define('EE_LANGUAGES_SAFE_LOC', '../' . 'uploads/' . 'espresso/languages/'); |
|
| 70 | -define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/'); |
|
| 69 | +define('EE_LANGUAGES_SAFE_LOC', '../'.'uploads/'.'espresso/languages/'); |
|
| 70 | +define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages/'); |
|
| 71 | 71 | // check for DOMPDF fonts in uploads |
| 72 | -if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) { |
|
| 73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
| 72 | +if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts/')) { |
|
| 73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts/'); |
|
| 74 | 74 | } |
| 75 | 75 | // ajax constants |
| 76 | 76 | define( |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | // want to change its default value! or find when -1 means infinity |
| 87 | 87 | define('EE_INF_IN_DB', -1); |
| 88 | 88 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
| 89 | -if (! defined('EE_DEBUG')) { |
|
| 89 | +if ( ! defined('EE_DEBUG')) { |
|
| 90 | 90 | define('EE_DEBUG', false); |
| 91 | 91 | } |
| 92 | 92 | // for older WP versions |
| 93 | -if (! defined('MONTH_IN_SECONDS')) { |
|
| 93 | +if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 94 | 94 | define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
| 95 | 95 | } |