Make WordPress Core


Ignore:
Timestamp:
08/17/2007 09:22:37 PM (18 years ago)
Author:
ryan
Message:

First cut of taxonomy API phpdoc from darkdragon. see #4742

File:
1 edited

Legend:

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

    r5879 r5896  
    11<?php
    22
    3 function get_bookmark($bookmark_id, $output = OBJECT) {
     3function get_bookmark($bookmark_id, $output = OBJECT, $filter = 'raw') {
    44    global $wpdb;
    55
     
    88    $link->link_category = wp_get_link_cats($bookmark_id);
    99
     10    $link = sanitize_bookmark($link, $filter);
     11   
    1012    if ( $output == OBJECT ) {
    1113        return $link;
     
    143145}
    144146
     147function sanitize_bookmark($bookmark, $context = 'display') {
     148    $fields = array('link_id', 'link_url', 'link_name', 'link_image', 'link_target', 'link_category',
     149        'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_updated',
     150        'link_rel', 'link_', 'link_notes', 'link_rss', );
     151
     152    $do_object = false;
     153    if ( is_object($bookmark) )
     154        $do_object = true;
     155
     156    foreach ( $fields as $field ) {
     157        if ( $do_object )
     158            $bookmark->$field = sanitize_bookmark_field($field, $bookmark->$field, $bookmark->link_id, $context);
     159        else
     160            $bookmark[$field] = sanitize_bookmark_field($field, $bookmark[$field], $bookmark['link_id'], $context);
     161    }
     162
     163    return $bookmark;
     164}
     165
     166function sanitize_bookmark_field($field, $value, $bookmark_id, $context) {
     167    $int_fields = array('ID', 'bookmark_parent', 'menu_order');
     168    if ( in_array($field, $int_fields) )
     169        $value = (int) $value;
     170
     171    if ( 'raw' == $context )
     172        return $value;
     173
     174    $prefixed = false;
     175    if ( false !== strpos($field, 'bookmark_') ) {
     176        $prefixed = true;
     177        $field_no_prefix = str_replace('bookmark_', '', $field);
     178    }
     179
     180    if ( 'edit' == $context ) {
     181        $format_to_edit = array('bookmark_content', 'bookmark_excerpt', 'bookmark_title', 'bookmark_password');
     182
     183        if ( $prefixed ) {
     184            $value = apply_filters("edit_$field", $value, $bookmark_id);
     185            // Old school
     186            $value = apply_filters("${field_no_prefix}_edit_pre", $value, $bookmark_id);
     187        } else {
     188            $value = apply_filters("edit_bookmark_$field", $value, $bookmark_id);
     189        }
     190
     191        if ( in_array($field, $format_to_edit) ) {
     192            if ( 'bookmark_content' == $field )
     193                $value = format_to_edit($value, user_can_richedit());
     194            else
     195                $value = format_to_edit($value);
     196        } else {
     197            $value = attribute_escape($value);
     198        }
     199    } else if ( 'db' == $context ) {
     200        if ( $prefixed ) {
     201            $value = apply_filters("pre_$field", $value);
     202            $value = apply_filters("${field_no_prefix}_save_pre", $value);
     203        } else {
     204            $value = apply_filters("pre_bookmark_$field", $value);
     205            $value = apply_filters("${field}_pre", $value);
     206        }
     207    } else {
     208        // Use display filters by default.
     209        $value = apply_filters("bookmark_$field", $value, $bookmark_id, $context);
     210    }
     211
     212    if ( 'attribute' == $context )
     213        $value = attribute_escape($value);
     214    else if ( 'js' == $context )
     215        $value = js_escape($value);
     216
     217    return $value;
     218}
     219
    145220function delete_get_bookmark_cache() {
    146221    wp_cache_delete( 'get_bookmarks', 'bookmark' );
Note: See TracChangeset for help on using the changeset viewer.