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

212 lines
7.2KB

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