From 9a09cf491eb9b8ac46761e03bda358c82ed96188 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 12 Aug 2015 14:16:25 +0200 Subject: [PATCH] Permit LSaddon to provide ajax callable function --- .../includes/class/class.LSsession.php | 4 ++- public_html/index_ajax.php | 29 ++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/public_html/includes/class/class.LSsession.php b/public_html/includes/class/class.LSsession.php index 5e0ad3b8..559dddf0 100644 --- a/public_html/includes/class/class.LSsession.php +++ b/public_html/includes/class/class.LSsession.php @@ -2353,7 +2353,9 @@ class LSsession { LSerror :: defineError('LSsession_20', _("LSsession : Error during password recovery. Contact administrators.(Step : %{step})") ); - // 21 : not yet used + LSerror :: defineError('LSsession_21', + _("LSsession : call function %{func} do not provided from LSaddon %{addon}.") + ); LSerror :: defineError('LSsession_22', _("LSsession : problem during initialisation.") ); diff --git a/public_html/index_ajax.php b/public_html/index_ajax.php index 837ab270..d4a4f953 100644 --- a/public_html/index_ajax.php +++ b/public_html/index_ajax.php @@ -14,15 +14,30 @@ else { $data=NULL; if (!isset($_ERRORS)) { - $class = $_REQUEST['template']; - if (LSsession :: loadLSclass($class)) { - $meth = 'ajax_'.$_REQUEST['action']; - if (method_exists($class,$meth)) { - $class :: $meth($data); + if (isset($_REQUEST['template'])) { + $class = $_REQUEST['template']; + if (LSsession :: loadLSclass($class)) { + $meth = 'ajax_'.$_REQUEST['action']; + if (method_exists($class,$meth)) { + $class :: $meth($data); + } + } + } + elseif (isset($_REQUEST['addon'])) { + $addon = $_REQUEST['addon']; + if (LSsession :: loadLSaddon($addon)) { + $func = 'ajax_'.$_REQUEST['action']; + if (function_exists($func)) { + $func = new ReflectionFunction($func); + if (basename($func->getFileName())=="LSaddons.$addon.php") { + $func->invokeArgs(array(&$data)); + } + else { + LSerror :: addErrorCode('LSsession_21',array('func' => $func -> getName(),'addon' => $addon)); + } + } } } } LSsession :: displayAjaxReturn($data); - -?>