Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.59 KB | None | 0 0
  1.         if (!$info && count($words) > 1) {
  2.             for ($z = 0; $z < 3; $z++) {
  3.                 for ($i = 0; $i < count($words); $i++) {
  4.                     for ($k = count($words) - 1; $k >= 0; $k--) {
  5.                         if (($z == 0 && (!(isset($info['country_id']) && $info['country_id']) ||
  6.                                     (
  7.                                         isset($info['country_id']) && $info['country_id'] &&
  8.                                         isset($info['city_id']) && $info['city_id'])
  9.                                 )
  10.                             ) ||
  11.                             ($z == 1 && !(isset($info['region_id']) && $info['region_id'])) ||
  12.                             ($z == 2 && !(isset($info['city_id']) && $info['city_id']))
  13.                         ) {
  14.                             $search_arr = [];
  15.                             $separators = [' ', '-'];
  16.                             foreach ($separators as $sep) {
  17.                                 if (($str_item = implode($sep, array_slice($words, $i, $k - $i + 1)))) {
  18.                                     $search_arr[$str_item] = 1;
  19.                                 }
  20.                             }
  21.                             foreach (array_keys($search_arr) as $name) {
  22.                                 if (!$z && (
  23.                                         // Страна не найдена
  24.                                         (!(isset($info['country_id']) && $info['country_id'])) ||
  25.                                         // Страна найдена в исключениях - пробуем еще
  26.                                         (
  27.                                             isset($info['country_id']) && $info['country_id'] &&
  28.                                             isset($info['city_id']) && $info['city_id']
  29.                                         )
  30.                                     )
  31.                                 ) {
  32.                                     if (($info1 = $obj->getCountry($name, 1))) {
  33.                                         $info = $info1;
  34.                                     }
  35.                                 } elseif ($z == 1) {
  36.                                     // Регион приоритетнее страны, поэтому не проверем соответсвте страна => регион
  37.                                     if (($info3 = $obj->getRegion($name)) &&
  38.                                         isset($info3['region_id']) && $info3['region_id']
  39.                                     ) {
  40.                                         $info = $info3;
  41.                                     }
  42.                                 } elseif ($z == 2) {
  43.                                     $info2 = $obj->getCity(
  44.                                         $name,
  45.                                         isset($info['country_id']) ? $info['country_id'] : 0,
  46.                                         isset($info['region_id']) ? $info['region_id'] : 0
  47.                                     );
  48.                                     if ($info2 && isset($info2['country_id']) &&
  49.                                         isset($info2['city_id']) && $info2['city_id'] &&
  50.                                         (isset($info['country_id']) ? ($info['country_id'] == $info2['country_id']) : 1)
  51.                                     ) {
  52.                                         $info = $info2;
  53.                                     }
  54.                                 }
  55.                             }
  56.                         }
  57.                     }
  58.                 }
  59.             }
  60.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement