Hi.
Ich hab ein (von mir dilettantisch modifiziertes) Script, das in Teilen ursprünglich für phpBB3 konzepiert wurde, zur Ausgabe von dynamischen Meta Tags für mein phpBB2 laufen. Leider wandelt es die in den Tabellen gespeicherten HTML-Zeichen wie &.; und ".; nicht um, d.h. mitunter werden in der viewforum.php solche:
Code:
<meta name="description" lang="de" content="Questions &.; Answers" /><meta name="keywords" content="Questions,amp,Answers" />
und in der viewtopic.php derartige Meta Tags ausgegeben:
Code:
<meta name="description" lang="de" content=" Nun hat es auch Johnny &.;quot;the Man in Black&.;quot; Cash erwischt">
statt
Code:
<meta name="description" lang="de" content=" Nun hat es auch Johnny "the Man in Black" Cash erwischt">
bzw.
Code:
<meta name="description" lang="de" content=" Nun hat es auch Johnny the Man in Black Cash erwischt">
Die relevanten Teile des Scripts:
Code:
function make_keywords($text) {
global $phpbb_root_path;
static $stop_words = array();
$keywords = '';
$num = 0;
$text = strtolower(preg_replace(array('`&(amp;)?#?[a-z0-9]+;`i', '`[[:punct:]]+`', '`[0-9]+`', '`[\s]+`'), ' ', strip_tags($text)));
$text = explode(' ', trim($text), 50);
include($phpbb_root_path . 'language/lang_german/search_stopwords.php');
$stop_words = & $words;
$text = array_diff($text, $stop_words);
// We take the most used words first
$text = array_count_values($text);
arsort($text);
foreach ($text as $word => $count) {
if ( strlen($word) >= 3 ) {
$keywords .= ', ' . $word;
$num++;
if ( $num >= 15 ) {
break;
}
}
}
return trim($keywords, ', ');
}
function meta_filter_txt($text, $bbcode = true) {
if ($bbcode) {
static $RegEx = array();
static $replace = array(' ', ' ', '', ' ');
if (empty($RegEx)) {
$RegEx = array('`<[^>]*>(.*<[^>]*>)?`Usi', // HTML code
'`\[(' . 'img|url|flash|code' . ')[^\[\]]+\].*\[/\1[^\[\]]+\]`Usi', // bbcode to strip
'`\[/?[^\[\]]+\]`mi', // Strip all bbcode tags
'`[\s]+`' // Multiple spaces
);
}
return $this->word_limit(htmlspecialchars(preg_replace($RegEx, $replace, $text), ENT_COMPAT));
}
return $this->word_limit(htmlspecialchars(preg_replace(array('`<[^>]*>(.*<[^>]*>)?`Usi', '`[\s]+`'), ' ', $text), ENT_COMPAT));
}
function word_limit($string) {
return count($words = preg_split('/\s+/', ltrim($string), 25 + 1)) > 25 ? rtrim(substr($string, 0, strlen($string) - strlen(end($words)))) . '...' : $string;
}
In der Viewtopic.php hab ich das hier stehen:
Code:
$phpbb_seo->seo_meta['meta_desc'] = $phpbb_seo->meta_filter_txt($postrow[0]['post_text']);
$m_kewrd = '';
$sql = "SELECT w.word_text
FROM " . TOPICS_TABLE . " t, " . SEARCH_MATCH_TABLE . " m, " . SEARCH_WORD_TABLE . " w
WHERE t.topic_id = $topic_id
AND t.topic_first_post_id = m.post_id
AND m.word_id = w.word_id LIMIT 15
ORDER BY w.word_count DESC";
if( ($result = $db->sql_query($sql)) ) {
while ( $meta_row = $db->sql_fetchrow($result) ) {
$m_kewrd .= " " . $meta_row['word_text'];
}
}
$phpbb_seo->seo_meta['keywords'] = $phpbb_seo->make_keywords("$m_kewrd " . $phpbb_seo->seo_meta['meta_desc']);
Wäre nett, wenn mir jemand helfen könnte!
[e] Musste einen Punkt nach "amp" setzen.