diff --git a/nodewords.install b/nodewords.install index 2cd71f6..76a7c78 100644 --- a/nodewords.install +++ b/nodewords.install @@ -1731,3 +1731,15 @@ function nodewords_update_6185() { return $ret; } + +/** + * Remove an unused variable. + */ +function nodewords_update_6186() { + $ret = array(); + + drupal_set_message(t('A legacy variable has been removed.')); + variable_del('nodewords_filter_regexp'); + + return $ret; +} diff --git a/nodewords.module b/nodewords.module index 6f055ed..5603c9b 100644 --- a/nodewords.module +++ b/nodewords.module @@ -1022,14 +1022,8 @@ function nodewords_mass_update($ids, $type, $operation = 'delete') { * The string used as meta tag content. */ function nodewords_metatag_from_node_content($node, $content, $options = array()) { - $default_options = array( - 'size' => variable_get('nodewords_max_size', 350), - ); - $filters = filter_list_format($node->format); + // The method used to generate the summary string. $method = variable_get('nodewords_metatags_generation_method_' . $node->type, NODEWORDS_GENERATION_WHEN_EMPTY); - $options += $default_options; - $result = ''; - $source = variable_get('nodewords_metatags_generation_source_' . $node->type, NODEWORDS_GENERATION_TEASER); // If not generating an automatic description, return immediately. if ($method == NODEWORDS_GENERATION_NEVER @@ -1037,63 +1031,68 @@ function nodewords_metatag_from_node_content($node, $content, $options = array() return $content; } + // Proceed as normal. + $result = ''; + $source = variable_get('nodewords_metatags_generation_source_' . $node->type, NODEWORDS_GENERATION_TEASER); + // If generating an automatic description, determine the source. - $text = ''; if (!empty($node->teaser) && ($source == NODEWORDS_GENERATION_TEASER || $source == NODEWORDS_GENERATION_TEASER_BODY)) { - $text = $node->teaser; + $result = $node->teaser; } elseif (!empty($node->body) && ($source == NODEWORDS_GENERATION_BODY || ($source == NODEWORDS_GENERATION_TEASER_BODY && empty($node->teaser)))) { - $text = $node->body; + $result = $node->body; } // Clean up the text by running it through applicable filters. - if (!empty($text)) { - // Check for the presence of the PHP evaluator filter in the current - // format. If the text contains PHP code, do not split it up to prevent - // parse errors. - if (isset($filters['php/0']) && strpos($text, ']*alt=[\"']([^\"']*)[\"'][^>]*>/i", - '_nodewords_teaser_match_callback', - $text - ) - ); - // Remove the strings added from third-party modules. - $modules = array_filter( - variable_get('nodewords_filter_modules_output_' . $node->type, array()) - ); - $regexps = array( - 'imagebrowser' => '/\[ibimage[^\]]*\]/i', - 'img_assist' => '/\[img_assist[^\]]*\]/i', - ); + // Check for the presence of the PHP evaluator filter in the current format. + // If the text contains PHP code, do not split it up to prevent parse errors. + $filters = filter_list_format($node->format); + if (isset($filters['php/0']) && strpos($result, ' $regexp) { - if (isset($modules[$module])) { - $result = preg_replace($regexp, '', $result); - } - } + // Optionally replace the tag IMG with its ALT attribute. + if (variable_get('nodewords_use_alt_attribute', FALSE)) { + $result = preg_replace("/]*alt=[\"']([^\"']*)[\"'][^>]*>/i", ' ($1) ', $result); + } - // Remove the text matching the type-specific regular expression. - if ($regexp = trim(variable_get('nodewords_filter_regexp_' . $node->type, ''))) { - $text = preg_replace('/' . $regexp . '/', '', $text); - } + // Strip off all the HTML tags. + $result = strip_tags($result); - // Remove the text matching the global regular expression. - if ($regexp = trim(variable_get('nodewords_filter_regexp', ''))) { - $text = preg_replace('/' . $regexp . '/', '', $text); + // Remove the strings added from third-party modules. + $modules = array_filter(variable_get('nodewords_filter_modules_output_' . $node->type, array())); + $regexps = array( + 'imagebrowser' => '/\[ibimage[^\]]*\]/i', + 'img_assist' => '/\[img_assist[^\]]*\]/i', + ); + foreach ($regexps as $module => $regexp) { + if (isset($modules[$module])) { + $result = preg_replace($regexp, '', $result); } + } - $result = node_teaser( - trim(preg_replace('/(\r\n?|\n)/', ' ', $text)), - $node->format, $options['size'] - ); + // Remove the text matching the type-specific regular expression. + if ($regexp = trim(variable_get('nodewords_filter_regexp_' . $node->type, ''))) { + $result = preg_replace('/' . $regexp . '/', '', $result); } + + // Remove line breaks. + $result = preg_replace('/(\r\n?|\n)/', ' ', $result); + + // Remove any leading & trailing whitespace. + $result = trim($result); + + // Remove excess inline whitespace. + $result = preg_replace('/\s\s+/', ' ', $result); + + // Trim the filtered text to the maximum length allowed. + $result = node_teaser($result, $node->format, $options['size']); } return $result; @@ -1537,24 +1536,6 @@ function _nodewords_output_tags($tags, $output_type = 'head') { } /** - * Helper function for preg_match_callback(), called when replacing the tag img - * in the teaser, when using it as meta tag DESCRIPTION content. - */ -function _nodewords_teaser_match_callback($matches) { - static $bool; - - if (!isset($bool)) { - $bool = variable_get('nodewords_use_alt_attribute', FALSE); - } - - if ($bool && !empty($matches[1])) { - return ' ' . $matches[1] . ' '; - } - - return ''; -} - -/** * Provide a complete path for the current URL, optionally using a value * manually assigned via a form. *