Skip to main content
Addons dir Started by emanuele · · Read 14279 times 0 Members and 2 Guests are viewing this topic. previous topic - next topic

Addons dir

Code: [Select]
	$dirs = array(
'\\' => '/',
'BOARDDIR' => BOARDDIR,
'SOURCEDIR' => SOURCEDIR,
'SUBSDIR' => SUBSDIR,
'ADMINDIR' => ADMINDIR,
'CONTROLLERDIR' => CONTROLLERDIR,
'$avatardir' => $modSettings['avatar_directory'],
'$avatars_dir' => $modSettings['avatar_directory'],
'$themedir' => $settings['default_theme_dir'],
'$imagesdir' => $settings['default_theme_dir'] . '/' . basename($settings['default_images_url']),
'LANGUAGEDIR' => $settings['default_theme_dir'] . '/languages',
'$languages_dir' => $settings['default_theme_dir'] . '/languages',
'$smileysdir' => $modSettings['smileys_dir'],
'$smileys_dir' => $modSettings['smileys_dir'],
);

It looks odd.
IMHO (<= I want to see the censor at work! :P)

What about:
Code: [Select]
	$dirs = array(
'\\' => '/',
'BOARDDIR' => BOARDDIR,
'SOURCEDIR' => SOURCEDIR,
'SUBSDIR' => SUBSDIR,
'ADMINDIR' => ADMINDIR,
'CONTROLLERDIR' => CONTROLLERDIR,
'AVATARSDIR' => $modSettings['avatar_directory'],
'THEMEDIR' => $settings['default_theme_dir'],
'IMAGESDIR' => $settings['default_theme_dir'] . '/' . basename($settings['default_images_url']),
'LANGUAGEDIR' => $settings['default_theme_dir'] . '/languages',
'SMILEYDIR' => $modSettings['smileys_dir'],
);
Bugs creator.
Features destroyer.
Template killer.

Re: Addons dir

Reply #1

I was looking at that the other day as well and thought it a bit odd ... Not sure why it had support for some older string versions (granted we did not define those terms in the core), and it had both LANGUAGEDIR and $langaugedir  ....  What you have would make addon writing more consistent so unless there are objections I'd say make the PR

Re: Addons dir

Reply #2

I don't see any ADDONSDIR for mod authors. Do we have to decide on putting our file(s) inside SUBSDIR or ADMINDIR. Personally, I think it will be cleaner if addons has its own directory. Just a thought though.

Re: Addons dir

Reply #3

Currently there is not an ADDONSDIR so they should follow the conventions that ElkArte follows if possible.

That means files that manage admin actions go in ADMINDIR, files that work on user actions in CONTROLLERDIR, support files go in SUBSDIR, templates/css/js in the THEMEDIR etc.  When you get used to this it makes things easy to find. 

There is also SOURCEDIR which tend to be more overall site things, like the dispatcher etc.  When writing mods I often place the integration/hooks file in that directory.

Having a ADDONDIR for integration files etc may be a good thing to add in 1.1

Re: Addons dir

Reply #4

What Spuds said.

I am kind of  working (more playing) with something like this and an "event" system.
My current idea is something like:
let addons put files into a specific directory
use a file named My_Addon.integrate.php that is auto-included
the file could contain classes for integration with specific naming pattern: Addon_ActionName_AddonName ("Addon_" is a common prefix, "ActionName" is the name of the action with the first char uppercase, for example "Display", "AddonName" is the actual name of the addon, for example "MyAddon")
the event system understands the integration request and loads the necessary files.

The two commits involved are:
https://github.com/emanuele45/Dialogo/commit/318b573f711c00979c31aa89c75abd6664b7674d
https://github.com/emanuele45/Dialogo/commit/a488d41c9959f0ae35eb28dece90324be915d7c3
It's not yet finished, it's a very early WIP.

The following is an example of how an integration file would look like:
Code: [Select]
<?php

class Addon_Display_Test1
{
public static $dep = array('_REQUEST');

public static function hooks()
{
require_once(BOARDDIR . '/packages/integration/test1/Test1Action.class.php');
return array('pre_load' => 'Test1_Action');
}
}
The require_once is there because the autoloading doesn't know (yet) anything about that path. :P
Bugs creator.
Features destroyer.
Template killer.

Re: Addons dir

Reply #5

OOoooo I like what I'm seeing there :D

Re: Addons dir

Reply #6

Growing!

https://github.com/emanuele45/Dialogo/compare/elkarte:development...emanuele45:playing

In particular:
https://github.com/emanuele45/Dialogo/commit/8795d0de8d16613b467a2592275fd1c1dbefd0af
and an example oh how use it:
https://github.com/emanuele45/Dialogo/commit/c9f93ea2510677fb122928bd943b29f21b54e8ec

That may be of interest to @ant59 as well in relation to his topic.

Far from being perfect for sure, any suggestion/opinion/etc. is welcome. ;)
Bugs creator.
Features destroyer.
Template killer.

Re: Addons dir

Reply #7

Please make the documentation and real examples for the Modules and Addons.
I think I do not understand very well how it should work correctly.

Addon:
modSettings['autoload_integrate'] += MyAddon.integrate.php
reloadSettings()
    loadIntegrations()
        hooks = MyAddon::register()
        add hooks

The addons needs to store hooks? or that all the files were isolated from the core files?
Sorry for my English

Re: Addons dir

Reply #8

Part of it was explained years ago in https://www.elkarte.net/community/index.php?topic=831.msg16689#msg16689
The rest... no documentation at the moment, you can have a look at both the https://github.com/Spuds/Elk_Image_Cache/ or the Draft code (modules and integration).
Bugs creator.
Features destroyer.
Template killer.

Re: Addons dir

Reply #9

I tried to make some "documentation" in the image class doc blocks / comments, so be sure to read those as they should help explain what the system is doing for you.