/** * get geocode lat/lon points for given address from google * * @param string $address * @return bool|array false if can't be geocoded, array or geocdoes if successful */ public static function address_coords($address) { $url = 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=' . rawurlencode($address); //try to get the json from the cache $coords = Core::cache($url); //not cached :( if ($coords === NULL) { $coords = FALSE; //get contents from google if ($result = core::curl_get_contents($url)) { $result = json_decode($result); //not found :() if ($result->status != "OK") { $coords = FALSE; } else { $coords['lat'] = $result->results[0]->geometry->location->lat; $coords['lon'] = $result->results[0]->geometry->location->lng; } } //save the json Core::cache($url, $coords, strtotime('+7 day')); } return $coords; }
/** * get geocode lat/lon points for given address from google * * @param string $address * @return bool|array false if can't be geocoded, array or geocdoes if successful */ public function action_get_ads_latlgn() { $ads = new Model_Ad(); $ads = $ads->where('latitude', 'IS', NULL)->where('longitude', 'IS', NULL)->where('address', 'IS NOT', NULL)->where('address', '!=', '')->find_all(); foreach ($ads as $ad) { $url = 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=' . urlencode($ad->address); //get contents from google if ($result = core::curl_get_contents($url)) { $result = json_decode($result); if ($result and $result->status == "OK") { $ad->latitude = $result->results[0]->geometry->location->lat; $ad->longitude = $result->results[0]->geometry->location->lng; try { $ad->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } } Alert::set(Alert::SUCCESS, __('Successfully imported latitude and longitude info from your ads.')); $this->redirect(Route::url('oc-panel', array('controller' => 'import', 'action' => 'csv'))); }
/** * returns array of last versions from json * @return array */ public static function versions() { return json_decode(core::curl_get_contents('http://open-classifieds.com/files/versions.json?r=' . time()), TRUE); }
public static function download($l) { $api_url = Kohana::$environment !== Kohana::DEVELOPMENT ? 'market.' . Core::DOMAIN : 'eshop.lo'; $download_url = 'http://' . $api_url . '/api/download/' . $l . '/?domain=' . parse_url(URL::base(), PHP_URL_HOST); $fname = DOCROOT . 'themes/' . $l . '.zip'; //root folder $file_content = core::curl_get_contents($download_url); if ($file_content != 'false') { // saving zip file to dir. file_put_contents($fname, $file_content); $zip = new ZipArchive(); if ($zip_open = $zip->open($fname)) { //if theres nothing in that ZIP file...zip corrupted :( if ($zip->getNameIndex(0) === FALSE) { return FALSE; } $theme_name = substr($zip->getNameIndex(0), 0, -1); $zip->extractTo(DOCROOT . 'themes/'); $zip->close(); unlink($fname); return $theme_name; } } return FALSE; }
/** * STEP 1 * Downloads and extracts latest version */ public function action_latest() { //save in a session the current version so we can selective update the DB later Session::instance()->set('update_from_version', Core::VERSION); $versions = core::config('versions'); //loads OC software version array $last_version = key($versions); //get latest version $download_link = $versions[$last_version]['download']; //get latest download link $update_src_dir = DOCROOT . 'update'; // update dir $file_name = $update_src_dir . '/' . $last_version . '.zip'; //full file name //check if exists already the download, if does delete if (file_exists($file_name)) { unlink($file_name); } //create update dir if doesnt exists if (!is_dir($update_src_dir)) { mkdir($update_src_dir, 0775); } //verify we could get the zip file $file_content = core::curl_get_contents($download_link); if ($file_content == FALSE) { Alert::set(Alert::ALERT, __('We had a problem downloading latest version, try later please.')); $this->redirect(Route::url('oc-panel', array('controller' => 'update', 'action' => 'index'))); } //Write the file file_put_contents($file_name, $file_content); //unpack zip $zip = new ZipArchive(); // open zip file, and extract to dir if ($zip_open = $zip->open($file_name)) { $zip->extractTo($update_src_dir); $zip->close(); } else { Alert::set(Alert::ALERT, $file_name . ' ' . __('Zip file failed to extract, please try again.')); $this->redirect(Route::url('oc-panel', array('controller' => 'update', 'action' => 'index'))); } //delete downloaded file unlink($file_name); //move files in different request so more time $this->redirect(Route::url('oc-panel', array('controller' => 'update', 'action' => 'files'))); }
/** * returns array of last versions from json * @return array */ public static function versions() { return json_decode(core::curl_get_contents('https://raw.githubusercontent.com/yclas/yclas/master/versions.json?t=' . time()), TRUE); }