WordPress.org

Make WordPress Core

Changeset 8758


Ignore:
Timestamp:
08/27/2008 10:04:12 PM (10 years ago)
Author:
ryan
Message:

Add edit and delete links to the Content->Links rows. Add get_edit_bookmark_link(). Add caching for individual bookmarks. see #7552

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/bookmark.php

    r8600 r8758  
    5252    do_action('deleted_link', $link_id);
    5353
     54    clean_bookmark_cache($link_id);
     55
    5456    return true;
    5557}
     
    6668}
    6769
    68 function wp_insert_link($linkdata) {
     70function wp_insert_link($linkdata, $wp_error = false) {
    6971    global $wpdb, $current_user;
    7072
     
    120122
    121123    if ( $update ) {
    122         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_url = %s,
     124        if ( false === $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_url = %s,
    123125            link_name = %s, link_image = %s, link_target = %s,
    124126            link_visible = %s, link_description = %s, link_rating = %s,
    125127            link_rel = %s, link_notes = %s, link_rss = %s
    126             WHERE link_id = %s", $link_url, $link_name, $link_image, $link_target, $link_visible, $link_description, $link_rating, $link_rel, $link_notes, $link_rss, $link_id) );
     128            WHERE link_id = %s", $link_url, $link_name, $link_image, $link_target, $link_visible, $link_description, $link_rating, $link_rel, $link_notes, $link_rss, $link_id) ) ) {
     129            if ( $wp_error )
     130                return new WP_Error('db_update_error', __('Could not update link in the database'), $wpdb->last_error);
     131            else
     132                return 0;
     133        }
    127134    } else {
    128         $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
    129         $link_url,$link_name, $link_image, $link_target, $link_description, $link_visible, $link_owner, $link_rating, $link_rel, $link_notes, $link_rss) );
     135        if ( false === $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
     136        $link_url,$link_name, $link_image, $link_target, $link_description, $link_visible, $link_owner, $link_rating, $link_rel, $link_notes, $link_rss) ) ) {
     137            if ( $wp_error )
     138                return new WP_Error('db_insert_error', __('Could not insert link into the database'), $wpdb->last_error);
     139            else
     140                return 0;
     141        }
    130142        $link_id = (int) $wpdb->insert_id;
    131143    }
     
    137149    else
    138150        do_action('add_link', $link_id);
     151
     152    clean_bookmark_cache($link_id);
    139153
    140154    return $link_id;
     
    150164
    151165    wp_set_object_terms($link_id, $link_categories, 'link_category');
     166
     167    clean_bookmark_cache($link_id);
    152168}   // wp_set_link_cats()
    153169
  • trunk/wp-admin/link-manager.php

    r8682 r8758  
    164164    <tbody>
    165165<?php
    166     $i = 0; // It is slower incrementing an undefined and valueless variable.
     166    $alt = 0;
    167167
    168168    foreach ($links as $link) {
     
    176176        if (strlen($short_url) > 35)
    177177            $short_url = substr($short_url, 0, 32).'...';
    178 
    179178        $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
    180         ++ $i;
    181         $style = ($i % 2) ? '' : ' class="alternate"';
     179        $style = ($alt % 2) ? '' : ' class="alternate"';
     180        ++ $alt;
     181        $edit_link = get_edit_bookmark_link();
    182182        ?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php
    183183        echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'.$link->link_id.'" /></th>';
     
    186186                case 'name':
    187187
    188                     echo "<td><strong><a class='row-title' href='link.php?link_id=$link->link_id&amp;action=edit' title='" . attribute_escape(sprintf(__('Edit "%s"'), $link->link_name)) . "' class='edit'>$link->link_name</a></strong><br />";
    189                     echo $link->link_description . "</td>";
     188                    echo "<td><strong><a class='row-title' href='$edit_link' title='" . attribute_escape(sprintf(__('Edit "%s"'), $link->link_name)) . "' class='edit'>$link->link_name</a></strong><br />";
     189                    $actions = array();
     190                    $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
     191                    $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id) . "' onclick=\"if ( confirm('" . js_escape(sprintf( __("You are about to delete this link '%s'\n  'Cancel' to stop, 'OK' to delete."), $link->link_name )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
     192                    $action_count = count($actions);
     193                    $i = 0;
     194                    foreach ( $actions as $action => $link ) {
     195                        ++$i;
     196                        ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
     197                        echo "<span class='$action'>$link$sep</span>";
     198                    }
     199                    echo '</td>';
    190200                    break;
    191201                case 'url':
  • trunk/wp-includes/bookmark.php

    r8742 r8758  
    1818 * @return array|object Type returned depends on $output value.
    1919 */
    20 function get_bookmark($bookmark_id, $output = OBJECT, $filter = 'raw') {
     20function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') {
    2121    global $wpdb;
    2222
    23     $link = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark_id));
    24     $link->link_category = array_unique( wp_get_object_terms($link->link_id, 'link_category', 'fields=ids') );
    25 
    26     $link = sanitize_bookmark($link, $filter);
     23    if ( empty($bookmark) ) {
     24        if ( isset($GLOBALS['link']) )
     25            $_bookmark = & $GLOBALS['link'];
     26        else
     27            $_bookmark = null;
     28    } elseif ( is_object($bookmark) ) {
     29        wp_cache_add($bookmark->link_id, $bookmark, 'bookmark');
     30        $_bookmark = $bookmark;
     31    } else {
     32        if ( isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $link) ) {
     33            $_bookmark = & $GLOBALS['link'];
     34        } elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark') ) {
     35            $_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark));
     36            $_bookmark->link_category = array_unique( wp_get_object_terms($_bookmark->link_id, 'link_category', 'fields=ids') );           
     37            wp_cache_add($_bookmark->link_id, $_bookmark, 'bookmark');
     38        }
     39    }
     40
     41    $_bookmark = sanitize_bookmark($_bookmark, $filter);
    2742
    2843    if ( $output == OBJECT ) {
    29         return $link;
     44        return $_bookmark;
    3045    } elseif ( $output == ARRAY_A ) {
    31         return get_object_vars($link);
     46        return get_object_vars($_bookmark);
    3247    } elseif ( $output == ARRAY_N ) {
    33         return array_values(get_object_vars($link));
     48        return array_values(get_object_vars($_bookmark));
    3449    } else {
    35         return $link;
     50        return $_bookmark;
    3651    }
    3752}
     
    332347
    333348/**
    334  * Deletes entire bookmark cache
    335  *
    336  * @since 2.1.0
     349 * Deletes bookmark cache
     350 *
     351 * @since 2.7.0
    337352 * @uses wp_cache_delete() Deletes the contents of 'get_bookmarks'
    338353 */
    339 function delete_get_bookmark_cache() {
     354function clean_bookmark_cache($bookmark_id) {
     355    wp_cache_delete( $bookmark_id, 'bookmark' );
    340356    wp_cache_delete( 'get_bookmarks', 'bookmark' );
    341357}
    342 add_action( 'add_link', 'delete_get_bookmark_cache' );
    343 add_action( 'edit_link', 'delete_get_bookmark_cache' );
    344 add_action( 'delete_link', 'delete_get_bookmark_cache' );
    345358
    346359?>
  • trunk/wp-includes/link-template.php

    r8706 r8758  
    548548}
    549549
     550function get_edit_bookmark_link( $link = 0 ) {
     551    $link = &get_bookmark( $link );
     552
     553    if ( !current_user_can('manage_links') )
     554        return;
     555
     556    $location = admin_url('link.php?action=edit&amp;link_id=') . $link->link_id;
     557    return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
     558}
     559
     560function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
     561    $bookmark = get_bookmark($bookmark);
     562
     563    if ( !current_user_can('manage_links') )
     564        return;
     565
     566    if ( empty($link) )
     567        $link = __('Edit This');
     568
     569    $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>';
     570    echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
     571}
     572
    550573// Navigation links
    551574
Note: See TracChangeset for help on using the changeset viewer.