Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: [MOD/ADDON] sNews Calendar (Help Needed)  (Read 7618 times)

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
[MOD/ADDON] sNews Calendar (Help Needed)
« on: February 18, 2007, 09:21:15 PM »

I'll never be tired of saying that sNews rocks, but lack of the calendar function makes me sad sometimes.

Here's what I would like to implement:

1. A simple PHP calendar function (generated as a table), taken from the net with the ability to cycle through months with <<<< and >>>> links.

2. MySQL lookup part of the code, which checks currently shown calendar month (For example February - month № 02) and scans the DB for articles written on this month and gets their ID's.

3. Then another MySQL lookup code which would scan these selected ID's for the DATE (or day of the month) of the post.

4. Then at the end of the script another part of code would ECHO calendar rows one after another WITH or WITHOUT links for the numbers.

5a. Linked numbers (specific days) would send a GET command to the index.php, when clicked. another sNews function, for example, "function display_dated" (or maybe an addition to the CENTER function) would lookup the DB for ID's of the articles created on this specific date and output them to the CENTER.

5b. And month's name, if clicked, would make sNews return related articles.

So... I'm not a professonal php-programmer, and it's gonna take me a lot to write such an addon.
That's why I'm asking for your help. Together, we'll be able to finish this a lot faster and get fully functional calendar for sNews.

So. Whaddaya think?
--------------
UPDATED
--------------

DO NOT USE (yet)

This is modified search function. It looks for published articles DATES. (sent through the hidden form, for example). Form must send "date_query" query in correct form to match values stored in DB. Requests would be sent from our linked numbers.







//DATE SEARCH ENGINE
function date_search() {
/*
- date searching routine
*/
# cleaning query from malicious inputs
$date_query = clean(cleanXSS($_POST['date_query']));
# title
echo '

'.l(search_results).'

';
# minimum character length needed for search is 4, if less, display error note
if (strlen($date_query) < 4 || $date_query == l('search_keywords')) {echo '

'.l(charerror).'

';}
else {
# creating an array of keywords from the query
$keywords = explode(' ', $date_query);
# counting keywords
$keyCount = count($keywords);
# search is performed only on published articles (articles and pages and NOT extra contents)
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND published = 1 AND";
if ($keyCount > 1) {
/*
- if there's more than one keyword, repeat SQL routine
(searching for occurances in "title" or "text" columns of the "article" table)
*/
for ($i = 0; $i < $keyCount - 1; $i++) {$query = $query." (date LIKE '%$keywords[$i]%' &&";}
$j = $keyCount - 1;
$query = $query." (date LIKE '%$keywords[$j]%')";
}
# only one keyword in the query
else {$query = $query." (date LIKE '%$keywords[0]%')";}
$query = $query." ORDER BY id DESC";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
# sorry, no results are available for your query at the moment ;)
if (!$numrows) {echo '

'.l('noresults').' '.$date_query.'.

';}
else {
# no kiddin'?! we did find something after all :)
# display number of results
echo '

'.$numrows.' '.l('resultsfound').' '.$search_query.'.

';
while ($r = mysql_fetch_array($result)) {
# date format
$date = date(s('date_format'), strtotime($r['date']));
# display links to search results
echo '

'.$r['title'].' - '.$date.'

';
        }
}
}
# "back home" link
echo '


'.l('backhome').'

';
$searched = true;
}

?>
UPDATE 20/02/2007

Here's my example of presenting search results as ordinary articles (there is a lot of my DIVs in there, so... Jut an example to see where it goes):

Code: [Select]
# ------------------------

# display links to search results
# echo '

'.$r['title'].' - '.$date.'

';

# ----- HEADER -----
$categoryName = retrieve('name', 'categories', 'id', $r['category']);
echo '

';
echo ''.$r['title'].'

';
echo '';
echo '
';

# ------- CONTENT --------

$text = stripslashes($r['text']);
   $short_display = strpos($text, '[break]'); $shorten = $short_display == 0 ? 9999000 : $short_display;
echo '
';
file_include(str_replace('[break]', '', $text), $shorten);
echo '
';

# ------- INFOLINE -------
$comments_query = "SELECT * FROM ".db('prefix')."comments WHERE articleid = $r[id] AND approved = 'True'";
$comments_result = mysql_query($comments_query);
# find number of comments
$comments_num = mysql_num_rows($comments_result); $commentable = $r['commentable'];
$tag = explode(',', tags('infoline'));
$link = ' # admin only link
$edit_link = $link.'index.php?action=admin_article&id='.$r['id'].'" title="'.l('edit').' '.$r['title'].'">'.l('edit').'
';

foreach ($tag as $tag) {
switch (true) {
case ($tag == 'date'): echo $date; break;
case ($tag == 'readmore' && strlen($r['text']) > $shorten):
echo $link.$category.'/'.$r['seftitle'].'/" title="'.l('read_more').'">'.l('read_more').' '; break;
case ($tag == 'comments' && ($commentable == 'YES' || $commentable == 'FREEZ')):
echo $link.$category.'/'.$r['seftitle'].'/#'.l('comment').'1" title="'.l('comments').'">'.l('comments').': '.$comments_num.' '; break;
# edit link is visible only when logged in
case ($tag == 'edit' && $_SESSION[db('website').'Logged_In'] == token()): echo ' '.$edit_link; break;
case ($tag == 'views'): break;
case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #1 on: February 18, 2007, 09:41:57 PM »

SerpantiN,
In my site (http://snews.vietbee.net/) I'll try to add a calendar, too. I've used this code:
Code: [Select]
function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()){
$first_of_month = gmmktime(0,0,0,$month,1,$year);

#remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()

$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name

list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #note that some locales don't capitalize month and day names

#Begin calendar. Uses a real . See http://diveintomark.org/archives/2002/07/03
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = ''.($pl ? ''.$p.'' : $p).' ';
if($n) $n = ' '.($nl ? ''.$n.'' : $n).'';
$calendar = ''."\n".
'\n";

if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= '';
$calendar .= "\n";
}

if($weekday > 0) $calendar .= ''; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "\n";
}
if(isset($days[$day]) and is_array($days[$day])){
@list($link, $classes, $content) = $days[$day];
if(is_null($content))  $content  = $day;
$calendar .= '' : '>').
($link ? ''.$content.'' : $content).'';
}
else $calendar .= "
";
}
if($weekday != 7) $calendar .= ''; #remaining "empty" days
return $calendar."\n
'.$p.($month_href ? ''.$title.'' : $title).$n."
'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'
 
$day 
\n";
}
I call it into my index.php like this:
Code: [Select]
    $time = time();
    $oldlocale = setlocale(LC_TIME, NULL); #save current locale
    setlocale(LC_TIME, 'es_ES'); # Locale for Spain
    echo generate_calendar(date('Y', $time), date('n', $time), NULL, 3, NULL, 1);
    setlocale(LC_TIME, $oldlocale);
?>
I'm trying to adding links from the articles to the calendar day's...
Maybe you can use this code and share your progress with me to make a MOD.
Thanks,
bram.
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Español

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #2 on: February 18, 2007, 09:47:53 PM »

Sure, Bram. Glad you're interested too. I've updated the post with working (I hope) DATE search engine.

We need to make static (at least now, for future coding) calendar send a request with id="date_engine".
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #3 on: February 18, 2007, 09:50:07 PM »

I too have wanted a calendar "module" for sNews. I've looked at severl stand-alone php scripts but have not yet come across one I was willing to spend the time on.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #4 on: February 18, 2007, 10:19:14 PM »

Code needed to be put inside CENTER function to make the new one to work.

Code: [Select]
# search engine
case isset($_POST['search_query']): search(); return; break;
# NEW CODE
# date search engine
case isset($_POST['date_query']): date_search(); return; break;
Aaand yes! It works. Try querying smth like "2007-02-02" (Y-M-D). And see it for yourself.

Wow! Now try "2007-02" (Y-M) - we've got all articles for the month! Incredible!

Now to make it display results like usual CENTER call...
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #5 on: February 20, 2007, 10:03:02 AM »

Ok, I've made date search results look like ordinary short articles with infoline (if enabled in the article) and header. So, now all I need is to change
Code: [Select]
$_POST routineto:
Code: [Select]
$_GET routineso we could get rid of the form and use ordinary links in the calendar.

But to do this I need to modify PROCESSING inside the Center function...

And here I need help from Luka or Mika. if you could help guys...

EXAMPLE

You can see it working here: http://funnydays.ru/
To the left is another form. Try submitting "2007-02-18" for example to see it in work.
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #6 on: February 20, 2007, 12:15:10 PM »

There's no processing inside center()... or am I missing something? No database is present either...
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #7 on: February 20, 2007, 04:12:03 PM »

Quote from: Mika
There's no processing inside center()... or am I missing something? No database is present either...
Yes, it's outside of CENTER. Does it matter? =)

Something like http://website.com/date/2007-02-20/ is what I'm looking for. So I guess I'll have to add new identificator to the function processing "date" which will make it send the "2007-02-20" with GET to the date_search.

Am I right?

BTW. What's that about database?
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #8 on: February 20, 2007, 04:54:43 PM »

:D

Here't the thing: what we have now is date column, and a date added to SEF article (MOD) - which one of them would you like to include in your calendar?
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #9 on: February 20, 2007, 05:17:58 PM »

Quote from: Mika
:D

Here't the thing: what we have now is date column, and a date added to SEF article (MOD) - which one of them would you like to include in your calendar?
Date column, of course.

All I know is if I try to GET http://site.com/2007-02-20/ I'll get an error, 'cause sNews will lookup for the category with requested SEF.

It's like with "home" SEF - it's like command for sNews to cancel looking up the category and load home-related articles.

The same thing I'd like to implement with date SEF, which would make sNews go directly to date_search and send "2007-02-20" as a GET...

I can even see it functioning in my head =)
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
[MOD/ADDON] sNews Calendar (Help Needed)
« Reply #10 on: June 15, 2007, 11:59:36 AM »

mhm, also looking at this, hehe... read- looking at downloadable scripts. But like Key's I have not found any worth spending time on...

I want a calendar function to which I easily can add events, and that they show up like one of them cool tooltips, we've seen people post on the board... Nothing more ;)
Logged
"It's only dead fish that goes with the flow... "
Updated