get real g.co url - google-maps

I got on my DB, allot like this urls
http://g.co/maps/8s4th
but i need to get the real googlpe maps address so i can embed it. Someone ha any idea how to do this?
i need the real one
http://maps.google.com.mx/maps?q=monterrey&hl=es&ie=UTF8&sll=23.625269,-102.540613&sspn=26.141296,41.616211&hnear=Monterrey,+Nuevo+León&t=h&z=12

Do a GET to the g.co, look at the Location: in the 301 response you receive.

Well obviously with ajax I CAN'T, but i do it with PHP i leave the code i hope it help
<?
$url = "http://g.co/maps/rdu3e";
$response = get_headers($url, 1);
print_r($response['Location']);
?>

Related

Save disk on google disk

I need to store file from Storage::disk('local') to Storage::disk('google')
I try next code, but not working
$file = \File::get(storage_path('my/file.docx'));
\Storage::disk('google')->put($path, $file);
if I receive it from request, it work
\Storage::disk('google')->put($path, $request->file);
Can somebody help me. Thanks
This is response for my question
\Storage::disk('google')->putFile($path, new File(storage_path('file.docx')), 'file.docx');

Does wp_cache still load Wordpress and use MySQL?

I have a JSON API endpoint that uses wp_cache_set/wp_cache_get to store the result. This endpoint is hit hundreds of thousands of times in a day.
However this often takes down my server as it seems the cache is still accessing MySQL and/or loading Wordpress.
Is this true? And if so what would be a better caching solution to make this as light as possible? (eg. memcached)
--
Here's code in case that's helpful:
define('WP_USE_THEMES', false);
require_once('../../../wp-blog-header.php');
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
if(!$image_url) $image_url = $_GET['url'];
if(!$image_url) return false;
$cacheTitle = md5($image_url) . '1';
$result = wp_cache_get( $cacheTitle );
$notCached = $result ? false : true;
if ($notCached){
/** Insert code here to get the data I need and store it in $result **/
wp_cache_set( $cacheTitle, $result );
}
return json_encode($result);
I ended up using Cloudflare Page Rules to cache that specific URL. Clean and easy :)
You're using caching routines within WP that are designed to save you repeating db queries and other expensive operations. So you're saving repeating your md5 but you're still running WP for every page load.
So, yes, to avoid the hit of running WP each time you do need some kind of page cache. Personally I've been using the w3totalcache plugin which has worked well. My next step will likely be a move to Varnish, but there are a few choices out there.

Wordpress Jetpack Json API not working

i'm trying to use Json API from Jetpack, but when i make the call i only get this:
{"error":"unknown_blog","message":"Unknown blog"}
I'm trying this: https://public-api.wordpress.com/rest/v1.1/sites/clasari.com/wp/posts/
The blog is hosted at wp folder (inside clasari.com) solo the blog url is clasari.com/wp, i guess that can be a problem.
I've also tried
https://public-api.wordpress.com/rest/v1.1/sites/clasari.com::wp/posts/
but it has the same result.
Any idea of what can be this problem? Thank you for your help
You need to use urlencode, like this:
$url = 'clasari.com/wp';
$url = url_encode( $url );
$request =
'https://public-api.wordpress.com/rest/v1.1/sites/' .
$url .
'/posts/';

PHP echo content of HTML page not working correctly

I am trying to use the following php code to display another html page. Sadly nothing is printed on the screen, and yes I have checked and confirmed that the link works. Any thoughts on why this could be happening would be helpful thank you.
$site = readfile("http://k9minecraft.tk/thanks.html");
echo $site;
First, make sure php is configured so that allow_url_fopen is on.
If you want to save the string to a variable, try using file_get_contents instead since it adds the file to memory. Refer file_get_contents for more detailed information on official documentation.
$site = file_get_contents("http://k9minecraft.tk/thanks.html");
echo $site;
The readfile function reads the file directly to the output buffer, so it doesn't require an echo. Refer readfile for more detailed information on official documentation.
readfile("http://k9minecraft.tk/thanks.html");
readfile is more efficient in terms of memory usage, whereas file_get_contents more useful in many situations.
<?php
//other php codes here
?>
Link Name
<?php
//continue other php codes.
?>
how about that ? Without using readfile.
readfile() actually returns just the number of characters read from the file. The content of the file is stored in buffer.
Turn output buffering OFF.
Use something like ob_end_flush
Check this too...It may help you

Google Maps Geocoding XML service returns error via Curl when city name with more than 1 word is used

I am using the following Google Maps Geocoding service via a php script
http://maps.googleapis.com/maps/api/geocode/xml?address=
I have already tried curl and file_get_contents but none of them worked. The problem is when I use city name with one word it works but when I use city name with two words then I do not get anything back from the service but the following error
That’s an error.
Your client has issued a malformed or illegal request. That’s all we know.
Below is some code snippet from the script
$city = $_GET["c"];
$url="http://maps.googleapis.com/maps/api/geocode/xml?address=$city&sensor=false";
$data = curl_download($url);
//$data = file_get_contents($url);
echo $data;
I have also uploaded the script to the location below
01)http://www.javeria.com/sites/travel/map/googlemap.php?c=Houston (works)
02)http://www.javeria.com/sites/travel/map/googlemap.php?c=New+York (does not work)
When invoked with 02) it won't display the map instead I am masking the error to display a user friendly message.
I would appreciate any help into this matter.
Try using + between the words. I am doing essentially the same thing - and that change makes it work for me.