Make WordPress Core


Ignore:
Timestamp:
09/18/2005 07:44:14 PM (20 years ago)
Author:
ryan
Message:

Link love. Add get_link(), get_link_to_edit(), add_link(), edit_link(), wp_insert_link(), wp_update_link(), wp_delete_link()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/link-manager.php

    r2832 r2889  
    160160    check_admin_referer();
    161161
    162     $link_url = wp_specialchars($_POST['linkurl']);
    163     $link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://' . $link_url;
    164     $link_name = wp_specialchars($_POST['name']);
    165     $link_image = wp_specialchars($_POST['image']);
    166     $link_target = $_POST['target'];
    167     $link_category = $_POST['category'];
    168     $link_description = $_POST['description'];
    169     $link_visible = $_POST['visible'];
    170     $link_rating = $_POST['rating'];
    171     $link_rel = $_POST['rel'];
    172     $link_notes = $_POST['notes'];
    173     $link_rss_uri =  wp_specialchars($_POST['rss_uri']);
    174     $auto_toggle = get_autotoggle($link_category);
     162    add_link();
     163   
     164    header('Location: ' . $_SERVER['HTTP_REFERER'] . '?added=true');
     165    break;
     166  } // end Add
     167
     168  case 'editlink':
     169  {
     170 
     171    check_admin_referer();
     172   
     173    if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
     174        $cat_id = $links_show_cat_id;
     175
     176    if (!isset($cat_id) || ($cat_id == '')) {
     177        if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
     178            $cat_id = 'All';
     179    }
     180    $links_show_cat_id = $cat_id;
     181
     182    $link_id = (int) $_POST['link_id'];
     183    edit_link($link_id);
     184   
     185    setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
     186    wp_redirect($this_file);
     187    break;
     188  } // end Save
     189
     190  case 'Delete':
     191  {
     192    check_admin_referer();
    175193
    176194    if ( !current_user_can('manage_links') )
    177195      die (__("Cheatin' uh ?"));
    178196
    179     // if we are in an auto toggle category and this one is visible then we
    180     // need to make the others invisible before we add this new one.
    181     if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
    182       $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category");
    183     }
    184     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) " .
    185       " VALUES('" . $link_url . "','"
    186            . $link_name . "', '"
    187            . $link_image . "', '$link_target', $link_category, '"
    188            . $link_description . "', '$link_visible', $user_ID, $link_rating, '" . $link_rel . "', '" . $link_notes . "', '$link_rss_uri')");
    189 
    190     header('Location: ' . $_SERVER['HTTP_REFERER'] . '?added=true');
    191     break;
    192   } // end Add
    193 
    194   case 'editlink':
    195   {
    196     if (isset($submit)) {
    197 
    198       if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
    199         $cat_id = $links_show_cat_id;
    200 
    201       if (!isset($cat_id) || ($cat_id == '')) {
    202         if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
    203           $cat_id = 'All';
    204       }
    205       $links_show_cat_id = $cat_id;
    206 
    207       check_admin_referer();
    208 
    209       $link_id = (int) $_POST['link_id'];
    210       $link_url = wp_specialchars($_POST['linkurl']);
    211       $link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://' . $link_url;
    212       $link_name = wp_specialchars($_POST['name']);
    213       $link_image = wp_specialchars($_POST['image']);
    214       $link_target = wp_specialchars($_POST['target']);
    215       $link_category = $_POST['category'];
    216       $link_description = $_POST['description'];
    217       $link_visible = $_POST['visible'];
    218       $link_rating = $_POST['rating'];
    219       $link_rel = $_POST['rel'];
    220       $link_notes = $_POST['notes'];
    221       $link_rss_uri =  $_POST['rss_uri'];
    222       $auto_toggle = get_autotoggle($link_category);
    223 
    224       if ( !current_user_can('manage_links') )
    225         die (__("Cheatin' uh ?"));
    226 
    227       // if we are in an auto toggle category and this one is visible then we
    228       // need to make the others invisible before we update this one.
    229       if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
    230         $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category");
    231       }
    232 
    233       $wpdb->query("UPDATE $wpdb->links SET link_url='" . $link_url . "',
    234       link_name='" . $link_name . "',\n link_image='" . $link_image . "',
    235       link_target='$link_target',\n link_category=$link_category,
    236       link_visible='$link_visible',\n link_description='" . $link_description . "',
    237       link_rating=$link_rating,
    238       link_rel='" . $link_rel . "',
    239       link_notes='" . $link_notes . "',
    240       link_rss = '$link_rss_uri'
    241       WHERE link_id=$link_id");
    242     } // end if save
    243     setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
    244     wp_redirect($this_file);
    245     break;
    246   } // end Save
    247 
    248   case 'Delete':
    249   {
    250     check_admin_referer();
    251 
    252197    $link_id = (int) $_GET['link_id'];
    253198
    254     if ( !current_user_can('manage_links') )
    255       die (__("Cheatin' uh ?"));
    256 
    257     $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = $link_id");
    258 
     199    wp_delete_link($link_id);
     200   
    259201    if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
    260202        $cat_id = $links_show_cat_id;
     
    277219
    278220    $link_id = (int) $_GET['link_id'];
    279     $row = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = $link_id");
    280 
    281     if ($row) {
    282       $link_url = wp_specialchars($row->link_url, 1);
    283       $link_name = wp_specialchars($row->link_name, 1);
    284       $link_image = $row->link_image;
    285       $link_target = $row->link_target;
    286       $link_category = $row->link_category;
    287       $link_description = wp_specialchars($row->link_description);
    288       $link_visible = $row->link_visible;
    289       $link_rating = $row->link_rating;
    290       $link_rel = $row->link_rel;
    291       $link_notes = wp_specialchars($row->link_notes);
    292       $link_rss_uri = wp_specialchars($row->link_rss);
    293     } else {
    294         die( __('Link not found.') );
    295     }
    296 
     221 
     222    if ( !$link = get_link_to_edit($link_id) )
     223        die( __('Link not found.') );
    297224?>
    298225
     
    305232         <tr>
    306233           <th width="33%" scope="row"><?php _e('URI:') ?></th>
    307            <td width="67%"><input type="text" name="linkurl" value="<?php echo $link_url; ?>" style="width: 95%;" /></td>
     234           <td width="67%"><input type="text" name="link_url" value="<?php echo $link->link_url; ?>" style="width: 95%;" /></td>
    308235         </tr>
    309236         <tr>
    310237           <th scope="row"><?php _e('Link Name:') ?></th>
    311            <td><input type="text" name="name" value="<?php echo $link_name; ?>" style="width: 95%" /></td>
     238           <td><input type="text" name="link_name" value="<?php echo $link->link_name; ?>" style="width: 95%" /></td>
    312239         </tr>
    313240         <tr>
    314241            <th scope="row"><?php _e('Short description:') ?></th>
    315             <td><input type="text" name="description" value="<?php echo $link_description; ?>" style="width: 95%" /></td>
     242            <td><input type="text" name="link_description" value="<?php echo $link->link_description; ?>" style="width: 95%" /></td>
    316243            </tr>
    317244        <tr>
    318245           <th scope="row"><?php _e('Category:') ?></th>
    319            <td><?php category_dropdown('category', $link_category); ?></td>
     246           <td><?php category_dropdown('link_category', $link->link_category); ?></td>
    320247         </tr>
    321248</table>
     
    329256            <tr>
    330257                <th width="33%" scope="row"><?php _e('rel:') ?></th>
    331                 <td width="67%"><input type="text" name="rel" id="rel" size="50" value="<?php echo $link_rel; ?>" /></td>
     258                <td width="67%"><input type="text" name="link_rel" id="rel" size="50" value="<?php echo $link->link_rel; ?>" /></td>
    332259            </tr>
    333260            <tr>
     
    442369         <tr>
    443370           <th width="33%" scope="row"><?php _e('Image URI:') ?></th>
    444            <td width="67%"><input type="text" name="image" size="50" value="<?php echo $link_image; ?>" style="width: 95%" /></td>
     371           <td width="67%"><input type="text" name="link_image" size="50" value="<?php echo $link->link_image; ?>" style="width: 95%" /></td>
    445372         </tr>
    446373<tr>
    447374           <th scope="row"><?php _e('RSS URI:') ?> </th>
    448            <td><input name="rss_uri" type="text" id="rss_uri" value="<?php echo $link_rss_uri; ?>" size="50" style="width: 95%" /></td>
     375           <td><input name="link_rss" type="text" id="rss_uri" value="<?php echo $link->link_rss; ?>" size="50" style="width: 95%" /></td>
    449376         </tr>
    450377         <tr>
    451378           <th scope="row"><?php _e('Notes:') ?></th>
    452            <td><textarea name="notes" cols="50" rows="10" style="width: 95%"><?php echo $link_notes; ?></textarea></td>
     379           <td><textarea name="link_notes" cols="50" rows="10" style="width: 95%"><?php echo $link->link_notes; ?></textarea></td>
    453380         </tr>
    454381         <tr>
    455382           <th scope="row"><?php _e('Rating:') ?></th>
    456            <td><select name="rating" size="1">
     383           <td><select name="link_rating" size="1">
    457384<?php
    458385    for ($r = 0; $r < 10; $r++) {
    459386      echo('            <option value="'.$r.'" ');
    460       if ($link_rating == $r)
     387      if ($link->link_rating == $r)
    461388        echo 'selected="selected"';
    462389      echo('>'.$r.'</option>');
     
    469396           <th scope="row"><?php _e('Target') ?></th>
    470397           <td><label>
    471           <input type="radio" name="target" value="_blank"   <?php echo(($link_target == '_blank') ? 'checked="checked"' : ''); ?> />
     398          <input type="radio" name="target" value="_blank"   <?php echo(($link->link_target == '_blank') ? 'checked="checked"' : ''); ?> />
    472399          <code>_blank</code></label><br />
    473400<label>
    474 <input type="radio" name="target" value="_top" <?php echo(($link_target == '_top') ? 'checked="checked"' : ''); ?> />
     401<input type="radio" name="target" value="_top" <?php echo(($link->link_target == '_top') ? 'checked="checked"' : ''); ?> />
    475402<code>_top</code></label><br />
    476403<label>
    477 <input type="radio" name="target" value=""     <?php echo(($link_target == '') ? 'checked="checked"' : ''); ?> />
     404<input type="radio" name="link_target" value=""     <?php echo(($link->link_target == '') ? 'checked="checked"' : ''); ?> />
    478405<?php _e('none') ?></label><br />
    479406<?php _e('(Note that the <code>target</code> attribute is illegal in XHTML 1.1 and 1.0 Strict.)') ?></td>
     
    482409           <th scope="row"><?php _e('Visible:') ?></th>
    483410           <td><label>
    484              <input type="radio" name="visible" <?php if ($link_visible == 'Y') echo "checked='checked'"; ?> value="Y" />
     411             <input type="radio" name="link_visible" <?php if ($link->link_visible == 'Y') echo "checked='checked'"; ?> value="Y" />
    485412<?php _e('Yes') ?></label><br /><label>
    486 <input type="radio" name="visible" <?php if ($link_visible == 'N') echo "checked='checked'"; ?> value="N" />
     413<input type="radio" name="visible" <?php if ($link->link_visible == 'N') echo "checked='checked'"; ?> value="N" />
    487414<?php _e('No') ?></label></td>
    488415         </tr>
Note: See TracChangeset for help on using the changeset viewer.