--- gtranslate_links.module.OLD	2009-09-20 04:23:03.000000000 +1000
+++ gtranslate_links.module	2009-09-29 12:22:44.000000000 +1000
@@ -1,59 +1,58 @@
 <?php
 // $Id: gtranslate_links.module,v 1.8 2009/09/19 18:23:03 wicherminnaard Exp $
 
-/*
+/**
  * @file
  * Generates a block with flags a user can click on to translate the current page via Google Translate. Only displays the block on pages GT can actually reach.
-*/
+ */
 
 define('GTRANSLATE_PATH', drupal_get_path('module', 'gtranslate_links'));
 
 function gtranslate_links_block($op = 'list', $delta = 0) {
 
   if ($op == "list") {
-     $block[0]["info"] = t('Google Translate links');
-     return $block;
+    $block[0]["info"] = t('Google Translate links');
+    return $block;
   }
 
   else if ($op == 'view') {
-    
-  /*
-  Various checks to determine whether we should display. The idea is
-  not to display when GT can't reach this page anyway.
-  */
-  $url = 'http'. ($_SERVER['HTTPS'] ? 's' : null) .'://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+
+  // Various checks to determine whether we should display. The idea is not to
+  //  display when GT can't reach this page anyway.
+  $url = 'http'. ($_SERVER['HTTPS'] ? 's' : NULL) .'://'. $_SERVER['HTTP_HOST'] . request_uri();
   if (!gtranslate_is_translatable($url)) return;
   $block_content = '';
 
-  //Determine the enabled languages
-  $files = scandir(GTRANSLATE_PATH . '/enabledlangs');
-  $langflags = Array();
+  // Determine the enabled languages
+  $files = scandir(GTRANSLATE_PATH .'/enabledlangs');
+  $langflags = array();
   foreach ($files as $file) {
-    //extract the language code and description from the filename (see README.txt for semantics)
-    $matches = Array();
+    // Extract the language code and description from the filename (see README.txt for semantics)
+    $matches = array();
     if (preg_match('/_([^.]*)_([^.]*)\.[^.]*$/', $file, $matches) > 0) {
       $desc = $matches[1];
       $lang = $matches[2];
-      $langflags[] = Array('langcode' => $lang, 'hoverdesc' => $desc, 'filename' => $file);
-      }
+      $langflags[] = array('langcode' => $lang, 'hoverdesc' => $desc, 'filename' => $file);
     }
+  }
 
-  //Compose the HTML content - links and images
-  //Parameters for l() depend on drupal version.
-  if (substr(VERSION,0,1) == '5') $D5 = true;
+  // Compose the HTML content - links and images
+  // Parameters for l() depend on drupal version
+  if (substr(VERSION, 0, 1) == '5') $D5 = TRUE;
   foreach ($langflags as $langflag) {
-    $imgurl = base_path() . GTRANSLATE_PATH .'/enabledlangs/' . urlencode($langflag['filename']);
-    $gtransurl = 'http://translate.google.com/translate?u=' . urlencode($url) . '&tl=' . $langflag['langcode'];
-    $attributes = Array('title' => $langflag['hoverdesc'],);
-    $altdesc = "Flag icon for '".$langflag['langcode']."' language";
+    $imgurl = base_path() . GTRANSLATE_PATH .'/enabledlangs/'. urlencode($langflag['filename']);
+    $gtransurl = 'http://translate.google.com/translate?u='. urlencode($url) .'&tl='. $langflag['langcode'];
+    $attributes = array('title' => $langflag['hoverdesc']);
+    $altdesc = "Flag icon for '". $langflag['langcode'] ."' language";
     if ($D5) {
-      $block_content .= l('<img src="'.$imgurl.'" alt="'.$altdesc.'" />', $gtransurl, $attributes, NULL, NULL, TRUE, TRUE);
+      $block_content .= l('<img src="'. $imgurl .'" alt="'. $altdesc .'" />', $gtransurl, $attributes, NULL, NULL, TRUE, TRUE);
     }
     else {
-      $block_content .= l('<img src="'.$imgurl.'" alt="'.$altdesc.'" />', $gtransurl, array('absolute' => TRUE, 'html' => TRUE, 'attributes' => $attributes));
+      $block_content .= l('<img src="'. $imgurl .'" alt="'. $altdesc .'" />', $gtransurl, array('absolute' => TRUE, 'html' => TRUE, 'attributes' => $attributes));
     }
   }
-  //Done, return the content 
+
+  // Done, return the content
   $block['content'] = $block_content;
   return $block;
   }
@@ -61,24 +60,26 @@ function gtranslate_links_block($op = 'l
 
 function gtranslate_is_translatable($url) {
 
-  //this request came in via GT, do not show block (prevents nested translations)
+  // This request came in via GT, do not show block (prevents nested translations)
   if (strstr($_SERVER["HTTP_VIA"], 'translate.google.com')) return FALSE;
 
-  //visitor is anonymous. therefore, the current page will be accessible by GT.
+  // Visitor is anonymous, therefore the current page will be accessible by GT
   global $user;
   if ($user->uid == 0) return TRUE;
 
-  //user is logged in. let's see if GT can reach this page. (2xx response)
-  //TODO: Using http requests doesn't seem right. We should be able to do this
-  //via drupal internals. http://drupal.org/node/470858
+  // User is logged in. Let's see if GT can reach this page (2xx response)
+  // TODO: Using http requests doesn't seem right. We should be able to do this
+  //  via drupal internals. http://drupal.org/node/470858
 
-  //No safe mode, and we have curl. Let's curl!
+  // No safe mode, and we have curl. Let's curl!
   if (!ini_get('safe_mode') && extension_loaded('curl')) {
     $ch = curl_init($url);
-    curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_NOBODY => true));
+    curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_NOBODY => TRUE));
     if ((curl_exec($ch) != 0) || (substr(curl_getinfo($ch, CURLINFO_HTTP_CODE), 0, 1) != '2')) $denied = TRUE;
     curl_close($ch);
     return (!isset($denied));
   }
-  else return (substr(drupal_http_request($url, NULL,'HEAD')->code,0,1) == '2');
+  else {
+    return (substr(drupal_http_request($url, NULL, 'HEAD')->code, 0, 1) == '2');
+  }
 }
