msg.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. class msg_c extends Control
  3. {
  4. var $subject;
  5. var $tplfile = "msg";
  6. function __construct()
  7. {
  8. parent::Control();
  9. $this->load_model("msg");
  10. }
  11. function msg_c()
  12. {
  13. $this->__construct();
  14. }
  15. function index_f()
  16. {
  17. $id = $this->trans_lib->int("id");
  18. $ts = $this->trans_lib->safe("ts");
  19. if(!$id && !$ts)
  20. {
  21. error($this->lang["msg_not_id"],site_url("index"));
  22. }
  23. if($id)
  24. {
  25. $rs = $this->msg_m->get_one($id);
  26. }
  27. else
  28. {
  29. $rs = $this->msg_m->get_one_fromtype($ts,$_SESSION["sys_lang_id"]);
  30. }
  31. if(!$rs)
  32. {
  33. error($this->lang["msg_not_rs"],site_url("index"));
  34. }
  35. //判断如果语言包不一样,自动刷新一遍
  36. if($rs["langid"] != $_SESSION["sys_lang_id"])
  37. {
  38. $_SESSION["sys_lang_id"] = $rs["langid"];
  39. sys_header(site_url("msg","id=".$rs["id"]));
  40. }
  41. //如果存在分类
  42. $this->subject = $rs["title"];
  43. $this->load_module_msg($rs["module_id"]);
  44. if($rs["cate_id"])
  45. {
  46. $this->load_cate_msg($rs["cate_id"]);
  47. }
  48. $this->phpok_seo($rs);
  49. $id = $rs["id"];
  50. $this->tpl->assign("id",$id);
  51. $this->tpl->assign("rs",$rs);
  52. $this->tpl->assign("cateid",$rs["cate_id"]);
  53. //读取自定义配置字段的数据信息
  54. if($rs["tplfile"])
  55. {
  56. $this->tplfile = $rs["tplfile"];
  57. }
  58. //更新点击率
  59. $this->msg_m->update_hits($rs["id"]);
  60. $this->tpl->display($this->tplfile.".".$this->tpl->ext);
  61. }
  62. function load_module_msg($mid)
  63. {
  64. $rs = $this->module_m->get_one($mid);
  65. if(!$rs)
  66. {
  67. return false;
  68. }
  69. $this->tpl->assign("mid",$mid);
  70. $this->tpl->assign("m_rs",$rs);
  71. //设置模块涉及到的文件
  72. $this->tplfile = "msg_".$rs["identifier"];//内容模块
  73. $array = array();
  74. $array[0]["title"] = $rs["title"];
  75. $array[1]["title"] = $this->subject;
  76. $this->tpl->assign("leader",$array);
  77. //设置头部信息
  78. $sitetitle = $this->subject;
  79. $this->tpl->assign("sitetitle",$sitetitle);
  80. return true;
  81. }
  82. function load_cate_msg($cateid)
  83. {
  84. $this->tpl->assign("cid",$cateid);
  85. $rs = $this->cate_m->get_one($cateid);
  86. if(!$rs)
  87. {
  88. return false;
  89. }
  90. if($rs["tpl_file"])
  91. {
  92. $this->tplfile = $rs["tpl_file"];
  93. }
  94. $this->phpok_seo($rs);
  95. $this->tpl->assign("cate_rs",$rs);
  96. $array = array();
  97. $array[0] = $rs;
  98. if($rs["parentid"])
  99. {
  100. $this->cate_m->get_parent_array($array,$rs["parentid"]);
  101. }
  102. $rslist = array();
  103. $site_title_array = array();
  104. foreach($array AS $key=>$value)
  105. {
  106. $tmp = array();
  107. $tmp["title"] = $value["cate_name"];
  108. $ext = $value["identifier"] ? "cs=".$value["identifier"] : "cid=".$value["id"];
  109. $tmp["url"] = site_url("list",$ext);
  110. $rslist[$key] = $tmp;
  111. $site_title_array[] = $value["cate_name"];
  112. }
  113. $sitetitle = $this->subject." - ".implode(" - ",$site_title_array);
  114. $this->tpl->assign("sitetitle",$sitetitle);
  115. //倒序数组
  116. krsort($rslist);
  117. $count = count($rslist);
  118. $rslist[$count]["title"] = $this->subject;
  119. unset($array);
  120. $this->tpl->assign("leader",$rslist);
  121. }
  122. function content_f()
  123. {
  124. $id = $this->trans_lib->int("id");
  125. $field = $this->trans_lib->safe("field");
  126. $pageid = $this->trans_lib->int("pageid");
  127. $msg = phpok_c($id,$field,$pageid,false);
  128. exit($msg);
  129. }
  130. //SEO优化
  131. function phpok_seo($rs)
  132. {
  133. $_sys = $this->sys_config;
  134. if($rs["keywords"])
  135. {
  136. $_sys["keywords"] = $rs["keywords"].",".$_sys["keywords"];
  137. }
  138. if($rs["description"])
  139. {
  140. $_sys["description"] = $rs["description"].",".$_sys["description"];
  141. }
  142. $this->sys_config($_sys);
  143. $this->tpl->assign("_sys",$_sys);
  144. }
  145. }
  146. ?>