HTML Uploader Videos and Picture from iOS devices!

MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Thu, 2013-06-20 13:54

The iOS upload dream module. one minor little edit and I've been able to upload directly from my iPhone and iPad. Even allows choice to upload from camera or library. Video and Pictures.
/modules/html_uploader/controllers/upload.php
in_array(strtolower($path_info["extension"]), array("flv", "mp4", "m4v"))) {
so it looks like this:
in_array(strtolower($path_info["extension"]), array("flv", "mp4", "m4v","mov","MOV"))) {

One thing would make it perfect, the ability to add title and description on upload. Now this option is available in the viGallery (picture upload only) app so i know it's doable. Maybe the advanced coders can figure it out.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sat, 2013-06-22 01:38

I guess that this module shoul be updated to use the new function to check file types not just extensions.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Sat, 2013-06-22 02:02

I'll test it if upgraded.

 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Sat, 2013-06-22 21:31

Here is the contents of the HTML uploader.php file.
Can any of you super coders edit/tweak this file so it will allow for the user to enter the Name/Title and a Description as the media is being uploaded?

<?php defined("SYSPATH") or die("No direct script access.");
/**
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2013 Bharat Mediratta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */
class Uploader_Controller extends Controller {
  public function index($id) {
    $album = ORM::factory("item", $id);
    access::required("view", $album);
    access::required("add", $album);
    if (!$album->is_album()) {
      $album = $album->parent();
    }

    print $this->_get_add_form($album);
  }

  public function add($id) {
    $album = ORM::factory("item", $id);
    access::required("view", $album);
    access::required("add", $album);
    access::verify_csrf();

    $form = $this->_get_add_form($album);
    if ($form->validate()) {
      batch::start();

      $count = 0;
      $added_a_movie = false;
      $added_a_photo = false;
      foreach (array("file1", "file2", "file3") as $key) {
        if ($form->add_photos->$key->value == "") {
          continue;
        }

        try {
          $temp_filename = $form->add_photos->$key->value;
          $item = ORM::factory("item");
          $item->name = basename($temp_filename);
          $item->title = item::convert_filename_to_title($item->name);
          $item->parent_id = $album->id;
          $item->set_data_file($temp_filename);

          $path_info = @pathinfo($temp_filename);
          if (array_key_exists("extension", $path_info) &&
              in_array(strtolower($path_info["extension"]), array("flv", "mp4", "m4v", "MOV", "wmv"))) {
            $item->type = "movie";
            $item->save();
            $added_a_movie = true;
            log::success("content", t("Added a movie"),
                         html::anchor("movies/$item->id", t("view movie")));
          } else {
            $item->type = "photo";
            $item->save();
            $added_a_photo = true;
            log::success("content", t("Added a photo"),
                         html::anchor("photos/$item->id", t("view photo")));
          }
          $count++;
          module::event("add_photos_form_completed", $item, $form);
        } catch (Exception $e) {
          // Lame error handling for now.  Just record the exception and move on
          Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());

          // Ugh.  I hate to use instanceof, But this beats catching the exception separately since
          // we mostly want to treat it the same way as all other exceptions
          if ($e instanceof ORM_Validation_Exception) {
            Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1));
          }
        }

        if (file_exists($temp_filename)) {
          unlink($temp_filename);
        }
      }
      batch::stop();
      if ($count) {
        if ($added_a_photo && $added_a_movie) {
          message::success(t("Added %count photos and movies", array("count" => $count)));
        } else if ($added_a_photo) {
          message::success(t2("Added one photo", "Added %count photos", $count));
        } else {
          message::success(t2("Added one movie", "Added %count movies", $count));
        }
      }
      json::reply(array("result" => "success"));
    } else {
      json::reply(array("result" => "error", "html" => (string) $form));
    }

    // Override the application/json mime type.  The dialog based HTML uploader uses an iframe to
    // buffer the reply, and on some browsers (Firefox 3.6) it does not know what to do with the
    // JSON that it gets back so it puts up a dialog asking the user what to do with it.  So force
    // the encoding type back to HTML for the iframe.
    // See: http://jquery.malsup.com/form/#file-upload
    header("Content-Type: text/html; charset=" . Kohana::CHARSET);
  }

  private function _get_add_form($album) {
    $form = new Forge("uploader/add/{$album->id}", "", "post", array("id" => "g-add-photos-form"));
    $group = $form->group("add_photos")
      ->label(t("Add photos to %album_title", array("album_title" => html::purify($album->title))));
    $group->upload("file1")->add_rule("foo");
    $group->upload("file2");
    $group->upload("file3");

    module::event("add_photos_form", $album, $form);

    $group = $form->group("buttons")->label("");
    $group->submit("")->value(t("Upload"));

    return $form;
  }
}
 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2013-06-26 04:59

Started to work on this..... try the attached file to replace the existing one controllers/uploader.php

1. Changed some text to say item not photos.
2. Used the new function to check movies (get_movie_extensions) not tested much so let me know.
3. Reduced the upload to one item at a time. I assume that the screen might be a bit small for and confusing for the 3 upload and 3 titles and 3 descriptions to fit on a idevice. Can test so let me know about that as well.
4. If all is well with this I will develop a new upload module with these changes.

Cheers!
Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Wed, 2013-06-26 16:14

Dave,
Pardon my excitement.
WOW! Exactly what my intention was.
So far everything works perfectly. I tested it with mp4 and MOV files as well as jpg picture files from my iPad and iPhone, all worked flawlessly.
One upload at a time is perfect (in my opinion, although I'm sure other users will want or need more)

I can't see where anything needs changing at this point.

 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Wed, 2013-06-26 15:40

Dave,
Just gave it a through test.
1. Title and Description fields are mandatory. Thus will not work with JNashes new stadfed or the exif module(s)
2. Seems to be picking up files properly (uploaded mp4,MP4, mov and MOV files [yes there seems to be a difference in extension]) as well as picture files (I use jpg only).
3. The one upload is perfect for iOS and other mobile devices.
4. Changes can still be made using the edit function that is standard with gallery.

I'd say run with it. This is the perfect uploader for mobile devices (only tested on iPhone and iPad) and also for desktop application for those that don't have meta editing tools and/or don't know how to use them.
All the changes you and jNash have made recently really bring gallery into the html5 era. Which, IMHO, make this the best sharing software of all.
Believe me Gallery now totally outshines other graphics sharing software such as ClipBucket for ease of use and compatibility through out all devices.
These changes (including my metadata inclusion) should be incorporated into any updates or future releases of Gallery as standard parts of the program.
It's versatility is now unsurpassed by any other.
Thank you again for all your efforts

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Wed, 2013-06-26 16:32

For #1, what doesn't work for the stadfed module (I may have fixed the issue if it's what I think it is...)

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2013-06-26 17:53

For #1 I can make it a option and take the title from the name and same for the discription.

The original HTML uploder replaces the standard uploader I think I will make the new module be a 'mobile' upload to "add" to the exsisting methods not replace them.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Wed, 2013-06-26 18:10

Awesome,
I can't wait to try the new module. I've been having a blast testing this today.

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Wed, 2013-06-26 18:14

What I've done to the stadfed module (as I noticed on my linker module and error) is that if a title and/or description exist in the image, but the user has provided them, I don't use the ones from the image. - Hope that makes sense...

I'll say it another way... if when uploading an image there is a title and/or description provided (existing in database after image uploads) then stadfed doesn't change it... (stadfed runs right after the database is committed with the new image data)

I'll upload the new module shortly. actually the latest is in the codex... with description as to what was changed

If there is something else that's not working in conjunction with this module and stadfed, please let me know. Dave and I work closely enough together to get it sorted. :-)

James

 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Wed, 2013-06-26 18:34

You guys are awesome. let me know when your change is made James.
This is a very exciting moment for Gallery and it's users.

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Wed, 2013-06-26 19:21
 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2013-06-26 19:57

MikeLFD,
post a image that has the EXIF/IPTC data that you want the stadfed module to work with so I can test against it.
tell us what the title should be and the other meta data that should be populated.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Wed, 2013-06-26 20:25

I don't understand Dave.
The only thing I found happening with the "new mobile uploader" was it won't upload anything (pic or vid) if stadfed module is enabled.
it will go through the motions but doesn't make the upload.
Stadfed works perfectly without the new uploader activated or with the original html uploader active.

For me it's not an issue as I prefer to manually enter the title and description of my media on upload, which is what the new mobile uploader does and it does it perfectly.
Thinking out of the box (and not wanting to cause any confusion) I'm sure there will be some users who prefer the option of using existing exif/iptc as well as the option to set the name and desc. or maybe choosing to use one method and not the other.

Don't make any changes to stadfed it's not broke (haha).
All that said- the new mobile uploader isn't really broken either it's just more of a compatibility issue. If you can (as you mentioned) cause the title and desc. as an option then I believe the conflict with stadfed would be solved.

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Wed, 2013-06-26 20:30

the conflict is what we want to determine and fix.

Send us a link to an image that doesn't work with both modules enabled - then Dave can test it out and see what we need to do.

 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Wed, 2013-06-26 20:38

That's the problem I can't. Nothing will upload with both modules enabled.

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Wed, 2013-06-26 20:48

Ah, gotcha. Dave, let me know what you find out then. I'm sure it's something simple.

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Wed, 2013-06-26 20:53

Okay, I see it is failing out in uploader.php for title being required...

... excluded extra ...

html_uploader/controllers/uploader.php(68): Item_Model_Core->save()

... excluded extra ..

2013-06-26 16:51:12 -04:00 --- error: Validation errors: Array
(
    [title] => required
)

Dave you want to fix?

 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Wed, 2013-06-26 21:24

aha just make a note on the form Title (required)
I edited the php file and added (Required) next to the label title (to remind me I need to give it a name) Made an upload using both modules after entering a title and It works flawlessly.

private function _get_add_form($album) {
    $form = new Forge("uploader/add/{$album->id}", "", "post", array("id" => "g-add-photos-form"));
    $group = $form->group("add_photos")
      ->label(t("Add an item to %album_title", array("album_title" => html::purify($album->title))));
    $group->upload("file1");
	$group->input("title1")->label(t('Title (Required).'));
	$group->input("description1")->label(t('description.'));

    module::event("add_photos_form", $album, $form);

    $group = $form->group("buttons")->label("");
    $group->submit("")->value(t("Upload"));

    return $form;
 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Wed, 2013-06-26 22:38

Dave,
Couldn't figure how to send this zip file by PM

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Thu, 2013-06-27 00:36

Should probably pre-fill and validate: (quick edit, untested)

private function _get_add_form($album) {
    $form = new Forge("uploader/add/{$album->id}", "", "post", array("id" => "g-add-photos-form"));
    $group = $form->group("add_photos")
      ->label(t("Add an item to %album_title", array("album_title" => html::purify($album->title))));
    $group->upload("file1");
	$group->input("title1")
           ->label(t('Title (Required).')
           ->rules('required')
           ->error_messages("required",t("Title is required"))
           ->value(item::convert_filename_to_title($item->name))
           ->rules('required')
        );
	$group->input("description1")->label(t('description.'));

    module::event("add_photos_form", $album, $form);

    $group = $form->group("buttons")->label("");
    $group->submit("")->value(t("Upload"));

    return $form;
 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Thu, 2013-06-27 00:59

Nope. That only causes it not to launch the form

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Thu, 2013-06-27 01:10

ah, I see it... hmmm... let me think about it a bit, $item doesn't exist yet... doh!

for now, take out the line:

->value(item::convert_filename_to_title($item->name))
 
MikeLFD

Joined: 2013-03-22
Posts: 79
Posted: Thu, 2013-06-27 01:26

Doesn't matter any deviation from this

$group->upload("file1");
	$group->input("title1")->label(t('Title (Required).'));

seems to throw it into error and not function.

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Thu, 2013-06-27 03:20

yea, forget it, it's been a long day, and I shouldn't have even tried :-)

Especially since I couldn't do any testing...

Plus, I see I duplicated the ->rules line...

Dave and I will refocus and address a better solution.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2013-06-27 03:46

I'm confused.
I can add a item with the stadfed module installed. That is why I needed a image to test with. So i went and found one that I assume has some EXIF/IPTC data in it.

If I add the attached image and give it a name of 'test' and a description of 'testing', it adds and the stadfed module over-rides the title to 'Communication' and the description to 'Communication'. I guess that is not the expected behavior?

Could be a module order issue?

I know if I add a item that does not have a title or description it fails. This can be fixed.

please attach a item that fails with a good user story.

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Thu, 2013-06-27 13:35
Quote:
I know if I add a item that does not have a title or description it fails. This can be fixed.

This is the issue... hence the 'required' part of our discussions... I just didn't have time or effort to look at it further.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2013-06-27 13:38

I'm not sure why

->rules('required')
           ->error_messages("required",t("Title is required"))

Does not work. :-( I can't figure it out.

Anyway, I think what I will do is use some jquery to listen for the upload form to be populated, grab the file name, strip the extension and populate the title field. Then it will be used unless the user overrides that field with a different title, before clicking the upload button.

Does that sound good?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
jnash
jnash's picture

Joined: 2004-08-02
Posts: 814
Posted: Thu, 2013-06-27 13:49

Sounds like a plan to me!

Or do it at the processing of the form... another file edit, but hey, it's open source!

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2013-06-27 21:24

Try the attached. If you already have a module called mobile_uploader, uninstall it first, delete the files and then upload this module.

It does not replace the existing upload method but adds a new method in the 'add' menu drop-down.
The title of the item will be auto populated and still editable.
Not test in other browsers, other than FF, so there needs to be some testing in some mobile browsers.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team