my_article_post.php 4.4 KB

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