国内流行的内容管理系统(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.

205 lines
7.2KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 栏目模型单元类
  5. *
  6. * @version $id:channelunit.class.php 2 17:32 2010年7月6日 tianya $
  7. * @package DedeBIZ.Libraries
  8. * @copyright Copyright (c) 2022 DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(DEDEINC."/dedetag.class.php");
  13. require_once(DEDEINC."/channelunit.func.php");
  14. /*----------------------------------
  15. function C____ChannelUnit();
  16. -----------------------------------*/
  17. class ChannelUnit
  18. {
  19. var $ChannelInfos;
  20. var $ChannelFields;
  21. var $AllFieldNames;
  22. var $ChannelID;
  23. var $ArcID;
  24. var $dsql;
  25. var $SplitPageField;
  26. //php5构造函数
  27. function __construct($cid, $aid = 0)
  28. {
  29. $this->ChannelInfos = '';
  30. $this->ChannelFields = array();
  31. $this->AllFieldNames = '';
  32. $this->SplitPageField = '';
  33. $this->ChannelID = $cid;
  34. $this->ArcID = $aid;
  35. $this->dsql = $GLOBALS['dsql'];
  36. $sql = " SELECT * FROM `#@__channeltype` WHERE id='$cid' ";
  37. $this->ChannelInfos = $this->dsql->GetOne($sql);
  38. if (!is_array($this->ChannelInfos)) {
  39. echo '读取栏目信息失败,无法进行后续操作';
  40. exit();
  41. }
  42. $dtp = new DedeTagParse();
  43. $dtp->SetNameSpace('field', '<', '>');
  44. $dtp->LoadSource($this->ChannelInfos['fieldset']);
  45. if (is_array($dtp->CTags)) {
  46. $tnames = array();
  47. foreach ($dtp->CTags as $ctag) {
  48. $tname = $ctag->GetName();
  49. if (isset($tnames[$tname])) {
  50. break;
  51. }
  52. $tnames[$tname] = 1;
  53. if ($this->AllFieldNames != '') {
  54. $this->AllFieldNames .= ','.$tname;
  55. } else {
  56. $this->AllFieldNames .= $tname;
  57. }
  58. if (is_array($ctag->CAttribute->Items)) {
  59. $this->ChannelFields[$tname] = $ctag->CAttribute->Items;
  60. }
  61. $this->ChannelFields[$tname]['value'] = '';
  62. $this->ChannelFields[$tname]['innertext'] = $ctag->GetInnerText();
  63. if (empty($this->ChannelFields[$tname]['itemname'])) {
  64. $this->ChannelFields[$tname]['itemname'] = $tname;
  65. }
  66. if ($ctag->GetAtt('page') == 'split') {
  67. $this->SplitPageField = $tname;
  68. }
  69. }
  70. }
  71. $dtp->Clear();
  72. }
  73. function ChannelUnit($cid, $aid = 0)
  74. {
  75. $this->__construct($cid, $aid);
  76. }
  77. /**
  78. * 设置文档ID
  79. *
  80. * @access private
  81. * @param int $aid 文档ID
  82. * @return void
  83. */
  84. function SetArcID($aid)
  85. {
  86. $this->ArcID = $aid;
  87. }
  88. /**
  89. * 处理某个字段的值
  90. *
  91. * @access public
  92. * @param string $fname 字段名称
  93. * @param string $fvalue 字段值
  94. * @param string $addvalue 增加值
  95. * @return string
  96. */
  97. function MakeField($fname, $fvalue, $addvalue = '')
  98. {
  99. //处理各种数据类型
  100. $ftype = $this->ChannelFields[$fname]['type'];
  101. if ($fvalue == '') {
  102. if ($ftype != 'checkbox') $fvalue = $this->ChannelFields[$fname]['default'];
  103. }
  104. if ($ftype == 'text') {
  105. $fvalue = HtmlReplace($fvalue);
  106. } else if ($ftype == 'textdata') {
  107. if (!is_file($GLOBALS['cfg_basedir'].$fvalue)) {
  108. return '';
  109. }
  110. $fp = fopen($GLOBALS['cfg_basedir'].$fvalue, 'r');
  111. $fvalue = '';
  112. while (!feof($fp)) {
  113. $fvalue .= fgets($fp, 1024);
  114. }
  115. fclose($fp);
  116. } else if ($ftype == 'addon') {
  117. $foldvalue = $fvalue;
  118. $tmptext = GetSysTemplets("channel_addon.htm");
  119. $fvalue = str_replace('~link~', $foldvalue, $tmptext);
  120. $fvalue = str_replace('~phpurl~', $GLOBALS['cfg_phpurl'], $fvalue);
  121. } else if (file_exists(DEDEINC.'/taglib/channel/'.$ftype.'.lib.php')) {
  122. include_once(DEDEINC.'/taglib/channel/'.$ftype.'.lib.php');
  123. $func = 'ch_'.$ftype;
  124. $fvalue = $func($fvalue, $addvalue, $this, $fname);
  125. }
  126. return $fvalue;
  127. }
  128. /**
  129. * 获取缩略图链接
  130. *
  131. * @access public
  132. * @param string $fvalue 表单值
  133. * @return string
  134. */
  135. function GetlitImgLinks($fvalue)
  136. {
  137. if ($GLOBALS["htmltype"] == "dm") {
  138. if (empty($GLOBALS["pageno"])) $NowPage = 1;
  139. else $NowPage = intval($GLOBALS["pageno"]);
  140. } else {
  141. if (empty($GLOBALS["stNowPage"])) $NowPage = 1;
  142. else $NowPage = intval($GLOBALS["stNowPage"]);
  143. }
  144. $revalue = "";
  145. $dtp = new DedeTagParse();
  146. $dtp->LoadSource($fvalue);
  147. if (!is_array($dtp->CTags)) {
  148. $dtp->Clear();
  149. return "无图片信息";
  150. }
  151. $ptag = $dtp->GetTag("pagestyle");
  152. if (is_object($ptag)) {
  153. $pagestyle = $ptag->GetAtt('value');
  154. $maxwidth = $ptag->GetAtt('maxwidth');
  155. $ddmaxwidth = $ptag->GetAtt('ddmaxwidth');
  156. $irow = $ptag->GetAtt('row');
  157. $icol = $ptag->GetAtt('col');
  158. if (empty($maxwidth)) $maxwidth = $GLOBALS['cfg_album_width'];
  159. } else {
  160. $pagestyle = 2;
  161. $maxwidth = $GLOBALS['cfg_album_width'];
  162. $ddmaxwidth = 200;
  163. }
  164. if ($pagestyle == 3) {
  165. if (empty($irow)) $irow = 4;
  166. if (empty($icol)) $icol = 4;
  167. }
  168. $mrow = 0;
  169. $mcol = 0;
  170. $photoid = 1;
  171. $images = array();
  172. $TotalPhoto = sizeof($dtp->CTags);
  173. foreach ($dtp->CTags as $ctag) {
  174. if ($ctag->GetName() == "img") {
  175. $iw = $ctag->GetAtt('width');
  176. $ih = $ctag->GetAtt('heigth');
  177. $alt = str_replace("'", "", $ctag->GetAtt('text'));
  178. $src = trim($ctag->GetInnerText());
  179. $ddimg = $ctag->GetAtt('ddimg');
  180. if ($iw > $maxwidth) $iw = $maxwidth;
  181. $iw = (empty($iw) ? "" : "width='$iw'");
  182. if ($GLOBALS["htmltype"] == "dm") {
  183. $imgurl = "view.php?aid=$this->ArcID&pageno=$photoid";
  184. } else {
  185. if ($photoid == 1) {
  186. $imgurl = $GLOBALS["fileFirst"].".html";
  187. } else {
  188. $imgurl = $GLOBALS["fileFirst"]."_".$photoid.".html";
  189. }
  190. }
  191. $imgcls = "image".($photoid - 1);
  192. $revalue .= "<dl><dt>$alt<dd>$ddimg<dd>$ddimg<dd>$ddimg<dd><dd><div></div><div></div><dd><dd>$photoid</dd></dl>\r\n";
  193. $photoid++;
  194. }
  195. }
  196. unset($dtp);
  197. unset($images);
  198. return $revalue;
  199. }
  200. //关闭所占用的资源
  201. function Close()
  202. {
  203. }
  204. }//End class ChannelUnit
  205. ?>