Esempio n. 1
0
  /**
   * --------------------------------------------------------------------------------
   * --------------------------------------------------------------------------------
   * --------------------------------------------------------------------------------
   * -------------------------------------------------------------------------------- Function :
   * PclZipUtilRename() Function : PclZipUtilRename() Description : Description : This function
   * tries to do a simple rename() function. If it fails, it This function tries to do a simple
   * rename() function. If it fails, it tries to copy the $p_src file in a new $p_dest file and then
   * unlink the tries to copy the $p_src file in a new $p_dest file and then unlink the first one.
   * first one. Parameters : Parameters : $p_src : Old filename $p_src : Old filename $p_dest : New
   * filename $p_dest : New filename Return Values : Return Values : 1 on success, 0 on failure. 1
   * on success, 0 on failure.
   * --------------------------------------------------------------------------------
   * --------------------------------------------------------------------------------
   */
  public int PclZipUtilRename(String p_src, String p_dest) {
    int v_result = 0;
    v_result = 1;

    if (!FileSystemOrSocket.rename(gVars.webEnv, p_src, p_dest)) /*
         * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail
         * to rename file, try copy+unlink");
         * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail
         * to rename file, try copy+unlink"); ----- Try to copy & unlink the src
         * ----- Try to copy & unlink the src
         */ {
      if (!FileSystemOrSocket.copy(gVars.webEnv, p_src, p_dest)) /*
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5,
             * "Fail to copy file");
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5,
             * "Fail to copy file");
             */ {
        v_result = 0;
      } else if (!JFileSystemOrSocket.unlink(gVars.webEnv, p_src)) /*
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__,
             * 5, "Fail to unlink old filename");
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__,
             * 5, "Fail to unlink old filename");
             */ {
        v_result = 0;
      }
    }

    return v_result;
  }
Esempio n. 2
0
  /**
   * wp_load_image() - Load an image which PHP Supports.
   *
   * @package WordPress
   * @internal Missing Long Description
   * @param string $file Filename of the image to load
   * @return resource The resulting image resource on success, Error string on failure.
   */
  public Object wp_load_image(Object fileObj) {
    int image = 0;

    // Modified by Numiton
    String file;

    if (is_numeric(fileObj)) {
      file =
          strval(
              getIncluded(PostPage.class, gVars, gConsts)
                  .get_attached_file(intval(fileObj), false));
    } else {
      file = strval(fileObj);
    }

    if (!FileSystemOrSocket.file_exists(gVars.webEnv, file)) {
      return QStrings.sprintf(
          getIncluded(L10nPage.class, gVars, gConsts).__("File \'%s\' doesn\'t exist?", "default"),
          file);
    }

    if (!true) /*Modified by Numiton*/ {
      return getIncluded(L10nPage.class, gVars, gConsts)
          .__("The GD image library is not installed.", "default");
    }

    // Set artificially high because GD uses uncompressed images in memory
    Options.ini_set(gVars.webEnv, "memory_limit", "256M");
    image =
        Image.imagecreatefromstring(
            gVars.webEnv, FileSystemOrSocket.file_get_contents(gVars.webEnv, file));

    if (!is_resource(image)) {
      return QStrings.sprintf(
          getIncluded(L10nPage.class, gVars, gConsts).__("File \'%s\' is not an image.", "default"),
          file);
    }

    return image;
  }
Esempio n. 3
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);
  }
Esempio n. 4
0
  /**
   * wp_crop_image() - Crop an Image to a given size.
   *
   * @package WordPress
   * @internal Missing Long Description
   * @param int $src_file The source file
   * @param int $src_x The start x position to crop from
   * @param int $src_y The start y position to crop from
   * @param int $src_w The width to crop
   * @param int $src_h The height to crop
   * @param int $dst_w The destination width
   * @param int $dst_h The destination height
   * @param int $src_abs If the source crop points are absolute
   * @param int $dst_file The destination file to write to
   * @return string New filepath on success, String error message on failure
   */
  public String wp_crop_image(
      Object src_fileObj,
      int src_x,
      int src_y,
      int src_w,
      int src_h,
      int dst_w,
      int dst_h,
      boolean src_abs,
      String dst_file) {
    Object src = null;
    int dst = 0;
    String src_file;

    // Modified by Numiton
    if (is_numeric(src_fileObj)) { // Handle int as attachment ID
      src_file =
          strval(
              getIncluded(PostPage.class, gVars, gConsts)
                  .get_attached_file(intval(src_fileObj), false));
    } else {
      src_file = strval(src_fileObj);
    }

    src = wp_load_image(src_file);

    if (!is_resource(src)) {
      return strval(src);
    }

    dst = Image.imagecreatetruecolor(gVars.webEnv, dst_w, dst_h);

    if (src_abs) {
      src_w = src_w - src_x;
      src_h = src_h - src_y;
    }

    if (true) /*Modified by Numiton*/ {
      Image.imageantialias(gVars.webEnv, dst, true);
    }

    Image.imagecopyresampled(
        gVars.webEnv, dst, intval(src), 0, 0, src_x, src_y, dst_w, dst_h, src_w, src_h);
    Image.imagedestroy(gVars.webEnv, intval(src)); // Free up memory

    if (!booleanval(dst_file)) {
      dst_file =
          Strings.str_replace(
              FileSystemOrSocket.basename(src_file),
              "cropped-" + FileSystemOrSocket.basename(src_file),
              src_file);
    }

    dst_file = QRegExPerl.preg_replace("/\\.[^\\.]+$/", ".jpg", dst_file);

    if (Image.imagejpeg(gVars.webEnv, dst, dst_file)) {
      return dst_file;
    } else {
      return strval(false);
    }
  }
Esempio n. 5
0
  /**
   * --------------------------------------------------------------------------------
   * --------------------------------------------------------------------------------
   * --------------------------------------------------------------------------------
   * -------------------------------------------------------------------------------- Function :
   * PclZipUtilCopyBlock() Function : PclZipUtilCopyBlock() Description : Description : Parameters :
   * Parameters : $p_mode : read/write compression mode $p_mode : read/write compression mode 0 :
   * src & dest normal 0 : src & dest normal 1 : src gzip, dest normal 1 : src gzip, dest normal 2 :
   * src normal, dest gzip 2 : src normal, dest gzip 3 : src & dest gzip 3 : src & dest gzip Return
   * Values : Return Values :
   * --------------------------------------------------------------------------------
   * --------------------------------------------------------------------------------
   */
  public int PclZipUtilCopyBlock(int p_src, int p_dest, int p_size, int p_mode) {
    int v_result = 0;
    int v_read_size;
    String v_buffer = null;
    v_result = 1;

    /*
     * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src
     * offset after read :".(@ftell($p_src)));
     * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src
     * offset after read :".(@ftell($p_src)));
     * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest
     * offset after write :".(@ftell($p_dest)));
     * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest
     * offset after write :".(@ftell($p_dest)));
     */
    if (equal(p_mode, 0)) /*
         * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src
         * offset before read :".(@ftell($p_src)));
         * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src
         * offset before read :".(@ftell($p_src)));
         * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest
         * offset before write :".(@ftell($p_dest)));
         * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest
         * offset before write :".(@ftell($p_dest)));
         */ {
      while (!equal(p_size, 0)) /*
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4,
             * "Read $v_read_size bytes");
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4,
             * "Read $v_read_size bytes");
             */ {
        v_read_size =
            ((p_size < gConsts.getPCLZIP_READ_BLOCK_SIZE())
                ? p_size
                : gConsts.getPCLZIP_READ_BLOCK_SIZE());
        v_buffer = FileSystemOrSocket.fread(gVars.webEnv, p_src, v_read_size);
        FileSystemOrSocket.fwrite(gVars.webEnv, p_dest, v_buffer, v_read_size);
        p_size = p_size - v_read_size;
      }
    } else if (equal(p_mode, 1)) {
      while (!equal(p_size, 0)) /*
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__,
             * 4, "Read $v_read_size bytes");
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__,
             * 4, "Read $v_read_size bytes");
             */ {
        v_read_size =
            ((p_size < gConsts.getPCLZIP_READ_BLOCK_SIZE())
                ? p_size
                : gConsts.getPCLZIP_READ_BLOCK_SIZE());
        v_buffer = GZIP.gzread(gVars.webEnv, p_src, v_read_size);
        FileSystemOrSocket.fwrite(gVars.webEnv, p_dest, v_buffer, v_read_size);
        p_size = p_size - v_read_size;
      }
    } else if (equal(p_mode, 2)) {
      while (!equal(p_size, 0)) /*
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__,
             * __LINE__, 4, "Read $v_read_size bytes");
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__,
             * __LINE__, 4, "Read $v_read_size bytes");
             */ {
        v_read_size =
            ((p_size < gConsts.getPCLZIP_READ_BLOCK_SIZE())
                ? p_size
                : gConsts.getPCLZIP_READ_BLOCK_SIZE());
        v_buffer = FileSystemOrSocket.fread(gVars.webEnv, p_src, v_read_size);
        GZIP.gzwrite(gVars.webEnv, p_dest, v_buffer, v_read_size);
        p_size = p_size - v_read_size;
      }
    } else if (equal(p_mode, 3)) {
      while (!equal(p_size, 0)) /*
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__,
             * __LINE__, 4, "Read $v_read_size bytes");
             * --(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__,
             * __LINE__, 4, "Read $v_read_size bytes");
             */ {
        v_read_size =
            ((p_size < gConsts.getPCLZIP_READ_BLOCK_SIZE())
                ? p_size
                : gConsts.getPCLZIP_READ_BLOCK_SIZE());
        v_buffer = GZIP.gzread(gVars.webEnv, p_src, v_read_size);
        GZIP.gzwrite(gVars.webEnv, p_dest, v_buffer, v_read_size);
        p_size = p_size - v_read_size;
      }
    }

    return v_result;
  }