body); } } /** * Implementation of hook_perm(). */ function helpedit_perm() { return array('customize help'); } /** * Implementation of hook_menu(). */ function helpedit_menu($may_cache) { if ($may_cache) { $items[] = array( 'path' => 'admin/help/custom', 'title' => t('customize'), 'callback' => 'helpedit_list_page', 'access' => user_access('customize help'), ); $items[] = array( 'path' => 'admin/help/custom/edit', 'title' => t('edit message'), 'callback' => 'helpedit_edit_page', 'access' => user_access('customize help'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/help/custom/delete', 'title' => t('delete message'), 'callback' => 'helpedit_delete_page', 'access' => user_access('customize help'), 'type' => MENU_CALLBACK, ); } return $items; } /** * Helper function for loading a help row. */ function helpedit_load($hid) { return db_fetch_array(db_query("SELECT * FROM {help} WHERE hid = %d", $hid)); } /** * Page that lists all help messages and commands for creating/editing/deleteing. */ function helpedit_list_page () { $header = array(t('Path'), t('Type'), t('Message'), t('Operations')); $output = '' .''; $result = db_query("SELECT * FROM {help} ORDER BY path"); while ($help = db_fetch_object($result)) { $links = l(t('edit'), 'admin/help/custom/edit/'. $help->hid) .' ' . l(t('delete'), 'admin/help/custom/delete/'. $help->hid); $rows[] = array($help->path, ($help->path_type == 0 ? t('exact') : t('fuzzy')), $help->body, $links); $output .= '' .'' .'' .'' .''; } $output .= '
PathTypeMessageOperations
'. $help->path .''. ($help->path_type==0 ? 'exact' : 'fuzzy') .''. $help->body. ''. l('edit', 'admin/help/custom/edit/'. $help->hid) .' '. l('delete', 'admin/help/custom/delete/'.$help->hid) .'

'. l('new help message', 'admin/help/custom/edit'); $output = theme_table($header, $rows) .'
'. l(t('new help message'), 'admin/help/custom/edit'); return $output; } /** * Page to edit a help message. */ function helpedit_edit_page($hid = 0) { if ($hid) { $help = helpedit_load($hid); } $form['path'] = array( '#type' => 'textfield', '#title' => t('Path'), '#default_value' => $help['path'], '#size' => 50, '#maxlength' => 128, '#description' => t('The existing path you wish to provide a help message for.') .'
' . t('This can either be an exact path (like node/23) or an fuzzy path (like node/%).'), '#required' => TRUE, ); $form['path_type'] = array( '#type' => 'radios', '#title' => t('Exact or fuzzy path matching'), '#options' => array( '0' => t('The path you entered must match the request path exactly for this help message to be displayed.'), '1' => t('Fuzzy matching allows you to use % as a wildcard in the path.'), ), '#default_value' => (isset($help['path_type']) ? $help['path_type'] : '0'), ); $form['body'] = array( '#type' => 'textarea', '#title' => t('Body'), '#default_value' => $help['body'], '#cols' => 50, '#rows' => 6, '#required' => TRUE, ); $form['hid'] = array( '#type' => 'hidden', '#value' => $help['hid'], ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save message'), ); $output = drupal_get_form('help_message_form', $form); return $output; } /** * Save a edited help meesage. */ function help_message_form_submit($form_id, $form_values) { if (!$form_values['hid']) { db_query("INSERT INTO {help} SET path = '%s', path_type = %d, body='%s'", $form_values['path'], $form_values['path_type'], $form_values['body']); drupal_set_message(t('The message has been created.')); } else { db_query("UPDATE {help} SET path = '%s', path_type = %d, body = '%s' WHERE hid = %d", $form_values['path'], $form_values['path_type'], $form_values['body'], $form_values['hid']); drupal_set_message(t('The message has been updated.')); } drupal_goto('admin/help/custom'); } /** * Delete a help message. */ function helpedit_delete_page($hid = 0) { db_query("DELETE FROM {help} WHERE hid = %d", $hid); drupal_set_message(t('The help message has been deleted.')); drupal_goto('admin/help/custom'); }