my_article_post.php 4.2 KB

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