Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.1

Bug #12306 Can't make relative links with only a filename.
Submitted: 2007-10-23 00:58 UTC
From: cwiedmann Assigned: quipo
Status: Closed Package: Pager (version 2.4.4)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2007-10-23 00:58 UTC] cwiedmann (Carsten Wiedmann)
Description: ------------ Hello, sometimes I want have only relative links, without an abs_path and only a filename. For a test, put the testscript with the name "test.php" into the directory "$DocumentRoot/foo/" and request it with "http://www.example.com/foo/test.php". (The difference in the result is the "/" prepending the filename.) Regards, Carsten Test script: --------------- <?php require_once 'Pager.php'; $params = array( 'mode' => 'Sliding', 'path' => '', 'itemData' => range('a', 'z') ); $pager = Pager::factory($params); echo nl2br(htmlspecialchars($pager->linkTags)); ?> Expected result: ---------------- <link rel="next" href="test.php?pageID=2" title="next page" /> <link rel="last" href="test.php?pageID=3" title="last page" /> Actual result: -------------- <link rel="next" href="/test.php?pageID=2" title="next page" /> <link rel="last" href="/test.php?pageID=3" title="last page" />

Comments

 [2007-11-25 16:21 UTC] quipo (Lorenzo Alberton)
I've added a new 'addSlash' boolean option to allow relative links. Set it to false and the slash will not be added.
 [2007-11-29 10:03 UTC] cwiedmann (Carsten Wiedmann)
> I've added a new 'addSlash' boolean option > to allow relative links. I do not aggree with this change. For example with this code: | <?php | require_once 'Pager.php'; | | $params = array( | 'mode' => 'Sliding', | 'itemData' => range('a', 'z'), | 'addSlash' => false | ); | $pager = Pager::factory($params); | | echo nl2br(htmlspecialchars($pager->linkTags)); | ?> The result is now: <link rel="next" href="/testtest.php?pageID=2" title="next page" /> <link rel="last" href="/testtest.php?pageID=3" title="last page" /> As you see in my patch from Request #12267, there was only a problem, because you allways prepend _fileName with a "/", also if _path is empty, while your are building _url. Maybe there is a problem how I have fiexed this, which I not see? For example if I set: | 'path' => 'test/', it's still possible to set a realtive path with the old code. And with your patch, _url is also relative, regardless how I set "addSlash". (There was only a problem when you set "path" to an empty string) Regards, Carsten
 [2007-11-29 13:20 UTC] quipo (Lorenzo Alberton)
The current behaviour is somewhat intentional, there are cases when the leading slash is necessary indeed (@see bug #2617). My last patch should let you decide the desired behaviour. Considering that both are valid concerns, and must be both addressed, what do you propose, exactly? I can't check right now if a simple "is_empty($this->_path)" check preserves BC, I need to add a few test cases.
 [2007-11-29 14:59 UTC] cwiedmann (Carsten Wiedmann)
| The current behaviour is somewhat intentional, there | are cases when the leading slash is necessary indeed | (@see bug #2617). Well, I think this bug is a bad example. PHP_SELF is not only a path, it's allways the uri-path to the current script with filename, even if you call the script in your browser without filename. I think this user have another problem with his code ;-) and he should not change PHP_SELF in his code. Better use path, fileName and fixFileName from Pager. Well, I've tried to simulate his script: | <?php | $_SERVER['PHP_SELF'] = dirname($_SERVER['PHP_SELF']).'/'; | | require_once 'Pager.php'; | | $files = glob('*.php'); | unset($files[reset(array_keys($files, 'index.php'))]); | $files = array_values($files); | | $params = array( | 'mode' => 'Sliding', | 'perPage' => 3, | // 'path' => '', | // 'fileName' => '', | // 'fixFileName' => false, | 'itemData' => $files | ); | $pager = Pager::factory($params); | | $links = $pager->getLinks(); | echo $links['all'].PHP_EOL; | echo '<br>'.PHP_EOL; | | $data = $pager->getPageData(); | foreach ($data as $file) { | echo "<a href='{$file}'>{$file}</a><br>".PHP_EOL; | } | ?> Put also a couple of other *.php files in the test dir and browse to it with "http://localhost/test/". Works without problems (with my patch). And if you appply my patch, you have correct relative links, if you set "perPage" to "". | --- Common.php 29 Jul 2007 08:10:34 -0000 1.60 | +++ Common.php 29 Nov 2007 14:36:56 -0000 | @@ -1417,11 +1417,11 @@ | if ($this->_fixFileName) { | $this->_fileName = CURRENT_FILENAME; //avoid possible user error; | } | - $this->_url = $this->_path.'/'.$this->_fileName; | + $this->_url = $this->_path.(!empty($this->_path) ? '/' : '').$this->_fileName; | } else { | $this->_url = $this->_path; | if (strncasecmp($this->_fileName, 'javascript', 10) != 0) { | - $this->_url .= '/'; | + $this->_url .= !empty($this->_path) ? '/' : ''; | } | if (strpos($this->_fileName, '%d') === false) { | trigger_error($this->errorMessage(ERROR_PAGER_INVALID_USAGE), E_USER_WARNING); Regards, Carsten
 [2007-12-01 13:30 UTC] quipo (Lorenzo Alberton)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.