Exemple #1
0
  // convert the exif date format to a unix timestamp
  public int wp_exif_date2ts(String str) {
    // seriously, who formats a date like 'YYYY:MM:DD hh:mm:ss'?
    new ListAssigner<String>() {
      public Array<String> doAssign(Array<String> srcArray) {
        if (strictEqual(srcArray, null)) {
          return null;
        }

        wp_exif_date2ts_date = srcArray.getValue(0);
        wp_exif_date2ts_time = srcArray.getValue(1);

        return srcArray;
      }
    }.doAssign(Strings.explode(" ", Strings.trim(str)));
    new ListAssigner<String>() {
      public Array<String> doAssign(Array<String> srcArray) {
        if (strictEqual(srcArray, null)) {
          return null;
        }

        wp_exif_date2ts_y = srcArray.getValue(0);
        wp_exif_date2ts_m = srcArray.getValue(1);
        wp_exif_date2ts_d = srcArray.getValue(2);

        return srcArray;
      }
    }.doAssign(Strings.explode(":", wp_exif_date2ts_date));

    return QDateTime.strtotime(
        strval(wp_exif_date2ts_y)
            + "-"
            + strval(wp_exif_date2ts_m)
            + "-"
            + strval(wp_exif_date2ts_d)
            + " "
            + strval(wp_exif_date2ts_time));
  }
Exemple #2
0
  // get extended image metadata, exif or iptc as available
  public Array<Object> wp_read_image_metadata(String file) {
    Array<Object> meta = new Array<Object>();
    Array<Object> info = new Array<Object>();
    Array<Object> iptc = new Array<Object>();
    Array<Object> exif = new Array<Object>();

    if (!FileSystemOrSocket.file_exists(gVars.webEnv, file)) {
      return new Array<Object>();
    }

    new ListAssigner<Object>() {
      public Array<Object> doAssign(Array<Object> srcArray) {
        if (strictEqual(srcArray, null)) {
          return null;
        }

        wp_read_image_metadata_sourceImageType = srcArray.getValue(2);

        return srcArray;
      }
    }.doAssign(QImage.getimagesize(gVars.webEnv, file));

    // exif contains a bunch of data we'll probably never need formatted in ways that are difficult
    // to use.
    // We'll normalize it and just extract the fields that are likely to be useful.  Fractions and
    // numbers
    // are converted to floats, dates to unix timestamps, and everything else to strings.
    meta =
        new Array<Object>(
            new ArrayEntry<Object>("aperture", 0),
            new ArrayEntry<Object>("credit", ""),
            new ArrayEntry<Object>("camera", ""),
            new ArrayEntry<Object>("caption", ""),
            new ArrayEntry<Object>("created_timestamp", 0),
            new ArrayEntry<Object>("copyright", ""),
            new ArrayEntry<Object>("focal_length", 0),
            new ArrayEntry<Object>("iso", 0),
            new ArrayEntry<Object>("shutter_speed", 0),
            new ArrayEntry<Object>("title", ""));

    // read iptc first, since it might contain data not available in exif such as caption,
    // description etc
    if (true) /*Modified by Numiton*/ {
      QImage.getimagesize(gVars.webEnv, file, info);

      if (!empty(info.getValue("APP13"))) {
        iptc = new Array<Object>();

        if (!empty(iptc.getArrayValue("2#110").getValue(0))) { // credit
          meta.putValue("credit", Strings.trim(strval(iptc.getArrayValue("2#110").getValue(0))));
        } else if (!empty(iptc.getArrayValue("2#080").getValue(0))) { // byline
          meta.putValue("credit", Strings.trim(strval(iptc.getArrayValue("2#080").getValue(0))));
        }

        if (!empty(iptc.getArrayValue("2#055").getValue(0))
            && !empty(iptc.getArrayValue("2#060").getValue(0))) { // created datee and time
          meta.putValue(
              "created_timestamp",
              QDateTime.strtotime(
                  strval(iptc.getArrayValue("2#055").getValue(0))
                      + " "
                      + strval(iptc.getArrayValue("2#060").getValue(0))));
        }

        if (!empty(iptc.getArrayValue("2#120").getValue(0))) { // caption
          meta.putValue("caption", Strings.trim(strval(iptc.getArrayValue("2#120").getValue(0))));
        }

        if (!empty(iptc.getArrayValue("2#116").getValue(0))) { // copyright
          meta.putValue("copyright", Strings.trim(strval(iptc.getArrayValue("2#116").getValue(0))));
        }

        if (!empty(iptc.getArrayValue("2#005").getValue(0))) { // title
          meta.putValue("title", Strings.trim(strval(iptc.getArrayValue("2#005").getValue(0))));
        }
      }
    }

    // fetch additional info from exif if available
    if (false
        && /*Modified by Numiton*/ Array.in_array(
            wp_read_image_metadata_sourceImageType,
            (Array)
                getIncluded(PluginPage.class, gVars, gConsts)
                    .apply_filters(
                        "wp_read_image_metadata_types",
                        new Array<Object>(
                            new ArrayEntry<Object>(Image.IMAGETYPE_JPEG),
                            new ArrayEntry<Object>(Image.IMAGETYPE_TIFF_II),
                            new ArrayEntry<Object>(Image.IMAGETYPE_TIFF_MM))))) {
      exif = new Array<Object>();

      if (!empty(exif.getValue("FNumber"))) {
        meta.putValue(
            "aperture", Math.round(wp_exif_frac2dec(strval(exif.getValue("FNumber"))), 2));
      }

      if (!empty(exif.getValue("Model"))) {
        meta.putValue("camera", Strings.trim(strval(exif.getValue("Model"))));
      }

      if (!empty(exif.getValue("DateTimeDigitized"))) {
        meta.putValue(
            "created_timestamp", wp_exif_date2ts(strval(exif.getValue("DateTimeDigitized"))));
      }

      if (!empty(exif.getValue("FocalLength"))) {
        meta.putValue("focal_length", wp_exif_frac2dec(strval(exif.getValue("FocalLength"))));
      }

      if (!empty(exif.getValue("ISOSpeedRatings"))) {
        meta.putValue("iso", exif.getValue("ISOSpeedRatings"));
      }

      if (!empty(exif.getValue("ExposureTime"))) {
        meta.putValue("shutter_speed", wp_exif_frac2dec(strval(exif.getValue("ExposureTime"))));
      }
    }

    // FIXME: try other exif libraries if available

    return (Array<Object>)
        getIncluded(PluginPage.class, gVars, gConsts)
            .apply_filters(
                "wp_read_image_metadata", meta, file, wp_read_image_metadata_sourceImageType);
  }
  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;
  }