Commit:    6e1cd72453926b6c463343642293e1c2a3e22359
Author:    Hannes Magnusson <[email protected]>         Wed, 22 Jan 2014 
21:55:14 -0800
Parents:   84c7d04d1c471461dbac74e6e890841115c1c46e
Branches:  master

Link:       
http://git.php.net/?p=web/php.git;a=commitdiff;h=6e1cd72453926b6c463343642293e1c2a3e22359

Log:
List upcoming event, if available. Also list all countries with known UGs

Changed paths:
  M  include/layout.inc
  M  ug.php


Diff:
diff --git a/include/layout.inc b/include/layout.inc
index ee42acf..da3fdf3 100644
--- a/include/layout.inc
+++ b/include/layout.inc
@@ -603,14 +603,17 @@ function get_near_usergroups()
 
 
 }
-function get_usergroups_in($country) {
+function get_usergroups_in($country, &$allcountries = array()) {
     $filename = $_SERVER["DOCUMENT_ROOT"] . "/backend/usergroups.json";
 
     $matches = array();
     $data = json_decode(file_get_contents($filename), true);
     foreach($data["groups"] as $group) {
-        if (isset($group["ccc"]) && $group["ccc"] == $country) {
-            $matches[] = $group;
+        if (isset($group["ccc"])) {
+            $allcountries[$group["ccc"]] = 1;
+            if ($group["ccc"] == $country) {
+                $matches[] = $group;
+            }
         }
     }
 
diff --git a/ug.php b/ug.php
index a844157..ce3a965 100644
--- a/ug.php
+++ b/ug.php
@@ -21,10 +21,74 @@ function print_cc_header($country) {
     <ul class="ugs">
     <?php
 }
+function ug_get_more_info($group) {
+    if (trim($group["icalendar_url"])) {
+        $url = $group["icalendar_url"];
+        /*
+        if (strncmp("webcal://", $url, strlen("webcal://")) == 0) {
+            $url = str_replace("webcal://", "http://";, $url);
+            $data = file_get_contents($url);
+            file_put_contents("backend/events/" . 
md5($group["icalendar_url"]), $data);
+        }
+         */
+        $data = file("backend/events/" . md5($url), 
FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
+        $retval = ug_get_next_even_from_ical_array($data);
+        return $retval;
+    }
+
+    return "";
+}
+function ug_get_next_even_from_ical_array($ical) {
+    $ok = false;
+    $data = array();
+    foreach($ical as $line) {
+        if ($line == "BEGIN:VEVENT") {
+            do {
+                if ($line[0] == " ") {
+                    // data continued from previous key
+                    $data[$lastkey] .= ltrim($line);
+                } else {
+                    list($lastkey, $value) = explode(":", $line, 2);
+                    $data[$lastkey] = $value;
+                }
+            } while((list($n, $line) = each($ical)) && $line != "END:VEVENT");
+            break;
+        }
+    }
+    if (!isset($data["DTSTAMP"])) {
+        /* There is no scheduled next meeting */
+        return array();
+    }
+    /* Meetup.com seems to have fetish for injecting the TZ into the keyname */
+    if (isset($data["TZID"])) {
+        $data["STARTSAT"] = $data["DTSTART;TZID={$data["TZID"]}"];
+    } else {
+        $data["STARTSAT"] = $data["DTSTART"];
+    }
+
+    // Yes.. Replace literal '\n' with new line
+    $data["DESCRIPTION"] = str_replace('\n', "\n", $data["DESCRIPTION"]);
+    return array("event" => $data);
+}
 function print_ug_matches($matches) {
     $content = "";
     foreach($matches as $group) {
-        echo '<li class="ug"><a href="'. $group["url"].'">' . $group["name"] . 
" (" . $group["shortname"] . ")</a></li>";
+        $data = ug_get_more_info($group);
+        $details = "";
+        if ($data && $data["event"]) {
+            $d = date(DATE_RSS, strtotime($data["event"]["STARTSAT"], 
$_SERVER["REQUEST_TIME"]));
+            $url         = isset($data["event"]["URL"]) ? 
addslashes($data["event"]["URL"]) : "";
+            $summary     = htmlspecialchars($data["event"]["SUMMARY"]);
+            /* The icalendar has all sorts of weird trailing slashes and 
totally weirdo 
+             * newlines making this look like geocities */
+            //$description = 
nl2br(htmlspecialchars($data["event"]["DESCRIPTION"]), false);
+            if ($url) { /* Google Calendar doesn't have this */
+                $details = ": <a href='$url'>{$summary}</a> - {$d}"; //<br>" . 
$description;
+            } else {
+                $details = ": $summary - {$d}";// . $description;
+            }
+        }
+        echo '<li class="ug"><a href="'. $group["url"].'">' . $group["name"] . 
"</a>$details</li>";
     }
     if (!$matches) {
         echo "<li>There are no known User Groups in {$COUNTRIES[$country]} at 
this time :(</li>";
@@ -35,7 +99,7 @@ function print_ug_matches($matches) {
 $country = isset($_GET["cc"]) ? $_GET["cc"] : $COUNTRY;
 
 if (isset($COUNTRIES[$country])) {
-    $matches = get_usergroups_in($country);
+    $matches = get_usergroups_in($country, $allcountries);
     print_cc_header($country);
     print_ug_matches($matches);
 } else {
@@ -47,6 +111,9 @@ if (isset($COUNTRIES[$country])) {
 $SIDEBAR_DATA = <<< EOF
     <p class="panel"><a href="http://php.ug/ug/promote";>Register new UG</a></p>
 EOF;
+foreach($allcountries as $country => $nada) {
+    $SIDEBAR_DATA .= '<p class="panel"><a href="/ug.php?cc=' . $country . '">' 
. $COUNTRIES[$country] . '</a></p>';
+}
 
 // Print the common footer.
 site_footer(


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to