export.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. if (!isset ($_POST['browser']) || $_POST['browser'] == "" ||
  3. ($_POST['browser'] != "netscape" &&
  4. $_POST['browser'] != "opera" &&
  5. $_POST['browser'] != "IE")) {
  6. # header.php is included here, because we want to print
  7. # plain text when exporting bookmarks, so that browsers
  8. # can handle results better. header.php is needed only to
  9. # display html.
  10. require_once ("./header.php");
  11. logged_in_only ();
  12. $folderid = set_get_folderid ();
  13. # get the browser type for default setting below if possible
  14. if( preg_match ("/opera/i", $_SERVER['HTTP_USER_AGENT'])) {
  15. $default_browser = "opera";
  16. }
  17. else if (preg_match ("/msie/i", $_SERVER['HTTP_USER_AGENT'])) {
  18. $default_browser = "IE";
  19. }
  20. else{
  21. $default_browser = "netscape";
  22. }
  23. ?>
  24. <h1 id="caption">Export Bookmarks</h1>
  25. <!-- Wrapper starts here. -->
  26. <div style="min-width: <?php echo 230 + $settings['column_width_folder']; ?>px;">
  27. <!-- Menu starts here. -->
  28. <div id="menu">
  29. <h2 class="nav">Bookmarks</h2>
  30. <ul class="nav">
  31. <li><a href="./index.php">My Bookmarks</a></li>
  32. <li><a href="./shared.php">Shared Bookmarks</a></li>
  33. </ul>
  34. <h2 class="nav">Tools</h2>
  35. <ul class="nav">
  36. <?php if (admin_only ()) { ?>
  37. <li><a href="./admin.php">Admin</a></li>
  38. <?php } ?>
  39. <li><a href="./import.php">Import</a></li>
  40. <li><a href="./export.php">Export</a></li>
  41. <li><a href="./sidebar.php">View as Sidebar</a></li>
  42. <li><a href="./settings.php">Settings</a></li>
  43. <li><a href="./index.php?logout=1">Logout</a></li>
  44. </ul>
  45. <!-- Menu ends here. -->
  46. </div>
  47. <!-- Main content starts here. -->
  48. <div id="main">
  49. <div id="content">
  50. <form enctype="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="POST">
  51. <table border="0">
  52. <tr>
  53. <td>
  54. Export Bookmarks to Browser:
  55. </td>
  56. <td width="<?php echo $column_width_folder?>">
  57. <select name="browser">
  58. <option value="IE"<?php if ($default_browser == "IE") {echo " selected"; } ?>>Internet Explorer</option>
  59. <option value="netscape"<?php if ($default_browser == "netscape") {echo " selected"; } ?>>Netscape / Mozilla</option>
  60. <option value="opera"<?php if ($default_browser == "opera") {echo " selected"; } ?>>Opera .adr</option>
  61. </select>
  62. </td>
  63. </tr>
  64. <tr>
  65. <td>Character encoding</td>
  66. <td>
  67. <select name="charset">
  68. <?php
  69. $charsets = return_charsets ();
  70. foreach ($charsets as $value) {
  71. $selected = '';
  72. if ($value == 'UTF-8') {$selected = ' selected';}
  73. echo '<option value="'.$value.'"'.$selected.'>'.$value.'</option>' . "\n";
  74. }
  75. ?>
  76. </select>
  77. </td>
  78. </tr>
  79. <tr>
  80. <td>
  81. Folder to export:
  82. </td>
  83. <td>
  84. <div style="width:<?php echo $column_width_folder; ?>; height:350px; overflow:auto;">
  85. <?php
  86. require_once (ABSOLUTE_PATH . "folders.php");
  87. $tree = new folder;
  88. $tree->make_tree (0);
  89. $tree->print_tree ();
  90. ?>
  91. </div>
  92. </td>
  93. </tr>
  94. <tr>
  95. <td>
  96. <input type="hidden" name="folder" value="<?php echo $folderid; ?>">
  97. <input type="submit" value="Export">
  98. <input type="button" value=" Cancel " onClick="self.location.href='./index.php'">
  99. </td>
  100. <td>
  101. </td>
  102. </tr>
  103. </table>
  104. </form>
  105. </div>
  106. <!-- Main content ends here. -->
  107. </div>
  108. <!-- Wrapper ends here. -->
  109. </div>
  110. <?php
  111. print_footer ();
  112. require_once (ABSOLUTE_PATH . "footer.php");
  113. }
  114. else{
  115. # these files are being included, because we do not want to include
  116. # header.php since there is no reason for the http header to display.
  117. define ("ABSOLUTE_PATH", dirname (__FILE__) . "/");
  118. require_once (ABSOLUTE_PATH . "lib/webstart.php");
  119. require_once (ABSOLUTE_PATH . "config/config.php");
  120. require_once (ABSOLUTE_PATH . "lib/mysql.php");
  121. $mysql = new mysql;
  122. require_once (ABSOLUTE_PATH . "lib/auth.php");
  123. $auth = new Auth;
  124. require_once (ABSOLUTE_PATH . "lib/lib.php");
  125. logged_in_only ();
  126. require_once (ABSOLUTE_PATH . "lib/login.php");
  127. $browser = set_post_browser ();
  128. if ($browser == "opera") {
  129. $filename = "opera6.adr";
  130. }
  131. else if ($browser == "IE") {
  132. $filename = "bookmark.htm";
  133. }
  134. else if ($browser == "netscape") {
  135. $filename = "bookmarks.html";
  136. }
  137. else {
  138. $filename = "bookmarks.html";
  139. }
  140. header("Content-Disposition: attachment; filename=$filename");
  141. header("Content-type: application/octet-stream");
  142. header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
  143. header("Cache-Control: post-check=0, pre-check=0", false); // HTTP/1.0
  144. header("Content-Type: text/html; charset=UTF-8");
  145. $folderid = set_get_folderid ();
  146. if ($browser == "netscape" || $browser == "IE") {
  147. echo "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n";
  148. echo "<TITLE>Bookmarks</TITLE>\n";
  149. echo "<H1>Bookmarks</H1>\n";
  150. echo "<DL><p>\n";
  151. $export = new export;
  152. $export->make_tree ($folderid);
  153. echo "</DL><p>\n";
  154. }
  155. else if ($browser == "opera") {
  156. echo "Opera Hotlist version 2.0\n";
  157. echo "Options: encoding = utf8, version=3\n\n";
  158. $export = new export;
  159. $export->make_tree ($folderid);
  160. }
  161. }
  162. class export {
  163. function export () {
  164. global $settings, $browser;
  165. # collect the folder data
  166. require_once (ABSOLUTE_PATH . "folders.php");
  167. $this->tree = new folder;
  168. $this->tree->folders[0] = array ('id' => 0, 'childof' => null, 'name' => $settings['root_folder_name']);
  169. global $username, $mysql;
  170. $this->browser = $browser;
  171. $this->counter = 0;
  172. # work around PHP < 5 problem
  173. # http://bugs.php.net/bug.php?id=25670
  174. if (intval(str_replace('.', '', phpversion())) < 500) {
  175. $this->charset = 'iso-8859-1';
  176. }
  177. else {
  178. $this->charset = set_post_charset ();
  179. }
  180. # collect the bookmark data
  181. $query = sprintf ("SELECT title, url, description, childof, id
  182. FROM bookmark
  183. WHERE user='%s'
  184. AND deleted!='1'",
  185. $mysql->escape ($username));
  186. if ($mysql->query ($query)) {
  187. while ($row = mysqli_fetch_assoc ($mysql->result)) {
  188. if (!isset ($this->bookmarks[$row['childof']])) {
  189. $this->bookmarks[$row['childof']] = array ();
  190. }
  191. array_push ($this->bookmarks[$row['childof']], $row);
  192. }
  193. }
  194. else {
  195. message ($mysql->error);
  196. }
  197. }
  198. function make_tree ($id) {
  199. if (isset ($this->tree->children[$id])) {
  200. $this->counter++;
  201. foreach ($this->tree->children[$id] as $value) {
  202. $this->print_folder ($value);
  203. $this->make_tree ($value);
  204. $this->print_folder_close ();
  205. }
  206. $this->counter--;
  207. }
  208. $this->print_bookmarks ($id);
  209. }
  210. function print_folder ($folderid) {
  211. $spacer = str_repeat (" ", $this->counter);
  212. $foldername = html_entity_decode ($this->tree->folders[$folderid]['name'], ENT_QUOTES, $this->charset);
  213. if ($this->browser == "netscape") {
  214. echo $spacer . "<DT><H3>" . $foldername . "</H3>\n";
  215. echo $spacer . "<DL><p>\n";
  216. }
  217. else if ($this->browser == "IE") {
  218. echo $spacer . '<DT><H3 FOLDED ADD_DATE="">' . $foldername . "</H3>\n";
  219. echo $spacer . "<DL><p>\n";
  220. }
  221. else if ($this->browser == "opera") {
  222. echo "\n#FOLDER\n";
  223. echo "\tNAME=" . $foldername . "\n";
  224. }
  225. }
  226. function print_folder_close () {
  227. $spacer = str_repeat (" ", $this->counter);
  228. if ($this->browser == "netscape" || $this->browser == "IE"){
  229. echo $spacer . "</DL><p>\n";
  230. }
  231. else if ($this->browser == "opera"){
  232. echo "\n-\n";
  233. }
  234. }
  235. function print_bookmarks ($folderid) {
  236. $spacer = str_repeat (" ", $this->counter);
  237. if (isset ($this->bookmarks[$folderid])) {
  238. foreach ($this->bookmarks[$folderid] as $value) {
  239. $url = html_entity_decode ($value['url'], ENT_QUOTES, $this->charset);
  240. $title = html_entity_decode ($value['title'], ENT_QUOTES, $this->charset);
  241. if ($value['description'] != '') {
  242. $description = html_entity_decode ($value['description'], ENT_QUOTES, $this->charset);
  243. }
  244. else {
  245. $description = '';
  246. }
  247. if ($this->browser == 'netscape') {
  248. echo $spacer . ' <DT><A HREF="' . $url . '">' . $title . "</A>\n";
  249. if ($description != '') {
  250. echo $spacer . ' <DD>' . $description . "\n";
  251. }
  252. }
  253. else if ($this->browser == 'IE') {
  254. echo $spacer . ' <DT><A HREF="' . $url . '" ADD_DATE="" LAST_VISIT="" LAST_MODIFIED="">' . $title . "</A>\n";
  255. # unfortunately description for bookmarks in MS Internet Explorer is not supported.
  256. # thats why we just ignore the output of the description here.
  257. }
  258. else if ($this->browser == 'opera') {
  259. echo "\n#URL\n";
  260. echo "\tNAME=" . $title . "\n";
  261. echo "\tURL=" . $url . "\n";
  262. if ($description != "") {
  263. # opera cannot handle the \r\n character, so we fix this.
  264. $description = str_replace ("\r\n", " ", $description);
  265. echo "\tDESCRIPTION=" . $description . "\n";
  266. }
  267. }
  268. }
  269. }
  270. }
  271. }
  272. ?>