Is there a Calendar Extension for PivotX?

Discuss PivotX 2.0.x extensions here, and view extensions that are available for download.

Re: Is there a Calendar Extension for PivotX?

Postby hansfn » Sun Jan 25, 2009 7:57 pm

Code: Select all
Okay, I found out that the function read_entries only works for mySQL and I have a flat database.

Very annoying, that flatfile and MySQL use different functions to read entries, right? So we have fixed it. All the getlist* functions are gone from the flatfile database and you can use read_entries for both database types. You better upgrade to beta 12g so you don't waste your time coding for the wrong API - http://pivotx.net/files/unstable-development/ (Note that the pivot folder has been renamed to pivotx.)
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Is there a Calendar Extension for PivotX?

Postby Kay » Sun Jan 25, 2009 9:26 pm

Okay, I got it to work now. Here's the updated code.

widget_calendar.php
Code: Select all
<?php
// - Extension: Calendar
// - Version: 0.7 - development
// - Author: Khevor/Kay Hermann
// - Email: khevor@khevorslanding.net
// - Site: http://www.khevorslanding.net/
// - Updatecheck: n/a
// - Description: a calendar widget
// - Date: 2009-01-25
// - Identifier: calendar

global $calendar_config;

$calendar_config = array(
   'calendar_folder'   => "calendar",
   'week_start_day'   => 1
);

/**
* Adds the hook for calendarAdmin()
*
* @see calendarAdmin()
*/
$this->addHook(
   'configuration_add',
   'calendar',
   array("calendarAdmin", "Calendar")
);

/**
* Adds the hook for the actual widget. We just use the same
* as the snippet, in this case.
*
* @see smarty_calendar()
*/
$this->addHook(
    'widget',
    'calendar',
    "smarty_calendar"
);

/**
* Add the calendar.css to the header..
*/
$this->addHook(
    'after_parse',
    'insert_before_close_head',
    "<!-- calendar -->
     <link href='[[pivotx_dir]]extensions/calendar/calendar.css' rel='stylesheet' type='text/css' />
    <script type='text/javascript'>
    // <![CDATA[
    function showCalendarDiv(dday) {
      var divDay = 'day' + dday;
      document.getElementById('dlCalendarEntries').style.display='block';
      document.getElementById('dlCalendarEntries').innerHTML = ' ';
      document.getElementById('dlCalendarEntries').innerHTML = document.getElementById(divDay).innerHTML;
    }
    // ]]>
    </script>"
    );

// Register 'calendar' as a smarty tag.
$PIVOTX['template']->register_function('calendar', 'smarty_calendar');

/**
* Output
*/
function smarty_calendar($params) {
    global $PIVOTX, $calendar_config;

    $iWeekStart = get_default($PIVOTX['config']->get('week_start_day'), $calendar_config['week_start_day']);
    $iTimeZone = $PIVOTX['config']->get('timeoffset');
   $iTimeZoneUnit = $PIVOTX['config']->get('timeoffset_unit');
   
   // Translate TimeZone Unit to full English
   switch ($iTimeZoneUnit) {
      case "i":
         $iTZU = " minutes";
         break;
      case "d":
         $iTZU = " days";
         break;
      case "m":
         $iTZU = " months";
         break;
      case "y":
         $iTZU = " years";
         break;
      default:
         $iTZU = " hours";
   }

   // Get the current date
   $aStoredDate = getdate(strtotime($iTimeZone . $iTZU));
   
   // Were the month and year passed and if so, change the $aCurrentDate to that month/year
   //   unless it matches the current month and year, then use the date stored in $aStoredDate.
   if (isset($_REQUEST['m'])) {
      $sCalledMonth = $_REQUEST['m'];
      $bMonOk = preg_match("/^[0-9]{1,2}$/", $sCalledMonth) > 0 ? true : false;
      if ($sCalledMonth < 1 || $sCalledMonth > 13) { $bMonOk = false; }
   }

   if (isset($_REQUEST['y'])) {
      $sCalledYear = $_REQUEST['y'];
      $bYearOk = preg_match("/^[0-9]{4}$/", $sCalledYear) > 0 ? true : false;
   }
   
   if ($bMonOk && $bYearOk) {
      if ( $sCalledMonth == $aStoredDate['mon'] && $sCalledYear == $aStoredDate['year']) {
         $aCurrentDate = $aStoredDate;
      } else {
         $aCurrentDate = getdate(mktime(0, 0, 0, $sCalledMonth, 1, $sCalledYear));
      }
   } else {
      $aCurrentDate = $aStoredDate;
   }
   

   // Get number of days in the month
   switch ($aCurrentDate['mon']) {
      case 1:
      case 3:
      case 5:
      case 7:
      case 8:
      case 10:
      case 12:
         $iNumDays = 31;
         break;
      case 4:
      case 6:
      case 9:
      case 11:
         $iNumDays = 30;
         break;
      case 2:
         $iNumDays = date("L", mktime(0, 0, 0, $aCurrentDate['mon'], 1, $aCurrentDate['year'])) ? 29 : 28;
   }

   // Determine the day of the week the month starts at.
   $iStartDay = date("w", mktime(0, 0, 0, $aCurrentDate['mon'], 1, $aCurrentDate['year']));

   if($iStartDay == 0) $iStartDay = 7;

   $j = $iStartDay;

   $aMonth = array_fill(1, $iNumDays, 0);

   for($i = 1; $i < $iNumDays + 1; $i++) {
      if ($j > 7) { $j = 1; }
      $aMonth[$i] = $j;
      $j++;
   }
   
   /******************************
   *  Get Entries For the Month  *
   ******************************/
   
   $dStartDate = date("Y-m-d-H-i", mktime(0, 0, 0, $aCurrentDate['mon'], 1, $aCurrentDate['year']));
   $dStopDate = date("Y-m-d-H-i", mktime(23, 59, 59, $aCurrentDate['mon'], $iNumDays, $aCurrentDate['year']));
   
   $aParams = array ("start" => $dStartDate, "end" => $dStopDate, "status" => "publish");
   $aListEntries = $PIVOTX['db']->read_entries($aParams);
   

   
   /******************************
   * Start building the calendar *
   ******************************/
   // Build variables for previous and next month links
   $prevMonth = $aCurrentDate['mon'] - 1;
   $prevYear = $aCurrentDate['year'];
   if ($prevMonth < 1) { $prevMonth = 12; $prevYear--; }
   
   $nextMonth = $aCurrentDate['mon'] + 1;
   $nextYear = $aCurrentDate['year'];
   if ($nextMonth > 12) { $nextMonth = 1; $nextYear++; }
   
   // Escape sequences are only to make it look tidy and serve no other real purpose.
   // Build the Month/Year header and the Days of the Week Header
   $output = "<a name=\"dlCName\"></a><div class=\"dlCalendarTable\"><table class=\"dlCalendar\">\n\t<tbody>\n";
   $output .= "\t<tr><th class=\"previous\"><a href=\"?m=" . $prevMonth . "&amp;y=" . $prevYear . "#dlCName\" title=\"Previous Month\">&laquo;</a></th><th colspan=\"5\" class=\"dlCalendarHead\">" . $aCurrentDate['month'] . " " . $aCurrentDate['year'] . "</th><th class=\"next\"><a href=\"?m=" . $nextMonth . "&amp;y=" . $nextYear . "#dlCName\" title=\"Next Month\">&raquo;</a></th></tr>\n";
   $output .= "\t<tr class=\"dlCalendarSubHead\">\n";

   $j = $iWeekStart;
   for ($i = 0; $i < 7; $i++) {
      switch ($j) {
         case 1:
            $output .= "\t\t<td>Mo</td>\n";
            break;
         case 2:
            $output .= "\t\t<td>Tu</td>\n";
            break;
         case 3:
            $output .= "\t\t<td>We</td>\n";
            break;
         case 4:
            $output .= "\t\t<td>Th</td>\n";
            break;
         case 5:
            $output .= "\t\t<td>Fr</td>\n";
            break;
         case 6:
            $output .= "\t\t<td>Sa</td>\n";
            break;
         case 7:
            $output .= "\t\t<td>Su</td>\n";
      }
      $j++;
      if ($j > 7) { $j = 1; }
   }

   $output .= "\t</tr>\n\t<tr>\n";

   /******************************
   *  Build the actual calendar  *
   ******************************/

   // Insert blank days for the first week if necessary.
   if ($iWeekStart <= $iStartDay) {
      $iBlankDays = $iStartDay - $iWeekStart;
   } else {
      $iBlankDays = 7 - ($iWeekStart - $iStartDay);
   }

   for ($i = 0; $i < $iBlankDays; $i++) {
      $output .= "\t\t<td>&nbsp;</td>\n";
   }

   // Insert links for the published entries during the iteration of days.
   $aDivInfo = array_fill(1, $iNumDays, "");
   for ($i = 1; $i < $iNumDays + 1; $i++) {
      if ($aMonth[$i] == $iWeekStart) {
         $output .= "\t</tr>\n\t<tr>\n";
      }
     
      $dNow = date("Y-m-d", mktime(23, 59, 59, $aCurrentDate['mon'], $i, $aCurrentDate['year']));
      $dStoredNow = date("Y-m-d", mktime(23, 59, 59, $aStoredDate['mon'], $aStoredDate['mday'], $aStoredDate['year']));
     
      $bCounter = false;
      $sDivInfo = "";
      foreach ($aListEntries as $a) {
         if ( $dNow == substr($a['publish_date'], 0, 10)) {
            $sDivInfo .= '<a href="' . $a['link'] . '" title="' . $a['title'] . '">' . $a['title'] . '</a><br />';
            $bCounter = true;
         }
      }
     
      if ($bCounter) {
         if ($dNow == $dStoredNow) {
            $output .= "\t\t<td class=\"dlCalendarCurrentDay\"><a class=\"dlCalendarDivLink\" onClick=\"showCalendarDiv(" . $i . ");\">" . $i . "</a></td>\n";
         } else {
            $output .= "\t\t<td><a class=\"dlCalendarDivLink\" onClick=\"showCalendarDiv(" . $i . ");\">" . $i . "</a></td>\n";
         }
      } else {
         if ($dNow == $dStoredNow) {
            $output .= "\t\t<td class=\"dlCalendarCurrentDay\">" . $i . "</td>\n";
         } else {
            $output .= "\t\t<td>" . $i . "</td>\n";
         }
      }

      $aDivInfo[$i] = $sDivInfo;
   }

   // Insert blank days for the last week if necessary.
   $iEndDay = $aMonth[$iNumDays];
   $iWeekEnd = $iWeekStart - 1;
   if ($iWeekEnd < 1 ) { $iWeekEnd = 7; }
   if ($iEndDay <= $iWeekEnd) {
      $iBlankDays = $iWeekEnd - $iEndDay;
   } else {
      $iBlankDays = 7 - ($iEndDay - $iWeekEnd);
   }

   for ($i = 0; $i < $iBlankDays; $i++ ) {
      $output .= "\t\t<td>&nbsp;</td>\n";
   }

   // Close off the calendar construction
   $output .= "\t</tr>\n";
   $output .= "\t</tbody>\n</table>\n";
   
   // Build the Entry Div (where the entry titles are to be displayed)
   $output .= "<div id=\"dlCalendarEntries\">&nbsp;</div>\n";
   
   // Build sub Divs where the all entries for that month are hidden
   //   for use with the javascript.
   for ($i = 1; $i < $iNumDays + 1; $i++) {
      if ($aDivInfo[$i] != "" ) {
         $output .= "<div id=\"day" . $i . "\" style=\"display:none;\">" . $aDivInfo[$i] . "</div>\n";
      }
   }
   
   // Close the Entry Div.
   $output .= "</div>\n";

   // Output the calendar
   return $output;
}

/**
* The configuration screen for calendar
*
* @param unknown_type $form_html
*/
function calendarAdmin(&$form_html) {
    global $PIVOTX, $calendar_config;

   $form = $PIVOTX['extensions']->getAdminForm('calendar');

    $form->add( array(
        'type' => 'text',
        'name' => 'week_start_day',
        'label' => "Week Start Day",
        'value' => '1',
        'error' => 'That\'s not a valid start day for the week!',
        'text' => "Enter a numerical value for the day of the week you wish the calendar to start at.  1 = Monday, 2 = Tuesday, ... 7 = Sunday.",
        'size' => 8,
        'isrequired' => 1,
        'validation' => 'string|minlen=1|maxlen=1'
    ));
   
    /**
     * Add the form to our (referenced) $form_html. Make sure you use the same key
     * as the first parameter to $PIVOTX['extensions']->getAdminForm
     */
    $form_html['calendar'] = $PIVOTX['extensions']->getAdminFormHtml($form, $calendar_config);

}

?>


Don't forget the css found in Khevor's post on page 1.

@hansfn
Thanks for telling me about the updated version. I have one problem though: After updating, the text following the article names on the dashboard and the articles' page appears scrambled. Is this a known bug?

Image
Kay
Contributor
 
Posts: 24
Joined: Sun Jan 11, 2009 10:48 pm

Re: Is there a Calendar Extension for PivotX?

Postby hansfn » Mon Jan 26, 2009 7:28 am

After updating, the text following the article names on the dashboard and the articles' page appears scrambled.

Just rebuild the index.
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Is there a Calendar Extension for PivotX?

Postby Kay » Mon Jan 26, 2009 8:56 am

Thanks, that did the trick.
Kay
Contributor
 
Posts: 24
Joined: Sun Jan 11, 2009 10:48 pm

Re: Is there a Calendar Extension for PivotX?

Postby Stingray » Sun Nov 01, 2009 11:33 pm

Thanks!

NIce extension; it's good to have a calendar back. Unfortunately for me, my skill with php isn't the greatest, so I wouldn't know how to make it so that it filters out entries from hidden categories (I don't know if it shows them right now or not) or categories not part of the weblog the [[ calendar ]] tag is placed in (this has happened to me), or if that's even possible with the way it is currently written. Can this be done? Can I make it a suggestion?

Anyway, though not very much of this reply shows it, my point is to thank you for creating this!
Stingray
 
Posts: 107
Joined: Wed Oct 28, 2009 2:40 pm

Re: Is there a Calendar Extension for PivotX?

Postby Kay » Mon Nov 02, 2009 6:42 am

I don't have the time right now to check this in detail but I guess you'd need to modify this section:

Code: Select all
   /******************************
   *  Get Entries For the Month  *
   ******************************/
   
   $dStartDate = date("Y-m-d-H-i", mktime(0, 0, 0, $aCurrentDate['mon'], 1, $aCurrentDate['year']));
   $dStopDate = date("Y-m-d-H-i", mktime(23, 59, 59, $aCurrentDate['mon'], $iNumDays, $aCurrentDate['year']));
   
   $aParams = array ("start" => $dStartDate, "end" => $dStopDate, "status" => "publish");
   $aListEntries = $PIVOTX['db']->read_entries($aParams);


Mores specifically, here, the "status" => "publish" part:

Code: Select all
   $aParams = array ("start" => $dStartDate, "end" => $dStopDate, "status" => "publish");


But don't ask me what to change it to exactly. Maybe one of the devs can help you you with that?

I'll have another look at it tonight.
Kay
Contributor
 
Posts: 24
Joined: Sun Jan 11, 2009 10:48 pm

Re: Is there a Calendar Extension for PivotX?

Postby Stingray » Mon Nov 02, 2009 7:59 am

I wonder if it might be easier to pass some parameters through the tag in the templates:
[[ calendar include="this-category, that-category, other-category" ]]
or
[[ calendar exclude="some-other-category, yet-another-category" ]]
or
[[ calendar excludehidden=1 ]]
etc.

If the parameter isn't or parameters aren't present, every category is included, such as it is currently written.
Stingray
 
Posts: 107
Joined: Wed Oct 28, 2009 2:40 pm

Re: Is there a Calendar Extension for PivotX?

Postby Kay » Mon Nov 02, 2009 5:37 pm

Well, I didn't write the code (Khevor did), I just added/edited some bits to make it work (involving a lot of trial and error as I only have a basic understanding of PHP programming). I'm glad it works now the way it's supposed to, for me at least. If anyone needs more functions feel free to to add to the existing code.

I'm not sure how the PivotX read_entries function works, can't find it in the documentation either, so I guess we'll have to wait for one of the devs to tell us how to exclude hidden entries. Sorry.
Kay
Contributor
 
Posts: 24
Joined: Sun Jan 11, 2009 10:48 pm

Re: Is there a Calendar Extension for PivotX?

Postby Stingray » Tue Nov 03, 2009 3:10 am

I guess I'm not asking anyone specific to do anything; I'm just throwing out ideas for anyone willing to take the code and try to improve it any. If I can find the time, I'll certainly look at it, too, but I'm not too skilled with the php either.
Stingray
 
Posts: 107
Joined: Wed Oct 28, 2009 2:40 pm

Re: Is there a Calendar Extension for PivotX?

Postby Stingray » Mon Nov 16, 2009 10:46 pm

I've been kinda quiet around here lately.

But, I've gone and done it. I've added some stuff so that you can specify which category or categories you would like to include in your calendar. This is done thus:
Code: Select all
[[ calendar category="category-one,category-two,category-three,etc." ]]

Of course, you would use the names of your categories (not the display names, the "internal" names). For instance, if you had a category with the display name My Ramblings you would use category="my-ramblings". If you do not use the parameter, every category will be displayed, just as it worked before this update.

Hopefully, I haven't stepped on any toes doing this.

Here's the code:
Code: Select all
<?php
// - Extension: Calendar
// - Version: 0.8 - development
// - Author: Khevor/Kay Hermann/Stingray
// - Email: khevor@khevorslanding.net
// - Site: http://www.khevorslanding.net/
// - Updatecheck: n/a
// - Description: a calendar widget
// - Date: 2009-01-25
// - Identifier: calendar

global $calendar_config;

$calendar_config = array(
   'calendar_folder'   => "calendar",
   'week_start_day'   => 1
);

/**
* Adds the hook for calendarAdmin()
*
* @see calendarAdmin()
*/
$this->addHook(
    'configuration_add',
    'calendar',
    array("calendarAdmin", "Calendar")
);

/**
* Adds the hook for the actual widget. We just use the same
* as the snippet, in this case.
*
* @see smarty_calendar()
*/
$this->addHook(
    'widget',
    'calendar',
    "smarty_calendar"
);

/**
* Add the calendar.css to the header..
*/
$this->addHook(
    'after_parse',
    'insert_before_close_head',
    "<!-- calendar -->
    <link href='[[pivotx_dir]]extensions/calendar/calendar.css' rel='stylesheet' type='text/css' />
    <script type='text/javascript'>
    // <![CDATA[
    function showCalendarDiv(dday) {
      var divDay = 'day' + dday;
      document.getElementById('dlCalendarEntries').style.display='block';
      document.getElementById('dlCalendarEntries').innerHTML = ' ';
      document.getElementById('dlCalendarEntries').innerHTML = document.getElementById(divDay).innerHTML;
    }
    // ]]>
    </script>"
);

// Register 'calendar' as a smarty tag.
$PIVOTX['template']->register_function('calendar', 'smarty_calendar');

/**
* Output
*/
function smarty_calendar($params) {
    global $PIVOTX, $calendar_config;

    $params = clean_params($params);

    $iWeekStart = get_default($PIVOTX['config']->get('week_start_day'), $calendar_config['week_start_day']);
    $iTimeZone = $PIVOTX['config']->get('timeoffset');
    $iTimeZoneUnit = $PIVOTX['config']->get('timeoffset_unit');

    // Stingray addition, to limit categories.
    if ($params['category']) {
      $categories = explode(",", $params['category']);
    }

    // Translate TimeZone Unit to full English
    switch ($iTimeZoneUnit) {
      case "i":
         $iTZU = " minutes";
         break;
      case "d":
         $iTZU = " days";
         break;
      case "m":
         $iTZU = " months";
         break;
      case "y":
         $iTZU = " years";
         break;
      default:
         $iTZU = " hours";
    }

    // Get the current date
    $aStoredDate = getdate(strtotime($iTimeZone . $iTZU));
   
    // Were the month and year passed and if so, change the $aCurrentDate to that month/year
    //   unless it matches the current month and year, then use the date stored in $aStoredDate.
    if (isset($_REQUEST['m'])) {
      $sCalledMonth = $_REQUEST['m'];
      $bMonOk = preg_match("/^[0-9]{1,2}$/", $sCalledMonth) > 0 ? true : false;
      if ($sCalledMonth < 1 || $sCalledMonth > 13) { $bMonOk = false; }
    }

    if (isset($_REQUEST['y'])) {
      $sCalledYear = $_REQUEST['y'];
      $bYearOk = preg_match("/^[0-9]{4}$/", $sCalledYear) > 0 ? true : false;
    }

    if ($bMonOk && $bYearOk) {
      if ( $sCalledMonth == $aStoredDate['mon'] && $sCalledYear == $aStoredDate['year']) {
         $aCurrentDate = $aStoredDate;
      } else {
         $aCurrentDate = getdate(mktime(0, 0, 0, $sCalledMonth, 1, $sCalledYear));
      }
    } else {
      $aCurrentDate = $aStoredDate;
    }

    // Get number of days in the month
    switch ($aCurrentDate['mon']) {
      case 1:
      case 3:
      case 5:
      case 7:
      case 8:
      case 10:
      case 12:
         $iNumDays = 31;
         break;
      case 4:
      case 6:
      case 9:
      case 11:
         $iNumDays = 30;
         break;
      case 2:
         $iNumDays = date("L", mktime(0, 0, 0, $aCurrentDate['mon'], 1, $aCurrentDate['year'])) ? 29 : 28;
    }

    // Determine the day of the week the month starts at.
    $iStartDay = date("w", mktime(0, 0, 0, $aCurrentDate['mon'], 1, $aCurrentDate['year']));

    if($iStartDay == 0) $iStartDay = 7;

    $j = $iStartDay;

    $aMonth = array_fill(1, $iNumDays, 0);

    for($i = 1; $i < $iNumDays + 1; $i++) {
      if ($j > 7) { $j = 1; }
      $aMonth[$i] = $j;
      $j++;
    }

    /******************************
    *  Get Entries For the Month  *
    ******************************/
   
    $dStartDate = date("Y-m-d-H-i", mktime(0, 0, 0, $aCurrentDate['mon'], 1, $aCurrentDate['year']));
    $dStopDate = date("Y-m-d-H-i", mktime(23, 59, 59, $aCurrentDate['mon'], $iNumDays, $aCurrentDate['year']));

    $aParams = array ("start" => $dStartDate, "end" => $dStopDate, "status" => "publish");
    $aListEntriesRead = $PIVOTX['db']->read_entries($aParams);
    $aListEntries = array();

   // STINGRAY ADDITION
   /*********************************************************
   * Limits the entried displayed to the desired categories *
   *********************************************************/
   if ($categories) {
      $categoriescount = count($categories);
      $entriescount = count($aListEntriesRead);
      for ($i=0;$i<$entriescount;$i++) {
         $match = 0;
         for ($ii=0;$ii<$categoriescount;$ii++) {
            if (in_array($categories[$ii], $aListEntriesRead[$i]['category'])) {
               $match++;
            }
         }
         if ($match > 0) {
            $aListEntries[] = $aListEntriesRead[$i];
         }
      }
   } else {
      $aListEntries = $aListEntriesRead;
   }

    /******************************
    * Start building the calendar *
    ******************************/
    // Build variables for previous and next month links
    $prevMonth = $aCurrentDate['mon'] - 1;
    $prevYear = $aCurrentDate['year'];
    if ($prevMonth < 1) { $prevMonth = 12; $prevYear--; }

    $nextMonth = $aCurrentDate['mon'] + 1;
    $nextYear = $aCurrentDate['year'];
    if ($nextMonth > 12) { $nextMonth = 1; $nextYear++; }

    // Escape sequences are only to make it look tidy and serve no other real purpose.
    // Build the Month/Year header and the Days of the Week Header
    $output = "<a name=\"dlCName\"></a><div class=\"dlCalendarTable\"><table class=\"dlCalendar\">\n\t<tbody>\n";
    $output .= "\t<tr><th class=\"previous\"><a href=\"?m=" . $prevMonth . "&amp;y=" . $prevYear . "#dlCName\" title=\"Previous Month\">&laquo;</a></th><th colspan=\"5\" class=\"dlCalendarHead\">" . $aCurrentDate['month'] . " " . $aCurrentDate['year'] . "</th><th class=\"next\"><a href=\"?m=" . $nextMonth . "&amp;y=" . $nextYear . "#dlCName\" title=\"Next Month\">&raquo;</a></th></tr>\n";
    $output .= "\t<tr class=\"dlCalendarSubHead\">\n";

    $j = $iWeekStart;
    for ($i = 0; $i < 7; $i++) {
      switch ($j) {
         case 1:
            $output .= "\t\t<td>Mo</td>\n";
            break;
         case 2:
            $output .= "\t\t<td>Tu</td>\n";
            break;
         case 3:
            $output .= "\t\t<td>We</td>\n";
            break;
         case 4:
            $output .= "\t\t<td>Th</td>\n";
            break;
         case 5:
            $output .= "\t\t<td>Fr</td>\n";
            break;
         case 6:
            $output .= "\t\t<td>Sa</td>\n";
            break;
         case 7:
            $output .= "\t\t<td>Su</td>\n";
      }
      $j++;
      if ($j > 7) { $j = 1; }
    }

    //$output .= "\t</tr>\n\t<tr>\n";

    /******************************
    *  Build the actual calendar  *
    ******************************/

    // Insert blank days for the first week if necessary.
    if ($iWeekStart <= $iStartDay) {
      $iBlankDays = $iStartDay - $iWeekStart;
    } else {
      $iBlankDays = 7 - ($iWeekStart - $iStartDay);
    }

    for ($i = 0; $i < $iBlankDays; $i++) {
      $output .= "\t\t<td>&nbsp;</td>\n";
    }

    // Insert links for the published entries during the iteration of days.
    $aDivInfo = array_fill(1, $iNumDays, "");
    for ($i = 1; $i < $iNumDays + 1; $i++) {
      if ($aMonth[$i] == $iWeekStart) {
         $output .= "\t</tr>\n\t<tr>\n";
      }

      $dNow = date("Y-m-d", mktime(23, 59, 59, $aCurrentDate['mon'], $i, $aCurrentDate['year']));
      $dStoredNow = date("Y-m-d", mktime(23, 59, 59, $aStoredDate['mon'], $aStoredDate['mday'], $aStoredDate['year']));

      $bCounter = false;
      $sDivInfo = "";
      foreach ($aListEntries as $a) {
         if ( $dNow == substr($a['publish_date'], 0, 10)) {
            $sDivInfo .= '<li><a href="' . $a['link'] . '" title="' . $a['title'] . '">' . $a['title'] . '</a></li>';
            $bCounter = true;
         }
      }

      if ($bCounter) {
         if ($dNow == $dStoredNow) {
            $output .= "\t\t<td class=\"dlCalendarCurrentDay\"><a class=\"dlCalendarDivLink\" onclick=\"showCalendarDiv(" . $i . ");\">" . $i . "</a></td>\n";
         } else {
            $output .= "\t\t<td><a class=\"dlCalendarDivLink\" onclick=\"showCalendarDiv(" . $i . ");\">" . $i . "</a></td>\n";
         }
      } else {
         if ($dNow == $dStoredNow) {
            $output .= "\t\t<td class=\"dlCalendarCurrentDay\">" . $i . "</td>\n";
         } else {
            $output .= "\t\t<td>" . $i . "</td>\n";
         }
      }

      $aDivInfo[$i] = $sDivInfo;
    }

    // Insert blank days for the last week if necessary.
    $iEndDay = $aMonth[$iNumDays];
    $iWeekEnd = $iWeekStart - 1;
    if ($iWeekEnd < 1 ) { $iWeekEnd = 7; }
    if ($iEndDay <= $iWeekEnd) {
      $iBlankDays = $iWeekEnd - $iEndDay;
    } else {
      $iBlankDays = 7 - ($iEndDay - $iWeekEnd);
    }

    for ($i = 0; $i < $iBlankDays; $i++ ) {
      $output .= "\t\t<td>&nbsp;</td>\n";
    }

    // Close off the calendar construction
    $output .= "\t</tr>\n";
    $output .= "\t</tbody>\n</table>\n";

    // Build the Entry Div (where the entry titles are to be displayed)
    $output .= "<div id=\"dlCalendarEntries\">&nbsp;</div>\n";

    // Build sub Divs where the all entries for that month are hidden
    //   for use with the javascript.
    for ($i = 1; $i < $iNumDays + 1; $i++) {
      if ($aDivInfo[$i] != "" ) {
         $output .= "<div id=\"day" . $i . "\" style=\"display:none;\"><ul>" . $aDivInfo[$i] . "</ul></div>\n";
      }
    }

    // Close the Entry Div.
    $output .= "</div>\n";

    // Output the calendar
    return $output;
}

/**
* The configuration screen for calendar
*
* @param unknown_type $form_html
*/
function calendarAdmin(&$form_html) {
    global $PIVOTX, $calendar_config;

    $form = $PIVOTX['extensions']->getAdminForm('calendar');

    $form->add( array(
        'type' => 'text',
        'name' => 'week_start_day',
        'label' => "Week Start Day",
        'value' => '1',
        'error' => 'That\'s not a valid start day for the week!',
        'text' => "Enter a numerical value for the day of the week you wish the calendar to start at.  1 = Monday, 2 = Tuesday, ... 7 = Sunday.",
        'size' => 8,
        'isrequired' => 1,
        'validation' => 'string|minlen=1|maxlen=1'
    ));

    /**
    * Add the form to our (referenced) $form_html. Make sure you use the same key
    * as the first parameter to $PIVOTX['extensions']->getAdminForm
    */
    $form_html['calendar'] = $PIVOTX['extensions']->getAdminFormHtml($form, $calendar_config);

}

?>


Remember to rid yourselves of the unwanted spaces if copying the code (as mentioned elsewhere in this thread).
Stingray
 
Posts: 107
Joined: Wed Oct 28, 2009 2:40 pm

PreviousNext

Return to 2.x Extensions

Who is online

Users browsing this forum: No registered users and 3 guests

cron