Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
May 25, 2012, 11:35:18 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter
hier
und auf unserer
neuen Webseite
.
155500
Posts in
21710
Topics by
7736
Members
Latest Member:
deenangle
WebsiteBaker Community Forum
English
Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
(Moderator:
Argos
)
Droplet : Header links for a newsgroup
Pages: [
1
]
Go Down
Author
Topic: Droplet : Header links for a newsgroup (Read 3298 times)
KonTrax
Offline
Posts: 21
Droplet : Header links for a newsgroup
«
on:
May 01, 2009, 04:11:37 AM »
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)
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)
The old code
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 Edit: September 07, 2010, 12:50:16 PM by KonTrax
»
Logged
Once you go Droplets you never go back
erpe
Offline
Posts: 2077
Re: Droplet : Header links for a newsgroup
«
Reply #1 on:
May 01, 2009, 09:58:28 AM »
Hi
please send it with
this form
and let the droplet get part of the official library.
rgds
erpe
Logged
stories about
be part of the Tutorials-Project
visit the jQuery-Showroom
Ruud
WebsiteBaker Org e.V.
Online
Posts: 2295
Re: Droplet : Header links for a newsgroup
«
Reply #2 on:
May 01, 2009, 10: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.
Code:
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.
It is added on
this page
.
Ruud
Logged
Professional WebsiteBaker Solutions
KonTrax
Offline
Posts: 21
Re: Droplet : Header links for a newsgroup
«
Reply #3 on:
May 01, 2009, 02:16:24 PM »
Quote from: Ruud on May 01, 2009, 10: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.
Logged
Once you go Droplets you never go back
Ruud
WebsiteBaker Org e.V.
Online
Posts: 2295
Re: Droplet : Header links for a newsgroup
«
Reply #4 on:
May 01, 2009, 02:38:51 PM »
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
Logged
Professional WebsiteBaker Solutions
KonTrax
Offline
Posts: 21
Re: Droplet : Header links for a newsgroup
«
Reply #5 on:
May 01, 2009, 02:50:11 PM »
Quote from: Ruud on May 01, 2009, 02: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]]]]
«
Last Edit: May 01, 2009, 02:52:53 PM by KonTrax
»
Logged
Once you go Droplets you never go back
Ruud
WebsiteBaker Org e.V.
Online
Posts: 2295
Re: Droplet : Header links for a newsgroup
«
Reply #6 on:
May 01, 2009, 03:01:35 PM »
Quote from: KonTrax on May 01, 2009, 02:50:11 PM
BTW Ruud, The Library says Example Call : [[[[GetNewsHeads?group=2&max=2]]]]
Fixed..
Logged
Professional WebsiteBaker Solutions
KonTrax
Offline
Posts: 21
Re: Droplet : Header links for a newsgroup
«
Reply #7 on:
May 01, 2009, 05:39:34 PM »
I found a bug in my Droplet
New code is updated.
Ruud could you update it in the library?
Logged
Once you go Droplets you never go back
Ruud
WebsiteBaker Org e.V.
Online
Posts: 2295
Re: Droplet : Header links for a newsgroup
«
Reply #8 on:
May 01, 2009, 10:56:33 PM »
I updated the library after changing it a bit again
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.
That would make it perfect.
Ruud
Logged
Professional WebsiteBaker Solutions
KonTrax
Offline
Posts: 21
Re: Droplet : Header links for a newsgroup
«
Reply #9 on:
May 03, 2009, 05:49:11 PM »
Quote from: Ruud on May 01, 2009, 10:56:33 PM
Now it actually should have an additional test for the optional start_date / end_date.
That would make it perfect.
Ruud
I'm on it
Logged
Once you go Droplets you never go back
KonTrax
Offline
Posts: 21
Re: Droplet : Header links for a newsgroup
«
Reply #10 on:
May 03, 2009, 08:29:48 PM »
New features added. Ready for library update Ruud.
Information about the update in main post
Logged
Once you go Droplets you never go back
Ruud
WebsiteBaker Org e.V.
Online
Posts: 2295
Re: Droplet : Header links for a newsgroup
«
Reply #11 on:
May 03, 2009, 10:53:33 PM »
Nice work,
It is updated in the
Official Droplet Library
Ruud
Logged
Professional WebsiteBaker Solutions
LordDarkman
Development Team
Offline
Posts: 343
Re: Droplet : Header links for a newsgroup
«
Reply #12 on:
October 25, 2009, 02:30:02 AM »
I've a small problem with the droplet. My call is
Code:
[[GetNewsHeads?group=2&max=10&start_date=-90 day&stop_date=now&order=ASC]]
The droplet code
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
Quote
Kein 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
Logged
LordDarkman
Development Team
Offline
Posts: 343
Re: Droplet : Header links for a newsgroup
«
Reply #13 on:
October 25, 2009, 06:40:01 PM »
I think I found a "workaround". My new call is
Code:
[[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
Logged
KonTrax
Offline
Posts: 21
Re: Droplet : Header links for a newsgroup
«
Reply #14 on:
November 13, 2009, 03:14:35 PM »
I'm looking in to it
Logged
Once you go Droplets you never go back
dbs
WebsiteBaker Org e.V.
Offline
Posts: 3714
Re: Droplet : Header links for a newsgroup
«
Reply #15 on:
April 12, 2010, 05:32:33 PM »
hello,
my news aren't in groups.
how ist the call?
or must delete the part in the droplet: AND group_id = ".$group." ?
dbs
Logged
Ruud
WebsiteBaker Org e.V.
Online
Posts: 2295
Re: Droplet : Header links for a newsgroup
«
Reply #16 on:
April 13, 2010, 10:26:43 AM »
The group "No Group" is group_id = 0,
Removing the group from the query would use "All groups".
Logged
Professional WebsiteBaker Solutions
dbs
WebsiteBaker Org e.V.
Offline
Posts: 3714
Re: Droplet : Header links for a newsgroup
«
Reply #17 on:
April 13, 2010, 10:37:19 AM »
group_id=0 display a white page...
removing groups works better for me
thx
Logged
SickBoy75
Offline
Posts: 16
Re: Droplet : Header links for a newsgroup
«
Reply #18 on:
May 20, 2010, 10: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
this is how i did it:
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"; }
$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
Code:
$txt_search="";
if ( isset($pageid) ){ $txt_search= " AND page_id=".$pageid; }
.....
Code:
" 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.
Logged
KonTrax
Offline
Posts: 21
Re: Droplet : Header links for a newsgroup
«
Reply #19 on:
May 20, 2010, 05:03:35 PM »
Quote from: SickBoy75 on May 20, 2010, 10: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.
Logged
Once you go Droplets you never go back
SickBoy75
Offline
Posts: 16
Re: Droplet : Header links for a newsgroup
«
Reply #20 on:
May 20, 2010, 07:05:43 PM »
I like the new code!!!
Logged
KonTrax
Offline
Posts: 21
Re: Droplet : Header links for a newsgroup
«
Reply #21 on:
May 20, 2010, 09:56:26 PM »
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
Logged
Once you go Droplets you never go back
Pages: [
1
]
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
=> Security Announcements
=> Documentation
=> WebsiteBaker Website Showcase
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
=====> Modules / Extensions
===> Suggestions
===> Software bugs
=> Help & Support
=> Modules
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
=> jQuery
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
=> Archive (posts up to 2007)
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
=====> Module / Extensions
===> Vorschläge
===> Softwarefehler
===> Erfahrungs und Testberichte
=> Hilfe/Support
=> Module & Snippets
=> Templates & Design
=> Tutorials
=> jQuery
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...