Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for pwg format served alternative format files #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

extorn
Copy link

@extorn extorn commented Feb 17, 2021

This adds support for resources of any type served under the pwg_format child folder of a piwigo site.


if (in_array($type, $arrayZips) && in_array($original_extension, $arrayExtensions))
{
return $original_extension;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you return the extension here and not the mime type ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is heavily based on code I found on the internet. Using the mime type of the file is inappropriate since it is a zip file. So, you want to return a mime type that identifies it as an ms word document or excel document etc. I'm not sure if anyone actually serves files of this type, but it didn't seem to harm by leaving it in.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I recall, the place I got this from said there is no mime type specific to e.g. an ms excel or ms word file, hence just use the file extension as that. Whether that is true or not I did not check.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense for a method that suppose to return the mime type to return the extension instead.
I'm not sure what the issue with zips is, but I doubt if it's relevant to what this plugin does.
If you can find the source of this code and the reason for it we can reconsider.

return $original_extension;
}
// strip the charset encoding part
$type = preg_replace('#^([a-zA-Z*]*/[a-zA-Z*]*).*$#','$1',$type);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it be better to use FILEINFO_MIME_TYPE so you won't have the encoding in the first place?
Also won't having the encoding cause the previous checks to always be false as the mime arrays do not contain any encoding info ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FILEINFO_MIME_TYPE isn't always available depending on php version. I'm not well versed in php. I've taken such statements at face value.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From PHP doc FILEINFO_MIME_TYPE is available since php 5.3.0 so we can use it without any worries.
It seem like this makes this whole function obsolete if we don't need to hack around zip files

// the the base path for the original file
$base_img_path = preg_replace('#(.*/)[^/]*\.[^.]*$#','$1',$original_file_path);
// get the filename without extension of the original file
$base_img_name = preg_replace('#.*/([^/]*)\.[^.]*$#','$1',$original_file_path);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this regex looks a bit comple. Any reason not to use pathinfo here instead ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not specifically. I know regexp, I don't know php :-)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's probably better to see if pathinfo info gives the desired results and use it instead

This was referenced Mar 20, 2021
@extorn
Copy link
Author

extorn commented Mar 20, 2021

I don't mind what changes you make to achieve what this code does, but in a simpler more php minded way.
I am using the changes to successfully serve files of type mp4, m4a, jpg from a subfolder hosted piwigo server.
I tested with pwg_format folder hosted files too.

@yonjah
Copy link
Owner

yonjah commented Mar 21, 2021

@extorn I'm not sure from your other comments if you want to work on this PR or you just want me to try and add this logic in (will probably take longer).
Also can you comment how you use the plugin ? do you use the redirect header to let nginx serve the static files ?
If you do it seem like most of this changes are irrelevant to your setup.

@extorn
Copy link
Author

extorn commented Mar 21, 2021

@yonjah, I don't really want to work on the PR thanks. I read through the code, gained a basic understanding sufficient to provide some kind of a fix. PHP isn't a language I am confident in, so I am certain that you'll achieve a working version quicker on your own from the boost this code has hopefully provided than I would by searching the net for PHP example code I can cobble together. It stands to reason that you'll understand this code base substantially better than I.

@Catfriend1
Copy link

I'll fork and try this thing now.

@Catfriend1
Copy link

Sorry, this does not work for me. I've got .pdf files in my gallery and added ".pdf" / "application/pdf" to the two arrays changed in code above but then my gallery was broken. No more pictures are viewed and no pdf files miss the /sessId/ prefix leading to a http 404 error code.

@yonjah
Copy link
Owner

yonjah commented Apr 1, 2021

Sorry, this does not work for me. I've got .pdf files in my gallery and added ".pdf" / "application/pdf" to the two arrays changed in code above but then my gallery was broken. No more pictures are viewed and no pdf files miss the /sessId/ prefix leading to a http 404 error code.

Have you tried with the base plugin ? I'm not sure you need this changes.

Also 404 error might be an issue with your http server config.
We need to see your config and the exact URL that fails (reducting any sensitive info like domain or exact filenames)
Also try to disable the plugin and compare the file url

@Catfriend1
Copy link

I'll gather this info and report back. The v1.0.1 base does not work, too. I've used "charlies-content" plugin to displays the pdf files directly in the gallery. if I disable the nginx stuff and piwigo_privacy, it works correctly.

@yonjah
Copy link
Owner

yonjah commented Apr 4, 2021

I'll gather this info and report back. The v1.0.1 base does not work, too. I've used "charlies-content" plugin to displays the pdf files directly in the gallery. if I disable the nginx stuff and piwigo_privacy, it works correctly.

Maybe the plugin is using another path that is not defined in the basic nginx conf example ?
I wonder if the privacy plugin will work nicely with the other plugin as if it uses diffrent paths it might need some adjustments.
If pdf do load you need to make sure you can't accesses them directly when you are logged out of the system (to make sure the privacy plugin actually blocks access)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants