Support » Plugin: JSON Content Importer » Coordinate from current product

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author berkux

    (@berkux)

    Hi riccardocrosa,

    the question is how we get lat & long from the database.

    When loadinf a product-page lat/long should be available in any way to insert it into the shortcode which lookd like this:
    [jsoncontentimporter url=https://api.openweathermap.org/data/2.5/weather?lat=geo_latitude&lon=geo_longitude&appid=MY_API_ID&units=metric&lang=it]something[/jsoncontentimporter]

    The placeholders for geo_longitude must be replaced by the values of the page.

    Do you have any idea how Geo Mashup stores and provides lat/long on a page?

    Bernhard

    Thread Starter riccardocrosa

    (@riccardocrosa)

    Thank you Bernhard,
    I’ve found this
    https://github.com/cyberhobo/wordpress-geo-mashup/wiki/Tag-Reference#post-coordinates
    and this
    https://github.com/cyberhobo/wordpress-geo-mashup/issues/134

    And I’ve tried to put in place this code

    [jsoncontentimporter url=https://api.openweathermap.org/data/2.5/weather?<?php if (function_exists(‘geo_mashup_map’)) $coords =
    GeoMashup::post_coordinates(); if ($coords) { echo
    ‘<span>lat=’ . $coords[‘lat’] .
    ‘&lon=’ . $coords[‘lng’] .
    ‘</span>’; } ?>&appid=MY_API_ID&units=metric&lang=it] Meteo ubicazione: {name} {subloop:main:-1}{main.temp} °C {/subloop:main} {subloop-array:weather:-1} {weather.description} {/subloop-array:weather}  [/jsoncontentimporter]

    but don’t works.
    Have some ideas?
    Thanks
    Riccardo

    Plugin Author berkux

    (@berkux)

    Hi Riccardo,

    ok, this should be a way. Direct PHP in the template or using a plugin like
    https://de.wordpress.org/plugins/php-everywhere/
    to be able to execute PHP.

    Add debugmode=10 and check the used url to see if the PHP is really executed.
    If you see something like PHP code you might use the PHP-everywhere (or another) plugin to be able to use PHP on this level.

    Bernhard

    Thread Starter riccardocrosa

    (@riccardocrosa)

    Hi Bernhard,
    thanks for your reply.
    So, I made some test with the code

    1) code
    [jsoncontentimporter url=https://api.openweathermap.org/data/2.5/weather?lat=44.9810638&lon=10.0421553&appid=MY_API_CODE&units=metric&lang=it] Ubicazione: {name} {subloop:main:-1}{main.temp} °C {/subloop:main} {subloop-array:weather:-1} {weather.description} {/subloop-array:weather} [/jsoncontentimporter]

    page show: Ubicazione: Busseto 24.78 °C cielo sereno

    2) code
    https://api.openweathermap.org/data/2.5/weather?[php_everywhere]&appid=MY_API_CODE&units=metric&lang=it

    with php
    <?php if (function_exists('geo_mashup_map')) $coords = GeoMashup::post_coordinates(); if ($coords) { echo 'lat=' . $coords['lat'] . '&lon=' . $coords['lng'] ; } ?>

    page show a valid URL: https://api.openweathermap.org/data/2.5/weather?lat=44.9810638&lon=10.0421553&appid=MY_API_CODE&units=metric&lang=it

    3) code

    [jsoncontentimporter url=https://api.openweathermap.org/data/2.5/weather?[php_everywhere]&appid=5b2810e06f7abcaa01fc2de6569918ce&units=metric&lang=it debugmode=10] Ubicazione: {name} {subloop:main:-1}{main.temp} °C {/subloop:main} {subloop-array:weather:-1} {weather.description} {/subloop-array:weather} 
     [/jsoncontentimporter]

    with php
    <?php if (function_exists('geo_mashup_map')) $coords = GeoMashup::post_coordinates(); if ($coords) { echo 'lat=' . $coords['lat'] . '&lon=' . $coords['lng'] ; } ?>

    page show: &appid=MY_API_CODE&units=metric&lang=it debugmode=10] Ubicazione: °C

    it seems that the code is cut perhaps because one shortcode contains another shortcode.
    Any idea?

    Thank you
    Riccardo

    Plugin Author berkux

    (@berkux)

    First: Edit your post and remove the appid token

    Thread Starter riccardocrosa

    (@riccardocrosa)

    Hello Bernhard,
    I saw that, but I can’t edit the posts (the system don’t show me the edit link) so I cancelled the token on openweathermap.
    I thought was to create the url of example 2 that is created correctly and copy it into your plugin.
    I can’t find the way to build the code.
    Thanks
    Riccardo

    Plugin Author berkux

    (@berkux)

    Hi,

    I did some research: https://www.reiseliste.de/aa-test-geo-mashup/

    try this:
    In the sidebar should be a textarea for “PHP Everywhere”.
    Put this into that:

    <?php echo do_shortcode(“[jsoncontentimporter debugmode=10 url=https://api.openweathermap.org/data/2.5/weather?LATLON=”.time().”&appid=MY_API_CODE&units=metric&lang=it] Ubicazione: {name} {subloop:main:-1}{main.temp} °C {/subloop:main} {subloop-array:weather:-1} {weather.description} {/subloop-array:weather} [/jsoncontentimporter]”); ?>

    Then place
    [php_everywhere]
    in the usual textare.
    Then [php_everywhere] should execute the PHP code defined in the textarea.
    There do_shortcode executes the jsoncontentimporter-Shortcode, where you can put some PHP to define the URL. Here just “time()”…

    Bernhard

    • This reply was modified 1 year, 4 months ago by berkux.
    Thread Starter riccardocrosa

    (@riccardocrosa)

    Hello Bernhard,
    I did some tests with PHP everywhere, but since the php code should be in the right column of the backend of each product, I thought to use a plugin that reserves to the administrator the view of the code, avoiding that anyone (vendors) must insert it, see it or modify it.

    https://it.wordpress.org/plugins/insert-php/

    So, with this code in a shortcode the system works fine

    <?php echo do_shortcode('[jsoncontentimporter url=https://api.openweathermap.org/data/2.5/weather?lat=45&lon=7&appid=MY_APP_ID&units=metric&lang=it] Ubicazione: {name} {subloop:main:-1}{main.temp} °C {/subloop:main} {subloop-array:weather:-1} {weather.description} {/subloop-array:weather} [/jsoncontentimporter]'); ?>

    But problem remains the usual when I try to insert in the middle of the URL that invokes the Openweathermap API the php code that gets the coordinates of the product on the fly

    <?php if (function_exists('geo_mashup_map')) $coords = GeoMashup::post_coordinates(); if ($coords) { echo 'lat=' . $coords['lat'] . '&lon=' . $coords['lng'] ; } ?>

    and the system breaks the URL making visible only the second part with an error.
    I’m blocked on a single row of code!
    Thank you,
    Riccardo

    Plugin Author berkux

    (@berkux)

    What if you put all in 1, like:

    
    <?php 
    $lat =1;
    $lon =2;
    if (function_exists('geo_mashup_map')) {
    $coords = GeoMashup::post_coordinates(); 
    if ($coords) { $lat= $coords['lat']; $lon = $coords['lng'] ; }
    }
    $url = "https://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&appid=MY_APP_ID&units=metric&lang=i";
    $sc = '[jsoncontentimporter url='.$url.'] Ubicazione: {name} {subloop:main:-1}{main.temp} °C {/subloop:main} {subloop-array:weather:-1} {weather.description} {/subloop-array:weather} [/jsoncontentimporter]';
    
    echo do_shortcode($sc); 
    ?>
    

    Bernhard

    • This reply was modified 1 year, 4 months ago by berkux.
    Thread Starter riccardocrosa

    (@riccardocrosa)

    Hello Bernhard,
    Great! I wouldn’t have gotten there on my own. Now it works like a charm.
    You will see the result when it is online in the next few days at http://www.mirada.online
    I wanted to ask you if you can tell me about free APIs like Openweathermap that have to do with consumers’ buying habits, vehicular traffic (I saw opendata, Yelp and google) but maybe you have more experience having written a plugin that processes the response of these APIs.
    Thanks and have a nice day
    Riccardo

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Coordinate from current product’ is closed to new replies.