channel.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. 废弃
  4. */
  5. require_once "../config.php";
  6. require_once "../db/table.php";
  7. require_once "../public/function.php";
  8. class Channel extends Table
  9. {
  10. function __construct($redis=false) {
  11. parent::__construct(_FILE_DB_CHANNAL_, _TABLE_CHANNEL_, _DB_USERNAME_,_DB_PASSWORD_,$redis);
  12. }
  13. public function index(){
  14. switch ($_GET["view"]) {
  15. case 'studio':
  16. # code...
  17. break;
  18. case 'user':
  19. # code...
  20. break;
  21. default:
  22. # code...
  23. break;
  24. }
  25. $where["like_type"] = "like";
  26. $where["resource_type"] = $_GET["type"];
  27. $where["resource_id"] = explode($_GET["id"],",");
  28. echo json_encode($this->_index(["id","name","lang","status"],$where), JSON_UNESCAPED_UNICODE);
  29. }
  30. public function create($data=null){
  31. if($data===null){
  32. if(!isset($_COOKIE["userid"])){
  33. return;
  34. }
  35. $json = file_get_contents('php://input');
  36. $data = json_decode($json,true);
  37. $data["owner"] = $_COOKIE["userid"];
  38. }
  39. $isExist = $this->medoo->has($this->table,["owner"=>$data["owner"],"name"=>$data["name"]]);
  40. if(!$isExist){
  41. $data["id"] = UUID::v4();
  42. $data["create_time"] = mTime();
  43. $data["modify_time"] = mTime();
  44. $result = $this->_create($data,["id","owner","lang","name","summary","status","create_time","modify_time"]);
  45. }
  46. else{
  47. $this->result["ok"]=false;
  48. $this->result["message"]="is exist";
  49. $result = $this->result;
  50. }
  51. if($data===null){
  52. echo json_encode($result, JSON_UNESCAPED_UNICODE);
  53. }else{
  54. return $result;
  55. }
  56. }
  57. public function delete(){
  58. if(!isset($_COOKIE["userid"])){
  59. return;
  60. }
  61. $where["like_type"] = $_GET["like_type"];
  62. $where["resource_type"] = $_GET["resource_type"];
  63. $where["resource_id"] = $_GET["resource_id"];
  64. $where["user_id"] = $_COOKIE["userid"];
  65. $row = $this->_delete($where);
  66. if($row["data"]>0){
  67. $this->result["data"] = $where;
  68. }else{
  69. $this->result["ok"]=false;
  70. $this->result["message"]="no delete";
  71. }
  72. echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
  73. }
  74. }
  75. ?>