PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Frontend
<?php namespace WilokeListingTools\Frontend; use WilokeListingTools\Framework\Helpers\DebugStatus; use WilokeListingTools\Framework\Helpers\GetSettings; use WilokeListingTools\Framework\Helpers\Time; use WilokeListingTools\MetaBoxes\Listing; class BusinessHours { public static $aTimezones; public static $aUTCs; /** * Get Time Format * * @param [Int] $listingID * * @return String */ public static function getTimeFormat($listingID) { $timeFormat = GetSettings::getPostMeta($listingID, 'timeFormat', '', 'int'); if (empty($timeFormat) || $timeFormat === 'inherit') { $timeFormat = (int)\WilokeThemeOptions::getOptionDetail('timeformat'); } return $timeFormat; } public static function isEnableBusinessHour($post = null) { $postID = is_numeric($post) ? $post : $post->ID; if (!empty($postID)) { $planID = GetSettings::getListingBelongsToPlan($postID); if (!empty($planID) && get_post_status($planID) == 'publish' && get_post_type($planID) == 'listing_plan') { $aPlanSettings = GetSettings::getPlanSettings($planID); if ( isset($aPlanSettings['toggle_business_hours']) && $aPlanSettings['toggle_business_hours'] == 'disable' ) { return false; } } $hourMode = GetSettings::getPostMeta($postID, 'hourMode'); if (!$hourMode || $hourMode == 'no_hours_available') { return false; } return apply_filters('wilcity/is_enable_business_hour', true); } return false; } public static function getTimezone($postID) { // return get_option('timezone_string'); $postID = is_numeric($postID) ? $postID : $postID->ID; if (isset(self::$aTimezones[$postID])) { return self::$aTimezones[$postID]; } $individualTimeFormat = GetSettings::getPostMeta($postID, 'timezone'); if (!empty($individualTimeFormat)) { self::$aTimezones[$postID] = GetSettings::getPostMeta($postID, 'timezone'); } else { self::$aTimezones[$postID] = get_option('timezone_string'); } return self::$aTimezones[$postID]; } public static function getListingUTC($post) { $timezone = self::getTimezone($post); return Time::findUTCOffsetByTimezoneID($timezone); } public static function getTodayIndex($postID = '') { $siteTimeString = self::getListingUTC(get_post($postID)); $utcTimestampNow = \time(); return Time::convertToNewDateFormat($utcTimestampNow, 'w', $siteTimeString); } public static function getTodayKey($postID = '') { return Time::getDayKey(self::getTodayIndex($postID)); } public static function getPrevDayKey($postID = '') { $todayIndex = self::getTodayIndex($postID); $prevIndex = $todayIndex === 0 ? 6 : $todayIndex; return Time::getDayKey($prevIndex); } public static function getTodayBusinessHours($postID) { if (!is_numeric($postID)) { $postID = $postID->ID; } $todayKey = self::getTodayKey($postID); return Listing::getBusinessHoursOfDay($postID, $todayKey); } public static function getPrevBusinessHour($postID) { if (!is_numeric($postID)) { $postID = $postID->ID; } $prevDayKey = self::getPrevDayKey($postID); return Listing::getBusinessHoursOfDay($postID, $prevDayKey); } public static function isSecondHourExists($aTodayBusinessHour) { if ( empty($aTodayBusinessHour['secondOpenHour']) || empty($aTodayBusinessHour['secondCloseHour']) || $aTodayBusinessHour['secondOpenHour'] == $aTodayBusinessHour['secondCloseHour'] ) { return false; } return true; } public static function invalidFirstHours($aTodayBusinessHour) { if ( empty($aTodayBusinessHour['firstOpenHour']) || empty($aTodayBusinessHour['firstCloseHour']) || ($aTodayBusinessHour['firstOpenHour'] == $aTodayBusinessHour['firstCloseHour'] && $aTodayBusinessHour['firstCloseHour'] !== '24:00:00') ) { return true; } return false; } public static function getAllBusinessHours($postID) { if (!is_numeric($postID)) { $postID = $postID->ID; } $hourMode = GetSettings::getPostMeta($postID, 'hourMode'); if (in_array($hourMode, ['always_open', 'no_hours_available'])) { return [ 'mode' => $hourMode ]; } $aDays = array_keys(wilokeListingToolsRepository()->get('general:aDayOfWeek', false)); $aOperatingTimes = []; foreach ($aDays as $day) { $aOperatingTimes[$day] = Listing::getBusinessHoursOfDay($postID, $day); } return [ 'mode' => $hourMode, 'operating_times' => $aOperatingTimes, 'timezone' => self::getTimezone($postID) ]; } public static function getCurrentBusinessHourStatus($postID, $aTodayBusinessHour = []) { if (!is_numeric($postID)) { $postID = $postID->ID; } $openNow = __('Open now', 'wiloke-listing-tools'); $closed = __('Closed', 'wiloke-listing-tools'); $hourMode = GetSettings::getPostMeta($postID, 'hourMode'); if (empty($aTodayBusinessHour)) { if ($hourMode == 'always_open') { return [ 'status' => 'open', 'class' => 'color-secondary', 'text' => $openNow ]; } $aTodayBusinessHour = self::getTodayBusinessHours($postID); } if (!$aTodayBusinessHour || $aTodayBusinessHour['isOpen'] == 'no') { return [ 'status' => 'day_off', 'class' => 'color-quaternary', 'text' => esc_html__('Day Off', 'wiloke-listing-tools') ]; } $todayKey = self::getTodayKey($postID); $timezone = self::getTimezone($postID); $today = date('Y-m-d', time()); $firstStart = Time::convertToNewDateFormat( strtotime($today.' '.$aTodayBusinessHour['firstOpenHour']), 'H:i:s' ); $firstClosed = Time::convertToNewDateFormat( strtotime($today.' '.$aTodayBusinessHour['firstCloseHour']), 'H:i:s' ); $currentHour = Time::convertToNewDateFormat(time(), 'H:i:s', $timezone); if (Time::compareDateTime($currentHour, $firstStart, '>=') && Time::compareDateTime($currentHour, $firstClosed, '<=')) { return array_merge([ 'status' => 'open', 'class' => 'color-secondary', 'text' => $openNow, 'dayKey' => $todayKey ], $aTodayBusinessHour); } $lastOpen = $firstStart; $lastEnd = $firstClosed; // If the closed is middle night, We should understand that it's 23:59:59 if ($lastEnd == '00:00:00') { $lastEnd = '23:59:59'; } if (self::isSecondHourExists($aTodayBusinessHour)) { $secondStart = Time::convertToNewDateFormat( strtotime($today.' '.$aTodayBusinessHour['secondOpenHour']), 'H:i:s' ); $secondClosed = Time::convertToNewDateFormat( strtotime($today.' '.$aTodayBusinessHour['secondCloseHour']), 'H:i:s' ); if (Time::compareDateTime($currentHour, $secondStart, '>=') && Time::compareDateTime($currentHour, $secondClosed, '<=')) { return array_merge([ 'status' => 'open', 'class' => 'color-secondary', 'text' => $openNow, 'dayKey' => $todayKey ], $aTodayBusinessHour); } $lastOpen = $secondStart; $lastEnd = $secondClosed; if ($lastEnd == '00:00:00') { $lastEnd = '23:59:59'; } } if ($lastEnd === '23:59:59') { if (Time::compareDateTime($currentHour, $lastOpen, '>=') && Time::compareDateTime($currentHour, $lastEnd, '<=')) { return array_merge([ 'status' => 'open', 'class' => 'color-secondary', 'text' => $openNow, 'dayKey' => $todayKey ], $aTodayBusinessHour); } } if (Time::compareDateTime($lastOpen, $lastEnd, '>') && ( Time::compareDateTime($currentHour, $lastOpen, '>') || Time::compareDateTime($currentHour, $lastEnd, '<') ) ) { return array_merge([ 'status' => 'open', 'class' => 'color-secondary', 'text' => $openNow, 'dayKey' => $todayKey ], $aTodayBusinessHour); } $aPrevDayHours = self::getPrevBusinessHour($postID); if ($aPrevDayHours['isOpen'] == 'yes') { $lastClosedHour = !empty($aPrevDayHours['secondCloseHour']) ? $aPrevDayHours['secondCloseHour'] : $aPrevDayHours['secondCloseHour']; if (!empty($lastClosedHour)) { $secondClosed = Time::convertToNewDateFormat(strtotime($today.' '.$lastClosedHour), 'H:i:s'); $secondClosedToNumber = abs(str_replace(':', '', $lastClosedHour)); if ($secondClosedToNumber < 70100 && Time::compareDateTime($secondClosed, $currentHour, '>=')) { $prevDayKey = self::getPrevDayKey($postID); return array_merge($aPrevDayHours, [ 'status' => 'open', 'class' => 'color-secondary', 'text' => $openNow, 'dayKey' => $prevDayKey, 'isPrevDay' => true // this business is overnight and it's opening ]); } } } $aTodayBusinessHour = is_array($aTodayBusinessHour) ? $aTodayBusinessHour : []; return wp_parse_args([ 'status' => 'close', 'class' => 'color-quaternary', 'text' => $closed, 'dayKey' => $todayKey ], $aTodayBusinessHour); } }
[+]
..
[-] SingleListing.php
[edit]
[-] CheckoutPage.php
[edit]
[-] PriceRange.php
[edit]
[-] User.php
[edit]
[-] EnqueueScripts.php
[edit]
[-] BusinessHours.php
[edit]
[-] GenerateURL.php
[edit]
[-] Gallery.php
[edit]