WB: Droplet: GetNewsHeads |
![PHP]() |
| Posted by BeA (KonTrax) on 25 May 2009 |
| Scripts >> PHP |
A simple droplet that generates linked headlines from a newsgroup.
USAGE : [[ GetNewsHeads?group=2&page=false&max=2&start_date=-3 day&stop_date=now&order=ASC ]]
group : the ID of the newsgroup you want to use * optional ("0" by default)
page : the ID of the newspage you want to use * optional ("false" by default)
max : max newspost headlines to collect * optional ("10" by default)
active : active/inactive (1/0) posts filter * optional ("1" by default)(false not supported)
start_date : earlyest newspost headlines to collect * optional ("-10 day" by default)
stop_date : latest newspost headlines to collect * optional ("now" by default)
order : Newest or Oldest posts first * optional ("ASC" or "DESC", "DESC" by default)
false :
When using "false" as a parameter that filter will ignore default value. This allowes to mix and get all.
example: ?group=false
Date examples:
now
- / +1 day
- / +1 week
- / +1 month
- / +1 year
- / +1 year 1 month 1 week 1 day
10 September 2000
next Thursday
last Monday
NEW! 20 May 2010 (use size 6 tabs in editor for best readability)
New Code :
if( !function_exists('doif') ){
function doif( $pre , $str , $strict=FALSE ){
if( !$strict ){
if( $str ) return $pre.$str;
}else{
if( !is_bool($strict) ){
if( $str!==$strict ) return $pre.$str;
}else{
if( $str!==FALSE ) return $pre.$str;
}
}
return NULL;
}
}
global $database, $wb;
$mod_query = $database->query(
"SELECT title, link, published_when"
." FROM ".TABLE_PREFIX."mod_news_posts"
." WHERE"
." active = ".
((isset($active)) ? $active : 1 )
.doif(" AND group_id = ",
((isset($group)) ? $group : 0 ),'false')
.doif(" AND published_when >= ",
((isset($start_date)) ? strtotime($start_date) : strtotime("-10 day") ))
.doif(" AND published_when <= ",
((isset($stop_date)) ? strtotime($stop_date) : strtotime("now") ))
.doif(" AND page_id = " ,
((isset($page)) ? $page : false ),TRUE)
.doif(" ORDER BY post_id ",
((isset($order)) ? $order : "DESC" ),'false')
.doif(" LIMIT ",
((isset($max)) ? $max : 10 ),'false')
);
$mod_list = "";
while ( $row = $mod_query->fetchRow() ){
$mod_list .= '<a href="'.WB_URL.PAGES_DIRECTORY.$row["link"].PAGE_EXTENSION.'">'.$row["title"].'</a><br>';
}
return $mod_list;
UPDATED CODE
20.05.10
ADDED :
page
active
=false (get all)
Old Code :
if ( !isset($max) ){ $max = 10; }
if ( !isset($start_date) ){ $start_date= "-10 day"; }
if ( !isset($stop_date) ){ $stop_date= "now"; }
if ( !isset($order) ){ $order= "DESC"; }
global $database, $wb;
$mod_query = $database->query("SELECT title, link, published_when FROM ".TABLE_PREFIX.
"mod_news_posts WHERE active='1' AND group_id = ".$group.
" AND published_when>=".strtotime($start_date).
" AND published_when<=".strtotime($stop_date).
" ORDER BY post_id ".$order." LIMIT ".$max);
$mod_list = " ";while ( $row =& $mod_query->fetchRow()){
$mod_list .= '<a href="'.WB_URL.PAGES_DIRECTORY.$row["link"].PAGE_EXTENSION.'">'.$row["title"].'</a><br>';
}
return $mod_list;
UPDATED CODE
03.05.09
ADDED :
start_date
stop_date
order
Last changed: 07 Sep 2010 at 11:48
Back
Comments
Add Comment