韩日性爱视频

« “齐鲁风采”电脑福利彩票手机投注操作办法
linux空间下.htacess的几个用处 »

让dedecms的likearticle标签支持orderby跟subday等属性.

dedecms5.6中标签{dede:likearticle }{/dede:likearticle}默认不支持order by 和subway属性,
为了满足对这两个属性的需求,可以通过修改likearticle标签源代码来实现。
在标签源码管理中 找到likearticle.lib.php即为likearticle的源代码。
 
1.orderby 属性
 
首先获得标签传递过来的orderby的属性值
$orderby=$ctag->GetAtt('orderby');
在源代码中有这样一组代码
if( empty($arcid) || $byabs==0 ) {
   $orderquery = " order by arc.id desc "; 
}
else {
   $orderquery = " order by ABS(arc.id - ".$arcid.") ";
}
likearticle标签默认的排序方式。赋予标签orderby属性那么这段代码就没意义了,先在源码中注释掉这段代码
 
/*if( empty($arcid) || $byabs==0 ) {
   $orderquery = " order by arc.id desc "; 
}
else {
   $orderquery = " order by ABS(arc.id - ".$arcid.") ";
}
*/
直接延用默认的order by 子句变量$orderquery,这样sql语句就不用做更改了。
创建新变量 orderquery='';//mysql 查询语句中的order by子句 初始为空
然后根据传递的值做相应的判断,在这里只做一些最常用的值的判断
根据$orderby的值做不同的orderby 查询
if($orderby=='hot' || $orderby=='click') $orderquery = " order by arc.click $orderWay";
else if($orderby == 'sortrank' || $orderby=='pubdate') $orderquery = " order by arc.sortrank $orderWay";
else if($orderby == 'id') $orderquery = " order by arc.id $orderWay";
else if($orderby == 'near') $orderquery = " order by ABS(arc.id - ".$arcid.")";
else if($orderby == 'lastpost') $orderquery = " order by arc.lastpost $orderWay";
else if($orderby == 'scores') $orderquery = " order by arc.scores $orderWay";
else if($orderby == 'rand') $orderquery = " order by rand()";
else if($orderby == 'weight') $orderquery = " order by arc.weight asc";//如果没有特定设置排序则按照权重先排序
else $orderquery = " order by arc.sortrank $orderWay"; 
 
 
ok这样就为likearticle标签增加了完整的order by 属性
 
 
2.subday属性(标签获取subday指定的最近几天的数据
同样先获得subday 的属性值
$subday=$ctag->GetAtt('subday');
然后做时间差计算
if($subday > 0)
   {
    $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
    $limitday = $ntime - ($subday * 24 * 3600);
    $subdaysql = " and arc.senddate > $limitday ";
   }
然后在标签源码的两处sql查询语句中 增加$subdaysql子句判断
第一处为:
$query = "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 `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id
            where arc.arcrank>-1 and ($keyword) $typeid $orderquery limit 0, $row";
修改为:
$query = "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 `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id
            where arc.arcrank>-1 and ($keyword) $typeid $subdaysql $orderquery limit 0, $row";
第二处为:
$query = "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 `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id
           where arc.arcrank>-1 and $typeid $orderquery limit 0, $row";
修改为:
$query = "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 `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id
           where arc.arcrank>-1 and $typeid $subdaysql $orderquery limit 0, $row";
做完以上更改就为likearticle标签增加了subday属性
 
 
3.修改后完整版的likearticle.lib.php代码
 
以下为修改完之后的likearticle.lib.php的完整代码(增加了 orderby 和 subday 属性)
 
以下的代码可以直接复制,另存为likearticle.lib.php,直接覆盖即可使用.   使用范围:dedecmsv56
<?php
 
if(!defined('DEDEINC')) exit('Request Error!');
 
function lib_likearticle(&$ctag,&$refObj)
{
global $dsql;
 
//属性处理
$attlist="row|12,titlelen|28,infolen|150,col|1,tablewidth|100,mytypeid|0,byabs|0,imgwidth|120,imgheight|90";
FillAttsDefault($ctag->CAttribute->Items,$attlist);
extract($ctag->CAttribute->Items, EXTR_SKIP);
$revalue = '';
$orderby = $ctag->GetAtt('orderby');
$orderWay=$ctag->GetAtt('orderway');
 
$subday=$ctag->GetAtt('subday');
           if($subday > 0)
   {
    $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
    $limitday = $ntime - ($subday * 24 * 3600);
    $subdaysql = " and arc.senddate > $limitday ";
   }
if(empty($tablewidth)) $tablewidth = 100;
if(empty($col)) $col = 1;
$colWidth = ceil(100/$col);
$tablewidth = $tablewidth."%";
$colWidth = $colWidth."%";
 
$ids = array();
$tids = array();
 
if(!empty($refObj->Fields['tags'])) {
   $keyword = $refObj->Fields['tags'];
}
else {
   $keyword = ( !empty($refObj->Fields['keywords']) ? $refObj->Fields['keywords'] : '' );
}
 
$typeid = ( !empty($mytypeid) ? $mytypeid : 0 );
if(empty($typeid))
{
    if(!empty($refObj->Typelink->TypeInfos['reid'])) {
     $typeid = $refObj->Typelink->TypeInfos['reid'];
    }
    else {
     if(!empty($refObj->Fields['typeid'])) $typeid = $refObj->Fields['typeid'];
    }
}
 
if( !empty($typeid) && !ereg(',', $typeid) ) {
    $typeid = GetSonIds($typeid);
}
 
$limitRow = $row - count($ids);
$keyword = '';
if(!empty($refObj->Fields['keywords']))
{
    $keywords = explode(',' , trim($refObj->Fields['keywords']));
    $keyword = '';
    $n = 1;
    foreach($keywords as $k)
    {
     if($n > 3) break;
     
     if(trim($k)=='') continue;
     else $k = addslashes($k);
     
     $keyword .= ($keyword=='' ? " CONCAT(arc.keywords,' ',arc.title) like '%$k%' " : " OR CONCAT(arc.keywords,' ',arc.title) like '%$k%' ");
       $n++;
    }
}
$arcid = (!empty($refObj->Fields['id']) ? $refObj->Fields['aid'] : 0);
/*if( empty($arcid) || $byabs==0 ) {
   $orderquery = " order by arc.id desc "; 
}
else {
   $orderquery = " order by ABS(arc.id - ".$arcid.") ";
}*/
$orderquery = '';
if($orderby=='hot' || $orderby=='click') $orderquery = " order by arc.click $orderWay";
else if($orderby == 'sortrank' || $orderby=='pubdate') $orderquery = " order by arc.sortrank $orderWay";
else if($orderby == 'id') $orderquery = " order by arc.id $orderWay";
else if($orderby == 'near') $orderquery = " order by ABS(arc.id - ".$arcid.")";
else if($orderby == 'lastpost') $orderquery = " order by arc.lastpost $orderWay";
else if($orderby == 'scores') $orderquery = " order by arc.scores $orderWay";
else if($orderby == 'rand') $orderquery = " order by rand()";
else if($orderby == 'weight') $orderquery = " order by arc.weight asc";//如果没有特定设置排序则按照权重先排序
else $orderquery = " order by arc.sortrank $orderWay";
 
if($keyword != '')
{
    if(!empty($typeid)) {
       $typeid = " And arc.typeid in($typeid) And arc.id<>$arcid ";
    }
    $query = "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 `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id
            where arc.arcrank>-1 and ($keyword) $typeid $subdaysql $orderquery limit 0, $row";
}
else
{
    if(!empty($typeid)) {
      $typeid = " arc.typeid in($typeid) And arc.id<>$arcid ";
    }
   $query = "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 `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id
           where arc.arcrank>-1 and $typeid $subdaysql $orderquery limit 0, $row";
}
 
$innertext = trim( $ctag->GetInnerText() );
if($innertext=='') $innertext = GetSysTemplets('part_arclist.htm');
 
$dsql->SetQuery($query);
$dsql->Execute('al');
$artlist = '';
if($col > 1) {
   $artlist = "<table width='$tablewidth' border='0' cellspacing='0' cellpadding='0'>\r\n";
}
$dtp2 = new DedeTagParse();
$dtp2->SetNameSpace('field', '[', ']');
$dtp2->LoadString($innertext);
$GLOBALS['autoindex'] = 0;
$line = $row;
for($i=0; $i < $line; $i++)
{
   if($col>1) $artlist .= "<tr>\r\n";
   for($j=0; $j < $col; $j++)
   {
    if($col>1) $artlist .= " <td width='$colWidth'>\r\n";
    if($row = $dsql->GetArray("al"))
    {
     $ids[] = $row['id'];
     //处理一些特殊字段
     $row['info'] = $row['infos'] = cn_substr($row['description'],$infolen);
     $row['id'] = $row['id'];
 
     if($row['corank'] > 0 && $row['arcrank']==0)
     {
       $row['arcrank'] = $row['corank'];
     }
 
     $row['filename'] = $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['typeurl'] = GetTypeUrl($row['typeid'],$row['typedir'],$row['isdefault'],$row['defaultname'],$row['ispart'],
     $row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
 
     if($row['litpic'] == '-' || $row['litpic'] == '')
     {
      $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
     }
     if(!eregi("^http://",$row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
     {
      $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
     }
     $row['picname'] = $row['litpic'];
     $row['stime'] = GetDateMK($row['pubdate']);
     $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
     $row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".ereg_replace("['><]","",$row['title'])."'>";
     $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
     $row['fulltitle'] = $row['title'];
     $row['title'] = cn_substr($row['title'],$titlelen);
     if($row['color']!='') $row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";
     if(ereg('b',$row['flag'])) $row['title'] = "<strong>".$row['title']."</strong>";
     $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
     $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
     $row['memberurl'] = $GLOBALS['cfg_memberurl'];
     $row['templeturl'] = $GLOBALS['cfg_templeturl'];
    
     if(is_array($dtp2->CTags))
     {
      foreach($dtp2->CTags as $k=>$ctag)
      {
       if($ctag->GetName()=='array') {
        $dtp2->Assign($k,$row);
       }
       else {
        if(isset($row[$ctag->GetName()])) $dtp2->Assign($k,$row[$ctag->GetName()]);
        else $dtp2->Assign($k,'');
       }
      }
      $GLOBALS['autoindex']++;
     }
 
     $artlist .= $dtp2->GetResult()."\r\n";
    }
    //if hasRow
    else
    {
     $artlist .= '';
    }
    if($col>1) $artlist .= " </td>\r\n";
   }
   //Loop Col
   if($col>1) $i += $col - 1;
   if($col>1) $artlist .= " </tr>\r\n";
}
//loop line
if($col>1) $artlist .= " </table>\r\n";
$dsql->FreeResult("al");
return $artlist;
}
?>

  • quote 1.babystroller 2011/2/23 23:45:10 
  • 代码代码,少一点还好,一多眼睛就开始花,悲哀。。。
    回复该留言

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

韩日性爱视频

免责声明: 本站资料及图片来源互联网文章,本网不承担任何由内容信息所引起的争议和法律责任-|。所有作品版权归原创作者所有-|,与本站立场无关,如用户分享不慎侵犯了您的权益-|,请联系我们告知,我们将做删除处理!