my_article_put.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_,_DB_USERNAME_,_DB_PASSWORD_);
  32. $query="INSERT INTO "._TABLE_ARTICLE_." (
  33. uid,
  34. title ,
  35. subtitle ,
  36. summary ,
  37. content ,
  38. owner,
  39. owner_id,
  40. editor_id,
  41. setting ,
  42. status ,
  43. create_time ,
  44. modify_time
  45. ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? ,? ,?, ? , ? ) ";
  46. $sth = $PDO->prepare($query);
  47. $uuid = UUID::v4();
  48. //写入日志
  49. add_edit_event(_ARTICLE_NEW_,$uuid);
  50. #新建文章默认私有
  51. $sth->execute(array($uuid , $_POST["title"] , "" ,"", $content , $_COOKIE["user_uid"] , $_COOKIE["user_id"] , $_COOKIE["user_id"] , "{}" , 10 , mTime() , mTime() ));
  52. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  53. $error = PDO_ErrorInfo();
  54. $respond['ok']=false;
  55. $respond['message']=$error[2];
  56. }
  57. else{
  58. $respond['data']=["id"=>$uuid,"title"=>$_POST["title"]];
  59. }
  60. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  61. ?>