hello devs,
recently I had some troubles with UserCollections and BatchDownloader with $conf["question_mark_in_urls"] = false
the initial problem was that I didn't use add_url_params() so all my urls where badly formed for this kinf of url
but the real issue is in one of my constants
define('USER_COLLEC_PUBLIC', make_index_url(array('section' => 'collections')) . '/');
I use make_index_url() which needs to have correclty initialized $page['root_path'] in order to return good urls
first I defined this constant in the main.inc.php of my plugins ($page['root_path'] is not initialized)
then I tried in the 'init' event ($page['root_path'] still not initialized)
the I tried in the 'loc_end_section_init' event, OK
BUT this event is not called on admin side, so I need to redefine my constant on admin side, I don't like that !
so here I what I want to do : move lines 48-73 of section_init.inc.php to common.inc.php (before the 'init' event obviously)
if ( $conf['question_mark_in_urls']==false and isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) { $rewritten = $_SERVER["PATH_INFO"]; $rewritten = str_replace('//', '/', $rewritten); $path_count = count( explode('/', $rewritten) ); $page['root_path'] = PHPWG_ROOT_PATH.str_repeat('../', $path_count-1); } else { $rewritten = ''; foreach (array_keys($_GET) as $keynum => $key) { $rewritten = $key; break; } // the $_GET keys are not protected in include/common.inc.php, only the values $rewritten = pwg_db_real_escape_string($rewritten); $page['root_path'] = PHPWG_ROOT_PATH; } if ( strncmp($page['root_path'], './', 2) == 0 ) { $page['root_path'] = substr($page['root_path'], 2); }
what do you think ? can this induces errors ?
ps: I plan this for 2.5
Offline
actually if it's possible for 2.4.4 or 2.4.5, it would be great
except if I miss something, using a constant for this kind of url is a plague (in admin, section_init is not included)
Offline
don't forget it can be overriden later. for example when sending mails, rss feeds, web service etc ...
Offline
and what are the consequences ?
are your for or against this modification ?
because look
http://piwigo.org/dev/browser/extension … ts.inc.php
I define my url line 18, and also line 206 for pages without section, I would like to use it in Batch Downloader but I can't (don't remember why),
+ same thing for Contact Form with one more declaration for admin side (which always give urls WITH question_mark)
(actually there is no more interrest of having a constant)
the point is $page['root_path'] is for me a major parameter, it should be accessible everytime
Offline
against!
if you want to have a defined constant in your init handler, than you should always use get_absolute_root_url()
Offline
thats not the problem !
the problem is the relative path returned by get_root_url() (in case of question_mark_in_url=false), which need $page['root_path'] to be initialized
get_absolute_root_url() doesn't do the job
and why against ? I don't understand
Offline
mistic100 wrote:
thats not the problem !
the problem is the relative path returned by get_root_url() (in case of question_mark_in_url=false), which need $page['root_path'] to be initialized
get_absolute_root_url() doesn't do the job
and why against ? I don't understand
I don't really understand the problem you explain either. Why get_absolute_root_url doesn't do the job ? I don't really get why you need to define a constant in your plugin ...
Offline
yeah, I made a mistake, get_absolute_root_url() is good, thank you for opening my eyes :D
I want a constant to have cleaner code, instead fo writing
get_absolute_root_url() . make_index_url(array('section' => 'collections')) . '/'
everywhere, I just write USER_COLLEC_PUBLIC
I still don't understand why this piece of code can't be in common.inc (now my only wish is a kind of uniformity) but as I don't need it anymore... not important
Offline
mistic100 wrote:
I still don't understand why this piece of code can't be in common.inc (now my only wish is a kind of uniformity) but as I don't need it anymore... not important
I think you can put $page['root_path'] in common, but from my point of view all the $rewritten part should be in section_init
Offline
well $rewritten is needed to create root_path :D
Offline
mistic100 wrote:
well $rewritten is needed to create root_path :D
yes yes ... something like
if ( $conf['question_mark_in_urls']==false and isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) { $page['root_path'] = PHPWG_ROOT_PATH.str_repeat('../', count( explode('/', str_replace('//', '/', $_SERVER["PATH_INFO"]) ) )-1); } else { $page['root_path'] = PHPWG_ROOT_PATH; } if ( strncmp($page['root_path'], './', 2) == 0 ) { $page['root_path'] = substr($page['root_path'], 2); }
You can put it just right after load_conf_from_db call ...
PS: I'm joking ... What I meant is in section_init we'll still need to look at the $GET etc ...
Offline