manual1-lookup.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. require_once 'include/prepend.php';
  3. require_once 'include/manual1-lookup.inc';
  4. $pattern = isset($_POST['pattern']) ? $_POST['PATTERN'] : null;
  5. $function = $_GET['function'];
  6. if (!$function && $pattern) $function = $pattern;
  7. $function = strtolower($function);
  8. /* it gets messy trying to pass $lang around - so get it from the referral dir */
  9. if(isset($_SERVER['HTTP_REFERER']) && strstr(dirname($_SERVER['HTTP_REFERER']), "manual1/")) {
  10. $lang = substr(dirname($_SERVER['HTTP_REFERER']), -2);
  11. } else {
  12. $lang="en";
  13. }
  14. /* there's always one, eh? */
  15. if($lang == "BR") $lang = "pt_BR";
  16. function make404($lang) {
  17. commonHeader("404 Not Found");
  18. $no_path = str_replace("/php-gtk-web/manual1-lookup.php?lang=$lang&amp;function=", "", htmlspecialchars($_SERVER['REQUEST_URI']));
  19. $no_path = ereg_replace('&[x]=[0-9]&[y]=[0-9]', '', $no_path);
  20. echo "<br/>&nbsp;<h1>Not Found</h1><br>";
  21. if(strlen($no_path) < 3)
  22. echo "&nbsp;<b>" . $no_path . "</b> is too short to be used as a search string. <a href=\"$_SERVER[HTTP_REFERER]\">Go back and try something longer</a><br/><br/><br/><br/><br/><br/><br/>";
  23. else echo "&nbsp;The function <b>" . $no_path . "</b> could not be found. <a href=\"$_SERVER[HTTP_REFERER]\">Try again</a><br/><br/><br/><br/><br/><br/><br/>";
  24. commonFooter();
  25. }
  26. function multi_choice($file, $lang) {
  27. global $full_match;
  28. $request = $_GET['function'];
  29. $switch = (int)0;
  30. if($full_match > 1) {
  31. commonHeader('multiple choice');
  32. echo "<br><br>";
  33. echo "<h1>PHP-GTK 1 Manual search results for &quot;$request&quot;</h1>\n";
  34. echo "<br>";
  35. }
  36. elseif($full_match < 1) {
  37. commonHeader('multiple choice');
  38. echo "<br><br>";
  39. echo "<h1>There is no exact match for &quot;$request&quot; in the PHP-GTK 1 Manual.<br>Here is a list of the nearest matches:</h1>\n";
  40. echo "<br>";
  41. $switch = 1;
  42. }
  43. for($i = 0; $i < sizeof($file); $i++) {
  44. $path[$i] = str_replace("/manual1/", "", $file[$i]);
  45. $bits[$i][] = explode(".", $path[$i]);
  46. foreach($bits[$i] as $piece) {
  47. $GTK = substr(strtoupper($piece[0]), strlen($lang) + 1);
  48. $classlink = strtolower($file[$i]);
  49. if(strpos($classlink, "pt_br"))
  50. $classlink = str_replace("pt_br", "pt_BR", $classlink);
  51. if(sizeof($piece) == 5 && $piece[2] == "method") {
  52. similar_text(strtolower($request), strtolower($piece[3]), $percent);
  53. if($percent == 100 && $full_match == 1) {
  54. header("Location: http://$_SERVER[HTTP_HOST]$classlink");
  55. exit;
  56. /* We should have a nice clean separate function for $full_match == 1) */
  57. }
  58. elseif(($percent == 100 && $full_match > 1) || ($percent > 50 && $full_match == 0)) {
  59. echo "<P>&nbsp;$piece[3]() as in the <B><a href = 'http://$_SERVER[HTTP_HOST]$classlink'>$piece[1] $piece[2]</a></B>";
  60. if($switch == 0) echo "?";
  61. echo "</P>";
  62. }
  63. }
  64. elseif(sizeof($piece) == 5 && $piece[2] == "property") {
  65. $prop = strtolower(substr($piece[1], 3, strlen($piece[1])));
  66. if(strstr($prop, "event")) $prop = "event";
  67. similar_text(strtolower($request), strtolower($piece[3]), $percent);
  68. if($percent == 100 && $full_match == 1) {
  69. header("Location: http://$_SERVER[HTTP_HOST]$classlink");
  70. exit;
  71. }
  72. elseif(($percent == 100 && $full_match > 1) || ($percent > 50 && $full_match == 0)) {
  73. echo "<P>&nbsp;\$$prop-&gt;$piece[3] as in the <B><a href = 'http://$_SERVER[HTTP_HOST]$classlink'>$piece[1] $piece[2]</a></B>";
  74. if($switch == 0) echo "?";
  75. echo "</P>";
  76. }
  77. }
  78. elseif(sizeof($piece) == 5) {
  79. similar_text(strtolower($request), strtolower($piece[3]), $percent);
  80. if($percent == 100 && $full_match == 1) {
  81. header("Location: http://$_SERVER[HTTP_HOST]$classlink");
  82. exit;
  83. }
  84. elseif(($percent == 100 && $full_match > 1) || ($percent > 50 && $full_match == 0)) {
  85. echo "<P>&nbsp;&quot;$piece[3]&quot; as in the <B><a href = 'http://$_SERVER[HTTP_HOST]$classlink'>$piece[1] $piece[2]</a></B>";
  86. $i++;
  87. }
  88. }
  89. elseif(sizeof($piece) == 4 && $piece[1] == "enum") {
  90. similar_text(strtolower($request), strtolower($piece[2]), $percent);
  91. if($percent == 100 && $full_match == 1) {
  92. header("Location: http://$_SERVER[HTTP_HOST]$classlink");
  93. exit;
  94. }
  95. elseif(($percent == 100 && $full_match > 1) || ($percent > 50 && $full_match !== 1)) {
  96. echo "<P>&nbsp;[$piece[2]Value] as in the <B><a href = 'http://$_SERVER[HTTP_HOST]$classlink'>$piece[2] $piece[1]s</a></B>";
  97. if($switch == 0) echo "?";
  98. echo "</P>";
  99. }
  100. }
  101. elseif(sizeof($piece) == 4 && $piece[2] == "constructor") {
  102. similar_text(strtolower($request), strtolower($piece[1]), $percent);
  103. if($percent == 100 && $full_match == 1) {
  104. header("Location: http://$_SERVER[HTTP_HOST]$classlink");
  105. exit;
  106. }
  107. elseif(($percent == 100 && $full_match > 1) || ($percent > 50 && $full_match !== 1)) {
  108. echo "<P>&nbsp;$piece[1]() as in the <B><a href = 'http://$_SERVER[HTTP_HOST]$classlink'>$piece[1] $piece[2]</a></B>";
  109. if($switch == 0) echo "?";
  110. echo "</P>";
  111. }
  112. }
  113. elseif(sizeof($piece) == 4) {
  114. similar_text(strtolower($request), strtolower($piece[2]), $percent);
  115. if($percent == 100 && $full_match == 1) {
  116. header("Location: http://$_SERVER[HTTP_HOST]$classlink");
  117. exit;
  118. }
  119. elseif(($percent == 100 && $full_match > 1) || ($percent > 50 && $full_match !== 1)) {
  120. echo "<P>&nbsp;$piece[2]() as in the <B><a href = 'http://$_SERVER[HTTP_HOST]$classlink'>$GTK function</a></B>";
  121. if($switch == 0) echo "?";
  122. echo "</P>";
  123. }
  124. }
  125. elseif(sizeof($piece) == 3 && $piece[2] == "constructor") {
  126. similar_text(strtolower($request), strtolower($piece[1]), $percent);
  127. if($percent == 100 && $full_match == 1) {
  128. header("Location: http://$_SERVER[HTTP_HOST]$classlink");
  129. exit;
  130. }
  131. elseif(($percent == 100 && $full_match > 1) || ($percent > 50 && $full_match !== 1)) {
  132. echo "<P>&nbsp;$piece[1]() as in the <B><a href = 'http://$_SERVER[HTTP_HOST]$classlink.php'>$piece[1] $piece[2]</a></B>";
  133. if($switch == 0) echo "?";
  134. echo "</P>";
  135. }
  136. }
  137. elseif(sizeof($piece) == 3) {
  138. similar_text(strtolower($request), strtolower($piece[1]), $percent);
  139. if($percent == 100 && $full_match == 1) {
  140. header("Location: http://$_SERVER[HTTP_HOST]$classlink");
  141. exit;
  142. }
  143. elseif(($percent == 100 && $full_match > 1) || ($percent > 50 && $full_match !== 1)) {
  144. echo "<P>&nbsp;$piece[1] as in the <B><a href = 'http://$_SERVER[HTTP_HOST]$classlink'>$piece[1] class</a></B>";
  145. if($switch == 0) echo "?";
  146. echo "</P>";
  147. }
  148. }
  149. }
  150. }
  151. echo "<br><a href=$_SERVER[HTTP_REFERER]>Back</a>";
  152. commonFooter();
  153. }
  154. $function = strtolower($_GET['function']);
  155. if(strlen($function) < 3) {
  156. make404($lang);
  157. exit;
  158. }
  159. $file = find_manual_page($lang, $function);
  160. if(is_array($file)) {
  161. if(sizeof($file) < 2) {
  162. $file = strtolower($file[0]);
  163. if(strpos($file, "pt_br"))
  164. $file = str_replace("pt_br", "pt_BR", $file);
  165. header("Location: http://$_SERVER[HTTP_HOST]$file");
  166. exit;
  167. }
  168. multi_choice($file, $lang);
  169. exit;
  170. }
  171. elseif($file && !is_array($file)) {
  172. $file = strtolower($file);
  173. if(strpos($file, "pt_br"))
  174. $file = str_replace("pt_br", "pt_BR", $file);
  175. header("Location: http://$_SERVER[HTTP_HOST]$file");
  176. exit;
  177. }
  178. else {
  179. make404($lang);
  180. exit;
  181. }
  182. ?>