PHP File Manager
Editing File: Calendar.php
<?php /* * Copyright (C) Wayne Purton-Smith - All Rights Reserved * Unauthorized copying of this file or removing this paragraph, via any medium is strictly prohibited * Proprietary and confidential * Written by Wayne Purton-Smith <waynepurtonsmith@hotmail.co.uk> February 2014 */ class Calendar extends CI_Model { function __construct() { $this->syncBankHolidays(); } public function getUKBankHolidays($holiday_id = 0, $date = NULL, $include_disabled = true) { if($this->config->item('disable_bank_holidays')) { return array(); } $limit = NULL; $sql = "SELECT * FROM `bank_holidays` WHERE 1 = 1 "; if($include_disabled === false) { $sql .= " AND `is_disabled` = 0 "; } if(($holiday_id = (int) $holiday_id) > 0) { $sql .= " AND `holiday_id` = $holiday_id "; $limit = 1; } if(is_numeric($date) && ($date = (int) $date) > 1) { $sql .= " AND `date` = $date "; $limit = 1; } $sql .= " ORDER BY `date` ASC"; if($limit > 0) { $sql .= " LIMIT $limit"; } $result = $this->db->query($sql); if($result->num_rows()) { if($holiday_id > 0 || $date > 1) return $result->row(); $rows = $result->result(); $result->free_result(); return $rows; } return array(); } public function isBankHoliday($date = NULL) { if(!is_numeric($date)) { $date = strtotime($date . ' 00:00:00'); } return (bool) $this->getUKBankHolidays(NULL, $date, false); } public function syncBankHolidays() { // Sync every 2 months if(($this->config->item('bank_holidays_last_sync') + (60 * 60 * 24 * 60)) < time()) { $ch = curl_init('https://www.gov.uk/bank-holidays.json'); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CAINFO, APPPATH . 'third_party/cacert.pem'); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0'); $response = curl_exec($ch); curl_close($ch); $current_time = time(); if(($json_data = @json_decode($response, true)) !== false) { if(isset($json_data['england-and-wales']['events'])) { foreach($json_data['england-and-wales']['events'] as $event_info) { $event_date = strtotime($event_info['date']); if($event_date < $current_time) { continue; } if(!$this->getUKBankHolidays(NULL, $event_date)) { $this->db->query($this->db->insert_string('bank_holidays', array ( 'name' => $event_info['title'], 'date' => $event_date ))); } } $this->db->query("DELETE FROM `bank_holidays` WHERE `date` < $current_time"); $this->common->saveSettings(array('bank_holidays_last_sync' => ($current_time + (60 * 60 * 24 * 60)))); } } } } }
Cancel