Added notes column to links. Can add/edit/save them in linkmanager.

Update/install scripts updated for new column.
added new methods get_linkobjects() and get_linkobjectsbyname()


git-svn-id: http://svn.automattic.com/wordpress/trunk@265 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
mikelittle 2003-07-23 00:26:03 +00:00
parent 3bc9d650ba
commit 81d1deec51
5 changed files with 211 additions and 100 deletions

View File

@ -123,6 +123,7 @@ if (!$got_links) {
" link_rating int NOT NULL DEFAULT '0', " .
" link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
" link_rel varchar(255) NOT NULL default '', " .
" link_notes MEDIUMTEXT NOT NULL default '', " .
" PRIMARY KEY (link_id) " .
") ";
$result = mysql_query($sql) or print ("Can't create the table '$tablelinks' in the database.<br />" . $sql . "<br />" . mysql_error());

View File

@ -51,7 +51,7 @@ if (!get_magic_quotes_gpc()) {
$b2varstoreset = array('action','standalone','cat_id', 'linkurl', 'name', 'image',
'description', 'visible', 'target', 'category', 'link_id',
'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel');
'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel', 'notes');
for ($i=0; $i<count($b2varstoreset); $i += 1) {
$b2var = $b2varstoreset[$i];
if (!isset($$b2var)) {
@ -87,6 +87,7 @@ switch ($action) {
$link_visible = $HTTP_POST_VARS["visible"];
$link_rating = $HTTP_POST_VARS["rating"];
$link_rel = $HTTP_POST_VARS["rel"];
$link_notes = $HTTP_POST_VARS["notes"];
$auto_toggle = get_autotoggle($link_category);
if ($user_level < $minadminlevel)
@ -97,12 +98,11 @@ switch ($action) {
if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
$wpdb->query("UPDATE $tablelinks set link_visible = 'N' WHERE link_category = $link_category");
}
$wpdb->query("INSERT INTO $tablelinks (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel) " .
$wpdb->query("INSERT INTO $tablelinks (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes) " .
" VALUES('" . addslashes($link_url) . "','"
. addslashes($link_name) . "', '"
. addslashes($link_image) . "', '$link_target', $link_category, '"
. addslashes($link_description) . "', '$link_visible', $user_ID, $link_rating, '" . addslashes($link_rel) ."')");
. addslashes($link_description) . "', '$link_visible', $user_ID, $link_rating, '" . addslashes($link_rel) . "', '" . addslashes($link_notes) . "')");
header('Location: linkmanager.php');
break;
@ -134,6 +134,7 @@ switch ($action) {
$link_visible = $HTTP_POST_VARS["visible"];
$link_rating = $HTTP_POST_VARS["rating"];
$link_rel = $HTTP_POST_VARS["rel"];
$link_notes = $HTTP_POST_VARS["notes"];
$auto_toggle = get_autotoggle($link_category);
if ($user_level < $minadminlevel)
@ -150,7 +151,8 @@ switch ($action) {
" 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" .
" link_rel='" . addslashes($link_rel) . "'\n" .
" link_rel='" . addslashes($link_rel) . "',\n" .
" link_notes='" . addslashes($link_notes) . "'\n" .
" WHERE link_id=$link_id");
//error_log($sql);
} // end if save
@ -192,12 +194,12 @@ switch ($action) {
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>. :)");
}
$row = $wpdb->get_row("SELECT link_url, link_name, link_image, link_target, link_description, link_visible, link_category AS cat_id, link_rating, link_rel " .
$row = $wpdb->get_row("SELECT link_url, link_name, link_image, link_target, link_description, link_visible, link_category AS cat_id, link_rating, link_rel, link_notes " .
" FROM $tablelinks " .
" WHERE link_id = $link_id");
if ($row) {
$link_url = $row->link_url;
$link_url = stripslashes($row->link_url);
$link_name = stripslashes($row->link_name);
$link_image = $row->link_image;
$link_target = $row->link_target;
@ -206,13 +208,15 @@ switch ($action) {
$link_visible = $row->link_visible;
$link_rating = $row->link_rating;
$link_rel = stripslashes($row->link_rel);
$link_notes = stripslashes($row->link_notes);
}
?>
<div class="wrap">
<table width="95%" cellpadding="5" cellspacing="0" border="0"><form name="editlink" method="post">
<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 ?>" />
@ -240,9 +244,14 @@ switch ($action) {
<td height="20" align="right">Rel:</td>
<td><input type="text" name="rel" size="80" value="<?php echo $link_rel; ?>"></td>
</tr>
<tr height="20">
<td height="20" valign="top" align="right">Notes:</td>
<td><textarea name="notes" cols="80" rows="10"><?php echo $link_notes; ?></textarea></td>
</tr>
<tr height="20">
<td height="20" align="right">Rating:</td>
<td> <select name="rating" size="1">
<td>
<select name="rating" size="1">
<?php
for ($r = 0; $r < 10; $r++) {
echo(' <option value="'.$r.'" ');
@ -251,32 +260,28 @@ switch ($action) {
echo('>'.$r.'</option>');
}
?>
</select>
&nbsp;(Leave at 0 for no rating.) </td>
</select>&nbsp;(Leave at 0 for no rating.)
</td>
</tr>
<tr height="20">
<td height="20" align="right">Target:</td>
<td><label>
<input type="radio" name="target" value="_blank" <?php echo(($link_target == '_blank') ? 'checked="checked"' : ''); ?>>
_blank</label> &nbsp;
<label>
<input type="radio" name="target" value="_top" <?php echo(($link_target == '_top') ? 'checked="checked"' : ''); ?>>
_top</label> &nbsp;
<label>
<input type="radio" name="target" value="" <?php echo(($link_target == '') ? 'checked="checked"' : ''); ?>>
none</label>
<td><label><input type="radio" name="target" value="_blank" <?php echo(($link_target == '_blank') ? 'checked="checked"' : ''); ?>> _blank</label>
&nbsp;<label><input type="radio" name="target" value="_top" <?php echo(($link_target == '_top') ? 'checked="checked"' : ''); ?>> _top</label>
&nbsp;<label><input type="radio" name="target" value="" <?php echo(($link_target == '') ? 'checked="checked"' : ''); ?>> none</label>
</td>
</tr>
<tr height="20">
<td height="20" align="right">Visible:</td>
<td><label>
<input type="radio" name="visible" checked="checked" value="Y">
Y</label> &nbsp; <label>
Yes</label>
&nbsp;<label>
<input type="radio" name="visible" value="N">
N</label></td>
No</label>
</td>
</tr>
<tr height="20">
<td height="20" align="right">Category:</td>
<td height="20" align="right"><label for="category">Category</label>:</td>
<td>
<?php
$results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id");
@ -295,9 +300,9 @@ switch ($action) {
</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 colspan="2" align="center">
<input type="submit" name="submit" value="Save" class="search">&nbsp;
<input type="submit" name="submit" value="Cancel" class="search">
</td>
</tr>
</table>
@ -367,7 +372,11 @@ switch ($action) {
<div class="wrap">
<form name="cats" method="post">
<table width="75%" cellpadding="5" cellspacing="0" border="0">
<tr><td><b>Link Categories:</b></td><td><a href="linkcategories.php">Manage Link Categories</a></td><td><a href="links.import.php">Import Blogroll</a></td></tr>
<tr>
<td><b>Link Categories:</b></td>
<td><a href="linkcategories.php">Manage Link Categories</a></td>
<td><a href="links.import.php">Import Blogroll</a></td>
</tr>
<tr>
<td>
<b>Show</b> links in category:<br />
@ -428,7 +437,7 @@ switch ($action) {
<th width="15%">Name</th>
<th>URL</th>
<th>Category</th>
<th>Relevance</th>
<th>Relationship</th>
<th>Image</th>
<th>Visible</th>
<th>&nbsp;</th>
@ -464,14 +473,17 @@ switch ($action) {
$links = $wpdb->get_results($sql);
if ($links) {
foreach ($links as $link) {
$short_url = str_replace('http://', '', $link->link_url);
$short_url = str_replace('http://', '', stripslashes($link->link_url));
$short_url = str_replace('www.', '', $short_url);
if ('/' == substr($short_url, -1)) $short_url = substr($short_url, 0, -1);
if (strlen($short_url) > 35) $short_url = substr($short_url, 0, 32).'...';
if ('/' == substr($short_url, -1))
$short_url = substr($short_url, 0, -1);
if (strlen($short_url) > 35)
$short_url = substr($short_url, 0, 32).'...';
$link->link_name = stripslashes($link->link_name);
$link->category = stripslashes($link->category);
$link->link_rel = stripslashes($link->link_rel);
$link->link_description = stripslashes($link->link_description);
$image = ($link->link_image != null) ? 'Yes' : 'No';
$visible = ($link->link_visible == 'Y') ? 'Yes' : 'No';
++$i;
@ -488,6 +500,7 @@ switch ($action) {
<td><input type="submit" name="edit" onclick="document.forms['links'].link_id.value='$link->link_id'; document.forms['links'].action.value='linkedit'; " value="Edit" class="search" /></td>
<td><input type="submit" name="delete" onclick="document.forms['links'].link_id.value='$link->link_id'; document.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>
</tr>
LINKS;
}
}
@ -511,7 +524,7 @@ LINKS;
</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>
<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>
@ -525,6 +538,10 @@ LINKS;
<td height="20" align="right">Rel:</td>
<td><input type="text" name="rel" size="80" value=""></td>
</tr>
<tr height="20">
<td height="20" valign="top" align="right">Notes:</td>
<td><textarea name="notes" cols="80" rows="10"></textarea></td>
</tr>
<tr height="20">
<td height="20" align="right">Rating:</td>
<td>
@ -540,22 +557,22 @@ LINKS;
<tr height="20">
<td height="20" align="right">Target:</td>
<td><label><input type="radio" name="target" value="_blank"> _blank</label>
&nbsp;<label><input type="radio" name="target" value="_top">
_top</label>&nbsp;<label><input type="radio" name="target" value="" checked="checked">
none</label></td>
&nbsp;<label><input type="radio" name="target" value="_top"> _top</label>
&nbsp;<label><input type="radio" name="target" value="" checked="checked"> none</label>
</td>
</tr>
<tr height="20">
<td height="20" align="right">Visible:</td>
<td><label>
<input type="radio" name="visible" checked="checked" value="Y">
Y</label>
&nbsp;
<label>
Yes</label>
&nbsp;<label>
<input type="radio" name="visible" value="N">
N</label></td>
No</label>
</td>
</tr>
<tr height="20">
<td height="20" align="right">Category:</td>
<td height="20" align="right"><label for="category">Category</label>:</td>
<td>
<?php
$results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id");

View File

@ -74,6 +74,26 @@ switch($step) {
case 1:
?>
<h1>Step 1</h1>
<p>There are some changes we need to make to the links tables with this version, so lets get those out of
the way.</p>
<?php
$error_count = 0;
$tablename = $tablelinks;
$ddl = "ALTER TABLE $tablelinks ADD COLUMN link_notes MEDIUMTEXT NOT NULL DEFAULT '' ";
maybe_add_column($tablename, 'link_notes', $ddl);
if (check_column($tablelinks, 'link_notes', 'mediumtext')) {
$res .= $tablename . ' - ok <br />';
} else {
$res .= 'There was a problem with ' . $tablename . '<br />';
++$error_count;
}
?>
<p>OK, that wasn't too bad was it? Let's move on to <a href="<?php echo $thisfile;?>?step=2">step 2</a>!</p>
<?php
case 2:
?>
<h1>Step 2</h1>
<p>There are a few new database tables with this version, so lets get those out of
the way.</p>
<?php

View File

@ -73,4 +73,76 @@ function maybe_drop_column($table_name, $column_name, $drop_ddl) {
// else didn't find it
return true;
}
/**
** check_column()
** Check column matches passed in criteria.
** Pass in null to skip checking that criteria
** Returns: true if it matches
** false otherwise
** (case sensitive) Column names returned from DESC table are:
** Field
** Type
** Null
** Key
** Default
** Extra
*/
function check_column($table_name, $col_name, $col_type, $is_null = null, $key = null, $default = null, $extra = null) {
global $wpdb;
$diffs = 0;
$results = $wpdb->get_results("DESC $table_name");
foreach ($results as $row ) {
print_r($row);
if ($row->Field == $col_name) {
// got our column, check the params
echo ("checking $row->Type != $col_type\n");
if (($col_type != null) && ($row->Type != $col_type)) {
++$diffs;
}
if (($is_null != null) && ($row->Null != $is_null)) {
++$diffs;
}
if (($key != null) && ($row->Key != $key)) {
++$diffs;
}
if (($default != null) && ($row->Default != $default)) {
++$diffs;
}
if (($extra != null) && ($row->Extra != $extra)) {
++$diffs;
}
if ($diffs > 0)
return false;
return true;
} // end if found our column
}
return false;
}
/*
echo "<p>testing</p>";
echo "<pre>";
//check_column('wp_links', 'link_description', 'mediumtext');
//if (check_column($tablecomments, 'comment_author', 'tinytext'))
// echo "ok\n";
$error_count = 0;
$tablename = $tablelinks;
// check the column
if (!check_column($tablelinks, 'link_description', 'varchar(255)'))
{
$ddl = "ALTER TABLE $tablelinks MODIFY COLUMN link_description varchar(255) NOT NULL DEFAULT '' ";
$q = $wpdb->query($ddl);
}
if (check_column($tablelinks, 'link_description', 'varchar(255)')) {
$res .= $tablename . ' - ok <br />';
} else {
$res .= 'There was a problem with ' . $tablename . '<br />';
++$error_count;
}
echo "</pre>";
*/
?>

View File

@ -113,6 +113,7 @@ if (!$got_links) {
" link_rating int NOT NULL DEFAULT '0', " .
" link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
" link_rel varchar(255) NOT NULL default '', " .
" link_notes MEDIUMTEXT NOT NULL default '', " .
" PRIMARY KEY (link_id) " .
") ";
$result = mysql_query($sql) or print ("Can't create the table '$tablelinks' in the database.<br />" . $sql . "<br />" . mysql_error());