Changeset 2868385
- Timestamp:
- 02/20/2023 08:05:18 PM (3 years ago)
- Location:
- promissa/trunk
- Files:
-
- 3 edited
-
functions.php (modified) (4 diffs)
-
readme.txt (modified) (1 diff)
-
shortcodes/intentions.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
promissa/trunk/functions.php
r2753313 r2868385 81 81 } 82 82 } 83 84 if (!function_exists('idiv')) { 85 function idiv($a, $b) 86 { 87 return floor($a / $b); 88 } 89 } 90 91 /** 92 * Calculates the Easter date for a given year 93 * 94 * @param int $y 95 * @return DateTime 96 */ 97 if (!function_exists('EasterDate')) { 98 function EasterDate($y) 99 { 100 $firstdig1 = array(21, 24, 25, 27, 28, 29, 30, 31, 32, 34, 35, 38); 101 $firstdig2 = array(33, 36, 37, 39, 40); 102 103 $firstdig = idiv($y, 100); 104 $remain19 = $y % 19; 105 106 $temp = idiv($firstdig - 15, 2) + 202 - 11 * $remain19; 107 108 if (in_array($firstdig, $firstdig1)) { 109 $temp = $temp - 1; 110 } 111 if (in_array($firstdig, $firstdig2)) { 112 $temp = $temp - 2; 113 } 114 115 $temp = $temp % 30; 116 117 $ta = $temp + 21; 118 if ($temp == 29) { 119 $ta = $ta - 1; 120 } 121 if ($temp == 28 and $remain19 > 10) { 122 $ta = $ta - 1; 123 } 124 125 $tb = ($ta - 19) % 7; 126 127 $tc = (40 - $firstdig) % 4; 128 if ($tc == 3) { 129 $tc = $tc + 1; 130 } 131 if ($tc > 1) { 132 $tc = $tc + 1; 133 } 134 135 $temp = $y % 100; 136 $td = ($temp + idiv($temp, 4)) % 7; 137 138 $te = ((20 - $tb - $tc - $td) % 7) + 1; 139 $d = $ta + $te; 140 141 if ($d > 31) { 142 $d = $d - 31; 143 $m = 4; 144 } else { 145 $m = 3; 146 } 147 return new DateTime("$y-$m-$d", new DateTimeZone('Europe/Amsterdam')); 148 } 149 } 150 83 151 if (!function_exists('FeastDate_YN')) : 84 152 function FeastDate_YN($date) … … 88 156 return true; 89 157 endif; 90 $feasts = array('08-12', '25-12', '01-01', '06-01', '19-03', '25-03', '24-06', '29-06', '15-08', '01-11', '07-11');158 $feasts = array('08-12','24-12', '25-12', '26-12', '01-01', '06-01', '19-03', '25-03', '24-06', '29-06', '15-08', '01-11', '07-11'); 91 159 if (in_array($datetime->format('d-m'), $feasts)) : 92 160 return true; 93 161 endif; 94 162 95 $easter = easter_date($datetime->format('Y'));96 $specialDates = array( date('Y-m-d', $easter + (39 * 24 * 60 * 60)), date('Y-m-d', $easter + (68 * 24 * 60 * 60)));163 $easter = EasterDate($datetime->format('Y')); 164 $specialDates = array($easter->add(new DateInterval('P39D'))->format('Y-m-d'), $easter->add(new DateInterval('P68D'))->format('Y-m-d')); 97 165 if (in_array($datetime->format('Y-m-d'), $specialDates)) : 98 166 return true; … … 318 386 function ProMissaREST($page, $filter = '') 319 387 { 320 $promissa = get_option('promissa'); 321 $url = 'https://api.promissa.nl/v1.5/records/' . $page . $filter; 322 $args = array( 323 'headers' => array( 324 'Authorization' => 'Basic ' . base64_encode($promissa['private'] . ":" . $promissa['public']) 325 ) 326 ); 327 if(empty($filter)) : 328 $url .= '?'; 329 else : 330 $url .= '&'; 331 endif; 332 $response = wp_remote_get( $url . 'exclude=api_private,domain', $args ); 333 334 $body = wp_remote_retrieve_body( $response ); 335 336 $manage = json_decode($body, true); 337 if($manage["records"] != NULL) : 338 return $manage["records"]; 339 else : 340 //var_dump($response ); 341 return $manage["records"]; 342 endif; 388 try { 389 $promissa = get_option('promissa'); 390 $url = 'https://api.promissa.nl/v1.6/records/' . $page . $filter; 391 $args = array( 392 'headers' => array( 393 'Authorization' => 'Basic ' . base64_encode($promissa['private'] . ":" . $promissa['public']) 394 ) 395 ); 396 if(empty($filter)) : 397 $url .= '?'; 398 else : 399 $url .= '&'; 400 endif; 401 $response = wp_remote_get( $url . 'exclude=api_private,domain', $args ); 402 403 $body = wp_remote_retrieve_body( $response ); 404 405 $manage = json_decode($body, true); 406 if($manage["records"] != NULL) : 407 return $manage["records"]; 408 else : 409 //var_dump($response ); 410 return $manage["records"]; 411 endif; 412 } catch (Exception $e) { 413 414 } 343 415 344 416 } … … 348 420 function ProMissaREST_POST($page, $data = array()) 349 421 { 350 $promissa = get_option('promissa'); 351 $url = 'https://api.promissa.nl/v1.5/records/' . $page; 352 $args = array( 353 'headers' => array( 354 'Authorization' => 'Basic ' . base64_encode($promissa['private'] . ":" . $promissa['public']) 355 ), 356 'body' => $data, 357 'method' => 'POST', 358 'data_format' => 'body', 359 ); 360 361 $response = wp_remote_post($url, $args); 362 363 //varDump($response); 422 try { 423 $promissa = get_option('promissa'); 424 $url = 'https://api.promissa.nl/v1.5/records/' . $page; 425 $args = array( 426 'headers' => array( 427 'Authorization' => 'Basic ' . base64_encode($promissa['private'] . ":" . $promissa['public']) 428 ), 429 'body' => $data, 430 'method' => 'POST', 431 'data_format' => 'body', 432 ); 433 434 $response = wp_remote_post($url, $args); 435 436 //varDump($response); 437 } catch (Exception $e) { 438 } 364 439 } 365 440 } -
promissa/trunk/readme.txt
r2753313 r2868385 80 80 == Changelog == 81 81 82 = 1.4.2 = 83 84 * Fixed problem with the unix timestamp bug for the easter date 85 82 86 = 1.4.1 = 83 87 -
promissa/trunk/shortcodes/intentions.php
r2753313 r2868385 1 1 <?php 2 if (!function_exists('promissa_intentions_handler')) :2 if (!function_exists('promissa_intentions_handler')) : 3 3 define('EOL_SPLIT', '- '); 4 4 define('EOL_SPLIT_SEARCH', ' - '); 5 5 define('EOL_SPLIT_REPLACE', '$#'); 6 define('WEEK_SPLIT_HOUR', 13); 7 function promissa_intentions_handler( $atts, $content = null ) 6 define('WEEK_SPLIT_HOUR', 15); 7 define('WEEK_SPLIT_TIME', (WEEK_SPLIT_HOUR - 12) . 'pm'); 8 function promissa_intentions_handler($atts, $content = null) 8 9 { 9 10 $timestamp = time(); 10 //if (is_user_logged_in()) :11 // $timestamp = strtotime('2021-11-04 14:00:00');12 //endif;13 $atts_extended = shortcode_atts(array(14 'church_id' => '',15 'subtitle' => '',16 'limit' => 100,17 'show_title' => 'false',18 ), $atts);19 extract($atts_extended);11 if (is_user_logged_in()) : 12 $timestamp = strtotime('2022-09-11 16:00:00'); 13 endif; 14 $atts_extended = shortcode_atts(array( 15 'church_id' => '', 16 'subtitle' => '', 17 'limit' => 100, 18 'show_title' => 'false', 19 ), $atts); 20 extract($atts_extended); 20 21 $itemCount = 0; 21 22 $single_church = (isset($church_id) && !empty($church_id)); 22 23 $intentions = NULL; 23 24 $nextWeekOffset = 1; 24 25 $offset = (date('N', $timestamp) == 5 ? (date('H', $timestamp) <= WEEK_SPLIT_HOUR ? 1 : 2) : (date('N', $timestamp) == 6 ? 1 : 1)); 26 $nextWeek = new DateTime('friday next week'); 27 if(date('N', $timestamp) == 7) : 28 $nextWeekOffset = 0; 29 $nextWeek = new DateTime('friday next week'); 30 elseif(date('N', $timestamp) < 5 || (date('N', $timestamp) == 5 && (date('H', $timestamp) <= WEEK_SPLIT_HOUR))) : 31 $nextWeekOffset = 0; 32 $nextWeek = new DateTime('friday this week'); 33 endif; 34 $nextWeek->add(new DateInterval('PT13H')); 35 if(is_user_logged_in()) : 36 $nextWeek->add(new DateInterval('P14D')); 37 endif; 38 if (false && is_user_logged_in()) : 39 $now = strtotime('monday last week') - (14 * 24 * 60 * 70) - (60 * 60 * 60); 40 $from = $timestamp + ($offset * 24 * 60 * 60) - (14 * 24 * 60 * 70); 41 else : 42 $now = strtotime('monday this week') - (60 * 60 * 60); 43 $from = $timestamp + ($offset * 24 * 60 * 60); 44 endif; 45 $to = $timestamp + ((is_user_logged_in() ? 21 : 3) * 24 * 60 * 60); 46 $to2 = $now + (3 * 7 * 24 * 60 * 60); 47 48 49 $fromDate = DateTimeAdd(((new DateTime())->setISODate(date('Y', $from), date('W', $from) + $nextWeekOffset)), -2, 'Y-m-d 13:00:00'); 50 $toDate = DateTimeAdd(((new DateTime())->setISODate(date('Y', $to), date('W', $to) + 1)), 'P5D', 'Y-m-d 13:00:00'); 25 switch(date('w', $timestamp)) : 26 case 0: //Sunday 27 case 1: //Monday 28 case 2: //Tuesday 29 case 3: //Wednesday 30 case 4: //Thursday 31 $from = strtotime('Last Saturday ' . WEEK_SPLIT_TIME); 32 $to = strtotime('Next Saturday ' . WEEK_SPLIT_TIME); 33 $nextWeek = new DateTime('Saturday next week'); 34 //varDump($from); 35 break; 36 case 5: //Friday 37 if(date('H', $timestamp) <= WEEK_SPLIT_HOUR) : 38 $from = strtotime('Last Saturday ' . WEEK_SPLIT_TIME); 39 $to = strtotime('Next Saturday ' . WEEK_SPLIT_TIME); 40 else: 41 $from = strtotime('Last Saturday ' . WEEK_SPLIT_TIME); 42 $to = strtotime('Saturday next week ' . WEEK_SPLIT_TIME); 43 endif; 44 $nextWeek = new DateTime('Saturday next week'); 45 break; 46 case 6: //Saturday 47 $from = strtotime('Today ' . WEEK_SPLIT_TIME); 48 $to = strtotime('Next Saturday ' . WEEK_SPLIT_TIME); 49 $nextWeek = new DateTime('Saturday next week'); 50 break; 51 endswitch; 52 53 //$now = strtotime('Last Saturday ' . WEEK_SPLIT_TIME); 54 //$to2 = strtotime('Next Saturday ' . WEEK_SPLIT_TIME); 55 56 //$fromDate = DateTimeAdd(((new DateTime())->setISODate(date('Y', $from), date('W', $from) + $nextWeekOffset)), -2, 'Y-m-d 13:00:00'); 57 $fromDate = date('Y-m-d H:i:s', $from); 58 //varDump($fromDate); 59 //$toDate = DateTimeAdd(((new DateTime())->setISODate(date('Y', $to), date('W', $to) + 1)), 'P5D', 'Y-m-d 13:00:00'); 60 $toDate = date('Y-m-d H:i:s', $to); 61 //varDump($toDate); 51 62 //varDump($fromDate, $toDate); 52 if ($single_church) :53 54 //varDump($fromDate, $toDate);55 $intentions = ProMissaREST('Intenties', '?size=' . $limit . '&filter=church_ID,eq,' . html_entity_decode($church_id) . '&filter2=start,ge,' . $fromDate . '&filter2=start,le,' . $toDate);56 57 if (strpos($church_id, '&') !== -1) :63 if ($single_church) : 64 65 //varDump($fromDate, $toDate); 66 $intentions = ProMissaREST('Intenties', '?size=' . $limit . '&filter=church_ID,eq,' . html_entity_decode($church_id) . '&filter2=start,ge,' . $fromDate . '&filter2=start,le,' . $toDate); 67 68 if (strpos($church_id, '&') !== -1) : 58 69 $church_id = explode('&', $church_id)[0]; 59 70 endif; … … 63 74 //varDump($intentions); 64 75 $output = ''; 65 if (!$single_church && $content != null && !empty($content)) :76 if (!$single_church && $content != null && !empty($content)) : 66 77 $output .= sprintf('<p>%s</p>', $content); 67 78 endif; 68 if (!$single_church && !empty($subtitle)) :79 if (!$single_church && !empty($subtitle)) : 69 80 $output .= sprintf('<p>%s</p>', $subtitle); 70 81 endif; 71 82 //$output .= sprintf('<strong>%s</strong>', $intention['church']); 72 if ($single_church && $content != null && !empty($subtitle)) :83 if ($single_church && $content != null && !empty($subtitle)) : 73 84 $output .= sprintf('<h2>%s</h2>', $subtitle); 74 85 endif; 75 if ($single_church && !empty($subtitle)) :86 if ($single_church && !empty($subtitle)) : 76 87 $output .= sprintf('<h2>%s</h2>', $subtitle); 77 88 endif; … … 79 90 80 91 81 if (count($intentions) > 0) :92 if (count($intentions) > 0) : 82 93 uasort($intentions, function ($a, $b) { 83 return $a["start"] . '#' . str_pad($a["order"], 2, "0", STR_PAD_LEFT) <=> $b["start"] . '#' . str_pad($b["order"], 2, "0", STR_PAD_LEFT);94 return $a["start"] . '#' . str_pad($a["order"], 2, "0", STR_PAD_LEFT) <=> $b["start"] . '#' . str_pad($b["order"], 2, "0", STR_PAD_LEFT); 84 95 }); 85 96 $last_date = ''; … … 95 106 96 107 $note = strtolower(trim($intention['note'])); 97 $hourMinu e = null;98 for ($time = $ now; $time < $to2; $time += 86400) :108 $hourMinute = null; 109 for ($time = $from; $time < $to; $time += 86400) : 99 110 100 111 for ($h = 0; $h < 24; $h++) : 101 112 foreach (array('00', '15', '30', '45') as $m) : 102 113 if (strpos($note, $h . "." . $m) !== false) : 103 $hourMinu e = ($h * 60) + (int)$m;114 $hourMinute = ($h * 60) + (int)$m; 104 115 break 2; 105 116 endif; 106 117 endforeach; 107 118 endfor; 108 if ($hourMinu e == null) :109 $hourMinu e = 77777;119 if ($hourMinute == null) : 120 $hourMinute = 77777; 110 121 endif; 111 122 if (strpos($note, DayDateMonth($time)) !== false) : 112 $idate = $time + $sort + ($hourMinu e ?? 77777);123 $idate = $time + $sort + ($hourMinute ?? 77777); 113 124 elseif (strpos($note, ShortDateAndMonth($time)) !== false) : 114 $idate = $time + $sort + ($hourMinu e ?? 77777);125 $idate = $time + $sort + ($hourMinute ?? 77777); 115 126 elseif (strpos($note, LongDate($time)) !== false) : 116 $idate = $time + $sort + ($hourMinu e ?? 77777);127 $idate = $time + $sort + ($hourMinute ?? 77777); 117 128 elseif (strpos($note, ShortDate($time)) !== false) : 118 $idate = $time + $sort + ($hourMinu e ?? 77777);129 $idate = $time + $sort + ($hourMinute ?? 77777); 119 130 elseif (strpos($note, FullDateAt($time)) !== false) : 120 $idate = $time + $sort + ($hourMinu e ?? 77777);131 $idate = $time + $sort + ($hourMinute ?? 77777); 121 132 endif; 122 133 endfor; 123 134 if ($idate != null && (strpos($note, 'doop') !== false || strpos($note, 'huwelijk') !== false || strpos($note, 'uitvaart') !== false)) : 124 $idate += ($hourMinu e ?? 800);135 $idate += ($hourMinute ?? 800); 125 136 endif; 126 137 $intention['sort'] = ($idate ?? ($maxTime + $sort)); … … 128 139 $sort++; 129 140 endforeach; 130 foreach (array('intention', 'funeral', 'baptize', 'marriage', 'announcement') as $type) :131 if (isset($intentionsList[$type]) && $intentionsList[$type] != null && is_array($intentionsList[$type])) :141 foreach (array('intention', 'funeral', 'baptize', 'marriage', 'announcement') as $type) : 142 if (isset($intentionsList[$type]) && $intentionsList[$type] != null && is_array($intentionsList[$type])) : 132 143 uasort($intentionsList[$type], function ($a, $b) { 133 144 global $type; 134 145 return str_pad($a["sort"], 13, "0", STR_PAD_LEFT) . '#' . $a["start"] . '#' . str_pad($a["order"], 13, "0", STR_PAD_LEFT) <=> str_pad($b["sort"], 13, "0", STR_PAD_LEFT) . '#' . $b["start"] . '#' . str_pad($b["order"], 13, "0", STR_PAD_LEFT); 135 136 146 }); 137 147 $dayOfWeek = NULL; 138 148 $usedIntentions = array(); 139 foreach ($intentionsList[$type] as $intention) :140 if ($single_church && $intention['church_ID'] != $church_id) :149 foreach ($intentionsList[$type] as $intention) : 150 if ($single_church && $intention['church_ID'] != $church_id) : 141 151 continue; 142 152 endif; … … 145 155 $date = new DateTime($intention['start']); 146 156 //varDump($date, $nextWeek); 147 if ($date > $nextWeek) :157 if ($date > $nextWeek) : 148 158 break; 149 159 endif; 150 160 151 161 $dateFormatter = \IntlDateFormatter::create( 152 Locale::getDefault(),153 IntlDateFormatter::NONE,154 IntlDateFormatter::NONE,155 date_default_timezone_get(),156 IntlDateFormatter::GREGORIAN,157 'cccc d MMMM Y'162 Locale::getDefault(), 163 IntlDateFormatter::NONE, 164 IntlDateFormatter::NONE, 165 date_default_timezone_get(), 166 IntlDateFormatter::GREGORIAN, 167 'cccc d MMMM Y' 158 168 ); 159 169 160 if ($intention['type'] == $type && $type == 'intention') :161 if ($dayOfWeek !== $date->format('w')) :170 if ($intention['type'] == $type && $type == 'intention') : 171 if ($dayOfWeek !== $date->format('w')) : 162 172 $last_date = sprintf('<h4>%s', (((ucfirst($dateFormatter->format($date)))))); 163 173 endif; 164 174 165 $day .= sprintf('%1$s %2$s %3$02d%4$s%5$02d%6$s</h4><ul>', 166 167 168 (!$single_church ? $intention['church'] : $last_date), //1 175 $day .= sprintf( 176 '%1$s %2$s %3$02d%4$s%5$02d%6$s</h4><ul>', 177 178 179 (!$single_church ? $intention['church'] : $last_date), //1 169 180 __('at', 'promissa'), //2 170 181 $date->format('H'), //3 … … 174 185 ); 175 186 $dayOfWeek = $date->format('N'); 176 elseif ($intention['type'] == $type && $type == 'announcement') :187 elseif ($intention['type'] == $type && $type == 'announcement') : 177 188 $day .= sprintf('<strong>%1$s</strong><ul>', __('Announcements', 'promissa')); 178 elseif ($intention['type'] == $type && $type == 'funeral') :189 elseif ($intention['type'] == $type && $type == 'funeral') : 179 190 $day .= sprintf('<strong>%1$s</strong><ul>', __('Funeral(s) from this week', 'promissa')); 180 elseif ($intention['type'] == $type && $type == 'baptize') :191 elseif ($intention['type'] == $type && $type == 'baptize') : 181 192 $day .= sprintf('<strong>%1$s</strong><ul>', __('Baptize(s) from this week', 'promissa')); 182 elseif ($intention['type'] == $type && $type == 'marriage') :193 elseif ($intention['type'] == $type && $type == 'marriage') : 183 194 $day .= sprintf('<strong>%1$s</strong><ul>', __('Marriage(s) from this week', 'promissa')); 184 195 endif; 185 if ($intention['type'] == $type) :186 if ($day !== $last_day) :187 if (!empty($last_day)) :196 if ($intention['type'] == $type) : 197 if ($day !== $last_day) : 198 if (!empty($last_day)) : 188 199 $output .= '</ul>'; 189 200 endif; … … 192 203 endif; 193 204 $last_day = $day; 194 if ($show_title == 'true' && !empty($intention['note'])) :205 if ($show_title == 'true' && !empty($intention['note'])) : 195 206 $itemCount++; 196 foreach (array(EOL_SPLIT) as $split) :197 if (substr($intention['note'], 0, 2) == $split) :198 foreach (explode(PHP_EOL, $intention['note']) as $note) :207 foreach (array(EOL_SPLIT) as $split) : 208 if (substr($intention['note'], 0, 2) == $split) : 209 foreach (explode(PHP_EOL, $intention['note']) as $note) : 199 210 $note = KeiFormat::IntentionNote($note, $intention['type']); 200 $output .= '<li>' . ltrim($note, $split) . '</li>'; 211 if ($intention['type'] != 'announcement') : 212 $output .= '<li>' . ltrim($note, $split) . '</li>'; 213 endif; 201 214 $usedIntentions[] = removeEndOfString(ltrim($note, $split)); 202 215 endforeach; … … 212 225 $intention['note'] = KeiFormat::IntentionNote($intention['note'], $intention['type']); 213 226 $usedIntentions[] = $intention['note']; 214 $output .= '<li>' . $intention['note'] . '</li>'; 227 if($intention['type'] != 'announcement') : 228 $output .= '<li>' . $intention['note'] . '</li>'; 229 endif; 215 230 endif; 216 231 endif; 217 232 218 233 endforeach; 234 //varDump($usedIntentions); 235 if($type == 'announcement' && $usedIntentions != null && is_array($usedIntentions) && count($usedIntentions) > 0) : 236 $output .= '<li>' . implode('</li><li>', array_unique($usedIntentions, SORT_REGULAR)) . '</li>'; 237 endif; 219 238 $output .= '</ul>'; 220 239 … … 222 241 endforeach; 223 242 endif; 224 if (!empty($output) && $itemCount > 0) :243 if (!empty($output) && $itemCount > 0) : 225 244 return $output; 226 245 endif; 227 246 } 228 247 endif; 229 add_shortcode( 'promissa-intentions', 'promissa_intentions_handler');248 add_shortcode('promissa-intentions', 'promissa_intentions_handler');
Note: See TracChangeset
for help on using the changeset viewer.