Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
/**
* Create or update IPB session
*/
if ( !empty( $_COOKIE['session_id'] ))
{
$_COOKIE['session_id'] = $db->safesql($_COOKIE['session_id']);
$db->query( "DELETE FROM ibf_sessions WHERE id = '{$_COOKIE['session_id']}';" );
}
/**
* Build a strings of keys and values to use in SQL insert
*
* @return Array [0] => keys string, [1] => values string
* @param $data Array
*/
function build_insert_string( $data )
{
global $db;
$keys = Array();
$values = Array();
foreach( $data as $key => $value )
{
$keys[] = $key;
$values[] = '"' . $db->safesql( $value ) . '"';
}
$keys = implode( ',', $keys );
$values = implode( ',', $values );
return Array( $keys, $values );
}
$dle_name = $db->safesql( $member_id['name'] );
$ipb_member = $db->super_query("SELECT id, name, mgroup,member_login_key FROM ibf_members WHERE name = '{$dle_name}'");
if ( !$ipb_member['id'] )
{
// Member logged into DLE but not found in IPB
// Lets create one !
$email = $db->safesql($member_id['email']);
$regpassword = $db->safesql($member_id['password']);
$add_time = $db->safesql($member_id['reg_date']);
$name = $db->safesql( $member_id['name'] );
$_IP = $db->safesql($_SERVER['REMOTE_ADDR']);
$salt = substr( str_shuffle( 'abcdefghijklmnopqrstuvwzyxABCDEFGHJIKLMNOPQRSTUXYZ1234567890!@#$%^&*()' ), 0, 5 ); // quick salt generator
$converge = Array
(
'converge_email' => $email,
'converge_joined' => $add_time,
'converge_pass_hash' => md5( $salt . $regpassword ),
'converge_pass_salt' => $salt
);
list( $keys, $values ) = build_insert_string( $converge );
$db->query( "INSERT INTO ibf_members_converge({$keys}) VALUES({$values});" );
$member_id = $db->insert_id();
$login_key = md5( microtime() );
$member = Array
(
'id' => $member_id,
'name' => $name,
'members_l_username' => strtolower( $name ),
'members_created_remote' => 1,
'email' => $email,
'member_login_key' => $login_key,
'member_login_key_expire' => time() + 3600 * 24 * 7 * 365,
'mgroup' => 3,
'posts' => 0,
'joined' => $add_time,
'ip_address' => $_IP,
'view_sigs' => 1,
'email_pm' => 1,
'view_img' => 1,
'view_avs' => 1,
'restrict_post' => 0,
'view_pop' => 1,
'msg_total' => 0,
'new_msg' => 0,
'coppa_user' => 0,
'language' => 'ru',
'subs_pkg_chosen' => 0,
'members_display_name' => $name,
'members_l_display_name' => strtolower( $name )
);
list( $keys, $values ) = build_insert_string( $member );
$db->query( "INSERT INTO ibf_members({$keys}) VALUES({$values});" );
$extra = Array
(
'id' => $member_id,
'vdirs' => "in:Входящие|sent:Отправленные"
);
list( $keys, $values ) = build_insert_string( $extra );
$db->query( "INSERT INTO ibf_member_extra({$keys}) VALUES({$values});" );
// XBTT user
$xbt_user = Array
(
'uid' => $member_id,
'name' => $name,
'email' => $email,
'added' => $add_time,
'peers_limit' => 1,
'torrent_pass' => md5( microtime() . time() )
);
list( $keys, $values ) = build_insert_string( $xbt_user );
$db->query( "INSERT INTO users({$keys}) VALUES({$values});" );
// Newly created member
$ipb_member = Array( 'id' => $member_id, 'name' => $name, 'mgroup' => 3, 'member_login_key' => $login_key );
}
// Login IPB member
$ipb_member['id'] = (int) $ipb_member['id'];
$db->query( "DELETE FROM ibf_sessions WHERE member_id = {$ipb_member['id']}" );
$session_id = md5( uniqid(microtime()) );
$session = Array
(
'id' => $session_id,
'member_name' => $ipb_member['name'],
'member_id' => $ipb_member['id'],
'member_group' => $ipb_member['mgroup'],
'login_type' => 0,
'running_time' => time(),
'ip_address' => $_IP,
'browser' => $_SERVER['HTTP_USER_AGENT'],
'location' => 'idx,0,',
'in_error' => 0,
'location_1_type' => '',
'location_1_id' => 0,
'location_2_type' => '',
'location_2_id' => 0,
'location_3_type' => '',
'location_3_id' => 0,
);
list( $keys, $values ) = build_insert_string( $session );
$db->query( "INSERT INTO ibf_sessions({$keys}) VALUES({$values});" );
set_cookie( 'member_id', $ipb_member['id'], 365 );
set_cookie( 'pass_hash', $ipb_member['member_login_key'], 365 );
set_cookie( 'session_id', $session_id, 365 );
}
if (isset($_POST['login']) && (
strpos($_SERVER['HTTP_REFERER'],'/afisha/') !== false
)){
header('Location: '.$_SERVER['HTTP_REFERER']);
die();
}
/**
* Adding IPB member
*/
/**
* Build a strings of keys and values to use in SQL insert
*
* @return Array [0] => keys string, [1] => values string
* @param $data Array
*/
if ( !function_exists ( 'build_insert_string') )
{
function build_insert_string( $data )
{
global $db;
$keys = Array();
$values = Array();
foreach( $data as $key => $value )
{
$keys[] = $key;
$values[] = '"' . $db->safesql( $value ) . '"';
}
$keys = implode( ',', $keys );
$values = implode( ',', $values );
return Array( $keys, $values );
}
}
$salt = substr( str_shuffle( 'abcdefghijklmnopqrstuvwzyxABCDEFGHJIKLMNOPQRSTUXYZ1234567890!@#$%^&*()' ), 0, 5 ); // quick salt generator
$converge = Array
(
'converge_email' => $email,
'converge_joined' => $add_time,
'converge_pass_hash' => md5( $salt . $regpassword ),
'converge_pass_salt' => $salt
);
list( $keys, $values ) = build_insert_string( $converge );
$db->query( "INSERT INTO ibf_members_converge({$keys}) VALUES({$values});" );
$member_id = $db->insert_id();
$login_key = md5( microtime() );
$member = Array
(
'id' => $member_id,
'name' => $name,
'members_l_username' => strtolower( $name ),
'members_created_remote' => 1,
'email' => $email,
'member_login_key' => $login_key,
'member_login_key_expire' => time() + 3600 * 24 * 7 * 365,
'mgroup' => 3,
'posts' => 0,
'joined' => $add_time,
'ip_address' => $_IP,
'view_sigs' => 1,
'email_pm' => 1,
'view_img' => 1,
'view_avs' => 1,
'restrict_post' => 0,
'view_pop' => 1,
'msg_total' => 0,
'new_msg' => 0,
'coppa_user' => 0,
'language' => 'ru',
'subs_pkg_chosen' => 0,
'members_display_name' => $name,
'members_l_display_name' => strtolower( $name )
);
list( $keys, $values ) = build_insert_string( $member );
$db->query( "INSERT INTO ibf_members({$keys}) VALUES({$values});" );
$extra = Array
(
'id' => $member_id,
'vdirs' => "in:Входящие|sent:Отправленные"
);
list( $keys, $values ) = build_insert_string( $extra );
$db->query( "INSERT INTO ibf_member_extra({$keys}) VALUES({$values});" );
// XBTT user (auto created)
$xbt_user = Array
(
'uid' => $member_id,
'name' => $name,
'email' => $email,
'added' => $add_time,
'peers_limit' => 1,
'torrent_pass' => md5( microtime() . time() )
);
list( $keys, $values ) = build_insert_string( $xbt_user );
$db->query( "INSERT INTO users({$keys}) VALUES({$values});" );
/**
* Create IPB session
*/
$session_id = md5( uniqid(microtime()) );
$session = Array
(
'id' => $session_id,
'member_name' => $name,
'member_id' => $member_id,
'member_group' => 3,
'login_type' => 0,
'running_time' => time(),
'ip_address' => $_IP,
'browser' => $_SERVER['HTTP_USER_AGENT'],
'location' => 'idx,0,',
'in_error' => 0,
'location_1_type' => '',
'location_1_id' => 0,
'location_2_type' => '',
'location_2_id' => 0,
'location_3_type' => '',
'location_3_id' => 0,
);
list( $keys, $values ) = build_insert_string( $session );
$db->query( "INSERT INTO ibf_sessions({$keys}) VALUES({$values});" );
set_cookie ( 'member_id', $member_id, 365 );
set_cookie ( 'pass_hash', $login_key, 365 );
set_cookie ( 'session_id', $session_id, 365 );
/**
* Delete IPB user
*/
$name = $db->safesql( $row['name'] );
$ipb_mem = $db->super_query( 'SELECT id FROM ibf_members WHERE name = "' . $name . '"' );
if ( $ipb_mem['id'] )
{
$mid = '=' . (int) $ipb_mem['id'];
$db->query('DELETE FROM users WHERE uid' . $mid );
$db->query('UPDATE ibf_posts SET author_id = 0 WHERE author_id' . $mid );
$db->query('UPDATE ibf_topics SET starter_id = 0 WHERE starter_id' . $mid );
$db->query('UPDATE ibf_profile_comments SET comment_by_member_id = 0 WHERE comment_by_member_id' . $mid );
$db->query('UPDATE ibf_profile_ratings SET rating_by_member_id = 0 WHERE rating_by_member_id' . $mid );
$db->query('DELETE FROM ibf_profile_comments WHERE comment_for_member_id'.$mid );
$db->query('DELETE FROM ibf_profile_ratings WHERE rating_for_member_id'.$mid );
$db->query('DELETE FROM ibf_profile_portal WHERE pp_member_id'.$mid );
$db->query('DELETE FROM ibf_profile_friends WHERE friends_member_id'.$mid );
$db->query('DELETE FROM ibf_profile_friends WHERE friends_friend_id'.$mid );
$db->query('DELETE FROM ibf_pfields_content WHERE member_id'.$mid );
$db->query('DELETE FROM ibf_member_extra WHERE id'.$mid );
$db->query('DELETE FROM ibf_members_converge WHERE converge_id'. $mid );
$db->query('DELETE FROM ibf_admin_permission_rows WHERE row_member_id'.$mid );
$db->query('DELETE FROM ibf_message_topics WHERE mt_owner_id'.$mid );
$db->query('DELETE FROM ibf_contacts WHERE member_id'.$mid." or contact_id".$mid );
$db->query('DELETE FROM ibf_tracker WHERE member_id'.$mid );
$db->query('DELETE FROM ibf_forum_tracker WHERE member_id'.$mid );
$db->query('DELETE FROM ibf_warn_logs WHERE wlog_mid' .$mid );
$db->query('DELETE FROM ibf_validating WHERE member_id'.$mid );
$db->query('DELETE FROM ibf_members WHERE id'.$mid );
ТС на это есть интеграция с движком,можно купить у калиостро,или использовать альтернативу,вот код как прописать в файлы движка:
вставка в saitlogin.php
...
if( ! $is_logged ) {
$member_id = array ();
set_cookie( "dle_user_id", "", 0 );
set_cookie( "dle_password", "", 0 );
set_cookie( 'member_id', 0, -1 );
set_cookie( 'pass_hash', 0, -1 );
set_cookie( 'session_id', 0, -1 );
}
else
{
/**
* Create or update IPB session
*/
if ( !empty( $_COOKIE['session_id'] ))
{
$_COOKIE['session_id'] = $db->safesql($_COOKIE['session_id']);
$db->query( "DELETE FROM ibf_sessions WHERE id = '{$_COOKIE['session_id']}';" );
}
/**
* Build a strings of keys and values to use in SQL insert
*
* @return Array [0] => keys string, [1] => values string
* @param $data Array
*/
function build_insert_string( $data )
{
global $db;
$keys = Array();
$values = Array();
foreach( $data as $key => $value )
{
$keys[] = $key;
$values[] = '"' . $db->safesql( $value ) . '"';
}
$keys = implode( ',', $keys );
$values = implode( ',', $values );
return Array( $keys, $values );
}
$dle_name = $db->safesql( $member_id['name'] );
$ipb_member = $db->super_query("SELECT id, name, mgroup,member_login_key FROM ibf_members WHERE name = '{$dle_name}'");
if ( !$ipb_member['id'] )
{
// Member logged into DLE but not found in IPB
// Lets create one !
$email = $db->safesql($member_id['email']);
$regpassword = $db->safesql($member_id['password']);
$add_time = $db->safesql($member_id['reg_date']);
$name = $db->safesql( $member_id['name'] );
$_IP = $db->safesql($_SERVER['REMOTE_ADDR']);
$salt = substr( str_shuffle( 'abcdefghijklmnopqrstuvwzyxABCDEFGHJIKLMNOPQRSTUXYZ1234567890!@#$%^&*()' ), 0, 5 ); // quick salt generator
$converge = Array
(
'converge_email' => $email,
'converge_joined' => $add_time,
'converge_pass_hash' => md5( $salt . $regpassword ),
'converge_pass_salt' => $salt
);
list( $keys, $values ) = build_insert_string( $converge );
$db->query( "INSERT INTO ibf_members_converge({$keys}) VALUES({$values});" );
$member_id = $db->insert_id();
$login_key = md5( microtime() );
$member = Array
(
'id' => $member_id,
'name' => $name,
'members_l_username' => strtolower( $name ),
'members_created_remote' => 1,
'email' => $email,
'member_login_key' => $login_key,
'member_login_key_expire' => time() + 3600 * 24 * 7 * 365,
'mgroup' => 3,
'posts' => 0,
'joined' => $add_time,
'ip_address' => $_IP,
'view_sigs' => 1,
'email_pm' => 1,
'view_img' => 1,
'view_avs' => 1,
'restrict_post' => 0,
'view_pop' => 1,
'msg_total' => 0,
'new_msg' => 0,
'coppa_user' => 0,
'language' => 'ru',
'subs_pkg_chosen' => 0,
'members_display_name' => $name,
'members_l_display_name' => strtolower( $name )
);
list( $keys, $values ) = build_insert_string( $member );
$db->query( "INSERT INTO ibf_members({$keys}) VALUES({$values});" );
$extra = Array
(
'id' => $member_id,
'vdirs' => "in:Входящие|sent:Отправленные"
);
list( $keys, $values ) = build_insert_string( $extra );
$db->query( "INSERT INTO ibf_member_extra({$keys}) VALUES({$values});" );
// Newly created member
$ipb_member = Array( 'id' => $member_id, 'name' => $name, 'mgroup' => 3, 'member_login_key' => $login_key );
}
// Login IPB member
$ipb_member['id'] = (int) $ipb_member['id'];
$db->query( "DELETE FROM ibf_sessions WHERE member_id = {$ipb_member['id']}" );
$session_id = md5( uniqid(microtime()) );
$session = Array
(
'id' => $session_id,
'member_name' => $ipb_member['name'],
'member_id' => $ipb_member['id'],
'member_group' => $ipb_member['mgroup'],
'login_type' => 0,
'running_time' => time(),
'ip_address' => $_IP,
'browser' => $_SERVER['HTTP_USER_AGENT'],
'location' => 'idx,0,',
'in_error' => 0,
'location_1_type' => '',
'location_1_id' => 0,
'location_2_type' => '',
'location_2_id' => 0,
'location_3_type' => '',
'location_3_id' => 0,
);
list( $keys, $values ) = build_insert_string( $session );
$db->query( "INSERT INTO ibf_sessions({$keys}) VALUES({$values});" );
set_cookie( 'member_id', $ipb_member['id'], 365 );
set_cookie( 'pass_hash', $ipb_member['member_login_key'], 365 );
set_cookie( 'session_id', $session_id, 365 );
}
if (isset($_POST['login']) && (
strpos($_SERVER['HTTP_REFERER'],'/forum/') !== false ||
)){
header('Location: '.$_SERVER['HTTP_REFERER']);
die();
}
$_SESSION['dle_user_id'] = $id;
$_SESSION['dle_name'] = $name;
$_SESSION['dle_password'] = $user_arr[2];
set_cookie( "dle_user_id", $id, 365 );
set_cookie( "dle_password", $user_arr[2], 365 );
@session_register( 'dle_user_id' );
@session_register( 'dle_password' );
$_SESSION['dle_user_id'] = $id;
$_SESSION['dle_password'] = $user_arr[2];
set_cookie( "dle_user_id", $id, 365 );
set_cookie ("dle_name", $name, 365);
set_cookie( "dle_password", $user_arr[2], 365 );
@session_register( 'dle_user_id' );
@session_register('dle_name');
@session_register( 'dle_password' );
$_SESSION['dle_user_id'] = $id;
$_SESSION['dle_name'] = $name;
$_SESSION['dle_password'] = $user_arr[2];
/**
* Adding IPB member
*/
/**
* Build a strings of keys and values to use in SQL insert
*
* @return Array [0] => keys string, [1] => values string
* @param $data Array
*/
if ( !function_exists ( 'build_insert_string') )
{
function build_insert_string( $data )
{
global $db;
$keys = Array();
$values = Array();
foreach( $data as $key => $value )
{
$keys[] = $key;
$values[] = '"' . $db->safesql( $value ) . '"';
}
$keys = implode( ',', $keys );
$values = implode( ',', $values );
return Array( $keys, $values );
}
}
$salt = substr( str_shuffle( 'abcdefghijklmnopqrstuvwzyxABCDEFGHJIKLMNOPQRSTUXYZ1234567890!@#$%^&*()' ), 0, 5 ); // quick salt generator
$converge = Array
(
'converge_email' => $email,
'converge_joined' => $add_time,
'converge_pass_hash' => md5( $salt . $regpassword ),
'converge_pass_salt' => $salt
);
list( $keys, $values ) = build_insert_string( $converge );
$db->query( "INSERT INTO ibf_members_converge({$keys}) VALUES({$values});" );
$member_id = $db->insert_id();
$login_key = md5( microtime() );
$member = Array
(
'id' => $member_id,
'name' => $name,
'members_l_username' => strtolower( $name ),
'members_created_remote' => 1,
'email' => $email,
'member_login_key' => $login_key,
'member_login_key_expire' => time() + 3600 * 24 * 7 * 365,
'mgroup' => 3,
'posts' => 0,
'joined' => $add_time,
'ip_address' => $_IP,
'view_sigs' => 1,
'email_pm' => 1,
'view_img' => 1,
'view_avs' => 1,
'restrict_post' => 0,
'view_pop' => 1,
'msg_total' => 0,
'new_msg' => 0,
'coppa_user' => 0,
'language' => 'ru',
'subs_pkg_chosen' => 0,
'members_display_name' => $name,
'members_l_display_name' => strtolower( $name )
);
list( $keys, $values ) = build_insert_string( $member );
$db->query( "INSERT INTO ibf_members({$keys}) VALUES({$values});" );
$extra = Array
(
'id' => $member_id,
'vdirs' => "in:Входящие|sent:Отправленные"
);
list( $keys, $values ) = build_insert_string( $extra );
$db->query( "INSERT INTO ibf_member_extra({$keys}) VALUES({$values});" );
/**
* Create IPB session
*/
$session_id = md5( uniqid(microtime()) );
$session = Array
(
'id' => $session_id,
'member_name' => $name,
'member_id' => $member_id,
'member_group' => 3,
'login_type' => 0,
'running_time' => time(),
'ip_address' => $_IP,
'browser' => $_SERVER['HTTP_USER_AGENT'],
'location' => 'idx,0,',
'in_error' => 0,
'location_1_type' => '',
'location_1_id' => 0,
'location_2_type' => '',
'location_2_id' => 0,
'location_3_type' => '',
'location_3_id' => 0,
);
list( $keys, $values ) = build_insert_string( $session );
$db->query( "INSERT INTO ibf_sessions({$keys}) VALUES({$values});" );
set_cookie ( 'member_id', $member_id, 365 );
set_cookie ( 'pass_hash', $login_key, 365 );
set_cookie ( 'session_id', $session_id, 365 );
}
}
}
$db->query( "delete FROM " . USERPREFIX . "_users WHERE user_id='$id'" );
$db->query( "delete FROM " . USERPREFIX . "_banned WHERE users_id='$id'" );
$db->query( "delete FROM " . USERPREFIX . "_pm WHERE user='$id'" );
/**
* Delete IPB user
*/
$name = $db->safesql( $row['name'] );
$ipb_mem = $db->super_query( 'SELECT id FROM ibf_members WHERE name = "' . $name . '"' );
if ( $ipb_mem['id'] )
{
$mid = '=' . (int) $ipb_mem['id'];
$db->query('DELETE FROM users WHERE uid' . $mid );
$db->query('UPDATE ibf_posts SET author_id = 0 WHERE author_id' . $mid );
$db->query('UPDATE ibf_topics SET starter_id = 0 WHERE starter_id' . $mid );
$db->query('UPDATE ibf_profile_comments SET comment_by_member_id = 0 WHERE comment_by_member_id' . $mid );
$db->query('UPDATE ibf_profile_ratings SET rating_by_member_id = 0 WHERE rating_by_member_id' . $mid );
$db->query('DELETE FROM ibf_profile_comments WHERE comment_for_member_id'.$mid );
$db->query('DELETE FROM ibf_profile_ratings WHERE rating_for_member_id'.$mid );
$db->query('DELETE FROM ibf_profile_portal WHERE pp_member_id'.$mid );
$db->query('DELETE FROM ibf_profile_friends WHERE friends_member_id'.$mid );
$db->query('DELETE FROM ibf_profile_friends WHERE friends_friend_id'.$mid );
$db->query('DELETE FROM ibf_pfields_content WHERE member_id'.$mid );
$db->query('DELETE FROM ibf_member_extra WHERE id'.$mid );
$db->query('DELETE FROM ibf_members_converge WHERE converge_id'. $mid );
$db->query('DELETE FROM ibf_admin_permission_rows WHERE row_member_id'.$mid );
$db->query('DELETE FROM ibf_message_topics WHERE mt_owner_id'.$mid );
$db->query('DELETE FROM ibf_contacts WHERE member_id'.$mid." or contact_id".$mid );
$db->query('DELETE FROM ibf_tracker WHERE member_id'.$mid );
$db->query('DELETE FROM ibf_forum_tracker WHERE member_id'.$mid );
$db->query('DELETE FROM ibf_warn_logs WHERE wlog_mid' .$mid );
$db->query('DELETE FROM ibf_validating WHERE member_id'.$mid );
$db->query('DELETE FROM ibf_members WHERE id'.$mid );
}