my_article_post.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once '../hostsetting/function.php';
  6. $respond=array("status"=>0,"message"=>"");
  7. $_content = $_POST["content"];
  8. if($_POST["import"]=='on'){
  9. $sent = explode("\n",$_POST["content"]);
  10. if($sent && count($sent)>0){
  11. $setting = new Hostsetting();
  12. $max_book = $setting->get("max_book_number");
  13. if($max_book){
  14. $currBook = $max_book+1;
  15. $setbooknum = $setting->set("max_book_number",$currBook);
  16. if($setbooknum==false){
  17. $respond["status"]=1;
  18. $respond["message"]="设置书号错误";
  19. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  20. exit;
  21. }
  22. }
  23. else{
  24. $respond["status"]=1;
  25. $respond["message"]="获取书号错误";
  26. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  27. exit;
  28. }
  29. PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
  30. /* 开始一个事务,关闭自动提交 */
  31. $PDO->beginTransaction();
  32. $query="INSERT INTO sentence ('id','block_id','book','paragraph','begin','end','tag','author','editor','text','language','ver','status','strlen','modify_time','receive_time') VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  33. $sth = $PDO->prepare($query);
  34. $para = 1;
  35. $sentNum = 0;
  36. $newText = "";
  37. foreach ($sent as $data) {
  38. $data = trim($data);
  39. if($data==""){
  40. $para++;
  41. $sentNum = 0;
  42. $newText .="\n";
  43. continue;
  44. }
  45. else{
  46. $sentNum=$sentNum+10;
  47. }
  48. if(mb_substr($data,0,2,"UTF-8")=="{{"){
  49. $newText .=$data."\n";
  50. }
  51. else{
  52. $newText .='{{'."{$currBook}-{$para}-{$sentNum}-{$sentNum}"."}}\n";
  53. $sth->execute(
  54. array(UUID::v4(),
  55. "",
  56. $currBook,
  57. $para,
  58. $sentNum,
  59. $sentNum,
  60. "",
  61. "[]",
  62. $_COOKIE["userid"],
  63. $data,
  64. "my",
  65. 1,
  66. 1,
  67. mb_strlen($data,"UTF-8"),
  68. mTime(),
  69. mTime()
  70. ));
  71. }
  72. }
  73. $PDO->commit();
  74. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  75. /* 识别错误且回滚更改 */
  76. $PDO->rollBack();
  77. $error = PDO_ErrorInfo();
  78. $respond['status']=1;
  79. $respond['message']=$error[2];
  80. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  81. exit;
  82. }
  83. else{
  84. $respond['status']=0;
  85. $respond['message']="成功";
  86. $_content = $newText;
  87. }
  88. }
  89. }
  90. PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
  91. $query="UPDATE article SET title = ? , subtitle = ? , summary = ?, content = ? , tag = ? , setting = ? , status = ? , receive_time= ? , modify_time= ? where id = ? ";
  92. $sth = $PDO->prepare($query);
  93. $sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"], $_content , $_POST["tag"] , $_POST["setting"] , $_POST["status"] , mTime() , mTime() , $_POST["id"]));
  94. $respond=array("status"=>0,"message"=>"");
  95. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  96. $error = PDO_ErrorInfo();
  97. $respond['status']=1;
  98. $respond['message']=$error[2];
  99. }
  100. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  101. ?>