获取指定条件的日志函数 for EMLOG

简爱代码>PHP2013-7-23 9:10782917

获取指定条件的日志函数 for EMLOG

获取指定条件的日志

主要方便主题、插件作者 中的新手 写的自定义函数  (老手勿喷)

可以按照分类、标签、作者、日期、日期段、置顶、含附件日志

 

 sort 获取指定 '分类' 的日志 
  JA_EM_LogList('sort', '代码', 10, 1); 获取 分类名 为 < 代码 > 的日志 10 篇  第 1 页
  JA_EM_LogList('sort', '代码', 20); 获取 分类名 为 < 代码 > 的日志 20 篇
 tag 获取指定 '标签' 的日志 
  JA_EM_LogList('tag', 'EMLOG'); 获取 标签名 为 < EMLOG > 的日志
   (日志条数 $sum 缺省 10, 默认 10 篇日志)
 user 获取指定 '用户' 的日志 
  JA_EM_LogList('user', '简爱'); 获取 用户名 为 < 简爱 > 的日志
 date 获取指定 '日期/日期范围内' 的日志 
  JA_EM_LogList('date', '20121202'); 获取 日期为 为 < 2012年12月2日 > 的日志
   日期可以为 标准 8 位年月日  如:20121202
   日期可以为 以 - 分割的日期  如:2012-12-02 或 2012-2-02
  JA_EM_LogList('date', '2012-12-1|2012-12-3'); 获取 日期为 为 < 2012年12月1日 至 2012年12月3日 > 的日志
 key 获取指定 '关键字' 的日志 (同日志搜索功能)
  JA_EM_LogList('key', '简爱'); 列出 以 < 简爱 > 为关键字 搜索到的日志
 top 获取 '置顶' 的日志 
  JA_EM_LogList('top', , 11); 获取 < 置顶 > 的日志 11 篇  (注意 不需要的参数留空)
 att
获取 '含有附件' 的日志


JA_EM_LogList('att');
获取 < 含有附件 > 的日志




JA_EM_LogList();
获取最新的 日志 10 篇

JA_EM_LogList( , , 0);
获取所有日志

注:以上全部函数,日志条数$sum设置为0

将输出全部符合条件的日志


 

 

 PHP 代码  下一页

 

<?php

/**
 * $name   获取日志类型
 * $data   指定参数
 * $sum    日志数量
 * $page   页数
**/
function JA_EM_LogList($name, $data, $sum=10, $page=1){
  global $CACHE;
  $Log_Model = new Log_Model();
  $name = strtolower($name);

  if($name == 'sort'){                // 分类日志
    $Sorts = $CACHE->readCache('sort');
    foreach($Sorts as $k => $v){
      if($v['sortname'] == $data){$sortid = $k; break;}
    }
    $sqlSegment =  "and sortid=$sortid order by date desc";
  }elseif($name == 'tag'){            // 标签日志
    $Tag_Model  = new Tag_Model();
    $blogIdStr  = $Tag_Model->getTagByName($data);
    $sqlSegment = "and gid in ($blogIdStr) order by date desc";
  }elseif($name == 'user'){           // 用户日志
    $Users = $CACHE->readCache('user');
    foreach($Users as $k => $v){
      if($v['name'] == $data){$author_id = $k; break;}
    }
    $sqlSegment = "and author=$author_id order by date desc";
  }elseif($name == 'date'){           // 指定 日期 / 日期内 日志
    $data = strtr($data,array('年'=>'-', '月'=>'-', '日'=>''));
    $date = explode('|',$data);
    if(isset($date[1])){
      $record_stime = emStrtotime($date[0]);
      $record_etime = emStrtotime($date[1]) + 3600 * 24;
    }else{
      $record_stime = emStrtotime($data);
      $record_etime = $record_stime + 3600 * 24;
    }
    $sqlSegment = "and date>=$record_stime and date<$record_etime order by top desc ,date desc";
  }elseif($name == 'key'){            // 搜索日志
    $keyword = addslashes(htmlspecialchars(urldecode($keyword)));
    $keyword = str_replace(array('%', '_'), array('\%', '\_'), $keyword);
    $sqlSegment = "and title like '%{$keyword}%' order by date desc";
  }elseif($name == 'top'){            // 置顶日志
    $sqlSegment = "and top='y' order by date desc";
  }elseif($name == 'att'){            // 含有附件日志
    $sqlSegment = "and attnum>0 order by date desc";
  }else{                              // 全部日志
    $sqlSegment = "order by top desc ,date desc";
  }
  return $JA_log_list = $Log_Model -> getLogsForHome($sqlSegment, $page, $sum);
}




require_once './init.php'; // 用作插件 或 模板内部时 请删除本行


// 打印 2013年1月1日 至 2013年7月23日 之间的所有日志
print_r(JA_EM_LogList('date', '2013-1-1|2013-7-23', 0));

// 打印 作者:《简爱》的日志 10 篇
print_r(JA_EM_LogList('user', '简爱'));


本文出自简爱博客,转载时请注明出处及相应链接。

评论

  1. miss2014-12-03 17:48回复

    来看代码的

  2. Veris2014-11-14 12:26回复

    (⊙o⊙)…我是来看代码的。

  3. 90fuli2014-11-13 23:50回复

    看下代码

  4. 担保行业报告2014-03-10 11:52回复

    写的挺不错的 谢谢博主分享

  5. 简爱2013-10-13 03:33回复

    {JA_face:8}

  6. 茅屋网2013-08-17 23:27回复

    你这篇日志 显示不全啊,方便的话,可否邮件分享一下,不胜感激    yhxseu@126.com

  7. 黎健雄2013-07-23 09:14回复

    留名闪人。

    1. 简爱2013-07-23 09:17回复

      @黎健雄:汗  你这是不是 有什么 监控插件?

      1. 黎健雄2013-07-23 09:18回复

        @简爱:chrome.google.com/webstore/detail/rss-feed-reader/pnjaodmkngahhkoihejjehlcdlnohgmp我丢。。中文中文、。

      2. 简爱2013-07-23 09:22回复

        @黎健雄:RSS 订阅插件  你这也是有时间上网

      3. 黎健雄2013-07-23 09:23回复

        @简爱:放暑假你说有没有时间。
        现在在码日记。

发表评论

电子邮件地址不会被公开。必填项已用*标注