home *** CD-ROM | disk | FTP | other *** search
/ Clickx 23 / Clickx 23.iso / DATA / wordpress / wp-admin / link-categories.php < prev    next >
Encoding:
PHP Script  |  2005-03-15  |  16.8 KB  |  454 lines

  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.  
  9. $wpvarstoreset = array('action', 'cat', 'auto_toggle');
  10. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  11.     $wpvar = $wpvarstoreset[$i];
  12.     if (!isset($$wpvar)) {
  13.         if (empty($_POST["$wpvar"])) {
  14.             if (empty($_GET["$wpvar"])) {
  15.                 $$wpvar = '';
  16.             } else {
  17.                 $$wpvar = $_GET["$wpvar"];
  18.             }
  19.         } else {
  20.             $$wpvar = $_POST["$wpvar"];
  21.         }
  22.     }
  23. }
  24.  
  25. switch ($action) {
  26.   case 'addcat':
  27.   {
  28.       if ($user_level < 5)
  29.           die (__("Cheatin' uh ?"));
  30.  
  31.       $cat_name = wp_specialchars($_POST['cat_name']);
  32.       $auto_toggle = $_POST['auto_toggle'];
  33.       if ($auto_toggle != 'Y') {
  34.           $auto_toggle = 'N';
  35.       }
  36.  
  37.       $show_images = $_POST['show_images'];
  38.       if ($show_images != 'Y') {
  39.           $show_images = 'N';
  40.       }
  41.  
  42.       $show_description = $_POST['show_description'];
  43.       if ($show_description != 'Y') {
  44.           $show_description = 'N';
  45.       }
  46.  
  47.       $show_rating = $_POST['show_rating'];
  48.       if ($show_rating != 'Y') {
  49.           $show_rating = 'N';
  50.       }
  51.  
  52.       $show_updated = $_POST['show_updated'];
  53.       if ($show_updated != 'Y') {
  54.           $show_updated = 'N';
  55.       }
  56.  
  57.       $sort_order = $_POST['sort_order'];
  58.  
  59.       $sort_desc = $_POST['sort_desc'];
  60.       if ($sort_desc != 'Y') {
  61.           $sort_desc = 'N';
  62.       }
  63.       $text_before_link = addslashes($_POST['text_before_link']);
  64.       $text_after_link = addslashes($_POST['text_after_link']);
  65.       $text_after_all = addslashes($_POST['text_after_all']);
  66.  
  67.       $list_limit = $_POST['list_limit'];
  68.       if ($list_limit == '')
  69.           $list_limit = -1;
  70.  
  71.       $wpdb->query("INSERT INTO $wpdb->linkcategories (cat_id, cat_name, auto_toggle, show_images, show_description, \n" .
  72.              " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, text_after_all, list_limit) \n" .
  73.              " VALUES ('0', '$cat_name', '$auto_toggle', '$show_images', '$show_description', \n" .
  74.              " '$show_rating', '$show_updated', '$sort_order', '$sort_desc', '$text_before_link', '$text_after_link', \n" .
  75.              " '$text_after_all', $list_limit)");
  76.  
  77.       header('Location: link-categories.php');
  78.     break;
  79.   } // end addcat
  80.   case 'Delete':
  81.   {
  82.     $cat_id = (int) $_GET['cat_id'];
  83.     $cat_name=get_linkcatname($cat_id);
  84.  
  85.     if ($cat_id=="1")
  86.         die(sprintf(__("Can't delete the <strong>%s</strong> link category: this is the default one"), $cat_name));
  87.  
  88.     if ($user_level < 5)
  89.       die (__("Cheatin' uh ?"));
  90.  
  91.     $wpdb->query("DELETE FROM $wpdb->linkcategories WHERE cat_id='$cat_id'");
  92.     $wpdb->query("UPDATE $wpdb->links SET link_category=1 WHERE link_category='$cat_id'");
  93.  
  94.     header('Location: link-categories.php');
  95.     break;
  96.   } // end delete
  97.   case 'Edit':
  98.   {
  99.     include_once ('admin-header.php');
  100.     $cat_id = (int) $_GET['cat_id'];
  101.     $row = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, "
  102.          . " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, "
  103.          . " text_after_all, list_limit FROM $wpdb->linkcategories WHERE cat_id=$cat_id");
  104.     if ($row) {
  105.         if ($row->list_limit == -1) {
  106.             $row->list_limit = '';
  107.         }
  108. ?>
  109.  
  110. <div class="wrap">
  111.   <h2><?php printf(__('Edit “%s” Category'), wp_specialchars($row->cat_name)); ?></h2>
  112.  
  113.   <form name="editcat" method="post">
  114.       <input type="hidden" name="action" value="editedcat" />
  115.       <input type="hidden" name="cat_id" value="<?php echo $row->cat_id ?>" />
  116. <fieldset class="options">
  117. <legend><?php _e('Category Options') ?></legend>
  118. <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  119. <tr>
  120.     <th width="33%" scope="row"><?php _e('Name:') ?></th>
  121.     <td width="67%"><input name="cat_name" type="text" value="<?php echo wp_specialchars($row->cat_name)?>" size="30" /></td>
  122. </tr>
  123. <tr>
  124.     <th scope="row"><?php _e('Show:') ?></th>
  125.         <td>
  126.             <label>
  127.             <input type="checkbox" name="show_images"  value="Y" <?php checked('Y', $row->show_images); ?> /> 
  128.             <?php _e('Image') ?></label> <br />
  129.             <label>
  130.             <input type="checkbox" name="show_description" value="Y" <?php checked('Y', $row->show_description); ?> /> 
  131.             <?php _e('Description') ?></label> 
  132.             <?php _e('(shown in <code>title</code> regardless)') ?><br />
  133.             <label>
  134.             <input type="checkbox" name="show_rating"  value="Y" <?php checked('Y', $row->show_rating); ?> /> 
  135.             <?php _e('Rating') ?></label> <br />
  136.             <label>
  137.             <input type="checkbox" name="show_updated" value="Y" <?php checked('Y', $row->show_updated); ?> /> 
  138.             <?php _e('Updated') ?></label>
  139. <?php _e('(shown in <code>title</code> regardless)') ?></td>
  140. </tr>
  141. <tr>
  142.     <th scope="row"><?php _e('Sort order:') ?></th>
  143.     <td>
  144.     <select name="sort_order" size="1">
  145.             <option value="name" <?php echo ($row->sort_order == 'name') ? 'selected="selected"' : ''?>><?php _e('Name') ?></option>
  146.             <option value="id"      <?php echo ($row->sort_order == 'id') ? 'selected' : ''?>><?php _e('Id') ?></option>
  147.             <option value="url"     <?php echo ($row->sort_order == 'url') ? 'selected' : ''?>><?php _e('URL') ?></option>
  148.             <option value="rating"  <?php echo ($row->sort_order == 'rating') ? 'selected' : ''?>><?php _e('Rating') ?></option>
  149.             <option value="updated" <?php echo ($row->sort_order == 'updated') ? 'selected' : ''?>><?php _e('Updated') ?></option>
  150.             <option value="rand"  <?php echo ($row->sort_order == 'rand') ? 'selected' : ''?>><?php _e('Random') ?></option>
  151.             <option value="length"  <?php echo ($row->sort_order == 'length') ? 'selected' : ''?>><?php _e('Name Length') ?></option>
  152.     </select>
  153.     <label>
  154.     <input type="checkbox" name="sort_desc" value="Y" <?php checked('Y', $row->sort_desc); ?> /> 
  155.     <?php _e('Descending') ?></label>
  156.     </td>
  157. </tr>
  158. <tr>
  159.     <th scope="row"><?php _e('Limit:') ?></th>
  160.     <td>
  161.     <input type="text" name="list_limit" size="5" value="<?php echo $row->list_limit ?>" /> 
  162.     <?php _e('(Leave empty for no limit to number of links shown)') ?>
  163.     </td>
  164. </tr>
  165. <tr>
  166.     <th scope="row"><?php _e('Toggle:') ?></th>
  167.     <td><label>
  168.         <input type="checkbox" name="auto_toggle"  value="Y" <?php checked('Y', $row->auto_toggle); ?> /> 
  169.         <?php _e('When new link is added toggle all others to be invisible') ?></label></td>
  170. </tr>
  171.  
  172. </table>
  173. </fieldset>
  174. <fieldset class="options">
  175. <legend><?php _e('Formatting') ?></legend>
  176. <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  177. <tr>
  178.     <th width="33%" scope="row"><?php _e('Before Link:') ?></th>
  179.     <td width="67%"><input type="text" name="text_before_link" size="45" value="<?php echo wp_specialchars($row->text_before_link)?>" /></td>
  180. </tr>
  181. <tr>
  182. <th scope="row"><?php _e('Between Link and Description:') ?></th>
  183. <td><input type="text" name="text_after_link" size="45" value="<?php echo wp_specialchars($row->text_after_link)?>" /></td>
  184. </tr>
  185. <tr>
  186. <th scope="row"><?php _e('After Link:') ?></th>
  187. <td><input type="text" name="text_after_all" size="45" value="<?php echo wp_specialchars($row->text_after_all)?>"/></td>
  188. </tr>
  189. </table>
  190. </fieldset>
  191. <p class="submit"><input type="submit" name="submit" value="<?php _e('Save Category Settings »') ?>" /></p>
  192. </form>
  193.  
  194. </div>
  195. <?php
  196.     } // end if row
  197.     break;
  198.   } // end Edit
  199.   case "editedcat":
  200.   {
  201.     if ($user_level < 5)
  202.       die (__("Cheatin' uh ?"));
  203.  
  204.     $submit=$_POST["submit"];
  205.     if (isset($submit)) {
  206.  
  207.     $cat_id = (int)$_POST["cat_id"];
  208.  
  209.     $cat_name= wp_specialchars($_POST["cat_name"]);
  210.     $auto_toggle = $_POST["auto_toggle"];
  211.     if ($auto_toggle != 'Y') {
  212.         $auto_toggle = 'N';
  213.     }
  214.  
  215.     $show_images = $_POST["show_images"];
  216.     if ($show_images != 'Y') {
  217.         $show_images = 'N';
  218.     }
  219.  
  220.     $show_description = $_POST["show_description"];
  221.     if ($show_description != 'Y') {
  222.         $show_description = 'N';
  223.     }
  224.  
  225.     $show_rating = $_POST["show_rating"];
  226.     if ($show_rating != 'Y') {
  227.         $show_rating = 'N';
  228.     }
  229.  
  230.     $show_updated = $_POST["show_updated"];
  231.     if ($show_updated != 'Y') {
  232.         $show_updated = 'N';
  233.     }
  234.  
  235.     $sort_order = $_POST["sort_order"];
  236.  
  237.     $sort_desc = $_POST["sort_desc"];
  238.     if ($sort_desc != 'Y') {
  239.         $sort_desc = 'N';
  240.     }
  241.     $text_before_link = addslashes($_POST["text_before_link"]);
  242.     $text_after_link = addslashes($_POST["text_after_link"]);
  243.     $text_after_all = addslashes($_POST["text_after_all"]);
  244.  
  245.     $list_limit = $_POST["list_limit"];
  246.     if ($list_limit == '')
  247.         $list_limit = -1;
  248.  
  249.     $wpdb->query("UPDATE $wpdb->linkcategories set
  250.             cat_name='$cat_name',
  251.             auto_toggle='$auto_toggle',
  252.             show_images='$show_images',
  253.             show_description='$show_description',
  254.             show_rating='$show_rating',
  255.             show_updated='$show_updated',
  256.             sort_order='$sort_order',
  257.             sort_desc='$sort_desc',
  258.             text_before_link='$text_before_link',
  259.             text_after_link='$text_after_link',
  260.             text_after_all='$text_after_all',
  261.             list_limit=$list_limit
  262.             WHERE cat_id=$cat_id
  263.             ");
  264.     } // end if save
  265.  
  266.  
  267.     header("Location: link-categories.php");
  268.     break;
  269.   } // end editcat
  270.   default:
  271.   {
  272.     include_once ("admin-header.php");
  273.     if ($user_level < 5) {
  274.       die(__("You have do not have sufficient permissions to edit the link categories for this blog. :)"));
  275.     }
  276. ?>
  277.  
  278. <div class="wrap">
  279.             <h2><?php _e('Link Categories:') ?></h2>
  280.             <table 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"> </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 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)?> </td>
  349.                 <td nowrap="nowrap"><?php echo htmlentities($row->text_after_link)?> </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?>&action=Edit" class="edit"><?php _e('Edit') ?></a></td>
  353.                 <td><a href="link-categories.php?cat_id=<?php echo $row->cat_id?>&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>
  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>
  363.  
  364. <div class="wrap">
  365.     <form name="addcat" method="post">
  366.       <input type="hidden" name="action" value="addcat" />
  367.       <h2><?php _e('Add a Link Category:') ?></h2>
  368. <fieldset class="options">
  369. <legend><?php _e('Category Options') ?></legend>
  370. <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  371. <tr>
  372.     <th width="33%" scope="row"><?php _e('Name:') ?></th>
  373.     <td width="67%"><input type="text" name="cat_name" size="30" /></td>
  374. </tr>
  375. <tr>
  376.     <th scope="row"><?php _e('Show:') ?></th>
  377.         <td>
  378.             <label>
  379.             <input type="checkbox" name="show_images"  value="Y" /> 
  380.             <?php _e('Image') ?></label> <br />
  381.             <label>
  382.             <input type="checkbox" name="show_description" value="Y" /> 
  383.             <?php _e('Description') ?></label> 
  384.             <?php _e('(shown in <code>title</code> regardless)') ?><br />
  385.             <label>
  386.             <input type="checkbox" name="show_rating"  value="Y" /> 
  387.             <?php _e('Rating') ?></label> <br />
  388.             <label>
  389.             <input type="checkbox" name="show_updated" value="Y" /> 
  390.             <?php _e('Updated') ?></label>
  391. <?php _e('(shown in <code>title</code> regardless)') ?></td>
  392. </tr>
  393. <tr>
  394.     <th scope="row"><?php _e('Sort order:') ?></th>
  395.     <td>
  396.     <select name="sort_order" size="1">
  397.     <option value="name"><?php _e('Name') ?></option>
  398.     <option value="id"><?php _e('Id') ?></option>
  399.     <option value="url"><?php _e('URL') ?></option>
  400.     <option value="rating"><?php _e('Rating') ?></option>
  401.     <option value="updated"><?php _e('Updated') ?></option>
  402.     <option value="rand"><?php _e('Random') ?></option>
  403.     </select>
  404.     <label>
  405.     <input type="checkbox" name="sort_desc" value="Y" /> 
  406.     <?php _e('Descending') ?></label>
  407.     </td>
  408. </tr>
  409. <tr>
  410.     <th scope="row"><?php _e('Limit:') ?></th>
  411.     <td>
  412.     <input type="text" name="list_limit" size="5" value="" /> <?php _e('(Leave empty for no limit to number of links shown)') ?>
  413.     </td>
  414. </tr>
  415. <tr>
  416.     <th scope="row"><?php _e('Toggle:') ?></th>
  417.     <td><label>
  418.         <input type="checkbox" name="auto_toggle"  value="Y" /> 
  419.         <?php _e('When new link is added toggle all others to be invisible') ?></label></td>
  420. </tr>
  421.  
  422. </table>
  423. </fieldset>
  424. <fieldset class="options">
  425. <legend><?php _e('Formatting') ?></legend>
  426. <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  427. <tr>
  428.     <th width="33%" scope="row"><?php _e('Before Link:') ?></th>
  429.     <td width="67%"><input type="text" name="text_before_link" size="45" value="<li>" /></td>
  430. </tr>
  431. <tr>
  432. <th scope="row"><?php _e('Between Link and Description:') ?></th>
  433. <td><input type="text" name="text_after_link" size="45" value="<br />" /></td>
  434. </tr>
  435. <tr>
  436. <th scope="row"><?php _e('After Link:') ?></th>
  437. <td><input type="text" name="text_after_all" size="45" value="</li>"/></td>
  438. </tr>
  439. </table>
  440. </fieldset>
  441. <p class="submit"><input type="submit" name="submit" value="<?php _e('Add Category »') ?>" /></p>
  442.   </form>
  443. </div>
  444. <div class="wrap">
  445.     <h3><?php _e('Note:') ?></h3>
  446.     <?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>
  447. </div>
  448. <?php
  449.     break;
  450.   } // end default
  451. } // end case
  452. ?>
  453. <?php include('admin-footer.php'); ?>
  454.