Jump to content
Nico Knoll

Module: Manage Files

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

Share this post


Link to post
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

Share this post


Link to post
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?)

Share this post


Link to post
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...

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Nico & Soma,

any chance of further developmnet of this plugin? Deleting images through file manager would be quite nice.

Thx

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

works perfectly Nico!

edit: although it tells me that all files are 0MB. Should be measured in KB maybe

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Great work, Nico. Gonna check it out as soon as I have time. And I need to find a way to collect and categorize all this cool little snippets Ryan's posting here :)

Share this post


Link to post
Share on other sites

OK, new version is up (fixed point 1 and 2 of Ryan's).

@Ryan: (Point 3) I need this to find the "InputfieldFiles" and the "InputfieldImages", I guess...

Share this post


Link to post
Share on other sites

Nico, I guess the question is then, why do you need those Inputfields? :) I can't figure out why they are necessary there.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By David Karich
      ProcessWire InputfieldRepeaterMatrixDuplicate
      Thanks to the great ProModule "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use a content module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      This module extends the commercial ProModule "RepeaterMatrix" by the function to duplicate repeater items from one page to another page. The condition is that the target field is the same matrix field from which the item is duplicated. This module is currently understood as proof of concept. There are a few limitations that need to be considered. The intention of the module is that this functionality is integrated into the core of RepeaterMatrix and does not require an extra module.
      Check out the screencast
      What the module can do
      Duplicate a repeater item from one page to another No matter how complex the item is Full support for file and image fields Multilingual support Support of Min and Max settings Live synchronization of clipboard between multiple browser tabs. Copy an item and simply switch the browser tab to the target page and you will immediately see the past button Support of multiple RepeaterMatrix fields on one page Configurable which roles and fields are excluded Duplicated items are automatically pasted to the end of the target field and set to hidden status so that changes are not directly published Automatic clipboard update when other items are picked Automatically removes old clipboard data if it is not pasted within 6 hours Delete clipboard itself by clicking the selected item again Benefit: unbelievably fast workflow and content replication What the module can't do
      Before an item can be duplicated in its current version, the source page must be saved. This means that if you make changes to an item and copy this, the old saved state will be duplicated Dynamic loading is currently not possible. Means no AJAX. When pasting, the target page is saved completely No support for nested repeater items. Currently only first level items can be duplicated. Means a repeater field in a repeater field cannot be duplicated. Workaround: simply duplicate the parent item Dynamic reloading and adding of repeater items cannot be registered. Several interfaces and events from the core are missing. The initialization occurs only once after the page load event Changelog
      1.0.4
      Bug fix: Various bug fixes and improvements in live synchronization Bug fix: Items are no longer inserted when the normal save button is clicked. Only when the past button is explicitly clicked Feature: Support of multiple repeater fields in one page Feature: Support of repeater Min/Max settings Feature: Configurable roles and fields Enhancement: Improved clipboard management Enhancement: Documentation improvement Enhancement: Corrected few typos #1 1.0.3
      Feature: Live synchronization Enhancement: Load the module only in the backend Enhancement: Documentation improvement 1.0.2
      Bug fix: Various bug fixes and improvements in JS functions Enhancement: Documentation improvement Enhancement: Corrected few typos 1.0.1
      Bug fix: Various bug fixes and improvements in the duplication process 1.0.0
      Initial release Support this module
      If this module is useful for you, I am very thankful for your small donation: Donate 5,- Euro (via PayPal – or an amount of your choice. Thank you!)
      Download this module
      > Github: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate
      > PW module directory: – soon –
    • By Robin S
      A community member raised a question and I thought a new sanitizer method for the purpose would be useful, hence...
      Sanitizer Transliterate
      Adds a transliterate method to $sanitizer that performs character replacements as defined in the module config. The default character replacements are based on the defaults from InputfieldPageName, but with uppercase characters included too.
      Usage
      Install the Sanitizer Transliterate module.
      Customise the character replacements in the module config as needed.
      Use the sanitizer on strings like so:
      $transliterated_string = $sanitizer->transliterate($string);
       
      https://github.com/Toutouwai/SanitizerTransliterate
      https://modules.processwire.com/modules/sanitizer-transliterate/
       
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version to 2.10, add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By thomasaull
      I created a little helper module to trigger a CI pipeline when your website has been changed. It's quite simple and works like this: As soon as you save a page the module sets a Boolean via a pages save after hook. Once a day via LazyCron the module checks if the Boolean is set and sends a POST Request to a configurable Webhook URL.
      Some ideas to extend this:
      make request type configurable (GET, POST) make the module trigger at a specified time (probably only possible with a server cronjob) trigger manually Anything else? If there's interest, I might put in some more functionality. Let me know what you're interested in. Until then, maybe it is useful for a couple of people 🙂
      Github Repo: https://github.com/thomasaull/CiTrigger
    • By Robin S
      I created this module a while ago and never got around to publicising it, but it has been outed in the latest PW Weekly so here goes the support thread...
      Unique Image Variations
      Ensures that all ImageSizer options and focus settings affect image variation filenames.

      Background
      When using methods that produce image variations such as Pageimage::size(), ProcessWire includes some of the ImageSizer settings (height, width, cropping location, etc) in the variation filename. This is useful so that if you change these settings in your size() call a new variation is generated and you see this variation on the front-end.
      However, ProcessWire does not include several of the other ImageSizer settings in the variation filename:
      upscaling cropping, when set to false or a blank string interlace sharpening quality hidpi quality focus (whether any saved focus area for an image should affect cropping) focus data (the top/left/zoom data for the focus area) This means that if you change any of these settings, either in $config->imageSizerOptions or in an $options array passed to a method like size(), and you already have variations at the requested size/crop, then ProcessWire will not create new variations and will continue to serve the old variations. In other words you won't see the effect of your changed ImageSizer options on the front-end until you delete the old variations.
      Features
      The Unique Image Variations module ensures that any changes to ImageSizer options and any changes to the focus area made in Page Edit are reflected in the variation filename, so new variations will always be generated and displayed on the front-end.
      Installation
      Install the Unique Image Variations module.
      In the module config, set the ImageSizer options that you want to include in image variation filenames.
      Warnings
      Installing the module (and keeping one or more of the options selected in the module config) will cause all existing image variations to be regenerated the next time they are requested. If you have an existing website with a large number of images you may not want the performance impact of that. The module is perhaps best suited to new sites where image variations have not yet been generated.
      Similarly, if you change the module config settings on an existing site then all image variations will be regenerated the next time they are requested.
      If you think you might want to change an ImageSizer option in the future (I'm thinking here primarily of options such as interlace that are typically set in $config->imageSizerOptions) and would not want that change to cause existing image variations to be regenerated then best to not include that option in the module config after you first install the module.
       
      https://github.com/Toutouwai/UniqueImageVariations
      https://modules.processwire.com/modules/unique-image-variations/
×
×
  • Create New...