public function getGeoByIp() { $cached_geo = cmsUser::sessionGet('geo_data'); if ($cached_geo) { return $cached_geo; } $out = simplexml_load_string(file_get_contents_from_url('http://ipgeobase.ru:7020/geo?ip=' . cmsUser::getIp())); $data = array(); if ($out && is_object($out) && !empty($out->ip[0])) { foreach ($out->ip[0] as $key => $value) { $data[$key] = (string) $value; } } $geo = array('city' => array('id' => null, 'name' => null), 'country' => array('id' => null, 'name' => null)); if (isset($data['country'])) { $geo['country'] = $this->model->getItemByField('geo_countries', 'alpha2', $data['country']); } if (isset($data['city'])) { if (!empty($geo['country']['id'])) { $this->model->filterEqual('country_id', $geo['country']['id']); } $geo['city'] = $this->model->getItemByField('geo_cities', 'name', $data['city']); } cmsUser::sessionSet('geo_data', $geo); return $geo; }
public function getUpdateFileContents($current_version, $only_cached) { if (file_exists($this->cache_file)) { return file_get_contents($this->cache_file); } else { if ($only_cached) { return false; } } $url = sprintf($this->update_info_url, $current_version); $data = file_get_contents_from_url($url); if ($data === false) { return false; } file_put_contents($this->cache_file, $data); return $data; }
public function getUpdateFileContents($current_version, $only_cached) { if (function_exists('gethostbyname')) { if (gethostbyname(parse_url($this->update_info_url, PHP_URL_HOST)) !== '176.9.155.142') { return false; } } if (file_exists($this->cache_file)) { return file_get_contents($this->cache_file); } else { if ($only_cached) { return false; } } $url = sprintf($this->update_info_url, $current_version); $data = file_get_contents_from_url($url); if ($data === false) { return false; } file_put_contents($this->cache_file, $data); return $data; }
public function uploadFromLink($post_filename, $allowed_ext = false, $allowed_size = 0, $destination = false) { $dest_ext = strtolower(pathinfo(parse_url(trim($_POST[$post_filename]), PHP_URL_PATH), PATHINFO_EXTENSION)); $dest_name = files_sanitize_name($_POST[$post_filename]); if (!$this->checkExt($dest_ext, $allowed_ext)) { return array('error' => LANG_UPLOAD_ERR_MIME, 'success' => false, 'name' => $dest_name); } $file_bin = file_get_contents_from_url($_POST[$post_filename]); if (!$file_bin) { return array('success' => false, 'error' => LANG_UPLOAD_ERR_PARTIAL, 'name' => $dest_name, 'path' => ''); } $image_size = strlen($file_bin); if ($allowed_size) { if ($image_size > $allowed_size) { return array('error' => sprintf(LANG_UPLOAD_ERR_INI_SIZE, files_format_bytes($allowed_size)), 'success' => false, 'name' => $dest_name); } } $dest_file = substr(md5(uniqid() . microtime(true)), 0, 8) . '.' . $dest_ext; if (!$destination) { cmsUser::getInstance()->increaseFilesCount(); $destination = $this->getUploadDestinationDirectory() . '/' . $dest_file; } else { $destination = cmsConfig::get('upload_path') . $destination . '/' . $dest_file; } $f = fopen($destination, 'w+'); fwrite($f, $file_bin); fclose($f); return array('success' => true, 'path' => $destination, 'url' => str_replace(cmsConfig::get('upload_path'), '', $destination), 'name' => $dest_name, 'size' => $image_size); }