예제 #1
0
  public function __construct($item) {
    
    global $wf;
    
    parent::__construct($item);
    
    $id = $this->id();
    
    $file_url = wp_get_attachment_url( $id );
    $file_path = WOOF_File::infer_content_path($file_url);

    if (wp_attachment_is_image( $id ) ) {
      $c = $wf->get_image_class();
      $this->file = new $c( $file_path, $file_url );
    } else {
      $c = $wf->get_file_class();
      $this->file = new $c( $file_path, $file_url );
    }

  }
예제 #2
0
  function __construct( $info, $field ) {
    
    global $wf;
    
    parent::__construct( $info, $field );
    
    // infer the path, url to the file.

    $data = $this->data();
    
    if (isset($data)) {
    
      $this->valid = false;

      if (isset($data->val)) {
    
        if ($data->val == "") {
          $this->valid = false;
        } else {
          $this->valid = true;
        }

        $url = $data->val;
        $path = WOOF_File::infer_content_path($url);

        $fc = $wf->get_file_class();
        
        $this->file = new $fc( $path, $url );
    
        if ($this->file->exists()) {
          $this->valid = TRUE;
        } else {
          
          // try to access the file at the URL 

          if ($path == "" && defined("MASTERPRESS_RESOLVE_EXTERNAL_URLS")) {

            /* 
            
            We should ONLY access the URL if this file could not possibly exist on this server.
            If we try to hit a file that could exist on this server but doesn't, this can cause an infinite httpd loop
            where a 404 causes another WP page load, which causes additional 404s, which cause more page loads ...
            
            Note that infer_content_path above will return an empty string if the URL is external
            
            */
            
            $this->file = $wf->file_from_url($url);
            $this->valid = $this->file->exists();
          }
        }
        
        if (!$this->valid) {
          $this->file = new WOOF_Silent(__("The file could not be found", MASTERPRESS_DOMAIN));
        }
        
        
      
      } else {
        $this->file = new WOOF_Silent(__("no file path has been set", MASTERPRESS_DOMAIN));
      }

    }
  
    
  } 
예제 #3
0
  public static function upload_info() {

    global $wf;

    $url = trim($_REQUEST["url"]);
    $path = WOOF_File::infer_content_path($url);
    
    if (file_exists($path)) {
    
      $fc = $wf->get_file_class();
      
      $file = new $fc($path, $url);

      if ($file->exists()) {
        
        if ($url && $info = $file->info()) {
          self::ajax_success( $info );
        }
      }
      
    } else {
      
      // pull the image down?
      // this method would need to delete the image after it grabs the info / generates thumbnails,
      // since the whole point of requesting
      // image info from another store would be to avoid having large images on THIS web server.
      
    }
    
  }
예제 #4
0
  public static function image_info() {

    global $wf;
    $ic = $wf->get_image_class();

    $url = trim($_REQUEST["url"]);
    $path = WOOF_File::infer_content_path($url);
    
    if (file_exists($path)) {
    
      $image = new $ic($path, $url);

      if ($image->exists()) {
        
        if ($url && $info = $image->info()) {
          // generate the thumbnail

          $width = $info["width"];
          $height = $info["height"];
          
          list($tw, $th) = self::thumb_wh($width, $height);
          list($stw, $sth) = self::summary_thumb_wh($width, $height);

          $thumb = $image->resize("w=".($tw * 2)."&h=".($th * 2)."&crop=true&q=90&up=0");
          $summary_thumb = $image->resize("w=".($stw * 2)."&h=".($sth * 2)."&crop=true&q=90&up=0");

          $info["thumb"] = $thumb->url();
          $info["summary_thumb"] = $summary_thumb->url();

          $info["thumb_width"] = min($tw, $thumb->width());
          $info["thumb_height"] = min($th, $thumb->height());

          $info["summary_thumb_width"] = min($stw, $summary_thumb->width());
          $info["summary_thumb_height"] = min($sth, $summary_thumb->height());

          
          self::ajax_success( $info );
        }
      }
      
    } else {
      
      // self::ajax_error("image not found");
      
      // call an "image from url" method to pull the image down 
      // this method would need to delete the image after it grabs the info / generates thumbnails,
      // since the whole point of requesting
      // image info from another store would be to avoid having large images on THIS web server.
      
    }
    
  }
예제 #5
0
  public static function upload_info() {

    global $wf;

    $url = trim($_REQUEST["url"]);
    $path = WOOF_File::infer_content_path($url);
    
    if (file_exists($path)) {
    
      $fc = $wf->get_file_class();
      
      $file = new $fc($path, $url);

      if ($file->exists()) {
        
        if ($url && $info = $file->info()) {
          self::ajax_success( $info );
        }
      }
      
    } else {
      
      
    }
    
  }
예제 #6
0
  public function thumbnail() {

    if (!$ret = $this->property_cache( __FUNCTION__ )) {

      $ret = false;
      
      global $wf;

      $ic = $wf->get_image_class();

      $image = get_post_thumbnail_id( $this->item->ID );

      if ($image && is_numeric($image)) {
        
        $file_url = wp_get_attachment_url( $image );
        $file_path = WOOF_File::infer_content_path($file_url);
      
      
        $ret = new $ic( $file_path, $file_url );
      
        $this->property_cache( __FUNCTION__, $ret );
        
      }
    }

    if (!$ret) {
      return new WOOF_Silent(__("Cannot generate thumbnail - no featured image has been set", WOOF_DOMAIN));
    }
    
    return $ret;

  }