Development Generating URIs
From Contrexx Wiki (English)
There are many cases where you need to generate a link for the output.
The way of generating a link/URI depends on how the request was made and what purpose the link/URI is for.
Contents |
[edit] Tools
[edit] Escaping File Paths
The method FWValidator::getEscapedSource() can be used to prepare the path of a file for its use in the source attribute of a HTML-tag. The method will ensure that special characters like spaces or quotes will be escaped correctly.
// This will output the string:<img src="/images/content/foo%20bar%20%22%20%24.jpg" /> echo '<img src="'.FWValidator::getEscapedSource('/images/content/foo bar " $.jpg').'" />;
[edit] Request: Frontend
[edit] Output: Frontend - direct (Browser)
/* some output examples: * * # useVirtualLanguagePath is set to off * /index.php * * # useVirtualLanguagePath is set to off and the cms is located in the subdirectory website * /website/index.php * * # useVirtualLanguagePath is set to on and the user requested the english content * /en/index.php * * # useVirtualLanguagePath is set to on and the user requested the english content * # in addition the cms is located in the subdirectory website * /website/en/index.php * */ $uri = CONTREXX_SCRIPT_PATH
[edit] Output: Frontend - indirect (RSS Feeds, E-Mails)
/* some output examples: * * # useVirtualLanguagePath is set to off * http://www.example.com/index.php * * # useVirtualLanguagePath is set to off and the cms is located in the subdirectory website * http://www.example.com/website/index.php * * # useVirtualLanguagePath is set to on and the user requested the english content * http://www.example.com/en/index.phpp * * # useVirtualLanguagePath is set to on and the user requested the english content * # in additino the cms is located in the subdirectory website * http://www.example.com/website/en/index.php * */ $uri = ASCMS_PROTOCOL.'://' .$_CONFIG['domainUrl'] .($_SERVER['SERVER_PORT'] == 80 ? NULL : ':'.intval($_SERVER['SERVER_PORT'])) .CONTREXX_SCRIPT_PATH
[edit] Request: Backend
[edit] Output: Frontend - direct (Browser)
/* some output examples: * * # useVirtualLanguagePath is set to off * http://www.example.com/index.php * * # useVirtualLanguagePath is set to off and the cms is located in the subdirectory website * http://www.example.com/website/index.php * * # useVirtualLanguagePath is set to on and the user requested the english content * http://www.example.com/en/index.php * * # useVirtualLanguagePath is set to on and the user requested the english content * # in addition the cms is located in the subdirectory website * http://www.example.com/website/en/index.php * */ $uri = ASCMS_PATH_OFFSET .($_CONFIG['useVirtualLanguagePath'] == 'on' ? '/'.$objLanguage->getLanguageParameter($intLanguageId, 'lang') : NULL) .'/'.CONTREXX_DIRECTORY_INDEX
[edit] Output: Frontend - indirect (RSS Feeds, E-Mails)
/* some output examples: * * # useVirtualLanguagePath is set to off * http://www.example.com/index.php * * # useVirtualLanguagePath is set to off and the cms is located in the subdirectory website * http://www.example.com/website/index.php * * # useVirtualLanguagePath is set to on and the user requested the english content * http://www.example.com/en/index.php * * # useVirtualLanguagePath is set to on and the user requested the english content * # in addition the cms is located in the subdirectory website * http://www.example.com/website/en/index.php * */ $uri = ASCMS_PROTOCOL.'://' .$_CONFIG['domainUrl'] .($_SERVER['SERVER_PORT'] == 80 ? NULL : ':'.intval($_SERVER['SERVER_PORT'])) .ASCMS_PATH_OFFSET .($_CONFIG['useVirtualLanguagePath'] == 'on' ? '/'.$objLanguage->getLanguageParameter($intLanguageId, 'lang') : NULL) .'/'.CONTREXX_DIRECTORY_INDEX
