Ejemplo n.º 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 );
    }

  }
Ejemplo n.º 2
0
  public static function do_download_file($type) {
    
    global $wf;
    
    // used by the "From URL" control 
    
    if (isset($_REQUEST["url"])) {
      
      $url = trim($_REQUEST["url"]);
    
      if ($url) {
        
        MPC::incl("files");

        $model_id = $_REQUEST["model_id"];
        
        // need to check the extensions
        
        $pi = pathinfo(urldecode($url));
        
        $field = MPM_Field::find_by_id($model_id);
        
        if ($field) {

          $type_options = $field->type_options;

          $extensions = $type_options["allowed_types"];
          
          if (!in_array(strtolower($pi["extension"]), $extensions)) {
            self::ajax_error( sprintf( __("Cannot download %s. This field only allows the file types %s", MASTERPRESS_DOMAIN ), $type, implode(", ", $extensions)));  
          }
          
          list($dir, $sub) = MPC_Files::upload_dir($field);
          
          $name = MPC_Files::sanitize_filename($pi["filename"], $type_options).".".md5($url);
          
          if ($type == "image") {
            $file = $wf->image_from_url($url, $name, $dir);
          } else {
            $file = $wf->file_from_url($url, $name, $dir);
          }
        
          if ($file->exists()) {
            // check the file size 
            
            $limit = self::get_filesize_limit();

            if (isset($type_options["allowed_maxsize"])) {
              if (is_numeric($type_options["allowed_maxsize"])) {
                $limit = WOOF_File::to_bytes($type_options["allowed_maxsize"]."M");
              }
            }
          
            if ($file->filesizeinbytes() > $limit) {
              $file->delete();
              self::ajax_error( sprintf( __("The %s was downloaded, but it could not saved as it was too large. This field only allows files up to %s", MASTERPRESS_DOMAIN ), $type, WOOF_File::format_filesize($limit, "MB", TRUE, $sep = " ")));  
            }
            
            $info = array( "url" => $file->permalink() );
            self::ajax_success($info);
          } else {
            self::ajax_error( sprintf( __("The %s could not be downloaded. Please check the URL is valid and try again", MASTERPRESS_DOMAIN ), $type ) );  
          }
      
        } else {
          self::ajax_error( sprintf( __( "This %s field could not be found in the database to check the validity of this download.", MASTERPRESS_DOMAIN ), $type ) );  
        }
        
      }
    
    }
    
    self::ajax_error(__("No URL specified", MASTERPRESS_DOMAIN));  
  }
Ejemplo n.º 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.
      
    }
    
  }
Ejemplo n.º 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.
      
    }
    
  }
Ejemplo n.º 5
0
 function __construct($path, $url, $attr = array("alt" => "")) {
   parent::__construct($path, $url);
   $this->_attr = $attr;
 }
Ejemplo n.º 6
0
	public static function mem($label) {
		pr( "MEMORY $label - ". WOOF_File::format_filesize( memory_get_usage(), "AUTO" ) . "<br/>" );
  }
Ejemplo n.º 7
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 {
      
      
    }
    
  }
Ejemplo n.º 8
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;

  }