Is there a Calendar Extension for PivotX?

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

Is there a Calendar Extension for PivotX?

Postby Khevor » Sun Aug 03, 2008 2:46 am

#----------------------------------------------------------------------------------------------------------------------------------------

As of PivotX 2.1 there is a core calendar extension. Use PivotX Latest if you can't wait for 2.1 ...
(This calendar can be limited to categories or even users.)


Added by hansfn 5th of December, 2009.

#----------------------------------------------------------------------------------------------------------------------------------------

If there isn't, that's fine. I'm building my own. If there is, point me to where, if someone would, so I can stop pulling my hair out.

The problem I'm having with the one I'm working on deals with the getlist_range() function. I've tried seven ways to Sunday to get that thing to work but it just won't. It always returns an empty array. I can get the getlist() to work great.

This is the function I'm referring to (within an extension, mind you with $PIVOTX set as global).
Code: Select all
$aListEntries = $PIVOTX['db']->getlist_range($dStartDate, $dStopDate, "", "", TRUE, "publish");


For the start and stop date strings, I've had everything from a timestamp, to a date formatted like what's in the mySql database. I've left the last four arguments off, also left them blank, tried assorted things but no matter what, I get an empty array returned.

Now, if I change it to getlist and not getlist_range, it spits back whatever number of entries I ask for without issue. Am I doing something wrong, or is that getlist_range function non-functional?
Khevor
 
Posts: 26
Joined: Sun Aug 03, 2008 2:37 am
Location: Ontario, Canada

Re: Is there a Calendar Extension for PivotX?

Postby hansfn » Sun Aug 03, 2008 9:11 am

The dates should be in "Pivot format" - "yyyy-mm-dd-hh-mm". Could you try (as an example) the following code
Code: Select all
$aListEntries = $PIVOTX['db']->getlist_range("1970-01-01-00-00", "2020-12-31-23-59", "", "", TRUE, "publish");

It should return all (published) entries.

The calendar extension hasn't been ported from Pivot yet, but that shouldn't be a lot of work. I suggest you look at the old code in stead of writing from scratch, but do whatever makes you happy. If you write this extension, please consider giving the code back to us...
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Is there a Calendar Extension for PivotX?

Postby Khevor » Sun Aug 03, 2008 3:14 pm

Hmmm... copied and pasted exactly what you had and it still returns a blank array when I use the print_r($aListEntries);. I even set "publish" to "" to see if that changed anything. No go.

You wouldn't want my code. It's not exactly clean code and I'm only doing it because I wanted to try my hand at it. Am I missing a global declaration or something?

The following is what I have and currently, it just displays a lovely calendar that shows the current date, nothing more. It has the option to set the week start day to any day of the week (for people that like calendars to start on Monday, or Sunday, or Friday if they wanted to). It also makes an adjustment for whatever the user's set Time Offset is.

Code: Select all
<?php
// - Extension: Calendar
// - Version: 0.2 - development
// - Author: Khevor
// - Email: khevor@khevorslanding.net
// - Site: http://www.khevorslanding.net/
// - Updatecheck: n/a
// - Description: a calendar widget
// - Date: 2008-08-02
// - Identifier: calendar

global $calendar_config;

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

/**
 * 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='[[pivot_dir]]extensions/calendar/calendar.css' rel='stylesheet' type='text/css' />"
    );

// 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
   $aCurrentDate = getdate(strtotime($iTimeZone . $iTZU));

   // 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:
         date("L") ? $iNumDays = 29 : $iNumDays = 28;
   }

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

   $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("m-d-Y H:i:s", mktime(0, 0, 0, $aCurrentDate['mon'], 1, $aCurrentDate['year']));
   //$dStopDate = date("m-d-Y H:i:s", mktime(23, 59, 59, $aCurrentDate['mon'], $iNumDays, $aCurrentDate['year']));
   
   $aListEntries = $PIVOTX['db']->getlist_range("1970-01-01-00-00", "2020-12-31-23-59", "", "", TRUE, "");
   print_r($aListEntries);
   
   /******************************
   * Start building the calendar *
   ******************************/
   // 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 = "<div class=\"dlCalendarTable\"><table class=\"dlCalendar\">\n\t<tbody>\n";
   $output .= "\t<tr><th colspan=\"7\" class=\"dlCalendarHead\">" . $aCurrentDate['month'] . " " . $aCurrentDate['year'] . "</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>M</td>\n";
            break;
         case 2:
         case 4:
            $output .= "\t\t<td>T</td>\n";
            break;
         case 3:
            $output .= "\t\t<td>W</td>\n";
            break;
         case 5:
            $output .= "\t\t<td>F</td>\n";
            break;
         case 6:
         case 7:
            $output .= "\t\t<td>S</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";
   }

   for ($i = 1; $i < $iNumDays + 1; $i++) {
      if ($aMonth[$i] == $iWeekStart) {
         $output .= "\t</tr>\n\t<tr>\n";
      }
      if ($i == $aCurrentDate['mday']) {
         $output .= "\t\t<td class=\"dlCalendarCurrentDay\">" . $i . "</td>\n";
      } else {
         $output .= "\t\t<td>" . $i . "</td>\n";
      }
   }

   // 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</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' => '7',
        '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);

}

?>
Last edited by Khevor on Mon Aug 04, 2008 3:54 pm, edited 1 time in total.
Khevor
 
Posts: 26
Joined: Sun Aug 03, 2008 2:37 am
Location: Ontario, Canada

Re: Is there a Calendar Extension for PivotX?

Postby Khevor » Mon Aug 04, 2008 3:47 pm

Update: I just wanted to update my post.

I updated PivotX to ver 1.9 (got the link from another post) and discovered that the getlist_range() function was removed. However, I found the function read_entries(). As a result, I changed my code to incorporate this function instead. It worked.

Code: Select all
   $aParams = array ("start" => "1970-01-01-00-00", "end" => "2020-12-31-23-59");
   $aListEntries = $PIVOTX['db']->read_entries($aParams);
   print_r($aListEntries);


That gave me the entries within a specific date as I wanted. I can now continue work on the calendar widget. I don't know if that function was in v1.8 (as I don't remember seeing it) but if it wasn't, thanks :). If it was, then my apologies for being blind. lol.
Khevor
 
Posts: 26
Joined: Sun Aug 03, 2008 2:37 am
Location: Ontario, Canada

Re: Is there a Calendar Extension for PivotX?

Postby Bob » Mon Aug 04, 2008 4:13 pm

Getlist_range has been removed, to keep the Flat Files and MySQL versions in sync.

Glad to hear you can keep going. Looking forward to seeing the results! :-)
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: Is there a Calendar Extension for PivotX?

Postby Khevor » Mon Aug 04, 2008 8:07 pm

Well, keep going I did. I got it working. The code may be convoluted compared to your standards but if you want to test it out for yourself, feel free. I imagine there are easier, cleaner ways to do the same thing, but this is what I came up with.

Update: I realized I forgot something on the calendar (the ability to look at previous and next months). As a result, I added that in and updated the information below as a result.

widget_calendar.php
Code: Select all
<?php
// - Extension: Calendar
// - Version: 0.6 - development
// - Author: Khevor
// - Email: khevor@khevorslanding.net
// - Site: http://www.khevorslanding.net/
// - Updatecheck: n/a
// - Description: a calendar widget
// - Date: 2008-08-02
// - Identifier: calendar

global $calendar_config;

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

/**
 * 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='[[pivot_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("N", mktime(0, 0, 0, $aCurrentDate['mon'], 1, $aCurrentDate['year']));

   $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);
   $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>M</td>\n";
            break;
         case 2:
         case 4:
            $output .= "\t\t<td>T</td>\n";
            break;
         case 3:
            $output .= "\t\t<td>W</td>\n";
            break;
         case 5:
            $output .= "\t\t<td>F</td>\n";
            break;
         case 6:
         case 7:
            $output .= "\t\t<td>S</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 == date("Y-m-d", strtotime($a['publish_date']))) {
            $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' => '7',
        '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);

}

?>


And calendar.css
Code: Select all
/* Calendar Widget Styles */

/* Sets the width of the table (the margin centers it) */
div.dlCalendarTable {
   width: 180px;
   margin: 0px auto;
}

/* Formats how entry titles are displayed below the calendar */
div#dlCalendarEntries {
   display: none;
   text-align: center;
   overflow: hidden;
}

/* Basic calendar formatting */
table.dlCalendar {
   font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
   font-size: 0.9em;
   margin: 0px;
   width: 100%;
   background-color: #ECF3F7;
   border-collapse: collapse;
   border: 1px solid #666;
   cursor: default;
}

/* Formats the main Header (that displays the month and year) */
table.dlCalendar th {
   background-color: #0047ab;
   color: #ffffff;
   padding: 2px 0px;
}

table.dlCalendar th.dlCalendarHead {
   font-weight: bold;
   font-size: 1.1em;
   border-top: 1px solid #666;
   border-bottom: 1px solid #666;
}

table.dlCalendar th.previous {
   border-top: 1px solid #666;
   border-left: 1px solid #666;
   border-bottom: 1px solid #666;
}

table.dlCalendar th.next {
   border-top: 1px solid #666;
   border-right: 1px solid #666;
   border-bottom: 1px solid #666;
}

/* Formats the secondary header (that displays the days of the week
   and cancels out the calendar's mouse hover effects for that header */
table.dlCalendar tr.dlCalendarSubHead,
table.dlCalendar tr.dlCalendarSubHead td:hover {
   background-color: #3a71bf;
   color: #FFFFFF;
   font-weight: bold;
}

/* General formatting for all cells in the calendar */
table.dlCalendar td {
   text-align: center;
   border: 1px solid #BBB;
   padding: 2px;
}

/* Formats the current day cell */
table.dlCalendar td.dlCalendarCurrentDay {
   background-color: #fafad2;
   color: #FF0000;
   font-weight:bold;
   border-style: inset;
}

/* Mouse hover effect */
table.dlCalendar td:hover {
   background-color: #fafad2;
   color: #000;
   border-style: outset;
}

/* Formats day links on the calendar */
table a.dlCalendarDivLink {
   /* Double cursor declaration is for compatibility between MSIE and other browsers */
   cursor: pointer;
   cursor: hand;
   text-decoration: underline;
   color: #000080;
}
Khevor
 
Posts: 26
Joined: Sun Aug 03, 2008 2:37 am
Location: Ontario, Canada

Re: Is there a Calendar Extension for PivotX?

Postby Khevor » Thu Oct 02, 2008 8:48 am

For those people that are using this widget code as is, please be careful when copying and pasting this code. Extra blanks before the first line <? can (and has) cause issues with your installation of PivotX (http://forum.pivotx.net/viewtopic.php?f=2&t=432).

This widget has never been officially released (or accepted by the developers of PivotX) and should be considered 'alpha' software (read: pre-beta). The code was provided here in the event that the PivotX developers wanted to incorporate it (or parts of it) into future versions of PivotX or if they were going to port the version from the original Pivot. For that reason, I never continued with this widget's development.

I apologize for any issues this code may cause for users that wish to use it, but please be warned that if you choose to use this code, you are indeed using it at your own risk.
Khevor
 
Posts: 26
Joined: Sun Aug 03, 2008 2:37 am
Location: Ontario, Canada

Re: Is there a Calendar Extension for PivotX?

Postby Bob » Thu Oct 02, 2008 5:48 pm

(or accepted by the developers of PivotX)


We will, we will.. As soon as themes.pivotx.net is finished. ;-)
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: Is there a Calendar Extension for PivotX?

Postby Kay » Wed Jan 21, 2009 10:43 pm

First of all thanks for writing this widget. I installed it on my blog and I noticed two problems:

1. All days were displayed in one line.
2. No links are created for the entries in the calendar.

The first one I was able to solve myself by changing this part:

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


Like this:

Code: Select all
   // 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;


Regarding number two, I was trying to debug the widget and noticed that apparently the reading of the entries into the array $aListEntries fails. Any ideas how to fix this?

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);
   $aListEntries = $PIVOTX['db']->read_entries($aParams);
Kay
Contributor
 
Posts: 24
Joined: Sun Jan 11, 2009 10:48 pm

Re: Is there a Calendar Extension for PivotX?

Postby Kay » Sun Jan 25, 2009 7:27 pm

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

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);
   $aListEntries = $PIVOTX['db']->read_entries($aParams);


Like this:

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']));
   
   $aListEntries = $PIVOTX['db']->getlist_range($dStartDate, $dStopDate, "", "", TRUE, "publish");


Basically I substituted read_entries with getlist_range. Now I'm a step closer to the solution, but the $aListEntries array lacks the keys 'link' and 'publish_date' which makes this part not work correctly:

Code: Select all
      foreach ($aListEntries as $a) {
         if ( $dNow == date("Y-m-d", strtotime($a['publish_date']))) {
            $sDivInfo .= '<a href="' . $a['link'] . '" title="' . $a['title'] . '">' . $a['title'] . '</a><br />';
            $bCounter = true;
         }
      }


$a['publish_date'] is an empty string and for some reason $dNow == date("Y-m-d", strtotime($a['publish_date'])) is true when the day in question is the current day. I'm assuming if you pass an empty string to strtotime it returns the stamp for the current day?

Well the part further down creates one link for the current day with a javascript function which lists all entries for that month (since their publish date is ignored and it's always true on the current day). But the $sDivInfo doesn't include a link because $a['link'] is also empty.

Are 'link' and 'publish_date' the wrong keys for the information they represent? Can you tell me the structure of the array that makes up an entry so I can fix it?

You can see the result here. 25th is a link and if you click it it shows all entries for January (none of them was written today). But they link to the blog itself, not the entry URL.
Kay
Contributor
 
Posts: 24
Joined: Sun Jan 11, 2009 10:48 pm

Next

Return to 2.x Extensions

Who is online

Users browsing this forum: No registered users and 1 guest