my_article_post.php 4.5 KB

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