diff --git a/linkcategories.php b/linkcategories.php
new file mode 100644
index 0000000000..95ba031c22
--- /dev/null
+++ b/linkcategories.php
@@ -0,0 +1,208 @@
+$cat_name".mysql_error());
+
+ header("Location: linkcategories.php");
+ break;
+ } // end addcat
+ case "Delete":
+ {
+ $standalone = 1;
+ include_once("./b2header.php");
+ include_once("./links.php");
+
+ $cat_id = $HTTP_POST_VARS["cat_id"];
+ $cat_name=get_linkcatname($cat_id);
+ $cat_name=addslashes($cat_name);
+
+ if ($cat_id=="1")
+ die("Can't delete the $cat_name link category: this is the default one");
+
+ if ($user_level < $minadminlevel)
+ die ("Cheatin' uh ?");
+
+ $query="DELETE FROM $tablelinkcategories WHERE cat_id=\"$cat_id\"";
+ $result=mysql_query($query) or die("Couldn't delete link category $cat_name".mysql_error());
+
+ $query="UPDATE $tablelinks SET link_category=1 WHERE link_category='$cat_id'";
+ $result=mysql_query($query) or die("Couldn't reset category on links where category was $cat_name");
+
+ header("Location: linkcategories.php");
+ break;
+ } // end delete
+ case "Edit":
+ {
+ include_once ("./b2header.php");
+ include_once("./links.php");
+ $cat_id = $HTTP_POST_VARS["cat_id"];
+ $cat_name=get_linkcatname($cat_id);
+ $cat_name=addslashes($cat_name);
+ $auto_toggle=get_autotoggle($cat_id);
+?>
+
+
+
Old name:
+
+
+
+
+$cat_name: ".$query.mysql_error());
+
+ header("Location: linkcategories.php");
+ break;
+ } // end edit
+ default:
+ {
+ $standalone=0;
+ include_once ("./b2header.php");
+ if ($user_level < $minadminlevel) {
+ die("You have no right to edit the link categories for this blog. Ask for a promotion to your blog admin :)");
+ }
+?>
+
+
+
+
Link Categories:
+
+
+
+
+
+
+
+
+ Add a link category:
+
+
+
+
+
+
+
+
+
+ Note:
+ Deleting a link category does not delete links from that category. It will
+ just set them back to the default category .
+
+
+
+
+
+
+
diff --git a/linkmanager.php b/linkmanager.php
new file mode 100644
index 0000000000..c41827814d
--- /dev/null
+++ b/linkmanager.php
@@ -0,0 +1,549 @@
+ $v) {
+ if (is_array($v)) {
+ $array[$k] = add_magic_quotes($v);
+ } else {
+ $array[$k] = addslashes($v);
+ }
+ }
+ return $array;
+}
+
+if (!get_magic_quotes_gpc()) {
+ $HTTP_GET_VARS = add_magic_quotes($HTTP_GET_VARS);
+ $HTTP_POST_VARS = add_magic_quotes($HTTP_POST_VARS);
+ $HTTP_COOKIE_VARS = add_magic_quotes($HTTP_COOKIE_VARS);
+}
+
+$b2varstoreset = array('action','standalone','cat_id', 'linkurl', 'name', 'image',
+ 'description', 'visible', 'target', 'category', 'link_id',
+ 'submit', 'order_by', 'links_show_cat_id', 'rating');
+for ($i=0; $iAsk for a promotion to your blog admin :)");
+ }
+
+ $sql = "SELECT link_url, link_name, link_image, link_target, link_description, link_visible, link_category AS cat_id, link_rating " .
+ " FROM $tablelinks " .
+ " WHERE link_id = $link_id";
+
+ $result = mysql_query($sql) or die("Couldn't execute query.".mysql_error());
+ if ($row = mysql_fetch_object($result)) {
+ $link_url = $row->link_url;
+ $link_name = stripslashes($row->link_name);
+ $link_image = $row->link_image;
+ $link_target = $row->link_target;
+ $link_category = $row->cat_id;
+ $link_description = stripslashes($row->link_description);
+ $link_visible = $row->link_visible;
+ $link_rating = $row->link_rating;
+ }
+
+?>
+
+
+
+
+
+Ask for a promotion to your blog admin :)");
+ }
+
+ switch ($order_by)
+ {
+ case 'order_name': $sqlorderby = 'name'; break;
+ case 'order_url': $sqlorderby = 'url'; break;
+ case 'order_desc': $sqlorderby = 'description'; break;
+ case 'order_owner': $sqlorderby = 'owner'; break;
+ case 'order_rating': $sqlorderby = 'rating'; break;
+ case 'order_id': //fall through
+ default: $sqlorderby = 'id'; break;
+ }
+
+ if ($action != "popup") {
+?>
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/links.bookmark.txt b/links.bookmark.txt
new file mode 100644
index 0000000000..33629669e7
--- /dev/null
+++ b/links.bookmark.txt
@@ -0,0 +1,4 @@
+Change the server name in this javascript and add to your browser toolbar. This currently only works in Mozilla.
+
+javascript:void(linkmanpopup=window.open('http://test.zed1.com/b2/linkmanager.php?action=popup&linkurl='+escape(location.href)+'&name='+escape(document.title),'Link Manager','scrollbars=yes,width=750,height=550,left=15,top=15,status=yes,resizable=yes'));linkmanpopup.focus();window.focus();linkmanpopup.focus();
+
diff --git a/links.config.php b/links.config.php
new file mode 100644
index 0000000000..e1ab18673e
--- /dev/null
+++ b/links.config.php
@@ -0,0 +1,83 @@
+
diff --git a/links.html b/links.html
new file mode 100644
index 0000000000..790cfdc829
--- /dev/null
+++ b/links.html
@@ -0,0 +1,255 @@
+
+
+ Links
+
+
+
+
Links
+
+
+// $Id$
+//
+// Links
+// Copyright (C) 2002 Mike Little -- mike@zed1.com
+//
+// This is an add-on to b2 weblog / news publishing tool
+// b2 is copyright (c)2001, 2002 by Michel Valdrighi - m@tidakada.com
+//
+// **********************************************************************
+// Copyright (C) 2002 Mike Little
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+// Mike Little (mike@zed1.com)
+// *****************************************************************
+
+
+
Links is an add-on to b2 weblogging software.
+
+
It plugs in to the admin screens.
+
It adds to menu commands: Link Categories and Link Manager
+
It allows you to define multiple categories under which to store your links.
+
You can then define links with a url, name, optional image, href target and category.
+
You can then list your links in your template with a simple function call.
+
You can list them by category id or category name
+
You can specify text or html to be output before and after each link.
+
You can specifiy the sort order of the links displayed.
+
You can add a 'star' rating to your links.
+
There is special category type, auto-toggle which will allow only on link in the
+ category to display at once.
+
Each link is owned by the user who created it. You can only edit or delete links
+ created by you or someone with a lower b2 administration level than you.
Execute the SQL from the file links.sql. This will create the two tables
+ and add a default category and an example link. Alternatively, upload
+ the file links.install.php to your B2 installation directory and load
+ it into your browser.
+
Edit the b2-include/b2menutop.txt file to add in the two new commands.
+ 5 linkcategories.php Link Categories
+ 5 linkmanager.php Link Manager
+ Note: there should be a tab character after the 5 and after the filename.
+
Add the files linkcategories.php, linkmanager.php, links.config.php, and links.php into your b2 install directory.
+
Edit links.config.php to your requirements. There are comments in the file to explain each configuration variable.
+
Login and click on the Link Categories menu command. Here you can edit link categories.
+
Name is the name of the category.
+
Auto-toggle: if you check this box, this category will only allow one link in this category to be visible at a time.
+ If you edit an existing link or create a new one with the visible flag set on; all the other links in this category will be
+ turned off. You can use this feature for a current mood category or current CD.
+
+
+
Click on the Link Manager command to edit links:
+
The url is the href part of the link tag. This is optional; if you wanted to, for example, use it for mood icons.
+
The name will either be the linked word(s) or the alt and title tag for the image.
+
The image will be used as the src for an image tag. Use either an absolute address or one relative to your template.
+
The target is the target of the link. _blank to open in a new browser window, and _top to open in the same window.
+
The category is the category under which to store this link.
+
The description is the description to be used as the title tag for the link (if it exists) and the text displayed after the link when no image is defined.
+
The visibilty flag is used to turn off an individual link. Perhaps when a site goes down temporarily but you don't want to delete your link. See also auto-toggle categories above.
+
The rating is used to display a number, a number of characters, an image, or a number of images after the link.
+
+
+
+
+
In your template include_once("links.php")
+
You can then <?php echo get_linkcatname(1); ?> or any category id.
+ This will output the name of the category (perhaps for a heading)
+
Then <?php get_links(1); ?> to output all the links in category 1.
+ You can also specify text to be output before and after the link, and the order
+ of the links.
+
You can also <?php get_linksbyname('General'); ?> To output all the links in the category called General.
+
Other functions are get_linksbyname_withrating(), get_links_withrating(), and get_linkcatname().
+
See the comments above each function for full details.
+
+
+
+
Bookmarklet: I have a partially working bookmarklet to add to your browser toolbar.
+
Clicking on this while viewing a site will cause the 'add a link' form to
+ pop up in a new window with the site url and title pre-filled.
+
This currently *only* works if you are already logged in to b2. The
+ bookmarklet *only* works in Mozilla.
+
+
+
+
Updating:
+
+
If you are updating from a pre 0.5 version, you will need to execute the sql in links.update-0.5.sql
+
If you are updating from a pre 0.7 version, you will need to execute the sql in links.update-0.7.sql
+
If you are updating from a pre 1.0 version, you will need to execute the sql in links.update-1.0.sql
+
+
+
+
+
Changes
+
+
1.2 - Name change and minor bug fixes.
+
1.1 - Added sample 'list all links' file.
+ Added links_popup_script() function.
+ Added the ability to return links in random order.
+ Bug fixes: Can't create new category without auto-toggle.
+ links.install.php does not compile with smartquotes turned on.
+ Added missing title to linkcategories.php
+
1.0 - Added mysql_connect() call to install script.
+ Added separate configuration file.
+ Added cookie to remember 'show' filter when managing links.
+ Add ratings system.
+ Added auto-toggle category flag.
+ Added descending to sort order.
+
0.9.1 - Added links.install.php DB installation script
+
0.9 - URLs are optional. Delete asks for confirmation. You can now turn
+ off the descriptions, even if you have no image or images turned off.
+
0.8 - Added orderby parameter to output functions.
+ In the link manager you can now sort your list of links.
+ User level visibility now controlled by a variable at the top of
+ linkmanager.php
+
0.7 - Added link owners. Added truncation of long urls.
+
0.6 - Added ability to not show images. Partially functional
+ 'add link' bookmarklet. Documented template functions.
+
0.5 - Added description and visibility flag.
+
0.4 - Add stripslashes() calls in a couple of places.
+
0.3 - fixed bad mysql call
+
0.2 - fixed bad sql script
+
0.1 - initial release
+
+
+
+
+
+
Screen shots
+
+
When you've added the lines to b2menutop.txt your menu should look like this:
+
+
+
Clicking on the 'Link Categories' menu will give you a page like this:
+
+
+
Editing an existing category looks like this:
+
+
+
Clicking on the 'Link Manager' menu will give you a page like this:
+
+
You can choose display all your links or just a single category of links. You can also select the sort order.
+
+
Adding a new link is at the bottom of the link manager page:
+
+
+
Editing an individual link looks like this:
+
+
+
In your template you can output the link categories as seperate lists like this:
+You can see the description as title attribute for both text links and image
+links. You can also see the description output after the text links.
+
+
+
+
+
+
Thats about it really. This is reasonably stable software, however is has not been extensively tested. Use with caution.
\n";
+}
+?>
+
+
diff --git a/links.php b/links.php
new file mode 100644
index 0000000000..17cedf1528
--- /dev/null
+++ b/links.php
@@ -0,0 +1,326 @@
+') - the html to output after the link
+ ** between (default ' ') - the html to output between the link/image
+ ** and it's description. Not used if no image or show_images == true
+ ** show_images (default true) - whether to show images (if defined).
+ ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
+ ** 'url', 'description' or 'rating'. Or maybe owner. If you start the
+ ** name with an underscore the order will be reversed.
+ ** You can also specify 'rand' as the order which will return links in a
+ ** random order.
+ ** show_description (default true) - whether to show the description if
+ ** show_images=false/not defined
+ ** show_rating (default false) - show rating stars/chars
+ ** limit (default -1) - Limit to X entries. If not specified, all entries
+ ** are shown.
+ ** show_updated (default 0) - whether to show last updated timestamp
+ */
+function get_linksbyname($cat_name = "noname", $before = '', $after = ' ',
+ $between = " ", $show_images = true, $orderby = 'id',
+ $show_description = true, $show_rating = false,
+ $limit = -1, $show_updated = 0) {
+ global $tablelinkcategories;
+ $cat_id = -1;
+ $sql = "SELECT cat_id FROM $tablelinkcategories WHERE cat_name='$cat_name'";
+ $result = mysql_query($sql)
+ or die("Oops, couldn't query the db for categories."
+ . $sql . mysql_error());
+ if ($row = mysql_fetch_object($result)) {
+ $cat_id = $row->cat_id;
+ }
+ get_links($cat_id, $before, $after, $between, $show_images, $orderby,
+ $show_description, $show_rating, $limit, $show_updated);
+}
+
+
+/** function get_links()
+ ** Gets the links associated with category n.
+ ** Parameters:
+ ** category (default -1) - The category to use. If no category supplied
+ ** uses all
+ ** before (default '') - the html to output before the link
+ ** after (default ' ') - the html to output after the link
+ ** between (default ' ') - the html to output between the link/image
+ ** and it's description. Not used if no image or show_images == true
+ ** show_images (default true) - whether to show images (if defined).
+ ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
+ ** 'url', 'description', or 'rating'. Or maybe owner. If you start the
+ ** name with an underscore the order will be reversed.
+ ** You can also specify 'rand' as the order which will return links in a
+ ** random order.
+ ** show_description (default true) - whether to show the description if
+ ** show_images=false/not defined .
+ ** show_rating (default false) - show rating stars/chars
+ ** limit (default -1) - Limit to X entries. If not specified, all entries
+ ** are shown.
+ ** show_updated (default 0) - whether to show last updated timestamp
+ */
+function get_links($category = -1, $before = '', $after = ' ',
+ $between = " ", $show_images = true, $orderby = 'id',
+ $show_description = true, $show_rating = false,
+ $limit = -1, $show_updated = 0) {
+
+ global $tablelinks, $links_rating_type, $links_rating_char,
+ $links_rating_image, $links_rating_ignore_zero,
+ $links_rating_single_image;
+
+ $direction = ' ASC';
+ $category_query = "";
+ if ($category != -1) {
+ $category_query = " AND link_category = $category ";
+ }
+ if ($show_updated) {
+ $get_updated = ", DATE_FORMAT(link_updated, '%d/%m/%Y %h:%i') AS link_updated ";
+ }
+ dbconnect();
+ $sql = "SELECT link_url, link_name, link_image, link_target, " .
+ " link_description, link_rating $get_updated " .
+ " FROM $tablelinks " .
+ " WHERE link_visible = 'Y' " .
+ $category_query;
+ if ($orderby == '')
+ $orderby = 'id';
+ if (substr($orderby,0,1) == '_') {
+ $direction = ' DESC';
+ $orderby = substr($orderby,1);
+ }
+ if (strcasecmp('rand',$orderby) == 0) {
+ $orderby = 'rand()';
+ } else {
+ $orderby = " link_" . $orderby;
+ }
+ $sql .= ' ORDER BY ' . $orderby;
+ $sql .= $direction;
+ /* The next 2 lines implement LIMIT TO processing */
+ if ($limit != -1)
+ $sql .= " LIMIT $limit";
+
+ $result = mysql_query($sql)
+ or die("Couldn't execute query. " . $sql . mysql_error());
+ while ($row = mysql_fetch_object($result)) {
+ echo($before);
+ $the_link = '#';
+ if (($row->link_url != null) || ($row->link_url != '')) {
+ $the_link = $row->link_url;
+ }
+ echo("link_description) .
+ "\" target=\"$row->link_target\">");
+ if (($row->link_image != null) && $show_images) {
+ echo("link_image\" border=\"0\" alt=\"" .
+ stripslashes($row->link_name) . "\" title=\"" .
+ stripslashes($row->link_description) . "\" />");
+ } else {
+ echo(stripslashes($row->link_name));
+ }
+ if ((($row->link_image != null) && $show_images) || !$show_description) {
+ echo("");
+ } else {
+ echo("$between" . stripslashes($row->link_description));
+ }
+
+ if ($show_updated) {
+ if (substr($row->link_updated,0,2) != '00') {
+ echo("$between " . $row->link_updated);
+ }
+ }
+ // now do the rating
+ if ($show_rating) {
+ echo($between);
+ if ($links_rating_type == 'number') {
+ if (($row->link_rating != 0) || ($links_rating_ignore_zero != 1)) {
+ echo(" $row->link_rating\n");
+ }
+ } else if ($links_rating_type == 'char') {
+ for ($r = $row->link_rating; $r > 0; $r--) {
+ echo($links_rating_char);
+ }
+ } else if ($links_rating_type == 'image') {
+ if ($links_rating_single_image) {
+ for ($r = $row->link_rating; $r > 0; $r--) {
+ echo(' '."\n");
+ }
+ } else {
+ if (($row->link_rating != 0) || ($links_rating_ignore_zero != 1)) {
+ echo(' '."\n");
+ }
+ }
+ } // end if image
+ } // end if show_rating
+ echo("$after\n");
+ } // end while
+}
+
+/** function get_linksbyname_withrating()
+ ** Gets the links associated with category 'cat_name' and display rating stars/chars.
+ ** Parameters:
+ ** cat_name (default 'noname') - The category name to use. If no
+ ** match is found uses all
+ ** before (default '') - the html to output before the link
+ ** after (default ' ') - the html to output after the link
+ ** between (default ' ') - the html to output between the link/image
+ ** and it's description. Not used if no image or show_images == true
+ ** show_images (default true) - whether to show images (if defined).
+ ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
+ ** 'url' or 'description'. Or maybe owner. If you start the
+ ** name with an underscore the order will be reversed.
+ ** You can also specify 'rand' as the order which will return links in a
+ ** random order.
+ ** show_description (default true) - whether to show the description if
+ ** show_images=false/not defined
+ ** limit (default -1) - Limit to X entries. If not specified, all entries
+ ** are shown.
+ ** show_updated (default 0) - whether to show last updated timestamp
+ */
+function get_linksbyname_withrating($cat_name = "noname", $before = '',
+ $after = ' ', $between = " ",
+ $show_images = true, $orderby = 'id',
+ $show_description = true, $limit = -1, $show_updated = 0) {
+
+ get_linksbyname($cat_name, $before, $after, $between, $show_images,
+ $orderby, $show_description, true, $limit, $show_updated);
+}
+
+/** function get_links_withrating()
+ ** Gets the links associated with category n and display rating stars/chars.
+ ** Parameters:
+ ** category (default -1) - The category to use. If no category supplied
+ ** uses all
+ ** before (default '') - the html to output before the link
+ ** after (default ' ') - the html to output after the link
+ ** between (default ' ') - the html to output between the link/image
+ ** and it's description. Not used if no image or show_images == true
+ ** show_images (default true) - whether to show images (if defined).
+ ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
+ ** 'url' or 'description'. Or maybe owner. If you start the
+ ** name with an underscore the order will be reversed.
+ ** You can also specify 'rand' as the order which will return links in a
+ ** random order.
+ ** show_description (default true) - whether to show the description if
+ ** show_images=false/not defined .
+ ** limit (default -1) - Limit to X entries. If not specified, all entries
+ ** are shown.
+ ** show_updated (default 0) - whether to show last updated timestamp
+ */
+function get_links_withrating($category = -1, $before = '', $after = ' ',
+ $between = " ", $show_images = true,
+ $orderby = 'id', $show_description = true,
+ $limit = -1, $show_updated = 0) {
+
+ get_links($category, $before, $after, $between, $show_images, $orderby,
+ $show_description, true, $limit, $show_updated);
+}
+
+/** function get_linkcatname()
+ ** Gets the name of category n.
+ ** Parameters: id (default 0) - The category to get. If no category supplied
+ ** uses 0
+ */
+function get_linkcatname($id = 0) {
+ global $tablelinkcategories;
+ $cat_name = "noname";
+ $sql = "SELECT cat_name FROM $tablelinkcategories WHERE cat_id=$id";
+ $result = mysql_query($sql)
+ or die("Couldn't query the db for categories:". $sql. mysql_error());
+ if ($row = mysql_fetch_object($result)) {
+ $cat_name = stripslashes($row->cat_name);
+ }
+ return $cat_name;
+}
+
+/** function get_get_autotoggle()
+ ** Gets the auto_toggle setting of category n.
+ ** Parameters: id (default 0) - The category to get. If no category supplied
+ ** uses 0
+ */
+function get_autotoggle($id = 0) {
+ global $tablelinkcategories;
+ $auto_toggle = "N";
+ $sql = "SELECT auto_toggle FROM $tablelinkcategories WHERE cat_id=$id";
+ $result = mysql_query($sql)
+ or die("Couldn't query the db for categories:". $sql.
+ mysql_error());
+ if ($row = mysql_fetch_object($result)) {
+ $auto_toggle = $row->auto_toggle;
+ }
+ return $auto_toggle;
+}
+
+/** function links_popup_script()
+ ** This function contributed by Fullo -- http://sprite.csr.unibo.it/fullo/
+ ** Show the link to the links popup and the number of links
+ ** Parameters:
+ ** text (default Links) - the text of the link
+ ** width (default 400) - the width of the popup window
+ ** height (default 400) - the height of the popup window
+ ** file (default linkspopup.php) - the page to open in the popup window
+ ** count (default true) - the number of links in the db
+ */
+function links_popup_script($text = 'Links', $width=400, $height=400,
+ $file='links.all.php', $count = true) {
+ global $tablelinks;
+ if ($count == true) {
+ $sql = "SELECT count(*) FROM $tablelinks";
+ $result = mysql_query($sql)
+ or die("Couldn't query the db for categories:". $sql .
+ mysql_error());
+
+ if ($row = mysql_fetch_row($result)) {
+ $counts = $row[0];
+ }
+ }
+
+ $javascript = "";
+ $javascript .= $text;
+
+ if ($count == true) {
+ $javascript .= " ($counts)";
+ }
+
+ $javascript .="\n\n";
+ echo $javascript;
+}
+
+?>
diff --git a/links.readme.txt b/links.readme.txt
new file mode 100644
index 0000000000..8b7ac5bf75
--- /dev/null
+++ b/links.readme.txt
@@ -0,0 +1,190 @@
+// $Id$
+//
+// Links
+// Copyright (C) 2002 Mike Little -- mike@zed1.com
+//
+// This is an add-on to b2 weblog / news publishing tool
+// b2 is copyright (c)2001, 2002 by Michel Valdrighi - m@tidakada.com
+//
+// **********************************************************************
+// Copyright (C) 2002 Mike Little
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+// Mike Little (mike@zed1.com)
+// *****************************************************************
+
+Links is an add-on to b2 weblogging software.
+ * It plugs in to the admin screens.
+ * It adds to menu commands: Link Categories and Link Manager
+ * It allows you to define multiple categories under which to store your links.
+ * You can then define links with a url, name, optional image, href
+ target and category.
+ * You can then list your links in your template with a simple function call.
+ * You can list them by category id or category name
+ * You can specify text or html to be output before and after each link.
+ * You can specifiy the sort order of the links displayed.
+ * You can add a 'star' rating to your links.
+ * There is special category type, auto-toggle which will allow only on link in
+ the category to display at once.
+ * Each link is owned by the user who created it. You can only edit or delete
+ links created by you or someone with a lower b2 administration level than you.
+
+
+Files:
+links.readme.txt - this file
+links.sql - sql to create the necessary database tables
+links.update-0.5.sql - sql to update the pre 0.5 tables
+links.update-0.7.sql - sql to update the pre 0.7 tables
+links.update-1.0.sql - sql to update the pre 1.0 tables
+linkcategories.php - admin plugin to manage link categories
+linkmanager.php - admin plugin to manage links
+links.php - template functions
+links.install.php - alternate installation method
+links.config.php - configuration file
+links.bookmark.txt - mozilla bookmarklet
+links.all.php - Sample page to show all links
+links-images\rating-0.gif - ratings images
+links-images\rating-1.gif
+links-images\rating-2.gif
+links-images\rating-3.gif
+links-images\rating-4.gif
+links-images\rating-5.gif
+links-images\rating-6.gif
+links-images\rating-7.gif
+links-images\rating-8.gif
+links-images\rating-9.gif
+links-images\star.gif
+license.txt - GNU General Public License Version 2
+
+You can download it from http://zed1.com/links/links-1.1.zip or http://zed1.com/links/links-1.1.tar.gz
+
+There is an html version of this readme file at
+http://zed1.com/links/links.html with screenshots and more detailed info.
+
+Installation:
+
+1. Execute the SQL from the file links.sql. This will create the two
+ tables and add a default category and an example link. Alternatively, upload
+ the file links.install.php to your B2 installation directory and
+ load it into your browser.
+
+2. Edit the b2-include/b2menutop.txt file to add in the two new commands.
+
+5 linkcategories.php Link Categories
+5 linkmanager.php Link Manager
+
+ Note: there should be a tab character after the 5 and after the filename.
+
+3. Add the files linkcategories.php, linkmanager.php, links.config.php,
+ and links.php into your b2 install directory.
+
+4. Edit links.config.php to your requirements. There are comments in the file
+ to explain each configuration variable.
+
+5. Login and click on the Link Categories menu command. Here you can
+ create or edit link categories.
+ - Name is the name of the category.
+ - Auto-toggle: if you check this box, this category will only allow one link
+ in this category to be visible at a time. If you edit an existing link or
+ create a new one with the visible flag set on; all the other links in this
+ category will be turned off. You can use this feature for a current mood
+ category or current CD.
+
+6. Click on the Link Manager command to edit links:
+ - The url is the href part of the link tag. This is optional; if you wanted
+ to, for example, use it for mood icons.
+ - The name will either be the linked word(s) or the alt and title tag for
+ the image.
+ - Image will be used as the src for an image tag. Use either an absolute
+ address or one relative to your template.
+ - Target is the target of the link. _blank to open in a new browser window,
+ and _top to open in the same window.
+ - Category is the category under which to store this link.
+ - Description is the description to be used as the title tag for the link
+ (if it exists) and the text displayed after the link when no image is
+ defined.
+ - Visible flag is used to turn off an individual link. Perhaps when a site
+ goes down temporarily but you don't want to delete your link. See also
+ auto-toggle categories above.
+ - Rating is used to display a number, a number of characters, an image, or a
+ number of images after the link.
+
+7. In your template include_once("links.php")
+ - You can then or any category id. This will
+ output the name of the category (perhaps for a heading)
+ - Then to output all the links in category 1. You can
+ also specify text to be output before and after the link, and the order of
+ the links.
+ - You can also to output all the links in
+ the category called General.
+ - Other functions are get_linksbyname_withrating(), get_links_withrating(),
+ and get_linkcatname().
+ - See the comments above each function for full details.
+
+9. Bookmarklet: I have a partially working bookmarklet to add to your browser
+ toolbar.
+ - Clicking on this while viewing a site will cause the 'add a link' form to
+ pop up in a new window with the site url and title pre-filled.
+ - This currently *only* works if you are already logged in to b2. The
+ bookmarklet *only* works in Mozilla.
+
+Updating:
+
+1. If you are updating from a pre 0.5 version, you will need to execute the sql
+ in links.update-0.5.sql
+2. If you are updating from a pre 0.7 version, you will need to execute the sql
+ in links.update-0.7.sql
+3. If you are updating from a pre 1.0 version, you will need to execute the sql
+ in links.update-1.0.sql
+
+Changes:
+
+ 1.1 - Added sample 'list all links' file.
+ Added links_popup_script() function.
+ Added the ability to return links in random order.
+ Bug fixes: Can't create new category without auto-toggle.
+ links.install.php does not compile with smartquotes turned on.
+ Added missing title to linkcategories.php
+ 1.0 - Added mysql_connect() call to install script.
+ Added separate configuration file.
+ Added cookie to remember 'show' filter when managing links.
+ Add ratings system.
+ Added auto-toggle category flag.
+ Added descending to sort order.
+ 0.9.1 - Added links.install.php DB installation script
+ 0.9 - URLs are optional. Delete asks for confirmation. You can now turn
+ off the descriptions, even if you have no image or images turned off.
+ 0.8 - Added orderby parameter to output functions.
+ In the link manager you can now sort your list of links.
+ User level visibility now controlled by a variable at the top of
+ linkmanager.php
+ 0.7 - Added link owners. Added truncation of long urls.
+ 0.6 - Added ability to not show images. Partially functional
+ 'add link' bookmarklet. Documented template functions.
+ 0.5 - Added description and visibility flag.
+ 0.4 - Add stripslashes() calls in a couple of places.
+ 0.3 - fixed bad mysql call
+ 0.2 - fixed bad sql script
+ 0.1 - initial release
+
+
+Thats about it really. This is reasonably stable software, however is has not
+been extensively tested. Use with caution.
+
+
+--
+Mike Little
+mike@zed1.com
diff --git a/links.sql b/links.sql
new file mode 100644
index 0000000000..8fb559f83e
--- /dev/null
+++ b/links.sql
@@ -0,0 +1,58 @@
+-- --------------------------------------------------------
+-- // $Id$
+-- //
+-- // Links
+-- // Copyright (C) 2002 Mike Little -- mike@zed1.com
+-- //
+-- // This is an add-on to b2 weblog / news publishing tool
+-- // b2 is copyright (c)2001, 2002 by Michel Valdrighi - m@tidakada.com
+-- //
+-- // **********************************************************************
+-- // Copyright (C) 2002 Mike Little
+-- //
+-- // This program is free software; you can redistribute it and/or modify
+-- // it under the terms of the GNU General Public License as published by
+-- // the Free Software Foundation; either version 2 of the License, or
+-- // (at your option) any later version.
+-- //
+-- // This program is distributed in the hope that it will be useful, but
+-- // WITHOUT ANY WARRANTY; without even the implied warranty of
+-- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+-- // General Public License for more details.
+-- //
+-- // You should have received a copy of the GNU General Public License
+-- // along with this program; if not, write to the Free Software
+-- // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+-- //
+-- // Mike Little (mike@zed1.com)
+-- // *****************************************************************
+
+-- DROP TABLE IF EXISTS b2links;
+CREATE TABLE b2links (
+ link_id int(11) NOT NULL auto_increment,
+ link_url varchar(255) NOT NULL default '',
+ link_name varchar(255) NOT NULL default '',
+ link_image varchar(255) NOT NULL default '',
+ link_target varchar(25) NOT NULL default '',
+ link_category int(11) NOT NULL default 0,
+ link_description varchar(255) NOT NULL default '',
+ link_visible enum ('Y','N') NOT NULL default 'Y',
+ link_owner int NOT NULL DEFAULT '1',
+ link_rating int NOT NULL DEFAULT '0',
+ link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (link_id)
+) TYPE=MyISAM;
+
+
+-- DROP TABLE IF EXISTS linkcategories;
+CREATE TABLE linkcategories (
+ cat_id int(11) NOT NULL auto_increment,
+ cat_name tinytext NOT NULL,
+ auto_toggle enum ('Y','N') NOT NULL default 'N',
+ PRIMARY KEY (cat_id)
+) TYPE=MyISAM;
+
+INSERT INTO linkcategories (cat_id, cat_name) VALUES (1, 'General');
+
+INSERT INTO b2links (link_id, link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner)
+VALUES (1, 'http://www.cafelog.com/', 'Cafelog', '', '_blank', 1, 'Cafelog', 'Y', 1);
diff --git a/links.update-0.5.sql b/links.update-0.5.sql
new file mode 100644
index 0000000000..00788ad937
--- /dev/null
+++ b/links.update-0.5.sql
@@ -0,0 +1,34 @@
+-- --------------------------------------------------------
+-- // $Id$
+-- //
+-- // B2Links
+-- // Copyright (C) 2002 Mike Little -- mike@zed1.com
+-- //
+-- // This is an add-on to b2 weblog / news publishing tool
+-- // b2 is copyright (c)2001, 2002 by Michel Valdrighi - m@tidakada.com
+-- //
+-- // **********************************************************************
+-- // Copyright (C) 2002 Mike Little
+-- //
+-- // This program is free software; you can redistribute it and/or modify
+-- // it under the terms of the GNU General Public License as published by
+-- // the Free Software Foundation; either version 2 of the License, or
+-- // (at your option) any later version.
+-- //
+-- // This program is distributed in the hope that it will be useful, but
+-- // WITHOUT ANY WARRANTY; without even the implied warranty of
+-- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+-- // General Public License for more details.
+-- //
+-- // You should have received a copy of the GNU General Public License
+-- // along with this program; if not, write to the Free Software
+-- // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+-- //
+-- // Mike Little (mike@zed1.com)
+-- // *****************************************************************
+
+alter table b2links modify column link_url varchar(255) NOT NULL default '';
+-- this will have silently changed all the other chars to varchars!
+alter table b2links add column link_description varchar(255) NOT NULL default '';
+alter table b2links add column link_visible enum ('Y','N') NOT NULL default 'Y';
+update b2links set link_description = link_name;
diff --git a/links.update-0.7.sql b/links.update-0.7.sql
new file mode 100644
index 0000000000..e2910532bd
--- /dev/null
+++ b/links.update-0.7.sql
@@ -0,0 +1,32 @@
+-- --------------------------------------------------------
+-- // $Id$
+-- //
+-- // B2Links
+-- // Copyright (C) 2002 Mike Little -- mike@zed1.com
+-- //
+-- // This is an add-on to b2 weblog / news publishing tool
+-- // b2 is copyright (c)2001, 2002 by Michel Valdrighi - m@tidakada.com
+-- //
+-- // **********************************************************************
+-- // Copyright (C) 2002 Mike Little
+-- //
+-- // This program is free software; you can redistribute it and/or modify
+-- // it under the terms of the GNU General Public License as published by
+-- // the Free Software Foundation; either version 2 of the License, or
+-- // (at your option) any later version.
+-- //
+-- // This program is distributed in the hope that it will be useful, but
+-- // WITHOUT ANY WARRANTY; without even the implied warranty of
+-- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+-- // General Public License for more details.
+-- //
+-- // You should have received a copy of the GNU General Public License
+-- // along with this program; if not, write to the Free Software
+-- // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+-- //
+-- // Mike Little (mike@zed1.com)
+-- // *****************************************************************
+
+ALTER TABLE b2links ADD COLUMN link_owner INT NOT NULL DEFAULT '1';
+-- set link owner to admin (id 1)
+UPDATE b2links SET link_owner = 1;
diff --git a/links.update-1.0.sql b/links.update-1.0.sql
new file mode 100644
index 0000000000..312d75d1ff
--- /dev/null
+++ b/links.update-1.0.sql
@@ -0,0 +1,33 @@
+-- --------------------------------------------------------
+-- // $Id$
+-- //
+-- // B2Links
+-- // Copyright (C) 2002 Mike Little -- mike@zed1.com
+-- //
+-- // This is an add-on to b2 weblog / news publishing tool
+-- // b2 is copyright (c)2001, 2002 by Michel Valdrighi - m@tidakada.com
+-- //
+-- // **********************************************************************
+-- // Copyright (C) 2002 Mike Little
+-- //
+-- // This program is free software; you can redistribute it and/or modify
+-- // it under the terms of the GNU General Public License as published by
+-- // the Free Software Foundation; either version 2 of the License, or
+-- // (at your option) any later version.
+-- //
+-- // This program is distributed in the hope that it will be useful, but
+-- // WITHOUT ANY WARRANTY; without even the implied warranty of
+-- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+-- // General Public License for more details.
+-- //
+-- // You should have received a copy of the GNU General Public License
+-- // along with this program; if not, write to the Free Software
+-- // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+-- //
+-- // Mike Little (mike@zed1.com)
+-- // *****************************************************************
+
+ALTER TABLE b2links ADD COLUMN link_rating INT NOT NULL DEFAULT '0';
+
+ALTER TABLE b2linkcategories ADD COLUMN auto_toggle enum ('Y','N') NOT NULL default 'N';
+
diff --git a/links.update-1.3.sql b/links.update-1.3.sql
new file mode 100644
index 0000000000..bc9c175554
--- /dev/null
+++ b/links.update-1.3.sql
@@ -0,0 +1,33 @@
+-- --------------------------------------------------------
+-- // $Id$
+-- //
+-- // Links
+-- // Copyright (C) 2002 Mike Little -- mike@zed1.com
+-- //
+-- // This is an add-on to b2 weblog / news publishing tool
+-- // b2 is copyright (c)2001, 2002 by Michel Valdrighi - m@tidakada.com
+-- //
+-- // **********************************************************************
+-- // Copyright (C) 2002 Mike Little
+-- //
+-- // This program is free software; you can redistribute it and/or modify
+-- // it under the terms of the GNU General Public License as published by
+-- // the Free Software Foundation; either version 2 of the License, or
+-- // (at your option) any later version.
+-- //
+-- // This program is distributed in the hope that it will be useful, but
+-- // WITHOUT ANY WARRANTY; without even the implied warranty of
+-- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+-- // General Public License for more details.
+-- //
+-- // You should have received a copy of the GNU General Public License
+-- // along with this program; if not, write to the Free Software
+-- // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+-- //
+-- // Mike Little (mike@zed1.com)
+-- // *****************************************************************
+
+ALTER TABLE b2links ADD COLUMN link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
+
+
+
diff --git a/links.weblogs.com.php b/links.weblogs.com.php
new file mode 100644
index 0000000000..3d90fff4d3
--- /dev/null
+++ b/links.weblogs.com.php
@@ -0,0 +1,148 @@
+
+include_once('links.config.php');
+require_once('./b2config.php');
+require_once($b2inc.'/b2functions.php');
+
+// globals to hold state
+$inside_weblog = false;
+$updated_timestamp = 0;
+$all_links = array();
+
+/**
+ ** preload_links()
+ ** Pre-load the visible, non-blank, links into an associative array $all_links
+ ** key is url, value is array of link_id and update_time
+ ** Note: update time is initialised to 0. That way we only have to update (in
+ ** the db) the ones which have been updated.
+ **/
+function preload_links() {
+ global $tablelinks, $all_links;
+ dbconnect();
+ $sql = "SELECT link_id, link_url FROM $tablelinks WHERE link_visible = 'Y' AND link_url <> ''";
+ $result = mysql_query($sql)
+ or die("Couldn't execute query. " . $sql . mysql_error());
+ while ($row = mysql_fetch_object($result)) {
+ $all_links[$row->link_url] = array($row->link_id,0);
+ }
+}
+
+/**
+ ** update_links()
+ ** Update in the db the links which have been updated ($all_links[url][1] != 0)
+ **/
+function update_links() {
+ global $tablelinks, $all_links;
+ dbconnect();
+
+ reset($all_links);
+ while (list($id, $val) = each($all_links)) {
+ if ($val[1]) {
+ $sql = "UPDATE $tablelinks SET link_updated = '$val[1]' WHERE link_id = $val[0] ";
+ //echo("executing: $sql\n");
+ if (mysql_query($sql) == false) {
+ //ignore update errors! no data loss
+ //echo("Couldn't execute query. " . $sql . mysql_error());
+ }
+ }
+ } // end while
+}
+
+/**
+ ** get_weblogs_updatedfile()
+ ** Retrieves and caches a copy of the weblogs.com changed blogs xml file.
+ ** If the file exists check it's age, get new copy if old.
+ ** If a new or updated file has been written return true (needs processing)
+ ** otherwise return false (nothing to do)
+ **/
+function get_weblogs_updatedfile() {
+ global $weblogs_cache_file, $weblogs_xml_url, $weblogs_cacheminutes;
+ $update = false;
+
+ if (file_exists($weblogs_cache_file)) {
+ // is it old?
+ $modtime = filemtime($weblogs_cache_file);
+ if ((time() - $modtime) > ($weblogs_cacheminutes * 60)) {
+ $update = true;
+ }
+ } else { // doesn't exist
+ $update = true;
+ }
+
+ if ($update) {
+ // get a new copy
+ $contents = implode('', file($weblogs_xml_url)); // file_get_contents not available < 4.3
+ $cachefp = fopen($weblogs_cache_file, "w");
+ fwrite($cachefp, $contents);
+ fclose($cachefp);
+ }
+ return $update;
+}
+
+/**
+ ** startElement()
+ ** Callback function. Called at the start of a new xml tag.
+ **/
+function startElement($parser, $tagName, $attrs) {
+ global $inside_weblog, $updated_timestamp, $all_links;
+ if ($tagName == 'WEBLOGUPDATES') {
+ //convert 'updated' into php date variable
+ $updated_timestamp = strtotime($attrs['UPDATED']);
+ //echo('got timestamp of ' . gmdate('F j, Y, H:i:s', $updated_timestamp) . "\n");
+ } else if ($tagName == 'WEBLOG') {
+ // is this url in our links?
+ if (isset($all_links[$attrs['URL']])) {
+ $all_links[$attrs['URL']][1] = gmdate('YmdHis', $updated_timestamp - $attrs['WHEN']);
+ //echo('set link id ' . $all_links[$attrs['URL']][0] . ' to date ' . $all_links[$attrs['URL']][1] . "\n");
+ }
+ }
+}
+
+/**
+ ** endElement()
+ ** Callback function. Called at the end of an xml tag.
+ **/
+function endElement($parser, $tagName) {
+ // nothing to do.
+}
+
+
+// get/update the cache file.
+// true return means new copy
+if (get_weblogs_updatedfile()) {
+
+ // pre-load the links
+ preload_links();
+
+ // Create an XML parser
+ $xml_parser = xml_parser_create();
+
+ // Set the functions to handle opening and closing tags
+ xml_set_element_handler($xml_parser, "startElement", "endElement");
+
+ // Open the XML file for reading
+ $fp = fopen($weblogs_cache_file, "r")
+ or die("Error reading XML data.");
+
+ //echo('
');
+ // Read the XML file 4KB at a time
+ while ($data = fread($fp, 4096)) {
+ // Parse each 4KB chunk with the XML parser created above
+ xml_parse($xml_parser, $data, feof($fp))
+ // Handle errors in parsing
+ or die(sprintf("XML error: %s at line %d",
+ xml_error_string(xml_get_error_code($xml_parser)),
+ xml_get_current_line_number($xml_parser)));
+ }
+
+ // Close the XML file
+ fclose($fp);
+
+ // Free up memory used by the XML parser
+ xml_parser_free($xml_parser);
+
+ // now update the db with latest times
+ update_links();
+
+ //echo('