国内流行的内容管理系统(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. function obtaintags($aid, $num = 3)
  26. {
  27. global $dsql, $cfg_cmspath, $cfg_rewrite;
  28. $tags = '';
  29. $query = "SELECT * FROM `#@__taglist` WHERE aid='$aid' LIMIT $num";
  30. $dsql->Execute('tag', $query);
  31. while ($row = $dsql->GetArray('tag')) {
  32. if ($cfg_rewrite == 'Y') {
  33. $link = $cfg_cmspath."/tags/{$row['tid']}";
  34. } else {
  35. $link = $cfg_cmspath."/apps/tags.php?/{$row['tid']}";
  36. }
  37. $tags .= ($tags == '' ? "<a href=\"{$link}\">{$row['tag']}</a>" : "、<a href=\"{$link}\">{$row['tag']}</a>");
  38. }
  39. return $tags;
  40. }
  41. //提取文档多图片[field:body function='obtainimgs(@me,3)'/]3表示调用文档3张图片,例如:文档模型body字段,列表附加字段添加body,dede:arclist标签调用添加channelid='1' addfields='body'
  42. if (!function_exists('obtainimgs')) {
  43. function obtainimgs($string, $num)
  44. {
  45. preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/", $string, $matches);
  46. $imgsrc_arr = array_unique($matches[3]);
  47. $i = 0;
  48. $result = '';
  49. foreach ($imgsrc_arr as $imgsrc)
  50. {
  51. if ($i == $num) break;
  52. $result .= "<img src=\"{$imgsrc}\">";
  53. $i++;
  54. }
  55. return $result;
  56. }
  57. }
  58. //文档图片注释自动为标题{dede:field.body function='obtainalt(@me)'/}
  59. function obtainalt($newalt)
  60. {
  61. global $dsql, $id, $aid;
  62. $myid = isset($id) ? $id : $aid;
  63. $row = $dsql->GetOne("SELECT title FROM `#@__archives` WHERE id='$myid'");
  64. //检查$row是否为有效的数组并且包含title
  65. if (is_array($row) && isset($row['title'])) {
  66. //图片注释自动为标题
  67. $newalt = str_ireplace(array('alt=""', "alt=''", 'title=""', "title=''"), "", $newalt);
  68. $newalt = str_ireplace("<img", "<img alt=\"".$row['title']."\" title=\"".$row['title']."\"", $newalt);
  69. //去掉图片宽度和高度
  70. $newalt = preg_replace("/style=\"width\:(.*)\"/", "", $newalt);
  71. //去掉结尾多余的空格和斜杠
  72. $newalt = str_ireplace(" ", " ", $newalt);
  73. $newalt = str_ireplace(" /", "", $newalt);
  74. }
  75. return $newalt;
  76. }
  77. //联动单筛选{dede:php}obtainfilter(模型id,类型,'字段1,字段2');{/dede:php}类型表示前台展现方式,对应case值,例如:文档模型style字段radio选项卡类型,列表附加字段类别添加style,标签调用{dede:php}obtainfilter(1,1,'style');{/dede:php}
  78. function obtainfilter($channelid, $type = 1, $fieldsnamef = '', $defaulttid = 0, $toptid = 0, $loadtype = 'autofield')
  79. {
  80. global $tid, $dsql, $id, $aid;
  81. $tid = $defaulttid ? $defaulttid : $tid;
  82. if ($id!="" || $aid!="") {
  83. $arcid = $id!="" ? $id : $aid;
  84. $tidsq = $dsql->GetOne("SELECT * FROM `#@__archives` WHERE id='$arcid'");
  85. $tid = $toptid==0 ? $tidsq["typeid"] : $tidsq["topid"];
  86. }
  87. $nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".$_REQUEST['PageNo'] : '');
  88. $filterarr = stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."apps/list.php?tid=".$tid;
  89. $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid'");
  90. $fieldset=$cInfos['fieldset'];
  91. $dtp = new DedeTagParse();
  92. $dtp->SetNameSpace('field', '<', '>');
  93. $dtp->LoadSource($fieldset);
  94. $biz_addonfields = '';
  95. if (is_array($dtp->CTags)) {
  96. foreach($dtp->CTags as $tida=>$ctag)
  97. {
  98. $fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $ctag->GetName());
  99. if (($loadtype!='autofield' || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1)) && in_array($ctag->GetName(), $fieldsname)) {
  100. $href1 = explode($ctag->GetName().'=', $filterarr);
  101. $href2 = explode('&', $href1[1]);
  102. $fields_value = $href2[0];
  103. switch ($type) {
  104. case 1:
  105. $biz_addonfields .= '<p>';
  106. $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>');
  107. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  108. for ($i=0; $i<count($addonfields_items); $i++)
  109. {
  110. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  111. $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>');
  112. }
  113. $biz_addonfields .= '</p>';
  114. break;
  115. case 2:
  116. $biz_addonfields .= '<select name="filter'.$ctag->GetName().'" onchange="window.location=this.options[this.selectedIndex].value" class="form-control w-25 mr-3">
  117. '.'<option value="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部</option>';
  118. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  119. for ($i=0; $i<count($addonfields_items); $i++)
  120. {
  121. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  122. $biz_addonfields .= '<option value="'.$href.'"'.($fields_value==urlencode($addonfields_items[$i]) ? ' selected="selected"' : '').'>'.$addonfields_items[$i].'</option>
  123. ';
  124. }
  125. $biz_addonfields .= '</select>';
  126. break;
  127. case 3:
  128. $biz_addonfields .= '<p>';
  129. $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>');
  130. $addonfields_items = explode(",",$ctag->GetAtt('default'));
  131. for ($i=0; $i<count($addonfields_items); $i++)
  132. {
  133. $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
  134. $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>');
  135. }
  136. $biz_addonfields .= '</p>';
  137. break;
  138. }
  139. }
  140. }
  141. }
  142. echo $biz_addonfields;
  143. }
  144. //联动单筛选获取附加表
  145. function litimgurls($imgid = 0)
  146. {
  147. global $dsql, $lit_imglist;
  148. $row = $dsql->GetOne("SELECT c.addtable FROM `#@__archives` AS a LEFT JOIN `#@__channeltype` AS c ON a.channel=c.id WHERE a.id='$imgid'");
  149. $addtable = trim($row['addtable']);
  150. $row = $dsql->GetOne("SELECT imgurls FROM `$addtable` WHERE aid='$imgid'");
  151. $ChannelUnit = new ChannelUnit(2, $imgid);
  152. $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
  153. return $lit_imglist;
  154. }
  155. ?>