diff options
| -rw-r--r-- | includes/bit_setup_inc.php | 29 | ||||
| -rw-r--r-- | includes/classes/Calendar.php (renamed from Calendar.php) | 133 | ||||
| -rw-r--r-- | liberty_plugins/data.calendar.php | 42 |
3 files changed, 103 insertions, 101 deletions
diff --git a/includes/bit_setup_inc.php b/includes/bit_setup_inc.php index 44444dd..85f47b7 100644 --- a/includes/bit_setup_inc.php +++ b/includes/bit_setup_inc.php @@ -1,21 +1,28 @@ <?php global $gBitSystem, $gBitSmarty, $gBitUser; -$registerHash = array( +$pRegisterHash = [ 'package_name' => 'calendar', - 'package_path' => dirname( dirname( __FILE__ ) ).'/', - 'homeable' => TRUE, -); -$gBitSystem->registerPackage( $registerHash ); + 'package_path' => dirname( dirname( __FILE__ ) ) . '/', + 'homeable' => true, +]; + +// fix to quieten down VS Code which can't see the dynamic creation of these ... +define( 'CALENDAR_PKG_NAME', $pRegisterHash['package_name'] ); +define( 'CALENDAR_PKG_URL', BIT_ROOT_URL . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'CALENDAR_PKG_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'CALENDAR_PKG_INCLUDE_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/'); +define( 'CALENDAR_PKG_CLASS_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/classes/'); +define( 'CALENDAR_PKG_ADMIN_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/admin/'); +$gBitSystem->registerPackage( $pRegisterHash ); if( $gBitSystem->isPackageActive( 'calendar' ) && $gBitUser->hasPermission( 'p_calendar_view' )) { - $menuHash = array( - 'package_name' => CALENDAR_PKG_NAME, - 'index_url' => CALENDAR_PKG_URL.'index.php', - 'menu_template' => 'bitpackage:calendar/menu_calendar.tpl', - ); + $menuHash = [ + 'package_name' => CALENDAR_PKG_NAME, + 'index_url' => CALENDAR_PKG_URL . 'index.php', + 'menu_template' => 'bitpackage:calendar/menu_calendar.tpl', + ]; $gBitSystem->registerAppMenu( $menuHash ); } -?> diff --git a/Calendar.php b/includes/classes/Calendar.php index 146b42b..f62f907 100644 --- a/Calendar.php +++ b/includes/classes/Calendar.php @@ -11,7 +11,11 @@ /** * Required setup */ -include_once( KERNEL_PKG_CLASS_PATH.'BitDate.php' ); +namespace Bitweaver\Calendar; +use Bitweaver\BitDate; +use Bitweaver\KernelTools; +use Bitweaver\Liberty\LibertyContent; + // set week offset - start with a day other than monday define( 'WEEK_OFFSET', !empty( $gBitUser->mUserPrefs['calendar_week_offset'] ) ? $gBitUser->mUserPrefs['calendar_week_offset'] : $gBitSystem->getConfig( 'calendar_week_offset', 0 ) ); @@ -21,8 +25,9 @@ define( 'WEEK_OFFSET', !empty( $gBitUser->mUserPrefs['calendar_week_offset'] ) ? class Calendar extends LibertyContent { public $display_offset; + public $mDate; - function Calendar() { + public function Calendar() { parent::__construct(); global $gBitUser; $this->mDate = new BitDate(0); @@ -40,8 +45,8 @@ class Calendar extends LibertyContent { * UTC day that the item is in, rather than the UTC day of the item. In this way * the display view provides a list of locally correct entries for each day. **/ - function getList( $pListHash ) { - $ret = array(); + public function getList( $pListHash ) { + $ret = []; $pListHash['include_data'] = TRUE; if( !empty( $pListHash['focus_date'] ) ) { @@ -73,9 +78,9 @@ class Calendar extends LibertyContent { // shift all time data by user timezone offset // and then display as a simple UTC time $item['timestamp'] = $item[$pListHash['time_limit_column']] + $this->display_offset; - $item['created'] = $item['created'] + $this->display_offset; - $item['last_modified'] = $item['last_modified'] + $this->display_offset; - $item['event_time'] = $item['event_time'] + $this->display_offset; + $item['created'] += $this->display_offset; + $item['last_modified'] += $this->display_offset; + $item['event_time'] += $this->display_offset; $item['parsed'] = self::parseDataHash( $item ); $dstart = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date( "m", $item['timestamp'], true ), $this->mDate->date( "d", $item['timestamp'], true ), $this->mDate->date( "Y", $item['timestamp'], true ) ); $ret[$dstart][] = $item; @@ -86,18 +91,14 @@ class Calendar extends LibertyContent { /** * calculate the start and stop time for the current display page **/ - function doRangeCalculations( $pDateHash ) { + public function doRangeCalculations( $pDateHash ) { $focus = $this->mDate->_getdate( $pDateHash['focus_date'], false, true ); if( $pDateHash['view_mode'] == 'month' ) { $view_start = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], 1, $focus['year'] ); $view_end = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'] + 1, 1, $focus['year'] ) - 1; } elseif( $pDateHash['view_mode'] == 'week' or $pDateHash['view_mode'] == 'weeklist') { - if ( $focus['wday'] == 0 ) { - $wd = 7 + WEEK_OFFSET; - } else { - $wd = $focus['wday'] + WEEK_OFFSET; - } + $wd = $focus['wday'] == 0 ? 7 + WEEK_OFFSET : $focus['wday'] + WEEK_OFFSET; // if we are moving out from the selected week, move us back in if( $wd > 7 ) { $wd -= 7; @@ -118,10 +119,10 @@ class Calendar extends LibertyContent { $view_end = 0; } - $ret = array( + $ret = [ 'view_start' => $view_start, - 'view_end' => $view_end, - ); + 'view_end' => $view_end, + ]; // Insert ISO dates if they are set - Used for dates pre 1902 if ( !empty($view_start_iso) ) { $ret['view_start_iso'] = $view_start_iso; @@ -131,9 +132,11 @@ class Calendar extends LibertyContent { } /** - * prepare ListHash to ensure errorfree usage + * prepare ListHash to ensure errorfree usage + * @param array pListHash hash of parameters for any getList() function + * @return array the link to display the page. **/ - public static function prepGetList( &$pListHash ) { + public function prepGetList( &$pListHash ) { $pListHash['include_data'] = TRUE; if( !empty( $pListHash['focus_date'] ) ) { $calDates = $this->doRangeCalculations( $pListHash ); @@ -161,15 +164,15 @@ class Calendar extends LibertyContent { return TRUE; } - function buildDay( $pDateHash ) { + public function buildDay( $pDateHash ) { global $gBitSystem, $gBitUser; $focus = $this->mDate->getdate( $pDateHash['focus_date'], false, true ); - $ret = array(); + $ret = []; if( $pDateHash['view_mode'] == 'day' ) { // calculare what the visible day view range is - $day_start = isset( $gBitUser->mUserPrefs['calendar_day_start'] ) ? $gBitUser->mUserPrefs['calendar_day_start'] : $gBitSystem->getConfig( 'calendar_day_start', 0 ); - $day_end = isset( $gBitUser->mUserPrefs['calendar_day_end'] ) ? $gBitUser->mUserPrefs['calendar_day_end'] : $gBitSystem->getConfig( 'calendar_day_end', 24 ); + $day_start = $gBitUser->mUserPrefs['calendar_day_start'] ?? $gBitSystem->getConfig( 'calendar_day_start', 0 ); + $day_end = $gBitUser->mUserPrefs['calendar_day_end'] ?? $gBitSystem->getConfig( 'calendar_day_end', 24 ); $start_time = $this->mDate->mktime( 0, 0, 0, $focus['mon'], $focus['mday'], $focus['year'] ) + ( 60 * 60 * $day_start ); $stop_time = $this->mDate->mktime( 0, 0, 0, $focus['mon'], $focus['mday'] + 1, $focus['year'] ) - ( 60 * 60 * ( 24 - $day_end ) ); $hours_count = ( $stop_time - $start_time ) / ( 60 * 60 ); @@ -200,31 +203,31 @@ class Calendar extends LibertyContent { * offsets provided by tz_offset information. Daylight saving information * is not available via this route! **/ - function buildCalendarNavigation( $pDateHash ) { + public function buildCalendarNavigation( $pDateHash ) { global $gBitUser, $gBitSystem; $today = $this->mDate->getdate( time(), false, true ); $focus = $this->mDate->getdate( $pDateHash['focus_date'], false, true ); - $ret = array( - 'before' => array( + $ret = [ + 'before' => [ 'day' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] - 1, $focus['year'] ), 'week' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] - 7, $focus['year'] ), 'month' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'] - 1, $focus['mday'], $focus['year'] ), 'year' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'], $focus['year'] - 1 ), - ), - 'after' => array( + ], + 'after' => [ 'day' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] + 1, $focus['year'] ), 'week' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] + 7, $focus['year'] ), 'month' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'] + 1, $focus['mday'], $focus['year'] ), 'year' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'], $focus['year'] + 1 ), - ), - 'focus_month' => $focus['mon'], - 'focus_year' => $focus['year'], - 'focus_date' => $focus[0], - 'today' => $this->mDate->gmmktime( 0, 0, 0, $today['mon'], $today['mday'], $today['year'] ), - 'tz_flag' => $gBitUser->getPreference('site_display_utc', "Local"), + ], + 'focus_month' => $focus['mon'], + 'focus_year' => $focus['year'], + 'focus_date' => $focus[0], + 'today' => $this->mDate->gmmktime( 0, 0, 0, $today['mon'], $today['mday'], $today['year'] ), + 'tz_flag' => $gBitUser->getPreference( 'site_display_utc', "Local" ), 'display_focus_date' => $focus[0], - ); + ]; return $ret; } @@ -237,7 +240,7 @@ class Calendar extends LibertyContent { * timezone and daylight saving, but the USERS daylight saving information * is not available, which will cause some problems! **/ - function buildMonth( $pDateHash ) { + public function buildMonth( $pDateHash ) { global $gBitSmarty; $focus = $this->mDate->getdate( $pDateHash['focus_date'], false, true ); @@ -250,10 +253,10 @@ class Calendar extends LibertyContent { $prev_month_year = $prev_month_end_info['year']; // Build a two-dimensional array of UNIX timestamps. - $cal = array(); + $cal = []; // Start the first row with the final day( s ) of the previous month. - $week = array(); + $week = []; $month_begin = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], WEEK_OFFSET, $focus['year'] ); $month_begin_day_of_week = $this->mDate->dayOfWeek( $focus['year'], $focus['mon'], WEEK_OFFSET ); $days_in_prev_month = $this->mDate->daysInMonth( $prev_month, $prev_month_year ); @@ -272,7 +275,7 @@ class Calendar extends LibertyContent { // re-initialize $day_of_week and $week $day_of_week = 0; - $week = array(); + $week = []; } $week[]['day'] = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $i, $focus['year'] ); $day_of_week++; @@ -288,18 +291,17 @@ class Calendar extends LibertyContent { // Modify offset to fix roll over on week numbers // This is required because the week numbers are calculated for Sunday // Offseting the result in BitDate is the real solution - if ( WEEK_OFFSET == 7 ) $offset = $focus['mday'] + 1; - else $offset = $focus['mday'] + 1 + WEEK_OFFSET; + $offset = WEEK_OFFSET == 7 ? $focus['mday'] + 1 : $focus['mday'] + 1 + WEEK_OFFSET; // this week number has to be calculated, since the cal start can be configured $week_num = $this->mDate->weekOfYear( $focus['year'], $focus['mon'], $offset ); // if we only want to see a weeks / days worth of data, nuke all xs data if( $pDateHash['view_mode'] == 'week' or $pDateHash['view_mode'] == 'weeklist' ) { $cal = $calendar[$week_num]; - $calendar = array(); + $calendar = []; $calendar[$week_num] = $cal; } elseif( $pDateHash['view_mode'] == 'day' ) { - $calendar = array(); + $calendar = []; $calendar[$week_num][]['day'] = $pDateHash['focus_date']; } @@ -307,7 +309,7 @@ class Calendar extends LibertyContent { } // Setup the content types for use in the calendar. - function setupContentTypes() { + public function setupContentTypes() { global $gLibertySystem, $gBitSmarty, $gBitSystem; foreach( $gLibertySystem->mContentTypes as $cName => $cType ) { if ( $gBitSystem->isPackageActive( $cType['handler_package'] ) ) { @@ -319,19 +321,19 @@ class Calendar extends LibertyContent { } // Setup the day names for use in the calendar - function setupDayNames() { + public function setupDayNames() { global $gBitSmarty; // set up daynames for the calendar - $dayNames = array( - tra( "Monday" ), - tra( "Tuesday" ), - tra( "Wednesday" ), - tra( "Thursday" ), - tra( "Friday" ), - tra( "Saturday" ), - tra( "Sunday" ), - ); + $dayNames = [ + KernelTools::tra( "Monday" ), + KernelTools::tra( "Tuesday" ), + KernelTools::tra( "Wednesday" ), + KernelTools::tra( "Thursday" ), + KernelTools::tra( "Friday" ), + KernelTools::tra( "Saturday" ), + KernelTools::tra( "Sunday" ), + ]; // depending on what day we want to view first, we need to adjust the dayNames array for( $i = 0; $i < WEEK_OFFSET; $i++ ) { @@ -351,19 +353,15 @@ class Calendar extends LibertyContent { } elseif( !isset( $pStore['content_type_guid'] ) && $gBitUser->getPreference( 'calendar_default_guids' ) && $gBitUser->isRegistered() ) { $pStore['content_type_guid'] = unserialize( $gBitUser->getPreference( 'calendar_default_guids' ) ); } elseif( !isset( $pStore['content_type_guid'] ) ) { - $pStore['content_type_guid'] = array(); + $pStore['content_type_guid'] = []; } elseif( isset( $pRequest["refresh"] ) && !isset( $pRequest["content_type_guid"] ) ) { - $pStore['content_type_guid'] = array(); + $pStore['content_type_guid'] = []; } // set up the todate if( !empty( $pRequest["todate"] ) ) { // clean up todate. who knows where this has come from - if ( is_numeric( $pRequest['todate'] ) ) { - $pStore['focus_date'] = $pRequest['todate'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date( 'm', $pRequest['todate'], true ), $this->mDate->date( 'd', $pRequest['todate'], true ), $this->mDate->date( 'Y', $pRequest['todate'], true ) ); - } else { - $pStore['focus_date'] = $pRequest['todate'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date2( 'm', $pRequest['todate'], true ), $this->mDate->date2( 'd', $pRequest['todate'], true ), $this->mDate->date2( 'Y', $pRequest['todate'], true ) ); - } + $pStore['focus_date'] = is_numeric( $pRequest['todate'] ) ? $pRequest['todate'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date( 'm', $pRequest['todate'], true ), $this->mDate->date( 'd', $pRequest['todate'], true ), $this->mDate->date( 'Y', $pRequest['todate'], true ) ) : $pRequest['todate'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date2( 'm', $pRequest['todate'], true ), $this->mDate->date2( 'd', $pRequest['todate'], true ), $this->mDate->date2( 'Y', $pRequest['todate'], true ) ); } elseif( !empty( $pStore['focus_date'] ) ) { $pRequest["todate"] = $pStore['focus_date']; } else { @@ -379,10 +377,10 @@ class Calendar extends LibertyContent { } } - function getEvents(&$pListHash) { + public function getEvents(&$pListHash) { global $gBitSystem, $gLibertySystem; - $bitEvents = array(); + $bitEvents = []; if ( !empty( $pListHash['content_type_guid'] ) ) { // Verify that the type is still active foreach ( $pListHash['content_type_guid'] as $index => $type ) { @@ -398,7 +396,7 @@ class Calendar extends LibertyContent { return $bitEvents; } - function buildCalendar(&$pListHash, &$pDateHash) { + public function buildCalendar(&$pListHash, &$pDateHash) { global $gBitSmarty, $gBitSystem; if( isset($pDateHash['focus_date']) && !isset($pListHash['focus_date']) ) { @@ -415,7 +413,7 @@ class Calendar extends LibertyContent { foreach( $calMonth as $w => $week ) { foreach( $week as $d => $day ) { - $dayEvents = array(); + $dayEvents = []; if( !empty( $bitEvents[$day['day']] ) ) { $i = 0; foreach( $bitEvents[$day['day']] as $bitEvent ) { @@ -447,8 +445,8 @@ class Calendar extends LibertyContent { } } } - $gBitSmarty->assignByRef( 'calDay', $calDay ); - $gBitSmarty->assignByRef( 'calMonth', $calMonth ); + $gBitSmarty->assign( 'calDay', $calDay ); + $gBitSmarty->assign( 'calMonth', $calMonth ); } function setupCalendar($pShowContentOptions = TRUE) { @@ -479,8 +477,7 @@ class Calendar extends LibertyContent { // Asssign it so templates see it. $gBitSmarty->assign('baseCalendarUrl', $pBaseUrl); - $gBitSystem->display( 'bitpackage:calendar/calendar.tpl', $pTitle , array( 'display_mode' => 'display' )); + $gBitSystem->display( 'bitpackage:calendar/calendar.tpl', $pTitle , [ 'display_mode' => 'display' ]); } } -?> diff --git a/liberty_plugins/data.calendar.php b/liberty_plugins/data.calendar.php index 7851a6e..cc7861a 100644 --- a/liberty_plugins/data.calendar.php +++ b/liberty_plugins/data.calendar.php @@ -1,4 +1,8 @@ <?php + +use Bitweaver\BitDate; +use Bitweaver\KernelTools; + /** * @version $Revision$ * @package liberty @@ -24,17 +28,17 @@ */ define( 'PLUGIN_GUID_DATACALENDAR', 'datacalendar' ); global $gLibertySystem; -$pluginParams = array ( - 'tag' => 'CALENDAR', - 'auto_activate' => TRUE, - 'requires_pair' => FALSE, +$pluginParams = [ + 'tag' => 'CALENDAR', + 'auto_activate' => true, + 'requires_pair' => false, 'load_function' => 'data_calendar', - 'title' => 'Calendar', - 'help_page' => 'DataPluginCalendar', - 'description' => tra("Displays a mini calendar that links to the calendar package."), - 'syntax' => " {CALENDAR} ", - 'plugin_type' => DATA_PLUGIN -); + 'title' => 'Calendar', + 'help_page' => 'DataPluginCalendar', + 'description' => KernelTools::tra( "Displays a mini calendar that links to the calendar package." ), + 'syntax' => " {CALENDAR} ", + 'plugin_type' => DATA_PLUGIN, +]; $gLibertySystem->registerPlugin( PLUGIN_GUID_DATACALENDAR, $pluginParams ); $gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATACALENDAR ); @@ -61,7 +65,7 @@ function data_calendar( $data, $params ) { $last = $bitDate->getDate($last_time); $next = $bitDate->getDate($next_time); - $days = array(); + $days = []; for ($i = 2; $i < 9; $i++) { // Start from known sunday. $timestamp = $bitDate->mktime(0, 0, 0, 1, $i, 2000); @@ -69,10 +73,10 @@ function data_calendar( $data, $params ) { } // Build a two-dimensional array of UNIX timestamps. - $calendar = array(); + $calendar = []; // Start with last days of previous month. - $week = array(); + $week = []; $month_begin = $bitDate->mktime(0, 0, 0, $month, 1, $year); $month_begin_dow = strftime('%w', $month_begin); @@ -95,7 +99,7 @@ function data_calendar( $data, $params ) { // Done with row $dow = 0; unset($week); - $week = array(); + $week = []; } $d['time'] = $bitDate->mktime(0, 0, 0, $month, $i, $year); $d['dim'] = false; @@ -127,17 +131,11 @@ function data_calendar( $data, $params ) { $gBitSmarty->assign('today', $time); // Assign a base url - if (empty($params['events'])) { - $pBaseUrl = CALENDAR_PKG_URL.'index.php'; - } - else { - $pBaseUrl = EVENTS_PKG_URL.'calendar.php'; - } + $pBaseUrl = ( empty( $params['events'] ) ) ? CALENDAR_PKG_URL . 'index.php' : CALENDAR_PKG_URL . 'calendar.php'; $gBitSmarty->assign('baseCalendarUrl', $pBaseUrl); return $gBitSmarty->fetch('bitpackage:calendar/minical.tpl'); } return '<div class="error">Calendar Package Not Active</div>'; -} -?> +}
\ No newline at end of file |
