added a gravatar enable/disable bit
authorPaul J R <me@pjr.cc>
Sat, 22 Sep 2012 21:41:56 +0000 (07:41 +1000)
committerPaul J R <me@pjr.cc>
Sat, 22 Sep 2012 21:41:56 +0000 (07:41 +1000)
gwvpmini/gwvpmini_admin.php
gwvpmini/gwvpmini_gitrepo.php
gwvpmini/gwvpmini_search.php
gwvpmini/gwvpmini_view.php
gwvpmini/gwvpmini_web.php

index 6b721c3..b4f9db6 100644 (file)
@@ -7,6 +7,18 @@ if(gwvpmini_isLoggedIn()) if(gwvpmini_isUserAdmin()) {
 }
 
 
+$reg = gwvpmini_getConfigVal("gravatarenabled");
+
+$use_gravatar = false;\r
+if($reg == null) {\r
+       gwvpmini_setConfigVal("gravatarenabled", "1");\r
+} else if($reg == 1) {\r
+       $use_gravatar = true;\r
+} else {\r
+       $use_gravatar = false;\r
+}\r
+\r
+global $use_gravatar;
 
 function gwvpmini_AdminCallMe()\r
 {\r
@@ -48,6 +60,9 @@ function gwvpmini_AdminCallMe()
                                        if($qspl[1] == "switchenablerepo") {
                                                return "gwvpmini_SwitchEnableRepo";
                                        }
+                                       if($qspl[1] == "changegravs") {
+                                               return "gwvpmini_SwitchGravatars";
+                                       }
                                } else {\r
                                        error_log("i got here, where next?");\r
                                        return "gwvpmini_AdminMainPage";\r
@@ -81,7 +96,7 @@ function gwvpmini_AdminMainPage()
 function gwvpmini_AdminMainPageBody()
 {
        global $BASE_URL;
-       global $can_register, $reg_reqs_confirm, $confirm_from_address;
+       global $can_register, $reg_reqs_confirm, $confirm_from_address, $use_gravatar;
        
        if($can_register) {
                $register = "Registration Enabled (<a href=\"$BASE_URL/admin/changereg\">Disable</a>)";
@@ -94,10 +109,17 @@ function gwvpmini_AdminMainPageBody()
        } else {
                $regconfirm = "Registration Doesnt Require Confirmation (<a href=\"$BASE_URL/admin/changeconfirm\">Enable</a>)";
        }
+       
+       if($use_gravatar) {
+               $usegrav = "Gravatars are enabled (<a href=\"$BASE_URL/admin/changegravs\">Disable</a>)";
+       } else {
+               $usegrav = "Gravatars are disabled (<a href=\"$BASE_URL/admin/changegravs\">Enable</a>)";
+       }
+       
        $totalusers = gwvpmini_GetNUsers();
        echo "<table><tr valign=\"top\"><td>";
        echo "<h2>Users - $totalusers</h2>";
-       echo "$register<br>$regconfirm<br>";
+       echo "$register<br>$regconfirm<br>$usegrav<br>";
        echo "<form method=\"post\" action=\"$BASE_URL/admin/changefromemail\">";
        echo "Address emails are sent from <input type=\"text\" name=\"fromemail\" value=\"$confirm_from_address\"><input type=\"submit\" name=\"Update\" value=\"Update\"><br>";
        echo "</form>"; 
@@ -471,4 +493,22 @@ function gwvpmini_SwitchEnableRepo()
        \r
        header("Location: $BASE_URL/admin");
 }
+
+function gwvpmini_SwitchGravatars()
+{
+       global $BASE_URL, $use_gravatar;\r
+       \r
+       if($newst == 1) $stat = "disabled";\r
+       else $stat = "enabled";\r
+       
+       if($use_gravatar) {
+               gwvpmini_setConfigVal("gravatarenabled", "0");
+       } else {
+               gwvpmini_setConfigVal("gravatarenabled", "1");
+       }
+       \r
+       gwvpmini_SendMessage("info", "Gravatars $stat");\r
+       \r
+       header("Location: $BASE_URL/admin");
+}
 ?>
\ No newline at end of file
index d8e0d32..b24e4bd 100644 (file)
@@ -110,7 +110,7 @@ function gwvpmini_RepoMainPageBody()
                                
                                $owner = gwvpmini_getUser(null, null, $repo["owner"]);
                                $repname = "<a href=\"$BASE_URL/view/$name\">$name</a>";
-                               $repown = get_gravatar($owner["email"], 30, 'mm', 'g', true)."<br><a href=\"$BASE_URL/user/".$owner["username"]."\">".$owner["username"]."</a>";
+                               $repown = gwvpmini_HtmlGravatar($owner["email"], 30, "<br>")."<a href=\"$BASE_URL/user/".$owner["username"]."\">".$owner["username"]."</a>";
                                
                                
                                echo "<tr><td>$repname</td><td>$repown</td><td>$desc</td><td>$lastlog</td></tr>";
index 870dc0b..40fae3f 100644 (file)
@@ -76,13 +76,12 @@ function gwvpmini_SearchMainPageBody()
        echo "<tr valign=\"top\"><td>";
        
        
-       // get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
+       
        if($reps != false) {
                echo "<table border=\"1\">";
                foreach($reps as $rep) {
                        $ownerinfo = gwvpmini_getUser(null, null, $rep["owner"]);
-                       $userdets = get_gravatar($ownerinfo["email"], 40, 'mm', 'g', true);
-                       $userdets .= "<br><a href=\"$BASE_URL/user/".$ownerinfo["username"]."\">".$ownerinfo["username"]."</a>";
+                       $userdets = gwvpmini_HtmlGravatar($ownerinfo["email"], 40, "<br>")."<a href=\"$BASE_URL/user/".$ownerinfo["username"]."\">".$ownerinfo["username"]."</a>";
                        
                        $repodets = "<b><a href=\"$BASE_URL/view/".$rep["name"]."\">".$rep["name"]."</a></b><br>".$rep["desc"];
                        echo "<tr><td>$userdets</td><td>$repodets</td></tr>";
@@ -97,8 +96,7 @@ function gwvpmini_SearchMainPageBody()
                echo "<table border=\"1\">";
                $ownedrepos = "BLAHBLAH";\r
                foreach($ppls as $ppl) {\r
-                       $userdets = get_gravatar($ppl["email"], 40, 'mm', 'g', true);
-                       $userdets .= "<br><a href=\"$BASE_URL/user/".$ppl["username"]."\">".$ppl["username"]."</a>";
+                       $userdets = gwvpmini_HtmlGravatar($ppl["email"], 40, "<br>")."<a href=\"$BASE_URL/user/".$ppl["username"]."\">".$ppl["username"]."</a>";
                        $repos = gwvpmini_GetOwnedRepos($ppl["username"]);
                        if($repos == false) $ownedrepos = "No Repos";
                        else {
index 126f5e4..d9721a7 100644 (file)
@@ -111,7 +111,7 @@ function gwvpmini_RepoViewPageBody()
        if($owner_view) $owner_extra = " (YOU)";
        else $owner_extra = "";\r
        
-       echo "<h2>".get_gravatar($owner["email"], 30, 'mm', 'g', true)."$repo_view_call - $owner_name$owner_extra</h2>";
+       echo "<h2>".gwvpmini_HtmlGravatar($owner["email"], 30)."$repo_view_call - $owner_name$owner_extra</h2>";
        if(!$owner_view) echo "<b>$desc</b><br>";
        
        if($owner_view) {
@@ -150,7 +150,7 @@ function gwvpmini_RepoViewPageBody()
                        foreach($bperms_f as $key=>$val) {
                                if($val == 1) {
                                        $dets = gwvpmini_getUser(null, null, $key);
-                                       echo get_gravatar($dets["email"], 18, 'mm', 'g', true)." <input type=\"checkbox\" name=\"$key\"> ".$dets["username"]."<br>";
+                                       echo gwvpmini_HtmlGravatar($dets["email"], 18, " ")."<input type=\"checkbox\" name=\"$key\"> ".$dets["username"]."<br>";
                                        $nl = 1;
                                }
                        }
@@ -167,7 +167,7 @@ function gwvpmini_RepoViewPageBody()
                foreach($bperms_f as $key=>$val) {\r
                        if($val == 2) {\r
                                $dets = gwvpmini_getUser(null, null, $key);\r
-                               echo get_gravatar($dets["email"], 18, 'mm', 'g', true)." <input type=\"checkbox\" name=\"$key\"> ".$dets["username"]."<br>";
+                               echo gwvpmini_HtmlGravatar($dets["email"], 18, " ")."<input type=\"checkbox\" name=\"$key\"> ".$dets["username"]."<br>";
                                $nl = 1;\r
                        }\r
                }\r
@@ -215,7 +215,7 @@ function gwvpmini_RepoViewPageBody()
                                        $flon = "$flin3 (external)";
                                }
                        }
-                       echo "<tr><td>".get_gravatar($flin2, 18, 'mm', 'g', true)."$flon</td><td>$flin1</td><td>$flin4</td></tr>";
+                       echo "<tr><td>".gwvpmini_HtmlGravatar($flin2, 18)."$flon</td><td>$flin1</td><td>$flin4</td></tr>";
                }
                echo "</table>";
        } else {
index 97afbaa..6d45c4a 100644 (file)
@@ -264,7 +264,17 @@ function gwvpmini_fourZeroFour()
  * @param array $atts Optional, additional key/value attributes to include in the IMG tag\r
  * @return String containing either just a URL or a complete image tag\r
  * @source http://gravatar.com/site/implement/images/php/\r
- */\r
+ */
+function gwvpmini_HtmlGravatar($email, $size, $htmlappend="")
+{
+       
+       global $use_gravatar;
+       
+       
+       if($use_gravatar == false) return "";
+       return get_gravatar( $email, $size, 'mm', 'g', true)."$htmlappend";
+}
+\r
 function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {\r
        $url = 'http://en.gravatar.com/avatar/';\r
        $url .= md5( strtolower( trim( $email ) ) );\r