| 1 |
<?php |
<?php |
| 2 |
// $Id: nodewords.module,v 1.66.2.26 2009/11/09 10:10:14 kiam Exp $ |
// $Id: nodewords.module,v 1.66.2.27 2009/11/09 11:20:04 kiam Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 950 |
/** |
/** |
| 951 |
* Create the content of a meta tag from a node teaser. |
* Create the content of a meta tag from a node teaser. |
| 952 |
* |
* |
| 953 |
* @param $body |
* @param $text |
| 954 |
* The node body. |
* The string to use. |
| 955 |
* @param $format |
* @param $format |
| 956 |
* The format set for the node. |
* The format set for the node. |
| 957 |
* @param $alt_attribute |
* @param $options |
| 958 |
* If TRUE, any tag img will be replaced with its attribute alt. |
* An array of options. The currently defined are: |
| 959 |
* @param $size |
* 'alt_attribute' |
| 960 |
* The maximum allowed size; if it is zero, then the function will use the |
If TRUE, any tag img will be replaced with its attribute alt. |
| 961 |
* value of the Drupal variable nodewords_max_size. |
* size' |
| 962 |
|
* The maximum allowed size; if it is zero, then the function will use |
| 963 |
|
the value of the Drupal variable "nodewords_max_size". |
| 964 |
* |
* |
| 965 |
* @return |
* @return |
| 966 |
* The string to use to populate the meta tag. |
* The string to use to populate the meta tag. |
| 967 |
*/ |
*/ |
| 968 |
function nodewords_metatag_from_teaser($body, $format, $alt_attribute, $size = 0) { |
function nodewords_metatag_from_teaser($text, $format, $options = array()) { |
| 969 |
if (!$size) { |
$default_options = array( |
| 970 |
$size = variable_get('nodewords_max_size', 350); |
'alt_attribute' => FALSE, |
| 971 |
} |
'size' => variable_get('nodewords_max_size', 350), |
| 972 |
|
); |
| 973 |
|
$options += $default_options; |
| 974 |
|
|
| 975 |
// We check for the presence of the PHP evaluator filter in the current |
// We check for the presence of the PHP evaluator filter in the current |
| 976 |
// format. If the body contains PHP code, we do not split it up to prevent |
// format. If the body contains PHP code, we do not split it up to prevent |
| 977 |
// parse errors. |
// parse errors. |
| 978 |
if (isset($format)) { |
if (isset($format)) { |
| 979 |
$filters = filter_list_format($format); |
$filters = filter_list_format($format); |
| 980 |
if (isset($filters['php/0']) && strpos($body, '<?') !== FALSE) { |
if (isset($filters['php/0']) && strpos($text, '<?') !== FALSE) { |
| 981 |
return ''; |
return ''; |
| 982 |
} |
} |
| 983 |
} |
} |
| 984 |
|
|
| 985 |
|
// Remove the string added from Image Assist. |
| 986 |
|
$text = preg_replace('/\[img_assist.*\]/i', '', $text); |
| 987 |
|
|
| 988 |
// Initialize the helper function used for preg_replace_callback. |
// Initialize the helper function used for preg_replace_callback. |
| 989 |
_nodewords_teaser_match_callback($alt_attribute, TRUE); |
_nodewords_teaser_match_callback($alt_attribute, TRUE); |
| 990 |
|
|
| 991 |
// Replace the meta tag img with the attribute alt, and strip off all the |
// Replace the meta tag img with the attribute alt, and strip off all the |
| 992 |
// HTML tags. |
// HTML tags. |
| 993 |
$body = strip_tags( |
$text = strip_tags( |
| 994 |
preg_replace_callback('/<img\s[^>]*alt=["\']([^"\']*)["\'][^>]*>/i', |
preg_replace_callback('/<img\s[^>]*alt=["\']([^"\']*)["\'][^>]*>/i', |
| 995 |
'_nodewords_teaser_match_callback', |
'_nodewords_teaser_match_callback', |
| 996 |
$body |
$text |
| 997 |
) |
) |
| 998 |
); |
); |
| 999 |
|
|
| 1000 |
// Truncate the string at last space within the given size. |
// Truncate the string at last space within the given size. |
| 1001 |
return truncate_utf8($body, $size, TRUE); |
return truncate_utf8($text, $size, TRUE); |
| 1002 |
} |
} |
| 1003 |
|
|
| 1004 |
/** |
/** |