зеркало из https://github.com/mozilla/oldpto.git
Patch for PTO to work with MoMo
git-svn-id: https://svn.mozilla.org/projects/pto/trunk@48570 4eb1ac78-321c-0410-a911-ec516a8615a5
This commit is contained in:
Родитель
9a07bdd36f
Коммит
e867fc4bb7
4
auth.php
4
auth.php
|
@ -16,8 +16,8 @@ if (!isset($_SERVER["PHP_AUTH_USER"])) {
|
|||
wail_and_bail();
|
||||
} else {
|
||||
// Check for validity of login
|
||||
if (preg_match("/[a-z]+@mozilla\\.com/", $_SERVER["PHP_AUTH_USER"])) {
|
||||
$dn = "mail=". $_SERVER["PHP_AUTH_USER"] .",o=com,dc=mozilla";
|
||||
if (preg_match("/[a-z]+@(mozilla(?:messaging)?)\\.com/", $_SERVER["PHP_AUTH_USER"], $matches)) {
|
||||
$dn = "mail=". $_SERVER["PHP_AUTH_USER"] .",o=com,dc={$matches[1]}";
|
||||
$password = $_SERVER["PHP_AUTH_PW"];
|
||||
} else {
|
||||
wail_and_bail();
|
||||
|
|
|
@ -64,7 +64,14 @@ require_once "./templates/header.php";
|
|||
jQuery.noConflict();
|
||||
(function($) {
|
||||
$(document).ready(function() {
|
||||
$("#view-all").click(function() { fetch(); }).click(); // Fire "View All"
|
||||
$("#view-all").click(function() { fetch(); });
|
||||
|
||||
var match;
|
||||
if (match = window.location.search.match(/^\?id=(\d+)/)) {
|
||||
fetch({id: match[1]});
|
||||
} else {
|
||||
$("#view-all").click(); // Fire "View All"
|
||||
}
|
||||
|
||||
$("#view-today").click(function() {
|
||||
var [from, to] = makeZeroedDates();
|
||||
|
|
|
@ -13,7 +13,7 @@ if (!empty($_GET["end"])) {
|
|||
$conditions[] = "end >= ". safeint($_GET["end"]);
|
||||
}
|
||||
|
||||
// Actual, useful from / to querying
|
||||
// Actual, useful `from` / `to` querying
|
||||
$from_time = NULL;
|
||||
$to_time = NULL;
|
||||
if (!empty($_GET["from"])) {
|
||||
|
@ -36,6 +36,11 @@ if (!empty($_GET["person"])) {
|
|||
$conditions[] = 'person LIKE "%'. htmlspecialchars($_GET["person"], ENT_QUOTES) .'%mozilla.com"';
|
||||
}
|
||||
|
||||
// ID overrides everything else
|
||||
if (!empty($_GET["id"])) {
|
||||
$conditions = array("id = " . (int)$_GET["id"]);
|
||||
}
|
||||
|
||||
// Join all WHERE clauses
|
||||
$conditions = implode(" AND ", $conditions);
|
||||
if (!empty($conditions)) {
|
||||
|
|
95
output.inc
95
output.inc
|
@ -12,16 +12,14 @@ function output_json($data) {
|
|||
}
|
||||
|
||||
function output_csv($data) {
|
||||
$correct_mime = FALSE;
|
||||
if (strpos($_SERVER["HTTP_ACCEPT"], "text/csv") !== FALSE ||
|
||||
$_GET["valid_mime"] == '1') {
|
||||
$correct_mime = TRUE;
|
||||
$correct_mime = TRUE;
|
||||
if ($_GET["as_text"] == '1') {
|
||||
$correct_mime = FALSE;
|
||||
}
|
||||
|
||||
header("Content-Type: ". ($correct_mime ? "text/csv" : "text/plain"));
|
||||
$f = fopen("php://output", 'w');
|
||||
$fields = array("id", "person", "added", "hours", "details", "start", "end");
|
||||
$dates = array("added", "start", "end");
|
||||
fputcsv($f, array_map("ucwords", $fields));
|
||||
foreach ($data as $pto) {
|
||||
$row = array();
|
||||
|
@ -40,7 +38,92 @@ function output_csv($data) {
|
|||
|
||||
function output_xml($data) {
|
||||
header("Content-Type: text/xml");
|
||||
print '<?xml version="1.0"?><AreYouKiddingMe/>';
|
||||
print '<?xml version="1.0"?><AreYouKiddingMe><WhateverHappenedToAtom/></AreYouKiddingMe>';
|
||||
die;
|
||||
}
|
||||
|
||||
function output_atom($data) {
|
||||
$uuid = "e2f436c4-791d-4045-a6e5-52e981bb3db7";
|
||||
$protocol = $_SERVER["HTTPS"] ? "https" : "http";
|
||||
$path = $protocol ."://". $_SERVER["HTTP_HOST"];
|
||||
$self = $path . $_SERVER["REQUEST_URI"];
|
||||
$document = $path . $_SERVER["PHP_SELF"];
|
||||
header("Content-Type: application/atom+xml");
|
||||
print '<?xml version="1.0" encoding="utf-8"?>';
|
||||
print '<feed xmlns="http://www.w3.org/2005/Atom">';
|
||||
print "<title>PTO Search</title>";
|
||||
print "<id>url:uuid:$uuid</id>";
|
||||
print '<link rel="self" href="'. $self .'" />';
|
||||
print "<updated>". date(DATE_ATOM) ."</updated>";
|
||||
print "<author><name>Mozilla PTO</name></author>";
|
||||
foreach ($data as $pto) {
|
||||
$pto["email"] = $pto["person"];
|
||||
$pto["person"] = str_replace("@mozilla.com", '', $pto["person"]);
|
||||
$start = date("m/d/y", $pto["start"]);
|
||||
$end = date("m/d/y", $pto["end"]);
|
||||
$range = ($start == $end) ? "on $start" : "from $start to $end";
|
||||
print "<entry>";
|
||||
print "<title>{$pto['person']} $range</title>";
|
||||
print "<id>$document?id={$pto["id"]}</id>";
|
||||
print "<link href=\"$document?id={$pto["id"]}\" />";
|
||||
print "<author><name>{$pto['person']}</name><email>{$pto['email']}</email></author>";
|
||||
print "<updated>". date(DATE_ATOM, $pto["added"]) ."</updated>";
|
||||
print "<summary>". htmlspecialchars($pto["details"]) ."</summary>";
|
||||
print "</entry>";
|
||||
}
|
||||
print '</feed>';
|
||||
die;
|
||||
}
|
||||
|
||||
function output_ics($data) {
|
||||
output_ical($data);
|
||||
}
|
||||
|
||||
function fold($string, $octets=75, $whitespace=' ') {
|
||||
$results = ""; $length = strlen($string);
|
||||
for ($i = 0; $i <= $length; $i += $octets) {
|
||||
$results .= substr($string, $i, $octets) ."\r\n". $whitespace;
|
||||
}
|
||||
return rtrim($results);
|
||||
}
|
||||
|
||||
function output_ical($data) {
|
||||
header("Content-Type: text/calendar");
|
||||
header("Content-Disposition: attachment; filename=\"PTOs.ics\"");
|
||||
$format = 'Ymd\THis\Z';
|
||||
ob_start();
|
||||
print <<<EOD
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:PUBLISH
|
||||
X-WR-TIMEZONE:US/Pacific
|
||||
VERSION:2.0
|
||||
PRODID:-//Mozilla//PTO//EN
|
||||
CALSCALE:GEORGIAN
|
||||
X-WR-CALNAME:PTOs
|
||||
|
||||
EOD;
|
||||
foreach ($data as $pto) {
|
||||
$pto["person"] = str_replace("@mozilla.com", '', $pto["person"]);
|
||||
// Line breaks and commas must be escaped.
|
||||
$pto["details"] = str_replace(", ", '\, ', $pto["details"]);
|
||||
$pto["details"] = str_replace("\n", '\n', $pto["details"]);
|
||||
print "BEGIN:VEVENT\n";
|
||||
print "SEQUENCE:0\n";
|
||||
print empty($pto["details"]) ? '' : "DESCRIPTION:{$pto['details']}\n";
|
||||
// Outlook 2003 requires both UID and DTSTAMP.
|
||||
print "UID:{$pto['id']}\n";
|
||||
print "TRANSP:OPAQUE\n";
|
||||
print "DTSTART:". date($format, $pto["start"]) ."\n";
|
||||
print "DTSTAMP:". date($format, $pto["added"]) ."\n";
|
||||
print "SUMMARY:PTO of {$pto['person']}\n";
|
||||
print "CREATED:". date($format, $pto["added"]) ."\n";
|
||||
print "DTEND:". date($format, $pto["end"]) ."\n";
|
||||
print "END:VEVENT\n";
|
||||
}
|
||||
print "END:VCALENDAR";
|
||||
// Per RFC 2445 Section 4.1, lines longer than 75 octets should be folded.
|
||||
$out = explode("\n", ob_get_clean());
|
||||
print implode("\r\n", array_map("fold", $out));
|
||||
die;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче