/** * Author Template functions for use in themes. * * These functions must be used within the WordPress Loop. * * @link http://codex.wordpress.org/Author_Templates * * @package WordPress * @subpackage Template */ /** * Retrieve the author of the current post. * * @since 1.5 * @uses $authordata The current author's DB object. * @uses apply_filters() Calls 'the_author' hook on the author display name. * * @param string $deprecated Deprecated. * @return string The author's display name. */ function get_the_author($deprecated = '') { global $authordata; if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.1' ); return apply_filters('the_author', is_object($authordata) ? $authordata->display_name : null); } /** * Display the name of the author of the current post. * * The behavior of this function is based off of old functionality predating * get_the_author(). This function is not deprecated, but is designed to echo * the value from get_the_author() and as an result of any old theme that might * still use the old behavior will also pass the value from get_the_author(). * * The normal, expected behavior of this function is to echo the author and not * return it. However, backwards compatiability has to be maintained. * * @since 0.71 * @see get_the_author() * @link http://codex.wordpress.org/Template_Tags/the_author * * @param string $deprecated Deprecated. * @param string $deprecated_echo Deprecated. Use get_the_author(). Echo the string or return it. * @return string The author's display name, from get_the_author(). */ function the_author( $deprecated = '', $deprecated_echo = true ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.1' ); if ( $deprecated_echo !== true ) _deprecated_argument( __FUNCTION__, '1.5', __('Use get_the_author() instead if you do not want the value echoed.') ); if ( $deprecated_echo ) echo get_the_author(); return get_the_author(); } /** * Retrieve the author who last edited the current post. * * @since 2.8 * @uses $post The current post's DB object. * @uses get_post_meta() Retrieves the ID of the author who last edited the current post. * @uses get_userdata() Retrieves the author's DB object. * @uses apply_filters() Calls 'the_modified_author' hook on the author display name. * @return string The author's display name. */ function get_the_modified_author() { global $post; if ( $last_id = get_post_meta($post->ID, '_edit_last', true) ) { $last_user = get_userdata($last_id); return apply_filters('the_modified_author', $last_user->display_name); } } /** * Display the name of the author who last edited the current post. * * @since 2.8 * @see get_the_author() * @return string The author's display name, from get_the_modified_author(). */ function the_modified_author() { echo get_the_modified_author(); } /** * Retrieve the requested data of the author of the current post. * @link http://codex.wordpress.org/Template_Tags/the_author_meta * @since 2.8.0 * @uses $authordata The current author's DB object (if $user_id not specified). * @param string $field selects the field of the users record. * @param int $user_id Optional. User ID. * @return string The author's field from the current author's DB object. */ function get_the_author_meta($field = '', $user_id = false) { if ( ! $user_id ) global $authordata; else $authordata = get_userdata( $user_id ); $field = strtolower($field); $user_field = "user_$field"; if ( 'id' == $field ) $value = isset($authordata->ID) ? (int)$authordata->ID : 0; elseif ( isset($authordata->$user_field) ) $value = $authordata->$user_field; else $value = isset($authordata->$field) ? $authordata->$field : ''; return apply_filters('get_the_author_' . $field, $value, $user_id); } /** * Retrieve the requested data of the author of the current post. * @link http://codex.wordpress.org/Template_Tags/the_author_meta * @since 2.8.0 * @param string $field selects the field of the users record. * @param int $user_id Optional. User ID. * @echo string The author's field from the current author's DB object. */ function the_author_meta($field = '', $user_id = false) { echo apply_filters('the_author_' . $field, get_the_author_meta($field, $user_id), $user_id); } /** * Retrieve either author's link or author's name. * * If the author has a home page set, return an HTML link, otherwise just return the * author's name. * * @uses get_the_author_meta() * @uses get_the_author() */ function get_the_author_link() { if ( get_the_author_meta('url') ) { return '' . get_the_author() . ''; } else { return get_the_author(); } } /** * Display either author's link or author's name. * * If the author has a home page set, echo an HTML link, otherwise just echo the * author's name. * * @link http://codex.wordpress.org/Template_Tags/the_author_link * @since 2.1 * @uses get_the_author_link() */ function the_author_link() { echo get_the_author_link(); } /** * Retrieve the number of posts by the author of the current post. * * @since 1.5 * @uses $post The current post in the Loop's DB object. * @uses count_user_posts() * @return int The number of posts by the author. */ function get_the_author_posts() { global $post; return count_user_posts($post->post_author); } /** * Display the number of posts by the author of the current post. * * @link http://codex.wordpress.org/Template_Tags/the_author_posts * @since 0.71 * @uses get_the_author_posts() Echoes returned value from function. */ function the_author_posts() { echo get_the_author_posts(); } /** * Display an HTML link to the author page of the author of the current post. * * Does just echo get_author_posts_url() function, like the others do. The * reason for this, is that another function is used to help in printing the * link to the author's posts. * * @link http://codex.wordpress.org/Template_Tags/the_author_posts_link * @since 1.2.0 * @uses $authordata The current author's DB object. * @uses get_author_posts_url() * @uses get_the_author() * @param string $deprecated Deprecated. */ function the_author_posts_link($deprecated = '') { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.1' ); global $authordata; $link = sprintf( '%3$s', get_author_posts_url( $authordata->ID, $authordata->user_nicename ), esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ), get_the_author() ); echo apply_filters( 'the_author_posts_link', $link ); } /** * Retrieve the URL to the author page of the author of the current post. * * @since 2.1.0 * @uses $wp_rewrite WP_Rewrite * @return string The URL to the author's page. */ function get_author_posts_url($author_id, $author_nicename = '') { global $wp_rewrite; $auth_ID = (int) $author_id; $link = $wp_rewrite->get_author_permastruct(); if ( empty($link) ) { $file = home_url() . '/'; $link = $file . '?author=' . $auth_ID; } else { if ( '' == $author_nicename ) { $user = get_userdata($author_id); if ( !empty($user->user_nicename) ) $author_nicename = $user->user_nicename; } $link = str_replace('%author%', $author_nicename, $link); $link = home_url() . trailingslashit($link); } $link = apply_filters('author_link', $link, $author_id, $author_nicename); return $link; } /** * List all the authors of the blog, with several options available. * * * * @link http://codex.wordpress.org/Template_Tags/wp_list_authors * @since 1.2.0 * @param array $args The argument array. * @return null|string The output, if echo is set to false. */ function wp_list_authors($args = '') { global $wpdb; $defaults = array( 'optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true ); $r = wp_parse_args( $args, $defaults ); extract($r, EXTR_SKIP); $return = ''; /** @todo Move select to get_authors(). */ $users = get_users_of_blog(); $author_ids = array(); foreach ( (array) $users as $user ) $author_ids[] = $user->user_id; if ( count($author_ids) > 0 ) { $author_ids = implode(',', $author_ids ); $authors = $wpdb->get_results( "SELECT ID, user_nicename from $wpdb->users WHERE ID IN($author_ids) " . ($exclude_admin ? "AND user_login <> 'admin' " : '') . "ORDER BY display_name" ); } else { $authors = array(); } $author_count = array(); foreach ( (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row ) $author_count[$row->post_author] = $row->count; foreach ( (array) $authors as $author ) { $link = ''; $author = get_userdata( $author->ID ); $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; $name = $author->display_name; if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) $name = "$author->first_name $author->last_name"; if( !$html ) { if ( $posts == 0 ) { if ( ! $hide_empty ) $return .= $name . ', '; } else $return .= $name . ', '; // No need to go further to process HTML. continue; } if ( !($posts == 0 && $hide_empty) && 'list' == $style ) $return .= '
  • '; if ( $posts == 0 ) { if ( ! $hide_empty ) $link = $name; } else { $link = 'display_name) ) . '">' . $name . ''; if ( (! empty($feed_image)) || (! empty($feed)) ) { $link .= ' '; if (empty($feed_image)) $link .= '('; $link .= ''; else $link .= $name; $link .= ''; if ( empty($feed_image) ) $link .= ')'; } if ( $optioncount ) $link .= ' ('. $posts . ')'; } if ( $posts || ! $hide_empty ) $return .= $link . ( ( 'list' == $style ) ? '
  • ' : ', ' ); } $return = trim($return, ', '); if ( ! $echo ) return $return; echo $return; } ?> /** * Link/Bookmark API * * @package WordPress * @subpackage Bookmark */ /** * Retrieve Bookmark data based on ID * * @since 2.1.0 * @uses $wpdb Database Object * * @param int $bookmark_id * @param string $output Optional. Either OBJECT, ARRAY_N, or ARRAY_A constant * @param string $filter Optional, default is 'raw'. * @return array|object Type returned depends on $output value. */ function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') { global $wpdb; if ( empty($bookmark) ) { if ( isset($GLOBALS['link']) ) $_bookmark = & $GLOBALS['link']; else $_bookmark = null; } elseif ( is_object($bookmark) ) { wp_cache_add($bookmark->link_id, $bookmark, 'bookmark'); $_bookmark = $bookmark; } else { if ( isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $bookmark) ) { $_bookmark = & $GLOBALS['link']; } elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark') ) { $_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark)); $_bookmark->link_category = array_unique( wp_get_object_terms($_bookmark->link_id, 'link_category', array('fields' => 'ids')) ); wp_cache_add($_bookmark->link_id, $_bookmark, 'bookmark'); } } $_bookmark = sanitize_bookmark($_bookmark, $filter); if ( $output == OBJECT ) { return $_bookmark; } elseif ( $output == ARRAY_A ) { return get_object_vars($_bookmark); } elseif ( $output == ARRAY_N ) { return array_values(get_object_vars($_bookmark)); } else { return $_bookmark; } } /** * Retrieve single bookmark data item or field. * * @since 2.3.0 * @uses get_bookmark() Gets bookmark object using $bookmark as ID * @uses sanitize_bookmark_field() Sanitizes Bookmark field based on $context. * * @param string $field The name of the data field to return * @param int $bookmark The bookmark ID to get field * @param string $context Optional. The context of how the field will be used. * @return string */ function get_bookmark_field( $field, $bookmark, $context = 'display' ) { $bookmark = (int) $bookmark; $bookmark = get_bookmark( $bookmark ); if ( is_wp_error($bookmark) ) return $bookmark; if ( !is_object($bookmark) ) return ''; if ( !isset($bookmark->$field) ) return ''; return sanitize_bookmark_field($field, $bookmark->$field, $bookmark->link_id, $context); } /** * Retrieves the list of bookmarks * * Attempts to retrieve from the cache first based on MD5 hash of arguments. If * that fails, then the query will be built from the arguments and executed. The * results will be stored to the cache. * * List of default arguments are as follows: * 'orderby' - Default is 'name' (string). How to order the links by. String is * based off of the bookmark scheme. * 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either * ascending or descending order. * 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to * display. * 'category' - Default is empty string (string). Include the links in what * category ID(s). * 'category_name' - Default is empty string (string). Get links by category * name. * 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide * links marked as 'invisible'. * 'show_updated' - Default is 0 (integer). Will show the time of when the * bookmark was last updated. * 'include' - Default is empty string (string). Include other categories * separated by commas. * 'exclude' - Default is empty string (string). Exclude other categories * separated by commas. * * @since 2.1.0 * @uses $wpdb Database Object * @link http://codex.wordpress.org/Template_Tags/get_bookmarks * * @param string|array $args List of arguments to overwrite the defaults * @return array List of bookmark row objects */ function get_bookmarks($args = '') { global $wpdb; $defaults = array( 'orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '', 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '', 'search' => '' ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $cache = array(); $key = md5( serialize( $r ) ); if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) { if ( is_array($cache) && isset( $cache[ $key ] ) ) return apply_filters('get_bookmarks', $cache[ $key ], $r ); } if ( !is_array($cache) ) $cache = array(); $inclusions = ''; if ( !empty($include) ) { $exclude = ''; //ignore exclude, category, and category_name params if using include $category = ''; $category_name = ''; $inclinks = preg_split('/[\s,]+/',$include); if ( count($inclinks) ) { foreach ( $inclinks as $inclink ) { if (empty($inclusions)) $inclusions = ' AND ( link_id = ' . intval($inclink) . ' '; else $inclusions .= ' OR link_id = ' . intval($inclink) . ' '; } } } if (!empty($inclusions)) $inclusions .= ')'; $exclusions = ''; if ( !empty($exclude) ) { $exlinks = preg_split('/[\s,]+/',$exclude); if ( count($exlinks) ) { foreach ( $exlinks as $exlink ) { if (empty($exclusions)) $exclusions = ' AND ( link_id <> ' . intval($exlink) . ' '; else $exclusions .= ' AND link_id <> ' . intval($exlink) . ' '; } } } if (!empty($exclusions)) $exclusions .= ')'; if ( !empty($category_name) ) { if ( $category = get_term_by('name', $category_name, 'link_category') ) { $category = $category->term_id; } else { $cache[ $key ] = array(); wp_cache_set( 'get_bookmarks', $cache, 'bookmark' ); return apply_filters( 'get_bookmarks', array(), $r ); } } if ( ! empty($search) ) { $search = like_escape($search); $search = " AND ( (link_url LIKE '%$search%') OR (link_name LIKE '%$search%') OR (link_description LIKE '%$search%') ) "; } $category_query = ''; $join = ''; if ( !empty($category) ) { $incategories = preg_split('/[\s,]+/',$category); if ( count($incategories) ) { foreach ( $incategories as $incat ) { if (empty($category_query)) $category_query = ' AND ( tt.term_id = ' . intval($incat) . ' '; else $category_query .= ' OR tt.term_id = ' . intval($incat) . ' '; } } } if (!empty($category_query)) { $category_query .= ") AND taxonomy = 'link_category'"; $join = " INNER JOIN $wpdb->term_relationships AS tr ON ($wpdb->links.link_id = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id"; } if ( $show_updated && get_option('links_recently_updated_time') ) { $recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL " . get_option('links_recently_updated_time') . " MINUTE) >= NOW(), 1,0) as recently_updated "; } else { $recently_updated_test = ''; } $get_updated = ( $show_updated ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : ''; $orderby = strtolower($orderby); $length = ''; switch ($orderby) { case 'length': $length = ", CHAR_LENGTH(link_name) AS length"; break; case 'rand': $orderby = 'rand()'; break; default: $orderparams = array(); foreach ( explode(',', $orderby) as $ordparam ) $orderparams[] = 'link_' . trim($ordparam); $orderby = implode(',', $orderparams); } if ( 'link_id' == $orderby ) $orderby = "$wpdb->links.link_id"; $visible = ''; if ( $hide_invisible ) $visible = "AND link_visible = 'Y'"; $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query"; $query .= " $exclusions $inclusions $search"; $query .= " ORDER BY $orderby $order"; if ($limit != -1) $query .= " LIMIT $limit"; $results = $wpdb->get_results($query); $cache[ $key ] = $results; wp_cache_set( 'get_bookmarks', $cache, 'bookmark' ); return apply_filters('get_bookmarks', $results, $r); } /** * Sanitizes all bookmark fields * * @since 2.3.0 * * @param object|array $bookmark Bookmark row * @param string $context Optional, default is 'display'. How to filter the * fields * @return object|array Same type as $bookmark but with fields sanitized. */ function sanitize_bookmark($bookmark, $context = 'display') { $fields = array('link_id', 'link_url', 'link_name', 'link_image', 'link_target', 'link_category', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_updated', 'link_rel', 'link_notes', 'link_rss', ); if ( is_object($bookmark) ) { $do_object = true; $link_id = $bookmark->link_id; } else { $do_object = false; $link_id = $bookmark['link_id']; } foreach ( $fields as $field ) { if ( $do_object ) { if ( isset($bookmark->$field) ) $bookmark->$field = sanitize_bookmark_field($field, $bookmark->$field, $link_id, $context); } else { if ( isset($bookmark[$field]) ) $bookmark[$field] = sanitize_bookmark_field($field, $bookmark[$field], $link_id, $context); } } return $bookmark; } /** * Sanitizes a bookmark field * * Sanitizes the bookmark fields based on what the field name is. If the field * has a strict value set, then it will be tested for that, else a more generic * filtering is applied. After the more strict filter is applied, if the * $context is 'raw' then the value is immediately return. * * Hooks exist for the more generic cases. With the 'edit' context, the * 'edit_$field' filter will be called and passed the $value and $bookmark_id * respectively. With the 'db' context, the 'pre_$field' filter is called and * passed the value. The 'display' context is the final context and has the * $field has the filter name and is passed the $value, $bookmark_id, and * $context respectively. * * @since 2.3.0 * * @param string $field The bookmark field * @param mixed $value The bookmark field value * @param int $bookmark_id Bookmark ID * @param string $context How to filter the field value. Either 'raw', 'edit', * 'attribute', 'js', 'db', or 'display' * @return mixed The filtered value */ function sanitize_bookmark_field($field, $value, $bookmark_id, $context) { switch ( $field ) { case 'link_id' : // ints case 'link_rating' : $value = (int) $value; break; case 'link_category' : // array( ints ) $value = array_map('absint', (array) $value); // We return here so that the categories aren't filtered. // The 'link_category' filter is for the name of a link category, not an array of a link's link categories return $value; break; case 'link_visible' : // bool stored as Y|N $value = preg_replace('/[^YNyn]/', '', $value); break; case 'link_target' : // "enum" $targets = array('_top', '_blank'); if ( ! in_array($value, $targets) ) $value = ''; break; } if ( 'raw' == $context ) return $value; if ( 'edit' == $context ) { $format_to_edit = array('link_notes'); $value = apply_filters("edit_$field", $value, $bookmark_id); if ( in_array($field, $format_to_edit) ) { $value = format_to_edit($value); } else { $value = esc_attr($value); } } else if ( 'db' == $context ) { $value = apply_filters("pre_$field", $value); } else { // Use display filters by default. $value = apply_filters($field, $value, $bookmark_id, $context); if ( 'attribute' == $context ) $value = esc_attr($value); else if ( 'js' == $context ) $value = esc_js($value); } return $value; } /** * Deletes bookmark cache * * @since 2.7.0 * @uses wp_cache_delete() Deletes the contents of 'get_bookmarks' */ function clean_bookmark_cache($bookmark_id) { wp_cache_delete( $bookmark_id, 'bookmark' ); wp_cache_delete( 'get_bookmarks', 'bookmark' ); } ?> /** * Bookmark Template Functions for usage in Themes * * @package WordPress * @subpackage Template */ /** * The formatted output of a list of bookmarks. * * The $bookmarks array must contain bookmark objects and will be iterated over * to retrieve the bookmark to be used in the output. * * The output is formatted as HTML with no way to change that format. However, * what is between, before, and after can be changed. The link itself will be * HTML. * * This function is used internally by wp_list_bookmarks() and should not be * used by themes. * * The defaults for overwriting are: * 'show_updated' - Default is 0 (integer). Will show the time of when the * bookmark was last updated. * 'show_description' - Default is 0 (integer). Whether to show the description * of the bookmark. * 'show_images' - Default is 1 (integer). Whether to show link image if * available. * 'show_name' - Default is 0 (integer). Whether to show link name if * available. * 'before' - Default is '
  • ' (string). The html or text to prepend to each * bookmarks. * 'after' - Default is '
  • ' (string). The html or text to append to each * bookmarks. * 'link_before' - Default is '' (string). The html or text to prepend to each * bookmarks inside the tag. * 'link_after' - Default is '' (string). The html or text to append to each * bookmarks inside the tag. * 'between' - Default is '\n' (string). The string for use in between the link, * description, and image. * 'show_rating' - Default is 0 (integer). Whether to show the link rating. * * @since 2.1.0 * @access private * @usedby wp_list_bookmarks() * * @param array $bookmarks List of bookmarks to traverse * @param string|array $args Optional. Overwrite the defaults. * @return string Formatted output in HTML */ function _walk_bookmarks($bookmarks, $args = '' ) { $defaults = array( 'show_updated' => 0, 'show_description' => 0, 'show_images' => 1, 'show_name' => 0, 'before' => '
  • ', 'after' => '
  • ', 'between' => "\n", 'show_rating' => 0, 'link_before' => '', 'link_after' => '' ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $output = ''; // Blank string to start with. foreach ( (array) $bookmarks as $bookmark ) { if ( !isset($bookmark->recently_updated) ) $bookmark->recently_updated = false; $output .= $before; if ( $show_updated && $bookmark->recently_updated ) $output .= get_option('links_recently_updated_prepend'); $the_link = '#'; if ( !empty($bookmark->link_url) ) $the_link = esc_url($bookmark->link_url); $desc = esc_attr(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display')); $name = esc_attr(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display')); $title = $desc; if ( $show_updated ) if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) { $title .= ' ('; $title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * 3600))); $title .= ')'; } $alt = ' alt="' . $name . ( $show_description ? ' ' . $title : '' ) . '"'; if ( '' != $title ) $title = ' title="' . $title . '"'; $rel = $bookmark->link_rel; if ( '' != $rel ) $rel = ' rel="' . esc_attr($rel) . '"'; $target = $bookmark->link_target; if ( '' != $target ) $target = ' target="' . $target . '"'; $output .= '
    '; $output .= $link_before; if ( $bookmark->link_image != null && $show_images ) { if ( strpos($bookmark->link_image, 'http') === 0 ) $output .= "link_image\" $alt $title />"; else // If it's a relative path $output .= "link_image\" $alt $title />"; if ( $show_name ) $output .= " $name"; } else { $output .= $name; } $output .= $link_after; $output .= ''; if ( $show_updated && $bookmark->recently_updated ) $output .= get_option('links_recently_updated_append'); if ( $show_description && '' != $desc ) $output .= $between . $desc; if ( $show_rating ) $output .= $between . sanitize_bookmark_field('link_rating', $bookmark->link_rating, $bookmark->link_id, 'display'); $output .= "$after\n"; } // end while return $output; } /** * Retrieve or echo all of the bookmarks. * * List of default arguments are as follows: * 'orderby' - Default is 'name' (string). How to order the links by. String is * based off of the bookmark scheme. * 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either * ascending or descending order. * 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to * display. * 'category' - Default is empty string (string). Include the links in what * category ID(s). * 'category_name' - Default is empty string (string). Get links by category * name. * 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide * links marked as 'invisible'. * 'show_updated' - Default is 0 (integer). Will show the time of when the * bookmark was last updated. * 'echo' - Default is 1 (integer). Whether to echo (default) or return the * formatted bookmarks. * 'categorize' - Default is 1 (integer). Whether to show links listed by * category (default) or show links in one column. * 'show_description' - Default is 0 (integer). Whether to show the description * of the bookmark. * * These options define how the Category name will appear before the category * links are displayed, if 'categorize' is 1. If 'categorize' is 0, then it will * display for only the 'title_li' string and only if 'title_li' is not empty. * 'title_li' - Default is 'Bookmarks' (translatable string). What to show * before the links appear. * 'title_before' - Default is '

    ' (string). The HTML or text to show before * the 'title_li' string. * 'title_after' - Default is '

    ' (string). The HTML or text to show after * the 'title_li' string. * 'class' - Default is 'linkcat' (string). The CSS class to use for the * 'title_li'. * * 'category_before' - Default is '
  • '. String must * contain '%id' and '%class' to get * the id of the category and the 'class' argument. These are used for * formatting in themes. * Argument will be displayed before the 'title_before' argument. * 'category_after' - Default is '
  • ' (string). The HTML or text that will * appear after the list of links. * * These are only used if 'categorize' is set to 1 or true. * 'category_orderby' - Default is 'name'. How to order the bookmark category * based on term scheme. * 'category_order' - Default is 'ASC'. Set the order by either ASC (ascending) * or DESC (descending). * * @see _walk_bookmarks() For other arguments that can be set in this function * and passed to _walk_bookmarks(). * @see get_bookmarks() For other arguments that can be set in this function and * passed to get_bookmarks(). * @link http://codex.wordpress.org/Template_Tags/wp_list_bookmarks * * @since 2.1.0 * @uses _list_bookmarks() Used to iterate over all of the bookmarks and return * the html * @uses get_terms() Gets all of the categories that are for links. * * @param string|array $args Optional. Overwrite the defaults of the function * @return string|null Will only return if echo option is set to not echo. * Default is not return anything. */ function wp_list_bookmarks($args = '') { $defaults = array( 'orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '', 'exclude_category' => '', 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'echo' => 1, 'categorize' => 1, 'title_li' => __('Bookmarks'), 'title_before' => '

    ', 'title_after' => '

    ', 'category_orderby' => 'name', 'category_order' => 'ASC', 'class' => 'linkcat', 'category_before' => '
  • ', 'category_after' => '
  • ' ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $output = ''; if ( $categorize ) { //Split the bookmarks into ul's for each category $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0)); foreach ( (array) $cats as $cat ) { $params = array_merge($r, array('category'=>$cat->term_id)); $bookmarks = get_bookmarks($params); if ( empty($bookmarks) ) continue; $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before); $catname = apply_filters( "link_category", $cat->name ); $output .= "$title_before$catname$title_after\n\t\n$category_after\n"; } } else { //output one single list using title_li for the title $bookmarks = get_bookmarks($r); if ( !empty($bookmarks) ) { if ( !empty( $title_li ) ){ $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before); $output .= "$title_before$title_li$title_after\n\t\n$category_after\n"; } else { $output .= _walk_bookmarks($bookmarks, $r); } } } $output = apply_filters( 'wp_list_bookmarks', $output ); if ( !$echo ) return $output; echo $output; } ?> An API for Drupal

    An API for Drupal

    My friend Kin Lane recently got me interested in RESTful APIs, and posed to me an interesting challenge. He asked if I could build out a secured RESTful API as a Drupal module. This ended up being a learning experience on many levels, but I am happy to announce its completion.

    In order to satisfy user needs, I built out two modules that provide interaction with the native object types of Pages and Articles that Drupal pre-defines. These modules each provide one of two dual layers of security that this project implements. The second layer will be discussed in a moment. I felt it important to, at the very least, provide a direct control mechanism at the application level for access to these powerful methods. To accomplish this I created a configuration screen that allows the site administrator to either enable or disable each function provided in the API.

    3scale logoThe second layer of security is established with the help of 3scale.net. A third module is included in this project; the purpose of this third module is establish connection resources to the 3scale.net services for the other depending modules. The 3scale.net services provide for analytic services as well as access control to APIs that subscribe to the 3scale.net services.

    These APIs establish straightforward CRUD functionality and leverages the fairly established REST integration practices. That is GET accomplishes the retrieval functionality, POST for create, PUT performs update, and DELETE obviously deletes.

    Once these modules are downloaded and installed, activation of the 3scale service is simply a matter of entering the provider id into the configuration page of the 3scale connector module.

    Share

    Comments on this entry are closed.