get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
echo "\n\n";
}
$wpvarstoreset = array('action','cat_id', 'linkurl', 'name', 'image',
'description', 'visible', 'target', 'category', 'link_id',
'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel',
'notes', 'linkcheck[]');
for ($i=0; $i= the
//userlevel of the owner of the link then we can proceed.
if (count($linkcheck) == 0) {
header('Location: ' . $this_file);
exit;
}
$all_links = join(',', $linkcheck);
$results = $wpdb->get_results("SELECT link_id, link_owner, user_level FROM $wpdb->links LEFT JOIN $wpdb->users ON link_owner = ID WHERE link_id in ($all_links)");
foreach ($results as $row) {
if (($user_level >= $row->user_level)) { // ok to proceed
$ids_to_change[] = $row->link_id;
}
}
// should now have an array of links we can change
$all_links = join(',', $ids_to_change);
$q = $wpdb->query("update $wpdb->links SET link_owner='$newowner' WHERE link_id IN ($all_links)");
header('Location: ' . $this_file);
break;
}
case 'visibility':
{
check_admin_referer();
// check the current user's level first.
if ($user_level < 5)
die (__("Cheatin' uh ?"));
//for each link id (in $linkcheck[]): toggle the visibility
if (count($linkcheck) == 0) {
header('Location: ' . $this_file);
exit;
}
$all_links = join(',', $linkcheck);
$results = $wpdb->get_results("SELECT link_id, link_visible FROM $wpdb->links WHERE link_id in ($all_links)");
foreach ($results as $row) {
if ($row->link_visible == 'Y') { // ok to proceed
$ids_to_turnoff[] = $row->link_id;
} else {
$ids_to_turnon[] = $row->link_id;
}
}
// should now have two arrays of links to change
if (count($ids_to_turnoff)) {
$all_linksoff = join(',', $ids_to_turnoff);
$q = $wpdb->query("update $wpdb->links SET link_visible='N' WHERE link_id IN ($all_linksoff)");
}
if (count($ids_to_turnon)) {
$all_linkson = join(',', $ids_to_turnon);
$q = $wpdb->query("update $wpdb->links SET link_visible='Y' WHERE link_id IN ($all_linkson)");
}
header('Location: ' . $this_file);
break;
}
case 'move':
{
check_admin_referer();
// check the current user's level first.
if ($user_level < 5)
die (__("Cheatin' uh ?"));
//for each link id (in $linkcheck[]) change category to selected value
if (count($linkcheck) == 0) {
header('Location: ' . $this_file);
exit;
}
$all_links = join(',', $linkcheck);
// should now have an array of links we can change
$q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");
header('Location: ' . $this_file);
break;
}
case 'Add':
{
check_admin_referer();
$link_url = wp_specialchars($_POST['linkurl']);
$link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://' . $link_url;
$link_name = wp_specialchars($_POST['name']);
$link_image = wp_specialchars($_POST['image']);
$link_target = $_POST['target'];
$link_category = $_POST['category'];
$link_description = $_POST['description'];
$link_visible = $_POST['visible'];
$link_rating = $_POST['rating'];
$link_rel = $_POST['rel'];
$link_notes = $_POST['notes'];
$link_rss_uri = wp_specialchars($_POST['rss_uri']);
$auto_toggle = get_autotoggle($link_category);
if ($user_level < 5)
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')) {
$wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category");
}
$wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) " .
" VALUES('" . $link_url . "','"
. $link_name . "', '"
. $link_image . "', '$link_target', $link_category, '"
. $link_description . "', '$link_visible', $user_ID, $link_rating, '" . $link_rel . "', '" . $link_notes . "', '$link_rss_uri')");
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?added=true');
break;
} // end Add
case 'editlink':
{
if (isset($submit)) {
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;
check_admin_referer();
$link_id = (int) $_POST['link_id'];
$link_url = wp_specialchars($_POST['linkurl']);
$link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://' . $link_url;
$link_name = wp_specialchars($_POST['name']);
$link_image = wp_specialchars($_POST['image']);
$link_target = wp_specialchars($_POST['target']);
$link_category = $_POST['category'];
$link_description = $_POST['description'];
$link_visible = $_POST['visible'];
$link_rating = $_POST['rating'];
$link_rel = $_POST['rel'];
$link_notes = $_POST['notes'];
$link_rss_uri = $_POST['rss_uri'];
$auto_toggle = get_autotoggle($link_category);
if ($user_level < 5)
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')) {
$wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category");
}
$wpdb->query("UPDATE $wpdb->links SET link_url='" . $link_url . "',
link_name='" . $link_name . "',\n link_image='" . $link_image . "',
link_target='$link_target',\n link_category=$link_category,
link_visible='$link_visible',\n link_description='" . $link_description . "',
link_rating=$link_rating,
link_rel='" . $link_rel . "',
link_notes='" . $link_notes . "',
link_rss = '$link_rss_uri'
WHERE link_id=$link_id");
} // end if save
setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
wp_redirect($this_file);
break;
} // end Save
case 'Delete':
{
check_admin_referer();
$link_id = (int) $_GET['link_id'];
if ($user_level < 5)
die (__("Cheatin' uh ?"));
$wpdb->query("DELETE FROM $wpdb->links WHERE link_id = $link_id");
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_' . COOKIEHASH, $links_show_cat_id, time()+600);
wp_redirect($this_file);
break;
} // end Delete
case 'linkedit': {
$xfn = true;
include_once ('admin-header.php');
if ($user_level < 5)
die(__('You do not have sufficient permissions to edit the links for this blog.'));
$link_id = (int) $_GET['link_id'];
$row = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = $link_id");
if ($row) {
$link_url = wp_specialchars($row->link_url, 1);
$link_name = wp_specialchars($row->link_name, 1);
$link_image = $row->link_image;
$link_target = $row->link_target;
$link_category = $row->link_category;
$link_description = wp_specialchars($row->link_description);
$link_visible = $row->link_visible;
$link_rating = $row->link_rating;
$link_rel = $row->link_rel;
$link_notes = wp_specialchars($row->link_notes);
$link_rss_uri = wp_specialchars($row->link_rss);
} else {
die( __('Link not found.') );
}
?>