Droplet -> Generate_Calender

WebBird

#28
I tried with 2.7 and can confirm that. Seems to be a bug in the Droplets module.

Edit: Found this in line 59 of the droplets.php:


$content = stripslashes($fetch_content['code']);


Droplets 1.0.1 (WB 2.8 ) does this:


$codedata = ($fetch_content['code']);


So, the problem is caused by the droplets module. There are two ways to get around it:

* Remove all \-thingies from droplet codes (ALL droplet codes!)
* Correct the Droplets module (remove "stripslashes" in line 59)

But, I think the best way is: Upgrade to 2.8!

pcwacht

The \n only generates a linebreak in your html source, not in your output on your screen.
It is only there for source reading purposes

It is safe to delete them all.

Have fun,
John
[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....

tiesy

OK, I found out one thing (and yes, with your code not opened with Word, WebBird! ):

on a WB2.7-installation (online) the "n"s are shown.
on a WB2.8-installation (xampp) there are no "n"s. Everything is right there 

Where is the problem, deleting all "\n" in the calendar_droplet.php? Without them, it works in 2.7 and 2.8


WebBird

Here's the code as a download. Open with your favourite text editor (not Word...) and paste as a droplet. I added some comments that may help.



global $wb, $database;

// --- config options; you may change these ---
// day names length; values > 3 = full name
$day_name_length = 3;
// first day of week; 0 = Sunday, 1 = Monday
$first_day       = 0;
// set locale to the value you need
// set to NULL to use the OS setting -> $locale = NULL;
$locale          = 'de_DE';

// --- do not change these! ---
$month_href      = NULL;
$pn              = array(); // array for prev/next links; they don't work
                            // in this droplet, so don't add anything!
$days            = array();

if ( isset( $locale ) ) {
    // store old locale
    $oldlocale = setlocale(LC_TIME, NULL); #save current locale
    setlocale( LC_TIME, $locale );
}

// year and month defaults
if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };

// Get Events from "Event Calendar" Module (1.8c)
$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month'";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
        }
        else {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'>".$row['day']."</span>" );
        }
    }
}

$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

if ( isset( $oldlocale ) ) {
    // reset locale
    setlocale(LC_TIME, $oldlocale);
}

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)).'&nbsp;'.$year;  #note that some locales don't capitalize month and day names

#Begin calendar. Uses a real <caption>. 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 = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>&nbsp;';
if($n) $n = '&nbsp;<span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table class="calendar">'."\n".
   '<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";

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 .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
   $calendar .= "</tr>\n<tr>";
}

if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'">&nbsp;</td>'; #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 .= "</tr>\n<tr>";
   }
   if(isset($days[$day]) and is_array($days[$day])){
      @list($link, $classes, $content) = $days[$day];
      if(is_null($content))  $content  = $day;
      $calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
         ($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
   }
   else $calendar .= "<td>$day</td>";
}
if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>'; #remaining "empty" days

return $calendar."</tr>\n</table>\n";



[gelöscht durch Administrator]

WebBird

They only work if the $pn array is filled. In my code, it isn't.

Stefek

Hello Tiesy.
Prev-Next Links won't work with this droplet.

It's not applicable, so WebBird didn't use them..

Regards,
Stefek
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

tiesy

Ah, and what about these lines in your reply #9 ?

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable

..and so on

WebBird

I did not provide prev/next, so it's not my code you copied. :roll:

tiesy

#20
I do have backslashes, believe me and of course there are prevs and next-links.

The last "n" after the calendar-table disappears, if I delete the last "\n" in the last line of your code:

return $calendar."</tr>\n</table>\n";

changed to:

return $calendar."</tr>\n</table>";

I´m shure, there must be a mistake in the code. Some code-parts do not execute.

OK, I´ve to learn php first. If I´ve found the solution in about two years, I´ll post it here :wink:


My first dirty "solution": Delete all "\n" in the code. It works!

WebBird

Look at the very last line of the droplet code. It should look like this:

return $calendar."</tr>\n</table>\n";

Note the Backslash before the n's. Make sure that you really really have Backslashes there!

WebBird

I have not provided any prev/next links in my code. :roll:

tiesy

The link-problem is solved, thank you very much, but I can´t handle the "n"-problem until yet. I´ve only copied the code to a new droplet without any changes. The prevs and next-links are missing and instead there are seven "n"s above the table-tag and one after the table.

I think, there must be a problem generating the output for the previous and next-links, because the span-tag are missing in the HTML-output. Could it be a little syntax-error between line 45 and 50 in the code?

My HTML-output starts like this:
<table class="calendar">n<caption class="calendar-month">November&nbsp;2009</caption>n<tr><th abbr="Sonntag">Son</th>

And these are the last tags:
<td>30</td><td colspan="5">&nbsp;</td></tr>n</table>n


I think, this droplet is very welcome by many users, because you can find a lot of WB-Sites with "Event Calendar 1.8c" in use.





WebBird

Quote from: tiesy on November 12, 2009, 06:35:06 PM
The only thing: The days with are not linked and I don´t know why.

They are linked only if the Event entry has a link. You may change this code:


if ( $result->numRows() > 0 ) {
   while( $row = $result->fetchRow() ) {
       if ( ! empty( $row['url'] ) ) {
           $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
       }
       else {
           $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'>".$row['day']."</span>" );
       }
   }
}


In the else, the day is highligted only, but not linked, as there is no link in the Event entry. So, just add a <a href> that links to your events page. Example:


if ( $result->numRows() > 0 ) {
   while( $row = $result->fetchRow() ) {
       if ( ! empty( $row['url'] ) ) {
           $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
       }
       else {
           $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='http://...../'>".$row['day']."</a></span>" );
       }
   }
}


Edit: As of the n's, I think pcwacht is right.

pcwacht

The n's

Not sure but I think:
Make sure IN your droplet the \n exists and not just a n
Look at the code above to see where they are.

Have fun
John
[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....

tiesy

Hey WebBird,

your Generate_Calender-mod for the Event Calendar is very welcome and useful. Many thanks for that. It shows the actual Month and the right days with events are marked correct with a red square.
The only thing: The days with are not linked and I don´t know why. I tried to understand the code, but I´m not a programmer, so I didn´t find, how to solve this. For me, it would be sufficient, when it links to the site, where the Event Calendar is.

Second thing: I don´t know, where the "nnnnnn" comes form (see screenshot). I think, there should be shown prev and next-links. Is that right?

 

[gelöscht durch Administrator]

WebBird

Hint: The droplet code above extracts events from any page the event calendar module is included. To give a certain page/section, try to change the SQL to this:


$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE section_id = '###' AND YEAR(date) = '$year' AND MONTH(date) = '$month'";


Replace ### with the section_id you wish to use.

WebBird

I think this is already possible. Try [[HoweverYouCalledThis?year=2009&month=5]]

Day is not useful for a month calendar sheet, I think. :-D

Edit: Default is current month, of course!

macsmet

@Webbird: this is nice!
Is it possible to make a link to: monthno=11&year=2009?
So to go to the month or even day?

Greetings,

MacSmet

WebBird

#10
I hacked this droplet to avoid some "undefined" errors and to retrieve event data from "Event Calendar 1.8c". The day is linked to the URL given at the event entry. I am going to extend this for events not having an URL. Done. :-D


global $wb, $database;

$days = array();
$day_name_length = 3;
$month_href = NULL;
$first_day = 0;
$pn = array();

$oldlocale = setlocale(LC_TIME, NULL); #save current locale
setlocale(LC_TIME, 'de_DE');

if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };

// Get Events from "Event Calendar" Module (1.8c)
$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month'";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
   while( $row = $result->fetchRow() ) {
       if ( ! empty( $row['url'] ) ) {
           $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
       }
       else {
           $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'>".$row['day']."</span>" );
       }
   }
}

$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
 
// reset locale
setlocale(LC_TIME, $oldlocale);

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)).'&nbsp;'.$year;  #note that some locales don't capitalize month and day names

#Begin calendar. Uses a real <caption>. 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 = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>&nbsp;';
if($n) $n = '&nbsp;<span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table class="calendar">'."\n".
  '<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";

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 .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
  $calendar .= "</tr>\n<tr>";
}

if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'">&nbsp;</td>'; #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 .= "</tr>\n<tr>";
  }
  if(isset($days[$day]) and is_array($days[$day])){
     @list($link, $classes, $content) = $days[$day];
     if(is_null($content))  $content  = $day;
     $calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
        ($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
  }
  else $calendar .= "<td>$day</td>";
}
if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>'; #remaining "empty" days

return $calendar."</tr>\n</table>\n";

WebBird

You will have to pull the entries from the database by yourself.

AR1306

Is there any way to automatically generate links from the entries in the eventcal or news module ... that it would be in my opinion.  :wink:

But for the first it´s a cool Droplet ...

pcwacht

Dunnoh how to get it IN the dropletcall, dunnoh how to add arrays in a parameter call like the droplet uses

To do it inside the droplet you should create some code to create the days array

Something like this, add it in the beginning of the droplet to test it:

<?php
global $wb$database;
if (
PAGE_ID>0) {
  
$days = array();
  
$query $database->query("SELECT modified_when, link,page_title FROM ".TABLE_PREFIX."pages order by modified_when desc limit 5");
  while(
$mod_page=$query->fetchRow()){
    
$mod_day date("j"$mod_page['modified_when']);
    
$weblink=$mod_page['link'];
    
$webtitle $mod_page['title'];
    
$days[$mod_day] = array($weblink,'linked-day'); 
  }  
}    
asort($days);

This will give you a calender with links to pages on the day they are modified.

It would be easier if the droplet was a snippet instead. Then you could fill the $days array and call the function.


Thsi bit Add

Code:
<?php
if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };
right at the beginning to show current month by default

Was NO answer to your question ;)
But a better use of calender.

Have fun,
John
[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....

WebBird

You just put them into a $days Array.

Example taken from http://keithdevens.com/software/php_calendar#examples

<?php
    $days 
= array(
        
2=>array('/weblog/archive/2004/Jan/02','linked-day'),
        
3=>array('/weblog/archive/2004/Jan/03','linked-day'),
        
8=>array('/weblog/archive/2004/Jan/08','linked-day'),
        
22=>array('/weblog/archive/2004/Jan/22','linked-day'),
        
26=>array(NULL,'linked-day textual','twenty-six'),
    );
?>




The first param is the link url, the second one is a CSS class. There's also an optional third param to set a content (default is current day number).

Stefek

Quote from: pcwacht on November 04, 2009, 12:00:22 PM
Add
<?php
if(!isset($year))  {$year  date('Y'time()); };
if(!isset(
$month)) {$month date('n'time()); };

right at the beginning to show current month by default


Have fun,
John
Hello John,
I think you didn't get my question :-D

I meant in the fourth example there are links on dates.
Is there any way to specify links like this?

Regards,
Stefek
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

AR1306

#4
WOW - a cool Droplet, but ...

I have the same question just like Stefek - Is there any way to get this feature.

Thanks - you are one of the best  :wink:

Andreas