Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.420
diff -U3 -r1.420 common.inc
--- includes/common.inc 22 Jan 2005 11:15:24 -0000 1.420
+++ includes/common.inc 24 Jan 2005 16:36:14 -0000
@@ -60,6 +60,7 @@
$output = "\n";
$output .= "\n";
$output .= theme('stylesheet_import', 'misc/drupal.css');
+ $output .= '';
return $output . drupal_set_html_head();
}
Index: misc/drupal.css
===================================================================
RCS file: /cvs/drupal/drupal/misc/drupal.css,v
retrieving revision 1.92
diff -U3 -r1.92 drupal.css
--- misc/drupal.css 23 Jan 2005 15:36:07 -0000 1.92
+++ misc/drupal.css 24 Jan 2005 16:36:14 -0000
@@ -84,6 +84,15 @@
td.menu-disabled {
background: #ccc;
}
+#quick-menu-form {
+ background-color: #eee;
+ padding: 0.5em;
+}
+
+#quick-menu-menu ul {
+ margin-left: 1.0em;
+ padding-left: 0;
+}
/*
** Other common styles
Index: modules/menu.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu.module,v
retrieving revision 1.26
diff -U3 -r1.26 menu.module
--- modules/menu.module 23 Nov 2004 22:20:41 -0000 1.26
+++ modules/menu.module 24 Jan 2005 16:36:14 -0000
@@ -92,6 +92,61 @@
}
/**
+ * Implementation of hook_nodeapi().
+ */
+function menu_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+
+ if (user_access('administer menu')) {
+ switch ($op) {
+ case 'form post':
+ if (!in_array($node->type, (array) variable_get('menu_link_nodes_hide', ''))) {
+ $edit = $_POST['edit'];
+ $edit['nid'] = $node->nid;
+
+ $output = '
';
+
+ $output .= '';
+
+ return $output;
+ }
+ break;
+
+ case 'insert':
+ case 'update':
+ if ($node->menu['delete']) {
+ db_query('DELETE FROM {menu} WHERE mid = %d', $node->menu['mid']);
+ drupal_set_message(t('Menu item deleted.'));
+ menu_rebuild();
+ }
+ elseif ($node->menu['title']) {
+ $edit['title'] = $node->menu['title'];
+ $edit['description'] = '';
+ $edit['path'] = ($node->menu['path']) ? $node->menu['path'] : "node/$node->nid";
+ $edit['pid'] = $node->menu['pid'];
+ $edit['weight'] = $node->menu['weight'];
+ $edit['mid'] = $node->menu['mid'];
+ $edit['type'] = $node->menu['type'];
+
+ menu_edit_item_save($edit);
+ menu_rebuild();
+ }
+ break;
+
+ case 'delete':
+ db_query('DELETE FROM {menu} WHERE mid = %d', $node->menu['mid']);
+ drupal_set_message(t('Menu item deleted.'));
+ menu_rebuild();
+ break;
+ }
+ }
+}
+
+/**
* Implementation of hook_perm().
*/
function menu_perm() {
@@ -99,6 +154,22 @@
}
/**
+ * Implementation of hook_settings().
+ */
+function menu_settings() {
+ $output = '';
+
+ foreach (node_list() as $type) {
+ $nodetypes[$type] = node_invoke($type, 'node_name');
+ }
+ $group = form_checkboxes(t('Hide the menu quick link for the following node types.'), 'menu_link_nodes_hide', variable_get('menu_link_nodes_hide', array()), $nodetypes, t('Check the node types you do not want to be quickly add to the menu system via the node editing form.'));
+ $options = menu_parent_options(0);
+ $group .= form_select(t('Default parent item'), 'menu_quick_link_pid', variable_get('menu_quick_link_pid', 1), $options, t('Choose a parent to be selected by default in the menu \'quick item\' form.'));
+ $output = form_group(t('Menu \'quick link\' form'), $group);
+ return $output;
+}
+
+/**
* Menu callback; present the main menu management page.
*/
function menu_overview() {
@@ -487,6 +558,37 @@
}
return $options;
+}
+
+/**
+ * Build the form for quickly adding a menu item for a given node.
+ */
+function menu_quick_link_form($edit = array()) {
+ $item = array();
+ if ($edit['nid'] > 0) {
+ $item = db_fetch_array(db_query("SELECT * FROM {menu} WHERE path = 'node/%d'", $edit['nid']));
+ if (!$item['path']) {
+ // I don't really have to set this, but it's probably good practice.
+ $item['path'] = 'node/'. $edit['nid'];
+ }
+ }
+ $item = ($_POST['op'] == t('Preview')) ? array_merge($item, $edit['menu']) : array_merge($edit['menu'], $item);
+
+ $form = form_textfield(t('Menu item title'), 'menu][title', $item['title'], 60, 128, t('The name to display for this link.'), NULL, TRUE);
+ // Generate a list of possible parents (not including this item or descendants).
+ $options = menu_parent_options($edit['mid']);
+ $form .= form_select(t('Parent item'), 'menu][pid', ($item['pid']) ? $item['pid'] : variable_get('menu_quick_link_pid', 1), $options);
+ $form .= form_hidden('menu][description', $item['description']);
+ $form .= form_hidden('menu][path', $item['path']);
+ $form .= form_hidden('menu][weight', ($item['weight']) ? $item['weight'] : 0);
+ $form .= form_hidden('menu][mid', ($item['mid']) ? $item['mid'] : 0);
+ $form .= form_hidden('menu][type', ($item['type']) ? $item['type'] : MENU_CUSTOM_ITEM);
+
+ if ($item['mid'] > 0) {
+ $form .= form_checkbox(t('Check to remove this menu item.'), 'menu][delete', 1, $item['delete'], null);
+ }
+
+ return $form;
}
?>