my_article_post.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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','channal','book','paragraph','begin','end','tag','author','editor','text','language','ver','status','strlen','create_time','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. $_POST["channal"],
  67. $currBook,
  68. $para,
  69. $sentNum,
  70. $sentNum,
  71. "",
  72. "[]",
  73. $_COOKIE["userid"],
  74. $data,
  75. $_POST["lang"],
  76. 1,
  77. 1,
  78. mb_strlen($data,"UTF-8"),
  79. mTime(),
  80. mTime(),
  81. mTime()
  82. ));
  83. }
  84. }
  85. $PDO->commit();
  86. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  87. /* 识别错误且回滚更改 */
  88. $PDO->rollBack();
  89. $error = PDO_ErrorInfo();
  90. $respond['status']=1;
  91. $respond['message']=$error[2];
  92. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  93. exit;
  94. }
  95. else{
  96. $respond['status']=0;
  97. $respond['message']="成功";
  98. $_content = $newText;
  99. }
  100. }
  101. }
  102. PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
  103. $query="UPDATE article SET title = ? , subtitle = ? , summary = ?, content = ? , tag = ? , setting = ? , status = ? , receive_time= ? , modify_time= ? where id = ? ";
  104. $sth = $PDO->prepare($query);
  105. $sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"], $_content , $_POST["tag"] , $_POST["setting"] , $_POST["status"] , mTime() , mTime() , $_POST["id"]));
  106. $respond=array("status"=>0,"message"=>"");
  107. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  108. $error = PDO_ErrorInfo();
  109. $respond['status']=1;
  110. $respond['message']=$error[2];
  111. }
  112. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  113. ?>