public function timeSinceInWords($data) { $diff = \TimeSource::time() - $data->getTimestamp(); if ($diff < 0) { return "in the future"; } elseif ($diff == 0) { return "now"; } elseif ($diff == 1) { return "1 second ago"; } elseif ($diff < 60) { return $diff . " seconds ago"; } elseif ($diff < 60 * 2) { return "1 minute ago"; } elseif ($diff < 60 * 60) { return round($diff / 60) . " minutes ago"; } elseif ($diff < 60 * 60 * 2) { return "1 hour ago"; } elseif ($diff < 60 * 60 * 24) { return round($diff / (60 * 60)) . " hours ago"; } elseif ($diff < 60 * 60 * 24 * 2) { return "1 day ago"; } else { return round($diff / (60 * 60 * 24)) . " days ago"; } }
function resendVerifyEmail(Request $request, Application $app) { $repo = new UserAccountVerifyEmailRepository(); $date = $repo->getLastSentForUserAccount($app['currentUser']); if ($date && $date->getTimestamp() > \TimeSource::time() - $app['config']->userAccountVerificationSecondsBetweenAllowedSends) { $app['flashmessages']->addMessage("Sorry, but an email was sent too recently. Please try again later."); } else { $verifyEmail = $repo->create($app['currentUser']); $verifyEmail->sendEmail($app, $app['currentUser']); $app['flashmessages']->addMessage("Verification email resent."); } return $app->redirect("/me/"); }
function index(Request $request, Application $app) { $form = $app['form.factory']->create(new LogInUserForm()); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $data = $form->getData(); if ($app['currentUser']->checkPassword($data['password']) && $data['extrapassword'] == $app['config']->sysAdminExtraPassword) { $app['websession']->set('sysAdminLastActive', \TimeSource::time()); return $app->redirect("/sysadmin"); } else { $form->addError(new FormError('passwords wrong')); } } } return $app['twig']->render('sysadmin/login/index.html.twig', array('form' => $form->createView())); }
protected function processMeetupData($meetupData) { global $CONFIG; $start = new \DateTime('', new \DateTimeZone('UTC')); $start->setTimestamp($meetupData->time / 1000); if (property_exists($meetupData, 'duration') && $meetupData->duration) { $end = new \DateTime('', new \DateTimeZone('UTC')); $end->setTimestamp($meetupData->time / 1000); $end->add(new \DateInterval("PT" . $meetupData->duration / 1000 . "S")); } else { $end = clone $start; $end->add(new \DateInterval("PT3H")); } if ($start && $end && $start <= $end) { if ($end->getTimeStamp() < \TimeSource::time()) { $this->countInPast++; } else { if ($start->getTimeStamp() > \TimeSource::time() + $CONFIG->importURLAllowEventsSecondsIntoFuture) { $this->countToFarInFuture++; } else { $importedEventRepo = new \repositories\ImportedEventRepository(); $id = "event_" . $meetupData->id . "@meetup.com"; $importedEvent = $importedEventRepo->loadByImportURLIDAndImportId($this->importURLRun->getImportURL()->getId(), $id); $changesToSave = false; if (!$importedEvent) { if ($meetupData->status != 'cancelled') { ++$this->countNew; $importedEvent = new ImportedEventModel(); $importedEvent->setImportId($id); $importedEvent->setImportUrlId($this->importURLRun->getImportURL()->getId()); $this->setImportedEventFromMeetupData($importedEvent, $meetupData); $changesToSave = true; } } else { ++$this->countExisting; if ($meetupData->status == 'cancelled') { if (!$importedEvent->getIsDeleted()) { $importedEvent->setIsDeleted(true); $changesToSave = true; } } else { $changesToSave = $this->setImportedEventFromMeetupData($importedEvent, $meetupData); // if was deleted, undelete if ($importedEvent->getIsDeleted()) { $importedEvent->setIsDeleted(false); $changesToSave = true; } } } if ($changesToSave && $this->countSaved < $this->limitToSaveOnEachRun) { ++$this->countSaved; $this->importedEventsToEvents->addImportedEvent($importedEvent); if ($importedEvent->getId()) { if ($importedEvent->getIsDeleted()) { $importedEventRepo->delete($importedEvent); } else { $importedEventRepo->edit($importedEvent); } } else { $importedEventRepo->create($importedEvent); } } } } } }
/** * * Gets new monthly events on the basis that the event is on the something day in the week. * eg. 2nd tuesday of month * eg. 4th saturday in month * * @param \models\EventModel $event * @param type $monthsInAdvance * @return \models\EventModel */ public function getNewMonthlyEventsOnSetDayInWeek(EventModel $event, $daysInAdvance = 186) { // constants $interval = new \DateInterval('P1D'); $timeZone = new \DateTimeZone($this->timeZoneName); $timeZoneUTC = new \DateTimeZone("UTC"); // calculate which day of month it should be $dayOfWeek = $event->getStartAt()->format("N"); $thisStart = new \DateTime($event->getStartAt()->format('Y-m-d H:i:s'), $timeZoneUTC); $thisEnd = new \DateTime($event->getEndAt()->format('Y-m-d H:i:s'), $timeZoneUTC); $thisStart->setTimeZone($timeZone); $thisEnd->setTimeZone($timeZone); $weekInMonth = 1; while ($thisStart->format('d') > 1) { $thisStart->sub($interval); $thisEnd->sub($interval); if ($thisStart->format("N") == $dayOfWeek) { ++$weekInMonth; } } // vars $out = array(); $currentMonthLong = $thisStart->format('F'); $currentMonthShort = $thisStart->format('M'); $currentMonth = $thisStart->format('m'); $currentWeekInMonth = 1; $loopStop = \TimeSource::time() + $daysInAdvance * 24 * 60 * 60; while ($thisStart->getTimestamp() < $loopStop) { $thisStart->add($interval); $thisEnd->add($interval); //print $thisStart->format("r")." current month: ".$currentMonth." current week: ".$currentWeekInMonth."\n"; if ($currentMonth != $thisStart->format('m')) { $currentMonth = $thisStart->format('m'); $currentWeekInMonth = 1; } if ($thisStart->format("N") == $dayOfWeek) { if ($currentWeekInMonth == $weekInMonth && $thisStart->getTimestamp() > \TimeSource::time()) { $start = clone $thisStart; $end = clone $thisEnd; $start->setTimeZone($timeZoneUTC); $end->setTimeZone($timeZoneUTC); $include = true; if ($include) { $newEvent = new EventModel(); $newEvent->setGroupId($event->getGroupId()); $newEvent->setVenueId($event->getVenueId()); $newEvent->setCountryId($event->getCountryId()); $newEvent->setEventRecurSetId($this->id); $newEvent->setSummary($event->getSummary()); $newEvent->setDescription($event->getDescription()); $newEvent->setStartAt($start); $newEvent->setEndAt($end); foreach ($this->customFields as $customField) { if ($event->hasCustomField($customField)) { $newEvent->setCustomField($customField, $event->getCustomField($customField)); } } if (stripos($newEvent->getSummary(), $currentMonthLong) !== false) { $newEvent->setSummary(str_ireplace($currentMonthLong, $newEvent->getStartAt()->format('F'), $newEvent->getSummary())); } else { if (stripos($newEvent->getSummary(), $currentMonthShort) !== false) { $newEvent->setSummary(str_ireplace($currentMonthShort, $newEvent->getStartAt()->format('M'), $newEvent->getSummary())); } } $out[] = $newEvent; } } ++$currentWeekInMonth; } } return $out; }
///////////////////////////////////////////// SECURITY if (!$app['currentUser']) { die("No"); } if (!$app['currentUser']->getIsSystemAdmin()) { die("No"); } if (!$WEBSESSION->has('sysAdminLastActive')) { header("Location: /authintosysadmin.php"); die; } if ($WEBSESSION->get('sysAdminLastActive') + $CONFIG->sysAdminLogInTimeOutSeconds < TimeSource::time()) { header("Location: /authintosysadmin.php"); die; } $WEBSESSION->set('sysAdminLastActive', \TimeSource::time()); ///////////////////////////////////////////// APP $app->before(function (Request $request) use($app) { global $CONFIG; # ////////////// Timezone $timezone = $CONFIG->sysAdminTimeZone; $app['twig']->addGlobal('currentTimeZone', $timezone); $app['currentTimeZone'] = $timezone; }); require APP_ROOT_DIR . '/core/webSysAdmin/index.routes.php'; foreach ($CONFIG->extensions as $extensionName) { if (file_exists(APP_ROOT_DIR . '/extension/' . $extensionName . '/webSysAdmin/index.routes.php')) { require APP_ROOT_DIR . '/extension/' . $extensionName . '/webSysAdmin/index.routes.php'; } } $app->run();
public function isInPast() { return $this->end_at->getTimeStamp() < \TimeSource::time(); }
protected function processFBData($id, $fbData) { global $CONFIG; $start = new \DateTime($fbData['start_time'], new \DateTimeZone('UTC')); if ($fbData['end_time']) { $end = new \DateTime($fbData['end_time'], new \DateTimeZone('UTC')); } else { $end = clone $start; } if ($start && $end && $start <= $end) { if ($end->getTimeStamp() < \TimeSource::time()) { $this->countInPast++; } else { if ($start->getTimeStamp() > \TimeSource::time() + $CONFIG->importURLAllowEventsSecondsIntoFuture) { $this->countToFarInFuture++; } else { $importedEventRepo = new \repositories\ImportedEventRepository(); $importedEvent = $importedEventRepo->loadByImportURLIDAndImportId($this->importURLRun->getImportURL()->getId(), $id); $changesToSave = false; if (!$importedEvent) { ++$this->countNew; $importedEvent = new ImportedEventModel(); $importedEvent->setImportId($id); $importedEvent->setImportUrlId($this->importURLRun->getImportURL()->getId()); $this->setImportedEventFromFBData($importedEvent, $fbData); $changesToSave = true; } else { ++$this->countExisting; $changesToSave = $this->setImportedEventFromFBData($importedEvent, $fbData); // if was deleted, undelete if ($importedEvent->getIsDeleted()) { $importedEvent->setIsDeleted(false); $changesToSave = true; } } if ($changesToSave && $this->countSaved < $this->limitToSaveOnEachRun) { ++$this->countSaved; $this->importedEventsToEvents->addImportedEvent($importedEvent); if ($importedEvent->getId()) { if ($importedEvent->getIsDeleted()) { $importedEventRepo->delete($importedEvent); } else { $importedEventRepo->edit($importedEvent); } } else { $importedEventRepo->create($importedEvent); } } } } } }
/** * * @return int|boolean 0= false, 1=warn, 2=out */ public function isGroupRunningOutOfFutureEvents(GroupModel $group, SiteModel $site) { global $DB, $CONFIG; if (!$group) { return 0; } $stat = $DB->prepare("SELECT event_information.start_at FROM event_information " . " LEFT JOIN event_in_group ON event_in_group.event_id = event_information.id AND event_in_group.removed_at IS NULL " . "WHERE event_in_group.group_id =:id AND start_at > :start_at AND is_deleted = '0' " . "ORDER BY event_information.start_at DESC"); $stat->execute(array('id' => $group->getId(), 'start_at' => \TimeSource::getFormattedForDataBase())); if ($stat->rowCount() > 0) { $data = $stat->fetch(); $utc = new \DateTimeZone("UTC"); $lastStartAt = new \DateTime($data['start_at'], $utc); $secondsToWarn = $site->getPromptEmailsDaysInAdvance() * 24 * 60 * 60; if ($lastStartAt->getTimestamp() < \TimeSource::time() + $secondsToWarn) { return 1; } else { return 0; } } return 2; }
public function isShouldExpireNow() { global $CONFIG; $r = new ImportURLRepository(); $lastEdit = $r->getLastEditDateForImportURL($this); return $lastEdit->getTimeStamp() < \TimeSource::time() - $CONFIG->importURLExpireSecondsAfterLastEdit; }