my_article_put.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. require_once __DIR__."/../public/snowflakeid.php";
  11. $snowflake = new SnowFlakeId();
  12. $respond=array("ok"=>true,"message"=>"");
  13. if(!isset($_COOKIE["userid"])){
  14. #不登录不能新建
  15. $respond['ok']=false;
  16. $respond['message']="no power create article";
  17. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  18. exit;
  19. }
  20. if(!isset($_POST["title"])){
  21. #无标题不能新建
  22. $respond['ok']=false;
  23. $respond['message']="no title";
  24. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  25. exit;
  26. }
  27. if(isset($_POST["content"])){
  28. $content = $_POST["content"];
  29. }
  30. else{
  31. $content = "";
  32. }
  33. PDO_Connect(_FILE_DB_USER_ARTICLE_,_DB_USERNAME_,_DB_PASSWORD_);
  34. $query="INSERT INTO "._TABLE_ARTICLE_."
  35. (
  36. id,
  37. uid,
  38. title ,
  39. subtitle ,
  40. summary ,
  41. content ,
  42. owner,
  43. owner_id,
  44. editor_id,
  45. setting ,
  46. status ,
  47. create_time ,
  48. modify_time
  49. ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? ,? ,?, ? , ? ) ";
  50. $sth = $PDO->prepare($query);
  51. $uuid = UUID::v4();
  52. //写入日志
  53. add_edit_event(_ARTICLE_NEW_,$uuid);
  54. #新建文章默认私有
  55. $sth->execute(array(
  56. $snowflake->id() ,
  57. $uuid ,
  58. $_POST["title"] ,
  59. "" ,
  60. "",
  61. $content ,
  62. $_COOKIE["user_uid"] ,
  63. $_COOKIE["user_id"] ,
  64. $_COOKIE["user_id"] ,
  65. "{}" ,
  66. 10 ,
  67. mTime() ,
  68. mTime()
  69. ));
  70. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  71. $error = PDO_ErrorInfo();
  72. $respond['ok']=false;
  73. $respond['message']=$error[2];
  74. }
  75. else{
  76. $respond['data']=["id"=>$uuid,"title"=>$_POST["title"]];
  77. }
  78. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  79. ?>