public function mail() { if (jet_Post('action') == 'do_mailer') { error_reporting(0); $mail = new \PHPMailer(); apply_config($mail, 'smtp'); $mail->isSMTP(); // Set mailer to use SMTP $mail->addAddress(jet_Post('to'), 'HELLO'); // Add a recipient $mail->isHTML(true); // Set email format to HTML $mail->Subject = '这是一架邮件轰炸机!'; $content = jet_Post('content'); if (!$content) { $content = '这是一架邮件轰炸机!'; } $mail->Body = $content; $mail->AltBody = strip_tags($content); if (!$mail->send()) { echo jet_JSON(array('message' => '错误: ' . $mail->ErrorInfo, 'has' => false)); } else { echo jet_JSON(array('message' => "你的邮件已经发送给" . jet_Post('to') . ",内容是{$content}" . $mail->Username, 'has' => true)); } } else { $this->render(); } }
/** * 添加 */ public function insert() { $data = jet_Post('data'); dump($data, 1); echo jet_JSON(array('status' => true)); die; }
public static function start() { $route = self::URL_parse(); $route['control'] = @trim(ucfirst($route[0])) ? @trim(ucfirst($route[0])) : "index"; $route[0] = $route['control']; $route['method'] = @trim($route[1]) ? @trim($route[1]) : 'index'; $route[1] = $route['method']; $flag = strstr($route['method'], '.html') || strstr($route['method'], '.htm') || strstr($route['method'], '.php'); $flag2 = $flag || strstr($route['method'], '.jsp'); //去掉后缀 if ($flag2) { $pattern = '/(.*?)\\.(.*?)/'; preg_match($pattern, $route['method'], $match); $route['method'] = $match[1]; } $route['method'] = str_replace('-', '_', $route['method']); //dump($route,1); //是否转入agent if ($route[0] == 'Agent' && !empty($route[1])) { if (file_exists(JET . '/agent/' . $route[1] . 'Agent.php')) { $agent_space = 'Jet\\Agent\\' . $route[1] . "Agent"; $agent = new $agent_space(); return $agent->{$route}[2](); } else { die(jet_JSON(array('msg' => '不存在该代理'))); } } if (file_exists(CTL . '/' . $route['control'] . 'Controller.php')) { $control_space = 'Jet\\Controller\\' . $route[0] . 'Controller'; $control = new $control_space(); //第二个参数为数字的情况 if (is_numeric($route['method']) && method_exists($control, 'index')) { //调用index方法并且得到id $control->index($route['method']); return 0; } //dump($route); if (method_exists($control, $route['method'])) { //判断更多参数的情况 if (isset($route[2])) { $control->{$route}['method']($route[2]); } elseif (isset($route[3])) { $control->{$route}['method']($route[2], $route[3]); } else { $control->{$route}['method'](); } } elseif (method_exists($control, 'index')) { $control->index($route['method']); //将路由数据传给index } else { $control = new Jet\Core\Controller(); //渲染404页面 $control->error_404('404 NOT FIND !'); } } else { $control = new Jet\Core\Controller(); //渲染404页面 $control->error_404('404 NOT FIND !'); } }
/** * ajaxGet 接收消息 * 接收用户消息,系统消息,todo 群组消息 */ public function ajaxGet() { $con = new Controller(); $current_user = $con->current_user(); $not = $this->model('notification')->where("is_read = 0 and receiver = 'ALL_USER' or receiver = '{$current_user}' ")->select(); if (!$not) { echo jet_JSON(array('notNum' => 0, 'has' => false)); } else { $notNum = count($not); echo jet_JSON(array('not' => $not, 'msg' => "got {$notNum} new message", 'has' => true, 'notNum' => $notNum)); } }
/** * 通过id设置消息为已读 * 这个方法用于ajax请求 */ public function setread() { $id = jet_Post('id'); if (!empty($id)) { $flag = $this->model('notification')->where($id)->setField('is_read', 1); if ($flag) { echo jet_JSON(array('message' => '设置已读成功!', 'has' => 1)); return; } else { echo jet_JSON(array('message' => '设置已读失败!', 'has' => 0)); return; } } }
/** * 注册功能 */ public function register() { if (jet_Post('action') === 'do_register') { $mail = jet_Post('mail'); $user = jet_Post('user'); $pswd = jet_Post('pswd'); $p_mail = '/^[\\w]+(\\.[\\w+])*@[\\w-]+(\\.[\\w-]+)+$/i'; $p_user = "******"; $p_pswd = "#^[A-Za-z0-9\\-_]{3,20}#"; if (!preg_match($p_mail, $mail)) { echo jet_JSON(array('msg' => '请输入正确的邮箱格式', 'has' => false)); return; } elseif (!preg_match($p_pswd, $pswd)) { echo jet_JSON(array('msg' => '请输入正确的密码,长度在3-20之间', 'has' => false)); return; } elseif (preg_match($p_user, $user)) { //判断是否有相同账号 if ($this->model('user')->where("user = '******'")->num()) { echo jet_JSON(array('msg' => '已经存在相同用户,请修改您的名字', 'has' => false)); return; } else { } //everything is ok } else { echo jet_JSON(array('msg' => '用户名格式不正确,请不要输入字符,长度在3-20之间', 'has' => false)); return; } $salt = jet_Config('jet_identity'); $reg['identity'] = md5($salt . $user); //识别码加密 $reg['pswd'] = md5($pswd); //密码MD5加密 $reg['user'] = $user; $reg['mail'] = $mail; $reg['fans'] = jet_Config('register_fans'); $reg['type'] = jet_Config('register_type'); $reg['register_time'] = date('Y-m-d h:i:s', time()); $reg['status'] = jet_Config('register_status'); //向数据库插入数据 $flag = $this->model('user')->insert($reg); if ($flag) { $flag = $this->sendVerifyMail($reg); if ($flag) { echo jet_JSON(array('msg' => '注册成功!', 'has' => true)); } else { echo jet_JSON(array('msg' => '程序出现错误,希望你能将这个错误反馈给我们!错误代码:ERROR_REG_01', 'has' => false)); } } else { echo jet_JSON(array('msg' => '程序出现错误,希望你能将这个错误反馈给我们!错误代码:ERROR_REG_02', 'has' => false)); } } else { echo jet_JSON(array('msg' => '程序出现错误,希望你能将这个错误反馈给我们!错误代码:ERROR_REG_03', 'has' => false)); } }
/** * 评论管理 */ public function comment() { //评论列表 if ($this->a == '' or $this->a == 'index' or $this->a == 'list') { $list = $this->model('comment')->select(); foreach ($list as $key => $value) { foreach ($value as $k => $v) { $attach = $list[$key]['attach']; $list[$key]['attach_title'] = $this->model('post')->where($attach)->field('title'); if ($k == 'content') { $list[$key]['content'] = strip_tags($v); //去掉html标签v } } } $this->assign('list', $list); $this->render('admin/comment/index'); } //删除操作 if ($this->a == 'd' or $this->a == 'delete') { $id = jet_Post('id'); if (strpos($id, ',')) { $flag = $this->model('comment')->delete(trim($id, ',')); //移除前后的字符, } else { $flag = $this->model('comment')->where($id)->delete(); } if ($flag) { echo jet_JSON(array('msg' => true)); } else { echo jet_JSON(array('msg' => false)); } } }
/** * 长轮询测试 */ public function polling() { if (jet_Post('id')) { $id = jet_Post('id'); $list = $this->model('post')->where("id > {$id}")->get(); if ($list) { //$list = array_slice($list,0,2); $list['has'] = true; foreach ($list as $key => $value) { $list[$key] = str_replace('"', '\'', $value); //替换双引号 $list[$key] = str_replace(':', '|=|', $list[$key]); //替换冒号 } echo jet_JSON($list); return; } else { $list['has'] = false; echo jet_JSON($list); return; } } else { $this->render(); } }