-
+ 1C639B91AC9A2DAC87AAABF0634D11F260123F2C8FCB9521041069AD3BC74E490492A16D8442ADE919AA7DAD594E6FC147902BA482899619D6DDD31DCCCB7915
mp-wp/wp-admin/includes/bookmark.php
(0 . 0)(1 . 268)
22778 <?php
22779 /**
22780 * WordPress Bookmark Administration API
22781 *
22782 * @package WordPress
22783 * @subpackage Administration
22784 */
22785
22786 /**
22787 * {@internal Missing Short Description}}
22788 *
22789 * @since unknown
22790 *
22791 * @return unknown
22792 */
22793 function add_link() {
22794 return edit_link();
22795 }
22796
22797 /**
22798 * {@internal Missing Short Description}}
22799 *
22800 * @since unknown
22801 *
22802 * @param unknown_type $link_id
22803 * @return unknown
22804 */
22805 function edit_link( $link_id = '' ) {
22806 if (!current_user_can( 'manage_links' ))
22807 wp_die( __( 'Cheatin’ uh?' ));
22808
22809 $_POST['link_url'] = wp_specialchars( $_POST['link_url'] );
22810 $_POST['link_url'] = clean_url($_POST['link_url']);
22811 $_POST['link_name'] = wp_specialchars( $_POST['link_name'] );
22812 $_POST['link_image'] = wp_specialchars( $_POST['link_image'] );
22813 $_POST['link_rss'] = clean_url($_POST['link_rss']);
22814 if ( !isset($_POST['link_visible']) || 'N' != $_POST['link_visible'] )
22815 $_POST['link_visible'] = 'Y';
22816
22817 if ( !empty( $link_id ) ) {
22818 $_POST['link_id'] = $link_id;
22819 return wp_update_link( $_POST);
22820 } else {
22821 return wp_insert_link( $_POST);
22822 }
22823 }
22824
22825 /**
22826 * {@internal Missing Short Description}}
22827 *
22828 * @since unknown
22829 *
22830 * @return unknown
22831 */
22832 function get_default_link_to_edit() {
22833 if ( isset( $_GET['linkurl'] ) )
22834 $link->link_url = clean_url( $_GET['linkurl']);
22835 else
22836 $link->link_url = '';
22837
22838 if ( isset( $_GET['name'] ) )
22839 $link->link_name = attribute_escape( $_GET['name']);
22840 else
22841 $link->link_name = '';
22842
22843 $link->link_visible = 'Y';
22844
22845 return $link;
22846 }
22847
22848 /**
22849 * {@internal Missing Short Description}}
22850 *
22851 * @since unknown
22852 *
22853 * @param unknown_type $link_id
22854 * @return unknown
22855 */
22856 function wp_delete_link( $link_id ) {
22857 global $wpdb;
22858
22859 do_action( 'delete_link', $link_id );
22860
22861 wp_delete_object_term_relationships( $link_id, 'link_category' );
22862
22863 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->links WHERE link_id = %d", $link_id ) );
22864
22865 do_action( 'deleted_link', $link_id );
22866
22867 clean_bookmark_cache( $link_id );
22868
22869 return true;
22870 }
22871
22872 /**
22873 * {@internal Missing Short Description}}
22874 *
22875 * @since unknown
22876 *
22877 * @param unknown_type $link_id
22878 * @return unknown
22879 */
22880 function wp_get_link_cats( $link_id = 0 ) {
22881
22882 $cats = wp_get_object_terms( $link_id, 'link_category', 'fields=ids' );
22883
22884 return array_unique( $cats );
22885 }
22886
22887 /**
22888 * {@internal Missing Short Description}}
22889 *
22890 * @since unknown
22891 *
22892 * @param unknown_type $link_id
22893 * @return unknown
22894 */
22895 function get_link_to_edit( $link_id ) {
22896 return get_bookmark( $link_id, OBJECT, 'edit' );
22897 }
22898
22899 /**
22900 * {@internal Missing Short Description}}
22901 *
22902 * @since unknown
22903 *
22904 * @param unknown_type $linkdata
22905 * @return unknown
22906 */
22907 function wp_insert_link( $linkdata, $wp_error = false ) {
22908 global $wpdb, $current_user;
22909
22910 $defaults = array( 'link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 );
22911
22912 $linkdata = wp_parse_args( $linkdata, $defaults );
22913 $linkdata = sanitize_bookmark( $linkdata, 'db' );
22914
22915 extract( stripslashes_deep( $linkdata ), EXTR_SKIP );
22916
22917 $update = false;
22918
22919 if ( !empty( $link_id ) )
22920 $update = true;
22921
22922 if ( trim( $link_name ) == '' )
22923 return 0;
22924
22925 if ( trim( $link_url ) == '' )
22926 return 0;
22927
22928 if ( empty( $link_rating ) )
22929 $link_rating = 0;
22930
22931 if ( empty( $link_image ) )
22932 $link_image = '';
22933
22934 if ( empty( $link_target ) )
22935 $link_target = '';
22936
22937 if ( empty( $link_visible ) )
22938 $link_visible = 'Y';
22939
22940 if ( empty( $link_owner ) )
22941 $link_owner = $current_user->id;
22942
22943 if ( empty( $link_notes ) )
22944 $link_notes = '';
22945
22946 if ( empty( $link_description ) )
22947 $link_description = '';
22948
22949 if ( empty( $link_rss ) )
22950 $link_rss = '';
22951
22952 if ( empty( $link_rel ) )
22953 $link_rel = '';
22954
22955 // Make sure we set a valid category
22956 if ( ! isset( $link_category ) ||0 == count( $link_category ) || !is_array( $link_category ) ) {
22957 $link_category = array( get_option( 'default_link_category' ) );
22958 }
22959
22960 if ( $update ) {
22961 if ( false === $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_url = %s,
22962 link_name = %s, link_image = %s, link_target = %s,
22963 link_visible = %s, link_description = %s, link_rating = %s,
22964 link_rel = %s, link_notes = %s, link_rss = %s
22965 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 ) ) ) {
22966 if ( $wp_error )
22967 return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), $wpdb->last_error );
22968 else
22969 return 0;
22970 }
22971 } else {
22972 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)",
22973 $link_url,$link_name, $link_image, $link_target, $link_description, $link_visible, $link_owner, $link_rating, $link_rel, $link_notes, $link_rss ) ) ) {
22974 if ( $wp_error )
22975 return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), $wpdb->last_error );
22976 else
22977 return 0;
22978 }
22979 $link_id = (int) $wpdb->insert_id;
22980 }
22981
22982 wp_set_link_cats( $link_id, $link_category );
22983
22984 if ( $update )
22985 do_action( 'edit_link', $link_id );
22986 else
22987 do_action( 'add_link', $link_id );
22988
22989 clean_bookmark_cache( $link_id );
22990
22991 return $link_id;
22992 }
22993
22994 /**
22995 * {@internal Missing Short Description}}
22996 *
22997 * @since unknown
22998 *
22999 * @param unknown_type $link_id
23000 * @param unknown_type $link_categories
23001 */
23002 function wp_set_link_cats( $link_id = 0, $link_categories = array() ) {
23003 // If $link_categories isn't already an array, make it one:
23004 if ( !is_array( $link_categories ) || 0 == count( $link_categories ) )
23005 $link_categories = array( get_option( 'default_link_category' ) );
23006
23007 $link_categories = array_map( 'intval', $link_categories );
23008 $link_categories = array_unique( $link_categories );
23009
23010 wp_set_object_terms( $link_id, $link_categories, 'link_category' );
23011
23012 clean_bookmark_cache( $link_id );
23013 } // wp_set_link_cats()
23014
23015 /**
23016 * {@internal Missing Short Description}}
23017 *
23018 * @since unknown
23019 *
23020 * @param unknown_type $linkdata
23021 * @return unknown
23022 */
23023 function wp_update_link( $linkdata ) {
23024 $link_id = (int) $linkdata['link_id'];
23025
23026 $link = get_link( $link_id, ARRAY_A );
23027
23028 // Escape data pulled from DB.
23029 $link = add_magic_quotes( $link );
23030
23031 // Passed link category list overwrites existing category list if not empty.
23032 if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] )
23033 && 0 != count( $linkdata['link_category'] ) )
23034 $link_cats = $linkdata['link_category'];
23035 else
23036 $link_cats = $link['link_category'];
23037
23038 // Merge old and new fields with new fields overwriting old ones.
23039 $linkdata = array_merge( $link, $linkdata );
23040 $linkdata['link_category'] = $link_cats;
23041
23042 return wp_insert_link( $linkdata );
23043 }
23044
23045 ?>