my_article_post.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. require_once "../db/custom_book.php";
  10. add_edit_event(_ARTICLE_EDIT_,$_POST["id"]);
  11. $respond=array("status"=>0,"message"=>"");
  12. # 检查是否有修改权限
  13. $redis = redis_connect();
  14. $article = new Article($redis);
  15. $power = $article->getPower($_POST["id"]);
  16. if($power<20){
  17. $respond["status"]=1;
  18. $respond["message"]="No Power For Edit";
  19. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  20. exit;
  21. }
  22. $_content = $_POST["content"];
  23. if($_POST["import"]=='on'){
  24. #导入自定义书
  25. $custom_book = new CustomBook($redis);
  26. $_lang = explode("_",$_POST["lang"]);
  27. if(count($_lang)===3){
  28. $lang = $_lang[2];
  29. }
  30. else if(count($_lang)===1){
  31. $lang = $_lang[0];
  32. }
  33. else{
  34. $respond["status"]=1;
  35. $respond["message"]="无法识别的语言".$_POST["lang"];
  36. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  37. exit;
  38. }
  39. $respond = $custom_book->new($_POST["title"],$_content,$lang);
  40. if($respond["status"]==0){
  41. $_content = $respond["content"];
  42. }
  43. else{
  44. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  45. exit;
  46. }
  47. }
  48. PDO_Connect(_FILE_DB_USER_ARTICLE_);
  49. $query="UPDATE article SET title = ? , subtitle = ? , summary = ?, content = ? , tag = ? , setting = ? , status = ? , receive_time= ? , modify_time= ? where id = ? ";
  50. $sth = $PDO->prepare($query);
  51. $sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"], $_content , $_POST["tag"] , $_POST["setting"] , $_POST["status"] , mTime() , mTime() , $_POST["id"]));
  52. $respond=array("status"=>0,"message"=>"");
  53. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  54. $error = PDO_ErrorInfo();
  55. $respond['status']=1;
  56. $respond['message']=$error[2];
  57. }
  58. else{
  59. if($redis){
  60. $redis->del("article://".$_POST["id"]);
  61. $redis->del("power://article/".$_POST["id"]);
  62. }
  63. }
  64. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  65. ?>