Browse Source

! The rest of the changes required for category descriptions. A few notes: I don't think I broke anything in the theme by de-restricting the catbg height, nothing looks obviously broken; I'm not exactly a fan of how we do the board descriptions stuff anyway, but I've made the cat description behave consistently - i.e. not running htmlspecialchars. Not going to argue about this; unless we're going to change the board descriptions, cat descriptions will behave this way. This will be fixed in 3.0 but we've always said about not fixing it in 2.x for the reason that users rely on it. As far as performance goes, there should be no significant increases; if it's going to filesort, it was going to do it anyway, and if not, it won't now anyway.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 11 years ago
parent
commit
45f9f397b7

+ 3 - 0
Sources/ManageBoards.php

@@ -243,6 +243,7 @@ function EditCategory()
 			'id' => 0,
 			'name' => $txt['mboards_new_cat_name'],
 			'editable_name' => $smcFunc['htmlspecialchars']($txt['mboards_new_cat_name']),
+			'description' => '',
 			'can_collapse' => true,
 			'is_new' => true,
 			'is_empty' => true
@@ -257,6 +258,7 @@ function EditCategory()
 			'id' => $_REQUEST['cat'],
 			'name' => $cat_tree[$_REQUEST['cat']]['node']['name'],
 			'editable_name' => $smcFunc['htmlspecialchars']($cat_tree[$_REQUEST['cat']]['node']['name']),
+			'description' => $smcFunc['htmlspecialchars']($cat_tree[$_REQUEST['cat']]['node']['description']),
 			'can_collapse' => !empty($cat_tree[$_REQUEST['cat']]['node']['can_collapse']),
 			'children' => array(),
 			'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children'])
@@ -327,6 +329,7 @@ function EditCategory2()
 
 		// Change "This & That" to "This &amp; That" but don't change "&cent" to "&amp;cent;"...
 		$catOptions['cat_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&amp;$1', $_POST['cat_name']);
+		$catOptions['cat_desc'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&amp;$1', $_POST['cat_desc']);
 
 		$catOptions['is_collapsible'] = isset($_POST['collapse']);
 

+ 2 - 1
Sources/Subs-BoardIndex.php

@@ -44,7 +44,7 @@ function getBoardIndex($boardIndexOptions)
 	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
 	$result_boards = $smcFunc['db_query']('boardindex_fetch_boards', '
 		SELECT' . ($boardIndexOptions['include_categories'] ? '
-			c.id_cat, c.name AS cat_name,' : '') . '
+			c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . '
 			b.id_board, b.name AS board_name, b.description,
 			CASE WHEN b.redirect != {string:blank_string} THEN 1 ELSE 0 END AS is_redirect,
 			b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent,
@@ -99,6 +99,7 @@ function getBoardIndex($boardIndexOptions)
 				$categories[$row_board['id_cat']] = array(
 					'id' => $row_board['id_cat'],
 					'name' => $row_board['cat_name'],
+					'description' => $row_board['cat_desc'],
 					'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'] : '',

+ 2 - 1
Sources/Subs-Boards.php

@@ -1148,7 +1148,7 @@ function getBoardTree()
 		SELECT
 			IFNULL(b.id_board, 0) AS id_board, b.id_parent, b.name AS board_name, b.description, b.child_level,
 			b.board_order, b.count_posts, b.member_groups, b.id_theme, b.override_theme, b.id_profile, b.redirect,
-			b.num_posts, b.num_topics, b.deny_member_groups, c.id_cat, c.name AS cat_name, c.cat_order, c.can_collapse
+			b.num_posts, b.num_topics, b.deny_member_groups, c.id_cat, c.name AS cat_name, c.description AS cat_desc, c.cat_order, c.can_collapse
 		FROM {db_prefix}categories AS c
 			LEFT JOIN {db_prefix}boards AS b ON (b.id_cat = c.id_cat)
 		ORDER BY c.cat_order, b.child_level, b.board_order',
@@ -1166,6 +1166,7 @@ function getBoardTree()
 				'node' => array(
 					'id' => $row['id_cat'],
 					'name' => $row['cat_name'],
+					'description' => $row['cat_desc'],
 					'order' => $row['cat_order'],
 					'can_collapse' => $row['can_collapse']
 				),

+ 10 - 0
Sources/Subs-Categories.php

@@ -87,6 +87,12 @@ function modifyCategory($category_id, $catOptions)
 		$catParameters['cat_name'] = $catOptions['cat_name'];
 	}
 
+	if (isset($catOptions['cat_desc']))
+	{
+		$catUpdates[] = 'description = {string:cat_desc}';
+		$catParameters['cat_desc'] = $catOptions['cat_desc'];
+	}
+
 	// Can a user collapse this category or is it too important?
 	if (isset($catOptions['is_collapsible']))
 	{
@@ -133,6 +139,8 @@ function createCategory($catOptions)
 		trigger_error('createCategory(): A category name is required', E_USER_ERROR);
 
 	// Set default values.
+	if (!isset($catOptions['cat_desc']))
+		$catOptions['cat_desc'] = '';
 	if (!isset($catOptions['move_after']))
 		$catOptions['move_after'] = 0;
 	if (!isset($catOptions['is_collapsible']))
@@ -142,9 +150,11 @@ function createCategory($catOptions)
 
 	$cat_columns = array(
 		'name' => 'string-48',
+		'description' => 'string',
 	);
 	$cat_parameters = array(
 		$catOptions['cat_name'],
+		$catOptions['cat_desc'],
 	);
 
 	call_integration_hook('integrate_create_category', array(&$catOptions, &$cat_columns, &$cat_parameters));

+ 2 - 1
Themes/default/BoardIndex.template.php

@@ -120,7 +120,8 @@ function template_main()
 								<a class="collapse" href="', $category['collapse_href'], '" title="' ,$category['is_collapsed'] ? $txt['show'] : $txt['hide'] ,'">', $category['collapse_image'], '</a>';
 
 		echo '
-								', $category['link'], '
+								', $category['link'], !empty($category['description']) ? '
+								<div class="desc">' . $category['description'] . '</div>' : '', '
 							</h3>
 						</div>
 					</td>

+ 7 - 0
Themes/default/ManageBoards.template.php

@@ -152,6 +152,13 @@ function template_modify_category()
 						<dd>
 							<input type="text" name="cat_name" value="', $context['category']['editable_name'], '" size="30" tabindex="', $context['tabindex']++, '" class="input_text" />
 						</dd>
+						<dt>
+							<strong>', $txt['mboards_description'], '</strong><br />
+							<span class="smalltext">', $txt['mboards_cat_description_desc'], '</span>
+						</dt>
+						<dd>
+							<textarea name="cat_desc" rows="3" cols="35" style="width: 99%;">', $context['category']['description'], '</textarea>
+						</dd>
 						<dt>
 							<strong>', $txt['collapse_enable'], '</strong><br />
 							<span class="smalltext">', $txt['collapse_desc'], '</span>

+ 6 - 1
Themes/default/css/index.css

@@ -833,6 +833,12 @@ h3.catbg, h3.catbg2, h3.titlebg, h4.titlebg, h4.catbg {
 	line-height: 1.5em;
 	padding: 8px;
 }
+h3.catbg .desc
+{
+	font-size: 10px;
+	line-height: 1.5em;
+	font-weight: normal;
+}
 h3.catbg a:link, h3.catbg a:visited, h4.catbg a:link, h4.catbg a:visited, h3.catbg, .table_list tbody.header td, .table_list tbody.header td a {
 	color: #fff;
 }
@@ -905,7 +911,6 @@ div.cat_bar {
 }
 .cat_bar h3 {
 	padding: 8px 12px 6px 12px;
-	height: 1.6em;
 }
 div.title_bar {
 	background: #557ea0;

+ 1 - 0
Themes/default/languages/ManageBoards.english.php

@@ -47,6 +47,7 @@ $txt['mboards_delete_cancel'] = 'Cancel';
 $txt['mboards_category'] = 'Category';
 $txt['mboards_description'] = 'Description';
 $txt['mboards_description_desc'] = 'A short description of your board.';
+$txt['mboards_cat_description_desc'] = 'A short description of your category.';
 $txt['mboards_groups'] = 'Allowed Groups';
 $txt['mboards_groups_desc'] = 'Groups allowed to access this board.<br /><em>Note: if the member is in any group or post group checked, they will have access to this board.</em>';
 $txt['mboards_groups_regular_members'] = 'This group contains all members that have no primary group set.';