/** * Post List * @return void */ public function index() { $pageNum = 5; $where = []; if (!($page = intval($this->get("page")))) { $page = 1; } $skip = ($page - 1) * $pageNum; $select = ["id", "ptype", "title", "url", "public", "html", "created_at"]; $PostList = $this->PostModel->select($select)->skip($skip)->limit($pageNum)->orderby("created_at", "DESC")->get(); $postlists = []; $imgReg = '/<img\\s+src=[\'"].*[\'"]\\s*>/i'; foreach ($PostList as $post) { if (preg_match($imgReg, $post->html, $mat)) { $post->first_img = $mat[0]; } $post->summary = mb_substr(strip_tags($post->html), 0, 200, "utf-8"); $post->ptype = ucfirst($post->ptype); $postlists[] = $post; } if ($this->AjaxRequest) { return $this->renderJson(['code' => 200, "postList" => $postlists]); } else { $Category = $this->CateModel->get(); $this->assign("categories", $Category); $this->assign("postList", $postlists); $this->assign("site", $this->getSiteInfo()); $this->assign("user", tSession::getLoginedUserInfo()); $this->display("adminPostList.html"); } }
public function chpwd() { if ($this->AjaxRequest) { $user = tSession::getLoginedUserInfo(); $userModel = Model::make("User"); $userObj = $userModel->getUserById($user->id); if (!($old = $this->post("old"))) { return $this->renderJson(400, "Missing required parameter:old password!"); } if (!($newPwd = $this->post("new"))) { return $this->renderJson(400, "Missing requried parameter:new password"); } if (!($confirm = $this->post("confirm"))) { return $this->renderJson(400, "Missing requred parameter:confirm password!"); } if ($newPwd !== $confirm) { return $this->renderJson(400, "两次新密码输入不相同!"); } if (!tPassword::verify($old, $userObj->passwd)) { return $this->renderJson(400, "原密码不正确!"); } $userObj->passwd = tPassword::hash($newPwd); $userObj->save(); return $this->renderJson(["code" => 200, "errmsg" => "ok"]); } }
public function reply() { $mid = intVal($this->post("mid")); $resbody = nl2br(strip_tags($this->post("content"))); if (!($msg = $this->msgModel->getMessageById($mid))) { return $this->renderJson(401, "消息不存在!"); } $user = tSession::getLoginedUserInfo(); $Resp = []; $Resp['resp'] = $mid; $Resp['name'] = $user->name; $Resp['email'] = $user->email; $Resp['gravatar'] = $user->avatar; $Resp['msgbody'] = $resbody; $Resp['created_at'] = date("Y-m-d H:i:s"); $this->msgModel->insert($Resp); $mailer = Mailer::newInstance(); $mailer->addAddress($msg->email, $msg->name); $mailer->addReplyTo($user->email, $user->name); $mailer->isHTML(TRUE); $mailer->Subject = "来自 " . $this->siteInfo['site_name'] . " 的私信回复"; $mailer->Body = "<img src='" . $user->avatar . "' style='width:50px;height:50px;border-radius:100%;float:left; margin-right:1em;'/> " . $user->name . " " . date("Y-m-d H:i:s") . "<br/>" . $resbody . "<div style='width:100%;float:left;border-top:1px dashed #CCC;padding-top:1em;margin-top:1em;'>您在" . $msg->created_at . "发来的私信内容:<br/>" . $msg->msgbody . "</div>"; if (!$mailer->send()) { Log::error($mailer->ErrorInfo); } return $this->renderJson(200, "ok"); }
public function index() { $PostModel = Model::make("Post"); $CategoryModel = Model::make("Category"); $CommentModel = Model::make("Comment"); $MessageModel = Model::make("Message"); $AttachmentModel = Model::make("file"); $postNum = $PostModel->where("public", 1)->count(); $draftNum = $PostModel->where("public", 0)->count(); $CategoryNum = $CategoryModel->count(); $CommentNum = $CommentModel->count(); $newMessage = $MessageModel->where("resp", 0)->orderBy("created_at", "DESC")->get(); $attachment = $AttachmentModel->count(); $this->assign("totalCategoryNum", $CategoryNum); $this->assign("totalPostNum", $postNum); $this->assign("draftNum", $draftNum); $this->assign("newMsgCount", count($newMessage)); $this->assign("files", $this->getRecentImages()); $this->assign("AttachmentCount", $attachment); $categories = $this->CateModel->get(); $this->assign("categories", $categories); $this->assign("user", tSession::getLoginedUserInfo()); $this->assign("site", $this->getSiteInfo()); $this->display("adminCategory.html"); }
protected function falseHandler() { tSession::clear(); if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") { exit(json_encode(["success" => 0, "message" => "登陆已过期!请重新登陆后操作!"])); } else { Route::redirect("sign"); exit; } }
public function index() { $posts = $this->fetchPosts(1, 10); $this->assign("posts", $posts); if ($loginedUser = tSession::getLoginedUserInfo()) { $this->assign("adminlogined", true); $this->assign("loginedUser", $loginedUser); } $this->display("index.html"); }
public function index() { $FeedModel = Model::make("Feed"); $feeds = $FeedModel->getFeeds(20); $feeds = iterator_to_array($feeds); foreach ($feeds as $k => $feed) { $feeds[$k]['humanLookTime'] = DateTime::humanLook($feed->created_at); } $this->assign("feeds", $feeds); $this->assign("user", tSession::getLoginedUserInfo()); return $this->display("feeds.html"); }
protected function falseHandler() { tSession::clear(); $req = Factory::make("request"); if (HTTP_METHOD == "GET") { setCookie("hl_http_referer", Route::get_currentUri(), time() + 3600, "/"); } if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") { exit(json_encode(["code" => 503, "errmsg" => "登陆已过期,请重新登陆", "go_url" => "/admin/entrance.html"])); } else { Route::redirect("sign"); exit; } }
public function resp() { if (!($cid = intval($this->post("cid")))) { return $this->renderJson(400, "Invalid input parameter:cid"); } if (!($content = strip_tags($this->post("resContent")))) { return $this->renderJson(400, "Invalid input response content!"); } $comment = $this->commentModel->getCommentById($cid); $post = $comment->post; $user = tSession::getLoginedUserInfo(); $resp = []; $resp['resp'] = $cid; $resp['postId'] = $post->id; $resp['name'] = $user->name; $resp['email'] = $user->email; $resp['gravatar'] = $user->avatar; $resp['content'] = $content; $resp['created_at'] = date("Y-m-d H:i:s"); $this->commentModel->insert($resp); /** * Send an email to original commentor; */ $site = $this->getSiteInfo(); $mail = Mailer::newInstance(); $mail->addAddress($comment->email, $comment->name); $mail->addReplyTo($user->email, $user->name); $mail->isHTML(TRUE); $mail->Subject = "来自{$user->name} 的回复!"; $mail->Body = "{$content}"; $mail->Body .= "<hr/>原文地址:<a href='http://{$site['site_domain']}/Blog/{$post->url}.html' target='_blank'>" . $post->title . "</a><br/>"; $mail->Body .= "您在{$comment->created_at}发表的评论:<br/>" . $comment->content; if (!$mail->send()) { Log::error($mail->ErrorInfo); } return $this->renderJson(200, "ok"); }
public function logout() { tSession::clear(); $goRoute = Route::getRouteUri("index"); Route::redirect($goRoute[1]); }
public function index() { $this->assign("site", $this->getSiteInfo()); $this->assign("user", tSession::getLoginedUserInfo()); return $this->display("adminSettings.html"); }