Skip to content

Commit

Permalink
added support of new style plugins in userpanel module setup part
Browse files Browse the repository at this point in the history
  • Loading branch information
chilek committed Jul 3, 2015
1 parent 3ac4ee1 commit 74f6749
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 38 deletions.
1 change: 1 addition & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version ?.??.?? (????-??-??):

- added support of new style plugins in userpanel - hooks executed before
module load have 'userpanel_*_on_load' name pattern [chilan]
- added support of new style plugins in userpanel module setup part [chilan]

version 1.11.17 (2015-06-29):

Expand Down
50 changes: 30 additions & 20 deletions userpanel/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,27 @@
$enabled_modules = ConfigHelper::getConfig('userpanel.enabled_modules', null, true);
if (!is_null($enabled_modules))
$enabled_modules = explode(',', $enabled_modules);
$dh = opendir(USERPANEL_MODULES_DIR);
while (false !== ($filename = readdir($dh))) {
if ((is_null($enabled_modules) || in_array($filename, $enabled_modules)) && (preg_match('/^[a-zA-Z0-9]/',$filename))
&& (is_dir(USERPANEL_MODULES_DIR.$filename)) && file_exists(USERPANEL_MODULES_DIR.$filename . DIRECTORY_SEPARATOR . 'configuration.php'))
{
@include(USERPANEL_MODULES_DIR.$filename . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR . $_ui_language . DIRECTORY_SEPARATOR . 'strings.php');
include(USERPANEL_MODULES_DIR.$filename . DIRECTORY_SEPARATOR . 'configuration.php');
if (is_dir(USERPANEL_MODULES_DIR.$filename . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR))
{
$plugins = glob(USERPANEL_MODULES_DIR.$filename . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . '*.php');
if (!empty($plugins))
foreach ($plugins as $plugin_name)
if(is_readable($plugin_name))
include($plugin_name);

$modules_dirs = array(USERPANEL_MODULES_DIR);
$modules_dirs = $plugin_manager->executeHook('userpanel_modules_dir_initialized', $modules_dirs);

foreach ($modules_dirs as $suspected_module_dir) {
$dh = opendir($suspected_module_dir);
while (false !== ($filename = readdir($dh))) {
if ((is_null($enabled_modules) || in_array($filename, $enabled_modules)) && (preg_match('/^[a-zA-Z0-9]/',$filename))
&& (is_dir($suspected_module_dir . $filename)) && file_exists($suspected_module_dir . $filename . DIRECTORY_SEPARATOR . 'configuration.php')) {
@include($suspected_module_dir . $filename . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR . $_ui_language . DIRECTORY_SEPARATOR . 'strings.php');
include($suspected_module_dir . $filename . DIRECTORY_SEPARATOR . 'configuration.php');
if (is_dir($suspected_module_dir . $filename . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR)) {
$plugins = glob($suspected_module_dir . $filename . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . '*.php');
if (!empty($plugins))
foreach ($plugins as $plugin_name)
if (is_readable($plugin_name))
include($plugin_name);
}
}
}
}
};
}

$SMARTY->assignByRef('LANGDEFS', $LANGDEFS);
$SMARTY->assignByRef('_ui_language', $LMS->ui_lang);
Expand Down Expand Up @@ -231,10 +235,16 @@

$LMS->executeHook('userpanel_' . $module . '_on_load');

if( file_exists(USERPANEL_MODULES_DIR.$module . DIRECTORY_SEPARATOR . 'functions.php')
&& isset($USERPANEL->MODULES[$module]) )
{
include(USERPANEL_MODULES_DIR.$module . DIRECTORY_SEPARATOR . 'functions.php');
$module_dir = null;
foreach ($modules_dirs as $suspected_module_dir)
if (file_exists($suspected_module_dir . $module . DIRECTORY_SEPARATOR . 'functions.php')
&& isset($USERPANEL->MODULES[$module])) {
$module_dir = $suspected_module_dir;
break;
}

if ($module_dir !== null) {
include($module_dir . $module . DIRECTORY_SEPARATOR . 'functions.php');

$function = isset($_GET['f']) && $_GET['f']!='' ? $_GET['f'] : 'main';
if (function_exists('module_'.$function))
Expand Down
41 changes: 27 additions & 14 deletions userpanel/lib/LMS.setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

function module_get_template($tpl_name, &$tpl_source, $smarty_obj)
{
global $LMS;
global $LMS, $module_dir;
$template = explode(':', $tpl_name);
$template_path = ConfigHelper::getConfig('directories.userpanel_dir').'/modules/'.$template[0].'/templates/'.$template[1];
$template_path = $module_dir . $template[0].'/templates/'.$template[1];
if (file_exists($template_path))
{
$tpl_source = file_get_contents($template_path);
Expand All @@ -43,9 +43,9 @@ function module_get_template($tpl_name, &$tpl_source, $smarty_obj)

function module_get_timestamp($tpl_name, &$tpl_timestamp, $smarty_obj)
{
global $LMS;
global $LMS, $module_dir;
$template = explode(':', $tpl_name);
$template_path = ConfigHelper::getConfig('directories.userpanel_dir').'/modules/'.$template[0].'/templates/'.$template[1];
$template_path = $module_dir . $template[0].'/templates/'.$template[1];
if (file_exists($template_path))
{
$tpl_timestamp = filectime($template_path);
Expand Down Expand Up @@ -79,15 +79,20 @@ function module_get_trusted($tpl_name, &$smarty_obj)
$USERPANEL = new USERPANEL($DB, $SESSION);

// Initialize modules
$dh = opendir(USERPANEL_MODULES_DIR);
while (false !== ($filename = readdir($dh)))
{
if ((preg_match('/^[a-zA-Z0-9]/',$filename)) && (is_dir(USERPANEL_MODULES_DIR.$filename)) && file_exists(USERPANEL_MODULES_DIR.$filename.'/configuration.php'))
{
@include(USERPANEL_MODULES_DIR.$filename.'/locale/'.$_ui_language.'/strings.php');
include(USERPANEL_MODULES_DIR.$filename.'/configuration.php');

$modules_dirs = array(USERPANEL_MODULES_DIR);
$modules_dirs = $plugin_manager->executeHook('userpanel_modules_dir_initialized', $modules_dirs);

foreach ($modules_dirs as $suspected_module_dir) {
$dh = opendir($suspected_module_dir);
while (false !== ($filename = readdir($dh))) {
if ((preg_match('/^[a-zA-Z0-9]/',$filename)) && (is_dir($suspected_module_dir . $filename))
&& file_exists($suspected_module_dir . $filename.'/configuration.php')) {
@include($suspected_module_dir . $filename.'/locale/'.$_ui_language.'/strings.php');
include($suspected_module_dir . $filename.'/configuration.php');
}
}
};
}

$SMARTY->assignByRef('menu', $USERPANEL->MODULES);

Expand All @@ -98,8 +103,16 @@ function module_get_trusted($tpl_name, &$smarty_obj)

if($module == 'userpanel')
$modulefile_include = USERPANEL_DIR.'/lib/setup_functions.php';
else
$modulefile_include = file_exists(USERPANEL_MODULES_DIR.$module.'/functions.php') ? USERPANEL_MODULES_DIR.$module.'/functions.php' : NULL;
else {
global $module_dir;
$module_dir = null;
foreach ($modules_dirs as $suspected_module_dir)
if (file_exists($suspected_module_dir . $module.'/functions.php')) {
$module_dir = $suspected_module_dir;
break;
}
$modulefile_include = ($module_dir !== null ? $module_dir . $module.'/functions.php' : NULL);
}

if (isset($modulefile_include))
{
Expand Down
12 changes: 8 additions & 4 deletions userpanel/lib/smarty_addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,17 @@ function _smarty_function_img($params, $template)

function module_get_template($tpl_name, &$tpl_source, $template)
{
global $module_dir;

$module = $_GET['m'];
$style = ConfigHelper::getConfig('userpanel.style', 'default');
$template_path = ConfigHelper::getConfig('directories.userpanel_dir') . '/modules/' . $module . '/style/' . $style . '/templates/' . $tpl_name;
$template_path = $module_dir . $module . '/style/' . $style . '/templates/' . $tpl_name;
if (file_exists($template_path))
{
$tpl_source = file_get_contents($template_path);
return true;
} else {
$template_path = ConfigHelper::getConfig('directories.userpanel_dir').'/modules/'.$module.'/templates/'.$tpl_name;
$template_path = $module_dir . $module.'/templates/'.$tpl_name;
if (file_exists($template_path)) {
$tpl_source = file_get_contents($template_path);
return true;
Expand All @@ -198,15 +200,17 @@ function module_get_template($tpl_name, &$tpl_source, $template)

function module_get_timestamp($tpl_name, &$tpl_timestamp, $template)
{
global $module_dir;

$module = $_GET['m'];
$style = ConfigHelper::getConfig('userpanel.style', 'default');
$template_path = ConfigHelper::getConfig('directories.userpanel_dir') . '/modules/' . $module . '/style/' . $style . '/templates/' . $tpl_name;
$template_path = $module_dir . $module . '/style/' . $style . '/templates/' . $tpl_name;
if (file_exists($template_path))
{
$tpl_timestamp = filectime($template_path);
return true;
} else {
$template_path = ConfigHelper::getConfig('directories.userpanel_dir').'/modules/'.$module.'/templates/'.$tpl_name;
$template_path = $module_dir . $module.'/templates/'.$tpl_name;
if (file_exists($template_path)) {
$tpl_timestamp = filectime($template_path);
return true;
Expand Down

0 comments on commit 74f6749

Please sign in to comment.