Browse Source

That should allow people to define a file to include when they add a function to a hook

Signed-off-by: emanuele <[email protected]>
emanuele 12 years ago
parent
commit
1f94fbe8ad
1 changed files with 35 additions and 13 deletions
  1. 35 13
      Sources/Subs.php

+ 35 - 13
Sources/Subs.php

@@ -4046,7 +4046,7 @@ function smf_seed_generator()
  */
 function call_integration_hook($hook, $parameters = array())
 {
-	global $modSettings;
+	global $modSettings, $settings, $boarddir, $sourcedir;
 
 	$results = array();
 	if (empty($modSettings[$hook]))
@@ -4058,7 +4058,23 @@ function call_integration_hook($hook, $parameters = array())
 	foreach ($functions as $function)
 	{
 		$function = trim($function);
-		$call = strpos($function, '::') !== false ? explode('::', $function) : $function;
+		if (strpos($function, '::') !== false)
+		{
+			$call = explode('::', $function);
+			if (strpos($call[1], ':') !== false)
+			{
+				list($func, $file) = explode(':', $call[1]);
+				if (!empty($settings['theme_dir']))
+					include_once(strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)));
+				else
+					include_once(strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])));
+				$call = array($call[0], $func);
+			}
+		}
+		else
+		{
+			$call = $function;
+		}
 
 		// Is it valid?
 		if (is_callable($call))
@@ -4074,12 +4090,15 @@ function call_integration_hook($hook, $parameters = array())
  *
  * @param string $hook
  * @param string $function
+ * @param string $file
  * @param bool $permanent = true if true, updates the value in settings table
  */
-function add_integration_function($hook, $function, $permanent = true)
+function add_integration_function($hook, $function, $file, $permanent = true)
 {
 	global $smcFunc, $modSettings;
 
+	$integration_call = $function . ':' . $file;
+
 	// Is it going to be permanent?
 	if ($permanent)
 	{
@@ -4097,13 +4116,13 @@ function add_integration_function($hook, $function, $permanent = true)
 		if (!empty($current_functions))
 		{
 			$current_functions = explode(',', $current_functions);
-			if (in_array($function, $current_functions))
+			if (in_array($integration_call, $current_functions))
 				return;
 
-			$permanent_functions = array_merge($current_functions, array($function));
+			$permanent_functions = array_merge($current_functions, array($integration_call));
 		}
 		else
-			$permanent_functions = array($function);
+			$permanent_functions = array($integration_call);
 
 		updateSettings(array($hook => implode(',', $permanent_functions)));
 	}
@@ -4112,10 +4131,10 @@ function add_integration_function($hook, $function, $permanent = true)
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
 
 	// Do nothing, if it's already there.
-	if (in_array($function, $functions))
+	if (in_array($integration_call, $functions))
 		return;
 
-	$functions[] = $function;
+	$functions[] = $integration_call;
 	$modSettings[$hook] = implode(',', $functions);
 }
 
@@ -4126,11 +4145,14 @@ function add_integration_function($hook, $function, $permanent = true)
  *
  * @param string $hook
  * @param string $function
+ * @param string $file
  */
-function remove_integration_function($hook, $function)
+function remove_integration_function($hook, $function, $file)
 {
 	global $smcFunc, $modSettings;
 
+	$integration_call = $function . ':' . $file;
+
 	// Get the permanent functions.
 	$request = $smcFunc['db_query']('', '
 		SELECT value
@@ -4147,18 +4169,18 @@ function remove_integration_function($hook, $function)
 	{
 		$current_functions = explode(',', $current_functions);
 
-		if (in_array($function, $current_functions))
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($function)))));
+		if (in_array($integration_call, $current_functions))
+			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
 	}
 
 	// Turn the function list into something usable.
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
 
 	// You can only remove it if it's available.
-	if (!in_array($function, $functions))
+	if (!in_array($integration_call, $functions))
 		return;
 
-	$functions = array_diff($functions, array($function));
+	$functions = array_diff($functions, array($integration_call));
 	$modSettings[$hook] = implode(',', $functions);
 }