/gui/tools/webmail/plugins/bookmarks/bookmark_edit.php

https://github.com/BenBE/ispCP · PHP · 105 lines · 93 code · 11 blank · 1 comment · 39 complexity · c47c128869437970a91ca0029d2a68ce MD5 · raw file

  1. <?php
  2. define('SM_PATH','../../');
  3. include_once('bookmarks_data.php');
  4. include_once('functions.php');
  5. if (file_exists(SM_PATH . 'include/validate.php'))
  6. include_once(SM_PATH . 'include/validate.php');
  7. else if (file_exists(SM_PATH . 'src/validate.php'))
  8. include_once(SM_PATH . 'src/validate.php');
  9. include_once(SM_PATH . 'functions/page_header.php');
  10. sqgetGlobalVar('passval', $passval, SQ_GET);
  11. if (!isset($passval)) sqgetGlobalVar('passval', $passval, SQ_POST);
  12. sqgetGlobalVar('confirmed', $confirmed, SQ_GET);
  13. if (!isset($confirmed)) sqgetGlobalVar('confirmed', $confirmed, SQ_POST);
  14. sqgetGlobalVar('title', $title, SQ_GET);
  15. if (!isset($title)) sqgetGlobalVar('title', $title, SQ_POST);
  16. sqgetGlobalVar('url', $url, SQ_GET);
  17. if (!isset($url)) sqgetGlobalVar('url', $url, SQ_POST);
  18. $passval = urldecode($passval);
  19. $bookmarksdata = $_SESSION['bookmarksdata'];
  20. if ($confirmed == '') {
  21. foreach ($bookmarksdata as $bookfoo) {
  22. if ($bookfoo["index"] == $passval) {
  23. $url = $bookfoo["url"];
  24. $title = $bookfoo["title"];
  25. $folder = $bookfoo["folder"];
  26. }
  27. }
  28. }
  29. if (isset($url)) {
  30. if (!isset($confirmed)) {
  31. global $bookmarksdata;
  32. displayPageHeader($color, 'None');
  33. echo '<br><br>';
  34. echo '<form method="POST" action="bookmark_edit.php">';
  35. echo '<input type="hidden" name="passval" value="' . $passval . '">';
  36. echo '<input type="hidden" name="confirmed" value="yes">';
  37. echo 'URL:<br><input type="text" name="url" value="' . $url . '">';
  38. echo '<br><br>';
  39. echo 'Title: (leave blank to fetch from URL)<br>';
  40. echo '<input type="text" name="title" value="' . $title . '">';
  41. echo '<br><br>';
  42. echo '<input type="submit" value="Save">';
  43. echo '</form>';
  44. echo '</body></html>';
  45. } else {
  46. if ((substr(strtolower($url),0,7) != 'http://') && (substr(strtolower($url),0,6) != 'ftp://') && (substr(strtolower($url),0,8) != 'https://') && (substr(strtolower($url),0,9) != 'telnet://') && (substr(strtolower($url),0,7) != 'nntp://')) {
  47. $url = 'http://' . $url;
  48. }
  49. if (($title == "") && ((substr(strtolower($url),0,7) == 'http://') || (substr(strtolower($url),0,8) != 'https://'))){
  50. $retstr = "";
  51. $targeturl = $url;
  52. $explode = explode('://',$targeturl);
  53. $prefix = $explode[0] . '://';
  54. $targeturl = $explode[1];
  55. $explode = explode('?',$targeturl);
  56. $targeturl = $explode[0];
  57. $querystring = $explode[1];
  58. $lastslash = strrchr($targeturl,'/');
  59. if ($lastslash != false) {
  60. if (strrchr(substr($targeturl,$lastslash),'.') == false) {
  61. $targeturl = $targeturl . '/';
  62. }
  63. }
  64. $sk = fopen($prefix . $targeturl . "?" . $querystring,"r");
  65. if ($sk != false) {
  66. while(!feof($sk)){
  67. $resp=fgets($sk,80);
  68. $retstr.=$resp;
  69. }
  70. fclose($sk);
  71. $sString = $retstr;
  72. $sString = str_replace('<title>','<TITLE>',$sString);
  73. $sString = str_replace('</title>','</TITLE>',$sString);
  74. $explode = explode("<TITLE>",$sString);
  75. $sString = $explode[1];
  76. $explode = explode("</TITLE>",$sString);
  77. $sString = $explode[0];
  78. /* @author ispCP PHP5.3 Compatibility Change */
  79. $title = preg_replace("/(\r\n|\n|\r)/", "", $sString);
  80. }
  81. }
  82. if ($title == "") {
  83. $title = $url;
  84. }
  85. $bookmarksdata[$passval]["title"] = $title;
  86. $bookmarksdata[$passval]["url"] = $url;
  87. writebookmarksdata();
  88. readbookmarksdata();
  89. header('Location: bookmarks.php?passval=' . urlencode($folder));
  90. }
  91. } else {
  92. echo "Nothing to edit";
  93. }
  94. ?>