remove old readme
[atutor.git] / mods / _standard / google_search / index.php
1 <?php\r
2 define('AT_INCLUDE_PATH', '../../../include/');\r
3 require(AT_INCLUDE_PATH.'vitals.inc.php');\r
4 require(AT_INCLUDE_PATH.'../mods/_standard/google_search/SOAP_Google.php');\r
5 $_custom_css = $_base_path . 'mods/_standard/google_search/module.css'; // use a custom stylesheet\r
6 $search_key = $_config['gsearch'];\r
7 \r
8 require(AT_INCLUDE_PATH.'header.inc.php');\r
9 ?>\r
10 \r
11 <?php \r
12 /* \r
13  * Check which type of google search this is, and perform the corresponding action\r
14  * Note:        If the key was invalid, it doesn't matter what search type the admin has chosen.\r
15  *                      It should simply just forward the query to the Google site.\r
16  */\r
17 if (!$_config['gsearch'] || $_config['gtype']==GOOGLE_TYPE_SOAP){ ?>\r
18         <?php\r
19         //Search post - SOAP\r
20         if (isset($_GET['submit'])){\r
21                 $google = new SOAP_Google($search_key);\r
22                 $search_array = array();\r
23                 $search_array['filter'] = true; \r
24                 $search_array['query'] = stripslashes($_GET['q']);\r
25                 $search_array['maxResults'] = 10;\r
26                 $search_array['lr'] = "lang_en";\r
27 \r
28                 $result = $google->search($search_array);\r
29 \r
30                 if (isset($result['faultstring'])) {\r
31                         $msg->printErrorS('GOOGLE_QUERY_FAILED');\r
32                 } else if ($result) {\r
33                         echo '<h3>Search Results</h3>';\r
34                         if (is_array($result['resultElements'])) {\r
35                                 echo '<ol>';\r
36 \r
37                                 foreach ($result['resultElements'] as $r) {\r
38                                         echo '<li><a href="' . $r['URL'] . '">' . ($r['title'] ? $r['title'] : '<strong>'._AT('no_title').'</strong>' ) . '</a>';\r
39                                         echo '<br />';\r
40                                         echo '<small>'.($r['snippet'] ? $r['snippet'] : '<strong>'._AT('no_content_avail').'</strong>' ) .'<br /><i>'.$r['URL'].'</i></small>';\r
41                                         echo '</li>';\r
42                                 }\r
43 \r
44                                 if (count($result['resultElements']) == 10) {\r
45                                         $search_array['start'] = 10;    \r
46                                         $result2 = $google->search($search_array);\r
47 \r
48                                         if (false !== $result2) {               \r
49                                                 foreach ($result2['resultElements'] as $r) {\r
50                                                         echo '<li><a href="' . $r['URL'] . '">' . ($r['title'] ? $r['title'] : '<strong>'._AT('no_title').'</strong>' ) . '</a>';\r
51                                                         echo '<br />';\r
52                                                         echo '<small>'.($r['snippet'] ? $r['snippet'] : '<strong>'._AT('no_content_avail').'</strong>' ) .'<br /><i>'.$r['URL'].'</i></small>';\r
53                                                         echo '</li>';\r
54                                                 }\r
55                                         } \r
56                                 }\r
57                                 echo '</ol>';\r
58 \r
59                                 if (count($result2['resultElements']) == 10) {\r
60                                         echo '<p><i>'._AT('top_20').'</i></p>';\r
61                                 }\r
62                         } else {\r
63                                 echo '<p>'._AT('none_found').'</p>';\r
64                         }\r
65                 } \r
66         }\r
67         ?>\r
68         <?php if ($_config['gsearch']): ?>\r
69                 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">\r
70         <?php else: ?>\r
71                 <form action="http://www.google.com/search" method="get" target="_new">\r
72                 <input type="hidden" name="hl" value="<?php echo $_SESSION['lang']; ?>" />\r
73         <?php endif; ?>\r
74 \r
75         <div class="input-form" style="max-width: 525px">\r
76                 <div class="row">\r
77                         <?php echo _AT('google_search_txt'); ?>\r
78                         <?php if (!$_config['gsearch']): ?>\r
79                                 <br /><br />\r
80                                 <p><?php echo _AT('google_new_window'); ?></p>\r
81                         <?php endif; ?>\r
82                 </div>\r
83 \r
84                 <div class="row">\r
85                         <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="keywords"><?php echo _AT('search_words'); ?></label><br />\r
86                         <input type="text" name="q" size="30" id="keywords" value="<?php echo htmlspecialchars($stripslashes($_GET['q'])); ?>" />\r
87                 </div>\r
88 \r
89                 <div class="row buttons">\r
90                         <input type="hidden" name="submit" value="<?php echo _AT('search'); ?>"/>\r
91                         <input type="submit"  accesskey="s" />\r
92                 </div>\r
93 \r
94                 <div class="row">\r
95                         <small><?php echo _AT('powered_by_google'); ?></small>\r
96                 </div>\r
97         </div>\r
98         </form>\r
99 \r
100 <?php\r
101 } elseif ($_config['gtype']==GOOGLE_TYPE_AJAX){  \r
102         $side_menu_q = stripslashes($_GET['q']);        //side menu query\r
103         include('gsearch.php');\r
104 } ?>\r
105 \r
106 \r
107 <?php\r
108 require(AT_INCLUDE_PATH.'footer.inc.php');\r
109 ?>