WordPress.org

Ready to get started?Download WordPress

Forums

POST2PDF Converter
[resolved] Relative Hyperlinks does not work (6 posts)

  1. Coksnuss
    Member
    Posted 2 years ago #

    Hi redcocker,

    your fast response & acting regarding my last support request, leads me to an other one:

    Hyperlinks within the PDF does not always work properly.

    Example #1:
    HTML: "Relative Link"
    PDF: "file:///relative-link"

    (Should be http(s)://www.example.tld/relative-link)

    Example #2:
    HTML: "<b>Document name</b>, Version
    PDF: "file:///<TEMPDIR>/<PDF DOCUMENT>.pdf?aid=1736&sa=1"

    In this case an absolute URL is given, but is then somehow converted so that the URL that the user called when reading the article (https://www.example.tld/worpress/article/) is replaced by the PDF document location on local harddrive (file:///<TEMPDIR>/<PDF DOCUMENT>.pdf)

    External (absolute) links seems to work correctly.

    Could you provide a fix for this? Thanks in advance

    http://wordpress.org/extend/plugins/post2pdf-converter/

  2. Coksnuss
    Member
    Posted 2 years ago #

    Errr.. Sorry, didn't new that the HTML code that i type in here is actually parsed.

    Again in Codeblocks:
    Example #1:

    HTML: "<a href="/relative-link">Relative Link</a>"
    PDF: "file:///relative-link"

    (Should be http(s)://www.example.tld/relative-link)

    Example #2:

    HTML: "<a href="https://www.example.tld/worpress/article/?aid=1736&sa=1" title="Document name"><b>Document name</b>, Version</a>
    PDF: "file:///<%TEMPDIR>;/<PDF DOCUMENT>.pdf?aid=1736&sa=1"

    In this case an absolute URL is given, but is then somehow converted so that the URL that the user called when reading the article (https://www.example.tld/worpress/article/) is replaced by the PDF document location on local harddrive (file:///<%TEMP%><PDF DOCUMENT>.pdf)

  3. Coksnuss
    Member
    Posted 2 years ago #

    Hey,

    i found a workaround for myself, but if i use it i am unable to update the plugin without override the changes.

    The basic idea is to edit the file located in post2pdf-converter/post2pdf-converter-pdf-maker.php and add some "search/replace" routine @line 488 (below shortcode parsing).

    Assuming that you have two variables which contains the siteurl (e.g. $siteurl = 'http://www.example.com') while the other one holds the referer of the calling page (e.g. `$fullpath = 'http://www.example.com/cat/my-article') one can use this code to replace all relative URLs in href-attributes and replace them by absolute links:

    preg_replace('/(<a [^>]*href=)"([^"]+)/e', "substr('$2', 0, 4) === 'http' ? '$1' . '\"' . '$2' : substr('$2', 0, 1) === '/' ? '$1' . '\"' . '$siteurl' . '$2' : '$1' . '\"' . '$fullpath' . '/' . '$2'", content);

    This line could be made somehow more readable. But i think you get the idea. It basicly checks if the URL given in an href-attribute within an a-tag is
    1) absolute
    2) relative to current URL
    3) reltive to domain
    In the first case the link is left as it it, while in the second and third case the link is expanded to an absolute URL.

    Hope you can implement a fix soon.

  4. redcocker
    Member
    Plugin Author

    Posted 2 years ago #

    Hi, Coksnuss san

    Thank you for your report and idea.

    I will fix it in future release.

  5. redcocker
    Member
    Plugin Author

    Posted 2 years ago #

    Hi, Coksnuss san

    Please try to re-install Development Version.

    I fixed it.
    But I can't reproduct following issue.

    HTML: "<a href="https://www.example.tld/worpress/article/?aid=1736&sa=1" title="Document name"><b>Document name</b>, Version</a>
    PDF: "file:///<%TEMPDIR>;/<PDF DOCUMENT>.pdf?aid=1736&sa=1"
  6. Coksnuss
    Member
    Posted 2 years ago #

    Thanks again.

    For some reason the development version also fixed the issue that you couldn't reproduce :).

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic