Commit:    6e9e1f30d24695315c2b08e20a040d0fb8b6974d
Author:    Hannes Magnusson <[email protected]>         Sun, 29 Dec 2013 
20:40:30 -0800
Parents:   4de9826286ae8378c26f788fec1f646702295f7a
Branches:  master

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

Log:
Use the cached() function and remove some code

Changed paths:
  M  include/karma.php


Diff:
diff --git a/include/karma.php b/include/karma.php
index ac28b46..385f19a 100644
--- a/include/karma.php
+++ b/include/karma.php
@@ -1,13 +1,12 @@
 <?php
 
-define("KARMA_FILE", sys_get_temp_dir() . "/karma.txt");
 function findKarma($username)
 {
-    refreshStaleKarma();
-    $karma = json_decode(file_get_contents(KARMA_FILE), true);
+    $karma = fetchKarma();
     if ($karma === FALSE) {
         return false;
     }
+
     $mykarma = $karma[$username];
     $retval = array(
         "avail"   => explode(PATH_SEPARATOR, $mykarma["avail"]),
@@ -16,34 +15,11 @@ function findKarma($username)
     return $retval;
 }
 
-function refreshStaleKarma()
-{
-    $karma_updated = filemtime(KARMA_FILE);
-    $timezone      = timezone_open("UTC");
-    $is_expired    = (date_create("@$karma_updated", $timezone) < 
date_create("1 day ago", $timezone));
-    if ($is_expired) {
-        $karma = fetchKarma();
-        file_put_contents(KARMA_FILE, json_encode($karma));
-    }
-}
-
 function fetchKarma()
 {
     $ctx = stream_context_create(array("http" => array("ignore_errors" => 
true)));
-    $retval = 
@file_get_contents("https://svn.php.net/repository/SVNROOT/global_avail";, 
false, $ctx);
-    if (!$retval) {
-        if (isset($http_response_header) && $http_response_header) {
-            list($protocol, $errcode, $errmsg) = explode(" ", 
$http_response_header[0], 3);
-        } else {
-            $error   = error_get_last();
-            // Remove the function name, arguments and all that stuff... we
-            // really only care about whatever comes after the last colon
-            $message = explode(":", $error["message"]);
-            $errmsg  = array_pop($message);
-        }
-        error($errmsg);
-    }
-    $karma = parseKarma(explode("\n", $retval));
+    $content = cached("https://svn.php.net/repository/SVNROOT/global_avail";, 
false, $ctx);
+    $karma = parseKarma(explode("\n", $content));
     return $karma;
 }


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

Reply via email to