HomebaseController.class.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. /**
  3. * 洛阳赤炎鹰网络科技有限公司
  4. * https://www.cyyvip.com
  5. * Copyright (c) 2022 赤店商城 All rights reserved.
  6. */
  7. namespace Common\Controller;
  8. use Common\Controller\AppframeController;
  9. class HomebaseController extends AppframeController {
  10. public function __construct() {
  11. $this->set_action_success_error_tpl();
  12. parent::__construct();
  13. }
  14. function _initialize() {
  15. parent::_initialize();
  16. $site_options=get_site_options();
  17. $this->assign($site_options);
  18. $ucenter_syn=C("UCENTER_ENABLED");
  19. if($ucenter_syn){
  20. if(!isset($_SESSION["user"])){
  21. if(!empty($_COOKIE['thinkcmf_auth']) && $_COOKIE['thinkcmf_auth']!="logout"){
  22. $thinkcmf_auth=sp_authcode($_COOKIE['thinkcmf_auth'],"DECODE");
  23. $thinkcmf_auth=explode("\t", $thinkcmf_auth);
  24. $auth_username=$thinkcmf_auth[1];
  25. $users_model=M('Users');
  26. $where['user_login']=$auth_username;
  27. $user=$users_model->where($where)->find();
  28. if(!empty($user)){
  29. $is_login=true;
  30. $_SESSION["user"]=$user;
  31. }
  32. }
  33. }else{
  34. }
  35. }
  36. if(sp_is_user_login()){
  37. $this->assign("user",sp_get_current_user());
  38. }
  39. }
  40. /**
  41. * 检查用户登录
  42. */
  43. protected function check_login(){
  44. if(!isset($_SESSION["user"])){
  45. $this->error('您还没有登录!',__ROOT__."/");
  46. }
  47. }
  48. /**
  49. * 检查用户状态
  50. */
  51. protected function check_user(){
  52. $user_status=M('Users')->where(array("id"=>sp_get_current_userid()))->getField("user_status");
  53. if($user_status==2){
  54. $this->error('您还没有激活账号,请激活后再使用!',U("user/login/active"));
  55. }
  56. if($user_status==0){
  57. $this->error('此账号已经被禁止使用,请联系管理员!',__ROOT__."/");
  58. }
  59. }
  60. /**
  61. * 发送注册激活邮件
  62. */
  63. protected function _send_to_active(){
  64. $option = M('Options')->where(array('option_name'=>'member_email_active'))->find();
  65. if(!$option){
  66. $this->error('网站未配置账号激活信息,请联系网站管理员');
  67. }
  68. $options = json_decode($option['option_value'], true);
  69. //邮件标题
  70. $title = $options['title'];
  71. $uid=$_SESSION['user']['id'];
  72. $username=$_SESSION['user']['user_login'];
  73. $activekey=md5($uid.time().uniqid());
  74. $users_model=M("Users");
  75. $result=$users_model->where(array("id"=>$uid))->save(array("user_activation_key"=>$activekey));
  76. if(!$result){
  77. $this->error('激活码生成失败!');
  78. }
  79. //生成激活链接
  80. $url = U('user/register/active',array("hash"=>$activekey), "", true);
  81. //邮件内容
  82. $template = $options['template'];
  83. $content = str_replace(array('http://#link#','#username#'), array($url,$username),$template);
  84. $send_result=sp_send_email($_SESSION['user']['user_email'], $title, $content);
  85. if($send_result['error']){
  86. $this->error('激活邮件发送失败,请尝试登录后,手动发送激活邮件!');
  87. }
  88. }
  89. /**
  90. * 加载模板和页面输出 可以返回输出内容
  91. * @access public
  92. * @param string $templateFile 模板文件名
  93. * @param string $charset 模板输出字符集
  94. * @param string $contentType 输出类型
  95. * @param string $content 模板输出内容
  96. * @return mixed
  97. */
  98. public function display($templateFile = '', $charset = '', $contentType = '', $content = '', $prefix = '') {
  99. //echo $this->parseTemplate($templateFile);
  100. parent::display($this->parseTemplate($templateFile), $charset, $contentType);
  101. }
  102. /**
  103. * 获取输出页面内容
  104. * 调用内置的模板引擎fetch方法,
  105. * @access protected
  106. * @param string $templateFile 指定要调用的模板文件
  107. * 默认为空 由系统自动定位模板文件
  108. * @param string $content 模板输出内容
  109. * @param string $prefix 模板缓存前缀*
  110. * @return string
  111. */
  112. public function fetch($templateFile='',$content='',$prefix=''){
  113. $templateFile = empty($content)?$this->parseTemplate($templateFile):'';
  114. return parent::fetch($templateFile,$content,$prefix);
  115. }
  116. /**
  117. * 自动定位模板文件
  118. * @access protected
  119. * @param string $template 模板文件规则
  120. * @return string
  121. */
  122. public function parseTemplate($template='') {
  123. $tmpl_path=C("SP_TMPL_PATH");
  124. define("SP_TMPL_PATH", $tmpl_path);
  125. // 获取当前主题名称
  126. $theme = C('SP_DEFAULT_THEME');
  127. if(C('TMPL_DETECT_THEME')) {// 自动侦测模板主题
  128. $t = C('VAR_TEMPLATE');
  129. if (isset($_GET[$t])){
  130. $theme = $_GET[$t];
  131. }elseif(cookie('think_template')){
  132. $theme = cookie('think_template');
  133. }
  134. if(!file_exists($tmpl_path."/".$theme)){
  135. $theme = C('SP_DEFAULT_THEME');
  136. }
  137. cookie('think_template',$theme,864000);
  138. }
  139. $theme_suffix="";
  140. if(C('MOBILE_TPL_ENABLED') && sp_is_mobile()){//开启手机模板支持
  141. if (C('LANG_SWITCH_ON',null,false)){
  142. if(file_exists($tmpl_path."/".$theme."_mobile_".LANG_SET)){//优先级最高
  143. $theme_suffix = "_mobile_".LANG_SET;
  144. }elseif (file_exists($tmpl_path."/".$theme."_mobile")){
  145. $theme_suffix = "_mobile";
  146. }elseif (file_exists($tmpl_path."/".$theme."_".LANG_SET)){
  147. $theme_suffix = "_".LANG_SET;
  148. }
  149. }else{
  150. if(file_exists($tmpl_path."/".$theme."_mobile")){
  151. $theme_suffix = "_mobile";
  152. }
  153. }
  154. }else{
  155. $lang_suffix="_".LANG_SET;
  156. if (C('LANG_SWITCH_ON',null,false) && file_exists($tmpl_path."/".$theme.$lang_suffix)){
  157. $theme_suffix = $lang_suffix;
  158. }
  159. }
  160. $theme=$theme.$theme_suffix;
  161. C('SP_DEFAULT_THEME',$theme);
  162. $current_tmpl_path=$tmpl_path.$theme."/";
  163. // 获取当前主题的模版路径
  164. define('THEME_PATH', $current_tmpl_path);
  165. C("TMPL_PARSE_STRING.__TMPL__",__ROOT__."/".$current_tmpl_path);
  166. C('SP_VIEW_PATH',$tmpl_path);
  167. C('DEFAULT_THEME',$theme);
  168. define("SP_CURRENT_THEME", $theme);
  169. if(is_file($template)) {
  170. return $template;
  171. }
  172. $depr = C('TMPL_FILE_DEPR');
  173. $template = str_replace(':', $depr, $template);
  174. // 获取当前模块
  175. $module = MODULE_NAME;
  176. if(strpos($template,'@')){ // 跨模块调用模版文件
  177. list($module,$template) = explode('@',$template);
  178. }
  179. // 分析模板文件规则
  180. if('' == $template) {
  181. // 如果模板文件名为空 按照默认规则定位
  182. $template = "/".CONTROLLER_NAME . $depr . ACTION_NAME;
  183. }elseif(false === strpos($template, '/')){
  184. $template = "/".CONTROLLER_NAME . $depr . $template;
  185. }
  186. $file = sp_add_template_file_suffix($current_tmpl_path.$module.$template);
  187. $file= str_replace("//",'/',$file);
  188. if(!file_exists_case($file)) E(L('_TEMPLATE_NOT_EXIST_').':'.$file);
  189. return $file;
  190. }
  191. /**
  192. * 设置错误,成功跳转界面
  193. */
  194. private function set_action_success_error_tpl(){
  195. $theme = C('SP_DEFAULT_THEME');
  196. if(C('TMPL_DETECT_THEME')) {// 自动侦测模板主题
  197. if(cookie('think_template')){
  198. $theme = cookie('think_template');
  199. }
  200. }
  201. //by ayumi手机提示模板
  202. $tpl_path = '';
  203. if(C('MOBILE_TPL_ENABLED')){//开启手机模板支持
  204. if(sp_is_mobile()){
  205. if(file_exists(C("SP_TMPL_PATH")."/".$theme."_mobile")){
  206. $theme = $theme."_mobile";
  207. $tpl_path=C("SP_TMPL_PATH").$theme."/";
  208. }
  209. }
  210. }
  211. else{
  212. $tpl_path=C("SP_TMPL_PATH").$theme."/";
  213. }
  214. //by ayumi手机提示模板
  215. $defaultjump=THINK_PATH.'Tpl/dispatch_jump.tpl';
  216. $action_success = sp_add_template_file_suffix($tpl_path.C("SP_TMPL_ACTION_SUCCESS"));
  217. $action_error = sp_add_template_file_suffix($tpl_path.C("SP_TMPL_ACTION_ERROR"));
  218. if(file_exists_case($action_success)){
  219. C("TMPL_ACTION_SUCCESS",$action_success);
  220. }else{
  221. C("TMPL_ACTION_SUCCESS",$defaultjump);
  222. }
  223. if(file_exists_case($action_error)){
  224. C("TMPL_ACTION_ERROR",$action_error);
  225. }else{
  226. C("TMPL_ACTION_ERROR",$defaultjump);
  227. }
  228. }
  229. }