]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/link-categories.php
Wordpress 2.0.11
[autoinstalls/wordpress.git] / wp-admin / link-categories.php
1 <?php
2 // Links
3 // Copyright (C) 2002, 2003 Mike Little -- mike@zed1.com
4 require_once('admin.php');
5 $title = __('Link Categories');
6 $this_file='link-categories.php';
7 $parent_file = 'link-manager.php';
8 $list_js = true;
9
10 $wpvarstoreset = array('action', 'cat', 'auto_toggle');
11 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
12     $wpvar = $wpvarstoreset[$i];
13     if (!isset($$wpvar)) {
14         if (empty($_POST["$wpvar"])) {
15             if (empty($_GET["$wpvar"])) {
16                 $$wpvar = '';
17             } else {
18                 $$wpvar = $_GET["$wpvar"];
19             }
20         } else {
21             $$wpvar = $_POST["$wpvar"];
22         }
23     }
24 }
25
26 switch ($action) {
27   case 'addcat':
28   {
29       check_admin_referer('add-link-category');
30
31       if ( !current_user_can('manage_links') )
32           die (__("Cheatin' uh ?"));
33
34       $cat_name = wp_specialchars($_POST['cat_name']);
35       $auto_toggle = $_POST['auto_toggle'];
36       if ($auto_toggle != 'Y') {
37           $auto_toggle = 'N';
38       }
39
40       $show_images = $_POST['show_images'];
41       if ($show_images != 'Y') {
42           $show_images = 'N';
43       }
44
45       $show_description = $_POST['show_description'];
46       if ($show_description != 'Y') {
47           $show_description = 'N';
48       }
49
50       $show_rating = $_POST['show_rating'];
51       if ($show_rating != 'Y') {
52           $show_rating = 'N';
53       }
54
55       $show_updated = $_POST['show_updated'];
56       if ($show_updated != 'Y') {
57           $show_updated = 'N';
58       }
59
60       $sort_order = $_POST['sort_order'];
61
62       $sort_desc = $_POST['sort_desc'];
63       if ($sort_desc != 'Y') {
64           $sort_desc = 'N';
65       }
66       $text_before_link = $_POST['text_before_link'];
67       $text_after_link = $_POST['text_after_link'];
68       $text_after_all = $_POST['text_after_all'];
69
70       $list_limit = $_POST['list_limit'];
71       if ($list_limit == '')
72           $list_limit = -1;
73
74       $wpdb->query("INSERT INTO $wpdb->linkcategories (cat_id, cat_name, auto_toggle, show_images, show_description, \n" .
75              " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, text_after_all, list_limit) \n" .
76              " VALUES ('0', '$cat_name', '$auto_toggle', '$show_images', '$show_description', \n" .
77              " '$show_rating', '$show_updated', '$sort_order', '$sort_desc', '$text_before_link', '$text_after_link', \n" .
78              " '$text_after_all', $list_limit)");
79
80       wp_redirect('link-categories.php');
81     break;
82   } // end addcat
83   case 'Delete':
84   {
85         $cat_id = (int) $_GET['cat_id'];
86     check_admin_referer('delete-link-category_' . $cat_id);
87
88     $cat_name=get_linkcatname($cat_id);
89
90     if ($cat_id=="1")
91         die(sprintf(__("Can't delete the <strong>%s</strong> link category: this is the default one"), $cat_name));
92
93     if ( !current_user_can('manage_links') )
94       die (__("Cheatin' uh ?"));
95
96     $wpdb->query("DELETE FROM $wpdb->linkcategories WHERE cat_id='$cat_id'");
97     $wpdb->query("UPDATE $wpdb->links SET link_category=1 WHERE link_category='$cat_id'");
98
99     wp_redirect('link-categories.php');
100     break;
101   } // end delete
102   case 'Edit':
103   {
104     include_once ('admin-header.php');
105     $cat_id = (int) $_GET['cat_id'];
106     $row = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, "
107          . " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, "
108          . " text_after_all, list_limit FROM $wpdb->linkcategories WHERE cat_id=$cat_id");
109     if ($row) {
110         if ($row->list_limit == -1) {
111             $row->list_limit = '';
112         }
113 ?>
114
115 <div class="wrap">
116   <h2><?php printf(__('Edit &#8220%s&#8221; Category'), wp_specialchars($row->cat_name)); ?></h2>
117
118   <form name="editcat" method="post">
119   <?php wp_nonce_field('update-link-category_' . $row->cat_id) ?>
120       <input type="hidden" name="action" value="editedcat" />
121       <input type="hidden" name="cat_id" value="<?php echo $row->cat_id ?>" />
122 <fieldset class="options">
123 <legend><?php _e('Category Options') ?></legend>
124 <table class="editform" width="100%" cellspacing="2" cellpadding="5">
125 <tr>
126         <th width="33%" scope="row"><?php _e('Name:') ?></th>
127         <td width="67%"><input name="cat_name" type="text" value="<?php echo attribute_escape($row->cat_name)?>" size="30" /></td>
128 </tr>
129 <tr>
130         <th scope="row"><?php _e('Show:') ?></th>
131         <td>
132             <label>
133             <input type="checkbox" name="show_images"  value="Y" <?php checked('Y', $row->show_images); ?> /> 
134             <?php _e('Image') ?></label> <br />
135             <label>
136             <input type="checkbox" name="show_description" value="Y" <?php checked('Y', $row->show_description); ?> /> 
137             <?php _e('Description') ?></label> 
138             <?php _e('(shown in <code>title</code> regardless)') ?><br />
139             <label>
140             <input type="checkbox" name="show_rating"  value="Y" <?php checked('Y', $row->show_rating); ?> /> 
141             <?php _e('Rating') ?></label> <br />
142             <label>
143             <input type="checkbox" name="show_updated" value="Y" <?php checked('Y', $row->show_updated); ?> /> 
144             <?php _e('Updated') ?></label>
145 <?php _e('(shown in <code>title</code> regardless)') ?></td>
146 </tr>
147 <tr>
148         <th scope="row"><?php _e('Sort order:') ?></th>
149         <td>
150         <select name="sort_order" size="1">
151             <option value="name" <?php echo ($row->sort_order == 'name') ? 'selected="selected"' : ''?>><?php _e('Name') ?></option>
152             <option value="id"      <?php echo ($row->sort_order == 'id') ? 'selected' : ''?>><?php _e('Id') ?></option>
153             <option value="url"     <?php echo ($row->sort_order == 'url') ? 'selected' : ''?>><?php _e('URL') ?></option>
154             <option value="rating"  <?php echo ($row->sort_order == 'rating') ? 'selected' : ''?>><?php _e('Rating') ?></option>
155             <option value="updated" <?php echo ($row->sort_order == 'updated') ? 'selected' : ''?>><?php _e('Updated') ?></option>
156             <option value="rand"  <?php echo ($row->sort_order == 'rand') ? 'selected' : ''?>><?php _e('Random') ?></option>
157             <option value="length"  <?php echo ($row->sort_order == 'length') ? 'selected' : ''?>><?php _e('Name Length') ?></option>
158         </select>
159         <label>
160         <input type="checkbox" name="sort_desc" value="Y" <?php checked('Y', $row->sort_desc); ?> /> 
161         <?php _e('Descending') ?></label>
162         </td>
163 </tr>
164 <tr>
165         <th scope="row"><?php _e('Limit:') ?></th>
166         <td>
167         <input type="text" name="list_limit" size="5" value="<?php echo $row->list_limit ?>" /> 
168         <?php _e('(Leave empty for no limit to number of links shown)') ?>
169         </td>
170 </tr>
171 <tr>
172         <th scope="row"><?php _e('Toggle:') ?></th>
173         <td><label>
174                 <input type="checkbox" name="auto_toggle"  value="Y" <?php checked('Y', $row->auto_toggle); ?> /> 
175                 <?php _e('When new link is added toggle all others to be invisible') ?></label></td>
176 </tr>
177
178 </table>
179 </fieldset>
180 <fieldset class="options">
181 <legend><?php _e('Formatting') ?></legend>
182 <table class="editform" width="100%" cellspacing="2" cellpadding="5">
183 <tr>
184         <th width="33%" scope="row"><?php _e('Before Link:') ?></th>
185         <td width="67%"><input type="text" name="text_before_link" size="45" value="<?php echo wp_specialchars($row->text_before_link,'double')?>" /></td>
186 </tr>
187 <tr>
188 <th scope="row"><?php _e('Between Link and Description:') ?></th>
189 <td><input type="text" name="text_after_link" size="45" value="<?php echo wp_specialchars($row->text_after_link,'double')?>" /></td>
190 </tr>
191 <tr>
192 <th scope="row"><?php _e('After Link:') ?></th>
193 <td><input type="text" name="text_after_all" size="45" value="<?php echo wp_specialchars($row->text_after_all,'double')?>"/></td>
194 </tr>
195 </table>
196 </fieldset>
197 <p class="submit"><input type="submit" name="submit" value="<?php _e('Save Category Settings &raquo;') ?>" /></p>
198 </form>
199
200 </div>
201 <?php
202     } // end if row
203     break;
204   } // end Edit
205   case "editedcat":
206   {
207     $cat_id = (int)$_POST["cat_id"];
208     check_admin_referer('update-link-category_' . $cat_id);
209
210     if ( !current_user_can('manage_links') )
211       die (__("Cheatin' uh ?"));
212
213     $submit=$_POST["submit"];
214     if (isset($submit)) {
215
216     $cat_name= wp_specialchars($_POST["cat_name"]);
217     $auto_toggle = $_POST["auto_toggle"];
218     if ($auto_toggle != 'Y') {
219         $auto_toggle = 'N';
220     }
221
222     $show_images = $_POST["show_images"];
223     if ($show_images != 'Y') {
224         $show_images = 'N';
225     }
226
227     $show_description = $_POST["show_description"];
228     if ($show_description != 'Y') {
229         $show_description = 'N';
230     }
231
232     $show_rating = $_POST["show_rating"];
233     if ($show_rating != 'Y') {
234         $show_rating = 'N';
235     }
236
237     $show_updated = $_POST["show_updated"];
238     if ($show_updated != 'Y') {
239         $show_updated = 'N';
240     }
241
242     $sort_order = $_POST["sort_order"];
243
244     $sort_desc = $_POST["sort_desc"];
245     if ($sort_desc != 'Y') {
246         $sort_desc = 'N';
247     }
248     $text_before_link = $_POST["text_before_link"];
249     $text_after_link = $_POST["text_after_link"];
250     $text_after_all = $_POST["text_after_all"];
251
252     $list_limit = $_POST["list_limit"];
253     if ($list_limit == '')
254         $list_limit = -1;
255
256     $wpdb->query("UPDATE $wpdb->linkcategories set
257             cat_name='$cat_name',
258             auto_toggle='$auto_toggle',
259             show_images='$show_images',
260             show_description='$show_description',
261             show_rating='$show_rating',
262             show_updated='$show_updated',
263             sort_order='$sort_order',
264             sort_desc='$sort_desc',
265             text_before_link='$text_before_link',
266             text_after_link='$text_after_link',
267             text_after_all='$text_after_all',
268             list_limit=$list_limit
269             WHERE cat_id=$cat_id
270             ");
271     } // end if save
272
273
274     wp_redirect("link-categories.php");
275     break;
276   } // end editcat
277   default:
278   {
279     include_once ("admin-header.php");
280     if ( !current_user_can('manage_links') )
281       die(__("You have do not have sufficient permissions to edit the link categories for this blog. :)"));
282 ?>
283
284 <div class="wrap">
285             <h2><?php _e('Link Categories:') ?></h2>
286             <table id="the-list" width="100%" cellpadding="5" cellspacing="0" border="0">
287               <tr>
288                 <th rowspan="2" valign="bottom"><?php _e('Name') ?></th>
289                 <th rowspan="2" valign="bottom"><?php _e('ID') ?></th>
290                 <th rowspan="2" valign="bottom"><?php _e('Toggle?') ?></th>
291                 <th colspan="4" valign="bottom" class="alternate"><?php _e('Show') ?></th>
292                 <th rowspan="2" valign="bottom"><?php _e('Sort Order') ?></th>
293                 <th rowspan="2" valign="bottom"><?php _e('Desc?') ?></th>
294                 <th colspan="3" valign="bottom" class="alternate"><?php _e('Formatting') ?></th>
295                 <th rowspan="2" valign="bottom"><?php _e('Limit') ?></th>
296                 <th rowspan="2" colspan="2">&nbsp;</th>
297               </tr>
298               <tr>
299                 <th valign="top"><?php _e('Images') ?></th>
300                 <th valign="top"><?php _e('Description') ?></th>
301                 <th valign="top"><?php _e('Rating') ?></th>
302                 <th valign="top"><?php _e('Updated') ?></th>
303                 <th valign="top"><?php _e('Before') ?></th>
304                 <th valign="top"><?php _e('Between') ?></th>
305                 <th valign="top"><?php _e('After') ?></th>
306               </tr>
307 <?php
308 $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, "
309          . " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, "
310          . " text_after_all, list_limit FROM $wpdb->linkcategories ORDER BY cat_id");
311 $i = 1;
312 foreach ( (array) $results as $row) {
313     if ($row->list_limit == -1) {
314         $row->list_limit = __('none');
315     }
316     $style = ($i % 2) ? ' class="alternate"' : '';
317     /*
318         Manually internationalize every sort order option.
319     */
320     switch ($row->sort_order) {
321         case 'name':
322                 $row->sort_order = __('name');
323                 break;
324         case 'id':
325                 $row->sort_order = __('id');
326                 break;
327         case 'url':
328                 $row->sort_order = __('url');
329                 break;
330         case 'rating':
331                 $row->sort_order = __('rating');
332                 break;
333         case 'updated':
334                 $row->sort_order = __('updated');
335                 break;
336         case 'rand':
337                 $row->sort_order = __('rand');
338                 break;
339         case 'length':
340                 $row->sort_order = __('length');
341                 break;
342     }
343 ?>
344               <tr id="link-category-<?php echo $row->cat_id; ?>" valign="middle" align="center" <?php echo $style ?> style="border-bottom: 1px dotted #9C9A9C;">
345                 <td><?php echo wp_specialchars($row->cat_name)?></td>
346                                 <td ><?php echo $row->cat_id?></td>
347                 <td><?php echo $row->auto_toggle == 'Y' ? __('Yes') : __('No') ?></td>
348                 <td><?php echo $row->show_images == 'Y' ? __('Yes') : __('No') ?></td>
349                 <td><?php echo $row->show_description == 'Y' ? __('Yes') : __('No') ?></td>
350                 <td><?php echo $row->show_rating == 'Y' ? __('Yes') : __('No') ?></td>
351                 <td><?php echo $row->show_updated == 'Y' ? __('Yes') : __('No') ?></td>
352                 <td><?php echo $row->sort_order ?></td>
353                 <td><?php echo $row->sort_desc == 'Y' ? __('Yes') : __('No') ?></td>
354                 <td nowrap="nowrap"><?php echo wp_specialchars($row->text_before_link)?>&nbsp;</td>
355                 <td nowrap="nowrap"><?php echo wp_specialchars($row->text_after_link)?>&nbsp;</td>
356                 <td nowrap="nowrap"><?php echo wp_specialchars($row->text_after_all)?></td>
357                 <td><?php echo $row->list_limit ?></td>
358                 <td><a href="link-categories.php?cat_id=<?php echo $row->cat_id?>&amp;action=Edit" class="edit"><?php _e('Edit') ?></a></td>
359                 <td>
360                                 <?php if (1 == $row->cat_id ) { 
361                                         _e('Default');
362                                 } else { ?>
363                                         <a href="<?php echo wp_nonce_url("link-categories.php?cat_id=$row->cat_id?>&amp;action=Delete", 'delete-link-category_' . $row->cat_id) ?>" onclick="return deleteSomething( 'link category', <?php echo $row->cat_id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; link category.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), js_escape($row->cat_name)); ?>' );" class="delete"><?php _e('Delete') ?></a>
364                                 <?php } ?>
365               </td>
366            </tr>
367 <?php
368         ++$i;
369     }
370 ?>
371             </table>
372 <p><?php _e('These are the defaults for when you call a link category with no additional arguments. All of these settings may be overwritten.') ?></p>
373
374 <div id="ajax-response"></div>
375
376 </div>
377
378 <div class="wrap">
379     <form name="addcat" method="post" action="">
380     <?php wp_nonce_field('add-link-category'); ?>
381       <input type="hidden" name="action" value="addcat" />
382           <h2><?php _e('Add a Link Category:') ?></h2>
383 <fieldset class="options">
384 <legend><?php _e('Category Options') ?></legend>
385 <table class="editform" width="100%" cellspacing="2" cellpadding="5">
386 <tr>
387         <th width="33%" scope="row"><?php _e('Name:') ?></th>
388         <td width="67%"><input type="text" name="cat_name" size="30" /></td>
389 </tr>
390 <tr>
391         <th scope="row"><?php _e('Show:') ?></th>
392         <td>
393             <label>
394             <input type="checkbox" name="show_images"  value="Y" /> 
395             <?php _e('Image') ?></label> <br />
396             <label>
397             <input type="checkbox" name="show_description" value="Y" /> 
398             <?php _e('Description') ?></label> 
399             <?php _e('(shown in <code>title</code> regardless)') ?><br />
400             <label>
401             <input type="checkbox" name="show_rating"  value="Y" /> 
402             <?php _e('Rating') ?></label> <br />
403             <label>
404             <input type="checkbox" name="show_updated" value="Y" /> 
405             <?php _e('Updated') ?></label>
406 <?php _e('(shown in <code>title</code> regardless)') ?></td>
407 </tr>
408 <tr>
409         <th scope="row"><?php _e('Sort order:') ?></th>
410         <td>
411         <select name="sort_order" size="1">
412         <option value="name"><?php _e('Name') ?></option>
413         <option value="id"><?php _e('Id') ?></option>
414         <option value="url"><?php _e('URL') ?></option>
415         <option value="rating"><?php _e('Rating') ?></option>
416         <option value="updated"><?php _e('Updated') ?></option>
417         <option value="rand"><?php _e('Random') ?></option>
418         </select>
419         <label>
420         <input type="checkbox" name="sort_desc" value="Y" /> 
421         <?php _e('Descending') ?></label>
422         </td>
423 </tr>
424 <tr>
425         <th scope="row"><?php _e('Limit:') ?></th>
426         <td>
427         <input type="text" name="list_limit" size="5" value="" /> <?php _e('(Leave empty for no limit to number of links shown)') ?>
428         </td>
429 </tr>
430 <tr>
431         <th scope="row"><?php _e('Toggle:') ?></th>
432         <td><label>
433                 <input type="checkbox" name="auto_toggle"  value="Y" /> 
434                 <?php _e('When new link is added toggle all others to be invisible') ?></label></td>
435 </tr>
436
437 </table>
438 </fieldset>
439 <fieldset class="options">
440 <legend><?php _e('Formatting') ?></legend>
441 <table class="editform" width="100%" cellspacing="2" cellpadding="5">
442 <tr>
443         <th width="33%" scope="row"><?php _e('Before Link:') ?></th>
444         <td width="67%"><input type="text" name="text_before_link" size="45" value="&lt;li&gt;" /></td>
445 </tr>
446 <tr>
447 <th scope="row"><?php _e('Between Link and Description:') ?></th>
448 <td><input type="text" name="text_after_link" size="45" value="&lt;br /&gt;" /></td>
449 </tr>
450 <tr>
451 <th scope="row"><?php _e('After Link:') ?></th>
452 <td><input type="text" name="text_after_all" size="45" value="&lt;/li&gt;"/></td>
453 </tr>
454 </table>
455 </fieldset>
456 <p class="submit"><input type="submit" name="submit" value="<?php _e('Add Category &raquo;') ?>" /></p>
457   </form>
458 </div>
459 <div class="wrap">
460     <h3><?php _e('Note:') ?></h3>
461         <p><?php printf(__('Deleting a link category does not delete links from that category.<br />It will just set them back to the default category <strong>%s</strong>.'), get_linkcatname(1)) ?></p>
462 </div>
463 <?php
464     break;
465   } // end default
466 } // end case
467 ?>
468 <?php include('admin-footer.php'); ?>