2
0

function.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. require_once "../config.php";
  3. require_once "../share/function.php";
  4. require_once "../db/table.php";
  5. class Channal extends Table
  6. {
  7. function __construct($redis=false) {
  8. parent::__construct(_FILE_DB_CHANNAL_, _TABLE_CHANNEL_, _DB_USERNAME_,_DB_PASSWORD_,$redis);
  9. }
  10. public function getChannal($id){
  11. if(empty($id)){
  12. return false;
  13. }
  14. $query = "SELECT * FROM ".$this->table." WHERE uid =? ";
  15. $stmt = $this->dbh->prepare($query);
  16. $stmt->execute(array($id));
  17. $channal = $stmt->fetch(PDO::FETCH_ASSOC);
  18. if($channal){
  19. return $channal;
  20. }
  21. else{
  22. return false;
  23. }
  24. }
  25. public function getTitle($id)
  26. {
  27. if (isset($id)) {
  28. $query = "SELECT name FROM ".$this->table." WHERE uid = ? ";
  29. $stmt = $this->dbh->prepare($query);
  30. $stmt->execute(array($id));
  31. $channal = $stmt->fetch(PDO::FETCH_ASSOC);
  32. if ($channel) {
  33. return $channel["name"];
  34. } else {
  35. return "";
  36. }
  37. } else {
  38. return "";
  39. }
  40. }
  41. public function insert($data){
  42. }
  43. public function update($data){
  44. }
  45. public function delete($data){
  46. }
  47. public function getPower($id){
  48. #查询用户对此channel是否有权限
  49. if(isset($_COOKIE["user_id"])){
  50. $userId = $_COOKIE["user_id"];
  51. }
  52. else{
  53. $userId='0';
  54. }
  55. if($this->redis!==false){
  56. $power = $this->redis->hGet("power://channel/".$id,$userId);
  57. if($power!==FALSE){
  58. return $power;
  59. }
  60. }
  61. $channelPower = 0;
  62. $query = "SELECT owner_uid,status FROM "._TABLE_CHANNEL_." WHERE uid=? and status>0 ";
  63. $stmt = $this->dbh->prepare($query);
  64. $stmt->execute(array($id));
  65. $channel = $stmt->fetch(PDO::FETCH_ASSOC);
  66. if($channel){
  67. if(!isset($_COOKIE["user_id"]) ){
  68. #未登录用户
  69. if($channel["status"]==30){
  70. #全网公开有建议权限
  71. return 10;
  72. }
  73. else{
  74. #其他状态没有任何权限
  75. return 0;
  76. }
  77. }
  78. if($channel["owner_uid"]==$_COOKIE["user_uid"]){
  79. return 30;
  80. }
  81. else if($channel["status"]>=30){
  82. #全网公开的 可以提交pr
  83. $channelPower = 10;
  84. }
  85. }
  86. #查询共享权限,如果共享权限更大,覆盖上面的的
  87. $sharePower = share_get_res_power($_COOKIE["user_uid"],$id);
  88. if($sharePower>$channelPower){
  89. $channelPower=$sharePower;
  90. }
  91. if($this->redis){
  92. $this->redis->hSet("power://channel/".$id,$_COOKIE["user_uid"],$channelPower);
  93. }
  94. return $channelPower;
  95. }
  96. }
  97. ?>