Osclass forums

Development => Plugins => Topic started by: Hussard (Madhouse) on October 23, 2013, 06:09:05 pm

Title: [HOW TO] Develop plugins for Osclass!
Post by: Hussard (Madhouse) on October 23, 2013, 06:09:05 pm
Osclass lack of development guidelines when it comes to plugins. Here is a draft of what we (madhouse) have been using lately. This document is intended to give some guidelines to produce quality plugins for Osclass and make them easy to be understood and eventually included in the core by the team. You can choose to follow them entirely, partly or not follow them at all but I think it’s always nice to have some guidance / talk about it.

Read the tutorial on our website :

How to develop plugins for Osclass - Part 1 (http://osclassmadhouse.com/2013/10/11/how-to-develop-osclass-plugins/)

-
How to develop plugins for Osclass - Part 2 (https://osclassmadhouse.com/2016/07/27/how-to-develop-osclass-plugins-part-2/)


You can find the source code on Github: Madhouse HelloWorld (https://github.com/friends-of-osclass/madhouse_helloworld)



See you, chimps.

Changelog :
Title: Re: How to develop quality plugins (development guidelines)
Post by: Hussard (Madhouse) on October 28, 2013, 02:02:03 pm
Is there someone from the Osclass team that have time to read it and get back to me ?

If it's good enough, we could add it to the wiki.
Title: Re: How to develop quality plugins (development guidelines)
Post by: frosticek on October 28, 2013, 02:47:52 pm
@adrienrn

Nice article  ;)
Title: Re: How to develop quality plugins (development guidelines)
Post by: Nicolas30 on October 28, 2013, 03:08:58 pm
File "madhouse_helloworld.zip" empties  :(

Regards
Title: Re: How to develop quality plugins (development guidelines)
Post by: Hussard (Madhouse) on October 29, 2013, 09:22:54 pm
@adrienrn

Nice article  ;)

Thanks!

File "madhouse_helloworld.zip" empties  :(

Regards

I've re-uploaded the ZIP file. Should not be empty anymore.

PS : I will provide as soon as possible the missing parts (about Admin pages and custom hooks) and eventually French translation.
Title: Re: How to develop quality plugins (development guidelines)
Post by: Nicolas30 on October 29, 2013, 09:42:39 pm
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
Title: Re: How to develop quality plugins (development guidelines)
Post by: strata on October 30, 2013, 03:08:21 am
Waiting for the next chapter :)
Title: Re: How to develop quality plugins (development guidelines)
Post by: lexosc on October 30, 2013, 03:27:47 am
Who are you?! this has to be the best documentation for osclass! epic job and thanks!
Title: Re: How to develop quality plugins (development guidelines)
Post by: Hussard (Madhouse) on October 30, 2013, 09:46:00 pm
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

I'm sorry. This is utilities functions. I've said that I have used functions from my plugin madhouse_utils that contains common utilities that I use in all my plugins in my first post (blue line at the beggining).

I'm working on distribute this plugin, so for now, here are the functions that you will need. Copy them to your madhouse_helloworld/index.php.
Code: [Select]
<?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"));
}

?>

Title: Re: How to develop quality plugins (development guidelines)
Post by: achmadzackyr on December 22, 2013, 08:47:15 pm
Thanks for such a good lesson.

I have tried to implement it step by step.
But I got an error.
At first my error is
Quote
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

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 error

Quote
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

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  :)
Title: Re: How to develop quality plugins (development guidelines)
Post by: Hussard (Madhouse) on December 22, 2013, 10:14:14 pm
Thanks for such a good lesson.

I have tried to implement it step by step.
But I got an error.
At first my error is
Quote
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

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 error

Quote
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

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  :)


Sorry about that. I'll take a look and let you know.

PS : I'm working on a releasable version of madhouse_utils !

Title: Re: How to develop quality plugins (development guidelines)
Post by: gnoe on December 24, 2013, 06:32:44 pm
Great documentation and help. :)
Title: Re: How to develop quality plugins (development guidelines)
Post by: Hussard (Madhouse) on January 02, 2014, 08:14:15 pm
Okay, so. Big updates warning here ;).

Madhouse Utils

Madhouse Utils is finally available for download on our website : Madhouse Utils (http://wearemadhouse.wordpress.com/2013/10/27/madhouse-utils/). Just download it (big yellow button ;)) install it on your Osclass before starting the tutorial and you should be fine. Tested on Osclass 3.2 and Osclass 3.3.

New tutorial is out!

New revision of my tutorial on our website : How to develop plugins for Osclass (http://wearemadhouse.wordpress.com/2013/10/11/how-to-develop-osclass-plugins/).

I think this is much much readable.
Title: Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
Post by: _CONEJO on January 03, 2014, 02:57:08 pm
Hi adrienrn,

I'm sorry I didn't discovered this topic before. I will be contacting you soon.

Thanks a lot for your work.
Title: Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
Post by: Hussard (Madhouse) on January 03, 2014, 06:27:50 pm
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 to Minifyer plugin. I've discovered the new 'custom_controller' hook which will allow me to ditch the main.php entry point. It will get converted as a function added to this new hook :), use custom and get url rewriting.
Title: Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
Post by: Hussard (Madhouse) on April 03, 2014, 12:44:18 pm
This post was pinned in the development. Can it still be here ?  :'(
Title: Re: How to develop quality plugins (development guidelines)
Post by: jorge.yoma on January 09, 2015, 07:10:19 pm
Thanks for such a good lesson.

I have tried to implement it step by step.
But I got an error.
At first my error is
Quote
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

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 error

Quote
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

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.

thanks Hussard for your work, but I can't install the helloword plugin.

I installed the utils plugin without problem, but any of your solutions make the hello word work.

B/R.

Title: Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
Post by: SmaRTeY on January 14, 2015, 01:18:37 am
The information of the architecture is very usefull and should definitely be part of OSClass documentation as well as a simple data diagram and explanation of the system's architecture and it's classes so it makes customizations easier and of higher quality (in line with Osclass meant architecture) as is explained by Hussard.

Compliments for explaining the view on how to go about Osclass plugins!


Thanks,
Eric
Title: Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
Post by: jorge.yoma on November 13, 2015, 09:15:33 pm
Hi,

I can't get to downlonad the utils, the link is broken. :-\
Title: Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
Post by: gaissa on April 26, 2016, 06:46:46 pm
Yes, where is madhouse_utils?
Title: Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
Post by: osclassics on June 07, 2016, 01:05:58 pm
Also looking for the utils download link, it is not on the Madhouse page?
Title: Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
Post by: Hussard (Madhouse) on July 27, 2016, 04:51:17 pm
Hello everyone,

After almost two years, here's the second part of the tutorial: How to develop Osclass plugins - part 2 (https://osclassmadhouse.com/2016/07/27/how-to-develop-osclass-plugins-part-2/)

It shows how to create an admin page and a settings page, how to use paginations and how to manage version and upgrades! :)

Important: I've updated the original tutorial to work without Utils and uploaded the source code to Github: Madhouse HelloWorld (https://github.com/friends-of-osclass/madhouse_helloworld).