Fork me on GitHub

Is there a modifier to convert relative to absolute URLs?  Bottom

  • Hi, I am writing a plugin to send some selected News using Mailz module. The problem is that the links sent with the news articles refer to relative paths, so in the mail they are received as http://index.php/News/whatever

    Is there a modifier to make the URL absolute?

    Thanks in advance
  • IIRC you can use:

    Code

    <!--[pnmodurl ... ... fqurl=1]-->


    --
    Guite | ModuleStudio
  • Thanks, that solved part of the problem!! I was looking for a way to do it in the PHP code too, as I want

    Code

    $preformat = pnModAPIFunc('News', 'user', 'getArticlePreformat', array('info' => $info, 'links' => $links));


    to return $preformat.hometext with absolute URLs (or in the template with a modifier with

    Code

    <!--[$preformat.hometext|a_nice_modifier]-->


    Is this possible?



    edited by: danx, datetimebrief
  • You can use the pnModURL in the code too, like so...

    Code

    $preformat = pnModURL('News', 'user', 'getArticlePreformat', array('info' => $info, 'links' => $links, 'furl' => 1));


    A good way to look this stuff up is to find the original function. The developers of Zikula have done a good job documenting the code. Here is the header to pnModURL.

    Code

    /**
     * generate a module function URL
     *
     * if the module is non-API compliant (type 1) then
     * a) $func is ignored.
     * b) $type=admin will generate admin.php?module=... and $type=user will generate index.php?name=...
     *
     * @author Jim McDonald <jim@mcdee.net>
     * @link http://www.mcdee.net
     * @param 'modname' the name of the module
     * @param 'type' the type of function to run
     * @param 'func' the specific function to run
     * @param 'args' the array of arguments to put on the URL
     * @param 'ssl'  set to constant null,true,false $ssl = true not $ssl = 'true'  null - leave the current status untouched, true - create a ssl url, false - create a non-ssl url
     * @param 'fragment' the framgment to target within the URL
     * @param 'fqurl' Fully Qualified URL. True to get full URL, eg for Redirect, else gets root-relative path unless SSL
     * @param 'forcelongurl' force pnModURL to not create a short url even if the system is configured to do so
     * @return sting absolute URL for call
     */
  • Paustian

    You can use the pnModURL in the code too, like so...

    Code

    $preformat = pnModURL('News', 'user', 'getArticlePreformat', array('info' => $info, 'links' => $links, 'furl' => 1));




    Yes, but in the PHP code I'm using pnModAPIFunc to get the news article; fqurl works with pnModURL, so it's not working...



    edited by: danx, datetimebrief
  • As the result of this API function is the whole article's text, I doubt that there is a really reliable solution without having to change all articles manually.
    You could try to do something like this:

    Code

    $baseURL = pnGetBaseURL();
        $preformat = str_replace('<a href="', '<a href="' . $baseURL, $preformat);
        $preformat = str_replace($baseURL . 'http', 'http', $preformat);

    It first adds the base path (http://example.com/) to all anchors. After that it removes it again for those links which were already absolute before.
    Note that this a quite dirty way to achieve what you are heading for. Maybe a regular expression (see php manual) would be appropriate to solve this problem more precisely.

    --
    Guite | ModuleStudio
  • Yes, I was thinking of using a regexp to do this, but thought that maybe it was already solved elsewhere in the zikula code with a cleaner method... Thanks a lot for your time, Guite, you really helped me!

This list is based on users active over the last 60 minutes.