Log in with username/password: lyceum/lyceum

root/branches/1.0/src/lyceum/wp-admin/link-categories.php

Revision 1183, 17.9 kB (checked in by jjb, 2 years ago)

making code more parallel with wordpress, cleaning up cruft, fixing link category deletion default category check (was only broken on the backend-- the link was never made available anyway).

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