国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
9.2KB

  1. <?php
  2. if (!defined('DEDEINC')) exit ('dedebiz');
  3. /**
  4. * 扩展函数
  5. *
  6. * @version $id:extend.func.php 2 20:50 2010年7月7日 tianya $
  7. * @package DedeBIZ.Libraries
  8. * @copyright Copyright (c) 2022 DedeBIZ.COM
  9. * @license GNU GPL v2 (https://www.dedebiz.com/license)
  10. * @link https://www.dedebiz.com
  11. */
  12. /*会员中心调用主题模板<?php obtaintheme('head.htm');?>*/
  13. if (!function_exists('obtaintheme')) {
  14. require_once DEDEINC."/archive/partview.class.php";
  15. function obtaintheme($path)
  16. {
  17. global $cfg_basedir, $cfg_templets_dir, $cfg_df_style;
  18. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$cfg_df_style.'/'.$path;
  19. $dtp = new PartView();
  20. $dtp->SetTemplet($tmpfile);
  21. $dtp->Display();
  22. }
  23. }
  24. //标签调用[field:id function='obtaintags(@me,3)'/]3表示调用文档3个标签
  25. if (!function_exists('obtaintags')) {
  26. function obtaintags($aid, $num = 3)
  27. {
  28. global $dsql;
  29. $tags = '';
  30. $query = "SELECT * FROM `#@__taglist` WHERE aid='$aid' LIMIT $num";
  31. $dsql->Execute('tag',$query);
  32. while($row = $dsql->GetArray('tag')) {
  33. $link = "/apps/tags.php?/{$row['tid']}";
  34. $tags .= ($tags == '' ? "<a href='{$link}'>{$row['tag']}</a>" : "<a href='{$link}'>{$row['tag']}</a>");
  35. }
  36. return $tags;
  37. }
  38. }
  39. //提取文档多图片[field:body function='obtainimgs(@me,3)'/]3表示调用文档3张图片,则附加字段需添加body字段调用channelid='模型id' addfields='字段1,字段2'
  40. if (!function_exists('obtainimgs')) {
  41. function obtainimgs($string, $num)
  42. {
  43. preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/", $string, $matches);
  44. $imgsrc_arr = array_unique($matches[3]);
  45. $i = 0;
  46. $result = '';
  47. foreach($imgsrc_arr as $imgsrc)
  48. {
  49. if ($i == $num) break;
  50. $result .= "<img src=\"$imgsrc\">";
  51. $i++;
  52. }
  53. return $result;
  54. }
  55. }
  56. //联动单筛选{dede:php}obtainfilter(模型id,类型,'字段1,字段2');{/dede:php}类型表示前台展现方式对应case值
  57. function obtainfilter($channelid, $type = 1, $fieldsnamef = '', $defaulttid = 0, $toptid = 0, $loadtype = 'autofield')
  58. {
  59. global $tid, $dsql, $id, $aid;
  60. $tid = $defaulttid ? $defaulttid : $tid;
  61. if ($id!="" || $aid!="") {
  62. $arcid = $id!="" ? $id : $aid;
  63. $tidsq = $dsql->GetOne("SELECT * FROM `#@__archives` WHERE id='$arcid'");
  64. $tid = $toptid==0 ? $tidsq["typeid"] : $tidsq["topid"];
  65. }
  66. $nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".$_REQUEST['PageNo'] : '');
  67. $filterarr = string_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/apps/list.php?tid=".$tid);
  68. $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid'");
  69. $fieldset=$cInfos['fieldset'];
  70. $dtp = new DedeTagParse();
  71. $dtp->SetNameSpace('field', '<', '>');
  72. $dtp->LoadSource($fieldset);
  73. $biz_addonfields = '';
  74. if (is_array($dtp->CTags)) {
  75. foreach($dtp->CTags as $tida=>$ctag)
  76. {
  77. $fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $ctag->GetName());
  78. if (($loadtype!='autofield' || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1)) && in_array($ctag->GetName(), $fieldsname)) {
  79. $href1 = explode($ctag->GetName().'=', $filterarr);
  80. $href2 = explode('&', $href1[1]);
  81. $fields_value = $href2[0];
  82. switch ($type) {
  83. case 1:
  84. $biz_addonfields .= '<p>';
  85. $biz_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? '<a href="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'" class="btn btn-outline-success btn-sm">全部</a>' : '<a href="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'" class="btn btn-success btn-sm">全部</a>');
  86. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  87. for ($i=0; $i<count($addonfields_items); $i++)
  88. {
  89. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  90. $biz_addonfields .= ($fields_value!=urlencode($addonfields_items[$i]) ? '<a title="'.$addonfields_items[$i].'" href="'.$href.'" class="btn btn-outline-success btn-sm">'.$addonfields_items[$i].'</a>' : '<a href="'.$href.'" class="btn btn-success btn-sm">'.$addonfields_items[$i].'</a>');
  91. }
  92. $biz_addonfields .= '</p>';
  93. break;
  94. case 2:
  95. $biz_addonfields .= '<select name="filter'.$ctag->GetName().'" onchange="window.location=this.options[this.selectedIndex].value" class="form-control w-25 mr-3">
  96. '.'<option value="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部</option>';
  97. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  98. for ($i=0; $i<count($addonfields_items); $i++)
  99. {
  100. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  101. $biz_addonfields .= '<option value="'.$href.'"'.($fields_value==urlencode($addonfields_items[$i]) ? ' selected="selected"' : '').'>'.$addonfields_items[$i].'</option>
  102. ';
  103. }
  104. $biz_addonfields .= '</select>';
  105. break;
  106. case 3:
  107. $biz_addonfields .= '<p>';
  108. $biz_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? '<a href="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'"><input type="radio" name="filter'.$ctag->GetName().'" value="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'" onclick="window.location=this.value">全部</a>' : '<span><input type="radio" name="filter'.$ctag->GetName().'" checked>全部</span>');
  109. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  110. for ($i=0; $i<count($addonfields_items); $i++)
  111. {
  112. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  113. $biz_addonfields .= ($fields_value!=urlencode($addonfields_items[$i]) ? '<a title="'.$addonfields_items[$i].'" href="'.$href.'"><input type="radio" name="filter'.$ctag->GetName().'" value="'.$href.'" onclick="window.location=this.value">'.$addonfields_items[$i].'</a>' : '<span><input type="radio" name="filter'.$ctag->GetName().'" checked>'.$addonfields_items[$i].'</span>');
  114. }
  115. $biz_addonfields .= '</p>';
  116. break;
  117. }
  118. }
  119. }
  120. }
  121. echo $biz_addonfields;
  122. }
  123. //联动单筛选获取附加表
  124. function litimgurls($imgid = 0)
  125. {
  126. global $dsql, $lit_imglist;
  127. $row = $dsql->GetOne("SELECT c.addtable FROM `#@__archives` AS a LEFT JOIN `#@__channeltype` AS c ON a.channel=c.id WHERE a.id='$imgid'");
  128. $addtable = trim($row['addtable']);
  129. $row = $dsql->GetOne("SELECT imgurls FROM `$addtable` WHERE aid='$imgid'");
  130. $ChannelUnit = new ChannelUnit(2, $imgid);
  131. $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
  132. return $lit_imglist;
  133. }
  134. //联动单筛选字符过滤函数
  135. function string_filter($str, $stype = "inject")
  136. {
  137. if ($stype == "inject") {
  138. $str = str_replace(
  139. array("select", "insert", "update", "delete", "alter", "cas", "union", "into", "load_file", "outfile", "create", "join", "where", "like", "drop", "modify", "rename", "'", "/*", "*", "../", "./"),
  140. array("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""),
  141. $str
  142. );
  143. } else if ($stype == "xss") {
  144. $farr = array("/\s+/", "/<(\/?)(script|META|STYLE|HTML|HEAD|BODY|STYLE |i?frame|b|strong|style|html|img|P|o:p|iframe|u|em|strike|BR|div|a|TABLE|TBODY|object|tr|td|st1:chsdate|FONT|span|MARQUEE|body|title|\r\n|link|meta|\?|\%)([^>]*?)>/isU", "/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",);
  145. $tarr = array(" ", "", "\\1\\2",);
  146. $str = preg_replace($farr, $tarr, $str);
  147. $str = str_replace(
  148. array("<", ">", "'", "\"", ";", "/*", "*", "../", "./"),
  149. array("&lt;", "&gt;", "", "", "", "", "", "", ""),
  150. $str
  151. );
  152. }
  153. return $str;
  154. }
  155. ?>