function addBatch() { $users = str_getcsv($_POST['users']); $saved = TRUE; $testid = $this->session->userdata('testid'); $test = new Test(); $test->get_by_id($testid); $this->load->helper("pinyin"); foreach ($users as $user) { $u = new User(); $u->uStudId = $user[0]; $u->uName = str_replace(' ', '', $user[1]); //$u->uPassword = $user[0];//密码等于用户的学号 $pinyin = get_pinyin($u->uName); $u->uPassword = str_replace('_', '', $pinyin); //用拼音作为密码 $u->uType = 'student'; if (!$u->save()) { $saved = FALSE; break; } $test->save($u); } return 'saved'; }
public function import($wf) { if (file_exists($wf) === FALSE) { $this->_error("文件:{$wf}, 不存在!"); return FALSE; } $words = file($wf, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $words = array_unique($words); if (count($words) == 0) { $this->_error("没有需要导入的关键词!"); return FALSE; } $this->load->helper('pinyin'); print_r("开始执行导入, 共" . count($words) . "个关键词\n"); $result = 0; foreach ($words as $word) { $alpha = ucwords(get_pinyin(mb_substr($word, 0, 1, 'UTF8'), TRUE)); $entry = array('keyword' => $word, 'alpha' => $alpha == '_' ? 'X' : $alpha); $this->db->replace('article_tags', $entry) && $result++; if ($result <= 0) { $this->_error('导入操作失败,请检查文件后,重试'); } } print_r("导入完成, 成功导入" . count($words) . "个关键词\n"); }
/** * 第三方登录 */ public function third_login() { $type = I('get.type'); $file = ROOT_PATH . 'plugins/connect/' . $type . '.php'; if (file_exists($file)) { include_once $file; } else { show_message(L('process_false'), L('relogin_lnk'), url('login', array('referer' => urlencode($this->back_act))), 'error'); } $url = __URL__ . '/index.php?m=default&c=user&a=third_login&type=' . $type; $info = model('ClipsBase')->get_third_user_info($type); // 判断是否安装 if (!$info) { show_message(L('no_register_auth'), L('relogin_lnk'), url('login', array('referer' => urlencode($this->back_act))), 'error'); } $obj = new $type($info); if ($_GET['code'] && $_GET['code'] != '') { // 授权成功 返回登录 if ($obj->call_back($info, $url, $_GET['code'])) { if ($_SESSION['access_token']) { $res = new $type($info, $_SESSION['access_token']); $openid = $res->get_openid(); // 获取用户信息 $userinfo = $res->get_user_info($openid); // 处理数据 $userinfo['aite_id'] = $type . '_' . $openid; // 添加登录标示 $userinfo['user_name'] = str_replace("'", "", empty($userinfo['name']) ? $userinfo['nickname'] : $userinfo['name']); if (model('Users')->get_one_user($userinfo['aite_id'])) { // 已有记录 self::$user->set_session($userinfo['user_name']); self::$user->set_cookie($userinfo['user_name']); model('Users')->update_user_info(); model('Users')->recalculate_price(); $jump_url = empty($this->back_act) ? url('index') : $this->back_act; $this->redirect($jump_url); } // 无记录 if (model('Users')->check_user_name($userinfo['user_name'])) { // 重名处理 $userinfo['user_name'] = $userinfo['user_name'] . '_' . $type . rand(10000, 99999); } $userinfo['email'] = empty($userinfo['email']) ? get_pinyin($userinfo['user_name']) . '@' . get_top_domain() : $userinfo['email']; // 插入数据库 model('Users')->third_reg($userinfo); self::$user->set_session($userinfo['user_name']); self::$user->set_cookie($userinfo['user_name']); model('Users')->update_user_info(); model('Users')->recalculate_price(); $jump_url = empty($this->back_act) ? url('index') : $this->back_act; $this->redirect($jump_url); } } else { show_message(L('process_false'), L('relogin_lnk'), url('login', array('referer' => urlencode($this->back_act))), 'error'); } } else { // 开始授权登录 $url = $obj->act_login($info, $url); ecs_header("Location: " . $url . "\n"); exit; } }
private function mappedField($rows) { $return = array(); $this->load->helper('pinyin'); $existcates = $this->db->get('categories')->result_array(); function tmp_call($v) { return (int) $v['id']; } $existscateis = array_map("tmp_call", $existcates); foreach ($rows as $k => $v) { if (in_array($v['cateid'], $existscateis)) { continue; } $return[$k]['id'] = $v['cateid']; $return[$k]['name'] = $v['catename']; $return[$k]['description'] = $v['catename']; $return[$k]['excerpt'] = $v['catename']; $return[$k]['parent_id'] = 0; if (!empty($v['parent'])) { $return[$k]['parent_id'] = $v['parent']['cateid']; } $return[$k]['sequence'] = 0; $return[$k]['seo_title'] = $this->config->item('company_name') . '->' . $v['catename']; $return[$k]['slug'] = get_pinyin($v['catename'], false, true); $return[$k]['meta'] = '<meta name="request" content="-app-absearch-category-' . $v['cateid'] . '" /><meta name="description" content="衣联网' . $v['catename'] . '价格最低,款式最多,促销活动一目了然,让你省钱又放心!" /><meta name="keywords" content="' . $v['catename'] . '" /><meta name="author" content="www.eelly.com" />'; } return $return; }