1
0

index.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * bookmark management
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  7. *
  8. * You should have received a copy of the
  9. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  10. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  11. */
  12. /**
  13. * display any error we have
  14. */
  15. ini_set('error_reporting',-1);
  16. ini_set('display_errors',true);
  17. # load the config file
  18. require('./config.php');
  19. # db connection
  20. $db_con = mysql_connect(DB_HOST,DB_USER,DB_PASS) OR die('Can not connect to SQL server');
  21. $db_sel = mysql_select_db(DB_NAME,$db_con) OR die('Can not select database');
  22. # process the add
  23. if(isset($_POST['sub']['submitNew'])) {
  24. $link = trim($_POST['new']['link']);
  25. $title = trim($_POST['new']['title']);
  26. $cat = trim($_POST['new']['category']);
  27. if(!empty($link) && !empty($title) && !empty($cat)) {
  28. $mir = '0';
  29. if(isset($_POST['new']['mirror']) && $_POST['new']['mirror'] == "yes") {
  30. $mir = '1';
  31. }
  32. $query = mysql_query("INSERT INTO `bookmarks`
  33. SET `category` = '".mysql_real_escape_string($cat)."',
  34. `title` = '".mysql_real_escape_string($title)."',
  35. `link` = '".mysql_real_escape_string($link)."',
  36. `date_added` = '".time()."',
  37. `mirror` = '".mysql_real_escape_string($mir)."'");
  38. if($query !== false) {
  39. if($mir === "1") {
  40. // we want a mirror
  41. $insertID = mysql_insert_id();
  42. if(!empty($insertID)) {
  43. $postfields['link'] = $link;
  44. $postfields['saveTo'] = $insertID;
  45. // do the curl call to trigger the mirror creation
  46. # this way "avaoid" any wayting time
  47. $ch = curl_init("http://www.tld.de/createMirror.php");
  48. curl_setopt($ch, CURLOPT_POST, 1); // we use POST
  49. curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  50. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  52. # use this if you protect the script with htaccess
  53. curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
  54. $cResult = curl_exec($ch);
  55. curl_close($ch);
  56. }
  57. }
  58. header("Location: index.php");
  59. }
  60. else {
  61. echo "not saved";
  62. }
  63. }
  64. }
  65. elseif(isset($_POST['sub']['submitEdit']) && isset($_GET['edit']) && !empty($_GET['edit'])) {
  66. # process edit
  67. $link = trim($_POST['new']['link']);
  68. $title = trim($_POST['new']['title']);
  69. $cat = trim($_POST['new']['category']);
  70. if(!empty($link) && !empty($title) && !empty($cat)) {
  71. $query = mysql_query("UPDATE `bookmarks`
  72. SET `category` = '".mysql_escape_string($cat)."',
  73. `title` = '".mysql_escape_string($title)."',
  74. `link` = '".mysql_escape_string($link)."'
  75. WHERE `id` = '".mysql_escape_string($_GET['edit'])."'");
  76. if($query !== false) {
  77. header("Location: index.php");
  78. }
  79. else {
  80. echo "not saved";
  81. }
  82. }
  83. }
  84. # get the bookmarks
  85. $bookmarks = array();
  86. $query = mysql_query('SELECT * FROM `bookmarks` ORDER BY `category`,`title`');
  87. if(mysql_num_rows($query) > 0) {
  88. while($result = mysql_fetch_assoc($query)) {
  89. $bookmarks[$result['id']] = $result;
  90. }
  91. }
  92. ?>
  93. <html>
  94. <head>
  95. <title>Bookmarks for myself</title>
  96. <style type="text/css">
  97. img {
  98. border: 0;
  99. padding: 0;
  100. margin: 0;
  101. }
  102. </style>
  103. </head>
  104. <body>
  105. <?php if(isset($_GET['edit']) && !empty($_GET['edit'])) { ?>
  106. <form method="post" action="">
  107. Link:<br />
  108. <input type="text" name="new[link]" size="60" value="<?php echo $bookmarks[$_GET['edit']]['link']; ?>" /><br />
  109. Titel:<br />
  110. <input type="text" name="new[title]" value="<?php echo $bookmarks[$_GET['edit']]['title']; ?>" size="60" /><br />
  111. Kategorie:<br />
  112. <input type="text" name="new[category]" value="<?php echo $bookmarks[$_GET['edit']]['category']; ?>" size="60" /><br />
  113. <button type="submit" title="Speichern" name="sub[submitEdit]">Speichern</button>
  114. </form>
  115. <?php } else { ?>
  116. <form method="post" action="">
  117. Link:<br />
  118. <input type="text" name="new[link]" size="60" value="" /><br />
  119. Titel:<br />
  120. <input type="text" name="new[title]" value="" size="60" /><br />
  121. Kategorie:<br />
  122. <input type="text" name="new[category]" value="" size="60" /><br />
  123. <br />
  124. <input type="checkbox" name="new[mirror]" value="yes" /> Httrack Mirror anlegen.<br />
  125. <button type="submit" title="Speichern" name="sub[submitNew]">Speichern</button>
  126. </form>
  127. <?php
  128. }
  129. # display the bookmark
  130. if(!empty($bookmarks)) {
  131. $cat = false;
  132. foreach($bookmarks as $entry) {
  133. if($cat != $entry['category']) {
  134. if(!empty($cat)) echo '</ul>';
  135. echo '<h2>'.$entry['category'].'</h2>';
  136. echo '<ul>';
  137. $cat = $entry['category'];
  138. }
  139. echo '<li><a href="'.$entry['link'].'">'.$entry['title'].'</a>';
  140. if($entry['mirror'] == "1") {
  141. echo ' | <a href="http://www.bananas-development-server.de/bookmarkMirror/'.$entry['id'].'/">mirror</a>';
  142. }
  143. echo ' | <a href="index.php?edit='.$entry['id'].'" title="edit"><img src="edit.png" width="16" alt="edit" /></a></li>';
  144. }
  145. echo '</ul>';
  146. }
  147. ?>
  148. </body>
  149. </html>