Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. class Admin{
  2. /**
  3. * Authorized actions
  4. * @since 1.0
  5. **/
  6. protected $actions = array("ads","users","media","blog","pages","settings","themes","editor","languages","search","server", "categories","stats","activities", "tools", "comments", "reports","menu");
  7. /**
  8. * Config + DB
  9. * @since 1.0
  10. **/
  11. protected $config;
  12. protected $db;
  13.  
  14. /**
  15. * Admin Info + URL
  16. * @since 1.0
  17. **/
  18. protected $user;
  19. protected $url;
  20. /**
  21. * Reserved Variable
  22. * @since 1.0
  23. **/
  24. protected $page;
  25. protected $action;
  26. protected $do;
  27. protected $id;
  28. /**
  29. * Admin Limit/Page
  30. * @since 1.0
  31. **/
  32. protected $limit=24;
  33. /**
  34. * Valid Media types
  35. * @since 1.0
  36. **/
  37. protected $formats = NULL;
  38. /**
  39. * Construct Admin
  40. * @since 1.0
  41. **/
  42. public function __construct($config,$db){
  43. $this->config=$config;
  44. $this->db=$db;
  45. $this->url="{$this->config["url"]}/admin";
  46. $this->page=(isset($_GET["page"]) && is_numeric($_GET["page"]) && $_GET["page"]!="0") ? Main::clean($_GET["page"],3,TRUE):"1";
  47. $this->check();
  48. }
  49. /**
  50. * Free Memory (don't need it but do it anyway)
  51. * @since 1.0
  52. **/
  53. public function __destruct(){
  54. unset($this->db, $this->user, $this->config);
  55. }
  56. /**
  57. * Check if user is logged and has admin privileges!
  58. * @since 1.0
  59. **/
  60. public function check(){
  61. if($info=Main::user()){
  62. if($user=$this->db->get("user",array("id"=>"?","auth_key"=>"?"),array("limit"=>1),array($info[0],$info[1]))){
  63. if(!$user->admin) return Main::redirect("404");
  64. $this->logged=TRUE;
  65. $this->user=$user;
  66. $user=NULL;
  67. // Unset sensitive information
  68. unset($this->user->password);
  69. unset($this->user->auth_key);
  70. return TRUE;
  71. }
  72. }
  73. return Main::redirect("404");
  74. }
  75. /**
  76. * Run Admin Panel
  77. * @since 1.0
  78. **/
  79. public function run(){
  80. if(isset($_GET["a"]) && !empty($_GET["a"])){
  81. $var=explode("/",$_GET["a"]);
  82. if(in_array($var[0],$this->actions) && method_exists("Admin", $var[0])){
  83. $this->action=Main::clean($var[0],3,TRUE);
  84. if(isset($var[1]) && !empty($var[1])) $this->do=Main::clean($var[1],3,TRUE);
  85. if(isset($var[2]) && !empty($var[2])) $this->id=Main::clean($var[2],3,TRUE);
  86. return $this->{$var[0]}();
  87. }
  88. return Main::redirect("admin",array("danger","Oups! The page you are looking for doesn't exist."));
  89. }else{
  90. return $this->home();
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement