Taxonomy terms are not getting added to keywords (+patch)

SteffenL - June 13, 2008 - 13:10
Project:Nodewords
Version:6.x-1.0-rc1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

In Drupal 6, taxonomy_node_get_terms() no longer takes a node id as argument but a full $node object.

See http://drupal.org/node/114774#taxonomy-revisions

The following code in 6.x-1.0-rc1 keywords.inc is obviously incorrect and causes taxonomy terms to not generate keywords:

  function nodewords_keywords_prepare($type, $ids, $value, $settings) {
     if ($type == 'node' && function_exists('taxonomy_node_get_terms') && count($ids) == 1) {
       if (node_access('view', node_load($ids[0]))) {
         foreach (taxonomy_node_get_terms($ids[0]) as $term) {

This should probably be something like:

  function nodewords_keywords_prepare($type, $ids, $value, $settings) {
    if ($type == 'node' && function_exists('taxonomy_node_get_terms') && count($ids) == 1) {
     $n = node_load($ids[0]);
     if (node_access('view', $n)) {
       foreach (taxonomy_node_get_terms($n) as $term) {

A patch that works for me is attached

Steffen

#1

Rob T - June 30, 2008 - 05:05

I made this modification, and the taxonomy keyword feature is working so far.

#2

jcfiala - July 11, 2008 - 15:13
Status:active» needs review

I've made the same modification, and the taxonomy keyword seems to work fine now. Included is a patch, as I don't see one attached to the ticket yet.

AttachmentSize
nodewords_taxonomy_keywords.patch 980 bytes

#3

vladimir.dolgopolov - September 2, 2008 - 06:46

The patch works well.
Just rerolled the pach ($n -> $node and some cleanup)

AttachmentSize
nodewords270193.patch 969 bytes

#4

c4gamerz - September 17, 2008 - 10:52

there is one more problem, keywords looks like fun,humour,drupal but there should be space between them like fun, humour, drupal like that! any fix for it?

#5

c4gamerz - September 19, 2008 - 06:46

okay i just fixed it with the help of a forum member

here is the code

<?php
// $Id: keywords.inc,v 1.1.4.3 2008/01/24 20:49:32 robrechtj Exp $

/**
* @file
* Support file for KEYWORDS meta tag.
*/

function nodewords_keywords_prepare($type, $ids, $value, $settings) {
  if ($type == 'node' && function_exists('taxonomy_node_get_terms') && count($ids) == 1) {
  $node = node_load($ids[0]);
    if (node_access('view', $node)) {
      foreach (taxonomy_node_get_terms($node) as $term) {
        if (in_array($term->vid, $settings['keywords_vids'])) {
           $value .= ', '. $term->name;
         }
      }
    }
  }
  $value .= ', '. $settings['global']['keywords'];
  $value = _nodewords_keywords_uniq($value);
  return $value;
}

function nodewords_keywords_form($type, $value, $settings) {
  return array(
    '#type' => 'textfield',
    '#title' => t('Keywords'),
    '#default_value' => $value,
    '#size' => 60,
    '#maxlength' => $settings['max_size'],
    '#description' => t('Enter a comma separated list of keywords for this page. Avoid duplication of words as this will lower your search engine ranking.'),
  );
}

/*
* Uniq a string which is a seperated list to items, preserving
* the order in which they appeared.
*/
function _nodewords_keywords_uniq($text, $max_items = 0, $seperator = ', ') {
  if (empty($text)) {
    return $text;
  }

  $items = array_map('trim', explode($seperator, $text));
  $uniq_values = array();
  $uniq_lowers = array();

  foreach ($items as $item) {
    $lower = strtolower($item);
    if (!in_array($lower, $uniq_lowers) && $lower != '') {
      $uniq_values[] = $item;
      $uniq_lowers[] = $lower;
    }
  }

  if ($max_items > 0) {
    $uniq_values = array_slice($uniq_values, 0, $max_items);
  }

  return implode($seperator, $uniq_values);
}

i just added space in three lines :D

#6

jrglasgow - October 6, 2008 - 20:10
Status:needs review» reviewed & tested by the community

this patch (nodewords270193.patch) works great for me

#7

bjraines - October 8, 2008 - 14:52

how do i apply this patch?

what do the + and - mean by each line?

#8

c4gamerz - October 8, 2008 - 15:17

- means to removes those lines and + means to add those lines ;)

#9

jrglasgow - October 11, 2008 - 00:36

the other option would be to copy the patch file to the module directory and from the command line type

patch < nodewords270193.patch

this should apply the patch

#10

c4gamerz - October 11, 2008 - 06:57

lol i didnt knew that ^^ thanks ;)

#11

marcob - October 30, 2008 - 12:40

This patch works for me.
Thanks

#12

wildtang3nt - November 24, 2008 - 16:23

Patch works fine, awaiting inclusion into Nodewords proper.

#13

podarok - November 26, 2008 - 22:43
Category:bug report» support request

Thanks a lot
This patch works for me
What about including it into release?
If You have no time - I can do it (just add me to developers)

---------
Andriy Podanenko
web: http://my.ukrweb.info

#14

Summit - January 17, 2009 - 12:00

Hi Robert,

Will this patch go in D6 please?
Thanks a lot in advance for considering this!

Greetings.
Martijn

#15

Robrecht Jacques - February 6, 2009 - 13:10
Status:reviewed & tested by the community» fixed

Committed as part of http://drupal.org/node/340642.

Will be included in next releasE. Thanks!

#16

System Message - February 20, 2009 - 13:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.