Created
November 5, 2016 03:27
-
-
Save digideskio/cdf548f56ee223f7df027e692f903269 to your computer and use it in GitHub Desktop.
Invision Power Board (IPB) to MODX Revolution user synchronization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* <pre> | |
* Invision Power Services | |
* IP.Board v3.3.3 | |
* Forum permissions mappings | |
* Last Updated: $Date: 2012-05-10 16:10:13 -0400 (Thu, 10 May 2012) $ | |
* </pre> | |
* | |
* @author $author$ | |
* @copyright (c) 2001 - 2009 Invision Power Services, Inc. | |
* @license http://www.invisionpower.com/company/standards.php#license | |
* @package IP.Board | |
* @subpackage Forums | |
* @link http://www.invisionpower.com | |
* @version $Rev: 10721 $ | |
*/ | |
if (! defined('IN_IPB')) | |
{ | |
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files."; | |
exit(); | |
} | |
/** | |
* Member Synchronization extensions | |
* | |
* @author $author$ | |
* @copyright (c) 2001 - 2009 Invision Power Services, Inc. | |
* @license http://www.invisionpower.com/company/standards.php#license | |
* @package IP.Board | |
* @subpackage Forums | |
* @link http://www.invisionpower.com | |
* @version $Rev: 10721 $ | |
*/ | |
class forumsMemberSync | |
{ | |
/** | |
* Registry reference | |
* | |
* @var object | |
*/ | |
public $registry; | |
public $base_path = '/var/www/sitename/www/'; | |
public $groups = 'Users'; | |
public $loginContext = 'web'; | |
public $addContexts = ''; | |
public $rememberme = 1; | |
/** | |
* CONSTRUCTOR | |
* | |
* @return @e void | |
*/ | |
public function __construct() { | |
$this->registry = ipsRegistry::instance(); | |
$mtime = microtime(); | |
$mtime = explode(" ", $mtime); | |
$mtime = $mtime[1] + $mtime[0]; | |
$tstart = $mtime; | |
ini_set('display_errors', 'On'); | |
define('MODX_API_MODE', true); | |
//$modx_cache_disabled = false; | |
@include $this->base_path . 'config.core.php'; | |
@include_once MODX_CORE_PATH . 'model/modx/modx.class.php'; | |
ob_start(); | |
$this->modx = new modX(); | |
$this->modx->startTime = $tstart; | |
$this->modx->initialize('web'); | |
$this->modx->getService('error','error.modError'); | |
$this->modx->setLogLevel(modX::LOG_LEVEL_INFO); | |
} | |
/** | |
* This method is run when a member is flagged as a spammer | |
* | |
* @param array $member Array of member data | |
* @return @e void | |
*/ | |
public function onSetAsSpammer($member) | |
{ | |
} | |
/** | |
* This method is run when a member is un-flagged as a spammer | |
* | |
* @param array $member Array of member data | |
* @return @e void | |
*/ | |
public function onUnSetAsSpammer($member) { | |
} | |
/** | |
* This method is run when a new account is created | |
* | |
* @param array $member Array of member data | |
* @return @e void | |
*/ | |
public function onCreateAccount($member) { | |
} | |
/** | |
* This method is run when the register form is displayed to a user | |
* | |
* @return @e void | |
*/ | |
public function onRegisterForm() { | |
} | |
/** | |
* This method is run when a user successfully logs in | |
* | |
* @param array $member Array of member data | |
* @return @e void | |
*/ | |
public function onLogin($member) { | |
$uid = $member['member_id']; | |
$username = $member['name']; | |
$password = $member['plainPassword']; | |
if (!$user = $this->modx->getObject('modUser', array('remote_key' => $uid))) { | |
$user = $this->modx->newObject('modUser', array('username' => $username, 'password' => $password, 'remote_key' => $uid)); | |
// Профиль юзера, мы его обновим чуть позже | |
$userProfile = $this->modx->newObject('modUserProfile'); | |
$user->addOne($userProfile); | |
// Если указано - заносим в группы | |
if (!empty($this->groups)) { | |
$groups = explode(',', $this->groups); | |
$userGroups = array(); | |
foreach ($groups as $group) { | |
$group = trim($group); | |
if ($tmp = $this->modx->getObject('modUserGroup', array('name' => $group))) { | |
$gid = $tmp->get('id'); | |
$userGroup = $this->modx->newObject('modUserGroupMember'); | |
$userGroup->set('user_group', $gid); | |
$userGroup->set('role', 1); | |
$userGroups[] = $userGroup; | |
} | |
} | |
$user->addMany($userGroups); | |
} | |
$user->save(); | |
$profile = $user->getOne('Profile'); | |
$profile->set('fullname', $member['members_display_name']); | |
$profile->set('email', $member['email']); | |
$profile->set('dob', strtotime($member['bday_year'].'-'.$member['bday_month'].'-'.$member['bday_day'])); | |
$profile->save(); | |
} | |
$data = array( | |
'username' => $username, | |
'password' => $password, | |
'rememberme' => $this->rememberme | |
); | |
if (!empty($this->loginContext)) {$data['login_context'] = $this->loginContext;} | |
if (!empty($this->addContexts)) {$data['add_contexts'] = $this->addContexts;} | |
// Логиним юзера | |
$response = $this->modx->runProcessor('/security/login', $data); | |
if ($response->isError()) { | |
$this->modx->log(modX::LOG_LEVEL_ERROR, 'Login error. Username: '.$username.', uid: '.$user->get('id').'. Message: '.$response->getMessage()); | |
} | |
} | |
/** | |
* This method is called after a member account has been removed | |
* | |
* @param string $ids SQL IN() clause | |
* @return @e void | |
*/ | |
public function onDelete($mids) { | |
} | |
/** | |
* This method is called after a member's account has been merged into another member's account | |
* | |
* @param array $member Member account being kept | |
* @param array $member2 Member account being removed | |
* @return @e void | |
*/ | |
public function onMerge($member, $member2) { | |
} | |
/** | |
* This method is run after a users email address is successfully changed | |
* | |
* @param integer $id Member ID | |
* @param string $new_email New email address | |
* @param string $old_email Old email address | |
* @return void | |
*/ | |
public function onEmailChange($id, $new_email, $old_email) { | |
if ($user = $this->modx->getObject('modUser', array('remote_key' => $id))) { | |
$profile = $user->getOne('Profile'); | |
$profile->set('email', $new_email); | |
$profile->save(); | |
} | |
} | |
/** | |
* This method is run after a users password is successfully changed | |
* | |
* @param integer $id Member ID | |
* @param string $new_plain_text_pass The new password | |
* @return @e void | |
*/ | |
public function onPassChange($id, $new_plain_text_pass) { | |
if ($user = $this->modx->getObject('modUser', array('remote_key' => $id))) { | |
$user->set('password', $new_plain_text_pass); | |
$user->save(); | |
} | |
} | |
/** | |
* This method is run after a users profile is successfully updated | |
* $member will contain EITHER 'member_id' OR 'email' depending on what data was passed to | |
* IPSMember::save(). | |
* | |
* @param array $member Array of values that were changed | |
* @return @e void | |
*/ | |
public function onProfileUpdate($member) { | |
if (isset($member['member_id']) && isset($member['core'])) { | |
if ($user = $this->modx->getObject('modUser', array('remote_key' => $member['member_id']))) { | |
$profile = $user->getOne('Profile'); | |
$profile->set('dob', strtotime($member['core']['bday_year'].'-'.$member['core']['bday_month'].'-'.$member['core']['bday_day'])); | |
$profile->save(); | |
} | |
} | |
} | |
/** | |
* This method is run after a users group is successfully changed | |
* | |
* @param integer $id Member ID | |
* @param integer $new_group New Group ID | |
* @param integer $old_group Old Group ID | |
* @return @e void | |
*/ | |
public function onGroupChange($id, $new_group, $old_group) { | |
} | |
/** | |
* This method is run after a users display name is successfully changed | |
* | |
* @param integer $id Member ID | |
* @param string $new_name New display name | |
* @return @e void | |
*/ | |
public function onNameChange($id, $new_name) { | |
if ($user = $this->modx->getObject('modUser', array('remote_key' => $id))) { | |
$profile = $user->getOne('Profile'); | |
$profile->set('fullname', $new_name); | |
$profile->save(); | |
} | |
} | |
/** | |
* This method is run when a user logs out | |
* | |
* @param array $member Array of member data | |
* @return @e void | |
*/ | |
public function onLogOut($member) { | |
$response = $this->modx->runProcessor('/security/logout'); | |
if ($response->isError()) { | |
//$this->modx->log(modX::LOG_LEVEL_ERROR, 'Logout error. Username: '.$this->modx->user->get('username').', uid: '.$this->modx->user->get('id').'. Message: '.$response->getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment