<?php
/**
* 父分类内容调用标签
* @author XingDongHai (http://www.xingdonghai.cn)
* @version 1.0 (2012-01-06)
*
* 用于调用父类或其他平行子类的内容,标签中可使用self参数进行设置是否包含父类自身,1为包含,0为不包含,默认为0
* 模板可用字段与arclist一致
*
* 可用的参数:
* row : 调用数量
* titlenlen : 标题长度
* infolen : 摘要长度
* orderby : 排序字段,rand为随机排序
* orderby : 排列顺序,asc升序、desc降序,当orderby为rand时此参数无效
* self : 是否包含父类自身
*
* 实例:
* {dede:parentlist row='10' titlelen='34'}
* <li><span>[field:pubdate function="MyDate('m-d', @me)"/]</span> <a href="[field:arcurl/]" title="[field:fulltitle/]">[field:title/]</a></li>
* {/dede:parentlist}
*/
if (!defined('DEDEINC'))
die('Request Error!');
function lib_parentlist(&$ctag, &$refObj) {
global $dsql, $envs;
//属性处理
$attlist="row|12,titlelen|40,infolen|200,orderby|id,orderby|desc,self|0";
FillAttsDefault($ctag->CAttribute->Items, $attlist);
extract($ctag->CAttribute->Items, EXTR_SKIP);
$revalue = '';
$innertext = $ctag->GetInnerText();
$ctp = new DedeTagParse();
$ctp->SetNameSpace('field', '[', ']');
//对一些数字型的参数进行验证
if (!is_numeric($row))
$row = 12;
if (!is_numeric($titlelen))
$titlelen = 40;
if (!is_numeric($infolen))
$infolen = 200;
$self = '0' != $self && '1' != $self ? 0 : (int) $self;
//处理排序方式
if (!in_array($orderby, array('id', 'pubdate', 'rand', 'click', 'scores', 'lastpost')))
$orderby = '';
if ('rand' == $orderby) {
$orderby = ' ORDER BY RAND()';
} elseif ('' != $orderby) {
$orderway = strtoupper($orderway);
$orderby = ' ORDER BY ' . $orderby . ' ' . ('DESC' != $orderway && 'ASC' != $orderway ? 'DESC' : $orderway);
}
//获取父类下的所有子类
$tids = GetSonIds($envs['reid'], 0, $self);
if ('' == $tids)
return '';
$sql = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath FROM `dede_archives` AS arc LEFT JOIN `dede_arctype` tp ON arc.typeid=tp.id WHERE arc.arcrank>-1 AND arc.typeid IN ({$tids}){$orderby} LIMIT 0,{$row}";
$dsql->Execute('me' ,$sql);
$restr = '';
while($row = $dsql->GetArray('me')) {
//处理标题信息
$row['fulltitle'] = $row['title'];
if ('' == $row['shorttitle'])
$row['shorttitle'] = $row['title'];
$row['title'] = cn_substr($row['title'], $titlelen);
if ('' != $row['color'])
$row['title'] = '<font color="' . $row['color'] . '">' . $row['title'] . '</font>';
if (strpos($row['flag'], 'b'))
$row['title'] = '<strong>' . $row['title'] . '</strong>';
//处理摘要
$row['info'] = cn_substr($row['description'], $infolen);
//处理缩略图
$row['image'] = '<img src="' . $row['picname'] . '" border="0" width="' . $imgwidth . '" height="' . $imgheight . '" alt="' . preg_replace('["><]', '', $row['title']) . '">';
if ('-' == $row['litpic'] || '' == $row['litpic'])
$row['litpic'] = $GLOBALS['cfg_cmspath'] . '/images/defaultpic.gif';
if ('Y' == $GLOBALS['cfg_multi_site'] && !preg_match('/^http:\/\//', $row['litpic']))
$row['litpic'] = $GLOBALS['cfg_mainsite'] . $row['litpic'];
$row['picname'] = $row['litpic'];
//处理链接
$row['arcurl'] = GetFileUrl($row['id'], $row['typeid'], $row['senddate'], $row['title'], $row['ismake'], $row['arcrank'], $row['namerule'], $row['typedir'], $row['money'], $row['filename'], $row['moresite'], $row['siteurl'], $row['sitepath']);
$row['imglink'] = '<a href="' . $row['arcurl'] . '">' . $row['image'] . '</a>';
$row['typeurl'] = GetTypeUrl($row['typeid'], $row['typedir'], $row['isdefault'], $row['defaultname'], $row['ispart'], $row['namerule2'], $row['moresite'], $row['siteurl'], $row['sitepath']);
$row['typelink'] = '<a href="' . $row['typeurl'] . '">' . $row['typename'] . '</a>';
$row['textlink'] = '<a href="' . $row['arcurl'] . '">' . $row['title'] . '</a>';
//替换模板
$ctp->LoadSource($innertext);
foreach ($ctp->CTags as $tagid => $ctag) {
if (!empty($row[strtolower($ctag->GetName())]))
$ctp->Assign($tagid, $row[$ctag->GetName()]);
}
$restr .= $ctp->GetResult();
}
return $restr;
}
?>
|