function ubik_links() { // Initialize $links = $category = $search = ''; $links_array = array(); // Private links can only be seen by users with the manage_links capability $hide_invisible = current_user_can('manage_links') ? 0 : 1; // Get the link category from the query string if (get_query_var('link_category')) { $category = get_query_var('link_category'); } // Link search; also works with categories if (get_query_var('link_search')) { $search = get_query_var('link_search'); } // Fetch the bookmarks $links = get_bookmarks(array('orderby' => apply_filters('ubik_links_orderby', 'link_id'), 'order' => apply_filters('ubik_links_order', 'DESC'), 'category_name' => $category, 'hide_invisible' => $hide_invisible, 'search' => esc_sql($search), 'limit' => -1)); // Check for results then run through the loop if (!empty($links)) { foreach ($links as $link) { // Initialize all variables $title = $desc = $url = $rel = $target = $updated = $cats = $cats_formatted = ''; // Conditionally set relevant variables if (!empty($link->link_id)) { $id = $link->link_id; } if (!empty($link->link_name)) { $title = $link->link_name; } if (!empty($link->link_description)) { $desc = $link->link_description; } if (!empty($link->link_url)) { $url = $link->link_url; $domain = parse_url($url); $domain = $domain['host']; } if (!empty($link->link_rel)) { $rel = ' rel="' . $link->link_rel . '"'; } if (!empty($link->link_target)) { $target = ' target="' . $link->link_target . '"'; } // Link categories if (!empty($id)) { $cats = ubik_links_categories($id); } // Assemble the links array; this returns the raw data as well as processed strings $links_array[] = array('id' => $id, 'title' => $title, 'description' => $desc, 'url' => $url, 'domain' => $domain, 'rel' => $rel, 'target' => $target, 'cats' => $cats, 'cats_html' => implode(', ', $cats), 'cats_list' => ubik_links_categories_list($cats), 'link' => '<a href="' . $url . '"' . $rel . $target . '>' . $title . '</a>'); } } return apply_filters('ubik_links', $links_array); }
function ubik_links_sidebar($sidebar) { if (is_page_template(UBIK_LINKS_PAGE_TEMPLATE)) { // Retrieve the list of all categories $cats = ubik_links_categories(); // Add the links page template to the bottom of the list (relies on `get_permalink`) $cats[] = '<strong><a class="link-category" href="' . get_permalink() . '">' . __('All links', 'ubik') . '</a></strong>'; $cats = ubik_links_categories_list($cats); // Output the links sidebar $sidebar = '<aside id="ubik-links-search-widget" class="widget widget-links-search"><h2>' . __('Search links', 'ubik') . '</h2>' . ubik_links_search_form() . '</aside>'; // A list of link categories if (!empty($cats)) { $sidebar .= '<aside id="ubik-links-categories-widget" class="widget widget-links-categories"><h2>' . __('Link categories', 'ubik') . '</h2>' . $cats . '</aside>'; } } return $sidebar; }