国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

170 rindas
9.9KB

  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, $cfg_cmspath;
  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 = $cfg_cmspath."/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:field.body function='obtainalt(@me)'/}
  57. function obtainalt($newalt)
  58. {
  59. global $dsql, $id, $aid;
  60. $myid = isset($id) ? $id : $aid;
  61. $row = $dsql->GetOne("SELECT title FROM `#@__archives` WHERE id='$myid'");
  62. //图片注释自动为标题
  63. $newalt = str_ireplace(array('alt=""', 'alt=\'\'', 'title=""', 'title=\'\''), "", $newalt);
  64. $newalt = str_ireplace("<img", "<img alt=\"".$row['title']."\" title=\"".$row['title']."\"", $newalt);
  65. //去掉图片宽度和高度
  66. $newalt = preg_replace("/style=\"width\:(.*)\"/", "", $newalt);
  67. //去掉结尾
  68. $newalt = str_ireplace(" /", "", $newalt);
  69. return $newalt;
  70. }
  71. //联动单筛选{dede:php}obtainfilter(模型id,类型,'字段1,字段2');{/dede:php}类型表示前台展现方式对应case值
  72. function obtainfilter($channelid, $type = 1, $fieldsnamef = '', $defaulttid = 0, $toptid = 0, $loadtype = 'autofield')
  73. {
  74. global $tid, $dsql, $id, $aid;
  75. $tid = $defaulttid ? $defaulttid : $tid;
  76. if ($id!="" || $aid!="") {
  77. $arcid = $id!="" ? $id : $aid;
  78. $tidsq = $dsql->GetOne("SELECT * FROM `#@__archives` WHERE id='$arcid'");
  79. $tid = $toptid==0 ? $tidsq["typeid"] : $tidsq["topid"];
  80. }
  81. $nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".$_REQUEST['PageNo'] : '');
  82. $filterarr = string_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/apps/list.php?tid=".$tid);
  83. $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid'");
  84. $fieldset=$cInfos['fieldset'];
  85. $dtp = new DedeTagParse();
  86. $dtp->SetNameSpace('field', '<', '>');
  87. $dtp->LoadSource($fieldset);
  88. $biz_addonfields = '';
  89. if (is_array($dtp->CTags)) {
  90. foreach($dtp->CTags as $tida=>$ctag)
  91. {
  92. $fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $ctag->GetName());
  93. if (($loadtype!='autofield' || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1)) && in_array($ctag->GetName(), $fieldsname)) {
  94. $href1 = explode($ctag->GetName().'=', $filterarr);
  95. $href2 = explode('&', $href1[1]);
  96. $fields_value = $href2[0];
  97. switch ($type) {
  98. case 1:
  99. $biz_addonfields .= '<p>';
  100. $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>');
  101. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  102. for ($i=0; $i<count($addonfields_items); $i++)
  103. {
  104. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  105. $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>');
  106. }
  107. $biz_addonfields .= '</p>';
  108. break;
  109. case 2:
  110. $biz_addonfields .= '<select name="filter'.$ctag->GetName().'" onchange="window.location=this.options[this.selectedIndex].value" class="form-control w-25 mr-3">
  111. '.'<option value="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部</option>';
  112. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  113. for ($i=0; $i<count($addonfields_items); $i++)
  114. {
  115. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  116. $biz_addonfields .= '<option value="'.$href.'"'.($fields_value==urlencode($addonfields_items[$i]) ? ' selected="selected"' : '').'>'.$addonfields_items[$i].'</option>
  117. ';
  118. }
  119. $biz_addonfields .= '</select>';
  120. break;
  121. case 3:
  122. $biz_addonfields .= '<p>';
  123. $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>');
  124. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  125. for ($i=0; $i<count($addonfields_items); $i++)
  126. {
  127. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  128. $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>');
  129. }
  130. $biz_addonfields .= '</p>';
  131. break;
  132. }
  133. }
  134. }
  135. }
  136. echo $biz_addonfields;
  137. }
  138. //联动单筛选获取附加表
  139. function litimgurls($imgid = 0)
  140. {
  141. global $dsql, $lit_imglist;
  142. $row = $dsql->GetOne("SELECT c.addtable FROM `#@__archives` AS a LEFT JOIN `#@__channeltype` AS c ON a.channel=c.id WHERE a.id='$imgid'");
  143. $addtable = trim($row['addtable']);
  144. $row = $dsql->GetOne("SELECT imgurls FROM `$addtable` WHERE aid='$imgid'");
  145. $ChannelUnit = new ChannelUnit(2, $imgid);
  146. $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
  147. return $lit_imglist;
  148. }
  149. //联动单筛选字符过滤函数
  150. function string_filter($str, $stype = "inject")
  151. {
  152. if ($stype == "inject") {
  153. $str = str_replace(
  154. array("select", "insert", "update", "delete", "alter", "cas", "union", "into", "load_file", "outfile", "create", "join", "where", "like", "drop", "modify", "rename", "'", "/*", "*", "../", "./"),
  155. array("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""),
  156. $str
  157. );
  158. } else if ($stype == "xss") {
  159. $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",);
  160. $tarr = array(" ", "", "\\1\\2",);
  161. $str = preg_replace($farr, $tarr, $str);
  162. $str = str_replace(
  163. array("<", ">", "'", "\"", ";", "/*", "*", "../", "./"),
  164. array("&lt;", "&gt;", "", "", "", "", "", "", ""),
  165. $str
  166. );
  167. }
  168. return $str;
  169. }
  170. ?>