TwisterMc / pdfjs-viewer-shortcode

A Wordpress plugin for embedding PDFs using Mozilla's Excellent PDF.js
https://wordpress.org/plugins/pdfjs-viewer-shortcode/
Apache License 2.0
7 stars 4 forks source link

URLs being manipulated #8

Closed gms199 closed 3 years ago

gms199 commented 4 years ago

When updating the 1.5.2 the plugin is no longer loading the PDFs properly.

I am using this shortcode

[pdfjs-viewer url=https://octavosystems.com/octavosystems.com/wp-content/uploads/2020/04/OSD32MP1_BRK_SCH.pdf viewer_width=600px viewer_height=700px fullscreen=true download=true print=true]

I am getting this error message:

PDF.js v2.3.200 (build: 4ae3f9fc) Message: Missing PDF "https://octavosystems.com/wp-content/uploads/2020/04/OSD32MP1_BRK_SCH.pdf".

it looks like the URL path is being manipulated to pull out the second octavosystems.com in the correct URL.

erikwelsh commented 4 years ago

Look like this is an issue in commit:

https://github.com/TwisterMc/pdfjs-viewer-shortcode/commit/084814438ec02cecc513c3358ae51cd98ac14fce

$file_name = str_replace( get_site_url(), '', $file_name );

will replace the site url as many times as it occurs in the file name. In the above instance, this removes "octavosystems.com" multiple times from $file_name. You might want to use preg_replace() instead which has an optional limit on the number of replacements performed.

TwisterMc commented 4 years ago

I did not expect anyone to have their domain name in the URL twice. I've never seen that setup before. Is there a reason your site is setup this way?

I'll have to think up a work around as we're trying to fix a bigger issue by removing the domain name from the PDF URL.

gms199 commented 4 years ago

I think the installation was originally configured to support multisite but I am not sure. Unfortunately it was done for us and I no longer have access to the person that set it up.

Right now we are commenting out the line the @erikwelsh pointed out. That appears to fix our issue..

Thanks for the support.

TwisterMc commented 4 years ago

Ok, I'll look into just removing the first instance of the domain, hopefully that'll fix everyone's issues.

TwisterMc commented 4 years ago

I updated the plugin to only remove the first instance of the domain. Give it a whirl.

gms199 commented 4 years ago

Thanks @TwisterMc. I just checked my site and it appears to be having the same problem. I checked what get_site_url() is returning and it is actually this: https://octavosystems.com/octavosystems.com.

So I don't think it is the two occurrences but how the final URL is rebuilt. Let me know if you want me to test anything else out.

TwisterMc commented 4 years ago

I have an idea that I'll try to get pushed up soon. Currently I'm removing the site_url as set in WordPress when I should probably just be figuring out the domain and removing that.

TwisterMc commented 4 years ago

Ok, new version is up, hope it fixes the issue.

gms199 commented 4 years ago

That looks like it fixed it! Thanks for the awesome support.

On Thu, Sep 3, 2020 at 9:40 PM Thomas McMahon notifications@github.com wrote:

Ok, new version is up, hope it fixes the issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/TwisterMc/pdfjs-viewer-shortcode/issues/8#issuecomment-686866092, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLNQO2EGU7P4IZH4L52PLTSEBHRZANCNFSM4QNEVR2A .