PHP Bookmark Script Free For Handling Bookmarks

Apr 13, 2012, by admin

Bookmarker is a WWW-based application for handling bookmarks. It allows multiple users to list, search, maintain, and create bookmarks. It is written in PHP using PHPLIB, which allows support for multiple databases. bookmarker includes functions to store URLs and send URLs via email directly from your browser (quik-mark, mail-this-link) using Javascript functions that link directly to the application. Netscape bookmark import is included as well as public/private settings to allow some/all bookmarks to be shared among users.

  1. <?
  2. //####################################################################
  3. // Active PHP Bookmarks – lbstone.com/apb/
  4. //
  5. // Filename: apb_group_class.php
  6. // Author:   L. Brandon Stone (lbstone.com)
  7. //           Nathanial P. Hendler (retards.org)
  8. //
  9. // 2001-09-05 00:18     Starting on version 1.0 (NPH) (LBS)
  10. //
  11. // This class is pretty easy, except for the constructor.  Look at
  12. // the comments for apb_bookmark() in apb_common.php to get an idea of what
  13. // is going on.
  14. //
  15. //####################################################################
  16. class Group {
  17. var $id;
  18. var $parent_id;
  19. var $title;
  20. var $description;
  21. var $user_id;
  22. var $private;
  23. var $creation_date;
  24. function Group ($constructor) {
  25. if (is_array($constructor)) {
  26. // $constructor is an associate array
  27. // created by a db query, that contains
  28. // the bookmarks info so we’ll use that
  29. // to populate the variables
  30. $this->id            = $constructor[‘group_id’];
  31. $this->parent_id     = $constructor[‘group_parent_id’];
  32. $this->title         = $constructor[‘group_title’];
  33. $this->description   = $constructor[‘group_description’];
  34. $this->user_id       = $constructor[‘user_id’];
  35. $this->private       = $constructor[‘group_private’];
  36. $this->creation_date = $constructor[‘group_creation_date’];
  37. } else {
  38. // $constructor is a bookmark id
  39. $this->load_vars($constructor);
  40. }
  41. }
  42. function id() {
  43. return $this->id;
  44. }
  45. function parent_id () {
  46. if (! $this->parent_id) {
  47. $this->load_vars($this->parent_id);
  48. }
  49. return $this->parent_id;
  50. }
  51. function title () {
  52. if (! $this->title) {
  53. $this->load_vars($this->id);
  54. }
  55. return $this->title;
  56. }
  57. function description () {
  58. if (! $this->description) {
  59. $this->load_vars($this->id);
  60. }
  61. return $this->description;
  62. }
  63. function creation_date () {
  64. if (! $this->creation_date) {
  65. $this->load_vars($this->id);
  66. }
  67. return $this->creation_date;
  68. }
  69. function private () {
  70. if (! $this->private) {
  71. $this->load_vars($this->id);
  72. }
  73. return $this->private;
  74. }
  75. function user_id () {
  76. if (! $this->user_id) {
  77. $this->load_vars($this->id);
  78. }
  79. return $this->user_id;
  80. }
  81. function link ($color = “”) {
  82. global $APB_SETTINGS;
  83. $this->title() || $this->load_vars($this->id);
  84. // Start creating the link…
  85. $link = “<a href='”;
  86. // If we’re in “edit mode” display a different link than the normal one.
  87. if ($APB_SETTINGS[‘auth_user_id’] AND $APB_SETTINGS[‘edit_mode’]) {
  88. $link .= $APB_SETTINGS[‘apb_url’].”edit_group.php?id=”.$this->id;
  89. } else {
  90. $link .= $APB_SETTINGS[‘view_group_path’] . “?id=” . $this->id;
  91. }
  92. // Finish with some user-friendly additions to the link…
  93. $link .= “‘ “.
  94. “onmouseover=’window.status=””. str_replace (“&quot;”, “&quot;”, $this->get_group_path()) . “”; “.
  95. “return true;’ onmouseout=’window.status=””; return true;’ “.
  96. “title='”. $this->get_group_path() .”‘”.
  97. “>”;
  98. if ($color) { $link .= “<font color='”.$color.”‘>”; }
  99. $link .= $this->title;
  100. if ($color) { $link .= “</font>”; }
  101. $link .= “</a>”;
  102. return $link;
  103. }
  104. function load_vars ($id) {
  105. global $APB_SETTINGS;
  106. if (!$id) { return 0; }
  107. $query = “SELECT * FROM apb_groups WHERE group_id = $id”;
  108. $result = mysql_db_query($APB_SETTINGS[‘apb_database’], $query);
  109. if ($result) {
  110. $row = mysql_fetch_assoc($result);
  111. $this->id            = $row[‘group_id’];
  112. $this->parent_id     = $row[‘group_parent_id’];
  113. $this->title         = htmlentities($row[‘group_title’], ENT_QUOTES);
  114. $this->description   = htmlentities($row[‘group_description’], ENT_QUOTES);
  115. $this->user_id       = $row[‘user_id’];
  116. $this->private       = $row[‘group_private’];
  117. $this->creation_date = $row[‘group_creation_date’];
  118. } else {
  119. error(“Creating Group $id: “.mysql_error());
  120. error(“SQL: $query”);
  121. }
  122. }
  123. function get_group_path () {
  124. global $APB_SETTINGS;
  125. $string   = $this->title();
  126. $group_id = $this->parent_id();
  127. while ($group_id > 0) {
  128. $query = “
  129. SELECT g.group_id #, g.group_parent_id, g.group_title
  130. FROM apb_groups g
  131. WHERE g.group_id = $group_id
  132. AND g.user_id = ” . $APB_SETTINGS[‘user_id’] . “
  133. “;
  134. #print “<p><pre>$query</pre><p>nn”;
  135. $result = mysql_db_query($APB_SETTINGS[‘apb_database’], $query);
  136. $row = mysql_fetch_assoc($result);
  137. $g = apb_group($row[‘group_id’]);
  138. $string = $g->title() . ” :: ” . $string;
  139. $group_id = $g->parent_id();
  140. }
  141. return $string;
  142. }
  143. function print_group_path () {
  144. global $APB_SETTINGS;
  145. $string   = “<b>”.$this->link().”</b>”;
  146. $group_id = $this->parent_id();
  147. while ($group_id > 0) {
  148. $query = “
  149. SELECT g.group_id #, g.group_parent_id, g.group_title
  150. FROM apb_groups g
  151. WHERE g.group_id = $group_id
  152. AND g.user_id = ” . $APB_SETTINGS[‘user_id’] . “
  153. “;
  154. #print “<p><pre>$query</pre><p>nn”;
  155. $result = mysql_db_query($APB_SETTINGS[‘apb_database’], $query);
  156. $row = mysql_fetch_assoc($result);
  157. $g = apb_group($row[‘group_id’]);
  158. $string = $g->link() . ” :: ” . $string;
  159. $group_id = $g->parent_id();
  160. }
  161. print “<a href='” . $APB_SETTINGS[‘home_url’] . “‘>Home</a> :: ” . $string;
  162. }
  163. function print_group_children () {
  164. global $APB_SETTINGS;
  165. $group_id = $this->id();
  166. $query = “
  167. SELECT g.group_id
  168. FROM apb_groups g
  169. WHERE g.group_parent_id = $group_id
  170. AND g.user_id = ” . $APB_SETTINGS[‘user_id’] . “
  171. ORDER BY g.group_title
  172. “;
  173. $result = mysql_db_query($APB_SETTINGS[‘apb_database’], $query);
  174. echo “<ul>”;
  175. while ($row = mysql_fetch_assoc($result)) {
  176. $g = apb_group($row[‘group_id’]);
  177. $c = $g->number_of_bookmarks() + $g->number_of_child_groups();
  178. print “<li>” . $g->link() . ” (” . $c . “)n”;
  179. }
  180. echo “</ul>”;
  181. }
  182. function number_of_child_groups () {
  183. if (! $this->number_of_child_groups) {
  184. global $APB_SETTINGS;
  185. $group_id = $this->id();
  186. $query = “
  187. SELECT COUNT(g.group_id) as total
  188. FROM apb_groups g
  189. WHERE g.group_parent_id = $group_id
  190. AND g.user_id = ” . $APB_SETTINGS[‘user_id’] . “
  191. “;
  192. $result = mysql_db_query($APB_SETTINGS[‘apb_database’], $query);
  193. $row = mysql_fetch_assoc($result);
  194. $this->number_of_child_groups = $row[‘total’];
  195. }
  196. return $this->number_of_child_groups;
  197. }
  198. function number_of_bookmarks() {
  199. global $APB_SETTINGS;
  200. if ($APB_SETTINGS[‘auth_user_id’]) { $private_sql = “”; }
  201. else { $private_sql = “AND b.bookmark_private != 1”; }
  202. // Added the bookmark deleted bit, so that it returns a real number. [LBS 20020211]
  203. $query = “
  204. SELECT count(*) as total
  205. FROM apb_bookmarks b
  206. WHERE b.group_id = ” . $this->id() . “
  207. AND b.bookmark_deleted != 1
  208. $private_sql
  209. AND b.user_id = ” . $APB_SETTINGS[‘user_id’] . “
  210. “;
  211. #print “<p><pre>$query</pre><p>nn”;
  212. $result = mysql_db_query($APB_SETTINGS[‘apb_database’], $query);
  213. $row = mysql_fetch_assoc($result);
  214. return $row[‘total’];
  215. }
  216. function print_group_bookmarks () {
  217. global $APB_SETTINGS;
  218. if (!$APB_SETTINGS[‘auth_user_id’]) {
  219. $private_sql = “AND b.bookmark_private = 0”;
  220. }
  221. $query = “
  222. SELECT b.bookmark_id
  223. FROM apb_bookmarks b
  224. WHERE b.group_id = ” . $this->id() . “
  225. AND b.user_id = ” . $APB_SETTINGS[‘user_id’] . “
  226. ” . $private_sql . “
  227. AND b.bookmark_deleted != 1
  228. ORDER BY b.bookmark_title
  229. “;
  230. #print “<p><pre>$query</pre><p>nn”;
  231. $result = mysql_db_query($APB_SETTINGS[‘apb_database’], $query);
  232. echo “<ul>”;
  233. while ($row = mysql_fetch_assoc($result)) {
  234. $b = apb_bookmark($row[‘bookmark_id’]);
  235. print “<li>” . $b->link();
  236. if ($b->description()) { print ” – ” . $b->description(); }
  237. print “<br>n”;
  238. }
  239. echo “</ul>”;
  240. }
  241. function return_child_groups () {
  242. global $APB_SETTINGS;
  243. if (! $this->child_groups_loop) {
  244. $this->group_list = array();
  245. array_push($this->group_list, $this->id);
  246. $this->child_groups_loop($this->id);
  247. }
  248. return $this->group_list;
  249. }
  250. function child_groups_loop ($id) {
  251. global $APB_SETTINGS;
  252. $query = “
  253. SELECT g.group_id, g.group_parent_id
  254. FROM apb_groups g
  255. WHERE g.user_id = ” . $APB_SETTINGS[‘user_id’] . “
  256. AND g.group_parent_id = ” . $id . “
  257. “;
  258. #print “<p><pre>$query</pre><p>nn”;
  259. $result = mysql_db_query($APB_SETTINGS[‘apb_database’], $query);
  260. while ($row = mysql_fetch_assoc($result)) {
  261. array_push($this->group_list, $row[‘group_id’]);
  262. $this->child_groups_loop($row[‘group_id’]);
  263. }
  264. }
  265. }
  266. ?>
  267. &nbsp;