shared-manual.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <?php
  2. require_once('cvs-auth.inc');
  3. define('NAV_NONE', 0);
  4. define('NAV_CLASSENTRY', 1);
  5. define('NAV_CONSTRUCTOR', 2);
  6. define('NAV_METHOD', 3);
  7. define('NAV_SIGNAL', 4);
  8. define('NAV_ENUM', 5);
  9. $NEXT = $PREV = $UP = $HOME = array(false, false);
  10. $TOC = array();
  11. $SIDEBAR_DATA = '';
  12. function recursive_trim(&$s, $k) {
  13. if (is_array($s)) {
  14. array_walk($s, 'recursive_trim');
  15. } else {
  16. $s = trim($s);
  17. }
  18. }
  19. function setupNavigation($data) {
  20. global $NEXT, $PREV, $UP, $HOME, $TOC, $tstamp;
  21. @array_walk($data, 'recursive_trim');
  22. $HOME = @$data["home"];
  23. $HOME[0] = "./";
  24. $NEXT = @$data["next"];
  25. $PREV = @$data["prev"];
  26. $TOC = @$data["toc"];
  27. $UP = @$data["up"];
  28. $tstamp = gmdate("D, d M Y", getlastmod());
  29. }
  30. function makeBorderTOC($this) {
  31. global $NEXT, $PREV, $UP, $HOME, $TOC;
  32. global $SIDEBAR_DATA;
  33. $SIDEBAR_DATA = '<form method="get" action="/manual-lookup.php">';
  34. $SIDEBAR_DATA.= '<table border="0" cellpadding="4" cellspacing="0" width="160">';
  35. if(sizeof($TOC) > 1) {
  36. $SIDEBAR_DATA.= '<tr valign="top"><td><small>' .
  37. 'lookup: <input type="text" class="small" name="function" size="10"/> ' .
  38. make_submit('small_submit.gif', 'lookup', 'bottom') .
  39. '<br /></small></td></tr>';
  40. $SIDEBAR_DATA.= '<tr bgcolor="#cccccc"><td></td></tr>';
  41. $SIDEBAR_DATA.= '<tr valign="top"><td>' .
  42. make_link('./', make_image('caret-t.gif', $HOME[1]) . $HOME[1] ) .
  43. '<br /></td></tr>';
  44. $SIDEBAR_DATA.= '<tr bgcolor="#cccccc"><td></td></tr>';
  45. if (($HOME[1] != $UP[1]) && $UP[1]) {
  46. $SIDEBAR_DATA.= '<tr valign="top"><td>' .
  47. make_link($UP[0], make_image('caret-u.gif', $UP[1]) . $UP[1] ) .
  48. '<br /></td></tr>';
  49. }
  50. $SIDEBAR_DATA.= '<tr valign="top"><td>';
  51. for ($i = 0; $i < count($TOC); $i++) {
  52. list($url, $title, $type) = $TOC[$i];
  53. if (!$url || !$title) {
  54. continue;
  55. }
  56. $end = '0.gif';
  57. if ($title == $this) {
  58. $end = '1.gif';
  59. }
  60. switch($type) {
  61. case NAV_CLASSENTRY:
  62. $img = "icon-o".$end;
  63. break;
  64. case NAV_CONSTRUCTOR:
  65. $img = "icon-c".$end;
  66. break;
  67. case NAV_METHOD:
  68. $img = "icon-m".$end;
  69. break;
  70. case NAV_SIGNAL:
  71. $img = "icon-s".$end;
  72. break;
  73. case NAV_ENUM:
  74. $img = "icon-e".$end;
  75. break;
  76. default:
  77. $img = "box-".$end;
  78. }
  79. if ($UP[0] == 'funcref.php') {
  80. $title = eregi_replace(" functions\$", "", $title);
  81. }
  82. $SIDEBAR_DATA .= '&nbsp;' .
  83. make_link($url, make_image($img, $title) . $title ) .
  84. '<br />';
  85. }
  86. $SIDEBAR_DATA.= '</td></tr>';
  87. }
  88. $SIDEBAR_DATA.= '</table></form>';
  89. }
  90. function navigationBar($title, $id, $loc) {
  91. global $NEXT, $PREV, $tstamp, $LANGUAGES, $man2_languages;
  92. echo '<table border="0" width="100%" bgcolor="#e0e0e0" cellpadding="0" cellspacing="4">';
  93. echo '<tr><td>';
  94. if ($PREV[1]) {
  95. echo make_link( $PREV[0] , make_image('caret-l.gif', 'previous') . $PREV[1] ) ;
  96. }
  97. echo '<br /></td>';
  98. echo '<td align="right">';
  99. if ($NEXT[1]) {
  100. echo make_link( $NEXT[0] , $NEXT[1] . make_image('caret-r.gif', 'next') ) ;
  101. }
  102. echo '<br /></td>';
  103. echo '</tr>';
  104. echo '<tr bgcolor="#cccccc"><td colspan="2">';
  105. spacer(1,1);
  106. echo '<br /></td></tr>';
  107. echo '<tr>';
  108. echo '<td align="right" colspan="2"><small>Last updated: '.$tstamp.'<br />';
  109. $links = array();
  110. foreach($LANGUAGES as $code=>$name) {
  111. if (in_array($code, $man2_languages) && file_exists("../$code/$id")) {
  112. $links[] = make_link("../$code/$id", $name);
  113. }
  114. }
  115. $file = substr($id, 0, -4);
  116. if (file_exists("html/$file.html")) {
  117. $links[] = make_link("html/$file.html", 'Plain HTML');
  118. }
  119. if (count($links)) {
  120. echo 'view this page in ' . join (delim(), $links);
  121. echo '<br />';
  122. }
  123. echo '</small></td></tr>';
  124. echo "</table>\n";
  125. }
  126. function makeTitle($title) {
  127. echo "<tr bgcolor='#d0d0d0' valign='top'>\n";
  128. echo "<td colspan='2'><b>$title</b><br /></td>\n";
  129. echo "</tr>\n";
  130. }
  131. function makeEntry($row, $show_admin = false) {
  132. echo "<tr valign='top'>\n";
  133. echo "<td bgcolor='#e0e0e0' colspan='2'>\n";
  134. echo "<table border='0' cellpadding='2' cellspacing='0' width='100%'>\n";
  135. echo "<tr valign='top'>\n<td>\n";
  136. $name = $row['display'];
  137. if ($name) {
  138. echo "<b>$name</b><br />\n";
  139. }
  140. echo "<small>" . date('d-M-Y H:i', $row['date']) . "</small>\n";
  141. echo "<br />\n</td>\n";
  142. echo "<td align='right' nowrap><small>";
  143. if (get_user() && $show_admin) {
  144. $get = (isset($_POST['queue']) || array_key_exists('q', $_GET)) ? '&q': null;
  145. $get .= isset($_GET['let']) ? "&amp;let={$_GET['let']}" : null;
  146. $get .= isset($_GET['y']) ? "&amp;y={$_GET['y']}" : null;
  147. print_link("{$_SERVER['PHP_SELF']}?edit={$row['id']}$get",
  148. make_image('notes-edit.gif', 'edit note'));
  149. echo '&nbsp';
  150. print_link("{$_SERVER['PHP_SELF']}?reject={$row['id']}$get",
  151. make_image('notes-reject.gif', 'reject note'));
  152. echo '&nbsp';
  153. print_link("{$_SERVER['PHP_SELF']}?delete={$row['id']}$get",
  154. make_image('notes-delete.gif', 'delete note'));
  155. }
  156. echo "<br />\n";
  157. echo "</small></td>\n</tr>\n";
  158. echo "<tr bgcolor='#f0f0f0'>\n<td colspan='2'>\n";
  159. if (strstr($row['comment'], '&lt;?')) {
  160. $note = do_highlighting($row['comment']);
  161. } else {
  162. $note = nl2br(stripslashes($row['comment']));
  163. }
  164. echo "\n<br />\n".$note."\n<br />\n";
  165. echo "</td>\n</tr>\n";
  166. echo "</table>\n";
  167. echo "</td>\n</tr>\n";
  168. }
  169. function do_highlighting($orig_note) {
  170. $startcodes = array();
  171. $endcodes = array();
  172. $samples = array();
  173. $clean_samples = array();
  174. $lines = explode("\n", $orig_note);
  175. $i = 0;
  176. /* find PHP start and end tags */
  177. foreach ($lines as $line) {
  178. if (strstr($line, '&lt;?')) {
  179. $startcodes[] = $i;
  180. }
  181. if (strstr($line, "?&gt;")) {
  182. $endcodes[] = $i;
  183. }
  184. $i++;
  185. }
  186. /* collect code samples */
  187. foreach($startcodes as $key => $startcode) {
  188. if (isset($endcodes[$key])) {
  189. $samples[] = array_slice($lines, $startcode, ($endcodes[$key] - ($startcode - 1)));
  190. }
  191. }
  192. /* clean code samples */
  193. if (!empty($samples)) {
  194. foreach($samples as $sample) {
  195. foreach($sample as $number => $sampleline) {
  196. $sample[$number] = strip_tags($sampleline);
  197. }
  198. $clean_samples[] = $sample;
  199. }
  200. }
  201. /* make the array be a string again */
  202. $data = implode("<br />\n", $lines);
  203. /* highlight code samples */
  204. if (!empty($clean_samples)) {
  205. foreach($clean_samples as $number => $sample) {
  206. $original = implode("<br />\n", $samples[$number]);
  207. $string = trim(implode("\n", $sample));
  208. $string = str_replace("&gt;", '>', $string);
  209. $string = str_replace("&lt;", '<', $string);
  210. $string = str_replace('&quot;', '"', $string);
  211. $string = str_replace('&amp;', '&', $string);
  212. ob_start();
  213. highlight_string($string);
  214. $highlit = ob_get_contents();
  215. ob_end_clean();
  216. $highlit = preg_replace("'([a-zA-Z0-9\=])&nbsp;'", "$1 ", $highlit);
  217. if (substr(PHP_OS, 0, 3) == 'WIN') {
  218. $highlit = str_replace("\r<br />", "<br />\r", $highlit);
  219. } else {
  220. $highlit = str_replace("\n<br />", "<br />\n", $highlit);
  221. }
  222. $data = str_replace($original, $highlit, $data);
  223. }
  224. }
  225. return $data;
  226. }
  227. function manualGetUserNotes($id) {
  228. global $okfile, $notesfile;
  229. $notes = array();
  230. if (file_exists($okfile) || $user = get_user()) {
  231. $db = sqlite_open($notesfile);
  232. $result = sqlite_array_query($db, "SELECT * FROM notes WHERE page = '$id' ORDER BY date DESC");
  233. foreach ($result as $row) {
  234. $notes[] = $row;
  235. }
  236. sqlite_close($db);
  237. }
  238. return $notes;
  239. }
  240. function manualUserNotes($title, $id) {
  241. $current = dirname($_SERVER['PHP_SELF']);
  242. $toplevel = substr($current, 0, strrpos($current, '/'));
  243. echo "<br />\n\n";
  244. echo '<table border="0" cellpadding="4" cellspacing="0" width="100%">';
  245. $notes = manualGetUserNotes($id);
  246. $ref = isset($_SERVER['HTTP_REFERER']) ? null : "?ref={$_SERVER['PHP_SELF']}";
  247. echo '<tr bgcolor="#d0d0d0" valign="top">';
  248. echo '<td><small>User Contributed Notes<br /></small><b>' . $id . '</b><br /></td>';
  249. echo '<td align="right">';
  250. print_link($toplevel.'/add-note.php'.$ref, make_image('notes-add.gif','add a note'));
  251. echo "&nbsp;";
  252. print_link($toplevel.'/about-notes.php'.$ref, make_image('notes-about.gif', 'about notes'));
  253. echo "<br /></td>\n";
  254. echo "</tr>\n";
  255. if (sizeof($notes) == 0) {
  256. echo '<tr valign="top">';
  257. echo '<td bgcolor="#e0e0e0" colspan="2">';
  258. echo 'There are no user contributed notes for this page.';
  259. echo '<br /></td></tr>';
  260. } else {
  261. foreach($notes as $note) {
  262. makeEntry($note);
  263. }
  264. echo "<tr bgcolor=\"#d0d0d0\" valign=\"top\">\n";
  265. echo "<td colspan=\"2\" align=\"right\">\n";
  266. print_link($toplevel.'/add-note.php'.$ref, make_image('notes-add.gif','add a note'));
  267. echo "&nbsp;";
  268. print_link($toplevel.'/about-notes.php'.$ref, make_image('notes-about.gif', 'about notes'));
  269. echo "<br /></td>\n";
  270. echo "</tr>\n";
  271. }
  272. echo "</table><br /><br />\n";
  273. }
  274. function sendManualHeaders($charset, $lang) {
  275. header("Content-type: text/html; charset=UTF-8");
  276. header("Content-language: $lang");
  277. }
  278. function manualHeader($title, $id="") {
  279. makeBorderTOC($title);
  280. commonHeader('PHP-GTK 2 Manual : '.$title);
  281. navigationBar($title, $id, "top");
  282. }
  283. function manualFooter($title, $id="") {
  284. manualUserNotes($title, $id);
  285. navigationBar($title, $id, "bottom");
  286. commonFooter();
  287. }
  288. function dehtmlspecialchars($str) {
  289. $str = str_replace("&gt;",">", $str);
  290. $str = str_replace("&lt;","<", $str);
  291. $str = str_replace("&quot;","\"", $str);
  292. $str = str_replace("&amp;","&", $str);
  293. return $str;
  294. }
  295. function makeAdminOpts() {
  296. global $SIDEBAR_DATA;
  297. if (isset($_POST['order'])) {
  298. $order = $_POST['order'];
  299. } elseif (isset($_COOKIE['order'])) {
  300. $order = $_COOKIE['order'];
  301. } else {
  302. $order = 'page';
  303. }
  304. $SIDEBAR_DATA = "<form method='POST' action='browse-notes.php'>\n".
  305. "<table border='0' cellpadding='0' cellspacing='0' align='center'>\n".
  306. "<tr><td valign='top' colspan='3'><br />\n".
  307. make_link('../admin-login.php', '<b>Admin home</b>')."<br />\n<br />\n</td></tr>\n";
  308. if (strstr($_SERVER['PHP_SELF'], '/manual/browse-notes.php')) {
  309. $SIDEBAR_DATA .= "<tr><td valign='top' colspan='3'>\n";
  310. if (!isset($_POST['queue']) && !array_key_exists('q', $_GET)) {
  311. $SIDEBAR_DATA .= make_link($_SERVER['PHP_SELF'].'?q','<b>Queue administration</b>');
  312. } else {
  313. $SIDEBAR_DATA .= make_link($_SERVER['PHP_SELF'],'<b>Notes administration</b>').
  314. "<input type='hidden' name='queue' value='1' />";
  315. }
  316. $SIDEBAR_DATA .= "<br />\n<br />\n</td></tr>\n";
  317. }
  318. $SIDEBAR_DATA .= "<tr><td valign='bottom' colspan='3'><br /><b>Order notes by:</b></td></tr>\n".
  319. "<tr><td valign='top'><br />page (default)</td>\n".
  320. "<td colspan='2'><br /><input type='radio' name='order' value='page'";
  321. if ($order == 'page') $SIDEBAR_DATA .= " checked";
  322. $SIDEBAR_DATA .= " /></td></tr>\n".
  323. "<tr><td valign='top'>user</td>\n".
  324. "<td colspan='2'><input type='radio' name='order' value='display'";
  325. if ($order == 'display') $SIDEBAR_DATA .= " checked";
  326. $SIDEBAR_DATA .= " /></td></tr>\n".
  327. "<tr><td valign='top'>date</td>\n".
  328. "<td><input type='radio' name='order' value='date'";
  329. if ($order == 'date') $SIDEBAR_DATA .= " checked";
  330. $SIDEBAR_DATA .= " /></td>\n<td>&nbsp;&nbsp;".
  331. make_submit('small_submit.gif', 'Order by', 'bottom', 'style = "height: 11; width: 11"').
  332. "</td></tr>\n</table>\n</form>\n";
  333. }
  334. ?>