anttiviljami / wp-pdf-templates

Add PDF templates to your WordPress theme
https://wordpress.org/plugins/wp-pdf-templates
GNU General Public License v3.0
42 stars 18 forks source link

Fixing Issue 17 #18

Closed e3betht closed 8 years ago

e3betht commented 8 years ago

This fixes Issue 17 (https://github.com/anttiviljami/wp-pdf-templates/issues/17) where $html is not empty, but localhost is not writable, which leads to blank PDFs. This is most likely to happen on shared hosting environments where localhost is not configured correctly.

anttiviljami commented 8 years ago

I don't understand how this works. How can you check the writability of a web URL?

e3betht commented 8 years ago

You can check using the is_writable() function in PHP: http://php.net/manual/en/function.is-writable.php

We can also just check if the directory is writable, which would allow for line 213 to be moved after the is_writable() and prevent it from having to be duplicated. I can make that update in my PR if you'd like.

On 5/3/16 2:31 PM, Antti Kuosmanen wrote:

I don't understand how this work. How can you check the writability of a web URL?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/anttiviljami/wp-pdf-templates/pull/18#issuecomment-216640106

Beth Tucker Long Treeline Design, LLC 807 Arbor Vitae Place Verona, WI 53593 608-770-6677 http://www.TreelineDesign.com

anttiviljami commented 8 years ago

I'm sorry, but I think you're confused by what is_writable() does. It checks the writability of a file path in the filesystem, not a URL. Passing a URL value as a parameter to is_writable will always return false due to URLs starting with http:// or https:// not being valid filesystem paths.

I agree that just checking empty() is not enough, but this pull request will not work.

anttiviljami commented 8 years ago

Closing this pull request.

Let me know if you can come up with a better way to check if localhost is configured correctly! :)

e3betht commented 8 years ago

As of PHP 5.0, is_writable() supports file://, so we could use that instead of http:// to check writability of the dir.

Beth Tucker Long Treeline Design, LLC 807 Arbor Vitae Place Verona, WI 53593 608-770-6677 http://www.TreelineDesign.com

On May 3, 2016, at 14:38, Antti Kuosmanen notifications@github.com wrote:

I'm sorry, but I think you're confused by what is_writable() does. It checks the writability of a file path in the filesystem, not a URL. Passing a URL value as a parameter to is_writable will always return false due to URLs starting with http:// or https:// not being valid filesystem paths.

I agree that just checking empty() is not enough, but this pull request will not work.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub

anttiviljami commented 8 years ago

but then that would not help with our localhost problem :)

anttiviljami commented 8 years ago

Really, what we should be checking is whether localhost points to the local Wordpress installation. That can't be done via the file:// URLs.

e3betht commented 8 years ago

How about testing: if (file_put_contents($link, 'test') === false) {

This would tell us if the file is writable. Beth

On 5/3/16 3:19 PM, Antti Kuosmanen wrote:

Really, what we should be checking is whether localhost points to the local Wordpress installation. That can't be done via the file:// URLs.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/anttiviljami/wp-pdf-templates/pull/18#issuecomment-216652593

Beth Tucker Long Treeline Design, LLC 807 Arbor Vitae Place Verona, WI 53593 608-770-6677 http://www.TreelineDesign.com

anttiviljami commented 8 years ago

again. we can't file_put_contents to a http url. same issue as with is_writable.

e3betht commented 8 years ago

From the PHP.net documentation for file_put_contents():

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

I checked, and allow_url_fopen has defaulted to 1 since PHP 4.0.4.

So, it's not a guarantee, but it's something.

On 5/3/16 3:31 PM, Antti Kuosmanen wrote:

again. we can't file_put_contents to a http url. same issue as with is_writable.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/anttiviljami/wp-pdf-templates/pull/18#issuecomment-216655548

Beth Tucker Long Treeline Design, LLC 807 Arbor Vitae Place Verona, WI 53593 608-770-6677 http://www.TreelineDesign.com