[geeklog-cvs] geeklog-1.3/public_html lib-common.php,1.334,1.335

dhaun at iowaoutdoors.org dhaun at iowaoutdoors.org
Thu Jul 8 15:38:15 EDT 2004


Update of /var/cvs/geeklog-1.3/public_html
In directory www:/tmp/cvs-serv13869/public_html

Modified Files:
	lib-common.php 
Log Message:
Moved the hacks to get the current URL and to check for Geeklog's front page to their own function. Also extended the hack to work on the Zeus webserver.


Index: lib-common.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/public_html/lib-common.php,v
retrieving revision 1.334
retrieving revision 1.335
diff -C2 -d -r1.334 -r1.335
*** lib-common.php	17 Jun 2004 11:15:29 -0000	1.334
--- lib-common.php	8 Jul 2004 19:38:11 -0000	1.335
***************
*** 2083,2092 ****
          // Give a link to the homepage here since a lot of people use this for
          // navigating the site
-         // Note: We can't use $PHP_SELF here since the site may not be in the
-         // DocumentRoot
  
!         preg_match( "/\/\/[^\/]*(.*)/", $_CONF['site_url'], $pathonly );
!         if(( $HTTP_SERVER_VARS['SCRIPT_NAME'] <> $pathonly[1] . "/index.php" )
!                 OR !empty( $topic ) OR ( $page > 1 ) OR $newstories )
          {
              $sections->set_var( 'option_url',
--- 2083,2088 ----
          // Give a link to the homepage here since a lot of people use this for
          // navigating the site
  
!         if( COM_isFrontpage() )
          {
              $sections->set_var( 'option_url',
***************
*** 2228,2270 ****
  
          // what's our current URL?
!         $thisUrl = $HTTP_SERVER_VARS['SCRIPT_URI'];
!         if( empty( $thisUrl ))
!         {
!             $thisUrl = $HTTP_SERVER_VARS['DOCUMENT_URI'];
!         }
!         if( !empty( $thisUrl ) && !empty( $HTTP_SERVER_VARS['QUERY_STRING'] ))
!         {
!             $thisUrl .= '?' . $HTTP_SERVER_VARS['QUERY_STRING'];
!         }
!         if( empty( $thisUrl ))
!         {
!             $requestUri = $HTTP_SERVER_VARS['REQUEST_URI'];
!             if( empty( $HTTP_SERVER_VARS['REQUEST_URI'] ))
!             {
!                 $requestUri = $HTTP_SERVER_VARS['SCRIPT_NAME'];
!                 if( !empty( $HTTP_SERVER_VARS['QUERY_STRING'] ))
!                 {
!                     $requestUri .= '?' . $HTTP_SERVER_VARS['QUERY_STRING'];     
!                 }
!             }
! 
!             $firstslash = strpos( $_CONF['site_url'], '/' );
!             if( $firstslash === false )
!             {
!                 // special case - assume it's okay
!                 $thisUrl = $_CONF['site_url'] . $requestUri;
!             }
!             else if( $firstslash + 1 == strrpos( $_CONF['site_url'], '/' ))
!             {
!                 // site is in the document root
!                 $thisUrl = $_CONF['site_url'] . $requestUri;
!             }
!             else
!             {
!                 // extract server name first
!                 $pos = strpos( $_CONF['site_url'], '/', $firstslash + 2 );
!                 $thisUrl = substr( $_CONF['site_url'], 0, $pos ) . $requestUri;
!             }
!         }
  
          $retval .= COM_startBlock( $title, $help,
--- 2224,2228 ----
  
          // what's our current URL?
!         $thisUrl = COM_getCurrentURL();
  
          $retval .= COM_startBlock( $title, $help,
***************
*** 2403,2445 ****
      {
          // what's our current URL?
!         $thisUrl = $HTTP_SERVER_VARS['SCRIPT_URI'];
!         if( empty( $thisUrl ))
!         {
!             $thisUrl = $HTTP_SERVER_VARS['DOCUMENT_URI'];
!         }
!         if( !empty( $thisUrl ) && !empty( $HTTP_SERVER_VARS['QUERY_STRING'] ))
!         {
!             $thisUrl .= '?' . $HTTP_SERVER_VARS['QUERY_STRING'];
!         }
!         if( empty( $thisUrl ))
!         {
!             $requestUri = $HTTP_SERVER_VARS['REQUEST_URI'];
!             if( empty( $HTTP_SERVER_VARS['REQUEST_URI'] ))
!             {
!                 $requestUri = $HTTP_SERVER_VARS['SCRIPT_NAME'];
!                 if( !empty( $HTTP_SERVER_VARS['QUERY_STRING'] ))
!                 {
!                     $requestUri .= '?' . $HTTP_SERVER_VARS['QUERY_STRING'];     
!                 }
!             }
! 
!             $firstslash = strpos( $_CONF['site_url'], '/' );
!             if( $firstslash === false )
!             {
!                 // special case - assume it's okay
!                 $thisUrl = $_CONF['site_url'] . $requestUri;
!             }
!             else if( $firstslash + 1 == strrpos( $_CONF['site_url'], '/' ))
!             {
!                 // site is in the document root
!                 $thisUrl = $_CONF['site_url'] . $requestUri;
!             }
!             else
!             {
!                 // extract server name first
!                 $pos = strpos( $_CONF['site_url'], '/', $firstslash + 2 );
!                 $thisUrl = substr( $_CONF['site_url'], 0, $pos ) . $requestUri;
!             }
!         }
  
          $adminmenu = new Template( $_CONF['path_layout'] );
--- 2361,2365 ----
      {
          // what's our current URL?
!         $thisUrl = COM_getCurrentURL();
  
          $adminmenu = new Template( $_CONF['path_layout'] );
***************
*** 3412,3416 ****
  }
  
! /** undo function for htmlspecialchars()
  *
  * This function translates HTML entities created by htmlspecialchars() back
--- 3332,3337 ----
  }
  
! /**
! * undo function for htmlspecialchars()
  *
  * This function translates HTML entities created by htmlspecialchars() back
***************
*** 3768,3773 ****
      else
      {
!         preg_match( "/\/\/[^\/]*(.*)/", $_CONF['site_url'], $pathonly );
!         if(( $HTTP_SERVER_VARS['SCRIPT_NAME'] <> $pathonly[1] . "/index.php" ) OR !empty( $topic ) OR ( $page > 1 ) OR $newstories )
          {
              $sql .= " AND (tid = 'all' AND type <> 'layout')";
--- 3689,3693 ----
      else
      {
!         if( COM_isFrontpage() )
          {
              $sql .= " AND (tid = 'all' AND type <> 'layout')";
***************
*** 5849,5852 ****
--- 5769,5874 ----
  }
  
+ /**
+ * Try to figure out our current URL, including all parameters.
+ *
+ * This is an ugly hack since there's no single variable that returns what
+ * we want and the variables used here may not be available on all servers
+ * and / or setups.
+ *
+ * Seems to work on Apache (1.3.x and 2.x), IIS, and Zeus ...
+ *
+ * @return   string  complete URL, e.g. 'http://www.example.com/blah.php?foo=bar'
+ *
+ */
+ function COM_getCurrentURL()
+ {
+     global $_CONF, $HTTP_SERVER_VARS;
+ 
+     $thisUrl = $HTTP_SERVER_VARS['SCRIPT_URI'];
+     if( empty( $thisUrl ))
+     {
+         $thisUrl = $HTTP_SERVER_VARS['DOCUMENT_URI'];
+     }
+     if( !empty( $thisUrl ) && !empty( $HTTP_SERVER_VARS['QUERY_STRING'] ))
+     {
+         $thisUrl .= '?' . $HTTP_SERVER_VARS['QUERY_STRING'];
+     }
+     if( empty( $thisUrl ))
+     {
+         $requestUri = $HTTP_SERVER_VARS['REQUEST_URI'];
+         if( empty( $HTTP_SERVER_VARS['REQUEST_URI'] ))
+         {
+             // on a Zeus webserver, prefer PATH_INFO over SCRIPT_NAME
+             if( empty( $HTTP_SERVER_VARS['PATH_INFO'] ))
+             {
+                 $requestUri = $HTTP_SERVER_VARS['SCRIPT_NAME'];
+             }
+             else
+             {
+                 $requestUri = $HTTP_SERVER_VARS['PATH_INFO'];
+             }
+             if( !empty( $HTTP_SERVER_VARS['QUERY_STRING'] ))
+             {
+                 $requestUri .= '?' . $HTTP_SERVER_VARS['QUERY_STRING'];     
+             }
+         }
+ 
+         $firstslash = strpos( $_CONF['site_url'], '/' );
+         if( $firstslash === false )
+         {
+             // special case - assume it's okay
+             $thisUrl = $_CONF['site_url'] . $requestUri;
+         }
+         else if( $firstslash + 1 == strrpos( $_CONF['site_url'], '/' ))
+         {
+             // site is in the document root
+             $thisUrl = $_CONF['site_url'] . $requestUri;
+         }
+         else
+         {
+             // extract server name first
+             $pos = strpos( $_CONF['site_url'], '/', $firstslash + 2 );
+             $thisUrl = substr( $_CONF['site_url'], 0, $pos ) . $requestUri;
+         }
+     }
+ 
+     return $thisUrl;
+ }
+ 
+ /**
+ * Check if we're on Geeklog's index page.
+ *
+ * See if we're on the main index page (first page, no topics selected).
+ *
+ * @return   bool    true = we're on the frontpage, false = we're not
+ *
+ */
+ function COM_isFrontpage()
+ {
+     global $_CONF, $HTTP_SERVER_VARS, $topic, $page, $newstories;
+ 
+     // Note: We can't use $PHP_SELF here since the site may not be in the
+     // DocumentRoot
+     $isFrontpage = false;
+ 
+     // on a Zeus webserver, prefer PATH_INFO over SCRIPT_NAME
+     if( empty( $HTTP_SERVER_VARS['PATH_INFO'] ))
+     {
+         $scriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
+     }
+     else
+     {
+         $scriptName = $HTTP_SERVER_VARS['PATH_INFO'];
+     }
+ 
+     preg_match( '/\/\/[^\/]*(.*)/', $_CONF['site_url'], $pathonly );
+     if(( $scriptName <> $pathonly[1] . '/index.php' ) OR
+             !empty( $topic ) OR ( $page > 1 ) OR $newstories )
+     {
+         $isFrontpage = true;
+     }
+ 
+     return $isFrontpage;
+ }
  
  // Now include all plugin functions




More information about the geeklog-cvs mailing list