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
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- rgasch created topic »Using PageUtil::addVar() to load script code« 11:48 AM
- michiel responded to »password problem« 10:01 AM
- mazdev responded to »Hide "Register new account" and change template to 3 col« 07:50 AM
- mesteele101 created topic »Zikula 1.3.3 - Site Search 1.5.2 - Unable to turn off plug-ins« 07:48 AM
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 25. May
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 25. May
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 25. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Is there a modifier to convert relative to absolute URLs?
-
- Rank: Registered User
- Registered: Jul 13, 2009
- Last visit: Apr 03, 2010
- Posts: 16
-
- Rank: Team Member
- Registered: Jan 19, 2003
- Last visit: Apr 06, 2010
- Posts: 442
-
- Rank: Registered User
- Registered: Jul 13, 2009
- Last visit: Apr 03, 2010
- Posts: 16
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 -
- Rank: Softmore
- Registered: May 30, 2005
- Last visit: May 31, 2010
- Posts: 340
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
*/ -
- Rank: Registered User
- Registered: Jul 13, 2009
- Last visit: Apr 03, 2010
- Posts: 16
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 -
- Rank: Team Member
- Registered: Jan 19, 2003
- Last visit: Apr 06, 2010
- Posts: 442
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 -
- Rank: Registered User
- Registered: Jul 13, 2009
- Last visit: Apr 03, 2010
- Posts: 16
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!
- Moderated by:
- Support
