国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

235 строки
7.5KB

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