my_article_put.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. 新建文章
  4. */
  5. require_once "../config.php";
  6. require_once "../public/_pdo.php";
  7. require_once '../public/function.php';
  8. require_once '../hostsetting/function.php';
  9. require_once "../ucenter/active.php";
  10. $respond=array("ok"=>true,"message"=>"");
  11. if(!isset($_COOKIE["userid"])){
  12. #不登录不能新建
  13. $respond['ok']=false;
  14. $respond['message']="no power create article";
  15. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  16. exit;
  17. }
  18. if(!isset($_POST["title"])){
  19. #无标题不能新建
  20. $respond['ok']=false;
  21. $respond['message']="no title";
  22. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  23. exit;
  24. }
  25. if(isset($_POST["content"])){
  26. $content = $_POST["content"];
  27. }
  28. else{
  29. $content = "";
  30. }
  31. PDO_Connect(_FILE_DB_USER_ARTICLE_);
  32. $query="INSERT INTO article ( id, title , subtitle , summary , content , tag , owner, setting , status , create_time , modify_time , receive_time ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ";
  33. $sth = $PDO->prepare($query);
  34. $uuid = UUID::v4();
  35. //写入日志
  36. add_edit_event(_ARTICLE_NEW_,$uuid);
  37. #新建文章默认私有
  38. $sth->execute(array($uuid , $_POST["title"] , "" ,"", $content , "" , $_COOKIE["userid"] , "{}" , 10 , mTime() , mTime() , mTime() ));
  39. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  40. $error = PDO_ErrorInfo();
  41. $respond['ok']=false;
  42. $respond['message']=$error[2];
  43. }
  44. else{
  45. $respond['data']=["id"=>$uuid,"title"=>$_POST["title"]];
  46. }
  47. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  48. ?>