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