Added in a version of b2links with update from

weblogs.com.


git-svn-id: http://svn.automattic.com/wordpress/trunk@21 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
mikelittle 2003-05-12 22:33:47 +00:00
parent 064a0eb79e
commit b7e64e6d6c
16 changed files with 2143 additions and 0 deletions

View File

@ -103,6 +103,13 @@
<li><a href="b2register.php">register</a></li>
</ul>
</li>
<?php include_once('links.php') ?>
<?php include_once('links.weblogs.com.php') ?>
<li>Links:
<ul>
<?php get_links(-1, '<li>', '</li>', '', 0, '_updated', 0, 0, -1, 1 )?>
</ul>
</li>
<li>Misc:
<ul>
<li><a href="b2rss.php"><img src="b2-img/xml.gif" alt="view this weblog as RSS !" width="36" height="14" border="0" /></a></li>

208
linkcategories.php Normal file
View File

@ -0,0 +1,208 @@
<?php
// $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)
// *****************************************************************
include_once('links.config.php');
include_once('links.php');
$title = "Link Categories";
$b2varstoreset = array('action','standalone','cat', 'auto_toggle');
for ($i=0; $i<count($b2varstoreset); $i += 1) {
$b2var = $b2varstoreset[$i];
if (!isset($$b2var)) {
if (empty($HTTP_POST_VARS["$b2var"])) {
if (empty($HTTP_GET_VARS["$b2var"])) {
$$b2var = '';
} else {
$$b2var = $HTTP_GET_VARS["$b2var"];
}
} else {
$$b2var = $HTTP_POST_VARS["$b2var"];
}
}
}
switch ($action) {
case "addcat":
{
$standalone = 1;
include_once("./b2header.php");
if ($user_level < $minadminlevel)
die ("Cheatin' uh ?");
$cat_name=addslashes($HTTP_POST_VARS["cat_name"]);
$auto_toggle = $HTTP_POST_VARS["auto_toggle"];
if ($auto_toggle != 'Y') {
$auto_toggle = 'N';
}
$query="INSERT INTO $tablelinkcategories (cat_id,cat_name, auto_toggle) VALUES ('0', '$cat_name', '$auto_toggle')";
$result=mysql_query($query) or die("Couldn't add category <b>$cat_name</b>".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 <b>$cat_name</b> 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 <b>$cat_name</b>".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 <b>$cat_name</b>");
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);
?>
<?php echo $blankline; ?>
<?php echo $tabletop; ?>
<p><b>Old</b> name: <?php echo $cat_name ?></p>
<p>
<form name="editcat" method="post">
<b>New</b> name:<br />
<input type="hidden" name="action" value="editedcat" />
<input type="hidden" name="cat_id" value="<?php echo $HTTP_POST_VARS["cat_id"] ?>" />
<input type="text" name="cat_name" value="<?php echo $cat_name ?>" /><br />
<input type="checkbox" name="auto_toggle" value="Y" <?php echo $auto_toggle = "Y" ? '"checked"' : ''; ?>/> auto-toggle?<br />
<input type="submit" name="submit" value="Edit it !" class="search" />
</form>
</p>
<?php echo $tablebottom; ?>
<?php
break;
} // end Edit
case "editedcat":
{
$standalone = 1;
include_once("./b2header.php");
if ($user_level < $minadminlevel)
die ("Cheatin' uh ?");
$cat_name=addslashes($HTTP_POST_VARS["cat_name"]);
$cat_id=$HTTP_POST_VARS["cat_id"];
$auto_toggle=$HTTP_POST_VARS["auto_toggle"];
$query="UPDATE $tablelinkcategories SET cat_name='$cat_name', auto_toggle='$auto_toggle' WHERE cat_id=$cat_id";
$result=mysql_query($query) or die("Couldn't edit link category <b>$cat_name</b>: ".$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.<br>Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a> :)");
}
?>
<?php echo $blankline ?>
<?php echo $tabletop ?>
<table width="" cellpadding="5" cellspacing="0" border="0">
<tr><td><b>Link Categories:</b></td></tr>
<tr>
<td>
<form name="cats" method="post">
<b>Edit</b> a link category:<br />
<?php
$query = "SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id";
$result = mysql_query($query) or die("Couldn't execute query. ".mysql_error());
echo " <select name=\"cat_id\">\n";
while($row = mysql_fetch_object($result)) {
echo " <option value=\"".$row->cat_id."\"";
if ($row->cat_id == $cat_id)
echo ' selected';
echo ">".$row->cat_id.": ".$row->cat_name;
if ($row->auto_toggle == 'Y')
echo ' (auto toggle)';
echo "</option>\n";
}
echo " </select>\n";
?>
<br /><br />
<input type="submit" name="action" value="Delete" class="search" />
<input type="submit" name="action" value="Edit" class="search" />
</form>
</td>
<td>
<?php echo $blankline ?>
</td>
<td>
<b>Add</b> a link category:<br />
<form name="addcat" method="post">
<input type="hidden" name="action" value="addcat" />
<input type="text" name="cat_name" />&nbsp;<input type="checkbox" name="auto_toggle" value="Y" /> auto-toggle?<br /><br />
<input type="submit" name="submit" value="Add it !" class="search" />
</form>
</td>
</tr>
</table>
<?php echo $tablebottom ?>
<?php echo $blankline ?>
<?php echo $tabletop ?>
<b>Note:</b><br />
Deleting a link category does not delete links from that category.<br />It will
just set them back to the default category <b><?php echo get_linkcatname(1) ?></b>.
<?php echo $tablebottom ?>
<?php echo $blankline ?>
<?php
break;
} // end default
} // end case
?>
</table>
<?php include($b2inc."/b2footer.php") ?>

549
linkmanager.php Normal file
View File

@ -0,0 +1,549 @@
<?php
// $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)
// *****************************************************************
include_once('links.config.php');
include_once("./links.php");
$title = "Manage Links";
function add_magic_quotes($array) {
foreach ($array as $k => $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; $i<count($b2varstoreset); $i += 1) {
$b2var = $b2varstoreset[$i];
if (!isset($$b2var)) {
if (empty($HTTP_POST_VARS["$b2var"])) {
if (empty($HTTP_GET_VARS["$b2var"])) {
$$b2var = '';
} else {
$$b2var = $HTTP_GET_VARS["$b2var"];
}
} else {
$$b2var = $HTTP_POST_VARS["$b2var"];
}
}
}
$links_show_cat_id = $HTTP_COOKIE_VARS["links_show_cat_id"];
//error_log("start, links_show_cat_id=$links_show_cat_id");
switch ($action) {
case "Add":
{
$standalone = 1;
include_once("./b2header.php");
$link_url = $HTTP_POST_VARS["linkurl"];
$link_name = $HTTP_POST_VARS["name"];
$link_image = $HTTP_POST_VARS["image"];
$link_target = $HTTP_POST_VARS["target"];
$link_category = $HTTP_POST_VARS["category"];
$link_description = $HTTP_POST_VARS["description"];
$link_visible = $HTTP_POST_VARS["visible"];
$link_rating = $HTTP_POST_VARS["rating"];
$auto_toggle = get_autotoggle($link_category);
if ($user_level < $minadminlevel)
die ("Cheatin' uh ?");
// if we are in an auto toggle category and this one is visible then we
// need to make the others invisible before we add this new one.
if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
$sql = "UPDATE $tablelinks set link_visible = 'N' WHERE link_category = $link_category";
$sql_result = mysql_query($sql) or die("Couldn't execute query."."sql=[$sql]". mysql_error());
}
$sql = "INSERT INTO $tablelinks (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating) " .
" VALUES('" . addslashes($link_url) . "','"
. addslashes($link_name) . "', '"
. addslashes($link_image) . "', '$link_target', $link_category, '"
. addslashes($link_description) . "', '$link_visible', $user_ID, $link_rating)";
$sql_result = mysql_query($sql) or die("Couldn't execute query."."sql=[$sql]". mysql_error());
header("Location: linkmanager.php");
break;
} // end Add
case "editlink":
{
if (isset($submit) && ($submit == "Save")) {
if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
$cat_id = $links_show_cat_id;
if (!isset($cat_id) || ($cat_id == '')) {
if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
$cat_id = 'All';
}
$links_show_cat_id = $cat_id;
$standalone = 1;
include_once("./b2header.php");
$link_id = $HTTP_POST_VARS["link_id"];
$link_url = $HTTP_POST_VARS["linkurl"];
$link_name = $HTTP_POST_VARS["name"];
$link_image = $HTTP_POST_VARS["image"];
$link_target = $HTTP_POST_VARS["target"];
$link_category = $HTTP_POST_VARS["category"];
$link_description = $HTTP_POST_VARS["description"];
$link_visible = $HTTP_POST_VARS["visible"];
$link_rating = $HTTP_POST_VARS["rating"];
$auto_toggle = get_autotoggle($link_category);
if ($user_level < $minadminlevel)
die ("Cheatin' uh ?");
// if we are in an auto toggle category and this one is visible then we
// need to make the others invisible before we update this one.
if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
$sql = "UPDATE $tablelinks set link_visible = 'N' WHERE link_category = $link_category";
$sql_result = mysql_query($sql) or die("Couldn't execute query."."sql=[$sql]". mysql_error());
}
$sql = "UPDATE $tablelinks SET link_url='" . addslashes($link_url) . "',\n " .
" link_name='" . addslashes($link_name) . "',\n link_image='" . addslashes($link_image) . "',\n " .
" link_target='$link_target',\n link_category=$link_category,\n " .
" link_visible='$link_visible',\n link_description='" . addslashes($link_description) . "',\n " .
" link_rating=$link_rating\n" .
" WHERE link_id=$link_id";
//error_log($sql);
$sql_result = mysql_query($sql) or die("Couldn't execute query."."sql=[$sql]". mysql_error());
} // end if save
setcookie('links_show_cat_id', $links_show_cat_id, time()+600);
header("Location: linkmanager.php");
break;
} // end Save
case "Delete":
{
$standalone = 1;
include_once("./b2header.php");
$link_id = $HTTP_POST_VARS["link_id"];
if ($user_level < $minadminlevel)
die ("Cheatin' uh ?");
$sql = "DELETE FROM $tablelinks WHERE link_id = '$link_id'";
$sql_result = mysql_query($sql) or die("Couldn't execute query.".mysql_error());
if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
$cat_id = $links_show_cat_id;
if (!isset($cat_id) || ($cat_id == '')) {
if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
$cat_id = 'All';
}
$links_show_cat_id = $cat_id;
setcookie("links_show_cat_id", $links_show_cat_id, time()+600);
header("Location: linkmanager.php");
break;
} // end Delete
case "linkedit":
{
$standalone=0;
include_once ("./b2header.php");
if ($user_level < $minadminlevel) {
die("You have no right to edit the links for this blog.<br>Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a> :)");
}
$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;
}
?>
<?php echo $blankline ?>
<?php echo $tabletop ?>
<table width="95%" cellpadding="5" cellspacing="0" border="0">
<form name="editlink" method="post">
<input type="hidden" name="action" value="editlink" />
<input type="hidden" name="link_id" value="<?php echo $link_id; ?>" />
<input type="hidden" name="order_by" value="<?php echo $order_by ?>" />
<input type="hidden" name="cat_id" value="<?php echo $cat_id ?>" />
<tr><td colspan="2"><b>Edit</b> a link:</td></tr>
<tr height="20">
<td height="20" align="right">URL:</td>
<td><input type="text" name="linkurl" size="80" value="<?php echo $link_url; ?>"></td>
</tr>
<tr height="20">
<td height="20" align="right">Display Name/Alt text:</td>
<td><input type="text" name="name" size="80" value="<?php echo $link_name; ?>"></td>
</tr>
<tr height="20">
<td height="20" align="right">Image:</td>
<td><input type="text" name="image" size="80" value="<?php echo $link_image; ?>"></td>
</tr>
<tr height="20">
<td height="20" align="right">Description:</td>
<td><input type="text" name="description" size="80" value="<?php echo $link_description; ?>"></td>
</tr>
<tr height="20">
<td height="20" align="right">Rating:</td>
<td>
<select name="rating" size="1">
<?php
for ($r = 0; $r < 10; $r++) {
echo(' <option value="'.$r.'" ');
if ($link_rating == $r)
echo('selected');
echo('>'.$r.'</option>');
}
?>
</select>&nbsp;(Leave at 0 for no rating.)
</td>
</tr>
<tr height="20">
<td height="20" align="right">Target:</td>
<td><input type="radio" name="target" <?php if ($link_target == '_blank') echo "checked"; ?> value="_blank">_blank&nbsp;<input type="radio" name="target" <?php if ($link_target == '_top') echo "checked"; ?> value="_top">_top</td>
</tr>
<tr height="20">
<td height="20" align="right">Visible:</td>
<td><input type="radio" name="visible" <?php if ($link_visible == 'Y') echo "checked"; ?> value="Y">Y&nbsp;<input type="radio" name="visible" <?php if ($link_visible == 'N') echo "checked"; ?> value="N">N</td>
</tr>
<tr height="20">
<td height="20" align="right">Category:</td>
<td>
<?php
$query = "SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id";
$result = mysql_query($query) or die("Couldn't execute query. ".mysql_error());
echo " <select name=\"category\" size=\"1\">\n";
while($row = mysql_fetch_object($result)) {
echo " <option value=\"".$row->cat_id."\"";
if ($row->cat_id == $link_category)
echo " selected";
echo ">".$row->cat_id.": ".$row->cat_name;
if ($row->auto_toggle == 'Y')
echo ' (auto toggle)';
echo "</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr height="20">
<td colspan="2" align="center">
<input type="submit" name="submit" value="Save" class="search">&nbsp;<input type="submit" name="submit" value="Cancel" class="search"></a>
</td>
</tr>
</table>
<?php
break;
} // end linkedit
case "Show":
{
if (!isset($cat_id) || ($cat_id == '')) {
if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
$cat_id = 'All';
}
$links_show_cat_id = $cat_id;
//break; fall through
} // end Show
case "popup":
{
$link_url = $HTTP_GET_VARS["linkurl"];
$link_name = $HTTP_GET_VARS["name"];
//break; fall through
}
default:
{
if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
$cat_id = $links_show_cat_id;
if (!isset($cat_id) || ($cat_id == '')) {
if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
$cat_id = 'All';
}
$links_show_cat_id = $cat_id;
if (!isset($order_by) || ($order_by == ''))
$order_by = 'order_id';
setcookie('links_show_cat_id', $links_show_cat_id, time()+600);
$standalone=0;
include_once ("./b2header.php");
if ($user_level < $minadminlevel) {
die("You have no right to edit the links for this blog.<br>Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a> :)");
}
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") {
?>
<?php echo $blankline ?>
<?php echo $tabletop ?>
<form name="cats" method="post">
<table width="50%" cellpadding="5" cellspacing="0" border="0">
<tr><td><b>Link Categories:</b></td><td colspan="2"><a href="linkcategories.php">Manage Link Categories</a></td></tr>
<tr>
<td>
<b>Show</b> links in category:<br />
</td>
<td>
<b>Order</b> by:
</td>
</tr>
<tr>
<td>
<?php
$query = "SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id";
$result = mysql_query($query) or die("Couldn't execute query. ".mysql_error());
echo " <select name=\"cat_id\">\n";
echo " <option value=\"All\"";
if ($cat_id == 'All')
echo " selected";
echo "> All</option>\n";
while($row = mysql_fetch_object($result)) {
echo " <option value=\"".$row->cat_id."\"";
if ($row->cat_id == $cat_id)
echo " selected";
echo ">".$row->cat_id.": ".$row->cat_name;
if ($row->auto_toggle == 'Y')
echo ' (auto toggle)';
echo "</option>\n";
}
echo " </select>\n";
?>
</td>
<td>
<select name="order_by">
<option value="order_id" <?php if ($order_by == 'order_id') echo " selected";?>>Id</option>
<option value="order_name" <?php if ($order_by == 'order_name') echo " selected";?>>Name</option>
<option value="order_url" <?php if ($order_by == 'order_url') echo " selected";?>>URL</option>
<option value="order_desc" <?php if ($order_by == 'order_desc') echo " selected";?>>Description</option>
<option value="order_owner" <?php if ($order_by == 'order_owner') echo " selected";?>>Owner</option>
<option value="order_rating" <?php if ($order_by == 'order_rating') echo " selected";?>>Rating</option>
</select>
</td>
<td>
<input type="submit" name="action" value="Show" class="search" />
</td>
</tr>
</table>
</form>
<?php echo $tablebottom ?>
<?php echo $blankline ?>
<?php echo $tabletop ?>
<table width="100%" cellpadding="1" cellspacing="0" border="0">
<form name="links" method="post">
<input type="hidden" name="link_id" value="" />
<input type="hidden" name="action" value="" />
<input type="hidden" name="order_by" value="<?php echo $order_by ?>" />
<input type="hidden" name="cat_id" value="<?php echo $cat_id ?>" />
<tr >
<td style="border-bottom: 1px dotted #9C9A9C;"><b>URL</b></td>
<td style="border-bottom: 1px dotted #9C9A9C;"><b>Name</b></td>
<td style="border-bottom: 1px dotted #9C9A9C;"><b>Img?</b></td>
<td style="border-bottom: 1px dotted #9C9A9C;"><b>Vis?</b></td>
<td style="border-bottom: 1px dotted #9C9A9C;"><b>Category</b></td>
<td style="border-bottom: 1px dotted #9C9A9C;">&nbsp;</td>
<td style="border-bottom: 1px dotted #9C9A9C;">&nbsp;</td>
</tr>
<?php
$sql = "SELECT link_url, link_name, link_image, link_description, link_visible, link_category AS cat_id, cat_name AS category, $tableusers.user_login, link_id, link_rating "
. " FROM $tablelinks LEFT JOIN $tablelinkcategories ON $tablelinks.link_category = $tablelinkcategories.cat_id "
. " LEFT JOIN $tableusers on $tableusers.ID = $tablelinks.link_owner ";
// have we got a where clause?
if (($use_adminlevels) || (isset($cat_id) && ($cat_id != 'All')) ) {
$sql .= " WHERE ";
}
if ($use_adminlevels) {
$sql .= " ($tableusers.user_level <= $user_level"
. " OR $tableusers.ID = $user_ID)";
}
if (isset($cat_id) && ($cat_id != 'All')) {
// have we already started the where clause?
if ($use_adminlevels) {
$sql .= " AND ";
}
$sql .= " link_category = $cat_id ";
}
$sql .= " ORDER BY link_".$sqlorderby;
//echo "$sql";
$result = mysql_query($sql) or die("Couldn't execute query.".mysql_error());
while ($row = mysql_fetch_object($result)) {
$short_url = str_replace('http://', '', $row->link_url);
if (strlen($short_url) > 35) {
$short_url = substr($short_url, 0, 32).'...';
}
echo("<tr>\n");
echo(" <td ><a href=\"".$row->link_url."\">".$short_url."</a></td>\n");
echo(" <td >".stripslashes($row->link_name)."</td>\n");
if ($row->link_image != null) {
echo(" <td align=\"center\">Y</td>\n");
} else {
echo(" <td align=\"center\">N</td>\n");
}
if ($row->link_visible == 'Y') {
echo(" <td align=\"center\">Y</td>\n");
} else {
echo(" <td align=\"center\">N</td>\n");
}
echo(" <td>".stripslashes($row->category)."</td>\n");
echo(" <td><input type=\"submit\" name=\"edit\" onclick=\"forms['links'].link_id.value='$row->link_id'; forms['links'].action.value='linkedit'; \" value=\"Edit\" class=\"search\" /></td>\n");
echo(" <td><input type=\"submit\" name=\"delete\" onclick=\"forms['links'].link_id.value='$row->link_id'; forms['links'].action.value='Delete'; return confirm('You are about to delete this link.\\n \'Cancel\' to stop, \'OK\' to delete.'); \" value=\"Delete\" class=\"search\" /></td>\n");
echo("</tr>\n");
echo("<tr>\n");
echo(" <td style=\"border-bottom: 1px dotted #9C9A9C;\" colspan=\"4\"><b>Desc:</b>&nbsp;".stripslashes($row->link_description)."</td>\n");
echo(" <td style=\"border-bottom: 1px dotted #9C9A9C;\" ><b>Rating:</b>&nbsp;".$row->link_rating."</td>\n");
echo(" <td style=\"border-bottom: 1px dotted #9C9A9C;\" valign=\"top\"><b>Owner:</ab></td>\n");
echo(" <td style=\"border-bottom: 1px dotted #9C9A9C;\" valign=\"top\">".$row->user_login."</td>\n");
echo("</tr>\n");
}
?>
</form>
</table>
<?php
} // end if !popup
?>
<?php echo $tablebottom ?>
<?php echo $blankline ?>
<?php echo $tabletop ?>
<table width="95%" cellpadding="5" cellspacing="0" border="0">
<form name="addlink" method="post">
<input type="hidden" name="action" value="Add" />
<tr><td colspan="2"><b>Add</b> a link:</td></tr>
<tr height="20">
<td height="20" align="right">URL:</td>
<td><input type="text" name="linkurl" size="80" value="<?php echo $link_url; ?>"></td>
</tr>
<tr height="20">
<td height="20" align="right">Display Name/Alt text:</td>
<td><input type="text" name="name" size="80" value="<?php echo $name; ?>"></td>
</tr>
<tr height="20">
<td height="20" align="right">Image:</td>
<td><input type="text" name="image" size="80" value=""></td>
</tr>
<tr height="20">
<td height="20" align="right">Description:</td>
<td><input type="text" name="description" size="80" value=""></td>
</tr>
<tr height="20">
<td height="20" align="right">Rating:</td>
<td>
<select name="rating" size="1">
<?php
for ($r = 0; $r < 10; $r++) {
echo(' <option value="'.$r.'">'.$r.'</option>');
}
?>
</select>&nbsp;(Leave at 0 for no rating.)
</td>
</tr>
<tr height="20">
<td height="20" align="right">Target:</td>
<td><input type="radio" name="target" checked="checked" value="_blank">_blank&nbsp;<input type="radio" name="target" value="_top">_top</td>
</tr>
<tr height="20">
<td height="20" align="right">Visible:</td>
<td><input type="radio" name="visible" checked="checked" value="Y">Y&nbsp;<input type="radio" name="visible" value="N">N</td>
</tr>
<tr height="20">
<td height="20" align="right">Category:</td>
<td>
<?php
$query = "SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id";
$result = mysql_query($query) or die("Couldn't execute query. ".mysql_error());
echo " <select name=\"category\" size=\"1\">\n";
while($row = mysql_fetch_object($result)) {
echo " <option value=\"".$row->cat_id."\"";
if ($row->cat_id == $cat_id)
echo " selected";
echo ">".$row->cat_id.": ".$row->cat_name;
if ($row->auto_toggle == 'Y')
echo ' (auto toggle)';
echo "</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr height="20">
<td colspan="2" align="center">
<input type="submit" name="submit" value="Add" class="search">
</td>
</tr>
</table>
<?php
break;
} // end default
} // end case
?>
<?php echo $tablebottom ?>
<?php include($b2inc."/b2footer.php") ?>

51
links.all.php Normal file
View File

@ -0,0 +1,51 @@
<?php
// This sample file provided by Loyd Goodbar http://www.blackrobes.net/
$blog=1;
include("./blog.header.php");
include_once("./links.php");
$query = "SELECT cat_id, cat_name FROM $tablelinkcategories ORDER BY cat_name";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-control" content="no-cache" />
<title><?php bloginfo('name') ?> :: Links</title>
<link rel="stylesheet" type="text/css" href="/layout2b.css" />
</head>
<body>
<div id="header">
<a href="" title="<?php bloginfo('name'); ?>"><?php bloginfo('name'); ?> :: Links</a>
</div>
<table align="center" columns="1" width="600">
<tr>
<td>
<?php
/* motor for link categories, then show all links therein */
$result = mysql_query($query) or die("Could not retrieve list of link categories.");
while ($row = mysql_fetch_array($result)) {
?>
<h2><?php echo $row['cat_name']; ?></h2>
<p class="storyContent"><?php get_links($row['cat_id'],'','<br />',' ',true,'name',true,false); ?></p>
<?php
}
?>
</td>
</tr>
</table>
<p>
<?php
if (isset($HTTP_GET_VARS['popup'])) {
echo('<a href="javascript:window.close()">Close this window</a>');
} else {
echo('<a href="'.$siteurl.'/'.$blogfilename.'">Return home</a>');
}
?>
</p>
</body>
</html>

4
links.bookmark.txt Normal file
View File

@ -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();

83
links.config.php Normal file
View File

@ -0,0 +1,83 @@
<?php
// $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)
// *****************************************************************
// Various variables to control your Links configuration
// table names in the database
$tablelinks = "b2links";
$tablelinkcategories = "b2linkcategories";
$minadminlevel = 5;
$use_adminlevels = true; // set this to false to have all links visible to
// everyone in the link manager
// Set this to the type rating system you wish to use.
// allowed values are: none, number, char, image
$links_rating_type = 'image';
// if we are set to 'char' which char to use.
$links_rating_char = '*';
// what do we do with a value of zero?
// set this to 1 to output nothing
// set it to 0 to output as normal (number/image)
$links_rating_ignore_zero = 0;
//use the same image (time rating)?
// uses $links_rating_image[0]
$links_rating_single_image = 1;
//or use an individual image for each value?
$links_rating_image[0]='links-images/star.gif';
//$links_rating_image[0]='links-images/rating-0.gif';
$links_rating_image[1]='links-images/rating-1.gif';
$links_rating_image[2]='links-images/rating-2.gif';
$links_rating_image[3]='links-images/rating-3.gif';
$links_rating_image[4]='links-images/rating-4.gif';
$links_rating_image[5]='links-images/rating-5.gif';
$links_rating_image[6]='links-images/rating-6.gif';
$links_rating_image[7]='links-images/rating-7.gif';
$links_rating_image[8]='links-images/rating-8.gif';
$links_rating_image[9]='links-images/rating-9.gif';
//weblogs.com lookup values
// path/to/cachefile needs to be writable by web server
$weblogs_cache_file = 'weblogs.com.changes.cache';
// Which file to grab. changes.xml contains about 3 hours worth of updates and
// is at least 100kb (you don't want to grab this every 10 minutes)
// shortChanges.xml is about 5 minutes worth and around 5kb you don't want to
// grab this less frequently than every five minutes.
//$weblogs_xml_url = 'http://www.weblogs.com/changes.xml';
$weblogs_xml_url = 'http://www.weblogs.com/shortChanges.xml';
$weblogs_cacheminutes = 5; // cache time in minutes (if it is older than this get a new copy)
?>

255
links.html Normal file
View File

@ -0,0 +1,255 @@
<html>
<head>
<title>Links</title>
<link rel="stylesheet" type="text/css" href="http://zed1.com/main.css" />
</head>
<body>
<h1>Links</h1>
<pre class="quote">
// $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)
// *****************************************************************
</pre>
<h2>Links is an add-on to b2 weblogging software.</h2>
<ul>
<li>It plugs in to the admin screens. </li>
<li>It adds to menu commands: Link Categories and Link Manager </li>
<li>It allows you to define multiple categories under which to store your links. </li>
<li>You can then define links with a url, name, optional image, href target and category. </li>
<li>You can then list your links in your template with a simple function call. </li>
<li>You can list them by category id or category name </li>
<li>You can specify text or html to be output before and after each link. </li>
<li>You can specifiy the sort order of the links displayed. </li>
<li>You can add a 'star' rating to your links. </li>
<li>There is special category type, auto-toggle which will allow only on link in the
category to display at once. </li>
<li>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. </li>
</ul>
<p>You can download it from <a href="http://stats.zed1.net/pphlogger/dlcount.php?id=journalized&amp;url=/links/links-1.2.zip">http://zed1.com/links/links-1.2.zip</a><br />
or as a tar ball: <a href="http://stats.zed1.net/pphlogger/dlcount.php?id=journalized&amp;url=/links/links-1.2.tar.gz">http://zed1.com/links/links-1.2.tar.gz</a></p>
<h3>Files:</h3>
<dl>
<dt>links.readme.txt </dt><dd>readme file </dd>
<dt>links.sql </dt><dd>sql to create the necessary database tables </dd>
<dt>links.update-0.5.sql</dt><dd>sql to update the pre 0.5 tables </dd>
<dt>links.update-0.7.sql</dt><dd>sql to update the pre 0.7 tables </dd>
<dt>links.update-1.0.sql</dt><dd>sql to update the pre 1.0 tables </dd>
<dt>linkcategories.php </dt><dd>admin plugin to manage link categories </dd>
<dt>linkmanager.php </dt><dd>admin plugin to manage links </dd>
<dt>links.php </dt><dd>template functions </dd>
<dt>links.install.php </dt><dd>alternate installation method </dd>
<dt>links.config.php </dt><dd>configuration file </dd>
<dt>links.bookmark.txt </dt><dd>mozilla bookmarklet </dd>
<dt>links.all.php </dt><dd>Sample page to show all links </dd>
<dt>links-images\rating-0.gif</dt><dd>ratings image </dd>
<dt>links-images\rating-1.gif</dt><dd>ratings image </dd>
<dt>links-images\rating-2.gif</dt><dd>ratings image </dd>
<dt>links-images\rating-3.gif</dt><dd>ratings image </dd>
<dt>links-images\rating-4.gif</dt><dd>ratings image </dd>
<dt>links-images\rating-5.gif</dt><dd>ratings image </dd>
<dt>links-images\rating-6.gif</dt><dd>ratings image </dd>
<dt>links-images\rating-7.gif</dt><dd>ratings image </dd>
<dt>links-images\rating-8.gif</dt><dd>ratings image </dd>
<dt>links-images\rating-9.gif</dt><dd>ratings image </dd>
<dt>links-images\star.gif </dt><dd>ratings image </dd>
<dt>license.txt </dt><dd>GNU General Public License Version 2 </dd>
</dl>
<h3>Installation:</h3>
<ol>
<li>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.</li>
<li>Edit the b2-include/b2menutop.txt file to add in the two new commands.<br />
5&nbsp; &nbsp; &nbsp; linkcategories.php &nbsp; &nbsp; &nbsp; Link Categories<br />
5&nbsp; &nbsp; &nbsp; linkmanager.php &nbsp; &nbsp; &nbsp; Link Manager<br />
Note: there should be a tab character after the 5 and after the filename.</li>
<li>Add the files linkcategories.php, linkmanager.php, links.config.php, and links.php into your b2 install directory.</li>
<li>Edit links.config.php to your requirements. There are comments in the file to explain each configuration variable.</li>
<li>Login and click on the Link Categories menu command. Here you can edit link categories.<ul>
<li><i>Name</i> is the name of the category.</li>
<li><i>Auto-toggle</i>: 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.</li>
</ul>
</li>
<li>Click on the Link Manager command to edit links:<ul>
<li>The <i>url</i> is the href part of the link tag. This is optional; if you wanted to, for example, use it for mood icons.</li>
<li>The <i>name</i> will either be the linked word(s) or the alt and title tag for the image. </li>
<li>The <i>image</i> will be used as the src for an image tag. Use either an absolute address or one relative to your template.</li>
<li>The <i>target</i> is the target of the link. _blank to open in a new browser window, and _top to open in the same window.</li>
<li>The <i>category</i> is the category under which to store this link.</li>
<li>The <i>description</i> 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.</li>
<li>The <i>visibilty</i> 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.</li>
<li>The <i>rating</i> is used to display a number, a number of characters, an image, or a number of images after the link.</li>
</ul>
</li>
<li>In your template include_once("links.php")<ul>
<li>You can then &lt;?php echo get_linkcatname(1); ?&gt; or any category id.
This will output the name of the category (perhaps for a heading) </li>
<li>Then &lt;?php get_links(1); ?&gt; 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. </li>
<li>You can also &lt;?php get_linksbyname('General'); ?&gt; To output all the links in the category called General. </li>
<li>Other functions are get_linksbyname_withrating(), get_links_withrating(), and get_linkcatname().</li>
<li>See the comments above each function for full details.
</ul>
</li>
<li>Bookmarklet: I have a partially working bookmarklet to add to your browser toolbar.<ul>
<li>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. </li>
<li>This currently *only* works if you are already logged in to b2. The
bookmarklet *only* works in Mozilla.</li>
</li>
</ol>
<h3>Updating:</h3>
<ol>
<li>If you are updating from a pre 0.5 version, you will need to execute the sql in links.update-0.5.sql</li>
<li>If you are updating from a pre 0.7 version, you will need to execute the sql in links.update-0.7.sql</li>
<li>If you are updating from a pre 1.0 version, you will need to execute the sql in links.update-1.0.sql</li>
</ol>
<hr />
<h2>Changes</h2>
<ul>
<li>1.2 - Name change and minor bug fixes.</li>
<li>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</li>
<li>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.</li>
<li>0.9.1 - Added links.install.php DB installation script</li>
<li>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.</li>
<li>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</li>
<li>0.7 - Added link owners. Added truncation of long urls.</li>
<li>0.6 - Added ability to not show images. Partially functional
'add link' bookmarklet. Documented template functions.</li>
<li>0.5 - Added description and visibility flag.</li>
<li>0.4 - Add stripslashes() calls in a couple of places.</li>
<li>0.3 - fixed bad mysql call</li>
<li>0.2 - fixed bad sql script</li>
<li>0.1 - initial release</li>
</ul>
<hr />
<h2>Screen shots</h2>
<ul>
<li>When you've added the lines to b2menutop.txt your menu should look like this:<br />
<img src="menu.png" alt="picture of admin menu"/></li>
<li>Clicking on the 'Link Categories' menu will give you a page like this:<br />
<img src="link-categories.png" alt="picture of editing link categories"/></li>
<li>Editing an existing category looks like this:<br />
<img src="edit-category.png" alt="picture of editing a link"/></li>
<li>Clicking on the 'Link Manager' menu will give you a page like this:<br />
<img src="link-manager.png" alt="picture of managing links"/></li>
<li>You can choose display all your links or just a single category of links. You can also select the sort order.</li>
<li>Adding a new link is at the bottom of the link manager page:<br />
<img src="add-a-link.png" alt="picture of editing a link"/></li>
<li>Editing an individual link looks like this:<br />
<img src="edit-a-link.png" alt="picture of editing a link"/></li>
<li>In your template you can output the link categories as seperate lists like this:<br />
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.<br />
<img src="sidebar.jpg" alt="picture of link output"/>&nbsp;<img src="sidebar2.jpg" alt="picture of link output"/>
&nbsp;<img src="links-with-ratings.png" alt="picture of link output"/></li>
</ul>
<hr />
<p>Thats about it really. This is reasonably stable software, however is has not been extensively tested. Use with caution.</p>
<hr />
<a name="buttons"><h2>Buttons</h2></a>
<p>I've now created some 'Powered by Links' buttons for those of you who wish to show your support.</p>
<p>All you need to do is choose one of the images below, upload it to your own server, and create a link with the following HTML:
</p>
<pre>
&lt;a href="http://zed1.com/links/" title="Links"&gt;
&lt;img src="/path/to/the/image.png" alt="Links" border="0" /&gt;&lt;/a&gt;
</pre>
<table border="1">
<tr>
<td align="center" bgcolor="#00000"><img src="links-black.png" alt="Powered by Links" /></td>
<td align="center" bgcolor="#00000"><img src="links-black-trans.png" alt="Powered by Links" /></td>
</tr>
<tr>
<td>Rendered <br />on a black background</td>
<td>Transparent (Rendered <br />on a black background)</td>
</tr>
<tr>
<td align="center" bgcolor="#ffffff"><img src="links-white.png" alt="Powered by Links" /></td>
<td align="center" bgcolor="#ffffff"><img src="links-white-trans.png" alt="Powered by Links" /></td>
</tr>
<tr>
<td>Rendered <br />on a white background</td>
<td>Transparent (rendered <br />on a white background)</td>
</tr>
</table>
<hr />
<p>--<br />
Mike Little<br />
mike@zed1.com</p>
<!-- PowerPhlogger Code START -->
<script language="JavaScript" type="text/javascript" src="/pphlogger.js"></script>
<noscript><img alt="" src="http://stats.zed1.net/pphlogger/pphlogger.php?id=journalized&amp;st=img" /></noscript>
<!-- PowerPhlogger Code END -->
</body>
</html>

132
links.install.php Normal file
View File

@ -0,0 +1,132 @@
<?php
// $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)
// *****************************************************************
// Start Connect To MYSQL
require_once("b2config.php");
include_once("$b2inc/b2template.functions.php");
include_once("$b2inc/b2vars.php");
include_once("$b2inc/b2functions.php");
include_once('links.config.php');
$connexion = mysql_connect($server,$loginsql,$passsql) or die("Can't connect to the database<br>".mysql_error());
$dbconnexion = mysql_select_db($base, $connexion);
$got_links = false;
$got_cats = false;
$got_row = false;
?><html>
<head>
<title>links > Installation</title>
</head>
<body>
<p>Checking for tables...</p>
<?php
$result = mysql_list_tables($dbname);
if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
if ($row[0] == $tablelinks)
$got_links = true;
if ($row[0] == $tablelinkcategories)
$got_cats = true;
//print "Table: $row[0]<br />\n";
}
if (!$got_cats) {
echo "<p>Can't find table '$tablelinkcategories', gonna create it...</p>\n";
$sql = "CREATE TABLE $tablelinkcategories ( " .
" 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) ".
") ";
$result = mysql_query($sql) or print ("Can't create the table '$tablelinkcategories' in the database.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Table '$tablelinkcategories' created OK</p>\n";
$got_cats = true;
}
} else {
echo "<p>Found table '$tablelinkcategories', don't need to create it...</p>\n";
$got_cats = true;
}
if (!$got_links) {
echo "<p>Can't find '$tablelinks', gonna create it...</p>\n";
$sql = "CREATE TABLE $tablelinks ( " .
" 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) " .
") ";
$result = mysql_query($sql) or print ("Can't create the table '$tablelinks' in the database.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Table '$tablelinks' created OK</p>\n";
$got_links = true;
}
} else {
echo "<p>Found table '$tablelinks', don't need to create it...</p>\n";
$got_links = true;
}
if ($got_links && $got_cats) {
echo "<p>Looking for category 1...</p>\n";
$sql = "SELECT * FROM $tablelinkcategories WHERE cat_id=1 ";
$result = mysql_query($sql) or print ("Can't query '$tablelinkcategories'.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
if ($row = mysql_fetch_object($result)) {
echo "<p>You have at least got category 1. Good!</p>\n";
$got_row = true;
} else {
echo "<p>Gonna insert category 1...</p>\n";
$sql = "INSERT INTO $tablelinkcategories (cat_id, cat_name) VALUES (1, 'General')";
$result = mysql_query($sql) or print ("Can't query insert category.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Inserted category Ok</p>\n";
$got_row = true;
}
}
}
}
if ($got_row) {
echo "<p>All done.</p>\n";
}
?>
</body>
</html>

326
links.php Normal file
View File

@ -0,0 +1,326 @@
<?php
// $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)
// *****************************************************************
include_once('links.config.php');
/** function get_linksbyname()
** Gets the links associated with category 'cat_name'.
** 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 '<br />') - 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 = '<br />',
$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 '<br />') - 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 = '<br />',
$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("<a href=\"".$the_link."\" title=\"" .
stripslashes($row->link_description) .
"\" target=\"$row->link_target\">");
if (($row->link_image != null) && $show_images) {
echo("<img src=\"$row->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("</a>");
} else {
echo("</a>$between" . stripslashes($row->link_description));
}
if ($show_updated) {
if (substr($row->link_updated,0,2) != '00') {
echo("</a>$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(' <img src="'.$links_rating_image[0].'" alt="' .
$row->link_rating.'" />'."\n");
}
} else {
if (($row->link_rating != 0) || ($links_rating_ignore_zero != 1)) {
echo(' <img src="' .
$links_rating_image[$row->link_rating].'" alt="' .
$row->link_rating.'" />'."\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 '<br />') - 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 = '<br />', $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 '<br />') - 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 = '<br />',
$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 = "<a href=\"#\" " .
" onclick=\"javascript:window.open('$file?popup=1', '_blank', " .
"'width=$width,height=$height,scrollbars=yes,status=no'); " .
" return false\">";
$javascript .= $text;
if ($count == true) {
$javascript .= " ($counts)";
}
$javascript .="</a>\n\n";
echo $javascript;
}
?>

190
links.readme.txt Normal file
View File

@ -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 <?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.
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

58
links.sql Normal file
View File

@ -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);

34
links.update-0.5.sql Normal file
View File

@ -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;

32
links.update-0.7.sql Normal file
View File

@ -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;

33
links.update-1.0.sql Normal file
View File

@ -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';

33
links.update-1.3.sql Normal file
View File

@ -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';

148
links.weblogs.com.php Normal file
View File

@ -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('<pre>');
// 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('</pre>');
} // end if updated cache file
?>