Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Admin{
- /**
- * Authorized actions
- * @since 1.0
- **/
- protected $actions = array("ads","users","media","blog","pages","settings","themes","editor","languages","search","server", "categories","stats","activities", "tools", "comments", "reports","menu");
- /**
- * Config + DB
- * @since 1.0
- **/
- protected $config;
- protected $db;
- /**
- * Admin Info + URL
- * @since 1.0
- **/
- protected $user;
- protected $url;
- /**
- * Reserved Variable
- * @since 1.0
- **/
- protected $page;
- protected $action;
- protected $do;
- protected $id;
- /**
- * Admin Limit/Page
- * @since 1.0
- **/
- protected $limit=24;
- /**
- * Valid Media types
- * @since 1.0
- **/
- protected $formats = NULL;
- /**
- * Construct Admin
- * @since 1.0
- **/
- public function __construct($config,$db){
- $this->config=$config;
- $this->db=$db;
- $this->url="{$this->config["url"]}/admin";
- $this->page=(isset($_GET["page"]) && is_numeric($_GET["page"]) && $_GET["page"]!="0") ? Main::clean($_GET["page"],3,TRUE):"1";
- $this->check();
- }
- /**
- * Free Memory (don't need it but do it anyway)
- * @since 1.0
- **/
- public function __destruct(){
- unset($this->db, $this->user, $this->config);
- }
- /**
- * Check if user is logged and has admin privileges!
- * @since 1.0
- **/
- public function check(){
- if($info=Main::user()){
- if($user=$this->db->get("user",array("id"=>"?","auth_key"=>"?"),array("limit"=>1),array($info[0],$info[1]))){
- if(!$user->admin) return Main::redirect("404");
- $this->logged=TRUE;
- $this->user=$user;
- $user=NULL;
- // Unset sensitive information
- unset($this->user->password);
- unset($this->user->auth_key);
- return TRUE;
- }
- }
- return Main::redirect("404");
- }
- /**
- * Run Admin Panel
- * @since 1.0
- **/
- public function run(){
- if(isset($_GET["a"]) && !empty($_GET["a"])){
- $var=explode("/",$_GET["a"]);
- if(in_array($var[0],$this->actions) && method_exists("Admin", $var[0])){
- $this->action=Main::clean($var[0],3,TRUE);
- if(isset($var[1]) && !empty($var[1])) $this->do=Main::clean($var[1],3,TRUE);
- if(isset($var[2]) && !empty($var[2])) $this->id=Main::clean($var[2],3,TRUE);
- return $this->{$var[0]}();
- }
- return Main::redirect("admin",array("danger","Oups! The page you are looking for doesn't exist."));
- }else{
- return $this->home();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement