فهرست منبع

Add support for calling static and normal method on AdminMain()
yes call_user_func() does have a cost... I'm aware of that.

Signed-off-by: Suki <[email protected]>

Suki 10 سال پیش
والد
کامیت
3cf75dccfd
2فایلهای تغییر یافته به همراه19 افزوده شده و 2 حذف شده
  1. 17 1
      Sources/Admin.php
  2. 2 1
      Sources/Profile.php

+ 17 - 1
Sources/Admin.php

@@ -484,7 +484,23 @@ function AdminMain()
 	if (isset($admin_include_data['file']))
 		require_once($sourcedir . '/' . $admin_include_data['file']);
 
-	$admin_include_data['function']();
+	// Do we defined a class for this function?
+	if (isset($admin_include_data['class']) && !empty($admin_include_data['class']) && is_string($admin_include_data['class']))
+	{
+		// Is there an instance already? nope? then create it!
+		if (empty($context['instances'][$admin_include_data['class']]) || !($context['instances'][$admin_include_data['class']] instanceof $admin_include_data['class']))
+			$context['instances'][$admin_include_data['class']] = new $admin_include_data['class'];
+
+		$call = array($context['instances'][$admin_include_data['class']], $admin_include_data['function']);
+	}
+
+	// A static one or more likely, a plain good old function.
+	else
+		$call = $admin_include_data['function'];
+
+	// Is it valid?
+	if (is_callable($call))
+		call_user_func($call);
 }
 
 /**

+ 2 - 1
Sources/Profile.php

@@ -724,7 +724,7 @@ function ModifyProfile($post_errors = array())
 		redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
 
 	// Is this a "real" method?
-	if (isset($profile_include_data['class']))
+	if (isset($profile_include_data['class']) && !empty($profile_include_data['class']) && is_string($profile_include_data['class']))
 	{
 		// Is there an instance already? nope? then create it!
 		if (empty($context['instances'][$profile_include_data['class']]) || !($context['instances'][$profile_include_data['class']] instanceof $profile_include_data['class']))
@@ -733,6 +733,7 @@ function ModifyProfile($post_errors = array())
 		$call = array($context['instances'][$profile_include_data['class']], $profile_include_data['function']);
 	}
 
+	// A static one or more likely, a plain good old function.
 	else
 		$call = $profile_include_data['function'];