protected function importUsers() { $db = $this->db(); $prefix = $this->vars['db_prefix']; $rs = $db->select('SELECT * FROM ' . $prefix . 'users'); try { $this->con->begin(); while ($rs->fetch()) { $user_login = preg_replace('/[^A-Za-z0-9@._-]/', '-', $rs->user_login); $this->vars['user_ids'][$rs->ID] = $user_login; if (!$this->core->userExists($user_login)) { $cur = $this->con->openCursor($this->prefix . 'user'); $cur->user_id = $user_login; $cur->user_pwd = crypt::createPassword(); $cur->user_displayname = $rs->user_nicename; $cur->user_email = $rs->user_email; $cur->user_url = $rs->user_url; $cur->user_creadt = $rs->user_registered; $cur->user_lang = $this->core->blog->settings->lang; $cur->user_tz = $this->core->blog->settings->blog_timezone; $permissions = array(); $rs_meta = $db->select('SELECT * FROM ' . $prefix . 'usermeta WHERE user_id = ' . $rs->ID); while ($rs_meta->fetch()) { switch ($rs_meta->meta_key) { case 'first_name': $cur->user_firstname = $this->cleanStr($rs_meta->meta_value); break; case 'last_name': $cur->user_name = $this->cleanStr($rs_meta->meta_value); break; case 'description': $cur->user_desc = $this->cleanStr($rs_meta->meta_value); break; case 'rich_editing': $cur->user_options = new ArrayObject(array('enable_wysiwyg' => $rs_meta->meta_value == 'true' ? true : false)); break; case 'wp_user_level': switch ($rs_meta->meta_value) { case '0': # Subscriber $cur->user_status = 0; break; case '1': # Contributor $permissions['usage'] = true; $permissions['publish'] = true; $permissions['delete'] = true; break; case '2': # Author # Author case '3': case '4': $permissions['contentadmin'] = true; $permissions['media'] = true; break; case '5': # Editor # Editor case '6': case '7': $permissions['contentadmin'] = true; $permissions['categories'] = true; $permissions['media_admin'] = true; $permissions['pages'] = true; $permissions['blogroll'] = true; break; case '8': # Administrator # Administrator case '9': case '10': $permissions['admin'] = true; break; } break; } } $this->core->addUser($cur); $this->core->setUserBlogPermissions($cur->user_id, $this->blog_id, $permissions); } } $this->con->commit(); $db->close(); } catch (Exception $e) { $this->con->rollback(); $db->close(); throw $e; } }
protected function importUsers() { $db = $this->db(); $prefix = $this->vars['db_prefix']; $rs = $db->select('SELECT * FROM ' . $prefix . 'user'); try { $this->con->begin(); while ($rs->fetch()) { if (!$this->core->userExists($rs->user_id)) { $cur = $this->con->openCursor($this->prefix . 'user'); $cur->user_id = $rs->user_id; $cur->user_name = $rs->user_nom; $cur->user_firstname = $rs->user_prenom; $cur->user_displayname = $rs->user_pseudo; $cur->user_pwd = crypt::createPassword(); $cur->user_email = $rs->user_email; $cur->user_lang = $rs->user_lang; $cur->user_tz = $this->core->blog->settings->system->blog_timezone; $cur->user_post_status = $rs->user_post_pub ? 1 : -2; $cur->user_options = new ArrayObject(array('edit_size' => (int) $rs->user_edit_size, 'post_format' => $rs->user_post_format)); $permissions = array(); switch ($rs->user_level) { case '0': $cur->user_status = 0; break; case '1': # editor $permissions['usage'] = true; break; case '5': # advanced editor $permissions['contentadmin'] = true; $permissions['categories'] = true; $permissions['media_admin'] = true; break; case '9': # admin $permissions['admin'] = true; break; } $this->core->addUser($cur); $this->core->setUserBlogPermissions($rs->user_id, $this->blog_id, $permissions); } } $this->con->commit(); $db->close(); } catch (Exception $e) { $this->con->rollback(); $db->close(); throw $e; } }
/** * Creates a new user password using recovery key. Returns an array: * * - user_email * - user_id * - new_pass * * @param string $recover_key Recovery key * @return array */ public function recoverUserPassword($recover_key) { $strReq = 'SELECT user_id, user_email ' . 'FROM ' . $this->user_table . ' ' . "WHERE user_recover_key = '" . $this->con->escape($recover_key) . "' "; $rs = $this->con->select($strReq); if ($rs->isEmpty()) { throw new Exception(__('That key does not exist in the database.')); } $new_pass = crypt::createPassword(); $cur = $this->con->openCursor($this->user_table); $cur->user_pwd = $this->crypt($new_pass); $cur->user_recover_key = null; $cur->update("WHERE user_recover_key = '" . $this->con->escape($recover_key) . "'"); return array('user_email' => $rs->user_email, 'user_id' => $rs->user_id, 'new_pass' => $new_pass); }