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

234 lines
7.4KB

  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 DedeCMS.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. {
  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. {
  46. $tnames = Array();
  47. foreach($dtp->CTags as $ctag)
  48. {
  49. $tname = $ctag->GetName();
  50. if(isset($tnames[$tname]))
  51. {
  52. break;
  53. }
  54. $tnames[$tname] = 1;
  55. if($this->AllFieldNames!='')
  56. {
  57. $this->AllFieldNames .= ','.$tname;
  58. }
  59. else
  60. {
  61. $this->AllFieldNames .= $tname;
  62. }
  63. if(is_array($ctag->CAttribute->Items))
  64. {
  65. $this->ChannelFields[$tname] = $ctag->CAttribute->Items;
  66. }
  67. $this->ChannelFields[$tname]['value'] = '';
  68. $this->ChannelFields[$tname]['innertext'] = $ctag->GetInnerText();
  69. if(empty($this->ChannelFields[$tname]['itemname']))
  70. {
  71. $this->ChannelFields[$tname]['itemname'] = $tname;
  72. }
  73. if($ctag->GetAtt('page')=='split')
  74. {
  75. $this->SplitPageField = $tname;
  76. }
  77. }
  78. }
  79. $dtp->Clear();
  80. }
  81. function ChannelUnit($cid,$aid=0)
  82. {
  83. $this->__construct($cid,$aid);
  84. }
  85. /**
  86. * 设置档案ID
  87. *
  88. * @access private
  89. * @param int $aid 档案ID
  90. * @return void
  91. */
  92. function SetArcID($aid)
  93. {
  94. $this->ArcID = $aid;
  95. }
  96. /**
  97. * 处理某个字段的值
  98. *
  99. * @access public
  100. * @param string $fname 字段名称
  101. * @param string $fvalue 字段值
  102. * @param string $addvalue 增加值
  103. * @return string
  104. */
  105. function MakeField($fname, $fvalue, $addvalue='')
  106. {
  107. //处理各种数据类型
  108. $ftype = $this->ChannelFields[$fname]['type'];
  109. if($fvalue=='')
  110. {
  111. if($ftype != 'checkbox') $fvalue = $this->ChannelFields[$fname]['default'];
  112. }
  113. if($ftype=='text')
  114. {
  115. $fvalue = HtmlReplace($fvalue);
  116. }
  117. else if($ftype=='textdata')
  118. {
  119. if(!is_file($GLOBALS['cfg_basedir'].$fvalue))
  120. {
  121. return '';
  122. }
  123. $fp = fopen($GLOBALS['cfg_basedir'].$fvalue,'r');
  124. $fvalue = '';
  125. while(!feof($fp))
  126. {
  127. $fvalue .= fgets($fp,1024);
  128. }
  129. fclose($fp);
  130. }
  131. else if($ftype=='addon')
  132. {
  133. $foldvalue = $fvalue;
  134. $tmptext = GetSysTemplets("channel_addon.htm");
  135. $fvalue = str_replace('~link~',$foldvalue,$tmptext);
  136. $fvalue = str_replace('~phpurl~',$GLOBALS['cfg_phpurl'],$fvalue);
  137. }
  138. else if(file_exists(DEDEINC.'/taglib/channel/'.$ftype.'.lib.php'))
  139. {
  140. include_once(DEDEINC.'/taglib/channel/'.$ftype.'.lib.php');
  141. $func = 'ch_'.$ftype;
  142. $fvalue = $func($fvalue,$addvalue,$this,$fname);
  143. }
  144. return $fvalue;
  145. }
  146. /**
  147. * 获取缩略图链接
  148. *
  149. * @access public
  150. * @param string $fvalue 表单值
  151. * @return string
  152. */
  153. function GetlitImgLinks($fvalue)
  154. {
  155. if($GLOBALS["htmltype"]=="dm"){
  156. if(empty($GLOBALS["pageno"])) $NowPage = 1;
  157. else $NowPage = intval($GLOBALS["pageno"]);
  158. }else{
  159. if(empty($GLOBALS["stNowPage"])) $NowPage = 1;
  160. else $NowPage = intval($GLOBALS["stNowPage"]);
  161. }
  162. $revalue = "";
  163. $dtp = new DedeTagParse();
  164. $dtp->LoadSource($fvalue);
  165. if(!is_array($dtp->CTags)){
  166. $dtp->Clear();
  167. return "无图片信息!";
  168. }
  169. $ptag = $dtp->GetTag("pagestyle");
  170. if(is_object($ptag)){
  171. $pagestyle = $ptag->GetAtt('value');
  172. $maxwidth = $ptag->GetAtt('maxwidth');
  173. $ddmaxwidth = $ptag->GetAtt('ddmaxwidth');
  174. $irow = $ptag->GetAtt('row');
  175. $icol = $ptag->GetAtt('col');
  176. if(empty($maxwidth)) $maxwidth = $GLOBALS['cfg_album_width'];
  177. }else{
  178. $pagestyle = 2;
  179. $maxwidth = $GLOBALS['cfg_album_width'];
  180. $ddmaxwidth = 200;
  181. }
  182. if($pagestyle == 3){
  183. if(empty($irow)) $irow = 4;
  184. if(empty($icol)) $icol = 4;
  185. }
  186. $mrow = 0;
  187. $mcol = 0;
  188. $photoid = 1;
  189. $images = array();
  190. $TotalPhoto = sizeof($dtp->CTags);
  191. foreach($dtp->CTags as $ctag){
  192. if($ctag->GetName()=="img")
  193. {
  194. $iw = $ctag->GetAtt('width');
  195. $ih = $ctag->GetAtt('heigth');
  196. $alt = str_replace("'","",$ctag->GetAtt('text'));
  197. $src = trim($ctag->GetInnerText());
  198. $ddimg = $ctag->GetAtt('ddimg');
  199. if($iw > $maxwidth) $iw = $maxwidth;
  200. $iw = (empty($iw) ? "" : "width='$iw'");
  201. if($GLOBALS["htmltype"]=="dm") {
  202. $imgurl = "view.php?aid=$this->ArcID&pageno=$photoid";
  203. }else{
  204. if($photoid==1){
  205. $imgurl = $GLOBALS["fileFirst"].".html";
  206. }else{
  207. $imgurl = $GLOBALS["fileFirst"]."_".$photoid.".html";
  208. }
  209. }
  210. $imgcls = "image".($photoid-1);
  211. $revalue .= "<dl><dt>$alt<dd>$ddimg<dd>$ddimg<dd>$ddimg<dd><dd><div></div><div></div><dd><dd>$photoid</dd></dl>\r\n";
  212. $photoid++;
  213. }
  214. }
  215. unset($dtp);
  216. unset($images);
  217. return $revalue;
  218. }
  219. //关闭所占用的资源
  220. function Close()
  221. {
  222. }
  223. }//End class ChannelUnit