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

202 lines
7.0KB

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