summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-admin/link-categories.php
blob: 86f3da384caf43986fe05a0dcf0587d32424553e (plain)
1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<?php
// Links
// Copyright (C) 2002, 2003 Mike Little -- mike@zed1.com
require_once('admin.php');
$title = __('Link Categories');
$this_file='link-categories.php';
$parent_file = 'link-manager.php';

$wpvarstoreset = array('action', 'cat', 'auto_toggle');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
    $wpvar = $wpvarstoreset[$i];
    if (!isset($$wpvar)) {
        if (empty($_POST["$wpvar"])) {
            if (empty($_GET["$wpvar"])) {
                $$wpvar = '';
            } else {
                $$wpvar = $_GET["$wpvar"];
            }
        } else {
            $$wpvar = $_POST["$wpvar"];
        }
    }
}

switch ($action) {
  case 'addcat':
  {
      if ($user_level < 5)
          die (__("Cheatin' uh ?"));

      $cat_name = wp_specialchars($_POST['cat_name']);
      $auto_toggle = $_POST['auto_toggle'];
      if ($auto_toggle != 'Y') {
          $auto_toggle = 'N';
      }

      $show_images = $_POST['show_images'];
      if ($show_images != 'Y') {
          $show_images = 'N';
      }

      $show_description = $_POST['show_description'];
      if ($show_description != 'Y') {
          $show_description = 'N';
      }

      $show_rating = $_POST['show_rating'];
      if ($show_rating != 'Y') {
          $show_rating = 'N';
      }

      $show_updated = $_POST['show_updated'];
      if ($show_updated != 'Y') {
          $show_updated = 'N';
      }

      $sort_order = $_POST['sort_order'];

      $sort_desc = $_POST['sort_desc'];
      if ($sort_desc != 'Y') {
          $sort_desc = 'N';
      }
      $text_before_link = $_POST['text_before_link'];
      $text_after_link = $_POST['text_after_link'];
      $text_after_all = $_POST['text_after_all'];

      $list_limit = $_POST['list_limit'];
      if ($list_limit == '')
          $list_limit = -1;

      $wpdb->query("INSERT INTO $wpdb->linkcategories (cat_id, cat_name, auto_toggle, show_images, show_description, \n" .
             " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, text_after_all, list_limit) \n" .
             " VALUES ('0', '$cat_name', '$auto_toggle', '$show_images', '$show_description', \n" .
             " '$show_rating', '$show_updated', '$sort_order', '$sort_desc', '$text_before_link', '$text_after_link', \n" .
             " '$text_after_all', $list_limit)");

      header('Location: link-categories.php');
    break;
  } // end addcat
  case 'Delete':
  {
    $cat_id = (int) $_GET['cat_id'];
    $cat_name=get_linkcatname($cat_id);

    if ($cat_id=="1")
        die(sprintf(__("Can't delete the <strong>%s</strong> link category: this is the default one"), $cat_name));

    if ($user_level < 5)
      die (__("Cheatin' uh ?"));

    $wpdb->query("DELETE FROM $wpdb->linkcategories WHERE cat_id='$cat_id'");
    $wpdb->query("UPDATE $wpdb->links SET link_category=1 WHERE link_category='$cat_id'");

    header('Location: link-categories.php');
    break;
  } // end delete
  case 'Edit':
  {
    include_once ('admin-header.php');
    $cat_id = (int) $_GET['cat_id'];
    $row = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, "
         . " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, "
         . " text_after_all, list_limit FROM $wpdb->linkcategories WHERE cat_id=$cat_id");
    if ($row) {
        if ($row->list_limit == -1) {
            $row->list_limit = '';
        }
?>

<div class="wrap">
  <h2><?php printf(__('Edit &#8220%s&#8221; Category'), wp_specialchars($row->cat_name)); ?></h2>

  <form name="editcat" method="post">
      <input type="hidden" name="action" value="editedcat" />
      <input type="hidden" name="cat_id" value="<?php echo $row->cat_id ?>" />
<fieldset class="options">
<legend><?php _e('Category Options') ?></legend>
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
<tr>
	<th width="33%" scope="row"><?php _e('Name:') ?></th>
	<td width="67%"><input name="cat_name" type="text" value="<?php echo wp_specialchars($row->cat_name)?>" size="30" /></td>
</tr>
<tr>
	<th scope="row"><?php _e('Show:') ?></th>
        <td>
            <label>
            <input type="checkbox" name="show_images"  value="Y" <?php checked('Y', $row->show_images); ?> /> 
            <?php _e('Image') ?></label> <br />
            <label>
            <input type="checkbox" name="show_description" value="Y" <?php checked('Y', $row->show_description); ?> /> 
            <?php _e('Description') ?></label> 
            <?php _e('(shown in <code>title</code> regardless)') ?><br />
            <label>
            <input type="checkbox" name="show_rating"  value="Y" <?php checked('Y', $row->show_rating); ?> /> 
            <?php _e('Rating') ?></label> <br />
            <label>
            <input type="checkbox" name="show_updated" value="Y" <?php checked('Y', $row->show_updated); ?> /> 
            <?php _e('Updated') ?></label>
<?php _e('(shown in <code>title</code> regardless)') ?></td>
</tr>
<tr>
	<th scope="row"><?php _e('Sort order:') ?></th>
	<td>
	<select name="sort_order" size="1">
            <option value="name" <?php echo ($row->sort_order == 'name') ? 'selected="selected"' : ''?>><?php _e('Name') ?></option>
            <option value="id"      <?php echo ($row->sort_order == 'id') ? 'selected' : ''?>><?php _e('Id') ?></option>
            <option value="url"     <?php echo ($row->sort_order == 'url') ? 'selected' : ''?>><?php _e('URL') ?></option>
            <option value="rating"  <?php echo ($row->sort_order == 'rating') ? 'selected' : ''?>><?php _e('Rating') ?></option>
            <option value="updated" <?php echo ($row->sort_order == 'updated') ? 'selected' : ''?>><?php _e('Updated') ?></option>
            <option value="rand"  <?php echo ($row->sort_order == 'rand') ? 'selected' : ''?>><?php _e('Random') ?></option>
            <option value="length"  <?php echo ($row->sort_order == 'length') ? 'selected' : ''?>><?php _e('Name Length') ?></option>
	</select>
	<label>
	<input type="checkbox" name="sort_desc" value="Y" <?php checked('Y', $row->sort_desc); ?> /> 
	<?php _e('Descending') ?></label>
	</td>
</tr>
<tr>
	<th scope="row"><?php _e('Limit:') ?></th>
	<td>
	<input type="text" name="list_limit" size="5" value="<?php echo $row->list_limit ?>" /> 
	<?php _e('(Leave empty for no limit to number of links shown)') ?>
	</td>
</tr>
<tr>
	<th scope="row"><?php _e('Toggle:') ?></th>
	<td><label>
		<input type="checkbox" name="auto_toggle"  value="Y" <?php checked('Y', $row->auto_toggle); ?> /> 
		<?php _e('When new link is added toggle all others to be invisible') ?></label></td>
</tr>

</table>
</fieldset>
<fieldset class="options">
<legend><?php _e('Formatting') ?></legend>
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
<tr>
	<th width="33%" scope="row"><?php _e('Before Link:') ?></th>
	<td width="67%"><input type="text" name="text_before_link" size="45" value="<?php echo wp_specialchars($row->text_before_link)?>" /></td>
</tr>
<tr>
<th scope="row"><?php _e('Between Link and Description:') ?></th>
<td><input type="text" name="text_after_link" size="45" value="<?php echo wp_specialchars($row->text_after_link)?>" /></td>
</tr>
<tr>
<th scope="row"><?php _e('After Link:') ?></th>
<td><input type="text" name="text_after_all" size="45" value="<?php echo wp_specialchars($row->text_after_all)?>"/></td>
</tr>
</table>
</fieldset>
<p class="submit"><input type="submit" name="submit" value="<?php _e('Save Category Settings &raquo;') ?>" /></p>
</form>

</div>
<?php
    } // end if row
    break;
  } // end Edit
  case "editedcat":
  {
    if ($user_level < 5)
      die (__("Cheatin' uh ?"));

    $submit=$_POST["submit"];
    if (isset($submit)) {

    $cat_id = (int)$_POST["cat_id"];

    $cat_name= wp_specialchars($_POST["cat_name"]);
    $auto_toggle = $_POST["auto_toggle"];
    if ($auto_toggle != 'Y') {
        $auto_toggle = 'N';
    }

    $show_images = $_POST["show_images"];
    if ($show_images != 'Y') {
        $show_images = 'N';
    }

    $show_description = $_POST["show_description"];
    if ($show_description != 'Y') {
        $show_description = 'N';
    }

    $show_rating = $_POST["show_rating"];
    if ($show_rating != 'Y') {
        $show_rating = 'N';
    }

    $show_updated = $_POST["show_updated"];
    if ($show_updated != 'Y') {
        $show_updated = 'N';
    }

    $sort_order = $_POST["sort_order"];

    $sort_desc = $_POST["sort_desc"];
    if ($sort_desc != 'Y') {
        $sort_desc = 'N';
    }
    $text_before_link = $_POST["text_before_link"];
    $text_after_link = $_POST["text_after_link"];
    $text_after_all = $_POST["text_after_all"];

    $list_limit = $_POST["list_limit"];
    if ($list_limit == '')
        $list_limit = -1;

    $wpdb->query("UPDATE $wpdb->linkcategories set
            cat_name='$cat_name',
            auto_toggle='$auto_toggle',
            show_images='$show_images',
            show_description='$show_description',
            show_rating='$show_rating',
            show_updated='$show_updated',
            sort_order='$sort_order',
            sort_desc='$sort_desc',
            text_before_link='$text_before_link',
            text_after_link='$text_after_link',
            text_after_all='$text_after_all',
            list_limit=$list_limit
            WHERE cat_id=$cat_id
            ");
    } // end if save


    header("Location: link-categories.php");
    break;
  } // end editcat
  default:
  {
    include_once ("admin-header.php");
    if ($user_level < 5) {
      die(__("You have do not have sufficient permissions to edit the link categories for this blog. :)"));
    }
?>

<div class="wrap">
            <h2><?php _e('Link Categories:') ?></h2>
            <table width="100%" cellpadding="5" cellspacing="0" border="0">
              <tr>
 	        <th rowspan="2" valign="bottom"><?php _e('Name') ?></th>
                <th rowspan="2" valign="bottom"><?php _e('ID') ?></th>
                <th rowspan="2" valign="bottom"><?php _e('Toggle?') ?></th>
                <th colspan="4" valign="bottom" class="alternate"><?php _e('Show') ?></th>
                <th rowspan="2" valign="bottom"><?php _e('Sort Order') ?></th>
                <th rowspan="2" valign="bottom"><?php _e('Desc?') ?></th>
                <th colspan="3" valign="bottom" class="alternate"><?php _e('Formatting') ?></th>
                <th rowspan="2" valign="bottom"><?php _e('Limit') ?></th>
                <th rowspan="2" colspan="2">&nbsp;</th>
              </tr>
              <tr>
                <th valign="top"><?php _e('Images') ?></th>
                <th valign="top"><?php _e('Description') ?></th>
                <th valign="top"><?php _e('Rating') ?></th>
                <th valign="top"><?php _e('Updated') ?></th>
                <th valign="top"><?php _e('Before') ?></th>
                <th valign="top"><?php _e('Between') ?></th>
                <th valign="top"><?php _e('After') ?></th>
              </tr>
<?php
$results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, "
         . " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, "
         . " text_after_all, list_limit FROM $wpdb->linkcategories ORDER BY cat_id");
$i = 1;
foreach ($results as $row) {
    if ($row->list_limit == -1) {
        $row->list_limit = __('none');
    }
    $style = ($i % 2) ? ' class="alternate"' : '';
    /*
    	Manually internationalize every sort order option.
    */
    switch ($row->sort_order) {
    	case 'name':
    		$row->sort_order = __('name');
    		break;
    	case 'id':
    		$row->sort_order = __('id');
    		break;
    	case 'url':
    		$row->sort_order = __('url');
    		break;
    	case 'rating':
    		$row->sort_order = __('rating');
    		break;
    	case 'updated':
    		$row->sort_order = __('updated');
    		break;
    	case 'rand':
    		$row->sort_order = __('rand');
    		break;
    	case 'length':
    		$row->sort_order = __('length');
    		break;
    }
?>
              <tr valign="middle" align="center" <?php echo $style ?> style="border-bottom: 1px dotted #9C9A9C;">
                <td><?php echo wp_specialchars($row->cat_name)?></td>
				<td ><?php echo $row->cat_id?></td>
                <td><?php echo $row->auto_toggle == 'Y' ? __('Yes') : __('No') ?></td>
                <td><?php echo $row->show_images == 'Y' ? __('Yes') : __('No') ?></td>
                <td><?php echo $row->show_description == 'Y' ? __('Yes') : __('No') ?></td>
                <td><?php echo $row->show_rating == 'Y' ? __('Yes') : __('No') ?></td>
                <td><?php echo $row->show_updated == 'Y' ? __('Yes') : __('No') ?></td>
                <td><?php echo $row->sort_order ?></td>
                <td><?php echo $row->sort_desc == 'Y' ? __('Yes') : __('No') ?></td>
                <td nowrap="nowrap"><?php echo htmlentities($row->text_before_link)?>&nbsp;</td>
                <td nowrap="nowrap"><?php echo htmlentities($row->text_after_link)?>&nbsp;</td>
                <td nowrap="nowrap"><?php echo htmlentities($row->text_after_all)?></td>
                <td><?php echo $row->list_limit ?></td>
                <td><a href="link-categories.php?cat_id=<?php echo $row->cat_id?>&amp;action=Edit" class="edit"><?php _e('Edit') ?></a></td>
                <td><a href="link-categories.php?cat_id=<?php echo $row->cat_id?>&amp;action=Delete" onclick="return confirm('<?php _e("You are about to delete this category.\\n  \'Cancel\' to stop, \'OK\' to delete.") ?>');" class="delete"><?php _e('Delete') ?></a></td>
              </tr>
<?php
        ++$i;
    }
?>
            </table>
<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>

</div>

<div class="wrap">
    <form name="addcat" method="post">
      <input type="hidden" name="action" value="addcat" />
	  <h2><?php _e('Add a Link Category:') ?></h2>
<fieldset class="options">
<legend><?php _e('Category Options') ?></legend>
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
<tr>
	<th width="33%" scope="row"><?php _e('Name:') ?></th>
	<td width="67%"><input type="text" name="cat_name" size="30" /></td>
</tr>
<tr>
	<th scope="row"><?php _e('Show:') ?></th>
        <td>
            <label>
            <input type="checkbox" name="show_images"  value="Y" /> 
            <?php _e('Image') ?></label> <br />
            <label>
            <input type="checkbox" name="show_description" value="Y" /> 
            <?php _e('Description') ?></label> 
            <?php _e('(shown in <code>title</code> regardless)') ?><br />
            <label>
            <input type="checkbox" name="show_rating"  value="Y" /> 
            <?php _e('Rating') ?></label> <br />
            <label>
            <input type="checkbox" name="show_updated" value="Y" /> 
            <?php _e('Updated') ?></label>
<?php _e('(shown in <code>title</code> regardless)') ?></td>
</tr>
<tr>
	<th scope="row"><?php _e('Sort order:') ?></th>
	<td>
	<select name="sort_order" size="1">
	<option value="name"><?php _e('Name') ?></option>
	<option value="id"><?php _e('Id') ?></option>
	<option value="url"><?php _e('URL') ?></option>
	<option value="rating"><?php _e('Rating') ?></option>
	<option value="updated"><?php _e('Updated') ?></option>
	<option value="rand"><?php _e('Random') ?></option>
	</select>
	<label>
	<input type="checkbox" name="sort_desc" value="Y" /> 
	<?php _e('Descending') ?></label>
	</td>
</tr>
<tr>
	<th scope="row"><?php _e('Limit:') ?></th>
	<td>
	<input type="text" name="list_limit" size="5" value="" /> <?php _e('(Leave empty for no limit to number of links shown)') ?>
	</td>
</tr>
<tr>
	<th scope="row"><?php _e('Toggle:') ?></th>
	<td><label>
		<input type="checkbox" name="auto_toggle"  value="Y" /> 
		<?php _e('When new link is added toggle all others to be invisible') ?></label></td>
</tr>

</table>
</fieldset>
<fieldset class="options">
<legend><?php _e('Formatting') ?></legend>
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
<tr>
	<th width="33%" scope="row"><?php _e('Before Link:') ?></th>
	<td width="67%"><input type="text" name="text_before_link" size="45" value="&lt;li&gt;" /></td>
</tr>
<tr>
<th scope="row"><?php _e('Between Link and Description:') ?></th>
<td><input type="text" name="text_after_link" size="45" value="&lt;br /&gt;" /></td>
</tr>
<tr>
<th scope="row"><?php _e('After Link:') ?></th>
<td><input type="text" name="text_after_all" size="45" value="&lt;/li&gt;"/></td>
</tr>
</table>
</fieldset>
<p class="submit"><input type="submit" name="submit" value="<?php _e('Add Category &raquo;') ?>" /></p>
  </form>
</div>
<div class="wrap">
    <h3><?php _e('Note:') ?></h3>
    <?php printf(__('<p>Deleting a link category does not delete links from that category.<br />It will just set them back to the default category <b>%s</b>.'), get_linkcatname(1)) ?></p>
</div>
<?php
    break;
  } // end default
} // end case
?>
<?php include('admin-footer.php'); ?>