? forumadmin3.patch ? forumadmin4.patch ? forumadmin5.patch ? sites/pollock.local Index: database/database.mysql =================================================================== RCS file: /cvs/drupal/drupal/database/database.mysql,v retrieving revision 1.167 diff -u -r1.167 database.mysql --- database/database.mysql 27 Jan 2005 19:41:00 -0000 1.167 +++ database/database.mysql 27 Jan 2005 20:22:26 -0000 @@ -750,6 +750,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 '', weight tinyint(4) NOT NULL default '0', PRIMARY KEY (vid) ) TYPE=MyISAM; Index: database/updates.inc =================================================================== RCS file: /cvs/drupal/drupal/database/updates.inc,v retrieving revision 1.88 diff -u -r1.88 updates.inc --- database/updates.inc 27 Jan 2005 19:41:00 -0000 1.88 +++ database/updates.inc 27 Jan 2005 20:22:27 -0000 @@ -98,7 +98,8 @@ "2005-01-20" => "update_119", "2005-01-25" => "update_120", "2005-01-26" => "update_121", - "2005-01-27" => "update_122" + "2005-01-27" => "update_122", + "2005-01-28" => "update_123" ); function update_32() { @@ -2176,6 +2177,19 @@ $ret[] = update_sql("ALTER TABLE {blocks} ADD type text"); return $ret; +} + +function update_123() { + $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) { Index: modules/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum.module,v retrieving revision 1.225 diff -u -r1.225 forum.module --- modules/forum.module 26 Jan 2005 22:59:41 -0000 1.225 +++ modules/forum.module 27 Jan 2005 20:22:27 -0000 @@ -13,16 +13,21 @@ switch ($section) { case 'admin/help#forum': return t(" -

Creating a forum

-

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 additional 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.

-

Icons

-

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.

+

Creating forums

+

Forums and containers are used to organize the threaded discussions. Forums may be nested within 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. +

Icons

+

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 creating 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 t('A forum is a threaded discussion, enabling users to communicate about a particular topic.'); } @@ -40,11 +45,11 @@ */ function forum_access($op, $node) { global $user; - + if ($op == 'create') { return user_access('create forum topics'); } - + if ($op == 'update' || $op == 'delete') { if (user_access('edit own forum topics') && ($user->uid == $node->uid)) { return TRUE; @@ -56,46 +61,241 @@ * Implementation of hook_perm(). */ function forum_perm() { - return array('create forum topics', 'edit own forum topics'); + return array('create forum topics', 'edit own 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; +/** + * 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 sub-forums 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 container name is used on the forum listing page to identify a group of forums.'), NULL, TRUE); + $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('The description can provide additional information about the forum grouping.')); + + $form .= _forum_parent_select($edit['tid'], t('Parent'), 'parent]['); + $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier terms (with a larger weight) 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); +} - 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); +/** + * 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 is used to identify the forum.'), NULL, TRUE); + $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('The description can be used to provide more information about the forum, or further details about the topic.')); + + $form .= _forum_parent_select($edit['tid'], t('Parent'), 'parent]['); + $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier (with a higher weight value) 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); +} - $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.')); - $group .= form_select(t('Hot topic threshold'), 'forum_hot_topic', variable_get('forum_hot_topic', 15), drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 10000)), t('The number of posts a topic must have to be considered hot.')); - $group .= form_select(t('Topics per page'), 'forum_per_page', variable_get('forum_per_page', 25), drupal_map_assoc(array(10, 25, 50, 75, 100)), t('The default number of topics displayed per page; links to browse older messages are automatically being displayed.')); - $group .= form_radios(t('Default order'), 'forum_order', variable_get('forum_order', '1'), array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4=> t('Posts - least active first')), t('The default display order for topics.')); - $output .= form_group(t('Forum viewing options'), $group); +/** + * 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); + + // 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 form_select($title, $name, $parents, $options, NULL, 0, FALSE, TRUE); +} - return $output; +/** + * Returns an overview list of existing forums and contianers + */ +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); + } } /** - * Implementation of hook_taxonomy(). + * 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_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_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)) { + // Check to see if a forum vocabulary exists + $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module='%s'", 'forum')); + if (!$vid) { + $vocabulary = taxonomy_save_vocabulary(array('name' => 'Forums', 'multiple' => '0', 'required' => '1', 'hierarchy' => '1', 'relations' => '0', 'module' => 'forum', '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)); } /** @@ -103,7 +303,7 @@ */ function forum_load($node) { $forum = db_fetch_object(db_query('SELECT * FROM {forum} WHERE nid = %d', $node->nid)); - + return $forum; } @@ -202,12 +402,34 @@ if ($may_cache) { $items[] = array('path' => 'node/add/forum', 'title' => t('forum topic'), 'access' => user_access('create forum topics')); + $items[] = array('path' => 'forum', 'title' => t('forums'), 'callback' => 'forum_page', 'access' => user_access('access content'), 'type' => MENU_SUGGESTED_ITEM); - } + $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.169 diff -u -r1.169 taxonomy.module --- modules/taxonomy.module 19 Jan 2005 16:22:52 -0000 1.169 +++ modules/taxonomy.module 27 Jan 2005 20:22:27 -0000 @@ -145,7 +145,7 @@ $edit['nodes'] = array(); } - $data = array('name' => $edit['name'], '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'], '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']); db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d", $edit['vid']); @@ -357,21 +357,23 @@ $vocabularies = taxonomy_get_vocabularies(); foreach ($vocabularies as $vocabulary) { - $types = array(); - foreach($vocabulary->nodes as $type) { - $node_type = node_invoke($type, 'node_name'); - $types[] = $node_type ? $node_type : $type; - } - - $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")); + if ($vocabulary->module == 'taxonomy') { + $types = array(); + foreach($vocabulary->nodes as $type) { + $node_type = node_invoke($type, 'node_name'); + $types[] = $node_type ? $node_type : $type; + } + + $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); + $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") .')
'; } $rows[] = array(array('data' => $data, 'colspan' => '5')); + } } }