common.php 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. // 关闭所有PHP错误报告
  14. error_reporting(0);
  15. include_once EXTEND_PATH."function.php";
  16. // 应用公共文件
  17. if (!function_exists('switch_exception'))
  18. {
  19. // 模板错误提示
  20. function switch_exception() {
  21. $web_exception = tpCache('web.web_exception');
  22. if (!empty($web_exception)) {
  23. config('ey_config.web_exception', $web_exception);
  24. error_reporting(-1);
  25. }
  26. }
  27. }
  28. if (!function_exists('tpCache'))
  29. {
  30. /**
  31. * 获取缓存或者更新缓存,只适用于config表
  32. * @param string $config_key 缓存文件名称
  33. * @param array $data 缓存数据 array('k1'=>'v1','k2'=>'v3')
  34. * @param array $options 缓存配置
  35. * @param string $lang 语言标识
  36. * @return array or string or bool
  37. */
  38. function tpCache($config_key,$data = array(), $lang = '', $options = null){
  39. $tableName = 'config';
  40. $table_db = \think\Db::name($tableName);
  41. $param = explode('.', $config_key);
  42. $cache_inc_type = $tableName.$param[0];
  43. // $cache_inc_type = $param[0];
  44. $lang = !empty($lang) ? $lang : get_current_lang();
  45. if (empty($options)) {
  46. $options['path'] = CACHE_PATH.$lang.DS;
  47. }
  48. if(empty($data)){
  49. //如$config_key=shop_info则获取网站信息数组
  50. //如$config_key=shop_info.logo则获取网站logo字符串
  51. $config = cache($cache_inc_type,'',$options);//直接获取缓存文件
  52. if(empty($config)){
  53. //缓存文件不存在就读取数据库
  54. if ($param[0] == 'global') {
  55. $param[0] = 'global';
  56. $res = $table_db->where([
  57. 'lang' => $lang,
  58. 'is_del' => 0,
  59. ])->select();
  60. } else {
  61. $res = $table_db->where([
  62. 'inc_type' => $param[0],
  63. 'lang' => $lang,
  64. 'is_del' => 0,
  65. ])->select();
  66. }
  67. if($res){
  68. foreach($res as $k=>$val){
  69. $config[$val['name']] = $val['value'];
  70. }
  71. cache($cache_inc_type,$config,$options);
  72. }
  73. // write_global_params($lang, $options);
  74. }
  75. if(!empty($param) && count($param)>1){
  76. $newKey = strtolower($param[1]);
  77. return isset($config[$newKey]) ? $config[$newKey] : '';
  78. }else{
  79. return $config;
  80. }
  81. }else{
  82. //更新缓存
  83. $result = $table_db->where([
  84. 'inc_type' => $param[0],
  85. 'lang' => $lang,
  86. 'is_del' => 0,
  87. ])->select();
  88. if($result){
  89. foreach($result as $val){
  90. $temp[$val['name']] = $val['value'];
  91. }
  92. $add_data = array();
  93. foreach ($data as $k=>$v){
  94. $newK = strtolower($k);
  95. $newArr = array(
  96. 'name'=>$newK,
  97. 'value'=>trim($v),
  98. 'inc_type'=>$param[0],
  99. 'lang' => $lang,
  100. 'update_time' => getTime(),
  101. );
  102. if(!isset($temp[$newK])){
  103. array_push($add_data, $newArr); //新key数据插入数据库
  104. }else{
  105. if ($v != $temp[$newK]) {
  106. $table_db->where([
  107. 'name' => $newK,
  108. 'lang' => $lang,
  109. ])->save($newArr);//缓存key存在且值有变更新此项
  110. }
  111. }
  112. }
  113. if (!empty($add_data)) {
  114. $table_db->insertAll($add_data);
  115. }
  116. //更新后的数据库记录
  117. $newRes = $table_db->where([
  118. 'inc_type' => $param[0],
  119. 'lang' => $lang,
  120. 'is_del' => 0,
  121. ])->select();
  122. foreach ($newRes as $rs){
  123. $newData[$rs['name']] = $rs['value'];
  124. }
  125. }else{
  126. if ($param[0] != 'global') {
  127. foreach($data as $k=>$v){
  128. $newK = strtolower($k);
  129. $newArr[] = array(
  130. 'name'=>$newK,
  131. 'value'=>trim($v),
  132. 'inc_type'=>$param[0],
  133. 'lang' => $lang,
  134. 'update_time' => time(),
  135. );
  136. }
  137. !empty($newArr) && $table_db->insertAll($newArr);
  138. }
  139. $newData = $data;
  140. }
  141. $result = false;
  142. $res = $table_db->where([
  143. 'lang' => $lang,
  144. 'is_del' => 0,
  145. ])->select();
  146. if($res){
  147. $global = array();
  148. foreach($res as $k=>$val){
  149. $global[$val['name']] = $val['value'];
  150. }
  151. $result = cache($tableName.'global',$global,$options);
  152. }
  153. if ($param[0] != 'global') {
  154. $result = cache($cache_inc_type,$newData,$options);
  155. }
  156. return $result;
  157. }
  158. }
  159. }
  160. if (!function_exists('tpSetting'))
  161. {
  162. /**
  163. * 获取缓存或者更新缓存,只适用于setting表
  164. * @param string $config_key 缓存文件名称
  165. * @param array $data 缓存数据 array('k1'=>'v1','k2'=>'v3')
  166. * @param array $options 缓存配置
  167. * @param string $lang 语言标识
  168. * @return array or string or bool
  169. */
  170. function tpSetting($config_key,$data = array(), $lang = '', $options = null){
  171. $tableName = 'setting';
  172. $table_db = \think\Db::name($tableName);
  173. $param = explode('.', $config_key);
  174. $cache_inc_type = $tableName.$param[0];
  175. // $cache_inc_type = $param[0];
  176. $lang = !empty($lang) ? $lang : get_current_lang();
  177. if (empty($options)) {
  178. $options['path'] = CACHE_PATH.$lang.DS;
  179. }
  180. if(empty($data)){
  181. //如$config_key=shop_info则获取网站信息数组
  182. //如$config_key=shop_info.logo则获取网站logo字符串
  183. $config = cache($cache_inc_type,'',$options);//直接获取缓存文件
  184. if(empty($config)){
  185. //缓存文件不存在就读取数据库
  186. if ($param[0] == 'global') {
  187. $param[0] = 'global';
  188. $res = $table_db->where([
  189. 'lang' => $lang,
  190. ])->select();
  191. } else {
  192. $res = $table_db->where([
  193. 'inc_type' => $param[0],
  194. 'lang' => $lang,
  195. ])->select();
  196. }
  197. if($res){
  198. foreach($res as $k=>$val){
  199. $config[$val['name']] = $val['value'];
  200. }
  201. cache($cache_inc_type,$config,$options);
  202. }
  203. // write_global_params($lang, $options);
  204. }
  205. if(!empty($param) && count($param)>1){
  206. $newKey = strtolower($param[1]);
  207. return isset($config[$newKey]) ? $config[$newKey] : '';
  208. }else{
  209. return $config;
  210. }
  211. }else{
  212. //更新缓存
  213. $result = $table_db->where([
  214. 'inc_type' => $param[0],
  215. 'lang' => $lang,
  216. ])->select();
  217. if($result){
  218. foreach($result as $val){
  219. $temp[$val['name']] = $val['value'];
  220. }
  221. $add_data = array();
  222. foreach ($data as $k=>$v){
  223. $newK = strtolower($k);
  224. $newArr = array(
  225. 'name'=>$newK,
  226. 'value'=>trim($v),
  227. 'inc_type'=>$param[0],
  228. 'lang' => $lang,
  229. 'update_time' => getTime(),
  230. );
  231. if(!isset($temp[$newK])){
  232. array_push($add_data, $newArr); //新key数据插入数据库
  233. }else{
  234. if ($v != $temp[$newK]) {
  235. $table_db->where([
  236. 'name' => $newK,
  237. 'lang' => $lang,
  238. ])->save($newArr);//缓存key存在且值有变更新此项
  239. }
  240. }
  241. }
  242. if (!empty($add_data)) {
  243. $table_db->insertAll($add_data);
  244. }
  245. //更新后的数据库记录
  246. $newRes = $table_db->where([
  247. 'inc_type' => $param[0],
  248. 'lang' => $lang,
  249. ])->select();
  250. foreach ($newRes as $rs){
  251. $newData[$rs['name']] = $rs['value'];
  252. }
  253. }else{
  254. if ($param[0] != 'global') {
  255. foreach($data as $k=>$v){
  256. $newK = strtolower($k);
  257. $newArr[] = array(
  258. 'name'=>$newK,
  259. 'value'=>trim($v),
  260. 'inc_type'=>$param[0],
  261. 'lang' => $lang,
  262. 'update_time' => time(),
  263. );
  264. }
  265. $table_db->insertAll($newArr);
  266. }
  267. $newData = $data;
  268. }
  269. $result = false;
  270. $res = $table_db->where([
  271. 'lang' => $lang,
  272. ])->select();
  273. if($res){
  274. $global = array();
  275. foreach($res as $k=>$val){
  276. $global[$val['name']] = $val['value'];
  277. }
  278. $result = cache($tableName.'global',$global,$options);
  279. }
  280. if ($param[0] != 'global') {
  281. $result = cache($cache_inc_type,$newData,$options);
  282. }
  283. return $result;
  284. }
  285. }
  286. }
  287. if (!function_exists('write_global_params'))
  288. {
  289. /**
  290. * 写入全局内置参数
  291. * @return array
  292. */
  293. function write_global_params($lang = '', $options = null)
  294. {
  295. $webConfigParams = \think\Db::name('config')->where([
  296. 'inc_type' => 'web',
  297. 'lang' => $lang,
  298. 'is_del' => 0,
  299. ])->getAllWithIndex('name');
  300. $web_basehost = !empty($webConfigParams['web_basehost']) ? $webConfigParams['web_basehost']['value'] : ''; // 网站根网址
  301. $web_cmspath = !empty($webConfigParams['web_cmspath']) ? $webConfigParams['web_cmspath']['value'] : ''; // EyouCMS安装目录
  302. /*启用绝对网址,开启此项后附件、栏目连接、arclist内容等都使用http路径*/
  303. $web_multi_site = !empty($webConfigParams['web_multi_site']) ? $webConfigParams['web_multi_site']['value'] : '';
  304. if($web_multi_site == 1)
  305. {
  306. $web_mainsite = $web_basehost.$web_cmspath;
  307. }
  308. else
  309. {
  310. $web_mainsite = '';
  311. }
  312. /*--end*/
  313. /*CMS安装目录的网址*/
  314. $param['web_cmsurl'] = $web_mainsite;
  315. /*--end*/
  316. $param['web_templets_dir'] = '/template'; // 前台模板根目录
  317. $param['web_templeturl'] = $web_mainsite.$param['web_templets_dir']; // 前台模板根目录的网址
  318. $param['web_templets_pc'] = $web_mainsite.$param['web_templets_dir'].'/pc'; // 前台PC模板主题
  319. $param['web_templets_m'] = $web_mainsite.$param['web_templets_dir'].'/mobile'; // 前台手机模板主题
  320. $param['web_eyoucms'] = str_replace('#', '', '#h#t#t#p#:#/#/#w#w#w#.#e#y#o#u#c#m#s#.#c#o#m#'); // eyou网址
  321. /*将内置的全局变量(页面上没有入口更改的全局变量)存储到web版块里*/
  322. $inc_type = 'web';
  323. foreach ($param as $key => $val) {
  324. if (preg_match("/^".$inc_type."_(.)+/i", $key) !== 1) {
  325. $nowKey = strtolower($inc_type.'_'.$key);
  326. $param[$nowKey] = $val;
  327. }
  328. }
  329. tpCache($inc_type, $param, $lang, $options);
  330. /*--end*/
  331. }
  332. }
  333. if (!function_exists('write_html_cache'))
  334. {
  335. /**
  336. * 写入静态页面缓存
  337. */
  338. function write_html_cache($html = ''){
  339. $html_cache_status = config('HTML_CACHE_STATUS');
  340. $html_cache_arr = config('HTML_CACHE_ARR');
  341. if ($html_cache_status && !empty($html_cache_arr) && !empty($html)) {
  342. $home_lang = get_home_lang(); // 多语言
  343. $request = \think\Request::instance();
  344. $param = input('param.');
  345. /*URL模式是否启动页面缓存(排除admin后台、前台可视化装修、前台筛选)*/
  346. $uiset = input('param.uiset/s', 'off');
  347. $uiset = trim($uiset, '/');
  348. $url_screen_var = config('global.url_screen_var');
  349. if (isset($param[$url_screen_var]) || 'on' == $uiset || 'admin' == $request->module()) {
  350. return false;
  351. }
  352. $seo_pseudo = config('ey_config.seo_pseudo');
  353. if (!in_array($seo_pseudo, array(1,3)) && (2 == $seo_pseudo && !isMobile())) { // 排除普通动态模式
  354. return false;
  355. }
  356. /*--end*/
  357. if (1 == $seo_pseudo) {
  358. isset($param['tid']) && $param['tid'] = input('param.tid/d');
  359. } else {
  360. isset($param['tid']) && $param['tid'] = input('param.tid/s');
  361. }
  362. isset($param['page']) && $param['page'] = input('param.page/d');
  363. // aid唯一性的处理
  364. if (isset($param['aid'])) {
  365. if (strval(intval($param['aid'])) !== strval($param['aid'])) {
  366. abort(404,'页面不存在');
  367. }
  368. $param['aid'] = intval($param['aid']);
  369. }
  370. $m_c_a_str = $request->module().'_'.$request->controller().'_'.$request->action(); // 模块_控制器_方法
  371. $m_c_a_str = strtolower($m_c_a_str);
  372. //exit('write_html_cache写入缓存<br/>');
  373. foreach($html_cache_arr as $mca=>$val)
  374. {
  375. $mca = strtolower($mca);
  376. if($mca != $m_c_a_str) //不是当前 模块 控制器 方法 直接跳过
  377. continue;
  378. if (empty($val['filename'])) {
  379. continue;
  380. }
  381. $cache_tag = ''; // 缓存标签
  382. $filename = '';
  383. // 组合参数
  384. if(isset($val['p']))
  385. {
  386. $tid = '';
  387. if (in_array('tid', $val['p'])) {
  388. $tid = $param['tid'];
  389. if (strval(intval($tid)) != strval($tid)) {
  390. $tid = \think\Db::name('arctype')->where([
  391. 'dirname' => $tid,
  392. 'lang' => $home_lang,
  393. ])->getField('id');
  394. $param['tid'] = $tid;
  395. }
  396. }
  397. foreach ($val['p'] as $k=>$v) {
  398. if (isset($param[$v])) {
  399. if (preg_match('/\/$/i', $filename)) {
  400. $filename .= $param[$v];
  401. } else {
  402. if (!empty($filename)) {
  403. $filename .= '_';
  404. }
  405. $filename .= $param[$v];
  406. }
  407. }
  408. }
  409. /*针对列表缓存的标签*/
  410. !empty($tid) && $cache_tag = $tid;
  411. /*--end*/
  412. /*针对内容缓存的标签*/
  413. $aid = input("param.aid/d");
  414. !empty($aid) && $cache_tag = $aid;
  415. /*--end*/
  416. }
  417. empty($filename) && $filename = 'index';
  418. /*子域名(移动端域名)*/
  419. $is_mobile_domain = false;
  420. $web_mobile_domain = config('tpcache.web_mobile_domain');
  421. $goto = $request->param('goto');
  422. $goto = trim($goto, '/');
  423. $subDomain = $request->subDomain();
  424. if ('m' == $goto || (!empty($subDomain) && $subDomain == $web_mobile_domain)) {
  425. $is_mobile_domain = true;
  426. } else {
  427. if (3 == $seo_pseudo) {
  428. $pathinfo = $request->pathinfo();
  429. if (!empty($pathinfo)) {
  430. $s_arr = explode('/', $pathinfo);
  431. if ('m' == $s_arr[0]) {
  432. $is_mobile_domain = true;
  433. }
  434. }
  435. }
  436. }
  437. /*end*/
  438. // 缓存时间
  439. $web_cmsmode = 1;//tpCache('web.web_cmsmode');
  440. if (1 == intval($web_cmsmode)) { // 永久
  441. $path = HTML_PATH.$val['filename'].DS.$home_lang;
  442. if (isMobile() || $is_mobile_domain) {
  443. $path .= "_mobile";
  444. } else {
  445. $path .= "_pc";
  446. }
  447. $filename = $path.'_html'.DS."{$filename}.html";
  448. tp_mkdir(dirname($filename));
  449. !empty($html) && file_put_contents($filename, $html);
  450. } else {
  451. $path = HTML_PATH.$val['filename'].DS.$home_lang;
  452. if (isMobile()) {
  453. $path .= "_mobile";
  454. } else {
  455. $path .= "_pc";
  456. }
  457. $path .= '_cache'.DS;
  458. $web_htmlcache_expires_in = config('tpcache.web_htmlcache_expires_in');
  459. $options = array(
  460. 'path' => $path,
  461. 'expire'=> intval($web_htmlcache_expires_in),
  462. 'prefix' => $cache_tag,
  463. );
  464. !empty($html) && html_cache($filename,$html,$options);
  465. }
  466. }
  467. }
  468. }
  469. }
  470. if (!function_exists('read_html_cache'))
  471. {
  472. /**
  473. * 读取静态页面缓存
  474. */
  475. function read_html_cache(){
  476. $html_cache_status = config('HTML_CACHE_STATUS');
  477. $html_cache_arr = config('HTML_CACHE_ARR');
  478. if ($html_cache_status && !empty($html_cache_arr)) {
  479. $home_lang = get_home_lang();
  480. $request = \think\Request::instance();
  481. $seo_pseudo = config('ey_config.seo_pseudo');
  482. $param = input('param.');
  483. /*前台筛选不进行页面缓存*/
  484. $url_screen_var = config('global.url_screen_var');
  485. if (isset($param[$url_screen_var])) {
  486. return false;
  487. }
  488. /*end*/
  489. if (1 == $seo_pseudo) {
  490. isset($param['tid']) && $param['tid'] = input('param.tid/d');
  491. } else {
  492. isset($param['tid']) && $param['tid'] = input('param.tid/s');
  493. }
  494. isset($param['page']) && $param['page'] = input('param.page/d');
  495. // aid唯一性的处理
  496. if (isset($param['aid'])) {
  497. if (strval(intval($param['aid'])) !== strval($param['aid'])) {
  498. abort(404,'页面不存在');
  499. }
  500. $param['aid'] = intval($param['aid']);
  501. }
  502. $m_c_a_str = $request->module().'_'.$request->controller().'_'.$request->action(); // 模块_控制器_方法
  503. $m_c_a_str = strtolower($m_c_a_str);
  504. //exit('read_html_cache读取缓存<br/>');
  505. foreach($html_cache_arr as $mca=>$val)
  506. {
  507. $mca = strtolower($mca);
  508. if($mca != $m_c_a_str) //不是当前 模块 控制器 方法 直接跳过
  509. continue;
  510. if (empty($val['filename'])) {
  511. continue;
  512. }
  513. $cache_tag = ''; // 缓存标签
  514. $filename = '';
  515. // 组合参数
  516. if(isset($val['p']))
  517. {
  518. $tid = '';
  519. if (in_array('tid', $val['p'])) {
  520. $tid = $param['tid'];
  521. if (strval(intval($tid)) != strval($tid)) {
  522. $tid = \think\Db::name('arctype')->where([
  523. 'dirname' => $tid,
  524. 'lang' => $home_lang,
  525. ])->getField('id');
  526. $param['tid'] = $tid;
  527. }
  528. }
  529. foreach ($val['p'] as $k=>$v) {
  530. if (isset($param[$v])) {
  531. if (preg_match('/\/$/i', $filename)) {
  532. $filename .= $param[$v];
  533. } else {
  534. if (!empty($filename)) {
  535. $filename .= '_';
  536. }
  537. $filename .= $param[$v];
  538. }
  539. }
  540. }
  541. /*针对列表缓存的标签*/
  542. !empty($tid) && $cache_tag = $tid;
  543. /*--end*/
  544. /*针对内容缓存的标签*/
  545. $aid = input("param.aid/d");
  546. !empty($aid) && $cache_tag = $aid;
  547. /*--end*/
  548. }
  549. empty($filename) && $filename = 'index';
  550. /*子域名(移动端域名)*/
  551. $is_mobile_domain = false;
  552. $web_mobile_domain = config('tpcache.web_mobile_domain');
  553. $goto = $request->param('goto');
  554. $goto = trim($goto, '/');
  555. $subDomain = $request->subDomain();
  556. if ('m' == $goto || (!empty($subDomain) && $subDomain == $web_mobile_domain)) {
  557. $is_mobile_domain = true;
  558. } else {
  559. if (3 == $seo_pseudo) {
  560. $pathinfo = $request->pathinfo();
  561. if (!empty($pathinfo)) {
  562. $s_arr = explode('/', $pathinfo);
  563. if ('m' == $s_arr[0]) {
  564. $is_mobile_domain = true;
  565. }
  566. }
  567. }
  568. }
  569. /*end*/
  570. // 缓存时间
  571. $web_cmsmode = 1;//tpCache('web.web_cmsmode');
  572. if (1 == intval($web_cmsmode)) { // 永久
  573. $path = HTML_PATH.$val['filename'].DS.$home_lang;
  574. if (isMobile() || $is_mobile_domain) {
  575. $path .= "_mobile";
  576. } else {
  577. $path .= "_pc";
  578. }
  579. $filename = $path.'_html'.DS."{$filename}.html";
  580. if(is_file($filename) && file_exists($filename))
  581. {
  582. echo file_get_contents($filename);
  583. exit();
  584. }
  585. } else {
  586. $path = HTML_PATH.$val['filename'].DS.$home_lang;
  587. if (isMobile()) {
  588. $path .= "_mobile";
  589. } else {
  590. $path .= "_pc";
  591. }
  592. $path .= '_cache'.DS;
  593. $web_htmlcache_expires_in = config('tpcache.web_htmlcache_expires_in');
  594. $options = array(
  595. 'path' => $path,
  596. 'expire'=> intval($web_htmlcache_expires_in),
  597. 'prefix' => $cache_tag,
  598. );
  599. $html = html_cache($filename, '', $options);
  600. // $html = $html_cache->get($filename);
  601. if($html)
  602. {
  603. echo $html;
  604. exit();
  605. }
  606. }
  607. }
  608. }
  609. }
  610. }
  611. if (!function_exists('is_local_images'))
  612. {
  613. /**
  614. * 判断远程链接是否属于本地图片,并返回本地图片路径
  615. *
  616. * @param string $pic_url 图片地址
  617. * @param boolean $returnbool 返回类型,false 返回图片路径,true 返回布尔值
  618. */
  619. function is_local_images($pic_url = '', $returnbool = false)
  620. {
  621. $picPath = parse_url($pic_url, PHP_URL_PATH);
  622. // if (preg_match('/^([^:]*):?\/\/([^\/]+)(.*)\/(uploads\/allimg|public\/upload)\/(.*)\.([^\.]+)$/i', $pic_url) && file_exists('.'.$picPath)) {
  623. if (!empty($picPath) && file_exists('.'.$picPath)) {
  624. $picPath = preg_replace('#^'.ROOT_DIR.'/#i', '/', $picPath);
  625. $pic_url = ROOT_DIR.$picPath;
  626. if (true == $returnbool) {
  627. return $pic_url;
  628. }
  629. }
  630. if (true == $returnbool) {
  631. return false;
  632. } else {
  633. return $pic_url;
  634. }
  635. }
  636. }
  637. if (!function_exists('get_head_pic'))
  638. {
  639. /**
  640. * 默认头像
  641. */
  642. function get_head_pic($pic_url = '', $is_admin = false)
  643. {
  644. if ($is_admin) {
  645. $default_pic = ROOT_DIR . '/public/static/admin/images/admint.png';
  646. } else {
  647. $default_pic = ROOT_DIR . '/public/static/common/images/dfboy.png';
  648. }
  649. return empty($pic_url) ? $default_pic : $pic_url;
  650. }
  651. }
  652. if (!function_exists('get_default_pic'))
  653. {
  654. /**
  655. * 图片不存在,显示默认无图封面
  656. * @param string $pic_url 图片路径
  657. * @param string|boolean $domain 完整路径的域名
  658. */
  659. function get_default_pic($pic_url = '', $domain = false)
  660. {
  661. if (!is_http_url($pic_url)) {
  662. if (true === $domain) {
  663. $domain = request()->domain();
  664. } else if (false === $domain) {
  665. $domain = '';
  666. }
  667. $pic_url = preg_replace('#^(/[/\w]+)?(/public/upload/|/public/static/|/uploads/|/weapp/)#i', '$2', $pic_url); // 支持子目录
  668. $realpath = realpath(trim($pic_url, '/'));
  669. if ( is_file($realpath) && file_exists($realpath) ) {
  670. $pic_url = $domain . ROOT_DIR . $pic_url;
  671. } else {
  672. $pic_url = $domain . ROOT_DIR . '/public/static/common/images/not_adv.jpg';
  673. }
  674. }
  675. return $pic_url;
  676. }
  677. }
  678. if (!function_exists('handle_subdir_pic'))
  679. {
  680. /**
  681. * 处理子目录与根目录的图片平缓切换
  682. * @param string $str 图片路径或html代码
  683. */
  684. function handle_subdir_pic($str = '', $type = 'img', $domain = false)
  685. {
  686. $root_dir = ROOT_DIR;
  687. switch ($type) {
  688. case 'img':
  689. if (!is_http_url($str) && !empty($str)) {
  690. // if (!empty($root_dir)) { // 子目录之间切换
  691. $str = preg_replace('#^(/[/\w]+)?(/public/upload/|/public/static/|/uploads/|/weapp/)#i', $root_dir.'$2', $str);
  692. // } else { // 子目录与根目录切换
  693. // $str = preg_replace('#^(/[/\w]+)?(/public/upload/|/uploads/)#i', $root_dir.'$2', $str);
  694. // }
  695. }else if (is_http_url($str) && !empty($str)) {
  696. // 图片路径处理
  697. $str = preg_replace('#^(/[/\w]+)?(/public/upload/|/uploads/|/public/static/)#i', $root_dir.'$2', $str);
  698. $StrData = parse_url($str);
  699. $strlen = strlen($root_dir);
  700. if (empty($StrData['scheme'])) {
  701. if ('/uploads/'==substr($StrData['path'],$strlen,9) || '/public/upload/'==substr($StrData['path'],$strlen,15)) {
  702. // 七牛云配置处理
  703. static $Qiniuyun = null;
  704. if (null == $Qiniuyun) {
  705. // 需要填写你的 Access Key 和 Secret Key
  706. $data = M('weapp')->where('code','Qiniuyun')->field('data,status')->find();
  707. $Qiniuyun = json_decode($data['data'], true);
  708. $Qiniuyun['status'] = $data['status'];
  709. }
  710. // 是否开启图片加速
  711. if ('1' == $Qiniuyun['status']) {
  712. // 开启
  713. if ($Qiniuyun['domain'] == $StrData['host']) {
  714. $tcp = !empty($Qiniuyun['tcp']) ? $Qiniuyun['tcp'] : '';
  715. switch ($tcp) {
  716. case '2':
  717. $tcp = 'https://';
  718. break;
  719. case '3':
  720. $tcp = '//';
  721. break;
  722. case '1':
  723. default:
  724. $tcp = 'http://';
  725. break;
  726. }
  727. $str = $tcp.$Qiniuyun['domain'].$StrData['path'];
  728. }else{
  729. // 若切换了存储空间或访问域名,与数据库中存储的图片路径域名不一致时,访问本地路径,保证图片正常
  730. $str = $StrData['path'];
  731. }
  732. }else{
  733. // 关闭
  734. $str = $StrData['path'];
  735. }
  736. }
  737. }
  738. }
  739. break;
  740. case 'html':
  741. // if (!empty($root_dir)) { // 子目录之间切换
  742. $str = preg_replace('#(.*)(\#39;|&quot;|"|\')(/[/\w]+)?(/public/upload/|/public/plugins/|/uploads/)(.*)#iU', '$1$2'.$root_dir.'$4$5', $str);
  743. // } else { // 子目录与根目录切换
  744. // $str = preg_replace('#(.*)(\#39;|&quot;|"|\')(/[/\w]+)?(/public/upload/|/public/plugins/|/uploads/)(.*)#iU', '$1$2'.$root_dir.'$4$5', $str);
  745. // }
  746. break;
  747. case 'soft':
  748. if (!is_http_url($str) && !empty($str)) {
  749. $str = preg_replace('#^(/[/\w]+)?(/public/upload/soft/|/uploads/soft/)#i', $root_dir.'$2', $str);
  750. }
  751. break;
  752. case 'media': //多媒体文件
  753. if (!is_http_url($str) && !empty($str)) {
  754. $str = preg_replace('#^(/[/\w]+)?(/uploads/media/)#i', $root_dir.'$2', $str);
  755. }
  756. break;
  757. default:
  758. # code...
  759. break;
  760. }
  761. if (!empty($str) && !is_http_url($str) && false !== $domain) {
  762. if (true === $domain) {
  763. static $domain_new = null;
  764. if (null === $domain_new) {
  765. $request = \think\Request::instance();
  766. $domain_new = $request->domain();
  767. }
  768. $domain = $domain_new;
  769. }
  770. $str = $domain.$str;
  771. }
  772. return $str;
  773. }
  774. }
  775. /**
  776. * 获取阅读权限
  777. */
  778. if ( ! function_exists('get_arcrank_list'))
  779. {
  780. function get_arcrank_list()
  781. {
  782. $result = \think\Db::name('arcrank')->where([
  783. 'lang' => get_admin_lang(),
  784. ])
  785. ->order('id asc')
  786. ->cache(true,0,"arcrank")
  787. ->getAllWithIndex('rank');
  788. // 等级分类
  789. $LevelData = \think\Db::name('users_level')->field('level_name as `name`, level_value as `rank`')->order('level_value asc, level_id asc')->select();
  790. if (!empty($LevelData)) {
  791. $result = array_merge($result, $LevelData);
  792. }
  793. return $result;
  794. }
  795. }
  796. if (!function_exists('thumb_img'))
  797. {
  798. /**
  799. * 缩略图 从原始图来处理出来
  800. * @param type $original_img 图片路径
  801. * @param type $width 生成缩略图的宽度
  802. * @param type $height 生成缩略图的高度
  803. * @param type $thumb_mode 生成方式
  804. */
  805. function thumb_img($original_img = '', $width = '', $height = '', $thumb_mode = '')
  806. {
  807. // 缩略图配置
  808. static $thumbConfig = null;
  809. null === $thumbConfig && $thumbConfig = tpCache('thumb');
  810. $thumbextra = config('global.thumb');
  811. if (!empty($width) || !empty($height) || !empty($thumb_mode)) { // 单独在模板里调用,不受缩略图全局开关影响
  812. } else { // 非单独模板调用,比如内置的arclist\list标签里
  813. if (empty($thumbConfig['thumb_open'])) {
  814. return $original_img;
  815. }
  816. }
  817. // 缩略图优先级别高于七牛云,自动把七牛云的图片路径转为本地图片路径,并且进行缩略图
  818. $original_img = is_local_images($original_img);
  819. // 未开启缩略图,或远程图片
  820. if (is_http_url($original_img) || stristr($original_img, '/public/static/common/images/not_adv.jpg')) {
  821. return $original_img;
  822. } else if (empty($original_img)) {
  823. return ROOT_DIR.'/public/static/common/images/not_adv.jpg';
  824. }
  825. // 图片文件名
  826. $filename = '';
  827. $imgArr = explode('/', $original_img);
  828. $imgArr = end($imgArr);
  829. $filename = preg_replace("/\.([^\.]+)$/i", "", $imgArr);
  830. $file_ext = preg_replace("/^(.*)\.([^\.]+)$/i", "$2", $imgArr);
  831. // 如果图片参数是缩略图,则直接获取到原图,并进行缩略处理
  832. if (preg_match('/\/uploads\/thumb\/\d{1,}_\d{1,}\//i', $original_img)) {
  833. $pattern = UPLOAD_PATH.'allimg/*/'.$filename;
  834. if (in_array(strtolower($file_ext), ['jpg','jpeg'])) {
  835. $pattern .= '.jp*g';
  836. } else {
  837. $pattern .= '.'.$file_ext;
  838. }
  839. $original_img_tmp = glob($pattern);
  840. if (!empty($original_img_tmp)) {
  841. $original_img = '/'.current($original_img_tmp);
  842. }
  843. } else {
  844. if ('bmp' == $file_ext && version_compare(PHP_VERSION,'7.2.0','<')) {
  845. return $original_img;
  846. }
  847. }
  848. // --end
  849. $original_img1 = preg_replace('#^'.ROOT_DIR.'#i', '', handle_subdir_pic($original_img));
  850. $original_img1 = '.' . $original_img1; // 相对路径
  851. //获取图像信息
  852. $info = @getimagesize($original_img1);
  853. //检测图像合法性
  854. if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) {
  855. return $original_img;
  856. } else {
  857. if (!empty($info['mime']) && stristr($info['mime'], 'bmp') && version_compare(PHP_VERSION,'7.2.0','<')) {
  858. return $original_img;
  859. }
  860. }
  861. // 缩略图宽高度
  862. empty($width) && $width = !empty($thumbConfig['thumb_width']) ? $thumbConfig['thumb_width'] : $thumbextra['width'];
  863. empty($height) && $height = !empty($thumbConfig['thumb_height']) ? $thumbConfig['thumb_height'] : $thumbextra['height'];
  864. $width = intval($width);
  865. $height = intval($height);
  866. //判断缩略图是否存在
  867. $path = UPLOAD_PATH."thumb/{$width}_{$height}/";
  868. $img_thumb_name = "{$filename}";
  869. // 已经生成过这个比例的图片就直接返回了
  870. if (is_file($path . $img_thumb_name . '.jpg')) return ROOT_DIR.'/' . $path . $img_thumb_name . '.jpg';
  871. if (is_file($path . $img_thumb_name . '.jpeg')) return ROOT_DIR.'/' . $path . $img_thumb_name . '.jpeg';
  872. if (is_file($path . $img_thumb_name . '.gif')) return ROOT_DIR.'/' . $path . $img_thumb_name . '.gif';
  873. if (is_file($path . $img_thumb_name . '.png')) return ROOT_DIR.'/' . $path . $img_thumb_name . '.png';
  874. if (is_file($path . $img_thumb_name . '.bmp')) return ROOT_DIR.'/' . $path . $img_thumb_name . '.bmp';
  875. if (!is_file($original_img1)) {
  876. return ROOT_DIR.'/public/static/common/images/not_adv.jpg';
  877. }
  878. try {
  879. vendor('topthink.think-image.src.Image');
  880. vendor('topthink.think-image.src.image.Exception');
  881. if(stristr($original_img1,'.gif'))
  882. {
  883. vendor('topthink.think-image.src.image.gif.Encoder');
  884. vendor('topthink.think-image.src.image.gif.Decoder');
  885. vendor('topthink.think-image.src.image.gif.Gif');
  886. }
  887. $image = \think\Image::open($original_img1);
  888. $img_thumb_name = $img_thumb_name . '.' . $image->type();
  889. // 生成缩略图
  890. !is_dir($path) && mkdir($path, 0777, true);
  891. // 填充颜色
  892. $thumb_color = !empty($thumbConfig['thumb_color']) ? $thumbConfig['thumb_color'] : $thumbextra['color'];
  893. // 生成方式参考 vendor/topthink/think-image/src/Image.php
  894. if (!empty($thumb_mode)) {
  895. $thumb_mode = intval($thumb_mode);
  896. } else {
  897. $thumb_mode = !empty($thumbConfig['thumb_mode']) ? $thumbConfig['thumb_mode'] : $thumbextra['mode'];
  898. }
  899. 1 == $thumb_mode && $thumb_mode = 6; // 按照固定比例拉伸
  900. 2 == $thumb_mode && $thumb_mode = 2; // 填充空白
  901. if (3 == $thumb_mode) {
  902. $img_width = $image->width();
  903. $img_height = $image->height();
  904. if ($width < $img_width && $height < $img_height) {
  905. // 先进行缩略图等比例缩放类型,取出宽高中最小的属性值
  906. $min_width = ($img_width < $img_height) ? $img_width : 0;
  907. $min_height = ($img_width > $img_height) ? $img_height : 0;
  908. if ($min_width > $width || $min_height > $height) {
  909. if (0 < intval($min_width)) {
  910. $scale = $min_width / min($width, $height);
  911. } else if (0 < intval($min_height)) {
  912. $scale = $min_height / $height;
  913. } else {
  914. $scale = $min_width / $width;
  915. }
  916. $s_width = $img_width / $scale;
  917. $s_height = $img_height / $scale;
  918. $image->thumb($s_width, $s_height, 1, $thumb_color)->save($path . $img_thumb_name, NULL, 100); //按照原图的比例生成一个最大为$width*$height的缩略图并保存
  919. }
  920. }
  921. $thumb_mode = 3; // 截减
  922. }
  923. // 参考文章 http://www.mb5u.com/biancheng/php/php_84533.html 改动参考 http://www.thinkphp.cn/topic/13542.html
  924. $image->thumb($width, $height, $thumb_mode, $thumb_color)->save($path . $img_thumb_name, NULL, 100); //按照原图的比例生成一个最大为$width*$height的缩略图并保存
  925. //图片水印处理
  926. $water = tpCache('water');
  927. if($water['is_mark']==1 && $water['is_thumb_mark'] == 1 && $image->width()>$water['mark_width'] && $image->height()>$water['mark_height']){
  928. $imgresource = '.' . ROOT_DIR . '/' . $path . $img_thumb_name;
  929. if($water['mark_type'] == 'text'){
  930. //$image->text($water['mark_txt'],ROOT_PATH.'public/static/common/font/hgzb.ttf',20,'#000000',9)->save($imgresource);
  931. $ttf = ROOT_PATH.'public/static/common/font/hgzb.ttf';
  932. if (file_exists($ttf)) {
  933. $size = $water['mark_txt_size'] ? $water['mark_txt_size'] : 30;
  934. $color = $water['mark_txt_color'] ?: '#000000';
  935. if (!preg_match('/^#[0-9a-fA-F]{6}$/', $color)) {
  936. $color = '#000000';
  937. }
  938. $transparency = intval((100 - $water['mark_degree']) * (127/100));
  939. $color .= dechex($transparency);
  940. $image->open($imgresource)->text($water['mark_txt'], $ttf, $size, $color, $water['mark_sel'])->save($imgresource);
  941. $return_data['mark_txt'] = $water['mark_txt'];
  942. }
  943. }else{
  944. /*支持子目录*/
  945. $water['mark_img'] = preg_replace('#^(/[/\w]+)?(/public/upload/|/uploads/)#i', '$2', $water['mark_img']); // 支持子目录
  946. /*--end*/
  947. //$image->water(".".$water['mark_img'],9,$water['mark_degree'])->save($imgresource);
  948. $waterPath = "." . $water['mark_img'];
  949. if (eyPreventShell($waterPath) && file_exists($waterPath)) {
  950. $quality = $water['mark_quality'] ? $water['mark_quality'] : 80;
  951. $waterTempPath = dirname($waterPath).'/temp_'.basename($waterPath);
  952. $image->open($waterPath)->save($waterTempPath, null, $quality);
  953. $image->open($imgresource)->water($waterTempPath, $water['mark_sel'], $water['mark_degree'])->save($imgresource);
  954. @unlink($waterTempPath);
  955. }
  956. }
  957. }
  958. $img_url = ROOT_DIR.'/' . $path . $img_thumb_name;
  959. return $img_url;
  960. } catch (think\Exception $e) {
  961. return $original_img;
  962. }
  963. }
  964. }
  965. if (!function_exists('get_controller_byct')) {
  966. /**
  967. * 根据模型ID获取控制器的名称
  968. * @return mixed
  969. */
  970. function get_controller_byct($current_channel)
  971. {
  972. $channeltype_info = model('Channeltype')->getInfo($current_channel);
  973. return $channeltype_info['ctl_name'];
  974. }
  975. }
  976. if (!function_exists('ui_read_bidden_inc')) {
  977. /**
  978. * 读取被禁止外部访问的配置文件
  979. * @param string $filename 文件路径
  980. * @return mixed
  981. */
  982. function ui_read_bidden_inc($filename)
  983. {
  984. $data = false;
  985. if (file_exists($filename)) {
  986. $data = @file($filename);
  987. $data = json_decode($data[1], true);
  988. }
  989. if (empty($data)) {
  990. // -------------优先读取配置文件,不存在才读取数据表
  991. $params = explode('/', $filename);
  992. $page = $params[count($params) - 1];
  993. $pagearr = explode('.', $page);
  994. reset($pagearr);
  995. $page = current($pagearr);
  996. $map = array(
  997. 'page' => $page,
  998. 'theme_style' => THEME_STYLE,
  999. );
  1000. $result = M('ui_config')->where($map)->cache(true,EYOUCMS_CACHE_TIME,"ui_config")->select();
  1001. if ($result) {
  1002. $dataArr = array();
  1003. foreach ($result as $key => $val) {
  1004. $k = "{$val['lang']}_{$val['type']}_{$val['name']}";
  1005. $dataArr[$k] = $val['value'];
  1006. }
  1007. $data = $dataArr;
  1008. } else {
  1009. $data = false;
  1010. }
  1011. //---------------end
  1012. if (!empty($data)) {
  1013. // ----------文件不存在,并写入文件缓存
  1014. tp_mkdir(dirname($filename));
  1015. $nowData = $data;
  1016. $setting = "<?php die('forbidden'); ?>\n";
  1017. $setting .= json_encode($nowData);
  1018. $setting = str_replace("\/", "/",$setting);
  1019. $incFile = fopen($filename, "w+");
  1020. if ($incFile != false && fwrite($incFile, $setting)) {
  1021. fclose($incFile);
  1022. }
  1023. //---------------end
  1024. }
  1025. }
  1026. return $data;
  1027. }
  1028. }
  1029. if (!function_exists('ui_write_bidden_inc')) {
  1030. /**
  1031. * 写入被禁止外部访问的配置文件
  1032. * @param array $arr 配置变量
  1033. * @param string $filename 文件路径
  1034. * @param bool $is_append false
  1035. * @return mixed
  1036. */
  1037. function ui_write_bidden_inc($data, $filename, $is_append = false)
  1038. {
  1039. $data2 = $data;
  1040. if (!empty($filename)) {
  1041. // -------------写入数据表,同时写入配置文件
  1042. reset($data2);
  1043. $value = current($data2);
  1044. $tmp_val = json_decode($value, true);
  1045. $name = $tmp_val['id'];
  1046. $type = $tmp_val['type'];
  1047. $page = $tmp_val['page'];
  1048. $lang = !empty($tmp_val['lang']) ? $tmp_val['lang'] : cookie(config('global.home_lang'));
  1049. if (empty($lang)) {
  1050. $lang = model('language')->order('id asc')
  1051. ->limit(1)
  1052. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  1053. ->getField('mark');
  1054. }
  1055. $theme_style = THEME_STYLE;
  1056. $md5key = md5($name.$page.$theme_style.$lang);
  1057. $savedata = array(
  1058. 'md5key' => $md5key,
  1059. 'theme_style' => $theme_style,
  1060. 'page' => $page,
  1061. 'type' => $type,
  1062. 'name' => $name,
  1063. 'value' => $value,
  1064. 'lang' => $lang,
  1065. );
  1066. $map = array(
  1067. 'name' => $name,
  1068. 'page' => $page,
  1069. 'theme_style' => $theme_style,
  1070. 'lang' => $lang,
  1071. );
  1072. $count = M('ui_config')->where($map)->count('id');
  1073. if ($count > 0) {
  1074. $savedata['update_time'] = getTime();
  1075. $r = M('ui_config')->where($map)->cache(true,EYOUCMS_CACHE_TIME,'ui_config')->update($savedata);
  1076. } else {
  1077. $savedata['add_time'] = getTime();
  1078. $savedata['update_time'] = getTime();
  1079. $r = M('ui_config')->insert($savedata);
  1080. \think\Cache::clear('ui_config');
  1081. }
  1082. if ($r) {
  1083. // ----------同时写入文件缓存
  1084. tp_mkdir(dirname($filename));
  1085. // 追加
  1086. if ($is_append) {
  1087. $inc = ui_read_bidden_inc($filename);
  1088. if ($inc) {
  1089. $oldarr = (array)$inc;
  1090. $data = array_merge($oldarr, $data);
  1091. }
  1092. }
  1093. $setting = "<?php die('forbidden'); ?>\n";
  1094. $setting .= json_encode($data);
  1095. $setting = str_replace("\/", "/",$setting);
  1096. $incFile = fopen($filename, "w+");
  1097. if ($incFile != false && fwrite($incFile, $setting)) {
  1098. fclose($incFile);
  1099. }
  1100. //---------------end
  1101. return true;
  1102. }
  1103. }
  1104. return false;
  1105. }
  1106. }
  1107. if (!function_exists('get_ui_inc_params')) {
  1108. /**
  1109. * 获取模板主题的美化配置参数
  1110. * @return mixed
  1111. */
  1112. function get_ui_inc_params($page)
  1113. {
  1114. $e_page = $page;
  1115. $filename = RUNTIME_PATH.'ui/'.THEME_STYLE.'/'.$e_page.'.inc.php';
  1116. $inc = ui_read_bidden_inc($filename);
  1117. return $inc;
  1118. }
  1119. }
  1120. if (!function_exists('allow_release_arctype'))
  1121. {
  1122. /**
  1123. * 允许发布文档的栏目列表
  1124. */
  1125. function allow_release_arctype($selected = 0, $allow_release_channel = array(), $selectform = true)
  1126. {
  1127. $where = [];
  1128. $where['c.weapp_code'] = ''; // 回收站功能
  1129. $where['c.lang'] = get_current_lang(); // 多语言 by 小虎哥
  1130. $where['c.is_del'] = 0; // 回收站功能
  1131. /*权限控制 by 小虎哥*/
  1132. $admin_info = session('admin_info');
  1133. if (0 < intval($admin_info['role_id'])) {
  1134. $auth_role_info = $admin_info['auth_role_info'];
  1135. if(! empty($auth_role_info)){
  1136. if(! empty($auth_role_info['permission']['arctype'])){
  1137. $where['c.id'] = array('IN', $auth_role_info['permission']['arctype']);
  1138. }
  1139. }
  1140. }
  1141. /*--end*/
  1142. if (!is_array($selected)) {
  1143. $selected = [$selected];
  1144. }
  1145. $cacheKey = json_encode($selected).json_encode($allow_release_channel).$selectform.json_encode($where);
  1146. $select_html = cache($cacheKey);
  1147. if (empty($select_html) || false == $selectform) {
  1148. /*允许发布文档的模型*/
  1149. $allow_release_channel = !empty($allow_release_channel) ? $allow_release_channel : config('global.allow_release_channel');
  1150. /*所有栏目分类*/
  1151. $arctype_max_level = intval(config('global.arctype_max_level'));
  1152. $where['c.status'] = 1;
  1153. $fields = "c.id, c.parent_id, c.current_channel, c.typename, c.grade, count(s.id) as has_children, '' as children";
  1154. $res = \think\Db::name('arctype')
  1155. ->field($fields)
  1156. ->alias('c')
  1157. ->join('__ARCTYPE__ s','s.parent_id = c.id','LEFT')
  1158. ->where($where)
  1159. ->group('c.id')
  1160. ->order('c.parent_id asc, c.sort_order asc, c.id')
  1161. ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  1162. ->select();
  1163. /*--end*/
  1164. if (empty($res)) {
  1165. return '';
  1166. }
  1167. /*过滤掉第三级栏目属于不允许发布的模型下*/
  1168. foreach ($res as $key => $val) {
  1169. if ($val['grade'] == ($arctype_max_level - 1) && !in_array($val['current_channel'], $allow_release_channel)) {
  1170. unset($res[$key]);
  1171. }
  1172. }
  1173. /*--end*/
  1174. /*所有栏目列表进行层次归类*/
  1175. $arr = group_same_key($res, 'parent_id');
  1176. for ($i=0; $i < $arctype_max_level; $i++) {
  1177. foreach ($arr as $key => $val) {
  1178. foreach ($arr[$key] as $key2 => $val2) {
  1179. if (!isset($arr[$val2['id']])) {
  1180. $arr[$key][$key2]['has_children'] = 0;
  1181. continue;
  1182. }
  1183. $val2['children'] = $arr[$val2['id']];
  1184. $arr[$key][$key2] = $val2;
  1185. }
  1186. }
  1187. }
  1188. /*--end*/
  1189. /*过滤掉第二级不包含允许发布模型的栏目*/
  1190. $nowArr = $arr[0];
  1191. foreach ($nowArr as $key => $val) {
  1192. if (!empty($nowArr[$key]['children'])) {
  1193. foreach ($nowArr[$key]['children'] as $key2 => $val2) {
  1194. if (empty($val2['children']) && !in_array($val2['current_channel'], $allow_release_channel)) {
  1195. unset($nowArr[$key]['children'][$key2]);
  1196. }
  1197. }
  1198. }
  1199. if (empty($nowArr[$key]['children']) && !in_array($nowArr[$key]['current_channel'], $allow_release_channel)) {
  1200. unset($nowArr[$key]);
  1201. continue;
  1202. }
  1203. }
  1204. /*--end*/
  1205. /*组装成层级下拉列表框*/
  1206. $select_html = '';
  1207. if (false == $selectform) {
  1208. $select_html = $nowArr;
  1209. } else if (true == $selectform) {
  1210. foreach ($nowArr AS $key => $val)
  1211. {
  1212. $select_html .= '<option value="' . $val['id'] . '" data-grade="' . $val['grade'] . '" data-current_channel="' . $val['current_channel'] . '"';
  1213. $select_html .= (in_array($val['id'], $selected)) ? ' selected="ture"' : '';
  1214. if (!empty($allow_release_channel) && !in_array($val['current_channel'], $allow_release_channel)) {
  1215. $select_html .= ' disabled="true" style="background-color:#f5f5f5;"';
  1216. }
  1217. $select_html .= '>';
  1218. if ($val['grade'] > 0)
  1219. {
  1220. $select_html .= str_repeat('&nbsp;', $val['grade'] * 4);
  1221. }
  1222. $select_html .= htmlspecialchars_decode(addslashes($val['typename'])) . '</option>';
  1223. if (empty($val['children'])) {
  1224. continue;
  1225. }
  1226. foreach ($nowArr[$key]['children'] as $key2 => $val2) {
  1227. $select_html .= '<option value="' . $val2['id'] . '" data-grade="' . $val2['grade'] . '" data-current_channel="' . $val2['current_channel'] . '"';
  1228. $select_html .= (in_array($val2['id'], $selected)) ? ' selected="ture"' : '';
  1229. if (!empty($allow_release_channel) && !in_array($val2['current_channel'], $allow_release_channel)) {
  1230. $select_html .= ' disabled="true" style="background-color:#f5f5f5;"';
  1231. }
  1232. $select_html .= '>';
  1233. if ($val2['grade'] > 0)
  1234. {
  1235. $select_html .= str_repeat('&nbsp;', $val2['grade'] * 4);
  1236. }
  1237. $select_html .= htmlspecialchars_decode(addslashes($val2['typename'])) . '</option>';
  1238. if (empty($val2['children'])) {
  1239. continue;
  1240. }
  1241. foreach ($nowArr[$key]['children'][$key2]['children'] as $key3 => $val3) {
  1242. $select_html .= '<option value="' . $val3['id'] . '" data-grade="' . $val3['grade'] . '" data-current_channel="' . $val3['current_channel'] . '"';
  1243. $select_html .= (in_array($val3['id'], $selected)) ? ' selected="ture"' : '';
  1244. if (!empty($allow_release_channel) && !in_array($val3['current_channel'], $allow_release_channel)) {
  1245. $select_html .= ' disabled="true" style="background-color:#f5f5f5;"';
  1246. }
  1247. $select_html .= '>';
  1248. if ($val3['grade'] > 0)
  1249. {
  1250. $select_html .= str_repeat('&nbsp;', $val3['grade'] * 4);
  1251. }
  1252. $select_html .= htmlspecialchars_decode(addslashes($val3['typename'])) . '</option>';
  1253. }
  1254. }
  1255. }
  1256. cache($cacheKey, $select_html, null, 'admin_archives_release');
  1257. }
  1258. }
  1259. return $select_html;
  1260. }
  1261. }
  1262. if (!function_exists('every_top_dirname_list'))
  1263. {
  1264. /**
  1265. * 获取一级栏目的目录名称
  1266. */
  1267. function every_top_dirname_list() {
  1268. $arctypeModel = new \app\common\model\Arctype();
  1269. $result = $arctypeModel->getEveryTopDirnameList();
  1270. return $result;
  1271. }
  1272. }
  1273. if (!function_exists('gettoptype'))
  1274. {
  1275. /**
  1276. * 获取当前栏目的第一级栏目
  1277. */
  1278. function gettoptype($typeid, $field = 'typename')
  1279. {
  1280. $parent_list = model('Arctype')->getAllPid($typeid); // 获取当前栏目的所有父级栏目
  1281. $result = current($parent_list); // 第一级栏目
  1282. if (isset($result[$field]) && !empty($result[$field])) {
  1283. return handle_subdir_pic($result[$field]); // 支持子目录
  1284. } else {
  1285. return '';
  1286. }
  1287. }
  1288. }
  1289. if (!function_exists('get_main_lang'))
  1290. {
  1291. /**
  1292. * 获取主体语言(语言列表里最早的一条)
  1293. */
  1294. function get_main_lang()
  1295. {
  1296. $keys = 'common_get_main_lang';
  1297. $main_lang = \think\Cache::get($keys);
  1298. if (empty($main_lang)) {
  1299. $main_lang = \think\Db::name('language')->order('id asc')
  1300. ->limit(1)
  1301. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  1302. ->getField('mark');
  1303. \think\Cache::set($keys, $main_lang);
  1304. }
  1305. return $main_lang;
  1306. }
  1307. }
  1308. if (!function_exists('get_default_lang'))
  1309. {
  1310. /**
  1311. * 获取默认语言
  1312. */
  1313. function get_default_lang()
  1314. {
  1315. $request = \think\Request::instance();
  1316. if (!stristr($request->baseFile(), 'index.php')) {
  1317. $default_lang = get_admin_lang();
  1318. } else {
  1319. $default_lang = \think\Config::get('ey_config.system_home_default_lang');
  1320. }
  1321. return $default_lang;
  1322. }
  1323. }
  1324. if (!function_exists('get_current_lang'))
  1325. {
  1326. /**
  1327. * 获取当前默认语言
  1328. */
  1329. function get_current_lang()
  1330. {
  1331. $request = \think\Request::instance();
  1332. if (!stristr($request->baseFile(), 'index.php')) {
  1333. $current_lang = get_admin_lang();
  1334. } else {
  1335. $current_lang = get_home_lang();
  1336. }
  1337. return $current_lang;
  1338. }
  1339. }
  1340. if (!function_exists('get_admin_lang'))
  1341. {
  1342. /**
  1343. * 获取后台当前语言
  1344. */
  1345. function get_admin_lang()
  1346. {
  1347. $keys = \think\Config::get('global.admin_lang');
  1348. $admin_lang = \think\Cookie::get($keys);
  1349. if (empty($admin_lang)) {
  1350. $admin_lang = input('param.lang/s');
  1351. empty($admin_lang) && $admin_lang = get_main_lang();
  1352. \think\Cookie::set($keys, $admin_lang);
  1353. }
  1354. return $admin_lang;
  1355. }
  1356. }
  1357. if (!function_exists('get_home_lang'))
  1358. {
  1359. /**
  1360. * 获取前台当前语言
  1361. */
  1362. function get_home_lang()
  1363. {
  1364. $keys = \think\Config::get('global.home_lang');
  1365. $home_lang = \think\Cookie::get($keys);
  1366. if (empty($home_lang)) {
  1367. $home_lang = input('param.lang/s');
  1368. if (empty($home_lang)) {
  1369. $home_lang = \think\Db::name('language')->where([
  1370. 'is_home_default' => 1,
  1371. 'status' => 1,
  1372. ])->getField('mark');
  1373. }
  1374. \think\Cookie::set($keys, $home_lang);
  1375. }
  1376. return $home_lang;
  1377. }
  1378. }
  1379. if (!function_exists('is_language'))
  1380. {
  1381. /**
  1382. * 是否多语言
  1383. */
  1384. function is_language()
  1385. {
  1386. $module = \think\Request::instance()->module();
  1387. if (empty($module)) {
  1388. $system_langnum = tpCache('system.system_langnum');
  1389. } else {
  1390. $system_langnum = config('ey_config.system_langnum');
  1391. }
  1392. if (1 < intval($system_langnum)) {
  1393. return $system_langnum;
  1394. } else {
  1395. return false;
  1396. }
  1397. }
  1398. }
  1399. if (!function_exists('switch_language'))
  1400. {
  1401. /**
  1402. * 多语言切换(默认中文)
  1403. *
  1404. * @param string $lang 语言变量值
  1405. * @return void
  1406. */
  1407. function switch_language($lang = null)
  1408. {
  1409. static $language_db = null;
  1410. static $request = null;
  1411. if (null == $language_db) {
  1412. $language_db = \think\Db::name('language');
  1413. }
  1414. if (null == $request) {
  1415. $request = \think\Request::instance();
  1416. }
  1417. $is_admin = false;
  1418. if (!stristr($request->baseFile(), 'index.php')) {
  1419. $is_admin = true;
  1420. $langCookieVar = \think\Config::get('global.admin_lang');
  1421. } else {
  1422. $langCookieVar = \think\Config::get('global.home_lang');
  1423. }
  1424. \think\Lang::setLangCookieVar($langCookieVar);
  1425. /*单语言执行代码 - 排序不要乱改,影响很大*/
  1426. $langRow = \think\Db::name('language')->field('mark,is_home_default')
  1427. ->order('id asc')
  1428. ->select();
  1429. if (1 >= count($langRow)) {
  1430. $langRow = current($langRow);
  1431. $lang = $langRow['mark'];
  1432. \think\Config::set('cache.path', CACHE_PATH.$lang.DS);
  1433. \think\Cookie::set($langCookieVar, $lang);
  1434. return true;
  1435. }
  1436. /*--end*/
  1437. $current_lang = '';
  1438. /*兼容伪静态多语言切换*/
  1439. $pathinfo = $request->pathinfo();
  1440. if (!empty($pathinfo)) {
  1441. $s_arr = explode('/', $pathinfo);
  1442. if ('m' == $s_arr[0]) {
  1443. $s_arr[0] = $s_arr[1];
  1444. }
  1445. $count = $language_db->where(['mark'=>$s_arr[0]])->count();
  1446. if (!empty($count)) {
  1447. $current_lang = $s_arr[0];
  1448. }
  1449. }
  1450. /*--end*/
  1451. /*前后台默认语言*/
  1452. if (empty($current_lang)) {
  1453. if ($is_admin) {
  1454. $current_lang = !empty($langRow[0]['mark']) ? $langRow[0]['mark'] : 'cn';
  1455. } else {
  1456. foreach ($langRow as $key => $val) {
  1457. if (1 == $val['is_home_default']) {
  1458. $current_lang = $val['mark'];
  1459. break;
  1460. }
  1461. }
  1462. empty($current_lang) && $current_lang = !empty($langRow[0]['mark']) ? $langRow[0]['mark'] : 'cn';
  1463. }
  1464. }
  1465. /*end*/
  1466. $lang = $request->param('lang/s', $current_lang);
  1467. $lang = trim($lang, '/');
  1468. if (!empty($lang)) {
  1469. // 处理访问不存在的语言
  1470. $lang = $language_db->where('mark',$lang)->getField('mark');
  1471. }
  1472. if (empty($lang)) {
  1473. if ($is_admin) {
  1474. $lang = !empty($langRow[0]['mark']) ? $langRow[0]['mark'] : 'cn';
  1475. // $lang = \think\Db::name('language')->order('id asc')->getField('mark');
  1476. } else {
  1477. abort(404,'页面不存在');
  1478. foreach ($langRow as $key => $val) {
  1479. if (1 == $val['is_home_default']) {
  1480. $lang = $val['mark'];
  1481. break;
  1482. }
  1483. }
  1484. }
  1485. }
  1486. \think\Config::set('cache.path', CACHE_PATH.$lang.DS);
  1487. $pre_lang = \think\Cookie::get($langCookieVar);
  1488. \think\Cookie::set($langCookieVar, $lang);
  1489. if ($pre_lang != $lang) {
  1490. if ($is_admin) {
  1491. \think\Db::name('admin')->where('admin_id', \think\Session::get('admin_id'))->update([
  1492. 'mark_lang' => $lang,
  1493. 'update_time' => getTime(),
  1494. ]);
  1495. }
  1496. }
  1497. }
  1498. }
  1499. if (!function_exists('getUsersConfigData'))
  1500. {
  1501. // 专用于获取users_config,会员配置表数据处理。
  1502. // 参数1:必须传入,传入值不同,获取数据不同:
  1503. // 例:获取配置所有数据,传入:all,
  1504. // 获取分组所有数据,传入:分组标识,如:member,
  1505. // 获取分组中的单个数据,传入:分组标识.名称标识,如:users.users_open_register
  1506. // 参数2:data数据,为空则查询,否则为添加或修改。
  1507. // 参数3:多语言标识,为空则获取当前默认语言。
  1508. function getUsersConfigData($config_key,$data=array(),$lang='', $options = null){
  1509. $tableName = 'users_config';
  1510. $table_db = \think\Db::name($tableName);
  1511. $param = explode('.', $config_key);
  1512. $cache_inc_type = $tableName.$param[0];
  1513. $lang = !empty($lang) ? $lang : get_current_lang();
  1514. if (empty($options)) {
  1515. $options['path'] = CACHE_PATH.$lang.DS;
  1516. }
  1517. if(empty($data)){
  1518. //如$config_key=shop_info则获取网站信息数组
  1519. //如$config_key=shop_info.logo则获取网站logo字符串
  1520. $config = cache($cache_inc_type,'',$options);//直接获取缓存文件
  1521. if(empty($config)){
  1522. //缓存文件不存在就读取数据库
  1523. if ($param[0] == 'all') {
  1524. $param[0] = 'all';
  1525. $res = $table_db->where([
  1526. 'lang' => $lang,
  1527. ])->select();
  1528. } else {
  1529. $res = $table_db->where([
  1530. 'inc_type' => $param[0],
  1531. 'lang' => $lang,
  1532. ])->select();
  1533. }
  1534. if($res){
  1535. foreach($res as $k=>$val){
  1536. $config[$val['name']] = $val['value'];
  1537. }
  1538. cache($cache_inc_type,$config,$options);
  1539. }
  1540. }
  1541. if(!empty($param) && count($param)>1){
  1542. $newKey = strtolower($param[1]);
  1543. return isset($config[$newKey]) ? $config[$newKey] : '';
  1544. }else{
  1545. return $config;
  1546. }
  1547. }else{
  1548. //更新缓存
  1549. $result = $table_db->where([
  1550. 'inc_type' => $param[0],
  1551. 'lang' => $lang,
  1552. ])->select();
  1553. if($result){
  1554. foreach($result as $val){
  1555. $temp[$val['name']] = $val['value'];
  1556. }
  1557. $add_data = array();
  1558. foreach ($data as $k=>$v){
  1559. $newK = strtolower($k);
  1560. $newArr = array(
  1561. 'name'=>$newK,
  1562. 'value'=>trim($v),
  1563. 'inc_type'=>$param[0],
  1564. 'lang' => $lang,
  1565. 'update_time' => time(),
  1566. );
  1567. if(!isset($temp[$newK])){
  1568. array_push($add_data, $newArr); //新key数据插入数据库
  1569. }else{
  1570. if ($v != $temp[$newK]) {
  1571. $table_db->where([
  1572. 'name' => $newK,
  1573. 'lang' => $lang,
  1574. ])->save($newArr);//缓存key存在且值有变更新此项
  1575. }
  1576. }
  1577. }
  1578. if (!empty($add_data)) {
  1579. $table_db->insertAll($add_data);
  1580. }
  1581. //更新后的数据库记录
  1582. $newRes = $table_db->where([
  1583. 'inc_type' => $param[0],
  1584. 'lang' => $lang,
  1585. ])->select();
  1586. foreach ($newRes as $rs){
  1587. $newData[$rs['name']] = $rs['value'];
  1588. }
  1589. }else{
  1590. if ($param[0] != 'all') {
  1591. foreach($data as $k=>$v){
  1592. $newK = strtolower($k);
  1593. $newArr[] = array(
  1594. 'name'=>$newK,
  1595. 'value'=>trim($v),
  1596. 'inc_type'=>$param[0],
  1597. 'lang' => $lang,
  1598. 'update_time' => time(),
  1599. );
  1600. }
  1601. !empty($newArr) && $table_db->insertAll($newArr);
  1602. }
  1603. $newData = $data;
  1604. }
  1605. $result = false;
  1606. $res = $table_db->where([
  1607. 'lang' => $lang,
  1608. ])->select();
  1609. if($res){
  1610. $global = array();
  1611. foreach($res as $k=>$val){
  1612. $global[$val['name']] = $val['value'];
  1613. }
  1614. $result = cache($tableName.'all',$global,$options);
  1615. }
  1616. if ($param[0] != 'all') {
  1617. $result = cache($cache_inc_type,$newData,$options);
  1618. }
  1619. return $result;
  1620. }
  1621. }
  1622. }
  1623. if (!function_exists('send_email'))
  1624. {
  1625. /**
  1626. * 邮件发送
  1627. * @param $to 接收人
  1628. * @param string $subject 邮件标题
  1629. * @param string $content 邮件内容(html模板渲染后的内容)
  1630. * @param string $scene 使用场景
  1631. * @throws Exception
  1632. * @throws phpmailerException
  1633. */
  1634. function send_email($to='', $subject='', $data=array(), $scene=0, $smtp_config = []){
  1635. // 实例化类库,调用发送邮件
  1636. $emailLogic = new \app\common\logic\EmailLogic($smtp_config);
  1637. $res = $emailLogic->send_email($to, $subject, $data, $scene);
  1638. return $res;
  1639. }
  1640. }
  1641. /**
  1642. * 发送短信逻辑
  1643. * @param unknown $scene
  1644. */
  1645. function sendSms($scene, $sender, $params,$unique_id=0)
  1646. {
  1647. $smsLogic = new \app\common\logic\SmsLogic;
  1648. return $smsLogic->sendSms($scene, $sender, $params, $unique_id);
  1649. }
  1650. /**
  1651. * 获得全部省份列表
  1652. */
  1653. function get_province_list()
  1654. {
  1655. $result = extra_cache('global_get_province_list');
  1656. if ($result == false) {
  1657. $result = M('region')->field('id, name')
  1658. ->where('level',1)
  1659. ->getAllWithIndex('id');
  1660. extra_cache('global_get_province_list', $result);
  1661. }
  1662. return $result;
  1663. }
  1664. /**
  1665. * 获得全部城市列表
  1666. */
  1667. function get_city_list()
  1668. {
  1669. $result = extra_cache('global_get_city_list');
  1670. if ($result == false) {
  1671. $result = M('region')->field('id, name')
  1672. ->where('level',2)
  1673. ->getAllWithIndex('id');
  1674. extra_cache('global_get_city_list', $result);
  1675. }
  1676. return $result;
  1677. }
  1678. /**
  1679. * 获得全部地区列表
  1680. */
  1681. function get_area_list()
  1682. {
  1683. $result = extra_cache('global_get_area_list');
  1684. if ($result == false) {
  1685. $result = M('region')->field('id, name')
  1686. ->where('level',3)
  1687. ->getAllWithIndex('id');
  1688. extra_cache('global_get_area_list', $result);
  1689. }
  1690. return $result;
  1691. }
  1692. /**
  1693. * 根据地区ID获得省份名称
  1694. */
  1695. function get_province_name($id)
  1696. {
  1697. $result = get_province_list();
  1698. return empty($result[$id]) ? '银河系' : $result[$id]['name'];
  1699. }
  1700. /**
  1701. * 根据地区ID获得城市名称
  1702. */
  1703. function get_city_name($id)
  1704. {
  1705. $result = get_city_list();
  1706. return empty($result[$id]) ? '火星' : $result[$id]['name'];
  1707. }
  1708. /**
  1709. * 根据地区ID获得县区名称
  1710. */
  1711. function get_area_name($id)
  1712. {
  1713. $result = get_area_list();
  1714. return empty($result[$id]) ? '部落' : $result[$id]['name'];
  1715. }
  1716. if (!function_exists('AddOrderAction'))
  1717. {
  1718. /**
  1719. * 添加订单操作表数据
  1720. * 参数说明:
  1721. * $OrderId 订单ID或订单ID数组
  1722. * $UsersId 会员ID,若不为0,则ActionUsers为0
  1723. * $ActionUsers 操作员ID,为0,表示会员操作,反之则为管理员ID
  1724. * $OrderStatus 操作时,订单当前状态
  1725. * $ExpressStatus 操作时,订单当前物流状态
  1726. * $PayStatus 操作时,订单当前付款状态
  1727. * $ActionDesc 操作描述
  1728. * $ActionNote 操作备注
  1729. * 返回说明:
  1730. * return 无需返回
  1731. */
  1732. function AddOrderAction($OrderId,$UsersId,$ActionUsers='0',$OrderStatus='0',$ExpressStatus='0',$PayStatus='0',$ActionDesc='提交订单!',$ActionNote='会员提交订单成功!')
  1733. {
  1734. if (is_array($OrderId) && '4' == $OrderStatus) {
  1735. // OrderId为数组并且订单状态为过期,则执行
  1736. foreach ($OrderId as $key => $value) {
  1737. $ActionData[] = [
  1738. 'order_id' => $value['order_id'],
  1739. 'users_id' => $UsersId,
  1740. 'action_user' => $ActionUsers,
  1741. 'order_status' => $OrderStatus,
  1742. 'express_status' => $ExpressStatus,
  1743. 'pay_status' => $PayStatus,
  1744. 'action_desc' => $ActionDesc,
  1745. 'action_note' => $ActionNote,
  1746. 'lang' => get_home_lang(),
  1747. 'add_time' => getTime(),
  1748. ];
  1749. }
  1750. // 批量添加
  1751. M('shop_order_log')->insertAll($ActionData);
  1752. }else{
  1753. // OrderId不为数组,则执行
  1754. $ActionData = [
  1755. 'order_id' => $OrderId,
  1756. 'users_id' => $UsersId,
  1757. 'action_user' => $ActionUsers,
  1758. 'order_status' => $OrderStatus,
  1759. 'express_status' => $ExpressStatus,
  1760. 'pay_status' => $PayStatus,
  1761. 'action_desc' => $ActionDesc,
  1762. 'action_note' => $ActionNote,
  1763. 'lang' => get_home_lang(),
  1764. 'add_time' => getTime(),
  1765. ];
  1766. // 单条添加
  1767. M('shop_order_log')->add($ActionData);
  1768. }
  1769. }
  1770. }
  1771. if (!function_exists('GetEamilSendData'))
  1772. {
  1773. /**
  1774. * 获取邮箱发送数据
  1775. * 参数说明:
  1776. * $SmtpConfig 后台设置的邮箱配置信息
  1777. * $users 会员数据
  1778. * $OrderData 订单信息
  1779. * $type 订单操作
  1780. * $pay_method 支付方式
  1781. * 返回说明:
  1782. * return 邮箱发送所需参数
  1783. */
  1784. function GetEamilSendData($SmtpConfig = [], $users = [], $OrderData = [], $type = 1, $pay_method = null)
  1785. {
  1786. if (empty($SmtpConfig) || empty($users) || empty($OrderData)) return false;
  1787. if (1 == $type) {
  1788. if (isset($SmtpConfig['smtp_shop_order_pay']) && 0 == $SmtpConfig['smtp_shop_order_pay']) return false;
  1789. } else if (2 == $type) {
  1790. if (isset($SmtpConfig['smtp_shop_order_send']) && 0 == $SmtpConfig['smtp_shop_order_send']) return false;
  1791. }
  1792. if (in_array($type, [1])) {
  1793. $email = !empty($SmtpConfig['smtp_from_eamil']) ? $SmtpConfig['smtp_from_eamil'] : null;
  1794. } else if (in_array($type, [2])) {
  1795. $email = !empty($users['email']) ? $users['email'] : null;
  1796. }
  1797. if (empty($email)) return false;
  1798. if (!empty($SmtpConfig['smtp_server']) && !empty($SmtpConfig['smtp_user']) && !empty($SmtpConfig['smtp_pwd'])) {
  1799. $Result = [];
  1800. switch ($type) {
  1801. case '1':
  1802. $title = '订单支付';
  1803. break;
  1804. case '2':
  1805. $title = '订单发货';
  1806. break;
  1807. }
  1808. $Result = [
  1809. 'url' => ROOT_DIR . '/index.php?m=user&c=Smtpmail&a=send_email&_ajax=1',
  1810. 'data' => [
  1811. 'email' => $email,
  1812. 'title' => $title,
  1813. 'type' => 'order_msg',
  1814. 'scene' => 5,
  1815. 'data' => [
  1816. 'type' => $type,
  1817. 'nickname' => !empty($users['nickname']) ? $users['nickname'] : $users['username'],
  1818. 'pay_method' => $pay_method,
  1819. 'order_id' => !empty($OrderData['order_id']) ? $OrderData['order_id'] : '',
  1820. 'order_code' => !empty($OrderData['order_code']) ? $OrderData['order_code'] : '',
  1821. 'service_id' => !empty($OrderData['service_id']) ? $OrderData['service_id'] : ''
  1822. ],
  1823. ]
  1824. ];
  1825. return $Result;
  1826. }
  1827. return false;
  1828. }
  1829. }
  1830. if (!function_exists('GetMobileSendData'))
  1831. {
  1832. /**
  1833. * 获取手机发送数据
  1834. * 参数说明:
  1835. * $SmtpConfig 后台设置的短信配置信息
  1836. * $users 会员数据
  1837. * $OrderData 订单信息
  1838. * $type 订单操作
  1839. * $pay_method 支付方式
  1840. * 返回说明:
  1841. * return 手机短信发送所需参数
  1842. */
  1843. function GetMobileSendData($SmsConfig = [], $users = [], $OrderData = [], $type = 1, $pay_method = null)
  1844. {
  1845. if (empty($SmsConfig) || empty($users) || empty($OrderData)) return false;
  1846. if (1 == $type) {
  1847. if (isset($SmsConfig['sms_shop_order_pay']) && 0 == $SmsConfig['sms_shop_order_pay']) return false;
  1848. } else if (2 == $type) {
  1849. if (isset($SmsConfig['sms_shop_order_send']) && 0 == $SmsConfig['sms_shop_order_send']) return false;
  1850. } else {
  1851. return false;
  1852. }
  1853. if (in_array($type, [1])) {
  1854. $mobile = $SmsConfig['sms_test_mobile'];
  1855. } else if (in_array($type, [2])) {
  1856. $mobile = $users['mobile'];
  1857. } else {
  1858. return false;
  1859. }
  1860. if (empty($mobile)) return false;
  1861. if (!empty($SmsConfig['sms_appkey']) && !empty($SmsConfig['sms_secretkey'])) {
  1862. $Result = [];
  1863. switch ($type) {
  1864. case '1':
  1865. $title = '订单支付';
  1866. break;
  1867. case '2':
  1868. $title = '订单发货';
  1869. break;
  1870. }
  1871. $Result = [
  1872. 'url' => ROOT_DIR . '/index.php?m=api&c=Ajax&a=SendMobileCode&_ajax=1',
  1873. 'data' => [
  1874. 'mobile' => $mobile,
  1875. 'scene' => 5,
  1876. 'title' => $title,
  1877. 'type' => 'order_msg',
  1878. 'data' => [
  1879. 'type' => $type,
  1880. 'nickname' => !empty($users['nickname']) ? $users['nickname'] : $users['username'],
  1881. 'pay_method' => $pay_method,
  1882. 'order_code' => !empty($OrderData['order_code']) ? $OrderData['order_code'] : '',
  1883. ],
  1884. ]
  1885. ];
  1886. return $Result;
  1887. }
  1888. return false;
  1889. }
  1890. }
  1891. if (!function_exists('download_file'))
  1892. {
  1893. /**
  1894. * 下载文件
  1895. * @param $down_path 文件路径
  1896. * @param $file_mime 文件类型
  1897. */
  1898. function download_file($down_path = '', $file_mime = '')
  1899. {
  1900. $down_path = iconv("utf-8","gb2312//IGNORE",$down_path);
  1901. /*支持子目录*/
  1902. $down_path = preg_replace('#^(/[/\w]+)?(/public/upload/soft/|/uploads/soft/)#i', '$2', $down_path);
  1903. /*--end*/
  1904. //文件名
  1905. $filename = explode('/', $down_path);
  1906. $filename = end($filename);
  1907. //以只读和二进制模式打开文件
  1908. $file = fopen('.'.$down_path, "rb");
  1909. //文件大小
  1910. $file_size = filesize('.'.$down_path);
  1911. //告诉浏览器这是一个文件流格式的文件
  1912. header("Content-type: ".$file_mime);
  1913. //请求范围的度量单位
  1914. Header("Accept-Ranges: bytes");
  1915. //Content-Length是指定包含于请求或响应中数据的字节长度
  1916. Header("Accept-Length: " . $file_size);
  1917. //用来告诉浏览器,文件是可以当做附件被下载,下载后的文件名称为$filename该变量的值。
  1918. Header("Content-Disposition: attachment; filename=" . $filename);
  1919. //读取文件内容并直接输出到浏览器
  1920. echo fread($file, $file_size);
  1921. fclose($file);
  1922. exit();
  1923. }
  1924. }
  1925. if (!function_exists('is_realdomain'))
  1926. {
  1927. /**
  1928. * 简单判断当前访问的域名是否真实
  1929. * @param string $domain 不带协议的域名
  1930. * @return boolean
  1931. */
  1932. function is_realdomain($domain = '')
  1933. {
  1934. $is_real = false;
  1935. $domain = !empty($domain) ? $domain : request()->host();
  1936. if (!preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i', $domain) && 'localhost' != $domain && '127.0.0.1' != serverIP()) {
  1937. $is_real = true;
  1938. }
  1939. return $is_real;
  1940. }
  1941. }
  1942. if (!function_exists('img_style_wh'))
  1943. {
  1944. /**
  1945. * 追加指定内嵌样式到编辑器内容的img标签,兼容图片自动适应页面
  1946. */
  1947. function img_style_wh($content = '', $title = '')
  1948. {
  1949. if (!empty($content)) {
  1950. // 是否开启图片大小自适应
  1951. $basic_img_style_wh = tpCache('basic.basic_img_style_wh');
  1952. if (empty($basic_img_style_wh)) {
  1953. return $content;
  1954. }
  1955. preg_match_all('/<img.*(\/)?>/iUs', $content, $imginfo);
  1956. $imginfo = !empty($imginfo[0]) ? $imginfo[0] : [];
  1957. if (!empty($imginfo)) {
  1958. $num = 1;
  1959. $appendStyle = "max-width:100%!important;height:auto!important;";
  1960. $title = preg_replace('/("|\')/i', '', $title);
  1961. foreach ($imginfo as $key => $imgstr) {
  1962. $imgstrNew = $imgstr;
  1963. /* 兼容已存在的多重追加样式,处理去重 */
  1964. if (stristr($imgstrNew, $appendStyle.$appendStyle)) {
  1965. $imgstrNew = preg_replace('/'.$appendStyle.$appendStyle.'/i', '', $imgstrNew);
  1966. }
  1967. if (stristr($imgstrNew, $appendStyle)) {
  1968. $content = str_ireplace($imgstr, $imgstrNew, $content);
  1969. $num++;
  1970. continue;
  1971. }
  1972. /* end */
  1973. // 追加style属性
  1974. $imgstrNew = preg_replace('/style(\s*)=(\s*)[\'|\"](.*?)[\'|\"]/i', 'style="'.$appendStyle.'${3}"', $imgstrNew);
  1975. if (!preg_match('/<img(.*?)style(\s*)=(\s*)[\'|\"](.*?)[\'|\"](.*?)[\/]?(\s*)>/i', $imgstrNew)) {
  1976. // 新增style属性
  1977. $imgstrNew = str_ireplace('<img', "<img style=\"".$appendStyle."\" ", $imgstrNew);
  1978. }
  1979. // 移除img中多余的title属性
  1980. // $imgstrNew = preg_replace('/title(\s*)=(\s*)[\'|\"]([\w\.]*?)[\'|\"]/i', '', $imgstrNew);
  1981. // 追加alt属性
  1982. $altNew = $title."(图{$num})";
  1983. $imgstrNew = preg_replace('/alt(\s*)=(\s*)[\'|\"]([\w\.]*?)[\'|\"]/i', 'alt="'.$altNew.'"', $imgstrNew);
  1984. if (!preg_match('/<img(.*?)alt(\s*)=(\s*)[\'|\"](.*?)[\'|\"](.*?)[\/]?(\s*)>/i', $imgstrNew)) {
  1985. // 新增alt属性
  1986. $imgstrNew = str_ireplace('<img', "<img alt=\"{$altNew}\" ", $imgstrNew);
  1987. }
  1988. // 追加title属性
  1989. $titleNew = $title."(图{$num})";
  1990. $imgstrNew = preg_replace('/title(\s*)=(\s*)[\'|\"]([\w\.]*?)[\'|\"]/i', 'title="'.$titleNew.'"', $imgstrNew);
  1991. if (!preg_match('/<img(.*?)title(\s*)=(\s*)[\'|\"](.*?)[\'|\"](.*?)[\/]?(\s*)>/i', $imgstrNew)) {
  1992. // 新增alt属性
  1993. $imgstrNew = str_ireplace('<img', "<img alt=\"{$titleNew}\" ", $imgstrNew);
  1994. }
  1995. // 新的img替换旧的img
  1996. $content = str_ireplace($imgstr, $imgstrNew, $content);
  1997. $num++;
  1998. }
  1999. }
  2000. }
  2001. return $content;
  2002. }
  2003. }
  2004. if (!function_exists('get_archives_data'))
  2005. {
  2006. /**
  2007. * 查询文档主表信息和文档栏目表信息整合到一个数组中
  2008. * @param string $array 产品数组信息
  2009. * @param string $id 产品ID,购物车下单页传入aid,订单列表订单详情页传入product_id
  2010. * @return return array_new
  2011. */
  2012. function get_archives_data($array,$id)
  2013. {
  2014. // 目前定义订单中心和评论中使用
  2015. if (empty($array) || empty($id)) {
  2016. return false;
  2017. }
  2018. $array_new = array();
  2019. $aids = get_arr_column($array, $id);
  2020. $archivesList = \think\Db::name('archives')->field('*')->where('aid','IN',$aids)->getAllWithIndex('aid');
  2021. $typeids = get_arr_column($archivesList, 'typeid');
  2022. $arctypeList = \think\Db::name('arctype')->field('*')->where('id','IN',$typeids)->getAllWithIndex('id');
  2023. foreach ($archivesList as $key2 => $val2) {
  2024. $array_new[$key2] = array_merge($arctypeList[$val2['typeid']],$val2);
  2025. }
  2026. return $array_new;
  2027. }
  2028. }
  2029. if (!function_exists('SynchronizeQiniu'))
  2030. {
  2031. /**
  2032. * 参数说明:
  2033. * $images 本地图片地址
  2034. * $Qiniuyun 七牛云插件配置信息
  2035. * $is_tcp 是否携带协议
  2036. * 返回说明:
  2037. * return false 没有配置齐全
  2038. * return true 同步成功
  2039. */
  2040. function SynchronizeQiniu($images,$Qiniuyun=null,$is_tcp=false)
  2041. {
  2042. static $Qiniuyun = null;
  2043. // 若没有传入配信信息则读取数据库
  2044. if (null == $Qiniuyun) {
  2045. // 需要填写你的 Access Key 和 Secret Key
  2046. $data = M('weapp')->where('code','Qiniuyun')->field('data')->find();
  2047. $Qiniuyun = json_decode($data['data'], true);
  2048. }
  2049. // 配置为空则返回原图片路径
  2050. if (empty($Qiniuyun)) {
  2051. return $images;
  2052. }
  2053. //引入七牛云的相关文件
  2054. weapp_vendor('Qiniu.src.Qiniu.Auth', 'Qiniuyun');
  2055. weapp_vendor('Qiniu.src.Qiniu.Storage.UploadManager', 'Qiniuyun');
  2056. require_once ROOT_PATH.'weapp/Qiniuyun/vendor/Qiniu/autoload.php';
  2057. // 配置信息
  2058. $accessKey = $Qiniuyun['access_key'];
  2059. $secretKey = $Qiniuyun['secret_key'];
  2060. $bucket = $Qiniuyun['bucket'];
  2061. $domain = $Qiniuyun['domain'];
  2062. // 图片处理,去除图片途径中的第一个斜杠
  2063. $images = ltrim($images, '/');
  2064. // 构建鉴权对象
  2065. $auth = new Qiniu\Auth($accessKey, $secretKey);
  2066. // 生成上传 Token
  2067. $token = $auth->uploadToken($bucket);
  2068. // 要上传文件的本地路径
  2069. $filePath = ROOT_PATH.$images;
  2070. // 上传到七牛后保存的文件名
  2071. $key = $images;
  2072. // 初始化 UploadManager 对象并进行文件的上传。
  2073. $uploadMgr = new Qiniu\Storage\UploadManager;
  2074. // 调用 UploadManager 的 putFile 方法进行文件的上传。
  2075. list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
  2076. // list($ret, $err) = $uploadMgr->put($token, $key, $filePath);
  2077. if (empty($err) || $err === null) {
  2078. $tcp = '//';
  2079. if ($is_tcp) {
  2080. $tcp = !empty($Qiniuyun['tcp']) ? $Qiniuyun['tcp'] : '';
  2081. switch ($tcp) {
  2082. case '2':
  2083. $tcp = 'https://';
  2084. break;
  2085. case '3':
  2086. $tcp = '//';
  2087. break;
  2088. case '1':
  2089. default:
  2090. $tcp = 'http://';
  2091. break;
  2092. }
  2093. }
  2094. return $tcp.$domain.'/'.$images;
  2095. }
  2096. return $images;
  2097. }
  2098. }
  2099. // if (!function_exists('SynchronizeOSS'))
  2100. // {
  2101. // /**
  2102. // * 参数说明:
  2103. // * $images 本地图片地址
  2104. // * $OssCo OSS配置信息
  2105. // * 返回说明:
  2106. // * return false 没有配置齐全
  2107. // * return true 同步成功
  2108. // */
  2109. // function SynchronizeOSS($ossConfig = [], $images = null, $file = [])
  2110. // {
  2111. // static $ossConfig = null;
  2112. // // 若没有传入配信信息则读取数据库
  2113. // if (null == $ossConfig) $ossConfig = tpCache('oss');
  2114. // // 配置为空则返回原图片路径
  2115. // if (empty($ossConfig)) {
  2116. // $result = [
  2117. // 'url' => ROOT_DIR . $images,
  2118. // 'state' => 'SUCCESS',
  2119. // ];
  2120. // return $result;
  2121. // }
  2122. // // 上传OSS
  2123. // $ossClient = new \app\common\logic\OssLogic;
  2124. // $url = $ossClient->uploadFile($file->getRealPath(), $images);
  2125. // $state = "SUCCESS";
  2126. // if (empty($url)) {
  2127. // $url = '';
  2128. // $state = "ERROR" . $ossClient->getError();
  2129. // }
  2130. // // 删除图片源链接
  2131. // @unlink($file->getRealPath());
  2132. // // 返回数据
  2133. // $result = [
  2134. // 'url' => $url,
  2135. // 'state' => $state,
  2136. // ];
  2137. // return $result;
  2138. // }
  2139. // }
  2140. if (!function_exists('getAllChild'))
  2141. {
  2142. /**
  2143. * 递归查询所有的子类
  2144. * @param array $arctype_child_all 存放所有的子栏目
  2145. * @param int $id 栏目ID 或 父栏目ID
  2146. * @param int $type 1=栏目,2=文章
  2147. */
  2148. function getAllChild(&$arctype_child_all,$id,$type = 1){
  2149. if($type == 1){
  2150. $arctype_child = \think\Db::name('arctype')->where(['is_del'=>0,'status'=>1,'parent_id'=>$id])->getfield('id',true);
  2151. }else{
  2152. $where['is_del'] = 0;
  2153. $where['status'] = 1;
  2154. $where['parent_id'] = $id;
  2155. $where['current_channel'] = array(array('neq',6),array('neq',8));
  2156. $arctype_child = \think\Db::name('arctype')->where($where)->getfield('id',true);
  2157. }
  2158. if(!empty($arctype_child)){
  2159. $arctype_child_all = array_merge($arctype_child_all,$arctype_child);
  2160. for($i=0;$i<count($arctype_child);$i++){
  2161. getAllChild($arctype_child_all,$arctype_child[$i],$type);
  2162. }
  2163. }
  2164. }
  2165. }
  2166. if (!function_exists('getAllChildByList'))
  2167. {
  2168. /**
  2169. * 生成栏目页面时获取同模型下级
  2170. * @param array $arctype_child_all 存放所有的子栏目
  2171. * @param int $id 栏目ID 或 父栏目ID
  2172. * @param int $current_channel 当前栏目的模型ID
  2173. */
  2174. function getAllChildByList(&$arctype_child_all,$id,$current_channel){
  2175. $arctype_child = \think\Db::name('arctype')->where(['is_del'=>0,'status'=>1,'parent_id'=>$id,'current_channel'=>$current_channel])->getfield('id',true);
  2176. if(!empty($arctype_child)){
  2177. $arctype_child_all = array_merge($arctype_child_all,$arctype_child);
  2178. for($i=0;$i<count($arctype_child);$i++){
  2179. getAllChild($arctype_child_all,$arctype_child[$i]);
  2180. }
  2181. }
  2182. }
  2183. }
  2184. if (!function_exists('getAllChildArctype'))
  2185. {
  2186. //递归查询所有的子类
  2187. function getAllChildArctype(&$arctype_child_all,$id){
  2188. $where['a.is_del'] = 0;
  2189. $where['a.status'] = 1;
  2190. $where['a.parent_id'] = $id;
  2191. $arctype_child = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  2192. ->alias('a')
  2193. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  2194. ->where($where)
  2195. ->select();
  2196. if(!empty($arctype_child)){
  2197. $arctype_child_all = array_merge($arctype_child,$arctype_child_all);
  2198. for($i=0;$i<count($arctype_child);$i++){
  2199. getAllChildArctype($arctype_child_all,$arctype_child[$i]['typeid']);
  2200. }
  2201. }
  2202. }
  2203. }
  2204. if (!function_exists('getAllArctype'))
  2205. {
  2206. /*
  2207. * 递归查询所有栏目
  2208. * $home_lang 语言
  2209. * $id 栏目id 存在则获取指定的栏目,不存在获取全部
  2210. * $parent 是否获取下级栏目 true:获取,false:不获取
  2211. * $aid
  2212. */
  2213. function getAllArctype($home_lang,$id,$view_suffix,$parent = true,$aid = 0){
  2214. $map = [];
  2215. if (!empty($id)){
  2216. $map['a.id'] = $id;
  2217. }
  2218. $map['a.lang'] = $home_lang;
  2219. $map['a.is_del'] = 0;
  2220. $map['a.status'] = 1;
  2221. $info = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  2222. ->alias('a')
  2223. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  2224. ->where($map)
  2225. ->order("a.id desc")
  2226. ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  2227. ->select();
  2228. if (!empty($id) && $parent && $aid == 0){ // $aid > 0 表示栏目生成不生成子栏目
  2229. getAllChildArctype($info,$id);
  2230. }
  2231. $info = getAllArctypeCount($home_lang,$info,$id,$view_suffix,$aid);
  2232. return $info;
  2233. }
  2234. }
  2235. if (!function_exists('getAllArctypeCount'))
  2236. {
  2237. /*
  2238. * 获取所有栏目数据条数
  2239. * 获取需要生成的栏目页的静态文件的个数 缓存到channel_page_total
  2240. */
  2241. function getAllArctypeCount($home_lang,$info,$id = 0,$view_suffix = ".htm",$aid = 0){
  2242. $pagetotal = 0;
  2243. if ($id){
  2244. $map_arc['typeid'] = array('in',get_arr_column($info,'typeid'));
  2245. }
  2246. $map_arc['is_del'] = 0;
  2247. $map_arc['status'] = 1;
  2248. $map_arc['lang'] = $home_lang;
  2249. $info = convert_arr_key($info,'typeid');
  2250. $count_type = \think\Db::name('archives')->field("count(*) as count,typeid")->where($map_arc)->group("typeid")->select();
  2251. $count_type = convert_arr_key($count_type,'typeid');
  2252. foreach($info as $k=>$v){
  2253. if (!isset($info[$k]['count'])){ //判断当前栏目的count是否已经存在
  2254. $info[$k]['count'] = 0;
  2255. }
  2256. if (isset($count_type[$v['typeid']])){ //存在当前栏目个数
  2257. $info[$k]['count'] += $count_type[$v['typeid']]['count'];
  2258. }
  2259. if ($v['parent_id'] && $v['current_channel'] != 6 && $v['current_channel'] != 8 && isset($info[$v['parent_id']]) && $v['current_channel'] == $info[$v['parent_id']]['current_channel']){ //判断是否存在上级目录
  2260. if (isset($info[$v['parent_id']]['count'])){
  2261. $info[$v['parent_id']]['count'] += $info[$k]['count'];
  2262. }else{
  2263. $info[$v['parent_id']]['count'] = $info[$k]['count'];
  2264. }
  2265. }
  2266. if ($v['current_channel'] == 6 || $v['current_channel'] == 8){
  2267. $info[$k]['pagesize'] = 1;
  2268. $pagetotal += $info[$k]['pagetotal'] = 1;
  2269. }else{
  2270. $tpl = !empty($v['templist']) ? str_replace('.'.$view_suffix, '',$v['templist']) : 'lists_'. $v['nid'];
  2271. $template_html = "./template/pc/".$tpl.".htm";
  2272. $content = file_get_contents($template_html);
  2273. if($content){
  2274. preg_match_all('/\{eyou:list(.*)pagesize=[\'\"](\d+)[\'\"](.*)\}/',$content,$rese);
  2275. $pagesize = !empty($rese[2][0]) ? $rese[2][0] : 10;
  2276. if ($aid){
  2277. preg_match_all('/\{eyou:list(.*)orderby=[\'\"](.*)[\'\"](.*)\}/',$content,$reseby);
  2278. $orderby = !empty($reseby[2][0]) ? $reseby[2][0] : "";
  2279. preg_match_all('/\{eyou:list(.*)orderWay=[\'\"](.*)[\'\"](.*)\}/',$content,$reseway);
  2280. $orderway = !empty($reseway[2][0]) ? $reseway[2][0] : "desc";
  2281. }
  2282. }
  2283. $info[$k]['pagesize'] = $pagesize = !empty($pagesize)?$pagesize:10;
  2284. $pagetotal += $info[$k]['pagetotal'] = !empty($info[$k]['count']) ? ceil($info[$k]['count']/$pagesize):1;
  2285. }
  2286. $info[$k]['orderby'] = !empty($orderby)?$orderby:"";
  2287. $info[$k]['orderway'] = !empty($orderway)?$orderway:"desc";
  2288. }
  2289. $info = array_merge($info);
  2290. return ["info"=>$info,"pagetotal"=>$pagetotal];
  2291. }
  2292. }
  2293. if (!function_exists('getAllArchives'))
  2294. {
  2295. //递归查询所有栏目
  2296. function getAllArchives($home_lang,$id,$aid = 0){
  2297. $map = [];
  2298. if(!empty($aid)){
  2299. $map['a.aid'] = $aid;
  2300. }else if (!empty($id)){
  2301. $id_arr = [$id];
  2302. getAllChild($id_arr,$id,2);
  2303. $map['a.typeid'] = ['in',$id_arr];
  2304. }
  2305. $allow_release_channel = config('global.allow_release_channel');
  2306. $map['a.channel'] = ['IN', $allow_release_channel];
  2307. $map['a.lang'] = $home_lang;
  2308. $map['a.is_jump'] = 0;
  2309. $map['a.is_del'] = 0;
  2310. $map['a.status'] = 1;
  2311. $info = \think\Db::name('archives')->field('a.*')
  2312. ->alias('a')
  2313. ->where($map)
  2314. ->select();
  2315. $typeids = get_arr_column($info, 'typeid');
  2316. $info = getAllContent($info);
  2317. /*栏目信息*/
  2318. $arctypeRow = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  2319. ->alias('a')
  2320. ->where(['a.lang'=>$home_lang])
  2321. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  2322. ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  2323. ->getAllWithIndex('typeid');
  2324. return [
  2325. 'info' => $info,
  2326. 'arctypeRow' => $arctypeRow,
  2327. ];
  2328. }
  2329. }
  2330. if (!function_exists('getPreviousArchives'))
  2331. {
  2332. //获取上一条文章数据
  2333. function getPreviousArchives($home_lang,$id,$aid = 0){
  2334. $map = [];
  2335. if(!empty($aid)){
  2336. $map['a.aid'] = ['lt',$aid];
  2337. }
  2338. if (!empty($id)){
  2339. $id_arr = [$id];
  2340. getAllChild($id_arr,$id,2);
  2341. $map['a.typeid'] = ['in',$id_arr];
  2342. }
  2343. $allow_release_channel = config('global.allow_release_channel');
  2344. $map['a.channel'] = ['IN', $allow_release_channel];
  2345. $map['a.lang'] = $home_lang;
  2346. $map['a.is_jump'] = 0;
  2347. $map['a.is_del'] = 0;
  2348. $map['a.status'] = 1;
  2349. $info = \think\Db::name('archives')->field('a.*')
  2350. ->alias('a')
  2351. ->where($map)
  2352. ->order("a.aid desc")
  2353. ->limit(1)
  2354. ->select();
  2355. $typeids = get_arr_column($info, 'typeid');
  2356. $info = getAllContent($info);
  2357. /*栏目信息*/
  2358. $arctypeRow = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  2359. ->alias('a')
  2360. ->where(['a.lang'=>$home_lang])
  2361. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  2362. ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  2363. ->getAllWithIndex('typeid');
  2364. return [
  2365. 'info' => $info,
  2366. 'arctypeRow' => $arctypeRow,
  2367. ];
  2368. }
  2369. }
  2370. if (!function_exists('getNextArchives'))
  2371. {
  2372. //获取下一条文章数据
  2373. function getNextArchives($home_lang,$id,$aid = 0){
  2374. $map = [];
  2375. if(!empty($aid)){
  2376. $map['a.aid'] = ['gt',$aid];
  2377. }
  2378. if (!empty($id)){
  2379. $id_arr = [$id];
  2380. getAllChild($id_arr,$id,2);
  2381. $map['a.typeid'] = ['in',$id_arr];
  2382. }
  2383. $allow_release_channel = config('global.allow_release_channel');
  2384. $map['a.channel'] = ['IN', $allow_release_channel];
  2385. $map['a.lang'] = $home_lang;
  2386. $map['a.is_jump'] = 0;
  2387. $map['a.is_del'] = 0;
  2388. $map['a.status'] = 1;
  2389. $info = \think\Db::name('archives')->field('a.*')
  2390. ->alias('a')
  2391. ->where($map)
  2392. ->order("a.aid asc")
  2393. ->limit(1)
  2394. ->select();
  2395. $typeids = get_arr_column($info, 'typeid');
  2396. $info = getAllContent($info);
  2397. /*栏目信息*/
  2398. $arctypeRow = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  2399. ->alias('a')
  2400. ->where(['a.lang'=>$home_lang])
  2401. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  2402. ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  2403. ->getAllWithIndex('typeid');
  2404. return [
  2405. 'info' => $info,
  2406. 'arctypeRow' => $arctypeRow,
  2407. ];
  2408. }
  2409. }
  2410. if (!function_exists('getAllContent'))
  2411. {
  2412. //获取指定文档列表的内容附加表字段值
  2413. function getAllContent($archivesList = []){
  2414. $contentList = [];
  2415. $db = new \think\Db;
  2416. $channeltype_list = config('global.channeltype_list');
  2417. $arr = group_same_key($archivesList, 'channel');
  2418. foreach ($arr as $nid => $list) {
  2419. $table = array_search($nid, $channeltype_list);
  2420. if (!empty($table)) {
  2421. $aids = get_arr_column($list, 'aid');
  2422. $row = $db::name($table.'_content')->field('*')
  2423. ->where(['aid'=>['IN', $aids]])
  2424. ->select();
  2425. $result = [];
  2426. foreach ($row as $_k => $_v) {
  2427. unset($_v['id']);
  2428. unset($_v['add_time']);
  2429. unset($_v['update_time']);
  2430. $result[$_v['aid']] = $_v;
  2431. }
  2432. $contentList += $result;
  2433. }
  2434. }
  2435. $firstFieldData = current($contentList);
  2436. foreach ($archivesList as $key => $val) {
  2437. /*文档所属模型是不存在,或已被禁用*/
  2438. $table = array_search($val['channel'], $channeltype_list);
  2439. if (empty($table)) {
  2440. unset($archivesList[$key]);
  2441. continue;
  2442. }
  2443. /*end*/
  2444. /*文档内容表没有记录的特殊情况*/
  2445. if (!isset($contentList[$val['aid']])) {
  2446. $contentList[$val['aid']] = [];
  2447. foreach ($firstFieldData as $k2 => $v2) {
  2448. if (in_array($k2, ['aid'])) {
  2449. $contentList[$val['aid']][$k2] = $val[$k2];
  2450. } else {
  2451. $contentList[$val['aid']][$k2] = '';
  2452. }
  2453. }
  2454. }
  2455. /*end*/
  2456. $val = array_merge($val, $contentList[$val['aid']]);
  2457. $archivesList[$key] = $val;
  2458. }
  2459. return $archivesList;
  2460. }
  2461. }
  2462. if (!function_exists('getAllTags'))
  2463. {
  2464. //递归查询所有栏目内容
  2465. function getAllTags($aid_arr){
  2466. $map = [];
  2467. $info = [];
  2468. $map['aid'] = ['in',$aid_arr];
  2469. $result = \think\Db::name('taglist')->field("aid,tag")->where($map)->select();
  2470. if ($result) {
  2471. foreach ($result as $key => $val) {
  2472. if (!isset($info[$val['aid']])) $info[$val['aid']] = array();
  2473. array_push($info[$val['aid']], $val['tag']);
  2474. }
  2475. }
  2476. return $info;
  2477. }
  2478. }
  2479. if (!function_exists('getAllAttrInfo'))
  2480. {
  2481. //递归查询所有栏目内容
  2482. function getAllAttrInfo($aid_arr){
  2483. $info = [];
  2484. $info['product_img'] = model('ProductImg')->getProImg($aid_arr);
  2485. $info['product_attr'] = model('ProductAttr')->getProAttr($aid_arr);
  2486. $info['images_upload'] = model('ImagesUpload')->getImgUpload($aid_arr);
  2487. $info['download_file'] = model('DownloadFile')->getDownFile($aid_arr);
  2488. return $info;
  2489. }
  2490. }
  2491. if (!function_exists('getOrderBy'))
  2492. {
  2493. //根据tags-list规则,获取查询排序,用于标签文件 TagArclist / TagList
  2494. function getOrderBy($orderby,$orderWay,$isrand=false){
  2495. switch ($orderby) {
  2496. case 'hot':
  2497. case 'click':
  2498. $orderby = "a.click {$orderWay}";
  2499. break;
  2500. case 'id': // 兼容织梦的写法
  2501. case 'aid':
  2502. $orderby = "a.aid {$orderWay}";
  2503. break;
  2504. case 'now':
  2505. case 'new': // 兼容织梦的写法
  2506. case 'pubdate': // 兼容织梦的写法
  2507. case 'add_time':
  2508. $orderby = "a.add_time {$orderWay}";
  2509. break;
  2510. case 'sortrank': // 兼容织梦的写法
  2511. case 'sort_order':
  2512. $orderby = "a.sort_order {$orderWay}";
  2513. break;
  2514. case 'rand':
  2515. if (true === $isrand) {
  2516. $orderby = "rand()";
  2517. } else {
  2518. $orderby = "a.aid {$orderWay}";
  2519. }
  2520. break;
  2521. default:
  2522. {
  2523. if (empty($orderby)) {
  2524. $orderby = 'a.sort_order asc, a.aid desc';
  2525. } elseif (trim($orderby) != 'rand()') {
  2526. $orderbyArr = explode(',', $orderby);
  2527. foreach ($orderbyArr as $key => $val) {
  2528. $val = trim($val);
  2529. if (preg_match('/^([a-z]+)\./i', $val) == 0) {
  2530. $val = 'a.'.$val;
  2531. $orderbyArr[$key] = $val;
  2532. }
  2533. }
  2534. $orderby = implode(',', $orderbyArr);
  2535. }
  2536. break;
  2537. }
  2538. }
  2539. return $orderby;
  2540. }
  2541. }
  2542. if (!function_exists('getLocationPages'))
  2543. {
  2544. /*
  2545. * 获取当前文章属于栏目第几条
  2546. */
  2547. function getLocationPages($tid,$aid,$order){
  2548. $map_arc = [];
  2549. if (!empty($tid)){
  2550. $id_arr = [$tid];
  2551. getAllChild($id_arr,$tid,2);
  2552. $map_arc['typeid'] = ['in',$id_arr];
  2553. }
  2554. $map_arc['is_del'] = 0;
  2555. $map_arc['status'] = 1;
  2556. $result = \think\Db::name('archives')->alias('a')->field("a.aid")->where($map_arc)->orderRaw($order)->select();
  2557. foreach ($result as $key=>$val){
  2558. if ($aid == $val['aid']){
  2559. return $key + 1;
  2560. }
  2561. }
  2562. return false;
  2563. }
  2564. }
  2565. if (!function_exists('auto_hide_index'))
  2566. {
  2567. /**
  2568. * URL中隐藏index.php入口文件(适用后台显示前台的URL)
  2569. */
  2570. function auto_hide_index($url, $seo_inlet = null) {
  2571. static $web_adminbasefile = null;
  2572. if (null === $web_adminbasefile) {
  2573. $web_adminbasefile = tpCache('web.web_adminbasefile');
  2574. $web_adminbasefile = !empty($web_adminbasefile) ? $web_adminbasefile : ROOT_DIR.'/login.php'; // 支持子目录
  2575. }
  2576. $url = str_replace($web_adminbasefile, ROOT_DIR.'/index.php', $url); // 支持子目录
  2577. null === $seo_inlet && $seo_inlet = config('ey_config.seo_inlet');
  2578. if (1 == $seo_inlet) {
  2579. $url = str_replace('/index.php/', '/', $url);
  2580. }
  2581. return $url;
  2582. }
  2583. }
  2584. if (!function_exists('getArchivesField'))
  2585. {
  2586. /**
  2587. * 获取指定文档的字段值
  2588. */
  2589. function getArchivesField($aid = 0, $fieldName = 'aid') {
  2590. $value = '';
  2591. if (0 < intval($aid)) {
  2592. if ('arcurl' == $fieldName) {
  2593. $row = \think\Db::name('archives')->where(['aid'=>$aid])->find();
  2594. $value = get_arcurl($row);
  2595. } else {
  2596. $value = \think\Db::name('archives')->where(['aid'=>$aid])->getField($fieldName);
  2597. if ('litpic' == $fieldName) {
  2598. $value = handle_subdir_pic($value); // 支持子目录
  2599. }
  2600. }
  2601. }
  2602. return $value;
  2603. }
  2604. }
  2605. if (!function_exists('GetUsersLatestData'))
  2606. {
  2607. /**
  2608. * 获取登录的会员最新数据
  2609. */
  2610. function GetUsersLatestData($users_id = null) {
  2611. $users_id = empty($users_id) ? session('users_id') : $users_id;
  2612. if(!empty($users_id)) {
  2613. /*读取的字段*/
  2614. $field = 'a.*, b.*, b.discount as level_discount';
  2615. /* END */
  2616. /*查询数据*/
  2617. $users = \think\Db::name('users')->field($field)
  2618. ->alias('a')
  2619. ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
  2620. ->where([
  2621. 'a.users_id' => $users_id,
  2622. 'a.lang' => get_home_lang(),
  2623. 'a.is_activation' => 1,
  2624. 'a.is_del' => 0,
  2625. ])->find();
  2626. // 会员不存在则返回空
  2627. if (empty($users)) return false;
  2628. /* END */
  2629. /*会员数据处理*/
  2630. // 头像处理
  2631. $users['head_pic'] = get_head_pic($users['head_pic']);
  2632. // 昵称处理
  2633. $users['nickname'] = empty($users['nickname']) ? $users['username'] : $users['nickname'];
  2634. // 密码为空并且存在openid则表示微信注册登录,密码字段更新为0,可重置密码一次。
  2635. $users['password'] = empty($users['password']) && !empty($users['thirdparty']) ? 1 : 1;
  2636. // 删除登录密码及支付密码
  2637. unset($users['paypwd']);
  2638. // 级别处理
  2639. $LevelData = [];
  2640. if (intval($users['level_maturity_days']) >= 36600) {
  2641. $users['maturity_code'] = 1;
  2642. $users['maturity_date'] = '终身';
  2643. }else if (0 == $users['open_level_time'] && 0 == $users['level_maturity_days']) {
  2644. $users['maturity_code'] = 0;
  2645. $users['maturity_date'] = '未升级会员';// 没有升级会员,置空
  2646. }else{
  2647. /*计算剩余天数*/
  2648. $days = $users['open_level_time'] + ($users['level_maturity_days'] * 86400);
  2649. // 取整
  2650. $days = ceil(($days - getTime()) / 86400);
  2651. if (0 >= $days) {
  2652. /*更新会员的级别*/
  2653. $LevelData = model('EyouUsers')->UpUsersLevelData($users_id);
  2654. /* END */
  2655. $users['maturity_code'] = 2;
  2656. $users['maturity_date'] = '未升级会员';// 会员过期,置空
  2657. }else{
  2658. $users['maturity_code'] = 3;
  2659. $users['maturity_date'] = $days.' 天';
  2660. }
  2661. /* END */
  2662. }
  2663. /* END */
  2664. // 合并数据
  2665. $LatestData = array_merge($users, $LevelData);
  2666. /*更新session*/
  2667. session('users', $LatestData);
  2668. session('users_id', $LatestData['users_id']);
  2669. setcookie('users_id', $LatestData['users_id'], null);
  2670. /* END */
  2671. // 返回数据
  2672. return $LatestData;
  2673. }else{
  2674. // session中不存在会员ID则返回空
  2675. return false;
  2676. }
  2677. }
  2678. }
  2679. if (!function_exists('GetTotalArc'))
  2680. {
  2681. /**
  2682. * 统计栏目文章数
  2683. */
  2684. function GetTotalArc($typeid = 0)
  2685. {
  2686. if (empty($typeid)) {
  2687. return 0;
  2688. } else {
  2689. $row = model('Arctype')->getHasChildren($typeid);
  2690. if (empty($row)) return 0;
  2691. $typeids = array_keys($row);
  2692. $condition = [
  2693. 'typeid' => ['IN', $typeids],
  2694. 'arcrank' => ['gt', -1],
  2695. 'status' => 1,
  2696. 'is_del' => 0,
  2697. ];
  2698. /*定时文档显示插件*/
  2699. if (is_dir('./weapp/TimingTask/')) {
  2700. $TimingTaskRow = model('Weapp')->getWeappList('TimingTask');
  2701. if (!empty($TimingTaskRow['status']) && 1 == $TimingTaskRow['status']) {
  2702. $condition['add_time'] = ['elt', getTime()]; // 只显当天或之前的文档
  2703. }
  2704. }
  2705. /*end*/
  2706. $count = \think\Db::name('archives')->where($condition)->count('aid');
  2707. return intval($count);
  2708. }
  2709. }
  2710. }