source: t29-www/lib/search.php @ 736

Last change on this file since 736 was 347, checked in by sven, 11 years ago

Diverse Verbesserungen am Homepagesystem, die bereits lange anstanden.

  • Die Suche ist endlich implementiert, wenngleich auch relativ unschoen mittels einer eingebundenen Google-Suche.

Bugfixes:

  • de/news.php: Syntaxfehler im Neuigkeiten-Menü

Backend-Aenderungen:

  • Englischsprachige Benutzer, die auf die deutsche Seite kommen oder andersrum erhalten einen Hinweis, dass es die andere Sprachversion gibt (noch nicht vollständig implementiert)
  • Es gibt ein besseres Logging-System, welches Client- und Serverausgaben verbindet
  • Das System generiert jetzt selbst Clean-URLs direkt (zumindest aus Menue/Template, Inhalte werden nicht touchiert). Das reduziert die Anzahl der Zugriffe erheblich.
  • Ein paar CSS-Details
  • navigation.xml: "#DUMME-VERLINKUNG"-Einträge entfernt
File size: 3.1 KB
Line 
1<?php
2
3class t29Search {
4        static $actions = array(
5                'opensearch-desc' => 'print_opensearch_desc',
6        );
7
8        function page_handler() {
9                if(!isset($_GET['action'])) {
10                        // This is an "ordinary" page call.
11                        // do some organisation stuff and return.
12                        $this->setup_interlang();
13                        return;
14                }
15                $action = $_GET['action'];
16                if(array_key_exists($action, self::$actions)) {
17                        $method_name = self::$actions[$action];
18                        $this->$method_name();
19                } else {
20                        print "<b>Page action $action unkown!\n";
21                }
22        }
23
24
25        function print_opensearch_desc($lang=null) {
26                $path = array('de' => '/de/suche.php', 'en' => '/en/search.php');
27                // assure a valid given language
28                if(!$lang && isset($_GET['lang'])) $lang = $_GET['lang'];
29                if(!isset($path[$lang])) $lang = 'de';
30               
31                header('Content-Type: application/opensearchdescription+xml');
32                print '<?xml version="1.0"?>'.PHP_EOL;
33                ?>
34                <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
35                        <ShortName>technikum29 (<?=$lang; ?>)</ShortName>
36                        <Description>technikum29 (<?=$lang; ?>)</Description>
37                        <Image height="16" width="16" type="image/x-icon">http://www.technikum29.de/favicon.ico</Image>
38                        <Url type="text/html" method="get" template="http://www.technikum29.de/<?=$path[$lang]; ?>?q={searchTerms}" />
39                        <Url type="application/x-suggestions+json" method="get" template="http://www.technikum29.de/<?=$path[$lang]; ?>?get=suggestions&amp;q={searchTerms}&amp;format=json" />
40                        <Url type="application/x-suggestions+xml" method="get" template="http://www.technikum29.de/<?=$path[$lang]; ?>?get=suggestions&amp;q={searchTerms}&amp;format=xml" />
41                        <moz:SearchForm>http://www.technikum29.de/<?=$path[$lang]; ?></moz:SearchForm>
42                </OpenSearchDescription>
43                <?php
44                exit;
45        }
46       
47        /**
48         * Since the search isn't denoted in the navigation.xml, the interlanguage
49         * system doesn't work. This method fixes that by talking with t29Template.
50         * This must be done after including technikum29.php.
51         **/
52        function setup_interlang() {
53                $GLOBALS['template_callback'] = function($template) {
54                        // Interlanguage Links: Defakto nicht cachebar da das Cachesystem fuer dynamische Seiten
55                        // den header/footer cacht und damit auch die Interlang-Eintraege. Links wie
56                        // "/de/suche.php"+$_SERVER['QUERY_STRING'] funktionieren daher nicht dynamisch,
57                        // da der Head ja gecacht wird. Ist ein nicht so wichtiges FIXME.
58                        $template->set_interlang_link("de", "/de/suche.php", "Suche");
59                        $template->set_interlang_link("en", "/en/search.php", "Search");
60                };
61        }
62       
63        function google_search_snippet() {
64        ?>
65        <script>
66                (function() {
67                var cx = '010117769997860607363:ovbd9zjaaps';
68                var gcse = document.createElement('script');
69                gcse.type = 'text/javascript';
70                gcse.async = true;
71                gcse.src = (document.location.protocol == 'https' ? 'https:' : 'http:') +
72                        '//www.google.com/cse/cse.js?cx=' + cx;
73                var s = document.getElementsByTagName('script')[0];
74                s.parentNode.insertBefore(gcse, s);
75                })();
76        </script>
77        <gcse:search></gcse:search>
78        <?php
79        }
80}
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License