Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
953 views
in Plugins by
I want to publish a plugin but I need to be sure that it will work with all configurations supporting QA. Thank you for your time. I found some methods in the code plugins but I want to use the official ones - and not workarounds - for next versions compatibility purposes.

1) Apache documentroot
with mass hosting, older versions of Apache prior to 2.4 don't send the good documents roots to php.

2) with unix links
In the case where all the qa-* directories are links to the same location on the disk ( sharing the QA application  between domains , except qa-config.php and probably qa-index.php ) : the core "converts" the apparent path to the real path and when it goes up , it finds the upper directory of the directory linked and not the the directory containing the link

It's probably useless to enter in the details since the venerable core authors got their code working in all cases :)

Thus :
For plugins authors , what are the prepared core expressions of :
- the document root ( absolute disk path of the web root )
- the QA site location relative to the web root ? on the disk and on the web if not the same
Q2A version: 1.7

1 Answer

+1 vote
by
edited by
 
Best answer

You seem to be asking question that, most likely, you shouldn't be asking.

If you're writing a plugin then you should only care about the plugin itself. The only reason I can think of why you would need the abosolute path to the webroot is that you want to get into the core, other plugins or other themes. Assuming you aren't in a need of this then you shouldn't care about it at all. Understanding this specific need will lead to a better approach to solve your issue.

Assuming the plugin directory would be enough for you (in 99.99% cases it should), then it is not the same if you're in the context of the qa-plugin.php file, a layer or a module. The first ones are part of the global context, so you shouldn't add code to the qa-plugin.php other than the module registrations and some class loading logic. If you still want to add code in there then you should use the global variables $qa_plugin_directory (absolute path to the plugin directory) and $qa_plugin_urltoroot (relative path to the plugin directory from the requested page).

In the case of layer the same approach is followed but, as you can see here, some pieces of text (yes, you're reading it properly) are replaced during runtime into the appropriate directory path and urltoroot. These are QA_HTML_THEME_LAYER_DIRECTORY and QA_HTML_THEME_LAYER_URLTOROOT.

Modules are handled differently and in a better way. When they're registered they pass those parameters through the load_module($directory, $urltoroot, $type, $name) function. So just implement that function and it will work. You don't have to inherit anything as the function is called after checking it with a method_exists.

In the unlikely case in which these approaches are not enough, check the QA_BASE_DIR constant and the qa_path_to_root() function. Other functions in qa-base.php might be helpful too.

by
QA_BASE_DIR QA_INCLUDE_DIR QA_PLUGIN_DIR and qa_path_html(target) fit my needs ! Now it works with all the url structures. The only last thing is that I assume knowing the name of the plugin and that it is located in QA_PLUGIN_DIR. Perhaps it is normal ... Thank you again :)
by
That would be the plugin directory, which I mentioned in 3 different parts of the answer :) Even if you only need the plugin directory name only you could just apply a basename($directory)
by
what files exactly must I include to get global $qa_modules readable in the context of the module scripts ? TY. My next module will be a ( candidate ) ftp module installer and updater based on small scripts. I need to have a good representation of all kinds of installations and to understand all the lines of qa_options and config ...
by
I found this :  $bb  = qa_list_modules_info() ; $cc = $bb['module'][$name] with $name the one given at the module registration step. $cc['directory'] is the plugin directory and its basename the wanted name :) thank you for your help
...