[Xfce4-commits] <wiki:master> Add help redirect script.
Nick Schermer
noreply at xfce.org
Fri Jan 6 21:16:01 CET 2012
Updating branch refs/heads/master
to e3a78a5a4ffdf57e7a1b12c0de874a8ec9ae3185 (commit)
from 1573b0f2fe016dfaa47f6bffa3d5f4854798f206 (commit)
commit e3a78a5a4ffdf57e7a1b12c0de874a8ec9ae3185
Author: Nick Schermer <nick at xfce.org>
Date: Fri Jan 6 21:15:08 2012 +0100
Add help redirect script.
help.php | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/help.php b/help.php
new file mode 100644
index 0000000..8bb679b
--- /dev/null
+++ b/help.php
@@ -0,0 +1,103 @@
+<?php
+
+function get_value($name, $fallback = null)
+{
+ if (isset ($_GET[$name]))
+ return $_GET[$name];
+ return $fallback;
+}
+
+/* Path to the dokuwiki data */
+$relpath = '/../domains/docs2.xfce.org/data/pages/';
+$root = realpath (dirname ($_SERVER['SCRIPT_FILENAME']) . $relpath);
+if (!is_dir ($root) || !chdir (($root)))
+ die ('Pages path is not properly configured');
+
+/* Subpaths in which components are expected */
+$subdirs = array ('xfce', 'apps', 'panel-plugins', 'thunar-plugins');
+$defpage = 'start';
+
+/* Get information about from the uri */
+//$version = get_value ('version');
+$locale = get_value ('locale');
+$component = get_value ('component');
+$page = get_value ('page', $defpage);
+$offset = get_value ('offset');
+
+/* Start uri */
+$uri = '';
+
+/* Find component */
+if ($component != null)
+{
+ foreach ($subdirs as $subdir)
+ {
+ $path = $subdir.'/'.$component.'/';
+ if (is_dir ($path))
+ {
+ $uri = $path;
+ break;
+ }
+ }
+}
+
+/* Get component page */
+if (is_file ($uri.$page.'.txt'))
+ $uri .= $page;
+elseif (is_file ($uri.$defpage.'.txt'))
+ $uri .= $defpage;
+else
+ $uri = $defpage;
+
+/* Get locales array */
+if (empty ($locale))
+{
+ $locales = array ();
+}
+else
+{
+ /* Sanitize the value */
+ list ($locale) = preg_split ('/[\s.]+/', $locale);
+ $locale = str_replace ('_', '-', $locale);
+
+ /* Create possible locales array */
+ $locales = array ($locale);
+ $codes = explode ('-', $locale);
+ if (count ($codes) > 1)
+ $locales[] = $codes[0];
+}
+
+/* Append browser languages */
+if (isset ($_SERVER['HTTP_ACCEPT_LANGUAGE']))
+{
+ $accept = strtolower ($_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ foreach (explode (',', $accept) as $lang)
+ {
+ list ($code) = explode (';', $lang);
+ if (!in_array ($code, $locales))
+ $locales[] = $code;
+ }
+}
+
+/* Check if there is a translation */
+foreach ($locales as $code)
+{
+ if (!empty ($code) && is_dir ($code))
+ {
+ $path = $code.'/'.$uri;
+ if (is_file ($path.'.txt'))
+ {
+ $uri = $path;
+ break;
+ }
+ }
+}
+
+/* Append the offset */
+if (!empty ($offset))
+ $uri .= '#'.$offset;
+
+/* Redirect */
+header('Location: /'.$uri);
+
+?>
More information about the Xfce4-commits
mailing list