Browse Source

Merge pull request #936 from Arantor/release-2.1

Categories can have descriptions too. Some of the commits have useful and interesting notes.
Arantor 11 years ago
parent
commit
feaac6608f

+ 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 & That" but don't change "&cent" to "¢"...
 		$catOptions['cat_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$1', $_POST['cat_name']);
+		$catOptions['cat_desc'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$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.';

+ 2 - 1
other/install_2-1_mysql.sql

@@ -707,6 +707,7 @@ CREATE TABLE {$db_prefix}categories (
   id_cat tinyint(4) unsigned NOT NULL auto_increment,
   cat_order tinyint(4) NOT NULL default '0',
   name varchar(255) NOT NULL default '',
+  description text NOT NULL default
   can_collapse tinyint(1) NOT NULL default '1',
   PRIMARY KEY (id_cat)
 ) ENGINE=MyISAM;
@@ -716,7 +717,7 @@ CREATE TABLE {$db_prefix}categories (
 #
 
 INSERT INTO {$db_prefix}categories
-VALUES (1, 0, '{$default_category_name}', 1);
+VALUES (1, 0, '{$default_category_name}', '', 1);
 # --------------------------------------------------------
 
 #

+ 2 - 1
other/install_2-1_postgresql.sql

@@ -917,6 +917,7 @@ CREATE TABLE {$db_prefix}categories (
   id_cat smallint default nextval('{$db_prefix}categories_seq'),
   cat_order smallint NOT NULL default '0',
   name varchar(255) NOT NULL,
+  description text NOT NULL,
   can_collapse smallint NOT NULL default '1',
   PRIMARY KEY (id_cat)
 );
@@ -926,7 +927,7 @@ CREATE TABLE {$db_prefix}categories (
 #
 
 INSERT INTO {$db_prefix}categories
-VALUES (1, 0, '{$default_category_name}', 1);
+VALUES (1, 0, '{$default_category_name}', '', 1);
 # --------------------------------------------------------
 
 #

+ 2 - 1
other/install_2-1_sqlite.sql

@@ -727,6 +727,7 @@ CREATE TABLE {$db_prefix}categories (
   id_cat integer primary key,
   cat_order smallint NOT NULL default '0',
   name varchar(255) NOT NULL,
+  description text NOT NULL,
   can_collapse smallint NOT NULL default '1'
 );
 
@@ -735,7 +736,7 @@ CREATE TABLE {$db_prefix}categories (
 #
 
 INSERT INTO {$db_prefix}categories
-VALUES (1, 0, '{$default_category_name}', 1);
+VALUES (1, 0, '{$default_category_name}', '', 1);
 # --------------------------------------------------------
 
 #

+ 1 - 0
other/install_2-1_sqlite3.sql

@@ -727,6 +727,7 @@ CREATE TABLE {$db_prefix}categories (
   id_cat integer primary key,
   cat_order smallint NOT NULL default '0',
   name varchar(255) NOT NULL,
+  description text NOT NULL,
   can_collapse smallint NOT NULL default '1'
 );
 

+ 8 - 0
other/upgrade_2-1_mysql.sql

@@ -234,6 +234,14 @@ ALTER TABLE {$db_prefix}boards
 ADD COLUMN deny_member_groups varchar(255) NOT NULL DEFAULT '';
 ---#
 
+/******************************************************************************/
+--- Adding support for category descriptions
+/******************************************************************************/
+---# Adding new columns to categories...
+ALTER TABLE {$db_prefix}categories
+ADD COLUMN description text NOT NULL;
+---#
+
 /******************************************************************************/
 --- Adding support for topic unwatch
 /******************************************************************************/

+ 11 - 0
other/upgrade_2-1_postgresql.sql

@@ -295,6 +295,17 @@ upgrade_query("
 ---}
 ---#
 
+/******************************************************************************/
+--- Adding support for category descriptions
+/******************************************************************************/
+---# Adding new columns to categories...
+---{
+upgrade_query("
+	ALTER TABLE {$db_prefix}categories
+	ADD COLUMN description text NOT NULL;");
+---}
+---#
+
 /******************************************************************************/
 --- Adding support for topic unwatch
 /******************************************************************************/

+ 18 - 0
other/upgrade_2-1_sqlite.sql

@@ -267,6 +267,24 @@ $smcFunc['db_alter_table']('{db_prefix}boards', array(
 ---}
 ---#
 
+/******************************************************************************/
+--- Adding support for category descriptions
+/******************************************************************************/
+---# Adding new columns to categories...
+---{
+$smcFunc['db_alter_table']('{db_prefix}log_topics', array(
+	'add' => array(
+		'description' => array(
+			'name' => 'description',
+			'null' => false,
+			'type' => 'text',
+			'auto' => false,
+		),
+	)
+));
+---}
+---#
+
 /******************************************************************************/
 --- Adding support for topic unwatch
 /******************************************************************************/