/** * get_bookmarks() - Retrieves the list of bookmarks * * <p>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. * * <p>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 * @uses $wpdb Database Object * @param string|array $args List of arguments to overwrite the defaults * @return array List of bookmark row objects */ public Array<Object> get_bookmarks(Object args) { Array<Object> defaults = new Array<Object>(); Array<Object> r = null; String key = null; Array<Object> cache = new Array<Object>(); String inclusions = null; String include = null; String exclude = null; String category = null; String category_name = null; Array<Object> inclinks = new Array<Object>(); Object inclink = null; String exclusions = null; Array<Object> exlinks = new Array<Object>(); Object exlink = null; String search = null; String category_query = null; String join = null; Array<Object> incategories = new Array<Object>(); Object incat = null; String recently_updated_test = null; String get_updated = null; Object show_updated = null; String orderby = null; String length = null; String visible = null; Object hide_invisible = null; String query = null; Object order = null; Object limit = null; Array<Object> results = new Array<Object>(); defaults = new Array<Object>( new ArrayEntry<Object>("orderby", "name"), new ArrayEntry<Object>("order", "ASC"), new ArrayEntry<Object>("limit", -1), new ArrayEntry<Object>("category", ""), new ArrayEntry<Object>("category_name", ""), new ArrayEntry<Object>("hide_invisible", 1), new ArrayEntry<Object>("show_updated", 0), new ArrayEntry<Object>("include", ""), new ArrayEntry<Object>("exclude", ""), new ArrayEntry<Object>("search", "")); r = getIncluded(FunctionsPage.class, gVars, gConsts).wp_parse_args(args, defaults); include = strval(Array.extractVar(r, "include", include, Array.EXTR_SKIP)); exclude = strval(Array.extractVar(r, "exclude", exclude, Array.EXTR_SKIP)); category = strval(Array.extractVar(r, "category", category, Array.EXTR_SKIP)); category_name = strval(Array.extractVar(r, "category_name", category_name, Array.EXTR_SKIP)); search = strval(Array.extractVar(r, "search", search, Array.EXTR_SKIP)); show_updated = Array.extractVar(r, "show_updated", show_updated, Array.EXTR_SKIP); orderby = strval(Array.extractVar(r, "orderby", orderby, Array.EXTR_SKIP)); hide_invisible = Array.extractVar(r, "hide_invisible", hide_invisible, Array.EXTR_SKIP); order = Array.extractVar(r, "order", order, Array.EXTR_SKIP); limit = Array.extractVar(r, "limit", limit, Array.EXTR_SKIP); key = Strings.md5(serialize(r)); if (booleanval( cache = (Array<Object>) getIncluded(CachePage.class, gVars, gConsts) .wp_cache_get("get_bookmarks", "bookmark"))) { if (isset(cache.getValue(key))) { return (Array<Object>) getIncluded(PluginPage.class, gVars, gConsts) .apply_filters("get_bookmarks", cache.getValue(key), r); } } else { cache = new Array<Object>(); } inclusions = ""; if (!empty(include)) { exclude = ""; // ignore exclude, category, and category_name params if using include category = ""; category_name = ""; inclinks = QRegExPerl.preg_split("/[\\s,]+/", include); if (booleanval(Array.count(inclinks))) { for (Map.Entry javaEntry380 : inclinks.entrySet()) { inclink = javaEntry380.getValue(); if (empty(inclusions)) { inclusions = " AND ( link_id = " + strval(inclink) + " "; } else { inclusions = inclusions + " OR link_id = " + strval(inclink) + " "; } } } } if (!empty(inclusions)) { inclusions = inclusions + ")"; } exclusions = ""; if (!empty(exclude)) { exlinks = QRegExPerl.preg_split("/[\\s,]+/", exclude); if (booleanval(Array.count(exlinks))) { for (Map.Entry javaEntry381 : exlinks.entrySet()) { exlink = javaEntry381.getValue(); if (empty(exclusions)) { exclusions = " AND ( link_id <> " + strval(exlink) + " "; } else { exclusions = exclusions + " AND link_id <> " + strval(exlink) + " "; } } } } if (!empty(exclusions)) { exclusions = exclusions + ")"; } if (!empty(category_name)) { StdClass categoryObj; if (booleanval( categoryObj = (StdClass) getIncluded(TaxonomyPage.class, gVars, gConsts) .get_term_by( "name", category_name, "link_category", gConsts.getOBJECT(), "raw"))) { category = strval(StdClass.getValue(categoryObj, "term_id")); } } if (!empty(search)) { search = getIncluded(FormattingPage.class, gVars, gConsts).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 = QRegExPerl.preg_split("/[\\s,]+/", category); if (booleanval(Array.count(incategories))) { for (Map.Entry javaEntry382 : incategories.entrySet()) { incat = javaEntry382.getValue(); if (empty(category_query)) { category_query = " AND ( tt.term_id = " + strval(incat) + " "; } else { category_query = category_query + " OR tt.term_id = " + strval(incat) + " "; } } } } if (!empty(category_query)) { category_query = category_query + ") AND taxonomy = \'link_category\'"; join = " INNER JOIN " + gVars.wpdb.term_relationships + " AS tr ON (" + gVars.wpdb.links + ".link_id = tr.object_id) INNER JOIN " + gVars.wpdb.term_taxonomy + " as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id"; } if (booleanval( getIncluded(FunctionsPage.class, gVars, gConsts) .get_option("links_recently_updated_time"))) { recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL " + getIncluded(FunctionsPage.class, gVars, gConsts) .get_option("links_recently_updated_time") + " MINUTE) >= NOW(), 1,0) as recently_updated "; } else { recently_updated_test = ""; } get_updated = (booleanval(show_updated) ? ", UNIX_TIMESTAMP(link_updated) AS link_updated_f " : ""); orderby = Strings.strtolower(orderby); length = ""; { int javaSwitchSelector38 = 0; if (equal(orderby, "length")) { javaSwitchSelector38 = 1; } if (equal(orderby, "rand")) { javaSwitchSelector38 = 2; } switch (javaSwitchSelector38) { case 1: { length = ", CHAR_LENGTH(link_name) AS length"; break; } case 2: { orderby = "rand()"; break; } default: orderby = "link_" + orderby; } } if (equal("link_id", orderby)) { orderby = gVars.wpdb.links + ".link_id"; } visible = ""; if (booleanval(hide_invisible)) { visible = "AND link_visible = \'Y\'"; } query = "SELECT * " + length + " " + recently_updated_test + " " + get_updated + " FROM " + gVars.wpdb.links + " " + join + " WHERE 1=1 " + visible + " " + category_query; query = query + " " + exclusions + " " + inclusions + " " + search; query = query + " ORDER BY " + orderby + " " + strval(order); if (!equal(limit, -1)) { query = query + " LIMIT " + strval(limit); } results = gVars.wpdb.get_results(query); cache.putValue(key, results); getIncluded(CachePage.class, gVars, gConsts) .wp_cache_set("get_bookmarks", cache, "bookmark", 0); return (Array<Object>) getIncluded(PluginPage.class, gVars, gConsts).apply_filters("get_bookmarks", results, r); }