Hi,

On Drupal 5.12, I have installed the latest feedapi (10 november 2008), which should support location mapper, right?
I have installed latest location and gmap module.
And I have installed http://drupal.org/node/265196#comment-1073099 (the feedapi_mapper_location).

When I add one location to a feedapi nodetype I do not see the location mapper.
I see the taxonomy mapper.
Do I do something wrong?

Thanks a lot in advance for your support!

Greetings,
Martijn

CommentFileSizeAuthor
#11 mapping_country.jpg121.87 KBsummit
#1 location_mapper_country_map.jpg145.39 KBsummit

Comments

summit’s picture

Category: support » bug
StatusFileSize
new145.39 KB

Hi,

The patch on http://drupal.org/node/265196#comment-1073099 worked for me on Drupal 5 as to that effect that I got the location_mapper showing on the parent-feed. The missing part was that I also needed to enable location info on the feed-item nodes on which the feed is mapped to.

I added the underneath lines to the patch so that country, province, city, street and postal_code info is included.

 else if ($op == 'list') {
      $sub_fields['country'] = 'country';
      $sub_fields['province'] = 'province';
      $sub_fields['city'] = 'city';
      $sub_fields['street'] = 'street';
      $sub_fields['postal_code'] = 'postal_code';
      $sub_fields['latitude'] = 'Latitude';
      $sub_fields['longitude'] = 'Longitude';
      return $sub_fields;

See attached picture for mapping of the country field to Tag[2].
I would expect this info to be inserted in the location database table and on the location_country field on the specific nodes. But that is not the case.

Can somebody tell me what I do wrong maybe?
Thanks a lot in advance for your response!

Greetings,
Martijn

alex_b’s picture

Martijn, Without looking at this closer: Does this issue also concern Drupal 6?

summit’s picture

The answer is YES Alex.

Greetings,
Martijn

alex_b’s picture

I cannot test it on drupal 6, I do not have a drupal 6 site with feedapi configuration

Not a hard thing to come by ;-)

summit’s picture

Hi Alex,
testing also on Drupal 6 :)
I saw this code was added in the parser_simplepie.module also for drupal 6.

    // Location 
    $latitude = $simplepie_item->get_latitude();
    $longitude = $simplepie_item->get_longitude();
    if (!is_null($latitude) && !is_null($longitude)) {
      $curr_item->options->location->latitude[] = $latitude;
      $curr_item->options->location->longitude[] = $longitude;
    }

How does this need to be altered to also have also country, province, city, street and postal_code?
Are there also other changes I have to look for to alter the code to have the country, province, city, street and postal_code in the location table from feedapi?

greetings,
Martijn

alex_b’s picture

Category: bug » feature

How does this need to be altered to also have also country, province, city, street and postal_code

Where does this information sit on your feed? Does simplepie know about these properties? If not, there is no straightforward way to expose this information to the FeedAPI.

FeedAPI and Feed Element Mapper for Drupal 5 are rapidly receding into history, I'm really reluctant to add new features to them. So far the patches we're talking about are not very invasive - it should be easy for you to maintain a patched 5.x version for your project.

#3 - I assume that there is no bug that also affects Feed Element Mapper for 6 but this is only a feature request for 5.x - correct me if I'm wrong.

summit’s picture

Hi Alex.

Your remark Where does this information sit on your feed? Does simplepie know about these properties? If not, there is no straightforward way to expose this information to the FeedAPI.

The information sits on a productfeed which I can load into feedapi. What I would like is similar to the lat/lon fields, only it effects the other feeds from location: country, province, city, street and postal_code, so I can map my feed fields to these on location_mapper (likewise taxonomy_mapper).

I am fine if you add those only to D6, I will then myself maintain a D5 version. Off course I understand D6 is the way forward! I set this then as feature request for D6.

Thanks a lot in advance going into this.

Greetings,
Martijn

summit’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev

Hi Alex,

Will not open http://drupal.org/node/265196. Thanks for getting lat/lon in.
Please also bring the other location fields in:

      $sub_fields['country'] = 'country';
      $sub_fields['province'] = 'province';
      $sub_fields['city'] = 'city';
      $sub_fields['street'] = 'street';
      $sub_fields['postal_code'] = 'postal_code';

I do not know how to code the stuff in parser_simplepie.module to get this in. Present code:

// Location 
    $latitude = $simplepie_item->get_latitude();
    $longitude = $simplepie_item->get_longitude();
    if (!is_null($latitude) && !is_null($longitude)) {
      $curr_item->options->location->latitude[] = $latitude;
      $curr_item->options->location->longitude[] = $longitude;
    }

Please help me so I can map my feed fields to country, province, city, street and postal_code on location_mapper (likewise taxonomy_mapper).
Thanks a lot in advance!

Greetings,
Martijn

summit’s picture

Title: Feedapi_mapper_location on Drupal 5? » Feedapi_mapper_location country, province, city, street and postal_code fields

Guys, Alex is to bussy with great other work.
Anyone can help get this roaling?

Thanks a lot in advance!
Greetings,
Martijn

summit’s picture

Hi,

I installed the patch http://drupal.org/comment/reply/316721/1115371#comment-1115371 to get the possibiltiy to get the other location information out of the feed. How now to I get other items mapped to the feed?
This is my add-on to simplepie_parser.module:

 $tags=array();
    $country = $tag[1]->term;
    $province = $tag[2]->term;
    $city = $tag[3]->term;
    $street =$tag[4]->term;
    #$latitude = $xmlfetch_item->get_latitude();
    #$longitude = $xmlfetch_item->get_longitude();
    #if (!is_null($latitude) && !is_null($longitude)) {
    #  $curr_item->options->location->latitude[] = $latitude;
    #  $curr_item->options->location->longitude[] = $longitude;
    #}
    if (!is_null($country)) {
      $curr_item->options->location->country[] = $country;
    }
    if (!is_null($province)) {
      $curr_item->options->location->province[]= $province;
    }
    if (!is_null($city)) {
      $curr_item->options->location->city[] = $city;
    }
    if (!is_null($street)) {
      $curr_item->options->location->street[] = $street;
    }

Greetings,
Martijn

summit’s picture

StatusFileSize
new121.87 KB

Hi,

This is my feed item example now:

Array
(
    [title] => Appartementen Dengg
    [description] => 

Appartementen Dengg

Leuke, comfortabele appartementen centraal in Mayrhofen.€ 679.00

    [options] => Array
        (
            [guid] => c6954c7df96bfc9765b6555a92fc0dbe
            [location] => Array
                (
                    [country] => Array
                        (
                            [0] => Frankrijk
                        )

                    [province] => Array
                        (
                            [0] => 
                        )

                    [city] => Array
                        (
                            [0] => 
                        )

                    [street] => Array
                        (
                            [0] => 
                        )

                )

            [tags] => Array
                (
                    [0] => Reizen
                    [1] => Vakanties
                    [2] => Wintersport
                )

        )

)

And this is my mapper screen now (see screenshot). country is from the location mapper country field as added on http://drupal.org/node/333519#comment-1107467

What I did:
Step 1) Install the location mapper from: http://drupal.org/node/265196#comment-1073099
Location mapper working ok
Step 2) Enhance location mapper with other location fields:
I see the other fields: country, province, city, street and postal_code in my mapper. So this step should be ok, right?
Step 3) Enhance simplepie_parser.module with the other location fields.

So feed data country should be mapped to location field country, right?
Whycan I only see one tag in the mapping screen?
Why can't I see the country field in the location table filled with any value?
Why can't I see the feed-items showing this location information?

I am really stuck here, please assist.
Thanks a lot in advance!

Greetings,
Martijn

alex_b’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev
Category: feature » support

I assume #10 is a patch to parser_simplepie. I think that's not necessary.

You can write your own mapper after the model of one of the existing ones that goes through the tag array and maps tags to address data. I see you are identifying address data by its position in the tag array. This looks like a custom convention to me (?) - therefore I would keep this code in a custom module.

Understand that your custom mapper /can/ deal with node fields like taxonomy although there is already a taxonomy mapper.

For writing your own mapper, please refer to the resources on the project page of Feed Element Mapper: http://drupal.org/project/feedapi_mapper

This is a 5.x support issue.

summit’s picture

Hi,
I am building a mapper with a friend (www.brambring.nl )which works on D6, but we are not able to get it working on D5. It seems the Drupal 5 mapper can't map per item (the D6 mapper can do this, right)

See here the code of my mapper which is working on D6. How to get it also working on D5?
I need a D5 version because it depends on the place module, which is not available on D6.

<?php
// $Id: feedapi_mapper_location.inc,v 1.1.2.1 2008/11/14 14:44:46 alexb Exp $
/**
 * Implementation of feed element mapper for location.module.
 */

/**
 * Implementation of hook_feedapi_mapper().
 * Maps feed elements to location fields.
 * @param $op
 *   'list' or 'map'
 * @param $node
 *   Feed item node to map on.
 * @param $field_name
 *   Name of field to map to.
 * @param $feed_element
 *   Feed item element to map from. Parameter only present on $op = 'map'
 * @param @sub_field
 *   Subfield on field to map to. Parameter only present on $op = 'map'.
 *   This parameter will depend on if the hook implementation returns a subfield on
 *   $op = 'list'.
 *
 * Return key => name array of sub fields on 'list'.
 * If only one field and no subfields are available for this content type return TRUE.
 * If no fields available for this content type return FALSE.
 * Options are necessary because a field like
 * e. g. "taxonomy" might have more than one slot for information - e. g. vocabularies.
 *
 * Todo: $node could be passed by reference - implementers wouldn't need to return node
 * (PHP5 passes in by reference by default).
 */
function location_feedapi_mapper($op, $node, $field_name, $feed_element = array(), $sub_field = '') {
 if ($field_name == 'locations' && variable_get('location_maxnum_'. $node->type, 0)) {
   if ($op == 'describe') {
     return t('Maps pairs of geographic coordinates to the location of a node.');
   }
   else if ($op == 'list') {
     $sub_fields['latitude'] = 'Latitude';
     $sub_fields['longitude'] = 'Longitude';
     $sub_fields['country'] = 'Country';
     $sub_fields['province'] = 'Region';
     $sub_fields['city'] = 'City';
     return $sub_fields;
   }
   else if ($op == 'map') {
     if (is_array($feed_element)) {
       foreach ($feed_element as $i => $val) {
         $node->locations[$i][$sub_field] = $val;
       }
     } else {
         $node->locations[0][$sub_field] = $feed_element;
     }
     return $node;
   }
 }
 else {
   return FALSE;
 }
}

Any help getting this to work on D5 very much appreciated.

Greetings,
Martijn

burgs’s picture

Martijn,

try replacing
$node->locations[0][$sub_field] = $feed_element;

with

$node->location[$sub_field] = $feed_element;

towards the end of your script.

summit’s picture

Hi Simon,

thanks for your reply!
Will: $node->locations[$i][$sub_field] = $val; work in D5 then, or need I alter something there also?

greetings,
Martijn

burgs’s picture

I've tested a demo version with just the one line replaced. I haven't looked into how it works too much, but if it's an array, do the first bit, otherwise, use that line of replaced code.

Try it out, but i don't think you need to change anything else.

burgs’s picture

You're right, it fails big time in drupal 5
This is the (heavy) mod that i've made to see if this thing will update properly. It works for single addresses, which seems appropriate for csv imports (which is what i'm doing).
Let me know if this suits your current set up and maybe we can think about a patch to submit.


else if ($op == 'map') {
      if (is_array($feed_element)) {
        foreach ($feed_element as $i => $val) {
          $node->locations[$i][$sub_field] = $val;
        }
      } else {
         $node->location[$sub_field] = $feed_element;      
         $node->locations[0][$sub_field] = $feed_element;
         if($node->nid && !$node->locations[0]['lid']){
         	 $n = node_load($node->nid);
         	 $node->locations[0]['lid'] = $n->locations[0]['lid'];
         }
     }

gionnibgud’s picture

Hi this is the full list of fields for mapping:


     $sub_fields['latitude'] = 'Latitude';
     $sub_fields['longitude'] = 'Longitude';     
     $sub_fields['name'] = 'Name';
     $sub_fields['street'] = 'Street';
     $sub_fields['additional'] = 'Additional';
     $sub_fields['city'] = 'City';    
     $sub_fields['province'] = 'Province';
     $sub_fields['province_name'] = 'Province name';
     $sub_fields['postal_code'] = 'Postal code';     
     $sub_fields['country'] = 'Country';
     $sub_fields['country_name'] = 'Country Name';
     $sub_fields['phone'] = 'Phone';
     $sub_fields['fax'] = 'Fax';

cheers

alex_b’s picture

summit’s picture

Hi Alex,
No this thread is about D5 solution, the other one is D6.
greetings,
Martijn

j0k3z’s picture

How do I use the code in this thread? Is there a patch or is this a new file I need to create?

summit’s picture

Hi Farang,

This is custom code for specific feedapi-parsing I use with another parser in D6, it is not working in D5 unfortunately
Off course I can try to help you to get what you want.
What is your question, what you want to do with this code?
You can build a patch of course from this thread if you like.
Greetings,
Martijn
www.reizen-naar.nl

socialnicheguru’s picture

While I get lat and lon to connect to, I don't get the venue, street, province, etc location fields.

Chris

EDIT:

I get all fields if I do not try to map country which is a drop down select.