Хак Хак теги соц. сети в main.tpl
В Dle версии 10.3 реализовали возможность регистрации и входа на сайт через соц.сети. Но вот вывод нужных тегов возможен только в login.tpl . Данный хак делает возможным использование этих тегов в файле шаблона main.tpl .
1. В файле index.php найти:
Добавить выше:
2. В файл main.tpl, в нужное место добавить:
$tpl->set ( '{AJAX}', $ajax );
Добавить выше:
// social auth
if( $config['allow_social'] AND $config['allow_registration'] AND !$is_logged ) {
include_once (ENGINE_DIR . '/data/socialconfig.php');
if( !$_SESSION['state'] ) $_SESSION['state'] = md5(uniqid(rand(), TRUE));
if( $social_config['vk'] ) {
$social_params = array(
'client_id' => $social_config['vkid'],
'redirect_uri' => $config['http_home_url'] . "index.php?do=auth-social&provider=vk",
'scope' => 'offline,wall,email',
'state' => $_SESSION['state'],
'response_type' => 'code'
);
$tpl->set( '[vk]', "" );
$tpl->set( '[/vk]', "" );
$tpl->set( '{vk_url}', 'http://oauth.vk.com/authorize' . '?' . http_build_query($social_params) );
} else {
$tpl->set_block( "'\\[vk\\](.*?)\\[/vk\\]'si", "" );
$tpl->set( '{vk_url}', '' );
}
if( $social_config['od'] ) {
$social_params = array(
'client_id' => $social_config['odid'],
'redirect_uri' => $config['http_home_url'] . "index.php?do=auth-social&provider=od&state=" . $_SESSION['state'],
'response_type' => 'code'
);
$tpl->set( '[odnoklassniki]', "" );
$tpl->set( '[/odnoklassniki]', "" );
$tpl->set( '{odnoklassniki_url}', 'http://www.odnoklassniki.ru/oauth/authorize' . '?' . http_build_query($social_params) );
} else {
$tpl->set_block( "'\\[odnoklassniki\\](.*?)\\[/odnoklassniki\\]'si", "" );
$tpl->set( '{odnoklassniki_url}', '' );
}
if( $social_config['fc'] ) {
$social_params = array(
'client_id' => $social_config['fcid'],
'redirect_uri' => $config['http_home_url'] . "index.php?do=auth-social&provider=fc",
'scope' => 'public_profile, email',
'display' => 'popup',
'state' => $_SESSION['state'],
'response_type' => 'code'
);
$tpl->set( '[facebook]', "" );
$tpl->set( '[/facebook]', "" );
$tpl->set( '{facebook_url}', 'https://www.facebook.com/dialog/oauth' . '?' . http_build_query($social_params) );
} else {
$tpl->set_block( "'\\[facebook\\](.*?)\\[/facebook\\]'si", "" );
$tpl->set( '{facebook_url}', '' );
}
if( $social_config['google'] ) {
$social_params = array(
'client_id' => $social_config['googleid'],
'redirect_uri' => $config['http_home_url'] . "index.php?do=auth-social&provider=google",
'scope' => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile',
'state' => $_SESSION['state'],
'response_type' => 'code'
);
$tpl->set( '[google]', "" );
$tpl->set( '[/google]', "" );
$tpl->set( '{google_url}', 'https://accounts.google.com/o/oauth2/auth'.'?' . http_build_query($social_params) );
} else {
$tpl->set_block( "'\\[google\\](.*?)\\[/google\\]'si", "" );
$tpl->set( '{google_url}', '' );
}
if( $social_config['mailru'] ) {
$social_params = array(
'client_id' => $social_config['mailruid'],
'redirect_uri' => $config['http_home_url'] . "index.php?do=auth-social&provider=mailru",
'state' => $_SESSION['state'],
'response_type' => 'code'
);
$tpl->set( '[mailru]', "" );
$tpl->set( '[/mailru]', "" );
$tpl->set( '{mailru_url}', 'https://connect.mail.ru/oauth/authorize'.'?' . http_build_query($social_params) );
} else {
$tpl->set_block( "'\\[mailru\\](.*?)\\[/mailru\\]'si", "" );
$tpl->set( '{mailru_url}', '' );
}
if( $social_config['yandex'] ) {
$social_params = array(
'client_id' => $social_config['yandexid'],
'redirect_uri' => $config['http_home_url'] . "index.php?do=auth-social&provider=yandex",
'state' => $_SESSION['state'],
'response_type' => 'code'
);
$tpl->set( '[yandex]', "" );
$tpl->set( '[/yandex]', "" );
$tpl->set( '{yandex_url}', 'https://oauth.yandex.ru/authorize' . '?' . http_build_query($social_params) );
} else {
$tpl->set_block( "'\\[yandex\\](.*?)\\[/yandex\\]'si", "" );
$tpl->set( '{yandex_url}', '' );
}
} else {
$_SESSION['state'] = false;
$tpl->set_block( "'\\[vk\\](.*?)\\[/vk\\]'si", "" );
$tpl->set( '{vk_url}', '' );
$tpl->set_block( "'\\[odnoklassniki\\](.*?)\\[/odnoklassniki\\]'si", "" );
$tpl->set( '{odnoklassniki_url}', '' );
$tpl->set_block( "'\\[facebook\\](.*?)\\[/facebook\\]'si", "" );
$tpl->set( '{facebook_url}', '' );
$tpl->set_block( "'\\[google\\](.*?)\\[/google\\]'si", "" );
$tpl->set( '{google_url}', '' );
$tpl->set_block( "'\\[mailru\\](.*?)\\[/mailru\\]'si", "" );
$tpl->set( '{mailru_url}', '' );
$tpl->set_block( "'\\[yandex\\](.*?)\\[/yandex\\]'si", "" );
$tpl->set( '{yandex_url}', '' );
}
// social auth
2. В файл main.tpl, в нужное место добавить:
<div class="sociallogin">
[vk]<a href="{vk_url}" target="_blank"><img src="{THEME}/images/social/vkontakte.gif" /></a>[/vk]
[odnoklassniki]<a href="{odnoklassniki_url}" target="_blank"><img src="{THEME}/images/social/odnoklassniki.gif" /></a>[/odnoklassniki]
[facebook]<a href="{facebook_url}" target="_blank"><img src="{THEME}/images/social/facebook.gif" /></a>[/facebook]
[mailru]<a href="{mailru_url}" target="_blank"><img src="{THEME}/images/social/mailru.gif" /></a>[/mailru]
[yandex]<a href="{yandex_url}" target="_blank"><img src="{THEME}/images/social/yandex.gif" /></a>[/yandex]
[google]<a href="{google_url}" target="_blank"><img src="{THEME}/images/social/google.gif" /></a>[/google]
</div>
Готово!
Версия DLE: 10.3
Автор: Vitnet