/**
  * InitContent.
  * Checks the cache status and create the content.
  */
 function pmxc_InitContent()
 {
     global $sourcedir, $pmxCacheFunc, $options;
     // if visible init the content
     if ($this->visible) {
         $this->today = array('day' => (int) strftime('%d', forum_time()), 'month' => (int) strftime('%m', forum_time()), 'year' => (int) strftime('%Y', forum_time()), 'date' => strftime('%Y-%m-%d', forum_time()));
         $this->cal_startday = isset($options['calendar_start_day']) ? $options['calendar_start_day'] : $this->cfg['config']['settings']['firstday'];
         $this->cache_key .= '-' . $this->cal_startday;
         $cachedata = null;
         if (!empty($this->cfg['cache'])) {
             if (($cachedata = $pmxCacheFunc['get']($this->cache_key, $this->cache_mode)) !== null) {
                 list($curday, $this->calgrid, $this->calbirthdays, $this->calholidays, $this->calevents) = $cachedata;
                 if ($curday != $this->today['date']) {
                     $pmxCacheFunc['clear']($this->cache_key, $this->cache_mode);
                     $cachedata = null;
                 }
             }
         }
         if (empty($cachedata)) {
             include_once $sourcedir . '/Subs-Calendar.php';
             $calendarOptions = array('start_day' => $this->cal_startday, 'show_birthdays' => false, 'show_events' => false, 'show_holidays' => false, 'show_week_num' => false, 'short_day_titles' => true, 'show_next_prev' => false, 'show_week_links' => false, 'size' => 'small');
             $this->calgrid = getCalendarGrid($this->today['month'], $this->today['year'], $calendarOptions);
             $this->calbirthdays = array();
             if (!empty($this->cfg['config']['settings']['birthdays']['show'])) {
                 $start_data = isset($this->cfg['config']['settings']['birthdays']['before']) ? date('Y-m-d', time() - 86400 * intval($this->cfg['config']['settings']['birthdays']['after'])) : date('Y-m-d');
                 $end_data = isset($this->cfg['config']['settings']['birthdays']['after']) ? date('Y-m-d', time() + 86400 * intval($this->cfg['config']['settings']['birthdays']['before'])) : date('Y-m-d');
                 $temp = getBirthdayRange($start_data, $end_data);
                 foreach ($temp as $key => $val) {
                     $mnt = intval(substr($key, 5, 2));
                     if (in_array($mnt, array(11, 12)) && in_array($this->today['month'], array(1, 12))) {
                         $nkey = strval($this->today['year'] - 1) . substr($key, 4);
                     } else {
                         $nkey = strval($this->today['year']) . substr($key, 4);
                     }
                     $this->calbirthdays[$nkey] = $val;
                 }
                 ksort($this->calbirthdays);
             }
             $this->calholidays = array();
             if (!empty($this->cfg['config']['settings']['holidays']['show'])) {
                 $start_data = isset($this->cfg['config']['settings']['holidays']['before']) ? date('Y-m-d', time() - 86400 * intval($this->cfg['config']['settings']['holidays']['after'])) : date('Y-m-d');
                 $end_data = isset($this->cfg['config']['settings']['holidays']['after']) ? date('Y-m-d', time() + 86400 * intval($this->cfg['config']['settings']['holidays']['before'])) : date('Y-m-d');
                 $this->calholidays = getHolidayRange($start_data, $end_data);
                 ksort($this->calholidays);
             }
             $this->calevents = array();
             if (!empty($this->cfg['config']['settings']['events']['show'])) {
                 $start_data = isset($this->cfg['config']['settings']['events']['before']) ? date('Y-m-d', time() - 86400 * intval($this->cfg['config']['settings']['events']['after'])) : date('Y-m-d');
                 $end_data = isset($this->cfg['config']['settings']['events']['after']) ? date('Y-m-d', time() + 86400 * intval($this->cfg['config']['settings']['events']['before'])) : date('Y-m-d');
                 $events = getEventRange($start_data, $end_data);
                 ksort($events);
                 foreach ($events as $event) {
                     foreach ($event as $data) {
                         if (!array_key_exists($data['id'], $this->calevents)) {
                             $this->calevents[$data['id']] = $data;
                         }
                     }
                 }
             }
             if (!empty($this->cfg['cache'])) {
                 $cachedata = array($this->today['date'], $this->calgrid, $this->calbirthdays, $this->calholidays, $this->calevents);
                 $pmxCacheFunc['put']($this->cache_key, $cachedata, $this->cache_time, $this->cache_mode);
                 unset($cachedata);
             }
         }
     }
     return $this->visible;
 }
Example #2
0
/**
 * Retrieve all events for the given days, independently of the users offset.
 *
 * What it does:
 * - cache callback function used to retrieve the birthdays, holidays, and events between now and now + days_to_index.
 * - widens the search range by an extra 24 hours to support time offset shifts.
 * - used by the cache_getRecentEvents function to get the information needed to calculate the events taking the users time offset into account.
 *
 * @package Calendar
 * @param int $days_to_index
 * @return array
 */
function cache_getOffsetIndependentEvents($days_to_index)
{
    $low_date = strftime('%Y-%m-%d', forum_time(false) - 24 * 3600);
    $high_date = strftime('%Y-%m-%d', forum_time(false) + $days_to_index * 24 * 3600);
    return array('data' => array('holidays' => getHolidayRange($low_date, $high_date), 'birthdays' => getBirthdayRange($low_date, $high_date), 'events' => getEventRange($low_date, $high_date, false)), 'refresh_eval' => 'return \'' . strftime('%Y%m%d', forum_time(false)) . '\' != strftime(\'%Y%m%d\', forum_time(false)) || (!empty($modSettings[\'calendar_updated\']) && ' . time() . ' < $modSettings[\'calendar_updated\']);', 'expires' => time() + 3600);
}