Ejemplo n.º 1
0
  /**
   * get_bookmark() - Get Bookmark data based on ID
   *
   * @since 2.1
   * @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.
   */
  public Object get_bookmark(Object bookmark_id, Object output, String filter) {
    StdClass link = null;
    link =
        (StdClass)
            gVars.wpdb.get_row(
                gVars.wpdb.prepare(
                    "SELECT * FROM " + gVars.wpdb.links + " WHERE link_id = %d LIMIT 1",
                    bookmark_id));
    link.fields.putValue(
        "link_category",
        Array.array_unique(
            (Array)
                getIncluded(TaxonomyPage.class, gVars, gConsts)
                    .wp_get_object_terms(
                        StdClass.getValue(link, "link_id"), "link_category", "fields=ids")));
    link = (StdClass) sanitize_bookmark(link, filter);

    if (equal(output, gConsts.getOBJECT())) {
      return link;
    } else if (equal(output, gConsts.getARRAY_A())) {
      return ClassHandling.get_object_vars(link);
    } else if (equal(output, gConsts.getARRAY_N())) {
      return Array.array_values(ClassHandling.get_object_vars(link));
    } else {
      return link;
    }
  }
Ejemplo n.º 2
0
  public boolean check_post_keyword(boolean precheck) {
    Object metakeys; /* Do not change type */
    int count = 0;
    StdClass post_meta = null;
    Array<String> post_keys = new Array<String>();
    String keyword = null;

    echo(gVars.webEnv, "<div class=\"narrow\">");
    echo(
        gVars.webEnv,
        "<p><h3>"
            + getIncluded(L10nPage.class, gVars, gConsts)
                .__("Reading Bunny&#8217;s Technorati Tags&#8230;", "default")
            + "</h3></p>");

    // import Bunny's Keywords tags
    metakeys =
        gVars.wpdb.get_results(
            "SELECT post_id, meta_id, meta_key, meta_value FROM "
                + gVars.wpdb.postmeta
                + " WHERE "
                + gVars.wpdb.postmeta
                + ".meta_key = \'tags\'");

    if (!is_array(metakeys)) {
      echo(
          gVars.webEnv,
          "<p>"
              + getIncluded(L10nPage.class, gVars, gConsts).__("No Tags Found!", "default")
              + "</p>");

      return false;
    } else {
      count = Array.count(metakeys);
      echo(
          gVars.webEnv,
          "<p>"
              + QStrings.sprintf(
                  getIncluded(L10nPage.class, gVars, gConsts)
                      .__ngettext(
                          "Done! <strong>%s</strong> post with tags were read.",
                          "Done! <strong>%s</strong> posts with tags were read.", count, "default"),
                  count)
              + "<br /></p>");
      echo(gVars.webEnv, "<ul>");

      for (Map.Entry javaEntry50 : ((Array<?>) metakeys).entrySet()) {
        post_meta = (StdClass) javaEntry50.getValue();

        if (!equal(StdClass.getValue(post_meta, "meta_value"), "")) {
          post_keys = Strings.explode(" ", strval(StdClass.getValue(post_meta, "meta_value")));

          for (Map.Entry javaEntry51 : post_keys.entrySet()) {
            keyword = strval(javaEntry51.getValue());
            keyword =
                Strings.addslashes(
                    gVars.webEnv, Strings.trim(Strings.str_replace("+", " ", keyword)));

            if (!equal("", keyword)) {
              echo(
                  gVars.webEnv,
                  "<li>"
                      + StdClass.getValue(post_meta, "post_id")
                      + "&nbsp;-&nbsp;"
                      + keyword
                      + "</li>");

              if (!precheck) {
                getIncluded(PostPage.class, gVars, gConsts)
                    .wp_add_post_tags(intval(StdClass.getValue(post_meta, "post_id")), keyword);
              }
            }
          }
        }

        if (!precheck) {
          getIncluded(PostPage.class, gVars, gConsts)
              .delete_post_meta(intval(StdClass.getValue(post_meta, "post_id")), "tags", "");
        }
      }

      echo(gVars.webEnv, "</ul>");
    }

    echo(
        gVars.webEnv,
        "<form action=\"admin.php?import=btt&amp;step="
            + strval(precheck ? 2 : 3)
            + "\" method=\"post\">");
    getIncluded(FunctionsPage.class, gVars, gConsts)
        .wp_nonce_field("import-btt", "_wpnonce", true, true);
    echo(
        gVars.webEnv,
        "<p class=\"submit\"><input type=\"submit\" name=\"submit\" value=\""
            + getIncluded(L10nPage.class, gVars, gConsts).__("Next", "default")
            + "\" /></p>");
    echo(gVars.webEnv, "</form>");
    echo(gVars.webEnv, "</div>");

    return false;
  }
Ejemplo n.º 3
0
  /**
   * 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);
  }