Changeset 8758
- Timestamp:
- 08/27/2008 10:04:12 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/bookmark.php
r8600 r8758 52 52 do_action('deleted_link', $link_id); 53 53 54 clean_bookmark_cache($link_id); 55 54 56 return true; 55 57 } … … 66 68 } 67 69 68 function wp_insert_link($linkdata ) {70 function wp_insert_link($linkdata, $wp_error = false) { 69 71 global $wpdb, $current_user; 70 72 … … 120 122 121 123 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, 123 125 link_name = %s, link_image = %s, link_target = %s, 124 126 link_visible = %s, link_description = %s, link_rating = %s, 125 127 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 } 127 134 } 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 } 130 142 $link_id = (int) $wpdb->insert_id; 131 143 } … … 137 149 else 138 150 do_action('add_link', $link_id); 151 152 clean_bookmark_cache($link_id); 139 153 140 154 return $link_id; … … 150 164 151 165 wp_set_object_terms($link_id, $link_categories, 'link_category'); 166 167 clean_bookmark_cache($link_id); 152 168 } // wp_set_link_cats() 153 169 -
trunk/wp-admin/link-manager.php
r8682 r8758 164 164 <tbody> 165 165 <?php 166 $ i = 0; // It is slower incrementing an undefined and valueless variable.166 $alt = 0; 167 167 168 168 foreach ($links as $link) { … … 176 176 if (strlen($short_url) > 35) 177 177 $short_url = substr($short_url, 0, 32).'...'; 178 179 178 $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(); 182 182 ?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php 183 183 echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'.$link->link_id.'" /></th>'; … … 186 186 case 'name': 187 187 188 echo "<td><strong><a class='row-title' href='link.php?link_id=$link->link_id&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&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>'; 190 200 break; 191 201 case 'url': -
trunk/wp-includes/bookmark.php
r8742 r8758 18 18 * @return array|object Type returned depends on $output value. 19 19 */ 20 function get_bookmark($bookmark _id, $output = OBJECT, $filter = 'raw') {20 function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') { 21 21 global $wpdb; 22 22 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); 27 42 28 43 if ( $output == OBJECT ) { 29 return $ link;44 return $_bookmark; 30 45 } elseif ( $output == ARRAY_A ) { 31 return get_object_vars($ link);46 return get_object_vars($_bookmark); 32 47 } elseif ( $output == ARRAY_N ) { 33 return array_values(get_object_vars($ link));48 return array_values(get_object_vars($_bookmark)); 34 49 } else { 35 return $ link;50 return $_bookmark; 36 51 } 37 52 } … … 332 347 333 348 /** 334 * Deletes entirebookmark cache335 * 336 * @since 2. 1.0349 * Deletes bookmark cache 350 * 351 * @since 2.7.0 337 352 * @uses wp_cache_delete() Deletes the contents of 'get_bookmarks' 338 353 */ 339 function delete_get_bookmark_cache() { 354 function clean_bookmark_cache($bookmark_id) { 355 wp_cache_delete( $bookmark_id, 'bookmark' ); 340 356 wp_cache_delete( 'get_bookmarks', 'bookmark' ); 341 357 } 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' );345 358 346 359 ?> -
trunk/wp-includes/link-template.php
r8706 r8758 548 548 } 549 549 550 function 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&link_id=') . $link->link_id; 557 return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id ); 558 } 559 560 function 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 550 573 // Navigation links 551 574
Note: See TracChangeset
for help on using the changeset viewer.