public function getOutput()
 {
     /* Load language  */
     $this->registry->class_localization->loadLanguageFile(array('public_calendar'));
     /* Load calendar library */
     require_once IPSLib::getAppDir('calendar') . '/modules_public/calendar/calendars.php';
     $cal = new public_calendar_calendar_calendars($this->registry);
     $cal->makeRegistryShortcuts($this->registry);
     /* Get current month and year */
     $a = explode(',', gmdate('Y,n,j,G,i,s', time() + $this->registry->class_localization->getTimeOffset()));
     $this->now_date = array('year' => $a[0], 'mon' => $a[1]);
     /* Setup language arrays */
     $cal->month_words = array($this->lang->words['M_1'], $this->lang->words['M_2'], $this->lang->words['M_3'], $this->lang->words['M_4'], $this->lang->words['M_5'], $this->lang->words['M_6'], $this->lang->words['M_7'], $this->lang->words['M_8'], $this->lang->words['M_9'], $this->lang->words['M_10'], $this->lang->words['M_11'], $this->lang->words['M_12']);
     if (!$this->settings['ipb_calendar_mon']) {
         $cal->day_words = array($this->lang->words['D_0'], $this->lang->words['D_1'], $this->lang->words['D_2'], $this->lang->words['D_3'], $this->lang->words['D_4'], $this->lang->words['D_5'], $this->lang->words['D_6']);
     } else {
         $cal->day_words = array($this->lang->words['D_1'], $this->lang->words['D_2'], $this->lang->words['D_3'], $this->lang->words['D_4'], $this->lang->words['D_5'], $this->lang->words['D_6'], $this->lang->words['D_0']);
     }
     /* Return calendar */
     return "<div id='mini_calendars' class='calendar_wrap'>" . $cal->getMiniCalendar($this->now_date['mon'], $this->now_date['year']) . '</div><br />';
 }
 /**
  * Execute the plugin and return the HTML to show on the page.  
  * Can be called from ACP or front end, so the plugin needs to setup any appropriate lang files, skin files, etc.
  *
  * @access	public
  * @param	array 				Block data
  * @return	string				Block HTML to display or cache
  */
 public function executePlugin($block)
 {
     $config = unserialize($block['block_config']);
     //-----------------------------------------
     // Grab calendar class
     //-----------------------------------------
     require_once IPSLib::getAppDir('calendar') . '/modules_public/calendar/calendars.php';
     $calendar = new public_calendar_calendar_calendars($this->registry);
     $calendar->makeRegistryShortcuts($this->registry);
     //-----------------------------------------
     // Load lang and templs
     //-----------------------------------------
     $this->lang->loadLanguageFile(array('public_calendar'), 'calendar');
     //-----------------------------------------
     // DO some set up
     //-----------------------------------------
     $calendar->calendar_id = $config['custom']['calendar'];
     if (!count($this->caches['calendars'])) {
         $cache = array();
         $this->DB->build(array('select' => 'c.*', 'from' => array('cal_calendars' => 'c'), 'add_join' => array(array('select' => 'p.*', 'from' => array('permission_index' => 'p'), 'where' => "p.perm_type='calendar' AND perm_type_id=c.cal_id", 'type' => 'left'))));
         $this->DB->execute();
         while ($cal = $this->DB->fetch()) {
             $cache[$cal['cal_id']] = $cal;
         }
         $this->cache->setCache('calendars', $cache, array('array' => 1, 'deletefirst' => 1));
     }
     /* Calendar Cache */
     if (count($this->caches['calendars']) and is_array($this->caches['calendars'])) {
         foreach ($this->caches['calendars'] as $cal_id => $cal) {
             $selected = "";
             /* Got a perm */
             if (!$this->registry->permissions->check('view', $cal)) {
                 continue;
             }
             if ($cal['cal_id'] == $calendar->calendar_id) {
                 $calendar->calendar = $cal;
                 $selected = " selected='selected'";
             }
             $calendar->calendar_cache[$cal['cal_id']] = $cal;
         }
     }
     if (!$calendar->calendar) {
         if (count($calendar->calendar_cache)) {
             $tmp_resort = $calendar->calendar_cache;
             ksort($tmp_resort);
             reset($tmp_resort);
             $default_calid = key($tmp_resort);
             $calendar->calendar_id = $default_calid;
             $calendar->calendar = $tmp_resort[$default_calid];
             unset($tmp_resort);
         }
     }
     $calendar->calendarBuildPermissions();
     if (!is_array($calendar->calendar) or !count($calendar->calendar) or !$calendar->can_read) {
         return '';
     }
     //-----------------------------------------
     // Finally, build up the lang arrays
     //-----------------------------------------
     $calendar->month_words = array($this->lang->words['M_1'], $this->lang->words['M_2'], $this->lang->words['M_3'], $this->lang->words['M_4'], $this->lang->words['M_5'], $this->lang->words['M_6'], $this->lang->words['M_7'], $this->lang->words['M_8'], $this->lang->words['M_9'], $this->lang->words['M_10'], $this->lang->words['M_11'], $this->lang->words['M_12']);
     if (!$this->settings['ipb_calendar_mon']) {
         $calendar->day_words = array($this->lang->words['D_0'], $this->lang->words['D_1'], $this->lang->words['D_2'], $this->lang->words['D_3'], $this->lang->words['D_4'], $this->lang->words['D_5'], $this->lang->words['D_6']);
     } else {
         $calendar->day_words = array($this->lang->words['D_1'], $this->lang->words['D_2'], $this->lang->words['D_3'], $this->lang->words['D_4'], $this->lang->words['D_5'], $this->lang->words['D_6'], $this->lang->words['D_0']);
     }
     //-----------------------------------------
     // What now?
     //-----------------------------------------
     $a = explode(',', gmdate('Y,n,j,G,i,s', time() + $this->lang->getTimeOffset()));
     $now_date = array('year' => $a[0], 'mon' => $a[1], 'mday' => $a[2], 'hours' => $a[3], 'minutes' => $a[4], 'seconds' => $a[5]);
     $content = $calendar->getMiniCalendar($now_date['mon'], $now_date['year']);
     $pluginConfig = $this->returnPluginInfo();
     $templateBit = $pluginConfig['templateBit'] . '_' . $block['block_id'];
     return $this->registry->getClass('output')->getTemplate('ccs')->{$templateBit}($content);
 }
 /**
  * Rebuild Calendar Cache
  *
  * @access	public
  * @param	bool		Whether to return or not
  * @return	void
  */
 public function calendarRebuildCache($return = 0)
 {
     /* INIT */
     $this->settings['calendar_limit'] = intval($this->settings['calendar_limit']) < 2 ? 1 : intval($this->settings['calendar_limit']);
     //--------------------------------------------
     // Grab an extra day for the TZ diff
     //--------------------------------------------
     $this->settings['calendar_limit']++;
     list($month, $day, $year) = explode(',', gmdate('n,j,Y', time()));
     $timenow = gmmktime(0, 0, 0, $month, 1, $year);
     $timethen = time() + intval($this->settings['calendar_limit']) * 86400;
     $seenids = array();
     $nowtime = time() - 86400;
     $birthdays = array();
     $calevents = array();
     $calendars = array();
     $a = explode(',', gmdate('Y,n,j,G,i,s', time()));
     $day = $a[2];
     $month = $a[1];
     $year = $a[0];
     $daysinmonth = date('t', time());
     //-----------------------------------------
     // Get 24hr before and 24hr after to make
     // sure we don't break any timezones
     //-----------------------------------------
     $last_day = $day - 1;
     $last_month = $month;
     $last_year = $year;
     $next_day = $day + 1;
     $next_month = $month;
     $next_year = $year;
     //-----------------------------------------
     // Calculate dates..
     //-----------------------------------------
     if ($last_day == 0) {
         $last_month -= 1;
         $last_day = gmdate('t', time());
     }
     if ($last_month == 0) {
         $last_month = 12;
         $last_year -= 1;
     }
     if ($next_day > gmdate('t', time())) {
         $next_month += 1;
         $next_day = 1;
     }
     if ($next_month == 13) {
         $next_month = 1;
         $next_year += 1;
     }
     //--------------------------------------------
     // Get classes
     //--------------------------------------------
     require_once IPSLib::getAppDir('calendar') . '/modules_public/calendar/calendars.php';
     $calendar = new public_calendar_calendar_calendars($this->registry);
     $calendar->makeRegistryShortcuts($this->registry);
     //--------------------------------------------
     // Get stuff
     //--------------------------------------------
     $this->DB->build(array('select' => 'c.*', 'from' => array('cal_calendars' => 'c'), 'order' => 'c.cal_position ASC', 'add_join' => array(array('select' => 'p.*', 'from' => array('permission_index' => 'p'), 'where' => "p.perm_type='calendar' AND perm_type_id=c.cal_id", 'type' => 'left'))));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $row['_perm_read'] = $perms['perm_view'];
         $calendars[$row['cal_id']] = $row;
     }
     $calendar->calendarGetEventsSQL(0, 0, array('timenow' => $timenow, 'timethen' => $timethen));
     //--------------------------------------------
     // OK.. Go through days and check events
     //--------------------------------------------
     for ($i = 0; $i <= $this->settings['calendar_limit']; $i++) {
         list($_month, $tday, $year) = explode(',', gmdate('n,j,Y', $nowtime));
         $eventcache = $calendar->calendarGetDayEvents($_month, $tday, $year);
         foreach ($eventcache as $event) {
             if (!in_array($event['event_id'], $seenids)) {
                 if ($calendar->getInfoEvents($event, $_month, $tday, $year, 0)) {
                     if (!$event['event_approved']) {
                         continue;
                     }
                     unset($event['event_content'], $event['event_smilies']);
                     $event['_perm_read'] = $calendars[$event['event_calendar_id']]['perm_view'];
                     $calevents[$event['event_id']] = $event;
                 }
                 $seenids[$event['event_id']] = $event['event_id'];
             }
         }
         $nowtime += 86400;
     }
     //-----------------------------------------
     // Grab birthdays
     //-----------------------------------------
     $append_string = "";
     if (!date("L")) {
         if ($month == "2" and ($day == "28" or $day == "27")) {
             $append_string = " or( bday_month=2 AND bday_day=29 )";
         }
     }
     $this->DB->build(array('select' => 'member_id, members_seo_name, members_display_name, member_group_id, bday_day, bday_month, bday_year', 'from' => 'members', 'where' => "( bday_day={$last_day} AND bday_month={$last_month} )\n\t\t\t\t\t\t\t\t\t\t\t or ( bday_day={$day} AND bday_month={$month} )\n\t\t\t\t\t\t\t\t\t\t\t or ( bday_day={$next_day} AND bday_month={$next_month} ) {$append_string}"));
     $this->DB->execute();
     $birthdays = array();
     while ($r = $this->DB->fetch()) {
         $birthdays[$r['member_id']] = $r;
     }
     //--------------------------------------------
     // Update calendar array
     //--------------------------------------------
     $this->cache->setCache('calendar', $calevents, array('array' => 1, 'deletefirst' => 1));
     $this->cache->setCache('birthdays', $birthdays, array('array' => 1, 'deletefirst' => 1));
     if ($return) {
         $this->registry->output->global_message = $this->lang->words['c_recached'];
         $this->calendarsList();
     }
 }