Advertisement:

Author Topic: [HOW TO] Develop plugins for Osclass!  (Read 19727 times)

Hussard (Madhouse)

  • Full Member
  • ***
  • Posts: 214
  • Outlaw web developer & padawan designer.
[HOW TO] Develop plugins for Osclass!
« 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 :




See you, chimps.

Changelog :
  • 27/07/2016 : Updated part 1 and published part 2!
  • 03/01/2014 : Post is pinned; thanks a lot!
  • 02/01/2014 : Major update; post in now on our website. Madhouse Utils is now available for download too.
  • 23/10/2013 : First draft, on the forum. Still have this version if needed but you won't ;).
« Last Edit: July 27, 2016, 04:51:59 pm by Hussard (Madhouse) »

Hussard (Madhouse)

  • Full Member
  • ***
  • Posts: 214
  • Outlaw web developer & padawan designer.
Re: How to develop quality plugins (development guidelines)
« Reply #1 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.

frosticek

  • Hero Member
  • *****
  • Posts: 3948
Re: How to develop quality plugins (development guidelines)
« Reply #2 on: October 28, 2013, 02:47:52 pm »
@adrienrn

Nice article  ;)

Nicolas30

  • Sr. Member
  • ****
  • Posts: 295
Re: How to develop quality plugins (development guidelines)
« Reply #3 on: October 28, 2013, 03:08:58 pm »
File "madhouse_helloworld.zip" empties  :(

Regards

Hussard (Madhouse)

  • Full Member
  • ***
  • Posts: 214
  • Outlaw web developer & padawan designer.
Re: How to develop quality plugins (development guidelines)
« Reply #4 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.

Nicolas30

  • Sr. Member
  • ****
  • Posts: 295
Re: How to develop quality plugins (development guidelines)
« Reply #5 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
« Last Edit: October 30, 2013, 09:56:00 am by Nicolas30 »

strata

  • Sr. Member
  • ****
  • Posts: 411
  • Always good, always...
Re: How to develop quality plugins (development guidelines)
« Reply #6 on: October 30, 2013, 03:08:21 am »
Waiting for the next chapter :)

lexosc

  • Sr. Member
  • ****
  • Posts: 344
Re: How to develop quality plugins (development guidelines)
« Reply #7 on: October 30, 2013, 03:27:47 am »
Who are you?! this has to be the best documentation for osclass! epic job and thanks!

Hussard (Madhouse)

  • Full Member
  • ***
  • Posts: 214
  • Outlaw web developer & padawan designer.
Re: How to develop quality plugins (development guidelines)
« Reply #8 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"));
}

?>


achmadzackyr

  • Newbie
  • *
  • Posts: 13
Re: How to develop quality plugins (development guidelines)
« Reply #9 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  :)

Hussard (Madhouse)

  • Full Member
  • ***
  • Posts: 214
  • Outlaw web developer & padawan designer.
Re: How to develop quality plugins (development guidelines)
« Reply #10 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 !


gnoe

  • Full Member
  • ***
  • Posts: 237
Re: How to develop quality plugins (development guidelines)
« Reply #11 on: December 24, 2013, 06:32:44 pm »
Great documentation and help. :)

Hussard (Madhouse)

  • Full Member
  • ***
  • Posts: 214
  • Outlaw web developer & padawan designer.
Re: How to develop quality plugins (development guidelines)
« Reply #12 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. 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.

I think this is much much readable.

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
« Reply #13 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.

Hussard (Madhouse)

  • Full Member
  • ***
  • Posts: 214
  • Outlaw web developer & padawan designer.
Re: [HOW TO] Develop quality plugins (Madhouse guidelines)
« Reply #14 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.