my_article_post.php 4.5 KB

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