示例#1
0
            if (preg_match('/№([0-9]+)<.*Поштова адреса ОВК<\\/td>\\n<td class=td2  >(.*)</Uims', iconv('windows-1251', 'utf-8', $district), $district)) {
                $address = $district[2];
                $location = _json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . rawurlencode($address) . '&sensor=false'));
                if ($location['status'] == 'OK') {
                    $location = $location['results'][0]['geometry']['location'];
                    call_user_func_array([$Precincts, 'add'], [$district[1], $address, $location['lat'], $location['lng'], 0]);
                }
            }
        }
        unset($districts, $district, $address, $location);
    }
    unset($regions, $region);
    $Precincts->db_prime()->q("INSERT INTO `[prefix]precincts` (`id`, `number`, `address_uk`, `address_en`, `address_ru`, `lat`, `lng`, `district`, `violations`) VALUES (NULL, '0', '01196, м.Київ, площа Лесі Українки, 1, 2-й поверх, хол прес-центру ЦВК', '1196, Kyiv, Lesi Ukrainky square 1, 2nd Floor, Hall Press Center CEC', '01196, г.Киев, площадь Леси Украинки, 1, 2-й этаж, холл пресс-центра ЦИК', '50.428073', '30.541399', '0', '0')");
}
if (isset($_POST['update_addresses'])) {
    time_limit_pause();
    $Precincts = Precincts::instance();
    $all_precincts = $Precincts->get_all();
    $cdb = $Precincts->db_prime();
    foreach ($all_precincts as $p) {
        if ($cdb->qfs("SELECT `address_en` FROM `[prefix]precincts` WHERE `id` = {$p}")) {
            continue;
        }
        $p = $Precincts->get($p);
        $en_address = _json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . rawurlencode($p['address']) . '&sensor=false&language=en'));
        if ($en_address['status'] == 'OK') {
            $cdb->q("UPDATE `[prefix]precincts`\n\t\t\t\tSET `address_en` = '%s'\n\t\t\t\tWHERE `id` = '%s'", $en_address['results'][0]['formatted_address'], $p['id']);
        }
        unset($en_address);
        $ru_address = _json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . rawurlencode($p['address']) . '&sensor=false&language=ru'));
        if ($ru_address['status'] == 'OK') {
示例#2
0
 /**
  * Moves an uploaded file to a new location
  *
  * @abstract
  *
  * @see move_uploaded_file()
  *
  * @param string	$filename
  * @param string	$destination
  *
  * @return bool
  */
 function move_uploaded_file($filename, $destination)
 {
     $temp = md5(uniqid(microtime(true)));
     while (file_exists(TEMP . "/{$temp}")) {
         $temp = md5(uniqid(microtime(true)));
     }
     time_limit_pause();
     if (move_uploaded_file($filename, TEMP . "/{$temp}") === false) {
         time_limit_pause(false);
         return false;
     }
     time_limit_pause(false);
     return $this->request(['function' => __FUNCTION__, 'filename' => Config::instance()->base_url() . "/{$temp}", 'destination' => $destination])[1] && unlink(TEMP . "/{$temp}");
 }
示例#3
0
             if (isset($module_data['db']) && file_exists("{$module_dir}/meta/db.json")) {
                 $db_json = file_get_json("{$module_dir}/meta/db.json");
                 time_limit_pause();
                 foreach ($db_json as $database) {
                     if ($module_data['db'][$database] == 0) {
                         $db_type = $Core->db_type;
                     } else {
                         $db_type = $Config->db[$module_data['db'][$database]]['type'];
                     }
                     $sql_file = "{$module_dir}/meta/update_db/{$database}/{$version}/{$db_type}.sql";
                     if (file_exists($sql_file)) {
                         $db->{$module_data['db'][$database]}()->q(explode(';', file_get_contents($sql_file)));
                     }
                 }
                 unset($db_json, $database, $db_type, $sql_file);
                 time_limit_pause(false);
             }
         }
     }
     unset($old_version);
 }
 unlink(DIR . '/core/fs_old.json');
 unlink("{$module_dir}/meta_old.json");
 /**
  * Restore previous site mode
  */
 if ($site_mode) {
     $Config->core['site_mode'] = 1;
 }
 $a->save();
 clean_pcache();
示例#4
0
 /**
  * Sending of api request to the specified host
  *
  * @param string	$url	With prefix <i>https://</b> (<i>http://</b> can be missed), and (if necessary) with port address
  * @param mixed		$data	Any type of data, will be accessible through <i>$_POST['data']</b>
  *
  * @return bool|string		Result or <i>false</i> at error
  */
 protected function send($url, $data)
 {
     if (!Config::instance(true)) {
         return false;
     }
     $Key = Key::instance();
     $protocol = 'http';
     if (mb_strpos($url, '://') !== false) {
         list($protocol, $url) = explode('://', $url);
     }
     $database = Config::instance()->module('System')->db('keys');
     $key = $Key->generate($database);
     $url .= "/{$key}";
     $Key->add($database, $key, ['url' => $url], time() + 30);
     list($host, $url) = explode('/', $url, 2);
     $host = explode(':', $host);
     $socket = fsockopen($host[0], isset($host[1]) ? $host[1] : $protocol == 'http' ? 80 : 443, $errno, $errstr);
     $host = implode(':', $host);
     if (!is_resource($socket)) {
         trigger_error("#{$errno} {$errstr}", E_USER_WARNING);
         return false;
     }
     $data = 'data=' . urlencode(json_encode($data));
     time_limit_pause();
     fwrite($socket, "POST /{$url} HTTP/1.1\r\n" . "Host: {$host}\r\n" . "Content-Type: application/x-www-form-urlencoded\r\n" . "Content-length:" . strlen($data) . "\r\n" . "Accept:*/*\r\n" . "User-agent: CleverStyle CMS\r\n\r\n" . "{$data}\r\n\r\n");
     $return = explode("\r\n\r\n", stream_get_contents($socket), 2);
     time_limit_pause(false);
     fclose($socket);
     return $return[1];
 }