Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - brandonc

Pages: [1]
1
Instructions for modifying your customized installation
This requires several changes to 2 PHP files and 1 small change to a template file.  There are several changes in each of the PHP files.   Line numbers here were taken from the latest download and will be different once you modify your files.


Changes to member.php

(starting at about line 549):
change this:
Code: [Select]
    // Upload Media file
    if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none") {
      $new_name = $site_upload->upload_file("media_file", "media", $upload_cat);
      if (!$new_name) {
        $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name."</b><br />".$site_upload->get_upload_errors();
        $uploaderror = 1;
      }
    }
    else {
      $new_name = $remote_media_file;
    }

Into this:
Code: [Select]
    // Upload Media file
    if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none") {
      $new_name = $site_upload->upload_file("media_file", "media", $upload_cat);
      if (!$new_name) {
        $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name."</b><br />".$site_upload->get_upload_errors();
        $uploaderror = 1;
      }
    }
    //  BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net bchecketts at hotmail dot com
    elseif ($HTTP_POST_VARS['remote_media_file_download']) {
        $new_name = $site_upload->download_file("remote_media_file", "media", $upload_cat);
    }
    // END BC MODIFICATION
    else {
      $new_name = $remote_media_file;
    }



Change this (about line 573)
Code: [Select]
elseif ($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none" && !$uploaderror) {

Into this:
Code: [Select]
    // BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net  bchecketts at hotmail dot com
    elseif ($config['auto_thumbnail'] == 1 && !empty($_POST['remote_media_file']) && !$uploaderror) {
      if ($direct_upload) {
        $src = MEDIA_PATH."/".$cat_id."/".$new_name;
        $dest = THUMB_PATH."/".$cat_id."/".$new_name;
      }
      else {
        $src = MEDIA_TEMP_PATH."/".$new_name;
        $dest = THUMB_TEMP_PATH."/".$new_name;
      }
      $do_create = 0;
      if ($image_info = @getimagesize($src)) {
        if ($image_info[2] == 1 || $image_info[2] == 2 || $image_info[2] == 3) {
          $do_create = 1;
        }
      }
      if ($do_create) {
        require(ROOT_PATH.'includes/image_utils.php');
        $convert_options = init_convert_options();
        if (!$convert_options['convert_error']) {
          $dimension = (intval($config['auto_thumbnail_dimension'])) ? intval($config['auto_thumbnail_dimension']) : 100;
          $resize_type = (intval($config['auto_thumbnail_resize_type'])) ? intval($config['auto_thumbnail_resize_type']) : 1;
          $quality = (intval($config['auto_thumbnail_quality']) && intval($config['auto_thumbnail_quality']) <= 100) ? intval($config['auto_thumbnail_quality']) : 100;

          if (create_thumbnail($src, $dest, $quality, $dimension, $resize_type)) {
            $new_thumb_name = $new_name;
          }
        }
      }
    }
    // END BC MODIFICATION


    elseif (($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none" && !$uploaderror) ||
        ($config['auto_thumbnail'] == 1 && !$empty($_POST['remote_media_file']) && !empty($_POST['remote_media_file_download']) && !$uploaderror) ) {



Changes to includes/upload.php

About line 44, Add this function before the Upload class is defined:
Code: [Select]
// BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net  bchecketts at hotmail dot com
function move_downloaded_file($file_name, $destination) {
    return copy($file_name, $destination) ? 1 : 0 ;
}
// END BC MODIFICATION

class Upload {


Change this (about line 103)
Code: [Select]
$ok = move_uploaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);to this
Code: [Select]
        // BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net  bchecketts at hotmail dot com
        if(isset($_POST['remote_media_file_download']) && $_POST['remote_media_file_download']) {
            $ok = move_downloaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
        } else {
            $ok = move_uploaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
        }
        // END BC MODIFICATION

Change this (line 122)
Code: [Select]
$ok = move_uploaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
to this:
Code: [Select]
        // BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net  bchecketts at hotmail dot com
        if(isset($_POST['remote_media_file_download']) && $_POST['remote_media_file_download']) {
            $ok = move_downloaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
        } else {
            $ok = move_uploaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
        }
        // END BC MODIFICATION


Add this function on line 226 before the "function check_file_extension($extension = "") { line
Code: [Select]
// START MODIFICATIONS by Brandon Checketts from www.webpipe.net  bchecketts at hotmail dot com
  function download_file($field_name, $image_type, $cat_id = 0, $file_name = "")
  {
    $this->field_name = $field_name;
    $this->image_type = $image_type;

    if ($cat_id) {
      $this->upload_path['thumb'] = THUMB_PATH."/".$cat_id;
      $this->upload_path['media'] = MEDIA_PATH."/".$cat_id;
    }
    else {
      $this->upload_path['thumb'] = THUMB_TEMP_PATH;
      $this->upload_path['media'] = MEDIA_TEMP_PATH;
    }

    // Figure out an appropriate file name
    if ($file_name != "") {
      ereg("(.+)\.(.+)", $file_name, $regs);
      $this->name = $regs[1];
      ereg("(.+)\.(.+)", $this->HTTP_POST_FILES[$this->field_name]['name'], $regs);
      $this->extension = $regs[2];
      $this->file_name = $this->name.".".$this->extension ;
    }
    else {
      $file_only = $_POST[$field_name];
      $file_only = preg_replace("/.*\//","",$file_only);
      $this->file_name = $file_only;
      $this->file_name = ereg_replace(" ", "_", $this->file_name);
      $this->file_name = ereg_replace("%20", "_", $this->file_name);
      $this->file_name = preg_replace("/[^-\._a-zA-Z0-9]/", "", $this->file_name);

      ereg("(.+)\.(.+)", $this->file_name, $regs);
      $this->name = $regs[1];
      $this->extension = $regs[2];
    }


    $url = $_POST[$field_name];
    $ch = curl_init($url);
    $save_file = "/tmp/" . $this->file_name;

    $fp = fopen($save_file,"w");

    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);

    curl_exec($ch);

    $this->mime_type = curl_getinfo($ch,CURLINFO_CONTENT_TYPE);

    curl_close($ch);
    fclose($fp);
    if ($this->save_downloaded_file($save_file)) {
      return $this->file_name;
    }
    else {
      return false;
    }

  }
  // END BC MODIFICATIONS




Changes to your template file (member_uploadform.html)
Add this line in the section where it prompts for the URL (line 27 for for the 4blue_orange1 template)
Code: [Select]
<!-- BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net  bchecketts at hotmail dot com -->
<input type="checkbox" name="remote_media_file_download">Save a copy locally  <br />
<!-- END BC MODIFICATION -->



Thanks,
Brandon Checketts
bchecketts at hotmail dot com
www.webpipe.net System Administrator
Hosting accounts at Webpipe.net are fully compatible with 4images!

2
This mod allows you to save a local copy of an image when loading the image from a URL path.  It downloads the file to the server and saves a copy of it on the server, instead of just referencing the URL.  I've found this incredibly useful and hope that you will too.  This also auto-creates thumbnails for me (using ImageMagick), but some other features may not work correctly as I didn't pay much attention to other functionality requirements.

Use the attached files to replace these files:
member.txt->4images_root/member.php
upload.txt->4images_root/includes/upload.php
member_uploadform.txt->4images_root/templates/4blue_orange1/member_uploadform.html

Of course the changes in the template file would need to be applied to which ever template you are using.  Just add this line in your template file where you want the option to appear:
Code: [Select]
<input type="checkbox" name="remote_media_file_download">Save a copy locally  <br />
Enjoy!
Brandon Checketts
www.webpipe.net System Administrator
Webpipe.net hosting accounts are fully compatible with 4images

Pages: [1]