11<?php
2- if (!$ conf =apc_fetch ('ws_config ' )) {
3- include '/local/Web/ws.conf ' ;
4- apc_store ('ws_config ' ,$ conf );
2+ include 'include/languages.inc ' ;
3+ if (!$ conf =apc_fetch ('ws2_config ' )) {
4+ include '/local/Web/ws2.conf ' ;
5+ apc_store ('ws2_config ' ,$ conf );
56}
67$ raw = filter_input (INPUT_GET , 'q ' , FILTER_UNSAFE_RAW );
78$ q = urlencode ($ raw );
89$ r = isset ($ _REQUEST ['results ' ]) ? (int )$ _REQUEST ['results ' ] : 10 ;
910$ s = isset ($ _REQUEST ['start ' ]) ? (int )$ _REQUEST ['start ' ] : 1 ;
10- $ l = isset ($ _REQUEST ['lang ' ]) ? htmlspecialchars ($ _REQUEST ['lang ' ]) : 'en ' ;
11- $ m = isset ($ _REQUEST ['mirror ' ]) ? htmlspecialchars ($ _REQUEST ['mirror ' ]) : '' ;
11+ $ l = isset ($ _REQUEST ['lang ' ]) ? htmlspecialchars ($ _REQUEST ['lang ' ], ENT_QUOTES ) : 'en ' ;
12+ $ m = isset ($ _REQUEST ['mirror ' ]) ? htmlspecialchars ($ _REQUEST ['mirror ' ], ENT_QUOTES ) : '' ;
1213$ sites = array ( 'all ' =>'php.net ' ,
1314 'local ' =>'www.php.net ' ,
14- 'manual ' =>' www.php.net ' ,
15+ 'manual ' =>" www.php.net/manual/ $ l " ,
1516 'news ' =>'news.php.net ' ,
1617 'bugs ' =>'bugs.php.net ' ,
1718 'pear ' =>'pear.php.net ' ,
1819 'pecl ' =>'pecl.php.net ' ,
1920 'talks ' =>'talks.php.net ' ,
2021 );
2122
23+ $ market = 'en-us ' ;
24+ if (!empty ($ LANGUAGES_MAP [$ l ])) $ market = $ LANGUAGES_MAP [$ l ];
25+
2226if (isset ($ sites [$ _REQUEST ['profile ' ]])) {
23- $ scope = $ _REQUEST ['profile ' ];
27+ $ scope = htmlspecialchars ($ _REQUEST ['profile ' ], ENT_QUOTES );
28+ // If they are doing a manual search in a language we don't have a translation for, default to English
29+ if ($ scope == 'manual ' && empty ($ ACTIVE_ONLINE_LANGUAGES [$ l ])) {
30+ $ sites ['manual ' ] = "www.php.net/manual/en " ;
31+ }
2432} else {
25- $ scope = 'all ' ;
33+ $ scope = 'all ' ;
2634}
2735
28- $ request = "{$ conf ['svc ' ]}$ q ?appid= {$ conf ['appid ' ]}&start= $ s &count= $ r &sites= {$ sites [$ scope ]}&lang= $ l &format=json " ;
36+ $ request = "{$ conf ['svc ' ]}?appid= {$ conf ['appid ' ]}&query= $ q %20site: {$ sites [$ scope ]}&version=2.2&Sources=Web&web.offset= $ s &web.count= $ r &market= $ market " ;
2937$ data = @file_get_contents ($ request );
3038list ($ version ,$ status_code ,$ msg ) = explode (' ' ,$ http_response_header [0 ], 3 );
31- if ($ status_code ==200 ) echo ws_boss_massage ($ data );
39+ if ($ status_code ==200 ) echo ws_bing_massage ($ data );
3240else echo serialize ($ http_response_header [0 ]);
3341
34- function ws_boss_massage ($ data ) {
42+ function ws_bing_massage ($ data ) {
3543 $ results = json_decode ($ data , true );
36- $ rsp = $ results ['ysearchresponse ' ];
37- $ set = $ rsp ['resultset_web ' ];
44+ $ rsp = $ results ['SearchResponse ' ][ ' Web ' ];
45+ $ set = $ rsp ['Results ' ];
3846
3947 $ massaged = array (
4048 'ResultSet ' => array (
41- 'totalResultsAvailable ' => $ rsp ['totalhits ' ],
42- 'totalResultsReturned ' => $ rsp [ ' count ' ] ,
43- 'firstResultPosition ' => $ rsp ['start ' ],
49+ 'totalResultsAvailable ' => $ rsp ['Total ' ],
50+ 'totalResultsReturned ' => count ( $ set ) ,
51+ 'firstResultPosition ' => $ rsp ['Offset ' ],
4452 'Result ' => array (),
4553 ),
4654 );
4755
4856 foreach ($ set as $ result ) {
4957 $ massaged ['ResultSet ' ]['Result ' ][] = array (
50- 'Title ' => $ result ['title ' ],
51- 'Summary ' => $ result ['abstract ' ],
52- 'Url ' => $ result ['url ' ],
53- 'ClickUrl ' => $ result ['clickurl ' ],
54- 'MimeType ' => NULL , // Not returned from BOSS
55- 'ModificationDate ' => strtotime ($ result ['date ' ]),
56- 'Cache ' => NULL , // Not returned from BOSS
58+ 'Title ' => $ result ['Title ' ],
59+ 'Summary ' => $ result ['Description ' ],
60+ 'Url ' => $ result ['Url ' ],
61+ 'ClickUrl ' => $ result ['Url ' ],
62+ 'MimeType ' => NULL , // Not returned by Bing
63+ 'ModificationDate ' => strtotime ($ result ['DateTime ' ]),
64+ 'Cache ' => $ result [ ' CacheUrl ' ]
5765 );
5866 }
5967
@@ -64,8 +72,8 @@ function ws_boss_massage($data) {
6472 PDO ::MYSQL_ATTR_USE_BUFFERED_QUERY => true ));
6573$ dbh ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
6674try {
67- $ stmt = $ dbh ->prepare ("INSERT INTO log (query,profile,mirror) VALUES (:query,:profile,:mirror) " );
68- $ stmt ->execute (array (':query ' =>$ raw ,':profile ' =>$ scope ,':mirror ' =>$ m ));
75+ $ stmt = $ dbh ->prepare ("INSERT INTO log (query,profile,mirror,lang ) VALUES (:query,:profile,:mirror,:lang ) " );
76+ $ stmt ->execute (array (':query ' =>$ raw ,':profile ' =>$ scope ,':mirror ' =>$ m, ' :lang ' => $ l ));
6977} catch (PDOException $ e ) {
7078
7179}
0 commit comments