Droplet : Header links for a newsgroup

KonTrax

Thanks, good to hear.

I hope i'ts an easy read. Implemented my doif() function for max readability. btw, recommend size 6 tabs in editor
Once you go Droplets you never go back


KonTrax

Quote from: SickBoy75 on May 20, 2010, 11:50:33 AM
nice work, but i needed more...

What if you have more than one news page in a web??
I have 3 in mine, so i needed to list the news form every page, but in diferent places.

Yeah, i know i can use groups, but it's not exactlly the same.

BTW, it was so easy to modify that i couldn't resist, jejeje

If you like this, just say thanks.

Thanx.

I just rewrote the hole thing with the page and some other small filter features.
Once you go Droplets you never go back

SickBoy75

nice work, but i needed more...

What if you have more than one news page in a web??
I have 3 in mine, so i needed to list the news form every page, but in diferent places.

Yeah, i know i can use groups, but it's not exactlly the same.

BTW, it was so easy to modify that i couldn't resist, jejeje

this is how i did it:
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";    }
$txt_search="";
if ( isset($pageid) ){    $txt_search= " AND page_id=".$pageid;    }
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).
$txt_search.
" 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;


A new param is added, pageid, it's the ID of the news page you want to show.
It's optional, if not used nothing happends

This is what i add
$txt_search="";
if ( isset($pageid) ){    $txt_search= " AND page_id=".$pageid;    }

.....
" AND published_when<=".strtotime($stop_date).
$txt_search.


$txt_search do the trick, it's blank if no pageid is set.

If you like this, just say thanks.

dbs

group_id=0 display a white page...

removing groups works better for me ;-) thx
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]

Ruud

The group "No Group" is group_id = 0,
Removing the group from the query would use "All groups".
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

dbs

hello,
my news aren't in groups.
how ist the call?
or must delete the part in the droplet: AND group_id = ".$group."   ?

dbs
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]

KonTrax

Once you go Droplets you never go back

LordDarkman

I think I found a "workaround". My new call is [[GetNewsHeads?group=2&max=10&start_date=-90 day&stop_date=+0&order=ASC]] This way it skips the old News. Can someone please test this to so we can change the droplet?
Just try stop_date=now and stop_date=+0

Thanks Moritz

LordDarkman

I've a small problem with the droplet. My call is [[GetNewsHeads?group=2&max=10&start_date=-90 day&stop_date=now&order=ASC]] The droplet 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 published_until ".$order." LIMIT ".$max);
$mod_list = " ";

while ( $row =& $mod_query->fetchRow()){

  $mod_list .= '**** N E W S ****';
  $mod_list .= '<a href="'.WB_URL.PAGES_DIRECTORY.$row["link"].PAGE_EXTENSION.'">'.$row["title"].'</a>';

}
return $mod_list.'**** N E W S ****';
Only thing I changed is ORDER BY. But it displays news wich are not active. We use it to publish stream times at a webradio and I wand the news to disapear after Date is over.
When I hit on a not active News it shows me
QuoteKein aktiver Inhalt auf dieser Seite vorhanden

Zurück
and the Droplet code is visibel. Can someone tell me how to change this?
Link to page http://gatesofdoom.de/

CU Moritz

Ruud

[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

KonTrax

New features added. Ready for library update Ruud.

Information about the update in main post
Once you go Droplets you never go back

KonTrax

Quote from: Ruud on May 01, 2009, 11:56:33 PM
Now it actually should have an additional test for the optional start_date / end_date.  :-P
That would make it perfect.

Ruud

I'm on it
Once you go Droplets you never go back

Ruud

I updated the library after changing it a bit again  8-)

The first test ($i < $max) would give a notice that $max is not existing.
So I switched the tests for $max. Working without errors/notices now.

Also another notice was given about the $mod_list that was not initialized.
I added a $mod_list = '';

Now it actually should have an additional test for the optional start_date / end_date.  :-P
That would make it perfect.

Ruud
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

KonTrax

I found a bug in my Droplet

New code is updated.

Ruud could you update it in the library?
Once you go Droplets you never go back

Ruud

Quote from: KonTrax on May 01, 2009, 03:50:11 PM
BTW Ruud, The Library says Example Call : [[[[GetNewsHeads?group=2&max=2]]]]
Fixed..
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

KonTrax

#6
Quote from: Ruud on May 01, 2009, 03:38:51 PM
I updated the Droplet in the library.
It is now using $i < $ max again but the query has an extra WHERE clause to select only active items.

Ruud

Of course.. active items, totaly forgot that! Thanks god that someone though of it

BTW Ruud, The Library says Example Call : [[[[GetNewsHeads?group=2&max=2]]]]
Once you go Droplets you never go back

Ruud

You're right.
I was put on a wrong track a bit because I was testing with group=0 (no group)
In that group there is an empty record (created by the installer) that was included but, since there is no title, wasn't displayed.

I updated the Droplet in the library.
It is now using $i < $ max again but the query has an extra WHERE clause to select only active items.

Ruud
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

KonTrax

Quote from: Ruud on May 01, 2009, 11:36:08 AM
Hi KonTrax,

Nice to see a first time user contribute to the Droplet library.
It is a nice idea too..

I made a few changes to your original Droplet.

1. The Max value was interpreted with one line less than it should. (< $max is now <= $max)
2. The url was not built correctly. WB_PATH was used, it should be WB_URL.
Also the /pages/ and the .php extention can be modified in WB. It is better to use the defined constants PAGES_DIRECTORY and PAGE_EXTENSION to build the correct url.

Thanks.

Just to mention, the $max starts at 0 so <= will give you one header more than you ask for.
Once you go Droplets you never go back

Ruud

Hi KonTrax,

Nice to see a first time user contribute to the Droplet library.
It is a nice idea too..

I made a few changes to your original Droplet.

1. The Max value was interpreted with one line less than it should. (< $max is now <= $max)
2. The url was not built correctly. WB_PATH was used, it should be WB_URL.
Also the /pages/ and the .php extention can be modified in WB. It is better to use the defined constants PAGES_DIRECTORY and PAGE_EXTENSION to build the correct url.

global $database, $wb;
$mod_query = $database->query("SELECT title, link FROM ".TABLE_PREFIX."mod_news_posts WHERE group_id = ".$group);

$i = 0;
while ($row =& $mod_query->fetchRow() && $i <= $max) {
$i++;

// To change how the links are presented, have fun with this variable
     $mod_list .= '<a href="'.WB_URL.PAGES_DIRECTORY.$row["link"].PAGE_EXTENSION.'">'.$row["title"].'</a><br>';

}

return $mod_list;


No need to submit the Droplet using the Form.  :-D
It is added on this page.

Ruud
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

erpe0812

Hi

please send it with this form and let the droplet get part of the official library.

rgds

erpe

KonTrax

#1
I guess you allready have a lot of scripts like this one.
Just 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)

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)



The 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
Once you go Droplets you never go back