| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
function akca_request_handler() { |
|---|
| 28 |
if (isset($_GET['ak_action'])) { |
|---|
| 29 |
switch ($_GET['ak_action']) { |
|---|
| 30 |
case 'akca_blank': |
|---|
| 31 |
die('<html></html>'); |
|---|
| 32 |
break; |
|---|
| 33 |
case 'akca_select_cat': |
|---|
| 34 |
ak_select_cat(); |
|---|
| 35 |
break; |
|---|
| 36 |
} |
|---|
| 37 |
} |
|---|
| 38 |
} |
|---|
| 39 |
add_action('init', 'akca_request_handler'); |
|---|
| 40 |
|
|---|
| 41 |
function ak_cat_rows($output) { |
|---|
| 42 |
ob_start(); |
|---|
| 43 |
if (isset($_GET['ak_cat_parent'])) { |
|---|
| 44 |
$parent = intval($_GET['ak_cat_parent']); |
|---|
| 45 |
$parent_cat = get_category($parent); |
|---|
| 46 |
} |
|---|
| 47 |
else { |
|---|
| 48 |
$parent = 0; |
|---|
| 49 |
} |
|---|
| 50 |
if (isset($_GET['ak_offset'])) { |
|---|
| 51 |
$offset = intval($_GET['ak_offset']); |
|---|
| 52 |
} |
|---|
| 53 |
else { |
|---|
| 54 |
$offset = 0; |
|---|
| 55 |
} |
|---|
| 56 |
global $wpdb, $class; |
|---|
| 57 |
|
|---|
| 58 |
$categories = $wpdb->get_results(" |
|---|
| 59 |
SELECT SQL_CALC_FOUND_ROWS |
|---|
| 60 |
t.term_id AS cat_ID, tt.count AS category_count, |
|---|
| 61 |
tt.description AS category_description, t.name AS cat_name, |
|---|
| 62 |
t.slug AS category_nicename, tt.parent AS category_parent |
|---|
| 63 |
FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id |
|---|
| 64 |
WHERE tt.taxonomy = 'category' AND tt.parent = '$parent' |
|---|
| 65 |
ORDER BY t.name LIMIT $offset, 50 |
|---|
| 66 |
"); |
|---|
| 67 |
$cat_count = intval($wpdb->get_var('SELECT FOUND_ROWS()')); |
|---|
| 68 |
|
|---|
| 69 |
$tools = ''; |
|---|
| 70 |
|
|---|
| 71 |
if ($cat_count > 50 || $parent != 0) { |
|---|
| 72 |
if ($offset + 50 < $cat_count) { |
|---|
| 73 |
$next = $offset + 50; |
|---|
| 74 |
$tools .= '<a href="categories.php?ak_offset='.$next.'&ak_cat_parent='.$parent.'" style="float: right;">Next »</a>'; |
|---|
| 75 |
} |
|---|
| 76 |
if ($offset > 0) { |
|---|
| 77 |
$prev = $offset - 50; |
|---|
| 78 |
if ($prev < 0) { |
|---|
| 79 |
$prev = 0; |
|---|
| 80 |
} |
|---|
| 81 |
$tools .= '<a href="categories.php?ak_offset='.$prev.'&ak_cat_parent='.$parent.'" style="float: left;">« Previous</a>'; |
|---|
| 82 |
} |
|---|
| 83 |
if ($parent != 0) { |
|---|
| 84 |
$tools .= '<a href="categories.php?ak_cat_parent='.$parent_cat->category_parent.'">Up a Level</a>'; |
|---|
| 85 |
} |
|---|
| 86 |
$tools = '<tr><td colspan="6" style="background: #DEEEFC; text-align: center;">'.$tools.'</td></tr>'; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
print($tools); |
|---|
| 90 |
|
|---|
| 91 |
if ($categories) { |
|---|
| 92 |
foreach ($categories as $category) { |
|---|
| 93 |
$category->cat_name = wp_specialchars($category->cat_name); |
|---|
| 94 |
$pad = str_repeat('— ', $level); |
|---|
| 95 |
if ( current_user_can('manage_categories') ) { |
|---|
| 96 |
$edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>"; |
|---|
| 97 |
$default_cat_id = get_option('default_category'); |
|---|
| 98 |
|
|---|
| 99 |
if ($category->cat_ID != $default_cat_id) |
|---|
| 100 |
$edit .= "<td><a href='" . wp_nonce_url("categories.php?action=delete&cat_ID=$category->cat_ID", 'delete-category_' . $category->cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . sprintf(__("You are about to delete the category "%s". All of its posts will go to the default category.\\n"OK" to delete, "Cancel" to stop."), js_escape($category->cat_name))."' );\" class='delete'>".__('Delete')."</a>"; |
|---|
| 101 |
else |
|---|
| 102 |
$edit .= "<td style='text-align:center'>".__("Default"); |
|---|
| 103 |
} |
|---|
| 104 |
else |
|---|
| 105 |
$edit = ''; |
|---|
| 106 |
|
|---|
| 107 |
$class = ('alternate' == $class) ? '' : 'alternate'; |
|---|
| 108 |
echo "<tr id='cat-$category->cat_ID' class='$class'> |
|---|
| 109 |
<th scope='row'>$category->cat_ID</th> |
|---|
| 110 |
<td><a href='categories.php?ak_cat_parent=$category->cat_ID'>$category->cat_name</a></td> |
|---|
| 111 |
<td>$category->category_description</td> |
|---|
| 112 |
<td>$category->category_count</td> |
|---|
| 113 |
<td>$edit</td> |
|---|
| 114 |
</tr>"; |
|---|
| 115 |
} |
|---|
| 116 |
} else { |
|---|
| 117 |
echo '<tr><td colspan="6" style="text-align: center;">No categories found.</td></tr>'; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
print($tools); |
|---|
| 121 |
$output = ob_get_contents(); |
|---|
| 122 |
ob_end_clean(); |
|---|
| 123 |
|
|---|
| 124 |
return $output; |
|---|
| 125 |
} |
|---|
| 126 |
add_action('cat_rows', 'ak_cat_rows'); |
|---|
| 127 |
|
|---|
| 128 |
function ak_cat_select_rows() { |
|---|
| 129 |
if (isset($_GET['ak_cat_parent'])) { |
|---|
| 130 |
$parent = intval($_GET['ak_cat_parent']); |
|---|
| 131 |
} |
|---|
| 132 |
else { |
|---|
| 133 |
$parent = 0; |
|---|
| 134 |
} |
|---|
| 135 |
if (isset($_GET['ak_offset'])) { |
|---|
| 136 |
$offset = intval($_GET['ak_offset']); |
|---|
| 137 |
} |
|---|
| 138 |
else { |
|---|
| 139 |
$offset = 0; |
|---|
| 140 |
} |
|---|
| 141 |
global $wpdb, $class; |
|---|
| 142 |
|
|---|
| 143 |
$categories = $wpdb->get_results(" |
|---|
| 144 |
SELECT SQL_CALC_FOUND_ROWS |
|---|
| 145 |
t.term_id AS cat_ID, tt.count AS category_count, |
|---|
| 146 |
tt.description AS category_description, t.name AS cat_name, |
|---|
| 147 |
t.slug AS category_nicename, tt.parent AS category_parent |
|---|
| 148 |
FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id |
|---|
| 149 |
WHERE tt.taxonomy = 'category' AND tt.parent = '$parent' |
|---|
| 150 |
ORDER BY t.name LIMIT $offset, 50 |
|---|
| 151 |
"); |
|---|
| 152 |
$cat_count = $wpdb->get_var('SELECT FOUND_ROWS()'); |
|---|
| 153 |
|
|---|
| 154 |
$tools = ''; |
|---|
| 155 |
|
|---|
| 156 |
if ($cat_count > 50) { |
|---|
| 157 |
if ($offset + 50 < $cat_count) { |
|---|
| 158 |
$next = $offset + 50; |
|---|
| 159 |
$tools .= '<a href="options-general.php?ak_action=akca_select_cat&ak_cat_parent='.$parent.'&ak_offset='.$next.'" style="float: right;">Next »</a>'; |
|---|
| 160 |
} |
|---|
| 161 |
if ($offset > 0) { |
|---|
| 162 |
$prev = $offset - 50; |
|---|
| 163 |
if ($prev < 0) { |
|---|
| 164 |
$prev = 0; |
|---|
| 165 |
} |
|---|
| 166 |
$tools .= '<a href="options-general.php?ak_action=akca_select_cat&ak_cat_parent='.$parent.'&ak_offset='.$prev.'">« Previous</a>'; |
|---|
| 167 |
} |
|---|
| 168 |
$tools = '<tr><td colspan="5" style="background: #DEEEFC;">'.$tools.'</td></tr>'; |
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
print($tools); |
|---|
| 172 |
|
|---|
| 173 |
if ($categories) { |
|---|
| 174 |
foreach ($categories as $category) { |
|---|
| 175 |
$category->cat_name = wp_specialchars($category->cat_name); |
|---|
| 176 |
$pad = str_repeat('— ', $level); |
|---|
| 177 |
|
|---|
| 178 |
$class = ('alternate' == $class) ? '' : 'alternate'; |
|---|
| 179 |
echo "<tr id='cat-$category->cat_ID' class='$class'> |
|---|
| 180 |
<th scope='row'>$category->cat_ID</th> |
|---|
| 181 |
<td><a href='options-general.php?ak_action=akca_select_cat&ak_cat_parent=$category->cat_ID'>$category->cat_name</a></td> |
|---|
| 182 |
<td>$category->category_description</td> |
|---|
| 183 |
".'<td style="text-align: center"><a href="#" onclick="top.document.getElementById(\'ak_cat_parent_display\').innerHTML=\''.$category->cat_name.'\'; top.document.getElementById(\'category_parent\').value=\''.$category->cat_ID.'\'; top.document.getElementById(\'ak_cat_chooser\').style.display=\'none\'; ">Select</a></td> |
|---|
| 184 |
</tr>'; |
|---|
| 185 |
} |
|---|
| 186 |
} else { |
|---|
| 187 |
echo '<tr><td colspan="4" style="text-align: center";>No categories found.</td></tr>'; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
print($tools); |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
function ak_edit_category_form($category) { |
|---|
| 194 |
if ($category->category_parent != 0) { |
|---|
| 195 |
$parent = get_category_to_edit($category->category_parent); |
|---|
| 196 |
$parent_name = $parent->cat_name; |
|---|
| 197 |
} |
|---|
| 198 |
else { |
|---|
| 199 |
$parent_name = 'None'; |
|---|
| 200 |
} |
|---|
| 201 |
$parent_id = $category->category_parent; |
|---|
| 202 |
?> |
|---|
| 203 |
|
|---|
| 204 |
<div class="wrap"> |
|---|
| 205 |
<h2><?php _e('Edit Category') ?></h2> |
|---|
| 206 |
<form name="editcat" action="categories.php" method="post"> |
|---|
| 207 |
<?php wp_nonce_field('update-category_' . $category->cat_ID); ?> |
|---|
| 208 |
<table class="editform" width="100%" cellspacing="2" cellpadding="5"> |
|---|
| 209 |
<tr> |
|---|
| 210 |
<th width="33%" scope="row"><?php _e('Category name:') ?></th> |
|---|
| 211 |
<td width="67%"><input name="cat_name" type="text" value="<?php echo wp_specialchars($category->cat_name); ?>" size="40" /> <input type="hidden" name="action" value="editedcat" /> |
|---|
| 212 |
<input type="hidden" name="cat_ID" value="<?php echo $category->cat_ID ?>" /></td> |
|---|
| 213 |
</tr> |
|---|
| 214 |
<tr> |
|---|
| 215 |
<th scope="row"><?php _e('Category slug:') ?></th> |
|---|
| 216 |
<td><input name="category_nicename" type="text" value="<?php echo wp_specialchars($category->category_nicename); ?>" size="40" /></td> |
|---|
| 217 |
</tr> |
|---|
| 218 |
<tr> |
|---|
| 219 |
<th scope="row" style="vertical-align: top; padding-top: 17px;"><?php _e('Category parent:') ?></th> |
|---|
| 220 |
<td> |
|---|
| 221 |
<p> |
|---|
| 222 |
<strong id="ak_cat_parent_display"><?php print($parent_name); ?></strong> (<a href="#" onclick="document.getElementById('ak_cat_chooser').style.display='block'; document.getElementById('ak_cat_chooser_iframe').src='options-general.php?ak_action=akca_select_cat&ak_cat_parent=0'; return false;">Change</a>) |
|---|
| 223 |
<input type="hidden" id="category_parent" name="category_parent" value="<?php print($parent_id); ?>" /> |
|---|
| 224 |
</p> |
|---|
| 225 |
<div id="ak_cat_chooser" style="display: none;"> |
|---|
| 226 |
<a href="#" onclick="document.getElementById('ak_cat_chooser').style.display='none'; return false;" style="float: right;">Close</a> |
|---|
| 227 |
<h3><?php _e('Categories'); ?> </h3> |
|---|
| 228 |
<iframe id="ak_cat_chooser_iframe" src="options-general.php?ak_action=akca_blank" border="0" frameborder="0" borderwidth="0" style="border: 1px solid #B2B2B2; height: 250px; width: 100%;"></iframe> |
|---|
| 229 |
</div> |
|---|
| 230 |
</td> |
|---|
| 231 |
</tr> |
|---|
| 232 |
<tr> |
|---|
| 233 |
<th scope="row"><?php _e('Description:') ?></th> |
|---|
| 234 |
<td><textarea name="category_description" rows="5" cols="50" style="width: 97%;"><?php echo wp_specialchars($category->category_description, 1); ?></textarea></td> |
|---|
| 235 |
</tr> |
|---|
| 236 |
</table> |
|---|
| 237 |
<p class="submit"><input type="submit" name="submit" value="<?php _e('Edit category') ?> »" /></p> |
|---|
| 238 |
</form> |
|---|
| 239 |
<p><a href="categories.php"><?php _e('« Return to category list'); ?></a></p> |
|---|
| 240 |
</div> |
|---|
| 241 |
<?php |
|---|
| 242 |
include('admin-footer.php'); |
|---|
| 243 |
die(); |
|---|
| 244 |
} |
|---|
| 245 |
add_action('edit_category_form_pre', 'ak_edit_category_form'); |
|---|
| 246 |
|
|---|
| 247 |
function ak_add_category_form() { |
|---|
| 248 |
require_once ('admin-header.php'); |
|---|
| 249 |
if ( current_user_can('manage_categories') ) : |
|---|
| 250 |
?> |
|---|
| 251 |
<div class="wrap"> |
|---|
| 252 |
<h2><?php _e('Add New Category') ?></h2> |
|---|
| 253 |
<form name="addcat" id="addcat" action="categories.php" method="post"> |
|---|
| 254 |
<?php wp_nonce_field('add-category'); ?> |
|---|
| 255 |
<p><?php _e('Name:') ?><br /> |
|---|
| 256 |
<input type="text" name="cat_name" value="" /></p> |
|---|
| 257 |
<p><?php _e('Category parent:') ?> |
|---|
| 258 |
<strong id="ak_cat_parent_display">None</strong> (<a href="#" onclick="document.getElementById('ak_cat_chooser').style.display='block'; document.getElementById('ak_cat_chooser_iframe').src='options-general.php?ak_action=akca_select_cat&ak_cat_parent=0'; return false;">Change</a>) |
|---|
| 259 |
<input type="hidden" id="category_parent" name="category_parent" value="0" /> |
|---|
| 260 |
</p> |
|---|
| 261 |
<div id="ak_cat_chooser" style="display: none;"> |
|---|
| 262 |
<a href="#" onclick="document.getElementById('ak_cat_chooser').style.display='none'; return false;" style="float: right;">Close</a> |
|---|
| 263 |
<h3><?php _e('Categories'); ?> </h3> |
|---|
| 264 |
<iframe id="ak_cat_chooser_iframe" src="options-general.php?ak_action=akca_blank" border="0" frameborder="0" borderwidth="0" style="border: 1px solid #B2B2B2; height: 250px; width: 100%;"></iframe> |
|---|
| 265 |
</div> |
|---|
| 266 |
<p><?php _e('Description: (optional)') ?> <br /> |
|---|
| 267 |
<textarea name="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p> |
|---|
| 268 |
<p class="submit"><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="<?php _e('Add Category »') ?>" /></p> |
|---|
| 269 |
</form> |
|---|
| 270 |
</div> |
|---|
| 271 |
<?php endif; |
|---|
| 272 |
include('admin-footer.php'); |
|---|
| 273 |
die(); |
|---|
| 274 |
} |
|---|
| 275 |
add_action('add_category_form_pre', 'ak_add_category_form'); |
|---|
| 276 |
|
|---|
| 277 |
function ak_select_cat() { |
|---|
| 278 |
$cat_ID = (int) $_GET['ak_cat_parent']; |
|---|
| 279 |
$category = get_category($cat_ID); |
|---|
| 280 |
|
|---|
| 281 |
?> |
|---|
| 282 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 283 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 284 |
<head> |
|---|
| 285 |
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_settings('blog_charset'); ?>" /> |
|---|
| 286 |
<title><?php bloginfo('name') ?> › <?php echo $title; ?> — WordPress</title> |
|---|
| 287 |
<link rel="stylesheet" href="<?php echo get_settings('siteurl') ?>/wp-admin/wp-admin.css?version=<?php bloginfo('version'); ?>" type="text/css" /> |
|---|
| 288 |
<?php do_action('admin_head'); ?> |
|---|
| 289 |
</head> |
|---|
| 290 |
<body> |
|---|
| 291 |
<?php |
|---|
| 292 |
if ($cat_ID != 0) { |
|---|
| 293 |
print('<p style="background: #DEEEFC; padding: 5px; margin: 0;"><a href="options-general.php?ak_action=akca_select_cat&ak_cat_parent='.$category->category_parent.'">« Up a Level</a></p>'); |
|---|
| 294 |
} |
|---|
| 295 |
?> |
|---|
| 296 |
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3"> |
|---|
| 297 |
<tr> |
|---|
| 298 |
<th scope="col"><?php _e('ID') ?></th> |
|---|
| 299 |
<th scope="col"><?php _e('Name') ?></th> |
|---|
| 300 |
<th scope="col"><?php _e('Description') ?></th> |
|---|
| 301 |
<th scope="col"><?php _e('Action') ?></th> |
|---|
| 302 |
</tr> |
|---|
| 303 |
<?php |
|---|
| 304 |
ak_cat_select_rows(); |
|---|
| 305 |
?> |
|---|
| 306 |
</table> |
|---|
| 307 |
</body> |
|---|
| 308 |
</html> |
|---|
| 309 |
<?php |
|---|
| 310 |
die(); |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
?> |
|---|