Lin_Controller.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /** STAR 核心控制类扩展 */
  3. define('IN_STAR',TRUE);
  4. define('STAR_NAME','STAR');
  5. define('STAR_VERSION','V1.0.00');
  6. define('STAR_BUILDTIME','201801011');
  7. // ------------------------------------------------------------------------
  8. class Lin_Controller extends CI_Controller {
  9. public $setting;
  10. public $S;
  11. //初始化扩展控制类
  12. function __construct()
  13. {
  14. parent::__construct();
  15. //载入配置
  16. $this->load->library('session');
  17. $this->load->_model('Model_setting','setting');
  18. $this->load->_model('Model_user','user');
  19. $this->load->helper('url');
  20. }
  21. }
  22. // END Lin_Controller class
  23. //前台页面控制器
  24. abstract class Start_Controller extends Lin_Controller {
  25. public $data;
  26. function __construct()
  27. {
  28. parent::__construct();
  29. $setting = $this->setting->get_settings();
  30. if(!isset($_SESSION['api']) && $this->uri->slash_segment(1) != "/" && $this->uri->slash_segment(1) != "phone/" && $this->uri->slash_segment(1) != "apt/" && $this->uri->slash_segment(1) != "outbound/" && $this->uri->slash_segment(2) != "isorder/" && $this->uri->slash_segment(2) != "waybill/" && $this->uri->slash_segment(2) != "apple/" && $this->uri->slash_segment(2) != "query/" && $this->uri->slash_segment(2) != "fhd/" && $this->uri->slash_segment(2) != "kc/" && $this->uri->slash_segment(2) != "syns/" && $this->uri->slash_segment(1) != "api/" && $this->uri->slash_segment(2) != "khjz/" && $this->uri->slash_segment(2) != "khjzfs/" && $this->uri->slash_segment(2) != "webhook/" && $this->uri->slash_segment(2) != "ttwebhook/" && $this->uri->slash_segment(2) != "sq/" && $this->uri->slash_segment(2) != "kcpd/"&& $this->uri->slash_segment(1) != "errorlog/" && $this->uri->slash_segment(1) != "apiexpress/" && $this->uri->slash_segment(1) != "apiexpressv1/")//如果有api
  31. {
  32. $this->session->sess_destroy();
  33. header("Location:/");
  34. }
  35. if(isset($_SESSION['api']))
  36. {
  37. $u = $this->user->get_api($_SESSION['api']);
  38. if(!$u && $this->uri->slash_segment(1) != "/")
  39. {
  40. $this->session->sess_destroy();
  41. header("Location:/");
  42. }
  43. else if($this->uri->slash_segment(1) == "/")
  44. {
  45. header("Location:/user/");
  46. }
  47. }
  48. if(!empty($u)){
  49. $this->user->save(['lasttime'=>time()],$u['id']);
  50. }
  51. $this->load->library('template');
  52. //设置前台模板路径
  53. $this->template->_init($setting['theme']);
  54. //载入自定义函数
  55. $this->load->library('common');
  56. //设置控制器分享参数
  57. $this->setting->primaryKey = 'skey';
  58. //基本信息
  59. $this->data['userkz'] = (isset($u['download']))?$u['download']:1;
  60. $this->data['theme'] = '/template/'.$setting['theme'].'/';
  61. $this->data['route'] = $this->uri->segment(1);
  62. $this->config->set_item('index_page',''); //后缀index.php为空
  63. $this->config->set_item('url_suffix','');//路径后缀.htmml为空
  64. }
  65. /** 载入模版 */
  66. function _template($template, $data = array() )
  67. {
  68. $this->template->assign($data);
  69. $this->template->display($template);
  70. }
  71. //前台提示信息
  72. function _message($msg, $goto = '',$auto = true,$fix = '')
  73. {
  74. if($goto == '')
  75. {
  76. $goto = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : site_url();
  77. }
  78. else
  79. {
  80. $goto = strpos($goto,'http') !== false ? $goto : site_url($goto);
  81. }
  82. $goto .= $fix;
  83. $this->_template('sys_message',array('msg'=>$msg,'goto'=>$goto,'auto'=>$auto,'ver'=>STAR_NAME.' '.STAR_VERSION));
  84. echo $this->output->get_output();
  85. exit();
  86. }
  87. }
  88. //后台控制器扩展
  89. abstract class Admin_Controller extends Lin_Controller {
  90. public $template_path;
  91. public $logined;
  92. function __construct()
  93. {
  94. parent::__construct();
  95. $this->template_path = APPPATH.'views/'; //后台视图路径
  96. //设置后台模板路径
  97. $this->config->set_item('url_suffix',''); //强制不使用伪静态
  98. $this->load->library('session');
  99. //check user login status
  100. $this->logined = $this->_check_login();
  101. //载入超级变量
  102. if($this->logined)
  103. {
  104. $this->_set_s();
  105. }
  106. }
  107. function _check_login()
  108. {
  109. if (!$this->session->userdata('uid') )
  110. {
  111. $setting = $this->setting->get_settings();
  112. $redirect = $this->uri->uri_string(); //获取后台入口路径
  113. }
  114. else
  115. {
  116. return 1;
  117. }
  118. }
  119. function _check_permit($action = '')
  120. {
  121. if(!$this->acl->permit($action))
  122. {
  123. $this->_message('对不起,你没有访问这里的权限!','',false);
  124. }
  125. }
  126. function _show($template, $data = array())
  127. {
  128. $this->load->view($template,$data);
  129. }
  130. function _template($template, $data = array())
  131. {
  132. $cr = '</body></html>';
  133. $this->load->view($template,$data);
  134. $this->output->append_output($cr);
  135. }
  136. function _set_s(){
  137. $this->load->_model('Model_login');
  138. $this->load->library('common');
  139. $this->S['admin'] = $this->Model_login->get_userid($this->session->userdata('uid'));
  140. }
  141. }
  142. // END Admin_Controller class
  143. function made_admin_url($uri,$qs = '')
  144. {
  145. return site_url('gold'.'/'.$uri).($qs == '' ? '' : '?'.$qs);
  146. }