Интеграция модулей nodeteaser и meta tags (nodewords)

Главные вкладки

Аватар пользователя VladSavitsky VladSavitsky 29 мая 2008 в 20:14

При одновременной работе этих модулей получается, что автозаполнение мета-тега description анонсом не происходит.
На друпал.орг нашёл упоминания о том, что и в других случаях такое бывает.
Решением стала правка кода модуля с самой благородной целью - подружить оба модуля и получить искомый мета-тег.

В /sites/all/modules/nodewords/metatags/description.inc код функции нужно изменить:
<?php
function nodewords_description_prepare($type, $ids, $value, $settings) {
if ((!isset($value) || empty($value)) && $settings['use_teaser'] && count($ids) == 1) {
switch ($type) {
case 'node':
$node = node_load($ids[0]);
if ($node && node_access('view', $node)) {
// HACK: see http://drupal.org/node/79315 (can't use php functions in
// body of nodes). Note that this still won't work if you have a
// CCK field with PHP format.
if (filter_format_allowcache($node->format)) {
// We would like to use node_view($node, TRUE, FALSE), unfortunately
// this uses theme_node() which, by default, adds 'Posted by ...'
// information (which we don't want). The code below calls all
// functions node_view() does, without the theme.
$node = node_build_content($node, TRUE, FALSE);
$content = drupal_render($node->content);
$node->teaser = $content;
node_invoke_nodeapi($node, 'alter', TRUE, FALSE);
$value = $node->teaser;
}
// Start of hack
elseif ($node->format!=2) {//Not PHP filter format
$node = node_build_content($node, TRUE, FALSE);
$content = drupal_render($node->content);
$node->teaser = $content;
node_invoke_nodeapi($node, 'alter', TRUE, FALSE);
$value = $node->teaser;
}
// End of hack
}
break;

case 'term':
// TODO: probably we have to do a db_rewrite_sql() query here so access is restricted
$term = taxonomy_get_term($ids[0]);
if ($term) {
$value = $term->description;
}
break;
case 'vocabulary':
// TODO: probably we have to do a db_rewrite_sql() query here so access is restricted
$voc = taxonomy_get_vocabulary($ids[0]);
if ($voc) {
$value = $voc->description;
}
break;
}
}
return $value;
}
?>

Моё предложение на друпал.орг: http://drupal.org/node/264221