PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/core/mapi/base.mapi.php

https://github.com/alin40404/FanweShare
PHP | 178 lines | 150 code | 23 blank | 5 comment | 17 complexity | 5e3dd73e3aa0a632f0aaf79da5d5eba5 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. function m_getMConfig(){
  3. global $_FANWE;
  4. //FanweService::instance()->cache->loadCache("m_config");
  5. $m_config = $_FANWE['cache']['m_config'];
  6. if($m_config==false) //测试时,不取缓存
  7. {
  8. //init_config_data();//检查初始化数据
  9. $m_config = array();
  10. $list = FDB::fetchAll("select code,val from ".FDB::table("m_config"));
  11. foreach($list as $item){
  12. $m_config[$item['code']] = $item['val'];
  13. }
  14. //新闻公告
  15. $sql = "select code as title, title as content from ".FDB::table("m_config_list")." where `group` = 4 and is_verify = 1 order by id desc";
  16. $list = FDB::fetchAll($sql);
  17. $newslist = array();
  18. foreach($list as $item){
  19. $newslist[] = array("title"=>$item['title'],"content"=>str_replace("/public/upload/images/",$_FANWE['site_url']."public/upload/images/",$item['content']));
  20. }
  21. $m_config['newslist'] = $newslist;
  22. //print_r($addrtlist);exit;
  23. FanweService::instance()->cache->saveCache("m_config",$m_config);
  24. }
  25. //print_r($m_config);
  26. return $m_config;
  27. }
  28. function m_emptyTag($string)
  29. {
  30. if(empty($string))
  31. return "";
  32. $string = strip_tags(trim($string));
  33. $string = preg_replace("|&.+?;|",'',$string);
  34. return $string;
  35. }
  36. function m_convertUrl($url)
  37. {
  38. $url = str_replace("&","&amp;",$url);
  39. return $url;
  40. }
  41. function m_display($root)
  42. {
  43. global $_FANWE;
  44. $root['user'] = $_FANWE['user'];
  45. header("Content-Type:text/html; charset=utf-8");
  46. $r_type = intval($_REQUEST['r_type']);//返回数据格式类型; 0:base64;1;json_encode;2:array
  47. if ($r_type == 0){
  48. echo base64_encode(json_encode($root));
  49. }else if ($r_type == 1){
  50. print_r(json_encode($root));
  51. }else if ($r_type == 2){
  52. print_r($root);
  53. };
  54. exit;
  55. }
  56. function m_express($content)
  57. {
  58. global $_FANWE;
  59. $express = getCache('m_emotion_express_cache'); //缓存过的表情hash
  60. if(!$express)
  61. {
  62. $express_rs = FDB::fetchAll("select `emotion`,concat('".$_FANWE['site_url']."public/expression/',`type`,'/',`filename`) as fname from ".FDB::table('expression'));
  63. foreach($express_rs as $k=>$row)
  64. {
  65. $express[0][] = $row['emotion'];
  66. $express[1][] = "<img src='".$row['fname']."' title='".preg_replace("/[\[\]]/",'',$row['emotion'])."' />";
  67. }
  68. setCache('m_emotion_express_cache',$express);
  69. }
  70. $content = str_replace($express[0],$express[1],$content);
  71. $parse_user = array();
  72. preg_match_all("/@([^\f\n\r\t\v@<> ]{2,20}?)(?:\:| )/",$content,$users);
  73. if(!empty($users[1]))
  74. {
  75. $patterns = array();
  76. $replace = array();
  77. $users = array_unique($users[1]);
  78. $arr = array();
  79. foreach($users as $user)
  80. {
  81. if(!empty($user))
  82. {
  83. $arr[] = addslashes($user);
  84. }
  85. }
  86. $res = FDB::query('SELECT uid,user_name
  87. FROM '.FDB::table('user').'
  88. WHERE user_name '.FDB::createIN($arr));
  89. while($data = FDB::fetch($res))
  90. {
  91. $parse_user[$data['user_name']] = $data['uid'];
  92. }
  93. }
  94. $parse_events = array();
  95. preg_match_all("/#([^\f\n\r\t\v]{1,80}?)#/",$content,$events);
  96. if(!empty($events[1]))
  97. {
  98. $patterns = array();
  99. $replace = array();
  100. $events = array_unique($events[1]);
  101. $arr = array();
  102. foreach($events as $event)
  103. {
  104. if(!empty($event))
  105. {
  106. $arr[] = addslashes($event);
  107. }
  108. }
  109. $res = FDB::query('SELECT id,title
  110. FROM '.FDB::table('event').'
  111. WHERE title '.FDB::createIN($arr));
  112. while($data = FDB::fetch($res))
  113. {
  114. $parse_events[$data['title']] = $data['id'];
  115. }
  116. }
  117. return array("users"=>$parse_user,"events"=>$parse_events);
  118. }
  119. function m_youhuiItem($item){
  120. global $_FANWE;
  121. $is_sc = intval($item['is_sc']);
  122. if ($is_sc > 0) $is_sc = 1;//1:已收藏; 0:未收藏
  123. if (intval($item['begin_time']) > 0 && intval($item['end_time'])){
  124. $days = round(($item['end_time']-$item['begin_time'])/3600/24);
  125. if ($days < 0){
  126. $ycq = fToDate($item['begin_time'],'Y-m-d').'至'.fToDate($item['end_time'],'Y-m-d').',已过期';
  127. }else{
  128. $ycq = fToDate($item['begin_time'],'Y-m-d').'至'.fToDate($item['end_time'],'Y-m-d').',还有'.$days.'天';
  129. }
  130. }else{
  131. $ycq = '';
  132. }
  133. return array("id"=>$item['id'],
  134. "title"=>$item['title'],
  135. "logo"=> $_FANWE['site_url'].$item['image_1'],
  136. "logo_1" => $_FANWE['site_url'].$item['image_2'],
  137. "logo_2" => $_FANWE['site_url'].$item['image_3'],
  138. "merchant_logo"=> $_FANWE['site_url'].$item['merchant_logo'],
  139. "create_time"=>$item['create_time'],
  140. "create_time_format"=>getBeforeTimelag($item['create_time']),
  141. "xpoint"=>$item['merchant_xpoint'],
  142. "ypoint"=>$item['merchant_ypoint'],
  143. "address"=>$item['merchant_api_address'],
  144. "content"=>$item['content'],
  145. "is_sc"=>$is_sc,
  146. "comment_count"=>intval($item['comment_count']),
  147. "merchant_id"=>intval($item['merchant_id']),
  148. "begin_time_format"=>fToDate($item['begin_time'],'Y-m-d'),
  149. "end_time_format"=>fToDate($item['end_time'],'Y-m-d'),
  150. "ycq"=>$ycq,
  151. "url"=>$item['url'],
  152. "city_name"=>$item['city_name']
  153. );
  154. }
  155. ?>