@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | $this->container = array(); |
| 37 | 37 | |
| 38 | - if(classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) { |
|
| 38 | + if (classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) { |
|
| 39 | 39 | $this->cache = classSupernova::$cache; |
| 40 | 40 | classSupernova::log_file('locale.__constructor: Cache is present'); |
| 41 | 41 | //$this->cache->unset_by_prefix($this->cache_prefix); // TODO - remove? 'cause debug! |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if($enable_stat_usage && empty($this->stat_usage)) { |
|
| 44 | + if ($enable_stat_usage && empty($this->stat_usage)) { |
|
| 45 | 45 | $this->enable_stat_usage = $enable_stat_usage; |
| 46 | 46 | $this->usage_stat_load(); |
| 47 | 47 | // TODO shutdown function |
@@ -67,18 +67,18 @@ discard block |
||
| 67 | 67 | unset($fallback[$this->active]); |
| 68 | 68 | |
| 69 | 69 | // Проходим по оставшимся локалям |
| 70 | - foreach($fallback as $try_language) { |
|
| 70 | + foreach ($fallback as $try_language) { |
|
| 71 | 71 | // Если нет такой строки - пытаемся вытащить из кэша |
| 72 | - if(!isset($this->container[$try_language][$offset]) && $this->cache) { |
|
| 73 | - $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix . $try_language . '_' . $offset); |
|
| 72 | + if (!isset($this->container[$try_language][$offset]) && $this->cache) { |
|
| 73 | + $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix.$try_language.'_'.$offset); |
|
| 74 | 74 | // Записываем результат работы кэша |
| 75 | 75 | $locale_cache_statistic['queries']++; |
| 76 | 76 | isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['hits']++ : $locale_cache_statistic['misses']++; |
| 77 | -!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix . $try_language . '_' . $offset : false; |
|
| 77 | +!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix.$try_language.'_'.$offset : false; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Если мы как-то где-то нашли строку... |
| 81 | - if(isset($this->container[$try_language][$offset])) { |
|
| 81 | + if (isset($this->container[$try_language][$offset])) { |
|
| 82 | 82 | // ...значит она получена в результате фоллбэка и записываем её в кэш и контейнер |
| 83 | 83 | $this[$offset] = $this->container[$try_language][$offset]; |
| 84 | 84 | $locale_cache_statistic['fallbacks']++; |
@@ -94,16 +94,16 @@ discard block |
||
| 94 | 94 | $this->container[$this->active][] = $value; |
| 95 | 95 | } else { |
| 96 | 96 | $this->container[$this->active][$offset] = $value; |
| 97 | - if($this->cache) { |
|
| 98 | - $this->cache->__set($this->cache_prefix_lang . $offset, $value); |
|
| 97 | + if ($this->cache) { |
|
| 98 | + $this->cache->__set($this->cache_prefix_lang.$offset, $value); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | public function offsetExists($offset) { |
| 103 | 103 | // Шорткат если у нас уже есть строка в памяти PHP |
| 104 | - if(!isset($this->container[$this->active][$offset])) { |
|
| 104 | + if (!isset($this->container[$this->active][$offset])) { |
|
| 105 | 105 | // pdump($this->cache_prefix_lang . $offset); |
| 106 | - if(!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang . $offset))) { |
|
| 106 | + if (!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang.$offset))) { |
|
| 107 | 107 | // pdump($this->cache_prefix_lang . $offset); |
| 108 | 108 | // Если нету такой строки - делаем фоллбэк |
| 109 | 109 | $this->locale_string_fallback($offset); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | public function offsetGet($offset) { |
| 121 | 121 | $value = $this->offsetExists($offset) ? $this->container[$this->active][$offset] : null; |
| 122 | - if($this->enable_stat_usage) { |
|
| 122 | + if ($this->enable_stat_usage) { |
|
| 123 | 123 | $this->usage_stat_log($offset, $value); |
| 124 | 124 | } |
| 125 | 125 | return $value; |
@@ -136,26 +136,26 @@ discard block |
||
| 136 | 136 | public function usage_stat_load() { |
| 137 | 137 | global $sn_cache; |
| 138 | 138 | |
| 139 | - $this->stat_usage = $sn_cache->lng_stat_usage = array(); // TODO for debug |
|
| 140 | - if(empty($this->stat_usage)) { |
|
| 139 | + $this->stat_usage = $sn_cache->lng_stat_usage = array(); // TODO for debug |
|
| 140 | + if (empty($this->stat_usage)) { |
|
| 141 | 141 | $query = doquery("SELECT * FROM {{lng_usage_stat}}"); |
| 142 | - while($row = db_fetch($query)) { |
|
| 143 | - $this->stat_usage[$row['lang_code'] . ':' . $row['string_id'] . ':' . $row['file'] . ':' . $row['line']] = $row['is_empty']; |
|
| 142 | + while ($row = db_fetch($query)) { |
|
| 143 | + $this->stat_usage[$row['lang_code'].':'.$row['string_id'].':'.$row['file'].':'.$row['line']] = $row['is_empty']; |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | public function usage_stat_save() { |
| 148 | - if(!empty($this->stat_usage_new)) { |
|
| 148 | + if (!empty($this->stat_usage_new)) { |
|
| 149 | 149 | global $sn_cache; |
| 150 | 150 | $sn_cache->lng_stat_usage = $this->stat_usage; |
| 151 | 151 | doquery("SELECT 1 FROM {{lng_usage_stat}} LIMIT 1"); |
| 152 | - foreach($this->stat_usage_new as &$value) { |
|
| 153 | - foreach($value as &$value2) { |
|
| 154 | - $value2 = '"' . db_escape($value2) . '"'; |
|
| 152 | + foreach ($this->stat_usage_new as &$value) { |
|
| 153 | + foreach ($value as &$value2) { |
|
| 154 | + $value2 = '"'.db_escape($value2).'"'; |
|
| 155 | 155 | } |
| 156 | - $value = '(' . implode(',', $value) .')'; |
|
| 156 | + $value = '('.implode(',', $value).')'; |
|
| 157 | 157 | } |
| 158 | - doquery("REPLACE INTO {{lng_usage_stat}} (lang_code,string_id,`file`,line,is_empty,locale) VALUES " . implode(',', $this->stat_usage_new)); |
|
| 158 | + doquery("REPLACE INTO {{lng_usage_stat}} (lang_code,string_id,`file`,line,is_empty,locale) VALUES ".implode(',', $this->stat_usage_new)); |
|
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | public function usage_stat_log(&$offset, &$value) { |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | $file = str_replace('\\', '/', substr($trace[1]['file'], strlen(SN_ROOT_PHYSICAL) - 1)); |
| 167 | 167 | |
| 168 | - $string_id = $this->active . ':' . $offset . ':' . $file . ':' . $trace[1]['line']; |
|
| 169 | - if(!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != $empty) { |
|
| 168 | + $string_id = $this->active.':'.$offset.':'.$file.':'.$trace[1]['line']; |
|
| 169 | + if (!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != $empty) { |
|
| 170 | 170 | $this->stat_usage[$string_id] = empty($value); |
| 171 | 171 | $this->stat_usage_new[] = array( |
| 172 | 172 | 'lang_code' => $this->active, |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | 'file' => $file, |
| 175 | 175 | 'line' => $trace[1]['line'], |
| 176 | 176 | 'is_empty' => intval(empty($value)), |
| 177 | - 'locale' => '' . $value, |
|
| 177 | + 'locale' => ''.$value, |
|
| 178 | 178 | ); |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
| 183 | 183 | protected function lng_try_filepath($path, $file_path_relative) { |
| 184 | - $file_path = SN_ROOT_PHYSICAL . ($path && file_exists(SN_ROOT_PHYSICAL . $path . $file_path_relative) ? $path : '') . $file_path_relative; |
|
| 184 | + $file_path = SN_ROOT_PHYSICAL.($path && file_exists(SN_ROOT_PHYSICAL.$path.$file_path_relative) ? $path : '').$file_path_relative; |
|
| 185 | 185 | return file_exists($file_path) ? $file_path : false; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -203,14 +203,14 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | classSupernova::log_file("locale.include: Loading data from domain '{$filename}'", 1); |
| 205 | 205 | |
| 206 | - $cache_file_key = $this->cache_prefix_lang . '__' . $filename; |
|
| 206 | + $cache_file_key = $this->cache_prefix_lang.'__'.$filename; |
|
| 207 | 207 | |
| 208 | 208 | // Подключен ли внешний кэш? |
| 209 | - if($this->cache) { |
|
| 209 | + if ($this->cache) { |
|
| 210 | 210 | // Загружен ли уже данный файл? |
| 211 | 211 | $cache_file_status = $this->cache->__get($cache_file_key); |
| 212 | - classSupernova::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is " . ($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0); |
|
| 213 | - if($cache_file_status) { |
|
| 212 | + classSupernova::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is ".($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0); |
|
| 213 | + if ($cache_file_status) { |
|
| 214 | 214 | // Если да - повторять загрузку нет смысла |
| 215 | 215 | return null; |
| 216 | 216 | } |
@@ -224,46 +224,46 @@ discard block |
||
| 224 | 224 | $this->make_fallback($language); |
| 225 | 225 | |
| 226 | 226 | $file_path = ''; |
| 227 | - foreach($this->fallback as $lang_try) { |
|
| 228 | - if(!$lang_try /* || isset($language_tried[$lang_try]) */) { |
|
| 227 | + foreach ($this->fallback as $lang_try) { |
|
| 228 | + if (!$lang_try /* || isset($language_tried[$lang_try]) */) { |
|
| 229 | 229 | continue; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) { |
|
| 232 | + if ($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) { |
|
| 233 | 233 | break; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) { |
|
| 236 | + if ($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) { |
|
| 237 | 237 | break; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | $file_path = ''; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if($file_path) { |
|
| 243 | + if ($file_path) { |
|
| 244 | 244 | include($file_path); |
| 245 | 245 | |
| 246 | - if(!empty($a_lang_array)) { |
|
| 246 | + if (!empty($a_lang_array)) { |
|
| 247 | 247 | $this->merge($a_lang_array); |
| 248 | 248 | |
| 249 | 249 | // Загрузка данных из файла в кэш |
| 250 | - if($this->cache) { |
|
| 250 | + if ($this->cache) { |
|
| 251 | 251 | classSupernova::log_file("Locale: loading '{$filename}' into cache"); |
| 252 | - foreach($a_lang_array as $key => $value) { |
|
| 253 | - $value_cache_key = $this->cache_prefix_lang . $key; |
|
| 254 | - if($this->cache->__isset($value_cache_key)) { |
|
| 255 | - if(is_array($value)) { |
|
| 252 | + foreach ($a_lang_array as $key => $value) { |
|
| 253 | + $value_cache_key = $this->cache_prefix_lang.$key; |
|
| 254 | + if ($this->cache->__isset($value_cache_key)) { |
|
| 255 | + if (is_array($value)) { |
|
| 256 | 256 | $alt_value = $this->cache->__get($value_cache_key); |
| 257 | 257 | $value = array_replace_recursive($alt_value, $value); |
| 258 | 258 | // pdump($alt_value, $alt_value); |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | - $this->cache->__set($this->cache_prefix_lang . $key, $value); |
|
| 261 | + $this->cache->__set($this->cache_prefix_lang.$key, $value); |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if($this->cache) { |
|
| 266 | + if ($this->cache) { |
|
| 267 | 267 | $this->cache->__set($cache_file_key, true); |
| 268 | 268 | } |
| 269 | 269 | |
@@ -276,14 +276,14 @@ discard block |
||
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | public function lng_load_i18n($i18n) { |
| 279 | - if(!isset($i18n)) { |
|
| 279 | + if (!isset($i18n)) { |
|
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - foreach($i18n as $i18n_data) { |
|
| 284 | - if(is_string($i18n_data)) { |
|
| 283 | + foreach ($i18n as $i18n_data) { |
|
| 284 | + if (is_string($i18n_data)) { |
|
| 285 | 285 | $this->lng_include($i18n_data); |
| 286 | - } elseif(is_array($i18n_data)) { |
|
| 286 | + } elseif (is_array($i18n_data)) { |
|
| 287 | 287 | $this->lng_include($i18n_data['file'], $i18n_data['path']); |
| 288 | 288 | } |
| 289 | 289 | } |
@@ -301,27 +301,27 @@ discard block |
||
| 301 | 301 | |
| 302 | 302 | classSupernova::log_file("locale.switch: Trying to switch language to '{$language_new}'"); |
| 303 | 303 | |
| 304 | - if($language_new == $this->active) { |
|
| 304 | + if ($language_new == $this->active) { |
|
| 305 | 305 | classSupernova::log_file("locale.switch: New language '{$language_new}' is equal to current language '{$this->active}' - EXIT", -1); |
| 306 | 306 | return false; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $this->active = $language = $language_new; |
| 310 | - $this->cache_prefix_lang = $this->cache_prefix . $this->active . '_'; |
|
| 310 | + $this->cache_prefix_lang = $this->cache_prefix.$this->active.'_'; |
|
| 311 | 311 | |
| 312 | 312 | $this['LANG_INFO'] = $this->lng_get_info($this->active); |
| 313 | 313 | $this->make_fallback($this->active); |
| 314 | 314 | |
| 315 | - if($this->cache) { |
|
| 316 | - $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang . '__INIT'); |
|
| 317 | - classSupernova::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is " . ($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0); |
|
| 318 | - if($cache_lang_init_status) { |
|
| 315 | + if ($this->cache) { |
|
| 316 | + $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang.'__INIT'); |
|
| 317 | + classSupernova::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is ".($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0); |
|
| 318 | + if ($cache_lang_init_status) { |
|
| 319 | 319 | return false; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Чистим текущие локализации из кэша. Достаточно почистить только флаги инициализации языкового кэша и загрузки файлов - они начинаются с '__' |
| 323 | 323 | classSupernova::log_file("locale.switch: Cache - invalidating data"); |
| 324 | - $this->cache->unset_by_prefix($this->cache_prefix_lang . '__'); |
|
| 324 | + $this->cache->unset_by_prefix($this->cache_prefix_lang.'__'); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | $this->lng_include('system'); |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | // Loading global language files |
| 332 | 332 | $this->lng_load_i18n(classSupernova::$sn_mvc['i18n']['']); |
| 333 | 333 | |
| 334 | - if($this->cache) { |
|
| 335 | - classSupernova::log_file("locale.switch: Cache - setting flag " . $this->cache_prefix_lang . '__INIT'); |
|
| 336 | - $this->cache->__set($this->cache_prefix_lang . '__INIT', true); |
|
| 334 | + if ($this->cache) { |
|
| 335 | + classSupernova::log_file("locale.switch: Cache - setting flag ".$this->cache_prefix_lang.'__INIT'); |
|
| 336 | + $this->cache->__set($this->cache_prefix_lang.'__INIT', true); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | classSupernova::log_file("locale.switch: Complete - EXIT"); |
@@ -343,9 +343,9 @@ discard block |
||
| 343 | 343 | |
| 344 | 344 | |
| 345 | 345 | public function lng_get_info($entry) { |
| 346 | - $file_name = SN_ROOT_PHYSICAL . 'language/' . $entry . '/language.mo.php'; |
|
| 346 | + $file_name = SN_ROOT_PHYSICAL.'language/'.$entry.'/language.mo.php'; |
|
| 347 | 347 | $lang_info = array(); |
| 348 | - if(file_exists($file_name)) { |
|
| 348 | + if (file_exists($file_name)) { |
|
| 349 | 349 | include($file_name); |
| 350 | 350 | } |
| 351 | 351 | |
@@ -353,15 +353,15 @@ discard block |
||
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | public function lng_get_list() { |
| 356 | - if(empty($this->lang_list)) { |
|
| 356 | + if (empty($this->lang_list)) { |
|
| 357 | 357 | $this->lang_list = array(); |
| 358 | 358 | |
| 359 | - $path = SN_ROOT_PHYSICAL . 'language/'; |
|
| 359 | + $path = SN_ROOT_PHYSICAL.'language/'; |
|
| 360 | 360 | $dir = dir($path); |
| 361 | - while(false !== ($entry = $dir->read())) { |
|
| 362 | - if(is_dir($path . $entry) && $entry[0] != '.') { |
|
| 361 | + while (false !== ($entry = $dir->read())) { |
|
| 362 | + if (is_dir($path.$entry) && $entry[0] != '.') { |
|
| 363 | 363 | $lang_info = $this->lng_get_info($entry); |
| 364 | - if($lang_info['LANG_NAME_ISO2'] == $entry) { |
|
| 364 | + if ($lang_info['LANG_NAME_ISO2'] == $entry) { |
|
| 365 | 365 | $this->lang_list[$lang_info['LANG_NAME_ISO2']] = $lang_info; |
| 366 | 366 | } |
| 367 | 367 | } |
@@ -89,15 +89,15 @@ discard block |
||
| 89 | 89 | // Инфа об устройстве и браузере - общая для всех |
| 90 | 90 | sn_db_transaction_start(); |
| 91 | 91 | $this->device_cypher = $_COOKIE[SN_COOKIE_D]; |
| 92 | - if($this->device_cypher) { |
|
| 92 | + if ($this->device_cypher) { |
|
| 93 | 93 | $cypher_safe = db_escape($this->device_cypher); |
| 94 | 94 | $device_id = doquery("SELECT `device_id` FROM {{security_device}} WHERE `device_cypher` = '{$cypher_safe}' LIMIT 1 FOR UPDATE", true); |
| 95 | - if(!empty($device_id['device_id'])) { |
|
| 95 | + if (!empty($device_id['device_id'])) { |
|
| 96 | 96 | $this->device_id = $device_id['device_id']; |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if($this->device_id <= 0) { |
|
| 100 | + if ($this->device_id <= 0) { |
|
| 101 | 101 | do { |
| 102 | 102 | $cypher_safe = db_escape($this->device_cypher = sys_random_string()); |
| 103 | 103 | $row = doquery("SELECT `device_id` FROM {{security_device}} WHERE `device_cypher` = '{$cypher_safe}' LIMIT 1 FOR UPDATE", true); |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | $this->page_address_id = db_get_set_unique_id_value($this->page_address, 'url_id', 'security_url', 'url_string'); |
| 119 | 119 | sn_db_transaction_commit(); |
| 120 | 120 | |
| 121 | - if($this->write_full_url) { |
|
| 121 | + if ($this->write_full_url) { |
|
| 122 | 122 | sn_db_transaction_start(); |
| 123 | 123 | $this->page_url = substr($_SERVER['REQUEST_URI'], strlen(SN_ROOT_RELATIVE)); |
| 124 | - if(strpos($_SERVER['REQUEST_URI'], '/simulator.php') === 0) { |
|
| 124 | + if (strpos($_SERVER['REQUEST_URI'], '/simulator.php') === 0) { |
|
| 125 | 125 | $this->page_url = '/simulator.php'; |
| 126 | 126 | } |
| 127 | 127 | $this->page_url_id = db_get_set_unique_id_value($this->page_url, 'url_id', 'security_url', 'url_string'); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function db_security_entry_insert($user_id_unsafe) { |
| 146 | 146 | // TODO $user_id = !empty(self::$user['id']) ? self::$user['id'] : 'NULL'; |
| 147 | - if(empty($user_id_unsafe)) { |
|
| 147 | + if (empty($user_id_unsafe)) { |
|
| 148 | 148 | // self::flog('Нет ИД пользователя'); |
| 149 | 149 | return true; |
| 150 | 150 | } |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | // self::flog('Вставляем запись системы безопасности'); |
| 155 | 155 | return doquery( |
| 156 | 156 | "INSERT IGNORE INTO {{security_player_entry}} (`player_id`, `device_id`, `browser_id`, `user_ip`, `user_proxy`) |
| 157 | - VALUES ({$user_id_safe}," . $this->device_id . "," . $this->browser_id . "," . |
|
| 158 | - $this->ip_v4_int . ", '" . db_escape($this->ip_v4_proxy_chain) . "');" |
|
| 157 | + VALUES ({$user_id_safe},".$this->device_id.",".$this->browser_id.",". |
|
| 158 | + $this->ip_v4_int.", '".db_escape($this->ip_v4_proxy_chain)."');" |
|
| 159 | 159 | ); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | public function db_counter_insert($user_id_unsafe) { |
| 168 | 168 | global $sys_stop_log_hit; |
| 169 | 169 | |
| 170 | - if($sys_stop_log_hit || !classSupernova::$config->game_counter) { |
|
| 170 | + if ($sys_stop_log_hit || !classSupernova::$config->game_counter) { |
|
| 171 | 171 | return; |
| 172 | 172 | } |
| 173 | 173 | |
@@ -177,14 +177,14 @@ discard block |
||
| 177 | 177 | classSupernova::$db->isWatching = true; |
| 178 | 178 | doquery( |
| 179 | 179 | "INSERT INTO {{counter}} SET |
| 180 | - `visit_time` = '" . SN_TIME_SQL. "', |
|
| 180 | + `visit_time` = '" . SN_TIME_SQL."', |
|
| 181 | 181 | `user_id` = {$user_id_safe}, |
| 182 | 182 | `device_id` = {$this->device_id}, |
| 183 | 183 | `browser_id` = {$this->browser_id}, |
| 184 | 184 | `user_ip` = {$this->ip_v4_int}, |
| 185 | 185 | `user_proxy` = '{$proxy_safe}', |
| 186 | - `page_url_id` = {$this->page_address_id}" . |
|
| 187 | - ($this->write_full_url ? ", `plain_url_id` = {$this->page_url_id}" : '' ). |
|
| 186 | + `page_url_id` = {$this->page_address_id}". |
|
| 187 | + ($this->write_full_url ? ", `plain_url_id` = {$this->page_url_id}" : ''). |
|
| 188 | 188 | ";"); |
| 189 | 189 | |
| 190 | 190 | classSupernova::$db->isWatching = false; |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | global $phpbb_root_path, $user; |
| 63 | 63 | |
| 64 | - if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template')) |
|
| 64 | + if (file_exists($phpbb_root_path.'styles/'.$user->theme['template_path'].'/template')) |
|
| 65 | 65 | { |
| 66 | - $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'; |
|
| 67 | - $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_'; |
|
| 66 | + $this->root = $phpbb_root_path.'styles/'.$user->theme['template_path'].'/template'; |
|
| 67 | + $this->cachepath = $phpbb_root_path.'cache/tpl_'.str_replace('_', '-', $user->theme['template_path']).'_'; |
|
| 68 | 68 | |
| 69 | 69 | if ($this->orig_tpl_storedb === null) |
| 70 | 70 | { |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | if ($user->theme['template_inherits_id']) |
| 83 | 83 | { |
| 84 | - $this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template'; |
|
| 84 | + $this->inherit_root = $phpbb_root_path.'styles/'.$user->theme['template_inherit_path'].'/template'; |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | else |
| 88 | 88 | { |
| 89 | - trigger_error('Template path could not be found: styles/' . $user->theme['template_path'] . '/template', E_USER_ERROR); |
|
| 89 | + trigger_error('Template path could not be found: styles/'.$user->theme['template_path'].'/template', E_USER_ERROR); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $this->_rootref = &$this->_tpldata['.'][0]; |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | $this->root = $template_path; |
| 112 | - $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; |
|
| 112 | + $this->cachepath = $phpbb_root_path.'cache/ctpl_'.str_replace('_', '-', $template_name).'_'; |
|
| 113 | 113 | |
| 114 | 114 | if ($fallback_template_path !== false) |
| 115 | 115 | { |
@@ -154,11 +154,11 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $this->filename[$handle] = $filename; |
| 157 | - $this->files[$handle] = $this->root . '/' . $filename; |
|
| 157 | + $this->files[$handle] = $this->root.'/'.$filename; |
|
| 158 | 158 | |
| 159 | 159 | if ($this->inherit_root) |
| 160 | 160 | { |
| 161 | - $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; |
|
| 161 | + $this->files_inherit[$handle] = $this->inherit_root.'/'.$filename; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | else |
| 237 | 237 | { |
| 238 | - eval(' ?>' . $this->compiled_code[$handle] . '<?php '); |
|
| 238 | + eval(' ?>'.$this->compiled_code[$handle].'<?php '); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | return true; |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | //$user->theme['template_storedb'] = $this->orig_tpl_storedb; |
| 281 | 281 | //$user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id; |
| 282 | 282 | |
| 283 | - $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . DOT_PHP_EX; |
|
| 283 | + $filename = $this->cachepath.str_replace('/', '.', $this->filename[$handle]).DOT_PHP_EX; |
|
| 284 | 284 | //$this->files_template[$handle] = (isset($user->theme['template_id'])) ? $user->theme['template_id'] : 0; |
| 285 | 285 | |
| 286 | 286 | $recompile = false; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | if (!class_exists('template_compile')) |
| 311 | 311 | { |
| 312 | - include($phpbb_root_path . 'includes/functions_template' . DOT_PHP_EX); |
|
| 312 | + include($phpbb_root_path.'includes/functions_template'.DOT_PHP_EX); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | // Inheritance - we point to another template file for this one. Equality is also used for store_db |
@@ -348,10 +348,10 @@ discard block |
||
| 348 | 348 | foreach ($ids as $id) |
| 349 | 349 | { |
| 350 | 350 | $sql = 'SELECT * |
| 351 | - FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' |
|
| 352 | - WHERE template_id = ' . $id . " |
|
| 353 | - AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "' |
|
| 354 | - OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')'; |
|
| 351 | + FROM ' . STYLES_TEMPLATE_DATA_TABLE.' |
|
| 352 | + WHERE template_id = ' . $id." |
|
| 353 | + AND (template_filename = '" . $db->sql_escape($this->filename[$handle])."' |
|
| 354 | + OR template_included " . $db->sql_like_expression($db->any_char.$this->filename[$handle].':'.$db->any_char).')'; |
|
| 355 | 355 | |
| 356 | 356 | $result = $db->sql_query($sql); |
| 357 | 357 | while ($row = $db->sql_fetchrow($result)) |
@@ -365,14 +365,14 @@ discard block |
||
| 365 | 365 | { |
| 366 | 366 | foreach ($rows as $row) |
| 367 | 367 | { |
| 368 | - $file = $this->root . '/' . $row['template_filename']; |
|
| 368 | + $file = $this->root.'/'.$row['template_filename']; |
|
| 369 | 369 | $force_reload = false; |
| 370 | 370 | if ($row['template_id'] != $user->theme['template_id']) |
| 371 | 371 | { |
| 372 | 372 | // make sure that we are not overlooking a file not in the db yet |
| 373 | 373 | if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) |
| 374 | 374 | { |
| 375 | - $file = $this->inherit_root . '/' . $row['template_filename']; |
|
| 375 | + $file = $this->inherit_root.'/'.$row['template_filename']; |
|
| 376 | 376 | $this->files[$row['template_filename']] = $file; |
| 377 | 377 | $this->files_inherit[$row['template_filename']] = $file; |
| 378 | 378 | $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | else |
| 415 | 415 | { |
| 416 | 416 | // Only bother compiling if it doesn't already exist |
| 417 | - if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . DOT_PHP_EX)) |
|
| 417 | + if (!file_exists($this->cachepath.str_replace('/', '.', $row['template_filename']).DOT_PHP_EX)) |
|
| 418 | 418 | { |
| 419 | 419 | $this->filename[$row['template_filename']] = $row['template_filename']; |
| 420 | 420 | $compile->compile_write($row['template_filename'], $compile->compile(trim($row['template_data']))); |
@@ -425,11 +425,11 @@ discard block |
||
| 425 | 425 | } |
| 426 | 426 | else |
| 427 | 427 | { |
| 428 | - $file = $this->root . '/' . $row['template_filename']; |
|
| 428 | + $file = $this->root.'/'.$row['template_filename']; |
|
| 429 | 429 | |
| 430 | 430 | if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) |
| 431 | 431 | { |
| 432 | - $file = $this->inherit_root . '/' . $row['template_filename']; |
|
| 432 | + $file = $this->inherit_root.'/'.$row['template_filename']; |
|
| 433 | 433 | $this->files[$row['template_filename']] = $file; |
| 434 | 434 | $this->files_inherit[$row['template_filename']] = $file; |
| 435 | 435 | $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | // Re-position template blocks |
| 623 | 623 | for ($i = sizeof($this->_tpldata[$blockname]); $i > $key; $i--) |
| 624 | 624 | { |
| 625 | - $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i-1]; |
|
| 625 | + $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i - 1]; |
|
| 626 | 626 | $this->_tpldata[$blockname][$i]['S_ROW_COUNT'] = $i; |
| 627 | 627 | } |
| 628 | 628 | |
@@ -656,10 +656,10 @@ discard block |
||
| 656 | 656 | { |
| 657 | 657 | $handle = $filename; |
| 658 | 658 | $this->filename[$handle] = $filename; |
| 659 | - $this->files[$handle] = $this->root . '/' . $filename; |
|
| 659 | + $this->files[$handle] = $this->root.'/'.$filename; |
|
| 660 | 660 | if ($this->inherit_root) |
| 661 | 661 | { |
| 662 | - $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; |
|
| 662 | + $this->files_inherit[$handle] = $this->inherit_root.'/'.$filename; |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | $filename = $this->_tpl_load($handle); |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | include($filename); |
| 674 | 674 | return; |
| 675 | 675 | } |
| 676 | - eval(' ?>' . $this->compiled_code[$handle] . '<?php '); |
|
| 676 | + eval(' ?>'.$this->compiled_code[$handle].'<?php '); |
|
| 677 | 677 | } |
| 678 | 678 | } |
| 679 | 679 | |
@@ -685,12 +685,12 @@ discard block |
||
| 685 | 685 | { |
| 686 | 686 | global $phpbb_root_path; |
| 687 | 687 | |
| 688 | - $file = $phpbb_root_path . $filename; |
|
| 688 | + $file = $phpbb_root_path.$filename; |
|
| 689 | 689 | |
| 690 | 690 | if (!file_exists($file)) |
| 691 | 691 | { |
| 692 | 692 | // trigger_error cannot be used here, as the output already started |
| 693 | - echo 'template->_php_include(): File ' . htmlspecialchars($file) . ' does not exist or is empty'; |
|
| 693 | + echo 'template->_php_include(): File '.htmlspecialchars($file).' does not exist or is empty'; |
|
| 694 | 694 | return; |
| 695 | 695 | } |
| 696 | 696 | include($file); |
@@ -702,13 +702,13 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | function assign_recursive($values, $name = '') |
| 704 | 704 | { |
| 705 | - if(isset($values['.'])) |
|
| 705 | + if (isset($values['.'])) |
|
| 706 | 706 | { |
| 707 | 707 | $values_extra = $values['.']; |
| 708 | 708 | unset($values['.']); |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | - if(!$name) |
|
| 711 | + if (!$name) |
|
| 712 | 712 | { |
| 713 | 713 | $this->assign_vars($values); |
| 714 | 714 | } |
@@ -717,12 +717,12 @@ discard block |
||
| 717 | 717 | $this->assign_block_vars($name, $values); |
| 718 | 718 | } |
| 719 | 719 | |
| 720 | - if(isset($values_extra)) |
|
| 720 | + if (isset($values_extra)) |
|
| 721 | 721 | { |
| 722 | - foreach($values_extra as $sub_array_name => $sub_array) |
|
| 722 | + foreach ($values_extra as $sub_array_name => $sub_array) |
|
| 723 | 723 | { |
| 724 | - $new_name = $name . ($name ? '.' : '') . $sub_array_name; |
|
| 725 | - foreach($sub_array as $sub_element) |
|
| 724 | + $new_name = $name.($name ? '.' : '').$sub_array_name; |
|
| 725 | + foreach ($sub_array as $sub_element) |
|
| 726 | 726 | { |
| 727 | 727 | $this->assign_recursive($sub_element, $new_name); |
| 728 | 728 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | 'template_data' => trim(@file_get_contents($this->template->files[$handle])), |
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | - $sql = 'INSERT INTO ' . STYLES_TEMPLATE_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); |
|
| 94 | + $sql = 'INSERT INTO '.STYLES_TEMPLATE_DATA_TABLE.' '.$db->sql_build_array('INSERT', $sql_ary); |
|
| 95 | 95 | $db->sql_query($sql); |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -138,9 +138,9 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches); |
| 140 | 140 | $include_blocks = $matches[1]; |
| 141 | - if($include_blocks) |
|
| 141 | + if ($include_blocks) |
|
| 142 | 142 | { |
| 143 | - foreach($include_blocks as &$included_file) |
|
| 143 | + foreach ($include_blocks as &$included_file) |
|
| 144 | 144 | { |
| 145 | 145 | $included_file .= '.tpl.html'; |
| 146 | 146 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | case 'BEGIN': |
| 171 | 171 | $this->block_else_level[] = false; |
| 172 | - $compile_blocks[] = '<?php ' . $this->compile_tag_block($block_val[2]) . ' ?>'; |
|
| 172 | + $compile_blocks[] = '<?php '.$this->compile_tag_block($block_val[2]).' ?>'; |
|
| 173 | 173 | break; |
| 174 | 174 | |
| 175 | 175 | case 'BEGINELSE': |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | case 'END': |
| 181 | 181 | array_pop($this->block_names); |
| 182 | - $compile_blocks[] = '<?php ' . ((array_pop($this->block_else_level)) ? '}' : '}}') . ' ?>'; |
|
| 182 | + $compile_blocks[] = '<?php '.((array_pop($this->block_else_level)) ? '}' : '}}').' ?>'; |
|
| 183 | 183 | break; |
| 184 | 184 | |
| 185 | 185 | case 'IF': |
| 186 | - $compile_blocks[] = '<?php ' . $this->compile_tag_if($block_val[2], false) . ' ?>'; |
|
| 186 | + $compile_blocks[] = '<?php '.$this->compile_tag_if($block_val[2], false).' ?>'; |
|
| 187 | 187 | break; |
| 188 | 188 | |
| 189 | 189 | case 'ELSE': |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | break; |
| 192 | 192 | |
| 193 | 193 | case 'ELSEIF': |
| 194 | - $compile_blocks[] = '<?php ' . $this->compile_tag_if($block_val[2], true) . ' ?>'; |
|
| 194 | + $compile_blocks[] = '<?php '.$this->compile_tag_if($block_val[2], true).' ?>'; |
|
| 195 | 195 | break; |
| 196 | 196 | |
| 197 | 197 | case 'ENDIF': |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | break; |
| 200 | 200 | |
| 201 | 201 | case 'DEFINE': |
| 202 | - $compile_blocks[] = '<?php ' . $this->compile_tag_define($block_val[2], true) . ' ?>'; |
|
| 202 | + $compile_blocks[] = '<?php '.$this->compile_tag_define($block_val[2], true).' ?>'; |
|
| 203 | 203 | break; |
| 204 | 204 | |
| 205 | 205 | case 'UNDEFINE': |
| 206 | - $compile_blocks[] = '<?php ' . $this->compile_tag_define($block_val[2], false) . ' ?>'; |
|
| 206 | + $compile_blocks[] = '<?php '.$this->compile_tag_define($block_val[2], false).' ?>'; |
|
| 207 | 207 | break; |
| 208 | 208 | |
| 209 | 209 | case 'INCLUDE': |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | $file = $temp; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $compile_blocks[] = '<?php ' . $this->compile_tag_include($temp) . ' ?>'; |
|
| 237 | + $compile_blocks[] = '<?php '.$this->compile_tag_include($temp).' ?>'; |
|
| 238 | 238 | |
| 239 | 239 | // No point in checking variable includes |
| 240 | 240 | if ($file) |
@@ -244,11 +244,11 @@ discard block |
||
| 244 | 244 | break; |
| 245 | 245 | |
| 246 | 246 | case 'INCLUDEPHP': |
| 247 | - $compile_blocks[] = (classSupernova::$config->tpl_allow_php) ? '<?php ' . $this->compile_tag_include_php(array_shift($includephp_blocks)) . ' ?>' : ''; |
|
| 247 | + $compile_blocks[] = (classSupernova::$config->tpl_allow_php) ? '<?php '.$this->compile_tag_include_php(array_shift($includephp_blocks)).' ?>' : ''; |
|
| 248 | 248 | break; |
| 249 | 249 | |
| 250 | 250 | case 'PHP': |
| 251 | - $compile_blocks[] = (classSupernova::$config->tpl_allow_php) ? '<?php ' . array_shift($php_blocks) . ' ?>' : ''; |
|
| 251 | + $compile_blocks[] = (classSupernova::$config->tpl_allow_php) ? '<?php '.array_shift($php_blocks).' ?>' : ''; |
|
| 252 | 252 | break; |
| 253 | 253 | |
| 254 | 254 | default: |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | for ($i = 0, $size = sizeof($text_blocks); $i < $size; $i++) |
| 264 | 264 | { |
| 265 | 265 | $trim_check_text = trim($text_blocks[$i]); |
| 266 | - $template_php .= (!$no_echo) ? (($trim_check_text != '') ? $text_blocks[$i] : '') . ((isset($compile_blocks[$i])) ? $compile_blocks[$i] : '') : (($trim_check_text != '') ? $text_blocks[$i] : '') . ((isset($compile_blocks[$i])) ? $compile_blocks[$i] : ''); |
|
| 266 | + $template_php .= (!$no_echo) ? (($trim_check_text != '') ? $text_blocks[$i] : '').((isset($compile_blocks[$i])) ? $compile_blocks[$i] : '') : (($trim_check_text != '') ? $text_blocks[$i] : '').((isset($compile_blocks[$i])) ? $compile_blocks[$i] : ''); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // Remove unused opening/closing tags |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | // we'll strip out such occurences, minimising such switching |
| 279 | 279 | if ($no_echo) |
| 280 | 280 | { |
| 281 | - return "\$$echo_var .= '" . $template_php . "'"; |
|
| 281 | + return "\$$echo_var .= '".$template_php."'"; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | return $template_php; |
@@ -373,30 +373,30 @@ discard block |
||
| 373 | 373 | |
| 374 | 374 | if ($match[2] < 0) |
| 375 | 375 | { |
| 376 | - $loop_start = '($_' . $tag_args . '_count ' . $match[2] . ' < 0 ? 0 : $_' . $tag_args . '_count ' . $match[2] . ')'; |
|
| 376 | + $loop_start = '($_'.$tag_args.'_count '.$match[2].' < 0 ? 0 : $_'.$tag_args.'_count '.$match[2].')'; |
|
| 377 | 377 | } |
| 378 | 378 | else |
| 379 | 379 | { |
| 380 | - $loop_start = '($_' . $tag_args . '_count < ' . $match[2] . ' ? $_' . $tag_args . '_count : ' . $match[2] . ')'; |
|
| 380 | + $loop_start = '($_'.$tag_args.'_count < '.$match[2].' ? $_'.$tag_args.'_count : '.$match[2].')'; |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | if (strlen($match[3]) < 1 || $match[3] == -1) |
| 384 | 384 | { |
| 385 | - $loop_end = '$_' . $tag_args . '_count'; |
|
| 385 | + $loop_end = '$_'.$tag_args.'_count'; |
|
| 386 | 386 | } |
| 387 | 387 | else if ($match[3] >= 0) |
| 388 | 388 | { |
| 389 | - $loop_end = '(' . ($match[3] + 1) . ' > $_' . $tag_args . '_count ? $_' . $tag_args . '_count : ' . ($match[3] + 1) . ')'; |
|
| 389 | + $loop_end = '('.($match[3] + 1).' > $_'.$tag_args.'_count ? $_'.$tag_args.'_count : '.($match[3] + 1).')'; |
|
| 390 | 390 | } |
| 391 | 391 | else //if ($match[3] < -1) |
| 392 | 392 | { |
| 393 | - $loop_end = '$_' . $tag_args . '_count' . ($match[3] + 1); |
|
| 393 | + $loop_end = '$_'.$tag_args.'_count'.($match[3] + 1); |
|
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | else |
| 397 | 397 | { |
| 398 | 398 | $loop_start = 0; |
| 399 | - $loop_end = '$_' . $tag_args . '_count'; |
|
| 399 | + $loop_end = '$_'.$tag_args.'_count'; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | $tag_template_php = ''; |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | if (sizeof($block) < 2) |
| 416 | 416 | { |
| 417 | 417 | // Block is not nested. |
| 418 | - $tag_template_php = '$_' . $tag_args . "_count = (isset(\$this->_tpldata['$tag_args'])) ? sizeof(\$this->_tpldata['$tag_args']) : 0;"; |
|
| 418 | + $tag_template_php = '$_'.$tag_args."_count = (isset(\$this->_tpldata['$tag_args'])) ? sizeof(\$this->_tpldata['$tag_args']) : 0;"; |
|
| 419 | 419 | $varref = "\$this->_tpldata['$tag_args']"; |
| 420 | 420 | } |
| 421 | 421 | else |
@@ -429,10 +429,10 @@ discard block |
||
| 429 | 429 | $varref = $this->generate_block_data_ref($namespace, false); |
| 430 | 430 | |
| 431 | 431 | // Create the for loop code to iterate over this block. |
| 432 | - $tag_template_php = '$_' . $tag_args . '_count = (isset(' . $varref . ')) ? sizeof(' . $varref . ') : 0;'; |
|
| 432 | + $tag_template_php = '$_'.$tag_args.'_count = (isset('.$varref.')) ? sizeof('.$varref.') : 0;'; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - $tag_template_php .= 'if ($_' . $tag_args . '_count) {'; |
|
| 435 | + $tag_template_php .= 'if ($_'.$tag_args.'_count) {'; |
|
| 436 | 436 | |
| 437 | 437 | /** |
| 438 | 438 | * The following uses foreach for iteration instead of a for loop, foreach is faster but requires PHP to make a copy of the contents of the array which uses more memory |
@@ -444,10 +444,10 @@ discard block |
||
| 444 | 444 | * </code> |
| 445 | 445 | */ |
| 446 | 446 | |
| 447 | - $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){'; |
|
| 447 | + $tag_template_php .= 'for ($_'.$tag_args.'_i = '.$loop_start.'; $_'.$tag_args.'_i < '.$loop_end.'; ++$_'.$tag_args.'_i){'; |
|
| 448 | 448 | // $tag_template_php .= '$this->_block_counter["'. $tag_args . '"] = $_' . $tag_args . '_i;'; |
| 449 | - $tag_template_php .= '$_'. $tag_args . '_val = &' . $varref . '[$_'. $tag_args. '_i];'; |
|
| 450 | - $tag_template_php .= '$this->_block_value["'. $tag_args . '"] = &' . $varref . '[$_'. $tag_args. '_i];'; |
|
| 449 | + $tag_template_php .= '$_'.$tag_args.'_val = &'.$varref.'[$_'.$tag_args.'_i];'; |
|
| 450 | + $tag_template_php .= '$this->_block_value["'.$tag_args.'"] = &'.$varref.'[$_'.$tag_args.'_i];'; |
|
| 451 | 451 | |
| 452 | 452 | return $tag_template_php; |
| 453 | 453 | } |
@@ -551,10 +551,10 @@ discard block |
||
| 551 | 551 | break; |
| 552 | 552 | |
| 553 | 553 | case 'is': |
| 554 | - $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1; |
|
| 554 | + $is_arg_start = ($tokens[$i - 1] == ')') ? array_pop($is_arg_stack) : $i - 1; |
|
| 555 | 555 | $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start)); |
| 556 | 556 | |
| 557 | - $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1)); |
|
| 557 | + $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i + 1)); |
|
| 558 | 558 | |
| 559 | 559 | array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens); |
| 560 | 560 | |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | default: |
| 566 | 566 | if (preg_match('#^((?:[a-z0-9\-_]+\.)+)?(\$)?(?=[A-Za-z])([A-Za-z0-9\-_]+)#s', $token, $varrefs)) |
| 567 | 567 | { |
| 568 | - $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[2]) . '[\'' . $varrefs[3] . '\']' : (($varrefs[2]) ? '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[3] . '\']' : '$this->_rootref[\'' . $varrefs[3] . '\']'); |
|
| 568 | + $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[2]).'[\''.$varrefs[3].'\']' : (($varrefs[2]) ? '$this->_tpldata[\'DEFINE\'][\'.\'][\''.$varrefs[3].'\']' : '$this->_rootref[\''.$varrefs[3].'\']'); |
|
| 569 | 569 | } |
| 570 | 570 | else if (preg_match('#^\.((?:[a-z0-9\-_]+\.?)+)$#s', $token, $varrefs)) |
| 571 | 571 | { |
@@ -582,20 +582,20 @@ discard block |
||
| 582 | 582 | $varref = $this->generate_block_data_ref($namespace, true); |
| 583 | 583 | |
| 584 | 584 | // Add the block reference for the last child. |
| 585 | - $varref .= "['" . $block . "']"; |
|
| 585 | + $varref .= "['".$block."']"; |
|
| 586 | 586 | } |
| 587 | 587 | else |
| 588 | 588 | { |
| 589 | 589 | $varref = '$this->_tpldata'; |
| 590 | 590 | |
| 591 | 591 | // Add the block reference for the last child. |
| 592 | - $varref .= "['" . $blocks[0] . "']"; |
|
| 592 | + $varref .= "['".$blocks[0]."']"; |
|
| 593 | 593 | } |
| 594 | 594 | $token = "sizeof($varref)"; |
| 595 | 595 | } |
| 596 | 596 | else if (!empty($token)) |
| 597 | 597 | { |
| 598 | - $token = '(' . $token . ')'; |
|
| 598 | + $token = '('.$token.')'; |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | break; |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | { |
| 608 | 608 | $tokens = array('false'); |
| 609 | 609 | } |
| 610 | - return (($elseif) ? '} else if (' : 'if (') . (implode(' ', $tokens) . ') { '); |
|
| 610 | + return (($elseif) ? '} else if (' : 'if (').(implode(' ', $tokens).') { '); |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | |
| 626 | 626 | if (!$op) |
| 627 | 627 | { |
| 628 | - return 'unset(' . (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ');'; |
|
| 628 | + return 'unset('.(($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true).'[\''.$match[2].'\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\''.$match[2].'\']').');'; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | // Are we a string? |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | $match[4] = $this->compile($match[4]); |
| 638 | 638 | |
| 639 | 639 | // Now replace the php code |
| 640 | - $match[4] = "'" . str_replace(array('<?php echo ', '; ?>'), array("' . ", " . '"), $match[4]) . "'"; |
|
| 640 | + $match[4] = "'".str_replace(array('<?php echo ', '; ?>'), array("' . ", " . '"), $match[4])."'"; |
|
| 641 | 641 | } |
| 642 | 642 | else |
| 643 | 643 | { |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | } |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ' = ' . $match[4] . ';'; |
|
| 663 | + return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true).'[\''.$match[2].'\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\''.$match[2].'\']').' = '.$match[4].';'; |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | /** |
@@ -801,24 +801,24 @@ discard block |
||
| 801 | 801 | // Build up the string with everything but the last child. |
| 802 | 802 | for ($i = 0; $i < $blockcount; $i++) |
| 803 | 803 | { |
| 804 | - $varref .= "['" . $blocks[$i] . "'][\$_" . $blocks[$i] . '_i]'; |
|
| 804 | + $varref .= "['".$blocks[$i]."'][\$_".$blocks[$i].'_i]'; |
|
| 805 | 805 | } |
| 806 | 806 | // Add the block reference for the last child. |
| 807 | - $varref .= "['" . $blocks[$blockcount] . "']"; |
|
| 807 | + $varref .= "['".$blocks[$blockcount]."']"; |
|
| 808 | 808 | // Add the iterator for the last child if requried. |
| 809 | 809 | if ($include_last_iterator) |
| 810 | 810 | { |
| 811 | - $varref .= '[$_' . $blocks[$blockcount] . '_i]'; |
|
| 811 | + $varref .= '[$_'.$blocks[$blockcount].'_i]'; |
|
| 812 | 812 | } |
| 813 | 813 | return $varref; |
| 814 | 814 | } |
| 815 | 815 | else if ($include_last_iterator) |
| 816 | 816 | { |
| 817 | - return '$_'. $blocks[$blockcount] . '_val'; |
|
| 817 | + return '$_'.$blocks[$blockcount].'_val'; |
|
| 818 | 818 | } |
| 819 | 819 | else |
| 820 | 820 | { |
| 821 | - return '$_'. $blocks[$blockcount - 1] . '_val[\''. $blocks[$blockcount]. '\']'; |
|
| 821 | + return '$_'.$blocks[$blockcount - 1].'_val[\''.$blocks[$blockcount].'\']'; |
|
| 822 | 822 | } |
| 823 | 823 | } |
| 824 | 824 | |
@@ -828,14 +828,14 @@ discard block |
||
| 828 | 828 | */ |
| 829 | 829 | function compile_write($handle, $data) |
| 830 | 830 | { |
| 831 | - $filename = $this->template->cachepath . str_replace('/', '.', $this->template->filename[$handle]) . DOT_PHP_EX; |
|
| 831 | + $filename = $this->template->cachepath.str_replace('/', '.', $this->template->filename[$handle]).DOT_PHP_EX; |
|
| 832 | 832 | |
| 833 | - $data = "<?php if (!defined('INSIDE')) exit;" . ((strpos($data, '<?php') === 0) ? substr($data, 5) : ' ?>' . $data); |
|
| 833 | + $data = "<?php if (!defined('INSIDE')) exit;".((strpos($data, '<?php') === 0) ? substr($data, 5) : ' ?>'.$data); |
|
| 834 | 834 | |
| 835 | 835 | if ($fp = @fopen($filename, 'wb')) |
| 836 | 836 | { |
| 837 | 837 | @flock($fp, LOCK_EX); |
| 838 | - @fwrite ($fp, $data); |
|
| 838 | + @fwrite($fp, $data); |
|
| 839 | 839 | @flock($fp, LOCK_UN); |
| 840 | 840 | @fclose($fp); |
| 841 | 841 | |
@@ -852,7 +852,7 @@ discard block |
||
| 852 | 852 | */ |
| 853 | 853 | private function minify($html) |
| 854 | 854 | { |
| 855 | - if(!classSupernova::$config->tpl_minifier) |
|
| 855 | + if (!classSupernova::$config->tpl_minifier) |
|
| 856 | 856 | { |
| 857 | 857 | return $html; |
| 858 | 858 | } |
@@ -862,14 +862,14 @@ discard block |
||
| 862 | 862 | $html = preg_replace('/(<script[^>]*?>.*?<\/script>)/si', '#pre#', $html); |
| 863 | 863 | $html = preg_replace('/>[\s]*</', '><', $html); // Strip spacechars between tags |
| 864 | 864 | $html = preg_replace('/[\s]+/', ' ', $html); // Replace several spacechars with one space |
| 865 | - if(!empty($pre[0])) |
|
| 865 | + if (!empty($pre[0])) |
|
| 866 | 866 | { |
| 867 | - foreach($pre[0] as $tag) |
|
| 867 | + foreach ($pre[0] as $tag) |
|
| 868 | 868 | { |
| 869 | 869 | $tag = preg_replace('/^\ *\/\/[^\<]*?$/m', ' ', $tag); // Strips comments - except those that contains HTML comment inside |
| 870 | 870 | $tag = preg_replace('/[\ \t]{2,}/', ' ', $tag); // Replace several spaces by one |
| 871 | 871 | $tag = preg_replace('/\s{2,}/', "\r\n", $tag); // Replace several linefeeds by one |
| 872 | - $html = preg_replace('/#pre#/', $tag, $html,1); |
|
| 872 | + $html = preg_replace('/#pre#/', $tag, $html, 1); |
|
| 873 | 873 | } |
| 874 | 874 | } |
| 875 | 875 | |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | public function compile_request($request) { |
| 451 | 451 | global $user; |
| 452 | 452 | |
| 453 | - if(!(classSupernova::$auth->account instanceof Account)) { |
|
| 453 | + if (!(classSupernova::$auth->account instanceof Account)) { |
|
| 454 | 454 | // TODO - throw new Exception(lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); |
| 455 | 455 | } |
| 456 | 456 | $this->account = classSupernova::$auth->account; |
@@ -471,15 +471,15 @@ discard block |
||
| 471 | 471 | $this->payment_currency = classSupernova::$config->payment_currency_default; |
| 472 | 472 | $this->payment_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_currency); |
| 473 | 473 | |
| 474 | - if(empty($this->payment_external_currency) && !empty($this->config['currency'])) { |
|
| 474 | + if (empty($this->payment_external_currency) && !empty($this->config['currency'])) { |
|
| 475 | 475 | $this->payment_external_currency = $this->config['currency']; |
| 476 | 476 | } |
| 477 | - if(empty($this->payment_external_currency)) { |
|
| 477 | + if (empty($this->payment_external_currency)) { |
|
| 478 | 478 | throw new Exception(classLocale::$lang['pay_error_internal_no_external_currency_set'], SN_PAYMENT_ERROR_INTERNAL_NO_EXTERNAL_CURRENCY_SET); |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | $this->payment_external_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_external_currency); |
| 482 | - if($this->payment_external_amount < 0.01) { |
|
| 482 | + if ($this->payment_external_amount < 0.01) { |
|
| 483 | 483 | throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); |
| 484 | 484 | } |
| 485 | 485 | |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | $this->generate_description(); |
| 489 | 489 | |
| 490 | 490 | $this->db_insert(); |
| 491 | - if(!$this->is_exists) { |
|
| 491 | + if (!$this->is_exists) { |
|
| 492 | 492 | throw new Exception(classLocale::$lang['pay_msg_request_error_db_payment_create'], SN_PAYMENT_REQUEST_DB_ERROR_PAYMENT_CREATE); |
| 493 | 493 | } |
| 494 | 494 | } |
@@ -500,26 +500,26 @@ discard block |
||
| 500 | 500 | * @throws Exception |
| 501 | 501 | */ |
| 502 | 502 | protected function payment_request_process($options = array()) { |
| 503 | - if(!$this->manifest['active']) { |
|
| 503 | + if (!$this->manifest['active']) { |
|
| 504 | 504 | throw new Exception(classLocale::$lang['pay_msg_module_disabled'], SN_MODULE_DISABLED); |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | // Если есть payment_id - загружаем под него данные |
| 508 | - if(!empty($this->payment_params['payment_id'])) { |
|
| 508 | + if (!empty($this->payment_params['payment_id'])) { |
|
| 509 | 509 | $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']); |
| 510 | - if(!$this->request_payment_id) { |
|
| 510 | + if (!$this->request_payment_id) { |
|
| 511 | 511 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - if(!$this->db_get_by_id($this->request_payment_id)) { |
|
| 514 | + if (!$this->db_get_by_id($this->request_payment_id)) { |
|
| 515 | 515 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // Проверяем - был ли этот платеж обработан? |
| 519 | 519 | // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed |
| 520 | - if($this->payment_status != PAYMENT_STATUS_NONE) { |
|
| 520 | + if ($this->payment_status != PAYMENT_STATUS_NONE) { |
|
| 521 | 521 | sn_db_transaction_rollback(); |
| 522 | - sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id); |
|
| 522 | + sys_redirect(SN_ROOT_VIRTUAL.'metamatter.php?payment_id='.$this->payment_id); |
|
| 523 | 523 | die(); |
| 524 | 524 | } |
| 525 | 525 | } |
@@ -527,89 +527,89 @@ discard block |
||
| 527 | 527 | // Пытаемся получить из запроса ИД аккаунта |
| 528 | 528 | $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0; |
| 529 | 529 | // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id |
| 530 | - if(empty($request_account_id) && !empty($this->payment_account_id)) { |
|
| 530 | + if (empty($request_account_id) && !empty($this->payment_account_id)) { |
|
| 531 | 531 | $request_account_id = $this->payment_account_id; |
| 532 | 532 | } |
| 533 | 533 | // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать |
| 534 | - if(empty($request_account_id)) { |
|
| 534 | + if (empty($request_account_id)) { |
|
| 535 | 535 | // TODO - аккаунт |
| 536 | 536 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
| 537 | 537 | } |
| 538 | 538 | // Если нет записи в таблице - тогда берем payment_account_id из запроса |
| 539 | - if(empty($this->payment_account_id)) { |
|
| 539 | + if (empty($this->payment_account_id)) { |
|
| 540 | 540 | $this->payment_account_id = $request_account_id; |
| 541 | 541 | } |
| 542 | 542 | // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать |
| 543 | - if($this->payment_account_id != $request_account_id) { |
|
| 543 | + if ($this->payment_account_id != $request_account_id) { |
|
| 544 | 544 | // TODO - Поменять сообщение об ошибке |
| 545 | 545 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
| 546 | 546 | } |
| 547 | 547 | // Проверяем существование аккаунта с данным ИД |
| 548 | - if(!$this->account->db_get_by_id($this->payment_account_id)) { |
|
| 549 | - throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'] . ' ID ' . $this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
|
| 548 | + if (!$this->account->db_get_by_id($this->payment_account_id)) { |
|
| 549 | + throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'].' ID '.$this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | // TODO Проверка на сервер_ид - как бы и не нужна, наверное? |
| 553 | - if(!empty($this->payment_params['server_id'])) { |
|
| 553 | + if (!empty($this->payment_params['server_id'])) { |
|
| 554 | 554 | $this->request_server_id = sys_get_param_str($this->payment_params['server_id']); |
| 555 | - if(SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
| 556 | - throw new Exception(classLocale::$lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); |
|
| 555 | + if (SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
| 556 | + throw new Exception(classLocale::$lang['pay_msg_request_server_wrong']." {$this->request_server_id} вместо ".SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); |
|
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | // Сверка количества оплаченной ММ с учётом бонусов |
| 561 | - if(!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
| 561 | + if (!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
| 562 | 562 | $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']); |
| 563 | - if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
| 564 | - throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'] . " пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); |
|
| 563 | + if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
| 564 | + throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid']." пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); |
|
| 565 | 565 | } |
| 566 | 566 | empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false; |
| 567 | 567 | } |
| 568 | - if(empty($this->payment_dark_matter_paid)) { |
|
| 568 | + if (empty($this->payment_dark_matter_paid)) { |
|
| 569 | 569 | // TODO - обратный расчёт из gained |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | // Проверка наличия внешнего ИД платежа |
| 573 | - if(!empty($this->payment_params['payment_external_id'])) { |
|
| 573 | + if (!empty($this->payment_params['payment_external_id'])) { |
|
| 574 | 574 | $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']); |
| 575 | - if(empty($request_payment_external_id)) { |
|
| 575 | + if (empty($request_payment_external_id)) { |
|
| 576 | 576 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
| 577 | - } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
| 577 | + } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
| 578 | 578 | // TODO - Может быть поменять сообщение |
| 579 | 579 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
| 580 | 580 | } |
| 581 | 581 | $this->payment_external_id = $request_payment_external_id; |
| 582 | 582 | } |
| 583 | 583 | // Сверка суммы, запрошенной СН к оплате |
| 584 | - if(!empty($this->payment_params['payment_external_money'])) { |
|
| 584 | + if (!empty($this->payment_params['payment_external_money'])) { |
|
| 585 | 585 | $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']); |
| 586 | - if($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
| 587 | - throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 586 | + if ($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
| 587 | + throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 588 | 588 | } |
| 589 | 589 | empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false; |
| 590 | 590 | } |
| 591 | 591 | // Заполняем поле валюты платёжной системы |
| 592 | - if(!empty($this->payment_params['payment_external_currency'])) { |
|
| 592 | + if (!empty($this->payment_params['payment_external_currency'])) { |
|
| 593 | 593 | $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']); |
| 594 | - if(empty($this->payment_external_currency)) { |
|
| 594 | + if (empty($this->payment_external_currency)) { |
|
| 595 | 595 | // TODO - поменять сообщение |
| 596 | - throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 596 | + throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 597 | 597 | } |
| 598 | 598 | } |
| 599 | - if(empty($this->payment_external_currency)) { |
|
| 599 | + if (empty($this->payment_external_currency)) { |
|
| 600 | 600 | $this->payment_external_currency = $this->config['currency']; |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | // Заполнение внутренней суммы и валюты из внешних данных |
| 604 | - if(empty($this->payment_currency)) { |
|
| 604 | + if (empty($this->payment_currency)) { |
|
| 605 | 605 | $this->payment_currency = classSupernova::$config->payment_currency_default; |
| 606 | 606 | } |
| 607 | - if(empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
| 607 | + if (empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
| 608 | 608 | $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency); |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | // TODO - Тестовый режим |
| 612 | - if(!empty($this->payment_params['test'])) { |
|
| 612 | + if (!empty($this->payment_params['test'])) { |
|
| 613 | 613 | $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']); |
| 614 | 614 | } |
| 615 | 615 | |
@@ -636,21 +636,21 @@ discard block |
||
| 636 | 636 | sn_db_transaction_start(); |
| 637 | 637 | try { |
| 638 | 638 | $response = $this->payment_request_process(); |
| 639 | - } catch(Exception $e) { |
|
| 639 | + } catch (Exception $e) { |
|
| 640 | 640 | $response['result'] = $e->getCode(); |
| 641 | 641 | $response['message'] = $e->getMessage(); |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | - if($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
| 644 | + if ($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
| 645 | 645 | sn_db_transaction_commit(); |
| 646 | - classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT); |
|
| 646 | + classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Успешный платёж', LOG_INFO_PAYMENT); |
|
| 647 | 647 | } else { |
| 648 | 648 | sn_db_transaction_rollback(); |
| 649 | - classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Ошибка платежа', LOG_INFO_PAYMENT, true); |
|
| 649 | + classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Ошибка платежа', LOG_INFO_PAYMENT, true); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | // Переводим код результата из СН в код платежной системы |
| 653 | - if(is_array($this->result_translations) && !empty($this->result_translations)) { |
|
| 653 | + if (is_array($this->result_translations) && !empty($this->result_translations)) { |
|
| 654 | 654 | $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR]; |
| 655 | 655 | } |
| 656 | 656 | |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | $currency_from = strtolower($currency_from); |
| 674 | 674 | $currency_to = strtolower($currency_to); |
| 675 | 675 | |
| 676 | - if($currency_from != $currency_to) { |
|
| 676 | + if ($currency_from != $currency_to) { |
|
| 677 | 677 | $exchange_from = get_exchange_rate($currency_from); |
| 678 | 678 | $exchange_to = get_exchange_rate($currency_to); |
| 679 | 679 | |
@@ -697,10 +697,10 @@ discard block |
||
| 697 | 697 | public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) { |
| 698 | 698 | $bonus = 0; |
| 699 | 699 | $dark_matter_new = $dark_matter; |
| 700 | - if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
| 701 | - if($direct) { |
|
| 702 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 703 | - if($dm_for_bonus <= $dark_matter) { |
|
| 700 | + if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
| 701 | + if ($direct) { |
|
| 702 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 703 | + if ($dm_for_bonus <= $dark_matter) { |
|
| 704 | 704 | $dark_matter_new = $dark_matter * (1 + $multiplier); |
| 705 | 705 | $bonus = $multiplier; |
| 706 | 706 | } else { |
@@ -708,9 +708,9 @@ discard block |
||
| 708 | 708 | } |
| 709 | 709 | } |
| 710 | 710 | } else { |
| 711 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 711 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 712 | 712 | $temp = $dm_for_bonus * (1 + $multiplier); |
| 713 | - if($dark_matter >= $temp) { |
|
| 713 | + if ($dark_matter >= $temp) { |
|
| 714 | 714 | $dark_matter_new = round($dark_matter / (1 + $multiplier)); |
| 715 | 715 | $bonus = $multiplier; |
| 716 | 716 | } else { |
@@ -764,30 +764,30 @@ discard block |
||
| 764 | 764 | ); |
| 765 | 765 | |
| 766 | 766 | $replace = false; |
| 767 | - if($this->payment_id) { |
|
| 767 | + if ($this->payment_id) { |
|
| 768 | 768 | $payment['payment_id'] = $this->payment_id; |
| 769 | 769 | $replace = true; |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | $query = array(); |
| 773 | - foreach($payment as $key => $value) { |
|
| 774 | - $value = is_string($value) ? '"' . db_escape($value) . '"' : $value; |
|
| 773 | + foreach ($payment as $key => $value) { |
|
| 774 | + $value = is_string($value) ? '"'.db_escape($value).'"' : $value; |
|
| 775 | 775 | $query[] = "`{$key}` = {$value}"; |
| 776 | 776 | } |
| 777 | 777 | |
| 778 | - $this->db->doquery(($replace ? 'REPLACE' : 'INSERT') . ' INTO `{{payment}}` SET ' . implode(',', $query) . ';'); |
|
| 778 | + $this->db->doquery(($replace ? 'REPLACE' : 'INSERT').' INTO `{{payment}}` SET '.implode(',', $query).';'); |
|
| 779 | 779 | |
| 780 | 780 | return $this->db_get_by_id($this->db->db_insert_id()); |
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | |
| 784 | 784 | function payment_adjust_mm_new() { |
| 785 | - if(!$this->payment_test) { |
|
| 785 | + if (!$this->payment_test) { |
|
| 786 | 786 | // Not a test payment. Adding DM to account |
| 787 | 787 | $this->account = new Account($this->db); |
| 788 | 788 | $this->account->db_get_by_id($this->payment_account_id); |
| 789 | 789 | $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment); |
| 790 | - if(!$result) { |
|
| 790 | + if (!$result) { |
|
| 791 | 791 | throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
| 792 | 792 | } |
| 793 | 793 | } |
@@ -796,25 +796,25 @@ discard block |
||
| 796 | 796 | function payment_cancel(&$payment) { |
| 797 | 797 | die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}'); |
| 798 | 798 | |
| 799 | - if(!isset($payment['payment_status'])) { |
|
| 799 | + if (!isset($payment['payment_status'])) { |
|
| 800 | 800 | throw new exception(classLocale::$lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND); |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | - if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
| 804 | - $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']); |
|
| 803 | + if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
| 804 | + $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'].' '.$payment['payment_comment']); |
|
| 805 | 805 | |
| 806 | - if(!$payment['payment_test']) { |
|
| 806 | + if (!$payment['payment_test']) { |
|
| 807 | 807 | $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']); |
| 808 | - if(!$result) { |
|
| 808 | + if (!$result) { |
|
| 809 | 809 | throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
| 810 | 810 | } |
| 811 | 811 | } |
| 812 | 812 | $payment['payment_status'] = PAYMENT_STATUS_CANCELED; |
| 813 | 813 | db_payment_update($payment, $safe_comment); |
| 814 | 814 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK); |
| 815 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
| 815 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
| 816 | 816 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK); |
| 817 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
| 817 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
| 818 | 818 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE); |
| 819 | 819 | } |
| 820 | 820 | } |
@@ -828,8 +828,8 @@ discard block |
||
| 828 | 828 | |
| 829 | 829 | protected function db_complete_payment() { |
| 830 | 830 | // TODO - поле payment_processed |
| 831 | - if($this->payment_status == PAYMENT_STATUS_NONE) { |
|
| 832 | - if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
| 831 | + if ($this->payment_status == PAYMENT_STATUS_NONE) { |
|
| 832 | + if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
| 833 | 833 | $this->payment_adjust_mm_new(); |
| 834 | 834 | $this->payment_status = PAYMENT_STATUS_COMPLETE; |
| 835 | 835 | } else { |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | protected function db_assign_payment($payment = null) { |
| 877 | 877 | $this->payment_reset(); |
| 878 | 878 | |
| 879 | - if(is_array($payment) && isset($payment['payment_id'])) { |
|
| 879 | + if (is_array($payment) && isset($payment['payment_id'])) { |
|
| 880 | 880 | $this->payment_id = $payment['payment_id']; |
| 881 | 881 | $this->payment_status = $payment['payment_status']; |
| 882 | 882 | $this->payment_date = $payment['payment_date']; |
@@ -918,11 +918,11 @@ discard block |
||
| 918 | 918 | protected function generate_description() { |
| 919 | 919 | // TODO - системная локализация |
| 920 | 920 | $this->description_generated = array( |
| 921 | - PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на " . SN_ROOT_VIRTUAL, 0, 100), |
|
| 922 | - PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL, 0, 250), |
|
| 923 | - PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : '') . |
|
| 924 | - "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL . |
|
| 925 | - " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)" . |
|
| 921 | + PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на ".SN_ROOT_VIRTUAL, 0, 100), |
|
| 922 | + PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL, 0, 250), |
|
| 923 | + PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : ''). |
|
| 924 | + "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL. |
|
| 925 | + " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)". |
|
| 926 | 926 | " через '{$this->manifest['name']}' сумма {$this->payment_external_amount} {$this->payment_external_currency}", |
| 927 | 927 | ); |
| 928 | 928 | } |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | !mysql_select_db($settings['name']) |
| 53 | 53 | ? classSupernova::$debug->error_fatal('DB error - cannot find DB on server', $this->mysql_error()) |
| 54 | 54 | : false; |
| 55 | - !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';') |
|
| 55 | + !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL '.self::DB_MYSQL_TRANSACTION_REPEATABLE_READ.';') |
|
| 56 | 56 | ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level', $this->mysql_error()) |
| 57 | 57 | : false; |
| 58 | 58 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | public static function _init($group_name = '') { |
| 27 | 27 | parent::_init($group_name); |
| 28 | 28 | |
| 29 | - foreach(static::$_group_unit_id_list as $resource_id) { |
|
| 29 | + foreach (static::$_group_unit_id_list as $resource_id) { |
|
| 30 | 30 | static::$_group_pnames[$resource_id] = pname_resource_name($resource_id); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | !is_array($resource_array) ? $resource_array = array() : false; |
| 50 | 50 | |
| 51 | - foreach($resource_array as $resource_id => $resource_actual_delta) { |
|
| 52 | - if(!$resource_actual_delta) { |
|
| 51 | + foreach ($resource_array as $resource_id => $resource_actual_delta) { |
|
| 52 | + if (!$resource_actual_delta) { |
|
| 53 | 53 | // No delta - no changes |
| 54 | 54 | continue; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $result[$prefix . static::$_group_pnames[$resource_id]] = $resource_actual_delta; |
|
| 57 | + $result[$prefix.static::$_group_pnames[$resource_id]] = $resource_actual_delta; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return $result; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function __get($name) { |
| 110 | 110 | // Redirecting inaccessible get to __call which will handle the rest |
| 111 | - return $this->__call('get' . ucfirst($name), array()); |
|
| 111 | + return $this->__call('get'.ucfirst($name), array()); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | // TODO - сеттер должен параллельно изменять значение db_row - for now... |
| 121 | 121 | public function __set($name, $value) { |
| 122 | 122 | // Redirecting inaccessible set to __call which will handle the rest |
| 123 | - $this->__call('set' . ucfirst($name), array($value)); |
|
| 123 | + $this->__call('set'.ucfirst($name), array($value)); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -138,15 +138,15 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | // If method is not getter or setter OR property name not exists in $_properties - raising exception |
| 140 | 140 | // Descendants can catch this Exception to make own __call magic |
| 141 | - if(($left3 != 'get' && $left3 != 'set') || empty(static::$_properties[$propertyName])) { |
|
| 142 | - throw new ExceptionPropertyNotExists('Property ' . $propertyName . ' not exists when calling getter/setter ' . get_called_class() . '::' . $name, ERR_ERROR); |
|
| 141 | + if (($left3 != 'get' && $left3 != 'set') || empty(static::$_properties[$propertyName])) { |
|
| 142 | + throw new ExceptionPropertyNotExists('Property '.$propertyName.' not exists when calling getter/setter '.get_called_class().'::'.$name, ERR_ERROR); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // TODO check for read-only |
| 146 | 146 | |
| 147 | - if($left3 == 'set') { |
|
| 148 | - if(!empty($this->propertiesAdjusted[$propertyName])) { |
|
| 149 | - throw new PropertyAccessException('Property ' . $propertyName . ' already was adjusted so no SET is possible until dbSave in ' . get_called_class() . '::' . $name, ERR_ERROR); |
|
| 147 | + if ($left3 == 'set') { |
|
| 148 | + if (!empty($this->propertiesAdjusted[$propertyName])) { |
|
| 149 | + throw new PropertyAccessException('Property '.$propertyName.' already was adjusted so no SET is possible until dbSave in '.get_called_class().'::'.$name, ERR_ERROR); |
|
| 150 | 150 | } |
| 151 | 151 | $this->propertiesChanged[$propertyName] = 1; |
| 152 | 152 | } |
@@ -154,18 +154,18 @@ discard block |
||
| 154 | 154 | // Now deciding - will we call a protected setter or will we work with protected property |
| 155 | 155 | |
| 156 | 156 | // If method exists - just calling it |
| 157 | - if(method_exists($this, $name)) { |
|
| 157 | + if (method_exists($this, $name)) { |
|
| 158 | 158 | return call_user_func_array(array($this, $name), $arguments); |
| 159 | 159 | } |
| 160 | 160 | // No getter/setter exists - works directly with protected property |
| 161 | 161 | |
| 162 | 162 | // Is it getter? |
| 163 | - if($left3 === 'get') { |
|
| 164 | - return $this->{'_' . $propertyName}; |
|
| 163 | + if ($left3 === 'get') { |
|
| 164 | + return $this->{'_'.$propertyName}; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Not getter? Then it's setter |
| 168 | - $this->{'_' . $propertyName} = $arguments[0]; |
|
| 168 | + $this->{'_'.$propertyName} = $arguments[0]; |
|
| 169 | 169 | |
| 170 | 170 | return null; |
| 171 | 171 | } |
@@ -182,8 +182,8 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | public function dbLoad($dbId, $lockSkip = false) { |
| 184 | 184 | $dbId = idval($dbId); |
| 185 | - if($dbId <= 0) { |
|
| 186 | - classSupernova::$debug->error(get_called_class() . '::dbLoad $dbId not positive = ' . $dbId); |
|
| 185 | + if ($dbId <= 0) { |
|
| 186 | + classSupernova::$debug->error(get_called_class().'::dbLoad $dbId not positive = '.$dbId); |
|
| 187 | 187 | |
| 188 | 188 | return; |
| 189 | 189 | } |
@@ -191,12 +191,12 @@ discard block |
||
| 191 | 191 | $this->_dbId = $dbId; |
| 192 | 192 | $this->lockSkip = $lockSkip; |
| 193 | 193 | // TODO - Use classSupernova::$db_records_locked |
| 194 | - if(false && !$lockSkip && sn_db_transaction_check(false)) { |
|
| 194 | + if (false && !$lockSkip && sn_db_transaction_check(false)) { |
|
| 195 | 195 | $this->dbGetLockById($this->_dbId); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - $db_row = doquery("SELECT * FROM `{{" . static::$_table . "}}` WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId . " LIMIT 1 FOR UPDATE;", true); |
|
| 199 | - if(empty($db_row)) { |
|
| 198 | + $db_row = doquery("SELECT * FROM `{{".static::$_table."}}` WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId." LIMIT 1 FOR UPDATE;", true); |
|
| 199 | + if (empty($db_row)) { |
|
| 200 | 200 | return; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -224,26 +224,26 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | // TODO - perform operations only if properties was changed |
| 226 | 226 | public function dbSave() { |
| 227 | - if($this->isNew()) { |
|
| 227 | + if ($this->isNew()) { |
|
| 228 | 228 | // No DB_ID - new unit |
| 229 | - if($this->isEmpty()) { |
|
| 230 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - object is empty on ' . get_called_class() . '::dbSave'); |
|
| 229 | + if ($this->isEmpty()) { |
|
| 230 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - object is empty on '.get_called_class().'::dbSave'); |
|
| 231 | 231 | } |
| 232 | 232 | $this->dbInsert(); |
| 233 | 233 | } else { |
| 234 | 234 | // DB_ID is present |
| 235 | - if($this->isEmpty()) { |
|
| 235 | + if ($this->isEmpty()) { |
|
| 236 | 236 | $this->dbDelete(); |
| 237 | 237 | } else { |
| 238 | - if(!sn_db_transaction_check(false)) { |
|
| 239 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - transaction should always be started on ' . get_called_class() . '::dbUpdate'); |
|
| 238 | + if (!sn_db_transaction_check(false)) { |
|
| 239 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - transaction should always be started on '.get_called_class().'::dbUpdate'); |
|
| 240 | 240 | } |
| 241 | 241 | $this->dbUpdate(); |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - if(!empty($this->triggerDbOperationOn)) { |
|
| 246 | - foreach($this->triggerDbOperationOn as $item) { |
|
| 245 | + if (!empty($this->triggerDbOperationOn)) { |
|
| 246 | + foreach ($this->triggerDbOperationOn as $item) { |
|
| 247 | 247 | $item->dbSave(); |
| 248 | 248 | } |
| 249 | 249 | } |
@@ -263,13 +263,13 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | // TODO - protected |
| 265 | 265 | public function dbInsert() { |
| 266 | - if(!$this->isNew()) { |
|
| 267 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - record db_id is not empty on ' . get_called_class() . '::dbInsert'); |
|
| 266 | + if (!$this->isNew()) { |
|
| 267 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - record db_id is not empty on '.get_called_class().'::dbInsert'); |
|
| 268 | 268 | } |
| 269 | 269 | $this->_dbId = $this->db_field_set_create($this->dbMakeFieldSet()); |
| 270 | 270 | |
| 271 | - if(empty($this->_dbId)) { |
|
| 272 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - error saving record ' . get_called_class() . '::dbInsert'); |
|
| 271 | + if (empty($this->_dbId)) { |
|
| 272 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - error saving record '.get_called_class().'::dbInsert'); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | return $this->_dbId; |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | // TODO - protected |
| 282 | 282 | public function dbUpdate() { |
| 283 | 283 | // TODO - Update |
| 284 | - if($this->isNew()) { |
|
| 285 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbUpdate'); |
|
| 284 | + if ($this->isNew()) { |
|
| 285 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbUpdate'); |
|
| 286 | 286 | } |
| 287 | 287 | $this->db_field_update($this->dbMakeFieldSet(true)); |
| 288 | 288 | } |
@@ -292,10 +292,10 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | // TODO - protected |
| 294 | 294 | public function dbDelete() { |
| 295 | - if($this->isNew()) { |
|
| 296 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbDelete'); |
|
| 295 | + if ($this->isNew()) { |
|
| 296 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbDelete'); |
|
| 297 | 297 | } |
| 298 | - doquery("DELETE FROM {{" . static::$_table . "}} WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId); |
|
| 298 | + doquery("DELETE FROM {{".static::$_table."}} WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId); |
|
| 299 | 299 | $this->_dbId = 0; |
| 300 | 300 | // Обо всём остальном должен позаботиться контейнер |
| 301 | 301 | } |
@@ -334,18 +334,18 @@ discard block |
||
| 334 | 334 | * @param array $db_row |
| 335 | 335 | */ |
| 336 | 336 | public function dbRowParse(array $db_row) { |
| 337 | - foreach(static::$_properties as $property_name => &$property_data) { |
|
| 337 | + foreach (static::$_properties as $property_name => &$property_data) { |
|
| 338 | 338 | // Advanced values extraction procedure. Should be used when at least one of following rules is matched: |
| 339 | 339 | // - one field should translate to several properties; |
| 340 | 340 | // - one property should be filled according to several fields; |
| 341 | 341 | // - property filling requires some lookup in object values; |
| 342 | - if(!empty($property_data[P_METHOD_EXTRACT]) && is_callable(array($this, $property_data[P_METHOD_EXTRACT]))) { |
|
| 342 | + if (!empty($property_data[P_METHOD_EXTRACT]) && is_callable(array($this, $property_data[P_METHOD_EXTRACT]))) { |
|
| 343 | 343 | call_user_func_array(array($this, $property_data[P_METHOD_EXTRACT]), array(&$db_row)); |
| 344 | 344 | continue; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | // If property is read-only - doing nothing |
| 348 | - if(!empty($property_data[P_READ_ONLY])) { |
|
| 348 | + if (!empty($property_data[P_READ_ONLY])) { |
|
| 349 | 349 | continue; |
| 350 | 350 | } |
| 351 | 351 | |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | !empty($property_data[P_FUNC_INPUT]) && is_callable($property_data[P_FUNC_INPUT]) ? $value = call_user_func($property_data[P_FUNC_INPUT], $value) : false; |
| 357 | 357 | |
| 358 | 358 | // If there is setter for this field - using it. Setters is always a methods of $THIS |
| 359 | - if(!empty($property_data[P_METHOD_SET]) && is_callable(array($this, $property_data[P_METHOD_SET]))) { |
|
| 359 | + if (!empty($property_data[P_METHOD_SET]) && is_callable(array($this, $property_data[P_METHOD_SET]))) { |
|
| 360 | 360 | call_user_func(array($this, $property_data[P_METHOD_SET]), $value); |
| 361 | 361 | } else { |
| 362 | 362 | $this->{$property_name} = $value; |
@@ -372,21 +372,21 @@ discard block |
||
| 372 | 372 | protected function dbMakeFieldSet($isUpdate = false) { |
| 373 | 373 | $array = array(); |
| 374 | 374 | |
| 375 | - foreach(static::$_properties as $property_name => &$property_data) { |
|
| 375 | + foreach (static::$_properties as $property_name => &$property_data) { |
|
| 376 | 376 | // TODO - on isUpdate add only changed/adjusted properties |
| 377 | 377 | |
| 378 | - if(!empty($property_data[P_METHOD_INJECT]) && is_callable(array($this, $property_data[P_METHOD_INJECT]))) { |
|
| 378 | + if (!empty($property_data[P_METHOD_INJECT]) && is_callable(array($this, $property_data[P_METHOD_INJECT]))) { |
|
| 379 | 379 | call_user_func_array(array($this, $property_data[P_METHOD_INJECT]), array(&$array)); |
| 380 | 380 | continue; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | // Skipping properties which have no corresponding field in DB |
| 384 | - if(empty($property_data[P_DB_FIELD])) { |
|
| 384 | + if (empty($property_data[P_DB_FIELD])) { |
|
| 385 | 385 | continue; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | // Checking - is property was adjusted or changed |
| 389 | - if($isUpdate && array_key_exists($property_name, $this->propertiesAdjusted)) { |
|
| 389 | + if ($isUpdate && array_key_exists($property_name, $this->propertiesAdjusted)) { |
|
| 390 | 390 | // For adjusted property - take value from propertiesAdjusted array |
| 391 | 391 | // TODO - differ how treated conversion to string for changed and adjusted properties |
| 392 | 392 | $value = $this->propertiesAdjusted[$property_name]; |
@@ -416,17 +416,17 @@ discard block |
||
| 416 | 416 | */ |
| 417 | 417 | protected function isFieldChanged($fieldName) { |
| 418 | 418 | $isFieldChanged = false; |
| 419 | - foreach($this->propertiesChanged as $propertyName => $cork) { |
|
| 419 | + foreach ($this->propertiesChanged as $propertyName => $cork) { |
|
| 420 | 420 | $propertyScheme = static::$_properties[$propertyName]; |
| 421 | - if(!empty($propertyScheme[P_DB_FIELDS_LINKED])) { |
|
| 422 | - foreach($propertyScheme[P_DB_FIELDS_LINKED] as $linkedFieldName) { |
|
| 423 | - if($linkedFieldName == $fieldName) { |
|
| 421 | + if (!empty($propertyScheme[P_DB_FIELDS_LINKED])) { |
|
| 422 | + foreach ($propertyScheme[P_DB_FIELDS_LINKED] as $linkedFieldName) { |
|
| 423 | + if ($linkedFieldName == $fieldName) { |
|
| 424 | 424 | $isFieldChanged = $propertyName; |
| 425 | 425 | break 2; |
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | - if(!empty($propertyScheme[P_DB_FIELD]) && $propertyScheme[P_DB_FIELD] == $fieldName) { |
|
| 429 | + if (!empty($propertyScheme[P_DB_FIELD]) && $propertyScheme[P_DB_FIELD] == $fieldName) { |
|
| 430 | 430 | $isFieldChanged = $propertyName; |
| 431 | 431 | break; |
| 432 | 432 | } |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | $fields = implode(',', array_keys($field_set)); |
| 449 | 449 | |
| 450 | 450 | $result = 0; |
| 451 | - if(classSupernova::db_query("INSERT INTO `{{" . static::$_table . "}}` ({$fields}) VALUES ({$values});")) { |
|
| 451 | + if (classSupernova::db_query("INSERT INTO `{{".static::$_table."}}` ({$fields}) VALUES ({$values});")) { |
|
| 452 | 452 | $result = db_insert_id(); |
| 453 | 453 | } |
| 454 | 454 | |
@@ -466,13 +466,13 @@ discard block |
||
| 466 | 466 | sn_db_field_set_safe_flag_clear($field_set); |
| 467 | 467 | |
| 468 | 468 | $set = array(); |
| 469 | - foreach($field_set as $fieldName => $value) { |
|
| 470 | - if(!($changedProperty = $this->isFieldChanged($fieldName))) { |
|
| 469 | + foreach ($field_set as $fieldName => $value) { |
|
| 470 | + if (!($changedProperty = $this->isFieldChanged($fieldName))) { |
|
| 471 | 471 | continue; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | // TODO - separate sets from adjusts |
| 475 | - if(array_key_exists($changedProperty, $this->propertiesAdjusted)) { |
|
| 475 | + if (array_key_exists($changedProperty, $this->propertiesAdjusted)) { |
|
| 476 | 476 | $value = "`{$fieldName}` + ($value)"; // braces for negative values |
| 477 | 477 | } |
| 478 | 478 | |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | return empty($set_string) |
| 486 | 486 | ? true |
| 487 | - : classSupernova::db_query("UPDATE `{{" . static::$_table . "}}` SET {$set_string} WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId); |
|
| 487 | + : classSupernova::db_query("UPDATE `{{".static::$_table."}}` SET {$set_string} WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | } |
@@ -39,19 +39,19 @@ |
||
| 39 | 39 | |
| 40 | 40 | @$this->link = mysqli_connect($settings['server'], $settings['user'], $settings['pass'], $settings['name']); |
| 41 | 41 | if (!is_object($this->link) || $this->link->connect_error) { |
| 42 | - classSupernova::$debug->error_fatal('DB Error - cannot connect to server error #' . $this->link->connect_errno, $this->link->connect_error); |
|
| 42 | + classSupernova::$debug->error_fatal('DB Error - cannot connect to server error #'.$this->link->connect_errno, $this->link->connect_error); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | !$this->mysql_query("/*!40101 SET NAMES 'utf8' */") |
| 47 | - ? classSupernova::$debug->error_fatal('DB error - cannot set names 1 error #' . $this->link->errno, $this->link->error) |
|
| 47 | + ? classSupernova::$debug->error_fatal('DB error - cannot set names 1 error #'.$this->link->errno, $this->link->error) |
|
| 48 | 48 | : false; |
| 49 | 49 | !$this->mysql_query("SET NAMES 'utf8';") |
| 50 | - ? classSupernova::$debug->error_fatal('DB error - cannot set names 2 error #' . $this->link->errno, $this->link->error) |
|
| 50 | + ? classSupernova::$debug->error_fatal('DB error - cannot set names 2 error #'.$this->link->errno, $this->link->error) |
|
| 51 | 51 | : false; |
| 52 | 52 | |
| 53 | - !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';') |
|
| 54 | - ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level error #' . $this->link->errno, $this->link->error) |
|
| 53 | + !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL '.self::DB_MYSQL_TRANSACTION_REPEATABLE_READ.';') |
|
| 54 | + ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level error #'.$this->link->errno, $this->link->error) |
|
| 55 | 55 | : false; |
| 56 | 56 | |
| 57 | 57 | $this->connected = true; |