Index: database/database.mysql =================================================================== RCS file: /cvs/drupal/drupal/database/database.mysql,v retrieving revision 1.145 diff -u -F^f -r1.145 database.mysql --- database/database.mysql 13 Sep 2004 13:50:06 -0000 1.145 +++ database/database.mysql 15 Sep 2004 05:02:19 -0000 @@ -714,6 +714,7 @@ hierarchy tinyint(3) unsigned NOT NULL default '0', multiple tinyint(3) unsigned NOT NULL default '0', required tinyint(3) unsigned NOT NULL default '0', + module varchar(255) NOT NULL default '', nodes longtext, weight tinyint(4) NOT NULL default '0', PRIMARY KEY (vid) Index: database/updates.inc =================================================================== RCS file: /cvs/drupal/drupal/database/updates.inc,v retrieving revision 1.59 diff -u -F^f -r1.59 updates.inc --- database/updates.inc 14 Sep 2004 21:13:01 -0000 1.59 +++ database/updates.inc 15 Sep 2004 05:02:20 -0000 @@ -81,7 +81,8 @@ "2004-08-12" => "update_102", "2004-08-17" => "update_103", "2004-08-19" => "update_104", - "2004-09-14" => "update_105" + "2004-09-14" => "update_105", + "2004-09-15" => "udpate_106" ); function update_32() { @@ -1798,6 +1799,20 @@ function update_105() { return $ret; } +function update_106() { + $ret = array(); + + $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255) NOT NULL default ''"); + $ret[] = update_sql("UPDATE {vocabulary} SET module = 'taxonomy'"); + $vid = variable_get('forum_nav_vocabulary', ''); + if (!empty($vid)) { + $ret[] = update_sql("UDPATE {vocabulary} SET module = 'forum' WHERE vid = " . $vid); + } + + return $ret; +} + + function update_sql($sql) { $edit = $_POST["edit"]; $result = db_query($sql); Index: modules/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum.module,v retrieving revision 1.198 diff -u -F^f -r1.198 forum.module --- modules/forum.module 14 Sep 2004 05:48:02 -0000 1.198 +++ modules/forum.module 15 Sep 2004 05:02:21 -0000 @@ -13,16 +13,21 @@ function forum_help($section) { switch ($section) { case 'admin/help#forum': return t(" -
The forum module uses taxonomy to organize itself. To create a forum you first have to create a taxonomy vocabulary. When doing this, choose a sensible name for it (such as \"fora\") and make sure under \"Types\" that \"forum\" is selected. Once you have done this, add some terms to it. Each term will become a forum. If you fill in the description field, users will be given additonal information about the forum on the main forum page. For example: \"troubleshooting\" - \"Please ask your questions here.\"
-When you are happy with your vocabulary, go to administer » settings » forum and set Forum vocabulary to the one you have just created. There will now be fora active on the site. For users to access them they must have the \"access content\" permission and to create a topic they must have the \"create forum topics\" permission. These permissions can be set in the permission pages.
-To disable icons, set the icon path as blank in administer » settings » forum.
-All files in the icon directory are assumed to be images. You may use images of whatever size you wish, but it is recommended to use 15x15 or 16x16.
", array("%taxonomy" => url('admin/taxonomy/add/vocabulary'), '%taxo-terms' => url('admin/taxonomy'), '%forums' => url('admin/settings/forum'), '%permission' => url('admin/user/configure/permission'))); +The forum module allows you to create threaded discussion forums on your site.
+Forums and containers are used to organize the threaded discussions. Forums may be nested in each other. A container is used to group like forums together with out allowing topics to be created in the container. Containers can be nested just like forums. The forums and containers are created and maintained in administer » forums. +
All files in the icon directory are assumed to be images. You may use images of whatever size you wish, but it is recommended to use 15x15 or 16x16. To disable icons, set the icon path as blank in administer » forums » configure.
", array('%forums' => url('admin/forum'), '%forum_config' => url('admin/forum/configure'), '%permission' => url('admin/user/configure/permission'))); + case 'admin/forum': + return t('Forums and containers are used to organize the threaded discussions. Forums may be nested in each other. A container is used to group like forums together with out allowing topics to be created in the container. Containers can be nested just like forums. To delete a forum or container choose the appropriate "edit" operation.'); + case 'admin/forum/add/container': + return t('When creating a contianer you are creating a group to contain multiple forums. Users are not able to create topic inside container. You can nest containers inside forums or other containers.'); + case 'admin/forum/add/forum': + return t('When createing a forum you are creating an area for user to create similar topics for discussion. Forums may be nested underneath other forums or in containers.'); + case 'admin/forum/configure': + return t('Settings for how forums are displayed.'); case 'admin/modules#description': return t('Enable threaded discussions about general topics.'); - case 'admin/settings/forum': - return t("Forums are threaded discussions based on the taxonomy system. For the forums to work, the taxonomy module has to be installed and enabled. When activated, a taxonomy vocabulary (eg. \"forums\") needs to be created and bound to the node type \"forum topic\".", array('%created' => url('admin/taxonomy/add/vocabulary'))); case 'node/add/forum': return variable_get('forum_help', ''); case 'node/add#forum': @@ -50,54 +55,236 @@ function forum_access($op, $node) { * Implementation of hook_perm(). */ function forum_perm() { - return array('create forum topics'); + return array('create forum topics', 'administer forums'); } /** - * Implementation of hook_settings(). + * Admiinstration page which allows maintaining forums */ -function forum_settings() { +function forum_admin() { + $op = $_POST['op']; + $edit = $_POST['edit']; + + if (empty($op)) { + $op = arg(2); + } + + switch ($op) { + case 'add': + if (arg(3) == 'forum') { + $output = forum_form_forum(); + } + else if (arg(3) == 'container') { + $output = forum_form_container(); + } + break; + case 'edit': + if (arg(3) == 'forum') { + $output = forum_form_forum(object2array(taxonomy_get_term(arg(4)))); + } + else if (arg(3) == 'container') { + $output = forum_form_container(object2array(taxonomy_get_term(arg(4)))); + } + break; + case t('Delete'): + if (!$edit['confirm']) { + $output = _forum_confirm_del($edit['tid']); + break; + } + else { + $edit['name'] = 0; + } + case t('Submit'): + $edit = taxonomy_save_term($edit); + if (arg(3) == 'container') { + $containers = variable_get('forum_containers', array()); + $containers[] = $edit['tid']; + variable_set('forum_containers', $containers); + } + drupal_goto('admin/forum'); + default: + $output = forum_overview(); + } + + print theme('page', $output); +} - if (module_exist('taxonomy')) { - $vocs[0] = '<'. t('none') .'>'; - foreach (taxonomy_get_vocabularies('forum') as $vid => $voc) { - $vocs[$vid] = $voc->name; - } - - if ($voc) { - $group = form_select(t('Forum vocabulary'), 'forum_nav_vocabulary', variable_get('forum_nav_vocabulary', ''), $vocs, t("The taxonomy vocabulary that will be used as the navigation tree. The vocabulary's terms define the forums.")); - $group .= _taxonomy_term_select(t('Containers'), 'forum_containers', variable_get('forum_containers', array()), variable_get('forum_nav_vocabulary', ''), t('You can choose forums which will not have topics, but will be just containers for other forums. This lets you both group and nest forums.'), 1, '<'. t('none') .'>'); - - $output = form_group(t('Forum structure settings'), $group); - - $group = form_textarea(t('Explanation or submission guidelines'), 'forum_help', variable_get('forum_help', ''), 70, 5, t('This text will be displayed at the top of the forum submission form. Useful for helping or instructing your users.')); - $group .= form_textfield(t('Forum icon path'), 'forum_icon_path', variable_get('forum_icon_path', ''), 30, 255, t('The path to the forum icons. Leave blank to disable icons. Don\'t add a trailing slash. Default icons are available in the "misc" directory.')); - $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 10000)); - $group .= form_select(t('Hot topic threshold'), 'forum_hot_topic', variable_get('forum_hot_topic', 15), $number, t('The number of posts a topic must have to be considered hot.')); - $number = drupal_map_assoc(array(10, 25, 50, 75, 100)); - $group .= form_select(t('Topics per page'), 'forum_per_page', variable_get('forum_per_page', 25), $number, t('The default number of topics displayed per page; links to browse older messages are automatically being displayed.')); - $forder = array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4=> t('Posts - least active first')); - $group .= form_radios(t('Default order'), 'forum_order', variable_get('forum_order', '1'), $forder, t('The default display order for topics.')); - $output .= form_group(t('Forum viewing options'), $group); +/** + * Implementation of hook_taxonomy(). + */ +function forum_taxonomy($op, $type, $object) { + if ($op == 'delete' && $type == 'term' && $object->vid == _forum_get_vid()) { + $results = db_query('SELECT f.nid FROM forum f WHERE f.tid = %d', $object->tid); + while ($node = db_fetch_object($results)) { + $edit['nid'] = $node->nid; + $edit['confirm'] = TRUE; + node_delete($edit); + } + } +} + +/** + * Returns a confirmation page for deleting a forum taxonomy term + * + * @param $tid ID of the term to be deleted + */ +function _forum_confirm_del($tid) { + $term = taxonomy_get_term($tid); + + $form .= form_hidden('confirm', 1); + $form .= form_hidden('tid', $tid); + $form .= form_submit(t('Delete')); + $form .= form_submit(t('Cancel')); + + return form(form_item(t('Delete "%name"', array('%name' => $term->name)), $form, t('Deleteing a forum or container will delete all children as well. Are you sure you want to delete?'))); +} + +/** + * Returns a form for adding a container to the forum vocabulary + * + * @param $edit Associative array containing a container term to be added or edited. + */ +function forum_form_container($edit = array()) { + $form = form_textfield(t('Container name'), 'name', $edit['name'], 50, 64, t('The name for this container.'), NULL, TRUE); + $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('A description of the container.')); + + $form .= _forum_parent_select($edit['tid'], t('Parent'), 'parent]['); + $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.')); + + $form .= form_hidden('vid', _forum_get_vid()); + $form .= form_submit(t('Submit')); + if ($edit['tid']) { + $form .= form_submit(t('Delete')); + $form .= form_hidden('tid', $edit['tid']); + } + + return form($form); +} + +/** + * Returns a form for adding a forum to the forum vocabulary + * + * @param $edit Associative array containing a forum term to be added or edited. + */ +function forum_form_forum($edit = array()) { + $form = form_textfield(t('Forum name'), 'name', $edit['name'], 50, 64, t('The name for this forum.'), NULL, TRUE); + $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('A description of the forum.')); + + $form .= _forum_parent_select($edit['tid'], t('Parent'), 'parent]['); + $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.')); + + $form .= form_hidden('vid', _forum_get_vid()); + $form .= form_submit(t('Submit')); + if ($edit['tid']) { + $form .= form_submit(t('Delete')); + $form .= form_hidden('tid', $edit['tid']); + } + + return form($form); +} + +/** + * Returns a select box for available parent terms + * + * @param $tid ID of the term which is being added or edited + * @param $title Title to display the select box with + * @param $name Name to use in the forum + */ + function _forum_parent_select($tid, $title, $name) { + + $parents = taxonomy_get_parents($tid); + $children = taxonomy_get_tree(_forum_get_vid, $tid); - $group = form_select(t('Number of topics in block'), 'forum_block_num', variable_get('forum_block_num', '5'), drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)), t('The number of topics to show in the "Forum topics" block. To enable the block, go to the block administration page.', array('%block-administration' => url('admin/block')))); - $output .= form_group(t('"Forum topic" block settings'), $group); + // A term can't be the child of itself, nor of its children. + foreach ($children as $child) { + $exclude[] = $child->tid; + } + $exclude[] = $tid; + + $tree = taxonomy_get_tree(_forum_get_vid()); + $options[0] = '<'. t('root') .'>'; + if ($tree) { + foreach ($tree as $term) { + if (!in_array($term->tid, $exclude)) { + $options[$term->tid] = _forum_depth($term->depth).$term->name; + } } + } + + if (!$parents) { + $parents = 0; } - return $output; + return form_select($title, $name, $parents, $options, NULL, 0, FALSE, TRUE); } /** - * Implementation of hook_taxonomy(). + * Returns an overview list of existing forums and contianers */ -function forum_taxonomy($op, $type, $object) { - if ($type == 'vocabulary' && ($op == 'insert' || $op == 'update')) { - if (variable_get('forum_nav_vocabulary', '') == '' && in_array('forum', $object['nodes'])) { - // since none is already set, silently set this vocabulary as the navigation vocabulary - variable_set('forum_nav_vocabulary', $object['vid']); +function forum_overview() { + $header = array(t('Name'), t('Operations')); + + $tree = taxonomy_get_tree(_forum_get_vid()); + if ($tree) { + foreach ($tree as $term) { + if (in_array($term->tid, variable_get('forum_containers', array()))) { + $rows[] = array(_forum_depth($term->depth) .' '. $term->name, l(t('edit container'), "admin/forum/edit/container/$term->tid")); + } + else { + $rows[] = array(_forum_depth($term->depth) .' '. $term->name, l(t('edit forum'), "admin/forum/edit/forum/$term->tid")); + } } } + + return theme('table', $header, $rows); +} + +/** + * Helper function used to generate indentation for forum list + * + * @param $depth Depth of the indentation + * @param $graphic HTML text to be repeated for each stage of depth + */ +function _forum_depth($depth, $graphic = '--') { + for ($n = 0; $n < $depth; $n++) { + $result .= $graphic; + } + return $result; +} + +/** + * Returns the vocabulary id for forum navigation. + */ +function _forum_get_vid() { + $vid = variable_get('forum_nav_vocabulary', ''); + if (empty($vid)) { + $vocabulary = taxonomy_save_vocabulary(array('name' => 'Forums', 'multiple' => '0', 'required' => '1', 'hierarchy' => '1', 'relations' => '0', 'module' => 'forums', 'nodes' => array('forum'))); + $vid = $vocabulary['vid']; + variable_set('forum_nav_vocabulary', $vid); + } + + return $vid; +} + +/** + * Menu callback; present general forum configuration options + */ +function forum_configure() { + if ($_POST) { + system_settings_save(); + } + + $output = form_textarea(t('Explanation or submission guidelines'), 'forum_help', variable_get('forum_help', ''), 70, 5, t('This text will be displayed at the top of the forum submission form. Useful for helping or instructing your users.')); + $output .= form_textfield(t('Forum icon path'), 'forum_icon_path', variable_get('forum_icon_path', ''), 30, 255, t('The path to the forum icons. Leave blank to disable icons. Don\'t add a trailing slash. Default icons are available in the "misc" directory.')); + $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 10000)); + $output .= form_select(t('Hot topic threshold'), 'forum_hot_topic', variable_get('forum_hot_topic', 15), $number, t('The number of posts a topic must have to be considered hot.')); + $number = drupal_map_assoc(array(10, 25, 50, 75, 100)); + $output .= form_select(t('Topics per page'), 'forum_per_page', variable_get('forum_per_page', 25), $number, t('The default number of topics displayed per page; links to browse older messages are automatically being displayed.')); + $forder = array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4=> t('Posts - least active first')); + $output .= form_radios(t('Default order'), 'forum_order', variable_get('forum_order', '1'), $forder, t('The default display order for topics.')); + $output .= form_select(t('Number of topics in block'), 'forum_block_num', variable_get('forum_block_num', '5'), drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)), t('The number of topics to show in the "Forum topics" block. To enable the block, go to the block administration page.', array('%block-administration' => url('admin/block')))); + + print theme('page', system_settings_form($output)); } /** @@ -188,14 +375,34 @@ function forum_link($type, $node = 0, $m */ function forum_menu() { $items = array(); - + $items[] = array('path' => 'node/add/forum', 'title' => t('forum topic'), - 'access' => user_access('create forum topics')); + 'access' => user_access('create forum topics')); + $items[] = array('path' => 'forum', 'title' => t('forums'), 'callback' => 'forum_page', 'access' => user_access('access content'), 'type' => MENU_CALLBACK); - + + $items[] = array('path' => 'admin/forum', 'title' => t('forums'), + 'callback' => 'forum_admin', + 'access' => user_access('administer forums'), + 'type' => MENU_NORMAL_ITEM); + + $items[] = array('path' => 'admin/forum/list', 'title' => t('list'), + 'access' => user_access('administer forums'), + 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); + $items[] = array('path' => 'admin/forum/add/container', 'title' => t('add container'), + 'access' => user_access('administer forums'), + 'type' => MENU_LOCAL_TASK); + $items[] = array('path' => 'admin/forum/add/forum', 'title' => t('add forum'), + 'access' => user_access('administer forums'), + 'type' => MENU_LOCAL_TASK); + $items[] = array('path' => 'admin/forum/configure', 'title' => t('configure'), + 'access' => user_access('administer forums'), + 'callback' => 'forum_configure', + 'type' => MENU_LOCAL_TASK); + return $items; } Index: modules/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy.module,v retrieving revision 1.143 diff -u -F^f -r1.143 taxonomy.module --- modules/taxonomy.module 14 Sep 2004 22:55:40 -0000 1.143 +++ modules/taxonomy.module 15 Sep 2004 05:02:21 -0000 @@ -118,7 +118,7 @@ function taxonomy_save_vocabulary($edit) $edit['nodes'] = array(); } - $data = array('name' => $edit['name'], 'nodes' => implode(',', $edit['nodes']), 'description' => $edit['description'], 'help' => $edit['help'], 'multiple' => $edit['multiple'], 'required' => $edit['required'], 'hierarchy' => $edit['hierarchy'], 'relations' => $edit['relations'], 'weight' => $edit['weight']); + $data = array('name' => $edit['name'], 'nodes' => implode(',', $edit['nodes']), 'description' => $edit['description'], 'help' => $edit['help'], 'multiple' => $edit['multiple'], 'required' => $edit['required'], 'hierarchy' => $edit['hierarchy'], 'relations' => $edit['relations'], 'weight' => $edit['weight'], 'module' => isset($edit['module']) ? $edit['module'] : 'taxonomy'); if ($edit['vid'] && $edit['name']) { db_query('UPDATE {vocabulary} SET '. _taxonomy_prepare_update($data) .' WHERE vid = %d', $edit['vid']); module_invoke_all('taxonomy', 'update', 'vocabulary', $edit); @@ -304,21 +304,23 @@ function taxonomy_overview() { $vocabularies = taxonomy_get_vocabularies(); foreach ($vocabularies as $vocabulary) { - $links = array(); - $types = array(); - foreach(explode(',', $vocabulary->nodes) as $type) { - $types[] = node_invoke($type, 'node_name'); - } - $rows[] = array($vocabulary->name, array('data' => implode(', ', $types), 'align' => 'center'), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('add term'), "admin/taxonomy/add/term/$vocabulary->vid"), l(t('preview form'), "admin/taxonomy/preview/vocabulary/$vocabulary->vid")); - - $tree = taxonomy_get_tree($vocabulary->vid); - if ($tree) { - unset($data); - foreach ($tree as $term) { - $data .= _taxonomy_depth($term->depth) .' '. $term->name .' ('. l(t('edit term'), "admin/taxonomy/edit/term/$term->tid") .')