Пример #1
0
 public function login()
 {
     if ($this->AjaxRequest) {
         if (!($name = $this->post("name"))) {
             return $this->renderJson(['code' => 400, 'errmsg' => 'Missing required parameter:$username.']);
         }
         if (!($passwd = $this->post("passwd"))) {
             return $this->renderjson(['code' => 400, 'errmsg' => "Missing required parameter: {$password}"]);
         }
         $userModel = Model::make("User");
         if (!($userObj = $userModel->getUserByName($name))) {
             return $this->renderJson(['code' => 401, "errmsg" => "Incorrect password input"]);
         }
         //var_dump( $passwd, $userObj->passwd );
         if (!tPassword::verify($passwd, $userObj->passwd)) {
             return $this->renderJson(['code' => 401, 'errmsg' => "incorrect password input"]);
         }
         tSession::login($userObj, $this->server("HTTP_USER_AGENT"));
         $this->updateLoginInfo($userObj, $this->server("REMOTE_ADDR"));
         if ($http_referer = $this->post("http_referer")) {
             $go_url = $http_referer;
         } else {
             $go_url = "/admin/dashBoard.html";
         }
         return $this->renderJson(['code' => 200, 'errmsg' => 'ok', 'go_url' => $go_url]);
     } else {
         return $this->renderJson(["code" => 403, "errmsg" => "Access forbindden"]);
     }
 }
Пример #2
0
 public function __construct()
 {
     parent::__construct();
     $this->session = Factory::make("session");
     $this->CateModel = Model::make("Category");
     $this->PostModel = Model::make("Post");
 }
Пример #3
0
 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"]);
     }
 }
Пример #4
0
 public function index()
 {
     $pageNum = 24;
     if (!($page = $this->get('page'))) {
         $page = 1;
     }
     $skip = ($page - 1) * $pageNum;
     $FileModel = Model::make("file");
     $files = $FileModel->getFiles($skip, $pageNum);
     $totalFiles = $FileModel->count();
     $totalPage = ceil($totalFiles / $pageNum);
     $afiles = [];
     $filelength = count($files);
     foreach ($files as $file) {
         $nfile = [];
         $nfile['url'] = str_replace(ROOT_PATH, '', Config::get("SAVE-UPLOAD-DIR") . '/' . $file->filename);
         $nfile['id'] = $file->id;
         $afiles[] = $nfile;
     }
     if ($this->AjaxRequest) {
         return $this->renderJson(['code' => 200, "files" => $afiles]);
     } else {
         $this->assign("totalPage", $totalPage);
         $this->assign("files", $afiles);
         $this->assign("site", $this->getSiteInfo());
         $this->assign("morefile", $filelength < $totalFiles);
         return $this->display("adminArchives.html");
     }
 }
Пример #5
0
 public function submit()
 {
     if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") {
         $msg = [];
         $msg['name'] = strip_tags($this->post("name"));
         $msg['email'] = strip_tags($this->post("email"));
         $msg['gravatar'] = md5($msg['email']);
         $msg['msgbody'] = strip_tags($this->post("text"));
         $msg['created_at'] = date("Y-m-d H:i:s");
         $MessageModel = Model::make("Message");
         $id = $MessageModel->insertGetId($msg);
         /******************* 插入Feed ******************/
         $feed = [];
         $feed['name'] = $msg['name'];
         $feed['email'] = $msg['email'];
         $feed['gravatar'] = $msg['gravatar'];
         $feed['content'] = $feed['name'] . "给你发来私信:<br/><a href='/Admin/Message/View/" . $id . ".html' style='font-size:14px;color:#0083D6;'>" . mb_substr($msg['msgbody'], 0, 60, "utf-8") . "</a>";
         $feed['created_at'] = date("Y-m-d H:i:s");
         Feed::add($feed);
         /***************** Sending email asyn way **********/
         popen("php " . APP_PATH . "/task/MailTo.php -fmessageEmail -d" . $id . "&", "r");
         return $this->renderJson(200, "ok");
     } else {
         return $this->renderJson(403, "Access denied!");
     }
 }
Пример #6
0
 private function getRecentImages()
 {
     $FileModel = Model::make("file");
     $files = $FileModel->getFiles(0, 6);
     $ret_files = [];
     foreach ($files as $file) {
         $ret_files[]['url'] = str_replace(ROOT_PATH, "", Config::get("SAVE-UPLOAD-DIR") . "/" . $file->filename);
     }
     return $ret_files;
 }
Пример #7
0
 private function getFeeds()
 {
     $FeedModel = Model::make("Feed");
     $feeds = $FeedModel->getFeeds(10);
     $feedCount = $FeedModel->count();
     $feeds = iterator_to_array($feeds);
     foreach ($feeds as $k => $feed) {
         $feeds[$k]['humanLookTime'] = DateTime::humanLook($feed->created_at);
     }
     return ["FeedCount" => $feedCount, "feeds" => $feeds];
 }
Пример #8
0
 public function delPost()
 {
     $id = $this->id;
     $categid = $this->category;
     $this->delete();
     $cateid_array = explode(",", $categid);
     $CateModel = Model::make("Category");
     foreach ($cateid_array as $k => $cid) {
         $Category = $CateModel->getCategoryById($cid);
         $Category->deletePost($id);
     }
 }
Пример #9
0
 public function comment()
 {
     if (!($postId = intval($this->post("postId")))) {
         return $this->renderJson(400, "Invalid input post id!");
     }
     $commentModel = Model::make("Comment");
     $comments = $commentModel->where("resp", 0)->where("postId", $postId)->get();
     foreach ($comments as $k => $comment) {
         $comments[$k]["subcomment"] = iterator_to_array($comment->getSubComments($comment->id));
     }
     return $this->renderJson(["code" => 200, "comments" => iterator_to_array($comments)]);
 }
Пример #10
0
 public function submit()
 {
     if ($this->AjaxRequest) {
         $siteModel = Model::make("SiteInfo");
         $site = [];
         foreach ($this->post as $name => $val) {
             $site[$name] = $val;
         }
         $siteModel->addSiteInfo($site);
         return $this->renderJson(200, "ok");
     }
 }
Пример #11
0
 public function ajaxLoadFeed()
 {
     if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") {
         $FeedModel = Model::make("Feed");
         $feeds = $FeedModel->getFeeds(5);
         $feeds = iterator_to_array($feeds);
         foreach ($feeds as $k => $feed) {
             $feeds[$k]['humanLookTime'] = DateTime::humanLook($feed->created_at);
         }
         return $this->renderJson(['code' => 200, 'feeds' => $feeds]);
     } else {
         return $this->renderJson(403, "Access denied!");
     }
 }
Пример #12
0
 /**
  * get all tags
  */
 public static function getTags()
 {
     $PostModel = Model::make("Post");
     $tags = $PostModel->select("tags")->get();
     $tags = iterator_to_array($tags);
     $tagsInOne = [];
     foreach ($tags as $tag) {
         if ($tag->tags == '') {
             continue;
         }
         $tagsInOne = array_merge($tagsInOne, explode('|', $tag->tags));
     }
     return $tagsInOne;
 }
Пример #13
0
 public function messageEmail($msgId)
 {
     $messageModel = Model::make("Message");
     if (!($msg = $messageModel->getMessageById($msgId))) {
         return;
     }
     $this->mail->addAddress("*****@*****.**", "root");
     $this->mail->addReplyTo($msg->email, $msg->name);
     $this->mail->isHTML(TRUE);
     $this->mail->Subject = "您收到一条私信!";
     $this->mail->Body = '<div style="width:1000px;">' . '<div style="width:100px; float:left;">' . '<img src="" style="width:60px;height:60px;borderr-radius:100%;"/>' . '</div><div style="width:900px;float:left;">' . $msg->name . "&nbsp;&nbsp;" . date("Y-m-d H:i:s") . "<br/>" . $msg->msgbody . '</div></div>';
     if (!$this->mail->send()) {
         Log::error($this->mail->ErrorInfo);
     }
 }
Пример #14
0
 protected function getSiteInfo()
 {
     $SiteModel = Model::make("SiteInfo");
     $info = $SiteModel->get();
     $info = iterator_to_array($info);
     $info_combined = [];
     foreach ($info as $k => $if) {
         $info_combined[$if->meta] = $if->val;
     }
     $User = Model::make("User");
     $admin = $User->find(1);
     $info_combined["admin_sname"] = $admin->sname;
     $info_combined['admin_name'] = $admin->name;
     $info_combined['admin_avatar'] = $admin->avatar;
     $info_combined['admin_email'] = $admin->email;
     $info_combined['admin_id'] = $admin->id;
     return $this->SiteInfo = $info_combined;
 }
Пример #15
0
 public static function boot()
 {
     date_default_timezone_set("Asia/Shanghai");
     if (version_compare(PHP_VERSION, 5.5, "<")) {
         exit("PHP required 5.5+");
     }
     set_exception_handler(array(__CLASS__, 'panic'));
     tRedis::newInstance();
     Route::initCacheRoute();
     Config::init();
     Dependency::initCache();
     Model::initCache();
     Factory::make("session")->start();
     $self = new static();
     $self->route = Route::newInstance();
     $self->request = Request::newInstance();
     return $self;
 }
Пример #16
0
 public function deleteFiles()
 {
     if ($this->AjaxRequest) {
         if (!($fileIds = $this->post("fileIds"))) {
             return $this->renderJson(400, "Missing requried parameter: fileIds");
         }
         $fileArray = explode(",", $fileIds);
         $FileModel = Model::make("file");
         foreach ($fileArray as $fileId) {
             $file = $FileModel->find($fileId);
             $fileWithPath = Config::get('SAVE-UPLOAD-DIR') . '/' . $file->filename;
             if (is_file($fileWithPath)) {
                 unlink($fileWithPath);
             }
             $file->delete();
         }
         return $this->renderJson(200, "ok");
     } else {
         return $this->renderString("Access denied");
     }
 }
Пример #17
0
 public function viewComment($cid)
 {
     if (!($theComment = $this->commentModel->getCommentById($cid))) {
         $this->assign("post", null);
         return $this->display("commentView.html");
     }
     $post = $theComment->post;
     $category_arr = [];
     $postcate = explode(",", $post->category);
     $CategoryModel = Model::make("Category");
     foreach ($postcate as $cate) {
         $category_arr[] = $CategoryModel->getCategoryById($cate);
     }
     $comRepl = $this->commentModel->where("resp", $cid)->get();
     $comments = $post->comments()->where("id", "!=", $cid)->where("resp", 0)->get();
     $this->assign("post", $post);
     $this->assign("postCategory", $category_arr);
     $this->assign("thecomment", $theComment);
     $this->assign("comRepls", iterator_to_array($comRepl));
     $this->assign("comments", $comments);
     $this->assign("user", tSession::getLoginedUserInfo());
     return $this->display("commentView.html");
 }
Пример #18
0
 public function getAdmin()
 {
     $userModel = Model::make("User");
     $this->admin = $userModel->getAdmin();
 }
Пример #19
0
 public function del()
 {
     if (!($postId = $this->post("postId"))) {
         return $this->renderJson(["code" => 400, "errmsg" => "Missing requried parameter:postId"]);
     }
     $postIdList = explode(",", $postId);
     $CommentModel = Model::make("Comment");
     foreach ($postIdList as $pid) {
         if ($Post = $this->PostModel->getPostById($pid)) {
             $Post->delPost();
         }
     }
     $CommentModel->destroy($postIdList);
     return $this->renderJson(['code' => 200, 'errmsg' => "ok"]);
 }
Пример #20
0
 public function __construct()
 {
     parent::__Construct();
     $this->msgModel = Model::make("Message");
     $this->siteInfo = $this->getSiteInfo();
 }
Пример #21
0
 public function tagPost($tag)
 {
     $postModel = Model::make("Post");
     $posts = $postModel->getTagPosts($tag);
     $this->assign("posts", $posts);
     $this->display("index.html");
 }