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

channelunit.class.php 7.2KB

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