Login | Sign up | Toll-Free: 1-800-752-0455
 
 

Forum

 

11 posts by 2 authors in: Forums > CMS Builder
Last Post: January 5, 2018

I wish to expand the upload strategy, see how to do it by passing the instance to upload_storage_strategy() great, but I thought there was a custom.php widget available to add stuff like this or I am just thinking of the js/css?

Don't want to do it as a plugin just want to add some code, did I miss something or should I ask for a custom.php to be loaded by the init process.

Thanks
Larry

---
<? Larry >
Coding since 1973

Hi Larry, 

All that code might change a bit when we implement a new uploader.  The original upload strategy was designed to support different methods.  We have a (internal, unsupported) plugin that stores uploads on Amazon S3.  So it was to have support for switching to/from that.

What are you wanting to do? 

Dave Edis - Senior Developer
interactivetools.com

At the moment all uploads go to one directory which is ok for smallish ones, I have implemented one where if it is the fieldName gallery it adds yyyy/mm to the file name.

So a a general thing the upload path allows you to put /my/main/path/{yyyy}/{mm} (or whatever) the url path would still be /my/main/path as the y/m is added to the file name in the uploads table. This is similar to what wordpress does for its uploads.

FWIW ... having more than a few hundred files in a single directory is a bad idea ;-)

---
<? Larry >
Coding since 1973

Check out the 'upload_saveAsFilename' plugin hook.  We've used that before to modify the name and/or path uploads are stored with on save.

Dave Edis - Senior Developer
interactivetools.com

By jenolan - December 22, 2017 - edited: December 22, 2017

Will have a gander, after the latest wordpress hack I am going to have to accelerate my move with the other site ... hohum

Just had a look ... no schema passed so can not process per field/table

---
<? Larry >
Coding since 1973

By Dave - December 22, 2017 - edited: December 22, 2017

Try $GLOBALS['schema']

These are also available (from /lib/menus/default/action_handler.php)

global $TABLE_PREFIX, $tableName, $escapedTableName, $action, $schema, $CURRENT_USER, $hasEditorAccess, $hasAuthorAccess, $hasViewerAccess, $hasViewerAccessOnly, $hasAuthorViewerAccess, $isMyAccountMenu, $isSingleMenu;

Dave Edis - Senior Developer
interactivetools.com

OK will look at that .... one thing that would be handy but probably too hard is a settings handler. Really hate coding the form stuff whinge moan I know

---
<? Larry >
Coding since 1973

By jenolan - December 22, 2017 - edited: December 23, 2017

I am trying as a straight filter ... all ok except ... how do I ascertain the fieldName for the upload that is being processed?

DefaultUploadStorageStrategy::storeMainFile() has $fieldSchema so the call to _saveUpload_chooseUniqueNumberedFilename() needs to add it and the hook call also needs to add it ... that should not cause any old hook issues.

Is this possible ... as my check is for tableName == 'blog'and fieldname == 'gallery' (as an example)

Thanks!

What I am about to try changed upload_functions.php line 295

// move main upload to long-term storage
$GLOBALS['fieldname'] = $fieldname;
upload_storage_strategy()->storeMainFile($mainUploadWorkingPath, $uploadInfo['name'], $fieldSchema, $uploadRecordDetails);
unset($GLOBALS['fieldname']);

OK that works for saving the filePath but the change is NOT made to the urlPath the base name is there so all of the file links fail ;-)

---
<? Larry >
Coding since 1973

What I have done is that for each of my areas, if I want a gallery I name the field 'gallery' set the upload information and my code adds the year/month to the name.

The problem (I think) with what you want is that the category is not necessarily set when the upload code is called. The actual file name is not really an issue if you are showing them on the site or am I missing something?

---
<? Larry >
Coding since 1973

Assuming the data (ie the name year model etc) is available, it would be possible to do it either when the record is saved or as a cron job, that's assuming you want the file names changed naturally.

---
<? Larry >
Coding since 1973