my_collect_put.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. require_once "../config.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once '../hostsetting/function.php';
  6. require_once "../ucenter/active.php";
  7. require_once __DIR__."/../public/snowflakeid.php";
  8. $snowflake = new SnowFlakeId();
  9. $respond=array("status"=>0,"message"=>"");
  10. if(!isset($_COOKIE["userid"])){
  11. #不登录不能新建
  12. $respond['status']=1;
  13. $respond['message']="no power create article";
  14. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  15. exit;
  16. }
  17. if(!isset($_POST["title"])){
  18. #无标题不能新建
  19. $respond['status']=1;
  20. $respond['message']="no title";
  21. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  22. exit;
  23. }
  24. $uuid = UUID::v4();
  25. add_edit_event(_COLLECTION_NEW_,$uuid);
  26. PDO_Connect(_FILE_DB_USER_ARTICLE_,_DB_USERNAME_,_DB_PASSWORD_);
  27. $query="INSERT INTO "._TABLE_COLLECTION_." (
  28. id,
  29. uid ,
  30. title ,
  31. subtitle ,
  32. summary ,
  33. article_list ,
  34. owner,
  35. owner_id,
  36. editor_id,
  37. lang ,
  38. status ,
  39. create_time ,
  40. modify_time
  41. ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ";
  42. $sth = $PDO->prepare($query);
  43. $sth->execute(array(
  44. $snowflake->id() ,
  45. $uuid ,
  46. $_POST["title"] ,
  47. "" ,
  48. "",
  49. "[]" ,
  50. $_COOKIE["user_uid"] ,
  51. $_COOKIE["user_id"],
  52. $_COOKIE["user_id"],
  53. "" ,
  54. $_POST["status"] ,
  55. mTime() ,
  56. mTime()
  57. ));
  58. $respond=array("status"=>0,"message"=>"");
  59. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  60. $error = PDO_ErrorInfo();
  61. $respond['status']=1;
  62. $respond['message']=$error[2];
  63. }
  64. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  65. ?>