Example #1
0
// the iCal date format. Note the Z on the end indicates a UTC timestamp.
define('DATE_ICAL', 'Ymd\\THis\\Z');
define('DATE_ALLDAY_ICAL', 'Ymd');
$matches = [];
$cal = preg_match("/calendars\\/(\\d+)\\.ics/", $_SERVER["SCRIPT_URL"], $matches);
if (!isset($matches[1])) {
    throw new \Exception("Calendar resource not found", 454);
}
// Set the headers
header("Content-type: text/calendar; charset=utf-8");
header("Content-Disposition: inline; filename=" . $matches[1] . ".ics");
$ics = "BEGIN:VCALENDAR\n";
$ics .= "METHOD:PUBLISH\n";
$ics .= "VERSION:2.0\n";
$ics .= "PRODID:-//Battleship/Lexi//EN\n";
$usecase = new \Lexicon\Application\FindUserSessionsUseCase();
if ($sessions = $usecase->execute($matches[1])) {
    $ss = $sessions->getSession();
    foreach ($ss as $s) {
        $ics .= "BEGIN:VEVENT\n";
        $ics .= "UID:" . $matches[1] . "\n";
        $ics .= "SUMMARY:Start learning English words\n";
        $ics .= "DESCRIPTION: Изучил " . $s->getUsed() . " слов английского языка.\n";
        $ics .= "http://www.battleship.ru/lexi?code=" . $s->getCode() . "\n";
        $ics .= "DTSTART:" . date(DATE_ALLDAY_ICAL, strtotime($s->getDtStart())) . "\n";
        $ics .= "DTEND:" . date(DATE_ALLDAY_ICAL, strtotime($s->getLastmod()) + 24 * 60 * 60) . "\n";
        $ics .= "LAST-MODIFIED:" . date(DATE_ICAL, strtotime($s->getLastmod())) . "\n";
        $ics .= "END:VEVENT\n";
    }
}
$ics .= "END:VCALENDAR\n";
Example #2
0
    throw new Exception("Facebook validation fails or other local issues", 550);
}
if (isset($session)) {
    // Retrieve & store the access token in a session.
    $_SESSION['access_token'] = $session->getToken();
    // Retrieve User’s Profile Information
    $request = (new FacebookRequest($session, 'GET', '/me'))->execute();
    // Get response as an array
    $info = $request->getGraphObject()->asArray();
    // Найти пользователя
    $usecase = new \Lexicon\Application\RegisterUserUseCase();
    $user = $usecase->execute($info);
    $_SESSION["LEXICON_USER"] = $user->getId();
    // если пользователя в базе не существует, то надо создать его
    // Найти сессии пользователя
    $usecase = new \Lexicon\Application\FindUserSessionsUseCase();
    $sessions = $usecase->execute($user->getId());
    $link = new \Lexicon\Port\Adaptor\Data\Lexicon\Link();
    $link->setRel("user");
    $link->setHref("?");
    $link->setResource($user);
    $sessions->setLink($link);
    header("Content-Type: text/xml; charset=utf-8");
    $sessions->setPI("stylesheets/Lexicon/Sessions.grid.xsl");
    echo $sessions->toXmlStr();
    exit;
} else {
    // Generate the login URL for Facebook authentication.
    $permissions = array('email', 'publish_actions');
    $loginUrl = $helper->getLoginUrl();
    $xmlstr = "<?xml version=\"1.0\" encoding=\"utf-8\"?><?xml-stylesheet type=\"text/xsl\" href=\"stylesheets/Lexicon/Login.grid.xsl\"?><url xmlns=\"urn:ru:battleship:Lexicon\">" . htmlspecialchars($loginUrl) . "</url>";