You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a well known topic but has not yet been resolved. @svivian I cannot find the original discussion in the qa-forum, but this problem is so important that I need to issue it here.
Situation: Often programmers need to point to some files like CSS or JS that is located in their plugin folder.
Problem: How to get the correct path to the plugin, under all possible circumstances.
The approach until now:
Create a layer.
And code like that (example from one of the q2apro plugins):
class qa_html_theme_layer extends qa_html_theme_base {
// needed to get the plugin url
function qa_html_theme_layer($template, $content, $rooturl, $request)
{
if(qa_opt('q2apro_bestusers_enabled')) {
global $qa_layers;
$this->plugin_url_bestuserspro = $qa_layers['q2apro Best Users Layer']['urltoroot'];
}
qa_html_theme_base::qa_html_theme_base($template, $content, $rooturl, $request);
}
// ...
Now I can use $this->plugin_url_bestuserspro everywhere to get the path.
WRONG!
If the user has not enabled friendly URLs, but uses queries / URLs such as domain.com/index.php?qa=208&qa_1=24 the output looks like this:
So my urgent request: Please provide a core function that you throw in the plugin name and that returns the correct path, which should work for all URL structures.
My not-foolproof workaround for now:
// option_neat_urls is set to userfriendly URLs that path is correctly set
$neaturls = qa_opt('neat_urls');
if($neaturls==1) {
$this->output('<link rel="stylesheet" type="text/css" href="'.qa_path($this->plugin_url_bestuserspro).'styles.css">');
}
else {
// important: if user changes the plugin folder name it will not work!
$this->output('<link rel="stylesheet" type="text/css" href="'.qa_opt('site_url').'qa-plugin/q2apro-best-users-pro/styles.css">');
}
}
// insert CSS file
function head_script(){
qa_html_theme_base::head_script();
if(qa_opt('q2apro_bestusers_enabled')) {
if($this->request == 'bestusers' || $this->request == 'bestusers-year') {
// option_neat_urls is set to userfriendly URLs that path is correctly set
$neaturls = qa_opt('neat_urls');
if($neaturls==1) {
$this->output('<link rel="stylesheet" type="text/css" href="'.qa_path($this->plugin_url_bestuserspro).'styles.css">');
}
else {
// important: if user changes the plugin folder name it will not work!!!
$this->output('<link rel="stylesheet" type="text/css" href="'.qa_opt('site_url').'qa-plugin/q2apro-best-users-pro/styles.css">');
}
}
}
}
The text was updated successfully, but these errors were encountered:
OK unless I'm misunderstanding your issue, you should be able to just use the QA_HTML_THEME_LAYER_URLTOROOT constant, as described in the docs: http://www.question2answer.org/layers.php
So you can get rid of the class contructor (qa_html_theme_layer function) and instead of using $this->plugin_url_bestuserspro put QA_HTML_THEME_LAYER_URLTOROOT instead.
This is a well known topic but has not yet been resolved. @svivian I cannot find the original discussion in the qa-forum, but this problem is so important that I need to issue it here.
Situation: Often programmers need to point to some files like CSS or JS that is located in their plugin folder.
Problem: How to get the correct path to the plugin, under all possible circumstances.
The approach until now:
class qa_html_theme_layer extends qa_html_theme_base {
Now I can use
$this->plugin_url_bestuserspro
everywhere to get the path.WRONG!
If the user has not enabled friendly URLs, but uses queries / URLs such as domain.com/index.php?qa=208&qa_1=24 the output looks like this:
And leads to a 404 not found!
So my urgent request: Please provide a core function that you throw in the plugin name and that returns the correct path, which should work for all URL structures.
My not-foolproof workaround for now:
The text was updated successfully, but these errors were encountered: