Хак Автоматическое добавление тегов из заголовка новости
Автоматическое добавление тегов из заголовка новости
Небольшой Хак, который автоматически берет теги из заголовка новости, и добавляет их в новость.
Установка Хака:
Открываем engine/modules/addnews.php
Находим и удаляем (99 строка):
if( ! $config['allow_add_tags'] ) $_POST['tags'] = "";
elseif( preg_match( "/[\||\'|\<|\>|\"|\!|\?|\$|\@|\/|\\\|\&\~\*\+]/", $_POST['tags'] ) ) $_POST['tags'] = "";
else $_POST['tags'] = $db->safesql( htmlspecialchars( strip_tags( stripslashes( trim( $_POST['tags'] ) ) ), ENT_QUOTES ) );
Находим (209 строка):
if( $found ) {
$db->query( "UPDATE " . PREFIX . "_post set title='$title', short_story='$short_story', full_story='$full_story', xfields='$filecontents', category='$category_list', alt_name='$alt_name', allow_comm='$allow_comm', approve='$approve', allow_main='$allow_main', allow_rate='$allow_rating', fixed='$news_fixed', allow_br='$allow_br', flag='1', tags='" . $_POST['tags'] . "' WHERE id='$id'" );
// Облако тегов
if( $_POST['tags'] != $row['tags'] or $approve ) {
$db->query( "DELETE FROM " . PREFIX . "_tags WHERE news_id = '{$row['id']}'" );
if( $_POST['tags'] != "" and $approve ) {
$tags = array ();
$_POST['tags'] = explode( ",", $_POST['tags'] );
foreach ( $_POST['tags'] as $value ) {
$tags[] = "('" . $row['id'] . "', '" . trim( $value ) . "')";
}
$tags = implode( ", ", $tags );
$db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) VALUES " . $tags );
}
}
} else {
Заменяем на:
//Авто Теги
if( ! $config['allow_add_tags'] ) $tags = "";
else $tags = str_word_count ( strip_tags( stripslashes( $title ) ), 1 );
$tag = implode ( ",", $tags );
//Авто Теги
if( $found ) {
$db->query( "UPDATE " . PREFIX . "_post set title='$title', short_story='$short_story', full_story='$full_story', xfields='$filecontents', category='$category_list', alt_name='$alt_name', allow_comm='$allow_comm', approve='$approve', allow_main='$allow_main', allow_rate='$allow_rating', fixed='$news_fixed', allow_br='$allow_br', flag='1', tags='$tag' WHERE id='$id'" );
// Облако тегов
if( $tag != $row['tags'] or $approve ) {
$db->query( "DELETE FROM " . PREFIX . "_tags WHERE news_id = '{$row['id']}'" );
if( $tag != "" and $approve ) {
$tag = "";
foreach ( $tags as $value ) {
$tag[] = "('" . $row['id'] . "', '" . trim( $value ) . "')";
}
$tag = implode( ", ", $tag );
$db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) VALUES " . $tag );
}
}
} else {
Находим (239 строка):
$db->query( "INSERT INTO " . PREFIX . "_post (date, autor, short_story, full_story, xfields, title, keywords, category, alt_name, allow_comm, approve, allow_main, fixed, allow_rate, allow_br, flag, tags) values ('$thistime', '$member_id[name]', '$short_story', '$full_story', '$filecontents', '$title', '', '$category_list', '$alt_name', '$allow_comm', '$approve', '$allow_main', '$news_fixed', '$allow_rating', '$allow_br', '1', '" . $_POST['tags'] . "')" );
Заменяем на:
$db->query( "INSERT INTO " . PREFIX . "_post (date, autor, short_story, full_story, xfields, title, keywords, category, alt_name, allow_comm, approve, allow_main, fixed, allow_rate, allow_br, flag, tags) values ('$thistime', '$member_id[name]', '$short_story', '$full_story', '$filecontents', '$title', '', '$category_list', '$alt_name', '$allow_comm', '$approve', '$allow_main', '$news_fixed', '$allow_rating', '$allow_br', '1', '$tag')" );
Находим (246 строка):
if( $_POST['tags'] != "" and $approve ) {
$tags = array ();
$_POST['tags'] = explode( ",", $_POST['tags'] );
foreach ( $_POST['tags'] as $value ) {
$tags[] = "('" . $row['id'] . "', '" . trim( $value ) . "')";
}
$tags = implode( ", ", $tags );
$db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) VALUES " . $tags );
}
Заменяем на:
if( $tag != $row['tags'] or $approve ) {
$db->query( "DELETE FROM " . PREFIX . "_tags WHERE news_id = '{$row['id']}'" );
if( $tag != "" and $approve ) {
$tag = "";
foreach ( $tags as $value ) {
$tag[] = "('" . $row['id'] . "', '" . trim( $value ) . "')";
}
$tag = implode( ", ", $tag );
$db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) VALUES " . $tag );
}
}
Открываем engine/inc/addnews.php
Находим и удаляем (444 строка):
if( preg_match( "/[\||\'|\<|\>|\"|\!|\?|\$|\@|\/|\\\|\&\~\*\+]/", $_POST['tags'] ) ) $_POST['tags'] = "";
else $_POST['tags'] = $db->safesql( htmlspecialchars( strip_tags( stripslashes( trim( $_POST['tags'] ) ) ), ENT_QUOTES ) );
Находим (543 строка):
$db->query( "INSERT INTO " . PREFIX . "_post (date, autor, short_story, full_story, xfields, title, descr, keywords, category, alt_name, allow_comm, approve, allow_main, fixed, allow_rate, allow_br, votes, access, symbol, flag, tags, metatitle) values ('$thistime', '{$member_id['name']}', '$short_story', '$full_story', '$filecontents', '$title', '{$metatags['description']}', '{$metatags['keywords']}', '$category_list', '$alt_name', '$allow_comm', '$approve', '$allow_main', '$news_fixed', '$allow_rating', '$allow_br', '$add_vote', '$group_regel', '$catalog_url', '1', '{$_POST['tags']}', '{$metatags['title']}')" );
Заменяем на:
//Авто Теги
if( ! $config['allow_add_tags'] ) $tags = "";
else $tags = str_word_count ( strip_tags( stripslashes( $title ) ), 1 );
$tag = implode ( ",", $tags );
//Авто Теги
$db->query( "INSERT INTO " . PREFIX . "_post (date, autor, short_story, full_story, xfields, title, descr, keywords, category, alt_name, allow_comm, approve, allow_main, fixed, allow_rate, allow_br, votes, access, symbol, flag, tags, metatitle) values ('$thistime', '{$member_id['name']}', '$short_story', '$full_story', '$filecontents', '$title', '{$metatags['description']}', '{$metatags['keywords']}', '$category_list', '$alt_name', '$allow_comm', '$approve', '$allow_main', '$news_fixed', '$allow_rating', '$allow_br', '$add_vote', '$group_regel', '$catalog_url', '1', '$tag', '{$metatags['title']}')" );
Находим (556 строка):
if( $_POST['tags'] != "" and $approve ) {
$tags = array ();
$_POST['tags'] = explode( ",", $_POST['tags'] );
foreach ( $_POST['tags'] as $value ) {
$tags[] = "('" . $row . "', '" . trim( $value ) . "')";
}
$tags = implode( ", ", $tags );
$db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) VALUES " . $tags );
}
Заменяем на:
if( $tag != $row['tags'] or $approve ) {
$db->query( "DELETE FROM " . PREFIX . "_tags WHERE news_id = '{$row['id']}'" );
if( $tag != "" and $approve ) {
$tag = "";
foreach ( $tags as $value ) {
$tag[] = "('" . $row['id'] . "', '" . trim( $value ) . "')";
}
$tag = implode( ", ", $tag );
$db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) VALUES " . $tag );
}
}
Установка завершена.
Версия DataLife Engine: 8.2 и ниже