| 1 |
<?php |
<?php |
| 2 |
// $Id: nodewords.module,v 1.57.2.215 2009/11/08 16:09:24 kiam Exp $ |
// $Id: nodewords.module,v 1.57.2.216 2009/11/09 11:25:26 kiam Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 860 |
/** |
/** |
| 861 |
* Create the content of a meta tag from a node teaser. |
* Create the content of a meta tag from a node teaser. |
| 862 |
* |
* |
| 863 |
* @param $body |
* @param $text |
| 864 |
* The node body. |
* The string to use. |
| 865 |
* @param $format |
* @param $format |
| 866 |
* The format set for the node. |
* The format set for the node. |
| 867 |
* @param $alt_attribute |
* @param $alt_attribute |
| 873 |
* @return |
* @return |
| 874 |
* The string to use to populate the meta tag. |
* The string to use to populate the meta tag. |
| 875 |
*/ |
*/ |
| 876 |
function nodewords_metatag_from_teaser($body, $format, $alt_attribute, $size = 0) { |
function nodewords_metatag_from_teaser($text, $format, $alt_attribute, $size = 0) { |
| 877 |
if (!$size) { |
if (!$size) { |
| 878 |
$size = variable_get('nodewords_max_size', 350); |
$size = variable_get('nodewords_max_size', 350); |
| 879 |
} |
} |
| 883 |
// parse errors. |
// parse errors. |
| 884 |
if (isset($format)) { |
if (isset($format)) { |
| 885 |
$filters = filter_list_format($format); |
$filters = filter_list_format($format); |
| 886 |
if (isset($filters['php/0']) && strpos($body, '<?') !== FALSE) { |
if (isset($filters['php/0']) && strpos($text, '<?') !== FALSE) { |
| 887 |
return ''; |
return ''; |
| 888 |
} |
} |
| 889 |
} |
} |
| 890 |
|
|
| 891 |
|
// Remove the string added from Image Assist. |
| 892 |
|
$text = preg_replace('/\[img_assist.*\]/i', '', $text); |
| 893 |
|
|
| 894 |
// Initialize the helper function used for preg_replace_callback. |
// Initialize the helper function used for preg_replace_callback. |
| 895 |
_nodewords_teaser_match_callback($alt_attribute, TRUE); |
_nodewords_teaser_match_callback($alt_attribute, TRUE); |
| 896 |
|
|
| 897 |
// 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 |
| 898 |
// HTML tags. |
// HTML tags. |
| 899 |
$body = strip_tags( |
$text = strip_tags( |
| 900 |
preg_replace_callback('/<img\s[^>]*alt=["\']([^"\']*)["\'][^>]*>/i', |
preg_replace_callback('/<img\s[^>]*alt=["\']([^"\']*)["\'][^>]*>/i', |
| 901 |
'_nodewords_teaser_match_callback', |
'_nodewords_teaser_match_callback', |
| 902 |
$body |
$text |
| 903 |
) |
) |
| 904 |
); |
); |
| 905 |
|
|
| 906 |
// Truncate the string at last space within the given size. |
// Truncate the string at last space within the given size. |
| 907 |
return truncate_utf8($body, $size, TRUE); |
return truncate_utf8($text, $size, TRUE); |
| 908 |
} |
} |
| 909 |
|
|
| 910 |
/** |
/** |