Hi brevity,

In what form is the inputted url (or eg isbn, i guess) available? Is it

$keywords

? Basically, I want to do two things.

1. Save the URL in a text field in the created node. I can't find the code where the drupal form is altered, but I guess this would be relatively easy to do when everything else is being done... (Let's call this CCK field 'url')

2. Check for duplicates based on this inputted url rather than title (as inputs can throw same titles, so makes sense, right?)

I've found the relevant code in the .module, (line 336) so would it be something like this:

// check on duplicates by url
  $node = node_load(array('url'=>$keywords));  // CCK field called 'url', and $keywords if that is indeed where url is stored
  if ($node) {
    $msg = "A node with this title already exists; editing ".l("node/".$node->nid, "node/".$node->nid)." instead with filled in retrieved values"; 
    drupal_set_message($msg, error);
    //$form_action = '/node/'.$node->nid.'/edit';
    $gotourl = 'node/'.$node->nid.'/edit';
  }

I would really appreciate your help in this ... I have made an effort to find and alter the code, and I created that Last.FM example (and would be happy to create a patch if necessary) ;).

Comments

brevity’s picture

1. If you have a cck text-field named 'url' or 'URL' this should get mapped automatically -- if not you could try to define a mapping in createfromweb (although people find this admittedly awkward :)

Is your inputted data (your url) correctly displayed along the createfromweb process ...?

2. This seems to be even more complicated; in the code snippet above node_load is used to determine and load any node in the drupal database with given title. As http://api.drupal.org/api/function/node_load/6 to my knowledge only checks on attributes in the node table, a duplicate check here on an cck field is not that straightforward. We would have to find out such nodes with own code, searching also in cck fields...

Hope this helps somewhat for a start

B747’s picture

Thanks for your reply. Let's go backwards...

2. I got this code from somewhere on d.o. (and have customized it for our purposes)


function createfromweb_get_page_nid($value) {    //unfortunately content type 'page' is hard-coded
   static $cache = array();

   $key = "$value";      // I needed to make sure "00023864" values stayed as strings -- 
                                 // quotes unnecessary? I wasn't sure
   if (isset($cache[$key])) {
      $nid = $cache[$key];
   }
   else {
      $query = "SELECT nid FROM {table where your field lives} WHERE field_url = '%s' LIMIT 1 ";
      // if the field is an integer type, change '%s' above to %d
      $nid = db_result(db_query($query, $key));
      if ($nid) {
         $cache[$key] = $nid;
      }
         else $nid = '';
   }
   return $nid;
}

and then

$node = node_load(createfromweb_get_page_nid($value));

Not sure if this will actually work - do you have any ideas? The discussion I got the code from is here, and the thread certainly continues with many a code snippet, but I'm not sure whether any are relevant to this situation, perhaps you could have a quick peek?

But this is irrelevant until the other point is sorted...

1. When I talk about 'URL' I mean what is inputted on /createfromweb with the label 'Input'. As far as I can tell, nowhere either in the UI or code is this referred to as 'url', and therefore won't be recognized by the mapping process as such. Right? This is with the possible exception of operator_wikipedia.inc, which I'm not using anyway.

I hope this makes it a bit clearer! I did for the record create a text field 'url' and -- nada.

Thanks for your help.

brevity’s picture

ok, so e.g. you would like the user to enter a url, let's say "http://python.org/dev/peps/pep-0020/" ... you're right, nowhere in the mapping process would be some array key be "url" unless you define it in your createfromweb operator.inc in the $result array. your operator could e.g. read the content of that url and parse/extract a title and maybe an abstract, thus you're $result could have three keys like url=>'http://...' , title=>'PEP 20', abstract=>'Long time...' -- which again createfromweb could use to fill cck fields of similar names -- this sounds like a community web caching/extracting thingy, nice ;)

checking on duplicate urls then should work as you sketched it out, right!

B747’s picture

Great, however, I am not planning to have my operator extract the url from the url, if that makes sense. In fact, I want to employ a different operator depending on the URL. So the URL that goes into my CCK must be directly from the input form, and not spat out from the operator. So, do you remember which variable the inputted data is stored in? Thanks for your help!

brevity’s picture

the input form you mentioned is on line 130 $form['createfromweb_query']['rawtext'] ...

to get the inputted data over after processing the 'operator', you have to store that value maybe into a $_SESSION var -- actually it seems I've done that in $_SESSION['createfromweb_keywords'] -- the devel module helps to see what's going on with session vars

cheers