Делаем атрибут Alternate для модуля multi-language DLE

1. Открываем engine/modules/functions.php, ищем:

function GzipOut($debug=0){


Выше вставляем:

function altReplace($matches = [], $title = '')
{
	return $matches[1] . '="' . $title . '"';
}

function setAlternate($alternativeArray = [])
{
	global $alternative;

	$alternativeArrayMerge = array_replace_recursive($alternative, $alternativeArray);

	foreach ($alternativeArrayMerge as $name => $content) {
		if( !$content ) {
			continue;
		}

		$alternative[$name] = $content;
	}
}


2. Открываем engine/init.php, ищем:

$custom_news = false;


Ниже вставляем:

$alternative = [
	'x-default' => $config['http_home_url'],
	'ru' => $config['http_home_url'],
	'en' => $config['http_home_url'] . 'en/'
];


3. Открываем engine/engine.php, ищем:

if ($config['allow_rss']) $metatags .= <<<HTML


Выше вставляем:

if(count($alternative)) {
	foreach ($alternative as $key => $value) {
		$metatags .= "\n<link rel=\"alternate\" hreflang=\"{$key}\" href=\"{$value}\" />";
	}
}


4. Открываем engine/modules/show.full.php, ищем:

$options = news_permission( $row['access'] );


Выше вставляем:

$storyLink = get_url( $row['category'] ) . "/" . $row['id'] . "-" . $row['alt_name'] . ".html";

	setAlternate([
		'x-default' => $config['http_home_url'] . $storyLink,
		'ru' => $config['http_home_url'] . $storyLink,
		'en' => $config['http_home_url'] . 'en/' . $storyLink
	]);

	if($_GET['lang'] == 'en') {
		$row['short_story'] = preg_replace_callback (
			"#(alt|title)=['\"](.+?)['\"]#i",
			function ( $matches ) use ( $row )
			{
				return altReplace( $matches, $row['title'] );
			}, $row['short_story']
		);
		$row['full_story'] = preg_replace_callback (
			"#(alt|title)=['\"](.+?)['\"]#i",
			function ( $matches ) use ( $row )
			{
				return altReplace( $matches, $row['title'] );
			}, $row['full_story']
		);
	}
  • CMS:
    DLE

Рекомендуем посмотреть