@adrienrn
Nice article ;)
File "madhouse_helloworld.zip" empties :(
Regards
The installation generated an error:
Fatal error: Call to undefined function mdh_current_plugin_path() in /homez.***/********/www/a/oc-content/plugins/madhouse_helloworld/index.php on line 12
Regards
<?php
function mdh_handle_error($target=NULL, $message=NULL) {
if($target == NULL) {
$target = osc_base_url();
}
if(is_null($message)) {
$message = __("Oops! We got confused at some point. Try to refresh the page.", "madhouse_utils");
}
osc_add_flash_error_message($message);
osc_redirect_to($target);
}
function mdh_handle_error_ugly($target=NULL, $message=NULL) {
if($target == NULL) {
$target = osc_base_url();
}
if(is_null($message)) {
$message = __("Oops! We got confused at some point. Try to refresh the page.", "madhouse_utils");
}
osc_add_flash_error_message($message);
echo sprintf("<script type='text/javascript'>window.location='%s'</script>", $target);
}
/**
* Returns the name of the current plugin (plugin in which the calling file is located)
* @returns a string (name of the plugin).
* @throws Exception if the calling file is not located in a plugin at all.
* @since 1.10
*/
function mdh_current_plugin_name($bt=NULL) {
if($bt == NULL) {
$bt = debug_backtrace();
}
if(! preg_match("#^/.*/oc-content/plugins/.*$#", $bt[0]['file'])) {
throw new Exception("Current file does not belong to a plugin!");
}
return preg_replace('#^([^/]+)/.*$#', '$1', osc_plugin_folder($bt[0]['file']));
}
/**
* Requires or returns the file of the current plugin.
* Ex. mdh_current_plugin_path("assets/img/logo.png") in madhouse_hello plugin will produce :
* '{ABS_PATH}/oc-content/plugins/madhouse_hello/assets/img/logo.png'
*
* @param $file relative path to the file from the root of the current plugin.
* @param $include tells if the file should be imported (require_once). Default: true.
* @throws Exception if the file does not exists.
* @since 1.10
*/
function mdh_current_plugin_path($file=NULL, $include=true) {
$path = osc_plugin_path(mdh_current_plugin_name(debug_backtrace()));
if($file != NULL) {
$path = $path . DIRECTORY_SEPARATOR . $file;
}
if($include) {
require_once($path);
} else {
if(! file_exists($path)) {
throw new Exception(sprintf("File '%s' does not exists!", $path));
}
return $path;
}
}
/**
* Tells if the specified plugin is ready to be used (installed and enabled).
* @param $pluginId the identifier of the plugin (name of the folder, '/' or '/index.php' is not needed).
* @returns true if installed and enabled, false otherwise.
* @since 1.10
*/
function mdh_plugin_is_ready($pluginId) {
return (osc_plugin_is_installed($pluginId . "/index.php") && osc_plugin_is_enabled($pluginId . "/index.php"));
}
?>
The installation generated an error:
Fatal error: Call to undefined function mdh_current_plugin_path() in /homez.***/********/www/a/oc-content/plugins/madhouse_helloworld/index.php on line 12
Regards
Fatal error: Uncaught exception 'Exception' with message 'Current file does not belong to a plugin!' in C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php:78 Stack trace: #0 C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php(94): mdh_current_plugin_name(Array) #1 C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php(12): mdh_current_plugin_path('oc-load.php') #2 C:\xampp\htdocs\xxxx\oc-admin\plugins.php(234): include('C:\xampp\htdocs...') #3 C:\xampp\htdocs\xxxx\oc-admin\index.php(84): CAdminPlugins->doModel() #4 {main} thrown in C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php on line 78
Thanks for such a good lesson.
I have tried to implement it step by step.
But I got an error.
At first my error isQuoteThe installation generated an error:
Fatal error: Call to undefined function mdh_current_plugin_path() in /homez.***/********/www/a/oc-content/plugins/madhouse_helloworld/index.php on line 12
Regards
Then I scroll down and got the answer.
I have add the function that you write above, but it still generate error.
It's said
Plugin couldn't be installed because it triggered a fatal errorQuoteFatal error: Uncaught exception 'Exception' with message 'Current file does not belong to a plugin!' in C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php:78 Stack trace: #0 C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php(94): mdh_current_plugin_name(Array) #1 C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php(12): mdh_current_plugin_path('oc-load.php') #2 C:\xampp\htdocs\xxxx\oc-admin\plugins.php(234): include('C:\xampp\htdocs...') #3 C:\xampp\htdocs\xxxx\oc-admin\index.php(84): CAdminPlugins->doModel() #4 {main} thrown in C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php on line 78
That's is for the plugin that I write self and renaming the variable.
So I try to install your plugin in the attachment and I add function that not added yet in index.php.
Then I tried to install it, it's got the same error.
Maybe there is something you forget to describe here :)
Hi adrienrn,
I'm sorry I didn't discovered this topic before. I will be contacting you soon.
Thanks a lot for your work.
Thanks for such a good lesson.
I have tried to implement it step by step.
But I got an error.
At first my error isQuoteThe installation generated an error:
Fatal error: Call to undefined function mdh_current_plugin_path() in /homez.***/********/www/a/oc-content/plugins/madhouse_helloworld/index.php on line 12
Regards
Then I scroll down and got the answer.
I have add the function that you write above, but it still generate error.
It's said
Plugin couldn't be installed because it triggered a fatal errorQuoteFatal error: Uncaught exception 'Exception' with message 'Current file does not belong to a plugin!' in C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php:78 Stack trace: #0 C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php(94): mdh_current_plugin_name(Array) #1 C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php(12): mdh_current_plugin_path('oc-load.php') #2 C:\xampp\htdocs\xxxx\oc-admin\plugins.php(234): include('C:\xampp\htdocs...') #3 C:\xampp\htdocs\xxxx\oc-admin\index.php(84): CAdminPlugins->doModel() #4 {main} thrown in C:\xampp\htdocs\xxxx\oc-content\plugins\madhouse_helloworld\index.php on line 78
That's is for the plugin that I write self and renaming the variable.
So I try to install your plugin in the attachment and I add function that not added yet in index.php.
Then I tried to install it, it's got the same error.
Maybe there is something you forget to describe here :)