Jump to content

Module: Manage Files


Nico Knoll
 Share

Recommended Posts

Hi,

I didn't like the way how ProcessWire works with files right now. So I thought it's time for an Module which makes it better. Right now the module isn't finished but I'm working on it (probably together with Soma).

My goal is to create an module which let's you mange all of your files and images easy and let you upload files which aren't connected to a page so that every page can use it.

If you have wishes or ideas for this module you can post them here. (Also if you know a better way to solve this)

And by the way here's a first screenshot (I started today, so it isn't that great right now).

UPDATE:

Download: https://github.com/N...oll/ManageFiles

post-5023-132614279919_thumb.png

Edited by Pete
  • Like 2
Link to comment
Share on other sites

I would like to know a little more about your plans.

Not sure if you seen my edit on your other thread showcase you site. I copied it to here:

---

For your problem in managing images. Reading again you post, you want to have images in one place and select them on different pages? Or what are you needs here exactly?

There's a simple way to archive something like this:

Have an external section "files" where you upload images. But each image a separate page. Have a template "image" and add a single image field and may even more fields imaginable.

So you could add a Page reference field "selected_image" that is set up to select from the section and only the "image" template. Add this field to your pages templates. Now you can select images/image using this field. You can manage images in one location and select it on each page. If you upload and replace an image the reference will not get lost, so this is a great solution.

In the php template you would output the image using:

<?php

// if single page reference 
echo $page->selected_image->image->url;

// if multiple page reference select
foreach($page->selected_image as $img){
   echo $img->image->url;
}

You even can select in TinyMCEs image PW dialog (select page, and chose image from that page), but this will add a path to the file and not an id reference, (which is my biggest problem with that approach).

Though as long as you use it for out of TinyMCE content on page it's a great solution to have more control. It's also possible with a little hack (untill Ryan implemented this) to show a thumbnail in the page list select, if the label of the template is an image field (in template advanced setting available). Look this thread of mine: http://processwire.com/talk/index.php/topic,411.0.html

  • Like 1
Link to comment
Share on other sites

Yeah, I read your answer but I thought if I open this topic it's like an answer.

I think that you shouldn't create a separate page for each picture (I mean I've got more than 2000 images and files so it would be kind of confusing).

(By the way is there a way to chat with you like Facebook or Twitter?)

Link to comment
Share on other sites

Great stuff Nico.

As a side note: our old cms had very similar file management to pw: you add files to any page and the do cross references to those. It works fine on most cases, but sometimes it is just easy to "lost" files for clients ("well.. I don't remember where I put it"). It will be great to have central repo for files (but still keep page relationship).

What I would love to have regarding file management is more meta tags for files (tags). This is easy if you go one file per page route - but to be honest - it is clumsy way here. Imagine uploading 50 files that way comparing current ajax way or even old dynamic form method...

Link to comment
Share on other sites

Would love to have the possibility to manage "assets" like files / images in an own manager interface. File or image fields of pages could be linked with directories in the asset manager, so there wouldn’t be a conflict between centralized and page related approach.

Link to comment
Share on other sites

I'm trying to help Nico a little on this. And I think we reached a major problem concerning how this should work.

I was chatting with Nico last night and he showed me his current module. It's was mainly reading the assets files dir to glob all files and in relation to the folder id delete them with manual sql from the field table. This show's all files (including thumbs) of each file and it has some limitations.

I thought it may possible to make this using API and scan all templates for FieldtypeFile fields and do a find over all pages using those templates. Then iterate through them and list all files depending what type it is output a preview or link to the file. It works fine so far but I got problems getting the delete of the file to work on the page it is located through API. Anyway that's not the main issue.

Now major problem is how to expand this with filtering and per branch in the tree and get a pager working, since it's returning pages with various files attached... the pager can't possibly be on the pages found but should be on the files found instead. I don't see an easy way to get this all running and having filtering (per page or pages, filetype etc) or search function possibly.

So my question is what features would be needed and how could it possibly be done. I reach a major wall here I can't decide what would be best way to go. Many traps here I think.

Attached the current rough proof of concept module. It installs a "Files" page after "Pages", and it shows files (no thumbs) and a pager which doesn't work correctly. Also deleting doesn't work, but it's just to give an example.

ManageFiles.module.zip

Link to comment
Share on other sites

I had a quick look at the data model in the db associating the files with their pages. I haven’t tested your plugin, yet, but I think, it would be nice to let the user navigate through files by treating the page structure and file fields like directories. Similar to the url paths. And with the possibility to directly upload files into those "virtual" directories.

Link to comment
Share on other sites

  • 2 months later...

Hey, almost forgot about it, but only almost. I recently just was thinking about this one, great to hear you're working on it Nico. Unfortunately I got so much up with higher prio, I need to catch up first before I could spend more time on this.

Link to comment
Share on other sites

Nice module Nico! I have a few suggestions:

1. The current way you are using $pages->find() to find files is going to mess up the pagination for any pages that have blank file fields. For instance, on the site I tested, I have 30 files, but hundreds of pages with blank file fields. I ended up with 90+ pagination links, where most pages were just blank. So I think that finding files by template is probably not ideal. Instead I'd suggest finding them by field. This will work:

$fields = $this->fields->find('type=FieldtypeFile|FieldtypeImage')->getArray();
$pages = $this->pages->find(implode('|', $fields) . ">0, sort=-modified, limit=10"); 

2. You have some stray var_dump() functions that are breaking the display in some parts of the module.

3. In your executeDelete(), I don't understand why you have this line:

foreach($f->page->getInputfields() as $field) {

It doesn't seem necessary? I would get rid of it if you can.

Link to comment
Share on other sites

Nice module Nico! I have a few suggestions:

1. The current way you are using $pages->find() to find files is going to mess up the pagination for any pages that have blank file fields. For instance, on the site I tested, I have 30 files, but hundreds of pages with blank file fields. I ended up with 90+ pagination links, where most pages were just blank. So I think that finding files by template is probably not ideal. Instead I'd suggest finding them by field. This will work:

$fields = $this->fields->find('type=FieldtypeFile|FieldtypeImage')->getArray();
$pages = $this->pages->find(implode('|', $fields) . ">0, sort=-modified, limit=10"); 

Aaaand I was waiting for this answer since 2 months :P as I wrote a lengthy post back then about this issue above in this thread asking how this issue could be solved... Think you must have missed it then :D

Link to comment
Share on other sites

  • 1 month later...

If using Thumbnails module in conjunction with Manage files module you could get following scenario:

Error occurs without showing any images...

Field does not exist:

That happens if you set field(s) that contain images to use "CropImage" type instead of "Image" type.

You can fix that by adding two lines in ManageFiles.module, first at line 62:

Replace:

$fields = $this->fields->find('type=FieldtypeFile|FieldtypeImage')->getArray();

with:

$fields = $this->fields->find('type=FieldtypeFile|FieldtypeImage|FieldtypeCropImage')->getArray();

and on line 164:

Replace:

if($field == 'InputfieldImage' || $field == 'InputfieldFile') {

with:

if($field == 'InputfieldImage' || $field == 'InputfieldCropImage' || $field == 'InputfieldFile') {
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Thanks Nico for this module.

Please may I ask, how I can allow a non superuser to see the 'Files' link in the admin? I've looked at hidden templates (etc) but can't see a way to do this.

Link to comment
Share on other sites

Alan, for non superuser to see the custom admin page, the module requires a permission set in getModuleInfo static method:

simplest would be to add:

"permission" => "page-edit"

you could also create a custom permission and add that to the roles you want them to see the admin page.

  • Like 1
Link to comment
Share on other sites

@Soma I looked but couldn't find in Google a page that covers 'permissions' and 'page-edit' http://goo.gl/Pw6ZB — if you think this is a page of documentation that should be added and if there is a place to note that I would be happy to go and note it — anything I can do to help.

And just in case it helps anyone else, I also found (presumably by design as part of 2.1/2.2) that

they must also have access to a permission with the same name as the module

is indeed not true for 2.2, that is, I wanted to add permission for the module ManageFiles and I was able to add a Permission called randomname and the line "'permission' => 'randomname'" in the module file worked fine.

Link to comment
Share on other sites

Alan, this seemed to be true for 2.0. I think. I would search with site:processwire.com permission page-edit https://www.google.c...iw=1352&bih=850

Mainly it's simple and straight forward. If the module has no "permission" set only superuser will see it. If it has a "permission" the user has assigned to one of he's roles he will see the page in the admin. So "page-edit" is a possibility, but not the only solution.

If one creates a module (look at AdminBar) he can decide to give it for example a "adminbar" permission, so it can be used for site admin to give access to only certain users using that permission.

Edit: So far this is mainly for advanced module developement, which isn't covered anywhere yet, but will in the near future.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...