Небольшой хак для тегов DLE, он преобразует ссылки облака тегов в транслит и записывает в базу. Есть проблемы, не работает в спидбар (выводится транслитом), не работают метатеги и не обновляется при редактировании новости, надо удалять теги и вписывать снова.1. открыть файл engine.phpнайти:
$db->query ( "SELECT news_id FROM " . PREFIX . "_tags WHERE tag='{$tag}'" );
заменить на:
$db->query ( "SELECT news_id FROM " . PREFIX . "_tags WHERE alt_name='{$tag}'" );
2. открыть файл modules/tagscloud.phpнайти:
$db->query("SELECT SQL_CALC_FOUND_ROWS tag, COUNT(*) AS count FROM " . PREFIX . "_tags GROUP BY tag ORDER BY count DESC LIMIT 0,{$config['tags_number']}");
заменить на:
$db->query("SELECT SQL_CALC_FOUND_ROWS tag, alt_name, COUNT(*) AS count FROM " . PREFIX . "_tags GROUP BY tag ORDER BY count DESC LIMIT 0,{$config['tags_number']}");
найти 2 раза:
$tags[$row['tag']] = $row['count'];
заменить на:
$tags[$row['tag']] = $row['count'].'||'.$row['alt_name'];
найти 2 раза:
foreach ($tags as $tag => $value) { $list[$tag]['tag'] = $tag; $list[$tag]['size'] = $sizes[sprintf("%d", ($value-$min)/$range*4 )]; $list[$tag]['count'] = $value; }
заменить на:
foreach ($tags as $tag => $value) { $value = explode('||', $value); $list[$tag]['tag'] = $tag; $list[$tag]['size'] = $sizes[sprintf("%d", ($value[0]-$min)/$range*4 )]; $list[$tag]['count'] = $value[0]; $list[$tag]['alt_name'] = $value[1]; }
найти 2 раза:
foreach ($list as $value) { if (trim($value['tag']) != "" ) { if ($config['allow_alt_url'] ) $tags[] = "".$value['tag'].""; else $tags[] = "".$value['tag'].""; } }
заменить на:
foreach ($list as $value) { if (trim($value['tag']) != "" ) { if (empty($value['alt_name'])) { $value['alt_name'] = $value['tag']; } if ($config['allow_alt_url'] ) $tags[] = "".$value['tag'].""; else $tags[] = "".$value['tag'].""; } }
найти:
$sql_select = "SELECT tag, COUNT(*) AS count FROM " . PREFIX . "_tags GROUP BY tag ORDER BY count DESC LIMIT 0,".intval($matches[1]); } else $sql_select = "SELECT tag, COUNT(*) AS count FROM " . PREFIX . "_tags GROUP BY tag";
заменить на:
$sql_select = "SELECT tag, alt_name, COUNT(*) AS count FROM " . PREFIX . "_tags GROUP BY tag ORDER BY count DESC LIMIT 0,".intval($matches[1]); } else $sql_select = "SELECT tag, alt_name, COUNT(*) AS count FROM " . PREFIX . "_tags GROUP BY tag";
3. открыть файлы modules/show.short.php modules/show.full.php modules/show.custom.phpнайти:
if( $config['allow_tags'] and $row['tags'] ) {
после вставить:
$tags_alt_names = array(); $result_tags = $db->query("SELECT `tag`, `alt_name` FROM `".PREFIX."_tags` WHERE `news_id` = '".$row['id']."'"); while ($row_tag = $db->get_row($result_tags)) { $tags_alt_names[$row_tag['tag']] = $row_tag['alt_name']; }
найти:
$value = trim( $value );
после вставить:
$alt_name = !empty($tags_alt_names[$value]) ? $tags_alt_names[$value] : $value;
найти:
if( $config['allow_alt_url'] ) $tags[] = "" . $value . ""; else $tags[] = "" . $value . "";
заменить на:
if( $config['allow_alt_url'] ) $tags[] = "" . $value . ""; else $tags[] = "" . $value . "";
4. открыть файл modules/addnews.phpнайти:
// Облако тегов 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 ); } }
заменить на:
// Облако тегов 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 ) { $value = trim( $value ); $tag_alt_name = totranslit($value); $tags[] = "('" . $row['id'] . "', '" . $value . "', '".$tag_alt_name."')"; } $tags = implode( ", ", $tags ); $db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag, alt_name) VALUES " . $tags ); } }
5. Открыть файл inc/addnews.phpнайти:
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( $_POST['tags'] != "" and $approve ) { $tags = array (); $_POST['tags'] = explode( ",", $_POST['tags'] ); foreach ( $_POST['tags'] as $value ) { $value = trim( $value ); $tag_alt_name = totranslit($value); $tags[] = "('" . $row . "', '" . $value . "', '".$tag_alt_name."')"; } $tags = implode( ", ", $tags ); $db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag, alt_name) VALUES " . $tags ); }
6. открыть файл inc/editnews.phpнайти:
// Облако тегов if( $_POST['tags'] != $item_db[2] or $approve != $item_db[3] ) { $db->query( "DELETE FROM " . PREFIX . "_tags WHERE news_id = '$item_db[0]'" ); if( $_POST['tags'] != "" and $approve ) { $tags = array (); $_POST['tags'] = explode( ",", $_POST['tags'] ); foreach ( $_POST['tags'] as $value ) { $tags[] = "('" . $item_db[0] . "', '" . trim( $value ) . "')"; } $tags = implode( ", ", $tags ); $db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) VALUES " . $tags ); } }
заменить на:
// Облако тегов if( $_POST['tags'] != $item_db[2] or $approve != $item_db[3] ) { $db->query( "DELETE FROM " . PREFIX . "_tags WHERE news_id = '$item_db[0]'" ); if( $_POST['tags'] != "" and $approve ) { $tags = array (); $_POST['tags'] = explode( ",", $_POST['tags'] ); foreach ( $_POST['tags'] as $value ) { $value = trim( $value ); $tag_alt_name = totranslit($value); $tags[] = "('" . $item_db[0] . "', '" . $value . "', '".$tag_alt_name."')"; } $tags = implode( ", ", $tags ); $db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag, alt_name) VALUES " . $tags ); } }
7. открыть файл inc/tagscloud.phpнайти:
clear_cache(); header( "Location: ?mod=tagscloud&start_from={$start_from}" ); die(); } echoheader( "".$lang['header_tc_1'], $lang['header_tc_2'] );
выше найти:
if ( count($tags) ) { $tagcloud = array (); foreach ( $tags as $value ) { $tagcloud[] = "('" . $row['id'] . "', '" . $db->safesql(trim( $value )) . "')"; } $tagcloud = implode( ", ", $tagcloud ); $db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) VALUES " . $tagcloud ); }
заменить на:
if ( count($tags) ) { $tagcloud = array (); foreach ( $tags as $value ) { $value = trim( $value ); $tag_alt_name = totranslit($value); $tagcloud[] = "('" . $row['id'] . "', '" . $db->safesql($value) . "', '".$db->safesql($tag_alt_name)."')"; } $tagcloud = implode( ", ", $tagcloud ); $db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag, alt_name) VALUES " . $tagcloud ); }
8. выполнить запрос в базу:
ALTER TABLE `dle_tags` ADD `alt_name` VARCHAR( 255 ) NOT NULL