示例#1
0
 function _permission($_content = null, $_login = true)
 {
     // if user is not login then redirect
     if ($_login && !$this->login()) {
         \lib\debug::warn(T_("first of all, you must login to system!"));
         $mydomain = \lib\utility\option::get('config', 'meta', 'redirectURL');
         if ($mydomain && $mydomain !== 'on') {
             $this->redirector($mydomain . '/login', false)->redirect();
         } else {
             $this->redirector(null, false)->set_domain()->set_url('login')->redirect();
         }
     }
     // if content is not set then
     if ($_content === null) {
         $_content = \lib\router::get_sub_domain();
     }
     // Check permission and if user can do this operation
     // allow to do it, else show related message in notify center
     $this->access($_content, null, null, 'block');
 }
示例#2
0
 /**
  * check status of permission to access special module
  * @param  [type] $route [description]
  * @return [type]        [description]
  */
 public function check($route)
 {
     $mysub = router::get_sub_domain();
     if (router::get_sub_domain() === "cp") {
         $mymodule = router::get_url(0);
         $mychild = router::get_url(1);
         $mymethod = $this->api_method;
         $myrequest = 'view';
         $myblock = 'block';
         if (strrpos($mychild, '=') !== false) {
             $mychild = substr($mychild, 0, strrpos($mychild, '='));
         }
         // set request name by type of it
         switch ($mymethod) {
             case 'get':
                 $myrequest = 'view';
                 break;
             case 'post':
                 $myrequest = 'add';
                 $myblock = 'notify';
                 break;
             case 'put':
                 $myrequest = 'edit';
                 $myblock = 'notify';
                 break;
             case 'delete':
                 $myrequest = 'delete';
                 $myblock = 'notify';
                 break;
             default:
                 $myrequest = '#invalid';
                 break;
         }
         // find request by 2th slash in url named as child
         switch ($mychild) {
             case 'add':
                 $myrequest = 'add';
                 break;
             case 'edit':
                 $myrequest = 'edit';
                 break;
             case 'delete':
                 $myrequest = 'delete';
                 break;
         }
         // set some setting for special module
         switch ($mymodule) {
             case 'posts':
             case 'pages':
             case 'users':
             case 'options':
             case 'permissions':
             case 'tags':
             case 'cats':
                 break;
             case 'profile':
                 $myblock = false;
                 break;
             default:
                 break;
         }
         // Check permission and if user can do this operation
         // allow to do it, else show related message in notify center
         $myController = \lib\main::$controller;
         $myController->access($mysub, $mymodule, $myrequest, $myblock);
     }
     parent::check(...func_get_args());
 }
示例#3
0
 /**
  * clearly return url property for use
  * @param  [type] $_type type of url you need
  * @param  [type] $_arg  an argument for pass into some condition
  * @return [type]        the url value
  */
 public function url($_type = null, $_arg = null)
 {
     $tmp_result = null;
     $myprefix = Protocol . "://";
     $mypostfix = '/';
     $mytld = router::get_root_domain('tld');
     switch ($_type) {
         // sub domain like 'account'
         case 'sub':
             return router::get_sub_domain($_arg);
             break;
         case 'path':
             $myUrl = router::get_url($_arg);
             if ($_arg == '_') {
                 // filter url to delete disallow characters
                 $myUrl = router::urlfilterer($myUrl);
                 // dont use $ in id
                 $myUrl = str_replace('$', 'dollar', $myUrl);
             }
             return $myUrl;
             break;
         case 'breadcrumb':
             $myurl = router::get_url(-1);
             $breadcrumb = array();
             foreach ($myurl as $value) {
                 $tmp_pos = strpos($value, '=');
                 array_push($breadcrumb, $tmp_pos ? substr($value, 0, $tmp_pos) : $value);
             }
             return $breadcrumb;
             break;
         case 'param':
             return \lib\utility::get(null, $_arg);
             break;
             // domain tld like 'com'
         // domain tld like 'com'
         case 'tld':
             return $mytld;
             break;
             // domain name like 'ermile'
         // domain name like 'ermile'
         case 'domain':
             return router::get_root_domain('domain');
             break;
             // domain name except subdomain like 'ermile.com'
         // domain name except subdomain like 'ermile.com'
         case 'raw':
             return router::get_root_domain('domain') . '.' . $mytld;
             break;
             // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/'
         // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/'
         case 'root':
             return $myprefix . router::get_root_domain() . $mypostfix;
             break;
             // use main protocol and give it from config file if not exist use root url
             // return http or https
         // use main protocol and give it from config file if not exist use root url
         // return http or https
         case 'MainProtocol':
             if (defined('MainProtocol') && constant('MainProtocol') && is_string(constant('MainProtocol'))) {
                 return constant('MainProtocol');
             } else {
                 return 'http';
             }
             break;
             // use main site and give it from config file if not exist use root url
             // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/'
         // use main site and give it from config file if not exist use root url
         // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/'
         case 'MainSite':
             if (defined('MainSite') && constant('MainSite') && is_string(constant('MainSite'))) {
                 return constant('MainSite');
             } else {
                 return router::get_root_domain() . $mypostfix;
             }
             break;
             // base url for user in base tag with http[s]
         // base url for user in base tag with http[s]
         case 'base':
             return router::$base;
             break;
             // full url except get parameter with http[s]
         // full url except get parameter with http[s]
         case 'full':
             return $myprefix . router::get_domain() . '/' . router::get_url();
             break;
             // return module info
         // return module info
         case 'module':
             if ($_arg === 'prefix') {
                 $mymodule = substr(router::get_url(0), 0, -1);
             } elseif ($_arg == 'array') {
                 $mymodule = router::get_url(-1);
             } elseif ($_arg == 'cp') {
                 $mymodule = router::get_url(0);
                 switch ($mymodule) {
                     case 'tags':
                     case 'cats':
                         $mymodule = 'terms';
                         break;
                     case 'pages':
                         $mymodule = 'posts';
                         break;
                 }
             } else {
                 $mymodule = router::get_url(0);
             }
             return $mymodule;
             break;
         case 'child':
             $mychild = router::get_url(1);
             if (strrpos($mychild, '=') !== false) {
                 $mychild = substr($mychild, 0, strrpos($mychild, '='));
             }
             if (!$_arg) {
                 return $mychild;
             }
             if ($mychild == 'add') {
                 return T_('add new');
             }
             if ($mychild == 'edit') {
                 return T_('edit');
             }
             if ($mychild == 'delete') {
                 return T_('delete');
             }
             break;
             // login service and main service with full address
         // login service and main service with full address
         case 'LoginService':
         case 'account':
             return $myprefix . AccountService . MainTld . '/' . MyAccount;
             break;
         case 'MainService':
             $_arg = is_array($_arg) ? $_arg : array('com', 'dev');
             if (in_array($mytld, $_arg)) {
                 return $myprefix . constant('MainService') . '.' . $mytld;
             } else {
                 return $myprefix . constant('MainService') . MainTld;
             }
             break;
         default:
             return null;
             break;
     }
 }