[Xfce4-commits] <docs:master> Add page to handle redirects to user documentation.

Nick Schermer noreply at xfce.org
Mon Apr 25 21:44:02 CEST 2011


Updating branch refs/heads/master
         to dc471645baa766997318e831a77ea4d7591616ad (commit)
       from 5a77b24d3d00c802da9d4b49b69152106987f824 (commit)

commit dc471645baa766997318e831a77ea4d7591616ad
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Apr 25 20:50:03 2011 +0200

    Add page to handle redirects to user documentation.

 index.php => 404.php |   32 +++++++++---------
 help.php             |   85 ++++++++++++++++++++++++++++++++++++++++++++++++++
 index.php            |   15 +++++++--
 3 files changed, 113 insertions(+), 19 deletions(-)

diff --git a/index.php b/404.php
similarity index 53%
copy from index.php
copy to 404.php
index fd304e9..a0c9874 100644
--- a/index.php
+++ b/404.php
@@ -3,7 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-	<title>Xfce Docs</title>
+	<title>Page not found - Xfce Docs</title>
 	<link rel="shortcut icon" href="/style/favicon.png" type="image/png" />
 	<link rel="stylesheet" media="screen" href="/style/base.css" type="text/css" />
 </head>
@@ -29,23 +29,23 @@
 	<div id="xfce-header-clear"></div>
 </div>
 <div id="page-wrap">
-<h1>Xfce Documentation</h1>
-<p>
-  User documentation will be here soonish, but can already be found in the packages.
-</p>
+  <h1>Page not found</h1>
 
+  <h3>We're sorry, the page or file you requested was not found on this server.</h3>
+  <p>
+    If you clicked on a link that brought you to this page, or you have reached
+    this page through a search engine or bookmark, it could very well be that
+    the page you were looking for was removed, renamed or temporary unavailable.
+  </p>
+  <p>
+    Please try one of the following methods to find the page you are looking for:
+  </p>
 
-<h2>API References</h2>
-<ul>
-  <li><a href="/api/exo/">Exo</a> (<a href="/api/exo/ix01.html">Index</a>, <a href="/api/exo-html.tar.bz2">Download</a>)</li>
-  <li><a href="/api/garcon/">Garcon</a> (<a href="/api/garcon/api-index-full.html">Index</a>, <a href="/api/garcon-html.tar.bz2">Download</a>)</li>
-  <li><a href="/api/libxfce4panel/">Libxfce4panel</a> (<a href="/api/libxfce4panel/api-index-full.html">Index</a>, <a href="/api/libxfce4panel-html.tar.bz2">Download</a>)</li>
-  <li><a href="/api/libxfce4ui/">Libxfce4ui</a> (<a href="/api/libxfce4ui/ix01.html">Index</a>, <a href="/api/libxfce4ui-html.tar.bz2">Download</a>)</li>
-  <li><a href="/api/libxfce4util/">ibxfce4util</a> (<a href="/api/libxfce4util-html.tar.bz2">Download</a>)</li>
-  <li><a href="/api/thunarx/">Thunarx</a> (<a href="/api/thunarx/ix01.html">Index</a>, <a href="/api/thunarx-html.tar.bz2">Download</a>)</li>
-  <li><a href="/api/tumbler/">Tumbler</a> (<a href="/api/tumbler/api-index-full.html">Index</a>, <a href="/api/tumbler-html.tar.bz2">Download</a>)</li>
-  <li><a href="/api/xfconf/">Xfconf</a> (<a href="/api/xfconf-html.tar.bz2">Download</a>)</li>
-</ul>
+  <ul>
+    <li>If you typed the page address in the Address bar, make sure that it is spelled correctly.</li>
+    <li>Open the <a href="/">Xfce documentation page</a> and look for links to the information you want.</li>
+    <li>Click the Back button to try another link.</li>
+  </ul>
 </div>
 </body>
 </html>
diff --git a/help.php b/help.php
new file mode 100644
index 0000000..6f3a5f5
--- /dev/null
+++ b/help.php
@@ -0,0 +1,85 @@
+<?php
+
+/* similar function is used in docs.xfce.org */
+function lookup_user_language ($valid_values, $default = 'C')
+{
+  if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
+    return $default;
+
+  $accept = strtolower ($_SERVER['HTTP_ACCEPT_LANGUAGE']);
+  if (empty ($accept))
+    return $default;
+
+  foreach (explode (',', $accept) as $lang)
+  {
+    /* check if we have a match for the full language, ie pt-br */
+    $code = explode (';', $lang, 2); /* explode code and quantifier */
+    $primarytag = str_replace ('-', '_', $code[0]);
+    if (in_array (trim ($primarytag), $valid_values))
+      return $primarytag;
+
+    /* check if we have a match for the sub language, ie pt */
+    $subtag = explode ('-', $code[0]);
+    if (in_array (trim ($subtag[0]), $valid_values))
+      return $subtag[0];
+  }
+
+  return $default;
+}
+
+/* location if nothing is found */
+$location = '/404.php';
+
+if (isset ($_GET['package']))
+{
+  $package = $_GET['package'];
+  $path = 'help/'.$package;
+
+  if (is_dir ($path))
+    {
+      if (isset ($_GET['lang'])
+          && $_GET['lang'] != 'C'
+          && is_dir ($path.'/'.$_GET['lang']))
+        {
+          /* user language exists */
+          $lang = $_GET['lang'];
+        }
+      else
+        {
+          $langs = array ();
+          $dh = opendir ($path);
+
+          /* get list of languages of this package */
+          while (($file = readdir ($dh)) !== false)
+            {
+              if ($file != '..' && $file != '.'
+                  && is_dir ($path.'/'.$file))
+                $langs[] = $file;
+            }
+
+          /* try to determine the language from the users' browser */ 
+          $lang = lookup_user_language ($langs);
+        }
+
+      /* path to the package docs */
+      $path .= '/'.$lang;
+
+      if (isset ($_GET['page']))
+        {
+          $file = $path.'/'.$_GET['page'].'.html';
+          if (is_file ($file))
+            $path = $file;
+        }
+
+      /* we have a valid location */
+      $location = '/'.$path;
+
+      if (isset ($_GET['anchor']))
+        $location .= '#'.$_GET['anchor'];
+    }
+}
+
+/* jump to the document */
+header ('Location: '. $location);
+
+?>
diff --git a/index.php b/index.php
index fd304e9..abce683 100644
--- a/index.php
+++ b/index.php
@@ -30,12 +30,21 @@
 </div>
 <div id="page-wrap">
 <h1>Xfce Documentation</h1>
-<p>
-  User documentation will be here soonish, but can already be found in the packages.
-</p>
+
+<h2>User Documentation</h2>
+<ul>
+  <li><a href="/help.php?package=xfce4-panel">Xfce4-panel</a></li>
+  <li><a href="/help.php?package=terminal">Terminal</a></li>
+</ul>
 
 
 <h2>API References</h2>
+<p>
+  Only the API documentation from the Xfce master branch is available. If functions are not
+  available in older version, you should be able to see that by looking at the 'Since' in
+  the function blocks. Note that the API references are also shipped in the tarballs which
+  you can download from the <a href="http://archive.xfce.org">Xfce Archive</a>.
+</p>
 <ul>
   <li><a href="/api/exo/">Exo</a> (<a href="/api/exo/ix01.html">Index</a>, <a href="/api/exo-html.tar.bz2">Download</a>)</li>
   <li><a href="/api/garcon/">Garcon</a> (<a href="/api/garcon/api-index-full.html">Index</a>, <a href="/api/garcon-html.tar.bz2">Download</a>)</li>



More information about the Xfce4-commits mailing list