shared-manual1.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php
  2. define(NAV_NONE, 0);
  3. define(NAV_CLASSENTRY, 1);
  4. define(NAV_CONSTRUCTOR, 2);
  5. define(NAV_METHOD, 3);
  6. define(NAV_SIGNAL, 4);
  7. define(NAV_ENUM, 5);
  8. mysql_connect("localhost","nobody","");
  9. mysql_select_db("gtk");
  10. $NEXT = $PREV = $UP = $HOME = array(false, false);
  11. $TOC = array();
  12. $SIDEBAR_DATA = '';
  13. function recursive_trim(&$s, $k) {
  14. if (is_array($s)) {
  15. array_walk($s, 'recursive_trim');
  16. } else {
  17. $s = trim($s);
  18. }
  19. }
  20. function setupNavigation($data) {
  21. global $NEXT, $PREV, $UP, $HOME, $TOC, $tstamp;
  22. @array_walk($data, 'recursive_trim');
  23. $HOME = @$data["home"];
  24. $HOME[0] = "./";
  25. $NEXT = @$data["next"];
  26. $PREV = @$data["prev"];
  27. $TOC = @$data["toc"];
  28. $UP = @$data["up"];
  29. $tstamp = gmdate("D, d M Y",getlastmod());
  30. }
  31. function makeBorderTOC($this) {
  32. global $NEXT, $PREV, $UP, $HOME, $TOC;
  33. global $SIDEBAR_DATA;
  34. $SIDEBAR_DATA = '<form method="get" action="/manual1-lookup.php">';
  35. /* ALTER FOR LOCAL "../../php-gtk-web/manual1-lookup.php" */
  36. $SIDEBAR_DATA.= '<table border="0" CELLPADDING="4" CELLSPACING="0" WIDTH="160">';
  37. if(sizeof($TOC) > 1) {
  38. $SIDEBAR_DATA.= '<tr valign="top"><td><small>' .
  39. 'lookup: <input type="text" class="small" name="function" size="10"> ' .
  40. make_submit('small_submit.gif', 'lookup', 'bottom') .
  41. '<br></small></td></tr>';
  42. $SIDEBAR_DATA.= '<tr bgcolor="#cccccc"><td></td></tr>';
  43. $SIDEBAR_DATA.= '<tr valign="top"><td>' .
  44. make_link('./', make_image('caret-t.gif', $HOME[1]) . $HOME[1] ) .
  45. '<br></td></tr>';
  46. $SIDEBAR_DATA.= '<tr bgcolor="#cccccc"><td></td></tr>';
  47. if (($HOME[1] != $UP[1]) && $UP[1]) {
  48. $SIDEBAR_DATA.= '<tr valign="top"><td>' .
  49. make_link($UP[0], make_image('caret-u.gif', $UP[1]) . $UP[1] ) .
  50. '<br></td></tr>';
  51. }
  52. $SIDEBAR_DATA.= '<tr valign="top"><td><small>';
  53. for ($i = 0; $i < count($TOC); $i++) {
  54. list($url, $title, $type) = $TOC[$i];
  55. if (!$url || !$title) {
  56. continue;
  57. }
  58. $end = '0.gif';
  59. if ($title == $this) {
  60. $end = '1.gif';
  61. }
  62. switch($type) {
  63. case NAV_CLASSENTRY:
  64. $img = "icon-o".$end;
  65. break;
  66. case NAV_CONSTRUCTOR:
  67. $img = "icon-c".$end;
  68. break;
  69. case NAV_METHOD:
  70. $img = "icon-m".$end;
  71. break;
  72. case NAV_SIGNAL:
  73. $img = "icon-s".$end;
  74. break;
  75. case NAV_ENUM:
  76. $img = "icon-e".$end;
  77. break;
  78. default:
  79. $img = "box-".$end;
  80. }
  81. if ($UP[0] == 'funcref.php') {
  82. $title = eregi_replace(" functions\$", "", $title);
  83. }
  84. $SIDEBAR_DATA .= '&nbsp;' .
  85. make_link($url, make_image($img, $title) . $title ) .
  86. '<br>';
  87. }
  88. $SIDEBAR_DATA.= '</small></td></tr>';
  89. }
  90. $SIDEBAR_DATA.= '</table></form>';
  91. }
  92. function navigationBar($title, $id, $loc) {
  93. global $NEXT, $PREV, $tstamp;
  94. echo '<table border="0" width="100%" bgcolor="#e0e0e0" cellpadding="0" cellspacing="4">';
  95. echo '<tr><td>';
  96. if ($PREV[1]) {
  97. echo make_link( $PREV[0] , make_image('caret-l.gif', 'previous') . $PREV[1] ) ;
  98. }
  99. echo '<br></td>';
  100. echo '<td align="right">';
  101. if ($NEXT[1]) {
  102. echo make_link( $NEXT[0] , $NEXT[1] . make_image('caret-r.gif', 'next') ) ;
  103. }
  104. echo '<br></td>';
  105. echo '</tr>';
  106. echo '<tr bgcolor="#cccccc"><td colspan="2">';
  107. spacer(1,1);
  108. echo '<br></td></tr>';
  109. echo '<tr>';
  110. echo '<td align="right" colspan="2"><small>Last updated: '.$tstamp.'<br>';
  111. # if ($loc == 'bottom') {
  112. # $back_url = 'http://' . $_SERVER['SERVER_NAME'] .
  113. # (($_SERVER['SERVER_PORT']==80) ? '' : ':'.$_SERVER['SERVER_PORT'] ) .
  114. # $_SERVER['PHP_SELF'];
  115. # } else {
  116. global $LANGUAGES;
  117. $links = array();
  118. if($LANGUAGES){
  119. foreach($LANGUAGES as $code=>$name) {
  120. if (file_exists("../$code/$id")) {
  121. $links[] = make_link("../$code/$id", $name);
  122. }
  123. }
  124. }
  125. $file = substr($id,0,-4);
  126. if (file_exists("html/$file.html")) {
  127. $links[] = make_link("html/$file.html", 'Plain HTML');
  128. }
  129. if (count($links)) {
  130. echo 'view this page in ' . join (delim(), $links);
  131. echo '<br></small></td></tr>';
  132. }
  133. echo "</table>\n";
  134. }
  135. function makeTitle($title) {
  136. echo '<tr bgcolor="#d0d0d0" valign="top">';
  137. echo '<td colspan="2"><b>' . $title . '</b><br></td>';
  138. echo "</tr>\n";
  139. }
  140. function makeEntry($row, $show_admin = true, $show_rating = true ) {
  141. global $MAGIC_COOKIE;
  142. echo '<tr valign="top">';
  143. echo '<td bgcolor="#e0e0e0" colspan="2">';
  144. echo '<table border="0" cellpadding="2" cellspacing="0" width="100%">';
  145. echo '<tr valign="top"><td>';
  146. $name = htmlspecialchars($row['user']);
  147. if ($name && $name != "php-gtk@lists.php.net" && $name != "user@example.com") {
  148. if (ereg("(.+)@(.+)\.(.+)",$name)) {
  149. echo '<a href="mailto:'.$name.'">'.$name.'</a><br>';
  150. } else {
  151. echo '<b>'.$name.'</b><br>';
  152. }
  153. }
  154. echo '<small>' . date("d-M-Y h:i", $row['xwhen']) . '</small>';
  155. echo '<br></td>';
  156. echo '<td align="right" nowrap><small>';
  157. if (isset($MAGIC_COOKIE) && $show_admin) {
  158. print_link('/manual1/admin-notes.php?action=edit+' . $row['id'] . '&brief=1',
  159. make_image('notes-edit.gif', 'edit note')
  160. );
  161. echo '&nbsp';
  162. print_link('/manual1/admin-notes.php?action=reject+' . $row['id'] . '&brief=1&popup=1',
  163. make_image('notes-reject.gif', 'reject note'),
  164. 'admin'
  165. );
  166. echo '&nbsp';
  167. print_link('/manual1/admin-notes.php?action=delete+' . $row['id'] . '&brief=1&popup=1',
  168. make_image('notes-delete.gif', 'delete note'),
  169. 'admin'
  170. );
  171. }
  172. echo '<br>';
  173. if ($show_rating) {
  174. echo 'rating: ';
  175. if ( $row['votes'] > 2 ) {
  176. printf('<b>%.01f</b>', $row['rate'] );
  177. } else {
  178. echo '<b><font color="#cc0000">new</font></b>';
  179. }
  180. echo ' | rate: ';
  181. for ($i=1; $i<=5; $i++) {
  182. if ($i>1) {
  183. echo ' <font color="#999999">|</font> ';
  184. }
  185. print_link(htmlspecialchars($_SERVER['PHP_SELF']).'?rate_id='.$row['id'].'&rate_note='.$i, $i);
  186. }
  187. echo '<br>';
  188. }
  189. echo '</small></td></tr>';
  190. echo '<tr bgcolor="#f0f0f0"><td colspan="2">';
  191. echo clean_note($row['note']). '<br>';
  192. echo '</td></tr>';
  193. echo '</table>';
  194. echo '</td></tr>';
  195. }
  196. function updateNotesVoting() {
  197. # probably a better way/place to do this, but ...
  198. if ($_GET['rate_id'] && $_GET['rate_note']) {
  199. $p = parse_url($_SERVER['HTTP_REFERER']);
  200. echo "\n\n<!-- " . $p['path'] . " :: " . $_SERVER['SCRIPT_NAME'] . " -->\n\n";
  201. /* prevent outside scripts from voting */
  202. if ($_SERVER['SCRIPT_NAME']==$p['path']) {
  203. $query = 'UPDATE note SET votes=votes+1, rating=rating+' .
  204. min(5, $_GET['rate_note']) .
  205. ' WHERE id=' . $_GET['rate_id'];
  206. $result_id = @mysql_query($query);
  207. }
  208. }
  209. }
  210. function manualGetUserNotes($title, $id) {
  211. // if we're gtk.php.net, get it from the local DB
  212. // otherwise look in "/manual1/usernotes/$title.txt" (if present)
  213. $notes = array();
  214. # if(is_primary_site() || strstr($MYSITE,"localhost")) {
  215. if ( true ) {
  216. updateNotesVoting();
  217. $query = "SELECT *, UNIX_TIMESTAMP(ts) AS xwhen, IF(votes=0, 10, rating/votes) AS rate FROM note " .
  218. "WHERE sect='$title' OR sect='$id' ORDER BY xwhen DESC, id";
  219. echo "\n\n<!-- DEBUG: $query -->\n\n";
  220. $result_id = @mysql_query($query);
  221. if ($result_id && mysql_num_rows($result_id) > 0) {
  222. echo "\n\n<!-- DEBUG: numrows=" . mysql_num_rows($result_id) . " -->\n\n";
  223. while ($row = mysql_fetch_array($result_id)) {
  224. $notes[] = $row;
  225. }
  226. } else {
  227. echo "\n\n<!-- DEBUG: err=" . @mysql_error($result_id) . " -->\n\n";
  228. }
  229. } else {
  230. $notes_file = "../usernotes/" . urlencode( $title ) . ".txt";
  231. if ( @file_exists( $notes_file ) )
  232. {
  233. $fp = @fopen($notes_file,"r");
  234. if ($fp) {
  235. $body = fread($fp,filesize($notes_file));
  236. if (strlen($body)) {
  237. $notes = @unserialize($body);
  238. }
  239. fclose($fp);
  240. }
  241. }
  242. }
  243. return $notes;
  244. }
  245. function manualUserNotes($title, $id) {
  246. global $LANG, $MYSITE;
  247. $cur = substr(dirname($_SERVER['PHP_SELF']), -2);
  248. if($cur=='al') {
  249. $cur='en';
  250. }
  251. echo "<BR>\n\n";
  252. echo '<table border="0" cellpadding="4" cellspacing="0" width="100%">';
  253. $notes = manualGetUserNotes($title, $id);
  254. $back_url = 'http://' . $_SERVER['SERVER_NAME'] .
  255. (($SERVER_PORT==80) ? '' : ':'.$_SERVER['SERVER_PORT'] ) .
  256. htmlspecialchars($_SERVER['PHP_SELF']);
  257. echo '<tr bgcolor="#d0d0d0" valign="top">';
  258. echo '<td><small>User Contributed Notes<br></small><b>' . $title . '</b><br></td>';
  259. echo '<td align="right">';
  260. print_link('/manual1/add-note.php?sect='.$id.'&redirect='.$back_url,
  261. make_image('notes-add.gif','add a note')
  262. );
  263. echo "&nbsp;";
  264. print_link('/manual1/about-notes.php',
  265. make_image('notes-about.gif', 'about notes')
  266. );
  267. echo "<br></td>\n";
  268. echo "</tr>\n";
  269. if ( sizeof($notes) == 0 ) {
  270. if ( false ) {
  271. echo '<tr valign="top">';
  272. echo '<td bgcolor="#e0e0e0" colspan="2">';
  273. echo 'User contributed notes are not available on this mirror site; try ';
  274. print_link('http://gtk.php.net/manual1/'.$LANG.'/'.$id, 'here');
  275. echo '.<br></td></tr>';
  276. } else {
  277. echo '<tr valign="top">';
  278. echo '<td bgcolor="#e0e0e0" colspan="2">';
  279. echo 'There are no user contributed notes for this page.';
  280. echo '<br></td></tr>';
  281. }
  282. } else {
  283. foreach($notes as $note) {
  284. makeEntry($note);
  285. }
  286. echo "<tr bgcolor=\"#d0d0d0\" valign=\"top\">\n";
  287. echo "<td colspan=\"2\" align=\"right\">\n";
  288. print_link('/manual1/add-note.php?sect='.$id.'&redirect='.$back_url,
  289. make_image('notes-add.gif','add a note')
  290. );
  291. echo "&nbsp;";
  292. print_link('/manual1/about-notes.php',
  293. make_image('notes-about.gif', 'about notes')
  294. );
  295. echo "<br></td>\n";
  296. echo "</tr>\n";
  297. }
  298. echo "</table><br><br>\n";
  299. }
  300. function sendManualHeaders($charset, $LANG) {
  301. global $LANG;
  302. Header("Content-type: text/html;charset=UTF-8");
  303. Header("Content-language: $LANG");
  304. }
  305. function manualHeader($title, $id="") {
  306. global $HTDIG;
  307. makeBorderTOC($title);
  308. commonHeader('PHP-GTK 1 Manual : '.$title);
  309. # create links to plain html and other languages
  310. if (!$HTDIG) {
  311. navigationBar($title, $id, "top");
  312. }
  313. }
  314. function manualFooter($title, $id="") {
  315. global $HTDIG;
  316. if (!$HTDIG) {
  317. manualUserNotes($title,$id);
  318. navigationBar($title, $id, "bottom");
  319. }
  320. commonFooter();
  321. }
  322. function dehtmlspecialchars($str) {
  323. $str = str_replace("&gt;",">",$str);
  324. $str = str_replace("&lt;","<",$str);
  325. $str = str_replace("&quot;","\"",$str);
  326. $str = str_replace("&amp;","&",$str);
  327. return $str;
  328. }
  329. ?>