function generate_event_page() { ob_start(); $ical = new ICal(get_option('nev-file_path')); $events = $ical->events(); $FORMAT = 'd-m-Y'; $time = time(); echo '<ul>'; foreach ($events as $event) { $eventTime = strtotime($event['DTSTART']); //those in a past are not bolded if ($time - 60 * 60 * 24 > $eventTime) { echo '<li><p>'; $date = substr($event['DTSTART'], 6, 2) . "/" . substr($event['DTSTART'], 4, 2) . "/" . substr($event['DTSTART'], 0, 4); echo $date . ': ' . $event['SUMMARY'] . ", " . @$event['DESCRIPTION']; echo '</p></li>'; } else { echo '<li><p><strong>'; $date = substr($event['DTSTART'], 6, 2) . "/" . substr($event['DTSTART'], 4, 2) . "/" . substr($event['DTSTART'], 0, 4); echo $date . ':</strong> ' . $event['SUMMARY'] . ", " . @$event['DESCRIPTION']; echo '</p></li>'; } } echo '</ul>'; //Show link to download ical file $file_name = get_option('nev-file_path'); $upload_path = wp_upload_dir()['url'] . substr($file_name, strripos($file_name, '/')); echo '<p>Download <a href="' . $upload_path . '" download>.ics file</a></p>'; return ob_get_clean(); }
function updateRessources($db, $ressources, $startdate = null, $enddate = null, $GMT = "+1 hour") { if ($startdate == null) { $startdate = date("Y-m-d"); } if ($enddate == null) { $enddate = date("Y-m-d", strtotime("+30 days")); } $nb = array(); foreach ($ressources as $ressource) { $ical = new ICal('https://planning.univ-rennes1.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?resources=' . $ressource . '&projectId=1&calType=ical&firstDate=' . $startdate . '&lastDate=' . $enddate); $events = $ical->events(); $insertNb = 0; purge_events($db, $ressource); if ($events) { foreach ($events as $event) { $export_d = date("Y/m/d H:i:s", strtotime($GMT, $ical->iCalDateToUnixTimestamp($event['DTSTAMP']))); $start_d = date("Y-m-d", strtotime($GMT, $ical->iCalDateToUnixTimestamp($event['DTSTART']))); $start_t = date("H:i:s", strtotime($GMT, $ical->iCalDateToUnixTimestamp($event['DTSTART']))); $end_d = date("Y-m-d", strtotime($GMT, $ical->iCalDateToUnixTimestamp($event['DTEND']))); $end_t = date("H:i:s", strtotime($GMT, $ical->iCalDateToUnixTimestamp($event['DTEND']))); $description = desc2json($event['DESCRIPTION']); $req = $db->prepare('insert into events (UID,ressource, StartDate, StartTime, EndDate, EndTime, Title, Location, Description,Export) VALUES (?,?,?,?,?,?,?,?,?,?)'); $res = $req->execute(array(issetor($event['UID']), $ressource, $start_d, $start_t, $end_d, $end_t, $event['SUMMARY'], issetor($event['LOCATION']), $description, $export_d)); $insertNb += $res; } } $nb[$ressource] = $insertNb; } $req = $db->prepare("UPDATE ressources r inner join events e on r.number = e.ressource set r.last_sync = e.Export"); $req->execute(); return $nb; }
public function validate($value, Constraint $constraint) { if ($value !== null) { $ical = new \ICal($value->getPathName()); $events = $ical->events(); if ($events === null || count($events) === 0) { $this->context->addViolation($constraint->message); } } }
/** * Hierbei handelt es sich um eine Funktion, die über die URL nicht aufgerufen werden kann. * Stattdessen wird sie vom AutoController aufgerufen, wenn die Ferien automatisch importiert werden sollen * Dabei werden Daten, die bereits als Specialdate markiert sind, übersprungen. * * @author aloeser * @return void */ public function importVacations() { try { $importyear = date('Y') + 1; $sourceURL = 'http://www.schulferien.org/iCal/Ferien/icals/Ferien_Berlin_' . $importyear . '.ics'; $icalreader = new ICal($sourceURL); $events = $icalreader->events(); if ($events == array()) { //Die angegebene Datei existiert nicht throw new Exception(); } $tmpSpecialdates = $this->Specialdate->find('all', array('recursive' => -1, 'conditions' => array('Specialdate.date LIKE ' => $importyear . '-__-__'))); $specialdates = array(); foreach ($tmpSpecialdates as $tmpSpecialdate) { array_push($specialdates, $tmpSpecialdate['Specialdate']['date']); } foreach ($events as $event) { $timeBegin = $this->icalToUnixtime($event['DTSTART']); $timeEnd = $this->icalToUnixtime($event['DTEND']); $datetime = new Datetime(date('Y-m-d', $timeBegin)); for ($i = $timeBegin; $i <= $timeEnd; $i += DAY) { $dateString = $datetime->format('Y-m-d'); if (!in_array($dateString, $specialdates)) { //Datum existiert noch nicht if (!($datetime->format('N') >= 6)) { //Kein Wochenende -> Specialdate eintragen, um das Datum zu deaktivieren $this->Specialdate->create(); $this->Specialdate->save(array('Specialdate' => array('date' => $dateString))); } } else { //Datum existiert bereits } $datetime->modify("+1 day"); } } AutoController::saveLog('Ferienimport', 0, 'SpecialdatesController', 'importVacations'); } catch (Exception $e) { AutoController::saveLog('Ferienimport', 3, 'SpecialdatesController', 'importVacations'); } }
public function put() { $this->requiresLogin(); $this->check_input(['tags' => ['*' => 1]]); if (isset($this->data['id'])) { unset($this->data['id']); } if (isset($this->data['email'])) { unset($this->data['email']); } if (isset($this->data['country'])) { $this->data['country'] = substr(preg_replace('/[^a-z]/i', '', $this->data['country']), 0, 3); } if (isset($this->data['lang'])) { $this->data['lang'] = substr(preg_replace('/[^a-z]/', '', $this->data['lang']), 0, 2); } if (isset($this->data['city']) && isset($this->data['country']) && isset($this->data['address']) && isset($this->data['postal']) && (isset($this->data['lat']) && !$this->data['lat'] || isset($this->data['lng']) && !$this->data['lng'] || $this->data['city'] != Bootstrap::$main->user['city'] || $this->data['country'] != Bootstrap::$main->user['country'] || $this->data['address'] != Bootstrap::$main->user['address'] || $this->data['postal'] != Bootstrap::$main->user['postal'])) { $url = 'https://maps.google.com/maps/api/geocode/json?address=' . urlencode($this->data['address'] . ', ' . $this->data['postal'] . ' ' . $this->data['city']) . '&sensor=false®ion=' . $this->data['country'] . '&key=' . Bootstrap::$main->getConfig('maps.api_key'); $place = json_decode($this->req($url), true); if (isset($place['results'][0]['geometry']['location'])) { $this->data['lat'] = $place['results'][0]['geometry']['location']['lat']; $this->data['lng'] = $place['results'][0]['geometry']['location']['lng']; } } if (isset($this->data['lat'])) { $this->data['lat'] += 0; } if (isset($this->data['lng'])) { $this->data['lng'] += 0; } if (Bootstrap::$main->isAdmin() && $this->id) { $user = $this->user()->get($this->id); } else { $user = Bootstrap::$main->user; } if (isset($this->data['url'])) { $this->data['url'] = trim(Tools::str_to_url($this->data['url'])); if ($this->data['url'] != $user['url']) { if ($this->user()->find_one_by_url($this->data['url']) || in_array($this->data['url'], Bootstrap::$main->getConfig('forbidden_url'))) { return $this->error(17); } } } if (isset($this->data['password']) && strlen($this->data['password']) != 32) { Tools::log('password-change', $this->data); $this->data['password'] = $this->hashPass($this->data['password']); } if (isset($this->data['ical']) && $this->data['ical']) { require_once __DIR__ . '/../class/iCalReader/class.iCalReader.php'; $ical = new ICal($this->data['ical']); $events = $ical->events(); if (!is_array($events)) { return $this->error(50); } } $model = new userModel($user['id']); foreach ($this->data as $k => $v) { if (!is_array($v)) { $model->{$k} = $v; } } if ($this->data('payment')) { $this->check_payment($model->country, $this->data('payment')); } if ($model->save()) { $data = $user = $model->data(); if (isset($this->data['tags'])) { $user['tags'] = Tools::tags(Bootstrap::$main->getConfig('profile.tags'), $this->add_tags($user['id'], $this->data['tags'])); } if (Bootstrap::$main->user['id'] == $model->id) { Bootstrap::$main->session('user', $data); } $this->getPublicUser($user, true); return array('status' => true, 'id' => $user['id'], 'user' => $user); } error(9); }
$activiteit->tijd = \Request::get('tijd'); $activiteit->werkvormsoort = \Request::get('werkvormsoort'); $activiteit->intelligenties = \Request::get('intelligenties', []); $activiteit->inhoud = \Request::get('inhoud'); $activiteit->save(); return redirect()->back()->withInput(['activiteit.updated', []]); }); Route::get('/contactmoment/import', function () { return makeBlade()->render('contactmoment.import', []); }); Route::post('/contactmoment/import', function () { switch (\Request::get("type")) { case "ics": $url = \Request::get("url"); $icalReader = new \ICal($url); foreach ($icalReader->events() as $event) { if (array_key_exists('SUMMARY', $event) === false) { continue; } $module = extractModule($event['SUMMARY']); if ($module === null) { continue; } if (preg_match('/Groepen:\\s+(?<groepen>[^\\n]+)\\\\n\\\\n/', $event['DESCRIPTION'], $groepMatches) === 1) { $groepen = explode('\\, ', $groepMatches['groepen']); } importEvent($module, new \DateTime($event['DTSTART']), new \DateTime($event['DTEND']), $event['UID'], $event['LOCATION'], $groepen); } // remove future, imported contactmomenten which where not touched in this batch (today) \App\Contactmoment::where(function ($query) { $query->where('updated_at', '<', date('Y-m-d'))->orWhereNull('updated_at');
* This example demonstrates how the Ics-Parser should be used. * * PHP Version 5 * * @category Example * @package Ics-parser * @author Martin Thoma <*****@*****.**> * @license http://www.opensource.org/licenses/mit-license.php MIT License * @version SVN: <svn_id> * @link http://code.google.com/p/ics-parser/ * @example $ical = new ical('MyCal.ics'); * print_r( $ical->get_event_array() ); */ require 'class.iCalReader.php'; $ical = new ICal('Calendar.ics'); $events = $ical->events(); $date = $events[0]['DTSTART']; echo 'The ical date: '; echo $date; echo "<br />\n"; echo 'The Unix timestamp: '; echo $ical->iCalDateToUnixTimestamp($date); echo "<br />\n"; echo 'The number of events: '; echo $ical->event_count; echo "<br />\n"; echo 'The number of todos: '; echo $ical->todo_count; echo "<br />\n"; echo '<hr/><hr/>'; foreach ($events as $event) {
/** * Import ICal files * * @since 0.1 * * @return json */ function import_ical() { $this->verify_nonce('wp-erp-hr-nonce'); if (empty($_FILES['ics']['tmp_name'])) { $this->send_error(__('File upload error!', 'wp-erp')); } /* * An iCal may contain events from previous and future years. * We'll import only events from current year */ $first_day_of_year = strtotime(date('Y-01-01 00:00:00')); $last_day_of_year = strtotime(date('Y-12-31 23:59:59')); /* * We'll ignore duplicate entries with the same title and * start date in the foreach loop when inserting an entry */ $holiday_model = new \WeDevs\ERP\HRM\Models\Leave_Holiday(); // create the ical parser object $ical = new \ICal($_FILES['ics']['tmp_name']); $events = $ical->events(); foreach ($events as $event) { $start = strtotime($event['DTSTART']); $end = strtotime($event['DTEND']); if ($start >= $first_day_of_year && $end <= $last_day_of_year) { $title = sanitize_text_field($event['SUMMARY']); $start = date('Y-m-d H:i:s', $start); $end = date('Y-m-d H:i:s', $end); $description = !empty($event['DESCRIPTION']) ? $event['DESCRIPTION'] : $event['SUMMARY']; // check for duplicate entries $holiday = $holiday_model->where('title', '=', $title)->where('start', '=', $start); // insert only unique one if (!$holiday->count()) { erp_hr_leave_insert_holiday(array('id' => 0, 'title' => $title, 'start' => $start, 'end' => $end, 'description' => sanitize_text_field($description))); } } } $this->send_success(); }
function churchcal_updateICalSource($id) { // Set modified date to not load this calendar each cron job //db_query("UPDATE {cc_calcategory} SET modified_date = now() WHERE id = :id", (array(":id"=>$id))); $cat = db_query("SELECT * FROM {cc_calcategory}\n WHERE id = :id", array(":id" => $id))->fetch(); if (!$cat) { throw new CTException("No calcategory found"); } include_once ASSETS . '/ics-parser/class.iCalReader.php'; $ical = new ICal($cat->ical_source_url); $events = $ical->events(); if (!$events) { ct_log("iCal Source from {$cat->bezeichnung} could not readed and processed!", 2, "calcategory", $id); } else { db_query("DELETE FROM {cc_cal} WHERE category_id = :id", array(":id" => $id)); include_once CHURCHCAL . '/churchcal_db.php'; foreach ($events as $event) { $data = array(); $data["startdate"] = churchcore_icalToDate($event["DTSTART"]); if (isset($event["DTEND"])) { $data["enddate"] = churchcore_icalToDate($event["DTEND"]); } $data["bezeichnung"] = utf8_encode(getVar("SUMMARY", "", $event)); $data["category_id"] = $id; $data["repeat_id"] = 0; $data["intern_yn"] = 0; $data["modified_pid"] = -1; $data["notizen"] = getVar("SUMMARY", "", $event) . " " . getVar("DESCRIPTION", "", $event); $data["link"] = getVar("URL", "", $event); $data["ort"] = ""; if ($data["startdate"] != "") { // Substract one day if it is a whole day date $sd = new Datetime($data["startdate"]); if (!isset($data["enddate"])) { $ed = new Datetime($data["startdate"]); } else { $ed = new Datetime($data["enddate"]); if (isFullDay($sd, $ed)) { $ed->modify("-1 DAY"); } } $data["startdate"] = $sd->format("Y-m-d H:i"); $data["enddate"] = $ed->format("Y-m-d H:i"); churchcal_createEvent($data, null, true); } } ct_log("iCal Source from {$cat->bezeichnung} readed and processed!", 2, $id, "category"); } }
echo "<p style='color:red'>Échec de l'écriture du fichier temporaire.</p>"; require "../lib/footer.inc.php"; die; } echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='post'>\n\t<fieldset class='fieldset_opacite50'>\n\t\t" . add_token_field() . "\n\t\t<p style='margin-bottom:1em;'>L'année scolaire telle que saisie dans <a href='../gestion/param_gen.php'>Gestion générale/Configuration générale</a> court du " . strftime("%d/%m/%Y", $begin_bookings) . " au " . strftime("%d/%m/%Y", $end_bookings) . "</p>\n\t\t<p>Choisissez les dates à importer </p>"; require "./edt_ics_lib.php"; require "../lib/class.iCalReader.php"; $ical2 = new ICal($temp_perso . "/fichier_vacances_scolaires.ics"); // Mode debug: $debug_edt = "n"; echo "<p style='margin-bottom:1em; font-size:x-small;'>" . $ical2->event_count . " enregistrements dans ce fichier (<em>une partie seulement sera affichée (celle correspondant à l'année scolaire en cours)</em>).</p>"; if ($debug_edt == "y") { echo '<pre>'; } $cpt = 0; foreach ($ical2->events() as $event) { $tmp_ts_debut = $ical2->iCalDateToUnixTimestamp($event['DTSTART']); if ($tmp_ts_debut > $begin_bookings && $tmp_ts_debut < $end_bookings) { if ($debug_edt == "y") { echo "<hr />"; print_r($event); } $annee_courante = strftime("%Y", $tmp_ts_debut); $mois_courant = strftime("%m", $tmp_ts_debut); $jour_courant = strftime("%d", $tmp_ts_debut); if ($mois_courant > 10 || $mois_courant < 3) { $decalage_horaire = 1 * 3600; } elseif ($mois_courant > 3 && $mois_courant < 10) { $decalage_horaire = 2 * 3600; } elseif ($mois_courant == 3) { if (!isset($num_dernier_dimanche[$annee_courante][$mois_courant])) {
<!-- Main Footer --> <?php include '../plugins/ics-parser/class.iCalReader.php'; $ical = new ICal('../plugins/ics-parser/MyCal.ics'); $eventsCal = $ical->events(); ?> </div> <!-- ./wrapper --> <!-- jQuery UI 1.11.4 --> <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script> <!-- Slimscroll --> <script src="../plugins/slimScroll/jquery.slimscroll.min.js"></script> <!-- FastClick --> <script src="../plugins/fastclick/fastclick.min.js"></script> <!-- fullCalendar 2.2.5 --> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.min.js"></script> <script src="../plugins/fullcalendar/fullcalendar.min.js"></script> <script src="../plugins/fullcalendar/fr.js"></script> <!-- Page specific script --> <script> $(function () { /* initialize the calendar -----------------------------------------------------------------*/ //Date for the calendar events (dummy data) var date = new Date(); var d = date.getDate(), m = date.getMonth(),
/** * Insert a rendered h-Event list from a VCal feed * @param array $atts * @param string $content * @return string */ public static function shortcode($atts, $content = "") { $atts = shortcode_atts(array('url' => '', 'paginated' => '10'), $atts); $body = $content; $vcal = new ICal(); // Request VCalendar and cache the response for 7 days $vcal->setCache(dirname(__FILE__) . '/cache', 7 * 24 * 3600)->initURL($atts['url']); if ($vcal->hasEvents()) { ob_start(); ?> <div class="icalfeed"> <ul> <?php foreach ($vcal->events() as $event) { $event['DTSTART'] = new \DateTime($event['DTSTART']); $event['DTEND'] = new \DateTime($event['DTEND']); // Render an event ?> <li class="hevent"> <p><strong class="p-name"><?php echo $event['SUMMARY']; ?> </strong><br/> Du <time class="dt-start" datetime="<?php echo $event['DTSTART']->format(\DateTime::ISO8601); ?> "><?php echo $event['DTSTART']->format('d/m'); ?> </time> au <time class="dt-end" datetime="<?php echo $event['DTEND']->format(\DateTime::ISO8601); ?> "><?php echo $event['DTEND']->format('d/m'); ?> </time><br/> <!--span class="p-location">Some bar in SF</span--> <?php if (strpos('://', $event['DESCRIPTION'])) { ?> <span class="p-summary"><?php echo preg_replace('#.*(https?://.+)$#is', '<a href="$1" target="icalfeedNewWindow">Voir le site</a>', $event['DESCRIPTION']); ?> </span> <?php } ?> </p> </li> <?php } ?> </ul> </div> <?php $body = ob_get_contents(); ob_clean(); } else { $body = '<p>Aucun événement...</p>'; } return $body; }