..` and not parse for the shortcodes in that HTML block. + +## Other things I've created for Bludit + +* [BS5Docs](https://bludit-bs5docs.joho.se), a fully featured Bootstrap 5 documentation theme for Bludit +* [BS5SimplyBlog](https://bludit-bs5simplyblog.joho.se), a fully featured Bootstrap 5 blog theme for Bludit +* [BS5Plain](https://bludit-bs5plain.joho.se), a simplistic and clean Bootstrap 5 blog theme for Bludit +* [Chuck Norris Quotes](https://github.com/joho1968/bludit-are-we-open), provides random Chuck Norris quotes for your Bludit page content + +## Changelog + +### 1.0.0 (2024-10-25) +* Initial release + +## Other notes + +This plugin has only been tested with PHP 8.1.x, but should work with other versions too. If you find an issue with your specific PHP version, please let me know and I will look into it. + +## License + +Please see [LICENSE](LICENSE) for a full copy of AGPLv3. + +Copyright 2024 [Joaquim Homrighausen](https://github.com/joho1968); all rights reserved. + +This file is part of are-we-open. are-we-open is free software. + +are-we-open is free software: you may redistribute it and/or modify it under +the terms of the GNU AFFERO GENERAL PUBLIC LICENSE v3 as published by the +Free Software Foundation. + +are-we-open is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU AFFERO GENERAL PUBLIC LICENSE +v3 for more details. + +You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE v3 +along with the are-we-open package. If not, write to: +``` +The Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor +Boston, MA 02110-1301, USA. +``` + +## Credits + +The Are We Open Plugin for Bludit was written by Joaquim Homrighausen while converting :coffee: into code. + +Kudos to [Diego Najar](https://github.com/dignajar) for [Bludit](https://bludit.com) :blush: + +### Whatever + +Commercial support and customizations for this plugin is available from WebbPlatsen i Sverige AB. + +If you find this Bludit add-on useful, feel free to donate, review it, and or spread the word :blush: + +If there is something you feel to be missing from this Bludit add-on, or if you have found a problem with the code or a feature, please do not hesitate to reach out to bluditcode@webbplatsen.se. diff --git a/are-we-open/languages/en.json b/are-we-open/languages/en.json new file mode 100644 index 0000000..dc67793 --- /dev/null +++ b/are-we-open/languages/en.json @@ -0,0 +1,37 @@ +{ + "plugin-data": { + "name": "Are We Open", + "description": "Display availability and/or business operating open/closed notice." + }, + "plugin-status": "Plugin status", + "plugin-enabled": "Enabled", + "plugin-disabled": "Disabled", + "help-plugin-status": "Allows you to temporarily enable/disable the plugin", + "plugin-general-status": "Are you open?", + "plugin-as-configured": "As configured by schedule below", + "plugin-closed": "We are closed, disregarding the schedule", + "help-plugin-general-status": "Allows you to override your Open status", + "weareopen-status": "According to schedule, the result", + "weareopen-for-date": "for", + "weareopen-closed": "Closed", + "weareopen-open": "Open", + "areweopen-day-configuration": "Daily schedule", + "areweopen-day-configuration-label": "Schedule for", + "monday": "Monday", + "tuesday": "Tuesday", + "wednesday": "Wednesday", + "thursday": "Thursday", + "friday": "Friday", + "saturday": "Saturday", + "sunday": "Sunday", + "areweopen-help-day-configuration": "Configuration of status for each weekday, time slots separated by a space", + "areweopen-help-day-configuration-sample": "0830-1130 1230-1700 or 0830- or 0830-1600", + "areweopen-closed-on-days": "Closed on these days", + "areweopen-closed-on-days-label": "Closed on", + "areweopen-help-closed-on-days": "You are closed on these days, regardless of schedule above", + "areweopen-closed-on-dates": "Closed on these dates", + "areweopen-help-closed-on-dates": "You are closed on these dates, regardless of schedule above, separated by a space", + "areweopen-help-closed-on-dates-sample": "20241231 20250101-20250131 ????1224-????1225", + "areweopen-usage-header": "Usage", + "areweopen-usage-help": "Simply put [areweopen_open] your content [/areweopen_open] and [areweopen_closed] your content [/areweopen_closed] somewhere in a page's content. You may, of course, use HTML to make your information stand out." +} diff --git a/are-we-open/languages/sv_SE.json b/are-we-open/languages/sv_SE.json new file mode 100644 index 0000000..6ab1a35 --- /dev/null +++ b/are-we-open/languages/sv_SE.json @@ -0,0 +1,37 @@ +{ + "plugin-data": { + "name": "Are We Open", + "description": "Visar tillgänglighet och/eller öppet/stängt status." + }, + "plugin-status": "Status för insticksprogram", + "plugin-enabled": "Aktiverat", + "plugin-disabled": "Inaktiverat", + "help-plugin-status": "Möjliggör tillfällig inaktivering utan att förlora inställningarna", + "plugin-general-status": "Har ni öppet?", + "plugin-as-configured": "Enligt schema nedan", + "plugin-closed": "Vi har stängt, oavsett vad schemat säger", + "help-plugin-general-status": "Möjliggör att tillfälligt hålla stängt oavsett schema", + "weareopen-status": "Enligt schemat så är resultatet", + "weareopen-for-date": "för", + "weareopen-closed": "Stängt", + "weareopen-open": "Öppet", + "areweopen-day-configuration": "Dagschema", + "areweopen-day-configuration-label": "Schema för", + "monday": "Måndag", + "tuesday": "Tisdag", + "wednesday": "Onsdag", + "thursday": "Torsdag", + "friday": "Fredag", + "saturday": "Lördag", + "sunday": "Söndag", + "areweopen-help-day-configuration": "Inställningar för varje veckodag, tidblock separeras med mellanslag", + "areweopen-help-day-configuration-sample": "0830-1130 1230-1700 ellerr 0830- eller 0830-1600", + "areweopen-closed-on-days": "Stängt dessa dagar", + "areweopen-closed-on-days-label": "Stängt på", + "areweopen-help-closed-on-days": "Du har stängt dessa dagar, oavsett schemat", + "areweopen-closed-on-dates": "Stängt dessa datum", + "areweopen-help-closed-on-dates": "Du har stängt dessa datum, oavsett schemat, använd mellanslag för att ange fler datum", + "areweopen-help-closed-on-dates-sample": "20241231 20250101-20250131 ????1224-????1225", + "areweopen-usage-header": "Användning", + "areweopen-usage-help": "Skriv in [areweopen_open] ditt innehåll [/areweopen_open] och [areweopen_closed] ditt innehåll [/areweopen_closed] någonstans i en sidas innehåll. Du kan, såklart, använda HTML." +} diff --git a/are-we-open/metadata.json b/are-we-open/metadata.json new file mode 100644 index 0000000..e635e19 --- /dev/null +++ b/are-we-open/metadata.json @@ -0,0 +1,10 @@ +{ + "author": "Joaquim Homrighausen", + "email": "joho@webbplatsen.se", + "website": "https://webbplatsen.se", + "version": "1.0.0", + "releaseDate": "2024-10-24", + "license": "AGPLv3", + "compatible": "3.16,3.16.1,3.16.2,3.15,3.15.0,3.15.1,3.15.2,3.15.3", + "notes": "Display availability and/or business operating open/closed notice" +} diff --git a/are-we-open/php/COPYING b/are-we-open/php/COPYING new file mode 100644 index 0000000..93c6d2e --- /dev/null +++ b/are-we-open/php/COPYING @@ -0,0 +1,10 @@ +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU AFFERO GENERAL PUBLIC LICENSE version 3 as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE v3 +along with this program. If not, see
..+ private function preProcessCustomTags( $content ) { + $shortcode_closed = $this->getCustomTagRegEx( 'areweopen_open' ); + $shortcode_open = $this->getCustomTagRegEx( 'areweopen_closed' ); + // Split the content by
tags, we will skip the content insidetags + $parts = preg_split( '/(.*?<\/pre>)/is', $content, -1, PREG_SPLIT_DELIM_CAPTURE ); + foreach( $parts as &$part ) { + // If the part is not inside a tag, process the shortcodes + if ( ! preg_match('/^.*?<\/pre>$/is', $part ) ) { + $part = $this->processCustomTags( $part, $shortcode_closed ); + $part = $this->processCustomTags( $part, $shortcode_open ); + } + } + return( implode('', $parts) ); + } + // Create array with our entire scheduled availability + private function generateAvailabilityData() { + $availability = array( + 'schedule' => array(), + 'daysclosed' => array(), + 'datesclosed' => array(), + ); + $available_times = array(); + $closed_days = array(); + foreach( $this->plugin_days_values as $k ) { + if ( ! $this->getDayActive( $k ) ) { + continue; + } else { + try { + $available_times[$k] = explode( ' ', $this->getDaySchedule( $k ) ); + } catch( \Throwable $e ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . '): Exception ' . $e->getMessage() ); + $available_times[$k] = array(); + } + } + if ( $this->getDayClosed( $k ) ) { + $closed_days[] = $k; + } + }// foreach + // Create array for excluded dates + try { + $availability['datesclosed'] = explode( ' ', $this->getClosedOnDates() ); + } catch( \Throwable $e ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . '): Exception ' . $e->getMessage() ); + $availability['datesclosed'] = array(); + } + $availability['schedule'] = $available_times; + $availability['daysclosed'] = $closed_days; + return( $availability ); + } + /* + public function beforeAdminLoad() { + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + } + */ + /* + public function afterAdminLoad() { + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + } + */ + /* + public function beforeSiteLoad() { + global $staticContent; + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + } + */ + /* + public function afterSiteLoad() { + global $staticContent; + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + } + */ + /* + public function afterAdminLoad() { + global $staticContent; + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + } + */ + /* + public function beforeAll() { + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + } + */ + /* + public function siteBodyBegin() { + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + } + */ + /* + public function siteBodyEnd() { + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + } + */ + protected function processContent() { + $text = ob_get_clean(); + if ( $text !== false ) { + if ( $this->getPluginGeneralStatus() === AREWEOPEN_PLUGIN_GENERAL_STATUS_CONFIGURED ) { + try { + require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'availabletime.class.php'; + // Fetch availability + $availability = $this->generateAvailabilityData(); + // Initialize AvailableTime object + $available_times = new AvailableTime( $availability['schedule'], $availability['datesclosed'], $availability['daysclosed'] ); + // Are We Open? + $this->areweopen_status_open = $available_times->isAvailableTime( 'now' ); + } catch( \Throwable $e ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . '): Exception ' . $e->getMessage() ); + $this->areweopen_status_open = false; + } + } else { + // Temporarily closed override is active + $this->areweopen_status_open = false; + } + $text = $this->preProcessCustomTags( $text ); + echo $text; + } + } + public function pageBegin() { + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + if ( $this->getPluginStatus() === AREWEOPEN_PLUGIN_ENABLED ) { + ob_start(); + } + } + public function pageEnd() { + if ( defined( 'AREWEOPEN_PLUGIN_DEBUG' ) && AREWEOPEN_PLUGIN_DEBUG ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . ')' ); + } + if ( $this->getPluginStatus() === AREWEOPEN_PLUGIN_ENABLED ) { + $this->processContent(); + } + } + // Form + public function form() { + global $L; + global $site; + + $html = ''; + // Plugin status + $current_setting = $this->getPluginStatus(); + $html .= ' '; + $html .= ''; + // Plugin general status + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= '' . $L->get( 'help-' . AREWEOPEN_PLUGIN_STATUS ) . ''; + $html .= ''; + $html .= ''; + // Are We Open? + try { + $now_date_time = new DateTimeImmutable( 'now' ); + } catch( \Throwable $e ) { + error_log( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) . '(' . __FUNCTION__ . '): Exception ' . $e->getMessage() ); + // That didn't work out, assume we're not available + $now_date_time = false; + } + if ( $now_date_time !== false ) { + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= '' . $L->get( 'help-' . AREWEOPEN_PLUGIN_GENERAL_STATUS ) . ''; + $html .= ''; + $html .= ''; + } else { + $html .= ''; + require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'availabletime.class.php'; + // Fetch availability + $availability = $this->generateAvailabilityData(); + // Initialize AvailableTime object + $available_times = new AvailableTime( $availability['schedule'], $availability['datesclosed'], $availability['daysclosed'] ); + $now_day_of_week = strtolower( $now_date_time->format( 'l' ) ); + $html .= '' . $L->get( 'weareopen-status' ) . ' ' . $L->get( 'weareopen-for-date' ) . ' ' . + $now_date_time->format( 'Y-m-d, H:i' ) . + ' (' . + $L->get( $now_date_time->format( 'l' ) ) . ')' . ''; + $html .= '
'; + if ( $available_times->isAvailableTime( 'now' ) ) { + $html .= '' . $L->get( 'weareopen-open' ) . ''; + } else { + $html .= '' . $L->get( 'weareopen-closed' ) . ''; + } + $html .= ''; + $html .= ''; + $html .= ''; + } + // Day configuration + $html .= ''; + $html .= $L->get( 'error-unable-to-fetch-current-time' ); + $html .= ''; + $html .= ''; + $html .= ''; + // Closed on specific days + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $day_counter = 0; + foreach( $this->plugin_days_values as $k ) { + $day_counter++; + if ( $day_counter == 6 ) { + $html .= ''; + $html .= ''; + } + $html .= ''; + $html .= ''; + $html .= ''; + } + $html .= ''; + $html .= 'getDayActive( $k ) ) { + $html .= ' checked'; + } + $html .= '>'; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= $L->get( 'areweopen-help-' . AREWEOPEN_PLUGIN_DAY_CONFIGURATION ) . ''; + $html .= '
'; + $html .= '' . $L->get( 'areweopen-help-' . AREWEOPEN_PLUGIN_DAY_CONFIGURATION . '-sample' ) . ''; + $html .= ''; + + // Closed on specific dates + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + foreach( $this->plugin_days_values as $k ) { + $html .= ''; + $html .= ''; + $html .= ''; + } + $html .= ''; + $html .= 'getDayClosed( $k ) ) { + $html .= ' checked'; + } + $html .= '>'; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= $L->get( 'areweopen-help-' . AREWEOPEN_PLUGIN_CLOSED_ON_DAYS ); + $html .= ''; + $html .= ''; + $html .= ''; + + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= $L->get( 'areweopen-help-' . AREWEOPEN_PLUGIN_CLOSED_ON_DATES ) . ''; + $html .= '
'; + $html .= '' . $L->get( 'areweopen-help-' . AREWEOPEN_PLUGIN_CLOSED_ON_DATES . '-sample' ) . ''; + $html .= ''; + + return $html; + } + + public function getPluginStatus() { + return( $this->getValue( AREWEOPEN_PLUGIN_STATUS ) ); + } + public function getPluginGeneralStatus() { + return( $this->getValue( AREWEOPEN_PLUGIN_GENERAL_STATUS ) ); + } + public function getClosedOnDates() { + return( $this->getValue( AREWEOPEN_PLUGIN_CLOSED_ON_DATES ) ); + } + public function getDayActive( $weekday ) { + return( $this->getValue( $weekday . '-active' ) ); + } + public function getDayClosed( $weekday ) { + return( $this->getValue( $weekday . '-closed' ) ); + } + public function getDaySchedule( $weekday ) { + return( $this->getValue( $weekday . '-schedule' ) ); + } + +}'; + $html .= ''; + $html .= '' . $L->get( 'areweopen-usage-header' ) . '
'; + $html .= '' . $L->get( 'areweopen-usage-help' ) . '
'; + $html .= '