Quellcode durchsuchen

Merge pull request #706 from Arantor/release-2.1

! Ba-da-dum-dum-dum another one bites the dust. In this case, it is Inte...
Arantor vor 11 Jahren
Ursprung
Commit
ea16ebbc73

+ 1 - 1
Sources/Admin.php

@@ -171,7 +171,6 @@ function AdminMain()
 					'icon' => 'modifications.png',
 					'subsections' => array(
 						'general' => array($txt['mods_cat_modifications_misc']),
-						'hooks' => array($txt['hooks_title_list']),
 						// Mod Authors for a "ADD AFTER" on this line. Ensure you end your change with a comma. For example:
 						// 'shout' => array($txt['shout']),
 						// Note the comma!! The setting with automatically appear with the first mod to be added.
@@ -394,6 +393,7 @@ function AdminMain()
 						'database' => array($txt['maintain_sub_database'], 'admin_forum'),
 						'members' => array($txt['maintain_sub_members'], 'admin_forum'),
 						'topics' => array($txt['maintain_sub_topics'], 'admin_forum'),
+						'hooks' => array($txt['hooks_title_list'], 'admin_forum'),
 					),
 				),
 				'scheduledtasks' => array(

+ 427 - 0
Sources/ManageMaintenance.php

@@ -84,6 +84,9 @@ function ManageMaintenance()
 				'olddrafts' => 'MaintainRemoveOldDrafts',
 			),
 		),
+		'hooks' => array(
+			'function' => 'list_integration_hooks',
+		),
 		'destroy' => array(
 			'function' => 'Destroy',
 			'activities' => array(),
@@ -2126,4 +2129,428 @@ function MaintainRecountPosts()
 	redirectexit('action=admin;area=maintain;sa=members;done=recountposts');
 }
 
+/**
+ * Generates a list of integration hooks for display
+ * Accessed through ?action=admin;area=maintain;sa=hooks;
+ * Allows for removal or disabing of selected hooks
+ */
+function list_integration_hooks()
+{
+	global $sourcedir, $scripturl, $context, $txt, $modSettings, $settings;
+
+	$context['filter_url'] = '';
+	$context['current_filter'] = '';
+	$currentHooks = get_integration_hooks();
+	if (isset($_GET['filter']) && in_array($_GET['filter'], array_keys($currentHooks)))
+	{
+		$context['filter_url'] = ';filter=' . $_GET['filter'];
+		$context['current_filter'] = $_GET['filter'];
+	}
+
+	if (!empty($_REQUEST['do']) && isset($_REQUEST['hook']) && isset($_REQUEST['function']))
+	{
+		checkSession('request');
+		validateToken('admin-hook', 'request');
+
+		if ($_REQUEST['do'] == 'remove')
+			remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
+		else
+		{
+			if ($_REQUEST['do'] == 'disable')
+			{
+				// It's a hack I know...but I'm way too lazy!!!
+				$function_remove = $_REQUEST['function'];
+				$function_add = $_REQUEST['function'] . ']';
+			}
+			else
+			{
+				$function_remove = $_REQUEST['function'] . ']';
+				$function_add = $_REQUEST['function'];
+			}
+			$file = !empty($_REQUEST['includedfile']) ? urldecode($_REQUEST['includedfile']) : '';
+
+			remove_integration_function($_REQUEST['hook'], $function_remove, $file);
+			add_integration_function($_REQUEST['hook'], $function_add, $file);
+
+			redirectexit('action=admin;area=maintain;sa=hooks' . $context['filter_url']);
+		}
+	}
+
+	$list_options = array(
+		'id' => 'list_integration_hooks',
+		'title' => $txt['hooks_title_list'],
+		'items_per_page' => 20,
+		'base_href' => $scripturl . '?action=admin;area=maintain;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'],
+		'default_sort_col' => 'hook_name',
+		'get_items' => array(
+			'function' => 'get_integration_hooks_data',
+		),
+		'get_count' => array(
+			'function' => 'get_integration_hooks_count',
+		),
+		'no_items_label' => $txt['hooks_no_hooks'],
+		'columns' => array(
+			'hook_name' => array(
+				'header' => array(
+					'value' => $txt['hooks_field_hook_name'],
+				),
+				'data' => array(
+					'db' => 'hook_name',
+				),
+				'sort' =>  array(
+					'default' => 'hook_name',
+					'reverse' => 'hook_name DESC',
+				),
+			),
+			'function_name' => array(
+				'header' => array(
+					'value' => $txt['hooks_field_function_name'],
+				),
+				'data' => array(
+					'function' => create_function('$data', '
+						global $txt;
+
+						if (!empty($data[\'included_file\']))
+							return $txt[\'hooks_field_function\'] . \': \' . $data[\'real_function\'] . \'<br />\' . $txt[\'hooks_field_included_file\'] . \': \' . $data[\'included_file\'];
+						else
+							return $data[\'real_function\'];
+					'),
+				),
+				'sort' =>  array(
+					'default' => 'function_name',
+					'reverse' => 'function_name DESC',
+				),
+			),
+			'file_name' => array(
+				'header' => array(
+					'value' => $txt['hooks_field_file_name'],
+				),
+				'data' => array(
+					'db' => 'file_name',
+				),
+				'sort' =>  array(
+					'default' => 'file_name',
+					'reverse' => 'file_name DESC',
+				),
+			),
+			'status' => array(
+				'header' => array(
+					'value' => $txt['hooks_field_hook_exists'],
+					'style' => 'width:3%;',
+				),
+				'data' => array(
+					'function' => create_function('$data', '
+						global $txt, $settings, $scripturl, $context;
+
+						$change_status = array(\'before\' => \'\', \'after\' => \'\');
+						if ($data[\'can_be_disabled\'] && $data[\'status\'] != \'deny\')
+						{
+							$change_status[\'before\'] = \'<a href="\' . $scripturl . \'?action=admin;area=maintain;sa=hooks;do=\' . ($data[\'enabled\'] ? \'disable\' : \'enable\') . \';hook=\' . $data[\'hook_name\'] . \';function=\' . $data[\'real_function\'] . (!empty($data[\'included_file\']) ? \';includedfile=\' . urlencode($data[\'included_file\']) : \'\') . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">\';
+							$change_status[\'after\'] = \'</a>\';
+						}
+						return $change_status[\'before\'] . \'<img src="\' . $settings[\'images_url\'] . \'/admin/post_moderation_\' . $data[\'status\'] . \'.png" alt="\' . $data[\'img_text\'] . \'" title="\' . $data[\'img_text\'] . \'" />\' . $change_status[\'after\'];
+					'),
+					'class' => 'centertext',
+				),
+				'sort' =>  array(
+					'default' => 'status',
+					'reverse' => 'status DESC',
+				),
+			),
+		),
+		'additional_rows' => array(
+			array(
+				'position' => 'after_title',
+				'value' => $txt['hooks_disable_instructions'] . '<br />
+					' . $txt['hooks_disable_legend'] . ':
+									<ul style="list-style: none;">
+					<li><img src="' . $settings['images_url'] . '/admin/post_moderation_allow.png" alt="' . $txt['hooks_active'] . '" title="' . $txt['hooks_active'] . '" /> ' . $txt['hooks_disable_legend_exists'] . '</li>
+					<li><img src="' . $settings['images_url'] . '/admin/post_moderation_moderate.png" alt="' . $txt['hooks_disabled'] . '" title="' . $txt['hooks_disabled'] . '" /> ' . $txt['hooks_disable_legend_disabled'] . '</li>
+					<li><img src="' . $settings['images_url'] . '/admin/post_moderation_deny.png" alt="' . $txt['hooks_missing'] . '" title="' . $txt['hooks_missing'] . '" /> ' . $txt['hooks_disable_legend_missing'] . '</li>
+				</ul>'
+			),
+		),
+	);
+
+	createToken('admin-hook', 'request');
+
+	$list_options['columns']['remove'] = array(
+		'header' => array(
+			'value' => $txt['hooks_button_remove'],
+			'style' => 'width:3%',
+		),
+		'data' => array(
+			'function' => create_function('$data', '
+				global $txt, $settings, $scripturl, $context;
+
+				if (!$data[\'hook_exists\'])
+					return \'
+					<a href="\' . $scripturl . \'?action=admin;area=maintain;sa=hooks;do=remove;hook=\' . $data[\'hook_name\'] . \';function=\' . urlencode($data[\'function_name\']) . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">
+						<img src="\' . $settings[\'images_url\'] . \'/icons/quick_remove.png" alt="\' . $txt[\'hooks_button_remove\'] . \'" title="\' . $txt[\'hooks_button_remove\'] . \'" />
+					</a>\';
+			'),
+			'class' => 'centertext',
+		),
+	);
+	$list_options['form'] = array(
+		'href' => $scripturl . '?action=admin;area=maintain;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'],
+		'name' => 'list_integration_hooks',
+	);
+
+
+	require_once($sourcedir . '/Subs-List.php');
+	createList($list_options);
+
+	$context['page_title'] = $txt['hooks_title_list'];
+	$context['sub_template'] = 'show_list';
+	$context['default_list'] = 'list_integration_hooks';
+}
+
+/**
+ * Gets all of the files in a directory and its chidren directories
+ *
+ * @param type $dir_path
+ * @return array
+ */
+function get_files_recursive($dir_path)
+{
+	$files = array();
+
+	if ($dh = opendir($dir_path))
+	{
+		while (($file = readdir($dh)) !== false)
+		{
+			if ($file != '.' && $file != '..')
+			{
+				if (is_dir($dir_path . '/' . $file))
+					$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
+				else
+					$files[] = array('dir' => $dir_path, 'name' => $file);
+			}
+		}
+	}
+	closedir($dh);
+
+	return $files;
+}
+
+/**
+ * Callback function for the integration hooks list (list_integration_hooks)
+ * Gets all of the hooks in the system and their status
+ * Would be better documented if Ema was not lazy
+ *
+ * @param type $start
+ * @param type $per_page
+ * @param type $sort
+ * @return array
+ */
+function get_integration_hooks_data($start, $per_page, $sort)
+{
+	global $boarddir, $sourcedir, $settings, $txt, $context, $scripturl, $modSettings;
+
+	$hooks = $temp_hooks = get_integration_hooks();
+	$hooks_data = $temp_data = $hook_status = array();
+
+	$files = get_files_recursive($sourcedir);
+	if (!empty($files))
+	{
+		foreach ($files as $file)
+		{
+			if (is_file($file['dir'] . '/' . $file['name']) && substr($file['name'], -4) === '.php')
+			{
+				$fp = fopen($file['dir'] . '/' . $file['name'], 'rb');
+				$fc = fread($fp, filesize($file['dir'] . '/' . $file['name']));
+				fclose($fp);
+
+				foreach ($temp_hooks as $hook => $functions)
+				{
+					foreach ($functions as $function_o)
+					{
+						$hook_name = str_replace(']', '', $function_o);
+						if (strpos($hook_name, '::') !== false)
+						{
+							$function = explode('::', $hook_name);
+							$function = $function[1];
+						}
+						else
+							$function = $hook_name;
+						$function = explode(':', $function);
+						$function = $function[0];
+
+						if (substr($hook, -8) === '_include')
+						{
+							$hook_status[$hook][$function]['exists'] = file_exists(strtr(trim($function), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])));
+							// I need to know if there is at least one function called in this file.
+							$temp_data['include'][basename($function)] = array('hook' => $hook, 'function' => $function);
+							unset($temp_hooks[$hook][$function_o]);
+						}
+						elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($function) . '(') !== false)
+						{
+							$hook_status[$hook][$hook_name]['exists'] = true;
+							$hook_status[$hook][$hook_name]['in_file'] = $file['name'];
+							// I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too)
+							$temp_data['function'][$file['name']][] = $function_o;
+							unset($temp_hooks[$hook][$function_o]);
+						}
+					}
+				}
+			}
+		}
+	}
+
+	$sort_types = array(
+		'hook_name' => array('hook', SORT_ASC),
+		'hook_name DESC' => array('hook', SORT_DESC),
+		'function_name' => array('function', SORT_ASC),
+		'function_name DESC' => array('function', SORT_DESC),
+		'file_name' => array('file_name', SORT_ASC),
+		'file_name DESC' => array('file_name', SORT_DESC),
+		'status' => array('status', SORT_ASC),
+		'status DESC' => array('status', SORT_DESC),
+	);
+
+	$sort_options = $sort_types[$sort];
+	$sort = array();
+	$hooks_filters = array();
+
+	foreach ($hooks as $hook => $functions)
+	{
+		$hooks_filters[] = '<option ' . ($context['current_filter'] == $hook ? 'selected="selected" ' : '') . 'onclick="window.location = \'' . $scripturl . '?action=admin;area=maintain;sa=hooks;filter=' . $hook . '\';">' . $hook . '</option>';
+		foreach ($functions as $function)
+		{
+			$enabled = strstr($function, ']') === false;
+			$function = str_replace(']', '', $function);
+
+			// This is a not an include and the function is included in a certain file (if not it doesn't exists so don't care)
+			if (substr($hook, -8) !== '_include' && isset($hook_status[$hook][$function]['in_file']))
+			{
+				$current_hook = isset($temp_data['include'][$hook_status[$hook][$function]['in_file']]) ? $temp_data['include'][$hook_status[$hook][$function]['in_file']] : '';
+				$enabled = false;
+
+				// Checking all the functions within this particular file
+				// if any of them is enable then the file *must* be included and the integrate_*_include hook cannot be disabled
+				foreach ($temp_data['function'][$hook_status[$hook][$function]['in_file']] as $func)
+					$enabled = $enabled || strstr($func, ']') !== false;
+
+				if (!$enabled &&  !empty($current_hook))
+					$hook_status[$current_hook['hook']][$current_hook['function']]['enabled'] = true;
+			}
+		}
+	}
+
+	if (!empty($hooks_filters))
+		$context['insert_after_template'] .= '
+		<script type="text/javascript"><!-- // --><![CDATA[
+			var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
+			hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;"><option>---</option><option onclick="window.location = \'' . $scripturl . '?action=admin;area=maintain;sa=hooks\';">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>'). ';
+		// ]]></script>';
+
+	$temp_data = array();
+	$id = 0;
+
+	foreach ($hooks as $hook => $functions)
+	{
+		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
+		{
+			foreach ($functions as $function)
+			{
+				$enabled = strstr($function, ']') === false;
+				$function = str_replace(']', '', $function);
+				$hook_exists = !empty($hook_status[$hook][$function]['exists']);
+				$file_name = isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ((substr($hook, -8) === '_include') ? 'zzzzzzzzz' : 'zzzzzzzza');
+				$sort[] = $$sort_options[0];
+
+				if (strpos($function, '::') !== false)
+				{
+					$function = explode('::', $function);
+					$function = $function[1];
+				}
+				$exploded = explode(':', $function);
+
+				$temp_data[] = array(
+					'id' => 'hookid_' . $id++,
+					'hook_name' => $hook,
+					'function_name' => $function,
+					'real_function' => $exploded[0],
+					'included_file' => isset($exploded[1]) ? strtr(trim($exploded[1]), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])) : '',
+					'file_name' => (isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ''),
+					'hook_exists' => $hook_exists,
+					'status' => $hook_exists ? ($enabled ? 'allow' : 'moderate') : 'deny',
+					'img_text' => $txt['hooks_' . ($hook_exists ? ($enabled ? 'active' : 'disabled') : 'missing')],
+					'enabled' => $enabled,
+					'can_be_disabled' => !isset($hook_status[$hook][$function]['enabled']),
+				);
+			}
+		}
+	}
+
+	array_multisort($sort, $sort_options[1], $temp_data);
+
+	$counter = 0;
+	$start++;
+
+	foreach ($temp_data as $data)
+	{
+		if (++$counter < $start)
+			continue;
+		elseif ($counter == $start + $per_page)
+			break;
+
+		$hooks_data[] = $data;
+	}
+
+	return $hooks_data;
+}
+
+/**
+ * Simply returns the total count of integraion hooks
+ * Used but the intergation hooks list function (list_integration_hooks)
+ *
+ * @global type $context
+ * @return int
+ */
+function get_integration_hooks_count()
+{
+	global $context;
+
+	$hooks = get_integration_hooks();
+	$hooks_count = 0;
+
+	$context['filter'] = false;
+	if (isset($_GET['filter']))
+		$context['filter'] = $_GET['filter'];
+
+	foreach ($hooks as $hook => $functions)
+	{
+		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
+			$hooks_count += count($functions);
+	}
+
+	return $hooks_count;
+}
+
+/**
+ * Parses modSettings to create integration hook array
+ *
+ * @staticvar type $integration_hooks
+ * @return type
+ */
+function get_integration_hooks()
+{
+	global $modSettings;
+	static $integration_hooks;
+
+	if (!isset($integration_hooks))
+	{
+		$integration_hooks = array();
+		foreach ($modSettings as $key => $value)
+		{
+			if (!empty($value) && substr($key, 0, 10) === 'integrate_')
+				$integration_hooks[$key] = explode(',', $value);
+		}
+	}
+
+	return $integration_hooks;
+}
+
 ?>

+ 0 - 440
Sources/ManageSettings.php

@@ -148,7 +148,6 @@ function ModifyModSettings()
 
 	$subActions = array(
 		'general' => 'ModifyGeneralModSettings',
-		'hooks' => 'list_integration_hooks',
 		// Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end.
 	);
 
@@ -165,8 +164,6 @@ function ModifyModSettings()
 		'tabs' => array(
 			'general' => array(
 			),
-			'hooks' => array(
-			),
 		),
 	);
 
@@ -223,13 +220,6 @@ function ModifyCoreFeatures($return_config = false)
 				);
 			'),
 		),
-		// ih = Integration Hooks Handling.
-		'ih' => array(
-			'url' => 'action=admin;area=modsettings;sa=hooks',
-			'settings' => array(
-				'handlinghooks_enabled' => 1,
-			),
-		),
 		// k = karma.
 		'k' => array(
 			'url' => 'action=admin;area=featuresettings;sa=karma',
@@ -2279,434 +2269,4 @@ function ModifyGeneralModSettings($return_config = false)
 	prepareDBSettingContext($config_vars);
 }
 
-/**
- * Generates a list of integration hooks for display
- * Accessed through ?action=admin;area=modsettings;sa=hooks;
- * Allows for removal or disabing of selected hooks
- */
-function list_integration_hooks()
-{
-	global $sourcedir, $scripturl, $context, $txt, $modSettings, $settings;
-
-	$context['filter_url'] = '';
-	$context['current_filter'] = '';
-	$currentHooks = get_integration_hooks();
-	if (isset($_GET['filter']) && in_array($_GET['filter'], array_keys($currentHooks)))
-	{
-		$context['filter_url'] = ';filter=' . $_GET['filter'];
-		$context['current_filter'] = $_GET['filter'];
-	}
-
-	if (!empty($modSettings['handlinghooks_enabled']))
-	{
-		if (!empty($_REQUEST['do']) && isset($_REQUEST['hook']) && isset($_REQUEST['function']))
-		{
-			checkSession('request');
-			validateToken('admin-hook', 'request');
-
-			if ($_REQUEST['do'] == 'remove')
-				remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
-			else
-			{
-				if ($_REQUEST['do'] == 'disable')
-				{
-					// It's a hack I know...but I'm way too lazy!!!
-					$function_remove = $_REQUEST['function'];
-					$function_add = $_REQUEST['function'] . ']';
-				}
-				else
-				{
-					$function_remove = $_REQUEST['function'] . ']';
-					$function_add = $_REQUEST['function'];
-				}
-				$file = !empty($_REQUEST['includedfile']) ? urldecode($_REQUEST['includedfile']) : '';
-
-				remove_integration_function($_REQUEST['hook'], $function_remove, $file);
-				add_integration_function($_REQUEST['hook'], $function_add, $file);
-
-				redirectexit('action=admin;area=modsettings;sa=hooks' . $context['filter_url']);
-			}
-		}
-	}
-
-	$list_options = array(
-		'id' => 'list_integration_hooks',
-		'title' => $txt['hooks_title_list'],
-		'items_per_page' => 20,
-		'base_href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'],
-		'default_sort_col' => 'hook_name',
-		'get_items' => array(
-			'function' => 'get_integration_hooks_data',
-		),
-		'get_count' => array(
-			'function' => 'get_integration_hooks_count',
-		),
-		'no_items_label' => $txt['hooks_no_hooks'],
-		'columns' => array(
-			'hook_name' => array(
-				'header' => array(
-					'value' => $txt['hooks_field_hook_name'],
-				),
-				'data' => array(
-					'db' => 'hook_name',
-				),
-				'sort' =>  array(
-					'default' => 'hook_name',
-					'reverse' => 'hook_name DESC',
-				),
-			),
-			'function_name' => array(
-				'header' => array(
-					'value' => $txt['hooks_field_function_name'],
-				),
-				'data' => array(
-					'function' => create_function('$data', '
-						global $txt;
-
-						if (!empty($data[\'included_file\']))
-							return $txt[\'hooks_field_function\'] . \': \' . $data[\'real_function\'] . \'<br />\' . $txt[\'hooks_field_included_file\'] . \': \' . $data[\'included_file\'];
-						else
-							return $data[\'real_function\'];
-					'),
-				),
-				'sort' =>  array(
-					'default' => 'function_name',
-					'reverse' => 'function_name DESC',
-				),
-			),
-			'file_name' => array(
-				'header' => array(
-					'value' => $txt['hooks_field_file_name'],
-				),
-				'data' => array(
-					'db' => 'file_name',
-				),
-				'sort' =>  array(
-					'default' => 'file_name',
-					'reverse' => 'file_name DESC',
-				),
-			),
-			'status' => array(
-				'header' => array(
-					'value' => $txt['hooks_field_hook_exists'],
-					'style' => 'width:3%;',
-				),
-				'data' => array(
-					'function' => create_function('$data', '
-						global $txt, $settings, $scripturl, $context;
-
-						$change_status = array(\'before\' => \'\', \'after\' => \'\');
-						if ($data[\'can_be_disabled\'] && $data[\'status\'] != \'deny\')
-						{
-							$change_status[\'before\'] = \'<a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=\' . ($data[\'enabled\'] ? \'disable\' : \'enable\') . \';hook=\' . $data[\'hook_name\'] . \';function=\' . $data[\'real_function\'] . (!empty($data[\'included_file\']) ? \';includedfile=\' . urlencode($data[\'included_file\']) : \'\') . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">\';
-							$change_status[\'after\'] = \'</a>\';
-						}
-						return $change_status[\'before\'] . \'<img src="\' . $settings[\'images_url\'] . \'/admin/post_moderation_\' . $data[\'status\'] . \'.png" alt="\' . $data[\'img_text\'] . \'" title="\' . $data[\'img_text\'] . \'" />\' . $change_status[\'after\'];
-					'),
-					'class' => 'centertext',
-				),
-				'sort' =>  array(
-					'default' => 'status',
-					'reverse' => 'status DESC',
-				),
-			),
-		),
-		'additional_rows' => array(
-			array(
-				'position' => 'after_title',
-				'value' => $txt['hooks_disable_instructions'] . '<br />
-					' . $txt['hooks_disable_legend'] . ':
-									<ul style="list-style: none;">
-					<li><img src="' . $settings['images_url'] . '/admin/post_moderation_allow.png" alt="' . $txt['hooks_active'] . '" title="' . $txt['hooks_active'] . '" /> ' . $txt['hooks_disable_legend_exists'] . '</li>
-					<li><img src="' . $settings['images_url'] . '/admin/post_moderation_moderate.png" alt="' . $txt['hooks_disabled'] . '" title="' . $txt['hooks_disabled'] . '" /> ' . $txt['hooks_disable_legend_disabled'] . '</li>
-					<li><img src="' . $settings['images_url'] . '/admin/post_moderation_deny.png" alt="' . $txt['hooks_missing'] . '" title="' . $txt['hooks_missing'] . '" /> ' . $txt['hooks_disable_legend_missing'] . '</li>
-				</ul>'
-			),
-		),
-	);
-
-	if (!empty($modSettings['handlinghooks_enabled']))
-	{
-		createToken('admin-hook', 'request');
-
-		$list_options['columns']['remove'] = array(
-			'header' => array(
-				'value' => $txt['hooks_button_remove'],
-				'style' => 'width:3%',
-			),
-			'data' => array(
-				'function' => create_function('$data', '
-					global $txt, $settings, $scripturl, $context;
-
-					if (!$data[\'hook_exists\'])
-						return \'
-						<a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=remove;hook=\' . $data[\'hook_name\'] . \';function=\' . urlencode($data[\'function_name\']) . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">
-							<img src="\' . $settings[\'images_url\'] . \'/icons/quick_remove.png" alt="\' . $txt[\'hooks_button_remove\'] . \'" title="\' . $txt[\'hooks_button_remove\'] . \'" />
-						</a>\';
-				'),
-				'class' => 'centertext',
-			),
-		);
-		$list_options['form'] = array(
-			'href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'],
-			'name' => 'list_integration_hooks',
-		);
-	}
-
-
-	require_once($sourcedir . '/Subs-List.php');
-	createList($list_options);
-
-	$context['page_title'] = $txt['hooks_title_list'];
-	$context['sub_template'] = 'show_list';
-	$context['default_list'] = 'list_integration_hooks';
-}
-
-/**
- * Gets all of the files in a directory and its chidren directories
- *
- * @param type $dir_path
- * @return array
- */
-function get_files_recursive($dir_path)
-{
-	$files = array();
-
-	if ($dh = opendir($dir_path))
-	{
-		while (($file = readdir($dh)) !== false)
-		{
-			if ($file != '.' && $file != '..')
-			{
-				if (is_dir($dir_path . '/' . $file))
-					$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
-				else
-					$files[] = array('dir' => $dir_path, 'name' => $file);
-			}
-		}
-	}
-	closedir($dh);
-
-	return $files;
-}
-
-/**
- * Callback function for the integration hooks list (list_integration_hooks)
- * Gets all of the hooks in the system and their status
- * Would be better documented if Ema was not lazy
- *
- * @param type $start
- * @param type $per_page
- * @param type $sort
- * @return array
- */
-function get_integration_hooks_data($start, $per_page, $sort)
-{
-	global $boarddir, $sourcedir, $settings, $txt, $context, $scripturl, $modSettings;
-
-	$hooks = $temp_hooks = get_integration_hooks();
-	$hooks_data = $temp_data = $hook_status = array();
-
-	$files = get_files_recursive($sourcedir);
-	if (!empty($files))
-	{
-		foreach ($files as $file)
-		{
-			if (is_file($file['dir'] . '/' . $file['name']) && substr($file['name'], -4) === '.php')
-			{
-				$fp = fopen($file['dir'] . '/' . $file['name'], 'rb');
-				$fc = fread($fp, filesize($file['dir'] . '/' . $file['name']));
-				fclose($fp);
-
-				foreach ($temp_hooks as $hook => $functions)
-				{
-					foreach ($functions as $function_o)
-					{
-						$hook_name = str_replace(']', '', $function_o);
-						if (strpos($hook_name, '::') !== false)
-						{
-							$function = explode('::', $hook_name);
-							$function = $function[1];
-						}
-						else
-							$function = $hook_name;
-						$function = explode(':', $function);
-						$function = $function[0];
-
-						if (substr($hook, -8) === '_include')
-						{
-							$hook_status[$hook][$function]['exists'] = file_exists(strtr(trim($function), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])));
-							// I need to know if there is at least one function called in this file.
-							$temp_data['include'][basename($function)] = array('hook' => $hook, 'function' => $function);
-							unset($temp_hooks[$hook][$function_o]);
-						}
-						elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($function) . '(') !== false)
-						{
-							$hook_status[$hook][$hook_name]['exists'] = true;
-							$hook_status[$hook][$hook_name]['in_file'] = $file['name'];
-							// I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too)
-							$temp_data['function'][$file['name']][] = $function_o;
-							unset($temp_hooks[$hook][$function_o]);
-						}
-					}
-				}
-			}
-		}
-	}
-
-	$sort_types = array(
-		'hook_name' => array('hook', SORT_ASC),
-		'hook_name DESC' => array('hook', SORT_DESC),
-		'function_name' => array('function', SORT_ASC),
-		'function_name DESC' => array('function', SORT_DESC),
-		'file_name' => array('file_name', SORT_ASC),
-		'file_name DESC' => array('file_name', SORT_DESC),
-		'status' => array('status', SORT_ASC),
-		'status DESC' => array('status', SORT_DESC),
-	);
-
-	$sort_options = $sort_types[$sort];
-	$sort = array();
-	$hooks_filters = array();
-
-	foreach ($hooks as $hook => $functions)
-	{
-		$hooks_filters[] = '<option ' . ($context['current_filter'] == $hook ? 'selected="selected" ' : '') . 'onclick="window.location = \'' . $scripturl . '?action=admin;area=modsettings;sa=hooks;filter=' . $hook . '\';">' . $hook . '</option>';
-		foreach ($functions as $function)
-		{
-			$enabled = strstr($function, ']') === false;
-			$function = str_replace(']', '', $function);
-
-			// This is a not an include and the function is included in a certain file (if not it doesn't exists so don't care)
-			if (substr($hook, -8) !== '_include' && isset($hook_status[$hook][$function]['in_file']))
-			{
-				$current_hook = isset($temp_data['include'][$hook_status[$hook][$function]['in_file']]) ? $temp_data['include'][$hook_status[$hook][$function]['in_file']] : '';
-				$enabled = false;
-
-				// Checking all the functions within this particular file
-				// if any of them is enable then the file *must* be included and the integrate_*_include hook cannot be disabled
-				foreach ($temp_data['function'][$hook_status[$hook][$function]['in_file']] as $func)
-					$enabled = $enabled || strstr($func, ']') !== false;
-
-				if (!$enabled &&  !empty($current_hook))
-					$hook_status[$current_hook['hook']][$current_hook['function']]['enabled'] = true;
-			}
-		}
-	}
-
-	if (!empty($hooks_filters))
-		$context['insert_after_template'] .= '
-		<script type="text/javascript"><!-- // --><![CDATA[
-			var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
-			hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;"><option>---</option><option onclick="window.location = \'' . $scripturl . '?action=admin;area=modsettings;sa=hooks\';">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>'). ';
-		// ]]></script>';
-
-	$temp_data = array();
-	$id = 0;
-
-	foreach ($hooks as $hook => $functions)
-	{
-		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
-		{
-			foreach ($functions as $function)
-			{
-				$enabled = strstr($function, ']') === false;
-				$function = str_replace(']', '', $function);
-				$hook_exists = !empty($hook_status[$hook][$function]['exists']);
-				$file_name = isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ((substr($hook, -8) === '_include') ? 'zzzzzzzzz' : 'zzzzzzzza');
-				$sort[] = $$sort_options[0];
-
-				if (strpos($function, '::') !== false)
-				{
-					$function = explode('::', $function);
-					$function = $function[1];
-				}
-				$exploded = explode(':', $function);
-
-				$temp_data[] = array(
-					'id' => 'hookid_' . $id++,
-					'hook_name' => $hook,
-					'function_name' => $function,
-					'real_function' => $exploded[0],
-					'included_file' => isset($exploded[1]) ? strtr(trim($exploded[1]), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])) : '',
-					'file_name' => (isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ''),
-					'hook_exists' => $hook_exists,
-					'status' => $hook_exists ? ($enabled ? 'allow' : 'moderate') : 'deny',
-					'img_text' => $txt['hooks_' . ($hook_exists ? ($enabled ? 'active' : 'disabled') : 'missing')],
-					'enabled' => $enabled,
-					'can_be_disabled' => !empty($modSettings['handlinghooks_enabled']) && !isset($hook_status[$hook][$function]['enabled']),
-				);
-			}
-		}
-	}
-
-	array_multisort($sort, $sort_options[1], $temp_data);
-
-	$counter = 0;
-	$start++;
-
-	foreach ($temp_data as $data)
-	{
-		if (++$counter < $start)
-			continue;
-		elseif ($counter == $start + $per_page)
-			break;
-
-		$hooks_data[] = $data;
-	}
-
-	return $hooks_data;
-}
-
-/**
- * Simply returns the total count of integraion hooks
- * Used but the intergation hooks list function (list_integration_hooks)
- *
- * @global type $context
- * @return int
- */
-function get_integration_hooks_count()
-{
-	global $context;
-
-	$hooks = get_integration_hooks();
-	$hooks_count = 0;
-
-	$context['filter'] = false;
-	if (isset($_GET['filter']))
-		$context['filter'] = $_GET['filter'];
-
-	foreach ($hooks as $hook => $functions)
-	{
-		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
-			$hooks_count += count($functions);
-	}
-
-	return $hooks_count;
-}
-
-/**
- * Parses modSettings to create integration hook array
- *
- * @staticvar type $integration_hooks
- * @return type
- */
-function get_integration_hooks()
-{
-	global $modSettings;
-	static $integration_hooks;
-
-	if (!isset($integration_hooks))
-	{
-		$integration_hooks = array();
-		foreach ($modSettings as $key => $value)
-		{
-			if (!empty($value) && substr($key, 0, 10) === 'integrate_')
-				$integration_hooks[$key] = explode(',', $value);
-		}
-	}
-
-	return $integration_hooks;
-}
-
 ?>

BIN
Themes/default/images/admin/feature_ih.png


+ 0 - 2
Themes/default/languages/ManageSettings.english.php

@@ -300,8 +300,6 @@ $txt['core_settings_item_cd'] = 'Calendar';
 $txt['core_settings_item_cd_desc'] = 'Enabling this feature will open up a selection of options to enable your users to view the calendar, add and review events, see users birthdates on a calendar and much, much more.';
 $txt['core_settings_item_dr'] = 'Drafts';
 $txt['core_settings_item_dr_desc'] = 'Enabling this feature will allow users to save drafts of their posts so they can return later to post them.';
-$txt['core_settings_item_ih'] = 'Integration Hooks Management';
-$txt['core_settings_item_ih_desc'] = 'This feature allows you to enable or disable any integration hooks added by modifications. Changing hooks can prevent your forum from working properly, so use this feature only if you know what you are doing.';
 $txt['core_settings_item_k'] = 'Karma';
 $txt['core_settings_item_k_desc'] = 'Karma is a feature that shows the popularity of a member. Members, if allowed, can \'applaud\' or \'smite\' other members, which is how their popularity is calculated.';
 $txt['core_settings_item_ml'] = 'Moderation, Administration and User Logs';