root/traduc/trunk/www/search.php

Revision 1028 (checked in by gleu, 2 months ago)

Migration de urchin.js à ga.js (Google Analytics, voir
http://www.google.com/support/googleanalytics/bin/answer.py?answer=69588&topic=10988&hl=fr).

  • Property svn:executable set to *
Line 
1 <?
2 $recherche = $_REQUEST['q'];
3 $filtreversion = $_REQUEST['v'];
4
5 ## No backslashes allowed
6 $recherche = preg_replace('/\\\/', '', $recherche);
7 ## Collapse parens into nearby words:
8 $recherche = preg_replace('/\s*\(\s*/', ' (', $recherche);
9 $recherche = preg_replace('/\s*\)\s*/', ') ', $recherche);
10 ## Treat colons as word separators:
11 $recherche = preg_replace('/:/', ' ', $recherche);
12
13 $recherche_value = strlen($recherche)>0 ? $recherche : 'Rechercher';
14
15 $pgconn = @pg_connect("host=localhost dbname=docspgfr user=docspgfr") or die('Connexion impossible');
16
17 $query = "SET client_encoding TO utf8;";
18 $result = pg_query($pgconn, $query);
19
20 $version['801'] = '8.1';
21 $version['802'] = '8.2';
22 $version['803'] = '8.3';
23 ?>
24 <!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
25 <html xmlns="http://www.w3.org/1999/xhtml">
26     <head>
27         <title>Documentation PostgreSQL en français</title>
28         <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
29         <link rel="shortcut icon" href="/favicon.ico" />
30         <link rel="stylesheet" href="css/style.css" type="text/css" title="Test" />
31         <script type="text/javascript">
32         <!--
33         function errorMsg()
34         {
35           alert("Netscape 6 or Mozilla is needed to install a sherlock plugin");
36         }
37
38         function addEngine(name,ext,cat,type)
39         {
40           if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
41             window.sidebar.addSearchEngine(
42               "http://docs.postgresqlfr.org/addon/"+name+".src",
43               "http://docs.postgresqlfr.org/addon/"+name+"."+ext,
44               name,
45               cat );
46           } else {
47             errorMsg();
48           }
49         }
50         //-->
51         </script>       
52     </head>
53     <body>
54     <div id="content">
55         <a id="bandeau" href="http://www.postgresqlfr.org/">
56             <img src="img/gauche.png" id="gauche" alt="PostgreSQL" />
57             <img src="img/droite.png" id="droite" alt="PostgreSQL" />
58         </a>
59 <form method="post" action="search.php">
60   <div>
61   <input id="q" name="q" type="text" size="20" maxlength="255" onfocus="if( this.value=='Rechercher' ) this.value='';" value="<?= strlen($_REQUEST['q'])>0 ? $_REQUEST['q'] : 'Rechercher' ?>" accesskey="s" />
62   <input id="submit" name="submit" type="submit" value="Rechercher" />
63   <select id="v" name="v">
64 <?
65   $query = "SELECT version, count(*) as nb FROM pages GROUP BY version ORDER BY version DESC";
66   $result = pg_query($pgconn, $query);
67
68   echo '<option value="0"';
69   if ($filtreversion=='0') echo ' SELECTED';
70   echo '>(toutes)</option>';
71   $ligne = 1;
72   while ($ligne = pg_fetch_array($result)) {
73     echo '<option value="'.$ligne['version'].'"';
74     if ($filtreversion==$ligne['version'] or (strlen($filtreversion)==0 and $ligne==1))
75       echo ' SELECTED';
76     echo '>'.$version[$ligne['version']].' ('.$ligne['nb'].' pages)</option>';
77     $ligne++;
78   }
79 ?>
80   </select>
81   </div>
82 </form>
83 <?
84 $like[0]="'sql-%".pg_escape_string(ereg_replace(' ','',$recherche))."%.html'";
85 $like[1]="'app-%".pg_escape_string(ereg_replace('_','',$recherche))."%.html'";
86 $like[2]="'app-%".pg_escape_string(ereg_replace('_','-',$recherche))."%.html'";
87
88 $query = "SELECT version, url, titre
89 FROM pages
90 WHERE (url like {$like[0]} OR url like {$like[1]} OR url like {$like[2]}) ";
91 if (array_key_exists($filtreversion, $version)) {
92   $query .= "AND version=".pg_escape_string($filtreversion)." ";
93 }
94 $query .= "ORDER BY version desc, titre ";
95 $result = pg_query($pgconn, $query);
96 if (pg_num_rows($result) > 0) {
97 ?>
98         <div style="text-align:left;text-weight:normal;">
99 <h1>Pages man</h1>
100 <ol>
101 <?
102
103 while ($ligne = pg_fetch_array($result)) {
104   echo '<li>
105 <a href="http://docs.postgresqlfr.org/'.$version[$ligne['version']].'/'.$ligne['url'].'">Manuel PostgreSQL '.$version[$ligne['version']].', '.$ligne['titre'].'</a></li>';
106 }
107
108   $result = pg_query($pgconn, $query);
109 ?>
110 </ol>
111         </div>
112 <?
113 }
114 ?>
115         <div style="text-align:left;text-weight:normal;">
116 <h1>Résultats complets</h1>
117 <ol>
118 <?
119
120 $searchstring = '';
121 if( preg_match_all('/([-!]?)(\S+)\s*/', $recherche, $m, PREG_SET_ORDER ) ) {
122   foreach( $m as $terms ) {
123     if (strlen($terms[1])) {
124       $searchstring .= ' & !';
125     }
126     if (strtolower($terms[2]) === 'and') {
127       $searchstring .= ' & ';
128     }
129     else if (strtolower($terms[2]) === 'or' or $terms[2] === '|') {
130       $searchstring .= ' | ';
131     }
132     else if (strtolower($terms[2]) === 'not') {
133       $searchstring .= ' & !';
134     }
135     else {
136       $searchstring .= " & $terms[2]";
137     }
138   }
139 }
140
141 ## Strip out leading junk
142 $searchstring = preg_replace('/^[\s\&\|]+/', '', $searchstring);
143
144 ## Remove any doubled-up operators
145 $searchstring = preg_replace('/([\!\&\|]) +(?:[\&\|] +)+/', "$1 ", $searchstring);
146
147 ## Remove any non-spaced operators (e.g. "Zounds!")
148 $searchstring = preg_replace('/([^ ])[\!\&\|]/', "$1", $searchstring);
149
150 ## Remove any trailing whitespace or operators
151 $searchstring = preg_replace('/[\s\!\&\|]+$/', '', $searchstring);
152
153 ## Remove unnecessary quotes around everything
154 $searchstring = preg_replace('/^[\'"](.*)[\'"]$/', "$1", $searchstring);
155
156 $query = "SELECT version, url, titre, ts_headline(contenu, q) AS resume, to_char(ts_rank(fti, q)*100, '999.99') AS score
157 FROM pages, to_tsquery('".pg_escape_string($searchstring)."') AS q
158 WHERE fti @@ q ";
159 if (array_key_exists($filtreversion, $version)) {
160   $query .= "AND version=".pg_escape_string($filtreversion)." ";
161 }
162 $query .= "ORDER BY ts_rank(fti, q) DESC, version DESC
163 LIMIT 100";
164 $result = pg_query($pgconn, $query);
165
166 while ($ligne = pg_fetch_array($result)) {
167   echo '<li>
168 <a href="http://docs.postgresqlfr.org/'.$version[$ligne['version']].'/'.$ligne['url'].'">Manuel PostgreSQL '.$version[$ligne['version']].', '.$ligne['titre'].'</a> ['.$ligne['score'].' %]<br/>
169 ...'.$ligne['resume'].'...<br/>&nbsp;<br/>
170 </li>';
171 }
172
173   $result = pg_query($pgconn, $query);
174
175 pg_close($pgconn);
176 ?>
177 </ol>
178         </div>
179
180         <div id="basdepage" >
181             <a href="http://www.postgresqlfr.org/">Retour au site</a>
182             &nbsp;|&nbsp;
183             <a href="http://www.postgresqlfr.org/?q=forum">Forums Web</a>
184             &nbsp;|&nbsp;
185             <a href="http://www.freebsd.org/copyright/license.html">Documentations sous licence BSD</a>
186             &nbsp;|&nbsp;
187             <a href="http://www.mozilla-europe.org/fr/products/firefox/"><img border="0" alt="Get Firefox!" title="Get Firefox!" src="http://sfx-images.mozilla.org/affiliates/Buttons/80x15/white_1.gif"/></a>
188         </div>
189     </div>
190     </div>
191   </body>
192 <script type="text/javascript">
193   var gaJsHost = (("https:" == document.location.protocol) ?
194   "https://ssl." : "http://www.");
195   document.write(unescape("%3Cscript src='" + gaJsHost +
196   "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
197 </script>
198 <script type="text/javascript">
199    var pageTracker = _gat._getTracker("UA-140513-1");
200    pageTracker._initData();
201    pageTracker._trackPageview();
202 </script>
203 </html>
204
Note: See TracBrowser for help on using the browser.