Browse Source

Merge pull request #777 from Arantor/release-2.1

Some more goodies for SMF
Arantor 11 years ago
parent
commit
3d5fb390b5

+ 73 - 2
Sources/ManageServer.php

@@ -36,6 +36,9 @@
  * 		array('permissions', 'manage_groups'),
  * - A BBC selection box.
  * 		array('bbc', 'sig_bbc'),
+ * - A list of boards to choose from
+ *  	array('boards', 'likes_boards'),
+ *  	Note that the storage in the database is as 1,2,3,4
  *
  * For each option:
  * 	- type (see above), variable name, size/possible values.
@@ -666,6 +669,7 @@ function prepareDBSettingContext(&$config_vars)
 	$context['config_vars'] = array();
 	$inlinePermissions = array();
 	$bbcChoice = array();
+	$board_list = false;
 	foreach ($config_vars as $config_var)
 	{
 		// HR?
@@ -683,10 +687,48 @@ function prepareDBSettingContext(&$config_vars)
 			elseif ($config_var[0] == 'permissions')
 				continue;
 
+			if ($config_var[0] == 'boards')
+				$board_list = true;
+
 			// Are we showing the BBC selection box?
 			if ($config_var[0] == 'bbc')
 				$bbcChoice[] = $config_var[1];
 
+			// We need to do some parsing of the value before we pass it in.
+			if (isset($modSettings[$config_var[1]]))
+			{
+				switch ($config_var[0])
+				{
+					case 'select':
+						$value = $modSettings[$config_var[1]];
+						break;
+					case 'boards':
+						$value = explode(',', $modSettings[$config_var[1]]);
+						break;
+					default:
+						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
+				}
+			}
+			else
+			{
+				// Darn, it's empty. What type is expected?
+				switch ($config_var[0])
+				{
+					case 'int':
+					case 'float':
+						$value = 0;
+						break;
+					case 'select':
+						$value = !empty($config_var['multiple']) ? serialize(array()) : '';
+						break;
+					case 'boards':
+						$value = array();
+						break;
+					default:
+						$value = '';
+				}
+			}
+
 			$context['config_vars'][$config_var[1]] = array(
 				'label' => isset($config_var['text_label']) ? $config_var['text_label'] : (isset($txt[$config_var[1]]) ? $txt[$config_var[1]] : (isset($config_var[3]) && !is_array($config_var[3]) ? $config_var[3] : '')),
 				'help' => isset($helptxt[$config_var[1]]) ? $config_var[1] : '',
@@ -694,7 +736,7 @@ function prepareDBSettingContext(&$config_vars)
 				'size' => !empty($config_var[2]) && !is_array($config_var[2]) ? $config_var[2] : (in_array($config_var[0], array('int', 'float')) ? 6 : 0),
 				'data' => array(),
 				'name' => $config_var[1],
-				'value' => isset($modSettings[$config_var[1]]) ? ($config_var[0] == 'select' ? $modSettings[$config_var[1]] : $smcFunc['htmlspecialchars']($modSettings[$config_var[1]])) : (in_array($config_var[0], array('int', 'float')) ? 0 : (!empty($config_var['multiple']) ? serialize(array()) : '')),
+				'value' => $value,
 				'disabled' => false,
 				'invalid' => !empty($config_var['invalid']),
 				'javascript' => '',
@@ -759,6 +801,12 @@ function prepareDBSettingContext(&$config_vars)
 		init_inline_permissions($inlinePermissions, isset($context['permissions_excluded']) ? $context['permissions_excluded'] : array());
 	}
 
+	if ($board_list)
+	{
+		require_once($sourcedir . '/Subs-MessageIndex.php');
+		$context['board_list'] = getBoardList();
+	}
+
 	// What about any BBC selection boxes?
 	if (!empty($bbcChoice))
 	{
@@ -922,7 +970,8 @@ function saveSettings(&$config_vars)
  */
 function saveDBSettings(&$config_vars)
 {
-	global $sourcedir, $context;
+	global $sourcedir, $context, $smcFunc;
+	static $board_list = null;
 
 	validateToken('admin-dbsc');
 
@@ -948,6 +997,28 @@ function saveDBSettings(&$config_vars)
 
 			$setArray[$var[1]] = serialize($options);
 		}
+		// List of boards!
+		elseif ($var[0] == 'boards')
+		{
+			// We just need a simple list of valid boards, nothing more.
+			if ($board_list === null)
+			{
+				$board_list = array();
+				$request = $smcFunc['db_query']('', '
+					SELECT id_board
+					FROM {db_prefix}boards');
+				while ($row = $smcFunc['db_fetch_row']($request))
+					$board_list[$row[0]] = true;
+				$smcFunc['db_free_result']($request);
+			}
+
+			$options = array();
+			foreach ($_POST[$var[1]] as $invar => $dummy)
+				if (isset($board_list[$invar]))
+					$options[] = $invar;
+
+			$setArray[$var[1]] = implode(',', $options);
+		}
 		// Integers!
 		elseif ($var[0] == 'int')
 			$setArray[$var[1]] = (int) $_POST[$var[1]];

+ 1 - 1
Sources/Subs-BoardIndex.php

@@ -102,7 +102,7 @@ function getBoardIndex($boardIndexOptions)
 					'is_collapsed' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1 && $row_board['is_collapsed'] > 0,
 					'can_collapse' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1,
 					'collapse_href' => isset($row_board['can_collapse']) ? $scripturl . '?action=collapse;c=' . $row_board['id_cat'] . ';sa=' . ($row_board['is_collapsed'] > 0 ? 'expand;' : 'collapse;') . $context['session_var'] . '=' . $context['session_id'] . '#c' . $row_board['id_cat'] : '',
-					'collapse_image' => isset($row_board['can_collapse']) ? '<img src="' . $settings['images_url'] . '/' . $context['theme_variant_url'] . ($row_board['is_collapsed'] > 0 ? 'expand.png" alt="+"' : 'collapse.png" alt="-"') . ' />' : '',
+					'collapse_image' => isset($row_board['can_collapse']) ? '<span class="' . ($row_board['is_collapsed'] > 0 ? 'toggle_down' : 'toggle_up') . '"></span>' : '',
 					'href' => $scripturl . '#c' . $row_board['id_cat'],
 					'boards' => array(),
 					'new' => false

+ 41 - 0
Themes/default/Admin.template.php

@@ -845,6 +845,34 @@ function template_show_settings()
 					echo '
 							</select>';
 				}
+				// List of boards? This requires getBoardList() having been run and the results in $context['board_list'].
+				elseif ($config_var['type'] == 'boards')
+				{
+					$board_list = true;
+					$first = true;
+					echo '
+							<a href="#" class="board_selector">[ ', $txt['select_boards_from_list'], ' ]</a>
+							<fieldset>
+								<legend class="board_selector"><a href="#">', $txt['select_boards_from_list'], '</a></legend>';
+					foreach ($context['board_list'] as $id_cat => $cat)
+					{
+						if (!$first)
+							echo '
+								<hr />';
+						echo '
+								<strong>', $cat['name'], '</strong>
+								<ul>';
+						foreach ($cat['boards'] as $id_board => $brd)
+							echo '
+									<li><label><input type="checkbox" name="', $config_var['name'], '[', $brd['id'], ']" value="1" class="input_check"', in_array($brd['id'], $config_var['value']) ? ' checked="checked"' : '', ' /> ', $brd['child_level'] > 0 ? str_repeat('&nbsp; &nbsp;', $brd['child_level']) : '', $brd['name'], '</label></li>';
+
+						echo '
+								</ul>';
+						$first = false;
+					}
+					echo '
+							</fieldset>';
+				}
 				// Text area?
 				elseif ($config_var['type'] == 'large_text')
 					echo '
@@ -943,6 +971,19 @@ function template_show_settings()
 
 	if (!empty($context['settings_insert_below']))
 		echo $context['settings_insert_below'];
+
+	// We may have added a board listing. If we did, we need to make it work.
+	addInlineJavascript('
+	$("legend.board_selector").closest("fieldset").hide();
+	$("a.board_selector").click(function(e) {
+		e.preventDefault();
+		$(this).hide().next("fieldset").show();
+	});
+	$("fieldset legend.board_selector a").click(function(e) {
+		e.preventDefault();
+		$(this).closest("fieldset").hide().prev("a").show();
+	});
+	', true);
 }
 
 // Template for showing custom profile fields.

+ 3 - 1
Themes/default/languages/ManageSettings.english.php

@@ -358,4 +358,6 @@ $txt['setting_frame_security_SAMEORIGIN'] = 'Allow Same Origin';
 $txt['setting_frame_security_DENY'] = 'Deny all frames';
 $txt['setting_frame_security_DISABLE'] = 'Disabled';
 
-?>
+$txt['select_boards_from_list'] = 'Select boards which apply';
+
+?>