bookmark_new.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. require_once ('./header.php');
  3. $get_title = set_title ();
  4. $get_url = set_url ();
  5. logged_in_only ();
  6. $post_title = set_post_title ($persistent = true);
  7. $post_url = set_post_url ();
  8. $post_description = set_post_description ();
  9. $post_childof = set_post_childof ();
  10. $post_public = set_post_bool_var ("public", false);
  11. require_once (ABSOLUTE_PATH . "folders.php");
  12. $tree = new folder;
  13. $query_string = "?expand=" . implode(",", $tree->get_path_to_root ($post_childof)) . "&amp;folderid=" . $post_childof;
  14. if ($post_title == '' || $post_url == '') {
  15. $path = $tree->print_path ($folderid);
  16. if ($post_title != '') {
  17. $title = $post_title;
  18. }
  19. else {
  20. $title = $get_title;
  21. }
  22. if ($post_url != '') {
  23. $url = $post_url;
  24. }
  25. else if ($get_url != '') {
  26. $url = $get_url;
  27. }
  28. else {
  29. $url = 'http://';
  30. }
  31. if (strtolower (basename ($_SERVER['SCRIPT_NAME'])) == 'bookmark_add.php') {
  32. $js_onclick = 'history.back()';
  33. }
  34. else {
  35. $js_onclick = 'self.close()';
  36. }
  37. ?>
  38. <h2 class="title">New Bookmark</h2>
  39. <form action="<?php echo $_SERVER['SCRIPT_NAME'] . "?folderid=" . $folderid; ?>" id="bmnew" method="POST">
  40. <p>Title<br>
  41. <input type=text name="title" size="50" value="<?php echo $title; ?>"></p>
  42. <p>URL<br>
  43. <input type=text name="url" size="50" value="<?php echo $url; ?>"></p>
  44. <p>Description<br>
  45. <textarea name="description" cols="50" rows="8"><?php echo $post_description; ?></textarea></p>
  46. <p><input type="button" value="Select folder" onClick="window.childof=document.forms['bmnew'].childof; window.path=document.forms['bmnew'].path; selectfolder('<?php echo $query_string; ?>')"><br>
  47. <input type="text" name="path" value="<?php echo $path; ?>" size="50" readonly>
  48. <input type="text" name="childof" value="<?php echo $folderid; ?>" size="1" class="invisible" readonly></p>
  49. <p>Tags<br>
  50. <input type=text name="tags" size="50" value="Not yet working"></p>
  51. <input type="submit" value=" OK ">
  52. <input type="button" value=" Cancel " onClick="<?php echo $js_onclick; ?>">
  53. Public <input type="checkbox" name="public" <?php echo $post_public ? "checked" : "";?>>
  54. </form>
  55. <script>
  56. this.focus();
  57. document.getElementById('bmnew').title.focus();
  58. </script>
  59. <?php
  60. }
  61. else {
  62. $query = sprintf ("INSERT INTO bookmark
  63. (user, title, url, description, childof, public)
  64. VALUES ('%s', '%s', '%s', '%s', '%d', '%d')",
  65. $mysql->escape ($username),
  66. $mysql->escape ($post_title),
  67. $mysql->escape ($post_url),
  68. $mysql->escape ($post_description),
  69. $mysql->escape ($post_childof),
  70. $mysql->escape ($post_public));
  71. if ($mysql->query ($query)) {
  72. echo "Bookmark successfully created<br>\n";
  73. $bm_id = mysqli_insert_id ($mysql->link);
  74. }
  75. else {
  76. message ($mysql->error);
  77. }
  78. unset ($_SESSION['title'], $_SESSION['url']);
  79. # safing the favicon in a separate second step is done because
  80. # we want to make sure the bookmark is safed in any case. the
  81. # favicon is not that important.
  82. if ($settings['show_bookmark_icon']) {
  83. require_once (ABSOLUTE_PATH . "favicon.php");
  84. $favicon = new favicon ($post_url);
  85. if (isset ($favicon->favicon)) {
  86. $query = sprintf ("UPDATE bookmark set favicon='%s' WHERE user='%s' AND id='%d'",
  87. $mysql->escape ($favicon->favicon),
  88. $mysql->escape ($username),
  89. $mysql->escape ($bm_id));
  90. $mysql->query ($query);
  91. $icon = '<img src="'.$favicon->favicon.'">';
  92. }
  93. else {
  94. $icon = $bookmark_image;
  95. }
  96. }
  97. if (strtolower (basename ($_SERVER['SCRIPT_NAME'])) == "bookmark_add.php") {
  98. echo 'Back to '.$icon.' <a href="'.$post_url.'">'.$post_title.'</a><br>' . "\n";
  99. echo 'Open '.$folder_opened.' <a href="./index.php'.$query_string.'">folder</a> containing new Bookmark<br>' . "\n";
  100. }
  101. else {
  102. echo '<script language="JavaScript">reloadclose();</script>';
  103. # I know, the following is ugly, but I found no other way to do.
  104. # When creating a bookmark out of the personal toolbar, there is no
  105. # window.opener that can be closed. Thus javascript exits with an error
  106. # without finishing itself (self.close()).
  107. echo '<script language="JavaScript">self.close();</script>';
  108. }
  109. }
  110. require_once (ABSOLUTE_PATH . "footer.php");
  111. ?>